Jan Kiszka | 8ff2ff8 | 2021-09-18 08:17:53 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Board specific initialization for IOT2050 |
Jan Kiszka | b2d24f9 | 2023-07-27 06:34:54 +0200 | [diff] [blame] | 4 | * Copyright (c) Siemens AG, 2018-2023 |
Jan Kiszka | 8ff2ff8 | 2021-09-18 08:17:53 +0200 | [diff] [blame] | 5 | * |
| 6 | * Authors: |
| 7 | * Le Jin <le.jin@siemens.com> |
| 8 | * Jan Kiszka <jan.kiszka@siemens.com> |
| 9 | */ |
| 10 | |
Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 11 | #include <config.h> |
Jan Kiszka | 8ff2ff8 | 2021-09-18 08:17:53 +0200 | [diff] [blame] | 12 | #include <bootstage.h> |
| 13 | #include <dm.h> |
Jan Kiszka | e31f16c | 2023-02-28 19:19:23 +0100 | [diff] [blame] | 14 | #include <fdt_support.h> |
Jan Kiszka | 8ff2ff8 | 2021-09-18 08:17:53 +0200 | [diff] [blame] | 15 | #include <i2c.h> |
| 16 | #include <led.h> |
| 17 | #include <malloc.h> |
Jan Kiszka | e31f16c | 2023-02-28 19:19:23 +0100 | [diff] [blame] | 18 | #include <mapmem.h> |
Jan Kiszka | 8ff2ff8 | 2021-09-18 08:17:53 +0200 | [diff] [blame] | 19 | #include <net.h> |
| 20 | #include <phy.h> |
| 21 | #include <spl.h> |
| 22 | #include <version.h> |
| 23 | #include <linux/delay.h> |
Jan Kiszka | 8ff2ff8 | 2021-09-18 08:17:53 +0200 | [diff] [blame] | 24 | #include <asm/arch/hardware.h> |
| 25 | #include <asm/gpio.h> |
| 26 | #include <asm/io.h> |
| 27 | |
| 28 | #define IOT2050_INFO_MAGIC 0x20502050 |
| 29 | |
| 30 | struct iot2050_info { |
| 31 | u32 magic; |
| 32 | u16 size; |
| 33 | char name[20 + 1]; |
| 34 | char serial[16 + 1]; |
| 35 | char mlfb[18 + 1]; |
| 36 | char uuid[32 + 1]; |
| 37 | char a5e[18 + 1]; |
| 38 | u8 mac_addr_cnt; |
| 39 | u8 mac_addr[8][ARP_HLEN]; |
| 40 | char seboot_version[40 + 1]; |
Baocheng Su | c9bdd3d | 2024-10-22 08:04:21 +0200 | [diff] [blame] | 41 | u8 padding[3]; |
| 42 | u32 ddr_size_mb; |
Jan Kiszka | 8ff2ff8 | 2021-09-18 08:17:53 +0200 | [diff] [blame] | 43 | } __packed; |
| 44 | |
| 45 | /* |
| 46 | * Scratch SRAM (available before DDR RAM) contains extracted EEPROM data. |
| 47 | */ |
| 48 | #define IOT2050_INFO_DATA ((struct iot2050_info *) \ |
| 49 | TI_SRAM_SCRATCH_BOARD_EEPROM_START) |
| 50 | |
| 51 | DECLARE_GLOBAL_DATA_PTR; |
| 52 | |
Jan Kiszka | e31f16c | 2023-02-28 19:19:23 +0100 | [diff] [blame] | 53 | struct gpio_config { |
| 54 | const char *gpio_name; |
| 55 | const char *label; |
| 56 | }; |
| 57 | |
| 58 | enum m2_connector_mode { |
| 59 | BKEY_PCIEX2 = 0, |
| 60 | BKEY_PCIE_EKEY_PCIE, |
| 61 | BKEY_USB30_EKEY_PCIE, |
| 62 | CONNECTOR_MODE_INVALID |
| 63 | }; |
| 64 | |
| 65 | struct m2_config_pins { |
| 66 | int config[4]; |
| 67 | }; |
| 68 | |
| 69 | struct serdes_mux_control { |
| 70 | int ctrl_usb30_pcie0_lane0; |
| 71 | int ctrl_pcie1_pcie0; |
| 72 | int ctrl_usb30_pcie0_lane1; |
| 73 | }; |
| 74 | |
| 75 | struct m2_config_table { |
| 76 | struct m2_config_pins config_pins; |
| 77 | enum m2_connector_mode mode; |
| 78 | }; |
| 79 | |
| 80 | static const struct gpio_config serdes_mux_ctl_pin_info[] = { |
| 81 | {"gpio@600000_88", "CTRL_USB30_PCIE0_LANE0"}, |
| 82 | {"gpio@600000_82", "CTRL_PCIE1_PCIE0"}, |
| 83 | {"gpio@600000_89", "CTRL_USB30_PCIE0_LANE1"}, |
| 84 | }; |
| 85 | |
| 86 | static const struct gpio_config m2_bkey_cfg_pin_info[] = { |
| 87 | {"gpio@601000_18", "KEY_CONFIG_0"}, |
| 88 | {"gpio@601000_19", "KEY_CONFIG_1"}, |
| 89 | {"gpio@601000_88", "KEY_CONFIG_2"}, |
| 90 | {"gpio@601000_89", "KEY_CONFIG_3"}, |
| 91 | }; |
| 92 | |
| 93 | static const struct m2_config_table m2_config_table[] = { |
| 94 | {{{0, 1, 0, 0}}, BKEY_PCIEX2}, |
| 95 | {{{0, 0, 1, 0}}, BKEY_PCIE_EKEY_PCIE}, |
| 96 | {{{0, 1, 1, 0}}, BKEY_PCIE_EKEY_PCIE}, |
| 97 | {{{1, 0, 0, 1}}, BKEY_PCIE_EKEY_PCIE}, |
| 98 | {{{1, 1, 0, 1}}, BKEY_PCIE_EKEY_PCIE}, |
| 99 | {{{0, 0, 0, 1}}, BKEY_USB30_EKEY_PCIE}, |
| 100 | {{{0, 1, 0, 1}}, BKEY_USB30_EKEY_PCIE}, |
| 101 | {{{0, 0, 1, 1}}, BKEY_USB30_EKEY_PCIE}, |
| 102 | {{{0, 1, 1, 1}}, BKEY_USB30_EKEY_PCIE}, |
| 103 | {{{1, 0, 1, 1}}, BKEY_USB30_EKEY_PCIE}, |
| 104 | }; |
| 105 | |
| 106 | static const struct serdes_mux_control serdes_mux_ctrl[] = { |
| 107 | [BKEY_PCIEX2] = {0, 0, 1}, |
| 108 | [BKEY_PCIE_EKEY_PCIE] = {0, 1, 0}, |
| 109 | [BKEY_USB30_EKEY_PCIE] = {1, 1, 0}, |
| 110 | }; |
| 111 | |
| 112 | static const char *m2_connector_mode_name[] = { |
| 113 | [BKEY_PCIEX2] = "PCIe x2 (key B)", |
| 114 | [BKEY_PCIE_EKEY_PCIE] = "PCIe (key B) / PCIe (key E)", |
| 115 | [BKEY_USB30_EKEY_PCIE] = "USB 3.0 (key B) / PCIe (key E)", |
| 116 | }; |
| 117 | |
| 118 | static enum m2_connector_mode connector_mode; |
| 119 | |
| 120 | #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) |
| 121 | static void *connector_overlay; |
| 122 | static u32 connector_overlay_size; |
| 123 | #endif |
| 124 | |
| 125 | static int get_pinvalue(const char *gpio_name, const char *label) |
| 126 | { |
| 127 | struct gpio_desc gpio; |
| 128 | |
| 129 | if (dm_gpio_lookup_name(gpio_name, &gpio) < 0 || |
| 130 | dm_gpio_request(&gpio, label) < 0 || |
| 131 | dm_gpio_set_dir_flags(&gpio, GPIOD_IS_IN) < 0) { |
| 132 | pr_err("Cannot get pin %s for M.2 configuration\n", gpio_name); |
| 133 | return 0; |
| 134 | } |
| 135 | |
| 136 | return dm_gpio_get_value(&gpio); |
| 137 | } |
| 138 | |
| 139 | static void set_pinvalue(const char *gpio_name, const char *label, int value) |
| 140 | { |
| 141 | struct gpio_desc gpio; |
| 142 | |
| 143 | if (dm_gpio_lookup_name(gpio_name, &gpio) < 0 || |
| 144 | dm_gpio_request(&gpio, label) < 0 || |
| 145 | dm_gpio_set_dir_flags(&gpio, GPIOD_IS_OUT) < 0) { |
| 146 | pr_err("Cannot set pin %s for M.2 configuration\n", gpio_name); |
| 147 | return; |
| 148 | } |
| 149 | dm_gpio_set_value(&gpio, value); |
| 150 | } |
| 151 | |
Jan Kiszka | b2d24f9 | 2023-07-27 06:34:54 +0200 | [diff] [blame] | 152 | static bool board_is_advanced(void) |
Jan Kiszka | e31f16c | 2023-02-28 19:19:23 +0100 | [diff] [blame] | 153 | { |
| 154 | struct iot2050_info *info = IOT2050_INFO_DATA; |
| 155 | |
Jan Kiszka | b2d24f9 | 2023-07-27 06:34:54 +0200 | [diff] [blame] | 156 | return info->magic == IOT2050_INFO_MAGIC && |
| 157 | strstr((char *)info->name, "IOT2050-ADVANCED") != NULL; |
Jan Kiszka | e31f16c | 2023-02-28 19:19:23 +0100 | [diff] [blame] | 158 | } |
| 159 | |
Jan Kiszka | 8008505 | 2023-10-17 07:20:14 +0200 | [diff] [blame] | 160 | static bool board_is_pg1(void) |
Jan Kiszka | 8ff2ff8 | 2021-09-18 08:17:53 +0200 | [diff] [blame] | 161 | { |
| 162 | struct iot2050_info *info = IOT2050_INFO_DATA; |
| 163 | |
| 164 | return info->magic == IOT2050_INFO_MAGIC && |
Jan Kiszka | 8008505 | 2023-10-17 07:20:14 +0200 | [diff] [blame] | 165 | (strcmp((char *)info->name, "IOT2050-BASIC") == 0 || |
| 166 | strcmp((char *)info->name, "IOT2050-ADVANCED") == 0); |
Jan Kiszka | 8ff2ff8 | 2021-09-18 08:17:53 +0200 | [diff] [blame] | 167 | } |
| 168 | |
Jan Kiszka | b2d24f9 | 2023-07-27 06:34:54 +0200 | [diff] [blame] | 169 | static bool board_is_m2(void) |
| 170 | { |
| 171 | struct iot2050_info *info = IOT2050_INFO_DATA; |
| 172 | |
Jan Kiszka | 8008505 | 2023-10-17 07:20:14 +0200 | [diff] [blame] | 173 | return info->magic == IOT2050_INFO_MAGIC && |
Jan Kiszka | b2d24f9 | 2023-07-27 06:34:54 +0200 | [diff] [blame] | 174 | strcmp((char *)info->name, "IOT2050-ADVANCED-M2") == 0; |
| 175 | } |
| 176 | |
Baocheng Su | 0b064eb | 2024-10-22 08:04:27 +0200 | [diff] [blame] | 177 | static bool board_is_sm(void) |
| 178 | { |
| 179 | struct iot2050_info *info = IOT2050_INFO_DATA; |
| 180 | |
| 181 | return info->magic == IOT2050_INFO_MAGIC && |
| 182 | strcmp((char *)info->name, "IOT2050-ADVANCED-SM") == 0; |
| 183 | } |
| 184 | |
Jan Kiszka | 8ff2ff8 | 2021-09-18 08:17:53 +0200 | [diff] [blame] | 185 | static void remove_mmc1_target(void) |
| 186 | { |
| 187 | char *boot_targets = strdup(env_get("boot_targets")); |
| 188 | char *mmc1 = strstr(boot_targets, "mmc1"); |
| 189 | |
| 190 | if (mmc1) { |
| 191 | memmove(mmc1, mmc1 + 4, strlen(mmc1 + 4) + 1); |
| 192 | env_set("boot_targets", boot_targets); |
| 193 | } |
| 194 | |
| 195 | free(boot_targets); |
| 196 | } |
| 197 | |
Baocheng Su | 6e8b716 | 2024-10-22 08:04:20 +0200 | [diff] [blame] | 198 | static void enable_pcie_connector_power(void) |
| 199 | { |
Baocheng Su | 0b064eb | 2024-10-22 08:04:27 +0200 | [diff] [blame] | 200 | if (board_is_sm()) |
| 201 | set_pinvalue("gpio@601000_22", "P3V3_PCIE_CON_EN", 1); |
| 202 | else |
| 203 | set_pinvalue("gpio@601000_17", "P3V3_PCIE_CON_EN", 1); |
Baocheng Su | 6e8b716 | 2024-10-22 08:04:20 +0200 | [diff] [blame] | 204 | udelay(4 * 100); |
| 205 | } |
| 206 | |
Jan Kiszka | 8ff2ff8 | 2021-09-18 08:17:53 +0200 | [diff] [blame] | 207 | void set_board_info_env(void) |
| 208 | { |
| 209 | struct iot2050_info *info = IOT2050_INFO_DATA; |
| 210 | u8 __maybe_unused mac_cnt; |
| 211 | const char *fdtfile; |
| 212 | |
| 213 | if (info->magic != IOT2050_INFO_MAGIC) { |
| 214 | pr_err("IOT2050: Board info parsing error!\n"); |
| 215 | return; |
| 216 | } |
| 217 | |
| 218 | if (env_get("board_uuid")) |
| 219 | return; |
| 220 | |
| 221 | env_set("board_name", info->name); |
| 222 | env_set("board_serial", info->serial); |
| 223 | env_set("mlfb", info->mlfb); |
| 224 | env_set("board_uuid", info->uuid); |
| 225 | env_set("board_a5e", info->a5e); |
| 226 | env_set("fw_version", PLAIN_VERSION); |
| 227 | env_set("seboot_version", info->seboot_version); |
| 228 | |
| 229 | if (IS_ENABLED(CONFIG_NET)) { |
| 230 | /* set MAC addresses to ensure forwarding to the OS */ |
| 231 | for (mac_cnt = 0; mac_cnt < info->mac_addr_cnt; mac_cnt++) { |
| 232 | if (is_valid_ethaddr(info->mac_addr[mac_cnt])) |
| 233 | eth_env_set_enetaddr_by_index("eth", |
| 234 | mac_cnt + 1, |
| 235 | info->mac_addr[mac_cnt]); |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | if (board_is_advanced()) { |
Jan Kiszka | 8008505 | 2023-10-17 07:20:14 +0200 | [diff] [blame] | 240 | if (board_is_pg1()) |
Jan Kiszka | 8ff2ff8 | 2021-09-18 08:17:53 +0200 | [diff] [blame] | 241 | fdtfile = "ti/k3-am6548-iot2050-advanced.dtb"; |
Baocheng Su | ccdeb5b | 2024-10-22 08:04:19 +0200 | [diff] [blame] | 242 | else if (board_is_m2()) |
Jan Kiszka | e31f16c | 2023-02-28 19:19:23 +0100 | [diff] [blame] | 243 | fdtfile = "ti/k3-am6548-iot2050-advanced-m2.dtb"; |
Baocheng Su | 0b064eb | 2024-10-22 08:04:27 +0200 | [diff] [blame] | 244 | else if (board_is_sm()) |
| 245 | fdtfile = "ti/k3-am6548-iot2050-advanced-sm.dtb"; |
Jan Kiszka | 8ff2ff8 | 2021-09-18 08:17:53 +0200 | [diff] [blame] | 246 | else |
| 247 | fdtfile = "ti/k3-am6548-iot2050-advanced-pg2.dtb"; |
| 248 | } else { |
Jan Kiszka | 8008505 | 2023-10-17 07:20:14 +0200 | [diff] [blame] | 249 | if (board_is_pg1()) |
Jan Kiszka | 8ff2ff8 | 2021-09-18 08:17:53 +0200 | [diff] [blame] | 250 | fdtfile = "ti/k3-am6528-iot2050-basic.dtb"; |
| 251 | else |
| 252 | fdtfile = "ti/k3-am6528-iot2050-basic-pg2.dtb"; |
| 253 | /* remove the unavailable eMMC (mmc1) from the list */ |
| 254 | remove_mmc1_target(); |
| 255 | } |
| 256 | env_set("fdtfile", fdtfile); |
| 257 | |
| 258 | env_save(); |
| 259 | } |
| 260 | |
Baocheng Su | c99731e | 2024-10-22 08:04:22 +0200 | [diff] [blame] | 261 | static void do_overlay_prepare(const char *overlay_path) |
Jan Kiszka | e31f16c | 2023-02-28 19:19:23 +0100 | [diff] [blame] | 262 | { |
| 263 | #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) |
Jan Kiszka | e31f16c | 2023-02-28 19:19:23 +0100 | [diff] [blame] | 264 | void *overlay; |
| 265 | u64 loadaddr; |
| 266 | ofnode node; |
| 267 | int ret; |
| 268 | |
Jan Kiszka | e31f16c | 2023-02-28 19:19:23 +0100 | [diff] [blame] | 269 | node = ofnode_path(overlay_path); |
| 270 | if (!ofnode_valid(node)) |
| 271 | goto fit_error; |
| 272 | |
| 273 | ret = ofnode_read_u64(node, "load", &loadaddr); |
| 274 | if (ret) |
| 275 | goto fit_error; |
| 276 | |
| 277 | ret = ofnode_read_u32(node, "size", &connector_overlay_size); |
| 278 | if (ret) |
| 279 | goto fit_error; |
| 280 | |
| 281 | overlay = map_sysmem(loadaddr, connector_overlay_size); |
| 282 | |
| 283 | connector_overlay = malloc(connector_overlay_size); |
| 284 | if (!connector_overlay) |
| 285 | goto fit_error; |
| 286 | |
| 287 | memcpy(connector_overlay, overlay, connector_overlay_size); |
| 288 | return; |
| 289 | |
| 290 | fit_error: |
| 291 | pr_err("M.2 device tree overlay %s not available,\n", overlay_path); |
| 292 | #endif |
| 293 | } |
| 294 | |
Baocheng Su | c99731e | 2024-10-22 08:04:22 +0200 | [diff] [blame] | 295 | static void m2_overlay_prepare(void) |
| 296 | { |
| 297 | const char *overlay_path; |
| 298 | |
| 299 | if (connector_mode == BKEY_PCIEX2) |
| 300 | return; |
| 301 | |
| 302 | if (connector_mode == BKEY_PCIE_EKEY_PCIE) |
| 303 | overlay_path = "/fit-images/bkey-ekey-pcie-overlay"; |
| 304 | else |
| 305 | overlay_path = "/fit-images/bkey-usb3-overlay"; |
| 306 | |
| 307 | do_overlay_prepare(overlay_path); |
| 308 | } |
| 309 | |
Jan Kiszka | e31f16c | 2023-02-28 19:19:23 +0100 | [diff] [blame] | 310 | static void m2_connector_setup(void) |
| 311 | { |
| 312 | ulong m2_manual_config = env_get_ulong("m2_manual_config", 10, |
| 313 | CONNECTOR_MODE_INVALID); |
| 314 | const char *mode_info = ""; |
| 315 | struct m2_config_pins config_pins; |
| 316 | unsigned int n; |
| 317 | |
Jan Kiszka | e31f16c | 2023-02-28 19:19:23 +0100 | [diff] [blame] | 318 | if (m2_manual_config < CONNECTOR_MODE_INVALID) { |
| 319 | mode_info = " [manual mode]"; |
| 320 | connector_mode = m2_manual_config; |
| 321 | } else { /* auto detection */ |
| 322 | for (n = 0; n < ARRAY_SIZE(config_pins.config); n++) |
| 323 | config_pins.config[n] = |
| 324 | get_pinvalue(m2_bkey_cfg_pin_info[n].gpio_name, |
| 325 | m2_bkey_cfg_pin_info[n].label); |
| 326 | connector_mode = CONNECTOR_MODE_INVALID; |
| 327 | for (n = 0; n < ARRAY_SIZE(m2_config_table); n++) { |
| 328 | if (!memcmp(config_pins.config, |
| 329 | m2_config_table[n].config_pins.config, |
| 330 | sizeof(config_pins.config))) { |
| 331 | connector_mode = m2_config_table[n].mode; |
| 332 | break; |
| 333 | } |
| 334 | } |
| 335 | if (connector_mode == CONNECTOR_MODE_INVALID) { |
| 336 | mode_info = " [fallback, card unknown/unsupported]"; |
| 337 | connector_mode = BKEY_USB30_EKEY_PCIE; |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | printf("M.2: %s%s\n", m2_connector_mode_name[connector_mode], |
| 342 | mode_info); |
| 343 | |
| 344 | /* configure serdes mux */ |
| 345 | set_pinvalue(serdes_mux_ctl_pin_info[0].gpio_name, |
| 346 | serdes_mux_ctl_pin_info[0].label, |
| 347 | serdes_mux_ctrl[connector_mode].ctrl_usb30_pcie0_lane0); |
| 348 | set_pinvalue(serdes_mux_ctl_pin_info[1].gpio_name, |
| 349 | serdes_mux_ctl_pin_info[1].label, |
| 350 | serdes_mux_ctrl[connector_mode].ctrl_pcie1_pcie0); |
| 351 | set_pinvalue(serdes_mux_ctl_pin_info[2].gpio_name, |
| 352 | serdes_mux_ctl_pin_info[2].label, |
| 353 | serdes_mux_ctrl[connector_mode].ctrl_usb30_pcie0_lane1); |
| 354 | |
| 355 | m2_overlay_prepare(); |
| 356 | } |
| 357 | |
Jan Kiszka | 8ff2ff8 | 2021-09-18 08:17:53 +0200 | [diff] [blame] | 358 | int board_init(void) |
| 359 | { |
| 360 | return 0; |
| 361 | } |
| 362 | |
| 363 | int dram_init(void) |
| 364 | { |
Baocheng Su | c9bdd3d | 2024-10-22 08:04:21 +0200 | [diff] [blame] | 365 | struct iot2050_info *info = IOT2050_INFO_DATA; |
| 366 | gd->ram_size = ((phys_size_t)(info->ddr_size_mb)) << 20; |
Jan Kiszka | 8ff2ff8 | 2021-09-18 08:17:53 +0200 | [diff] [blame] | 367 | |
| 368 | return 0; |
| 369 | } |
| 370 | |
Baocheng Su | c9bdd3d | 2024-10-22 08:04:21 +0200 | [diff] [blame] | 371 | ulong board_get_usable_ram_top(ulong total_size) |
| 372 | { |
| 373 | /* Limit RAM used by U-Boot to the DDR low region */ |
| 374 | if (gd->ram_top > 0x100000000) |
| 375 | return 0x100000000; |
| 376 | |
| 377 | return gd->ram_top; |
| 378 | } |
| 379 | |
Jan Kiszka | 8ff2ff8 | 2021-09-18 08:17:53 +0200 | [diff] [blame] | 380 | int dram_init_banksize(void) |
| 381 | { |
| 382 | dram_init(); |
| 383 | |
Baocheng Su | c9bdd3d | 2024-10-22 08:04:21 +0200 | [diff] [blame] | 384 | if (gd->ram_size > SZ_2G) { |
| 385 | /* Bank 0 declares the memory available in the DDR low region */ |
| 386 | gd->bd->bi_dram[0].start = CFG_SYS_SDRAM_BASE; |
| 387 | gd->bd->bi_dram[0].size = SZ_2G; |
| 388 | |
| 389 | /* Bank 1 declares the memory available in the DDR high region */ |
| 390 | gd->bd->bi_dram[1].start = CFG_SYS_SDRAM_BASE1; |
| 391 | gd->bd->bi_dram[1].size = gd->ram_size - SZ_2G; |
| 392 | } else { |
| 393 | /* Bank 0 declares the memory available in the DDR low region */ |
| 394 | gd->bd->bi_dram[0].start = CFG_SYS_SDRAM_BASE; |
| 395 | gd->bd->bi_dram[0].size = gd->ram_size; |
Jan Kiszka | 8ff2ff8 | 2021-09-18 08:17:53 +0200 | [diff] [blame] | 396 | |
Baocheng Su | c9bdd3d | 2024-10-22 08:04:21 +0200 | [diff] [blame] | 397 | /* Bank 1 declares the memory available in the DDR high region */ |
| 398 | gd->bd->bi_dram[1].start = 0; |
| 399 | gd->bd->bi_dram[1].size = 0; |
| 400 | } |
Jan Kiszka | 8ff2ff8 | 2021-09-18 08:17:53 +0200 | [diff] [blame] | 401 | |
| 402 | return 0; |
| 403 | } |
| 404 | |
| 405 | #ifdef CONFIG_SPL_LOAD_FIT |
| 406 | int board_fit_config_name_match(const char *name) |
| 407 | { |
| 408 | struct iot2050_info *info = IOT2050_INFO_DATA; |
| 409 | char upper_name[32]; |
| 410 | |
Jan Kiszka | 3fedadf | 2024-10-22 08:04:26 +0200 | [diff] [blame] | 411 | /* skip the prefix "ti/k3-am65x8-" */ |
| 412 | name += 13; |
Su Baocheng | 8999cc5 | 2023-02-28 19:19:10 +0100 | [diff] [blame] | 413 | |
Jan Kiszka | 8ff2ff8 | 2021-09-18 08:17:53 +0200 | [diff] [blame] | 414 | if (info->magic != IOT2050_INFO_MAGIC || |
| 415 | strlen(name) >= sizeof(upper_name)) |
| 416 | return -1; |
| 417 | |
| 418 | str_to_upper(name, upper_name, sizeof(upper_name)); |
| 419 | if (!strcmp(upper_name, (char *)info->name)) |
| 420 | return 0; |
| 421 | |
| 422 | return -1; |
| 423 | } |
| 424 | #endif |
| 425 | |
| 426 | int do_board_detect(void) |
| 427 | { |
| 428 | return 0; |
| 429 | } |
| 430 | |
| 431 | #ifdef CONFIG_IOT2050_BOOT_SWITCH |
| 432 | static bool user_button_pressed(void) |
| 433 | { |
| 434 | struct udevice *red_led = NULL; |
| 435 | unsigned long count = 0; |
| 436 | struct gpio_desc gpio; |
| 437 | |
| 438 | memset(&gpio, 0, sizeof(gpio)); |
| 439 | |
chao zeng | 7d933ad | 2023-02-28 19:19:20 +0100 | [diff] [blame] | 440 | if (dm_gpio_lookup_name("gpio@42110000_25", &gpio) < 0 || |
Jan Kiszka | 8ff2ff8 | 2021-09-18 08:17:53 +0200 | [diff] [blame] | 441 | dm_gpio_request(&gpio, "USER button") < 0 || |
| 442 | dm_gpio_set_dir_flags(&gpio, GPIOD_IS_IN) < 0) |
| 443 | return false; |
| 444 | |
| 445 | if (dm_gpio_get_value(&gpio) == 1) |
| 446 | return false; |
| 447 | |
| 448 | printf("USER button pressed - booting from external media only\n"); |
| 449 | |
| 450 | led_get_by_label("status-led-red", &red_led); |
| 451 | |
| 452 | if (red_led) |
| 453 | led_set_state(red_led, LEDST_ON); |
| 454 | |
| 455 | while (dm_gpio_get_value(&gpio) == 0 && count++ < 10000) |
| 456 | mdelay(1); |
| 457 | |
| 458 | if (red_led) |
| 459 | led_set_state(red_led, LEDST_OFF); |
| 460 | |
| 461 | return true; |
| 462 | } |
| 463 | #endif |
| 464 | |
| 465 | #define SERDES0_LANE_SELECT 0x00104080 |
| 466 | |
| 467 | int board_late_init(void) |
| 468 | { |
| 469 | /* change CTRL_MMR register to let serdes0 not output USB3.0 signals. */ |
| 470 | writel(0x3, SERDES0_LANE_SELECT); |
| 471 | |
Baocheng Su | 6e8b716 | 2024-10-22 08:04:20 +0200 | [diff] [blame] | 472 | enable_pcie_connector_power(); |
| 473 | |
Jan Kiszka | e31f16c | 2023-02-28 19:19:23 +0100 | [diff] [blame] | 474 | if (board_is_m2()) |
| 475 | m2_connector_setup(); |
| 476 | |
Jan Kiszka | 8ff2ff8 | 2021-09-18 08:17:53 +0200 | [diff] [blame] | 477 | set_board_info_env(); |
| 478 | |
| 479 | /* remove the eMMC if requested via button */ |
| 480 | if (IS_ENABLED(CONFIG_IOT2050_BOOT_SWITCH) && board_is_advanced() && |
| 481 | user_button_pressed()) |
| 482 | remove_mmc1_target(); |
| 483 | |
| 484 | return 0; |
| 485 | } |
| 486 | |
| 487 | #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) |
Baocheng Su | c99731e | 2024-10-22 08:04:22 +0200 | [diff] [blame] | 488 | static void variants_fdt_fixup(void *blob) |
Jan Kiszka | e31f16c | 2023-02-28 19:19:23 +0100 | [diff] [blame] | 489 | { |
| 490 | void *overlay_copy = NULL; |
| 491 | void *fdt_copy = NULL; |
| 492 | u32 fdt_size; |
| 493 | int err; |
| 494 | |
| 495 | if (!connector_overlay) |
| 496 | return; |
| 497 | |
| 498 | /* |
| 499 | * We need to work with temporary copies here because fdt_overlay_apply |
| 500 | * is destructive to the overlay and also to the target blob, even if |
| 501 | * application fails. |
| 502 | */ |
| 503 | fdt_size = fdt_totalsize(blob); |
| 504 | fdt_copy = malloc(fdt_size); |
| 505 | if (!fdt_copy) |
| 506 | goto fixup_error; |
| 507 | |
| 508 | memcpy(fdt_copy, blob, fdt_size); |
| 509 | |
| 510 | overlay_copy = malloc(connector_overlay_size); |
| 511 | if (!overlay_copy) |
| 512 | goto fixup_error; |
| 513 | |
| 514 | memcpy(overlay_copy, connector_overlay, connector_overlay_size); |
| 515 | |
| 516 | err = fdt_overlay_apply_verbose(fdt_copy, overlay_copy); |
| 517 | if (err) |
| 518 | goto fixup_error; |
| 519 | |
| 520 | memcpy(blob, fdt_copy, fdt_size); |
| 521 | |
| 522 | cleanup: |
| 523 | free(fdt_copy); |
| 524 | free(overlay_copy); |
| 525 | return; |
| 526 | |
| 527 | fixup_error: |
Baocheng Su | c99731e | 2024-10-22 08:04:22 +0200 | [diff] [blame] | 528 | pr_err("Could not apply device tree overlay\n"); |
Jan Kiszka | e31f16c | 2023-02-28 19:19:23 +0100 | [diff] [blame] | 529 | goto cleanup; |
| 530 | } |
| 531 | |
Jan Kiszka | 8ff2ff8 | 2021-09-18 08:17:53 +0200 | [diff] [blame] | 532 | int ft_board_setup(void *blob, struct bd_info *bd) |
| 533 | { |
Jan Kiszka | e31f16c | 2023-02-28 19:19:23 +0100 | [diff] [blame] | 534 | if (board_is_m2()) |
Baocheng Su | c99731e | 2024-10-22 08:04:22 +0200 | [diff] [blame] | 535 | variants_fdt_fixup(blob); |
Jan Kiszka | e31f16c | 2023-02-28 19:19:23 +0100 | [diff] [blame] | 536 | |
Andrew Davis | b1c2979 | 2023-04-06 11:38:10 -0500 | [diff] [blame] | 537 | return 0; |
Jan Kiszka | 8ff2ff8 | 2021-09-18 08:17:53 +0200 | [diff] [blame] | 538 | } |
| 539 | #endif |
| 540 | |
| 541 | void spl_board_init(void) |
| 542 | { |
| 543 | } |
| 544 | |
Marek Vasut | 9815434 | 2021-10-23 03:06:03 +0200 | [diff] [blame] | 545 | #if CONFIG_IS_ENABLED(LED) && CONFIG_IS_ENABLED(SHOW_BOOT_PROGRESS) |
Jan Kiszka | 8ff2ff8 | 2021-09-18 08:17:53 +0200 | [diff] [blame] | 546 | /* |
| 547 | * Indicate any error or (accidental?) entering of CLI via the red status LED. |
| 548 | */ |
| 549 | void show_boot_progress(int progress) |
| 550 | { |
| 551 | struct udevice *dev; |
| 552 | int ret; |
| 553 | |
Jan Kiszka | a8ea4f4 | 2021-11-03 15:12:30 +0100 | [diff] [blame] | 554 | if ((progress < 0 && progress != -BOOTSTAGE_ID_NET_ETH_START) || |
| 555 | progress == BOOTSTAGE_ID_ENTER_CLI_LOOP) { |
Jan Kiszka | 8ff2ff8 | 2021-09-18 08:17:53 +0200 | [diff] [blame] | 556 | ret = led_get_by_label("status-led-green", &dev); |
| 557 | if (ret == 0) |
| 558 | led_set_state(dev, LEDST_OFF); |
| 559 | |
| 560 | ret = led_get_by_label("status-led-red", &dev); |
| 561 | if (ret == 0) |
| 562 | led_set_state(dev, LEDST_ON); |
| 563 | } |
| 564 | } |
| 565 | #endif |