f26bb829e45c79c9f9276964c387e211b7628c16
[openwrt/staging/wigyori.git] /
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
5 override
6
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.
13
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>
18 ---
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(-)
23
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
27 struct aqr107_priv {
28 u64 sgmii_stats[AQR107_SGMII_STAT_SZ];
29 unsigned long leds_active_low;
30 + unsigned long leds_active_high;
31 };
32
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
37 {
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);
42 }
43
44 int aqr_phy_led_polarity_set(struct phy_device *phydev, int index, unsigned long modes)
45 {
46 + bool force_active_low = false, force_active_high = false;
47 struct aqr107_priv *priv = phydev->priv;
48 - bool active_low = false;
49 u32 mode;
50
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) {
54 switch (mode) {
55 case PHY_LED_ACTIVE_LOW:
56 - active_low = true;
57 + force_active_low = true;
58 + break;
59 + case PHY_LED_ACTIVE_HIGH:
60 + force_active_high = true;
61 break;
62 default:
63 return -EINVAL;
64 @@ -144,8 +147,14 @@ int aqr_phy_led_polarity_set(struct phy_
65 }
66
67 /* Save LED driver vdd state to restore on SW reset */
68 - if (active_low)
69 + if (force_active_low)
70 priv->leds_active_low |= BIT(index);
71
72 - return aqr_phy_led_active_low_set(phydev, index, active_low);
73 + if (force_active_high)
74 + priv->leds_active_high |= BIT(index);
75 +
76 + if (force_active_high || force_active_low)
77 + return aqr_phy_led_active_low_set(phydev, index, force_active_low);
78 +
79 + unreachable();
80 }
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)
85 {
86 struct aqr107_priv *priv = phydev->priv;
87 - u32 led_active_low;
88 + u32 led_idx;
89 int ret;
90
91 /* Check that the PHY interface type is compatible */
92 @@ -569,8 +569,14 @@ static int aqr107_config_init(struct phy
93 return ret;
94
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);
100 + if (ret)
101 + return ret;
102 + }
103 +
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);
106 if (ret)
107 return ret;
108 }