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