]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
net: phy: Add helper for mapping RGMII link speed to clock rate
authorJan Petrous (OSS) <jan.petrous@oss.nxp.com>
Thu, 5 Dec 2024 16:43:01 +0000 (17:43 +0100)
committerJakub Kicinski <kuba@kernel.org>
Tue, 10 Dec 2024 02:36:02 +0000 (18:36 -0800)
The RGMII interface supports three data rates: 10/100 Mbps
and 1 Gbps. These speeds correspond to clock frequencies
of 2.5/25 MHz and 125 MHz, respectively.

Many Ethernet drivers, including glues in stmmac, follow
a similar pattern of converting RGMII speed to clock frequency.

To simplify code, define the helper rgmii_clock(speed)
to convert connection speed to clock frequency.

Suggested-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Signed-off-by: Jan Petrous (OSS) <jan.petrous@oss.nxp.com>
Link: https://patch.msgid.link/20241205-upstream_s32cc_gmac-v8-4-ec1d180df815@oss.nxp.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/linux/phy.h

index bb157136351e7a02538011d42beafb01ff6975a4..e597a32cc787a3b142f9b012e0ea5004f7c6b560 100644 (file)
@@ -298,6 +298,29 @@ 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.
+ *
+ * Returns: clock rate or negative errno
+ */
+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