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)
38 static inline int reset_control_assert(struct reset_control *rstc)
44 static inline int reset_control_deassert(struct reset_control *rstc)
50 static inline int reset_control_status(struct reset_control *rstc)
56 static inline void reset_control_put(struct reset_control *rstc)
61 static inline int __must_check device_reset(struct device *dev)
67 static inline int device_reset_optional(struct device *dev)
72 static inline struct reset_control *__of_reset_control_get(
73 struct device_node *node,
74 const char *id, int index, bool shared,
77 return ERR_PTR(-ENOTSUPP);
80 static inline struct reset_control *__devm_reset_control_get(
81 struct device *dev, const char *id,
82 int index, bool shared, bool optional)
84 return ERR_PTR(-ENOTSUPP);
87 #endif /* CONFIG_RESET_CONTROLLER */
90 * reset_control_get_exclusive - Lookup and obtain an exclusive reference
91 * to a reset controller.
92 * @dev: device to be reset by the controller
93 * @id: reset line name
95 * Returns a struct reset_control or IS_ERR() condition containing errno.
96 * If this function is called more then once for the same reset_control it will
99 * See reset_control_get_shared for details on shared references to
102 * Use of id names is optional.
104 static inline struct reset_control *
105 __must_check reset_control_get_exclusive(struct device *dev, const char *id)
107 #ifndef CONFIG_RESET_CONTROLLER
110 return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, false,
115 * reset_control_get_shared - Lookup and obtain a shared reference to a
117 * @dev: device to be reset by the controller
118 * @id: reset line name
120 * Returns a struct reset_control or IS_ERR() condition containing errno.
121 * This function is intended for use with reset-controls which are shared
122 * between hardware-blocks.
124 * When a reset-control is shared, the behavior of reset_control_assert /
125 * deassert is changed, the reset-core will keep track of a deassert_count
126 * and only (re-)assert the reset after reset_control_assert has been called
127 * as many times as reset_control_deassert was called. Also see the remark
128 * about shared reset-controls in the reset_control_assert docs.
130 * Calling reset_control_assert without first calling reset_control_deassert
131 * is not allowed on a shared reset control. Calling reset_control_reset is
132 * also not allowed on a shared reset control.
134 * Use of id names is optional.
136 static inline struct reset_control *reset_control_get_shared(
137 struct device *dev, const char *id)
139 return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, true,
143 static inline struct reset_control *reset_control_get_optional_exclusive(
144 struct device *dev, const char *id)
146 return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, false,
150 static inline struct reset_control *reset_control_get_optional_shared(
151 struct device *dev, const char *id)
153 return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, true,
158 * of_reset_control_get_exclusive - Lookup and obtain an exclusive reference
159 * to a reset controller.
160 * @node: device to be reset by the controller
161 * @id: reset line name
163 * Returns a struct reset_control or IS_ERR() condition containing errno.
165 * Use of id names is optional.
167 static inline struct reset_control *of_reset_control_get_exclusive(
168 struct device_node *node, const char *id)
170 return __of_reset_control_get(node, id, 0, false, false);
174 * of_reset_control_get_shared - Lookup and obtain an shared reference
175 * to a reset controller.
176 * @node: device to be reset by the controller
177 * @id: reset line name
179 * When a reset-control is shared, the behavior of reset_control_assert /
180 * deassert is changed, the reset-core will keep track of a deassert_count
181 * and only (re-)assert the reset after reset_control_assert has been called
182 * as many times as reset_control_deassert was called. Also see the remark
183 * about shared reset-controls in the reset_control_assert docs.
185 * Calling reset_control_assert without first calling reset_control_deassert
186 * is not allowed on a shared reset control. Calling reset_control_reset is
187 * also not allowed on a shared reset control.
188 * Returns a struct reset_control or IS_ERR() condition containing errno.
190 * Use of id names is optional.
192 static inline struct reset_control *of_reset_control_get_shared(
193 struct device_node *node, const char *id)
195 return __of_reset_control_get(node, id, 0, true, false);
199 * of_reset_control_get_exclusive_by_index - Lookup and obtain an exclusive
200 * reference to a reset controller
202 * @node: device to be reset by the controller
203 * @index: index of the reset controller
205 * This is to be used to perform a list of resets for a device or power domain
206 * in whatever order. Returns a struct reset_control or IS_ERR() condition
209 static inline struct reset_control *of_reset_control_get_exclusive_by_index(
210 struct device_node *node, int index)
212 return __of_reset_control_get(node, NULL, index, false, false);
216 * of_reset_control_get_shared_by_index - Lookup and obtain an shared
217 * reference to a reset controller
219 * @node: device to be reset by the controller
220 * @index: index of the reset controller
222 * When a reset-control is shared, the behavior of reset_control_assert /
223 * deassert is changed, the reset-core will keep track of a deassert_count
224 * and only (re-)assert the reset after reset_control_assert has been called
225 * as many times as reset_control_deassert was called. Also see the remark
226 * about shared reset-controls in the reset_control_assert docs.
228 * Calling reset_control_assert without first calling reset_control_deassert
229 * is not allowed on a shared reset control. Calling reset_control_reset is
230 * also not allowed on a shared reset control.
231 * Returns a struct reset_control or IS_ERR() condition containing errno.
233 * This is to be used to perform a list of resets for a device or power domain
234 * in whatever order. Returns a struct reset_control or IS_ERR() condition
237 static inline struct reset_control *of_reset_control_get_shared_by_index(
238 struct device_node *node, int index)
240 return __of_reset_control_get(node, NULL, index, true, false);
244 * devm_reset_control_get_exclusive - resource managed
245 * reset_control_get_exclusive()
246 * @dev: device to be reset by the controller
247 * @id: reset line name
249 * Managed reset_control_get_exclusive(). For reset controllers returned
250 * from this function, reset_control_put() is called automatically on driver
253 * See reset_control_get_exclusive() for more information.
255 static inline struct reset_control *
256 __must_check devm_reset_control_get_exclusive(struct device *dev,
259 #ifndef CONFIG_RESET_CONTROLLER
262 return __devm_reset_control_get(dev, id, 0, false, false);
266 * devm_reset_control_get_shared - resource managed reset_control_get_shared()
267 * @dev: device to be reset by the controller
268 * @id: reset line name
270 * Managed reset_control_get_shared(). For reset controllers returned from
271 * this function, reset_control_put() is called automatically on driver detach.
272 * See reset_control_get_shared() for more information.
274 static inline struct reset_control *devm_reset_control_get_shared(
275 struct device *dev, const char *id)
277 return __devm_reset_control_get(dev, id, 0, true, false);
280 static inline struct reset_control *devm_reset_control_get_optional_exclusive(
281 struct device *dev, const char *id)
283 return __devm_reset_control_get(dev, id, 0, false, true);
286 static inline struct reset_control *devm_reset_control_get_optional_shared(
287 struct device *dev, const char *id)
289 return __devm_reset_control_get(dev, id, 0, true, true);
293 * devm_reset_control_get_exclusive_by_index - resource managed
294 * reset_control_get_exclusive()
295 * @dev: device to be reset by the controller
296 * @index: index of the reset controller
298 * Managed reset_control_get_exclusive(). For reset controllers returned from
299 * this function, reset_control_put() is called automatically on driver
302 * See reset_control_get_exclusive() for more information.
304 static inline struct reset_control *
305 devm_reset_control_get_exclusive_by_index(struct device *dev, int index)
307 return __devm_reset_control_get(dev, NULL, index, false, false);
311 * devm_reset_control_get_shared_by_index - resource managed
312 * reset_control_get_shared
313 * @dev: device to be reset by the controller
314 * @index: index of the reset controller
316 * Managed reset_control_get_shared(). For reset controllers returned from
317 * this function, reset_control_put() is called automatically on driver detach.
318 * See reset_control_get_shared() for more information.
320 static inline struct reset_control *
321 devm_reset_control_get_shared_by_index(struct device *dev, int index)
323 return __devm_reset_control_get(dev, NULL, index, true, false);
327 * TEMPORARY calls to use during transition:
329 * of_reset_control_get() => of_reset_control_get_exclusive()
331 * These inline function calls will be removed once all consumers
332 * have been moved over to the new explicit API.
334 static inline struct reset_control *reset_control_get(
335 struct device *dev, const char *id)
337 return reset_control_get_exclusive(dev, id);
340 static inline struct reset_control *reset_control_get_optional(
341 struct device *dev, const char *id)
343 return reset_control_get_optional_exclusive(dev, id);
346 static inline struct reset_control *of_reset_control_get(
347 struct device_node *node, const char *id)
349 return of_reset_control_get_exclusive(node, id);
352 static inline struct reset_control *of_reset_control_get_by_index(
353 struct device_node *node, int index)
355 return of_reset_control_get_exclusive_by_index(node, index);
358 static inline struct reset_control *devm_reset_control_get(
359 struct device *dev, const char *id)
361 return devm_reset_control_get_exclusive(dev, id);
364 static inline struct reset_control *devm_reset_control_get_optional(
365 struct device *dev, const char *id)
367 return devm_reset_control_get_optional_exclusive(dev, id);
371 static inline struct reset_control *devm_reset_control_get_by_index(
372 struct device *dev, int index)
374 return devm_reset_control_get_exclusive_by_index(dev, index);