1 #ifndef __LINUX_GPIO_CONSUMER_H
2 #define __LINUX_GPIO_CONSUMER_H
6 #include <linux/kernel.h>
11 * Opaque descriptor for a GPIO. These are obtained using gpiod_get() and are
12 * preferable to the old integer-based handles.
14 * Contrary to integers, a pointer to a gpio_desc is guaranteed to be valid
15 * until the GPIO is released.
19 #define GPIOD_FLAGS_BIT_DIR_SET BIT(0)
20 #define GPIOD_FLAGS_BIT_DIR_OUT BIT(1)
21 #define GPIOD_FLAGS_BIT_DIR_VAL BIT(2)
24 * Optional flags that can be passed to one of gpiod_* to configure direction
25 * and output value. These values cannot be OR'd.
29 GPIOD_IN
= GPIOD_FLAGS_BIT_DIR_SET
,
30 GPIOD_OUT_LOW
= GPIOD_FLAGS_BIT_DIR_SET
| GPIOD_FLAGS_BIT_DIR_OUT
,
31 GPIOD_OUT_HIGH
= GPIOD_FLAGS_BIT_DIR_SET
| GPIOD_FLAGS_BIT_DIR_OUT
|
32 GPIOD_FLAGS_BIT_DIR_VAL
,
37 /* Acquire and dispose GPIOs */
38 struct gpio_desc
*__must_check
__gpiod_get(struct device
*dev
,
40 enum gpiod_flags flags
);
41 struct gpio_desc
*__must_check
__gpiod_get_index(struct device
*dev
,
44 enum gpiod_flags flags
);
45 struct gpio_desc
*__must_check
__gpiod_get_optional(struct device
*dev
,
47 enum gpiod_flags flags
);
48 struct gpio_desc
*__must_check
__gpiod_get_index_optional(struct device
*dev
,
51 enum gpiod_flags flags
);
52 void gpiod_put(struct gpio_desc
*desc
);
54 struct gpio_desc
*__must_check
__devm_gpiod_get(struct device
*dev
,
56 enum gpiod_flags flags
);
57 struct gpio_desc
*__must_check
__devm_gpiod_get_index(struct device
*dev
,
60 enum gpiod_flags flags
);
61 struct gpio_desc
*__must_check
__devm_gpiod_get_optional(struct device
*dev
,
63 enum gpiod_flags flags
);
64 struct gpio_desc
*__must_check
65 __devm_gpiod_get_index_optional(struct device
*dev
, const char *con_id
,
66 unsigned int index
, enum gpiod_flags flags
);
67 void devm_gpiod_put(struct device
*dev
, struct gpio_desc
*desc
);
69 int gpiod_get_direction(const struct gpio_desc
*desc
);
70 int gpiod_direction_input(struct gpio_desc
*desc
);
71 int gpiod_direction_output(struct gpio_desc
*desc
, int value
);
72 int gpiod_direction_output_raw(struct gpio_desc
*desc
, int value
);
74 /* Value get/set from non-sleeping context */
75 int gpiod_get_value(const struct gpio_desc
*desc
);
76 void gpiod_set_value(struct gpio_desc
*desc
, int value
);
77 int gpiod_get_raw_value(const struct gpio_desc
*desc
);
78 void gpiod_set_raw_value(struct gpio_desc
*desc
, int value
);
80 /* Value get/set from sleeping context */
81 int gpiod_get_value_cansleep(const struct gpio_desc
*desc
);
82 void gpiod_set_value_cansleep(struct gpio_desc
*desc
, int value
);
83 int gpiod_get_raw_value_cansleep(const struct gpio_desc
*desc
);
84 void gpiod_set_raw_value_cansleep(struct gpio_desc
*desc
, int value
);
86 int gpiod_set_debounce(struct gpio_desc
*desc
, unsigned debounce
);
88 int gpiod_is_active_low(const struct gpio_desc
*desc
);
89 int gpiod_cansleep(const struct gpio_desc
*desc
);
91 int gpiod_to_irq(const struct gpio_desc
*desc
);
93 /* Convert between the old gpio_ and new gpiod_ interfaces */
94 struct gpio_desc
*gpio_to_desc(unsigned gpio
);
95 int desc_to_gpio(const struct gpio_desc
*desc
);
97 #else /* CONFIG_GPIOLIB */
99 static inline struct gpio_desc
*__must_check
__gpiod_get(struct device
*dev
,
101 enum gpiod_flags flags
)
103 return ERR_PTR(-ENOSYS
);
105 static inline struct gpio_desc
*__must_check
106 __gpiod_get_index(struct device
*dev
,
109 enum gpiod_flags flags
)
111 return ERR_PTR(-ENOSYS
);
114 static inline struct gpio_desc
*__must_check
115 __gpiod_get_optional(struct device
*dev
, const char *con_id
,
116 enum gpiod_flags flags
)
118 return ERR_PTR(-ENOSYS
);
121 static inline struct gpio_desc
*__must_check
122 __gpiod_get_index_optional(struct device
*dev
, const char *con_id
,
123 unsigned int index
, enum gpiod_flags flags
)
125 return ERR_PTR(-ENOSYS
);
128 static inline void gpiod_put(struct gpio_desc
*desc
)
132 /* GPIO can never have been requested */
136 static inline struct gpio_desc
*__must_check
137 __devm_gpiod_get(struct device
*dev
,
139 enum gpiod_flags flags
)
141 return ERR_PTR(-ENOSYS
);
144 struct gpio_desc
*__must_check
145 __devm_gpiod_get_index(struct device
*dev
,
148 enum gpiod_flags flags
)
150 return ERR_PTR(-ENOSYS
);
153 static inline struct gpio_desc
*__must_check
154 __devm_gpiod_get_optional(struct device
*dev
, const char *con_id
,
155 enum gpiod_flags flags
)
157 return ERR_PTR(-ENOSYS
);
160 static inline struct gpio_desc
*__must_check
161 __devm_gpiod_get_index_optional(struct device
*dev
, const char *con_id
,
162 unsigned int index
, enum gpiod_flags flags
)
164 return ERR_PTR(-ENOSYS
);
167 static inline void devm_gpiod_put(struct device
*dev
, struct gpio_desc
*desc
)
171 /* GPIO can never have been requested */
176 static inline int gpiod_get_direction(const struct gpio_desc
*desc
)
178 /* GPIO can never have been requested */
182 static inline int gpiod_direction_input(struct gpio_desc
*desc
)
184 /* GPIO can never have been requested */
188 static inline int gpiod_direction_output(struct gpio_desc
*desc
, int value
)
190 /* GPIO can never have been requested */
194 static inline int gpiod_direction_output_raw(struct gpio_desc
*desc
, int value
)
196 /* GPIO can never have been requested */
202 static inline int gpiod_get_value(const struct gpio_desc
*desc
)
204 /* GPIO can never have been requested */
208 static inline void gpiod_set_value(struct gpio_desc
*desc
, int value
)
210 /* GPIO can never have been requested */
213 static inline int gpiod_get_raw_value(const struct gpio_desc
*desc
)
215 /* GPIO can never have been requested */
219 static inline void gpiod_set_raw_value(struct gpio_desc
*desc
, int value
)
221 /* GPIO can never have been requested */
225 static inline int gpiod_get_value_cansleep(const struct gpio_desc
*desc
)
227 /* GPIO can never have been requested */
231 static inline void gpiod_set_value_cansleep(struct gpio_desc
*desc
, int value
)
233 /* GPIO can never have been requested */
236 static inline int gpiod_get_raw_value_cansleep(const struct gpio_desc
*desc
)
238 /* GPIO can never have been requested */
242 static inline void gpiod_set_raw_value_cansleep(struct gpio_desc
*desc
,
245 /* GPIO can never have been requested */
249 static inline int gpiod_set_debounce(struct gpio_desc
*desc
, unsigned debounce
)
251 /* GPIO can never have been requested */
256 static inline int gpiod_is_active_low(const struct gpio_desc
*desc
)
258 /* GPIO can never have been requested */
262 static inline int gpiod_cansleep(const struct gpio_desc
*desc
)
264 /* GPIO can never have been requested */
269 static inline int gpiod_to_irq(const struct gpio_desc
*desc
)
271 /* GPIO can never have been requested */
276 static inline struct gpio_desc
*gpio_to_desc(unsigned gpio
)
278 return ERR_PTR(-EINVAL
);
280 static inline int desc_to_gpio(const struct gpio_desc
*desc
)
282 /* GPIO can never have been requested */
287 #endif /* CONFIG_GPIOLIB */
290 * Vararg-hacks! This is done to transition the kernel to always pass
291 * the options flags argument to the below functions. During a transition
292 * phase these vararg macros make both old-and-newstyle code compile,
293 * but when all calls to the elder API are removed, these should go away
294 * and the __gpiod_get() etc functions above be renamed just gpiod_get()
297 #define __gpiod_get(dev, con_id, flags, ...) __gpiod_get(dev, con_id, flags)
298 #define gpiod_get(varargs...) __gpiod_get(varargs, 0)
299 #define __gpiod_get_index(dev, con_id, index, flags, ...) \
300 __gpiod_get_index(dev, con_id, index, flags)
301 #define gpiod_get_index(varargs...) __gpiod_get_index(varargs, 0)
302 #define __gpiod_get_optional(dev, con_id, flags, ...) \
303 __gpiod_get_optional(dev, con_id, flags)
304 #define gpiod_get_optional(varargs...) __gpiod_get_optional(varargs, 0)
305 #define __gpiod_get_index_optional(dev, con_id, index, flags, ...) \
306 __gpiod_get_index_optional(dev, con_id, index, flags)
307 #define gpiod_get_index_optional(varargs...) \
308 __gpiod_get_index_optional(varargs, 0)
309 #define __devm_gpiod_get(dev, con_id, flags, ...) \
310 __devm_gpiod_get(dev, con_id, flags)
311 #define devm_gpiod_get(varargs...) __devm_gpiod_get(varargs, 0)
312 #define __devm_gpiod_get_index(dev, con_id, index, flags, ...) \
313 __devm_gpiod_get_index(dev, con_id, index, flags)
314 #define devm_gpiod_get_index(varargs...) __devm_gpiod_get_index(varargs, 0)
315 #define __devm_gpiod_get_optional(dev, con_id, flags, ...) \
316 __devm_gpiod_get_optional(dev, con_id, flags)
317 #define devm_gpiod_get_optional(varargs...) \
318 __devm_gpiod_get_optional(varargs, 0)
319 #define __devm_gpiod_get_index_optional(dev, con_id, index, flags, ...) \
320 __devm_gpiod_get_index_optional(dev, con_id, index, flags)
321 #define devm_gpiod_get_index_optional(varargs...) \
322 __devm_gpiod_get_index_optional(varargs, 0)
324 #if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS)
326 int gpiod_export(struct gpio_desc
*desc
, bool direction_may_change
);
327 int gpiod_export_link(struct device
*dev
, const char *name
,
328 struct gpio_desc
*desc
);
329 int gpiod_sysfs_set_active_low(struct gpio_desc
*desc
, int value
);
330 void gpiod_unexport(struct gpio_desc
*desc
);
332 #else /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */
334 static inline int gpiod_export(struct gpio_desc
*desc
,
335 bool direction_may_change
)
340 static inline int gpiod_export_link(struct device
*dev
, const char *name
,
341 struct gpio_desc
*desc
)
346 static inline int gpiod_sysfs_set_active_low(struct gpio_desc
*desc
, int value
)
351 static inline void gpiod_unexport(struct gpio_desc
*desc
)
355 #endif /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */
This page took 0.066508 seconds and 6 git commands to generate.