Merge tag 'tegra-for-4.7-pci' of git://git.kernel.org/pub/scm/linux/kernel/git/tegra...
[deliverable/linux.git] / include / linux / reset.h
1 #ifndef _LINUX_RESET_H_
2 #define _LINUX_RESET_H_
3
4 #include <linux/device.h>
5
6 struct reset_control;
7
8 #ifdef CONFIG_RESET_CONTROLLER
9
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);
14
15 struct reset_control *__of_reset_control_get(struct device_node *node,
16 const char *id, int index, int shared);
17 void reset_control_put(struct reset_control *rstc);
18 struct reset_control *__devm_reset_control_get(struct device *dev,
19 const char *id, int index, int shared);
20
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
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
48 static inline int reset_control_status(struct reset_control *rstc)
49 {
50 WARN_ON(1);
51 return 0;
52 }
53
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 {
61 return -ENOTSUPP;
62 }
63
64 static inline struct reset_control *__of_reset_control_get(
65 struct device_node *node,
66 const char *id, int index, int shared)
67 {
68 return ERR_PTR(-EINVAL);
69 }
70
71 static inline struct reset_control *__devm_reset_control_get(
72 struct device *dev,
73 const char *id, int index, int shared)
74 {
75 return ERR_PTR(-EINVAL);
76 }
77
78 #endif /* CONFIG_RESET_CONTROLLER */
79
80 /**
81 * reset_control_get - Lookup and obtain an exclusive reference to a
82 * reset controller.
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.
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.
92 *
93 * Use of id names is optional.
94 */
95 static inline struct reset_control *__must_check reset_control_get(
96 struct device *dev, const char *id)
97 {
98 #ifndef CONFIG_RESET_CONTROLLER
99 WARN_ON(1);
100 #endif
101 return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, 0);
102 }
103
104 static inline struct reset_control *reset_control_get_optional(
105 struct device *dev, const char *id)
106 {
107 return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, 0);
108 }
109
110 /**
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.
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 */
148 static inline struct reset_control *of_reset_control_get(
149 struct device_node *node, const char *id)
150 {
151 return __of_reset_control_get(node, id, 0, 0);
152 }
153
154 /**
155 * of_reset_control_get_by_index - Lookup and obtain an exclusive reference to
156 * a reset controller by index.
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 */
164 static inline struct reset_control *of_reset_control_get_by_index(
165 struct device_node *node, int index)
166 {
167 return __of_reset_control_get(node, NULL, index, 0);
168 }
169
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
185 return __devm_reset_control_get(dev, id, 0, 0);
186 }
187
188 static inline struct reset_control *devm_reset_control_get_optional(
189 struct device *dev, const char *id)
190 {
191 return __devm_reset_control_get(dev, id, 0, 0);
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 {
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);
238 }
239
240 #endif
This page took 0.035374 seconds and 6 git commands to generate.