Stephen Warren | 0d04f34 | 2012-08-05 16:07:22 +0000 | [diff] [blame] | 1 | /* |
Stephen Warren | ea697ae | 2013-05-27 18:31:18 +0000 | [diff] [blame] | 2 | * (C) Copyright 2012-2013 Stephen Warren |
Stephen Warren | 0d04f34 | 2012-08-05 16:07:22 +0000 | [diff] [blame] | 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> |
Stephen Warren | ea697ae | 2013-05-27 18:31:18 +0000 | [diff] [blame] | 18 | #include <config.h> |
Simon Glass | 41e98e0 | 2014-09-22 17:30:56 -0600 | [diff] [blame] | 19 | #include <dm.h> |
Jeroen Hofstee | 5dfd162 | 2014-07-13 22:01:51 +0200 | [diff] [blame] | 20 | #include <fdt_support.h> |
Stephen Warren | ea697ae | 2013-05-27 18:31:18 +0000 | [diff] [blame] | 21 | #include <lcd.h> |
Jeroen Hofstee | 5dfd162 | 2014-07-13 22:01:51 +0200 | [diff] [blame] | 22 | #include <mmc.h> |
Simon Glass | 41e98e0 | 2014-09-22 17:30:56 -0600 | [diff] [blame] | 23 | #include <asm/gpio.h> |
Stephen Warren | 3f39778 | 2013-01-29 16:37:37 +0000 | [diff] [blame] | 24 | #include <asm/arch/mbox.h> |
Stephen Warren | 131a1e6 | 2013-01-29 16:37:42 +0000 | [diff] [blame] | 25 | #include <asm/arch/sdhci.h> |
Stephen Warren | 0d04f34 | 2012-08-05 16:07:22 +0000 | [diff] [blame] | 26 | #include <asm/global_data.h> |
Simon Glass | 1150666 | 2014-11-24 21:36:34 -0700 | [diff] [blame] | 27 | #include <dm/platform_data/serial_pl01x.h> |
Stephen Warren | 0d04f34 | 2012-08-05 16:07:22 +0000 | [diff] [blame] | 28 | |
| 29 | DECLARE_GLOBAL_DATA_PTR; |
| 30 | |
Simon Glass | 41e98e0 | 2014-09-22 17:30:56 -0600 | [diff] [blame] | 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 | |
Simon Glass | 1150666 | 2014-11-24 21:36:34 -0700 | [diff] [blame] | 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 | |
Stephen Warren | 3f39778 | 2013-01-29 16:37:37 +0000 | [diff] [blame] | 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 | |
Stephen Warren | 6fe7845 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 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 | |
Stephen Warren | 4f80a06 | 2014-09-26 20:51:39 -0600 | [diff] [blame] | 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 | |
Stephen Warren | f66f2aa | 2014-01-13 19:50:11 -0700 | [diff] [blame] | 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 | |
Stephen Warren | 131a1e6 | 2013-01-29 16:37:42 +0000 | [diff] [blame] | 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 | |
Stephen Warren | 6fe7845 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 81 | /* See comments in mbox.h for data source */ |
| 82 | static const struct { |
| 83 | const char *name; |
| 84 | const char *fdtfile; |
Stephen Warren | 3207d8f | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 85 | bool has_onboard_eth; |
Stephen Warren | 6fe7845 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 86 | } models[] = { |
Stephen Warren | 914627f | 2014-12-23 20:01:44 -0700 | [diff] [blame] | 87 | [0] = { |
| 88 | "Unknown model", |
| 89 | "bcm2835-rpi-other.dtb", |
| 90 | false, |
| 91 | }, |
Stephen Warren | 6fe7845 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 92 | [BCM2835_BOARD_REV_B_I2C0_2] = { |
| 93 | "Model B (no P5)", |
| 94 | "bcm2835-rpi-b-i2c0.dtb", |
Stephen Warren | 3207d8f | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 95 | true, |
Stephen Warren | 6fe7845 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 96 | }, |
| 97 | [BCM2835_BOARD_REV_B_I2C0_3] = { |
| 98 | "Model B (no P5)", |
| 99 | "bcm2835-rpi-b-i2c0.dtb", |
Stephen Warren | 3207d8f | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 100 | true, |
Stephen Warren | 6fe7845 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 101 | }, |
| 102 | [BCM2835_BOARD_REV_B_I2C1_4] = { |
| 103 | "Model B", |
| 104 | "bcm2835-rpi-b.dtb", |
Stephen Warren | 3207d8f | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 105 | true, |
Stephen Warren | 6fe7845 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 106 | }, |
| 107 | [BCM2835_BOARD_REV_B_I2C1_5] = { |
| 108 | "Model B", |
| 109 | "bcm2835-rpi-b.dtb", |
Stephen Warren | 3207d8f | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 110 | true, |
Stephen Warren | 6fe7845 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 111 | }, |
| 112 | [BCM2835_BOARD_REV_B_I2C1_6] = { |
| 113 | "Model B", |
| 114 | "bcm2835-rpi-b.dtb", |
Stephen Warren | 3207d8f | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 115 | true, |
Stephen Warren | 6fe7845 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 116 | }, |
| 117 | [BCM2835_BOARD_REV_A_7] = { |
| 118 | "Model A", |
| 119 | "bcm2835-rpi-a.dtb", |
Stephen Warren | 3207d8f | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 120 | false, |
Stephen Warren | 6fe7845 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 121 | }, |
| 122 | [BCM2835_BOARD_REV_A_8] = { |
| 123 | "Model A", |
| 124 | "bcm2835-rpi-a.dtb", |
Stephen Warren | 3207d8f | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 125 | false, |
Stephen Warren | 6fe7845 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 126 | }, |
| 127 | [BCM2835_BOARD_REV_A_9] = { |
| 128 | "Model A", |
| 129 | "bcm2835-rpi-a.dtb", |
Stephen Warren | 3207d8f | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 130 | false, |
Stephen Warren | 6fe7845 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 131 | }, |
| 132 | [BCM2835_BOARD_REV_B_REV2_d] = { |
| 133 | "Model B rev2", |
| 134 | "bcm2835-rpi-b-rev2.dtb", |
Stephen Warren | 3207d8f | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 135 | true, |
Stephen Warren | 6fe7845 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 136 | }, |
| 137 | [BCM2835_BOARD_REV_B_REV2_e] = { |
| 138 | "Model B rev2", |
| 139 | "bcm2835-rpi-b-rev2.dtb", |
Stephen Warren | 3207d8f | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 140 | true, |
Stephen Warren | 6fe7845 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 141 | }, |
| 142 | [BCM2835_BOARD_REV_B_REV2_f] = { |
| 143 | "Model B rev2", |
| 144 | "bcm2835-rpi-b-rev2.dtb", |
Stephen Warren | 3207d8f | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 145 | true, |
Stephen Warren | 6fe7845 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 146 | }, |
| 147 | [BCM2835_BOARD_REV_B_PLUS] = { |
| 148 | "Model B+", |
| 149 | "bcm2835-rpi-b-plus.dtb", |
Stephen Warren | 3207d8f | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 150 | true, |
Stephen Warren | 6fe7845 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 151 | }, |
| 152 | [BCM2835_BOARD_REV_CM] = { |
| 153 | "Compute Module", |
| 154 | "bcm2835-rpi-cm.dtb", |
Stephen Warren | 3207d8f | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 155 | false, |
Stephen Warren | 6fe7845 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 156 | }, |
Stephen Warren | 47705ef | 2014-12-23 20:01:43 -0700 | [diff] [blame] | 157 | [BCM2835_BOARD_REV_A_PLUS] = { |
| 158 | "Model A+", |
| 159 | "bcm2835-rpi-a-plus.dtb", |
| 160 | false, |
| 161 | }, |
Stephen Warren | 6fe7845 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 162 | }; |
| 163 | |
| 164 | u32 rpi_board_rev = 0; |
| 165 | |
Stephen Warren | 0d04f34 | 2012-08-05 16:07:22 +0000 | [diff] [blame] | 166 | int dram_init(void) |
| 167 | { |
Stephen Warren | 3f39778 | 2013-01-29 16:37:37 +0000 | [diff] [blame] | 168 | ALLOC_ALIGN_BUFFER(struct msg_get_arm_mem, msg, 1, 16); |
| 169 | int ret; |
| 170 | |
| 171 | BCM2835_MBOX_INIT_HDR(msg); |
| 172 | BCM2835_MBOX_INIT_TAG(&msg->get_arm_mem, GET_ARM_MEMORY); |
| 173 | |
| 174 | ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr); |
| 175 | if (ret) { |
| 176 | printf("bcm2835: Could not query ARM memory size\n"); |
| 177 | return -1; |
| 178 | } |
| 179 | |
| 180 | gd->ram_size = msg->get_arm_mem.body.resp.mem_size; |
Stephen Warren | 0d04f34 | 2012-08-05 16:07:22 +0000 | [diff] [blame] | 181 | |
| 182 | return 0; |
| 183 | } |
| 184 | |
Stephen Warren | 6fe7845 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 185 | static void set_fdtfile(void) |
| 186 | { |
| 187 | const char *fdtfile; |
| 188 | |
| 189 | if (getenv("fdtfile")) |
| 190 | return; |
| 191 | |
| 192 | fdtfile = models[rpi_board_rev].fdtfile; |
Stephen Warren | 6fe7845 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 193 | setenv("fdtfile", fdtfile); |
| 194 | } |
| 195 | |
| 196 | static void set_usbethaddr(void) |
Stephen Warren | 4f80a06 | 2014-09-26 20:51:39 -0600 | [diff] [blame] | 197 | { |
| 198 | ALLOC_ALIGN_BUFFER(struct msg_get_mac_address, msg, 1, 16); |
| 199 | int ret; |
| 200 | |
Stephen Warren | 3207d8f | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 201 | if (!models[rpi_board_rev].has_onboard_eth) |
| 202 | return; |
| 203 | |
Stephen Warren | 4f80a06 | 2014-09-26 20:51:39 -0600 | [diff] [blame] | 204 | if (getenv("usbethaddr")) |
Stephen Warren | 6fe7845 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 205 | return; |
Stephen Warren | 4f80a06 | 2014-09-26 20:51:39 -0600 | [diff] [blame] | 206 | |
| 207 | BCM2835_MBOX_INIT_HDR(msg); |
| 208 | BCM2835_MBOX_INIT_TAG(&msg->get_mac_address, GET_MAC_ADDRESS); |
| 209 | |
| 210 | ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr); |
| 211 | if (ret) { |
| 212 | printf("bcm2835: Could not query MAC address\n"); |
| 213 | /* Ignore error; not critical */ |
Stephen Warren | 6fe7845 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 214 | return; |
Stephen Warren | 4f80a06 | 2014-09-26 20:51:39 -0600 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | eth_setenv_enetaddr("usbethaddr", msg->get_mac_address.body.resp.mac); |
| 218 | |
Stephen Warren | 6fe7845 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 219 | return; |
| 220 | } |
| 221 | |
| 222 | int misc_init_r(void) |
| 223 | { |
| 224 | set_fdtfile(); |
| 225 | set_usbethaddr(); |
Stephen Warren | 4f80a06 | 2014-09-26 20:51:39 -0600 | [diff] [blame] | 226 | return 0; |
| 227 | } |
| 228 | |
Stephen Warren | f66f2aa | 2014-01-13 19:50:11 -0700 | [diff] [blame] | 229 | static int power_on_module(u32 module) |
| 230 | { |
| 231 | ALLOC_ALIGN_BUFFER(struct msg_set_power_state, msg_pwr, 1, 16); |
| 232 | int ret; |
| 233 | |
| 234 | BCM2835_MBOX_INIT_HDR(msg_pwr); |
| 235 | BCM2835_MBOX_INIT_TAG(&msg_pwr->set_power_state, |
| 236 | 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; |
| 241 | |
| 242 | ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, |
| 243 | &msg_pwr->hdr); |
| 244 | if (ret) { |
| 245 | printf("bcm2835: Could not set module %u power state\n", |
| 246 | module); |
| 247 | return -1; |
| 248 | } |
| 249 | |
| 250 | return 0; |
| 251 | } |
| 252 | |
Stephen Warren | 6fe7845 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 253 | static void get_board_rev(void) |
| 254 | { |
| 255 | ALLOC_ALIGN_BUFFER(struct msg_get_board_rev, msg, 1, 16); |
| 256 | int ret; |
| 257 | const char *name; |
| 258 | |
| 259 | BCM2835_MBOX_INIT_HDR(msg); |
| 260 | BCM2835_MBOX_INIT_TAG(&msg->get_board_rev, GET_BOARD_REV); |
| 261 | |
| 262 | ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr); |
| 263 | if (ret) { |
| 264 | printf("bcm2835: Could not query board revision\n"); |
| 265 | /* Ignore error; not critical */ |
| 266 | return; |
| 267 | } |
| 268 | |
| 269 | rpi_board_rev = msg->get_board_rev.body.resp.rev; |
Stephen Warren | 47705ef | 2014-12-23 20:01:43 -0700 | [diff] [blame] | 270 | if (rpi_board_rev >= ARRAY_SIZE(models)) { |
| 271 | printf("RPI: Board rev %u outside known range\n", |
| 272 | rpi_board_rev); |
Stephen Warren | 6fe7845 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 273 | rpi_board_rev = 0; |
Stephen Warren | 47705ef | 2014-12-23 20:01:43 -0700 | [diff] [blame] | 274 | } |
Stephen Warren | 914627f | 2014-12-23 20:01:44 -0700 | [diff] [blame] | 275 | if (!models[rpi_board_rev].name) { |
| 276 | printf("RPI: Board rev %u unknown\n", rpi_board_rev); |
| 277 | rpi_board_rev = 0; |
| 278 | } |
Stephen Warren | 6fe7845 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 279 | |
| 280 | name = models[rpi_board_rev].name; |
Stephen Warren | 6fe7845 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 281 | printf("RPI model: %s\n", name); |
| 282 | } |
| 283 | |
Stephen Warren | 0d04f34 | 2012-08-05 16:07:22 +0000 | [diff] [blame] | 284 | int board_init(void) |
| 285 | { |
Stephen Warren | 6fe7845 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 286 | get_board_rev(); |
| 287 | |
Stephen Warren | 0d04f34 | 2012-08-05 16:07:22 +0000 | [diff] [blame] | 288 | gd->bd->bi_boot_params = 0x100; |
| 289 | |
Stephen Warren | f66f2aa | 2014-01-13 19:50:11 -0700 | [diff] [blame] | 290 | return power_on_module(BCM2835_MBOX_POWER_DEVID_USB_HCD); |
Stephen Warren | 0d04f34 | 2012-08-05 16:07:22 +0000 | [diff] [blame] | 291 | } |
Stephen Warren | 131a1e6 | 2013-01-29 16:37:42 +0000 | [diff] [blame] | 292 | |
Jeroen Hofstee | 5dfd162 | 2014-07-13 22:01:51 +0200 | [diff] [blame] | 293 | int board_mmc_init(bd_t *bis) |
Stephen Warren | 131a1e6 | 2013-01-29 16:37:42 +0000 | [diff] [blame] | 294 | { |
| 295 | ALLOC_ALIGN_BUFFER(struct msg_get_clock_rate, msg_clk, 1, 16); |
| 296 | int ret; |
| 297 | |
Stephen Warren | f66f2aa | 2014-01-13 19:50:11 -0700 | [diff] [blame] | 298 | power_on_module(BCM2835_MBOX_POWER_DEVID_SDHCI); |
| 299 | |
Stephen Warren | 131a1e6 | 2013-01-29 16:37:42 +0000 | [diff] [blame] | 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; |
| 303 | |
| 304 | ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg_clk->hdr); |
| 305 | if (ret) { |
| 306 | printf("bcm2835: Could not query eMMC clock rate\n"); |
| 307 | return -1; |
| 308 | } |
| 309 | |
| 310 | return bcm2835_sdhci_init(BCM2835_SDHCI_BASE, |
| 311 | msg_clk->get_clock_rate.body.resp.rate_hz); |
| 312 | } |
Stephen Warren | ea697ae | 2013-05-27 18:31:18 +0000 | [diff] [blame] | 313 | |
Simon Glass | e895a4b | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 314 | int ft_board_setup(void *blob, bd_t *bd) |
Stephen Warren | ea697ae | 2013-05-27 18:31:18 +0000 | [diff] [blame] | 315 | { |
| 316 | /* |
| 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. |
| 320 | */ |
| 321 | lcd_dt_simplefb_add_node(blob); |
Simon Glass | e895a4b | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 322 | |
| 323 | return 0; |
Stephen Warren | ea697ae | 2013-05-27 18:31:18 +0000 | [diff] [blame] | 324 | } |