Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
79a9becd AC |
2 | #ifndef __LINUX_GPIO_CONSUMER_H |
3 | #define __LINUX_GPIO_CONSUMER_H | |
4 | ||
cdf86cd2 | 5 | #include <linux/bug.h> |
79a9becd AC |
6 | #include <linux/err.h> |
7 | #include <linux/kernel.h> | |
8 | ||
79a9becd | 9 | struct device; |
79a9becd AC |
10 | |
11 | /** | |
12 | * Opaque descriptor for a GPIO. These are obtained using gpiod_get() and are | |
13 | * preferable to the old integer-based handles. | |
14 | * | |
15 | * Contrary to integers, a pointer to a gpio_desc is guaranteed to be valid | |
16 | * until the GPIO is released. | |
17 | */ | |
18 | struct gpio_desc; | |
19 | ||
bf9346f5 JK |
20 | /** |
21 | * Opaque descriptor for a structure of GPIO array attributes. This structure | |
22 | * is attached to struct gpiod_descs obtained from gpiod_get_array() and can be | |
23 | * passed back to get/set array functions in order to activate fast processing | |
24 | * path if applicable. | |
25 | */ | |
26 | struct gpio_array; | |
27 | ||
66858527 RI |
28 | /** |
29 | * Struct containing an array of descriptors that can be obtained using | |
30 | * gpiod_get_array(). | |
31 | */ | |
32 | struct gpio_descs { | |
bf9346f5 | 33 | struct gpio_array *info; |
66858527 RI |
34 | unsigned int ndescs; |
35 | struct gpio_desc *desc[]; | |
36 | }; | |
37 | ||
39b2bbe3 AC |
38 | #define GPIOD_FLAGS_BIT_DIR_SET BIT(0) |
39 | #define GPIOD_FLAGS_BIT_DIR_OUT BIT(1) | |
40 | #define GPIOD_FLAGS_BIT_DIR_VAL BIT(2) | |
f926dfc1 | 41 | #define GPIOD_FLAGS_BIT_OPEN_DRAIN BIT(3) |
b0ce7b29 | 42 | #define GPIOD_FLAGS_BIT_NONEXCLUSIVE BIT(4) |
39b2bbe3 AC |
43 | |
44 | /** | |
45 | * Optional flags that can be passed to one of gpiod_* to configure direction | |
46 | * and output value. These values cannot be OR'd. | |
47 | */ | |
48 | enum gpiod_flags { | |
49 | GPIOD_ASIS = 0, | |
50 | GPIOD_IN = GPIOD_FLAGS_BIT_DIR_SET, | |
51 | GPIOD_OUT_LOW = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT, | |
52 | GPIOD_OUT_HIGH = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT | | |
53 | GPIOD_FLAGS_BIT_DIR_VAL, | |
0969a204 AS |
54 | GPIOD_OUT_LOW_OPEN_DRAIN = GPIOD_OUT_LOW | GPIOD_FLAGS_BIT_OPEN_DRAIN, |
55 | GPIOD_OUT_HIGH_OPEN_DRAIN = GPIOD_OUT_HIGH | GPIOD_FLAGS_BIT_OPEN_DRAIN, | |
39b2bbe3 AC |
56 | }; |
57 | ||
58b84f6a LW |
58 | #ifdef CONFIG_GPIOLIB |
59 | ||
66858527 RI |
60 | /* Return the number of GPIOs associated with a device / function */ |
61 | int gpiod_count(struct device *dev, const char *con_id); | |
62 | ||
bae48da2 | 63 | /* Acquire and dispose GPIOs */ |
b17d1bf1 | 64 | struct gpio_desc *__must_check gpiod_get(struct device *dev, |
39b2bbe3 AC |
65 | const char *con_id, |
66 | enum gpiod_flags flags); | |
b17d1bf1 | 67 | struct gpio_desc *__must_check gpiod_get_index(struct device *dev, |
bae48da2 | 68 | const char *con_id, |
39b2bbe3 AC |
69 | unsigned int idx, |
70 | enum gpiod_flags flags); | |
b17d1bf1 | 71 | struct gpio_desc *__must_check gpiod_get_optional(struct device *dev, |
39b2bbe3 AC |
72 | const char *con_id, |
73 | enum gpiod_flags flags); | |
b17d1bf1 | 74 | struct gpio_desc *__must_check gpiod_get_index_optional(struct device *dev, |
29a1f233 | 75 | const char *con_id, |
39b2bbe3 AC |
76 | unsigned int index, |
77 | enum gpiod_flags flags); | |
66858527 RI |
78 | struct gpio_descs *__must_check gpiod_get_array(struct device *dev, |
79 | const char *con_id, | |
80 | enum gpiod_flags flags); | |
81 | struct gpio_descs *__must_check gpiod_get_array_optional(struct device *dev, | |
82 | const char *con_id, | |
83 | enum gpiod_flags flags); | |
bae48da2 | 84 | void gpiod_put(struct gpio_desc *desc); |
66858527 | 85 | void gpiod_put_array(struct gpio_descs *descs); |
bae48da2 | 86 | |
b17d1bf1 | 87 | struct gpio_desc *__must_check devm_gpiod_get(struct device *dev, |
39b2bbe3 AC |
88 | const char *con_id, |
89 | enum gpiod_flags flags); | |
b17d1bf1 | 90 | struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev, |
bae48da2 | 91 | const char *con_id, |
39b2bbe3 AC |
92 | unsigned int idx, |
93 | enum gpiod_flags flags); | |
b17d1bf1 | 94 | struct gpio_desc *__must_check devm_gpiod_get_optional(struct device *dev, |
39b2bbe3 AC |
95 | const char *con_id, |
96 | enum gpiod_flags flags); | |
29a1f233 | 97 | struct gpio_desc *__must_check |
b17d1bf1 | 98 | devm_gpiod_get_index_optional(struct device *dev, const char *con_id, |
39b2bbe3 | 99 | unsigned int index, enum gpiod_flags flags); |
331758ee RI |
100 | struct gpio_descs *__must_check devm_gpiod_get_array(struct device *dev, |
101 | const char *con_id, | |
102 | enum gpiod_flags flags); | |
103 | struct gpio_descs *__must_check | |
104 | devm_gpiod_get_array_optional(struct device *dev, const char *con_id, | |
105 | enum gpiod_flags flags); | |
bae48da2 | 106 | void devm_gpiod_put(struct device *dev, struct gpio_desc *desc); |
891ddbc7 | 107 | void devm_gpiod_unhinge(struct device *dev, struct gpio_desc *desc); |
331758ee | 108 | void devm_gpiod_put_array(struct device *dev, struct gpio_descs *descs); |
bae48da2 | 109 | |
8e53b0f1 | 110 | int gpiod_get_direction(struct gpio_desc *desc); |
79a9becd AC |
111 | int gpiod_direction_input(struct gpio_desc *desc); |
112 | int gpiod_direction_output(struct gpio_desc *desc, int value); | |
ef70bbe1 | 113 | int gpiod_direction_output_raw(struct gpio_desc *desc, int value); |
79a9becd AC |
114 | |
115 | /* Value get/set from non-sleeping context */ | |
116 | int gpiod_get_value(const struct gpio_desc *desc); | |
eec1d566 | 117 | int gpiod_get_array_value(unsigned int array_size, |
b9762beb | 118 | struct gpio_desc **desc_array, |
77588c14 | 119 | struct gpio_array *array_info, |
b9762beb | 120 | unsigned long *value_bitmap); |
79a9becd | 121 | void gpiod_set_value(struct gpio_desc *desc, int value); |
cf9af0d5 GU |
122 | int gpiod_set_array_value(unsigned int array_size, |
123 | struct gpio_desc **desc_array, | |
124 | struct gpio_array *array_info, | |
125 | unsigned long *value_bitmap); | |
79a9becd | 126 | int gpiod_get_raw_value(const struct gpio_desc *desc); |
eec1d566 LW |
127 | int gpiod_get_raw_array_value(unsigned int array_size, |
128 | struct gpio_desc **desc_array, | |
77588c14 | 129 | struct gpio_array *array_info, |
b9762beb | 130 | unsigned long *value_bitmap); |
79a9becd | 131 | void gpiod_set_raw_value(struct gpio_desc *desc, int value); |
3027743f | 132 | int gpiod_set_raw_array_value(unsigned int array_size, |
3c940660 GU |
133 | struct gpio_desc **desc_array, |
134 | struct gpio_array *array_info, | |
135 | unsigned long *value_bitmap); | |
79a9becd AC |
136 | |
137 | /* Value get/set from sleeping context */ | |
138 | int gpiod_get_value_cansleep(const struct gpio_desc *desc); | |
eec1d566 LW |
139 | int gpiod_get_array_value_cansleep(unsigned int array_size, |
140 | struct gpio_desc **desc_array, | |
77588c14 | 141 | struct gpio_array *array_info, |
b9762beb | 142 | unsigned long *value_bitmap); |
79a9becd | 143 | void gpiod_set_value_cansleep(struct gpio_desc *desc, int value); |
cf9af0d5 GU |
144 | int gpiod_set_array_value_cansleep(unsigned int array_size, |
145 | struct gpio_desc **desc_array, | |
146 | struct gpio_array *array_info, | |
147 | unsigned long *value_bitmap); | |
79a9becd | 148 | int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc); |
eec1d566 LW |
149 | int gpiod_get_raw_array_value_cansleep(unsigned int array_size, |
150 | struct gpio_desc **desc_array, | |
77588c14 | 151 | struct gpio_array *array_info, |
b9762beb | 152 | unsigned long *value_bitmap); |
79a9becd | 153 | void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, int value); |
3027743f | 154 | int gpiod_set_raw_array_value_cansleep(unsigned int array_size, |
3c940660 GU |
155 | struct gpio_desc **desc_array, |
156 | struct gpio_array *array_info, | |
157 | unsigned long *value_bitmap); | |
79a9becd AC |
158 | |
159 | int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce); | |
e10f72bf | 160 | int gpiod_set_transitory(struct gpio_desc *desc, bool transitory); |
79a9becd AC |
161 | |
162 | int gpiod_is_active_low(const struct gpio_desc *desc); | |
163 | int gpiod_cansleep(const struct gpio_desc *desc); | |
164 | ||
165 | int gpiod_to_irq(const struct gpio_desc *desc); | |
18534df4 | 166 | int gpiod_set_consumer_name(struct gpio_desc *desc, const char *name); |
79a9becd AC |
167 | |
168 | /* Convert between the old gpio_ and new gpiod_ interfaces */ | |
169 | struct gpio_desc *gpio_to_desc(unsigned gpio); | |
170 | int desc_to_gpio(const struct gpio_desc *desc); | |
79a9becd | 171 | |
40b73183 MW |
172 | /* Child properties interface */ |
173 | struct fwnode_handle; | |
174 | ||
175 | struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, | |
537b94da | 176 | const char *propname, int index, |
b2987d74 AS |
177 | enum gpiod_flags dflags, |
178 | const char *label); | |
13949fa9 DT |
179 | struct gpio_desc *fwnode_gpiod_get_index(struct fwnode_handle *fwnode, |
180 | const char *con_id, int index, | |
181 | enum gpiod_flags flags, | |
182 | const char *label); | |
2d2f116d DT |
183 | struct gpio_desc *devm_fwnode_gpiod_get_index(struct device *dev, |
184 | struct fwnode_handle *child, | |
185 | const char *con_id, int index, | |
186 | enum gpiod_flags flags, | |
187 | const char *label); | |
3498d869 | 188 | |
79a9becd AC |
189 | #else /* CONFIG_GPIOLIB */ |
190 | ||
66858527 RI |
191 | static inline int gpiod_count(struct device *dev, const char *con_id) |
192 | { | |
193 | return 0; | |
194 | } | |
195 | ||
b17d1bf1 UKK |
196 | static inline struct gpio_desc *__must_check gpiod_get(struct device *dev, |
197 | const char *con_id, | |
198 | enum gpiod_flags flags) | |
79a9becd AC |
199 | { |
200 | return ERR_PTR(-ENOSYS); | |
201 | } | |
0dbc8b7a | 202 | static inline struct gpio_desc *__must_check |
b17d1bf1 UKK |
203 | gpiod_get_index(struct device *dev, |
204 | const char *con_id, | |
205 | unsigned int idx, | |
206 | enum gpiod_flags flags) | |
79a9becd AC |
207 | { |
208 | return ERR_PTR(-ENOSYS); | |
209 | } | |
29a1f233 TR |
210 | |
211 | static inline struct gpio_desc *__must_check | |
b17d1bf1 UKK |
212 | gpiod_get_optional(struct device *dev, const char *con_id, |
213 | enum gpiod_flags flags) | |
29a1f233 | 214 | { |
22c40367 | 215 | return NULL; |
29a1f233 TR |
216 | } |
217 | ||
218 | static inline struct gpio_desc *__must_check | |
b17d1bf1 UKK |
219 | gpiod_get_index_optional(struct device *dev, const char *con_id, |
220 | unsigned int index, enum gpiod_flags flags) | |
29a1f233 | 221 | { |
22c40367 | 222 | return NULL; |
29a1f233 TR |
223 | } |
224 | ||
66858527 RI |
225 | static inline struct gpio_descs *__must_check |
226 | gpiod_get_array(struct device *dev, const char *con_id, | |
227 | enum gpiod_flags flags) | |
228 | { | |
229 | return ERR_PTR(-ENOSYS); | |
230 | } | |
231 | ||
232 | static inline struct gpio_descs *__must_check | |
233 | gpiod_get_array_optional(struct device *dev, const char *con_id, | |
234 | enum gpiod_flags flags) | |
235 | { | |
22c40367 | 236 | return NULL; |
66858527 RI |
237 | } |
238 | ||
79a9becd AC |
239 | static inline void gpiod_put(struct gpio_desc *desc) |
240 | { | |
241 | might_sleep(); | |
242 | ||
243 | /* GPIO can never have been requested */ | |
ffe0bbab | 244 | WARN_ON(desc); |
79a9becd AC |
245 | } |
246 | ||
891ddbc7 LW |
247 | static inline void devm_gpiod_unhinge(struct device *dev, |
248 | struct gpio_desc *desc) | |
249 | { | |
250 | might_sleep(); | |
251 | ||
252 | /* GPIO can never have been requested */ | |
ffe0bbab | 253 | WARN_ON(desc); |
891ddbc7 LW |
254 | } |
255 | ||
66858527 RI |
256 | static inline void gpiod_put_array(struct gpio_descs *descs) |
257 | { | |
258 | might_sleep(); | |
259 | ||
260 | /* GPIO can never have been requested */ | |
ffe0bbab | 261 | WARN_ON(descs); |
66858527 RI |
262 | } |
263 | ||
0dbc8b7a | 264 | static inline struct gpio_desc *__must_check |
b17d1bf1 | 265 | devm_gpiod_get(struct device *dev, |
0dbc8b7a LW |
266 | const char *con_id, |
267 | enum gpiod_flags flags) | |
79a9becd AC |
268 | { |
269 | return ERR_PTR(-ENOSYS); | |
270 | } | |
271 | static inline | |
0dbc8b7a | 272 | struct gpio_desc *__must_check |
b17d1bf1 | 273 | devm_gpiod_get_index(struct device *dev, |
0dbc8b7a LW |
274 | const char *con_id, |
275 | unsigned int idx, | |
276 | enum gpiod_flags flags) | |
79a9becd AC |
277 | { |
278 | return ERR_PTR(-ENOSYS); | |
279 | } | |
29a1f233 TR |
280 | |
281 | static inline struct gpio_desc *__must_check | |
b17d1bf1 | 282 | devm_gpiod_get_optional(struct device *dev, const char *con_id, |
0dbc8b7a | 283 | enum gpiod_flags flags) |
29a1f233 | 284 | { |
22c40367 | 285 | return NULL; |
29a1f233 TR |
286 | } |
287 | ||
288 | static inline struct gpio_desc *__must_check | |
b17d1bf1 | 289 | devm_gpiod_get_index_optional(struct device *dev, const char *con_id, |
0dbc8b7a | 290 | unsigned int index, enum gpiod_flags flags) |
29a1f233 | 291 | { |
22c40367 | 292 | return NULL; |
29a1f233 TR |
293 | } |
294 | ||
331758ee RI |
295 | static inline struct gpio_descs *__must_check |
296 | devm_gpiod_get_array(struct device *dev, const char *con_id, | |
297 | enum gpiod_flags flags) | |
298 | { | |
299 | return ERR_PTR(-ENOSYS); | |
300 | } | |
301 | ||
302 | static inline struct gpio_descs *__must_check | |
303 | devm_gpiod_get_array_optional(struct device *dev, const char *con_id, | |
304 | enum gpiod_flags flags) | |
305 | { | |
22c40367 | 306 | return NULL; |
331758ee RI |
307 | } |
308 | ||
79a9becd | 309 | static inline void devm_gpiod_put(struct device *dev, struct gpio_desc *desc) |
331758ee RI |
310 | { |
311 | might_sleep(); | |
312 | ||
313 | /* GPIO can never have been requested */ | |
ffe0bbab | 314 | WARN_ON(desc); |
331758ee RI |
315 | } |
316 | ||
317 | static inline void devm_gpiod_put_array(struct device *dev, | |
318 | struct gpio_descs *descs) | |
79a9becd AC |
319 | { |
320 | might_sleep(); | |
321 | ||
322 | /* GPIO can never have been requested */ | |
ffe0bbab | 323 | WARN_ON(descs); |
79a9becd AC |
324 | } |
325 | ||
326 | ||
327 | static inline int gpiod_get_direction(const struct gpio_desc *desc) | |
328 | { | |
329 | /* GPIO can never have been requested */ | |
ffe0bbab | 330 | WARN_ON(desc); |
79a9becd AC |
331 | return -ENOSYS; |
332 | } | |
333 | static inline int gpiod_direction_input(struct gpio_desc *desc) | |
334 | { | |
335 | /* GPIO can never have been requested */ | |
ffe0bbab | 336 | WARN_ON(desc); |
79a9becd AC |
337 | return -ENOSYS; |
338 | } | |
339 | static inline int gpiod_direction_output(struct gpio_desc *desc, int value) | |
340 | { | |
341 | /* GPIO can never have been requested */ | |
ffe0bbab | 342 | WARN_ON(desc); |
79a9becd AC |
343 | return -ENOSYS; |
344 | } | |
ef70bbe1 PZ |
345 | static inline int gpiod_direction_output_raw(struct gpio_desc *desc, int value) |
346 | { | |
347 | /* GPIO can never have been requested */ | |
ffe0bbab | 348 | WARN_ON(desc); |
ef70bbe1 PZ |
349 | return -ENOSYS; |
350 | } | |
79a9becd AC |
351 | |
352 | ||
353 | static inline int gpiod_get_value(const struct gpio_desc *desc) | |
354 | { | |
355 | /* GPIO can never have been requested */ | |
ffe0bbab | 356 | WARN_ON(desc); |
79a9becd AC |
357 | return 0; |
358 | } | |
eec1d566 LW |
359 | static inline int gpiod_get_array_value(unsigned int array_size, |
360 | struct gpio_desc **desc_array, | |
77588c14 | 361 | struct gpio_array *array_info, |
b9762beb | 362 | unsigned long *value_bitmap) |
eec1d566 LW |
363 | { |
364 | /* GPIO can never have been requested */ | |
ffe0bbab | 365 | WARN_ON(desc_array); |
eec1d566 LW |
366 | return 0; |
367 | } | |
79a9becd AC |
368 | static inline void gpiod_set_value(struct gpio_desc *desc, int value) |
369 | { | |
370 | /* GPIO can never have been requested */ | |
ffe0bbab | 371 | WARN_ON(desc); |
79a9becd | 372 | } |
cf9af0d5 GU |
373 | static inline int gpiod_set_array_value(unsigned int array_size, |
374 | struct gpio_desc **desc_array, | |
375 | struct gpio_array *array_info, | |
376 | unsigned long *value_bitmap) | |
5f424243 RI |
377 | { |
378 | /* GPIO can never have been requested */ | |
ffe0bbab | 379 | WARN_ON(desc_array); |
cf9af0d5 | 380 | return 0; |
5f424243 | 381 | } |
79a9becd AC |
382 | static inline int gpiod_get_raw_value(const struct gpio_desc *desc) |
383 | { | |
384 | /* GPIO can never have been requested */ | |
ffe0bbab | 385 | WARN_ON(desc); |
79a9becd AC |
386 | return 0; |
387 | } | |
eec1d566 LW |
388 | static inline int gpiod_get_raw_array_value(unsigned int array_size, |
389 | struct gpio_desc **desc_array, | |
77588c14 | 390 | struct gpio_array *array_info, |
b9762beb | 391 | unsigned long *value_bitmap) |
eec1d566 LW |
392 | { |
393 | /* GPIO can never have been requested */ | |
ffe0bbab | 394 | WARN_ON(desc_array); |
eec1d566 LW |
395 | return 0; |
396 | } | |
79a9becd AC |
397 | static inline void gpiod_set_raw_value(struct gpio_desc *desc, int value) |
398 | { | |
399 | /* GPIO can never have been requested */ | |
ffe0bbab | 400 | WARN_ON(desc); |
79a9becd | 401 | } |
3027743f | 402 | static inline int gpiod_set_raw_array_value(unsigned int array_size, |
3c940660 GU |
403 | struct gpio_desc **desc_array, |
404 | struct gpio_array *array_info, | |
405 | unsigned long *value_bitmap) | |
5f424243 RI |
406 | { |
407 | /* GPIO can never have been requested */ | |
ffe0bbab | 408 | WARN_ON(desc_array); |
3027743f | 409 | return 0; |
5f424243 | 410 | } |
79a9becd AC |
411 | |
412 | static inline int gpiod_get_value_cansleep(const struct gpio_desc *desc) | |
413 | { | |
414 | /* GPIO can never have been requested */ | |
ffe0bbab | 415 | WARN_ON(desc); |
79a9becd AC |
416 | return 0; |
417 | } | |
eec1d566 LW |
418 | static inline int gpiod_get_array_value_cansleep(unsigned int array_size, |
419 | struct gpio_desc **desc_array, | |
77588c14 | 420 | struct gpio_array *array_info, |
b9762beb | 421 | unsigned long *value_bitmap) |
eec1d566 LW |
422 | { |
423 | /* GPIO can never have been requested */ | |
ffe0bbab | 424 | WARN_ON(desc_array); |
eec1d566 LW |
425 | return 0; |
426 | } | |
79a9becd AC |
427 | static inline void gpiod_set_value_cansleep(struct gpio_desc *desc, int value) |
428 | { | |
429 | /* GPIO can never have been requested */ | |
ffe0bbab | 430 | WARN_ON(desc); |
79a9becd | 431 | } |
cf9af0d5 | 432 | static inline int gpiod_set_array_value_cansleep(unsigned int array_size, |
5f424243 | 433 | struct gpio_desc **desc_array, |
77588c14 | 434 | struct gpio_array *array_info, |
b9762beb | 435 | unsigned long *value_bitmap) |
5f424243 RI |
436 | { |
437 | /* GPIO can never have been requested */ | |
ffe0bbab | 438 | WARN_ON(desc_array); |
cf9af0d5 | 439 | return 0; |
5f424243 | 440 | } |
79a9becd AC |
441 | static inline int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc) |
442 | { | |
443 | /* GPIO can never have been requested */ | |
ffe0bbab | 444 | WARN_ON(desc); |
79a9becd AC |
445 | return 0; |
446 | } | |
eec1d566 LW |
447 | static inline int gpiod_get_raw_array_value_cansleep(unsigned int array_size, |
448 | struct gpio_desc **desc_array, | |
77588c14 | 449 | struct gpio_array *array_info, |
b9762beb | 450 | unsigned long *value_bitmap) |
eec1d566 LW |
451 | { |
452 | /* GPIO can never have been requested */ | |
ffe0bbab | 453 | WARN_ON(desc_array); |
eec1d566 LW |
454 | return 0; |
455 | } | |
79a9becd AC |
456 | static inline void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, |
457 | int value) | |
458 | { | |
459 | /* GPIO can never have been requested */ | |
ffe0bbab | 460 | WARN_ON(desc); |
79a9becd | 461 | } |
3027743f | 462 | static inline int gpiod_set_raw_array_value_cansleep(unsigned int array_size, |
5f424243 | 463 | struct gpio_desc **desc_array, |
77588c14 | 464 | struct gpio_array *array_info, |
b9762beb | 465 | unsigned long *value_bitmap) |
5f424243 RI |
466 | { |
467 | /* GPIO can never have been requested */ | |
ffe0bbab | 468 | WARN_ON(desc_array); |
3027743f | 469 | return 0; |
5f424243 | 470 | } |
79a9becd AC |
471 | |
472 | static inline int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce) | |
473 | { | |
474 | /* GPIO can never have been requested */ | |
ffe0bbab | 475 | WARN_ON(desc); |
79a9becd AC |
476 | return -ENOSYS; |
477 | } | |
478 | ||
e10f72bf AJ |
479 | static inline int gpiod_set_transitory(struct gpio_desc *desc, bool transitory) |
480 | { | |
481 | /* GPIO can never have been requested */ | |
ffe0bbab | 482 | WARN_ON(desc); |
e10f72bf AJ |
483 | return -ENOSYS; |
484 | } | |
485 | ||
79a9becd AC |
486 | static inline int gpiod_is_active_low(const struct gpio_desc *desc) |
487 | { | |
488 | /* GPIO can never have been requested */ | |
ffe0bbab | 489 | WARN_ON(desc); |
79a9becd AC |
490 | return 0; |
491 | } | |
492 | static inline int gpiod_cansleep(const struct gpio_desc *desc) | |
493 | { | |
494 | /* GPIO can never have been requested */ | |
ffe0bbab | 495 | WARN_ON(desc); |
79a9becd AC |
496 | return 0; |
497 | } | |
498 | ||
499 | static inline int gpiod_to_irq(const struct gpio_desc *desc) | |
500 | { | |
501 | /* GPIO can never have been requested */ | |
ffe0bbab | 502 | WARN_ON(desc); |
79a9becd AC |
503 | return -EINVAL; |
504 | } | |
505 | ||
18534df4 MS |
506 | static inline int gpiod_set_consumer_name(struct gpio_desc *desc, |
507 | const char *name) | |
90b39402 LW |
508 | { |
509 | /* GPIO can never have been requested */ | |
ffe0bbab | 510 | WARN_ON(desc); |
18534df4 | 511 | return -EINVAL; |
90b39402 LW |
512 | } |
513 | ||
79a9becd AC |
514 | static inline struct gpio_desc *gpio_to_desc(unsigned gpio) |
515 | { | |
c5510b8d | 516 | return NULL; |
79a9becd | 517 | } |
c0017ed7 | 518 | |
79a9becd AC |
519 | static inline int desc_to_gpio(const struct gpio_desc *desc) |
520 | { | |
521 | /* GPIO can never have been requested */ | |
ffe0bbab | 522 | WARN_ON(desc); |
79a9becd AC |
523 | return -EINVAL; |
524 | } | |
79a9becd | 525 | |
496e7ce2 GU |
526 | /* Child properties interface */ |
527 | struct fwnode_handle; | |
528 | ||
a264d10f AS |
529 | static inline |
530 | struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, | |
537b94da | 531 | const char *propname, int index, |
b2987d74 AS |
532 | enum gpiod_flags dflags, |
533 | const char *label) | |
496e7ce2 GU |
534 | { |
535 | return ERR_PTR(-ENOSYS); | |
536 | } | |
537 | ||
13949fa9 DT |
538 | static inline |
539 | struct gpio_desc *fwnode_gpiod_get_index(struct fwnode_handle *fwnode, | |
540 | const char *con_id, int index, | |
541 | enum gpiod_flags flags, | |
542 | const char *label) | |
543 | { | |
544 | return ERR_PTR(-ENOSYS); | |
545 | } | |
546 | ||
2d2f116d DT |
547 | static inline |
548 | struct gpio_desc *devm_fwnode_gpiod_get_index(struct device *dev, | |
549 | struct fwnode_handle *fwnode, | |
550 | const char *con_id, int index, | |
551 | enum gpiod_flags flags, | |
552 | const char *label) | |
553 | { | |
554 | return ERR_PTR(-ENOSYS); | |
555 | } | |
556 | ||
557 | #endif /* CONFIG_GPIOLIB */ | |
558 | ||
559 | static inline | |
560 | struct gpio_desc *devm_fwnode_gpiod_get(struct device *dev, | |
561 | struct fwnode_handle *fwnode, | |
562 | const char *con_id, | |
563 | enum gpiod_flags flags, | |
564 | const char *label) | |
565 | { | |
566 | return devm_fwnode_gpiod_get_index(dev, fwnode, con_id, 0, | |
567 | flags, label); | |
568 | } | |
569 | ||
537b94da BB |
570 | static inline |
571 | struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev, | |
572 | const char *con_id, int index, | |
573 | struct fwnode_handle *child, | |
574 | enum gpiod_flags flags, | |
575 | const char *label) | |
576 | { | |
2d2f116d DT |
577 | return devm_fwnode_gpiod_get_index(dev, child, con_id, index, |
578 | flags, label); | |
537b94da BB |
579 | } |
580 | ||
a264d10f | 581 | static inline |
4b094797 BB |
582 | struct gpio_desc *devm_fwnode_get_gpiod_from_child(struct device *dev, |
583 | const char *con_id, | |
584 | struct fwnode_handle *child, | |
585 | enum gpiod_flags flags, | |
586 | const char *label) | |
496e7ce2 | 587 | { |
2d2f116d | 588 | return devm_fwnode_gpiod_get_index(dev, child, con_id, 0, flags, label); |
496e7ce2 GU |
589 | } |
590 | ||
fce04b1c AS |
591 | #if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_OF_GPIO) |
592 | struct device_node; | |
593 | ||
594 | struct gpio_desc *gpiod_get_from_of_node(struct device_node *node, | |
595 | const char *propname, int index, | |
596 | enum gpiod_flags dflags, | |
597 | const char *label); | |
598 | ||
599 | #else /* CONFIG_GPIOLIB && CONFIG_OF_GPIO */ | |
600 | ||
601 | struct device_node; | |
602 | ||
603 | static inline | |
604 | struct gpio_desc *gpiod_get_from_of_node(struct device_node *node, | |
605 | const char *propname, int index, | |
606 | enum gpiod_flags dflags, | |
607 | const char *label) | |
608 | { | |
609 | return ERR_PTR(-ENOSYS); | |
610 | } | |
611 | ||
612 | #endif /* CONFIG_GPIOLIB && CONFIG_OF_GPIO */ | |
613 | ||
614 | #ifdef CONFIG_GPIOLIB | |
615 | struct device_node; | |
616 | ||
617 | struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev, | |
618 | struct device_node *node, | |
619 | const char *propname, int index, | |
620 | enum gpiod_flags dflags, | |
621 | const char *label); | |
622 | ||
623 | #else /* CONFIG_GPIOLIB */ | |
624 | ||
625 | struct device_node; | |
626 | ||
627 | static inline | |
628 | struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev, | |
629 | struct device_node *node, | |
630 | const char *propname, int index, | |
631 | enum gpiod_flags dflags, | |
632 | const char *label) | |
633 | { | |
634 | return ERR_PTR(-ENOSYS); | |
635 | } | |
636 | ||
637 | #endif /* CONFIG_GPIOLIB */ | |
638 | ||
2838bf94 AS |
639 | struct acpi_gpio_params { |
640 | unsigned int crs_entry_index; | |
641 | unsigned int line_index; | |
642 | bool active_low; | |
643 | }; | |
644 | ||
645 | struct acpi_gpio_mapping { | |
646 | const char *name; | |
647 | const struct acpi_gpio_params *data; | |
648 | unsigned int size; | |
649 | ||
650 | /* Ignore IoRestriction field */ | |
651 | #define ACPI_GPIO_QUIRK_NO_IO_RESTRICTION BIT(0) | |
652 | /* | |
653 | * When ACPI GPIO mapping table is in use the index parameter inside it | |
654 | * refers to the GPIO resource in _CRS method. That index has no | |
655 | * distinction of actual type of the resource. When consumer wants to | |
656 | * get GpioIo type explicitly, this quirk may be used. | |
657 | */ | |
658 | #define ACPI_GPIO_QUIRK_ONLY_GPIOIO BIT(1) | |
659 | ||
660 | unsigned int quirks; | |
661 | }; | |
662 | ||
663 | #if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_ACPI) | |
664 | ||
665 | struct acpi_device; | |
666 | ||
667 | int acpi_dev_add_driver_gpios(struct acpi_device *adev, | |
668 | const struct acpi_gpio_mapping *gpios); | |
669 | void acpi_dev_remove_driver_gpios(struct acpi_device *adev); | |
670 | ||
671 | int devm_acpi_dev_add_driver_gpios(struct device *dev, | |
672 | const struct acpi_gpio_mapping *gpios); | |
673 | void devm_acpi_dev_remove_driver_gpios(struct device *dev); | |
674 | ||
675 | #else /* CONFIG_GPIOLIB && CONFIG_ACPI */ | |
676 | ||
677 | struct acpi_device; | |
678 | ||
679 | static inline int acpi_dev_add_driver_gpios(struct acpi_device *adev, | |
680 | const struct acpi_gpio_mapping *gpios) | |
681 | { | |
682 | return -ENXIO; | |
683 | } | |
684 | static inline void acpi_dev_remove_driver_gpios(struct acpi_device *adev) {} | |
685 | ||
686 | static inline int devm_acpi_dev_add_driver_gpios(struct device *dev, | |
687 | const struct acpi_gpio_mapping *gpios) | |
688 | { | |
689 | return -ENXIO; | |
690 | } | |
691 | static inline void devm_acpi_dev_remove_driver_gpios(struct device *dev) {} | |
692 | ||
693 | #endif /* CONFIG_GPIOLIB && CONFIG_ACPI */ | |
694 | ||
695 | ||
79a9becd AC |
696 | #if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS) |
697 | ||
698 | int gpiod_export(struct gpio_desc *desc, bool direction_may_change); | |
699 | int gpiod_export_link(struct device *dev, const char *name, | |
700 | struct gpio_desc *desc); | |
79a9becd AC |
701 | void gpiod_unexport(struct gpio_desc *desc); |
702 | ||
703 | #else /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */ | |
704 | ||
705 | static inline int gpiod_export(struct gpio_desc *desc, | |
706 | bool direction_may_change) | |
707 | { | |
708 | return -ENOSYS; | |
709 | } | |
710 | ||
711 | static inline int gpiod_export_link(struct device *dev, const char *name, | |
712 | struct gpio_desc *desc) | |
713 | { | |
714 | return -ENOSYS; | |
715 | } | |
716 | ||
79a9becd AC |
717 | static inline void gpiod_unexport(struct gpio_desc *desc) |
718 | { | |
719 | } | |
720 | ||
721 | #endif /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */ | |
722 | ||
723 | #endif |