From b1aa3382bc20101be6df9808fa65b6c60e696516 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Fri, 19 Dec 2014 05:26:45 +0100 Subject: [PATCH] WIP: use mac address from EEPROM, not eFuse mac address THIS IS NOT WORKING YET the problem is that the cpsw ethernet device is initialized before I2C is initialized, and we thus cannot read the EEPROM from coredev_init, and once we reach device_init, it is already too late :( --- arch/arm/boards/phytec-phycore-am335x/board.c | 54 ++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/arch/arm/boards/phytec-phycore-am335x/board.c b/arch/arm/boards/phytec-phycore-am335x/board.c index 9482b80ed..151a0c84b 100644 --- a/arch/arm/boards/phytec-phycore-am335x/board.c +++ b/arch/arm/boards/phytec-phycore-am335x/board.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -29,15 +30,62 @@ #include #include #include +#include #include +#include +#define SOBJB_EE_MAGIC 0x50b0d0ee + +static int sysmocom_odu_eth_init(void) +{ + struct i2c_adapter *adapter; + struct i2c_client client; + uint32_t magic; + char mac[6]; + int ret, ix; + + adapter = i2c_get_adapter(0); + if (!adapter) { + pr_err("[ODU] Failed to obtain I2C adapter 0 reference\n"); + return -4; + } + client.addr = 0x50; + client.adapter = adapter; + + ret = i2c_read_reg(&client, 0, (uint8_t *)&magic, sizeof(magic)); + if (ret != sizeof(magic)) { + pr_err("[ODU] Reading %d instead of %u\n", ret, sizeof(magic)); + return -1; + } + + if (magic != SOBJB_EE_MAGIC) { + pr_err("[ODU] Wrong magic (0x%08x != 0x%08x\n", magic, SOBJB_EE_MAGIC); + return -2; + } + + for (ix = 0; ix < 2; ix++) { + int mac_offset; + + /* offsetof(sob_odu_eeprom, mac_eth0) = 24 */ + mac_offset = 24 + (sizeof(mac) * ix); + ret = i2c_read_reg(&client, mac_offset, mac, sizeof(mac)); + if (ret != sizeof(mac)) { + pr_err("[ODU] Failed to read MAC address\n"); + return -3; + } else { + pr_err("[ODU] Registering EEPROM MAC address\n"); + eth_register_ethaddr(ix, mac); + } + } + + return 0; +} static int pcm051_coredevice_init(void) { if (!of_machine_is_compatible("phytec,pcm051")) return 0; - am33xx_register_ethaddr(0, 0); return 0; } coredevice_initcall(pcm051_coredevice_init); @@ -61,6 +109,10 @@ static int pcm051_devices_init(void) if (!of_machine_is_compatible("phytec,pcm051")) return 0; + /* First try to retrieve MAC address from SOB-ODU (>= v3) EEPROM */ + if (sysmocom_odu_eth_init() < 0) + am33xx_register_ethaddr(0, 0); + switch (bootsource_get()) { case BOOTSOURCE_SPI: of_device_enable_path("/chosen/environment-spi");