]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - drivers/gpio/gpiolib.c
karo: merge with Ka-Ro specific tree for secure boot support
[karo-tx-uboot.git] / drivers / gpio / gpiolib.c
1 #include <common.h>
2 #include <asm-generic/gpio.h>
3
4 int gpio_request_one(unsigned int gpio, enum gpio_flags flags,
5                 const char *label)
6 {
7         int ret;
8
9         ret = gpio_request(gpio, label);
10         if (ret)
11                 return ret;
12
13         if (flags == GPIOFLAG_INPUT)
14                 gpio_direction_input(gpio);
15         else if (flags == GPIOFLAG_OUTPUT_INIT_LOW)
16                 gpio_direction_output(gpio, 0);
17         else if (flags == GPIOFLAG_OUTPUT_INIT_HIGH)
18                 gpio_direction_output(gpio, 1);
19
20         return ret;
21 }
22
23 int gpio_request_array(const struct gpio *gpios, int count)
24 {
25         int ret;
26         int i;
27
28         for (i = 0; i < count; i++) {
29                 ret = gpio_request_one(gpios[i].gpio, gpios[i].flags,
30                                 gpios[i].label);
31                 if (ret) {
32                         printf("Failed to request GPIO%d (%u of %u): %d\n",
33                                 gpios[i].gpio, i, count, ret);
34                         goto error;
35                 }
36         }
37         return 0;
38
39 error:
40         while (--i >= 0)
41                 gpio_free(gpios[i].gpio);
42
43         return ret;
44 }
45
46 int gpio_free_array(const struct gpio *gpios, int count)
47 {
48         int ret = 0;
49         int i;
50
51         for (i = 0; i < count; i++)
52                 ret |= gpio_free(gpios[i].gpio);
53
54         return ret;
55 }