/*
- * (C) Copyright 2012-2013,2015 Stephen Warren
+ * (C) Copyright 2012-2016 Stephen Warren
*
* SPDX-License-Identifier: GPL-2.0
*/
#include <common.h>
+#include <inttypes.h>
#include <config.h>
#include <dm.h>
+#include <efi_loader.h>
#include <fdt_support.h>
#include <fdt_simplefb.h>
#include <lcd.h>
#include <asm/arch/mbox.h>
#include <asm/arch/sdhci.h>
#include <asm/global_data.h>
-#include <dm/platform_data/serial_pl01x.h>
+#include <dm/platform_data/serial_bcm283x_mu.h>
+#ifdef CONFIG_ARM64
+#include <asm/armv8/mmu.h>
+#endif
DECLARE_GLOBAL_DATA_PTR;
-static const struct bcm2835_gpio_platdata gpio_platdata = {
- .base = BCM2835_GPIO_BASE,
-};
-
-U_BOOT_DEVICE(bcm2835_gpios) = {
- .name = "gpio_bcm2835",
- .platdata = &gpio_platdata,
-};
-
-static const struct pl01x_serial_platdata serial_platdata = {
-#ifdef CONFIG_BCM2836
- .base = 0x3f201000,
-#else
- .base = 0x20201000,
-#endif
- .type = TYPE_PL011,
- .clock = 3000000,
-};
+/* From lowlevel_init.S */
+extern unsigned long fw_dtb_pointer;
-U_BOOT_DEVICE(bcm2835_serials) = {
- .name = "serial_pl01x",
- .platdata = &serial_platdata,
-};
struct msg_get_arm_mem {
struct bcm2835_mbox_hdr hdr;
u32 end_tag;
};
+struct msg_get_board_serial {
+ struct bcm2835_mbox_hdr hdr;
+ struct bcm2835_mbox_tag_get_board_serial get_board_serial;
+ u32 end_tag;
+};
+
struct msg_get_mac_address {
struct bcm2835_mbox_hdr hdr;
struct bcm2835_mbox_tag_get_mac_address get_mac_address;
u32 end_tag;
};
-/* See comments in mbox.h for data source */
-static const struct {
+/*
+ * http://raspberryalphaomega.org.uk/2013/02/06/automatic-raspberry-pi-board-revision-detection-model-a-b1-and-b2/
+ * http://www.raspberrypi.org/forums/viewtopic.php?f=63&t=32733
+ * http://git.drogon.net/?p=wiringPi;a=blob;f=wiringPi/wiringPi.c;h=503151f61014418b9c42f4476a6086f75cd4e64b;hb=refs/heads/master#l922
+ *
+ * In http://lists.denx.de/pipermail/u-boot/2016-January/243752.html
+ * ("[U-Boot] [PATCH] rpi: fix up Model B entries") Dom Cobley at the RPi
+ * Foundation stated that the following source was accurate:
+ * https://github.com/AndrewFromMelbourne/raspberry_pi_revision
+ */
+struct rpi_model {
const char *name;
const char *fdtfile;
bool has_onboard_eth;
-} models[] = {
- [0] = {
- "Unknown model",
-#ifdef CONFIG_BCM2836
- "bcm2836-rpi-other.dtb",
-#else
- "bcm2835-rpi-other.dtb",
-#endif
- false,
- },
-#ifdef CONFIG_BCM2836
- [BCM2836_BOARD_REV_2_B] = {
+};
+
+static const struct rpi_model rpi_model_unknown = {
+ "Unknown model",
+ "bcm283x-rpi-other.dtb",
+ false,
+};
+
+static const struct rpi_model rpi_models_new_scheme[] = {
+ [0x4] = {
"2 Model B",
"bcm2836-rpi-2-b.dtb",
true,
},
-#else
- [BCM2835_BOARD_REV_B_I2C0_2] = {
- "Model B (no P5)",
- "bcm2835-rpi-b-i2c0.dtb",
+ [0x8] = {
+ "3 Model B",
+ "bcm2837-rpi-3-b.dtb",
true,
},
- [BCM2835_BOARD_REV_B_I2C0_3] = {
- "Model B (no P5)",
- "bcm2835-rpi-b-i2c0.dtb",
- true,
+ [0x9] = {
+ "Zero",
+ "bcm2835-rpi-zero.dtb",
+ false,
},
- [BCM2835_BOARD_REV_B_I2C1_4] = {
+};
+
+static const struct rpi_model rpi_models_old_scheme[] = {
+ [0x2] = {
"Model B",
"bcm2835-rpi-b.dtb",
true,
},
- [BCM2835_BOARD_REV_B_I2C1_5] = {
+ [0x3] = {
"Model B",
"bcm2835-rpi-b.dtb",
true,
},
- [BCM2835_BOARD_REV_B_I2C1_6] = {
- "Model B",
- "bcm2835-rpi-b.dtb",
+ [0x4] = {
+ "Model B rev2",
+ "bcm2835-rpi-b-rev2.dtb",
+ true,
+ },
+ [0x5] = {
+ "Model B rev2",
+ "bcm2835-rpi-b-rev2.dtb",
true,
},
- [BCM2835_BOARD_REV_A_7] = {
+ [0x6] = {
+ "Model B rev2",
+ "bcm2835-rpi-b-rev2.dtb",
+ true,
+ },
+ [0x7] = {
"Model A",
"bcm2835-rpi-a.dtb",
false,
},
- [BCM2835_BOARD_REV_A_8] = {
+ [0x8] = {
"Model A",
"bcm2835-rpi-a.dtb",
false,
},
- [BCM2835_BOARD_REV_A_9] = {
+ [0x9] = {
"Model A",
"bcm2835-rpi-a.dtb",
false,
},
- [BCM2835_BOARD_REV_B_REV2_d] = {
+ [0xd] = {
"Model B rev2",
"bcm2835-rpi-b-rev2.dtb",
true,
},
- [BCM2835_BOARD_REV_B_REV2_e] = {
+ [0xe] = {
"Model B rev2",
"bcm2835-rpi-b-rev2.dtb",
true,
},
- [BCM2835_BOARD_REV_B_REV2_f] = {
+ [0xf] = {
"Model B rev2",
"bcm2835-rpi-b-rev2.dtb",
true,
},
- [BCM2835_BOARD_REV_B_PLUS] = {
+ [0x10] = {
"Model B+",
"bcm2835-rpi-b-plus.dtb",
true,
},
- [BCM2835_BOARD_REV_CM] = {
+ [0x11] = {
"Compute Module",
"bcm2835-rpi-cm.dtb",
false,
},
- [BCM2835_BOARD_REV_A_PLUS] = {
+ [0x12] = {
"Model A+",
"bcm2835-rpi-a-plus.dtb",
false,
},
- [BCM2835_BOARD_REV_B_PLUS_13] = {
+ [0x13] = {
"Model B+",
"bcm2835-rpi-b-plus.dtb",
true,
},
- [BCM2835_BOARD_REV_CM_14] = {
+ [0x14] = {
"Compute Module",
"bcm2835-rpi-cm.dtb",
false,
},
-#endif
+ [0x15] = {
+ "Model A+",
+ "bcm2835-rpi-a-plus.dtb",
+ false,
+ },
};
-u32 rpi_board_rev = 0;
+static uint32_t revision;
+static uint32_t rev_scheme;
+static uint32_t rev_type;
+static const struct rpi_model *model;
+
+#ifdef CONFIG_ARM64
+static struct mm_region bcm2837_mem_map[] = {
+ {
+ .virt = 0x00000000UL,
+ .phys = 0x00000000UL,
+ .size = 0x3f000000UL,
+ .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
+ PTE_BLOCK_INNER_SHARE
+ }, {
+ .virt = 0x3f000000UL,
+ .phys = 0x3f000000UL,
+ .size = 0x01000000UL,
+ .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
+ PTE_BLOCK_NON_SHARE |
+ PTE_BLOCK_PXN | PTE_BLOCK_UXN
+ }, {
+ /* List terminator */
+ 0,
+ }
+};
+
+struct mm_region *mem_map = bcm2837_mem_map;
+#endif
int dram_init(void)
{
if (getenv("fdtfile"))
return;
- fdtfile = models[rpi_board_rev].fdtfile;
+ fdtfile = model->fdtfile;
setenv("fdtfile", fdtfile);
}
+/*
+ * If the firmware provided a valid FDT at boot time, let's expose it in
+ * ${fdt_addr} so it may be passed unmodified to the kernel.
+ */
+static void set_fdt_addr(void)
+{
+ if (getenv("fdt_addr"))
+ return;
+
+ if (fdt_magic(fw_dtb_pointer) != FDT_MAGIC)
+ return;
+
+ setenv_hex("fdt_addr", fw_dtb_pointer);
+}
+
+/*
+ * Prevent relocation from stomping on a firmware provided FDT blob.
+ */
+unsigned long board_get_usable_ram_top(unsigned long total_size)
+{
+ if ((gd->ram_top - fw_dtb_pointer) > SZ_64M)
+ return gd->ram_top;
+ return fw_dtb_pointer & ~0xffff;
+}
+
static void set_usbethaddr(void)
{
ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_mac_address, msg, 1);
int ret;
- if (!models[rpi_board_rev].has_onboard_eth)
+ if (!model->has_onboard_eth)
return;
if (getenv("usbethaddr"))
eth_setenv_enetaddr("usbethaddr", msg->get_mac_address.body.resp.mac);
+ if (!getenv("ethaddr"))
+ setenv("ethaddr", getenv("usbethaddr"));
+
return;
}
+#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
+static void set_board_info(void)
+{
+ char s[11];
+
+ snprintf(s, sizeof(s), "0x%X", revision);
+ setenv("board_revision", s);
+ snprintf(s, sizeof(s), "%d", rev_scheme);
+ setenv("board_rev_scheme", s);
+ /* Can't rename this to board_rev_type since it's an ABI for scripts */
+ snprintf(s, sizeof(s), "0x%X", rev_type);
+ setenv("board_rev", s);
+ setenv("board_name", model->name);
+}
+#endif /* CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG */
+
+static void set_serial_number(void)
+{
+ ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_board_serial, msg, 1);
+ int ret;
+ char serial_string[17] = { 0 };
+
+ if (getenv("serial#"))
+ return;
+
+ BCM2835_MBOX_INIT_HDR(msg);
+ BCM2835_MBOX_INIT_TAG_NO_REQ(&msg->get_board_serial, GET_BOARD_SERIAL);
+
+ ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr);
+ if (ret) {
+ printf("bcm2835: Could not query board serial\n");
+ /* Ignore error; not critical */
+ return;
+ }
+
+ snprintf(serial_string, sizeof(serial_string), "%016" PRIx64,
+ msg->get_board_serial.body.resp.serial);
+ setenv("serial#", serial_string);
+}
+
int misc_init_r(void)
{
+ set_fdt_addr();
set_fdtfile();
set_usbethaddr();
+#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
+ set_board_info();
+#endif
+ set_serial_number();
+
return 0;
}
{
ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_board_rev, msg, 1);
int ret;
- const char *name;
+ const struct rpi_model *models;
+ uint32_t models_count;
BCM2835_MBOX_INIT_HDR(msg);
BCM2835_MBOX_INIT_TAG(&msg->get_board_rev, GET_BOARD_REV);
* http://www.raspberrypi.org/forums/viewtopic.php?f=63&t=98367&start=250
* http://www.raspberrypi.org/forums/viewtopic.php?f=31&t=20594
*/
- rpi_board_rev = msg->get_board_rev.body.resp.rev;
- if (rpi_board_rev & 0x800000)
- rpi_board_rev = (rpi_board_rev >> 4) & 0xff;
- else
- rpi_board_rev &= 0xff;
- if (rpi_board_rev >= ARRAY_SIZE(models)) {
- printf("RPI: Board rev %u outside known range\n",
- rpi_board_rev);
- rpi_board_rev = 0;
+ revision = msg->get_board_rev.body.resp.rev;
+ if (revision & 0x800000) {
+ rev_scheme = 1;
+ rev_type = (revision >> 4) & 0xff;
+ models = rpi_models_new_scheme;
+ models_count = ARRAY_SIZE(rpi_models_new_scheme);
+ } else {
+ rev_scheme = 0;
+ rev_type = revision & 0xff;
+ models = rpi_models_old_scheme;
+ models_count = ARRAY_SIZE(rpi_models_old_scheme);
}
- if (!models[rpi_board_rev].name) {
- printf("RPI: Board rev %u unknown\n", rpi_board_rev);
- rpi_board_rev = 0;
+ if (rev_type >= models_count) {
+ printf("RPI: Board rev 0x%x outside known range\n", rev_type);
+ model = &rpi_model_unknown;
+ } else if (!models[rev_type].name) {
+ printf("RPI: Board rev 0x%x unknown\n", rev_type);
+ model = &rpi_model_unknown;
+ } else {
+ model = &models[rev_type];
}
- name = models[rpi_board_rev].name;
- printf("RPI %s\n", name);
+ printf("RPI %s (0x%x)\n", model->name, revision);
+}
+
+#ifndef CONFIG_PL01X_SERIAL
+static bool rpi_is_serial_active(void)
+{
+ int serial_gpio = 15;
+ struct udevice *dev;
+
+ /*
+ * The RPi3 disables the mini uart by default. The easiest way to find
+ * out whether it is available is to check if the RX pin is muxed.
+ */
+
+ if (uclass_first_device(UCLASS_GPIO, &dev) || !dev)
+ return true;
+
+ if (bcm2835_gpio_get_func_id(dev, serial_gpio) != BCM2835_GPIO_ALT5)
+ return false;
+
+ return true;
}
+/* Disable mini-UART I/O if it's not pinmuxed to our pins.
+ * The firmware only enables it if explicitly done in config.txt: enable_uart=1
+ */
+static void rpi_disable_inactive_uart(void)
+{
+ struct udevice *dev;
+ struct bcm283x_mu_serial_platdata *plat;
+
+ if (uclass_get_device_by_driver(UCLASS_SERIAL,
+ DM_GET_DRIVER(serial_bcm283x_mu),
+ &dev) || !dev)
+ return;
+
+ if (!rpi_is_serial_active()) {
+ plat = dev_get_platdata(dev);
+ plat->disabled = true;
+ }
+}
+#endif
+
int board_init(void)
{
+#ifndef CONFIG_PL01X_SERIAL
+ rpi_disable_inactive_uart();
+#endif
+
get_board_rev();
gd->bd->bi_boot_params = 0x100;
*/
lcd_dt_simplefb_add_node(blob);
+#ifdef CONFIG_EFI_LOADER
+ /* Reserve the spin table */
+ efi_add_memory_map(0, 1, EFI_RESERVED_MEMORY_TYPE, 0);
+#endif
+
return 0;
}