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> |
| 13 | #include <image.h> |
Simon Glass | 67c4e9f | 2019-11-14 12:57:45 -0700 | [diff] [blame] | 14 | #include <init.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 15 | #include <log.h> |
Simon Glass | 90526e9 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 16 | #include <net.h> |
Andreas Dannenberg | 643eb6e | 2020-01-07 13:15:54 +0530 | [diff] [blame] | 17 | #include <asm/arch/sys_proto.h> |
| 18 | #include <asm/arch/hardware.h> |
| 19 | #include <asm/gpio.h> |
Lokesh Vutla | f818503 | 2019-06-13 10:29:49 +0530 | [diff] [blame] | 20 | #include <asm/io.h> |
| 21 | #include <spl.h> |
Suman Anna | d146af5 | 2019-06-13 10:29:50 +0530 | [diff] [blame] | 22 | #include <asm/arch/sys_proto.h> |
Tero Kristo | fa281f6 | 2020-02-14 11:18:19 +0200 | [diff] [blame] | 23 | #include <dm.h> |
| 24 | #include <dm/uclass-internal.h> |
Lokesh Vutla | f818503 | 2019-06-13 10:29:49 +0530 | [diff] [blame] | 25 | |
Andreas Dannenberg | 643eb6e | 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 | |
| 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 | f818503 | 2019-06-13 10:29:49 +0530 | [diff] [blame] | 34 | DECLARE_GLOBAL_DATA_PTR; |
| 35 | |
| 36 | int board_init(void) |
| 37 | { |
| 38 | return 0; |
| 39 | } |
| 40 | |
| 41 | int dram_init(void) |
| 42 | { |
| 43 | #ifdef CONFIG_PHYS_64BIT |
| 44 | gd->ram_size = 0x100000000; |
| 45 | #else |
| 46 | gd->ram_size = 0x80000000; |
| 47 | #endif |
| 48 | |
| 49 | return 0; |
| 50 | } |
| 51 | |
| 52 | ulong board_get_usable_ram_top(ulong total_size) |
| 53 | { |
| 54 | #ifdef CONFIG_PHYS_64BIT |
| 55 | /* Limit RAM used by U-Boot to the DDR low region */ |
| 56 | if (gd->ram_top > 0x100000000) |
| 57 | return 0x100000000; |
| 58 | #endif |
| 59 | |
| 60 | return gd->ram_top; |
| 61 | } |
| 62 | |
| 63 | int dram_init_banksize(void) |
| 64 | { |
| 65 | /* Bank 0 declares the memory available in the DDR low region */ |
| 66 | gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE; |
| 67 | gd->bd->bi_dram[0].size = 0x80000000; |
| 68 | gd->ram_size = 0x80000000; |
| 69 | |
| 70 | #ifdef CONFIG_PHYS_64BIT |
| 71 | /* Bank 1 declares the memory available in the DDR high region */ |
| 72 | gd->bd->bi_dram[1].start = CONFIG_SYS_SDRAM_BASE1; |
| 73 | gd->bd->bi_dram[1].size = 0x80000000; |
| 74 | gd->ram_size = 0x100000000; |
| 75 | #endif |
| 76 | |
| 77 | return 0; |
| 78 | } |
| 79 | |
| 80 | #ifdef CONFIG_SPL_LOAD_FIT |
| 81 | int board_fit_config_name_match(const char *name) |
| 82 | { |
| 83 | if (!strcmp(name, "k3-j721e-common-proc-board")) |
| 84 | return 0; |
| 85 | |
| 86 | return -1; |
| 87 | } |
| 88 | #endif |
Suman Anna | d146af5 | 2019-06-13 10:29:50 +0530 | [diff] [blame] | 89 | |
| 90 | #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) |
Masahiro Yamada | b75d8dc | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 91 | int ft_board_setup(void *blob, struct bd_info *bd) |
Suman Anna | d146af5 | 2019-06-13 10:29:50 +0530 | [diff] [blame] | 92 | { |
| 93 | int ret; |
| 94 | |
Suman Anna | 0526460 | 2020-08-05 22:44:15 +0530 | [diff] [blame] | 95 | ret = fdt_fixup_msmc_ram(blob, "/bus@100000", "sram@70000000"); |
| 96 | if (ret < 0) |
| 97 | ret = fdt_fixup_msmc_ram(blob, "/interconnect@100000", |
| 98 | "sram@70000000"); |
Suman Anna | d146af5 | 2019-06-13 10:29:50 +0530 | [diff] [blame] | 99 | if (ret) |
| 100 | printf("%s: fixing up msmc ram failed %d\n", __func__, ret); |
| 101 | |
| 102 | return ret; |
| 103 | } |
| 104 | #endif |
Andreas Dannenberg | 643eb6e | 2020-01-07 13:15:54 +0530 | [diff] [blame] | 105 | |
Lokesh Vutla | b29a7cd | 2020-08-05 22:44:14 +0530 | [diff] [blame] | 106 | #ifdef CONFIG_TI_I2C_BOARD_DETECT |
Andreas Dannenberg | 643eb6e | 2020-01-07 13:15:54 +0530 | [diff] [blame] | 107 | int do_board_detect(void) |
| 108 | { |
| 109 | int ret; |
| 110 | |
| 111 | ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS, |
| 112 | CONFIG_EEPROM_CHIP_ADDRESS); |
| 113 | if (ret) |
| 114 | pr_err("Reading on-board EEPROM at 0x%02x failed %d\n", |
| 115 | CONFIG_EEPROM_CHIP_ADDRESS, ret); |
| 116 | |
| 117 | return ret; |
| 118 | } |
| 119 | |
Lokesh Vutla | c7068ab | 2020-01-07 13:15:55 +0530 | [diff] [blame] | 120 | int checkboard(void) |
| 121 | { |
| 122 | struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA; |
| 123 | |
| 124 | if (do_board_detect()) |
| 125 | /* EEPROM not populated */ |
| 126 | printf("Board: %s rev %s\n", "J721EX-PM1-SOM", "E2"); |
| 127 | else |
| 128 | printf("Board: %s rev %s\n", ep->name, ep->version); |
| 129 | |
| 130 | return 0; |
| 131 | } |
| 132 | |
Andreas Dannenberg | 643eb6e | 2020-01-07 13:15:54 +0530 | [diff] [blame] | 133 | static void setup_board_eeprom_env(void) |
| 134 | { |
| 135 | char *name = "j721e"; |
| 136 | |
| 137 | if (do_board_detect()) |
| 138 | goto invalid_eeprom; |
| 139 | |
| 140 | if (board_is_j721e_som()) |
| 141 | name = "j721e"; |
| 142 | else |
| 143 | printf("Unidentified board claims %s in eeprom header\n", |
| 144 | board_ti_get_name()); |
| 145 | |
| 146 | invalid_eeprom: |
| 147 | set_board_info_env_am6(name); |
| 148 | } |
| 149 | |
| 150 | static void setup_serial(void) |
| 151 | { |
| 152 | struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA; |
| 153 | unsigned long board_serial; |
| 154 | char *endp; |
| 155 | char serial_string[17] = { 0 }; |
| 156 | |
| 157 | if (env_get("serial#")) |
| 158 | return; |
| 159 | |
| 160 | board_serial = simple_strtoul(ep->serial, &endp, 16); |
| 161 | if (*endp != '\0') { |
| 162 | pr_err("Error: Can't set serial# to %s\n", ep->serial); |
| 163 | return; |
| 164 | } |
| 165 | |
| 166 | snprintf(serial_string, sizeof(serial_string), "%016lx", board_serial); |
| 167 | env_set("serial#", serial_string); |
| 168 | } |
| 169 | |
| 170 | /* |
| 171 | * Declaration of daughtercards to probe. Note that when adding more |
| 172 | * cards they should be grouped by the 'i2c_addr' field to allow for a |
| 173 | * more efficient probing process. |
| 174 | */ |
| 175 | static const struct { |
| 176 | u8 i2c_addr; /* I2C address of card EEPROM */ |
| 177 | char *card_name; /* EEPROM-programmed card name */ |
| 178 | char *dtbo_name; /* Device tree overlay to apply */ |
| 179 | u8 eth_offset; /* ethXaddr MAC address index offset */ |
| 180 | } ext_cards[] = { |
| 181 | { |
| 182 | 0x51, |
| 183 | "J7X-BASE-CPB", |
| 184 | "", /* No dtbo for this board */ |
| 185 | 0, |
| 186 | }, |
| 187 | { |
| 188 | 0x52, |
| 189 | "J7X-INFOTAN-EXP", |
| 190 | "", /* No dtbo for this board */ |
| 191 | 0, |
| 192 | }, |
| 193 | { |
| 194 | 0x52, |
| 195 | "J7X-GESI-EXP", |
| 196 | "", /* No dtbo for this board */ |
| 197 | 5, /* Start populating from eth5addr */ |
| 198 | }, |
| 199 | { |
| 200 | 0x54, |
| 201 | "J7X-VSC8514-ETH", |
| 202 | "", /* No dtbo for this board */ |
| 203 | 1, /* Start populating from eth1addr */ |
| 204 | }, |
| 205 | }; |
| 206 | |
| 207 | static bool daughter_card_detect_flags[ARRAY_SIZE(ext_cards)]; |
| 208 | |
| 209 | const char *board_fit_get_additionnal_images(int index, const char *type) |
| 210 | { |
| 211 | int i, j; |
| 212 | |
| 213 | if (strcmp(type, FIT_FDT_PROP)) |
| 214 | return NULL; |
| 215 | |
| 216 | j = 0; |
| 217 | for (i = 0; i < ARRAY_SIZE(ext_cards); i++) { |
| 218 | if (daughter_card_detect_flags[i]) { |
| 219 | if (j == index) { |
| 220 | /* |
| 221 | * Return dtbo name only if populated, |
| 222 | * otherwise stop parsing here. |
| 223 | */ |
| 224 | if (strlen(ext_cards[i].dtbo_name)) |
| 225 | return ext_cards[i].dtbo_name; |
| 226 | else |
| 227 | return NULL; |
| 228 | }; |
| 229 | |
| 230 | j++; |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | return NULL; |
| 235 | } |
| 236 | |
| 237 | static int probe_daughtercards(void) |
| 238 | { |
| 239 | char mac_addr[DAUGHTER_CARD_NO_OF_MAC_ADDR][TI_EEPROM_HDR_ETH_ALEN]; |
| 240 | bool eeprom_read_success; |
| 241 | struct ti_am6_eeprom ep; |
| 242 | u8 previous_i2c_addr; |
| 243 | u8 mac_addr_cnt; |
| 244 | int i; |
| 245 | int ret; |
| 246 | |
| 247 | /* Mark previous I2C address variable as not populated */ |
| 248 | previous_i2c_addr = 0xff; |
| 249 | |
| 250 | /* No EEPROM data was read yet */ |
| 251 | eeprom_read_success = false; |
| 252 | |
| 253 | /* Iterate through list of daughtercards */ |
| 254 | for (i = 0; i < ARRAY_SIZE(ext_cards); i++) { |
| 255 | /* Obtain card-specific I2C address */ |
| 256 | u8 i2c_addr = ext_cards[i].i2c_addr; |
| 257 | |
| 258 | /* Read card EEPROM if not already read previously */ |
| 259 | if (i2c_addr != previous_i2c_addr) { |
| 260 | /* Store I2C address so we can avoid reading twice */ |
| 261 | previous_i2c_addr = i2c_addr; |
| 262 | |
| 263 | /* Get and parse the daughter card EEPROM record */ |
| 264 | ret = ti_i2c_eeprom_am6_get(CONFIG_EEPROM_BUS_ADDRESS, |
| 265 | i2c_addr, |
| 266 | &ep, |
| 267 | (char **)mac_addr, |
| 268 | DAUGHTER_CARD_NO_OF_MAC_ADDR, |
| 269 | &mac_addr_cnt); |
| 270 | if (ret) { |
| 271 | debug("%s: No daughtercard EEPROM at 0x%02x found %d\n", |
| 272 | __func__, i2c_addr, ret); |
| 273 | eeprom_read_success = false; |
| 274 | /* Skip to the next daughtercard to probe */ |
| 275 | continue; |
| 276 | } |
| 277 | |
| 278 | /* EEPROM read successful, okay to further process. */ |
| 279 | eeprom_read_success = true; |
| 280 | } |
| 281 | |
| 282 | /* Only continue processing if EEPROM data was read */ |
| 283 | if (!eeprom_read_success) |
| 284 | continue; |
| 285 | |
| 286 | /* Only process the parsed data if we found a match */ |
| 287 | if (strncmp(ep.name, ext_cards[i].card_name, sizeof(ep.name))) |
| 288 | continue; |
| 289 | |
| 290 | printf("Detected: %s rev %s\n", ep.name, ep.version); |
| 291 | daughter_card_detect_flags[i] = true; |
| 292 | |
| 293 | #ifndef CONFIG_SPL_BUILD |
| 294 | int j; |
| 295 | /* |
| 296 | * Populate any MAC addresses from daughtercard into the U-Boot |
| 297 | * environment, starting with a card-specific offset so we can |
| 298 | * have multiple ext_cards contribute to the MAC pool in a well- |
| 299 | * defined manner. |
| 300 | */ |
| 301 | for (j = 0; j < mac_addr_cnt; j++) { |
| 302 | if (!is_valid_ethaddr((u8 *)mac_addr[j])) |
| 303 | continue; |
| 304 | |
| 305 | eth_env_set_enetaddr_by_index("eth", |
| 306 | ext_cards[i].eth_offset + j, |
| 307 | (uchar *)mac_addr[j]); |
| 308 | } |
| 309 | #endif |
| 310 | } |
| 311 | #ifndef CONFIG_SPL_BUILD |
| 312 | char name_overlays[1024] = { 0 }; |
| 313 | |
| 314 | for (i = 0; i < ARRAY_SIZE(ext_cards); i++) { |
| 315 | if (!daughter_card_detect_flags[i]) |
| 316 | continue; |
| 317 | |
| 318 | /* Skip if no overlays are to be added */ |
| 319 | if (!strlen(ext_cards[i].dtbo_name)) |
| 320 | continue; |
| 321 | |
| 322 | /* |
| 323 | * Make sure we are not running out of buffer space by checking |
| 324 | * if we can fit the new overlay, a trailing space to be used |
| 325 | * as a separator, plus the terminating zero. |
| 326 | */ |
| 327 | if (strlen(name_overlays) + strlen(ext_cards[i].dtbo_name) + 2 > |
| 328 | sizeof(name_overlays)) |
| 329 | return -ENOMEM; |
| 330 | |
| 331 | /* Append to our list of overlays */ |
| 332 | strcat(name_overlays, ext_cards[i].dtbo_name); |
| 333 | strcat(name_overlays, " "); |
| 334 | } |
| 335 | |
| 336 | /* Apply device tree overlay(s) to the U-Boot environment, if any */ |
| 337 | if (strlen(name_overlays)) |
| 338 | return env_set("name_overlays", name_overlays); |
| 339 | #endif |
| 340 | |
| 341 | return 0; |
| 342 | } |
Lokesh Vutla | b29a7cd | 2020-08-05 22:44:14 +0530 | [diff] [blame] | 343 | #endif |
Andreas Dannenberg | 643eb6e | 2020-01-07 13:15:54 +0530 | [diff] [blame] | 344 | |
| 345 | int board_late_init(void) |
| 346 | { |
Lokesh Vutla | b29a7cd | 2020-08-05 22:44:14 +0530 | [diff] [blame] | 347 | if (IS_ENABLED(CONFIG_TI_I2C_BOARD_DETECT)) { |
| 348 | setup_board_eeprom_env(); |
| 349 | setup_serial(); |
Andreas Dannenberg | 643eb6e | 2020-01-07 13:15:54 +0530 | [diff] [blame] | 350 | |
Lokesh Vutla | b29a7cd | 2020-08-05 22:44:14 +0530 | [diff] [blame] | 351 | /* Check for and probe any plugged-in daughtercards */ |
| 352 | probe_daughtercards(); |
| 353 | } |
Andreas Dannenberg | 643eb6e | 2020-01-07 13:15:54 +0530 | [diff] [blame] | 354 | |
| 355 | return 0; |
| 356 | } |
| 357 | |
| 358 | void spl_board_init(void) |
| 359 | { |
Tero Kristo | fa281f6 | 2020-02-14 11:18:19 +0200 | [diff] [blame] | 360 | #if defined(CONFIG_ESM_K3) || defined(CONFIG_ESM_PMIC) |
| 361 | struct udevice *dev; |
| 362 | int ret; |
| 363 | #endif |
| 364 | |
Lokesh Vutla | cf1d686 | 2020-08-05 22:44:24 +0530 | [diff] [blame^] | 365 | if ((IS_ENABLED(CONFIG_TARGET_J721E_A72_EVM) || |
| 366 | IS_ENABLED(CONFIG_TARGET_J7200_A72_EVM)) && |
Lokesh Vutla | b29a7cd | 2020-08-05 22:44:14 +0530 | [diff] [blame] | 367 | IS_ENABLED(CONFIG_TI_I2C_BOARD_DETECT)) |
| 368 | probe_daughtercards(); |
Tero Kristo | fa281f6 | 2020-02-14 11:18:19 +0200 | [diff] [blame] | 369 | |
| 370 | #ifdef CONFIG_ESM_K3 |
| 371 | if (board_ti_k3_is("J721EX-PM2-SOM")) { |
| 372 | ret = uclass_get_device_by_driver(UCLASS_MISC, |
| 373 | DM_GET_DRIVER(k3_esm), &dev); |
| 374 | if (ret) |
| 375 | printf("ESM init failed: %d\n", ret); |
| 376 | } |
| 377 | #endif |
| 378 | |
| 379 | #ifdef CONFIG_ESM_PMIC |
| 380 | if (board_ti_k3_is("J721EX-PM2-SOM")) { |
| 381 | ret = uclass_get_device_by_driver(UCLASS_MISC, |
| 382 | DM_GET_DRIVER(pmic_esm), |
| 383 | &dev); |
| 384 | if (ret) |
| 385 | printf("ESM PMIC init failed: %d\n", ret); |
| 386 | } |
| 387 | #endif |
Andreas Dannenberg | 643eb6e | 2020-01-07 13:15:54 +0530 | [diff] [blame] | 388 | } |