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>
11 #include <fdt_support.h>
15 #include <asm/arch/sys_proto.h>
16 #include <asm/arch/hardware.h>
20 #include <asm/arch/sys_proto.h>
22 #include <dm/uclass-internal.h>
24 #include "../common/board_detect.h"
26 #define board_is_j721e_som() (board_ti_k3_is("J721EX-PM1-SOM") || \
27 board_ti_k3_is("J721EX-PM2-SOM"))
29 /* Max number of MAC addresses that are parsed/processed per daughter card */
30 #define DAUGHTER_CARD_NO_OF_MAC_ADDR 8
32 DECLARE_GLOBAL_DATA_PTR;
41 #ifdef CONFIG_PHYS_64BIT
42 gd->ram_size = 0x100000000;
44 gd->ram_size = 0x80000000;
50 ulong board_get_usable_ram_top(ulong total_size)
52 #ifdef CONFIG_PHYS_64BIT
53 /* Limit RAM used by U-Boot to the DDR low region */
54 if (gd->ram_top > 0x100000000)
61 int dram_init_banksize(void)
63 /* Bank 0 declares the memory available in the DDR low region */
64 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
65 gd->bd->bi_dram[0].size = 0x80000000;
66 gd->ram_size = 0x80000000;
68 #ifdef CONFIG_PHYS_64BIT
69 /* Bank 1 declares the memory available in the DDR high region */
70 gd->bd->bi_dram[1].start = CONFIG_SYS_SDRAM_BASE1;
71 gd->bd->bi_dram[1].size = 0x80000000;
72 gd->ram_size = 0x100000000;
78 #ifdef CONFIG_SPL_LOAD_FIT
79 int board_fit_config_name_match(const char *name)
81 if (!strcmp(name, "k3-j721e-common-proc-board"))
88 #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
89 int ft_board_setup(void *blob, bd_t *bd)
93 ret = fdt_fixup_msmc_ram(blob, "/interconnect@100000", "sram@70000000");
95 printf("%s: fixing up msmc ram failed %d\n", __func__, ret);
101 int do_board_detect(void)
105 ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS,
106 CONFIG_EEPROM_CHIP_ADDRESS);
108 pr_err("Reading on-board EEPROM at 0x%02x failed %d\n",
109 CONFIG_EEPROM_CHIP_ADDRESS, ret);
116 struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
118 if (do_board_detect())
119 /* EEPROM not populated */
120 printf("Board: %s rev %s\n", "J721EX-PM1-SOM", "E2");
122 printf("Board: %s rev %s\n", ep->name, ep->version);
127 static void setup_board_eeprom_env(void)
129 char *name = "j721e";
131 if (do_board_detect())
134 if (board_is_j721e_som())
137 printf("Unidentified board claims %s in eeprom header\n",
138 board_ti_get_name());
141 set_board_info_env_am6(name);
144 static void setup_serial(void)
146 struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
147 unsigned long board_serial;
149 char serial_string[17] = { 0 };
151 if (env_get("serial#"))
154 board_serial = simple_strtoul(ep->serial, &endp, 16);
156 pr_err("Error: Can't set serial# to %s\n", ep->serial);
160 snprintf(serial_string, sizeof(serial_string), "%016lx", board_serial);
161 env_set("serial#", serial_string);
165 * Declaration of daughtercards to probe. Note that when adding more
166 * cards they should be grouped by the 'i2c_addr' field to allow for a
167 * more efficient probing process.
169 static const struct {
170 u8 i2c_addr; /* I2C address of card EEPROM */
171 char *card_name; /* EEPROM-programmed card name */
172 char *dtbo_name; /* Device tree overlay to apply */
173 u8 eth_offset; /* ethXaddr MAC address index offset */
178 "", /* No dtbo for this board */
184 "", /* No dtbo for this board */
190 "", /* No dtbo for this board */
191 5, /* Start populating from eth5addr */
196 "", /* No dtbo for this board */
197 1, /* Start populating from eth1addr */
201 static bool daughter_card_detect_flags[ARRAY_SIZE(ext_cards)];
203 const char *board_fit_get_additionnal_images(int index, const char *type)
207 if (strcmp(type, FIT_FDT_PROP))
211 for (i = 0; i < ARRAY_SIZE(ext_cards); i++) {
212 if (daughter_card_detect_flags[i]) {
215 * Return dtbo name only if populated,
216 * otherwise stop parsing here.
218 if (strlen(ext_cards[i].dtbo_name))
219 return ext_cards[i].dtbo_name;
231 static int probe_daughtercards(void)
233 char mac_addr[DAUGHTER_CARD_NO_OF_MAC_ADDR][TI_EEPROM_HDR_ETH_ALEN];
234 bool eeprom_read_success;
235 struct ti_am6_eeprom ep;
236 u8 previous_i2c_addr;
241 /* Mark previous I2C address variable as not populated */
242 previous_i2c_addr = 0xff;
244 /* No EEPROM data was read yet */
245 eeprom_read_success = false;
247 /* Iterate through list of daughtercards */
248 for (i = 0; i < ARRAY_SIZE(ext_cards); i++) {
249 /* Obtain card-specific I2C address */
250 u8 i2c_addr = ext_cards[i].i2c_addr;
252 /* Read card EEPROM if not already read previously */
253 if (i2c_addr != previous_i2c_addr) {
254 /* Store I2C address so we can avoid reading twice */
255 previous_i2c_addr = i2c_addr;
257 /* Get and parse the daughter card EEPROM record */
258 ret = ti_i2c_eeprom_am6_get(CONFIG_EEPROM_BUS_ADDRESS,
262 DAUGHTER_CARD_NO_OF_MAC_ADDR,
265 debug("%s: No daughtercard EEPROM at 0x%02x found %d\n",
266 __func__, i2c_addr, ret);
267 eeprom_read_success = false;
268 /* Skip to the next daughtercard to probe */
272 /* EEPROM read successful, okay to further process. */
273 eeprom_read_success = true;
276 /* Only continue processing if EEPROM data was read */
277 if (!eeprom_read_success)
280 /* Only process the parsed data if we found a match */
281 if (strncmp(ep.name, ext_cards[i].card_name, sizeof(ep.name)))
284 printf("Detected: %s rev %s\n", ep.name, ep.version);
285 daughter_card_detect_flags[i] = true;
287 #ifndef CONFIG_SPL_BUILD
290 * Populate any MAC addresses from daughtercard into the U-Boot
291 * environment, starting with a card-specific offset so we can
292 * have multiple ext_cards contribute to the MAC pool in a well-
295 for (j = 0; j < mac_addr_cnt; j++) {
296 if (!is_valid_ethaddr((u8 *)mac_addr[j]))
299 eth_env_set_enetaddr_by_index("eth",
300 ext_cards[i].eth_offset + j,
301 (uchar *)mac_addr[j]);
305 #ifndef CONFIG_SPL_BUILD
306 char name_overlays[1024] = { 0 };
308 for (i = 0; i < ARRAY_SIZE(ext_cards); i++) {
309 if (!daughter_card_detect_flags[i])
312 /* Skip if no overlays are to be added */
313 if (!strlen(ext_cards[i].dtbo_name))
317 * Make sure we are not running out of buffer space by checking
318 * if we can fit the new overlay, a trailing space to be used
319 * as a separator, plus the terminating zero.
321 if (strlen(name_overlays) + strlen(ext_cards[i].dtbo_name) + 2 >
322 sizeof(name_overlays))
325 /* Append to our list of overlays */
326 strcat(name_overlays, ext_cards[i].dtbo_name);
327 strcat(name_overlays, " ");
330 /* Apply device tree overlay(s) to the U-Boot environment, if any */
331 if (strlen(name_overlays))
332 return env_set("name_overlays", name_overlays);
338 int board_late_init(void)
340 setup_board_eeprom_env();
343 /* Check for and probe any plugged-in daughtercards */
344 probe_daughtercards();
349 void spl_board_init(void)
351 #if defined(CONFIG_ESM_K3) || defined(CONFIG_ESM_PMIC)
356 probe_daughtercards();
359 if (board_ti_k3_is("J721EX-PM2-SOM")) {
360 ret = uclass_get_device_by_driver(UCLASS_MISC,
361 DM_GET_DRIVER(k3_esm), &dev);
363 printf("ESM init failed: %d\n", ret);
367 #ifdef CONFIG_ESM_PMIC
368 if (board_ti_k3_is("J721EX-PM2-SOM")) {
369 ret = uclass_get_device_by_driver(UCLASS_MISC,
370 DM_GET_DRIVER(pmic_esm),
373 printf("ESM PMIC init failed: %d\n", ret);