net: phy: Add support for PHY timing-role configuration via device tree
authorOleksij Rempel <o.rempel@pengutronix.de>
Fri, 4 Oct 2024 09:01:00 +0000 (11:01 +0200)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 8 Oct 2024 08:50:15 +0000 (10:50 +0200)
Introduce support for configuring the master/slave role of PHYs based on
the `timing-role` property in the device tree. While this functionality
is necessary for Single Pair Ethernet (SPE) PHYs (1000/100/10Base-T1)
where hardware strap pins may be unavailable or incorrectly set, it
works for any PHY type.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
Reviewed-by: Divya Koppera <divya.koppera@microchip.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
drivers/net/phy/phy-core.c
drivers/net/phy/phy_device.c
include/linux/phy.h

index 1f98b6a96c15355e5c318de0f161e426639c483c..4e8db12d60928d509a90d90c6e993846a107d81f 100644 (file)
@@ -412,6 +412,39 @@ void of_set_phy_eee_broken(struct phy_device *phydev)
        phydev->eee_broken_modes = broken;
 }
 
+/**
+ * of_set_phy_timing_role - Set the master/slave mode of the PHY
+ *
+ * @phydev: The phy_device struct
+ *
+ * Set master/slave configuration of the PHY based on the device tree.
+ */
+void of_set_phy_timing_role(struct phy_device *phydev)
+{
+       struct device_node *node = phydev->mdio.dev.of_node;
+       const char *master;
+
+       if (!IS_ENABLED(CONFIG_OF_MDIO))
+               return;
+
+       if (!node)
+               return;
+
+       if (of_property_read_string(node, "timing-role", &master))
+               return;
+
+       if (strcmp(master, "forced-master") == 0)
+               phydev->master_slave_set = MASTER_SLAVE_CFG_MASTER_FORCE;
+       else if (strcmp(master, "forced-slave") == 0)
+               phydev->master_slave_set = MASTER_SLAVE_CFG_SLAVE_FORCE;
+       else if (strcmp(master, "preferred-master") == 0)
+               phydev->master_slave_set = MASTER_SLAVE_CFG_MASTER_PREFERRED;
+       else if (strcmp(master, "preferred-slave") == 0)
+               phydev->master_slave_set = MASTER_SLAVE_CFG_SLAVE_PREFERRED;
+       else
+               phydev_warn(phydev, "Unknown master-slave mode %s\n", master);
+}
+
 /**
  * phy_resolve_aneg_pause - Determine pause autoneg results
  *
index 560e338b307a40988e2b35962471152690fbaf1b..4ccf504a8b2c251387f4f01fe97f7ca008a527dc 100644 (file)
@@ -3608,6 +3608,9 @@ static int phy_probe(struct device *dev)
         */
        of_set_phy_eee_broken(phydev);
 
+       /* Get master/slave strap overrides */
+       of_set_phy_timing_role(phydev);
+
        /* The Pause Frame bits indicate that the PHY can support passing
         * pause frames. During autonegotiation, the PHYs will determine if
         * they should allow pause frames to pass.  The MAC driver should then
index a98bc91a0cde9cfce0d466708a7d18c55c7c07cb..ff762a3d8270a569795b0642cb4349b88f87289f 100644 (file)
@@ -1260,6 +1260,7 @@ size_t phy_speeds(unsigned int *speeds, size_t size,
                  unsigned long *mask);
 void of_set_phy_supported(struct phy_device *phydev);
 void of_set_phy_eee_broken(struct phy_device *phydev);
+void of_set_phy_timing_role(struct phy_device *phydev);
 int phy_speed_down_core(struct phy_device *phydev);
 
 /**