summaryrefslogtreecommitdiffstats
path: root/drivers/gpio
diff options
context:
space:
mode:
authorAntony Pavlov <antonynpavlov@gmail.com>2013-11-22 00:11:24 +0400
committerSascha Hauer <s.hauer@pengutronix.de>2013-11-22 10:59:04 +0100
commitbcf08772662c47ff69b253c44ac2415507fb9a93 (patch)
tree945f0eb8700af0a19452243aa8dd774f511f1b35 /drivers/gpio
parent6339a419e91ec16afe02cb9270c487778129aa3c (diff)
downloadbarebox-bcf08772662c47ff69b253c44ac2415507fb9a93.tar.gz
barebox-bcf08772662c47ff69b253c44ac2415507fb9a93.tar.xz
gpiolib: import gpio_request_array() from linux 3.7
Also import related functions gpio_request_one() and gpio_free_array(). This commit imports code from linux 3.7 as the more recent linux kernel versions use gpiolib descriptors, see this commit for details: commit 372e722ea4dd4ca11c3d04845e11cbc15f32144c Author: Alexandre Courbot <acourbot@nvidia.com> Date: Sun Feb 3 01:29:29 2013 +0900 gpiolib: use descriptors internally Make sure gpiolib works internally with descriptors and (chip, offset) pairs instead of using the global integer namespace. This prepares the ground for the removal of the global gpio_desc[] array and the introduction of the descriptor-based GPIO API. Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/gpio')
-rw-r--r--drivers/gpio/gpiolib.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 03fc196546..cafef907ef 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -85,6 +85,72 @@ void gpio_free(unsigned gpio)
free(gi->label);
}
+/**
+ * gpio_request_one - request a single GPIO with initial configuration
+ * @gpio: the GPIO number
+ * @flags: GPIO configuration as specified by GPIOF_*
+ * @label: a literal description string of this GPIO
+ */
+int gpio_request_one(unsigned gpio, unsigned long flags, const char *label)
+{
+ int err;
+
+ err = gpio_request(gpio, label);
+ if (err)
+ return err;
+
+ if (flags & GPIOF_DIR_IN)
+ err = gpio_direction_input(gpio);
+ else
+ err = gpio_direction_output(gpio,
+ (flags & GPIOF_INIT_HIGH) ? 1 : 0);
+
+ if (err)
+ goto free_gpio;
+
+ return 0;
+
+ free_gpio:
+ gpio_free(gpio);
+ return err;
+}
+EXPORT_SYMBOL_GPL(gpio_request_one);
+
+/**
+ * gpio_request_array - request multiple GPIOs in a single call
+ * @array: array of the 'struct gpio'
+ * @num: how many GPIOs in the array
+ */
+int gpio_request_array(const struct gpio *array, size_t num)
+{
+ int i, err;
+
+ for (i = 0; i < num; i++, array++) {
+ err = gpio_request_one(array->gpio, array->flags, array->label);
+ if (err)
+ goto err_free;
+ }
+ return 0;
+
+err_free:
+ while (i--)
+ gpio_free((--array)->gpio);
+ return err;
+}
+EXPORT_SYMBOL_GPL(gpio_request_array);
+
+/**
+ * gpio_free_array - release multiple GPIOs in a single call
+ * @array: array of the 'struct gpio'
+ * @num: how many GPIOs in the array
+ */
+void gpio_free_array(const struct gpio *array, size_t num)
+{
+ while (num--)
+ gpio_free((array++)->gpio);
+}
+EXPORT_SYMBOL_GPL(gpio_free_array);
+
void gpio_set_value(unsigned gpio, int value)
{
struct gpio_info *gi = gpio_to_desc(gpio);