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 <fdt_support.h>
17 #include <asm/arch/sys_proto.h>
18 #include <asm/arch/hardware.h>
22 #include <asm/arch/sys_proto.h>
24 #include <dm/uclass-internal.h>
26 #include "../common/board_detect.h"
28 #define board_is_j721e_som() (board_ti_k3_is("J721EX-PM1-SOM") || \
29 board_ti_k3_is("J721EX-PM2-SOM"))
31 #define board_is_j7200_som() board_ti_k3_is("J7200X-PM1-SOM")
33 /* Max number of MAC addresses that are parsed/processed per daughter card */
34 #define DAUGHTER_CARD_NO_OF_MAC_ADDR 8
36 DECLARE_GLOBAL_DATA_PTR;
45 #ifdef CONFIG_PHYS_64BIT
46 gd->ram_size = 0x100000000;
48 gd->ram_size = 0x80000000;
54 ulong board_get_usable_ram_top(ulong total_size)
56 #ifdef CONFIG_PHYS_64BIT
57 /* Limit RAM used by U-Boot to the DDR low region */
58 if (gd->ram_top > 0x100000000)
65 int dram_init_banksize(void)
67 /* Bank 0 declares the memory available in the DDR low region */
68 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
69 gd->bd->bi_dram[0].size = 0x80000000;
70 gd->ram_size = 0x80000000;
72 #ifdef CONFIG_PHYS_64BIT
73 /* Bank 1 declares the memory available in the DDR high region */
74 gd->bd->bi_dram[1].start = CONFIG_SYS_SDRAM_BASE1;
75 gd->bd->bi_dram[1].size = 0x80000000;
76 gd->ram_size = 0x100000000;
82 #ifdef CONFIG_SPL_LOAD_FIT
83 int board_fit_config_name_match(const char *name)
85 if (!strcmp(name, "k3-j721e-common-proc-board"))
92 #if CONFIG_IS_ENABLED(DM_GPIO) && CONFIG_IS_ENABLED(OF_LIBFDT)
93 /* Returns 1, if onboard mux is set to hyperflash */
94 static void __maybe_unused detect_enable_hyperflash(void *blob)
96 struct gpio_desc desc = {0};
98 if (dm_gpio_lookup_name("6", &desc))
101 if (dm_gpio_request(&desc, "6"))
104 if (dm_gpio_set_dir_flags(&desc, GPIOD_IS_IN))
107 if (dm_gpio_get_value(&desc)) {
110 do_fixup_by_compat(blob, "ti,am654-hbmc", "status",
111 "okay", sizeof("okay"), 0);
112 offset = fdt_node_offset_by_compatible(blob, -1,
114 fdt_setprop(blob, offset, "status", "disabled",
120 #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
121 int ft_board_setup(void *blob, struct bd_info *bd)
125 ret = fdt_fixup_msmc_ram(blob, "/bus@100000", "sram@70000000");
127 ret = fdt_fixup_msmc_ram(blob, "/interconnect@100000",
130 printf("%s: fixing up msmc ram failed %d\n", __func__, ret);
132 detect_enable_hyperflash(blob);
138 #ifdef CONFIG_TI_I2C_BOARD_DETECT
139 int do_board_detect(void)
143 ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS,
144 CONFIG_EEPROM_CHIP_ADDRESS);
146 pr_err("Reading on-board EEPROM at 0x%02x failed %d\n",
147 CONFIG_EEPROM_CHIP_ADDRESS, ret);
154 struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
156 if (do_board_detect())
157 /* EEPROM not populated */
158 printf("Board: %s rev %s\n", "J721EX-PM1-SOM", "E2");
160 printf("Board: %s rev %s\n", ep->name, ep->version);
165 static void setup_board_eeprom_env(void)
167 char *name = "j721e";
169 if (do_board_detect())
172 if (board_is_j721e_som())
174 else if (board_is_j7200_som())
177 printf("Unidentified board claims %s in eeprom header\n",
178 board_ti_get_name());
181 set_board_info_env_am6(name);
184 static void setup_serial(void)
186 struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
187 unsigned long board_serial;
189 char serial_string[17] = { 0 };
191 if (env_get("serial#"))
194 board_serial = simple_strtoul(ep->serial, &endp, 16);
196 pr_err("Error: Can't set serial# to %s\n", ep->serial);
200 snprintf(serial_string, sizeof(serial_string), "%016lx", board_serial);
201 env_set("serial#", serial_string);
205 * Declaration of daughtercards to probe. Note that when adding more
206 * cards they should be grouped by the 'i2c_addr' field to allow for a
207 * more efficient probing process.
209 static const struct {
210 u8 i2c_addr; /* I2C address of card EEPROM */
211 char *card_name; /* EEPROM-programmed card name */
212 char *dtbo_name; /* Device tree overlay to apply */
213 u8 eth_offset; /* ethXaddr MAC address index offset */
218 "", /* No dtbo for this board */
224 "", /* No dtbo for this board */
230 "", /* No dtbo for this board */
231 5, /* Start populating from eth5addr */
236 "", /* No dtbo for this board */
237 1, /* Start populating from eth1addr */
241 static bool daughter_card_detect_flags[ARRAY_SIZE(ext_cards)];
243 const char *board_fit_get_additionnal_images(int index, const char *type)
247 if (strcmp(type, FIT_FDT_PROP))
251 for (i = 0; i < ARRAY_SIZE(ext_cards); i++) {
252 if (daughter_card_detect_flags[i]) {
255 * Return dtbo name only if populated,
256 * otherwise stop parsing here.
258 if (strlen(ext_cards[i].dtbo_name))
259 return ext_cards[i].dtbo_name;
271 static int probe_daughtercards(void)
273 char mac_addr[DAUGHTER_CARD_NO_OF_MAC_ADDR][TI_EEPROM_HDR_ETH_ALEN];
274 bool eeprom_read_success;
275 struct ti_am6_eeprom ep;
276 u8 previous_i2c_addr;
281 /* Mark previous I2C address variable as not populated */
282 previous_i2c_addr = 0xff;
284 /* No EEPROM data was read yet */
285 eeprom_read_success = false;
287 /* Iterate through list of daughtercards */
288 for (i = 0; i < ARRAY_SIZE(ext_cards); i++) {
289 /* Obtain card-specific I2C address */
290 u8 i2c_addr = ext_cards[i].i2c_addr;
292 /* Read card EEPROM if not already read previously */
293 if (i2c_addr != previous_i2c_addr) {
294 /* Store I2C address so we can avoid reading twice */
295 previous_i2c_addr = i2c_addr;
297 /* Get and parse the daughter card EEPROM record */
298 ret = ti_i2c_eeprom_am6_get(CONFIG_EEPROM_BUS_ADDRESS,
302 DAUGHTER_CARD_NO_OF_MAC_ADDR,
305 debug("%s: No daughtercard EEPROM at 0x%02x found %d\n",
306 __func__, i2c_addr, ret);
307 eeprom_read_success = false;
308 /* Skip to the next daughtercard to probe */
312 /* EEPROM read successful, okay to further process. */
313 eeprom_read_success = true;
316 /* Only continue processing if EEPROM data was read */
317 if (!eeprom_read_success)
320 /* Only process the parsed data if we found a match */
321 if (strncmp(ep.name, ext_cards[i].card_name, sizeof(ep.name)))
324 printf("Detected: %s rev %s\n", ep.name, ep.version);
325 daughter_card_detect_flags[i] = true;
327 #ifndef CONFIG_SPL_BUILD
330 * Populate any MAC addresses from daughtercard into the U-Boot
331 * environment, starting with a card-specific offset so we can
332 * have multiple ext_cards contribute to the MAC pool in a well-
335 for (j = 0; j < mac_addr_cnt; j++) {
336 if (!is_valid_ethaddr((u8 *)mac_addr[j]))
339 eth_env_set_enetaddr_by_index("eth",
340 ext_cards[i].eth_offset + j,
341 (uchar *)mac_addr[j]);
345 #ifndef CONFIG_SPL_BUILD
346 char name_overlays[1024] = { 0 };
348 for (i = 0; i < ARRAY_SIZE(ext_cards); i++) {
349 if (!daughter_card_detect_flags[i])
352 /* Skip if no overlays are to be added */
353 if (!strlen(ext_cards[i].dtbo_name))
357 * Make sure we are not running out of buffer space by checking
358 * if we can fit the new overlay, a trailing space to be used
359 * as a separator, plus the terminating zero.
361 if (strlen(name_overlays) + strlen(ext_cards[i].dtbo_name) + 2 >
362 sizeof(name_overlays))
365 /* Append to our list of overlays */
366 strcat(name_overlays, ext_cards[i].dtbo_name);
367 strcat(name_overlays, " ");
370 /* Apply device tree overlay(s) to the U-Boot environment, if any */
371 if (strlen(name_overlays))
372 return env_set("name_overlays", name_overlays);
379 int board_late_init(void)
381 if (IS_ENABLED(CONFIG_TI_I2C_BOARD_DETECT)) {
382 setup_board_eeprom_env();
385 /* Check for and probe any plugged-in daughtercards */
386 probe_daughtercards();
392 void spl_board_init(void)
394 #if defined(CONFIG_ESM_K3) || defined(CONFIG_ESM_PMIC)
399 if ((IS_ENABLED(CONFIG_TARGET_J721E_A72_EVM) ||
400 IS_ENABLED(CONFIG_TARGET_J7200_A72_EVM)) &&
401 IS_ENABLED(CONFIG_TI_I2C_BOARD_DETECT))
402 probe_daughtercards();
405 if (board_ti_k3_is("J721EX-PM2-SOM")) {
406 ret = uclass_get_device_by_driver(UCLASS_MISC,
407 DM_GET_DRIVER(k3_esm), &dev);
409 printf("ESM init failed: %d\n", ret);
413 #ifdef CONFIG_ESM_PMIC
414 if (board_ti_k3_is("J721EX-PM2-SOM")) {
415 ret = uclass_get_device_by_driver(UCLASS_MISC,
416 DM_GET_DRIVER(pmic_esm),
419 printf("ESM PMIC init failed: %d\n", ret);