xref: /openbmc/linux/include/linux/gpio.h (revision aca5ce14)
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 
17aca5ce14SLaxman Dewangan /* Gpio pin is open drain */
18aca5ce14SLaxman Dewangan #define GPIOF_OPEN_DRAIN	(1 << 2)
19aca5ce14SLaxman Dewangan 
20feb83699SMark Brown /**
21feb83699SMark Brown  * struct gpio - a structure describing a GPIO with configuration
22feb83699SMark Brown  * @gpio:	the GPIO number
23feb83699SMark Brown  * @flags:	GPIO configuration as specified by GPIOF_*
24feb83699SMark Brown  * @label:	a literal description string of this GPIO
25feb83699SMark Brown  */
26feb83699SMark Brown struct gpio {
27feb83699SMark Brown 	unsigned	gpio;
28feb83699SMark Brown 	unsigned long	flags;
29feb83699SMark Brown 	const char	*label;
30feb83699SMark Brown };
31feb83699SMark Brown 
327560fa60SDavid Brownell #ifdef CONFIG_GENERIC_GPIO
337560fa60SDavid Brownell #include <asm/gpio.h>
347560fa60SDavid Brownell 
357560fa60SDavid Brownell #else
367560fa60SDavid Brownell 
373d599d1cSUwe Kleine-König #include <linux/kernel.h>
386ea0205bSDavid Brownell #include <linux/types.h>
396ea0205bSDavid Brownell #include <linux/errno.h>
406ea0205bSDavid Brownell 
41a4177ee7SJani Nikula struct device;
424e4438b8SAnton Vorontsov struct gpio_chip;
43a4177ee7SJani Nikula 
443474cb3cSJoe Perches static inline bool gpio_is_valid(int number)
457560fa60SDavid Brownell {
463474cb3cSJoe Perches 	return false;
477560fa60SDavid Brownell }
487560fa60SDavid Brownell 
49d8a3515eSLinus Torvalds static inline int gpio_request(unsigned gpio, const char *label)
507560fa60SDavid Brownell {
517560fa60SDavid Brownell 	return -ENOSYS;
527560fa60SDavid Brownell }
537560fa60SDavid Brownell 
54323b7fe8SWolfram Sang static inline int gpio_request_one(unsigned gpio,
555f829e40SWolfram Sang 					unsigned long flags, const char *label)
565f829e40SWolfram Sang {
575f829e40SWolfram Sang 	return -ENOSYS;
585f829e40SWolfram Sang }
595f829e40SWolfram Sang 
607c295975SLars-Peter Clausen static inline int gpio_request_array(const struct gpio *array, size_t num)
615f829e40SWolfram Sang {
625f829e40SWolfram Sang 	return -ENOSYS;
635f829e40SWolfram Sang }
645f829e40SWolfram Sang 
657560fa60SDavid Brownell static inline void gpio_free(unsigned gpio)
667560fa60SDavid Brownell {
673d599d1cSUwe Kleine-König 	might_sleep();
683d599d1cSUwe Kleine-König 
697560fa60SDavid Brownell 	/* GPIO can never have been requested */
707560fa60SDavid Brownell 	WARN_ON(1);
717560fa60SDavid Brownell }
727560fa60SDavid Brownell 
737c295975SLars-Peter Clausen static inline void gpio_free_array(const struct gpio *array, size_t num)
745f829e40SWolfram Sang {
755f829e40SWolfram Sang 	might_sleep();
765f829e40SWolfram Sang 
775f829e40SWolfram Sang 	/* GPIO can never have been requested */
785f829e40SWolfram Sang 	WARN_ON(1);
795f829e40SWolfram Sang }
805f829e40SWolfram Sang 
81d8a3515eSLinus Torvalds static inline int gpio_direction_input(unsigned gpio)
827560fa60SDavid Brownell {
837560fa60SDavid Brownell 	return -ENOSYS;
847560fa60SDavid Brownell }
857560fa60SDavid Brownell 
86d8a3515eSLinus Torvalds static inline int gpio_direction_output(unsigned gpio, int value)
877560fa60SDavid Brownell {
887560fa60SDavid Brownell 	return -ENOSYS;
897560fa60SDavid Brownell }
907560fa60SDavid Brownell 
91c4b5be98SFelipe Balbi static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
92c4b5be98SFelipe Balbi {
93c4b5be98SFelipe Balbi 	return -ENOSYS;
94c4b5be98SFelipe Balbi }
95c4b5be98SFelipe Balbi 
967560fa60SDavid Brownell static inline int gpio_get_value(unsigned gpio)
977560fa60SDavid Brownell {
987560fa60SDavid Brownell 	/* GPIO can never have been requested or set as {in,out}put */
997560fa60SDavid Brownell 	WARN_ON(1);
1007560fa60SDavid Brownell 	return 0;
1017560fa60SDavid Brownell }
1027560fa60SDavid Brownell 
1037560fa60SDavid Brownell static inline void gpio_set_value(unsigned gpio, int value)
1047560fa60SDavid Brownell {
1057560fa60SDavid Brownell 	/* GPIO can never have been requested or set as output */
1067560fa60SDavid Brownell 	WARN_ON(1);
1077560fa60SDavid Brownell }
1087560fa60SDavid Brownell 
1097560fa60SDavid Brownell static inline int gpio_cansleep(unsigned gpio)
1107560fa60SDavid Brownell {
1117560fa60SDavid Brownell 	/* GPIO can never have been requested or set as {in,out}put */
1127560fa60SDavid Brownell 	WARN_ON(1);
1137560fa60SDavid Brownell 	return 0;
1147560fa60SDavid Brownell }
1157560fa60SDavid Brownell 
1167560fa60SDavid Brownell static inline int gpio_get_value_cansleep(unsigned gpio)
1177560fa60SDavid Brownell {
1187560fa60SDavid Brownell 	/* GPIO can never have been requested or set as {in,out}put */
1197560fa60SDavid Brownell 	WARN_ON(1);
1207560fa60SDavid Brownell 	return 0;
1217560fa60SDavid Brownell }
1227560fa60SDavid Brownell 
1237560fa60SDavid Brownell static inline void gpio_set_value_cansleep(unsigned gpio, int value)
1247560fa60SDavid Brownell {
1257560fa60SDavid Brownell 	/* GPIO can never have been requested or set as output */
1267560fa60SDavid Brownell 	WARN_ON(1);
1277560fa60SDavid Brownell }
1287560fa60SDavid Brownell 
129d8f388d8SDavid Brownell static inline int gpio_export(unsigned gpio, bool direction_may_change)
130d8f388d8SDavid Brownell {
131d8f388d8SDavid Brownell 	/* GPIO can never have been requested or set as {in,out}put */
132d8f388d8SDavid Brownell 	WARN_ON(1);
133d8f388d8SDavid Brownell 	return -EINVAL;
134d8f388d8SDavid Brownell }
135d8f388d8SDavid Brownell 
136a4177ee7SJani Nikula static inline int gpio_export_link(struct device *dev, const char *name,
137a4177ee7SJani Nikula 				unsigned gpio)
138a4177ee7SJani Nikula {
139a4177ee7SJani Nikula 	/* GPIO can never have been exported */
140a4177ee7SJani Nikula 	WARN_ON(1);
141a4177ee7SJani Nikula 	return -EINVAL;
142a4177ee7SJani Nikula }
143a4177ee7SJani Nikula 
14407697461SJani Nikula static inline int gpio_sysfs_set_active_low(unsigned gpio, int value)
14507697461SJani Nikula {
14607697461SJani Nikula 	/* GPIO can never have been requested */
14707697461SJani Nikula 	WARN_ON(1);
14807697461SJani Nikula 	return -EINVAL;
14907697461SJani Nikula }
150a4177ee7SJani Nikula 
151d8f388d8SDavid Brownell static inline void gpio_unexport(unsigned gpio)
152d8f388d8SDavid Brownell {
153d8f388d8SDavid Brownell 	/* GPIO can never have been exported */
154d8f388d8SDavid Brownell 	WARN_ON(1);
155d8f388d8SDavid Brownell }
156d8f388d8SDavid Brownell 
1577560fa60SDavid Brownell static inline int gpio_to_irq(unsigned gpio)
1587560fa60SDavid Brownell {
1597560fa60SDavid Brownell 	/* GPIO can never have been requested or set as input */
1607560fa60SDavid Brownell 	WARN_ON(1);
1617560fa60SDavid Brownell 	return -EINVAL;
1627560fa60SDavid Brownell }
1637560fa60SDavid Brownell 
1647560fa60SDavid Brownell static inline int irq_to_gpio(unsigned irq)
1657560fa60SDavid Brownell {
1667560fa60SDavid Brownell 	/* irq can never have been returned from gpio_to_irq() */
1677560fa60SDavid Brownell 	WARN_ON(1);
1687560fa60SDavid Brownell 	return -EINVAL;
1697560fa60SDavid Brownell }
1707560fa60SDavid Brownell 
1717560fa60SDavid Brownell #endif
1727560fa60SDavid Brownell 
1737560fa60SDavid Brownell #endif /* __LINUX_GPIO_H */
174