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