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 632c96922aSMark Brown static inline int devm_gpio_request(struct device *dev, unsigned gpio, 642c96922aSMark Brown const char *label) 652c96922aSMark Brown { 662c96922aSMark Brown return -ENOSYS; 672c96922aSMark Brown } 682c96922aSMark Brown 69323b7fe8SWolfram Sang static inline int gpio_request_one(unsigned gpio, 705f829e40SWolfram Sang unsigned long flags, const char *label) 715f829e40SWolfram Sang { 725f829e40SWolfram Sang return -ENOSYS; 735f829e40SWolfram Sang } 745f829e40SWolfram Sang 757c295975SLars-Peter Clausen static inline int gpio_request_array(const struct gpio *array, size_t num) 765f829e40SWolfram Sang { 775f829e40SWolfram Sang return -ENOSYS; 785f829e40SWolfram Sang } 795f829e40SWolfram Sang 807560fa60SDavid Brownell static inline void gpio_free(unsigned gpio) 817560fa60SDavid Brownell { 823d599d1cSUwe Kleine-König might_sleep(); 833d599d1cSUwe Kleine-König 847560fa60SDavid Brownell /* GPIO can never have been requested */ 857560fa60SDavid Brownell WARN_ON(1); 867560fa60SDavid Brownell } 877560fa60SDavid Brownell 882c96922aSMark Brown static inline void devm_gpio_free(struct device *dev, unsigned gpio) 892c96922aSMark Brown { 902c96922aSMark Brown might_sleep(); 912c96922aSMark Brown 922c96922aSMark Brown /* GPIO can never have been requested */ 932c96922aSMark Brown WARN_ON(1); 942c96922aSMark Brown } 952c96922aSMark Brown 967c295975SLars-Peter Clausen static inline void gpio_free_array(const struct gpio *array, size_t num) 975f829e40SWolfram Sang { 985f829e40SWolfram Sang might_sleep(); 995f829e40SWolfram Sang 1005f829e40SWolfram Sang /* GPIO can never have been requested */ 1015f829e40SWolfram Sang WARN_ON(1); 1025f829e40SWolfram Sang } 1035f829e40SWolfram Sang 104d8a3515eSLinus Torvalds static inline int gpio_direction_input(unsigned gpio) 1057560fa60SDavid Brownell { 1067560fa60SDavid Brownell return -ENOSYS; 1077560fa60SDavid Brownell } 1087560fa60SDavid Brownell 109d8a3515eSLinus Torvalds static inline int gpio_direction_output(unsigned gpio, int value) 1107560fa60SDavid Brownell { 1117560fa60SDavid Brownell return -ENOSYS; 1127560fa60SDavid Brownell } 1137560fa60SDavid Brownell 114c4b5be98SFelipe Balbi static inline int gpio_set_debounce(unsigned gpio, unsigned debounce) 115c4b5be98SFelipe Balbi { 116c4b5be98SFelipe Balbi return -ENOSYS; 117c4b5be98SFelipe Balbi } 118c4b5be98SFelipe Balbi 1197560fa60SDavid Brownell static inline int gpio_get_value(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(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 1327560fa60SDavid Brownell static inline int gpio_cansleep(unsigned gpio) 1337560fa60SDavid Brownell { 1347560fa60SDavid Brownell /* GPIO can never have been requested or set as {in,out}put */ 1357560fa60SDavid Brownell WARN_ON(1); 1367560fa60SDavid Brownell return 0; 1377560fa60SDavid Brownell } 1387560fa60SDavid Brownell 1397560fa60SDavid Brownell static inline int gpio_get_value_cansleep(unsigned gpio) 1407560fa60SDavid Brownell { 1417560fa60SDavid Brownell /* GPIO can never have been requested or set as {in,out}put */ 1427560fa60SDavid Brownell WARN_ON(1); 1437560fa60SDavid Brownell return 0; 1447560fa60SDavid Brownell } 1457560fa60SDavid Brownell 1467560fa60SDavid Brownell static inline void gpio_set_value_cansleep(unsigned gpio, int value) 1477560fa60SDavid Brownell { 1487560fa60SDavid Brownell /* GPIO can never have been requested or set as output */ 1497560fa60SDavid Brownell WARN_ON(1); 1507560fa60SDavid Brownell } 1517560fa60SDavid Brownell 152d8f388d8SDavid Brownell static inline int gpio_export(unsigned gpio, bool direction_may_change) 153d8f388d8SDavid Brownell { 154d8f388d8SDavid Brownell /* GPIO can never have been requested or set as {in,out}put */ 155d8f388d8SDavid Brownell WARN_ON(1); 156d8f388d8SDavid Brownell return -EINVAL; 157d8f388d8SDavid Brownell } 158d8f388d8SDavid Brownell 159a4177ee7SJani Nikula static inline int gpio_export_link(struct device *dev, const char *name, 160a4177ee7SJani Nikula unsigned gpio) 161a4177ee7SJani Nikula { 162a4177ee7SJani Nikula /* GPIO can never have been exported */ 163a4177ee7SJani Nikula WARN_ON(1); 164a4177ee7SJani Nikula return -EINVAL; 165a4177ee7SJani Nikula } 166a4177ee7SJani Nikula 16707697461SJani Nikula static inline int gpio_sysfs_set_active_low(unsigned gpio, int value) 16807697461SJani Nikula { 16907697461SJani Nikula /* GPIO can never have been requested */ 17007697461SJani Nikula WARN_ON(1); 17107697461SJani Nikula return -EINVAL; 17207697461SJani Nikula } 173a4177ee7SJani Nikula 174d8f388d8SDavid Brownell static inline void gpio_unexport(unsigned gpio) 175d8f388d8SDavid Brownell { 176d8f388d8SDavid Brownell /* GPIO can never have been exported */ 177d8f388d8SDavid Brownell WARN_ON(1); 178d8f388d8SDavid Brownell } 179d8f388d8SDavid Brownell 1807560fa60SDavid Brownell static inline int gpio_to_irq(unsigned gpio) 1817560fa60SDavid Brownell { 1827560fa60SDavid Brownell /* GPIO can never have been requested or set as input */ 1837560fa60SDavid Brownell WARN_ON(1); 1847560fa60SDavid Brownell return -EINVAL; 1857560fa60SDavid Brownell } 1867560fa60SDavid Brownell 1877560fa60SDavid Brownell static inline int irq_to_gpio(unsigned irq) 1887560fa60SDavid Brownell { 1897560fa60SDavid Brownell /* irq can never have been returned from gpio_to_irq() */ 1907560fa60SDavid Brownell WARN_ON(1); 1917560fa60SDavid Brownell return -EINVAL; 1927560fa60SDavid Brownell } 1937560fa60SDavid Brownell 1947560fa60SDavid Brownell #endif 1957560fa60SDavid Brownell 1967560fa60SDavid Brownell #endif /* __LINUX_GPIO_H */ 197