1 /****************************************************************************************
2 * driver/input/touchscreen/hannstar_nas.c
3 *Copyright :ROCKCHIP Inc
6 *This driver use for rk28 chip extern touchscreen. Use i2c IF ,the chip is Hannstar
8 ********************************************************************************************/
10 #include <linux/module.h>
11 #include <linux/delay.h>
12 #include <linux/earlysuspend.h>
13 #include <linux/hrtimer.h>
14 #include <linux/i2c.h>
15 #include <linux/input.h>
16 #include <linux/interrupt.h>
18 #include <linux/platform_device.h>
19 #include <linux/async.h>
20 #include <mach/gpio.h>
21 #include <linux/irq.h>
22 #include <mach/board.h>
23 #include <linux/proc_fs.h>
24 #include <asm/uaccess.h>
26 #include <linux/earlysuspend.h>
27 #define MAX_SUPPORT_POINT 2// // 4
28 #define PACKGE_BUFLEN 10
30 #define CHECK_STATUS 1
31 //#define TP_ERROR_RESTART_POWER 1
33 //#define Singltouch_Mode
34 //#define NAS_TP_DEBUG 0
37 #define sakura_dbg_msg(fmt,...) do { \
38 printk("sakura dbg msg------>" \
39 " (func-->%s ; line-->%d) " fmt, __func__, __LINE__ , ##__VA_ARGS__); \
41 #define sakura_dbg_report_key_msg(fmt,...) do{ \
42 printk("sakura report " fmt,##__VA_ARGS__); \
45 #define sakura_dbg_msg(fmt,...) do {} while(0)
46 #define sakura_dbg_report_key_msg(fmt,...) do{}while(0)
50 #define TOUCH_REPORT_X_MAX 1280//(1255) //(1280 - 1)//(0xfff)
51 #define TOUCH_REPORT_Y_MAX 768//(700) //(768 - 1)//(0xfff)
53 #define RECORD_PREVIOUS_VALUES
54 #define FILTER_SAME_POINTS
56 #define NASTECH_ZERO_TOUCH 0
57 #define NASTECH_ONE_TOUCH 1
58 #define NASTECH_TWO_TOUCH 2
59 #define NASTECH_PENUP_RECHECK 3
60 #define NASTECH_DeltaX 100
61 #define NASTECH_DeltaY 80
62 #define NASTECH_R_Threshold 4000
64 /*delay used to check the touch panel current status.*/
65 #define TS_RELEASE_CHECK_DELAY (100)
66 #define TS_CUR_STATUS_PUSH 1
67 #define TS_CUR_STATUS_RELEASE 0
68 #define TS_POLL_DELAY_DOWN (2) /* ms delay before the first sample */
69 #define TS_POLL_DELAY_UP (10) /* ms delay after pen up, to double check the pen up event */
70 #define TS_POLL_PERIOD (30) /* ms delay between samples */
71 #define PENUP_DETECT_MAX (4) /* How many times we should detect for a penup event. */
72 #define INT_TEST_TIMES 40
82 #ifdef RECORD_PREVIOUS_VALUES
97 struct multitouch_event{
98 struct point_data point_data[MAX_SUPPORT_POINT];
104 struct input_dev *input;
106 struct delayed_work work;
107 struct workqueue_struct *wq;
109 struct i2c_client *client;
110 struct multitouch_event mt_event;
116 int has_relative_report;
120 bool pendown_sent; /* Whether we've sent out a pendown event */
121 bool pendown_ignore; /* Sample two points and send out only one point */
122 int penup_recheck; /* Pen up re-check times, when it reaches PENUP_DETECTE_MAX, pen up is reported. */
123 int release_check_time; /* Debounse time for pen down, ms */
124 int pendown_debounce_time; /* Debounse time for pen down, ms */
125 int penup_debounce_time; /* Debounce time for pen up, ms */
126 int repeat_time; /* Time between samples, ms */
127 struct touch_point point;
128 struct timer_list status_check_timer;
129 int reported_finger_count;
130 int touch_cur_status;
132 int (*get_pendown_state)(void);
133 void (*clear_penirq)(void);
135 struct delayed_work work1;
136 struct workqueue_struct *wq1;
142 unsigned short y_gamma[]={
144 2 , 3 , 3 , 4 , 5 , 6 , 6 , 7 ,
145 8 , 9 , 10 , 10 , 11 , 12 , 13 , 14 ,
146 15 , 15 , 16 , 17 , 18 , 19 , 20 , 21 ,
147 21 , 22 , 23 , 24 , 25 , 26 , 27 , 28 ,
148 28 , 29 , 30 , 31 , 32 , 33 , 34 , 35 ,
149 36 , 37 , 38 , 38 , 39 , 40 , 41 , 42 ,
150 43 , 44 , 45 , 46 , 47 , 48 , 49 , 50 ,
151 51 , 52 , 52 , 53 , 54 , 55 , 56 , 57 ,
152 58 , 59 , 60 , 61 , 62 , 63 , 64 , 65 ,
153 66 , 67 , 68 , 69 , 70 , 71 , 72 , 73 ,
154 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 ,
155 82 , 83 , 84 , 85 , 86 , 87 , 88 , 89 ,
156 90 , 91 , 92 , 93 , 94 , 95 , 96 , 97 ,
157 98 , 99 , 100 , 101 , 102 , 103 , 104 , 105 ,
158 106 , 107 , 108 , 109 , 110 , 111 , 112 , 113 ,
159 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 ,
160 122 , 123 , 124 , 125 , 126 , 127 , 128 , 129 ,
161 130 , 132 , 133 , 134 , 135 , 136 , 137 , 138 ,
162 139 , 140 , 141 , 142 , 143 , 144 , 145 , 146 ,
163 147 , 148 , 149 , 150 , 151 , 152 , 154 , 155 ,
164 156 , 157 , 158 , 159 , 160 , 161 , 162 , 163 ,
165 164 , 165 , 166 , 167 , 168 , 169 , 171 , 172 ,
166 173 , 174 , 175 , 176 , 177 , 178 , 179 , 180 ,
167 181 , 182 , 183 , 184 , 186 , 187 , 188 , 189 ,
168 190 , 191 , 192 , 193 , 194 , 195 , 196 , 197 ,
169 199 , 200 , 201 , 202 , 203 , 204 , 205 , 206 ,
170 207 , 208 , 209 , 210 , 212 , 213 , 214 , 215 ,
171 216 , 217 , 218 , 219 , 220 , 221 , 222 , 224 ,
172 225 , 226 , 227 , 228 , 229 , 230 , 231 , 232 ,
173 233 , 235 , 236 , 237 };
175 unsigned short y_gamma900[]={
177 3 , 4 , 4 , 5 , 6 , 7 , 8 , 9 ,
178 10 , 11 , 12 , 12 , 13 , 14 , 15 , 16 ,
179 17 , 18 , 19 , 20 , 21 , 22 , 23 , 23 ,
180 24 , 25 , 26 , 27 , 28 , 29 , 30 , 31 ,
181 32 , 33 , 34 , 35 , 36 , 37 , 38 , 39 ,
182 40 , 41 , 42 , 42 , 43 , 44 , 45 , 46 ,
183 47 , 48 , 49 , 50 , 51 , 52 , 53 , 54 ,
184 55 , 56 , 57 , 58 , 59 , 60 , 61 , 62 ,
185 63 , 64 , 65 , 66 , 67 , 68 , 69 , 70 ,
186 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 ,
187 79 , 80 , 81 , 82 , 83 , 84 , 85 , 86 ,
188 87 , 88 , 89 , 90 , 91 , 92 , 93 , 94 ,
189 95 , 96 , 97 , 98 , 99 , 100 , 101 , 102 ,
190 103 , 104 , 105 , 106 , 107 , 108 , 109 , 110 ,
191 111 , 112 , 113 , 114 , 115 , 116 , 117 , 118 ,
192 119 , 120 , 121 , 122 , 123 , 124 , 125 , 126 ,
193 127 , 128 , 129 , 130 , 131 , 132 , 133 , 134 ,
194 135 , 136 , 137 , 138 , 139 , 140 , 141 , 142 ,
195 143 , 144 , 145 , 146 , 147 , 148 , 149 , 150 ,
196 152 , 153 , 154 , 155 , 156 , 157 , 158 , 159 ,
197 160 , 161 , 162 , 163 , 164 , 165 , 166 , 167 ,
198 168 , 169 , 170 , 171 , 172 , 173 , 174 , 175 ,
199 176 , 177 , 178 , 179 , 180 , 181 , 182 , 183 ,
200 185 , 186 , 187 , 188 , 189 , 190 , 191 , 192 ,
201 193 , 194 , 195 , 196 , 197 , 198 , 199 , 200 ,
202 201 , 202 , 203 , 204 , 205 , 206 , 207 , 208 ,
203 209 , 210 , 212 , 213 , 214 , 215 , 216 , 217 ,
204 218 , 219 , 220 , 221 , 222 , 223 , 224 , 225 ,
205 226 , 227 , 228 , 229 , 230 , 231 , 232 , 233 ,
206 235 , 236 , 237 , 238 };
209 unsigned short y_gamma800[]={
210 0 , 0 , 0 , 0 , 1 , 1 ,
211 2 , 2 , 3 , 3 , 4 , 5 , 5 , 6 ,
212 6 , 7 , 8 , 8 , 9 , 9 , 10 , 11 ,
213 11 , 12 , 13 , 13 , 14 , 15 , 16 , 16 ,
214 17 , 18 , 19 , 19 , 20 , 21 , 22 , 22 ,
215 23 , 24 , 25 , 25 , 26 , 27 , 28 , 29 ,
216 29 , 30 , 31 , 32 , 33 , 34 , 34 , 35 ,
217 36 , 37 , 38 , 39 , 40 , 40 , 41 , 42 ,
218 43 , 44 , 45 , 46 , 47 , 47 , 48 , 49 ,
219 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 ,
220 58 , 58 , 59 , 60 , 61 , 62 , 63 , 64 ,
221 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 ,
222 73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 ,
223 81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 ,
224 89 , 90 , 91 , 92 , 93 , 94 , 95 , 96 ,
225 97 , 98 , 99 , 100 , 101 , 102 , 103 , 104 ,
226 105 , 106 , 107 , 108 , 109 , 110 , 111 , 113 ,
227 114 , 115 , 116 , 117 , 118 , 119 , 120 , 121 ,
228 122 , 123 , 124 , 125 , 127 , 128 , 129 , 130 ,
229 131 , 132 , 133 , 134 , 135 , 136 , 137 , 139 ,
230 140 , 141 , 142 , 143 , 144 , 145 , 146 , 147 ,
231 149 , 150 , 151 , 152 , 153 , 154 , 155 , 157 ,
232 158 , 159 , 160 , 161 , 162 , 163 , 164 , 166 ,
233 167 , 168 , 169 , 170 , 171 , 173 , 174 , 175 ,
234 176 , 177 , 178 , 180 , 181 , 182 , 183 , 184 ,
235 185 , 187 , 188 , 189 , 190 , 191 , 192 , 194 ,
236 195 , 196 , 197 , 198 , 200 , 201 , 202 , 203 ,
237 204 , 206 , 207 , 208 , 209 , 210 , 212 , 213 ,
238 214 , 215 , 216 , 218 , 219 , 220 , 221 , 222 ,
239 224 , 225 , 226 , 227 , 229 , 230 , 231 , 232 ,
240 233 , 235 , 236 , 237 , 238 , 240 , 241 , 242 ,
241 243 , 245 , 246 , 247 , 248 , 250 , 251 , 252 ,
242 253 , 255 , 256 , 257 , 258 , 260 , 261 , 262
245 static struct proc_dir_entry *nas_tp_debug_ctl_entry;
246 static char nas_tp_debug_flag = 0;
248 extern void nas_reset(void);
249 static void nas_early_resume(struct early_suspend *h)
253 static struct early_suspend nastech_early_suspend =
255 .resume = nas_early_resume
258 static void nas_status_check_timer(unsigned long data)
260 unsigned char buf[4]={0};
261 struct ts_nas *ts_dev = (struct ts_nas *)data;
263 //printk("nas_status_check_timer ...\n");
264 queue_delayed_work(ts_dev->wq1, &ts_dev->work1, 0);
265 ts_dev->status_check_timer.expires = jiffies + msecs_to_jiffies(1000);
266 add_timer(&ts_dev->status_check_timer);
269 #define FB_DISPLAY_ON_PIN RK29_PIN6_PD0
270 extern void rk29_lcd_reset(void);
271 static void nas_status_check_work(struct work_struct *work1)
273 unsigned char buf[4]={0};
274 struct ts_nas *ts_dev =
275 container_of(to_delayed_work(work1), struct ts_nas, work1);
278 if (GPIO_LOW == gpio_get_value(FB_DISPLAY_ON_PIN))
281 //printk("nas_status_check_work ...");
282 ret = i2c_master_reg8_recv( ts_dev->client, 0xFC, buf, 1, 200*1000);
283 //printk(" ret = %d\n", ret);
286 printk("nas status error, ret=%d \nnas_reset()\n", ret);
287 #ifdef TP_ERROR_RESTART_POWER
295 /** Get point from touch pannel */
296 static int nastech_ts_get_point(struct ts_nas *ts_dev, unsigned short *pX, unsigned short *pY)
298 unsigned short xpos, ypos;
299 unsigned short xpos0, ypos0;
301 unsigned char Finger, hwFinger;
302 unsigned char buf[26];
303 //unsigned char buf[13]; // for 2 finger touch, only used the first 13 bytes
306 struct i2c_client *client = ts_dev->client;
307 struct input_dev *input = ts_dev->input;
309 memset(buf, 0xff, sizeof(buf));
310 //ret = nastech_read_regs(client, NASTECH_READ_POS, buf, sizeof(buf));
311 ret = i2c_master_reg8_recv( ts_dev->client, 0xF9, buf, 26, 200*1000);
315 //-------------------------------------------------------------------------------------------
316 //xpos=(unsigned short)(buf[7]*0x100);
317 xpos=(unsigned short)((buf[7]&0x0f)<<8 );
319 //ypos=(unsigned short)(buf[5]*0x100);
320 ypos=(unsigned short)((buf[5]&0x0f)<<8 );
323 //xpos0=(unsigned short)(buf[11]*0x100);
324 xpos0=(unsigned short)((buf[11]&0x0f)<<8 );
326 //ypos0=(unsigned short)(buf[9]*0x100);
327 ypos0=(unsigned short)((buf[9]&0x0f)<<8 );
329 //-------------------------------------------------------------------------------------------
331 //#ifdef NAS_TP_DEBUG
332 if (nas_tp_debug_flag == 1)
333 printk(KERN_INFO "read from TP: (%d,%d), (%d,%d)\n", xpos, ypos, xpos0, ypos0);
335 unsigned short ypos_pre,ratio;
342 #ifdef TOUCH_REPORT_ONLY_ONE_POINT
343 if(xpos==0x0FFF || ypos==0x0FFF)
345 Finger = NASTECH_ZERO_TOUCH;
349 Finger = NASTECH_ONE_TOUCH;
353 if(xpos==0x0FFF || ypos==0x0FFF)
355 Finger = NASTECH_ZERO_TOUCH;
359 Finger = NASTECH_ONE_TOUCH;
362 if(xpos0!=0x0FFF && ypos0!=0x0FFF)
364 Finger = NASTECH_TWO_TOUCH;
368 ypos = TOUCH_REPORT_Y_MAX - ypos;
376 ypos= y_gamma800[ratio];
383 ypos=767-y_gamma800[ratio];
393 xpos= y_gamma800[ratio];
400 xpos= 1279-y_gamma800[ratio];
405 //ypos=report_y_correction(y_pre); //mg for coorection
407 ypos0 = TOUCH_REPORT_Y_MAX - ypos0;
415 ypos0= y_gamma800[ratio];
422 ypos0=767-y_gamma800[ratio];
432 xpos0= y_gamma800[ratio];
439 xpos0= 1279-y_gamma800[ratio];
443 //#ifdef NAS_TP_DEBUG
444 if (nas_tp_debug_flag == 1) {
445 if (NASTECH_TWO_TOUCH == Finger) {
446 printk(KERN_INFO "original: (%d,%d), (%d,%d)\n", xpos, ypos, xpos0, ypos0);
447 } else if (NASTECH_ONE_TOUCH == Finger) {
448 printk(KERN_INFO "original: (%d,%d)\n", xpos, ypos);
452 //printk("nastech_ts_get_point: Finger = %d!\n",Finger);
453 #ifdef RECORD_PREVIOUS_VALUES
454 if (ts_dev->point.last_finger == Finger)
458 case NASTECH_ZERO_TOUCH:
460 case NASTECH_ONE_TOUCH:
461 if (ts_dev->point.x[0] == xpos && ts_dev->point.y[0] == ypos)
464 case NASTECH_TWO_TOUCH:
465 if ((ts_dev->point.x[0] == xpos && ts_dev->point.y[0] == ypos)
466 && (ts_dev->point.x[1] == xpos0 && ts_dev->point.y[1] == ypos0))
470 ts_dev->point.x[0] = xpos;
471 ts_dev->point.y[0] = ypos;
472 ts_dev->point.x[1] = xpos0;
473 ts_dev->point.y[1] = ypos0;
477 ts_dev->point.last_finger = Finger;
478 ts_dev->point.x[0] = xpos;
479 ts_dev->point.y[0] = ypos;
480 ts_dev->point.x[1] = xpos0;
481 ts_dev->point.y[1] = ypos0;
497 ts_dev->touch_cur_status = TS_CUR_STATUS_PUSH;
501 input_report_abs(input, ABS_MT_TOUCH_MAJOR, z);
502 input_report_abs(input, ABS_MT_WIDTH_MAJOR, w);
503 input_report_abs(input, ABS_MT_POSITION_X, xpos);
504 input_report_abs(input, ABS_MT_POSITION_Y, ypos);
505 input_report_key(ts_dev->input, BTN_TOUCH, 1);
506 input_mt_sync(input);
508 input_report_abs(input, ABS_MT_TOUCH_MAJOR, z);
509 input_report_abs(input, ABS_MT_WIDTH_MAJOR, w);
510 input_report_abs(input, ABS_MT_POSITION_X, xpos0);
511 input_report_abs(input, ABS_MT_POSITION_Y, ypos0);
512 input_report_key(ts_dev->input, BTN_2, 1);
513 input_mt_sync(input);
519 input_report_abs(input, ABS_MT_POSITION_X, xpos);
520 input_report_abs(input, ABS_MT_POSITION_Y, ypos);
521 input_report_abs(input, ABS_MT_TOUCH_MAJOR, z);
522 input_report_abs(input, ABS_MT_WIDTH_MAJOR, w);
523 input_report_key(ts_dev->input, BTN_TOUCH, 1);
524 input_mt_sync(input);
525 //printk("pen press (x,y):(%d,%d)\n",xpos,ypos);
529 // printk("nastech_ts_get_point: released......!\n");
530 input_report_abs(input, ABS_MT_POSITION_X, xpos);
531 input_report_abs(input, ABS_MT_POSITION_Y, ypos);
532 input_report_abs(input, ABS_MT_TOUCH_MAJOR, z);
533 input_report_abs(input, ABS_MT_WIDTH_MAJOR, w);
534 input_report_key(ts_dev->input, BTN_TOUCH, 0);
535 input_mt_sync(input);
536 ts_dev->touch_cur_status = TS_CUR_STATUS_RELEASE;
539 if(ts_dev->reported_finger_count > 1)
541 input_report_abs(input, ABS_MT_POSITION_X, xpos);
542 input_report_abs(input, ABS_MT_POSITION_Y, ypos);
543 input_report_abs(input, ABS_MT_TOUCH_MAJOR, 0);
544 input_report_abs(input, ABS_MT_WIDTH_MAJOR, 0);
545 input_report_key(ts_dev->input, BTN_2, 0);
546 input_mt_sync(input);
549 ts_dev->reported_finger_count = Finger;
556 static int nastech_sample_new_point(struct ts_nas *ts_dev)
559 unsigned int nTouch = 0;
561 struct i2c_client *client = ts_dev->client;
562 struct touch_point *point = &ts_dev->point;
564 nTouch = nastech_ts_get_point(ts_dev, &x, &y);
568 if (unlikely(NASTECH_ZERO_TOUCH == nTouch)) {
569 //printk(KERN_INFO "<======Pen released at (%d, %d)\n", point->prevX, point->prevY);
570 point->curX = point->curY = 0;
575 #ifdef TOUCHPANEL_SWAP_XY
577 int temp = point->curX;
578 point->curX = point->curY;
582 if(nTouch == NASTECH_ONE_TOUCH) {
583 if( !ts_dev->pendown_sent || (abs(point->curX-point->prevX) < NASTECH_DeltaX)
584 && (abs(point->curY - point->prevY) < NASTECH_DeltaY) ){ // is it a movement ?
585 // update pX, pY and send new point
586 point->prevX = point->curX;
587 point->prevY = point->curY;
589 printk(KERN_INFO "use the old touch: prev=(%d,%d), cur=(%d,%d)\n",
590 point->prevX, point->prevY, point->curX, point->curY);
592 point->curX = point->prevX;
593 point->curY = point->prevY;
599 int nas_get_pendown_state(void)
604 static void nas_report_event(struct ts_nas *ts,struct multitouch_event *tc)
606 struct input_dev *input = ts->input;
608 dev_dbg(&ts->client->dev, "UP\n");
610 for(i=0; i<MAX_SUPPORT_POINT;i++){
611 if(tc->point_data[i].status >= 0){
612 pandown |= tc->point_data[i].status;
613 input_report_abs(input, ABS_MT_TRACKING_ID, i);
614 input_report_abs(input, ABS_MT_TOUCH_MAJOR, tc->point_data[i].status);
615 input_report_abs(input, ABS_MT_WIDTH_MAJOR, 0);
616 input_report_abs(input, ABS_MT_POSITION_X, tc->point_data[i].x);
617 input_report_abs(input, ABS_MT_POSITION_Y, tc->point_data[i].y);
618 input_mt_sync(input);
620 sakura_dbg_report_key_msg("ABS_MT_TRACKING_ID = %x, ABS_MT_TOUCH_MAJOR = %x\n ABS_MT_POSITION_X = %x, ABS_MT_POSITION_Y = %x\n",i,tc->point_data[i].status,tc->point_data[i].x,tc->point_data[i].y);
621 #if defined(CONFIG_HANNSTAR_DEBUG)
622 printk("hannstar nas Px = [%d],Py = [%d] \n",tc->point_data[i].x,tc->point_data[i].y);
625 if(tc->point_data[i].status == 0)
626 tc->point_data[i].status--;
631 ts->pendown = pandown;
636 static inline int nas_check_firmwork(struct ts_nas *ts)
640 char buf[10] = {0x03 , 0x03 , 0x0a , 0x01 , 'D' , 0x00 , 0x00 , 0x00 , 0x00 , 0x00};
644 data = i2c_master_normal_send(ts->client, buf,len, 200*1000);
647 dev_err(&ts->client->dev, "i2c io error %d \n", data);
651 data = i2c_master_normal_recv(ts->client, buf,len, 200*1000);
654 dev_err(&ts->client->dev, "i2c io error %d \n", data);
658 printk("nas reg[5] = %c ,reg[6] = %c, reg[7] = %c, reg[8] = %c\n" , buf[5],buf[6],buf[7],buf[8]);
659 printk("nas reg[5] = %x ,reg[6] = %x, reg[7] = %x, reg[8] = %x\n" , buf[5],buf[6],buf[7],buf[8]);
664 static inline int nas_read_values(struct ts_nas *ts, struct multitouch_event *tc)
671 unsigned short xpos, ypos, xpos0, ypos0;
672 memset(buff, 0xff, sizeof(buff));
673 ret = i2c_master_reg8_recv( ts->client, 0xF9, buff, 26, 200*1000);
675 printk("ret = %d, buff[]=\n", ret);
680 printk("0x%02x ", buff[i]);
683 //-------------------------------------------------------------------------------------------
684 //xpos=(unsigned short)(buf[7]*0x100);
685 xpos=(unsigned short)((buff[7]&0x0f)<<8 );
687 //ypos=(unsigned short)(buf[5]*0x100);
688 ypos=(unsigned short)((buff[5]&0x0f)<<8 );
691 //xpos0=(unsigned short)(buf[11]*0x100);
692 xpos0=(unsigned short)((buff[11]&0x0f)<<8 );
693 xpos0=xpos0|buff[12];
694 //ypos0=(unsigned short)(buf[9]*0x100);
695 ypos0=(unsigned short)((buff[9]&0x0f)<<8 );
696 ypos0=ypos0|buff[10];
697 //-------------------------------------------------------------------------------------------
699 // printk("read from TP: (%d,%d), (%d,%d)\n", xpos, ypos, xpos0, ypos0);
704 static void nas_work(struct work_struct *work)
707 container_of(to_delayed_work(work), struct ts_nas, work);
708 struct multitouch_event *tc = &ts->mt_event;
711 rt = nas_read_values(ts,tc);
716 #if defined (Singltouch_Mode)
717 nas_report_single_event(ts,tc);
719 nas_report_event(ts,tc);
723 // if (ts->sleepstatus == 1)
726 switch(nastech_sample_new_point(ts)) {
727 case NASTECH_ZERO_TOUCH:
729 case NASTECH_ONE_TOUCH:
730 case NASTECH_TWO_TOUCH:
733 /* periodly sample the next points */
734 del_timer(&ts->repeat_timer);
735 ts->repeat_timer.expires = jiffies + msecs_to_jiffies(ts->repeat_time);
736 add_timer(&ts->repeat_timer);
748 queue_delayed_work(ts->wq, &ts->work, msecs_to_jiffies(10));
757 static irqreturn_t nas_irq(int irq, void *handle)
759 struct ts_nas *ts = handle;
760 //printk("enter nas_irq()\n");
762 if (!ts->get_pendown_state || likely(ts->get_pendown_state())) {
763 //printk("disable_irq_nosync()\n");
764 disable_irq_nosync(ts->irq);
765 queue_delayed_work(ts->wq, &ts->work, 0);
772 static void nas_free_irq(struct ts_nas *ts)
774 free_irq(ts->irq, ts);
775 if (cancel_delayed_work_sync(&ts->work)) {
777 * Work was pending, therefore we need to enable
778 * IRQ here to balance the disable_irq() done in the
786 static ssize_t nas_tp_debug_ctl(struct file *file, const char __user *buffer, size_t count, loff_t *data)
790 if (copy_from_user(&val, buffer, 1))
793 if (val != '0' && val != '1')
796 nas_tp_debug_flag = val - '0';
801 static int __devinit nas_probe(struct i2c_client *client,
802 const struct i2c_device_id *id)
805 struct nas_platform_data *pdata = pdata = client->dev.platform_data;
806 struct input_dev *input_dev;
810 dev_err(&client->dev, "platform data is required!\n");
814 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
817 ts = kzalloc(sizeof(struct ts_nas), GFP_KERNEL);
818 input_dev = input_allocate_device();
819 if (!ts || !input_dev) {
825 ts->irq = client->irq;
826 ts->input = input_dev;
827 ts->status =0 ;// fjp add by 2010-9-30
828 ts->pendown = 0; // fjp add by 2010-10-06
830 ts->wq = create_rt_workqueue("nas_wq");
831 INIT_DELAYED_WORK(&ts->work, nas_work);
834 ts->wq1 = create_rt_workqueue("nas_wq1");
835 INIT_DELAYED_WORK(&ts->work1, nas_status_check_work);
837 ts->model = pdata->model;
839 snprintf(ts->phys, sizeof(ts->phys),
840 "%s/input0", dev_name(&client->dev));
842 input_dev->name = "nas Touchscreen";
843 input_dev->phys = ts->phys;
844 input_dev->id.bustype = BUS_I2C;
846 ts->has_relative_report = 0;
847 input_dev->evbit[0] = BIT_MASK(EV_ABS)|BIT_MASK(EV_KEY)|BIT_MASK(EV_SYN);
848 input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
849 input_dev->keybit[BIT_WORD(BTN_2)] = BIT_MASK(BTN_2); //jaocbchen for dual
851 input_set_abs_params(input_dev, ABS_X, 0, CONFIG_HANNSTAR_MAX_X, 0, 0);
852 input_set_abs_params(input_dev, ABS_Y, 0, CONFIG_HANNSTAR_MAX_Y, 0, 0);
853 input_set_abs_params(input_dev, ABS_PRESSURE, 0, 255, 0, 0);
854 input_set_abs_params(input_dev, ABS_TOOL_WIDTH, 0, 15, 0, 0);
855 input_set_abs_params(input_dev, ABS_HAT0X, 0, CONFIG_HANNSTAR_MAX_X, 0, 0);
856 input_set_abs_params(input_dev, ABS_HAT0Y, 0, CONFIG_HANNSTAR_MAX_Y, 0, 0);
857 input_set_abs_params(input_dev, ABS_MT_POSITION_X,0, CONFIG_HANNSTAR_MAX_X, 0, 0);
858 input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0, CONFIG_HANNSTAR_MAX_Y, 0, 0);
859 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
860 input_set_abs_params(input_dev, ABS_MT_WIDTH_MAJOR, 0, 255, 0, 0);
861 input_set_abs_params(input_dev, ABS_MT_TRACKING_ID, 0, 10, 0, 0);
863 input_set_abs_params(input_dev, ABS_X, 0, TOUCH_REPORT_X_MAX, 0, 0);
864 input_set_abs_params(input_dev, ABS_Y, 0, TOUCH_REPORT_Y_MAX, 0, 0);
865 input_set_abs_params(input_dev, ABS_PRESSURE, 0, 1, 0, 0);
866 input_set_abs_params(input_dev, ABS_HAT0X, 0, TOUCH_REPORT_X_MAX, 0, 0);
867 input_set_abs_params(input_dev, ABS_HAT0Y, 0, TOUCH_REPORT_Y_MAX, 0, 0);
868 input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0, TOUCH_REPORT_X_MAX, 0, 0);
869 input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0, TOUCH_REPORT_Y_MAX, 0, 0);
870 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
871 input_set_abs_params(input_dev, ABS_MT_WIDTH_MAJOR, 0, 15, 0, 0);
873 if (pdata->init_platform_hw)
874 pdata->init_platform_hw();
877 dev_dbg(&ts->client->dev, "no IRQ?\n");
880 ts->irq = gpio_to_irq(ts->irq);
883 err = request_irq(ts->irq, nas_irq, GPIOEdgelFalling,
884 client->dev.driver->name, ts);
885 // err = request_irq(ts->irq, nas_irq, 0,
886 // client->dev.driver->name, ts);
889 dev_err(&client->dev, "irq %d busy?\n", ts->irq);
896 err = set_irq_type(ts->irq,IRQ_TYPE_LEVEL_LOW);
898 dev_err(&client->dev, "irq %d busy?\n", ts->irq);
904 err = input_register_device(input_dev);
908 i2c_set_clientdata(client, ts);
910 nas_check_firmwork(ts);
912 nas_tp_debug_ctl_entry = create_proc_entry("nas_tp_debug_ctl", 0644, NULL);
913 if (nas_tp_debug_ctl_entry) {
914 nas_tp_debug_ctl_entry->read_proc = NULL;
915 nas_tp_debug_ctl_entry->write_proc = nas_tp_debug_ctl;
917 #ifdef CONFIG_HAS_EARLYSUSPEND
918 register_early_suspend(&nastech_early_suspend);
922 setup_timer(&ts->status_check_timer, nas_status_check_timer, (unsigned long)ts);
923 ts->status_check_timer.expires = jiffies + msecs_to_jiffies(1000);
924 add_timer(&ts->status_check_timer);
930 if (pdata->exit_platform_hw)
931 pdata->exit_platform_hw();
933 input_free_device(input_dev);
938 static int __devexit nas_remove(struct i2c_client *client)
940 struct ts_nas *ts = i2c_get_clientdata(client);
941 struct nas_platform_data *pdata = client->dev.platform_data;
945 if (pdata->exit_platform_hw)
946 pdata->exit_platform_hw();
948 input_unregister_device(ts->input);
951 if (nas_tp_debug_ctl_entry)
952 remove_proc_entry("nas_tp_debug_ctl", NULL);
957 static struct i2c_device_id nas_idtable[] = {
962 MODULE_DEVICE_TABLE(i2c, nas_idtable);
964 static struct i2c_driver nas_driver = {
966 .owner = THIS_MODULE,
969 .id_table = nas_idtable,
971 .remove = __devexit_p(nas_remove),
974 static void __init nas_init_async(void *unused, async_cookie_t cookie)
976 printk("--------> %s <-------------\n",__func__);
977 i2c_add_driver(&nas_driver);
980 static int __init nas_init(void)
982 async_schedule(nas_init_async, NULL);
986 static void __exit nas_exit(void)
988 return i2c_del_driver(&nas_driver);
990 module_init(nas_init);
991 module_exit(nas_exit);
992 MODULE_LICENSE("GPL");