Skip to contentSkip to conversation

net: eth-phy: Add reset control support

PATCH In review Jonas Karlman 2 participants 4 messages Oct 4 – Oct 9 Network drivers

lore
Share & tools
lore
#0 lore raw

cover net: eth-phy: Add reset control support

This series extends support for reset of Ethernet PHYs using reset controls in addition to GPIO to the generic eth phy driver.

Some boards have Ethernet PHYs that use reset controls instead of GPIO reset, e.g. some Rockchip boards using an integrated Fast Ethernet PHY.

Jonas Karlman (2):
net: eth-phy: Refactor DM_GPIO guard
net: eth-phy: Add reset control support

 drivers/net/eth-phy-uclass.c | 38 +++++++++++++++++++++++-------------
 1 file changed, 24 insertions(+), 14 deletions(-)
Signature · 1 line
2.55.0
#1 lore raw

PATCH 1/2 net: eth-phy: Refactor DM_GPIO guard

Refactor the DM_GPIO guard for the generic eth phy driver in preparation for adding support for use of eth phy reset controls.

This has no intended functional change beside delay DT properties now being parsed even when DM_GPIO is disabled.

---
 drivers/net/eth-phy-uclass.c | 24 +++++++++---------------
 1 file changed, 9 insertions(+), 15 deletions(-)
drivers/net/eth-phy-uclass.c +9 -15
index 1dae26878e61..7c60b3e57975 100644
@@ -130,15 +130,14 @@ static int eth_phy_of_to_plat(struct udevice *dev)
 	struct eth_phy_device_priv *uc_priv = dev_get_uclass_priv(dev);
 	int ret;
 
-	if (!CONFIG_IS_ENABLED(DM_GPIO))
-		return 0;
-
 	/* search "reset-gpios" in phy node */
-	ret = gpio_request_by_name(dev, "reset-gpios", 0,
-				   &uc_priv->reset_gpio,
-				   GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
-	if (ret && ret != -ENOENT)
-		return ret;
+	if (CONFIG_IS_ENABLED(DM_GPIO)) {
+		ret = gpio_request_by_name(dev, "reset-gpios", 0,
+					   &uc_priv->reset_gpio,
+					   GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
+		if (ret && ret != -ENOENT)
+			return ret;
+	}
 
 	uc_priv->reset_assert_delay = dev_read_u32_default(dev, "reset-assert-us", 0);
 	uc_priv->reset_deassert_delay = dev_read_u32_default(dev, "reset-deassert-us", 0);
@@ -159,13 +158,8 @@ static void eth_phy_reset(struct udevice *dev, int value)
 	struct eth_phy_device_priv *uc_priv = dev_get_uclass_priv(dev);
 	u32 delay;
 
-	if (!CONFIG_IS_ENABLED(DM_GPIO))
-		return;
-
-	if (!dm_gpio_is_valid(&uc_priv->reset_gpio))
-		return;
-
-	dm_gpio_set_value(&uc_priv->reset_gpio, value);
+	if (CONFIG_IS_ENABLED(DM_GPIO) && dm_gpio_is_valid(&uc_priv->reset_gpio))
+		dm_gpio_set_value(&uc_priv->reset_gpio, value);
 
 	delay = value ? uc_priv->reset_assert_delay : uc_priv->reset_deassert_delay;
 	if (delay)
Signature · 1 line
2.55.0
#2 lore raw

PATCH 2/2 net: eth-phy: Add reset control support

In reply to Jonas Karlman

Add support for Ethernet PHY reset using reset controls.

This closely matches how Linux handles Ethernet PHY reset using reset controls, initially introduced in the Linux commit 71dd6c0dff51 ("net:
phy: add support for reset-controller").

---
 drivers/net/eth-phy-uclass.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
drivers/net/eth-phy-uclass.c +16 -0
index 7c60b3e57975..a13e2fc7c50a 100644
@@ -8,6 +8,7 @@
 #include <dm.h>
 #include <log.h>
 #include <net.h>
+#include <reset.h>
 #include <asm-generic/gpio.h>
 #include <dm/device_compat.h>
 #include <dm/device-internal.h>
@@ -18,6 +19,7 @@
 struct eth_phy_device_priv {
 	struct mii_dev *mdio_bus;
 	struct gpio_desc reset_gpio;
+	struct reset_ctl reset_ctrl;
 	u32 reset_assert_delay;
 	u32 reset_deassert_delay;
 };
@@ -139,6 +141,13 @@ static int eth_phy_of_to_plat(struct udevice *dev)
 			return ret;
 	}
 
+	/* search "resets" in phy node */
+	if (CONFIG_IS_ENABLED(DM_RESET)) {
+		ret = reset_get_by_index(dev, 0, &uc_priv->reset_ctrl);
+		if (ret && ret != -ENOENT)
+			return ret;
+	}
+
 	uc_priv->reset_assert_delay = dev_read_u32_default(dev, "reset-assert-us", 0);
 	uc_priv->reset_deassert_delay = dev_read_u32_default(dev, "reset-deassert-us", 0);
 
@@ -161,6 +170,13 @@ static void eth_phy_reset(struct udevice *dev, int value)
 	if (CONFIG_IS_ENABLED(DM_GPIO) && dm_gpio_is_valid(&uc_priv->reset_gpio))
 		dm_gpio_set_value(&uc_priv->reset_gpio, value);
 
+	if (CONFIG_IS_ENABLED(DM_RESET) && reset_valid(&uc_priv->reset_ctrl)) {
+		if (value)
+			reset_assert(&uc_priv->reset_ctrl);
+		else
+			reset_deassert(&uc_priv->reset_ctrl);
+	}
+
 	delay = value ? uc_priv->reset_assert_delay : uc_priv->reset_deassert_delay;
 	if (delay)
 		udelay(delay);
Signature · 1 line
2.55.0
#3 lore raw
In reply to Jonas Karlman
Quoted 11 lines · Jonas Karlman

This series extends support for reset of Ethernet PHYs using reset controls in addition to GPIO to the generic eth phy driver.

Some boards have Ethernet PHYs that use reset controls instead of GPIO reset, e.g. some Rockchip boards using an integrated Fast Ethernet PHY.

Jonas Karlman (2):
net: eth-phy: Refactor DM_GPIO guard
net: eth-phy: Add reset control support

[...]

Applied to u-boot-net branch for-next, thanks!

[1/2] net: eth-phy: Refactor DM_GPIO guard

      commit: f3886299756b8835046cc7c23cd8bb04e514bbe0
[2/2] net: eth-phy: Add reset control support
      commit: b6aeb2b880fe96b51ece8909cf37a73a7927c4b3

Best regards,

Signature · 1 line
Jerome Forissier <[email protected]>