Merge tag 'dmaengine-fix-4.7-rc4' of git://git.infradead.org/users/vkoul/slave-dma
[linux-2.6-block.git] / include / linux / reset.h
CommitLineData
61fc4131
PZ
1#ifndef _LINUX_RESET_H_
2#define _LINUX_RESET_H_
3
6c96f05c
HG
4#include <linux/device.h>
5
61fc4131
PZ
6struct reset_control;
7
b424080a
PZ
8#ifdef CONFIG_RESET_CONTROLLER
9
61fc4131
PZ
10int reset_control_reset(struct reset_control *rstc);
11int reset_control_assert(struct reset_control *rstc);
12int reset_control_deassert(struct reset_control *rstc);
729de41b 13int reset_control_status(struct reset_control *rstc);
61fc4131 14
6c96f05c 15struct reset_control *__of_reset_control_get(struct device_node *node,
0b52297f 16 const char *id, int index, int shared);
61fc4131 17void reset_control_put(struct reset_control *rstc);
6c96f05c 18struct reset_control *__devm_reset_control_get(struct device *dev,
0b52297f 19 const char *id, int index, int shared);
61fc4131 20
b424080a
PZ
21int __must_check device_reset(struct device *dev);
22
23static inline int device_reset_optional(struct device *dev)
24{
25 return device_reset(dev);
26}
27
b424080a
PZ
28#else
29
30static inline int reset_control_reset(struct reset_control *rstc)
31{
32 WARN_ON(1);
33 return 0;
34}
35
36static inline int reset_control_assert(struct reset_control *rstc)
37{
38 WARN_ON(1);
39 return 0;
40}
41
42static inline int reset_control_deassert(struct reset_control *rstc)
43{
44 WARN_ON(1);
45 return 0;
46}
47
729de41b
DN
48static inline int reset_control_status(struct reset_control *rstc)
49{
50 WARN_ON(1);
51 return 0;
52}
53
b424080a
PZ
54static inline void reset_control_put(struct reset_control *rstc)
55{
56 WARN_ON(1);
57}
58
41136522
DL
59static inline int __must_check device_reset(struct device *dev)
60{
61 WARN_ON(1);
62 return -ENOTSUPP;
63}
64
b424080a
PZ
65static inline int device_reset_optional(struct device *dev)
66{
39b4da71 67 return -ENOTSUPP;
b424080a
PZ
68}
69
6c96f05c
HG
70static inline struct reset_control *__of_reset_control_get(
71 struct device_node *node,
0b52297f 72 const char *id, int index, int shared)
5bcd0b7f 73{
5bcd0b7f
AL
74 return ERR_PTR(-EINVAL);
75}
76
6c96f05c
HG
77static inline struct reset_control *__devm_reset_control_get(
78 struct device *dev,
0b52297f 79 const char *id, int index, int shared)
5bcd0b7f 80{
5bcd0b7f
AL
81 return ERR_PTR(-EINVAL);
82}
83
6c96f05c
HG
84#endif /* CONFIG_RESET_CONTROLLER */
85
86/**
0b52297f
HG
87 * reset_control_get - Lookup and obtain an exclusive reference to a
88 * reset controller.
6c96f05c
HG
89 * @dev: device to be reset by the controller
90 * @id: reset line name
91 *
92 * Returns a struct reset_control or IS_ERR() condition containing errno.
0b52297f
HG
93 * If this function is called more then once for the same reset_control it will
94 * return -EBUSY.
95 *
96 * See reset_control_get_shared for details on shared references to
97 * reset-controls.
6c96f05c
HG
98 *
99 * Use of id names is optional.
100 */
101static inline struct reset_control *__must_check reset_control_get(
b424080a
PZ
102 struct device *dev, const char *id)
103{
6c96f05c
HG
104#ifndef CONFIG_RESET_CONTROLLER
105 WARN_ON(1);
106#endif
0b52297f 107 return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, 0);
b424080a
PZ
108}
109
6c96f05c 110static inline struct reset_control *reset_control_get_optional(
b424080a
PZ
111 struct device *dev, const char *id)
112{
0b52297f 113 return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, 0);
b424080a
PZ
114}
115
6c96f05c 116/**
0b52297f
HG
117 * reset_control_get_shared - Lookup and obtain a shared reference to a
118 * reset controller.
119 * @dev: device to be reset by the controller
120 * @id: reset line name
121 *
122 * Returns a struct reset_control or IS_ERR() condition containing errno.
123 * This function is intended for use with reset-controls which are shared
124 * between hardware-blocks.
125 *
126 * When a reset-control is shared, the behavior of reset_control_assert /
127 * deassert is changed, the reset-core will keep track of a deassert_count
128 * and only (re-)assert the reset after reset_control_assert has been called
129 * as many times as reset_control_deassert was called. Also see the remark
130 * about shared reset-controls in the reset_control_assert docs.
131 *
132 * Calling reset_control_assert without first calling reset_control_deassert
133 * is not allowed on a shared reset control. Calling reset_control_reset is
134 * also not allowed on a shared reset control.
135 *
136 * Use of id names is optional.
137 */
138static inline struct reset_control *reset_control_get_shared(
139 struct device *dev, const char *id)
140{
141 return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, 1);
142}
143
144/**
145 * of_reset_control_get - Lookup and obtain an exclusive reference to a
146 * reset controller.
6c96f05c
HG
147 * @node: device to be reset by the controller
148 * @id: reset line name
149 *
150 * Returns a struct reset_control or IS_ERR() condition containing errno.
151 *
152 * Use of id names is optional.
153 */
e3ec0a8c
HG
154static inline struct reset_control *of_reset_control_get(
155 struct device_node *node, const char *id)
156{
0b52297f 157 return __of_reset_control_get(node, id, 0, 0);
e3ec0a8c
HG
158}
159
6c96f05c 160/**
0b52297f
HG
161 * of_reset_control_get_by_index - Lookup and obtain an exclusive reference to
162 * a reset controller by index.
6c96f05c
HG
163 * @node: device to be reset by the controller
164 * @index: index of the reset controller
165 *
166 * This is to be used to perform a list of resets for a device or power domain
167 * in whatever order. Returns a struct reset_control or IS_ERR() condition
168 * containing errno.
169 */
c0a13aa6 170static inline struct reset_control *of_reset_control_get_by_index(
6c96f05c 171 struct device_node *node, int index)
c0a13aa6 172{
0b52297f 173 return __of_reset_control_get(node, NULL, index, 0);
c0a13aa6
VH
174}
175
6c96f05c
HG
176/**
177 * devm_reset_control_get - resource managed reset_control_get()
178 * @dev: device to be reset by the controller
179 * @id: reset line name
180 *
181 * Managed reset_control_get(). For reset controllers returned from this
182 * function, reset_control_put() is called automatically on driver detach.
183 * See reset_control_get() for more information.
184 */
185static inline struct reset_control *__must_check devm_reset_control_get(
186 struct device *dev, const char *id)
187{
188#ifndef CONFIG_RESET_CONTROLLER
189 WARN_ON(1);
190#endif
0b52297f 191 return __devm_reset_control_get(dev, id, 0, 0);
6c96f05c
HG
192}
193
194static inline struct reset_control *devm_reset_control_get_optional(
195 struct device *dev, const char *id)
196{
0b52297f 197 return __devm_reset_control_get(dev, id, 0, 0);
6c96f05c
HG
198}
199
200/**
201 * devm_reset_control_get_by_index - resource managed reset_control_get
202 * @dev: device to be reset by the controller
203 * @index: index of the reset controller
204 *
205 * Managed reset_control_get(). For reset controllers returned from this
206 * function, reset_control_put() is called automatically on driver detach.
207 * See reset_control_get() for more information.
208 */
209static inline struct reset_control *devm_reset_control_get_by_index(
210 struct device *dev, int index)
211{
0b52297f
HG
212 return __devm_reset_control_get(dev, NULL, index, 0);
213}
214
215/**
216 * devm_reset_control_get_shared - resource managed reset_control_get_shared()
217 * @dev: device to be reset by the controller
218 * @id: reset line name
219 *
220 * Managed reset_control_get_shared(). For reset controllers returned from
221 * this function, reset_control_put() is called automatically on driver detach.
222 * See reset_control_get_shared() for more information.
223 */
224static inline struct reset_control *devm_reset_control_get_shared(
225 struct device *dev, const char *id)
226{
227 return __devm_reset_control_get(dev, id, 0, 1);
228}
229
230/**
231 * devm_reset_control_get_shared_by_index - resource managed
232 * reset_control_get_shared
233 * @dev: device to be reset by the controller
234 * @index: index of the reset controller
235 *
236 * Managed reset_control_get_shared(). For reset controllers returned from
237 * this function, reset_control_put() is called automatically on driver detach.
238 * See reset_control_get_shared() for more information.
239 */
240static inline struct reset_control *devm_reset_control_get_shared_by_index(
241 struct device *dev, int index)
242{
243 return __devm_reset_control_get(dev, NULL, index, 1);
6c96f05c 244}
61fc4131
PZ
245
246#endif