Skip to content

Commit 0a8b275

Browse files
committed
Merge branch 'lan78xx-Read-configuration-from-Device-Tree'
Phil Elwell says: ==================== lan78xx: Read configuration from Device Tree The Microchip LAN78XX family of devices are Ethernet controllers with a USB interface. Despite being discoverable devices it can be useful to be able to configure them from Device Tree, particularly in low-cost applications without an EEPROM or programmed OTP. This patch set adds support for reading the MAC address and LED modes from Device Tree. v4: - Rename nodes in bindings doc. v3: - Move LED setting into PHY driver. v2: - Use eth_platform_get_mac_address. - Support up to 4 LEDs, and move LED mode constants into dt-bindings header. - Improve bindings document. - Remove EEE support. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents a83762d + 01d2658 commit 0a8b275

File tree

6 files changed

+156
-23
lines changed

6 files changed

+156
-23
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
Microchip LAN78xx Gigabit Ethernet controller
2+
3+
The LAN78XX devices are usually configured by programming their OTP or with
4+
an external EEPROM, but some platforms (e.g. Raspberry Pi 3 B+) have neither.
5+
The Device Tree properties, if present, override the OTP and EEPROM.
6+
7+
Required properties:
8+
- compatible: Should be one of "usb424,7800", "usb424,7801" or "usb424,7850".
9+
10+
Optional properties:
11+
- local-mac-address: see ethernet.txt
12+
- mac-address: see ethernet.txt
13+
14+
Optional properties of the embedded PHY:
15+
- microchip,led-modes: a 0..4 element vector, with each element configuring
16+
the operating mode of an LED. Omitted LEDs are turned off. Allowed values
17+
are defined in "include/dt-bindings/net/microchip-lan78xx.h".
18+
19+
Example:
20+
21+
/* Based on the configuration for a Raspberry Pi 3 B+ */
22+
&usb {
23+
usb-port@1 {
24+
compatible = "usb424,2514";
25+
reg = <1>;
26+
#address-cells = <1>;
27+
#size-cells = <0>;
28+
29+
usb-port@1 {
30+
compatible = "usb424,2514";
31+
reg = <1>;
32+
#address-cells = <1>;
33+
#size-cells = <0>;
34+
35+
ethernet: ethernet@1 {
36+
compatible = "usb424,7800";
37+
reg = <1>;
38+
local-mac-address = [ 00 11 22 33 44 55 ];
39+
40+
mdio {
41+
#address-cells = <0x1>;
42+
#size-cells = <0x0>;
43+
eth_phy: ethernet-phy@1 {
44+
reg = <1>;
45+
microchip,led-modes = <
46+
LAN78XX_LINK_1000_ACTIVITY
47+
LAN78XX_LINK_10_100_ACTIVITY
48+
>;
49+
};
50+
};
51+
};
52+
};
53+
};
54+
};

MAINTAINERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14571,7 +14571,9 @@ M: Woojung Huh <woojung.huh@microchip.com>
1457114571
M: Microchip Linux Driver Support <UNGLinuxDriver@microchip.com>
1457214572
L: netdev@vger.kernel.org
1457314573
S: Maintained
14574+
F: Documentation/devicetree/bindings/net/microchip,lan78xx.txt
1457414575
F: drivers/net/usb/lan78xx.*
14576+
F: include/dt-bindings/net/microchip-lan78xx.h
1457514577

1457614578
USB MASS STORAGE DRIVER
1457714579
M: Alan Stern <stern@rowland.harvard.edu>

drivers/net/phy/microchip.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include <linux/ethtool.h>
2121
#include <linux/phy.h>
2222
#include <linux/microchipphy.h>
23+
#include <linux/of.h>
24+
#include <dt-bindings/net/microchip-lan78xx.h>
2325

2426
#define DRIVER_AUTHOR "WOOJUNG HUH <woojung.huh@microchip.com>"
2527
#define DRIVER_DESC "Microchip LAN88XX PHY driver"
@@ -70,13 +72,36 @@ static int lan88xx_probe(struct phy_device *phydev)
7072
{
7173
struct device *dev = &phydev->mdio.dev;
7274
struct lan88xx_priv *priv;
75+
u32 led_modes[4];
76+
int len;
7377

7478
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
7579
if (!priv)
7680
return -ENOMEM;
7781

7882
priv->wolopts = 0;
7983

84+
len = of_property_read_variable_u32_array(dev->of_node,
85+
"microchip,led-modes",
86+
led_modes,
87+
0,
88+
ARRAY_SIZE(led_modes));
89+
if (len >= 0) {
90+
u32 reg = 0;
91+
int i;
92+
93+
for (i = 0; i < len; i++) {
94+
if (led_modes[i] > 15)
95+
return -EINVAL;
96+
reg |= led_modes[i] << (i * 4);
97+
}
98+
for (; i < ARRAY_SIZE(led_modes); i++)
99+
reg |= LAN78XX_FORCE_LED_OFF << (i * 4);
100+
(void)phy_write(phydev, LAN78XX_PHY_LED_MODE_SELECT, reg);
101+
} else if (len == -EOVERFLOW) {
102+
return -EINVAL;
103+
}
104+
80105
/* these values can be used to identify internal PHY */
81106
priv->chip_id = phy_read_mmd(phydev, 3, LAN88XX_MMD3_CHIP_ID);
82107
priv->chip_rev = phy_read_mmd(phydev, 3, LAN88XX_MMD3_CHIP_REV);

drivers/net/usb/lan78xx.c

Lines changed: 51 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
#include <linux/irqchip/chained_irq.h>
3838
#include <linux/microchipphy.h>
3939
#include <linux/phy.h>
40+
#include <linux/of_mdio.h>
41+
#include <linux/of_net.h>
4042
#include "lan78xx.h"
4143

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

16541656
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);
1657+
if (!eth_platform_get_mac_address(&dev->udev->dev, addr)) {
1658+
/* valid address present in Device Tree */
1659+
netif_dbg(dev, ifup, dev->net,
1660+
"MAC address read from Device Tree");
1661+
} else if (((lan78xx_read_eeprom(dev, EEPROM_MAC_OFFSET,
1662+
ETH_ALEN, addr) == 0) ||
1663+
(lan78xx_read_otp(dev, EEPROM_MAC_OFFSET,
1664+
ETH_ALEN, addr) == 0)) &&
1665+
is_valid_ether_addr(addr)) {
1666+
/* eeprom values are valid so use them */
1667+
netif_dbg(dev, ifup, dev->net,
1668+
"MAC address read from EEPROM");
16771669
} else {
16781670
/* generate random MAC */
16791671
random_ether_addr(addr);
16801672
netif_dbg(dev, ifup, dev->net,
16811673
"MAC address set to random addr");
16821674
}
1675+
1676+
addr_lo = addr[0] | (addr[1] << 8) |
1677+
(addr[2] << 16) | (addr[3] << 24);
1678+
addr_hi = addr[4] | (addr[5] << 8);
1679+
1680+
ret = lan78xx_write_reg(dev, RX_ADDRL, addr_lo);
1681+
ret = lan78xx_write_reg(dev, RX_ADDRH, addr_hi);
16831682
}
16841683

16851684
ret = lan78xx_write_reg(dev, MAF_LO(0), addr_lo);
@@ -1762,6 +1761,7 @@ static int lan78xx_mdiobus_write(struct mii_bus *bus, int phy_id, int idx,
17621761

17631762
static int lan78xx_mdio_init(struct lan78xx_net *dev)
17641763
{
1764+
struct device_node *node;
17651765
int ret;
17661766

17671767
dev->mdiobus = mdiobus_alloc();
@@ -1790,7 +1790,13 @@ static int lan78xx_mdio_init(struct lan78xx_net *dev)
17901790
break;
17911791
}
17921792

1793-
ret = mdiobus_register(dev->mdiobus);
1793+
node = of_get_child_by_name(dev->udev->dev.of_node, "mdio");
1794+
if (node) {
1795+
ret = of_mdiobus_register(dev->mdiobus, node);
1796+
of_node_put(node);
1797+
} else {
1798+
ret = mdiobus_register(dev->mdiobus);
1799+
}
17941800
if (ret) {
17951801
netdev_err(dev->net, "can't register MDIO bus\n");
17961802
goto exit1;
@@ -2079,6 +2085,28 @@ static int lan78xx_phy_init(struct lan78xx_net *dev)
20792085
mii_adv = (u32)mii_advertise_flowctrl(dev->fc_request_control);
20802086
phydev->advertising |= mii_adv_to_ethtool_adv_t(mii_adv);
20812087

2088+
if (phydev->mdio.dev.of_node) {
2089+
u32 reg;
2090+
int len;
2091+
2092+
len = of_property_count_elems_of_size(phydev->mdio.dev.of_node,
2093+
"microchip,led-modes",
2094+
sizeof(u32));
2095+
if (len >= 0) {
2096+
/* Ensure the appropriate LEDs are enabled */
2097+
lan78xx_read_reg(dev, HW_CFG, &reg);
2098+
reg &= ~(HW_CFG_LED0_EN_ |
2099+
HW_CFG_LED1_EN_ |
2100+
HW_CFG_LED2_EN_ |
2101+
HW_CFG_LED3_EN_);
2102+
reg |= (len > 0) * HW_CFG_LED0_EN_ |
2103+
(len > 1) * HW_CFG_LED1_EN_ |
2104+
(len > 2) * HW_CFG_LED2_EN_ |
2105+
(len > 3) * HW_CFG_LED3_EN_;
2106+
lan78xx_write_reg(dev, HW_CFG, reg);
2107+
}
2108+
}
2109+
20822110
genphy_config_aneg(phydev);
20832111

20842112
dev->fc_autoneg = phydev->autoneg;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef _DT_BINDINGS_MICROCHIP_LAN78XX_H
3+
#define _DT_BINDINGS_MICROCHIP_LAN78XX_H
4+
5+
/* LED modes for LAN7800/LAN7850 embedded PHY */
6+
7+
#define LAN78XX_LINK_ACTIVITY 0
8+
#define LAN78XX_LINK_1000_ACTIVITY 1
9+
#define LAN78XX_LINK_100_ACTIVITY 2
10+
#define LAN78XX_LINK_10_ACTIVITY 3
11+
#define LAN78XX_LINK_100_1000_ACTIVITY 4
12+
#define LAN78XX_LINK_10_1000_ACTIVITY 5
13+
#define LAN78XX_LINK_10_100_ACTIVITY 6
14+
#define LAN78XX_DUPLEX_COLLISION 8
15+
#define LAN78XX_COLLISION 9
16+
#define LAN78XX_ACTIVITY 10
17+
#define LAN78XX_AUTONEG_FAULT 12
18+
#define LAN78XX_FORCE_LED_OFF 14
19+
#define LAN78XX_FORCE_LED_ON 15
20+
21+
#endif

include/linux/microchipphy.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,7 @@
7070
#define LAN88XX_MMD3_CHIP_ID (32877)
7171
#define LAN88XX_MMD3_CHIP_REV (32878)
7272

73+
/* Registers specific to the LAN7800/LAN7850 embedded phy */
74+
#define LAN78XX_PHY_LED_MODE_SELECT (0x1D)
75+
7376
#endif /* _MICROCHIPPHY_H */

0 commit comments

Comments
 (0)