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_assert(struct reset_control *rstc);
17 int reset_control_deassert(struct reset_control *rstc);
18 int reset_control_status(struct reset_control *rstc);
19 int reset_control_acquire(struct reset_control *rstc);
20 void reset_control_release(struct reset_control *rstc);
22 struct reset_control *__of_reset_control_get(struct device_node *node,
23 const char *id, int index, bool shared,
24 bool optional, bool acquired);
25 struct reset_control *__reset_control_get(struct device *dev, const char *id,
26 int index, bool shared,
27 bool optional, bool acquired);
28 void reset_control_put(struct reset_control *rstc);
29 int __device_reset(struct device *dev, bool optional);
30 struct reset_control *__devm_reset_control_get(struct device *dev,
31 const char *id, int index, bool shared,
32 bool optional, bool acquired);
34 struct reset_control *devm_reset_control_array_get(struct device *dev,
35 bool shared, bool optional);
36 struct reset_control *of_reset_control_array_get(struct device_node *np,
37 bool shared, bool optional,
40 int reset_control_get_count(struct device *dev);
44 static inline int reset_control_reset(struct reset_control *rstc)
49 static inline int reset_control_assert(struct reset_control *rstc)
54 static inline int reset_control_deassert(struct reset_control *rstc)
59 static inline int reset_control_status(struct reset_control *rstc)
64 static inline int reset_control_acquire(struct reset_control *rstc)
69 static inline void reset_control_release(struct reset_control *rstc)
73 static inline void reset_control_put(struct reset_control *rstc)
77 static inline int __device_reset(struct device *dev, bool optional)
79 return optional ? 0 : -ENOTSUPP;
82 static inline struct reset_control *__of_reset_control_get(
83 struct device_node *node,
84 const char *id, int index, bool shared,
85 bool optional, bool acquired)
87 return optional ? NULL : ERR_PTR(-ENOTSUPP);
90 static inline struct reset_control *__reset_control_get(
91 struct device *dev, const char *id,
92 int index, bool shared, bool optional,
95 return optional ? NULL : ERR_PTR(-ENOTSUPP);
98 static inline struct reset_control *__devm_reset_control_get(
99 struct device *dev, const char *id,
100 int index, bool shared, bool optional,
103 return optional ? NULL : ERR_PTR(-ENOTSUPP);
106 static inline struct reset_control *
107 devm_reset_control_array_get(struct device *dev, bool shared, bool optional)
109 return optional ? NULL : ERR_PTR(-ENOTSUPP);
112 static inline struct reset_control *
113 of_reset_control_array_get(struct device_node *np, bool shared, bool optional,
116 return optional ? NULL : ERR_PTR(-ENOTSUPP);
119 static inline int reset_control_get_count(struct device *dev)
124 #endif /* CONFIG_RESET_CONTROLLER */
126 static inline int __must_check device_reset(struct device *dev)
128 return __device_reset(dev, false);
131 static inline int device_reset_optional(struct device *dev)
133 return __device_reset(dev, true);
137 * reset_control_get_exclusive - Lookup and obtain an exclusive reference
138 * to a reset controller.
139 * @dev: device to be reset by the controller
140 * @id: reset line name
142 * Returns a struct reset_control or IS_ERR() condition containing errno.
143 * If this function is called more than once for the same reset_control it will
146 * See reset_control_get_shared for details on shared references to
149 * Use of id names is optional.
151 static inline struct reset_control *
152 __must_check reset_control_get_exclusive(struct device *dev, const char *id)
154 return __reset_control_get(dev, id, 0, false, false, true);
158 * reset_control_get_exclusive_released - Lookup and obtain a temoprarily
159 * exclusive reference to a reset
161 * @dev: device to be reset by the controller
162 * @id: reset line name
164 * Returns a struct reset_control or IS_ERR() condition containing errno.
165 * reset-controls returned by this function must be acquired via
166 * reset_control_acquire() before they can be used and should be released
167 * via reset_control_release() afterwards.
169 * Use of id names is optional.
171 static inline struct reset_control *
172 __must_check reset_control_get_exclusive_released(struct device *dev,
175 return __reset_control_get(dev, id, 0, false, false, false);
179 * reset_control_get_shared - Lookup and obtain a shared reference to a
181 * @dev: device to be reset by the controller
182 * @id: reset line name
184 * Returns a struct reset_control or IS_ERR() condition containing errno.
185 * This function is intended for use with reset-controls which are shared
186 * between hardware blocks.
188 * When a reset-control is shared, the behavior of reset_control_assert /
189 * deassert is changed, the reset-core will keep track of a deassert_count
190 * and only (re-)assert the reset after reset_control_assert has been called
191 * as many times as reset_control_deassert was called. Also see the remark
192 * about shared reset-controls in the reset_control_assert docs.
194 * Calling reset_control_assert without first calling reset_control_deassert
195 * is not allowed on a shared reset control. Calling reset_control_reset is
196 * also not allowed on a shared reset control.
198 * Use of id names is optional.
200 static inline struct reset_control *reset_control_get_shared(
201 struct device *dev, const char *id)
203 return __reset_control_get(dev, id, 0, true, false, false);
206 static inline struct reset_control *reset_control_get_optional_exclusive(
207 struct device *dev, const char *id)
209 return __reset_control_get(dev, id, 0, false, true, true);
212 static inline struct reset_control *reset_control_get_optional_shared(
213 struct device *dev, const char *id)
215 return __reset_control_get(dev, id, 0, true, true, false);
219 * of_reset_control_get_exclusive - Lookup and obtain an exclusive reference
220 * to a reset controller.
221 * @node: device to be reset by the controller
222 * @id: reset line name
224 * Returns a struct reset_control or IS_ERR() condition containing errno.
226 * Use of id names is optional.
228 static inline struct reset_control *of_reset_control_get_exclusive(
229 struct device_node *node, const char *id)
231 return __of_reset_control_get(node, id, 0, false, false, true);
235 * of_reset_control_get_shared - Lookup and obtain a shared reference
236 * to a reset controller.
237 * @node: device to be reset by the controller
238 * @id: reset line name
240 * When a reset-control is shared, the behavior of reset_control_assert /
241 * deassert is changed, the reset-core will keep track of a deassert_count
242 * and only (re-)assert the reset after reset_control_assert has been called
243 * as many times as reset_control_deassert was called. Also see the remark
244 * about shared reset-controls in the reset_control_assert docs.
246 * Calling reset_control_assert without first calling reset_control_deassert
247 * is not allowed on a shared reset control. Calling reset_control_reset is
248 * also not allowed on a shared reset control.
249 * Returns a struct reset_control or IS_ERR() condition containing errno.
251 * Use of id names is optional.
253 static inline struct reset_control *of_reset_control_get_shared(
254 struct device_node *node, const char *id)
256 return __of_reset_control_get(node, id, 0, true, false, false);
260 * of_reset_control_get_exclusive_by_index - Lookup and obtain an exclusive
261 * reference to a reset controller
263 * @node: device to be reset by the controller
264 * @index: index of the reset controller
266 * This is to be used to perform a list of resets for a device or power domain
267 * in whatever order. Returns a struct reset_control or IS_ERR() condition
270 static inline struct reset_control *of_reset_control_get_exclusive_by_index(
271 struct device_node *node, int index)
273 return __of_reset_control_get(node, NULL, index, false, false, true);
277 * of_reset_control_get_shared_by_index - Lookup and obtain a shared
278 * reference to a reset controller
280 * @node: device to be reset by the controller
281 * @index: index of the reset controller
283 * When a reset-control is shared, the behavior of reset_control_assert /
284 * deassert is changed, the reset-core will keep track of a deassert_count
285 * and only (re-)assert the reset after reset_control_assert has been called
286 * as many times as reset_control_deassert was called. Also see the remark
287 * about shared reset-controls in the reset_control_assert docs.
289 * Calling reset_control_assert without first calling reset_control_deassert
290 * is not allowed on a shared reset control. Calling reset_control_reset is
291 * also not allowed on a shared reset control.
292 * Returns a struct reset_control or IS_ERR() condition containing errno.
294 * This is to be used to perform a list of resets for a device or power domain
295 * in whatever order. Returns a struct reset_control or IS_ERR() condition
298 static inline struct reset_control *of_reset_control_get_shared_by_index(
299 struct device_node *node, int index)
301 return __of_reset_control_get(node, NULL, index, true, false, false);
305 * devm_reset_control_get_exclusive - resource managed
306 * reset_control_get_exclusive()
307 * @dev: device to be reset by the controller
308 * @id: reset line name
310 * Managed reset_control_get_exclusive(). For reset controllers returned
311 * from this function, reset_control_put() is called automatically on driver
314 * See reset_control_get_exclusive() for more information.
316 static inline struct reset_control *
317 __must_check devm_reset_control_get_exclusive(struct device *dev,
320 return __devm_reset_control_get(dev, id, 0, false, false, true);
324 * devm_reset_control_get_exclusive_released - resource managed
325 * reset_control_get_exclusive_released()
326 * @dev: device to be reset by the controller
327 * @id: reset line name
329 * Managed reset_control_get_exclusive_released(). For reset controllers
330 * returned from this function, reset_control_put() is called automatically on
333 * See reset_control_get_exclusive_released() for more information.
335 static inline struct reset_control *
336 __must_check devm_reset_control_get_exclusive_released(struct device *dev,
339 return __devm_reset_control_get(dev, id, 0, false, false, false);
343 * devm_reset_control_get_shared - resource managed reset_control_get_shared()
344 * @dev: device to be reset by the controller
345 * @id: reset line name
347 * Managed reset_control_get_shared(). For reset controllers returned from
348 * this function, reset_control_put() is called automatically on driver detach.
349 * See reset_control_get_shared() for more information.
351 static inline struct reset_control *devm_reset_control_get_shared(
352 struct device *dev, const char *id)
354 return __devm_reset_control_get(dev, id, 0, true, false, false);
357 static inline struct reset_control *devm_reset_control_get_optional_exclusive(
358 struct device *dev, const char *id)
360 return __devm_reset_control_get(dev, id, 0, false, true, true);
363 static inline struct reset_control *devm_reset_control_get_optional_shared(
364 struct device *dev, const char *id)
366 return __devm_reset_control_get(dev, id, 0, true, true, false);
370 * devm_reset_control_get_exclusive_by_index - resource managed
371 * reset_control_get_exclusive()
372 * @dev: device to be reset by the controller
373 * @index: index of the reset controller
375 * Managed reset_control_get_exclusive(). For reset controllers returned from
376 * this function, reset_control_put() is called automatically on driver
379 * See reset_control_get_exclusive() for more information.
381 static inline struct reset_control *
382 devm_reset_control_get_exclusive_by_index(struct device *dev, int index)
384 return __devm_reset_control_get(dev, NULL, index, false, false, true);
388 * devm_reset_control_get_shared_by_index - resource managed
389 * reset_control_get_shared
390 * @dev: device to be reset by the controller
391 * @index: index of the reset controller
393 * Managed reset_control_get_shared(). For reset controllers returned from
394 * this function, reset_control_put() is called automatically on driver detach.
395 * See reset_control_get_shared() for more information.
397 static inline struct reset_control *
398 devm_reset_control_get_shared_by_index(struct device *dev, int index)
400 return __devm_reset_control_get(dev, NULL, index, true, false, false);
404 * TEMPORARY calls to use during transition:
406 * of_reset_control_get() => of_reset_control_get_exclusive()
408 * These inline function calls will be removed once all consumers
409 * have been moved over to the new explicit API.
411 static inline struct reset_control *of_reset_control_get(
412 struct device_node *node, const char *id)
414 return of_reset_control_get_exclusive(node, id);
417 static inline struct reset_control *of_reset_control_get_by_index(
418 struct device_node *node, int index)
420 return of_reset_control_get_exclusive_by_index(node, index);
423 static inline struct reset_control *devm_reset_control_get(
424 struct device *dev, const char *id)
426 return devm_reset_control_get_exclusive(dev, id);
429 static inline struct reset_control *devm_reset_control_get_optional(
430 struct device *dev, const char *id)
432 return devm_reset_control_get_optional_exclusive(dev, id);
436 static inline struct reset_control *devm_reset_control_get_by_index(
437 struct device *dev, int index)
439 return devm_reset_control_get_exclusive_by_index(dev, index);
443 * APIs to manage a list of reset controllers
445 static inline struct reset_control *
446 devm_reset_control_array_get_exclusive(struct device *dev)
448 return devm_reset_control_array_get(dev, false, false);
451 static inline struct reset_control *
452 devm_reset_control_array_get_shared(struct device *dev)
454 return devm_reset_control_array_get(dev, true, false);
457 static inline struct reset_control *
458 devm_reset_control_array_get_optional_exclusive(struct device *dev)
460 return devm_reset_control_array_get(dev, false, true);
463 static inline struct reset_control *
464 devm_reset_control_array_get_optional_shared(struct device *dev)
466 return devm_reset_control_array_get(dev, true, true);
469 static inline struct reset_control *
470 of_reset_control_array_get_exclusive(struct device_node *node)
472 return of_reset_control_array_get(node, false, false, true);
475 static inline struct reset_control *
476 of_reset_control_array_get_exclusive_released(struct device_node *node)
478 return of_reset_control_array_get(node, false, false, false);
481 static inline struct reset_control *
482 of_reset_control_array_get_shared(struct device_node *node)
484 return of_reset_control_array_get(node, true, false, true);
487 static inline struct reset_control *
488 of_reset_control_array_get_optional_exclusive(struct device_node *node)
490 return of_reset_control_array_get(node, false, true, true);
493 static inline struct reset_control *
494 of_reset_control_array_get_optional_shared(struct device_node *node)
496 return of_reset_control_array_get(node, true, true, true);