sunxi: initial 4.4 support
[openwrt/openwrt.git] / target / linux / sunxi / patches-4.4 / 140-reset-add-of_reset_control_get_by_index.patch
1 From b4faa163a7ebae9faab5d0aefe70143e3379178b Mon Sep 17 00:00:00 2001
2 From: Vince Hsu <vinceh@nvidia.com>
3 Date: Mon, 13 Jul 2015 13:39:39 +0100
4 Subject: [PATCH] reset: add of_reset_control_get_by_index()
5
6 Add of_reset_control_get_by_index() to allow the drivers to get reset
7 device without knowing its name.
8
9 Signed-off-by: Vince Hsu <vinceh@nvidia.com>
10 [jonathanh@nvidia.com: Updated stub function to return -ENOTSUPP instead
11 of -ENOSYS which should only be used for system calls.]
12 Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
13 Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
14 ---
15 drivers/reset/core.c | 40 +++++++++++++++++++++++++++++-----------
16 include/linux/reset.h | 9 +++++++++
17 2 files changed, 38 insertions(+), 11 deletions(-)
18
19 diff --git a/drivers/reset/core.c b/drivers/reset/core.c
20 index 7955e00..81ae17d 100644
21 --- a/drivers/reset/core.c
22 +++ b/drivers/reset/core.c
23 @@ -141,27 +141,24 @@ int reset_control_status(struct reset_control *rstc)
24 EXPORT_SYMBOL_GPL(reset_control_status);
25
26 /**
27 - * of_reset_control_get - Lookup and obtain a reference to a reset controller.
28 + * of_reset_control_get_by_index - Lookup and obtain a reference to a reset
29 + * controller by index.
30 * @node: device to be reset by the controller
31 - * @id: reset line name
32 - *
33 - * Returns a struct reset_control or IS_ERR() condition containing errno.
34 + * @index: index of the reset controller
35 *
36 - * Use of id names is optional.
37 + * This is to be used to perform a list of resets for a device or power domain
38 + * in whatever order. Returns a struct reset_control or IS_ERR() condition
39 + * containing errno.
40 */
41 -struct reset_control *of_reset_control_get(struct device_node *node,
42 - const char *id)
43 +struct reset_control *of_reset_control_get_by_index(struct device_node *node,
44 + int index)
45 {
46 struct reset_control *rstc = ERR_PTR(-EPROBE_DEFER);
47 struct reset_controller_dev *r, *rcdev;
48 struct of_phandle_args args;
49 - int index = 0;
50 int rstc_id;
51 int ret;
52
53 - if (id)
54 - index = of_property_match_string(node,
55 - "reset-names", id);
56 ret = of_parse_phandle_with_args(node, "resets", "#reset-cells",
57 index, &args);
58 if (ret)
59 @@ -202,6 +199,27 @@ struct reset_control *of_reset_control_get(struct device_node *node,
60
61 return rstc;
62 }
63 +EXPORT_SYMBOL_GPL(of_reset_control_get_by_index);
64 +
65 +/**
66 + * of_reset_control_get - Lookup and obtain a reference to a reset controller.
67 + * @node: device to be reset by the controller
68 + * @id: reset line name
69 + *
70 + * Returns a struct reset_control or IS_ERR() condition containing errno.
71 + *
72 + * Use of id names is optional.
73 + */
74 +struct reset_control *of_reset_control_get(struct device_node *node,
75 + const char *id)
76 +{
77 + int index = 0;
78 +
79 + if (id)
80 + index = of_property_match_string(node,
81 + "reset-names", id);
82 + return of_reset_control_get_by_index(node, index);
83 +}
84 EXPORT_SYMBOL_GPL(of_reset_control_get);
85
86 /**
87 diff --git a/include/linux/reset.h b/include/linux/reset.h
88 index 7f65f9c..6db74ad 100644
89 --- a/include/linux/reset.h
90 +++ b/include/linux/reset.h
91 @@ -38,6 +38,9 @@ static inline struct reset_control *devm_reset_control_get_optional(
92 struct reset_control *of_reset_control_get(struct device_node *node,
93 const char *id);
94
95 +struct reset_control *of_reset_control_get_by_index(
96 + struct device_node *node, int index);
97 +
98 #else
99
100 static inline int reset_control_reset(struct reset_control *rstc)
101 @@ -106,6 +109,12 @@ static inline struct reset_control *of_reset_control_get(
102 return ERR_PTR(-ENOSYS);
103 }
104
105 +static inline struct reset_control *of_reset_control_get_by_index(
106 + struct device_node *node, int index)
107 +{
108 + return ERR_PTR(-ENOTSUPP);
109 +}
110 +
111 #endif /* CONFIG_RESET_CONTROLLER */
112
113 #endif