aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/gpio/consumer.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/gpio/consumer.h')
-rw-r--r--include/linux/gpio/consumer.h77
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 */
17struct gpio_desc; 17struct gpio_desc;
18 18
19/**
20 * Struct containing an array of descriptors that can be obtained using
21 * gpiod_get_array().
22 */
23struct 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 */
47int gpiod_count(struct device *dev, const char *con_id);
48
37/* Acquire and dispose GPIOs */ 49/* Acquire and dispose GPIOs */
38struct gpio_desc *__must_check __gpiod_get(struct device *dev, 50struct 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);
64struct gpio_descs *__must_check gpiod_get_array(struct device *dev,
65 const char *con_id,
66 enum gpiod_flags flags);
67struct gpio_descs *__must_check gpiod_get_array_optional(struct device *dev,
68 const char *con_id,
69 enum gpiod_flags flags);
52void gpiod_put(struct gpio_desc *desc); 70void gpiod_put(struct gpio_desc *desc);
71void gpiod_put_array(struct gpio_descs *descs);
53 72
54struct gpio_desc *__must_check __devm_gpiod_get(struct device *dev, 73struct 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,
64struct gpio_desc *__must_check 83struct 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);
86struct gpio_descs *__must_check devm_gpiod_get_array(struct device *dev,
87 const char *con_id,
88 enum gpiod_flags flags);
89struct gpio_descs *__must_check
90devm_gpiod_get_array_optional(struct device *dev, const char *con_id,
91 enum gpiod_flags flags);
67void devm_gpiod_put(struct device *dev, struct gpio_desc *desc); 92void devm_gpiod_put(struct device *dev, struct gpio_desc *desc);
93void devm_gpiod_put_array(struct device *dev, struct gpio_descs *descs);
68 94
69int gpiod_get_direction(struct gpio_desc *desc); 95int gpiod_get_direction(struct gpio_desc *desc);
70int gpiod_direction_input(struct gpio_desc *desc); 96int gpiod_direction_input(struct gpio_desc *desc);
@@ -110,9 +136,15 @@ struct fwnode_handle;
110struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, 136struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
111 const char *propname); 137 const char *propname);
112struct gpio_desc *devm_get_gpiod_from_child(struct device *dev, 138struct 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
143static inline int gpiod_count(struct device *dev, const char *con_id)
144{
145 return 0;
146}
147
116static inline struct gpio_desc *__must_check __gpiod_get(struct device *dev, 148static 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
177static inline struct gpio_descs *__must_check
178gpiod_get_array(struct device *dev, const char *con_id,
179 enum gpiod_flags flags)
180{
181 return ERR_PTR(-ENOSYS);
182}
183
184static inline struct gpio_descs *__must_check
185gpiod_get_array_optional(struct device *dev, const char *con_id,
186 enum gpiod_flags flags)
187{
188 return ERR_PTR(-ENOSYS);
189}
190
145static inline void gpiod_put(struct gpio_desc *desc) 191static 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
199static 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
153static inline struct gpio_desc *__must_check 207static 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
238static inline struct gpio_descs *__must_check
239devm_gpiod_get_array(struct device *dev, const char *con_id,
240 enum gpiod_flags flags)
241{
242 return ERR_PTR(-ENOSYS);
243}
244
245static inline struct gpio_descs *__must_check
246devm_gpiod_get_array_optional(struct device *dev, const char *con_id,
247 enum gpiod_flags flags)
248{
249 return ERR_PTR(-ENOSYS);
250}
251
184static inline void devm_gpiod_put(struct device *dev, struct gpio_desc *desc) 252static 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
260static 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
193static inline int gpiod_get_direction(const struct gpio_desc *desc) 270static inline int gpiod_get_direction(const struct gpio_desc *desc)
194{ 271{