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>
24 #include <asm/arch/mbox.h>
25 #include <asm/arch/sdhci.h>
26 #include <asm/global_data.h>
27 #include <dm/platform_data/serial_pl01x.h>
29 DECLARE_GLOBAL_DATA_PTR;
31 static const struct bcm2835_gpio_platdata gpio_platdata = {
32 .base = BCM2835_GPIO_BASE,
35 U_BOOT_DEVICE(bcm2835_gpios) = {
36 .name = "gpio_bcm2835",
37 .platdata = &gpio_platdata,
40 static const struct pl01x_serial_platdata serial_platdata = {
46 U_BOOT_DEVICE(bcm2835_serials) = {
47 .name = "serial_pl01x",
48 .platdata = &serial_platdata,
51 struct msg_get_arm_mem {
52 struct bcm2835_mbox_hdr hdr;
53 struct bcm2835_mbox_tag_get_arm_mem get_arm_mem;
57 struct msg_get_board_rev {
58 struct bcm2835_mbox_hdr hdr;
59 struct bcm2835_mbox_tag_get_board_rev get_board_rev;
63 struct msg_get_mac_address {
64 struct bcm2835_mbox_hdr hdr;
65 struct bcm2835_mbox_tag_get_mac_address get_mac_address;
69 struct msg_set_power_state {
70 struct bcm2835_mbox_hdr hdr;
71 struct bcm2835_mbox_tag_set_power_state set_power_state;
75 struct msg_get_clock_rate {
76 struct bcm2835_mbox_hdr hdr;
77 struct bcm2835_mbox_tag_get_clock_rate get_clock_rate;
81 /* See comments in mbox.h for data source */
89 "bcm2835-rpi-other.dtb",
92 [BCM2835_BOARD_REV_B_I2C0_2] = {
94 "bcm2835-rpi-b-i2c0.dtb",
97 [BCM2835_BOARD_REV_B_I2C0_3] = {
99 "bcm2835-rpi-b-i2c0.dtb",
102 [BCM2835_BOARD_REV_B_I2C1_4] = {
107 [BCM2835_BOARD_REV_B_I2C1_5] = {
112 [BCM2835_BOARD_REV_B_I2C1_6] = {
117 [BCM2835_BOARD_REV_A_7] = {
122 [BCM2835_BOARD_REV_A_8] = {
127 [BCM2835_BOARD_REV_A_9] = {
132 [BCM2835_BOARD_REV_B_REV2_d] = {
134 "bcm2835-rpi-b-rev2.dtb",
137 [BCM2835_BOARD_REV_B_REV2_e] = {
139 "bcm2835-rpi-b-rev2.dtb",
142 [BCM2835_BOARD_REV_B_REV2_f] = {
144 "bcm2835-rpi-b-rev2.dtb",
147 [BCM2835_BOARD_REV_B_PLUS] = {
149 "bcm2835-rpi-b-plus.dtb",
152 [BCM2835_BOARD_REV_CM] = {
154 "bcm2835-rpi-cm.dtb",
157 [BCM2835_BOARD_REV_A_PLUS] = {
159 "bcm2835-rpi-a-plus.dtb",
164 u32 rpi_board_rev = 0;
168 ALLOC_ALIGN_BUFFER(struct msg_get_arm_mem, msg, 1, 16);
171 BCM2835_MBOX_INIT_HDR(msg);
172 BCM2835_MBOX_INIT_TAG(&msg->get_arm_mem, GET_ARM_MEMORY);
174 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr);
176 printf("bcm2835: Could not query ARM memory size\n");
180 gd->ram_size = msg->get_arm_mem.body.resp.mem_size;
185 static void set_fdtfile(void)
189 if (getenv("fdtfile"))
192 fdtfile = models[rpi_board_rev].fdtfile;
193 setenv("fdtfile", fdtfile);
196 static void set_usbethaddr(void)
198 ALLOC_ALIGN_BUFFER(struct msg_get_mac_address, msg, 1, 16);
201 if (!models[rpi_board_rev].has_onboard_eth)
204 if (getenv("usbethaddr"))
207 BCM2835_MBOX_INIT_HDR(msg);
208 BCM2835_MBOX_INIT_TAG(&msg->get_mac_address, GET_MAC_ADDRESS);
210 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr);
212 printf("bcm2835: Could not query MAC address\n");
213 /* Ignore error; not critical */
217 eth_setenv_enetaddr("usbethaddr", msg->get_mac_address.body.resp.mac);
222 int misc_init_r(void)
229 static int power_on_module(u32 module)
231 ALLOC_ALIGN_BUFFER(struct msg_set_power_state, msg_pwr, 1, 16);
234 BCM2835_MBOX_INIT_HDR(msg_pwr);
235 BCM2835_MBOX_INIT_TAG(&msg_pwr->set_power_state,
237 msg_pwr->set_power_state.body.req.device_id = module;
238 msg_pwr->set_power_state.body.req.state =
239 BCM2835_MBOX_SET_POWER_STATE_REQ_ON |
240 BCM2835_MBOX_SET_POWER_STATE_REQ_WAIT;
242 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN,
245 printf("bcm2835: Could not set module %u power state\n",
253 static void get_board_rev(void)
255 ALLOC_ALIGN_BUFFER(struct msg_get_board_rev, msg, 1, 16);
259 BCM2835_MBOX_INIT_HDR(msg);
260 BCM2835_MBOX_INIT_TAG(&msg->get_board_rev, GET_BOARD_REV);
262 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr);
264 printf("bcm2835: Could not query board revision\n");
265 /* Ignore error; not critical */
269 rpi_board_rev = msg->get_board_rev.body.resp.rev;
270 if (rpi_board_rev >= ARRAY_SIZE(models)) {
271 printf("RPI: Board rev %u outside known range\n",
275 if (!models[rpi_board_rev].name) {
276 printf("RPI: Board rev %u unknown\n", rpi_board_rev);
280 name = models[rpi_board_rev].name;
281 printf("RPI model: %s\n", name);
288 gd->bd->bi_boot_params = 0x100;
290 return power_on_module(BCM2835_MBOX_POWER_DEVID_USB_HCD);
293 int board_mmc_init(bd_t *bis)
295 ALLOC_ALIGN_BUFFER(struct msg_get_clock_rate, msg_clk, 1, 16);
298 power_on_module(BCM2835_MBOX_POWER_DEVID_SDHCI);
300 BCM2835_MBOX_INIT_HDR(msg_clk);
301 BCM2835_MBOX_INIT_TAG(&msg_clk->get_clock_rate, GET_CLOCK_RATE);
302 msg_clk->get_clock_rate.body.req.clock_id = BCM2835_MBOX_CLOCK_ID_EMMC;
304 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg_clk->hdr);
306 printf("bcm2835: Could not query eMMC clock rate\n");
310 return bcm2835_sdhci_init(BCM2835_SDHCI_BASE,
311 msg_clk->get_clock_rate.body.resp.rate_hz);
314 int ft_board_setup(void *blob, bd_t *bd)
317 * For now, we simply always add the simplefb DT node. Later, we
318 * should be more intelligent, and e.g. only do this if no enabled DT
319 * node exists for the "real" graphics driver.
321 lcd_dt_simplefb_add_node(blob);