1 Index: linux-2.6.30.9/drivers/input/touchscreen/Kconfig
2 ===================================================================
3 --- linux-2.6.30.9.orig/drivers/input/touchscreen/Kconfig 2009-11-24 21:00:18.000000000 +0100
4 +++ linux-2.6.30.9/drivers/input/touchscreen/Kconfig 2009-11-24 21:00:45.000000000 +0100
6 module will be called wacom_w8001.
9 +config TOUCHSCREEN_EP93XX
10 + tristate "EP93xx Touchscreen"
11 + depends on ARM && INPUT && ARCH_EP93XX
13 config TOUCHSCREEN_MTOUCH
14 tristate "MicroTouch serial touchscreens"
16 Index: linux-2.6.30.9/drivers/input/touchscreen/Makefile
17 ===================================================================
18 --- linux-2.6.30.9.orig/drivers/input/touchscreen/Makefile 2009-11-24 21:00:18.000000000 +0100
19 +++ linux-2.6.30.9/drivers/input/touchscreen/Makefile 2009-11-24 21:00:45.000000000 +0100
21 obj-$(CONFIG_TOUCHSCREEN_CORGI) += corgi_ts.o
22 obj-$(CONFIG_TOUCHSCREEN_GUNZE) += gunze.o
23 obj-$(CONFIG_TOUCHSCREEN_ELO) += elo.o
24 +obj-$(CONFIG_TOUCHSCREEN_EP93XX) += ep93xx_ts.o
25 obj-$(CONFIG_TOUCHSCREEN_FUJITSU) += fujitsu_ts.o
26 obj-$(CONFIG_TOUCHSCREEN_INEXIO) += inexio.o
27 obj-$(CONFIG_TOUCHSCREEN_MIGOR) += migor_ts.o
28 Index: linux-2.6.30.9/drivers/input/touchscreen/ep93xx_ts.c
29 ===================================================================
30 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
31 +++ linux-2.6.30.9/drivers/input/touchscreen/ep93xx_ts.c 2009-11-24 21:09:48.000000000 +0100
34 + * linux/drivers/input/touchscreen/ep93xx_ts.c
36 + * Copyright (C) 2003-2004 Cirrus Corp.
38 + * This program is free software; you can redistribute it and/or modify
39 + * it under the terms of the GNU General Public License version 2 as
40 + * published by the Free Software Foundation.
43 +#include <linux/module.h>
44 +#include <linux/types.h>
45 +#include <linux/delay.h>
46 +#include <linux/wait.h>
47 +#include <linux/fs.h>
48 +#include <linux/sched.h>
49 +#include <linux/poll.h>
50 +#include <linux/miscdevice.h>
51 +#include <linux/init.h>
52 +#include <linux/compiler.h>
53 +#include <linux/timer.h>
54 +#include <linux/interrupt.h>
55 +#include <linux/syscalls.h>
56 +#include <linux/input.h>
58 +#include <mach/hardware.h>
61 +#define TOUCH_OFFSET 0x100000
62 +#define TOUCH_BASE (EP93XX_APB_VIRT_BASE|TOUCH_OFFSET)
63 +#define TSSetup (TOUCH_BASE+0x00) /* R/W touchscreen controller setup control register. */
64 +#define TSXYMaxMin (TOUCH_BASE+0x04) /* R/W touchscreen controller max/min register. */
65 +#define TSXYResult (TOUCH_BASE+0x08) /* R touchscreen controller result register. */
66 +#define TSDischarge (TOUCH_BASE+0x0C) /* LOCKED R/W touchscreen Switch Matrix control register. */
67 +#define TSXSample (TOUCH_BASE+0x10) /* LOCKED R/W touchscreen Switch Matrix control register. */
68 +#define TSYSample (TOUCH_BASE+0x14) /* LOCKED R/W touchscreen Switch Matrix control register. */
69 +#define TSDirect (TOUCH_BASE+0x18) /* LOCKED R/W touchscreen Switch Matrix control register. */
70 +#define TSDetect (TOUCH_BASE+0x1C) /* LOCKED R/W touchscreen Switch Matrix control register. */
71 +#define TSSWLock (TOUCH_BASE+0x20) /* NA R/W touchscreen software lock register. */
72 +#define TSSetup2 (TOUCH_BASE+0x24) /* R/W touchscreen setup control register #2. */
75 +// To customize for a new touchscreen, there are various macros that
76 +// have to be set. If you allow UART_HACK_DEBUG to be defined, you
77 +// will get real time ts data scrolling up your serial terminal
78 +// screen that will help you empirically determine good values for these.
82 +// These are used as trigger levels to know when we have pen up/down
85 +// 1. TS_HEAVY_INV_PRESSURE < TS_LIGHT_INV_PRESSURE because these
86 +// are Inverse pressure.
87 +// 2. Any touch lighter than TS_LIGHT_INV_PRESSURE is a pen up.
88 +// 3. Any touch heavier than TS_HEAVY_INV_PRESSURE is a pen down.
90 +#define TS_HEAVY_INV_PRESSURE 0xFE0 //C00
91 +#define TS_LIGHT_INV_PRESSURE 0xFFF //e00
94 +// If the x, y, or inverse pressure changes more than these values
95 +// between two succeeding points, the point is not reported.
97 +#define TS_MAX_VALID_XY_CHANGE 0x300
98 +#define TS_MAX_VALID_PRESSURE_CHANGE 0x100
101 +// This is the minimum Z1 Value that is valid.
103 +#define MIN_Z1_VALUE 0x50
106 +// Settling delay for taking each ADC measurement. Increase this
107 +// if ts is jittery.
109 +#define EP93XX_TS_ADC_DELAY_USEC 2000
112 +// Delay between TS points.
114 +#define EP93XX_TS_PER_POINT_DELAY_USEC 10000
116 +//-----------------------------------------------------------------------------
117 +// Debug messaging thru the UARTs
118 +//-----------------------------------------------------------------------------
120 + * Hello there! Are you trying to get this driver to work with a new
121 + * touschscreen? Turn this on and you will get useful info coming
122 + * out of your serial port.
124 +/* #define PRINT_CALIBRATION_FACTORS */
125 +#ifdef PRINT_CALIBRATION_FACTORS
126 +#define UART_HACK_DEBUG 1
127 +int iMaxX=0, iMaxY=0, iMinX = 0xfff, iMinY = 0xfff;
131 + * For debugging, let's spew messages out serial port 1 or 3 at 57,600 baud.
133 +/* #define UART_HACK_DEBUG 1 */
135 +#ifdef UART_HACK_DEBUG
136 +static char szBuf[256];
137 +void UARTWriteString(char * msg);
138 +#define DPRINTK( x... ) \
139 + sprintf( szBuf, ##x ); \
140 + UARTWriteString( szBuf );
142 +static char szBuf[256];
143 +#define DPRINTK( x... ) \
144 + sprintf( szBuf, ##x ); \
148 +#define DPRINTK( x... )
150 +//-----------------------------------------------------------------------------
151 +// A few more macros...
152 +//-----------------------------------------------------------------------------
153 +#define TSSETUP_DEFAULT ( TSSETUP_NSMP_32 | TSSETUP_DEV_64 | \
154 + ((128<<TSSETUP_SDLY_SHIFT) & TSSETUP_SDLY_MASK) | \
155 + ((128<<TSSETUP_DLY_SHIFT) & TSSETUP_DLY_MASK) )
157 +#define TSSETUP2_DEFAULT (TSSETUP2_NSIGND)
160 +// For now, we use one of the minor numbers from the local/experimental
163 +#define EP93XX_TS_MINOR 240
165 +//-----------------------------------------------------------------------------
166 +// Static Declarations
167 +//-----------------------------------------------------------------------------
168 +static unsigned int guiLastX, guiLastY;
169 +static unsigned int guiLastInvPressure;
171 +struct TouchScreenSample
176 + int currentPressure;
177 + struct timeval currentTime;
181 +// This must match the structure in tslib.
186 + unsigned int pressure;
191 +static struct TouchScreenSample gSample;
193 +// static int currentX, currentY, currentButton;
194 +// static int gPressure;
195 +// static struct timeval gtime;
197 +static int bFreshTouchData;
198 +static int bCurrentPenDown;
202 +static DECLARE_WAIT_QUEUE_HEAD(queue);
203 +static DECLARE_MUTEX(open_sem);
204 +static spinlock_t event_buffer_lock = SPIN_LOCK_UNLOCKED;
205 +static struct fasync_struct *ep93xx_fasync;
207 +//-----------------------------------------------------------------------------
208 +// Typedef Declarations
209 +//-----------------------------------------------------------------------------
211 + TS_MODE_UN_INITIALIZED,
212 + TS_MODE_HARDWARE_SCAN,
216 +static ts_mode_t gScanningMode;
219 + TS_STATE_STOPPED = 0,
236 +static ts_struct_t sTouch;
239 + * From the spec, here's how to set up the touch screen's switch registers.
243 + unsigned int uiDetect;
244 + unsigned int uiDischarge;
245 + unsigned int uiXSample;
246 + unsigned int uiYSample;
247 + unsigned int uiSwitchZ1;
248 + unsigned int uiSwitchZ2;
252 +// Here's the switch settings for a 4-wire touchscreen. See the spec
253 +// for how to handle a 4, 7, or 8-wire.
255 +const static SwitchStructType sSwitchSettings =
257 + * TSDetect TSDischarge TSXSample TSYSample SwitchZ1 SwitchZ2
259 + {0x00403604, 0x0007fe04, 0x00081604, 0x00104601, 0x00101601, 0x00101608};
262 +//-----------------------------------------------------------------------------
263 +// Function Declarations
264 +//-----------------------------------------------------------------------------
265 +static void ep93xx_ts_set_direct( unsigned int uiADCSwitch );
266 +static irqreturn_t ep93xx_ts_isr(int irq, void *dev_id);
267 +static irqreturn_t ep93xx_timer2_isr(int irq, void *dev_id);
268 +static void ee93xx_ts_evt_add( int button, int dX, int dY, int Pressure );
269 +static ssize_t ep93xx_ts_read(struct file *filp, char *buf,
270 + size_t count, loff_t *l);
271 +static unsigned int ep93xx_ts_poll(struct file *filp, poll_table *wait);
272 +static int ep93xx_ts_open(struct inode *inode, struct file *filp);
273 +static int ep93xx_ts_fasync(int fd, struct file *filp, int on);
274 +static int ep93xx_ts_release(struct inode *inode, struct file *filp);
275 +static ssize_t ep93xx_ts_write(struct file *file, const char *buffer,
276 + size_t count, loff_t *ppos);
277 +static void ep93xx_ts_setup(void);
278 +static void ep93xx_ts_shutdown(void);
279 +int __init ep93xx_ts_init(void);
280 +void __exit ep93xx_ts_exit(void);
281 +static unsigned int CalculateInvPressure( void );
282 +static unsigned int ADCGetData( unsigned int uiSamples, unsigned int uiMaxDiff);
283 +static void TS_Soft_Scan_Mode(void);
284 +static void TS_Hardware_Scan_Mode(void);
285 +static void ProcessPointData(void);
286 +static void Set_Timer2_uSec( unsigned int Delay_mSec );
287 +static void Stop_Timer2(void);
291 +//-----------------------------------------------------------------------------
293 +//-----------------------------------------------------------------------------
295 +#ifdef UART_HACK_DEBUG
297 +// This "array" is a cheap-n-easy way of getting access to the UART registers.
298 +static unsigned int * const pDebugUART=(unsigned int *)IO_ADDRESS(UART1_BASE);
299 +//static unsigned int * const pDebugUART=(unsigned int *)IO_ADDRESS(UART3_BASE);
300 +static int bUartInitialized = 0;
302 +void SendChar(char value)
304 + // wait for Tx fifo full flag to clear.
305 + while (pDebugUART[0x18>>2] & 0x20);
307 + // send a char to the uart
308 + pDebugUART[0] = value;
311 +void UARTWriteString(char * msg)
314 + unsigned int uiTemp;
316 + //if((pDebugUART[0x14>>2] & 0x1) == 0)
317 + if( bUartInitialized == 0 )
319 + uiTemp = inl(EP93XX_SYSCON_DEVICE_CONFIG);
320 + uiTemp |= EP93XX_SYSCON_DEVCFG_U1E;
321 + //uiTemp |= EP93XX_SYSCON_DEVCFG_U3E;
322 + SysconSetLocked(EP93XX_SYSCON_DEVICE_CONFIG, uiTemp);
323 + pDebugUART[0x10>>2] = 0xf;
324 + pDebugUART[0xc>>2] = 0;
325 + pDebugUART[0x8>>2] = 0x70;
326 + pDebugUART[0x14>>2] = 0x1;
327 + bUartInitialized = 1;
329 + while (msg[index] != 0)
331 + if (msg[index] == '\n')
338 + SendChar(msg[index]);
343 +#endif // UART_HACK_DEBUG
348 +static irqreturn_t ep93xx_ts_isr(int irq, void *dev_id)
353 + // Note that we don't clear the interrupt here. The interrupt
354 + // gets cleared in TS_Soft_Scan_Mode when the TS ENABLE
359 + // Set the ts to manual polling mode and schedule a callback.
360 + // That way we can return from the isr in a reasonable amount of
361 + // time and process the touch in the callback after a brief delay.
363 + TS_Soft_Scan_Mode();
365 + return(IRQ_HANDLED);
369 + * Save the current ts 'event' in an atomic fashion.
371 +static void ee93xx_ts_evt_add( int buttons, int iX, int iY, int iPressure )
373 +#ifdef PRINT_CALIBRATION_FACTORS
374 + if( iX > iMaxX ) iMaxX = iX;
375 + if( iX < iMinX ) iMinX = iX;
376 + if( iY > iMaxY ) iMaxY = iY;
377 + if( iY < iMinY ) iMinY = iY;
381 + // printk("ee93xx_ts_evt_add\n");
384 + * Note the event, but use spinlocks to keep it from getting
385 + * halfway read if we get interrupted.
388 + spin_lock(&event_buffer_lock);
389 + gSample.currentX = iX;
390 + gSample.currentY = iY;
391 + gSample.currentButton = buttons;
392 + gSample.currentPressure = iPressure;
393 + bFreshTouchData = 1;
394 + do_gettimeofday(&gSample.currentTime);
397 + spin_unlock(&event_buffer_lock);
399 + kill_fasync(&ep93xx_fasync, SIGIO, POLL_IN);
400 + wake_up_interruptible(&queue);
405 +static ssize_t ep93xx_ts_read(struct file *filp, char *buf, size_t count, loff_t *l)
408 + unsigned short data[3];
409 + struct ts_sample ts_data;
410 + int iReturn = -EFAULT;
411 + // printk("ep93xx_ts_read\n");
413 +#ifdef PRINT_CALIBRATION_FACTORS
415 + if( bFreshTouchData && (lala++ > 9) )
417 + DPRINTK("%4d, %4d - range [%4d to %4d],[%4d to %4d]\n",
418 + f, currentY, iMinX, iMaxX, iMinY, iMaxY );
422 + if( !bFreshTouchData)
426 + else if( (count == sizeof(data)) )
428 + spin_lock_irq(&event_buffer_lock);
429 + bFreshTouchData = 0;
430 + data[0] = gSample.currentX;
431 + data[1] = gSample.currentY;
432 + data[2] = gSample.currentButton;
434 + spin_unlock_irq(&event_buffer_lock);
436 + if (copy_to_user(buf, data, sizeof data))
439 + count -= sizeof(data);
441 + /* return the # of bytes that got read */
442 + iReturn = sizeof(data) ;
444 + else if (count == sizeof(struct ts_sample) )
446 + spin_lock_irq(&event_buffer_lock);
447 + bFreshTouchData = 0;
448 + ts_data.x = gSample.currentX;
449 + ts_data.y = gSample.currentY;
450 + ts_data.pressure = gSample.currentPressure;
451 + ts_data.tv = gSample.currentTime;
452 + spin_unlock_irq(&event_buffer_lock);
454 + if (copy_to_user(buf, &ts_data, sizeof(struct ts_sample)))
460 + count -= sizeof(ts_data);
461 + iReturn = sizeof(ts_data);
469 +static unsigned int ep93xx_ts_poll(struct file *filp, poll_table *wait)
471 + // printk("ep93xx_ts_poll\n");
472 + poll_wait(filp, &queue, wait);
474 + if( bFreshTouchData )
476 + return POLLIN | POLLRDNORM;
482 +static int ep93xx_ts_open(struct inode *inode, struct file *filp)
484 + printk("ep93xx_ts_open");
486 + if( down_trylock(&open_sem) )
497 + * Asynchronous I/O support.
499 +static int ep93xx_ts_fasync(int fd, struct file *filp, int on)
503 + retval = fasync_helper(fd, filp, on, &ep93xx_fasync);
512 +static int ep93xx_ts_release(struct inode *inode, struct file *filp)
517 + * Call our async I/O support to request that this file
518 + * cease to be used for async I/O.
520 + ep93xx_ts_fasync(-1, filp, 0);
522 + ep93xx_ts_shutdown();
529 +static ssize_t ep93xx_ts_write(struct file *file, const char *buffer, size_t count,
536 +static int ep93xx_ts_ioctl(struct inode *inode, struct file *file, uint command, ulong u)
538 + static const int version = EV_VERSION;
539 + static const u_int32_t bit =(1 << EV_ABS);
540 + static const u_int32_t absbit = (1 << ABS_X) | (1 << ABS_Y) | (1 << ABS_PRESSURE);
546 + case EVIOCGVERSION:
547 + DPRINTK("ep93xx_ts_ioctl command = EVIOCGVERSION\r\n");
548 + i = copy_to_user((void __user *)u, (void *)version, sizeof(version));
549 + iReturn = i ? -EFAULT : 0;
552 + case EVIOCGBIT(0,sizeof(u_int32_t) * 8) :
553 + DPRINTK("ep93xx_ts_ioctl command = EVIOCGBIT(0,sizeof(uint32) * 8)\r\n");
554 + i = copy_to_user((void __user *)u, (void *)bit, sizeof(bit));
555 + iReturn = i ? -EFAULT : 0;
558 + case EVIOCGBIT(EV_ABS, sizeof(absbit) * 8):
559 + DPRINTK("ep93xx_ts_ioctl command = EVIOCGBIT(0,sizeof(uint32) * 8)\r\n");
560 + copy_to_user((void __user *)u, (void *)absbit, sizeof(absbit));
561 + iReturn = i ? -EFAULT : 0;
564 + DPRINTK(" ep93xx_ts_ioctl unknown command = %d\n",u);
572 +static struct file_operations ep93xx_ts_fops = {
573 + owner: THIS_MODULE,
574 + read: ep93xx_ts_read,
575 + write: ep93xx_ts_write,
576 + poll: ep93xx_ts_poll,
577 + open: ep93xx_ts_open,
578 + ioctl: ep93xx_ts_ioctl,
579 + release: ep93xx_ts_release,
580 + fasync: ep93xx_ts_fasync,
583 +static struct miscdevice ep93xx_ts_miscdev =
590 +void ep93xx_ts_setup(void)
592 + unsigned int uiKTDIV, uiTSXYMaxMin;
593 + // printk("ep93xx_hw_setup\n");
596 + * Set the TSEN bit in KTDIV so that we are enabling the clock
597 + * for the touchscreen.
599 + uiKTDIV = inl(SYSCON_KTDIV);
600 + uiKTDIV |= SYSCON_KTDIV_TSEN;
601 + SysconSetLocked( SYSCON_KTDIV, uiKTDIV );
604 + // Program the TSSetup and TSSetup2 registers.
606 + outl( TSSETUP_DEFAULT, TSSetup );
607 + outl( TSSETUP2_DEFAULT, TSSetup2 );
610 + // Set the the touch settings.
612 + outl( 0xaa, TSSWLock );
613 + outl( sSwitchSettings.uiDischarge, TSDirect );
615 + outl( 0xaa, TSSWLock );
616 + outl( sSwitchSettings.uiDischarge, TSDischarge );
618 + outl( 0xaa, TSSWLock );
619 + outl( sSwitchSettings.uiSwitchZ1, TSXSample );
621 + outl( 0xaa, TSSWLock );
622 + outl( sSwitchSettings.uiSwitchZ2, TSYSample );
624 + outl( 0xaa, TSSWLock );
625 + outl( sSwitchSettings.uiDetect, TSDetect );
628 + // X,YMin set to 0x40 = have to drag that many pixels for a new irq.
629 + // X,YMax set to 0x40 = 1024 pixels is the maximum movement within the
630 + // time scan limit.
632 + uiTSXYMaxMin = (50 << TSMAXMIN_XMIN_SHIFT) & TSMAXMIN_XMIN_MASK;
633 + uiTSXYMaxMin |= (50 << TSMAXMIN_YMIN_SHIFT) & TSMAXMIN_YMIN_MASK;
634 + uiTSXYMaxMin |= (0xff << TSMAXMIN_XMAX_SHIFT) & TSMAXMIN_XMAX_MASK;
635 + uiTSXYMaxMin |= (0xff << TSMAXMIN_YMAX_SHIFT) & TSMAXMIN_YMAX_MASK;
636 + outl( uiTSXYMaxMin, TSXYMaxMin );
638 + bCurrentPenDown = 0;
639 + bFreshTouchData = 0;
642 + guiLastInvPressure = 0xffffff;
645 + // Enable the touch screen scanning engine.
647 + TS_Hardware_Scan_Mode();
651 + * ep93xx_ts_shutdown
655 +ep93xx_ts_shutdown(void)
657 + unsigned int uiKTDIV;
659 + DPRINTK("ep93xx_ts_shutdown\n");
661 + sTouch.state = TS_STATE_STOPPED;
665 + * Disable the scanning engine.
667 + outl( 0, TSSetup );
668 + outl( 0, TSSetup2 );
671 + * Clear the TSEN bit in KTDIV so that we are disabling the clock
672 + * for the touchscreen.
674 + uiKTDIV = inl(SYSCON_KTDIV);
675 + uiKTDIV &= ~SYSCON_KTDIV_TSEN;
676 + SysconSetLocked( SYSCON_KTDIV, uiKTDIV );
678 +} /* ep93xx_ts_shutdown */
680 +static irqreturn_t ep93xx_timer2_isr(int irq, void *dev_id)
682 + DPRINTK("%d", (int)sTouch.state );
684 + switch( sTouch.state )
686 + case TS_STATE_STOPPED:
687 + TS_Hardware_Scan_Mode();
691 + // Get the Z1 value for pressure measurement and set up
692 + // the switch register for getting the Z2 measurement.
695 + Set_Timer2_uSec( EP93XX_TS_ADC_DELAY_USEC );
696 + sTouch.uiZ1 = ADCGetData( 2, 200 );
697 + ep93xx_ts_set_direct( sSwitchSettings.uiSwitchZ2 );
698 + sTouch.state = TS_STATE_Z2;
702 + // Get the Z2 value for pressure measurement and set up
703 + // the switch register for getting the Y measurement.
706 + sTouch.uiZ2 = ADCGetData( 2, 200 );
707 + ep93xx_ts_set_direct( sSwitchSettings.uiYSample );
708 + sTouch.state = TS_STATE_Y;
712 + // Get the Y value and set up the switch register for
713 + // getting the X measurement.
716 + sTouch.uiY = ADCGetData( 4, 20 );
717 + ep93xx_ts_set_direct( sSwitchSettings.uiXSample );
718 + sTouch.state = TS_STATE_X;
722 + // Read the X value. This is the last of the 4 adc values
723 + // we need so we continue on to process the data.
728 + sTouch.uiX = ADCGetData( 4, 20 );
730 + outl( 0xaa, TSSWLock );
731 + outl( sSwitchSettings.uiDischarge, TSDirect );
733 + sTouch.state = TS_STATE_DONE;
736 + * Process this set of ADC readings.
738 + ProcessPointData();
744 + // Shouldn't get here. But if we do, we can recover...
746 + case TS_STATE_DONE:
747 + TS_Hardware_Scan_Mode();
752 + // Clear the timer2 interrupt.
754 + outl( 1, TIMER2CLEAR );
755 + return(IRQ_HANDLED);
758 +/*---------------------------------------------------------------------
761 + * This routine processes the ADC data into usable point data and then
762 + * puts the driver into hw or sw scanning mode before returning.
764 + * We calculate inverse pressure (lower number = more pressure) then
765 + * do a hystheresis with the two pressure values 'light' and 'heavy'.
767 + * If we are above the light, we have pen up.
768 + * If we are below the heavy we have pen down.
769 + * As long as the pressure stays below the light, pen stays down.
770 + * When we get above the light again, pen goes back up.
773 +static void ProcessPointData(void)
775 + int bValidPoint = 0;
776 + unsigned int uiXDiff, uiYDiff, uiInvPressureDiff;
777 + unsigned int uiInvPressure;
780 + // Calculate the current pressure.
782 + uiInvPressure = CalculateInvPressure();
784 + DPRINTK(" X=0x%x, Y=0x%x, Z1=0x%x, Z2=0x%x, InvPressure=0x%x",
785 + sTouch.uiX, sTouch.uiY, sTouch.uiZ1, sTouch.uiZ2, uiInvPressure );
788 + // If pen pressure is so light that it is greater than the 'max' setting
789 + // then we consider this to be a pen up.
791 + if( uiInvPressure >= TS_LIGHT_INV_PRESSURE )
793 + DPRINTK(" -- up \n");
794 + bCurrentPenDown = 0;
795 + ee93xx_ts_evt_add( 0, guiLastX, guiLastY, 0 );
796 + TS_Hardware_Scan_Mode();
802 + // If the pen pressure is hard enough to be less than the 'min' OR
803 + // the pen is already down and is still less than the 'max'...
805 + if( (uiInvPressure < TS_HEAVY_INV_PRESSURE) ||
806 + ( bCurrentPenDown && (uiInvPressure < TS_LIGHT_INV_PRESSURE) ) )
808 + if( bCurrentPenDown )
811 + // If pen was previously down, check the difference between
812 + // the last sample and this one... if the difference between
813 + // samples is too great, ignore the sample.
815 + uiXDiff = abs(guiLastX - sTouch.uiX);
816 + uiYDiff = abs(guiLastY - sTouch.uiY);
817 + uiInvPressureDiff = abs(guiLastInvPressure - uiInvPressure);
819 + if( (uiXDiff < TS_MAX_VALID_XY_CHANGE) && (uiYDiff < TS_MAX_VALID_XY_CHANGE) &&
820 + (uiInvPressureDiff < TS_MAX_VALID_PRESSURE_CHANGE) )
822 + DPRINTK(" -- valid(two) \n");
827 + DPRINTK(" -- INvalid(two) \n");
832 + DPRINTK(" -- valid \n");
837 + * If either the pen was put down or dragged make a note of it.
841 + guiLastX = sTouch.uiX;
842 + guiLastY = sTouch.uiY;
843 + guiLastInvPressure = uiInvPressure;
844 + bCurrentPenDown = 1;
845 + ee93xx_ts_evt_add( 1, sTouch.uiX, sTouch.uiY, (0x7000000 /uiInvPressure) );
848 + TS_Soft_Scan_Mode();
852 + DPRINTK(" -- fallout \n");
853 + TS_Hardware_Scan_Mode();
856 +static void ep93xx_ts_set_direct( unsigned int uiADCSwitch )
858 + unsigned int uiResult;
861 + // Set the switch settings in the direct register.
863 + outl( 0xaa, TSSWLock );
864 + outl( uiADCSwitch, TSDirect );
867 + // Read and throw away the first sample.
870 + uiResult = inl(TSXYResult);
871 + } while( !(uiResult & TSXYRESULT_SDR) );
875 +static unsigned int ADCGetData
877 + unsigned int uiSamples,
878 + unsigned int uiMaxDiff
881 + unsigned int uiResult, uiValue, uiCount, uiLowest, uiHighest, uiSum, uiAve;
886 + //Initialize our values.
888 + uiLowest = 0xfffffff;
892 + for( uiCount = 0 ; uiCount < uiSamples ; uiCount++ )
895 + // Read the touch screen four more times and average.
898 + uiResult = inl(TSXYResult);
899 + } while( !(uiResult & TSXYRESULT_SDR) );
901 + uiValue = (uiResult & TSXYRESULT_AD_MASK) >> TSXYRESULT_AD_SHIFT;
902 + uiValue = ((uiValue >> 4) + ((1 + TSXYRESULT_X_MASK)>>1)) & TSXYRESULT_X_MASK;
905 + // Add up the values.
910 + // Get the lowest and highest values.
912 + if( uiValue < uiLowest )
914 + uiLowest = uiValue;
916 + if( uiValue > uiHighest )
918 + uiHighest = uiValue;
922 + } while( (uiHighest - uiLowest) > uiMaxDiff );
925 + // Calculate the Average value.
927 + uiAve = uiSum / uiSamples;
932 +//****************************************************************************
933 +// CalculateInvPressure
934 +//****************************************************************************
935 +// Is the Touch Valid. Touch is not valid if the X or Y value is not
936 +// in range and the pressure is not enough.
938 +// Touch resistance can be measured by the following formula:
941 +// Rtouch = --------- * (-- - 1)
944 +// This is simplified in the ration of Rtouch to Rx. The lower the value, the
945 +// higher the pressure.
948 +// InvPressure = X * (-- - 1)
951 +static unsigned int CalculateInvPressure(void)
953 + unsigned int uiInvPressure;
956 + // Check to see if the point is valid.
958 + if( sTouch.uiZ1 < MIN_Z1_VALUE )
960 + uiInvPressure = 0x10000;
964 + // Can omit the pressure calculation if you need to get rid of the division.
968 + uiInvPressure = ((sTouch.uiX * sTouch.uiZ2) / sTouch.uiZ1) - sTouch.uiX;
971 + return uiInvPressure;
976 +//****************************************************************************
977 +// TS_Hardware_Scan_Mode
978 +//****************************************************************************
979 +// Enables the ep93xx ts scanning engine so that when the pen goes down
980 +// we will get an interrupt.
983 +static void TS_Hardware_Scan_Mode(void)
985 + unsigned int uiDevCfg;
990 + // Disable the soft scanning engine.
992 + sTouch.state = TS_STATE_STOPPED;
996 + // Clear the TIN (Touchscreen INactive) bit so we can go to
997 + // automatic scanning mode.
999 + uiDevCfg = inl( EP93XX_SYSCON_DEVICE_CONFIG );
1000 + SysconSetLocked( EP93XX_SYSCON_DEVICE_CONFIG, (uiDevCfg & ~EP93XX_SYSCON_DEVCFG_TIN) );
1003 + // Enable the touch screen scanning state machine by setting
1004 + // the ENABLE bit.
1006 + outl( (TSSETUP_DEFAULT | TSSETUP_ENABLE), TSSetup );
1009 + // Set the flag to show that we are in interrupt mode.
1011 + gScanningMode = TS_MODE_HARDWARE_SCAN;
1014 + // Initialize TSSetup2 register.
1016 + outl( TSSETUP2_DEFAULT, TSSetup2 );
1020 +//****************************************************************************
1021 +// TS_Soft_Scan_Mode
1022 +//****************************************************************************
1023 +// Sets the touch screen to manual polling mode.
1026 +static void TS_Soft_Scan_Mode(void)
1028 + unsigned int uiDevCfg;
1032 + if( gScanningMode != TS_MODE_SOFT_SCAN )
1035 + // Disable the touch screen scanning state machine by clearing
1036 + // the ENABLE bit.
1038 + outl( TSSETUP_DEFAULT, TSSetup );
1041 + // Set the TIN bit so we can do manual touchscreen polling.
1043 + uiDevCfg = inl(EP93XX_SYSCON_DEVICE_CONFIG );
1044 + SysconSetLocked( EP93XX_SYSCON_DEVICE_CONFIG, (uiDevCfg | EP93XX_SYSCON_DEVCFG_TIN) );
1048 + // Set the switch register up for the first ADC reading
1050 + ep93xx_ts_set_direct( sSwitchSettings.uiSwitchZ1 );
1053 + // Initialize our software state machine to know which ADC
1054 + // reading to take
1056 + sTouch.state = TS_STATE_Z1;
1059 + // Set the timer so after a mSec or two settling delay it will
1060 + // take the first ADC reading.
1062 + Set_Timer2_uSec( EP93XX_TS_PER_POINT_DELAY_USEC );
1065 + // Note that we are in sw scanning mode not hw scanning mode.
1067 + gScanningMode = TS_MODE_SOFT_SCAN;
1071 +static void Set_Timer2_uSec( unsigned int uiDelay_uSec )
1073 + unsigned int uiClockTicks;
1078 + outl( 0, TIMER2CONTROL );
1080 + uiClockTicks = ((uiDelay_uSec * 508) + 999) / 1000;
1081 + outl( uiClockTicks, TIMER2LOAD );
1082 + outl( uiClockTicks, TIMER2VALUE );
1085 + * Set up Timer 2 for 508 kHz clock and periodic mode.
1087 + outl( 0xC8, TIMER2CONTROL );
1091 +static void Stop_Timer2(void)
1093 + outl( 0, TIMER2CONTROL );
1097 + * Initialization and exit routines
1099 +int __init ep93xx_ts_init(void)
1103 + //printk("ep93xx_ts_init\n");
1105 + // printk("request Touchscreen interrupt.\n");
1106 + retval = request_irq( IRQ_EP93XX_TOUCH, ep93xx_ts_isr, IRQF_DISABLED, "ep93xx_ts", 0);
1109 + printk(KERN_WARNING "ep93xx_ts: failed to get touchscreen IRQ\n");
1113 + // printk("Request Timer interrupt.\n");
1114 + retval = request_irq( IRQ_EP93XX_TIMER2, ep93xx_timer2_isr,
1115 + IRQF_DISABLED, "ep93xx_timer2", 0);
1118 + printk(KERN_WARNING "ep93xx_ts: failed to get timer2 IRQ\n");
1122 + // printk("Register Touchscreen Driver\n");
1123 + misc_register(&ep93xx_ts_miscdev);
1125 + sTouch.state = TS_STATE_STOPPED;
1126 + gScanningMode = TS_MODE_UN_INITIALIZED;
1128 + printk(KERN_NOTICE "ep93xx touchscreen driver configured for 4-wire operation\n");
1133 +ep93xx_ts_exit(void)
1135 + DPRINTK("ep93xx_ts_exit\n");
1139 + free_irq(IRQ_EP93XX_TOUCH, 0);
1140 + free_irq(IRQ_EP93XX_TIMER2, 0);
1142 + misc_deregister(&ep93xx_ts_miscdev);
1145 +module_init(ep93xx_ts_init);
1146 +module_exit(ep93xx_ts_exit);
1148 +MODULE_DESCRIPTION("Cirrus EP93xx touchscreen driver");
1149 +MODULE_SUPPORTED_DEVICE("touchscreen/ep93xx");
1150 Index: linux-2.6.30.9/drivers/input/touchscreen/ep93xx_ts.h
1151 ===================================================================
1152 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1153 +++ linux-2.6.30.9/drivers/input/touchscreen/ep93xx_ts.h 2009-11-24 21:00:45.000000000 +0100
1158 + * The contents of this file are subject to the Mozilla Public License
1159 + * Version 1.1 (the "License"); you may not use this file except in
1160 + * compliance with the License. You may obtain a copy of the License
1161 + * at http://www.mozilla.org/MPL/
1163 + * Software distributed under the License is distributed on an "AS IS"
1164 + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
1165 + * the License for the specific language governing rights and
1166 + * limitations under the License.
1168 + * The initial developer of the original code is David A. Hinds
1169 + * <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
1170 + * are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
1172 + * Alternatively, the contents of this file may be used under the
1173 + * terms of the GNU General Public License version 2 (the "GPL"), in
1174 + * which case the provisions of the GPL are applicable instead of the
1175 + * above. If you wish to allow the use of your version of this file
1176 + * only under the terms of the GPL and not to allow others to use
1177 + * your version of this file under the MPL, indicate your decision by
1178 + * deleting the provisions above and replace them with the notice and
1179 + * other provisions required by the GPL. If you do not delete the
1180 + * provisions above, a recipient may use your version of this file
1181 + * under either the MPL or the GPL.
1184 +#ifndef _LINUX_EP93XX_TS_H
1185 +#define _LINUX_EP93XX_TS_H
1187 +/*touchscreen register defines*/
1188 +#define SYSCON_KTDIV EP93XX_SYSCON_KEY_TOUCH_CLOCK_DIV
1189 +#define SYSCON_SWLOCK EP93XX_SYSCON_SWLOCK
1190 +#define TSSetup EP93XX_TOUCHSCREEN_TSSetup
1191 +#define TSXYMaxMin EP93XX_TOUCHSCREEN_TSXYMaxMin
1192 +#define TSXYResult EP93XX_TOUCHSCREEN_TSDischarge
1193 +#define TSDischarge EP93XX_TOUCHSCREEN_TSDischarge
1194 +#define TSXSample EP93XX_TOUCHSCREEN_TSXSample
1195 +#define TSYSample EP93XX_TOUCHSCREEN_TSYSample
1196 +#define TSDirect EP93XX_TOUCHSCREEN_TSDirect
1197 +#define TSDetect EP93XX_TOUCHSCREEN_TSDetect
1198 +#define TSSWLock EP93XX_TOUCHSCREEN_TSSWLock
1199 +#define TSSetup2 EP93XX_TOUCHSCREEN_TSSetup2
1202 +//#define SYSCON_DEVCFG EP93XX_SYSCON_DEVICE_CONFIG
1203 +#define TIMER2CONTROL EP93XX_TIMER2_CONTROL
1204 +#define TIMER2LOAD EP93XX_TIMER2_LOAD
1205 +#define TIMER2VALUE EP93XX_TIMER2_VALUE
1206 +#define TIMER2CLEAR EP93XX_TIMER2_CLEAR
1208 Index: linux-2.6.30.9/arch/arm/mach-ep93xx/include/mach/hardware.h
1209 ===================================================================
1210 --- linux-2.6.30.9.orig/arch/arm/mach-ep93xx/include/mach/hardware.h 2009-11-24 21:00:18.000000000 +0100
1211 +++ linux-2.6.30.9/arch/arm/mach-ep93xx/include/mach/hardware.h 2009-11-24 21:09:21.000000000 +0100
1213 #include "ep93xx-regs.h"
1215 #define pcibios_assign_all_busses() 0
1216 +#include "regs_touch.h"
1218 #include "platform.h"
1220 Index: linux-2.6.30.9/arch/arm/mach-ep93xx/include/mach/regs_touch.h
1221 ===================================================================
1222 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
1223 +++ linux-2.6.30.9/arch/arm/mach-ep93xx/include/mach/regs_touch.h 2009-11-24 21:00:45.000000000 +0100
1225 +/*=============================================================================
1227 + * FILE: regs_touch.h
1229 + * DESCRIPTION: Analog Touchscreen Register Definition
1231 + * Copyright Cirrus Logic, 2001-2003
1233 + * This program is free software; you can redistribute it and/or modify
1234 + * it under the terms of the GNU General Public License as published by
1235 + * the Free Software Foundation; either version 2 of the License, or
1236 + * (at your option) any later version.
1238 + * This program is distributed in the hope that it will be useful,
1239 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1240 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1241 + * GNU General Public License for more details.
1243 + * You should have received a copy of the GNU General Public License
1244 + * along with this program; if not, write to the Free Software
1245 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1246 + *=============================================================================
1248 +#ifndef _REGS_TOUCH_H_
1249 +#define _REGS_TOUCH_H_
1252 + *-----------------------------------------------------------------------------
1253 + * Individual bit #defines
1254 + *-----------------------------------------------------------------------------
1256 +#define TSSETUP_SDLY_MASK 0x000003FF
1257 +#define TSSETUP_SDLY_SHIFT 0
1258 +#define TSSETUP_NSMP_4 0x00000000
1259 +#define TSSETUP_NSMP_8 0x00000400
1260 +#define TSSETUP_NSMP_16 0x00000800
1261 +#define TSSETUP_NSMP_32 0x00000C00
1262 +#define TSSETUP_NSMP_MASK 0x00000C00
1263 +#define TSSETUP_DEV_4 0x00000000
1264 +#define TSSETUP_DEV_8 0x00001000
1265 +#define TSSETUP_DEV_12 0x00002000
1266 +#define TSSETUP_DEV_16 0x00003000
1267 +#define TSSETUP_DEV_24 0x00004000
1268 +#define TSSETUP_DEV_32 0x00005000
1269 +#define TSSETUP_DEV_64 0x00006000
1270 +#define TSSETUP_DEV_128 0x00007000
1271 +#define TSSETUP_ENABLE 0x00008000
1272 +#define TSSETUP_DLY_MASK 0x03FF0000
1273 +#define TSSETUP_DLY_SHIFT 16
1274 +#define TSSETUP_TDTCT 0x80000000
1276 +#define TSMAXMIN_XMIN_MASK 0x000000FF
1277 +#define TSMAXMIN_XMIN_SHIFT 0
1278 +#define TSMAXMIN_YMIN_MASK 0x0000FF00
1279 +#define TSMAXMIN_YMIN_SHIFT 8
1280 +#define TSMAXMIN_XMAX_MASK 0x00FF0000
1281 +#define TSMAXMIN_XMAX_SHIFT 16
1282 +#define TSMAXMIN_YMAX_MASK 0xFF000000
1283 +#define TSMAXMIN_YMAX_SHIFT 24
1285 +#define TSXYRESULT_X_MASK 0x00000FFF
1286 +#define TSXYRESULT_X_SHIFT 0
1287 +#define TSXYRESULT_AD_MASK 0x0000FFFF
1288 +#define TSXYRESULT_AD_SHIFT 0
1289 +#define TSXYRESULT_Y_MASK 0x0FFF0000
1290 +#define TSXYRESULT_Y_SHIFT 16
1291 +#define TSXYRESULT_SDR 0x80000000
1293 +#define TSX_SAMPLE_MASK 0x00003FFF
1294 +#define TSX_SAMPLE_SHIFT 0x00
1295 +#define TSY_SAMPLE_MASK 0x3FFF0000
1296 +#define TSY_SAMPLE_SHIFT 0x10
1298 +#define TSSETUP2_TINT 0x00000001
1299 +#define TSSETUP2_NICOR 0x00000002
1300 +#define TSSETUP2_PINT 0x00000004
1301 +#define TSSETUP2_PENSTS 0x00000008
1302 +#define TSSETUP2_PINTEN 0x00000010
1303 +#define TSSETUP2_DEVINT 0x00000020
1304 +#define TSSETUP2_DINTEN 0x00000040
1305 +#define TSSETUP2_DTMEN 0x00000080
1306 +#define TSSETUP2_DISDEV 0x00000100
1307 +#define TSSETUP2_NSIGND 0x00000200
1308 +#define TSSETUP2_S28EN 0x00000400
1309 +#define TSSETUP2_RINTEN 0x00000800
1311 +#define TSXYRESULT_SDR 0x80000000
1314 + *-----------------------------------------------------------------------------
1315 + *-----------------------------------------------------------------------------
1319 +#endif /* _REGS_TOUCH_H_ */