blob: 6fc1c9e74854a58aa2a48dd80398eafbe11bd9e7 [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
Richard Genoudf7b370a2014-02-11 17:25:35 +01006/* see Documentation/gpio/gpio-legacy.txt */
David Brownell7560fa62008-03-04 14:28:27 -08007
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
Linus Walleij165adc92012-11-06 14:49:39 +010073#endif /* ! CONFIG_ARCH_HAVE_CUSTOM_GPIO_H */
David Brownell7560fa62008-03-04 14:28:27 -080074
Linus Walleij403c1d02013-10-25 12:59:05 +020075/* CONFIG_GPIOLIB: bindings for managed devices that want to request gpios */
76
77struct device;
78
79int devm_gpio_request(struct device *dev, unsigned gpio, const char *label);
80int devm_gpio_request_one(struct device *dev, unsigned gpio,
81 unsigned long flags, const char *label);
82void devm_gpio_free(struct device *dev, unsigned int gpio);
83
Alexandre Courbot76ec9d12013-03-28 04:34:56 -070084#else /* ! CONFIG_GPIOLIB */
David Brownell7560fa62008-03-04 14:28:27 -080085
Uwe Kleine-König3d599d12008-10-15 22:03:12 -070086#include <linux/kernel.h>
David Brownell6ea02052008-05-23 13:04:58 -070087#include <linux/types.h>
Paul Gortmaker187f1882011-11-23 20:12:59 -050088#include <linux/bug.h>
Christian Ruppert586a87e2013-10-15 15:37:54 +020089#include <linux/pinctrl/pinctrl.h>
David Brownell6ea02052008-05-23 13:04:58 -070090
Jani Nikulaa4177ee2009-09-22 16:46:33 -070091struct device;
Anton Vorontsov4e4438b2010-09-01 08:55:24 -060092struct gpio_chip;
Jani Nikulaa4177ee2009-09-22 16:46:33 -070093
Joe Perches3474cb32011-05-10 16:23:07 -070094static inline bool gpio_is_valid(int number)
David Brownell7560fa62008-03-04 14:28:27 -080095{
Joe Perches3474cb32011-05-10 16:23:07 -070096 return false;
David Brownell7560fa62008-03-04 14:28:27 -080097}
98
Linus Torvaldsd8a35152011-01-13 17:26:46 -080099static inline int gpio_request(unsigned gpio, const char *label)
David Brownell7560fa62008-03-04 14:28:27 -0800100{
101 return -ENOSYS;
102}
103
Wolfram Sang323b7fe2011-01-14 09:34:29 +0100104static inline int gpio_request_one(unsigned gpio,
Wolfram Sang5f829e42011-01-12 17:00:24 -0800105 unsigned long flags, const char *label)
106{
107 return -ENOSYS;
108}
109
Lars-Peter Clausen7c295972011-05-25 16:20:31 -0700110static inline int gpio_request_array(const struct gpio *array, size_t num)
Wolfram Sang5f829e42011-01-12 17:00:24 -0800111{
112 return -ENOSYS;
113}
114
David Brownell7560fa62008-03-04 14:28:27 -0800115static inline void gpio_free(unsigned gpio)
116{
Uwe Kleine-König3d599d12008-10-15 22:03:12 -0700117 might_sleep();
118
David Brownell7560fa62008-03-04 14:28:27 -0800119 /* GPIO can never have been requested */
120 WARN_ON(1);
121}
122
Lars-Peter Clausen7c295972011-05-25 16:20:31 -0700123static inline void gpio_free_array(const struct gpio *array, size_t num)
Wolfram Sang5f829e42011-01-12 17:00:24 -0800124{
125 might_sleep();
126
127 /* GPIO can never have been requested */
128 WARN_ON(1);
129}
130
Linus Torvaldsd8a35152011-01-13 17:26:46 -0800131static inline int gpio_direction_input(unsigned gpio)
David Brownell7560fa62008-03-04 14:28:27 -0800132{
133 return -ENOSYS;
134}
135
Linus Torvaldsd8a35152011-01-13 17:26:46 -0800136static inline int gpio_direction_output(unsigned gpio, int value)
David Brownell7560fa62008-03-04 14:28:27 -0800137{
138 return -ENOSYS;
139}
140
Felipe Balbic4b5be92010-05-26 14:42:23 -0700141static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
142{
143 return -ENOSYS;
144}
145
David Brownell7560fa62008-03-04 14:28:27 -0800146static inline int gpio_get_value(unsigned gpio)
147{
148 /* GPIO can never have been requested or set as {in,out}put */
149 WARN_ON(1);
150 return 0;
151}
152
153static inline void gpio_set_value(unsigned gpio, int value)
154{
155 /* GPIO can never have been requested or set as output */
156 WARN_ON(1);
157}
158
159static inline int gpio_cansleep(unsigned gpio)
160{
161 /* GPIO can never have been requested or set as {in,out}put */
162 WARN_ON(1);
163 return 0;
164}
165
166static inline int gpio_get_value_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 void gpio_set_value_cansleep(unsigned gpio, int value)
174{
175 /* GPIO can never have been requested or set as output */
176 WARN_ON(1);
177}
178
David Brownelld8f388d2008-07-25 01:46:07 -0700179static inline int gpio_export(unsigned gpio, bool direction_may_change)
180{
181 /* GPIO can never have been requested or set as {in,out}put */
182 WARN_ON(1);
183 return -EINVAL;
184}
185
Jani Nikulaa4177ee2009-09-22 16:46:33 -0700186static inline int gpio_export_link(struct device *dev, const char *name,
187 unsigned gpio)
188{
189 /* GPIO can never have been exported */
190 WARN_ON(1);
191 return -EINVAL;
192}
193
David Brownelld8f388d2008-07-25 01:46:07 -0700194static inline void gpio_unexport(unsigned gpio)
195{
196 /* GPIO can never have been exported */
197 WARN_ON(1);
198}
199
David Brownell7560fa62008-03-04 14:28:27 -0800200static inline int gpio_to_irq(unsigned gpio)
201{
202 /* GPIO can never have been requested or set as input */
203 WARN_ON(1);
204 return -EINVAL;
205}
206
Alexandre Courbote3a2e872014-10-23 17:27:07 +0900207static inline int gpiochip_lock_as_irq(struct gpio_chip *chip,
208 unsigned int offset)
Linus Walleijd468bf92013-09-24 11:54:38 +0200209{
210 WARN_ON(1);
211 return -EINVAL;
212}
213
Alexandre Courbote3a2e872014-10-23 17:27:07 +0900214static inline void gpiochip_unlock_as_irq(struct gpio_chip *chip,
215 unsigned int offset)
Linus Walleijd468bf92013-09-24 11:54:38 +0200216{
217 WARN_ON(1);
218}
219
Linus Walleij1e63d7b2012-11-06 16:03:35 +0100220static inline int
Linus Walleij165adc92012-11-06 14:49:39 +0100221gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name,
Linus Walleij316511c2012-11-21 08:48:09 +0100222 unsigned int gpio_offset, unsigned int pin_offset,
Linus Walleij3f0f8672012-11-20 12:40:15 +0100223 unsigned int npins)
Linus Walleij165adc92012-11-06 14:49:39 +0100224{
Linus Walleij50309a92012-11-06 17:16:39 +0100225 WARN_ON(1);
226 return -EINVAL;
Linus Walleij165adc92012-11-06 14:49:39 +0100227}
228
Christian Ruppert586a87e2013-10-15 15:37:54 +0200229static inline int
230gpiochip_add_pingroup_range(struct gpio_chip *chip,
231 struct pinctrl_dev *pctldev,
232 unsigned int gpio_offset, const char *pin_group)
233{
234 WARN_ON(1);
235 return -EINVAL;
236}
237
Linus Walleij165adc92012-11-06 14:49:39 +0100238static 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
Linus Walleij403c1d02013-10-25 12:59:05 +0200244static inline int devm_gpio_request(struct device *dev, unsigned gpio,
245 const char *label)
246{
247 WARN_ON(1);
248 return -EINVAL;
249}
250
251static inline int devm_gpio_request_one(struct device *dev, unsigned gpio,
252 unsigned long flags, const char *label)
253{
254 WARN_ON(1);
255 return -EINVAL;
256}
257
258static inline void devm_gpio_free(struct device *dev, unsigned int gpio)
259{
260 WARN_ON(1);
261}
262
Alexandre Courbot76ec9d12013-03-28 04:34:56 -0700263#endif /* ! CONFIG_GPIOLIB */
David Brownell7560fa62008-03-04 14:28:27 -0800264
David Brownell7560fa62008-03-04 14:28:27 -0800265#endif /* __LINUX_GPIO_H */