Re: [PATCH net-next] net: phy: intel-xway: add support for PHY LEDs

From: Daniel Golle
Date: Wed Oct 09 2024 - 08:32:47 EST


On Wed, Oct 09, 2024 at 02:16:29PM +0200, Andrew Lunn wrote:
> > +static int xway_gphy_led_polarity_set(struct phy_device *phydev, int index,
> > + unsigned long modes)
> > +{
> > + bool active_low = false;
> > + u32 mode;
> > +
> > + if (index >= XWAY_GPHY_MAX_LEDS)
> > + return -EINVAL;
> > +
> > + for_each_set_bit(mode, &modes, __PHY_LED_MODES_NUM) {
> > + switch (mode) {
> > + case PHY_LED_ACTIVE_LOW:
> > + active_low = true;
> > + break;
> > + case PHY_LED_ACTIVE_HIGH:
> > + break;
> > + default:
> > + return -EINVAL;
> > + }
> > + }
> > +
> > + return phy_modify(phydev, XWAY_MDIO_LED, XWAY_GPHY_LED_INV(index),
> > + active_low ? XWAY_GPHY_LED_INV(index) : 0);
>
> This does not appear to implement the 'leave it alone' option.

The framework already implements that. The function is never called with
modes == 0.
See commit 7ae215ee7bb8 net: phy: add support for PHY LEDs polarity modes:

if (of_property_read_bool(led, "active-low"))
set_bit(PHY_LED_ACTIVE_LOW, &modes);
if (of_property_read_bool(led, "inactive-high-impedance"))
set_bit(PHY_LED_INACTIVE_HIGH_IMPEDANCE, &modes);

if (modes) {
/* Return error if asked to set polarity modes but not supported */
if (!phydev->drv->led_polarity_set)
return -EINVAL;

err = phydev->drv->led_polarity_set(phydev, index, modes);
if (err)
return err;
}

So in case none of the LED polarity properties are set in DT, modes is 0
and hence led_polarity_set() isn't called.

I considered to change that with my suggested patch
https://patchwork.kernel.org/project/netdevbpf/patch/473d62f268f2a317fd81d0f38f15d2f2f98e2451.1728056697.git.daniel@xxxxxxxxxxxxxx/

But it was rightously critizised for breaking existing DT which assume
LED polarity not being touched if none of the polarity properties are
present.