17560fa60SDavid Brownell #ifndef __LINUX_GPIO_H 27560fa60SDavid Brownell #define __LINUX_GPIO_H 37560fa60SDavid Brownell 47563bbf8SMark Brown #include <linux/errno.h> 57563bbf8SMark Brown 67560fa60SDavid Brownell /* see Documentation/gpio.txt */ 77560fa60SDavid Brownell 8c001fb72SRandy Dunlap /* make these flag values available regardless of GPIO kconfig options */ 9c001fb72SRandy Dunlap #define GPIOF_DIR_OUT (0 << 0) 10c001fb72SRandy Dunlap #define GPIOF_DIR_IN (1 << 0) 11c001fb72SRandy Dunlap 12c001fb72SRandy Dunlap #define GPIOF_INIT_LOW (0 << 1) 13c001fb72SRandy Dunlap #define GPIOF_INIT_HIGH (1 << 1) 14c001fb72SRandy Dunlap 15c001fb72SRandy Dunlap #define GPIOF_IN (GPIOF_DIR_IN) 16c001fb72SRandy Dunlap #define GPIOF_OUT_INIT_LOW (GPIOF_DIR_OUT | GPIOF_INIT_LOW) 17c001fb72SRandy Dunlap #define GPIOF_OUT_INIT_HIGH (GPIOF_DIR_OUT | GPIOF_INIT_HIGH) 18c001fb72SRandy Dunlap 19aca5ce14SLaxman Dewangan /* Gpio pin is open drain */ 20aca5ce14SLaxman Dewangan #define GPIOF_OPEN_DRAIN (1 << 2) 21aca5ce14SLaxman Dewangan 2225553ff0SLaxman Dewangan /* Gpio pin is open source */ 2325553ff0SLaxman Dewangan #define GPIOF_OPEN_SOURCE (1 << 3) 2425553ff0SLaxman Dewangan 25f567fde2SLaxman Dewangan #define GPIOF_EXPORT (1 << 4) 26f567fde2SLaxman Dewangan #define GPIOF_EXPORT_CHANGEABLE (1 << 5) 27fc3a1f04SWolfram Sang #define GPIOF_EXPORT_DIR_FIXED (GPIOF_EXPORT) 28fc3a1f04SWolfram Sang #define GPIOF_EXPORT_DIR_CHANGEABLE (GPIOF_EXPORT | GPIOF_EXPORT_CHANGEABLE) 29fc3a1f04SWolfram Sang 30feb83699SMark Brown /** 31feb83699SMark Brown * struct gpio - a structure describing a GPIO with configuration 32feb83699SMark Brown * @gpio: the GPIO number 33feb83699SMark Brown * @flags: GPIO configuration as specified by GPIOF_* 34feb83699SMark Brown * @label: a literal description string of this GPIO 35feb83699SMark Brown */ 36feb83699SMark Brown struct gpio { 37feb83699SMark Brown unsigned gpio; 38feb83699SMark Brown unsigned long flags; 39feb83699SMark Brown const char *label; 40feb83699SMark Brown }; 41feb83699SMark Brown 427560fa60SDavid Brownell #ifdef CONFIG_GENERIC_GPIO 437563bbf8SMark Brown 447563bbf8SMark Brown #ifdef CONFIG_ARCH_HAVE_CUSTOM_GPIO_H 457560fa60SDavid Brownell #include <asm/gpio.h> 467563bbf8SMark Brown #else 477563bbf8SMark Brown 487563bbf8SMark Brown #include <asm-generic/gpio.h> 497563bbf8SMark Brown 507563bbf8SMark Brown static inline int gpio_get_value(unsigned int gpio) 517563bbf8SMark Brown { 527563bbf8SMark Brown return __gpio_get_value(gpio); 537563bbf8SMark Brown } 547563bbf8SMark Brown 557563bbf8SMark Brown static inline void gpio_set_value(unsigned int gpio, int value) 567563bbf8SMark Brown { 577563bbf8SMark Brown __gpio_set_value(gpio, value); 587563bbf8SMark Brown } 597563bbf8SMark Brown 607563bbf8SMark Brown static inline int gpio_cansleep(unsigned int gpio) 617563bbf8SMark Brown { 627563bbf8SMark Brown return __gpio_cansleep(gpio); 637563bbf8SMark Brown } 647563bbf8SMark Brown 657563bbf8SMark Brown static inline int gpio_to_irq(unsigned int gpio) 667563bbf8SMark Brown { 677563bbf8SMark Brown return __gpio_to_irq(gpio); 687563bbf8SMark Brown } 697563bbf8SMark Brown 707563bbf8SMark Brown static inline int irq_to_gpio(unsigned int irq) 717563bbf8SMark Brown { 727563bbf8SMark Brown return -EINVAL; 737563bbf8SMark Brown } 747563bbf8SMark Brown 75165adc9cSLinus Walleij #endif /* ! CONFIG_ARCH_HAVE_CUSTOM_GPIO_H */ 767560fa60SDavid Brownell 77165adc9cSLinus Walleij #else /* ! CONFIG_GENERIC_GPIO */ 787560fa60SDavid Brownell 793d599d1cSUwe Kleine-König #include <linux/kernel.h> 806ea0205bSDavid Brownell #include <linux/types.h> 816ea0205bSDavid Brownell #include <linux/errno.h> 82187f1882SPaul Gortmaker #include <linux/bug.h> 836ea0205bSDavid Brownell 84a4177ee7SJani Nikula struct device; 854e4438b8SAnton Vorontsov struct gpio_chip; 86a4177ee7SJani Nikula 873474cb3cSJoe Perches static inline bool gpio_is_valid(int number) 887560fa60SDavid Brownell { 893474cb3cSJoe Perches return false; 907560fa60SDavid Brownell } 917560fa60SDavid Brownell 92d8a3515eSLinus Torvalds static inline int gpio_request(unsigned gpio, const char *label) 937560fa60SDavid Brownell { 947560fa60SDavid Brownell return -ENOSYS; 957560fa60SDavid Brownell } 967560fa60SDavid Brownell 972c96922aSMark Brown static inline int devm_gpio_request(struct device *dev, unsigned gpio, 982c96922aSMark Brown const char *label) 992c96922aSMark Brown { 1002c96922aSMark Brown return -ENOSYS; 1012c96922aSMark Brown } 1022c96922aSMark Brown 103323b7fe8SWolfram Sang static inline int gpio_request_one(unsigned gpio, 1045f829e40SWolfram Sang unsigned long flags, const char *label) 1055f829e40SWolfram Sang { 1065f829e40SWolfram Sang return -ENOSYS; 1075f829e40SWolfram Sang } 1085f829e40SWolfram Sang 10909d71ff1SMark Brown static inline int devm_gpio_request_one(struct device *dev, unsigned gpio, 11009d71ff1SMark Brown unsigned long flags, const char *label) 11109d71ff1SMark Brown { 11209d71ff1SMark Brown return -ENOSYS; 11309d71ff1SMark Brown } 11409d71ff1SMark Brown 1157c295975SLars-Peter Clausen static inline int gpio_request_array(const struct gpio *array, size_t num) 1165f829e40SWolfram Sang { 1175f829e40SWolfram Sang return -ENOSYS; 1185f829e40SWolfram Sang } 1195f829e40SWolfram Sang 1207560fa60SDavid Brownell static inline void gpio_free(unsigned gpio) 1217560fa60SDavid Brownell { 1223d599d1cSUwe Kleine-König might_sleep(); 1233d599d1cSUwe Kleine-König 1247560fa60SDavid Brownell /* GPIO can never have been requested */ 1257560fa60SDavid Brownell WARN_ON(1); 1267560fa60SDavid Brownell } 1277560fa60SDavid Brownell 1282c96922aSMark Brown static inline void devm_gpio_free(struct device *dev, unsigned gpio) 1292c96922aSMark Brown { 1302c96922aSMark Brown might_sleep(); 1312c96922aSMark Brown 1322c96922aSMark Brown /* GPIO can never have been requested */ 1332c96922aSMark Brown WARN_ON(1); 1342c96922aSMark Brown } 1352c96922aSMark Brown 1367c295975SLars-Peter Clausen static inline void gpio_free_array(const struct gpio *array, size_t num) 1375f829e40SWolfram Sang { 1385f829e40SWolfram Sang might_sleep(); 1395f829e40SWolfram Sang 1405f829e40SWolfram Sang /* GPIO can never have been requested */ 1415f829e40SWolfram Sang WARN_ON(1); 1425f829e40SWolfram Sang } 1435f829e40SWolfram Sang 144d8a3515eSLinus Torvalds static inline int gpio_direction_input(unsigned gpio) 1457560fa60SDavid Brownell { 1467560fa60SDavid Brownell return -ENOSYS; 1477560fa60SDavid Brownell } 1487560fa60SDavid Brownell 149d8a3515eSLinus Torvalds static inline int gpio_direction_output(unsigned gpio, int value) 1507560fa60SDavid Brownell { 1517560fa60SDavid Brownell return -ENOSYS; 1527560fa60SDavid Brownell } 1537560fa60SDavid Brownell 154c4b5be98SFelipe Balbi static inline int gpio_set_debounce(unsigned gpio, unsigned debounce) 155c4b5be98SFelipe Balbi { 156c4b5be98SFelipe Balbi return -ENOSYS; 157c4b5be98SFelipe Balbi } 158c4b5be98SFelipe Balbi 1597560fa60SDavid Brownell static inline int gpio_get_value(unsigned gpio) 1607560fa60SDavid Brownell { 1617560fa60SDavid Brownell /* GPIO can never have been requested or set as {in,out}put */ 1627560fa60SDavid Brownell WARN_ON(1); 1637560fa60SDavid Brownell return 0; 1647560fa60SDavid Brownell } 1657560fa60SDavid Brownell 1667560fa60SDavid Brownell static inline void gpio_set_value(unsigned gpio, int value) 1677560fa60SDavid Brownell { 1687560fa60SDavid Brownell /* GPIO can never have been requested or set as output */ 1697560fa60SDavid Brownell WARN_ON(1); 1707560fa60SDavid Brownell } 1717560fa60SDavid Brownell 1727560fa60SDavid Brownell static inline int gpio_cansleep(unsigned gpio) 1737560fa60SDavid Brownell { 1747560fa60SDavid Brownell /* GPIO can never have been requested or set as {in,out}put */ 1757560fa60SDavid Brownell WARN_ON(1); 1767560fa60SDavid Brownell return 0; 1777560fa60SDavid Brownell } 1787560fa60SDavid Brownell 1797560fa60SDavid Brownell static inline int gpio_get_value_cansleep(unsigned gpio) 1807560fa60SDavid Brownell { 1817560fa60SDavid Brownell /* GPIO can never have been requested or set as {in,out}put */ 1827560fa60SDavid Brownell WARN_ON(1); 1837560fa60SDavid Brownell return 0; 1847560fa60SDavid Brownell } 1857560fa60SDavid Brownell 1867560fa60SDavid Brownell static inline void gpio_set_value_cansleep(unsigned gpio, int value) 1877560fa60SDavid Brownell { 1887560fa60SDavid Brownell /* GPIO can never have been requested or set as output */ 1897560fa60SDavid Brownell WARN_ON(1); 1907560fa60SDavid Brownell } 1917560fa60SDavid Brownell 192d8f388d8SDavid Brownell static inline int gpio_export(unsigned gpio, bool direction_may_change) 193d8f388d8SDavid Brownell { 194d8f388d8SDavid Brownell /* GPIO can never have been requested or set as {in,out}put */ 195d8f388d8SDavid Brownell WARN_ON(1); 196d8f388d8SDavid Brownell return -EINVAL; 197d8f388d8SDavid Brownell } 198d8f388d8SDavid Brownell 199a4177ee7SJani Nikula static inline int gpio_export_link(struct device *dev, const char *name, 200a4177ee7SJani Nikula unsigned gpio) 201a4177ee7SJani Nikula { 202a4177ee7SJani Nikula /* GPIO can never have been exported */ 203a4177ee7SJani Nikula WARN_ON(1); 204a4177ee7SJani Nikula return -EINVAL; 205a4177ee7SJani Nikula } 206a4177ee7SJani Nikula 20707697461SJani Nikula static inline int gpio_sysfs_set_active_low(unsigned gpio, int value) 20807697461SJani Nikula { 20907697461SJani Nikula /* GPIO can never have been requested */ 21007697461SJani Nikula WARN_ON(1); 21107697461SJani Nikula return -EINVAL; 21207697461SJani Nikula } 213a4177ee7SJani Nikula 214d8f388d8SDavid Brownell static inline void gpio_unexport(unsigned gpio) 215d8f388d8SDavid Brownell { 216d8f388d8SDavid Brownell /* GPIO can never have been exported */ 217d8f388d8SDavid Brownell WARN_ON(1); 218d8f388d8SDavid Brownell } 219d8f388d8SDavid Brownell 2207560fa60SDavid Brownell static inline int gpio_to_irq(unsigned gpio) 2217560fa60SDavid Brownell { 2227560fa60SDavid Brownell /* GPIO can never have been requested or set as input */ 2237560fa60SDavid Brownell WARN_ON(1); 2247560fa60SDavid Brownell return -EINVAL; 2257560fa60SDavid Brownell } 2267560fa60SDavid Brownell 2277560fa60SDavid Brownell static inline int irq_to_gpio(unsigned irq) 2287560fa60SDavid Brownell { 2297560fa60SDavid Brownell /* irq can never have been returned from gpio_to_irq() */ 2307560fa60SDavid Brownell WARN_ON(1); 2317560fa60SDavid Brownell return -EINVAL; 2327560fa60SDavid Brownell } 2337560fa60SDavid Brownell 234165adc9cSLinus Walleij #ifdef CONFIG_PINCTRL 235165adc9cSLinus Walleij 236165adc9cSLinus Walleij static inline void 237165adc9cSLinus Walleij gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name, 238165adc9cSLinus Walleij unsigned int pin_base, unsigned int npins) 239165adc9cSLinus Walleij { 240165adc9cSLinus Walleij } 241165adc9cSLinus Walleij 242165adc9cSLinus Walleij static inline void 243165adc9cSLinus Walleij gpiochip_remove_pin_ranges(struct gpio_chip *chip) 244165adc9cSLinus Walleij { 245165adc9cSLinus Walleij } 246165adc9cSLinus Walleij 247165adc9cSLinus Walleij #endif /* CONFIG_PINCTRL */ 248165adc9cSLinus Walleij 249165adc9cSLinus Walleij #endif /* ! CONFIG_GENERIC_GPIO */ 2507560fa60SDavid Brownell 2517560fa60SDavid Brownell #endif /* __LINUX_GPIO_H */ 252