xref: /openbmc/linux/include/linux/gpio.h (revision c001fb72)
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 
177560fa60SDavid Brownell #ifdef CONFIG_GENERIC_GPIO
187560fa60SDavid Brownell #include <asm/gpio.h>
197560fa60SDavid Brownell 
207560fa60SDavid Brownell #else
217560fa60SDavid Brownell 
223d599d1cSUwe Kleine-König #include <linux/kernel.h>
236ea0205bSDavid Brownell #include <linux/types.h>
246ea0205bSDavid Brownell #include <linux/errno.h>
256ea0205bSDavid Brownell 
26a4177ee7SJani Nikula struct device;
275f829e40SWolfram Sang struct gpio;
284e4438b8SAnton Vorontsov struct gpio_chip;
29a4177ee7SJani Nikula 
307560fa60SDavid Brownell /*
317560fa60SDavid Brownell  * Some platforms don't support the GPIO programming interface.
327560fa60SDavid Brownell  *
337560fa60SDavid Brownell  * In case some driver uses it anyway (it should normally have
347560fa60SDavid Brownell  * depended on GENERIC_GPIO), these routines help the compiler
357560fa60SDavid Brownell  * optimize out much GPIO-related code ... or trigger a runtime
367560fa60SDavid Brownell  * warning when something is wrongly called.
377560fa60SDavid Brownell  */
387560fa60SDavid Brownell 
393474cb3cSJoe Perches static inline bool gpio_is_valid(int number)
407560fa60SDavid Brownell {
413474cb3cSJoe Perches 	return false;
427560fa60SDavid Brownell }
437560fa60SDavid Brownell 
44d8a3515eSLinus Torvalds static inline int gpio_request(unsigned gpio, const char *label)
457560fa60SDavid Brownell {
467560fa60SDavid Brownell 	return -ENOSYS;
477560fa60SDavid Brownell }
487560fa60SDavid Brownell 
49323b7fe8SWolfram Sang static inline int gpio_request_one(unsigned gpio,
505f829e40SWolfram Sang 					unsigned long flags, const char *label)
515f829e40SWolfram Sang {
525f829e40SWolfram Sang 	return -ENOSYS;
535f829e40SWolfram Sang }
545f829e40SWolfram Sang 
557c295975SLars-Peter Clausen static inline int gpio_request_array(const struct gpio *array, size_t num)
565f829e40SWolfram Sang {
575f829e40SWolfram Sang 	return -ENOSYS;
585f829e40SWolfram Sang }
595f829e40SWolfram Sang 
607560fa60SDavid Brownell static inline void gpio_free(unsigned gpio)
617560fa60SDavid Brownell {
623d599d1cSUwe Kleine-König 	might_sleep();
633d599d1cSUwe Kleine-König 
647560fa60SDavid Brownell 	/* GPIO can never have been requested */
657560fa60SDavid Brownell 	WARN_ON(1);
667560fa60SDavid Brownell }
677560fa60SDavid Brownell 
687c295975SLars-Peter Clausen static inline void gpio_free_array(const struct gpio *array, size_t num)
695f829e40SWolfram Sang {
705f829e40SWolfram Sang 	might_sleep();
715f829e40SWolfram Sang 
725f829e40SWolfram Sang 	/* GPIO can never have been requested */
735f829e40SWolfram Sang 	WARN_ON(1);
745f829e40SWolfram Sang }
755f829e40SWolfram Sang 
76d8a3515eSLinus Torvalds static inline int gpio_direction_input(unsigned gpio)
777560fa60SDavid Brownell {
787560fa60SDavid Brownell 	return -ENOSYS;
797560fa60SDavid Brownell }
807560fa60SDavid Brownell 
81d8a3515eSLinus Torvalds static inline int gpio_direction_output(unsigned gpio, int value)
827560fa60SDavid Brownell {
837560fa60SDavid Brownell 	return -ENOSYS;
847560fa60SDavid Brownell }
857560fa60SDavid Brownell 
86c4b5be98SFelipe Balbi static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
87c4b5be98SFelipe Balbi {
88c4b5be98SFelipe Balbi 	return -ENOSYS;
89c4b5be98SFelipe Balbi }
90c4b5be98SFelipe Balbi 
917560fa60SDavid Brownell static inline int gpio_get_value(unsigned gpio)
927560fa60SDavid Brownell {
937560fa60SDavid Brownell 	/* GPIO can never have been requested or set as {in,out}put */
947560fa60SDavid Brownell 	WARN_ON(1);
957560fa60SDavid Brownell 	return 0;
967560fa60SDavid Brownell }
977560fa60SDavid Brownell 
987560fa60SDavid Brownell static inline void gpio_set_value(unsigned gpio, int value)
997560fa60SDavid Brownell {
1007560fa60SDavid Brownell 	/* GPIO can never have been requested or set as output */
1017560fa60SDavid Brownell 	WARN_ON(1);
1027560fa60SDavid Brownell }
1037560fa60SDavid Brownell 
1047560fa60SDavid Brownell static inline int gpio_cansleep(unsigned gpio)
1057560fa60SDavid Brownell {
1067560fa60SDavid Brownell 	/* GPIO can never have been requested or set as {in,out}put */
1077560fa60SDavid Brownell 	WARN_ON(1);
1087560fa60SDavid Brownell 	return 0;
1097560fa60SDavid Brownell }
1107560fa60SDavid Brownell 
1117560fa60SDavid Brownell static inline int gpio_get_value_cansleep(unsigned gpio)
1127560fa60SDavid Brownell {
1137560fa60SDavid Brownell 	/* GPIO can never have been requested or set as {in,out}put */
1147560fa60SDavid Brownell 	WARN_ON(1);
1157560fa60SDavid Brownell 	return 0;
1167560fa60SDavid Brownell }
1177560fa60SDavid Brownell 
1187560fa60SDavid Brownell static inline void gpio_set_value_cansleep(unsigned gpio, int value)
1197560fa60SDavid Brownell {
1207560fa60SDavid Brownell 	/* GPIO can never have been requested or set as output */
1217560fa60SDavid Brownell 	WARN_ON(1);
1227560fa60SDavid Brownell }
1237560fa60SDavid Brownell 
124d8f388d8SDavid Brownell static inline int gpio_export(unsigned gpio, bool direction_may_change)
125d8f388d8SDavid Brownell {
126d8f388d8SDavid Brownell 	/* GPIO can never have been requested or set as {in,out}put */
127d8f388d8SDavid Brownell 	WARN_ON(1);
128d8f388d8SDavid Brownell 	return -EINVAL;
129d8f388d8SDavid Brownell }
130d8f388d8SDavid Brownell 
131a4177ee7SJani Nikula static inline int gpio_export_link(struct device *dev, const char *name,
132a4177ee7SJani Nikula 				unsigned gpio)
133a4177ee7SJani Nikula {
134a4177ee7SJani Nikula 	/* GPIO can never have been exported */
135a4177ee7SJani Nikula 	WARN_ON(1);
136a4177ee7SJani Nikula 	return -EINVAL;
137a4177ee7SJani Nikula }
138a4177ee7SJani Nikula 
13907697461SJani Nikula static inline int gpio_sysfs_set_active_low(unsigned gpio, int value)
14007697461SJani Nikula {
14107697461SJani Nikula 	/* GPIO can never have been requested */
14207697461SJani Nikula 	WARN_ON(1);
14307697461SJani Nikula 	return -EINVAL;
14407697461SJani Nikula }
145a4177ee7SJani Nikula 
146d8f388d8SDavid Brownell static inline void gpio_unexport(unsigned gpio)
147d8f388d8SDavid Brownell {
148d8f388d8SDavid Brownell 	/* GPIO can never have been exported */
149d8f388d8SDavid Brownell 	WARN_ON(1);
150d8f388d8SDavid Brownell }
151d8f388d8SDavid Brownell 
1527560fa60SDavid Brownell static inline int gpio_to_irq(unsigned gpio)
1537560fa60SDavid Brownell {
1547560fa60SDavid Brownell 	/* GPIO can never have been requested or set as input */
1557560fa60SDavid Brownell 	WARN_ON(1);
1567560fa60SDavid Brownell 	return -EINVAL;
1577560fa60SDavid Brownell }
1587560fa60SDavid Brownell 
1597560fa60SDavid Brownell static inline int irq_to_gpio(unsigned irq)
1607560fa60SDavid Brownell {
1617560fa60SDavid Brownell 	/* irq can never have been returned from gpio_to_irq() */
1627560fa60SDavid Brownell 	WARN_ON(1);
1637560fa60SDavid Brownell 	return -EINVAL;
1647560fa60SDavid Brownell }
1657560fa60SDavid Brownell 
1667560fa60SDavid Brownell #endif
1677560fa60SDavid Brownell 
1687560fa60SDavid Brownell #endif /* __LINUX_GPIO_H */
169