xref: /openbmc/linux/include/linux/gpio.h (revision d8a3515e)
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;
165f829e40SWolfram Sang struct gpio;
174e4438b8SAnton Vorontsov struct gpio_chip;
18a4177ee7SJani Nikula 
197560fa60SDavid Brownell /*
207560fa60SDavid Brownell  * Some platforms don't support the GPIO programming interface.
217560fa60SDavid Brownell  *
227560fa60SDavid Brownell  * In case some driver uses it anyway (it should normally have
237560fa60SDavid Brownell  * depended on GENERIC_GPIO), these routines help the compiler
247560fa60SDavid Brownell  * optimize out much GPIO-related code ... or trigger a runtime
257560fa60SDavid Brownell  * warning when something is wrongly called.
267560fa60SDavid Brownell  */
277560fa60SDavid Brownell 
287560fa60SDavid Brownell static inline int gpio_is_valid(int number)
297560fa60SDavid Brownell {
307560fa60SDavid Brownell 	return 0;
317560fa60SDavid Brownell }
327560fa60SDavid Brownell 
33d8a3515eSLinus Torvalds static inline int gpio_request(unsigned gpio, const char *label)
347560fa60SDavid Brownell {
357560fa60SDavid Brownell 	return -ENOSYS;
367560fa60SDavid Brownell }
377560fa60SDavid Brownell 
385f829e40SWolfram Sang static inline int __must_check gpio_request_one(unsigned gpio,
395f829e40SWolfram Sang 					unsigned long flags, const char *label)
405f829e40SWolfram Sang {
415f829e40SWolfram Sang 	return -ENOSYS;
425f829e40SWolfram Sang }
435f829e40SWolfram Sang 
445f829e40SWolfram Sang static inline int __must_check gpio_request_array(struct gpio *array, size_t num)
455f829e40SWolfram Sang {
465f829e40SWolfram Sang 	return -ENOSYS;
475f829e40SWolfram Sang }
485f829e40SWolfram Sang 
497560fa60SDavid Brownell static inline void gpio_free(unsigned gpio)
507560fa60SDavid Brownell {
513d599d1cSUwe Kleine-König 	might_sleep();
523d599d1cSUwe Kleine-König 
537560fa60SDavid Brownell 	/* GPIO can never have been requested */
547560fa60SDavid Brownell 	WARN_ON(1);
557560fa60SDavid Brownell }
567560fa60SDavid Brownell 
575f829e40SWolfram Sang static inline void gpio_free_array(struct gpio *array, size_t num)
585f829e40SWolfram Sang {
595f829e40SWolfram Sang 	might_sleep();
605f829e40SWolfram Sang 
615f829e40SWolfram Sang 	/* GPIO can never have been requested */
625f829e40SWolfram Sang 	WARN_ON(1);
635f829e40SWolfram Sang }
645f829e40SWolfram Sang 
65d8a3515eSLinus Torvalds static inline int gpio_direction_input(unsigned gpio)
667560fa60SDavid Brownell {
677560fa60SDavid Brownell 	return -ENOSYS;
687560fa60SDavid Brownell }
697560fa60SDavid Brownell 
70d8a3515eSLinus Torvalds static inline int gpio_direction_output(unsigned gpio, int value)
717560fa60SDavid Brownell {
727560fa60SDavid Brownell 	return -ENOSYS;
737560fa60SDavid Brownell }
747560fa60SDavid Brownell 
75c4b5be98SFelipe Balbi static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
76c4b5be98SFelipe Balbi {
77c4b5be98SFelipe Balbi 	return -ENOSYS;
78c4b5be98SFelipe Balbi }
79c4b5be98SFelipe Balbi 
807560fa60SDavid Brownell static inline int gpio_get_value(unsigned gpio)
817560fa60SDavid Brownell {
827560fa60SDavid Brownell 	/* GPIO can never have been requested or set as {in,out}put */
837560fa60SDavid Brownell 	WARN_ON(1);
847560fa60SDavid Brownell 	return 0;
857560fa60SDavid Brownell }
867560fa60SDavid Brownell 
877560fa60SDavid Brownell static inline void gpio_set_value(unsigned gpio, int value)
887560fa60SDavid Brownell {
897560fa60SDavid Brownell 	/* GPIO can never have been requested or set as output */
907560fa60SDavid Brownell 	WARN_ON(1);
917560fa60SDavid Brownell }
927560fa60SDavid Brownell 
937560fa60SDavid Brownell static inline int gpio_cansleep(unsigned gpio)
947560fa60SDavid Brownell {
957560fa60SDavid Brownell 	/* GPIO can never have been requested or set as {in,out}put */
967560fa60SDavid Brownell 	WARN_ON(1);
977560fa60SDavid Brownell 	return 0;
987560fa60SDavid Brownell }
997560fa60SDavid Brownell 
1007560fa60SDavid Brownell static inline int gpio_get_value_cansleep(unsigned gpio)
1017560fa60SDavid Brownell {
1027560fa60SDavid Brownell 	/* GPIO can never have been requested or set as {in,out}put */
1037560fa60SDavid Brownell 	WARN_ON(1);
1047560fa60SDavid Brownell 	return 0;
1057560fa60SDavid Brownell }
1067560fa60SDavid Brownell 
1077560fa60SDavid Brownell static inline void gpio_set_value_cansleep(unsigned gpio, int value)
1087560fa60SDavid Brownell {
1097560fa60SDavid Brownell 	/* GPIO can never have been requested or set as output */
1107560fa60SDavid Brownell 	WARN_ON(1);
1117560fa60SDavid Brownell }
1127560fa60SDavid Brownell 
113d8f388d8SDavid Brownell static inline int gpio_export(unsigned gpio, bool direction_may_change)
114d8f388d8SDavid Brownell {
115d8f388d8SDavid Brownell 	/* GPIO can never have been requested or set as {in,out}put */
116d8f388d8SDavid Brownell 	WARN_ON(1);
117d8f388d8SDavid Brownell 	return -EINVAL;
118d8f388d8SDavid Brownell }
119d8f388d8SDavid Brownell 
120a4177ee7SJani Nikula static inline int gpio_export_link(struct device *dev, const char *name,
121a4177ee7SJani Nikula 				unsigned gpio)
122a4177ee7SJani Nikula {
123a4177ee7SJani Nikula 	/* GPIO can never have been exported */
124a4177ee7SJani Nikula 	WARN_ON(1);
125a4177ee7SJani Nikula 	return -EINVAL;
126a4177ee7SJani Nikula }
127a4177ee7SJani Nikula 
12807697461SJani Nikula static inline int gpio_sysfs_set_active_low(unsigned gpio, int value)
12907697461SJani Nikula {
13007697461SJani Nikula 	/* GPIO can never have been requested */
13107697461SJani Nikula 	WARN_ON(1);
13207697461SJani Nikula 	return -EINVAL;
13307697461SJani Nikula }
134a4177ee7SJani Nikula 
135d8f388d8SDavid Brownell static inline void gpio_unexport(unsigned gpio)
136d8f388d8SDavid Brownell {
137d8f388d8SDavid Brownell 	/* GPIO can never have been exported */
138d8f388d8SDavid Brownell 	WARN_ON(1);
139d8f388d8SDavid Brownell }
140d8f388d8SDavid Brownell 
1417560fa60SDavid Brownell static inline int gpio_to_irq(unsigned gpio)
1427560fa60SDavid Brownell {
1437560fa60SDavid Brownell 	/* GPIO can never have been requested or set as input */
1447560fa60SDavid Brownell 	WARN_ON(1);
1457560fa60SDavid Brownell 	return -EINVAL;
1467560fa60SDavid Brownell }
1477560fa60SDavid Brownell 
1487560fa60SDavid Brownell static inline int irq_to_gpio(unsigned irq)
1497560fa60SDavid Brownell {
1507560fa60SDavid Brownell 	/* irq can never have been returned from gpio_to_irq() */
1517560fa60SDavid Brownell 	WARN_ON(1);
1527560fa60SDavid Brownell 	return -EINVAL;
1537560fa60SDavid Brownell }
1547560fa60SDavid Brownell 
1557560fa60SDavid Brownell #endif
1567560fa60SDavid Brownell 
1577560fa60SDavid Brownell #endif /* __LINUX_GPIO_H */
158