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 <rmk+kernel@armlinux.org.uk> Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
committed by
David S. Miller
parent
e7e95c9003
commit
b5b6775d72
@@ -337,6 +337,29 @@ unregister:
|
|||||||
}
|
}
|
||||||
EXPORT_SYMBOL(of_mdiobus_register);
|
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.
|
||||||
|
* The caller should call put_device() on the mdio_device after its use
|
||||||
|
*/
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL(of_mdio_find_device);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* of_phy_find_device - Give a PHY node, find the phy_device
|
* of_phy_find_device - Give a PHY node, find the phy_device
|
||||||
* @phy_np: Pointer to the phy's device tree node
|
* @phy_np: Pointer to the phy's device tree node
|
||||||
@@ -346,19 +369,16 @@ EXPORT_SYMBOL(of_mdiobus_register);
|
|||||||
*/
|
*/
|
||||||
struct phy_device *of_phy_find_device(struct device_node *phy_np)
|
struct phy_device *of_phy_find_device(struct device_node *phy_np)
|
||||||
{
|
{
|
||||||
struct device *d;
|
|
||||||
struct mdio_device *mdiodev;
|
struct mdio_device *mdiodev;
|
||||||
|
|
||||||
if (!phy_np)
|
mdiodev = of_mdio_find_device(phy_np);
|
||||||
|
if (!mdiodev)
|
||||||
return NULL;
|
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)
|
if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY)
|
||||||
return to_phy_device(d);
|
return to_phy_device(&mdiodev->dev);
|
||||||
put_device(d);
|
|
||||||
}
|
put_device(&mdiodev->dev);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ bool of_mdiobus_child_is_phy(struct device_node *child);
|
|||||||
int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np);
|
int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np);
|
||||||
int devm_of_mdiobus_register(struct device *dev, struct mii_bus *mdio,
|
int devm_of_mdiobus_register(struct device *dev, struct mii_bus *mdio,
|
||||||
struct device_node *np);
|
struct device_node *np);
|
||||||
|
struct mdio_device *of_mdio_find_device(struct device_node *np);
|
||||||
struct phy_device *of_phy_find_device(struct device_node *phy_np);
|
struct phy_device *of_phy_find_device(struct device_node *phy_np);
|
||||||
struct phy_device *
|
struct phy_device *
|
||||||
of_phy_connect(struct net_device *dev, struct device_node *phy_np,
|
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 *
|
|||||||
return mdiobus_register(mdio);
|
return mdiobus_register(mdio);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline struct mdio_device *of_mdio_find_device(struct device_node *np)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static inline struct phy_device *of_phy_find_device(struct device_node *phy_np)
|
static inline struct phy_device *of_phy_find_device(struct device_node *phy_np)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user