Skip to content

Commit 43564f0

Browse files
Hans-Frieder Vogtkuba-moo
authored andcommitted
net: phy: Add swnode support to mdiobus_scan
This patch will allow to use a swnode/fwnode defined for a phy_device. The MDIO bus (mii_bus) needs to contain nodes for the PHY devices, named "ethernet-phy@i", with i being the MDIO address (0 .. PHY_MAX_ADDR - 1). The fwnode is only attached to the phy_device if there isn't already an fwnode attached. fwnode_get_named_child_node will increase the usage counter of the fwnode. However, no new code is needed to decrease the counter again, since this is already implemented in the phy_device_release function. Signed-off-by: Hans-Frieder Vogt <[email protected]> Reviewed-by: Andrew Lunn <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent e2ac75a commit 43564f0

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

drivers/net/phy/mdio_bus.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,8 @@ static int mdiobus_create_device(struct mii_bus *bus,
551551
static struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr, bool c45)
552552
{
553553
struct phy_device *phydev = ERR_PTR(-ENODEV);
554+
struct fwnode_handle *fwnode;
555+
char node_name[16];
554556
int err;
555557

556558
phydev = get_phy_device(bus, addr, c45);
@@ -562,6 +564,18 @@ static struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr, bool c45)
562564
*/
563565
of_mdiobus_link_mdiodev(bus, &phydev->mdio);
564566

567+
/* Search for a swnode for the phy in the swnode hierarchy of the bus.
568+
* If there is no swnode for the phy provided, just ignore it.
569+
*/
570+
if (dev_fwnode(&bus->dev) && !dev_fwnode(&phydev->mdio.dev)) {
571+
snprintf(node_name, sizeof(node_name), "ethernet-phy@%d",
572+
addr);
573+
fwnode = fwnode_get_named_child_node(dev_fwnode(&bus->dev),
574+
node_name);
575+
if (fwnode)
576+
device_set_node(&phydev->mdio.dev, fwnode);
577+
}
578+
565579
err = phy_device_register(phydev);
566580
if (err) {
567581
phy_device_free(phydev);

0 commit comments

Comments
 (0)