2 arch/arm/mach-ep93xx/include/mach/hardware.h | 1
3 arch/arm/mach-ep93xx/include/mach/regs_touch.h | 95 ++
4 drivers/input/touchscreen/Kconfig | 5
5 drivers/input/touchscreen/Makefile | 1
6 drivers/input/touchscreen/ep93xx_ts.c | 1117 +++++++++++++++++++++++++
7 drivers/input/touchscreen/ep93xx_ts.h | 53 +
8 6 files changed, 1272 insertions(+)
10 --- a/drivers/input/touchscreen/Kconfig
11 +++ b/drivers/input/touchscreen/Kconfig
12 @@ -177,6 +177,15 @@ config TOUCHSCREEN_EETI
13 To compile this driver as a module, choose M here: the
14 module will be called eeti_ts.
16 +config TOUCHSCREEN_EP93XX
17 + tristate "EP93xx Touchscreen"
18 + depends on ARM && INPUT && ARCH_EP93XX
20 + Say Y here to enable support for EP93xx touch screen.
22 + To compile this driver as a module, choose M here:
23 + the module will be called ep93xx_ts.
25 config TOUCHSCREEN_FUJITSU
26 tristate "Fujitsu serial touchscreen"
28 --- a/drivers/input/touchscreen/Makefile
29 +++ b/drivers/input/touchscreen/Makefile
30 @@ -23,6 +23,7 @@ obj-$(CONFIG_TOUCHSCREEN_HAMPSHIRE) += h
31 obj-$(CONFIG_TOUCHSCREEN_GUNZE) += gunze.o
32 obj-$(CONFIG_TOUCHSCREEN_EETI) += eeti_ts.o
33 obj-$(CONFIG_TOUCHSCREEN_ELO) += elo.o
34 +obj-$(CONFIG_TOUCHSCREEN_EP93XX) += ep93xx_ts.o
35 obj-$(CONFIG_TOUCHSCREEN_FUJITSU) += fujitsu_ts.o
36 obj-$(CONFIG_TOUCHSCREEN_INEXIO) += inexio.o
37 obj-$(CONFIG_TOUCHSCREEN_INTEL_MID) += intel-mid-touch.o
39 +++ b/drivers/input/touchscreen/ep93xx_ts.c
42 + * linux/drivers/input/touchscreen/ep93xx_ts.c
44 + * Copyright (C) 2003-2004 Cirrus Corp.
46 + * This program is free software; you can redistribute it and/or modify
47 + * it under the terms of the GNU General Public License version 2 as
48 + * published by the Free Software Foundation.
51 +#include <linux/module.h>
52 +#include <linux/types.h>
53 +#include <linux/delay.h>
54 +#include <linux/wait.h>
55 +#include <linux/fs.h>
56 +#include <linux/sched.h>
57 +#include <linux/poll.h>
58 +#include <linux/miscdevice.h>
59 +#include <linux/init.h>
60 +#include <linux/compiler.h>
61 +#include <linux/timer.h>
62 +#include <linux/interrupt.h>
63 +#include <linux/syscalls.h>
64 +#include <linux/input.h>
65 +#include <linux/semaphore.h>
67 +#include <mach/hardware.h>
70 +/* This stuff should be in ep93xx-regs.h */
71 +#define EP93XX_TOUCHSCREEN_REG(x) (EP93XX_TOUCHSCREEN_BASE + (x))
72 +/* R/W touchscreen controller setup control register. */
73 +#define EP93XX_TOUCHSCREEN_SETUP EP93XX_TOUCHSCREEN_REG(0x00)
74 +/* R/W touchscreen controller max/min register. */
75 +#define EP93XX_TOUCHSCREEN_XYMAXMIN EP93XX_TOUCHSCREEN_REG(0x04)
76 +/* R touchscreen controller result register. */
77 +#define EP93XX_TOUCHSCREEN_XYRESULT EP93XX_TOUCHSCREEN_REG(0x08)
78 +/* LOCKED R/W touchscreen Switch Matrix control register. */
79 +#define EP93XX_TOUCHSCREEN_DISCHARGE EP93XX_TOUCHSCREEN_REG(0x0C)
80 +#define EP93XX_TOUCHSCREEN_XSAMPLE EP93XX_TOUCHSCREEN_REG(0x10)
81 +#define EP93XX_TOUCHSCREEN_YSAMPLE EP93XX_TOUCHSCREEN_REG(0x14)
82 +#define EP93XX_TOUCHSCREEN_DIRECT EP93XX_TOUCHSCREEN_REG(0x18)
83 +#define EP93XX_TOUCHSCREEN_DETECT EP93XX_TOUCHSCREEN_REG(0x1C)
84 +/* NA R/W touchscreen software lock register. */
85 +#define EP93XX_TOUCHSCREEN_SWLOCK EP93XX_TOUCHSCREEN_REG(0x20)
86 +/* R/W touchscreen setup control register #2. */
87 +#define EP93XX_TOUCHSCREEN_SETUP2 EP93XX_TOUCHSCREEN_REG(0x24)
89 +/* These are duplicated in mach-ep93xx/core.c */
90 +#define EP93XX_TIMER_REG(x) (EP93XX_TIMER_BASE + (x))
91 +#define EP93XX_TIMER2_LOAD EP93XX_TIMER_REG(0x20)
92 +#define EP93XX_TIMER2_VALUE EP93XX_TIMER_REG(0x24)
93 +#define EP93XX_TIMER2_CONTROL EP93XX_TIMER_REG(0x28)
94 +#define EP93XX_TIMER2_CLEAR EP93XX_TIMER_REG(0x2c)
97 + * Register bit definitions
99 +#define TSSETUP_SDLY_MASK 0x000003FF
100 +#define TSSETUP_SDLY_SHIFT 0
101 +#define TSSETUP_NSMP_4 0x00000000
102 +#define TSSETUP_NSMP_8 0x00000400
103 +#define TSSETUP_NSMP_16 0x00000800
104 +#define TSSETUP_NSMP_32 0x00000C00
105 +#define TSSETUP_NSMP_MASK 0x00000C00
106 +#define TSSETUP_DEV_4 0x00000000
107 +#define TSSETUP_DEV_8 0x00001000
108 +#define TSSETUP_DEV_12 0x00002000
109 +#define TSSETUP_DEV_16 0x00003000
110 +#define TSSETUP_DEV_24 0x00004000
111 +#define TSSETUP_DEV_32 0x00005000
112 +#define TSSETUP_DEV_64 0x00006000
113 +#define TSSETUP_DEV_128 0x00007000
114 +#define TSSETUP_ENABLE 0x00008000
115 +#define TSSETUP_DLY_MASK 0x03FF0000
116 +#define TSSETUP_DLY_SHIFT 16
117 +#define TSSETUP_TDTCT 0x80000000
119 +#define TSMAXMIN_XMIN_MASK 0x000000FF
120 +#define TSMAXMIN_XMIN_SHIFT 0
121 +#define TSMAXMIN_YMIN_MASK 0x0000FF00
122 +#define TSMAXMIN_YMIN_SHIFT 8
123 +#define TSMAXMIN_XMAX_MASK 0x00FF0000
124 +#define TSMAXMIN_XMAX_SHIFT 16
125 +#define TSMAXMIN_YMAX_MASK 0xFF000000
126 +#define TSMAXMIN_YMAX_SHIFT 24
128 +#define TSXYRESULT_X_MASK 0x00000FFF
129 +#define TSXYRESULT_X_SHIFT 0
130 +#define TSXYRESULT_AD_MASK 0x0000FFFF
131 +#define TSXYRESULT_AD_SHIFT 0
132 +#define TSXYRESULT_Y_MASK 0x0FFF0000
133 +#define TSXYRESULT_Y_SHIFT 16
134 +#define TSXYRESULT_SDR 0x80000000
136 +#define TSX_SAMPLE_MASK 0x00003FFF
137 +#define TSX_SAMPLE_SHIFT 0x00
138 +#define TSY_SAMPLE_MASK 0x3FFF0000
139 +#define TSY_SAMPLE_SHIFT 0x10
141 +#define TSSETUP2_TINT 0x00000001
142 +#define TSSETUP2_NICOR 0x00000002
143 +#define TSSETUP2_PINT 0x00000004
144 +#define TSSETUP2_PENSTS 0x00000008
145 +#define TSSETUP2_PINTEN 0x00000010
146 +#define TSSETUP2_DEVINT 0x00000020
147 +#define TSSETUP2_DINTEN 0x00000040
148 +#define TSSETUP2_DTMEN 0x00000080
149 +#define TSSETUP2_DISDEV 0x00000100
150 +#define TSSETUP2_NSIGND 0x00000200
151 +#define TSSETUP2_S28EN 0x00000400
152 +#define TSSETUP2_RINTEN 0x00000800
154 +#define TSXYRESULT_SDR 0x80000000
157 + * These are used as trigger levels to know when we have pen up/down.
159 + * 1. TS_HEAVY_INV_PRESSURE < TS_LIGHT_INV_PRESSURE because these
160 + * are Inverse pressure.
161 + * 2. Any touch lighter than TS_LIGHT_INV_PRESSURE is a pen up.
162 + * 3. Any touch heavier than TS_HEAVY_INV_PRESSURE is a pen down.
164 +#define TS_HEAVY_INV_PRESSURE 0xFE0 /* C00 */
165 +#define TS_LIGHT_INV_PRESSURE 0xFFF /* e00 */
168 + * If the x, y, or inverse pressure changes more than these values
169 + * between two succeeding points, the point is not reported.
171 +#define TS_MAX_VALID_XY_CHANGE 0x300
172 +#define TS_MAX_VALID_PRESSURE_CHANGE 0x100
175 + * This is the minimum Z1 Value that is valid.
177 +#define MIN_Z1_VALUE 0x50
180 + * Settling delay for taking each ADC measurement. Increase this
181 + * if ts is jittery.
183 +#define EP93XX_TS_ADC_DELAY_USEC 2000
186 + * Delay between TS points.
188 +#define EP93XX_TS_PER_POINT_DELAY_USEC 10000
191 + * A few more macros...
193 +#define TSSETUP_DEFAULT (TSSETUP_NSMP_32 | TSSETUP_DEV_64 | \
194 + ((128<<TSSETUP_SDLY_SHIFT) & TSSETUP_SDLY_MASK) | \
195 + ((128<<TSSETUP_DLY_SHIFT) & TSSETUP_DLY_MASK))
197 +#define TSSETUP2_DEFAULT (TSSETUP2_NSIGND)
200 + * For now, we use one of the minor numbers from the local/experimental
203 +#define EP93XX_TS_MINOR 240
206 + * Static Declarations
208 +static unsigned int guiLastX, guiLastY;
209 +static unsigned int guiLastInvPressure;
211 +struct TouchScreenSample
216 + int currentPressure;
217 + struct timeval currentTime;
221 + * This must match the structure in tslib.
226 + unsigned int pressure;
230 +static struct TouchScreenSample gSample;
231 +static int bFreshTouchData;
232 +static int bCurrentPenDown;
234 +static DECLARE_WAIT_QUEUE_HEAD(queue);
235 +static DEFINE_SEMAPHORE(open_sem);
236 +static DEFINE_SPINLOCK(event_buffer_lock);
237 +static struct fasync_struct *ep93xx_fasync;
240 + * Typedef Declarations
243 + TS_MODE_UN_INITIALIZED,
244 + TS_MODE_HARDWARE_SCAN,
248 +static ts_mode_t gScanningMode;
251 + TS_STATE_STOPPED = 0,
268 +static ts_struct_t sTouch;
271 + * From the spec, here's how to set up the touch screen's switch registers.
275 + unsigned int uiDetect;
276 + unsigned int uiDischarge;
277 + unsigned int uiXSample;
278 + unsigned int uiYSample;
279 + unsigned int uiSwitchZ1;
280 + unsigned int uiSwitchZ2;
284 + * Here's the switch settings for a 4-wire touchscreen. See the spec
285 + * for how to handle a 4, 7, or 8-wire.
287 +const static SwitchStructType sSwitchSettings =
289 +/* TSDetect TSDischarge TSXSample TSYSample SwitchZ1 SwitchZ2 */
290 + {0x00403604, 0x0007fe04, 0x00081604, 0x00104601, 0x00101601, 0x00101608};
293 + * Function declarations
295 +static void ep93xx_ts_set_direct(unsigned int uiADCSwitch);
296 +static irqreturn_t ep93xx_ts_isr(int irq, void *dev_id);
297 +static irqreturn_t ep93xx_timer2_isr(int irq, void *dev_id);
298 +static void ee93xx_ts_evt_add(int button, int dX, int dY, int Pressure);
299 +static ssize_t ep93xx_ts_read(struct file *filp, char *buf,
300 + size_t count, loff_t *l);
301 +static unsigned int ep93xx_ts_poll(struct file *filp, poll_table *wait);
302 +static int ep93xx_ts_open(struct inode *inode, struct file *filp);
303 +static int ep93xx_ts_fasync(int fd, struct file *filp, int on);
304 +static int ep93xx_ts_release(struct inode *inode, struct file *filp);
305 +static ssize_t ep93xx_ts_write(struct file *file, const char *buffer,
306 + size_t count, loff_t *ppos);
307 +static void ep93xx_ts_setup(void);
308 +static void ep93xx_ts_shutdown(void);
309 +int __init ep93xx_ts_init(void);
310 +void __exit ep93xx_ts_exit(void);
311 +static unsigned int CalculateInvPressure(void);
312 +static unsigned int ADCGetData(unsigned int uiSamples, unsigned int uiMaxDiff);
313 +static void TS_Soft_Scan_Mode(void);
314 +static void TS_Hardware_Scan_Mode(void);
315 +static void ProcessPointData(void);
316 +static void Set_Timer2_uSec(unsigned int Delay_mSec);
317 +static void Stop_Timer2(void);
322 +static irqreturn_t ep93xx_ts_isr(int irq, void *dev_id)
325 + * Note that we don't clear the interrupt here. The interrupt
326 + * gets cleared in TS_Soft_Scan_Mode when the TS ENABLE
331 + * Set the ts to manual polling mode and schedule a callback.
332 + * That way we can return from the isr in a reasonable amount of
333 + * time and process the touch in the callback after a brief delay.
335 + TS_Soft_Scan_Mode();
337 + return(IRQ_HANDLED);
341 + * Save the current ts 'event' in an atomic fashion.
343 +static void ee93xx_ts_evt_add(int buttons, int iX, int iY, int iPressure)
346 + * Note the event, but use spinlocks to keep it from getting
347 + * halfway read if we get interrupted.
350 + spin_lock(&event_buffer_lock);
352 + gSample.currentX = iX;
353 + gSample.currentY = iY;
354 + gSample.currentButton = buttons;
355 + gSample.currentPressure = iPressure;
356 + bFreshTouchData = 1;
357 + do_gettimeofday(&gSample.currentTime);
359 + spin_unlock(&event_buffer_lock);
361 + kill_fasync(&ep93xx_fasync, SIGIO, POLL_IN);
362 + wake_up_interruptible(&queue);
366 +static ssize_t ep93xx_ts_read(struct file *filp, char *buf, size_t count, loff_t *l)
368 + unsigned short data[3];
369 + struct ts_sample ts_data;
370 + int iReturn = -EFAULT;
372 + if (!bFreshTouchData)
376 + else if (count == sizeof(data))
378 + spin_lock_irq(&event_buffer_lock);
379 + bFreshTouchData = 0;
380 + data[0] = gSample.currentX;
381 + data[1] = gSample.currentY;
382 + data[2] = gSample.currentButton;
384 + spin_unlock_irq(&event_buffer_lock);
386 + if (copy_to_user(buf, data, sizeof data))
389 + count -= sizeof(data);
391 + /* return the # of bytes that got read */
392 + iReturn = sizeof(data) ;
394 + else if (count == sizeof(struct ts_sample) )
396 + spin_lock_irq(&event_buffer_lock);
397 + bFreshTouchData = 0;
398 + ts_data.x = gSample.currentX;
399 + ts_data.y = gSample.currentY;
400 + ts_data.pressure = gSample.currentPressure;
401 + ts_data.tv = gSample.currentTime;
402 + spin_unlock_irq(&event_buffer_lock);
404 + if (copy_to_user(buf, &ts_data, sizeof(struct ts_sample)))
410 + count -= sizeof(ts_data);
411 + iReturn = sizeof(ts_data);
418 +static unsigned int ep93xx_ts_poll(struct file *filp, poll_table *wait)
420 + poll_wait(filp, &queue, wait);
422 + if (bFreshTouchData)
424 + return POLLIN | POLLRDNORM;
430 +static int ep93xx_ts_open(struct inode *inode, struct file *filp)
432 + if (down_trylock(&open_sem))
443 + * Asynchronous I/O support.
445 +static int ep93xx_ts_fasync(int fd, struct file *filp, int on)
449 + retval = fasync_helper(fd, filp, on, &ep93xx_fasync);
458 +static int ep93xx_ts_release(struct inode *inode, struct file *filp)
463 + * Call our async I/O support to request that this file
464 + * cease to be used for async I/O.
466 + ep93xx_ts_fasync(-1, filp, 0);
468 + ep93xx_ts_shutdown();
475 +static ssize_t ep93xx_ts_write(struct file *file, const char *buffer, size_t count,
482 +static int ep93xx_ts_ioctl(struct inode *inode, struct file *file, uint command, ulong u)
484 + static const int version = EV_VERSION;
485 + static const u_int32_t bit =(1 << EV_ABS);
486 + static const u_int32_t absbit = (1 << ABS_X) | (1 << ABS_Y) | (1 << ABS_PRESSURE);
492 + case EVIOCGVERSION:
493 + i = copy_to_user((void __user *)u, (void *)version, sizeof(version));
494 + iReturn = i ? -EFAULT : 0;
497 + case EVIOCGBIT(0,sizeof(u_int32_t) * 8) :
498 + i = copy_to_user((void __user *)u, (void *)bit, sizeof(bit));
499 + iReturn = i ? -EFAULT : 0;
502 + case EVIOCGBIT(EV_ABS, sizeof(absbit) * 8):
503 + i = copy_to_user((void __user *)u, (void *)absbit, sizeof(absbit));
504 + iReturn = i ? -EFAULT : 0;
514 +static struct file_operations ep93xx_ts_fops = {
515 + owner: THIS_MODULE,
516 + read: ep93xx_ts_read,
517 + write: ep93xx_ts_write,
518 + poll: ep93xx_ts_poll,
519 + open: ep93xx_ts_open,
520 + unlocked_ioctl: ep93xx_ts_ioctl,
521 + release: ep93xx_ts_release,
522 + fasync: ep93xx_ts_fasync,
525 +static struct miscdevice ep93xx_ts_miscdev =
532 +void ep93xx_ts_setup(void)
534 + unsigned int uiKTDIV, uiTSXYMaxMin;
537 + * Set the TSEN bit in KTDIV so that we are enabling the clock
538 + * for the touchscreen.
540 + uiKTDIV = __raw_readl(EP93XX_SYSCON_KEYTCHCLKDIV);
541 + uiKTDIV |= EP93XX_SYSCON_KEYTCHCLKDIV_TSEN;
542 + ep93xx_syscon_swlocked_write(uiKTDIV, EP93XX_SYSCON_KEYTCHCLKDIV);
545 + * Program the EP93XX_TOUCHSCREEN_SETUP and TSSetup2 registers.
547 + __raw_writel(TSSETUP_DEFAULT, EP93XX_TOUCHSCREEN_SETUP);
548 + __raw_writel(TSSETUP2_DEFAULT, EP93XX_TOUCHSCREEN_SETUP2);
551 + * Set the the touch settings.
553 + __raw_writel(0xaa, EP93XX_TOUCHSCREEN_SWLOCK);
554 + __raw_writel(sSwitchSettings.uiDischarge, EP93XX_TOUCHSCREEN_DIRECT);
556 + __raw_writel(0xaa, EP93XX_TOUCHSCREEN_SWLOCK);
557 + __raw_writel(sSwitchSettings.uiDischarge, EP93XX_TOUCHSCREEN_DISCHARGE);
559 + __raw_writel(0xaa, EP93XX_TOUCHSCREEN_SWLOCK);
560 + __raw_writel(sSwitchSettings.uiSwitchZ1, EP93XX_TOUCHSCREEN_XSAMPLE);
562 + __raw_writel(0xaa, EP93XX_TOUCHSCREEN_SWLOCK);
563 + __raw_writel(sSwitchSettings.uiSwitchZ2, EP93XX_TOUCHSCREEN_YSAMPLE);
565 + __raw_writel(0xaa, EP93XX_TOUCHSCREEN_SWLOCK);
566 + __raw_writel(sSwitchSettings.uiDetect, EP93XX_TOUCHSCREEN_DETECT);
569 + * X,YMin set to 0x40 = have to drag that many pixels for a new irq.
570 + * X,YMax set to 0x40 = 1024 pixels is the maximum movement within the
573 + uiTSXYMaxMin = (50 << TSMAXMIN_XMIN_SHIFT) & TSMAXMIN_XMIN_MASK;
574 + uiTSXYMaxMin |= (50 << TSMAXMIN_YMIN_SHIFT) & TSMAXMIN_YMIN_MASK;
575 + uiTSXYMaxMin |= (0xff << TSMAXMIN_XMAX_SHIFT) & TSMAXMIN_XMAX_MASK;
576 + uiTSXYMaxMin |= (0xff << TSMAXMIN_YMAX_SHIFT) & TSMAXMIN_YMAX_MASK;
577 + __raw_writel(uiTSXYMaxMin, EP93XX_TOUCHSCREEN_XYMAXMIN);
579 + bCurrentPenDown = 0;
580 + bFreshTouchData = 0;
583 + guiLastInvPressure = 0xffffff;
586 + * Enable the touch screen scanning engine.
588 + TS_Hardware_Scan_Mode();
592 + * ep93xx_ts_shutdown
596 +ep93xx_ts_shutdown(void)
598 + unsigned int uiKTDIV;
600 + sTouch.state = TS_STATE_STOPPED;
604 + * Disable the scanning engine.
606 + __raw_writel(0, EP93XX_TOUCHSCREEN_SETUP);
607 + __raw_writel(0, EP93XX_TOUCHSCREEN_SETUP2);
610 + * Clear the TSEN bit in KTDIV so that we are disabling the clock
611 + * for the touchscreen.
613 + uiKTDIV = __raw_readl(EP93XX_SYSCON_KEYTCHCLKDIV);
614 + uiKTDIV &= ~EP93XX_SYSCON_KEYTCHCLKDIV_TSEN;
615 + ep93xx_syscon_swlocked_write(uiKTDIV, EP93XX_SYSCON_KEYTCHCLKDIV);
617 +} /* ep93xx_ts_shutdown */
619 +static irqreturn_t ep93xx_timer2_isr(int irq, void *dev_id)
621 + switch(sTouch.state)
623 + case TS_STATE_STOPPED:
624 + TS_Hardware_Scan_Mode();
628 + * Get the Z1 value for pressure measurement and set up
629 + * the switch register for getting the Z2 measurement.
632 + Set_Timer2_uSec(EP93XX_TS_ADC_DELAY_USEC);
633 + sTouch.uiZ1 = ADCGetData(2, 200);
634 + ep93xx_ts_set_direct(sSwitchSettings.uiSwitchZ2);
635 + sTouch.state = TS_STATE_Z2;
639 + * Get the Z2 value for pressure measurement and set up
640 + * the switch register for getting the Y measurement.
643 + sTouch.uiZ2 = ADCGetData(2, 200);
644 + ep93xx_ts_set_direct(sSwitchSettings.uiYSample);
645 + sTouch.state = TS_STATE_Y;
649 + * Get the Y value and set up the switch register for
650 + * getting the X measurement.
653 + sTouch.uiY = ADCGetData(4, 20);
654 + ep93xx_ts_set_direct(sSwitchSettings.uiXSample);
655 + sTouch.state = TS_STATE_X;
659 + * Read the X value. This is the last of the 4 adc values
660 + * we need so we continue on to process the data.
665 + sTouch.uiX = ADCGetData(4, 20);
667 + __raw_writel(0xaa, EP93XX_TOUCHSCREEN_SWLOCK);
668 + __raw_writel(sSwitchSettings.uiDischarge, EP93XX_TOUCHSCREEN_DIRECT);
670 + sTouch.state = TS_STATE_DONE;
673 + * Process this set of ADC readings.
675 + ProcessPointData();
680 + * Shouldn't get here. But if we do, we can recover...
682 + case TS_STATE_DONE:
683 + TS_Hardware_Scan_Mode();
688 + * Clear the timer2 interrupt.
690 + __raw_writel(1, EP93XX_TIMER2_CLEAR);
691 + return(IRQ_HANDLED);
694 +/*---------------------------------------------------------------------
697 + * This routine processes the ADC data into usable point data and then
698 + * puts the driver into hw or sw scanning mode before returning.
700 + * We calculate inverse pressure (lower number = more pressure) then
701 + * do a hystheresis with the two pressure values 'light' and 'heavy'.
703 + * If we are above the light, we have pen up.
704 + * If we are below the heavy we have pen down.
705 + * As long as the pressure stays below the light, pen stays down.
706 + * When we get above the light again, pen goes back up.
709 +static void ProcessPointData(void)
711 + int bValidPoint = 0;
712 + unsigned int uiXDiff, uiYDiff, uiInvPressureDiff;
713 + unsigned int uiInvPressure;
716 + * Calculate the current pressure.
718 + uiInvPressure = CalculateInvPressure();
721 + * If pen pressure is so light that it is greater than the 'max' setting
722 + * then we consider this to be a pen up.
724 + if (uiInvPressure >= TS_LIGHT_INV_PRESSURE)
726 + bCurrentPenDown = 0;
727 + ee93xx_ts_evt_add(0, guiLastX, guiLastY, 0);
728 + TS_Hardware_Scan_Mode();
734 + * If the pen pressure is hard enough to be less than the 'min' OR
735 + * the pen is already down and is still less than the 'max'...
737 + if ((uiInvPressure < TS_HEAVY_INV_PRESSURE) ||
738 + (bCurrentPenDown && (uiInvPressure < TS_LIGHT_INV_PRESSURE)))
740 + if (bCurrentPenDown)
743 + * If pen was previously down, check the difference between
744 + * the last sample and this one... if the difference between
745 + * samples is too great, ignore the sample.
747 + uiXDiff = abs(guiLastX - sTouch.uiX);
748 + uiYDiff = abs(guiLastY - sTouch.uiY);
749 + uiInvPressureDiff = abs(guiLastInvPressure - uiInvPressure);
751 + if (uiXDiff < TS_MAX_VALID_XY_CHANGE
752 + && uiYDiff < TS_MAX_VALID_XY_CHANGE
753 + && uiInvPressureDiff < TS_MAX_VALID_PRESSURE_CHANGE)
764 + * If either the pen was put down or dragged make a note of it.
768 + guiLastX = sTouch.uiX;
769 + guiLastY = sTouch.uiY;
770 + guiLastInvPressure = uiInvPressure;
771 + bCurrentPenDown = 1;
772 + ee93xx_ts_evt_add(1, sTouch.uiX, sTouch.uiY,
773 + 0x7000000 / uiInvPressure);
776 + TS_Soft_Scan_Mode();
780 + TS_Hardware_Scan_Mode();
783 +static void ep93xx_ts_set_direct(unsigned int uiADCSwitch)
785 + unsigned int uiResult;
788 + * Set the switch settings in the direct register.
790 + __raw_writel(0xaa, EP93XX_TOUCHSCREEN_SWLOCK);
791 + __raw_writel(uiADCSwitch, EP93XX_TOUCHSCREEN_DIRECT);
794 + * Read and throw away the first sample.
797 + uiResult = __raw_readl(EP93XX_TOUCHSCREEN_XYRESULT);
798 + } while (!(uiResult & TSXYRESULT_SDR));
802 +static unsigned int ADCGetData(unsigned int uiSamples, unsigned int uiMaxDiff)
804 + unsigned int uiResult, uiValue, uiCount, uiLowest, uiHighest, uiSum, uiAve;
809 + * Initialize our values.
811 + uiLowest = 0xfffffff;
815 + for (uiCount = 0; uiCount < uiSamples; uiCount++)
818 + * Read the touch screen four more times and average.
821 + uiResult = __raw_readl(EP93XX_TOUCHSCREEN_XYRESULT);
822 + } while (!(uiResult & TSXYRESULT_SDR));
824 + uiValue = (uiResult & TSXYRESULT_AD_MASK) >> TSXYRESULT_AD_SHIFT;
825 + uiValue = ((uiValue >> 4) + ((1 + TSXYRESULT_X_MASK)>>1)) & TSXYRESULT_X_MASK;
828 + * Add up the values.
833 + * Get the lowest and highest values.
835 + if (uiValue < uiLowest)
837 + uiLowest = uiValue;
839 + if (uiValue > uiHighest)
841 + uiHighest = uiValue;
844 + } while ((uiHighest - uiLowest) > uiMaxDiff);
847 + * Calculate the Average value.
849 + uiAve = uiSum / uiSamples;
855 + * CalculateInvPressure
857 + * Is the Touch Valid. Touch is not valid if the X or Y value is not
858 + * in range and the pressure is not enough.
860 + * Touch resistance can be measured by the following formula:
863 + * Rtouch = --------- * (-- - 1)
866 + * This is simplified in the ration of Rtouch to Rx. The lower the value, the
867 + * higher the pressure.
870 + * InvPressure = X * (-- - 1)
873 +static unsigned int CalculateInvPressure(void)
875 + unsigned int uiInvPressure;
878 + * Check to see if the point is valid.
880 + if (sTouch.uiZ1 < MIN_Z1_VALUE)
882 + uiInvPressure = 0x10000;
886 + * Can omit the pressure calculation if you need to get rid of the division.
890 + uiInvPressure = ((sTouch.uiX * sTouch.uiZ2) / sTouch.uiZ1) - sTouch.uiX;
893 + return uiInvPressure;
897 + * TS_Hardware_Scan_Mode
899 + * Enables the ep93xx ts scanning engine so that when the pen goes down
900 + * we will get an interrupt.
902 +static void TS_Hardware_Scan_Mode(void)
904 + unsigned int uiDevCfg;
907 + * Disable the soft scanning engine.
909 + sTouch.state = TS_STATE_STOPPED;
913 + * Clear the TIN (Touchscreen INactive) bit so we can go to
914 + * automatic scanning mode.
916 + uiDevCfg = __raw_readl(EP93XX_SYSCON_DEVCFG);
917 + ep93xx_syscon_swlocked_write(uiDevCfg & ~EP93XX_SYSCON_DEVCFG_TIN,
918 + EP93XX_SYSCON_DEVCFG);
921 + * Enable the touch screen scanning state machine by setting
924 + __raw_writel(TSSETUP_DEFAULT | TSSETUP_ENABLE, EP93XX_TOUCHSCREEN_SETUP);
927 + * Set the flag to show that we are in interrupt mode.
929 + gScanningMode = TS_MODE_HARDWARE_SCAN;
932 + * Initialize EP93XX_TOUCHSCREEN_SETUP2 register.
934 + __raw_writel(TSSETUP2_DEFAULT, EP93XX_TOUCHSCREEN_SETUP2);
939 + * TS_Soft_Scan_Mode
941 + * Sets the touch screen to manual polling mode.
943 +static void TS_Soft_Scan_Mode(void)
945 + unsigned int uiDevCfg;
947 + if (gScanningMode != TS_MODE_SOFT_SCAN)
950 + * Disable the touch screen scanning state machine by clearing
953 + __raw_writel(TSSETUP_DEFAULT, EP93XX_TOUCHSCREEN_SETUP);
956 + * Set the TIN bit so we can do manual touchscreen polling.
958 + uiDevCfg = __raw_readl(EP93XX_SYSCON_DEVCFG);
959 + ep93xx_syscon_swlocked_write(uiDevCfg | EP93XX_SYSCON_DEVCFG_TIN,
960 + EP93XX_SYSCON_DEVCFG);
964 + * Set the switch register up for the first ADC reading
966 + ep93xx_ts_set_direct(sSwitchSettings.uiSwitchZ1);
969 + * Initialize our software state machine to know which ADC
972 + sTouch.state = TS_STATE_Z1;
975 + * Set the timer so after a mSec or two settling delay it will
976 + * take the first ADC reading.
978 + Set_Timer2_uSec(EP93XX_TS_PER_POINT_DELAY_USEC);
981 + * Note that we are in sw scanning mode not hw scanning mode.
983 + gScanningMode = TS_MODE_SOFT_SCAN;
987 +static void Set_Timer2_uSec(unsigned int uiDelay_uSec)
989 + unsigned int uiClockTicks;
994 + __raw_writel(0, EP93XX_TIMER2_CONTROL);
996 + uiClockTicks = ((uiDelay_uSec * 508) + 999) / 1000;
997 + __raw_writel(uiClockTicks, EP93XX_TIMER2_LOAD);
998 + __raw_writel(uiClockTicks, EP93XX_TIMER2_VALUE);
1001 + * Set up Timer 2 for 508 kHz clock and periodic mode.
1003 + __raw_writel(0xC8, EP93XX_TIMER2_CONTROL);
1007 +static void Stop_Timer2(void)
1009 + __raw_writel(0, EP93XX_TIMER2_CONTROL);
1013 + * Initialization and exit routines
1015 +int __init ep93xx_ts_init(void)
1019 + retval = request_irq(IRQ_EP93XX_TOUCH, ep93xx_ts_isr,
1020 + IRQF_DISABLED, "ep93xx_ts", 0);
1023 + printk(KERN_WARNING "ep93xx_ts: failed to get touchscreen IRQ\n");
1027 + retval = request_irq(IRQ_EP93XX_TIMER2, ep93xx_timer2_isr,
1028 + IRQF_DISABLED, "ep93xx_timer2", 0);
1031 + printk(KERN_WARNING "ep93xx_ts: failed to get timer2 IRQ\n");
1032 + free_irq(IRQ_EP93XX_TOUCH, 0);
1036 + misc_register(&ep93xx_ts_miscdev);
1038 + sTouch.state = TS_STATE_STOPPED;
1039 + gScanningMode = TS_MODE_UN_INITIALIZED;
1041 + printk(KERN_NOTICE "ep93xx touchscreen driver configured for 4-wire operation\n");
1046 +void __exit ep93xx_ts_exit(void)
1050 + free_irq(IRQ_EP93XX_TOUCH, 0);
1051 + free_irq(IRQ_EP93XX_TIMER2, 0);
1053 + misc_deregister(&ep93xx_ts_miscdev);
1056 +module_init(ep93xx_ts_init);
1057 +module_exit(ep93xx_ts_exit);
1059 +MODULE_DESCRIPTION("Cirrus EP93xx touchscreen driver");
1060 +MODULE_SUPPORTED_DEVICE("touchscreen/ep93xx");
1061 +MODULE_LICENSE("GPL");