6lowpan: remove initialization of tag value
[linux-2.6/btrfs-unstable.git] / include / linux / gpio / consumer.h
blob7a8144fef4065fab8505ffcfe2482cc0b60f3cbb
1 #ifndef __LINUX_GPIO_CONSUMER_H
2 #define __LINUX_GPIO_CONSUMER_H
4 #include <linux/err.h>
5 #include <linux/kernel.h>
7 struct device;
8 struct gpio_chip;
10 /**
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.
17 struct gpio_desc;
19 #ifdef CONFIG_GPIOLIB
21 /* Acquire and dispose GPIOs */
22 struct gpio_desc *__must_check gpiod_get(struct device *dev,
23 const char *con_id);
24 struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
25 const char *con_id,
26 unsigned int idx);
27 void gpiod_put(struct gpio_desc *desc);
29 struct gpio_desc *__must_check devm_gpiod_get(struct device *dev,
30 const char *con_id);
31 struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev,
32 const char *con_id,
33 unsigned int idx);
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,
67 const char *con_id)
69 return ERR_PTR(-ENOSYS);
71 static inline struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
72 const char *con_id,
73 unsigned int idx)
75 return ERR_PTR(-ENOSYS);
77 static inline void gpiod_put(struct gpio_desc *desc)
79 might_sleep();
81 /* GPIO can never have been requested */
82 WARN_ON(1);
85 static inline struct gpio_desc *__must_check devm_gpiod_get(struct device *dev,
86 const char *con_id)
88 return ERR_PTR(-ENOSYS);
90 static inline
91 struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev,
92 const char *con_id,
93 unsigned int idx)
95 return ERR_PTR(-ENOSYS);
97 static inline void devm_gpiod_put(struct device *dev, struct gpio_desc *desc)
99 might_sleep();
101 /* GPIO can never have been requested */
102 WARN_ON(1);
106 static inline int gpiod_get_direction(const struct gpio_desc *desc)
108 /* GPIO can never have been requested */
109 WARN_ON(1);
110 return -ENOSYS;
112 static inline int gpiod_direction_input(struct gpio_desc *desc)
114 /* GPIO can never have been requested */
115 WARN_ON(1);
116 return -ENOSYS;
118 static inline int gpiod_direction_output(struct gpio_desc *desc, int value)
120 /* GPIO can never have been requested */
121 WARN_ON(1);
122 return -ENOSYS;
126 static inline int gpiod_get_value(const struct gpio_desc *desc)
128 /* GPIO can never have been requested */
129 WARN_ON(1);
130 return 0;
132 static inline void gpiod_set_value(struct gpio_desc *desc, int value)
134 /* GPIO can never have been requested */
135 WARN_ON(1);
137 static inline int gpiod_get_raw_value(const struct gpio_desc *desc)
139 /* GPIO can never have been requested */
140 WARN_ON(1);
141 return 0;
143 static inline void gpiod_set_raw_value(struct gpio_desc *desc, int value)
145 /* GPIO can never have been requested */
146 WARN_ON(1);
149 static inline int gpiod_get_value_cansleep(const struct gpio_desc *desc)
151 /* GPIO can never have been requested */
152 WARN_ON(1);
153 return 0;
155 static inline void gpiod_set_value_cansleep(struct gpio_desc *desc, int value)
157 /* GPIO can never have been requested */
158 WARN_ON(1);
160 static inline int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc)
162 /* GPIO can never have been requested */
163 WARN_ON(1);
164 return 0;
166 static inline void gpiod_set_raw_value_cansleep(struct gpio_desc *desc,
167 int value)
169 /* GPIO can never have been requested */
170 WARN_ON(1);
173 static inline int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce)
175 /* GPIO can never have been requested */
176 WARN_ON(1);
177 return -ENOSYS;
180 static inline int gpiod_is_active_low(const struct gpio_desc *desc)
182 /* GPIO can never have been requested */
183 WARN_ON(1);
184 return 0;
186 static inline int gpiod_cansleep(const struct gpio_desc *desc)
188 /* GPIO can never have been requested */
189 WARN_ON(1);
190 return 0;
193 static inline int gpiod_to_irq(const struct gpio_desc *desc)
195 /* GPIO can never have been requested */
196 WARN_ON(1);
197 return -EINVAL;
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 */
207 WARN_ON(1);
208 return -EINVAL;
210 static inline struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc)
212 /* GPIO can never have been requested */
213 WARN_ON(1);
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)
233 return -ENOSYS;
236 static inline int gpiod_export_link(struct device *dev, const char *name,
237 struct gpio_desc *desc)
239 return -ENOSYS;
242 static inline int gpiod_sysfs_set_active_low(struct gpio_desc *desc, int value)
244 return -ENOSYS;
247 static inline void gpiod_unexport(struct gpio_desc *desc)
251 #endif /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */
253 #endif