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>
28 DECLARE_GLOBAL_DATA_PTR;
30 static const struct bcm2835_gpio_platdata gpio_platdata = {
31 .base = BCM2835_GPIO_BASE,
34 U_BOOT_DEVICE(bcm2835_gpios) = {
35 .name = "gpio_bcm2835",
36 .platdata = &gpio_platdata,
39 struct msg_get_arm_mem {
40 struct bcm2835_mbox_hdr hdr;
41 struct bcm2835_mbox_tag_get_arm_mem get_arm_mem;
45 struct msg_get_board_rev {
46 struct bcm2835_mbox_hdr hdr;
47 struct bcm2835_mbox_tag_get_board_rev get_board_rev;
51 struct msg_get_mac_address {
52 struct bcm2835_mbox_hdr hdr;
53 struct bcm2835_mbox_tag_get_mac_address get_mac_address;
57 struct msg_set_power_state {
58 struct bcm2835_mbox_hdr hdr;
59 struct bcm2835_mbox_tag_set_power_state set_power_state;
63 struct msg_get_clock_rate {
64 struct bcm2835_mbox_hdr hdr;
65 struct bcm2835_mbox_tag_get_clock_rate get_clock_rate;
69 /* See comments in mbox.h for data source */
74 [BCM2835_BOARD_REV_B_I2C0_2] = {
76 "bcm2835-rpi-b-i2c0.dtb",
78 [BCM2835_BOARD_REV_B_I2C0_3] = {
80 "bcm2835-rpi-b-i2c0.dtb",
82 [BCM2835_BOARD_REV_B_I2C1_4] = {
86 [BCM2835_BOARD_REV_B_I2C1_5] = {
90 [BCM2835_BOARD_REV_B_I2C1_6] = {
94 [BCM2835_BOARD_REV_A_7] = {
98 [BCM2835_BOARD_REV_A_8] = {
102 [BCM2835_BOARD_REV_A_9] = {
106 [BCM2835_BOARD_REV_B_REV2_d] = {
108 "bcm2835-rpi-b-rev2.dtb",
110 [BCM2835_BOARD_REV_B_REV2_e] = {
112 "bcm2835-rpi-b-rev2.dtb",
114 [BCM2835_BOARD_REV_B_REV2_f] = {
116 "bcm2835-rpi-b-rev2.dtb",
118 [BCM2835_BOARD_REV_B_PLUS] = {
120 "bcm2835-rpi-b-plus.dtb",
122 [BCM2835_BOARD_REV_CM] = {
124 "bcm2835-rpi-cm.dtb",
128 u32 rpi_board_rev = 0;
132 ALLOC_ALIGN_BUFFER(struct msg_get_arm_mem, msg, 1, 16);
135 BCM2835_MBOX_INIT_HDR(msg);
136 BCM2835_MBOX_INIT_TAG(&msg->get_arm_mem, GET_ARM_MEMORY);
138 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr);
140 printf("bcm2835: Could not query ARM memory size\n");
144 gd->ram_size = msg->get_arm_mem.body.resp.mem_size;
149 static void set_fdtfile(void)
153 if (getenv("fdtfile"))
156 fdtfile = models[rpi_board_rev].fdtfile;
158 fdtfile = "bcm2835-rpi-other.dtb";
160 setenv("fdtfile", fdtfile);
163 static void set_usbethaddr(void)
165 ALLOC_ALIGN_BUFFER(struct msg_get_mac_address, msg, 1, 16);
168 if (getenv("usbethaddr"))
171 BCM2835_MBOX_INIT_HDR(msg);
172 BCM2835_MBOX_INIT_TAG(&msg->get_mac_address, GET_MAC_ADDRESS);
174 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr);
176 printf("bcm2835: Could not query MAC address\n");
177 /* Ignore error; not critical */
181 eth_setenv_enetaddr("usbethaddr", msg->get_mac_address.body.resp.mac);
186 int misc_init_r(void)
193 static int power_on_module(u32 module)
195 ALLOC_ALIGN_BUFFER(struct msg_set_power_state, msg_pwr, 1, 16);
198 BCM2835_MBOX_INIT_HDR(msg_pwr);
199 BCM2835_MBOX_INIT_TAG(&msg_pwr->set_power_state,
201 msg_pwr->set_power_state.body.req.device_id = module;
202 msg_pwr->set_power_state.body.req.state =
203 BCM2835_MBOX_SET_POWER_STATE_REQ_ON |
204 BCM2835_MBOX_SET_POWER_STATE_REQ_WAIT;
206 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN,
209 printf("bcm2835: Could not set module %u power state\n",
217 static void get_board_rev(void)
219 ALLOC_ALIGN_BUFFER(struct msg_get_board_rev, msg, 1, 16);
223 BCM2835_MBOX_INIT_HDR(msg);
224 BCM2835_MBOX_INIT_TAG(&msg->get_board_rev, GET_BOARD_REV);
226 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr);
228 printf("bcm2835: Could not query board revision\n");
229 /* Ignore error; not critical */
233 rpi_board_rev = msg->get_board_rev.body.resp.rev;
234 if (rpi_board_rev >= ARRAY_SIZE(models))
237 name = models[rpi_board_rev].name;
239 name = "Unknown model";
240 printf("RPI model: %s\n", name);
247 gd->bd->bi_boot_params = 0x100;
249 return power_on_module(BCM2835_MBOX_POWER_DEVID_USB_HCD);
252 int board_mmc_init(bd_t *bis)
254 ALLOC_ALIGN_BUFFER(struct msg_get_clock_rate, msg_clk, 1, 16);
257 power_on_module(BCM2835_MBOX_POWER_DEVID_SDHCI);
259 BCM2835_MBOX_INIT_HDR(msg_clk);
260 BCM2835_MBOX_INIT_TAG(&msg_clk->get_clock_rate, GET_CLOCK_RATE);
261 msg_clk->get_clock_rate.body.req.clock_id = BCM2835_MBOX_CLOCK_ID_EMMC;
263 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg_clk->hdr);
265 printf("bcm2835: Could not query eMMC clock rate\n");
269 return bcm2835_sdhci_init(BCM2835_SDHCI_BASE,
270 msg_clk->get_clock_rate.body.resp.rate_hz);
273 int ft_board_setup(void *blob, bd_t *bd)
276 * For now, we simply always add the simplefb DT node. Later, we
277 * should be more intelligent, and e.g. only do this if no enabled DT
278 * node exists for the "real" graphics driver.
280 lcd_dt_simplefb_add_node(blob);