]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
net: phy: c45-tja11xx: add support for outputting RMII reference clock
authorWei Fang <wei.fang@nxp.com>
Thu, 10 Oct 2024 06:19:44 +0000 (14:19 +0800)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 15 Oct 2024 08:44:52 +0000 (10:44 +0200)
For TJA11xx PHYs, they have the capability to output 50MHz reference
clock on REF_CLK pin in RMII mode, which is called "revRMII" mode in
the PHY data sheet.

Signed-off-by: Wei Fang <wei.fang@nxp.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
drivers/net/phy/nxp-c45-tja11xx.c
drivers/net/phy/nxp-c45-tja11xx.h

index 5af5ade4fc64182be54b65cfbe2d0082a0de45ca..7e328c2a29a49f9e037a830430629083176f4f9b 100644 (file)
@@ -10,6 +10,7 @@
 #include <linux/kernel.h>
 #include <linux/mii.h>
 #include <linux/module.h>
+#include <linux/of.h>
 #include <linux/phy.h>
 #include <linux/processor.h>
 #include <linux/property.h>
 
 #define NXP_C45_SKB_CB(skb)    ((struct nxp_c45_skb_cb *)(skb)->cb)
 
+#define TJA11XX_REVERSE_MODE           BIT(0)
+
 struct nxp_c45_phy;
 
 struct nxp_c45_skb_cb {
@@ -1510,6 +1513,8 @@ static int nxp_c45_get_delays(struct phy_device *phydev)
 
 static int nxp_c45_set_phy_mode(struct phy_device *phydev)
 {
+       struct nxp_c45_phy *priv = phydev->priv;
+       u16 basic_config;
        int ret;
 
        ret = phy_read_mmd(phydev, MDIO_MMD_VEND1, VEND1_ABILITIES);
@@ -1561,8 +1566,15 @@ static int nxp_c45_set_phy_mode(struct phy_device *phydev)
                        phydev_err(phydev, "rmii mode not supported\n");
                        return -EINVAL;
                }
+
+               basic_config = MII_BASIC_CONFIG_RMII;
+
+               /* This is not PHY_INTERFACE_MODE_REVRMII */
+               if (priv->flags & TJA11XX_REVERSE_MODE)
+                       basic_config |= MII_BASIC_CONFIG_REV;
+
                phy_write_mmd(phydev, MDIO_MMD_VEND1, VEND1_MII_BASIC_CONFIG,
-                             MII_BASIC_CONFIG_RMII);
+                             basic_config);
                break;
        case PHY_INTERFACE_MODE_SGMII:
                if (!(ret & SGMII_ABILITY)) {
@@ -1623,6 +1635,20 @@ static int nxp_c45_get_features(struct phy_device *phydev)
        return genphy_c45_pma_read_abilities(phydev);
 }
 
+static int nxp_c45_parse_dt(struct phy_device *phydev)
+{
+       struct device_node *node = phydev->mdio.dev.of_node;
+       struct nxp_c45_phy *priv = phydev->priv;
+
+       if (!IS_ENABLED(CONFIG_OF_MDIO))
+               return 0;
+
+       if (of_property_read_bool(node, "nxp,rmii-refclk-out"))
+               priv->flags |= TJA11XX_REVERSE_MODE;
+
+       return 0;
+}
+
 static int nxp_c45_probe(struct phy_device *phydev)
 {
        struct nxp_c45_phy *priv;
@@ -1642,6 +1668,8 @@ static int nxp_c45_probe(struct phy_device *phydev)
 
        phydev->priv = priv;
 
+       nxp_c45_parse_dt(phydev);
+
        mutex_init(&priv->ptp_lock);
 
        phy_abilities = phy_read_mmd(phydev, MDIO_MMD_VEND1,
index f364fca68f0bedef7dd727b23460ddc78e906432..8b5fc383752bcf18dcc10a0ae402199777681fc4 100644 (file)
@@ -28,6 +28,7 @@ struct nxp_c45_phy {
        int extts_index;
        bool extts;
        struct nxp_c45_macsec *macsec;
+       u32 flags;
 };
 
 #if IS_ENABLED(CONFIG_MACSEC)