Skip to content

Commit 760db29

Browse files
Phil Elwelldavem330
authored andcommitted
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. At the same time, regularise the handling of the different address sources. Signed-off-by: Phil Elwell <phil@raspberrypi.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent a83762d commit 760db29

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

drivers/net/usb/lan78xx.c

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <linux/irqchip/chained_irq.h>
3838
#include <linux/microchipphy.h>
3939
#include <linux/phy.h>
40+
#include <linux/of_net.h>
4041
#include "lan78xx.h"
4142

4243
#define DRIVER_AUTHOR "WOOJUNG HUH <woojung.huh@microchip.com>"
@@ -1652,34 +1653,31 @@ static void lan78xx_init_mac_address(struct lan78xx_net *dev)
16521653
addr[5] = (addr_hi >> 8) & 0xFF;
16531654

16541655
if (!is_valid_ether_addr(addr)) {
1655-
/* reading mac address from EEPROM or OTP */
1656-
if ((lan78xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
1657-
addr) == 0) ||
1658-
(lan78xx_read_otp(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
1659-
addr) == 0)) {
1660-
if (is_valid_ether_addr(addr)) {
1661-
/* eeprom values are valid so use them */
1662-
netif_dbg(dev, ifup, dev->net,
1663-
"MAC address read from EEPROM");
1664-
} else {
1665-
/* generate random MAC */
1666-
random_ether_addr(addr);
1667-
netif_dbg(dev, ifup, dev->net,
1668-
"MAC address set to random addr");
1669-
}
1670-
1671-
addr_lo = addr[0] | (addr[1] << 8) |
1672-
(addr[2] << 16) | (addr[3] << 24);
1673-
addr_hi = addr[4] | (addr[5] << 8);
1674-
1675-
ret = lan78xx_write_reg(dev, RX_ADDRL, addr_lo);
1676-
ret = lan78xx_write_reg(dev, RX_ADDRH, addr_hi);
1656+
if (!eth_platform_get_mac_address(&dev->udev->dev, addr)) {
1657+
/* valid address present in Device Tree */
1658+
netif_dbg(dev, ifup, dev->net,
1659+
"MAC address read from Device Tree");
1660+
} else if (((lan78xx_read_eeprom(dev, EEPROM_MAC_OFFSET,
1661+
ETH_ALEN, addr) == 0) ||
1662+
(lan78xx_read_otp(dev, EEPROM_MAC_OFFSET,
1663+
ETH_ALEN, addr) == 0)) &&
1664+
is_valid_ether_addr(addr)) {
1665+
/* eeprom values are valid so use them */
1666+
netif_dbg(dev, ifup, dev->net,
1667+
"MAC address read from EEPROM");
16771668
} else {
16781669
/* generate random MAC */
16791670
random_ether_addr(addr);
16801671
netif_dbg(dev, ifup, dev->net,
16811672
"MAC address set to random addr");
16821673
}
1674+
1675+
addr_lo = addr[0] | (addr[1] << 8) |
1676+
(addr[2] << 16) | (addr[3] << 24);
1677+
addr_hi = addr[4] | (addr[5] << 8);
1678+
1679+
ret = lan78xx_write_reg(dev, RX_ADDRL, addr_lo);
1680+
ret = lan78xx_write_reg(dev, RX_ADDRH, addr_hi);
16831681
}
16841682

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

0 commit comments

Comments
 (0)