Merge git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
[linux-2.6.git] / include / linux / gpio.h
blob552e3f46e4a33f5b4915c86182c13cf0c876233a
1 #ifndef __LINUX_GPIO_H
2 #define __LINUX_GPIO_H
4 #include <linux/errno.h>
6 /* see Documentation/gpio.txt */
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)
12 #define GPIOF_INIT_LOW (0 << 1)
13 #define GPIOF_INIT_HIGH (1 << 1)
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)
19 /* Gpio pin is open drain */
20 #define GPIOF_OPEN_DRAIN (1 << 2)
22 /* Gpio pin is open source */
23 #define GPIOF_OPEN_SOURCE (1 << 3)
25 #define GPIOF_EXPORT (1 << 4)
26 #define GPIOF_EXPORT_CHANGEABLE (1 << 5)
27 #define GPIOF_EXPORT_DIR_FIXED (GPIOF_EXPORT)
28 #define GPIOF_EXPORT_DIR_CHANGEABLE (GPIOF_EXPORT | GPIOF_EXPORT_CHANGEABLE)
30 /**
31 * struct gpio - a structure describing a GPIO with configuration
32 * @gpio: the GPIO number
33 * @flags: GPIO configuration as specified by GPIOF_*
34 * @label: a literal description string of this GPIO
36 struct gpio {
37 unsigned gpio;
38 unsigned long flags;
39 const char *label;
42 #ifdef CONFIG_GPIOLIB
44 #ifdef CONFIG_ARCH_HAVE_CUSTOM_GPIO_H
45 #include <asm/gpio.h>
46 #else
48 #include <asm-generic/gpio.h>
50 static inline int gpio_get_value(unsigned int gpio)
52 return __gpio_get_value(gpio);
55 static inline void gpio_set_value(unsigned int gpio, int value)
57 __gpio_set_value(gpio, value);
60 static inline int gpio_cansleep(unsigned int gpio)
62 return __gpio_cansleep(gpio);
65 static inline int gpio_to_irq(unsigned int gpio)
67 return __gpio_to_irq(gpio);
70 static inline int irq_to_gpio(unsigned int irq)
72 return -EINVAL;
75 #endif /* ! CONFIG_ARCH_HAVE_CUSTOM_GPIO_H */
77 #else /* ! CONFIG_GPIOLIB */
79 #include <linux/kernel.h>
80 #include <linux/types.h>
81 #include <linux/errno.h>
82 #include <linux/bug.h>
84 struct device;
85 struct gpio_chip;
87 static inline bool gpio_is_valid(int number)
89 return false;
92 static inline int gpio_request(unsigned gpio, const char *label)
94 return -ENOSYS;
97 static inline int gpio_request_one(unsigned gpio,
98 unsigned long flags, const char *label)
100 return -ENOSYS;
103 static inline int gpio_request_array(const struct gpio *array, size_t num)
105 return -ENOSYS;
108 static inline void gpio_free(unsigned gpio)
110 might_sleep();
112 /* GPIO can never have been requested */
113 WARN_ON(1);
116 static inline void gpio_free_array(const struct gpio *array, size_t num)
118 might_sleep();
120 /* GPIO can never have been requested */
121 WARN_ON(1);
124 static inline int gpio_direction_input(unsigned gpio)
126 return -ENOSYS;
129 static inline int gpio_direction_output(unsigned gpio, int value)
131 return -ENOSYS;
134 static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
136 return -ENOSYS;
139 static inline int gpio_get_value(unsigned gpio)
141 /* GPIO can never have been requested or set as {in,out}put */
142 WARN_ON(1);
143 return 0;
146 static inline void gpio_set_value(unsigned gpio, int value)
148 /* GPIO can never have been requested or set as output */
149 WARN_ON(1);
152 static inline int gpio_cansleep(unsigned gpio)
154 /* GPIO can never have been requested or set as {in,out}put */
155 WARN_ON(1);
156 return 0;
159 static inline int gpio_get_value_cansleep(unsigned gpio)
161 /* GPIO can never have been requested or set as {in,out}put */
162 WARN_ON(1);
163 return 0;
166 static inline void gpio_set_value_cansleep(unsigned gpio, int value)
168 /* GPIO can never have been requested or set as output */
169 WARN_ON(1);
172 static inline int gpio_export(unsigned gpio, bool direction_may_change)
174 /* GPIO can never have been requested or set as {in,out}put */
175 WARN_ON(1);
176 return -EINVAL;
179 static inline int gpio_export_link(struct device *dev, const char *name,
180 unsigned gpio)
182 /* GPIO can never have been exported */
183 WARN_ON(1);
184 return -EINVAL;
187 static inline int gpio_sysfs_set_active_low(unsigned gpio, int value)
189 /* GPIO can never have been requested */
190 WARN_ON(1);
191 return -EINVAL;
194 static inline void gpio_unexport(unsigned gpio)
196 /* GPIO can never have been exported */
197 WARN_ON(1);
200 static inline int gpio_to_irq(unsigned gpio)
202 /* GPIO can never have been requested or set as input */
203 WARN_ON(1);
204 return -EINVAL;
207 static inline int irq_to_gpio(unsigned irq)
209 /* irq can never have been returned from gpio_to_irq() */
210 WARN_ON(1);
211 return -EINVAL;
214 static inline int
215 gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name,
216 unsigned int gpio_offset, unsigned int pin_offset,
217 unsigned int npins)
219 WARN_ON(1);
220 return -EINVAL;
223 static inline void
224 gpiochip_remove_pin_ranges(struct gpio_chip *chip)
226 WARN_ON(1);
229 #endif /* ! CONFIG_GPIOLIB */
231 struct device;
233 /* bindings for managed devices that want to request gpios */
234 int devm_gpio_request(struct device *dev, unsigned gpio, const char *label);
235 int devm_gpio_request_one(struct device *dev, unsigned gpio,
236 unsigned long flags, const char *label);
237 void devm_gpio_free(struct device *dev, unsigned int gpio);
239 #endif /* __LINUX_GPIO_H */