4 #include <linux/errno.h>
6 /* see Documentation/gpio/gpio-legacy.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)
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
47 #ifdef CONFIG_ARCH_HAVE_CUSTOM_GPIO_H
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 #endif /* ! CONFIG_ARCH_HAVE_CUSTOM_GPIO_H */
75 /* CONFIG_GPIOLIB: bindings for managed devices that want to request gpios */
79 int devm_gpio_request(struct device *dev, unsigned gpio, const char *label);
80 int devm_gpio_request_one(struct device *dev, unsigned gpio,
81 unsigned long flags, const char *label);
82 void devm_gpio_free(struct device *dev, unsigned int gpio);
84 #else /* ! CONFIG_GPIOLIB */
86 #include <linux/kernel.h>
87 #include <linux/types.h>
88 #include <linux/bug.h>
89 #include <linux/pinctrl/pinctrl.h>
94 static inline bool gpio_is_valid(int number)
99 static inline int gpio_request(unsigned gpio, const char *label)
104 static inline int gpio_request_one(unsigned gpio,
105 unsigned long flags, const char *label)
110 static inline int gpio_request_array(const struct gpio *array, size_t num)
115 static inline void gpio_free(unsigned gpio)
119 /* GPIO can never have been requested */
123 static inline void gpio_free_array(const struct gpio *array, size_t num)
127 /* GPIO can never have been requested */
131 static inline int gpio_direction_input(unsigned gpio)
136 static inline int gpio_direction_output(unsigned gpio, int value)
141 static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
146 static inline int gpio_get_value(unsigned gpio)
148 /* GPIO can never have been requested or set as {in,out}put */
153 static inline void gpio_set_value(unsigned gpio, int value)
155 /* GPIO can never have been requested or set as output */
159 static inline int gpio_cansleep(unsigned gpio)
161 /* GPIO can never have been requested or set as {in,out}put */
166 static inline int gpio_get_value_cansleep(unsigned gpio)
168 /* GPIO can never have been requested or set as {in,out}put */
173 static inline void gpio_set_value_cansleep(unsigned gpio, int value)
175 /* GPIO can never have been requested or set as output */
179 static inline int gpio_export(unsigned gpio, bool direction_may_change)
181 /* GPIO can never have been requested or set as {in,out}put */
186 static inline int gpio_export_link(struct device *dev, const char *name,
189 /* GPIO can never have been exported */
194 static inline void gpio_unexport(unsigned gpio)
196 /* GPIO can never have been exported */
200 static inline int gpio_to_irq(unsigned gpio)
202 /* GPIO can never have been requested or set as input */
207 static inline int gpiochip_lock_as_irq(struct gpio_chip *chip,
214 static inline void gpiochip_unlock_as_irq(struct gpio_chip *chip,
221 gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name,
222 unsigned int gpio_offset, unsigned int pin_offset,
230 gpiochip_add_pingroup_range(struct gpio_chip *chip,
231 struct pinctrl_dev *pctldev,
232 unsigned int gpio_offset, const char *pin_group)
239 gpiochip_remove_pin_ranges(struct gpio_chip *chip)
244 static inline int devm_gpio_request(struct device *dev, unsigned gpio,
251 static inline int devm_gpio_request_one(struct device *dev, unsigned gpio,
252 unsigned long flags, const char *label)
258 static inline void devm_gpio_free(struct device *dev, unsigned int gpio)
263 #endif /* ! CONFIG_GPIOLIB */
265 #endif /* __LINUX_GPIO_H */