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)
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
42 #ifdef CONFIG_GENERIC_GPIO
44 #ifdef CONFIG_ARCH_HAVE_CUSTOM_GPIO_H
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)
75 #endif /* ! CONFIG_ARCH_HAVE_CUSTOM_GPIO_H */
77 #else /* ! CONFIG_GENERIC_GPIO */
79 #include <linux/kernel.h>
80 #include <linux/types.h>
81 #include <linux/errno.h>
82 #include <linux/bug.h>
87 static inline bool gpio_is_valid(int number)
92 static inline int gpio_request(unsigned gpio, const char *label)
97 static inline int devm_gpio_request(struct device *dev, unsigned gpio,
103 static inline int gpio_request_one(unsigned gpio,
104 unsigned long flags, const char *label)
109 static inline int devm_gpio_request_one(struct device *dev, unsigned gpio,
110 unsigned long flags, const char *label)
115 static inline int gpio_request_array(const struct gpio *array, size_t num)
120 static inline void gpio_free(unsigned gpio)
124 /* GPIO can never have been requested */
128 static inline void devm_gpio_free(struct device *dev, unsigned gpio)
132 /* GPIO can never have been requested */
136 static inline void gpio_free_array(const struct gpio *array, size_t num)
140 /* GPIO can never have been requested */
144 static inline int gpio_direction_input(unsigned gpio)
149 static inline int gpio_direction_output(unsigned gpio, int value)
154 static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
159 static inline int gpio_get_value(unsigned gpio)
161 /* GPIO can never have been requested or set as {in,out}put */
166 static inline void gpio_set_value(unsigned gpio, int value)
168 /* GPIO can never have been requested or set as output */
172 static inline int gpio_cansleep(unsigned gpio)
174 /* GPIO can never have been requested or set as {in,out}put */
179 static inline int gpio_get_value_cansleep(unsigned gpio)
181 /* GPIO can never have been requested or set as {in,out}put */
186 static inline void gpio_set_value_cansleep(unsigned gpio, int value)
188 /* GPIO can never have been requested or set as output */
192 static inline int gpio_export(unsigned gpio, bool direction_may_change)
194 /* GPIO can never have been requested or set as {in,out}put */
199 static inline int gpio_export_link(struct device *dev, const char *name,
202 /* GPIO can never have been exported */
207 static inline int gpio_sysfs_set_active_low(unsigned gpio, int value)
209 /* GPIO can never have been requested */
214 static inline void gpio_unexport(unsigned gpio)
216 /* GPIO can never have been exported */
220 static inline int gpio_to_irq(unsigned gpio)
222 /* GPIO can never have been requested or set as input */
227 static inline int irq_to_gpio(unsigned irq)
229 /* irq can never have been returned from gpio_to_irq() */
234 #ifdef CONFIG_PINCTRL
237 gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name,
238 unsigned int pin_base, unsigned int npins)
243 gpiochip_remove_pin_ranges(struct gpio_chip *chip)
247 #endif /* CONFIG_PINCTRL */
249 #endif /* ! CONFIG_GENERIC_GPIO */
251 #endif /* __LINUX_GPIO_H */