blob: 7a8816a1a0d8a29e79656dc7db3979844110deb2 [file] [log] [blame]
David Brownell7560fa62008-03-04 14:28:27 -08001#ifndef __LINUX_GPIO_H
2#define __LINUX_GPIO_H
3
Mark Brown7563bbf2012-04-15 10:52:54 +01004#include <linux/errno.h>
5
David Brownell7560fa62008-03-04 14:28:27 -08006/* see Documentation/gpio.txt */
7
Randy Dunlapc001fb72011-06-14 17:05:11 -07008/* make these flag values available regardless of GPIO kconfig options */
9#define GPIOF_DIR_OUT (0 << 0)
10#define GPIOF_DIR_IN (1 << 0)
11
12#define GPIOF_INIT_LOW (0 << 1)
13#define GPIOF_INIT_HIGH (1 << 1)
14
15#define GPIOF_IN (GPIOF_DIR_IN)
16#define GPIOF_OUT_INIT_LOW (GPIOF_DIR_OUT | GPIOF_INIT_LOW)
17#define GPIOF_OUT_INIT_HIGH (GPIOF_DIR_OUT | GPIOF_INIT_HIGH)
18
Laxman Dewanganaca5ce12012-02-17 20:26:21 +053019/* Gpio pin is open drain */
20#define GPIOF_OPEN_DRAIN (1 << 2)
21
Laxman Dewangan25553ff2012-02-17 20:26:22 +053022/* Gpio pin is open source */
23#define GPIOF_OPEN_SOURCE (1 << 3)
24
Wolfram Sangfc3a1f02011-12-13 18:34:01 +010025#define GPIOF_EXPORT (1 << 2)
26#define GPIOF_EXPORT_CHANGEABLE (1 << 3)
27#define GPIOF_EXPORT_DIR_FIXED (GPIOF_EXPORT)
28#define GPIOF_EXPORT_DIR_CHANGEABLE (GPIOF_EXPORT | GPIOF_EXPORT_CHANGEABLE)
29
Mark Brownfeb83692011-10-24 15:24:10 +020030/**
31 * struct gpio - a structure describing a GPIO with configuration
32 * @gpio: the GPIO number
33 * @flags: GPIO configuration as specified by GPIOF_*
34 * @label: a literal description string of this GPIO
35 */
36struct gpio {
37 unsigned gpio;
38 unsigned long flags;
39 const char *label;
40};
41
David Brownell7560fa62008-03-04 14:28:27 -080042#ifdef CONFIG_GENERIC_GPIO
Mark Brown7563bbf2012-04-15 10:52:54 +010043
44#ifdef CONFIG_ARCH_HAVE_CUSTOM_GPIO_H
David Brownell7560fa62008-03-04 14:28:27 -080045#include <asm/gpio.h>
Mark Brown7563bbf2012-04-15 10:52:54 +010046#else
47
48#include <asm-generic/gpio.h>
49
50static inline int gpio_get_value(unsigned int gpio)
51{
52 return __gpio_get_value(gpio);
53}
54
55static inline void gpio_set_value(unsigned int gpio, int value)
56{
57 __gpio_set_value(gpio, value);
58}
59
60static inline int gpio_cansleep(unsigned int gpio)
61{
62 return __gpio_cansleep(gpio);
63}
64
65static inline int gpio_to_irq(unsigned int gpio)
66{
67 return __gpio_to_irq(gpio);
68}
69
70static inline int irq_to_gpio(unsigned int irq)
71{
72 return -EINVAL;
73}
74
75#endif
David Brownell7560fa62008-03-04 14:28:27 -080076
77#else
78
Uwe Kleine-König3d599d12008-10-15 22:03:12 -070079#include <linux/kernel.h>
David Brownell6ea02052008-05-23 13:04:58 -070080#include <linux/types.h>
81#include <linux/errno.h>
Paul Gortmaker187f1882011-11-23 20:12:59 -050082#include <linux/bug.h>
David Brownell6ea02052008-05-23 13:04:58 -070083
Jani Nikulaa4177ee2009-09-22 16:46:33 -070084struct device;
Anton Vorontsov4e4438b2010-09-01 08:55:24 -060085struct gpio_chip;
Jani Nikulaa4177ee2009-09-22 16:46:33 -070086
Joe Perches3474cb32011-05-10 16:23:07 -070087static inline bool gpio_is_valid(int number)
David Brownell7560fa62008-03-04 14:28:27 -080088{
Joe Perches3474cb32011-05-10 16:23:07 -070089 return false;
David Brownell7560fa62008-03-04 14:28:27 -080090}
91
Linus Torvaldsd8a35152011-01-13 17:26:46 -080092static inline int gpio_request(unsigned gpio, const char *label)
David Brownell7560fa62008-03-04 14:28:27 -080093{
94 return -ENOSYS;
95}
96
Mark Brown2c969222012-04-04 16:14:48 +010097static inline int devm_gpio_request(struct device *dev, unsigned gpio,
98 const char *label)
99{
100 return -ENOSYS;
101}
102
Wolfram Sang323b7fe2011-01-14 09:34:29 +0100103static inline int gpio_request_one(unsigned gpio,
Wolfram Sang5f829e42011-01-12 17:00:24 -0800104 unsigned long flags, const char *label)
105{
106 return -ENOSYS;
107}
108
Lars-Peter Clausen7c295972011-05-25 16:20:31 -0700109static inline int gpio_request_array(const struct gpio *array, size_t num)
Wolfram Sang5f829e42011-01-12 17:00:24 -0800110{
111 return -ENOSYS;
112}
113
David Brownell7560fa62008-03-04 14:28:27 -0800114static inline void gpio_free(unsigned gpio)
115{
Uwe Kleine-König3d599d12008-10-15 22:03:12 -0700116 might_sleep();
117
David Brownell7560fa62008-03-04 14:28:27 -0800118 /* GPIO can never have been requested */
119 WARN_ON(1);
120}
121
Mark Brown2c969222012-04-04 16:14:48 +0100122static inline void devm_gpio_free(struct device *dev, unsigned gpio)
123{
124 might_sleep();
125
126 /* GPIO can never have been requested */
127 WARN_ON(1);
128}
129
Lars-Peter Clausen7c295972011-05-25 16:20:31 -0700130static inline void gpio_free_array(const struct gpio *array, size_t num)
Wolfram Sang5f829e42011-01-12 17:00:24 -0800131{
132 might_sleep();
133
134 /* GPIO can never have been requested */
135 WARN_ON(1);
136}
137
Linus Torvaldsd8a35152011-01-13 17:26:46 -0800138static inline int gpio_direction_input(unsigned gpio)
David Brownell7560fa62008-03-04 14:28:27 -0800139{
140 return -ENOSYS;
141}
142
Linus Torvaldsd8a35152011-01-13 17:26:46 -0800143static inline int gpio_direction_output(unsigned gpio, int value)
David Brownell7560fa62008-03-04 14:28:27 -0800144{
145 return -ENOSYS;
146}
147
Felipe Balbic4b5be92010-05-26 14:42:23 -0700148static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
149{
150 return -ENOSYS;
151}
152
David Brownell7560fa62008-03-04 14:28:27 -0800153static inline int gpio_get_value(unsigned gpio)
154{
155 /* GPIO can never have been requested or set as {in,out}put */
156 WARN_ON(1);
157 return 0;
158}
159
160static inline void gpio_set_value(unsigned gpio, int value)
161{
162 /* GPIO can never have been requested or set as output */
163 WARN_ON(1);
164}
165
166static inline int gpio_cansleep(unsigned gpio)
167{
168 /* GPIO can never have been requested or set as {in,out}put */
169 WARN_ON(1);
170 return 0;
171}
172
173static inline int gpio_get_value_cansleep(unsigned gpio)
174{
175 /* GPIO can never have been requested or set as {in,out}put */
176 WARN_ON(1);
177 return 0;
178}
179
180static inline void gpio_set_value_cansleep(unsigned gpio, int value)
181{
182 /* GPIO can never have been requested or set as output */
183 WARN_ON(1);
184}
185
David Brownelld8f388d82008-07-25 01:46:07 -0700186static inline int gpio_export(unsigned gpio, bool direction_may_change)
187{
188 /* GPIO can never have been requested or set as {in,out}put */
189 WARN_ON(1);
190 return -EINVAL;
191}
192
Jani Nikulaa4177ee2009-09-22 16:46:33 -0700193static inline int gpio_export_link(struct device *dev, const char *name,
194 unsigned gpio)
195{
196 /* GPIO can never have been exported */
197 WARN_ON(1);
198 return -EINVAL;
199}
200
Jani Nikula07697462009-12-15 16:46:20 -0800201static inline int gpio_sysfs_set_active_low(unsigned gpio, int value)
202{
203 /* GPIO can never have been requested */
204 WARN_ON(1);
205 return -EINVAL;
206}
Jani Nikulaa4177ee2009-09-22 16:46:33 -0700207
David Brownelld8f388d82008-07-25 01:46:07 -0700208static inline void gpio_unexport(unsigned gpio)
209{
210 /* GPIO can never have been exported */
211 WARN_ON(1);
212}
213
David Brownell7560fa62008-03-04 14:28:27 -0800214static inline int gpio_to_irq(unsigned gpio)
215{
216 /* GPIO can never have been requested or set as input */
217 WARN_ON(1);
218 return -EINVAL;
219}
220
221static inline int irq_to_gpio(unsigned irq)
222{
223 /* irq can never have been returned from gpio_to_irq() */
224 WARN_ON(1);
225 return -EINVAL;
226}
227
228#endif
229
230#endif /* __LINUX_GPIO_H */