ARM: iPAQ: provide a way to setup platform-controlled GPIOs
authorRussell King <rmk+kernel@arm.linux.org.uk>
Tue, 6 Oct 2009 13:35:16 +0000 (14:35 +0100)
committerRussell King <rmk+kernel@arm.linux.org.uk>
Sun, 6 Dec 2009 16:52:24 +0000 (16:52 +0000)
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
arch/arm/mach-sa1100/h3600.c

index c51432bad46dd3aaf07b0ca08ce0ef7534ca3dc5..2b545a4baa0888548e511b017f3ed2d412172d80 100644 (file)
@@ -28,6 +28,7 @@
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/partitions.h>
 #include <linux/serial_core.h>
+#include <linux/gpio.h>
 
 #include <asm/irq.h>
 #include <mach/hardware.h>
 void (*assign_h3600_egpio)(enum ipaq_egpio_type x, int level);
 EXPORT_SYMBOL(assign_h3600_egpio);
 
+struct gpio_default_state {
+       int gpio;
+       int mode;
+       const char *name;
+};
+
+#define GPIO_MODE_IN   -1
+#define GPIO_MODE_OUT0 0
+#define GPIO_MODE_OUT1 1
+
+static void h3xxx_init_gpio(struct gpio_default_state *s, size_t n)
+{
+       while (n--) {
+               const char *name = s->name;
+               int err;
+
+               if (!name)
+                       name = "[init]";
+               err = gpio_request(s->gpio, name);
+               if (err) {
+                       printk(KERN_ERR "gpio%u: unable to request: %d\n",
+                               s->gpio, err);
+                       continue;
+               }
+               if (s->mode >= 0) {
+                       err = gpio_direction_output(s->gpio, s->mode);
+               } else {
+                       err = gpio_direction_input(s->gpio);
+               }
+               if (err) {
+                       printk(KERN_ERR "gpio%u: unable to set direction: %d\n",
+                               s->gpio, err);
+                       continue;
+               }
+               if (!s->name)
+                       gpio_free(s->gpio);
+               s++;
+       }
+}
+
+
 static struct mtd_partition h3xxx_partitions[] = {
        {
                .name           = "H3XXX boot firmware",