Merge tag 'mm-hotfixes-stable-2025-07-11-16-16' of git://git.kernel.org/pub/scm/linux...
[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
dad35f7d
PZ
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 */
d872bed8 31#define RESET_CONTROL_FLAGS_BIT_DEASSERTED BIT(3)
dad35f7d
PZ
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,
d872bed8 39 * @RESET_CONTROL_EXCLUSIVE_DEASSERTED: exclusive, acquired, deasserted
dad35f7d
PZ
40 * @RESET_CONTROL_EXCLUSIVE_RELEASED: exclusive, released,
41 * @RESET_CONTROL_SHARED: shared
d872bed8 42 * @RESET_CONTROL_SHARED_DEASSERTED: shared, deasserted
dad35f7d 43 * @RESET_CONTROL_OPTIONAL_EXCLUSIVE: optional, exclusive, acquired
d872bed8 44 * @RESET_CONTROL_OPTIONAL_EXCLUSIVE_DEASSERTED: optional, exclusive, acquired, deasserted
dad35f7d
PZ
45 * @RESET_CONTROL_OPTIONAL_EXCLUSIVE_RELEASED: optional, exclusive, released
46 * @RESET_CONTROL_OPTIONAL_SHARED: optional, shared
d872bed8 47 * @RESET_CONTROL_OPTIONAL_SHARED_DEASSERTED: optional, shared, deasserted
dad35f7d
PZ
48 */
49enum reset_control_flags {
50 RESET_CONTROL_EXCLUSIVE = RESET_CONTROL_FLAGS_BIT_ACQUIRED,
d872bed8
PZ
51 RESET_CONTROL_EXCLUSIVE_DEASSERTED = RESET_CONTROL_FLAGS_BIT_ACQUIRED |
52 RESET_CONTROL_FLAGS_BIT_DEASSERTED,
dad35f7d
PZ
53 RESET_CONTROL_EXCLUSIVE_RELEASED = 0,
54 RESET_CONTROL_SHARED = RESET_CONTROL_FLAGS_BIT_SHARED,
d872bed8
PZ
55 RESET_CONTROL_SHARED_DEASSERTED = RESET_CONTROL_FLAGS_BIT_SHARED |
56 RESET_CONTROL_FLAGS_BIT_DEASSERTED,
dad35f7d
PZ
57 RESET_CONTROL_OPTIONAL_EXCLUSIVE = RESET_CONTROL_FLAGS_BIT_OPTIONAL |
58 RESET_CONTROL_FLAGS_BIT_ACQUIRED,
d872bed8
PZ
59 RESET_CONTROL_OPTIONAL_EXCLUSIVE_DEASSERTED = RESET_CONTROL_FLAGS_BIT_OPTIONAL |
60 RESET_CONTROL_FLAGS_BIT_ACQUIRED |
61 RESET_CONTROL_FLAGS_BIT_DEASSERTED,
dad35f7d
PZ
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,
d872bed8
PZ
65 RESET_CONTROL_OPTIONAL_SHARED_DEASSERTED = RESET_CONTROL_FLAGS_BIT_OPTIONAL |
66 RESET_CONTROL_FLAGS_BIT_SHARED |
67 RESET_CONTROL_FLAGS_BIT_DEASSERTED,
dad35f7d
PZ
68};
69
b424080a
PZ
70#ifdef CONFIG_RESET_CONTROLLER
71
61fc4131 72int reset_control_reset(struct reset_control *rstc);
557acb3d 73int reset_control_rearm(struct reset_control *rstc);
61fc4131
PZ
74int reset_control_assert(struct reset_control *rstc);
75int reset_control_deassert(struct reset_control *rstc);
729de41b 76int reset_control_status(struct reset_control *rstc);
c84b0326
PZ
77int reset_control_acquire(struct reset_control *rstc);
78void reset_control_release(struct reset_control *rstc);
61fc4131 79
48d71395
PZ
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
6c96f05c 86struct reset_control *__of_reset_control_get(struct device_node *node,
dad35f7d 87 const char *id, int index, enum reset_control_flags flags);
62e24c57 88struct reset_control *__reset_control_get(struct device *dev, const char *id,
dad35f7d 89 int index, enum reset_control_flags flags);
61fc4131 90void reset_control_put(struct reset_control *rstc);
48d71395
PZ
91int __reset_control_bulk_get(struct device *dev, int num_rstcs,
92 struct reset_control_bulk_data *rstcs,
dad35f7d 93 enum reset_control_flags flags);
48d71395
PZ
94void reset_control_bulk_put(int num_rstcs, struct reset_control_bulk_data *rstcs);
95
1554bbd4 96int __device_reset(struct device *dev, bool optional);
6c96f05c 97struct reset_control *__devm_reset_control_get(struct device *dev,
dad35f7d 98 const char *id, int index, enum reset_control_flags flags);
48d71395
PZ
99int __devm_reset_control_bulk_get(struct device *dev, int num_rstcs,
100 struct reset_control_bulk_data *rstcs,
dad35f7d 101 enum reset_control_flags flags);
61fc4131 102
17c82e20 103struct reset_control *devm_reset_control_array_get(struct device *dev,
dad35f7d
PZ
104 enum reset_control_flags flags);
105struct reset_control *of_reset_control_array_get(struct device_node *np, enum reset_control_flags);
17c82e20 106
eaf91db0
GU
107int reset_control_get_count(struct device *dev);
108
b424080a
PZ
109#else
110
111static inline int reset_control_reset(struct reset_control *rstc)
112{
b424080a
PZ
113 return 0;
114}
115
48582b2e
JQ
116static inline int reset_control_rearm(struct reset_control *rstc)
117{
118 return 0;
119}
120
b424080a
PZ
121static inline int reset_control_assert(struct reset_control *rstc)
122{
b424080a
PZ
123 return 0;
124}
125
126static inline int reset_control_deassert(struct reset_control *rstc)
127{
b424080a
PZ
128 return 0;
129}
130
729de41b
DN
131static inline int reset_control_status(struct reset_control *rstc)
132{
729de41b
DN
133 return 0;
134}
135
c84b0326
PZ
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
b424080a
PZ
145static inline void reset_control_put(struct reset_control *rstc)
146{
b424080a
PZ
147}
148
1554bbd4 149static inline int __device_reset(struct device *dev, bool optional)
b424080a 150{
1554bbd4 151 return optional ? 0 : -ENOTSUPP;
b424080a
PZ
152}
153
6c96f05c
HG
154static inline struct reset_control *__of_reset_control_get(
155 struct device_node *node,
dad35f7d 156 const char *id, int index, enum reset_control_flags flags)
5bcd0b7f 157{
dad35f7d
PZ
158 bool optional = flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL;
159
0ca10b60 160 return optional ? NULL : ERR_PTR(-ENOTSUPP);
5bcd0b7f
AL
161}
162
62e24c57
PZ
163static inline struct reset_control *__reset_control_get(
164 struct device *dev, const char *id,
dad35f7d 165 int index, enum reset_control_flags flags)
62e24c57 166{
dad35f7d
PZ
167 bool optional = flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL;
168
62e24c57
PZ
169 return optional ? NULL : ERR_PTR(-ENOTSUPP);
170}
171
48d71395
PZ
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,
dad35f7d 204 enum reset_control_flags flags)
48d71395 205{
dad35f7d
PZ
206 bool optional = flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL;
207
48d71395
PZ
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
6c96f05c 216static inline struct reset_control *__devm_reset_control_get(
bb475230 217 struct device *dev, const char *id,
dad35f7d 218 int index, enum reset_control_flags flags)
5bcd0b7f 219{
dad35f7d
PZ
220 bool optional = flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL;
221
0ca10b60 222 return optional ? NULL : ERR_PTR(-ENOTSUPP);
5bcd0b7f
AL
223}
224
48d71395
PZ
225static inline int
226__devm_reset_control_bulk_get(struct device *dev, int num_rstcs,
227 struct reset_control_bulk_data *rstcs,
dad35f7d 228 enum reset_control_flags flags)
48d71395 229{
dad35f7d
PZ
230 bool optional = flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL;
231
48d71395
PZ
232 return optional ? 0 : -EOPNOTSUPP;
233}
234
17c82e20 235static inline struct reset_control *
dad35f7d 236devm_reset_control_array_get(struct device *dev, enum reset_control_flags flags)
17c82e20 237{
dad35f7d
PZ
238 bool optional = flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL;
239
17c82e20
VG
240 return optional ? NULL : ERR_PTR(-ENOTSUPP);
241}
242
243static inline struct reset_control *
dad35f7d 244of_reset_control_array_get(struct device_node *np, enum reset_control_flags flags)
17c82e20 245{
dad35f7d
PZ
246 bool optional = flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL;
247
17c82e20
VG
248 return optional ? NULL : ERR_PTR(-ENOTSUPP);
249}
250
eaf91db0
GU
251static inline int reset_control_get_count(struct device *dev)
252{
253 return -ENOENT;
254}
255
6c96f05c
HG
256#endif /* CONFIG_RESET_CONTROLLER */
257
1554bbd4
MY
258static inline int __must_check device_reset(struct device *dev)
259{
260 return __device_reset(dev, false);
261}
262
263static inline int device_reset_optional(struct device *dev)
264{
265 return __device_reset(dev, true);
266}
267
6c96f05c 268/**
a53e35db
LJ
269 * reset_control_get_exclusive - Lookup and obtain an exclusive reference
270 * to a reset controller.
6c96f05c
HG
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.
34845c93 275 * If this function is called more than once for the same reset_control it will
0b52297f
HG
276 * return -EBUSY.
277 *
b9e9348d 278 * See reset_control_get_shared() for details on shared references to
0b52297f 279 * reset-controls.
6c96f05c
HG
280 *
281 * Use of id names is optional.
282 */
a53e35db
LJ
283static inline struct reset_control *
284__must_check reset_control_get_exclusive(struct device *dev, const char *id)
b424080a 285{
dad35f7d 286 return __reset_control_get(dev, id, 0, RESET_CONTROL_EXCLUSIVE);
c84b0326
PZ
287}
288
48d71395
PZ
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{
dad35f7d 303 return __reset_control_bulk_get(dev, num_rstcs, rstcs, RESET_CONTROL_EXCLUSIVE);
48d71395
PZ
304}
305
c84b0326
PZ
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{
dad35f7d 324 return __reset_control_get(dev, id, 0, RESET_CONTROL_EXCLUSIVE_RELEASED);
b424080a
PZ
325}
326
48d71395
PZ
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{
dad35f7d 345 return __reset_control_bulk_get(dev, num_rstcs, rstcs, RESET_CONTROL_EXCLUSIVE_RELEASED);
48d71395
PZ
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{
dad35f7d
PZ
366 return __reset_control_bulk_get(dev, num_rstcs, rstcs,
367 RESET_CONTROL_OPTIONAL_EXCLUSIVE_RELEASED);
48d71395
PZ
368}
369
6c96f05c 370/**
0b52297f
HG
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
12c62b9d 378 * between hardware blocks.
0b52297f
HG
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{
dad35f7d 395 return __reset_control_get(dev, id, 0, RESET_CONTROL_SHARED);
0b52297f
HG
396}
397
48d71395
PZ
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{
dad35f7d 412 return __reset_control_bulk_get(dev, num_rstcs, rstcs, RESET_CONTROL_SHARED);
48d71395
PZ
413}
414
c2ffa00a
PZ
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 */
a53e35db 426static inline struct reset_control *reset_control_get_optional_exclusive(
3c35f6ed
LJ
427 struct device *dev, const char *id)
428{
dad35f7d 429 return __reset_control_get(dev, id, 0, RESET_CONTROL_OPTIONAL_EXCLUSIVE);
3c35f6ed
LJ
430}
431
48d71395
PZ
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{
dad35f7d 449 return __reset_control_bulk_get(dev, num_rstcs, rstcs, RESET_CONTROL_OPTIONAL_EXCLUSIVE);
48d71395
PZ
450}
451
c2ffa00a
PZ
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 */
c33d61a0
LJ
463static inline struct reset_control *reset_control_get_optional_shared(
464 struct device *dev, const char *id)
465{
dad35f7d 466 return __reset_control_get(dev, id, 0, RESET_CONTROL_OPTIONAL_SHARED);
c33d61a0
LJ
467}
468
48d71395
PZ
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{
dad35f7d 486 return __reset_control_bulk_get(dev, num_rstcs, rstcs, RESET_CONTROL_OPTIONAL_SHARED);
48d71395
PZ
487}
488
0b52297f 489/**
a53e35db
LJ
490 * of_reset_control_get_exclusive - Lookup and obtain an exclusive reference
491 * to a reset controller.
6c96f05c
HG
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 */
a53e35db 499static inline struct reset_control *of_reset_control_get_exclusive(
e3ec0a8c
HG
500 struct device_node *node, const char *id)
501{
dad35f7d 502 return __of_reset_control_get(node, id, 0, RESET_CONTROL_EXCLUSIVE);
e3ec0a8c
HG
503}
504
c4f5b30d
BD
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{
dad35f7d 522 return __of_reset_control_get(node, id, 0, RESET_CONTROL_OPTIONAL_EXCLUSIVE);
c4f5b30d
BD
523}
524
6c96f05c 525/**
12c62b9d 526 * of_reset_control_get_shared - Lookup and obtain a shared reference
40faee8e
LJ
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{
dad35f7d 547 return __of_reset_control_get(node, id, 0, RESET_CONTROL_SHARED);
40faee8e
LJ
548}
549
6c96f05c 550/**
a53e35db
LJ
551 * of_reset_control_get_exclusive_by_index - Lookup and obtain an exclusive
552 * reference to a reset controller
553 * by index.
6c96f05c
HG
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 */
a53e35db 561static inline struct reset_control *of_reset_control_get_exclusive_by_index(
6c96f05c 562 struct device_node *node, int index)
c0a13aa6 563{
dad35f7d 564 return __of_reset_control_get(node, NULL, index, RESET_CONTROL_EXCLUSIVE);
c0a13aa6
VH
565}
566
6c96f05c 567/**
12c62b9d 568 * of_reset_control_get_shared_by_index - Lookup and obtain a shared
40faee8e
LJ
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.
6c96f05c 584 *
40faee8e
LJ
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.
6c96f05c 588 */
40faee8e
LJ
589static inline struct reset_control *of_reset_control_get_shared_by_index(
590 struct device_node *node, int index)
6c96f05c 591{
dad35f7d 592 return __of_reset_control_get(node, NULL, index, RESET_CONTROL_SHARED);
6c96f05c
HG
593}
594
595/**
a53e35db
LJ
596 * devm_reset_control_get_exclusive - resource managed
597 * reset_control_get_exclusive()
6c96f05c 598 * @dev: device to be reset by the controller
6c96f05c 599 * @id: reset line name
6c96f05c 600 *
a53e35db
LJ
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.
6c96f05c 606 */
a53e35db
LJ
607static inline struct reset_control *
608__must_check devm_reset_control_get_exclusive(struct device *dev,
609 const char *id)
6c96f05c 610{
dad35f7d 611 return __devm_reset_control_get(dev, id, 0, RESET_CONTROL_EXCLUSIVE);
c84b0326
PZ
612}
613
d872bed8
PZ
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, 0, RESET_CONTROL_EXCLUSIVE_DEASSERTED);
631}
632
48d71395
PZ
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{
dad35f7d
PZ
650 return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs,
651 RESET_CONTROL_EXCLUSIVE);
48d71395
PZ
652}
653
c84b0326
PZ
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{
dad35f7d 670 return __devm_reset_control_get(dev, id, 0, RESET_CONTROL_EXCLUSIVE_RELEASED);
0b52297f
HG
671}
672
48d71395
PZ
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{
dad35f7d
PZ
690 return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs,
691 RESET_CONTROL_EXCLUSIVE_RELEASED);
48d71395
PZ
692}
693
d1765575
DO
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{
dad35f7d 710 return __devm_reset_control_get(dev, id, 0, RESET_CONTROL_OPTIONAL_EXCLUSIVE_RELEASED);
d1765575
DO
711}
712
48d71395
PZ
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{
dad35f7d
PZ
730 return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs,
731 RESET_CONTROL_OPTIONAL_EXCLUSIVE_RELEASED);
48d71395
PZ
732}
733
0b52297f
HG
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{
dad35f7d 746 return __devm_reset_control_get(dev, id, 0, RESET_CONTROL_SHARED);
0b52297f
HG
747}
748
d872bed8
PZ
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, 0, RESET_CONTROL_SHARED_DEASSERTED);
766}
767
48d71395
PZ
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{
dad35f7d 785 return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs, RESET_CONTROL_SHARED);
48d71395
PZ
786}
787
d872bed8
PZ
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 RESET_CONTROL_SHARED_DEASSERTED);
808}
809
c2ffa00a
PZ
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 */
a53e35db 822static inline struct reset_control *devm_reset_control_get_optional_exclusive(
6c96f05c
HG
823 struct device *dev, const char *id)
824{
dad35f7d 825 return __devm_reset_control_get(dev, id, 0, RESET_CONTROL_OPTIONAL_EXCLUSIVE);
6c96f05c
HG
826}
827
d872bed8
PZ
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, 0, RESET_CONTROL_OPTIONAL_EXCLUSIVE_DEASSERTED);
845}
846
48d71395
PZ
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{
dad35f7d
PZ
864 return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs,
865 RESET_CONTROL_OPTIONAL_EXCLUSIVE);
48d71395
PZ
866}
867
c2ffa00a
PZ
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 */
c33d61a0
LJ
880static inline struct reset_control *devm_reset_control_get_optional_shared(
881 struct device *dev, const char *id)
882{
dad35f7d 883 return __devm_reset_control_get(dev, id, 0, RESET_CONTROL_OPTIONAL_SHARED);
c33d61a0
LJ
884}
885
d872bed8
PZ
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, 0, RESET_CONTROL_OPTIONAL_SHARED_DEASSERTED);
903}
904
48d71395
PZ
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{
dad35f7d 922 return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs, RESET_CONTROL_OPTIONAL_SHARED);
48d71395
PZ
923}
924
6c96f05c 925/**
a53e35db
LJ
926 * devm_reset_control_get_exclusive_by_index - resource managed
927 * reset_control_get_exclusive()
6c96f05c
HG
928 * @dev: device to be reset by the controller
929 * @index: index of the reset controller
930 *
a53e35db
LJ
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.
6c96f05c 936 */
a53e35db
LJ
937static inline struct reset_control *
938devm_reset_control_get_exclusive_by_index(struct device *dev, int index)
6c96f05c 939{
dad35f7d 940 return __devm_reset_control_get(dev, NULL, index, RESET_CONTROL_EXCLUSIVE);
0b52297f
HG
941}
942
0b52297f
HG
943/**
944 * devm_reset_control_get_shared_by_index - resource managed
12c62b9d 945 * reset_control_get_shared
0b52297f
HG
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 */
0bcc0eab
LJ
953static inline struct reset_control *
954devm_reset_control_get_shared_by_index(struct device *dev, int index)
0b52297f 955{
dad35f7d 956 return __devm_reset_control_get(dev, NULL, index, RESET_CONTROL_SHARED);
6c96f05c 957}
61fc4131 958
a53e35db
LJ
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 */
a53e35db
LJ
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}
17c82e20
VG
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{
dad35f7d 1004 return devm_reset_control_array_get(dev, RESET_CONTROL_EXCLUSIVE);
17c82e20
VG
1005}
1006
6b375400
PC
1007static inline struct reset_control *
1008devm_reset_control_array_get_exclusive_released(struct device *dev)
1009{
1010 return devm_reset_control_array_get(dev, RESET_CONTROL_EXCLUSIVE_RELEASED);
1011}
1012
17c82e20
VG
1013static inline struct reset_control *
1014devm_reset_control_array_get_shared(struct device *dev)
1015{
dad35f7d 1016 return devm_reset_control_array_get(dev, RESET_CONTROL_SHARED);
17c82e20
VG
1017}
1018
1019static inline struct reset_control *
1020devm_reset_control_array_get_optional_exclusive(struct device *dev)
1021{
dad35f7d 1022 return devm_reset_control_array_get(dev, RESET_CONTROL_OPTIONAL_EXCLUSIVE);
17c82e20
VG
1023}
1024
1025static inline struct reset_control *
1026devm_reset_control_array_get_optional_shared(struct device *dev)
1027{
dad35f7d 1028 return devm_reset_control_array_get(dev, RESET_CONTROL_OPTIONAL_SHARED);
17c82e20
VG
1029}
1030
1031static inline struct reset_control *
1032of_reset_control_array_get_exclusive(struct device_node *node)
1033{
dad35f7d 1034 return of_reset_control_array_get(node, RESET_CONTROL_EXCLUSIVE);
17c82e20
VG
1035}
1036
22815f18
TR
1037static inline struct reset_control *
1038of_reset_control_array_get_exclusive_released(struct device_node *node)
1039{
dad35f7d 1040 return of_reset_control_array_get(node, RESET_CONTROL_EXCLUSIVE_RELEASED);
22815f18
TR
1041}
1042
17c82e20
VG
1043static inline struct reset_control *
1044of_reset_control_array_get_shared(struct device_node *node)
1045{
dad35f7d 1046 return of_reset_control_array_get(node, RESET_CONTROL_SHARED);
17c82e20
VG
1047}
1048
1049static inline struct reset_control *
1050of_reset_control_array_get_optional_exclusive(struct device_node *node)
1051{
dad35f7d 1052 return of_reset_control_array_get(node, RESET_CONTROL_OPTIONAL_EXCLUSIVE);
17c82e20
VG
1053}
1054
1055static inline struct reset_control *
1056of_reset_control_array_get_optional_shared(struct device_node *node)
1057{
dad35f7d 1058 return of_reset_control_array_get(node, RESET_CONTROL_OPTIONAL_SHARED);
17c82e20 1059}
61fc4131 1060#endif