]>
Commit | Line | Data |
---|---|---|
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 |
9 | struct device; |
10 | struct device_node; | |
61fc4131 PZ |
11 | struct reset_control; |
12 | ||
b424080a PZ |
13 | #ifdef CONFIG_RESET_CONTROLLER |
14 | ||
61fc4131 PZ |
15 | int reset_control_reset(struct reset_control *rstc); |
16 | int reset_control_assert(struct reset_control *rstc); | |
17 | int reset_control_deassert(struct reset_control *rstc); | |
729de41b | 18 | int reset_control_status(struct reset_control *rstc); |
c84b0326 PZ |
19 | int reset_control_acquire(struct reset_control *rstc); |
20 | void reset_control_release(struct reset_control *rstc); | |
61fc4131 | 21 | |
6c96f05c | 22 | struct reset_control *__of_reset_control_get(struct device_node *node, |
bb475230 | 23 | const char *id, int index, bool shared, |
c84b0326 | 24 | bool optional, bool acquired); |
62e24c57 PZ |
25 | struct reset_control *__reset_control_get(struct device *dev, const char *id, |
26 | int index, bool shared, | |
c84b0326 | 27 | bool optional, bool acquired); |
61fc4131 | 28 | void reset_control_put(struct reset_control *rstc); |
1554bbd4 | 29 | int __device_reset(struct device *dev, bool optional); |
6c96f05c | 30 | struct reset_control *__devm_reset_control_get(struct device *dev, |
bb475230 | 31 | const char *id, int index, bool shared, |
c84b0326 | 32 | bool optional, bool acquired); |
61fc4131 | 33 | |
17c82e20 VG |
34 | struct reset_control *devm_reset_control_array_get(struct device *dev, |
35 | bool shared, bool optional); | |
36 | struct reset_control *of_reset_control_array_get(struct device_node *np, | |
f31d5c24 TR |
37 | bool shared, bool optional, |
38 | bool acquired); | |
17c82e20 | 39 | |
eaf91db0 GU |
40 | int reset_control_get_count(struct device *dev); |
41 | ||
b424080a PZ |
42 | #else |
43 | ||
44 | static inline int reset_control_reset(struct reset_control *rstc) | |
45 | { | |
b424080a PZ |
46 | return 0; |
47 | } | |
48 | ||
49 | static inline int reset_control_assert(struct reset_control *rstc) | |
50 | { | |
b424080a PZ |
51 | return 0; |
52 | } | |
53 | ||
54 | static inline int reset_control_deassert(struct reset_control *rstc) | |
55 | { | |
b424080a PZ |
56 | return 0; |
57 | } | |
58 | ||
729de41b DN |
59 | static inline int reset_control_status(struct reset_control *rstc) |
60 | { | |
729de41b DN |
61 | return 0; |
62 | } | |
63 | ||
c84b0326 PZ |
64 | static inline int reset_control_acquire(struct reset_control *rstc) |
65 | { | |
66 | return 0; | |
67 | } | |
68 | ||
69 | static inline void reset_control_release(struct reset_control *rstc) | |
70 | { | |
71 | } | |
72 | ||
b424080a PZ |
73 | static inline void reset_control_put(struct reset_control *rstc) |
74 | { | |
b424080a PZ |
75 | } |
76 | ||
1554bbd4 | 77 | static inline int __device_reset(struct device *dev, bool optional) |
b424080a | 78 | { |
1554bbd4 | 79 | return optional ? 0 : -ENOTSUPP; |
b424080a PZ |
80 | } |
81 | ||
6c96f05c HG |
82 | static inline struct reset_control *__of_reset_control_get( |
83 | struct device_node *node, | |
bb475230 | 84 | const char *id, int index, bool shared, |
c84b0326 | 85 | bool optional, bool acquired) |
5bcd0b7f | 86 | { |
0ca10b60 | 87 | return optional ? NULL : ERR_PTR(-ENOTSUPP); |
5bcd0b7f AL |
88 | } |
89 | ||
62e24c57 PZ |
90 | static inline struct reset_control *__reset_control_get( |
91 | struct device *dev, const char *id, | |
c84b0326 PZ |
92 | int index, bool shared, bool optional, |
93 | bool acquired) | |
62e24c57 PZ |
94 | { |
95 | return optional ? NULL : ERR_PTR(-ENOTSUPP); | |
96 | } | |
97 | ||
6c96f05c | 98 | static inline struct reset_control *__devm_reset_control_get( |
bb475230 | 99 | struct device *dev, const char *id, |
c84b0326 PZ |
100 | int index, bool shared, bool optional, |
101 | bool acquired) | |
5bcd0b7f | 102 | { |
0ca10b60 | 103 | return optional ? NULL : ERR_PTR(-ENOTSUPP); |
5bcd0b7f AL |
104 | } |
105 | ||
17c82e20 VG |
106 | static inline struct reset_control * |
107 | devm_reset_control_array_get(struct device *dev, bool shared, bool optional) | |
108 | { | |
109 | return optional ? NULL : ERR_PTR(-ENOTSUPP); | |
110 | } | |
111 | ||
112 | static inline struct reset_control * | |
f31d5c24 TR |
113 | of_reset_control_array_get(struct device_node *np, bool shared, bool optional, |
114 | bool acquired) | |
17c82e20 VG |
115 | { |
116 | return optional ? NULL : ERR_PTR(-ENOTSUPP); | |
117 | } | |
118 | ||
eaf91db0 GU |
119 | static inline int reset_control_get_count(struct device *dev) |
120 | { | |
121 | return -ENOENT; | |
122 | } | |
123 | ||
6c96f05c HG |
124 | #endif /* CONFIG_RESET_CONTROLLER */ |
125 | ||
1554bbd4 MY |
126 | static inline int __must_check device_reset(struct device *dev) |
127 | { | |
128 | return __device_reset(dev, false); | |
129 | } | |
130 | ||
131 | static inline int device_reset_optional(struct device *dev) | |
132 | { | |
133 | return __device_reset(dev, true); | |
134 | } | |
135 | ||
6c96f05c | 136 | /** |
a53e35db LJ |
137 | * reset_control_get_exclusive - Lookup and obtain an exclusive reference |
138 | * to a reset controller. | |
6c96f05c HG |
139 | * @dev: device to be reset by the controller |
140 | * @id: reset line name | |
141 | * | |
142 | * Returns a struct reset_control or IS_ERR() condition containing errno. | |
34845c93 | 143 | * If this function is called more than once for the same reset_control it will |
0b52297f HG |
144 | * return -EBUSY. |
145 | * | |
b9e9348d | 146 | * See reset_control_get_shared() for details on shared references to |
0b52297f | 147 | * reset-controls. |
6c96f05c HG |
148 | * |
149 | * Use of id names is optional. | |
150 | */ | |
a53e35db LJ |
151 | static inline struct reset_control * |
152 | __must_check reset_control_get_exclusive(struct device *dev, const char *id) | |
b424080a | 153 | { |
c84b0326 PZ |
154 | return __reset_control_get(dev, id, 0, false, false, true); |
155 | } | |
156 | ||
157 | /** | |
158 | * reset_control_get_exclusive_released - Lookup and obtain a temoprarily | |
159 | * exclusive reference to a reset | |
160 | * controller. | |
161 | * @dev: device to be reset by the controller | |
162 | * @id: reset line name | |
163 | * | |
164 | * Returns a struct reset_control or IS_ERR() condition containing errno. | |
165 | * reset-controls returned by this function must be acquired via | |
166 | * reset_control_acquire() before they can be used and should be released | |
167 | * via reset_control_release() afterwards. | |
168 | * | |
169 | * Use of id names is optional. | |
170 | */ | |
171 | static inline struct reset_control * | |
172 | __must_check reset_control_get_exclusive_released(struct device *dev, | |
173 | const char *id) | |
174 | { | |
175 | return __reset_control_get(dev, id, 0, false, false, false); | |
b424080a PZ |
176 | } |
177 | ||
6c96f05c | 178 | /** |
0b52297f HG |
179 | * reset_control_get_shared - Lookup and obtain a shared reference to a |
180 | * reset controller. | |
181 | * @dev: device to be reset by the controller | |
182 | * @id: reset line name | |
183 | * | |
184 | * Returns a struct reset_control or IS_ERR() condition containing errno. | |
185 | * This function is intended for use with reset-controls which are shared | |
12c62b9d | 186 | * between hardware blocks. |
0b52297f HG |
187 | * |
188 | * When a reset-control is shared, the behavior of reset_control_assert / | |
189 | * deassert is changed, the reset-core will keep track of a deassert_count | |
190 | * and only (re-)assert the reset after reset_control_assert has been called | |
191 | * as many times as reset_control_deassert was called. Also see the remark | |
192 | * about shared reset-controls in the reset_control_assert docs. | |
193 | * | |
194 | * Calling reset_control_assert without first calling reset_control_deassert | |
195 | * is not allowed on a shared reset control. Calling reset_control_reset is | |
196 | * also not allowed on a shared reset control. | |
197 | * | |
198 | * Use of id names is optional. | |
199 | */ | |
200 | static inline struct reset_control *reset_control_get_shared( | |
201 | struct device *dev, const char *id) | |
202 | { | |
c84b0326 | 203 | return __reset_control_get(dev, id, 0, true, false, false); |
0b52297f HG |
204 | } |
205 | ||
a53e35db | 206 | static inline struct reset_control *reset_control_get_optional_exclusive( |
3c35f6ed LJ |
207 | struct device *dev, const char *id) |
208 | { | |
c84b0326 | 209 | return __reset_control_get(dev, id, 0, false, true, true); |
3c35f6ed LJ |
210 | } |
211 | ||
c33d61a0 LJ |
212 | static inline struct reset_control *reset_control_get_optional_shared( |
213 | struct device *dev, const char *id) | |
214 | { | |
c84b0326 | 215 | return __reset_control_get(dev, id, 0, true, true, false); |
c33d61a0 LJ |
216 | } |
217 | ||
0b52297f | 218 | /** |
a53e35db LJ |
219 | * of_reset_control_get_exclusive - Lookup and obtain an exclusive reference |
220 | * to a reset controller. | |
6c96f05c HG |
221 | * @node: device to be reset by the controller |
222 | * @id: reset line name | |
223 | * | |
224 | * Returns a struct reset_control or IS_ERR() condition containing errno. | |
225 | * | |
226 | * Use of id names is optional. | |
227 | */ | |
a53e35db | 228 | static inline struct reset_control *of_reset_control_get_exclusive( |
e3ec0a8c HG |
229 | struct device_node *node, const char *id) |
230 | { | |
c84b0326 | 231 | return __of_reset_control_get(node, id, 0, false, false, true); |
e3ec0a8c HG |
232 | } |
233 | ||
6c96f05c | 234 | /** |
12c62b9d | 235 | * of_reset_control_get_shared - Lookup and obtain a shared reference |
40faee8e LJ |
236 | * to a reset controller. |
237 | * @node: device to be reset by the controller | |
238 | * @id: reset line name | |
239 | * | |
240 | * When a reset-control is shared, the behavior of reset_control_assert / | |
241 | * deassert is changed, the reset-core will keep track of a deassert_count | |
242 | * and only (re-)assert the reset after reset_control_assert has been called | |
243 | * as many times as reset_control_deassert was called. Also see the remark | |
244 | * about shared reset-controls in the reset_control_assert docs. | |
245 | * | |
246 | * Calling reset_control_assert without first calling reset_control_deassert | |
247 | * is not allowed on a shared reset control. Calling reset_control_reset is | |
248 | * also not allowed on a shared reset control. | |
249 | * Returns a struct reset_control or IS_ERR() condition containing errno. | |
250 | * | |
251 | * Use of id names is optional. | |
252 | */ | |
253 | static inline struct reset_control *of_reset_control_get_shared( | |
254 | struct device_node *node, const char *id) | |
255 | { | |
c84b0326 | 256 | return __of_reset_control_get(node, id, 0, true, false, false); |
40faee8e LJ |
257 | } |
258 | ||
6c96f05c | 259 | /** |
a53e35db LJ |
260 | * of_reset_control_get_exclusive_by_index - Lookup and obtain an exclusive |
261 | * reference to a reset controller | |
262 | * by index. | |
6c96f05c HG |
263 | * @node: device to be reset by the controller |
264 | * @index: index of the reset controller | |
265 | * | |
266 | * This is to be used to perform a list of resets for a device or power domain | |
267 | * in whatever order. Returns a struct reset_control or IS_ERR() condition | |
268 | * containing errno. | |
269 | */ | |
a53e35db | 270 | static inline struct reset_control *of_reset_control_get_exclusive_by_index( |
6c96f05c | 271 | struct device_node *node, int index) |
c0a13aa6 | 272 | { |
c84b0326 | 273 | return __of_reset_control_get(node, NULL, index, false, false, true); |
c0a13aa6 VH |
274 | } |
275 | ||
6c96f05c | 276 | /** |
12c62b9d | 277 | * of_reset_control_get_shared_by_index - Lookup and obtain a shared |
40faee8e LJ |
278 | * reference to a reset controller |
279 | * by index. | |
280 | * @node: device to be reset by the controller | |
281 | * @index: index of the reset controller | |
282 | * | |
283 | * When a reset-control is shared, the behavior of reset_control_assert / | |
284 | * deassert is changed, the reset-core will keep track of a deassert_count | |
285 | * and only (re-)assert the reset after reset_control_assert has been called | |
286 | * as many times as reset_control_deassert was called. Also see the remark | |
287 | * about shared reset-controls in the reset_control_assert docs. | |
288 | * | |
289 | * Calling reset_control_assert without first calling reset_control_deassert | |
290 | * is not allowed on a shared reset control. Calling reset_control_reset is | |
291 | * also not allowed on a shared reset control. | |
292 | * Returns a struct reset_control or IS_ERR() condition containing errno. | |
6c96f05c | 293 | * |
40faee8e LJ |
294 | * This is to be used to perform a list of resets for a device or power domain |
295 | * in whatever order. Returns a struct reset_control or IS_ERR() condition | |
296 | * containing errno. | |
6c96f05c | 297 | */ |
40faee8e LJ |
298 | static inline struct reset_control *of_reset_control_get_shared_by_index( |
299 | struct device_node *node, int index) | |
6c96f05c | 300 | { |
c84b0326 | 301 | return __of_reset_control_get(node, NULL, index, true, false, false); |
6c96f05c HG |
302 | } |
303 | ||
304 | /** | |
a53e35db LJ |
305 | * devm_reset_control_get_exclusive - resource managed |
306 | * reset_control_get_exclusive() | |
6c96f05c | 307 | * @dev: device to be reset by the controller |
6c96f05c | 308 | * @id: reset line name |
6c96f05c | 309 | * |
a53e35db LJ |
310 | * Managed reset_control_get_exclusive(). For reset controllers returned |
311 | * from this function, reset_control_put() is called automatically on driver | |
312 | * detach. | |
313 | * | |
314 | * See reset_control_get_exclusive() for more information. | |
6c96f05c | 315 | */ |
a53e35db LJ |
316 | static inline struct reset_control * |
317 | __must_check devm_reset_control_get_exclusive(struct device *dev, | |
318 | const char *id) | |
6c96f05c | 319 | { |
c84b0326 PZ |
320 | return __devm_reset_control_get(dev, id, 0, false, false, true); |
321 | } | |
322 | ||
323 | /** | |
324 | * devm_reset_control_get_exclusive_released - resource managed | |
325 | * reset_control_get_exclusive_released() | |
326 | * @dev: device to be reset by the controller | |
327 | * @id: reset line name | |
328 | * | |
329 | * Managed reset_control_get_exclusive_released(). For reset controllers | |
330 | * returned from this function, reset_control_put() is called automatically on | |
331 | * driver detach. | |
332 | * | |
333 | * See reset_control_get_exclusive_released() for more information. | |
334 | */ | |
335 | static inline struct reset_control * | |
336 | __must_check devm_reset_control_get_exclusive_released(struct device *dev, | |
337 | const char *id) | |
338 | { | |
339 | return __devm_reset_control_get(dev, id, 0, false, false, false); | |
0b52297f HG |
340 | } |
341 | ||
342 | /** | |
343 | * devm_reset_control_get_shared - resource managed reset_control_get_shared() | |
344 | * @dev: device to be reset by the controller | |
345 | * @id: reset line name | |
346 | * | |
347 | * Managed reset_control_get_shared(). For reset controllers returned from | |
348 | * this function, reset_control_put() is called automatically on driver detach. | |
349 | * See reset_control_get_shared() for more information. | |
350 | */ | |
351 | static inline struct reset_control *devm_reset_control_get_shared( | |
352 | struct device *dev, const char *id) | |
353 | { | |
c84b0326 | 354 | return __devm_reset_control_get(dev, id, 0, true, false, false); |
0b52297f HG |
355 | } |
356 | ||
a53e35db | 357 | static inline struct reset_control *devm_reset_control_get_optional_exclusive( |
6c96f05c HG |
358 | struct device *dev, const char *id) |
359 | { | |
c84b0326 | 360 | return __devm_reset_control_get(dev, id, 0, false, true, true); |
6c96f05c HG |
361 | } |
362 | ||
c33d61a0 LJ |
363 | static inline struct reset_control *devm_reset_control_get_optional_shared( |
364 | struct device *dev, const char *id) | |
365 | { | |
c84b0326 | 366 | return __devm_reset_control_get(dev, id, 0, true, true, false); |
c33d61a0 LJ |
367 | } |
368 | ||
6c96f05c | 369 | /** |
a53e35db LJ |
370 | * devm_reset_control_get_exclusive_by_index - resource managed |
371 | * reset_control_get_exclusive() | |
6c96f05c HG |
372 | * @dev: device to be reset by the controller |
373 | * @index: index of the reset controller | |
374 | * | |
a53e35db LJ |
375 | * Managed reset_control_get_exclusive(). For reset controllers returned from |
376 | * this function, reset_control_put() is called automatically on driver | |
377 | * detach. | |
378 | * | |
379 | * See reset_control_get_exclusive() for more information. | |
6c96f05c | 380 | */ |
a53e35db LJ |
381 | static inline struct reset_control * |
382 | devm_reset_control_get_exclusive_by_index(struct device *dev, int index) | |
6c96f05c | 383 | { |
c84b0326 | 384 | return __devm_reset_control_get(dev, NULL, index, false, false, true); |
0b52297f HG |
385 | } |
386 | ||
0b52297f HG |
387 | /** |
388 | * devm_reset_control_get_shared_by_index - resource managed | |
12c62b9d | 389 | * reset_control_get_shared |
0b52297f HG |
390 | * @dev: device to be reset by the controller |
391 | * @index: index of the reset controller | |
392 | * | |
393 | * Managed reset_control_get_shared(). For reset controllers returned from | |
394 | * this function, reset_control_put() is called automatically on driver detach. | |
395 | * See reset_control_get_shared() for more information. | |
396 | */ | |
0bcc0eab LJ |
397 | static inline struct reset_control * |
398 | devm_reset_control_get_shared_by_index(struct device *dev, int index) | |
0b52297f | 399 | { |
c84b0326 | 400 | return __devm_reset_control_get(dev, NULL, index, true, false, false); |
6c96f05c | 401 | } |
61fc4131 | 402 | |
a53e35db LJ |
403 | /* |
404 | * TEMPORARY calls to use during transition: | |
405 | * | |
406 | * of_reset_control_get() => of_reset_control_get_exclusive() | |
407 | * | |
408 | * These inline function calls will be removed once all consumers | |
409 | * have been moved over to the new explicit API. | |
410 | */ | |
a53e35db LJ |
411 | static inline struct reset_control *of_reset_control_get( |
412 | struct device_node *node, const char *id) | |
413 | { | |
414 | return of_reset_control_get_exclusive(node, id); | |
415 | } | |
416 | ||
417 | static inline struct reset_control *of_reset_control_get_by_index( | |
418 | struct device_node *node, int index) | |
419 | { | |
420 | return of_reset_control_get_exclusive_by_index(node, index); | |
421 | } | |
422 | ||
423 | static inline struct reset_control *devm_reset_control_get( | |
424 | struct device *dev, const char *id) | |
425 | { | |
426 | return devm_reset_control_get_exclusive(dev, id); | |
427 | } | |
428 | ||
429 | static inline struct reset_control *devm_reset_control_get_optional( | |
430 | struct device *dev, const char *id) | |
431 | { | |
432 | return devm_reset_control_get_optional_exclusive(dev, id); | |
433 | ||
434 | } | |
435 | ||
436 | static inline struct reset_control *devm_reset_control_get_by_index( | |
437 | struct device *dev, int index) | |
438 | { | |
439 | return devm_reset_control_get_exclusive_by_index(dev, index); | |
440 | } | |
17c82e20 VG |
441 | |
442 | /* | |
443 | * APIs to manage a list of reset controllers | |
444 | */ | |
445 | static inline struct reset_control * | |
446 | devm_reset_control_array_get_exclusive(struct device *dev) | |
447 | { | |
448 | return devm_reset_control_array_get(dev, false, false); | |
449 | } | |
450 | ||
451 | static inline struct reset_control * | |
452 | devm_reset_control_array_get_shared(struct device *dev) | |
453 | { | |
454 | return devm_reset_control_array_get(dev, true, false); | |
455 | } | |
456 | ||
457 | static inline struct reset_control * | |
458 | devm_reset_control_array_get_optional_exclusive(struct device *dev) | |
459 | { | |
460 | return devm_reset_control_array_get(dev, false, true); | |
461 | } | |
462 | ||
463 | static inline struct reset_control * | |
464 | devm_reset_control_array_get_optional_shared(struct device *dev) | |
465 | { | |
466 | return devm_reset_control_array_get(dev, true, true); | |
467 | } | |
468 | ||
469 | static inline struct reset_control * | |
470 | of_reset_control_array_get_exclusive(struct device_node *node) | |
471 | { | |
f31d5c24 | 472 | return of_reset_control_array_get(node, false, false, true); |
17c82e20 VG |
473 | } |
474 | ||
22815f18 TR |
475 | static inline struct reset_control * |
476 | of_reset_control_array_get_exclusive_released(struct device_node *node) | |
477 | { | |
478 | return of_reset_control_array_get(node, false, false, false); | |
479 | } | |
480 | ||
17c82e20 VG |
481 | static inline struct reset_control * |
482 | of_reset_control_array_get_shared(struct device_node *node) | |
483 | { | |
f31d5c24 | 484 | return of_reset_control_array_get(node, true, false, true); |
17c82e20 VG |
485 | } |
486 | ||
487 | static inline struct reset_control * | |
488 | of_reset_control_array_get_optional_exclusive(struct device_node *node) | |
489 | { | |
f31d5c24 | 490 | return of_reset_control_array_get(node, false, true, true); |
17c82e20 VG |
491 | } |
492 | ||
493 | static inline struct reset_control * | |
494 | of_reset_control_array_get_optional_shared(struct device_node *node) | |
495 | { | |
f31d5c24 | 496 | return of_reset_control_array_get(node, true, true, true); |
17c82e20 | 497 | } |
61fc4131 | 498 | #endif |