Merge tag 'asoc-fix-4.17-rc2' of https://git.kernel.org/pub/scm/linux/kernel/git...
[linux-block.git] / include / linux / gpio.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
56a46b61
LW
2/*
3 * <linux/gpio.h>
4 *
5 * This is the LEGACY GPIO bulk include file, including legacy APIs. It is
6 * used for GPIO drivers still referencing the global GPIO numberspace,
7 * and should not be included in new code.
8 *
9 * If you're implementing a GPIO driver, only include <linux/gpio/driver.h>
10 * If you're implementing a GPIO consumer, only include <linux/gpio/consumer.h>
11 */
7560fa60
DB
12#ifndef __LINUX_GPIO_H
13#define __LINUX_GPIO_H
14
7563bbf8
MB
15#include <linux/errno.h>
16
f7b370a3 17/* see Documentation/gpio/gpio-legacy.txt */
7560fa60 18
c001fb72
RD
19/* make these flag values available regardless of GPIO kconfig options */
20#define GPIOF_DIR_OUT (0 << 0)
21#define GPIOF_DIR_IN (1 << 0)
22
23#define GPIOF_INIT_LOW (0 << 1)
24#define GPIOF_INIT_HIGH (1 << 1)
25
26#define GPIOF_IN (GPIOF_DIR_IN)
27#define GPIOF_OUT_INIT_LOW (GPIOF_DIR_OUT | GPIOF_INIT_LOW)
28#define GPIOF_OUT_INIT_HIGH (GPIOF_DIR_OUT | GPIOF_INIT_HIGH)
29
79a9becd
AC
30/* Gpio pin is active-low */
31#define GPIOF_ACTIVE_LOW (1 << 2)
32
aca5ce14 33/* Gpio pin is open drain */
79a9becd 34#define GPIOF_OPEN_DRAIN (1 << 3)
aca5ce14 35
25553ff0 36/* Gpio pin is open source */
79a9becd 37#define GPIOF_OPEN_SOURCE (1 << 4)
25553ff0 38
79a9becd
AC
39#define GPIOF_EXPORT (1 << 5)
40#define GPIOF_EXPORT_CHANGEABLE (1 << 6)
fc3a1f04
WS
41#define GPIOF_EXPORT_DIR_FIXED (GPIOF_EXPORT)
42#define GPIOF_EXPORT_DIR_CHANGEABLE (GPIOF_EXPORT | GPIOF_EXPORT_CHANGEABLE)
43
feb83699
MB
44/**
45 * struct gpio - a structure describing a GPIO with configuration
46 * @gpio: the GPIO number
47 * @flags: GPIO configuration as specified by GPIOF_*
48 * @label: a literal description string of this GPIO
49 */
50struct gpio {
51 unsigned gpio;
52 unsigned long flags;
53 const char *label;
54};
55
76ec9d18 56#ifdef CONFIG_GPIOLIB
7563bbf8
MB
57
58#ifdef CONFIG_ARCH_HAVE_CUSTOM_GPIO_H
7560fa60 59#include <asm/gpio.h>
7563bbf8
MB
60#else
61
62#include <asm-generic/gpio.h>
63
64static inline int gpio_get_value(unsigned int gpio)
65{
66 return __gpio_get_value(gpio);
67}
68
69static inline void gpio_set_value(unsigned int gpio, int value)
70{
71 __gpio_set_value(gpio, value);
72}
73
74static inline int gpio_cansleep(unsigned int gpio)
75{
76 return __gpio_cansleep(gpio);
77}
78
79static inline int gpio_to_irq(unsigned int gpio)
80{
81 return __gpio_to_irq(gpio);
82}
83
84static inline int irq_to_gpio(unsigned int irq)
85{
86 return -EINVAL;
87}
88
165adc9c 89#endif /* ! CONFIG_ARCH_HAVE_CUSTOM_GPIO_H */
7560fa60 90
403c1d0b
LW
91/* CONFIG_GPIOLIB: bindings for managed devices that want to request gpios */
92
93struct device;
94
95int devm_gpio_request(struct device *dev, unsigned gpio, const char *label);
96int devm_gpio_request_one(struct device *dev, unsigned gpio,
97 unsigned long flags, const char *label);
98void devm_gpio_free(struct device *dev, unsigned int gpio);
99
76ec9d18 100#else /* ! CONFIG_GPIOLIB */
7560fa60 101
3d599d1c 102#include <linux/kernel.h>
6ea0205b 103#include <linux/types.h>
187f1882 104#include <linux/bug.h>
586a87e6 105#include <linux/pinctrl/pinctrl.h>
6ea0205b 106
a4177ee7 107struct device;
4e4438b8 108struct gpio_chip;
a4177ee7 109
3474cb3c 110static inline bool gpio_is_valid(int number)
7560fa60 111{
3474cb3c 112 return false;
7560fa60
DB
113}
114
d8a3515e 115static inline int gpio_request(unsigned gpio, const char *label)
7560fa60
DB
116{
117 return -ENOSYS;
118}
119
323b7fe8 120static inline int gpio_request_one(unsigned gpio,
5f829e40
WS
121 unsigned long flags, const char *label)
122{
123 return -ENOSYS;
124}
125
7c295975 126static inline int gpio_request_array(const struct gpio *array, size_t num)
5f829e40
WS
127{
128 return -ENOSYS;
129}
130
7560fa60
DB
131static inline void gpio_free(unsigned gpio)
132{
3d599d1c
UKK
133 might_sleep();
134
7560fa60 135 /* GPIO can never have been requested */
2c96922a
MB
136 WARN_ON(1);
137}
138
7c295975 139static inline void gpio_free_array(const struct gpio *array, size_t num)
5f829e40
WS
140{
141 might_sleep();
142
143 /* GPIO can never have been requested */
144 WARN_ON(1);
145}
146
d8a3515e 147static inline int gpio_direction_input(unsigned gpio)
7560fa60
DB
148{
149 return -ENOSYS;
150}
151
d8a3515e 152static inline int gpio_direction_output(unsigned gpio, int value)
7560fa60
DB
153{
154 return -ENOSYS;
155}
156
c4b5be98
FB
157static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
158{
159 return -ENOSYS;
160}
161
7560fa60
DB
162static inline int gpio_get_value(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(unsigned gpio, int value)
170{
171 /* GPIO can never have been requested or set as output */
172 WARN_ON(1);
173}
174
175static inline int gpio_cansleep(unsigned gpio)
176{
177 /* GPIO can never have been requested or set as {in,out}put */
178 WARN_ON(1);
179 return 0;
180}
181
182static inline int gpio_get_value_cansleep(unsigned gpio)
183{
184 /* GPIO can never have been requested or set as {in,out}put */
185 WARN_ON(1);
186 return 0;
187}
188
189static inline void gpio_set_value_cansleep(unsigned gpio, int value)
190{
191 /* GPIO can never have been requested or set as output */
192 WARN_ON(1);
193}
194
d8f388d8
DB
195static inline int gpio_export(unsigned gpio, bool direction_may_change)
196{
197 /* GPIO can never have been requested or set as {in,out}put */
198 WARN_ON(1);
199 return -EINVAL;
200}
201
a4177ee7
JN
202static inline int gpio_export_link(struct device *dev, const char *name,
203 unsigned gpio)
204{
205 /* GPIO can never have been exported */
206 WARN_ON(1);
207 return -EINVAL;
208}
209
d8f388d8
DB
210static inline void gpio_unexport(unsigned gpio)
211{
212 /* GPIO can never have been exported */
213 WARN_ON(1);
214}
215
7560fa60
DB
216static inline int gpio_to_irq(unsigned gpio)
217{
218 /* GPIO can never have been requested or set as input */
219 WARN_ON(1);
220 return -EINVAL;
221}
222
e3a2e878
AC
223static inline int gpiochip_lock_as_irq(struct gpio_chip *chip,
224 unsigned int offset)
d468bf9e
LW
225{
226 WARN_ON(1);
227 return -EINVAL;
228}
229
e3a2e878
AC
230static inline void gpiochip_unlock_as_irq(struct gpio_chip *chip,
231 unsigned int offset)
d468bf9e
LW
232{
233 WARN_ON(1);
234}
235
7560fa60
DB
236static inline int irq_to_gpio(unsigned irq)
237{
238 /* irq can never have been returned from gpio_to_irq() */
239 WARN_ON(1);
240 return -EINVAL;
241}
242
1e63d7b9 243static inline int
165adc9c 244gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name,
316511c0 245 unsigned int gpio_offset, unsigned int pin_offset,
3f0f8670 246 unsigned int npins)
165adc9c 247{
50309a9c
LW
248 WARN_ON(1);
249 return -EINVAL;
165adc9c
LW
250}
251
586a87e6
CR
252static inline int
253gpiochip_add_pingroup_range(struct gpio_chip *chip,
254 struct pinctrl_dev *pctldev,
255 unsigned int gpio_offset, const char *pin_group)
256{
257 WARN_ON(1);
258 return -EINVAL;
259}
260
165adc9c
LW
261static inline void
262gpiochip_remove_pin_ranges(struct gpio_chip *chip)
263{
50309a9c 264 WARN_ON(1);
165adc9c
LW
265}
266
403c1d0b
LW
267static inline int devm_gpio_request(struct device *dev, unsigned gpio,
268 const char *label)
269{
270 WARN_ON(1);
271 return -EINVAL;
272}
7560fa60 273
403c1d0b
LW
274static inline int devm_gpio_request_one(struct device *dev, unsigned gpio,
275 unsigned long flags, const char *label)
276{
277 WARN_ON(1);
278 return -EINVAL;
279}
6a89a314 280
403c1d0b
LW
281static inline void devm_gpio_free(struct device *dev, unsigned int gpio)
282{
283 WARN_ON(1);
284}
285
286#endif /* ! CONFIG_GPIOLIB */
6a89a314 287
7560fa60 288#endif /* __LINUX_GPIO_H */