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