[PATCH net-next v3 09/12] net: dsa: lantiq_gswip: add vendor property to setup MII refclk output

Daniel Golle posted 12 patches 3 months, 1 week ago
There is a newer version of this series
[PATCH net-next v3 09/12] net: dsa: lantiq_gswip: add vendor property to setup MII refclk output
Posted by Daniel Golle 3 months, 1 week ago
Read boolean Device Tree property "maxlinear,rmii-refclk-out" and switch
the RMII reference clock to be a clock output rather than an input if it
is set.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
---
 drivers/net/dsa/lantiq/lantiq_gswip_common.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/dsa/lantiq/lantiq_gswip_common.c b/drivers/net/dsa/lantiq/lantiq_gswip_common.c
index 60a83093cd10..bf38ecc13f76 100644
--- a/drivers/net/dsa/lantiq/lantiq_gswip_common.c
+++ b/drivers/net/dsa/lantiq/lantiq_gswip_common.c
@@ -1442,6 +1442,10 @@ static void gswip_phylink_mac_config(struct phylink_config *config,
 		return;
 	}
 
+	if (of_property_read_bool(dp->dn, "maxlinear,rmii-refclk-out") &&
+	    !(miicfg & GSWIP_MII_CFG_MODE_RGMII))
+		miicfg |= GSWIP_MII_CFG_RMII_CLK;
+
 	gswip_mii_mask_cfg(priv,
 			   GSWIP_MII_CFG_MODE_MASK | GSWIP_MII_CFG_RMII_CLK |
 			   GSWIP_MII_CFG_RGMII_IBS | GSWIP_MII_CFG_LDCLKDIS,
-- 
2.51.1
Re: [PATCH net-next v3 09/12] net: dsa: lantiq_gswip: add vendor property to setup MII refclk output
Posted by Vladimir Oltean 3 months, 1 week ago
On Sun, Oct 26, 2025 at 11:47:21PM +0000, Daniel Golle wrote:
> Read boolean Device Tree property "maxlinear,rmii-refclk-out" and switch
> the RMII reference clock to be a clock output rather than an input if it
> is set.
> 
> Signed-off-by: Daniel Golle <daniel@makrotopia.org>
> ---
>  drivers/net/dsa/lantiq/lantiq_gswip_common.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/net/dsa/lantiq/lantiq_gswip_common.c b/drivers/net/dsa/lantiq/lantiq_gswip_common.c
> index 60a83093cd10..bf38ecc13f76 100644
> --- a/drivers/net/dsa/lantiq/lantiq_gswip_common.c
> +++ b/drivers/net/dsa/lantiq/lantiq_gswip_common.c
> @@ -1442,6 +1442,10 @@ static void gswip_phylink_mac_config(struct phylink_config *config,
>  		return;
>  	}
>  
> +	if (of_property_read_bool(dp->dn, "maxlinear,rmii-refclk-out") &&
> +	    !(miicfg & GSWIP_MII_CFG_MODE_RGMII))
> +		miicfg |= GSWIP_MII_CFG_RMII_CLK;
> +

What did you mean with the !(miicfg & GSWIP_MII_CFG_MODE_RGMII) test?
If the schema says "Only applicable for RMII mode.", what's the purpose
of this extra condition? For example, GSWIP_MII_CFG_MODE_GMII also has
the "GSWIP_MII_CFG_MODE_RGMII" bit (0x4) unset. Does this have any significance?

>  	gswip_mii_mask_cfg(priv,
>  			   GSWIP_MII_CFG_MODE_MASK | GSWIP_MII_CFG_RMII_CLK |
>  			   GSWIP_MII_CFG_RGMII_IBS | GSWIP_MII_CFG_LDCLKDIS,
> -- 
> 2.51.1
Re: [PATCH net-next v3 09/12] net: dsa: lantiq_gswip: add vendor property to setup MII refclk output
Posted by Daniel Golle 3 months, 1 week ago
On Tue, Oct 28, 2025 at 01:36:26AM +0200, Vladimir Oltean wrote:
> On Sun, Oct 26, 2025 at 11:47:21PM +0000, Daniel Golle wrote:
> > Read boolean Device Tree property "maxlinear,rmii-refclk-out" and switch
> > the RMII reference clock to be a clock output rather than an input if it
> > is set.
> > 
> > Signed-off-by: Daniel Golle <daniel@makrotopia.org>
> > ---
> >  drivers/net/dsa/lantiq/lantiq_gswip_common.c | 4 ++++
> >  1 file changed, 4 insertions(+)
> > 
> > diff --git a/drivers/net/dsa/lantiq/lantiq_gswip_common.c b/drivers/net/dsa/lantiq/lantiq_gswip_common.c
> > index 60a83093cd10..bf38ecc13f76 100644
> > --- a/drivers/net/dsa/lantiq/lantiq_gswip_common.c
> > +++ b/drivers/net/dsa/lantiq/lantiq_gswip_common.c
> > @@ -1442,6 +1442,10 @@ static void gswip_phylink_mac_config(struct phylink_config *config,
> >  		return;
> >  	}
> >  
> > +	if (of_property_read_bool(dp->dn, "maxlinear,rmii-refclk-out") &&
> > +	    !(miicfg & GSWIP_MII_CFG_MODE_RGMII))
> > +		miicfg |= GSWIP_MII_CFG_RMII_CLK;
> > +
> 
> What did you mean with the !(miicfg & GSWIP_MII_CFG_MODE_RGMII) test?
> If the schema says "Only applicable for RMII mode.", what's the purpose
> of this extra condition? For example, GSWIP_MII_CFG_MODE_GMII also has
> the "GSWIP_MII_CFG_MODE_RGMII" bit (0x4) unset. Does this have any significance?

You are right, probably the best would be to test (if at all) that
(miicfg == GSWIP_MII_CFG_MODE_RMIIM || miicfg ==
GSWIP_MII_CFG_MODE_RMIIP) and only in this case allow setting the
GSWIP_MII_CFG_RMII_CLK bit.

I forgot that there is older hardware which supports "full" MII, and MII
MAC as well as MII PHY modes also shouldn't allow to set the
GSWIP_MII_CFG_RMII_CLK bit to not end up with undefined behavior.
Re: [PATCH net-next v3 09/12] net: dsa: lantiq_gswip: add vendor property to setup MII refclk output
Posted by Vladimir Oltean 3 months, 1 week ago
On Mon, Oct 27, 2025 at 11:48:26PM +0000, Daniel Golle wrote:
> On Tue, Oct 28, 2025 at 01:36:26AM +0200, Vladimir Oltean wrote:
> > On Sun, Oct 26, 2025 at 11:47:21PM +0000, Daniel Golle wrote:
> > > Read boolean Device Tree property "maxlinear,rmii-refclk-out" and switch
> > > the RMII reference clock to be a clock output rather than an input if it
> > > is set.
> > > 
> > > Signed-off-by: Daniel Golle <daniel@makrotopia.org>
> > > ---
> > >  drivers/net/dsa/lantiq/lantiq_gswip_common.c | 4 ++++
> > >  1 file changed, 4 insertions(+)
> > > 
> > > diff --git a/drivers/net/dsa/lantiq/lantiq_gswip_common.c b/drivers/net/dsa/lantiq/lantiq_gswip_common.c
> > > index 60a83093cd10..bf38ecc13f76 100644
> > > --- a/drivers/net/dsa/lantiq/lantiq_gswip_common.c
> > > +++ b/drivers/net/dsa/lantiq/lantiq_gswip_common.c
> > > @@ -1442,6 +1442,10 @@ static void gswip_phylink_mac_config(struct phylink_config *config,
> > >  		return;
> > >  	}
> > >  
> > > +	if (of_property_read_bool(dp->dn, "maxlinear,rmii-refclk-out") &&
> > > +	    !(miicfg & GSWIP_MII_CFG_MODE_RGMII))
> > > +		miicfg |= GSWIP_MII_CFG_RMII_CLK;
> > > +
> > 
> > What did you mean with the !(miicfg & GSWIP_MII_CFG_MODE_RGMII) test?
> > If the schema says "Only applicable for RMII mode.", what's the purpose
> > of this extra condition? For example, GSWIP_MII_CFG_MODE_GMII also has
> > the "GSWIP_MII_CFG_MODE_RGMII" bit (0x4) unset. Does this have any significance?
> 
> You are right, probably the best would be to test (if at all) that
> (miicfg == GSWIP_MII_CFG_MODE_RMIIM || miicfg ==
> GSWIP_MII_CFG_MODE_RMIIP) and only in this case allow setting the
> GSWIP_MII_CFG_RMII_CLK bit.
> 
> I forgot that there is older hardware which supports "full" MII, and MII
> MAC as well as MII PHY modes also shouldn't allow to set the
> GSWIP_MII_CFG_RMII_CLK bit to not end up with undefined behavior.

Yeah, actually you'd be looking at FIELD_GET(GSWIP_MII_CFG_MODE_MASK, miicfg)
rather than miicfg directly.

If the schema restricted "maxlinear,rmii-refclk-out" to be used only in
combination with phy-mode = "rmii" and "rev-rmii", in theory that should
be sufficient with no further driver checks. But some checks that at
least make sense don't seem to hurt.