blob: 79f450e93abfd6d5bac1aefdaa5d1677cd16deb2 [file] [log] [blame]
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef __LINUX_GPIO_CONSUMER_H
3#define __LINUX_GPIO_CONSUMER_H
4
Olivier Deprez157378f2022-04-04 15:47:50 +02005#include <linux/bits.h>
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00006#include <linux/bug.h>
Olivier Deprez157378f2022-04-04 15:47:50 +02007#include <linux/compiler_types.h>
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00008#include <linux/err.h>
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00009
10struct device;
11
12/**
13 * Opaque descriptor for a GPIO. These are obtained using gpiod_get() and are
14 * preferable to the old integer-based handles.
15 *
16 * Contrary to integers, a pointer to a gpio_desc is guaranteed to be valid
17 * until the GPIO is released.
18 */
19struct gpio_desc;
20
21/**
David Brazdil0f672f62019-12-10 10:32:29 +000022 * Opaque descriptor for a structure of GPIO array attributes. This structure
23 * is attached to struct gpiod_descs obtained from gpiod_get_array() and can be
24 * passed back to get/set array functions in order to activate fast processing
25 * path if applicable.
26 */
27struct gpio_array;
28
29/**
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000030 * Struct containing an array of descriptors that can be obtained using
31 * gpiod_get_array().
32 */
33struct gpio_descs {
David Brazdil0f672f62019-12-10 10:32:29 +000034 struct gpio_array *info;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000035 unsigned int ndescs;
36 struct gpio_desc *desc[];
37};
38
39#define GPIOD_FLAGS_BIT_DIR_SET BIT(0)
40#define GPIOD_FLAGS_BIT_DIR_OUT BIT(1)
41#define GPIOD_FLAGS_BIT_DIR_VAL BIT(2)
42#define GPIOD_FLAGS_BIT_OPEN_DRAIN BIT(3)
David Brazdil0f672f62019-12-10 10:32:29 +000043#define GPIOD_FLAGS_BIT_NONEXCLUSIVE BIT(4)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000044
45/**
46 * Optional flags that can be passed to one of gpiod_* to configure direction
47 * and output value. These values cannot be OR'd.
48 */
49enum gpiod_flags {
50 GPIOD_ASIS = 0,
51 GPIOD_IN = GPIOD_FLAGS_BIT_DIR_SET,
52 GPIOD_OUT_LOW = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT,
53 GPIOD_OUT_HIGH = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT |
54 GPIOD_FLAGS_BIT_DIR_VAL,
55 GPIOD_OUT_LOW_OPEN_DRAIN = GPIOD_OUT_LOW | GPIOD_FLAGS_BIT_OPEN_DRAIN,
56 GPIOD_OUT_HIGH_OPEN_DRAIN = GPIOD_OUT_HIGH | GPIOD_FLAGS_BIT_OPEN_DRAIN,
57};
58
59#ifdef CONFIG_GPIOLIB
60
61/* Return the number of GPIOs associated with a device / function */
62int gpiod_count(struct device *dev, const char *con_id);
63
64/* Acquire and dispose GPIOs */
65struct gpio_desc *__must_check gpiod_get(struct device *dev,
66 const char *con_id,
67 enum gpiod_flags flags);
68struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
69 const char *con_id,
70 unsigned int idx,
71 enum gpiod_flags flags);
72struct gpio_desc *__must_check gpiod_get_optional(struct device *dev,
73 const char *con_id,
74 enum gpiod_flags flags);
75struct gpio_desc *__must_check gpiod_get_index_optional(struct device *dev,
76 const char *con_id,
77 unsigned int index,
78 enum gpiod_flags flags);
79struct gpio_descs *__must_check gpiod_get_array(struct device *dev,
80 const char *con_id,
81 enum gpiod_flags flags);
82struct gpio_descs *__must_check gpiod_get_array_optional(struct device *dev,
83 const char *con_id,
84 enum gpiod_flags flags);
85void gpiod_put(struct gpio_desc *desc);
86void gpiod_put_array(struct gpio_descs *descs);
87
88struct gpio_desc *__must_check devm_gpiod_get(struct device *dev,
89 const char *con_id,
90 enum gpiod_flags flags);
91struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev,
92 const char *con_id,
93 unsigned int idx,
94 enum gpiod_flags flags);
95struct gpio_desc *__must_check devm_gpiod_get_optional(struct device *dev,
96 const char *con_id,
97 enum gpiod_flags flags);
98struct gpio_desc *__must_check
99devm_gpiod_get_index_optional(struct device *dev, const char *con_id,
100 unsigned int index, enum gpiod_flags flags);
101struct gpio_descs *__must_check devm_gpiod_get_array(struct device *dev,
102 const char *con_id,
103 enum gpiod_flags flags);
104struct gpio_descs *__must_check
105devm_gpiod_get_array_optional(struct device *dev, const char *con_id,
106 enum gpiod_flags flags);
107void devm_gpiod_put(struct device *dev, struct gpio_desc *desc);
David Brazdil0f672f62019-12-10 10:32:29 +0000108void devm_gpiod_unhinge(struct device *dev, struct gpio_desc *desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000109void devm_gpiod_put_array(struct device *dev, struct gpio_descs *descs);
110
111int gpiod_get_direction(struct gpio_desc *desc);
112int gpiod_direction_input(struct gpio_desc *desc);
113int gpiod_direction_output(struct gpio_desc *desc, int value);
114int gpiod_direction_output_raw(struct gpio_desc *desc, int value);
115
116/* Value get/set from non-sleeping context */
117int gpiod_get_value(const struct gpio_desc *desc);
118int gpiod_get_array_value(unsigned int array_size,
David Brazdil0f672f62019-12-10 10:32:29 +0000119 struct gpio_desc **desc_array,
120 struct gpio_array *array_info,
121 unsigned long *value_bitmap);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000122void gpiod_set_value(struct gpio_desc *desc, int value);
David Brazdil0f672f62019-12-10 10:32:29 +0000123int gpiod_set_array_value(unsigned int array_size,
124 struct gpio_desc **desc_array,
125 struct gpio_array *array_info,
126 unsigned long *value_bitmap);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000127int gpiod_get_raw_value(const struct gpio_desc *desc);
128int gpiod_get_raw_array_value(unsigned int array_size,
129 struct gpio_desc **desc_array,
David Brazdil0f672f62019-12-10 10:32:29 +0000130 struct gpio_array *array_info,
131 unsigned long *value_bitmap);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000132void gpiod_set_raw_value(struct gpio_desc *desc, int value);
133int gpiod_set_raw_array_value(unsigned int array_size,
David Brazdil0f672f62019-12-10 10:32:29 +0000134 struct gpio_desc **desc_array,
135 struct gpio_array *array_info,
136 unsigned long *value_bitmap);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000137
138/* Value get/set from sleeping context */
139int gpiod_get_value_cansleep(const struct gpio_desc *desc);
140int gpiod_get_array_value_cansleep(unsigned int array_size,
141 struct gpio_desc **desc_array,
David Brazdil0f672f62019-12-10 10:32:29 +0000142 struct gpio_array *array_info,
143 unsigned long *value_bitmap);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000144void gpiod_set_value_cansleep(struct gpio_desc *desc, int value);
David Brazdil0f672f62019-12-10 10:32:29 +0000145int gpiod_set_array_value_cansleep(unsigned int array_size,
146 struct gpio_desc **desc_array,
147 struct gpio_array *array_info,
148 unsigned long *value_bitmap);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000149int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc);
150int gpiod_get_raw_array_value_cansleep(unsigned int array_size,
151 struct gpio_desc **desc_array,
David Brazdil0f672f62019-12-10 10:32:29 +0000152 struct gpio_array *array_info,
153 unsigned long *value_bitmap);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000154void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, int value);
155int gpiod_set_raw_array_value_cansleep(unsigned int array_size,
David Brazdil0f672f62019-12-10 10:32:29 +0000156 struct gpio_desc **desc_array,
157 struct gpio_array *array_info,
158 unsigned long *value_bitmap);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000159
Olivier Deprez157378f2022-04-04 15:47:50 +0200160int gpiod_set_config(struct gpio_desc *desc, unsigned long config);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000161int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce);
162int gpiod_set_transitory(struct gpio_desc *desc, bool transitory);
Olivier Deprez0e641232021-09-23 10:07:05 +0200163void gpiod_toggle_active_low(struct gpio_desc *desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000164
165int gpiod_is_active_low(const struct gpio_desc *desc);
166int gpiod_cansleep(const struct gpio_desc *desc);
167
168int gpiod_to_irq(const struct gpio_desc *desc);
David Brazdil0f672f62019-12-10 10:32:29 +0000169int gpiod_set_consumer_name(struct gpio_desc *desc, const char *name);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000170
171/* Convert between the old gpio_ and new gpiod_ interfaces */
172struct gpio_desc *gpio_to_desc(unsigned gpio);
173int desc_to_gpio(const struct gpio_desc *desc);
174
175/* Child properties interface */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000176struct fwnode_handle;
177
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000178struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
179 const char *propname, int index,
180 enum gpiod_flags dflags,
181 const char *label);
Olivier Deprez157378f2022-04-04 15:47:50 +0200182struct gpio_desc *fwnode_gpiod_get_index(struct fwnode_handle *fwnode,
183 const char *con_id, int index,
184 enum gpiod_flags flags,
185 const char *label);
186struct gpio_desc *devm_fwnode_gpiod_get_index(struct device *dev,
187 struct fwnode_handle *child,
188 const char *con_id, int index,
189 enum gpiod_flags flags,
190 const char *label);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000191
192#else /* CONFIG_GPIOLIB */
193
Olivier Deprez157378f2022-04-04 15:47:50 +0200194#include <linux/kernel.h>
195
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000196static inline int gpiod_count(struct device *dev, const char *con_id)
197{
198 return 0;
199}
200
201static inline struct gpio_desc *__must_check gpiod_get(struct device *dev,
202 const char *con_id,
203 enum gpiod_flags flags)
204{
205 return ERR_PTR(-ENOSYS);
206}
207static inline struct gpio_desc *__must_check
208gpiod_get_index(struct device *dev,
209 const char *con_id,
210 unsigned int idx,
211 enum gpiod_flags flags)
212{
213 return ERR_PTR(-ENOSYS);
214}
215
216static inline struct gpio_desc *__must_check
217gpiod_get_optional(struct device *dev, const char *con_id,
218 enum gpiod_flags flags)
219{
220 return NULL;
221}
222
223static inline struct gpio_desc *__must_check
224gpiod_get_index_optional(struct device *dev, const char *con_id,
225 unsigned int index, enum gpiod_flags flags)
226{
227 return NULL;
228}
229
230static inline struct gpio_descs *__must_check
231gpiod_get_array(struct device *dev, const char *con_id,
232 enum gpiod_flags flags)
233{
234 return ERR_PTR(-ENOSYS);
235}
236
237static inline struct gpio_descs *__must_check
238gpiod_get_array_optional(struct device *dev, const char *con_id,
239 enum gpiod_flags flags)
240{
241 return NULL;
242}
243
244static inline void gpiod_put(struct gpio_desc *desc)
245{
246 might_sleep();
247
248 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000249 WARN_ON(desc);
250}
251
252static inline void devm_gpiod_unhinge(struct device *dev,
253 struct gpio_desc *desc)
254{
255 might_sleep();
256
257 /* GPIO can never have been requested */
258 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000259}
260
261static inline void gpiod_put_array(struct gpio_descs *descs)
262{
263 might_sleep();
264
265 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000266 WARN_ON(descs);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000267}
268
269static inline struct gpio_desc *__must_check
270devm_gpiod_get(struct device *dev,
271 const char *con_id,
272 enum gpiod_flags flags)
273{
274 return ERR_PTR(-ENOSYS);
275}
276static inline
277struct gpio_desc *__must_check
278devm_gpiod_get_index(struct device *dev,
279 const char *con_id,
280 unsigned int idx,
281 enum gpiod_flags flags)
282{
283 return ERR_PTR(-ENOSYS);
284}
285
286static inline struct gpio_desc *__must_check
287devm_gpiod_get_optional(struct device *dev, const char *con_id,
288 enum gpiod_flags flags)
289{
290 return NULL;
291}
292
293static inline struct gpio_desc *__must_check
294devm_gpiod_get_index_optional(struct device *dev, const char *con_id,
295 unsigned int index, enum gpiod_flags flags)
296{
297 return NULL;
298}
299
300static inline struct gpio_descs *__must_check
301devm_gpiod_get_array(struct device *dev, const char *con_id,
302 enum gpiod_flags flags)
303{
304 return ERR_PTR(-ENOSYS);
305}
306
307static inline struct gpio_descs *__must_check
308devm_gpiod_get_array_optional(struct device *dev, const char *con_id,
309 enum gpiod_flags flags)
310{
311 return NULL;
312}
313
314static inline void devm_gpiod_put(struct device *dev, struct gpio_desc *desc)
315{
316 might_sleep();
317
318 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000319 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000320}
321
322static inline void devm_gpiod_put_array(struct device *dev,
323 struct gpio_descs *descs)
324{
325 might_sleep();
326
327 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000328 WARN_ON(descs);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000329}
330
331
332static inline int gpiod_get_direction(const struct gpio_desc *desc)
333{
334 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000335 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000336 return -ENOSYS;
337}
338static inline int gpiod_direction_input(struct gpio_desc *desc)
339{
340 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000341 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000342 return -ENOSYS;
343}
344static inline int gpiod_direction_output(struct gpio_desc *desc, int value)
345{
346 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000347 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000348 return -ENOSYS;
349}
350static inline int gpiod_direction_output_raw(struct gpio_desc *desc, int value)
351{
352 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000353 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000354 return -ENOSYS;
355}
356
357
358static inline int gpiod_get_value(const struct gpio_desc *desc)
359{
360 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000361 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000362 return 0;
363}
364static inline int gpiod_get_array_value(unsigned int array_size,
365 struct gpio_desc **desc_array,
David Brazdil0f672f62019-12-10 10:32:29 +0000366 struct gpio_array *array_info,
367 unsigned long *value_bitmap)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000368{
369 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000370 WARN_ON(desc_array);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000371 return 0;
372}
373static inline void gpiod_set_value(struct gpio_desc *desc, int value)
374{
375 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000376 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000377}
David Brazdil0f672f62019-12-10 10:32:29 +0000378static inline int gpiod_set_array_value(unsigned int array_size,
379 struct gpio_desc **desc_array,
380 struct gpio_array *array_info,
381 unsigned long *value_bitmap)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000382{
383 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000384 WARN_ON(desc_array);
385 return 0;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000386}
387static inline int gpiod_get_raw_value(const struct gpio_desc *desc)
388{
389 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000390 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000391 return 0;
392}
393static inline int gpiod_get_raw_array_value(unsigned int array_size,
394 struct gpio_desc **desc_array,
David Brazdil0f672f62019-12-10 10:32:29 +0000395 struct gpio_array *array_info,
396 unsigned long *value_bitmap)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000397{
398 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000399 WARN_ON(desc_array);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000400 return 0;
401}
402static inline void gpiod_set_raw_value(struct gpio_desc *desc, int value)
403{
404 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000405 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000406}
407static inline int gpiod_set_raw_array_value(unsigned int array_size,
David Brazdil0f672f62019-12-10 10:32:29 +0000408 struct gpio_desc **desc_array,
409 struct gpio_array *array_info,
410 unsigned long *value_bitmap)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000411{
412 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000413 WARN_ON(desc_array);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000414 return 0;
415}
416
417static inline int gpiod_get_value_cansleep(const struct gpio_desc *desc)
418{
419 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000420 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000421 return 0;
422}
423static inline int gpiod_get_array_value_cansleep(unsigned int array_size,
424 struct gpio_desc **desc_array,
David Brazdil0f672f62019-12-10 10:32:29 +0000425 struct gpio_array *array_info,
426 unsigned long *value_bitmap)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000427{
428 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000429 WARN_ON(desc_array);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000430 return 0;
431}
432static inline void gpiod_set_value_cansleep(struct gpio_desc *desc, int value)
433{
434 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000435 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000436}
David Brazdil0f672f62019-12-10 10:32:29 +0000437static inline int gpiod_set_array_value_cansleep(unsigned int array_size,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000438 struct gpio_desc **desc_array,
David Brazdil0f672f62019-12-10 10:32:29 +0000439 struct gpio_array *array_info,
440 unsigned long *value_bitmap)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000441{
442 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000443 WARN_ON(desc_array);
444 return 0;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000445}
446static inline int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc)
447{
448 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000449 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000450 return 0;
451}
452static inline int gpiod_get_raw_array_value_cansleep(unsigned int array_size,
453 struct gpio_desc **desc_array,
David Brazdil0f672f62019-12-10 10:32:29 +0000454 struct gpio_array *array_info,
455 unsigned long *value_bitmap)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000456{
457 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000458 WARN_ON(desc_array);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000459 return 0;
460}
461static inline void gpiod_set_raw_value_cansleep(struct gpio_desc *desc,
462 int value)
463{
464 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000465 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000466}
467static inline int gpiod_set_raw_array_value_cansleep(unsigned int array_size,
468 struct gpio_desc **desc_array,
David Brazdil0f672f62019-12-10 10:32:29 +0000469 struct gpio_array *array_info,
470 unsigned long *value_bitmap)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000471{
472 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000473 WARN_ON(desc_array);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000474 return 0;
475}
476
Olivier Deprez157378f2022-04-04 15:47:50 +0200477static inline int gpiod_set_config(struct gpio_desc *desc, unsigned long config)
478{
479 /* GPIO can never have been requested */
480 WARN_ON(desc);
481 return -ENOSYS;
482}
483
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000484static inline int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce)
485{
486 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000487 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000488 return -ENOSYS;
489}
490
491static inline int gpiod_set_transitory(struct gpio_desc *desc, bool transitory)
492{
493 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000494 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000495 return -ENOSYS;
496}
497
Olivier Deprez0e641232021-09-23 10:07:05 +0200498static inline void gpiod_toggle_active_low(struct gpio_desc *desc)
499{
500 /* GPIO can never have been requested */
501 WARN_ON(desc);
502}
503
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000504static inline int gpiod_is_active_low(const struct gpio_desc *desc)
505{
506 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000507 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000508 return 0;
509}
510static inline int gpiod_cansleep(const struct gpio_desc *desc)
511{
512 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000513 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000514 return 0;
515}
516
517static inline int gpiod_to_irq(const struct gpio_desc *desc)
518{
519 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000520 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000521 return -EINVAL;
522}
523
David Brazdil0f672f62019-12-10 10:32:29 +0000524static inline int gpiod_set_consumer_name(struct gpio_desc *desc,
525 const char *name)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000526{
527 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000528 WARN_ON(desc);
529 return -EINVAL;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000530}
531
532static inline struct gpio_desc *gpio_to_desc(unsigned gpio)
533{
David Brazdil0f672f62019-12-10 10:32:29 +0000534 return NULL;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000535}
536
537static inline int desc_to_gpio(const struct gpio_desc *desc)
538{
539 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000540 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000541 return -EINVAL;
542}
543
544/* Child properties interface */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000545struct fwnode_handle;
546
547static inline
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000548struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
549 const char *propname, int index,
550 enum gpiod_flags dflags,
551 const char *label)
552{
553 return ERR_PTR(-ENOSYS);
554}
555
556static inline
Olivier Deprez157378f2022-04-04 15:47:50 +0200557struct gpio_desc *fwnode_gpiod_get_index(struct fwnode_handle *fwnode,
558 const char *con_id, int index,
559 enum gpiod_flags flags,
560 const char *label)
561{
562 return ERR_PTR(-ENOSYS);
563}
564
565static inline
566struct gpio_desc *devm_fwnode_gpiod_get_index(struct device *dev,
567 struct fwnode_handle *fwnode,
568 const char *con_id, int index,
569 enum gpiod_flags flags,
570 const char *label)
571{
572 return ERR_PTR(-ENOSYS);
573}
574
575#endif /* CONFIG_GPIOLIB */
576
577static inline
578struct gpio_desc *devm_fwnode_gpiod_get(struct device *dev,
579 struct fwnode_handle *fwnode,
580 const char *con_id,
581 enum gpiod_flags flags,
582 const char *label)
583{
584 return devm_fwnode_gpiod_get_index(dev, fwnode, con_id, 0,
585 flags, label);
586}
587
588static inline
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000589struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev,
590 const char *con_id, int index,
591 struct fwnode_handle *child,
592 enum gpiod_flags flags,
593 const char *label)
594{
Olivier Deprez157378f2022-04-04 15:47:50 +0200595 return devm_fwnode_gpiod_get_index(dev, child, con_id, index,
596 flags, label);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000597}
598
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000599static inline
600struct gpio_desc *devm_fwnode_get_gpiod_from_child(struct device *dev,
601 const char *con_id,
602 struct fwnode_handle *child,
603 enum gpiod_flags flags,
604 const char *label)
605{
Olivier Deprez157378f2022-04-04 15:47:50 +0200606 return devm_fwnode_gpiod_get_index(dev, child, con_id, 0, flags, label);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000607}
608
David Brazdil0f672f62019-12-10 10:32:29 +0000609#if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_OF_GPIO)
610struct device_node;
611
612struct gpio_desc *gpiod_get_from_of_node(struct device_node *node,
613 const char *propname, int index,
614 enum gpiod_flags dflags,
615 const char *label);
616
617#else /* CONFIG_GPIOLIB && CONFIG_OF_GPIO */
618
619struct device_node;
620
621static inline
622struct gpio_desc *gpiod_get_from_of_node(struct device_node *node,
623 const char *propname, int index,
624 enum gpiod_flags dflags,
625 const char *label)
626{
627 return ERR_PTR(-ENOSYS);
628}
629
630#endif /* CONFIG_GPIOLIB && CONFIG_OF_GPIO */
631
632#ifdef CONFIG_GPIOLIB
633struct device_node;
634
635struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev,
636 struct device_node *node,
637 const char *propname, int index,
638 enum gpiod_flags dflags,
639 const char *label);
640
641#else /* CONFIG_GPIOLIB */
642
643struct device_node;
644
645static inline
646struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev,
647 struct device_node *node,
648 const char *propname, int index,
649 enum gpiod_flags dflags,
650 const char *label)
651{
652 return ERR_PTR(-ENOSYS);
653}
654
655#endif /* CONFIG_GPIOLIB */
656
657struct acpi_gpio_params {
658 unsigned int crs_entry_index;
659 unsigned int line_index;
660 bool active_low;
661};
662
663struct acpi_gpio_mapping {
664 const char *name;
665 const struct acpi_gpio_params *data;
666 unsigned int size;
667
668/* Ignore IoRestriction field */
669#define ACPI_GPIO_QUIRK_NO_IO_RESTRICTION BIT(0)
670/*
671 * When ACPI GPIO mapping table is in use the index parameter inside it
672 * refers to the GPIO resource in _CRS method. That index has no
673 * distinction of actual type of the resource. When consumer wants to
674 * get GpioIo type explicitly, this quirk may be used.
675 */
676#define ACPI_GPIO_QUIRK_ONLY_GPIOIO BIT(1)
Olivier Deprez157378f2022-04-04 15:47:50 +0200677/* Use given pin as an absolute GPIO number in the system */
678#define ACPI_GPIO_QUIRK_ABSOLUTE_NUMBER BIT(2)
David Brazdil0f672f62019-12-10 10:32:29 +0000679
680 unsigned int quirks;
681};
682
683#if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_ACPI)
684
685struct acpi_device;
686
687int acpi_dev_add_driver_gpios(struct acpi_device *adev,
688 const struct acpi_gpio_mapping *gpios);
689void acpi_dev_remove_driver_gpios(struct acpi_device *adev);
690
691int devm_acpi_dev_add_driver_gpios(struct device *dev,
692 const struct acpi_gpio_mapping *gpios);
693void devm_acpi_dev_remove_driver_gpios(struct device *dev);
694
695#else /* CONFIG_GPIOLIB && CONFIG_ACPI */
696
697struct acpi_device;
698
699static inline int acpi_dev_add_driver_gpios(struct acpi_device *adev,
700 const struct acpi_gpio_mapping *gpios)
701{
702 return -ENXIO;
703}
704static inline void acpi_dev_remove_driver_gpios(struct acpi_device *adev) {}
705
706static inline int devm_acpi_dev_add_driver_gpios(struct device *dev,
707 const struct acpi_gpio_mapping *gpios)
708{
709 return -ENXIO;
710}
711static inline void devm_acpi_dev_remove_driver_gpios(struct device *dev) {}
712
713#endif /* CONFIG_GPIOLIB && CONFIG_ACPI */
714
715
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000716#if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS)
717
718int gpiod_export(struct gpio_desc *desc, bool direction_may_change);
719int gpiod_export_link(struct device *dev, const char *name,
720 struct gpio_desc *desc);
721void gpiod_unexport(struct gpio_desc *desc);
722
723#else /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */
724
725static inline int gpiod_export(struct gpio_desc *desc,
726 bool direction_may_change)
727{
728 return -ENOSYS;
729}
730
731static inline int gpiod_export_link(struct device *dev, const char *name,
732 struct gpio_desc *desc)
733{
734 return -ENOSYS;
735}
736
737static inline void gpiod_unexport(struct gpio_desc *desc)
738{
739}
740
741#endif /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */
742
743#endif