[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1404295551-13470-3-git-send-email-rob.jones@codethink.co.uk>
Date: Wed, 2 Jul 2014 11:05:50 +0100
From: Rob Jones <rob.jones@...ethink.co.uk>
To: linus.walleij@...aro.org, gnurou@...il.com
Cc: lgirdwood@...il.com, broonie@...nel.org,
linux-gpio@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-kernel@...ethink.co.uk, ian.molton@...ethink.co.uk,
ben.dooks@...ethink.co.uk, heiko@...ech.de,
rob.jones@...ethink.co.uk
Subject: [PATCH V2 2/3] gpio: allow gpio array requests for managed devices
Add functions devm_gpio_request_array() and devm_gpio_free_array()
which are exactly analogous to the equivalent non-managed device
functions gpio_request_array() and gpio_free_array(), which can be
found in the module gpiolib.c.
Reviewed-by: Ian Molton <ian.molton@...ethink.co.uk>
Signed-off-by: Rob Jones <rob.jones@...ethink.co.uk>
---
drivers/gpio/devres.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++
include/linux/gpio.h | 4 ++++
2 files changed, 67 insertions(+)
diff --git a/drivers/gpio/devres.c b/drivers/gpio/devres.c
index 307464f..b97c34b 100644
--- a/drivers/gpio/devres.c
+++ b/drivers/gpio/devres.c
@@ -186,6 +186,69 @@ int devm_gpio_request_one(struct device *dev, unsigned gpio,
EXPORT_SYMBOL(devm_gpio_request_one);
/**
+ * devm_gpio_request_array - request multiple GPIOs in a single call
+ * for a managed device
+ * @dev: device requesting the gpio
+ * @array: array of the 'struct gpio'
+ * @num: how many GPIOs in the array
+ *
+ * Except for the extra @dev argument, this function takes the
+ * same arguments and performs the same function as
+ * gpio_request(). GPIOs requested with this function will be
+ * automatically freed on driver detach.
+ *
+ * Note that if any gpio request returns an error, any gpios previously
+ * obtained are immediately freed and the error code is returned,
+ * meaning that the whole call failed and no gpios are obtained, no
+ * indication is provided as to which particular request failed.
+ *
+ * If GPIOs allocated with this function need to be freed separately,
+ * devm_gpio_free_array() or devm_gpio_free() must be used.
+ */
+int devm_gpio_request_array(struct device *dev,
+ const struct gpio *array,
+ size_t num)
+{
+ int i, err = 0;
+
+ for (i = 0; i < num; i++, array++) {
+ err = devm_gpio_request_one(dev,
+ array->gpio,
+ array->flags,
+ array->label);
+ if (err) {
+ while (i--)
+ devm_gpio_free(dev, (--array)->gpio);
+ break;
+ }
+ }
+
+ return err;
+}
+EXPORT_SYMBOL(devm_gpio_request_array);
+
+/**
+ * devm_gpio_free_array - release multiple GPIOs in a single call
+ * for a managed device
+ * @dev: device requesting the gpio
+ * @array: array of the 'struct gpio'
+ * @num: how many GPIOs in the array
+ *
+ * Except for the extra @dev argument, this function takes the
+ * same arguments and performs the same function as gpio_free_array().
+ * This function instead of gpio_free_array() should be used to
+ * manually free GPIOs allocated with devm_gpio_request().
+ */
+void devm_gpio_free_array(struct device *dev,
+ const struct gpio *array,
+ size_t num)
+{
+ while (num--)
+ devm_gpio_free(dev, (array++)->gpio);
+}
+EXPORT_SYMBOL(devm_gpio_free_array);
+
+/**
* devm_gpio_free - free a GPIO
* @dev: device to free GPIO for
* @gpio: GPIO to free
diff --git a/include/linux/gpio.h b/include/linux/gpio.h
index 85aa5d0..12d5648 100644
--- a/include/linux/gpio.h
+++ b/include/linux/gpio.h
@@ -84,6 +84,10 @@ struct device;
int devm_gpio_request(struct device *dev, unsigned gpio, const char *label);
int devm_gpio_request_one(struct device *dev, unsigned gpio,
unsigned long flags, const char *label);
+int devm_gpio_request_array(struct device *dev, const struct gpio *array,
+ size_t num);
+void devm_gpio_free_array(struct device *dev, const struct gpio *array,
+ size_t num);
void devm_gpio_free(struct device *dev, unsigned int gpio);
#else /* ! CONFIG_GPIOLIB */
--
1.7.10.4
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists