1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_RESET_H_
3 #define _LINUX_RESET_H_
5 #include <linux/types.h>
11 #ifdef CONFIG_RESET_CONTROLLER
13 int reset_control_reset(struct reset_control *rstc);
14 int reset_control_assert(struct reset_control *rstc);
15 int reset_control_deassert(struct reset_control *rstc);
16 int reset_control_status(struct reset_control *rstc);
18 struct reset_control *__of_reset_control_get(struct device_node *node,
19 const char *id, int index, bool shared,
21 struct reset_control *__reset_control_get(struct device *dev, const char *id,
22 int index, bool shared,
24 void reset_control_put(struct reset_control *rstc);
25 int __device_reset(struct device *dev, bool optional);
26 struct reset_control *__devm_reset_control_get(struct device *dev,
27 const char *id, int index, bool shared,
30 struct reset_control *devm_reset_control_array_get(struct device *dev,
31 bool shared, bool optional);
32 struct reset_control *of_reset_control_array_get(struct device_node *np,
33 bool shared, bool optional);
35 int reset_control_get_count(struct device *dev);
39 static inline int reset_control_reset(struct reset_control *rstc)
44 static inline int reset_control_assert(struct reset_control *rstc)
49 static inline int reset_control_deassert(struct reset_control *rstc)
54 static inline int reset_control_status(struct reset_control *rstc)
59 static inline void reset_control_put(struct reset_control *rstc)
63 static inline int __device_reset(struct device *dev, bool optional)
65 return optional ? 0 : -ENOTSUPP;
68 static inline struct reset_control *__of_reset_control_get(
69 struct device_node *node,
70 const char *id, int index, bool shared,
73 return optional ? NULL : ERR_PTR(-ENOTSUPP);
76 static inline struct reset_control *__reset_control_get(
77 struct device *dev, const char *id,
78 int index, bool shared, bool optional)
80 return optional ? NULL : ERR_PTR(-ENOTSUPP);
83 static inline struct reset_control *__devm_reset_control_get(
84 struct device *dev, const char *id,
85 int index, bool shared, bool optional)
87 return optional ? NULL : ERR_PTR(-ENOTSUPP);
90 static inline struct reset_control *
91 devm_reset_control_array_get(struct device *dev, bool shared, bool optional)
93 return optional ? NULL : ERR_PTR(-ENOTSUPP);
96 static inline struct reset_control *
97 of_reset_control_array_get(struct device_node *np, bool shared, bool optional)
99 return optional ? NULL : ERR_PTR(-ENOTSUPP);
102 static inline int reset_control_get_count(struct device *dev)
107 #endif /* CONFIG_RESET_CONTROLLER */
109 static inline int __must_check device_reset(struct device *dev)
111 return __device_reset(dev, false);
114 static inline int device_reset_optional(struct device *dev)
116 return __device_reset(dev, true);
120 * reset_control_get_exclusive - Lookup and obtain an exclusive reference
121 * to a reset controller.
122 * @dev: device to be reset by the controller
123 * @id: reset line name
125 * Returns a struct reset_control or IS_ERR() condition containing errno.
126 * If this function is called more than once for the same reset_control it will
129 * See reset_control_get_shared for details on shared references to
132 * Use of id names is optional.
134 static inline struct reset_control *
135 __must_check reset_control_get_exclusive(struct device *dev, const char *id)
137 return __reset_control_get(dev, id, 0, false, false);
141 * reset_control_get_shared - Lookup and obtain a shared reference to a
143 * @dev: device to be reset by the controller
144 * @id: reset line name
146 * Returns a struct reset_control or IS_ERR() condition containing errno.
147 * This function is intended for use with reset-controls which are shared
148 * between hardware blocks.
150 * When a reset-control is shared, the behavior of reset_control_assert /
151 * deassert is changed, the reset-core will keep track of a deassert_count
152 * and only (re-)assert the reset after reset_control_assert has been called
153 * as many times as reset_control_deassert was called. Also see the remark
154 * about shared reset-controls in the reset_control_assert docs.
156 * Calling reset_control_assert without first calling reset_control_deassert
157 * is not allowed on a shared reset control. Calling reset_control_reset is
158 * also not allowed on a shared reset control.
160 * Use of id names is optional.
162 static inline struct reset_control *reset_control_get_shared(
163 struct device *dev, const char *id)
165 return __reset_control_get(dev, id, 0, true, false);
168 static inline struct reset_control *reset_control_get_optional_exclusive(
169 struct device *dev, const char *id)
171 return __reset_control_get(dev, id, 0, false, true);
174 static inline struct reset_control *reset_control_get_optional_shared(
175 struct device *dev, const char *id)
177 return __reset_control_get(dev, id, 0, true, true);
181 * of_reset_control_get_exclusive - Lookup and obtain an exclusive reference
182 * to a reset controller.
183 * @node: device to be reset by the controller
184 * @id: reset line name
186 * Returns a struct reset_control or IS_ERR() condition containing errno.
188 * Use of id names is optional.
190 static inline struct reset_control *of_reset_control_get_exclusive(
191 struct device_node *node, const char *id)
193 return __of_reset_control_get(node, id, 0, false, false);
197 * of_reset_control_get_shared - Lookup and obtain a shared reference
198 * to a reset controller.
199 * @node: device to be reset by the controller
200 * @id: reset line name
202 * When a reset-control is shared, the behavior of reset_control_assert /
203 * deassert is changed, the reset-core will keep track of a deassert_count
204 * and only (re-)assert the reset after reset_control_assert has been called
205 * as many times as reset_control_deassert was called. Also see the remark
206 * about shared reset-controls in the reset_control_assert docs.
208 * Calling reset_control_assert without first calling reset_control_deassert
209 * is not allowed on a shared reset control. Calling reset_control_reset is
210 * also not allowed on a shared reset control.
211 * Returns a struct reset_control or IS_ERR() condition containing errno.
213 * Use of id names is optional.
215 static inline struct reset_control *of_reset_control_get_shared(
216 struct device_node *node, const char *id)
218 return __of_reset_control_get(node, id, 0, true, false);
222 * of_reset_control_get_exclusive_by_index - Lookup and obtain an exclusive
223 * reference to a reset controller
225 * @node: device to be reset by the controller
226 * @index: index of the reset controller
228 * This is to be used to perform a list of resets for a device or power domain
229 * in whatever order. Returns a struct reset_control or IS_ERR() condition
232 static inline struct reset_control *of_reset_control_get_exclusive_by_index(
233 struct device_node *node, int index)
235 return __of_reset_control_get(node, NULL, index, false, false);
239 * of_reset_control_get_shared_by_index - Lookup and obtain a shared
240 * reference to a reset controller
242 * @node: device to be reset by the controller
243 * @index: index of the reset controller
245 * When a reset-control is shared, the behavior of reset_control_assert /
246 * deassert is changed, the reset-core will keep track of a deassert_count
247 * and only (re-)assert the reset after reset_control_assert has been called
248 * as many times as reset_control_deassert was called. Also see the remark
249 * about shared reset-controls in the reset_control_assert docs.
251 * Calling reset_control_assert without first calling reset_control_deassert
252 * is not allowed on a shared reset control. Calling reset_control_reset is
253 * also not allowed on a shared reset control.
254 * Returns a struct reset_control or IS_ERR() condition containing errno.
256 * This is to be used to perform a list of resets for a device or power domain
257 * in whatever order. Returns a struct reset_control or IS_ERR() condition
260 static inline struct reset_control *of_reset_control_get_shared_by_index(
261 struct device_node *node, int index)
263 return __of_reset_control_get(node, NULL, index, true, false);
267 * devm_reset_control_get_exclusive - resource managed
268 * reset_control_get_exclusive()
269 * @dev: device to be reset by the controller
270 * @id: reset line name
272 * Managed reset_control_get_exclusive(). For reset controllers returned
273 * from this function, reset_control_put() is called automatically on driver
276 * See reset_control_get_exclusive() for more information.
278 static inline struct reset_control *
279 __must_check devm_reset_control_get_exclusive(struct device *dev,
282 return __devm_reset_control_get(dev, id, 0, false, false);
286 * devm_reset_control_get_shared - resource managed reset_control_get_shared()
287 * @dev: device to be reset by the controller
288 * @id: reset line name
290 * Managed reset_control_get_shared(). For reset controllers returned from
291 * this function, reset_control_put() is called automatically on driver detach.
292 * See reset_control_get_shared() for more information.
294 static inline struct reset_control *devm_reset_control_get_shared(
295 struct device *dev, const char *id)
297 return __devm_reset_control_get(dev, id, 0, true, false);
300 static inline struct reset_control *devm_reset_control_get_optional_exclusive(
301 struct device *dev, const char *id)
303 return __devm_reset_control_get(dev, id, 0, false, true);
306 static inline struct reset_control *devm_reset_control_get_optional_shared(
307 struct device *dev, const char *id)
309 return __devm_reset_control_get(dev, id, 0, true, true);
313 * devm_reset_control_get_exclusive_by_index - resource managed
314 * reset_control_get_exclusive()
315 * @dev: device to be reset by the controller
316 * @index: index of the reset controller
318 * Managed reset_control_get_exclusive(). For reset controllers returned from
319 * this function, reset_control_put() is called automatically on driver
322 * See reset_control_get_exclusive() for more information.
324 static inline struct reset_control *
325 devm_reset_control_get_exclusive_by_index(struct device *dev, int index)
327 return __devm_reset_control_get(dev, NULL, index, false, false);
331 * devm_reset_control_get_shared_by_index - resource managed
332 * reset_control_get_shared
333 * @dev: device to be reset by the controller
334 * @index: index of the reset controller
336 * Managed reset_control_get_shared(). For reset controllers returned from
337 * this function, reset_control_put() is called automatically on driver detach.
338 * See reset_control_get_shared() for more information.
340 static inline struct reset_control *
341 devm_reset_control_get_shared_by_index(struct device *dev, int index)
343 return __devm_reset_control_get(dev, NULL, index, true, false);
347 * TEMPORARY calls to use during transition:
349 * of_reset_control_get() => of_reset_control_get_exclusive()
351 * These inline function calls will be removed once all consumers
352 * have been moved over to the new explicit API.
354 static inline struct reset_control *of_reset_control_get(
355 struct device_node *node, const char *id)
357 return of_reset_control_get_exclusive(node, id);
360 static inline struct reset_control *of_reset_control_get_by_index(
361 struct device_node *node, int index)
363 return of_reset_control_get_exclusive_by_index(node, index);
366 static inline struct reset_control *devm_reset_control_get(
367 struct device *dev, const char *id)
369 return devm_reset_control_get_exclusive(dev, id);
372 static inline struct reset_control *devm_reset_control_get_optional(
373 struct device *dev, const char *id)
375 return devm_reset_control_get_optional_exclusive(dev, id);
379 static inline struct reset_control *devm_reset_control_get_by_index(
380 struct device *dev, int index)
382 return devm_reset_control_get_exclusive_by_index(dev, index);
386 * APIs to manage a list of reset controllers
388 static inline struct reset_control *
389 devm_reset_control_array_get_exclusive(struct device *dev)
391 return devm_reset_control_array_get(dev, false, false);
394 static inline struct reset_control *
395 devm_reset_control_array_get_shared(struct device *dev)
397 return devm_reset_control_array_get(dev, true, false);
400 static inline struct reset_control *
401 devm_reset_control_array_get_optional_exclusive(struct device *dev)
403 return devm_reset_control_array_get(dev, false, true);
406 static inline struct reset_control *
407 devm_reset_control_array_get_optional_shared(struct device *dev)
409 return devm_reset_control_array_get(dev, true, true);
412 static inline struct reset_control *
413 of_reset_control_array_get_exclusive(struct device_node *node)
415 return of_reset_control_array_get(node, false, false);
418 static inline struct reset_control *
419 of_reset_control_array_get_shared(struct device_node *node)
421 return of_reset_control_array_get(node, true, false);
424 static inline struct reset_control *
425 of_reset_control_array_get_optional_exclusive(struct device_node *node)
427 return of_reset_control_array_get(node, false, true);
430 static inline struct reset_control *
431 of_reset_control_array_get_optional_shared(struct device_node *node)
433 return of_reset_control_array_get(node, true, true);