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);
109 static void setup_board_eeprom_env(void)
111 char *name = "j721e";
113 if (do_board_detect())
116 if (board_is_j721e_som())
119 printf("Unidentified board claims %s in eeprom header\n",
120 board_ti_get_name());
123 set_board_info_env_am6(name);
126 static void setup_serial(void)
128 struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
129 unsigned long board_serial;
131 char serial_string[17] = { 0 };
133 if (env_get("serial#"))
136 board_serial = simple_strtoul(ep->serial, &endp, 16);
138 pr_err("Error: Can't set serial# to %s\n", ep->serial);
142 snprintf(serial_string, sizeof(serial_string), "%016lx", board_serial);
143 env_set("serial#", serial_string);
147 * Declaration of daughtercards to probe. Note that when adding more
148 * cards they should be grouped by the 'i2c_addr' field to allow for a
149 * more efficient probing process.
151 static const struct {
152 u8 i2c_addr; /* I2C address of card EEPROM */
153 char *card_name; /* EEPROM-programmed card name */
154 char *dtbo_name; /* Device tree overlay to apply */
155 u8 eth_offset; /* ethXaddr MAC address index offset */
160 "", /* No dtbo for this board */
166 "", /* No dtbo for this board */
172 "", /* No dtbo for this board */
173 5, /* Start populating from eth5addr */
178 "", /* No dtbo for this board */
179 1, /* Start populating from eth1addr */
183 static bool daughter_card_detect_flags[ARRAY_SIZE(ext_cards)];
185 const char *board_fit_get_additionnal_images(int index, const char *type)
189 if (strcmp(type, FIT_FDT_PROP))
193 for (i = 0; i < ARRAY_SIZE(ext_cards); i++) {
194 if (daughter_card_detect_flags[i]) {
197 * Return dtbo name only if populated,
198 * otherwise stop parsing here.
200 if (strlen(ext_cards[i].dtbo_name))
201 return ext_cards[i].dtbo_name;
213 static int probe_daughtercards(void)
215 char mac_addr[DAUGHTER_CARD_NO_OF_MAC_ADDR][TI_EEPROM_HDR_ETH_ALEN];
216 bool eeprom_read_success;
217 struct ti_am6_eeprom ep;
218 u8 previous_i2c_addr;
223 /* Mark previous I2C address variable as not populated */
224 previous_i2c_addr = 0xff;
226 /* No EEPROM data was read yet */
227 eeprom_read_success = false;
229 /* Iterate through list of daughtercards */
230 for (i = 0; i < ARRAY_SIZE(ext_cards); i++) {
231 /* Obtain card-specific I2C address */
232 u8 i2c_addr = ext_cards[i].i2c_addr;
234 /* Read card EEPROM if not already read previously */
235 if (i2c_addr != previous_i2c_addr) {
236 /* Store I2C address so we can avoid reading twice */
237 previous_i2c_addr = i2c_addr;
239 /* Get and parse the daughter card EEPROM record */
240 ret = ti_i2c_eeprom_am6_get(CONFIG_EEPROM_BUS_ADDRESS,
244 DAUGHTER_CARD_NO_OF_MAC_ADDR,
247 debug("%s: No daughtercard EEPROM at 0x%02x found %d\n",
248 __func__, i2c_addr, ret);
249 eeprom_read_success = false;
250 /* Skip to the next daughtercard to probe */
254 /* EEPROM read successful, okay to further process. */
255 eeprom_read_success = true;
258 /* Only continue processing if EEPROM data was read */
259 if (!eeprom_read_success)
262 /* Only process the parsed data if we found a match */
263 if (strncmp(ep.name, ext_cards[i].card_name, sizeof(ep.name)))
266 printf("Detected: %s rev %s\n", ep.name, ep.version);
267 daughter_card_detect_flags[i] = true;
269 #ifndef CONFIG_SPL_BUILD
272 * Populate any MAC addresses from daughtercard into the U-Boot
273 * environment, starting with a card-specific offset so we can
274 * have multiple ext_cards contribute to the MAC pool in a well-
277 for (j = 0; j < mac_addr_cnt; j++) {
278 if (!is_valid_ethaddr((u8 *)mac_addr[j]))
281 eth_env_set_enetaddr_by_index("eth",
282 ext_cards[i].eth_offset + j,
283 (uchar *)mac_addr[j]);
287 #ifndef CONFIG_SPL_BUILD
288 char name_overlays[1024] = { 0 };
290 for (i = 0; i < ARRAY_SIZE(ext_cards); i++) {
291 if (!daughter_card_detect_flags[i])
294 /* Skip if no overlays are to be added */
295 if (!strlen(ext_cards[i].dtbo_name))
299 * Make sure we are not running out of buffer space by checking
300 * if we can fit the new overlay, a trailing space to be used
301 * as a separator, plus the terminating zero.
303 if (strlen(name_overlays) + strlen(ext_cards[i].dtbo_name) + 2 >
304 sizeof(name_overlays))
307 /* Append to our list of overlays */
308 strcat(name_overlays, ext_cards[i].dtbo_name);
309 strcat(name_overlays, " ");
312 /* Apply device tree overlay(s) to the U-Boot environment, if any */
313 if (strlen(name_overlays))
314 return env_set("name_overlays", name_overlays);
320 int board_late_init(void)
322 setup_board_eeprom_env();
325 /* Check for and probe any plugged-in daughtercards */
326 probe_daughtercards();
331 void spl_board_init(void)
333 probe_daughtercards();