diff options
author | Ramiro Oliveira <Ramiro.Oliveira@synopsys.com> | 2017-01-13 12:57:41 -0500 |
---|---|---|
committer | Philipp Zabel <p.zabel@pengutronix.de> | 2017-01-20 04:36:15 -0500 |
commit | bb475230b8e59a547ab66ac3b02572df21a580e9 (patch) | |
tree | 9fecc3af684950c395564fe3f5656ed1520589df /drivers | |
parent | ee48c726d0b014ac8dd5ec803fb63ce0596a42cf (diff) |
reset: make optional functions really optional
The *_get_optional_* functions weren't really optional so this patch
makes them really optional.
These *_get_optional_* functions will now return NULL instead of an error
if no matching reset phandle is found in the DT, and all the
reset_control_* functions now accept NULL rstc pointers.
Signed-off-by: Ramiro Oliveira <Ramiro.Oliveira@synopsys.com>
Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/reset/core.c | 49 |
1 files changed, 39 insertions, 10 deletions
diff --git a/drivers/reset/core.c b/drivers/reset/core.c index 272c1e4ecb5c..c79cce3a7b6d 100644 --- a/drivers/reset/core.c +++ b/drivers/reset/core.c | |||
@@ -143,12 +143,18 @@ EXPORT_SYMBOL_GPL(devm_reset_controller_register); | |||
143 | * a no-op. | 143 | * a no-op. |
144 | * Consumers must not use reset_control_(de)assert on shared reset lines when | 144 | * Consumers must not use reset_control_(de)assert on shared reset lines when |
145 | * reset_control_reset has been used. | 145 | * reset_control_reset has been used. |
146 | * | ||
147 | * If rstc is NULL it is an optional reset and the function will just | ||
148 | * return 0. | ||
146 | */ | 149 | */ |
147 | int reset_control_reset(struct reset_control *rstc) | 150 | int reset_control_reset(struct reset_control *rstc) |
148 | { | 151 | { |
149 | int ret; | 152 | int ret; |
150 | 153 | ||
151 | if (WARN_ON(IS_ERR_OR_NULL(rstc))) | 154 | if (!rstc) |
155 | return 0; | ||
156 | |||
157 | if (WARN_ON(IS_ERR(rstc))) | ||
152 | return -EINVAL; | 158 | return -EINVAL; |
153 | 159 | ||
154 | if (!rstc->rcdev->ops->reset) | 160 | if (!rstc->rcdev->ops->reset) |
@@ -182,10 +188,17 @@ EXPORT_SYMBOL_GPL(reset_control_reset); | |||
182 | * internal state to be reset, but must be prepared for this to happen. | 188 | * internal state to be reset, but must be prepared for this to happen. |
183 | * Consumers must not use reset_control_reset on shared reset lines when | 189 | * Consumers must not use reset_control_reset on shared reset lines when |
184 | * reset_control_(de)assert has been used. | 190 | * reset_control_(de)assert has been used. |
191 | * return 0. | ||
192 | * | ||
193 | * If rstc is NULL it is an optional reset and the function will just | ||
194 | * return 0. | ||
185 | */ | 195 | */ |
186 | int reset_control_assert(struct reset_control *rstc) | 196 | int reset_control_assert(struct reset_control *rstc) |
187 | { | 197 | { |
188 | if (WARN_ON(IS_ERR_OR_NULL(rstc))) | 198 | if (!rstc) |
199 | return 0; | ||
200 | |||
201 | if (WARN_ON(IS_ERR(rstc))) | ||
189 | return -EINVAL; | 202 | return -EINVAL; |
190 | 203 | ||
191 | if (!rstc->rcdev->ops->assert) | 204 | if (!rstc->rcdev->ops->assert) |
@@ -213,10 +226,17 @@ EXPORT_SYMBOL_GPL(reset_control_assert); | |||
213 | * After calling this function, the reset is guaranteed to be deasserted. | 226 | * After calling this function, the reset is guaranteed to be deasserted. |
214 | * Consumers must not use reset_control_reset on shared reset lines when | 227 | * Consumers must not use reset_control_reset on shared reset lines when |
215 | * reset_control_(de)assert has been used. | 228 | * reset_control_(de)assert has been used. |
229 | * return 0. | ||
230 | * | ||
231 | * If rstc is NULL it is an optional reset and the function will just | ||
232 | * return 0. | ||
216 | */ | 233 | */ |
217 | int reset_control_deassert(struct reset_control *rstc) | 234 | int reset_control_deassert(struct reset_control *rstc) |
218 | { | 235 | { |
219 | if (WARN_ON(IS_ERR_OR_NULL(rstc))) | 236 | if (!rstc) |
237 | return 0; | ||
238 | |||
239 | if (WARN_ON(IS_ERR(rstc))) | ||
220 | return -EINVAL; | 240 | return -EINVAL; |
221 | 241 | ||
222 | if (!rstc->rcdev->ops->deassert) | 242 | if (!rstc->rcdev->ops->deassert) |
@@ -237,12 +257,15 @@ EXPORT_SYMBOL_GPL(reset_control_deassert); | |||
237 | /** | 257 | /** |
238 | * reset_control_status - returns a negative errno if not supported, a | 258 | * reset_control_status - returns a negative errno if not supported, a |
239 | * positive value if the reset line is asserted, or zero if the reset | 259 | * positive value if the reset line is asserted, or zero if the reset |
240 | * line is not asserted. | 260 | * line is not asserted or if the desc is NULL (optional reset). |
241 | * @rstc: reset controller | 261 | * @rstc: reset controller |
242 | */ | 262 | */ |
243 | int reset_control_status(struct reset_control *rstc) | 263 | int reset_control_status(struct reset_control *rstc) |
244 | { | 264 | { |
245 | if (WARN_ON(IS_ERR_OR_NULL(rstc))) | 265 | if (!rstc) |
266 | return 0; | ||
267 | |||
268 | if (WARN_ON(IS_ERR(rstc))) | ||
246 | return -EINVAL; | 269 | return -EINVAL; |
247 | 270 | ||
248 | if (rstc->rcdev->ops->status) | 271 | if (rstc->rcdev->ops->status) |
@@ -299,7 +322,8 @@ static void __reset_control_put(struct reset_control *rstc) | |||
299 | } | 322 | } |
300 | 323 | ||
301 | struct reset_control *__of_reset_control_get(struct device_node *node, | 324 | struct reset_control *__of_reset_control_get(struct device_node *node, |
302 | const char *id, int index, bool shared) | 325 | const char *id, int index, bool shared, |
326 | bool optional) | ||
303 | { | 327 | { |
304 | struct reset_control *rstc; | 328 | struct reset_control *rstc; |
305 | struct reset_controller_dev *r, *rcdev; | 329 | struct reset_controller_dev *r, *rcdev; |
@@ -313,14 +337,18 @@ struct reset_control *__of_reset_control_get(struct device_node *node, | |||
313 | if (id) { | 337 | if (id) { |
314 | index = of_property_match_string(node, | 338 | index = of_property_match_string(node, |
315 | "reset-names", id); | 339 | "reset-names", id); |
340 | if (index == -EILSEQ) | ||
341 | return ERR_PTR(index); | ||
316 | if (index < 0) | 342 | if (index < 0) |
317 | return ERR_PTR(-ENOENT); | 343 | return optional ? NULL : ERR_PTR(-ENOENT); |
318 | } | 344 | } |
319 | 345 | ||
320 | ret = of_parse_phandle_with_args(node, "resets", "#reset-cells", | 346 | ret = of_parse_phandle_with_args(node, "resets", "#reset-cells", |
321 | index, &args); | 347 | index, &args); |
322 | if (ret) | 348 | if (ret == -EINVAL) |
323 | return ERR_PTR(ret); | 349 | return ERR_PTR(ret); |
350 | if (ret) | ||
351 | return optional ? NULL : ERR_PTR(ret); | ||
324 | 352 | ||
325 | mutex_lock(&reset_list_mutex); | 353 | mutex_lock(&reset_list_mutex); |
326 | rcdev = NULL; | 354 | rcdev = NULL; |
@@ -379,7 +407,8 @@ static void devm_reset_control_release(struct device *dev, void *res) | |||
379 | } | 407 | } |
380 | 408 | ||
381 | struct reset_control *__devm_reset_control_get(struct device *dev, | 409 | struct reset_control *__devm_reset_control_get(struct device *dev, |
382 | const char *id, int index, bool shared) | 410 | const char *id, int index, bool shared, |
411 | bool optional) | ||
383 | { | 412 | { |
384 | struct reset_control **ptr, *rstc; | 413 | struct reset_control **ptr, *rstc; |
385 | 414 | ||
@@ -389,7 +418,7 @@ struct reset_control *__devm_reset_control_get(struct device *dev, | |||
389 | return ERR_PTR(-ENOMEM); | 418 | return ERR_PTR(-ENOMEM); |
390 | 419 | ||
391 | rstc = __of_reset_control_get(dev ? dev->of_node : NULL, | 420 | rstc = __of_reset_control_get(dev ? dev->of_node : NULL, |
392 | id, index, shared); | 421 | id, index, shared, optional); |
393 | if (!IS_ERR(rstc)) { | 422 | if (!IS_ERR(rstc)) { |
394 | *ptr = rstc; | 423 | *ptr = rstc; |
395 | devres_add(dev, ptr); | 424 | devres_add(dev, ptr); |