]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
ti: common: am6: Add support for setting MAC addresses
authorAndreas Dannenberg <dannenberg@ti.com>
Tue, 4 Jun 2019 23:08:25 +0000 (18:08 -0500)
committerTom Rini <trini@konsulko.com>
Wed, 17 Jul 2019 15:13:18 +0000 (11:13 -0400)
The AM654x EVM based on the TI K3 family of SoCs has an updated board
detection EEPROM structure that contains a TLV record of dedicated MAC
addresses rather than a range of MAC addresses as it was used on earlier
platforms such as DRA7. Add a basic function that allows us setting up
Ethernet MAC addresses into the U-Boot environment based on the MAC
address record contained in the common TI EEPROM structure.

Signed-off-by: Andreas Dannenberg <dannenberg@ti.com>
Reviewed-by: Lokesh Vutla <lokeshvutla@ti.com>
board/ti/common/board_detect.c
board/ti/common/board_detect.h

index fea39f21e8ce0d114aeb9e2250f437298be98d71..32fa10599e8250a518c9a5ea7c65492f2cd8c6b2 100644 (file)
@@ -534,6 +534,25 @@ fail:
        memset(mac_addr, 0, TI_EEPROM_HDR_ETH_ALEN);
 }
 
+void __maybe_unused
+board_ti_am6_get_eth_mac_addr(int index,
+                             u8 mac_addr[TI_EEPROM_HDR_ETH_ALEN])
+{
+       struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
+
+       if (ep->header == TI_DEAD_EEPROM_MAGIC)
+               goto fail;
+
+       if (index < 0 || index >= ep->mac_addr_cnt)
+               goto fail;
+
+       memcpy(mac_addr, ep->mac_addr[index], TI_EEPROM_HDR_ETH_ALEN);
+       return;
+
+fail:
+       memset(mac_addr, 0, TI_EEPROM_HDR_ETH_ALEN);
+}
+
 u64 __maybe_unused board_ti_get_emif1_size(void)
 {
        struct ti_common_eeprom *ep = TI_EEPROM_DATA;
@@ -667,6 +686,19 @@ void board_ti_set_ethaddr(int index)
        }
 }
 
+void board_ti_am6_set_ethaddr(int index, int count)
+{
+       u8 mac_addr[6];
+       int i;
+
+       for (i = 0; i < count; i++) {
+               board_ti_am6_get_eth_mac_addr(i, mac_addr);
+               if (is_valid_ethaddr(mac_addr))
+                       eth_env_set_enetaddr_by_index("eth", i + index,
+                                                     mac_addr);
+       }
+}
+
 bool __maybe_unused board_ti_was_eeprom_read(void)
 {
        struct ti_common_eeprom *ep = TI_EEPROM_DATA;
index bf563c84c8f6b14921e0bace8f1a11aea031d36a..a45d8961b9ad89f2976b431b348137cf8d7a6988 100644 (file)
@@ -398,6 +398,18 @@ void set_board_info_env_am6(char *name);
  */
 void board_ti_set_ethaddr(int index);
 
+/**
+ * board_ti_am6_set_ethaddr- Sets the ethaddr environment from EEPROM
+ * @index: The first eth<index>addr environment variable to set
+ * @count: The number of MAC addresses to process
+ *
+ * EEPROM should be already read before calling this function. The EEPROM
+ * contains n dedicated MAC addresses. This function sets the ethaddr
+ * environment variable for all the available MAC addresses starting
+ * from eth<index>addr.
+ */
+void board_ti_am6_set_ethaddr(int index, int count);
+
 /**
  * board_ti_was_eeprom_read() - Check to see if the eeprom contents have been read
  *