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 @@ -235,6 +235,15 @@ config TOUCHSCREEN_EGALAX
13 To compile this driver as a module, choose M here: the
14 module will be called egalax_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 @@ -29,6 +29,7 @@ obj-$(CONFIG_TOUCHSCREEN_GUNZE) += gunz
31 obj-$(CONFIG_TOUCHSCREEN_EETI) += eeti_ts.o
32 obj-$(CONFIG_TOUCHSCREEN_ELO) += elo.o
33 obj-$(CONFIG_TOUCHSCREEN_EGALAX) += egalax_ts.o
34 +obj-$(CONFIG_TOUCHSCREEN_EP93XX) += ep93xx_ts.o
35 obj-$(CONFIG_TOUCHSCREEN_FUJITSU) += fujitsu_ts.o
36 obj-$(CONFIG_TOUCHSCREEN_ILI210X) += ili210x.o
37 obj-$(CONFIG_TOUCHSCREEN_INEXIO) += inexio.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>
69 +#include "../../../arch/arm/mach-ep93xx/soc.h"
71 +/* This stuff should be in ep93xx-regs.h */
72 +#define EP93XX_TOUCHSCREEN_REG(x) (EP93XX_TOUCHSCREEN_BASE + (x))
73 +/* R/W touchscreen controller setup control register. */
74 +#define EP93XX_TOUCHSCREEN_SETUP EP93XX_TOUCHSCREEN_REG(0x00)
75 +/* R/W touchscreen controller max/min register. */
76 +#define EP93XX_TOUCHSCREEN_XYMAXMIN EP93XX_TOUCHSCREEN_REG(0x04)
77 +/* R touchscreen controller result register. */
78 +#define EP93XX_TOUCHSCREEN_XYRESULT EP93XX_TOUCHSCREEN_REG(0x08)
79 +/* LOCKED R/W touchscreen Switch Matrix control register. */
80 +#define EP93XX_TOUCHSCREEN_DISCHARGE EP93XX_TOUCHSCREEN_REG(0x0C)
81 +#define EP93XX_TOUCHSCREEN_XSAMPLE EP93XX_TOUCHSCREEN_REG(0x10)
82 +#define EP93XX_TOUCHSCREEN_YSAMPLE EP93XX_TOUCHSCREEN_REG(0x14)
83 +#define EP93XX_TOUCHSCREEN_DIRECT EP93XX_TOUCHSCREEN_REG(0x18)
84 +#define EP93XX_TOUCHSCREEN_DETECT EP93XX_TOUCHSCREEN_REG(0x1C)
85 +/* NA R/W touchscreen software lock register. */
86 +#define EP93XX_TOUCHSCREEN_SWLOCK EP93XX_TOUCHSCREEN_REG(0x20)
87 +/* R/W touchscreen setup control register #2. */
88 +#define EP93XX_TOUCHSCREEN_SETUP2 EP93XX_TOUCHSCREEN_REG(0x24)
90 +/* These are duplicated in mach-ep93xx/core.c */
91 +#define EP93XX_TIMER_REG(x) (EP93XX_TIMER_BASE + (x))
92 +#define EP93XX_TIMER2_LOAD EP93XX_TIMER_REG(0x20)
93 +#define EP93XX_TIMER2_VALUE EP93XX_TIMER_REG(0x24)
94 +#define EP93XX_TIMER2_CONTROL EP93XX_TIMER_REG(0x28)
95 +#define EP93XX_TIMER2_CLEAR EP93XX_TIMER_REG(0x2c)
98 + * Register bit definitions
100 +#define TSSETUP_SDLY_MASK 0x000003FF
101 +#define TSSETUP_SDLY_SHIFT 0
102 +#define TSSETUP_NSMP_4 0x00000000
103 +#define TSSETUP_NSMP_8 0x00000400
104 +#define TSSETUP_NSMP_16 0x00000800
105 +#define TSSETUP_NSMP_32 0x00000C00
106 +#define TSSETUP_NSMP_MASK 0x00000C00
107 +#define TSSETUP_DEV_4 0x00000000
108 +#define TSSETUP_DEV_8 0x00001000
109 +#define TSSETUP_DEV_12 0x00002000
110 +#define TSSETUP_DEV_16 0x00003000
111 +#define TSSETUP_DEV_24 0x00004000
112 +#define TSSETUP_DEV_32 0x00005000
113 +#define TSSETUP_DEV_64 0x00006000
114 +#define TSSETUP_DEV_128 0x00007000
115 +#define TSSETUP_ENABLE 0x00008000
116 +#define TSSETUP_DLY_MASK 0x03FF0000
117 +#define TSSETUP_DLY_SHIFT 16
118 +#define TSSETUP_TDTCT 0x80000000
120 +#define TSMAXMIN_XMIN_MASK 0x000000FF
121 +#define TSMAXMIN_XMIN_SHIFT 0
122 +#define TSMAXMIN_YMIN_MASK 0x0000FF00
123 +#define TSMAXMIN_YMIN_SHIFT 8
124 +#define TSMAXMIN_XMAX_MASK 0x00FF0000
125 +#define TSMAXMIN_XMAX_SHIFT 16
126 +#define TSMAXMIN_YMAX_MASK 0xFF000000
127 +#define TSMAXMIN_YMAX_SHIFT 24
129 +#define TSXYRESULT_X_MASK 0x00000FFF
130 +#define TSXYRESULT_X_SHIFT 0
131 +#define TSXYRESULT_AD_MASK 0x0000FFFF
132 +#define TSXYRESULT_AD_SHIFT 0
133 +#define TSXYRESULT_Y_MASK 0x0FFF0000
134 +#define TSXYRESULT_Y_SHIFT 16
135 +#define TSXYRESULT_SDR 0x80000000
137 +#define TSX_SAMPLE_MASK 0x00003FFF
138 +#define TSX_SAMPLE_SHIFT 0x00
139 +#define TSY_SAMPLE_MASK 0x3FFF0000
140 +#define TSY_SAMPLE_SHIFT 0x10
142 +#define TSSETUP2_TINT 0x00000001
143 +#define TSSETUP2_NICOR 0x00000002
144 +#define TSSETUP2_PINT 0x00000004
145 +#define TSSETUP2_PENSTS 0x00000008
146 +#define TSSETUP2_PINTEN 0x00000010
147 +#define TSSETUP2_DEVINT 0x00000020
148 +#define TSSETUP2_DINTEN 0x00000040
149 +#define TSSETUP2_DTMEN 0x00000080
150 +#define TSSETUP2_DISDEV 0x00000100
151 +#define TSSETUP2_NSIGND 0x00000200
152 +#define TSSETUP2_S28EN 0x00000400
153 +#define TSSETUP2_RINTEN 0x00000800
155 +#define TSXYRESULT_SDR 0x80000000
158 + * These are used as trigger levels to know when we have pen up/down.
160 + * 1. TS_HEAVY_INV_PRESSURE < TS_LIGHT_INV_PRESSURE because these
161 + * are Inverse pressure.
162 + * 2. Any touch lighter than TS_LIGHT_INV_PRESSURE is a pen up.
163 + * 3. Any touch heavier than TS_HEAVY_INV_PRESSURE is a pen down.
165 +#define TS_HEAVY_INV_PRESSURE 0xFE0 /* C00 */
166 +#define TS_LIGHT_INV_PRESSURE 0xFFF /* e00 */
169 + * If the x, y, or inverse pressure changes more than these values
170 + * between two succeeding points, the point is not reported.
172 +#define TS_MAX_VALID_XY_CHANGE 0x300
173 +#define TS_MAX_VALID_PRESSURE_CHANGE 0x100
176 + * This is the minimum Z1 Value that is valid.
178 +#define MIN_Z1_VALUE 0x50
181 + * Settling delay for taking each ADC measurement. Increase this
182 + * if ts is jittery.
184 +#define EP93XX_TS_ADC_DELAY_USEC 2000
187 + * Delay between TS points.
189 +#define EP93XX_TS_PER_POINT_DELAY_USEC 10000
192 + * A few more macros...
194 +#define TSSETUP_DEFAULT (TSSETUP_NSMP_32 | TSSETUP_DEV_64 | \
195 + ((128<<TSSETUP_SDLY_SHIFT) & TSSETUP_SDLY_MASK) | \
196 + ((128<<TSSETUP_DLY_SHIFT) & TSSETUP_DLY_MASK))
198 +#define TSSETUP2_DEFAULT (TSSETUP2_NSIGND)
201 + * For now, we use one of the minor numbers from the local/experimental
204 +#define EP93XX_TS_MINOR 240
207 + * Static Declarations
209 +static unsigned int guiLastX, guiLastY;
210 +static unsigned int guiLastInvPressure;
212 +struct TouchScreenSample
217 + int currentPressure;
218 + struct timeval currentTime;
222 + * This must match the structure in tslib.
227 + unsigned int pressure;
231 +static struct TouchScreenSample gSample;
232 +static int bFreshTouchData;
233 +static int bCurrentPenDown;
235 +static DECLARE_WAIT_QUEUE_HEAD(queue);
236 +static DEFINE_SEMAPHORE(open_sem);
237 +static DEFINE_SPINLOCK(event_buffer_lock);
238 +static struct fasync_struct *ep93xx_fasync;
241 + * Typedef Declarations
244 + TS_MODE_UN_INITIALIZED,
245 + TS_MODE_HARDWARE_SCAN,
249 +static ts_mode_t gScanningMode;
252 + TS_STATE_STOPPED = 0,
269 +static ts_struct_t sTouch;
272 + * From the spec, here's how to set up the touch screen's switch registers.
276 + unsigned int uiDetect;
277 + unsigned int uiDischarge;
278 + unsigned int uiXSample;
279 + unsigned int uiYSample;
280 + unsigned int uiSwitchZ1;
281 + unsigned int uiSwitchZ2;
285 + * Here's the switch settings for a 4-wire touchscreen. See the spec
286 + * for how to handle a 4, 7, or 8-wire.
288 +const static SwitchStructType sSwitchSettings =
290 +/* TSDetect TSDischarge TSXSample TSYSample SwitchZ1 SwitchZ2 */
291 + {0x00403604, 0x0007fe04, 0x00081604, 0x00104601, 0x00101601, 0x00101608};
294 + * Function declarations
296 +static void ep93xx_ts_set_direct(unsigned int uiADCSwitch);
297 +static irqreturn_t ep93xx_ts_isr(int irq, void *dev_id);
298 +static irqreturn_t ep93xx_timer2_isr(int irq, void *dev_id);
299 +static void ee93xx_ts_evt_add(int button, int dX, int dY, int Pressure);
300 +static ssize_t ep93xx_ts_read(struct file *filp, char *buf,
301 + size_t count, loff_t *l);
302 +static unsigned int ep93xx_ts_poll(struct file *filp, poll_table *wait);
303 +static int ep93xx_ts_open(struct inode *inode, struct file *filp);
304 +static int ep93xx_ts_fasync(int fd, struct file *filp, int on);
305 +static int ep93xx_ts_release(struct inode *inode, struct file *filp);
306 +static ssize_t ep93xx_ts_write(struct file *file, const char *buffer,
307 + size_t count, loff_t *ppos);
308 +static void ep93xx_ts_setup(void);
309 +static void ep93xx_ts_shutdown(void);
310 +int __init ep93xx_ts_init(void);
311 +void __exit ep93xx_ts_exit(void);
312 +static unsigned int CalculateInvPressure(void);
313 +static unsigned int ADCGetData(unsigned int uiSamples, unsigned int uiMaxDiff);
314 +static void TS_Soft_Scan_Mode(void);
315 +static void TS_Hardware_Scan_Mode(void);
316 +static void ProcessPointData(void);
317 +static void Set_Timer2_uSec(unsigned int Delay_mSec);
318 +static void Stop_Timer2(void);
323 +static irqreturn_t ep93xx_ts_isr(int irq, void *dev_id)
326 + * Note that we don't clear the interrupt here. The interrupt
327 + * gets cleared in TS_Soft_Scan_Mode when the TS ENABLE
332 + * Set the ts to manual polling mode and schedule a callback.
333 + * That way we can return from the isr in a reasonable amount of
334 + * time and process the touch in the callback after a brief delay.
336 + TS_Soft_Scan_Mode();
338 + return(IRQ_HANDLED);
342 + * Save the current ts 'event' in an atomic fashion.
344 +static void ee93xx_ts_evt_add(int buttons, int iX, int iY, int iPressure)
347 + * Note the event, but use spinlocks to keep it from getting
348 + * halfway read if we get interrupted.
351 + spin_lock(&event_buffer_lock);
353 + gSample.currentX = iX;
354 + gSample.currentY = iY;
355 + gSample.currentButton = buttons;
356 + gSample.currentPressure = iPressure;
357 + bFreshTouchData = 1;
358 + do_gettimeofday(&gSample.currentTime);
360 + spin_unlock(&event_buffer_lock);
362 + kill_fasync(&ep93xx_fasync, SIGIO, POLL_IN);
363 + wake_up_interruptible(&queue);
367 +static ssize_t ep93xx_ts_read(struct file *filp, char *buf, size_t count, loff_t *l)
369 + unsigned short data[3];
370 + struct ts_sample ts_data;
371 + int iReturn = -EFAULT;
373 + if (!bFreshTouchData)
377 + else if (count == sizeof(data))
379 + spin_lock_irq(&event_buffer_lock);
380 + bFreshTouchData = 0;
381 + data[0] = gSample.currentX;
382 + data[1] = gSample.currentY;
383 + data[2] = gSample.currentButton;
385 + spin_unlock_irq(&event_buffer_lock);
387 + if (copy_to_user(buf, data, sizeof data))
390 + count -= sizeof(data);
392 + /* return the # of bytes that got read */
393 + iReturn = sizeof(data) ;
395 + else if (count == sizeof(struct ts_sample) )
397 + spin_lock_irq(&event_buffer_lock);
398 + bFreshTouchData = 0;
399 + ts_data.x = gSample.currentX;
400 + ts_data.y = gSample.currentY;
401 + ts_data.pressure = gSample.currentPressure;
402 + ts_data.tv = gSample.currentTime;
403 + spin_unlock_irq(&event_buffer_lock);
405 + if (copy_to_user(buf, &ts_data, sizeof(struct ts_sample)))
411 + count -= sizeof(ts_data);
412 + iReturn = sizeof(ts_data);
419 +static unsigned int ep93xx_ts_poll(struct file *filp, poll_table *wait)
421 + poll_wait(filp, &queue, wait);
423 + if (bFreshTouchData)
425 + return POLLIN | POLLRDNORM;
431 +static int ep93xx_ts_open(struct inode *inode, struct file *filp)
433 + if (down_trylock(&open_sem))
444 + * Asynchronous I/O support.
446 +static int ep93xx_ts_fasync(int fd, struct file *filp, int on)
450 + retval = fasync_helper(fd, filp, on, &ep93xx_fasync);
459 +static int ep93xx_ts_release(struct inode *inode, struct file *filp)
464 + * Call our async I/O support to request that this file
465 + * cease to be used for async I/O.
467 + ep93xx_ts_fasync(-1, filp, 0);
469 + ep93xx_ts_shutdown();
476 +static ssize_t ep93xx_ts_write(struct file *file, const char *buffer, size_t count,
483 +static int ep93xx_ts_ioctl(struct inode *inode, struct file *file, uint command, ulong u)
485 + static const int version = EV_VERSION;
486 + static const u_int32_t bit =(1 << EV_ABS);
487 + static const u_int32_t absbit = (1 << ABS_X) | (1 << ABS_Y) | (1 << ABS_PRESSURE);
493 + case EVIOCGVERSION:
494 + i = copy_to_user((void __user *)u, (void *)version, sizeof(version));
495 + iReturn = i ? -EFAULT : 0;
498 + case EVIOCGBIT(0,sizeof(u_int32_t) * 8) :
499 + i = copy_to_user((void __user *)u, (void *)bit, sizeof(bit));
500 + iReturn = i ? -EFAULT : 0;
503 + case EVIOCGBIT(EV_ABS, sizeof(absbit) * 8):
504 + i = copy_to_user((void __user *)u, (void *)absbit, sizeof(absbit));
505 + iReturn = i ? -EFAULT : 0;
515 +static struct file_operations ep93xx_ts_fops = {
516 + owner: THIS_MODULE,
517 + read: ep93xx_ts_read,
518 + write: ep93xx_ts_write,
519 + poll: ep93xx_ts_poll,
520 + open: ep93xx_ts_open,
521 + unlocked_ioctl: ep93xx_ts_ioctl,
522 + release: ep93xx_ts_release,
523 + fasync: ep93xx_ts_fasync,
526 +static struct miscdevice ep93xx_ts_miscdev =
533 +void ep93xx_ts_setup(void)
535 + unsigned int uiKTDIV, uiTSXYMaxMin;
538 + * Set the TSEN bit in KTDIV so that we are enabling the clock
539 + * for the touchscreen.
541 + uiKTDIV = __raw_readl(EP93XX_SYSCON_KEYTCHCLKDIV);
542 + uiKTDIV |= EP93XX_SYSCON_KEYTCHCLKDIV_TSEN;
543 + ep93xx_syscon_swlocked_write(uiKTDIV, EP93XX_SYSCON_KEYTCHCLKDIV);
546 + * Program the EP93XX_TOUCHSCREEN_SETUP and TSSetup2 registers.
548 + __raw_writel(TSSETUP_DEFAULT, EP93XX_TOUCHSCREEN_SETUP);
549 + __raw_writel(TSSETUP2_DEFAULT, EP93XX_TOUCHSCREEN_SETUP2);
552 + * Set the the touch settings.
554 + __raw_writel(0xaa, EP93XX_TOUCHSCREEN_SWLOCK);
555 + __raw_writel(sSwitchSettings.uiDischarge, EP93XX_TOUCHSCREEN_DIRECT);
557 + __raw_writel(0xaa, EP93XX_TOUCHSCREEN_SWLOCK);
558 + __raw_writel(sSwitchSettings.uiDischarge, EP93XX_TOUCHSCREEN_DISCHARGE);
560 + __raw_writel(0xaa, EP93XX_TOUCHSCREEN_SWLOCK);
561 + __raw_writel(sSwitchSettings.uiSwitchZ1, EP93XX_TOUCHSCREEN_XSAMPLE);
563 + __raw_writel(0xaa, EP93XX_TOUCHSCREEN_SWLOCK);
564 + __raw_writel(sSwitchSettings.uiSwitchZ2, EP93XX_TOUCHSCREEN_YSAMPLE);
566 + __raw_writel(0xaa, EP93XX_TOUCHSCREEN_SWLOCK);
567 + __raw_writel(sSwitchSettings.uiDetect, EP93XX_TOUCHSCREEN_DETECT);
570 + * X,YMin set to 0x40 = have to drag that many pixels for a new irq.
571 + * X,YMax set to 0x40 = 1024 pixels is the maximum movement within the
574 + uiTSXYMaxMin = (50 << TSMAXMIN_XMIN_SHIFT) & TSMAXMIN_XMIN_MASK;
575 + uiTSXYMaxMin |= (50 << TSMAXMIN_YMIN_SHIFT) & TSMAXMIN_YMIN_MASK;
576 + uiTSXYMaxMin |= (0xff << TSMAXMIN_XMAX_SHIFT) & TSMAXMIN_XMAX_MASK;
577 + uiTSXYMaxMin |= (0xff << TSMAXMIN_YMAX_SHIFT) & TSMAXMIN_YMAX_MASK;
578 + __raw_writel(uiTSXYMaxMin, EP93XX_TOUCHSCREEN_XYMAXMIN);
580 + bCurrentPenDown = 0;
581 + bFreshTouchData = 0;
584 + guiLastInvPressure = 0xffffff;
587 + * Enable the touch screen scanning engine.
589 + TS_Hardware_Scan_Mode();
593 + * ep93xx_ts_shutdown
597 +ep93xx_ts_shutdown(void)
599 + unsigned int uiKTDIV;
601 + sTouch.state = TS_STATE_STOPPED;
605 + * Disable the scanning engine.
607 + __raw_writel(0, EP93XX_TOUCHSCREEN_SETUP);
608 + __raw_writel(0, EP93XX_TOUCHSCREEN_SETUP2);
611 + * Clear the TSEN bit in KTDIV so that we are disabling the clock
612 + * for the touchscreen.
614 + uiKTDIV = __raw_readl(EP93XX_SYSCON_KEYTCHCLKDIV);
615 + uiKTDIV &= ~EP93XX_SYSCON_KEYTCHCLKDIV_TSEN;
616 + ep93xx_syscon_swlocked_write(uiKTDIV, EP93XX_SYSCON_KEYTCHCLKDIV);
618 +} /* ep93xx_ts_shutdown */
620 +static irqreturn_t ep93xx_timer2_isr(int irq, void *dev_id)
622 + switch(sTouch.state)
624 + case TS_STATE_STOPPED:
625 + TS_Hardware_Scan_Mode();
629 + * Get the Z1 value for pressure measurement and set up
630 + * the switch register for getting the Z2 measurement.
633 + Set_Timer2_uSec(EP93XX_TS_ADC_DELAY_USEC);
634 + sTouch.uiZ1 = ADCGetData(2, 200);
635 + ep93xx_ts_set_direct(sSwitchSettings.uiSwitchZ2);
636 + sTouch.state = TS_STATE_Z2;
640 + * Get the Z2 value for pressure measurement and set up
641 + * the switch register for getting the Y measurement.
644 + sTouch.uiZ2 = ADCGetData(2, 200);
645 + ep93xx_ts_set_direct(sSwitchSettings.uiYSample);
646 + sTouch.state = TS_STATE_Y;
650 + * Get the Y value and set up the switch register for
651 + * getting the X measurement.
654 + sTouch.uiY = ADCGetData(4, 20);
655 + ep93xx_ts_set_direct(sSwitchSettings.uiXSample);
656 + sTouch.state = TS_STATE_X;
660 + * Read the X value. This is the last of the 4 adc values
661 + * we need so we continue on to process the data.
666 + sTouch.uiX = ADCGetData(4, 20);
668 + __raw_writel(0xaa, EP93XX_TOUCHSCREEN_SWLOCK);
669 + __raw_writel(sSwitchSettings.uiDischarge, EP93XX_TOUCHSCREEN_DIRECT);
671 + sTouch.state = TS_STATE_DONE;
674 + * Process this set of ADC readings.
676 + ProcessPointData();
681 + * Shouldn't get here. But if we do, we can recover...
683 + case TS_STATE_DONE:
684 + TS_Hardware_Scan_Mode();
689 + * Clear the timer2 interrupt.
691 + __raw_writel(1, EP93XX_TIMER2_CLEAR);
692 + return(IRQ_HANDLED);
695 +/*---------------------------------------------------------------------
698 + * This routine processes the ADC data into usable point data and then
699 + * puts the driver into hw or sw scanning mode before returning.
701 + * We calculate inverse pressure (lower number = more pressure) then
702 + * do a hystheresis with the two pressure values 'light' and 'heavy'.
704 + * If we are above the light, we have pen up.
705 + * If we are below the heavy we have pen down.
706 + * As long as the pressure stays below the light, pen stays down.
707 + * When we get above the light again, pen goes back up.
710 +static void ProcessPointData(void)
712 + int bValidPoint = 0;
713 + unsigned int uiXDiff, uiYDiff, uiInvPressureDiff;
714 + unsigned int uiInvPressure;
717 + * Calculate the current pressure.
719 + uiInvPressure = CalculateInvPressure();
722 + * If pen pressure is so light that it is greater than the 'max' setting
723 + * then we consider this to be a pen up.
725 + if (uiInvPressure >= TS_LIGHT_INV_PRESSURE)
727 + bCurrentPenDown = 0;
728 + ee93xx_ts_evt_add(0, guiLastX, guiLastY, 0);
729 + TS_Hardware_Scan_Mode();
735 + * If the pen pressure is hard enough to be less than the 'min' OR
736 + * the pen is already down and is still less than the 'max'...
738 + if ((uiInvPressure < TS_HEAVY_INV_PRESSURE) ||
739 + (bCurrentPenDown && (uiInvPressure < TS_LIGHT_INV_PRESSURE)))
741 + if (bCurrentPenDown)
744 + * If pen was previously down, check the difference between
745 + * the last sample and this one... if the difference between
746 + * samples is too great, ignore the sample.
748 + uiXDiff = abs(guiLastX - sTouch.uiX);
749 + uiYDiff = abs(guiLastY - sTouch.uiY);
750 + uiInvPressureDiff = abs(guiLastInvPressure - uiInvPressure);
752 + if (uiXDiff < TS_MAX_VALID_XY_CHANGE
753 + && uiYDiff < TS_MAX_VALID_XY_CHANGE
754 + && uiInvPressureDiff < TS_MAX_VALID_PRESSURE_CHANGE)
765 + * If either the pen was put down or dragged make a note of it.
769 + guiLastX = sTouch.uiX;
770 + guiLastY = sTouch.uiY;
771 + guiLastInvPressure = uiInvPressure;
772 + bCurrentPenDown = 1;
773 + ee93xx_ts_evt_add(1, sTouch.uiX, sTouch.uiY,
774 + 0x7000000 / uiInvPressure);
777 + TS_Soft_Scan_Mode();
781 + TS_Hardware_Scan_Mode();
784 +static void ep93xx_ts_set_direct(unsigned int uiADCSwitch)
786 + unsigned int uiResult;
789 + * Set the switch settings in the direct register.
791 + __raw_writel(0xaa, EP93XX_TOUCHSCREEN_SWLOCK);
792 + __raw_writel(uiADCSwitch, EP93XX_TOUCHSCREEN_DIRECT);
795 + * Read and throw away the first sample.
798 + uiResult = __raw_readl(EP93XX_TOUCHSCREEN_XYRESULT);
799 + } while (!(uiResult & TSXYRESULT_SDR));
803 +static unsigned int ADCGetData(unsigned int uiSamples, unsigned int uiMaxDiff)
805 + unsigned int uiResult, uiValue, uiCount, uiLowest, uiHighest, uiSum, uiAve;
810 + * Initialize our values.
812 + uiLowest = 0xfffffff;
816 + for (uiCount = 0; uiCount < uiSamples; uiCount++)
819 + * Read the touch screen four more times and average.
822 + uiResult = __raw_readl(EP93XX_TOUCHSCREEN_XYRESULT);
823 + } while (!(uiResult & TSXYRESULT_SDR));
825 + uiValue = (uiResult & TSXYRESULT_AD_MASK) >> TSXYRESULT_AD_SHIFT;
826 + uiValue = ((uiValue >> 4) + ((1 + TSXYRESULT_X_MASK)>>1)) & TSXYRESULT_X_MASK;
829 + * Add up the values.
834 + * Get the lowest and highest values.
836 + if (uiValue < uiLowest)
838 + uiLowest = uiValue;
840 + if (uiValue > uiHighest)
842 + uiHighest = uiValue;
845 + } while ((uiHighest - uiLowest) > uiMaxDiff);
848 + * Calculate the Average value.
850 + uiAve = uiSum / uiSamples;
856 + * CalculateInvPressure
858 + * Is the Touch Valid. Touch is not valid if the X or Y value is not
859 + * in range and the pressure is not enough.
861 + * Touch resistance can be measured by the following formula:
864 + * Rtouch = --------- * (-- - 1)
867 + * This is simplified in the ration of Rtouch to Rx. The lower the value, the
868 + * higher the pressure.
871 + * InvPressure = X * (-- - 1)
874 +static unsigned int CalculateInvPressure(void)
876 + unsigned int uiInvPressure;
879 + * Check to see if the point is valid.
881 + if (sTouch.uiZ1 < MIN_Z1_VALUE)
883 + uiInvPressure = 0x10000;
887 + * Can omit the pressure calculation if you need to get rid of the division.
891 + uiInvPressure = ((sTouch.uiX * sTouch.uiZ2) / sTouch.uiZ1) - sTouch.uiX;
894 + return uiInvPressure;
898 + * TS_Hardware_Scan_Mode
900 + * Enables the ep93xx ts scanning engine so that when the pen goes down
901 + * we will get an interrupt.
903 +static void TS_Hardware_Scan_Mode(void)
905 + unsigned int uiDevCfg;
908 + * Disable the soft scanning engine.
910 + sTouch.state = TS_STATE_STOPPED;
914 + * Clear the TIN (Touchscreen INactive) bit so we can go to
915 + * automatic scanning mode.
917 + uiDevCfg = __raw_readl(EP93XX_SYSCON_DEVCFG);
918 + ep93xx_syscon_swlocked_write(uiDevCfg & ~EP93XX_SYSCON_DEVCFG_TIN,
919 + EP93XX_SYSCON_DEVCFG);
922 + * Enable the touch screen scanning state machine by setting
925 + __raw_writel(TSSETUP_DEFAULT | TSSETUP_ENABLE, EP93XX_TOUCHSCREEN_SETUP);
928 + * Set the flag to show that we are in interrupt mode.
930 + gScanningMode = TS_MODE_HARDWARE_SCAN;
933 + * Initialize EP93XX_TOUCHSCREEN_SETUP2 register.
935 + __raw_writel(TSSETUP2_DEFAULT, EP93XX_TOUCHSCREEN_SETUP2);
940 + * TS_Soft_Scan_Mode
942 + * Sets the touch screen to manual polling mode.
944 +static void TS_Soft_Scan_Mode(void)
946 + unsigned int uiDevCfg;
948 + if (gScanningMode != TS_MODE_SOFT_SCAN)
951 + * Disable the touch screen scanning state machine by clearing
954 + __raw_writel(TSSETUP_DEFAULT, EP93XX_TOUCHSCREEN_SETUP);
957 + * Set the TIN bit so we can do manual touchscreen polling.
959 + uiDevCfg = __raw_readl(EP93XX_SYSCON_DEVCFG);
960 + ep93xx_syscon_swlocked_write(uiDevCfg | EP93XX_SYSCON_DEVCFG_TIN,
961 + EP93XX_SYSCON_DEVCFG);
965 + * Set the switch register up for the first ADC reading
967 + ep93xx_ts_set_direct(sSwitchSettings.uiSwitchZ1);
970 + * Initialize our software state machine to know which ADC
973 + sTouch.state = TS_STATE_Z1;
976 + * Set the timer so after a mSec or two settling delay it will
977 + * take the first ADC reading.
979 + Set_Timer2_uSec(EP93XX_TS_PER_POINT_DELAY_USEC);
982 + * Note that we are in sw scanning mode not hw scanning mode.
984 + gScanningMode = TS_MODE_SOFT_SCAN;
988 +static void Set_Timer2_uSec(unsigned int uiDelay_uSec)
990 + unsigned int uiClockTicks;
995 + __raw_writel(0, EP93XX_TIMER2_CONTROL);
997 + uiClockTicks = ((uiDelay_uSec * 508) + 999) / 1000;
998 + __raw_writel(uiClockTicks, EP93XX_TIMER2_LOAD);
999 + __raw_writel(uiClockTicks, EP93XX_TIMER2_VALUE);
1002 + * Set up Timer 2 for 508 kHz clock and periodic mode.
1004 + __raw_writel(0xC8, EP93XX_TIMER2_CONTROL);
1008 +static void Stop_Timer2(void)
1010 + __raw_writel(0, EP93XX_TIMER2_CONTROL);
1014 + * Initialization and exit routines
1016 +int __init ep93xx_ts_init(void)
1020 + retval = request_irq(IRQ_EP93XX_TOUCH, ep93xx_ts_isr,
1021 + IRQF_DISABLED, "ep93xx_ts", 0);
1024 + printk(KERN_WARNING "ep93xx_ts: failed to get touchscreen IRQ\n");
1028 + retval = request_irq(IRQ_EP93XX_TIMER2, ep93xx_timer2_isr,
1029 + IRQF_DISABLED, "ep93xx_timer2", 0);
1032 + printk(KERN_WARNING "ep93xx_ts: failed to get timer2 IRQ\n");
1033 + free_irq(IRQ_EP93XX_TOUCH, 0);
1037 + misc_register(&ep93xx_ts_miscdev);
1039 + sTouch.state = TS_STATE_STOPPED;
1040 + gScanningMode = TS_MODE_UN_INITIALIZED;
1042 + printk(KERN_NOTICE "ep93xx touchscreen driver configured for 4-wire operation\n");
1047 +void __exit ep93xx_ts_exit(void)
1051 + free_irq(IRQ_EP93XX_TOUCH, 0);
1052 + free_irq(IRQ_EP93XX_TIMER2, 0);
1054 + misc_deregister(&ep93xx_ts_miscdev);
1057 +module_init(ep93xx_ts_init);
1058 +module_exit(ep93xx_ts_exit);
1060 +MODULE_DESCRIPTION("Cirrus EP93xx touchscreen driver");
1061 +MODULE_SUPPORTED_DEVICE("touchscreen/ep93xx");
1062 +MODULE_LICENSE("GPL");
1063 --- a/arch/arm/mach-ep93xx/core.c
1064 +++ b/arch/arm/mach-ep93xx/core.c
1065 @@ -205,6 +205,7 @@ void ep93xx_syscon_swlocked_write(unsign
1067 spin_unlock_irqrestore(&syscon_swlock, flags);
1069 +EXPORT_SYMBOL(ep93xx_syscon_swlocked_write);
1071 void ep93xx_devcfg_set_clear(unsigned int set_bits, unsigned int clear_bits)