Skip to content

Commit 2510602

Browse files
daviddaneydavem330
authored andcommitted
netdev/of/phy: New function: of_mdio_find_bus().
Add of_mdio_find_bus() which allows an mii_bus to be located given its associated the device tree node. This is needed by the follow-on patch to add a driver for MDIO bus multiplexers. The of_mdiobus_register() function is modified so that the device tree node is recorded in the mii_bus. Then we can find it again by iterating over all mdio_bus_class devices. Because the OF device tree has now become an integral part of the kernel, this can live in mdio_bus.c (which contains the needed mdio_bus_class structure) instead of of_mdio.c. Signed-off-by: David Daney <david.daney@cavium.com> Cc: Grant Likely <grant.likely@secretlab.ca> Cc: "David S. Miller" <davem@davemloft.net> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 7dc2ce5 commit 2510602

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

drivers/net/phy/mdio_bus.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,38 @@ static struct class mdio_bus_class = {
8888
.dev_release = mdiobus_release,
8989
};
9090

91+
#ifdef CONFIG_OF_MDIO
92+
/* Helper function for of_mdio_find_bus */
93+
static int of_mdio_bus_match(struct device *dev, void *mdio_bus_np)
94+
{
95+
return dev->of_node == mdio_bus_np;
96+
}
97+
/**
98+
* of_mdio_find_bus - Given an mii_bus node, find the mii_bus.
99+
* @mdio_np: Pointer to the mii_bus.
100+
*
101+
* Returns a pointer to the mii_bus, or NULL if none found.
102+
*
103+
* Because the association of a device_node and mii_bus is made via
104+
* of_mdiobus_register(), the mii_bus cannot be found before it is
105+
* registered with of_mdiobus_register().
106+
*
107+
*/
108+
struct mii_bus *of_mdio_find_bus(struct device_node *mdio_bus_np)
109+
{
110+
struct device *d;
111+
112+
if (!mdio_bus_np)
113+
return NULL;
114+
115+
d = class_find_device(&mdio_bus_class, NULL, mdio_bus_np,
116+
of_mdio_bus_match);
117+
118+
return d ? to_mii_bus(d) : NULL;
119+
}
120+
EXPORT_SYMBOL(of_mdio_find_bus);
121+
#endif
122+
91123
/**
92124
* mdiobus_register - bring up all the PHYs on a given bus and attach them to bus
93125
* @bus: target mii_bus

drivers/of/of_mdio.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
4545
for (i=0; i<PHY_MAX_ADDR; i++)
4646
mdio->irq[i] = PHY_POLL;
4747

48+
mdio->dev.of_node = np;
49+
4850
/* Register the MDIO bus */
4951
rc = mdiobus_register(mdio);
5052
if (rc)

include/linux/of_mdio.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@ extern struct phy_device *of_phy_connect_fixed_link(struct net_device *dev,
2222
void (*hndlr)(struct net_device *),
2323
phy_interface_t iface);
2424

25+
extern struct mii_bus *of_mdio_find_bus(struct device_node *mdio_np);
26+
2527
#endif /* __LINUX_OF_MDIO_H */

0 commit comments

Comments
 (0)