Skip to content

Commit 6c19a4c

Browse files
Phil Elwellpopcornmix
authored andcommitted
net: lan78xx: Support auto-downshift to 100Mb/s
Ethernet cables with faulty or missing pairs (specifically pairs C and D) allow auto-negotiation to 1000Mbs, but do not support the successful establishment of a link. Add a DT property, "microchip,downshift-after", to configure the number of auto-negotiation failures after which it falls back to 100Mbs. Valid values are 2, 3, 4, 5 and 0, where 0 means never downshift. Signed-off-by: Phil Elwell <phil@raspberrypi.org>
1 parent d25459f commit 6c19a4c

3 files changed

Lines changed: 38 additions & 0 deletions

File tree

‎Documentation/devicetree/bindings/net/microchip,lan78xx.txt‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ Optional properties of the embedded PHY:
1414
- microchip,led-modes: a 0..4 element vector, with each element configuring
1515
the operating mode of an LED. Omitted LEDs are turned off. Allowed values
1616
are defined in "include/dt-bindings/net/microchip-lan78xx.h".
17+
- microchip,downshift-after: sets the number of failed auto-negotiation
18+
attempts after which the link is downgraded from 1000BASE-T. Should be one of
19+
2, 3, 4, 5 or 0, where 0 means never downshift.
1720

1821
Example:
1922

‎drivers/net/phy/microchip.c‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ static int lan88xx_probe(struct phy_device *phydev)
217217
struct device *dev = &phydev->mdio.dev;
218218
struct lan88xx_priv *priv;
219219
u32 led_modes[4];
220+
u32 downshift_after = 0;
220221
int len;
221222

222223
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
@@ -246,6 +247,32 @@ static int lan88xx_probe(struct phy_device *phydev)
246247
return -EINVAL;
247248
}
248249

250+
if (!of_property_read_u32(dev->of_node,
251+
"microchip,downshift-after",
252+
&downshift_after)) {
253+
u32 mask = LAN78XX_PHY_CTRL3_DOWNSHIFT_CTRL_MASK;
254+
u32 val= LAN78XX_PHY_CTRL3_AUTO_DOWNSHIFT;
255+
256+
switch (downshift_after) {
257+
case 2: val |= LAN78XX_PHY_CTRL3_DOWNSHIFT_CTRL_2;
258+
break;
259+
case 3: val |= LAN78XX_PHY_CTRL3_DOWNSHIFT_CTRL_3;
260+
break;
261+
case 4: val |= LAN78XX_PHY_CTRL3_DOWNSHIFT_CTRL_4;
262+
break;
263+
case 5: val |= LAN78XX_PHY_CTRL3_DOWNSHIFT_CTRL_5;
264+
break;
265+
case 0: // Disable completely
266+
mask = LAN78XX_PHY_CTRL3_AUTO_DOWNSHIFT;
267+
val = 0;
268+
break;
269+
default:
270+
return -EINVAL;
271+
}
272+
(void)phy_modify_paged(phydev, 1, LAN78XX_PHY_CTRL3,
273+
mask, val);
274+
}
275+
249276
/* these values can be used to identify internal PHY */
250277
priv->chip_id = phy_read_mmd(phydev, 3, LAN88XX_MMD3_CHIP_ID);
251278
priv->chip_rev = phy_read_mmd(phydev, 3, LAN88XX_MMD3_CHIP_REV);

‎include/linux/microchipphy.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@
6161
/* Registers specific to the LAN7800/LAN7850 embedded phy */
6262
#define LAN78XX_PHY_LED_MODE_SELECT (0x1D)
6363

64+
#define LAN78XX_PHY_CTRL3 (0x14)
65+
#define LAN78XX_PHY_CTRL3_AUTO_DOWNSHIFT (0x0010)
66+
#define LAN78XX_PHY_CTRL3_DOWNSHIFT_CTRL_MASK (0x000c)
67+
#define LAN78XX_PHY_CTRL3_DOWNSHIFT_CTRL_2 (0x0000)
68+
#define LAN78XX_PHY_CTRL3_DOWNSHIFT_CTRL_3 (0x0004)
69+
#define LAN78XX_PHY_CTRL3_DOWNSHIFT_CTRL_4 (0x0008)
70+
#define LAN78XX_PHY_CTRL3_DOWNSHIFT_CTRL_5 (0x000c)
71+
6472
/* DSP registers */
6573
#define PHY_ARDENNES_MMD_DEV_3_PHY_CFG (0x806A)
6674
#define PHY_ARDENNES_MMD_DEV_3_PHY_CFG_ZD_DLY_EN_ (0x2000)

0 commit comments

Comments
 (0)