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