2 * (C) Copyright 2012-2013,2015 Stephen Warren
4 * SPDX-License-Identifier: GPL-2.0
11 #include <fdt_support.h>
12 #include <fdt_simplefb.h>
17 #include <asm/arch/mbox.h>
18 #include <asm/arch/sdhci.h>
19 #include <asm/global_data.h>
20 #include <dm/platform_data/serial_pl01x.h>
22 DECLARE_GLOBAL_DATA_PTR;
24 static const struct bcm2835_gpio_platdata gpio_platdata = {
25 .base = BCM2835_GPIO_BASE,
28 U_BOOT_DEVICE(bcm2835_gpios) = {
29 .name = "gpio_bcm2835",
30 .platdata = &gpio_platdata,
33 static const struct pl01x_serial_platdata serial_platdata = {
34 #ifndef CONFIG_BCM2835
43 U_BOOT_DEVICE(bcm2835_serials) = {
44 .name = "serial_pl01x",
45 .platdata = &serial_platdata,
48 struct msg_get_arm_mem {
49 struct bcm2835_mbox_hdr hdr;
50 struct bcm2835_mbox_tag_get_arm_mem get_arm_mem;
54 struct msg_get_board_rev {
55 struct bcm2835_mbox_hdr hdr;
56 struct bcm2835_mbox_tag_get_board_rev get_board_rev;
60 struct msg_get_board_serial {
61 struct bcm2835_mbox_hdr hdr;
62 struct bcm2835_mbox_tag_get_board_serial get_board_serial;
66 struct msg_get_mac_address {
67 struct bcm2835_mbox_hdr hdr;
68 struct bcm2835_mbox_tag_get_mac_address get_mac_address;
72 struct msg_set_power_state {
73 struct bcm2835_mbox_hdr hdr;
74 struct bcm2835_mbox_tag_set_power_state set_power_state;
78 struct msg_get_clock_rate {
79 struct bcm2835_mbox_hdr hdr;
80 struct bcm2835_mbox_tag_get_clock_rate get_clock_rate;
85 * http://raspberryalphaomega.org.uk/2013/02/06/automatic-raspberry-pi-board-revision-detection-model-a-b1-and-b2/
86 * http://www.raspberrypi.org/forums/viewtopic.php?f=63&t=32733
87 * http://git.drogon.net/?p=wiringPi;a=blob;f=wiringPi/wiringPi.c;h=503151f61014418b9c42f4476a6086f75cd4e64b;hb=refs/heads/master#l922
89 * In http://lists.denx.de/pipermail/u-boot/2016-January/243752.html
90 * ("[U-Boot] [PATCH] rpi: fix up Model B entries") Dom Cobley at the RPi
91 * Foundation stated that the following source was accurate:
92 * https://github.com/AndrewFromMelbourne/raspberry_pi_revision
100 static const struct rpi_model rpi_model_unknown = {
102 #ifdef CONFIG_BCM2836
103 "bcm2836-rpi-other.dtb",
105 "bcm2835-rpi-other.dtb",
110 static const struct rpi_model rpi_models_new_scheme[] = {
113 "bcm2836-rpi-2-b.dtb",
118 "bcm2835-rpi-zero.dtb",
123 static const struct rpi_model rpi_models_old_scheme[] = {
136 "bcm2835-rpi-b-rev2.dtb",
141 "bcm2835-rpi-b-rev2.dtb",
146 "bcm2835-rpi-b-rev2.dtb",
166 "bcm2835-rpi-b-rev2.dtb",
171 "bcm2835-rpi-b-rev2.dtb",
176 "bcm2835-rpi-b-rev2.dtb",
181 "bcm2835-rpi-b-plus.dtb",
186 "bcm2835-rpi-cm.dtb",
191 "bcm2835-rpi-a-plus.dtb",
196 "bcm2835-rpi-b-plus.dtb",
201 "bcm2835-rpi-cm.dtb",
206 "bcm2835-rpi-a-plus.dtb",
211 static uint32_t revision;
212 static uint32_t rev_scheme;
213 static uint32_t rev_type;
214 static const struct rpi_model *model;
218 ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_arm_mem, msg, 1);
221 BCM2835_MBOX_INIT_HDR(msg);
222 BCM2835_MBOX_INIT_TAG(&msg->get_arm_mem, GET_ARM_MEMORY);
224 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr);
226 printf("bcm2835: Could not query ARM memory size\n");
230 gd->ram_size = msg->get_arm_mem.body.resp.mem_size;
235 static void set_fdtfile(void)
239 if (getenv("fdtfile"))
242 fdtfile = model->fdtfile;
243 setenv("fdtfile", fdtfile);
246 static void set_usbethaddr(void)
248 ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_mac_address, msg, 1);
251 if (!model->has_onboard_eth)
254 if (getenv("usbethaddr"))
257 BCM2835_MBOX_INIT_HDR(msg);
258 BCM2835_MBOX_INIT_TAG(&msg->get_mac_address, GET_MAC_ADDRESS);
260 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr);
262 printf("bcm2835: Could not query MAC address\n");
263 /* Ignore error; not critical */
267 eth_setenv_enetaddr("usbethaddr", msg->get_mac_address.body.resp.mac);
269 if (!getenv("ethaddr"))
270 setenv("ethaddr", getenv("usbethaddr"));
275 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
276 static void set_board_info(void)
280 snprintf(s, sizeof(s), "0x%X", revision);
281 setenv("board_revision", s);
282 snprintf(s, sizeof(s), "%d", rev_scheme);
283 setenv("board_rev_scheme", s);
284 /* Can't rename this to board_rev_type since it's an ABI for scripts */
285 snprintf(s, sizeof(s), "0x%X", rev_type);
286 setenv("board_rev", s);
287 setenv("board_name", model->name);
289 #endif /* CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG */
291 static void set_serial_number(void)
293 ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_board_serial, msg, 1);
295 char serial_string[17] = { 0 };
297 if (getenv("serial#"))
300 BCM2835_MBOX_INIT_HDR(msg);
301 BCM2835_MBOX_INIT_TAG_NO_REQ(&msg->get_board_serial, GET_BOARD_SERIAL);
303 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr);
305 printf("bcm2835: Could not query board serial\n");
306 /* Ignore error; not critical */
310 snprintf(serial_string, sizeof(serial_string), "%016" PRIx64,
311 msg->get_board_serial.body.resp.serial);
312 setenv("serial#", serial_string);
315 int misc_init_r(void)
319 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
327 static int power_on_module(u32 module)
329 ALLOC_CACHE_ALIGN_BUFFER(struct msg_set_power_state, msg_pwr, 1);
332 BCM2835_MBOX_INIT_HDR(msg_pwr);
333 BCM2835_MBOX_INIT_TAG(&msg_pwr->set_power_state,
335 msg_pwr->set_power_state.body.req.device_id = module;
336 msg_pwr->set_power_state.body.req.state =
337 BCM2835_MBOX_SET_POWER_STATE_REQ_ON |
338 BCM2835_MBOX_SET_POWER_STATE_REQ_WAIT;
340 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN,
343 printf("bcm2835: Could not set module %u power state\n",
351 static void get_board_rev(void)
353 ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_board_rev, msg, 1);
355 const struct rpi_model *models;
356 uint32_t models_count;
358 BCM2835_MBOX_INIT_HDR(msg);
359 BCM2835_MBOX_INIT_TAG(&msg->get_board_rev, GET_BOARD_REV);
361 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr);
363 printf("bcm2835: Could not query board revision\n");
364 /* Ignore error; not critical */
369 * For details of old-vs-new scheme, see:
370 * https://github.com/pimoroni/RPi.version/blob/master/RPi/version.py
371 * http://www.raspberrypi.org/forums/viewtopic.php?f=63&t=99293&p=690282
374 * For the RPi 1, bit 24 is the "warranty bit", so we mask off just the
375 * lower byte to use as the board rev:
376 * http://www.raspberrypi.org/forums/viewtopic.php?f=63&t=98367&start=250
377 * http://www.raspberrypi.org/forums/viewtopic.php?f=31&t=20594
379 revision = msg->get_board_rev.body.resp.rev;
380 if (revision & 0x800000) {
382 rev_type = (revision >> 4) & 0xff;
383 models = rpi_models_new_scheme;
384 models_count = ARRAY_SIZE(rpi_models_new_scheme);
387 rev_type = revision & 0xff;
388 models = rpi_models_old_scheme;
389 models_count = ARRAY_SIZE(rpi_models_old_scheme);
391 if (rev_type >= models_count) {
392 printf("RPI: Board rev 0x%x outside known range\n", rev_type);
393 model = &rpi_model_unknown;
394 } else if (!models[rev_type].name) {
395 printf("RPI: Board rev 0x%x unknown\n", rev_type);
396 model = &rpi_model_unknown;
398 model = &models[rev_type];
401 printf("RPI %s (0x%x)\n", model->name, revision);
408 gd->bd->bi_boot_params = 0x100;
410 return power_on_module(BCM2835_MBOX_POWER_DEVID_USB_HCD);
413 int board_mmc_init(bd_t *bis)
415 ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_clock_rate, msg_clk, 1);
418 power_on_module(BCM2835_MBOX_POWER_DEVID_SDHCI);
420 BCM2835_MBOX_INIT_HDR(msg_clk);
421 BCM2835_MBOX_INIT_TAG(&msg_clk->get_clock_rate, GET_CLOCK_RATE);
422 msg_clk->get_clock_rate.body.req.clock_id = BCM2835_MBOX_CLOCK_ID_EMMC;
424 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg_clk->hdr);
426 printf("bcm2835: Could not query eMMC clock rate\n");
430 return bcm2835_sdhci_init(BCM2835_SDHCI_BASE,
431 msg_clk->get_clock_rate.body.resp.rate_hz);
434 int ft_board_setup(void *blob, bd_t *bd)
437 * For now, we simply always add the simplefb DT node. Later, we
438 * should be more intelligent, and e.g. only do this if no enabled DT
439 * node exists for the "real" graphics driver.
441 lcd_dt_simplefb_add_node(blob);