17560fa60SDavid Brownell #ifndef __LINUX_GPIO_H 27560fa60SDavid Brownell #define __LINUX_GPIO_H 37560fa60SDavid Brownell 47560fa60SDavid Brownell /* see Documentation/gpio.txt */ 57560fa60SDavid Brownell 6c001fb72SRandy Dunlap /* make these flag values available regardless of GPIO kconfig options */ 7c001fb72SRandy Dunlap #define GPIOF_DIR_OUT (0 << 0) 8c001fb72SRandy Dunlap #define GPIOF_DIR_IN (1 << 0) 9c001fb72SRandy Dunlap 10c001fb72SRandy Dunlap #define GPIOF_INIT_LOW (0 << 1) 11c001fb72SRandy Dunlap #define GPIOF_INIT_HIGH (1 << 1) 12c001fb72SRandy Dunlap 13c001fb72SRandy Dunlap #define GPIOF_IN (GPIOF_DIR_IN) 14c001fb72SRandy Dunlap #define GPIOF_OUT_INIT_LOW (GPIOF_DIR_OUT | GPIOF_INIT_LOW) 15c001fb72SRandy Dunlap #define GPIOF_OUT_INIT_HIGH (GPIOF_DIR_OUT | GPIOF_INIT_HIGH) 16c001fb72SRandy Dunlap 17aca5ce14SLaxman Dewangan /* Gpio pin is open drain */ 18aca5ce14SLaxman Dewangan #define GPIOF_OPEN_DRAIN (1 << 2) 19aca5ce14SLaxman Dewangan 2025553ff0SLaxman Dewangan /* Gpio pin is open source */ 2125553ff0SLaxman Dewangan #define GPIOF_OPEN_SOURCE (1 << 3) 2225553ff0SLaxman Dewangan 23feb83699SMark Brown /** 24feb83699SMark Brown * struct gpio - a structure describing a GPIO with configuration 25feb83699SMark Brown * @gpio: the GPIO number 26feb83699SMark Brown * @flags: GPIO configuration as specified by GPIOF_* 27feb83699SMark Brown * @label: a literal description string of this GPIO 28feb83699SMark Brown */ 29feb83699SMark Brown struct gpio { 30feb83699SMark Brown unsigned gpio; 31feb83699SMark Brown unsigned long flags; 32feb83699SMark Brown const char *label; 33feb83699SMark Brown }; 34feb83699SMark Brown 357560fa60SDavid Brownell #ifdef CONFIG_GENERIC_GPIO 367560fa60SDavid Brownell #include <asm/gpio.h> 377560fa60SDavid Brownell 387560fa60SDavid Brownell #else 397560fa60SDavid Brownell 403d599d1cSUwe Kleine-König #include <linux/kernel.h> 416ea0205bSDavid Brownell #include <linux/types.h> 426ea0205bSDavid Brownell #include <linux/errno.h> 436ea0205bSDavid Brownell 44a4177ee7SJani Nikula struct device; 454e4438b8SAnton Vorontsov struct gpio_chip; 46a4177ee7SJani Nikula 473474cb3cSJoe Perches static inline bool gpio_is_valid(int number) 487560fa60SDavid Brownell { 493474cb3cSJoe Perches return false; 507560fa60SDavid Brownell } 517560fa60SDavid Brownell 52d8a3515eSLinus Torvalds static inline int gpio_request(unsigned gpio, const char *label) 537560fa60SDavid Brownell { 547560fa60SDavid Brownell return -ENOSYS; 557560fa60SDavid Brownell } 567560fa60SDavid Brownell 57323b7fe8SWolfram Sang static inline int gpio_request_one(unsigned gpio, 585f829e40SWolfram Sang unsigned long flags, const char *label) 595f829e40SWolfram Sang { 605f829e40SWolfram Sang return -ENOSYS; 615f829e40SWolfram Sang } 625f829e40SWolfram Sang 637c295975SLars-Peter Clausen static inline int gpio_request_array(const struct gpio *array, size_t num) 645f829e40SWolfram Sang { 655f829e40SWolfram Sang return -ENOSYS; 665f829e40SWolfram Sang } 675f829e40SWolfram Sang 687560fa60SDavid Brownell static inline void gpio_free(unsigned gpio) 697560fa60SDavid Brownell { 703d599d1cSUwe Kleine-König might_sleep(); 713d599d1cSUwe Kleine-König 727560fa60SDavid Brownell /* GPIO can never have been requested */ 737560fa60SDavid Brownell WARN_ON(1); 747560fa60SDavid Brownell } 757560fa60SDavid Brownell 767c295975SLars-Peter Clausen static inline void gpio_free_array(const struct gpio *array, size_t num) 775f829e40SWolfram Sang { 785f829e40SWolfram Sang might_sleep(); 795f829e40SWolfram Sang 805f829e40SWolfram Sang /* GPIO can never have been requested */ 815f829e40SWolfram Sang WARN_ON(1); 825f829e40SWolfram Sang } 835f829e40SWolfram Sang 84d8a3515eSLinus Torvalds static inline int gpio_direction_input(unsigned gpio) 857560fa60SDavid Brownell { 867560fa60SDavid Brownell return -ENOSYS; 877560fa60SDavid Brownell } 887560fa60SDavid Brownell 89d8a3515eSLinus Torvalds static inline int gpio_direction_output(unsigned gpio, int value) 907560fa60SDavid Brownell { 917560fa60SDavid Brownell return -ENOSYS; 927560fa60SDavid Brownell } 937560fa60SDavid Brownell 94c4b5be98SFelipe Balbi static inline int gpio_set_debounce(unsigned gpio, unsigned debounce) 95c4b5be98SFelipe Balbi { 96c4b5be98SFelipe Balbi return -ENOSYS; 97c4b5be98SFelipe Balbi } 98c4b5be98SFelipe Balbi 997560fa60SDavid Brownell static inline int gpio_get_value(unsigned gpio) 1007560fa60SDavid Brownell { 1017560fa60SDavid Brownell /* GPIO can never have been requested or set as {in,out}put */ 1027560fa60SDavid Brownell WARN_ON(1); 1037560fa60SDavid Brownell return 0; 1047560fa60SDavid Brownell } 1057560fa60SDavid Brownell 1067560fa60SDavid Brownell static inline void gpio_set_value(unsigned gpio, int value) 1077560fa60SDavid Brownell { 1087560fa60SDavid Brownell /* GPIO can never have been requested or set as output */ 1097560fa60SDavid Brownell WARN_ON(1); 1107560fa60SDavid Brownell } 1117560fa60SDavid Brownell 1127560fa60SDavid Brownell static inline int gpio_cansleep(unsigned gpio) 1137560fa60SDavid Brownell { 1147560fa60SDavid Brownell /* GPIO can never have been requested or set as {in,out}put */ 1157560fa60SDavid Brownell WARN_ON(1); 1167560fa60SDavid Brownell return 0; 1177560fa60SDavid Brownell } 1187560fa60SDavid Brownell 1197560fa60SDavid Brownell static inline int gpio_get_value_cansleep(unsigned gpio) 1207560fa60SDavid Brownell { 1217560fa60SDavid Brownell /* GPIO can never have been requested or set as {in,out}put */ 1227560fa60SDavid Brownell WARN_ON(1); 1237560fa60SDavid Brownell return 0; 1247560fa60SDavid Brownell } 1257560fa60SDavid Brownell 1267560fa60SDavid Brownell static inline void gpio_set_value_cansleep(unsigned gpio, int value) 1277560fa60SDavid Brownell { 1287560fa60SDavid Brownell /* GPIO can never have been requested or set as output */ 1297560fa60SDavid Brownell WARN_ON(1); 1307560fa60SDavid Brownell } 1317560fa60SDavid Brownell 132d8f388d8SDavid Brownell static inline int gpio_export(unsigned gpio, bool direction_may_change) 133d8f388d8SDavid Brownell { 134d8f388d8SDavid Brownell /* GPIO can never have been requested or set as {in,out}put */ 135d8f388d8SDavid Brownell WARN_ON(1); 136d8f388d8SDavid Brownell return -EINVAL; 137d8f388d8SDavid Brownell } 138d8f388d8SDavid Brownell 139a4177ee7SJani Nikula static inline int gpio_export_link(struct device *dev, const char *name, 140a4177ee7SJani Nikula unsigned gpio) 141a4177ee7SJani Nikula { 142a4177ee7SJani Nikula /* GPIO can never have been exported */ 143a4177ee7SJani Nikula WARN_ON(1); 144a4177ee7SJani Nikula return -EINVAL; 145a4177ee7SJani Nikula } 146a4177ee7SJani Nikula 14707697461SJani Nikula static inline int gpio_sysfs_set_active_low(unsigned gpio, int value) 14807697461SJani Nikula { 14907697461SJani Nikula /* GPIO can never have been requested */ 15007697461SJani Nikula WARN_ON(1); 15107697461SJani Nikula return -EINVAL; 15207697461SJani Nikula } 153a4177ee7SJani Nikula 154d8f388d8SDavid Brownell static inline void gpio_unexport(unsigned gpio) 155d8f388d8SDavid Brownell { 156d8f388d8SDavid Brownell /* GPIO can never have been exported */ 157d8f388d8SDavid Brownell WARN_ON(1); 158d8f388d8SDavid Brownell } 159d8f388d8SDavid Brownell 1607560fa60SDavid Brownell static inline int gpio_to_irq(unsigned gpio) 1617560fa60SDavid Brownell { 1627560fa60SDavid Brownell /* GPIO can never have been requested or set as input */ 1637560fa60SDavid Brownell WARN_ON(1); 1647560fa60SDavid Brownell return -EINVAL; 1657560fa60SDavid Brownell } 1667560fa60SDavid Brownell 1677560fa60SDavid Brownell static inline int irq_to_gpio(unsigned irq) 1687560fa60SDavid Brownell { 1697560fa60SDavid Brownell /* irq can never have been returned from gpio_to_irq() */ 1707560fa60SDavid Brownell WARN_ON(1); 1717560fa60SDavid Brownell return -EINVAL; 1727560fa60SDavid Brownell } 1737560fa60SDavid Brownell 1747560fa60SDavid Brownell #endif 1757560fa60SDavid Brownell 1767560fa60SDavid Brownell #endif /* __LINUX_GPIO_H */ 177