]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/linux/gpio.h
rhashtable: Mark internal/private inline functions as such
[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
f7b370a3 6/* see Documentation/gpio/gpio-legacy.txt */
7560fa60 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
403c1d0b
LW
80/* CONFIG_GPIOLIB: bindings for managed devices that want to request gpios */
81
82struct device;
83
84int devm_gpio_request(struct device *dev, unsigned gpio, const char *label);
85int devm_gpio_request_one(struct device *dev, unsigned gpio,
86 unsigned long flags, const char *label);
87void devm_gpio_free(struct device *dev, unsigned int gpio);
88
76ec9d18 89#else /* ! CONFIG_GPIOLIB */
7560fa60 90
3d599d1c 91#include <linux/kernel.h>
6ea0205b 92#include <linux/types.h>
187f1882 93#include <linux/bug.h>
586a87e6 94#include <linux/pinctrl/pinctrl.h>
6ea0205b 95
a4177ee7 96struct device;
4e4438b8 97struct gpio_chip;
a4177ee7 98
3474cb3c 99static inline bool gpio_is_valid(int number)
7560fa60 100{
3474cb3c 101 return false;
7560fa60
DB
102}
103
d8a3515e 104static inline int gpio_request(unsigned gpio, const char *label)
7560fa60
DB
105{
106 return -ENOSYS;
107}
108
323b7fe8 109static inline int gpio_request_one(unsigned gpio,
5f829e40
WS
110 unsigned long flags, const char *label)
111{
112 return -ENOSYS;
113}
114
7c295975 115static inline int gpio_request_array(const struct gpio *array, size_t num)
5f829e40
WS
116{
117 return -ENOSYS;
118}
119
7560fa60
DB
120static inline void gpio_free(unsigned gpio)
121{
3d599d1c
UKK
122 might_sleep();
123
7560fa60 124 /* GPIO can never have been requested */
2c96922a
MB
125 WARN_ON(1);
126}
127
7c295975 128static inline void gpio_free_array(const struct gpio *array, size_t num)
5f829e40
WS
129{
130 might_sleep();
131
132 /* GPIO can never have been requested */
133 WARN_ON(1);
134}
135
d8a3515e 136static inline int gpio_direction_input(unsigned gpio)
7560fa60
DB
137{
138 return -ENOSYS;
139}
140
d8a3515e 141static inline int gpio_direction_output(unsigned gpio, int value)
7560fa60
DB
142{
143 return -ENOSYS;
144}
145
c4b5be98
FB
146static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
147{
148 return -ENOSYS;
149}
150
7560fa60
DB
151static inline int gpio_get_value(unsigned gpio)
152{
153 /* GPIO can never have been requested or set as {in,out}put */
154 WARN_ON(1);
155 return 0;
156}
157
158static inline void gpio_set_value(unsigned gpio, int value)
159{
160 /* GPIO can never have been requested or set as output */
161 WARN_ON(1);
162}
163
164static inline int gpio_cansleep(unsigned gpio)
165{
166 /* GPIO can never have been requested or set as {in,out}put */
167 WARN_ON(1);
168 return 0;
169}
170
171static inline int gpio_get_value_cansleep(unsigned gpio)
172{
173 /* GPIO can never have been requested or set as {in,out}put */
174 WARN_ON(1);
175 return 0;
176}
177
178static inline void gpio_set_value_cansleep(unsigned gpio, int value)
179{
180 /* GPIO can never have been requested or set as output */
181 WARN_ON(1);
182}
183
d8f388d8
DB
184static inline int gpio_export(unsigned gpio, bool direction_may_change)
185{
186 /* GPIO can never have been requested or set as {in,out}put */
187 WARN_ON(1);
188 return -EINVAL;
189}
190
a4177ee7
JN
191static inline int gpio_export_link(struct device *dev, const char *name,
192 unsigned gpio)
193{
194 /* GPIO can never have been exported */
195 WARN_ON(1);
196 return -EINVAL;
197}
198
07697461
JN
199static inline int gpio_sysfs_set_active_low(unsigned gpio, int value)
200{
201 /* GPIO can never have been requested */
202 WARN_ON(1);
203 return -EINVAL;
204}
a4177ee7 205
d8f388d8
DB
206static inline void gpio_unexport(unsigned gpio)
207{
208 /* GPIO can never have been exported */
209 WARN_ON(1);
210}
211
7560fa60
DB
212static inline int gpio_to_irq(unsigned gpio)
213{
214 /* GPIO can never have been requested or set as input */
215 WARN_ON(1);
216 return -EINVAL;
217}
218
e3a2e878
AC
219static inline int gpiochip_lock_as_irq(struct gpio_chip *chip,
220 unsigned int offset)
d468bf9e
LW
221{
222 WARN_ON(1);
223 return -EINVAL;
224}
225
e3a2e878
AC
226static inline void gpiochip_unlock_as_irq(struct gpio_chip *chip,
227 unsigned int offset)
d468bf9e
LW
228{
229 WARN_ON(1);
230}
231
7560fa60
DB
232static inline int irq_to_gpio(unsigned irq)
233{
234 /* irq can never have been returned from gpio_to_irq() */
235 WARN_ON(1);
236 return -EINVAL;
237}
238
1e63d7b9 239static inline int
165adc9c 240gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name,
316511c0 241 unsigned int gpio_offset, unsigned int pin_offset,
3f0f8670 242 unsigned int npins)
165adc9c 243{
50309a9c
LW
244 WARN_ON(1);
245 return -EINVAL;
165adc9c
LW
246}
247
586a87e6
CR
248static inline int
249gpiochip_add_pingroup_range(struct gpio_chip *chip,
250 struct pinctrl_dev *pctldev,
251 unsigned int gpio_offset, const char *pin_group)
252{
253 WARN_ON(1);
254 return -EINVAL;
255}
256
165adc9c
LW
257static inline void
258gpiochip_remove_pin_ranges(struct gpio_chip *chip)
259{
50309a9c 260 WARN_ON(1);
165adc9c
LW
261}
262
403c1d0b
LW
263static inline int devm_gpio_request(struct device *dev, unsigned gpio,
264 const char *label)
265{
266 WARN_ON(1);
267 return -EINVAL;
268}
7560fa60 269
403c1d0b
LW
270static inline int devm_gpio_request_one(struct device *dev, unsigned gpio,
271 unsigned long flags, const char *label)
272{
273 WARN_ON(1);
274 return -EINVAL;
275}
6a89a314 276
403c1d0b
LW
277static inline void devm_gpio_free(struct device *dev, unsigned int gpio)
278{
279 WARN_ON(1);
280}
281
282#endif /* ! CONFIG_GPIOLIB */
6a89a314 283
7560fa60 284#endif /* __LINUX_GPIO_H */