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/
6 * Lokesh Vutla <lokeshvutla@ti.com>
12 #include <asm/arch/sys_proto.h>
13 #include <asm/arch/hardware.h>
17 #include <asm/arch/sys_proto.h>
19 #include <dm/uclass-internal.h>
21 #include "../common/board_detect.h"
23 #define board_is_j721e_som() (board_ti_k3_is("J721EX-PM1-SOM") || \
24 board_ti_k3_is("J721EX-PM2-SOM"))
26 /* Max number of MAC addresses that are parsed/processed per daughter card */
27 #define DAUGHTER_CARD_NO_OF_MAC_ADDR 8
29 DECLARE_GLOBAL_DATA_PTR;
38 #ifdef CONFIG_PHYS_64BIT
39 gd->ram_size = 0x100000000;
41 gd->ram_size = 0x80000000;
47 ulong board_get_usable_ram_top(ulong total_size)
49 #ifdef CONFIG_PHYS_64BIT
50 /* Limit RAM used by U-Boot to the DDR low region */
51 if (gd->ram_top > 0x100000000)
58 int dram_init_banksize(void)
60 /* Bank 0 declares the memory available in the DDR low region */
61 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
62 gd->bd->bi_dram[0].size = 0x80000000;
63 gd->ram_size = 0x80000000;
65 #ifdef CONFIG_PHYS_64BIT
66 /* Bank 1 declares the memory available in the DDR high region */
67 gd->bd->bi_dram[1].start = CONFIG_SYS_SDRAM_BASE1;
68 gd->bd->bi_dram[1].size = 0x80000000;
69 gd->ram_size = 0x100000000;
75 #ifdef CONFIG_SPL_LOAD_FIT
76 int board_fit_config_name_match(const char *name)
78 if (!strcmp(name, "k3-j721e-common-proc-board"))
85 #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
86 int ft_board_setup(void *blob, bd_t *bd)
90 ret = fdt_fixup_msmc_ram(blob, "/interconnect@100000", "sram@70000000");
92 printf("%s: fixing up msmc ram failed %d\n", __func__, ret);
98 int do_board_detect(void)
102 ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS,
103 CONFIG_EEPROM_CHIP_ADDRESS);
105 pr_err("Reading on-board EEPROM at 0x%02x failed %d\n",
106 CONFIG_EEPROM_CHIP_ADDRESS, ret);
113 struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
115 if (do_board_detect())
116 /* EEPROM not populated */
117 printf("Board: %s rev %s\n", "J721EX-PM1-SOM", "E2");
119 printf("Board: %s rev %s\n", ep->name, ep->version);
124 static void setup_board_eeprom_env(void)
126 char *name = "j721e";
128 if (do_board_detect())
131 if (board_is_j721e_som())
134 printf("Unidentified board claims %s in eeprom header\n",
135 board_ti_get_name());
138 set_board_info_env_am6(name);
141 static void setup_serial(void)
143 struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
144 unsigned long board_serial;
146 char serial_string[17] = { 0 };
148 if (env_get("serial#"))
151 board_serial = simple_strtoul(ep->serial, &endp, 16);
153 pr_err("Error: Can't set serial# to %s\n", ep->serial);
157 snprintf(serial_string, sizeof(serial_string), "%016lx", board_serial);
158 env_set("serial#", serial_string);
162 * Declaration of daughtercards to probe. Note that when adding more
163 * cards they should be grouped by the 'i2c_addr' field to allow for a
164 * more efficient probing process.
166 static const struct {
167 u8 i2c_addr; /* I2C address of card EEPROM */
168 char *card_name; /* EEPROM-programmed card name */
169 char *dtbo_name; /* Device tree overlay to apply */
170 u8 eth_offset; /* ethXaddr MAC address index offset */
175 "", /* No dtbo for this board */
181 "", /* No dtbo for this board */
187 "", /* No dtbo for this board */
188 5, /* Start populating from eth5addr */
193 "", /* No dtbo for this board */
194 1, /* Start populating from eth1addr */
198 static bool daughter_card_detect_flags[ARRAY_SIZE(ext_cards)];
200 const char *board_fit_get_additionnal_images(int index, const char *type)
204 if (strcmp(type, FIT_FDT_PROP))
208 for (i = 0; i < ARRAY_SIZE(ext_cards); i++) {
209 if (daughter_card_detect_flags[i]) {
212 * Return dtbo name only if populated,
213 * otherwise stop parsing here.
215 if (strlen(ext_cards[i].dtbo_name))
216 return ext_cards[i].dtbo_name;
228 static int probe_daughtercards(void)
230 char mac_addr[DAUGHTER_CARD_NO_OF_MAC_ADDR][TI_EEPROM_HDR_ETH_ALEN];
231 bool eeprom_read_success;
232 struct ti_am6_eeprom ep;
233 u8 previous_i2c_addr;
238 /* Mark previous I2C address variable as not populated */
239 previous_i2c_addr = 0xff;
241 /* No EEPROM data was read yet */
242 eeprom_read_success = false;
244 /* Iterate through list of daughtercards */
245 for (i = 0; i < ARRAY_SIZE(ext_cards); i++) {
246 /* Obtain card-specific I2C address */
247 u8 i2c_addr = ext_cards[i].i2c_addr;
249 /* Read card EEPROM if not already read previously */
250 if (i2c_addr != previous_i2c_addr) {
251 /* Store I2C address so we can avoid reading twice */
252 previous_i2c_addr = i2c_addr;
254 /* Get and parse the daughter card EEPROM record */
255 ret = ti_i2c_eeprom_am6_get(CONFIG_EEPROM_BUS_ADDRESS,
259 DAUGHTER_CARD_NO_OF_MAC_ADDR,
262 debug("%s: No daughtercard EEPROM at 0x%02x found %d\n",
263 __func__, i2c_addr, ret);
264 eeprom_read_success = false;
265 /* Skip to the next daughtercard to probe */
269 /* EEPROM read successful, okay to further process. */
270 eeprom_read_success = true;
273 /* Only continue processing if EEPROM data was read */
274 if (!eeprom_read_success)
277 /* Only process the parsed data if we found a match */
278 if (strncmp(ep.name, ext_cards[i].card_name, sizeof(ep.name)))
281 printf("Detected: %s rev %s\n", ep.name, ep.version);
282 daughter_card_detect_flags[i] = true;
284 #ifndef CONFIG_SPL_BUILD
287 * Populate any MAC addresses from daughtercard into the U-Boot
288 * environment, starting with a card-specific offset so we can
289 * have multiple ext_cards contribute to the MAC pool in a well-
292 for (j = 0; j < mac_addr_cnt; j++) {
293 if (!is_valid_ethaddr((u8 *)mac_addr[j]))
296 eth_env_set_enetaddr_by_index("eth",
297 ext_cards[i].eth_offset + j,
298 (uchar *)mac_addr[j]);
302 #ifndef CONFIG_SPL_BUILD
303 char name_overlays[1024] = { 0 };
305 for (i = 0; i < ARRAY_SIZE(ext_cards); i++) {
306 if (!daughter_card_detect_flags[i])
309 /* Skip if no overlays are to be added */
310 if (!strlen(ext_cards[i].dtbo_name))
314 * Make sure we are not running out of buffer space by checking
315 * if we can fit the new overlay, a trailing space to be used
316 * as a separator, plus the terminating zero.
318 if (strlen(name_overlays) + strlen(ext_cards[i].dtbo_name) + 2 >
319 sizeof(name_overlays))
322 /* Append to our list of overlays */
323 strcat(name_overlays, ext_cards[i].dtbo_name);
324 strcat(name_overlays, " ");
327 /* Apply device tree overlay(s) to the U-Boot environment, if any */
328 if (strlen(name_overlays))
329 return env_set("name_overlays", name_overlays);
335 int board_late_init(void)
337 setup_board_eeprom_env();
340 /* Check for and probe any plugged-in daughtercards */
341 probe_daughtercards();
346 void spl_board_init(void)
348 #if defined(CONFIG_ESM_K3) || defined(CONFIG_ESM_PMIC)
353 probe_daughtercards();
356 if (board_ti_k3_is("J721EX-PM2-SOM")) {
357 ret = uclass_get_device_by_driver(UCLASS_MISC,
358 DM_GET_DRIVER(k3_esm), &dev);
360 printf("ESM init failed: %d\n", ret);
364 #ifdef CONFIG_ESM_PMIC
365 if (board_ti_k3_is("J721EX-PM2-SOM")) {
366 ret = uclass_get_device_by_driver(UCLASS_MISC,
367 DM_GET_DRIVER(pmic_esm),
370 printf("ESM PMIC init failed: %d\n", ret);