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