[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1450875402-20740-16-git-send-email-andrew@lunn.ch>
Date: Wed, 23 Dec 2015 13:56:29 +0100
From: Andrew Lunn <andrew@...n.ch>
To: Florian Fainelli <f.fainelli@...il.com>, narmstrong@...libre.com,
vivien.didelot@...oirfairelinux.com
Cc: netdev <netdev@...r.kernel.org>, Andrew Lunn <andrew@...n.ch>
Subject: [PATCH RFC 15/28] of_mdio: Add "mii-bus" and address property parser
Add a helper function for parsing an mii-bus property, which should be
a phandle to an MDIO device, and an address of a device on that bus.
Signed-off-by: Andrew Lunn <andrew@...n.ch>
---
drivers/of/of_mdio.c | 38 ++++++++++++++++++++++++++++++++++++++
include/linux/of_mdio.h | 10 ++++++++++
2 files changed, 48 insertions(+)
diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c
index a87a868fed64..3b5c961b8746 100644
--- a/drivers/of/of_mdio.c
+++ b/drivers/of/of_mdio.c
@@ -114,6 +114,44 @@ int of_mdio_parse_addr(struct device *dev, const struct device_node *np)
}
EXPORT_SYMBOL(of_mdio_parse_addr);
+int of_mdio_parse_bus_and_addr(struct device *dev, const struct device_node *np,
+ struct mii_bus **mii_bus, int *addr)
+{
+ struct device_node *bus;
+ int ret;
+
+ bus = of_parse_phandle(np, "mii-bus", 0);
+ if (!bus) {
+ dev_err(dev, "%s has invalid mii-bus property",
+ np->full_name);
+ return -EINVAL;
+ }
+
+ *mii_bus = of_mdio_find_bus(bus);
+ if (!*mii_bus) {
+ ret = -EPROBE_DEFER;
+ goto out;
+ }
+
+ ret = of_property_read_u32(np, "addr", addr);
+ if (ret < 0) {
+ dev_err(dev, "%s has invalid PHY address\n", np->full_name);
+ goto out;
+ }
+
+ /* A PHY must have a reg property in the range [0-31] */
+ if (*addr >= PHY_MAX_ADDR) {
+ dev_err(dev, "%s PHY address %i is too large\n",
+ np->full_name, *addr);
+ ret = -EINVAL;
+ }
+out:
+ of_node_put(bus);
+
+ return ret;
+}
+EXPORT_SYMBOL(of_mdio_parse_bus_and_addr);
+
/**
* of_mdiobus_register - Register mii_bus and create PHYs from the device tree
* @mdio: pointer to mii_bus structure
diff --git a/include/linux/of_mdio.h b/include/linux/of_mdio.h
index 8f2237eb3485..25f9440cbc49 100644
--- a/include/linux/of_mdio.h
+++ b/include/linux/of_mdio.h
@@ -25,6 +25,9 @@ struct phy_device *of_phy_attach(struct net_device *dev,
extern struct mii_bus *of_mdio_find_bus(struct device_node *mdio_np);
extern int of_mdio_parse_addr(struct device *dev, const struct device_node *np);
+extern int of_mdio_parse_bus_and_addr(struct device *dev,
+ const struct device_node *np,
+ struct mii_bus **mii_bus, int *addr);
#else /* CONFIG_OF */
static inline int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
@@ -67,6 +70,13 @@ static inline int of_mdio_parse_addr(struct device *dev,
{
return -ENOSYS;
}
+
+static inline int of_mdio_parse_bus(struct device *dev,
+ const struct device_node *np,
+ struct mii_bus **mii_bus, int *addr)
+{
+ return -ENOSYS;
+}
#endif /* CONFIG_OF */
#if defined(CONFIG_OF) && defined(CONFIG_FIXED_PHY)
--
2.6.3
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists