19316e144SStephen Warren /* 2f031f501SStephen Warren * (C) Copyright 2012-2016 Stephen Warren 39316e144SStephen Warren * 4a033171bSStephen Warren * SPDX-License-Identifier: GPL-2.0 59316e144SStephen Warren */ 69316e144SStephen Warren 79316e144SStephen Warren #include <common.h> 8757cd149SLubomir Rintel #include <inttypes.h> 99316e144SStephen Warren #include <config.h> 109316e144SStephen Warren #include <dm.h> 111bcf7a30SAlexander Graf #include <efi_loader.h> 129316e144SStephen Warren #include <fdt_support.h> 13033167c4SNikita Kiryanov #include <fdt_simplefb.h> 149316e144SStephen Warren #include <lcd.h> 15cf92e05cSSimon Glass #include <memalign.h> 169316e144SStephen Warren #include <mmc.h> 179316e144SStephen Warren #include <asm/gpio.h> 189316e144SStephen Warren #include <asm/arch/mbox.h> 1970997d88SSimon Glass #include <asm/arch/msg.h> 209316e144SStephen Warren #include <asm/arch/sdhci.h> 219316e144SStephen Warren #include <asm/global_data.h> 22f031f501SStephen Warren #include <dm/platform_data/serial_bcm283x_mu.h> 23d22a7657SStephen Warren #ifdef CONFIG_ARM64 24d22a7657SStephen Warren #include <asm/armv8/mmu.h> 25d22a7657SStephen Warren #endif 2645a6d231SPaolo Pisati #include <watchdog.h> 27caf2233bSAlexander Graf #include <dm/pinctrl.h> 289316e144SStephen Warren 299316e144SStephen Warren DECLARE_GLOBAL_DATA_PTR; 309316e144SStephen Warren 31ade243a2SCédric Schieli /* From lowlevel_init.S */ 32ade243a2SCédric Schieli extern unsigned long fw_dtb_pointer; 33ade243a2SCédric Schieli 343e16705dSSimon Glass /* TODO(sjg@chromium.org): Move these to the msg.c file */ 359316e144SStephen Warren struct msg_get_arm_mem { 369316e144SStephen Warren struct bcm2835_mbox_hdr hdr; 379316e144SStephen Warren struct bcm2835_mbox_tag_get_arm_mem get_arm_mem; 389316e144SStephen Warren u32 end_tag; 399316e144SStephen Warren }; 409316e144SStephen Warren 419316e144SStephen Warren struct msg_get_board_rev { 429316e144SStephen Warren struct bcm2835_mbox_hdr hdr; 439316e144SStephen Warren struct bcm2835_mbox_tag_get_board_rev get_board_rev; 449316e144SStephen Warren u32 end_tag; 459316e144SStephen Warren }; 469316e144SStephen Warren 47757cd149SLubomir Rintel struct msg_get_board_serial { 48757cd149SLubomir Rintel struct bcm2835_mbox_hdr hdr; 49757cd149SLubomir Rintel struct bcm2835_mbox_tag_get_board_serial get_board_serial; 50757cd149SLubomir Rintel u32 end_tag; 51757cd149SLubomir Rintel }; 52757cd149SLubomir Rintel 539316e144SStephen Warren struct msg_get_mac_address { 549316e144SStephen Warren struct bcm2835_mbox_hdr hdr; 559316e144SStephen Warren struct bcm2835_mbox_tag_get_mac_address get_mac_address; 569316e144SStephen Warren u32 end_tag; 579316e144SStephen Warren }; 589316e144SStephen Warren 599316e144SStephen Warren struct msg_get_clock_rate { 609316e144SStephen Warren struct bcm2835_mbox_hdr hdr; 619316e144SStephen Warren struct bcm2835_mbox_tag_get_clock_rate get_clock_rate; 629316e144SStephen Warren u32 end_tag; 639316e144SStephen Warren }; 649316e144SStephen Warren 655d3c4ba1STuomas Tynkkynen #ifdef CONFIG_ARM64 665d3c4ba1STuomas Tynkkynen #define DTB_DIR "broadcom/" 675d3c4ba1STuomas Tynkkynen #else 685d3c4ba1STuomas Tynkkynen #define DTB_DIR "" 695d3c4ba1STuomas Tynkkynen #endif 705d3c4ba1STuomas Tynkkynen 71dbe6f1ebSStephen Warren /* 72dbe6f1ebSStephen Warren * http://raspberryalphaomega.org.uk/2013/02/06/automatic-raspberry-pi-board-revision-detection-model-a-b1-and-b2/ 73dbe6f1ebSStephen Warren * http://www.raspberrypi.org/forums/viewtopic.php?f=63&t=32733 74c4ea1edbSStephen Warren * http://git.drogon.net/?p=wiringPi;a=blob;f=wiringPi/wiringPi.c;h=503151f61014418b9c42f4476a6086f75cd4e64b;hb=refs/heads/master#l922 75dba060ceSStephen Warren * 76dba060ceSStephen Warren * In http://lists.denx.de/pipermail/u-boot/2016-January/243752.html 77dba060ceSStephen Warren * ("[U-Boot] [PATCH] rpi: fix up Model B entries") Dom Cobley at the RPi 78dba060ceSStephen Warren * Foundation stated that the following source was accurate: 79dba060ceSStephen Warren * https://github.com/AndrewFromMelbourne/raspberry_pi_revision 80dbe6f1ebSStephen Warren */ 81c4ea1edbSStephen Warren struct rpi_model { 829316e144SStephen Warren const char *name; 839316e144SStephen Warren const char *fdtfile; 843207d8fcSStephen Warren bool has_onboard_eth; 85c4ea1edbSStephen Warren }; 86c4ea1edbSStephen Warren 87c4ea1edbSStephen Warren static const struct rpi_model rpi_model_unknown = { 88914627feSStephen Warren "Unknown model", 895d3c4ba1STuomas Tynkkynen DTB_DIR "bcm283x-rpi-other.dtb", 90914627feSStephen Warren false, 91c4ea1edbSStephen Warren }; 92c4ea1edbSStephen Warren 93c4ea1edbSStephen Warren static const struct rpi_model rpi_models_new_scheme[] = { 94dbe6f1ebSStephen Warren [0x4] = { 9546414296SStephen Warren "2 Model B", 965d3c4ba1STuomas Tynkkynen DTB_DIR "bcm2836-rpi-2-b.dtb", 9746414296SStephen Warren true, 9846414296SStephen Warren }, 997233fb31SStephen Warren [0x8] = { 1007233fb31SStephen Warren "3 Model B", 1015d3c4ba1STuomas Tynkkynen DTB_DIR "bcm2837-rpi-3-b.dtb", 1027233fb31SStephen Warren true, 1037233fb31SStephen Warren }, 104af7c03eaSStephen Warren [0x9] = { 105af7c03eaSStephen Warren "Zero", 1065d3c4ba1STuomas Tynkkynen DTB_DIR "bcm2835-rpi-zero.dtb", 107af7c03eaSStephen Warren false, 108af7c03eaSStephen Warren }, 1098993056fSDmitry Korunov [0xC] = { 1108993056fSDmitry Korunov "Zero W", 1118993056fSDmitry Korunov DTB_DIR "bcm2835-rpi-zero-w.dtb", 1128993056fSDmitry Korunov false, 1138993056fSDmitry Korunov }, 114*7fe77226SAlexander Graf [0xD] = { 115*7fe77226SAlexander Graf "3 Model B+", 116*7fe77226SAlexander Graf DTB_DIR "bcm2837-rpi-3-b-plus.dtb", 117*7fe77226SAlexander Graf true, 118*7fe77226SAlexander Graf }, 119c4ea1edbSStephen Warren }; 120c4ea1edbSStephen Warren 121c4ea1edbSStephen Warren static const struct rpi_model rpi_models_old_scheme[] = { 122dbe6f1ebSStephen Warren [0x2] = { 1237443a9c4SLubomir Rintel "Model B", 1245d3c4ba1STuomas Tynkkynen DTB_DIR "bcm2835-rpi-b.dtb", 1253207d8fcSStephen Warren true, 1269316e144SStephen Warren }, 127dbe6f1ebSStephen Warren [0x3] = { 1287443a9c4SLubomir Rintel "Model B", 1295d3c4ba1STuomas Tynkkynen DTB_DIR "bcm2835-rpi-b.dtb", 1303207d8fcSStephen Warren true, 1319316e144SStephen Warren }, 132dbe6f1ebSStephen Warren [0x4] = { 1337443a9c4SLubomir Rintel "Model B rev2", 1345d3c4ba1STuomas Tynkkynen DTB_DIR "bcm2835-rpi-b-rev2.dtb", 1353207d8fcSStephen Warren true, 1369316e144SStephen Warren }, 137dbe6f1ebSStephen Warren [0x5] = { 1387443a9c4SLubomir Rintel "Model B rev2", 1395d3c4ba1STuomas Tynkkynen DTB_DIR "bcm2835-rpi-b-rev2.dtb", 1403207d8fcSStephen Warren true, 1419316e144SStephen Warren }, 142dbe6f1ebSStephen Warren [0x6] = { 1437443a9c4SLubomir Rintel "Model B rev2", 1445d3c4ba1STuomas Tynkkynen DTB_DIR "bcm2835-rpi-b-rev2.dtb", 1453207d8fcSStephen Warren true, 1469316e144SStephen Warren }, 147dbe6f1ebSStephen Warren [0x7] = { 1489316e144SStephen Warren "Model A", 1495d3c4ba1STuomas Tynkkynen DTB_DIR "bcm2835-rpi-a.dtb", 1503207d8fcSStephen Warren false, 1519316e144SStephen Warren }, 152dbe6f1ebSStephen Warren [0x8] = { 1539316e144SStephen Warren "Model A", 1545d3c4ba1STuomas Tynkkynen DTB_DIR "bcm2835-rpi-a.dtb", 1553207d8fcSStephen Warren false, 1569316e144SStephen Warren }, 157dbe6f1ebSStephen Warren [0x9] = { 1589316e144SStephen Warren "Model A", 1595d3c4ba1STuomas Tynkkynen DTB_DIR "bcm2835-rpi-a.dtb", 1603207d8fcSStephen Warren false, 1619316e144SStephen Warren }, 162dbe6f1ebSStephen Warren [0xd] = { 1639316e144SStephen Warren "Model B rev2", 1645d3c4ba1STuomas Tynkkynen DTB_DIR "bcm2835-rpi-b-rev2.dtb", 1653207d8fcSStephen Warren true, 1669316e144SStephen Warren }, 167dbe6f1ebSStephen Warren [0xe] = { 1689316e144SStephen Warren "Model B rev2", 1695d3c4ba1STuomas Tynkkynen DTB_DIR "bcm2835-rpi-b-rev2.dtb", 1703207d8fcSStephen Warren true, 1719316e144SStephen Warren }, 172dbe6f1ebSStephen Warren [0xf] = { 1739316e144SStephen Warren "Model B rev2", 1745d3c4ba1STuomas Tynkkynen DTB_DIR "bcm2835-rpi-b-rev2.dtb", 1753207d8fcSStephen Warren true, 1769316e144SStephen Warren }, 177dbe6f1ebSStephen Warren [0x10] = { 1789316e144SStephen Warren "Model B+", 1795d3c4ba1STuomas Tynkkynen DTB_DIR "bcm2835-rpi-b-plus.dtb", 1803207d8fcSStephen Warren true, 1819316e144SStephen Warren }, 182dbe6f1ebSStephen Warren [0x11] = { 1839316e144SStephen Warren "Compute Module", 1845d3c4ba1STuomas Tynkkynen DTB_DIR "bcm2835-rpi-cm.dtb", 1853207d8fcSStephen Warren false, 1869316e144SStephen Warren }, 187dbe6f1ebSStephen Warren [0x12] = { 18847705effSStephen Warren "Model A+", 1895d3c4ba1STuomas Tynkkynen DTB_DIR "bcm2835-rpi-a-plus.dtb", 19047705effSStephen Warren false, 19147705effSStephen Warren }, 192dbe6f1ebSStephen Warren [0x13] = { 193787affb4SStephen Warren "Model B+", 1945d3c4ba1STuomas Tynkkynen DTB_DIR "bcm2835-rpi-b-plus.dtb", 195787affb4SStephen Warren true, 196787affb4SStephen Warren }, 197dbe6f1ebSStephen Warren [0x14] = { 198787affb4SStephen Warren "Compute Module", 1995d3c4ba1STuomas Tynkkynen DTB_DIR "bcm2835-rpi-cm.dtb", 200787affb4SStephen Warren false, 201787affb4SStephen Warren }, 202dbe6f1ebSStephen Warren [0x15] = { 20379ad5cefSLubomir Rintel "Model A+", 2045d3c4ba1STuomas Tynkkynen DTB_DIR "bcm2835-rpi-a-plus.dtb", 20579ad5cefSLubomir Rintel false, 20679ad5cefSLubomir Rintel }, 2079316e144SStephen Warren }; 2089316e144SStephen Warren 209c4ea1edbSStephen Warren static uint32_t revision; 210c4ea1edbSStephen Warren static uint32_t rev_scheme; 211c4ea1edbSStephen Warren static uint32_t rev_type; 212c4ea1edbSStephen Warren static const struct rpi_model *model; 2139316e144SStephen Warren 214d22a7657SStephen Warren #ifdef CONFIG_ARM64 215d22a7657SStephen Warren static struct mm_region bcm2837_mem_map[] = { 216d22a7657SStephen Warren { 217cd4b0c5fSYork Sun .virt = 0x00000000UL, 218cd4b0c5fSYork Sun .phys = 0x00000000UL, 219d22a7657SStephen Warren .size = 0x3f000000UL, 220d22a7657SStephen Warren .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | 221d22a7657SStephen Warren PTE_BLOCK_INNER_SHARE 222d22a7657SStephen Warren }, { 223cd4b0c5fSYork Sun .virt = 0x3f000000UL, 224cd4b0c5fSYork Sun .phys = 0x3f000000UL, 225d22a7657SStephen Warren .size = 0x01000000UL, 226d22a7657SStephen Warren .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | 227d22a7657SStephen Warren PTE_BLOCK_NON_SHARE | 228d22a7657SStephen Warren PTE_BLOCK_PXN | PTE_BLOCK_UXN 229d22a7657SStephen Warren }, { 230d22a7657SStephen Warren /* List terminator */ 231d22a7657SStephen Warren 0, 232d22a7657SStephen Warren } 233d22a7657SStephen Warren }; 234d22a7657SStephen Warren 235d22a7657SStephen Warren struct mm_region *mem_map = bcm2837_mem_map; 236d22a7657SStephen Warren #endif 237d22a7657SStephen Warren 2389316e144SStephen Warren int dram_init(void) 2399316e144SStephen Warren { 240927753aeSAlexander Stein ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_arm_mem, msg, 1); 2419316e144SStephen Warren int ret; 2429316e144SStephen Warren 2439316e144SStephen Warren BCM2835_MBOX_INIT_HDR(msg); 2449316e144SStephen Warren BCM2835_MBOX_INIT_TAG(&msg->get_arm_mem, GET_ARM_MEMORY); 2459316e144SStephen Warren 2469316e144SStephen Warren ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr); 2479316e144SStephen Warren if (ret) { 2489316e144SStephen Warren printf("bcm2835: Could not query ARM memory size\n"); 2499316e144SStephen Warren return -1; 2509316e144SStephen Warren } 2519316e144SStephen Warren 2529316e144SStephen Warren gd->ram_size = msg->get_arm_mem.body.resp.mem_size; 2539316e144SStephen Warren 2549316e144SStephen Warren return 0; 2559316e144SStephen Warren } 2569316e144SStephen Warren 2579316e144SStephen Warren static void set_fdtfile(void) 2589316e144SStephen Warren { 2599316e144SStephen Warren const char *fdtfile; 2609316e144SStephen Warren 26100caae6dSSimon Glass if (env_get("fdtfile")) 2629316e144SStephen Warren return; 2639316e144SStephen Warren 264c4ea1edbSStephen Warren fdtfile = model->fdtfile; 265382bee57SSimon Glass env_set("fdtfile", fdtfile); 2669316e144SStephen Warren } 2679316e144SStephen Warren 268ade243a2SCédric Schieli /* 269ade243a2SCédric Schieli * If the firmware provided a valid FDT at boot time, let's expose it in 270ade243a2SCédric Schieli * ${fdt_addr} so it may be passed unmodified to the kernel. 271ade243a2SCédric Schieli */ 272ade243a2SCédric Schieli static void set_fdt_addr(void) 273ade243a2SCédric Schieli { 27400caae6dSSimon Glass if (env_get("fdt_addr")) 275ade243a2SCédric Schieli return; 276ade243a2SCédric Schieli 277ade243a2SCédric Schieli if (fdt_magic(fw_dtb_pointer) != FDT_MAGIC) 278ade243a2SCédric Schieli return; 279ade243a2SCédric Schieli 280018f5303SSimon Glass env_set_hex("fdt_addr", fw_dtb_pointer); 281ade243a2SCédric Schieli } 282ade243a2SCédric Schieli 283ade243a2SCédric Schieli /* 284ade243a2SCédric Schieli * Prevent relocation from stomping on a firmware provided FDT blob. 285ade243a2SCédric Schieli */ 286ade243a2SCédric Schieli unsigned long board_get_usable_ram_top(unsigned long total_size) 287ade243a2SCédric Schieli { 288ade243a2SCédric Schieli if ((gd->ram_top - fw_dtb_pointer) > SZ_64M) 289ade243a2SCédric Schieli return gd->ram_top; 290ade243a2SCédric Schieli return fw_dtb_pointer & ~0xffff; 291ade243a2SCédric Schieli } 292ade243a2SCédric Schieli 2939316e144SStephen Warren static void set_usbethaddr(void) 2949316e144SStephen Warren { 295927753aeSAlexander Stein ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_mac_address, msg, 1); 2969316e144SStephen Warren int ret; 2979316e144SStephen Warren 298c4ea1edbSStephen Warren if (!model->has_onboard_eth) 2993207d8fcSStephen Warren return; 3003207d8fcSStephen Warren 30100caae6dSSimon Glass if (env_get("usbethaddr")) 3029316e144SStephen Warren return; 3039316e144SStephen Warren 3049316e144SStephen Warren BCM2835_MBOX_INIT_HDR(msg); 3059316e144SStephen Warren BCM2835_MBOX_INIT_TAG(&msg->get_mac_address, GET_MAC_ADDRESS); 3069316e144SStephen Warren 3079316e144SStephen Warren ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr); 3089316e144SStephen Warren if (ret) { 3099316e144SStephen Warren printf("bcm2835: Could not query MAC address\n"); 3109316e144SStephen Warren /* Ignore error; not critical */ 3119316e144SStephen Warren return; 3129316e144SStephen Warren } 3139316e144SStephen Warren 314fd1e959eSSimon Glass eth_env_set_enetaddr("usbethaddr", msg->get_mac_address.body.resp.mac); 3159316e144SStephen Warren 31600caae6dSSimon Glass if (!env_get("ethaddr")) 31700caae6dSSimon Glass env_set("ethaddr", env_get("usbethaddr")); 318859f1437SLubomir Rintel 3199316e144SStephen Warren return; 3209316e144SStephen Warren } 3219316e144SStephen Warren 322bff78567SGuillaume GARDET #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG 323bff78567SGuillaume GARDET static void set_board_info(void) 324bff78567SGuillaume GARDET { 325c4ea1edbSStephen Warren char s[11]; 326c4ea1edbSStephen Warren 327c4ea1edbSStephen Warren snprintf(s, sizeof(s), "0x%X", revision); 328382bee57SSimon Glass env_set("board_revision", s); 329c4ea1edbSStephen Warren snprintf(s, sizeof(s), "%d", rev_scheme); 330382bee57SSimon Glass env_set("board_rev_scheme", s); 331c4ea1edbSStephen Warren /* Can't rename this to board_rev_type since it's an ABI for scripts */ 332c4ea1edbSStephen Warren snprintf(s, sizeof(s), "0x%X", rev_type); 333382bee57SSimon Glass env_set("board_rev", s); 334382bee57SSimon Glass env_set("board_name", model->name); 335bff78567SGuillaume GARDET } 336bff78567SGuillaume GARDET #endif /* CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG */ 337bff78567SGuillaume GARDET 338757cd149SLubomir Rintel static void set_serial_number(void) 339757cd149SLubomir Rintel { 340757cd149SLubomir Rintel ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_board_serial, msg, 1); 341757cd149SLubomir Rintel int ret; 342757cd149SLubomir Rintel char serial_string[17] = { 0 }; 343757cd149SLubomir Rintel 34400caae6dSSimon Glass if (env_get("serial#")) 345757cd149SLubomir Rintel return; 346757cd149SLubomir Rintel 347757cd149SLubomir Rintel BCM2835_MBOX_INIT_HDR(msg); 348757cd149SLubomir Rintel BCM2835_MBOX_INIT_TAG_NO_REQ(&msg->get_board_serial, GET_BOARD_SERIAL); 349757cd149SLubomir Rintel 350757cd149SLubomir Rintel ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr); 351757cd149SLubomir Rintel if (ret) { 352757cd149SLubomir Rintel printf("bcm2835: Could not query board serial\n"); 353757cd149SLubomir Rintel /* Ignore error; not critical */ 354757cd149SLubomir Rintel return; 355757cd149SLubomir Rintel } 356757cd149SLubomir Rintel 357757cd149SLubomir Rintel snprintf(serial_string, sizeof(serial_string), "%016" PRIx64, 358757cd149SLubomir Rintel msg->get_board_serial.body.resp.serial); 359382bee57SSimon Glass env_set("serial#", serial_string); 360757cd149SLubomir Rintel } 361757cd149SLubomir Rintel 3629316e144SStephen Warren int misc_init_r(void) 3639316e144SStephen Warren { 364ade243a2SCédric Schieli set_fdt_addr(); 3659316e144SStephen Warren set_fdtfile(); 3669316e144SStephen Warren set_usbethaddr(); 367bff78567SGuillaume GARDET #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG 368bff78567SGuillaume GARDET set_board_info(); 369bff78567SGuillaume GARDET #endif 370757cd149SLubomir Rintel set_serial_number(); 371757cd149SLubomir Rintel 3729316e144SStephen Warren return 0; 3739316e144SStephen Warren } 3749316e144SStephen Warren 3759316e144SStephen Warren static void get_board_rev(void) 3769316e144SStephen Warren { 377927753aeSAlexander Stein ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_board_rev, msg, 1); 3789316e144SStephen Warren int ret; 379c4ea1edbSStephen Warren const struct rpi_model *models; 380c4ea1edbSStephen Warren uint32_t models_count; 3819316e144SStephen Warren 3829316e144SStephen Warren BCM2835_MBOX_INIT_HDR(msg); 3839316e144SStephen Warren BCM2835_MBOX_INIT_TAG(&msg->get_board_rev, GET_BOARD_REV); 3849316e144SStephen Warren 3859316e144SStephen Warren ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr); 3869316e144SStephen Warren if (ret) { 3879316e144SStephen Warren printf("bcm2835: Could not query board revision\n"); 3889316e144SStephen Warren /* Ignore error; not critical */ 3899316e144SStephen Warren return; 3909316e144SStephen Warren } 3919316e144SStephen Warren 39246414296SStephen Warren /* 39346414296SStephen Warren * For details of old-vs-new scheme, see: 39446414296SStephen Warren * https://github.com/pimoroni/RPi.version/blob/master/RPi/version.py 39546414296SStephen Warren * http://www.raspberrypi.org/forums/viewtopic.php?f=63&t=99293&p=690282 39646414296SStephen Warren * (a few posts down) 39795b4f112SStephen Warren * 39895b4f112SStephen Warren * For the RPi 1, bit 24 is the "warranty bit", so we mask off just the 39995b4f112SStephen Warren * lower byte to use as the board rev: 40095b4f112SStephen Warren * http://www.raspberrypi.org/forums/viewtopic.php?f=63&t=98367&start=250 40195b4f112SStephen Warren * http://www.raspberrypi.org/forums/viewtopic.php?f=31&t=20594 40246414296SStephen Warren */ 403c4ea1edbSStephen Warren revision = msg->get_board_rev.body.resp.rev; 404c4ea1edbSStephen Warren if (revision & 0x800000) { 405c4ea1edbSStephen Warren rev_scheme = 1; 406c4ea1edbSStephen Warren rev_type = (revision >> 4) & 0xff; 407c4ea1edbSStephen Warren models = rpi_models_new_scheme; 408c4ea1edbSStephen Warren models_count = ARRAY_SIZE(rpi_models_new_scheme); 409c4ea1edbSStephen Warren } else { 410c4ea1edbSStephen Warren rev_scheme = 0; 411c4ea1edbSStephen Warren rev_type = revision & 0xff; 412c4ea1edbSStephen Warren models = rpi_models_old_scheme; 413c4ea1edbSStephen Warren models_count = ARRAY_SIZE(rpi_models_old_scheme); 41447705effSStephen Warren } 415c4ea1edbSStephen Warren if (rev_type >= models_count) { 416c4ea1edbSStephen Warren printf("RPI: Board rev 0x%x outside known range\n", rev_type); 417c4ea1edbSStephen Warren model = &rpi_model_unknown; 418c4ea1edbSStephen Warren } else if (!models[rev_type].name) { 419c4ea1edbSStephen Warren printf("RPI: Board rev 0x%x unknown\n", rev_type); 420c4ea1edbSStephen Warren model = &rpi_model_unknown; 421c4ea1edbSStephen Warren } else { 422c4ea1edbSStephen Warren model = &models[rev_type]; 423914627feSStephen Warren } 4249316e144SStephen Warren 425c4ea1edbSStephen Warren printf("RPI %s (0x%x)\n", model->name, revision); 4269316e144SStephen Warren } 4279316e144SStephen Warren 428d8396a32SFabian Vogt int board_init(void) 429601147b0SAlexander Graf { 43045a6d231SPaolo Pisati #ifdef CONFIG_HW_WATCHDOG 43145a6d231SPaolo Pisati hw_watchdog_init(); 43245a6d231SPaolo Pisati #endif 433601147b0SAlexander Graf 434d8396a32SFabian Vogt get_board_rev(); 435d8396a32SFabian Vogt 436d8396a32SFabian Vogt gd->bd->bi_boot_params = 0x100; 437d8396a32SFabian Vogt 43870997d88SSimon Glass return bcm2835_power_on_module(BCM2835_MBOX_POWER_DEVID_USB_HCD); 439601147b0SAlexander Graf } 440601147b0SAlexander Graf 44182f766d1SAlex Deymo /* 44282f766d1SAlex Deymo * If the firmware passed a device tree use it for U-Boot. 44382f766d1SAlex Deymo */ 44482f766d1SAlex Deymo void *board_fdt_blob_setup(void) 44582f766d1SAlex Deymo { 44682f766d1SAlex Deymo if (fdt_magic(fw_dtb_pointer) != FDT_MAGIC) 44782f766d1SAlex Deymo return NULL; 44882f766d1SAlex Deymo return (void *)fw_dtb_pointer; 44982f766d1SAlex Deymo } 45082f766d1SAlex Deymo 4519316e144SStephen Warren int ft_board_setup(void *blob, bd_t *bd) 4529316e144SStephen Warren { 4539316e144SStephen Warren /* 4549316e144SStephen Warren * For now, we simply always add the simplefb DT node. Later, we 4559316e144SStephen Warren * should be more intelligent, and e.g. only do this if no enabled DT 4569316e144SStephen Warren * node exists for the "real" graphics driver. 4579316e144SStephen Warren */ 4589316e144SStephen Warren lcd_dt_simplefb_add_node(blob); 4599316e144SStephen Warren 4601bcf7a30SAlexander Graf #ifdef CONFIG_EFI_LOADER 4611bcf7a30SAlexander Graf /* Reserve the spin table */ 4621bcf7a30SAlexander Graf efi_add_memory_map(0, 1, EFI_RESERVED_MEMORY_TYPE, 0); 4631bcf7a30SAlexander Graf #endif 4641bcf7a30SAlexander Graf 4659316e144SStephen Warren return 0; 4669316e144SStephen Warren } 467