Subject: Assabet touchscreen patch (cont.)

From: Tak-Shing Chan <[email-masked]>
Date: Wed, 28 Jun 2000 13:52:22 +0800 (CST)

Hi Assabeters,

     Patch below fixes the IRQ and fops stuffs.

Tak-Shing Chan

--- /usr/src/linux-2.4.0-test2-ac1-rmk2-np1/drivers/char/sa1100_ts.c.orig	Tue Jun 27 13:52:43 2000
+++ /usr/src/linux-2.4.0-test2-ac1-rmk2-np1/drivers/char/sa1100_ts.c	Wed Jun 28 13:39:56 2000
@@ -6,7 +6,8 @@
 #include <linux/fs.h>
 #include <linux/poll.h>
 #include <asm/uaccess.h>
-#include <asm-arm/arch-sa1100/hardware.h>
+#include <asm/arch/hardware.h>
+#include <asm/arch/irqs.h>
 #include <linux/string.h>
 
 #ifdef DEBUG
@@ -98,18 +99,11 @@
 struct timer_list g_timer;
 
 struct file_operations sa1100_ts_fops = {
-		NULL,				/* LSEEK */
-		sa1100_ts_read,		/* READ  */
-		NULL,				/* WRITE */
-		NULL,				/* READDIR */
-		sa1100_ts_poll,		/* SELECT */
-		sa1100_ts_ioctl,	/* IOCTL */
-		NULL,				/* MMAP */
-		sa1100_ts_open,		/* OPEN */
-		NULL,		
-		sa1100_ts_release,	/* CLOSE */
-		NULL,
-		NULL
+	read:		sa1100_ts_read,
+	poll:		sa1100_ts_poll,
+	ioctl:		sa1100_ts_ioctl,
+	open:		sa1100_ts_open,
+	release:	sa1100_ts_release
 };
 
 //------------------------------------------------------------
@@ -467,16 +461,15 @@
 	  BCR_set(BCR_CODEC_RST);
 
 	  /* Enable the MCP */
-	  Ser4MCCR0 = (1 << UGL_SA1100_MCCR0_MCE);
-	  Ser4MCCR0 |= (1 << UGL_SA1100_MCCR0_ADM);
+	  Ser4MCCR0 = MCCR0_MCE | MCCR0_SmpCnt;
 
 	  /* Enable the sa1100 interrupt on a rising edge */
 	  /* Clear any old interrupts of sa1100 */
 
-	  GPDR |= (1 << 23);
-	  GAFR |= (1 << 23);
-	  GRER |= (1 << 23);
-	  GEDR |= (1 << 23);
+	  GPDR |= GPIO_UCB1300_IRQ;
+	  GAFR |= GPIO_UCB1300_IRQ;
+	  set_GPIO_IRQ_edge(GPIO_UCB1300_IRQ, GPIO_RISING_EDGE);
+	  GEDR |= GPIO_UCB1300_IRQ;
 	} 
 
 	if ( machine_is_graphicsclient()) {
@@ -514,15 +507,19 @@
 	sa1100_ts_regwrite(UGL_UCB1200_IO_CLR_I,0);
 	sa1100_ts_regwrite(UGL_UCB1200_IO_CLR_I,UGL_UCB1200_IO_TS_INT);
 	
-	tmp = GEDR;
-	tmp |= UGL_SA1100_GRER_TS_PINS;
-	GEDR = tmp;
+#if defined(CONFIG_SA1100_GRAPHICSCLIENT)
+	if (machine_is_graphicsclient()) {
+		tmp = GEDR;
+		tmp |= UGL_SA1100_GRER_TS_PINS;
+		GEDR = tmp;
+	}
+#endif
 	
 	register_chrdev(0,"sa1100-ts",&sa1100_ts_fops);
 	irq = -1;
 #if defined(CONFIG_SA1100_ASSABET)
 	if (machine_is_assabet())
-	  irq = CODEC_IRQ_ASSABET;
+	  irq = IRQ_GPIO_UCB1300_IRQ;
 #endif
 #if defined(CONFIG_SA1100_GRAPHICSCLIENT)
 	if (machine_is_graphicsclient())

unsubscribe: body of `unsubscribe linux-arm-kernel' to [email-masked]

---

From: Nicolas Pitre <[email-masked]>
Date: Wed, 28 Jun 2000 21:30:40 -0400 (EDT)

To all SA1100 driver writers out there, please read this, especially for
the end...

>      Patch below fixes the IRQ and fops stuffs.

There are few things here that are wrong regarding GPIO IRQ handling on

> +++ /usr/src/linux-2.4.0-test2-ac1-rmk2-np1/drivers/char/sa1100_ts.c	Wed Jun 28 13:39:56 2000

Here it should be:

#include <asm/hardware.h>
#include <asm/irq.h>

> +	  GEDR |= GPIO_UCB1300_IRQ;

Here the GPIO direction should be set to input i.e.:

	GPDR &= ~GPIO_UCB1300_IRQ;

And the GPIO Alternate Function (GAFR) must not be activated for the GPIO
to act as an interrupt line.

Also, since the new IRQ handling stuff, no driver code should touch to
GEDR/GFER/GRER any longer.  The IRQ handling code is taking care of them.

Here neither the old nor the new version is correct.  All this should
disappear as mentionned above.

In general, GPIO lines used as IRQ lines should be set up like this:

For example, if GPIO 18 should be used as an IRQ line on a falling edge:

	GPDR &= ~GPIO_GPIO18;	/* input direction */
	set_GPIO_IRQ_edge( GPIO_GPIO18, GPIO_FALLING_EDGE );
	request_irq( IRQ_GPIO18, irq_handler, ..... );

That's it!  You even don't have to bother about GPIO >= 11 IRQs
multiplexed on IRQ 11, etc.  Everything is handled by the low-level IRQ
handling code (for the curious, see include/asm/arch-sa1100/irq.h). The
important thing is to *always* call set_GPIO_IRQ_edge() *before*
request_irq().  Then you only need to bother with the real job in your
irq_handler.

Thanks!

Nicolas

---

From: Tak-Shing Chan <[email-masked]>
Date: Fri, 30 Jun 2000 12:20:03 +0800 (CST)

Nicolas,

     Thanks for your correction.  By the way do we really need
tmp &= ~UGL_SA1100_GRER_TS_NOT_PINS?  I suppose it has no effect,
otherwise it leads to a second question: is it legal to use
GPIO_IRQ_{fall,ris}ing_edge directly?

     Updated patch below.

Tak-Shing Chan

--- /usr/src/linux-2.4.0-test2-ac1-rmk2-np1/drivers/char/sa1100_ts.c.orig	Tue Jun 27 13:52:43 2000
+++ /usr/src/linux-2.4.0-test2-ac1-rmk2-np1/drivers/char/sa1100_ts.c	Fri Jun 30 12:06:13 2000
@@ -6,7 +6,8 @@
 #include <linux/fs.h>
 #include <linux/poll.h>
 #include <asm/uaccess.h>
-#include <asm-arm/arch-sa1100/hardware.h>
+#include <asm/hardware.h>
+#include <asm/irq.h>
 #include <linux/string.h>
 
 #ifdef DEBUG
@@ -98,18 +99,11 @@
 
+	release:	sa1100_ts_release,
 };
 
@@ -467,31 +461,19 @@
 	  BCR_set(BCR_CODEC_RST);
 
 	  /* Enable the MCP */

-	  GPDR |= (1 << 23);
-	  GAFR |= (1 << 23);
-	  GRER |= (1 << 23);
-	  GEDR |= (1 << 23);
+	  GPDR &= ~GPIO_UCB1300_IRQ;
+	  set_GPIO_IRQ_edge(GPIO_UCB1300_IRQ, GPIO_RISING_EDGE);
 	} 
 
 	if ( machine_is_graphicsclient()) {
 	  /* Enable the MCP */
-	  Ser4MCCR0 = (1 << UGL_SA1100_MCCR0_MCE);
-	
-	  tmp = GRER;
-	  tmp |= UGL_SA1100_GRER_TS_PINS;
-	  tmp &= ~UGL_SA1100_GRER_TS_NOT_PINS;
-	  GRER = tmp;
-	  
-
-	  tmp = GEDR;
-	  tmp |= UGL_SA1100_GRER_TS_PINS;
-	  GEDR = tmp;
+	  Ser4MCCR0 = MCCR0_MCE;
+	  set_GPIO_IRQ_edge(UGL_SA1100_GRER_TS_PINS, GPIO_RISING_EDGE);
 	}
 
 #ifdef DEBUG
@@ -513,22 +495,17 @@
 	sa1100_ts_regread(UGL_UCB1200_IO_CLR_I);
 	sa1100_ts_regwrite(UGL_UCB1200_IO_CLR_I,0);
 	sa1100_ts_regwrite(UGL_UCB1200_IO_CLR_I,UGL_UCB1200_IO_TS_INT);
-	
-	tmp = GEDR;
-	tmp |= UGL_SA1100_GRER_TS_PINS;
-	GEDR = tmp;
-	
 	register_chrdev(0,"sa1100-ts",&sa1100_ts_fops);
 	irq = -1;
 #if defined(CONFIG_SA1100_ASSABET)
 	if (machine_is_assabet())
-	  irq = CODEC_IRQ_ASSABET;
+	  irq = IRQ_GPIO_UCB1300_IRQ;
 #endif
 #if defined(CONFIG_SA1100_GRAPHICSCLIENT)
 	if (machine_is_graphicsclient())
-	  irq = CODEC_IRQ_GRAPHICSCLIENT;
+	  irq = IRQ_GPIO6;
 #endif
-	if(request_irq(irq, sa1100_ts_inthandler, 0, 
+	if(request_irq(irq, sa1100_ts_inthandler, SA_INTERRUPT, 
 		"sa1100-ts",&g_dev_id) != 0) {
 		printk("sa1100_ts_init: Could not get CODEC IRQ\n");
 	}