[ARM] 3827/1: iop3xx: add common gpio module
authorLennert Buytenhek <buytenh@wantstofly.org>
Mon, 18 Sep 2006 22:23:07 +0000 (23:23 +0100)
committerRussell King <rmk+kernel@arm.linux.org.uk>
Mon, 25 Sep 2006 09:25:47 +0000 (10:25 +0100)
Implement the gpio_line_{config,get,set} API for iop3xx.

Signed-off-by: Lennert Buytenhek <buytenh@wantstofly.org>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
arch/arm/plat-iop/Makefile
arch/arm/plat-iop/gpio.c [new file with mode: 0644]
drivers/i2c/busses/i2c-iop3xx.c
include/asm-arm/arch-iop32x/iop321.h
include/asm-arm/arch-iop33x/iop331.h
include/asm-arm/hardware/iop3xx.h

index d20cdec..23da00b 100644 (file)
@@ -2,7 +2,7 @@
 # Makefile for the linux kernel.
 #
 
-obj-y                  := i2c.o pci.o setup.o time.o
+obj-y                  := gpio.o i2c.o pci.o setup.o time.o
 obj-m                  :=
 obj-n                  :=
 obj-                   :=
diff --git a/arch/arm/plat-iop/gpio.c b/arch/arm/plat-iop/gpio.c
new file mode 100644 (file)
index 0000000..eda4360
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * arch/arm/plat-iop/gpio.c
+ * GPIO handling for Intel IOP3xx processors.
+ *
+ * Copyright (C) 2006 Lennert Buytenhek <buytenh@wantstofly.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ */
+
+#include <linux/device.h>
+#include <asm/hardware/iop3xx.h>
+
+void gpio_line_config(int line, int direction)
+{
+       unsigned long flags;
+
+       local_irq_save(flags);
+       if (direction == GPIO_IN) {
+               *IOP3XX_GPOE |= 1 << line;
+       } else if (direction == GPIO_OUT) {
+               *IOP3XX_GPOE &= ~(1 << line);
+       }
+       local_irq_restore(flags);
+}
+EXPORT_SYMBOL(gpio_line_config);
+
+int gpio_line_get(int line)
+{
+       return !!(*IOP3XX_GPID & (1 << line));
+}
+EXPORT_SYMBOL(gpio_line_get);
+
+void gpio_line_set(int line, int value)
+{
+       unsigned long flags;
+
+       local_irq_save(flags);
+       if (value == GPIO_LOW) {
+               *IOP3XX_GPOD &= ~(1 << line);
+       } else if (value == GPIO_HIGH) {
+               *IOP3XX_GPOD |= 1 << line;
+       }
+       local_irq_restore(flags);
+}
+EXPORT_SYMBOL(gpio_line_set);
index 035417f..a2d0cc3 100644 (file)
@@ -82,14 +82,16 @@ iop3xx_i2c_enable(struct i2c_algo_iop3xx_data *iop3xx_adap)
 
        /* 
         * Every time unit enable is asserted, GPOD needs to be cleared
-        * on IOP32X to avoid data corruption on the bus.
+        * on IOP3XX to avoid data corruption on the bus.
         */
-#ifdef CONFIG_ARCH_IOP32X
-#define IOP321_GPOD_I2C0    0x00c0  /* clear these bits to enable ch0 */
-#define IOP321_GPOD_I2C1    0x0030  /* clear these bits to enable ch1 */
-
-       *IOP321_GPOD &= (iop3xx_adap->id == 0) ? ~IOP321_GPOD_I2C0 : 
-               ~IOP321_GPOD_I2C1;
+#ifdef CONFIG_PLAT_IOP
+       if (iop3xx_adap->id == 0) {
+               gpio_line_set(IOP3XX_GPIO_LINE(7), GPIO_LOW);
+               gpio_line_set(IOP3XX_GPIO_LINE(6), GPIO_LOW);
+       } else {
+               gpio_line_set(IOP3XX_GPIO_LINE(5), GPIO_LOW);
+               gpio_line_set(IOP3XX_GPIO_LINE(4), GPIO_LOW);
+       }
 #endif
        /* NB SR bits not same position as CR IE bits :-( */
        iop3xx_adap->SR_enabled = 
index 34fe07f..1e57e00 100644 (file)
  * Peripherals that are shared between the iop32x and iop33x but
  * located at different addresses.
  */
+#define IOP3XX_GPIO_REG(reg)   (IOP3XX_PERIPHERAL_VIRT_BASE + 0x07c0 + (reg))
 #define IOP3XX_TIMER_REG(reg)  (IOP3XX_PERIPHERAL_VIRT_BASE + 0x07e0 + (reg))
 
 #include <asm/hardware/iop3xx.h>
index 4ebcd71..d12a95a 100644 (file)
  * Peripherals that are shared between the iop32x and iop33x but
  * located at different addresses.
  */
+#define IOP3XX_GPIO_REG(reg)   (IOP3XX_PERIPHERAL_VIRT_BASE + 0x1780 + (reg))
 #define IOP3XX_TIMER_REG(reg)  (IOP3XX_PERIPHERAL_VIRT_BASE + 0x07d0 + (reg))
 
 #include <asm/hardware/iop3xx.h>
index 98b7cbc..f3c61d0 100644 (file)
 #ifndef __IOP3XX_H
 #define __IOP3XX_H
 
+/*
+ * IOP3XX GPIO handling
+ */
+#define GPIO_IN                        0
+#define GPIO_OUT               1
+#define GPIO_LOW               0
+#define GPIO_HIGH              1
+#define IOP3XX_GPIO_LINE(x)    (x)
+
+#ifndef __ASSEMBLY__
+extern void gpio_line_config(int line, int direction);
+extern int  gpio_line_get(int line);
+extern void gpio_line_set(int line, int value);
+#endif
+
+
 /*
  * IOP3XX processor registers
  */
 #define IOP3XX_PCIXSR          (volatile u32 *)IOP3XX_REG_ADDR(0x01e4)
 #define IOP3XX_PCIIRSR         (volatile u32 *)IOP3XX_REG_ADDR(0x01ec)
 
+/* General Purpose I/O  */
+#define IOP3XX_GPOE            (volatile u32 *)IOP3XX_GPIO_REG(0x0004)
+#define IOP3XX_GPID            (volatile u32 *)IOP3XX_GPIO_REG(0x0008)
+#define IOP3XX_GPOD            (volatile u32 *)IOP3XX_GPIO_REG(0x000c)
+
 /* Timers  */
 #define IOP3XX_TU_TMR0         (volatile u32 *)IOP3XX_TIMER_REG(0x0000)
 #define IOP3XX_TU_TMR1         (volatile u32 *)IOP3XX_TIMER_REG(0x0004)