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