xref: /openbmc/linux/include/linux/gpio.h (revision c4b5be98)
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 
54c4b5be98SFelipe Balbi static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
55c4b5be98SFelipe Balbi {
56c4b5be98SFelipe Balbi 	return -ENOSYS;
57c4b5be98SFelipe Balbi }
58c4b5be98SFelipe Balbi 
597560fa60SDavid Brownell static inline int gpio_get_value(unsigned gpio)
607560fa60SDavid Brownell {
617560fa60SDavid Brownell 	/* GPIO can never have been requested or set as {in,out}put */
627560fa60SDavid Brownell 	WARN_ON(1);
637560fa60SDavid Brownell 	return 0;
647560fa60SDavid Brownell }
657560fa60SDavid Brownell 
667560fa60SDavid Brownell static inline void gpio_set_value(unsigned gpio, int value)
677560fa60SDavid Brownell {
687560fa60SDavid Brownell 	/* GPIO can never have been requested or set as output */
697560fa60SDavid Brownell 	WARN_ON(1);
707560fa60SDavid Brownell }
717560fa60SDavid Brownell 
727560fa60SDavid Brownell static inline int gpio_cansleep(unsigned gpio)
737560fa60SDavid Brownell {
747560fa60SDavid Brownell 	/* GPIO can never have been requested or set as {in,out}put */
757560fa60SDavid Brownell 	WARN_ON(1);
767560fa60SDavid Brownell 	return 0;
777560fa60SDavid Brownell }
787560fa60SDavid Brownell 
797560fa60SDavid Brownell static inline int gpio_get_value_cansleep(unsigned gpio)
807560fa60SDavid Brownell {
817560fa60SDavid Brownell 	/* GPIO can never have been requested or set as {in,out}put */
827560fa60SDavid Brownell 	WARN_ON(1);
837560fa60SDavid Brownell 	return 0;
847560fa60SDavid Brownell }
857560fa60SDavid Brownell 
867560fa60SDavid Brownell static inline void gpio_set_value_cansleep(unsigned gpio, int value)
877560fa60SDavid Brownell {
887560fa60SDavid Brownell 	/* GPIO can never have been requested or set as output */
897560fa60SDavid Brownell 	WARN_ON(1);
907560fa60SDavid Brownell }
917560fa60SDavid Brownell 
92d8f388d8SDavid Brownell static inline int gpio_export(unsigned gpio, bool direction_may_change)
93d8f388d8SDavid Brownell {
94d8f388d8SDavid Brownell 	/* GPIO can never have been requested or set as {in,out}put */
95d8f388d8SDavid Brownell 	WARN_ON(1);
96d8f388d8SDavid Brownell 	return -EINVAL;
97d8f388d8SDavid Brownell }
98d8f388d8SDavid Brownell 
99a4177ee7SJani Nikula static inline int gpio_export_link(struct device *dev, const char *name,
100a4177ee7SJani Nikula 				unsigned gpio)
101a4177ee7SJani Nikula {
102a4177ee7SJani Nikula 	/* GPIO can never have been exported */
103a4177ee7SJani Nikula 	WARN_ON(1);
104a4177ee7SJani Nikula 	return -EINVAL;
105a4177ee7SJani Nikula }
106a4177ee7SJani Nikula 
10707697461SJani Nikula static inline int gpio_sysfs_set_active_low(unsigned gpio, int value)
10807697461SJani Nikula {
10907697461SJani Nikula 	/* GPIO can never have been requested */
11007697461SJani Nikula 	WARN_ON(1);
11107697461SJani Nikula 	return -EINVAL;
11207697461SJani Nikula }
113a4177ee7SJani Nikula 
114d8f388d8SDavid Brownell static inline void gpio_unexport(unsigned gpio)
115d8f388d8SDavid Brownell {
116d8f388d8SDavid Brownell 	/* GPIO can never have been exported */
117d8f388d8SDavid Brownell 	WARN_ON(1);
118d8f388d8SDavid Brownell }
119d8f388d8SDavid Brownell 
1207560fa60SDavid Brownell static inline int gpio_to_irq(unsigned gpio)
1217560fa60SDavid Brownell {
1227560fa60SDavid Brownell 	/* GPIO can never have been requested or set as input */
1237560fa60SDavid Brownell 	WARN_ON(1);
1247560fa60SDavid Brownell 	return -EINVAL;
1257560fa60SDavid Brownell }
1267560fa60SDavid Brownell 
1277560fa60SDavid Brownell static inline int irq_to_gpio(unsigned irq)
1287560fa60SDavid Brownell {
1297560fa60SDavid Brownell 	/* irq can never have been returned from gpio_to_irq() */
1307560fa60SDavid Brownell 	WARN_ON(1);
1317560fa60SDavid Brownell 	return -EINVAL;
1327560fa60SDavid Brownell }
1337560fa60SDavid Brownell 
1347560fa60SDavid Brownell #endif
1357560fa60SDavid Brownell 
1367560fa60SDavid Brownell #endif /* __LINUX_GPIO_H */
137