The function referred to (of_mdiobus_link_mdiodev()) is only built when
CONFIG_OF_MDIO is enabled, which is again, a DT specific thing, and would
not work in case of ACPI.
Given that it is a static function so renamed of_mdiobus_link_mdiodev()
as mdiobus_link_mdiodev() and did necessary changes, finally moved it out
of the #ifdef(CONFIG_OF_MDIO) therefore make it work for both DT & ACPI.

Signed-off-by: Vikas Singh <vikas.si...@puresoftware.com>
---

Notes:
    - Add generic handling for "fwnode" and "of_node".
    - Remove duplicate loops.

 drivers/net/phy/mdio_bus.c | 43 +++++++++++++++++++++++--------------------
 1 file changed, 23 insertions(+), 20 deletions(-)

diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 46b3370..b0faa95 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -434,6 +434,7 @@ struct mii_bus *of_mdio_find_bus(struct device_node 
*mdio_bus_np)
        return d ? to_mii_bus(d) : NULL;
 }
 EXPORT_SYMBOL(of_mdio_find_bus);
+#endif
 
 /* Walk the list of subnodes of a mdio bus and look for a node that
  * matches the mdio device's address with its 'reg' property. If
@@ -441,35 +442,37 @@ EXPORT_SYMBOL(of_mdio_find_bus);
  * auto-probed phy devices to be supplied with information passed in
  * via DT.
  */
-static void of_mdiobus_link_mdiodev(struct mii_bus *bus,
-                                   struct mdio_device *mdiodev)
+static void mdiobus_link_mdiodev(struct mii_bus *bus,
+                                struct mdio_device *mdiodev)
 {
        struct device *dev = &mdiodev->dev;
-       struct device_node *child;
+       struct fwnode_handle *child;
+       int addr;
 
-       if (dev->of_node || !bus->dev.of_node)
+       if (dev->fwnode || !bus->dev.fwnode) {
+               pr_err("PHY fwnode is not available on bus for registration\n");
                return;
+       }
 
-       for_each_available_child_of_node(bus->dev.of_node, child) {
-               int addr;
+       device_for_each_child_node(&bus->dev, child) {
+               if (!fwnode_device_is_available(child))
+                       continue;
 
-               addr = of_mdio_parse_addr(dev, child);
-               if (addr < 0)
+               if (is_of_node(child)) {
+                       addr = of_mdio_parse_addr(dev, to_of_node(child));
+                       if (addr < 0)
+                               continue;
+               } else if (fwnode_property_read_u32(child, "reg", &addr))
                        continue;
 
                if (addr == mdiodev->addr) {
-                       dev->of_node = child;
-                       dev->fwnode = of_fwnode_handle(child);
-                       return;
+                       dev->of_node = to_of_node(child);
+                       dev->fwnode = child;
+                       break;
                }
        }
+       return;
 }
-#else /* !IS_ENABLED(CONFIG_OF_MDIO) */
-static inline void of_mdiobus_link_mdiodev(struct mii_bus *mdio,
-                                          struct mdio_device *mdiodev)
-{
-}
-#endif
 
 /**
  * mdiobus_create_device_from_board_info - create a full MDIO device given
@@ -688,10 +691,10 @@ struct phy_device *mdiobus_scan(struct mii_bus *bus, int 
addr)
                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.
+        * See if the auto-probed phy has a corresponding child
+        * in the bus node, and set the of_node & fwnode pointers.
         */
-       of_mdiobus_link_mdiodev(bus, &phydev->mdio);
+       mdiobus_link_mdiodev(bus, &phydev->mdio);
 
        err = phy_device_register(phydev);
        if (err) {
-- 
2.7.4

Reply via email to