]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - include/linux/reset.h
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 struct reset_control
*devm_reset_control_array_get(struct device
*dev
,
29 bool shared
, bool optional
);
30 struct reset_control
*of_reset_control_array_get(struct device_node
*np
,
31 bool shared
, bool optional
);
33 static inline int device_reset_optional(struct device
*dev
)
35 return device_reset(dev
);
40 static inline int reset_control_reset(struct reset_control
*rstc
)
45 static inline int reset_control_assert(struct reset_control
*rstc
)
50 static inline int reset_control_deassert(struct reset_control
*rstc
)
55 static inline int reset_control_status(struct reset_control
*rstc
)
60 static inline void reset_control_put(struct reset_control
*rstc
)
64 static inline int __must_check
device_reset(struct device
*dev
)
70 static inline int device_reset_optional(struct device
*dev
)
75 static inline struct reset_control
*__of_reset_control_get(
76 struct device_node
*node
,
77 const char *id
, int index
, bool shared
,
80 return optional
? NULL
: ERR_PTR(-ENOTSUPP
);
83 static inline struct reset_control
*__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
*__devm_reset_control_get(
91 struct device
*dev
, const char *id
,
92 int index
, bool shared
, bool optional
)
94 return optional
? NULL
: ERR_PTR(-ENOTSUPP
);
97 static inline struct reset_control
*
98 devm_reset_control_array_get(struct device
*dev
, bool shared
, bool optional
)
100 return optional
? NULL
: ERR_PTR(-ENOTSUPP
);
103 static inline struct reset_control
*
104 of_reset_control_array_get(struct device_node
*np
, bool shared
, bool optional
)
106 return optional
? NULL
: ERR_PTR(-ENOTSUPP
);
109 #endif /* CONFIG_RESET_CONTROLLER */
112 * reset_control_get_exclusive - Lookup and obtain an exclusive reference
113 * to a reset controller.
114 * @dev: device to be reset by the controller
115 * @id: reset line name
117 * Returns a struct reset_control or IS_ERR() condition containing errno.
118 * If this function is called more then once for the same reset_control it will
121 * See reset_control_get_shared for details on shared references to
124 * Use of id names is optional.
126 static inline struct reset_control
*
127 __must_check
reset_control_get_exclusive(struct device
*dev
, const char *id
)
129 #ifndef CONFIG_RESET_CONTROLLER
132 return __reset_control_get(dev
, id
, 0, false, false);
136 * reset_control_get_shared - Lookup and obtain a shared reference to a
138 * @dev: device to be reset by the controller
139 * @id: reset line name
141 * Returns a struct reset_control or IS_ERR() condition containing errno.
142 * This function is intended for use with reset-controls which are shared
143 * between hardware-blocks.
145 * When a reset-control is shared, the behavior of reset_control_assert /
146 * deassert is changed, the reset-core will keep track of a deassert_count
147 * and only (re-)assert the reset after reset_control_assert has been called
148 * as many times as reset_control_deassert was called. Also see the remark
149 * about shared reset-controls in the reset_control_assert docs.
151 * Calling reset_control_assert without first calling reset_control_deassert
152 * is not allowed on a shared reset control. Calling reset_control_reset is
153 * also not allowed on a shared reset control.
155 * Use of id names is optional.
157 static inline struct reset_control
*reset_control_get_shared(
158 struct device
*dev
, const char *id
)
160 return __reset_control_get(dev
, id
, 0, true, false);
163 static inline struct reset_control
*reset_control_get_optional_exclusive(
164 struct device
*dev
, const char *id
)
166 return __reset_control_get(dev
, id
, 0, false, true);
169 static inline struct reset_control
*reset_control_get_optional_shared(
170 struct device
*dev
, const char *id
)
172 return __reset_control_get(dev
, id
, 0, true, true);
176 * of_reset_control_get_exclusive - Lookup and obtain an exclusive reference
177 * to a reset controller.
178 * @node: device to be reset by the controller
179 * @id: reset line name
181 * Returns a struct reset_control or IS_ERR() condition containing errno.
183 * Use of id names is optional.
185 static inline struct reset_control
*of_reset_control_get_exclusive(
186 struct device_node
*node
, const char *id
)
188 return __of_reset_control_get(node
, id
, 0, false, false);
192 * of_reset_control_get_shared - Lookup and obtain an shared reference
193 * to a reset controller.
194 * @node: device to be reset by the controller
195 * @id: reset line name
197 * When a reset-control is shared, the behavior of reset_control_assert /
198 * deassert is changed, the reset-core will keep track of a deassert_count
199 * and only (re-)assert the reset after reset_control_assert has been called
200 * as many times as reset_control_deassert was called. Also see the remark
201 * about shared reset-controls in the reset_control_assert docs.
203 * Calling reset_control_assert without first calling reset_control_deassert
204 * is not allowed on a shared reset control. Calling reset_control_reset is
205 * also not allowed on a shared reset control.
206 * Returns a struct reset_control or IS_ERR() condition containing errno.
208 * Use of id names is optional.
210 static inline struct reset_control
*of_reset_control_get_shared(
211 struct device_node
*node
, const char *id
)
213 return __of_reset_control_get(node
, id
, 0, true, false);
217 * of_reset_control_get_exclusive_by_index - Lookup and obtain an exclusive
218 * reference to a reset controller
220 * @node: device to be reset by the controller
221 * @index: index of the reset controller
223 * This is to be used to perform a list of resets for a device or power domain
224 * in whatever order. Returns a struct reset_control or IS_ERR() condition
227 static inline struct reset_control
*of_reset_control_get_exclusive_by_index(
228 struct device_node
*node
, int index
)
230 return __of_reset_control_get(node
, NULL
, index
, false, false);
234 * of_reset_control_get_shared_by_index - Lookup and obtain an shared
235 * reference to a reset controller
237 * @node: device to be reset by the controller
238 * @index: index of the reset controller
240 * When a reset-control is shared, the behavior of reset_control_assert /
241 * deassert is changed, the reset-core will keep track of a deassert_count
242 * and only (re-)assert the reset after reset_control_assert has been called
243 * as many times as reset_control_deassert was called. Also see the remark
244 * about shared reset-controls in the reset_control_assert docs.
246 * Calling reset_control_assert without first calling reset_control_deassert
247 * is not allowed on a shared reset control. Calling reset_control_reset is
248 * also not allowed on a shared reset control.
249 * Returns a struct reset_control or IS_ERR() condition containing errno.
251 * This is to be used to perform a list of resets for a device or power domain
252 * in whatever order. Returns a struct reset_control or IS_ERR() condition
255 static inline struct reset_control
*of_reset_control_get_shared_by_index(
256 struct device_node
*node
, int index
)
258 return __of_reset_control_get(node
, NULL
, index
, true, false);
262 * devm_reset_control_get_exclusive - resource managed
263 * reset_control_get_exclusive()
264 * @dev: device to be reset by the controller
265 * @id: reset line name
267 * Managed reset_control_get_exclusive(). For reset controllers returned
268 * from this function, reset_control_put() is called automatically on driver
271 * See reset_control_get_exclusive() for more information.
273 static inline struct reset_control
*
274 __must_check
devm_reset_control_get_exclusive(struct device
*dev
,
277 #ifndef CONFIG_RESET_CONTROLLER
280 return __devm_reset_control_get(dev
, id
, 0, false, false);
284 * devm_reset_control_get_shared - resource managed reset_control_get_shared()
285 * @dev: device to be reset by the controller
286 * @id: reset line name
288 * Managed reset_control_get_shared(). For reset controllers returned from
289 * this function, reset_control_put() is called automatically on driver detach.
290 * See reset_control_get_shared() for more information.
292 static inline struct reset_control
*devm_reset_control_get_shared(
293 struct device
*dev
, const char *id
)
295 return __devm_reset_control_get(dev
, id
, 0, true, false);
298 static inline struct reset_control
*devm_reset_control_get_optional_exclusive(
299 struct device
*dev
, const char *id
)
301 return __devm_reset_control_get(dev
, id
, 0, false, true);
304 static inline struct reset_control
*devm_reset_control_get_optional_shared(
305 struct device
*dev
, const char *id
)
307 return __devm_reset_control_get(dev
, id
, 0, true, true);
311 * devm_reset_control_get_exclusive_by_index - resource managed
312 * reset_control_get_exclusive()
313 * @dev: device to be reset by the controller
314 * @index: index of the reset controller
316 * Managed reset_control_get_exclusive(). For reset controllers returned from
317 * this function, reset_control_put() is called automatically on driver
320 * See reset_control_get_exclusive() for more information.
322 static inline struct reset_control
*
323 devm_reset_control_get_exclusive_by_index(struct device
*dev
, int index
)
325 return __devm_reset_control_get(dev
, NULL
, index
, false, false);
329 * devm_reset_control_get_shared_by_index - resource managed
330 * reset_control_get_shared
331 * @dev: device to be reset by the controller
332 * @index: index of the reset controller
334 * Managed reset_control_get_shared(). For reset controllers returned from
335 * this function, reset_control_put() is called automatically on driver detach.
336 * See reset_control_get_shared() for more information.
338 static inline struct reset_control
*
339 devm_reset_control_get_shared_by_index(struct device
*dev
, int index
)
341 return __devm_reset_control_get(dev
, NULL
, index
, true, false);
345 * TEMPORARY calls to use during transition:
347 * of_reset_control_get() => of_reset_control_get_exclusive()
349 * These inline function calls will be removed once all consumers
350 * have been moved over to the new explicit API.
352 static inline struct reset_control
*reset_control_get(
353 struct device
*dev
, const char *id
)
355 return reset_control_get_exclusive(dev
, id
);
358 static inline struct reset_control
*reset_control_get_optional(
359 struct device
*dev
, const char *id
)
361 return reset_control_get_optional_exclusive(dev
, id
);
364 static inline struct reset_control
*of_reset_control_get(
365 struct device_node
*node
, const char *id
)
367 return of_reset_control_get_exclusive(node
, id
);
370 static inline struct reset_control
*of_reset_control_get_by_index(
371 struct device_node
*node
, int index
)
373 return of_reset_control_get_exclusive_by_index(node
, index
);
376 static inline struct reset_control
*devm_reset_control_get(
377 struct device
*dev
, const char *id
)
379 return devm_reset_control_get_exclusive(dev
, id
);
382 static inline struct reset_control
*devm_reset_control_get_optional(
383 struct device
*dev
, const char *id
)
385 return devm_reset_control_get_optional_exclusive(dev
, id
);
389 static inline struct reset_control
*devm_reset_control_get_by_index(
390 struct device
*dev
, int index
)
392 return devm_reset_control_get_exclusive_by_index(dev
, index
);
396 * APIs to manage a list of reset controllers
398 static inline struct reset_control
*
399 devm_reset_control_array_get_exclusive(struct device
*dev
)
401 return devm_reset_control_array_get(dev
, false, false);
404 static inline struct reset_control
*
405 devm_reset_control_array_get_shared(struct device
*dev
)
407 return devm_reset_control_array_get(dev
, true, false);
410 static inline struct reset_control
*
411 devm_reset_control_array_get_optional_exclusive(struct device
*dev
)
413 return devm_reset_control_array_get(dev
, false, true);
416 static inline struct reset_control
*
417 devm_reset_control_array_get_optional_shared(struct device
*dev
)
419 return devm_reset_control_array_get(dev
, true, true);
422 static inline struct reset_control
*
423 of_reset_control_array_get_exclusive(struct device_node
*node
)
425 return of_reset_control_array_get(node
, false, false);
428 static inline struct reset_control
*
429 of_reset_control_array_get_shared(struct device_node
*node
)
431 return of_reset_control_array_get(node
, true, false);
434 static inline struct reset_control
*
435 of_reset_control_array_get_optional_exclusive(struct device_node
*node
)
437 return of_reset_control_array_get(node
, false, true);
440 static inline struct reset_control
*
441 of_reset_control_array_get_optional_shared(struct device_node
*node
)
443 return of_reset_control_array_get(node
, true, true);