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.
20 * Struct containing an array of descriptors that can be obtained using
25 struct gpio_desc
*desc
[];
28 #define GPIOD_FLAGS_BIT_DIR_SET BIT(0)
29 #define GPIOD_FLAGS_BIT_DIR_OUT BIT(1)
30 #define GPIOD_FLAGS_BIT_DIR_VAL BIT(2)
33 * Optional flags that can be passed to one of gpiod_* to configure direction
34 * and output value. These values cannot be OR'd.
38 GPIOD_IN
= GPIOD_FLAGS_BIT_DIR_SET
,
39 GPIOD_OUT_LOW
= GPIOD_FLAGS_BIT_DIR_SET
| GPIOD_FLAGS_BIT_DIR_OUT
,
40 GPIOD_OUT_HIGH
= GPIOD_FLAGS_BIT_DIR_SET
| GPIOD_FLAGS_BIT_DIR_OUT
|
41 GPIOD_FLAGS_BIT_DIR_VAL
,
46 /* Return the number of GPIOs associated with a device / function */
47 int gpiod_count(struct device
*dev
, const char *con_id
);
49 /* Acquire and dispose GPIOs */
50 struct gpio_desc
*__must_check
gpiod_get(struct device
*dev
,
52 enum gpiod_flags flags
);
53 struct gpio_desc
*__must_check
gpiod_get_index(struct device
*dev
,
56 enum gpiod_flags flags
);
57 struct gpio_desc
*__must_check
gpiod_get_optional(struct device
*dev
,
59 enum gpiod_flags flags
);
60 struct gpio_desc
*__must_check
gpiod_get_index_optional(struct device
*dev
,
63 enum gpiod_flags flags
);
64 struct gpio_descs
*__must_check
gpiod_get_array(struct device
*dev
,
66 enum gpiod_flags flags
);
67 struct gpio_descs
*__must_check
gpiod_get_array_optional(struct device
*dev
,
69 enum gpiod_flags flags
);
70 void gpiod_put(struct gpio_desc
*desc
);
71 void gpiod_put_array(struct gpio_descs
*descs
);
73 struct gpio_desc
*__must_check
devm_gpiod_get(struct device
*dev
,
75 enum gpiod_flags flags
);
76 struct gpio_desc
*__must_check
devm_gpiod_get_index(struct device
*dev
,
79 enum gpiod_flags flags
);
80 struct gpio_desc
*__must_check
devm_gpiod_get_optional(struct device
*dev
,
82 enum gpiod_flags flags
);
83 struct gpio_desc
*__must_check
84 devm_gpiod_get_index_optional(struct device
*dev
, const char *con_id
,
85 unsigned int index
, enum gpiod_flags flags
);
86 struct gpio_descs
*__must_check
devm_gpiod_get_array(struct device
*dev
,
88 enum gpiod_flags flags
);
89 struct gpio_descs
*__must_check
90 devm_gpiod_get_array_optional(struct device
*dev
, const char *con_id
,
91 enum gpiod_flags flags
);
92 void devm_gpiod_put(struct device
*dev
, struct gpio_desc
*desc
);
93 void devm_gpiod_put_array(struct device
*dev
, struct gpio_descs
*descs
);
95 int gpiod_get_direction(struct gpio_desc
*desc
);
96 int gpiod_direction_input(struct gpio_desc
*desc
);
97 int gpiod_direction_output(struct gpio_desc
*desc
, int value
);
98 int gpiod_direction_output_raw(struct gpio_desc
*desc
, int value
);
100 /* Value get/set from non-sleeping context */
101 int gpiod_get_value(const struct gpio_desc
*desc
);
102 void gpiod_set_value(struct gpio_desc
*desc
, int value
);
103 void gpiod_set_array_value(unsigned int array_size
,
104 struct gpio_desc
**desc_array
, int *value_array
);
105 int gpiod_get_raw_value(const struct gpio_desc
*desc
);
106 void gpiod_set_raw_value(struct gpio_desc
*desc
, int value
);
107 void gpiod_set_raw_array_value(unsigned int array_size
,
108 struct gpio_desc
**desc_array
,
111 /* Value get/set from sleeping context */
112 int gpiod_get_value_cansleep(const struct gpio_desc
*desc
);
113 void gpiod_set_value_cansleep(struct gpio_desc
*desc
, int value
);
114 void gpiod_set_array_value_cansleep(unsigned int array_size
,
115 struct gpio_desc
**desc_array
,
117 int gpiod_get_raw_value_cansleep(const struct gpio_desc
*desc
);
118 void gpiod_set_raw_value_cansleep(struct gpio_desc
*desc
, int value
);
119 void gpiod_set_raw_array_value_cansleep(unsigned int array_size
,
120 struct gpio_desc
**desc_array
,
123 int gpiod_set_debounce(struct gpio_desc
*desc
, unsigned debounce
);
125 int gpiod_is_active_low(const struct gpio_desc
*desc
);
126 int gpiod_cansleep(const struct gpio_desc
*desc
);
128 int gpiod_to_irq(const struct gpio_desc
*desc
);
130 /* Convert between the old gpio_ and new gpiod_ interfaces */
131 struct gpio_desc
*gpio_to_desc(unsigned gpio
);
132 int desc_to_gpio(const struct gpio_desc
*desc
);
134 /* Child properties interface */
135 struct fwnode_handle
;
137 struct gpio_desc
*fwnode_get_named_gpiod(struct fwnode_handle
*fwnode
,
138 const char *propname
);
139 struct gpio_desc
*devm_get_gpiod_from_child(struct device
*dev
,
141 struct fwnode_handle
*child
);
142 #else /* CONFIG_GPIOLIB */
144 static inline int gpiod_count(struct device
*dev
, const char *con_id
)
149 static inline struct gpio_desc
*__must_check
gpiod_get(struct device
*dev
,
151 enum gpiod_flags flags
)
153 return ERR_PTR(-ENOSYS
);
155 static inline struct gpio_desc
*__must_check
156 gpiod_get_index(struct device
*dev
,
159 enum gpiod_flags flags
)
161 return ERR_PTR(-ENOSYS
);
164 static inline struct gpio_desc
*__must_check
165 gpiod_get_optional(struct device
*dev
, const char *con_id
,
166 enum gpiod_flags flags
)
168 return ERR_PTR(-ENOSYS
);
171 static inline struct gpio_desc
*__must_check
172 gpiod_get_index_optional(struct device
*dev
, const char *con_id
,
173 unsigned int index
, enum gpiod_flags flags
)
175 return ERR_PTR(-ENOSYS
);
178 static inline struct gpio_descs
*__must_check
179 gpiod_get_array(struct device
*dev
, const char *con_id
,
180 enum gpiod_flags flags
)
182 return ERR_PTR(-ENOSYS
);
185 static inline struct gpio_descs
*__must_check
186 gpiod_get_array_optional(struct device
*dev
, const char *con_id
,
187 enum gpiod_flags flags
)
189 return ERR_PTR(-ENOSYS
);
192 static inline void gpiod_put(struct gpio_desc
*desc
)
196 /* GPIO can never have been requested */
200 static inline void gpiod_put_array(struct gpio_descs
*descs
)
204 /* GPIO can never have been requested */
208 static inline struct gpio_desc
*__must_check
209 devm_gpiod_get(struct device
*dev
,
211 enum gpiod_flags flags
)
213 return ERR_PTR(-ENOSYS
);
216 struct gpio_desc
*__must_check
217 devm_gpiod_get_index(struct device
*dev
,
220 enum gpiod_flags flags
)
222 return ERR_PTR(-ENOSYS
);
225 static inline struct gpio_desc
*__must_check
226 devm_gpiod_get_optional(struct device
*dev
, const char *con_id
,
227 enum gpiod_flags flags
)
229 return ERR_PTR(-ENOSYS
);
232 static inline struct gpio_desc
*__must_check
233 devm_gpiod_get_index_optional(struct device
*dev
, const char *con_id
,
234 unsigned int index
, enum gpiod_flags flags
)
236 return ERR_PTR(-ENOSYS
);
239 static inline struct gpio_descs
*__must_check
240 devm_gpiod_get_array(struct device
*dev
, const char *con_id
,
241 enum gpiod_flags flags
)
243 return ERR_PTR(-ENOSYS
);
246 static inline struct gpio_descs
*__must_check
247 devm_gpiod_get_array_optional(struct device
*dev
, const char *con_id
,
248 enum gpiod_flags flags
)
250 return ERR_PTR(-ENOSYS
);
253 static inline void devm_gpiod_put(struct device
*dev
, struct gpio_desc
*desc
)
257 /* GPIO can never have been requested */
261 static inline void devm_gpiod_put_array(struct device
*dev
,
262 struct gpio_descs
*descs
)
266 /* GPIO can never have been requested */
271 static inline int gpiod_get_direction(const struct gpio_desc
*desc
)
273 /* GPIO can never have been requested */
277 static inline int gpiod_direction_input(struct gpio_desc
*desc
)
279 /* GPIO can never have been requested */
283 static inline int gpiod_direction_output(struct gpio_desc
*desc
, int value
)
285 /* GPIO can never have been requested */
289 static inline int gpiod_direction_output_raw(struct gpio_desc
*desc
, int value
)
291 /* GPIO can never have been requested */
297 static inline int gpiod_get_value(const struct gpio_desc
*desc
)
299 /* GPIO can never have been requested */
303 static inline void gpiod_set_value(struct gpio_desc
*desc
, int value
)
305 /* GPIO can never have been requested */
308 static inline void gpiod_set_array_value(unsigned int array_size
,
309 struct gpio_desc
**desc_array
,
312 /* GPIO can never have been requested */
315 static inline int gpiod_get_raw_value(const struct gpio_desc
*desc
)
317 /* GPIO can never have been requested */
321 static inline void gpiod_set_raw_value(struct gpio_desc
*desc
, int value
)
323 /* GPIO can never have been requested */
326 static inline void gpiod_set_raw_array_value(unsigned int array_size
,
327 struct gpio_desc
**desc_array
,
330 /* GPIO can never have been requested */
334 static inline int gpiod_get_value_cansleep(const struct gpio_desc
*desc
)
336 /* GPIO can never have been requested */
340 static inline void gpiod_set_value_cansleep(struct gpio_desc
*desc
, int value
)
342 /* GPIO can never have been requested */
345 static inline void gpiod_set_array_value_cansleep(unsigned int array_size
,
346 struct gpio_desc
**desc_array
,
349 /* GPIO can never have been requested */
352 static inline int gpiod_get_raw_value_cansleep(const struct gpio_desc
*desc
)
354 /* GPIO can never have been requested */
358 static inline void gpiod_set_raw_value_cansleep(struct gpio_desc
*desc
,
361 /* GPIO can never have been requested */
364 static inline void gpiod_set_raw_array_value_cansleep(unsigned int array_size
,
365 struct gpio_desc
**desc_array
,
368 /* GPIO can never have been requested */
372 static inline int gpiod_set_debounce(struct gpio_desc
*desc
, unsigned debounce
)
374 /* GPIO can never have been requested */
379 static inline int gpiod_is_active_low(const struct gpio_desc
*desc
)
381 /* GPIO can never have been requested */
385 static inline int gpiod_cansleep(const struct gpio_desc
*desc
)
387 /* GPIO can never have been requested */
392 static inline int gpiod_to_irq(const struct gpio_desc
*desc
)
394 /* GPIO can never have been requested */
399 static inline struct gpio_desc
*gpio_to_desc(unsigned gpio
)
401 return ERR_PTR(-EINVAL
);
404 static inline int desc_to_gpio(const struct gpio_desc
*desc
)
406 /* GPIO can never have been requested */
411 /* Child properties interface */
412 struct fwnode_handle
;
414 static inline struct gpio_desc
*fwnode_get_named_gpiod(
415 struct fwnode_handle
*fwnode
, const char *propname
)
417 return ERR_PTR(-ENOSYS
);
420 static inline struct gpio_desc
*devm_get_gpiod_from_child(
421 struct device
*dev
, const char *con_id
, struct fwnode_handle
*child
)
423 return ERR_PTR(-ENOSYS
);
426 #endif /* CONFIG_GPIOLIB */
428 #if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS)
430 int gpiod_export(struct gpio_desc
*desc
, bool direction_may_change
);
431 int gpiod_export_link(struct device
*dev
, const char *name
,
432 struct gpio_desc
*desc
);
433 void gpiod_unexport(struct gpio_desc
*desc
);
435 #else /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */
437 static inline int gpiod_export(struct gpio_desc
*desc
,
438 bool direction_may_change
)
443 static inline int gpiod_export_link(struct device
*dev
, const char *name
,
444 struct gpio_desc
*desc
)
449 static inline void gpiod_unexport(struct gpio_desc
*desc
)
453 #endif /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */
This page took 0.04966 seconds and 5 git commands to generate.