blob: 56463f37f3e67ec03e0f594a331bf62eb2d70722 [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 Oliveirabb475232017-01-13 17:57:41 +000016 const char *id, int index, bool shared,
17 bool optional);
Philipp Zabel62e24c52016-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);
Hans de Goede6c96f052016-02-23 18:46:24 +010022struct reset_control *__devm_reset_control_get(struct device *dev,
Ramiro Oliveirabb475232017-01-13 17:57:41 +000023 const char *id, int index, bool shared,
24 bool optional);
Philipp Zabel61fc4132012-11-19 17:23:13 +010025
Philipp Zabelb4240802014-03-07 15:18:47 +010026int __must_check device_reset(struct device *dev);
27
Vivek Gautam17c82e22017-05-22 16:53:25 +053028struct reset_control *devm_reset_control_array_get(struct device *dev,
29 bool shared, bool optional);
30struct reset_control *of_reset_control_array_get(struct device_node *np,
31 bool shared, bool optional);
32
Philipp Zabelb4240802014-03-07 15:18:47 +010033static inline int device_reset_optional(struct device *dev)
34{
35 return device_reset(dev);
36}
37
Philipp Zabelb4240802014-03-07 15:18:47 +010038#else
39
40static inline int reset_control_reset(struct reset_control *rstc)
41{
Philipp Zabelb4240802014-03-07 15:18:47 +010042 return 0;
43}
44
45static inline int reset_control_assert(struct reset_control *rstc)
46{
Philipp Zabelb4240802014-03-07 15:18:47 +010047 return 0;
48}
49
50static inline int reset_control_deassert(struct reset_control *rstc)
51{
Philipp Zabelb4240802014-03-07 15:18:47 +010052 return 0;
53}
54
Dinh Nguyen729de412014-10-10 10:21:14 -050055static inline int reset_control_status(struct reset_control *rstc)
56{
Dinh Nguyen729de412014-10-10 10:21:14 -050057 return 0;
58}
59
Philipp Zabelb4240802014-03-07 15:18:47 +010060static inline void reset_control_put(struct reset_control *rstc)
61{
Philipp Zabelb4240802014-03-07 15:18:47 +010062}
63
Daniel Lezcano41136522016-04-01 21:38:16 +020064static inline int __must_check device_reset(struct device *dev)
65{
66 WARN_ON(1);
67 return -ENOTSUPP;
68}
69
Philipp Zabelb4240802014-03-07 15:18:47 +010070static inline int device_reset_optional(struct device *dev)
71{
Philipp Zabel39b4da72015-10-29 09:55:00 +010072 return -ENOTSUPP;
Philipp Zabelb4240802014-03-07 15:18:47 +010073}
74
Hans de Goede6c96f052016-02-23 18:46:24 +010075static inline struct reset_control *__of_reset_control_get(
76 struct device_node *node,
Ramiro Oliveirabb475232017-01-13 17:57:41 +000077 const char *id, int index, bool shared,
78 bool optional)
Axel Lin5bcd0b72015-09-01 07:56:38 +080079{
Philipp Zabel0ca10b62017-03-20 11:25:16 +010080 return optional ? NULL : ERR_PTR(-ENOTSUPP);
Axel Lin5bcd0b72015-09-01 07:56:38 +080081}
82
Philipp Zabel62e24c52016-02-05 13:41:39 +010083static inline struct reset_control *__reset_control_get(
84 struct device *dev, const char *id,
85 int index, bool shared, bool optional)
86{
87 return optional ? NULL : ERR_PTR(-ENOTSUPP);
88}
89
Hans de Goede6c96f052016-02-23 18:46:24 +010090static inline struct reset_control *__devm_reset_control_get(
Ramiro Oliveirabb475232017-01-13 17:57:41 +000091 struct device *dev, const char *id,
92 int index, bool shared, bool optional)
Hans de Goede6c96f052016-02-23 18:46:24 +010093{
Philipp Zabel0ca10b62017-03-20 11:25:16 +010094 return optional ? NULL : ERR_PTR(-ENOTSUPP);
Hans de Goede6c96f052016-02-23 18:46:24 +010095}
96
Vivek Gautam17c82e22017-05-22 16:53:25 +053097static inline struct reset_control *
98devm_reset_control_array_get(struct device *dev, bool shared, bool optional)
99{
100 return optional ? NULL : ERR_PTR(-ENOTSUPP);
101}
102
103static inline struct reset_control *
104of_reset_control_array_get(struct device_node *np, bool shared, bool optional)
105{
106 return optional ? NULL : ERR_PTR(-ENOTSUPP);
107}
108
Hans de Goede6c96f052016-02-23 18:46:24 +0100109#endif /* CONFIG_RESET_CONTROLLER */
110
111/**
Lee Jonesa53e35d2016-06-06 16:56:50 +0100112 * reset_control_get_exclusive - Lookup and obtain an exclusive reference
113 * to a reset controller.
Hans de Goede6c96f052016-02-23 18:46:24 +0100114 * @dev: device to be reset by the controller
115 * @id: reset line name
116 *
117 * Returns a struct reset_control or IS_ERR() condition containing errno.
Hans de Goede0b522972016-02-23 18:46:26 +0100118 * If this function is called more then once for the same reset_control it will
119 * return -EBUSY.
120 *
121 * See reset_control_get_shared for details on shared references to
122 * reset-controls.
Hans de Goede6c96f052016-02-23 18:46:24 +0100123 *
124 * Use of id names is optional.
125 */
Lee Jonesa53e35d2016-06-06 16:56:50 +0100126static inline struct reset_control *
127__must_check reset_control_get_exclusive(struct device *dev, const char *id)
Axel Lin5bcd0b72015-09-01 07:56:38 +0800128{
Hans de Goede6c96f052016-02-23 18:46:24 +0100129#ifndef CONFIG_RESET_CONTROLLER
Axel Lin5bcd0b72015-09-01 07:56:38 +0800130 WARN_ON(1);
Hans de Goede6c96f052016-02-23 18:46:24 +0100131#endif
Philipp Zabel62e24c52016-02-05 13:41:39 +0100132 return __reset_control_get(dev, id, 0, false, false);
Axel Lin5bcd0b72015-09-01 07:56:38 +0800133}
134
Hans de Goede6c96f052016-02-23 18:46:24 +0100135/**
Hans de Goede0b522972016-02-23 18:46:26 +0100136 * reset_control_get_shared - Lookup and obtain a shared reference to a
137 * reset controller.
138 * @dev: device to be reset by the controller
139 * @id: reset line name
140 *
141 * Returns a struct reset_control or IS_ERR() condition containing errno.
142 * This function is intended for use with reset-controls which are shared
143 * between hardware-blocks.
144 *
145 * When a reset-control is shared, the behavior of reset_control_assert /
146 * deassert is changed, the reset-core will keep track of a deassert_count
147 * and only (re-)assert the reset after reset_control_assert has been called
148 * as many times as reset_control_deassert was called. Also see the remark
149 * about shared reset-controls in the reset_control_assert docs.
150 *
151 * Calling reset_control_assert without first calling reset_control_deassert
152 * is not allowed on a shared reset control. Calling reset_control_reset is
153 * also not allowed on a shared reset control.
154 *
155 * Use of id names is optional.
156 */
157static inline struct reset_control *reset_control_get_shared(
158 struct device *dev, const char *id)
159{
Philipp Zabel62e24c52016-02-05 13:41:39 +0100160 return __reset_control_get(dev, id, 0, true, false);
Hans de Goede0b522972016-02-23 18:46:26 +0100161}
162
Lee Jonesa53e35d2016-06-06 16:56:50 +0100163static inline struct reset_control *reset_control_get_optional_exclusive(
Lee Jones3c35f6e2016-06-06 16:56:49 +0100164 struct device *dev, const char *id)
165{
Philipp Zabel62e24c52016-02-05 13:41:39 +0100166 return __reset_control_get(dev, id, 0, false, true);
Lee Jones3c35f6e2016-06-06 16:56:49 +0100167}
168
Lee Jonesc33d61a2016-06-06 16:56:52 +0100169static inline struct reset_control *reset_control_get_optional_shared(
170 struct device *dev, const char *id)
171{
Philipp Zabel62e24c52016-02-05 13:41:39 +0100172 return __reset_control_get(dev, id, 0, true, true);
Lee Jonesc33d61a2016-06-06 16:56:52 +0100173}
174
Hans de Goede0b522972016-02-23 18:46:26 +0100175/**
Lee Jonesa53e35d2016-06-06 16:56:50 +0100176 * of_reset_control_get_exclusive - Lookup and obtain an exclusive reference
177 * to a reset controller.
Hans de Goede6c96f052016-02-23 18:46:24 +0100178 * @node: device to be reset by the controller
179 * @id: reset line name
180 *
181 * Returns a struct reset_control or IS_ERR() condition containing errno.
182 *
183 * Use of id names is optional.
184 */
Lee Jonesa53e35d2016-06-06 16:56:50 +0100185static inline struct reset_control *of_reset_control_get_exclusive(
Hans de Goede6c96f052016-02-23 18:46:24 +0100186 struct device_node *node, const char *id)
187{
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000188 return __of_reset_control_get(node, id, 0, false, false);
Hans de Goede6c96f052016-02-23 18:46:24 +0100189}
190
191/**
Lee Jones40faee8e2016-06-06 16:56:51 +0100192 * of_reset_control_get_shared - Lookup and obtain an shared reference
193 * to a reset controller.
194 * @node: device to be reset by the controller
195 * @id: reset line name
196 *
197 * When a reset-control is shared, the behavior of reset_control_assert /
198 * deassert is changed, the reset-core will keep track of a deassert_count
199 * and only (re-)assert the reset after reset_control_assert has been called
200 * as many times as reset_control_deassert was called. Also see the remark
201 * about shared reset-controls in the reset_control_assert docs.
202 *
203 * Calling reset_control_assert without first calling reset_control_deassert
204 * is not allowed on a shared reset control. Calling reset_control_reset is
205 * also not allowed on a shared reset control.
206 * Returns a struct reset_control or IS_ERR() condition containing errno.
207 *
208 * Use of id names is optional.
209 */
210static inline struct reset_control *of_reset_control_get_shared(
211 struct device_node *node, const char *id)
212{
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000213 return __of_reset_control_get(node, id, 0, true, false);
Lee Jones40faee8e2016-06-06 16:56:51 +0100214}
215
216/**
Lee Jonesa53e35d2016-06-06 16:56:50 +0100217 * of_reset_control_get_exclusive_by_index - Lookup and obtain an exclusive
218 * reference to a reset controller
219 * by index.
Hans de Goede6c96f052016-02-23 18:46:24 +0100220 * @node: device to be reset by the controller
221 * @index: index of the reset controller
222 *
223 * This is to be used to perform a list of resets for a device or power domain
224 * in whatever order. Returns a struct reset_control or IS_ERR() condition
225 * containing errno.
226 */
Lee Jonesa53e35d2016-06-06 16:56:50 +0100227static inline struct reset_control *of_reset_control_get_exclusive_by_index(
Hans de Goede6c96f052016-02-23 18:46:24 +0100228 struct device_node *node, int index)
229{
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000230 return __of_reset_control_get(node, NULL, index, false, false);
Hans de Goede6c96f052016-02-23 18:46:24 +0100231}
232
233/**
Lee Jones40faee8e2016-06-06 16:56:51 +0100234 * of_reset_control_get_shared_by_index - Lookup and obtain an shared
235 * reference to a reset controller
236 * by index.
237 * @node: device to be reset by the controller
238 * @index: index of the reset controller
239 *
240 * When a reset-control is shared, the behavior of reset_control_assert /
241 * deassert is changed, the reset-core will keep track of a deassert_count
242 * and only (re-)assert the reset after reset_control_assert has been called
243 * as many times as reset_control_deassert was called. Also see the remark
244 * about shared reset-controls in the reset_control_assert docs.
245 *
246 * Calling reset_control_assert without first calling reset_control_deassert
247 * is not allowed on a shared reset control. Calling reset_control_reset is
248 * also not allowed on a shared reset control.
249 * Returns a struct reset_control or IS_ERR() condition containing errno.
250 *
251 * This is to be used to perform a list of resets for a device or power domain
252 * in whatever order. Returns a struct reset_control or IS_ERR() condition
253 * containing errno.
254 */
255static inline struct reset_control *of_reset_control_get_shared_by_index(
256 struct device_node *node, int index)
257{
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000258 return __of_reset_control_get(node, NULL, index, true, false);
Lee Jones40faee8e2016-06-06 16:56:51 +0100259}
260
261/**
Lee Jonesa53e35d2016-06-06 16:56:50 +0100262 * devm_reset_control_get_exclusive - resource managed
263 * reset_control_get_exclusive()
Hans de Goede6c96f052016-02-23 18:46:24 +0100264 * @dev: device to be reset by the controller
265 * @id: reset line name
266 *
Lee Jonesa53e35d2016-06-06 16:56:50 +0100267 * Managed reset_control_get_exclusive(). For reset controllers returned
268 * from this function, reset_control_put() is called automatically on driver
269 * detach.
270 *
271 * See reset_control_get_exclusive() for more information.
Hans de Goede6c96f052016-02-23 18:46:24 +0100272 */
Lee Jonesa53e35d2016-06-06 16:56:50 +0100273static inline struct reset_control *
274__must_check devm_reset_control_get_exclusive(struct device *dev,
275 const char *id)
Hans de Goede6c96f052016-02-23 18:46:24 +0100276{
277#ifndef CONFIG_RESET_CONTROLLER
278 WARN_ON(1);
279#endif
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000280 return __devm_reset_control_get(dev, id, 0, false, false);
Philipp Zabelb4240802014-03-07 15:18:47 +0100281}
282
Hans de Goede0b522972016-02-23 18:46:26 +0100283/**
284 * devm_reset_control_get_shared - resource managed reset_control_get_shared()
285 * @dev: device to be reset by the controller
286 * @id: reset line name
287 *
288 * Managed reset_control_get_shared(). For reset controllers returned from
289 * this function, reset_control_put() is called automatically on driver detach.
290 * See reset_control_get_shared() for more information.
291 */
292static inline struct reset_control *devm_reset_control_get_shared(
293 struct device *dev, const char *id)
294{
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000295 return __devm_reset_control_get(dev, id, 0, true, false);
Hans de Goede0b522972016-02-23 18:46:26 +0100296}
297
Lee Jonesa53e35d2016-06-06 16:56:50 +0100298static inline struct reset_control *devm_reset_control_get_optional_exclusive(
Philipp Zabelb4240802014-03-07 15:18:47 +0100299 struct device *dev, const char *id)
300{
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000301 return __devm_reset_control_get(dev, id, 0, false, true);
Philipp Zabelb4240802014-03-07 15:18:47 +0100302}
303
Lee Jonesc33d61a2016-06-06 16:56:52 +0100304static inline struct reset_control *devm_reset_control_get_optional_shared(
305 struct device *dev, const char *id)
306{
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000307 return __devm_reset_control_get(dev, id, 0, true, true);
Lee Jonesc33d61a2016-06-06 16:56:52 +0100308}
309
Hans de Goede6c96f052016-02-23 18:46:24 +0100310/**
Lee Jonesa53e35d2016-06-06 16:56:50 +0100311 * devm_reset_control_get_exclusive_by_index - resource managed
312 * reset_control_get_exclusive()
Hans de Goede6c96f052016-02-23 18:46:24 +0100313 * @dev: device to be reset by the controller
314 * @index: index of the reset controller
315 *
Lee Jonesa53e35d2016-06-06 16:56:50 +0100316 * Managed reset_control_get_exclusive(). For reset controllers returned from
317 * this function, reset_control_put() is called automatically on driver
318 * detach.
319 *
320 * See reset_control_get_exclusive() for more information.
Hans de Goede6c96f052016-02-23 18:46:24 +0100321 */
Lee Jonesa53e35d2016-06-06 16:56:50 +0100322static inline struct reset_control *
323devm_reset_control_get_exclusive_by_index(struct device *dev, int index)
Hans de Goedee3ec0a82014-04-13 14:09:15 +0200324{
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000325 return __devm_reset_control_get(dev, NULL, index, false, false);
Hans de Goede0b522972016-02-23 18:46:26 +0100326}
327
Hans de Goede0b522972016-02-23 18:46:26 +0100328/**
329 * devm_reset_control_get_shared_by_index - resource managed
330 * reset_control_get_shared
331 * @dev: device to be reset by the controller
332 * @index: index of the reset controller
333 *
334 * Managed reset_control_get_shared(). For reset controllers returned from
335 * this function, reset_control_put() is called automatically on driver detach.
336 * See reset_control_get_shared() for more information.
337 */
Lee Jones0bcc0ea2016-06-06 16:56:53 +0100338static inline struct reset_control *
339devm_reset_control_get_shared_by_index(struct device *dev, int index)
Hans de Goede0b522972016-02-23 18:46:26 +0100340{
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000341 return __devm_reset_control_get(dev, NULL, index, true, false);
Hans de Goedee3ec0a82014-04-13 14:09:15 +0200342}
343
Lee Jonesa53e35d2016-06-06 16:56:50 +0100344/*
345 * TEMPORARY calls to use during transition:
346 *
347 * of_reset_control_get() => of_reset_control_get_exclusive()
348 *
349 * These inline function calls will be removed once all consumers
350 * have been moved over to the new explicit API.
351 */
352static inline struct reset_control *reset_control_get(
353 struct device *dev, const char *id)
354{
355 return reset_control_get_exclusive(dev, id);
356}
357
358static inline struct reset_control *reset_control_get_optional(
359 struct device *dev, const char *id)
360{
361 return reset_control_get_optional_exclusive(dev, id);
362}
363
364static inline struct reset_control *of_reset_control_get(
365 struct device_node *node, const char *id)
366{
367 return of_reset_control_get_exclusive(node, id);
368}
369
370static inline struct reset_control *of_reset_control_get_by_index(
371 struct device_node *node, int index)
372{
373 return of_reset_control_get_exclusive_by_index(node, index);
374}
375
376static inline struct reset_control *devm_reset_control_get(
377 struct device *dev, const char *id)
378{
379 return devm_reset_control_get_exclusive(dev, id);
380}
381
382static inline struct reset_control *devm_reset_control_get_optional(
383 struct device *dev, const char *id)
384{
385 return devm_reset_control_get_optional_exclusive(dev, id);
386
387}
388
389static inline struct reset_control *devm_reset_control_get_by_index(
390 struct device *dev, int index)
391{
392 return devm_reset_control_get_exclusive_by_index(dev, index);
393}
Vivek Gautam17c82e22017-05-22 16:53:25 +0530394
395/*
396 * APIs to manage a list of reset controllers
397 */
398static inline struct reset_control *
399devm_reset_control_array_get_exclusive(struct device *dev)
400{
401 return devm_reset_control_array_get(dev, false, false);
402}
403
404static inline struct reset_control *
405devm_reset_control_array_get_shared(struct device *dev)
406{
407 return devm_reset_control_array_get(dev, true, false);
408}
409
410static inline struct reset_control *
411devm_reset_control_array_get_optional_exclusive(struct device *dev)
412{
413 return devm_reset_control_array_get(dev, false, true);
414}
415
416static inline struct reset_control *
417devm_reset_control_array_get_optional_shared(struct device *dev)
418{
419 return devm_reset_control_array_get(dev, true, true);
420}
421
422static inline struct reset_control *
423of_reset_control_array_get_exclusive(struct device_node *node)
424{
425 return of_reset_control_array_get(node, false, false);
426}
427
428static inline struct reset_control *
429of_reset_control_array_get_shared(struct device_node *node)
430{
431 return of_reset_control_array_get(node, true, false);
432}
433
434static inline struct reset_control *
435of_reset_control_array_get_optional_exclusive(struct device_node *node)
436{
437 return of_reset_control_array_get(node, false, true);
438}
439
440static inline struct reset_control *
441of_reset_control_array_get_optional_shared(struct device_node *node)
442{
443 return of_reset_control_array_get(node, true, true);
444}
Philipp Zabel61fc4132012-11-19 17:23:13 +0100445#endif