* [PATCH net-next v4] net: phy: marvell: add support for PHY LEDs polarity modes
@ 2026-11-24 18:11 Aleksander Jan Bajkowski
2026-11-24 21:07 ` Andrew Lunn
2026-11-25 14:53 ` netdev-bot+sashiko
0 siblings, 2 replies; 3+ messages in thread
From: Aleksander Jan Bajkowski @ 2026-11-24 18:11 UTC (permalink / raw)
To: skyline, andrew, hkallweit1, linux, davem, edumazet, kuba, pabeni,
netdev
Cc: Aleksander Jan Bajkowski
Add the led_polarity_set callback for setting LED polarity. Implement
this callback for the 88E1116R, 88E1318 and 88E1510 PHYs. This should
also work on other Marvell PHYs, but I don't have access to the TRM or
the hardware.
Tested on Adapteva Paralella board with Marvell 88E1318 PHY.
Signed-off-by: Aleksander Jan Bajkowski <olek2@wp.pl>
---
Changes in v4:
- Throw out restiring polarity setting after hardware reset
Changes in v3:
- Restore polarity settings after hardware reset
- Enable polarity control on 88E1116R
Changes in v2:
- Add support for PHY_LED_INACTIVE_HIGH_IMPEDANCE mode
---
drivers/net/phy/marvell.c | 40 ++++++++++++++++++++++++++++++++++++++-
1 file changed, 39 insertions(+), 1 deletion(-)
diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c
index 87f66dfa92dd..00ce215bb71b 100644
--- a/drivers/net/phy/marvell.c
+++ b/drivers/net/phy/marvell.c
@@ -146,6 +146,9 @@
#define MII_88E1318S_PHY_LED_FUNC_ON (0x9)
#define MII_88E1318S_PHY_LED_FUNC_HI_Z (0xa)
#define MII_88E1318S_PHY_LED_FUNC_BLINK (0xb)
+#define MII_88E1318S_PHY_LED_POL 0x11
+#define MII_88E1318S_PHY_LED_POL_ACT_HIGH(idx) BIT(2 * (idx))
+#define MII_88E1318S_PHY_LED_POL_HIGH_IMP(idx) BIT(2 * (idx) + 1)
#define MII_88E1318S_PHY_LED_TCR 0x12
#define MII_88E1318S_PHY_LED_TCR_FORCE_INT BIT(15)
#define MII_88E1318S_PHY_LED_TCR_INTn_ENABLE BIT(7)
@@ -301,6 +304,8 @@
#define NB_FIBER_STATS 1
#define NB_STAT_MAX 3
+#define M88E1318S_MAX_LEDS 3
+
MODULE_DESCRIPTION("Marvell PHY driver");
MODULE_AUTHOR("Andy Fleming");
MODULE_LICENSE("GPL");
@@ -3625,7 +3630,7 @@ static int m88e1318_led_hw_control_get(struct phy_device *phydev, u8 index,
{
int mode, reg;
- if (index > 2)
+ if (index >= M88E1318S_MAX_LEDS)
return -EINVAL;
reg = phy_read_paged(phydev, MII_MARVELL_LED_PAGE,
@@ -3638,6 +3643,36 @@ static int m88e1318_led_hw_control_get(struct phy_device *phydev, u8 index,
return marvell_get_led_rules(index, rules, mode);
}
+static int m88e1318_led_polarity_set(struct phy_device *phydev, int index,
+ unsigned long modes)
+{
+ u16 val = 0;
+ u32 mode;
+
+ if (index >= M88E1318S_MAX_LEDS)
+ return -EINVAL;
+
+ for_each_set_bit(mode, &modes, __PHY_LED_MODES_NUM) {
+ switch (mode) {
+ case PHY_LED_ACTIVE_LOW:
+ break;
+ case PHY_LED_ACTIVE_HIGH:
+ val |= MII_88E1318S_PHY_LED_POL_ACT_HIGH(index);
+ break;
+ case PHY_LED_INACTIVE_HIGH_IMPEDANCE:
+ val |= MII_88E1318S_PHY_LED_POL_HIGH_IMP(index);
+ break;
+ default:
+ return -EINVAL;
+ }
+ }
+
+ return phy_modify_paged(phydev, MII_MARVELL_LED_PAGE,
+ MII_88E1318S_PHY_LED_POL,
+ MII_88E1318S_PHY_LED_POL_ACT_HIGH(index) |
+ MII_88E1318S_PHY_LED_POL_HIGH_IMP(index), val);
+}
+
static int marvell_probe(struct phy_device *phydev)
{
struct marvell_priv *priv;
@@ -3886,6 +3921,7 @@ static struct phy_driver marvell_drivers[] = {
.led_hw_is_supported = m88e1318_led_hw_is_supported,
.led_hw_control_set = m88e1318_led_hw_control_set,
.led_hw_control_get = m88e1318_led_hw_control_get,
+ .led_polarity_set = m88e1318_led_polarity_set,
},
{
.phy_id = MARVELL_PHY_ID_88E1145,
@@ -3971,6 +4007,7 @@ static struct phy_driver marvell_drivers[] = {
.led_hw_is_supported = m88e1318_led_hw_is_supported,
.led_hw_control_set = m88e1318_led_hw_control_set,
.led_hw_control_get = m88e1318_led_hw_control_get,
+ .led_polarity_set = m88e1318_led_polarity_set,
},
{
.phy_id = MARVELL_PHY_ID_88E1510,
@@ -4005,6 +4042,7 @@ static struct phy_driver marvell_drivers[] = {
.led_hw_is_supported = m88e1318_led_hw_is_supported,
.led_hw_control_set = m88e1318_led_hw_control_set,
.led_hw_control_get = m88e1318_led_hw_control_get,
+ .led_polarity_set = m88e1318_led_polarity_set,
.attach_mii_port = m88e1510_attach_mii_port,
},
{
--
2.55.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net-next v4] net: phy: marvell: add support for PHY LEDs polarity modes
2026-11-24 18:11 [PATCH net-next v4] net: phy: marvell: add support for PHY LEDs polarity modes Aleksander Jan Bajkowski
@ 2026-11-24 21:07 ` Andrew Lunn
2026-11-25 14:53 ` netdev-bot+sashiko
1 sibling, 0 replies; 3+ messages in thread
From: Andrew Lunn @ 2026-11-24 21:07 UTC (permalink / raw)
To: Aleksander Jan Bajkowski
Cc: skyline, hkallweit1, linux, davem, edumazet, kuba, pabeni, netdev
On Tue, Nov 24, 2026 at 07:11:35PM +0100, Aleksander Jan Bajkowski wrote:
> Add the led_polarity_set callback for setting LED polarity. Implement
> this callback for the 88E1116R, 88E1318 and 88E1510 PHYs. This should
> also work on other Marvell PHYs, but I don't have access to the TRM or
> the hardware.
>
> Tested on Adapteva Paralella board with Marvell 88E1318 PHY.
>
> Signed-off-by: Aleksander Jan Bajkowski <olek2@wp.pl>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Andrew
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net-next v4] net: phy: marvell: add support for PHY LEDs polarity modes
2026-11-24 18:11 [PATCH net-next v4] net: phy: marvell: add support for PHY LEDs polarity modes Aleksander Jan Bajkowski
2026-11-24 21:07 ` Andrew Lunn
@ 2026-11-25 14:53 ` netdev-bot+sashiko
1 sibling, 0 replies; 3+ messages in thread
From: netdev-bot+sashiko @ 2026-11-25 14:53 UTC (permalink / raw)
To: olek2
Cc: skyline, andrew, hkallweit1, linux, davem, edumazet, kuba, pabeni,
netdev
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] In drivers/net/phy/marvell.c, m88e1318_led_polarity_set()
treats @modes as a complete description of the LED polarity.
- [Medium] In drivers/net/phy/marvell.c, page 3 register 0x11 (LED
polarity) is written only once, from of_phy_led() during phy_probe(),…
--
net: phy: marvell: add support for PHY LEDs polarity modes
This patch adds a led_polarity_set callback for the 88E1116R, 88E1318 and
88E1510 PHYs. The callback programs the per-LED active-high and
high-impedance bits in the LED polarity register (page 3, register 0x11).
> diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c
> index 87f66dfa92dda..00ce215bb71ba 100644
> --- a/drivers/net/phy/marvell.c
> +++ b/drivers/net/phy/marvell.c
[ ... ]
> @@ -3638,6 +3643,36 @@ static int m88e1318_led_hw_control_get(struct phy_device *phydev, u8 index,
> return marvell_get_led_rules(index, rules, mode);
> }
>
> +static int m88e1318_led_polarity_set(struct phy_device *phydev, int index,
> + unsigned long modes)
> +{
> + u16 val = 0;
> + u32 mode;
> +
> + if (index >= M88E1318S_MAX_LEDS)
> + return -EINVAL;
> +
> + for_each_set_bit(mode, &modes, __PHY_LED_MODES_NUM) {
> + switch (mode) {
> + case PHY_LED_ACTIVE_LOW:
> + break;
> + case PHY_LED_ACTIVE_HIGH:
> + val |= MII_88E1318S_PHY_LED_POL_ACT_HIGH(index);
> + break;
> + case PHY_LED_INACTIVE_HIGH_IMPEDANCE:
> + val |= MII_88E1318S_PHY_LED_POL_HIGH_IMP(index);
> + break;
> + default:
> + return -EINVAL;
> + }
> + }
> +
> + return phy_modify_paged(phydev, MII_MARVELL_LED_PAGE,
> + MII_88E1318S_PHY_LED_POL,
> + MII_88E1318S_PHY_LED_POL_ACT_HIGH(index) |
> + MII_88E1318S_PHY_LED_POL_HIGH_IMP(index), val);
[Severity: Medium]
What happens here when the DT LED node only has inactive-high-impedance?
of_phy_led() sets each mode bit on its own and calls ->led_polarity_set()
whenever modes is non-zero:
drivers/net/phy/phy_device.c:of_phy_led() {
...
if (of_property_read_bool(led, "inactive-high-impedance"))
set_bit(PHY_LED_INACTIVE_HIGH_IMPEDANCE, &modes);
...
if (modes) {
...
err = phydev->drv->led_polarity_set(phydev, index, modes);
...
}
In that case val holds only HIGH_IMP(index), but the mask always includes
ACT_HIGH(index). The on-state polarity is then forced to active-low, and
the reset or bootloader value is lost.
The binding in Documentation/devicetree/bindings/leds/common.yaml describes
inactive-high-impedance only as the off state ("Set LED to high-impedance
mode to turn the LED OFF"). The on state has its own active-high and
active-low properties.
Other implementers of this op that pick a default when neither property
is given choose active-high:
- dp83867_led_polarity_set() ("Default active high")
- as21xxx
- an8801r_led_polarity_set()
- an7581_phy_led_polarity_set()
- qca808x
gpy, xway and aqr reject any request that doesn't explicitly ask for
active-low or active-high.
On a board with an active-high LED and only inactive-high-impedance in the
DT, wouldn't the LED end up as "on = drive low, off = tristate" and never
light?
The reverse also happens: active-high or active-low on its own clears any
tristate-off setting already in the register.
Could ACT_HIGH(index) be touched only when active-high or active-low is
explicitly present in modes? Otherwise, could it be documented that an
unspecified on-state polarity means active-low?
[Severity: Medium]
Is this polarity setting lost after a PHY hardware reset?
This is the only place register 0x11 is written. It runs once, from
of_phy_led() during phy_probe(), and the requested modes are not saved in
struct marvell_priv.
On boards with a reset GPIO or reset controller, an ndo_stop/ndo_open
cycle in MAC drivers that connect the PHY on open goes through:
phy_disconnect()->phy_detach()
phy_device_reset(phydev, 1);
phy_attach_direct()->phy_init_hw()
phy_device_reset(phydev, 0);
...
phydev->drv->config_init(phydev);
marvell_config_init()->marvell_config_led() rewrites only the LED function
register (16), plus the optional marvell,reg-init values. Nothing writes
the polarity register again. of_phy_led() is not re-run either, because
the LED classdevs stay registered.
After the first ifdown/ifup, wouldn't an active-high LED be inverted, and
an inactive-high-impedance LED be driven again when off?
aqr107_config_init() saves the polarity and reapplies it ("Restore LED
polarity state after reset"). qca808x does the same with
priv->led_polarity_mode in config_init.
The v3 changelog had "Restore polarity settings after hardware reset", and
the v4 changelog says "Throw out restiring polarity setting after hardware
reset". The commit message gives no reason for dropping it and does not
mention the limitation.
Could the restore be brought back, or the reason and limitation be added
to the commit message?
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124202054.1070702-1-olek2%40wp.pl
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-25 14:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 18:11 [PATCH net-next v4] net: phy: marvell: add support for PHY LEDs polarity modes Aleksander Jan Bajkowski
2026-11-24 21:07 ` Andrew Lunn
2026-11-25 14:53 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox