Skip to contentSkip to conversation

net: phy: qca808x: fix the active-high LED polarity mode

PATCH Applied Donggeun Yoo 3 participants 6 messages Sep 15 – Sep 18

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

v3 cover net: phy: qca808x: fix the active-high LED polarity mode

A QCA8081 with an 'active-high' LED node does not work today, in two separate ways, so this is now two patches: qca808x_led_polarity_set() rejects the mode outright, and once it stops doing that qca808x_config_init() still will not put the bit back after the reset phy_init_hw() runs.

Tested in QEMU against a synthetic MDIO bus that answers as a QCA8081 and emulates MMD7 0x901a, with the reset clearing BIT(6) as f203c8c77c76 describes. One kernel, one harness, three arms, x86_64, 7.3.0-rc2+:

  DT node            base      1/2 only   1/2 + 2/2
  active-high        -EINVAL   inverted   correct
  active-low         correct   correct    correct
  no polarity node   correct   correct    correct
  high-impedance     -EINVAL   -EINVAL    -EINVAL

Still no QCA808x hardware here; the harness emulates the one register, so a confirmation on a real board would be welcome.

Changes since v2: https://lore.kernel.org/netdev/[email protected]/
- Split in two, one defect each, per Christian Marangi.
- Add QCA808X_PHY_LED_UNSET and express the condition as
PHY_LED_ACTIVE_LOW instead of bare -1/0/1, per Christian Marangi.
- Tested rather than compile-tested; see the table above.

Donggeun Yoo (2):
net: phy: qca808x: accept the active-high LED polarity mode
net: phy: qca808x: keep an explicit active-high LED across the reset

 drivers/net/phy/qcom/qca808x.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
Signature · 1 line
2.53.0
#1 lore raw

PATCH v3 1/2 net: phy: qca808x: accept the active-high LED polarity mode

commit a274465cc3be ("net: phy: support 'active-high' property for PHY LEDs") added PHY_LED_ACTIVE_HIGH, but qca808x_led_polarity_set() still rejects everything except PHY_LED_ACTIVE_LOW. An LED node carrying 'active-high' therefore falls into the default case and returns -EINVAL, which phy_probe() propagates: the mdio device is left unbound and phy_attach_direct() falls back to the genphy driver, so the PHY loses every qca808x-specific feature, not just the LED.

Accept the mode. The register write below already handles both polarities.

Fixes a274465cc3be ("net: phy: support 'active-high' property for PHY LEDs")
Assisted-by Claude:claude-fable-5

---
Tested in QEMU against a synthetic MDIO bus answering as a QCA8081; see the cover letter for the three-arm table.

 drivers/net/phy/qcom/qca808x.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/phy/qcom/qca808x.c +3 -0
index 8eb51b1a006c..3ba58f14e248 100644
@@ -603,6 +603,9 @@ static int qca808x_led_polarity_set(struct phy_device *phydev, int index,
 		case PHY_LED_ACTIVE_LOW:
 			active_low = true;
 			break;
+		case PHY_LED_ACTIVE_HIGH:
+			active_low = false;
+			break;
 		default:
 			return -EINVAL;
 		}
Signature · 1 line
2.53.0
#3 lore raw

PATCH v3 2/2 net: phy: qca808x: keep an explicit active-high LED across the reset

In reply to Donggeun Yoo

With the previous patch an 'active-high' LED node is accepted, so led_polarity_mode can now hold 0. qca808x_config_init() only re-asserts QCA808X_LED_ACTIVE_HIGH when the mode is -1, the value that means device tree asked for nothing, so an explicit active-high does not reach the register.

That matters because the bit does not survive a reset. phy_init_hw() runs .soft_reset before .config_init on every attach and resume, and
commit f203c8c77c76 ("net: phy: qcom: qca808x: default to LED active High if not set") records why: "on PHY reset, the Active High bit is not set resulting in the LED driven as active-low". The polarity written from device tree during phy_probe() is therefore gone by the time the link comes up, and the LED runs inverted.

Re-assert the bit for anything other than an explicit active-low, which is the one case that wants it clear and gets that from the reset for free. Name the unset value while here: led_polarity_mode otherwise holds a PHY_LED_ACTIVE_* value, so spelling the comparison PHY_LED_ACTIVE_LOW says what it means where -1, 0 and 1 did not.

Fixes a274465cc3be ("net: phy: support 'active-high' property for PHY LEDs")
Assisted-by Claude:claude-fable-5

---
Tested in QEMU against a synthetic MDIO bus answering as a QCA8081, with the reset clearing BIT(6). With only 1/2 applied an 'active-high' node comes up inverted; see the cover letter.

 drivers/net/phy/qcom/qca808x.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/net/phy/qcom/qca808x.c +7 -5
index 3ba58f14e248..bab26e4c6140 100644
@@ -87,6 +87,9 @@
 
 #define QCA8081_PHY_ID				0x004dd101
 
+/* led_polarity_mode otherwise holds a PHY_LED_ACTIVE_* value */
+#define QCA808X_PHY_LED_UNSET			-1
+
 MODULE_DESCRIPTION("Qualcomm Atheros QCA808X PHY driver");
 MODULE_AUTHOR("Matus Ujhelyi");
 MODULE_LICENSE("GPL");
@@ -187,8 +190,7 @@ static int qca808x_probe(struct phy_device *phydev)
 	if (!priv)
 		return -ENOMEM;
 
-	/* Init LED polarity mode to -1 */
-	priv->led_polarity_mode = -1;
+	priv->led_polarity_mode = QCA808X_PHY_LED_UNSET;
 
 	phydev->priv = priv;
 
@@ -200,8 +202,8 @@ static int qca808x_config_init(struct phy_device *phydev)
 	struct qca808x_priv *priv = phydev->priv;
 	int ret;
 
-	/* Default to LED Active High if active-low not in DT */
-	if (priv->led_polarity_mode == -1) {
+	/* Set LED Active High unless active-low was requested in DT */
+	if (priv->led_polarity_mode != PHY_LED_ACTIVE_LOW) {
 		ret = phy_set_bits_mmd(phydev, MDIO_MMD_AN,
 				       QCA808X_MMD7_LED_POLARITY_CTRL,
 				       QCA808X_LED_ACTIVE_HIGH);
@@ -615,7 +617,7 @@ static int qca808x_led_polarity_set(struct phy_device *phydev, int index,
 	 * To detect this, check if last requested polarity mode
 	 * match the new one.
 	 */
-	if (priv->led_polarity_mode >= 0 &&
+	if (priv->led_polarity_mode != QCA808X_PHY_LED_UNSET &&
 	    priv->led_polarity_mode != active_low) {
 		phydev_err(phydev, "PHY polarity is global. Mismatched polarity on different LED\n");
 		return -EINVAL;
Signature · 1 line
2.53.0
Reviewed-by on v3 1/2
#2 lore raw

Re: [PATCH net v3 1/2] net: phy: qca808x: accept the active-high LED polarity mode

In reply to Donggeun Yoo
Quoted 8 lines · Donggeun Yoo

commit a274465cc3be ("net: phy: support 'active-high' property for PHY LEDs") added PHY_LED_ACTIVE_HIGH, but qca808x_led_polarity_set() still rejects everything except PHY_LED_ACTIVE_LOW. An LED node carrying 'active-high' therefore falls into the default case and returns -EINVAL, which phy_probe() propagates: the mdio device is left unbound and phy_attach_direct() falls back to the genphy driver, so the PHY loses every qca808x-specific feature, not just the LED.

Quoted 7 lines

Accept the mode. The register write below already handles both polarities.

Fixes a274465cc3be ("net: phy: support 'active-high' property for PHY LEDs")
Assisted-by Claude:claude-fable-5
Signature · 1 line
	Ansuel
Reviewed-by on v3 2/2
#4 lore raw

Re: [PATCH net v3 2/2] net: phy: qca808x: keep an explicit active-high LED across the reset

In reply to Donggeun Yoo
Quoted 20 lines · Donggeun Yoo

With the previous patch an 'active-high' LED node is accepted, so led_polarity_mode can now hold 0. qca808x_config_init() only re-asserts QCA808X_LED_ACTIVE_HIGH when the mode is -1, the value that means device tree asked for nothing, so an explicit active-high does not reach the register.

That matters because the bit does not survive a reset. phy_init_hw() runs .soft_reset before .config_init on every attach and resume, and
commit f203c8c77c76 ("net: phy: qcom: qca808x: default to LED active High if not set") records why: "on PHY reset, the Active High bit is not set resulting in the LED driven as active-low". The polarity written from device tree during phy_probe() is therefore gone by the time the link comes up, and the LED runs inverted.

Re-assert the bit for anything other than an explicit active-low, which is the one case that wants it clear and gets that from the reset for free. Name the unset value while here: led_polarity_mode otherwise holds a PHY_LED_ACTIVE_* value, so spelling the comparison PHY_LED_ACTIVE_LOW says what it means where -1, 0 and 1 did not.

Quoted 6 lines
Fixes a274465cc3be ("net: phy: support 'active-high' property for PHY LEDs")
Assisted-by Claude:claude-fable-5
Signature · 1 line
	Ansuel
#5 lore raw
In reply to Donggeun Yoo
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 11 lines · On Wed, 16 Sep 2026 07:31:36 +0900 you wrote:

A QCA8081 with an 'active-high' LED node does not work today, in two separate ways, so this is now two patches: qca808x_led_polarity_set() rejects the mode outright, and once it stops doing that qca808x_config_init() still will not put the bit back after the reset phy_init_hw() runs.

Tested in QEMU against a synthetic MDIO bus that answers as a QCA8081 and emulates MMD7 0x901a, with the reset clearing BIT(6) as f203c8c77c76 describes. One kernel, one harness, three arms, x86_64, 7.3.0-rc2+:

[...]

Here is the summary with links:
- [net,v3,1/2] net: phy: qca808x: accept the active-high LED polarity mode

    https://git.kernel.org/netdev/net-next/c/5117ce8c35d1
  - [net,v3,2/2] net: phy: qca808x: keep an explicit active-high LED across the reset
    https://git.kernel.org/netdev/net-next/c/f1b4766d67bb

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html