]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - drivers/gpio/gpio-uclass.c
update to 2015.04-rc1
[karo-tx-uboot.git] / drivers / gpio / gpio-uclass.c
index a69bbd2002e9f62c06f75cb1f1b4b755140eecc2..8ff82c5e62b5c1e62f03026a9979db5900170199 100644 (file)
@@ -190,6 +190,48 @@ int gpio_requestf(unsigned gpio, const char *fmt, ...)
        return gpio_request(gpio, buf);
 }
 
+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 == GPIOFLAG_INPUT)
+               gpio_direction_input(gpio);
+       else if (flags == GPIOFLAG_OUTPUT_INIT_LOW)
+               gpio_direction_output(gpio, 0);
+       else if (flags == GPIOFLAG_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 _dm_gpio_free(struct udevice *dev, uint offset)
 {
        struct gpio_dev_priv *uc_priv;
@@ -210,6 +252,17 @@ int _dm_gpio_free(struct udevice *dev, uint offset)
        return 0;
 }
 
+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;
+}
+
 /**
  * gpio_free() - [COMPAT] Relinquish GPIO
  * gpio:       GPIO number