1 From 9d55e68b19f222e6334ef4021c5527998f5ab537 Mon Sep 17 00:00:00 2001
2 From: Daniel Golle <daniel@makrotopia.org>
3 Date: Thu, 10 Oct 2024 13:55:00 +0100
4 Subject: [PATCH 2/4] net: phy: aquantia: correctly describe LED polarity
7 Use newly defined 'active-high' property to set the
8 VEND1_GLOBAL_LED_DRIVE_VDD bit and let 'active-low' clear that bit. This
9 reflects the technical reality which was inverted in the previous
10 description in which the 'active-low' property was used to actually set
11 the VEND1_GLOBAL_LED_DRIVE_VDD bit, which means that VDD (ie. supply
12 voltage) of the LED is driven rather than GND.
14 Signed-off-by: Daniel Golle <daniel@makrotopia.org>
15 Reviewed-by: Andrew Lunn <andrew@lunn.ch>
16 Link: https://patch.msgid.link/86a413b4387c42dcb54f587cc2433a06f16aae83.1728558223.git.daniel@makrotopia.org
17 Signed-off-by: Paolo Abeni <pabeni@redhat.com>
19 drivers/net/phy/aquantia/aquantia.h | 1 +
20 drivers/net/phy/aquantia/aquantia_leds.c | 19 ++++++++++++++-----
21 drivers/net/phy/aquantia/aquantia_main.c | 12 +++++++++---
22 3 files changed, 24 insertions(+), 8 deletions(-)
24 --- a/drivers/net/phy/aquantia/aquantia.h
25 +++ b/drivers/net/phy/aquantia/aquantia.h
26 @@ -169,6 +169,7 @@ static const struct aqr107_hw_stat aqr10
28 u64 sgmii_stats[AQR107_SGMII_STAT_SZ];
29 unsigned long leds_active_low;
30 + unsigned long leds_active_high;
33 #if IS_REACHABLE(CONFIG_HWMON)
34 --- a/drivers/net/phy/aquantia/aquantia_leds.c
35 +++ b/drivers/net/phy/aquantia/aquantia_leds.c
36 @@ -121,13 +121,13 @@ int aqr_phy_led_active_low_set(struct ph
38 return phy_modify_mmd(phydev, MDIO_MMD_VEND1, AQR_LED_DRIVE(index),
39 VEND1_GLOBAL_LED_DRIVE_VDD,
40 - enable ? VEND1_GLOBAL_LED_DRIVE_VDD : 0);
41 + enable ? 0 : VEND1_GLOBAL_LED_DRIVE_VDD);
44 int aqr_phy_led_polarity_set(struct phy_device *phydev, int index, unsigned long modes)
46 + bool force_active_low = false, force_active_high = false;
47 struct aqr107_priv *priv = phydev->priv;
48 - bool active_low = false;
51 if (index >= AQR_MAX_LEDS)
52 @@ -136,7 +136,10 @@ int aqr_phy_led_polarity_set(struct phy_
53 for_each_set_bit(mode, &modes, __PHY_LED_MODES_NUM) {
55 case PHY_LED_ACTIVE_LOW:
57 + force_active_low = true;
59 + case PHY_LED_ACTIVE_HIGH:
60 + force_active_high = true;
64 @@ -144,8 +147,14 @@ int aqr_phy_led_polarity_set(struct phy_
67 /* Save LED driver vdd state to restore on SW reset */
69 + if (force_active_low)
70 priv->leds_active_low |= BIT(index);
72 - return aqr_phy_led_active_low_set(phydev, index, active_low);
73 + if (force_active_high)
74 + priv->leds_active_high |= BIT(index);
76 + if (force_active_high || force_active_low)
77 + return aqr_phy_led_active_low_set(phydev, index, force_active_low);
81 --- a/drivers/net/phy/aquantia/aquantia_main.c
82 +++ b/drivers/net/phy/aquantia/aquantia_main.c
83 @@ -529,7 +529,7 @@ static int aqr107_config_mdi(struct phy_
84 static int aqr107_config_init(struct phy_device *phydev)
86 struct aqr107_priv *priv = phydev->priv;
91 /* Check that the PHY interface type is compatible */
92 @@ -569,8 +569,14 @@ static int aqr107_config_init(struct phy
95 /* Restore LED polarity state after reset */
96 - for_each_set_bit(led_active_low, &priv->leds_active_low, AQR_MAX_LEDS) {
97 - ret = aqr_phy_led_active_low_set(phydev, led_active_low, true);
98 + for_each_set_bit(led_idx, &priv->leds_active_low, AQR_MAX_LEDS) {
99 + ret = aqr_phy_led_active_low_set(phydev, led_idx, true);
104 + for_each_set_bit(led_idx, &priv->leds_active_high, AQR_MAX_LEDS) {
105 + ret = aqr_phy_led_active_low_set(phydev, led_idx, false);