summaryrefslogtreecommitdiff
path: root/packages/linux/linux-ezx/ezx_ts.patch
blob: 41339dcf523ec6aec0464752c7c246c5e0f6f963 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
Index: linux-2.6.16.5-ezx/drivers/input/touchscreen/Kconfig
===================================================================
--- linux-2.6.16.5-ezx.orig/drivers/input/touchscreen/Kconfig	2006-04-12 17:27:57.000000000 -0300
+++ linux-2.6.16.5-ezx/drivers/input/touchscreen/Kconfig	2006-04-24 22:40:00.000000000 -0300
@@ -108,4 +108,16 @@
 	  To compile this driver as a module, choose M here: the
 	  module will be called hp680_ts_input.
 
+config TOUCHSCREEN_EZX
+	tristate "Motorola EZX (via PCAP2) touchscreen"
+	depends on EZX
+	help
+	  Say Y here if you have a Motorola EZX (E680, A780) telephone
+	  and want to support the built-in touchscreen.
+
+	  If unsure, say N.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called hp680_ts_input.
+
 endif
Index: linux-2.6.16.5-ezx/drivers/input/touchscreen/Makefile
===================================================================
--- linux-2.6.16.5-ezx.orig/drivers/input/touchscreen/Makefile	2006-04-12 17:27:57.000000000 -0300
+++ linux-2.6.16.5-ezx/drivers/input/touchscreen/Makefile	2006-04-24 22:40:15.000000000 -0300
@@ -12,3 +12,4 @@
 obj-$(CONFIG_TOUCHSCREEN_MTOUCH) += mtouch.o
 obj-$(CONFIG_TOUCHSCREEN_MK712)	+= mk712.o
 obj-$(CONFIG_TOUCHSCREEN_HP600)	+= hp680_ts_input.o
+obj-$(CONFIG_TOUCHSCREEN_EZX)	+= ezx.o
Index: linux-2.6.16.5-ezx/drivers/input/touchscreen/ezx.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ linux-2.6.16.5-ezx/drivers/input/touchscreen/ezx.c	2006-04-24 22:52:20.000000000 -0300
@@ -0,0 +1,991 @@
+/*
+ *  linux/drivers/char/ezx-ts.c
+ *
+ *  Copyright (C) 2002 Lili Jiang, All Rights Reserved.
+ * 
+ *
+ *  June, 2002 Lili Jiang, create
+ */
+
+#if 0
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/fs.h>
+#include <linux/miscdevice.h>
+#include <linux/poll.h>
+#include <linux/smp.h>
+#include <linux/smp_lock.h>
+#include <linux/sched.h>
+#include <linux/completion.h>
+#include <linux/string.h>
+#include <linux/pm.h>
+#include <linux/config.h>
+#include <linux/fb.h>
+
+#include <asm/semaphore.h>
+#include <asm/hardware.h>
+#include <asm/arch/irqs.h>
+#include <linux/timex.h>
+#include <linux/interrupt.h>
+
+#include <asm/arch/pxa-regs.h>
+
+#include "ezx-ts.h"
+#include "ssp_pcap.h"
+
+#define DEBUG 0  /*change it when formal release*/
+#if DEBUG
+#  define TS_DPRINTK(s...)	printk(s)
+#else
+#  define TS_DPRINTK(s...)
+#endif
+
+/*
+ * This structure is nonsense - millisecs is not very useful
+ * since the field size is too small.  Also, we SHOULD NOT
+ * be exposing jiffies to user space directly.
+ */
+struct ts_event {
+	u16		pressure;
+	u16		x;
+	u16		y;
+	u16		pad;
+//	struct timeval	stamp;
+};
+
+static struct timer_list ezx_ts_penup_timer;
+
+static struct irqaction ezx_ts_custom_timer_irq = {
+        name: "ezx_ts_custom_timer",
+};
+
+static u8 bSetPenupTimer = 0;
+static u8 bFirstPen = 0;
+//static unsigned long penCurJiffies = 0;
+static unsigned int penSampleCount = 0;
+static u32  tspenSampleCount = 0;
+static u32  tsDiscardDataCount = 0;
+
+typedef enum
+{
+    PRESSURE,
+    COORDINATE	
+}EZX_TS_READ_STATE;
+
+EZX_TS_READ_STATE ezx_ts_read_state = PRESSURE;
+
+#define TS_NR_EVENTS	128
+/*250 //pay attention to that haed and tail is defined as u8*/
+
+#define TS_EDGE_MIN_LIMIT  (0) /* 10 */
+#define TS_EDGE_MAX_LIMIT  (1023)
+
+/* jiffies : 10ms,  pen shake 50ms????? */
+//#define EZX_TS_READ_MIN_SPACE   10 /*100//5*/
+//#define EZX_TS_PENUP_TIMEOUT_MS 8 
+
+#define EZX_TS_PENSAMPLE_TIMEOUT_MS  2
+                                    //8,6
+//#define EZX_TS_HWR_TIMEOUT_MS   2
+
+#define QT_ONEPEN_SAMPLES_NUM   1
+                               //3,5
+//#define HWR_ONEPEN_SAMPLES_NUM  1
+
+#define CUSTOM_ONEPEN_SAMPLES_NUM  1
+#define EZX_TS_CUSTOM_TIMEOUT_MS   12
+                                   //15ms
+#define X_DIFF 85
+#define Y_DIFF 75
+#define MIN_X_HOLD              5
+#define MIN_Y_HOLD              4  
+#define SAMPLE_COUNT_NOT_JUMPER   20
+
+typedef enum
+{
+	EZX_PEN_NORMAL,
+	EZX_PEN_CUSTOM
+}EZX_TS_PEN_STYLE;
+
+static EZX_TS_PEN_STYLE gPenStyle = EZX_PEN_NORMAL;
+static u8 gPenSamplesNum = QT_ONEPEN_SAMPLES_NUM;
+//static u32 gHwrTimer = EZX_TS_HWR_TIMEOUT_MS;
+static u32 gCustomTimer = EZX_TS_CUSTOM_TIMEOUT_MS;
+static u8 getPenUp = 0;
+
+struct ezx_ts_info {
+	/*struct ucb1x00		*ucb;*/
+	struct fasync_struct	*fasync;
+	wait_queue_head_t	read_wait;
+
+	/*
+	struct semaphore	irq_wait;
+	struct semaphore	sem;
+	struct completion	init_exit;
+	struct task_struct	*rtask;
+	*/
+	u16			x_cur; /*store the current pen value read from ADC*/
+	u16			y_cur; /*store the current pen value read from ADC */
+    u16         cur_pressure;
+    u16         x_pre;
+    u16         y_pre;
+	u8			evt_head;
+	u8			evt_tail;
+	struct ts_event		events[TS_NR_EVENTS]; /* buffer for store pen data*/
+/*	
+    int			restart:1;
+	int			adcsync:1;
+
+#ifdef CONFIG_PM
+	struct pm_dev		*pmdev;
+#endif
+*/
+};
+
+static struct ezx_ts_info ezxts;
+
+#define EZX_TS_SHAKE_SAMPLES 3
+static u8 ezx_ts_shake_samples_count = 0;
+static struct ts_event ezx_ts_shake_samples[EZX_TS_SHAKE_SAMPLES];
+
+static int ezx_ts_init(void);
+static void ezx_ts_exit(void);
+static int ezx_ts_open(struct inode *inode, struct file * filp);
+static int ezx_ts_release(struct inode *inode, struct file *filp);
+static ssize_t ezx_ts_read(struct file* filp, char* buffer, size_t count, loff_t *ppos);
+static unsigned int ezx_ts_poll(struct file* filp, struct poll_table_struct * wait);
+static int ezx_ts_fasync(int fd, struct file* filp, int mode);
+
+/* internal function */
+static void ezx_ts_init_penEvent(void);
+static void ezx_ts_pen_touch_handler(void);
+static void ezx_ts_penup_timeout(unsigned long data);
+static void ezx_ts_set_timer(struct timer_list *timer, void (*timer_timeout)(unsigned long), signed long timeout);
+static void ezx_ts_check_pen_samples(void);
+static void ezx_ts_evt_add(u16 pressure, u16 x, u16 y);
+static struct ts_event ezx_ts_get_onedata(void);
+
+/* for setup ezx ts self timer,begin */
+static void ezx_ts_custom_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
+{
+    TS_DPRINTK("ezx_ts_custom_timer_interrupt entered.jiffies: %d\n@@@\n", jiffies);
+    SSP_PCAP_TSI_mode_set(PCAP_TS_POSITION_XY_MEASUREMENT);
+    SSP_PCAP_TSI_start_XY_read(); 
+    
+    /* clear this timer */
+    OIER &= ~OIER_E3;
+    OSSR = OSSR_M3;  /* Clear match on timer 2 */
+}
+
+static void ezx_ts_custom_setup_timer()
+{
+    ezx_ts_custom_timer_irq.handler = ezx_ts_custom_timer_interrupt;
+    setup_irq(IRQ_OST3, &ezx_ts_custom_timer_irq);
+}
+
+
+static void ezx_ts_custom_timer_start(void)
+{
+    OIER |= OIER_E3;
+    //OSMR2 = OSCR + sleep_limit * LATCH; //OSCR: 0x40A00010
+    OSMR3 = OSCR + (gCustomTimer * HZ * LATCH) /1000;
+}
+
+static void ezx_ts_custom_timer_stop(void)
+{
+    OIER &= ~OIER_E3;
+    OSSR = OSSR_M3;  /* Clear match on timer 2 */
+}
+
+/* for setup ezx ts self timer, end */
+
+
+static void ezx_ts_init_penEvent(void)
+{
+   int i;
+   
+   ezxts.x_cur = 0;
+   ezxts.y_cur = 0;
+   ezxts.x_pre = 0;
+   ezxts.y_pre = 0;
+   ezxts.cur_pressure = PEN_UP;
+
+   for (i = 0; i < TS_NR_EVENTS; i++)
+   {       
+       ezxts.events[i].pressure=(u16)0;
+       ezxts.events[i].x=(u16)0;
+       ezxts.events[i].y=(u16)0;
+       ezxts.events[i].pad=(u16)0;
+   }
+   ezxts.evt_head = 0;
+   ezxts.evt_tail = 0;
+   
+   gPenStyle = EZX_PEN_NORMAL;	
+   gPenSamplesNum = QT_ONEPEN_SAMPLES_NUM;
+   //gHwrTimer = EZX_TS_HWR_TIMEOUT_MS;
+   gCustomTimer = EZX_TS_CUSTOM_TIMEOUT_MS;
+}
+
+
+static void ezx_ts_pen_touch_handler(void)
+{
+    SSP_PCAP_TSI_mode_set(PCAP_TS_PRESSURE_MEASUREMENT);
+    SSP_PCAP_TSI_start_XY_read();  
+    ezx_ts_read_state = PRESSURE;
+    ezxts.x_pre = 0;
+    ezxts.y_pre = 0;
+
+    TS_DPRINTK("ezx_ts pen touch handler done.\n");
+}
+    
+static void ezx_ts_penup_timeout(unsigned long data)
+{
+    TS_DPRINTK("@@@\nIn pen drag! jiffies: %d\n@@@\n", jiffies);
+    bSetPenupTimer = 0;
+    SSP_PCAP_TSI_mode_set(PCAP_TS_POSITION_XY_MEASUREMENT);
+    SSP_PCAP_TSI_start_XY_read(); 
+}
+
+static void ezx_ts_check_pen_samples(void)
+{
+	if ( (ezx_ts_read_state == COORDINATE) && (penSampleCount != 0 ) )
+	{
+	    int k;
+        if (penSampleCount < gPenSamplesNum)
+        {
+			for ( k = 0; k < (gPenSamplesNum - penSampleCount); k++)
+			{
+			    ezx_ts_evt_add(PEN_DOWN, ezxts.x_cur, ezxts.y_cur);
+			    TS_DPRINTK("ezx_ts_add_additional_samples: %d\n", k);
+			}    
+		}	
+		TS_DPRINTK("ezx_ts_evt_add: PEN_UP\n");
+	    //ezx_ts_evt_add(PEN_UP, 0, 0);
+	}
+	
+    if (bSetPenupTimer)
+	{
+        del_timer(&ezx_ts_penup_timer);
+        bSetPenupTimer = 0;
+        TS_DPRINTK("^^^^Delete penup timer1.\n");
+    }
+    penSampleCount = 0;
+}	
+
+static void ezx_ts_set_timer(struct timer_list *timer, void (*timer_timeout)(unsigned long), 
+	                        signed long timeout)
+{
+	init_timer(timer);
+	timer->expires = timeout + jiffies;
+	timer->data = (unsigned long) current;
+    timer->function = timer_timeout;
+    	
+	add_timer(timer);
+	//TS_DPRINTK("ezx_ts set timer done.\n");
+}
+
+static void ezx_ts_evt_add(u16 pressure, u16 x, u16 y)
+{
+	int next_head;
+	int last_head;
+    /* if pen_up, then copy pressure=0, last_evt.x y to current evt*/
+   
+    next_head = ezxts.evt_head + 1;
+    if (next_head == TS_NR_EVENTS)
+    {
+    	next_head = 0;
+    }
+    
+    last_head = ezxts.evt_head - 1;
+    if (last_head == -1)
+    {
+    	last_head = TS_NR_EVENTS - 1;
+    }
+    
+/*    if (next_head != ezxts.evt_tail)*/
+    //{
+	    if ( pressure == PEN_DOWN)
+	    {
+/*	        if ( (penSampleCount >1) && ((penCurJiffies + EZX_TS_READ_MIN_SPACE) < jiffies))
+	        {
+	            // see two ~ four data or just ignore the data except the first one????
+                    return;
+	        }
+	        else*/
+	        //{
+			    ezxts.events[ezxts.evt_head].pressure = pressure;
+				ezxts.events[ezxts.evt_head].x = x;
+				ezxts.events[ezxts.evt_head].y = y;
+				TS_DPRINTK("ezx_store: x: %d, y :%d, pressure: 0x%x\n", x, y, pressure);
+	        //}
+	    }	
+	    else
+	    {
+	        ezxts.events[ezxts.evt_head].pressure = pressure;
+	        ezxts.events[ezxts.evt_head].x = ezxts.events[last_head].x;
+			ezxts.events[ezxts.evt_head].y = ezxts.events[last_head].y;
+			TS_DPRINTK("ezx_store: PEN_UP\n");
+	    }
+	//}   
+//      do_gettimeofday(&(ezxts.events[ezxts.evt_head].stamp)); 
+	ezxts.evt_head = next_head;
+	
+	if (ezxts.evt_head == ezxts.evt_tail)
+	{
+	    if ( ++ezxts.evt_tail == TS_NR_EVENTS )
+		    ezxts.evt_tail = 0;
+	}
+
+	if (ezxts.fasync)
+			kill_fasync(&ezxts.fasync, SIGIO, POLL_IN);
+	wake_up_interruptible(&ezxts.read_wait);
+}
+
+static struct ts_event ezx_ts_get_onedata(void)
+{
+	int cur = ezxts.evt_tail;
+
+	if (++ezxts.evt_tail == TS_NR_EVENTS)
+		ezxts.evt_tail = 0;
+
+	return ezxts.events[cur];
+}
+
+/*****************************************************************************
+ *  FUNCTION NAME  : ezx_ts_open()
+ * 
+ *  INPUTS: 
+ *    
+ *  OUTPUTS:  pen info from ts event structure
+ *                
+ *  VALUE RETURNED: none
+ *    
+ *  DESCRIPTION: 
+ *    i) Increase this device module used count.
+ *    ii) Initialize a buffer for store data read from touch screen interface.
+ *    iii) Initialize touch screen interface hardware.
+ *    iv) Setup touch screen wait queue.
+*****************************************************************************
+ */
+static int ezx_ts_open(struct inode *inode, struct file * filp)
+{
+	struct ezx_ts_info *ts = &ezxts;
+
+/*    ssp_pcap_init(); //  change to _start_kernel 
+      ssp_pcap_open(); */
+    ssp_pcap_open(SSP_PCAP_TS_OPEN);
+    SSP_PCAP_bit_clean( SSP_PCAP_ADJ_BIT_MSR_TSM);	 
+    
+    ezx_ts_init_penEvent();
+    filp->private_data = ts;
+    
+    
+	TS_DPRINTK("ezx touch screen driver opened\n");
+	return 0;
+}
+
+/*  Decrease this device module used count. */
+static int ezx_ts_release(struct inode *inode, struct file *filp)
+{
+    ezx_ts_init_penEvent();
+    ezx_ts_fasync(-1, filp, 0);
+    
+	TS_DPRINTK("ezx touch screen driver closed\n");
+	return 0;
+}
+
+/*****************************************************************************
+ *  FUNCTION NAME  :  ezx_ts_read
+ * 
+ *  INPUTS: 
+ *    
+ *  OUTPUTS:  pen info from ts event structure
+ *                
+ *  VALUE RETURNED: none
+ *    
+ *  DESCRIPTION: 
+ *   This is used for UI app to call.
+ *   If device is opened by nonblock mode then copy available data from the ts event buffer
+ *   to user buffer and return the actual read data count, if device is opened by block mode 
+ *   and no data available then sleep until the required data count be read completed. 
+ *
+ *  CAUTIONS: 
+ *    
+ *    
+ *****************************************************************************
+ */
+static ssize_t ezx_ts_read(struct file* filp, char* buffer, size_t count, loff_t *ppos)
+{
+	DECLARE_WAITQUEUE(wait, current);
+	
+	struct ezx_ts_info *ts = filp->private_data;
+	char *ptr = buffer;
+	int err = 0;
+    struct ts_event evt;
+    
+	add_wait_queue(&ts->read_wait, &wait);
+	while (count >= sizeof(struct ts_event)) 
+	{
+	    err = -ERESTARTSYS;
+		if (signal_pending(current))
+			break;
+		if ((ts)->evt_head != (ts)->evt_tail)
+		{
+			evt = ezx_ts_get_onedata(); /*evt_tail pos changed in this func*/
+			err = copy_to_user(ptr, &evt, sizeof(struct ts_event));
+
+			if (err)
+				break;
+			//printk("ezx_ts_read: x:%d, y:%d, pressure:0x%x\n", evt.x, evt.y, evt.pressure);	
+			ptr += sizeof(struct ts_event);
+			count -= sizeof(struct ts_event);
+			continue;
+		}
+
+		set_current_state(TASK_INTERRUPTIBLE);
+		err = -EAGAIN;
+		if (filp->f_flags & O_NONBLOCK)
+			break;
+		schedule();
+	}
+	current->state = TASK_RUNNING;
+	remove_wait_queue(&(ts->read_wait), &wait);
+
+	return ptr == buffer ? err : ptr - buffer;
+
+}
+
+/*
+This function is used in nonblock mode to determine whether it can read data from touch screen 
+device without blocking. 
+Call poll_wait to wait until read operation status changed then return POLLIN (flag of device can be 
+read without blocking) | POLLRDNORM (flag of data is available) bit mask if there is readable data 
+now.
+*/
+
+static unsigned int ezx_ts_poll(struct file* filp, struct poll_table_struct * wait)
+{
+	struct ezx_ts_info *ts = filp->private_data;
+	int ret = 0;
+
+    if ( ts != NULL)
+	{
+        TS_DPRINTK("ezx_ts_poll.\n");
+	    poll_wait(filp, &ts->read_wait, wait);
+	    if (ts->evt_head != ts->evt_tail)
+	    {
+	    	TS_DPRINTK("ezx_ts_poll: ts->evt_head != ts->evt_tail\n");
+		    ret = POLLIN | POLLRDNORM;
+		}    
+    }		    
+
+	return ret;
+}
+
+/* Setup fasync queue for touch screen device. */
+
+static int ezx_ts_fasync(int fd, struct file* filp, int mode)
+{
+	struct ezx_ts_info *ts = filp->private_data;
+
+    if ( ts != NULL)
+    {
+    	TS_DPRINTK("ezx_ts_fasync.\n");
+	    return fasync_helper(fd, filp, mode, &ts->fasync);
+	}
+	else return 0;    
+}
+
+static int
+ezx_ts_ioctl(struct inode *inode, struct  file *file, uint cmd, ulong arg)
+{	
+	int res = 0;
+	
+	TS_DPRINTK("ezx_ts_ioctl: arg is %d\n", arg);
+	switch (cmd) {
+/*
+	case SETTONORMAL:
+	    TS_DPRINTK("ezx_ts_ioctl_test: This is SETTONORMAL.\n");
+	    gPenStyle = EZX_PEN_NORMAL;	
+	    gPenSamplesNum = QT_ONEPEN_SAMPLES_NUM;
+	    //gHwrTimer = EZX_TS_HWR_TIMEOUT_MS;
+	    gCustomTimer = EZX_TS_CUSTOM_TIMEOUT_MS;
+	    break;
+	    
+	case SETTOHWR:
+	    TS_DPRINTK("ezx_ts_ioctl_test: This is SETTOHWR.\n");
+		gPenStyle = EZX_PEN_HWR;	
+		gPenSamplesNum = HWR_ONEPEN_SAMPLES_NUM;
+		if ( (arg > 0 ) && (arg < 100) )
+		{
+			gHwrTimer = arg;
+			TS_DPRINTK("ezx_ts_ioctl_test: gHwrTimer is %d.\n", gHwrTimer);
+		}	
+		break;    
+
+	case SETTOCUSTOM:
+	    TS_DPRINTK("ezx_ts_ioctl_test: This is SETTOCUSTOM.\n");
+		gPenStyle = EZX_PEN_CUSTOM;	
+		gPenSamplesNum = CUSTOM_ONEPEN_SAMPLES_NUM;
+		if ( (arg > 0 ) && (arg < 100) )
+		{
+			gCustomTimer = arg;
+			TS_DPRINTK("ezx_ts_ioctl_test: gCustomTimer is %d.\n", gCustomTimer);
+		}	
+		break;    	
+	case GETPENSTYLE:
+	    TS_DPRINTK("ezx_ts_ioctl_test: This is GETPENSTYLE.\n");
+	    put_user(gPenStyle, (u32*)arg);    
+		break;
+	default:
+	    res = -EINVAL;
+*/
+	}
+	
+	return res;
+}
+
+/*****************************************************************************
+ *  FUNCTION NAME  :  ezx_ts_touch_interrupt
+ * 
+ *  INPUTS:
+ *    
+ *  
+ *  OUTPUTS:
+ *    
+ *
+ *  VALUE RETURNED:
+ *    
+ *
+ *  DESCRIPTION: 
+ *  This is touch screen touch interrupt service routine called by PCAP module when touch screen 
+ *  interrupt happened. First eliminate shake signal to get stable touch screen press information. 
+ *  Then write instruction to PCAP register to read ADC conversion value of pressed spot x,y coordinate 
+ *  and return.
+ *
+ *  CAUTIONS:
+ *    
+ *    
+ *
+ *****************************************************************************
+ */
+void ezx_ts_touch_interrupt(int irq, void* dev_id, struct pt_regs *regs)
+{	
+	TS_DPRINTK("ezx_ts_touch_irq happened.\n");
+	ezx_ts_shake_samples_count = 0;
+	//TS_DPRINTK("ezx_ts_touch_irq excuted.\n");
+	ezx_ts_check_pen_samples();
+    ezx_ts_pen_touch_handler();	    
+	
+}
+
+/*****************************************************************************
+ *  FUNCTION NAME  :  ezx_ts_dataReadok_interrupt
+ * 
+ *  INPUTS: call PCAP API to read x,y
+ *    
+ *  OUTPUTS:  Store the pen info to ts event structure
+ *                
+ *  VALUE RETURNED: none
+ *    
+ *  DESCRIPTION: 
+ *   This is called by PCAP module to deal with the touch screen press raw information read from ADC
+ *   when ADC data conversion finished. It performs write the data to ts event buffer for user to 
+ *   read out. 
+ *
+ *  CAUTIONS: Consider pen shake
+ *    
+ *    
+ *****************************************************************************
+ */
+void ezx_ts_dataReadok_interrupt(int irq, void* dev_id, struct pt_regs *regs)
+{
+    static u16 pressure;
+    u16 x;
+    u16 y;
+    U16 tempx,tempy;
+
+    if (SSP_PCAP_TSI_get_XY_value(&x, &y) != SSP_PCAP_SUCCESS)
+    {
+        return;
+    }
+    /* convert x,y???? */
+   // TS_DPRINTK( "ezx_ts_get_XY_value: x:%d, y:%d\n",x, y);
+   /* TS_DPRINTK( "\nezx_ts before convert: x:%d, y:%d\n",x, y);*/
+  
+    if ( ezx_ts_read_state == PRESSURE)
+    {
+        if (( y >= TS_EDGE_MAX_LIMIT ) || (y <= TS_EDGE_MIN_LIMIT))
+        {
+            TS_DPRINTK("ezx_ts_datareadok_irq: PEN_UP.\n");
+            pressure = PEN_UP;
+            ezxts.cur_pressure = PEN_UP;
+           
+            /*ezx_ts_check_pen_samples();*/
+            if ( getPenUp == 0 )
+            {
+            	ezx_ts_evt_add( pressure, 0, 0);
+            }
+             SSP_PCAP_bit_clean( SSP_PCAP_ADJ_BIT_MSR_TSM);
+            return;
+        }
+        else 
+        {
+            TS_DPRINTK("ezx_ts_datareadok_irq: PEN_DOWN.\n");
+            getPenUp = 0;
+            pressure = PEN_DOWN;
+            ezxts.cur_pressure = PEN_DOWN;
+            tspenSampleCount = 0;
+            ezxts.x_pre = 0;
+            ezxts.y_pre = 0;
+            bFirstPen = 1 ;
+	        SSP_PCAP_TSI_mode_set(PCAP_TS_POSITION_XY_MEASUREMENT);
+	        SSP_PCAP_TSI_start_XY_read(); 
+	        ezx_ts_read_state = COORDINATE;
+	       
+	        //TS_DPRINTK("ezx_ts_datareadok_irq: Begin read XY.\n");
+            return;
+        }
+    }
+    else if ( ezx_ts_read_state == COORDINATE)
+    {/*
+    	u8 count;
+    	
+        count = 0;
+       	while ( (( x <= TS_EDGE_MIN_LIMIT)||( x >= TS_EDGE_MAX_LIMIT) ||
+	            ( y <= TS_EDGE_MIN_LIMIT)||( y >= TS_EDGE_MAX_LIMIT))
+	            && (count++ < 15) )
+	    {
+	    	SSP_PCAP_bit_clean( SSP_PCAP_ADJ_BIT_MSR_TSM);
+	    	SSP_PCAP_TSI_mode_set(PCAP_TS_POSITION_XY_MEASUREMENT);
+	        SSP_PCAP_TSI_start_XY_read(); 
+ 	    }
+ 	  */  
+	    if ( ( x <= TS_EDGE_MIN_LIMIT)||( x >= TS_EDGE_MAX_LIMIT) ||
+	         ( y <= TS_EDGE_MIN_LIMIT)||( y >= TS_EDGE_MAX_LIMIT) )	        
+	    {  /* regard it as PEN_UP */
+	        pressure = PEN_UP;
+	        ezxts.cur_pressure = PEN_UP;
+	   	    x = 0;
+	        y = 0;
+                tspenSampleCount = 0;
+  	        SSP_PCAP_bit_clean( SSP_PCAP_ADJ_BIT_MSR_TSM); 
+	        /*del_timer(&ezx_ts_read_timer);*/
+	        ezx_ts_check_pen_samples();
+	        ezx_ts_evt_add( pressure, 0, 0);
+	       /* SSP_PCAP_bit_clean( SSP_PCAP_ADJ_BIT_MSR_TSM);*/
+	        ezx_ts_read_state = PRESSURE;
+	        getPenUp = 1;
+	        TS_DPRINTK( "ezx_ts Invalid x,y position: PEN_UP?\n");
+            return;
+	    }
+	    getPenUp = 0;
+        penSampleCount++;
+        //TS_DPRINTK("ezx_ts_datareadok_irq: Begin store XY %d.\n", penSampleCount);
+	    
+	    if ( gPenStyle == EZX_PEN_CUSTOM )
+	    {
+	    	if ( ((ezxts.x_pre == 0) && (ezxts.y_pre == 0)) 
+	    	     || ( (ezxts.x_pre != 0) && (ezxts.y_pre != 0)
+	    	     &&(!((abs(ezxts.x_pre - x) > X_DIFF) || (abs(ezxts.y_pre - y) > Y_DIFF))) )
+	    	   )     
+	    	{
+	    		//TS_DPRINTK("ezx_ts_datareadok_irq: diff <= XY_DIFF.\n");
+	    		
+	    		ezxts.x_pre = x;
+	    		ezxts.y_pre = y;
+	    		 
+	    		TS_DPRINTK("ezx_ts_datareadok_irq:x_pre=%d,y_pre=%d\n", ezxts.x_pre, ezxts.y_pre);
+	    		ezxts.x_cur = x;
+    			ezxts.y_cur = y;
+    			ezx_ts_evt_add(pressure, ezxts.x_cur, ezxts.y_cur);
+			//printk("ezx_ts_datareadok_irq_custom add pressure0x%x,x_cur%d,y_cur%d\n",pressure,ezxts.x_cur,ezxts.y_cur);
+    			ezx_ts_custom_timer_start();
+            }
+            else
+            {
+            	//TS_DPRINTK("ezx_ts_datareadok_irq: DIFF > XY_DIFF\n");
+            	SSP_PCAP_TSI_mode_set(PCAP_TS_POSITION_XY_MEASUREMENT);
+	            SSP_PCAP_TSI_start_XY_read(); 
+            	TS_DPRINTK("ezx_ts_datareadok_irq:x_pre=%d,y_pre=%d, x=%d,y=%d\n", ezxts.x_pre, ezxts.y_pre,x,y);
+	        }
+	        
+	        
+	        /*
+	        if ( ezx_ts_shake_samples_count < EZX_TS_SHAKE_SAMPLES )
+	        {
+	        	ezx_ts_shake_samples[ezx_ts_shake_samples_count].x = x;
+	        	ezx_ts_shake_samples[ezx_ts_shake_samples_count].y = y;
+	        	ezx_ts_shake_samples[ezx_ts_shake_samples_count++].pressure = PEN_DOWN;
+	            SSP_PCAP_TSI_mode_set(PCAP_TS_POSITION_XY_MEASUREMENT);
+                SSP_PCAP_TSI_start_XY_read();
+                TS_DPRINTK("ezx_ts_read_shake_samples%d:x=%d,y=%d\n", ezx_ts_shake_samples_count,x,y);
+		    }
+		    if (ezx_ts_shake_samples_count >= EZX_TS_SHAKE_SAMPLES)
+	        {
+	        	if ( (abs(ezx_ts_shake_samples[0].x - ezx_ts_shake_samples[1].x) > X_DIFF) ||
+                     (abs(ezx_ts_shake_samples[0].y - ezx_ts_shake_samples[1].y) > Y_DIFF) ||   	        	
+	        	     (abs(ezx_ts_shake_samples[1].x - ezx_ts_shake_samples[2].x) > X_DIFF) ||
+                     (abs(ezx_ts_shake_samples[1].y - ezx_ts_shake_samples[2].y) > Y_DIFF)
+                   )  
+                {   
+                	// throw these data and re-read
+	        	    ezx_ts_shake_samples_count = 0;
+	        	}
+	        	else //save to ts_event queue
+	        	{
+	        		ezxts.x_pre = ezxts.x_cur;
+		    		ezxts.y_pre = ezxts.y_cur;
+		    		TS_DPRINTK("ezx_ts_datareadok_irq:x_pre=%d,y_pre=%d\n", ezxts.x_pre, ezxts.y_pre);
+		    		ezxts.x_cur = (ezx_ts_shake_samples[0].x + ezx_ts_shake_samples[1].x + ezx_ts_shake_samples[2].x) / 3;
+	    			ezxts.y_cur = (ezx_ts_shake_samples[0].y + ezx_ts_shake_samples[1].y + ezx_ts_shake_samples[2].y) / 3;;
+    				ezx_ts_shake_samples_count = 0;
+	        		ezx_ts_evt_add(pressure, ezxts.x_cur, ezxts.y_cur);
+	        	}	    
+	        	ezx_ts_custom_timer_start();
+	        }	
+    	    */
+    	}    
+        else 
+        {
+             /* ezxts.x_pre and ezxts.y_pre store the last position */
+             tspenSampleCount ++;
+             if(1 == tspenSampleCount)
+             {
+                 ezxts.x_cur = x;
+                 ezxts.y_cur = y;   
+                 if( 0 == bSetPenupTimer )
+                 {              
+                     SSP_PCAP_TSI_mode_set(PCAP_TS_POSITION_XY_MEASUREMENT);
+                     SSP_PCAP_TSI_start_XY_read(); 
+                 }
+             }
+             else if (2 == tspenSampleCount)
+             {
+                 tspenSampleCount = 0;
+
+                 tempx = (ezxts.x_cur > x? ezxts.x_cur - x:x - ezxts.x_cur);
+                 tempy = (ezxts.y_cur > y? ezxts.y_cur - y:y - ezxts.y_cur);
+                 if(tempx <= X_DIFF && tempy <= Y_DIFF )
+                 {
+                     x = (x+ezxts.x_cur)/2;
+                     y = (y+ezxts.y_cur)/2;
+                     if( 1 == bFirstPen)
+                     {
+                         bFirstPen = 0;
+                         ezxts.x_pre = x;
+                         ezxts.y_pre = y;
+                     }
+                     tempx = ( ezxts.x_pre > x? ezxts.x_pre -x:x - ezxts.x_pre);
+                     tempy = ( ezxts.y_pre > y? ezxts.y_pre -y:y - ezxts.y_pre);
+                     if(tempx <= X_DIFF && tempy <= Y_DIFF )
+                     {
+                         tsDiscardDataCount = 0;
+                         if(tempx > MIN_X_HOLD || tempy > MIN_Y_HOLD)
+                         {
+                             ezxts.x_pre = x;
+                             ezxts.y_pre = y;
+                         }
+                         ezx_ts_evt_add(pressure, ezxts.x_pre, ezxts.y_pre);	                
+                         if ( bSetPenupTimer == 0 )
+                         {
+                             ezx_ts_set_timer(&ezx_ts_penup_timer, ezx_ts_penup_timeout, 
+    	        	              EZX_TS_PENSAMPLE_TIMEOUT_MS);
+                             TS_DPRINTK("ezx_ts_datareadok_irq: set timer pen sample\n");    	        	              
+                             bSetPenupTimer = 1;
+                         }
+                     }
+                     else
+                     {
+                         
+                         tsDiscardDataCount ++; 
+                         if(tsDiscardDataCount > SAMPLE_COUNT_NOT_JUMPER)
+                         {
+                             tsDiscardDataCount = 0;
+                             ezxts.x_pre = x;
+                             ezxts.y_pre = y;
+                             ezx_ts_evt_add(pressure, ezxts.x_pre, ezxts.y_pre);	                
+                             if ( bSetPenupTimer == 0 )
+                             {
+                                  ezx_ts_set_timer(&ezx_ts_penup_timer, ezx_ts_penup_timeout, 
+    	        	                          EZX_TS_PENSAMPLE_TIMEOUT_MS);
+                                  TS_DPRINTK("ezx_ts_datareadok_irq: set timer pen sample\n");    	        	              
+                                  bSetPenupTimer = 1;
+                             }
+                         }
+                         else if( 0 == bSetPenupTimer )
+                         {              
+                             SSP_PCAP_TSI_mode_set(PCAP_TS_POSITION_XY_MEASUREMENT);
+                             SSP_PCAP_TSI_start_XY_read(); 
+                         }
+                     }
+                 }
+                 else
+                 {
+                     if( 0 == bSetPenupTimer )
+                     {              
+                         SSP_PCAP_TSI_mode_set(PCAP_TS_POSITION_XY_MEASUREMENT);
+                         SSP_PCAP_TSI_start_XY_read(); 
+                     }
+                 }                                  
+             }
+             else /* discard the case */
+             {
+                 tspenSampleCount = 0;
+                 if( 0 == bSetPenupTimer )
+                 {              
+                     SSP_PCAP_TSI_mode_set(PCAP_TS_POSITION_XY_MEASUREMENT);
+                     SSP_PCAP_TSI_start_XY_read(); 
+                 }
+             }
+        }
+        /*if (penSampleCount >= gPenSamplesNum)
+        {
+            penSampleCount = 0;
+        }*/
+        //TS_DPRINTK("ezx_ts_datareadok_irq: read XY finished.\n");
+    }
+    
+}
+
+
+static struct file_operations ezx_ts_fops = {
+	.owner		= THIS_MODULE,
+	.read		= ezx_ts_read,
+	.poll		= ezx_ts_poll,
+	.open		= ezx_ts_open,
+	.release	= ezx_ts_release,
+	.fasync	    	= ezx_ts_fasync,
+	.ioctl      	= ezx_ts_ioctl,
+};
+
+/*
+ * miscdevice structure for misc driver registration.
+ */
+static struct miscdevice ezx_ts_dev = 
+{
+	.minor		= EZX_TS_MINOR_ID,
+	.name		= "ezx_ts",
+	.fops		= &ezx_ts_fops,
+};
+
+
+/*Register touch screen device in misc devices.*/
+static int ezx_ts_init(void)
+{
+	int ret;
+
+    init_waitqueue_head(&ezxts.read_wait);
+	ret = misc_register(&ezx_ts_dev);
+	
+	if (ret<0)
+	{
+	    printk("ezx_ts_dev: failed to registering the device\n");
+	}	
+    ezx_ts_custom_setup_timer();
+    
+    TS_DPRINTK("ezx_ts_init done.\n");
+	return ret;
+}	
+
+/*Unregister touch screen device.*/
+static void ezx_ts_exit(void)
+{
+	
+    if (bSetPenupTimer)
+    {
+        del_timer(&ezx_ts_penup_timer);
+        bSetPenupTimer = 0;
+    }
+    
+    ezx_ts_custom_timer_stop();
+    	
+	misc_deregister(&ezx_ts_dev);
+
+	TS_DPRINTK("ezx touch screen driver removed\n");
+}
+
+module_init(ezx_ts_init);
+module_exit(ezx_ts_exit);
+
+MODULE_DESCRIPTION("ezx touchscreen driver");
+MODULE_LICENSE("GPL");
+
+#endif
+
+static int __init ezxts_probe(struct platform_device *pdev)
+{
+	struct ezx_ts *ezx_ts;
+	struct input_dev *input_dev;
+	int err = -ENOMEM;
+
+	ezx_ts = kzalloc(sizeof(struct ezx_ts), GFP_KERNEL);
+	input_dev = input_allocate_device();
+	if (!ezx_ts || !input_dev)
+		goto fail;
+
+	platform_set_drvdata(pdev, ezx_ts);
+
+	...;
+
+	input_dev->name = "EZX PCAP2 Touchscreen";
+	input_dev->phys = "ezxts/input0";
+	input_dev->id.bustype = BUS_HOST;
+	input_dev->id.vendor = 0x0001;
+	input_dev->id.product = 0x0002;
+	input_dev->id.version = 0x0100;
+	input_dev->cdev.dev = &pdev->dev;
+	input_dev->private = ezx_ts;
+
+	input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
+	input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
+	input_set_abs_params(input_dev, ABS_X, X_AXIS_MIN, X_AXIS_MAX, 0, 0,);
+	input_set_abs_params(input_dev, ABS_Y, Y_AXIS_MIN, Y_AXIS_MAX, 0, 0,);
+
+	...;
+
+	input_register_device(ezx_ts->input);
+
+	return 0;
+
+fail:
+	input_free_device(input_dev);
+	kfree(ezx_ts);
+
+	return err;
+}
+
+static int ezxts_remove(struct platform_device *pdev)
+{
+	struct ezx_ts *ezx_ts = platform_get_drvdata(pdev);
+
+	input_unregister_device(ezx_ts->input);
+	kfree(ezx_ts);
+
+	return 0;
+}
+
+static struct platform_driver ezxts_driver = {
+	.probe		= ezxts_probe,
+	.remove		= ezxts_remove,
+	.suspend	= ezxts_suspend,
+	.resume		= ezxts_resume,
+	.driver		= {
+		.name	= "ezx-ts",
+	},
+};
+
+static int __devinit ezxts_init(void)
+{
+	return platform_driver_register(&ezxts_driver);
+}
+
+static void __exit ezxts_exit(void)
+{
+	platform_driver_unregister(&ezxts_driver);
+}
+
+MODULE_DESCRIPTION("Motorola EZX / PCAP2 touchscreen driver");
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Harald Welte <laforge@open-ezx.org>");