xref: /openbmc/linux/include/linux/gpio.h (revision a4177ee7)
17560fa60SDavid Brownell #ifndef __LINUX_GPIO_H
27560fa60SDavid Brownell #define __LINUX_GPIO_H
37560fa60SDavid Brownell 
47560fa60SDavid Brownell /* see Documentation/gpio.txt */
57560fa60SDavid Brownell 
67560fa60SDavid Brownell #ifdef CONFIG_GENERIC_GPIO
77560fa60SDavid Brownell #include <asm/gpio.h>
87560fa60SDavid Brownell 
97560fa60SDavid Brownell #else
107560fa60SDavid Brownell 
113d599d1cSUwe Kleine-König #include <linux/kernel.h>
126ea0205bSDavid Brownell #include <linux/types.h>
136ea0205bSDavid Brownell #include <linux/errno.h>
146ea0205bSDavid Brownell 
15a4177ee7SJani Nikula struct device;
16a4177ee7SJani Nikula 
177560fa60SDavid Brownell /*
187560fa60SDavid Brownell  * Some platforms don't support the GPIO programming interface.
197560fa60SDavid Brownell  *
207560fa60SDavid Brownell  * In case some driver uses it anyway (it should normally have
217560fa60SDavid Brownell  * depended on GENERIC_GPIO), these routines help the compiler
227560fa60SDavid Brownell  * optimize out much GPIO-related code ... or trigger a runtime
237560fa60SDavid Brownell  * warning when something is wrongly called.
247560fa60SDavid Brownell  */
257560fa60SDavid Brownell 
267560fa60SDavid Brownell static inline int gpio_is_valid(int number)
277560fa60SDavid Brownell {
287560fa60SDavid Brownell 	return 0;
297560fa60SDavid Brownell }
307560fa60SDavid Brownell 
317560fa60SDavid Brownell static inline int gpio_request(unsigned gpio, const char *label)
327560fa60SDavid Brownell {
337560fa60SDavid Brownell 	return -ENOSYS;
347560fa60SDavid Brownell }
357560fa60SDavid Brownell 
367560fa60SDavid Brownell static inline void gpio_free(unsigned gpio)
377560fa60SDavid Brownell {
383d599d1cSUwe Kleine-König 	might_sleep();
393d599d1cSUwe Kleine-König 
407560fa60SDavid Brownell 	/* GPIO can never have been requested */
417560fa60SDavid Brownell 	WARN_ON(1);
427560fa60SDavid Brownell }
437560fa60SDavid Brownell 
447560fa60SDavid Brownell static inline int gpio_direction_input(unsigned gpio)
457560fa60SDavid Brownell {
467560fa60SDavid Brownell 	return -ENOSYS;
477560fa60SDavid Brownell }
487560fa60SDavid Brownell 
497560fa60SDavid Brownell static inline int gpio_direction_output(unsigned gpio, int value)
507560fa60SDavid Brownell {
517560fa60SDavid Brownell 	return -ENOSYS;
527560fa60SDavid Brownell }
537560fa60SDavid Brownell 
547560fa60SDavid Brownell static inline int gpio_get_value(unsigned gpio)
557560fa60SDavid Brownell {
567560fa60SDavid Brownell 	/* GPIO can never have been requested or set as {in,out}put */
577560fa60SDavid Brownell 	WARN_ON(1);
587560fa60SDavid Brownell 	return 0;
597560fa60SDavid Brownell }
607560fa60SDavid Brownell 
617560fa60SDavid Brownell static inline void gpio_set_value(unsigned gpio, int value)
627560fa60SDavid Brownell {
637560fa60SDavid Brownell 	/* GPIO can never have been requested or set as output */
647560fa60SDavid Brownell 	WARN_ON(1);
657560fa60SDavid Brownell }
667560fa60SDavid Brownell 
677560fa60SDavid Brownell static inline int gpio_cansleep(unsigned gpio)
687560fa60SDavid Brownell {
697560fa60SDavid Brownell 	/* GPIO can never have been requested or set as {in,out}put */
707560fa60SDavid Brownell 	WARN_ON(1);
717560fa60SDavid Brownell 	return 0;
727560fa60SDavid Brownell }
737560fa60SDavid Brownell 
747560fa60SDavid Brownell static inline int gpio_get_value_cansleep(unsigned gpio)
757560fa60SDavid Brownell {
767560fa60SDavid Brownell 	/* GPIO can never have been requested or set as {in,out}put */
777560fa60SDavid Brownell 	WARN_ON(1);
787560fa60SDavid Brownell 	return 0;
797560fa60SDavid Brownell }
807560fa60SDavid Brownell 
817560fa60SDavid Brownell static inline void gpio_set_value_cansleep(unsigned gpio, int value)
827560fa60SDavid Brownell {
837560fa60SDavid Brownell 	/* GPIO can never have been requested or set as output */
847560fa60SDavid Brownell 	WARN_ON(1);
857560fa60SDavid Brownell }
867560fa60SDavid Brownell 
87d8f388d8SDavid Brownell static inline int gpio_export(unsigned gpio, bool direction_may_change)
88d8f388d8SDavid Brownell {
89d8f388d8SDavid Brownell 	/* GPIO can never have been requested or set as {in,out}put */
90d8f388d8SDavid Brownell 	WARN_ON(1);
91d8f388d8SDavid Brownell 	return -EINVAL;
92d8f388d8SDavid Brownell }
93d8f388d8SDavid Brownell 
94a4177ee7SJani Nikula static inline int gpio_export_link(struct device *dev, const char *name,
95a4177ee7SJani Nikula 				unsigned gpio)
96a4177ee7SJani Nikula {
97a4177ee7SJani Nikula 	/* GPIO can never have been exported */
98a4177ee7SJani Nikula 	WARN_ON(1);
99a4177ee7SJani Nikula 	return -EINVAL;
100a4177ee7SJani Nikula }
101a4177ee7SJani Nikula 
102a4177ee7SJani Nikula 
103d8f388d8SDavid Brownell static inline void gpio_unexport(unsigned gpio)
104d8f388d8SDavid Brownell {
105d8f388d8SDavid Brownell 	/* GPIO can never have been exported */
106d8f388d8SDavid Brownell 	WARN_ON(1);
107d8f388d8SDavid Brownell }
108d8f388d8SDavid Brownell 
1097560fa60SDavid Brownell static inline int gpio_to_irq(unsigned gpio)
1107560fa60SDavid Brownell {
1117560fa60SDavid Brownell 	/* GPIO can never have been requested or set as input */
1127560fa60SDavid Brownell 	WARN_ON(1);
1137560fa60SDavid Brownell 	return -EINVAL;
1147560fa60SDavid Brownell }
1157560fa60SDavid Brownell 
1167560fa60SDavid Brownell static inline int irq_to_gpio(unsigned irq)
1177560fa60SDavid Brownell {
1187560fa60SDavid Brownell 	/* irq can never have been returned from gpio_to_irq() */
1197560fa60SDavid Brownell 	WARN_ON(1);
1207560fa60SDavid Brownell 	return -EINVAL;
1217560fa60SDavid Brownell }
1227560fa60SDavid Brownell 
1237560fa60SDavid Brownell #endif
1247560fa60SDavid Brownell 
1257560fa60SDavid Brownell #endif /* __LINUX_GPIO_H */
126