]>
Commit | Line | Data |
---|---|---|
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 | ||
60a86668 | 17 | /* see Documentation/driver-api/gpio/legacy.rst */ |
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 | */ | |
50 | struct 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 | ||
64 | static inline int gpio_get_value(unsigned int gpio) | |
65 | { | |
66 | return __gpio_get_value(gpio); | |
67 | } | |
68 | ||
69 | static inline void gpio_set_value(unsigned int gpio, int value) | |
70 | { | |
71 | __gpio_set_value(gpio, value); | |
72 | } | |
73 | ||
74 | static inline int gpio_cansleep(unsigned int gpio) | |
75 | { | |
76 | return __gpio_cansleep(gpio); | |
77 | } | |
78 | ||
79 | static inline int gpio_to_irq(unsigned int gpio) | |
80 | { | |
81 | return __gpio_to_irq(gpio); | |
82 | } | |
83 | ||
84 | static 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 | ||
93 | struct device; | |
94 | ||
95 | int devm_gpio_request(struct device *dev, unsigned gpio, const char *label); | |
96 | int devm_gpio_request_one(struct device *dev, unsigned gpio, | |
97 | unsigned long flags, const char *label); | |
98 | void 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> |
6ea0205b | 105 | |
a4177ee7 | 106 | struct device; |
4e4438b8 | 107 | struct gpio_chip; |
a4177ee7 | 108 | |
3474cb3c | 109 | static inline bool gpio_is_valid(int number) |
7560fa60 | 110 | { |
3474cb3c | 111 | return false; |
7560fa60 DB |
112 | } |
113 | ||
d8a3515e | 114 | static inline int gpio_request(unsigned gpio, const char *label) |
7560fa60 DB |
115 | { |
116 | return -ENOSYS; | |
117 | } | |
118 | ||
323b7fe8 | 119 | static inline int gpio_request_one(unsigned gpio, |
5f829e40 WS |
120 | unsigned long flags, const char *label) |
121 | { | |
122 | return -ENOSYS; | |
123 | } | |
124 | ||
7c295975 | 125 | static inline int gpio_request_array(const struct gpio *array, size_t num) |
5f829e40 WS |
126 | { |
127 | return -ENOSYS; | |
128 | } | |
129 | ||
7560fa60 DB |
130 | static inline void gpio_free(unsigned gpio) |
131 | { | |
3d599d1c UKK |
132 | might_sleep(); |
133 | ||
7560fa60 | 134 | /* GPIO can never have been requested */ |
2c96922a MB |
135 | WARN_ON(1); |
136 | } | |
137 | ||
7c295975 | 138 | static inline void gpio_free_array(const struct gpio *array, size_t num) |
5f829e40 WS |
139 | { |
140 | might_sleep(); | |
141 | ||
142 | /* GPIO can never have been requested */ | |
143 | WARN_ON(1); | |
144 | } | |
145 | ||
d8a3515e | 146 | static inline int gpio_direction_input(unsigned gpio) |
7560fa60 DB |
147 | { |
148 | return -ENOSYS; | |
149 | } | |
150 | ||
d8a3515e | 151 | static inline int gpio_direction_output(unsigned gpio, int value) |
7560fa60 DB |
152 | { |
153 | return -ENOSYS; | |
154 | } | |
155 | ||
c4b5be98 FB |
156 | static inline int gpio_set_debounce(unsigned gpio, unsigned debounce) |
157 | { | |
158 | return -ENOSYS; | |
159 | } | |
160 | ||
7560fa60 DB |
161 | static inline int gpio_get_value(unsigned gpio) |
162 | { | |
163 | /* GPIO can never have been requested or set as {in,out}put */ | |
164 | WARN_ON(1); | |
165 | return 0; | |
166 | } | |
167 | ||
168 | static inline void gpio_set_value(unsigned gpio, int value) | |
169 | { | |
170 | /* GPIO can never have been requested or set as output */ | |
171 | WARN_ON(1); | |
172 | } | |
173 | ||
174 | static inline int gpio_cansleep(unsigned gpio) | |
175 | { | |
176 | /* GPIO can never have been requested or set as {in,out}put */ | |
177 | WARN_ON(1); | |
178 | return 0; | |
179 | } | |
180 | ||
181 | static inline int gpio_get_value_cansleep(unsigned gpio) | |
182 | { | |
183 | /* GPIO can never have been requested or set as {in,out}put */ | |
184 | WARN_ON(1); | |
185 | return 0; | |
186 | } | |
187 | ||
188 | static inline void gpio_set_value_cansleep(unsigned gpio, int value) | |
189 | { | |
190 | /* GPIO can never have been requested or set as output */ | |
191 | WARN_ON(1); | |
192 | } | |
193 | ||
d8f388d8 DB |
194 | static inline int gpio_export(unsigned gpio, bool direction_may_change) |
195 | { | |
196 | /* GPIO can never have been requested or set as {in,out}put */ | |
197 | WARN_ON(1); | |
198 | return -EINVAL; | |
199 | } | |
200 | ||
a4177ee7 JN |
201 | static inline int gpio_export_link(struct device *dev, const char *name, |
202 | unsigned gpio) | |
203 | { | |
204 | /* GPIO can never have been exported */ | |
205 | WARN_ON(1); | |
206 | return -EINVAL; | |
207 | } | |
208 | ||
d8f388d8 DB |
209 | static inline void gpio_unexport(unsigned gpio) |
210 | { | |
211 | /* GPIO can never have been exported */ | |
212 | WARN_ON(1); | |
213 | } | |
214 | ||
7560fa60 DB |
215 | static inline int gpio_to_irq(unsigned gpio) |
216 | { | |
217 | /* GPIO can never have been requested or set as input */ | |
218 | WARN_ON(1); | |
219 | return -EINVAL; | |
220 | } | |
221 | ||
222 | static 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 | ||
403c1d0b LW |
229 | static inline int devm_gpio_request(struct device *dev, unsigned gpio, |
230 | const char *label) | |
231 | { | |
232 | WARN_ON(1); | |
233 | return -EINVAL; | |
234 | } | |
7560fa60 | 235 | |
403c1d0b LW |
236 | static inline int devm_gpio_request_one(struct device *dev, unsigned gpio, |
237 | unsigned long flags, const char *label) | |
238 | { | |
239 | WARN_ON(1); | |
240 | return -EINVAL; | |
241 | } | |
6a89a314 | 242 | |
403c1d0b LW |
243 | static inline void devm_gpio_free(struct device *dev, unsigned int gpio) |
244 | { | |
245 | WARN_ON(1); | |
246 | } | |
247 | ||
248 | #endif /* ! CONFIG_GPIOLIB */ | |
6a89a314 | 249 | |
7560fa60 | 250 | #endif /* __LINUX_GPIO_H */ |