]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - include/linux/gpio.h
Merge remote-tracking branch 'gpio/for-next'
[karo-tx-linux.git] / include / linux / gpio.h
1 #ifndef __LINUX_GPIO_H
2 #define __LINUX_GPIO_H
3
4 #include <linux/errno.h>
5
6 /* see Documentation/gpio.txt */
7
8 /* make these flag values available regardless of GPIO kconfig options */
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 /* Gpio pin is active-low */
20 #define GPIOF_ACTIVE_LOW        (1 << 2)
21
22 /* Gpio pin is open drain */
23 #define GPIOF_OPEN_DRAIN        (1 << 3)
24
25 /* Gpio pin is open source */
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  * struct gpio - a structure describing a GPIO with configuration
35  * @gpio:       the GPIO number
36  * @flags:      GPIO configuration as specified by GPIOF_*
37  * @label:      a literal description string of this GPIO
38  */
39 struct 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
53 static inline int gpio_get_value(unsigned int gpio)
54 {
55         return __gpio_get_value(gpio);
56 }
57
58 static inline void gpio_set_value(unsigned int gpio, int value)
59 {
60         __gpio_set_value(gpio, value);
61 }
62
63 static inline int gpio_cansleep(unsigned int gpio)
64 {
65         return __gpio_cansleep(gpio);
66 }
67
68 static inline int gpio_to_irq(unsigned int gpio)
69 {
70         return __gpio_to_irq(gpio);
71 }
72
73 static inline int irq_to_gpio(unsigned int irq)
74 {
75         return -EINVAL;
76 }
77
78 #endif /* ! CONFIG_ARCH_HAVE_CUSTOM_GPIO_H */
79
80 #else /* ! CONFIG_GPIOLIB */
81
82 #include <linux/kernel.h>
83 #include <linux/types.h>
84 #include <linux/errno.h>
85 #include <linux/bug.h>
86 #include <linux/pinctrl/pinctrl.h>
87
88 struct device;
89 struct gpio_chip;
90
91 static inline bool gpio_is_valid(int number)
92 {
93         return false;
94 }
95
96 static inline int gpio_request(unsigned gpio, const char *label)
97 {
98         return -ENOSYS;
99 }
100
101 static inline int gpio_request_one(unsigned gpio,
102                                         unsigned long flags, const char *label)
103 {
104         return -ENOSYS;
105 }
106
107 static inline int gpio_request_array(const struct gpio *array, size_t num)
108 {
109         return -ENOSYS;
110 }
111
112 static inline void gpio_free(unsigned gpio)
113 {
114         might_sleep();
115
116         /* GPIO can never have been requested */
117         WARN_ON(1);
118 }
119
120 static inline void gpio_free_array(const struct gpio *array, size_t num)
121 {
122         might_sleep();
123
124         /* GPIO can never have been requested */
125         WARN_ON(1);
126 }
127
128 static inline int gpio_direction_input(unsigned gpio)
129 {
130         return -ENOSYS;
131 }
132
133 static inline int gpio_direction_output(unsigned gpio, int value)
134 {
135         return -ENOSYS;
136 }
137
138 static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
139 {
140         return -ENOSYS;
141 }
142
143 static inline int gpio_get_value(unsigned gpio)
144 {
145         /* GPIO can never have been requested or set as {in,out}put */
146         WARN_ON(1);
147         return 0;
148 }
149
150 static inline void gpio_set_value(unsigned gpio, int value)
151 {
152         /* GPIO can never have been requested or set as output */
153         WARN_ON(1);
154 }
155
156 static inline int gpio_cansleep(unsigned gpio)
157 {
158         /* GPIO can never have been requested or set as {in,out}put */
159         WARN_ON(1);
160         return 0;
161 }
162
163 static inline int gpio_get_value_cansleep(unsigned gpio)
164 {
165         /* GPIO can never have been requested or set as {in,out}put */
166         WARN_ON(1);
167         return 0;
168 }
169
170 static inline void gpio_set_value_cansleep(unsigned gpio, int value)
171 {
172         /* GPIO can never have been requested or set as output */
173         WARN_ON(1);
174 }
175
176 static inline int gpio_export(unsigned gpio, bool direction_may_change)
177 {
178         /* GPIO can never have been requested or set as {in,out}put */
179         WARN_ON(1);
180         return -EINVAL;
181 }
182
183 static inline int gpio_export_link(struct device *dev, const char *name,
184                                 unsigned gpio)
185 {
186         /* GPIO can never have been exported */
187         WARN_ON(1);
188         return -EINVAL;
189 }
190
191 static inline int gpio_sysfs_set_active_low(unsigned gpio, int value)
192 {
193         /* GPIO can never have been requested */
194         WARN_ON(1);
195         return -EINVAL;
196 }
197
198 static inline void gpio_unexport(unsigned gpio)
199 {
200         /* GPIO can never have been exported */
201         WARN_ON(1);
202 }
203
204 static inline int gpio_to_irq(unsigned gpio)
205 {
206         /* GPIO can never have been requested or set as input */
207         WARN_ON(1);
208         return -EINVAL;
209 }
210
211 static inline int gpio_lock_as_irq(struct gpio_chip *chip, unsigned int offset)
212 {
213         WARN_ON(1);
214         return -EINVAL;
215 }
216
217 static inline void gpio_unlock_as_irq(struct gpio_chip *chip,
218                                       unsigned int offset)
219 {
220         WARN_ON(1);
221 }
222
223 static inline int irq_to_gpio(unsigned irq)
224 {
225         /* irq can never have been returned from gpio_to_irq() */
226         WARN_ON(1);
227         return -EINVAL;
228 }
229
230 static inline int
231 gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name,
232                        unsigned int gpio_offset, unsigned int pin_offset,
233                        unsigned int npins)
234 {
235         WARN_ON(1);
236         return -EINVAL;
237 }
238
239 static inline int
240 gpiochip_add_pingroup_range(struct gpio_chip *chip,
241                         struct pinctrl_dev *pctldev,
242                         unsigned int gpio_offset, const char *pin_group)
243 {
244         WARN_ON(1);
245         return -EINVAL;
246 }
247
248 static inline void
249 gpiochip_remove_pin_ranges(struct gpio_chip *chip)
250 {
251         WARN_ON(1);
252 }
253
254 #endif /* ! CONFIG_GPIOLIB */
255
256 struct device;
257
258 /* bindings for managed devices that want to request gpios */
259 int devm_gpio_request(struct device *dev, unsigned gpio, const char *label);
260 int devm_gpio_request_one(struct device *dev, unsigned gpio,
261                           unsigned long flags, const char *label);
262 void devm_gpio_free(struct device *dev, unsigned int gpio);
263
264 #endif /* __LINUX_GPIO_H */