diff mbox series

[v3,04/16] net: phy: Add helper for mapping RGMII link speed to clock rate

Message ID 20241013-upstream_s32cc_gmac-v3-4-d84b5a67b930@oss.nxp.com (mailing list archive)
State Changes Requested
Headers show
Series Add support for Synopsis DWMAC IP on NXP Automotive SoCs S32G2xx/S32G3xx/S32R45 | expand

Checks

Context Check Description
netdev/series_format fail Series longer than 15 patches
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 5 this patch: 5
netdev/build_tools success Errors and warnings before: 0 (+1) this patch: 0 (+1)
netdev/cc_maintainers success CCed 4 of 4 maintainers
netdev/build_clang success Errors and warnings before: 16 this patch: 16
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 389 this patch: 389
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 27 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc fail Errors and warnings before: 30 this patch: 31
netdev/source_inline success Was 0 now: 0

Commit Message

Jan Petrous via B4 Relay Oct. 13, 2024, 9:27 p.m. UTC
From: "Jan Petrous (OSS)" <jan.petrous@oss.nxp.com>

The helper rgmii_clock() implemented Russel's hint during stmmac
glue driver review:

  > We seem to have multiple cases of very similar logic in lots of stmmac
  > platform drivers, and I think it's about time we said no more to this.
  > So, what I think we should do is as follows:
  >
  > add the following helper - either in stmmac, or more generically
  > (phylib? - in which case its name will need changing.)
  >
  > static long stmmac_get_rgmii_clock(int speed)
  > {
  >        switch (speed) {
  >        case SPEED_10:
  >                return 2500000;
  >
  >        case SPEED_100:
  >                return 25000000;
  >
  >        case SPEED_1000:
  >                return 125000000;
  >
  >        default:
  >                return -ENVAL;
  >        }
  > }
  >
  > Then, this can become:
  >
  >        long tx_clk_rate;
  >
  >        ...
  >
  >        tx_clk_rate = stmmac_get_rgmii_clock(speed);
  >        if (tx_clk_rate < 0) {
  >                dev_err(gmac->dev, "Unsupported/Invalid speed: %d\n", speed);
  >                return;
  >        }
  >
  >        ret = clk_set_rate(gmac->tx_clk, tx_clk_rate);

Suggested-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Signed-off-by: Jan Petrous (OSS) <jan.petrous@oss.nxp.com>
---
 include/linux/phy.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

Comments

Andrew Lunn Oct. 14, 2024, 1:40 p.m. UTC | #1
On Sun, Oct 13, 2024 at 11:27:39PM +0200, Jan Petrous via B4 Relay wrote:
> From: "Jan Petrous (OSS)" <jan.petrous@oss.nxp.com>
> 
> The helper rgmii_clock() implemented Russel's hint during stmmac
> glue driver review:
> 
>   > We seem to have multiple cases of very similar logic in lots of stmmac
>   > platform drivers, and I think it's about time we said no more to this.
>   > So, what I think we should do is as follows:
>   >
>   > add the following helper - either in stmmac, or more generically
>   > (phylib? - in which case its name will need changing.)
>   >
>   > static long stmmac_get_rgmii_clock(int speed)
>   > {
>   >        switch (speed) {
>   >        case SPEED_10:
>   >                return 2500000;
>   >
>   >        case SPEED_100:
>   >                return 25000000;
>   >
>   >        case SPEED_1000:
>   >                return 125000000;
>   >
>   >        default:
>   >                return -ENVAL;
>   >        }
>   > }
>   >
>   > Then, this can become:
>   >
>   >        long tx_clk_rate;
>   >
>   >        ...
>   >
>   >        tx_clk_rate = stmmac_get_rgmii_clock(speed);
>   >        if (tx_clk_rate < 0) {
>   >                dev_err(gmac->dev, "Unsupported/Invalid speed: %d\n", speed);
>   >                return;
>   >        }
>   >
>   >        ret = clk_set_rate(gmac->tx_clk, tx_clk_rate);
> 
> Suggested-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
> Signed-off-by: Jan Petrous (OSS) <jan.petrous@oss.nxp.com>

But of an unusual commit message, but it does explain the "Why?".

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

>  
> +/**
> + * rgmii_clock - map link speed to the clock rate
> + * @speed: link speed value
> + *
> + * Description: maps RGMII supported link speeds
> + * into the clock rates.
> + */

A Returns: line would be nice. 

	Andrew
Jan Petrous Oct. 28, 2024, 8:12 p.m. UTC | #2
On Mon, Oct 14, 2024 at 03:40:51PM +0200, Andrew Lunn wrote:
> On Sun, Oct 13, 2024 at 11:27:39PM +0200, Jan Petrous via B4 Relay wrote:
> > From: "Jan Petrous (OSS)" <jan.petrous@oss.nxp.com>
> > 
> > The helper rgmii_clock() implemented Russel's hint during stmmac
> > glue driver review:
> > 
> >   > We seem to have multiple cases of very similar logic in lots of stmmac
> >   > platform drivers, and I think it's about time we said no more to this.
> >   > So, what I think we should do is as follows:
> >   >
> >   > add the following helper - either in stmmac, or more generically
> >   > (phylib? - in which case its name will need changing.)
> >   >
> >   > static long stmmac_get_rgmii_clock(int speed)
> >   > {
> >   >        switch (speed) {
> >   >        case SPEED_10:
> >   >                return 2500000;
> >   >
> >   >        case SPEED_100:
> >   >                return 25000000;
> >   >
> >   >        case SPEED_1000:
> >   >                return 125000000;
> >   >
> >   >        default:
> >   >                return -ENVAL;
> >   >        }
> >   > }
> >   >
> >   > Then, this can become:
> >   >
> >   >        long tx_clk_rate;
> >   >
> >   >        ...
> >   >
> >   >        tx_clk_rate = stmmac_get_rgmii_clock(speed);
> >   >        if (tx_clk_rate < 0) {
> >   >                dev_err(gmac->dev, "Unsupported/Invalid speed: %d\n", speed);
> >   >                return;
> >   >        }
> >   >
> >   >        ret = clk_set_rate(gmac->tx_clk, tx_clk_rate);
> > 
> > Suggested-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
> > Signed-off-by: Jan Petrous (OSS) <jan.petrous@oss.nxp.com>
> 
> But of an unusual commit message, but it does explain the "Why?".

I will reformulate description in v4.

> 
> Reviewed-by: Andrew Lunn <andrew@lunn.ch>
> 

Thanks.

> >  
> > +/**
> > + * rgmii_clock - map link speed to the clock rate
> > + * @speed: link speed value
> > + *
> > + * Description: maps RGMII supported link speeds
> > + * into the clock rates.
> > + */
> 
> A Returns: line would be nice. 

 will add it in v4.

Thanks
/Jan
diff mbox series

Patch

diff --git a/include/linux/phy.h b/include/linux/phy.h
index a98bc91a0cde..7f6d9e7533ce 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -298,6 +298,27 @@  static inline const char *phy_modes(phy_interface_t interface)
 	}
 }
 
+/**
+ * rgmii_clock - map link speed to the clock rate
+ * @speed: link speed value
+ *
+ * Description: maps RGMII supported link speeds
+ * into the clock rates.
+ */
+static inline long rgmii_clock(int speed)
+{
+	switch (speed) {
+	case SPEED_10:
+		return 2500000;
+	case SPEED_100:
+		return 25000000;
+	case SPEED_1000:
+		return 125000000;
+	default:
+		return -EINVAL;
+	}
+}
+
 #define PHY_INIT_TIMEOUT	100000
 #define PHY_FORCE_TIMEOUT	10