1#ifndef __LINUX_GPIO_H
2#define __LINUX_GPIO_H
3
4#include <linux/errno.h>
5
6
7
8
9#define GPIOF_DIR_OUT (0 << 0)
10#define GPIOF_DIR_IN (1 << 0)
11
12#define GPIOF_INIT_LOW (0 << 1)
13#define GPIOF_INIT_HIGH (1 << 1)
14
15#define GPIOF_IN (GPIOF_DIR_IN)
16#define GPIOF_OUT_INIT_LOW (GPIOF_DIR_OUT | GPIOF_INIT_LOW)
17#define GPIOF_OUT_INIT_HIGH (GPIOF_DIR_OUT | GPIOF_INIT_HIGH)
18
19
20#define GPIOF_ACTIVE_LOW (1 << 2)
21
22
23#define GPIOF_OPEN_DRAIN (1 << 3)
24
25
26#define GPIOF_OPEN_SOURCE (1 << 4)
27
28#define GPIOF_EXPORT (1 << 5)
29#define GPIOF_EXPORT_CHANGEABLE (1 << 6)
30#define GPIOF_EXPORT_DIR_FIXED (GPIOF_EXPORT)
31#define GPIOF_EXPORT_DIR_CHANGEABLE (GPIOF_EXPORT | GPIOF_EXPORT_CHANGEABLE)
32
33
34
35
36
37
38
39struct gpio {
40 unsigned gpio;
41 unsigned long flags;
42 const char *label;
43};
44
45#ifdef CONFIG_GPIOLIB
46
47#ifdef CONFIG_ARCH_HAVE_CUSTOM_GPIO_H
48#include <asm/gpio.h>
49#else
50
51#include <asm-generic/gpio.h>
52
53static inline int gpio_get_value(unsigned int gpio)
54{
55 return __gpio_get_value(gpio);
56}
57
58static inline void gpio_set_value(unsigned int gpio, int value)
59{
60 __gpio_set_value(gpio, value);
61}
62
63static inline int gpio_cansleep(unsigned int gpio)
64{
65 return __gpio_cansleep(gpio);
66}
67
68static inline int gpio_to_irq(unsigned int gpio)
69{
70 return __gpio_to_irq(gpio);
71}
72
73static inline int irq_to_gpio(unsigned int irq)
74{
75 return -EINVAL;
76}
77
78#endif
79
80
81
82struct device;
83
84int devm_gpio_request(struct device *dev, unsigned gpio, const char *label);
85int devm_gpio_request_one(struct device *dev, unsigned gpio,
86 unsigned long flags, const char *label);
87void devm_gpio_free(struct device *dev, unsigned int gpio);
88
89#else
90
91#include <linux/kernel.h>
92#include <linux/types.h>
93#include <linux/bug.h>
94#include <linux/pinctrl/pinctrl.h>
95
96struct device;
97struct gpio_chip;
98
99static inline bool gpio_is_valid(int number)
100{
101 return false;
102}
103
104static inline int gpio_request(unsigned gpio, const char *label)
105{
106 return -ENOSYS;
107}
108
109static inline int gpio_request_one(unsigned gpio,
110 unsigned long flags, const char *label)
111{
112 return -ENOSYS;
113}
114
115static inline int gpio_request_array(const struct gpio *array, size_t num)
116{
117 return -ENOSYS;
118}
119
120static inline void gpio_free(unsigned gpio)
121{
122 might_sleep();
123
124
125 WARN_ON(1);
126}
127
128static inline void gpio_free_array(const struct gpio *array, size_t num)
129{
130 might_sleep();
131
132
133 WARN_ON(1);
134}
135
136static inline int gpio_direction_input(unsigned gpio)
137{
138 return -ENOSYS;
139}
140
141static inline int gpio_direction_output(unsigned gpio, int value)
142{
143 return -ENOSYS;
144}
145
146static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
147{
148 return -ENOSYS;
149}
150
151static inline int gpio_get_value(unsigned gpio)
152{
153
154 WARN_ON(1);
155 return 0;
156}
157
158static inline void gpio_set_value(unsigned gpio, int value)
159{
160
161 WARN_ON(1);
162}
163
164static inline int gpio_cansleep(unsigned gpio)
165{
166
167 WARN_ON(1);
168 return 0;
169}
170
171static inline int gpio_get_value_cansleep(unsigned gpio)
172{
173
174 WARN_ON(1);
175 return 0;
176}
177
178static inline void gpio_set_value_cansleep(unsigned gpio, int value)
179{
180
181 WARN_ON(1);
182}
183
184static inline int gpio_export(unsigned gpio, bool direction_may_change)
185{
186
187 WARN_ON(1);
188 return -EINVAL;
189}
190
191static inline int gpio_export_link(struct device *dev, const char *name,
192 unsigned gpio)
193{
194
195 WARN_ON(1);
196 return -EINVAL;
197}
198
199static inline void gpio_unexport(unsigned gpio)
200{
201
202 WARN_ON(1);
203}
204
205static inline int gpio_to_irq(unsigned gpio)
206{
207
208 WARN_ON(1);
209 return -EINVAL;
210}
211
212static inline int gpiochip_lock_as_irq(struct gpio_chip *chip,
213 unsigned int offset)
214{
215 WARN_ON(1);
216 return -EINVAL;
217}
218
219static inline void gpiochip_unlock_as_irq(struct gpio_chip *chip,
220 unsigned int offset)
221{
222 WARN_ON(1);
223}
224
225static inline int irq_to_gpio(unsigned irq)
226{
227
228 WARN_ON(1);
229 return -EINVAL;
230}
231
232static inline int
233gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name,
234 unsigned int gpio_offset, unsigned int pin_offset,
235 unsigned int npins)
236{
237 WARN_ON(1);
238 return -EINVAL;
239}
240
241static inline int
242gpiochip_add_pingroup_range(struct gpio_chip *chip,
243 struct pinctrl_dev *pctldev,
244 unsigned int gpio_offset, const char *pin_group)
245{
246 WARN_ON(1);
247 return -EINVAL;
248}
249
250static inline void
251gpiochip_remove_pin_ranges(struct gpio_chip *chip)
252{
253 WARN_ON(1);
254}
255
256static inline int devm_gpio_request(struct device *dev, unsigned gpio,
257 const char *label)
258{
259 WARN_ON(1);
260 return -EINVAL;
261}
262
263static inline int devm_gpio_request_one(struct device *dev, unsigned gpio,
264 unsigned long flags, const char *label)
265{
266 WARN_ON(1);
267 return -EINVAL;
268}
269
270static inline void devm_gpio_free(struct device *dev, unsigned int gpio)
271{
272 WARN_ON(1);
273}
274
275#endif
276
277#endif
278