1 #ifndef _LINUX_RESET_H_
2 #define _LINUX_RESET_H_
4 #include <linux/device.h>
8 #ifdef CONFIG_RESET_CONTROLLER
10 int reset_control_reset(struct reset_control *rstc);
11 int reset_control_assert(struct reset_control *rstc);
12 int reset_control_deassert(struct reset_control *rstc);
13 int reset_control_status(struct reset_control *rstc);
15 struct reset_control *__of_reset_control_get(struct device_node *node,
16 const char *id, int index, bool shared,
18 struct reset_control *__reset_control_get(struct device *dev, const char *id,
19 int index, bool shared,
21 void reset_control_put(struct reset_control *rstc);
22 int __device_reset(struct device *dev, bool optional);
23 struct reset_control *__devm_reset_control_get(struct device *dev,
24 const char *id, int index, bool shared,
29 static inline int reset_control_reset(struct reset_control *rstc)
34 static inline int reset_control_assert(struct reset_control *rstc)
39 static inline int reset_control_deassert(struct reset_control *rstc)
44 static inline int reset_control_status(struct reset_control *rstc)
49 static inline void reset_control_put(struct reset_control *rstc)
53 static inline int __device_reset(struct device *dev, bool optional)
55 return optional ? 0 : -ENOTSUPP;
58 static inline struct reset_control *__of_reset_control_get(
59 struct device_node *node,
60 const char *id, int index, bool shared,
63 return optional ? NULL : ERR_PTR(-ENOTSUPP);
66 static inline struct reset_control *__reset_control_get(
67 struct device *dev, const char *id,
68 int index, bool shared, bool optional)
70 return optional ? NULL : ERR_PTR(-ENOTSUPP);
73 static inline struct reset_control *__devm_reset_control_get(
74 struct device *dev, const char *id,
75 int index, bool shared, bool optional)
77 return optional ? NULL : ERR_PTR(-ENOTSUPP);
80 #endif /* CONFIG_RESET_CONTROLLER */
82 static inline int __must_check device_reset(struct device *dev)
84 return __device_reset(dev, false);
87 static inline int device_reset_optional(struct device *dev)
89 return __device_reset(dev, true);
93 * reset_control_get_exclusive - Lookup and obtain an exclusive reference
94 * to a reset controller.
95 * @dev: device to be reset by the controller
96 * @id: reset line name
98 * Returns a struct reset_control or IS_ERR() condition containing errno.
99 * If this function is called more then once for the same reset_control it will
102 * See reset_control_get_shared for details on shared references to
105 * Use of id names is optional.
107 static inline struct reset_control *
108 __must_check reset_control_get_exclusive(struct device *dev, const char *id)
110 return __reset_control_get(dev, id, 0, false, false);
114 * reset_control_get_shared - Lookup and obtain a shared reference to a
116 * @dev: device to be reset by the controller
117 * @id: reset line name
119 * Returns a struct reset_control or IS_ERR() condition containing errno.
120 * This function is intended for use with reset-controls which are shared
121 * between hardware-blocks.
123 * When a reset-control is shared, the behavior of reset_control_assert /
124 * deassert is changed, the reset-core will keep track of a deassert_count
125 * and only (re-)assert the reset after reset_control_assert has been called
126 * as many times as reset_control_deassert was called. Also see the remark
127 * about shared reset-controls in the reset_control_assert docs.
129 * Calling reset_control_assert without first calling reset_control_deassert
130 * is not allowed on a shared reset control. Calling reset_control_reset is
131 * also not allowed on a shared reset control.
133 * Use of id names is optional.
135 static inline struct reset_control *reset_control_get_shared(
136 struct device *dev, const char *id)
138 return __reset_control_get(dev, id, 0, true, false);
141 static inline struct reset_control *reset_control_get_optional_exclusive(
142 struct device *dev, const char *id)
144 return __reset_control_get(dev, id, 0, false, true);
147 static inline struct reset_control *reset_control_get_optional_shared(
148 struct device *dev, const char *id)
150 return __reset_control_get(dev, id, 0, true, true);
154 * of_reset_control_get_exclusive - Lookup and obtain an exclusive reference
155 * to a reset controller.
156 * @node: device to be reset by the controller
157 * @id: reset line name
159 * Returns a struct reset_control or IS_ERR() condition containing errno.
161 * Use of id names is optional.
163 static inline struct reset_control *of_reset_control_get_exclusive(
164 struct device_node *node, const char *id)
166 return __of_reset_control_get(node, id, 0, false, false);
170 * of_reset_control_get_shared - Lookup and obtain an shared reference
171 * to a reset controller.
172 * @node: device to be reset by the controller
173 * @id: reset line name
175 * When a reset-control is shared, the behavior of reset_control_assert /
176 * deassert is changed, the reset-core will keep track of a deassert_count
177 * and only (re-)assert the reset after reset_control_assert has been called
178 * as many times as reset_control_deassert was called. Also see the remark
179 * about shared reset-controls in the reset_control_assert docs.
181 * Calling reset_control_assert without first calling reset_control_deassert
182 * is not allowed on a shared reset control. Calling reset_control_reset is
183 * also not allowed on a shared reset control.
184 * Returns a struct reset_control or IS_ERR() condition containing errno.
186 * Use of id names is optional.
188 static inline struct reset_control *of_reset_control_get_shared(
189 struct device_node *node, const char *id)
191 return __of_reset_control_get(node, id, 0, true, false);
195 * of_reset_control_get_exclusive_by_index - Lookup and obtain an exclusive
196 * reference to a reset controller
198 * @node: device to be reset by the controller
199 * @index: index of the reset controller
201 * This is to be used to perform a list of resets for a device or power domain
202 * in whatever order. Returns a struct reset_control or IS_ERR() condition
205 static inline struct reset_control *of_reset_control_get_exclusive_by_index(
206 struct device_node *node, int index)
208 return __of_reset_control_get(node, NULL, index, false, false);
212 * of_reset_control_get_shared_by_index - Lookup and obtain an shared
213 * reference to a reset controller
215 * @node: device to be reset by the controller
216 * @index: index of the reset controller
218 * When a reset-control is shared, the behavior of reset_control_assert /
219 * deassert is changed, the reset-core will keep track of a deassert_count
220 * and only (re-)assert the reset after reset_control_assert has been called
221 * as many times as reset_control_deassert was called. Also see the remark
222 * about shared reset-controls in the reset_control_assert docs.
224 * Calling reset_control_assert without first calling reset_control_deassert
225 * is not allowed on a shared reset control. Calling reset_control_reset is
226 * also not allowed on a shared reset control.
227 * Returns a struct reset_control or IS_ERR() condition containing errno.
229 * This is to be used to perform a list of resets for a device or power domain
230 * in whatever order. Returns a struct reset_control or IS_ERR() condition
233 static inline struct reset_control *of_reset_control_get_shared_by_index(
234 struct device_node *node, int index)
236 return __of_reset_control_get(node, NULL, index, true, false);
240 * devm_reset_control_get_exclusive - resource managed
241 * reset_control_get_exclusive()
242 * @dev: device to be reset by the controller
243 * @id: reset line name
245 * Managed reset_control_get_exclusive(). For reset controllers returned
246 * from this function, reset_control_put() is called automatically on driver
249 * See reset_control_get_exclusive() for more information.
251 static inline struct reset_control *
252 __must_check devm_reset_control_get_exclusive(struct device *dev,
255 return __devm_reset_control_get(dev, id, 0, false, false);
259 * devm_reset_control_get_shared - resource managed reset_control_get_shared()
260 * @dev: device to be reset by the controller
261 * @id: reset line name
263 * Managed reset_control_get_shared(). For reset controllers returned from
264 * this function, reset_control_put() is called automatically on driver detach.
265 * See reset_control_get_shared() for more information.
267 static inline struct reset_control *devm_reset_control_get_shared(
268 struct device *dev, const char *id)
270 return __devm_reset_control_get(dev, id, 0, true, false);
273 static inline struct reset_control *devm_reset_control_get_optional_exclusive(
274 struct device *dev, const char *id)
276 return __devm_reset_control_get(dev, id, 0, false, true);
279 static inline struct reset_control *devm_reset_control_get_optional_shared(
280 struct device *dev, const char *id)
282 return __devm_reset_control_get(dev, id, 0, true, true);
286 * devm_reset_control_get_exclusive_by_index - resource managed
287 * reset_control_get_exclusive()
288 * @dev: device to be reset by the controller
289 * @index: index of the reset controller
291 * Managed reset_control_get_exclusive(). For reset controllers returned from
292 * this function, reset_control_put() is called automatically on driver
295 * See reset_control_get_exclusive() for more information.
297 static inline struct reset_control *
298 devm_reset_control_get_exclusive_by_index(struct device *dev, int index)
300 return __devm_reset_control_get(dev, NULL, index, false, false);
304 * devm_reset_control_get_shared_by_index - resource managed
305 * reset_control_get_shared
306 * @dev: device to be reset by the controller
307 * @index: index of the reset controller
309 * Managed reset_control_get_shared(). For reset controllers returned from
310 * this function, reset_control_put() is called automatically on driver detach.
311 * See reset_control_get_shared() for more information.
313 static inline struct reset_control *
314 devm_reset_control_get_shared_by_index(struct device *dev, int index)
316 return __devm_reset_control_get(dev, NULL, index, true, false);
320 * TEMPORARY calls to use during transition:
322 * of_reset_control_get() => of_reset_control_get_exclusive()
324 * These inline function calls will be removed once all consumers
325 * have been moved over to the new explicit API.
327 static inline struct reset_control *reset_control_get(
328 struct device *dev, const char *id)
330 return reset_control_get_exclusive(dev, id);
333 static inline struct reset_control *reset_control_get_optional(
334 struct device *dev, const char *id)
336 return reset_control_get_optional_exclusive(dev, id);
339 static inline struct reset_control *of_reset_control_get(
340 struct device_node *node, const char *id)
342 return of_reset_control_get_exclusive(node, id);
345 static inline struct reset_control *of_reset_control_get_by_index(
346 struct device_node *node, int index)
348 return of_reset_control_get_exclusive_by_index(node, index);
351 static inline struct reset_control *devm_reset_control_get(
352 struct device *dev, const char *id)
354 return devm_reset_control_get_exclusive(dev, id);
357 static inline struct reset_control *devm_reset_control_get_optional(
358 struct device *dev, const char *id)
360 return devm_reset_control_get_optional_exclusive(dev, id);
364 static inline struct reset_control *devm_reset_control_get_by_index(
365 struct device *dev, int index)
367 return devm_reset_control_get_exclusive_by_index(dev, index);