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 17feb83699SMark Brown /** 18feb83699SMark Brown * struct gpio - a structure describing a GPIO with configuration 19feb83699SMark Brown * @gpio: the GPIO number 20feb83699SMark Brown * @flags: GPIO configuration as specified by GPIOF_* 21feb83699SMark Brown * @label: a literal description string of this GPIO 22feb83699SMark Brown */ 23feb83699SMark Brown struct gpio { 24feb83699SMark Brown unsigned gpio; 25feb83699SMark Brown unsigned long flags; 26feb83699SMark Brown const char *label; 27feb83699SMark Brown }; 28feb83699SMark Brown 297560fa60SDavid Brownell #ifdef CONFIG_GENERIC_GPIO 307560fa60SDavid Brownell #include <asm/gpio.h> 317560fa60SDavid Brownell 327560fa60SDavid Brownell #else 337560fa60SDavid Brownell 343d599d1cSUwe Kleine-König #include <linux/kernel.h> 356ea0205bSDavid Brownell #include <linux/types.h> 366ea0205bSDavid Brownell #include <linux/errno.h> 376ea0205bSDavid Brownell 38a4177ee7SJani Nikula struct device; 394e4438b8SAnton Vorontsov struct gpio_chip; 40a4177ee7SJani Nikula 413474cb3cSJoe Perches static inline bool gpio_is_valid(int number) 427560fa60SDavid Brownell { 433474cb3cSJoe Perches return false; 447560fa60SDavid Brownell } 457560fa60SDavid Brownell 46d8a3515eSLinus Torvalds static inline int gpio_request(unsigned gpio, const char *label) 477560fa60SDavid Brownell { 487560fa60SDavid Brownell return -ENOSYS; 497560fa60SDavid Brownell } 507560fa60SDavid Brownell 51323b7fe8SWolfram Sang static inline int gpio_request_one(unsigned gpio, 525f829e40SWolfram Sang unsigned long flags, const char *label) 535f829e40SWolfram Sang { 545f829e40SWolfram Sang return -ENOSYS; 555f829e40SWolfram Sang } 565f829e40SWolfram Sang 577c295975SLars-Peter Clausen static inline int gpio_request_array(const struct gpio *array, size_t num) 585f829e40SWolfram Sang { 595f829e40SWolfram Sang return -ENOSYS; 605f829e40SWolfram Sang } 615f829e40SWolfram Sang 627560fa60SDavid Brownell static inline void gpio_free(unsigned gpio) 637560fa60SDavid Brownell { 643d599d1cSUwe Kleine-König might_sleep(); 653d599d1cSUwe Kleine-König 667560fa60SDavid Brownell /* GPIO can never have been requested */ 677560fa60SDavid Brownell WARN_ON(1); 687560fa60SDavid Brownell } 697560fa60SDavid Brownell 707c295975SLars-Peter Clausen static inline void gpio_free_array(const struct gpio *array, size_t num) 715f829e40SWolfram Sang { 725f829e40SWolfram Sang might_sleep(); 735f829e40SWolfram Sang 745f829e40SWolfram Sang /* GPIO can never have been requested */ 755f829e40SWolfram Sang WARN_ON(1); 765f829e40SWolfram Sang } 775f829e40SWolfram Sang 78d8a3515eSLinus Torvalds static inline int gpio_direction_input(unsigned gpio) 797560fa60SDavid Brownell { 807560fa60SDavid Brownell return -ENOSYS; 817560fa60SDavid Brownell } 827560fa60SDavid Brownell 83d8a3515eSLinus Torvalds static inline int gpio_direction_output(unsigned gpio, int value) 847560fa60SDavid Brownell { 857560fa60SDavid Brownell return -ENOSYS; 867560fa60SDavid Brownell } 877560fa60SDavid Brownell 88c4b5be98SFelipe Balbi static inline int gpio_set_debounce(unsigned gpio, unsigned debounce) 89c4b5be98SFelipe Balbi { 90c4b5be98SFelipe Balbi return -ENOSYS; 91c4b5be98SFelipe Balbi } 92c4b5be98SFelipe Balbi 937560fa60SDavid Brownell static inline int gpio_get_value(unsigned gpio) 947560fa60SDavid Brownell { 957560fa60SDavid Brownell /* GPIO can never have been requested or set as {in,out}put */ 967560fa60SDavid Brownell WARN_ON(1); 977560fa60SDavid Brownell return 0; 987560fa60SDavid Brownell } 997560fa60SDavid Brownell 1007560fa60SDavid Brownell static inline void gpio_set_value(unsigned gpio, int value) 1017560fa60SDavid Brownell { 1027560fa60SDavid Brownell /* GPIO can never have been requested or set as output */ 1037560fa60SDavid Brownell WARN_ON(1); 1047560fa60SDavid Brownell } 1057560fa60SDavid Brownell 1067560fa60SDavid Brownell static inline int gpio_cansleep(unsigned gpio) 1077560fa60SDavid Brownell { 1087560fa60SDavid Brownell /* GPIO can never have been requested or set as {in,out}put */ 1097560fa60SDavid Brownell WARN_ON(1); 1107560fa60SDavid Brownell return 0; 1117560fa60SDavid Brownell } 1127560fa60SDavid Brownell 1137560fa60SDavid Brownell static inline int gpio_get_value_cansleep(unsigned gpio) 1147560fa60SDavid Brownell { 1157560fa60SDavid Brownell /* GPIO can never have been requested or set as {in,out}put */ 1167560fa60SDavid Brownell WARN_ON(1); 1177560fa60SDavid Brownell return 0; 1187560fa60SDavid Brownell } 1197560fa60SDavid Brownell 1207560fa60SDavid Brownell static inline void gpio_set_value_cansleep(unsigned gpio, int value) 1217560fa60SDavid Brownell { 1227560fa60SDavid Brownell /* GPIO can never have been requested or set as output */ 1237560fa60SDavid Brownell WARN_ON(1); 1247560fa60SDavid Brownell } 1257560fa60SDavid Brownell 126d8f388d8SDavid Brownell static inline int gpio_export(unsigned gpio, bool direction_may_change) 127d8f388d8SDavid Brownell { 128d8f388d8SDavid Brownell /* GPIO can never have been requested or set as {in,out}put */ 129d8f388d8SDavid Brownell WARN_ON(1); 130d8f388d8SDavid Brownell return -EINVAL; 131d8f388d8SDavid Brownell } 132d8f388d8SDavid Brownell 133a4177ee7SJani Nikula static inline int gpio_export_link(struct device *dev, const char *name, 134a4177ee7SJani Nikula unsigned gpio) 135a4177ee7SJani Nikula { 136a4177ee7SJani Nikula /* GPIO can never have been exported */ 137a4177ee7SJani Nikula WARN_ON(1); 138a4177ee7SJani Nikula return -EINVAL; 139a4177ee7SJani Nikula } 140a4177ee7SJani Nikula 14107697461SJani Nikula static inline int gpio_sysfs_set_active_low(unsigned gpio, int value) 14207697461SJani Nikula { 14307697461SJani Nikula /* GPIO can never have been requested */ 14407697461SJani Nikula WARN_ON(1); 14507697461SJani Nikula return -EINVAL; 14607697461SJani Nikula } 147a4177ee7SJani Nikula 148d8f388d8SDavid Brownell static inline void gpio_unexport(unsigned gpio) 149d8f388d8SDavid Brownell { 150d8f388d8SDavid Brownell /* GPIO can never have been exported */ 151d8f388d8SDavid Brownell WARN_ON(1); 152d8f388d8SDavid Brownell } 153d8f388d8SDavid Brownell 1547560fa60SDavid Brownell static inline int gpio_to_irq(unsigned gpio) 1557560fa60SDavid Brownell { 1567560fa60SDavid Brownell /* GPIO can never have been requested or set as input */ 1577560fa60SDavid Brownell WARN_ON(1); 1587560fa60SDavid Brownell return -EINVAL; 1597560fa60SDavid Brownell } 1607560fa60SDavid Brownell 1617560fa60SDavid Brownell static inline int irq_to_gpio(unsigned irq) 1627560fa60SDavid Brownell { 1637560fa60SDavid Brownell /* irq can never have been returned from gpio_to_irq() */ 1647560fa60SDavid Brownell WARN_ON(1); 1657560fa60SDavid Brownell return -EINVAL; 1667560fa60SDavid Brownell } 1677560fa60SDavid Brownell 1687560fa60SDavid Brownell #endif 1697560fa60SDavid Brownell 1707560fa60SDavid Brownell #endif /* __LINUX_GPIO_H */ 171