lan78xx: Read MAC address from DT if present
authorPhil Elwell <phil@raspberrypi.org>
Fri, 21 Jul 2017 10:30:18 +0000 (11:30 +0100)
committerRaspbian kernel package updater <root@raspbian.org>
Sat, 31 Mar 2018 14:57:25 +0000 (15:57 +0100)
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 <phil@raspberrypi.org>
drivers/net/usb/lan78xx.c

index c53385a0052f1229b6d8b8ad64d179816e915fc7..aac8f206908797bfdd781ae9b14ba8f03afcb75a 100644 (file)
@@ -31,6 +31,7 @@
 #include <linux/mdio.h>
 #include <net/ip6_checksum.h>
 #include <linux/microchipphy.h>
+#include <linux/of_net.h>
 #include "lan78xx.h"
 
 #define DRIVER_AUTHOR  "WOOJUNG HUH <woojung.huh@microchip.com>"
@@ -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);