blob: 2b0389f0bec4cb2ff3fa10d654a18757c649c32b [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,
Janusz Krzysztofikb9762be2018-09-05 23:50:05 +0200107 struct gpio_desc **desc_array,
108 unsigned long *value_bitmap);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700109void gpiod_set_value(struct gpio_desc *desc, int value);
Rojhalat Ibrahim3fff99b2015-05-13 11:04:56 +0200110void gpiod_set_array_value(unsigned int array_size,
Janusz Krzysztofikb9762be2018-09-05 23:50:05 +0200111 struct gpio_desc **desc_array,
112 unsigned long *value_bitmap);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700113int gpiod_get_raw_value(const struct gpio_desc *desc);
Lukas Wunnereec1d562017-10-12 12:40:10 +0200114int gpiod_get_raw_array_value(unsigned int array_size,
115 struct gpio_desc **desc_array,
Janusz Krzysztofikb9762be2018-09-05 23:50:05 +0200116 unsigned long *value_bitmap);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700117void gpiod_set_raw_value(struct gpio_desc *desc, int value);
Laura Abbott30277432018-05-21 10:57:07 -0700118int gpiod_set_raw_array_value(unsigned int array_size,
Rojhalat Ibrahim3fff99b2015-05-13 11:04:56 +0200119 struct gpio_desc **desc_array,
Janusz Krzysztofikb9762be2018-09-05 23:50:05 +0200120 unsigned long *value_bitmap);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700121
122/* Value get/set from sleeping context */
123int gpiod_get_value_cansleep(const struct gpio_desc *desc);
Lukas Wunnereec1d562017-10-12 12:40:10 +0200124int gpiod_get_array_value_cansleep(unsigned int array_size,
125 struct gpio_desc **desc_array,
Janusz Krzysztofikb9762be2018-09-05 23:50:05 +0200126 unsigned long *value_bitmap);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700127void gpiod_set_value_cansleep(struct gpio_desc *desc, int value);
Rojhalat Ibrahim3fff99b2015-05-13 11:04:56 +0200128void gpiod_set_array_value_cansleep(unsigned int array_size,
129 struct gpio_desc **desc_array,
Janusz Krzysztofikb9762be2018-09-05 23:50:05 +0200130 unsigned long *value_bitmap);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700131int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc);
Lukas Wunnereec1d562017-10-12 12:40:10 +0200132int gpiod_get_raw_array_value_cansleep(unsigned int array_size,
133 struct gpio_desc **desc_array,
Janusz Krzysztofikb9762be2018-09-05 23:50:05 +0200134 unsigned long *value_bitmap);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700135void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, int value);
Laura Abbott30277432018-05-21 10:57:07 -0700136int gpiod_set_raw_array_value_cansleep(unsigned int array_size,
Rojhalat Ibrahim3fff99b2015-05-13 11:04:56 +0200137 struct gpio_desc **desc_array,
Janusz Krzysztofikb9762be2018-09-05 23:50:05 +0200138 unsigned long *value_bitmap);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700139
140int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce);
Andrew Jefferye10f72b2017-11-30 14:25:24 +1030141int gpiod_set_transitory(struct gpio_desc *desc, bool transitory);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700142
143int gpiod_is_active_low(const struct gpio_desc *desc);
144int gpiod_cansleep(const struct gpio_desc *desc);
145
146int gpiod_to_irq(const struct gpio_desc *desc);
Linus Walleij90b39402e2018-06-01 13:21:27 +0200147void gpiod_set_consumer_name(struct gpio_desc *desc, const char *name);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700148
149/* Convert between the old gpio_ and new gpiod_ interfaces */
150struct gpio_desc *gpio_to_desc(unsigned gpio);
151int desc_to_gpio(const struct gpio_desc *desc);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700152
Mika Westerberg40b73182014-10-21 13:33:59 +0200153/* Child properties interface */
Linus Walleij92542ed2017-12-29 22:52:02 +0100154struct device_node;
Mika Westerberg40b73182014-10-21 13:33:59 +0200155struct fwnode_handle;
156
Linus Walleij92542ed2017-12-29 22:52:02 +0100157struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev,
158 struct device_node *node,
159 const char *propname, int index,
160 enum gpiod_flags dflags,
161 const char *label);
Mika Westerberg40b73182014-10-21 13:33:59 +0200162struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
Boris Brezillon537b94d2017-02-02 14:53:11 +0100163 const char *propname, int index,
Alexander Steinb2987d72017-01-12 17:39:24 +0100164 enum gpiod_flags dflags,
165 const char *label);
Boris Brezillon537b94d2017-02-02 14:53:11 +0100166struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev,
167 const char *con_id, int index,
168 struct fwnode_handle *child,
169 enum gpiod_flags flags,
170 const char *label);
Linus Walleij3498d862017-02-21 14:19:45 +0100171
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700172#else /* CONFIG_GPIOLIB */
173
Rojhalat Ibrahim66858522015-02-11 17:27:58 +0100174static inline int gpiod_count(struct device *dev, const char *con_id)
175{
176 return 0;
177}
178
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +0100179static inline struct gpio_desc *__must_check gpiod_get(struct device *dev,
180 const char *con_id,
181 enum gpiod_flags flags)
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700182{
183 return ERR_PTR(-ENOSYS);
184}
Linus Walleij0dbc8b72014-09-01 15:15:40 +0200185static inline struct gpio_desc *__must_check
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +0100186gpiod_get_index(struct device *dev,
187 const char *con_id,
188 unsigned int idx,
189 enum gpiod_flags flags)
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700190{
191 return ERR_PTR(-ENOSYS);
192}
Thierry Reding29a1f2332014-04-25 17:10:06 +0200193
194static inline struct gpio_desc *__must_check
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +0100195gpiod_get_optional(struct device *dev, const char *con_id,
196 enum gpiod_flags flags)
Thierry Reding29a1f2332014-04-25 17:10:06 +0200197{
Dmitry Torokhov22c40362017-02-12 17:13:55 -0800198 return NULL;
Thierry Reding29a1f2332014-04-25 17:10:06 +0200199}
200
201static inline struct gpio_desc *__must_check
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +0100202gpiod_get_index_optional(struct device *dev, const char *con_id,
203 unsigned int index, enum gpiod_flags flags)
Thierry Reding29a1f2332014-04-25 17:10:06 +0200204{
Dmitry Torokhov22c40362017-02-12 17:13:55 -0800205 return NULL;
Thierry Reding29a1f2332014-04-25 17:10:06 +0200206}
207
Rojhalat Ibrahim66858522015-02-11 17:27:58 +0100208static inline struct gpio_descs *__must_check
209gpiod_get_array(struct device *dev, const char *con_id,
210 enum gpiod_flags flags)
211{
212 return ERR_PTR(-ENOSYS);
213}
214
215static inline struct gpio_descs *__must_check
216gpiod_get_array_optional(struct device *dev, const char *con_id,
217 enum gpiod_flags flags)
218{
Dmitry Torokhov22c40362017-02-12 17:13:55 -0800219 return NULL;
Rojhalat Ibrahim66858522015-02-11 17:27:58 +0100220}
221
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700222static inline void gpiod_put(struct gpio_desc *desc)
223{
224 might_sleep();
225
226 /* GPIO can never have been requested */
227 WARN_ON(1);
228}
229
Rojhalat Ibrahim66858522015-02-11 17:27:58 +0100230static inline void gpiod_put_array(struct gpio_descs *descs)
231{
232 might_sleep();
233
234 /* GPIO can never have been requested */
235 WARN_ON(1);
236}
237
Linus Walleij0dbc8b72014-09-01 15:15:40 +0200238static inline struct gpio_desc *__must_check
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +0100239devm_gpiod_get(struct device *dev,
Linus Walleij0dbc8b72014-09-01 15:15:40 +0200240 const char *con_id,
241 enum gpiod_flags flags)
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700242{
243 return ERR_PTR(-ENOSYS);
244}
245static inline
Linus Walleij0dbc8b72014-09-01 15:15:40 +0200246struct gpio_desc *__must_check
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +0100247devm_gpiod_get_index(struct device *dev,
Linus Walleij0dbc8b72014-09-01 15:15:40 +0200248 const char *con_id,
249 unsigned int idx,
250 enum gpiod_flags flags)
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700251{
252 return ERR_PTR(-ENOSYS);
253}
Thierry Reding29a1f2332014-04-25 17:10:06 +0200254
255static inline struct gpio_desc *__must_check
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +0100256devm_gpiod_get_optional(struct device *dev, const char *con_id,
Linus Walleij0dbc8b72014-09-01 15:15:40 +0200257 enum gpiod_flags flags)
Thierry Reding29a1f2332014-04-25 17:10:06 +0200258{
Dmitry Torokhov22c40362017-02-12 17:13:55 -0800259 return NULL;
Thierry Reding29a1f2332014-04-25 17:10:06 +0200260}
261
262static inline struct gpio_desc *__must_check
Uwe Kleine-Königb17d1bf2015-02-11 11:52:37 +0100263devm_gpiod_get_index_optional(struct device *dev, const char *con_id,
Linus Walleij0dbc8b72014-09-01 15:15:40 +0200264 unsigned int index, enum gpiod_flags flags)
Thierry Reding29a1f2332014-04-25 17:10:06 +0200265{
Dmitry Torokhov22c40362017-02-12 17:13:55 -0800266 return NULL;
Thierry Reding29a1f2332014-04-25 17:10:06 +0200267}
268
Rojhalat Ibrahim331758e2015-02-11 17:28:02 +0100269static inline struct gpio_descs *__must_check
270devm_gpiod_get_array(struct device *dev, const char *con_id,
271 enum gpiod_flags flags)
272{
273 return ERR_PTR(-ENOSYS);
274}
275
276static inline struct gpio_descs *__must_check
277devm_gpiod_get_array_optional(struct device *dev, const char *con_id,
278 enum gpiod_flags flags)
279{
Dmitry Torokhov22c40362017-02-12 17:13:55 -0800280 return NULL;
Rojhalat Ibrahim331758e2015-02-11 17:28:02 +0100281}
282
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700283static inline void devm_gpiod_put(struct device *dev, struct gpio_desc *desc)
284{
285 might_sleep();
286
287 /* GPIO can never have been requested */
288 WARN_ON(1);
289}
290
Rojhalat Ibrahim331758e2015-02-11 17:28:02 +0100291static inline void devm_gpiod_put_array(struct device *dev,
292 struct gpio_descs *descs)
293{
294 might_sleep();
295
296 /* GPIO can never have been requested */
297 WARN_ON(1);
298}
299
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700300
301static inline int gpiod_get_direction(const struct gpio_desc *desc)
302{
303 /* GPIO can never have been requested */
304 WARN_ON(1);
305 return -ENOSYS;
306}
307static inline int gpiod_direction_input(struct gpio_desc *desc)
308{
309 /* GPIO can never have been requested */
310 WARN_ON(1);
311 return -ENOSYS;
312}
313static inline int gpiod_direction_output(struct gpio_desc *desc, int value)
314{
315 /* GPIO can never have been requested */
316 WARN_ON(1);
317 return -ENOSYS;
318}
Philipp Zabelef70bbe2014-01-07 12:34:11 +0100319static inline int gpiod_direction_output_raw(struct gpio_desc *desc, int value)
320{
321 /* GPIO can never have been requested */
322 WARN_ON(1);
323 return -ENOSYS;
324}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700325
326
327static inline int gpiod_get_value(const struct gpio_desc *desc)
328{
329 /* GPIO can never have been requested */
330 WARN_ON(1);
331 return 0;
332}
Lukas Wunnereec1d562017-10-12 12:40:10 +0200333static inline int gpiod_get_array_value(unsigned int array_size,
334 struct gpio_desc **desc_array,
Janusz Krzysztofikb9762be2018-09-05 23:50:05 +0200335 unsigned long *value_bitmap)
Lukas Wunnereec1d562017-10-12 12:40:10 +0200336{
337 /* GPIO can never have been requested */
338 WARN_ON(1);
339 return 0;
340}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700341static inline void gpiod_set_value(struct gpio_desc *desc, int value)
342{
343 /* GPIO can never have been requested */
344 WARN_ON(1);
345}
Rojhalat Ibrahim3fff99b2015-05-13 11:04:56 +0200346static inline void gpiod_set_array_value(unsigned int array_size,
347 struct gpio_desc **desc_array,
Janusz Krzysztofikb9762be2018-09-05 23:50:05 +0200348 unsigned long *value_bitmap)
Rojhalat Ibrahim5f424242014-11-04 17:12:06 +0100349{
350 /* GPIO can never have been requested */
351 WARN_ON(1);
352}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700353static inline int gpiod_get_raw_value(const struct gpio_desc *desc)
354{
355 /* GPIO can never have been requested */
356 WARN_ON(1);
357 return 0;
358}
Lukas Wunnereec1d562017-10-12 12:40:10 +0200359static inline int gpiod_get_raw_array_value(unsigned int array_size,
360 struct gpio_desc **desc_array,
Janusz Krzysztofikb9762be2018-09-05 23:50:05 +0200361 unsigned long *value_bitmap)
Lukas Wunnereec1d562017-10-12 12:40:10 +0200362{
363 /* GPIO can never have been requested */
364 WARN_ON(1);
365 return 0;
366}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700367static inline void gpiod_set_raw_value(struct gpio_desc *desc, int value)
368{
369 /* GPIO can never have been requested */
370 WARN_ON(1);
371}
Laura Abbott30277432018-05-21 10:57:07 -0700372static inline int gpiod_set_raw_array_value(unsigned int array_size,
Rojhalat Ibrahim3fff99b2015-05-13 11:04:56 +0200373 struct gpio_desc **desc_array,
Janusz Krzysztofikb9762be2018-09-05 23:50:05 +0200374 unsigned long *value_bitmap)
Rojhalat Ibrahim5f424242014-11-04 17:12:06 +0100375{
376 /* GPIO can never have been requested */
377 WARN_ON(1);
Laura Abbott30277432018-05-21 10:57:07 -0700378 return 0;
Rojhalat Ibrahim5f424242014-11-04 17:12:06 +0100379}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700380
381static inline int gpiod_get_value_cansleep(const struct gpio_desc *desc)
382{
383 /* GPIO can never have been requested */
384 WARN_ON(1);
385 return 0;
386}
Lukas Wunnereec1d562017-10-12 12:40:10 +0200387static inline int gpiod_get_array_value_cansleep(unsigned int array_size,
388 struct gpio_desc **desc_array,
Janusz Krzysztofikb9762be2018-09-05 23:50:05 +0200389 unsigned long *value_bitmap)
Lukas Wunnereec1d562017-10-12 12:40:10 +0200390{
391 /* GPIO can never have been requested */
392 WARN_ON(1);
393 return 0;
394}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700395static inline void gpiod_set_value_cansleep(struct gpio_desc *desc, int value)
396{
397 /* GPIO can never have been requested */
398 WARN_ON(1);
399}
Rojhalat Ibrahim3fff99b2015-05-13 11:04:56 +0200400static inline void gpiod_set_array_value_cansleep(unsigned int array_size,
Rojhalat Ibrahim5f424242014-11-04 17:12:06 +0100401 struct gpio_desc **desc_array,
Janusz Krzysztofikb9762be2018-09-05 23:50:05 +0200402 unsigned long *value_bitmap)
Rojhalat Ibrahim5f424242014-11-04 17:12:06 +0100403{
404 /* GPIO can never have been requested */
405 WARN_ON(1);
406}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700407static inline int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc)
408{
409 /* GPIO can never have been requested */
410 WARN_ON(1);
411 return 0;
412}
Lukas Wunnereec1d562017-10-12 12:40:10 +0200413static inline int gpiod_get_raw_array_value_cansleep(unsigned int array_size,
414 struct gpio_desc **desc_array,
Janusz Krzysztofikb9762be2018-09-05 23:50:05 +0200415 unsigned long *value_bitmap)
Lukas Wunnereec1d562017-10-12 12:40:10 +0200416{
417 /* GPIO can never have been requested */
418 WARN_ON(1);
419 return 0;
420}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700421static inline void gpiod_set_raw_value_cansleep(struct gpio_desc *desc,
422 int value)
423{
424 /* GPIO can never have been requested */
425 WARN_ON(1);
426}
Laura Abbott30277432018-05-21 10:57:07 -0700427static inline int gpiod_set_raw_array_value_cansleep(unsigned int array_size,
Rojhalat Ibrahim5f424242014-11-04 17:12:06 +0100428 struct gpio_desc **desc_array,
Janusz Krzysztofikb9762be2018-09-05 23:50:05 +0200429 unsigned long *value_bitmap)
Rojhalat Ibrahim5f424242014-11-04 17:12:06 +0100430{
431 /* GPIO can never have been requested */
432 WARN_ON(1);
Laura Abbott30277432018-05-21 10:57:07 -0700433 return 0;
Rojhalat Ibrahim5f424242014-11-04 17:12:06 +0100434}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700435
436static inline int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce)
437{
438 /* GPIO can never have been requested */
439 WARN_ON(1);
440 return -ENOSYS;
441}
442
Andrew Jefferye10f72b2017-11-30 14:25:24 +1030443static inline int gpiod_set_transitory(struct gpio_desc *desc, bool transitory)
444{
445 /* GPIO can never have been requested */
446 WARN_ON(1);
447 return -ENOSYS;
448}
449
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700450static inline int gpiod_is_active_low(const struct gpio_desc *desc)
451{
452 /* GPIO can never have been requested */
453 WARN_ON(1);
454 return 0;
455}
456static inline int gpiod_cansleep(const struct gpio_desc *desc)
457{
458 /* GPIO can never have been requested */
459 WARN_ON(1);
460 return 0;
461}
462
463static inline int gpiod_to_irq(const struct gpio_desc *desc)
464{
465 /* GPIO can never have been requested */
466 WARN_ON(1);
467 return -EINVAL;
468}
469
Linus Walleij90b39402e2018-06-01 13:21:27 +0200470static inline void gpiod_set_consumer_name(struct gpio_desc *desc, const char *name)
471{
472 /* GPIO can never have been requested */
473 WARN_ON(1);
474}
475
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700476static inline struct gpio_desc *gpio_to_desc(unsigned gpio)
477{
478 return ERR_PTR(-EINVAL);
479}
Markus Pargmannc0017ed2015-08-14 16:10:59 +0200480
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700481static inline int desc_to_gpio(const struct gpio_desc *desc)
482{
483 /* GPIO can never have been requested */
484 WARN_ON(1);
485 return -EINVAL;
486}
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700487
Geert Uytterhoeven496e7ce2015-05-07 01:08:08 -0700488/* Child properties interface */
Linus Walleij92542ed2017-12-29 22:52:02 +0100489struct device_node;
Geert Uytterhoeven496e7ce2015-05-07 01:08:08 -0700490struct fwnode_handle;
491
Andy Shevchenkoa264d102017-01-09 16:02:28 +0200492static inline
Linus Walleij92542ed2017-12-29 22:52:02 +0100493struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev,
494 struct device_node *node,
495 const char *propname, int index,
496 enum gpiod_flags dflags,
497 const char *label)
498{
499 return ERR_PTR(-ENOSYS);
500}
501
502static inline
Andy Shevchenkoa264d102017-01-09 16:02:28 +0200503struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
Boris Brezillon537b94d2017-02-02 14:53:11 +0100504 const char *propname, int index,
Alexander Steinb2987d72017-01-12 17:39:24 +0100505 enum gpiod_flags dflags,
506 const char *label)
Geert Uytterhoeven496e7ce2015-05-07 01:08:08 -0700507{
508 return ERR_PTR(-ENOSYS);
509}
510
Andy Shevchenkoa264d102017-01-09 16:02:28 +0200511static inline
Boris Brezillon537b94d2017-02-02 14:53:11 +0100512struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev,
513 const char *con_id, int index,
514 struct fwnode_handle *child,
515 enum gpiod_flags flags,
516 const char *label)
517{
518 return ERR_PTR(-ENOSYS);
519}
520
521#endif /* CONFIG_GPIOLIB */
522
523static inline
Boris Brezillon4b094792017-02-02 14:53:10 +0100524struct gpio_desc *devm_fwnode_get_gpiod_from_child(struct device *dev,
525 const char *con_id,
526 struct fwnode_handle *child,
527 enum gpiod_flags flags,
528 const char *label)
Geert Uytterhoeven496e7ce2015-05-07 01:08:08 -0700529{
Boris Brezillon537b94d2017-02-02 14:53:11 +0100530 return devm_fwnode_get_index_gpiod_from_child(dev, con_id, 0, child,
531 flags, label);
Geert Uytterhoeven496e7ce2015-05-07 01:08:08 -0700532}
533
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700534#if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS)
535
536int gpiod_export(struct gpio_desc *desc, bool direction_may_change);
537int gpiod_export_link(struct device *dev, const char *name,
538 struct gpio_desc *desc);
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700539void gpiod_unexport(struct gpio_desc *desc);
540
541#else /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */
542
543static inline int gpiod_export(struct gpio_desc *desc,
544 bool direction_may_change)
545{
546 return -ENOSYS;
547}
548
549static inline int gpiod_export_link(struct device *dev, const char *name,
550 struct gpio_desc *desc)
551{
552 return -ENOSYS;
553}
554
Alexandre Courbot79a9bec2013-10-17 10:21:36 -0700555static inline void gpiod_unexport(struct gpio_desc *desc)
556{
557}
558
559#endif /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */
560
561#endif