net: eth-phy: release reset GPIO and reset control on device removal
PATCH v4 1/1 net: eth-phy: release reset GPIO and reset control on device removal
eth_phy_of_to_plat() claims the PHY reset GPIO with gpio_request_by_name() and the PHY reset control with reset_get_by_index(), but nothing releases either when the device is removed. When retrying a wedged PHY, any follow-up probes fail because the reset GPIO is already claimed.
Add a pre_remove hook that frees both.
---
This patch was 4/4 of the zynq_gem resource leak series up to v3. As Michal Simek requested, it is now sent separately so that it can go through the net tree; the zynq_gem patches continue as their own v4.
Tested on QEMU (xilinx-zynq-a9, xilinx_zynq_virt), with a PHY that has reset-gpios and a (syscon-reset) resets property: after repeated unbind/bind of the ethernet controller, the eth-phy device probes again. Without this patch, the next probe fails because the reset GPIO is still claimed.
Changes in v4:
- Split out of the zynq_gem series; no code changes
- Rebased onto current main
- Add Acked-by from Michal Simek
- Link to v3: https://lore.kernel.org/r/[email protected]
Changes in v3:
- Rebased onto the eth-phy reset control support; also release the reset control with reset_free(). Use per-feature DM_GPIO/DM_RESET guards, and reword the subject accordingly
--- drivers/net/eth-phy-uclass.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
drivers/net/eth-phy-uclass.c +14 -0
@@ -191,11 +191,25 @@ static int eth_phy_pre_probe(struct udevice *dev)return 0 ; } +static int eth_phy_pre_remove (struct udevice *dev) +{ +struct eth_phy_device_priv *uc_priv =dev_get_uclass_priv (dev); + +if (CONFIG_IS_ENABLED (DM_GPIO ) &&dm_gpio_is_valid (&uc_priv->reset_gpio)) +dm_gpio_free (dev, &uc_priv->reset_gpio); + +if (CONFIG_IS_ENABLED (DM_RESET ) &&reset_valid (&uc_priv->reset_ctrl)) +reset_free (&uc_priv->reset_ctrl); + +return 0 ; +} +UCLASS_DRIVER (eth_phy_generic) = { .id =UCLASS_ETH_PHY , .name ="eth_phy_generic" , .per_device_auto =sizeof (struct eth_phy_device_priv ), .pre_probe = eth_phy_pre_probe, + .pre_remove = eth_phy_pre_remove, };U_BOOT_DRIVER (eth_phy_generic_drv) = {
---
base-commit: 709a97a05df66e394f40d249105d0baade46f107
change-id: 20261106-eth-phy-release-reset-0e959156e2c8
Best regards,
Signature · 1 line
Graeme Smecher <[email protected]>
Quoted 27 lines
eth_phy_of_to_plat()claims the PHY reset GPIO withgpio_request_by_name()and the PHY reset control withreset_get_by_index(), but nothing releases either when the device is removed. When retrying a wedged PHY, any follow-up probes fail because the reset GPIO is already claimed.Add a
pre_removehook that frees both.Signed-off-by Graeme Smecher <[email protected]>Acked-by Michal Simek <[email protected]>---
This patch was 4/4 of thezynq_gemresource leak series up to v3. As Michal Simek requested, it is now sent separately so that it can go through the net tree; thezynq_gempatches continue as their own v4.Tested on QEMU (xilinx-zynq-a9,
xilinx_zynq_virt), with a PHY that has reset-gpios and a (syscon-reset) resets property: after repeated unbind/bind of the ethernet controller, the eth-phy device probes again. Without this patch, the next probe fails because the reset GPIO is still claimed.Changes in v4:
- Split out of thezynq_gemseries; no code changes
- Rebased onto current main
- Add Acked-by from Michal Simek
- Link to v3: https://lore.kernel.org/r/[email protected]
Quoted 7 lines
Changes in v3:
- Rebased onto the eth-phy reset control support; also release the reset control withreset_free(). Use per-feature DM_GPIO/DM_RESET guards, and reword the subject accordingly--- drivers/net/eth-phy-uclass.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
Applied to u-boot-net branch for-main [1], thanks!
[1] https://git.u-boot-project.org/u-boot/custodians/u-boot-net/-/commits/for-main
[1/1] net: eth-phy: release reset GPIO and reset control on device removal
commit: af9898a75f1543525ddaa43bff1133878ebe1bd9
Best regards,
Signature · 1 line
Jerome Forissier <[email protected]>