2 * (C) Copyright 2012-2013,2015 Stephen Warren
4 * SPDX-License-Identifier: GPL-2.0
10 #include <fdt_support.h>
11 #include <fdt_simplefb.h>
16 #include <asm/arch/mbox.h>
17 #include <asm/arch/sdhci.h>
18 #include <asm/global_data.h>
19 #include <dm/platform_data/serial_pl01x.h>
21 DECLARE_GLOBAL_DATA_PTR;
23 static const struct bcm2835_gpio_platdata gpio_platdata = {
24 .base = BCM2835_GPIO_BASE,
27 U_BOOT_DEVICE(bcm2835_gpios) = {
28 .name = "gpio_bcm2835",
29 .platdata = &gpio_platdata,
32 static const struct pl01x_serial_platdata serial_platdata = {
42 U_BOOT_DEVICE(bcm2835_serials) = {
43 .name = "serial_pl01x",
44 .platdata = &serial_platdata,
47 struct msg_get_arm_mem {
48 struct bcm2835_mbox_hdr hdr;
49 struct bcm2835_mbox_tag_get_arm_mem get_arm_mem;
53 struct msg_get_board_rev {
54 struct bcm2835_mbox_hdr hdr;
55 struct bcm2835_mbox_tag_get_board_rev get_board_rev;
59 struct msg_get_mac_address {
60 struct bcm2835_mbox_hdr hdr;
61 struct bcm2835_mbox_tag_get_mac_address get_mac_address;
65 struct msg_set_power_state {
66 struct bcm2835_mbox_hdr hdr;
67 struct bcm2835_mbox_tag_set_power_state set_power_state;
71 struct msg_get_clock_rate {
72 struct bcm2835_mbox_hdr hdr;
73 struct bcm2835_mbox_tag_get_clock_rate get_clock_rate;
77 /* See comments in mbox.h for data source */
86 "bcm2836-rpi-other.dtb",
88 "bcm2835-rpi-other.dtb",
93 [BCM2836_BOARD_REV_2_B] = {
95 "bcm2836-rpi-2-b.dtb",
99 [BCM2835_BOARD_REV_B_I2C0_2] = {
101 "bcm2835-rpi-b-i2c0.dtb",
104 [BCM2835_BOARD_REV_B_I2C0_3] = {
106 "bcm2835-rpi-b-i2c0.dtb",
109 [BCM2835_BOARD_REV_B_I2C1_4] = {
114 [BCM2835_BOARD_REV_B_I2C1_5] = {
119 [BCM2835_BOARD_REV_B_I2C1_6] = {
124 [BCM2835_BOARD_REV_A_7] = {
129 [BCM2835_BOARD_REV_A_8] = {
134 [BCM2835_BOARD_REV_A_9] = {
139 [BCM2835_BOARD_REV_B_REV2_d] = {
141 "bcm2835-rpi-b-rev2.dtb",
144 [BCM2835_BOARD_REV_B_REV2_e] = {
146 "bcm2835-rpi-b-rev2.dtb",
149 [BCM2835_BOARD_REV_B_REV2_f] = {
151 "bcm2835-rpi-b-rev2.dtb",
154 [BCM2835_BOARD_REV_B_PLUS] = {
156 "bcm2835-rpi-b-plus.dtb",
159 [BCM2835_BOARD_REV_CM] = {
161 "bcm2835-rpi-cm.dtb",
164 [BCM2835_BOARD_REV_A_PLUS] = {
166 "bcm2835-rpi-a-plus.dtb",
169 [BCM2835_BOARD_REV_B_PLUS_13] = {
171 "bcm2835-rpi-b-plus.dtb",
174 [BCM2835_BOARD_REV_CM_14] = {
176 "bcm2835-rpi-cm.dtb",
179 [BCM2835_BOARD_REV_A_PLUS_15] = {
181 "bcm2835-rpi-a-plus.dtb",
187 u32 rpi_board_rev = 0;
191 ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_arm_mem, msg, 1);
194 BCM2835_MBOX_INIT_HDR(msg);
195 BCM2835_MBOX_INIT_TAG(&msg->get_arm_mem, GET_ARM_MEMORY);
197 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr);
199 printf("bcm2835: Could not query ARM memory size\n");
203 gd->ram_size = msg->get_arm_mem.body.resp.mem_size;
208 static void set_fdtfile(void)
212 if (getenv("fdtfile"))
215 fdtfile = models[rpi_board_rev].fdtfile;
216 setenv("fdtfile", fdtfile);
219 static void set_usbethaddr(void)
221 ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_mac_address, msg, 1);
224 if (!models[rpi_board_rev].has_onboard_eth)
227 if (getenv("usbethaddr"))
230 BCM2835_MBOX_INIT_HDR(msg);
231 BCM2835_MBOX_INIT_TAG(&msg->get_mac_address, GET_MAC_ADDRESS);
233 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr);
235 printf("bcm2835: Could not query MAC address\n");
236 /* Ignore error; not critical */
240 eth_setenv_enetaddr("usbethaddr", msg->get_mac_address.body.resp.mac);
245 int misc_init_r(void)
252 static int power_on_module(u32 module)
254 ALLOC_CACHE_ALIGN_BUFFER(struct msg_set_power_state, msg_pwr, 1);
257 BCM2835_MBOX_INIT_HDR(msg_pwr);
258 BCM2835_MBOX_INIT_TAG(&msg_pwr->set_power_state,
260 msg_pwr->set_power_state.body.req.device_id = module;
261 msg_pwr->set_power_state.body.req.state =
262 BCM2835_MBOX_SET_POWER_STATE_REQ_ON |
263 BCM2835_MBOX_SET_POWER_STATE_REQ_WAIT;
265 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN,
268 printf("bcm2835: Could not set module %u power state\n",
276 static void get_board_rev(void)
278 ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_board_rev, msg, 1);
282 BCM2835_MBOX_INIT_HDR(msg);
283 BCM2835_MBOX_INIT_TAG(&msg->get_board_rev, GET_BOARD_REV);
285 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr);
287 printf("bcm2835: Could not query board revision\n");
288 /* Ignore error; not critical */
293 * For details of old-vs-new scheme, see:
294 * https://github.com/pimoroni/RPi.version/blob/master/RPi/version.py
295 * http://www.raspberrypi.org/forums/viewtopic.php?f=63&t=99293&p=690282
298 * For the RPi 1, bit 24 is the "warranty bit", so we mask off just the
299 * lower byte to use as the board rev:
300 * http://www.raspberrypi.org/forums/viewtopic.php?f=63&t=98367&start=250
301 * http://www.raspberrypi.org/forums/viewtopic.php?f=31&t=20594
303 rpi_board_rev = msg->get_board_rev.body.resp.rev;
304 if (rpi_board_rev & 0x800000)
305 rpi_board_rev = (rpi_board_rev >> 4) & 0xff;
307 rpi_board_rev &= 0xff;
308 if (rpi_board_rev >= ARRAY_SIZE(models)) {
309 printf("RPI: Board rev %u outside known range\n",
313 if (!models[rpi_board_rev].name) {
314 printf("RPI: Board rev %u unknown\n", rpi_board_rev);
318 name = models[rpi_board_rev].name;
319 printf("RPI %s\n", name);
326 gd->bd->bi_boot_params = 0x100;
328 return power_on_module(BCM2835_MBOX_POWER_DEVID_USB_HCD);
331 int board_mmc_init(bd_t *bis)
333 ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_clock_rate, msg_clk, 1);
336 power_on_module(BCM2835_MBOX_POWER_DEVID_SDHCI);
338 BCM2835_MBOX_INIT_HDR(msg_clk);
339 BCM2835_MBOX_INIT_TAG(&msg_clk->get_clock_rate, GET_CLOCK_RATE);
340 msg_clk->get_clock_rate.body.req.clock_id = BCM2835_MBOX_CLOCK_ID_EMMC;
342 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg_clk->hdr);
344 printf("bcm2835: Could not query eMMC clock rate\n");
348 return bcm2835_sdhci_init(BCM2835_SDHCI_BASE,
349 msg_clk->get_clock_rate.body.resp.rate_hz);
352 int ft_board_setup(void *blob, bd_t *bd)
355 * For now, we simply always add the simplefb DT node. Later, we
356 * should be more intelligent, and e.g. only do this if no enabled DT
357 * node exists for the "real" graphics driver.
359 lcd_dt_simplefb_add_node(blob);