diff options
author | Eugen Hristev <eugen.hristev@microchip.com> | 2020-08-05 15:30:34 +0300 |
---|---|---|
committer | Eugen Hristev <eugen.hristev@microchip.com> | 2020-09-22 11:27:18 +0300 |
commit | 68d3ec599edff1c7ead539820efbc2234fb965ed (patch) | |
tree | 29dd14bfced7f9d20926637d5cbe3948b1246584 /board/atmel/common | |
parent | 6a6fe3ed4d80afba7efc65a87aca5344672768c5 (diff) | |
download | u-boot-68d3ec599edff1c7ead539820efbc2234fb965ed.tar.xz |
board: atmel: common: introduce at91_set_eth1addr for second interface
We already have a function to retrieve the mac address from one EEPROM.
For boards with a second Ethernet interface, however, we would
require another EEPROM with a second unique MAC address.
Introduce at91_set_eth1addr which will look for a second EEPROM
and set the 'eth1addr' variable with the obtained MAC address.
Signed-off-by: Eugen Hristev <eugen.hristev@microchip.com>
Diffstat (limited to 'board/atmel/common')
-rw-r--r-- | board/atmel/common/mac_eeprom.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/board/atmel/common/mac_eeprom.c b/board/atmel/common/mac_eeprom.c index 2205dd30f8..a723ba723c 100644 --- a/board/atmel/common/mac_eeprom.c +++ b/board/atmel/common/mac_eeprom.c @@ -36,3 +36,36 @@ int at91_set_ethaddr(int offset) return 0; } + +/* this function will set eth1addr from a second eeprom, if available */ +int at91_set_eth1addr(int offset) +{ + const int ETH_ADDR_LEN = 6; + unsigned char ethaddr[ETH_ADDR_LEN]; + /* configure eth1addr for second interface */ + const char *ETHADDR_NAME = "eth1addr"; + struct udevice *dev; + int ret; + + if (env_get(ETHADDR_NAME)) + return 0; + + /* first eeprom is retrieved, this is for the first interface */ + ret = uclass_first_device_err(UCLASS_I2C_EEPROM, &dev); + if (ret) + return ret; + + /* attempt to obtain a second eeprom device */ + ret = uclass_next_device(&dev); + if (ret) + return ret; + + ret = i2c_eeprom_read(dev, offset, ethaddr, 6); + if (ret) + return ret; + + if (is_valid_ethaddr(ethaddr)) + eth_env_set_enetaddr(ETHADDR_NAME, ethaddr); + + return 0; +} |