blob: ea9a8a1ce4b1e8b1531a3d2462c6f204d31c52dc [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Philipp Zabel61fc4132012-11-19 17:23:13 +01002#ifndef _LINUX_RESET_H_
3#define _LINUX_RESET_H_
4
Masahiro Yamadadfc1d9b2017-10-29 01:50:08 +09005#include <linux/types.h>
Hans de Goede6c96f052016-02-23 18:46:24 +01006
Masahiro Yamadadfc1d9b2017-10-29 01:50:08 +09007struct device;
8struct device_node;
Philipp Zabel61fc4132012-11-19 17:23:13 +01009struct reset_control;
10
Philipp Zabelb4240802014-03-07 15:18:47 +010011#ifdef CONFIG_RESET_CONTROLLER
12
Philipp Zabel61fc4132012-11-19 17:23:13 +010013int reset_control_reset(struct reset_control *rstc);
14int reset_control_assert(struct reset_control *rstc);
15int reset_control_deassert(struct reset_control *rstc);
Dinh Nguyen729de412014-10-10 10:21:14 -050016int reset_control_status(struct reset_control *rstc);
Philipp Zabelc84b0322019-02-21 16:25:53 +010017int reset_control_acquire(struct reset_control *rstc);
18void reset_control_release(struct reset_control *rstc);
Philipp Zabel61fc4132012-11-19 17:23:13 +010019
Hans de Goede6c96f052016-02-23 18:46:24 +010020struct reset_control *__of_reset_control_get(struct device_node *node,
Ramiro Oliveirabb475232017-01-13 17:57:41 +000021 const char *id, int index, bool shared,
Philipp Zabelc84b0322019-02-21 16:25:53 +010022 bool optional, bool acquired);
Philipp Zabel62e24c52016-02-05 13:41:39 +010023struct reset_control *__reset_control_get(struct device *dev, const char *id,
24 int index, bool shared,
Philipp Zabelc84b0322019-02-21 16:25:53 +010025 bool optional, bool acquired);
Philipp Zabel61fc4132012-11-19 17:23:13 +010026void reset_control_put(struct reset_control *rstc);
Masahiro Yamada1554bbd2017-10-29 01:50:06 +090027int __device_reset(struct device *dev, bool optional);
Hans de Goede6c96f052016-02-23 18:46:24 +010028struct reset_control *__devm_reset_control_get(struct device *dev,
Ramiro Oliveirabb475232017-01-13 17:57:41 +000029 const char *id, int index, bool shared,
Philipp Zabelc84b0322019-02-21 16:25:53 +010030 bool optional, bool acquired);
Philipp Zabel61fc4132012-11-19 17:23:13 +010031
Vivek Gautam17c82e22017-05-22 16:53:25 +053032struct reset_control *devm_reset_control_array_get(struct device *dev,
33 bool shared, bool optional);
34struct reset_control *of_reset_control_array_get(struct device_node *np,
35 bool shared, bool optional);
36
Geert Uytterhoeveneaf91db2018-11-13 13:47:44 +010037int reset_control_get_count(struct device *dev);
38
Philipp Zabelb4240802014-03-07 15:18:47 +010039#else
40
41static inline int reset_control_reset(struct reset_control *rstc)
42{
Philipp Zabelb4240802014-03-07 15:18:47 +010043 return 0;
44}
45
46static inline int reset_control_assert(struct reset_control *rstc)
47{
Philipp Zabelb4240802014-03-07 15:18:47 +010048 return 0;
49}
50
51static inline int reset_control_deassert(struct reset_control *rstc)
52{
Philipp Zabelb4240802014-03-07 15:18:47 +010053 return 0;
54}
55
Dinh Nguyen729de412014-10-10 10:21:14 -050056static inline int reset_control_status(struct reset_control *rstc)
57{
Dinh Nguyen729de412014-10-10 10:21:14 -050058 return 0;
59}
60
Philipp Zabelc84b0322019-02-21 16:25:53 +010061static inline int reset_control_acquire(struct reset_control *rstc)
62{
63 return 0;
64}
65
66static inline void reset_control_release(struct reset_control *rstc)
67{
68}
69
Philipp Zabelb4240802014-03-07 15:18:47 +010070static inline void reset_control_put(struct reset_control *rstc)
71{
Philipp Zabelb4240802014-03-07 15:18:47 +010072}
73
Masahiro Yamada1554bbd2017-10-29 01:50:06 +090074static inline int __device_reset(struct device *dev, bool optional)
Daniel Lezcano41136522016-04-01 21:38:16 +020075{
Masahiro Yamada1554bbd2017-10-29 01:50:06 +090076 return optional ? 0 : -ENOTSUPP;
Philipp Zabelb4240802014-03-07 15:18:47 +010077}
78
Hans de Goede6c96f052016-02-23 18:46:24 +010079static inline struct reset_control *__of_reset_control_get(
80 struct device_node *node,
Ramiro Oliveirabb475232017-01-13 17:57:41 +000081 const char *id, int index, bool shared,
Philipp Zabelc84b0322019-02-21 16:25:53 +010082 bool optional, bool acquired)
Axel Lin5bcd0b72015-09-01 07:56:38 +080083{
Philipp Zabel0ca10b62017-03-20 11:25:16 +010084 return optional ? NULL : ERR_PTR(-ENOTSUPP);
Axel Lin5bcd0b72015-09-01 07:56:38 +080085}
86
Philipp Zabel62e24c52016-02-05 13:41:39 +010087static inline struct reset_control *__reset_control_get(
88 struct device *dev, const char *id,
Philipp Zabelc84b0322019-02-21 16:25:53 +010089 int index, bool shared, bool optional,
90 bool acquired)
Philipp Zabel62e24c52016-02-05 13:41:39 +010091{
92 return optional ? NULL : ERR_PTR(-ENOTSUPP);
93}
94
Hans de Goede6c96f052016-02-23 18:46:24 +010095static inline struct reset_control *__devm_reset_control_get(
Ramiro Oliveirabb475232017-01-13 17:57:41 +000096 struct device *dev, const char *id,
Philipp Zabelc84b0322019-02-21 16:25:53 +010097 int index, bool shared, bool optional,
98 bool acquired)
Hans de Goede6c96f052016-02-23 18:46:24 +010099{
Philipp Zabel0ca10b62017-03-20 11:25:16 +0100100 return optional ? NULL : ERR_PTR(-ENOTSUPP);
Hans de Goede6c96f052016-02-23 18:46:24 +0100101}
102
Vivek Gautam17c82e22017-05-22 16:53:25 +0530103static inline struct reset_control *
104devm_reset_control_array_get(struct device *dev, bool shared, bool optional)
105{
106 return optional ? NULL : ERR_PTR(-ENOTSUPP);
107}
108
109static inline struct reset_control *
110of_reset_control_array_get(struct device_node *np, bool shared, bool optional)
111{
112 return optional ? NULL : ERR_PTR(-ENOTSUPP);
113}
114
Geert Uytterhoeveneaf91db2018-11-13 13:47:44 +0100115static inline int reset_control_get_count(struct device *dev)
116{
117 return -ENOENT;
118}
119
Hans de Goede6c96f052016-02-23 18:46:24 +0100120#endif /* CONFIG_RESET_CONTROLLER */
121
Masahiro Yamada1554bbd2017-10-29 01:50:06 +0900122static inline int __must_check device_reset(struct device *dev)
123{
124 return __device_reset(dev, false);
125}
126
127static inline int device_reset_optional(struct device *dev)
128{
129 return __device_reset(dev, true);
130}
131
Hans de Goede6c96f052016-02-23 18:46:24 +0100132/**
Lee Jonesa53e35d2016-06-06 16:56:50 +0100133 * reset_control_get_exclusive - Lookup and obtain an exclusive reference
134 * to a reset controller.
Hans de Goede6c96f052016-02-23 18:46:24 +0100135 * @dev: device to be reset by the controller
136 * @id: reset line name
137 *
138 * Returns a struct reset_control or IS_ERR() condition containing errno.
Geert Uytterhoeven34845c92018-09-26 15:20:03 +0200139 * If this function is called more than once for the same reset_control it will
Hans de Goede0b522972016-02-23 18:46:26 +0100140 * return -EBUSY.
141 *
142 * See reset_control_get_shared for details on shared references to
143 * reset-controls.
Hans de Goede6c96f052016-02-23 18:46:24 +0100144 *
145 * Use of id names is optional.
146 */
Lee Jonesa53e35d2016-06-06 16:56:50 +0100147static inline struct reset_control *
148__must_check reset_control_get_exclusive(struct device *dev, const char *id)
Axel Lin5bcd0b72015-09-01 07:56:38 +0800149{
Philipp Zabelc84b0322019-02-21 16:25:53 +0100150 return __reset_control_get(dev, id, 0, false, false, true);
151}
152
153/**
154 * reset_control_get_exclusive_released - Lookup and obtain a temoprarily
155 * exclusive reference to a reset
156 * controller.
157 * @dev: device to be reset by the controller
158 * @id: reset line name
159 *
160 * Returns a struct reset_control or IS_ERR() condition containing errno.
161 * reset-controls returned by this function must be acquired via
162 * reset_control_acquire() before they can be used and should be released
163 * via reset_control_release() afterwards.
164 *
165 * Use of id names is optional.
166 */
167static inline struct reset_control *
168__must_check reset_control_get_exclusive_released(struct device *dev,
169 const char *id)
170{
171 return __reset_control_get(dev, id, 0, false, false, false);
Axel Lin5bcd0b72015-09-01 07:56:38 +0800172}
173
Hans de Goede6c96f052016-02-23 18:46:24 +0100174/**
Hans de Goede0b522972016-02-23 18:46:26 +0100175 * reset_control_get_shared - Lookup and obtain a shared reference to a
176 * reset controller.
177 * @dev: device to be reset by the controller
178 * @id: reset line name
179 *
180 * Returns a struct reset_control or IS_ERR() condition containing errno.
181 * This function is intended for use with reset-controls which are shared
Geert Uytterhoeven12c62b92018-10-08 13:15:43 +0200182 * between hardware blocks.
Hans de Goede0b522972016-02-23 18:46:26 +0100183 *
184 * When a reset-control is shared, the behavior of reset_control_assert /
185 * deassert is changed, the reset-core will keep track of a deassert_count
186 * and only (re-)assert the reset after reset_control_assert has been called
187 * as many times as reset_control_deassert was called. Also see the remark
188 * about shared reset-controls in the reset_control_assert docs.
189 *
190 * Calling reset_control_assert without first calling reset_control_deassert
191 * is not allowed on a shared reset control. Calling reset_control_reset is
192 * also not allowed on a shared reset control.
193 *
194 * Use of id names is optional.
195 */
196static inline struct reset_control *reset_control_get_shared(
197 struct device *dev, const char *id)
198{
Philipp Zabelc84b0322019-02-21 16:25:53 +0100199 return __reset_control_get(dev, id, 0, true, false, false);
Hans de Goede0b522972016-02-23 18:46:26 +0100200}
201
Lee Jonesa53e35d2016-06-06 16:56:50 +0100202static inline struct reset_control *reset_control_get_optional_exclusive(
Lee Jones3c35f6e2016-06-06 16:56:49 +0100203 struct device *dev, const char *id)
204{
Philipp Zabelc84b0322019-02-21 16:25:53 +0100205 return __reset_control_get(dev, id, 0, false, true, true);
Lee Jones3c35f6e2016-06-06 16:56:49 +0100206}
207
Lee Jonesc33d61a2016-06-06 16:56:52 +0100208static inline struct reset_control *reset_control_get_optional_shared(
209 struct device *dev, const char *id)
210{
Philipp Zabelc84b0322019-02-21 16:25:53 +0100211 return __reset_control_get(dev, id, 0, true, true, false);
Lee Jonesc33d61a2016-06-06 16:56:52 +0100212}
213
Hans de Goede0b522972016-02-23 18:46:26 +0100214/**
Lee Jonesa53e35d2016-06-06 16:56:50 +0100215 * of_reset_control_get_exclusive - Lookup and obtain an exclusive reference
216 * to a reset controller.
Hans de Goede6c96f052016-02-23 18:46:24 +0100217 * @node: device to be reset by the controller
218 * @id: reset line name
219 *
220 * Returns a struct reset_control or IS_ERR() condition containing errno.
221 *
222 * Use of id names is optional.
223 */
Lee Jonesa53e35d2016-06-06 16:56:50 +0100224static inline struct reset_control *of_reset_control_get_exclusive(
Hans de Goede6c96f052016-02-23 18:46:24 +0100225 struct device_node *node, const char *id)
226{
Philipp Zabelc84b0322019-02-21 16:25:53 +0100227 return __of_reset_control_get(node, id, 0, false, false, true);
Hans de Goede6c96f052016-02-23 18:46:24 +0100228}
229
230/**
Geert Uytterhoeven12c62b92018-10-08 13:15:43 +0200231 * of_reset_control_get_shared - Lookup and obtain a shared reference
Lee Jones40faee8e2016-06-06 16:56:51 +0100232 * to a reset controller.
233 * @node: device to be reset by the controller
234 * @id: reset line name
235 *
236 * When a reset-control is shared, the behavior of reset_control_assert /
237 * deassert is changed, the reset-core will keep track of a deassert_count
238 * and only (re-)assert the reset after reset_control_assert has been called
239 * as many times as reset_control_deassert was called. Also see the remark
240 * about shared reset-controls in the reset_control_assert docs.
241 *
242 * Calling reset_control_assert without first calling reset_control_deassert
243 * is not allowed on a shared reset control. Calling reset_control_reset is
244 * also not allowed on a shared reset control.
245 * Returns a struct reset_control or IS_ERR() condition containing errno.
246 *
247 * Use of id names is optional.
248 */
249static inline struct reset_control *of_reset_control_get_shared(
250 struct device_node *node, const char *id)
251{
Philipp Zabelc84b0322019-02-21 16:25:53 +0100252 return __of_reset_control_get(node, id, 0, true, false, false);
Lee Jones40faee8e2016-06-06 16:56:51 +0100253}
254
255/**
Lee Jonesa53e35d2016-06-06 16:56:50 +0100256 * of_reset_control_get_exclusive_by_index - Lookup and obtain an exclusive
257 * reference to a reset controller
258 * by index.
Hans de Goede6c96f052016-02-23 18:46:24 +0100259 * @node: device to be reset by the controller
260 * @index: index of the reset controller
261 *
262 * This is to be used to perform a list of resets for a device or power domain
263 * in whatever order. Returns a struct reset_control or IS_ERR() condition
264 * containing errno.
265 */
Lee Jonesa53e35d2016-06-06 16:56:50 +0100266static inline struct reset_control *of_reset_control_get_exclusive_by_index(
Hans de Goede6c96f052016-02-23 18:46:24 +0100267 struct device_node *node, int index)
268{
Philipp Zabelc84b0322019-02-21 16:25:53 +0100269 return __of_reset_control_get(node, NULL, index, false, false, true);
Hans de Goede6c96f052016-02-23 18:46:24 +0100270}
271
272/**
Geert Uytterhoeven12c62b92018-10-08 13:15:43 +0200273 * of_reset_control_get_shared_by_index - Lookup and obtain a shared
Lee Jones40faee8e2016-06-06 16:56:51 +0100274 * reference to a reset controller
275 * by index.
276 * @node: device to be reset by the controller
277 * @index: index of the reset controller
278 *
279 * When a reset-control is shared, the behavior of reset_control_assert /
280 * deassert is changed, the reset-core will keep track of a deassert_count
281 * and only (re-)assert the reset after reset_control_assert has been called
282 * as many times as reset_control_deassert was called. Also see the remark
283 * about shared reset-controls in the reset_control_assert docs.
284 *
285 * Calling reset_control_assert without first calling reset_control_deassert
286 * is not allowed on a shared reset control. Calling reset_control_reset is
287 * also not allowed on a shared reset control.
288 * Returns a struct reset_control or IS_ERR() condition containing errno.
289 *
290 * This is to be used to perform a list of resets for a device or power domain
291 * in whatever order. Returns a struct reset_control or IS_ERR() condition
292 * containing errno.
293 */
294static inline struct reset_control *of_reset_control_get_shared_by_index(
295 struct device_node *node, int index)
296{
Philipp Zabelc84b0322019-02-21 16:25:53 +0100297 return __of_reset_control_get(node, NULL, index, true, false, false);
Lee Jones40faee8e2016-06-06 16:56:51 +0100298}
299
300/**
Lee Jonesa53e35d2016-06-06 16:56:50 +0100301 * devm_reset_control_get_exclusive - resource managed
302 * reset_control_get_exclusive()
Hans de Goede6c96f052016-02-23 18:46:24 +0100303 * @dev: device to be reset by the controller
304 * @id: reset line name
305 *
Lee Jonesa53e35d2016-06-06 16:56:50 +0100306 * Managed reset_control_get_exclusive(). For reset controllers returned
307 * from this function, reset_control_put() is called automatically on driver
308 * detach.
309 *
310 * See reset_control_get_exclusive() for more information.
Hans de Goede6c96f052016-02-23 18:46:24 +0100311 */
Lee Jonesa53e35d2016-06-06 16:56:50 +0100312static inline struct reset_control *
313__must_check devm_reset_control_get_exclusive(struct device *dev,
314 const char *id)
Hans de Goede6c96f052016-02-23 18:46:24 +0100315{
Philipp Zabelc84b0322019-02-21 16:25:53 +0100316 return __devm_reset_control_get(dev, id, 0, false, false, true);
317}
318
319/**
320 * devm_reset_control_get_exclusive_released - resource managed
321 * reset_control_get_exclusive_released()
322 * @dev: device to be reset by the controller
323 * @id: reset line name
324 *
325 * Managed reset_control_get_exclusive_released(). For reset controllers
326 * returned from this function, reset_control_put() is called automatically on
327 * driver detach.
328 *
329 * See reset_control_get_exclusive_released() for more information.
330 */
331static inline struct reset_control *
332__must_check devm_reset_control_get_exclusive_released(struct device *dev,
333 const char *id)
334{
335 return __devm_reset_control_get(dev, id, 0, false, false, false);
Philipp Zabelb4240802014-03-07 15:18:47 +0100336}
337
Hans de Goede0b522972016-02-23 18:46:26 +0100338/**
339 * devm_reset_control_get_shared - resource managed reset_control_get_shared()
340 * @dev: device to be reset by the controller
341 * @id: reset line name
342 *
343 * Managed reset_control_get_shared(). For reset controllers returned from
344 * this function, reset_control_put() is called automatically on driver detach.
345 * See reset_control_get_shared() for more information.
346 */
347static inline struct reset_control *devm_reset_control_get_shared(
348 struct device *dev, const char *id)
349{
Philipp Zabelc84b0322019-02-21 16:25:53 +0100350 return __devm_reset_control_get(dev, id, 0, true, false, false);
Hans de Goede0b522972016-02-23 18:46:26 +0100351}
352
Lee Jonesa53e35d2016-06-06 16:56:50 +0100353static inline struct reset_control *devm_reset_control_get_optional_exclusive(
Philipp Zabelb4240802014-03-07 15:18:47 +0100354 struct device *dev, const char *id)
355{
Philipp Zabelc84b0322019-02-21 16:25:53 +0100356 return __devm_reset_control_get(dev, id, 0, false, true, true);
Philipp Zabelb4240802014-03-07 15:18:47 +0100357}
358
Lee Jonesc33d61a2016-06-06 16:56:52 +0100359static inline struct reset_control *devm_reset_control_get_optional_shared(
360 struct device *dev, const char *id)
361{
Philipp Zabelc84b0322019-02-21 16:25:53 +0100362 return __devm_reset_control_get(dev, id, 0, true, true, false);
Lee Jonesc33d61a2016-06-06 16:56:52 +0100363}
364
Hans de Goede6c96f052016-02-23 18:46:24 +0100365/**
Lee Jonesa53e35d2016-06-06 16:56:50 +0100366 * devm_reset_control_get_exclusive_by_index - resource managed
367 * reset_control_get_exclusive()
Hans de Goede6c96f052016-02-23 18:46:24 +0100368 * @dev: device to be reset by the controller
369 * @index: index of the reset controller
370 *
Lee Jonesa53e35d2016-06-06 16:56:50 +0100371 * Managed reset_control_get_exclusive(). For reset controllers returned from
372 * this function, reset_control_put() is called automatically on driver
373 * detach.
374 *
375 * See reset_control_get_exclusive() for more information.
Hans de Goede6c96f052016-02-23 18:46:24 +0100376 */
Lee Jonesa53e35d2016-06-06 16:56:50 +0100377static inline struct reset_control *
378devm_reset_control_get_exclusive_by_index(struct device *dev, int index)
Hans de Goedee3ec0a82014-04-13 14:09:15 +0200379{
Philipp Zabelc84b0322019-02-21 16:25:53 +0100380 return __devm_reset_control_get(dev, NULL, index, false, false, true);
Hans de Goede0b522972016-02-23 18:46:26 +0100381}
382
Hans de Goede0b522972016-02-23 18:46:26 +0100383/**
384 * devm_reset_control_get_shared_by_index - resource managed
Geert Uytterhoeven12c62b92018-10-08 13:15:43 +0200385 * reset_control_get_shared
Hans de Goede0b522972016-02-23 18:46:26 +0100386 * @dev: device to be reset by the controller
387 * @index: index of the reset controller
388 *
389 * Managed reset_control_get_shared(). For reset controllers returned from
390 * this function, reset_control_put() is called automatically on driver detach.
391 * See reset_control_get_shared() for more information.
392 */
Lee Jones0bcc0ea2016-06-06 16:56:53 +0100393static inline struct reset_control *
394devm_reset_control_get_shared_by_index(struct device *dev, int index)
Hans de Goede0b522972016-02-23 18:46:26 +0100395{
Philipp Zabelc84b0322019-02-21 16:25:53 +0100396 return __devm_reset_control_get(dev, NULL, index, true, false, false);
Hans de Goedee3ec0a82014-04-13 14:09:15 +0200397}
398
Lee Jonesa53e35d2016-06-06 16:56:50 +0100399/*
400 * TEMPORARY calls to use during transition:
401 *
402 * of_reset_control_get() => of_reset_control_get_exclusive()
403 *
404 * These inline function calls will be removed once all consumers
405 * have been moved over to the new explicit API.
406 */
Lee Jonesa53e35d2016-06-06 16:56:50 +0100407static inline struct reset_control *of_reset_control_get(
408 struct device_node *node, const char *id)
409{
410 return of_reset_control_get_exclusive(node, id);
411}
412
413static inline struct reset_control *of_reset_control_get_by_index(
414 struct device_node *node, int index)
415{
416 return of_reset_control_get_exclusive_by_index(node, index);
417}
418
419static inline struct reset_control *devm_reset_control_get(
420 struct device *dev, const char *id)
421{
422 return devm_reset_control_get_exclusive(dev, id);
423}
424
425static inline struct reset_control *devm_reset_control_get_optional(
426 struct device *dev, const char *id)
427{
428 return devm_reset_control_get_optional_exclusive(dev, id);
429
430}
431
432static inline struct reset_control *devm_reset_control_get_by_index(
433 struct device *dev, int index)
434{
435 return devm_reset_control_get_exclusive_by_index(dev, index);
436}
Vivek Gautam17c82e22017-05-22 16:53:25 +0530437
438/*
439 * APIs to manage a list of reset controllers
440 */
441static inline struct reset_control *
442devm_reset_control_array_get_exclusive(struct device *dev)
443{
444 return devm_reset_control_array_get(dev, false, false);
445}
446
447static inline struct reset_control *
448devm_reset_control_array_get_shared(struct device *dev)
449{
450 return devm_reset_control_array_get(dev, true, false);
451}
452
453static inline struct reset_control *
454devm_reset_control_array_get_optional_exclusive(struct device *dev)
455{
456 return devm_reset_control_array_get(dev, false, true);
457}
458
459static inline struct reset_control *
460devm_reset_control_array_get_optional_shared(struct device *dev)
461{
462 return devm_reset_control_array_get(dev, true, true);
463}
464
465static inline struct reset_control *
466of_reset_control_array_get_exclusive(struct device_node *node)
467{
468 return of_reset_control_array_get(node, false, false);
469}
470
471static inline struct reset_control *
472of_reset_control_array_get_shared(struct device_node *node)
473{
474 return of_reset_control_array_get(node, true, false);
475}
476
477static inline struct reset_control *
478of_reset_control_array_get_optional_exclusive(struct device_node *node)
479{
480 return of_reset_control_array_get(node, false, true);
481}
482
483static inline struct reset_control *
484of_reset_control_array_get_optional_shared(struct device_node *node)
485{
486 return of_reset_control_array_get(node, true, true);
487}
Philipp Zabel61fc4132012-11-19 17:23:13 +0100488#endif