blob: b8d0e53a802f0eacadcd44f4f3fba8ec1163eda5 [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
Laxman Dewanganf567fde22012-06-20 14:14:05 +053025#define GPIOF_EXPORT (1 << 4)
26#define GPIOF_EXPORT_CHANGEABLE (1 << 5)
Wolfram Sangfc3a1f02011-12-13 18:34:01 +010027#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
Alexandre Courbot76ec9d12013-03-28 04:34:56 -070042#ifdef CONFIG_GPIOLIB
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
Linus Walleij165adc92012-11-06 14:49:39 +010075#endif /* ! CONFIG_ARCH_HAVE_CUSTOM_GPIO_H */
David Brownell7560fa62008-03-04 14:28:27 -080076
Alexandre Courbot76ec9d12013-03-28 04:34:56 -070077#else /* ! CONFIG_GPIOLIB */
David Brownell7560fa62008-03-04 14:28:27 -080078
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>
Christian Ruppert586a87e2013-10-15 15:37:54 +020083#include <linux/pinctrl/pinctrl.h>
David Brownell6ea02052008-05-23 13:04:58 -070084
Jani Nikulaa4177ee2009-09-22 16:46:33 -070085struct device;
Anton Vorontsov4e4438b2010-09-01 08:55:24 -060086struct gpio_chip;
Jani Nikulaa4177ee2009-09-22 16:46:33 -070087
Joe Perches3474cb32011-05-10 16:23:07 -070088static inline bool gpio_is_valid(int number)
David Brownell7560fa62008-03-04 14:28:27 -080089{
Joe Perches3474cb32011-05-10 16:23:07 -070090 return false;
David Brownell7560fa62008-03-04 14:28:27 -080091}
92
Linus Torvaldsd8a35152011-01-13 17:26:46 -080093static inline int gpio_request(unsigned gpio, const char *label)
David Brownell7560fa62008-03-04 14:28:27 -080094{
95 return -ENOSYS;
96}
97
Wolfram Sang323b7fe2011-01-14 09:34:29 +010098static inline int gpio_request_one(unsigned gpio,
Wolfram Sang5f829e42011-01-12 17:00:24 -080099 unsigned long flags, const char *label)
100{
101 return -ENOSYS;
102}
103
Lars-Peter Clausen7c295972011-05-25 16:20:31 -0700104static inline int gpio_request_array(const struct gpio *array, size_t num)
Wolfram Sang5f829e42011-01-12 17:00:24 -0800105{
106 return -ENOSYS;
107}
108
David Brownell7560fa62008-03-04 14:28:27 -0800109static inline void gpio_free(unsigned gpio)
110{
Uwe Kleine-König3d599d12008-10-15 22:03:12 -0700111 might_sleep();
112
David Brownell7560fa62008-03-04 14:28:27 -0800113 /* GPIO can never have been requested */
114 WARN_ON(1);
115}
116
Lars-Peter Clausen7c295972011-05-25 16:20:31 -0700117static inline void gpio_free_array(const struct gpio *array, size_t num)
Wolfram Sang5f829e42011-01-12 17:00:24 -0800118{
119 might_sleep();
120
121 /* GPIO can never have been requested */
122 WARN_ON(1);
123}
124
Linus Torvaldsd8a35152011-01-13 17:26:46 -0800125static inline int gpio_direction_input(unsigned gpio)
David Brownell7560fa62008-03-04 14:28:27 -0800126{
127 return -ENOSYS;
128}
129
Linus Torvaldsd8a35152011-01-13 17:26:46 -0800130static inline int gpio_direction_output(unsigned gpio, int value)
David Brownell7560fa62008-03-04 14:28:27 -0800131{
132 return -ENOSYS;
133}
134
Felipe Balbic4b5be92010-05-26 14:42:23 -0700135static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
136{
137 return -ENOSYS;
138}
139
David Brownell7560fa62008-03-04 14:28:27 -0800140static inline int gpio_get_value(unsigned gpio)
141{
142 /* GPIO can never have been requested or set as {in,out}put */
143 WARN_ON(1);
144 return 0;
145}
146
147static inline void gpio_set_value(unsigned gpio, int value)
148{
149 /* GPIO can never have been requested or set as output */
150 WARN_ON(1);
151}
152
153static inline int gpio_cansleep(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 int gpio_get_value_cansleep(unsigned gpio)
161{
162 /* GPIO can never have been requested or set as {in,out}put */
163 WARN_ON(1);
164 return 0;
165}
166
167static inline void gpio_set_value_cansleep(unsigned gpio, int value)
168{
169 /* GPIO can never have been requested or set as output */
170 WARN_ON(1);
171}
172
David Brownelld8f388d82008-07-25 01:46:07 -0700173static inline int gpio_export(unsigned gpio, bool direction_may_change)
174{
175 /* GPIO can never have been requested or set as {in,out}put */
176 WARN_ON(1);
177 return -EINVAL;
178}
179
Jani Nikulaa4177ee2009-09-22 16:46:33 -0700180static inline int gpio_export_link(struct device *dev, const char *name,
181 unsigned gpio)
182{
183 /* GPIO can never have been exported */
184 WARN_ON(1);
185 return -EINVAL;
186}
187
Jani Nikula07697462009-12-15 16:46:20 -0800188static inline int gpio_sysfs_set_active_low(unsigned gpio, int value)
189{
190 /* GPIO can never have been requested */
191 WARN_ON(1);
192 return -EINVAL;
193}
Jani Nikulaa4177ee2009-09-22 16:46:33 -0700194
David Brownelld8f388d82008-07-25 01:46:07 -0700195static inline void gpio_unexport(unsigned gpio)
196{
197 /* GPIO can never have been exported */
198 WARN_ON(1);
199}
200
David Brownell7560fa62008-03-04 14:28:27 -0800201static inline int gpio_to_irq(unsigned gpio)
202{
203 /* GPIO can never have been requested or set as input */
204 WARN_ON(1);
205 return -EINVAL;
206}
207
208static inline int irq_to_gpio(unsigned irq)
209{
210 /* irq can never have been returned from gpio_to_irq() */
211 WARN_ON(1);
212 return -EINVAL;
213}
214
Linus Walleij1e63d7b2012-11-06 16:03:35 +0100215static inline int
Linus Walleij165adc92012-11-06 14:49:39 +0100216gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name,
Linus Walleij316511c2012-11-21 08:48:09 +0100217 unsigned int gpio_offset, unsigned int pin_offset,
Linus Walleij3f0f8672012-11-20 12:40:15 +0100218 unsigned int npins)
Linus Walleij165adc92012-11-06 14:49:39 +0100219{
Linus Walleij50309a92012-11-06 17:16:39 +0100220 WARN_ON(1);
221 return -EINVAL;
Linus Walleij165adc92012-11-06 14:49:39 +0100222}
223
Christian Ruppert586a87e2013-10-15 15:37:54 +0200224static inline int
225gpiochip_add_pingroup_range(struct gpio_chip *chip,
226 struct pinctrl_dev *pctldev,
227 unsigned int gpio_offset, const char *pin_group)
228{
229 WARN_ON(1);
230 return -EINVAL;
231}
232
Linus Walleij165adc92012-11-06 14:49:39 +0100233static inline void
234gpiochip_remove_pin_ranges(struct gpio_chip *chip)
235{
Linus Walleij50309a92012-11-06 17:16:39 +0100236 WARN_ON(1);
Linus Walleij165adc92012-11-06 14:49:39 +0100237}
238
Alexandre Courbot76ec9d12013-03-28 04:34:56 -0700239#endif /* ! CONFIG_GPIOLIB */
David Brownell7560fa62008-03-04 14:28:27 -0800240
Shawn Guo6a89a312013-01-18 15:57:46 +0800241struct device;
242
243/* bindings for managed devices that want to request gpios */
244int devm_gpio_request(struct device *dev, unsigned gpio, const char *label);
245int devm_gpio_request_one(struct device *dev, unsigned gpio,
246 unsigned long flags, const char *label);
247void devm_gpio_free(struct device *dev, unsigned int gpio);
248
David Brownell7560fa62008-03-04 14:28:27 -0800249#endif /* __LINUX_GPIO_H */