diff mbox series

[net-next,v4,2/2] net: phy: Add support for PHY timing-role configuration via device tree

Message ID 20241001073704.1389952-3-o.rempel@pengutronix.de (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series net: phy: Support master-slave config via device tree | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for 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: 9 this patch: 9
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 22 this patch: 22
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 fail Errors and warnings before: 13 this patch: 13
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 55 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 96 this patch: 96
netdev/source_inline success Was 0 now: 0

Commit Message

Oleksij Rempel Oct. 1, 2024, 7:37 a.m. UTC
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>
---
changes v4:
- add "Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>"
changes v3:
- rename master-slave to timing-role
---
 drivers/net/phy/phy-core.c   | 33 +++++++++++++++++++++++++++++++++
 drivers/net/phy/phy_device.c |  3 +++
 include/linux/phy.h          |  1 +
 3 files changed, 37 insertions(+)

Comments

Florian Fainelli Oct. 2, 2024, 4:29 a.m. UTC | #1
On 10/1/2024 12:37 AM, Oleksij Rempel wrote:
> 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>
Divya Koppera Oct. 3, 2024, 10:45 a.m. UTC | #2
Hi @Oleksij Rempel

> -----Original Message-----
> From: Oleksij Rempel <o.rempel@pengutronix.de>
> Sent: Tuesday, October 1, 2024 1:07 PM
> To: Andrew Lunn <andrew@lunn.ch>; Heiner Kallweit
> <hkallweit1@gmail.com>; David S. Miller <davem@davemloft.net>; Eric
> Dumazet <edumazet@google.com>; Jakub Kicinski <kuba@kernel.org>; Paolo
> Abeni <pabeni@redhat.com>; Rob Herring <robh@kernel.org>; Krzysztof
> Kozlowski <krzk+dt@kernel.org>; Conor Dooley <conor+dt@kernel.org>;
> Florian Fainelli <f.fainelli@gmail.com>
> Cc: Oleksij Rempel <o.rempel@pengutronix.de>; Russell King
> <rmk+kernel@armlinux.org.uk>; kernel@pengutronix.de; linux-
> kernel@vger.kernel.org; netdev@vger.kernel.org; Russell King
> <linux@armlinux.org.uk>; devicetree@vger.kernel.org
> Subject: [PATCH net-next v4 2/2] net: phy: Add support for PHY timing-role
> configuration via device tree
> 
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the
> content is safe
> 
> 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>
> ---
> changes v4:
> - add "Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>"
> changes v3:
> - rename master-slave to timing-role
> ---
>  drivers/net/phy/phy-core.c   | 33 +++++++++++++++++++++++++++++++++
>  drivers/net/phy/phy_device.c |  3 +++
>  include/linux/phy.h          |  1 +
>  3 files changed, 37 insertions(+)
> 
> diff --git a/drivers/net/phy/phy-core.c b/drivers/net/phy/phy-core.c index
> 1f98b6a96c153..97ff10e226180 100644
> --- a/drivers/net/phy/phy-core.c
> +++ b/drivers/net/phy/phy-core.c
> @@ -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, "force-master") == 0)
> +               phydev->master_slave_set = MASTER_SLAVE_CFG_MASTER_FORCE;
> +       else if (strcmp(master, "force-slave") == 0)
> +               phydev->master_slave_set = MASTER_SLAVE_CFG_SLAVE_FORCE;
> +       else if (strcmp(master, "prefer-master") == 0)
> +               phydev->master_slave_set =
> MASTER_SLAVE_CFG_MASTER_PREFERRED;
> +       else if (strcmp(master, "prefer-slave") == 0)

I would suggest to use "preferred" instead of "prefer" to be in sync with existing macros.

> +               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
>   *
> diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> index 560e338b307a4..4ccf504a8b2c2 100644
> --- a/drivers/net/phy/phy_device.c
> +++ b/drivers/net/phy/phy_device.c
> @@ -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
> diff --git a/include/linux/phy.h b/include/linux/phy.h index
> a98bc91a0cde9..ff762a3d8270a 100644
> --- a/include/linux/phy.h
> +++ b/include/linux/phy.h
> @@ -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);
> 
>  /**
> --
> 2.39.5
> 

LGTM.

Reviewed-by: Divya Koppera <divya.koppera@microchip.com>
diff mbox series

Patch

diff --git a/drivers/net/phy/phy-core.c b/drivers/net/phy/phy-core.c
index 1f98b6a96c153..97ff10e226180 100644
--- a/drivers/net/phy/phy-core.c
+++ b/drivers/net/phy/phy-core.c
@@ -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, "force-master") == 0)
+		phydev->master_slave_set = MASTER_SLAVE_CFG_MASTER_FORCE;
+	else if (strcmp(master, "force-slave") == 0)
+		phydev->master_slave_set = MASTER_SLAVE_CFG_SLAVE_FORCE;
+	else if (strcmp(master, "prefer-master") == 0)
+		phydev->master_slave_set = MASTER_SLAVE_CFG_MASTER_PREFERRED;
+	else if (strcmp(master, "prefer-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
  *
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 560e338b307a4..4ccf504a8b2c2 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -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
diff --git a/include/linux/phy.h b/include/linux/phy.h
index a98bc91a0cde9..ff762a3d8270a 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -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);
 
 /**