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