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 @@ -153,6 +153,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 @@ -21,6 +21,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_MC13783) += mc13783_ts.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>
66 +#include <mach/hardware.h>
69 +/* This stuff should be in ep93xx-regs.h */
70 +#define EP93XX_TOUCHSCREEN_REG(x) (EP93XX_TOUCHSCREEN_BASE + (x))
71 +/* R/W touchscreen controller setup control register. */
72 +#define EP93XX_TOUCHSCREEN_SETUP EP93XX_TOUCHSCREEN_REG(0x00)
73 +/* R/W touchscreen controller max/min register. */
74 +#define EP93XX_TOUCHSCREEN_XYMAXMIN EP93XX_TOUCHSCREEN_REG(0x04)
75 +/* R touchscreen controller result register. */
76 +#define EP93XX_TOUCHSCREEN_XYRESULT EP93XX_TOUCHSCREEN_REG(0x08)
77 +/* LOCKED R/W touchscreen Switch Matrix control register. */
78 +#define EP93XX_TOUCHSCREEN_DISCHARGE EP93XX_TOUCHSCREEN_REG(0x0C)
79 +#define EP93XX_TOUCHSCREEN_XSAMPLE EP93XX_TOUCHSCREEN_REG(0x10)
80 +#define EP93XX_TOUCHSCREEN_YSAMPLE EP93XX_TOUCHSCREEN_REG(0x14)
81 +#define EP93XX_TOUCHSCREEN_DIRECT EP93XX_TOUCHSCREEN_REG(0x18)
82 +#define EP93XX_TOUCHSCREEN_DETECT EP93XX_TOUCHSCREEN_REG(0x1C)
83 +/* NA R/W touchscreen software lock register. */
84 +#define EP93XX_TOUCHSCREEN_SWLOCK EP93XX_TOUCHSCREEN_REG(0x20)
85 +/* R/W touchscreen setup control register #2. */
86 +#define EP93XX_TOUCHSCREEN_SETUP2 EP93XX_TOUCHSCREEN_REG(0x24)
88 +/* These are duplicated in mach-ep93xx/core.c */
89 +#define EP93XX_TIMER_REG(x) (EP93XX_TIMER_BASE + (x))
90 +#define EP93XX_TIMER2_LOAD EP93XX_TIMER_REG(0x20)
91 +#define EP93XX_TIMER2_VALUE EP93XX_TIMER_REG(0x24)
92 +#define EP93XX_TIMER2_CONTROL EP93XX_TIMER_REG(0x28)
93 +#define EP93XX_TIMER2_CLEAR EP93XX_TIMER_REG(0x2c)
96 + * Register bit definitions
98 +#define TSSETUP_SDLY_MASK 0x000003FF
99 +#define TSSETUP_SDLY_SHIFT 0
100 +#define TSSETUP_NSMP_4 0x00000000
101 +#define TSSETUP_NSMP_8 0x00000400
102 +#define TSSETUP_NSMP_16 0x00000800
103 +#define TSSETUP_NSMP_32 0x00000C00
104 +#define TSSETUP_NSMP_MASK 0x00000C00
105 +#define TSSETUP_DEV_4 0x00000000
106 +#define TSSETUP_DEV_8 0x00001000
107 +#define TSSETUP_DEV_12 0x00002000
108 +#define TSSETUP_DEV_16 0x00003000
109 +#define TSSETUP_DEV_24 0x00004000
110 +#define TSSETUP_DEV_32 0x00005000
111 +#define TSSETUP_DEV_64 0x00006000
112 +#define TSSETUP_DEV_128 0x00007000
113 +#define TSSETUP_ENABLE 0x00008000
114 +#define TSSETUP_DLY_MASK 0x03FF0000
115 +#define TSSETUP_DLY_SHIFT 16
116 +#define TSSETUP_TDTCT 0x80000000
118 +#define TSMAXMIN_XMIN_MASK 0x000000FF
119 +#define TSMAXMIN_XMIN_SHIFT 0
120 +#define TSMAXMIN_YMIN_MASK 0x0000FF00
121 +#define TSMAXMIN_YMIN_SHIFT 8
122 +#define TSMAXMIN_XMAX_MASK 0x00FF0000
123 +#define TSMAXMIN_XMAX_SHIFT 16
124 +#define TSMAXMIN_YMAX_MASK 0xFF000000
125 +#define TSMAXMIN_YMAX_SHIFT 24
127 +#define TSXYRESULT_X_MASK 0x00000FFF
128 +#define TSXYRESULT_X_SHIFT 0
129 +#define TSXYRESULT_AD_MASK 0x0000FFFF
130 +#define TSXYRESULT_AD_SHIFT 0
131 +#define TSXYRESULT_Y_MASK 0x0FFF0000
132 +#define TSXYRESULT_Y_SHIFT 16
133 +#define TSXYRESULT_SDR 0x80000000
135 +#define TSX_SAMPLE_MASK 0x00003FFF
136 +#define TSX_SAMPLE_SHIFT 0x00
137 +#define TSY_SAMPLE_MASK 0x3FFF0000
138 +#define TSY_SAMPLE_SHIFT 0x10
140 +#define TSSETUP2_TINT 0x00000001
141 +#define TSSETUP2_NICOR 0x00000002
142 +#define TSSETUP2_PINT 0x00000004
143 +#define TSSETUP2_PENSTS 0x00000008
144 +#define TSSETUP2_PINTEN 0x00000010
145 +#define TSSETUP2_DEVINT 0x00000020
146 +#define TSSETUP2_DINTEN 0x00000040
147 +#define TSSETUP2_DTMEN 0x00000080
148 +#define TSSETUP2_DISDEV 0x00000100
149 +#define TSSETUP2_NSIGND 0x00000200
150 +#define TSSETUP2_S28EN 0x00000400
151 +#define TSSETUP2_RINTEN 0x00000800
153 +#define TSXYRESULT_SDR 0x80000000
156 + * These are used as trigger levels to know when we have pen up/down.
158 + * 1. TS_HEAVY_INV_PRESSURE < TS_LIGHT_INV_PRESSURE because these
159 + * are Inverse pressure.
160 + * 2. Any touch lighter than TS_LIGHT_INV_PRESSURE is a pen up.
161 + * 3. Any touch heavier than TS_HEAVY_INV_PRESSURE is a pen down.
163 +#define TS_HEAVY_INV_PRESSURE 0xFE0 /* C00 */
164 +#define TS_LIGHT_INV_PRESSURE 0xFFF /* e00 */
167 + * If the x, y, or inverse pressure changes more than these values
168 + * between two succeeding points, the point is not reported.
170 +#define TS_MAX_VALID_XY_CHANGE 0x300
171 +#define TS_MAX_VALID_PRESSURE_CHANGE 0x100
174 + * This is the minimum Z1 Value that is valid.
176 +#define MIN_Z1_VALUE 0x50
179 + * Settling delay for taking each ADC measurement. Increase this
180 + * if ts is jittery.
182 +#define EP93XX_TS_ADC_DELAY_USEC 2000
185 + * Delay between TS points.
187 +#define EP93XX_TS_PER_POINT_DELAY_USEC 10000
190 + * A few more macros...
192 +#define TSSETUP_DEFAULT (TSSETUP_NSMP_32 | TSSETUP_DEV_64 | \
193 + ((128<<TSSETUP_SDLY_SHIFT) & TSSETUP_SDLY_MASK) | \
194 + ((128<<TSSETUP_DLY_SHIFT) & TSSETUP_DLY_MASK))
196 +#define TSSETUP2_DEFAULT (TSSETUP2_NSIGND)
199 + * For now, we use one of the minor numbers from the local/experimental
202 +#define EP93XX_TS_MINOR 240
205 + * Static Declarations
207 +static unsigned int guiLastX, guiLastY;
208 +static unsigned int guiLastInvPressure;
210 +struct TouchScreenSample
215 + int currentPressure;
216 + struct timeval currentTime;
220 + * This must match the structure in tslib.
225 + unsigned int pressure;
229 +static struct TouchScreenSample gSample;
230 +static int bFreshTouchData;
231 +static int bCurrentPenDown;
233 +static DECLARE_WAIT_QUEUE_HEAD(queue);
234 +static DECLARE_MUTEX(open_sem);
235 +static spinlock_t event_buffer_lock = SPIN_LOCK_UNLOCKED;
236 +static struct fasync_struct *ep93xx_fasync;
239 + * Typedef Declarations
242 + TS_MODE_UN_INITIALIZED,
243 + TS_MODE_HARDWARE_SCAN,
247 +static ts_mode_t gScanningMode;
250 + TS_STATE_STOPPED = 0,
267 +static ts_struct_t sTouch;
270 + * From the spec, here's how to set up the touch screen's switch registers.
274 + unsigned int uiDetect;
275 + unsigned int uiDischarge;
276 + unsigned int uiXSample;
277 + unsigned int uiYSample;
278 + unsigned int uiSwitchZ1;
279 + unsigned int uiSwitchZ2;
283 + * Here's the switch settings for a 4-wire touchscreen. See the spec
284 + * for how to handle a 4, 7, or 8-wire.
286 +const static SwitchStructType sSwitchSettings =
288 +/* TSDetect TSDischarge TSXSample TSYSample SwitchZ1 SwitchZ2 */
289 + {0x00403604, 0x0007fe04, 0x00081604, 0x00104601, 0x00101601, 0x00101608};
292 + * Function declarations
294 +static void ep93xx_ts_set_direct(unsigned int uiADCSwitch);
295 +static irqreturn_t ep93xx_ts_isr(int irq, void *dev_id);
296 +static irqreturn_t ep93xx_timer2_isr(int irq, void *dev_id);
297 +static void ee93xx_ts_evt_add(int button, int dX, int dY, int Pressure);
298 +static ssize_t ep93xx_ts_read(struct file *filp, char *buf,
299 + size_t count, loff_t *l);
300 +static unsigned int ep93xx_ts_poll(struct file *filp, poll_table *wait);
301 +static int ep93xx_ts_open(struct inode *inode, struct file *filp);
302 +static int ep93xx_ts_fasync(int fd, struct file *filp, int on);
303 +static int ep93xx_ts_release(struct inode *inode, struct file *filp);
304 +static ssize_t ep93xx_ts_write(struct file *file, const char *buffer,
305 + size_t count, loff_t *ppos);
306 +static void ep93xx_ts_setup(void);
307 +static void ep93xx_ts_shutdown(void);
308 +int __init ep93xx_ts_init(void);
309 +void __exit ep93xx_ts_exit(void);
310 +static unsigned int CalculateInvPressure(void);
311 +static unsigned int ADCGetData(unsigned int uiSamples, unsigned int uiMaxDiff);
312 +static void TS_Soft_Scan_Mode(void);
313 +static void TS_Hardware_Scan_Mode(void);
314 +static void ProcessPointData(void);
315 +static void Set_Timer2_uSec(unsigned int Delay_mSec);
316 +static void Stop_Timer2(void);
321 +static irqreturn_t ep93xx_ts_isr(int irq, void *dev_id)
324 + * Note that we don't clear the interrupt here. The interrupt
325 + * gets cleared in TS_Soft_Scan_Mode when the TS ENABLE
330 + * Set the ts to manual polling mode and schedule a callback.
331 + * That way we can return from the isr in a reasonable amount of
332 + * time and process the touch in the callback after a brief delay.
334 + TS_Soft_Scan_Mode();
336 + return(IRQ_HANDLED);
340 + * Save the current ts 'event' in an atomic fashion.
342 +static void ee93xx_ts_evt_add(int buttons, int iX, int iY, int iPressure)
345 + * Note the event, but use spinlocks to keep it from getting
346 + * halfway read if we get interrupted.
349 + spin_lock(&event_buffer_lock);
351 + gSample.currentX = iX;
352 + gSample.currentY = iY;
353 + gSample.currentButton = buttons;
354 + gSample.currentPressure = iPressure;
355 + bFreshTouchData = 1;
356 + do_gettimeofday(&gSample.currentTime);
358 + spin_unlock(&event_buffer_lock);
360 + kill_fasync(&ep93xx_fasync, SIGIO, POLL_IN);
361 + wake_up_interruptible(&queue);
365 +static ssize_t ep93xx_ts_read(struct file *filp, char *buf, size_t count, loff_t *l)
367 + unsigned short data[3];
368 + struct ts_sample ts_data;
369 + int iReturn = -EFAULT;
371 + if (!bFreshTouchData)
375 + else if (count == sizeof(data))
377 + spin_lock_irq(&event_buffer_lock);
378 + bFreshTouchData = 0;
379 + data[0] = gSample.currentX;
380 + data[1] = gSample.currentY;
381 + data[2] = gSample.currentButton;
383 + spin_unlock_irq(&event_buffer_lock);
385 + if (copy_to_user(buf, data, sizeof data))
388 + count -= sizeof(data);
390 + /* return the # of bytes that got read */
391 + iReturn = sizeof(data) ;
393 + else if (count == sizeof(struct ts_sample) )
395 + spin_lock_irq(&event_buffer_lock);
396 + bFreshTouchData = 0;
397 + ts_data.x = gSample.currentX;
398 + ts_data.y = gSample.currentY;
399 + ts_data.pressure = gSample.currentPressure;
400 + ts_data.tv = gSample.currentTime;
401 + spin_unlock_irq(&event_buffer_lock);
403 + if (copy_to_user(buf, &ts_data, sizeof(struct ts_sample)))
409 + count -= sizeof(ts_data);
410 + iReturn = sizeof(ts_data);
417 +static unsigned int ep93xx_ts_poll(struct file *filp, poll_table *wait)
419 + poll_wait(filp, &queue, wait);
421 + if (bFreshTouchData)
423 + return POLLIN | POLLRDNORM;
429 +static int ep93xx_ts_open(struct inode *inode, struct file *filp)
431 + if (down_trylock(&open_sem))
442 + * Asynchronous I/O support.
444 +static int ep93xx_ts_fasync(int fd, struct file *filp, int on)
448 + retval = fasync_helper(fd, filp, on, &ep93xx_fasync);
457 +static int ep93xx_ts_release(struct inode *inode, struct file *filp)
462 + * Call our async I/O support to request that this file
463 + * cease to be used for async I/O.
465 + ep93xx_ts_fasync(-1, filp, 0);
467 + ep93xx_ts_shutdown();
474 +static ssize_t ep93xx_ts_write(struct file *file, const char *buffer, size_t count,
481 +static int ep93xx_ts_ioctl(struct inode *inode, struct file *file, uint command, ulong u)
483 + static const int version = EV_VERSION;
484 + static const u_int32_t bit =(1 << EV_ABS);
485 + static const u_int32_t absbit = (1 << ABS_X) | (1 << ABS_Y) | (1 << ABS_PRESSURE);
491 + case EVIOCGVERSION:
492 + i = copy_to_user((void __user *)u, (void *)version, sizeof(version));
493 + iReturn = i ? -EFAULT : 0;
496 + case EVIOCGBIT(0,sizeof(u_int32_t) * 8) :
497 + i = copy_to_user((void __user *)u, (void *)bit, sizeof(bit));
498 + iReturn = i ? -EFAULT : 0;
501 + case EVIOCGBIT(EV_ABS, sizeof(absbit) * 8):
502 + i = copy_to_user((void __user *)u, (void *)absbit, sizeof(absbit));
503 + iReturn = i ? -EFAULT : 0;
513 +static struct file_operations ep93xx_ts_fops = {
514 + owner: THIS_MODULE,
515 + read: ep93xx_ts_read,
516 + write: ep93xx_ts_write,
517 + poll: ep93xx_ts_poll,
518 + open: ep93xx_ts_open,
519 + unlocked_ioctl: ep93xx_ts_ioctl,
520 + release: ep93xx_ts_release,
521 + fasync: ep93xx_ts_fasync,
524 +static struct miscdevice ep93xx_ts_miscdev =
531 +void ep93xx_ts_setup(void)
533 + unsigned int uiKTDIV, uiTSXYMaxMin;
536 + * Set the TSEN bit in KTDIV so that we are enabling the clock
537 + * for the touchscreen.
539 + uiKTDIV = __raw_readl(EP93XX_SYSCON_KEYTCHCLKDIV);
540 + uiKTDIV |= EP93XX_SYSCON_KEYTCHCLKDIV_TSEN;
541 + ep93xx_syscon_swlocked_write(uiKTDIV, EP93XX_SYSCON_KEYTCHCLKDIV);
544 + * Program the EP93XX_TOUCHSCREEN_SETUP and TSSetup2 registers.
546 + __raw_writel(TSSETUP_DEFAULT, EP93XX_TOUCHSCREEN_SETUP);
547 + __raw_writel(TSSETUP2_DEFAULT, EP93XX_TOUCHSCREEN_SETUP2);
550 + * Set the the touch settings.
552 + __raw_writel(0xaa, EP93XX_TOUCHSCREEN_SWLOCK);
553 + __raw_writel(sSwitchSettings.uiDischarge, EP93XX_TOUCHSCREEN_DIRECT);
555 + __raw_writel(0xaa, EP93XX_TOUCHSCREEN_SWLOCK);
556 + __raw_writel(sSwitchSettings.uiDischarge, EP93XX_TOUCHSCREEN_DISCHARGE);
558 + __raw_writel(0xaa, EP93XX_TOUCHSCREEN_SWLOCK);
559 + __raw_writel(sSwitchSettings.uiSwitchZ1, EP93XX_TOUCHSCREEN_XSAMPLE);
561 + __raw_writel(0xaa, EP93XX_TOUCHSCREEN_SWLOCK);
562 + __raw_writel(sSwitchSettings.uiSwitchZ2, EP93XX_TOUCHSCREEN_YSAMPLE);
564 + __raw_writel(0xaa, EP93XX_TOUCHSCREEN_SWLOCK);
565 + __raw_writel(sSwitchSettings.uiDetect, EP93XX_TOUCHSCREEN_DETECT);
568 + * X,YMin set to 0x40 = have to drag that many pixels for a new irq.
569 + * X,YMax set to 0x40 = 1024 pixels is the maximum movement within the
572 + uiTSXYMaxMin = (50 << TSMAXMIN_XMIN_SHIFT) & TSMAXMIN_XMIN_MASK;
573 + uiTSXYMaxMin |= (50 << TSMAXMIN_YMIN_SHIFT) & TSMAXMIN_YMIN_MASK;
574 + uiTSXYMaxMin |= (0xff << TSMAXMIN_XMAX_SHIFT) & TSMAXMIN_XMAX_MASK;
575 + uiTSXYMaxMin |= (0xff << TSMAXMIN_YMAX_SHIFT) & TSMAXMIN_YMAX_MASK;
576 + __raw_writel(uiTSXYMaxMin, EP93XX_TOUCHSCREEN_XYMAXMIN);
578 + bCurrentPenDown = 0;
579 + bFreshTouchData = 0;
582 + guiLastInvPressure = 0xffffff;
585 + * Enable the touch screen scanning engine.
587 + TS_Hardware_Scan_Mode();
591 + * ep93xx_ts_shutdown
595 +ep93xx_ts_shutdown(void)
597 + unsigned int uiKTDIV;
599 + sTouch.state = TS_STATE_STOPPED;
603 + * Disable the scanning engine.
605 + __raw_writel(0, EP93XX_TOUCHSCREEN_SETUP);
606 + __raw_writel(0, EP93XX_TOUCHSCREEN_SETUP2);
609 + * Clear the TSEN bit in KTDIV so that we are disabling the clock
610 + * for the touchscreen.
612 + uiKTDIV = __raw_readl(EP93XX_SYSCON_KEYTCHCLKDIV);
613 + uiKTDIV &= ~EP93XX_SYSCON_KEYTCHCLKDIV_TSEN;
614 + ep93xx_syscon_swlocked_write(uiKTDIV, EP93XX_SYSCON_KEYTCHCLKDIV);
616 +} /* ep93xx_ts_shutdown */
618 +static irqreturn_t ep93xx_timer2_isr(int irq, void *dev_id)
620 + switch(sTouch.state)
622 + case TS_STATE_STOPPED:
623 + TS_Hardware_Scan_Mode();
627 + * Get the Z1 value for pressure measurement and set up
628 + * the switch register for getting the Z2 measurement.
631 + Set_Timer2_uSec(EP93XX_TS_ADC_DELAY_USEC);
632 + sTouch.uiZ1 = ADCGetData(2, 200);
633 + ep93xx_ts_set_direct(sSwitchSettings.uiSwitchZ2);
634 + sTouch.state = TS_STATE_Z2;
638 + * Get the Z2 value for pressure measurement and set up
639 + * the switch register for getting the Y measurement.
642 + sTouch.uiZ2 = ADCGetData(2, 200);
643 + ep93xx_ts_set_direct(sSwitchSettings.uiYSample);
644 + sTouch.state = TS_STATE_Y;
648 + * Get the Y value and set up the switch register for
649 + * getting the X measurement.
652 + sTouch.uiY = ADCGetData(4, 20);
653 + ep93xx_ts_set_direct(sSwitchSettings.uiXSample);
654 + sTouch.state = TS_STATE_X;
658 + * Read the X value. This is the last of the 4 adc values
659 + * we need so we continue on to process the data.
664 + sTouch.uiX = ADCGetData(4, 20);
666 + __raw_writel(0xaa, EP93XX_TOUCHSCREEN_SWLOCK);
667 + __raw_writel(sSwitchSettings.uiDischarge, EP93XX_TOUCHSCREEN_DIRECT);
669 + sTouch.state = TS_STATE_DONE;
672 + * Process this set of ADC readings.
674 + ProcessPointData();
679 + * Shouldn't get here. But if we do, we can recover...
681 + case TS_STATE_DONE:
682 + TS_Hardware_Scan_Mode();
687 + * Clear the timer2 interrupt.
689 + __raw_writel(1, EP93XX_TIMER2_CLEAR);
690 + return(IRQ_HANDLED);
693 +/*---------------------------------------------------------------------
696 + * This routine processes the ADC data into usable point data and then
697 + * puts the driver into hw or sw scanning mode before returning.
699 + * We calculate inverse pressure (lower number = more pressure) then
700 + * do a hystheresis with the two pressure values 'light' and 'heavy'.
702 + * If we are above the light, we have pen up.
703 + * If we are below the heavy we have pen down.
704 + * As long as the pressure stays below the light, pen stays down.
705 + * When we get above the light again, pen goes back up.
708 +static void ProcessPointData(void)
710 + int bValidPoint = 0;
711 + unsigned int uiXDiff, uiYDiff, uiInvPressureDiff;
712 + unsigned int uiInvPressure;
715 + * Calculate the current pressure.
717 + uiInvPressure = CalculateInvPressure();
720 + * If pen pressure is so light that it is greater than the 'max' setting
721 + * then we consider this to be a pen up.
723 + if (uiInvPressure >= TS_LIGHT_INV_PRESSURE)
725 + bCurrentPenDown = 0;
726 + ee93xx_ts_evt_add(0, guiLastX, guiLastY, 0);
727 + TS_Hardware_Scan_Mode();
733 + * If the pen pressure is hard enough to be less than the 'min' OR
734 + * the pen is already down and is still less than the 'max'...
736 + if ((uiInvPressure < TS_HEAVY_INV_PRESSURE) ||
737 + (bCurrentPenDown && (uiInvPressure < TS_LIGHT_INV_PRESSURE)))
739 + if (bCurrentPenDown)
742 + * If pen was previously down, check the difference between
743 + * the last sample and this one... if the difference between
744 + * samples is too great, ignore the sample.
746 + uiXDiff = abs(guiLastX - sTouch.uiX);
747 + uiYDiff = abs(guiLastY - sTouch.uiY);
748 + uiInvPressureDiff = abs(guiLastInvPressure - uiInvPressure);
750 + if (uiXDiff < TS_MAX_VALID_XY_CHANGE
751 + && uiYDiff < TS_MAX_VALID_XY_CHANGE
752 + && uiInvPressureDiff < TS_MAX_VALID_PRESSURE_CHANGE)
763 + * If either the pen was put down or dragged make a note of it.
767 + guiLastX = sTouch.uiX;
768 + guiLastY = sTouch.uiY;
769 + guiLastInvPressure = uiInvPressure;
770 + bCurrentPenDown = 1;
771 + ee93xx_ts_evt_add(1, sTouch.uiX, sTouch.uiY,
772 + 0x7000000 / uiInvPressure);
775 + TS_Soft_Scan_Mode();
779 + TS_Hardware_Scan_Mode();
782 +static void ep93xx_ts_set_direct(unsigned int uiADCSwitch)
784 + unsigned int uiResult;
787 + * Set the switch settings in the direct register.
789 + __raw_writel(0xaa, EP93XX_TOUCHSCREEN_SWLOCK);
790 + __raw_writel(uiADCSwitch, EP93XX_TOUCHSCREEN_DIRECT);
793 + * Read and throw away the first sample.
796 + uiResult = __raw_readl(EP93XX_TOUCHSCREEN_XYRESULT);
797 + } while (!(uiResult & TSXYRESULT_SDR));
801 +static unsigned int ADCGetData(unsigned int uiSamples, unsigned int uiMaxDiff)
803 + unsigned int uiResult, uiValue, uiCount, uiLowest, uiHighest, uiSum, uiAve;
808 + * Initialize our values.
810 + uiLowest = 0xfffffff;
814 + for (uiCount = 0; uiCount < uiSamples; uiCount++)
817 + * Read the touch screen four more times and average.
820 + uiResult = __raw_readl(EP93XX_TOUCHSCREEN_XYRESULT);
821 + } while (!(uiResult & TSXYRESULT_SDR));
823 + uiValue = (uiResult & TSXYRESULT_AD_MASK) >> TSXYRESULT_AD_SHIFT;
824 + uiValue = ((uiValue >> 4) + ((1 + TSXYRESULT_X_MASK)>>1)) & TSXYRESULT_X_MASK;
827 + * Add up the values.
832 + * Get the lowest and highest values.
834 + if (uiValue < uiLowest)
836 + uiLowest = uiValue;
838 + if (uiValue > uiHighest)
840 + uiHighest = uiValue;
843 + } while ((uiHighest - uiLowest) > uiMaxDiff);
846 + * Calculate the Average value.
848 + uiAve = uiSum / uiSamples;
854 + * CalculateInvPressure
856 + * Is the Touch Valid. Touch is not valid if the X or Y value is not
857 + * in range and the pressure is not enough.
859 + * Touch resistance can be measured by the following formula:
862 + * Rtouch = --------- * (-- - 1)
865 + * This is simplified in the ration of Rtouch to Rx. The lower the value, the
866 + * higher the pressure.
869 + * InvPressure = X * (-- - 1)
872 +static unsigned int CalculateInvPressure(void)
874 + unsigned int uiInvPressure;
877 + * Check to see if the point is valid.
879 + if (sTouch.uiZ1 < MIN_Z1_VALUE)
881 + uiInvPressure = 0x10000;
885 + * Can omit the pressure calculation if you need to get rid of the division.
889 + uiInvPressure = ((sTouch.uiX * sTouch.uiZ2) / sTouch.uiZ1) - sTouch.uiX;
892 + return uiInvPressure;
896 + * TS_Hardware_Scan_Mode
898 + * Enables the ep93xx ts scanning engine so that when the pen goes down
899 + * we will get an interrupt.
901 +static void TS_Hardware_Scan_Mode(void)
903 + unsigned int uiDevCfg;
906 + * Disable the soft scanning engine.
908 + sTouch.state = TS_STATE_STOPPED;
912 + * Clear the TIN (Touchscreen INactive) bit so we can go to
913 + * automatic scanning mode.
915 + uiDevCfg = __raw_readl(EP93XX_SYSCON_DEVCFG);
916 + ep93xx_syscon_swlocked_write(uiDevCfg & ~EP93XX_SYSCON_DEVCFG_TIN,
917 + EP93XX_SYSCON_DEVCFG);
920 + * Enable the touch screen scanning state machine by setting
923 + __raw_writel(TSSETUP_DEFAULT | TSSETUP_ENABLE, EP93XX_TOUCHSCREEN_SETUP);
926 + * Set the flag to show that we are in interrupt mode.
928 + gScanningMode = TS_MODE_HARDWARE_SCAN;
931 + * Initialize EP93XX_TOUCHSCREEN_SETUP2 register.
933 + __raw_writel(TSSETUP2_DEFAULT, EP93XX_TOUCHSCREEN_SETUP2);
938 + * TS_Soft_Scan_Mode
940 + * Sets the touch screen to manual polling mode.
942 +static void TS_Soft_Scan_Mode(void)
944 + unsigned int uiDevCfg;
946 + if (gScanningMode != TS_MODE_SOFT_SCAN)
949 + * Disable the touch screen scanning state machine by clearing
952 + __raw_writel(TSSETUP_DEFAULT, EP93XX_TOUCHSCREEN_SETUP);
955 + * Set the TIN bit so we can do manual touchscreen polling.
957 + uiDevCfg = __raw_readl(EP93XX_SYSCON_DEVCFG);
958 + ep93xx_syscon_swlocked_write(uiDevCfg | EP93XX_SYSCON_DEVCFG_TIN,
959 + EP93XX_SYSCON_DEVCFG);
963 + * Set the switch register up for the first ADC reading
965 + ep93xx_ts_set_direct(sSwitchSettings.uiSwitchZ1);
968 + * Initialize our software state machine to know which ADC
971 + sTouch.state = TS_STATE_Z1;
974 + * Set the timer so after a mSec or two settling delay it will
975 + * take the first ADC reading.
977 + Set_Timer2_uSec(EP93XX_TS_PER_POINT_DELAY_USEC);
980 + * Note that we are in sw scanning mode not hw scanning mode.
982 + gScanningMode = TS_MODE_SOFT_SCAN;
986 +static void Set_Timer2_uSec(unsigned int uiDelay_uSec)
988 + unsigned int uiClockTicks;
993 + __raw_writel(0, EP93XX_TIMER2_CONTROL);
995 + uiClockTicks = ((uiDelay_uSec * 508) + 999) / 1000;
996 + __raw_writel(uiClockTicks, EP93XX_TIMER2_LOAD);
997 + __raw_writel(uiClockTicks, EP93XX_TIMER2_VALUE);
1000 + * Set up Timer 2 for 508 kHz clock and periodic mode.
1002 + __raw_writel(0xC8, EP93XX_TIMER2_CONTROL);
1006 +static void Stop_Timer2(void)
1008 + __raw_writel(0, EP93XX_TIMER2_CONTROL);
1012 + * Initialization and exit routines
1014 +int __init ep93xx_ts_init(void)
1018 + retval = request_irq(IRQ_EP93XX_TOUCH, ep93xx_ts_isr,
1019 + IRQF_DISABLED, "ep93xx_ts", 0);
1022 + printk(KERN_WARNING "ep93xx_ts: failed to get touchscreen IRQ\n");
1026 + retval = request_irq(IRQ_EP93XX_TIMER2, ep93xx_timer2_isr,
1027 + IRQF_DISABLED, "ep93xx_timer2", 0);
1030 + printk(KERN_WARNING "ep93xx_ts: failed to get timer2 IRQ\n");
1031 + free_irq(IRQ_EP93XX_TOUCH, 0);
1035 + misc_register(&ep93xx_ts_miscdev);
1037 + sTouch.state = TS_STATE_STOPPED;
1038 + gScanningMode = TS_MODE_UN_INITIALIZED;
1040 + printk(KERN_NOTICE "ep93xx touchscreen driver configured for 4-wire operation\n");
1045 +void __exit ep93xx_ts_exit(void)
1049 + free_irq(IRQ_EP93XX_TOUCH, 0);
1050 + free_irq(IRQ_EP93XX_TIMER2, 0);
1052 + misc_deregister(&ep93xx_ts_miscdev);
1055 +module_init(ep93xx_ts_init);
1056 +module_exit(ep93xx_ts_exit);
1058 +MODULE_DESCRIPTION("Cirrus EP93xx touchscreen driver");
1059 +MODULE_SUPPORTED_DEVICE("touchscreen/ep93xx");
1060 +MODULE_LICENSE("GPL");