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