diff options
Diffstat (limited to 'include/linux/gpio/consumer.h')
-rw-r--r-- | include/linux/gpio/consumer.h | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h index 45afc2dee560..3a7c9ffd5ab9 100644 --- a/include/linux/gpio/consumer.h +++ b/include/linux/gpio/consumer.h | |||
@@ -16,6 +16,15 @@ struct device; | |||
16 | */ | 16 | */ |
17 | struct gpio_desc; | 17 | struct gpio_desc; |
18 | 18 | ||
19 | /** | ||
20 | * Struct containing an array of descriptors that can be obtained using | ||
21 | * gpiod_get_array(). | ||
22 | */ | ||
23 | struct gpio_descs { | ||
24 | unsigned int ndescs; | ||
25 | struct gpio_desc *desc[]; | ||
26 | }; | ||
27 | |||
19 | #define GPIOD_FLAGS_BIT_DIR_SET BIT(0) | 28 | #define GPIOD_FLAGS_BIT_DIR_SET BIT(0) |
20 | #define GPIOD_FLAGS_BIT_DIR_OUT BIT(1) | 29 | #define GPIOD_FLAGS_BIT_DIR_OUT BIT(1) |
21 | #define GPIOD_FLAGS_BIT_DIR_VAL BIT(2) | 30 | #define GPIOD_FLAGS_BIT_DIR_VAL BIT(2) |
@@ -34,6 +43,9 @@ enum gpiod_flags { | |||
34 | 43 | ||
35 | #ifdef CONFIG_GPIOLIB | 44 | #ifdef CONFIG_GPIOLIB |
36 | 45 | ||
46 | /* Return the number of GPIOs associated with a device / function */ | ||
47 | int gpiod_count(struct device *dev, const char *con_id); | ||
48 | |||
37 | /* Acquire and dispose GPIOs */ | 49 | /* Acquire and dispose GPIOs */ |
38 | struct gpio_desc *__must_check __gpiod_get(struct device *dev, | 50 | struct gpio_desc *__must_check __gpiod_get(struct device *dev, |
39 | const char *con_id, | 51 | const char *con_id, |
@@ -49,7 +61,14 @@ struct gpio_desc *__must_check __gpiod_get_index_optional(struct device *dev, | |||
49 | const char *con_id, | 61 | const char *con_id, |
50 | unsigned int index, | 62 | unsigned int index, |
51 | enum gpiod_flags flags); | 63 | enum gpiod_flags flags); |
64 | struct gpio_descs *__must_check gpiod_get_array(struct device *dev, | ||
65 | const char *con_id, | ||
66 | enum gpiod_flags flags); | ||
67 | struct gpio_descs *__must_check gpiod_get_array_optional(struct device *dev, | ||
68 | const char *con_id, | ||
69 | enum gpiod_flags flags); | ||
52 | void gpiod_put(struct gpio_desc *desc); | 70 | void gpiod_put(struct gpio_desc *desc); |
71 | void gpiod_put_array(struct gpio_descs *descs); | ||
53 | 72 | ||
54 | struct gpio_desc *__must_check __devm_gpiod_get(struct device *dev, | 73 | struct gpio_desc *__must_check __devm_gpiod_get(struct device *dev, |
55 | const char *con_id, | 74 | const char *con_id, |
@@ -64,7 +83,14 @@ struct gpio_desc *__must_check __devm_gpiod_get_optional(struct device *dev, | |||
64 | struct gpio_desc *__must_check | 83 | struct gpio_desc *__must_check |
65 | __devm_gpiod_get_index_optional(struct device *dev, const char *con_id, | 84 | __devm_gpiod_get_index_optional(struct device *dev, const char *con_id, |
66 | unsigned int index, enum gpiod_flags flags); | 85 | unsigned int index, enum gpiod_flags flags); |
86 | struct gpio_descs *__must_check devm_gpiod_get_array(struct device *dev, | ||
87 | const char *con_id, | ||
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); | ||
67 | void devm_gpiod_put(struct device *dev, struct gpio_desc *desc); | 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); | ||
68 | 94 | ||
69 | int gpiod_get_direction(struct gpio_desc *desc); | 95 | int gpiod_get_direction(struct gpio_desc *desc); |
70 | int gpiod_direction_input(struct gpio_desc *desc); | 96 | int gpiod_direction_input(struct gpio_desc *desc); |
@@ -110,9 +136,15 @@ struct fwnode_handle; | |||
110 | struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, | 136 | struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, |
111 | const char *propname); | 137 | const char *propname); |
112 | struct gpio_desc *devm_get_gpiod_from_child(struct device *dev, | 138 | struct gpio_desc *devm_get_gpiod_from_child(struct device *dev, |
139 | const char *con_id, | ||
113 | struct fwnode_handle *child); | 140 | struct fwnode_handle *child); |
114 | #else /* CONFIG_GPIOLIB */ | 141 | #else /* CONFIG_GPIOLIB */ |
115 | 142 | ||
143 | static inline int gpiod_count(struct device *dev, const char *con_id) | ||
144 | { | ||
145 | return 0; | ||
146 | } | ||
147 | |||
116 | static inline struct gpio_desc *__must_check __gpiod_get(struct device *dev, | 148 | static inline struct gpio_desc *__must_check __gpiod_get(struct device *dev, |
117 | const char *con_id, | 149 | const char *con_id, |
118 | enum gpiod_flags flags) | 150 | enum gpiod_flags flags) |
@@ -142,6 +174,20 @@ __gpiod_get_index_optional(struct device *dev, const char *con_id, | |||
142 | return ERR_PTR(-ENOSYS); | 174 | return ERR_PTR(-ENOSYS); |
143 | } | 175 | } |
144 | 176 | ||
177 | static inline struct gpio_descs *__must_check | ||
178 | gpiod_get_array(struct device *dev, const char *con_id, | ||
179 | enum gpiod_flags flags) | ||
180 | { | ||
181 | return ERR_PTR(-ENOSYS); | ||
182 | } | ||
183 | |||
184 | static inline struct gpio_descs *__must_check | ||
185 | gpiod_get_array_optional(struct device *dev, const char *con_id, | ||
186 | enum gpiod_flags flags) | ||
187 | { | ||
188 | return ERR_PTR(-ENOSYS); | ||
189 | } | ||
190 | |||
145 | static inline void gpiod_put(struct gpio_desc *desc) | 191 | static inline void gpiod_put(struct gpio_desc *desc) |
146 | { | 192 | { |
147 | might_sleep(); | 193 | might_sleep(); |
@@ -150,6 +196,14 @@ static inline void gpiod_put(struct gpio_desc *desc) | |||
150 | WARN_ON(1); | 196 | WARN_ON(1); |
151 | } | 197 | } |
152 | 198 | ||
199 | static inline void gpiod_put_array(struct gpio_descs *descs) | ||
200 | { | ||
201 | might_sleep(); | ||
202 | |||
203 | /* GPIO can never have been requested */ | ||
204 | WARN_ON(1); | ||
205 | } | ||
206 | |||
153 | static inline struct gpio_desc *__must_check | 207 | static inline struct gpio_desc *__must_check |
154 | __devm_gpiod_get(struct device *dev, | 208 | __devm_gpiod_get(struct device *dev, |
155 | const char *con_id, | 209 | const char *con_id, |
@@ -181,6 +235,20 @@ __devm_gpiod_get_index_optional(struct device *dev, const char *con_id, | |||
181 | return ERR_PTR(-ENOSYS); | 235 | return ERR_PTR(-ENOSYS); |
182 | } | 236 | } |
183 | 237 | ||
238 | static inline struct gpio_descs *__must_check | ||
239 | devm_gpiod_get_array(struct device *dev, const char *con_id, | ||
240 | enum gpiod_flags flags) | ||
241 | { | ||
242 | return ERR_PTR(-ENOSYS); | ||
243 | } | ||
244 | |||
245 | static inline struct gpio_descs *__must_check | ||
246 | devm_gpiod_get_array_optional(struct device *dev, const char *con_id, | ||
247 | enum gpiod_flags flags) | ||
248 | { | ||
249 | return ERR_PTR(-ENOSYS); | ||
250 | } | ||
251 | |||
184 | static inline void devm_gpiod_put(struct device *dev, struct gpio_desc *desc) | 252 | static inline void devm_gpiod_put(struct device *dev, struct gpio_desc *desc) |
185 | { | 253 | { |
186 | might_sleep(); | 254 | might_sleep(); |
@@ -189,6 +257,15 @@ static inline void devm_gpiod_put(struct device *dev, struct gpio_desc *desc) | |||
189 | WARN_ON(1); | 257 | WARN_ON(1); |
190 | } | 258 | } |
191 | 259 | ||
260 | static inline void devm_gpiod_put_array(struct device *dev, | ||
261 | struct gpio_descs *descs) | ||
262 | { | ||
263 | might_sleep(); | ||
264 | |||
265 | /* GPIO can never have been requested */ | ||
266 | WARN_ON(1); | ||
267 | } | ||
268 | |||
192 | 269 | ||
193 | static inline int gpiod_get_direction(const struct gpio_desc *desc) | 270 | static inline int gpiod_get_direction(const struct gpio_desc *desc) |
194 | { | 271 | { |