]> git.karo-electronics.de Git - karo-tx-linux.git/blob - include/linux/gpio/consumer.h
gpio: Fix build breakage
[karo-tx-linux.git] / include / linux / gpio / consumer.h
1 #ifndef __LINUX_GPIO_CONSUMER_H
2 #define __LINUX_GPIO_CONSUMER_H
3
4 #include <linux/err.h>
5 #include <linux/kernel.h>
6
7 #ifdef CONFIG_GPIOLIB
8
9 struct device;
10 struct gpio_chip;
11
12 /**
13  * Opaque descriptor for a GPIO. These are obtained using gpiod_get() and are
14  * preferable to the old integer-based handles.
15  *
16  * Contrary to integers, a pointer to a gpio_desc is guaranteed to be valid
17  * until the GPIO is released.
18  */
19 struct gpio_desc;
20
21 /* Acquire and dispose GPIOs */
22 struct gpio_desc *__must_check gpiod_get(struct device *dev,
23                                          const char *con_id);
24 struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
25                                                const char *con_id,
26                                                unsigned int idx);
27 void gpiod_put(struct gpio_desc *desc);
28
29 int gpiod_get_direction(const struct gpio_desc *desc);
30 int gpiod_direction_input(struct gpio_desc *desc);
31 int gpiod_direction_output(struct gpio_desc *desc, int value);
32
33 /* Value get/set from non-sleeping context */
34 int gpiod_get_value(const struct gpio_desc *desc);
35 void gpiod_set_value(struct gpio_desc *desc, int value);
36 int gpiod_get_raw_value(const struct gpio_desc *desc);
37 void gpiod_set_raw_value(struct gpio_desc *desc, int value);
38
39 /* Value get/set from sleeping context */
40 int gpiod_get_value_cansleep(const struct gpio_desc *desc);
41 void gpiod_set_value_cansleep(struct gpio_desc *desc, int value);
42 int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc);
43 void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, int value);
44
45 int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce);
46
47 int gpiod_is_active_low(const struct gpio_desc *desc);
48 int gpiod_cansleep(const struct gpio_desc *desc);
49
50 int gpiod_to_irq(const struct gpio_desc *desc);
51
52 /* Convert between the old gpio_ and new gpiod_ interfaces */
53 struct gpio_desc *gpio_to_desc(unsigned gpio);
54 int desc_to_gpio(const struct gpio_desc *desc);
55 struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc);
56
57 #else /* CONFIG_GPIOLIB */
58
59 static inline struct gpio_desc *__must_check gpiod_get(struct device *dev,
60                                                        const char *con_id)
61 {
62         return ERR_PTR(-ENOSYS);
63 }
64
65 static inline struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
66                                                              const char *con_id,
67                                                              unsigned int idx)
68 {
69         return ERR_PTR(-ENOSYS);
70 }
71
72 static inline void gpiod_put(struct gpio_desc *desc)
73 {
74         might_sleep();
75
76         /* GPIO can never have been requested */
77         WARN_ON(1);
78 }
79
80 static inline int gpiod_get_direction(const struct gpio_desc *desc)
81 {
82         /* GPIO can never have been requested */
83         WARN_ON(1);
84         return -ENOSYS;
85 }
86
87 static inline int gpiod_direction_input(struct gpio_desc *desc)
88 {
89         /* GPIO can never have been requested */
90         WARN_ON(1);
91         return -ENOSYS;
92 }
93
94 static inline int gpiod_direction_output(struct gpio_desc *desc, int value)
95 {
96         /* GPIO can never have been requested */
97         WARN_ON(1);
98         return -ENOSYS;
99 }
100
101 static inline int gpiod_get_value(const struct gpio_desc *desc)
102 {
103         /* GPIO can never have been requested */
104         WARN_ON(1);
105         return 0;
106 }
107
108 static inline void gpiod_set_value(struct gpio_desc *desc, int value)
109 {
110         /* GPIO can never have been requested */
111         WARN_ON(1);
112 }
113
114 static inline int gpiod_get_raw_value(const struct gpio_desc *desc)
115 {
116         /* GPIO can never have been requested */
117         WARN_ON(1);
118         return 0;
119 }
120
121 static inline void gpiod_set_raw_value(struct gpio_desc *desc, int value)
122 {
123         /* GPIO can never have been requested */
124         WARN_ON(1);
125 }
126
127 static inline int gpiod_get_value_cansleep(const struct gpio_desc *desc)
128 {
129         /* GPIO can never have been requested */
130         WARN_ON(1);
131         return 0;
132 }
133
134 static inline void gpiod_set_value_cansleep(struct gpio_desc *desc, int value)
135 {
136         /* GPIO can never have been requested */
137         WARN_ON(1);
138 }
139
140 static inline int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc)
141 {
142         /* GPIO can never have been requested */
143         WARN_ON(1);
144         return 0;
145 }
146
147 static inline void gpiod_set_raw_value_cansleep(struct gpio_desc *desc,
148                                                 int value)
149 {
150         /* GPIO can never have been requested */
151         WARN_ON(1);
152 }
153
154 static inline int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce)
155 {
156         /* GPIO can never have been requested */
157         WARN_ON(1);
158         return -ENOSYS;
159 }
160
161 static inline int gpiod_is_active_low(const struct gpio_desc *desc)
162 {
163         /* GPIO can never have been requested */
164         WARN_ON(1);
165         return 0;
166 }
167
168 static inline int gpiod_cansleep(const struct gpio_desc *desc)
169 {
170         /* GPIO can never have been requested */
171         WARN_ON(1);
172         return 0;
173 }
174
175 static inline int gpiod_to_irq(const struct gpio_desc *desc)
176 {
177         /* GPIO can never have been requested */
178         WARN_ON(1);
179         return -EINVAL;
180 }
181
182 static inline struct gpio_desc *gpio_to_desc(unsigned gpio)
183 {
184         return ERR_PTR(-EINVAL);
185 }
186
187 static inline int desc_to_gpio(const struct gpio_desc *desc)
188 {
189         /* GPIO can never have been requested */
190         WARN_ON(1);
191         return -EINVAL;
192 }
193
194 static inline struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc)
195 {
196         /* GPIO can never have been requested */
197         WARN_ON(1);
198         return ERR_PTR(-ENODEV);
199 }
200
201 #endif /* CONFIG_GPIOLIB */
202
203 #if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS)
204
205 int gpiod_export(struct gpio_desc *desc, bool direction_may_change);
206 int gpiod_export_link(struct device *dev, const char *name,
207                       struct gpio_desc *desc);
208 int gpiod_sysfs_set_active_low(struct gpio_desc *desc, int value);
209 void gpiod_unexport(struct gpio_desc *desc);
210
211 #else  /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */
212
213 static inline int gpiod_export(struct gpio_desc *desc,
214                                bool direction_may_change)
215 {
216         return -ENOSYS;
217 }
218
219 static inline int gpiod_export_link(struct device *dev, const char *name,
220                                     struct gpio_desc *desc)
221 {
222         return -ENOSYS;
223 }
224
225 static inline int gpiod_sysfs_set_active_low(struct gpio_desc *desc, int value)
226 {
227         return -ENOSYS;
228 }
229
230 static inline void gpiod_unexport(struct gpio_desc *desc)
231 {
232 }
233
234 #endif /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */
235
236 #ifdef CONFIG_GPIO_DEVRES
237 struct gpio_desc *__must_check devm_gpiod_get(struct device *dev,
238                                               const char *con_id);
239 struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev,
240                                                     const char *con_id,
241                                                     unsigned int idx);
242 void devm_gpiod_put(struct device *dev, struct gpio_desc *desc);
243 #else
244 static inline struct gpio_desc *__must_check devm_gpiod_get(struct device *dev,
245                                                             const char *con_id)
246 {
247         return ERR_PTR(-ENOSYS);
248 }
249
250 static inline
251 struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev,
252                                                     const char *con_id,
253                                                     unsigned int idx)
254 {
255         return ERR_PTR(-ENOSYS);
256 }
257
258 static inline void devm_gpiod_put(struct device *dev, struct gpio_desc *desc)
259 {
260         might_sleep();
261
262         /* GPIO can never have been requested */
263         WARN_ON(1);
264 }
265 #endif
266
267 #endif