blob: c691df04445812c7ffae964be58d66c63e8ecaa6 [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
Alexandre Courbot79a9bec2013-10-17 10:21:36 -070019/* Gpio pin is active-low */
20#define GPIOF_ACTIVE_LOW (1 << 2)
21
Laxman Dewanganaca5ce12012-02-17 20:26:21 +053022/* Gpio pin is open drain */
Alexandre Courbot79a9bec2013-10-17 10:21:36 -070023#define GPIOF_OPEN_DRAIN (1 << 3)
Laxman Dewanganaca5ce12012-02-17 20:26:21 +053024
Laxman Dewangan25553ff2012-02-17 20:26:22 +053025/* Gpio pin is open source */
Alexandre Courbot79a9bec2013-10-17 10:21:36 -070026#define GPIOF_OPEN_SOURCE (1 << 4)
Laxman Dewangan25553ff2012-02-17 20:26:22 +053027
Alexandre Courbot79a9bec2013-10-17 10:21:36 -070028#define GPIOF_EXPORT (1 << 5)
29#define GPIOF_EXPORT_CHANGEABLE (1 << 6)
Wolfram Sangfc3a1f02011-12-13 18:34:01 +010030#define GPIOF_EXPORT_DIR_FIXED (GPIOF_EXPORT)
31#define GPIOF_EXPORT_DIR_CHANGEABLE (GPIOF_EXPORT | GPIOF_EXPORT_CHANGEABLE)
32
Mark Brownfeb83692011-10-24 15:24:10 +020033/**
34 * struct gpio - a structure describing a GPIO with configuration
35 * @gpio: the GPIO number
36 * @flags: GPIO configuration as specified by GPIOF_*
37 * @label: a literal description string of this GPIO
38 */
39struct gpio {
40 unsigned gpio;
41 unsigned long flags;
42 const char *label;
43};
44
Alexandre Courbot76ec9d12013-03-28 04:34:56 -070045#ifdef CONFIG_GPIOLIB
Mark Brown7563bbf2012-04-15 10:52:54 +010046
47#ifdef CONFIG_ARCH_HAVE_CUSTOM_GPIO_H
David Brownell7560fa62008-03-04 14:28:27 -080048#include <asm/gpio.h>
Mark Brown7563bbf2012-04-15 10:52:54 +010049#else
50
51#include <asm-generic/gpio.h>
52
53static inline int gpio_get_value(unsigned int gpio)
54{
55 return __gpio_get_value(gpio);
56}
57
58static inline void gpio_set_value(unsigned int gpio, int value)
59{
60 __gpio_set_value(gpio, value);
61}
62
63static inline int gpio_cansleep(unsigned int gpio)
64{
65 return __gpio_cansleep(gpio);
66}
67
68static inline int gpio_to_irq(unsigned int gpio)
69{
70 return __gpio_to_irq(gpio);
71}
72
73static inline int irq_to_gpio(unsigned int irq)
74{
75 return -EINVAL;
76}
77
Linus Walleij165adc92012-11-06 14:49:39 +010078#endif /* ! CONFIG_ARCH_HAVE_CUSTOM_GPIO_H */
David Brownell7560fa62008-03-04 14:28:27 -080079
Alexandre Courbot76ec9d12013-03-28 04:34:56 -070080#else /* ! CONFIG_GPIOLIB */
David Brownell7560fa62008-03-04 14:28:27 -080081
Uwe Kleine-König3d599d12008-10-15 22:03:12 -070082#include <linux/kernel.h>
David Brownell6ea02052008-05-23 13:04:58 -070083#include <linux/types.h>
84#include <linux/errno.h>
Paul Gortmaker187f1882011-11-23 20:12:59 -050085#include <linux/bug.h>
David Brownell6ea02052008-05-23 13:04:58 -070086
Jani Nikulaa4177ee2009-09-22 16:46:33 -070087struct device;
Anton Vorontsov4e4438b2010-09-01 08:55:24 -060088struct gpio_chip;
Jani Nikulaa4177ee2009-09-22 16:46:33 -070089
Joe Perches3474cb32011-05-10 16:23:07 -070090static inline bool gpio_is_valid(int number)
David Brownell7560fa62008-03-04 14:28:27 -080091{
Joe Perches3474cb32011-05-10 16:23:07 -070092 return false;
David Brownell7560fa62008-03-04 14:28:27 -080093}
94
Linus Torvaldsd8a35152011-01-13 17:26:46 -080095static inline int gpio_request(unsigned gpio, const char *label)
David Brownell7560fa62008-03-04 14:28:27 -080096{
97 return -ENOSYS;
98}
99
Wolfram Sang323b7fe2011-01-14 09:34:29 +0100100static inline int gpio_request_one(unsigned gpio,
Wolfram Sang5f829e42011-01-12 17:00:24 -0800101 unsigned long flags, const char *label)
102{
103 return -ENOSYS;
104}
105
Lars-Peter Clausen7c295972011-05-25 16:20:31 -0700106static inline int gpio_request_array(const struct gpio *array, size_t num)
Wolfram Sang5f829e42011-01-12 17:00:24 -0800107{
108 return -ENOSYS;
109}
110
David Brownell7560fa62008-03-04 14:28:27 -0800111static inline void gpio_free(unsigned gpio)
112{
Uwe Kleine-König3d599d12008-10-15 22:03:12 -0700113 might_sleep();
114
David Brownell7560fa62008-03-04 14:28:27 -0800115 /* GPIO can never have been requested */
116 WARN_ON(1);
117}
118
Lars-Peter Clausen7c295972011-05-25 16:20:31 -0700119static inline void gpio_free_array(const struct gpio *array, size_t num)
Wolfram Sang5f829e42011-01-12 17:00:24 -0800120{
121 might_sleep();
122
123 /* GPIO can never have been requested */
124 WARN_ON(1);
125}
126
Linus Torvaldsd8a35152011-01-13 17:26:46 -0800127static inline int gpio_direction_input(unsigned gpio)
David Brownell7560fa62008-03-04 14:28:27 -0800128{
129 return -ENOSYS;
130}
131
Linus Torvaldsd8a35152011-01-13 17:26:46 -0800132static inline int gpio_direction_output(unsigned gpio, int value)
David Brownell7560fa62008-03-04 14:28:27 -0800133{
134 return -ENOSYS;
135}
136
Felipe Balbic4b5be92010-05-26 14:42:23 -0700137static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
138{
139 return -ENOSYS;
140}
141
David Brownell7560fa62008-03-04 14:28:27 -0800142static inline int gpio_get_value(unsigned gpio)
143{
144 /* GPIO can never have been requested or set as {in,out}put */
145 WARN_ON(1);
146 return 0;
147}
148
149static inline void gpio_set_value(unsigned gpio, int value)
150{
151 /* GPIO can never have been requested or set as output */
152 WARN_ON(1);
153}
154
155static inline int gpio_cansleep(unsigned gpio)
156{
157 /* GPIO can never have been requested or set as {in,out}put */
158 WARN_ON(1);
159 return 0;
160}
161
162static inline int gpio_get_value_cansleep(unsigned gpio)
163{
164 /* GPIO can never have been requested or set as {in,out}put */
165 WARN_ON(1);
166 return 0;
167}
168
169static inline void gpio_set_value_cansleep(unsigned gpio, int value)
170{
171 /* GPIO can never have been requested or set as output */
172 WARN_ON(1);
173}
174
David Brownelld8f388d2008-07-25 01:46:07 -0700175static inline int gpio_export(unsigned gpio, bool direction_may_change)
176{
177 /* GPIO can never have been requested or set as {in,out}put */
178 WARN_ON(1);
179 return -EINVAL;
180}
181
Jani Nikulaa4177ee2009-09-22 16:46:33 -0700182static inline int gpio_export_link(struct device *dev, const char *name,
183 unsigned gpio)
184{
185 /* GPIO can never have been exported */
186 WARN_ON(1);
187 return -EINVAL;
188}
189
Jani Nikula07697462009-12-15 16:46:20 -0800190static inline int gpio_sysfs_set_active_low(unsigned gpio, int value)
191{
192 /* GPIO can never have been requested */
193 WARN_ON(1);
194 return -EINVAL;
195}
Jani Nikulaa4177ee2009-09-22 16:46:33 -0700196
David Brownelld8f388d2008-07-25 01:46:07 -0700197static inline void gpio_unexport(unsigned gpio)
198{
199 /* GPIO can never have been exported */
200 WARN_ON(1);
201}
202
David Brownell7560fa62008-03-04 14:28:27 -0800203static inline int gpio_to_irq(unsigned gpio)
204{
205 /* GPIO can never have been requested or set as input */
206 WARN_ON(1);
207 return -EINVAL;
208}
209
Linus Walleijd468bf92013-09-24 11:54:38 +0200210static inline int gpio_lock_as_irq(struct gpio_chip *chip, unsigned int offset)
211{
212 WARN_ON(1);
213 return -EINVAL;
214}
215
216static inline void gpio_unlock_as_irq(struct gpio_chip *chip,
217 unsigned int offset)
218{
219 WARN_ON(1);
220}
221
David Brownell7560fa62008-03-04 14:28:27 -0800222static inline int irq_to_gpio(unsigned irq)
223{
224 /* irq can never have been returned from gpio_to_irq() */
225 WARN_ON(1);
226 return -EINVAL;
227}
228
Linus Walleij1e63d7b2012-11-06 16:03:35 +0100229static inline int
Linus Walleij165adc92012-11-06 14:49:39 +0100230gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name,
Linus Walleij316511c2012-11-21 08:48:09 +0100231 unsigned int gpio_offset, unsigned int pin_offset,
Linus Walleij3f0f8672012-11-20 12:40:15 +0100232 unsigned int npins)
Linus Walleij165adc92012-11-06 14:49:39 +0100233{
Linus Walleij50309a92012-11-06 17:16:39 +0100234 WARN_ON(1);
235 return -EINVAL;
Linus Walleij165adc92012-11-06 14:49:39 +0100236}
237
238static inline void
239gpiochip_remove_pin_ranges(struct gpio_chip *chip)
240{
Linus Walleij50309a92012-11-06 17:16:39 +0100241 WARN_ON(1);
Linus Walleij165adc92012-11-06 14:49:39 +0100242}
243
Alexandre Courbot76ec9d12013-03-28 04:34:56 -0700244#endif /* ! CONFIG_GPIOLIB */
David Brownell7560fa62008-03-04 14:28:27 -0800245
Shawn Guo6a89a312013-01-18 15:57:46 +0800246struct device;
247
248/* bindings for managed devices that want to request gpios */
249int devm_gpio_request(struct device *dev, unsigned gpio, const char *label);
250int devm_gpio_request_one(struct device *dev, unsigned gpio,
251 unsigned long flags, const char *label);
252void devm_gpio_free(struct device *dev, unsigned int gpio);
253
David Brownell7560fa62008-03-04 14:28:27 -0800254#endif /* __LINUX_GPIO_H */