Commit 760db29b authored by Phil Elwell's avatar Phil Elwell Committed by David S. Miller

lan78xx: Read MAC address from DT if present

There is a standard mechanism for locating and using a MAC address from
the Device Tree. Use this facility in the lan78xx driver to support
applications without programmed EEPROM or OTP. At the same time,
regularise the handling of the different address sources.
Signed-off-by: default avatarPhil Elwell <phil@raspberrypi.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent a83762d9
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include <linux/irqchip/chained_irq.h> #include <linux/irqchip/chained_irq.h>
#include <linux/microchipphy.h> #include <linux/microchipphy.h>
#include <linux/phy.h> #include <linux/phy.h>
#include <linux/of_net.h>
#include "lan78xx.h" #include "lan78xx.h"
#define DRIVER_AUTHOR "WOOJUNG HUH <woojung.huh@microchip.com>" #define DRIVER_AUTHOR "WOOJUNG HUH <woojung.huh@microchip.com>"
...@@ -1652,34 +1653,31 @@ static void lan78xx_init_mac_address(struct lan78xx_net *dev) ...@@ -1652,34 +1653,31 @@ static void lan78xx_init_mac_address(struct lan78xx_net *dev)
addr[5] = (addr_hi >> 8) & 0xFF; addr[5] = (addr_hi >> 8) & 0xFF;
if (!is_valid_ether_addr(addr)) { if (!is_valid_ether_addr(addr)) {
/* reading mac address from EEPROM or OTP */ if (!eth_platform_get_mac_address(&dev->udev->dev, addr)) {
if ((lan78xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN, /* valid address present in Device Tree */
addr) == 0) || netif_dbg(dev, ifup, dev->net,
(lan78xx_read_otp(dev, EEPROM_MAC_OFFSET, ETH_ALEN, "MAC address read from Device Tree");
addr) == 0)) { } else if (((lan78xx_read_eeprom(dev, EEPROM_MAC_OFFSET,
if (is_valid_ether_addr(addr)) { ETH_ALEN, addr) == 0) ||
/* eeprom values are valid so use them */ (lan78xx_read_otp(dev, EEPROM_MAC_OFFSET,
netif_dbg(dev, ifup, dev->net, ETH_ALEN, addr) == 0)) &&
"MAC address read from EEPROM"); is_valid_ether_addr(addr)) {
} else { /* eeprom values are valid so use them */
/* generate random MAC */ netif_dbg(dev, ifup, dev->net,
random_ether_addr(addr); "MAC address read from EEPROM");
netif_dbg(dev, ifup, dev->net,
"MAC address set to random addr");
}
addr_lo = addr[0] | (addr[1] << 8) |
(addr[2] << 16) | (addr[3] << 24);
addr_hi = addr[4] | (addr[5] << 8);
ret = lan78xx_write_reg(dev, RX_ADDRL, addr_lo);
ret = lan78xx_write_reg(dev, RX_ADDRH, addr_hi);
} else { } else {
/* generate random MAC */ /* generate random MAC */
random_ether_addr(addr); random_ether_addr(addr);
netif_dbg(dev, ifup, dev->net, netif_dbg(dev, ifup, dev->net,
"MAC address set to random addr"); "MAC address set to random addr");
} }
addr_lo = addr[0] | (addr[1] << 8) |
(addr[2] << 16) | (addr[3] << 24);
addr_hi = addr[4] | (addr[5] << 8);
ret = lan78xx_write_reg(dev, RX_ADDRL, addr_lo);
ret = lan78xx_write_reg(dev, RX_ADDRH, addr_hi);
} }
ret = lan78xx_write_reg(dev, MAF_LO(0), addr_lo); ret = lan78xx_write_reg(dev, MAF_LO(0), addr_lo);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment