Skip to content

Commit 1827b06

Browse files
Phil Elwelldavem330
authored andcommitted
lan78xx: Read LED states from Device Tree
Add support for DT property "microchip,led-modes", a vector of zero to four cells (u32s) in the range 0-15, each of which sets the mode for one of the LEDs. Some possible values are: 0=link/activity 1=link1000/activity 2=link100/activity 3=link10/activity 4=link100/1000/activity 5=link10/1000/activity 6=link10/100/activity 14=off 15=on These values are given symbolic constants in a dt-bindings header. Also use the presence of the DT property to indicate that the LEDs should be enabled - necessary in the event that no valid OTP or EEPROM is available. Signed-off-by: Phil Elwell <phil@raspberrypi.org> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 760db29 commit 1827b06

File tree

5 files changed

+81
-1
lines changed

5 files changed

+81
-1
lines changed

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14572,6 +14572,7 @@ M: Microchip Linux Driver Support <UNGLinuxDriver@microchip.com>
1457214572
L: netdev@vger.kernel.org
1457314573
S: Maintained
1457414574
F: drivers/net/usb/lan78xx.*
14575+
F: include/dt-bindings/net/microchip-lan78xx.h
1457514576

1457614577
USB MASS STORAGE DRIVER
1457714578
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: 31 additions & 1 deletion
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_mdio.h>
4041
#include <linux/of_net.h>
4142
#include "lan78xx.h"
4243

@@ -1760,6 +1761,7 @@ static int lan78xx_mdiobus_write(struct mii_bus *bus, int phy_id, int idx,
17601761

17611762
static int lan78xx_mdio_init(struct lan78xx_net *dev)
17621763
{
1764+
struct device_node *node;
17631765
int ret;
17641766

17651767
dev->mdiobus = mdiobus_alloc();
@@ -1788,7 +1790,13 @@ static int lan78xx_mdio_init(struct lan78xx_net *dev)
17881790
break;
17891791
}
17901792

1791-
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+
}
17921800
if (ret) {
17931801
netdev_err(dev->net, "can't register MDIO bus\n");
17941802
goto exit1;
@@ -2077,6 +2085,28 @@ static int lan78xx_phy_init(struct lan78xx_net *dev)
20772085
mii_adv = (u32)mii_advertise_flowctrl(dev->fc_request_control);
20782086
phydev->advertising |= mii_adv_to_ethtool_adv_t(mii_adv);
20792087

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+
20802110
genphy_config_aneg(phydev);
20812111

20822112
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)