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 23fc3a1f04SWolfram Sang #define GPIOF_EXPORT (1 << 2) 24fc3a1f04SWolfram Sang #define GPIOF_EXPORT_CHANGEABLE (1 << 3) 25fc3a1f04SWolfram Sang #define GPIOF_EXPORT_DIR_FIXED (GPIOF_EXPORT) 26fc3a1f04SWolfram Sang #define GPIOF_EXPORT_DIR_CHANGEABLE (GPIOF_EXPORT | GPIOF_EXPORT_CHANGEABLE) 27fc3a1f04SWolfram Sang 28feb83699SMark Brown /** 29feb83699SMark Brown * struct gpio - a structure describing a GPIO with configuration 30feb83699SMark Brown * @gpio: the GPIO number 31feb83699SMark Brown * @flags: GPIO configuration as specified by GPIOF_* 32feb83699SMark Brown * @label: a literal description string of this GPIO 33feb83699SMark Brown */ 34feb83699SMark Brown struct gpio { 35feb83699SMark Brown unsigned gpio; 36feb83699SMark Brown unsigned long flags; 37feb83699SMark Brown const char *label; 38feb83699SMark Brown }; 39feb83699SMark Brown 407560fa60SDavid Brownell #ifdef CONFIG_GENERIC_GPIO 417560fa60SDavid Brownell #include <asm/gpio.h> 427560fa60SDavid Brownell 437560fa60SDavid Brownell #else 447560fa60SDavid Brownell 453d599d1cSUwe Kleine-König #include <linux/kernel.h> 466ea0205bSDavid Brownell #include <linux/types.h> 476ea0205bSDavid Brownell #include <linux/errno.h> 48187f1882SPaul Gortmaker #include <linux/bug.h> 496ea0205bSDavid Brownell 50a4177ee7SJani Nikula struct device; 514e4438b8SAnton Vorontsov struct gpio_chip; 52a4177ee7SJani Nikula 533474cb3cSJoe Perches static inline bool gpio_is_valid(int number) 547560fa60SDavid Brownell { 553474cb3cSJoe Perches return false; 567560fa60SDavid Brownell } 577560fa60SDavid Brownell 58d8a3515eSLinus Torvalds static inline int gpio_request(unsigned gpio, const char *label) 597560fa60SDavid Brownell { 607560fa60SDavid Brownell return -ENOSYS; 617560fa60SDavid Brownell } 627560fa60SDavid Brownell 63323b7fe8SWolfram Sang static inline int gpio_request_one(unsigned gpio, 645f829e40SWolfram Sang unsigned long flags, const char *label) 655f829e40SWolfram Sang { 665f829e40SWolfram Sang return -ENOSYS; 675f829e40SWolfram Sang } 685f829e40SWolfram Sang 697c295975SLars-Peter Clausen static inline int gpio_request_array(const struct gpio *array, size_t num) 705f829e40SWolfram Sang { 715f829e40SWolfram Sang return -ENOSYS; 725f829e40SWolfram Sang } 735f829e40SWolfram Sang 747560fa60SDavid Brownell static inline void gpio_free(unsigned gpio) 757560fa60SDavid Brownell { 763d599d1cSUwe Kleine-König might_sleep(); 773d599d1cSUwe Kleine-König 787560fa60SDavid Brownell /* GPIO can never have been requested */ 797560fa60SDavid Brownell WARN_ON(1); 807560fa60SDavid Brownell } 817560fa60SDavid Brownell 827c295975SLars-Peter Clausen static inline void gpio_free_array(const struct gpio *array, size_t num) 835f829e40SWolfram Sang { 845f829e40SWolfram Sang might_sleep(); 855f829e40SWolfram Sang 865f829e40SWolfram Sang /* GPIO can never have been requested */ 875f829e40SWolfram Sang WARN_ON(1); 885f829e40SWolfram Sang } 895f829e40SWolfram Sang 90d8a3515eSLinus Torvalds static inline int gpio_direction_input(unsigned gpio) 917560fa60SDavid Brownell { 927560fa60SDavid Brownell return -ENOSYS; 937560fa60SDavid Brownell } 947560fa60SDavid Brownell 95d8a3515eSLinus Torvalds static inline int gpio_direction_output(unsigned gpio, int value) 967560fa60SDavid Brownell { 977560fa60SDavid Brownell return -ENOSYS; 987560fa60SDavid Brownell } 997560fa60SDavid Brownell 100c4b5be98SFelipe Balbi static inline int gpio_set_debounce(unsigned gpio, unsigned debounce) 101c4b5be98SFelipe Balbi { 102c4b5be98SFelipe Balbi return -ENOSYS; 103c4b5be98SFelipe Balbi } 104c4b5be98SFelipe Balbi 1057560fa60SDavid Brownell static inline int gpio_get_value(unsigned gpio) 1067560fa60SDavid Brownell { 1077560fa60SDavid Brownell /* GPIO can never have been requested or set as {in,out}put */ 1087560fa60SDavid Brownell WARN_ON(1); 1097560fa60SDavid Brownell return 0; 1107560fa60SDavid Brownell } 1117560fa60SDavid Brownell 1127560fa60SDavid Brownell static inline void gpio_set_value(unsigned gpio, int value) 1137560fa60SDavid Brownell { 1147560fa60SDavid Brownell /* GPIO can never have been requested or set as output */ 1157560fa60SDavid Brownell WARN_ON(1); 1167560fa60SDavid Brownell } 1177560fa60SDavid Brownell 1187560fa60SDavid Brownell static inline int gpio_cansleep(unsigned gpio) 1197560fa60SDavid Brownell { 1207560fa60SDavid Brownell /* GPIO can never have been requested or set as {in,out}put */ 1217560fa60SDavid Brownell WARN_ON(1); 1227560fa60SDavid Brownell return 0; 1237560fa60SDavid Brownell } 1247560fa60SDavid Brownell 1257560fa60SDavid Brownell static inline int gpio_get_value_cansleep(unsigned gpio) 1267560fa60SDavid Brownell { 1277560fa60SDavid Brownell /* GPIO can never have been requested or set as {in,out}put */ 1287560fa60SDavid Brownell WARN_ON(1); 1297560fa60SDavid Brownell return 0; 1307560fa60SDavid Brownell } 1317560fa60SDavid Brownell 1327560fa60SDavid Brownell static inline void gpio_set_value_cansleep(unsigned gpio, int value) 1337560fa60SDavid Brownell { 1347560fa60SDavid Brownell /* GPIO can never have been requested or set as output */ 1357560fa60SDavid Brownell WARN_ON(1); 1367560fa60SDavid Brownell } 1377560fa60SDavid Brownell 138d8f388d8SDavid Brownell static inline int gpio_export(unsigned gpio, bool direction_may_change) 139d8f388d8SDavid Brownell { 140d8f388d8SDavid Brownell /* GPIO can never have been requested or set as {in,out}put */ 141d8f388d8SDavid Brownell WARN_ON(1); 142d8f388d8SDavid Brownell return -EINVAL; 143d8f388d8SDavid Brownell } 144d8f388d8SDavid Brownell 145a4177ee7SJani Nikula static inline int gpio_export_link(struct device *dev, const char *name, 146a4177ee7SJani Nikula unsigned gpio) 147a4177ee7SJani Nikula { 148a4177ee7SJani Nikula /* GPIO can never have been exported */ 149a4177ee7SJani Nikula WARN_ON(1); 150a4177ee7SJani Nikula return -EINVAL; 151a4177ee7SJani Nikula } 152a4177ee7SJani Nikula 15307697461SJani Nikula static inline int gpio_sysfs_set_active_low(unsigned gpio, int value) 15407697461SJani Nikula { 15507697461SJani Nikula /* GPIO can never have been requested */ 15607697461SJani Nikula WARN_ON(1); 15707697461SJani Nikula return -EINVAL; 15807697461SJani Nikula } 159a4177ee7SJani Nikula 160d8f388d8SDavid Brownell static inline void gpio_unexport(unsigned gpio) 161d8f388d8SDavid Brownell { 162d8f388d8SDavid Brownell /* GPIO can never have been exported */ 163d8f388d8SDavid Brownell WARN_ON(1); 164d8f388d8SDavid Brownell } 165d8f388d8SDavid Brownell 1667560fa60SDavid Brownell static inline int gpio_to_irq(unsigned gpio) 1677560fa60SDavid Brownell { 1687560fa60SDavid Brownell /* GPIO can never have been requested or set as input */ 1697560fa60SDavid Brownell WARN_ON(1); 1707560fa60SDavid Brownell return -EINVAL; 1717560fa60SDavid Brownell } 1727560fa60SDavid Brownell 1737560fa60SDavid Brownell static inline int irq_to_gpio(unsigned irq) 1747560fa60SDavid Brownell { 1757560fa60SDavid Brownell /* irq can never have been returned from gpio_to_irq() */ 1767560fa60SDavid Brownell WARN_ON(1); 1777560fa60SDavid Brownell return -EINVAL; 1787560fa60SDavid Brownell } 1797560fa60SDavid Brownell 1807560fa60SDavid Brownell #endif 1817560fa60SDavid Brownell 1827560fa60SDavid Brownell #endif /* __LINUX_GPIO_H */ 183