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