]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - include/linux/gpio/consumer.h
gpiolib: add gpiod_get_array and gpiod_put_array functions
[karo-tx-linux.git] / include / linux / gpio / consumer.h
index 45afc2dee560ccc478462789e8fb4d7e38817d10..33eb52fd0932611a5f12e80b0d682a3c5e7e3feb 100644 (file)
@@ -16,6 +16,15 @@ struct device;
  */
 struct gpio_desc;
 
+/**
+ * Struct containing an array of descriptors that can be obtained using
+ * gpiod_get_array().
+ */
+struct gpio_descs {
+       unsigned int ndescs;
+       struct gpio_desc *desc[];
+};
+
 #define GPIOD_FLAGS_BIT_DIR_SET                BIT(0)
 #define GPIOD_FLAGS_BIT_DIR_OUT                BIT(1)
 #define GPIOD_FLAGS_BIT_DIR_VAL                BIT(2)
@@ -34,6 +43,9 @@ enum gpiod_flags {
 
 #ifdef CONFIG_GPIOLIB
 
+/* Return the number of GPIOs associated with a device / function */
+int gpiod_count(struct device *dev, const char *con_id);
+
 /* Acquire and dispose GPIOs */
 struct gpio_desc *__must_check __gpiod_get(struct device *dev,
                                         const char *con_id,
@@ -49,7 +61,14 @@ struct gpio_desc *__must_check __gpiod_get_index_optional(struct device *dev,
                                                        const char *con_id,
                                                        unsigned int index,
                                                        enum gpiod_flags flags);
+struct gpio_descs *__must_check gpiod_get_array(struct device *dev,
+                                               const char *con_id,
+                                               enum gpiod_flags flags);
+struct gpio_descs *__must_check gpiod_get_array_optional(struct device *dev,
+                                                       const char *con_id,
+                                                       enum gpiod_flags flags);
 void gpiod_put(struct gpio_desc *desc);
+void gpiod_put_array(struct gpio_descs *descs);
 
 struct gpio_desc *__must_check __devm_gpiod_get(struct device *dev,
                                              const char *con_id,
@@ -110,9 +129,15 @@ struct fwnode_handle;
 struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
                                         const char *propname);
 struct gpio_desc *devm_get_gpiod_from_child(struct device *dev,
+                                           const char *con_id,
                                            struct fwnode_handle *child);
 #else /* CONFIG_GPIOLIB */
 
+static inline int gpiod_count(struct device *dev, const char *con_id)
+{
+       return 0;
+}
+
 static inline struct gpio_desc *__must_check __gpiod_get(struct device *dev,
                                                const char *con_id,
                                                enum gpiod_flags flags)
@@ -142,6 +167,20 @@ __gpiod_get_index_optional(struct device *dev, const char *con_id,
        return ERR_PTR(-ENOSYS);
 }
 
+static inline struct gpio_descs *__must_check
+gpiod_get_array(struct device *dev, const char *con_id,
+               enum gpiod_flags flags)
+{
+       return ERR_PTR(-ENOSYS);
+}
+
+static inline struct gpio_descs *__must_check
+gpiod_get_array_optional(struct device *dev, const char *con_id,
+                        enum gpiod_flags flags)
+{
+       return ERR_PTR(-ENOSYS);
+}
+
 static inline void gpiod_put(struct gpio_desc *desc)
 {
        might_sleep();
@@ -150,6 +189,14 @@ static inline void gpiod_put(struct gpio_desc *desc)
        WARN_ON(1);
 }
 
+static inline void gpiod_put_array(struct gpio_descs *descs)
+{
+       might_sleep();
+
+       /* GPIO can never have been requested */
+       WARN_ON(1);
+}
+
 static inline struct gpio_desc *__must_check
 __devm_gpiod_get(struct device *dev,
                 const char *con_id,