xref: /linux-6.15/include/linux/reset.h (revision c2ffa00a)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
261fc4131SPhilipp Zabel #ifndef _LINUX_RESET_H_
361fc4131SPhilipp Zabel #define _LINUX_RESET_H_
461fc4131SPhilipp Zabel 
5d005aa75SRandy Dunlap #include <linux/err.h>
6d005aa75SRandy Dunlap #include <linux/errno.h>
7dfc1d9b2SMasahiro Yamada #include <linux/types.h>
86c96f05cSHans de Goede 
9dfc1d9b2SMasahiro Yamada struct device;
10dfc1d9b2SMasahiro Yamada struct device_node;
1161fc4131SPhilipp Zabel struct reset_control;
1261fc4131SPhilipp Zabel 
13b424080aSPhilipp Zabel #ifdef CONFIG_RESET_CONTROLLER
14b424080aSPhilipp Zabel 
1561fc4131SPhilipp Zabel int reset_control_reset(struct reset_control *rstc);
1661fc4131SPhilipp Zabel int reset_control_assert(struct reset_control *rstc);
1761fc4131SPhilipp Zabel int reset_control_deassert(struct reset_control *rstc);
18729de41bSDinh Nguyen int reset_control_status(struct reset_control *rstc);
19c84b0326SPhilipp Zabel int reset_control_acquire(struct reset_control *rstc);
20c84b0326SPhilipp Zabel void reset_control_release(struct reset_control *rstc);
2161fc4131SPhilipp Zabel 
226c96f05cSHans de Goede struct reset_control *__of_reset_control_get(struct device_node *node,
23bb475230SRamiro Oliveira 				     const char *id, int index, bool shared,
24c84b0326SPhilipp Zabel 				     bool optional, bool acquired);
2562e24c57SPhilipp Zabel struct reset_control *__reset_control_get(struct device *dev, const char *id,
2662e24c57SPhilipp Zabel 					  int index, bool shared,
27c84b0326SPhilipp Zabel 					  bool optional, bool acquired);
2861fc4131SPhilipp Zabel void reset_control_put(struct reset_control *rstc);
291554bbd4SMasahiro Yamada int __device_reset(struct device *dev, bool optional);
306c96f05cSHans de Goede struct reset_control *__devm_reset_control_get(struct device *dev,
31bb475230SRamiro Oliveira 				     const char *id, int index, bool shared,
32c84b0326SPhilipp Zabel 				     bool optional, bool acquired);
3361fc4131SPhilipp Zabel 
3417c82e20SVivek Gautam struct reset_control *devm_reset_control_array_get(struct device *dev,
3517c82e20SVivek Gautam 						   bool shared, bool optional);
3617c82e20SVivek Gautam struct reset_control *of_reset_control_array_get(struct device_node *np,
37f31d5c24SThierry Reding 						 bool shared, bool optional,
38f31d5c24SThierry Reding 						 bool acquired);
3917c82e20SVivek Gautam 
40eaf91db0SGeert Uytterhoeven int reset_control_get_count(struct device *dev);
41eaf91db0SGeert Uytterhoeven 
42b424080aSPhilipp Zabel #else
43b424080aSPhilipp Zabel 
44b424080aSPhilipp Zabel static inline int reset_control_reset(struct reset_control *rstc)
45b424080aSPhilipp Zabel {
46b424080aSPhilipp Zabel 	return 0;
47b424080aSPhilipp Zabel }
48b424080aSPhilipp Zabel 
49b424080aSPhilipp Zabel static inline int reset_control_assert(struct reset_control *rstc)
50b424080aSPhilipp Zabel {
51b424080aSPhilipp Zabel 	return 0;
52b424080aSPhilipp Zabel }
53b424080aSPhilipp Zabel 
54b424080aSPhilipp Zabel static inline int reset_control_deassert(struct reset_control *rstc)
55b424080aSPhilipp Zabel {
56b424080aSPhilipp Zabel 	return 0;
57b424080aSPhilipp Zabel }
58b424080aSPhilipp Zabel 
59729de41bSDinh Nguyen static inline int reset_control_status(struct reset_control *rstc)
60729de41bSDinh Nguyen {
61729de41bSDinh Nguyen 	return 0;
62729de41bSDinh Nguyen }
63729de41bSDinh Nguyen 
64c84b0326SPhilipp Zabel static inline int reset_control_acquire(struct reset_control *rstc)
65c84b0326SPhilipp Zabel {
66c84b0326SPhilipp Zabel 	return 0;
67c84b0326SPhilipp Zabel }
68c84b0326SPhilipp Zabel 
69c84b0326SPhilipp Zabel static inline void reset_control_release(struct reset_control *rstc)
70c84b0326SPhilipp Zabel {
71c84b0326SPhilipp Zabel }
72c84b0326SPhilipp Zabel 
73b424080aSPhilipp Zabel static inline void reset_control_put(struct reset_control *rstc)
74b424080aSPhilipp Zabel {
75b424080aSPhilipp Zabel }
76b424080aSPhilipp Zabel 
771554bbd4SMasahiro Yamada static inline int __device_reset(struct device *dev, bool optional)
7841136522SDaniel Lezcano {
791554bbd4SMasahiro Yamada 	return optional ? 0 : -ENOTSUPP;
80b424080aSPhilipp Zabel }
81b424080aSPhilipp Zabel 
826c96f05cSHans de Goede static inline struct reset_control *__of_reset_control_get(
836c96f05cSHans de Goede 					struct device_node *node,
84bb475230SRamiro Oliveira 					const char *id, int index, bool shared,
85c84b0326SPhilipp Zabel 					bool optional, bool acquired)
865bcd0b7fSAxel Lin {
870ca10b60SPhilipp Zabel 	return optional ? NULL : ERR_PTR(-ENOTSUPP);
885bcd0b7fSAxel Lin }
895bcd0b7fSAxel Lin 
9062e24c57SPhilipp Zabel static inline struct reset_control *__reset_control_get(
9162e24c57SPhilipp Zabel 					struct device *dev, const char *id,
92c84b0326SPhilipp Zabel 					int index, bool shared, bool optional,
93c84b0326SPhilipp Zabel 					bool acquired)
9462e24c57SPhilipp Zabel {
9562e24c57SPhilipp Zabel 	return optional ? NULL : ERR_PTR(-ENOTSUPP);
9662e24c57SPhilipp Zabel }
9762e24c57SPhilipp Zabel 
986c96f05cSHans de Goede static inline struct reset_control *__devm_reset_control_get(
99bb475230SRamiro Oliveira 					struct device *dev, const char *id,
100c84b0326SPhilipp Zabel 					int index, bool shared, bool optional,
101c84b0326SPhilipp Zabel 					bool acquired)
1026c96f05cSHans de Goede {
1030ca10b60SPhilipp Zabel 	return optional ? NULL : ERR_PTR(-ENOTSUPP);
1046c96f05cSHans de Goede }
1056c96f05cSHans de Goede 
10617c82e20SVivek Gautam static inline struct reset_control *
10717c82e20SVivek Gautam devm_reset_control_array_get(struct device *dev, bool shared, bool optional)
10817c82e20SVivek Gautam {
10917c82e20SVivek Gautam 	return optional ? NULL : ERR_PTR(-ENOTSUPP);
11017c82e20SVivek Gautam }
11117c82e20SVivek Gautam 
11217c82e20SVivek Gautam static inline struct reset_control *
113f31d5c24SThierry Reding of_reset_control_array_get(struct device_node *np, bool shared, bool optional,
114f31d5c24SThierry Reding 			   bool acquired)
11517c82e20SVivek Gautam {
11617c82e20SVivek Gautam 	return optional ? NULL : ERR_PTR(-ENOTSUPP);
11717c82e20SVivek Gautam }
11817c82e20SVivek Gautam 
119eaf91db0SGeert Uytterhoeven static inline int reset_control_get_count(struct device *dev)
120eaf91db0SGeert Uytterhoeven {
121eaf91db0SGeert Uytterhoeven 	return -ENOENT;
122eaf91db0SGeert Uytterhoeven }
123eaf91db0SGeert Uytterhoeven 
1246c96f05cSHans de Goede #endif /* CONFIG_RESET_CONTROLLER */
1256c96f05cSHans de Goede 
1261554bbd4SMasahiro Yamada static inline int __must_check device_reset(struct device *dev)
1271554bbd4SMasahiro Yamada {
1281554bbd4SMasahiro Yamada 	return __device_reset(dev, false);
1291554bbd4SMasahiro Yamada }
1301554bbd4SMasahiro Yamada 
1311554bbd4SMasahiro Yamada static inline int device_reset_optional(struct device *dev)
1321554bbd4SMasahiro Yamada {
1331554bbd4SMasahiro Yamada 	return __device_reset(dev, true);
1341554bbd4SMasahiro Yamada }
1351554bbd4SMasahiro Yamada 
1366c96f05cSHans de Goede /**
137a53e35dbSLee Jones  * reset_control_get_exclusive - Lookup and obtain an exclusive reference
138a53e35dbSLee Jones  *                               to a reset controller.
1396c96f05cSHans de Goede  * @dev: device to be reset by the controller
1406c96f05cSHans de Goede  * @id: reset line name
1416c96f05cSHans de Goede  *
1426c96f05cSHans de Goede  * Returns a struct reset_control or IS_ERR() condition containing errno.
14334845c93SGeert Uytterhoeven  * If this function is called more than once for the same reset_control it will
1440b52297fSHans de Goede  * return -EBUSY.
1450b52297fSHans de Goede  *
1460b52297fSHans de Goede  * See reset_control_get_shared for details on shared references to
1470b52297fSHans de Goede  * reset-controls.
1486c96f05cSHans de Goede  *
1496c96f05cSHans de Goede  * Use of id names is optional.
1506c96f05cSHans de Goede  */
151a53e35dbSLee Jones static inline struct reset_control *
152a53e35dbSLee Jones __must_check reset_control_get_exclusive(struct device *dev, const char *id)
1535bcd0b7fSAxel Lin {
154c84b0326SPhilipp Zabel 	return __reset_control_get(dev, id, 0, false, false, true);
155c84b0326SPhilipp Zabel }
156c84b0326SPhilipp Zabel 
157c84b0326SPhilipp Zabel /**
158c84b0326SPhilipp Zabel  * reset_control_get_exclusive_released - Lookup and obtain a temoprarily
159c84b0326SPhilipp Zabel  *                                        exclusive reference to a reset
160c84b0326SPhilipp Zabel  *                                        controller.
161c84b0326SPhilipp Zabel  * @dev: device to be reset by the controller
162c84b0326SPhilipp Zabel  * @id: reset line name
163c84b0326SPhilipp Zabel  *
164c84b0326SPhilipp Zabel  * Returns a struct reset_control or IS_ERR() condition containing errno.
165c84b0326SPhilipp Zabel  * reset-controls returned by this function must be acquired via
166c84b0326SPhilipp Zabel  * reset_control_acquire() before they can be used and should be released
167c84b0326SPhilipp Zabel  * via reset_control_release() afterwards.
168c84b0326SPhilipp Zabel  *
169c84b0326SPhilipp Zabel  * Use of id names is optional.
170c84b0326SPhilipp Zabel  */
171c84b0326SPhilipp Zabel static inline struct reset_control *
172c84b0326SPhilipp Zabel __must_check reset_control_get_exclusive_released(struct device *dev,
173c84b0326SPhilipp Zabel 						  const char *id)
174c84b0326SPhilipp Zabel {
175c84b0326SPhilipp Zabel 	return __reset_control_get(dev, id, 0, false, false, false);
1765bcd0b7fSAxel Lin }
1775bcd0b7fSAxel Lin 
1786c96f05cSHans de Goede /**
1790b52297fSHans de Goede  * reset_control_get_shared - Lookup and obtain a shared reference to a
1800b52297fSHans de Goede  *                            reset controller.
1810b52297fSHans de Goede  * @dev: device to be reset by the controller
1820b52297fSHans de Goede  * @id: reset line name
1830b52297fSHans de Goede  *
1840b52297fSHans de Goede  * Returns a struct reset_control or IS_ERR() condition containing errno.
1850b52297fSHans de Goede  * This function is intended for use with reset-controls which are shared
18612c62b9dSGeert Uytterhoeven  * between hardware blocks.
1870b52297fSHans de Goede  *
1880b52297fSHans de Goede  * When a reset-control is shared, the behavior of reset_control_assert /
1890b52297fSHans de Goede  * deassert is changed, the reset-core will keep track of a deassert_count
1900b52297fSHans de Goede  * and only (re-)assert the reset after reset_control_assert has been called
1910b52297fSHans de Goede  * as many times as reset_control_deassert was called. Also see the remark
1920b52297fSHans de Goede  * about shared reset-controls in the reset_control_assert docs.
1930b52297fSHans de Goede  *
1940b52297fSHans de Goede  * Calling reset_control_assert without first calling reset_control_deassert
1950b52297fSHans de Goede  * is not allowed on a shared reset control. Calling reset_control_reset is
1960b52297fSHans de Goede  * also not allowed on a shared reset control.
1970b52297fSHans de Goede  *
1980b52297fSHans de Goede  * Use of id names is optional.
1990b52297fSHans de Goede  */
2000b52297fSHans de Goede static inline struct reset_control *reset_control_get_shared(
2010b52297fSHans de Goede 					struct device *dev, const char *id)
2020b52297fSHans de Goede {
203c84b0326SPhilipp Zabel 	return __reset_control_get(dev, id, 0, true, false, false);
2040b52297fSHans de Goede }
2050b52297fSHans de Goede 
206*c2ffa00aSPhilipp Zabel /**
207*c2ffa00aSPhilipp Zabel  * reset_control_get_optional_exclusive - optional reset_control_get_exclusive()
208*c2ffa00aSPhilipp Zabel  * @dev: device to be reset by the controller
209*c2ffa00aSPhilipp Zabel  * @id: reset line name
210*c2ffa00aSPhilipp Zabel  *
211*c2ffa00aSPhilipp Zabel  * Optional variant of reset_control_get_exclusive(). If the requested reset
212*c2ffa00aSPhilipp Zabel  * is not specified in the device tree, this function returns NULL instead of
213*c2ffa00aSPhilipp Zabel  * an error.
214*c2ffa00aSPhilipp Zabel  *
215*c2ffa00aSPhilipp Zabel  * See reset_control_get_exclusive() for more information.
216*c2ffa00aSPhilipp Zabel  */
217a53e35dbSLee Jones static inline struct reset_control *reset_control_get_optional_exclusive(
2183c35f6edSLee Jones 					struct device *dev, const char *id)
2193c35f6edSLee Jones {
220c84b0326SPhilipp Zabel 	return __reset_control_get(dev, id, 0, false, true, true);
2213c35f6edSLee Jones }
2223c35f6edSLee Jones 
223*c2ffa00aSPhilipp Zabel /**
224*c2ffa00aSPhilipp Zabel  * reset_control_get_optional_shared - optional reset_control_get_shared()
225*c2ffa00aSPhilipp Zabel  * @dev: device to be reset by the controller
226*c2ffa00aSPhilipp Zabel  * @id: reset line name
227*c2ffa00aSPhilipp Zabel  *
228*c2ffa00aSPhilipp Zabel  * Optional variant of reset_control_get_shared(). If the requested reset
229*c2ffa00aSPhilipp Zabel  * is not specified in the device tree, this function returns NULL instead of
230*c2ffa00aSPhilipp Zabel  * an error.
231*c2ffa00aSPhilipp Zabel  *
232*c2ffa00aSPhilipp Zabel  * See reset_control_get_shared() for more information.
233*c2ffa00aSPhilipp Zabel  */
234c33d61a0SLee Jones static inline struct reset_control *reset_control_get_optional_shared(
235c33d61a0SLee Jones 					struct device *dev, const char *id)
236c33d61a0SLee Jones {
237c84b0326SPhilipp Zabel 	return __reset_control_get(dev, id, 0, true, true, false);
238c33d61a0SLee Jones }
239c33d61a0SLee Jones 
2400b52297fSHans de Goede /**
241a53e35dbSLee Jones  * of_reset_control_get_exclusive - Lookup and obtain an exclusive reference
242a53e35dbSLee Jones  *                                  to a reset controller.
2436c96f05cSHans de Goede  * @node: device to be reset by the controller
2446c96f05cSHans de Goede  * @id: reset line name
2456c96f05cSHans de Goede  *
2466c96f05cSHans de Goede  * Returns a struct reset_control or IS_ERR() condition containing errno.
2476c96f05cSHans de Goede  *
2486c96f05cSHans de Goede  * Use of id names is optional.
2496c96f05cSHans de Goede  */
250a53e35dbSLee Jones static inline struct reset_control *of_reset_control_get_exclusive(
2516c96f05cSHans de Goede 				struct device_node *node, const char *id)
2526c96f05cSHans de Goede {
253c84b0326SPhilipp Zabel 	return __of_reset_control_get(node, id, 0, false, false, true);
2546c96f05cSHans de Goede }
2556c96f05cSHans de Goede 
2566c96f05cSHans de Goede /**
25712c62b9dSGeert Uytterhoeven  * of_reset_control_get_shared - Lookup and obtain a shared reference
25840faee8eSLee Jones  *                               to a reset controller.
25940faee8eSLee Jones  * @node: device to be reset by the controller
26040faee8eSLee Jones  * @id: reset line name
26140faee8eSLee Jones  *
26240faee8eSLee Jones  * When a reset-control is shared, the behavior of reset_control_assert /
26340faee8eSLee Jones  * deassert is changed, the reset-core will keep track of a deassert_count
26440faee8eSLee Jones  * and only (re-)assert the reset after reset_control_assert has been called
26540faee8eSLee Jones  * as many times as reset_control_deassert was called. Also see the remark
26640faee8eSLee Jones  * about shared reset-controls in the reset_control_assert docs.
26740faee8eSLee Jones  *
26840faee8eSLee Jones  * Calling reset_control_assert without first calling reset_control_deassert
26940faee8eSLee Jones  * is not allowed on a shared reset control. Calling reset_control_reset is
27040faee8eSLee Jones  * also not allowed on a shared reset control.
27140faee8eSLee Jones  * Returns a struct reset_control or IS_ERR() condition containing errno.
27240faee8eSLee Jones  *
27340faee8eSLee Jones  * Use of id names is optional.
27440faee8eSLee Jones  */
27540faee8eSLee Jones static inline struct reset_control *of_reset_control_get_shared(
27640faee8eSLee Jones 				struct device_node *node, const char *id)
27740faee8eSLee Jones {
278c84b0326SPhilipp Zabel 	return __of_reset_control_get(node, id, 0, true, false, false);
27940faee8eSLee Jones }
28040faee8eSLee Jones 
28140faee8eSLee Jones /**
282a53e35dbSLee Jones  * of_reset_control_get_exclusive_by_index - Lookup and obtain an exclusive
283a53e35dbSLee Jones  *                                           reference to a reset controller
284a53e35dbSLee Jones  *                                           by index.
2856c96f05cSHans de Goede  * @node: device to be reset by the controller
2866c96f05cSHans de Goede  * @index: index of the reset controller
2876c96f05cSHans de Goede  *
2886c96f05cSHans de Goede  * This is to be used to perform a list of resets for a device or power domain
2896c96f05cSHans de Goede  * in whatever order. Returns a struct reset_control or IS_ERR() condition
2906c96f05cSHans de Goede  * containing errno.
2916c96f05cSHans de Goede  */
292a53e35dbSLee Jones static inline struct reset_control *of_reset_control_get_exclusive_by_index(
2936c96f05cSHans de Goede 					struct device_node *node, int index)
2946c96f05cSHans de Goede {
295c84b0326SPhilipp Zabel 	return __of_reset_control_get(node, NULL, index, false, false, true);
2966c96f05cSHans de Goede }
2976c96f05cSHans de Goede 
2986c96f05cSHans de Goede /**
29912c62b9dSGeert Uytterhoeven  * of_reset_control_get_shared_by_index - Lookup and obtain a shared
30040faee8eSLee Jones  *                                        reference to a reset controller
30140faee8eSLee Jones  *                                        by index.
30240faee8eSLee Jones  * @node: device to be reset by the controller
30340faee8eSLee Jones  * @index: index of the reset controller
30440faee8eSLee Jones  *
30540faee8eSLee Jones  * When a reset-control is shared, the behavior of reset_control_assert /
30640faee8eSLee Jones  * deassert is changed, the reset-core will keep track of a deassert_count
30740faee8eSLee Jones  * and only (re-)assert the reset after reset_control_assert has been called
30840faee8eSLee Jones  * as many times as reset_control_deassert was called. Also see the remark
30940faee8eSLee Jones  * about shared reset-controls in the reset_control_assert docs.
31040faee8eSLee Jones  *
31140faee8eSLee Jones  * Calling reset_control_assert without first calling reset_control_deassert
31240faee8eSLee Jones  * is not allowed on a shared reset control. Calling reset_control_reset is
31340faee8eSLee Jones  * also not allowed on a shared reset control.
31440faee8eSLee Jones  * Returns a struct reset_control or IS_ERR() condition containing errno.
31540faee8eSLee Jones  *
31640faee8eSLee Jones  * This is to be used to perform a list of resets for a device or power domain
31740faee8eSLee Jones  * in whatever order. Returns a struct reset_control or IS_ERR() condition
31840faee8eSLee Jones  * containing errno.
31940faee8eSLee Jones  */
32040faee8eSLee Jones static inline struct reset_control *of_reset_control_get_shared_by_index(
32140faee8eSLee Jones 					struct device_node *node, int index)
32240faee8eSLee Jones {
323c84b0326SPhilipp Zabel 	return __of_reset_control_get(node, NULL, index, true, false, false);
32440faee8eSLee Jones }
32540faee8eSLee Jones 
32640faee8eSLee Jones /**
327a53e35dbSLee Jones  * devm_reset_control_get_exclusive - resource managed
328a53e35dbSLee Jones  *                                    reset_control_get_exclusive()
3296c96f05cSHans de Goede  * @dev: device to be reset by the controller
3306c96f05cSHans de Goede  * @id: reset line name
3316c96f05cSHans de Goede  *
332a53e35dbSLee Jones  * Managed reset_control_get_exclusive(). For reset controllers returned
333a53e35dbSLee Jones  * from this function, reset_control_put() is called automatically on driver
334a53e35dbSLee Jones  * detach.
335a53e35dbSLee Jones  *
336a53e35dbSLee Jones  * See reset_control_get_exclusive() for more information.
3376c96f05cSHans de Goede  */
338a53e35dbSLee Jones static inline struct reset_control *
339a53e35dbSLee Jones __must_check devm_reset_control_get_exclusive(struct device *dev,
340a53e35dbSLee Jones 					      const char *id)
3416c96f05cSHans de Goede {
342c84b0326SPhilipp Zabel 	return __devm_reset_control_get(dev, id, 0, false, false, true);
343c84b0326SPhilipp Zabel }
344c84b0326SPhilipp Zabel 
345c84b0326SPhilipp Zabel /**
346c84b0326SPhilipp Zabel  * devm_reset_control_get_exclusive_released - resource managed
347c84b0326SPhilipp Zabel  *                                             reset_control_get_exclusive_released()
348c84b0326SPhilipp Zabel  * @dev: device to be reset by the controller
349c84b0326SPhilipp Zabel  * @id: reset line name
350c84b0326SPhilipp Zabel  *
351c84b0326SPhilipp Zabel  * Managed reset_control_get_exclusive_released(). For reset controllers
352c84b0326SPhilipp Zabel  * returned from this function, reset_control_put() is called automatically on
353c84b0326SPhilipp Zabel  * driver detach.
354c84b0326SPhilipp Zabel  *
355c84b0326SPhilipp Zabel  * See reset_control_get_exclusive_released() for more information.
356c84b0326SPhilipp Zabel  */
357c84b0326SPhilipp Zabel static inline struct reset_control *
358c84b0326SPhilipp Zabel __must_check devm_reset_control_get_exclusive_released(struct device *dev,
359c84b0326SPhilipp Zabel 						       const char *id)
360c84b0326SPhilipp Zabel {
361c84b0326SPhilipp Zabel 	return __devm_reset_control_get(dev, id, 0, false, false, false);
362b424080aSPhilipp Zabel }
363b424080aSPhilipp Zabel 
3640b52297fSHans de Goede /**
3650b52297fSHans de Goede  * devm_reset_control_get_shared - resource managed reset_control_get_shared()
3660b52297fSHans de Goede  * @dev: device to be reset by the controller
3670b52297fSHans de Goede  * @id: reset line name
3680b52297fSHans de Goede  *
3690b52297fSHans de Goede  * Managed reset_control_get_shared(). For reset controllers returned from
3700b52297fSHans de Goede  * this function, reset_control_put() is called automatically on driver detach.
3710b52297fSHans de Goede  * See reset_control_get_shared() for more information.
3720b52297fSHans de Goede  */
3730b52297fSHans de Goede static inline struct reset_control *devm_reset_control_get_shared(
3740b52297fSHans de Goede 					struct device *dev, const char *id)
3750b52297fSHans de Goede {
376c84b0326SPhilipp Zabel 	return __devm_reset_control_get(dev, id, 0, true, false, false);
3770b52297fSHans de Goede }
3780b52297fSHans de Goede 
379*c2ffa00aSPhilipp Zabel /**
380*c2ffa00aSPhilipp Zabel  * devm_reset_control_get_optional_exclusive - resource managed
381*c2ffa00aSPhilipp Zabel  *                                             reset_control_get_optional_exclusive()
382*c2ffa00aSPhilipp Zabel  * @dev: device to be reset by the controller
383*c2ffa00aSPhilipp Zabel  * @id: reset line name
384*c2ffa00aSPhilipp Zabel  *
385*c2ffa00aSPhilipp Zabel  * Managed reset_control_get_optional_exclusive(). For reset controllers
386*c2ffa00aSPhilipp Zabel  * returned from this function, reset_control_put() is called automatically on
387*c2ffa00aSPhilipp Zabel  * driver detach.
388*c2ffa00aSPhilipp Zabel  *
389*c2ffa00aSPhilipp Zabel  * See reset_control_get_optional_exclusive() for more information.
390*c2ffa00aSPhilipp Zabel  */
391a53e35dbSLee Jones static inline struct reset_control *devm_reset_control_get_optional_exclusive(
392b424080aSPhilipp Zabel 					struct device *dev, const char *id)
393b424080aSPhilipp Zabel {
394c84b0326SPhilipp Zabel 	return __devm_reset_control_get(dev, id, 0, false, true, true);
395b424080aSPhilipp Zabel }
396b424080aSPhilipp Zabel 
397*c2ffa00aSPhilipp Zabel /**
398*c2ffa00aSPhilipp Zabel  * devm_reset_control_get_optional_shared - resource managed
399*c2ffa00aSPhilipp Zabel  *                                          reset_control_get_optional_shared()
400*c2ffa00aSPhilipp Zabel  * @dev: device to be reset by the controller
401*c2ffa00aSPhilipp Zabel  * @id: reset line name
402*c2ffa00aSPhilipp Zabel  *
403*c2ffa00aSPhilipp Zabel  * Managed reset_control_get_optional_shared(). For reset controllers returned
404*c2ffa00aSPhilipp Zabel  * from this function, reset_control_put() is called automatically on driver
405*c2ffa00aSPhilipp Zabel  * detach.
406*c2ffa00aSPhilipp Zabel  *
407*c2ffa00aSPhilipp Zabel  * See reset_control_get_optional_shared() for more information.
408*c2ffa00aSPhilipp Zabel  */
409c33d61a0SLee Jones static inline struct reset_control *devm_reset_control_get_optional_shared(
410c33d61a0SLee Jones 					struct device *dev, const char *id)
411c33d61a0SLee Jones {
412c84b0326SPhilipp Zabel 	return __devm_reset_control_get(dev, id, 0, true, true, false);
413c33d61a0SLee Jones }
414c33d61a0SLee Jones 
4156c96f05cSHans de Goede /**
416a53e35dbSLee Jones  * devm_reset_control_get_exclusive_by_index - resource managed
417a53e35dbSLee Jones  *                                             reset_control_get_exclusive()
4186c96f05cSHans de Goede  * @dev: device to be reset by the controller
4196c96f05cSHans de Goede  * @index: index of the reset controller
4206c96f05cSHans de Goede  *
421a53e35dbSLee Jones  * Managed reset_control_get_exclusive(). For reset controllers returned from
422a53e35dbSLee Jones  * this function, reset_control_put() is called automatically on driver
423a53e35dbSLee Jones  * detach.
424a53e35dbSLee Jones  *
425a53e35dbSLee Jones  * See reset_control_get_exclusive() for more information.
4266c96f05cSHans de Goede  */
427a53e35dbSLee Jones static inline struct reset_control *
428a53e35dbSLee Jones devm_reset_control_get_exclusive_by_index(struct device *dev, int index)
429e3ec0a8cSHans de Goede {
430c84b0326SPhilipp Zabel 	return __devm_reset_control_get(dev, NULL, index, false, false, true);
4310b52297fSHans de Goede }
4320b52297fSHans de Goede 
4330b52297fSHans de Goede /**
4340b52297fSHans de Goede  * devm_reset_control_get_shared_by_index - resource managed
4350b52297fSHans de Goede  *                                          reset_control_get_shared
4360b52297fSHans de Goede  * @dev: device to be reset by the controller
4370b52297fSHans de Goede  * @index: index of the reset controller
4380b52297fSHans de Goede  *
4390b52297fSHans de Goede  * Managed reset_control_get_shared(). For reset controllers returned from
4400b52297fSHans de Goede  * this function, reset_control_put() is called automatically on driver detach.
4410b52297fSHans de Goede  * See reset_control_get_shared() for more information.
4420b52297fSHans de Goede  */
4430bcc0eabSLee Jones static inline struct reset_control *
4440bcc0eabSLee Jones devm_reset_control_get_shared_by_index(struct device *dev, int index)
4450b52297fSHans de Goede {
446c84b0326SPhilipp Zabel 	return __devm_reset_control_get(dev, NULL, index, true, false, false);
447e3ec0a8cSHans de Goede }
448e3ec0a8cSHans de Goede 
449a53e35dbSLee Jones /*
450a53e35dbSLee Jones  * TEMPORARY calls to use during transition:
451a53e35dbSLee Jones  *
452a53e35dbSLee Jones  *   of_reset_control_get() => of_reset_control_get_exclusive()
453a53e35dbSLee Jones  *
454a53e35dbSLee Jones  * These inline function calls will be removed once all consumers
455a53e35dbSLee Jones  * have been moved over to the new explicit API.
456a53e35dbSLee Jones  */
457a53e35dbSLee Jones static inline struct reset_control *of_reset_control_get(
458a53e35dbSLee Jones 				struct device_node *node, const char *id)
459a53e35dbSLee Jones {
460a53e35dbSLee Jones 	return of_reset_control_get_exclusive(node, id);
461a53e35dbSLee Jones }
462a53e35dbSLee Jones 
463a53e35dbSLee Jones static inline struct reset_control *of_reset_control_get_by_index(
464a53e35dbSLee Jones 				struct device_node *node, int index)
465a53e35dbSLee Jones {
466a53e35dbSLee Jones 	return of_reset_control_get_exclusive_by_index(node, index);
467a53e35dbSLee Jones }
468a53e35dbSLee Jones 
469a53e35dbSLee Jones static inline struct reset_control *devm_reset_control_get(
470a53e35dbSLee Jones 				struct device *dev, const char *id)
471a53e35dbSLee Jones {
472a53e35dbSLee Jones 	return devm_reset_control_get_exclusive(dev, id);
473a53e35dbSLee Jones }
474a53e35dbSLee Jones 
475a53e35dbSLee Jones static inline struct reset_control *devm_reset_control_get_optional(
476a53e35dbSLee Jones 				struct device *dev, const char *id)
477a53e35dbSLee Jones {
478a53e35dbSLee Jones 	return devm_reset_control_get_optional_exclusive(dev, id);
479a53e35dbSLee Jones 
480a53e35dbSLee Jones }
481a53e35dbSLee Jones 
482a53e35dbSLee Jones static inline struct reset_control *devm_reset_control_get_by_index(
483a53e35dbSLee Jones 				struct device *dev, int index)
484a53e35dbSLee Jones {
485a53e35dbSLee Jones 	return devm_reset_control_get_exclusive_by_index(dev, index);
486a53e35dbSLee Jones }
48717c82e20SVivek Gautam 
48817c82e20SVivek Gautam /*
48917c82e20SVivek Gautam  * APIs to manage a list of reset controllers
49017c82e20SVivek Gautam  */
49117c82e20SVivek Gautam static inline struct reset_control *
49217c82e20SVivek Gautam devm_reset_control_array_get_exclusive(struct device *dev)
49317c82e20SVivek Gautam {
49417c82e20SVivek Gautam 	return devm_reset_control_array_get(dev, false, false);
49517c82e20SVivek Gautam }
49617c82e20SVivek Gautam 
49717c82e20SVivek Gautam static inline struct reset_control *
49817c82e20SVivek Gautam devm_reset_control_array_get_shared(struct device *dev)
49917c82e20SVivek Gautam {
50017c82e20SVivek Gautam 	return devm_reset_control_array_get(dev, true, false);
50117c82e20SVivek Gautam }
50217c82e20SVivek Gautam 
50317c82e20SVivek Gautam static inline struct reset_control *
50417c82e20SVivek Gautam devm_reset_control_array_get_optional_exclusive(struct device *dev)
50517c82e20SVivek Gautam {
50617c82e20SVivek Gautam 	return devm_reset_control_array_get(dev, false, true);
50717c82e20SVivek Gautam }
50817c82e20SVivek Gautam 
50917c82e20SVivek Gautam static inline struct reset_control *
51017c82e20SVivek Gautam devm_reset_control_array_get_optional_shared(struct device *dev)
51117c82e20SVivek Gautam {
51217c82e20SVivek Gautam 	return devm_reset_control_array_get(dev, true, true);
51317c82e20SVivek Gautam }
51417c82e20SVivek Gautam 
51517c82e20SVivek Gautam static inline struct reset_control *
51617c82e20SVivek Gautam of_reset_control_array_get_exclusive(struct device_node *node)
51717c82e20SVivek Gautam {
518f31d5c24SThierry Reding 	return of_reset_control_array_get(node, false, false, true);
51917c82e20SVivek Gautam }
52017c82e20SVivek Gautam 
52117c82e20SVivek Gautam static inline struct reset_control *
52222815f18SThierry Reding of_reset_control_array_get_exclusive_released(struct device_node *node)
52322815f18SThierry Reding {
52422815f18SThierry Reding 	return of_reset_control_array_get(node, false, false, false);
52522815f18SThierry Reding }
52622815f18SThierry Reding 
52722815f18SThierry Reding static inline struct reset_control *
52817c82e20SVivek Gautam of_reset_control_array_get_shared(struct device_node *node)
52917c82e20SVivek Gautam {
530f31d5c24SThierry Reding 	return of_reset_control_array_get(node, true, false, true);
53117c82e20SVivek Gautam }
53217c82e20SVivek Gautam 
53317c82e20SVivek Gautam static inline struct reset_control *
53417c82e20SVivek Gautam of_reset_control_array_get_optional_exclusive(struct device_node *node)
53517c82e20SVivek Gautam {
536f31d5c24SThierry Reding 	return of_reset_control_array_get(node, false, true, true);
53717c82e20SVivek Gautam }
53817c82e20SVivek Gautam 
53917c82e20SVivek Gautam static inline struct reset_control *
54017c82e20SVivek Gautam of_reset_control_array_get_optional_shared(struct device_node *node)
54117c82e20SVivek Gautam {
542f31d5c24SThierry Reding 	return of_reset_control_array_get(node, true, true, true);
54317c82e20SVivek Gautam }
54461fc4131SPhilipp Zabel #endif
545