blob: 21ddbe4400308ee51e8b29fe85acfe08022879ec [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Alexandre Courbot79a9bec2013-10-17 10:21:36 -07002#ifndef __LINUX_GPIO_CONSUMER_H
3#define __LINUX_GPIO_CONSUMER_H
4
Arnd Bergmanncdf86cd22014-05-08 15:42:25 +02005#include <linux/bug.h>
Alexandre Courbot79a9bec2013-10-17 10:21:36 -07006#include <linux/err.h>
7#include <linux/kernel.h>
8
Alexandre Courbot79a9bec2013-10-17 10:21:36 -07009struct device;
Alexandre Courbot79a9bec2013-10-17 10:21:36 -070010
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
Rojhalat Ibrahim66858522015-02-11 17:27:58 +010020/**
21 * Struct containing an array of descriptors that can be obtained using
22 * gpiod_get_array().
23 */
24struct gpio_descs {
25 unsigned int ndescs;
26 struct gpio_desc *desc[];
27};
28
Alexandre Courbot39b2bbe2014-07-25 23:38:36 +090029#define GPIOD_FLAGS_BIT_DIR_SET BIT(0)
30#define GPIOD_FLAGS_BIT_DIR_OUT BIT(1)
31#define GPIOD_FLAGS_BIT_DIR_VAL BIT(2)
Linus Walleijf926dfc2017-09-10 19:26:22 +020032#define GPIOD_FLAGS_BIT_OPEN_DRAIN BIT(3)
Alexandre Courbot39b2bbe2014-07-25 23:38:36 +090033
34/**
35 * Optional flags that can be passed to one of gpiod_* to configure direction
36 * and output value. These values cannot be OR'd.
37 */
38enum gpiod_flags {
39 GPIOD_ASIS = 0,
40 GPIOD_IN = GPIOD_FLAGS_BIT_DIR_SET,
41 GPIOD_OUT_LOW = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT,
42 GPIOD_OUT_HIGH = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT |
43 GPIOD_FLAGS_BIT_DIR_VAL,
Andy Shevchenko0969a202018-07-27 17:47:01 +030044 GPIOD_OUT_LOW_OPEN_DRAIN = GPIOD_OUT_LOW | GPIOD_FLAGS_BIT_OPEN_DRAIN,
45 GPIOD_OUT_HIGH_OPEN_DRAIN = GPIOD_OUT_HIGH | GPIOD_FLAGS_BIT_OPEN_DRAIN,
Alexandre Courbot39b2bbe2014-07-25 23:38:36 +090046};
47
Linus Walleij58b84f62014-08-19 12:00:53 -050048#ifdef CONFIG_GPIOLIB
49
Rojhalat Ibrahim66858522015-02-11 17:27:58 +010050/* Return the number of GPIOs associated with a device / function */
51int gpiod_count(struct device *dev, const char *con_id);
52
Alexandre Courbotbae48da2013-10-17 10:21:38 -070053/* Acquire and dispose GPIOs */
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +010054struct gpio_desc *__must_check gpiod_get(struct device *dev,
Alexandre Courbot39b2bbe2014-07-25 23:38:36 +090055 const char *con_id,
56 enum gpiod_flags flags);
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +010057struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
Alexandre Courbotbae48da2013-10-17 10:21:38 -070058 const char *con_id,
Alexandre Courbot39b2bbe2014-07-25 23:38:36 +090059 unsigned int idx,
60 enum gpiod_flags flags);
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +010061struct gpio_desc *__must_check gpiod_get_optional(struct device *dev,
Alexandre Courbot39b2bbe2014-07-25 23:38:36 +090062 const char *con_id,
63 enum gpiod_flags flags);
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +010064struct gpio_desc *__must_check gpiod_get_index_optional(struct device *dev,
Thierry Reding29a1f2332014-04-25 17:10:06 +020065 const char *con_id,
Alexandre Courbot39b2bbe2014-07-25 23:38:36 +090066 unsigned int index,
67 enum gpiod_flags flags);
Rojhalat Ibrahim66858522015-02-11 17:27:58 +010068struct gpio_descs *__must_check gpiod_get_array(struct device *dev,
69 const char *con_id,
70 enum gpiod_flags flags);
71struct gpio_descs *__must_check gpiod_get_array_optional(struct device *dev,
72 const char *con_id,
73 enum gpiod_flags flags);
Alexandre Courbotbae48da2013-10-17 10:21:38 -070074void gpiod_put(struct gpio_desc *desc);
Rojhalat Ibrahim66858522015-02-11 17:27:58 +010075void gpiod_put_array(struct gpio_descs *descs);
Alexandre Courbotbae48da2013-10-17 10:21:38 -070076
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +010077struct gpio_desc *__must_check devm_gpiod_get(struct device *dev,
Alexandre Courbot39b2bbe2014-07-25 23:38:36 +090078 const char *con_id,
79 enum gpiod_flags flags);
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +010080struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev,
Alexandre Courbotbae48da2013-10-17 10:21:38 -070081 const char *con_id,
Alexandre Courbot39b2bbe2014-07-25 23:38:36 +090082 unsigned int idx,
83 enum gpiod_flags flags);
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +010084struct gpio_desc *__must_check devm_gpiod_get_optional(struct device *dev,
Alexandre Courbot39b2bbe2014-07-25 23:38:36 +090085 const char *con_id,
86 enum gpiod_flags flags);
Thierry Reding29a1f2332014-04-25 17:10:06 +020087struct gpio_desc *__must_check
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +010088devm_gpiod_get_index_optional(struct device *dev, const char *con_id,
Alexandre Courbot39b2bbe2014-07-25 23:38:36 +090089 unsigned int index, enum gpiod_flags flags);
Rojhalat Ibrahim331758e2015-02-11 17:28:02 +010090struct gpio_descs *__must_check devm_gpiod_get_array(struct device *dev,
91 const char *con_id,
92 enum gpiod_flags flags);
93struct gpio_descs *__must_check
94devm_gpiod_get_array_optional(struct device *dev, const char *con_id,
95 enum gpiod_flags flags);
Alexandre Courbotbae48da2013-10-17 10:21:38 -070096void devm_gpiod_put(struct device *dev, struct gpio_desc *desc);
Rojhalat Ibrahim331758e2015-02-11 17:28:02 +010097void devm_gpiod_put_array(struct device *dev, struct gpio_descs *descs);
Alexandre Courbotbae48da2013-10-17 10:21:38 -070098
Alexandre Courbot8e53b0f2014-11-25 17:16:31 +090099int gpiod_get_direction(struct gpio_desc *desc);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700100int gpiod_direction_input(struct gpio_desc *desc);
101int gpiod_direction_output(struct gpio_desc *desc, int value);
Philipp Zabelef70bbe2014-01-07 12:34:11 +0100102int gpiod_direction_output_raw(struct gpio_desc *desc, int value);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700103
104/* Value get/set from non-sleeping context */
105int gpiod_get_value(const struct gpio_desc *desc);
Lukas Wunnereec1d562017-10-12 12:40:10 +0200106int gpiod_get_array_value(unsigned int array_size,
107 struct gpio_desc **desc_array, int *value_array);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700108void gpiod_set_value(struct gpio_desc *desc, int value);
Rojhalat Ibrahim3fff99b2015-05-13 11:04:56 +0200109void gpiod_set_array_value(unsigned int array_size,
110 struct gpio_desc **desc_array, int *value_array);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700111int gpiod_get_raw_value(const struct gpio_desc *desc);
Lukas Wunnereec1d562017-10-12 12:40:10 +0200112int gpiod_get_raw_array_value(unsigned int array_size,
113 struct gpio_desc **desc_array,
114 int *value_array);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700115void gpiod_set_raw_value(struct gpio_desc *desc, int value);
Laura Abbott30277432018-05-21 10:57:07 -0700116int gpiod_set_raw_array_value(unsigned int array_size,
Rojhalat Ibrahim3fff99b2015-05-13 11:04:56 +0200117 struct gpio_desc **desc_array,
118 int *value_array);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700119
120/* Value get/set from sleeping context */
121int gpiod_get_value_cansleep(const struct gpio_desc *desc);
Lukas Wunnereec1d562017-10-12 12:40:10 +0200122int gpiod_get_array_value_cansleep(unsigned int array_size,
123 struct gpio_desc **desc_array,
124 int *value_array);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700125void gpiod_set_value_cansleep(struct gpio_desc *desc, int value);
Rojhalat Ibrahim3fff99b2015-05-13 11:04:56 +0200126void gpiod_set_array_value_cansleep(unsigned int array_size,
127 struct gpio_desc **desc_array,
128 int *value_array);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700129int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc);
Lukas Wunnereec1d562017-10-12 12:40:10 +0200130int gpiod_get_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 -0700133void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, int value);
Laura Abbott30277432018-05-21 10:57:07 -0700134int gpiod_set_raw_array_value_cansleep(unsigned int array_size,
Rojhalat Ibrahim3fff99b2015-05-13 11:04:56 +0200135 struct gpio_desc **desc_array,
136 int *value_array);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700137
138int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce);
Andrew Jefferye10f72b2017-11-30 14:25:24 +1030139int gpiod_set_transitory(struct gpio_desc *desc, bool transitory);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700140
141int gpiod_is_active_low(const struct gpio_desc *desc);
142int gpiod_cansleep(const struct gpio_desc *desc);
143
144int gpiod_to_irq(const struct gpio_desc *desc);
Linus Walleij90b39402018-06-01 13:21:27 +0200145void gpiod_set_consumer_name(struct gpio_desc *desc, const char *name);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700146
147/* Convert between the old gpio_ and new gpiod_ interfaces */
148struct gpio_desc *gpio_to_desc(unsigned gpio);
149int desc_to_gpio(const struct gpio_desc *desc);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700150
Mika Westerberg40b73182014-10-21 13:33:59 +0200151/* Child properties interface */
Linus Walleij92542ed2017-12-29 22:52:02 +0100152struct device_node;
Mika Westerberg40b73182014-10-21 13:33:59 +0200153struct fwnode_handle;
154
Linus Walleij92542ed2017-12-29 22:52:02 +0100155struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev,
156 struct device_node *node,
157 const char *propname, int index,
158 enum gpiod_flags dflags,
159 const char *label);
Mika Westerberg40b73182014-10-21 13:33:59 +0200160struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
Boris Brezillon537b94d2017-02-02 14:53:11 +0100161 const char *propname, int index,
Alexander Steinb2987d72017-01-12 17:39:24 +0100162 enum gpiod_flags dflags,
163 const char *label);
Boris Brezillon537b94d2017-02-02 14:53:11 +0100164struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev,
165 const char *con_id, int index,
166 struct fwnode_handle *child,
167 enum gpiod_flags flags,
168 const char *label);
Linus Walleij3498d862017-02-21 14:19:45 +0100169
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700170#else /* CONFIG_GPIOLIB */
171
Rojhalat Ibrahim66858522015-02-11 17:27:58 +0100172static inline int gpiod_count(struct device *dev, const char *con_id)
173{
174 return 0;
175}
176
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +0100177static inline struct gpio_desc *__must_check gpiod_get(struct device *dev,
178 const char *con_id,
179 enum gpiod_flags flags)
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700180{
181 return ERR_PTR(-ENOSYS);
182}
Linus Walleij0dbc8b72014-09-01 15:15:40 +0200183static inline struct gpio_desc *__must_check
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +0100184gpiod_get_index(struct device *dev,
185 const char *con_id,
186 unsigned int idx,
187 enum gpiod_flags flags)
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700188{
189 return ERR_PTR(-ENOSYS);
190}
Thierry Reding29a1f2332014-04-25 17:10:06 +0200191
192static inline struct gpio_desc *__must_check
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +0100193gpiod_get_optional(struct device *dev, const char *con_id,
194 enum gpiod_flags flags)
Thierry Reding29a1f2332014-04-25 17:10:06 +0200195{
Dmitry Torokhov22c40362017-02-12 17:13:55 -0800196 return NULL;
Thierry Reding29a1f2332014-04-25 17:10:06 +0200197}
198
199static inline struct gpio_desc *__must_check
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +0100200gpiod_get_index_optional(struct device *dev, const char *con_id,
201 unsigned int index, enum gpiod_flags flags)
Thierry Reding29a1f2332014-04-25 17:10:06 +0200202{
Dmitry Torokhov22c40362017-02-12 17:13:55 -0800203 return NULL;
Thierry Reding29a1f2332014-04-25 17:10:06 +0200204}
205
Rojhalat Ibrahim66858522015-02-11 17:27:58 +0100206static inline struct gpio_descs *__must_check
207gpiod_get_array(struct device *dev, const char *con_id,
208 enum gpiod_flags flags)
209{
210 return ERR_PTR(-ENOSYS);
211}
212
213static inline struct gpio_descs *__must_check
214gpiod_get_array_optional(struct device *dev, const char *con_id,
215 enum gpiod_flags flags)
216{
Dmitry Torokhov22c40362017-02-12 17:13:55 -0800217 return NULL;
Rojhalat Ibrahim66858522015-02-11 17:27:58 +0100218}
219
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700220static inline void gpiod_put(struct gpio_desc *desc)
221{
222 might_sleep();
223
224 /* GPIO can never have been requested */
225 WARN_ON(1);
226}
227
Rojhalat Ibrahim66858522015-02-11 17:27:58 +0100228static inline void gpiod_put_array(struct gpio_descs *descs)
229{
230 might_sleep();
231
232 /* GPIO can never have been requested */
233 WARN_ON(1);
234}
235
Linus Walleij0dbc8b72014-09-01 15:15:40 +0200236static inline struct gpio_desc *__must_check
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +0100237devm_gpiod_get(struct device *dev,
Linus Walleij0dbc8b72014-09-01 15:15:40 +0200238 const char *con_id,
239 enum gpiod_flags flags)
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700240{
241 return ERR_PTR(-ENOSYS);
242}
243static inline
Linus Walleij0dbc8b72014-09-01 15:15:40 +0200244struct gpio_desc *__must_check
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +0100245devm_gpiod_get_index(struct device *dev,
Linus Walleij0dbc8b72014-09-01 15:15:40 +0200246 const char *con_id,
247 unsigned int idx,
248 enum gpiod_flags flags)
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700249{
250 return ERR_PTR(-ENOSYS);
251}
Thierry Reding29a1f2332014-04-25 17:10:06 +0200252
253static inline struct gpio_desc *__must_check
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +0100254devm_gpiod_get_optional(struct device *dev, const char *con_id,
Linus Walleij0dbc8b72014-09-01 15:15:40 +0200255 enum gpiod_flags flags)
Thierry Reding29a1f2332014-04-25 17:10:06 +0200256{
Dmitry Torokhov22c40362017-02-12 17:13:55 -0800257 return NULL;
Thierry Reding29a1f2332014-04-25 17:10:06 +0200258}
259
260static inline struct gpio_desc *__must_check
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +0100261devm_gpiod_get_index_optional(struct device *dev, const char *con_id,
Linus Walleij0dbc8b72014-09-01 15:15:40 +0200262 unsigned int index, enum gpiod_flags flags)
Thierry Reding29a1f2332014-04-25 17:10:06 +0200263{
Dmitry Torokhov22c40362017-02-12 17:13:55 -0800264 return NULL;
Thierry Reding29a1f2332014-04-25 17:10:06 +0200265}
266
Rojhalat Ibrahim331758e2015-02-11 17:28:02 +0100267static inline struct gpio_descs *__must_check
268devm_gpiod_get_array(struct device *dev, const char *con_id,
269 enum gpiod_flags flags)
270{
271 return ERR_PTR(-ENOSYS);
272}
273
274static inline struct gpio_descs *__must_check
275devm_gpiod_get_array_optional(struct device *dev, const char *con_id,
276 enum gpiod_flags flags)
277{
Dmitry Torokhov22c40362017-02-12 17:13:55 -0800278 return NULL;
Rojhalat Ibrahim331758e2015-02-11 17:28:02 +0100279}
280
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700281static inline void devm_gpiod_put(struct device *dev, struct gpio_desc *desc)
282{
283 might_sleep();
284
285 /* GPIO can never have been requested */
286 WARN_ON(1);
287}
288
Rojhalat Ibrahim331758e2015-02-11 17:28:02 +0100289static inline void devm_gpiod_put_array(struct device *dev,
290 struct gpio_descs *descs)
291{
292 might_sleep();
293
294 /* GPIO can never have been requested */
295 WARN_ON(1);
296}
297
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700298
299static inline int gpiod_get_direction(const struct gpio_desc *desc)
300{
301 /* GPIO can never have been requested */
302 WARN_ON(1);
303 return -ENOSYS;
304}
305static inline int gpiod_direction_input(struct gpio_desc *desc)
306{
307 /* GPIO can never have been requested */
308 WARN_ON(1);
309 return -ENOSYS;
310}
311static inline int gpiod_direction_output(struct gpio_desc *desc, int value)
312{
313 /* GPIO can never have been requested */
314 WARN_ON(1);
315 return -ENOSYS;
316}
Philipp Zabelef70bbe2014-01-07 12:34:11 +0100317static inline int gpiod_direction_output_raw(struct gpio_desc *desc, int value)
318{
319 /* GPIO can never have been requested */
320 WARN_ON(1);
321 return -ENOSYS;
322}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700323
324
325static inline int gpiod_get_value(const struct gpio_desc *desc)
326{
327 /* GPIO can never have been requested */
328 WARN_ON(1);
329 return 0;
330}
Lukas Wunnereec1d562017-10-12 12:40:10 +0200331static inline int gpiod_get_array_value(unsigned int array_size,
332 struct gpio_desc **desc_array,
333 int *value_array)
334{
335 /* GPIO can never have been requested */
336 WARN_ON(1);
337 return 0;
338}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700339static inline void gpiod_set_value(struct gpio_desc *desc, int value)
340{
341 /* GPIO can never have been requested */
342 WARN_ON(1);
343}
Rojhalat Ibrahim3fff99b2015-05-13 11:04:56 +0200344static inline void gpiod_set_array_value(unsigned int array_size,
345 struct gpio_desc **desc_array,
346 int *value_array)
Rojhalat Ibrahim5f424242014-11-04 17:12:06 +0100347{
348 /* GPIO can never have been requested */
349 WARN_ON(1);
350}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700351static inline int gpiod_get_raw_value(const struct gpio_desc *desc)
352{
353 /* GPIO can never have been requested */
354 WARN_ON(1);
355 return 0;
356}
Lukas Wunnereec1d562017-10-12 12:40:10 +0200357static inline int gpiod_get_raw_array_value(unsigned int array_size,
358 struct gpio_desc **desc_array,
359 int *value_array)
360{
361 /* GPIO can never have been requested */
362 WARN_ON(1);
363 return 0;
364}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700365static inline void gpiod_set_raw_value(struct gpio_desc *desc, int value)
366{
367 /* GPIO can never have been requested */
368 WARN_ON(1);
369}
Laura Abbott30277432018-05-21 10:57:07 -0700370static inline int gpiod_set_raw_array_value(unsigned int array_size,
Rojhalat Ibrahim3fff99b2015-05-13 11:04:56 +0200371 struct gpio_desc **desc_array,
372 int *value_array)
Rojhalat Ibrahim5f424242014-11-04 17:12:06 +0100373{
374 /* GPIO can never have been requested */
375 WARN_ON(1);
Laura Abbott30277432018-05-21 10:57:07 -0700376 return 0;
Rojhalat Ibrahim5f424242014-11-04 17:12:06 +0100377}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700378
379static inline int gpiod_get_value_cansleep(const struct gpio_desc *desc)
380{
381 /* GPIO can never have been requested */
382 WARN_ON(1);
383 return 0;
384}
Lukas Wunnereec1d562017-10-12 12:40:10 +0200385static inline int gpiod_get_array_value_cansleep(unsigned int array_size,
386 struct gpio_desc **desc_array,
387 int *value_array)
388{
389 /* GPIO can never have been requested */
390 WARN_ON(1);
391 return 0;
392}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700393static inline void gpiod_set_value_cansleep(struct gpio_desc *desc, int value)
394{
395 /* GPIO can never have been requested */
396 WARN_ON(1);
397}
Rojhalat Ibrahim3fff99b2015-05-13 11:04:56 +0200398static inline void gpiod_set_array_value_cansleep(unsigned int array_size,
Rojhalat Ibrahim5f424242014-11-04 17:12:06 +0100399 struct gpio_desc **desc_array,
400 int *value_array)
401{
402 /* GPIO can never have been requested */
403 WARN_ON(1);
404}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700405static inline int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc)
406{
407 /* GPIO can never have been requested */
408 WARN_ON(1);
409 return 0;
410}
Lukas Wunnereec1d562017-10-12 12:40:10 +0200411static inline int gpiod_get_raw_array_value_cansleep(unsigned int array_size,
412 struct gpio_desc **desc_array,
413 int *value_array)
414{
415 /* GPIO can never have been requested */
416 WARN_ON(1);
417 return 0;
418}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700419static inline void gpiod_set_raw_value_cansleep(struct gpio_desc *desc,
420 int value)
421{
422 /* GPIO can never have been requested */
423 WARN_ON(1);
424}
Laura Abbott30277432018-05-21 10:57:07 -0700425static inline int gpiod_set_raw_array_value_cansleep(unsigned int array_size,
Rojhalat Ibrahim5f424242014-11-04 17:12:06 +0100426 struct gpio_desc **desc_array,
427 int *value_array)
428{
429 /* GPIO can never have been requested */
430 WARN_ON(1);
Laura Abbott30277432018-05-21 10:57:07 -0700431 return 0;
Rojhalat Ibrahim5f424242014-11-04 17:12:06 +0100432}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700433
434static inline int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce)
435{
436 /* GPIO can never have been requested */
437 WARN_ON(1);
438 return -ENOSYS;
439}
440
Andrew Jefferye10f72b2017-11-30 14:25:24 +1030441static inline int gpiod_set_transitory(struct gpio_desc *desc, bool transitory)
442{
443 /* GPIO can never have been requested */
444 WARN_ON(1);
445 return -ENOSYS;
446}
447
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700448static inline int gpiod_is_active_low(const struct gpio_desc *desc)
449{
450 /* GPIO can never have been requested */
451 WARN_ON(1);
452 return 0;
453}
454static inline int gpiod_cansleep(const struct gpio_desc *desc)
455{
456 /* GPIO can never have been requested */
457 WARN_ON(1);
458 return 0;
459}
460
461static inline int gpiod_to_irq(const struct gpio_desc *desc)
462{
463 /* GPIO can never have been requested */
464 WARN_ON(1);
465 return -EINVAL;
466}
467
Linus Walleij90b39402018-06-01 13:21:27 +0200468static inline void gpiod_set_consumer_name(struct gpio_desc *desc, const char *name)
469{
470 /* GPIO can never have been requested */
471 WARN_ON(1);
472}
473
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700474static inline struct gpio_desc *gpio_to_desc(unsigned gpio)
475{
476 return ERR_PTR(-EINVAL);
477}
Markus Pargmannc0017ed2015-08-14 16:10:59 +0200478
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700479static inline int desc_to_gpio(const struct gpio_desc *desc)
480{
481 /* GPIO can never have been requested */
482 WARN_ON(1);
483 return -EINVAL;
484}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700485
Geert Uytterhoeven496e7ce2015-05-07 01:08:08 -0700486/* Child properties interface */
Linus Walleij92542ed2017-12-29 22:52:02 +0100487struct device_node;
Geert Uytterhoeven496e7ce2015-05-07 01:08:08 -0700488struct fwnode_handle;
489
Andy Shevchenkoa264d102017-01-09 16:02:28 +0200490static inline
Linus Walleij92542ed2017-12-29 22:52:02 +0100491struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev,
492 struct device_node *node,
493 const char *propname, int index,
494 enum gpiod_flags dflags,
495 const char *label)
496{
497 return ERR_PTR(-ENOSYS);
498}
499
500static inline
Andy Shevchenkoa264d102017-01-09 16:02:28 +0200501struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
Boris Brezillon537b94d2017-02-02 14:53:11 +0100502 const char *propname, int index,
Alexander Steinb2987d72017-01-12 17:39:24 +0100503 enum gpiod_flags dflags,
504 const char *label)
Geert Uytterhoeven496e7ce2015-05-07 01:08:08 -0700505{
506 return ERR_PTR(-ENOSYS);
507}
508
Andy Shevchenkoa264d102017-01-09 16:02:28 +0200509static inline
Boris Brezillon537b94d2017-02-02 14:53:11 +0100510struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev,
511 const char *con_id, int index,
512 struct fwnode_handle *child,
513 enum gpiod_flags flags,
514 const char *label)
515{
516 return ERR_PTR(-ENOSYS);
517}
518
519#endif /* CONFIG_GPIOLIB */
520
521static inline
Boris Brezillon4b094792017-02-02 14:53:10 +0100522struct gpio_desc *devm_fwnode_get_gpiod_from_child(struct device *dev,
523 const char *con_id,
524 struct fwnode_handle *child,
525 enum gpiod_flags flags,
526 const char *label)
Geert Uytterhoeven496e7ce2015-05-07 01:08:08 -0700527{
Boris Brezillon537b94d2017-02-02 14:53:11 +0100528 return devm_fwnode_get_index_gpiod_from_child(dev, con_id, 0, child,
529 flags, label);
Geert Uytterhoeven496e7ce2015-05-07 01:08:08 -0700530}
531
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700532#if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS)
533
534int gpiod_export(struct gpio_desc *desc, bool direction_may_change);
535int gpiod_export_link(struct device *dev, const char *name,
536 struct gpio_desc *desc);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700537void gpiod_unexport(struct gpio_desc *desc);
538
539#else /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */
540
541static inline int gpiod_export(struct gpio_desc *desc,
542 bool direction_may_change)
543{
544 return -ENOSYS;
545}
546
547static inline int gpiod_export_link(struct device *dev, const char *name,
548 struct gpio_desc *desc)
549{
550 return -ENOSYS;
551}
552
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700553static inline void gpiod_unexport(struct gpio_desc *desc)
554{
555}
556
557#endif /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */
558
559#endif