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 #define __gpiod_get(dev, con_id, flags, ...) __gpiod_get(dev, con_id, flags)
42 #define gpiod_get(varargs...) __gpiod_get(varargs, 0)
43 struct gpio_desc
*__must_check
__gpiod_get_index(struct device
*dev
,
46 enum gpiod_flags flags
);
47 #define __gpiod_get_index(dev, con_id, index, flags, ...) \
48 __gpiod_get_index(dev, con_id, index, flags)
49 #define gpiod_get_index(varargs...) __gpiod_get_index(varargs, 0)
50 struct gpio_desc
*__must_check
__gpiod_get_optional(struct device
*dev
,
52 enum gpiod_flags flags
);
53 #define __gpiod_get_optional(dev, con_id, flags, ...) \
54 __gpiod_get_optional(dev, con_id, flags)
55 #define gpiod_get_optional(varargs...) __gpiod_get_optional(varargs, 0)
56 struct gpio_desc
*__must_check
__gpiod_get_index_optional(struct device
*dev
,
59 enum gpiod_flags flags
);
60 #define __gpiod_get_index_optional(dev, con_id, index, flags, ...) \
61 __gpiod_get_index_optional(dev, con_id, index, flags)
62 #define gpiod_get_index_optional(varargs...) \
63 __gpiod_get_index_optional(varargs, 0)
65 void gpiod_put(struct gpio_desc
*desc
);
67 struct gpio_desc
*__must_check
__devm_gpiod_get(struct device
*dev
,
69 enum gpiod_flags flags
);
70 #define __devm_gpiod_get(dev, con_id, flags, ...) \
71 __devm_gpiod_get(dev, con_id, flags)
72 #define devm_gpiod_get(varargs...) __devm_gpiod_get(varargs, 0)
73 struct gpio_desc
*__must_check
__devm_gpiod_get_index(struct device
*dev
,
76 enum gpiod_flags flags
);
77 #define __devm_gpiod_get_index(dev, con_id, index, flags, ...) \
78 __devm_gpiod_get_index(dev, con_id, index, flags)
79 #define devm_gpiod_get_index(varargs...) __devm_gpiod_get_index(varargs, 0)
80 struct gpio_desc
*__must_check
__devm_gpiod_get_optional(struct device
*dev
,
82 enum gpiod_flags flags
);
83 #define __devm_gpiod_get_optional(dev, con_id, flags, ...) \
84 __devm_gpiod_get_optional(dev, con_id, flags)
85 #define devm_gpiod_get_optional(varargs...) \
86 __devm_gpiod_get_optional(varargs, 0)
87 struct gpio_desc
*__must_check
88 __devm_gpiod_get_index_optional(struct device
*dev
, const char *con_id
,
89 unsigned int index
, enum gpiod_flags flags
);
90 #define __devm_gpiod_get_index_optional(dev, con_id, index, flags, ...) \
91 __devm_gpiod_get_index_optional(dev, con_id, index, flags)
92 #define devm_gpiod_get_index_optional(varargs...) \
93 __devm_gpiod_get_index_optional(varargs, 0)
95 void devm_gpiod_put(struct device
*dev
, struct gpio_desc
*desc
);
97 int gpiod_get_direction(const struct gpio_desc
*desc
);
98 int gpiod_direction_input(struct gpio_desc
*desc
);
99 int gpiod_direction_output(struct gpio_desc
*desc
, int value
);
100 int gpiod_direction_output_raw(struct gpio_desc
*desc
, int value
);
102 /* Value get/set from non-sleeping context */
103 int gpiod_get_value(const struct gpio_desc
*desc
);
104 void gpiod_set_value(struct gpio_desc
*desc
, int value
);
105 int gpiod_get_raw_value(const struct gpio_desc
*desc
);
106 void gpiod_set_raw_value(struct gpio_desc
*desc
, int value
);
108 /* Value get/set from sleeping context */
109 int gpiod_get_value_cansleep(const struct gpio_desc
*desc
);
110 void gpiod_set_value_cansleep(struct gpio_desc
*desc
, int value
);
111 int gpiod_get_raw_value_cansleep(const struct gpio_desc
*desc
);
112 void gpiod_set_raw_value_cansleep(struct gpio_desc
*desc
, int value
);
114 int gpiod_set_debounce(struct gpio_desc
*desc
, unsigned debounce
);
116 int gpiod_is_active_low(const struct gpio_desc
*desc
);
117 int gpiod_cansleep(const struct gpio_desc
*desc
);
119 int gpiod_to_irq(const struct gpio_desc
*desc
);
121 /* Convert between the old gpio_ and new gpiod_ interfaces */
122 struct gpio_desc
*gpio_to_desc(unsigned gpio
);
123 int desc_to_gpio(const struct gpio_desc
*desc
);
125 #else /* CONFIG_GPIOLIB */
127 static inline struct gpio_desc
*__must_check
gpiod_get(struct device
*dev
,
130 return ERR_PTR(-ENOSYS
);
132 static inline struct gpio_desc
*__must_check
gpiod_get_index(struct device
*dev
,
136 return ERR_PTR(-ENOSYS
);
139 static inline struct gpio_desc
*__must_check
140 gpiod_get_optional(struct device
*dev
, const char *con_id
)
142 return ERR_PTR(-ENOSYS
);
145 static inline struct gpio_desc
*__must_check
146 gpiod_get_index_optional(struct device
*dev
, const char *con_id
,
149 return ERR_PTR(-ENOSYS
);
152 static inline void gpiod_put(struct gpio_desc
*desc
)
156 /* GPIO can never have been requested */
160 static inline struct gpio_desc
*__must_check
devm_gpiod_get(struct device
*dev
,
163 return ERR_PTR(-ENOSYS
);
166 struct gpio_desc
*__must_check
devm_gpiod_get_index(struct device
*dev
,
170 return ERR_PTR(-ENOSYS
);
173 static inline struct gpio_desc
*__must_check
174 devm_gpiod_get_optional(struct device
*dev
, const char *con_id
)
176 return ERR_PTR(-ENOSYS
);
179 static inline struct gpio_desc
*__must_check
180 devm_gpiod_get_index_optional(struct device
*dev
, const char *con_id
,
183 return ERR_PTR(-ENOSYS
);
186 static inline void devm_gpiod_put(struct device
*dev
, struct gpio_desc
*desc
)
190 /* GPIO can never have been requested */
195 static inline int gpiod_get_direction(const struct gpio_desc
*desc
)
197 /* GPIO can never have been requested */
201 static inline int gpiod_direction_input(struct gpio_desc
*desc
)
203 /* GPIO can never have been requested */
207 static inline int gpiod_direction_output(struct gpio_desc
*desc
, int value
)
209 /* GPIO can never have been requested */
213 static inline int gpiod_direction_output_raw(struct gpio_desc
*desc
, int value
)
215 /* GPIO can never have been requested */
221 static inline int gpiod_get_value(const struct gpio_desc
*desc
)
223 /* GPIO can never have been requested */
227 static inline void gpiod_set_value(struct gpio_desc
*desc
, int value
)
229 /* GPIO can never have been requested */
232 static inline int gpiod_get_raw_value(const struct gpio_desc
*desc
)
234 /* GPIO can never have been requested */
238 static inline void gpiod_set_raw_value(struct gpio_desc
*desc
, int value
)
240 /* GPIO can never have been requested */
244 static inline int gpiod_get_value_cansleep(const struct gpio_desc
*desc
)
246 /* GPIO can never have been requested */
250 static inline void gpiod_set_value_cansleep(struct gpio_desc
*desc
, int value
)
252 /* GPIO can never have been requested */
255 static inline int gpiod_get_raw_value_cansleep(const struct gpio_desc
*desc
)
257 /* GPIO can never have been requested */
261 static inline void gpiod_set_raw_value_cansleep(struct gpio_desc
*desc
,
264 /* GPIO can never have been requested */
268 static inline int gpiod_set_debounce(struct gpio_desc
*desc
, unsigned debounce
)
270 /* GPIO can never have been requested */
275 static inline int gpiod_is_active_low(const struct gpio_desc
*desc
)
277 /* GPIO can never have been requested */
281 static inline int gpiod_cansleep(const struct gpio_desc
*desc
)
283 /* GPIO can never have been requested */
288 static inline int gpiod_to_irq(const struct gpio_desc
*desc
)
290 /* GPIO can never have been requested */
295 static inline struct gpio_desc
*gpio_to_desc(unsigned gpio
)
297 return ERR_PTR(-EINVAL
);
299 static inline int desc_to_gpio(const struct gpio_desc
*desc
)
301 /* GPIO can never have been requested */
307 #endif /* CONFIG_GPIOLIB */
309 #if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS)
311 int gpiod_export(struct gpio_desc
*desc
, bool direction_may_change
);
312 int gpiod_export_link(struct device
*dev
, const char *name
,
313 struct gpio_desc
*desc
);
314 int gpiod_sysfs_set_active_low(struct gpio_desc
*desc
, int value
);
315 void gpiod_unexport(struct gpio_desc
*desc
);
317 #else /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */
319 static inline int gpiod_export(struct gpio_desc
*desc
,
320 bool direction_may_change
)
325 static inline int gpiod_export_link(struct device
*dev
, const char *name
,
326 struct gpio_desc
*desc
)
331 static inline int gpiod_sysfs_set_active_low(struct gpio_desc
*desc
, int value
)
336 static inline void gpiod_unexport(struct gpio_desc
*desc
)
340 #endif /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */
This page took 0.267503 seconds and 6 git commands to generate.