]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
net: of_mdio: add of_mdiobus_link_phydev()
authorDaniel Mack <zonque@gmail.com>
Sat, 24 May 2014 07:34:26 +0000 (09:34 +0200)
committerDavid S. Miller <davem@davemloft.net>
Thu, 29 May 2014 22:23:29 +0000 (15:23 -0700)
Add a function to walk the list of subnodes of a mdio bus and look for
a node that matches the phy's address with its 'reg' property. If found,
set the of_node pointer for the phy. This allows auto-probed pyh
devices to be augmented by information passed in via DT.

Signed-off-by: Daniel Mack <zonque@gmail.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
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 a6284964b71144055511dd7ecdc91b09ae09b02a..2e58aa54484c9ca4e3154e231a3af2766bc84933 100644 (file)
@@ -300,6 +300,12 @@ struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr)
        if (IS_ERR(phydev) || phydev == NULL)
                return phydev;
 
+       /*
+        * For DT, see if the auto-probed phy has a correspoding child
+        * in the bus node, and set the of_node pointer in this case.
+        */
+       of_mdiobus_link_phydev(bus, phydev);
+
        err = phy_device_register(phydev);
        if (err) {
                phy_device_free(phydev);
index 731d3d9052d71ebbe1db148a59160b679efc99a3..7c8c142e4eb84396b83c9b0f50ae10bc7fb2b570 100644 (file)
@@ -183,6 +183,39 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
 }
 EXPORT_SYMBOL(of_mdiobus_register);
 
+/**
+ * of_mdiobus_link_phydev - Find a device node for a phy
+ * @mdio: pointer to mii_bus structure
+ * @phydev: phydev for which the of_node pointer should be set
+ *
+ * Walk the list of subnodes of a mdio bus and look for a node that matches the
+ * phy's address with its 'reg' property. If found, set the of_node pointer for
+ * the phy. This allows auto-probed pyh devices to be supplied with information
+ * passed in via DT.
+ */
+void of_mdiobus_link_phydev(struct mii_bus *mdio,
+                           struct phy_device *phydev)
+{
+       struct device *dev = &phydev->dev;
+       struct device_node *child;
+
+       if (dev->of_node || !mdio->dev.of_node)
+               return;
+
+       for_each_available_child_of_node(mdio->dev.of_node, child) {
+               int addr;
+
+               addr = of_mdio_parse_addr(&mdio->dev, child);
+               if (addr < 0)
+                       continue;
+
+               if (addr == phydev->addr) {
+                       dev->of_node = child;
+                       return;
+               }
+       }
+}
+
 /* Helper function for of_phy_find_device */
 static int of_phy_match(struct device *dev, void *phy_np)
 {
index d449018d07265200f4d8d6eeaf8ddac1a9010ebd..a70c9493d55a4c01976b093b965cc91b270aaf92 100644 (file)
@@ -25,6 +25,9 @@ struct phy_device *of_phy_attach(struct net_device *dev,
 
 extern struct mii_bus *of_mdio_find_bus(struct device_node *mdio_np);
 
+extern void of_mdiobus_link_phydev(struct mii_bus *mdio,
+                                  struct phy_device *phydev);
+
 #else /* CONFIG_OF */
 static inline int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
 {
@@ -60,6 +63,11 @@ static inline struct mii_bus *of_mdio_find_bus(struct device_node *mdio_np)
 {
        return NULL;
 }
+
+static inline void of_mdiobus_link_phydev(struct mii_bus *mdio,
+                                         struct phy_device *phydev)
+{
+}
 #endif /* CONFIG_OF */
 
 #if defined(CONFIG_OF) && defined(CONFIG_FIXED_PHY)