Skip to content

Commit b5b6775

Browse files
Russell Kingdavem330
authored andcommitted
of: add of_mdio_find_device() api
Add a helper function which finds the mdio_device structure given a device tree node. This is helpful for finding the PCS device based on a DTS node but managing it as a mdio_device instead of a phy_device. Signed-off-by: Russell King <[email protected]> Signed-off-by: Ioana Ciornei <[email protected]> Reviewed-by: Andrew Lunn <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e7e95c9 commit b5b6775

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed

drivers/of/of_mdio.c

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,29 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
337337
}
338338
EXPORT_SYMBOL(of_mdiobus_register);
339339

340+
/**
341+
* of_mdio_find_device - Given a device tree node, find the mdio_device
342+
* @np: pointer to the mdio_device's device tree node
343+
*
344+
* If successful, returns a pointer to the mdio_device with the embedded
345+
* struct device refcount incremented by one, or NULL on failure.
346+
* The caller should call put_device() on the mdio_device after its use
347+
*/
348+
struct mdio_device *of_mdio_find_device(struct device_node *np)
349+
{
350+
struct device *d;
351+
352+
if (!np)
353+
return NULL;
354+
355+
d = bus_find_device_by_of_node(&mdio_bus_type, np);
356+
if (!d)
357+
return NULL;
358+
359+
return to_mdio_device(d);
360+
}
361+
EXPORT_SYMBOL(of_mdio_find_device);
362+
340363
/**
341364
* of_phy_find_device - Give a PHY node, find the phy_device
342365
* @phy_np: Pointer to the phy's device tree node
@@ -346,19 +369,16 @@ EXPORT_SYMBOL(of_mdiobus_register);
346369
*/
347370
struct phy_device *of_phy_find_device(struct device_node *phy_np)
348371
{
349-
struct device *d;
350372
struct mdio_device *mdiodev;
351373

352-
if (!phy_np)
374+
mdiodev = of_mdio_find_device(phy_np);
375+
if (!mdiodev)
353376
return NULL;
354377

355-
d = bus_find_device_by_of_node(&mdio_bus_type, phy_np);
356-
if (d) {
357-
mdiodev = to_mdio_device(d);
358-
if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY)
359-
return to_phy_device(d);
360-
put_device(d);
361-
}
378+
if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY)
379+
return to_phy_device(&mdiodev->dev);
380+
381+
put_device(&mdiodev->dev);
362382

363383
return NULL;
364384
}

include/linux/of_mdio.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ bool of_mdiobus_child_is_phy(struct device_node *child);
1717
int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np);
1818
int devm_of_mdiobus_register(struct device *dev, struct mii_bus *mdio,
1919
struct device_node *np);
20+
struct mdio_device *of_mdio_find_device(struct device_node *np);
2021
struct phy_device *of_phy_find_device(struct device_node *phy_np);
2122
struct phy_device *
2223
of_phy_connect(struct net_device *dev, struct device_node *phy_np,
@@ -74,6 +75,11 @@ static inline int of_mdiobus_register(struct mii_bus *mdio, struct device_node *
7475
return mdiobus_register(mdio);
7576
}
7677

78+
static inline struct mdio_device *of_mdio_find_device(struct device_node *np)
79+
{
80+
return NULL;
81+
}
82+
7783
static inline struct phy_device *of_phy_find_device(struct device_node *phy_np)
7884
{
7985
return NULL;

0 commit comments

Comments
 (0)