Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a4977f3e authored by Phil Elwell's avatar Phil Elwell Committed by Greg Kroah-Hartman
Browse files

lan78xx: Read MAC address from DT if present



commit 760db29bdc97b73ff60b091315ad787b1deb5cf5 upstream.

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>
Tested-by: default avatarPaolo Pisati <p.pisati@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 7bcfd8f9
Loading
Loading
Loading
Loading
+20 −22
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@
#include <linux/irqchip/chained_irq.h>
#include <linux/microchipphy.h>
#include <linux/phy.h>
#include <linux/of_net.h>
#include "lan78xx.h"

#define DRIVER_AUTHOR	"WOOJUNG HUH <woojung.huh@microchip.com>"
@@ -1645,12 +1646,15 @@ static void lan78xx_init_mac_address(struct lan78xx_net *dev)
	addr[5] = (addr_hi >> 8) & 0xFF;

	if (!is_valid_ether_addr(addr)) {
		/* reading mac address from EEPROM or OTP */
		if ((lan78xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
					 addr) == 0) ||
		    (lan78xx_read_otp(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
				      addr) == 0)) {
			if (is_valid_ether_addr(addr)) {
		if (!eth_platform_get_mac_address(&dev->udev->dev, addr)) {
			/* valid address present in Device Tree */
			netif_dbg(dev, ifup, dev->net,
				  "MAC address read from Device Tree");
		} else if (((lan78xx_read_eeprom(dev, EEPROM_MAC_OFFSET,
						 ETH_ALEN, addr) == 0) ||
			    (lan78xx_read_otp(dev, EEPROM_MAC_OFFSET,
					      ETH_ALEN, addr) == 0)) &&
			   is_valid_ether_addr(addr)) {
			/* eeprom values are valid so use them */
			netif_dbg(dev, ifup, dev->net,
				  "MAC address read from EEPROM");
@@ -1667,12 +1671,6 @@ static void lan78xx_init_mac_address(struct lan78xx_net *dev)

		ret = lan78xx_write_reg(dev, RX_ADDRL, addr_lo);
		ret = lan78xx_write_reg(dev, RX_ADDRH, addr_hi);
		} else {
			/* generate random MAC */
			random_ether_addr(addr);
			netif_dbg(dev, ifup, dev->net,
				  "MAC address set to random addr");
		}
	}

	ret = lan78xx_write_reg(dev, MAF_LO(0), addr_lo);