blob: 9cf4cf39bf1d096b39528476c44bbdca6c4ab7b2 [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,
Hans de Goede0b522972016-02-23 18:46:26 +010016 const char *id, int index, int shared);
Philipp Zabel61fc4132012-11-19 17:23:13 +010017void reset_control_put(struct reset_control *rstc);
Hans de Goede6c96f052016-02-23 18:46:24 +010018struct reset_control *__devm_reset_control_get(struct device *dev,
Hans de Goede0b522972016-02-23 18:46:26 +010019 const char *id, int index, int shared);
Philipp Zabel61fc4132012-11-19 17:23:13 +010020
Philipp Zabelb4240802014-03-07 15:18:47 +010021int __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
Philipp Zabelb4240802014-03-07 15:18:47 +010028#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
Dinh Nguyen729de412014-10-10 10:21:14 -050048static inline int reset_control_status(struct reset_control *rstc)
49{
50 WARN_ON(1);
51 return 0;
52}
53
Philipp Zabelb4240802014-03-07 15:18:47 +010054static inline void reset_control_put(struct reset_control *rstc)
55{
56 WARN_ON(1);
57}
58
Daniel Lezcano41136522016-04-01 21:38:16 +020059static inline int __must_check device_reset(struct device *dev)
60{
61 WARN_ON(1);
62 return -ENOTSUPP;
63}
64
Philipp Zabelb4240802014-03-07 15:18:47 +010065static inline int device_reset_optional(struct device *dev)
66{
Philipp Zabel39b4da72015-10-29 09:55:00 +010067 return -ENOTSUPP;
Philipp Zabelb4240802014-03-07 15:18:47 +010068}
69
Hans de Goede6c96f052016-02-23 18:46:24 +010070static inline struct reset_control *__of_reset_control_get(
71 struct device_node *node,
Hans de Goede0b522972016-02-23 18:46:26 +010072 const char *id, int index, int shared)
Axel Lin5bcd0b72015-09-01 07:56:38 +080073{
Axel Lin5bcd0b72015-09-01 07:56:38 +080074 return ERR_PTR(-EINVAL);
75}
76
Hans de Goede6c96f052016-02-23 18:46:24 +010077static inline struct reset_control *__devm_reset_control_get(
78 struct device *dev,
Hans de Goede0b522972016-02-23 18:46:26 +010079 const char *id, int index, int shared)
Hans de Goede6c96f052016-02-23 18:46:24 +010080{
81 return ERR_PTR(-EINVAL);
82}
83
84#endif /* CONFIG_RESET_CONTROLLER */
85
86/**
Lee Jonesa53e35d2016-06-06 16:56:50 +010087 * reset_control_get_exclusive - Lookup and obtain an exclusive reference
88 * to a reset controller.
Hans de Goede6c96f052016-02-23 18:46:24 +010089 * @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.
Hans de Goede0b522972016-02-23 18:46:26 +010093 * 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.
Hans de Goede6c96f052016-02-23 18:46:24 +010098 *
99 * Use of id names is optional.
100 */
Lee Jonesa53e35d2016-06-06 16:56:50 +0100101static inline struct reset_control *
102__must_check reset_control_get_exclusive(struct device *dev, const char *id)
Axel Lin5bcd0b72015-09-01 07:56:38 +0800103{
Hans de Goede6c96f052016-02-23 18:46:24 +0100104#ifndef CONFIG_RESET_CONTROLLER
Axel Lin5bcd0b72015-09-01 07:56:38 +0800105 WARN_ON(1);
Hans de Goede6c96f052016-02-23 18:46:24 +0100106#endif
Hans de Goede0b522972016-02-23 18:46:26 +0100107 return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, 0);
Axel Lin5bcd0b72015-09-01 07:56:38 +0800108}
109
Hans de Goede6c96f052016-02-23 18:46:24 +0100110/**
Hans de Goede0b522972016-02-23 18:46:26 +0100111 * 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
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{
141 return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, 0);
142}
143
Hans de Goede0b522972016-02-23 18:46:26 +0100144/**
Lee Jonesa53e35d2016-06-06 16:56:50 +0100145 * of_reset_control_get_exclusive - Lookup and obtain an exclusive reference
146 * to a reset controller.
Hans de Goede6c96f052016-02-23 18:46:24 +0100147 * @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 */
Lee Jonesa53e35d2016-06-06 16:56:50 +0100154static inline struct reset_control *of_reset_control_get_exclusive(
Hans de Goede6c96f052016-02-23 18:46:24 +0100155 struct device_node *node, const char *id)
156{
Hans de Goede0b522972016-02-23 18:46:26 +0100157 return __of_reset_control_get(node, id, 0, 0);
Hans de Goede6c96f052016-02-23 18:46:24 +0100158}
159
160/**
Lee Jonesa53e35d2016-06-06 16:56:50 +0100161 * of_reset_control_get_exclusive_by_index - Lookup and obtain an exclusive
162 * reference to a reset controller
163 * by index.
Hans de Goede6c96f052016-02-23 18:46:24 +0100164 * @node: device to be reset by the controller
165 * @index: index of the reset controller
166 *
167 * This is to be used to perform a list of resets for a device or power domain
168 * in whatever order. Returns a struct reset_control or IS_ERR() condition
169 * containing errno.
170 */
Lee Jonesa53e35d2016-06-06 16:56:50 +0100171static inline struct reset_control *of_reset_control_get_exclusive_by_index(
Hans de Goede6c96f052016-02-23 18:46:24 +0100172 struct device_node *node, int index)
173{
Hans de Goede0b522972016-02-23 18:46:26 +0100174 return __of_reset_control_get(node, NULL, index, 0);
Hans de Goede6c96f052016-02-23 18:46:24 +0100175}
176
177/**
Lee Jonesa53e35d2016-06-06 16:56:50 +0100178 * devm_reset_control_get_exclusive - resource managed
179 * reset_control_get_exclusive()
Hans de Goede6c96f052016-02-23 18:46:24 +0100180 * @dev: device to be reset by the controller
181 * @id: reset line name
182 *
Lee Jonesa53e35d2016-06-06 16:56:50 +0100183 * Managed reset_control_get_exclusive(). For reset controllers returned
184 * from this function, reset_control_put() is called automatically on driver
185 * detach.
186 *
187 * See reset_control_get_exclusive() for more information.
Hans de Goede6c96f052016-02-23 18:46:24 +0100188 */
Lee Jonesa53e35d2016-06-06 16:56:50 +0100189static inline struct reset_control *
190__must_check devm_reset_control_get_exclusive(struct device *dev,
191 const char *id)
Hans de Goede6c96f052016-02-23 18:46:24 +0100192{
193#ifndef CONFIG_RESET_CONTROLLER
194 WARN_ON(1);
195#endif
Hans de Goede0b522972016-02-23 18:46:26 +0100196 return __devm_reset_control_get(dev, id, 0, 0);
Philipp Zabelb4240802014-03-07 15:18:47 +0100197}
198
Lee Jones3c35f6e2016-06-06 16:56:49 +0100199/**
200 * devm_reset_control_get_shared - resource managed reset_control_get_shared()
201 * @dev: device to be reset by the controller
202 * @id: reset line name
203 *
204 * Managed reset_control_get_shared(). For reset controllers returned from
205 * this function, reset_control_put() is called automatically on driver detach.
206 * See reset_control_get_shared() for more information.
207 */
208static inline struct reset_control *devm_reset_control_get_shared(
209 struct device *dev, const char *id)
210{
211 return __devm_reset_control_get(dev, id, 0, 1);
212}
213
Lee Jonesa53e35d2016-06-06 16:56:50 +0100214static inline struct reset_control *devm_reset_control_get_optional_exclusive(
Philipp Zabelb4240802014-03-07 15:18:47 +0100215 struct device *dev, const char *id)
216{
Hans de Goede0b522972016-02-23 18:46:26 +0100217 return __devm_reset_control_get(dev, id, 0, 0);
Philipp Zabelb4240802014-03-07 15:18:47 +0100218}
219
Hans de Goede6c96f052016-02-23 18:46:24 +0100220/**
Lee Jonesa53e35d2016-06-06 16:56:50 +0100221 * devm_reset_control_get_exclusive_by_index - resource managed
222 * reset_control_get_exclusive()
Hans de Goede6c96f052016-02-23 18:46:24 +0100223 * @dev: device to be reset by the controller
224 * @index: index of the reset controller
225 *
Lee Jonesa53e35d2016-06-06 16:56:50 +0100226 * Managed reset_control_get_exclusive(). For reset controllers returned from
227 * this function, reset_control_put() is called automatically on driver
228 * detach.
229 *
230 * See reset_control_get_exclusive() for more information.
Hans de Goede6c96f052016-02-23 18:46:24 +0100231 */
Lee Jonesa53e35d2016-06-06 16:56:50 +0100232static inline struct reset_control *
233devm_reset_control_get_exclusive_by_index(struct device *dev, int index)
Hans de Goedee3ec0a82014-04-13 14:09:15 +0200234{
Hans de Goede0b522972016-02-23 18:46:26 +0100235 return __devm_reset_control_get(dev, NULL, index, 0);
236}
237
238/**
Hans de Goede0b522972016-02-23 18:46:26 +0100239 * devm_reset_control_get_shared_by_index - resource managed
240 * reset_control_get_shared
241 * @dev: device to be reset by the controller
242 * @index: index of the reset controller
243 *
244 * Managed reset_control_get_shared(). For reset controllers returned from
245 * this function, reset_control_put() is called automatically on driver detach.
246 * See reset_control_get_shared() for more information.
247 */
248static inline struct reset_control *devm_reset_control_get_shared_by_index(
249 struct device *dev, int index)
250{
251 return __devm_reset_control_get(dev, NULL, index, 1);
Hans de Goedee3ec0a82014-04-13 14:09:15 +0200252}
253
Lee Jonesa53e35d2016-06-06 16:56:50 +0100254/*
255 * TEMPORARY calls to use during transition:
256 *
257 * of_reset_control_get() => of_reset_control_get_exclusive()
258 *
259 * These inline function calls will be removed once all consumers
260 * have been moved over to the new explicit API.
261 */
262static inline struct reset_control *reset_control_get(
263 struct device *dev, const char *id)
264{
265 return reset_control_get_exclusive(dev, id);
266}
267
268static inline struct reset_control *reset_control_get_optional(
269 struct device *dev, const char *id)
270{
271 return reset_control_get_optional_exclusive(dev, id);
272}
273
274static inline struct reset_control *of_reset_control_get(
275 struct device_node *node, const char *id)
276{
277 return of_reset_control_get_exclusive(node, id);
278}
279
280static inline struct reset_control *of_reset_control_get_by_index(
281 struct device_node *node, int index)
282{
283 return of_reset_control_get_exclusive_by_index(node, index);
284}
285
286static inline struct reset_control *devm_reset_control_get(
287 struct device *dev, const char *id)
288{
289 return devm_reset_control_get_exclusive(dev, id);
290}
291
292static inline struct reset_control *devm_reset_control_get_optional(
293 struct device *dev, const char *id)
294{
295 return devm_reset_control_get_optional_exclusive(dev, id);
296
297}
298
299static inline struct reset_control *devm_reset_control_get_by_index(
300 struct device *dev, int index)
301{
302 return devm_reset_control_get_exclusive_by_index(dev, index);
303}
Philipp Zabel61fc4132012-11-19 17:23:13 +0100304#endif