summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSiddharth Vadapalli <s-vadapalli@ti.com>2023-02-21 12:34:43 +0530
committerUdit Kumar <u-kumar1@ti.com>2023-02-23 10:01:29 +0530
commitba520788a51d1101d66b4a8b23b0d379f688622d (patch)
tree0baac799e6d270325aacda04b5d57d8d25693303
parentf5c0a7ef3c77f84ec6b5abb0321cbf8e6622e11f (diff)
board: ti: am62ax: evm.c: Add EEPROM associated features
Add functions to support features such as detecting the board from the EEPROM as well as fetching the MAC address from EEPROM. Signed-off-by: Siddharth Vadapalli <s-vadapalli@ti.com>
-rw-r--r--board/ti/am62ax/evm.c88
1 files changed, 88 insertions, 0 deletions
diff --git a/board/ti/am62ax/evm.c b/board/ti/am62ax/evm.c
index f5c2f46884..a7c3d43e43 100644
--- a/board/ti/am62ax/evm.c
+++ b/board/ti/am62ax/evm.c
@@ -55,6 +55,94 @@ int board_fit_config_name_match(const char *name)
#define CTRLMMR_USB1_PHY_CTRL 0x43004018
#define CORE_VOLTAGE 0x80000000
+#ifdef CONFIG_TI_I2C_BOARD_DETECT
+int do_board_detect(void)
+{
+ int ret;
+
+ 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())
+ printf("Board: %s rev %s\n", ep->name, ep->version);
+
+ return 0;
+}
+#endif
+
+#ifdef CONFIG_BOARD_LATE_INIT
+static void setup_board_eeprom_env(void)
+{
+ char *name = "am62ax_skevm";
+
+ if (do_board_detect())
+ goto invalid_eeprom;
+
+ if (board_is_am62ax_skevm())
+ name = "am62ax_skevm";
+ 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);
+}
+
+int board_late_init(void)
+{
+ if (IS_ENABLED(CONFIG_TI_I2C_BOARD_DETECT)) {
+ struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
+
+ setup_board_eeprom_env();
+ setup_serial();
+ /*
+ * The first MAC address for ethernet a.k.a. ethernet0 comes from
+ * efuse populated via the am654 gigabit eth switch subsystem driver.
+ * All the other ones are populated via EEPROM, hence continue with
+ * an index of 1.
+ */
+ board_ti_am6_set_ethaddr(1, ep->mac_addr_cnt);
+ }
+ return 0;
+}
+#endif
+
#if defined(CONFIG_SPL_BOARD_INIT)
void spl_board_init(void)
{