1 #ifndef __LINUX_GPIO_CONSUMER_H
2 #define __LINUX_GPIO_CONSUMER_H
5 #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.
21 /* Acquire and dispose GPIOs */
22 struct gpio_desc
*__must_check
gpiod_get(struct device
*dev
,
24 struct gpio_desc
*__must_check
gpiod_get_index(struct device
*dev
,
27 void gpiod_put(struct gpio_desc
*desc
);
29 struct gpio_desc
*__must_check
devm_gpiod_get(struct device
*dev
,
31 struct gpio_desc
*__must_check
devm_gpiod_get_index(struct device
*dev
,
34 void devm_gpiod_put(struct device
*dev
, struct gpio_desc
*desc
);
36 int gpiod_get_direction(const struct gpio_desc
*desc
);
37 int gpiod_direction_input(struct gpio_desc
*desc
);
38 int gpiod_direction_output(struct gpio_desc
*desc
, int value
);
40 /* Value get/set from non-sleeping context */
41 int gpiod_get_value(const struct gpio_desc
*desc
);
42 void gpiod_set_value(struct gpio_desc
*desc
, int value
);
43 int gpiod_get_raw_value(const struct gpio_desc
*desc
);
44 void gpiod_set_raw_value(struct gpio_desc
*desc
, int value
);
46 /* Value get/set from sleeping context */
47 int gpiod_get_value_cansleep(const struct gpio_desc
*desc
);
48 void gpiod_set_value_cansleep(struct gpio_desc
*desc
, int value
);
49 int gpiod_get_raw_value_cansleep(const struct gpio_desc
*desc
);
50 void gpiod_set_raw_value_cansleep(struct gpio_desc
*desc
, int value
);
52 int gpiod_set_debounce(struct gpio_desc
*desc
, unsigned debounce
);
54 int gpiod_is_active_low(const struct gpio_desc
*desc
);
55 int gpiod_cansleep(const struct gpio_desc
*desc
);
57 int gpiod_to_irq(const struct gpio_desc
*desc
);
59 /* Convert between the old gpio_ and new gpiod_ interfaces */
60 struct gpio_desc
*gpio_to_desc(unsigned gpio
);
61 int desc_to_gpio(const struct gpio_desc
*desc
);
62 struct gpio_chip
*gpiod_to_chip(const struct gpio_desc
*desc
);
64 #else /* CONFIG_GPIOLIB */
66 static inline struct gpio_desc
*__must_check
gpiod_get(struct device
*dev
,
69 return ERR_PTR(-ENOSYS
);
71 static inline struct gpio_desc
*__must_check
gpiod_get_index(struct device
*dev
,
75 return ERR_PTR(-ENOSYS
);
77 static inline void gpiod_put(struct gpio_desc
*desc
)
81 /* GPIO can never have been requested */
85 static inline struct gpio_desc
*__must_check
devm_gpiod_get(struct device
*dev
,
88 return ERR_PTR(-ENOSYS
);
91 struct gpio_desc
*__must_check
devm_gpiod_get_index(struct device
*dev
,
95 return ERR_PTR(-ENOSYS
);
97 static inline void devm_gpiod_put(struct device
*dev
, struct gpio_desc
*desc
)
101 /* GPIO can never have been requested */
106 static inline int gpiod_get_direction(const struct gpio_desc
*desc
)
108 /* GPIO can never have been requested */
112 static inline int gpiod_direction_input(struct gpio_desc
*desc
)
114 /* GPIO can never have been requested */
118 static inline int gpiod_direction_output(struct gpio_desc
*desc
, int value
)
120 /* GPIO can never have been requested */
126 static inline int gpiod_get_value(const struct gpio_desc
*desc
)
128 /* GPIO can never have been requested */
132 static inline void gpiod_set_value(struct gpio_desc
*desc
, int value
)
134 /* GPIO can never have been requested */
137 static inline int gpiod_get_raw_value(const struct gpio_desc
*desc
)
139 /* GPIO can never have been requested */
143 static inline void gpiod_set_raw_value(struct gpio_desc
*desc
, int value
)
145 /* GPIO can never have been requested */
149 static inline int gpiod_get_value_cansleep(const struct gpio_desc
*desc
)
151 /* GPIO can never have been requested */
155 static inline void gpiod_set_value_cansleep(struct gpio_desc
*desc
, int value
)
157 /* GPIO can never have been requested */
160 static inline int gpiod_get_raw_value_cansleep(const struct gpio_desc
*desc
)
162 /* GPIO can never have been requested */
166 static inline void gpiod_set_raw_value_cansleep(struct gpio_desc
*desc
,
169 /* GPIO can never have been requested */
173 static inline int gpiod_set_debounce(struct gpio_desc
*desc
, unsigned debounce
)
175 /* GPIO can never have been requested */
180 static inline int gpiod_is_active_low(const struct gpio_desc
*desc
)
182 /* GPIO can never have been requested */
186 static inline int gpiod_cansleep(const struct gpio_desc
*desc
)
188 /* GPIO can never have been requested */
193 static inline int gpiod_to_irq(const struct gpio_desc
*desc
)
195 /* GPIO can never have been requested */
200 static inline struct gpio_desc
*gpio_to_desc(unsigned gpio
)
202 return ERR_PTR(-EINVAL
);
204 static inline int desc_to_gpio(const struct gpio_desc
*desc
)
206 /* GPIO can never have been requested */
210 static inline struct gpio_chip
*gpiod_to_chip(const struct gpio_desc
*desc
)
212 /* GPIO can never have been requested */
214 return ERR_PTR(-ENODEV
);
218 #endif /* CONFIG_GPIOLIB */
220 #if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS)
222 int gpiod_export(struct gpio_desc
*desc
, bool direction_may_change
);
223 int gpiod_export_link(struct device
*dev
, const char *name
,
224 struct gpio_desc
*desc
);
225 int gpiod_sysfs_set_active_low(struct gpio_desc
*desc
, int value
);
226 void gpiod_unexport(struct gpio_desc
*desc
);
228 #else /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */
230 static inline int gpiod_export(struct gpio_desc
*desc
,
231 bool direction_may_change
)
236 static inline int gpiod_export_link(struct device
*dev
, const char *name
,
237 struct gpio_desc
*desc
)
242 static inline int gpiod_sysfs_set_active_low(struct gpio_desc
*desc
, int value
)
247 static inline void gpiod_unexport(struct gpio_desc
*desc
)
251 #endif /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */