1 // SPDX-License-Identifier: GPL-2.0+
3 * Board specific initialization for J721E EVM
5 * Copyright (C) 2018-2019 Texas Instruments Incorporated - http://www.ti.com/
12 #include <fdt_support.h>
16 #include <asm/arch/sys_proto.h>
17 #include <asm/arch/hardware.h>
21 #include <asm/arch/sys_proto.h>
23 #include <dm/uclass-internal.h>
25 #include "../common/board_detect.h"
27 #define board_is_j721e_som() (board_ti_k3_is("J721EX-PM1-SOM") || \
28 board_ti_k3_is("J721EX-PM2-SOM"))
30 /* Max number of MAC addresses that are parsed/processed per daughter card */
31 #define DAUGHTER_CARD_NO_OF_MAC_ADDR 8
33 DECLARE_GLOBAL_DATA_PTR;
42 #ifdef CONFIG_PHYS_64BIT
43 gd->ram_size = 0x100000000;
45 gd->ram_size = 0x80000000;
51 ulong board_get_usable_ram_top(ulong total_size)
53 #ifdef CONFIG_PHYS_64BIT
54 /* Limit RAM used by U-Boot to the DDR low region */
55 if (gd->ram_top > 0x100000000)
62 int dram_init_banksize(void)
64 /* Bank 0 declares the memory available in the DDR low region */
65 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
66 gd->bd->bi_dram[0].size = 0x80000000;
67 gd->ram_size = 0x80000000;
69 #ifdef CONFIG_PHYS_64BIT
70 /* Bank 1 declares the memory available in the DDR high region */
71 gd->bd->bi_dram[1].start = CONFIG_SYS_SDRAM_BASE1;
72 gd->bd->bi_dram[1].size = 0x80000000;
73 gd->ram_size = 0x100000000;
79 #ifdef CONFIG_SPL_LOAD_FIT
80 int board_fit_config_name_match(const char *name)
82 if (!strcmp(name, "k3-j721e-common-proc-board"))
89 #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
90 int ft_board_setup(void *blob, bd_t *bd)
94 ret = fdt_fixup_msmc_ram(blob, "/interconnect@100000", "sram@70000000");
96 printf("%s: fixing up msmc ram failed %d\n", __func__, ret);
102 int do_board_detect(void)
106 ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS,
107 CONFIG_EEPROM_CHIP_ADDRESS);
109 pr_err("Reading on-board EEPROM at 0x%02x failed %d\n",
110 CONFIG_EEPROM_CHIP_ADDRESS, ret);
117 struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
119 if (do_board_detect())
120 /* EEPROM not populated */
121 printf("Board: %s rev %s\n", "J721EX-PM1-SOM", "E2");
123 printf("Board: %s rev %s\n", ep->name, ep->version);
128 static void setup_board_eeprom_env(void)
130 char *name = "j721e";
132 if (do_board_detect())
135 if (board_is_j721e_som())
138 printf("Unidentified board claims %s in eeprom header\n",
139 board_ti_get_name());
142 set_board_info_env_am6(name);
145 static void setup_serial(void)
147 struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
148 unsigned long board_serial;
150 char serial_string[17] = { 0 };
152 if (env_get("serial#"))
155 board_serial = simple_strtoul(ep->serial, &endp, 16);
157 pr_err("Error: Can't set serial# to %s\n", ep->serial);
161 snprintf(serial_string, sizeof(serial_string), "%016lx", board_serial);
162 env_set("serial#", serial_string);
166 * Declaration of daughtercards to probe. Note that when adding more
167 * cards they should be grouped by the 'i2c_addr' field to allow for a
168 * more efficient probing process.
170 static const struct {
171 u8 i2c_addr; /* I2C address of card EEPROM */
172 char *card_name; /* EEPROM-programmed card name */
173 char *dtbo_name; /* Device tree overlay to apply */
174 u8 eth_offset; /* ethXaddr MAC address index offset */
179 "", /* No dtbo for this board */
185 "", /* No dtbo for this board */
191 "", /* No dtbo for this board */
192 5, /* Start populating from eth5addr */
197 "", /* No dtbo for this board */
198 1, /* Start populating from eth1addr */
202 static bool daughter_card_detect_flags[ARRAY_SIZE(ext_cards)];
204 const char *board_fit_get_additionnal_images(int index, const char *type)
208 if (strcmp(type, FIT_FDT_PROP))
212 for (i = 0; i < ARRAY_SIZE(ext_cards); i++) {
213 if (daughter_card_detect_flags[i]) {
216 * Return dtbo name only if populated,
217 * otherwise stop parsing here.
219 if (strlen(ext_cards[i].dtbo_name))
220 return ext_cards[i].dtbo_name;
232 static int probe_daughtercards(void)
234 char mac_addr[DAUGHTER_CARD_NO_OF_MAC_ADDR][TI_EEPROM_HDR_ETH_ALEN];
235 bool eeprom_read_success;
236 struct ti_am6_eeprom ep;
237 u8 previous_i2c_addr;
242 /* Mark previous I2C address variable as not populated */
243 previous_i2c_addr = 0xff;
245 /* No EEPROM data was read yet */
246 eeprom_read_success = false;
248 /* Iterate through list of daughtercards */
249 for (i = 0; i < ARRAY_SIZE(ext_cards); i++) {
250 /* Obtain card-specific I2C address */
251 u8 i2c_addr = ext_cards[i].i2c_addr;
253 /* Read card EEPROM if not already read previously */
254 if (i2c_addr != previous_i2c_addr) {
255 /* Store I2C address so we can avoid reading twice */
256 previous_i2c_addr = i2c_addr;
258 /* Get and parse the daughter card EEPROM record */
259 ret = ti_i2c_eeprom_am6_get(CONFIG_EEPROM_BUS_ADDRESS,
263 DAUGHTER_CARD_NO_OF_MAC_ADDR,
266 debug("%s: No daughtercard EEPROM at 0x%02x found %d\n",
267 __func__, i2c_addr, ret);
268 eeprom_read_success = false;
269 /* Skip to the next daughtercard to probe */
273 /* EEPROM read successful, okay to further process. */
274 eeprom_read_success = true;
277 /* Only continue processing if EEPROM data was read */
278 if (!eeprom_read_success)
281 /* Only process the parsed data if we found a match */
282 if (strncmp(ep.name, ext_cards[i].card_name, sizeof(ep.name)))
285 printf("Detected: %s rev %s\n", ep.name, ep.version);
286 daughter_card_detect_flags[i] = true;
288 #ifndef CONFIG_SPL_BUILD
291 * Populate any MAC addresses from daughtercard into the U-Boot
292 * environment, starting with a card-specific offset so we can
293 * have multiple ext_cards contribute to the MAC pool in a well-
296 for (j = 0; j < mac_addr_cnt; j++) {
297 if (!is_valid_ethaddr((u8 *)mac_addr[j]))
300 eth_env_set_enetaddr_by_index("eth",
301 ext_cards[i].eth_offset + j,
302 (uchar *)mac_addr[j]);
306 #ifndef CONFIG_SPL_BUILD
307 char name_overlays[1024] = { 0 };
309 for (i = 0; i < ARRAY_SIZE(ext_cards); i++) {
310 if (!daughter_card_detect_flags[i])
313 /* Skip if no overlays are to be added */
314 if (!strlen(ext_cards[i].dtbo_name))
318 * Make sure we are not running out of buffer space by checking
319 * if we can fit the new overlay, a trailing space to be used
320 * as a separator, plus the terminating zero.
322 if (strlen(name_overlays) + strlen(ext_cards[i].dtbo_name) + 2 >
323 sizeof(name_overlays))
326 /* Append to our list of overlays */
327 strcat(name_overlays, ext_cards[i].dtbo_name);
328 strcat(name_overlays, " ");
331 /* Apply device tree overlay(s) to the U-Boot environment, if any */
332 if (strlen(name_overlays))
333 return env_set("name_overlays", name_overlays);
339 int board_late_init(void)
341 setup_board_eeprom_env();
344 /* Check for and probe any plugged-in daughtercards */
345 probe_daughtercards();
350 void spl_board_init(void)
352 #if defined(CONFIG_ESM_K3) || defined(CONFIG_ESM_PMIC)
357 probe_daughtercards();
360 if (board_ti_k3_is("J721EX-PM2-SOM")) {
361 ret = uclass_get_device_by_driver(UCLASS_MISC,
362 DM_GET_DRIVER(k3_esm), &dev);
364 printf("ESM init failed: %d\n", ret);
368 #ifdef CONFIG_ESM_PMIC
369 if (board_ti_k3_is("J721EX-PM2-SOM")) {
370 ret = uclass_get_device_by_driver(UCLASS_MISC,
371 DM_GET_DRIVER(pmic_esm),
374 printf("ESM PMIC init failed: %d\n", ret);