aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/gpio/consumer.h
diff options
context:
space:
mode:
authorRojhalat Ibrahim <imr@rtschenk.de>2015-02-11 11:27:58 -0500
committerLinus Walleij <linus.walleij@linaro.org>2015-03-05 03:52:28 -0500
commit668585273246f67b0cdafa30dd2da2047a2e1290 (patch)
treec6e3186d6aab7d08e0f50b5030be4bef4a8b17df /include/linux/gpio/consumer.h
parent7f2e553a7173b485db41a52060f91fb8e5ab1c69 (diff)
gpiolib: add gpiod_get_array and gpiod_put_array functions
Introduce new functions for conveniently obtaining and disposing of an entire array of GPIOs with one function call. ACPI parts tested by Mika Westerberg, DT parts tested by Rojhalat Ibrahim. Change log: v5: move the ACPI functions to gpiolib-acpi.c v4: - use shorter names for members of struct gpio_descs - rename lut_gpio_count to platform_gpio_count for clarity - add check for successful memory allocation - use ERR_CAST() v3: - rebase on current linux-gpio devel branch - fix ACPI GPIO counting - allow for zero-sized arrays - make the flags argument mandatory for the new functions - clarify documentation v2: change interface Suggested-by: Alexandre Courbot <acourbot@nvidia.com> Signed-off-by: Rojhalat Ibrahim <imr@rtschenk.de> Reviewed-by: Alexandre Courbot <acourbot@nvidia.com> Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com> Tested-by: Mika Westerberg <mika.westerberg@linux.intel.com> Tested-by: Rojhalat Ibrahim <imr@rtschenk.de> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'include/linux/gpio/consumer.h')
-rw-r--r--include/linux/gpio/consumer.h46
1 files changed, 46 insertions, 0 deletions
diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h
index ed20759229eb..33eb52fd0932 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,
@@ -114,6 +133,11 @@ struct gpio_desc *devm_get_gpiod_from_child(struct device *dev,
114 struct fwnode_handle *child); 133 struct fwnode_handle *child);
115#else /* CONFIG_GPIOLIB */ 134#else /* CONFIG_GPIOLIB */
116 135
136static inline int gpiod_count(struct device *dev, const char *con_id)
137{
138 return 0;
139}
140
117static inline struct gpio_desc *__must_check __gpiod_get(struct device *dev, 141static inline struct gpio_desc *__must_check __gpiod_get(struct device *dev,
118 const char *con_id, 142 const char *con_id,
119 enum gpiod_flags flags) 143 enum gpiod_flags flags)
@@ -143,6 +167,20 @@ __gpiod_get_index_optional(struct device *dev, const char *con_id,
143 return ERR_PTR(-ENOSYS); 167 return ERR_PTR(-ENOSYS);
144} 168}
145 169
170static inline struct gpio_descs *__must_check
171gpiod_get_array(struct device *dev, const char *con_id,
172 enum gpiod_flags flags)
173{
174 return ERR_PTR(-ENOSYS);
175}
176
177static inline struct gpio_descs *__must_check
178gpiod_get_array_optional(struct device *dev, const char *con_id,
179 enum gpiod_flags flags)
180{
181 return ERR_PTR(-ENOSYS);
182}
183
146static inline void gpiod_put(struct gpio_desc *desc) 184static inline void gpiod_put(struct gpio_desc *desc)
147{ 185{
148 might_sleep(); 186 might_sleep();
@@ -151,6 +189,14 @@ static inline void gpiod_put(struct gpio_desc *desc)
151 WARN_ON(1); 189 WARN_ON(1);
152} 190}
153 191
192static inline void gpiod_put_array(struct gpio_descs *descs)
193{
194 might_sleep();
195
196 /* GPIO can never have been requested */
197 WARN_ON(1);
198}
199
154static inline struct gpio_desc *__must_check 200static inline struct gpio_desc *__must_check
155__devm_gpiod_get(struct device *dev, 201__devm_gpiod_get(struct device *dev,
156 const char *con_id, 202 const char *con_id,