diff options
author | Roger Quadros <rogerq@ti.com> | 2016-03-18 13:18:12 +0200 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2016-03-27 09:12:27 -0400 |
commit | 92667e89fc5906531a7a1ff247e1ffec61b55b13 (patch) | |
tree | 7f8ed4dd50565e74595c9faf8a402cd6f6fdfd8c | |
parent | 5350bc8f65a96d7f3c2519ae2d76cafea875103a (diff) | |
download | u-boot-imx-92667e89fc5906531a7a1ff247e1ffec61b55b13.zip u-boot-imx-92667e89fc5906531a7a1ff247e1ffec61b55b13.tar.gz u-boot-imx-92667e89fc5906531a7a1ff247e1ffec61b55b13.tar.bz2 |
board: ti: am57xx: Set ethernet MAC addresses from EEPROM to env
The MAC addresses for the PRU Ethernet ports will be available in the
board EEPROM as an address range. Populate those MAC addresses (if valid)
into the u-boot environment so that they can be passed on to the
device tree during fdt_fixup_ethernet().
Signed-off-by: Roger Quadros <rogerq@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
-rw-r--r-- | board/ti/am57xx/board.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/board/ti/am57xx/board.c b/board/ti/am57xx/board.c index 67191af..18416ef 100644 --- a/board/ti/am57xx/board.c +++ b/board/ti/am57xx/board.c @@ -537,12 +537,39 @@ static struct cpsw_platform_data cpsw_data = { .version = CPSW_CTRL_VERSION_2, }; +static u64 mac_to_u64(u8 mac[6]) +{ + int i; + u64 addr = 0; + + for (i = 0; i < 6; i++) { + addr <<= 8; + addr |= mac[i]; + } + + return addr; +} + +static void u64_to_mac(u64 addr, u8 mac[6]) +{ + mac[5] = addr; + mac[4] = addr >> 8; + mac[3] = addr >> 16; + mac[2] = addr >> 24; + mac[1] = addr >> 32; + mac[0] = addr >> 40; +} + int board_eth_init(bd_t *bis) { int ret; uint8_t mac_addr[6]; uint32_t mac_hi, mac_lo; uint32_t ctrl_val; + int i; + u64 mac1, mac2; + u8 mac_addr1[6], mac_addr2[6]; + int num_macs; /* try reading mac address from efuse */ mac_lo = readl((*ctrl)->control_core_mac_id_0_lo); @@ -583,6 +610,32 @@ int board_eth_init(bd_t *bis) if (ret < 0) printf("Error %d registering CPSW switch\n", ret); + /* + * Export any Ethernet MAC addresses from EEPROM. + * On AM57xx the 2 MAC addresses define the address range + */ + board_ti_get_eth_mac_addr(0, mac_addr1); + board_ti_get_eth_mac_addr(1, mac_addr2); + + if (is_valid_ethaddr(mac_addr1) && is_valid_ethaddr(mac_addr2)) { + mac1 = mac_to_u64(mac_addr1); + mac2 = mac_to_u64(mac_addr2); + + /* must contain an address range */ + num_macs = mac2 - mac1 + 1; + /* <= 50 to protect against user programming error */ + if (num_macs > 0 && num_macs <= 50) { + for (i = 0; i < num_macs; i++) { + u64_to_mac(mac1 + i, mac_addr); + if (is_valid_ethaddr(mac_addr)) { + eth_setenv_enetaddr_by_index("eth", + i + 2, + mac_addr); + } + } + } + } + return ret; } #endif |