blob: b70af921c6145527322bd00cb97fa5749d4a335a [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
5#include <linux/bug.h>
6#include <linux/err.h>
7#include <linux/kernel.h>
8
9struct device;
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 */
18struct gpio_desc;
19
20/**
David Brazdil0f672f62019-12-10 10:32:29 +000021 * 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 */
26struct gpio_array;
27
28/**
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000029 * Struct containing an array of descriptors that can be obtained using
30 * gpiod_get_array().
31 */
32struct gpio_descs {
David Brazdil0f672f62019-12-10 10:32:29 +000033 struct gpio_array *info;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000034 unsigned int ndescs;
35 struct gpio_desc *desc[];
36};
37
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)
41#define GPIOD_FLAGS_BIT_OPEN_DRAIN BIT(3)
David Brazdil0f672f62019-12-10 10:32:29 +000042#define GPIOD_FLAGS_BIT_NONEXCLUSIVE BIT(4)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000043
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 */
48enum 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,
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,
56};
57
58#ifdef CONFIG_GPIOLIB
59
60/* Return the number of GPIOs associated with a device / function */
61int gpiod_count(struct device *dev, const char *con_id);
62
63/* Acquire and dispose GPIOs */
64struct gpio_desc *__must_check gpiod_get(struct device *dev,
65 const char *con_id,
66 enum gpiod_flags flags);
67struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
68 const char *con_id,
69 unsigned int idx,
70 enum gpiod_flags flags);
71struct gpio_desc *__must_check gpiod_get_optional(struct device *dev,
72 const char *con_id,
73 enum gpiod_flags flags);
74struct gpio_desc *__must_check gpiod_get_index_optional(struct device *dev,
75 const char *con_id,
76 unsigned int index,
77 enum gpiod_flags flags);
78struct gpio_descs *__must_check gpiod_get_array(struct device *dev,
79 const char *con_id,
80 enum gpiod_flags flags);
81struct gpio_descs *__must_check gpiod_get_array_optional(struct device *dev,
82 const char *con_id,
83 enum gpiod_flags flags);
84void gpiod_put(struct gpio_desc *desc);
85void gpiod_put_array(struct gpio_descs *descs);
86
87struct gpio_desc *__must_check devm_gpiod_get(struct device *dev,
88 const char *con_id,
89 enum gpiod_flags flags);
90struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev,
91 const char *con_id,
92 unsigned int idx,
93 enum gpiod_flags flags);
94struct gpio_desc *__must_check devm_gpiod_get_optional(struct device *dev,
95 const char *con_id,
96 enum gpiod_flags flags);
97struct gpio_desc *__must_check
98devm_gpiod_get_index_optional(struct device *dev, const char *con_id,
99 unsigned int index, enum gpiod_flags flags);
100struct gpio_descs *__must_check devm_gpiod_get_array(struct device *dev,
101 const char *con_id,
102 enum gpiod_flags flags);
103struct gpio_descs *__must_check
104devm_gpiod_get_array_optional(struct device *dev, const char *con_id,
105 enum gpiod_flags flags);
106void devm_gpiod_put(struct device *dev, struct gpio_desc *desc);
David Brazdil0f672f62019-12-10 10:32:29 +0000107void devm_gpiod_unhinge(struct device *dev, struct gpio_desc *desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000108void devm_gpiod_put_array(struct device *dev, struct gpio_descs *descs);
109
110int gpiod_get_direction(struct gpio_desc *desc);
111int gpiod_direction_input(struct gpio_desc *desc);
112int gpiod_direction_output(struct gpio_desc *desc, int value);
113int gpiod_direction_output_raw(struct gpio_desc *desc, int value);
114
115/* Value get/set from non-sleeping context */
116int gpiod_get_value(const struct gpio_desc *desc);
117int gpiod_get_array_value(unsigned int array_size,
David Brazdil0f672f62019-12-10 10:32:29 +0000118 struct gpio_desc **desc_array,
119 struct gpio_array *array_info,
120 unsigned long *value_bitmap);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000121void gpiod_set_value(struct gpio_desc *desc, int value);
David Brazdil0f672f62019-12-10 10:32:29 +0000122int 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);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000126int gpiod_get_raw_value(const struct gpio_desc *desc);
127int gpiod_get_raw_array_value(unsigned int array_size,
128 struct gpio_desc **desc_array,
David Brazdil0f672f62019-12-10 10:32:29 +0000129 struct gpio_array *array_info,
130 unsigned long *value_bitmap);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000131void gpiod_set_raw_value(struct gpio_desc *desc, int value);
132int gpiod_set_raw_array_value(unsigned int array_size,
David Brazdil0f672f62019-12-10 10:32:29 +0000133 struct gpio_desc **desc_array,
134 struct gpio_array *array_info,
135 unsigned long *value_bitmap);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000136
137/* Value get/set from sleeping context */
138int gpiod_get_value_cansleep(const struct gpio_desc *desc);
139int gpiod_get_array_value_cansleep(unsigned int array_size,
140 struct gpio_desc **desc_array,
David Brazdil0f672f62019-12-10 10:32:29 +0000141 struct gpio_array *array_info,
142 unsigned long *value_bitmap);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000143void gpiod_set_value_cansleep(struct gpio_desc *desc, int value);
David Brazdil0f672f62019-12-10 10:32:29 +0000144int 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);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000148int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc);
149int gpiod_get_raw_array_value_cansleep(unsigned int array_size,
150 struct gpio_desc **desc_array,
David Brazdil0f672f62019-12-10 10:32:29 +0000151 struct gpio_array *array_info,
152 unsigned long *value_bitmap);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000153void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, int value);
154int gpiod_set_raw_array_value_cansleep(unsigned int array_size,
David Brazdil0f672f62019-12-10 10:32:29 +0000155 struct gpio_desc **desc_array,
156 struct gpio_array *array_info,
157 unsigned long *value_bitmap);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000158
159int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce);
160int gpiod_set_transitory(struct gpio_desc *desc, bool transitory);
161
162int gpiod_is_active_low(const struct gpio_desc *desc);
163int gpiod_cansleep(const struct gpio_desc *desc);
164
165int gpiod_to_irq(const struct gpio_desc *desc);
David Brazdil0f672f62019-12-10 10:32:29 +0000166int gpiod_set_consumer_name(struct gpio_desc *desc, const char *name);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000167
168/* Convert between the old gpio_ and new gpiod_ interfaces */
169struct gpio_desc *gpio_to_desc(unsigned gpio);
170int desc_to_gpio(const struct gpio_desc *desc);
171
172/* Child properties interface */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000173struct fwnode_handle;
174
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000175struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
176 const char *propname, int index,
177 enum gpiod_flags dflags,
178 const char *label);
179struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev,
180 const char *con_id, int index,
181 struct fwnode_handle *child,
182 enum gpiod_flags flags,
183 const char *label);
184
185#else /* CONFIG_GPIOLIB */
186
187static inline int gpiod_count(struct device *dev, const char *con_id)
188{
189 return 0;
190}
191
192static inline struct gpio_desc *__must_check gpiod_get(struct device *dev,
193 const char *con_id,
194 enum gpiod_flags flags)
195{
196 return ERR_PTR(-ENOSYS);
197}
198static inline struct gpio_desc *__must_check
199gpiod_get_index(struct device *dev,
200 const char *con_id,
201 unsigned int idx,
202 enum gpiod_flags flags)
203{
204 return ERR_PTR(-ENOSYS);
205}
206
207static inline struct gpio_desc *__must_check
208gpiod_get_optional(struct device *dev, const char *con_id,
209 enum gpiod_flags flags)
210{
211 return NULL;
212}
213
214static inline struct gpio_desc *__must_check
215gpiod_get_index_optional(struct device *dev, const char *con_id,
216 unsigned int index, enum gpiod_flags flags)
217{
218 return NULL;
219}
220
221static inline struct gpio_descs *__must_check
222gpiod_get_array(struct device *dev, const char *con_id,
223 enum gpiod_flags flags)
224{
225 return ERR_PTR(-ENOSYS);
226}
227
228static inline struct gpio_descs *__must_check
229gpiod_get_array_optional(struct device *dev, const char *con_id,
230 enum gpiod_flags flags)
231{
232 return NULL;
233}
234
235static inline void gpiod_put(struct gpio_desc *desc)
236{
237 might_sleep();
238
239 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000240 WARN_ON(desc);
241}
242
243static inline void devm_gpiod_unhinge(struct device *dev,
244 struct gpio_desc *desc)
245{
246 might_sleep();
247
248 /* GPIO can never have been requested */
249 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000250}
251
252static inline void gpiod_put_array(struct gpio_descs *descs)
253{
254 might_sleep();
255
256 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000257 WARN_ON(descs);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000258}
259
260static inline struct gpio_desc *__must_check
261devm_gpiod_get(struct device *dev,
262 const char *con_id,
263 enum gpiod_flags flags)
264{
265 return ERR_PTR(-ENOSYS);
266}
267static inline
268struct gpio_desc *__must_check
269devm_gpiod_get_index(struct device *dev,
270 const char *con_id,
271 unsigned int idx,
272 enum gpiod_flags flags)
273{
274 return ERR_PTR(-ENOSYS);
275}
276
277static inline struct gpio_desc *__must_check
278devm_gpiod_get_optional(struct device *dev, const char *con_id,
279 enum gpiod_flags flags)
280{
281 return NULL;
282}
283
284static inline struct gpio_desc *__must_check
285devm_gpiod_get_index_optional(struct device *dev, const char *con_id,
286 unsigned int index, enum gpiod_flags flags)
287{
288 return NULL;
289}
290
291static inline struct gpio_descs *__must_check
292devm_gpiod_get_array(struct device *dev, const char *con_id,
293 enum gpiod_flags flags)
294{
295 return ERR_PTR(-ENOSYS);
296}
297
298static inline struct gpio_descs *__must_check
299devm_gpiod_get_array_optional(struct device *dev, const char *con_id,
300 enum gpiod_flags flags)
301{
302 return NULL;
303}
304
305static inline void devm_gpiod_put(struct device *dev, struct gpio_desc *desc)
306{
307 might_sleep();
308
309 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000310 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000311}
312
313static inline void devm_gpiod_put_array(struct device *dev,
314 struct gpio_descs *descs)
315{
316 might_sleep();
317
318 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000319 WARN_ON(descs);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000320}
321
322
323static inline int gpiod_get_direction(const struct gpio_desc *desc)
324{
325 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000326 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000327 return -ENOSYS;
328}
329static inline int gpiod_direction_input(struct gpio_desc *desc)
330{
331 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000332 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000333 return -ENOSYS;
334}
335static inline int gpiod_direction_output(struct gpio_desc *desc, int value)
336{
337 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000338 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000339 return -ENOSYS;
340}
341static inline int gpiod_direction_output_raw(struct gpio_desc *desc, int value)
342{
343 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000344 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000345 return -ENOSYS;
346}
347
348
349static inline int gpiod_get_value(const struct gpio_desc *desc)
350{
351 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000352 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000353 return 0;
354}
355static inline int gpiod_get_array_value(unsigned int array_size,
356 struct gpio_desc **desc_array,
David Brazdil0f672f62019-12-10 10:32:29 +0000357 struct gpio_array *array_info,
358 unsigned long *value_bitmap)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000359{
360 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000361 WARN_ON(desc_array);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000362 return 0;
363}
364static inline void gpiod_set_value(struct gpio_desc *desc, int value)
365{
366 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000367 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000368}
David Brazdil0f672f62019-12-10 10:32:29 +0000369static inline int gpiod_set_array_value(unsigned int array_size,
370 struct gpio_desc **desc_array,
371 struct gpio_array *array_info,
372 unsigned long *value_bitmap)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000373{
374 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000375 WARN_ON(desc_array);
376 return 0;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000377}
378static inline int gpiod_get_raw_value(const struct gpio_desc *desc)
379{
380 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000381 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000382 return 0;
383}
384static inline int gpiod_get_raw_array_value(unsigned int array_size,
385 struct gpio_desc **desc_array,
David Brazdil0f672f62019-12-10 10:32:29 +0000386 struct gpio_array *array_info,
387 unsigned long *value_bitmap)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000388{
389 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000390 WARN_ON(desc_array);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000391 return 0;
392}
393static inline void gpiod_set_raw_value(struct gpio_desc *desc, int value)
394{
395 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000396 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000397}
398static inline int gpiod_set_raw_array_value(unsigned int array_size,
David Brazdil0f672f62019-12-10 10:32:29 +0000399 struct gpio_desc **desc_array,
400 struct gpio_array *array_info,
401 unsigned long *value_bitmap)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000402{
403 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000404 WARN_ON(desc_array);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000405 return 0;
406}
407
408static inline int gpiod_get_value_cansleep(const struct gpio_desc *desc)
409{
410 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000411 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000412 return 0;
413}
414static inline int gpiod_get_array_value_cansleep(unsigned int array_size,
415 struct gpio_desc **desc_array,
David Brazdil0f672f62019-12-10 10:32:29 +0000416 struct gpio_array *array_info,
417 unsigned long *value_bitmap)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000418{
419 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000420 WARN_ON(desc_array);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000421 return 0;
422}
423static inline void gpiod_set_value_cansleep(struct gpio_desc *desc, int value)
424{
425 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000426 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000427}
David Brazdil0f672f62019-12-10 10:32:29 +0000428static inline int gpiod_set_array_value_cansleep(unsigned int array_size,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000429 struct gpio_desc **desc_array,
David Brazdil0f672f62019-12-10 10:32:29 +0000430 struct gpio_array *array_info,
431 unsigned long *value_bitmap)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000432{
433 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000434 WARN_ON(desc_array);
435 return 0;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000436}
437static inline int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc)
438{
439 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000440 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000441 return 0;
442}
443static inline int gpiod_get_raw_array_value_cansleep(unsigned int array_size,
444 struct gpio_desc **desc_array,
David Brazdil0f672f62019-12-10 10:32:29 +0000445 struct gpio_array *array_info,
446 unsigned long *value_bitmap)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000447{
448 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000449 WARN_ON(desc_array);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000450 return 0;
451}
452static inline void gpiod_set_raw_value_cansleep(struct gpio_desc *desc,
453 int value)
454{
455 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000456 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000457}
458static inline int gpiod_set_raw_array_value_cansleep(unsigned int array_size,
459 struct gpio_desc **desc_array,
David Brazdil0f672f62019-12-10 10:32:29 +0000460 struct gpio_array *array_info,
461 unsigned long *value_bitmap)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000462{
463 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000464 WARN_ON(desc_array);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000465 return 0;
466}
467
468static inline int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce)
469{
470 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000471 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000472 return -ENOSYS;
473}
474
475static inline int gpiod_set_transitory(struct gpio_desc *desc, bool transitory)
476{
477 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000478 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000479 return -ENOSYS;
480}
481
482static inline int gpiod_is_active_low(const struct gpio_desc *desc)
483{
484 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000485 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000486 return 0;
487}
488static inline int gpiod_cansleep(const struct gpio_desc *desc)
489{
490 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000491 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000492 return 0;
493}
494
495static inline int gpiod_to_irq(const struct gpio_desc *desc)
496{
497 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000498 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000499 return -EINVAL;
500}
501
David Brazdil0f672f62019-12-10 10:32:29 +0000502static inline int gpiod_set_consumer_name(struct gpio_desc *desc,
503 const char *name)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000504{
505 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000506 WARN_ON(desc);
507 return -EINVAL;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000508}
509
510static inline struct gpio_desc *gpio_to_desc(unsigned gpio)
511{
David Brazdil0f672f62019-12-10 10:32:29 +0000512 return NULL;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000513}
514
515static inline int desc_to_gpio(const struct gpio_desc *desc)
516{
517 /* GPIO can never have been requested */
David Brazdil0f672f62019-12-10 10:32:29 +0000518 WARN_ON(desc);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000519 return -EINVAL;
520}
521
522/* Child properties interface */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000523struct fwnode_handle;
524
525static inline
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000526struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
527 const char *propname, int index,
528 enum gpiod_flags dflags,
529 const char *label)
530{
531 return ERR_PTR(-ENOSYS);
532}
533
534static inline
535struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev,
536 const char *con_id, int index,
537 struct fwnode_handle *child,
538 enum gpiod_flags flags,
539 const char *label)
540{
541 return ERR_PTR(-ENOSYS);
542}
543
544#endif /* CONFIG_GPIOLIB */
545
546static inline
547struct gpio_desc *devm_fwnode_get_gpiod_from_child(struct device *dev,
548 const char *con_id,
549 struct fwnode_handle *child,
550 enum gpiod_flags flags,
551 const char *label)
552{
553 return devm_fwnode_get_index_gpiod_from_child(dev, con_id, 0, child,
554 flags, label);
555}
556
David Brazdil0f672f62019-12-10 10:32:29 +0000557#if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_OF_GPIO)
558struct device_node;
559
560struct gpio_desc *gpiod_get_from_of_node(struct device_node *node,
561 const char *propname, int index,
562 enum gpiod_flags dflags,
563 const char *label);
564
565#else /* CONFIG_GPIOLIB && CONFIG_OF_GPIO */
566
567struct device_node;
568
569static inline
570struct gpio_desc *gpiod_get_from_of_node(struct device_node *node,
571 const char *propname, int index,
572 enum gpiod_flags dflags,
573 const char *label)
574{
575 return ERR_PTR(-ENOSYS);
576}
577
578#endif /* CONFIG_GPIOLIB && CONFIG_OF_GPIO */
579
580#ifdef CONFIG_GPIOLIB
581struct device_node;
582
583struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev,
584 struct device_node *node,
585 const char *propname, int index,
586 enum gpiod_flags dflags,
587 const char *label);
588
589#else /* CONFIG_GPIOLIB */
590
591struct device_node;
592
593static inline
594struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev,
595 struct device_node *node,
596 const char *propname, int index,
597 enum gpiod_flags dflags,
598 const char *label)
599{
600 return ERR_PTR(-ENOSYS);
601}
602
603#endif /* CONFIG_GPIOLIB */
604
605struct acpi_gpio_params {
606 unsigned int crs_entry_index;
607 unsigned int line_index;
608 bool active_low;
609};
610
611struct acpi_gpio_mapping {
612 const char *name;
613 const struct acpi_gpio_params *data;
614 unsigned int size;
615
616/* Ignore IoRestriction field */
617#define ACPI_GPIO_QUIRK_NO_IO_RESTRICTION BIT(0)
618/*
619 * When ACPI GPIO mapping table is in use the index parameter inside it
620 * refers to the GPIO resource in _CRS method. That index has no
621 * distinction of actual type of the resource. When consumer wants to
622 * get GpioIo type explicitly, this quirk may be used.
623 */
624#define ACPI_GPIO_QUIRK_ONLY_GPIOIO BIT(1)
625
626 unsigned int quirks;
627};
628
629#if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_ACPI)
630
631struct acpi_device;
632
633int acpi_dev_add_driver_gpios(struct acpi_device *adev,
634 const struct acpi_gpio_mapping *gpios);
635void acpi_dev_remove_driver_gpios(struct acpi_device *adev);
636
637int devm_acpi_dev_add_driver_gpios(struct device *dev,
638 const struct acpi_gpio_mapping *gpios);
639void devm_acpi_dev_remove_driver_gpios(struct device *dev);
640
641#else /* CONFIG_GPIOLIB && CONFIG_ACPI */
642
643struct acpi_device;
644
645static inline int acpi_dev_add_driver_gpios(struct acpi_device *adev,
646 const struct acpi_gpio_mapping *gpios)
647{
648 return -ENXIO;
649}
650static inline void acpi_dev_remove_driver_gpios(struct acpi_device *adev) {}
651
652static inline int devm_acpi_dev_add_driver_gpios(struct device *dev,
653 const struct acpi_gpio_mapping *gpios)
654{
655 return -ENXIO;
656}
657static inline void devm_acpi_dev_remove_driver_gpios(struct device *dev) {}
658
659#endif /* CONFIG_GPIOLIB && CONFIG_ACPI */
660
661
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000662#if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS)
663
664int gpiod_export(struct gpio_desc *desc, bool direction_may_change);
665int gpiod_export_link(struct device *dev, const char *name,
666 struct gpio_desc *desc);
667void gpiod_unexport(struct gpio_desc *desc);
668
669#else /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */
670
671static inline int gpiod_export(struct gpio_desc *desc,
672 bool direction_may_change)
673{
674 return -ENOSYS;
675}
676
677static inline int gpiod_export_link(struct device *dev, const char *name,
678 struct gpio_desc *desc)
679{
680 return -ENOSYS;
681}
682
683static inline void gpiod_unexport(struct gpio_desc *desc)
684{
685}
686
687#endif /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */
688
689#endif