blob: af511a682925aa342d5a62674a191085bc2352f5 [file] [log] [blame]
David Brownell7560fa62008-03-04 14:28:27 -08001#ifndef __LINUX_GPIO_H
2#define __LINUX_GPIO_H
3
4/* see Documentation/gpio.txt */
5
Randy Dunlapc001fb72011-06-14 17:05:11 -07006/* make these flag values available regardless of GPIO kconfig options */
7#define GPIOF_DIR_OUT (0 << 0)
8#define GPIOF_DIR_IN (1 << 0)
9
10#define GPIOF_INIT_LOW (0 << 1)
11#define GPIOF_INIT_HIGH (1 << 1)
12
13#define GPIOF_IN (GPIOF_DIR_IN)
14#define GPIOF_OUT_INIT_LOW (GPIOF_DIR_OUT | GPIOF_INIT_LOW)
15#define GPIOF_OUT_INIT_HIGH (GPIOF_DIR_OUT | GPIOF_INIT_HIGH)
16
Laxman Dewanganaca5ce12012-02-17 20:26:21 +053017/* Gpio pin is open drain */
18#define GPIOF_OPEN_DRAIN (1 << 2)
19
Laxman Dewangan25553ff2012-02-17 20:26:22 +053020/* Gpio pin is open source */
21#define GPIOF_OPEN_SOURCE (1 << 3)
22
Wolfram Sangfc3a1f02011-12-13 18:34:01 +010023#define GPIOF_EXPORT (1 << 2)
24#define GPIOF_EXPORT_CHANGEABLE (1 << 3)
25#define GPIOF_EXPORT_DIR_FIXED (GPIOF_EXPORT)
26#define GPIOF_EXPORT_DIR_CHANGEABLE (GPIOF_EXPORT | GPIOF_EXPORT_CHANGEABLE)
27
Mark Brownfeb83692011-10-24 15:24:10 +020028/**
29 * struct gpio - a structure describing a GPIO with configuration
30 * @gpio: the GPIO number
31 * @flags: GPIO configuration as specified by GPIOF_*
32 * @label: a literal description string of this GPIO
33 */
34struct gpio {
35 unsigned gpio;
36 unsigned long flags;
37 const char *label;
38};
39
David Brownell7560fa62008-03-04 14:28:27 -080040#ifdef CONFIG_GENERIC_GPIO
41#include <asm/gpio.h>
42
43#else
44
Uwe Kleine-König3d599d12008-10-15 22:03:12 -070045#include <linux/kernel.h>
David Brownell6ea02052008-05-23 13:04:58 -070046#include <linux/types.h>
47#include <linux/errno.h>
Paul Gortmaker187f1882011-11-23 20:12:59 -050048#include <linux/bug.h>
David Brownell6ea02052008-05-23 13:04:58 -070049
Jani Nikulaa4177ee2009-09-22 16:46:33 -070050struct device;
Anton Vorontsov4e4438b2010-09-01 08:55:24 -060051struct gpio_chip;
Jani Nikulaa4177ee2009-09-22 16:46:33 -070052
Joe Perches3474cb32011-05-10 16:23:07 -070053static inline bool gpio_is_valid(int number)
David Brownell7560fa62008-03-04 14:28:27 -080054{
Joe Perches3474cb32011-05-10 16:23:07 -070055 return false;
David Brownell7560fa62008-03-04 14:28:27 -080056}
57
Linus Torvaldsd8a35152011-01-13 17:26:46 -080058static inline int gpio_request(unsigned gpio, const char *label)
David Brownell7560fa62008-03-04 14:28:27 -080059{
60 return -ENOSYS;
61}
62
Wolfram Sang323b7fe2011-01-14 09:34:29 +010063static inline int gpio_request_one(unsigned gpio,
Wolfram Sang5f829e42011-01-12 17:00:24 -080064 unsigned long flags, const char *label)
65{
66 return -ENOSYS;
67}
68
Lars-Peter Clausen7c295972011-05-25 16:20:31 -070069static inline int gpio_request_array(const struct gpio *array, size_t num)
Wolfram Sang5f829e42011-01-12 17:00:24 -080070{
71 return -ENOSYS;
72}
73
David Brownell7560fa62008-03-04 14:28:27 -080074static inline void gpio_free(unsigned gpio)
75{
Uwe Kleine-König3d599d12008-10-15 22:03:12 -070076 might_sleep();
77
David Brownell7560fa62008-03-04 14:28:27 -080078 /* GPIO can never have been requested */
79 WARN_ON(1);
80}
81
Lars-Peter Clausen7c295972011-05-25 16:20:31 -070082static inline void gpio_free_array(const struct gpio *array, size_t num)
Wolfram Sang5f829e42011-01-12 17:00:24 -080083{
84 might_sleep();
85
86 /* GPIO can never have been requested */
87 WARN_ON(1);
88}
89
Linus Torvaldsd8a35152011-01-13 17:26:46 -080090static inline int gpio_direction_input(unsigned gpio)
David Brownell7560fa62008-03-04 14:28:27 -080091{
92 return -ENOSYS;
93}
94
Linus Torvaldsd8a35152011-01-13 17:26:46 -080095static inline int gpio_direction_output(unsigned gpio, int value)
David Brownell7560fa62008-03-04 14:28:27 -080096{
97 return -ENOSYS;
98}
99
Felipe Balbic4b5be92010-05-26 14:42:23 -0700100static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
101{
102 return -ENOSYS;
103}
104
David Brownell7560fa62008-03-04 14:28:27 -0800105static inline int gpio_get_value(unsigned gpio)
106{
107 /* GPIO can never have been requested or set as {in,out}put */
108 WARN_ON(1);
109 return 0;
110}
111
112static inline void gpio_set_value(unsigned gpio, int value)
113{
114 /* GPIO can never have been requested or set as output */
115 WARN_ON(1);
116}
117
118static inline int gpio_cansleep(unsigned gpio)
119{
120 /* GPIO can never have been requested or set as {in,out}put */
121 WARN_ON(1);
122 return 0;
123}
124
125static inline int gpio_get_value_cansleep(unsigned gpio)
126{
127 /* GPIO can never have been requested or set as {in,out}put */
128 WARN_ON(1);
129 return 0;
130}
131
132static inline void gpio_set_value_cansleep(unsigned gpio, int value)
133{
134 /* GPIO can never have been requested or set as output */
135 WARN_ON(1);
136}
137
David Brownelld8f388d82008-07-25 01:46:07 -0700138static inline int gpio_export(unsigned gpio, bool direction_may_change)
139{
140 /* GPIO can never have been requested or set as {in,out}put */
141 WARN_ON(1);
142 return -EINVAL;
143}
144
Jani Nikulaa4177ee2009-09-22 16:46:33 -0700145static inline int gpio_export_link(struct device *dev, const char *name,
146 unsigned gpio)
147{
148 /* GPIO can never have been exported */
149 WARN_ON(1);
150 return -EINVAL;
151}
152
Jani Nikula07697462009-12-15 16:46:20 -0800153static inline int gpio_sysfs_set_active_low(unsigned gpio, int value)
154{
155 /* GPIO can never have been requested */
156 WARN_ON(1);
157 return -EINVAL;
158}
Jani Nikulaa4177ee2009-09-22 16:46:33 -0700159
David Brownelld8f388d82008-07-25 01:46:07 -0700160static inline void gpio_unexport(unsigned gpio)
161{
162 /* GPIO can never have been exported */
163 WARN_ON(1);
164}
165
David Brownell7560fa62008-03-04 14:28:27 -0800166static inline int gpio_to_irq(unsigned gpio)
167{
168 /* GPIO can never have been requested or set as input */
169 WARN_ON(1);
170 return -EINVAL;
171}
172
173static inline int irq_to_gpio(unsigned irq)
174{
175 /* irq can never have been returned from gpio_to_irq() */
176 WARN_ON(1);
177 return -EINVAL;
178}
179
180#endif
181
182#endif /* __LINUX_GPIO_H */