blob: d4920ec1f1da9b764f11dd02472b0711f28dfcf6 [file] [log] [blame]
Alexandre Courbot79a9bec2013-10-17 10:21:36 -07001#ifndef __LINUX_GPIO_CONSUMER_H
2#define __LINUX_GPIO_CONSUMER_H
3
Arnd Bergmanncdf86cd22014-05-08 15:42:25 +02004#include <linux/bug.h>
Alexandre Courbot79a9bec2013-10-17 10:21:36 -07005#include <linux/err.h>
6#include <linux/kernel.h>
7
Alexandre Courbot79a9bec2013-10-17 10:21:36 -07008struct device;
Alexandre Courbot79a9bec2013-10-17 10:21:36 -07009
10/**
11 * Opaque descriptor for a GPIO. These are obtained using gpiod_get() and are
12 * preferable to the old integer-based handles.
13 *
14 * Contrary to integers, a pointer to a gpio_desc is guaranteed to be valid
15 * until the GPIO is released.
16 */
17struct gpio_desc;
18
Rojhalat Ibrahim66858522015-02-11 17:27:58 +010019/**
20 * Struct containing an array of descriptors that can be obtained using
21 * gpiod_get_array().
22 */
23struct gpio_descs {
24 unsigned int ndescs;
25 struct gpio_desc *desc[];
26};
27
Alexandre Courbot39b2bbe2014-07-25 23:38:36 +090028#define GPIOD_FLAGS_BIT_DIR_SET BIT(0)
29#define GPIOD_FLAGS_BIT_DIR_OUT BIT(1)
30#define GPIOD_FLAGS_BIT_DIR_VAL BIT(2)
31
32/**
33 * Optional flags that can be passed to one of gpiod_* to configure direction
34 * and output value. These values cannot be OR'd.
35 */
36enum gpiod_flags {
37 GPIOD_ASIS = 0,
38 GPIOD_IN = GPIOD_FLAGS_BIT_DIR_SET,
39 GPIOD_OUT_LOW = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT,
40 GPIOD_OUT_HIGH = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT |
41 GPIOD_FLAGS_BIT_DIR_VAL,
42};
43
Linus Walleij58b84f62014-08-19 12:00:53 -050044#ifdef CONFIG_GPIOLIB
45
Rojhalat Ibrahim66858522015-02-11 17:27:58 +010046/* Return the number of GPIOs associated with a device / function */
47int gpiod_count(struct device *dev, const char *con_id);
48
Alexandre Courbotbae48da2013-10-17 10:21:38 -070049/* Acquire and dispose GPIOs */
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +010050struct gpio_desc *__must_check gpiod_get(struct device *dev,
Alexandre Courbot39b2bbe2014-07-25 23:38:36 +090051 const char *con_id,
52 enum gpiod_flags flags);
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +010053struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
Alexandre Courbotbae48da2013-10-17 10:21:38 -070054 const char *con_id,
Alexandre Courbot39b2bbe2014-07-25 23:38:36 +090055 unsigned int idx,
56 enum gpiod_flags flags);
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +010057struct gpio_desc *__must_check gpiod_get_optional(struct device *dev,
Alexandre Courbot39b2bbe2014-07-25 23:38:36 +090058 const char *con_id,
59 enum gpiod_flags flags);
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +010060struct gpio_desc *__must_check gpiod_get_index_optional(struct device *dev,
Thierry Reding29a1f2332014-04-25 17:10:06 +020061 const char *con_id,
Alexandre Courbot39b2bbe2014-07-25 23:38:36 +090062 unsigned int index,
63 enum gpiod_flags flags);
Rojhalat Ibrahim66858522015-02-11 17:27:58 +010064struct gpio_descs *__must_check gpiod_get_array(struct device *dev,
65 const char *con_id,
66 enum gpiod_flags flags);
67struct gpio_descs *__must_check gpiod_get_array_optional(struct device *dev,
68 const char *con_id,
69 enum gpiod_flags flags);
Alexandre Courbotbae48da2013-10-17 10:21:38 -070070void gpiod_put(struct gpio_desc *desc);
Rojhalat Ibrahim66858522015-02-11 17:27:58 +010071void gpiod_put_array(struct gpio_descs *descs);
Alexandre Courbotbae48da2013-10-17 10:21:38 -070072
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +010073struct gpio_desc *__must_check devm_gpiod_get(struct device *dev,
Alexandre Courbot39b2bbe2014-07-25 23:38:36 +090074 const char *con_id,
75 enum gpiod_flags flags);
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +010076struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev,
Alexandre Courbotbae48da2013-10-17 10:21:38 -070077 const char *con_id,
Alexandre Courbot39b2bbe2014-07-25 23:38:36 +090078 unsigned int idx,
79 enum gpiod_flags flags);
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +010080struct gpio_desc *__must_check devm_gpiod_get_optional(struct device *dev,
Alexandre Courbot39b2bbe2014-07-25 23:38:36 +090081 const char *con_id,
82 enum gpiod_flags flags);
Thierry Reding29a1f2332014-04-25 17:10:06 +020083struct gpio_desc *__must_check
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +010084devm_gpiod_get_index_optional(struct device *dev, const char *con_id,
Alexandre Courbot39b2bbe2014-07-25 23:38:36 +090085 unsigned int index, enum gpiod_flags flags);
Rojhalat Ibrahim331758e2015-02-11 17:28:02 +010086struct gpio_descs *__must_check devm_gpiod_get_array(struct device *dev,
87 const char *con_id,
88 enum gpiod_flags flags);
89struct gpio_descs *__must_check
90devm_gpiod_get_array_optional(struct device *dev, const char *con_id,
91 enum gpiod_flags flags);
Alexandre Courbotbae48da2013-10-17 10:21:38 -070092void devm_gpiod_put(struct device *dev, struct gpio_desc *desc);
Rojhalat Ibrahim331758e2015-02-11 17:28:02 +010093void devm_gpiod_put_array(struct device *dev, struct gpio_descs *descs);
Alexandre Courbotbae48da2013-10-17 10:21:38 -070094
Alexandre Courbot8e53b0f2014-11-25 17:16:31 +090095int gpiod_get_direction(struct gpio_desc *desc);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -070096int gpiod_direction_input(struct gpio_desc *desc);
97int gpiod_direction_output(struct gpio_desc *desc, int value);
Philipp Zabelef70bbe2014-01-07 12:34:11 +010098int gpiod_direction_output_raw(struct gpio_desc *desc, int value);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -070099
100/* Value get/set from non-sleeping context */
101int gpiod_get_value(const struct gpio_desc *desc);
Lukas Wunnereec1d562017-10-12 12:40:10 +0200102int gpiod_get_array_value(unsigned int array_size,
103 struct gpio_desc **desc_array, int *value_array);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700104void gpiod_set_value(struct gpio_desc *desc, int value);
Rojhalat Ibrahim3fff99b2015-05-13 11:04:56 +0200105void gpiod_set_array_value(unsigned int array_size,
106 struct gpio_desc **desc_array, int *value_array);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700107int gpiod_get_raw_value(const struct gpio_desc *desc);
Lukas Wunnereec1d562017-10-12 12:40:10 +0200108int gpiod_get_raw_array_value(unsigned int array_size,
109 struct gpio_desc **desc_array,
110 int *value_array);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700111void gpiod_set_raw_value(struct gpio_desc *desc, int value);
Rojhalat Ibrahim3fff99b2015-05-13 11:04:56 +0200112void gpiod_set_raw_array_value(unsigned int array_size,
113 struct gpio_desc **desc_array,
114 int *value_array);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700115
116/* Value get/set from sleeping context */
117int gpiod_get_value_cansleep(const struct gpio_desc *desc);
Lukas Wunnereec1d562017-10-12 12:40:10 +0200118int gpiod_get_array_value_cansleep(unsigned int array_size,
119 struct gpio_desc **desc_array,
120 int *value_array);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700121void gpiod_set_value_cansleep(struct gpio_desc *desc, int value);
Rojhalat Ibrahim3fff99b2015-05-13 11:04:56 +0200122void gpiod_set_array_value_cansleep(unsigned int array_size,
123 struct gpio_desc **desc_array,
124 int *value_array);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700125int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc);
Lukas Wunnereec1d562017-10-12 12:40:10 +0200126int gpiod_get_raw_array_value_cansleep(unsigned int array_size,
127 struct gpio_desc **desc_array,
128 int *value_array);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700129void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, int value);
Rojhalat Ibrahim3fff99b2015-05-13 11:04:56 +0200130void gpiod_set_raw_array_value_cansleep(unsigned int array_size,
131 struct gpio_desc **desc_array,
132 int *value_array);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700133
134int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce);
135
136int gpiod_is_active_low(const struct gpio_desc *desc);
137int gpiod_cansleep(const struct gpio_desc *desc);
138
139int gpiod_to_irq(const struct gpio_desc *desc);
140
141/* Convert between the old gpio_ and new gpiod_ interfaces */
142struct gpio_desc *gpio_to_desc(unsigned gpio);
143int desc_to_gpio(const struct gpio_desc *desc);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700144
Mika Westerberg40b73182014-10-21 13:33:59 +0200145/* Child properties interface */
146struct fwnode_handle;
147
148struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
Boris Brezillon537b94d2017-02-02 14:53:11 +0100149 const char *propname, int index,
Alexander Steinb2987d72017-01-12 17:39:24 +0100150 enum gpiod_flags dflags,
151 const char *label);
Boris Brezillon537b94d2017-02-02 14:53:11 +0100152struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev,
153 const char *con_id, int index,
154 struct fwnode_handle *child,
155 enum gpiod_flags flags,
156 const char *label);
Linus Walleij3498d862017-02-21 14:19:45 +0100157
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700158#else /* CONFIG_GPIOLIB */
159
Rojhalat Ibrahim66858522015-02-11 17:27:58 +0100160static inline int gpiod_count(struct device *dev, const char *con_id)
161{
162 return 0;
163}
164
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +0100165static inline struct gpio_desc *__must_check gpiod_get(struct device *dev,
166 const char *con_id,
167 enum gpiod_flags flags)
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700168{
169 return ERR_PTR(-ENOSYS);
170}
Linus Walleij0dbc8b72014-09-01 15:15:40 +0200171static inline struct gpio_desc *__must_check
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +0100172gpiod_get_index(struct device *dev,
173 const char *con_id,
174 unsigned int idx,
175 enum gpiod_flags flags)
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700176{
177 return ERR_PTR(-ENOSYS);
178}
Thierry Reding29a1f2332014-04-25 17:10:06 +0200179
180static inline struct gpio_desc *__must_check
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +0100181gpiod_get_optional(struct device *dev, const char *con_id,
182 enum gpiod_flags flags)
Thierry Reding29a1f2332014-04-25 17:10:06 +0200183{
Dmitry Torokhov22c40362017-02-12 17:13:55 -0800184 return NULL;
Thierry Reding29a1f2332014-04-25 17:10:06 +0200185}
186
187static inline struct gpio_desc *__must_check
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +0100188gpiod_get_index_optional(struct device *dev, const char *con_id,
189 unsigned int index, enum gpiod_flags flags)
Thierry Reding29a1f2332014-04-25 17:10:06 +0200190{
Dmitry Torokhov22c40362017-02-12 17:13:55 -0800191 return NULL;
Thierry Reding29a1f2332014-04-25 17:10:06 +0200192}
193
Rojhalat Ibrahim66858522015-02-11 17:27:58 +0100194static inline struct gpio_descs *__must_check
195gpiod_get_array(struct device *dev, const char *con_id,
196 enum gpiod_flags flags)
197{
198 return ERR_PTR(-ENOSYS);
199}
200
201static inline struct gpio_descs *__must_check
202gpiod_get_array_optional(struct device *dev, const char *con_id,
203 enum gpiod_flags flags)
204{
Dmitry Torokhov22c40362017-02-12 17:13:55 -0800205 return NULL;
Rojhalat Ibrahim66858522015-02-11 17:27:58 +0100206}
207
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700208static inline void gpiod_put(struct gpio_desc *desc)
209{
210 might_sleep();
211
212 /* GPIO can never have been requested */
213 WARN_ON(1);
214}
215
Rojhalat Ibrahim66858522015-02-11 17:27:58 +0100216static inline void gpiod_put_array(struct gpio_descs *descs)
217{
218 might_sleep();
219
220 /* GPIO can never have been requested */
221 WARN_ON(1);
222}
223
Linus Walleij0dbc8b72014-09-01 15:15:40 +0200224static inline struct gpio_desc *__must_check
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +0100225devm_gpiod_get(struct device *dev,
Linus Walleij0dbc8b72014-09-01 15:15:40 +0200226 const char *con_id,
227 enum gpiod_flags flags)
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700228{
229 return ERR_PTR(-ENOSYS);
230}
231static inline
Linus Walleij0dbc8b72014-09-01 15:15:40 +0200232struct gpio_desc *__must_check
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +0100233devm_gpiod_get_index(struct device *dev,
Linus Walleij0dbc8b72014-09-01 15:15:40 +0200234 const char *con_id,
235 unsigned int idx,
236 enum gpiod_flags flags)
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700237{
238 return ERR_PTR(-ENOSYS);
239}
Thierry Reding29a1f2332014-04-25 17:10:06 +0200240
241static inline struct gpio_desc *__must_check
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +0100242devm_gpiod_get_optional(struct device *dev, const char *con_id,
Linus Walleij0dbc8b72014-09-01 15:15:40 +0200243 enum gpiod_flags flags)
Thierry Reding29a1f2332014-04-25 17:10:06 +0200244{
Dmitry Torokhov22c40362017-02-12 17:13:55 -0800245 return NULL;
Thierry Reding29a1f2332014-04-25 17:10:06 +0200246}
247
248static inline struct gpio_desc *__must_check
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +0100249devm_gpiod_get_index_optional(struct device *dev, const char *con_id,
Linus Walleij0dbc8b72014-09-01 15:15:40 +0200250 unsigned int index, enum gpiod_flags flags)
Thierry Reding29a1f2332014-04-25 17:10:06 +0200251{
Dmitry Torokhov22c40362017-02-12 17:13:55 -0800252 return NULL;
Thierry Reding29a1f2332014-04-25 17:10:06 +0200253}
254
Rojhalat Ibrahim331758e2015-02-11 17:28:02 +0100255static inline struct gpio_descs *__must_check
256devm_gpiod_get_array(struct device *dev, const char *con_id,
257 enum gpiod_flags flags)
258{
259 return ERR_PTR(-ENOSYS);
260}
261
262static inline struct gpio_descs *__must_check
263devm_gpiod_get_array_optional(struct device *dev, const char *con_id,
264 enum gpiod_flags flags)
265{
Dmitry Torokhov22c40362017-02-12 17:13:55 -0800266 return NULL;
Rojhalat Ibrahim331758e2015-02-11 17:28:02 +0100267}
268
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700269static inline void devm_gpiod_put(struct device *dev, struct gpio_desc *desc)
270{
271 might_sleep();
272
273 /* GPIO can never have been requested */
274 WARN_ON(1);
275}
276
Rojhalat Ibrahim331758e2015-02-11 17:28:02 +0100277static inline void devm_gpiod_put_array(struct device *dev,
278 struct gpio_descs *descs)
279{
280 might_sleep();
281
282 /* GPIO can never have been requested */
283 WARN_ON(1);
284}
285
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700286
287static inline int gpiod_get_direction(const struct gpio_desc *desc)
288{
289 /* GPIO can never have been requested */
290 WARN_ON(1);
291 return -ENOSYS;
292}
293static inline int gpiod_direction_input(struct gpio_desc *desc)
294{
295 /* GPIO can never have been requested */
296 WARN_ON(1);
297 return -ENOSYS;
298}
299static inline int gpiod_direction_output(struct gpio_desc *desc, int value)
300{
301 /* GPIO can never have been requested */
302 WARN_ON(1);
303 return -ENOSYS;
304}
Philipp Zabelef70bbe2014-01-07 12:34:11 +0100305static inline int gpiod_direction_output_raw(struct gpio_desc *desc, int value)
306{
307 /* GPIO can never have been requested */
308 WARN_ON(1);
309 return -ENOSYS;
310}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700311
312
313static inline int gpiod_get_value(const struct gpio_desc *desc)
314{
315 /* GPIO can never have been requested */
316 WARN_ON(1);
317 return 0;
318}
Lukas Wunnereec1d562017-10-12 12:40:10 +0200319static inline int gpiod_get_array_value(unsigned int array_size,
320 struct gpio_desc **desc_array,
321 int *value_array)
322{
323 /* GPIO can never have been requested */
324 WARN_ON(1);
325 return 0;
326}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700327static inline void gpiod_set_value(struct gpio_desc *desc, int value)
328{
329 /* GPIO can never have been requested */
330 WARN_ON(1);
331}
Rojhalat Ibrahim3fff99b2015-05-13 11:04:56 +0200332static inline void gpiod_set_array_value(unsigned int array_size,
333 struct gpio_desc **desc_array,
334 int *value_array)
Rojhalat Ibrahim5f424242014-11-04 17:12:06 +0100335{
336 /* GPIO can never have been requested */
337 WARN_ON(1);
338}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700339static inline int gpiod_get_raw_value(const struct gpio_desc *desc)
340{
341 /* GPIO can never have been requested */
342 WARN_ON(1);
343 return 0;
344}
Lukas Wunnereec1d562017-10-12 12:40:10 +0200345static inline int gpiod_get_raw_array_value(unsigned int array_size,
346 struct gpio_desc **desc_array,
347 int *value_array)
348{
349 /* GPIO can never have been requested */
350 WARN_ON(1);
351 return 0;
352}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700353static inline void gpiod_set_raw_value(struct gpio_desc *desc, int value)
354{
355 /* GPIO can never have been requested */
356 WARN_ON(1);
357}
Rojhalat Ibrahim3fff99b2015-05-13 11:04:56 +0200358static inline void gpiod_set_raw_array_value(unsigned int array_size,
359 struct gpio_desc **desc_array,
360 int *value_array)
Rojhalat Ibrahim5f424242014-11-04 17:12:06 +0100361{
362 /* GPIO can never have been requested */
363 WARN_ON(1);
364}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700365
366static inline int gpiod_get_value_cansleep(const struct gpio_desc *desc)
367{
368 /* GPIO can never have been requested */
369 WARN_ON(1);
370 return 0;
371}
Lukas Wunnereec1d562017-10-12 12:40:10 +0200372static inline int gpiod_get_array_value_cansleep(unsigned int array_size,
373 struct gpio_desc **desc_array,
374 int *value_array)
375{
376 /* GPIO can never have been requested */
377 WARN_ON(1);
378 return 0;
379}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700380static inline void gpiod_set_value_cansleep(struct gpio_desc *desc, int value)
381{
382 /* GPIO can never have been requested */
383 WARN_ON(1);
384}
Rojhalat Ibrahim3fff99b2015-05-13 11:04:56 +0200385static inline void gpiod_set_array_value_cansleep(unsigned int array_size,
Rojhalat Ibrahim5f424242014-11-04 17:12:06 +0100386 struct gpio_desc **desc_array,
387 int *value_array)
388{
389 /* GPIO can never have been requested */
390 WARN_ON(1);
391}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700392static inline int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc)
393{
394 /* GPIO can never have been requested */
395 WARN_ON(1);
396 return 0;
397}
Lukas Wunnereec1d562017-10-12 12:40:10 +0200398static inline int gpiod_get_raw_array_value_cansleep(unsigned int array_size,
399 struct gpio_desc **desc_array,
400 int *value_array)
401{
402 /* GPIO can never have been requested */
403 WARN_ON(1);
404 return 0;
405}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700406static inline void gpiod_set_raw_value_cansleep(struct gpio_desc *desc,
407 int value)
408{
409 /* GPIO can never have been requested */
410 WARN_ON(1);
411}
Rojhalat Ibrahim3fff99b2015-05-13 11:04:56 +0200412static inline void gpiod_set_raw_array_value_cansleep(unsigned int array_size,
Rojhalat Ibrahim5f424242014-11-04 17:12:06 +0100413 struct gpio_desc **desc_array,
414 int *value_array)
415{
416 /* GPIO can never have been requested */
417 WARN_ON(1);
418}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700419
420static inline int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce)
421{
422 /* GPIO can never have been requested */
423 WARN_ON(1);
424 return -ENOSYS;
425}
426
427static inline int gpiod_is_active_low(const struct gpio_desc *desc)
428{
429 /* GPIO can never have been requested */
430 WARN_ON(1);
431 return 0;
432}
433static inline int gpiod_cansleep(const struct gpio_desc *desc)
434{
435 /* GPIO can never have been requested */
436 WARN_ON(1);
437 return 0;
438}
439
440static inline int gpiod_to_irq(const struct gpio_desc *desc)
441{
442 /* GPIO can never have been requested */
443 WARN_ON(1);
444 return -EINVAL;
445}
446
447static inline struct gpio_desc *gpio_to_desc(unsigned gpio)
448{
449 return ERR_PTR(-EINVAL);
450}
Markus Pargmannc0017ed2015-08-14 16:10:59 +0200451
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700452static inline int desc_to_gpio(const struct gpio_desc *desc)
453{
454 /* GPIO can never have been requested */
455 WARN_ON(1);
456 return -EINVAL;
457}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700458
Geert Uytterhoeven496e7ce2015-05-07 01:08:08 -0700459/* Child properties interface */
460struct fwnode_handle;
461
Andy Shevchenkoa264d102017-01-09 16:02:28 +0200462static inline
463struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
Boris Brezillon537b94d2017-02-02 14:53:11 +0100464 const char *propname, int index,
Alexander Steinb2987d72017-01-12 17:39:24 +0100465 enum gpiod_flags dflags,
466 const char *label)
Geert Uytterhoeven496e7ce2015-05-07 01:08:08 -0700467{
468 return ERR_PTR(-ENOSYS);
469}
470
Andy Shevchenkoa264d102017-01-09 16:02:28 +0200471static inline
Boris Brezillon537b94d2017-02-02 14:53:11 +0100472struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev,
473 const char *con_id, int index,
474 struct fwnode_handle *child,
475 enum gpiod_flags flags,
476 const char *label)
477{
478 return ERR_PTR(-ENOSYS);
479}
480
481#endif /* CONFIG_GPIOLIB */
482
483static inline
Boris Brezillon4b094792017-02-02 14:53:10 +0100484struct gpio_desc *devm_fwnode_get_gpiod_from_child(struct device *dev,
485 const char *con_id,
486 struct fwnode_handle *child,
487 enum gpiod_flags flags,
488 const char *label)
Geert Uytterhoeven496e7ce2015-05-07 01:08:08 -0700489{
Boris Brezillon537b94d2017-02-02 14:53:11 +0100490 return devm_fwnode_get_index_gpiod_from_child(dev, con_id, 0, child,
491 flags, label);
Geert Uytterhoeven496e7ce2015-05-07 01:08:08 -0700492}
493
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700494#if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS)
495
496int gpiod_export(struct gpio_desc *desc, bool direction_may_change);
497int gpiod_export_link(struct device *dev, const char *name,
498 struct gpio_desc *desc);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700499void gpiod_unexport(struct gpio_desc *desc);
500
501#else /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */
502
503static inline int gpiod_export(struct gpio_desc *desc,
504 bool direction_may_change)
505{
506 return -ENOSYS;
507}
508
509static inline int gpiod_export_link(struct device *dev, const char *name,
510 struct gpio_desc *desc)
511{
512 return -ENOSYS;
513}
514
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700515static inline void gpiod_unexport(struct gpio_desc *desc)
516{
517}
518
519#endif /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */
520
521#endif