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; |
| 85 | } models[] = { |
| 86 | [BCM2835_BOARD_REV_B_I2C0_2] = { |
| 87 | "Model B (no P5)", |
| 88 | "bcm2835-rpi-b-i2c0.dtb", |
| 89 | }, |
| 90 | [BCM2835_BOARD_REV_B_I2C0_3] = { |
| 91 | "Model B (no P5)", |
| 92 | "bcm2835-rpi-b-i2c0.dtb", |
| 93 | }, |
| 94 | [BCM2835_BOARD_REV_B_I2C1_4] = { |
| 95 | "Model B", |
| 96 | "bcm2835-rpi-b.dtb", |
| 97 | }, |
| 98 | [BCM2835_BOARD_REV_B_I2C1_5] = { |
| 99 | "Model B", |
| 100 | "bcm2835-rpi-b.dtb", |
| 101 | }, |
| 102 | [BCM2835_BOARD_REV_B_I2C1_6] = { |
| 103 | "Model B", |
| 104 | "bcm2835-rpi-b.dtb", |
| 105 | }, |
| 106 | [BCM2835_BOARD_REV_A_7] = { |
| 107 | "Model A", |
| 108 | "bcm2835-rpi-a.dtb", |
| 109 | }, |
| 110 | [BCM2835_BOARD_REV_A_8] = { |
| 111 | "Model A", |
| 112 | "bcm2835-rpi-a.dtb", |
| 113 | }, |
| 114 | [BCM2835_BOARD_REV_A_9] = { |
| 115 | "Model A", |
| 116 | "bcm2835-rpi-a.dtb", |
| 117 | }, |
| 118 | [BCM2835_BOARD_REV_B_REV2_d] = { |
| 119 | "Model B rev2", |
| 120 | "bcm2835-rpi-b-rev2.dtb", |
| 121 | }, |
| 122 | [BCM2835_BOARD_REV_B_REV2_e] = { |
| 123 | "Model B rev2", |
| 124 | "bcm2835-rpi-b-rev2.dtb", |
| 125 | }, |
| 126 | [BCM2835_BOARD_REV_B_REV2_f] = { |
| 127 | "Model B rev2", |
| 128 | "bcm2835-rpi-b-rev2.dtb", |
| 129 | }, |
| 130 | [BCM2835_BOARD_REV_B_PLUS] = { |
| 131 | "Model B+", |
| 132 | "bcm2835-rpi-b-plus.dtb", |
| 133 | }, |
| 134 | [BCM2835_BOARD_REV_CM] = { |
| 135 | "Compute Module", |
| 136 | "bcm2835-rpi-cm.dtb", |
| 137 | }, |
| 138 | }; |
| 139 | |
| 140 | u32 rpi_board_rev = 0; |
| 141 | |
Stephen Warren | 0d04f34 | 2012-08-05 16:07:22 +0000 | [diff] [blame] | 142 | int dram_init(void) |
| 143 | { |
Stephen Warren | 3f39778 | 2013-01-29 16:37:37 +0000 | [diff] [blame] | 144 | ALLOC_ALIGN_BUFFER(struct msg_get_arm_mem, msg, 1, 16); |
| 145 | int ret; |
| 146 | |
| 147 | BCM2835_MBOX_INIT_HDR(msg); |
| 148 | BCM2835_MBOX_INIT_TAG(&msg->get_arm_mem, GET_ARM_MEMORY); |
| 149 | |
| 150 | ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr); |
| 151 | if (ret) { |
| 152 | printf("bcm2835: Could not query ARM memory size\n"); |
| 153 | return -1; |
| 154 | } |
| 155 | |
| 156 | gd->ram_size = msg->get_arm_mem.body.resp.mem_size; |
Stephen Warren | 0d04f34 | 2012-08-05 16:07:22 +0000 | [diff] [blame] | 157 | |
| 158 | return 0; |
| 159 | } |
| 160 | |
Stephen Warren | 6fe7845 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 161 | static void set_fdtfile(void) |
| 162 | { |
| 163 | const char *fdtfile; |
| 164 | |
| 165 | if (getenv("fdtfile")) |
| 166 | return; |
| 167 | |
| 168 | fdtfile = models[rpi_board_rev].fdtfile; |
| 169 | if (!fdtfile) |
| 170 | fdtfile = "bcm2835-rpi-other.dtb"; |
| 171 | |
| 172 | setenv("fdtfile", fdtfile); |
| 173 | } |
| 174 | |
| 175 | static void set_usbethaddr(void) |
Stephen Warren | 4f80a06 | 2014-09-26 20:51:39 -0600 | [diff] [blame] | 176 | { |
| 177 | ALLOC_ALIGN_BUFFER(struct msg_get_mac_address, msg, 1, 16); |
| 178 | int ret; |
| 179 | |
| 180 | if (getenv("usbethaddr")) |
Stephen Warren | 6fe7845 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 181 | return; |
Stephen Warren | 4f80a06 | 2014-09-26 20:51:39 -0600 | [diff] [blame] | 182 | |
| 183 | BCM2835_MBOX_INIT_HDR(msg); |
| 184 | BCM2835_MBOX_INIT_TAG(&msg->get_mac_address, GET_MAC_ADDRESS); |
| 185 | |
| 186 | ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr); |
| 187 | if (ret) { |
| 188 | printf("bcm2835: Could not query MAC address\n"); |
| 189 | /* Ignore error; not critical */ |
Stephen Warren | 6fe7845 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 190 | return; |
Stephen Warren | 4f80a06 | 2014-09-26 20:51:39 -0600 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | eth_setenv_enetaddr("usbethaddr", msg->get_mac_address.body.resp.mac); |
| 194 | |
Stephen Warren | 6fe7845 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 195 | return; |
| 196 | } |
| 197 | |
| 198 | int misc_init_r(void) |
| 199 | { |
| 200 | set_fdtfile(); |
| 201 | set_usbethaddr(); |
Stephen Warren | 4f80a06 | 2014-09-26 20:51:39 -0600 | [diff] [blame] | 202 | return 0; |
| 203 | } |
| 204 | |
Stephen Warren | f66f2aa | 2014-01-13 19:50:11 -0700 | [diff] [blame] | 205 | static int power_on_module(u32 module) |
| 206 | { |
| 207 | ALLOC_ALIGN_BUFFER(struct msg_set_power_state, msg_pwr, 1, 16); |
| 208 | int ret; |
| 209 | |
| 210 | BCM2835_MBOX_INIT_HDR(msg_pwr); |
| 211 | BCM2835_MBOX_INIT_TAG(&msg_pwr->set_power_state, |
| 212 | SET_POWER_STATE); |
| 213 | msg_pwr->set_power_state.body.req.device_id = module; |
| 214 | msg_pwr->set_power_state.body.req.state = |
| 215 | BCM2835_MBOX_SET_POWER_STATE_REQ_ON | |
| 216 | BCM2835_MBOX_SET_POWER_STATE_REQ_WAIT; |
| 217 | |
| 218 | ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, |
| 219 | &msg_pwr->hdr); |
| 220 | if (ret) { |
| 221 | printf("bcm2835: Could not set module %u power state\n", |
| 222 | module); |
| 223 | return -1; |
| 224 | } |
| 225 | |
| 226 | return 0; |
| 227 | } |
| 228 | |
Stephen Warren | 6fe7845 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 229 | static void get_board_rev(void) |
| 230 | { |
| 231 | ALLOC_ALIGN_BUFFER(struct msg_get_board_rev, msg, 1, 16); |
| 232 | int ret; |
| 233 | const char *name; |
| 234 | |
| 235 | BCM2835_MBOX_INIT_HDR(msg); |
| 236 | BCM2835_MBOX_INIT_TAG(&msg->get_board_rev, GET_BOARD_REV); |
| 237 | |
| 238 | ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr); |
| 239 | if (ret) { |
| 240 | printf("bcm2835: Could not query board revision\n"); |
| 241 | /* Ignore error; not critical */ |
| 242 | return; |
| 243 | } |
| 244 | |
| 245 | rpi_board_rev = msg->get_board_rev.body.resp.rev; |
| 246 | if (rpi_board_rev >= ARRAY_SIZE(models)) |
| 247 | rpi_board_rev = 0; |
| 248 | |
| 249 | name = models[rpi_board_rev].name; |
| 250 | if (!name) |
| 251 | name = "Unknown model"; |
| 252 | printf("RPI model: %s\n", name); |
| 253 | } |
| 254 | |
Stephen Warren | 0d04f34 | 2012-08-05 16:07:22 +0000 | [diff] [blame] | 255 | int board_init(void) |
| 256 | { |
Stephen Warren | 6fe7845 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 257 | get_board_rev(); |
| 258 | |
Stephen Warren | 0d04f34 | 2012-08-05 16:07:22 +0000 | [diff] [blame] | 259 | gd->bd->bi_boot_params = 0x100; |
| 260 | |
Stephen Warren | f66f2aa | 2014-01-13 19:50:11 -0700 | [diff] [blame] | 261 | return power_on_module(BCM2835_MBOX_POWER_DEVID_USB_HCD); |
Stephen Warren | 0d04f34 | 2012-08-05 16:07:22 +0000 | [diff] [blame] | 262 | } |
Stephen Warren | 131a1e6 | 2013-01-29 16:37:42 +0000 | [diff] [blame] | 263 | |
Jeroen Hofstee | 5dfd162 | 2014-07-13 22:01:51 +0200 | [diff] [blame] | 264 | int board_mmc_init(bd_t *bis) |
Stephen Warren | 131a1e6 | 2013-01-29 16:37:42 +0000 | [diff] [blame] | 265 | { |
| 266 | ALLOC_ALIGN_BUFFER(struct msg_get_clock_rate, msg_clk, 1, 16); |
| 267 | int ret; |
| 268 | |
Stephen Warren | f66f2aa | 2014-01-13 19:50:11 -0700 | [diff] [blame] | 269 | power_on_module(BCM2835_MBOX_POWER_DEVID_SDHCI); |
| 270 | |
Stephen Warren | 131a1e6 | 2013-01-29 16:37:42 +0000 | [diff] [blame] | 271 | BCM2835_MBOX_INIT_HDR(msg_clk); |
| 272 | BCM2835_MBOX_INIT_TAG(&msg_clk->get_clock_rate, GET_CLOCK_RATE); |
| 273 | msg_clk->get_clock_rate.body.req.clock_id = BCM2835_MBOX_CLOCK_ID_EMMC; |
| 274 | |
| 275 | ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg_clk->hdr); |
| 276 | if (ret) { |
| 277 | printf("bcm2835: Could not query eMMC clock rate\n"); |
| 278 | return -1; |
| 279 | } |
| 280 | |
| 281 | return bcm2835_sdhci_init(BCM2835_SDHCI_BASE, |
| 282 | msg_clk->get_clock_rate.body.resp.rate_hz); |
| 283 | } |
Stephen Warren | ea697ae | 2013-05-27 18:31:18 +0000 | [diff] [blame] | 284 | |
Simon Glass | e895a4b | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 285 | int ft_board_setup(void *blob, bd_t *bd) |
Stephen Warren | ea697ae | 2013-05-27 18:31:18 +0000 | [diff] [blame] | 286 | { |
| 287 | /* |
| 288 | * For now, we simply always add the simplefb DT node. Later, we |
| 289 | * should be more intelligent, and e.g. only do this if no enabled DT |
| 290 | * node exists for the "real" graphics driver. |
| 291 | */ |
| 292 | lcd_dt_simplefb_add_node(blob); |
Simon Glass | e895a4b | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 293 | |
| 294 | return 0; |
Stephen Warren | ea697ae | 2013-05-27 18:31:18 +0000 | [diff] [blame] | 295 | } |