xref: /openbmc/linux/include/linux/gpio.h (revision 187f1882)
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 
17feb83699SMark Brown /**
18feb83699SMark Brown  * struct gpio - a structure describing a GPIO with configuration
19feb83699SMark Brown  * @gpio:	the GPIO number
20feb83699SMark Brown  * @flags:	GPIO configuration as specified by GPIOF_*
21feb83699SMark Brown  * @label:	a literal description string of this GPIO
22feb83699SMark Brown  */
23feb83699SMark Brown struct gpio {
24feb83699SMark Brown 	unsigned	gpio;
25feb83699SMark Brown 	unsigned long	flags;
26feb83699SMark Brown 	const char	*label;
27feb83699SMark Brown };
28feb83699SMark Brown 
297560fa60SDavid Brownell #ifdef CONFIG_GENERIC_GPIO
307560fa60SDavid Brownell #include <asm/gpio.h>
317560fa60SDavid Brownell 
327560fa60SDavid Brownell #else
337560fa60SDavid Brownell 
343d599d1cSUwe Kleine-König #include <linux/kernel.h>
356ea0205bSDavid Brownell #include <linux/types.h>
366ea0205bSDavid Brownell #include <linux/errno.h>
37187f1882SPaul Gortmaker #include <linux/bug.h>
386ea0205bSDavid Brownell 
39a4177ee7SJani Nikula struct device;
404e4438b8SAnton Vorontsov struct gpio_chip;
41a4177ee7SJani Nikula 
423474cb3cSJoe Perches static inline bool gpio_is_valid(int number)
437560fa60SDavid Brownell {
443474cb3cSJoe Perches 	return false;
457560fa60SDavid Brownell }
467560fa60SDavid Brownell 
47d8a3515eSLinus Torvalds static inline int gpio_request(unsigned gpio, const char *label)
487560fa60SDavid Brownell {
497560fa60SDavid Brownell 	return -ENOSYS;
507560fa60SDavid Brownell }
517560fa60SDavid Brownell 
52323b7fe8SWolfram Sang static inline int gpio_request_one(unsigned gpio,
535f829e40SWolfram Sang 					unsigned long flags, const char *label)
545f829e40SWolfram Sang {
555f829e40SWolfram Sang 	return -ENOSYS;
565f829e40SWolfram Sang }
575f829e40SWolfram Sang 
587c295975SLars-Peter Clausen static inline int gpio_request_array(const struct gpio *array, size_t num)
595f829e40SWolfram Sang {
605f829e40SWolfram Sang 	return -ENOSYS;
615f829e40SWolfram Sang }
625f829e40SWolfram Sang 
637560fa60SDavid Brownell static inline void gpio_free(unsigned gpio)
647560fa60SDavid Brownell {
653d599d1cSUwe Kleine-König 	might_sleep();
663d599d1cSUwe Kleine-König 
677560fa60SDavid Brownell 	/* GPIO can never have been requested */
687560fa60SDavid Brownell 	WARN_ON(1);
697560fa60SDavid Brownell }
707560fa60SDavid Brownell 
717c295975SLars-Peter Clausen static inline void gpio_free_array(const struct gpio *array, size_t num)
725f829e40SWolfram Sang {
735f829e40SWolfram Sang 	might_sleep();
745f829e40SWolfram Sang 
755f829e40SWolfram Sang 	/* GPIO can never have been requested */
765f829e40SWolfram Sang 	WARN_ON(1);
775f829e40SWolfram Sang }
785f829e40SWolfram Sang 
79d8a3515eSLinus Torvalds static inline int gpio_direction_input(unsigned gpio)
807560fa60SDavid Brownell {
817560fa60SDavid Brownell 	return -ENOSYS;
827560fa60SDavid Brownell }
837560fa60SDavid Brownell 
84d8a3515eSLinus Torvalds static inline int gpio_direction_output(unsigned gpio, int value)
857560fa60SDavid Brownell {
867560fa60SDavid Brownell 	return -ENOSYS;
877560fa60SDavid Brownell }
887560fa60SDavid Brownell 
89c4b5be98SFelipe Balbi static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
90c4b5be98SFelipe Balbi {
91c4b5be98SFelipe Balbi 	return -ENOSYS;
92c4b5be98SFelipe Balbi }
93c4b5be98SFelipe Balbi 
947560fa60SDavid Brownell static inline int gpio_get_value(unsigned gpio)
957560fa60SDavid Brownell {
967560fa60SDavid Brownell 	/* GPIO can never have been requested or set as {in,out}put */
977560fa60SDavid Brownell 	WARN_ON(1);
987560fa60SDavid Brownell 	return 0;
997560fa60SDavid Brownell }
1007560fa60SDavid Brownell 
1017560fa60SDavid Brownell static inline void gpio_set_value(unsigned gpio, int value)
1027560fa60SDavid Brownell {
1037560fa60SDavid Brownell 	/* GPIO can never have been requested or set as output */
1047560fa60SDavid Brownell 	WARN_ON(1);
1057560fa60SDavid Brownell }
1067560fa60SDavid Brownell 
1077560fa60SDavid Brownell static inline int gpio_cansleep(unsigned gpio)
1087560fa60SDavid Brownell {
1097560fa60SDavid Brownell 	/* GPIO can never have been requested or set as {in,out}put */
1107560fa60SDavid Brownell 	WARN_ON(1);
1117560fa60SDavid Brownell 	return 0;
1127560fa60SDavid Brownell }
1137560fa60SDavid Brownell 
1147560fa60SDavid Brownell static inline int gpio_get_value_cansleep(unsigned gpio)
1157560fa60SDavid Brownell {
1167560fa60SDavid Brownell 	/* GPIO can never have been requested or set as {in,out}put */
1177560fa60SDavid Brownell 	WARN_ON(1);
1187560fa60SDavid Brownell 	return 0;
1197560fa60SDavid Brownell }
1207560fa60SDavid Brownell 
1217560fa60SDavid Brownell static inline void gpio_set_value_cansleep(unsigned gpio, int value)
1227560fa60SDavid Brownell {
1237560fa60SDavid Brownell 	/* GPIO can never have been requested or set as output */
1247560fa60SDavid Brownell 	WARN_ON(1);
1257560fa60SDavid Brownell }
1267560fa60SDavid Brownell 
127d8f388d8SDavid Brownell static inline int gpio_export(unsigned gpio, bool direction_may_change)
128d8f388d8SDavid Brownell {
129d8f388d8SDavid Brownell 	/* GPIO can never have been requested or set as {in,out}put */
130d8f388d8SDavid Brownell 	WARN_ON(1);
131d8f388d8SDavid Brownell 	return -EINVAL;
132d8f388d8SDavid Brownell }
133d8f388d8SDavid Brownell 
134a4177ee7SJani Nikula static inline int gpio_export_link(struct device *dev, const char *name,
135a4177ee7SJani Nikula 				unsigned gpio)
136a4177ee7SJani Nikula {
137a4177ee7SJani Nikula 	/* GPIO can never have been exported */
138a4177ee7SJani Nikula 	WARN_ON(1);
139a4177ee7SJani Nikula 	return -EINVAL;
140a4177ee7SJani Nikula }
141a4177ee7SJani Nikula 
14207697461SJani Nikula static inline int gpio_sysfs_set_active_low(unsigned gpio, int value)
14307697461SJani Nikula {
14407697461SJani Nikula 	/* GPIO can never have been requested */
14507697461SJani Nikula 	WARN_ON(1);
14607697461SJani Nikula 	return -EINVAL;
14707697461SJani Nikula }
148a4177ee7SJani Nikula 
149d8f388d8SDavid Brownell static inline void gpio_unexport(unsigned gpio)
150d8f388d8SDavid Brownell {
151d8f388d8SDavid Brownell 	/* GPIO can never have been exported */
152d8f388d8SDavid Brownell 	WARN_ON(1);
153d8f388d8SDavid Brownell }
154d8f388d8SDavid Brownell 
1557560fa60SDavid Brownell static inline int gpio_to_irq(unsigned gpio)
1567560fa60SDavid Brownell {
1577560fa60SDavid Brownell 	/* GPIO can never have been requested or set as input */
1587560fa60SDavid Brownell 	WARN_ON(1);
1597560fa60SDavid Brownell 	return -EINVAL;
1607560fa60SDavid Brownell }
1617560fa60SDavid Brownell 
1627560fa60SDavid Brownell static inline int irq_to_gpio(unsigned irq)
1637560fa60SDavid Brownell {
1647560fa60SDavid Brownell 	/* irq can never have been returned from gpio_to_irq() */
1657560fa60SDavid Brownell 	WARN_ON(1);
1667560fa60SDavid Brownell 	return -EINVAL;
1677560fa60SDavid Brownell }
1687560fa60SDavid Brownell 
1697560fa60SDavid Brownell #endif
1707560fa60SDavid Brownell 
1717560fa60SDavid Brownell #endif /* __LINUX_GPIO_H */
172