blob: 13d8681210d545ab2dcedb472fa127b408446eae [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
28static inline int device_reset_optional(struct device *dev)
29{
30 return device_reset(dev);
31}
32
Philipp Zabelb4240802014-03-07 15:18:47 +010033#else
34
35static inline int reset_control_reset(struct reset_control *rstc)
36{
Philipp Zabelb4240802014-03-07 15:18:47 +010037 return 0;
38}
39
40static inline int reset_control_assert(struct reset_control *rstc)
41{
Philipp Zabelb4240802014-03-07 15:18:47 +010042 return 0;
43}
44
45static inline int reset_control_deassert(struct reset_control *rstc)
46{
Philipp Zabelb4240802014-03-07 15:18:47 +010047 return 0;
48}
49
Dinh Nguyen729de412014-10-10 10:21:14 -050050static inline int reset_control_status(struct reset_control *rstc)
51{
Dinh Nguyen729de412014-10-10 10:21:14 -050052 return 0;
53}
54
Philipp Zabelb4240802014-03-07 15:18:47 +010055static inline void reset_control_put(struct reset_control *rstc)
56{
Philipp Zabelb4240802014-03-07 15:18:47 +010057}
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,
Ramiro Oliveirabb475232017-01-13 17:57:41 +000072 const char *id, int index, bool shared,
73 bool optional)
Axel Lin5bcd0b72015-09-01 07:56:38 +080074{
Philipp Zabel0ca10b62017-03-20 11:25:16 +010075 return optional ? NULL : ERR_PTR(-ENOTSUPP);
Axel Lin5bcd0b72015-09-01 07:56:38 +080076}
77
Philipp Zabel62e24c52016-02-05 13:41:39 +010078static inline struct reset_control *__reset_control_get(
79 struct device *dev, const char *id,
80 int index, bool shared, bool optional)
81{
82 return optional ? NULL : ERR_PTR(-ENOTSUPP);
83}
84
Hans de Goede6c96f052016-02-23 18:46:24 +010085static inline struct reset_control *__devm_reset_control_get(
Ramiro Oliveirabb475232017-01-13 17:57:41 +000086 struct device *dev, const char *id,
87 int index, bool shared, bool optional)
Hans de Goede6c96f052016-02-23 18:46:24 +010088{
Philipp Zabel0ca10b62017-03-20 11:25:16 +010089 return optional ? NULL : ERR_PTR(-ENOTSUPP);
Hans de Goede6c96f052016-02-23 18:46:24 +010090}
91
92#endif /* CONFIG_RESET_CONTROLLER */
93
94/**
Lee Jonesa53e35d2016-06-06 16:56:50 +010095 * reset_control_get_exclusive - Lookup and obtain an exclusive reference
96 * to a reset controller.
Hans de Goede6c96f052016-02-23 18:46:24 +010097 * @dev: device to be reset by the controller
98 * @id: reset line name
99 *
100 * Returns a struct reset_control or IS_ERR() condition containing errno.
Hans de Goede0b522972016-02-23 18:46:26 +0100101 * If this function is called more then once for the same reset_control it will
102 * return -EBUSY.
103 *
104 * See reset_control_get_shared for details on shared references to
105 * reset-controls.
Hans de Goede6c96f052016-02-23 18:46:24 +0100106 *
107 * Use of id names is optional.
108 */
Lee Jonesa53e35d2016-06-06 16:56:50 +0100109static inline struct reset_control *
110__must_check reset_control_get_exclusive(struct device *dev, const char *id)
Axel Lin5bcd0b72015-09-01 07:56:38 +0800111{
Hans de Goede6c96f052016-02-23 18:46:24 +0100112#ifndef CONFIG_RESET_CONTROLLER
Axel Lin5bcd0b72015-09-01 07:56:38 +0800113 WARN_ON(1);
Hans de Goede6c96f052016-02-23 18:46:24 +0100114#endif
Philipp Zabel62e24c52016-02-05 13:41:39 +0100115 return __reset_control_get(dev, id, 0, false, false);
Axel Lin5bcd0b72015-09-01 07:56:38 +0800116}
117
Hans de Goede6c96f052016-02-23 18:46:24 +0100118/**
Hans de Goede0b522972016-02-23 18:46:26 +0100119 * reset_control_get_shared - Lookup and obtain a shared reference to a
120 * reset controller.
121 * @dev: device to be reset by the controller
122 * @id: reset line name
123 *
124 * Returns a struct reset_control or IS_ERR() condition containing errno.
125 * This function is intended for use with reset-controls which are shared
126 * between hardware-blocks.
127 *
128 * When a reset-control is shared, the behavior of reset_control_assert /
129 * deassert is changed, the reset-core will keep track of a deassert_count
130 * and only (re-)assert the reset after reset_control_assert has been called
131 * as many times as reset_control_deassert was called. Also see the remark
132 * about shared reset-controls in the reset_control_assert docs.
133 *
134 * Calling reset_control_assert without first calling reset_control_deassert
135 * is not allowed on a shared reset control. Calling reset_control_reset is
136 * also not allowed on a shared reset control.
137 *
138 * Use of id names is optional.
139 */
140static inline struct reset_control *reset_control_get_shared(
141 struct device *dev, const char *id)
142{
Philipp Zabel62e24c52016-02-05 13:41:39 +0100143 return __reset_control_get(dev, id, 0, true, false);
Hans de Goede0b522972016-02-23 18:46:26 +0100144}
145
Lee Jonesa53e35d2016-06-06 16:56:50 +0100146static inline struct reset_control *reset_control_get_optional_exclusive(
Lee Jones3c35f6e2016-06-06 16:56:49 +0100147 struct device *dev, const char *id)
148{
Philipp Zabel62e24c52016-02-05 13:41:39 +0100149 return __reset_control_get(dev, id, 0, false, true);
Lee Jones3c35f6e2016-06-06 16:56:49 +0100150}
151
Lee Jonesc33d61a2016-06-06 16:56:52 +0100152static inline struct reset_control *reset_control_get_optional_shared(
153 struct device *dev, const char *id)
154{
Philipp Zabel62e24c52016-02-05 13:41:39 +0100155 return __reset_control_get(dev, id, 0, true, true);
Lee Jonesc33d61a2016-06-06 16:56:52 +0100156}
157
Hans de Goede0b522972016-02-23 18:46:26 +0100158/**
Lee Jonesa53e35d2016-06-06 16:56:50 +0100159 * of_reset_control_get_exclusive - Lookup and obtain an exclusive reference
160 * to a reset controller.
Hans de Goede6c96f052016-02-23 18:46:24 +0100161 * @node: device to be reset by the controller
162 * @id: reset line name
163 *
164 * Returns a struct reset_control or IS_ERR() condition containing errno.
165 *
166 * Use of id names is optional.
167 */
Lee Jonesa53e35d2016-06-06 16:56:50 +0100168static inline struct reset_control *of_reset_control_get_exclusive(
Hans de Goede6c96f052016-02-23 18:46:24 +0100169 struct device_node *node, const char *id)
170{
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000171 return __of_reset_control_get(node, id, 0, false, false);
Hans de Goede6c96f052016-02-23 18:46:24 +0100172}
173
174/**
Lee Jones40faee8e2016-06-06 16:56:51 +0100175 * of_reset_control_get_shared - Lookup and obtain an shared reference
176 * to a reset controller.
177 * @node: device to be reset by the controller
178 * @id: reset line name
179 *
180 * When a reset-control is shared, the behavior of reset_control_assert /
181 * deassert is changed, the reset-core will keep track of a deassert_count
182 * and only (re-)assert the reset after reset_control_assert has been called
183 * as many times as reset_control_deassert was called. Also see the remark
184 * about shared reset-controls in the reset_control_assert docs.
185 *
186 * Calling reset_control_assert without first calling reset_control_deassert
187 * is not allowed on a shared reset control. Calling reset_control_reset is
188 * also not allowed on a shared reset control.
189 * Returns a struct reset_control or IS_ERR() condition containing errno.
190 *
191 * Use of id names is optional.
192 */
193static inline struct reset_control *of_reset_control_get_shared(
194 struct device_node *node, const char *id)
195{
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000196 return __of_reset_control_get(node, id, 0, true, false);
Lee Jones40faee8e2016-06-06 16:56:51 +0100197}
198
199/**
Lee Jonesa53e35d2016-06-06 16:56:50 +0100200 * of_reset_control_get_exclusive_by_index - Lookup and obtain an exclusive
201 * reference to a reset controller
202 * by index.
Hans de Goede6c96f052016-02-23 18:46:24 +0100203 * @node: device to be reset by the controller
204 * @index: index of the reset controller
205 *
206 * This is to be used to perform a list of resets for a device or power domain
207 * in whatever order. Returns a struct reset_control or IS_ERR() condition
208 * containing errno.
209 */
Lee Jonesa53e35d2016-06-06 16:56:50 +0100210static inline struct reset_control *of_reset_control_get_exclusive_by_index(
Hans de Goede6c96f052016-02-23 18:46:24 +0100211 struct device_node *node, int index)
212{
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000213 return __of_reset_control_get(node, NULL, index, false, false);
Hans de Goede6c96f052016-02-23 18:46:24 +0100214}
215
216/**
Lee Jones40faee8e2016-06-06 16:56:51 +0100217 * of_reset_control_get_shared_by_index - Lookup and obtain an shared
218 * reference to a reset controller
219 * by index.
220 * @node: device to be reset by the controller
221 * @index: index of the reset controller
222 *
223 * When a reset-control is shared, the behavior of reset_control_assert /
224 * deassert is changed, the reset-core will keep track of a deassert_count
225 * and only (re-)assert the reset after reset_control_assert has been called
226 * as many times as reset_control_deassert was called. Also see the remark
227 * about shared reset-controls in the reset_control_assert docs.
228 *
229 * Calling reset_control_assert without first calling reset_control_deassert
230 * is not allowed on a shared reset control. Calling reset_control_reset is
231 * also not allowed on a shared reset control.
232 * Returns a struct reset_control or IS_ERR() condition containing errno.
233 *
234 * This is to be used to perform a list of resets for a device or power domain
235 * in whatever order. Returns a struct reset_control or IS_ERR() condition
236 * containing errno.
237 */
238static inline struct reset_control *of_reset_control_get_shared_by_index(
239 struct device_node *node, int index)
240{
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000241 return __of_reset_control_get(node, NULL, index, true, false);
Lee Jones40faee8e2016-06-06 16:56:51 +0100242}
243
244/**
Lee Jonesa53e35d2016-06-06 16:56:50 +0100245 * devm_reset_control_get_exclusive - resource managed
246 * reset_control_get_exclusive()
Hans de Goede6c96f052016-02-23 18:46:24 +0100247 * @dev: device to be reset by the controller
248 * @id: reset line name
249 *
Lee Jonesa53e35d2016-06-06 16:56:50 +0100250 * Managed reset_control_get_exclusive(). For reset controllers returned
251 * from this function, reset_control_put() is called automatically on driver
252 * detach.
253 *
254 * See reset_control_get_exclusive() for more information.
Hans de Goede6c96f052016-02-23 18:46:24 +0100255 */
Lee Jonesa53e35d2016-06-06 16:56:50 +0100256static inline struct reset_control *
257__must_check devm_reset_control_get_exclusive(struct device *dev,
258 const char *id)
Hans de Goede6c96f052016-02-23 18:46:24 +0100259{
260#ifndef CONFIG_RESET_CONTROLLER
261 WARN_ON(1);
262#endif
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000263 return __devm_reset_control_get(dev, id, 0, false, false);
Philipp Zabelb4240802014-03-07 15:18:47 +0100264}
265
Hans de Goede0b522972016-02-23 18:46:26 +0100266/**
267 * devm_reset_control_get_shared - resource managed reset_control_get_shared()
268 * @dev: device to be reset by the controller
269 * @id: reset line name
270 *
271 * Managed reset_control_get_shared(). For reset controllers returned from
272 * this function, reset_control_put() is called automatically on driver detach.
273 * See reset_control_get_shared() for more information.
274 */
275static inline struct reset_control *devm_reset_control_get_shared(
276 struct device *dev, const char *id)
277{
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000278 return __devm_reset_control_get(dev, id, 0, true, false);
Hans de Goede0b522972016-02-23 18:46:26 +0100279}
280
Lee Jonesa53e35d2016-06-06 16:56:50 +0100281static inline struct reset_control *devm_reset_control_get_optional_exclusive(
Philipp Zabelb4240802014-03-07 15:18:47 +0100282 struct device *dev, const char *id)
283{
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000284 return __devm_reset_control_get(dev, id, 0, false, true);
Philipp Zabelb4240802014-03-07 15:18:47 +0100285}
286
Lee Jonesc33d61a2016-06-06 16:56:52 +0100287static inline struct reset_control *devm_reset_control_get_optional_shared(
288 struct device *dev, const char *id)
289{
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000290 return __devm_reset_control_get(dev, id, 0, true, true);
Lee Jonesc33d61a2016-06-06 16:56:52 +0100291}
292
Hans de Goede6c96f052016-02-23 18:46:24 +0100293/**
Lee Jonesa53e35d2016-06-06 16:56:50 +0100294 * devm_reset_control_get_exclusive_by_index - resource managed
295 * reset_control_get_exclusive()
Hans de Goede6c96f052016-02-23 18:46:24 +0100296 * @dev: device to be reset by the controller
297 * @index: index of the reset controller
298 *
Lee Jonesa53e35d2016-06-06 16:56:50 +0100299 * Managed reset_control_get_exclusive(). For reset controllers returned from
300 * this function, reset_control_put() is called automatically on driver
301 * detach.
302 *
303 * See reset_control_get_exclusive() for more information.
Hans de Goede6c96f052016-02-23 18:46:24 +0100304 */
Lee Jonesa53e35d2016-06-06 16:56:50 +0100305static inline struct reset_control *
306devm_reset_control_get_exclusive_by_index(struct device *dev, int index)
Hans de Goedee3ec0a82014-04-13 14:09:15 +0200307{
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000308 return __devm_reset_control_get(dev, NULL, index, false, false);
Hans de Goede0b522972016-02-23 18:46:26 +0100309}
310
Hans de Goede0b522972016-02-23 18:46:26 +0100311/**
312 * devm_reset_control_get_shared_by_index - resource managed
313 * reset_control_get_shared
314 * @dev: device to be reset by the controller
315 * @index: index of the reset controller
316 *
317 * Managed reset_control_get_shared(). For reset controllers returned from
318 * this function, reset_control_put() is called automatically on driver detach.
319 * See reset_control_get_shared() for more information.
320 */
Lee Jones0bcc0ea2016-06-06 16:56:53 +0100321static inline struct reset_control *
322devm_reset_control_get_shared_by_index(struct device *dev, int index)
Hans de Goede0b522972016-02-23 18:46:26 +0100323{
Ramiro Oliveirabb475232017-01-13 17:57:41 +0000324 return __devm_reset_control_get(dev, NULL, index, true, false);
Hans de Goedee3ec0a82014-04-13 14:09:15 +0200325}
326
Lee Jonesa53e35d2016-06-06 16:56:50 +0100327/*
328 * TEMPORARY calls to use during transition:
329 *
330 * of_reset_control_get() => of_reset_control_get_exclusive()
331 *
332 * These inline function calls will be removed once all consumers
333 * have been moved over to the new explicit API.
334 */
335static inline struct reset_control *reset_control_get(
336 struct device *dev, const char *id)
337{
338 return reset_control_get_exclusive(dev, id);
339}
340
341static inline struct reset_control *reset_control_get_optional(
342 struct device *dev, const char *id)
343{
344 return reset_control_get_optional_exclusive(dev, id);
345}
346
347static inline struct reset_control *of_reset_control_get(
348 struct device_node *node, const char *id)
349{
350 return of_reset_control_get_exclusive(node, id);
351}
352
353static inline struct reset_control *of_reset_control_get_by_index(
354 struct device_node *node, int index)
355{
356 return of_reset_control_get_exclusive_by_index(node, index);
357}
358
359static inline struct reset_control *devm_reset_control_get(
360 struct device *dev, const char *id)
361{
362 return devm_reset_control_get_exclusive(dev, id);
363}
364
365static inline struct reset_control *devm_reset_control_get_optional(
366 struct device *dev, const char *id)
367{
368 return devm_reset_control_get_optional_exclusive(dev, id);
369
370}
371
372static inline struct reset_control *devm_reset_control_get_by_index(
373 struct device *dev, int index)
374{
375 return devm_reset_control_get_exclusive_by_index(dev, index);
376}
Philipp Zabel61fc4132012-11-19 17:23:13 +0100377#endif