Re: [net-next,PATCH v2] net: phy: realtek: Add support for PHY LEDs on RTL8211F
From: Simon Horman
Date: Sat Jun 29 2024 - 05:16:15 EST
On Fri, Jun 28, 2024 at 08:58:51PM +0200, Marek Vasut wrote:
> On 6/28/24 4:27 PM, Simon Horman wrote:
> > On Tue, Jun 25, 2024 at 10:42:17PM +0200, Marek Vasut wrote:
> > > Realtek RTL8211F Ethernet PHY supports 3 LED pins which are used to
> > > indicate link status and activity. Add minimal LED controller driver
> > > supporting the most common uses with the 'netdev' trigger.
> > >
> > > Signed-off-by: Marek Vasut <marex@xxxxxxx>
> > > ---
> > > Cc: Alexandre Torgue <alexandre.torgue@xxxxxxxxxxx>
> > > Cc: Andrew Lunn <andrew@xxxxxxx>
> > > Cc: Christophe Roullier <christophe.roullier@xxxxxxxxxxx>
> > > Cc: David S. Miller <davem@xxxxxxxxxxxxx>
> > > Cc: Eric Dumazet <edumazet@xxxxxxxxxx>
> > > Cc: Heiner Kallweit <hkallweit1@xxxxxxxxx>
> > > Cc: Jakub Kicinski <kuba@xxxxxxxxxx>
> > > Cc: Paolo Abeni <pabeni@xxxxxxxxxx>
> > > Cc: Russell King <linux@xxxxxxxxxxxxxxx>
> > > Cc: kernel@xxxxxxxxxxxxxxxxxx
> > > Cc: linux-kernel@xxxxxxxxxxxxxxx
> > > Cc: netdev@xxxxxxxxxxxxxxx
> > > ---
> > > V2: - RX and TX are not differentiated, either both are set or not set,
> > > filter this in rtl8211f_led_hw_is_supported()
> > > ---
> > > drivers/net/phy/realtek.c | 106 ++++++++++++++++++++++++++++++++++++++
> > > 1 file changed, 106 insertions(+)
> > >
> > > diff --git a/drivers/net/phy/realtek.c b/drivers/net/phy/realtek.c
> > > index 2174893c974f3..bed839237fb55 100644
> > > --- a/drivers/net/phy/realtek.c
> > > +++ b/drivers/net/phy/realtek.c
> > > @@ -32,6 +32,15 @@
> > > #define RTL8211F_PHYCR2 0x19
> > > #define RTL8211F_INSR 0x1d
> > > +#define RTL8211F_LEDCR 0x10
> > > +#define RTL8211F_LEDCR_MODE BIT(15)
> > > +#define RTL8211F_LEDCR_ACT_TXRX BIT(4)
> > > +#define RTL8211F_LEDCR_LINK_1000 BIT(3)
> > > +#define RTL8211F_LEDCR_LINK_100 BIT(1)
> > > +#define RTL8211F_LEDCR_LINK_10 BIT(0)
> > > +#define RTL8211F_LEDCR_MASK GENMASK(4, 0)
> > > +#define RTL8211F_LEDCR_SHIFT 5
> > > +
> >
> > Hi Marek,
> >
> > FWIIW, I think that if you use FIELD_PREP and FIELD_GET then
> > RTL8211F_LEDCR_SHIFT can be removed.
>
> FIELD_PREP/FIELD_GET only works for constant mask, in this case the mask is
> not constant but shifted by SHIFT*index .
>
> Other drivers introduce workarounds like this for exactly this issue:
>
> drivers/clk/at91/pmc.h:#define field_prep(_mask, _val) (((_val) <<
> (ffs(_mask) - 1)) & (_mask))
>
> I don't think it is worth perpetuating that.
Thanks Marek,
Sorry for missing that the mask is not constant.
And in that case I agree with the approach you have taken in this patch.