1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _LINUX_RESET_H_
3#define _LINUX_RESET_H_
4
5#include <linux/err.h>
6#include <linux/errno.h>
7#include <linux/types.h>
8
9struct device;
10struct device_node;
11struct reset_control;
12
13/**
14 * struct reset_control_bulk_data - Data used for bulk reset control operations.
15 *
16 * @id: reset control consumer ID
17 * @rstc: struct reset_control * to store the associated reset control
18 *
19 * The reset APIs provide a series of reset_control_bulk_*() API calls as
20 * a convenience to consumers which require multiple reset controls.
21 * This structure is used to manage data for these calls.
22 */
23struct reset_control_bulk_data {
24 const char *id;
25 struct reset_control *rstc;
26};
27
28#define RESET_CONTROL_FLAGS_BIT_SHARED BIT(0) /* not exclusive */
29#define RESET_CONTROL_FLAGS_BIT_OPTIONAL BIT(1)
30#define RESET_CONTROL_FLAGS_BIT_ACQUIRED BIT(2) /* iff exclusive, not released */
31#define RESET_CONTROL_FLAGS_BIT_DEASSERTED BIT(3)
32
33/**
34 * enum reset_control_flags - Flags that can be passed to the reset_control_get functions
35 * to determine the type of reset control.
36 * These values cannot be OR'd.
37 *
38 * @RESET_CONTROL_EXCLUSIVE: exclusive, acquired,
39 * @RESET_CONTROL_EXCLUSIVE_DEASSERTED: exclusive, acquired, deasserted
40 * @RESET_CONTROL_EXCLUSIVE_RELEASED: exclusive, released,
41 * @RESET_CONTROL_SHARED: shared
42 * @RESET_CONTROL_SHARED_DEASSERTED: shared, deasserted
43 * @RESET_CONTROL_OPTIONAL_EXCLUSIVE: optional, exclusive, acquired
44 * @RESET_CONTROL_OPTIONAL_EXCLUSIVE_DEASSERTED: optional, exclusive, acquired, deasserted
45 * @RESET_CONTROL_OPTIONAL_EXCLUSIVE_RELEASED: optional, exclusive, released
46 * @RESET_CONTROL_OPTIONAL_SHARED: optional, shared
47 * @RESET_CONTROL_OPTIONAL_SHARED_DEASSERTED: optional, shared, deasserted
48 */
49enum reset_control_flags {
50 RESET_CONTROL_EXCLUSIVE = RESET_CONTROL_FLAGS_BIT_ACQUIRED,
51 RESET_CONTROL_EXCLUSIVE_DEASSERTED = RESET_CONTROL_FLAGS_BIT_ACQUIRED |
52 RESET_CONTROL_FLAGS_BIT_DEASSERTED,
53 RESET_CONTROL_EXCLUSIVE_RELEASED = 0,
54 RESET_CONTROL_SHARED = RESET_CONTROL_FLAGS_BIT_SHARED,
55 RESET_CONTROL_SHARED_DEASSERTED = RESET_CONTROL_FLAGS_BIT_SHARED |
56 RESET_CONTROL_FLAGS_BIT_DEASSERTED,
57 RESET_CONTROL_OPTIONAL_EXCLUSIVE = RESET_CONTROL_FLAGS_BIT_OPTIONAL |
58 RESET_CONTROL_FLAGS_BIT_ACQUIRED,
59 RESET_CONTROL_OPTIONAL_EXCLUSIVE_DEASSERTED = RESET_CONTROL_FLAGS_BIT_OPTIONAL |
60 RESET_CONTROL_FLAGS_BIT_ACQUIRED |
61 RESET_CONTROL_FLAGS_BIT_DEASSERTED,
62 RESET_CONTROL_OPTIONAL_EXCLUSIVE_RELEASED = RESET_CONTROL_FLAGS_BIT_OPTIONAL,
63 RESET_CONTROL_OPTIONAL_SHARED = RESET_CONTROL_FLAGS_BIT_OPTIONAL |
64 RESET_CONTROL_FLAGS_BIT_SHARED,
65 RESET_CONTROL_OPTIONAL_SHARED_DEASSERTED = RESET_CONTROL_FLAGS_BIT_OPTIONAL |
66 RESET_CONTROL_FLAGS_BIT_SHARED |
67 RESET_CONTROL_FLAGS_BIT_DEASSERTED,
68};
69
70#ifdef CONFIG_RESET_CONTROLLER
71
72int reset_control_reset(struct reset_control *rstc);
73int reset_control_rearm(struct reset_control *rstc);
74int reset_control_assert(struct reset_control *rstc);
75int reset_control_deassert(struct reset_control *rstc);
76int reset_control_status(struct reset_control *rstc);
77int reset_control_acquire(struct reset_control *rstc);
78void reset_control_release(struct reset_control *rstc);
79
80int reset_control_bulk_reset(int num_rstcs, struct reset_control_bulk_data *rstcs);
81int reset_control_bulk_assert(int num_rstcs, struct reset_control_bulk_data *rstcs);
82int reset_control_bulk_deassert(int num_rstcs, struct reset_control_bulk_data *rstcs);
83int reset_control_bulk_acquire(int num_rstcs, struct reset_control_bulk_data *rstcs);
84void reset_control_bulk_release(int num_rstcs, struct reset_control_bulk_data *rstcs);
85
86struct reset_control *__of_reset_control_get(struct device_node *node,
87 const char *id, int index, enum reset_control_flags flags);
88struct reset_control *__reset_control_get(struct device *dev, const char *id,
89 int index, enum reset_control_flags flags);
90void reset_control_put(struct reset_control *rstc);
91int __reset_control_bulk_get(struct device *dev, int num_rstcs,
92 struct reset_control_bulk_data *rstcs,
93 enum reset_control_flags flags);
94void reset_control_bulk_put(int num_rstcs, struct reset_control_bulk_data *rstcs);
95
96int __device_reset(struct device *dev, bool optional);
97struct reset_control *__devm_reset_control_get(struct device *dev,
98 const char *id, int index, enum reset_control_flags flags);
99int __devm_reset_control_bulk_get(struct device *dev, int num_rstcs,
100 struct reset_control_bulk_data *rstcs,
101 enum reset_control_flags flags);
102
103struct reset_control *devm_reset_control_array_get(struct device *dev,
104 enum reset_control_flags flags);
105struct reset_control *of_reset_control_array_get(struct device_node *np, enum reset_control_flags);
106
107int reset_control_get_count(struct device *dev);
108
109#else
110
111static inline int reset_control_reset(struct reset_control *rstc)
112{
113 return 0;
114}
115
116static inline int reset_control_rearm(struct reset_control *rstc)
117{
118 return 0;
119}
120
121static inline int reset_control_assert(struct reset_control *rstc)
122{
123 return 0;
124}
125
126static inline int reset_control_deassert(struct reset_control *rstc)
127{
128 return 0;
129}
130
131static inline int reset_control_status(struct reset_control *rstc)
132{
133 return 0;
134}
135
136static inline int reset_control_acquire(struct reset_control *rstc)
137{
138 return 0;
139}
140
141static inline void reset_control_release(struct reset_control *rstc)
142{
143}
144
145static inline void reset_control_put(struct reset_control *rstc)
146{
147}
148
149static inline int __device_reset(struct device *dev, bool optional)
150{
151 return optional ? 0 : -ENOTSUPP;
152}
153
154static inline struct reset_control *__of_reset_control_get(
155 struct device_node *node,
156 const char *id, int index, enum reset_control_flags flags)
157{
158 bool optional = flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL;
159
160 return optional ? NULL : ERR_PTR(error: -ENOTSUPP);
161}
162
163static inline struct reset_control *__reset_control_get(
164 struct device *dev, const char *id,
165 int index, enum reset_control_flags flags)
166{
167 bool optional = flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL;
168
169 return optional ? NULL : ERR_PTR(error: -ENOTSUPP);
170}
171
172static inline int
173reset_control_bulk_reset(int num_rstcs, struct reset_control_bulk_data *rstcs)
174{
175 return 0;
176}
177
178static inline int
179reset_control_bulk_assert(int num_rstcs, struct reset_control_bulk_data *rstcs)
180{
181 return 0;
182}
183
184static inline int
185reset_control_bulk_deassert(int num_rstcs, struct reset_control_bulk_data *rstcs)
186{
187 return 0;
188}
189
190static inline int
191reset_control_bulk_acquire(int num_rstcs, struct reset_control_bulk_data *rstcs)
192{
193 return 0;
194}
195
196static inline void
197reset_control_bulk_release(int num_rstcs, struct reset_control_bulk_data *rstcs)
198{
199}
200
201static inline int
202__reset_control_bulk_get(struct device *dev, int num_rstcs,
203 struct reset_control_bulk_data *rstcs,
204 enum reset_control_flags flags)
205{
206 bool optional = flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL;
207
208 return optional ? 0 : -EOPNOTSUPP;
209}
210
211static inline void
212reset_control_bulk_put(int num_rstcs, struct reset_control_bulk_data *rstcs)
213{
214}
215
216static inline struct reset_control *__devm_reset_control_get(
217 struct device *dev, const char *id,
218 int index, enum reset_control_flags flags)
219{
220 bool optional = flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL;
221
222 return optional ? NULL : ERR_PTR(error: -ENOTSUPP);
223}
224
225static inline int
226__devm_reset_control_bulk_get(struct device *dev, int num_rstcs,
227 struct reset_control_bulk_data *rstcs,
228 enum reset_control_flags flags)
229{
230 bool optional = flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL;
231
232 return optional ? 0 : -EOPNOTSUPP;
233}
234
235static inline struct reset_control *
236devm_reset_control_array_get(struct device *dev, enum reset_control_flags flags)
237{
238 bool optional = flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL;
239
240 return optional ? NULL : ERR_PTR(error: -ENOTSUPP);
241}
242
243static inline struct reset_control *
244of_reset_control_array_get(struct device_node *np, enum reset_control_flags flags)
245{
246 bool optional = flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL;
247
248 return optional ? NULL : ERR_PTR(error: -ENOTSUPP);
249}
250
251static inline int reset_control_get_count(struct device *dev)
252{
253 return -ENOENT;
254}
255
256#endif /* CONFIG_RESET_CONTROLLER */
257
258static inline int __must_check device_reset(struct device *dev)
259{
260 return __device_reset(dev, optional: false);
261}
262
263static inline int device_reset_optional(struct device *dev)
264{
265 return __device_reset(dev, optional: true);
266}
267
268/**
269 * reset_control_get_exclusive - Lookup and obtain an exclusive reference
270 * to a reset controller.
271 * @dev: device to be reset by the controller
272 * @id: reset line name
273 *
274 * Returns a struct reset_control or IS_ERR() condition containing errno.
275 * If this function is called more than once for the same reset_control it will
276 * return -EBUSY.
277 *
278 * See reset_control_get_shared() for details on shared references to
279 * reset-controls.
280 *
281 * Use of id names is optional.
282 */
283static inline struct reset_control *
284__must_check reset_control_get_exclusive(struct device *dev, const char *id)
285{
286 return __reset_control_get(dev, id, index: 0, flags: RESET_CONTROL_EXCLUSIVE);
287}
288
289/**
290 * reset_control_bulk_get_exclusive - Lookup and obtain exclusive references to
291 * multiple reset controllers.
292 * @dev: device to be reset by the controller
293 * @num_rstcs: number of entries in rstcs array
294 * @rstcs: array of struct reset_control_bulk_data with reset line names set
295 *
296 * Fills the rstcs array with pointers to exclusive reset controls and
297 * returns 0, or an IS_ERR() condition containing errno.
298 */
299static inline int __must_check
300reset_control_bulk_get_exclusive(struct device *dev, int num_rstcs,
301 struct reset_control_bulk_data *rstcs)
302{
303 return __reset_control_bulk_get(dev, num_rstcs, rstcs, flags: RESET_CONTROL_EXCLUSIVE);
304}
305
306/**
307 * reset_control_get_exclusive_released - Lookup and obtain a temoprarily
308 * exclusive reference to a reset
309 * controller.
310 * @dev: device to be reset by the controller
311 * @id: reset line name
312 *
313 * Returns a struct reset_control or IS_ERR() condition containing errno.
314 * reset-controls returned by this function must be acquired via
315 * reset_control_acquire() before they can be used and should be released
316 * via reset_control_release() afterwards.
317 *
318 * Use of id names is optional.
319 */
320static inline struct reset_control *
321__must_check reset_control_get_exclusive_released(struct device *dev,
322 const char *id)
323{
324 return __reset_control_get(dev, id, index: 0, flags: RESET_CONTROL_EXCLUSIVE_RELEASED);
325}
326
327/**
328 * reset_control_bulk_get_exclusive_released - Lookup and obtain temporarily
329 * exclusive references to multiple reset
330 * controllers.
331 * @dev: device to be reset by the controller
332 * @num_rstcs: number of entries in rstcs array
333 * @rstcs: array of struct reset_control_bulk_data with reset line names set
334 *
335 * Fills the rstcs array with pointers to exclusive reset controls and
336 * returns 0, or an IS_ERR() condition containing errno.
337 * reset-controls returned by this function must be acquired via
338 * reset_control_bulk_acquire() before they can be used and should be released
339 * via reset_control_bulk_release() afterwards.
340 */
341static inline int __must_check
342reset_control_bulk_get_exclusive_released(struct device *dev, int num_rstcs,
343 struct reset_control_bulk_data *rstcs)
344{
345 return __reset_control_bulk_get(dev, num_rstcs, rstcs, flags: RESET_CONTROL_EXCLUSIVE_RELEASED);
346}
347
348/**
349 * reset_control_bulk_get_optional_exclusive_released - Lookup and obtain optional
350 * temporarily exclusive references to multiple
351 * reset controllers.
352 * @dev: device to be reset by the controller
353 * @num_rstcs: number of entries in rstcs array
354 * @rstcs: array of struct reset_control_bulk_data with reset line names set
355 *
356 * Optional variant of reset_control_bulk_get_exclusive_released(). If the
357 * requested reset is not specified in the device tree, this function returns 0
358 * instead of an error and missing rtsc is set to NULL.
359 *
360 * See reset_control_bulk_get_exclusive_released() for more information.
361 */
362static inline int __must_check
363reset_control_bulk_get_optional_exclusive_released(struct device *dev, int num_rstcs,
364 struct reset_control_bulk_data *rstcs)
365{
366 return __reset_control_bulk_get(dev, num_rstcs, rstcs,
367 flags: RESET_CONTROL_OPTIONAL_EXCLUSIVE_RELEASED);
368}
369
370/**
371 * reset_control_get_shared - Lookup and obtain a shared reference to a
372 * reset controller.
373 * @dev: device to be reset by the controller
374 * @id: reset line name
375 *
376 * Returns a struct reset_control or IS_ERR() condition containing errno.
377 * This function is intended for use with reset-controls which are shared
378 * between hardware blocks.
379 *
380 * When a reset-control is shared, the behavior of reset_control_assert /
381 * deassert is changed, the reset-core will keep track of a deassert_count
382 * and only (re-)assert the reset after reset_control_assert has been called
383 * as many times as reset_control_deassert was called. Also see the remark
384 * about shared reset-controls in the reset_control_assert docs.
385 *
386 * Calling reset_control_assert without first calling reset_control_deassert
387 * is not allowed on a shared reset control. Calling reset_control_reset is
388 * also not allowed on a shared reset control.
389 *
390 * Use of id names is optional.
391 */
392static inline struct reset_control *reset_control_get_shared(
393 struct device *dev, const char *id)
394{
395 return __reset_control_get(dev, id, index: 0, flags: RESET_CONTROL_SHARED);
396}
397
398/**
399 * reset_control_bulk_get_shared - Lookup and obtain shared references to
400 * multiple reset controllers.
401 * @dev: device to be reset by the controller
402 * @num_rstcs: number of entries in rstcs array
403 * @rstcs: array of struct reset_control_bulk_data with reset line names set
404 *
405 * Fills the rstcs array with pointers to shared reset controls and
406 * returns 0, or an IS_ERR() condition containing errno.
407 */
408static inline int __must_check
409reset_control_bulk_get_shared(struct device *dev, int num_rstcs,
410 struct reset_control_bulk_data *rstcs)
411{
412 return __reset_control_bulk_get(dev, num_rstcs, rstcs, flags: RESET_CONTROL_SHARED);
413}
414
415/**
416 * reset_control_get_optional_exclusive - optional reset_control_get_exclusive()
417 * @dev: device to be reset by the controller
418 * @id: reset line name
419 *
420 * Optional variant of reset_control_get_exclusive(). If the requested reset
421 * is not specified in the device tree, this function returns NULL instead of
422 * an error.
423 *
424 * See reset_control_get_exclusive() for more information.
425 */
426static inline struct reset_control *reset_control_get_optional_exclusive(
427 struct device *dev, const char *id)
428{
429 return __reset_control_get(dev, id, index: 0, flags: RESET_CONTROL_OPTIONAL_EXCLUSIVE);
430}
431
432/**
433 * reset_control_bulk_get_optional_exclusive - optional
434 * reset_control_bulk_get_exclusive()
435 * @dev: device to be reset by the controller
436 * @num_rstcs: number of entries in rstcs array
437 * @rstcs: array of struct reset_control_bulk_data with reset line names set
438 *
439 * Optional variant of reset_control_bulk_get_exclusive(). If any of the
440 * requested resets are not specified in the device tree, this function sets
441 * them to NULL instead of returning an error.
442 *
443 * See reset_control_bulk_get_exclusive() for more information.
444 */
445static inline int __must_check
446reset_control_bulk_get_optional_exclusive(struct device *dev, int num_rstcs,
447 struct reset_control_bulk_data *rstcs)
448{
449 return __reset_control_bulk_get(dev, num_rstcs, rstcs, flags: RESET_CONTROL_OPTIONAL_EXCLUSIVE);
450}
451
452/**
453 * reset_control_get_optional_shared - optional reset_control_get_shared()
454 * @dev: device to be reset by the controller
455 * @id: reset line name
456 *
457 * Optional variant of reset_control_get_shared(). If the requested reset
458 * is not specified in the device tree, this function returns NULL instead of
459 * an error.
460 *
461 * See reset_control_get_shared() for more information.
462 */
463static inline struct reset_control *reset_control_get_optional_shared(
464 struct device *dev, const char *id)
465{
466 return __reset_control_get(dev, id, index: 0, flags: RESET_CONTROL_OPTIONAL_SHARED);
467}
468
469/**
470 * reset_control_bulk_get_optional_shared - optional
471 * reset_control_bulk_get_shared()
472 * @dev: device to be reset by the controller
473 * @num_rstcs: number of entries in rstcs array
474 * @rstcs: array of struct reset_control_bulk_data with reset line names set
475 *
476 * Optional variant of reset_control_bulk_get_shared(). If the requested resets
477 * are not specified in the device tree, this function sets them to NULL
478 * instead of returning an error.
479 *
480 * See reset_control_bulk_get_shared() for more information.
481 */
482static inline int __must_check
483reset_control_bulk_get_optional_shared(struct device *dev, int num_rstcs,
484 struct reset_control_bulk_data *rstcs)
485{
486 return __reset_control_bulk_get(dev, num_rstcs, rstcs, flags: RESET_CONTROL_OPTIONAL_SHARED);
487}
488
489/**
490 * of_reset_control_get_exclusive - Lookup and obtain an exclusive reference
491 * to a reset controller.
492 * @node: device to be reset by the controller
493 * @id: reset line name
494 *
495 * Returns a struct reset_control or IS_ERR() condition containing errno.
496 *
497 * Use of id names is optional.
498 */
499static inline struct reset_control *of_reset_control_get_exclusive(
500 struct device_node *node, const char *id)
501{
502 return __of_reset_control_get(node, id, index: 0, flags: RESET_CONTROL_EXCLUSIVE);
503}
504
505/**
506 * of_reset_control_get_optional_exclusive - Lookup and obtain an optional exclusive
507 * reference to a reset controller.
508 * @node: device to be reset by the controller
509 * @id: reset line name
510 *
511 * Optional variant of of_reset_control_get_exclusive(). If the requested reset
512 * is not specified in the device tree, this function returns NULL instead of
513 * an error.
514 *
515 * Returns a struct reset_control or IS_ERR() condition containing errno.
516 *
517 * Use of id names is optional.
518 */
519static inline struct reset_control *of_reset_control_get_optional_exclusive(
520 struct device_node *node, const char *id)
521{
522 return __of_reset_control_get(node, id, index: 0, flags: RESET_CONTROL_OPTIONAL_EXCLUSIVE);
523}
524
525/**
526 * of_reset_control_get_shared - Lookup and obtain a shared reference
527 * to a reset controller.
528 * @node: device to be reset by the controller
529 * @id: reset line name
530 *
531 * When a reset-control is shared, the behavior of reset_control_assert /
532 * deassert is changed, the reset-core will keep track of a deassert_count
533 * and only (re-)assert the reset after reset_control_assert has been called
534 * as many times as reset_control_deassert was called. Also see the remark
535 * about shared reset-controls in the reset_control_assert docs.
536 *
537 * Calling reset_control_assert without first calling reset_control_deassert
538 * is not allowed on a shared reset control. Calling reset_control_reset is
539 * also not allowed on a shared reset control.
540 * Returns a struct reset_control or IS_ERR() condition containing errno.
541 *
542 * Use of id names is optional.
543 */
544static inline struct reset_control *of_reset_control_get_shared(
545 struct device_node *node, const char *id)
546{
547 return __of_reset_control_get(node, id, index: 0, flags: RESET_CONTROL_SHARED);
548}
549
550/**
551 * of_reset_control_get_exclusive_by_index - Lookup and obtain an exclusive
552 * reference to a reset controller
553 * by index.
554 * @node: device to be reset by the controller
555 * @index: index of the reset controller
556 *
557 * This is to be used to perform a list of resets for a device or power domain
558 * in whatever order. Returns a struct reset_control or IS_ERR() condition
559 * containing errno.
560 */
561static inline struct reset_control *of_reset_control_get_exclusive_by_index(
562 struct device_node *node, int index)
563{
564 return __of_reset_control_get(node, NULL, index, flags: RESET_CONTROL_EXCLUSIVE);
565}
566
567/**
568 * of_reset_control_get_shared_by_index - Lookup and obtain a shared
569 * reference to a reset controller
570 * by index.
571 * @node: device to be reset by the controller
572 * @index: index of the reset controller
573 *
574 * When a reset-control is shared, the behavior of reset_control_assert /
575 * deassert is changed, the reset-core will keep track of a deassert_count
576 * and only (re-)assert the reset after reset_control_assert has been called
577 * as many times as reset_control_deassert was called. Also see the remark
578 * about shared reset-controls in the reset_control_assert docs.
579 *
580 * Calling reset_control_assert without first calling reset_control_deassert
581 * is not allowed on a shared reset control. Calling reset_control_reset is
582 * also not allowed on a shared reset control.
583 * Returns a struct reset_control or IS_ERR() condition containing errno.
584 *
585 * This is to be used to perform a list of resets for a device or power domain
586 * in whatever order. Returns a struct reset_control or IS_ERR() condition
587 * containing errno.
588 */
589static inline struct reset_control *of_reset_control_get_shared_by_index(
590 struct device_node *node, int index)
591{
592 return __of_reset_control_get(node, NULL, index, flags: RESET_CONTROL_SHARED);
593}
594
595/**
596 * devm_reset_control_get_exclusive - resource managed
597 * reset_control_get_exclusive()
598 * @dev: device to be reset by the controller
599 * @id: reset line name
600 *
601 * Managed reset_control_get_exclusive(). For reset controllers returned
602 * from this function, reset_control_put() is called automatically on driver
603 * detach.
604 *
605 * See reset_control_get_exclusive() for more information.
606 */
607static inline struct reset_control *
608__must_check devm_reset_control_get_exclusive(struct device *dev,
609 const char *id)
610{
611 return __devm_reset_control_get(dev, id, index: 0, flags: RESET_CONTROL_EXCLUSIVE);
612}
613
614/**
615 * devm_reset_control_get_exclusive_deasserted - resource managed
616 * reset_control_get_exclusive() +
617 * reset_control_deassert()
618 * @dev: device to be reset by the controller
619 * @id: reset line name
620 *
621 * Managed reset_control_get_exclusive() + reset_control_deassert(). For reset
622 * controllers returned from this function, reset_control_assert() +
623 * reset_control_put() is called automatically on driver detach.
624 *
625 * See reset_control_get_exclusive() for more information.
626 */
627static inline struct reset_control * __must_check
628devm_reset_control_get_exclusive_deasserted(struct device *dev, const char *id)
629{
630 return __devm_reset_control_get(dev, id, index: 0, flags: RESET_CONTROL_EXCLUSIVE_DEASSERTED);
631}
632
633/**
634 * devm_reset_control_bulk_get_exclusive - resource managed
635 * reset_control_bulk_get_exclusive()
636 * @dev: device to be reset by the controller
637 * @num_rstcs: number of entries in rstcs array
638 * @rstcs: array of struct reset_control_bulk_data with reset line names set
639 *
640 * Managed reset_control_bulk_get_exclusive(). For reset controllers returned
641 * from this function, reset_control_put() is called automatically on driver
642 * detach.
643 *
644 * See reset_control_bulk_get_exclusive() for more information.
645 */
646static inline int __must_check
647devm_reset_control_bulk_get_exclusive(struct device *dev, int num_rstcs,
648 struct reset_control_bulk_data *rstcs)
649{
650 return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs,
651 flags: RESET_CONTROL_EXCLUSIVE);
652}
653
654/**
655 * devm_reset_control_get_exclusive_released - resource managed
656 * reset_control_get_exclusive_released()
657 * @dev: device to be reset by the controller
658 * @id: reset line name
659 *
660 * Managed reset_control_get_exclusive_released(). For reset controllers
661 * returned from this function, reset_control_put() is called automatically on
662 * driver detach.
663 *
664 * See reset_control_get_exclusive_released() for more information.
665 */
666static inline struct reset_control *
667__must_check devm_reset_control_get_exclusive_released(struct device *dev,
668 const char *id)
669{
670 return __devm_reset_control_get(dev, id, index: 0, flags: RESET_CONTROL_EXCLUSIVE_RELEASED);
671}
672
673/**
674 * devm_reset_control_bulk_get_exclusive_released - resource managed
675 * reset_control_bulk_get_exclusive_released()
676 * @dev: device to be reset by the controller
677 * @num_rstcs: number of entries in rstcs array
678 * @rstcs: array of struct reset_control_bulk_data with reset line names set
679 *
680 * Managed reset_control_bulk_get_exclusive_released(). For reset controllers
681 * returned from this function, reset_control_put() is called automatically on
682 * driver detach.
683 *
684 * See reset_control_bulk_get_exclusive_released() for more information.
685 */
686static inline int __must_check
687devm_reset_control_bulk_get_exclusive_released(struct device *dev, int num_rstcs,
688 struct reset_control_bulk_data *rstcs)
689{
690 return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs,
691 flags: RESET_CONTROL_EXCLUSIVE_RELEASED);
692}
693
694/**
695 * devm_reset_control_get_optional_exclusive_released - resource managed
696 * reset_control_get_optional_exclusive_released()
697 * @dev: device to be reset by the controller
698 * @id: reset line name
699 *
700 * Managed-and-optional variant of reset_control_get_exclusive_released(). For
701 * reset controllers returned from this function, reset_control_put() is called
702 * automatically on driver detach.
703 *
704 * See reset_control_get_exclusive_released() for more information.
705 */
706static inline struct reset_control *
707__must_check devm_reset_control_get_optional_exclusive_released(struct device *dev,
708 const char *id)
709{
710 return __devm_reset_control_get(dev, id, index: 0, flags: RESET_CONTROL_OPTIONAL_EXCLUSIVE_RELEASED);
711}
712
713/**
714 * devm_reset_control_bulk_get_optional_exclusive_released - resource managed
715 * reset_control_bulk_optional_get_exclusive_released()
716 * @dev: device to be reset by the controller
717 * @num_rstcs: number of entries in rstcs array
718 * @rstcs: array of struct reset_control_bulk_data with reset line names set
719 *
720 * Managed reset_control_bulk_optional_get_exclusive_released(). For reset
721 * controllers returned from this function, reset_control_put() is called
722 * automatically on driver detach.
723 *
724 * See reset_control_bulk_optional_get_exclusive_released() for more information.
725 */
726static inline int __must_check
727devm_reset_control_bulk_get_optional_exclusive_released(struct device *dev, int num_rstcs,
728 struct reset_control_bulk_data *rstcs)
729{
730 return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs,
731 flags: RESET_CONTROL_OPTIONAL_EXCLUSIVE_RELEASED);
732}
733
734/**
735 * devm_reset_control_get_shared - resource managed reset_control_get_shared()
736 * @dev: device to be reset by the controller
737 * @id: reset line name
738 *
739 * Managed reset_control_get_shared(). For reset controllers returned from
740 * this function, reset_control_put() is called automatically on driver detach.
741 * See reset_control_get_shared() for more information.
742 */
743static inline struct reset_control *devm_reset_control_get_shared(
744 struct device *dev, const char *id)
745{
746 return __devm_reset_control_get(dev, id, index: 0, flags: RESET_CONTROL_SHARED);
747}
748
749/**
750 * devm_reset_control_get_shared_deasserted - resource managed
751 * reset_control_get_shared() +
752 * reset_control_deassert()
753 * @dev: device to be reset by the controller
754 * @id: reset line name
755 *
756 * Managed reset_control_get_shared() + reset_control_deassert(). For reset
757 * controllers returned from this function, reset_control_assert() +
758 * reset_control_put() is called automatically on driver detach.
759 *
760 * See devm_reset_control_get_shared() for more information.
761 */
762static inline struct reset_control * __must_check
763devm_reset_control_get_shared_deasserted(struct device *dev, const char *id)
764{
765 return __devm_reset_control_get(dev, id, index: 0, flags: RESET_CONTROL_SHARED_DEASSERTED);
766}
767
768/**
769 * devm_reset_control_bulk_get_shared - resource managed
770 * reset_control_bulk_get_shared()
771 * @dev: device to be reset by the controller
772 * @num_rstcs: number of entries in rstcs array
773 * @rstcs: array of struct reset_control_bulk_data with reset line names set
774 *
775 * Managed reset_control_bulk_get_shared(). For reset controllers returned
776 * from this function, reset_control_put() is called automatically on driver
777 * detach.
778 *
779 * See reset_control_bulk_get_shared() for more information.
780 */
781static inline int __must_check
782devm_reset_control_bulk_get_shared(struct device *dev, int num_rstcs,
783 struct reset_control_bulk_data *rstcs)
784{
785 return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs, flags: RESET_CONTROL_SHARED);
786}
787
788/**
789 * devm_reset_control_bulk_get_shared_deasserted - resource managed
790 * reset_control_bulk_get_shared() +
791 * reset_control_bulk_deassert()
792 * @dev: device to be reset by the controller
793 * @num_rstcs: number of entries in rstcs array
794 * @rstcs: array of struct reset_control_bulk_data with reset line names set
795 *
796 * Managed reset_control_bulk_get_shared() + reset_control_bulk_deassert(). For
797 * reset controllers returned from this function, reset_control_bulk_assert() +
798 * reset_control_bulk_put() are called automatically on driver detach.
799 *
800 * See devm_reset_control_bulk_get_shared() for more information.
801 */
802static inline int __must_check
803devm_reset_control_bulk_get_shared_deasserted(struct device *dev, int num_rstcs,
804 struct reset_control_bulk_data *rstcs)
805{
806 return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs,
807 flags: RESET_CONTROL_SHARED_DEASSERTED);
808}
809
810/**
811 * devm_reset_control_get_optional_exclusive - resource managed
812 * reset_control_get_optional_exclusive()
813 * @dev: device to be reset by the controller
814 * @id: reset line name
815 *
816 * Managed reset_control_get_optional_exclusive(). For reset controllers
817 * returned from this function, reset_control_put() is called automatically on
818 * driver detach.
819 *
820 * See reset_control_get_optional_exclusive() for more information.
821 */
822static inline struct reset_control *devm_reset_control_get_optional_exclusive(
823 struct device *dev, const char *id)
824{
825 return __devm_reset_control_get(dev, id, index: 0, flags: RESET_CONTROL_OPTIONAL_EXCLUSIVE);
826}
827
828/**
829 * devm_reset_control_get_optional_exclusive_deasserted - resource managed
830 * reset_control_get_optional_exclusive() +
831 * reset_control_deassert()
832 * @dev: device to be reset by the controller
833 * @id: reset line name
834 *
835 * Managed reset_control_get_optional_exclusive() + reset_control_deassert().
836 * For reset controllers returned from this function, reset_control_assert() +
837 * reset_control_put() is called automatically on driver detach.
838 *
839 * See devm_reset_control_get_optional_exclusive() for more information.
840 */
841static inline struct reset_control *
842devm_reset_control_get_optional_exclusive_deasserted(struct device *dev, const char *id)
843{
844 return __devm_reset_control_get(dev, id, index: 0, flags: RESET_CONTROL_OPTIONAL_EXCLUSIVE_DEASSERTED);
845}
846
847/**
848 * devm_reset_control_bulk_get_optional_exclusive - resource managed
849 * reset_control_bulk_get_optional_exclusive()
850 * @dev: device to be reset by the controller
851 * @num_rstcs: number of entries in rstcs array
852 * @rstcs: array of struct reset_control_bulk_data with reset line names set
853 *
854 * Managed reset_control_bulk_get_optional_exclusive(). For reset controllers
855 * returned from this function, reset_control_put() is called automatically on
856 * driver detach.
857 *
858 * See reset_control_bulk_get_optional_exclusive() for more information.
859 */
860static inline int __must_check
861devm_reset_control_bulk_get_optional_exclusive(struct device *dev, int num_rstcs,
862 struct reset_control_bulk_data *rstcs)
863{
864 return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs,
865 flags: RESET_CONTROL_OPTIONAL_EXCLUSIVE);
866}
867
868/**
869 * devm_reset_control_get_optional_shared - resource managed
870 * reset_control_get_optional_shared()
871 * @dev: device to be reset by the controller
872 * @id: reset line name
873 *
874 * Managed reset_control_get_optional_shared(). For reset controllers returned
875 * from this function, reset_control_put() is called automatically on driver
876 * detach.
877 *
878 * See reset_control_get_optional_shared() for more information.
879 */
880static inline struct reset_control *devm_reset_control_get_optional_shared(
881 struct device *dev, const char *id)
882{
883 return __devm_reset_control_get(dev, id, index: 0, flags: RESET_CONTROL_OPTIONAL_SHARED);
884}
885
886/**
887 * devm_reset_control_get_optional_shared_deasserted - resource managed
888 * reset_control_get_optional_shared() +
889 * reset_control_deassert()
890 * @dev: device to be reset by the controller
891 * @id: reset line name
892 *
893 * Managed reset_control_get_optional_shared() + reset_control_deassert(). For
894 * reset controllers returned from this function, reset_control_assert() +
895 * reset_control_put() is called automatically on driver detach.
896 *
897 * See devm_reset_control_get_optional_shared() for more information.
898 */
899static inline struct reset_control *
900devm_reset_control_get_optional_shared_deasserted(struct device *dev, const char *id)
901{
902 return __devm_reset_control_get(dev, id, index: 0, flags: RESET_CONTROL_OPTIONAL_SHARED_DEASSERTED);
903}
904
905/**
906 * devm_reset_control_bulk_get_optional_shared - resource managed
907 * reset_control_bulk_get_optional_shared()
908 * @dev: device to be reset by the controller
909 * @num_rstcs: number of entries in rstcs array
910 * @rstcs: array of struct reset_control_bulk_data with reset line names set
911 *
912 * Managed reset_control_bulk_get_optional_shared(). For reset controllers
913 * returned from this function, reset_control_put() is called automatically on
914 * driver detach.
915 *
916 * See reset_control_bulk_get_optional_shared() for more information.
917 */
918static inline int __must_check
919devm_reset_control_bulk_get_optional_shared(struct device *dev, int num_rstcs,
920 struct reset_control_bulk_data *rstcs)
921{
922 return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs, flags: RESET_CONTROL_OPTIONAL_SHARED);
923}
924
925/**
926 * devm_reset_control_get_exclusive_by_index - resource managed
927 * reset_control_get_exclusive()
928 * @dev: device to be reset by the controller
929 * @index: index of the reset controller
930 *
931 * Managed reset_control_get_exclusive(). For reset controllers returned from
932 * this function, reset_control_put() is called automatically on driver
933 * detach.
934 *
935 * See reset_control_get_exclusive() for more information.
936 */
937static inline struct reset_control *
938devm_reset_control_get_exclusive_by_index(struct device *dev, int index)
939{
940 return __devm_reset_control_get(dev, NULL, index, flags: RESET_CONTROL_EXCLUSIVE);
941}
942
943/**
944 * devm_reset_control_get_shared_by_index - resource managed
945 * reset_control_get_shared
946 * @dev: device to be reset by the controller
947 * @index: index of the reset controller
948 *
949 * Managed reset_control_get_shared(). For reset controllers returned from
950 * this function, reset_control_put() is called automatically on driver detach.
951 * See reset_control_get_shared() for more information.
952 */
953static inline struct reset_control *
954devm_reset_control_get_shared_by_index(struct device *dev, int index)
955{
956 return __devm_reset_control_get(dev, NULL, index, flags: RESET_CONTROL_SHARED);
957}
958
959/*
960 * TEMPORARY calls to use during transition:
961 *
962 * of_reset_control_get() => of_reset_control_get_exclusive()
963 *
964 * These inline function calls will be removed once all consumers
965 * have been moved over to the new explicit API.
966 */
967static inline struct reset_control *of_reset_control_get(
968 struct device_node *node, const char *id)
969{
970 return of_reset_control_get_exclusive(node, id);
971}
972
973static inline struct reset_control *of_reset_control_get_by_index(
974 struct device_node *node, int index)
975{
976 return of_reset_control_get_exclusive_by_index(node, index);
977}
978
979static inline struct reset_control *devm_reset_control_get(
980 struct device *dev, const char *id)
981{
982 return devm_reset_control_get_exclusive(dev, id);
983}
984
985static inline struct reset_control *devm_reset_control_get_optional(
986 struct device *dev, const char *id)
987{
988 return devm_reset_control_get_optional_exclusive(dev, id);
989
990}
991
992static inline struct reset_control *devm_reset_control_get_by_index(
993 struct device *dev, int index)
994{
995 return devm_reset_control_get_exclusive_by_index(dev, index);
996}
997
998/*
999 * APIs to manage a list of reset controllers
1000 */
1001static inline struct reset_control *
1002devm_reset_control_array_get_exclusive(struct device *dev)
1003{
1004 return devm_reset_control_array_get(dev, flags: RESET_CONTROL_EXCLUSIVE);
1005}
1006
1007static inline struct reset_control *
1008devm_reset_control_array_get_exclusive_released(struct device *dev)
1009{
1010 return devm_reset_control_array_get(dev, flags: RESET_CONTROL_EXCLUSIVE_RELEASED);
1011}
1012
1013static inline struct reset_control *
1014devm_reset_control_array_get_shared(struct device *dev)
1015{
1016 return devm_reset_control_array_get(dev, flags: RESET_CONTROL_SHARED);
1017}
1018
1019static inline struct reset_control *
1020devm_reset_control_array_get_optional_exclusive(struct device *dev)
1021{
1022 return devm_reset_control_array_get(dev, flags: RESET_CONTROL_OPTIONAL_EXCLUSIVE);
1023}
1024
1025static inline struct reset_control *
1026devm_reset_control_array_get_optional_shared(struct device *dev)
1027{
1028 return devm_reset_control_array_get(dev, flags: RESET_CONTROL_OPTIONAL_SHARED);
1029}
1030
1031static inline struct reset_control *
1032of_reset_control_array_get_exclusive(struct device_node *node)
1033{
1034 return of_reset_control_array_get(np: node, flags: RESET_CONTROL_EXCLUSIVE);
1035}
1036
1037static inline struct reset_control *
1038of_reset_control_array_get_exclusive_released(struct device_node *node)
1039{
1040 return of_reset_control_array_get(np: node, flags: RESET_CONTROL_EXCLUSIVE_RELEASED);
1041}
1042
1043static inline struct reset_control *
1044of_reset_control_array_get_shared(struct device_node *node)
1045{
1046 return of_reset_control_array_get(np: node, flags: RESET_CONTROL_SHARED);
1047}
1048
1049static inline struct reset_control *
1050of_reset_control_array_get_optional_exclusive(struct device_node *node)
1051{
1052 return of_reset_control_array_get(np: node, flags: RESET_CONTROL_OPTIONAL_EXCLUSIVE);
1053}
1054
1055static inline struct reset_control *
1056of_reset_control_array_get_optional_shared(struct device_node *node)
1057{
1058 return of_reset_control_array_get(np: node, flags: RESET_CONTROL_OPTIONAL_SHARED);
1059}
1060#endif
1061