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