blob: ca8e86dead6c24b737bb1b3508cddf9492a6e5f9 [file] [log] [blame]
Stephen Warren0d04f342012-08-05 16:07:22 +00001/*
Stephen Warrenea697ae2013-05-27 18:31:18 +00002 * (C) Copyright 2012-2013 Stephen Warren
Stephen Warren0d04f342012-08-05 16:07:22 +00003 *
4 * See file CREDITS for list of people who contributed to this
5 * project.
6 *
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.
10 *
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.
15 */
16
17#include <common.h>
Stephen Warrenea697ae2013-05-27 18:31:18 +000018#include <config.h>
Simon Glass41e98e02014-09-22 17:30:56 -060019#include <dm.h>
Jeroen Hofstee5dfd1622014-07-13 22:01:51 +020020#include <fdt_support.h>
Stephen Warrenea697ae2013-05-27 18:31:18 +000021#include <lcd.h>
Jeroen Hofstee5dfd1622014-07-13 22:01:51 +020022#include <mmc.h>
Simon Glass41e98e02014-09-22 17:30:56 -060023#include <asm/gpio.h>
Stephen Warren3f397782013-01-29 16:37:37 +000024#include <asm/arch/mbox.h>
Stephen Warren131a1e62013-01-29 16:37:42 +000025#include <asm/arch/sdhci.h>
Stephen Warren0d04f342012-08-05 16:07:22 +000026#include <asm/global_data.h>
Simon Glass11506662014-11-24 21:36:34 -070027#include <dm/platform_data/serial_pl01x.h>
Stephen Warren0d04f342012-08-05 16:07:22 +000028
29DECLARE_GLOBAL_DATA_PTR;
30
Simon Glass41e98e02014-09-22 17:30:56 -060031static const struct bcm2835_gpio_platdata gpio_platdata = {
32 .base = BCM2835_GPIO_BASE,
33};
34
35U_BOOT_DEVICE(bcm2835_gpios) = {
36 .name = "gpio_bcm2835",
37 .platdata = &gpio_platdata,
38};
39
Simon Glass11506662014-11-24 21:36:34 -070040static const struct pl01x_serial_platdata serial_platdata = {
41 .base = 0x20201000,
42 .type = TYPE_PL011,
43 .clock = 3000000,
44};
45
46U_BOOT_DEVICE(bcm2835_serials) = {
47 .name = "serial_pl01x",
48 .platdata = &serial_platdata,
49};
50
Stephen Warren3f397782013-01-29 16:37:37 +000051struct msg_get_arm_mem {
52 struct bcm2835_mbox_hdr hdr;
53 struct bcm2835_mbox_tag_get_arm_mem get_arm_mem;
54 u32 end_tag;
55};
56
Stephen Warren6fe78452014-11-18 21:40:21 -070057struct msg_get_board_rev {
58 struct bcm2835_mbox_hdr hdr;
59 struct bcm2835_mbox_tag_get_board_rev get_board_rev;
60 u32 end_tag;
61};
62
Stephen Warren4f80a062014-09-26 20:51:39 -060063struct msg_get_mac_address {
64 struct bcm2835_mbox_hdr hdr;
65 struct bcm2835_mbox_tag_get_mac_address get_mac_address;
66 u32 end_tag;
67};
68
Stephen Warrenf66f2aa2014-01-13 19:50:11 -070069struct msg_set_power_state {
70 struct bcm2835_mbox_hdr hdr;
71 struct bcm2835_mbox_tag_set_power_state set_power_state;
72 u32 end_tag;
73};
74
Stephen Warren131a1e62013-01-29 16:37:42 +000075struct msg_get_clock_rate {
76 struct bcm2835_mbox_hdr hdr;
77 struct bcm2835_mbox_tag_get_clock_rate get_clock_rate;
78 u32 end_tag;
79};
80
Stephen Warren6fe78452014-11-18 21:40:21 -070081/* See comments in mbox.h for data source */
82static const struct {
83 const char *name;
84 const char *fdtfile;
Stephen Warren3207d8f2014-12-05 20:56:46 -070085 bool has_onboard_eth;
Stephen Warren6fe78452014-11-18 21:40:21 -070086} models[] = {
87 [BCM2835_BOARD_REV_B_I2C0_2] = {
88 "Model B (no P5)",
89 "bcm2835-rpi-b-i2c0.dtb",
Stephen Warren3207d8f2014-12-05 20:56:46 -070090 true,
Stephen Warren6fe78452014-11-18 21:40:21 -070091 },
92 [BCM2835_BOARD_REV_B_I2C0_3] = {
93 "Model B (no P5)",
94 "bcm2835-rpi-b-i2c0.dtb",
Stephen Warren3207d8f2014-12-05 20:56:46 -070095 true,
Stephen Warren6fe78452014-11-18 21:40:21 -070096 },
97 [BCM2835_BOARD_REV_B_I2C1_4] = {
98 "Model B",
99 "bcm2835-rpi-b.dtb",
Stephen Warren3207d8f2014-12-05 20:56:46 -0700100 true,
Stephen Warren6fe78452014-11-18 21:40:21 -0700101 },
102 [BCM2835_BOARD_REV_B_I2C1_5] = {
103 "Model B",
104 "bcm2835-rpi-b.dtb",
Stephen Warren3207d8f2014-12-05 20:56:46 -0700105 true,
Stephen Warren6fe78452014-11-18 21:40:21 -0700106 },
107 [BCM2835_BOARD_REV_B_I2C1_6] = {
108 "Model B",
109 "bcm2835-rpi-b.dtb",
Stephen Warren3207d8f2014-12-05 20:56:46 -0700110 true,
Stephen Warren6fe78452014-11-18 21:40:21 -0700111 },
112 [BCM2835_BOARD_REV_A_7] = {
113 "Model A",
114 "bcm2835-rpi-a.dtb",
Stephen Warren3207d8f2014-12-05 20:56:46 -0700115 false,
Stephen Warren6fe78452014-11-18 21:40:21 -0700116 },
117 [BCM2835_BOARD_REV_A_8] = {
118 "Model A",
119 "bcm2835-rpi-a.dtb",
Stephen Warren3207d8f2014-12-05 20:56:46 -0700120 false,
Stephen Warren6fe78452014-11-18 21:40:21 -0700121 },
122 [BCM2835_BOARD_REV_A_9] = {
123 "Model A",
124 "bcm2835-rpi-a.dtb",
Stephen Warren3207d8f2014-12-05 20:56:46 -0700125 false,
Stephen Warren6fe78452014-11-18 21:40:21 -0700126 },
127 [BCM2835_BOARD_REV_B_REV2_d] = {
128 "Model B rev2",
129 "bcm2835-rpi-b-rev2.dtb",
Stephen Warren3207d8f2014-12-05 20:56:46 -0700130 true,
Stephen Warren6fe78452014-11-18 21:40:21 -0700131 },
132 [BCM2835_BOARD_REV_B_REV2_e] = {
133 "Model B rev2",
134 "bcm2835-rpi-b-rev2.dtb",
Stephen Warren3207d8f2014-12-05 20:56:46 -0700135 true,
Stephen Warren6fe78452014-11-18 21:40:21 -0700136 },
137 [BCM2835_BOARD_REV_B_REV2_f] = {
138 "Model B rev2",
139 "bcm2835-rpi-b-rev2.dtb",
Stephen Warren3207d8f2014-12-05 20:56:46 -0700140 true,
Stephen Warren6fe78452014-11-18 21:40:21 -0700141 },
142 [BCM2835_BOARD_REV_B_PLUS] = {
143 "Model B+",
144 "bcm2835-rpi-b-plus.dtb",
Stephen Warren3207d8f2014-12-05 20:56:46 -0700145 true,
Stephen Warren6fe78452014-11-18 21:40:21 -0700146 },
147 [BCM2835_BOARD_REV_CM] = {
148 "Compute Module",
149 "bcm2835-rpi-cm.dtb",
Stephen Warren3207d8f2014-12-05 20:56:46 -0700150 false,
Stephen Warren6fe78452014-11-18 21:40:21 -0700151 },
152};
153
154u32 rpi_board_rev = 0;
155
Stephen Warren0d04f342012-08-05 16:07:22 +0000156int dram_init(void)
157{
Stephen Warren3f397782013-01-29 16:37:37 +0000158 ALLOC_ALIGN_BUFFER(struct msg_get_arm_mem, msg, 1, 16);
159 int ret;
160
161 BCM2835_MBOX_INIT_HDR(msg);
162 BCM2835_MBOX_INIT_TAG(&msg->get_arm_mem, GET_ARM_MEMORY);
163
164 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr);
165 if (ret) {
166 printf("bcm2835: Could not query ARM memory size\n");
167 return -1;
168 }
169
170 gd->ram_size = msg->get_arm_mem.body.resp.mem_size;
Stephen Warren0d04f342012-08-05 16:07:22 +0000171
172 return 0;
173}
174
Stephen Warren6fe78452014-11-18 21:40:21 -0700175static void set_fdtfile(void)
176{
177 const char *fdtfile;
178
179 if (getenv("fdtfile"))
180 return;
181
182 fdtfile = models[rpi_board_rev].fdtfile;
183 if (!fdtfile)
184 fdtfile = "bcm2835-rpi-other.dtb";
185
186 setenv("fdtfile", fdtfile);
187}
188
189static void set_usbethaddr(void)
Stephen Warren4f80a062014-09-26 20:51:39 -0600190{
191 ALLOC_ALIGN_BUFFER(struct msg_get_mac_address, msg, 1, 16);
192 int ret;
193
Stephen Warren3207d8f2014-12-05 20:56:46 -0700194 if (!models[rpi_board_rev].has_onboard_eth)
195 return;
196
Stephen Warren4f80a062014-09-26 20:51:39 -0600197 if (getenv("usbethaddr"))
Stephen Warren6fe78452014-11-18 21:40:21 -0700198 return;
Stephen Warren4f80a062014-09-26 20:51:39 -0600199
200 BCM2835_MBOX_INIT_HDR(msg);
201 BCM2835_MBOX_INIT_TAG(&msg->get_mac_address, GET_MAC_ADDRESS);
202
203 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr);
204 if (ret) {
205 printf("bcm2835: Could not query MAC address\n");
206 /* Ignore error; not critical */
Stephen Warren6fe78452014-11-18 21:40:21 -0700207 return;
Stephen Warren4f80a062014-09-26 20:51:39 -0600208 }
209
210 eth_setenv_enetaddr("usbethaddr", msg->get_mac_address.body.resp.mac);
211
Stephen Warren6fe78452014-11-18 21:40:21 -0700212 return;
213}
214
215int misc_init_r(void)
216{
217 set_fdtfile();
218 set_usbethaddr();
Stephen Warren4f80a062014-09-26 20:51:39 -0600219 return 0;
220}
221
Stephen Warrenf66f2aa2014-01-13 19:50:11 -0700222static int power_on_module(u32 module)
223{
224 ALLOC_ALIGN_BUFFER(struct msg_set_power_state, msg_pwr, 1, 16);
225 int ret;
226
227 BCM2835_MBOX_INIT_HDR(msg_pwr);
228 BCM2835_MBOX_INIT_TAG(&msg_pwr->set_power_state,
229 SET_POWER_STATE);
230 msg_pwr->set_power_state.body.req.device_id = module;
231 msg_pwr->set_power_state.body.req.state =
232 BCM2835_MBOX_SET_POWER_STATE_REQ_ON |
233 BCM2835_MBOX_SET_POWER_STATE_REQ_WAIT;
234
235 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN,
236 &msg_pwr->hdr);
237 if (ret) {
238 printf("bcm2835: Could not set module %u power state\n",
239 module);
240 return -1;
241 }
242
243 return 0;
244}
245
Stephen Warren6fe78452014-11-18 21:40:21 -0700246static void get_board_rev(void)
247{
248 ALLOC_ALIGN_BUFFER(struct msg_get_board_rev, msg, 1, 16);
249 int ret;
250 const char *name;
251
252 BCM2835_MBOX_INIT_HDR(msg);
253 BCM2835_MBOX_INIT_TAG(&msg->get_board_rev, GET_BOARD_REV);
254
255 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr);
256 if (ret) {
257 printf("bcm2835: Could not query board revision\n");
258 /* Ignore error; not critical */
259 return;
260 }
261
262 rpi_board_rev = msg->get_board_rev.body.resp.rev;
263 if (rpi_board_rev >= ARRAY_SIZE(models))
264 rpi_board_rev = 0;
265
266 name = models[rpi_board_rev].name;
267 if (!name)
268 name = "Unknown model";
269 printf("RPI model: %s\n", name);
270}
271
Stephen Warren0d04f342012-08-05 16:07:22 +0000272int board_init(void)
273{
Stephen Warren6fe78452014-11-18 21:40:21 -0700274 get_board_rev();
275
Stephen Warren0d04f342012-08-05 16:07:22 +0000276 gd->bd->bi_boot_params = 0x100;
277
Stephen Warrenf66f2aa2014-01-13 19:50:11 -0700278 return power_on_module(BCM2835_MBOX_POWER_DEVID_USB_HCD);
Stephen Warren0d04f342012-08-05 16:07:22 +0000279}
Stephen Warren131a1e62013-01-29 16:37:42 +0000280
Jeroen Hofstee5dfd1622014-07-13 22:01:51 +0200281int board_mmc_init(bd_t *bis)
Stephen Warren131a1e62013-01-29 16:37:42 +0000282{
283 ALLOC_ALIGN_BUFFER(struct msg_get_clock_rate, msg_clk, 1, 16);
284 int ret;
285
Stephen Warrenf66f2aa2014-01-13 19:50:11 -0700286 power_on_module(BCM2835_MBOX_POWER_DEVID_SDHCI);
287
Stephen Warren131a1e62013-01-29 16:37:42 +0000288 BCM2835_MBOX_INIT_HDR(msg_clk);
289 BCM2835_MBOX_INIT_TAG(&msg_clk->get_clock_rate, GET_CLOCK_RATE);
290 msg_clk->get_clock_rate.body.req.clock_id = BCM2835_MBOX_CLOCK_ID_EMMC;
291
292 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg_clk->hdr);
293 if (ret) {
294 printf("bcm2835: Could not query eMMC clock rate\n");
295 return -1;
296 }
297
298 return bcm2835_sdhci_init(BCM2835_SDHCI_BASE,
299 msg_clk->get_clock_rate.body.resp.rate_hz);
300}
Stephen Warrenea697ae2013-05-27 18:31:18 +0000301
Simon Glasse895a4b2014-10-23 18:58:47 -0600302int ft_board_setup(void *blob, bd_t *bd)
Stephen Warrenea697ae2013-05-27 18:31:18 +0000303{
304 /*
305 * For now, we simply always add the simplefb DT node. Later, we
306 * should be more intelligent, and e.g. only do this if no enabled DT
307 * node exists for the "real" graphics driver.
308 */
309 lcd_dt_simplefb_add_node(blob);
Simon Glasse895a4b2014-10-23 18:58:47 -0600310
311 return 0;
Stephen Warrenea697ae2013-05-27 18:31:18 +0000312}