blob: 86b4ed75359e85345afb839483e5910bcf5fe6cb [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 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 Oliveirabb475232017-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{
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
Dinh Nguyen729de412014-10-10 10:21:14 -050050static inline int reset_control_status(struct reset_control *rstc)
51{
52 WARN_ON(1);
53 return 0;
54}
55
Philipp Zabelb4240802014-03-07 15:18:47 +010056static inline void reset_control_put(struct reset_control *rstc)
57{
58 WARN_ON(1);
59}
60
Daniel Lezcano41136522016-04-01 21:38:16 +020061static inline int __must_check device_reset(struct device *dev)
62{
63 WARN_ON(1);
64 return -ENOTSUPP;
65}
66
Philipp Zabelb4240802014-03-07 15:18:47 +010067static inline int device_reset_optional(struct device *dev)
68{
Philipp Zabel39b4da72015-10-29 09:55:00 +010069 return -ENOTSUPP;
Philipp Zabelb4240802014-03-07 15:18:47 +010070}
71
Hans de Goede6c96f052016-02-23 18:46:24 +010072static inline struct reset_control *__of_reset_control_get(
73 struct device_node *node,
Ramiro Oliveirabb475232017-01-13 17:57:41 +000074 const char *id, int index, bool shared,
75 bool optional)
Axel Lin5bcd0b72015-09-01 07:56:38 +080076{
John Youn168d7c42016-05-31 16:55:01 -070077 return ERR_PTR(-ENOTSUPP);
Axel Lin5bcd0b72015-09-01 07:56:38 +080078}
79
Hans de Goede6c96f052016-02-23 18:46:24 +010080static inline struct reset_control *__devm_reset_control_get(
Ramiro Oliveirabb475232017-01-13 17:57:41 +000081 struct device *dev, const char *id,
82 int index, bool shared, bool optional)
Hans de Goede6c96f052016-02-23 18:46:24 +010083{
John Youn168d7c42016-05-31 16:55:01 -070084 return ERR_PTR(-ENOTSUPP);
Hans de Goede6c96f052016-02-23 18:46:24 +010085}
86
87#endif /* CONFIG_RESET_CONTROLLER */
88
89/**
Lee Jonesa53e35d2016-06-06 16:56:50 +010090 * reset_control_get_exclusive - Lookup and obtain an exclusive reference
91 * to a reset controller.
Hans de Goede6c96f052016-02-23 18:46:24 +010092 * @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.
Hans de Goede0b522972016-02-23 18:46:26 +010096 * 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.
Hans de Goede6c96f052016-02-23 18:46:24 +0100101 *
102 * Use of id names is optional.
103 */
Lee Jonesa53e35d2016-06-06 16:56:50 +0100104static inline struct reset_control *
105__must_check reset_control_get_exclusive(struct device *dev, const char *id)
Axel Lin5bcd0b72015-09-01 07:56:38 +0800106{
Hans de Goede6c96f052016-02-23 18:46:24 +0100107#ifndef CONFIG_RESET_CONTROLLER
Axel Lin5bcd0b72015-09-01 07:56:38 +0800108 WARN_ON(1);
Hans de Goede6c96f052016-02-23 18:46:24 +0100109#endif
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000110 return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, false,
111 false);
Axel Lin5bcd0b72015-09-01 07:56:38 +0800112}
113
Hans de Goede6c96f052016-02-23 18:46:24 +0100114/**
Hans de Goede0b522972016-02-23 18:46:26 +0100115 * 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{
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000139 return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, true,
140 false);
Hans de Goede0b522972016-02-23 18:46:26 +0100141}
142
Lee Jonesa53e35d2016-06-06 16:56:50 +0100143static inline struct reset_control *reset_control_get_optional_exclusive(
Lee Jones3c35f6e2016-06-06 16:56:49 +0100144 struct device *dev, const char *id)
145{
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000146 return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, false,
147 true);
Lee Jones3c35f6e2016-06-06 16:56:49 +0100148}
149
Lee Jonesc33d61a2016-06-06 16:56:52 +0100150static inline struct reset_control *reset_control_get_optional_shared(
151 struct device *dev, const char *id)
152{
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000153 return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, true,
154 true);
Lee Jonesc33d61a2016-06-06 16:56:52 +0100155}
156
Hans de Goede0b522972016-02-23 18:46:26 +0100157/**
Lee Jonesa53e35d2016-06-06 16:56:50 +0100158 * of_reset_control_get_exclusive - Lookup and obtain an exclusive reference
159 * to a reset controller.
Hans de Goede6c96f052016-02-23 18:46:24 +0100160 * @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 */
Lee Jonesa53e35d2016-06-06 16:56:50 +0100167static inline struct reset_control *of_reset_control_get_exclusive(
Hans de Goede6c96f052016-02-23 18:46:24 +0100168 struct device_node *node, const char *id)
169{
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000170 return __of_reset_control_get(node, id, 0, false, false);
Hans de Goede6c96f052016-02-23 18:46:24 +0100171}
172
173/**
Lee Jones40faee8e2016-06-06 16:56:51 +0100174 * 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{
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000195 return __of_reset_control_get(node, id, 0, true, false);
Lee Jones40faee8e2016-06-06 16:56:51 +0100196}
197
198/**
Lee Jonesa53e35d2016-06-06 16:56:50 +0100199 * of_reset_control_get_exclusive_by_index - Lookup and obtain an exclusive
200 * reference to a reset controller
201 * by index.
Hans de Goede6c96f052016-02-23 18:46:24 +0100202 * @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 */
Lee Jonesa53e35d2016-06-06 16:56:50 +0100209static inline struct reset_control *of_reset_control_get_exclusive_by_index(
Hans de Goede6c96f052016-02-23 18:46:24 +0100210 struct device_node *node, int index)
211{
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000212 return __of_reset_control_get(node, NULL, index, false, false);
Hans de Goede6c96f052016-02-23 18:46:24 +0100213}
214
215/**
Lee Jones40faee8e2016-06-06 16:56:51 +0100216 * 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{
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000240 return __of_reset_control_get(node, NULL, index, true, false);
Lee Jones40faee8e2016-06-06 16:56:51 +0100241}
242
243/**
Lee Jonesa53e35d2016-06-06 16:56:50 +0100244 * devm_reset_control_get_exclusive - resource managed
245 * reset_control_get_exclusive()
Hans de Goede6c96f052016-02-23 18:46:24 +0100246 * @dev: device to be reset by the controller
247 * @id: reset line name
248 *
Lee Jonesa53e35d2016-06-06 16:56:50 +0100249 * 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.
Hans de Goede6c96f052016-02-23 18:46:24 +0100254 */
Lee Jonesa53e35d2016-06-06 16:56:50 +0100255static inline struct reset_control *
256__must_check devm_reset_control_get_exclusive(struct device *dev,
257 const char *id)
Hans de Goede6c96f052016-02-23 18:46:24 +0100258{
259#ifndef CONFIG_RESET_CONTROLLER
260 WARN_ON(1);
261#endif
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000262 return __devm_reset_control_get(dev, id, 0, false, false);
Philipp Zabelb4240802014-03-07 15:18:47 +0100263}
264
Hans de Goede0b522972016-02-23 18:46:26 +0100265/**
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{
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000277 return __devm_reset_control_get(dev, id, 0, true, false);
Hans de Goede0b522972016-02-23 18:46:26 +0100278}
279
Lee Jonesa53e35d2016-06-06 16:56:50 +0100280static inline struct reset_control *devm_reset_control_get_optional_exclusive(
Philipp Zabelb4240802014-03-07 15:18:47 +0100281 struct device *dev, const char *id)
282{
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000283 return __devm_reset_control_get(dev, id, 0, false, true);
Philipp Zabelb4240802014-03-07 15:18:47 +0100284}
285
Lee Jonesc33d61a2016-06-06 16:56:52 +0100286static inline struct reset_control *devm_reset_control_get_optional_shared(
287 struct device *dev, const char *id)
288{
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000289 return __devm_reset_control_get(dev, id, 0, true, true);
Lee Jonesc33d61a2016-06-06 16:56:52 +0100290}
291
Hans de Goede6c96f052016-02-23 18:46:24 +0100292/**
Lee Jonesa53e35d2016-06-06 16:56:50 +0100293 * devm_reset_control_get_exclusive_by_index - resource managed
294 * reset_control_get_exclusive()
Hans de Goede6c96f052016-02-23 18:46:24 +0100295 * @dev: device to be reset by the controller
296 * @index: index of the reset controller
297 *
Lee Jonesa53e35d2016-06-06 16:56:50 +0100298 * 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.
Hans de Goede6c96f052016-02-23 18:46:24 +0100303 */
Lee Jonesa53e35d2016-06-06 16:56:50 +0100304static inline struct reset_control *
305devm_reset_control_get_exclusive_by_index(struct device *dev, int index)
Hans de Goedee3ec0a82014-04-13 14:09:15 +0200306{
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000307 return __devm_reset_control_get(dev, NULL, index, false, false);
Hans de Goede0b522972016-02-23 18:46:26 +0100308}
309
Hans de Goede0b522972016-02-23 18:46:26 +0100310/**
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 */
Lee Jones0bcc0ea2016-06-06 16:56:53 +0100320static inline struct reset_control *
321devm_reset_control_get_shared_by_index(struct device *dev, int index)
Hans de Goede0b522972016-02-23 18:46:26 +0100322{
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000323 return __devm_reset_control_get(dev, NULL, index, true, false);
Hans de Goedee3ec0a82014-04-13 14:09:15 +0200324}
325
Lee Jonesa53e35d2016-06-06 16:56:50 +0100326/*
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}
Philipp Zabel61fc4132012-11-19 17:23:13 +0100376#endif