Subject: Re: [net-next,PATCH v2] net: phy: realtek: Add support for PHY LEDs on RTL8211F

From: Simon Horman <[email-masked]>
Date: Sat, 29 Jun 2024 10:16:02 +0100

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 <[email-masked]>
> > > ---
> > > Cc: Alexandre Torgue <[email-masked]>
> > > Cc: Andrew Lunn <[email-masked]>
> > > Cc: Christophe Roullier <[email-masked]>
> > > Cc: David S. Miller <[email-masked]>
> > > Cc: Eric Dumazet <[email-masked]>
> > > Cc: Heiner Kallweit <[email-masked]>
> > > Cc: Jakub Kicinski <[email-masked]>
> > > Cc: Paolo Abeni <[email-masked]>
> > > Cc: Russell King <[email-masked]>
> > > Cc: [email-masked]
> > > Cc: [email-masked]
> > > Cc: [email-masked]
> > > ---
> > > 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.