blob: ed070512b40eed97a99b1b837b5b980584d3a9b3 [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);
Rojhalat Ibrahim331758e2015-02-11 17:28:02 +0100107void devm_gpiod_put_array(struct device *dev, struct gpio_descs *descs);
Alexandre Courbotbae48da2013-10-17 10:21:38 -0700108
Alexandre Courbot8e53b0f2014-11-25 17:16:31 +0900109int gpiod_get_direction(struct gpio_desc *desc);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700110int gpiod_direction_input(struct gpio_desc *desc);
111int gpiod_direction_output(struct gpio_desc *desc, int value);
Philipp Zabelef70bbe2014-01-07 12:34:11 +0100112int gpiod_direction_output_raw(struct gpio_desc *desc, int value);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700113
114/* Value get/set from non-sleeping context */
115int gpiod_get_value(const struct gpio_desc *desc);
Lukas Wunnereec1d562017-10-12 12:40:10 +0200116int gpiod_get_array_value(unsigned int array_size,
Janusz Krzysztofikb9762be2018-09-05 23:50:05 +0200117 struct gpio_desc **desc_array,
Janusz Krzysztofik77588c12018-09-05 23:50:07 +0200118 struct gpio_array *array_info,
Janusz Krzysztofikb9762be2018-09-05 23:50:05 +0200119 unsigned long *value_bitmap);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700120void gpiod_set_value(struct gpio_desc *desc, int value);
Geert Uytterhoevencf9af0d2018-09-27 13:38:09 +0200121int gpiod_set_array_value(unsigned int array_size,
122 struct gpio_desc **desc_array,
123 struct gpio_array *array_info,
124 unsigned long *value_bitmap);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700125int gpiod_get_raw_value(const struct gpio_desc *desc);
Lukas Wunnereec1d562017-10-12 12:40:10 +0200126int gpiod_get_raw_array_value(unsigned int array_size,
127 struct gpio_desc **desc_array,
Janusz Krzysztofik77588c12018-09-05 23:50:07 +0200128 struct gpio_array *array_info,
Janusz Krzysztofikb9762be2018-09-05 23:50:05 +0200129 unsigned long *value_bitmap);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700130void gpiod_set_raw_value(struct gpio_desc *desc, int value);
Laura Abbott30277432018-05-21 10:57:07 -0700131int gpiod_set_raw_array_value(unsigned int array_size,
Geert Uytterhoeven3c940662018-09-27 13:38:10 +0200132 struct gpio_desc **desc_array,
133 struct gpio_array *array_info,
134 unsigned long *value_bitmap);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700135
136/* Value get/set from sleeping context */
137int gpiod_get_value_cansleep(const struct gpio_desc *desc);
Lukas Wunnereec1d562017-10-12 12:40:10 +0200138int gpiod_get_array_value_cansleep(unsigned int array_size,
139 struct gpio_desc **desc_array,
Janusz Krzysztofik77588c12018-09-05 23:50:07 +0200140 struct gpio_array *array_info,
Janusz Krzysztofikb9762be2018-09-05 23:50:05 +0200141 unsigned long *value_bitmap);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700142void gpiod_set_value_cansleep(struct gpio_desc *desc, int value);
Geert Uytterhoevencf9af0d2018-09-27 13:38:09 +0200143int gpiod_set_array_value_cansleep(unsigned int array_size,
144 struct gpio_desc **desc_array,
145 struct gpio_array *array_info,
146 unsigned long *value_bitmap);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700147int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc);
Lukas Wunnereec1d562017-10-12 12:40:10 +0200148int gpiod_get_raw_array_value_cansleep(unsigned int array_size,
149 struct gpio_desc **desc_array,
Janusz Krzysztofik77588c12018-09-05 23:50:07 +0200150 struct gpio_array *array_info,
Janusz Krzysztofikb9762be2018-09-05 23:50:05 +0200151 unsigned long *value_bitmap);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700152void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, int value);
Laura Abbott30277432018-05-21 10:57:07 -0700153int gpiod_set_raw_array_value_cansleep(unsigned int array_size,
Geert Uytterhoeven3c940662018-09-27 13:38:10 +0200154 struct gpio_desc **desc_array,
155 struct gpio_array *array_info,
156 unsigned long *value_bitmap);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700157
158int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce);
Andrew Jefferye10f72b2017-11-30 14:25:24 +1030159int gpiod_set_transitory(struct gpio_desc *desc, bool transitory);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700160
161int gpiod_is_active_low(const struct gpio_desc *desc);
162int gpiod_cansleep(const struct gpio_desc *desc);
163
164int gpiod_to_irq(const struct gpio_desc *desc);
Muchun Song18534df2018-11-01 21:12:50 +0800165int gpiod_set_consumer_name(struct gpio_desc *desc, const char *name);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700166
167/* Convert between the old gpio_ and new gpiod_ interfaces */
168struct gpio_desc *gpio_to_desc(unsigned gpio);
169int desc_to_gpio(const struct gpio_desc *desc);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700170
Mika Westerberg40b73182014-10-21 13:33:59 +0200171/* Child properties interface */
Linus Walleij92542ed2017-12-29 22:52:02 +0100172struct device_node;
Mika Westerberg40b73182014-10-21 13:33:59 +0200173struct fwnode_handle;
174
Linus Walleij92542ed2017-12-29 22:52:02 +0100175struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev,
176 struct device_node *node,
177 const char *propname, int index,
178 enum gpiod_flags dflags,
179 const char *label);
Mika Westerberg40b73182014-10-21 13:33:59 +0200180struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
Boris Brezillon537b94d2017-02-02 14:53:11 +0100181 const char *propname, int index,
Alexander Steinb2987d72017-01-12 17:39:24 +0100182 enum gpiod_flags dflags,
183 const char *label);
Boris Brezillon537b94d2017-02-02 14:53:11 +0100184struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev,
185 const char *con_id, int index,
186 struct fwnode_handle *child,
187 enum gpiod_flags flags,
188 const char *label);
Linus Walleij3498d862017-02-21 14:19:45 +0100189
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700190#else /* CONFIG_GPIOLIB */
191
Rojhalat Ibrahim66858522015-02-11 17:27:58 +0100192static inline int gpiod_count(struct device *dev, const char *con_id)
193{
194 return 0;
195}
196
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +0100197static inline struct gpio_desc *__must_check gpiod_get(struct device *dev,
198 const char *con_id,
199 enum gpiod_flags flags)
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700200{
201 return ERR_PTR(-ENOSYS);
202}
Linus Walleij0dbc8b72014-09-01 15:15:40 +0200203static inline struct gpio_desc *__must_check
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +0100204gpiod_get_index(struct device *dev,
205 const char *con_id,
206 unsigned int idx,
207 enum gpiod_flags flags)
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700208{
209 return ERR_PTR(-ENOSYS);
210}
Thierry Reding29a1f2332014-04-25 17:10:06 +0200211
212static inline struct gpio_desc *__must_check
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +0100213gpiod_get_optional(struct device *dev, const char *con_id,
214 enum gpiod_flags flags)
Thierry Reding29a1f2332014-04-25 17:10:06 +0200215{
Dmitry Torokhov22c40362017-02-12 17:13:55 -0800216 return NULL;
Thierry Reding29a1f2332014-04-25 17:10:06 +0200217}
218
219static inline struct gpio_desc *__must_check
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +0100220gpiod_get_index_optional(struct device *dev, const char *con_id,
221 unsigned int index, enum gpiod_flags flags)
Thierry Reding29a1f2332014-04-25 17:10:06 +0200222{
Dmitry Torokhov22c40362017-02-12 17:13:55 -0800223 return NULL;
Thierry Reding29a1f2332014-04-25 17:10:06 +0200224}
225
Rojhalat Ibrahim66858522015-02-11 17:27:58 +0100226static inline struct gpio_descs *__must_check
227gpiod_get_array(struct device *dev, const char *con_id,
228 enum gpiod_flags flags)
229{
230 return ERR_PTR(-ENOSYS);
231}
232
233static inline struct gpio_descs *__must_check
234gpiod_get_array_optional(struct device *dev, const char *con_id,
235 enum gpiod_flags flags)
236{
Dmitry Torokhov22c40362017-02-12 17:13:55 -0800237 return NULL;
Rojhalat Ibrahim66858522015-02-11 17:27:58 +0100238}
239
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700240static inline void gpiod_put(struct gpio_desc *desc)
241{
242 might_sleep();
243
244 /* GPIO can never have been requested */
245 WARN_ON(1);
246}
247
Rojhalat Ibrahim66858522015-02-11 17:27:58 +0100248static inline void gpiod_put_array(struct gpio_descs *descs)
249{
250 might_sleep();
251
252 /* GPIO can never have been requested */
253 WARN_ON(1);
254}
255
Linus Walleij0dbc8b72014-09-01 15:15:40 +0200256static inline struct gpio_desc *__must_check
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +0100257devm_gpiod_get(struct device *dev,
Linus Walleij0dbc8b72014-09-01 15:15:40 +0200258 const char *con_id,
259 enum gpiod_flags flags)
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700260{
261 return ERR_PTR(-ENOSYS);
262}
263static inline
Linus Walleij0dbc8b72014-09-01 15:15:40 +0200264struct gpio_desc *__must_check
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +0100265devm_gpiod_get_index(struct device *dev,
Linus Walleij0dbc8b72014-09-01 15:15:40 +0200266 const char *con_id,
267 unsigned int idx,
268 enum gpiod_flags flags)
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700269{
270 return ERR_PTR(-ENOSYS);
271}
Thierry Reding29a1f2332014-04-25 17:10:06 +0200272
273static inline struct gpio_desc *__must_check
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +0100274devm_gpiod_get_optional(struct device *dev, const char *con_id,
Linus Walleij0dbc8b72014-09-01 15:15:40 +0200275 enum gpiod_flags flags)
Thierry Reding29a1f2332014-04-25 17:10:06 +0200276{
Dmitry Torokhov22c40362017-02-12 17:13:55 -0800277 return NULL;
Thierry Reding29a1f2332014-04-25 17:10:06 +0200278}
279
280static inline struct gpio_desc *__must_check
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +0100281devm_gpiod_get_index_optional(struct device *dev, const char *con_id,
Linus Walleij0dbc8b72014-09-01 15:15:40 +0200282 unsigned int index, enum gpiod_flags flags)
Thierry Reding29a1f2332014-04-25 17:10:06 +0200283{
Dmitry Torokhov22c40362017-02-12 17:13:55 -0800284 return NULL;
Thierry Reding29a1f2332014-04-25 17:10:06 +0200285}
286
Rojhalat Ibrahim331758e2015-02-11 17:28:02 +0100287static inline struct gpio_descs *__must_check
288devm_gpiod_get_array(struct device *dev, const char *con_id,
289 enum gpiod_flags flags)
290{
291 return ERR_PTR(-ENOSYS);
292}
293
294static inline struct gpio_descs *__must_check
295devm_gpiod_get_array_optional(struct device *dev, const char *con_id,
296 enum gpiod_flags flags)
297{
Dmitry Torokhov22c40362017-02-12 17:13:55 -0800298 return NULL;
Rojhalat Ibrahim331758e2015-02-11 17:28:02 +0100299}
300
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700301static inline void devm_gpiod_put(struct device *dev, struct gpio_desc *desc)
302{
303 might_sleep();
304
305 /* GPIO can never have been requested */
306 WARN_ON(1);
307}
308
Rojhalat Ibrahim331758e2015-02-11 17:28:02 +0100309static inline void devm_gpiod_put_array(struct device *dev,
310 struct gpio_descs *descs)
311{
312 might_sleep();
313
314 /* GPIO can never have been requested */
315 WARN_ON(1);
316}
317
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700318
319static inline int gpiod_get_direction(const struct gpio_desc *desc)
320{
321 /* GPIO can never have been requested */
322 WARN_ON(1);
323 return -ENOSYS;
324}
325static inline int gpiod_direction_input(struct gpio_desc *desc)
326{
327 /* GPIO can never have been requested */
328 WARN_ON(1);
329 return -ENOSYS;
330}
331static inline int gpiod_direction_output(struct gpio_desc *desc, int value)
332{
333 /* GPIO can never have been requested */
334 WARN_ON(1);
335 return -ENOSYS;
336}
Philipp Zabelef70bbe2014-01-07 12:34:11 +0100337static inline int gpiod_direction_output_raw(struct gpio_desc *desc, int value)
338{
339 /* GPIO can never have been requested */
340 WARN_ON(1);
341 return -ENOSYS;
342}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700343
344
345static inline int gpiod_get_value(const struct gpio_desc *desc)
346{
347 /* GPIO can never have been requested */
348 WARN_ON(1);
349 return 0;
350}
Lukas Wunnereec1d562017-10-12 12:40:10 +0200351static inline int gpiod_get_array_value(unsigned int array_size,
352 struct gpio_desc **desc_array,
Janusz Krzysztofik77588c12018-09-05 23:50:07 +0200353 struct gpio_array *array_info,
Janusz Krzysztofikb9762be2018-09-05 23:50:05 +0200354 unsigned long *value_bitmap)
Lukas Wunnereec1d562017-10-12 12:40:10 +0200355{
356 /* GPIO can never have been requested */
357 WARN_ON(1);
358 return 0;
359}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700360static inline void gpiod_set_value(struct gpio_desc *desc, int value)
361{
362 /* GPIO can never have been requested */
363 WARN_ON(1);
364}
Geert Uytterhoevencf9af0d2018-09-27 13:38:09 +0200365static inline int gpiod_set_array_value(unsigned int array_size,
366 struct gpio_desc **desc_array,
367 struct gpio_array *array_info,
368 unsigned long *value_bitmap)
Rojhalat Ibrahim5f424242014-11-04 17:12:06 +0100369{
370 /* GPIO can never have been requested */
371 WARN_ON(1);
Geert Uytterhoevencf9af0d2018-09-27 13:38:09 +0200372 return 0;
Rojhalat Ibrahim5f424242014-11-04 17:12:06 +0100373}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700374static inline int gpiod_get_raw_value(const struct gpio_desc *desc)
375{
376 /* GPIO can never have been requested */
377 WARN_ON(1);
378 return 0;
379}
Lukas Wunnereec1d562017-10-12 12:40:10 +0200380static inline int gpiod_get_raw_array_value(unsigned int array_size,
381 struct gpio_desc **desc_array,
Janusz Krzysztofik77588c12018-09-05 23:50:07 +0200382 struct gpio_array *array_info,
Janusz Krzysztofikb9762be2018-09-05 23:50:05 +0200383 unsigned long *value_bitmap)
Lukas Wunnereec1d562017-10-12 12:40:10 +0200384{
385 /* GPIO can never have been requested */
386 WARN_ON(1);
387 return 0;
388}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700389static inline void gpiod_set_raw_value(struct gpio_desc *desc, int value)
390{
391 /* GPIO can never have been requested */
392 WARN_ON(1);
393}
Laura Abbott30277432018-05-21 10:57:07 -0700394static inline int gpiod_set_raw_array_value(unsigned int array_size,
Geert Uytterhoeven3c940662018-09-27 13:38:10 +0200395 struct gpio_desc **desc_array,
396 struct gpio_array *array_info,
397 unsigned long *value_bitmap)
Rojhalat Ibrahim5f424242014-11-04 17:12:06 +0100398{
399 /* GPIO can never have been requested */
400 WARN_ON(1);
Laura Abbott30277432018-05-21 10:57:07 -0700401 return 0;
Rojhalat Ibrahim5f424242014-11-04 17:12:06 +0100402}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700403
404static inline int gpiod_get_value_cansleep(const struct gpio_desc *desc)
405{
406 /* GPIO can never have been requested */
407 WARN_ON(1);
408 return 0;
409}
Lukas Wunnereec1d562017-10-12 12:40:10 +0200410static inline int gpiod_get_array_value_cansleep(unsigned int array_size,
411 struct gpio_desc **desc_array,
Janusz Krzysztofik77588c12018-09-05 23:50:07 +0200412 struct gpio_array *array_info,
Janusz Krzysztofikb9762be2018-09-05 23:50:05 +0200413 unsigned long *value_bitmap)
Lukas Wunnereec1d562017-10-12 12:40:10 +0200414{
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_value_cansleep(struct gpio_desc *desc, int value)
420{
421 /* GPIO can never have been requested */
422 WARN_ON(1);
423}
Geert Uytterhoevencf9af0d2018-09-27 13:38:09 +0200424static inline int gpiod_set_array_value_cansleep(unsigned int array_size,
Rojhalat Ibrahim5f424242014-11-04 17:12:06 +0100425 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)
Rojhalat Ibrahim5f424242014-11-04 17:12:06 +0100428{
429 /* GPIO can never have been requested */
430 WARN_ON(1);
Geert Uytterhoevencf9af0d2018-09-27 13:38:09 +0200431 return 0;
Rojhalat Ibrahim5f424242014-11-04 17:12:06 +0100432}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700433static inline int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc)
434{
435 /* GPIO can never have been requested */
436 WARN_ON(1);
437 return 0;
438}
Lukas Wunnereec1d562017-10-12 12:40:10 +0200439static inline int gpiod_get_raw_array_value_cansleep(unsigned int array_size,
440 struct gpio_desc **desc_array,
Janusz Krzysztofik77588c12018-09-05 23:50:07 +0200441 struct gpio_array *array_info,
Janusz Krzysztofikb9762be2018-09-05 23:50:05 +0200442 unsigned long *value_bitmap)
Lukas Wunnereec1d562017-10-12 12:40:10 +0200443{
444 /* GPIO can never have been requested */
445 WARN_ON(1);
446 return 0;
447}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700448static inline void gpiod_set_raw_value_cansleep(struct gpio_desc *desc,
449 int value)
450{
451 /* GPIO can never have been requested */
452 WARN_ON(1);
453}
Laura Abbott30277432018-05-21 10:57:07 -0700454static inline int gpiod_set_raw_array_value_cansleep(unsigned int array_size,
Rojhalat Ibrahim5f424242014-11-04 17:12:06 +0100455 struct gpio_desc **desc_array,
Janusz Krzysztofik77588c12018-09-05 23:50:07 +0200456 struct gpio_array *array_info,
Janusz Krzysztofikb9762be2018-09-05 23:50:05 +0200457 unsigned long *value_bitmap)
Rojhalat Ibrahim5f424242014-11-04 17:12:06 +0100458{
459 /* GPIO can never have been requested */
460 WARN_ON(1);
Laura Abbott30277432018-05-21 10:57:07 -0700461 return 0;
Rojhalat Ibrahim5f424242014-11-04 17:12:06 +0100462}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700463
464static inline int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce)
465{
466 /* GPIO can never have been requested */
467 WARN_ON(1);
468 return -ENOSYS;
469}
470
Andrew Jefferye10f72b2017-11-30 14:25:24 +1030471static inline int gpiod_set_transitory(struct gpio_desc *desc, bool transitory)
472{
473 /* GPIO can never have been requested */
474 WARN_ON(1);
475 return -ENOSYS;
476}
477
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700478static inline int gpiod_is_active_low(const struct gpio_desc *desc)
479{
480 /* GPIO can never have been requested */
481 WARN_ON(1);
482 return 0;
483}
484static inline int gpiod_cansleep(const struct gpio_desc *desc)
485{
486 /* GPIO can never have been requested */
487 WARN_ON(1);
488 return 0;
489}
490
491static inline int gpiod_to_irq(const struct gpio_desc *desc)
492{
493 /* GPIO can never have been requested */
494 WARN_ON(1);
495 return -EINVAL;
496}
497
Muchun Song18534df2018-11-01 21:12:50 +0800498static inline int gpiod_set_consumer_name(struct gpio_desc *desc,
499 const char *name)
Linus Walleij90b39402e2018-06-01 13:21:27 +0200500{
501 /* GPIO can never have been requested */
502 WARN_ON(1);
Muchun Song18534df2018-11-01 21:12:50 +0800503 return -EINVAL;
Linus Walleij90b39402e2018-06-01 13:21:27 +0200504}
505
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700506static inline struct gpio_desc *gpio_to_desc(unsigned gpio)
507{
508 return ERR_PTR(-EINVAL);
509}
Markus Pargmannc0017ed2015-08-14 16:10:59 +0200510
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700511static inline int desc_to_gpio(const struct gpio_desc *desc)
512{
513 /* GPIO can never have been requested */
514 WARN_ON(1);
515 return -EINVAL;
516}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700517
Geert Uytterhoeven496e7ce2015-05-07 01:08:08 -0700518/* Child properties interface */
Linus Walleij92542ed2017-12-29 22:52:02 +0100519struct device_node;
Geert Uytterhoeven496e7ce2015-05-07 01:08:08 -0700520struct fwnode_handle;
521
Andy Shevchenkoa264d102017-01-09 16:02:28 +0200522static inline
Linus Walleij92542ed2017-12-29 22:52:02 +0100523struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev,
524 struct device_node *node,
525 const char *propname, int index,
526 enum gpiod_flags dflags,
527 const char *label)
528{
529 return ERR_PTR(-ENOSYS);
530}
531
532static inline
Andy Shevchenkoa264d102017-01-09 16:02:28 +0200533struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
Boris Brezillon537b94d2017-02-02 14:53:11 +0100534 const char *propname, int index,
Alexander Steinb2987d72017-01-12 17:39:24 +0100535 enum gpiod_flags dflags,
536 const char *label)
Geert Uytterhoeven496e7ce2015-05-07 01:08:08 -0700537{
538 return ERR_PTR(-ENOSYS);
539}
540
Andy Shevchenkoa264d102017-01-09 16:02:28 +0200541static inline
Boris Brezillon537b94d2017-02-02 14:53:11 +0100542struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev,
543 const char *con_id, int index,
544 struct fwnode_handle *child,
545 enum gpiod_flags flags,
546 const char *label)
547{
548 return ERR_PTR(-ENOSYS);
549}
550
551#endif /* CONFIG_GPIOLIB */
552
553static inline
Boris Brezillon4b094792017-02-02 14:53:10 +0100554struct gpio_desc *devm_fwnode_get_gpiod_from_child(struct device *dev,
555 const char *con_id,
556 struct fwnode_handle *child,
557 enum gpiod_flags flags,
558 const char *label)
Geert Uytterhoeven496e7ce2015-05-07 01:08:08 -0700559{
Boris Brezillon537b94d2017-02-02 14:53:11 +0100560 return devm_fwnode_get_index_gpiod_from_child(dev, con_id, 0, child,
561 flags, label);
Geert Uytterhoeven496e7ce2015-05-07 01:08:08 -0700562}
563
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700564#if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS)
565
566int gpiod_export(struct gpio_desc *desc, bool direction_may_change);
567int gpiod_export_link(struct device *dev, const char *name,
568 struct gpio_desc *desc);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700569void gpiod_unexport(struct gpio_desc *desc);
570
571#else /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */
572
573static inline int gpiod_export(struct gpio_desc *desc,
574 bool direction_may_change)
575{
576 return -ENOSYS;
577}
578
579static inline int gpiod_export_link(struct device *dev, const char *name,
580 struct gpio_desc *desc)
581{
582 return -ENOSYS;
583}
584
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700585static inline void gpiod_unexport(struct gpio_desc *desc)
586{
587}
588
589#endif /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */
590
591#endif