summaryrefslogtreecommitdiffstats
path: root/drivers/net/phy/phy.c
diff options
context:
space:
mode:
authorSebastian Hesselbarth <sebastian.hesselbarth@gmail.com>2014-02-05 23:40:05 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2014-02-10 09:08:51 +0100
commit29af281cb1bc1d8b9d098fa6b550af9b019a2512 (patch)
treed916c99eaa169b74c26c67fc03b5f8506135a6c4 /drivers/net/phy/phy.c
parent7ccd47fd5ca57b0755abe39cb39887aae783ac9d (diff)
downloadbarebox-29af281cb1bc1d8b9d098fa6b550af9b019a2512.tar.gz
barebox-29af281cb1bc1d8b9d098fa6b550af9b019a2512.tar.xz
net: phy: add of_phy_device_connect
This implements a of_phy_device_connect to allow DT enabled drivers to connect to a PHY device by using the PHY's DT node only. It currently assumes that each PHY node is a child of the corresponding mdio bus. Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/net/phy/phy.c')
-rw-r--r--drivers/net/phy/phy.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index faa5c26c22..879939d4a2 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -331,6 +331,37 @@ fail:
return ret;
}
+#if defined(CONFIG_OFTREE)
+int of_phy_device_connect(struct eth_device *edev, struct device_node *phy_np,
+ void (*adjust_link) (struct eth_device *edev),
+ u32 flags, phy_interface_t interface)
+{
+ struct device_node *bus_np;
+ struct mii_bus *miibus;
+ int phy_addr = -ENODEV;
+
+ if (!phy_np)
+ return -EINVAL;
+
+ of_property_read_u32(phy_np, "reg", &phy_addr);
+
+ bus_np = of_get_parent(phy_np);
+ if (!bus_np)
+ return -ENODEV;
+
+ for_each_mii_bus(miibus) {
+ if (miibus->parent && miibus->parent->device_node == bus_np)
+ return phy_device_connect(edev, miibus, phy_addr,
+ adjust_link, flags, interface);
+ }
+
+ dev_err(&edev->dev, "unable to mdio bus for phy %s\n",
+ phy_np->full_name);
+
+ return -ENODEV;
+}
+#endif
+
/* Generic PHY support and helper functions */
/**