]> git.sur5r.net Git - u-boot/commitdiff
netspace_v2: Read Ethernet MAC address from EEPROM
authorSimon Guinot <simon.guinot@sequanux.org>
Tue, 8 Nov 2011 11:31:14 +0000 (11:31 +0000)
committerAlbert ARIBAUD <albert.u.boot@aribaud.net>
Tue, 6 Dec 2011 22:59:30 +0000 (23:59 +0100)
Signed-off-by: Simon Guinot <simon.guinot@sequanux.org>
board/LaCie/netspace_v2/netspace_v2.c
include/configs/netspace_v2.h

index 7c4b15ec477a9f1807e6072d7e1b9b26802cda75..6938a4370a80d6e83f06b4e5152012b22476add2 100644 (file)
@@ -24,6 +24,7 @@
 #include <miiphy.h>
 #include <netdev.h>
 #include <command.h>
+#include <i2c.h>
 #include <asm/arch/cpu.h>
 #include <asm/arch/kirkwood.h>
 #include <asm/arch/mpp.h>
@@ -89,6 +90,48 @@ int board_init(void)
        return 0;
 }
 
+int misc_init_r(void)
+{
+#if defined(CONFIG_CMD_I2C) && defined(CONFIG_SYS_I2C_EEPROM_ADDR)
+       if (!getenv("ethaddr")) {
+               ushort version;
+               uchar mac[6];
+               int ret;
+
+               /* I2C-0 for on-board EEPROM */
+               i2c_set_bus_num(0);
+
+               /* Check layout version for EEPROM data */
+               ret = i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0,
+                               CONFIG_SYS_I2C_EEPROM_ADDR_LEN,
+                               (uchar *) &version, 2);
+               if (ret != 0) {
+                       printf("Error: failed to read I2C EEPROM @%02x\n",
+                               CONFIG_SYS_I2C_EEPROM_ADDR);
+                       return ret;
+               }
+               version = be16_to_cpu(version);
+               if (version < 1 || version > 3) {
+                       printf("Error: unknown version %d for EEPROM data\n",
+                               version);
+                       return -1;
+               }
+
+               /* Read Ethernet MAC address from EEPROM */
+               ret = i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 2,
+                               CONFIG_SYS_I2C_EEPROM_ADDR_LEN, mac, 6);
+               if (ret != 0) {
+                       printf("Error: failed to read I2C EEPROM @%02x\n",
+                               CONFIG_SYS_I2C_EEPROM_ADDR);
+                       return ret;
+               }
+               eth_setenv_enetaddr("ethaddr", mac);
+       }
+#endif /* CONFIG_CMD_I2C && CONFIG_SYS_I2C_EEPROM_ADDR */
+
+       return 0;
+}
+
 void mv_phy_88e1116_init(char *name)
 {
        u16 reg;
index bb27ed76486909512543b4bf4dbb1fc78d0fcd8d..1ddf4b4b6c4896d8d14adf68b098e2b9e822cbbb 100644 (file)
@@ -87,6 +87,7 @@
  * Ethernet Driver configuration
  */
 #ifdef CONFIG_CMD_NET
+#define CONFIG_MISC_INIT_R /* Call misc_init_r() to initialize MAC address */
 #define CONFIG_MVGBE_PORTS             {1, 0} /* enable port 0 only */
 #define CONFIG_NETCONSOLE
 #endif