9
0
Fork 0

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 :(
This commit is contained in:
Harald Welte 2014-12-19 05:26:45 +01:00
parent 9bd8556fcf
commit b1aa3382bc
1 changed files with 53 additions and 1 deletions

View File

@ -22,6 +22,7 @@
#include <nand.h>
#include <init.h>
#include <io.h>
#include <net.h>
#include <sizes.h>
#include <envfs.h>
#include <asm/armlinux.h>
@ -29,15 +30,62 @@
#include <linux/phy.h>
#include <mach/am33xx-generic.h>
#include <mach/am33xx-silicon.h>
#include <mach/am33xx-devices.h>
#include <mach/bbu.h>
#include <i2c/i2c.h>
#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");