Linux MIPS Architecture development
 help / color / mirror / Atom feed
* [PATCH 1/4] rbtx4938: Add generic GPIO support
@ 2007-06-22 14:21 Atsushi Nemoto
  2007-06-24 20:54 ` Ralf Baechle
  0 siblings, 1 reply; 6+ messages in thread
From: Atsushi Nemoto @ 2007-06-22 14:21 UTC (permalink / raw)
  To: linux-mips; +Cc: ralf

GPIO 0..15 are for TX4938 PIO pins, GPIO 16..18 are for FPGA-driven
chipselect signals for SPI devices.

Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
---
This patch depends on:
[PATCH] Add MIPS generic GPIO support (by Yoichi Yuasa, already queued)
[PATCH] Create fallback gpio.h

 arch/mips/Kconfig                         |    1 +
 arch/mips/configs/rbhma4500_defconfig     |    1 +
 arch/mips/tx4938/toshiba_rbtx4938/setup.c |  100 +++++++++++++++++++++++++++++
 3 files changed, 102 insertions(+), 0 deletions(-)

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 24661d6..823a628 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -660,6 +660,7 @@ config TOSHIBA_RBTX4938
 	select SYS_SUPPORTS_BIG_ENDIAN
 	select SYS_SUPPORTS_KGDB
 	select GENERIC_HARDIRQS_NO__DO_IRQ
+	select GENERIC_GPIO
 	help
 	  This Toshiba board is based on the TX4938 processor. Say Y here to
 	  support this machine type
diff --git a/arch/mips/configs/rbhma4500_defconfig b/arch/mips/configs/rbhma4500_defconfig
index b0abd16..6e10c15 100644
--- a/arch/mips/configs/rbhma4500_defconfig
+++ b/arch/mips/configs/rbhma4500_defconfig
@@ -80,6 +80,7 @@ CONFIG_DMA_NONCOHERENT=y
 CONFIG_DMA_NEED_PCI_MAP_STATE=y
 CONFIG_GENERIC_ISA_DMA=y
 CONFIG_I8259=y
+CONFIG_GENERIC_GPIO=y
 # CONFIG_CPU_BIG_ENDIAN is not set
 CONFIG_CPU_LITTLE_ENDIAN=y
 CONFIG_SYS_SUPPORTS_BIG_ENDIAN=y
diff --git a/arch/mips/tx4938/toshiba_rbtx4938/setup.c b/arch/mips/tx4938/toshiba_rbtx4938/setup.c
index f5d1ce7..9f83844 100644
--- a/arch/mips/tx4938/toshiba_rbtx4938/setup.c
+++ b/arch/mips/tx4938/toshiba_rbtx4938/setup.c
@@ -29,6 +29,7 @@
 #include <asm/uaccess.h>
 #include <asm/io.h>
 #include <asm/bootinfo.h>
+#include <asm/gpio.h>
 #include <asm/tx4938/rbtx4938.h>
 #ifdef CONFIG_SERIAL_TXX9
 #include <linux/tty.h>
@@ -1057,3 +1058,102 @@ static int __init rbtx4938_ne_init(void)
 	return IS_ERR(dev) ? PTR_ERR(dev) : 0;
 }
 device_initcall(rbtx4938_ne_init);
+
+/* GPIO support */
+
+static DEFINE_SPINLOCK(rbtx4938_spi_gpio_lock);
+
+static void rbtx4938_spi_gpio_set(unsigned gpio, int value)
+{
+	u8 val;
+	unsigned long flags;
+	gpio -= 16;
+	spin_lock_irqsave(&rbtx4938_spi_gpio_lock, flags);
+	val = *rbtx4938_spics_ptr;
+	if (value)
+		val |= 1 << gpio;
+	else
+		val &= ~(1 << gpio);
+	*rbtx4938_spics_ptr = val;
+	spin_unlock_irqrestore(&rbtx4938_spi_gpio_lock, flags);
+}
+
+static int rbtx4938_spi_gpio_dir_out(unsigned gpio, int value)
+{
+	rbtx4938_spi_gpio_set(gpio, value);
+	return 0;
+}
+
+static DEFINE_SPINLOCK(tx4938_gpio_lock);
+
+static int tx4938_gpio_get(unsigned gpio)
+{
+	return tx4938_pioptr->din & (1 << gpio);
+}
+
+static void tx4938_gpio_set_raw(unsigned gpio, int value)
+{
+	u32 val;
+	val = tx4938_pioptr->dout;
+	if (value)
+		val |= 1 << gpio;
+	else
+		val &= ~(1 << gpio);
+	tx4938_pioptr->dout = val;
+}
+
+static void tx4938_gpio_set(unsigned gpio, int value)
+{
+	unsigned long flags;
+	spin_lock_irqsave(&tx4938_gpio_lock, flags);
+	tx4938_gpio_set_raw(gpio, value);
+	spin_unlock_irqrestore(&tx4938_gpio_lock, flags);
+}
+
+static int tx4938_gpio_dir_in(unsigned gpio)
+{
+	spin_lock_irq(&tx4938_gpio_lock);
+	tx4938_pioptr->dir &= ~(1 << gpio);
+	spin_unlock_irq(&tx4938_gpio_lock);
+	return 0;
+}
+
+static int tx4938_gpio_dir_out(unsigned int gpio, int value)
+{
+	spin_lock_irq(&tx4938_gpio_lock);
+	tx4938_gpio_set_raw(gpio, value);
+	tx4938_pioptr->dir |= 1 << gpio;
+	spin_unlock_irq(&tx4938_gpio_lock);
+	return 0;
+}
+
+int gpio_direction_input(unsigned gpio)
+{
+	if (gpio < 16)
+		return tx4938_gpio_dir_in(gpio);
+	return -EINVAL;
+}
+
+int gpio_direction_output(unsigned gpio, int value)
+{
+	if (gpio < 16)
+		return tx4938_gpio_dir_out(gpio, value);
+	if (gpio < 16 + 3)
+		return rbtx4938_spi_gpio_dir_out(gpio, value);
+	return -EINVAL;
+}
+
+int gpio_get_value(unsigned gpio)
+{
+	if (gpio < 16)
+		return tx4938_gpio_get(gpio);
+	return 0;
+}
+
+void gpio_set_value(unsigned gpio, int value)
+{
+	if (gpio < 16)
+		tx4938_gpio_set(gpio, value);
+	else
+		rbtx4938_spi_gpio_set(gpio, value);
+}

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/4] rbtx4938: Add generic GPIO support
  2007-06-22 14:21 [PATCH 1/4] rbtx4938: Add generic GPIO support Atsushi Nemoto
@ 2007-06-24 20:54 ` Ralf Baechle
  2007-06-25 14:36   ` Atsushi Nemoto
  0 siblings, 1 reply; 6+ messages in thread
From: Ralf Baechle @ 2007-06-24 20:54 UTC (permalink / raw)
  To: Atsushi Nemoto; +Cc: linux-mips

On Fri, Jun 22, 2007 at 11:21:55PM +0900, Atsushi Nemoto wrote:

> GPIO 0..15 are for TX4938 PIO pins, GPIO 16..18 are for FPGA-driven
> chipselect signals for SPI devices.

Queued also.

 Ralf

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/4] rbtx4938: Add generic GPIO support
  2007-06-24 20:54 ` Ralf Baechle
@ 2007-06-25 14:36   ` Atsushi Nemoto
  2007-06-26 23:56     ` Ralf Baechle
  0 siblings, 1 reply; 6+ messages in thread
From: Atsushi Nemoto @ 2007-06-25 14:36 UTC (permalink / raw)
  To: ralf; +Cc: linux-mips

On Sun, 24 Jun 2007 22:54:29 +0200, Ralf Baechle <ralf@linux-mips.org> wrote:
> > GPIO 0..15 are for TX4938 PIO pins, GPIO 16..18 are for FPGA-driven
> > chipselect signals for SPI devices.
> 
> Queued also.

Thanks.  And please queue this too.


Subject: [PATCH] rbtx4938: Add mmio barriers for GPIO.

Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
---
 arch/mips/tx4938/toshiba_rbtx4938/setup.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/arch/mips/tx4938/toshiba_rbtx4938/setup.c b/arch/mips/tx4938/toshiba_rbtx4938/setup.c
index a835870..330ee43 100644
--- a/arch/mips/tx4938/toshiba_rbtx4938/setup.c
+++ b/arch/mips/tx4938/toshiba_rbtx4938/setup.c
@@ -1021,6 +1021,7 @@ static void rbtx4938_spi_gpio_set(unsigned gpio, int value)
 	else
 		val &= ~(1 << gpio);
 	*rbtx4938_spics_ptr = val;
+	mmiowb();
 	spin_unlock_irqrestore(&rbtx4938_spi_gpio_lock, flags);
 }
 
@@ -1053,6 +1054,7 @@ static void tx4938_gpio_set(unsigned gpio, int value)
 	unsigned long flags;
 	spin_lock_irqsave(&tx4938_gpio_lock, flags);
 	tx4938_gpio_set_raw(gpio, value);
+	mmiowb();
 	spin_unlock_irqrestore(&tx4938_gpio_lock, flags);
 }
 
@@ -1060,6 +1062,7 @@ static int tx4938_gpio_dir_in(unsigned gpio)
 {
 	spin_lock_irq(&tx4938_gpio_lock);
 	tx4938_pioptr->dir &= ~(1 << gpio);
+	mmiowb();
 	spin_unlock_irq(&tx4938_gpio_lock);
 	return 0;
 }
@@ -1069,6 +1072,7 @@ static int tx4938_gpio_dir_out(unsigned int gpio, int value)
 	spin_lock_irq(&tx4938_gpio_lock);
 	tx4938_gpio_set_raw(gpio, value);
 	tx4938_pioptr->dir |= 1 << gpio;
+	mmiowb();
 	spin_unlock_irq(&tx4938_gpio_lock);
 	return 0;
 }

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/4] rbtx4938: Add generic GPIO support
  2007-06-25 14:36   ` Atsushi Nemoto
@ 2007-06-26 23:56     ` Ralf Baechle
  2007-06-27  2:13       ` Atsushi Nemoto
  0 siblings, 1 reply; 6+ messages in thread
From: Ralf Baechle @ 2007-06-26 23:56 UTC (permalink / raw)
  To: Atsushi Nemoto; +Cc: linux-mips

On Mon, Jun 25, 2007 at 11:36:37PM +0900, Atsushi Nemoto wrote:

> Thanks.  And please queue this too.

I've folded this one into the "rbtx4938: Add generic GPIO support" patch.

  Ralf

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/4] rbtx4938: Add generic GPIO support
  2007-06-26 23:56     ` Ralf Baechle
@ 2007-06-27  2:13       ` Atsushi Nemoto
  2007-06-27 11:05         ` Ralf Baechle
  0 siblings, 1 reply; 6+ messages in thread
From: Atsushi Nemoto @ 2007-06-27  2:13 UTC (permalink / raw)
  To: ralf; +Cc: linux-mips

On Wed, 27 Jun 2007 01:56:32 +0200, Ralf Baechle <ralf@linux-mips.org> wrote:
> > Thanks.  And please queue this too.
> 
> I've folded this one into the "rbtx4938: Add generic GPIO support" patch.

Thanks, that's better.

In general, which do you prefer on updating a patch in linux-queue
tree, incremental patch or replacement patch?

---
Atsushi Nemoto

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/4] rbtx4938: Add generic GPIO support
  2007-06-27  2:13       ` Atsushi Nemoto
@ 2007-06-27 11:05         ` Ralf Baechle
  0 siblings, 0 replies; 6+ messages in thread
From: Ralf Baechle @ 2007-06-27 11:05 UTC (permalink / raw)
  To: Atsushi Nemoto; +Cc: linux-mips

On Wed, Jun 27, 2007 at 11:13:19AM +0900, Atsushi Nemoto wrote:

> In general, which do you prefer on updating a patch in linux-queue
> tree, incremental patch or replacement patch?

Whatever you prefer.

  Ralf

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2007-06-27 11:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-22 14:21 [PATCH 1/4] rbtx4938: Add generic GPIO support Atsushi Nemoto
2007-06-24 20:54 ` Ralf Baechle
2007-06-25 14:36   ` Atsushi Nemoto
2007-06-26 23:56     ` Ralf Baechle
2007-06-27  2:13       ` Atsushi Nemoto
2007-06-27 11:05         ` Ralf Baechle

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox