[PATCH v3 11/16] board: ti: j784s4: Add support for board detection by EEPROM read

Apurva Nandan a-nandan at ti.com
Fri Sep 8 13:05:46 CEST 2023


From: Dasnavis Sabiya <sabiya.d at ti.com>

The board name is programmed in the EEPROM. Add support for board
detection and choose the right dtb based on the board name read
from EEPROM.

The J784S4/AM69 has two platforms naming J784S4-EVM and AM69-SK. The
J784S4 has EEPROM populated at 0x50. AM69 SK has EEPROM
populated at next address 0x51. So start looking for TI specific EEPROM
at 0x50, if not found look for EEPROM at 0x51.

Also, add support for setup_serial() to read the serial number from EEPROM
and update the serial environment variable with the same.

Signed-off-by: Dasnavis Sabiya <sabiya.d at ti.com>
Signed-off-by: Apurva Nandan <a-nandan at ti.com>
---
 board/ti/j784s4/evm.c | 96 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 96 insertions(+)

diff --git a/board/ti/j784s4/evm.c b/board/ti/j784s4/evm.c
index d6e695f183..f2a0216888 100644
--- a/board/ti/j784s4/evm.c
+++ b/board/ti/j784s4/evm.c
@@ -26,6 +26,8 @@
 
 #define board_is_j784s4_evm()	board_ti_k3_is("J784S4-EVM")
 
+#define board_is_am69_sk()      board_ti_k3_is("AM69-SK")
+
 DECLARE_GLOBAL_DATA_PTR;
 
 int board_init(void)
@@ -72,6 +74,100 @@ int dram_init_banksize(void)
 	return 0;
 }
 
+#ifdef CONFIG_SPL_LOAD_FIT
+int board_fit_config_name_match(const char *name)
+{
+	bool eeprom_read = board_ti_was_eeprom_read();
+
+	if (!eeprom_read || board_is_j784s4_evm()) {
+		if ((!strcmp(name, "k3-j784s4-evm")) || (!strcmp(name, "k3-j784s4-r5-evm")))
+			return 0;
+	} else if (!eeprom_read || board_is_am69_sk()) {
+		if ((!strcmp(name, "k3-am69-sk")) || (!strcmp(name, "k3-am69-r5-sk")))
+			return 0;
+	}
+
+	return -1;
+}
+#endif
+
+#ifdef CONFIG_TI_I2C_BOARD_DETECT
+int do_board_detect(void)
+{
+	int ret;
+
+	if (board_ti_was_eeprom_read())
+		return 0;
+
+	ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS,
+					 CONFIG_EEPROM_CHIP_ADDRESS);
+	if (ret) {
+		printf("EEPROM not available at 0x%02x, trying to read at 0x%02x\n",
+		       CONFIG_EEPROM_CHIP_ADDRESS, CONFIG_EEPROM_CHIP_ADDRESS + 1);
+		ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS,
+						 CONFIG_EEPROM_CHIP_ADDRESS + 1);
+		if (ret)
+			pr_err("Reading on-board EEPROM at 0x%02x failed %d\n",
+			       CONFIG_EEPROM_CHIP_ADDRESS + 1, ret);
+	}
+
+	return ret;
+}
+
+int checkboard(void)
+{
+	struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
+
+	if (do_board_detect())
+		/* EEPROM not populated */
+		printf("Board: %s rev %s\n", "J784S4-EVM", "E1");
+	else
+		printf("Board: %s rev %s\n", ep->name, ep->version);
+
+	return 0;
+}
+
+static void setup_board_eeprom_env(void)
+{
+	char *name = "j784s4";
+
+	if (do_board_detect())
+		goto invalid_eeprom;
+
+	if (board_is_j784s4_evm())
+		name = "j784s4";
+	else if (board_is_am69_sk())
+		name = "am69-sk";
+	else
+		printf("Unidentified board claims %s in eeprom header\n",
+		       board_ti_get_name());
+
+invalid_eeprom:
+	set_board_info_env_am6(name);
+}
+
+static void setup_serial(void)
+{
+	struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
+	unsigned long board_serial;
+	char *endp;
+	char serial_string[17] = { 0 };
+
+	if (env_get("serial#"))
+		return;
+
+	board_serial = simple_strtoul(ep->serial, &endp, 16);
+	if (*endp != '\0') {
+		pr_err("Error: Can't set serial# to %s\n", ep->serial);
+		return;
+	}
+
+	snprintf(serial_string, sizeof(serial_string), "%016lx", board_serial);
+	env_set("serial#", serial_string);
+}
+
+#endif
+
 int board_late_init(void)
 {
 	if (IS_ENABLED(CONFIG_TI_I2C_BOARD_DETECT)) {
-- 
2.34.1



More information about the U-Boot mailing list