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.

Fixes: 68a4d15061 ("net: phy: Bind ETH_PHY uclass driver to each new PHY")
Signed-off-by: Pranav Tilak <pranav.vinaytilak@amd.com>
This commit is contained in:
Pranav Tilak
2026-07-23 17:05:20 +02:00
committed by Jerome Forissier
parent 614ebea14b
commit 2671bd1d77
+28 -1
View File
@@ -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