494688d
From 6ed88d188a8240ba44da6578eab7d17e036d0e61 Mon Sep 17 00:00:00 2001
494688d
From: Phil Elwell <phil@raspberrypi.org>
494688d
Date: Tue, 17 Oct 2017 15:04:29 +0100
494688d
Subject: [PATCH] lan78xx: Enable LEDs if no valid EEPROM or OTP
494688d
494688d
For applications of the LAN78xx that don't have valid programmed
494688d
EEPROMs or OTPs, enabling both LEDs by default seems reasonable.
494688d
494688d
Signed-off-by: Phil Elwell <phil@raspberrypi.org>
494688d
---
494688d
 drivers/net/usb/lan78xx.c | 6 ++++++
494688d
 1 file changed, 6 insertions(+)
494688d
494688d
diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c
494688d
index a21039852f8d..cd20ce4ed87d 100644
494688d
--- a/drivers/net/usb/lan78xx.c
494688d
+++ b/drivers/net/usb/lan78xx.c
494688d
@@ -2414,6 +2414,12 @@ static int lan78xx_reset(struct lan78xx_net *dev)
494688d
 
494688d
 	ret = lan78xx_read_reg(dev, HW_CFG, &buf;;
494688d
 	buf |= HW_CFG_MEF_;
494688d
+
494688d
+	/* If no valid EEPROM and no valid OTP, enable the LEDs by default */
494688d
+	if (lan78xx_read_eeprom(dev, 0, 0, NULL) &&
494688d
+	    lan78xx_read_otp(dev, 0, 0, NULL))
494688d
+	    buf |= HW_CFG_LED0_EN_ | HW_CFG_LED1_EN_;
494688d
+
494688d
 	ret = lan78xx_write_reg(dev, HW_CFG, buf);
494688d
 
494688d
 	ret = lan78xx_read_reg(dev, USB_CFG0, &buf;;
494688d
From 4a4710f3847cd087e150f83382dffd92e09d9914 Mon Sep 17 00:00:00 2001
494688d
From: Phil Elwell <phil@raspberrypi.org>
494688d
Date: Sat, 17 Mar 2018 00:10:02 +0100
494688d
Subject: [PATCH] lan78xx: Read MAC address from DT if present
494688d
494688d
There is a standard mechanism for locating and using a MAC address from
494688d
the Device Tree. Use this facility in the lan78xx driver to support
494688d
applications without programmed EEPROM or OTP.
494688d
494688d
Signed-off-by: Phil Elwell <phil@raspberrypi.org>
494688d
---
494688d
 drivers/net/usb/lan78xx.c | 10 ++++++++++
494688d
 1 file changed, 10 insertions(+)
494688d
494688d
diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c
494688d
index 60a604cc7647..a21039852f8d 100644
494688d
--- a/drivers/net/usb/lan78xx.c
494688d
+++ b/drivers/net/usb/lan78xx.c
494688d
@@ -36,6 +36,7 @@
494688d
 #include <linux/irq.h>
494688d
 #include <linux/irqchip/chained_irq.h>
494688d
 #include <linux/microchipphy.h>
494688d
+#include <linux/of_net.h>
494688d
 #include <linux/phy.h>
494688d
 #include "lan78xx.h"
494688d
 
494688d
@@ -1639,6 +1640,14 @@ static void lan78xx_init_mac_address(struct lan78xx_net *dev)
494688d
 	u32 addr_lo, addr_hi;
494688d
 	int ret;
494688d
 	u8 addr[6];
494688d
+	const u8 *mac_addr;
494688d
+
494688d
+	/* maybe the boot loader passed the MAC address in devicetree */
494688d
+	mac_addr = of_get_mac_address(dev->udev->dev.of_node);
494688d
+	if (mac_addr) {
494688d
+		ether_addr_copy(addr, mac_addr);
494688d
+		goto set_mac_addr;
494688d
+	}
494688d
 
494688d
 	ret = lan78xx_read_reg(dev, RX_ADDRL, &addr_lo);
494688d
 	ret = lan78xx_read_reg(dev, RX_ADDRH, &addr_hi);
494688d
@@ -1667,6 +1676,7 @@ static void lan78xx_init_mac_address(struct lan78xx_net *dev)
494688d
 					  "MAC address set to random addr");
494688d
 			}
494688d
 
494688d
+set_mac_addr:
494688d
 			addr_lo = addr[0] | (addr[1] << 8) |
494688d
 				  (addr[2] << 16) | (addr[3] << 24);
494688d
 			addr_hi = addr[4] | (addr[5] << 8);