blob: a552134a209e5ab2ac7c17b6ee378b06caffac48 [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
59static inline int device_reset_optional(struct device *dev)
60{
Philipp Zabel39b4da72015-10-29 09:55:00 +010061 return -ENOTSUPP;
Philipp Zabelb4240802014-03-07 15:18:47 +010062}
63
Hans de Goede6c96f052016-02-23 18:46:24 +010064static inline struct reset_control *__of_reset_control_get(
65 struct device_node *node,
Hans de Goede0b522972016-02-23 18:46:26 +010066 const char *id, int index, int shared)
Axel Lin5bcd0b72015-09-01 07:56:38 +080067{
Axel Lin5bcd0b72015-09-01 07:56:38 +080068 return ERR_PTR(-EINVAL);
69}
70
Hans de Goede6c96f052016-02-23 18:46:24 +010071static inline struct reset_control *__devm_reset_control_get(
72 struct device *dev,
Hans de Goede0b522972016-02-23 18:46:26 +010073 const char *id, int index, int shared)
Hans de Goede6c96f052016-02-23 18:46:24 +010074{
75 return ERR_PTR(-EINVAL);
76}
77
78#endif /* CONFIG_RESET_CONTROLLER */
79
80/**
Hans de Goede0b522972016-02-23 18:46:26 +010081 * reset_control_get - Lookup and obtain an exclusive reference to a
82 * reset controller.
Hans de Goede6c96f052016-02-23 18:46:24 +010083 * @dev: device to be reset by the controller
84 * @id: reset line name
85 *
86 * Returns a struct reset_control or IS_ERR() condition containing errno.
Hans de Goede0b522972016-02-23 18:46:26 +010087 * If this function is called more then once for the same reset_control it will
88 * return -EBUSY.
89 *
90 * See reset_control_get_shared for details on shared references to
91 * reset-controls.
Hans de Goede6c96f052016-02-23 18:46:24 +010092 *
93 * Use of id names is optional.
94 */
95static inline struct reset_control *__must_check reset_control_get(
Axel Lin5bcd0b72015-09-01 07:56:38 +080096 struct device *dev, const char *id)
97{
Hans de Goede6c96f052016-02-23 18:46:24 +010098#ifndef CONFIG_RESET_CONTROLLER
Axel Lin5bcd0b72015-09-01 07:56:38 +080099 WARN_ON(1);
Hans de Goede6c96f052016-02-23 18:46:24 +0100100#endif
Hans de Goede0b522972016-02-23 18:46:26 +0100101 return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, 0);
Axel Lin5bcd0b72015-09-01 07:56:38 +0800102}
103
Philipp Zabelb4240802014-03-07 15:18:47 +0100104static inline struct reset_control *reset_control_get_optional(
105 struct device *dev, const char *id)
106{
Hans de Goede0b522972016-02-23 18:46:26 +0100107 return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, 0);
Hans de Goede6c96f052016-02-23 18:46:24 +0100108}
109
110/**
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
138/**
139 * of_reset_control_get - Lookup and obtain an exclusive reference to a
140 * reset controller.
Hans de Goede6c96f052016-02-23 18:46:24 +0100141 * @node: device to be reset by the controller
142 * @id: reset line name
143 *
144 * Returns a struct reset_control or IS_ERR() condition containing errno.
145 *
146 * Use of id names is optional.
147 */
148static inline struct reset_control *of_reset_control_get(
149 struct device_node *node, const char *id)
150{
Hans de Goede0b522972016-02-23 18:46:26 +0100151 return __of_reset_control_get(node, id, 0, 0);
Hans de Goede6c96f052016-02-23 18:46:24 +0100152}
153
154/**
Hans de Goede0b522972016-02-23 18:46:26 +0100155 * of_reset_control_get_by_index - Lookup and obtain an exclusive reference to
156 * a reset controller by index.
Hans de Goede6c96f052016-02-23 18:46:24 +0100157 * @node: device to be reset by the controller
158 * @index: index of the reset controller
159 *
160 * This is to be used to perform a list of resets for a device or power domain
161 * in whatever order. Returns a struct reset_control or IS_ERR() condition
162 * containing errno.
163 */
164static inline struct reset_control *of_reset_control_get_by_index(
165 struct device_node *node, int index)
166{
Hans de Goede0b522972016-02-23 18:46:26 +0100167 return __of_reset_control_get(node, NULL, index, 0);
Hans de Goede6c96f052016-02-23 18:46:24 +0100168}
169
170/**
171 * devm_reset_control_get - resource managed reset_control_get()
172 * @dev: device to be reset by the controller
173 * @id: reset line name
174 *
175 * Managed reset_control_get(). For reset controllers returned from this
176 * function, reset_control_put() is called automatically on driver detach.
177 * See reset_control_get() for more information.
178 */
179static inline struct reset_control *__must_check devm_reset_control_get(
180 struct device *dev, const char *id)
181{
182#ifndef CONFIG_RESET_CONTROLLER
183 WARN_ON(1);
184#endif
Hans de Goede0b522972016-02-23 18:46:26 +0100185 return __devm_reset_control_get(dev, id, 0, 0);
Philipp Zabelb4240802014-03-07 15:18:47 +0100186}
187
188static inline struct reset_control *devm_reset_control_get_optional(
189 struct device *dev, const char *id)
190{
Hans de Goede0b522972016-02-23 18:46:26 +0100191 return __devm_reset_control_get(dev, id, 0, 0);
Philipp Zabelb4240802014-03-07 15:18:47 +0100192}
193
Hans de Goede6c96f052016-02-23 18:46:24 +0100194/**
195 * devm_reset_control_get_by_index - resource managed reset_control_get
196 * @dev: device to be reset by the controller
197 * @index: index of the reset controller
198 *
199 * Managed reset_control_get(). For reset controllers returned from this
200 * function, reset_control_put() is called automatically on driver detach.
201 * See reset_control_get() for more information.
202 */
203static inline struct reset_control *devm_reset_control_get_by_index(
204 struct device *dev, int index)
Hans de Goedee3ec0a82014-04-13 14:09:15 +0200205{
Hans de Goede0b522972016-02-23 18:46:26 +0100206 return __devm_reset_control_get(dev, NULL, index, 0);
207}
208
209/**
210 * devm_reset_control_get_shared - resource managed reset_control_get_shared()
211 * @dev: device to be reset by the controller
212 * @id: reset line name
213 *
214 * Managed reset_control_get_shared(). For reset controllers returned from
215 * this function, reset_control_put() is called automatically on driver detach.
216 * See reset_control_get_shared() for more information.
217 */
218static inline struct reset_control *devm_reset_control_get_shared(
219 struct device *dev, const char *id)
220{
221 return __devm_reset_control_get(dev, id, 0, 1);
222}
223
224/**
225 * devm_reset_control_get_shared_by_index - resource managed
226 * reset_control_get_shared
227 * @dev: device to be reset by the controller
228 * @index: index of the reset controller
229 *
230 * Managed reset_control_get_shared(). For reset controllers returned from
231 * this function, reset_control_put() is called automatically on driver detach.
232 * See reset_control_get_shared() for more information.
233 */
234static inline struct reset_control *devm_reset_control_get_shared_by_index(
235 struct device *dev, int index)
236{
237 return __devm_reset_control_get(dev, NULL, index, 1);
Hans de Goedee3ec0a82014-04-13 14:09:15 +0200238}
239
Philipp Zabel61fc4132012-11-19 17:23:13 +0100240#endif