net: phy: fix duplicate eth_phy binding
Subsystems (2)
PATCH v6 1/1 net: phy: fix duplicate eth_phy binding
When both CONFIG_PHY_ETHERNET_ID and CONFIG_DM_ETH_PHY are enabled, eth_phy_binds_nodes() called from eth_post_bind() already binds the ethernet PHY node to eth_phy_generic_drv. However, phy_connect_phy_id() called via phy_connect() also binds the same PHY node, resulting in duplicate entries in the DM tree.
Fix this by introducing phy_connect_dm_bound() which checks if the PHY is already bound via uclass_find_device_by_phandle(). If so, it gets the phy_device via phy_find_by_mask() since the udevice does not store a phy_device pointer and the phy_device can only be obtained by scanning the MDIO bus. The phydev->node is then set from the already-bound DM device. This skips the generic binding methods in phy_connect() when the PHY is already DM-bound.
---
Changes in v6:
- Introduce phy_connect_dm_bound() helper to handle already DM-bound PHY
- Extend commit message to explain why phy_find_by_mask() is needed
Changes in v5:
- Use int ret instead of bool phy_bound and goto out
Changes in v4:
- Removed IS_ENABLED(CONFIG_DM_ETH_PHY), use runtime check via uclass_find_device_by_phandle()
- Fix indentation of binding methods block
- Assign phydev->node from the bound DM device's ofnode
Changes in v3:
- Moved duplicate binding check to beginning of phy_connect()
Changes in v2:
- Move duplicate binding check to caller phy_connect()
- Update commit description
drivers/net/phy/phy.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-)
drivers/net/phy/phy.c +28 -1
@@ -20,6 +20,7 @@#include <asm-generic/gpio.h> #include <dm/device_compat.h> #include <dm/of_extra.h> +#include <dm/uclass-internal.h> #include <linux/bitops.h> #include <linux/delay.h> #include <linux/err.h>
@@ -921,6 +922,27 @@ static struct phy_device *phy_connect_fixed(struct mii_dev *bus, }#endif +#ifdef CONFIG_DM_ETH_PHY +static struct phy_device *phy_connect_dm_bound (struct mii_dev *bus, +struct udevice *dev, +uint mask) +{ +struct udevice *dm_phy_dev; +struct phy_device *phydev; + +if (!uclass_find_device_by_phandle (UCLASS_ETH_PHY , dev, +"phy-handle" , &dm_phy_dev)) { + phydev =phy_find_by_mask (bus, mask); +if (phydev) + phydev->node =dev_ofnode (dm_phy_dev); + +return phydev; + } + +return NULL ; +} +#endif +struct phy_device *phy_connect (struct mii_dev *bus,int addr,struct udevice *dev,phy_interface_t interface)
@@ -928,8 +950,13 @@ struct phy_device *phy_connect(struct mii_dev *bus, int addr,struct phy_device *phydev =NULL ;uint mask = (addr >=0 ) ? (1 << addr) :0xffffffff ; +#ifdef CONFIG_DM_ETH_PHY + phydev =phy_connect_dm_bound (bus, dev, mask); +#endif +#ifdef CONFIG_PHY_FIXED - phydev =phy_connect_fixed (bus, dev); +if (!phydev) + phydev =phy_connect_fixed (bus, dev);#endif #ifdef CONFIG_PHY_NCSI
Signature · 1 line
2.34.1