summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2014-05-21 11:38:14 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2014-05-21 14:10:39 +0200
commit9b259eb3fd9c025d8a94d8ef682f96eb90cfdec8 (patch)
treef57399a2b6dd10da0f174382d6f8e9caee01f152 /drivers
parentb90dc180542602cb7581cff56f21fc90eb66fa68 (diff)
downloadbarebox-9b259eb3fd9c025d8a94d8ef682f96eb90cfdec8.tar.gz
barebox-9b259eb3fd9c025d8a94d8ef682f96eb90cfdec8.tar.xz
net: phy: register phys specified in devicetree
When a mdio bus has a device node attached then register the phys specified there. This makes it possible to lookup the phys using phandles later. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/net/phy/mdio_bus.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 5c4dea4e88..ca016736d2 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -49,6 +49,71 @@ int mdiobus_detect(struct device_d *dev)
return 0;
}
+static int of_mdiobus_register_phy(struct mii_bus *mdio, struct device_node *child,
+ u32 addr)
+{
+ struct phy_device *phy;
+ int ret;
+
+ phy = get_phy_device(mdio, addr);
+ if (IS_ERR(phy))
+ return PTR_ERR(phy);
+
+ /*
+ * Associate the OF node with the device structure so it
+ * can be looked up later
+ */
+ phy->dev.device_node = child;
+
+ /*
+ * All data is now stored in the phy struct;
+ * register it
+ */
+ ret = phy_register_device(phy);
+ if (ret)
+ return ret;
+
+ dev_dbg(&mdio->dev, "registered phy %s at address %i\n",
+ child->name, addr);
+
+ return 0;
+}
+
+/**
+ * of_mdiobus_register - Register mii_bus and create PHYs from the device tree
+ * @mdio: pointer to mii_bus structure
+ * @np: pointer to device_node of MDIO bus.
+ *
+ * This function registers the mii_bus structure and registers a phy_device
+ * for each child node of @np.
+ */
+static int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
+{
+ struct device_node *child;
+ u32 addr;
+ int ret;
+
+ /* Loop over the child nodes and register a phy_device for each one */
+ for_each_available_child_of_node(np, child) {
+ ret = of_property_read_u32(child, "reg", &addr);
+ if (ret) {
+ dev_err(&mdio->dev, "%s has invalid PHY address\n",
+ child->full_name);
+ continue;
+ }
+
+ if (addr >= PHY_MAX_ADDR) {
+ dev_err(&mdio->dev, "%s PHY address %i is too large\n",
+ child->full_name, addr);
+ continue;
+ }
+
+ of_mdiobus_register_phy(mdio, child, addr);
+ }
+
+ return 0;
+}
+
/**
* mdiobus_register - bring up all the PHYs on a given bus and attach them to bus
* @bus: target mii_bus
@@ -85,6 +150,10 @@ int mdiobus_register(struct mii_bus *bus)
list_add_tail(&bus->list, &mii_bus_list);
pr_info("%s: probed\n", dev_name(&bus->dev));
+
+ if (bus->dev.device_node)
+ of_mdiobus_register(bus, bus->dev.device_node);
+
return 0;
}
EXPORT_SYMBOL(mdiobus_register);