diff options
author | Hans de Goede <hdegoede@redhat.com> | 2016-02-23 12:46:24 -0500 |
---|---|---|
committer | Philipp Zabel <p.zabel@pengutronix.de> | 2016-03-30 09:42:01 -0400 |
commit | 6c96f05c8bb8bc4177613ef3c23a56b455e75887 (patch) | |
tree | 58c17810ceabd3002d2dad81fb693d5f22887b4a /drivers/reset | |
parent | f55532a0c0b8bb6148f4e07853b876ef73bc69ca (diff) |
reset: Make [of_]reset_control_get[_foo] functions wrappers
With both the regular, _by_index and _optional variants we already have
quite a few variants of [of_]reset_control_get[_foo], the upcoming
addition of shared reset lines support makes this worse.
This commit changes all the variants into wrappers around common core
functions. For completeness sake this commit also adds a new
devm_get_reset_control_by_index wrapper.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
Diffstat (limited to 'drivers/reset')
-rw-r--r-- | drivers/reset/core.c | 84 |
1 files changed, 17 insertions, 67 deletions
diff --git a/drivers/reset/core.c b/drivers/reset/core.c index f15f150b79da..bdf1763da87a 100644 --- a/drivers/reset/core.c +++ b/drivers/reset/core.c | |||
@@ -136,18 +136,8 @@ int reset_control_status(struct reset_control *rstc) | |||
136 | } | 136 | } |
137 | EXPORT_SYMBOL_GPL(reset_control_status); | 137 | EXPORT_SYMBOL_GPL(reset_control_status); |
138 | 138 | ||
139 | /** | 139 | struct reset_control *__of_reset_control_get(struct device_node *node, |
140 | * of_reset_control_get_by_index - Lookup and obtain a reference to a reset | 140 | const char *id, int index) |
141 | * controller by index. | ||
142 | * @node: device to be reset by the controller | ||
143 | * @index: index of the reset controller | ||
144 | * | ||
145 | * This is to be used to perform a list of resets for a device or power domain | ||
146 | * in whatever order. Returns a struct reset_control or IS_ERR() condition | ||
147 | * containing errno. | ||
148 | */ | ||
149 | struct reset_control *of_reset_control_get_by_index(struct device_node *node, | ||
150 | int index) | ||
151 | { | 141 | { |
152 | struct reset_control *rstc; | 142 | struct reset_control *rstc; |
153 | struct reset_controller_dev *r, *rcdev; | 143 | struct reset_controller_dev *r, *rcdev; |
@@ -155,6 +145,16 @@ struct reset_control *of_reset_control_get_by_index(struct device_node *node, | |||
155 | int rstc_id; | 145 | int rstc_id; |
156 | int ret; | 146 | int ret; |
157 | 147 | ||
148 | if (!node) | ||
149 | return ERR_PTR(-EINVAL); | ||
150 | |||
151 | if (id) { | ||
152 | index = of_property_match_string(node, | ||
153 | "reset-names", id); | ||
154 | if (index < 0) | ||
155 | return ERR_PTR(-ENOENT); | ||
156 | } | ||
157 | |||
158 | ret = of_parse_phandle_with_args(node, "resets", "#reset-cells", | 158 | ret = of_parse_phandle_with_args(node, "resets", "#reset-cells", |
159 | index, &args); | 159 | index, &args); |
160 | if (ret) | 160 | if (ret) |
@@ -200,49 +200,7 @@ struct reset_control *of_reset_control_get_by_index(struct device_node *node, | |||
200 | 200 | ||
201 | return rstc; | 201 | return rstc; |
202 | } | 202 | } |
203 | EXPORT_SYMBOL_GPL(of_reset_control_get_by_index); | 203 | EXPORT_SYMBOL_GPL(__of_reset_control_get); |
204 | |||
205 | /** | ||
206 | * of_reset_control_get - Lookup and obtain a reference to a reset controller. | ||
207 | * @node: device to be reset by the controller | ||
208 | * @id: reset line name | ||
209 | * | ||
210 | * Returns a struct reset_control or IS_ERR() condition containing errno. | ||
211 | * | ||
212 | * Use of id names is optional. | ||
213 | */ | ||
214 | struct reset_control *of_reset_control_get(struct device_node *node, | ||
215 | const char *id) | ||
216 | { | ||
217 | int index = 0; | ||
218 | |||
219 | if (id) { | ||
220 | index = of_property_match_string(node, | ||
221 | "reset-names", id); | ||
222 | if (index < 0) | ||
223 | return ERR_PTR(-ENOENT); | ||
224 | } | ||
225 | return of_reset_control_get_by_index(node, index); | ||
226 | } | ||
227 | EXPORT_SYMBOL_GPL(of_reset_control_get); | ||
228 | |||
229 | /** | ||
230 | * reset_control_get - Lookup and obtain a reference to a reset controller. | ||
231 | * @dev: device to be reset by the controller | ||
232 | * @id: reset line name | ||
233 | * | ||
234 | * Returns a struct reset_control or IS_ERR() condition containing errno. | ||
235 | * | ||
236 | * Use of id names is optional. | ||
237 | */ | ||
238 | struct reset_control *reset_control_get(struct device *dev, const char *id) | ||
239 | { | ||
240 | if (!dev) | ||
241 | return ERR_PTR(-EINVAL); | ||
242 | |||
243 | return of_reset_control_get(dev->of_node, id); | ||
244 | } | ||
245 | EXPORT_SYMBOL_GPL(reset_control_get); | ||
246 | 204 | ||
247 | /** | 205 | /** |
248 | * reset_control_put - free the reset controller | 206 | * reset_control_put - free the reset controller |
@@ -264,16 +222,8 @@ static void devm_reset_control_release(struct device *dev, void *res) | |||
264 | reset_control_put(*(struct reset_control **)res); | 222 | reset_control_put(*(struct reset_control **)res); |
265 | } | 223 | } |
266 | 224 | ||
267 | /** | 225 | struct reset_control *__devm_reset_control_get(struct device *dev, |
268 | * devm_reset_control_get - resource managed reset_control_get() | 226 | const char *id, int index) |
269 | * @dev: device to be reset by the controller | ||
270 | * @id: reset line name | ||
271 | * | ||
272 | * Managed reset_control_get(). For reset controllers returned from this | ||
273 | * function, reset_control_put() is called automatically on driver detach. | ||
274 | * See reset_control_get() for more information. | ||
275 | */ | ||
276 | struct reset_control *devm_reset_control_get(struct device *dev, const char *id) | ||
277 | { | 227 | { |
278 | struct reset_control **ptr, *rstc; | 228 | struct reset_control **ptr, *rstc; |
279 | 229 | ||
@@ -282,7 +232,7 @@ struct reset_control *devm_reset_control_get(struct device *dev, const char *id) | |||
282 | if (!ptr) | 232 | if (!ptr) |
283 | return ERR_PTR(-ENOMEM); | 233 | return ERR_PTR(-ENOMEM); |
284 | 234 | ||
285 | rstc = reset_control_get(dev, id); | 235 | rstc = __of_reset_control_get(dev ? dev->of_node : NULL, id, index); |
286 | if (!IS_ERR(rstc)) { | 236 | if (!IS_ERR(rstc)) { |
287 | *ptr = rstc; | 237 | *ptr = rstc; |
288 | devres_add(dev, ptr); | 238 | devres_add(dev, ptr); |
@@ -292,7 +242,7 @@ struct reset_control *devm_reset_control_get(struct device *dev, const char *id) | |||
292 | 242 | ||
293 | return rstc; | 243 | return rstc; |
294 | } | 244 | } |
295 | EXPORT_SYMBOL_GPL(devm_reset_control_get); | 245 | EXPORT_SYMBOL_GPL(__devm_reset_control_get); |
296 | 246 | ||
297 | /** | 247 | /** |
298 | * device_reset - find reset controller associated with the device | 248 | * device_reset - find reset controller associated with the device |