summaryrefslogtreecommitdiffstats
path: root/drivers/phy
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2016-09-29 11:41:14 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2016-09-29 13:58:32 +0200
commit850557842f01ecb47b00ecb43b3bc3c8f1bb826f (patch)
tree5ed1eea35fe33e49c1513042cbe4b93522cd6bbf /drivers/phy
parent4ed80f0643ce5c83ec8a5c5c9713ca7b1cb2f83a (diff)
downloadbarebox-850557842f01ecb47b00ecb43b3bc3c8f1bb826f.tar.gz
barebox-850557842f01ecb47b00ecb43b3bc3c8f1bb826f.tar.xz
phy: Introduce of_phy_get_by_phandle
Currently generic phy support assumes that the standard phy binding from dts/Bindings/phy/phy-bindings.txt is used. This adds a helper function which can be used to retrieve a phy when this standard binding is not used. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/phy')
-rw-r--r--drivers/phy/phy-core.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
index 67af14f680..7c1f3d440b 100644
--- a/drivers/phy/phy-core.c
+++ b/drivers/phy/phy-core.c
@@ -268,6 +268,42 @@ struct phy *of_phy_get(struct device_node *np, const char *con_id)
}
/**
+ * of_phy_get_by_phandle() - lookup and obtain a reference to a phy.
+ * @dev: device that requests this phy
+ * @phandle - name of the property holding the phy phandle value
+ * @index - the index of the phy
+ *
+ * Returns the phy driver, after getting a refcount to it; or
+ * -ENODEV if there is no such phy. The caller is responsible for
+ * calling phy_put() to release that count.
+ */
+struct phy *of_phy_get_by_phandle(struct device_d *dev, const char *phandle,
+ u8 index)
+{
+ struct device_node *np;
+ struct phy_provider *phy_provider;
+
+ if (!dev->device_node) {
+ dev_dbg(dev, "device does not have a device node entry\n");
+ return ERR_PTR(-EINVAL);
+ }
+
+ np = of_parse_phandle(dev->device_node, phandle, index);
+ if (!np) {
+ dev_dbg(dev, "failed to get %s phandle in %s node\n", phandle,
+ dev->device_node->full_name);
+ return ERR_PTR(-ENODEV);
+ }
+
+ phy_provider = of_phy_provider_lookup(np);
+ if (IS_ERR(phy_provider)) {
+ return ERR_PTR(-ENODEV);
+ }
+
+ return phy_provider->of_xlate(phy_provider->dev, NULL);
+}
+
+/**
* phy_get() - lookup and obtain a reference to a phy.
* @dev: device that requests this phy
* @string: the phy name as given in the dt data or the name of the controller