From 113ff3a3fc4da01dd17030d38171e5ed11b07ea8 Mon Sep 17 00:00:00 2001 From: Phil Elwell Date: Fri, 21 Jul 2017 11:30:18 +0100 Subject: [PATCH] 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. Signed-off-by: Phil Elwell --- drivers/net/usb/lan78xx.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c index c53385a0052f..aac8f2069087 100644 --- a/drivers/net/usb/lan78xx.c +++ b/drivers/net/usb/lan78xx.c @@ -31,6 +31,7 @@ #include #include #include +#include #include "lan78xx.h" #define DRIVER_AUTHOR "WOOJUNG HUH " @@ -1638,6 +1639,14 @@ static void lan78xx_init_mac_address(struct lan78xx_net *dev) u32 addr_lo, addr_hi; int ret; u8 addr[6]; + const u8 *mac_addr; + + /* maybe the boot loader passed the MAC address in devicetree */ + mac_addr = of_get_mac_address(dev->udev->dev.of_node); + if (mac_addr) { + ether_addr_copy(addr, mac_addr); + goto set_mac_addr; + } ret = lan78xx_read_reg(dev, RX_ADDRL, &addr_lo); ret = lan78xx_read_reg(dev, RX_ADDRH, &addr_hi); @@ -1666,6 +1675,7 @@ static void lan78xx_init_mac_address(struct lan78xx_net *dev) "MAC address set to random addr"); } +set_mac_addr: addr_lo = addr[0] | (addr[1] << 8) | (addr[2] << 16) | (addr[3] << 24); addr_hi = addr[4] | (addr[5] << 8); -- 2.30.2