diff options
author | Russell King <rmk+kernel@armlinux.org.uk> | 2020-04-16 22:06:49 +0100 |
---|---|---|
committer | Russell King <rmk+kernel@armlinux.org.uk> | 2020-05-23 13:11:38 +0100 |
commit | 4f7f2b4f0fd780f1328e0e12abca08a55390af6f (patch) | |
tree | 68b24ad6ad7175c49976b2de3be6a990812f164a /drivers | |
parent | aa629b0c0f75019c6f962b1077aa0e2d20415287 (diff) |
of: add of_mdio_find_device() api
Add an API to find the mdio_device structure given a device tree node.
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/of/of_mdio.c | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c index 9f982c0627a0..870b6d1ecb3b 100644 --- a/drivers/of/of_mdio.c +++ b/drivers/of/of_mdio.c @@ -320,6 +320,27 @@ unregister: EXPORT_SYMBOL(of_mdiobus_register); /** + * of_mdio_find_device - Given a device tree node, find the mdio_device + * @np: pointer to the mdio_device's device tree node + * + * If successful, returns a pointer to the mdio_device with the embedded + * struct device refcount incremented by one, or NULL on failure. + */ +struct mdio_device *of_mdio_find_device(struct device_node *np) +{ + struct device *d; + + if (!np) + return NULL; + + d = bus_find_device_by_of_node(&mdio_bus_type, np); + if (!d) + return NULL; + + return to_mdio_device(d); +} + +/** * of_phy_find_device - Give a PHY node, find the phy_device * @phy_np: Pointer to the phy's device tree node * @@ -328,19 +349,16 @@ EXPORT_SYMBOL(of_mdiobus_register); */ struct phy_device *of_phy_find_device(struct device_node *phy_np) { - struct device *d; struct mdio_device *mdiodev; - if (!phy_np) + mdiodev = of_mdio_find_device(phy_np); + if (!mdiodev) return NULL; - d = bus_find_device_by_of_node(&mdio_bus_type, phy_np); - if (d) { - mdiodev = to_mdio_device(d); - if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY) - return to_phy_device(d); - put_device(d); - } + if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY) + return to_phy_device(&mdiodev->dev); + + put_device(&mdiodev->dev); return NULL; } |