1 /* SPDX-License-Identifier: GPL-2.0 */
5 #include <linux/errno.h>
7 /* see Documentation/gpio/gpio-legacy.txt */
9 /* make these flag values available regardless of GPIO kconfig options */
10 #define GPIOF_DIR_OUT (0 << 0)
11 #define GPIOF_DIR_IN (1 << 0)
13 #define GPIOF_INIT_LOW (0 << 1)
14 #define GPIOF_INIT_HIGH (1 << 1)
16 #define GPIOF_IN (GPIOF_DIR_IN)
17 #define GPIOF_OUT_INIT_LOW (GPIOF_DIR_OUT | GPIOF_INIT_LOW)
18 #define GPIOF_OUT_INIT_HIGH (GPIOF_DIR_OUT | GPIOF_INIT_HIGH)
20 /* Gpio pin is active-low */
21 #define GPIOF_ACTIVE_LOW (1 << 2)
23 /* Gpio pin is open drain */
24 #define GPIOF_OPEN_DRAIN (1 << 3)
26 /* Gpio pin is open source */
27 #define GPIOF_OPEN_SOURCE (1 << 4)
29 #define GPIOF_EXPORT (1 << 5)
30 #define GPIOF_EXPORT_CHANGEABLE (1 << 6)
31 #define GPIOF_EXPORT_DIR_FIXED (GPIOF_EXPORT)
32 #define GPIOF_EXPORT_DIR_CHANGEABLE (GPIOF_EXPORT | GPIOF_EXPORT_CHANGEABLE)
35 * struct gpio - a structure describing a GPIO with configuration
36 * @gpio: the GPIO number
37 * @flags: GPIO configuration as specified by GPIOF_*
38 * @label: a literal description string of this GPIO
48 #ifdef CONFIG_ARCH_HAVE_CUSTOM_GPIO_H
52 #include <asm-generic/gpio.h>
54 static inline int gpio_get_value(unsigned int gpio)
56 return __gpio_get_value(gpio);
59 static inline void gpio_set_value(unsigned int gpio, int value)
61 __gpio_set_value(gpio, value);
64 static inline int gpio_cansleep(unsigned int gpio)
66 return __gpio_cansleep(gpio);
69 static inline int gpio_to_irq(unsigned int gpio)
71 return __gpio_to_irq(gpio);
74 static inline int irq_to_gpio(unsigned int irq)
79 #endif /* ! CONFIG_ARCH_HAVE_CUSTOM_GPIO_H */
81 /* CONFIG_GPIOLIB: bindings for managed devices that want to request gpios */
85 int devm_gpio_request(struct device *dev, unsigned gpio, const char *label);
86 int devm_gpio_request_one(struct device *dev, unsigned gpio,
87 unsigned long flags, const char *label);
88 void devm_gpio_free(struct device *dev, unsigned int gpio);
90 #else /* ! CONFIG_GPIOLIB */
92 #include <linux/kernel.h>
93 #include <linux/types.h>
94 #include <linux/bug.h>
95 #include <linux/pinctrl/pinctrl.h>
100 static inline bool gpio_is_valid(int number)
105 static inline int gpio_request(unsigned gpio, const char *label)
110 static inline int gpio_request_one(unsigned gpio,
111 unsigned long flags, const char *label)
116 static inline int gpio_request_array(const struct gpio *array, size_t num)
121 static inline void gpio_free(unsigned gpio)
125 /* GPIO can never have been requested */
129 static inline void gpio_free_array(const struct gpio *array, size_t num)
133 /* GPIO can never have been requested */
137 static inline int gpio_direction_input(unsigned gpio)
142 static inline int gpio_direction_output(unsigned gpio, int value)
147 static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
152 static inline int gpio_get_value(unsigned gpio)
154 /* GPIO can never have been requested or set as {in,out}put */
159 static inline void gpio_set_value(unsigned gpio, int value)
161 /* GPIO can never have been requested or set as output */
165 static inline int gpio_cansleep(unsigned gpio)
167 /* GPIO can never have been requested or set as {in,out}put */
172 static inline int gpio_get_value_cansleep(unsigned gpio)
174 /* GPIO can never have been requested or set as {in,out}put */
179 static inline void gpio_set_value_cansleep(unsigned gpio, int value)
181 /* GPIO can never have been requested or set as output */
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 */
192 static inline int gpio_export_link(struct device *dev, const char *name,
195 /* GPIO can never have been exported */
200 static inline void gpio_unexport(unsigned gpio)
202 /* GPIO can never have been exported */
206 static inline int gpio_to_irq(unsigned gpio)
208 /* GPIO can never have been requested or set as input */
213 static inline int gpiochip_lock_as_irq(struct gpio_chip *chip,
220 static inline void gpiochip_unlock_as_irq(struct gpio_chip *chip,
226 static inline int irq_to_gpio(unsigned irq)
228 /* irq can never have been returned from gpio_to_irq() */
234 gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name,
235 unsigned int gpio_offset, unsigned int pin_offset,
243 gpiochip_add_pingroup_range(struct gpio_chip *chip,
244 struct pinctrl_dev *pctldev,
245 unsigned int gpio_offset, const char *pin_group)
252 gpiochip_remove_pin_ranges(struct gpio_chip *chip)
257 static inline int devm_gpio_request(struct device *dev, unsigned gpio,
264 static inline int devm_gpio_request_one(struct device *dev, unsigned gpio,
265 unsigned long flags, const char *label)
271 static inline void devm_gpio_free(struct device *dev, unsigned int gpio)
276 #endif /* ! CONFIG_GPIOLIB */
278 #endif /* __LINUX_GPIO_H */