public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next v1 0/3] net: dsa: microchip: add single-led-mode support
@ 2026-01-28 13:38 Heinrich Toews
  2026-01-28 13:38 ` [PATCH v1 1/3] dt-bindings: net: dsa: microchip: add microchip,single-led-mode flag Heinrich Toews
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Heinrich Toews @ 2026-01-28 13:38 UTC (permalink / raw)
  To: netdev; +Cc: andrew, f.fainelli, olteanv, robh+dt, krzysztof.kozlowski+dt

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(+)

-- 
2.52.0


^ permalink raw reply	[flat|nested] 16+ messages in thread
* Re: [v1,3/3] net: dsa: microchip: add single-led-mode support for KSZ9477
@ 2026-01-30 21:46 Tim Harvey
  2026-02-03 16:58 ` Heinrich Toews
  0 siblings, 1 reply; 16+ messages in thread
From: Tim Harvey @ 2026-01-30 21:46 UTC (permalink / raw)
  To: Heinrich Toews, netdev
  Cc: Andrew Lunn, Florian Fainelli, Vladimir Oltean, Rob Herring,
	Krzysztof Kozlowski

>
> diff --git a/drivers/net/dsa/microchip/ksz_common.c
> b/drivers/net/dsa/microchip/ksz_common.c
> index e5fa1f5fc09b3..bef8ec51d9483 100644
> --- a/drivers/net/dsa/microchip/ksz_common.c
> +++ b/drivers/net/dsa/microchip/ksz_common.c
> @@ -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,
>  };
>
> @@ -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;
>   }
>

Hi Heinrich,

Thanks for doing this. I have two boards I work with that have a
KSZ9897S switch and use single-led mode (imx8mp-venice-gw74xx.dts and
imx8mm-venice-gw7901.dts) that suffer from this issue. In my scenario
I take care of this in the bootloader but when ksz9477_reset_switch()
is called and sets the SW_RESET bit of REG_SW_OPERATION it resets all
registers and reverts to tri-color dual-led mode thus we really do
need a dt prop and handling for this.

You can add the errata for KSZ9897 as well here:
+       case KSZ9897_CHIP_ID:
+               /* KSZ9897S Errata DS80000759F: Module 18 */
+               return MICREL_KSZ9_LED_ERRATA;

And because this errata applies to multiple chips it's probably best
to describe the workaround once and refer to the errata # in the cases
statements.

> +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 */

These are wrong: The MMD_SETUP and MMD_DATA regs you are using here
0x011a and 0x11c are actually 0xN11a 0x 0xN11c (where N is the port)
so they port specific so the above only would set them for port0.
Because these registers correspond to standardPHY register 0x0d and
0x0e which are defined in mii.h you can just use those.

What you want here is to use ksz_phy_write16 on the port which will
call the chip-specific w_phy which will handle writing to the port
specific register:
ksz_phy_write16(dev, port, MII_MMD_CTRL, 0x02);
ksz_phy_write16(dev, port, MII_MMD_DATA, 0x00);
ksz_phy_write16(dev, port, MII_MMD_CTRL, MII_MMD_CTRL_NOINCR | 0x02);
ksz_phy_write16(dev, port, MII_MMD_DATA, 0x10);

Note on that last one, the errata says to write 0x11 but that's a typo
as if you read closely it says 'setting bit 4' and looking at the
datasheet bit0 is reserved, so the 0x11 should be 0x10.

> +
> + /* 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);

Similarly the errata specifies this as PHY register 0x1E (which is a
vendor specific register so not defined in mii.h):

ksz_phy_write16(dev, port, 0x1e, 0xfa00);

Your original patch doesn't work in my case (maybe it worked for you
because you were trying to address port0?). With the above changes the
LED's are properly configured on my boards.

Best Regards,

Tim

> +
> + 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);
> diff --git a/drivers/net/dsa/microchip/ksz_common.h
> b/drivers/net/dsa/microchip/ksz_common.h
> index 929aff4c55de5..9900e9dd91810 100644
> --- a/drivers/net/dsa/microchip/ksz_common.h
> +++ b/drivers/net/dsa/microchip/ksz_common.h
> @@ -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 {

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2026-02-04 10:22 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-28 13:38 [PATCH net-next v1 0/3] net: dsa: microchip: add single-led-mode support Heinrich Toews
2026-01-28 13:38 ` [PATCH v1 1/3] dt-bindings: net: dsa: microchip: add microchip,single-led-mode flag Heinrich Toews
2026-01-28 13:59   ` Andrew Lunn
2026-01-28 15:10     ` Heinrich Töws (TWx)
2026-01-28 15:22       ` Andrew Lunn
2026-01-28 15:53         ` Heinrich Töws (TWx)
2026-01-28 18:06   ` Rob Herring
2026-02-03 10:22     ` Heinrich Toews
2026-01-28 13:38 ` [PATCH v1 2/3] net: phy: micrel: add flag for KSZ9477 LED erratum Heinrich Toews
2026-01-28 13:38 ` [PATCH v1 3/3] net: dsa: microchip: add single-led-mode support for KSZ9477 Heinrich Toews
2026-01-29  2:25   ` [v1,3/3] " Jakub Kicinski
2026-02-03 11:13     ` Heinrich Toews
  -- strict thread matches above, loose matches on Subject: below --
2026-01-30 21:46 Tim Harvey
2026-02-03 16:58 ` Heinrich Toews
2026-02-04  0:56   ` Tim Harvey
2026-02-04 10:22     ` Heinrich Toews

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox