]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
Add gpiolib for common gpio functions
authorLothar Waßmann <LW@KARO-electronics.de>
Thu, 16 Aug 2012 13:44:46 +0000 (15:44 +0200)
committerLothar Waßmann <LW@KARO-electronics.de>
Thu, 16 Aug 2012 13:44:46 +0000 (15:44 +0200)
drivers/gpio/Makefile
drivers/gpio/am33xx_gpio.c
drivers/gpio/gpiolib.c [new file with mode: 0644]

index f80f1d52e6f29054e06462f154eec3a48a2ef6b2..155402cdd8b07133158a4ed75990fe8575c43020 100644 (file)
@@ -25,6 +25,8 @@ include $(TOPDIR)/config.mk
 
 LIB    := $(obj)libgpio.o
 
+COBJS-y                                += gpiolib.o
+
 COBJS-$(CONFIG_AM33XX_GPIO)    += am33xx_gpio.o
 COBJS-$(CONFIG_AT91_GPIO)      += at91_gpio.o
 COBJS-$(CONFIG_KIRKWOOD_GPIO)  += kw_gpio.o
index bd6a68da0cf3e8d3d21989c618fa730c913a8bad..73ead2019619b82eb1768ae9cd80bc34f804cc37 100644 (file)
@@ -106,53 +106,3 @@ int gpio_direction_output(unsigned gpio, int val)
        writel(oe & ~mask, &gpio_base[bank]->oe);
        return 0;
 }
-
-int gpio_request_one(unsigned int gpio, enum gpio_flags flags,
-               const char *label)
-{
-       int ret;
-
-       ret = gpio_request(gpio, label);
-       if (ret)
-               return ret;
-
-       if (flags == GPIOF_INPUT)
-               gpio_direction_input(gpio);
-       else if (flags == GPIOF_OUTPUT_INIT_LOW)
-               gpio_direction_output(gpio, 0);
-       else if (flags == GPIOF_OUTPUT_INIT_HIGH)
-               gpio_direction_output(gpio, 1);
-
-       return ret;
-}
-
-int gpio_request_array(const struct gpio *gpios, int count)
-{
-       int ret;
-       int i;
-
-       for (i = 0; i < count; i++) {
-               ret = gpio_request_one(gpios[i].gpio, gpios[i].flags,
-                               gpios[i].label);
-               if (ret)
-                       goto error;
-       }
-       return 0;
-
-error:
-       while (--i >= 0)
-               gpio_free(gpios[i].gpio);
-
-       return ret;
-}
-
-int gpio_free_array(const struct gpio *gpios, int count)
-{
-       int ret = 0;
-       int i;
-
-       for (i = 0; i < count; i++)
-               ret |= gpio_free(gpios[i].gpio);
-
-       return ret;
-}
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
new file mode 100644 (file)
index 0000000..ef314ee
--- /dev/null
@@ -0,0 +1,55 @@
+#include <common.h>
+#include <asm-generic/gpio.h>
+
+int gpio_request_one(unsigned int gpio, enum gpio_flags flags,
+               const char *label)
+{
+       int ret;
+
+       ret = gpio_request(gpio, label);
+       if (ret)
+               return ret;
+
+       if (flags == GPIOF_INPUT)
+               gpio_direction_input(gpio);
+       else if (flags == GPIOF_OUTPUT_INIT_LOW)
+               gpio_direction_output(gpio, 0);
+       else if (flags == GPIOF_OUTPUT_INIT_HIGH)
+               gpio_direction_output(gpio, 1);
+
+       return ret;
+}
+
+int gpio_request_array(const struct gpio *gpios, int count)
+{
+       int ret;
+       int i;
+
+       for (i = 0; i < count; i++) {
+               ret = gpio_request_one(gpios[i].gpio, gpios[i].flags,
+                               gpios[i].label);
+               if (ret) {
+                       printf("Failed to request GPIO%d (%u of %u): %d\n",
+                               gpios[i].gpio, i, count, ret);
+                       goto error;
+               }
+       }
+       return 0;
+
+error:
+       while (--i >= 0)
+               gpio_free(gpios[i].gpio);
+
+       return ret;
+}
+
+int gpio_free_array(const struct gpio *gpios, int count)
+{
+       int ret = 0;
+       int i;
+
+       for (i = 0; i < count; i++)
+               ret |= gpio_free(gpios[i].gpio);
+
+       return ret;
+}