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