blob: 96fb139bdd08fdec3ad83e689ad2808375473126 [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 Zabel61fc4132012-11-19 17:23:13 +010018void reset_control_put(struct reset_control *rstc);
Hans de Goede6c96f052016-02-23 18:46:24 +010019struct reset_control *__devm_reset_control_get(struct device *dev,
Ramiro Oliveiraca58e3b2017-01-13 17:57:41 +000020 const char *id, int index, bool shared,
21 bool optional);
Philipp Zabel61fc4132012-11-19 17:23:13 +010022
Philipp Zabelb4240802014-03-07 15:18:47 +010023int __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
Philipp Zabelb4240802014-03-07 15:18:47 +010030#else
31
32static inline int reset_control_reset(struct reset_control *rstc)
33{
Philipp Zabelb4240802014-03-07 15:18:47 +010034 return 0;
35}
36
37static inline int reset_control_assert(struct reset_control *rstc)
38{
Philipp Zabelb4240802014-03-07 15:18:47 +010039 return 0;
40}
41
42static inline int reset_control_deassert(struct reset_control *rstc)
43{
Philipp Zabelb4240802014-03-07 15:18:47 +010044 return 0;
45}
46
Dinh Nguyen729de412014-10-10 10:21:14 -050047static inline int reset_control_status(struct reset_control *rstc)
48{
Dinh Nguyen729de412014-10-10 10:21:14 -050049 return 0;
50}
51
Philipp Zabelb4240802014-03-07 15:18:47 +010052static inline void reset_control_put(struct reset_control *rstc)
53{
Philipp Zabelb4240802014-03-07 15:18:47 +010054}
55
Daniel Lezcano41136522016-04-01 21:38:16 +020056static inline int __must_check device_reset(struct device *dev)
57{
58 WARN_ON(1);
59 return -ENOTSUPP;
60}
61
Philipp Zabelb4240802014-03-07 15:18:47 +010062static inline int device_reset_optional(struct device *dev)
63{
Philipp Zabel39b4da72015-10-29 09:55:00 +010064 return -ENOTSUPP;
Philipp Zabelb4240802014-03-07 15:18:47 +010065}
66
Hans de Goede6c96f052016-02-23 18:46:24 +010067static inline struct reset_control *__of_reset_control_get(
68 struct device_node *node,
Ramiro Oliveiraca58e3b2017-01-13 17:57:41 +000069 const char *id, int index, bool shared,
70 bool optional)
Axel Lin5bcd0b72015-09-01 07:56:38 +080071{
Philipp Zabel7be26002017-03-20 11:25:16 +010072 return optional ? NULL : ERR_PTR(-ENOTSUPP);
Axel Lin5bcd0b72015-09-01 07:56:38 +080073}
74
Hans de Goede6c96f052016-02-23 18:46:24 +010075static inline struct reset_control *__devm_reset_control_get(
Ramiro Oliveiraca58e3b2017-01-13 17:57:41 +000076 struct device *dev, const char *id,
77 int index, bool shared, bool optional)
Hans de Goede6c96f052016-02-23 18:46:24 +010078{
Philipp Zabel7be26002017-03-20 11:25:16 +010079 return optional ? NULL : ERR_PTR(-ENOTSUPP);
Hans de Goede6c96f052016-02-23 18:46:24 +010080}
81
82#endif /* CONFIG_RESET_CONTROLLER */
83
84/**
Lee Jonesa53e35d2016-06-06 16:56:50 +010085 * reset_control_get_exclusive - Lookup and obtain an exclusive reference
86 * to a reset controller.
Hans de Goede6c96f052016-02-23 18:46:24 +010087 * @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.
Hans de Goede0b522972016-02-23 18:46:26 +010091 * 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.
Hans de Goede6c96f052016-02-23 18:46:24 +010096 *
97 * Use of id names is optional.
98 */
Lee Jonesa53e35d2016-06-06 16:56:50 +010099static inline struct reset_control *
100__must_check reset_control_get_exclusive(struct device *dev, const char *id)
Axel Lin5bcd0b72015-09-01 07:56:38 +0800101{
Hans de Goede6c96f052016-02-23 18:46:24 +0100102#ifndef CONFIG_RESET_CONTROLLER
Axel Lin5bcd0b72015-09-01 07:56:38 +0800103 WARN_ON(1);
Hans de Goede6c96f052016-02-23 18:46:24 +0100104#endif
Ramiro Oliveiraca58e3b2017-01-13 17:57:41 +0000105 return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, false,
106 false);
Axel Lin5bcd0b72015-09-01 07:56:38 +0800107}
108
Hans de Goede6c96f052016-02-23 18:46:24 +0100109/**
Hans de Goede0b522972016-02-23 18:46:26 +0100110 * 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 */
131static inline struct reset_control *reset_control_get_shared(
132 struct device *dev, const char *id)
133{
Ramiro Oliveiraca58e3b2017-01-13 17:57:41 +0000134 return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, true,
135 false);
Hans de Goede0b522972016-02-23 18:46:26 +0100136}
137
Lee Jonesa53e35d2016-06-06 16:56:50 +0100138static inline struct reset_control *reset_control_get_optional_exclusive(
Lee Jones3c35f6e2016-06-06 16:56:49 +0100139 struct device *dev, const char *id)
140{
Ramiro Oliveiraca58e3b2017-01-13 17:57:41 +0000141 return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, false,
142 true);
Lee Jones3c35f6e2016-06-06 16:56:49 +0100143}
144
Lee Jonesc33d61a2016-06-06 16:56:52 +0100145static inline struct reset_control *reset_control_get_optional_shared(
146 struct device *dev, const char *id)
147{
Ramiro Oliveiraca58e3b2017-01-13 17:57:41 +0000148 return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, true,
149 true);
Lee Jonesc33d61a2016-06-06 16:56:52 +0100150}
151
Hans de Goede0b522972016-02-23 18:46:26 +0100152/**
Lee Jonesa53e35d2016-06-06 16:56:50 +0100153 * of_reset_control_get_exclusive - Lookup and obtain an exclusive reference
154 * to a reset controller.
Hans de Goede6c96f052016-02-23 18:46:24 +0100155 * @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 */
Lee Jonesa53e35d2016-06-06 16:56:50 +0100162static inline struct reset_control *of_reset_control_get_exclusive(
Hans de Goede6c96f052016-02-23 18:46:24 +0100163 struct device_node *node, const char *id)
164{
Ramiro Oliveiraca58e3b2017-01-13 17:57:41 +0000165 return __of_reset_control_get(node, id, 0, false, false);
Hans de Goede6c96f052016-02-23 18:46:24 +0100166}
167
168/**
Lee Jones40faee82016-06-06 16:56:51 +0100169 * 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 */
187static inline struct reset_control *of_reset_control_get_shared(
188 struct device_node *node, const char *id)
189{
Ramiro Oliveiraca58e3b2017-01-13 17:57:41 +0000190 return __of_reset_control_get(node, id, 0, true, false);
Lee Jones40faee82016-06-06 16:56:51 +0100191}
192
193/**
Lee Jonesa53e35d2016-06-06 16:56:50 +0100194 * of_reset_control_get_exclusive_by_index - Lookup and obtain an exclusive
195 * reference to a reset controller
196 * by index.
Hans de Goede6c96f052016-02-23 18:46:24 +0100197 * @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 */
Lee Jonesa53e35d2016-06-06 16:56:50 +0100204static inline struct reset_control *of_reset_control_get_exclusive_by_index(
Hans de Goede6c96f052016-02-23 18:46:24 +0100205 struct device_node *node, int index)
206{
Ramiro Oliveiraca58e3b2017-01-13 17:57:41 +0000207 return __of_reset_control_get(node, NULL, index, false, false);
Hans de Goede6c96f052016-02-23 18:46:24 +0100208}
209
210/**
Lee Jones40faee82016-06-06 16:56:51 +0100211 * 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.
227 *
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.
231 */
232static inline struct reset_control *of_reset_control_get_shared_by_index(
233 struct device_node *node, int index)
234{
Ramiro Oliveiraca58e3b2017-01-13 17:57:41 +0000235 return __of_reset_control_get(node, NULL, index, true, false);
Lee Jones40faee82016-06-06 16:56:51 +0100236}
237
238/**
Lee Jonesa53e35d2016-06-06 16:56:50 +0100239 * devm_reset_control_get_exclusive - resource managed
240 * reset_control_get_exclusive()
Hans de Goede6c96f052016-02-23 18:46:24 +0100241 * @dev: device to be reset by the controller
242 * @id: reset line name
243 *
Lee Jonesa53e35d2016-06-06 16:56:50 +0100244 * 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.
Hans de Goede6c96f052016-02-23 18:46:24 +0100249 */
Lee Jonesa53e35d2016-06-06 16:56:50 +0100250static inline struct reset_control *
251__must_check devm_reset_control_get_exclusive(struct device *dev,
252 const char *id)
Hans de Goede6c96f052016-02-23 18:46:24 +0100253{
254#ifndef CONFIG_RESET_CONTROLLER
255 WARN_ON(1);
256#endif
Ramiro Oliveiraca58e3b2017-01-13 17:57:41 +0000257 return __devm_reset_control_get(dev, id, 0, false, false);
Philipp Zabelb4240802014-03-07 15:18:47 +0100258}
259
Hans de Goede0b522972016-02-23 18:46:26 +0100260/**
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 */
269static inline struct reset_control *devm_reset_control_get_shared(
270 struct device *dev, const char *id)
271{
Ramiro Oliveiraca58e3b2017-01-13 17:57:41 +0000272 return __devm_reset_control_get(dev, id, 0, true, false);
Hans de Goede0b522972016-02-23 18:46:26 +0100273}
274
Lee Jonesa53e35d2016-06-06 16:56:50 +0100275static inline struct reset_control *devm_reset_control_get_optional_exclusive(
Philipp Zabelb4240802014-03-07 15:18:47 +0100276 struct device *dev, const char *id)
277{
Ramiro Oliveiraca58e3b2017-01-13 17:57:41 +0000278 return __devm_reset_control_get(dev, id, 0, false, true);
Philipp Zabelb4240802014-03-07 15:18:47 +0100279}
280
Lee Jonesc33d61a2016-06-06 16:56:52 +0100281static inline struct reset_control *devm_reset_control_get_optional_shared(
282 struct device *dev, const char *id)
283{
Ramiro Oliveiraca58e3b2017-01-13 17:57:41 +0000284 return __devm_reset_control_get(dev, id, 0, true, true);
Lee Jonesc33d61a2016-06-06 16:56:52 +0100285}
286
Hans de Goede6c96f052016-02-23 18:46:24 +0100287/**
Lee Jonesa53e35d2016-06-06 16:56:50 +0100288 * devm_reset_control_get_exclusive_by_index - resource managed
289 * reset_control_get_exclusive()
Hans de Goede6c96f052016-02-23 18:46:24 +0100290 * @dev: device to be reset by the controller
291 * @index: index of the reset controller
292 *
Lee Jonesa53e35d2016-06-06 16:56:50 +0100293 * 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.
Hans de Goede6c96f052016-02-23 18:46:24 +0100298 */
Lee Jonesa53e35d2016-06-06 16:56:50 +0100299static inline struct reset_control *
300devm_reset_control_get_exclusive_by_index(struct device *dev, int index)
Hans de Goedee3ec0a82014-04-13 14:09:15 +0200301{
Ramiro Oliveiraca58e3b2017-01-13 17:57:41 +0000302 return __devm_reset_control_get(dev, NULL, index, false, false);
Hans de Goede0b522972016-02-23 18:46:26 +0100303}
304
Hans de Goede0b522972016-02-23 18:46:26 +0100305/**
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 */
Lee Jones0bcc0ea2016-06-06 16:56:53 +0100315static inline struct reset_control *
316devm_reset_control_get_shared_by_index(struct device *dev, int index)
Hans de Goede0b522972016-02-23 18:46:26 +0100317{
Ramiro Oliveiraca58e3b2017-01-13 17:57:41 +0000318 return __devm_reset_control_get(dev, NULL, index, true, false);
Hans de Goedee3ec0a82014-04-13 14:09:15 +0200319}
320
Lee Jonesa53e35d2016-06-06 16:56:50 +0100321/*
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 */
329static 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
335static 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
341static 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
347static 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
353static 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
359static 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
366static 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}
Philipp Zabel61fc4132012-11-19 17:23:13 +0100371#endif