devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jan Petrous via B4 Relay <devnull+jan.petrous.oss.nxp.com@kernel.org>
To: Maxime Coquelin <mcoquelin.stm32@gmail.com>,
	 Alexandre Torgue <alexandre.torgue@foss.st.com>,
	 Jose Abreu <joabreu@synopsys.com>,
	"David S. Miller" <davem@davemloft.net>,
	 Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>,
	 Paolo Abeni <pabeni@redhat.com>, Vinod Koul <vkoul@kernel.org>,
	 Richard Cochran <richardcochran@gmail.com>,
	Andrew Lunn <andrew@lunn.ch>,
	 Heiner Kallweit <hkallweit1@gmail.com>,
	 Russell King <linux@armlinux.org.uk>,
	Shawn Guo <shawnguo@kernel.org>,
	 Sascha Hauer <s.hauer@pengutronix.de>,
	 Pengutronix Kernel Team <kernel@pengutronix.de>,
	 Fabio Estevam <festevam@gmail.com>,
	Emil Renner Berthing <kernel@esmil.dk>,
	 Minda Chen <minda.chen@starfivetech.com>,
	 Nicolas Ferre <nicolas.ferre@microchip.com>,
	 Claudiu Beznea <claudiu.beznea@tuxon.dev>,
	 Iyappan Subramanian <iyappan@os.amperecomputing.com>,
	 Keyur Chudgar <keyur@os.amperecomputing.com>,
	 Quan Nguyen <quan@os.amperecomputing.com>,
	Rob Herring <robh@kernel.org>,
	 Krzysztof Kozlowski <krzk+dt@kernel.org>,
	 Conor Dooley <conor+dt@kernel.org>,
	 Giuseppe Cavallaro <peppe.cavallaro@st.com>
Cc: linux-stm32@st-md-mailman.stormreply.com,
	 linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org,  netdev@vger.kernel.org,
	linux-arm-msm@vger.kernel.org, imx@lists.linux.dev,
	 devicetree@vger.kernel.org, NXP S32 Linux Team <s32@nxp.com>,
	 "Jan Petrous (OSS)" <jan.petrous@oss.nxp.com>,
	 "Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>
Subject: [PATCH v3 04/16] net: phy: Add helper for mapping RGMII link speed to clock rate
Date: Sun, 13 Oct 2024 23:27:39 +0200	[thread overview]
Message-ID: <20241013-upstream_s32cc_gmac-v3-4-d84b5a67b930@oss.nxp.com> (raw)
In-Reply-To: <20241013-upstream_s32cc_gmac-v3-0-d84b5a67b930@oss.nxp.com>

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(+)

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
 

-- 
2.46.0



  parent reply	other threads:[~2024-10-13 21:27 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-13 21:27 [PATCH v3 00/16] Add support for Synopsis DWMAC IP on NXP Automotive SoCs S32G2xx/S32G3xx/S32R45 Jan Petrous via B4 Relay
2024-10-13 21:27 ` [PATCH v3 01/16] net: driver: stmmac: Fix CSR divider comment Jan Petrous via B4 Relay
2024-10-13 21:27 ` [PATCH v3 02/16] net: driver: stmmac: Extend CSR calc support Jan Petrous via B4 Relay
2024-10-13 21:27 ` [PATCH v3 03/16] net: stmmac: Fix clock rate variables size Jan Petrous via B4 Relay
2024-10-13 21:27 ` Jan Petrous via B4 Relay [this message]
2024-10-14 13:40   ` [PATCH v3 04/16] net: phy: Add helper for mapping RGMII link speed to clock rate Andrew Lunn
2024-10-28 20:12     ` Jan Petrous
2024-10-13 21:27 ` [PATCH v3 05/16] net: dwmac-dwc-qos-eth: Use helper rgmii_clock Jan Petrous via B4 Relay
2024-10-14 13:46   ` Andrew Lunn
2024-10-14 21:40     ` Jan Petrous
2024-10-13 21:27 ` [PATCH v3 06/16] net: dwmac-imx: " Jan Petrous via B4 Relay
2024-10-13 21:27 ` [PATCH v3 07/16] net: dwmac-intel-plat: " Jan Petrous via B4 Relay
2024-10-13 21:27 ` [PATCH v3 08/16] net: dwmac-rk: " Jan Petrous via B4 Relay
2024-10-13 21:27 ` [PATCH v3 09/16] net: dwmac-starfive: " Jan Petrous via B4 Relay
2024-10-13 21:27 ` [PATCH v3 10/16] net: macb: " Jan Petrous via B4 Relay
2024-10-13 21:27 ` [PATCH v3 11/16] net: xgene_enet: " Jan Petrous via B4 Relay
2024-10-13 21:27 ` [PATCH v3 12/16] net: dwmac-sti: " Jan Petrous via B4 Relay
2024-10-13 21:27 ` [PATCH v3 13/16] dt-bindings: net: Add DT bindings for DWMAC on NXP S32G/R SoCs Jan Petrous via B4 Relay
2024-10-14  6:56   ` Krzysztof Kozlowski
2024-10-14  7:48     ` Jan Petrous
2024-10-14  8:24       ` Krzysztof Kozlowski
2024-10-13 21:27 ` [PATCH v3 14/16] net: stmmac: dwmac-s32: add basic NXP S32G/S32R glue driver Jan Petrous via B4 Relay
2024-10-16  9:37   ` Uwe Kleine-König
2024-10-16 10:11     ` Jan Petrous
2024-10-13 21:27 ` [PATCH v3 15/16] MAINTAINERS: Add Jan Petrous as the NXP S32G/R DWMAC driver maintainer Jan Petrous via B4 Relay
2024-10-13 21:27 ` [PATCH v3 16/16] net: stmmac: dwmac-s32: Read PTP clock rate when ready Jan Petrous via B4 Relay

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241013-upstream_s32cc_gmac-v3-4-d84b5a67b930@oss.nxp.com \
    --to=devnull+jan.petrous.oss.nxp.com@kernel.org \
    --cc=alexandre.torgue@foss.st.com \
    --cc=andrew@lunn.ch \
    --cc=claudiu.beznea@tuxon.dev \
    --cc=conor+dt@kernel.org \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=edumazet@google.com \
    --cc=festevam@gmail.com \
    --cc=hkallweit1@gmail.com \
    --cc=imx@lists.linux.dev \
    --cc=iyappan@os.amperecomputing.com \
    --cc=jan.petrous@oss.nxp.com \
    --cc=joabreu@synopsys.com \
    --cc=kernel@esmil.dk \
    --cc=kernel@pengutronix.de \
    --cc=keyur@os.amperecomputing.com \
    --cc=krzk+dt@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=linux@armlinux.org.uk \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=minda.chen@starfivetech.com \
    --cc=netdev@vger.kernel.org \
    --cc=nicolas.ferre@microchip.com \
    --cc=pabeni@redhat.com \
    --cc=peppe.cavallaro@st.com \
    --cc=quan@os.amperecomputing.com \
    --cc=richardcochran@gmail.com \
    --cc=rmk+kernel@armlinux.org.uk \
    --cc=robh@kernel.org \
    --cc=s.hauer@pengutronix.de \
    --cc=s32@nxp.com \
    --cc=shawnguo@kernel.org \
    --cc=vkoul@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).