]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/linux/gpio.h
gpiolib: devres: add missing headers
[mirror_ubuntu-bionic-kernel.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
79a9becd
AC
19/* Gpio pin is active-low */
20#define GPIOF_ACTIVE_LOW (1 << 2)
21
aca5ce14 22/* Gpio pin is open drain */
79a9becd 23#define GPIOF_OPEN_DRAIN (1 << 3)
aca5ce14 24
25553ff0 25/* Gpio pin is open source */
79a9becd 26#define GPIOF_OPEN_SOURCE (1 << 4)
25553ff0 27
79a9becd
AC
28#define GPIOF_EXPORT (1 << 5)
29#define GPIOF_EXPORT_CHANGEABLE (1 << 6)
fc3a1f04
WS
30#define GPIOF_EXPORT_DIR_FIXED (GPIOF_EXPORT)
31#define GPIOF_EXPORT_DIR_CHANGEABLE (GPIOF_EXPORT | GPIOF_EXPORT_CHANGEABLE)
32
feb83699
MB
33/**
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
76ec9d18 45#ifdef CONFIG_GPIOLIB
7563bbf8
MB
46
47#ifdef CONFIG_ARCH_HAVE_CUSTOM_GPIO_H
7560fa60 48#include <asm/gpio.h>
7563bbf8
MB
49#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
165adc9c 78#endif /* ! CONFIG_ARCH_HAVE_CUSTOM_GPIO_H */
7560fa60 79
76ec9d18 80#else /* ! CONFIG_GPIOLIB */
7560fa60 81
3d599d1c 82#include <linux/kernel.h>
6ea0205b
DB
83#include <linux/types.h>
84#include <linux/errno.h>
187f1882 85#include <linux/bug.h>
6ea0205b 86
a4177ee7 87struct device;
4e4438b8 88struct gpio_chip;
a4177ee7 89
3474cb3c 90static inline bool gpio_is_valid(int number)
7560fa60 91{
3474cb3c 92 return false;
7560fa60
DB
93}
94
d8a3515e 95static inline int gpio_request(unsigned gpio, const char *label)
7560fa60
DB
96{
97 return -ENOSYS;
98}
99
323b7fe8 100static inline int gpio_request_one(unsigned gpio,
5f829e40
WS
101 unsigned long flags, const char *label)
102{
103 return -ENOSYS;
104}
105
7c295975 106static inline int gpio_request_array(const struct gpio *array, size_t num)
5f829e40
WS
107{
108 return -ENOSYS;
109}
110
7560fa60
DB
111static inline void gpio_free(unsigned gpio)
112{
3d599d1c
UKK
113 might_sleep();
114
7560fa60 115 /* GPIO can never have been requested */
2c96922a
MB
116 WARN_ON(1);
117}
118
7c295975 119static inline void gpio_free_array(const struct gpio *array, size_t num)
5f829e40
WS
120{
121 might_sleep();
122
123 /* GPIO can never have been requested */
124 WARN_ON(1);
125}
126
d8a3515e 127static inline int gpio_direction_input(unsigned gpio)
7560fa60
DB
128{
129 return -ENOSYS;
130}
131
d8a3515e 132static inline int gpio_direction_output(unsigned gpio, int value)
7560fa60
DB
133{
134 return -ENOSYS;
135}
136
c4b5be98
FB
137static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
138{
139 return -ENOSYS;
140}
141
7560fa60
DB
142static 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
d8f388d8
DB
175static 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
a4177ee7
JN
182static 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
07697461
JN
190static 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}
a4177ee7 196
d8f388d8
DB
197static inline void gpio_unexport(unsigned gpio)
198{
199 /* GPIO can never have been exported */
200 WARN_ON(1);
201}
202
7560fa60
DB
203static 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
d468bf9e
LW
210static 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
7560fa60
DB
222static 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
1e63d7b9 229static inline int
165adc9c 230gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name,
316511c0 231 unsigned int gpio_offset, unsigned int pin_offset,
3f0f8670 232 unsigned int npins)
165adc9c 233{
50309a9c
LW
234 WARN_ON(1);
235 return -EINVAL;
165adc9c
LW
236}
237
238static inline void
239gpiochip_remove_pin_ranges(struct gpio_chip *chip)
240{
50309a9c 241 WARN_ON(1);
165adc9c
LW
242}
243
76ec9d18 244#endif /* ! CONFIG_GPIOLIB */
7560fa60 245
6a89a314
SG
246struct 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
7560fa60 254#endif /* __LINUX_GPIO_H */