Merge commit 'spi/fix/rcar' into spi-linus
[linux-2.6/btrfs-unstable.git] / include / linux / gpio.h
blob13dfd24d01abc0d156e9cfa553f6b41aac96cb5f
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 active-low */
20 #define GPIOF_ACTIVE_LOW (1 << 2)
22 /* Gpio pin is open drain */
23 #define GPIOF_OPEN_DRAIN (1 << 3)
25 /* Gpio pin is open source */
26 #define GPIOF_OPEN_SOURCE (1 << 4)
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)
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
39 struct gpio {
40 unsigned gpio;
41 unsigned long flags;
42 const char *label;
45 #ifdef CONFIG_GPIOLIB
47 #ifdef CONFIG_ARCH_HAVE_CUSTOM_GPIO_H
48 #include <asm/gpio.h>
49 #else
51 #include <asm-generic/gpio.h>
53 static inline int gpio_get_value(unsigned int gpio)
55 return __gpio_get_value(gpio);
58 static inline void gpio_set_value(unsigned int gpio, int value)
60 __gpio_set_value(gpio, value);
63 static inline int gpio_cansleep(unsigned int gpio)
65 return __gpio_cansleep(gpio);
68 static inline int gpio_to_irq(unsigned int gpio)
70 return __gpio_to_irq(gpio);
73 static inline int irq_to_gpio(unsigned int irq)
75 return -EINVAL;
78 #endif /* ! CONFIG_ARCH_HAVE_CUSTOM_GPIO_H */
80 /* CONFIG_GPIOLIB: bindings for managed devices that want to request gpios */
82 struct device;
84 int devm_gpio_request(struct device *dev, unsigned gpio, const char *label);
85 int devm_gpio_request_one(struct device *dev, unsigned gpio,
86 unsigned long flags, const char *label);
87 void devm_gpio_free(struct device *dev, unsigned int gpio);
89 #else /* ! CONFIG_GPIOLIB */
91 #include <linux/kernel.h>
92 #include <linux/types.h>
93 #include <linux/errno.h>
94 #include <linux/bug.h>
95 #include <linux/pinctrl/pinctrl.h>
97 struct device;
98 struct gpio_chip;
100 static inline bool gpio_is_valid(int number)
102 return false;
105 static inline int gpio_request(unsigned gpio, const char *label)
107 return -ENOSYS;
110 static inline int gpio_request_one(unsigned gpio,
111 unsigned long flags, const char *label)
113 return -ENOSYS;
116 static inline int gpio_request_array(const struct gpio *array, size_t num)
118 return -ENOSYS;
121 static inline void gpio_free(unsigned gpio)
123 might_sleep();
125 /* GPIO can never have been requested */
126 WARN_ON(1);
129 static inline void gpio_free_array(const struct gpio *array, size_t num)
131 might_sleep();
133 /* GPIO can never have been requested */
134 WARN_ON(1);
137 static inline int gpio_direction_input(unsigned gpio)
139 return -ENOSYS;
142 static inline int gpio_direction_output(unsigned gpio, int value)
144 return -ENOSYS;
147 static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
149 return -ENOSYS;
152 static inline int gpio_get_value(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 void gpio_set_value(unsigned gpio, int value)
161 /* GPIO can never have been requested or set as output */
162 WARN_ON(1);
165 static inline int gpio_cansleep(unsigned gpio)
167 /* GPIO can never have been requested or set as {in,out}put */
168 WARN_ON(1);
169 return 0;
172 static inline int gpio_get_value_cansleep(unsigned gpio)
174 /* GPIO can never have been requested or set as {in,out}put */
175 WARN_ON(1);
176 return 0;
179 static inline void gpio_set_value_cansleep(unsigned gpio, int value)
181 /* GPIO can never have been requested or set as output */
182 WARN_ON(1);
185 static inline int gpio_export(unsigned gpio, bool direction_may_change)
187 /* GPIO can never have been requested or set as {in,out}put */
188 WARN_ON(1);
189 return -EINVAL;
192 static inline int gpio_export_link(struct device *dev, const char *name,
193 unsigned gpio)
195 /* GPIO can never have been exported */
196 WARN_ON(1);
197 return -EINVAL;
200 static inline int gpio_sysfs_set_active_low(unsigned gpio, int value)
202 /* GPIO can never have been requested */
203 WARN_ON(1);
204 return -EINVAL;
207 static inline void gpio_unexport(unsigned gpio)
209 /* GPIO can never have been exported */
210 WARN_ON(1);
213 static inline int gpio_to_irq(unsigned gpio)
215 /* GPIO can never have been requested or set as input */
216 WARN_ON(1);
217 return -EINVAL;
220 static inline int gpio_lock_as_irq(struct gpio_chip *chip, unsigned int offset)
222 WARN_ON(1);
223 return -EINVAL;
226 static inline void gpio_unlock_as_irq(struct gpio_chip *chip,
227 unsigned int offset)
229 WARN_ON(1);
232 static inline int irq_to_gpio(unsigned irq)
234 /* irq can never have been returned from gpio_to_irq() */
235 WARN_ON(1);
236 return -EINVAL;
239 static inline int
240 gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name,
241 unsigned int gpio_offset, unsigned int pin_offset,
242 unsigned int npins)
244 WARN_ON(1);
245 return -EINVAL;
248 static inline int
249 gpiochip_add_pingroup_range(struct gpio_chip *chip,
250 struct pinctrl_dev *pctldev,
251 unsigned int gpio_offset, const char *pin_group)
253 WARN_ON(1);
254 return -EINVAL;
257 static inline void
258 gpiochip_remove_pin_ranges(struct gpio_chip *chip)
260 WARN_ON(1);
263 static inline int devm_gpio_request(struct device *dev, unsigned gpio,
264 const char *label)
266 WARN_ON(1);
267 return -EINVAL;
270 static inline int devm_gpio_request_one(struct device *dev, unsigned gpio,
271 unsigned long flags, const char *label)
273 WARN_ON(1);
274 return -EINVAL;
277 static inline void devm_gpio_free(struct device *dev, unsigned int gpio)
279 WARN_ON(1);
282 #endif /* ! CONFIG_GPIOLIB */
284 #endif /* __LINUX_GPIO_H */