nlm: Ensure callback code also checks that the files match
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / include / linux / gpio.h
CommitLineData
7560fa60
DB
1#ifndef __LINUX_GPIO_H
2#define __LINUX_GPIO_H
3
7563bbf8
MB
4#include <linux/errno.h>
5
7560fa60
DB
6/* see Documentation/gpio.txt */
7
c001fb72
RD
8/* 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
aca5ce14
LD
19/* Gpio pin is open drain */
20#define GPIOF_OPEN_DRAIN (1 << 2)
21
25553ff0
LD
22/* Gpio pin is open source */
23#define GPIOF_OPEN_SOURCE (1 << 3)
24
f567fde2
LD
25#define GPIOF_EXPORT (1 << 4)
26#define GPIOF_EXPORT_CHANGEABLE (1 << 5)
fc3a1f04
WS
27#define GPIOF_EXPORT_DIR_FIXED (GPIOF_EXPORT)
28#define GPIOF_EXPORT_DIR_CHANGEABLE (GPIOF_EXPORT | GPIOF_EXPORT_CHANGEABLE)
29
feb83699
MB
30/**
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
76ec9d18 42#ifdef CONFIG_GPIOLIB
7563bbf8
MB
43
44#ifdef CONFIG_ARCH_HAVE_CUSTOM_GPIO_H
7560fa60 45#include <asm/gpio.h>
7563bbf8
MB
46#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
165adc9c 75#endif /* ! CONFIG_ARCH_HAVE_CUSTOM_GPIO_H */
7560fa60 76
76ec9d18 77#else /* ! CONFIG_GPIOLIB */
7560fa60 78
3d599d1c 79#include <linux/kernel.h>
6ea0205b
DB
80#include <linux/types.h>
81#include <linux/errno.h>
187f1882 82#include <linux/bug.h>
6ea0205b 83
a4177ee7 84struct device;
4e4438b8 85struct gpio_chip;
a4177ee7 86
3474cb3c 87static inline bool gpio_is_valid(int number)
7560fa60 88{
3474cb3c 89 return false;
7560fa60
DB
90}
91
d8a3515e 92static inline int gpio_request(unsigned gpio, const char *label)
7560fa60
DB
93{
94 return -ENOSYS;
95}
96
323b7fe8 97static inline int gpio_request_one(unsigned gpio,
5f829e40
WS
98 unsigned long flags, const char *label)
99{
100 return -ENOSYS;
101}
102
7c295975 103static inline int gpio_request_array(const struct gpio *array, size_t num)
5f829e40
WS
104{
105 return -ENOSYS;
106}
107
7560fa60
DB
108static inline void gpio_free(unsigned gpio)
109{
3d599d1c
UKK
110 might_sleep();
111
7560fa60 112 /* GPIO can never have been requested */
2c96922a
MB
113 WARN_ON(1);
114}
115
7c295975 116static inline void gpio_free_array(const struct gpio *array, size_t num)
5f829e40
WS
117{
118 might_sleep();
119
120 /* GPIO can never have been requested */
121 WARN_ON(1);
122}
123
d8a3515e 124static inline int gpio_direction_input(unsigned gpio)
7560fa60
DB
125{
126 return -ENOSYS;
127}
128
d8a3515e 129static inline int gpio_direction_output(unsigned gpio, int value)
7560fa60
DB
130{
131 return -ENOSYS;
132}
133
c4b5be98
FB
134static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
135{
136 return -ENOSYS;
137}
138
7560fa60
DB
139static inline int gpio_get_value(unsigned gpio)
140{
141 /* GPIO can never have been requested or set as {in,out}put */
142 WARN_ON(1);
143 return 0;
144}
145
146static inline void gpio_set_value(unsigned gpio, int value)
147{
148 /* GPIO can never have been requested or set as output */
149 WARN_ON(1);
150}
151
152static inline int gpio_cansleep(unsigned gpio)
153{
154 /* GPIO can never have been requested or set as {in,out}put */
155 WARN_ON(1);
156 return 0;
157}
158
159static inline int gpio_get_value_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 void gpio_set_value_cansleep(unsigned gpio, int value)
167{
168 /* GPIO can never have been requested or set as output */
169 WARN_ON(1);
170}
171
d8f388d8
DB
172static inline int gpio_export(unsigned gpio, bool direction_may_change)
173{
174 /* GPIO can never have been requested or set as {in,out}put */
175 WARN_ON(1);
176 return -EINVAL;
177}
178
a4177ee7
JN
179static inline int gpio_export_link(struct device *dev, const char *name,
180 unsigned gpio)
181{
182 /* GPIO can never have been exported */
183 WARN_ON(1);
184 return -EINVAL;
185}
186
07697461
JN
187static inline int gpio_sysfs_set_active_low(unsigned gpio, int value)
188{
189 /* GPIO can never have been requested */
190 WARN_ON(1);
191 return -EINVAL;
192}
a4177ee7 193
d8f388d8
DB
194static inline void gpio_unexport(unsigned gpio)
195{
196 /* GPIO can never have been exported */
197 WARN_ON(1);
198}
199
7560fa60
DB
200static 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
207static inline int irq_to_gpio(unsigned irq)
208{
209 /* irq can never have been returned from gpio_to_irq() */
210 WARN_ON(1);
211 return -EINVAL;
212}
213
1e63d7b9 214static inline int
165adc9c 215gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name,
316511c0 216 unsigned int gpio_offset, unsigned int pin_offset,
3f0f8670 217 unsigned int npins)
165adc9c 218{
50309a9c
LW
219 WARN_ON(1);
220 return -EINVAL;
165adc9c
LW
221}
222
223static inline void
224gpiochip_remove_pin_ranges(struct gpio_chip *chip)
225{
50309a9c 226 WARN_ON(1);
165adc9c
LW
227}
228
76ec9d18 229#endif /* ! CONFIG_GPIOLIB */
7560fa60 230
6a89a314
SG
231struct device;
232
233/* bindings for managed devices that want to request gpios */
234int devm_gpio_request(struct device *dev, unsigned gpio, const char *label);
235int devm_gpio_request_one(struct device *dev, unsigned gpio,
236 unsigned long flags, const char *label);
237void devm_gpio_free(struct device *dev, unsigned int gpio);
238
7560fa60 239#endif /* __LINUX_GPIO_H */