]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/raspberrypi/rpi/rpi.c
ARM: rpi: support model A+
[karo-tx-uboot.git] / board / raspberrypi / rpi / rpi.c
1 /*
2  * (C) Copyright 2012-2013 Stephen Warren
3  *
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>
18 #include <config.h>
19 #include <dm.h>
20 #include <fdt_support.h>
21 #include <lcd.h>
22 #include <mmc.h>
23 #include <asm/gpio.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>
28
29 DECLARE_GLOBAL_DATA_PTR;
30
31 static const struct bcm2835_gpio_platdata gpio_platdata = {
32         .base = BCM2835_GPIO_BASE,
33 };
34
35 U_BOOT_DEVICE(bcm2835_gpios) = {
36         .name = "gpio_bcm2835",
37         .platdata = &gpio_platdata,
38 };
39
40 static const struct pl01x_serial_platdata serial_platdata = {
41         .base = 0x20201000,
42         .type = TYPE_PL011,
43         .clock = 3000000,
44 };
45
46 U_BOOT_DEVICE(bcm2835_serials) = {
47         .name = "serial_pl01x",
48         .platdata = &serial_platdata,
49 };
50
51 struct 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
57 struct 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
63 struct 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
69 struct 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
75 struct 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
81 /* See comments in mbox.h for data source */
82 static const struct {
83         const char *name;
84         const char *fdtfile;
85         bool has_onboard_eth;
86 } models[] = {
87         [BCM2835_BOARD_REV_B_I2C0_2] = {
88                 "Model B (no P5)",
89                 "bcm2835-rpi-b-i2c0.dtb",
90                 true,
91         },
92         [BCM2835_BOARD_REV_B_I2C0_3] = {
93                 "Model B (no P5)",
94                 "bcm2835-rpi-b-i2c0.dtb",
95                 true,
96         },
97         [BCM2835_BOARD_REV_B_I2C1_4] = {
98                 "Model B",
99                 "bcm2835-rpi-b.dtb",
100                 true,
101         },
102         [BCM2835_BOARD_REV_B_I2C1_5] = {
103                 "Model B",
104                 "bcm2835-rpi-b.dtb",
105                 true,
106         },
107         [BCM2835_BOARD_REV_B_I2C1_6] = {
108                 "Model B",
109                 "bcm2835-rpi-b.dtb",
110                 true,
111         },
112         [BCM2835_BOARD_REV_A_7] = {
113                 "Model A",
114                 "bcm2835-rpi-a.dtb",
115                 false,
116         },
117         [BCM2835_BOARD_REV_A_8] = {
118                 "Model A",
119                 "bcm2835-rpi-a.dtb",
120                 false,
121         },
122         [BCM2835_BOARD_REV_A_9] = {
123                 "Model A",
124                 "bcm2835-rpi-a.dtb",
125                 false,
126         },
127         [BCM2835_BOARD_REV_B_REV2_d] = {
128                 "Model B rev2",
129                 "bcm2835-rpi-b-rev2.dtb",
130                 true,
131         },
132         [BCM2835_BOARD_REV_B_REV2_e] = {
133                 "Model B rev2",
134                 "bcm2835-rpi-b-rev2.dtb",
135                 true,
136         },
137         [BCM2835_BOARD_REV_B_REV2_f] = {
138                 "Model B rev2",
139                 "bcm2835-rpi-b-rev2.dtb",
140                 true,
141         },
142         [BCM2835_BOARD_REV_B_PLUS] = {
143                 "Model B+",
144                 "bcm2835-rpi-b-plus.dtb",
145                 true,
146         },
147         [BCM2835_BOARD_REV_CM] = {
148                 "Compute Module",
149                 "bcm2835-rpi-cm.dtb",
150                 false,
151         },
152         [BCM2835_BOARD_REV_A_PLUS] = {
153                 "Model A+",
154                 "bcm2835-rpi-a-plus.dtb",
155                 false,
156         },
157 };
158
159 u32 rpi_board_rev = 0;
160
161 int dram_init(void)
162 {
163         ALLOC_ALIGN_BUFFER(struct msg_get_arm_mem, msg, 1, 16);
164         int ret;
165
166         BCM2835_MBOX_INIT_HDR(msg);
167         BCM2835_MBOX_INIT_TAG(&msg->get_arm_mem, GET_ARM_MEMORY);
168
169         ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr);
170         if (ret) {
171                 printf("bcm2835: Could not query ARM memory size\n");
172                 return -1;
173         }
174
175         gd->ram_size = msg->get_arm_mem.body.resp.mem_size;
176
177         return 0;
178 }
179
180 static void set_fdtfile(void)
181 {
182         const char *fdtfile;
183
184         if (getenv("fdtfile"))
185                 return;
186
187         fdtfile = models[rpi_board_rev].fdtfile;
188         if (!fdtfile)
189                 fdtfile = "bcm2835-rpi-other.dtb";
190
191         setenv("fdtfile", fdtfile);
192 }
193
194 static void set_usbethaddr(void)
195 {
196         ALLOC_ALIGN_BUFFER(struct msg_get_mac_address, msg, 1, 16);
197         int ret;
198
199         if (!models[rpi_board_rev].has_onboard_eth)
200                 return;
201
202         if (getenv("usbethaddr"))
203                 return;
204
205         BCM2835_MBOX_INIT_HDR(msg);
206         BCM2835_MBOX_INIT_TAG(&msg->get_mac_address, GET_MAC_ADDRESS);
207
208         ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr);
209         if (ret) {
210                 printf("bcm2835: Could not query MAC address\n");
211                 /* Ignore error; not critical */
212                 return;
213         }
214
215         eth_setenv_enetaddr("usbethaddr", msg->get_mac_address.body.resp.mac);
216
217         return;
218 }
219
220 int misc_init_r(void)
221 {
222         set_fdtfile();
223         set_usbethaddr();
224         return 0;
225 }
226
227 static int power_on_module(u32 module)
228 {
229         ALLOC_ALIGN_BUFFER(struct msg_set_power_state, msg_pwr, 1, 16);
230         int ret;
231
232         BCM2835_MBOX_INIT_HDR(msg_pwr);
233         BCM2835_MBOX_INIT_TAG(&msg_pwr->set_power_state,
234                               SET_POWER_STATE);
235         msg_pwr->set_power_state.body.req.device_id = module;
236         msg_pwr->set_power_state.body.req.state =
237                 BCM2835_MBOX_SET_POWER_STATE_REQ_ON |
238                 BCM2835_MBOX_SET_POWER_STATE_REQ_WAIT;
239
240         ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN,
241                                      &msg_pwr->hdr);
242         if (ret) {
243                 printf("bcm2835: Could not set module %u power state\n",
244                        module);
245                 return -1;
246         }
247
248         return 0;
249 }
250
251 static void get_board_rev(void)
252 {
253         ALLOC_ALIGN_BUFFER(struct msg_get_board_rev, msg, 1, 16);
254         int ret;
255         const char *name;
256
257         BCM2835_MBOX_INIT_HDR(msg);
258         BCM2835_MBOX_INIT_TAG(&msg->get_board_rev, GET_BOARD_REV);
259
260         ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr);
261         if (ret) {
262                 printf("bcm2835: Could not query board revision\n");
263                 /* Ignore error; not critical */
264                 return;
265         }
266
267         rpi_board_rev = msg->get_board_rev.body.resp.rev;
268         if (rpi_board_rev >= ARRAY_SIZE(models)) {
269                 printf("RPI: Board rev %u outside known range\n",
270                        rpi_board_rev);
271                 rpi_board_rev = 0;
272         }
273
274         name = models[rpi_board_rev].name;
275         if (!name) {
276                 printf("RPI: Board rev %u unknown\n", rpi_board_rev);
277                 name = "Unknown model";
278         }
279         printf("RPI model: %s\n", name);
280 }
281
282 int board_init(void)
283 {
284         get_board_rev();
285
286         gd->bd->bi_boot_params = 0x100;
287
288         return power_on_module(BCM2835_MBOX_POWER_DEVID_USB_HCD);
289 }
290
291 int board_mmc_init(bd_t *bis)
292 {
293         ALLOC_ALIGN_BUFFER(struct msg_get_clock_rate, msg_clk, 1, 16);
294         int ret;
295
296         power_on_module(BCM2835_MBOX_POWER_DEVID_SDHCI);
297
298         BCM2835_MBOX_INIT_HDR(msg_clk);
299         BCM2835_MBOX_INIT_TAG(&msg_clk->get_clock_rate, GET_CLOCK_RATE);
300         msg_clk->get_clock_rate.body.req.clock_id = BCM2835_MBOX_CLOCK_ID_EMMC;
301
302         ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg_clk->hdr);
303         if (ret) {
304                 printf("bcm2835: Could not query eMMC clock rate\n");
305                 return -1;
306         }
307
308         return bcm2835_sdhci_init(BCM2835_SDHCI_BASE,
309                                   msg_clk->get_clock_rate.body.resp.rate_hz);
310 }
311
312 int ft_board_setup(void *blob, bd_t *bd)
313 {
314         /*
315          * For now, we simply always add the simplefb DT node. Later, we
316          * should be more intelligent, and e.g. only do this if no enabled DT
317          * node exists for the "real" graphics driver.
318          */
319         lcd_dt_simplefb_add_node(blob);
320
321         return 0;
322 }