diff options
author | Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com> | 2014-02-05 23:40:05 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2014-02-10 09:08:51 +0100 |
commit | 29af281cb1bc1d8b9d098fa6b550af9b019a2512 (patch) | |
tree | d916c99eaa169b74c26c67fc03b5f8506135a6c4 | |
parent | 7ccd47fd5ca57b0755abe39cb39887aae783ac9d (diff) | |
download | barebox-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>
-rw-r--r-- | drivers/net/phy/phy.c | 31 | ||||
-rw-r--r-- | include/linux/phy.h | 14 |
2 files changed, 45 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 */ /** diff --git a/include/linux/phy.h b/include/linux/phy.h index c8980b0191..9567c43e38 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -280,6 +280,20 @@ int phy_device_connect(struct eth_device *dev, struct mii_bus *bus, int addr, void (*adjust_link) (struct eth_device *edev), u32 flags, phy_interface_t interface); +#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); +#else +static inline 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) +{ + return -ENOSYS; +} +#endif + int phy_update_status(struct phy_device *phydev); int phy_wait_aneg_done(struct phy_device *phydev); |