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 "../common/board_detect.h"
21 #define board_is_j721e_som() (board_ti_k3_is("J721EX-PM1-SOM") || \
22 board_ti_k3_is("J721EX-PM2-SOM"))
24 /* Max number of MAC addresses that are parsed/processed per daughter card */
25 #define DAUGHTER_CARD_NO_OF_MAC_ADDR 8
27 DECLARE_GLOBAL_DATA_PTR;
36 #ifdef CONFIG_PHYS_64BIT
37 gd->ram_size = 0x100000000;
39 gd->ram_size = 0x80000000;
45 ulong board_get_usable_ram_top(ulong total_size)
47 #ifdef CONFIG_PHYS_64BIT
48 /* Limit RAM used by U-Boot to the DDR low region */
49 if (gd->ram_top > 0x100000000)
56 int dram_init_banksize(void)
58 /* Bank 0 declares the memory available in the DDR low region */
59 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
60 gd->bd->bi_dram[0].size = 0x80000000;
61 gd->ram_size = 0x80000000;
63 #ifdef CONFIG_PHYS_64BIT
64 /* Bank 1 declares the memory available in the DDR high region */
65 gd->bd->bi_dram[1].start = CONFIG_SYS_SDRAM_BASE1;
66 gd->bd->bi_dram[1].size = 0x80000000;
67 gd->ram_size = 0x100000000;
73 #ifdef CONFIG_SPL_LOAD_FIT
74 int board_fit_config_name_match(const char *name)
76 if (!strcmp(name, "k3-j721e-common-proc-board"))
83 #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
84 int ft_board_setup(void *blob, bd_t *bd)
88 ret = fdt_fixup_msmc_ram(blob, "/interconnect@100000", "sram@70000000");
90 printf("%s: fixing up msmc ram failed %d\n", __func__, ret);
96 int do_board_detect(void)
100 ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS,
101 CONFIG_EEPROM_CHIP_ADDRESS);
103 pr_err("Reading on-board EEPROM at 0x%02x failed %d\n",
104 CONFIG_EEPROM_CHIP_ADDRESS, ret);
111 struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
113 if (do_board_detect())
114 /* EEPROM not populated */
115 printf("Board: %s rev %s\n", "J721EX-PM1-SOM", "E2");
117 printf("Board: %s rev %s\n", ep->name, ep->version);
122 static void setup_board_eeprom_env(void)
124 char *name = "j721e";
126 if (do_board_detect())
129 if (board_is_j721e_som())
132 printf("Unidentified board claims %s in eeprom header\n",
133 board_ti_get_name());
136 set_board_info_env_am6(name);
139 static void setup_serial(void)
141 struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
142 unsigned long board_serial;
144 char serial_string[17] = { 0 };
146 if (env_get("serial#"))
149 board_serial = simple_strtoul(ep->serial, &endp, 16);
151 pr_err("Error: Can't set serial# to %s\n", ep->serial);
155 snprintf(serial_string, sizeof(serial_string), "%016lx", board_serial);
156 env_set("serial#", serial_string);
160 * Declaration of daughtercards to probe. Note that when adding more
161 * cards they should be grouped by the 'i2c_addr' field to allow for a
162 * more efficient probing process.
164 static const struct {
165 u8 i2c_addr; /* I2C address of card EEPROM */
166 char *card_name; /* EEPROM-programmed card name */
167 char *dtbo_name; /* Device tree overlay to apply */
168 u8 eth_offset; /* ethXaddr MAC address index offset */
173 "", /* No dtbo for this board */
179 "", /* No dtbo for this board */
185 "", /* No dtbo for this board */
186 5, /* Start populating from eth5addr */
191 "", /* No dtbo for this board */
192 1, /* Start populating from eth1addr */
196 static bool daughter_card_detect_flags[ARRAY_SIZE(ext_cards)];
198 const char *board_fit_get_additionnal_images(int index, const char *type)
202 if (strcmp(type, FIT_FDT_PROP))
206 for (i = 0; i < ARRAY_SIZE(ext_cards); i++) {
207 if (daughter_card_detect_flags[i]) {
210 * Return dtbo name only if populated,
211 * otherwise stop parsing here.
213 if (strlen(ext_cards[i].dtbo_name))
214 return ext_cards[i].dtbo_name;
226 static int probe_daughtercards(void)
228 char mac_addr[DAUGHTER_CARD_NO_OF_MAC_ADDR][TI_EEPROM_HDR_ETH_ALEN];
229 bool eeprom_read_success;
230 struct ti_am6_eeprom ep;
231 u8 previous_i2c_addr;
236 /* Mark previous I2C address variable as not populated */
237 previous_i2c_addr = 0xff;
239 /* No EEPROM data was read yet */
240 eeprom_read_success = false;
242 /* Iterate through list of daughtercards */
243 for (i = 0; i < ARRAY_SIZE(ext_cards); i++) {
244 /* Obtain card-specific I2C address */
245 u8 i2c_addr = ext_cards[i].i2c_addr;
247 /* Read card EEPROM if not already read previously */
248 if (i2c_addr != previous_i2c_addr) {
249 /* Store I2C address so we can avoid reading twice */
250 previous_i2c_addr = i2c_addr;
252 /* Get and parse the daughter card EEPROM record */
253 ret = ti_i2c_eeprom_am6_get(CONFIG_EEPROM_BUS_ADDRESS,
257 DAUGHTER_CARD_NO_OF_MAC_ADDR,
260 debug("%s: No daughtercard EEPROM at 0x%02x found %d\n",
261 __func__, i2c_addr, ret);
262 eeprom_read_success = false;
263 /* Skip to the next daughtercard to probe */
267 /* EEPROM read successful, okay to further process. */
268 eeprom_read_success = true;
271 /* Only continue processing if EEPROM data was read */
272 if (!eeprom_read_success)
275 /* Only process the parsed data if we found a match */
276 if (strncmp(ep.name, ext_cards[i].card_name, sizeof(ep.name)))
279 printf("Detected: %s rev %s\n", ep.name, ep.version);
280 daughter_card_detect_flags[i] = true;
282 #ifndef CONFIG_SPL_BUILD
285 * Populate any MAC addresses from daughtercard into the U-Boot
286 * environment, starting with a card-specific offset so we can
287 * have multiple ext_cards contribute to the MAC pool in a well-
290 for (j = 0; j < mac_addr_cnt; j++) {
291 if (!is_valid_ethaddr((u8 *)mac_addr[j]))
294 eth_env_set_enetaddr_by_index("eth",
295 ext_cards[i].eth_offset + j,
296 (uchar *)mac_addr[j]);
300 #ifndef CONFIG_SPL_BUILD
301 char name_overlays[1024] = { 0 };
303 for (i = 0; i < ARRAY_SIZE(ext_cards); i++) {
304 if (!daughter_card_detect_flags[i])
307 /* Skip if no overlays are to be added */
308 if (!strlen(ext_cards[i].dtbo_name))
312 * Make sure we are not running out of buffer space by checking
313 * if we can fit the new overlay, a trailing space to be used
314 * as a separator, plus the terminating zero.
316 if (strlen(name_overlays) + strlen(ext_cards[i].dtbo_name) + 2 >
317 sizeof(name_overlays))
320 /* Append to our list of overlays */
321 strcat(name_overlays, ext_cards[i].dtbo_name);
322 strcat(name_overlays, " ");
325 /* Apply device tree overlay(s) to the U-Boot environment, if any */
326 if (strlen(name_overlays))
327 return env_set("name_overlays", name_overlays);
333 int board_late_init(void)
335 setup_board_eeprom_env();
338 /* Check for and probe any plugged-in daughtercards */
339 probe_daughtercards();
344 void spl_board_init(void)
346 probe_daughtercards();