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