From: Lothar Waßmann Date: Thu, 16 Aug 2012 13:44:46 +0000 (+0200) Subject: Add gpiolib for common gpio functions X-Git-Tag: KARO-TX53-2012-08-17~36 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=1eed620593e952414b70804287065038d78d9641;p=karo-tx-uboot.git Add gpiolib for common gpio functions --- diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index f80f1d52e6..155402cdd8 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile @@ -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 diff --git a/drivers/gpio/am33xx_gpio.c b/drivers/gpio/am33xx_gpio.c index bd6a68da0c..73ead20196 100644 --- a/drivers/gpio/am33xx_gpio.c +++ b/drivers/gpio/am33xx_gpio.c @@ -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 index 0000000000..ef314eefe9 --- /dev/null +++ b/drivers/gpio/gpiolib.c @@ -0,0 +1,55 @@ +#include +#include + +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; +}