net: dsa: microchip: add single-led-mode support
Subsystems (5)
cover net: dsa: microchip: add single-led-mode support
This series adds support for single LED mode to KSZ9477 switches.
The first patch adds the YAML device tree binding documentation for the new 'microchip,single-led-mode' property.
The second patch implements the mode configuration in the ksz_common driver, including a necessary hardware workaround for Errata Module 19 (DS80000754F), which requires an additional write to a debug register to ensure proper LED activity.
Heinrich Toews (3):
dt-bindings: net: dsa: microchip: add microchip,single-led-mode flag
net: phy: micrel: add flag for KSZ9477 LED erratum
net: dsa: microchip: add single-led-mode support for KSZ9477
.../bindings/net/dsa/microchip,ksz.yaml | 6 ++++ drivers/net/dsa/microchip/ksz_common.c | 34 +++++++++++++++++++ drivers/net/dsa/microchip/ksz_common.h | 4 +++ include/linux/micrel_phy.h | 1 + 4 files changed, 45 insertions(+)
Signature · 1 line
2.52.0
PATCH 1/3 dt-bindings: net: dsa: microchip: add microchip,single-led-mode flag
Enable single LED mode globally for all non-CPU ports to indicate link and activity via a single LED per port.
--- .../devicetree/bindings/net/dsa/microchip,ksz.yaml | 6 ++++++ 1 file changed, 6 insertions(+)
Documentation/devicetree/bindings/net/dsa/microchip,ksz.yaml +6 -0
@@ -65,6 +65,12 @@ properties: description: Indicates if the PME pin polarity is active-high. + microchip,single-led-mode: + type: boolean + description: + Enable single LED mode for all non-CPU ports. In this mode, a single LED + indicates both link and activity. + microchip,io-drive-strength-microamp: description: IO Pad Drive Strength
Signature · 1 line
2.52.0
Andrew Lunn
maintainerRe: [PATCH v1 1/3] dt-bindings: net: dsa: microchip: add microchip,single-led-mode flag
Quoted 2 lines · Heinrich Toews
Enable single LED mode globally for all non-CPU ports to indicate link and activity via a single LED per port.
Are there other blinking modes? If the LED is capable of more, you should be using /sys/class/leds and the netdev trigger. If the only thing it can indicate is link and activity, this approach is O.K.
Documentation/devicetree/bindings/net/dsa/microchip,ksz.yaml properties: · line 72
Quoted 5 lines
Documentation/devicetree/bindings/net/dsa/microchip,ksz.yaml +5
-0+ microchip,single-led-mode: + type: boolean + description: + Enable single LED mode for all non-CPU ports. In this mode, a single LED + indicates both link and activity.
Is there a dual LED mode? Triple LED mode? What happens if this property is not found?
Andrew
Re: [PATCH v1 1/3] dt-bindings: net: dsa: microchip: add microchip,single-led-mode flag
Hi Andrew,
Am 28.01.26 um 14:59 schrieb Andrew Lunn:
Quoted 3 lines
Are there other blinking modes? If the LED is capable of more, you should be using
/sys/class/ledsand the netdev trigger. If the only thing it can indicate is link and activity, this approach is O.K.
I re-checked the datasheet (DS00002392). The KSZ9477 PHY ports indeed have two pins, but they are not general-purpose. The term "programmable" in the datasheet refers only to switching between two fixed hardware-mapped modes via MMD:
1. Tri-Color Dual-LED Mode (Default): The pins LEDx_1 and LEDx_0 work in conjunction to indicate link speed (10/100/1000) and activity. For example, 10BASE-T status is indicated by both pins working together.
2. Single-LED Mode: Here, the logic is simplified so that LEDx_1 indicates Link and LEDx_0 indicates Activity.
There is no "Manual Mode" or "GPIO Mode" for these pins. They are driven by a fixed internal state machine. Since we cannot control the pins' brightness or trigger events independently from the PHY's hardcoded logic, the netdev trigger or the LED class cannot be used to emulate this behavior.
Quoted 2 lines
Is there a dual LED mode? Triple LED mode? What happens if this property is not found?
If the property is not found, the switch remains in its default "Tri-Color Dual-LED Mode".
I will clarify this in the description for v2.
Thanks,Heinrich.
Andrew Lunn
maintainerRe: [PATCH v1 1/3] dt-bindings: net: dsa: microchip: add microchip,single-led-mode flag
Quoted 4 lines
There is no "Manual Mode" or "GPIO Mode" for these pins. They are driven by a fixed internal state machine. Since we cannot control the pins' brightness or trigger events independently from the PHY's hardcoded logic, the netdev trigger or the LED class cannot be used to emulate this behavior.
Thanks for checking.
Quoted 5 lines
Quoted 2 lines
Is there a dual LED mode? Triple LED mode? What happens if this property is not found?
If the property is not found, the switch remains in its default "Tri-Color Dual-LED Mode".
Is that really true? Generally, what actually happens is the configuration is left alone. So if the boot loader, for example, has set the configuration, that configuration is left unchanged. So it could actually be in single LED mode, not tri-colour.
Andrew
Re: [PATCH v1 1/3] dt-bindings: net: dsa: microchip: add microchip,single-led-mode flag
Hi Andrew,
Am 28.01.26 um 16:22 schrieb Andrew Lunn:
Quoted 4 lines
Is that really true? Generally, what actually happens is the configuration is left alone. So if the boot loader, for example, has set the configuration, that configuration is left unchanged. So it could actually be in single LED mode, not tri-colour.
Oh, you're right. We cannot assume a hardware reset state here.
Since the driver currently does not touch these registers, the configuration is indeed "inherited" from the bootloader or the hardware strapping.
Thanks,
Heinrich.
Re: [PATCH v1 1/3] dt-bindings: net: dsa: microchip: add microchip,single-led-mode flag
In reply to Heinrich ToewsQuoted 3 lines · Heinrich Toews
Enable single LED mode globally for all non-CPU ports to indicate link and activity via a single LED per port.
Please use get_maintainers.pl and send to the correct lists if you want this reviewed.
Quoted 26 lines
Signed-off-by Heinrich Toews <[email protected]>--- .../devicetree/bindings/net/dsa/microchip,ksz.yaml | 6 ++++++ 1 file changed, 6 insertions(+)Documentation/devicetree/bindings/net/dsa/microchip,ksz.yaml +6
-1@@ -65,6 +65,12 @@ properties: description: Indicates if the PME pin polarity is active-high. + microchip,single-led-mode: + type: boolean + description: + Enable single LED mode for all non-CPU ports. In this mode, a single LED + indicates both link and activity. + microchip,io-drive-strength-microamp: description: IO Pad Drive Strength --2.52.0
Re: [PATCH v1 1/3] dt-bindings: net: dsa: microchip: add microchip,single-led-mode flag
Hi Rob,
Quoted 7 lines · Rob Herring
Quoted 3 lines · Heinrich Toews
Enable single LED mode globally for all non-CPU ports to indicate link and activity via a single LED per port.
Please use get_maintainers.pl and send to the correct lists if you want this reviewed.
Thanks for pointing that out. I will re-run the script and fix the recipient list in v2.
Best regards,
Heinrich.
PATCH 2/3 net: phy: micrel: add flag for KSZ9477 LED erratum
In reply to Heinrich ToewsAdd a new flag MICREL_KSZ9_LED_ERRATA to indicate support for a specific LED erratum workaround on Microchip KSZ9477 switches. This flag will be used by the DSA driver to trigger a hardware-specific register write required for correct LED activity in single-LED mode.
--- include/linux/micrel_phy.h | 1 + 1 file changed, 1 insertion(+)
include/linux/micrel_phy.h +1 -0
@@ -45,6 +45,7 @@#define MICREL_PHY_50MHZ_CLK BIT(0)#define MICREL_PHY_FXEN BIT(1)#define MICREL_KSZ8_P1_ERRATA BIT(2) +#define MICREL_KSZ9_LED_ERRATA BIT(3)#define MICREL_KSZ9021_EXTREG_CTRL 0xB#define MICREL_KSZ9021_EXTREG_DATA_WRITE 0xC
Signature · 1 line
2.52.0
PATCH 3/3 net: dsa: microchip: add single-led-mode support for KSZ9477
In reply to Heinrich ToewsAdd support for single LED mode via the "microchip,single-led-mode" device tree property which will apply the configuration globally on all non-CPU ports.
The implementation includes a workaround for Errata Module 19, requiring a debug register write to ensure proper LED activity. The mode is configured during the MAC link-up phase for non-CPU ports.
--- drivers/net/dsa/microchip/ksz_common.c | 34 ++++++++++++++++++++++++++ drivers/net/dsa/microchip/ksz_common.h | 4 +++ 2 files changed, 38 insertions(+)
drivers/net/dsa/microchip/ksz_common.c +34 -0
@@ -815,6 +815,9 @@ static const u16 ksz9477_regs[] = { [PTP_RTC_SEC] = 0x0508, [PTP_SUBNANOSEC_RATE] = 0x050C, [PTP_MSG_CONF1] = 0x0514, + [P_PHY_MMD_SETUP] = 0x011A, + [P_PHY_MMD_DATA] = 0x011C, + [P_PHY_DIGITAL_DEBUG_3] = 0x013C, };static const u32 ksz9477_masks[] = {
@@ -3241,6 +3244,14 @@ static u32 ksz_get_phy_flags(struct dsa_switch *ds, int port)if (!port)return MICREL_KSZ8_P1_ERRATA ;break ; +case KSZ9477_CHIP_ID : +/* KSZ9477S Errata DS80000754F +* +* Module 19: Single-LED Mode Setting Requires Two Register Writes +* The PHY Port LEDx_0 pin does not go low in the presence of link +* activity when Single-LED Mode is selected in the MMD LED Mode Register. +*/ +return MICREL_KSZ9_LED_ERRATA ; }return 0 ;
@@ -3909,6 +3920,24 @@ static void ksz_set_gbit(struct ksz_device *dev, int port, bool gbit)ksz_pwrite8 (dev, port, regs[P_XMII_CTRL_1 ], data8); } +static void ksz_enable_single_led_mode (struct ksz_device *dev,int port,struct phy_device *phydev) +{ +const u16 *regs = dev->info->regs; + +ksz_pwrite16 (dev, port, regs[P_PHY_MMD_SETUP ],0x0002 );/* Set up register address for MMD */ +ksz_pwrite16 (dev, port, regs[P_PHY_MMD_DATA ],0x0000 );/* Select Register 00h of MMD */ +ksz_pwrite16 (dev, port, regs[P_PHY_MMD_SETUP ],0x4002 );/* Select register data for MMD */ +ksz_pwrite16 (dev, port, regs[P_PHY_MMD_DATA ],0x0011 );/* Write value 0011h to MMD */ + +/* According to KSZ9477S Errata DS80000754F (Module 19) 0xfa00 has to +* be written to the Debug Register 3 to enable Single-LED Mode. +*/ +if (phydev->dev_flags &MICREL_KSZ9_LED_ERRATA ) +ksz_pwrite16 (dev, port, regs[P_PHY_DIGITAL_DEBUG_3 ],0xfa00 ); + +dev_info (dev->dev,"port-%d: single-led mode enabled.\n" , port); +} +static void ksz_set_100_10mbit (struct ksz_device *dev,int port,int speed) {const u8 *bitval = dev->info->xmii_ctrl0;
@@ -3977,6 +4006,9 @@ static void ksz9477_phylink_mac_link_up(struct phylink_config *config,int port = dp->index;struct ksz_port *p; +if (dev->single_led_mode && port != dev->cpu_port) +ksz_enable_single_led_mode (dev, port, phydev); + p = &dev->ports[port];/* Internal PHYs */
@@ -5526,6 +5558,8 @@ int ksz_switch_register(struct ksz_device *dev) "wakeup-source"); dev->pme_active_high =of_property_read_bool (dev->dev->of_node,"microchip,pme-active-high" ); + dev->single_led_mode =of_property_read_bool (dev->dev->of_node, +"microchip,single-led-mode" ); } ret =dsa_register_switch (dev->ds);
drivers/net/dsa/microchip/ksz_common.h +4 -0
@@ -187,6 +187,7 @@ struct ksz_device {bool synclko_disable;bool wakeup_source;bool pme_active_high; +bool single_led_mode;/* Enable Single LED Mode */ struct vlan_table *vlan_cache;
@@ -277,6 +278,9 @@ enum ksz_regs {PTP_RTC_SUB_NANOSEC ,PTP_SUBNANOSEC_RATE ,PTP_MSG_CONF1 , +P_PHY_MMD_SETUP , +P_PHY_MMD_DATA , + P_PHY_DIGITAL_DEBUG_3, }; enum ksz_masks {
Signature · 1 line
2.52.0
Jakub Kicinski
maintainerRe: [v1,3/3] net: dsa: microchip: add single-led-mode support for KSZ9477
This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html
---
net: dsa: microchip: add single-led-mode support for KSZ9477
This patch adds single LED mode support for KSZ9477 via a device tree property. The mode is configured during MAC link-up for non-CPU ports and includes a workaround for Errata Module 19.
Quoted 4 lines
drivers/net/dsa/microchip/ksz_common.c +0
-0
[ ... ]
Quoted 7 lines
drivers/net/dsa/microchip/ksz_common.c +3
-0@@ -3909,6 +3920,24 @@ static void ksz_set_gbit(struct ksz_device *dev, int port, bool gbit)ksz_pwrite8 (dev, port, regs[P_XMII_CTRL_1 ], data8); } +static void ksz_enable_single_led_mode (struct ksz_device *dev,int port,struct phy_device *phydev) +{ +const u16 *regs = dev->info->regs;
drivers/net/dsa/microchip/ksz_common.c static void ksz_set_gbit(struct ksz_device *dev, int port, bool gbit) · line 3935
Quoted 10 lines
drivers/net/dsa/microchip/ksz_common.c +10
-0+ +ksz_pwrite16 (dev, port, regs[P_PHY_MMD_SETUP ],0x0002 );/* Set up register address for MMD */ +ksz_pwrite16 (dev, port, regs[P_PHY_MMD_DATA ],0x0000 );/* Select Register 00h of MMD */ +ksz_pwrite16 (dev, port, regs[P_PHY_MMD_SETUP ],0x4002 );/* Select register data for MMD */ +ksz_pwrite16 (dev, port, regs[P_PHY_MMD_DATA ],0x0011 );/* Write value 0011h to MMD */ + +/* According to KSZ9477S Errata DS80000754F (Module 19) 0xfa00 has to +* be written to the Debug Register 3 to enable Single-LED Mode. +*/ +if (phydev->dev_flags &MICREL_KSZ9_LED_ERRATA )
^^^^^^
Can phydev be NULL here? The phylink framework passes phydev as NULL when using fixed-link configurations (MLO_AN_FIXED mode). For example, if a non-CPU port on KSZ9477 is configured with a fixed-link in device tree instead of a real PHY, phylink_fwnode_phy_connect() returns early without attaching a PHY, leaving pl->phydev as NULL.
When link comes up on such a port, phylink_link_up() calls the mac_link_up callback with this NULL phydev, which then gets passed to this function.
Quoted 4 lines
drivers/net/dsa/microchip/ksz_common.c +4
-0+ksz_pwrite16 (dev, port, regs[P_PHY_DIGITAL_DEBUG_3 ],0xfa00 ); + +dev_info (dev->dev,"port-%d: single-led mode enabled.\n" , port); +}
[ ... ]
drivers/net/dsa/microchip/ksz_common.c static void ksz9477_phylink_mac_link_up(struct phylink_config *config, · line 4010
Quoted 6 lines
drivers/net/dsa/microchip/ksz_common.c +2
-0@@ -3977,6 +4006,9 @@ static void ksz9477_phylink_mac_link_up(struct phylink_config *config,int port = dp->index;struct ksz_port *p; +if (dev->single_led_mode && port != dev->cpu_port) +ksz_enable_single_led_mode (dev, port, phydev);
The guard here checks single_led_mode and that port is not the CPU port, but it does not verify that phydev is valid. On KSZ9477, ports 5 and 6 do not have internal PHYs (internal_phy[] is false), and if one of these external ports is configured with fixed-link while cpu_port is the other external port, this path will be taken with phydev=NULL.
[ ... ]
Signature · 1 line
pw-bot: cr
Re: [v1,3/3] net: dsa: microchip: add single-led-mode support for KSZ9477
Hello Jakub,
Quoted 37 lines · Jakub Kicinski
This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html
---
net: dsa: microchip: add single-led-mode support for KSZ9477This patch adds single LED mode support for KSZ9477 via a device tree property. The mode is configured during MAC link-up for non-CPU ports and includes a workaround for Errata Module 19.
Quoted 4 lines
drivers/net/dsa/microchip/ksz_common.c +0
-0[ ... ]
Quoted 7 lines
drivers/net/dsa/microchip/ksz_common.c +3
-0@@ -3909,6 +3920,24 @@ static void ksz_set_gbit(struct ksz_device *dev, int port, bool gbit)ksz_pwrite8 (dev, port, regs[P_XMII_CTRL_1 ], data8); } +static void ksz_enable_single_led_mode (struct ksz_device *dev,int port,struct phy_device *phydev) +{ +const u16 *regs = dev->info->regs;drivers/net/dsa/microchip/ksz_common.c static void ksz_set_gbit(struct ksz_device *dev, int port, bool gbit) · line 3935
Quoted 10 lines
drivers/net/dsa/microchip/ksz_common.c +10
-0+ +ksz_pwrite16 (dev, port, regs[P_PHY_MMD_SETUP ],0x0002 );/* Set up register address for MMD */ +ksz_pwrite16 (dev, port, regs[P_PHY_MMD_DATA ],0x0000 );/* Select Register 00h of MMD */ +ksz_pwrite16 (dev, port, regs[P_PHY_MMD_SETUP ],0x4002 );/* Select register data for MMD */ +ksz_pwrite16 (dev, port, regs[P_PHY_MMD_DATA ],0x0011 );/* Write value 0011h to MMD */ + +/* According to KSZ9477S Errata DS80000754F (Module 19) 0xfa00 has to +* be written to the Debug Register 3 to enable Single-LED Mode. +*/ +if (phydev->dev_flags &MICREL_KSZ9_LED_ERRATA )^^^^^^
Quoted 8 lines
Can phydev be NULL here? The phylink framework passes phydev as NULL when using fixed-link configurations (
MLO_AN_FIXEDmode). For example, if a non-CPU port on KSZ9477 is configured with a fixed-link in device tree instead of a real PHY,phylink_fwnode_phy_connect()returns early without attaching a PHY, leavingpl->phydevas NULL.When link comes up on such a port,
phylink_link_up()calls themac_link_upcallback with this NULL phydev, which then gets passed to this function.
Thanks, I see the problem here. Indeed, in a fixed-link configuration, phydev will be NULL here.
Since the LED mode configuration is specific to the PHY, I will add a NULL check to ensure we only proceed if a PHY is actually attached to the port.
Quoted 11 lines
Quoted 4 lines
drivers/net/dsa/microchip/ksz_common.c +4
-0+ksz_pwrite16 (dev, port, regs[P_PHY_DIGITAL_DEBUG_3 ],0xfa00 ); + +dev_info (dev->dev,"port-%d: single-led mode enabled.\n" , port); +}[ ... ]
Quoted 4 lines
drivers/net/dsa/microchip/ksz_common.c +0
-0@@ -3977,6 +4006,9 @@ static void ksz9477_phylink_mac_link_up(struct phylink_config *config,int port = dp->index;struct ksz_port *p;
Quoted 8 lines
drivers/net/dsa/microchip/ksz_common.c static void ksz9477_phylink_mac_link_up(struct phylink_config *config, · line 4010
Quoted 2 lines
drivers/net/dsa/microchip/ksz_common.c +2
-0+if (dev->single_led_mode && port != dev->cpu_port) +ksz_enable_single_led_mode (dev, port, phydev);The guard here checks
single_led_modeand that port is not the CPU port, but it does not verify that phydev is valid. On KSZ9477, ports 5 and 6 do not have internal PHYs (internal_phy[] is false), and if one of these external ports is configured with fixed-link whilecpu_portis the other external port, this path will be taken with phydev=NULL.
I re-checked the datasheet (DS00002392C) and indeed the switch has seven ports, of which only five have integrated PHYs. The two external MAC ports (5 and 6) can be connected to a host processor, another switch, or an external PHY.
As you pointed out, if these are used as fixed-links, phydev will be NULL. I will add a check to ensure we only proceed if a PHY is attached to the port.
I will fix this in v2.
Regards,
Heinrich