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