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