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