@@ -339,18 +339,21 @@ config I2C0_ENABLE
config I2C1_ENABLE
bool "Enable I2C/TWI controller 1"
+ default y if (NET_ETHADDR_EEPROM_I2C_BUS = 1)
default n
---help---
See I2C0_ENABLE help text.
config I2C2_ENABLE
bool "Enable I2C/TWI controller 2"
+ default y if NET_ETHADDR_EEPROM_I2C_BUS = 2
default n
---help---
See I2C0_ENABLE help text.
if MACH_SUN6I || MACH_SUN7I
config I2C3_ENABLE
+ default y if NET_ETHADDR_EEPROM_I2C_BUS = 3
bool "Enable I2C/TWI controller 3"
default n
---help---
@@ -359,6 +362,7 @@ endif
if MACH_SUN7I
config I2C4_ENABLE
+ default y if NET_ETHADDR_EEPROM_I2C_BUS = 4
bool "Enable I2C/TWI controller 4"
default n
---help---
@@ -12,6 +12,7 @@
*/
#include <common.h>
+#include <i2c.h>
#include <mmc.h>
#include <axp_pmic.h>
#include <asm/arch/clock.h>
@@ -23,6 +24,7 @@
#include <asm/arch/usb_phy.h>
#include <asm/gpio.h>
#include <asm/io.h>
+#include <linux/crc8.h>
#include <nand.h>
#include <net.h>
@@ -510,6 +512,37 @@ void get_board_serial(struct tag_serialnr *serialnr)
}
#endif
+#if defined(CONFIG_NET_ETHADDR_EEPROM) && defined(CONFIG_NET_ETHADDR_EEPROM_I2C)
+static int read_mac_from_eeprom(uint8_t *mac_addr)
+{
+ uint8_t eeprom[8];
+ int old_i2c_bus;
+
+ old_i2c_bus = i2c_get_bus_num();
+ i2c_set_bus_num(CONFIG_NET_ETHADDR_EEPROM_I2C_BUS);
+ if (i2c_read(CONFIG_NET_ETHADDR_EEPROM_I2C_ADDR,
+ CONFIG_NET_ETHADDR_EEPROM_OFFSET,
+ CONFIG_NET_ETHADDR_EEPROM_I2C_ADDRLEN,
+ eeprom, 8)) {
+ i2c_set_bus_num(old_i2c_bus);
+ puts("Could not read the EEPROM; EEPROM missing?\n");
+ return -1;
+ }
+ i2c_set_bus_num(old_i2c_bus);
+#ifdef CONFIG_NET_ETHADDR_EEPROM_CRC8
+ if (crc8(eeprom, 7) != eeprom[7]) {
+ puts("CRC error on MAC address from EEPROM.\n");
+ return -1;
+ }
+#endif
+ memcpy(mac_addr, eeprom, 6);
+
+ return 0;
+}
+#else
+static int read_mac_from_eeprom(uint8_t *mac_addr) { return -1; }
+#endif
+
#if !defined(CONFIG_SPL_BUILD)
#include <asm/arch/spl.h>
@@ -553,6 +586,9 @@ int misc_init_r(void)
}
#endif
+ if ((!getenv("ethaddr")) && (!read_mac_from_eeprom(mac_addr)))
+ eth_setenv_enetaddr("ethaddr", mac_addr);
+
ret = sunxi_get_sid(sid);
if (ret == 0 && sid[0] != 0 && sid[3] != 0) {
if (!getenv("ethaddr")) {
@@ -8,6 +8,7 @@ menuconfig NET
if NET
config NET_ETHADDR_EEPROM
+ depends on ARCH_SUNXI
bool "Get ethaddr from eeprom"
help
Selecting this will try to get the Ethernet address from an onboard