Stephen Warren | 0e012c3 | 2012-08-05 16:07:22 +0000 | [diff] [blame] | 1 | /* |
Stephen Warren | d6f47c8 | 2016-03-24 22:15:20 -0600 | [diff] [blame] | 2 | * (C) Copyright 2012-2016 Stephen Warren |
Stephen Warren | 0e012c3 | 2012-08-05 16:07:22 +0000 | [diff] [blame] | 3 | * |
Stephen Warren | 29e494c | 2015-02-16 12:16:13 -0700 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0 |
Stephen Warren | 0e012c3 | 2012-08-05 16:07:22 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Lubomir Rintel | 7d33bb6 | 2016-02-22 22:06:47 +0100 | [diff] [blame] | 8 | #include <inttypes.h> |
Stephen Warren | aa44d53 | 2013-05-27 18:31:18 +0000 | [diff] [blame] | 9 | #include <config.h> |
Simon Glass | 7480762 | 2014-09-22 17:30:56 -0600 | [diff] [blame] | 10 | #include <dm.h> |
Jeroen Hofstee | d5b2fed | 2014-07-13 22:01:51 +0200 | [diff] [blame] | 11 | #include <fdt_support.h> |
Nikita Kiryanov | b071e4c | 2015-02-03 13:32:31 +0200 | [diff] [blame] | 12 | #include <fdt_simplefb.h> |
Stephen Warren | aa44d53 | 2013-05-27 18:31:18 +0000 | [diff] [blame] | 13 | #include <lcd.h> |
Simon Glass | 2dd337a | 2015-09-02 17:24:58 -0600 | [diff] [blame] | 14 | #include <memalign.h> |
Jeroen Hofstee | d5b2fed | 2014-07-13 22:01:51 +0200 | [diff] [blame] | 15 | #include <mmc.h> |
Simon Glass | 7480762 | 2014-09-22 17:30:56 -0600 | [diff] [blame] | 16 | #include <asm/gpio.h> |
Stephen Warren | acc8bf4 | 2013-01-29 16:37:37 +0000 | [diff] [blame] | 17 | #include <asm/arch/mbox.h> |
Stephen Warren | c4ab971 | 2013-01-29 16:37:42 +0000 | [diff] [blame] | 18 | #include <asm/arch/sdhci.h> |
Stephen Warren | 0e012c3 | 2012-08-05 16:07:22 +0000 | [diff] [blame] | 19 | #include <asm/global_data.h> |
Simon Glass | f52cada | 2014-11-24 21:36:34 -0700 | [diff] [blame] | 20 | #include <dm/platform_data/serial_pl01x.h> |
Stephen Warren | d6f47c8 | 2016-03-24 22:15:20 -0600 | [diff] [blame] | 21 | #include <dm/platform_data/serial_bcm283x_mu.h> |
Stephen Warren | 93ea526 | 2016-04-01 21:14:15 -0600 | [diff] [blame] | 22 | #ifdef CONFIG_ARM64 |
| 23 | #include <asm/armv8/mmu.h> |
| 24 | #endif |
Stephen Warren | 0e012c3 | 2012-08-05 16:07:22 +0000 | [diff] [blame] | 25 | |
| 26 | DECLARE_GLOBAL_DATA_PTR; |
| 27 | |
Cédric Schieli | 9473f53 | 2016-11-11 11:59:07 +0100 | [diff] [blame^] | 28 | /* From lowlevel_init.S */ |
| 29 | extern unsigned long fw_dtb_pointer; |
| 30 | |
Simon Glass | 7480762 | 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 | |
Stephen Warren | d6f47c8 | 2016-03-24 22:15:20 -0600 | [diff] [blame] | 40 | #ifdef CONFIG_PL01X_SERIAL |
Simon Glass | f52cada | 2014-11-24 21:36:34 -0700 | [diff] [blame] | 41 | static const struct pl01x_serial_platdata serial_platdata = { |
Stephen Warren | 9d5990b | 2016-03-16 21:40:56 -0600 | [diff] [blame] | 42 | #ifndef CONFIG_BCM2835 |
Stephen Warren | dc7ea68 | 2015-02-16 12:16:15 -0700 | [diff] [blame] | 43 | .base = 0x3f201000, |
| 44 | #else |
Simon Glass | f52cada | 2014-11-24 21:36:34 -0700 | [diff] [blame] | 45 | .base = 0x20201000, |
Stephen Warren | dc7ea68 | 2015-02-16 12:16:15 -0700 | [diff] [blame] | 46 | #endif |
Simon Glass | f52cada | 2014-11-24 21:36:34 -0700 | [diff] [blame] | 47 | .type = TYPE_PL011, |
Eric Anholt | be5a7dd | 2016-03-13 18:16:54 -0700 | [diff] [blame] | 48 | .skip_init = true, |
Simon Glass | f52cada | 2014-11-24 21:36:34 -0700 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | U_BOOT_DEVICE(bcm2835_serials) = { |
| 52 | .name = "serial_pl01x", |
| 53 | .platdata = &serial_platdata, |
| 54 | }; |
Stephen Warren | d6f47c8 | 2016-03-24 22:15:20 -0600 | [diff] [blame] | 55 | #else |
Alexander Graf | afb9907 | 2016-08-15 17:48:51 +0200 | [diff] [blame] | 56 | static struct bcm283x_mu_serial_platdata serial_platdata = { |
Stephen Warren | d6f47c8 | 2016-03-24 22:15:20 -0600 | [diff] [blame] | 57 | .base = 0x3f215040, |
| 58 | .clock = 250000000, |
| 59 | .skip_init = true, |
| 60 | }; |
| 61 | |
| 62 | U_BOOT_DEVICE(bcm2837_serials) = { |
| 63 | .name = "serial_bcm283x_mu", |
| 64 | .platdata = &serial_platdata, |
| 65 | }; |
| 66 | #endif |
Simon Glass | f52cada | 2014-11-24 21:36:34 -0700 | [diff] [blame] | 67 | |
Stephen Warren | acc8bf4 | 2013-01-29 16:37:37 +0000 | [diff] [blame] | 68 | struct msg_get_arm_mem { |
| 69 | struct bcm2835_mbox_hdr hdr; |
| 70 | struct bcm2835_mbox_tag_get_arm_mem get_arm_mem; |
| 71 | u32 end_tag; |
| 72 | }; |
| 73 | |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 74 | struct msg_get_board_rev { |
| 75 | struct bcm2835_mbox_hdr hdr; |
| 76 | struct bcm2835_mbox_tag_get_board_rev get_board_rev; |
| 77 | u32 end_tag; |
| 78 | }; |
| 79 | |
Lubomir Rintel | 7d33bb6 | 2016-02-22 22:06:47 +0100 | [diff] [blame] | 80 | struct msg_get_board_serial { |
| 81 | struct bcm2835_mbox_hdr hdr; |
| 82 | struct bcm2835_mbox_tag_get_board_serial get_board_serial; |
| 83 | u32 end_tag; |
| 84 | }; |
| 85 | |
Stephen Warren | af6e20d | 2014-09-26 20:51:39 -0600 | [diff] [blame] | 86 | struct msg_get_mac_address { |
| 87 | struct bcm2835_mbox_hdr hdr; |
| 88 | struct bcm2835_mbox_tag_get_mac_address get_mac_address; |
| 89 | u32 end_tag; |
| 90 | }; |
| 91 | |
Stephen Warren | 8672d20 | 2014-01-13 19:50:11 -0700 | [diff] [blame] | 92 | struct msg_set_power_state { |
| 93 | struct bcm2835_mbox_hdr hdr; |
| 94 | struct bcm2835_mbox_tag_set_power_state set_power_state; |
| 95 | u32 end_tag; |
| 96 | }; |
| 97 | |
Stephen Warren | c4ab971 | 2013-01-29 16:37:42 +0000 | [diff] [blame] | 98 | struct msg_get_clock_rate { |
| 99 | struct bcm2835_mbox_hdr hdr; |
| 100 | struct bcm2835_mbox_tag_get_clock_rate get_clock_rate; |
| 101 | u32 end_tag; |
| 102 | }; |
| 103 | |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 104 | /* |
| 105 | * http://raspberryalphaomega.org.uk/2013/02/06/automatic-raspberry-pi-board-revision-detection-model-a-b1-and-b2/ |
| 106 | * http://www.raspberrypi.org/forums/viewtopic.php?f=63&t=32733 |
Stephen Warren | 2668385 | 2015-12-04 22:07:45 -0700 | [diff] [blame] | 107 | * http://git.drogon.net/?p=wiringPi;a=blob;f=wiringPi/wiringPi.c;h=503151f61014418b9c42f4476a6086f75cd4e64b;hb=refs/heads/master#l922 |
Stephen Warren | a33dc8b | 2016-01-28 22:24:44 -0700 | [diff] [blame] | 108 | * |
| 109 | * In http://lists.denx.de/pipermail/u-boot/2016-January/243752.html |
| 110 | * ("[U-Boot] [PATCH] rpi: fix up Model B entries") Dom Cobley at the RPi |
| 111 | * Foundation stated that the following source was accurate: |
| 112 | * https://github.com/AndrewFromMelbourne/raspberry_pi_revision |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 113 | */ |
Stephen Warren | 2668385 | 2015-12-04 22:07:45 -0700 | [diff] [blame] | 114 | struct rpi_model { |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 115 | const char *name; |
| 116 | const char *fdtfile; |
Stephen Warren | b2fa3836 | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 117 | bool has_onboard_eth; |
Stephen Warren | 2668385 | 2015-12-04 22:07:45 -0700 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | static const struct rpi_model rpi_model_unknown = { |
| 121 | "Unknown model", |
Stephen Warren | 93970ce | 2016-03-24 22:15:17 -0600 | [diff] [blame] | 122 | "bcm283x-rpi-other.dtb", |
Stephen Warren | 2668385 | 2015-12-04 22:07:45 -0700 | [diff] [blame] | 123 | false, |
| 124 | }; |
| 125 | |
| 126 | static const struct rpi_model rpi_models_new_scheme[] = { |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 127 | [0x4] = { |
Stephen Warren | dc7ea68 | 2015-02-16 12:16:15 -0700 | [diff] [blame] | 128 | "2 Model B", |
| 129 | "bcm2836-rpi-2-b.dtb", |
| 130 | true, |
| 131 | }, |
Stephen Warren | 303244a | 2016-03-24 22:15:18 -0600 | [diff] [blame] | 132 | [0x8] = { |
| 133 | "3 Model B", |
| 134 | "bcm2837-rpi-3-b.dtb", |
| 135 | true, |
| 136 | }, |
Stephen Warren | 2f1f20b | 2015-12-04 22:07:46 -0700 | [diff] [blame] | 137 | [0x9] = { |
| 138 | "Zero", |
| 139 | "bcm2835-rpi-zero.dtb", |
| 140 | false, |
| 141 | }, |
Stephen Warren | 2668385 | 2015-12-04 22:07:45 -0700 | [diff] [blame] | 142 | }; |
| 143 | |
| 144 | static const struct rpi_model rpi_models_old_scheme[] = { |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 145 | [0x2] = { |
Lubomir Rintel | c44f76e | 2016-01-29 09:35:52 +0100 | [diff] [blame] | 146 | "Model B", |
| 147 | "bcm2835-rpi-b.dtb", |
Stephen Warren | b2fa3836 | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 148 | true, |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 149 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 150 | [0x3] = { |
Lubomir Rintel | c44f76e | 2016-01-29 09:35:52 +0100 | [diff] [blame] | 151 | "Model B", |
| 152 | "bcm2835-rpi-b.dtb", |
Stephen Warren | b2fa3836 | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 153 | true, |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 154 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 155 | [0x4] = { |
Lubomir Rintel | c44f76e | 2016-01-29 09:35:52 +0100 | [diff] [blame] | 156 | "Model B rev2", |
| 157 | "bcm2835-rpi-b-rev2.dtb", |
Stephen Warren | b2fa3836 | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 158 | true, |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 159 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 160 | [0x5] = { |
Lubomir Rintel | c44f76e | 2016-01-29 09:35:52 +0100 | [diff] [blame] | 161 | "Model B rev2", |
| 162 | "bcm2835-rpi-b-rev2.dtb", |
Stephen Warren | b2fa3836 | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 163 | true, |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 164 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 165 | [0x6] = { |
Lubomir Rintel | c44f76e | 2016-01-29 09:35:52 +0100 | [diff] [blame] | 166 | "Model B rev2", |
| 167 | "bcm2835-rpi-b-rev2.dtb", |
Stephen Warren | b2fa3836 | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 168 | true, |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 169 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 170 | [0x7] = { |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 171 | "Model A", |
| 172 | "bcm2835-rpi-a.dtb", |
Stephen Warren | b2fa3836 | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 173 | false, |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 174 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 175 | [0x8] = { |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 176 | "Model A", |
| 177 | "bcm2835-rpi-a.dtb", |
Stephen Warren | b2fa3836 | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 178 | false, |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 179 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 180 | [0x9] = { |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 181 | "Model A", |
| 182 | "bcm2835-rpi-a.dtb", |
Stephen Warren | b2fa3836 | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 183 | false, |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 184 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 185 | [0xd] = { |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 186 | "Model B rev2", |
| 187 | "bcm2835-rpi-b-rev2.dtb", |
Stephen Warren | b2fa3836 | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 188 | true, |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 189 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 190 | [0xe] = { |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 191 | "Model B rev2", |
| 192 | "bcm2835-rpi-b-rev2.dtb", |
Stephen Warren | b2fa3836 | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 193 | true, |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 194 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 195 | [0xf] = { |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 196 | "Model B rev2", |
| 197 | "bcm2835-rpi-b-rev2.dtb", |
Stephen Warren | b2fa3836 | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 198 | true, |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 199 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 200 | [0x10] = { |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 201 | "Model B+", |
| 202 | "bcm2835-rpi-b-plus.dtb", |
Stephen Warren | b2fa3836 | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 203 | true, |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 204 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 205 | [0x11] = { |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 206 | "Compute Module", |
| 207 | "bcm2835-rpi-cm.dtb", |
Stephen Warren | b2fa3836 | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 208 | false, |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 209 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 210 | [0x12] = { |
Stephen Warren | 18a5fc6 | 2014-12-23 20:01:43 -0700 | [diff] [blame] | 211 | "Model A+", |
| 212 | "bcm2835-rpi-a-plus.dtb", |
| 213 | false, |
| 214 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 215 | [0x13] = { |
Stephen Warren | 3648a85 | 2015-04-12 21:43:25 -0600 | [diff] [blame] | 216 | "Model B+", |
| 217 | "bcm2835-rpi-b-plus.dtb", |
| 218 | true, |
| 219 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 220 | [0x14] = { |
Stephen Warren | 3648a85 | 2015-04-12 21:43:25 -0600 | [diff] [blame] | 221 | "Compute Module", |
| 222 | "bcm2835-rpi-cm.dtb", |
| 223 | false, |
| 224 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 225 | [0x15] = { |
Lubomir Rintel | c87458c | 2015-10-14 17:17:54 +0200 | [diff] [blame] | 226 | "Model A+", |
| 227 | "bcm2835-rpi-a-plus.dtb", |
| 228 | false, |
| 229 | }, |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 230 | }; |
| 231 | |
Stephen Warren | 2668385 | 2015-12-04 22:07:45 -0700 | [diff] [blame] | 232 | static uint32_t revision; |
| 233 | static uint32_t rev_scheme; |
| 234 | static uint32_t rev_type; |
| 235 | static const struct rpi_model *model; |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 236 | |
Stephen Warren | 93ea526 | 2016-04-01 21:14:15 -0600 | [diff] [blame] | 237 | #ifdef CONFIG_ARM64 |
| 238 | static struct mm_region bcm2837_mem_map[] = { |
| 239 | { |
York Sun | c7104e5 | 2016-06-24 16:46:22 -0700 | [diff] [blame] | 240 | .virt = 0x00000000UL, |
| 241 | .phys = 0x00000000UL, |
Stephen Warren | 93ea526 | 2016-04-01 21:14:15 -0600 | [diff] [blame] | 242 | .size = 0x3f000000UL, |
| 243 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 244 | PTE_BLOCK_INNER_SHARE |
| 245 | }, { |
York Sun | c7104e5 | 2016-06-24 16:46:22 -0700 | [diff] [blame] | 246 | .virt = 0x3f000000UL, |
| 247 | .phys = 0x3f000000UL, |
Stephen Warren | 93ea526 | 2016-04-01 21:14:15 -0600 | [diff] [blame] | 248 | .size = 0x01000000UL, |
| 249 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 250 | PTE_BLOCK_NON_SHARE | |
| 251 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 252 | }, { |
| 253 | /* List terminator */ |
| 254 | 0, |
| 255 | } |
| 256 | }; |
| 257 | |
| 258 | struct mm_region *mem_map = bcm2837_mem_map; |
| 259 | #endif |
| 260 | |
Stephen Warren | 0e012c3 | 2012-08-05 16:07:22 +0000 | [diff] [blame] | 261 | int dram_init(void) |
| 262 | { |
Alexander Stein | c56c947 | 2015-07-24 09:22:12 +0200 | [diff] [blame] | 263 | ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_arm_mem, msg, 1); |
Stephen Warren | acc8bf4 | 2013-01-29 16:37:37 +0000 | [diff] [blame] | 264 | int ret; |
| 265 | |
| 266 | BCM2835_MBOX_INIT_HDR(msg); |
| 267 | BCM2835_MBOX_INIT_TAG(&msg->get_arm_mem, GET_ARM_MEMORY); |
| 268 | |
| 269 | ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr); |
| 270 | if (ret) { |
| 271 | printf("bcm2835: Could not query ARM memory size\n"); |
| 272 | return -1; |
| 273 | } |
| 274 | |
| 275 | gd->ram_size = msg->get_arm_mem.body.resp.mem_size; |
Stephen Warren | 0e012c3 | 2012-08-05 16:07:22 +0000 | [diff] [blame] | 276 | |
| 277 | return 0; |
| 278 | } |
| 279 | |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 280 | static void set_fdtfile(void) |
| 281 | { |
| 282 | const char *fdtfile; |
| 283 | |
| 284 | if (getenv("fdtfile")) |
| 285 | return; |
| 286 | |
Stephen Warren | 2668385 | 2015-12-04 22:07:45 -0700 | [diff] [blame] | 287 | fdtfile = model->fdtfile; |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 288 | setenv("fdtfile", fdtfile); |
| 289 | } |
| 290 | |
Cédric Schieli | 9473f53 | 2016-11-11 11:59:07 +0100 | [diff] [blame^] | 291 | /* |
| 292 | * If the firmware provided a valid FDT at boot time, let's expose it in |
| 293 | * ${fdt_addr} so it may be passed unmodified to the kernel. |
| 294 | */ |
| 295 | static void set_fdt_addr(void) |
| 296 | { |
| 297 | if (getenv("fdt_addr")) |
| 298 | return; |
| 299 | |
| 300 | if (fdt_magic(fw_dtb_pointer) != FDT_MAGIC) |
| 301 | return; |
| 302 | |
| 303 | setenv_hex("fdt_addr", fw_dtb_pointer); |
| 304 | } |
| 305 | |
| 306 | /* |
| 307 | * Prevent relocation from stomping on a firmware provided FDT blob. |
| 308 | */ |
| 309 | unsigned long board_get_usable_ram_top(unsigned long total_size) |
| 310 | { |
| 311 | if ((gd->ram_top - fw_dtb_pointer) > SZ_64M) |
| 312 | return gd->ram_top; |
| 313 | return fw_dtb_pointer & ~0xffff; |
| 314 | } |
| 315 | |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 316 | static void set_usbethaddr(void) |
Stephen Warren | af6e20d | 2014-09-26 20:51:39 -0600 | [diff] [blame] | 317 | { |
Alexander Stein | c56c947 | 2015-07-24 09:22:12 +0200 | [diff] [blame] | 318 | ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_mac_address, msg, 1); |
Stephen Warren | af6e20d | 2014-09-26 20:51:39 -0600 | [diff] [blame] | 319 | int ret; |
| 320 | |
Stephen Warren | 2668385 | 2015-12-04 22:07:45 -0700 | [diff] [blame] | 321 | if (!model->has_onboard_eth) |
Stephen Warren | b2fa3836 | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 322 | return; |
| 323 | |
Stephen Warren | af6e20d | 2014-09-26 20:51:39 -0600 | [diff] [blame] | 324 | if (getenv("usbethaddr")) |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 325 | return; |
Stephen Warren | af6e20d | 2014-09-26 20:51:39 -0600 | [diff] [blame] | 326 | |
| 327 | BCM2835_MBOX_INIT_HDR(msg); |
| 328 | BCM2835_MBOX_INIT_TAG(&msg->get_mac_address, GET_MAC_ADDRESS); |
| 329 | |
| 330 | ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr); |
| 331 | if (ret) { |
| 332 | printf("bcm2835: Could not query MAC address\n"); |
| 333 | /* Ignore error; not critical */ |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 334 | return; |
Stephen Warren | af6e20d | 2014-09-26 20:51:39 -0600 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | eth_setenv_enetaddr("usbethaddr", msg->get_mac_address.body.resp.mac); |
| 338 | |
Lubomir Rintel | 3ac09f8 | 2016-02-03 16:08:09 +0100 | [diff] [blame] | 339 | if (!getenv("ethaddr")) |
| 340 | setenv("ethaddr", getenv("usbethaddr")); |
| 341 | |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 342 | return; |
| 343 | } |
| 344 | |
Guillaume GARDET | 25fa860 | 2015-08-25 15:10:26 +0200 | [diff] [blame] | 345 | #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG |
| 346 | static void set_board_info(void) |
| 347 | { |
Stephen Warren | 2668385 | 2015-12-04 22:07:45 -0700 | [diff] [blame] | 348 | char s[11]; |
| 349 | |
| 350 | snprintf(s, sizeof(s), "0x%X", revision); |
| 351 | setenv("board_revision", s); |
| 352 | snprintf(s, sizeof(s), "%d", rev_scheme); |
| 353 | setenv("board_rev_scheme", s); |
| 354 | /* Can't rename this to board_rev_type since it's an ABI for scripts */ |
| 355 | snprintf(s, sizeof(s), "0x%X", rev_type); |
| 356 | setenv("board_rev", s); |
| 357 | setenv("board_name", model->name); |
Guillaume GARDET | 25fa860 | 2015-08-25 15:10:26 +0200 | [diff] [blame] | 358 | } |
| 359 | #endif /* CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG */ |
| 360 | |
Lubomir Rintel | 7d33bb6 | 2016-02-22 22:06:47 +0100 | [diff] [blame] | 361 | static void set_serial_number(void) |
| 362 | { |
| 363 | ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_board_serial, msg, 1); |
| 364 | int ret; |
| 365 | char serial_string[17] = { 0 }; |
| 366 | |
| 367 | if (getenv("serial#")) |
| 368 | return; |
| 369 | |
| 370 | BCM2835_MBOX_INIT_HDR(msg); |
| 371 | BCM2835_MBOX_INIT_TAG_NO_REQ(&msg->get_board_serial, GET_BOARD_SERIAL); |
| 372 | |
| 373 | ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr); |
| 374 | if (ret) { |
| 375 | printf("bcm2835: Could not query board serial\n"); |
| 376 | /* Ignore error; not critical */ |
| 377 | return; |
| 378 | } |
| 379 | |
| 380 | snprintf(serial_string, sizeof(serial_string), "%016" PRIx64, |
| 381 | msg->get_board_serial.body.resp.serial); |
| 382 | setenv("serial#", serial_string); |
| 383 | } |
| 384 | |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 385 | int misc_init_r(void) |
| 386 | { |
Cédric Schieli | 9473f53 | 2016-11-11 11:59:07 +0100 | [diff] [blame^] | 387 | set_fdt_addr(); |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 388 | set_fdtfile(); |
| 389 | set_usbethaddr(); |
Guillaume GARDET | 25fa860 | 2015-08-25 15:10:26 +0200 | [diff] [blame] | 390 | #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG |
| 391 | set_board_info(); |
| 392 | #endif |
Lubomir Rintel | 7d33bb6 | 2016-02-22 22:06:47 +0100 | [diff] [blame] | 393 | set_serial_number(); |
| 394 | |
Stephen Warren | af6e20d | 2014-09-26 20:51:39 -0600 | [diff] [blame] | 395 | return 0; |
| 396 | } |
| 397 | |
Stephen Warren | 8672d20 | 2014-01-13 19:50:11 -0700 | [diff] [blame] | 398 | static int power_on_module(u32 module) |
| 399 | { |
Alexander Stein | c56c947 | 2015-07-24 09:22:12 +0200 | [diff] [blame] | 400 | ALLOC_CACHE_ALIGN_BUFFER(struct msg_set_power_state, msg_pwr, 1); |
Stephen Warren | 8672d20 | 2014-01-13 19:50:11 -0700 | [diff] [blame] | 401 | int ret; |
| 402 | |
| 403 | BCM2835_MBOX_INIT_HDR(msg_pwr); |
| 404 | BCM2835_MBOX_INIT_TAG(&msg_pwr->set_power_state, |
| 405 | SET_POWER_STATE); |
| 406 | msg_pwr->set_power_state.body.req.device_id = module; |
| 407 | msg_pwr->set_power_state.body.req.state = |
| 408 | BCM2835_MBOX_SET_POWER_STATE_REQ_ON | |
| 409 | BCM2835_MBOX_SET_POWER_STATE_REQ_WAIT; |
| 410 | |
| 411 | ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, |
| 412 | &msg_pwr->hdr); |
| 413 | if (ret) { |
| 414 | printf("bcm2835: Could not set module %u power state\n", |
| 415 | module); |
| 416 | return -1; |
| 417 | } |
| 418 | |
| 419 | return 0; |
| 420 | } |
| 421 | |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 422 | static void get_board_rev(void) |
| 423 | { |
Alexander Stein | c56c947 | 2015-07-24 09:22:12 +0200 | [diff] [blame] | 424 | ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_board_rev, msg, 1); |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 425 | int ret; |
Stephen Warren | 2668385 | 2015-12-04 22:07:45 -0700 | [diff] [blame] | 426 | const struct rpi_model *models; |
| 427 | uint32_t models_count; |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 428 | |
| 429 | BCM2835_MBOX_INIT_HDR(msg); |
| 430 | BCM2835_MBOX_INIT_TAG(&msg->get_board_rev, GET_BOARD_REV); |
| 431 | |
| 432 | ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr); |
| 433 | if (ret) { |
| 434 | printf("bcm2835: Could not query board revision\n"); |
| 435 | /* Ignore error; not critical */ |
| 436 | return; |
| 437 | } |
| 438 | |
Stephen Warren | dc7ea68 | 2015-02-16 12:16:15 -0700 | [diff] [blame] | 439 | /* |
| 440 | * For details of old-vs-new scheme, see: |
| 441 | * https://github.com/pimoroni/RPi.version/blob/master/RPi/version.py |
| 442 | * http://www.raspberrypi.org/forums/viewtopic.php?f=63&t=99293&p=690282 |
| 443 | * (a few posts down) |
Stephen Warren | b834af8 | 2015-03-23 23:00:25 -0600 | [diff] [blame] | 444 | * |
| 445 | * For the RPi 1, bit 24 is the "warranty bit", so we mask off just the |
| 446 | * lower byte to use as the board rev: |
| 447 | * http://www.raspberrypi.org/forums/viewtopic.php?f=63&t=98367&start=250 |
| 448 | * http://www.raspberrypi.org/forums/viewtopic.php?f=31&t=20594 |
Stephen Warren | dc7ea68 | 2015-02-16 12:16:15 -0700 | [diff] [blame] | 449 | */ |
Stephen Warren | 2668385 | 2015-12-04 22:07:45 -0700 | [diff] [blame] | 450 | revision = msg->get_board_rev.body.resp.rev; |
| 451 | if (revision & 0x800000) { |
| 452 | rev_scheme = 1; |
| 453 | rev_type = (revision >> 4) & 0xff; |
| 454 | models = rpi_models_new_scheme; |
| 455 | models_count = ARRAY_SIZE(rpi_models_new_scheme); |
| 456 | } else { |
| 457 | rev_scheme = 0; |
| 458 | rev_type = revision & 0xff; |
| 459 | models = rpi_models_old_scheme; |
| 460 | models_count = ARRAY_SIZE(rpi_models_old_scheme); |
Stephen Warren | 18a5fc6 | 2014-12-23 20:01:43 -0700 | [diff] [blame] | 461 | } |
Stephen Warren | 2668385 | 2015-12-04 22:07:45 -0700 | [diff] [blame] | 462 | if (rev_type >= models_count) { |
| 463 | printf("RPI: Board rev 0x%x outside known range\n", rev_type); |
| 464 | model = &rpi_model_unknown; |
| 465 | } else if (!models[rev_type].name) { |
| 466 | printf("RPI: Board rev 0x%x unknown\n", rev_type); |
| 467 | model = &rpi_model_unknown; |
| 468 | } else { |
| 469 | model = &models[rev_type]; |
Stephen Warren | 18a5fc6 | 2014-12-23 20:01:43 -0700 | [diff] [blame] | 470 | } |
Stephen Warren | c61dfd1 | 2014-12-23 20:01:44 -0700 | [diff] [blame] | 471 | |
Stephen Warren | 2668385 | 2015-12-04 22:07:45 -0700 | [diff] [blame] | 472 | printf("RPI %s (0x%x)\n", model->name, revision); |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 473 | } |
| 474 | |
Stephen Warren | 0e012c3 | 2012-08-05 16:07:22 +0000 | [diff] [blame] | 475 | int board_init(void) |
| 476 | { |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 477 | get_board_rev(); |
| 478 | |
Stephen Warren | 0e012c3 | 2012-08-05 16:07:22 +0000 | [diff] [blame] | 479 | gd->bd->bi_boot_params = 0x100; |
| 480 | |
Stephen Warren | 8672d20 | 2014-01-13 19:50:11 -0700 | [diff] [blame] | 481 | return power_on_module(BCM2835_MBOX_POWER_DEVID_USB_HCD); |
Stephen Warren | 0e012c3 | 2012-08-05 16:07:22 +0000 | [diff] [blame] | 482 | } |
Stephen Warren | c4ab971 | 2013-01-29 16:37:42 +0000 | [diff] [blame] | 483 | |
Alexander Graf | afb9907 | 2016-08-15 17:48:51 +0200 | [diff] [blame] | 484 | #ifndef CONFIG_PL01X_SERIAL |
| 485 | static bool rpi_is_serial_active(void) |
| 486 | { |
| 487 | int serial_gpio = 15; |
| 488 | struct udevice *dev; |
| 489 | |
| 490 | /* |
| 491 | * The RPi3 disables the mini uart by default. The easiest way to find |
| 492 | * out whether it is available is to check if the RX pin is muxed. |
| 493 | */ |
| 494 | |
| 495 | if (uclass_first_device(UCLASS_GPIO, &dev) || !dev) |
| 496 | return true; |
| 497 | |
| 498 | if (bcm2835_gpio_get_func_id(dev, serial_gpio) != BCM2835_GPIO_ALT5) |
| 499 | return false; |
| 500 | |
| 501 | return true; |
| 502 | } |
| 503 | #endif |
| 504 | |
| 505 | int board_early_init_f(void) |
| 506 | { |
| 507 | #ifndef CONFIG_PL01X_SERIAL |
| 508 | /* Disable mini-UART I/O if it's not pinmuxed to our pins */ |
| 509 | if (!rpi_is_serial_active()) |
| 510 | serial_platdata.disabled = true; |
| 511 | #endif |
| 512 | |
| 513 | return 0; |
| 514 | } |
| 515 | |
Jeroen Hofstee | d5b2fed | 2014-07-13 22:01:51 +0200 | [diff] [blame] | 516 | int board_mmc_init(bd_t *bis) |
Stephen Warren | c4ab971 | 2013-01-29 16:37:42 +0000 | [diff] [blame] | 517 | { |
Alexander Stein | c56c947 | 2015-07-24 09:22:12 +0200 | [diff] [blame] | 518 | ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_clock_rate, msg_clk, 1); |
Stephen Warren | c4ab971 | 2013-01-29 16:37:42 +0000 | [diff] [blame] | 519 | int ret; |
| 520 | |
Stephen Warren | 8672d20 | 2014-01-13 19:50:11 -0700 | [diff] [blame] | 521 | power_on_module(BCM2835_MBOX_POWER_DEVID_SDHCI); |
| 522 | |
Stephen Warren | c4ab971 | 2013-01-29 16:37:42 +0000 | [diff] [blame] | 523 | BCM2835_MBOX_INIT_HDR(msg_clk); |
| 524 | BCM2835_MBOX_INIT_TAG(&msg_clk->get_clock_rate, GET_CLOCK_RATE); |
| 525 | msg_clk->get_clock_rate.body.req.clock_id = BCM2835_MBOX_CLOCK_ID_EMMC; |
| 526 | |
| 527 | ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg_clk->hdr); |
| 528 | if (ret) { |
| 529 | printf("bcm2835: Could not query eMMC clock rate\n"); |
| 530 | return -1; |
| 531 | } |
| 532 | |
| 533 | return bcm2835_sdhci_init(BCM2835_SDHCI_BASE, |
| 534 | msg_clk->get_clock_rate.body.resp.rate_hz); |
| 535 | } |
Stephen Warren | aa44d53 | 2013-05-27 18:31:18 +0000 | [diff] [blame] | 536 | |
Simon Glass | 2aec3cc | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 537 | int ft_board_setup(void *blob, bd_t *bd) |
Stephen Warren | aa44d53 | 2013-05-27 18:31:18 +0000 | [diff] [blame] | 538 | { |
| 539 | /* |
| 540 | * For now, we simply always add the simplefb DT node. Later, we |
| 541 | * should be more intelligent, and e.g. only do this if no enabled DT |
| 542 | * node exists for the "real" graphics driver. |
| 543 | */ |
| 544 | lcd_dt_simplefb_add_node(blob); |
Simon Glass | 2aec3cc | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 545 | |
| 546 | return 0; |
Stephen Warren | aa44d53 | 2013-05-27 18:31:18 +0000 | [diff] [blame] | 547 | } |