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