blob: 7e99690dbc81c91165252ee1a7cfc52dafcfb33f [file] [log] [blame]
Philipp Zabel61fc4132012-11-19 17:23:13 +01001#ifndef _LINUX_RESET_H_
2#define _LINUX_RESET_H_
3
Hans de Goede6c96f052016-02-23 18:46:24 +01004#include <linux/device.h>
5
Philipp Zabel61fc4132012-11-19 17:23:13 +01006struct reset_control;
7
Philipp Zabelb4240802014-03-07 15:18:47 +01008#ifdef CONFIG_RESET_CONTROLLER
9
Philipp Zabel61fc4132012-11-19 17:23:13 +010010int reset_control_reset(struct reset_control *rstc);
11int reset_control_assert(struct reset_control *rstc);
12int reset_control_deassert(struct reset_control *rstc);
Dinh Nguyen729de412014-10-10 10:21:14 -050013int reset_control_status(struct reset_control *rstc);
Philipp Zabel61fc4132012-11-19 17:23:13 +010014
Hans de Goede6c96f052016-02-23 18:46:24 +010015struct reset_control *__of_reset_control_get(struct device_node *node,
Ramiro Oliveiraca58e3b2017-01-13 17:57:41 +000016 const char *id, int index, bool shared,
17 bool optional);
Philipp Zabelee6e7fb2016-02-05 13:41:39 +010018struct reset_control *__reset_control_get(struct device *dev, const char *id,
19 int index, bool shared,
20 bool optional);
Philipp Zabel61fc4132012-11-19 17:23:13 +010021void reset_control_put(struct reset_control *rstc);
Masahiro Yamadaf109deb2017-10-29 01:50:06 +090022int __device_reset(struct device *dev, bool optional);
Hans de Goede6c96f052016-02-23 18:46:24 +010023struct reset_control *__devm_reset_control_get(struct device *dev,
Ramiro Oliveiraca58e3b2017-01-13 17:57:41 +000024 const char *id, int index, bool shared,
25 bool optional);
Philipp Zabel61fc4132012-11-19 17:23:13 +010026
Philipp Zabelb4240802014-03-07 15:18:47 +010027#else
28
29static inline int reset_control_reset(struct reset_control *rstc)
30{
Philipp Zabelb4240802014-03-07 15:18:47 +010031 return 0;
32}
33
34static inline int reset_control_assert(struct reset_control *rstc)
35{
Philipp Zabelb4240802014-03-07 15:18:47 +010036 return 0;
37}
38
39static inline int reset_control_deassert(struct reset_control *rstc)
40{
Philipp Zabelb4240802014-03-07 15:18:47 +010041 return 0;
42}
43
Dinh Nguyen729de412014-10-10 10:21:14 -050044static inline int reset_control_status(struct reset_control *rstc)
45{
Dinh Nguyen729de412014-10-10 10:21:14 -050046 return 0;
47}
48
Philipp Zabelb4240802014-03-07 15:18:47 +010049static inline void reset_control_put(struct reset_control *rstc)
50{
Philipp Zabelb4240802014-03-07 15:18:47 +010051}
52
Masahiro Yamadaf109deb2017-10-29 01:50:06 +090053static inline int __device_reset(struct device *dev, bool optional)
Daniel Lezcano41136522016-04-01 21:38:16 +020054{
Masahiro Yamadaf109deb2017-10-29 01:50:06 +090055 return optional ? 0 : -ENOTSUPP;
Philipp Zabelb4240802014-03-07 15:18:47 +010056}
57
Hans de Goede6c96f052016-02-23 18:46:24 +010058static inline struct reset_control *__of_reset_control_get(
59 struct device_node *node,
Ramiro Oliveiraca58e3b2017-01-13 17:57:41 +000060 const char *id, int index, bool shared,
61 bool optional)
Axel Lin5bcd0b72015-09-01 07:56:38 +080062{
Philipp Zabel7be26002017-03-20 11:25:16 +010063 return optional ? NULL : ERR_PTR(-ENOTSUPP);
Axel Lin5bcd0b72015-09-01 07:56:38 +080064}
65
Philipp Zabelee6e7fb2016-02-05 13:41:39 +010066static inline struct reset_control *__reset_control_get(
67 struct device *dev, const char *id,
68 int index, bool shared, bool optional)
69{
70 return optional ? NULL : ERR_PTR(-ENOTSUPP);
71}
72
Hans de Goede6c96f052016-02-23 18:46:24 +010073static inline struct reset_control *__devm_reset_control_get(
Ramiro Oliveiraca58e3b2017-01-13 17:57:41 +000074 struct device *dev, const char *id,
75 int index, bool shared, bool optional)
Hans de Goede6c96f052016-02-23 18:46:24 +010076{
Philipp Zabel7be26002017-03-20 11:25:16 +010077 return optional ? NULL : ERR_PTR(-ENOTSUPP);
Hans de Goede6c96f052016-02-23 18:46:24 +010078}
79
80#endif /* CONFIG_RESET_CONTROLLER */
81
Masahiro Yamadaf109deb2017-10-29 01:50:06 +090082static inline int __must_check device_reset(struct device *dev)
83{
84 return __device_reset(dev, false);
85}
86
87static inline int device_reset_optional(struct device *dev)
88{
89 return __device_reset(dev, true);
90}
91
Hans de Goede6c96f052016-02-23 18:46:24 +010092/**
Lee Jonesa53e35d2016-06-06 16:56:50 +010093 * reset_control_get_exclusive - Lookup and obtain an exclusive reference
94 * to a reset controller.
Hans de Goede6c96f052016-02-23 18:46:24 +010095 * @dev: device to be reset by the controller
96 * @id: reset line name
97 *
98 * Returns a struct reset_control or IS_ERR() condition containing errno.
Hans de Goede0b522972016-02-23 18:46:26 +010099 * If this function is called more then once for the same reset_control it will
100 * return -EBUSY.
101 *
102 * See reset_control_get_shared for details on shared references to
103 * reset-controls.
Hans de Goede6c96f052016-02-23 18:46:24 +0100104 *
105 * Use of id names is optional.
106 */
Lee Jonesa53e35d2016-06-06 16:56:50 +0100107static inline struct reset_control *
108__must_check reset_control_get_exclusive(struct device *dev, const char *id)
Axel Lin5bcd0b72015-09-01 07:56:38 +0800109{
Philipp Zabelee6e7fb2016-02-05 13:41:39 +0100110 return __reset_control_get(dev, id, 0, false, false);
Axel Lin5bcd0b72015-09-01 07:56:38 +0800111}
112
Hans de Goede6c96f052016-02-23 18:46:24 +0100113/**
Hans de Goede0b522972016-02-23 18:46:26 +0100114 * reset_control_get_shared - Lookup and obtain a shared reference to a
115 * reset controller.
116 * @dev: device to be reset by the controller
117 * @id: reset line name
118 *
119 * Returns a struct reset_control or IS_ERR() condition containing errno.
120 * This function is intended for use with reset-controls which are shared
121 * between hardware-blocks.
122 *
123 * When a reset-control is shared, the behavior of reset_control_assert /
124 * deassert is changed, the reset-core will keep track of a deassert_count
125 * and only (re-)assert the reset after reset_control_assert has been called
126 * as many times as reset_control_deassert was called. Also see the remark
127 * about shared reset-controls in the reset_control_assert docs.
128 *
129 * Calling reset_control_assert without first calling reset_control_deassert
130 * is not allowed on a shared reset control. Calling reset_control_reset is
131 * also not allowed on a shared reset control.
132 *
133 * Use of id names is optional.
134 */
135static inline struct reset_control *reset_control_get_shared(
136 struct device *dev, const char *id)
137{
Philipp Zabelee6e7fb2016-02-05 13:41:39 +0100138 return __reset_control_get(dev, id, 0, true, false);
Hans de Goede0b522972016-02-23 18:46:26 +0100139}
140
Lee Jonesa53e35d2016-06-06 16:56:50 +0100141static inline struct reset_control *reset_control_get_optional_exclusive(
Lee Jones3c35f6e2016-06-06 16:56:49 +0100142 struct device *dev, const char *id)
143{
Philipp Zabelee6e7fb2016-02-05 13:41:39 +0100144 return __reset_control_get(dev, id, 0, false, true);
Lee Jones3c35f6e2016-06-06 16:56:49 +0100145}
146
Lee Jonesc33d61a2016-06-06 16:56:52 +0100147static inline struct reset_control *reset_control_get_optional_shared(
148 struct device *dev, const char *id)
149{
Philipp Zabelee6e7fb2016-02-05 13:41:39 +0100150 return __reset_control_get(dev, id, 0, true, true);
Lee Jonesc33d61a2016-06-06 16:56:52 +0100151}
152
Hans de Goede0b522972016-02-23 18:46:26 +0100153/**
Lee Jonesa53e35d2016-06-06 16:56:50 +0100154 * of_reset_control_get_exclusive - Lookup and obtain an exclusive reference
155 * to a reset controller.
Hans de Goede6c96f052016-02-23 18:46:24 +0100156 * @node: device to be reset by the controller
157 * @id: reset line name
158 *
159 * Returns a struct reset_control or IS_ERR() condition containing errno.
160 *
161 * Use of id names is optional.
162 */
Lee Jonesa53e35d2016-06-06 16:56:50 +0100163static inline struct reset_control *of_reset_control_get_exclusive(
Hans de Goede6c96f052016-02-23 18:46:24 +0100164 struct device_node *node, const char *id)
165{
Ramiro Oliveiraca58e3b2017-01-13 17:57:41 +0000166 return __of_reset_control_get(node, id, 0, false, false);
Hans de Goede6c96f052016-02-23 18:46:24 +0100167}
168
169/**
Lee Jones40faee82016-06-06 16:56:51 +0100170 * of_reset_control_get_shared - Lookup and obtain an shared reference
171 * to a reset controller.
172 * @node: device to be reset by the controller
173 * @id: reset line name
174 *
175 * When a reset-control is shared, the behavior of reset_control_assert /
176 * deassert is changed, the reset-core will keep track of a deassert_count
177 * and only (re-)assert the reset after reset_control_assert has been called
178 * as many times as reset_control_deassert was called. Also see the remark
179 * about shared reset-controls in the reset_control_assert docs.
180 *
181 * Calling reset_control_assert without first calling reset_control_deassert
182 * is not allowed on a shared reset control. Calling reset_control_reset is
183 * also not allowed on a shared reset control.
184 * Returns a struct reset_control or IS_ERR() condition containing errno.
185 *
186 * Use of id names is optional.
187 */
188static inline struct reset_control *of_reset_control_get_shared(
189 struct device_node *node, const char *id)
190{
Ramiro Oliveiraca58e3b2017-01-13 17:57:41 +0000191 return __of_reset_control_get(node, id, 0, true, false);
Lee Jones40faee82016-06-06 16:56:51 +0100192}
193
194/**
Lee Jonesa53e35d2016-06-06 16:56:50 +0100195 * of_reset_control_get_exclusive_by_index - Lookup and obtain an exclusive
196 * reference to a reset controller
197 * by index.
Hans de Goede6c96f052016-02-23 18:46:24 +0100198 * @node: device to be reset by the controller
199 * @index: index of the reset controller
200 *
201 * This is to be used to perform a list of resets for a device or power domain
202 * in whatever order. Returns a struct reset_control or IS_ERR() condition
203 * containing errno.
204 */
Lee Jonesa53e35d2016-06-06 16:56:50 +0100205static inline struct reset_control *of_reset_control_get_exclusive_by_index(
Hans de Goede6c96f052016-02-23 18:46:24 +0100206 struct device_node *node, int index)
207{
Ramiro Oliveiraca58e3b2017-01-13 17:57:41 +0000208 return __of_reset_control_get(node, NULL, index, false, false);
Hans de Goede6c96f052016-02-23 18:46:24 +0100209}
210
211/**
Lee Jones40faee82016-06-06 16:56:51 +0100212 * of_reset_control_get_shared_by_index - Lookup and obtain an shared
213 * reference to a reset controller
214 * by index.
215 * @node: device to be reset by the controller
216 * @index: index of the reset controller
217 *
218 * When a reset-control is shared, the behavior of reset_control_assert /
219 * deassert is changed, the reset-core will keep track of a deassert_count
220 * and only (re-)assert the reset after reset_control_assert has been called
221 * as many times as reset_control_deassert was called. Also see the remark
222 * about shared reset-controls in the reset_control_assert docs.
223 *
224 * Calling reset_control_assert without first calling reset_control_deassert
225 * is not allowed on a shared reset control. Calling reset_control_reset is
226 * also not allowed on a shared reset control.
227 * Returns a struct reset_control or IS_ERR() condition containing errno.
228 *
229 * This is to be used to perform a list of resets for a device or power domain
230 * in whatever order. Returns a struct reset_control or IS_ERR() condition
231 * containing errno.
232 */
233static inline struct reset_control *of_reset_control_get_shared_by_index(
234 struct device_node *node, int index)
235{
Ramiro Oliveiraca58e3b2017-01-13 17:57:41 +0000236 return __of_reset_control_get(node, NULL, index, true, false);
Lee Jones40faee82016-06-06 16:56:51 +0100237}
238
239/**
Lee Jonesa53e35d2016-06-06 16:56:50 +0100240 * devm_reset_control_get_exclusive - resource managed
241 * reset_control_get_exclusive()
Hans de Goede6c96f052016-02-23 18:46:24 +0100242 * @dev: device to be reset by the controller
243 * @id: reset line name
244 *
Lee Jonesa53e35d2016-06-06 16:56:50 +0100245 * Managed reset_control_get_exclusive(). For reset controllers returned
246 * from this function, reset_control_put() is called automatically on driver
247 * detach.
248 *
249 * See reset_control_get_exclusive() for more information.
Hans de Goede6c96f052016-02-23 18:46:24 +0100250 */
Lee Jonesa53e35d2016-06-06 16:56:50 +0100251static inline struct reset_control *
252__must_check devm_reset_control_get_exclusive(struct device *dev,
253 const char *id)
Hans de Goede6c96f052016-02-23 18:46:24 +0100254{
Ramiro Oliveiraca58e3b2017-01-13 17:57:41 +0000255 return __devm_reset_control_get(dev, id, 0, false, false);
Philipp Zabelb4240802014-03-07 15:18:47 +0100256}
257
Hans de Goede0b522972016-02-23 18:46:26 +0100258/**
259 * devm_reset_control_get_shared - resource managed reset_control_get_shared()
260 * @dev: device to be reset by the controller
261 * @id: reset line name
262 *
263 * Managed reset_control_get_shared(). For reset controllers returned from
264 * this function, reset_control_put() is called automatically on driver detach.
265 * See reset_control_get_shared() for more information.
266 */
267static inline struct reset_control *devm_reset_control_get_shared(
268 struct device *dev, const char *id)
269{
Ramiro Oliveiraca58e3b2017-01-13 17:57:41 +0000270 return __devm_reset_control_get(dev, id, 0, true, false);
Hans de Goede0b522972016-02-23 18:46:26 +0100271}
272
Lee Jonesa53e35d2016-06-06 16:56:50 +0100273static inline struct reset_control *devm_reset_control_get_optional_exclusive(
Philipp Zabelb4240802014-03-07 15:18:47 +0100274 struct device *dev, const char *id)
275{
Ramiro Oliveiraca58e3b2017-01-13 17:57:41 +0000276 return __devm_reset_control_get(dev, id, 0, false, true);
Philipp Zabelb4240802014-03-07 15:18:47 +0100277}
278
Lee Jonesc33d61a2016-06-06 16:56:52 +0100279static inline struct reset_control *devm_reset_control_get_optional_shared(
280 struct device *dev, const char *id)
281{
Ramiro Oliveiraca58e3b2017-01-13 17:57:41 +0000282 return __devm_reset_control_get(dev, id, 0, true, true);
Lee Jonesc33d61a2016-06-06 16:56:52 +0100283}
284
Hans de Goede6c96f052016-02-23 18:46:24 +0100285/**
Lee Jonesa53e35d2016-06-06 16:56:50 +0100286 * devm_reset_control_get_exclusive_by_index - resource managed
287 * reset_control_get_exclusive()
Hans de Goede6c96f052016-02-23 18:46:24 +0100288 * @dev: device to be reset by the controller
289 * @index: index of the reset controller
290 *
Lee Jonesa53e35d2016-06-06 16:56:50 +0100291 * Managed reset_control_get_exclusive(). For reset controllers returned from
292 * this function, reset_control_put() is called automatically on driver
293 * detach.
294 *
295 * See reset_control_get_exclusive() for more information.
Hans de Goede6c96f052016-02-23 18:46:24 +0100296 */
Lee Jonesa53e35d2016-06-06 16:56:50 +0100297static inline struct reset_control *
298devm_reset_control_get_exclusive_by_index(struct device *dev, int index)
Hans de Goedee3ec0a82014-04-13 14:09:15 +0200299{
Ramiro Oliveiraca58e3b2017-01-13 17:57:41 +0000300 return __devm_reset_control_get(dev, NULL, index, false, false);
Hans de Goede0b522972016-02-23 18:46:26 +0100301}
302
Hans de Goede0b522972016-02-23 18:46:26 +0100303/**
304 * devm_reset_control_get_shared_by_index - resource managed
305 * reset_control_get_shared
306 * @dev: device to be reset by the controller
307 * @index: index of the reset controller
308 *
309 * Managed reset_control_get_shared(). For reset controllers returned from
310 * this function, reset_control_put() is called automatically on driver detach.
311 * See reset_control_get_shared() for more information.
312 */
Lee Jones0bcc0ea2016-06-06 16:56:53 +0100313static inline struct reset_control *
314devm_reset_control_get_shared_by_index(struct device *dev, int index)
Hans de Goede0b522972016-02-23 18:46:26 +0100315{
Ramiro Oliveiraca58e3b2017-01-13 17:57:41 +0000316 return __devm_reset_control_get(dev, NULL, index, true, false);
Hans de Goedee3ec0a82014-04-13 14:09:15 +0200317}
318
Lee Jonesa53e35d2016-06-06 16:56:50 +0100319/*
320 * TEMPORARY calls to use during transition:
321 *
322 * of_reset_control_get() => of_reset_control_get_exclusive()
323 *
324 * These inline function calls will be removed once all consumers
325 * have been moved over to the new explicit API.
326 */
327static inline struct reset_control *reset_control_get(
328 struct device *dev, const char *id)
329{
330 return reset_control_get_exclusive(dev, id);
331}
332
333static inline struct reset_control *reset_control_get_optional(
334 struct device *dev, const char *id)
335{
336 return reset_control_get_optional_exclusive(dev, id);
337}
338
339static inline struct reset_control *of_reset_control_get(
340 struct device_node *node, const char *id)
341{
342 return of_reset_control_get_exclusive(node, id);
343}
344
345static inline struct reset_control *of_reset_control_get_by_index(
346 struct device_node *node, int index)
347{
348 return of_reset_control_get_exclusive_by_index(node, index);
349}
350
351static inline struct reset_control *devm_reset_control_get(
352 struct device *dev, const char *id)
353{
354 return devm_reset_control_get_exclusive(dev, id);
355}
356
357static inline struct reset_control *devm_reset_control_get_optional(
358 struct device *dev, const char *id)
359{
360 return devm_reset_control_get_optional_exclusive(dev, id);
361
362}
363
364static inline struct reset_control *devm_reset_control_get_by_index(
365 struct device *dev, int index)
366{
367 return devm_reset_control_get_exclusive_by_index(dev, index);
368}
Philipp Zabel61fc4132012-11-19 17:23:13 +0100369#endif