]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - arch/arm/mach-ks8695/gpio.c
[ARM] 5296/1: [KS8695] Replace macro's with trailing underscores.
[linux-2.6-omap-h63xx.git] / arch / arm / mach-ks8695 / gpio.c
index b1aa3cb3d4a3a782132fde8dd0655d94e16dc5c5..55cee776ff55151b657d8a827755a45f7714c5a3 100644 (file)
 #include <linux/kernel.h>
 #include <linux/mm.h>
 #include <linux/init.h>
+#include <linux/debugfs.h>
+#include <linux/seq_file.h>
 #include <linux/module.h>
 
 #include <asm/io.h>
-#include <asm/hardware.h>
+#include <mach/hardware.h>
 #include <asm/mach/irq.h>
 
-#include <asm/arch/regs-gpio.h>
-#include <asm/arch/gpio.h>
+#include <mach/regs-gpio.h>
+#include <mach/gpio.h>
 
 /*
  * Configure a GPIO line for either GPIO function, or its internal
@@ -70,7 +72,7 @@ int __init_or_module ks8695_gpio_interrupt(unsigned int pin, unsigned int type)
 
        /* set pin as input */
        x = __raw_readl(KS8695_GPIO_VA + KS8695_IOPM);
-       x &= ~IOPM_(pin);
+       x &= ~IOPM(pin);
        __raw_writel(x, KS8695_GPIO_VA + KS8695_IOPM);
 
        local_irq_restore(flags);
@@ -106,7 +108,7 @@ int __init_or_module gpio_direction_input(unsigned int pin)
 
        /* set pin as input */
        x = __raw_readl(KS8695_GPIO_VA + KS8695_IOPM);
-       x &= ~IOPM_(pin);
+       x &= ~IOPM(pin);
        __raw_writel(x, KS8695_GPIO_VA + KS8695_IOPM);
 
        local_irq_restore(flags);
@@ -134,14 +136,14 @@ int __init_or_module gpio_direction_output(unsigned int pin, unsigned int state)
        /* set line state */
        x = __raw_readl(KS8695_GPIO_VA + KS8695_IOPD);
        if (state)
-               x |= (1 << pin);
+               x |= IOPD(pin);
        else
-               x &= ~(1 << pin);
+               x &= ~IOPD(pin);
        __raw_writel(x, KS8695_GPIO_VA + KS8695_IOPD);
 
        /* set pin as output */
        x = __raw_readl(KS8695_GPIO_VA + KS8695_IOPM);
-       x |= IOPM_(pin);
+       x |= IOPM(pin);
        __raw_writel(x, KS8695_GPIO_VA + KS8695_IOPM);
 
        local_irq_restore(flags);
@@ -166,9 +168,9 @@ void gpio_set_value(unsigned int pin, unsigned int state)
        /* set output line state */
        x = __raw_readl(KS8695_GPIO_VA + KS8695_IOPD);
        if (state)
-               x |= (1 << pin);
+               x |= IOPD(pin);
        else
-               x &= ~(1 << pin);
+               x &= ~IOPD(pin);
        __raw_writel(x, KS8695_GPIO_VA + KS8695_IOPD);
 
        local_irq_restore(flags);
@@ -187,7 +189,7 @@ int gpio_get_value(unsigned int pin)
                return -EINVAL;
 
        x = __raw_readl(KS8695_GPIO_VA + KS8695_IOPD);
-       return (x & (1 << pin)) != 0;
+       return (x & IOPD(pin)) != 0;
 }
 EXPORT_SYMBOL(gpio_get_value);
 
@@ -216,3 +218,84 @@ int irq_to_gpio(unsigned int irq)
        return (irq - KS8695_IRQ_EXTERN0);
 }
 EXPORT_SYMBOL(irq_to_gpio);
+
+
+/* .... Debug interface ..................................................... */
+
+#ifdef CONFIG_DEBUG_FS
+
+static int ks8695_gpio_show(struct seq_file *s, void *unused)
+{
+       unsigned int enable[] = { IOPC_IOEINT0EN, IOPC_IOEINT1EN, IOPC_IOEINT2EN, IOPC_IOEINT3EN, IOPC_IOTIM0EN, IOPC_IOTIM1EN };
+       unsigned int intmask[] = { IOPC_IOEINT0TM, IOPC_IOEINT1TM, IOPC_IOEINT2TM, IOPC_IOEINT3TM };
+       unsigned long mode, ctrl, data;
+       int i;
+
+       mode = __raw_readl(KS8695_GPIO_VA + KS8695_IOPM);
+       ctrl = __raw_readl(KS8695_GPIO_VA + KS8695_IOPC);
+       data = __raw_readl(KS8695_GPIO_VA + KS8695_IOPD);
+
+       seq_printf(s, "Pin\tI/O\tFunction\tState\n\n");
+
+       for (i = KS8695_GPIO_0; i <= KS8695_GPIO_15 ; i++) {
+               seq_printf(s, "%i:\t", i);
+
+               seq_printf(s, "%s\t", (mode & IOPM(i)) ? "Output" : "Input");
+
+               if (i <= KS8695_GPIO_3) {
+                       if (ctrl & enable[i]) {
+                               seq_printf(s, "EXT%i ", i);
+
+                               switch ((ctrl & intmask[i]) >> (4 * i)) {
+                                       case IOPC_TM_LOW:
+                                               seq_printf(s, "(Low)");         break;
+                                       case IOPC_TM_HIGH:
+                                               seq_printf(s, "(High)");        break;
+                                       case IOPC_TM_RISING:
+                                               seq_printf(s, "(Rising)");      break;
+                                       case IOPC_TM_FALLING:
+                                               seq_printf(s, "(Falling)");     break;
+                                       case IOPC_TM_EDGE:
+                                               seq_printf(s, "(Edges)");       break;
+                               }
+                       }
+                       else
+                               seq_printf(s, "GPIO\t");
+               }
+               else if (i <= KS8695_GPIO_5) {
+                       if (ctrl & enable[i])
+                               seq_printf(s, "TOUT%i\t", i - KS8695_GPIO_4);
+                       else
+                               seq_printf(s, "GPIO\t");
+               }
+               else
+                       seq_printf(s, "GPIO\t");
+
+               seq_printf(s, "\t");
+
+               seq_printf(s, "%i\n", (data & IOPD(i)) ? 1 : 0);
+       }
+       return 0;
+}
+
+static int ks8695_gpio_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, ks8695_gpio_show, NULL);
+}
+
+static const struct file_operations ks8695_gpio_operations = {
+       .open           = ks8695_gpio_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+};
+
+static int __init ks8695_gpio_debugfs_init(void)
+{
+       /* /sys/kernel/debug/ks8695_gpio */
+       (void) debugfs_create_file("ks8695_gpio", S_IFREG | S_IRUGO, NULL, NULL, &ks8695_gpio_operations);
+       return 0;
+}
+postcore_initcall(ks8695_gpio_debugfs_init);
+
+#endif