2 * (C) Copyright 2012-2013 Stephen Warren
4 * See file CREDITS for list of people who contributed to this
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * version 2 as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
20 #include <fdt_support.h>
21 #include <fdt_simplefb.h>
25 #include <asm/arch/mbox.h>
26 #include <asm/arch/sdhci.h>
27 #include <asm/global_data.h>
28 #include <dm/platform_data/serial_pl01x.h>
30 DECLARE_GLOBAL_DATA_PTR;
32 static const struct bcm2835_gpio_platdata gpio_platdata = {
33 .base = BCM2835_GPIO_BASE,
36 U_BOOT_DEVICE(bcm2835_gpios) = {
37 .name = "gpio_bcm2835",
38 .platdata = &gpio_platdata,
41 static const struct pl01x_serial_platdata serial_platdata = {
47 U_BOOT_DEVICE(bcm2835_serials) = {
48 .name = "serial_pl01x",
49 .platdata = &serial_platdata,
52 struct msg_get_arm_mem {
53 struct bcm2835_mbox_hdr hdr;
54 struct bcm2835_mbox_tag_get_arm_mem get_arm_mem;
58 struct msg_get_board_rev {
59 struct bcm2835_mbox_hdr hdr;
60 struct bcm2835_mbox_tag_get_board_rev get_board_rev;
64 struct msg_get_mac_address {
65 struct bcm2835_mbox_hdr hdr;
66 struct bcm2835_mbox_tag_get_mac_address get_mac_address;
70 struct msg_set_power_state {
71 struct bcm2835_mbox_hdr hdr;
72 struct bcm2835_mbox_tag_set_power_state set_power_state;
76 struct msg_get_clock_rate {
77 struct bcm2835_mbox_hdr hdr;
78 struct bcm2835_mbox_tag_get_clock_rate get_clock_rate;
82 /* See comments in mbox.h for data source */
90 "bcm2835-rpi-other.dtb",
93 [BCM2835_BOARD_REV_B_I2C0_2] = {
95 "bcm2835-rpi-b-i2c0.dtb",
98 [BCM2835_BOARD_REV_B_I2C0_3] = {
100 "bcm2835-rpi-b-i2c0.dtb",
103 [BCM2835_BOARD_REV_B_I2C1_4] = {
108 [BCM2835_BOARD_REV_B_I2C1_5] = {
113 [BCM2835_BOARD_REV_B_I2C1_6] = {
118 [BCM2835_BOARD_REV_A_7] = {
123 [BCM2835_BOARD_REV_A_8] = {
128 [BCM2835_BOARD_REV_A_9] = {
133 [BCM2835_BOARD_REV_B_REV2_d] = {
135 "bcm2835-rpi-b-rev2.dtb",
138 [BCM2835_BOARD_REV_B_REV2_e] = {
140 "bcm2835-rpi-b-rev2.dtb",
143 [BCM2835_BOARD_REV_B_REV2_f] = {
145 "bcm2835-rpi-b-rev2.dtb",
148 [BCM2835_BOARD_REV_B_PLUS] = {
150 "bcm2835-rpi-b-plus.dtb",
153 [BCM2835_BOARD_REV_CM] = {
155 "bcm2835-rpi-cm.dtb",
158 [BCM2835_BOARD_REV_A_PLUS] = {
160 "bcm2835-rpi-a-plus.dtb",
165 u32 rpi_board_rev = 0;
169 ALLOC_ALIGN_BUFFER(struct msg_get_arm_mem, msg, 1, 16);
172 BCM2835_MBOX_INIT_HDR(msg);
173 BCM2835_MBOX_INIT_TAG(&msg->get_arm_mem, GET_ARM_MEMORY);
175 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr);
177 printf("bcm2835: Could not query ARM memory size\n");
181 gd->ram_size = msg->get_arm_mem.body.resp.mem_size;
186 static void set_fdtfile(void)
190 if (getenv("fdtfile"))
193 fdtfile = models[rpi_board_rev].fdtfile;
194 setenv("fdtfile", fdtfile);
197 static void set_usbethaddr(void)
199 ALLOC_ALIGN_BUFFER(struct msg_get_mac_address, msg, 1, 16);
202 if (!models[rpi_board_rev].has_onboard_eth)
205 if (getenv("usbethaddr"))
208 BCM2835_MBOX_INIT_HDR(msg);
209 BCM2835_MBOX_INIT_TAG(&msg->get_mac_address, GET_MAC_ADDRESS);
211 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr);
213 printf("bcm2835: Could not query MAC address\n");
214 /* Ignore error; not critical */
218 eth_setenv_enetaddr("usbethaddr", msg->get_mac_address.body.resp.mac);
223 int misc_init_r(void)
230 static int power_on_module(u32 module)
232 ALLOC_ALIGN_BUFFER(struct msg_set_power_state, msg_pwr, 1, 16);
235 BCM2835_MBOX_INIT_HDR(msg_pwr);
236 BCM2835_MBOX_INIT_TAG(&msg_pwr->set_power_state,
238 msg_pwr->set_power_state.body.req.device_id = module;
239 msg_pwr->set_power_state.body.req.state =
240 BCM2835_MBOX_SET_POWER_STATE_REQ_ON |
241 BCM2835_MBOX_SET_POWER_STATE_REQ_WAIT;
243 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN,
246 printf("bcm2835: Could not set module %u power state\n",
254 static void get_board_rev(void)
256 ALLOC_ALIGN_BUFFER(struct msg_get_board_rev, msg, 1, 16);
260 BCM2835_MBOX_INIT_HDR(msg);
261 BCM2835_MBOX_INIT_TAG(&msg->get_board_rev, GET_BOARD_REV);
263 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr);
265 printf("bcm2835: Could not query board revision\n");
266 /* Ignore error; not critical */
270 rpi_board_rev = msg->get_board_rev.body.resp.rev;
271 if (rpi_board_rev >= ARRAY_SIZE(models)) {
272 printf("RPI: Board rev %u outside known range\n",
276 if (!models[rpi_board_rev].name) {
277 printf("RPI: Board rev %u unknown\n", rpi_board_rev);
281 name = models[rpi_board_rev].name;
282 printf("RPI model: %s\n", name);
289 gd->bd->bi_boot_params = 0x100;
291 return power_on_module(BCM2835_MBOX_POWER_DEVID_USB_HCD);
294 int board_mmc_init(bd_t *bis)
296 ALLOC_ALIGN_BUFFER(struct msg_get_clock_rate, msg_clk, 1, 16);
299 power_on_module(BCM2835_MBOX_POWER_DEVID_SDHCI);
301 BCM2835_MBOX_INIT_HDR(msg_clk);
302 BCM2835_MBOX_INIT_TAG(&msg_clk->get_clock_rate, GET_CLOCK_RATE);
303 msg_clk->get_clock_rate.body.req.clock_id = BCM2835_MBOX_CLOCK_ID_EMMC;
305 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg_clk->hdr);
307 printf("bcm2835: Could not query eMMC clock rate\n");
311 return bcm2835_sdhci_init(BCM2835_SDHCI_BASE,
312 msg_clk->get_clock_rate.body.resp.rate_hz);
315 int ft_board_setup(void *blob, bd_t *bd)
318 * For now, we simply always add the simplefb DT node. Later, we
319 * should be more intelligent, and e.g. only do this if no enabled DT
320 * node exists for the "real" graphics driver.
322 lcd_dt_simplefb_add_node(blob);