1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_RESET_H_
3 #define _LINUX_RESET_H_
6 #include <linux/errno.h>
7 #include <linux/types.h>
13 #ifdef CONFIG_RESET_CONTROLLER
15 int reset_control_reset(struct reset_control *rstc);
16 int reset_control_rearm(struct reset_control *rstc);
17 int reset_control_assert(struct reset_control *rstc);
18 int reset_control_deassert(struct reset_control *rstc);
19 int reset_control_status(struct reset_control *rstc);
20 int reset_control_acquire(struct reset_control *rstc);
21 void reset_control_release(struct reset_control *rstc);
23 struct reset_control *__of_reset_control_get(struct device_node *node,
24 const char *id, int index, bool shared,
25 bool optional, bool acquired);
26 struct reset_control *__reset_control_get(struct device *dev, const char *id,
27 int index, bool shared,
28 bool optional, bool acquired);
29 void reset_control_put(struct reset_control *rstc);
30 int __device_reset(struct device *dev, bool optional);
31 struct reset_control *__devm_reset_control_get(struct device *dev,
32 const char *id, int index, bool shared,
33 bool optional, bool acquired);
35 struct reset_control *devm_reset_control_array_get(struct device *dev,
36 bool shared, bool optional);
37 struct reset_control *of_reset_control_array_get(struct device_node *np,
38 bool shared, bool optional,
41 int reset_control_get_count(struct device *dev);
45 static inline int reset_control_reset(struct reset_control *rstc)
50 static inline int reset_control_assert(struct reset_control *rstc)
55 static inline int reset_control_deassert(struct reset_control *rstc)
60 static inline int reset_control_status(struct reset_control *rstc)
65 static inline int reset_control_acquire(struct reset_control *rstc)
70 static inline void reset_control_release(struct reset_control *rstc)
74 static inline void reset_control_put(struct reset_control *rstc)
78 static inline int __device_reset(struct device *dev, bool optional)
80 return optional ? 0 : -ENOTSUPP;
83 static inline struct reset_control *__of_reset_control_get(
84 struct device_node *node,
85 const char *id, int index, bool shared,
86 bool optional, bool acquired)
88 return optional ? NULL : ERR_PTR(-ENOTSUPP);
91 static inline struct reset_control *__reset_control_get(
92 struct device *dev, const char *id,
93 int index, bool shared, bool optional,
96 return optional ? NULL : ERR_PTR(-ENOTSUPP);
99 static inline struct reset_control *__devm_reset_control_get(
100 struct device *dev, const char *id,
101 int index, bool shared, bool optional,
104 return optional ? NULL : ERR_PTR(-ENOTSUPP);
107 static inline struct reset_control *
108 devm_reset_control_array_get(struct device *dev, bool shared, bool optional)
110 return optional ? NULL : ERR_PTR(-ENOTSUPP);
113 static inline struct reset_control *
114 of_reset_control_array_get(struct device_node *np, bool shared, bool optional,
117 return optional ? NULL : ERR_PTR(-ENOTSUPP);
120 static inline int reset_control_get_count(struct device *dev)
125 #endif /* CONFIG_RESET_CONTROLLER */
127 static inline int __must_check device_reset(struct device *dev)
129 return __device_reset(dev, false);
132 static inline int device_reset_optional(struct device *dev)
134 return __device_reset(dev, true);
138 * reset_control_get_exclusive - Lookup and obtain an exclusive reference
139 * to a reset controller.
140 * @dev: device to be reset by the controller
141 * @id: reset line name
143 * Returns a struct reset_control or IS_ERR() condition containing errno.
144 * If this function is called more than once for the same reset_control it will
147 * See reset_control_get_shared() for details on shared references to
150 * Use of id names is optional.
152 static inline struct reset_control *
153 __must_check reset_control_get_exclusive(struct device *dev, const char *id)
155 return __reset_control_get(dev, id, 0, false, false, true);
159 * reset_control_get_exclusive_released - Lookup and obtain a temoprarily
160 * exclusive reference to a reset
162 * @dev: device to be reset by the controller
163 * @id: reset line name
165 * Returns a struct reset_control or IS_ERR() condition containing errno.
166 * reset-controls returned by this function must be acquired via
167 * reset_control_acquire() before they can be used and should be released
168 * via reset_control_release() afterwards.
170 * Use of id names is optional.
172 static inline struct reset_control *
173 __must_check reset_control_get_exclusive_released(struct device *dev,
176 return __reset_control_get(dev, id, 0, false, false, false);
180 * reset_control_get_shared - Lookup and obtain a shared reference to a
182 * @dev: device to be reset by the controller
183 * @id: reset line name
185 * Returns a struct reset_control or IS_ERR() condition containing errno.
186 * This function is intended for use with reset-controls which are shared
187 * between hardware blocks.
189 * When a reset-control is shared, the behavior of reset_control_assert /
190 * deassert is changed, the reset-core will keep track of a deassert_count
191 * and only (re-)assert the reset after reset_control_assert has been called
192 * as many times as reset_control_deassert was called. Also see the remark
193 * about shared reset-controls in the reset_control_assert docs.
195 * Calling reset_control_assert without first calling reset_control_deassert
196 * is not allowed on a shared reset control. Calling reset_control_reset is
197 * also not allowed on a shared reset control.
199 * Use of id names is optional.
201 static inline struct reset_control *reset_control_get_shared(
202 struct device *dev, const char *id)
204 return __reset_control_get(dev, id, 0, true, false, false);
208 * reset_control_get_optional_exclusive - optional reset_control_get_exclusive()
209 * @dev: device to be reset by the controller
210 * @id: reset line name
212 * Optional variant of reset_control_get_exclusive(). If the requested reset
213 * is not specified in the device tree, this function returns NULL instead of
216 * See reset_control_get_exclusive() for more information.
218 static inline struct reset_control *reset_control_get_optional_exclusive(
219 struct device *dev, const char *id)
221 return __reset_control_get(dev, id, 0, false, true, true);
225 * reset_control_get_optional_shared - optional reset_control_get_shared()
226 * @dev: device to be reset by the controller
227 * @id: reset line name
229 * Optional variant of reset_control_get_shared(). If the requested reset
230 * is not specified in the device tree, this function returns NULL instead of
233 * See reset_control_get_shared() for more information.
235 static inline struct reset_control *reset_control_get_optional_shared(
236 struct device *dev, const char *id)
238 return __reset_control_get(dev, id, 0, true, true, false);
242 * of_reset_control_get_exclusive - Lookup and obtain an exclusive reference
243 * to a reset controller.
244 * @node: device to be reset by the controller
245 * @id: reset line name
247 * Returns a struct reset_control or IS_ERR() condition containing errno.
249 * Use of id names is optional.
251 static inline struct reset_control *of_reset_control_get_exclusive(
252 struct device_node *node, const char *id)
254 return __of_reset_control_get(node, id, 0, false, false, true);
258 * of_reset_control_get_shared - Lookup and obtain a shared reference
259 * to a reset controller.
260 * @node: device to be reset by the controller
261 * @id: reset line name
263 * When a reset-control is shared, the behavior of reset_control_assert /
264 * deassert is changed, the reset-core will keep track of a deassert_count
265 * and only (re-)assert the reset after reset_control_assert has been called
266 * as many times as reset_control_deassert was called. Also see the remark
267 * about shared reset-controls in the reset_control_assert docs.
269 * Calling reset_control_assert without first calling reset_control_deassert
270 * is not allowed on a shared reset control. Calling reset_control_reset is
271 * also not allowed on a shared reset control.
272 * Returns a struct reset_control or IS_ERR() condition containing errno.
274 * Use of id names is optional.
276 static inline struct reset_control *of_reset_control_get_shared(
277 struct device_node *node, const char *id)
279 return __of_reset_control_get(node, id, 0, true, false, false);
283 * of_reset_control_get_exclusive_by_index - Lookup and obtain an exclusive
284 * reference to a reset controller
286 * @node: device to be reset by the controller
287 * @index: index of the reset controller
289 * This is to be used to perform a list of resets for a device or power domain
290 * in whatever order. Returns a struct reset_control or IS_ERR() condition
293 static inline struct reset_control *of_reset_control_get_exclusive_by_index(
294 struct device_node *node, int index)
296 return __of_reset_control_get(node, NULL, index, false, false, true);
300 * of_reset_control_get_shared_by_index - Lookup and obtain a shared
301 * reference to a reset controller
303 * @node: device to be reset by the controller
304 * @index: index of the reset controller
306 * When a reset-control is shared, the behavior of reset_control_assert /
307 * deassert is changed, the reset-core will keep track of a deassert_count
308 * and only (re-)assert the reset after reset_control_assert has been called
309 * as many times as reset_control_deassert was called. Also see the remark
310 * about shared reset-controls in the reset_control_assert docs.
312 * Calling reset_control_assert without first calling reset_control_deassert
313 * is not allowed on a shared reset control. Calling reset_control_reset is
314 * also not allowed on a shared reset control.
315 * Returns a struct reset_control or IS_ERR() condition containing errno.
317 * This is to be used to perform a list of resets for a device or power domain
318 * in whatever order. Returns a struct reset_control or IS_ERR() condition
321 static inline struct reset_control *of_reset_control_get_shared_by_index(
322 struct device_node *node, int index)
324 return __of_reset_control_get(node, NULL, index, true, false, false);
328 * devm_reset_control_get_exclusive - resource managed
329 * reset_control_get_exclusive()
330 * @dev: device to be reset by the controller
331 * @id: reset line name
333 * Managed reset_control_get_exclusive(). For reset controllers returned
334 * from this function, reset_control_put() is called automatically on driver
337 * See reset_control_get_exclusive() for more information.
339 static inline struct reset_control *
340 __must_check devm_reset_control_get_exclusive(struct device *dev,
343 return __devm_reset_control_get(dev, id, 0, false, false, true);
347 * devm_reset_control_get_exclusive_released - resource managed
348 * reset_control_get_exclusive_released()
349 * @dev: device to be reset by the controller
350 * @id: reset line name
352 * Managed reset_control_get_exclusive_released(). For reset controllers
353 * returned from this function, reset_control_put() is called automatically on
356 * See reset_control_get_exclusive_released() for more information.
358 static inline struct reset_control *
359 __must_check devm_reset_control_get_exclusive_released(struct device *dev,
362 return __devm_reset_control_get(dev, id, 0, false, false, false);
366 * devm_reset_control_get_optional_exclusive_released - resource managed
367 * reset_control_get_optional_exclusive_released()
368 * @dev: device to be reset by the controller
369 * @id: reset line name
371 * Managed-and-optional variant of reset_control_get_exclusive_released(). For
372 * reset controllers returned from this function, reset_control_put() is called
373 * automatically on driver detach.
375 * See reset_control_get_exclusive_released() for more information.
377 static inline struct reset_control *
378 __must_check devm_reset_control_get_optional_exclusive_released(struct device *dev,
381 return __devm_reset_control_get(dev, id, 0, false, true, false);
385 * devm_reset_control_get_shared - resource managed reset_control_get_shared()
386 * @dev: device to be reset by the controller
387 * @id: reset line name
389 * Managed reset_control_get_shared(). For reset controllers returned from
390 * this function, reset_control_put() is called automatically on driver detach.
391 * See reset_control_get_shared() for more information.
393 static inline struct reset_control *devm_reset_control_get_shared(
394 struct device *dev, const char *id)
396 return __devm_reset_control_get(dev, id, 0, true, false, false);
400 * devm_reset_control_get_optional_exclusive - resource managed
401 * reset_control_get_optional_exclusive()
402 * @dev: device to be reset by the controller
403 * @id: reset line name
405 * Managed reset_control_get_optional_exclusive(). For reset controllers
406 * returned from this function, reset_control_put() is called automatically on
409 * See reset_control_get_optional_exclusive() for more information.
411 static inline struct reset_control *devm_reset_control_get_optional_exclusive(
412 struct device *dev, const char *id)
414 return __devm_reset_control_get(dev, id, 0, false, true, true);
418 * devm_reset_control_get_optional_shared - resource managed
419 * reset_control_get_optional_shared()
420 * @dev: device to be reset by the controller
421 * @id: reset line name
423 * Managed reset_control_get_optional_shared(). For reset controllers returned
424 * from this function, reset_control_put() is called automatically on driver
427 * See reset_control_get_optional_shared() for more information.
429 static inline struct reset_control *devm_reset_control_get_optional_shared(
430 struct device *dev, const char *id)
432 return __devm_reset_control_get(dev, id, 0, true, true, false);
436 * devm_reset_control_get_exclusive_by_index - resource managed
437 * reset_control_get_exclusive()
438 * @dev: device to be reset by the controller
439 * @index: index of the reset controller
441 * Managed reset_control_get_exclusive(). For reset controllers returned from
442 * this function, reset_control_put() is called automatically on driver
445 * See reset_control_get_exclusive() for more information.
447 static inline struct reset_control *
448 devm_reset_control_get_exclusive_by_index(struct device *dev, int index)
450 return __devm_reset_control_get(dev, NULL, index, false, false, true);
454 * devm_reset_control_get_shared_by_index - resource managed
455 * reset_control_get_shared
456 * @dev: device to be reset by the controller
457 * @index: index of the reset controller
459 * Managed reset_control_get_shared(). For reset controllers returned from
460 * this function, reset_control_put() is called automatically on driver detach.
461 * See reset_control_get_shared() for more information.
463 static inline struct reset_control *
464 devm_reset_control_get_shared_by_index(struct device *dev, int index)
466 return __devm_reset_control_get(dev, NULL, index, true, false, false);
470 * TEMPORARY calls to use during transition:
472 * of_reset_control_get() => of_reset_control_get_exclusive()
474 * These inline function calls will be removed once all consumers
475 * have been moved over to the new explicit API.
477 static inline struct reset_control *of_reset_control_get(
478 struct device_node *node, const char *id)
480 return of_reset_control_get_exclusive(node, id);
483 static inline struct reset_control *of_reset_control_get_by_index(
484 struct device_node *node, int index)
486 return of_reset_control_get_exclusive_by_index(node, index);
489 static inline struct reset_control *devm_reset_control_get(
490 struct device *dev, const char *id)
492 return devm_reset_control_get_exclusive(dev, id);
495 static inline struct reset_control *devm_reset_control_get_optional(
496 struct device *dev, const char *id)
498 return devm_reset_control_get_optional_exclusive(dev, id);
502 static inline struct reset_control *devm_reset_control_get_by_index(
503 struct device *dev, int index)
505 return devm_reset_control_get_exclusive_by_index(dev, index);
509 * APIs to manage a list of reset controllers
511 static inline struct reset_control *
512 devm_reset_control_array_get_exclusive(struct device *dev)
514 return devm_reset_control_array_get(dev, false, false);
517 static inline struct reset_control *
518 devm_reset_control_array_get_shared(struct device *dev)
520 return devm_reset_control_array_get(dev, true, false);
523 static inline struct reset_control *
524 devm_reset_control_array_get_optional_exclusive(struct device *dev)
526 return devm_reset_control_array_get(dev, false, true);
529 static inline struct reset_control *
530 devm_reset_control_array_get_optional_shared(struct device *dev)
532 return devm_reset_control_array_get(dev, true, true);
535 static inline struct reset_control *
536 of_reset_control_array_get_exclusive(struct device_node *node)
538 return of_reset_control_array_get(node, false, false, true);
541 static inline struct reset_control *
542 of_reset_control_array_get_exclusive_released(struct device_node *node)
544 return of_reset_control_array_get(node, false, false, false);
547 static inline struct reset_control *
548 of_reset_control_array_get_shared(struct device_node *node)
550 return of_reset_control_array_get(node, true, false, true);
553 static inline struct reset_control *
554 of_reset_control_array_get_optional_exclusive(struct device_node *node)
556 return of_reset_control_array_get(node, false, true, true);
559 static inline struct reset_control *
560 of_reset_control_array_get_optional_shared(struct device_node *node)
562 return of_reset_control_array_get(node, true, true, true);