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 | |
Stephen Warren | aa44d53 | 2013-05-27 18:31:18 +0000 | [diff] [blame] | 6 | #include <config.h> |
Simon Glass | 7480762 | 2014-09-22 17:30:56 -0600 | [diff] [blame] | 7 | #include <dm.h> |
Simon Glass | 313112a | 2019-08-01 09:46:46 -0600 | [diff] [blame] | 8 | #include <env.h> |
Alexander Graf | 013e9ae | 2016-11-02 10:36:20 +0100 | [diff] [blame] | 9 | #include <efi_loader.h> |
Jeroen Hofstee | d5b2fed | 2014-07-13 22:01:51 +0200 | [diff] [blame] | 10 | #include <fdt_support.h> |
Nikita Kiryanov | b071e4c | 2015-02-03 13:32:31 +0200 | [diff] [blame] | 11 | #include <fdt_simplefb.h> |
Simon Glass | 6980b6b | 2019-11-14 12:57:45 -0700 | [diff] [blame] | 12 | #include <init.h> |
Simon Glass | 2dd337a | 2015-09-02 17:24:58 -0600 | [diff] [blame] | 13 | #include <memalign.h> |
Jeroen Hofstee | d5b2fed | 2014-07-13 22:01:51 +0200 | [diff] [blame] | 14 | #include <mmc.h> |
Simon Glass | 7480762 | 2014-09-22 17:30:56 -0600 | [diff] [blame] | 15 | #include <asm/gpio.h> |
Stephen Warren | acc8bf4 | 2013-01-29 16:37:37 +0000 | [diff] [blame] | 16 | #include <asm/arch/mbox.h> |
Simon Glass | 558ec67 | 2017-04-05 16:23:36 -0600 | [diff] [blame] | 17 | #include <asm/arch/msg.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> |
Stephen Warren | d6f47c8 | 2016-03-24 22:15:20 -0600 | [diff] [blame] | 20 | #include <dm/platform_data/serial_bcm283x_mu.h> |
Stephen Warren | 93ea526 | 2016-04-01 21:14:15 -0600 | [diff] [blame] | 21 | #ifdef CONFIG_ARM64 |
| 22 | #include <asm/armv8/mmu.h> |
| 23 | #endif |
Paolo Pisati | 6213c55 | 2017-02-10 17:28:05 +0100 | [diff] [blame] | 24 | #include <watchdog.h> |
Alexander Graf | fce8e5c | 2018-01-23 18:05:21 +0100 | [diff] [blame] | 25 | #include <dm/pinctrl.h> |
Simon Glass | 18d4a11 | 2024-10-23 15:20:12 +0200 | [diff] [blame] | 26 | #include <dm/ofnode.h> |
| 27 | #include <acpi/acpi_table.h> |
| 28 | #include <acpi/acpigen.h> |
| 29 | #include <dm/lists.h> |
| 30 | #include <tables_csum.h> |
Stephen Warren | 0e012c3 | 2012-08-05 16:07:22 +0000 | [diff] [blame] | 31 | |
| 32 | DECLARE_GLOBAL_DATA_PTR; |
| 33 | |
Matthias Brugger | d75403d | 2019-11-19 16:01:02 +0100 | [diff] [blame] | 34 | /* Assigned in lowlevel_init.S |
| 35 | * Push the variable into the .data section so that it |
| 36 | * does not get cleared later. |
| 37 | */ |
| 38 | unsigned long __section(".data") fw_dtb_pointer; |
Cédric Schieli | 9473f53 | 2016-11-11 11:59:07 +0100 | [diff] [blame] | 39 | |
Simon Glass | 56991cd | 2017-04-05 16:23:45 -0600 | [diff] [blame] | 40 | /* TODO(sjg@chromium.org): Move these to the msg.c file */ |
Stephen Warren | acc8bf4 | 2013-01-29 16:37:37 +0000 | [diff] [blame] | 41 | struct msg_get_arm_mem { |
| 42 | struct bcm2835_mbox_hdr hdr; |
| 43 | struct bcm2835_mbox_tag_get_arm_mem get_arm_mem; |
| 44 | u32 end_tag; |
| 45 | }; |
| 46 | |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 47 | struct msg_get_board_rev { |
| 48 | struct bcm2835_mbox_hdr hdr; |
| 49 | struct bcm2835_mbox_tag_get_board_rev get_board_rev; |
| 50 | u32 end_tag; |
| 51 | }; |
| 52 | |
Lubomir Rintel | 7d33bb6 | 2016-02-22 22:06:47 +0100 | [diff] [blame] | 53 | struct msg_get_board_serial { |
| 54 | struct bcm2835_mbox_hdr hdr; |
| 55 | struct bcm2835_mbox_tag_get_board_serial get_board_serial; |
| 56 | u32 end_tag; |
| 57 | }; |
| 58 | |
Stephen Warren | af6e20d | 2014-09-26 20:51:39 -0600 | [diff] [blame] | 59 | struct msg_get_mac_address { |
| 60 | struct bcm2835_mbox_hdr hdr; |
| 61 | struct bcm2835_mbox_tag_get_mac_address get_mac_address; |
| 62 | u32 end_tag; |
| 63 | }; |
| 64 | |
Stephen Warren | c4ab971 | 2013-01-29 16:37:42 +0000 | [diff] [blame] | 65 | struct msg_get_clock_rate { |
| 66 | struct bcm2835_mbox_hdr hdr; |
| 67 | struct bcm2835_mbox_tag_get_clock_rate get_clock_rate; |
| 68 | u32 end_tag; |
| 69 | }; |
| 70 | |
Tuomas Tynkkynen | 9266d1d | 2017-01-23 01:34:39 +0200 | [diff] [blame] | 71 | #ifdef CONFIG_ARM64 |
| 72 | #define DTB_DIR "broadcom/" |
| 73 | #else |
| 74 | #define DTB_DIR "" |
| 75 | #endif |
| 76 | |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 77 | /* |
Peter Robinson | 52e3346 | 2021-11-21 17:03:45 +0000 | [diff] [blame] | 78 | * https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#raspberry-pi-revision-codes |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 79 | */ |
Stephen Warren | 2668385 | 2015-12-04 22:07:45 -0700 | [diff] [blame] | 80 | struct rpi_model { |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 81 | const char *name; |
| 82 | const char *fdtfile; |
Stephen Warren | b2fa3836 | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 83 | bool has_onboard_eth; |
Stephen Warren | 2668385 | 2015-12-04 22:07:45 -0700 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | static const struct rpi_model rpi_model_unknown = { |
| 87 | "Unknown model", |
Tuomas Tynkkynen | 9266d1d | 2017-01-23 01:34:39 +0200 | [diff] [blame] | 88 | DTB_DIR "bcm283x-rpi-other.dtb", |
Stephen Warren | 2668385 | 2015-12-04 22:07:45 -0700 | [diff] [blame] | 89 | false, |
| 90 | }; |
| 91 | |
| 92 | static const struct rpi_model rpi_models_new_scheme[] = { |
Jonathan Gray | de4524b | 2018-04-06 18:45:49 +1000 | [diff] [blame] | 93 | [0x0] = { |
| 94 | "Model A", |
| 95 | DTB_DIR "bcm2835-rpi-a.dtb", |
| 96 | false, |
| 97 | }, |
| 98 | [0x1] = { |
| 99 | "Model B", |
| 100 | DTB_DIR "bcm2835-rpi-b.dtb", |
| 101 | true, |
| 102 | }, |
| 103 | [0x2] = { |
| 104 | "Model A+", |
| 105 | DTB_DIR "bcm2835-rpi-a-plus.dtb", |
| 106 | false, |
| 107 | }, |
| 108 | [0x3] = { |
| 109 | "Model B+", |
| 110 | DTB_DIR "bcm2835-rpi-b-plus.dtb", |
| 111 | true, |
| 112 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 113 | [0x4] = { |
Stephen Warren | dc7ea68 | 2015-02-16 12:16:15 -0700 | [diff] [blame] | 114 | "2 Model B", |
Tuomas Tynkkynen | 9266d1d | 2017-01-23 01:34:39 +0200 | [diff] [blame] | 115 | DTB_DIR "bcm2836-rpi-2-b.dtb", |
Stephen Warren | dc7ea68 | 2015-02-16 12:16:15 -0700 | [diff] [blame] | 116 | true, |
| 117 | }, |
Jonathan Gray | de4524b | 2018-04-06 18:45:49 +1000 | [diff] [blame] | 118 | [0x6] = { |
| 119 | "Compute Module", |
| 120 | DTB_DIR "bcm2835-rpi-cm.dtb", |
| 121 | false, |
| 122 | }, |
Stephen Warren | 303244a | 2016-03-24 22:15:18 -0600 | [diff] [blame] | 123 | [0x8] = { |
| 124 | "3 Model B", |
Tuomas Tynkkynen | 9266d1d | 2017-01-23 01:34:39 +0200 | [diff] [blame] | 125 | DTB_DIR "bcm2837-rpi-3-b.dtb", |
Stephen Warren | 303244a | 2016-03-24 22:15:18 -0600 | [diff] [blame] | 126 | true, |
| 127 | }, |
Stephen Warren | 2f1f20b | 2015-12-04 22:07:46 -0700 | [diff] [blame] | 128 | [0x9] = { |
| 129 | "Zero", |
Tuomas Tynkkynen | 9266d1d | 2017-01-23 01:34:39 +0200 | [diff] [blame] | 130 | DTB_DIR "bcm2835-rpi-zero.dtb", |
Stephen Warren | 2f1f20b | 2015-12-04 22:07:46 -0700 | [diff] [blame] | 131 | false, |
| 132 | }, |
Jonathan Gray | de4524b | 2018-04-06 18:45:49 +1000 | [diff] [blame] | 133 | [0xA] = { |
| 134 | "Compute Module 3", |
| 135 | DTB_DIR "bcm2837-rpi-cm3.dtb", |
| 136 | false, |
| 137 | }, |
Dmitry Korunov | 3f88741 | 2017-11-26 13:38:53 +0400 | [diff] [blame] | 138 | [0xC] = { |
| 139 | "Zero W", |
| 140 | DTB_DIR "bcm2835-rpi-zero-w.dtb", |
| 141 | false, |
| 142 | }, |
Alexander Graf | d0043a0 | 2018-03-15 15:05:37 +0100 | [diff] [blame] | 143 | [0xD] = { |
| 144 | "3 Model B+", |
| 145 | DTB_DIR "bcm2837-rpi-3-b-plus.dtb", |
| 146 | true, |
| 147 | }, |
Jonathan Gray | ed10255 | 2018-11-16 23:07:39 +1100 | [diff] [blame] | 148 | [0xE] = { |
| 149 | "3 Model A+", |
| 150 | DTB_DIR "bcm2837-rpi-3-a-plus.dtb", |
| 151 | false, |
| 152 | }, |
Jonathan Gray | 765d34d | 2019-01-31 09:24:44 +1100 | [diff] [blame] | 153 | [0x10] = { |
| 154 | "Compute Module 3+", |
| 155 | DTB_DIR "bcm2837-rpi-cm3.dtb", |
| 156 | false, |
| 157 | }, |
Andrei Gherzan | 2633ec8 | 2019-07-24 15:39:07 +0100 | [diff] [blame] | 158 | [0x11] = { |
| 159 | "4 Model B", |
| 160 | DTB_DIR "bcm2711-rpi-4-b.dtb", |
| 161 | true, |
| 162 | }, |
Peter Robinson | 400260c | 2021-11-21 17:03:46 +0000 | [diff] [blame] | 163 | [0x12] = { |
| 164 | "Zero 2 W", |
Peter Robinson | 78c7e46 | 2023-02-28 10:17:26 +0000 | [diff] [blame] | 165 | DTB_DIR "bcm2837-rpi-zero-2-w.dtb", |
Peter Robinson | 400260c | 2021-11-21 17:03:46 +0000 | [diff] [blame] | 166 | false, |
| 167 | }, |
Nicolas Saenz Julienne | 1296961 | 2021-01-12 13:55:19 +0100 | [diff] [blame] | 168 | [0x13] = { |
| 169 | "400", |
| 170 | DTB_DIR "bcm2711-rpi-400.dtb", |
| 171 | true, |
| 172 | }, |
Nicolas Saenz Julienne | 0c29186 | 2021-01-12 13:55:20 +0100 | [diff] [blame] | 173 | [0x14] = { |
| 174 | "Compute Module 4", |
| 175 | DTB_DIR "bcm2711-rpi-cm4.dtb", |
| 176 | true, |
| 177 | }, |
Ivan T. Ivanov | 14fb952 | 2024-01-23 10:07:55 +0200 | [diff] [blame] | 178 | [0x17] = { |
| 179 | "5 Model B", |
| 180 | DTB_DIR "bcm2712-rpi-5-b.dtb", |
| 181 | true, |
| 182 | }, |
Stephen Warren | 2668385 | 2015-12-04 22:07:45 -0700 | [diff] [blame] | 183 | }; |
| 184 | |
| 185 | static const struct rpi_model rpi_models_old_scheme[] = { |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 186 | [0x2] = { |
Lubomir Rintel | c44f76e | 2016-01-29 09:35:52 +0100 | [diff] [blame] | 187 | "Model B", |
Tuomas Tynkkynen | 9266d1d | 2017-01-23 01:34:39 +0200 | [diff] [blame] | 188 | DTB_DIR "bcm2835-rpi-b.dtb", |
Stephen Warren | b2fa3836 | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 189 | true, |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 190 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 191 | [0x3] = { |
Lubomir Rintel | c44f76e | 2016-01-29 09:35:52 +0100 | [diff] [blame] | 192 | "Model B", |
Tuomas Tynkkynen | 9266d1d | 2017-01-23 01:34:39 +0200 | [diff] [blame] | 193 | DTB_DIR "bcm2835-rpi-b.dtb", |
Stephen Warren | b2fa3836 | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 194 | true, |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 195 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 196 | [0x4] = { |
Lubomir Rintel | c44f76e | 2016-01-29 09:35:52 +0100 | [diff] [blame] | 197 | "Model B rev2", |
Tuomas Tynkkynen | 9266d1d | 2017-01-23 01:34:39 +0200 | [diff] [blame] | 198 | DTB_DIR "bcm2835-rpi-b-rev2.dtb", |
Stephen Warren | b2fa3836 | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 199 | true, |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 200 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 201 | [0x5] = { |
Lubomir Rintel | c44f76e | 2016-01-29 09:35:52 +0100 | [diff] [blame] | 202 | "Model B rev2", |
Tuomas Tynkkynen | 9266d1d | 2017-01-23 01:34:39 +0200 | [diff] [blame] | 203 | DTB_DIR "bcm2835-rpi-b-rev2.dtb", |
Stephen Warren | b2fa3836 | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 204 | true, |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 205 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 206 | [0x6] = { |
Lubomir Rintel | c44f76e | 2016-01-29 09:35:52 +0100 | [diff] [blame] | 207 | "Model B rev2", |
Tuomas Tynkkynen | 9266d1d | 2017-01-23 01:34:39 +0200 | [diff] [blame] | 208 | DTB_DIR "bcm2835-rpi-b-rev2.dtb", |
Stephen Warren | b2fa3836 | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 209 | true, |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 210 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 211 | [0x7] = { |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 212 | "Model A", |
Tuomas Tynkkynen | 9266d1d | 2017-01-23 01:34:39 +0200 | [diff] [blame] | 213 | DTB_DIR "bcm2835-rpi-a.dtb", |
Stephen Warren | b2fa3836 | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 214 | false, |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 215 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 216 | [0x8] = { |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 217 | "Model A", |
Tuomas Tynkkynen | 9266d1d | 2017-01-23 01:34:39 +0200 | [diff] [blame] | 218 | DTB_DIR "bcm2835-rpi-a.dtb", |
Stephen Warren | b2fa3836 | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 219 | false, |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 220 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 221 | [0x9] = { |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 222 | "Model A", |
Tuomas Tynkkynen | 9266d1d | 2017-01-23 01:34:39 +0200 | [diff] [blame] | 223 | DTB_DIR "bcm2835-rpi-a.dtb", |
Stephen Warren | b2fa3836 | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 224 | false, |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 225 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 226 | [0xd] = { |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 227 | "Model B rev2", |
Tuomas Tynkkynen | 9266d1d | 2017-01-23 01:34:39 +0200 | [diff] [blame] | 228 | DTB_DIR "bcm2835-rpi-b-rev2.dtb", |
Stephen Warren | b2fa3836 | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 229 | true, |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 230 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 231 | [0xe] = { |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 232 | "Model B rev2", |
Tuomas Tynkkynen | 9266d1d | 2017-01-23 01:34:39 +0200 | [diff] [blame] | 233 | DTB_DIR "bcm2835-rpi-b-rev2.dtb", |
Stephen Warren | b2fa3836 | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 234 | true, |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 235 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 236 | [0xf] = { |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 237 | "Model B rev2", |
Tuomas Tynkkynen | 9266d1d | 2017-01-23 01:34:39 +0200 | [diff] [blame] | 238 | DTB_DIR "bcm2835-rpi-b-rev2.dtb", |
Stephen Warren | b2fa3836 | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 239 | true, |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 240 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 241 | [0x10] = { |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 242 | "Model B+", |
Tuomas Tynkkynen | 9266d1d | 2017-01-23 01:34:39 +0200 | [diff] [blame] | 243 | DTB_DIR "bcm2835-rpi-b-plus.dtb", |
Stephen Warren | b2fa3836 | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 244 | true, |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 245 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 246 | [0x11] = { |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 247 | "Compute Module", |
Tuomas Tynkkynen | 9266d1d | 2017-01-23 01:34:39 +0200 | [diff] [blame] | 248 | DTB_DIR "bcm2835-rpi-cm.dtb", |
Stephen Warren | b2fa3836 | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 249 | false, |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 250 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 251 | [0x12] = { |
Stephen Warren | 18a5fc6 | 2014-12-23 20:01:43 -0700 | [diff] [blame] | 252 | "Model A+", |
Tuomas Tynkkynen | 9266d1d | 2017-01-23 01:34:39 +0200 | [diff] [blame] | 253 | DTB_DIR "bcm2835-rpi-a-plus.dtb", |
Stephen Warren | 18a5fc6 | 2014-12-23 20:01:43 -0700 | [diff] [blame] | 254 | false, |
| 255 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 256 | [0x13] = { |
Stephen Warren | 3648a85 | 2015-04-12 21:43:25 -0600 | [diff] [blame] | 257 | "Model B+", |
Tuomas Tynkkynen | 9266d1d | 2017-01-23 01:34:39 +0200 | [diff] [blame] | 258 | DTB_DIR "bcm2835-rpi-b-plus.dtb", |
Stephen Warren | 3648a85 | 2015-04-12 21:43:25 -0600 | [diff] [blame] | 259 | true, |
| 260 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 261 | [0x14] = { |
Stephen Warren | 3648a85 | 2015-04-12 21:43:25 -0600 | [diff] [blame] | 262 | "Compute Module", |
Tuomas Tynkkynen | 9266d1d | 2017-01-23 01:34:39 +0200 | [diff] [blame] | 263 | DTB_DIR "bcm2835-rpi-cm.dtb", |
Stephen Warren | 3648a85 | 2015-04-12 21:43:25 -0600 | [diff] [blame] | 264 | false, |
| 265 | }, |
Stephen Warren | be8efec | 2015-12-04 22:07:44 -0700 | [diff] [blame] | 266 | [0x15] = { |
Lubomir Rintel | c87458c | 2015-10-14 17:17:54 +0200 | [diff] [blame] | 267 | "Model A+", |
Tuomas Tynkkynen | 9266d1d | 2017-01-23 01:34:39 +0200 | [diff] [blame] | 268 | DTB_DIR "bcm2835-rpi-a-plus.dtb", |
Lubomir Rintel | c87458c | 2015-10-14 17:17:54 +0200 | [diff] [blame] | 269 | false, |
| 270 | }, |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 271 | }; |
| 272 | |
Stephen Warren | 2668385 | 2015-12-04 22:07:45 -0700 | [diff] [blame] | 273 | static uint32_t revision; |
| 274 | static uint32_t rev_scheme; |
| 275 | static uint32_t rev_type; |
| 276 | static const struct rpi_model *model; |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 277 | |
Stephen Warren | 0e012c3 | 2012-08-05 16:07:22 +0000 | [diff] [blame] | 278 | int dram_init(void) |
| 279 | { |
Alexander Stein | c56c947 | 2015-07-24 09:22:12 +0200 | [diff] [blame] | 280 | ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_arm_mem, msg, 1); |
Stephen Warren | acc8bf4 | 2013-01-29 16:37:37 +0000 | [diff] [blame] | 281 | int ret; |
| 282 | |
| 283 | BCM2835_MBOX_INIT_HDR(msg); |
| 284 | BCM2835_MBOX_INIT_TAG(&msg->get_arm_mem, GET_ARM_MEMORY); |
| 285 | |
| 286 | ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr); |
| 287 | if (ret) { |
| 288 | printf("bcm2835: Could not query ARM memory size\n"); |
| 289 | return -1; |
| 290 | } |
| 291 | |
| 292 | gd->ram_size = msg->get_arm_mem.body.resp.mem_size; |
Stephen Warren | 0e012c3 | 2012-08-05 16:07:22 +0000 | [diff] [blame] | 293 | |
Marek Szyprowski | 8c5ca98 | 2021-02-01 12:16:33 +0100 | [diff] [blame] | 294 | /* |
| 295 | * In some configurations the memory size returned by VideoCore |
| 296 | * is not aligned to the section size, what is mandatory for |
| 297 | * the u-boot's memory setup. |
| 298 | */ |
| 299 | gd->ram_size &= ~MMU_SECTION_SIZE; |
| 300 | |
Stephen Warren | 0e012c3 | 2012-08-05 16:07:22 +0000 | [diff] [blame] | 301 | return 0; |
| 302 | } |
| 303 | |
Matthias Brugger | d3dcfe2 | 2019-09-09 18:31:56 +0200 | [diff] [blame] | 304 | #ifdef CONFIG_OF_BOARD |
Matthias Brugger | d3dcfe2 | 2019-09-09 18:31:56 +0200 | [diff] [blame] | 305 | int dram_init_banksize(void) |
| 306 | { |
Matthias Brugger | f978837 | 2019-12-05 18:53:13 +0100 | [diff] [blame] | 307 | int ret; |
| 308 | |
| 309 | ret = fdtdec_setup_memory_banksize(); |
| 310 | if (ret) |
| 311 | return ret; |
| 312 | |
| 313 | return fdtdec_setup_mem_size_base(); |
Matthias Brugger | d3dcfe2 | 2019-09-09 18:31:56 +0200 | [diff] [blame] | 314 | } |
| 315 | #endif |
Matthias Brugger | d3dcfe2 | 2019-09-09 18:31:56 +0200 | [diff] [blame] | 316 | |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 317 | static void set_fdtfile(void) |
| 318 | { |
| 319 | const char *fdtfile; |
| 320 | |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 321 | if (env_get("fdtfile")) |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 322 | return; |
| 323 | |
Stephen Warren | 2668385 | 2015-12-04 22:07:45 -0700 | [diff] [blame] | 324 | fdtfile = model->fdtfile; |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 325 | env_set("fdtfile", fdtfile); |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 326 | } |
| 327 | |
Cédric Schieli | 9473f53 | 2016-11-11 11:59:07 +0100 | [diff] [blame] | 328 | /* |
| 329 | * If the firmware provided a valid FDT at boot time, let's expose it in |
| 330 | * ${fdt_addr} so it may be passed unmodified to the kernel. |
| 331 | */ |
| 332 | static void set_fdt_addr(void) |
| 333 | { |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 334 | if (env_get("fdt_addr")) |
Cédric Schieli | 9473f53 | 2016-11-11 11:59:07 +0100 | [diff] [blame] | 335 | return; |
| 336 | |
| 337 | if (fdt_magic(fw_dtb_pointer) != FDT_MAGIC) |
| 338 | return; |
| 339 | |
Simon Glass | 4d949a2 | 2017-08-03 12:22:10 -0600 | [diff] [blame] | 340 | env_set_hex("fdt_addr", fw_dtb_pointer); |
Cédric Schieli | 9473f53 | 2016-11-11 11:59:07 +0100 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | /* |
| 344 | * Prevent relocation from stomping on a firmware provided FDT blob. |
| 345 | */ |
Heinrich Schuchardt | 51a9aac | 2023-08-12 20:16:58 +0200 | [diff] [blame] | 346 | phys_addr_t board_get_usable_ram_top(phys_size_t total_size) |
Cédric Schieli | 9473f53 | 2016-11-11 11:59:07 +0100 | [diff] [blame] | 347 | { |
| 348 | if ((gd->ram_top - fw_dtb_pointer) > SZ_64M) |
| 349 | return gd->ram_top; |
| 350 | return fw_dtb_pointer & ~0xffff; |
| 351 | } |
| 352 | |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 353 | static void set_usbethaddr(void) |
Stephen Warren | af6e20d | 2014-09-26 20:51:39 -0600 | [diff] [blame] | 354 | { |
Alexander Stein | c56c947 | 2015-07-24 09:22:12 +0200 | [diff] [blame] | 355 | ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_mac_address, msg, 1); |
Stephen Warren | af6e20d | 2014-09-26 20:51:39 -0600 | [diff] [blame] | 356 | int ret; |
| 357 | |
Stephen Warren | 2668385 | 2015-12-04 22:07:45 -0700 | [diff] [blame] | 358 | if (!model->has_onboard_eth) |
Stephen Warren | b2fa3836 | 2014-12-05 20:56:46 -0700 | [diff] [blame] | 359 | return; |
| 360 | |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 361 | if (env_get("usbethaddr")) |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 362 | return; |
Stephen Warren | af6e20d | 2014-09-26 20:51:39 -0600 | [diff] [blame] | 363 | |
| 364 | BCM2835_MBOX_INIT_HDR(msg); |
| 365 | BCM2835_MBOX_INIT_TAG(&msg->get_mac_address, GET_MAC_ADDRESS); |
| 366 | |
| 367 | ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr); |
| 368 | if (ret) { |
| 369 | printf("bcm2835: Could not query MAC address\n"); |
| 370 | /* Ignore error; not critical */ |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 371 | return; |
Stephen Warren | af6e20d | 2014-09-26 20:51:39 -0600 | [diff] [blame] | 372 | } |
| 373 | |
Simon Glass | 8551d55 | 2017-08-03 12:22:11 -0600 | [diff] [blame] | 374 | eth_env_set_enetaddr("usbethaddr", msg->get_mac_address.body.resp.mac); |
Stephen Warren | af6e20d | 2014-09-26 20:51:39 -0600 | [diff] [blame] | 375 | |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 376 | if (!env_get("ethaddr")) |
| 377 | env_set("ethaddr", env_get("usbethaddr")); |
Lubomir Rintel | 3ac09f8 | 2016-02-03 16:08:09 +0100 | [diff] [blame] | 378 | |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 379 | return; |
| 380 | } |
| 381 | |
Guillaume GARDET | 25fa860 | 2015-08-25 15:10:26 +0200 | [diff] [blame] | 382 | #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG |
| 383 | static void set_board_info(void) |
| 384 | { |
Stephen Warren | 2668385 | 2015-12-04 22:07:45 -0700 | [diff] [blame] | 385 | char s[11]; |
| 386 | |
| 387 | snprintf(s, sizeof(s), "0x%X", revision); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 388 | env_set("board_revision", s); |
Francois Berder | e440310 | 2024-07-09 14:20:48 +0200 | [diff] [blame] | 389 | snprintf(s, sizeof(s), "%u", rev_scheme); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 390 | env_set("board_rev_scheme", s); |
Stephen Warren | 2668385 | 2015-12-04 22:07:45 -0700 | [diff] [blame] | 391 | /* Can't rename this to board_rev_type since it's an ABI for scripts */ |
| 392 | snprintf(s, sizeof(s), "0x%X", rev_type); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 393 | env_set("board_rev", s); |
| 394 | env_set("board_name", model->name); |
Guillaume GARDET | 25fa860 | 2015-08-25 15:10:26 +0200 | [diff] [blame] | 395 | } |
| 396 | #endif /* CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG */ |
| 397 | |
Lubomir Rintel | 7d33bb6 | 2016-02-22 22:06:47 +0100 | [diff] [blame] | 398 | static void set_serial_number(void) |
| 399 | { |
| 400 | ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_board_serial, msg, 1); |
| 401 | int ret; |
| 402 | char serial_string[17] = { 0 }; |
| 403 | |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 404 | if (env_get("serial#")) |
Lubomir Rintel | 7d33bb6 | 2016-02-22 22:06:47 +0100 | [diff] [blame] | 405 | return; |
| 406 | |
| 407 | BCM2835_MBOX_INIT_HDR(msg); |
| 408 | BCM2835_MBOX_INIT_TAG_NO_REQ(&msg->get_board_serial, GET_BOARD_SERIAL); |
| 409 | |
| 410 | ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr); |
| 411 | if (ret) { |
| 412 | printf("bcm2835: Could not query board serial\n"); |
| 413 | /* Ignore error; not critical */ |
| 414 | return; |
| 415 | } |
| 416 | |
Masahiro Yamada | c7570a3 | 2018-08-06 20:47:40 +0900 | [diff] [blame] | 417 | snprintf(serial_string, sizeof(serial_string), "%016llx", |
Lubomir Rintel | 7d33bb6 | 2016-02-22 22:06:47 +0100 | [diff] [blame] | 418 | msg->get_board_serial.body.resp.serial); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 419 | env_set("serial#", serial_string); |
Lubomir Rintel | 7d33bb6 | 2016-02-22 22:06:47 +0100 | [diff] [blame] | 420 | } |
| 421 | |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 422 | int misc_init_r(void) |
| 423 | { |
Cédric Schieli | 9473f53 | 2016-11-11 11:59:07 +0100 | [diff] [blame] | 424 | set_fdt_addr(); |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 425 | set_fdtfile(); |
| 426 | set_usbethaddr(); |
Guillaume GARDET | 25fa860 | 2015-08-25 15:10:26 +0200 | [diff] [blame] | 427 | #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG |
| 428 | set_board_info(); |
| 429 | #endif |
Lubomir Rintel | 7d33bb6 | 2016-02-22 22:06:47 +0100 | [diff] [blame] | 430 | set_serial_number(); |
| 431 | |
Stephen Warren | af6e20d | 2014-09-26 20:51:39 -0600 | [diff] [blame] | 432 | return 0; |
| 433 | } |
| 434 | |
Tom Rini | 4cc3885 | 2021-08-30 09:16:30 -0400 | [diff] [blame] | 435 | static void get_board_revision(void) |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 436 | { |
Alexander Stein | c56c947 | 2015-07-24 09:22:12 +0200 | [diff] [blame] | 437 | ALLOC_CACHE_ALIGN_BUFFER(struct msg_get_board_rev, msg, 1); |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 438 | int ret; |
Stephen Warren | 2668385 | 2015-12-04 22:07:45 -0700 | [diff] [blame] | 439 | const struct rpi_model *models; |
| 440 | uint32_t models_count; |
Ivan T. Ivanov | 14fb952 | 2024-01-23 10:07:55 +0200 | [diff] [blame] | 441 | ofnode node; |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 442 | |
| 443 | BCM2835_MBOX_INIT_HDR(msg); |
| 444 | BCM2835_MBOX_INIT_TAG(&msg->get_board_rev, GET_BOARD_REV); |
| 445 | |
| 446 | ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr); |
| 447 | if (ret) { |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 448 | /* Ignore error; not critical */ |
Ivan T. Ivanov | 14fb952 | 2024-01-23 10:07:55 +0200 | [diff] [blame] | 449 | node = ofnode_path("/system"); |
| 450 | if (!ofnode_valid(node)) { |
| 451 | printf("bcm2835: Could not find /system node\n"); |
| 452 | return; |
| 453 | } |
| 454 | |
| 455 | ret = ofnode_read_u32(node, "linux,revision", &revision); |
| 456 | if (ret) { |
| 457 | printf("bcm2835: Could not find linux,revision\n"); |
| 458 | return; |
| 459 | } |
| 460 | } else { |
| 461 | revision = msg->get_board_rev.body.resp.rev; |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 462 | } |
| 463 | |
Stephen Warren | dc7ea68 | 2015-02-16 12:16:15 -0700 | [diff] [blame] | 464 | /* |
| 465 | * For details of old-vs-new scheme, see: |
| 466 | * https://github.com/pimoroni/RPi.version/blob/master/RPi/version.py |
| 467 | * http://www.raspberrypi.org/forums/viewtopic.php?f=63&t=99293&p=690282 |
| 468 | * (a few posts down) |
Stephen Warren | b834af8 | 2015-03-23 23:00:25 -0600 | [diff] [blame] | 469 | * |
| 470 | * For the RPi 1, bit 24 is the "warranty bit", so we mask off just the |
| 471 | * lower byte to use as the board rev: |
| 472 | * http://www.raspberrypi.org/forums/viewtopic.php?f=63&t=98367&start=250 |
| 473 | * http://www.raspberrypi.org/forums/viewtopic.php?f=31&t=20594 |
Stephen Warren | dc7ea68 | 2015-02-16 12:16:15 -0700 | [diff] [blame] | 474 | */ |
Stephen Warren | 2668385 | 2015-12-04 22:07:45 -0700 | [diff] [blame] | 475 | if (revision & 0x800000) { |
| 476 | rev_scheme = 1; |
| 477 | rev_type = (revision >> 4) & 0xff; |
| 478 | models = rpi_models_new_scheme; |
| 479 | models_count = ARRAY_SIZE(rpi_models_new_scheme); |
| 480 | } else { |
| 481 | rev_scheme = 0; |
| 482 | rev_type = revision & 0xff; |
| 483 | models = rpi_models_old_scheme; |
| 484 | models_count = ARRAY_SIZE(rpi_models_old_scheme); |
Stephen Warren | 18a5fc6 | 2014-12-23 20:01:43 -0700 | [diff] [blame] | 485 | } |
Stephen Warren | 2668385 | 2015-12-04 22:07:45 -0700 | [diff] [blame] | 486 | if (rev_type >= models_count) { |
| 487 | printf("RPI: Board rev 0x%x outside known range\n", rev_type); |
| 488 | model = &rpi_model_unknown; |
| 489 | } else if (!models[rev_type].name) { |
| 490 | printf("RPI: Board rev 0x%x unknown\n", rev_type); |
| 491 | model = &rpi_model_unknown; |
| 492 | } else { |
| 493 | model = &models[rev_type]; |
Stephen Warren | 18a5fc6 | 2014-12-23 20:01:43 -0700 | [diff] [blame] | 494 | } |
Stephen Warren | c61dfd1 | 2014-12-23 20:01:44 -0700 | [diff] [blame] | 495 | |
Stephen Warren | 2668385 | 2015-12-04 22:07:45 -0700 | [diff] [blame] | 496 | printf("RPI %s (0x%x)\n", model->name, revision); |
Stephen Warren | cd210c1 | 2014-11-18 21:40:21 -0700 | [diff] [blame] | 497 | } |
| 498 | |
Fabian Vogt | 1d317b7 | 2016-09-26 14:26:50 +0200 | [diff] [blame] | 499 | int board_init(void) |
Alexander Graf | afb9907 | 2016-08-15 17:48:51 +0200 | [diff] [blame] | 500 | { |
Tom Rini | 4cc3885 | 2021-08-30 09:16:30 -0400 | [diff] [blame] | 501 | get_board_revision(); |
Fabian Vogt | 1d317b7 | 2016-09-26 14:26:50 +0200 | [diff] [blame] | 502 | |
| 503 | gd->bd->bi_boot_params = 0x100; |
| 504 | |
Simon Glass | 558ec67 | 2017-04-05 16:23:36 -0600 | [diff] [blame] | 505 | return bcm2835_power_on_module(BCM2835_MBOX_POWER_DEVID_USB_HCD); |
Alexander Graf | afb9907 | 2016-08-15 17:48:51 +0200 | [diff] [blame] | 506 | } |
| 507 | |
Alex Deymo | 5b661ec | 2017-04-02 01:25:20 -0700 | [diff] [blame] | 508 | /* |
| 509 | * If the firmware passed a device tree use it for U-Boot. |
| 510 | */ |
Ilias Apalodimas | ab5348a | 2021-10-26 09:12:33 +0300 | [diff] [blame] | 511 | void *board_fdt_blob_setup(int *err) |
Alex Deymo | 5b661ec | 2017-04-02 01:25:20 -0700 | [diff] [blame] | 512 | { |
Ilias Apalodimas | ab5348a | 2021-10-26 09:12:33 +0300 | [diff] [blame] | 513 | *err = 0; |
| 514 | if (fdt_magic(fw_dtb_pointer) != FDT_MAGIC) { |
| 515 | *err = -ENXIO; |
Alex Deymo | 5b661ec | 2017-04-02 01:25:20 -0700 | [diff] [blame] | 516 | return NULL; |
Ilias Apalodimas | ab5348a | 2021-10-26 09:12:33 +0300 | [diff] [blame] | 517 | } |
| 518 | |
Alex Deymo | 5b661ec | 2017-04-02 01:25:20 -0700 | [diff] [blame] | 519 | return (void *)fw_dtb_pointer; |
| 520 | } |
| 521 | |
Antoine Mazeas | fb78482 | 2022-08-19 10:56:45 +0200 | [diff] [blame] | 522 | int copy_property(void *dst, void *src, char *path, char *property) |
| 523 | { |
| 524 | int dst_offset, src_offset; |
| 525 | const fdt32_t *prop; |
| 526 | int len; |
| 527 | |
| 528 | src_offset = fdt_path_offset(src, path); |
| 529 | dst_offset = fdt_path_offset(dst, path); |
| 530 | |
| 531 | if (src_offset < 0 || dst_offset < 0) |
| 532 | return -1; |
| 533 | |
| 534 | prop = fdt_getprop(src, src_offset, property, &len); |
| 535 | if (!prop) |
| 536 | return -1; |
| 537 | |
| 538 | return fdt_setprop(dst, dst_offset, property, prop, len); |
| 539 | } |
| 540 | |
| 541 | /* Copy tweaks from the firmware dtb to the loaded dtb */ |
| 542 | void update_fdt_from_fw(void *fdt, void *fw_fdt) |
| 543 | { |
| 544 | /* Using dtb from firmware directly; leave it alone */ |
| 545 | if (fdt == fw_fdt) |
| 546 | return; |
| 547 | |
| 548 | /* The firmware provides a more precie model; so copy that */ |
| 549 | copy_property(fdt, fw_fdt, "/", "model"); |
| 550 | |
| 551 | /* memory reserve as suggested by the firmware */ |
| 552 | copy_property(fdt, fw_fdt, "/", "memreserve"); |
| 553 | |
| 554 | /* Adjust dma-ranges for the SD card and PCI bus as they can depend on |
| 555 | * the SoC revision |
| 556 | */ |
| 557 | copy_property(fdt, fw_fdt, "emmc2bus", "dma-ranges"); |
| 558 | copy_property(fdt, fw_fdt, "pcie0", "dma-ranges"); |
| 559 | |
| 560 | /* Bootloader configuration template exposes as nvmem */ |
| 561 | if (copy_property(fdt, fw_fdt, "blconfig", "reg") == 0) |
| 562 | copy_property(fdt, fw_fdt, "blconfig", "status"); |
| 563 | |
| 564 | /* kernel address randomisation seed as provided by the firmware */ |
| 565 | copy_property(fdt, fw_fdt, "/chosen", "kaslr-seed"); |
Antoine Mazeas | 533e584 | 2022-08-19 10:56:46 +0200 | [diff] [blame] | 566 | |
| 567 | /* address of the PHY device as provided by the firmware */ |
| 568 | copy_property(fdt, fw_fdt, "ethernet0/mdio@e14/ethernet-phy@1", "reg"); |
Antoine Mazeas | fb78482 | 2022-08-19 10:56:45 +0200 | [diff] [blame] | 569 | } |
| 570 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 571 | int ft_board_setup(void *blob, struct bd_info *bd) |
Stephen Warren | aa44d53 | 2013-05-27 18:31:18 +0000 | [diff] [blame] | 572 | { |
Ivan T. Ivanov | 6436ecf | 2021-08-10 16:31:14 +0200 | [diff] [blame] | 573 | int node; |
| 574 | |
Antoine Mazeas | fb78482 | 2022-08-19 10:56:45 +0200 | [diff] [blame] | 575 | update_fdt_from_fw(blob, (void *)fw_dtb_pointer); |
| 576 | |
Ivan T. Ivanov | 6436ecf | 2021-08-10 16:31:14 +0200 | [diff] [blame] | 577 | node = fdt_node_offset_by_compatible(blob, -1, "simple-framebuffer"); |
| 578 | if (node < 0) |
Patrick Delaunay | e7e69a5 | 2021-11-15 16:32:19 +0100 | [diff] [blame] | 579 | fdt_simplefb_add_node(blob); |
Meng Li | c5eaa07 | 2023-07-26 10:42:35 +0800 | [diff] [blame] | 580 | else |
| 581 | fdt_simplefb_enable_and_mem_rsv(blob); |
Simon Glass | 2aec3cc | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 582 | |
Alexander Graf | 013e9ae | 2016-11-02 10:36:20 +0100 | [diff] [blame] | 583 | #ifdef CONFIG_EFI_LOADER |
| 584 | /* Reserve the spin table */ |
Michael Walle | 282d386 | 2020-05-17 12:29:19 +0200 | [diff] [blame] | 585 | efi_add_memory_map(0, CONFIG_RPI_EFI_NR_SPIN_PAGES << EFI_PAGE_SHIFT, |
| 586 | EFI_RESERVED_MEMORY_TYPE); |
Alexander Graf | 013e9ae | 2016-11-02 10:36:20 +0100 | [diff] [blame] | 587 | #endif |
| 588 | |
Simon Glass | 2aec3cc | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 589 | return 0; |
Stephen Warren | aa44d53 | 2013-05-27 18:31:18 +0000 | [diff] [blame] | 590 | } |
Simon Glass | 18d4a11 | 2024-10-23 15:20:12 +0200 | [diff] [blame] | 591 | |
| 592 | #if CONFIG_IS_ENABLED(GENERATE_ACPI_TABLE) |
| 593 | static bool is_rpi4(void) |
| 594 | { |
| 595 | return of_machine_is_compatible("brcm,bcm2711") || |
| 596 | of_machine_is_compatible("brcm,bcm2712"); |
| 597 | } |
| 598 | |
| 599 | static bool is_rpi3(void) |
| 600 | { |
| 601 | return of_machine_is_compatible("brcm,bcm2837"); |
| 602 | } |
| 603 | |
| 604 | static int acpi_rpi_board_fill_ssdt(struct acpi_ctx *ctx) |
| 605 | { |
| 606 | int node, ret, uart_in_use, mini_clock_rate; |
| 607 | bool enabled; |
| 608 | struct udevice *dev; |
| 609 | struct { |
| 610 | const char *fdt_compatible; |
| 611 | const char *acpi_scope; |
| 612 | bool on_rpi4; |
| 613 | bool on_rpi3; |
| 614 | u32 mmio_address; |
| 615 | } map[] = { |
| 616 | {"brcm,bcm2711-pcie", "\\_SB.PCI0", true, false}, |
| 617 | {"brcm,bcm2711-emmc2", "\\_SB.GDV1.SDC3", true, false}, |
| 618 | {"brcm,bcm2835-pwm", "\\_SB.GDV0.PWM0", true, true}, |
| 619 | {"brcm,bcm2711-genet-v5", "\\_SB.ETH0", true, false}, |
| 620 | {"brcm,bcm2711-thermal", "\\_SB.EC00", true, true}, |
| 621 | {"brcm,bcm2835-sdhci", "\\_SB.SDC1", true, true}, |
| 622 | {"brcm,bcm2835-sdhost", "\\_SB.SDC2", false, true}, |
| 623 | {"brcm,bcm2835-mbox", "\\_SB.GDV0.RPIQ", true, true}, |
| 624 | {"brcm,bcm2835-i2c", "\\_SB.GDV0.I2C1", true, true, 0xfe205000}, |
| 625 | {"brcm,bcm2835-i2c", "\\_SB.GDV0.I2C2", true, true, 0xfe804000}, |
| 626 | {"brcm,bcm2835-spi", "\\_SB.GDV0.SPI0", true, true}, |
| 627 | {"brcm,bcm2835-aux-spi", "\\_SB.GDV0.SPI1", true, true, 0xfe215080}, |
| 628 | {"arm,pl011", "\\_SB.URT0", true, true}, |
| 629 | {"brcm,bcm2835-aux-uart", "\\_SB.URTM", true, true}, |
| 630 | { /* Sentinel */ } |
| 631 | }; |
| 632 | |
| 633 | /* Device enable */ |
| 634 | for (int i = 0; map[i].fdt_compatible; i++) { |
| 635 | if ((is_rpi4() && !map[i].on_rpi4) || |
| 636 | (is_rpi3() && !map[i].on_rpi3)) { |
| 637 | enabled = false; |
| 638 | } else { |
| 639 | node = fdt_node_offset_by_compatible(gd->fdt_blob, -1, |
| 640 | map[i].fdt_compatible); |
| 641 | while (node != -FDT_ERR_NOTFOUND && map[i].mmio_address) { |
| 642 | struct fdt_resource r; |
| 643 | |
| 644 | ret = fdt_get_resource(gd->fdt_blob, node, "reg", 0, &r); |
| 645 | if (ret) { |
| 646 | node = -FDT_ERR_NOTFOUND; |
| 647 | break; |
| 648 | } |
| 649 | |
| 650 | if (r.start == map[i].mmio_address) |
| 651 | break; |
| 652 | |
| 653 | node = fdt_node_offset_by_compatible(gd->fdt_blob, node, |
| 654 | map[i].fdt_compatible); |
| 655 | } |
| 656 | |
| 657 | enabled = (node > 0) ? fdtdec_get_is_enabled(gd->fdt_blob, node) : 0; |
| 658 | } |
| 659 | acpigen_write_scope(ctx, map[i].acpi_scope); |
| 660 | acpigen_write_name_integer(ctx, "_STA", enabled ? 0xf : 0); |
| 661 | acpigen_pop_len(ctx); |
| 662 | } |
| 663 | |
| 664 | /* GPIO quirks */ |
| 665 | node = fdt_node_offset_by_compatible(gd->fdt_blob, -1, "brcm,bcm2835-gpio"); |
| 666 | if (node <= 0) |
| 667 | node = fdt_node_offset_by_compatible(gd->fdt_blob, -1, "brcm,bcm2711-gpio"); |
| 668 | |
| 669 | acpigen_write_scope(ctx, "\\_SB.GDV0.GPI0"); |
| 670 | enabled = (node > 0) ? fdtdec_get_is_enabled(gd->fdt_blob, node) : 0; |
| 671 | acpigen_write_name_integer(ctx, "_STA", enabled ? 0xf : 0); |
| 672 | acpigen_pop_len(ctx); |
| 673 | |
| 674 | if (is_rpi4()) { |
| 675 | /* eMMC quirks */ |
| 676 | node = fdt_node_offset_by_compatible(gd->fdt_blob, -1, "brcm,bcm2711-emmc2"); |
| 677 | if (node) { |
| 678 | phys_addr_t cpu; |
| 679 | dma_addr_t bus; |
| 680 | u64 size; |
| 681 | |
| 682 | ret = fdt_get_dma_range(gd->fdt_blob, node, &cpu, &bus, &size); |
| 683 | |
| 684 | acpigen_write_scope(ctx, "\\_SB.GDV1"); |
| 685 | acpigen_write_method_serialized(ctx, "_DMA", 0); |
| 686 | acpigen_emit_byte(ctx, RETURN_OP); |
| 687 | |
| 688 | if (!ret && bus != cpu) /* Translated DMA range */ |
| 689 | acpigen_emit_namestring(ctx, "\\_SB.GDV1.DMTR"); |
| 690 | else if (!ret && bus == cpu) /* Non translated DMA */ |
| 691 | acpigen_emit_namestring(ctx, "\\_SB.GDV1.DMNT"); |
| 692 | else /* Silicon revisions older than C0: Translated DMA range */ |
| 693 | acpigen_emit_namestring(ctx, "\\_SB.GDV1.DMTR"); |
| 694 | acpigen_pop_len(ctx); |
| 695 | } |
| 696 | } |
| 697 | |
| 698 | /* Serial */ |
| 699 | uart_in_use = ~0; |
| 700 | mini_clock_rate = 0x1000000; |
| 701 | |
| 702 | ret = uclass_get_device_by_driver(UCLASS_SERIAL, |
| 703 | DM_DRIVER_GET(bcm283x_pl011_uart), |
| 704 | &dev); |
| 705 | if (!ret) |
| 706 | uart_in_use = 0; |
| 707 | |
| 708 | ret = uclass_get_device_by_driver(UCLASS_SERIAL, |
| 709 | DM_DRIVER_GET(serial_bcm283x_mu), |
| 710 | &dev); |
| 711 | if (!ret) { |
| 712 | if (uart_in_use == 0) |
| 713 | log_err("Invalid config: PL011 and MiniUART are both enabled."); |
| 714 | else |
| 715 | uart_in_use = 1; |
| 716 | |
| 717 | mini_clock_rate = dev_read_u32_default(dev, "clock", 0x1000000); |
| 718 | } |
| 719 | if (uart_in_use > 1) |
| 720 | log_err("No working serial: PL011 and MiniUART are both disabled."); |
| 721 | |
| 722 | acpigen_write_scope(ctx, "\\_SB.BTH0"); |
| 723 | acpigen_write_name_integer(ctx, "URIU", uart_in_use); |
| 724 | acpigen_pop_len(ctx); |
| 725 | |
| 726 | acpigen_write_scope(ctx, "\\_SB.URTM"); |
| 727 | acpigen_write_name_integer(ctx, "MUCR", mini_clock_rate); |
| 728 | acpigen_pop_len(ctx); |
| 729 | |
| 730 | return 0; |
| 731 | } |
| 732 | |
| 733 | static int rpi_acpi_write_ssdt(struct acpi_ctx *ctx, const struct acpi_writer *entry) |
| 734 | { |
| 735 | struct acpi_table_header *ssdt; |
| 736 | int ret; |
| 737 | |
| 738 | ssdt = ctx->current; |
| 739 | memset(ssdt, '\0', sizeof(struct acpi_table_header)); |
| 740 | |
| 741 | acpi_fill_header(ssdt, "SSDT"); |
| 742 | ssdt->revision = acpi_get_table_revision(ACPITAB_SSDT); |
| 743 | ssdt->creator_revision = 1; |
| 744 | ssdt->length = sizeof(struct acpi_table_header); |
| 745 | |
| 746 | acpi_inc(ctx, sizeof(struct acpi_table_header)); |
| 747 | |
| 748 | ret = acpi_rpi_board_fill_ssdt(ctx); |
| 749 | if (ret) { |
| 750 | ctx->current = ssdt; |
| 751 | return log_msg_ret("fill", ret); |
| 752 | } |
| 753 | |
| 754 | /* (Re)calculate length and checksum */ |
| 755 | ssdt->length = ctx->current - (void *)ssdt; |
| 756 | ssdt->checksum = table_compute_checksum((void *)ssdt, ssdt->length); |
| 757 | log_debug("SSDT at %p, length %x\n", ssdt, ssdt->length); |
| 758 | |
| 759 | /* Drop the table if it is empty */ |
| 760 | if (ssdt->length == sizeof(struct acpi_table_header)) |
| 761 | return log_msg_ret("fill", -ENOENT); |
| 762 | acpi_add_table(ctx, ssdt); |
| 763 | |
| 764 | return 0; |
| 765 | } |
| 766 | |
| 767 | ACPI_WRITER(5ssdt, "SSDT", rpi_acpi_write_ssdt, 0); |
| 768 | #endif |