From: Kishon Vijay Abraham I <kishon@ti.com>
To: <gregkh@linuxfoundation.org>
Cc: <kishon@ti.com>, <linux-kernel@vger.kernel.org>
Subject: [PATCH 01/14] phy: core: Add devm_of_phy_get_by_index to phy-core
Date: Tue, 2 Jun 2015 20:13:32 +0530 [thread overview]
Message-ID: <1433256225-476-2-git-send-email-kishon@ti.com> (raw)
In-Reply-To: <1433256225-476-1-git-send-email-kishon@ti.com>
From: Arun Ramamurthy <arun.ramamurthy@broadcom.com>
Some generic drivers, such as ehci, may use multiple phys and for such
drivers referencing phy(s) by name(s) does not make sense. Instead of
inventing new naming schemes and using custom code to iterate through them,
such drivers are better of using nameless phy bindings and using this newly
introduced API to iterate through them.
Signed-off-by: Arun Ramamurthy <arun.ramamurthy@broadcom.com>
Reviewed-by: Ray Jui <rjui@broadcom.com>
Reviewed-by: Scott Branden <sbranden@broadcom.com>
[kishon@ti.com: fix compilation errors]
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
---
Documentation/phy.txt | 7 ++++++-
drivers/phy/phy-core.c | 32 ++++++++++++++++++++++++++++++++
include/linux/phy/phy.h | 9 +++++++++
3 files changed, 47 insertions(+), 1 deletion(-)
diff --git a/Documentation/phy.txt b/Documentation/phy.txt
index 371361c..b388c5a 100644
--- a/Documentation/phy.txt
+++ b/Documentation/phy.txt
@@ -76,6 +76,8 @@ struct phy *phy_get(struct device *dev, const char *string);
struct phy *phy_optional_get(struct device *dev, const char *string);
struct phy *devm_phy_get(struct device *dev, const char *string);
struct phy *devm_phy_optional_get(struct device *dev, const char *string);
+struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np,
+ int index);
phy_get, phy_optional_get, devm_phy_get and devm_phy_optional_get can
be used to get the PHY. In the case of dt boot, the string arguments
@@ -86,7 +88,10 @@ successful PHY get. On driver detach, release function is invoked on
the the devres data and devres data is freed. phy_optional_get and
devm_phy_optional_get should be used when the phy is optional. These
two functions will never return -ENODEV, but instead returns NULL when
-the phy cannot be found.
+the phy cannot be found.Some generic drivers, such as ehci, may use multiple
+phys and for such drivers referencing phy(s) by name(s) does not make sense. In
+this case, devm_of_phy_get_by_index can be used to get a phy reference based on
+the index.
It should be noted that NULL is a valid phy reference. All phy
consumer calls on the NULL phy become NOPs. That is the release calls,
diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
index 3791838..964a84d 100644
--- a/drivers/phy/phy-core.c
+++ b/drivers/phy/phy-core.c
@@ -623,6 +623,38 @@ struct phy *devm_of_phy_get(struct device *dev, struct device_node *np,
EXPORT_SYMBOL_GPL(devm_of_phy_get);
/**
+ * devm_of_phy_get_by_index() - lookup and obtain a reference to a phy by index.
+ * @dev: device that requests this phy
+ * @np: node containing the phy
+ * @index: index of the phy
+ *
+ * Gets the phy using _of_phy_get(), and associates a device with it using
+ * devres. On driver detach, release function is invoked on the devres data,
+ * then, devres data is freed.
+ *
+ */
+struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np,
+ int index)
+{
+ struct phy **ptr, *phy;
+
+ ptr = devres_alloc(devm_phy_release, sizeof(*ptr), GFP_KERNEL);
+ if (!ptr)
+ return ERR_PTR(-ENOMEM);
+
+ phy = _of_phy_get(np, index);
+ if (!IS_ERR(phy)) {
+ *ptr = phy;
+ devres_add(dev, ptr);
+ } else {
+ devres_free(ptr);
+ }
+
+ return phy;
+}
+EXPORT_SYMBOL_GPL(devm_of_phy_get_by_index);
+
+/**
* phy_create() - create a new phy
* @dev: device that is creating the new phy
* @node: device node of the phy
diff --git a/include/linux/phy/phy.h b/include/linux/phy/phy.h
index a0197fa..8cf05e3 100644
--- a/include/linux/phy/phy.h
+++ b/include/linux/phy/phy.h
@@ -133,6 +133,8 @@ struct phy *devm_phy_get(struct device *dev, const char *string);
struct phy *devm_phy_optional_get(struct device *dev, const char *string);
struct phy *devm_of_phy_get(struct device *dev, struct device_node *np,
const char *con_id);
+struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np,
+ int index);
void phy_put(struct phy *phy);
void devm_phy_put(struct device *dev, struct phy *phy);
struct phy *of_phy_get(struct device_node *np, const char *con_id);
@@ -261,6 +263,13 @@ static inline struct phy *devm_of_phy_get(struct device *dev,
return ERR_PTR(-ENOSYS);
}
+static inline struct phy *devm_of_phy_get_by_index(struct device *dev,
+ struct device_node *np,
+ int index)
+{
+ return ERR_PTR(-ENOSYS);
+}
+
static inline void phy_put(struct phy *phy)
{
}
--
1.7.9.5
next prev parent reply other threads:[~2015-06-02 14:44 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-02 14:43 [GIT PULL] phy: for v4.2 merge window Kishon Vijay Abraham I
2015-06-02 14:43 ` Kishon Vijay Abraham I [this message]
2015-06-02 14:43 ` [PATCH 02/14] usb: ehci-platform: Use devm_of_phy_get_by_index Kishon Vijay Abraham I
2015-06-02 14:43 ` [PATCH 03/14] usb: ohci-platform: " Kishon Vijay Abraham I
2015-06-02 14:43 ` [PATCH 04/14] phy: phy-core: allow specifying supply at port level Kishon Vijay Abraham I
2015-06-02 14:43 ` [PATCH 05/14] phy: miphy28lp: fix sparse warnings Kishon Vijay Abraham I
2015-06-02 14:43 ` [PATCH 06/14] phy: miphy365x: " Kishon Vijay Abraham I
2015-06-02 14:43 ` [PATCH 07/14] phy: core: Check requested PHY status in _of_phy_get() Kishon Vijay Abraham I
2015-06-02 14:43 ` [PATCH 08/14] phy: rcar-gen2: Add support for R-Car E2 Kishon Vijay Abraham I
2015-06-02 14:43 ` [PATCH 09/14] Documentation: devicetree: add Broadcom SATA PHY binding Kishon Vijay Abraham I
2015-06-02 14:43 ` [PATCH 10/14] phy: add Broadcom SATA3 PHY driver for Broadcom STB SoCs Kishon Vijay Abraham I
2015-06-02 14:43 ` [PATCH 11/14] phy: twl4030-usb: make runtime pm more reliable Kishon Vijay Abraham I
2015-06-02 14:43 ` [PATCH 12/14] phy: twl4030-usb: remove pointless 'suspended' test in 'suspend' callback Kishon Vijay Abraham I
2015-06-02 14:43 ` [PATCH 13/14] phy: twl4030-usb: remove incorrect pm_runtime_get_sync() in probe function Kishon Vijay Abraham I
2015-06-02 14:43 ` [PATCH 14/14] phy: twl4030-usb: add ABI documentation Kishon Vijay Abraham I
2015-06-03 5:14 ` [GIT PULL] phy: for v4.2 merge window Greg KH
2015-06-03 5:32 ` Kishon Vijay Abraham I
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=1433256225-476-2-git-send-email-kishon@ti.com \
--to=kishon@ti.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.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