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_shared - resource managed reset_control_get_shared()
367 * @dev: device to be reset by the controller
368 * @id: reset line name
370 * Managed reset_control_get_shared(). For reset controllers returned from
371 * this function, reset_control_put() is called automatically on driver detach.
372 * See reset_control_get_shared() for more information.
374 static inline struct reset_control *devm_reset_control_get_shared(
375 struct device *dev, const char *id)
377 return __devm_reset_control_get(dev, id, 0, true, false, false);
381 * devm_reset_control_get_optional_exclusive - resource managed
382 * reset_control_get_optional_exclusive()
383 * @dev: device to be reset by the controller
384 * @id: reset line name
386 * Managed reset_control_get_optional_exclusive(). For reset controllers
387 * returned from this function, reset_control_put() is called automatically on
390 * See reset_control_get_optional_exclusive() for more information.
392 static inline struct reset_control *devm_reset_control_get_optional_exclusive(
393 struct device *dev, const char *id)
395 return __devm_reset_control_get(dev, id, 0, false, true, true);
399 * devm_reset_control_get_optional_shared - resource managed
400 * reset_control_get_optional_shared()
401 * @dev: device to be reset by the controller
402 * @id: reset line name
404 * Managed reset_control_get_optional_shared(). For reset controllers returned
405 * from this function, reset_control_put() is called automatically on driver
408 * See reset_control_get_optional_shared() for more information.
410 static inline struct reset_control *devm_reset_control_get_optional_shared(
411 struct device *dev, const char *id)
413 return __devm_reset_control_get(dev, id, 0, true, true, false);
417 * devm_reset_control_get_exclusive_by_index - resource managed
418 * reset_control_get_exclusive()
419 * @dev: device to be reset by the controller
420 * @index: index of the reset controller
422 * Managed reset_control_get_exclusive(). For reset controllers returned from
423 * this function, reset_control_put() is called automatically on driver
426 * See reset_control_get_exclusive() for more information.
428 static inline struct reset_control *
429 devm_reset_control_get_exclusive_by_index(struct device *dev, int index)
431 return __devm_reset_control_get(dev, NULL, index, false, false, true);
435 * devm_reset_control_get_shared_by_index - resource managed
436 * reset_control_get_shared
437 * @dev: device to be reset by the controller
438 * @index: index of the reset controller
440 * Managed reset_control_get_shared(). For reset controllers returned from
441 * this function, reset_control_put() is called automatically on driver detach.
442 * See reset_control_get_shared() for more information.
444 static inline struct reset_control *
445 devm_reset_control_get_shared_by_index(struct device *dev, int index)
447 return __devm_reset_control_get(dev, NULL, index, true, false, false);
451 * TEMPORARY calls to use during transition:
453 * of_reset_control_get() => of_reset_control_get_exclusive()
455 * These inline function calls will be removed once all consumers
456 * have been moved over to the new explicit API.
458 static inline struct reset_control *of_reset_control_get(
459 struct device_node *node, const char *id)
461 return of_reset_control_get_exclusive(node, id);
464 static inline struct reset_control *of_reset_control_get_by_index(
465 struct device_node *node, int index)
467 return of_reset_control_get_exclusive_by_index(node, index);
470 static inline struct reset_control *devm_reset_control_get(
471 struct device *dev, const char *id)
473 return devm_reset_control_get_exclusive(dev, id);
476 static inline struct reset_control *devm_reset_control_get_optional(
477 struct device *dev, const char *id)
479 return devm_reset_control_get_optional_exclusive(dev, id);
483 static inline struct reset_control *devm_reset_control_get_by_index(
484 struct device *dev, int index)
486 return devm_reset_control_get_exclusive_by_index(dev, index);
490 * APIs to manage a list of reset controllers
492 static inline struct reset_control *
493 devm_reset_control_array_get_exclusive(struct device *dev)
495 return devm_reset_control_array_get(dev, false, false);
498 static inline struct reset_control *
499 devm_reset_control_array_get_shared(struct device *dev)
501 return devm_reset_control_array_get(dev, true, false);
504 static inline struct reset_control *
505 devm_reset_control_array_get_optional_exclusive(struct device *dev)
507 return devm_reset_control_array_get(dev, false, true);
510 static inline struct reset_control *
511 devm_reset_control_array_get_optional_shared(struct device *dev)
513 return devm_reset_control_array_get(dev, true, true);
516 static inline struct reset_control *
517 of_reset_control_array_get_exclusive(struct device_node *node)
519 return of_reset_control_array_get(node, false, false, true);
522 static inline struct reset_control *
523 of_reset_control_array_get_exclusive_released(struct device_node *node)
525 return of_reset_control_array_get(node, false, false, false);
528 static inline struct reset_control *
529 of_reset_control_array_get_shared(struct device_node *node)
531 return of_reset_control_array_get(node, true, false, true);
534 static inline struct reset_control *
535 of_reset_control_array_get_optional_exclusive(struct device_node *node)
537 return of_reset_control_array_get(node, false, true, true);
540 static inline struct reset_control *
541 of_reset_control_array_get_optional_shared(struct device_node *node)
543 return of_reset_control_array_get(node, true, true, true);