Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Stephen Warren | 0e012c3 | 2012-08-05 16:07:22 +0000 | [diff] [blame] | 2 | /* |
Stephen Warren | d6f47c8 | 2016-03-24 22:15:20 -0600 | [diff] [blame] | 3 | * (C) Copyright 2012-2016 Stephen Warren |
Stephen Warren | 0e012c3 | 2012-08-05 16:07:22 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Stephen Warren | aa44d53 | 2013-05-27 18:31:18 +0000 | [diff] [blame] | 7 | #include <config.h> |
Simon Glass | 7480762 | 2014-09-22 17:30:56 -0600 | [diff] [blame] | 8 | #include <dm.h> |
Simon Glass | 313112a | 2019-08-01 09:46:46 -0600 | [diff] [blame] | 9 | #include <env.h> |
Alexander Graf | 013e9ae | 2016-11-02 10:36:20 +0100 | [diff] [blame] | 10 | #include <efi_loader.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> |
Simon Glass | 558ec67 | 2017-04-05 16:23:36 -0600 | [diff] [blame] | 18 | #include <asm/arch/msg.h> |
Stephen Warren | c4ab971 | 2013-01-29 16:37:42 +0000 | [diff] [blame] | 19 | #include <asm/arch/sdhci.h> |
Stephen Warren | 0e012c3 | 2012-08-05 16:07:22 +0000 | [diff] [blame] | 20 | #include <asm/global_data.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 |
Paolo Pisati | 6213c55 | 2017-02-10 17:28:05 +0100 | [diff] [blame] | 25 | #include <watchdog.h> |
Alexander Graf | fce8e5c | 2018-01-23 18:05:21 +0100 | [diff] [blame] | 26 | #include <dm/pinctrl.h> |
Stephen Warren | 0e012c3 | 2012-08-05 16:07:22 +0000 | [diff] [blame] | 27 | |
| 28 | DECLARE_GLOBAL_DATA_PTR; |
| 29 | |
Matthias Brugger | d75403d | 2019-11-19 16:01:02 +0100 | [diff] [blame] | 30 | /* Assigned in lowlevel_init.S |
| 31 | * Push the variable into the .data section so that it |
| 32 | * does not get cleared later. |
| 33 | */ |
| 34 | unsigned long __section(".data") fw_dtb_pointer; |
Cédric Schieli | 9473f53 | 2016-11-11 11:59:07 +0100 | [diff] [blame] | 35 | |
Simon Glass | 56991cd | 2017-04-05 16:23:45 -0600 | [diff] [blame] | 36 | /* TODO(sjg@chromium.org): Move these to the msg.c file */ |
Stephen Warren | acc8bf4 | 2013-01-29 16:37:37 +0000 | [diff] [blame] | 37 | struct msg_get_arm_mem { |
| 38 | struct bcm2835_mbox_hdr hdr; |
| 39 | struct bcm2835_mbox_tag_get_arm_mem get_arm_mem; |
| 40 | u32 end_tag; |
| 41 | }; |
| 42 | |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 43 | struct msg_get_board_rev { |
| 44 | struct bcm2835_mbox_hdr hdr; |
| 45 | struct bcm2835_mbox_tag_get_board_rev get_board_rev; |
| 46 | u32 end_tag; |
| 47 | }; |
| 48 | |
Lubomir Rintel | 7d33bb6 | 2016-02-22 22:06:47 +0100 | [diff] [blame] | 49 | struct msg_get_board_serial { |
| 50 | struct bcm2835_mbox_hdr hdr; |
| 51 | struct bcm2835_mbox_tag_get_board_serial get_board_serial; |
| 52 | u32 end_tag; |
| 53 | }; |
| 54 | |
Stephen Warren | af6e20d | 2014-09-26 20:51:39 -0600 | [diff] [blame] | 55 | struct msg_get_mac_address { |
| 56 | struct bcm2835_mbox_hdr hdr; |
| 57 | struct bcm2835_mbox_tag_get_mac_address get_mac_address; |
| 58 | u32 end_tag; |
| 59 | }; |
| 60 | |
Stephen Warren | c4ab971 | 2013-01-29 16:37:42 +0000 | [diff] [blame] | 61 | struct msg_get_clock_rate { |
| 62 | struct bcm2835_mbox_hdr hdr; |
| 63 | struct bcm2835_mbox_tag_get_clock_rate get_clock_rate; |
| 64 | u32 end_tag; |
| 65 | }; |
| 66 | |
Tuomas Tynkkynen | 9266d1d | 2017-01-23 01:34:39 +0200 | [diff] [blame] | 67 | #ifdef CONFIG_ARM64 |
| 68 | #define DTB_DIR "broadcom/" |
| 69 | #else |
| 70 | #define DTB_DIR "" |
| 71 | #endif |
| 72 | |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 73 | /* |
Jonathan Gray | f3fb554 | 2018-11-16 23:06:05 +1100 | [diff] [blame] | 74 | * https://www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 75 | */ |
Stephen Warren | 2668385 | 2015-12-04 22:07:45 -0700 | [diff] [blame] | 76 | struct rpi_model { |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 77 | const char *name; |
| 78 | const char *fdtfile; |
Stephen Warren | b2fa3836 | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 79 | bool has_onboard_eth; |
Stephen Warren | 2668385 | 2015-12-04 22:07:45 -0700 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | static const struct rpi_model rpi_model_unknown = { |
| 83 | "Unknown model", |
Tuomas Tynkkynen | 9266d1d | 2017-01-23 01:34:39 +0200 | [diff] [blame] | 84 | DTB_DIR "bcm283x-rpi-other.dtb", |
Stephen Warren | 2668385 | 2015-12-04 22:07:45 -0700 | [diff] [blame] | 85 | false, |
| 86 | }; |
| 87 | |
| 88 | static const struct rpi_model rpi_models_new_scheme[] = { |
Jonathan Gray | de4524b | 2018-04-06 18:45:49 +1000 | [diff] [blame] | 89 | [0x0] = { |
| 90 | "Model A", |
| 91 | DTB_DIR "bcm2835-rpi-a.dtb", |
| 92 | false, |
| 93 | }, |
| 94 | [0x1] = { |
| 95 | "Model B", |
| 96 | DTB_DIR "bcm2835-rpi-b.dtb", |
| 97 | true, |
| 98 | }, |
| 99 | [0x2] = { |
| 100 | "Model A+", |
| 101 | DTB_DIR "bcm2835-rpi-a-plus.dtb", |
| 102 | false, |
| 103 | }, |
| 104 | [0x3] = { |
| 105 | "Model B+", |
| 106 | DTB_DIR "bcm2835-rpi-b-plus.dtb", |
| 107 | true, |
| 108 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 109 | [0x4] = { |
Stephen Warren | dc7ea68 | 2015-02-16 12:16:15 -0700 | [diff] [blame] | 110 | "2 Model B", |
Tuomas Tynkkynen | 9266d1d | 2017-01-23 01:34:39 +0200 | [diff] [blame] | 111 | DTB_DIR "bcm2836-rpi-2-b.dtb", |
Stephen Warren | dc7ea68 | 2015-02-16 12:16:15 -0700 | [diff] [blame] | 112 | true, |
| 113 | }, |
Jonathan Gray | de4524b | 2018-04-06 18:45:49 +1000 | [diff] [blame] | 114 | [0x6] = { |
| 115 | "Compute Module", |
| 116 | DTB_DIR "bcm2835-rpi-cm.dtb", |
| 117 | false, |
| 118 | }, |
Stephen Warren | 303244a | 2016-03-24 22:15:18 -0600 | [diff] [blame] | 119 | [0x8] = { |
| 120 | "3 Model B", |
Tuomas Tynkkynen | 9266d1d | 2017-01-23 01:34:39 +0200 | [diff] [blame] | 121 | DTB_DIR "bcm2837-rpi-3-b.dtb", |
Stephen Warren | 303244a | 2016-03-24 22:15:18 -0600 | [diff] [blame] | 122 | true, |
| 123 | }, |
Stephen Warren | 2f1f20b | 2015-12-04 22:07:46 -0700 | [diff] [blame] | 124 | [0x9] = { |
| 125 | "Zero", |
Tuomas Tynkkynen | 9266d1d | 2017-01-23 01:34:39 +0200 | [diff] [blame] | 126 | DTB_DIR "bcm2835-rpi-zero.dtb", |
Stephen Warren | 2f1f20b | 2015-12-04 22:07:46 -0700 | [diff] [blame] | 127 | false, |
| 128 | }, |
Jonathan Gray | de4524b | 2018-04-06 18:45:49 +1000 | [diff] [blame] | 129 | [0xA] = { |
| 130 | "Compute Module 3", |
| 131 | DTB_DIR "bcm2837-rpi-cm3.dtb", |
| 132 | false, |
| 133 | }, |
Dmitry Korunov | 3f88741 | 2017-11-26 13:38:53 +0400 | [diff] [blame] | 134 | [0xC] = { |
| 135 | "Zero W", |
| 136 | DTB_DIR "bcm2835-rpi-zero-w.dtb", |
| 137 | false, |
| 138 | }, |
Alexander Graf | d0043a0 | 2018-03-15 15:05:37 +0100 | [diff] [blame] | 139 | [0xD] = { |
| 140 | "3 Model B+", |
| 141 | DTB_DIR "bcm2837-rpi-3-b-plus.dtb", |
| 142 | true, |
| 143 | }, |
Jonathan Gray | ed10255 | 2018-11-16 23:07:39 +1100 | [diff] [blame] | 144 | [0xE] = { |
| 145 | "3 Model A+", |
| 146 | DTB_DIR "bcm2837-rpi-3-a-plus.dtb", |
| 147 | false, |
| 148 | }, |
Jonathan Gray | 765d34d | 2019-01-31 09:24:44 +1100 | [diff] [blame] | 149 | [0x10] = { |
| 150 | "Compute Module 3+", |
| 151 | DTB_DIR "bcm2837-rpi-cm3.dtb", |
| 152 | false, |
| 153 | }, |
Andrei Gherzan | 2633ec8 | 2019-07-24 15:39:07 +0100 | [diff] [blame] | 154 | [0x11] = { |
| 155 | "4 Model B", |
| 156 | DTB_DIR "bcm2711-rpi-4-b.dtb", |
| 157 | true, |
| 158 | }, |
Stephen Warren | 2668385 | 2015-12-04 22:07:45 -0700 | [diff] [blame] | 159 | }; |
| 160 | |
| 161 | static const struct rpi_model rpi_models_old_scheme[] = { |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 162 | [0x2] = { |
Lubomir Rintel | c44f76e | 2016-01-29 09:35:52 +0100 | [diff] [blame] | 163 | "Model B", |
Tuomas Tynkkynen | 9266d1d | 2017-01-23 01:34:39 +0200 | [diff] [blame] | 164 | DTB_DIR "bcm2835-rpi-b.dtb", |
Stephen Warren | b2fa3836 | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 165 | true, |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 166 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 167 | [0x3] = { |
Lubomir Rintel | c44f76e | 2016-01-29 09:35:52 +0100 | [diff] [blame] | 168 | "Model B", |
Tuomas Tynkkynen | 9266d1d | 2017-01-23 01:34:39 +0200 | [diff] [blame] | 169 | DTB_DIR "bcm2835-rpi-b.dtb", |
Stephen Warren | b2fa3836 | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 170 | true, |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 171 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 172 | [0x4] = { |
Lubomir Rintel | c44f76e | 2016-01-29 09:35:52 +0100 | [diff] [blame] | 173 | "Model B rev2", |
Tuomas Tynkkynen | 9266d1d | 2017-01-23 01:34:39 +0200 | [diff] [blame] | 174 | DTB_DIR "bcm2835-rpi-b-rev2.dtb", |
Stephen Warren | b2fa3836 | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 175 | true, |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 176 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 177 | [0x5] = { |
Lubomir Rintel | c44f76e | 2016-01-29 09:35:52 +0100 | [diff] [blame] | 178 | "Model B rev2", |
Tuomas Tynkkynen | 9266d1d | 2017-01-23 01:34:39 +0200 | [diff] [blame] | 179 | DTB_DIR "bcm2835-rpi-b-rev2.dtb", |
Stephen Warren | b2fa3836 | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 180 | true, |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 181 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 182 | [0x6] = { |
Lubomir Rintel | c44f76e | 2016-01-29 09:35:52 +0100 | [diff] [blame] | 183 | "Model B rev2", |
Tuomas Tynkkynen | 9266d1d | 2017-01-23 01:34:39 +0200 | [diff] [blame] | 184 | DTB_DIR "bcm2835-rpi-b-rev2.dtb", |
Stephen Warren | b2fa3836 | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 185 | true, |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 186 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 187 | [0x7] = { |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 188 | "Model A", |
Tuomas Tynkkynen | 9266d1d | 2017-01-23 01:34:39 +0200 | [diff] [blame] | 189 | DTB_DIR "bcm2835-rpi-a.dtb", |
Stephen Warren | b2fa3836 | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 190 | false, |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 191 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 192 | [0x8] = { |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 193 | "Model A", |
Tuomas Tynkkynen | 9266d1d | 2017-01-23 01:34:39 +0200 | [diff] [blame] | 194 | DTB_DIR "bcm2835-rpi-a.dtb", |
Stephen Warren | b2fa3836 | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 195 | false, |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 196 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 197 | [0x9] = { |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 198 | "Model A", |
Tuomas Tynkkynen | 9266d1d | 2017-01-23 01:34:39 +0200 | [diff] [blame] | 199 | DTB_DIR "bcm2835-rpi-a.dtb", |
Stephen Warren | b2fa3836 | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 200 | false, |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 201 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 202 | [0xd] = { |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 203 | "Model B rev2", |
Tuomas Tynkkynen | 9266d1d | 2017-01-23 01:34:39 +0200 | [diff] [blame] | 204 | DTB_DIR "bcm2835-rpi-b-rev2.dtb", |
Stephen Warren | b2fa3836 | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 205 | true, |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 206 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 207 | [0xe] = { |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 208 | "Model B rev2", |
Tuomas Tynkkynen | 9266d1d | 2017-01-23 01:34:39 +0200 | [diff] [blame] | 209 | DTB_DIR "bcm2835-rpi-b-rev2.dtb", |
Stephen Warren | b2fa3836 | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 210 | true, |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 211 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 212 | [0xf] = { |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 213 | "Model B rev2", |
Tuomas Tynkkynen | 9266d1d | 2017-01-23 01:34:39 +0200 | [diff] [blame] | 214 | DTB_DIR "bcm2835-rpi-b-rev2.dtb", |
Stephen Warren | b2fa3836 | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 215 | true, |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 216 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 217 | [0x10] = { |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 218 | "Model B+", |
Tuomas Tynkkynen | 9266d1d | 2017-01-23 01:34:39 +0200 | [diff] [blame] | 219 | DTB_DIR "bcm2835-rpi-b-plus.dtb", |
Stephen Warren | b2fa3836 | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 220 | true, |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 221 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 222 | [0x11] = { |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 223 | "Compute Module", |
Tuomas Tynkkynen | 9266d1d | 2017-01-23 01:34:39 +0200 | [diff] [blame] | 224 | DTB_DIR "bcm2835-rpi-cm.dtb", |
Stephen Warren | b2fa3836 | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 225 | false, |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 226 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 227 | [0x12] = { |
Stephen Warren | 18a5fc6 | 2014-12-23 20:01:43 -0700 | [diff] [blame] | 228 | "Model A+", |
Tuomas Tynkkynen | 9266d1d | 2017-01-23 01:34:39 +0200 | [diff] [blame] | 229 | DTB_DIR "bcm2835-rpi-a-plus.dtb", |
Stephen Warren | 18a5fc6 | 2014-12-23 20:01:43 -0700 | [diff] [blame] | 230 | false, |
| 231 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 232 | [0x13] = { |
Stephen Warren | 3648a85 | 2015-04-12 21:43:25 -0600 | [diff] [blame] | 233 | "Model B+", |
Tuomas Tynkkynen | 9266d1d | 2017-01-23 01:34:39 +0200 | [diff] [blame] | 234 | DTB_DIR "bcm2835-rpi-b-plus.dtb", |
Stephen Warren | 3648a85 | 2015-04-12 21:43:25 -0600 | [diff] [blame] | 235 | true, |
| 236 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 237 | [0x14] = { |
Stephen Warren | 3648a85 | 2015-04-12 21:43:25 -0600 | [diff] [blame] | 238 | "Compute Module", |
Tuomas Tynkkynen | 9266d1d | 2017-01-23 01:34:39 +0200 | [diff] [blame] | 239 | DTB_DIR "bcm2835-rpi-cm.dtb", |
Stephen Warren | 3648a85 | 2015-04-12 21:43:25 -0600 | [diff] [blame] | 240 | false, |
| 241 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 242 | [0x15] = { |
Lubomir Rintel | c87458c | 2015-10-14 17:17:54 +0200 | [diff] [blame] | 243 | "Model A+", |
Tuomas Tynkkynen | 9266d1d | 2017-01-23 01:34:39 +0200 | [diff] [blame] | 244 | DTB_DIR "bcm2835-rpi-a-plus.dtb", |
Lubomir Rintel | c87458c | 2015-10-14 17:17:54 +0200 | [diff] [blame] | 245 | false, |
| 246 | }, |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 247 | }; |
| 248 | |
Stephen Warren | 2668385 | 2015-12-04 22:07:45 -0700 | [diff] [blame] | 249 | static uint32_t revision; |
| 250 | static uint32_t rev_scheme; |
| 251 | static uint32_t rev_type; |
| 252 | static const struct rpi_model *model; |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 253 | |
Stephen Warren | 0e012c3 | 2012-08-05 16:07:22 +0000 | [diff] [blame] | 254 | int dram_init(void) |
| 255 | { |
Alexander Stein | c56c947 | 2015-07-24 09:22:12 +0200 | [diff] [blame] | 256 | ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_arm_mem, msg, 1); |
Stephen Warren | acc8bf4 | 2013-01-29 16:37:37 +0000 | [diff] [blame] | 257 | int ret; |
| 258 | |
| 259 | BCM2835_MBOX_INIT_HDR(msg); |
| 260 | BCM2835_MBOX_INIT_TAG(&msg->get_arm_mem, GET_ARM_MEMORY); |
| 261 | |
| 262 | ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr); |
| 263 | if (ret) { |
| 264 | printf("bcm2835: Could not query ARM memory size\n"); |
| 265 | return -1; |
| 266 | } |
| 267 | |
| 268 | gd->ram_size = msg->get_arm_mem.body.resp.mem_size; |
Stephen Warren | 0e012c3 | 2012-08-05 16:07:22 +0000 | [diff] [blame] | 269 | |
| 270 | return 0; |
| 271 | } |
| 272 | |
Matthias Brugger | d3dcfe2 | 2019-09-09 18:31:56 +0200 | [diff] [blame] | 273 | #ifdef CONFIG_OF_BOARD |
| 274 | #ifdef CONFIG_BCM2711 |
| 275 | int dram_init_banksize(void) |
| 276 | { |
| 277 | return fdtdec_decode_ram_size(gd->fdt_blob, NULL, 0, NULL, |
| 278 | (phys_size_t *)&gd->ram_size, gd->bd); |
| 279 | } |
| 280 | #endif |
| 281 | #endif |
| 282 | |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 283 | static void set_fdtfile(void) |
| 284 | { |
| 285 | const char *fdtfile; |
| 286 | |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 287 | if (env_get("fdtfile")) |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 288 | return; |
| 289 | |
Stephen Warren | 2668385 | 2015-12-04 22:07:45 -0700 | [diff] [blame] | 290 | fdtfile = model->fdtfile; |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 291 | env_set("fdtfile", fdtfile); |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 292 | } |
| 293 | |
Cédric Schieli | 9473f53 | 2016-11-11 11:59:07 +0100 | [diff] [blame] | 294 | /* |
| 295 | * If the firmware provided a valid FDT at boot time, let's expose it in |
| 296 | * ${fdt_addr} so it may be passed unmodified to the kernel. |
| 297 | */ |
| 298 | static void set_fdt_addr(void) |
| 299 | { |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 300 | if (env_get("fdt_addr")) |
Cédric Schieli | 9473f53 | 2016-11-11 11:59:07 +0100 | [diff] [blame] | 301 | return; |
| 302 | |
| 303 | if (fdt_magic(fw_dtb_pointer) != FDT_MAGIC) |
| 304 | return; |
| 305 | |
Simon Glass | 4d949a2 | 2017-08-03 12:22:10 -0600 | [diff] [blame] | 306 | env_set_hex("fdt_addr", fw_dtb_pointer); |
Cédric Schieli | 9473f53 | 2016-11-11 11:59:07 +0100 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | /* |
| 310 | * Prevent relocation from stomping on a firmware provided FDT blob. |
| 311 | */ |
| 312 | unsigned long board_get_usable_ram_top(unsigned long total_size) |
| 313 | { |
| 314 | if ((gd->ram_top - fw_dtb_pointer) > SZ_64M) |
| 315 | return gd->ram_top; |
| 316 | return fw_dtb_pointer & ~0xffff; |
| 317 | } |
| 318 | |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 319 | static void set_usbethaddr(void) |
Stephen Warren | af6e20d | 2014-09-26 20:51:39 -0600 | [diff] [blame] | 320 | { |
Alexander Stein | c56c947 | 2015-07-24 09:22:12 +0200 | [diff] [blame] | 321 | ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_mac_address, msg, 1); |
Stephen Warren | af6e20d | 2014-09-26 20:51:39 -0600 | [diff] [blame] | 322 | int ret; |
| 323 | |
Stephen Warren | 2668385 | 2015-12-04 22:07:45 -0700 | [diff] [blame] | 324 | if (!model->has_onboard_eth) |
Stephen Warren | b2fa3836 | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 325 | return; |
| 326 | |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 327 | if (env_get("usbethaddr")) |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 328 | return; |
Stephen Warren | af6e20d | 2014-09-26 20:51:39 -0600 | [diff] [blame] | 329 | |
| 330 | BCM2835_MBOX_INIT_HDR(msg); |
| 331 | BCM2835_MBOX_INIT_TAG(&msg->get_mac_address, GET_MAC_ADDRESS); |
| 332 | |
| 333 | ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr); |
| 334 | if (ret) { |
| 335 | printf("bcm2835: Could not query MAC address\n"); |
| 336 | /* Ignore error; not critical */ |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 337 | return; |
Stephen Warren | af6e20d | 2014-09-26 20:51:39 -0600 | [diff] [blame] | 338 | } |
| 339 | |
Simon Glass | 8551d55 | 2017-08-03 12:22:11 -0600 | [diff] [blame] | 340 | eth_env_set_enetaddr("usbethaddr", msg->get_mac_address.body.resp.mac); |
Stephen Warren | af6e20d | 2014-09-26 20:51:39 -0600 | [diff] [blame] | 341 | |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 342 | if (!env_get("ethaddr")) |
| 343 | env_set("ethaddr", env_get("usbethaddr")); |
Lubomir Rintel | 3ac09f8 | 2016-02-03 16:08:09 +0100 | [diff] [blame] | 344 | |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 345 | return; |
| 346 | } |
| 347 | |
Guillaume GARDET | 25fa860 | 2015-08-25 15:10:26 +0200 | [diff] [blame] | 348 | #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG |
| 349 | static void set_board_info(void) |
| 350 | { |
Stephen Warren | 2668385 | 2015-12-04 22:07:45 -0700 | [diff] [blame] | 351 | char s[11]; |
| 352 | |
| 353 | snprintf(s, sizeof(s), "0x%X", revision); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 354 | env_set("board_revision", s); |
Stephen Warren | 2668385 | 2015-12-04 22:07:45 -0700 | [diff] [blame] | 355 | snprintf(s, sizeof(s), "%d", rev_scheme); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 356 | env_set("board_rev_scheme", s); |
Stephen Warren | 2668385 | 2015-12-04 22:07:45 -0700 | [diff] [blame] | 357 | /* Can't rename this to board_rev_type since it's an ABI for scripts */ |
| 358 | snprintf(s, sizeof(s), "0x%X", rev_type); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 359 | env_set("board_rev", s); |
| 360 | env_set("board_name", model->name); |
Guillaume GARDET | 25fa860 | 2015-08-25 15:10:26 +0200 | [diff] [blame] | 361 | } |
| 362 | #endif /* CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG */ |
| 363 | |
Lubomir Rintel | 7d33bb6 | 2016-02-22 22:06:47 +0100 | [diff] [blame] | 364 | static void set_serial_number(void) |
| 365 | { |
| 366 | ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_board_serial, msg, 1); |
| 367 | int ret; |
| 368 | char serial_string[17] = { 0 }; |
| 369 | |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 370 | if (env_get("serial#")) |
Lubomir Rintel | 7d33bb6 | 2016-02-22 22:06:47 +0100 | [diff] [blame] | 371 | return; |
| 372 | |
| 373 | BCM2835_MBOX_INIT_HDR(msg); |
| 374 | BCM2835_MBOX_INIT_TAG_NO_REQ(&msg->get_board_serial, GET_BOARD_SERIAL); |
| 375 | |
| 376 | ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr); |
| 377 | if (ret) { |
| 378 | printf("bcm2835: Could not query board serial\n"); |
| 379 | /* Ignore error; not critical */ |
| 380 | return; |
| 381 | } |
| 382 | |
Masahiro Yamada | c7570a3 | 2018-08-06 20:47:40 +0900 | [diff] [blame] | 383 | snprintf(serial_string, sizeof(serial_string), "%016llx", |
Lubomir Rintel | 7d33bb6 | 2016-02-22 22:06:47 +0100 | [diff] [blame] | 384 | msg->get_board_serial.body.resp.serial); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 385 | env_set("serial#", serial_string); |
Lubomir Rintel | 7d33bb6 | 2016-02-22 22:06:47 +0100 | [diff] [blame] | 386 | } |
| 387 | |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 388 | int misc_init_r(void) |
| 389 | { |
Cédric Schieli | 9473f53 | 2016-11-11 11:59:07 +0100 | [diff] [blame] | 390 | set_fdt_addr(); |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 391 | set_fdtfile(); |
| 392 | set_usbethaddr(); |
Guillaume GARDET | 25fa860 | 2015-08-25 15:10:26 +0200 | [diff] [blame] | 393 | #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG |
| 394 | set_board_info(); |
| 395 | #endif |
Lubomir Rintel | 7d33bb6 | 2016-02-22 22:06:47 +0100 | [diff] [blame] | 396 | set_serial_number(); |
| 397 | |
Stephen Warren | af6e20d | 2014-09-26 20:51:39 -0600 | [diff] [blame] | 398 | return 0; |
| 399 | } |
| 400 | |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 401 | static void get_board_rev(void) |
| 402 | { |
Alexander Stein | c56c947 | 2015-07-24 09:22:12 +0200 | [diff] [blame] | 403 | ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_board_rev, msg, 1); |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 404 | int ret; |
Stephen Warren | 2668385 | 2015-12-04 22:07:45 -0700 | [diff] [blame] | 405 | const struct rpi_model *models; |
| 406 | uint32_t models_count; |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 407 | |
| 408 | BCM2835_MBOX_INIT_HDR(msg); |
| 409 | BCM2835_MBOX_INIT_TAG(&msg->get_board_rev, GET_BOARD_REV); |
| 410 | |
| 411 | ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr); |
| 412 | if (ret) { |
| 413 | printf("bcm2835: Could not query board revision\n"); |
| 414 | /* Ignore error; not critical */ |
| 415 | return; |
| 416 | } |
| 417 | |
Stephen Warren | dc7ea68 | 2015-02-16 12:16:15 -0700 | [diff] [blame] | 418 | /* |
| 419 | * For details of old-vs-new scheme, see: |
| 420 | * https://github.com/pimoroni/RPi.version/blob/master/RPi/version.py |
| 421 | * http://www.raspberrypi.org/forums/viewtopic.php?f=63&t=99293&p=690282 |
| 422 | * (a few posts down) |
Stephen Warren | b834af8 | 2015-03-23 23:00:25 -0600 | [diff] [blame] | 423 | * |
| 424 | * For the RPi 1, bit 24 is the "warranty bit", so we mask off just the |
| 425 | * lower byte to use as the board rev: |
| 426 | * http://www.raspberrypi.org/forums/viewtopic.php?f=63&t=98367&start=250 |
| 427 | * http://www.raspberrypi.org/forums/viewtopic.php?f=31&t=20594 |
Stephen Warren | dc7ea68 | 2015-02-16 12:16:15 -0700 | [diff] [blame] | 428 | */ |
Stephen Warren | 2668385 | 2015-12-04 22:07:45 -0700 | [diff] [blame] | 429 | revision = msg->get_board_rev.body.resp.rev; |
| 430 | if (revision & 0x800000) { |
| 431 | rev_scheme = 1; |
| 432 | rev_type = (revision >> 4) & 0xff; |
| 433 | models = rpi_models_new_scheme; |
| 434 | models_count = ARRAY_SIZE(rpi_models_new_scheme); |
| 435 | } else { |
| 436 | rev_scheme = 0; |
| 437 | rev_type = revision & 0xff; |
| 438 | models = rpi_models_old_scheme; |
| 439 | models_count = ARRAY_SIZE(rpi_models_old_scheme); |
Stephen Warren | 18a5fc6 | 2014-12-23 20:01:43 -0700 | [diff] [blame] | 440 | } |
Stephen Warren | 2668385 | 2015-12-04 22:07:45 -0700 | [diff] [blame] | 441 | if (rev_type >= models_count) { |
| 442 | printf("RPI: Board rev 0x%x outside known range\n", rev_type); |
| 443 | model = &rpi_model_unknown; |
| 444 | } else if (!models[rev_type].name) { |
| 445 | printf("RPI: Board rev 0x%x unknown\n", rev_type); |
| 446 | model = &rpi_model_unknown; |
| 447 | } else { |
| 448 | model = &models[rev_type]; |
Stephen Warren | 18a5fc6 | 2014-12-23 20:01:43 -0700 | [diff] [blame] | 449 | } |
Stephen Warren | c61dfd1 | 2014-12-23 20:01:44 -0700 | [diff] [blame] | 450 | |
Stephen Warren | 2668385 | 2015-12-04 22:07:45 -0700 | [diff] [blame] | 451 | printf("RPI %s (0x%x)\n", model->name, revision); |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 452 | } |
| 453 | |
Fabian Vogt | 1d317b7 | 2016-09-26 14:26:50 +0200 | [diff] [blame] | 454 | int board_init(void) |
Alexander Graf | afb9907 | 2016-08-15 17:48:51 +0200 | [diff] [blame] | 455 | { |
Paolo Pisati | 6213c55 | 2017-02-10 17:28:05 +0100 | [diff] [blame] | 456 | #ifdef CONFIG_HW_WATCHDOG |
| 457 | hw_watchdog_init(); |
| 458 | #endif |
Alexander Graf | afb9907 | 2016-08-15 17:48:51 +0200 | [diff] [blame] | 459 | |
Fabian Vogt | 1d317b7 | 2016-09-26 14:26:50 +0200 | [diff] [blame] | 460 | get_board_rev(); |
| 461 | |
| 462 | gd->bd->bi_boot_params = 0x100; |
| 463 | |
Simon Glass | 558ec67 | 2017-04-05 16:23:36 -0600 | [diff] [blame] | 464 | return bcm2835_power_on_module(BCM2835_MBOX_POWER_DEVID_USB_HCD); |
Alexander Graf | afb9907 | 2016-08-15 17:48:51 +0200 | [diff] [blame] | 465 | } |
| 466 | |
Alex Deymo | 5b661ec | 2017-04-02 01:25:20 -0700 | [diff] [blame] | 467 | /* |
| 468 | * If the firmware passed a device tree use it for U-Boot. |
| 469 | */ |
| 470 | void *board_fdt_blob_setup(void) |
| 471 | { |
| 472 | if (fdt_magic(fw_dtb_pointer) != FDT_MAGIC) |
| 473 | return NULL; |
| 474 | return (void *)fw_dtb_pointer; |
| 475 | } |
| 476 | |
Simon Glass | 2aec3cc | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 477 | int ft_board_setup(void *blob, bd_t *bd) |
Stephen Warren | aa44d53 | 2013-05-27 18:31:18 +0000 | [diff] [blame] | 478 | { |
| 479 | /* |
| 480 | * For now, we simply always add the simplefb DT node. Later, we |
| 481 | * should be more intelligent, and e.g. only do this if no enabled DT |
| 482 | * node exists for the "real" graphics driver. |
| 483 | */ |
| 484 | lcd_dt_simplefb_add_node(blob); |
Simon Glass | 2aec3cc | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 485 | |
Alexander Graf | 013e9ae | 2016-11-02 10:36:20 +0100 | [diff] [blame] | 486 | #ifdef CONFIG_EFI_LOADER |
| 487 | /* Reserve the spin table */ |
| 488 | efi_add_memory_map(0, 1, EFI_RESERVED_MEMORY_TYPE, 0); |
| 489 | #endif |
| 490 | |
Simon Glass | 2aec3cc | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 491 | return 0; |
Stephen Warren | aa44d53 | 2013-05-27 18:31:18 +0000 | [diff] [blame] | 492 | } |