blob: 9ddcf50a3c5924ad754d40029a3b0dd707ac556f [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/**
Janusz Krzysztofikbf9346f2018-09-05 23:50:06 +020021 * 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/**
Rojhalat Ibrahim66858522015-02-11 17:27:58 +010029 * Struct containing an array of descriptors that can be obtained using
30 * gpiod_get_array().
31 */
32struct gpio_descs {
Janusz Krzysztofikbf9346f2018-09-05 23:50:06 +020033 struct gpio_array *info;
Rojhalat Ibrahim66858522015-02-11 17:27:58 +010034 unsigned int ndescs;
35 struct gpio_desc *desc[];
36};
37
Alexandre Courbot39b2bbe2014-07-25 23:38:36 +090038#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)
Linus Walleijf926dfc2017-09-10 19:26:22 +020041#define GPIOD_FLAGS_BIT_OPEN_DRAIN BIT(3)
Linus Walleijb0ce7b292018-10-12 14:54:12 +020042#define GPIOD_FLAGS_BIT_NONEXCLUSIVE BIT(4)
Alexandre Courbot39b2bbe2014-07-25 23:38:36 +090043
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,
Andy Shevchenko0969a202018-07-27 17:47:01 +030054 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,
Alexandre Courbot39b2bbe2014-07-25 23:38:36 +090056};
57
Linus Walleij58b84f62014-08-19 12:00:53 -050058#ifdef CONFIG_GPIOLIB
59
Rojhalat Ibrahim66858522015-02-11 17:27:58 +010060/* Return the number of GPIOs associated with a device / function */
61int gpiod_count(struct device *dev, const char *con_id);
62
Alexandre Courbotbae48da2013-10-17 10:21:38 -070063/* Acquire and dispose GPIOs */
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +010064struct gpio_desc *__must_check gpiod_get(struct device *dev,
Alexandre Courbot39b2bbe2014-07-25 23:38:36 +090065 const char *con_id,
66 enum gpiod_flags flags);
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +010067struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
Alexandre Courbotbae48da2013-10-17 10:21:38 -070068 const char *con_id,
Alexandre Courbot39b2bbe2014-07-25 23:38:36 +090069 unsigned int idx,
70 enum gpiod_flags flags);
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +010071struct gpio_desc *__must_check gpiod_get_optional(struct device *dev,
Alexandre Courbot39b2bbe2014-07-25 23:38:36 +090072 const char *con_id,
73 enum gpiod_flags flags);
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +010074struct gpio_desc *__must_check gpiod_get_index_optional(struct device *dev,
Thierry Reding29a1f2332014-04-25 17:10:06 +020075 const char *con_id,
Alexandre Courbot39b2bbe2014-07-25 23:38:36 +090076 unsigned int index,
77 enum gpiod_flags flags);
Rojhalat Ibrahim66858522015-02-11 17:27:58 +010078struct 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);
Alexandre Courbotbae48da2013-10-17 10:21:38 -070084void gpiod_put(struct gpio_desc *desc);
Rojhalat Ibrahim66858522015-02-11 17:27:58 +010085void gpiod_put_array(struct gpio_descs *descs);
Alexandre Courbotbae48da2013-10-17 10:21:38 -070086
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +010087struct gpio_desc *__must_check devm_gpiod_get(struct device *dev,
Alexandre Courbot39b2bbe2014-07-25 23:38:36 +090088 const char *con_id,
89 enum gpiod_flags flags);
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +010090struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev,
Alexandre Courbotbae48da2013-10-17 10:21:38 -070091 const char *con_id,
Alexandre Courbot39b2bbe2014-07-25 23:38:36 +090092 unsigned int idx,
93 enum gpiod_flags flags);
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +010094struct gpio_desc *__must_check devm_gpiod_get_optional(struct device *dev,
Alexandre Courbot39b2bbe2014-07-25 23:38:36 +090095 const char *con_id,
96 enum gpiod_flags flags);
Thierry Reding29a1f2332014-04-25 17:10:06 +020097struct gpio_desc *__must_check
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +010098devm_gpiod_get_index_optional(struct device *dev, const char *con_id,
Alexandre Courbot39b2bbe2014-07-25 23:38:36 +090099 unsigned int index, enum gpiod_flags flags);
Rojhalat Ibrahim331758e2015-02-11 17:28:02 +0100100struct 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);
Alexandre Courbotbae48da2013-10-17 10:21:38 -0700106void devm_gpiod_put(struct device *dev, struct gpio_desc *desc);
Linus Walleij891ddbc2018-12-06 13:43:46 +0100107void devm_gpiod_unhinge(struct device *dev, struct gpio_desc *desc);
Rojhalat Ibrahim331758e2015-02-11 17:28:02 +0100108void devm_gpiod_put_array(struct device *dev, struct gpio_descs *descs);
Alexandre Courbotbae48da2013-10-17 10:21:38 -0700109
Alexandre Courbot8e53b0f2014-11-25 17:16:31 +0900110int gpiod_get_direction(struct gpio_desc *desc);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700111int gpiod_direction_input(struct gpio_desc *desc);
112int gpiod_direction_output(struct gpio_desc *desc, int value);
Philipp Zabelef70bbe2014-01-07 12:34:11 +0100113int gpiod_direction_output_raw(struct gpio_desc *desc, int value);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700114
115/* Value get/set from non-sleeping context */
116int gpiod_get_value(const struct gpio_desc *desc);
Lukas Wunnereec1d562017-10-12 12:40:10 +0200117int gpiod_get_array_value(unsigned int array_size,
Janusz Krzysztofikb9762be2018-09-05 23:50:05 +0200118 struct gpio_desc **desc_array,
Janusz Krzysztofik77588c12018-09-05 23:50:07 +0200119 struct gpio_array *array_info,
Janusz Krzysztofikb9762be2018-09-05 23:50:05 +0200120 unsigned long *value_bitmap);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700121void gpiod_set_value(struct gpio_desc *desc, int value);
Geert Uytterhoevencf9af0d2018-09-27 13:38:09 +0200122int 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);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700126int gpiod_get_raw_value(const struct gpio_desc *desc);
Lukas Wunnereec1d562017-10-12 12:40:10 +0200127int gpiod_get_raw_array_value(unsigned int array_size,
128 struct gpio_desc **desc_array,
Janusz Krzysztofik77588c12018-09-05 23:50:07 +0200129 struct gpio_array *array_info,
Janusz Krzysztofikb9762be2018-09-05 23:50:05 +0200130 unsigned long *value_bitmap);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700131void gpiod_set_raw_value(struct gpio_desc *desc, int value);
Laura Abbott30277432018-05-21 10:57:07 -0700132int gpiod_set_raw_array_value(unsigned int array_size,
Geert Uytterhoeven3c940662018-09-27 13:38:10 +0200133 struct gpio_desc **desc_array,
134 struct gpio_array *array_info,
135 unsigned long *value_bitmap);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700136
137/* Value get/set from sleeping context */
138int gpiod_get_value_cansleep(const struct gpio_desc *desc);
Lukas Wunnereec1d562017-10-12 12:40:10 +0200139int gpiod_get_array_value_cansleep(unsigned int array_size,
140 struct gpio_desc **desc_array,
Janusz Krzysztofik77588c12018-09-05 23:50:07 +0200141 struct gpio_array *array_info,
Janusz Krzysztofikb9762be2018-09-05 23:50:05 +0200142 unsigned long *value_bitmap);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700143void gpiod_set_value_cansleep(struct gpio_desc *desc, int value);
Geert Uytterhoevencf9af0d2018-09-27 13:38:09 +0200144int 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);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700148int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc);
Lukas Wunnereec1d562017-10-12 12:40:10 +0200149int gpiod_get_raw_array_value_cansleep(unsigned int array_size,
150 struct gpio_desc **desc_array,
Janusz Krzysztofik77588c12018-09-05 23:50:07 +0200151 struct gpio_array *array_info,
Janusz Krzysztofikb9762be2018-09-05 23:50:05 +0200152 unsigned long *value_bitmap);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700153void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, int value);
Laura Abbott30277432018-05-21 10:57:07 -0700154int gpiod_set_raw_array_value_cansleep(unsigned int array_size,
Geert Uytterhoeven3c940662018-09-27 13:38:10 +0200155 struct gpio_desc **desc_array,
156 struct gpio_array *array_info,
157 unsigned long *value_bitmap);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700158
159int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce);
Andrew Jefferye10f72b2017-11-30 14:25:24 +1030160int gpiod_set_transitory(struct gpio_desc *desc, bool transitory);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700161
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);
Muchun Song18534df2018-11-01 21:12:50 +0800166int gpiod_set_consumer_name(struct gpio_desc *desc, const char *name);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700167
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);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700171
Mika Westerberg40b73182014-10-21 13:33:59 +0200172/* Child properties interface */
Linus Walleij92542ed2017-12-29 22:52:02 +0100173struct device_node;
Mika Westerberg40b73182014-10-21 13:33:59 +0200174struct fwnode_handle;
175
Linus Walleijfe6c4732018-12-06 13:43:42 +0100176struct gpio_desc *gpiod_get_from_of_node(struct device_node *node,
177 const char *propname, int index,
178 enum gpiod_flags dflags,
179 const char *label);
Linus Walleij92542ed2017-12-29 22:52:02 +0100180struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev,
181 struct device_node *node,
182 const char *propname, int index,
183 enum gpiod_flags dflags,
184 const char *label);
Mika Westerberg40b73182014-10-21 13:33:59 +0200185struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
Boris Brezillon537b94d2017-02-02 14:53:11 +0100186 const char *propname, int index,
Alexander Steinb2987d72017-01-12 17:39:24 +0100187 enum gpiod_flags dflags,
188 const char *label);
Boris Brezillon537b94d2017-02-02 14:53:11 +0100189struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev,
190 const char *con_id, int index,
191 struct fwnode_handle *child,
192 enum gpiod_flags flags,
193 const char *label);
Linus Walleij3498d862017-02-21 14:19:45 +0100194
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700195#else /* CONFIG_GPIOLIB */
196
Rojhalat Ibrahim66858522015-02-11 17:27:58 +0100197static inline int gpiod_count(struct device *dev, const char *con_id)
198{
199 return 0;
200}
201
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +0100202static inline struct gpio_desc *__must_check gpiod_get(struct device *dev,
203 const char *con_id,
204 enum gpiod_flags flags)
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700205{
206 return ERR_PTR(-ENOSYS);
207}
Linus Walleij0dbc8b72014-09-01 15:15:40 +0200208static inline struct gpio_desc *__must_check
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +0100209gpiod_get_index(struct device *dev,
210 const char *con_id,
211 unsigned int idx,
212 enum gpiod_flags flags)
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700213{
214 return ERR_PTR(-ENOSYS);
215}
Thierry Reding29a1f2332014-04-25 17:10:06 +0200216
217static inline struct gpio_desc *__must_check
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +0100218gpiod_get_optional(struct device *dev, const char *con_id,
219 enum gpiod_flags flags)
Thierry Reding29a1f2332014-04-25 17:10:06 +0200220{
Dmitry Torokhov22c40362017-02-12 17:13:55 -0800221 return NULL;
Thierry Reding29a1f2332014-04-25 17:10:06 +0200222}
223
224static inline struct gpio_desc *__must_check
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +0100225gpiod_get_index_optional(struct device *dev, const char *con_id,
226 unsigned int index, enum gpiod_flags flags)
Thierry Reding29a1f2332014-04-25 17:10:06 +0200227{
Dmitry Torokhov22c40362017-02-12 17:13:55 -0800228 return NULL;
Thierry Reding29a1f2332014-04-25 17:10:06 +0200229}
230
Rojhalat Ibrahim66858522015-02-11 17:27:58 +0100231static inline struct gpio_descs *__must_check
232gpiod_get_array(struct device *dev, const char *con_id,
233 enum gpiod_flags flags)
234{
235 return ERR_PTR(-ENOSYS);
236}
237
238static inline struct gpio_descs *__must_check
239gpiod_get_array_optional(struct device *dev, const char *con_id,
240 enum gpiod_flags flags)
241{
Dmitry Torokhov22c40362017-02-12 17:13:55 -0800242 return NULL;
Rojhalat Ibrahim66858522015-02-11 17:27:58 +0100243}
244
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700245static inline void gpiod_put(struct gpio_desc *desc)
246{
247 might_sleep();
248
249 /* GPIO can never have been requested */
250 WARN_ON(1);
251}
252
Linus Walleij891ddbc2018-12-06 13:43:46 +0100253static inline void devm_gpiod_unhinge(struct device *dev,
254 struct gpio_desc *desc)
255{
256 might_sleep();
257
258 /* GPIO can never have been requested */
259 WARN_ON(1);
260}
261
Rojhalat Ibrahim66858522015-02-11 17:27:58 +0100262static inline void gpiod_put_array(struct gpio_descs *descs)
263{
264 might_sleep();
265
266 /* GPIO can never have been requested */
267 WARN_ON(1);
268}
269
Linus Walleij0dbc8b72014-09-01 15:15:40 +0200270static inline struct gpio_desc *__must_check
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +0100271devm_gpiod_get(struct device *dev,
Linus Walleij0dbc8b72014-09-01 15:15:40 +0200272 const char *con_id,
273 enum gpiod_flags flags)
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700274{
275 return ERR_PTR(-ENOSYS);
276}
277static inline
Linus Walleij0dbc8b72014-09-01 15:15:40 +0200278struct gpio_desc *__must_check
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +0100279devm_gpiod_get_index(struct device *dev,
Linus Walleij0dbc8b72014-09-01 15:15:40 +0200280 const char *con_id,
281 unsigned int idx,
282 enum gpiod_flags flags)
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700283{
284 return ERR_PTR(-ENOSYS);
285}
Thierry Reding29a1f2332014-04-25 17:10:06 +0200286
287static inline struct gpio_desc *__must_check
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +0100288devm_gpiod_get_optional(struct device *dev, const char *con_id,
Linus Walleij0dbc8b72014-09-01 15:15:40 +0200289 enum gpiod_flags flags)
Thierry Reding29a1f2332014-04-25 17:10:06 +0200290{
Dmitry Torokhov22c40362017-02-12 17:13:55 -0800291 return NULL;
Thierry Reding29a1f2332014-04-25 17:10:06 +0200292}
293
294static inline struct gpio_desc *__must_check
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +0100295devm_gpiod_get_index_optional(struct device *dev, const char *con_id,
Linus Walleij0dbc8b72014-09-01 15:15:40 +0200296 unsigned int index, enum gpiod_flags flags)
Thierry Reding29a1f2332014-04-25 17:10:06 +0200297{
Dmitry Torokhov22c40362017-02-12 17:13:55 -0800298 return NULL;
Thierry Reding29a1f2332014-04-25 17:10:06 +0200299}
300
Rojhalat Ibrahim331758e2015-02-11 17:28:02 +0100301static inline struct gpio_descs *__must_check
302devm_gpiod_get_array(struct device *dev, const char *con_id,
303 enum gpiod_flags flags)
304{
305 return ERR_PTR(-ENOSYS);
306}
307
308static inline struct gpio_descs *__must_check
309devm_gpiod_get_array_optional(struct device *dev, const char *con_id,
310 enum gpiod_flags flags)
311{
Dmitry Torokhov22c40362017-02-12 17:13:55 -0800312 return NULL;
Rojhalat Ibrahim331758e2015-02-11 17:28:02 +0100313}
314
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700315static inline void devm_gpiod_put(struct device *dev, struct gpio_desc *desc)
316{
317 might_sleep();
318
319 /* GPIO can never have been requested */
320 WARN_ON(1);
321}
322
Rojhalat Ibrahim331758e2015-02-11 17:28:02 +0100323static inline void devm_gpiod_put_array(struct device *dev,
324 struct gpio_descs *descs)
325{
326 might_sleep();
327
328 /* GPIO can never have been requested */
329 WARN_ON(1);
330}
331
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700332
333static inline int gpiod_get_direction(const struct gpio_desc *desc)
334{
335 /* GPIO can never have been requested */
336 WARN_ON(1);
337 return -ENOSYS;
338}
339static inline int gpiod_direction_input(struct gpio_desc *desc)
340{
341 /* GPIO can never have been requested */
342 WARN_ON(1);
343 return -ENOSYS;
344}
345static inline int gpiod_direction_output(struct gpio_desc *desc, int value)
346{
347 /* GPIO can never have been requested */
348 WARN_ON(1);
349 return -ENOSYS;
350}
Philipp Zabelef70bbe2014-01-07 12:34:11 +0100351static inline int gpiod_direction_output_raw(struct gpio_desc *desc, int value)
352{
353 /* GPIO can never have been requested */
354 WARN_ON(1);
355 return -ENOSYS;
356}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700357
358
359static inline int gpiod_get_value(const struct gpio_desc *desc)
360{
361 /* GPIO can never have been requested */
362 WARN_ON(1);
363 return 0;
364}
Lukas Wunnereec1d562017-10-12 12:40:10 +0200365static inline int gpiod_get_array_value(unsigned int array_size,
366 struct gpio_desc **desc_array,
Janusz Krzysztofik77588c12018-09-05 23:50:07 +0200367 struct gpio_array *array_info,
Janusz Krzysztofikb9762be2018-09-05 23:50:05 +0200368 unsigned long *value_bitmap)
Lukas Wunnereec1d562017-10-12 12:40:10 +0200369{
370 /* GPIO can never have been requested */
371 WARN_ON(1);
372 return 0;
373}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700374static inline void gpiod_set_value(struct gpio_desc *desc, int value)
375{
376 /* GPIO can never have been requested */
377 WARN_ON(1);
378}
Geert Uytterhoevencf9af0d2018-09-27 13:38:09 +0200379static inline int gpiod_set_array_value(unsigned int array_size,
380 struct gpio_desc **desc_array,
381 struct gpio_array *array_info,
382 unsigned long *value_bitmap)
Rojhalat Ibrahim5f424242014-11-04 17:12:06 +0100383{
384 /* GPIO can never have been requested */
385 WARN_ON(1);
Geert Uytterhoevencf9af0d2018-09-27 13:38:09 +0200386 return 0;
Rojhalat Ibrahim5f424242014-11-04 17:12:06 +0100387}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700388static inline int gpiod_get_raw_value(const struct gpio_desc *desc)
389{
390 /* GPIO can never have been requested */
391 WARN_ON(1);
392 return 0;
393}
Lukas Wunnereec1d562017-10-12 12:40:10 +0200394static inline int gpiod_get_raw_array_value(unsigned int array_size,
395 struct gpio_desc **desc_array,
Janusz Krzysztofik77588c12018-09-05 23:50:07 +0200396 struct gpio_array *array_info,
Janusz Krzysztofikb9762be2018-09-05 23:50:05 +0200397 unsigned long *value_bitmap)
Lukas Wunnereec1d562017-10-12 12:40:10 +0200398{
399 /* GPIO can never have been requested */
400 WARN_ON(1);
401 return 0;
402}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700403static inline void gpiod_set_raw_value(struct gpio_desc *desc, int value)
404{
405 /* GPIO can never have been requested */
406 WARN_ON(1);
407}
Laura Abbott30277432018-05-21 10:57:07 -0700408static inline int gpiod_set_raw_array_value(unsigned int array_size,
Geert Uytterhoeven3c940662018-09-27 13:38:10 +0200409 struct gpio_desc **desc_array,
410 struct gpio_array *array_info,
411 unsigned long *value_bitmap)
Rojhalat Ibrahim5f424242014-11-04 17:12:06 +0100412{
413 /* GPIO can never have been requested */
414 WARN_ON(1);
Laura Abbott30277432018-05-21 10:57:07 -0700415 return 0;
Rojhalat Ibrahim5f424242014-11-04 17:12:06 +0100416}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700417
418static inline int gpiod_get_value_cansleep(const struct gpio_desc *desc)
419{
420 /* GPIO can never have been requested */
421 WARN_ON(1);
422 return 0;
423}
Lukas Wunnereec1d562017-10-12 12:40:10 +0200424static inline int gpiod_get_array_value_cansleep(unsigned int array_size,
425 struct gpio_desc **desc_array,
Janusz Krzysztofik77588c12018-09-05 23:50:07 +0200426 struct gpio_array *array_info,
Janusz Krzysztofikb9762be2018-09-05 23:50:05 +0200427 unsigned long *value_bitmap)
Lukas Wunnereec1d562017-10-12 12:40:10 +0200428{
429 /* GPIO can never have been requested */
430 WARN_ON(1);
431 return 0;
432}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700433static inline void gpiod_set_value_cansleep(struct gpio_desc *desc, int value)
434{
435 /* GPIO can never have been requested */
436 WARN_ON(1);
437}
Geert Uytterhoevencf9af0d2018-09-27 13:38:09 +0200438static inline int gpiod_set_array_value_cansleep(unsigned int array_size,
Rojhalat Ibrahim5f424242014-11-04 17:12:06 +0100439 struct gpio_desc **desc_array,
Janusz Krzysztofik77588c12018-09-05 23:50:07 +0200440 struct gpio_array *array_info,
Janusz Krzysztofikb9762be2018-09-05 23:50:05 +0200441 unsigned long *value_bitmap)
Rojhalat Ibrahim5f424242014-11-04 17:12:06 +0100442{
443 /* GPIO can never have been requested */
444 WARN_ON(1);
Geert Uytterhoevencf9af0d2018-09-27 13:38:09 +0200445 return 0;
Rojhalat Ibrahim5f424242014-11-04 17:12:06 +0100446}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700447static inline int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc)
448{
449 /* GPIO can never have been requested */
450 WARN_ON(1);
451 return 0;
452}
Lukas Wunnereec1d562017-10-12 12:40:10 +0200453static inline int gpiod_get_raw_array_value_cansleep(unsigned int array_size,
454 struct gpio_desc **desc_array,
Janusz Krzysztofik77588c12018-09-05 23:50:07 +0200455 struct gpio_array *array_info,
Janusz Krzysztofikb9762be2018-09-05 23:50:05 +0200456 unsigned long *value_bitmap)
Lukas Wunnereec1d562017-10-12 12:40:10 +0200457{
458 /* GPIO can never have been requested */
459 WARN_ON(1);
460 return 0;
461}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700462static inline void gpiod_set_raw_value_cansleep(struct gpio_desc *desc,
463 int value)
464{
465 /* GPIO can never have been requested */
466 WARN_ON(1);
467}
Laura Abbott30277432018-05-21 10:57:07 -0700468static inline int gpiod_set_raw_array_value_cansleep(unsigned int array_size,
Rojhalat Ibrahim5f424242014-11-04 17:12:06 +0100469 struct gpio_desc **desc_array,
Janusz Krzysztofik77588c12018-09-05 23:50:07 +0200470 struct gpio_array *array_info,
Janusz Krzysztofikb9762be2018-09-05 23:50:05 +0200471 unsigned long *value_bitmap)
Rojhalat Ibrahim5f424242014-11-04 17:12:06 +0100472{
473 /* GPIO can never have been requested */
474 WARN_ON(1);
Laura Abbott30277432018-05-21 10:57:07 -0700475 return 0;
Rojhalat Ibrahim5f424242014-11-04 17:12:06 +0100476}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700477
478static inline int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce)
479{
480 /* GPIO can never have been requested */
481 WARN_ON(1);
482 return -ENOSYS;
483}
484
Andrew Jefferye10f72b2017-11-30 14:25:24 +1030485static inline int gpiod_set_transitory(struct gpio_desc *desc, bool transitory)
486{
487 /* GPIO can never have been requested */
488 WARN_ON(1);
489 return -ENOSYS;
490}
491
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700492static inline int gpiod_is_active_low(const struct gpio_desc *desc)
493{
494 /* GPIO can never have been requested */
495 WARN_ON(1);
496 return 0;
497}
498static inline int gpiod_cansleep(const struct gpio_desc *desc)
499{
500 /* GPIO can never have been requested */
501 WARN_ON(1);
502 return 0;
503}
504
505static inline int gpiod_to_irq(const struct gpio_desc *desc)
506{
507 /* GPIO can never have been requested */
508 WARN_ON(1);
509 return -EINVAL;
510}
511
Muchun Song18534df2018-11-01 21:12:50 +0800512static inline int gpiod_set_consumer_name(struct gpio_desc *desc,
513 const char *name)
Linus Walleij90b39402e2018-06-01 13:21:27 +0200514{
515 /* GPIO can never have been requested */
516 WARN_ON(1);
Muchun Song18534df2018-11-01 21:12:50 +0800517 return -EINVAL;
Linus Walleij90b39402e2018-06-01 13:21:27 +0200518}
519
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700520static inline struct gpio_desc *gpio_to_desc(unsigned gpio)
521{
Krzysztof Kozlowskic5510b82018-12-06 10:45:49 +0100522 return NULL;
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700523}
Markus Pargmannc0017ed2015-08-14 16:10:59 +0200524
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700525static inline int desc_to_gpio(const struct gpio_desc *desc)
526{
527 /* GPIO can never have been requested */
528 WARN_ON(1);
529 return -EINVAL;
530}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700531
Geert Uytterhoeven496e7ce2015-05-07 01:08:08 -0700532/* Child properties interface */
Linus Walleij92542ed2017-12-29 22:52:02 +0100533struct device_node;
Geert Uytterhoeven496e7ce2015-05-07 01:08:08 -0700534struct fwnode_handle;
535
Andy Shevchenkoa264d102017-01-09 16:02:28 +0200536static inline
Linus Walleijfe6c4732018-12-06 13:43:42 +0100537struct gpio_desc *gpiod_get_from_of_node(struct device_node *node,
538 const char *propname, int index,
539 enum gpiod_flags dflags,
540 const char *label)
541{
542 return ERR_PTR(-ENOSYS);
543}
544
545static inline
Linus Walleij92542ed2017-12-29 22:52:02 +0100546struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev,
547 struct device_node *node,
548 const char *propname, int index,
549 enum gpiod_flags dflags,
550 const char *label)
551{
552 return ERR_PTR(-ENOSYS);
553}
554
555static inline
Andy Shevchenkoa264d102017-01-09 16:02:28 +0200556struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
Boris Brezillon537b94d2017-02-02 14:53:11 +0100557 const char *propname, int index,
Alexander Steinb2987d72017-01-12 17:39:24 +0100558 enum gpiod_flags dflags,
559 const char *label)
Geert Uytterhoeven496e7ce2015-05-07 01:08:08 -0700560{
561 return ERR_PTR(-ENOSYS);
562}
563
Andy Shevchenkoa264d102017-01-09 16:02:28 +0200564static inline
Boris Brezillon537b94d2017-02-02 14:53:11 +0100565struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev,
566 const char *con_id, int index,
567 struct fwnode_handle *child,
568 enum gpiod_flags flags,
569 const char *label)
570{
571 return ERR_PTR(-ENOSYS);
572}
573
574#endif /* CONFIG_GPIOLIB */
575
576static inline
Boris Brezillon4b094792017-02-02 14:53:10 +0100577struct gpio_desc *devm_fwnode_get_gpiod_from_child(struct device *dev,
578 const char *con_id,
579 struct fwnode_handle *child,
580 enum gpiod_flags flags,
581 const char *label)
Geert Uytterhoeven496e7ce2015-05-07 01:08:08 -0700582{
Boris Brezillon537b94d2017-02-02 14:53:11 +0100583 return devm_fwnode_get_index_gpiod_from_child(dev, con_id, 0, child,
584 flags, label);
Geert Uytterhoeven496e7ce2015-05-07 01:08:08 -0700585}
586
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700587#if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS)
588
589int gpiod_export(struct gpio_desc *desc, bool direction_may_change);
590int gpiod_export_link(struct device *dev, const char *name,
591 struct gpio_desc *desc);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700592void gpiod_unexport(struct gpio_desc *desc);
593
594#else /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */
595
596static inline int gpiod_export(struct gpio_desc *desc,
597 bool direction_may_change)
598{
599 return -ENOSYS;
600}
601
602static inline int gpiod_export_link(struct device *dev, const char *name,
603 struct gpio_desc *desc)
604{
605 return -ENOSYS;
606}
607
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700608static inline void gpiod_unexport(struct gpio_desc *desc)
609{
610}
611
612#endif /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */
613
614#endif