]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/commitdiff
netdev/of/phy: New function: of_mdio_find_bus().
authorDavid Daney <david.daney@cavium.com>
Wed, 2 May 2012 15:16:37 +0000 (15:16 +0000)
committerDavid S. Miller <davem@davemloft.net>
Tue, 8 May 2012 02:58:09 +0000 (22:58 -0400)
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>
drivers/net/phy/mdio_bus.c
drivers/of/of_mdio.c
include/linux/of_mdio.h

index 8985cc62cf41c888ed5a31c9e0877bb2463c5555..83d5c9f556867b4dfff86beeec37c747c5c37729 100644 (file)
@@ -88,6 +88,38 @@ static struct class mdio_bus_class = {
        .dev_release    = mdiobus_release,
 };
 
+#ifdef CONFIG_OF_MDIO
+/* Helper function for of_mdio_find_bus */
+static int of_mdio_bus_match(struct device *dev, void *mdio_bus_np)
+{
+       return dev->of_node == mdio_bus_np;
+}
+/**
+ * of_mdio_find_bus - Given an mii_bus node, find the mii_bus.
+ * @mdio_np: Pointer to the mii_bus.
+ *
+ * Returns a pointer to the mii_bus, or NULL if none found.
+ *
+ * Because the association of a device_node and mii_bus is made via
+ * of_mdiobus_register(), the mii_bus cannot be found before it is
+ * registered with of_mdiobus_register().
+ *
+ */
+struct mii_bus *of_mdio_find_bus(struct device_node *mdio_bus_np)
+{
+       struct device *d;
+
+       if (!mdio_bus_np)
+               return NULL;
+
+       d = class_find_device(&mdio_bus_class, NULL,  mdio_bus_np,
+                             of_mdio_bus_match);
+
+       return d ? to_mii_bus(d) : NULL;
+}
+EXPORT_SYMBOL(of_mdio_find_bus);
+#endif
+
 /**
  * mdiobus_register - bring up all the PHYs on a given bus and attach them to bus
  * @bus: target mii_bus
index 483c0adcad87d4701b866d6934137e34a5c38ed9..2574abde8d995d2e704f0852bc7a645452e13cd9 100644 (file)
@@ -45,6 +45,8 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
                for (i=0; i<PHY_MAX_ADDR; i++)
                        mdio->irq[i] = PHY_POLL;
 
+       mdio->dev.of_node = np;
+
        /* Register the MDIO bus */
        rc = mdiobus_register(mdio);
        if (rc)
index 53b94e025c7c7ae7b167ecd1cdf836fe51c09897..912c27a0f7eeede26c7659956b11c70f7255f78e 100644 (file)
@@ -22,4 +22,6 @@ extern struct phy_device *of_phy_connect_fixed_link(struct net_device *dev,
                                         void (*hndlr)(struct net_device *),
                                         phy_interface_t iface);
 
+extern struct mii_bus *of_mdio_find_bus(struct device_node *mdio_np);
+
 #endif /* __LINUX_OF_MDIO_H */