blob: 649127c5bf06828029e8defc57ea0eadc67a6ee4 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Stephen Warren0e012c32012-08-05 16:07:22 +00002/*
Stephen Warrend6f47c82016-03-24 22:15:20 -06003 * (C) Copyright 2012-2016 Stephen Warren
Stephen Warren0e012c32012-08-05 16:07:22 +00004 */
5
6#include <common.h>
Stephen Warrenaa44d532013-05-27 18:31:18 +00007#include <config.h>
Simon Glass74807622014-09-22 17:30:56 -06008#include <dm.h>
Alex Kiernan9c215492018-04-01 09:22:38 +00009#include <environment.h>
Alexander Graf013e9ae2016-11-02 10:36:20 +010010#include <efi_loader.h>
Jeroen Hofsteed5b2fed2014-07-13 22:01:51 +020011#include <fdt_support.h>
Nikita Kiryanovb071e4c2015-02-03 13:32:31 +020012#include <fdt_simplefb.h>
Stephen Warrenaa44d532013-05-27 18:31:18 +000013#include <lcd.h>
Simon Glass2dd337a2015-09-02 17:24:58 -060014#include <memalign.h>
Jeroen Hofsteed5b2fed2014-07-13 22:01:51 +020015#include <mmc.h>
Simon Glass74807622014-09-22 17:30:56 -060016#include <asm/gpio.h>
Stephen Warrenacc8bf42013-01-29 16:37:37 +000017#include <asm/arch/mbox.h>
Simon Glass558ec672017-04-05 16:23:36 -060018#include <asm/arch/msg.h>
Stephen Warrenc4ab9712013-01-29 16:37:42 +000019#include <asm/arch/sdhci.h>
Stephen Warren0e012c32012-08-05 16:07:22 +000020#include <asm/global_data.h>
Stephen Warrend6f47c82016-03-24 22:15:20 -060021#include <dm/platform_data/serial_bcm283x_mu.h>
Stephen Warren93ea5262016-04-01 21:14:15 -060022#ifdef CONFIG_ARM64
23#include <asm/armv8/mmu.h>
24#endif
Paolo Pisati6213c552017-02-10 17:28:05 +010025#include <watchdog.h>
Alexander Graffce8e5c2018-01-23 18:05:21 +010026#include <dm/pinctrl.h>
Stephen Warren0e012c32012-08-05 16:07:22 +000027
28DECLARE_GLOBAL_DATA_PTR;
29
Cédric Schieli9473f532016-11-11 11:59:07 +010030/* From lowlevel_init.S */
31extern unsigned long fw_dtb_pointer;
32
Simon Glass56991cd2017-04-05 16:23:45 -060033/* TODO(sjg@chromium.org): Move these to the msg.c file */
Stephen Warrenacc8bf42013-01-29 16:37:37 +000034struct msg_get_arm_mem {
35 struct bcm2835_mbox_hdr hdr;
36 struct bcm2835_mbox_tag_get_arm_mem get_arm_mem;
37 u32 end_tag;
38};
39
Stephen Warrencd210c12014-11-18 21:40:21 -070040struct msg_get_board_rev {
41 struct bcm2835_mbox_hdr hdr;
42 struct bcm2835_mbox_tag_get_board_rev get_board_rev;
43 u32 end_tag;
44};
45
Lubomir Rintel7d33bb62016-02-22 22:06:47 +010046struct msg_get_board_serial {
47 struct bcm2835_mbox_hdr hdr;
48 struct bcm2835_mbox_tag_get_board_serial get_board_serial;
49 u32 end_tag;
50};
51
Stephen Warrenaf6e20d2014-09-26 20:51:39 -060052struct msg_get_mac_address {
53 struct bcm2835_mbox_hdr hdr;
54 struct bcm2835_mbox_tag_get_mac_address get_mac_address;
55 u32 end_tag;
56};
57
Stephen Warrenc4ab9712013-01-29 16:37:42 +000058struct msg_get_clock_rate {
59 struct bcm2835_mbox_hdr hdr;
60 struct bcm2835_mbox_tag_get_clock_rate get_clock_rate;
61 u32 end_tag;
62};
63
Tuomas Tynkkynen9266d1d2017-01-23 01:34:39 +020064#ifdef CONFIG_ARM64
65#define DTB_DIR "broadcom/"
66#else
67#define DTB_DIR ""
68#endif
69
Stephen Warrenbe8efec2015-12-04 22:07:44 -070070/*
71 * http://raspberryalphaomega.org.uk/2013/02/06/automatic-raspberry-pi-board-revision-detection-model-a-b1-and-b2/
72 * http://www.raspberrypi.org/forums/viewtopic.php?f=63&t=32733
Stephen Warren26683852015-12-04 22:07:45 -070073 * http://git.drogon.net/?p=wiringPi;a=blob;f=wiringPi/wiringPi.c;h=503151f61014418b9c42f4476a6086f75cd4e64b;hb=refs/heads/master#l922
Stephen Warrena33dc8b2016-01-28 22:24:44 -070074 *
75 * In http://lists.denx.de/pipermail/u-boot/2016-January/243752.html
76 * ("[U-Boot] [PATCH] rpi: fix up Model B entries") Dom Cobley at the RPi
77 * Foundation stated that the following source was accurate:
78 * https://github.com/AndrewFromMelbourne/raspberry_pi_revision
Stephen Warrenbe8efec2015-12-04 22:07:44 -070079 */
Stephen Warren26683852015-12-04 22:07:45 -070080struct rpi_model {
Stephen Warrencd210c12014-11-18 21:40:21 -070081 const char *name;
82 const char *fdtfile;
Stephen Warrenb2fa38362014-12-05 20:56:46 -070083 bool has_onboard_eth;
Stephen Warren26683852015-12-04 22:07:45 -070084};
85
86static const struct rpi_model rpi_model_unknown = {
87 "Unknown model",
Tuomas Tynkkynen9266d1d2017-01-23 01:34:39 +020088 DTB_DIR "bcm283x-rpi-other.dtb",
Stephen Warren26683852015-12-04 22:07:45 -070089 false,
90};
91
92static const struct rpi_model rpi_models_new_scheme[] = {
Jonathan Grayde4524b2018-04-06 18:45:49 +100093 [0x0] = {
94 "Model A",
95 DTB_DIR "bcm2835-rpi-a.dtb",
96 false,
97 },
98 [0x1] = {
99 "Model B",
100 DTB_DIR "bcm2835-rpi-b.dtb",
101 true,
102 },
103 [0x2] = {
104 "Model A+",
105 DTB_DIR "bcm2835-rpi-a-plus.dtb",
106 false,
107 },
108 [0x3] = {
109 "Model B+",
110 DTB_DIR "bcm2835-rpi-b-plus.dtb",
111 true,
112 },
Stephen Warrenbe8efec2015-12-04 22:07:44 -0700113 [0x4] = {
Stephen Warrendc7ea682015-02-16 12:16:15 -0700114 "2 Model B",
Tuomas Tynkkynen9266d1d2017-01-23 01:34:39 +0200115 DTB_DIR "bcm2836-rpi-2-b.dtb",
Stephen Warrendc7ea682015-02-16 12:16:15 -0700116 true,
117 },
Jonathan Grayde4524b2018-04-06 18:45:49 +1000118 [0x6] = {
119 "Compute Module",
120 DTB_DIR "bcm2835-rpi-cm.dtb",
121 false,
122 },
Stephen Warren303244a2016-03-24 22:15:18 -0600123 [0x8] = {
124 "3 Model B",
Tuomas Tynkkynen9266d1d2017-01-23 01:34:39 +0200125 DTB_DIR "bcm2837-rpi-3-b.dtb",
Stephen Warren303244a2016-03-24 22:15:18 -0600126 true,
127 },
Stephen Warren2f1f20b2015-12-04 22:07:46 -0700128 [0x9] = {
129 "Zero",
Tuomas Tynkkynen9266d1d2017-01-23 01:34:39 +0200130 DTB_DIR "bcm2835-rpi-zero.dtb",
Stephen Warren2f1f20b2015-12-04 22:07:46 -0700131 false,
132 },
Jonathan Grayde4524b2018-04-06 18:45:49 +1000133 [0xA] = {
134 "Compute Module 3",
135 DTB_DIR "bcm2837-rpi-cm3.dtb",
136 false,
137 },
Dmitry Korunov3f887412017-11-26 13:38:53 +0400138 [0xC] = {
139 "Zero W",
140 DTB_DIR "bcm2835-rpi-zero-w.dtb",
141 false,
142 },
Alexander Grafd0043a02018-03-15 15:05:37 +0100143 [0xD] = {
144 "3 Model B+",
145 DTB_DIR "bcm2837-rpi-3-b-plus.dtb",
146 true,
147 },
Stephen Warren26683852015-12-04 22:07:45 -0700148};
149
150static const struct rpi_model rpi_models_old_scheme[] = {
Stephen Warrenbe8efec2015-12-04 22:07:44 -0700151 [0x2] = {
Lubomir Rintelc44f76e2016-01-29 09:35:52 +0100152 "Model B",
Tuomas Tynkkynen9266d1d2017-01-23 01:34:39 +0200153 DTB_DIR "bcm2835-rpi-b.dtb",
Stephen Warrenb2fa38362014-12-05 20:56:46 -0700154 true,
Stephen Warrencd210c12014-11-18 21:40:21 -0700155 },
Stephen Warrenbe8efec2015-12-04 22:07:44 -0700156 [0x3] = {
Lubomir Rintelc44f76e2016-01-29 09:35:52 +0100157 "Model B",
Tuomas Tynkkynen9266d1d2017-01-23 01:34:39 +0200158 DTB_DIR "bcm2835-rpi-b.dtb",
Stephen Warrenb2fa38362014-12-05 20:56:46 -0700159 true,
Stephen Warrencd210c12014-11-18 21:40:21 -0700160 },
Stephen Warrenbe8efec2015-12-04 22:07:44 -0700161 [0x4] = {
Lubomir Rintelc44f76e2016-01-29 09:35:52 +0100162 "Model B rev2",
Tuomas Tynkkynen9266d1d2017-01-23 01:34:39 +0200163 DTB_DIR "bcm2835-rpi-b-rev2.dtb",
Stephen Warrenb2fa38362014-12-05 20:56:46 -0700164 true,
Stephen Warrencd210c12014-11-18 21:40:21 -0700165 },
Stephen Warrenbe8efec2015-12-04 22:07:44 -0700166 [0x5] = {
Lubomir Rintelc44f76e2016-01-29 09:35:52 +0100167 "Model B rev2",
Tuomas Tynkkynen9266d1d2017-01-23 01:34:39 +0200168 DTB_DIR "bcm2835-rpi-b-rev2.dtb",
Stephen Warrenb2fa38362014-12-05 20:56:46 -0700169 true,
Stephen Warrencd210c12014-11-18 21:40:21 -0700170 },
Stephen Warrenbe8efec2015-12-04 22:07:44 -0700171 [0x6] = {
Lubomir Rintelc44f76e2016-01-29 09:35:52 +0100172 "Model B rev2",
Tuomas Tynkkynen9266d1d2017-01-23 01:34:39 +0200173 DTB_DIR "bcm2835-rpi-b-rev2.dtb",
Stephen Warrenb2fa38362014-12-05 20:56:46 -0700174 true,
Stephen Warrencd210c12014-11-18 21:40:21 -0700175 },
Stephen Warrenbe8efec2015-12-04 22:07:44 -0700176 [0x7] = {
Stephen Warrencd210c12014-11-18 21:40:21 -0700177 "Model A",
Tuomas Tynkkynen9266d1d2017-01-23 01:34:39 +0200178 DTB_DIR "bcm2835-rpi-a.dtb",
Stephen Warrenb2fa38362014-12-05 20:56:46 -0700179 false,
Stephen Warrencd210c12014-11-18 21:40:21 -0700180 },
Stephen Warrenbe8efec2015-12-04 22:07:44 -0700181 [0x8] = {
Stephen Warrencd210c12014-11-18 21:40:21 -0700182 "Model A",
Tuomas Tynkkynen9266d1d2017-01-23 01:34:39 +0200183 DTB_DIR "bcm2835-rpi-a.dtb",
Stephen Warrenb2fa38362014-12-05 20:56:46 -0700184 false,
Stephen Warrencd210c12014-11-18 21:40:21 -0700185 },
Stephen Warrenbe8efec2015-12-04 22:07:44 -0700186 [0x9] = {
Stephen Warrencd210c12014-11-18 21:40:21 -0700187 "Model A",
Tuomas Tynkkynen9266d1d2017-01-23 01:34:39 +0200188 DTB_DIR "bcm2835-rpi-a.dtb",
Stephen Warrenb2fa38362014-12-05 20:56:46 -0700189 false,
Stephen Warrencd210c12014-11-18 21:40:21 -0700190 },
Stephen Warrenbe8efec2015-12-04 22:07:44 -0700191 [0xd] = {
Stephen Warrencd210c12014-11-18 21:40:21 -0700192 "Model B rev2",
Tuomas Tynkkynen9266d1d2017-01-23 01:34:39 +0200193 DTB_DIR "bcm2835-rpi-b-rev2.dtb",
Stephen Warrenb2fa38362014-12-05 20:56:46 -0700194 true,
Stephen Warrencd210c12014-11-18 21:40:21 -0700195 },
Stephen Warrenbe8efec2015-12-04 22:07:44 -0700196 [0xe] = {
Stephen Warrencd210c12014-11-18 21:40:21 -0700197 "Model B rev2",
Tuomas Tynkkynen9266d1d2017-01-23 01:34:39 +0200198 DTB_DIR "bcm2835-rpi-b-rev2.dtb",
Stephen Warrenb2fa38362014-12-05 20:56:46 -0700199 true,
Stephen Warrencd210c12014-11-18 21:40:21 -0700200 },
Stephen Warrenbe8efec2015-12-04 22:07:44 -0700201 [0xf] = {
Stephen Warrencd210c12014-11-18 21:40:21 -0700202 "Model B rev2",
Tuomas Tynkkynen9266d1d2017-01-23 01:34:39 +0200203 DTB_DIR "bcm2835-rpi-b-rev2.dtb",
Stephen Warrenb2fa38362014-12-05 20:56:46 -0700204 true,
Stephen Warrencd210c12014-11-18 21:40:21 -0700205 },
Stephen Warrenbe8efec2015-12-04 22:07:44 -0700206 [0x10] = {
Stephen Warrencd210c12014-11-18 21:40:21 -0700207 "Model B+",
Tuomas Tynkkynen9266d1d2017-01-23 01:34:39 +0200208 DTB_DIR "bcm2835-rpi-b-plus.dtb",
Stephen Warrenb2fa38362014-12-05 20:56:46 -0700209 true,
Stephen Warrencd210c12014-11-18 21:40:21 -0700210 },
Stephen Warrenbe8efec2015-12-04 22:07:44 -0700211 [0x11] = {
Stephen Warrencd210c12014-11-18 21:40:21 -0700212 "Compute Module",
Tuomas Tynkkynen9266d1d2017-01-23 01:34:39 +0200213 DTB_DIR "bcm2835-rpi-cm.dtb",
Stephen Warrenb2fa38362014-12-05 20:56:46 -0700214 false,
Stephen Warrencd210c12014-11-18 21:40:21 -0700215 },
Stephen Warrenbe8efec2015-12-04 22:07:44 -0700216 [0x12] = {
Stephen Warren18a5fc62014-12-23 20:01:43 -0700217 "Model A+",
Tuomas Tynkkynen9266d1d2017-01-23 01:34:39 +0200218 DTB_DIR "bcm2835-rpi-a-plus.dtb",
Stephen Warren18a5fc62014-12-23 20:01:43 -0700219 false,
220 },
Stephen Warrenbe8efec2015-12-04 22:07:44 -0700221 [0x13] = {
Stephen Warren3648a852015-04-12 21:43:25 -0600222 "Model B+",
Tuomas Tynkkynen9266d1d2017-01-23 01:34:39 +0200223 DTB_DIR "bcm2835-rpi-b-plus.dtb",
Stephen Warren3648a852015-04-12 21:43:25 -0600224 true,
225 },
Stephen Warrenbe8efec2015-12-04 22:07:44 -0700226 [0x14] = {
Stephen Warren3648a852015-04-12 21:43:25 -0600227 "Compute Module",
Tuomas Tynkkynen9266d1d2017-01-23 01:34:39 +0200228 DTB_DIR "bcm2835-rpi-cm.dtb",
Stephen Warren3648a852015-04-12 21:43:25 -0600229 false,
230 },
Stephen Warrenbe8efec2015-12-04 22:07:44 -0700231 [0x15] = {
Lubomir Rintelc87458c2015-10-14 17:17:54 +0200232 "Model A+",
Tuomas Tynkkynen9266d1d2017-01-23 01:34:39 +0200233 DTB_DIR "bcm2835-rpi-a-plus.dtb",
Lubomir Rintelc87458c2015-10-14 17:17:54 +0200234 false,
235 },
Stephen Warrencd210c12014-11-18 21:40:21 -0700236};
237
Stephen Warren26683852015-12-04 22:07:45 -0700238static uint32_t revision;
239static uint32_t rev_scheme;
240static uint32_t rev_type;
241static const struct rpi_model *model;
Stephen Warrencd210c12014-11-18 21:40:21 -0700242
Stephen Warren93ea5262016-04-01 21:14:15 -0600243#ifdef CONFIG_ARM64
244static struct mm_region bcm2837_mem_map[] = {
245 {
York Sunc7104e52016-06-24 16:46:22 -0700246 .virt = 0x00000000UL,
247 .phys = 0x00000000UL,
Stephen Warren93ea5262016-04-01 21:14:15 -0600248 .size = 0x3f000000UL,
249 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
250 PTE_BLOCK_INNER_SHARE
251 }, {
York Sunc7104e52016-06-24 16:46:22 -0700252 .virt = 0x3f000000UL,
253 .phys = 0x3f000000UL,
Stephen Warren93ea5262016-04-01 21:14:15 -0600254 .size = 0x01000000UL,
255 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
256 PTE_BLOCK_NON_SHARE |
257 PTE_BLOCK_PXN | PTE_BLOCK_UXN
258 }, {
259 /* List terminator */
260 0,
261 }
262};
263
264struct mm_region *mem_map = bcm2837_mem_map;
265#endif
266
Stephen Warren0e012c32012-08-05 16:07:22 +0000267int dram_init(void)
268{
Alexander Steinc56c9472015-07-24 09:22:12 +0200269 ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_arm_mem, msg, 1);
Stephen Warrenacc8bf42013-01-29 16:37:37 +0000270 int ret;
271
272 BCM2835_MBOX_INIT_HDR(msg);
273 BCM2835_MBOX_INIT_TAG(&msg->get_arm_mem, GET_ARM_MEMORY);
274
275 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr);
276 if (ret) {
277 printf("bcm2835: Could not query ARM memory size\n");
278 return -1;
279 }
280
281 gd->ram_size = msg->get_arm_mem.body.resp.mem_size;
Stephen Warren0e012c32012-08-05 16:07:22 +0000282
283 return 0;
284}
285
Stephen Warrencd210c12014-11-18 21:40:21 -0700286static void set_fdtfile(void)
287{
288 const char *fdtfile;
289
Simon Glass64b723f2017-08-03 12:22:12 -0600290 if (env_get("fdtfile"))
Stephen Warrencd210c12014-11-18 21:40:21 -0700291 return;
292
Stephen Warren26683852015-12-04 22:07:45 -0700293 fdtfile = model->fdtfile;
Simon Glass6a38e412017-08-03 12:22:09 -0600294 env_set("fdtfile", fdtfile);
Stephen Warrencd210c12014-11-18 21:40:21 -0700295}
296
Cédric Schieli9473f532016-11-11 11:59:07 +0100297/*
298 * If the firmware provided a valid FDT at boot time, let's expose it in
299 * ${fdt_addr} so it may be passed unmodified to the kernel.
300 */
301static void set_fdt_addr(void)
302{
Simon Glass64b723f2017-08-03 12:22:12 -0600303 if (env_get("fdt_addr"))
Cédric Schieli9473f532016-11-11 11:59:07 +0100304 return;
305
306 if (fdt_magic(fw_dtb_pointer) != FDT_MAGIC)
307 return;
308
Simon Glass4d949a22017-08-03 12:22:10 -0600309 env_set_hex("fdt_addr", fw_dtb_pointer);
Cédric Schieli9473f532016-11-11 11:59:07 +0100310}
311
312/*
313 * Prevent relocation from stomping on a firmware provided FDT blob.
314 */
315unsigned long board_get_usable_ram_top(unsigned long total_size)
316{
317 if ((gd->ram_top - fw_dtb_pointer) > SZ_64M)
318 return gd->ram_top;
319 return fw_dtb_pointer & ~0xffff;
320}
321
Stephen Warrencd210c12014-11-18 21:40:21 -0700322static void set_usbethaddr(void)
Stephen Warrenaf6e20d2014-09-26 20:51:39 -0600323{
Alexander Steinc56c9472015-07-24 09:22:12 +0200324 ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_mac_address, msg, 1);
Stephen Warrenaf6e20d2014-09-26 20:51:39 -0600325 int ret;
326
Stephen Warren26683852015-12-04 22:07:45 -0700327 if (!model->has_onboard_eth)
Stephen Warrenb2fa38362014-12-05 20:56:46 -0700328 return;
329
Simon Glass64b723f2017-08-03 12:22:12 -0600330 if (env_get("usbethaddr"))
Stephen Warrencd210c12014-11-18 21:40:21 -0700331 return;
Stephen Warrenaf6e20d2014-09-26 20:51:39 -0600332
333 BCM2835_MBOX_INIT_HDR(msg);
334 BCM2835_MBOX_INIT_TAG(&msg->get_mac_address, GET_MAC_ADDRESS);
335
336 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr);
337 if (ret) {
338 printf("bcm2835: Could not query MAC address\n");
339 /* Ignore error; not critical */
Stephen Warrencd210c12014-11-18 21:40:21 -0700340 return;
Stephen Warrenaf6e20d2014-09-26 20:51:39 -0600341 }
342
Simon Glass8551d552017-08-03 12:22:11 -0600343 eth_env_set_enetaddr("usbethaddr", msg->get_mac_address.body.resp.mac);
Stephen Warrenaf6e20d2014-09-26 20:51:39 -0600344
Simon Glass64b723f2017-08-03 12:22:12 -0600345 if (!env_get("ethaddr"))
346 env_set("ethaddr", env_get("usbethaddr"));
Lubomir Rintel3ac09f82016-02-03 16:08:09 +0100347
Stephen Warrencd210c12014-11-18 21:40:21 -0700348 return;
349}
350
Guillaume GARDET25fa8602015-08-25 15:10:26 +0200351#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
352static void set_board_info(void)
353{
Stephen Warren26683852015-12-04 22:07:45 -0700354 char s[11];
355
356 snprintf(s, sizeof(s), "0x%X", revision);
Simon Glass6a38e412017-08-03 12:22:09 -0600357 env_set("board_revision", s);
Stephen Warren26683852015-12-04 22:07:45 -0700358 snprintf(s, sizeof(s), "%d", rev_scheme);
Simon Glass6a38e412017-08-03 12:22:09 -0600359 env_set("board_rev_scheme", s);
Stephen Warren26683852015-12-04 22:07:45 -0700360 /* Can't rename this to board_rev_type since it's an ABI for scripts */
361 snprintf(s, sizeof(s), "0x%X", rev_type);
Simon Glass6a38e412017-08-03 12:22:09 -0600362 env_set("board_rev", s);
363 env_set("board_name", model->name);
Guillaume GARDET25fa8602015-08-25 15:10:26 +0200364}
365#endif /* CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG */
366
Lubomir Rintel7d33bb62016-02-22 22:06:47 +0100367static void set_serial_number(void)
368{
369 ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_board_serial, msg, 1);
370 int ret;
371 char serial_string[17] = { 0 };
372
Simon Glass64b723f2017-08-03 12:22:12 -0600373 if (env_get("serial#"))
Lubomir Rintel7d33bb62016-02-22 22:06:47 +0100374 return;
375
376 BCM2835_MBOX_INIT_HDR(msg);
377 BCM2835_MBOX_INIT_TAG_NO_REQ(&msg->get_board_serial, GET_BOARD_SERIAL);
378
379 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr);
380 if (ret) {
381 printf("bcm2835: Could not query board serial\n");
382 /* Ignore error; not critical */
383 return;
384 }
385
Masahiro Yamadac7570a32018-08-06 20:47:40 +0900386 snprintf(serial_string, sizeof(serial_string), "%016llx",
Lubomir Rintel7d33bb62016-02-22 22:06:47 +0100387 msg->get_board_serial.body.resp.serial);
Simon Glass6a38e412017-08-03 12:22:09 -0600388 env_set("serial#", serial_string);
Lubomir Rintel7d33bb62016-02-22 22:06:47 +0100389}
390
Stephen Warrencd210c12014-11-18 21:40:21 -0700391int misc_init_r(void)
392{
Cédric Schieli9473f532016-11-11 11:59:07 +0100393 set_fdt_addr();
Stephen Warrencd210c12014-11-18 21:40:21 -0700394 set_fdtfile();
395 set_usbethaddr();
Guillaume GARDET25fa8602015-08-25 15:10:26 +0200396#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
397 set_board_info();
398#endif
Lubomir Rintel7d33bb62016-02-22 22:06:47 +0100399 set_serial_number();
400
Stephen Warrenaf6e20d2014-09-26 20:51:39 -0600401 return 0;
402}
403
Stephen Warrencd210c12014-11-18 21:40:21 -0700404static void get_board_rev(void)
405{
Alexander Steinc56c9472015-07-24 09:22:12 +0200406 ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_board_rev, msg, 1);
Stephen Warrencd210c12014-11-18 21:40:21 -0700407 int ret;
Stephen Warren26683852015-12-04 22:07:45 -0700408 const struct rpi_model *models;
409 uint32_t models_count;
Stephen Warrencd210c12014-11-18 21:40:21 -0700410
411 BCM2835_MBOX_INIT_HDR(msg);
412 BCM2835_MBOX_INIT_TAG(&msg->get_board_rev, GET_BOARD_REV);
413
414 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr);
415 if (ret) {
416 printf("bcm2835: Could not query board revision\n");
417 /* Ignore error; not critical */
418 return;
419 }
420
Stephen Warrendc7ea682015-02-16 12:16:15 -0700421 /*
422 * For details of old-vs-new scheme, see:
423 * https://github.com/pimoroni/RPi.version/blob/master/RPi/version.py
424 * http://www.raspberrypi.org/forums/viewtopic.php?f=63&t=99293&p=690282
425 * (a few posts down)
Stephen Warrenb834af82015-03-23 23:00:25 -0600426 *
427 * For the RPi 1, bit 24 is the "warranty bit", so we mask off just the
428 * lower byte to use as the board rev:
429 * http://www.raspberrypi.org/forums/viewtopic.php?f=63&t=98367&start=250
430 * http://www.raspberrypi.org/forums/viewtopic.php?f=31&t=20594
Stephen Warrendc7ea682015-02-16 12:16:15 -0700431 */
Stephen Warren26683852015-12-04 22:07:45 -0700432 revision = msg->get_board_rev.body.resp.rev;
433 if (revision & 0x800000) {
434 rev_scheme = 1;
435 rev_type = (revision >> 4) & 0xff;
436 models = rpi_models_new_scheme;
437 models_count = ARRAY_SIZE(rpi_models_new_scheme);
438 } else {
439 rev_scheme = 0;
440 rev_type = revision & 0xff;
441 models = rpi_models_old_scheme;
442 models_count = ARRAY_SIZE(rpi_models_old_scheme);
Stephen Warren18a5fc62014-12-23 20:01:43 -0700443 }
Stephen Warren26683852015-12-04 22:07:45 -0700444 if (rev_type >= models_count) {
445 printf("RPI: Board rev 0x%x outside known range\n", rev_type);
446 model = &rpi_model_unknown;
447 } else if (!models[rev_type].name) {
448 printf("RPI: Board rev 0x%x unknown\n", rev_type);
449 model = &rpi_model_unknown;
450 } else {
451 model = &models[rev_type];
Stephen Warren18a5fc62014-12-23 20:01:43 -0700452 }
Stephen Warrenc61dfd12014-12-23 20:01:44 -0700453
Stephen Warren26683852015-12-04 22:07:45 -0700454 printf("RPI %s (0x%x)\n", model->name, revision);
Stephen Warrencd210c12014-11-18 21:40:21 -0700455}
456
Fabian Vogt1d317b72016-09-26 14:26:50 +0200457int board_init(void)
Alexander Grafafb99072016-08-15 17:48:51 +0200458{
Paolo Pisati6213c552017-02-10 17:28:05 +0100459#ifdef CONFIG_HW_WATCHDOG
460 hw_watchdog_init();
461#endif
Alexander Grafafb99072016-08-15 17:48:51 +0200462
Fabian Vogt1d317b72016-09-26 14:26:50 +0200463 get_board_rev();
464
465 gd->bd->bi_boot_params = 0x100;
466
Simon Glass558ec672017-04-05 16:23:36 -0600467 return bcm2835_power_on_module(BCM2835_MBOX_POWER_DEVID_USB_HCD);
Alexander Grafafb99072016-08-15 17:48:51 +0200468}
469
Alex Deymo5b661ec2017-04-02 01:25:20 -0700470/*
471 * If the firmware passed a device tree use it for U-Boot.
472 */
473void *board_fdt_blob_setup(void)
474{
475 if (fdt_magic(fw_dtb_pointer) != FDT_MAGIC)
476 return NULL;
477 return (void *)fw_dtb_pointer;
478}
479
Simon Glass2aec3cc2014-10-23 18:58:47 -0600480int ft_board_setup(void *blob, bd_t *bd)
Stephen Warrenaa44d532013-05-27 18:31:18 +0000481{
482 /*
483 * For now, we simply always add the simplefb DT node. Later, we
484 * should be more intelligent, and e.g. only do this if no enabled DT
485 * node exists for the "real" graphics driver.
486 */
487 lcd_dt_simplefb_add_node(blob);
Simon Glass2aec3cc2014-10-23 18:58:47 -0600488
Alexander Graf013e9ae2016-11-02 10:36:20 +0100489#ifdef CONFIG_EFI_LOADER
490 /* Reserve the spin table */
491 efi_add_memory_map(0, 1, EFI_RESERVED_MEMORY_TYPE, 0);
492#endif
493
Simon Glass2aec3cc2014-10-23 18:58:47 -0600494 return 0;
Stephen Warrenaa44d532013-05-27 18:31:18 +0000495}