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