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 struct reset_control *__devm_reset_control_get(struct device *dev,
23 const char *id, int index, bool shared,
26 int __must_check device_reset(struct device *dev);
28 static inline int device_reset_optional(struct device *dev)
30 return device_reset(dev);
35 static inline int reset_control_reset(struct reset_control *rstc)
40 static inline int reset_control_assert(struct reset_control *rstc)
45 static inline int reset_control_deassert(struct reset_control *rstc)
50 static inline int reset_control_status(struct reset_control *rstc)
55 static inline void reset_control_put(struct reset_control *rstc)
59 static inline int __must_check device_reset(struct device *dev)
65 static inline int device_reset_optional(struct device *dev)
70 static inline struct reset_control *__of_reset_control_get(
71 struct device_node *node,
72 const char *id, int index, bool shared,
75 return optional ? NULL : ERR_PTR(-ENOTSUPP);
78 static inline struct reset_control *__reset_control_get(
79 struct device *dev, const char *id,
80 int index, bool shared, bool optional)
82 return optional ? NULL : ERR_PTR(-ENOTSUPP);
85 static inline struct reset_control *__devm_reset_control_get(
86 struct device *dev, const char *id,
87 int index, bool shared, bool optional)
89 return optional ? NULL : ERR_PTR(-ENOTSUPP);
92 #endif /* CONFIG_RESET_CONTROLLER */
95 * reset_control_get_exclusive - Lookup and obtain an exclusive reference
96 * to a reset controller.
97 * @dev: device to be reset by the controller
98 * @id: reset line name
100 * Returns a struct reset_control or IS_ERR() condition containing errno.
101 * If this function is called more then once for the same reset_control it will
104 * See reset_control_get_shared for details on shared references to
107 * Use of id names is optional.
109 static inline struct reset_control *
110 __must_check reset_control_get_exclusive(struct device *dev, const char *id)
112 #ifndef CONFIG_RESET_CONTROLLER
115 return __reset_control_get(dev, id, 0, false, false);
119 * reset_control_get_shared - Lookup and obtain a shared reference to a
121 * @dev: device to be reset by the controller
122 * @id: reset line name
124 * Returns a struct reset_control or IS_ERR() condition containing errno.
125 * This function is intended for use with reset-controls which are shared
126 * between hardware-blocks.
128 * When a reset-control is shared, the behavior of reset_control_assert /
129 * deassert is changed, the reset-core will keep track of a deassert_count
130 * and only (re-)assert the reset after reset_control_assert has been called
131 * as many times as reset_control_deassert was called. Also see the remark
132 * about shared reset-controls in the reset_control_assert docs.
134 * Calling reset_control_assert without first calling reset_control_deassert
135 * is not allowed on a shared reset control. Calling reset_control_reset is
136 * also not allowed on a shared reset control.
138 * Use of id names is optional.
140 static inline struct reset_control *reset_control_get_shared(
141 struct device *dev, const char *id)
143 return __reset_control_get(dev, id, 0, true, false);
146 static inline struct reset_control *reset_control_get_optional_exclusive(
147 struct device *dev, const char *id)
149 return __reset_control_get(dev, id, 0, false, true);
152 static inline struct reset_control *reset_control_get_optional_shared(
153 struct device *dev, const char *id)
155 return __reset_control_get(dev, id, 0, true, true);
159 * of_reset_control_get_exclusive - Lookup and obtain an exclusive reference
160 * to a reset controller.
161 * @node: device to be reset by the controller
162 * @id: reset line name
164 * Returns a struct reset_control or IS_ERR() condition containing errno.
166 * Use of id names is optional.
168 static inline struct reset_control *of_reset_control_get_exclusive(
169 struct device_node *node, const char *id)
171 return __of_reset_control_get(node, id, 0, false, false);
175 * of_reset_control_get_shared - Lookup and obtain an shared reference
176 * to a reset controller.
177 * @node: device to be reset by the controller
178 * @id: reset line name
180 * When a reset-control is shared, the behavior of reset_control_assert /
181 * deassert is changed, the reset-core will keep track of a deassert_count
182 * and only (re-)assert the reset after reset_control_assert has been called
183 * as many times as reset_control_deassert was called. Also see the remark
184 * about shared reset-controls in the reset_control_assert docs.
186 * Calling reset_control_assert without first calling reset_control_deassert
187 * is not allowed on a shared reset control. Calling reset_control_reset is
188 * also not allowed on a shared reset control.
189 * Returns a struct reset_control or IS_ERR() condition containing errno.
191 * Use of id names is optional.
193 static inline struct reset_control *of_reset_control_get_shared(
194 struct device_node *node, const char *id)
196 return __of_reset_control_get(node, id, 0, true, false);
200 * of_reset_control_get_exclusive_by_index - Lookup and obtain an exclusive
201 * reference to a reset controller
203 * @node: device to be reset by the controller
204 * @index: index of the reset controller
206 * This is to be used to perform a list of resets for a device or power domain
207 * in whatever order. Returns a struct reset_control or IS_ERR() condition
210 static inline struct reset_control *of_reset_control_get_exclusive_by_index(
211 struct device_node *node, int index)
213 return __of_reset_control_get(node, NULL, index, false, false);
217 * of_reset_control_get_shared_by_index - Lookup and obtain an shared
218 * reference to a reset controller
220 * @node: device to be reset by the controller
221 * @index: index of the reset controller
223 * When a reset-control is shared, the behavior of reset_control_assert /
224 * deassert is changed, the reset-core will keep track of a deassert_count
225 * and only (re-)assert the reset after reset_control_assert has been called
226 * as many times as reset_control_deassert was called. Also see the remark
227 * about shared reset-controls in the reset_control_assert docs.
229 * Calling reset_control_assert without first calling reset_control_deassert
230 * is not allowed on a shared reset control. Calling reset_control_reset is
231 * also not allowed on a shared reset control.
232 * Returns a struct reset_control or IS_ERR() condition containing errno.
234 * This is to be used to perform a list of resets for a device or power domain
235 * in whatever order. Returns a struct reset_control or IS_ERR() condition
238 static inline struct reset_control *of_reset_control_get_shared_by_index(
239 struct device_node *node, int index)
241 return __of_reset_control_get(node, NULL, index, true, false);
245 * devm_reset_control_get_exclusive - resource managed
246 * reset_control_get_exclusive()
247 * @dev: device to be reset by the controller
248 * @id: reset line name
250 * Managed reset_control_get_exclusive(). For reset controllers returned
251 * from this function, reset_control_put() is called automatically on driver
254 * See reset_control_get_exclusive() for more information.
256 static inline struct reset_control *
257 __must_check devm_reset_control_get_exclusive(struct device *dev,
260 #ifndef CONFIG_RESET_CONTROLLER
263 return __devm_reset_control_get(dev, id, 0, false, false);
267 * devm_reset_control_get_shared - resource managed reset_control_get_shared()
268 * @dev: device to be reset by the controller
269 * @id: reset line name
271 * Managed reset_control_get_shared(). For reset controllers returned from
272 * this function, reset_control_put() is called automatically on driver detach.
273 * See reset_control_get_shared() for more information.
275 static inline struct reset_control *devm_reset_control_get_shared(
276 struct device *dev, const char *id)
278 return __devm_reset_control_get(dev, id, 0, true, false);
281 static inline struct reset_control *devm_reset_control_get_optional_exclusive(
282 struct device *dev, const char *id)
284 return __devm_reset_control_get(dev, id, 0, false, true);
287 static inline struct reset_control *devm_reset_control_get_optional_shared(
288 struct device *dev, const char *id)
290 return __devm_reset_control_get(dev, id, 0, true, true);
294 * devm_reset_control_get_exclusive_by_index - resource managed
295 * reset_control_get_exclusive()
296 * @dev: device to be reset by the controller
297 * @index: index of the reset controller
299 * Managed reset_control_get_exclusive(). For reset controllers returned from
300 * this function, reset_control_put() is called automatically on driver
303 * See reset_control_get_exclusive() for more information.
305 static inline struct reset_control *
306 devm_reset_control_get_exclusive_by_index(struct device *dev, int index)
308 return __devm_reset_control_get(dev, NULL, index, false, false);
312 * devm_reset_control_get_shared_by_index - resource managed
313 * reset_control_get_shared
314 * @dev: device to be reset by the controller
315 * @index: index of the reset controller
317 * Managed reset_control_get_shared(). For reset controllers returned from
318 * this function, reset_control_put() is called automatically on driver detach.
319 * See reset_control_get_shared() for more information.
321 static inline struct reset_control *
322 devm_reset_control_get_shared_by_index(struct device *dev, int index)
324 return __devm_reset_control_get(dev, NULL, index, true, false);
328 * TEMPORARY calls to use during transition:
330 * of_reset_control_get() => of_reset_control_get_exclusive()
332 * These inline function calls will be removed once all consumers
333 * have been moved over to the new explicit API.
335 static inline struct reset_control *reset_control_get(
336 struct device *dev, const char *id)
338 return reset_control_get_exclusive(dev, id);
341 static inline struct reset_control *reset_control_get_optional(
342 struct device *dev, const char *id)
344 return reset_control_get_optional_exclusive(dev, id);
347 static inline struct reset_control *of_reset_control_get(
348 struct device_node *node, const char *id)
350 return of_reset_control_get_exclusive(node, id);
353 static inline struct reset_control *of_reset_control_get_by_index(
354 struct device_node *node, int index)
356 return of_reset_control_get_exclusive_by_index(node, index);
359 static inline struct reset_control *devm_reset_control_get(
360 struct device *dev, const char *id)
362 return devm_reset_control_get_exclusive(dev, id);
365 static inline struct reset_control *devm_reset_control_get_optional(
366 struct device *dev, const char *id)
368 return devm_reset_control_get_optional_exclusive(dev, id);
372 static inline struct reset_control *devm_reset_control_get_by_index(
373 struct device *dev, int index)
375 return devm_reset_control_get_exclusive_by_index(dev, index);