]>
git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - include/linux/gpio/consumer.h
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.
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 struct gpio_desc
*__must_check
gpiod_get_optional(struct device
*dev
,
29 struct gpio_desc
*__must_check
gpiod_get_index_optional(struct device
*dev
,
33 void gpiod_put(struct gpio_desc
*desc
);
35 struct gpio_desc
*__must_check
devm_gpiod_get(struct device
*dev
,
37 struct gpio_desc
*__must_check
devm_gpiod_get_index(struct device
*dev
,
40 struct gpio_desc
*__must_check
devm_gpiod_get_optional(struct device
*dev
,
42 struct gpio_desc
*__must_check
43 devm_gpiod_get_index_optional(struct device
*dev
, const char *con_id
,
46 void devm_gpiod_put(struct device
*dev
, struct gpio_desc
*desc
);
48 int gpiod_get_direction(const struct gpio_desc
*desc
);
49 int gpiod_direction_input(struct gpio_desc
*desc
);
50 int gpiod_direction_output(struct gpio_desc
*desc
, int value
);
51 int gpiod_direction_output_raw(struct gpio_desc
*desc
, int value
);
53 /* Value get/set from non-sleeping context */
54 int gpiod_get_value(const struct gpio_desc
*desc
);
55 void gpiod_set_value(struct gpio_desc
*desc
, int value
);
56 int gpiod_get_raw_value(const struct gpio_desc
*desc
);
57 void gpiod_set_raw_value(struct gpio_desc
*desc
, int value
);
59 /* Value get/set from sleeping context */
60 int gpiod_get_value_cansleep(const struct gpio_desc
*desc
);
61 void gpiod_set_value_cansleep(struct gpio_desc
*desc
, int value
);
62 int gpiod_get_raw_value_cansleep(const struct gpio_desc
*desc
);
63 void gpiod_set_raw_value_cansleep(struct gpio_desc
*desc
, int value
);
65 int gpiod_set_debounce(struct gpio_desc
*desc
, unsigned debounce
);
67 int gpiod_is_active_low(const struct gpio_desc
*desc
);
68 int gpiod_cansleep(const struct gpio_desc
*desc
);
70 int gpiod_to_irq(const struct gpio_desc
*desc
);
72 /* Convert between the old gpio_ and new gpiod_ interfaces */
73 struct gpio_desc
*gpio_to_desc(unsigned gpio
);
74 int desc_to_gpio(const struct gpio_desc
*desc
);
76 #else /* CONFIG_GPIOLIB */
78 static inline struct gpio_desc
*__must_check
gpiod_get(struct device
*dev
,
81 return ERR_PTR(-ENOSYS
);
83 static inline struct gpio_desc
*__must_check
gpiod_get_index(struct device
*dev
,
87 return ERR_PTR(-ENOSYS
);
90 static inline struct gpio_desc
*__must_check
91 gpiod_get_optional(struct device
*dev
, const char *con_id
)
93 return ERR_PTR(-ENOSYS
);
96 static inline struct gpio_desc
*__must_check
97 gpiod_get_index_optional(struct device
*dev
, const char *con_id
,
100 return ERR_PTR(-ENOSYS
);
103 static inline void gpiod_put(struct gpio_desc
*desc
)
107 /* GPIO can never have been requested */
111 static inline struct gpio_desc
*__must_check
devm_gpiod_get(struct device
*dev
,
114 return ERR_PTR(-ENOSYS
);
117 struct gpio_desc
*__must_check
devm_gpiod_get_index(struct device
*dev
,
121 return ERR_PTR(-ENOSYS
);
124 static inline struct gpio_desc
*__must_check
125 devm_gpiod_get_optional(struct device
*dev
, const char *con_id
)
127 return ERR_PTR(-ENOSYS
);
130 static inline struct gpio_desc
*__must_check
131 devm_gpiod_get_index_optional(struct device
*dev
, const char *con_id
,
134 return ERR_PTR(-ENOSYS
);
137 static inline void devm_gpiod_put(struct device
*dev
, struct gpio_desc
*desc
)
141 /* GPIO can never have been requested */
146 static inline int gpiod_get_direction(const struct gpio_desc
*desc
)
148 /* GPIO can never have been requested */
152 static inline int gpiod_direction_input(struct gpio_desc
*desc
)
154 /* GPIO can never have been requested */
158 static inline int gpiod_direction_output(struct gpio_desc
*desc
, int value
)
160 /* GPIO can never have been requested */
164 static inline int gpiod_direction_output_raw(struct gpio_desc
*desc
, int value
)
166 /* GPIO can never have been requested */
172 static inline int gpiod_get_value(const struct gpio_desc
*desc
)
174 /* GPIO can never have been requested */
178 static inline void gpiod_set_value(struct gpio_desc
*desc
, int value
)
180 /* GPIO can never have been requested */
183 static inline int gpiod_get_raw_value(const struct gpio_desc
*desc
)
185 /* GPIO can never have been requested */
189 static inline void gpiod_set_raw_value(struct gpio_desc
*desc
, int value
)
191 /* GPIO can never have been requested */
195 static inline int gpiod_get_value_cansleep(const struct gpio_desc
*desc
)
197 /* GPIO can never have been requested */
201 static inline void gpiod_set_value_cansleep(struct gpio_desc
*desc
, int value
)
203 /* GPIO can never have been requested */
206 static inline int gpiod_get_raw_value_cansleep(const struct gpio_desc
*desc
)
208 /* GPIO can never have been requested */
212 static inline void gpiod_set_raw_value_cansleep(struct gpio_desc
*desc
,
215 /* GPIO can never have been requested */
219 static inline int gpiod_set_debounce(struct gpio_desc
*desc
, unsigned debounce
)
221 /* GPIO can never have been requested */
226 static inline int gpiod_is_active_low(const struct gpio_desc
*desc
)
228 /* GPIO can never have been requested */
232 static inline int gpiod_cansleep(const struct gpio_desc
*desc
)
234 /* GPIO can never have been requested */
239 static inline int gpiod_to_irq(const struct gpio_desc
*desc
)
241 /* GPIO can never have been requested */
246 static inline struct gpio_desc
*gpio_to_desc(unsigned gpio
)
248 return ERR_PTR(-EINVAL
);
250 static inline int desc_to_gpio(const struct gpio_desc
*desc
)
252 /* GPIO can never have been requested */
258 #endif /* CONFIG_GPIOLIB */
260 #if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS)
262 int gpiod_export(struct gpio_desc
*desc
, bool direction_may_change
);
263 int gpiod_export_link(struct device
*dev
, const char *name
,
264 struct gpio_desc
*desc
);
265 int gpiod_sysfs_set_active_low(struct gpio_desc
*desc
, int value
);
266 void gpiod_unexport(struct gpio_desc
*desc
);
268 #else /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */
270 static inline int gpiod_export(struct gpio_desc
*desc
,
271 bool direction_may_change
)
276 static inline int gpiod_export_link(struct device
*dev
, const char *name
,
277 struct gpio_desc
*desc
)
282 static inline int gpiod_sysfs_set_active_low(struct gpio_desc
*desc
, int value
)
287 static inline void gpiod_unexport(struct gpio_desc
*desc
)
291 #endif /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */