blob: 3d4afaf653aa9d6932f077c45faa9666eb030a56 [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>
Simon Glass313112a2019-08-01 09:46:46 -06009#include <env.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
Matthias Bruggerd75403d2019-11-19 16:01:02 +010030/* Assigned in lowlevel_init.S
31 * Push the variable into the .data section so that it
32 * does not get cleared later.
33 */
34unsigned long __section(".data") fw_dtb_pointer;
Cédric Schieli9473f532016-11-11 11:59:07 +010035
Simon Glass56991cd2017-04-05 16:23:45 -060036/* TODO(sjg@chromium.org): Move these to the msg.c file */
Stephen Warrenacc8bf42013-01-29 16:37:37 +000037struct msg_get_arm_mem {
38 struct bcm2835_mbox_hdr hdr;
39 struct bcm2835_mbox_tag_get_arm_mem get_arm_mem;
40 u32 end_tag;
41};
42
Stephen Warrencd210c12014-11-18 21:40:21 -070043struct msg_get_board_rev {
44 struct bcm2835_mbox_hdr hdr;
45 struct bcm2835_mbox_tag_get_board_rev get_board_rev;
46 u32 end_tag;
47};
48
Lubomir Rintel7d33bb62016-02-22 22:06:47 +010049struct msg_get_board_serial {
50 struct bcm2835_mbox_hdr hdr;
51 struct bcm2835_mbox_tag_get_board_serial get_board_serial;
52 u32 end_tag;
53};
54
Stephen Warrenaf6e20d2014-09-26 20:51:39 -060055struct msg_get_mac_address {
56 struct bcm2835_mbox_hdr hdr;
57 struct bcm2835_mbox_tag_get_mac_address get_mac_address;
58 u32 end_tag;
59};
60
Stephen Warrenc4ab9712013-01-29 16:37:42 +000061struct msg_get_clock_rate {
62 struct bcm2835_mbox_hdr hdr;
63 struct bcm2835_mbox_tag_get_clock_rate get_clock_rate;
64 u32 end_tag;
65};
66
Tuomas Tynkkynen9266d1d2017-01-23 01:34:39 +020067#ifdef CONFIG_ARM64
68#define DTB_DIR "broadcom/"
69#else
70#define DTB_DIR ""
71#endif
72
Stephen Warrenbe8efec2015-12-04 22:07:44 -070073/*
Jonathan Grayf3fb5542018-11-16 23:06:05 +110074 * https://www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md
Stephen Warrenbe8efec2015-12-04 22:07:44 -070075 */
Stephen Warren26683852015-12-04 22:07:45 -070076struct rpi_model {
Stephen Warrencd210c12014-11-18 21:40:21 -070077 const char *name;
78 const char *fdtfile;
Stephen Warrenb2fa38362014-12-05 20:56:46 -070079 bool has_onboard_eth;
Stephen Warren26683852015-12-04 22:07:45 -070080};
81
82static const struct rpi_model rpi_model_unknown = {
83 "Unknown model",
Tuomas Tynkkynen9266d1d2017-01-23 01:34:39 +020084 DTB_DIR "bcm283x-rpi-other.dtb",
Stephen Warren26683852015-12-04 22:07:45 -070085 false,
86};
87
88static const struct rpi_model rpi_models_new_scheme[] = {
Jonathan Grayde4524b2018-04-06 18:45:49 +100089 [0x0] = {
90 "Model A",
91 DTB_DIR "bcm2835-rpi-a.dtb",
92 false,
93 },
94 [0x1] = {
95 "Model B",
96 DTB_DIR "bcm2835-rpi-b.dtb",
97 true,
98 },
99 [0x2] = {
100 "Model A+",
101 DTB_DIR "bcm2835-rpi-a-plus.dtb",
102 false,
103 },
104 [0x3] = {
105 "Model B+",
106 DTB_DIR "bcm2835-rpi-b-plus.dtb",
107 true,
108 },
Stephen Warrenbe8efec2015-12-04 22:07:44 -0700109 [0x4] = {
Stephen Warrendc7ea682015-02-16 12:16:15 -0700110 "2 Model B",
Tuomas Tynkkynen9266d1d2017-01-23 01:34:39 +0200111 DTB_DIR "bcm2836-rpi-2-b.dtb",
Stephen Warrendc7ea682015-02-16 12:16:15 -0700112 true,
113 },
Jonathan Grayde4524b2018-04-06 18:45:49 +1000114 [0x6] = {
115 "Compute Module",
116 DTB_DIR "bcm2835-rpi-cm.dtb",
117 false,
118 },
Stephen Warren303244a2016-03-24 22:15:18 -0600119 [0x8] = {
120 "3 Model B",
Tuomas Tynkkynen9266d1d2017-01-23 01:34:39 +0200121 DTB_DIR "bcm2837-rpi-3-b.dtb",
Stephen Warren303244a2016-03-24 22:15:18 -0600122 true,
123 },
Stephen Warren2f1f20b2015-12-04 22:07:46 -0700124 [0x9] = {
125 "Zero",
Tuomas Tynkkynen9266d1d2017-01-23 01:34:39 +0200126 DTB_DIR "bcm2835-rpi-zero.dtb",
Stephen Warren2f1f20b2015-12-04 22:07:46 -0700127 false,
128 },
Jonathan Grayde4524b2018-04-06 18:45:49 +1000129 [0xA] = {
130 "Compute Module 3",
131 DTB_DIR "bcm2837-rpi-cm3.dtb",
132 false,
133 },
Dmitry Korunov3f887412017-11-26 13:38:53 +0400134 [0xC] = {
135 "Zero W",
136 DTB_DIR "bcm2835-rpi-zero-w.dtb",
137 false,
138 },
Alexander Grafd0043a02018-03-15 15:05:37 +0100139 [0xD] = {
140 "3 Model B+",
141 DTB_DIR "bcm2837-rpi-3-b-plus.dtb",
142 true,
143 },
Jonathan Grayed102552018-11-16 23:07:39 +1100144 [0xE] = {
145 "3 Model A+",
146 DTB_DIR "bcm2837-rpi-3-a-plus.dtb",
147 false,
148 },
Jonathan Gray765d34d2019-01-31 09:24:44 +1100149 [0x10] = {
150 "Compute Module 3+",
151 DTB_DIR "bcm2837-rpi-cm3.dtb",
152 false,
153 },
Andrei Gherzan2633ec82019-07-24 15:39:07 +0100154 [0x11] = {
155 "4 Model B",
156 DTB_DIR "bcm2711-rpi-4-b.dtb",
157 true,
158 },
Stephen Warren26683852015-12-04 22:07:45 -0700159};
160
161static const struct rpi_model rpi_models_old_scheme[] = {
Stephen Warrenbe8efec2015-12-04 22:07:44 -0700162 [0x2] = {
Lubomir Rintelc44f76e2016-01-29 09:35:52 +0100163 "Model B",
Tuomas Tynkkynen9266d1d2017-01-23 01:34:39 +0200164 DTB_DIR "bcm2835-rpi-b.dtb",
Stephen Warrenb2fa38362014-12-05 20:56:46 -0700165 true,
Stephen Warrencd210c12014-11-18 21:40:21 -0700166 },
Stephen Warrenbe8efec2015-12-04 22:07:44 -0700167 [0x3] = {
Lubomir Rintelc44f76e2016-01-29 09:35:52 +0100168 "Model B",
Tuomas Tynkkynen9266d1d2017-01-23 01:34:39 +0200169 DTB_DIR "bcm2835-rpi-b.dtb",
Stephen Warrenb2fa38362014-12-05 20:56:46 -0700170 true,
Stephen Warrencd210c12014-11-18 21:40:21 -0700171 },
Stephen Warrenbe8efec2015-12-04 22:07:44 -0700172 [0x4] = {
Lubomir Rintelc44f76e2016-01-29 09:35:52 +0100173 "Model B rev2",
Tuomas Tynkkynen9266d1d2017-01-23 01:34:39 +0200174 DTB_DIR "bcm2835-rpi-b-rev2.dtb",
Stephen Warrenb2fa38362014-12-05 20:56:46 -0700175 true,
Stephen Warrencd210c12014-11-18 21:40:21 -0700176 },
Stephen Warrenbe8efec2015-12-04 22:07:44 -0700177 [0x5] = {
Lubomir Rintelc44f76e2016-01-29 09:35:52 +0100178 "Model B rev2",
Tuomas Tynkkynen9266d1d2017-01-23 01:34:39 +0200179 DTB_DIR "bcm2835-rpi-b-rev2.dtb",
Stephen Warrenb2fa38362014-12-05 20:56:46 -0700180 true,
Stephen Warrencd210c12014-11-18 21:40:21 -0700181 },
Stephen Warrenbe8efec2015-12-04 22:07:44 -0700182 [0x6] = {
Lubomir Rintelc44f76e2016-01-29 09:35:52 +0100183 "Model B rev2",
Tuomas Tynkkynen9266d1d2017-01-23 01:34:39 +0200184 DTB_DIR "bcm2835-rpi-b-rev2.dtb",
Stephen Warrenb2fa38362014-12-05 20:56:46 -0700185 true,
Stephen Warrencd210c12014-11-18 21:40:21 -0700186 },
Stephen Warrenbe8efec2015-12-04 22:07:44 -0700187 [0x7] = {
Stephen Warrencd210c12014-11-18 21:40:21 -0700188 "Model A",
Tuomas Tynkkynen9266d1d2017-01-23 01:34:39 +0200189 DTB_DIR "bcm2835-rpi-a.dtb",
Stephen Warrenb2fa38362014-12-05 20:56:46 -0700190 false,
Stephen Warrencd210c12014-11-18 21:40:21 -0700191 },
Stephen Warrenbe8efec2015-12-04 22:07:44 -0700192 [0x8] = {
Stephen Warrencd210c12014-11-18 21:40:21 -0700193 "Model A",
Tuomas Tynkkynen9266d1d2017-01-23 01:34:39 +0200194 DTB_DIR "bcm2835-rpi-a.dtb",
Stephen Warrenb2fa38362014-12-05 20:56:46 -0700195 false,
Stephen Warrencd210c12014-11-18 21:40:21 -0700196 },
Stephen Warrenbe8efec2015-12-04 22:07:44 -0700197 [0x9] = {
Stephen Warrencd210c12014-11-18 21:40:21 -0700198 "Model A",
Tuomas Tynkkynen9266d1d2017-01-23 01:34:39 +0200199 DTB_DIR "bcm2835-rpi-a.dtb",
Stephen Warrenb2fa38362014-12-05 20:56:46 -0700200 false,
Stephen Warrencd210c12014-11-18 21:40:21 -0700201 },
Stephen Warrenbe8efec2015-12-04 22:07:44 -0700202 [0xd] = {
Stephen Warrencd210c12014-11-18 21:40:21 -0700203 "Model B rev2",
Tuomas Tynkkynen9266d1d2017-01-23 01:34:39 +0200204 DTB_DIR "bcm2835-rpi-b-rev2.dtb",
Stephen Warrenb2fa38362014-12-05 20:56:46 -0700205 true,
Stephen Warrencd210c12014-11-18 21:40:21 -0700206 },
Stephen Warrenbe8efec2015-12-04 22:07:44 -0700207 [0xe] = {
Stephen Warrencd210c12014-11-18 21:40:21 -0700208 "Model B rev2",
Tuomas Tynkkynen9266d1d2017-01-23 01:34:39 +0200209 DTB_DIR "bcm2835-rpi-b-rev2.dtb",
Stephen Warrenb2fa38362014-12-05 20:56:46 -0700210 true,
Stephen Warrencd210c12014-11-18 21:40:21 -0700211 },
Stephen Warrenbe8efec2015-12-04 22:07:44 -0700212 [0xf] = {
Stephen Warrencd210c12014-11-18 21:40:21 -0700213 "Model B rev2",
Tuomas Tynkkynen9266d1d2017-01-23 01:34:39 +0200214 DTB_DIR "bcm2835-rpi-b-rev2.dtb",
Stephen Warrenb2fa38362014-12-05 20:56:46 -0700215 true,
Stephen Warrencd210c12014-11-18 21:40:21 -0700216 },
Stephen Warrenbe8efec2015-12-04 22:07:44 -0700217 [0x10] = {
Stephen Warrencd210c12014-11-18 21:40:21 -0700218 "Model B+",
Tuomas Tynkkynen9266d1d2017-01-23 01:34:39 +0200219 DTB_DIR "bcm2835-rpi-b-plus.dtb",
Stephen Warrenb2fa38362014-12-05 20:56:46 -0700220 true,
Stephen Warrencd210c12014-11-18 21:40:21 -0700221 },
Stephen Warrenbe8efec2015-12-04 22:07:44 -0700222 [0x11] = {
Stephen Warrencd210c12014-11-18 21:40:21 -0700223 "Compute Module",
Tuomas Tynkkynen9266d1d2017-01-23 01:34:39 +0200224 DTB_DIR "bcm2835-rpi-cm.dtb",
Stephen Warrenb2fa38362014-12-05 20:56:46 -0700225 false,
Stephen Warrencd210c12014-11-18 21:40:21 -0700226 },
Stephen Warrenbe8efec2015-12-04 22:07:44 -0700227 [0x12] = {
Stephen Warren18a5fc62014-12-23 20:01:43 -0700228 "Model A+",
Tuomas Tynkkynen9266d1d2017-01-23 01:34:39 +0200229 DTB_DIR "bcm2835-rpi-a-plus.dtb",
Stephen Warren18a5fc62014-12-23 20:01:43 -0700230 false,
231 },
Stephen Warrenbe8efec2015-12-04 22:07:44 -0700232 [0x13] = {
Stephen Warren3648a852015-04-12 21:43:25 -0600233 "Model B+",
Tuomas Tynkkynen9266d1d2017-01-23 01:34:39 +0200234 DTB_DIR "bcm2835-rpi-b-plus.dtb",
Stephen Warren3648a852015-04-12 21:43:25 -0600235 true,
236 },
Stephen Warrenbe8efec2015-12-04 22:07:44 -0700237 [0x14] = {
Stephen Warren3648a852015-04-12 21:43:25 -0600238 "Compute Module",
Tuomas Tynkkynen9266d1d2017-01-23 01:34:39 +0200239 DTB_DIR "bcm2835-rpi-cm.dtb",
Stephen Warren3648a852015-04-12 21:43:25 -0600240 false,
241 },
Stephen Warrenbe8efec2015-12-04 22:07:44 -0700242 [0x15] = {
Lubomir Rintelc87458c2015-10-14 17:17:54 +0200243 "Model A+",
Tuomas Tynkkynen9266d1d2017-01-23 01:34:39 +0200244 DTB_DIR "bcm2835-rpi-a-plus.dtb",
Lubomir Rintelc87458c2015-10-14 17:17:54 +0200245 false,
246 },
Stephen Warrencd210c12014-11-18 21:40:21 -0700247};
248
Stephen Warren26683852015-12-04 22:07:45 -0700249static uint32_t revision;
250static uint32_t rev_scheme;
251static uint32_t rev_type;
252static const struct rpi_model *model;
Stephen Warrencd210c12014-11-18 21:40:21 -0700253
Stephen Warren0e012c32012-08-05 16:07:22 +0000254int dram_init(void)
255{
Alexander Steinc56c9472015-07-24 09:22:12 +0200256 ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_arm_mem, msg, 1);
Stephen Warrenacc8bf42013-01-29 16:37:37 +0000257 int ret;
258
259 BCM2835_MBOX_INIT_HDR(msg);
260 BCM2835_MBOX_INIT_TAG(&msg->get_arm_mem, GET_ARM_MEMORY);
261
262 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr);
263 if (ret) {
264 printf("bcm2835: Could not query ARM memory size\n");
265 return -1;
266 }
267
268 gd->ram_size = msg->get_arm_mem.body.resp.mem_size;
Stephen Warren0e012c32012-08-05 16:07:22 +0000269
270 return 0;
271}
272
Matthias Bruggerd3dcfe22019-09-09 18:31:56 +0200273#ifdef CONFIG_OF_BOARD
274#ifdef CONFIG_BCM2711
275int dram_init_banksize(void)
276{
277 return fdtdec_decode_ram_size(gd->fdt_blob, NULL, 0, NULL,
278 (phys_size_t *)&gd->ram_size, gd->bd);
279}
280#endif
281#endif
282
Stephen Warrencd210c12014-11-18 21:40:21 -0700283static void set_fdtfile(void)
284{
285 const char *fdtfile;
286
Simon Glass64b723f2017-08-03 12:22:12 -0600287 if (env_get("fdtfile"))
Stephen Warrencd210c12014-11-18 21:40:21 -0700288 return;
289
Stephen Warren26683852015-12-04 22:07:45 -0700290 fdtfile = model->fdtfile;
Simon Glass6a38e412017-08-03 12:22:09 -0600291 env_set("fdtfile", fdtfile);
Stephen Warrencd210c12014-11-18 21:40:21 -0700292}
293
Cédric Schieli9473f532016-11-11 11:59:07 +0100294/*
295 * If the firmware provided a valid FDT at boot time, let's expose it in
296 * ${fdt_addr} so it may be passed unmodified to the kernel.
297 */
298static void set_fdt_addr(void)
299{
Simon Glass64b723f2017-08-03 12:22:12 -0600300 if (env_get("fdt_addr"))
Cédric Schieli9473f532016-11-11 11:59:07 +0100301 return;
302
303 if (fdt_magic(fw_dtb_pointer) != FDT_MAGIC)
304 return;
305
Simon Glass4d949a22017-08-03 12:22:10 -0600306 env_set_hex("fdt_addr", fw_dtb_pointer);
Cédric Schieli9473f532016-11-11 11:59:07 +0100307}
308
309/*
310 * Prevent relocation from stomping on a firmware provided FDT blob.
311 */
312unsigned long board_get_usable_ram_top(unsigned long total_size)
313{
314 if ((gd->ram_top - fw_dtb_pointer) > SZ_64M)
315 return gd->ram_top;
316 return fw_dtb_pointer & ~0xffff;
317}
318
Stephen Warrencd210c12014-11-18 21:40:21 -0700319static void set_usbethaddr(void)
Stephen Warrenaf6e20d2014-09-26 20:51:39 -0600320{
Alexander Steinc56c9472015-07-24 09:22:12 +0200321 ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_mac_address, msg, 1);
Stephen Warrenaf6e20d2014-09-26 20:51:39 -0600322 int ret;
323
Stephen Warren26683852015-12-04 22:07:45 -0700324 if (!model->has_onboard_eth)
Stephen Warrenb2fa38362014-12-05 20:56:46 -0700325 return;
326
Simon Glass64b723f2017-08-03 12:22:12 -0600327 if (env_get("usbethaddr"))
Stephen Warrencd210c12014-11-18 21:40:21 -0700328 return;
Stephen Warrenaf6e20d2014-09-26 20:51:39 -0600329
330 BCM2835_MBOX_INIT_HDR(msg);
331 BCM2835_MBOX_INIT_TAG(&msg->get_mac_address, GET_MAC_ADDRESS);
332
333 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr);
334 if (ret) {
335 printf("bcm2835: Could not query MAC address\n");
336 /* Ignore error; not critical */
Stephen Warrencd210c12014-11-18 21:40:21 -0700337 return;
Stephen Warrenaf6e20d2014-09-26 20:51:39 -0600338 }
339
Simon Glass8551d552017-08-03 12:22:11 -0600340 eth_env_set_enetaddr("usbethaddr", msg->get_mac_address.body.resp.mac);
Stephen Warrenaf6e20d2014-09-26 20:51:39 -0600341
Simon Glass64b723f2017-08-03 12:22:12 -0600342 if (!env_get("ethaddr"))
343 env_set("ethaddr", env_get("usbethaddr"));
Lubomir Rintel3ac09f82016-02-03 16:08:09 +0100344
Stephen Warrencd210c12014-11-18 21:40:21 -0700345 return;
346}
347
Guillaume GARDET25fa8602015-08-25 15:10:26 +0200348#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
349static void set_board_info(void)
350{
Stephen Warren26683852015-12-04 22:07:45 -0700351 char s[11];
352
353 snprintf(s, sizeof(s), "0x%X", revision);
Simon Glass6a38e412017-08-03 12:22:09 -0600354 env_set("board_revision", s);
Stephen Warren26683852015-12-04 22:07:45 -0700355 snprintf(s, sizeof(s), "%d", rev_scheme);
Simon Glass6a38e412017-08-03 12:22:09 -0600356 env_set("board_rev_scheme", s);
Stephen Warren26683852015-12-04 22:07:45 -0700357 /* Can't rename this to board_rev_type since it's an ABI for scripts */
358 snprintf(s, sizeof(s), "0x%X", rev_type);
Simon Glass6a38e412017-08-03 12:22:09 -0600359 env_set("board_rev", s);
360 env_set("board_name", model->name);
Guillaume GARDET25fa8602015-08-25 15:10:26 +0200361}
362#endif /* CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG */
363
Lubomir Rintel7d33bb62016-02-22 22:06:47 +0100364static void set_serial_number(void)
365{
366 ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_board_serial, msg, 1);
367 int ret;
368 char serial_string[17] = { 0 };
369
Simon Glass64b723f2017-08-03 12:22:12 -0600370 if (env_get("serial#"))
Lubomir Rintel7d33bb62016-02-22 22:06:47 +0100371 return;
372
373 BCM2835_MBOX_INIT_HDR(msg);
374 BCM2835_MBOX_INIT_TAG_NO_REQ(&msg->get_board_serial, GET_BOARD_SERIAL);
375
376 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr);
377 if (ret) {
378 printf("bcm2835: Could not query board serial\n");
379 /* Ignore error; not critical */
380 return;
381 }
382
Masahiro Yamadac7570a32018-08-06 20:47:40 +0900383 snprintf(serial_string, sizeof(serial_string), "%016llx",
Lubomir Rintel7d33bb62016-02-22 22:06:47 +0100384 msg->get_board_serial.body.resp.serial);
Simon Glass6a38e412017-08-03 12:22:09 -0600385 env_set("serial#", serial_string);
Lubomir Rintel7d33bb62016-02-22 22:06:47 +0100386}
387
Stephen Warrencd210c12014-11-18 21:40:21 -0700388int misc_init_r(void)
389{
Cédric Schieli9473f532016-11-11 11:59:07 +0100390 set_fdt_addr();
Stephen Warrencd210c12014-11-18 21:40:21 -0700391 set_fdtfile();
392 set_usbethaddr();
Guillaume GARDET25fa8602015-08-25 15:10:26 +0200393#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
394 set_board_info();
395#endif
Lubomir Rintel7d33bb62016-02-22 22:06:47 +0100396 set_serial_number();
397
Stephen Warrenaf6e20d2014-09-26 20:51:39 -0600398 return 0;
399}
400
Stephen Warrencd210c12014-11-18 21:40:21 -0700401static void get_board_rev(void)
402{
Alexander Steinc56c9472015-07-24 09:22:12 +0200403 ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_board_rev, msg, 1);
Stephen Warrencd210c12014-11-18 21:40:21 -0700404 int ret;
Stephen Warren26683852015-12-04 22:07:45 -0700405 const struct rpi_model *models;
406 uint32_t models_count;
Stephen Warrencd210c12014-11-18 21:40:21 -0700407
408 BCM2835_MBOX_INIT_HDR(msg);
409 BCM2835_MBOX_INIT_TAG(&msg->get_board_rev, GET_BOARD_REV);
410
411 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr);
412 if (ret) {
413 printf("bcm2835: Could not query board revision\n");
414 /* Ignore error; not critical */
415 return;
416 }
417
Stephen Warrendc7ea682015-02-16 12:16:15 -0700418 /*
419 * For details of old-vs-new scheme, see:
420 * https://github.com/pimoroni/RPi.version/blob/master/RPi/version.py
421 * http://www.raspberrypi.org/forums/viewtopic.php?f=63&t=99293&p=690282
422 * (a few posts down)
Stephen Warrenb834af82015-03-23 23:00:25 -0600423 *
424 * For the RPi 1, bit 24 is the "warranty bit", so we mask off just the
425 * lower byte to use as the board rev:
426 * http://www.raspberrypi.org/forums/viewtopic.php?f=63&t=98367&start=250
427 * http://www.raspberrypi.org/forums/viewtopic.php?f=31&t=20594
Stephen Warrendc7ea682015-02-16 12:16:15 -0700428 */
Stephen Warren26683852015-12-04 22:07:45 -0700429 revision = msg->get_board_rev.body.resp.rev;
430 if (revision & 0x800000) {
431 rev_scheme = 1;
432 rev_type = (revision >> 4) & 0xff;
433 models = rpi_models_new_scheme;
434 models_count = ARRAY_SIZE(rpi_models_new_scheme);
435 } else {
436 rev_scheme = 0;
437 rev_type = revision & 0xff;
438 models = rpi_models_old_scheme;
439 models_count = ARRAY_SIZE(rpi_models_old_scheme);
Stephen Warren18a5fc62014-12-23 20:01:43 -0700440 }
Stephen Warren26683852015-12-04 22:07:45 -0700441 if (rev_type >= models_count) {
442 printf("RPI: Board rev 0x%x outside known range\n", rev_type);
443 model = &rpi_model_unknown;
444 } else if (!models[rev_type].name) {
445 printf("RPI: Board rev 0x%x unknown\n", rev_type);
446 model = &rpi_model_unknown;
447 } else {
448 model = &models[rev_type];
Stephen Warren18a5fc62014-12-23 20:01:43 -0700449 }
Stephen Warrenc61dfd12014-12-23 20:01:44 -0700450
Stephen Warren26683852015-12-04 22:07:45 -0700451 printf("RPI %s (0x%x)\n", model->name, revision);
Stephen Warrencd210c12014-11-18 21:40:21 -0700452}
453
Fabian Vogt1d317b72016-09-26 14:26:50 +0200454int board_init(void)
Alexander Grafafb99072016-08-15 17:48:51 +0200455{
Paolo Pisati6213c552017-02-10 17:28:05 +0100456#ifdef CONFIG_HW_WATCHDOG
457 hw_watchdog_init();
458#endif
Alexander Grafafb99072016-08-15 17:48:51 +0200459
Fabian Vogt1d317b72016-09-26 14:26:50 +0200460 get_board_rev();
461
462 gd->bd->bi_boot_params = 0x100;
463
Simon Glass558ec672017-04-05 16:23:36 -0600464 return bcm2835_power_on_module(BCM2835_MBOX_POWER_DEVID_USB_HCD);
Alexander Grafafb99072016-08-15 17:48:51 +0200465}
466
Alex Deymo5b661ec2017-04-02 01:25:20 -0700467/*
468 * If the firmware passed a device tree use it for U-Boot.
469 */
470void *board_fdt_blob_setup(void)
471{
472 if (fdt_magic(fw_dtb_pointer) != FDT_MAGIC)
473 return NULL;
474 return (void *)fw_dtb_pointer;
475}
476
Simon Glass2aec3cc2014-10-23 18:58:47 -0600477int ft_board_setup(void *blob, bd_t *bd)
Stephen Warrenaa44d532013-05-27 18:31:18 +0000478{
479 /*
480 * For now, we simply always add the simplefb DT node. Later, we
481 * should be more intelligent, and e.g. only do this if no enabled DT
482 * node exists for the "real" graphics driver.
483 */
484 lcd_dt_simplefb_add_node(blob);
Simon Glass2aec3cc2014-10-23 18:58:47 -0600485
Alexander Graf013e9ae2016-11-02 10:36:20 +0100486#ifdef CONFIG_EFI_LOADER
487 /* Reserve the spin table */
488 efi_add_memory_map(0, 1, EFI_RESERVED_MEMORY_TYPE, 0);
489#endif
490
Simon Glass2aec3cc2014-10-23 18:58:47 -0600491 return 0;
Stephen Warrenaa44d532013-05-27 18:31:18 +0000492}