Skip to contentSkip to conversation

gpiolib: add gpiod_get_array and gpiod_put_array functions

PATCH In review Rojhalat Ibrahim 2 participants 3 messages Feb 11, 2015 – Mar 5, 2015

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v5 2/4 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 part:

DT part:

---
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

 Documentation/gpio/consumer.txt |  33 ++++++++-
 drivers/gpio/gpiolib-acpi.c     |  84 +++++++++++++++++++++++
 drivers/gpio/gpiolib.c          | 145 ++++++++++++++++++++++++++++++++++++++++
 drivers/gpio/gpiolib.h          |   7 ++
 include/linux/gpio/consumer.h   |  46 +++++++++++++
 5 files changed, 312 insertions(+), 3 deletions(-)
Documentation/gpio/consumer.txt +30 -3
index d85fbae..2924f2f 100644
@@ -58,7 +58,6 @@ pattern where a GPIO is optional, the gpiod_get_optional() and
 gpiod_get_index_optional() functions can be used. These functions return NULL
 instead of -ENOENT if no GPIO has been assigned to the requested function:
 
-
 	struct gpio_desc *gpiod_get_optional(struct device *dev,
 					     const char *con_id,
 					     enum gpiod_flags flags)
@@ -68,6 +67,27 @@ instead of -ENOENT if no GPIO has been assigned to the requested function:
 						   unsigned int index,
 						   enum gpiod_flags flags)
 
+For a function using multiple GPIOs all of those can be obtained with one call:
+
+	struct gpio_descs *gpiod_get_array(struct device *dev,
+					   const char *con_id,
+					   enum gpiod_flags flags)
+
+This function returns a struct gpio_descs which contains an array of
+descriptors:
+
+	struct gpio_descs {
+		unsigned int ndescs;
+		struct gpio_desc *desc[];
+	}
+
+The following function returns NULL instead of -ENOENT if no GPIOs have been
+assigned to the requested function:
+
+	struct gpio_descs *gpiod_get_array_optional(struct device *dev,
+						    const char *con_id,
+						    enum gpiod_flags flags)
+
 Device-managed variants of these functions are also defined:
 
 	struct gpio_desc *devm_gpiod_get(struct device *dev, const char *con_id,
@@ -91,8 +111,15 @@ A GPIO descriptor can be disposed of using the gpiod_put() function:
 
 	void gpiod_put(struct gpio_desc *desc)
 
-It is strictly forbidden to use a descriptor after calling this function. The
-device-managed variant is, unsurprisingly:
+For an array of GPIOs this function can be used:
+
+	void gpiod_put_array(struct gpio_descs *descs)
+
+It is strictly forbidden to use a descriptor after calling these functions.
+It is also not allowed to individually release descriptors (using gpiod_put())
+from an array acquired with gpiod_get_array().
+
+The device-managed variant is, unsurprisingly:
 
 	void devm_gpiod_put(struct device *dev, struct gpio_desc *desc)
 
drivers/gpio/gpiolib-acpi.c +84 -0

87 lines not on this page · raw message

drivers/gpio/gpiolib.c +145 -0

163 lines not on this page · raw message

drivers/gpio/gpiolib.h +7 -0
index 3cbf3dd..054b401 100644
@@ -40,6 +40,8 @@ void acpi_gpiochip_free_interrupts(struct gpio_chip *chip);
 struct gpio_desc *acpi_get_gpiod_by_index(struct acpi_device *adev,
 					  const char *propname, int index,
 					  struct acpi_gpio_info *info);
+
+int acpi_gpio_count(struct device *dev, const char *con_id);
 #else
 static inline void acpi_gpiochip_add(struct gpio_chip *chip) { }
 static inline void acpi_gpiochip_remove(struct gpio_chip *chip) { }
@@ -56,6 +58,11 @@ acpi_get_gpiod_by_index(struct acpi_device *adev, const char *propname,
 {
 	return ERR_PTR(-ENOSYS);
 }
+
+static inline int acpi_gpio_count(struct device *dev, const char *con_id)
+{
+	return -ENODEV;
+}
 #endif
 
 struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np,
include/linux/gpio/consumer.h +46 -0

83 lines not on this page · raw message

Signature · 1 line
2.0.5
#1 lore raw
Quoted 13 lines · Rojhalat Ibrahim

Introduce new functions for conveniently obtaining and disposing of an entire array of GPIOs with one function call.

ACPI part:

DT part:

Quoted 13 lines

---
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

Patch applied with some fuzzing, check that it ended up correctly in my git (or linux-next).

Yours,
Linus Walleij

#2 lore raw
Quoted 29 lines · On Thursday 05 March 2015 09:55:09 Linus Walleij wrote:
Quoted 13 lines · Rojhalat Ibrahim

Introduce new functions for conveniently obtaining and disposing of an entire array of GPIOs with one function call.

ACPI part:

DT part:

Quoted 13 lines

---
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

Quoted 3 lines

Patch applied with some fuzzing, check that it ended up correctly in my git (or linux-next).

Looks good to me.

Thanks.
Rojhalat