]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - include/linux/reset.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_RESET_H_
3 #define _LINUX_RESET_H_
5 #include <linux/device.h>
9 #ifdef CONFIG_RESET_CONTROLLER
11 int reset_control_reset(struct reset_control
*rstc
);
12 int reset_control_assert(struct reset_control
*rstc
);
13 int reset_control_deassert(struct reset_control
*rstc
);
14 int reset_control_status(struct reset_control
*rstc
);
16 struct reset_control
*__of_reset_control_get(struct device_node
*node
,
17 const char *id
, int index
, bool shared
,
19 struct reset_control
*__reset_control_get(struct device
*dev
, const char *id
,
20 int index
, bool shared
,
22 void reset_control_put(struct reset_control
*rstc
);
23 int __device_reset(struct device
*dev
, bool optional
);
24 struct reset_control
*__devm_reset_control_get(struct device
*dev
,
25 const char *id
, int index
, bool shared
,
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
);
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 __device_reset(struct device
*dev
, bool optional
)
61 return optional
? 0 : -ENOTSUPP
;
64 static inline struct reset_control
*__of_reset_control_get(
65 struct device_node
*node
,
66 const char *id
, int index
, bool shared
,
69 return optional
? NULL
: ERR_PTR(-ENOTSUPP
);
72 static inline struct reset_control
*__reset_control_get(
73 struct device
*dev
, const char *id
,
74 int index
, bool shared
, bool optional
)
76 return optional
? NULL
: ERR_PTR(-ENOTSUPP
);
79 static inline struct reset_control
*__devm_reset_control_get(
80 struct device
*dev
, const char *id
,
81 int index
, bool shared
, bool optional
)
83 return optional
? NULL
: ERR_PTR(-ENOTSUPP
);
86 static inline struct reset_control
*
87 devm_reset_control_array_get(struct device
*dev
, bool shared
, bool optional
)
89 return optional
? NULL
: ERR_PTR(-ENOTSUPP
);
92 static inline struct reset_control
*
93 of_reset_control_array_get(struct device_node
*np
, bool shared
, bool optional
)
95 return optional
? NULL
: ERR_PTR(-ENOTSUPP
);
98 #endif /* CONFIG_RESET_CONTROLLER */
100 static inline int __must_check
device_reset(struct device
*dev
)
102 return __device_reset(dev
, false);
105 static inline int device_reset_optional(struct device
*dev
)
107 return __device_reset(dev
, true);
111 * reset_control_get_exclusive - Lookup and obtain an exclusive reference
112 * to a reset controller.
113 * @dev: device to be reset by the controller
114 * @id: reset line name
116 * Returns a struct reset_control or IS_ERR() condition containing errno.
117 * If this function is called more then once for the same reset_control it will
120 * See reset_control_get_shared for details on shared references to
123 * Use of id names is optional.
125 static inline struct reset_control
*
126 __must_check
reset_control_get_exclusive(struct device
*dev
, const char *id
)
128 #ifndef CONFIG_RESET_CONTROLLER
131 return __reset_control_get(dev
, id
, 0, false, false);
135 * reset_control_get_shared - Lookup and obtain a shared reference to a
137 * @dev: device to be reset by the controller
138 * @id: reset line name
140 * Returns a struct reset_control or IS_ERR() condition containing errno.
141 * This function is intended for use with reset-controls which are shared
142 * between hardware-blocks.
144 * When a reset-control is shared, the behavior of reset_control_assert /
145 * deassert is changed, the reset-core will keep track of a deassert_count
146 * and only (re-)assert the reset after reset_control_assert has been called
147 * as many times as reset_control_deassert was called. Also see the remark
148 * about shared reset-controls in the reset_control_assert docs.
150 * Calling reset_control_assert without first calling reset_control_deassert
151 * is not allowed on a shared reset control. Calling reset_control_reset is
152 * also not allowed on a shared reset control.
154 * Use of id names is optional.
156 static inline struct reset_control
*reset_control_get_shared(
157 struct device
*dev
, const char *id
)
159 return __reset_control_get(dev
, id
, 0, true, false);
162 static inline struct reset_control
*reset_control_get_optional_exclusive(
163 struct device
*dev
, const char *id
)
165 return __reset_control_get(dev
, id
, 0, false, true);
168 static inline struct reset_control
*reset_control_get_optional_shared(
169 struct device
*dev
, const char *id
)
171 return __reset_control_get(dev
, id
, 0, true, true);
175 * of_reset_control_get_exclusive - Lookup and obtain an exclusive reference
176 * to a reset controller.
177 * @node: device to be reset by the controller
178 * @id: reset line name
180 * Returns a struct reset_control or IS_ERR() condition containing errno.
182 * Use of id names is optional.
184 static inline struct reset_control
*of_reset_control_get_exclusive(
185 struct device_node
*node
, const char *id
)
187 return __of_reset_control_get(node
, id
, 0, false, false);
191 * of_reset_control_get_shared - Lookup and obtain an shared reference
192 * to a reset controller.
193 * @node: device to be reset by the controller
194 * @id: reset line name
196 * When a reset-control is shared, the behavior of reset_control_assert /
197 * deassert is changed, the reset-core will keep track of a deassert_count
198 * and only (re-)assert the reset after reset_control_assert has been called
199 * as many times as reset_control_deassert was called. Also see the remark
200 * about shared reset-controls in the reset_control_assert docs.
202 * Calling reset_control_assert without first calling reset_control_deassert
203 * is not allowed on a shared reset control. Calling reset_control_reset is
204 * also not allowed on a shared reset control.
205 * Returns a struct reset_control or IS_ERR() condition containing errno.
207 * Use of id names is optional.
209 static inline struct reset_control
*of_reset_control_get_shared(
210 struct device_node
*node
, const char *id
)
212 return __of_reset_control_get(node
, id
, 0, true, false);
216 * of_reset_control_get_exclusive_by_index - Lookup and obtain an exclusive
217 * reference to a reset controller
219 * @node: device to be reset by the controller
220 * @index: index of the reset controller
222 * This is to be used to perform a list of resets for a device or power domain
223 * in whatever order. Returns a struct reset_control or IS_ERR() condition
226 static inline struct reset_control
*of_reset_control_get_exclusive_by_index(
227 struct device_node
*node
, int index
)
229 return __of_reset_control_get(node
, NULL
, index
, false, false);
233 * of_reset_control_get_shared_by_index - Lookup and obtain an shared
234 * reference to a reset controller
236 * @node: device to be reset by the controller
237 * @index: index of the reset controller
239 * When a reset-control is shared, the behavior of reset_control_assert /
240 * deassert is changed, the reset-core will keep track of a deassert_count
241 * and only (re-)assert the reset after reset_control_assert has been called
242 * as many times as reset_control_deassert was called. Also see the remark
243 * about shared reset-controls in the reset_control_assert docs.
245 * Calling reset_control_assert without first calling reset_control_deassert
246 * is not allowed on a shared reset control. Calling reset_control_reset is
247 * also not allowed on a shared reset control.
248 * Returns a struct reset_control or IS_ERR() condition containing errno.
250 * This is to be used to perform a list of resets for a device or power domain
251 * in whatever order. Returns a struct reset_control or IS_ERR() condition
254 static inline struct reset_control
*of_reset_control_get_shared_by_index(
255 struct device_node
*node
, int index
)
257 return __of_reset_control_get(node
, NULL
, index
, true, false);
261 * devm_reset_control_get_exclusive - resource managed
262 * reset_control_get_exclusive()
263 * @dev: device to be reset by the controller
264 * @id: reset line name
266 * Managed reset_control_get_exclusive(). For reset controllers returned
267 * from this function, reset_control_put() is called automatically on driver
270 * See reset_control_get_exclusive() for more information.
272 static inline struct reset_control
*
273 __must_check
devm_reset_control_get_exclusive(struct device
*dev
,
276 #ifndef CONFIG_RESET_CONTROLLER
279 return __devm_reset_control_get(dev
, id
, 0, false, false);
283 * devm_reset_control_get_shared - resource managed reset_control_get_shared()
284 * @dev: device to be reset by the controller
285 * @id: reset line name
287 * Managed reset_control_get_shared(). For reset controllers returned from
288 * this function, reset_control_put() is called automatically on driver detach.
289 * See reset_control_get_shared() for more information.
291 static inline struct reset_control
*devm_reset_control_get_shared(
292 struct device
*dev
, const char *id
)
294 return __devm_reset_control_get(dev
, id
, 0, true, false);
297 static inline struct reset_control
*devm_reset_control_get_optional_exclusive(
298 struct device
*dev
, const char *id
)
300 return __devm_reset_control_get(dev
, id
, 0, false, true);
303 static inline struct reset_control
*devm_reset_control_get_optional_shared(
304 struct device
*dev
, const char *id
)
306 return __devm_reset_control_get(dev
, id
, 0, true, true);
310 * devm_reset_control_get_exclusive_by_index - resource managed
311 * reset_control_get_exclusive()
312 * @dev: device to be reset by the controller
313 * @index: index of the reset controller
315 * Managed reset_control_get_exclusive(). For reset controllers returned from
316 * this function, reset_control_put() is called automatically on driver
319 * See reset_control_get_exclusive() for more information.
321 static inline struct reset_control
*
322 devm_reset_control_get_exclusive_by_index(struct device
*dev
, int index
)
324 return __devm_reset_control_get(dev
, NULL
, index
, false, false);
328 * devm_reset_control_get_shared_by_index - resource managed
329 * reset_control_get_shared
330 * @dev: device to be reset by the controller
331 * @index: index of the reset controller
333 * Managed reset_control_get_shared(). For reset controllers returned from
334 * this function, reset_control_put() is called automatically on driver detach.
335 * See reset_control_get_shared() for more information.
337 static inline struct reset_control
*
338 devm_reset_control_get_shared_by_index(struct device
*dev
, int index
)
340 return __devm_reset_control_get(dev
, NULL
, index
, true, false);
344 * TEMPORARY calls to use during transition:
346 * of_reset_control_get() => of_reset_control_get_exclusive()
348 * These inline function calls will be removed once all consumers
349 * have been moved over to the new explicit API.
351 static inline struct reset_control
*reset_control_get(
352 struct device
*dev
, const char *id
)
354 return reset_control_get_exclusive(dev
, id
);
357 static inline struct reset_control
*reset_control_get_optional(
358 struct device
*dev
, const char *id
)
360 return reset_control_get_optional_exclusive(dev
, id
);
363 static inline struct reset_control
*of_reset_control_get(
364 struct device_node
*node
, const char *id
)
366 return of_reset_control_get_exclusive(node
, id
);
369 static inline struct reset_control
*of_reset_control_get_by_index(
370 struct device_node
*node
, int index
)
372 return of_reset_control_get_exclusive_by_index(node
, index
);
375 static inline struct reset_control
*devm_reset_control_get(
376 struct device
*dev
, const char *id
)
378 return devm_reset_control_get_exclusive(dev
, id
);
381 static inline struct reset_control
*devm_reset_control_get_optional(
382 struct device
*dev
, const char *id
)
384 return devm_reset_control_get_optional_exclusive(dev
, id
);
388 static inline struct reset_control
*devm_reset_control_get_by_index(
389 struct device
*dev
, int index
)
391 return devm_reset_control_get_exclusive_by_index(dev
, index
);
395 * APIs to manage a list of reset controllers
397 static inline struct reset_control
*
398 devm_reset_control_array_get_exclusive(struct device
*dev
)
400 return devm_reset_control_array_get(dev
, false, false);
403 static inline struct reset_control
*
404 devm_reset_control_array_get_shared(struct device
*dev
)
406 return devm_reset_control_array_get(dev
, true, false);
409 static inline struct reset_control
*
410 devm_reset_control_array_get_optional_exclusive(struct device
*dev
)
412 return devm_reset_control_array_get(dev
, false, true);
415 static inline struct reset_control
*
416 devm_reset_control_array_get_optional_shared(struct device
*dev
)
418 return devm_reset_control_array_get(dev
, true, true);
421 static inline struct reset_control
*
422 of_reset_control_array_get_exclusive(struct device_node
*node
)
424 return of_reset_control_array_get(node
, false, false);
427 static inline struct reset_control
*
428 of_reset_control_array_get_shared(struct device_node
*node
)
430 return of_reset_control_array_get(node
, true, false);
433 static inline struct reset_control
*
434 of_reset_control_array_get_optional_exclusive(struct device_node
*node
)
436 return of_reset_control_array_get(node
, false, true);
439 static inline struct reset_control
*
440 of_reset_control_array_get_optional_shared(struct device_node
*node
)
442 return of_reset_control_array_get(node
, true, true);