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