From 985371d3546514199471d44d1ba6668606ace2ba Mon Sep 17 00:00:00 2001
From: Tim Harvey <tharvey@gateworks.com>
Date: Fri, 30 Jan 2026 15:20:11 -0800
Subject: [PATCH] imx: venice: add patches for KSZ9897S LED configuration

Add a set of patches to configure the KSZ9897S LED's for the GW7901 and
GW74xx Network switch ports.

Signed-off-by: Tim Harvey <tharvey@gateworks.com>
---
 ...rel-add-flag-for-KSZ9477-LED-erratum.patch |  31 +++++
 ...p-add-single-led-mode-support-for-KS.patch | 122 ++++++++++++++++++
 ...-venice-gw7901-add-single-led-mode-m.patch |  30 +++++
 ...-venice-gw74xx-add-single-led-mode-m.patch |  30 +++++
 4 files changed, 213 insertions(+)
 create mode 100644 target/linux/imx/patches-6.6/0601-net-phy-micrel-add-flag-for-KSZ9477-LED-erratum.patch
 create mode 100644 target/linux/imx/patches-6.6/0602-net-dsa-microchip-add-single-led-mode-support-for-KS.patch
 create mode 100644 target/linux/imx/patches-6.6/0603-arm64-dts-imx8mm-venice-gw7901-add-single-led-mode-m.patch
 create mode 100644 target/linux/imx/patches-6.6/0604-arm64-dts-imx8mp-venice-gw74xx-add-single-led-mode-m.patch

diff --git a/target/linux/imx/patches-6.6/0601-net-phy-micrel-add-flag-for-KSZ9477-LED-erratum.patch b/target/linux/imx/patches-6.6/0601-net-phy-micrel-add-flag-for-KSZ9477-LED-erratum.patch
new file mode 100644
index 0000000000..084530f466
--- /dev/null
+++ b/target/linux/imx/patches-6.6/0601-net-phy-micrel-add-flag-for-KSZ9477-LED-erratum.patch
@@ -0,0 +1,31 @@
+From f4e92916c5f6652e070fdc270b7c0a8dbc22e16c Mon Sep 17 00:00:00 2001
+From: Heinrich Toews <ht@twx-software.de>
+Date: Wed, 28 Jan 2026 14:38:32 +0100
+Subject: [PATCH 601/604] net: phy: micrel: add flag for KSZ9477 LED erratum
+
+Add 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.
+
+Signed-off-by: Heinrich Toews <ht@twx-software.de>
+Signed-off-by: Tim Harvey <tharvey@gateworks.com>
+---
+ include/linux/micrel_phy.h | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/include/linux/micrel_phy.h b/include/linux/micrel_phy.h
+index 4e27ca7c49de..7a81d54deef8 100644
+--- a/include/linux/micrel_phy.h
++++ b/include/linux/micrel_phy.h
+@@ -45,6 +45,7 @@
+ #define MICREL_PHY_FXEN		BIT(1)
+ #define MICREL_KSZ8_P1_ERRATA	BIT(2)
+ #define MICREL_NO_EEE		BIT(3)
++#define MICREL_KSZ9_LED_ERRATA	BIT(4)
+ 
+ #define MICREL_KSZ9021_EXTREG_CTRL	0xB
+ #define MICREL_KSZ9021_EXTREG_DATA_WRITE	0xC
+-- 
+2.34.1
+
diff --git a/target/linux/imx/patches-6.6/0602-net-dsa-microchip-add-single-led-mode-support-for-KS.patch b/target/linux/imx/patches-6.6/0602-net-dsa-microchip-add-single-led-mode-support-for-KS.patch
new file mode 100644
index 0000000000..31adef4bf5
--- /dev/null
+++ b/target/linux/imx/patches-6.6/0602-net-dsa-microchip-add-single-led-mode-support-for-KS.patch
@@ -0,0 +1,122 @@
+From afb857e813967f64fec8ff05985f599fc7897f65 Mon Sep 17 00:00:00 2001
+From: Tim Harvey <tharvey@gateworks.com>
+Date: Fri, 30 Jan 2026 11:10:12 -0800
+Subject: [PATCH 602/604] net: dsa: microchip: add single-led-mode support for
+ KSZ9477
+
+Add 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 requiring a debug
+register write to ensure proper LED activity. The mode is configured
+during the MAC link-up phase for non-CPU ports.
+
+Signed-off-by: Heinrich Toews <ht@twx-software.de>
+Signed-off-by: Tim Harvey <tharvey@gateworks.com>
+---
+ drivers/net/dsa/microchip/ksz_common.c | 45 +++++++++++++++++++-------
+ drivers/net/dsa/microchip/ksz_common.h |  1 +
+ 2 files changed, 34 insertions(+), 12 deletions(-)
+
+diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
+index 651b81b278b2..06c4f5d3ab9e 100644
+--- a/drivers/net/dsa/microchip/ksz_common.c
++++ b/drivers/net/dsa/microchip/ksz_common.c
+@@ -2332,6 +2332,7 @@ static int ksz_phy_write16(struct dsa_switch *ds, int addr, int reg, u16 val)
+ static u32 ksz_get_phy_flags(struct dsa_switch *ds, int port)
+ {
+ 	struct ksz_device *dev = ds->priv;
++	u32 flags = 0;
+ 
+ 	switch (dev->chip_id) {
+ 	case KSZ8830_CHIP_ID:
+@@ -2343,20 +2344,19 @@ static u32 ksz_get_phy_flags(struct dsa_switch *ds, int port)
+ 			return MICREL_KSZ8_P1_ERRATA;
+ 		break;
+ 	case KSZ9477_CHIP_ID:
+-		/* KSZ9477 Errata DS80000754C
+-		 *
+-		 * Module 4: Energy Efficient Ethernet (EEE) feature select must
+-		 * be manually disabled
+-		 *   The EEE feature is enabled by default, but it is not fully
+-		 *   operational. It must be manually disabled through register
+-		 *   controls. If not disabled, the PHY ports can auto-negotiate
+-		 *   to enable EEE, and this feature can cause link drops when
+-		 *   linked to another device supporting EEE.
+-		 */
+-		return MICREL_NO_EEE;
++		/* KSZ9477 Errata DS80000754C: Module 4 */
++		flags |= MICREL_NO_EEE;
++		/* KSZ9477S Errata DS80000754F: Module 19 */
++		flags |= MICREL_KSZ9_LED_ERRATA;
++		break;
++	case KSZ9897_CHIP_ID:
++		flags |= MICREL_NO_EEE; /* KSZ9897R Errata DS80000758C Module 4 */
++		/* KSZ9897S Errata DS80000759F: Module 18 */
++		flags |= MICREL_KSZ9_LED_ERRATA;
++		break;
+ 	}
+ 
+-	return 0;
++	return flags;
+ }
+ 
+ static void ksz_mac_link_down(struct dsa_switch *ds, int port,
+@@ -2514,6 +2514,22 @@ static int ksz_enable_port(struct dsa_switch *ds, int port,
+ 	return 0;
+ }
+ 
++static void ksz_enable_single_led_mode(struct ksz_device *dev, int port,
++				       struct phy_device *phydev)
++{
++	ksz_phy_write16(dev->ds, port, MII_MMD_CTRL, 0x0002);
++	ksz_phy_write16(dev->ds, port,  MII_MMD_DATA, 0x0000);
++	ksz_phy_write16(dev->ds, port, MII_MMD_CTRL, MII_MMD_CTRL_NOINCR | 0x02);
++	ksz_phy_write16(dev->ds, port,  MII_MMD_DATA, 0x0010); /* set bit 4 */
++	/* KSZ9477 errata requires writing 0xfa00 to Debug Register 3
++	 * to enable Single-LED mode.
++	 */
++	if (phydev->dev_flags & MICREL_KSZ9_LED_ERRATA)
++		ksz_phy_write16(dev->ds, port, 0x1e, 0xfa00);
++
++	dev_info(dev->dev, "port-%d: single-led mode enabled.\n", port);
++}
++
+ void ksz_port_stp_state_set(struct dsa_switch *ds, int port, u8 state)
+ {
+ 	struct ksz_device *dev = ds->priv;
+@@ -3006,6 +3022,9 @@ static void ksz9477_phylink_mac_link_up(struct ksz_device *dev, int port,
+ {
+ 	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 */
+@@ -3649,6 +3668,8 @@ int ksz_switch_register(struct ksz_device *dev)
+ 			dev_err(dev->dev, "inconsistent synclko settings\n");
+ 			return -EINVAL;
+ 		}
++		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 0e51f2277381..329975003af7 100644
+--- a/drivers/net/dsa/microchip/ksz_common.h
++++ b/drivers/net/dsa/microchip/ksz_common.h
+@@ -157,6 +157,7 @@ struct ksz_device {
+ 	phy_interface_t compat_interface;
+ 	bool synclko_125;
+ 	bool synclko_disable;
++	bool single_led_mode;		/* Enable Single LED Mode */
+ 
+ 	struct vlan_table *vlan_cache;
+ 
+-- 
+2.34.1
+
diff --git a/target/linux/imx/patches-6.6/0603-arm64-dts-imx8mm-venice-gw7901-add-single-led-mode-m.patch b/target/linux/imx/patches-6.6/0603-arm64-dts-imx8mm-venice-gw7901-add-single-led-mode-m.patch
new file mode 100644
index 0000000000..48b235fff5
--- /dev/null
+++ b/target/linux/imx/patches-6.6/0603-arm64-dts-imx8mm-venice-gw7901-add-single-led-mode-m.patch
@@ -0,0 +1,30 @@
+From 9a76f4c417786b42063559a8b7aaa579883b6552 Mon Sep 17 00:00:00 2001
+From: Tim Harvey <tharvey@gateworks.com>
+Date: Fri, 30 Jan 2026 13:47:59 -0800
+Subject: [PATCH 603/604] arm64: dts: imx8mm-venice-gw7901: add single-led-mode
+ mode for ksz9897
+
+The GW7901 uses a KSZ9897 network switch with port LED's connected in
+single-led mode. Specifiy the single-led-mode property so that the
+port LEDs are configured properly.
+
+Signed-off-by: Tim Harvey <tharvey@gateworks.com>
+---
+ arch/arm64/boot/dts/freescale/imx8mm-venice-gw7901.dts | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/arch/arm64/boot/dts/freescale/imx8mm-venice-gw7901.dts b/arch/arm64/boot/dts/freescale/imx8mm-venice-gw7901.dts
+index ed46d4f3e66f..e81482643409 100644
+--- a/arch/arm64/boot/dts/freescale/imx8mm-venice-gw7901.dts
++++ b/arch/arm64/boot/dts/freescale/imx8mm-venice-gw7901.dts
+@@ -643,6 +643,7 @@ switch: switch@5f {
+ 		interrupt-parent = <&gpio4>;
+ 		interrupts = <18 IRQ_TYPE_EDGE_FALLING>;
+ 		phy-mode = "rgmii-id";
++		microchip,single-led-mode;
+ 
+ 		ports {
+ 			#address-cells = <1>;
+-- 
+2.34.1
+
diff --git a/target/linux/imx/patches-6.6/0604-arm64-dts-imx8mp-venice-gw74xx-add-single-led-mode-m.patch b/target/linux/imx/patches-6.6/0604-arm64-dts-imx8mp-venice-gw74xx-add-single-led-mode-m.patch
new file mode 100644
index 0000000000..2a25e94157
--- /dev/null
+++ b/target/linux/imx/patches-6.6/0604-arm64-dts-imx8mp-venice-gw74xx-add-single-led-mode-m.patch
@@ -0,0 +1,30 @@
+From 2608cf569d7869bd6a17265c84945b3ee1cbeb27 Mon Sep 17 00:00:00 2001
+From: Tim Harvey <tharvey@gateworks.com>
+Date: Fri, 30 Jan 2026 13:49:33 -0800
+Subject: [PATCH 604/604] arm64: dts: imx8mp-venice-gw74xx: add single-led-mode
+ mode for ksz9897
+
+The GW74xx uses a KSZ9897 network switch with port LED's connected in
+single-led mode. Specifiy the single-led-mode property so that the
+port LEDs are configured properly.
+
+Signed-off-by: Tim Harvey <tharvey@gateworks.com>
+---
+ arch/arm64/boot/dts/freescale/imx8mp-venice-gw74xx.dts | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/arch/arm64/boot/dts/freescale/imx8mp-venice-gw74xx.dts b/arch/arm64/boot/dts/freescale/imx8mp-venice-gw74xx.dts
+index 34619f085623..180cde917e2a 100644
+--- a/arch/arm64/boot/dts/freescale/imx8mp-venice-gw74xx.dts
++++ b/arch/arm64/boot/dts/freescale/imx8mp-venice-gw74xx.dts
+@@ -470,6 +470,7 @@ switch: switch@5f {
+ 		pinctrl-0 = <&pinctrl_ksz>;
+ 		interrupt-parent = <&gpio4>;
+ 		interrupts = <29 IRQ_TYPE_EDGE_FALLING>;
++		microchip,single-led-mode;
+ 
+ 		ports {
+ 			#address-cells = <1>;
+-- 
+2.34.1
+
-- 
2.34.1

