From: Reinder de Haan <[email protected]>

In some cases it is useful to be able to get a reset-controller by
index rather then by name. E.g. for a generic ip-block driver such
as the ehci-platform drivers which needs to support more then one reset,
without knowing the names of the reset lines (as that would make it
non generic).

Signed-off-by: Reinder de Haan <[email protected]>
Signed-off-by: Hans de Goede <[email protected]>
---
 drivers/reset/core.c  | 23 +++++++++++++++++++----
 include/linux/reset.h |  8 ++++++++
 2 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/drivers/reset/core.c b/drivers/reset/core.c
index 7955e00..b2405d8 100644
--- a/drivers/reset/core.c
+++ b/drivers/reset/core.c
@@ -152,16 +152,31 @@ EXPORT_SYMBOL_GPL(reset_control_status);
 struct reset_control *of_reset_control_get(struct device_node *node,
                                           const char *id)
 {
+       int index = 0;
+
+       if (id)
+               index = of_property_match_string(node, "reset-names", id);
+
+       return of_reset_control_get_by_index(node, index);
+}
+
+/**
+ * of_reset_control_get_by_index - Lookup and obtain a reference to a
+ * reset controller.
+ * @node: device to be reset by the controller
+ * @index: reset line index
+ *
+ * Returns a struct reset_control or IS_ERR() condition containing errno.
+ */
+struct reset_control *of_reset_control_get_by_index(struct device_node *node,
+                                                   int index)
+{
        struct reset_control *rstc = ERR_PTR(-EPROBE_DEFER);
        struct reset_controller_dev *r, *rcdev;
        struct of_phandle_args args;
-       int index = 0;
        int rstc_id;
        int ret;
 
-       if (id)
-               index = of_property_match_string(node,
-                                                "reset-names", id);
        ret = of_parse_phandle_with_args(node, "resets", "#reset-cells",
                                         index, &args);
        if (ret)
diff --git a/include/linux/reset.h b/include/linux/reset.h
index 7f65f9c..8f56b66 100644
--- a/include/linux/reset.h
+++ b/include/linux/reset.h
@@ -38,6 +38,9 @@ static inline struct reset_control 
*devm_reset_control_get_optional(
 struct reset_control *of_reset_control_get(struct device_node *node,
                                           const char *id);
 
+struct reset_control *of_reset_control_get_by_index(struct device_node *node,
+                                          int index);
+
 #else
 
 static inline int reset_control_reset(struct reset_control *rstc)
@@ -106,6 +109,11 @@ static inline struct reset_control *of_reset_control_get(
        return ERR_PTR(-ENOSYS);
 }
 
+static inline struct reset_control *of_reset_control_get_by_index(
+                               struct device_node *node, int index)
+{
+       return ERR_PTR(-EINVAL);
+}
 #endif /* CONFIG_RESET_CONTROLLER */
 
 #endif
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to