From: Phil Elwell Date: Fri, 21 Jul 2017 10:30:18 +0000 (+0100) Subject: lan78xx: Read MAC address from DT if present X-Git-Tag: archive/raspbian/4.9.80-2+rpi1~5^2~48 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=c452a1a795dcafca3502ec602d5e15bf373f3a69;p=linux-4.9.git 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 --- 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);