input: touchscreen: add touch screen of gslx680 for rk3399-firefly-edp
[firefly-linux-kernel-4.4.55.git] / drivers / input / touchscreen / ct36x_ts.c
1 /*
2  * drivers/input/touchscreen/gt801_ts.c
3  *
4  * Copyright (C) 2010 ROCKCHIP, Inc.
5  *
6  * This software is licensed under the terms of the GNU General Public
7  * License version 2, as published by the Free Software Foundation, and
8  * may be copied, distributed, and modified under those terms.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  */
15
16 #include <linux/module.h>
17 #include <linux/delay.h>
18 #include <linux/earlysuspend.h>
19 #include <linux/hrtimer.h>
20 #include <linux/i2c.h>
21 #include <linux/input.h>
22 #include <linux/input/mt.h>
23 #include <linux/interrupt.h>
24 #include <linux/io.h>
25 #include <linux/slab.h>
26 #include <linux/gpio.h>
27 #include <mach/iomux.h>
28 #include <mach/board.h>
29 #include <linux/platform_device.h>
30
31
32 #define CT360_DEBUG                     0
33 #define MYCT360_DEBUG                 0
34
35 #if CT360_DEBUG
36         #define ct360printk(msg...)     printk(msg);
37 #else
38         #define ct360printk(msg...)
39 #endif
40
41 #if 0
42         #define  yj_printk(msg...)  printk(msg);
43 #else
44         #define  yj_printk(msg...)
45 #endif
46
47 #if 0
48         #define  boot_printk(msg...)  printk(msg);
49 #else
50         #define  boot_printk(msg...)
51 #endif
52
53 #if MYCT360_DEBUG
54         #define myct360printk(msg...)   printk(msg);
55 #else
56         #define myct360printk(msg...)
57 #endif
58
59 #define IOMUX_NAME_SIZE 48
60
61 enum regadd {
62         ptxh = 0, ptxl = 1, ptyh = 2, ptyl = 3, ptpressure = 4,
63 };
64 enum touchstate {
65         TOUCH_UP = 0, TOUCH_DOWN = 1,
66 };
67
68
69 #define TOUCH_NUMBER 10
70 #define TOUCH_REG_NUM 6 
71
72 #define ct360_TS_NAME "ct3610_ts"
73
74 struct ct360_ts_data {
75         u16             x_max;  
76         u16             y_max;
77         bool    swap_xy;           //define?
78         int     irq;
79         struct  i2c_client *client;
80     struct      input_dev *input_dev;
81         struct workqueue_struct *ct360_wq;
82     struct      work_struct  work;
83     struct      early_suspend early_suspend;
84 };
85 /*tochscreen private data*/
86 static int touch_state[TOUCH_NUMBER] = {TOUCH_UP,TOUCH_UP};
87
88 #ifdef CONFIG_HAS_EARLYSUSPEND
89 static void ct360_ts_early_suspend(struct early_suspend *h);
90 static void ct360_ts_late_resume(struct early_suspend *h);
91 #endif
92
93 /*read the ct360 register ,used i2c bus*/
94 static int ct360_read_regs(struct i2c_client *client, u8 buf[], unsigned len)
95 {
96         int ret;
97         ret =i2c_master_normal_recv(client, buf, len, 400*1000);
98         if(ret < 0)
99                 printk("ct360_ts_work_func:i2c_transfer fail =%d\n",ret);
100         return ret;
101 }
102 /* set the ct360 registe,used i2c bus*/
103 static int ct360_write_regs(struct i2c_client *client, u8 reg, u8 const buf[], unsigned short len)
104 {
105         int ret;
106         ret = i2c_master_reg8_send(client,reg, buf, len, 100*1000);
107         if (ret < 0) {
108           printk("ct360_ts_work_func:i2c_transfer fail =%d\n",ret);
109     }
110         return ret;
111 }
112
113 char const  Binary_Data[32768]=
114 {
115 //#include "CT365RC972030D_V39120329A_waterproof_1.dat"
116 #include "CT36X_JS_DS_973H_LX20x30_V18120810W.txt"
117 };
118
119 char CTP_BootLoader(struct ct360_ts_data *ts)
120 {
121         unsigned int i = 0 ; 
122         unsigned int j = 0 ;  
123         unsigned int version = 0;
124         char value = 0;
125         char I2C_Buf[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
126         unsigned int Flash_Address = 0 ;                                
127         char CheckSum[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};                  // 128/8 = 16 times 
128
129         //--------------------------------------
130         // Step1 --> initial BootLoader
131         // Note. 0x7F -> 0x00 -> 0xA5 ;
132         //--------------------------------------
133         I2C_Buf [0] = 0x00;     
134         I2C_Buf [1] = 0xA5;                     
135
136         ts->client->addr = 0x7F;
137         ct360_write_regs(ts->client,0x00,&I2C_Buf[1], 1);                                       // Host issue 0xA5 Command to CT365  
138         mdelay(3);                                                                              // Delay 1 ms 
139
140
141         //------------------------------
142         // Reset I2C Offset address
143         // Note. 0x7F -> 0x00   
144         //------------------------------
145         I2C_Buf [0] = 0x00 ;            
146         i2c_master_normal_send(ts->client,I2C_Buf, 1,100*1000);                                 // Reset CT365 I2C Offset address   
147         udelay(500);                                                                    // Delay 500 us         
148
149         //------------------------------
150         // Read I2C Bus status
151         //------------------------------
152         i2c_master_normal_recv(ts->client,&value, 1,100*1000);
153
154         boot_printk("%s......0...\n",__FUNCTION__);
155         // if return "AAH" then going next step
156         if (value != 0xAA)
157                 return 0;               
158
159         boot_printk("%s......1...\n",__FUNCTION__);
160
161         {
162                 I2C_Buf[0] = 0x00;
163                 I2C_Buf[1] = 0x99;                                                                                                              // Generate check sum command
164                 I2C_Buf[2] = (char)(0x0044 >> 8);                       // define a flash address for CT365 to generate check sum       
165                 I2C_Buf[3] = (char)(0x0044 & 0xFF);             //
166                 I2C_Buf[4] = 0x08;                                                                                                              // Define a data length for CT365 to generate check sum 
167
168                 i2c_master_normal_send(ts->client,I2C_Buf, 5,100*1000);                                                         // Write Genertate check sum command to CT365
169
170                 mdelay(1);                                                                                                                                      // Delay 1 ms
171
172                 i2c_master_reg8_recv(ts->client,0x00, I2C_Buf,13, 100*1000);                                    // Read check sum and flash data from CT365
173                 if (!(I2C_Buf[5] != 'V') || (I2C_Buf[9] != 'T'))
174                         version = 1;            
175         }         
176
177         {
178                 I2C_Buf[0] = 0x00;
179                 I2C_Buf[1] = 0x99;                                                                                                              // Generate check sum command
180                 I2C_Buf[2] = (char)(0x00a4 >> 8);                       // define a flash address for CT365 to generate check sum       
181                 I2C_Buf[3] = (char)(0x00a4 & 0xFF);             //
182                 I2C_Buf[4] = 0x08;                                                                                                              // Define a data length for CT365 to generate check sum 
183
184                 i2c_master_normal_send(ts->client,I2C_Buf, 5,100*1000);                                                         // Write Genertate check sum command to CT365
185
186                 mdelay(1);                                                                                                                                      // Delay 1 ms
187
188                 i2c_master_reg8_recv(ts->client,0x00, I2C_Buf,13, 100*1000);                                    // Read check sum and flash data from CT365
189                 if (!(I2C_Buf[5] != 'V') || (I2C_Buf[9] != 'T'))
190                         version = 2;            
191         }       
192
193         if (!version)
194                 return 0;
195
196         //------------------------------
197         // Reset I2C Offset address
198         // Note. 0x7F -> 0x00   
199         //------------------------------
200         I2C_Buf [0] = 0x00;     
201         I2C_Buf [1] = 0xA5;                     
202
203         i2c_master_normal_send(ts->client,I2C_Buf, 2,100*1000);                                 // Host issue 0xA5 Command to CT365  
204         mdelay(3);
205
206         I2C_Buf [0] = 0x00 ;            
207         i2c_master_normal_send(ts->client,I2C_Buf, 1,100*1000);                                 // Reset CT365 I2C Offset address   
208         udelay(500);            
209         //-----------------------------------------------------
210         // Step 2 : Erase 32K flash memory via Mass Erase (33H)  
211         // 0x7F --> 0x00 --> 0x33 --> 0x00 ; 
212         //-----------------------------------------------------
213         I2C_Buf [0] = 0x00;                                                                                             // Offset address 
214         I2C_Buf [1] = 0x33;                                                                                             // Mass Erase command
215         I2C_Buf [2] = 0x00;  
216
217         i2c_master_normal_send(ts->client,I2C_Buf,3,100*1000);
218         mdelay(10);                                                                                                     // Delay 10 mS
219
220
221         //------------------------------
222         // Reset I2C Offset address
223         // Note. 0x7F -> 0x00   
224         //------------------------------
225         I2C_Buf [0] = 0x00 ;            
226         i2c_master_normal_send(ts->client,I2C_Buf, 1,100*1000);                                         // Reset CT365 I2C Offset address   
227         udelay(500);                                                                                                    // Delay 500 us         
228
229
230         //------------------------------
231         // Read I2C Bus status
232         //------------------------------
233         i2c_master_normal_recv(ts->client,&value, 1,100*1000);
234
235         // if return "AAH" then going next step
236         if (value != 0xAA)
237                 return 0;               
238
239         boot_printk("%s......2...\n",__FUNCTION__);
240
241         //----------------------------------------
242         // Step3. Host write 128 bytes to CT365  
243         // Step4. Host read checksum to verify ;
244         // Write/Read for 256 times ( 32k Bytes )
245         //----------------------------------------
246
247         for ( j = 0 ; j < 256 ; j++ )                                                   // 32k/128 = 256 times 
248         {
249                 Flash_Address = 128*j ;                                                         // 0 ~ 127 ; 128 ~ 255 ; 
250
251                 for ( i = 0 ; i < 16 ; i++ )                                    // 128/8 = 16 times for One Row program 
252                 {
253                         // Step 3 : write binary data to CT365  
254                         I2C_Buf[0] = 0x00;                                                                                                                      // Offset address 
255                         I2C_Buf[1] = 0x55;                                                                                                                      // Flash write command
256                         I2C_Buf[2] = (char)(Flash_Address  >> 8);                       // Flash address [15:8]
257                         I2C_Buf[3] = (char)(Flash_Address & 0xFF);                      // Flash address [7:0]
258                         I2C_Buf[4] = 0x08;                                                              // Data Length 
259                         I2C_Buf[6] = Binary_Data[Flash_Address + 0];            // Binary data 1
260                         I2C_Buf[7] = Binary_Data[Flash_Address + 1];            // Binary data 2
261                         I2C_Buf[8] = Binary_Data[Flash_Address + 2];            // Binary data 3
262                         I2C_Buf[9] = Binary_Data[Flash_Address + 3];            // Binary data 4
263                         I2C_Buf[10] = Binary_Data[Flash_Address + 4];           // Binary data 5
264                         I2C_Buf[11] = Binary_Data[Flash_Address + 5];           // Binary data 6
265                         I2C_Buf[12] = Binary_Data[Flash_Address + 6];           // Binary data 7
266                         I2C_Buf[13] = Binary_Data[Flash_Address + 7];           // Binary data 8
267
268                         // Calculate a check sum by Host controller. 
269                         // Checksum = / (FLASH_ADRH+FLASH_ADRL+LENGTH+
270                         // Binary_Data1+Binary_Data2+Binary_Data3+Binary_Data4+
271                         // Binary_Data5+Binary_Data6+Binary_Data7+Binary_Data8) + 1 
272                         CheckSum[i] = ~(I2C_Buf[2] + I2C_Buf[3] + I2C_Buf[4] + I2C_Buf[6] + I2C_Buf[7] + 
273                         I2C_Buf[8] + I2C_Buf[9] + I2C_Buf[10] + I2C_Buf[11] + I2C_Buf[12] +
274                         I2C_Buf[13]) + 1; 
275
276                         I2C_Buf[5] = CheckSum[i];                                                                               // Load check sum to I2C Buffer 
277
278                         i2c_master_normal_send(ts->client,I2C_Buf, 14,100*1000);                                                                        // Host write I2C_Buf[0¡K12] to CT365. 
279
280                         mdelay(1);                                                                                                      // 8 Bytes program --> Need 1 ms delay time 
281
282                         Flash_Address += 8 ;                                                                                    // Increase Flash Address. 8 bytes for 1 time 
283
284                 }
285
286                 mdelay(20);                                                                                                                             // Each Row command --> Need 20 ms delay time 
287
288                 Flash_Address = 128*j ;                                                                                 // 0 ~ 127 ; 128 ~ 255 ; 
289
290                 // Step4. Verify process 
291                 for ( i = 0 ; i < 16 ; i++ )                                                                            // 128/8 = 16 times for One Row program 
292                 {
293                         //Step 4 : Force CT365 generate check sum for host to compare data. 
294                         //Prepare get check sum from CT365
295                         I2C_Buf[0] = 0x00;
296                         I2C_Buf[1] = 0x99;                                                                                                              // Generate check sum command
297                         I2C_Buf[2] = (char)(Flash_Address >> 8);                        // define a flash address for NT1100x to generate check sum     
298                         I2C_Buf[3] = (char)(Flash_Address & 0xFF);              //
299                         I2C_Buf[4] = 0x08;                                                                                                              // Define a data length for CT36x to generate check sum 
300
301                         i2c_master_normal_send(ts->client,I2C_Buf, 5,100*1000);                                                                 // Write Genertate check sum command to CT365
302
303                         mdelay(1);                                                                                                                                      // Delay 1 ms
304
305                         i2c_master_reg8_recv(ts->client,0x00,I2C_Buf, 13,100*1000);                                             // Read check sum and flash data from CT365
306
307                         // Compare host check sum with CT365 check sum(I2C_Buf[4])
308                         if ( I2C_Buf[4] != CheckSum[i] )
309                         {
310                                 boot_printk("%s......3...\n",__FUNCTION__);
311                                 return 0;
312                         }
313
314                         Flash_Address += 8;                                                                                                             // Increase Flash Address.
315
316                 }
317
318         }       
319
320         ts->client->addr = 0x01;
321         boot_printk("%s......4...\n",__FUNCTION__);
322         return  1 ; 
323
324 }
325
326 static void ct360_ts_work_func(struct work_struct *work)
327 {
328         
329         unsigned short x;
330         unsigned short y;
331         int i,ret,syn_flag=0;
332         char toatl_num = 0;
333         unsigned char buf[TOUCH_REG_NUM*TOUCH_NUMBER+1] = {0};
334         int point_status;
335         int point_num,point_pressure;
336         
337         struct ct360_ts_data *ts = container_of(work,struct ct360_ts_data,work);
338
339         ret= ct360_read_regs(ts->client,buf,60);//only one data  represent the current touch num
340         if (ret < 0) {
341                 printk("%s:i2c_transfer fail =%d\n",__FUNCTION__,toatl_num);
342                 goto out;
343                 return;
344     }
345
346     for (i=0; i<60; i+=TOUCH_REG_NUM)
347     {
348                 if (((buf[i+1] << 4)|(buf[i+3] >> 4)) != 0x0fff)
349                 {
350                         x = ((buf[i+1] << 4)|(buf[i+3] >> 4));
351                         y = ((buf[i+2] << 4)|(buf[i+3]&0x0F));
352                         point_status=buf[i]&0x07;
353                         point_num = buf[i]>>3;
354                         point_pressure = (buf[i+5]*4)>=255? 255 : (buf[i+5]*4);
355
356                         if((point_status == 1) || (point_status == 2)){
357                                 input_mt_slot(ts->input_dev, point_num-1);
358                                 input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, point_num-1);
359                                 input_report_abs(ts->input_dev, ABS_MT_POSITION_X, x);
360                                 input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, y);
361                                 input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, point_pressure); //Finger Size
362                                 input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, point_pressure); //Touch Size
363                                 //input_mt_sync(ts->input_dev);
364                                 syn_flag = 1;
365                                 touch_state[point_num-1] = TOUCH_DOWN;
366                         }
367                         else if(point_status == 3){
368                                 input_mt_slot(ts->input_dev, point_num-1);
369                                 input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, -1);
370                                 touch_state[point_num-1] = TOUCH_UP;
371                                 syn_flag =1;
372                         }
373                 }
374         }
375         
376         if(syn_flag){
377                 input_sync(ts->input_dev);
378     }
379
380 out:
381         enable_irq(ts->irq);
382         return;
383 }
384
385 static irqreturn_t ct360_ts_irq_handler(int irq, void *dev_id)
386 {
387     struct ct360_ts_data *ts = dev_id;
388     
389         disable_irq_nosync(ts->irq);
390         queue_work(ts->ct360_wq, &ts->work);
391
392     return IRQ_HANDLED;
393 }
394
395 static int ct360_ts_probe(struct i2c_client *client, const struct i2c_device_id *id)
396 {
397     struct ct360_ts_data *ts;
398         struct ct360_platform_data      *pdata = client->dev.platform_data;
399         int ret = 0;
400         char loader_buf[2] = {0x3f,0xff};
401         char boot_buf = 0;
402         char boot_loader[2] = {0};
403     printk("%s \n",__FUNCTION__);
404         
405     if (!pdata) {
406                 dev_err(&client->dev, "empty platform_data\n");
407                 goto err_check_functionality_failed;
408     }
409     if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
410         printk(KERN_ERR "ct360_ts_probe: need I2C_FUNC_I2C\n");
411         ret = -ENODEV;
412         goto err_check_functionality_failed;
413     }
414         
415     ts = kzalloc(sizeof(*ts), GFP_KERNEL);
416     if (ts == NULL) {
417         ret = -ENOMEM;
418         goto err_alloc_data_failed;
419     }
420
421     ts->ct360_wq = create_singlethread_workqueue("ct360_wq");
422     if (!ts->ct360_wq){
423                 printk(KERN_ERR"%s: create workqueue failed\n", __func__);
424                 ret = -ENOMEM;
425                 goto err_input_dev_alloc_failed;
426         }
427
428     INIT_WORK(&ts->work, ct360_ts_work_func);
429
430     ts->client = client;
431     i2c_set_clientdata(client, ts);
432         
433         if(pdata->hw_init)
434                 pdata->hw_init();
435
436         if(pdata->shutdown){
437                 pdata->shutdown(1);
438                 mdelay(200);
439                 pdata->shutdown(0);
440                 mdelay(50);
441                 pdata->shutdown(1);
442                 mdelay(50);
443         }
444         //¼Ó40msÑÓʱ£¬·ñÔò¶ÁÈ¡³ö´í¡£¡£
445         mdelay(40);
446         ret=ct360_write_regs(client,0xfF, loader_buf, 2);       
447         if(ret<0){
448                 printk("\n--%s--Set Register values error !!!\n",__FUNCTION__);
449         }
450
451         mdelay(1);
452         printk("%s...........%d\n",__FUNCTION__,boot_buf);
453         ret = i2c_master_normal_send(client,boot_loader,1,100*1000);
454         if(ret < 0)
455                 printk("ct360_ts_probe:sdf  i2c_transfer fail =%d\n",ret);
456         else
457                 printk("%s.............ok\n",__FUNCTION__);     
458
459         mdelay(2);
460         ret = ct360_read_regs(client,&boot_buf,1);
461         printk("%s....3......%x\n",__FUNCTION__,boot_buf);
462         
463         if(ret < 0)
464                 printk("ct360_ts_probe:i2c_transfer fail =%d\n",ret);
465         else
466                 printk("%s.............boot_buf=%d\n",__FUNCTION__,boot_buf);
467
468         if (Binary_Data[32756] != boot_buf)
469         {
470                 printk("start Bootloader ...........boot_Buf=%x.....%d......%x..........TP \n\n",boot_buf,(Binary_Data[16372]-boot_buf),Binary_Data[16372]);
471                 ret = CTP_BootLoader(ts);
472                 if (ret == 1)
473                         printk("TP Bootloader success\n");
474                 else
475                         printk("TP Bootloader failed  ret=%d\n",ret);
476                 printk("stop Bootloader.................................TP \n\n");
477         }
478         else
479         {
480                 printk("Don't need bootloader.skip it %x \n",Binary_Data[16372]);
481         }
482
483         if(pdata->shutdown){
484                 pdata->shutdown(1);
485                 mdelay(5);
486                 pdata->shutdown(0);
487                 mdelay(20);
488                 pdata->shutdown(1);
489                 mdelay(20);
490         }
491         ts->client->addr = 0x01;
492         
493     /* allocate input device */
494     ts->input_dev = input_allocate_device();
495     if (ts->input_dev == NULL) {
496         ret = -ENOMEM;
497         printk(KERN_ERR "%s: Failed to allocate input device\n",__FUNCTION__);
498         goto err_input_dev_alloc_failed;
499     }
500         
501         ts->x_max = pdata->x_max;
502         ts->y_max = pdata->y_max;
503         ts->swap_xy = 1;
504         ts->input_dev->name = ct360_TS_NAME;
505         ts->input_dev->dev.parent = &client->dev;
506
507         //set_bit(EV_SYN, ts->input_dev->evbit);
508         //set_bit(BTN_TOUCH, ts->input_dev->keybit);
509         set_bit(EV_ABS, ts->input_dev->evbit);
510         set_bit(INPUT_PROP_DIRECT, ts->input_dev->propbit);
511         //set_bit(BTN_2, ts->input_dev->keybit);
512
513         input_mt_init_slots(ts->input_dev, TOUCH_NUMBER);
514     input_set_abs_params(ts->input_dev, ABS_MT_POSITION_X, 0, ts->x_max, 0, 0);
515     input_set_abs_params(ts->input_dev, ABS_MT_POSITION_Y, 0, ts->y_max, 0, 0);
516     input_set_abs_params(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0); //Finger Size
517     input_set_abs_params(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0, 255, 0, 0); //Touch Size
518     input_set_abs_params(ts->input_dev, ABS_MT_TRACKING_ID, 0, 10, 0, 0); //Touch Size
519
520     ret = input_register_device(ts->input_dev);
521     if (ret) {
522         printk(KERN_ERR "%s: Unable to register %s input device\n", __FUNCTION__,ts->input_dev->name);
523         goto err_input_register_device_failed;
524     }
525
526         ts->irq = gpio_to_irq(client->irq);
527         ret = request_irq(ts->irq, ct360_ts_irq_handler, IRQF_TRIGGER_FALLING, client->name, ts);
528         if (ret){
529                 printk("!!! ct360 request_irq failed\n");
530                 goto err_input_register_device_failed;
531         }
532         
533 #ifdef CONFIG_HAS_EARLYSUSPEND
534     ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
535     ts->early_suspend.suspend = ct360_ts_early_suspend;
536     ts->early_suspend.resume = ct360_ts_late_resume;
537     register_early_suspend(&ts->early_suspend);
538 #endif
539
540     printk("%s: probe ok!!\n", __FUNCTION__);
541
542     return 0;
543
544 err_input_register_device_failed:
545     input_free_device(ts->input_dev);
546 err_input_dev_alloc_failed:
547         kfree(ts);
548 err_alloc_data_failed:
549 err_check_functionality_failed:
550         
551     return ret;
552 }
553
554 static int ct360_ts_remove(struct i2c_client *client)
555 {
556     struct ct360_ts_data *ts = i2c_get_clientdata(client);
557     unregister_early_suspend(&ts->early_suspend);
558         free_irq(ts->irq, ts);
559     input_unregister_device(ts->input_dev);
560     if (ts->ct360_wq)
561         destroy_workqueue(ts->ct360_wq);
562
563     kfree(ts);
564     return 0;
565 }
566
567 static int ct360_ts_suspend(struct i2c_client *client, pm_message_t mesg)
568 {
569     struct ct360_ts_data *ts = i2c_get_clientdata(client);
570
571         int ret,i;
572         char buf[3] = {0xff,0x8f,0xff};
573         
574         //disable_irq(ts->irq);
575     free_irq(ts->irq,ts);
576     cancel_work_sync(&ts->work);
577         flush_work(&ts->work);
578
579         ret = i2c_master_normal_send(client, buf, 3, 400*1000);
580         if (ret < 0) {
581           printk("ct360_ts_suspend:i2c_transfer fail 1=%d\n",ret);
582     }
583         msleep(3);
584         buf[0] = 0x00;
585         buf[1] = 0xaf;
586         ret = i2c_master_normal_send(client, buf, 2, 400*1000);
587         if (ret < 0) {
588           printk("ct360_ts_suspend:i2c_transfer fail 2=%d\n",ret);
589     }   
590
591         for (i =0; i<10; i++)
592         {
593                 if (touch_state[i] == TOUCH_DOWN)
594                 {
595                         input_mt_slot(ts->input_dev, i);
596                         input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, -1);
597                         touch_state[i] = TOUCH_UP;
598                 }
599         }
600     return ret;
601 }
602
603 static int ct360_ts_resume(struct i2c_client *client)
604 {
605     struct ct360_ts_data *ts = i2c_get_clientdata(client);
606     struct ct360_platform_data  *pdata = client->dev.platform_data;
607         int i ,ret = 0;
608
609     if(pdata->shutdown)
610         {       pdata->shutdown(1);
611                 mdelay(200);
612                 pdata->shutdown(0);
613                 mdelay(50);
614                 pdata->shutdown(1);
615                 mdelay(50);
616         }
617     printk("ct360 TS Resume\n");
618     
619       for(i=0; i<10; i++) {
620             {
621                 input_mt_slot(ts->input_dev, i);
622                 input_mt_report_slot_state(ts->input_dev, MT_TOOL_FINGER, false);
623             }
624     }
625
626         for(i=0; i<10; i++) {
627             {
628                 input_mt_slot(ts->input_dev, i);
629                 input_mt_report_slot_state(ts->input_dev, MT_TOOL_FINGER, false);
630             }
631     }
632         
633     input_sync(ts->input_dev);
634
635         ret = request_irq(ts->irq, ct360_ts_irq_handler, IRQF_TRIGGER_FALLING, client->name, ts);
636         if (ret){
637                 printk("!!! ct360 request_irq failed\n");
638         }
639     return ret;
640 }
641
642 #ifdef CONFIG_HAS_EARLYSUSPEND
643 static void ct360_ts_early_suspend(struct early_suspend *h)
644 {
645     struct ct360_ts_data *ts;
646     ts = container_of(h, struct ct360_ts_data, early_suspend);
647     ct360_ts_suspend(ts->client, PMSG_SUSPEND);
648 }
649
650 static void ct360_ts_late_resume(struct early_suspend *h)
651 {
652     struct ct360_ts_data *ts;
653     ts = container_of(h, struct ct360_ts_data, early_suspend);
654     ct360_ts_resume(ts->client);
655 }
656 #endif
657
658 static const struct i2c_device_id ct360_ts_id[] = {
659     { ct360_TS_NAME, 0 },
660     { }
661 };
662
663 static struct i2c_driver ct360_ts_driver = {
664     .probe      = ct360_ts_probe,
665     .remove     = ct360_ts_remove,
666 #ifndef CONFIG_HAS_EARLYSUSPEND
667     .suspend    = ct360_ts_suspend,
668     .resume     = ct360_ts_resume,
669 #endif
670     .id_table   = ct360_ts_id,
671     .driver = {
672         .name   = ct360_TS_NAME,
673     },
674 };
675
676 static int __devinit ct360_ts_init(void)
677 {
678     printk("%s\n",__FUNCTION__);
679
680     return i2c_add_driver(&ct360_ts_driver);
681 }
682
683 static void __exit ct360_ts_exit(void)
684 {
685     printk("%s\n",__FUNCTION__);
686     i2c_del_driver(&ct360_ts_driver);
687 }
688
689 module_init(ct360_ts_init);
690 module_exit(ct360_ts_exit);
691
692 MODULE_DESCRIPTION("ct360 Touchscreen Driver");
693 MODULE_LICENSE("GPL");