Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1#ifndef _LINUX_RESET_H_
2#define _LINUX_RESET_H_
3
4#include <linux/device.h>
5
6struct reset_control;
7
8#ifdef CONFIG_RESET_CONTROLLER
9
10int reset_control_reset(struct reset_control *rstc);
11int reset_control_assert(struct reset_control *rstc);
12int reset_control_deassert(struct reset_control *rstc);
13int reset_control_status(struct reset_control *rstc);
14
15struct reset_control *__of_reset_control_get(struct device_node *node,
16 const char *id, int index, bool shared,
17 bool optional);
18void reset_control_put(struct reset_control *rstc);
19struct reset_control *__devm_reset_control_get(struct device *dev,
20 const char *id, int index, bool shared,
21 bool optional);
22
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
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
50static inline int reset_control_status(struct reset_control *rstc)
51{
52 WARN_ON(1);
53 return 0;
54}
55
56static inline void reset_control_put(struct reset_control *rstc)
57{
58 WARN_ON(1);
59}
60
61static inline int __must_check device_reset(struct device *dev)
62{
63 WARN_ON(1);
64 return -ENOTSUPP;
65}
66
67static inline int device_reset_optional(struct device *dev)
68{
69 return -ENOTSUPP;
70}
71
72static inline struct reset_control *__of_reset_control_get(
73 struct device_node *node,
74 const char *id, int index, bool shared,
75 bool optional)
76{
77 return ERR_PTR(-ENOTSUPP);
78}
79
80static inline struct reset_control *__devm_reset_control_get(
81 struct device *dev, const char *id,
82 int index, bool shared, bool optional)
83{
84 return ERR_PTR(-ENOTSUPP);
85}
86
87#endif /* CONFIG_RESET_CONTROLLER */
88
89/**
90 * reset_control_get_exclusive - Lookup and obtain an exclusive reference
91 * to a reset controller.
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.
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.
101 *
102 * Use of id names is optional.
103 */
104static inline struct reset_control *
105__must_check reset_control_get_exclusive(struct device *dev, const char *id)
106{
107#ifndef CONFIG_RESET_CONTROLLER
108 WARN_ON(1);
109#endif
110 return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, false,
111 false);
112}
113
114/**
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{
139 return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, true,
140 false);
141}
142
143static inline struct reset_control *reset_control_get_optional_exclusive(
144 struct device *dev, const char *id)
145{
146 return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, false,
147 true);
148}
149
150static inline struct reset_control *reset_control_get_optional_shared(
151 struct device *dev, const char *id)
152{
153 return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, true,
154 true);
155}
156
157/**
158 * of_reset_control_get_exclusive - Lookup and obtain an exclusive reference
159 * to a reset controller.
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 */
167static inline struct reset_control *of_reset_control_get_exclusive(
168 struct device_node *node, const char *id)
169{
170 return __of_reset_control_get(node, id, 0, false, false);
171}
172
173/**
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{
195 return __of_reset_control_get(node, id, 0, true, false);
196}
197
198/**
199 * of_reset_control_get_exclusive_by_index - Lookup and obtain an exclusive
200 * reference to a reset controller
201 * by index.
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 */
209static inline struct reset_control *of_reset_control_get_exclusive_by_index(
210 struct device_node *node, int index)
211{
212 return __of_reset_control_get(node, NULL, index, false, false);
213}
214
215/**
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.
232 *
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.
236 */
237static inline struct reset_control *of_reset_control_get_shared_by_index(
238 struct device_node *node, int index)
239{
240 return __of_reset_control_get(node, NULL, index, true, false);
241}
242
243/**
244 * devm_reset_control_get_exclusive - resource managed
245 * reset_control_get_exclusive()
246 * @dev: device to be reset by the controller
247 * @id: reset line name
248 *
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.
254 */
255static inline struct reset_control *
256__must_check devm_reset_control_get_exclusive(struct device *dev,
257 const char *id)
258{
259#ifndef CONFIG_RESET_CONTROLLER
260 WARN_ON(1);
261#endif
262 return __devm_reset_control_get(dev, id, 0, false, false);
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{
277 return __devm_reset_control_get(dev, id, 0, true, false);
278}
279
280static inline struct reset_control *devm_reset_control_get_optional_exclusive(
281 struct device *dev, const char *id)
282{
283 return __devm_reset_control_get(dev, id, 0, false, true);
284}
285
286static inline struct reset_control *devm_reset_control_get_optional_shared(
287 struct device *dev, const char *id)
288{
289 return __devm_reset_control_get(dev, id, 0, true, true);
290}
291
292/**
293 * devm_reset_control_get_exclusive_by_index - resource managed
294 * reset_control_get_exclusive()
295 * @dev: device to be reset by the controller
296 * @index: index of the reset controller
297 *
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.
303 */
304static inline struct reset_control *
305devm_reset_control_get_exclusive_by_index(struct device *dev, int index)
306{
307 return __devm_reset_control_get(dev, NULL, index, false, false);
308}
309
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 */
320static inline struct reset_control *
321devm_reset_control_get_shared_by_index(struct device *dev, int index)
322{
323 return __devm_reset_control_get(dev, NULL, index, true, false);
324}
325
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}
376#endif