Lokesh Vutla | 1a9dd21 | 2019-06-13 10:29:49 +0530 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Board specific initialization for J721E EVM |
| 4 | * |
Nishanth Menon | eaa39c6 | 2023-11-01 15:56:03 -0500 | [diff] [blame] | 5 | * Copyright (C) 2018-2019 Texas Instruments Incorporated - https://www.ti.com/ |
Lokesh Vutla | 1a9dd21 | 2019-06-13 10:29:49 +0530 | [diff] [blame] | 6 | * Lokesh Vutla <lokeshvutla@ti.com> |
| 7 | * |
| 8 | */ |
| 9 | |
Jonathan Humphreys | 1f522a9 | 2024-06-14 11:35:34 -0500 | [diff] [blame] | 10 | #include <efi_loader.h> |
Aswath Govindraju | 1e2b420 | 2021-07-21 21:28:39 +0530 | [diff] [blame] | 11 | #include <generic-phy.h> |
Simon Glass | 2dc9c34 | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 12 | #include <image.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 13 | #include <net.h> |
Andreas Dannenberg | d036a21 | 2020-01-07 13:15:54 +0530 | [diff] [blame] | 14 | #include <asm/arch/hardware.h> |
| 15 | #include <asm/gpio.h> |
Lokesh Vutla | 1a9dd21 | 2019-06-13 10:29:49 +0530 | [diff] [blame] | 16 | #include <spl.h> |
Tero Kristo | 1a2c7ba | 2020-02-14 11:18:19 +0200 | [diff] [blame] | 17 | #include <dm.h> |
Lokesh Vutla | 1a9dd21 | 2019-06-13 10:29:49 +0530 | [diff] [blame] | 18 | |
Andreas Dannenberg | d036a21 | 2020-01-07 13:15:54 +0530 | [diff] [blame] | 19 | #include "../common/board_detect.h" |
Nishanth Menon | 3c0f831 | 2024-02-12 13:47:22 -0600 | [diff] [blame] | 20 | #include "../common/fdt_ops.h" |
Andreas Dannenberg | d036a21 | 2020-01-07 13:15:54 +0530 | [diff] [blame] | 21 | |
| 22 | #define board_is_j721e_som() (board_ti_k3_is("J721EX-PM1-SOM") || \ |
| 23 | board_ti_k3_is("J721EX-PM2-SOM")) |
| 24 | |
Sinthu Raja | 1c24ab4 | 2022-02-09 15:06:50 +0530 | [diff] [blame] | 25 | #define board_is_j721e_sk() (board_ti_k3_is("J721EX-EAIK") || \ |
| 26 | board_ti_k3_is("J721EX-SK")) |
| 27 | |
Aswath Govindraju | 1e2b420 | 2021-07-21 21:28:39 +0530 | [diff] [blame] | 28 | #define board_is_j7200_som() (board_ti_k3_is("J7200X-PM1-SOM") || \ |
| 29 | board_ti_k3_is("J7200X-PM2-SOM")) |
Lokesh Vutla | e2af966 | 2020-08-05 22:44:25 +0530 | [diff] [blame] | 30 | |
Andreas Dannenberg | d036a21 | 2020-01-07 13:15:54 +0530 | [diff] [blame] | 31 | /* Max number of MAC addresses that are parsed/processed per daughter card */ |
| 32 | #define DAUGHTER_CARD_NO_OF_MAC_ADDR 8 |
| 33 | |
Lokesh Vutla | 1a9dd21 | 2019-06-13 10:29:49 +0530 | [diff] [blame] | 34 | DECLARE_GLOBAL_DATA_PTR; |
| 35 | |
Jonathan Humphreys | 1f522a9 | 2024-06-14 11:35:34 -0500 | [diff] [blame] | 36 | struct efi_fw_image fw_images[] = { |
| 37 | { |
| 38 | .image_type_id = J721E_SK_TIBOOT3_IMAGE_GUID, |
| 39 | .fw_name = u"J721E_SK_TIBOOT3", |
| 40 | .image_index = 1, |
| 41 | }, |
| 42 | { |
| 43 | .image_type_id = J721E_SK_SPL_IMAGE_GUID, |
| 44 | .fw_name = u"J721E_SK_SPL", |
| 45 | .image_index = 2, |
| 46 | }, |
| 47 | { |
| 48 | .image_type_id = J721E_SK_UBOOT_IMAGE_GUID, |
| 49 | .fw_name = u"J721E_SK_UBOOT", |
| 50 | .image_index = 3, |
| 51 | }, |
| 52 | { |
| 53 | .image_type_id = J721E_SK_SYSFW_IMAGE_GUID, |
| 54 | .fw_name = u"J721E_SK_SYSFW", |
| 55 | .image_index = 4, |
| 56 | } |
| 57 | }; |
| 58 | |
| 59 | struct efi_capsule_update_info update_info = { |
| 60 | .dfu_string = "sf 0:0=tiboot3.bin raw 0 80000;" |
| 61 | "tispl.bin raw 80000 200000;u-boot.img raw 280000 400000;" |
| 62 | "sysfw.itb raw 6C0000 100000", |
| 63 | .num_images = ARRAY_SIZE(fw_images), |
| 64 | .images = fw_images, |
| 65 | }; |
| 66 | |
| 67 | #if IS_ENABLED(CONFIG_SET_DFU_ALT_INFO) |
| 68 | void set_dfu_alt_info(char *interface, char *devstr) |
| 69 | { |
| 70 | if (IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT)) |
| 71 | env_set("dfu_alt_info", update_info.dfu_string); |
| 72 | } |
| 73 | #endif |
| 74 | |
Lokesh Vutla | 1a9dd21 | 2019-06-13 10:29:49 +0530 | [diff] [blame] | 75 | int board_init(void) |
| 76 | { |
| 77 | return 0; |
| 78 | } |
| 79 | |
| 80 | int dram_init(void) |
| 81 | { |
| 82 | #ifdef CONFIG_PHYS_64BIT |
| 83 | gd->ram_size = 0x100000000; |
| 84 | #else |
| 85 | gd->ram_size = 0x80000000; |
| 86 | #endif |
| 87 | |
| 88 | return 0; |
| 89 | } |
| 90 | |
Heinrich Schuchardt | 51a9aac | 2023-08-12 20:16:58 +0200 | [diff] [blame] | 91 | phys_addr_t board_get_usable_ram_top(phys_size_t total_size) |
Lokesh Vutla | 1a9dd21 | 2019-06-13 10:29:49 +0530 | [diff] [blame] | 92 | { |
| 93 | #ifdef CONFIG_PHYS_64BIT |
| 94 | /* Limit RAM used by U-Boot to the DDR low region */ |
| 95 | if (gd->ram_top > 0x100000000) |
| 96 | return 0x100000000; |
| 97 | #endif |
| 98 | |
| 99 | return gd->ram_top; |
| 100 | } |
| 101 | |
| 102 | int dram_init_banksize(void) |
| 103 | { |
| 104 | /* Bank 0 declares the memory available in the DDR low region */ |
Andrew Davis | ff64dc2 | 2023-11-30 08:49:11 -0600 | [diff] [blame] | 105 | gd->bd->bi_dram[0].start = 0x80000000; |
Lokesh Vutla | 1a9dd21 | 2019-06-13 10:29:49 +0530 | [diff] [blame] | 106 | gd->bd->bi_dram[0].size = 0x80000000; |
| 107 | gd->ram_size = 0x80000000; |
| 108 | |
| 109 | #ifdef CONFIG_PHYS_64BIT |
| 110 | /* Bank 1 declares the memory available in the DDR high region */ |
Andrew Davis | ff64dc2 | 2023-11-30 08:49:11 -0600 | [diff] [blame] | 111 | gd->bd->bi_dram[1].start = 0x880000000; |
Lokesh Vutla | 1a9dd21 | 2019-06-13 10:29:49 +0530 | [diff] [blame] | 112 | gd->bd->bi_dram[1].size = 0x80000000; |
| 113 | gd->ram_size = 0x100000000; |
| 114 | #endif |
| 115 | |
| 116 | return 0; |
| 117 | } |
| 118 | |
| 119 | #ifdef CONFIG_SPL_LOAD_FIT |
| 120 | int board_fit_config_name_match(const char *name) |
| 121 | { |
Sinthu Raja | 944ff63 | 2022-02-09 15:06:52 +0530 | [diff] [blame] | 122 | bool eeprom_read = board_ti_was_eeprom_read(); |
| 123 | |
| 124 | if (!eeprom_read || board_is_j721e_som()) { |
| 125 | if (!strcmp(name, "k3-j721e-common-proc-board") || |
| 126 | !strcmp(name, "k3-j721e-r5-common-proc-board")) |
| 127 | return 0; |
| 128 | } else if (board_is_j721e_sk()) { |
| 129 | if (!strcmp(name, "k3-j721e-sk") || |
| 130 | !strcmp(name, "k3-j721e-r5-sk")) |
| 131 | return 0; |
| 132 | } |
Lokesh Vutla | 1a9dd21 | 2019-06-13 10:29:49 +0530 | [diff] [blame] | 133 | |
| 134 | return -1; |
| 135 | } |
| 136 | #endif |
Suman Anna | 8eac9e6 | 2019-06-13 10:29:50 +0530 | [diff] [blame] | 137 | |
Vignesh Raghavendra | 685d865 | 2020-08-07 00:26:57 +0530 | [diff] [blame] | 138 | #if CONFIG_IS_ENABLED(DM_GPIO) && CONFIG_IS_ENABLED(OF_LIBFDT) |
| 139 | /* Returns 1, if onboard mux is set to hyperflash */ |
| 140 | static void __maybe_unused detect_enable_hyperflash(void *blob) |
| 141 | { |
| 142 | struct gpio_desc desc = {0}; |
Vaishnav Achath | b8b1744 | 2022-05-09 11:50:16 +0530 | [diff] [blame] | 143 | char *hypermux_sel_gpio = (board_is_j721e_som()) ? "8" : "6"; |
Vignesh Raghavendra | 685d865 | 2020-08-07 00:26:57 +0530 | [diff] [blame] | 144 | |
Vaishnav Achath | b8b1744 | 2022-05-09 11:50:16 +0530 | [diff] [blame] | 145 | if (dm_gpio_lookup_name(hypermux_sel_gpio, &desc)) |
Vignesh Raghavendra | 685d865 | 2020-08-07 00:26:57 +0530 | [diff] [blame] | 146 | return; |
| 147 | |
Vaishnav Achath | b8b1744 | 2022-05-09 11:50:16 +0530 | [diff] [blame] | 148 | if (dm_gpio_request(&desc, hypermux_sel_gpio)) |
Vignesh Raghavendra | 685d865 | 2020-08-07 00:26:57 +0530 | [diff] [blame] | 149 | return; |
| 150 | |
| 151 | if (dm_gpio_set_dir_flags(&desc, GPIOD_IS_IN)) |
| 152 | return; |
| 153 | |
| 154 | if (dm_gpio_get_value(&desc)) { |
| 155 | int offset; |
| 156 | |
| 157 | do_fixup_by_compat(blob, "ti,am654-hbmc", "status", |
| 158 | "okay", sizeof("okay"), 0); |
| 159 | offset = fdt_node_offset_by_compatible(blob, -1, |
Vignesh Raghavendra | 57b7836 | 2020-09-17 16:48:16 +0530 | [diff] [blame] | 160 | "ti,am654-ospi"); |
Vignesh Raghavendra | 685d865 | 2020-08-07 00:26:57 +0530 | [diff] [blame] | 161 | fdt_setprop(blob, offset, "status", "disabled", |
| 162 | sizeof("disabled")); |
| 163 | } |
| 164 | } |
| 165 | #endif |
| 166 | |
Vaishnav Achath | b8b1744 | 2022-05-09 11:50:16 +0530 | [diff] [blame] | 167 | #if defined(CONFIG_SPL_BUILD) && (defined(CONFIG_TARGET_J7200_A72_EVM) || defined(CONFIG_TARGET_J7200_R5_EVM) || \ |
| 168 | defined(CONFIG_TARGET_J721E_A72_EVM) || defined(CONFIG_TARGET_J721E_R5_EVM)) |
Vignesh Raghavendra | 4c3c3d2 | 2020-08-13 14:56:16 +0530 | [diff] [blame] | 169 | void spl_perform_fixups(struct spl_image_info *spl_image) |
| 170 | { |
| 171 | detect_enable_hyperflash(spl_image->fdt_addr); |
| 172 | } |
| 173 | #endif |
| 174 | |
Suman Anna | 8eac9e6 | 2019-06-13 10:29:50 +0530 | [diff] [blame] | 175 | #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 176 | int ft_board_setup(void *blob, struct bd_info *bd) |
Suman Anna | 8eac9e6 | 2019-06-13 10:29:50 +0530 | [diff] [blame] | 177 | { |
Vignesh Raghavendra | 685d865 | 2020-08-07 00:26:57 +0530 | [diff] [blame] | 178 | detect_enable_hyperflash(blob); |
| 179 | |
Andrew Davis | b1c2979 | 2023-04-06 11:38:10 -0500 | [diff] [blame] | 180 | return 0; |
Suman Anna | 8eac9e6 | 2019-06-13 10:29:50 +0530 | [diff] [blame] | 181 | } |
Andreas Dannenberg | d036a21 | 2020-01-07 13:15:54 +0530 | [diff] [blame] | 182 | #endif |
| 183 | |
Lokesh Vutla | 5a08e65 | 2020-08-05 22:44:14 +0530 | [diff] [blame] | 184 | #ifdef CONFIG_TI_I2C_BOARD_DETECT |
Andreas Dannenberg | d036a21 | 2020-01-07 13:15:54 +0530 | [diff] [blame] | 185 | int do_board_detect(void) |
| 186 | { |
| 187 | int ret; |
| 188 | |
Sinthu Raja | 944ff63 | 2022-02-09 15:06:52 +0530 | [diff] [blame] | 189 | if (board_ti_was_eeprom_read()) |
| 190 | return 0; |
| 191 | |
Andreas Dannenberg | d036a21 | 2020-01-07 13:15:54 +0530 | [diff] [blame] | 192 | ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS, |
| 193 | CONFIG_EEPROM_CHIP_ADDRESS); |
Sinthu Raja | 812364f | 2022-02-09 15:06:49 +0530 | [diff] [blame] | 194 | if (ret) { |
| 195 | printf("EEPROM not available at 0x%02x, trying to read at 0x%02x\n", |
| 196 | CONFIG_EEPROM_CHIP_ADDRESS, CONFIG_EEPROM_CHIP_ADDRESS + 1); |
| 197 | ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS, |
| 198 | CONFIG_EEPROM_CHIP_ADDRESS + 1); |
| 199 | if (ret) |
| 200 | pr_err("Reading on-board EEPROM at 0x%02x failed %d\n", |
| 201 | CONFIG_EEPROM_CHIP_ADDRESS + 1, ret); |
| 202 | } |
Andreas Dannenberg | d036a21 | 2020-01-07 13:15:54 +0530 | [diff] [blame] | 203 | |
| 204 | return ret; |
| 205 | } |
| 206 | |
Lokesh Vutla | 1db6b64 | 2020-01-07 13:15:55 +0530 | [diff] [blame] | 207 | int checkboard(void) |
| 208 | { |
| 209 | struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA; |
| 210 | |
| 211 | if (do_board_detect()) |
| 212 | /* EEPROM not populated */ |
| 213 | printf("Board: %s rev %s\n", "J721EX-PM1-SOM", "E2"); |
| 214 | else |
| 215 | printf("Board: %s rev %s\n", ep->name, ep->version); |
| 216 | |
| 217 | return 0; |
| 218 | } |
| 219 | |
Andreas Dannenberg | d036a21 | 2020-01-07 13:15:54 +0530 | [diff] [blame] | 220 | /* |
| 221 | * Declaration of daughtercards to probe. Note that when adding more |
| 222 | * cards they should be grouped by the 'i2c_addr' field to allow for a |
| 223 | * more efficient probing process. |
| 224 | */ |
| 225 | static const struct { |
| 226 | u8 i2c_addr; /* I2C address of card EEPROM */ |
| 227 | char *card_name; /* EEPROM-programmed card name */ |
| 228 | char *dtbo_name; /* Device tree overlay to apply */ |
| 229 | u8 eth_offset; /* ethXaddr MAC address index offset */ |
| 230 | } ext_cards[] = { |
| 231 | { |
| 232 | 0x51, |
| 233 | "J7X-BASE-CPB", |
| 234 | "", /* No dtbo for this board */ |
| 235 | 0, |
| 236 | }, |
| 237 | { |
| 238 | 0x52, |
| 239 | "J7X-INFOTAN-EXP", |
| 240 | "", /* No dtbo for this board */ |
| 241 | 0, |
| 242 | }, |
| 243 | { |
| 244 | 0x52, |
| 245 | "J7X-GESI-EXP", |
| 246 | "", /* No dtbo for this board */ |
| 247 | 5, /* Start populating from eth5addr */ |
| 248 | }, |
| 249 | { |
| 250 | 0x54, |
| 251 | "J7X-VSC8514-ETH", |
| 252 | "", /* No dtbo for this board */ |
| 253 | 1, /* Start populating from eth1addr */ |
| 254 | }, |
| 255 | }; |
| 256 | |
| 257 | static bool daughter_card_detect_flags[ARRAY_SIZE(ext_cards)]; |
| 258 | |
| 259 | const char *board_fit_get_additionnal_images(int index, const char *type) |
| 260 | { |
| 261 | int i, j; |
| 262 | |
| 263 | if (strcmp(type, FIT_FDT_PROP)) |
| 264 | return NULL; |
| 265 | |
| 266 | j = 0; |
| 267 | for (i = 0; i < ARRAY_SIZE(ext_cards); i++) { |
| 268 | if (daughter_card_detect_flags[i]) { |
| 269 | if (j == index) { |
| 270 | /* |
| 271 | * Return dtbo name only if populated, |
| 272 | * otherwise stop parsing here. |
| 273 | */ |
| 274 | if (strlen(ext_cards[i].dtbo_name)) |
| 275 | return ext_cards[i].dtbo_name; |
| 276 | else |
| 277 | return NULL; |
| 278 | }; |
| 279 | |
| 280 | j++; |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | return NULL; |
| 285 | } |
| 286 | |
| 287 | static int probe_daughtercards(void) |
| 288 | { |
| 289 | char mac_addr[DAUGHTER_CARD_NO_OF_MAC_ADDR][TI_EEPROM_HDR_ETH_ALEN]; |
| 290 | bool eeprom_read_success; |
| 291 | struct ti_am6_eeprom ep; |
| 292 | u8 previous_i2c_addr; |
| 293 | u8 mac_addr_cnt; |
| 294 | int i; |
| 295 | int ret; |
| 296 | |
| 297 | /* Mark previous I2C address variable as not populated */ |
| 298 | previous_i2c_addr = 0xff; |
| 299 | |
| 300 | /* No EEPROM data was read yet */ |
| 301 | eeprom_read_success = false; |
| 302 | |
| 303 | /* Iterate through list of daughtercards */ |
| 304 | for (i = 0; i < ARRAY_SIZE(ext_cards); i++) { |
| 305 | /* Obtain card-specific I2C address */ |
| 306 | u8 i2c_addr = ext_cards[i].i2c_addr; |
| 307 | |
| 308 | /* Read card EEPROM if not already read previously */ |
| 309 | if (i2c_addr != previous_i2c_addr) { |
| 310 | /* Store I2C address so we can avoid reading twice */ |
| 311 | previous_i2c_addr = i2c_addr; |
| 312 | |
| 313 | /* Get and parse the daughter card EEPROM record */ |
| 314 | ret = ti_i2c_eeprom_am6_get(CONFIG_EEPROM_BUS_ADDRESS, |
| 315 | i2c_addr, |
| 316 | &ep, |
| 317 | (char **)mac_addr, |
| 318 | DAUGHTER_CARD_NO_OF_MAC_ADDR, |
| 319 | &mac_addr_cnt); |
| 320 | if (ret) { |
| 321 | debug("%s: No daughtercard EEPROM at 0x%02x found %d\n", |
| 322 | __func__, i2c_addr, ret); |
| 323 | eeprom_read_success = false; |
| 324 | /* Skip to the next daughtercard to probe */ |
| 325 | continue; |
| 326 | } |
| 327 | |
| 328 | /* EEPROM read successful, okay to further process. */ |
| 329 | eeprom_read_success = true; |
| 330 | } |
| 331 | |
| 332 | /* Only continue processing if EEPROM data was read */ |
| 333 | if (!eeprom_read_success) |
| 334 | continue; |
| 335 | |
| 336 | /* Only process the parsed data if we found a match */ |
| 337 | if (strncmp(ep.name, ext_cards[i].card_name, sizeof(ep.name))) |
| 338 | continue; |
| 339 | |
| 340 | printf("Detected: %s rev %s\n", ep.name, ep.version); |
| 341 | daughter_card_detect_flags[i] = true; |
| 342 | |
Nishanth Menon | 4f4c9d8 | 2023-11-04 02:21:41 -0500 | [diff] [blame] | 343 | if (!IS_ENABLED(CONFIG_SPL_BUILD)) { |
| 344 | int j; |
| 345 | /* |
| 346 | * Populate any MAC addresses from daughtercard into the U-Boot |
| 347 | * environment, starting with a card-specific offset so we can |
| 348 | * have multiple ext_cards contribute to the MAC pool in a well- |
| 349 | * defined manner. |
| 350 | */ |
| 351 | for (j = 0; j < mac_addr_cnt; j++) { |
| 352 | if (!is_valid_ethaddr((u8 *)mac_addr[j])) |
| 353 | continue; |
Andreas Dannenberg | d036a21 | 2020-01-07 13:15:54 +0530 | [diff] [blame] | 354 | |
Nishanth Menon | 4f4c9d8 | 2023-11-04 02:21:41 -0500 | [diff] [blame] | 355 | eth_env_set_enetaddr_by_index("eth", |
| 356 | ext_cards[i].eth_offset + j, |
| 357 | (uchar *)mac_addr[j]); |
| 358 | } |
Andreas Dannenberg | d036a21 | 2020-01-07 13:15:54 +0530 | [diff] [blame] | 359 | } |
Andreas Dannenberg | d036a21 | 2020-01-07 13:15:54 +0530 | [diff] [blame] | 360 | } |
Andreas Dannenberg | d036a21 | 2020-01-07 13:15:54 +0530 | [diff] [blame] | 361 | |
Nishanth Menon | 4f4c9d8 | 2023-11-04 02:21:41 -0500 | [diff] [blame] | 362 | if (!IS_ENABLED(CONFIG_SPL_BUILD)) { |
| 363 | char name_overlays[1024] = { 0 }; |
Andreas Dannenberg | d036a21 | 2020-01-07 13:15:54 +0530 | [diff] [blame] | 364 | |
Nishanth Menon | 4f4c9d8 | 2023-11-04 02:21:41 -0500 | [diff] [blame] | 365 | for (i = 0; i < ARRAY_SIZE(ext_cards); i++) { |
| 366 | if (!daughter_card_detect_flags[i]) |
| 367 | continue; |
Andreas Dannenberg | d036a21 | 2020-01-07 13:15:54 +0530 | [diff] [blame] | 368 | |
Nishanth Menon | 4f4c9d8 | 2023-11-04 02:21:41 -0500 | [diff] [blame] | 369 | /* Skip if no overlays are to be added */ |
| 370 | if (!strlen(ext_cards[i].dtbo_name)) |
| 371 | continue; |
Andreas Dannenberg | d036a21 | 2020-01-07 13:15:54 +0530 | [diff] [blame] | 372 | |
Nishanth Menon | 4f4c9d8 | 2023-11-04 02:21:41 -0500 | [diff] [blame] | 373 | /* |
| 374 | * Make sure we are not running out of buffer space by checking |
| 375 | * if we can fit the new overlay, a trailing space to be used |
| 376 | * as a separator, plus the terminating zero. |
| 377 | */ |
| 378 | if (strlen(name_overlays) + strlen(ext_cards[i].dtbo_name) + 2 > |
| 379 | sizeof(name_overlays)) |
| 380 | return -ENOMEM; |
Andreas Dannenberg | d036a21 | 2020-01-07 13:15:54 +0530 | [diff] [blame] | 381 | |
Nishanth Menon | 4f4c9d8 | 2023-11-04 02:21:41 -0500 | [diff] [blame] | 382 | /* Append to our list of overlays */ |
| 383 | strcat(name_overlays, ext_cards[i].dtbo_name); |
| 384 | strcat(name_overlays, " "); |
| 385 | } |
| 386 | |
| 387 | /* Apply device tree overlay(s) to the U-Boot environment, if any */ |
| 388 | if (strlen(name_overlays)) |
| 389 | return env_set("name_overlays", name_overlays); |
| 390 | } |
Andreas Dannenberg | d036a21 | 2020-01-07 13:15:54 +0530 | [diff] [blame] | 391 | |
| 392 | return 0; |
| 393 | } |
Lokesh Vutla | 5a08e65 | 2020-08-05 22:44:14 +0530 | [diff] [blame] | 394 | #endif |
Andreas Dannenberg | d036a21 | 2020-01-07 13:15:54 +0530 | [diff] [blame] | 395 | |
Sinthu Raja | e861aa9 | 2022-02-09 15:06:48 +0530 | [diff] [blame] | 396 | #ifdef CONFIG_BOARD_LATE_INIT |
Nishanth Menon | 3c0f831 | 2024-02-12 13:47:22 -0600 | [diff] [blame] | 397 | static struct ti_fdt_map ti_j721e_evm_fdt_map[] = { |
| 398 | {"j721e", "k3-j721e-common-proc-board.dtb"}, |
| 399 | {"j721e-sk", "k3-j721e-sk.dtb"}, |
| 400 | {"j7200", "k3-j7200-common-proc-board.dtb"}, |
| 401 | { /* Sentinel. */ } |
| 402 | }; |
Sinthu Raja | e861aa9 | 2022-02-09 15:06:48 +0530 | [diff] [blame] | 403 | static void setup_board_eeprom_env(void) |
| 404 | { |
| 405 | char *name = "j721e"; |
| 406 | |
| 407 | if (do_board_detect()) |
| 408 | goto invalid_eeprom; |
| 409 | |
| 410 | if (board_is_j721e_som()) |
| 411 | name = "j721e"; |
Sinthu Raja | 1c24ab4 | 2022-02-09 15:06:50 +0530 | [diff] [blame] | 412 | else if (board_is_j721e_sk()) |
| 413 | name = "j721e-sk"; |
Sinthu Raja | e861aa9 | 2022-02-09 15:06:48 +0530 | [diff] [blame] | 414 | else if (board_is_j7200_som()) |
| 415 | name = "j7200"; |
| 416 | else |
| 417 | printf("Unidentified board claims %s in eeprom header\n", |
| 418 | board_ti_get_name()); |
| 419 | |
| 420 | invalid_eeprom: |
| 421 | set_board_info_env_am6(name); |
Nishanth Menon | 3c0f831 | 2024-02-12 13:47:22 -0600 | [diff] [blame] | 422 | ti_set_fdt_env(name, ti_j721e_evm_fdt_map); |
Sinthu Raja | e861aa9 | 2022-02-09 15:06:48 +0530 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | static void setup_serial(void) |
| 426 | { |
| 427 | struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA; |
| 428 | unsigned long board_serial; |
| 429 | char *endp; |
| 430 | char serial_string[17] = { 0 }; |
| 431 | |
| 432 | if (env_get("serial#")) |
| 433 | return; |
| 434 | |
| 435 | board_serial = hextoul(ep->serial, &endp); |
| 436 | if (*endp != '\0') { |
| 437 | pr_err("Error: Can't set serial# to %s\n", ep->serial); |
| 438 | return; |
| 439 | } |
| 440 | |
| 441 | snprintf(serial_string, sizeof(serial_string), "%016lx", board_serial); |
| 442 | env_set("serial#", serial_string); |
| 443 | } |
| 444 | |
Andreas Dannenberg | d036a21 | 2020-01-07 13:15:54 +0530 | [diff] [blame] | 445 | int board_late_init(void) |
| 446 | { |
Lokesh Vutla | 5a08e65 | 2020-08-05 22:44:14 +0530 | [diff] [blame] | 447 | if (IS_ENABLED(CONFIG_TI_I2C_BOARD_DETECT)) { |
| 448 | setup_board_eeprom_env(); |
| 449 | setup_serial(); |
Andreas Dannenberg | d036a21 | 2020-01-07 13:15:54 +0530 | [diff] [blame] | 450 | |
Lokesh Vutla | 5a08e65 | 2020-08-05 22:44:14 +0530 | [diff] [blame] | 451 | /* Check for and probe any plugged-in daughtercards */ |
Sinthu Raja | 9a4fa30 | 2022-02-09 15:06:51 +0530 | [diff] [blame] | 452 | if (board_is_j721e_som() || board_is_j7200_som()) |
| 453 | probe_daughtercards(); |
Lokesh Vutla | 5a08e65 | 2020-08-05 22:44:14 +0530 | [diff] [blame] | 454 | } |
Andreas Dannenberg | d036a21 | 2020-01-07 13:15:54 +0530 | [diff] [blame] | 455 | |
| 456 | return 0; |
| 457 | } |
Sinthu Raja | e861aa9 | 2022-02-09 15:06:48 +0530 | [diff] [blame] | 458 | #endif |
Andreas Dannenberg | d036a21 | 2020-01-07 13:15:54 +0530 | [diff] [blame] | 459 | |
Vaishnav Achath | b8b1744 | 2022-05-09 11:50:16 +0530 | [diff] [blame] | 460 | static int __maybe_unused detect_SW3_1_state(void) |
| 461 | { |
| 462 | if (IS_ENABLED(CONFIG_TARGET_J7200_A72_EVM) || IS_ENABLED(CONFIG_TARGET_J721E_A72_EVM)) { |
| 463 | struct gpio_desc desc = {0}; |
| 464 | int ret; |
| 465 | char *hypermux_sel_gpio = (board_is_j721e_som()) ? "8" : "6"; |
| 466 | |
| 467 | ret = dm_gpio_lookup_name(hypermux_sel_gpio, &desc); |
| 468 | if (ret) { |
| 469 | printf("error getting GPIO lookup name: %d\n", ret); |
| 470 | return ret; |
| 471 | } |
| 472 | |
| 473 | ret = dm_gpio_request(&desc, hypermux_sel_gpio); |
| 474 | if (ret) { |
| 475 | printf("error requesting GPIO: %d\n", ret); |
| 476 | goto err_free_gpio; |
| 477 | } |
| 478 | |
| 479 | ret = dm_gpio_set_dir_flags(&desc, GPIOD_IS_IN); |
| 480 | if (ret) { |
| 481 | printf("error setting direction flag of GPIO: %d\n", ret); |
| 482 | goto err_free_gpio; |
| 483 | } |
| 484 | |
| 485 | ret = dm_gpio_get_value(&desc); |
| 486 | if (ret < 0) |
| 487 | printf("error getting value of GPIO: %d\n", ret); |
| 488 | |
| 489 | err_free_gpio: |
| 490 | dm_gpio_free(desc.dev, &desc); |
| 491 | return ret; |
| 492 | } |
| 493 | } |
| 494 | |
Andreas Dannenberg | d036a21 | 2020-01-07 13:15:54 +0530 | [diff] [blame] | 495 | void spl_board_init(void) |
| 496 | { |
Tero Kristo | 1a2c7ba | 2020-02-14 11:18:19 +0200 | [diff] [blame] | 497 | struct udevice *dev; |
| 498 | int ret; |
Tero Kristo | 1a2c7ba | 2020-02-14 11:18:19 +0200 | [diff] [blame] | 499 | |
Lokesh Vutla | 046ad43 | 2020-08-05 22:44:24 +0530 | [diff] [blame] | 500 | if ((IS_ENABLED(CONFIG_TARGET_J721E_A72_EVM) || |
| 501 | IS_ENABLED(CONFIG_TARGET_J7200_A72_EVM)) && |
Sinthu Raja | 9a4fa30 | 2022-02-09 15:06:51 +0530 | [diff] [blame] | 502 | IS_ENABLED(CONFIG_TI_I2C_BOARD_DETECT)) { |
| 503 | if (!board_is_j721e_sk()) |
| 504 | probe_daughtercards(); |
| 505 | } |
Tero Kristo | 1a2c7ba | 2020-02-14 11:18:19 +0200 | [diff] [blame] | 506 | |
Nishanth Menon | 591443e | 2023-11-04 02:21:40 -0500 | [diff] [blame] | 507 | if (IS_ENABLED(CONFIG_ESM_K3)) { |
Udit Kumar | 43e842a | 2024-04-17 10:06:50 +0530 | [diff] [blame] | 508 | ret = uclass_get_device_by_name(UCLASS_MISC, "esm@700000", &dev); |
| 509 | if (ret) |
| 510 | printf("MISC init for esm@700000 failed: %d\n", ret); |
| 511 | |
| 512 | ret = uclass_get_device_by_name(UCLASS_MISC, "esm@40800000", &dev); |
Tero Kristo | 1a2c7ba | 2020-02-14 11:18:19 +0200 | [diff] [blame] | 513 | if (ret) |
Udit Kumar | 43e842a | 2024-04-17 10:06:50 +0530 | [diff] [blame] | 514 | printf("MISC init for esm@40800000 failed: %d\n", ret); |
Tero Kristo | 1a2c7ba | 2020-02-14 11:18:19 +0200 | [diff] [blame] | 515 | } |
Tero Kristo | 1a2c7ba | 2020-02-14 11:18:19 +0200 | [diff] [blame] | 516 | |
Nishanth Menon | 591443e | 2023-11-04 02:21:40 -0500 | [diff] [blame] | 517 | if (IS_ENABLED(CONFIG_ESM_PMIC)) { |
Tero Kristo | 1a2c7ba | 2020-02-14 11:18:19 +0200 | [diff] [blame] | 518 | ret = uclass_get_device_by_driver(UCLASS_MISC, |
Simon Glass | 65130cd | 2020-12-28 20:34:56 -0700 | [diff] [blame] | 519 | DM_DRIVER_GET(pmic_esm), |
Tero Kristo | 1a2c7ba | 2020-02-14 11:18:19 +0200 | [diff] [blame] | 520 | &dev); |
| 521 | if (ret) |
| 522 | printf("ESM PMIC init failed: %d\n", ret); |
| 523 | } |
Vaishnav Achath | b8b1744 | 2022-05-09 11:50:16 +0530 | [diff] [blame] | 524 | if ((IS_ENABLED(CONFIG_TARGET_J7200_A72_EVM) || IS_ENABLED(CONFIG_TARGET_J721E_A72_EVM)) && |
| 525 | IS_ENABLED(CONFIG_HBMC_AM654)) { |
| 526 | struct udevice *dev; |
| 527 | int ret; |
| 528 | |
| 529 | ret = detect_SW3_1_state(); |
| 530 | if (ret == 1) { |
| 531 | ret = uclass_get_device_by_driver(UCLASS_MTD, |
| 532 | DM_DRIVER_GET(hbmc_am654), |
| 533 | &dev); |
| 534 | if (ret) |
| 535 | debug("Failed to probe hyperflash\n"); |
| 536 | } |
| 537 | } |
Andreas Dannenberg | d036a21 | 2020-01-07 13:15:54 +0530 | [diff] [blame] | 538 | } |