]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
[MIPS] generic txx9 gpio support
authorAtsushi Nemoto <anemo@mba.ocn.ne.jp>
Fri, 4 Apr 2008 15:55:41 +0000 (00:55 +0900)
committerRalf Baechle <ralf@linux-mips.org>
Mon, 28 Apr 2008 16:14:31 +0000 (17:14 +0100)
This is a board-independent TXx9 gpio API implementation using gpiolib.

Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
arch/mips/Kconfig
arch/mips/kernel/Makefile
arch/mips/kernel/gpio_txx9.c [new file with mode: 0644]
include/asm-mips/txx9pio.h [new file with mode: 0644]

index 9e1fc966895cef9775b4ccf00d25be02c80a3838..f4c313f9036b462189060d657113d1ebd8d9dd8e 100644 (file)
@@ -789,6 +789,11 @@ config CSRC_R4K
 config CSRC_SB1250
        bool
 
+config GPIO_TXX9
+       select GENERIC_GPIO
+       select HAVE_GPIO_LIB
+       bool
+
 config CFE
        bool
 
index d0ca4d41bb742cba68f104b6a91c8cddb4b8fab7..87067e8fee9eac093c8a922fc530913eebe541b9 100644 (file)
@@ -81,6 +81,8 @@ obj-$(CONFIG_64BIT)           += cpu-bugs64.o
 
 obj-$(CONFIG_I8253)            += i8253.o
 
+obj-$(CONFIG_GPIO_TXX9)                += gpio_txx9.o
+
 obj-$(CONFIG_KEXEC)            += machine_kexec.o relocate_kernel.o
 obj-$(CONFIG_EARLY_PRINTK)     += early_printk.o
 
diff --git a/arch/mips/kernel/gpio_txx9.c b/arch/mips/kernel/gpio_txx9.c
new file mode 100644 (file)
index 0000000..b1436a8
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * A gpio chip driver for TXx9 SoCs
+ *
+ * Copyright (C) 2008 Atsushi Nemoto <anemo@mba.ocn.ne.jp>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/init.h>
+#include <linux/spinlock.h>
+#include <linux/gpio.h>
+#include <linux/errno.h>
+#include <linux/io.h>
+#include <asm/txx9pio.h>
+
+static DEFINE_SPINLOCK(txx9_gpio_lock);
+
+static struct txx9_pio_reg __iomem *txx9_pioptr;
+
+static int txx9_gpio_get(struct gpio_chip *chip, unsigned int offset)
+{
+       return __raw_readl(&txx9_pioptr->din) & (1 << offset);
+}
+
+static void txx9_gpio_set_raw(unsigned int offset, int value)
+{
+       u32 val;
+       val = __raw_readl(&txx9_pioptr->dout);
+       if (value)
+               val |= 1 << offset;
+       else
+               val &= ~(1 << offset);
+       __raw_writel(val, &txx9_pioptr->dout);
+}
+
+static void txx9_gpio_set(struct gpio_chip *chip, unsigned int offset,
+                         int value)
+{
+       unsigned long flags;
+       spin_lock_irqsave(&txx9_gpio_lock, flags);
+       txx9_gpio_set_raw(offset, value);
+       mmiowb();
+       spin_unlock_irqrestore(&txx9_gpio_lock, flags);
+}
+
+static int txx9_gpio_dir_in(struct gpio_chip *chip, unsigned int offset)
+{
+       spin_lock_irq(&txx9_gpio_lock);
+       __raw_writel(__raw_readl(&txx9_pioptr->dir) & ~(1 << offset),
+                    &txx9_pioptr->dir);
+       mmiowb();
+       spin_unlock_irq(&txx9_gpio_lock);
+       return 0;
+}
+
+static int txx9_gpio_dir_out(struct gpio_chip *chip, unsigned int offset,
+                            int value)
+{
+       spin_lock_irq(&txx9_gpio_lock);
+       txx9_gpio_set_raw(offset, value);
+       __raw_writel(__raw_readl(&txx9_pioptr->dir) | (1 << offset),
+                    &txx9_pioptr->dir);
+       mmiowb();
+       spin_unlock_irq(&txx9_gpio_lock);
+       return 0;
+}
+
+static struct gpio_chip txx9_gpio_chip = {
+       .get = txx9_gpio_get,
+       .set = txx9_gpio_set,
+       .direction_input = txx9_gpio_dir_in,
+       .direction_output = txx9_gpio_dir_out,
+       .label = "TXx9",
+};
+
+int __init txx9_gpio_init(unsigned long baseaddr,
+                         unsigned int base, unsigned int num)
+{
+       txx9_pioptr = ioremap(baseaddr, sizeof(struct txx9_pio_reg));
+       if (!txx9_pioptr)
+               return -ENODEV;
+       txx9_gpio_chip.base = base;
+       txx9_gpio_chip.ngpio = num;
+       return gpiochip_add(&txx9_gpio_chip);
+}
diff --git a/include/asm-mips/txx9pio.h b/include/asm-mips/txx9pio.h
new file mode 100644 (file)
index 0000000..3d6fa9f
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * include/asm-mips/txx9pio.h
+ * TX39/TX49 PIO controller definitions.
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
+#ifndef __ASM_TXX9PIO_H
+#define __ASM_TXX9PIO_H
+
+#include <linux/types.h>
+
+struct txx9_pio_reg {
+       __u32 dout;
+       __u32 din;
+       __u32 dir;
+       __u32 od;
+       __u32 flag[2];
+       __u32 pol;
+       __u32 intc;
+       __u32 maskcpu;
+       __u32 maskext;
+};
+
+int txx9_gpio_init(unsigned long baseaddr,
+                  unsigned int base, unsigned int num);
+
+#endif /* __ASM_TXX9PIO_H */