From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 5/9] phy: Introduce of_phy_get_by_phandle
Date: Thu, 29 Sep 2016 14:38:56 +0200 [thread overview]
Message-ID: <20160929123900.24853-5-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20160929123900.24853-1-s.hauer@pengutronix.de>
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>
---
drivers/phy/phy-core.c | 36 ++++++++++++++++++++++++++++++++++++
include/linux/phy/phy.h | 8 ++++++++
2 files changed, 44 insertions(+)
diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
index 67af14f..7c1f3d4 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
diff --git a/include/linux/phy/phy.h b/include/linux/phy/phy.h
index 94f0044..0d78923 100644
--- a/include/linux/phy/phy.h
+++ b/include/linux/phy/phy.h
@@ -136,6 +136,8 @@ static inline void phy_set_bus_width(struct phy *phy, int bus_width)
}
struct phy *phy_get(struct device_d *dev, const char *string);
struct phy *phy_optional_get(struct device_d *dev, const char *string);
+struct phy *of_phy_get_by_phandle(struct device_d *dev, const char *phandle,
+ u8 index);
void phy_put(struct phy *phy);
struct phy *of_phy_get(struct device_node *np, const char *con_id);
struct phy *of_phy_simple_xlate(struct device_d *dev,
@@ -198,6 +200,12 @@ static inline struct phy *phy_optional_get(struct device_d *dev,
return ERR_PTR(-ENOSYS);
}
+static inline struct phy *of_phy_get_by_phandle(struct device_d *dev,
+ const char *phandle, u8 index)
+{
+ return ERR_PTR(-ENOSYS);
+}
+
static inline void phy_put(struct phy *phy)
{
}
--
2.9.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2016-09-29 12:39 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-29 12:38 [PATCH 1/9] usb: Use standard debug macro Sascha Hauer
2016-09-29 12:38 ` [PATCH 2/9] usb: Add usb phy to usb host Sascha Hauer
2016-09-29 12:38 ` [PATCH 3/9] usb: ehci: forward phy given in registration data to host Sascha Hauer
2016-09-29 12:38 ` [PATCH 4/9] usb: imx-usb-phy: Drop unnecessary read/modify/write Sascha Hauer
2016-09-29 12:38 ` Sascha Hauer [this message]
2016-09-29 12:38 ` [PATCH 6/9] phy: Introduce to_usbphy conversion function Sascha Hauer
2016-09-29 12:38 ` [PATCH 7/9] phy: Add usb-nop-xceiv support Sascha Hauer
2016-09-29 12:38 ` [PATCH 8/9] usb: imx-us-phy: Convert driver to generic phy support Sascha Hauer
2016-09-29 12:39 ` [PATCH 9/9] usb: imx-us-phy: implement notify_(dis)concect Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160929123900.24853-5-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox