of: of_mdio: Check if MDIO bus controller is available
authorFlorian Fainelli <f.fainelli@gmail.com>
Thu, 28 Apr 2016 23:24:12 +0000 (16:24 -0700)
committerDavid S. Miller <davem@davemloft.net>
Sun, 1 May 2016 23:34:29 +0000 (19:34 -0400)
Add a check whether the 'struct device_node' pointer passed to
of_mdiobus_register() is an available (aka enabled) node in the Device
Tree.

Rationale for doing this are cases where an Ethernet MAC provides a MDIO
bus controller and node, and an additional Ethernet MAC might be
connecting its PHY/switches to that first MDIO bus controller, while
still embedding one internally which is therefore marked as "disabled".

Instead of sprinkling checks like these in callers of
of_mdiobus_register(), do this in a central location.

Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/of/of_mdio.c

index b622b33..e051e1b 100644 (file)
@@ -209,6 +209,10 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
        bool scanphys = false;
        int addr, rc;
 
+       /* Do not continue if the node is disabled */
+       if (!of_device_is_available(np))
+               return -ENODEV;
+
        /* Mask out all PHYs from auto probing.  Instead the PHYs listed in
         * the device tree are populated after the bus has been registered */
        mdio->phy_mask = ~0;