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 void reset_control_put(struct reset_control *rstc);
19 struct reset_control *__devm_reset_control_get(struct device *dev,
20 const char *id, int index, bool shared,
23 int __must_check device_reset(struct device *dev);
25 static inline int device_reset_optional(struct device *dev)
27 return device_reset(dev);
32 static inline int reset_control_reset(struct reset_control *rstc)
37 static inline int reset_control_assert(struct reset_control *rstc)
42 static inline int reset_control_deassert(struct reset_control *rstc)
47 static inline int reset_control_status(struct reset_control *rstc)
52 static inline void reset_control_put(struct reset_control *rstc)
56 static inline int __must_check device_reset(struct device *dev)
62 static inline int device_reset_optional(struct device *dev)
67 static inline struct reset_control *__of_reset_control_get(
68 struct device_node *node,
69 const char *id, int index, bool shared,
72 return optional ? NULL : ERR_PTR(-ENOTSUPP);
75 static inline struct reset_control *__devm_reset_control_get(
76 struct device *dev, const char *id,
77 int index, bool shared, bool optional)
79 return optional ? NULL : ERR_PTR(-ENOTSUPP);
82 #endif /* CONFIG_RESET_CONTROLLER */
85 * reset_control_get_exclusive - Lookup and obtain an exclusive reference
86 * to a reset controller.
87 * @dev: device to be reset by the controller
88 * @id: reset line name
90 * Returns a struct reset_control or IS_ERR() condition containing errno.
91 * If this function is called more then once for the same reset_control it will
94 * See reset_control_get_shared for details on shared references to
97 * Use of id names is optional.
99 static inline struct reset_control *
100 __must_check reset_control_get_exclusive(struct device *dev, const char *id)
102 #ifndef CONFIG_RESET_CONTROLLER
105 return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, false,
110 * reset_control_get_shared - Lookup and obtain a shared reference to a
112 * @dev: device to be reset by the controller
113 * @id: reset line name
115 * Returns a struct reset_control or IS_ERR() condition containing errno.
116 * This function is intended for use with reset-controls which are shared
117 * between hardware-blocks.
119 * When a reset-control is shared, the behavior of reset_control_assert /
120 * deassert is changed, the reset-core will keep track of a deassert_count
121 * and only (re-)assert the reset after reset_control_assert has been called
122 * as many times as reset_control_deassert was called. Also see the remark
123 * about shared reset-controls in the reset_control_assert docs.
125 * Calling reset_control_assert without first calling reset_control_deassert
126 * is not allowed on a shared reset control. Calling reset_control_reset is
127 * also not allowed on a shared reset control.
129 * Use of id names is optional.
131 static inline struct reset_control *reset_control_get_shared(
132 struct device *dev, const char *id)
134 return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, true,
138 static inline struct reset_control *reset_control_get_optional_exclusive(
139 struct device *dev, const char *id)
141 return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, false,
145 static inline struct reset_control *reset_control_get_optional_shared(
146 struct device *dev, const char *id)
148 return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, true,
153 * of_reset_control_get_exclusive - Lookup and obtain an exclusive reference
154 * to a reset controller.
155 * @node: device to be reset by the controller
156 * @id: reset line name
158 * Returns a struct reset_control or IS_ERR() condition containing errno.
160 * Use of id names is optional.
162 static inline struct reset_control *of_reset_control_get_exclusive(
163 struct device_node *node, const char *id)
165 return __of_reset_control_get(node, id, 0, false, false);
169 * of_reset_control_get_shared - Lookup and obtain an shared reference
170 * to a reset controller.
171 * @node: device to be reset by the controller
172 * @id: reset line name
174 * When a reset-control is shared, the behavior of reset_control_assert /
175 * deassert is changed, the reset-core will keep track of a deassert_count
176 * and only (re-)assert the reset after reset_control_assert has been called
177 * as many times as reset_control_deassert was called. Also see the remark
178 * about shared reset-controls in the reset_control_assert docs.
180 * Calling reset_control_assert without first calling reset_control_deassert
181 * is not allowed on a shared reset control. Calling reset_control_reset is
182 * also not allowed on a shared reset control.
183 * Returns a struct reset_control or IS_ERR() condition containing errno.
185 * Use of id names is optional.
187 static inline struct reset_control *of_reset_control_get_shared(
188 struct device_node *node, const char *id)
190 return __of_reset_control_get(node, id, 0, true, false);
194 * of_reset_control_get_exclusive_by_index - Lookup and obtain an exclusive
195 * reference to a reset controller
197 * @node: device to be reset by the controller
198 * @index: index of the reset controller
200 * This is to be used to perform a list of resets for a device or power domain
201 * in whatever order. Returns a struct reset_control or IS_ERR() condition
204 static inline struct reset_control *of_reset_control_get_exclusive_by_index(
205 struct device_node *node, int index)
207 return __of_reset_control_get(node, NULL, index, false, false);
211 * of_reset_control_get_shared_by_index - Lookup and obtain an shared
212 * reference to a reset controller
214 * @node: device to be reset by the controller
215 * @index: index of the reset controller
217 * When a reset-control is shared, the behavior of reset_control_assert /
218 * deassert is changed, the reset-core will keep track of a deassert_count
219 * and only (re-)assert the reset after reset_control_assert has been called
220 * as many times as reset_control_deassert was called. Also see the remark
221 * about shared reset-controls in the reset_control_assert docs.
223 * Calling reset_control_assert without first calling reset_control_deassert
224 * is not allowed on a shared reset control. Calling reset_control_reset is
225 * also not allowed on a shared reset control.
226 * Returns a struct reset_control or IS_ERR() condition containing errno.
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_shared_by_index(
233 struct device_node *node, int index)
235 return __of_reset_control_get(node, NULL, index, true, false);
239 * devm_reset_control_get_exclusive - resource managed
240 * reset_control_get_exclusive()
241 * @dev: device to be reset by the controller
242 * @id: reset line name
244 * Managed reset_control_get_exclusive(). For reset controllers returned
245 * from this function, reset_control_put() is called automatically on driver
248 * See reset_control_get_exclusive() for more information.
250 static inline struct reset_control *
251 __must_check devm_reset_control_get_exclusive(struct device *dev,
254 #ifndef CONFIG_RESET_CONTROLLER
257 return __devm_reset_control_get(dev, id, 0, false, false);
261 * devm_reset_control_get_shared - resource managed reset_control_get_shared()
262 * @dev: device to be reset by the controller
263 * @id: reset line name
265 * Managed reset_control_get_shared(). For reset controllers returned from
266 * this function, reset_control_put() is called automatically on driver detach.
267 * See reset_control_get_shared() for more information.
269 static inline struct reset_control *devm_reset_control_get_shared(
270 struct device *dev, const char *id)
272 return __devm_reset_control_get(dev, id, 0, true, false);
275 static inline struct reset_control *devm_reset_control_get_optional_exclusive(
276 struct device *dev, const char *id)
278 return __devm_reset_control_get(dev, id, 0, false, true);
281 static inline struct reset_control *devm_reset_control_get_optional_shared(
282 struct device *dev, const char *id)
284 return __devm_reset_control_get(dev, id, 0, true, true);
288 * devm_reset_control_get_exclusive_by_index - resource managed
289 * reset_control_get_exclusive()
290 * @dev: device to be reset by the controller
291 * @index: index of the reset controller
293 * Managed reset_control_get_exclusive(). For reset controllers returned from
294 * this function, reset_control_put() is called automatically on driver
297 * See reset_control_get_exclusive() for more information.
299 static inline struct reset_control *
300 devm_reset_control_get_exclusive_by_index(struct device *dev, int index)
302 return __devm_reset_control_get(dev, NULL, index, false, false);
306 * devm_reset_control_get_shared_by_index - resource managed
307 * reset_control_get_shared
308 * @dev: device to be reset by the controller
309 * @index: index of the reset controller
311 * Managed reset_control_get_shared(). For reset controllers returned from
312 * this function, reset_control_put() is called automatically on driver detach.
313 * See reset_control_get_shared() for more information.
315 static inline struct reset_control *
316 devm_reset_control_get_shared_by_index(struct device *dev, int index)
318 return __devm_reset_control_get(dev, NULL, index, true, false);
322 * TEMPORARY calls to use during transition:
324 * of_reset_control_get() => of_reset_control_get_exclusive()
326 * These inline function calls will be removed once all consumers
327 * have been moved over to the new explicit API.
329 static inline struct reset_control *reset_control_get(
330 struct device *dev, const char *id)
332 return reset_control_get_exclusive(dev, id);
335 static inline struct reset_control *reset_control_get_optional(
336 struct device *dev, const char *id)
338 return reset_control_get_optional_exclusive(dev, id);
341 static inline struct reset_control *of_reset_control_get(
342 struct device_node *node, const char *id)
344 return of_reset_control_get_exclusive(node, id);
347 static inline struct reset_control *of_reset_control_get_by_index(
348 struct device_node *node, int index)
350 return of_reset_control_get_exclusive_by_index(node, index);
353 static inline struct reset_control *devm_reset_control_get(
354 struct device *dev, const char *id)
356 return devm_reset_control_get_exclusive(dev, id);
359 static inline struct reset_control *devm_reset_control_get_optional(
360 struct device *dev, const char *id)
362 return devm_reset_control_get_optional_exclusive(dev, id);
366 static inline struct reset_control *devm_reset_control_get_by_index(
367 struct device *dev, int index)
369 return devm_reset_control_get_exclusive_by_index(dev, index);