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>
13 #include <asm/arch/sys_proto.h>
14 #include <asm/arch/hardware.h>
18 #include <asm/arch/sys_proto.h>
20 #include <dm/uclass-internal.h>
22 #include "../common/board_detect.h"
24 #define board_is_j721e_som() (board_ti_k3_is("J721EX-PM1-SOM") || \
25 board_ti_k3_is("J721EX-PM2-SOM"))
27 /* Max number of MAC addresses that are parsed/processed per daughter card */
28 #define DAUGHTER_CARD_NO_OF_MAC_ADDR 8
30 DECLARE_GLOBAL_DATA_PTR;
39 #ifdef CONFIG_PHYS_64BIT
40 gd->ram_size = 0x100000000;
42 gd->ram_size = 0x80000000;
48 ulong board_get_usable_ram_top(ulong total_size)
50 #ifdef CONFIG_PHYS_64BIT
51 /* Limit RAM used by U-Boot to the DDR low region */
52 if (gd->ram_top > 0x100000000)
59 int dram_init_banksize(void)
61 /* Bank 0 declares the memory available in the DDR low region */
62 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
63 gd->bd->bi_dram[0].size = 0x80000000;
64 gd->ram_size = 0x80000000;
66 #ifdef CONFIG_PHYS_64BIT
67 /* Bank 1 declares the memory available in the DDR high region */
68 gd->bd->bi_dram[1].start = CONFIG_SYS_SDRAM_BASE1;
69 gd->bd->bi_dram[1].size = 0x80000000;
70 gd->ram_size = 0x100000000;
76 #ifdef CONFIG_SPL_LOAD_FIT
77 int board_fit_config_name_match(const char *name)
79 if (!strcmp(name, "k3-j721e-common-proc-board"))
86 #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
87 int ft_board_setup(void *blob, bd_t *bd)
91 ret = fdt_fixup_msmc_ram(blob, "/interconnect@100000", "sram@70000000");
93 printf("%s: fixing up msmc ram failed %d\n", __func__, ret);
99 int do_board_detect(void)
103 ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS,
104 CONFIG_EEPROM_CHIP_ADDRESS);
106 pr_err("Reading on-board EEPROM at 0x%02x failed %d\n",
107 CONFIG_EEPROM_CHIP_ADDRESS, ret);
114 struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
116 if (do_board_detect())
117 /* EEPROM not populated */
118 printf("Board: %s rev %s\n", "J721EX-PM1-SOM", "E2");
120 printf("Board: %s rev %s\n", ep->name, ep->version);
125 static void setup_board_eeprom_env(void)
127 char *name = "j721e";
129 if (do_board_detect())
132 if (board_is_j721e_som())
135 printf("Unidentified board claims %s in eeprom header\n",
136 board_ti_get_name());
139 set_board_info_env_am6(name);
142 static void setup_serial(void)
144 struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
145 unsigned long board_serial;
147 char serial_string[17] = { 0 };
149 if (env_get("serial#"))
152 board_serial = simple_strtoul(ep->serial, &endp, 16);
154 pr_err("Error: Can't set serial# to %s\n", ep->serial);
158 snprintf(serial_string, sizeof(serial_string), "%016lx", board_serial);
159 env_set("serial#", serial_string);
163 * Declaration of daughtercards to probe. Note that when adding more
164 * cards they should be grouped by the 'i2c_addr' field to allow for a
165 * more efficient probing process.
167 static const struct {
168 u8 i2c_addr; /* I2C address of card EEPROM */
169 char *card_name; /* EEPROM-programmed card name */
170 char *dtbo_name; /* Device tree overlay to apply */
171 u8 eth_offset; /* ethXaddr MAC address index offset */
176 "", /* No dtbo for this board */
182 "", /* No dtbo for this board */
188 "", /* No dtbo for this board */
189 5, /* Start populating from eth5addr */
194 "", /* No dtbo for this board */
195 1, /* Start populating from eth1addr */
199 static bool daughter_card_detect_flags[ARRAY_SIZE(ext_cards)];
201 const char *board_fit_get_additionnal_images(int index, const char *type)
205 if (strcmp(type, FIT_FDT_PROP))
209 for (i = 0; i < ARRAY_SIZE(ext_cards); i++) {
210 if (daughter_card_detect_flags[i]) {
213 * Return dtbo name only if populated,
214 * otherwise stop parsing here.
216 if (strlen(ext_cards[i].dtbo_name))
217 return ext_cards[i].dtbo_name;
229 static int probe_daughtercards(void)
231 char mac_addr[DAUGHTER_CARD_NO_OF_MAC_ADDR][TI_EEPROM_HDR_ETH_ALEN];
232 bool eeprom_read_success;
233 struct ti_am6_eeprom ep;
234 u8 previous_i2c_addr;
239 /* Mark previous I2C address variable as not populated */
240 previous_i2c_addr = 0xff;
242 /* No EEPROM data was read yet */
243 eeprom_read_success = false;
245 /* Iterate through list of daughtercards */
246 for (i = 0; i < ARRAY_SIZE(ext_cards); i++) {
247 /* Obtain card-specific I2C address */
248 u8 i2c_addr = ext_cards[i].i2c_addr;
250 /* Read card EEPROM if not already read previously */
251 if (i2c_addr != previous_i2c_addr) {
252 /* Store I2C address so we can avoid reading twice */
253 previous_i2c_addr = i2c_addr;
255 /* Get and parse the daughter card EEPROM record */
256 ret = ti_i2c_eeprom_am6_get(CONFIG_EEPROM_BUS_ADDRESS,
260 DAUGHTER_CARD_NO_OF_MAC_ADDR,
263 debug("%s: No daughtercard EEPROM at 0x%02x found %d\n",
264 __func__, i2c_addr, ret);
265 eeprom_read_success = false;
266 /* Skip to the next daughtercard to probe */
270 /* EEPROM read successful, okay to further process. */
271 eeprom_read_success = true;
274 /* Only continue processing if EEPROM data was read */
275 if (!eeprom_read_success)
278 /* Only process the parsed data if we found a match */
279 if (strncmp(ep.name, ext_cards[i].card_name, sizeof(ep.name)))
282 printf("Detected: %s rev %s\n", ep.name, ep.version);
283 daughter_card_detect_flags[i] = true;
285 #ifndef CONFIG_SPL_BUILD
288 * Populate any MAC addresses from daughtercard into the U-Boot
289 * environment, starting with a card-specific offset so we can
290 * have multiple ext_cards contribute to the MAC pool in a well-
293 for (j = 0; j < mac_addr_cnt; j++) {
294 if (!is_valid_ethaddr((u8 *)mac_addr[j]))
297 eth_env_set_enetaddr_by_index("eth",
298 ext_cards[i].eth_offset + j,
299 (uchar *)mac_addr[j]);
303 #ifndef CONFIG_SPL_BUILD
304 char name_overlays[1024] = { 0 };
306 for (i = 0; i < ARRAY_SIZE(ext_cards); i++) {
307 if (!daughter_card_detect_flags[i])
310 /* Skip if no overlays are to be added */
311 if (!strlen(ext_cards[i].dtbo_name))
315 * Make sure we are not running out of buffer space by checking
316 * if we can fit the new overlay, a trailing space to be used
317 * as a separator, plus the terminating zero.
319 if (strlen(name_overlays) + strlen(ext_cards[i].dtbo_name) + 2 >
320 sizeof(name_overlays))
323 /* Append to our list of overlays */
324 strcat(name_overlays, ext_cards[i].dtbo_name);
325 strcat(name_overlays, " ");
328 /* Apply device tree overlay(s) to the U-Boot environment, if any */
329 if (strlen(name_overlays))
330 return env_set("name_overlays", name_overlays);
336 int board_late_init(void)
338 setup_board_eeprom_env();
341 /* Check for and probe any plugged-in daughtercards */
342 probe_daughtercards();
347 void spl_board_init(void)
349 #if defined(CONFIG_ESM_K3) || defined(CONFIG_ESM_PMIC)
354 probe_daughtercards();
357 if (board_ti_k3_is("J721EX-PM2-SOM")) {
358 ret = uclass_get_device_by_driver(UCLASS_MISC,
359 DM_GET_DRIVER(k3_esm), &dev);
361 printf("ESM init failed: %d\n", ret);
365 #ifdef CONFIG_ESM_PMIC
366 if (board_ti_k3_is("J721EX-PM2-SOM")) {
367 ret = uclass_get_device_by_driver(UCLASS_MISC,
368 DM_GET_DRIVER(pmic_esm),
371 printf("ESM PMIC init failed: %d\n", ret);