Merge tag 'v4.4-rc5'
[firefly-linux-kernel-4.4.55.git] / drivers / input / touchscreen / gt801_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
17 #include <linux/module.h>
18 #include <linux/delay.h>
19 #include <linux/earlysuspend.h>
20 #include <linux/hrtimer.h>
21 #include <linux/i2c.h>
22 #include <linux/input.h>
23 #include <linux/interrupt.h>
24 #include <linux/io.h>
25 #include <linux/gpio.h>
26 #include <mach/iomux.h>
27 #include <linux/platform_device.h>
28
29 #include "gt801_ts.h"
30
31 #define GT801_DEBUG                     0
32 #if GT801_DEBUG
33         #define gt801printk(msg...)     printk(msg);
34 #else
35         #define gt801printk(msg...)
36 #endif
37
38 #define SINGLTOUCH_MODE 0 
39 #define GT801_REGS_NUM 53
40
41 #if SINGLTOUCH_MODE
42         #define TOUCH_NUMBER 1
43 #else
44     #define TOUCH_NUMBER 2
45 #endif
46
47 #define TOUCH_REG_NUM 5 //ÿ�������Ҫ�ļĴ�����Ŀ
48
49 const unsigned char GT801_RegData[GT801_REGS_NUM]={     
50         0x19,0x05,0x06,0x28,0x02,0x14,0x14,0x10,0x40,0xB0,0x01,0xE0,0x03,0x4C,0x78,
51         0x9A,0xBC,0xDE,0x65,0x43,0x20,0x11,0x00,0x00,0x00,0x00,0x05,0xCF,0x20,0x0B,
52         0x0D,0x8D,0x32,0x3C,0x1E,0x28,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
53         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
54 };
55
56 struct gt801_ts_data {
57         u16             model;                  /* 801. */      
58         bool    swap_xy;                /* swap x and y axes */ 
59         u16             x_min, x_max;   
60         u16             y_min, y_max;
61     uint16_t addr;
62     int         use_irq;
63         int     gpio_pendown;
64         int     gpio_reset;
65         int     gpio_reset_active_low;
66         int             pendown_iomux_mode;     
67         int             resetpin_iomux_mode;
68         char    pendown_iomux_name[IOMUX_NAME_SIZE];    
69         char    resetpin_iomux_name[IOMUX_NAME_SIZE];   
70         char    phys[32];
71         char    name[32];
72         struct  i2c_client *client;
73     struct      input_dev *input_dev;
74     struct      hrtimer timer;
75     struct      work_struct  work;
76     struct      early_suspend early_suspend;
77 };
78 /*tochscreen private data*/
79 static int touch_state[TOUCH_NUMBER] = {TOUCH_UP,TOUCH_UP};
80 static struct workqueue_struct *gt801_wq;
81
82 #ifdef CONFIG_HAS_EARLYSUSPEND
83 static void gt801_ts_early_suspend(struct early_suspend *h);
84 static void gt801_ts_late_resume(struct early_suspend *h);
85 #endif
86
87 static int verify_coord(struct gt801_ts_data *ts,unsigned short *x,unsigned short *y)
88 {
89
90         gt801printk("%s:(%d/%d)\n",__FUNCTION__,*x, *y);
91         if((*x< ts->x_min) || (*x > ts->x_max))
92                 return -1;
93
94         if((*y< ts->y_min) || (*y > ts->y_max))
95                 return -1;
96 //      *x = ts->x_max - *x;
97         //if(*y <780)
98         *y = ts->y_max -*y;
99
100         return 0;
101 }
102
103 /*read the gt801 register ,used i2c bus*/
104 static int gt801_read_regs(struct i2c_client *client, u8 reg, u8 buf[], unsigned len)
105 {
106         int ret;
107         ret =i2c_master_reg8_recv(client, reg, buf, len, 200*1000);
108         if(ret < 0)
109                 printk("gt801_ts_work_func:i2c_transfer fail =%d\n",ret);
110         return ret;
111 }
112 /* set the gt801 registe,used i2c bus*/
113 static int gt801_write_regs(struct i2c_client *client, u8 reg, u8 const buf[], unsigned short len)
114 {
115         int ret;
116         ret = i2c_master_reg8_send(client,reg, buf, len, 200*1000);
117         if (ret < 0) {
118           printk("gt801_ts_work_func:i2c_transfer fail =%d\n",ret);
119     }
120         return ret;
121 }
122 static int gt801_init_panel(struct gt801_ts_data *ts)
123 {
124     return 0;
125 }
126
127 static void gt801_ts_work_func(struct work_struct *work)
128 {
129 #if  SINGLTOUCH_MODE
130   
131 #else
132         int  touch_state_index = 0;
133 #endif
134
135         unsigned char start_reg = 0x02;
136     unsigned char buf[TOUCH_NUMBER*TOUCH_REG_NUM];
137         unsigned short x;
138         unsigned short y;
139     int i,ret;
140         int syn_flag = 0;
141         int bufLen = TOUCH_NUMBER*TOUCH_REG_NUM;
142
143     struct gt801_ts_data *ts = container_of(work, struct gt801_ts_data, work);
144         
145         gt801printk("%s\n",__FUNCTION__);
146     
147         ret=gt801_read_regs(ts->client, start_reg, buf,bufLen);
148         if (ret < 0) {
149                 printk("%s:i2c_transfer fail =%d\n",__FUNCTION__,ret);
150                 if (ts->use_irq) 
151                         enable_irq(ts->client->irq);
152                 
153                 return;
154     }
155                
156 #if  SINGLTOUCH_MODE 
157         i = 0;
158         if(buf[i+ptpressure] == 0)
159         {
160                 gt801printk(" realse ts_dev->point.x=%d ,ts_dev->point.y=%d \n",ts->point.x,ts->point.y);
161
162                 if (touch_state[i] == TOUCH_DOWN)
163                 {
164                         input_report_key(ts->input_dev,BTN_TOUCH,0);
165                         syn_flag = 1;
166                         touch_state[i] = TOUCH_UP;
167                         gt801printk("SINGLTOUCH_MODE up\n");
168                 }
169         }
170         else
171         {
172                 x = ((( ((unsigned short)buf[i+ptxh] )<< 8) ) | buf[i+ptxl]);
173                 y= (((((unsigned short)buf[i+ptyh] )<< 8) )| buf[i+ptyl]);      
174                 
175                 if (ts->swap_xy)
176                         swap(x, y);
177                 
178                 if (verify_coord(ts,&x,&y))
179                         goto out;
180                 
181                 if (touch_state[i] == TOUCH_UP)
182                 {
183                         gt801printk("SINGLTOUCH_MODE down\n");
184                         input_report_key(ts->input_dev,BTN_TOUCH,1);
185                         touch_state[i] = TOUCH_DOWN;
186                 }
187                 
188                 gt801printk("input_report_abs(%d/%d)\n",x,y);
189                 input_report_abs(ts->input_dev,ABS_X,x );
190                 input_report_abs(ts->input_dev,ABS_Y,y );
191                 syn_flag = 1;
192         }
193
194 #else   
195
196     for(i=0; i<bufLen; i+=TOUCH_REG_NUM)
197         {
198                 if(buf[i+ptpressure] == 0){
199                         gt801printk("%s:buf=%d touch up\n",__FUNCTION__,buf[i+ptpressure]);
200                         if (touch_state[touch_state_index] == TOUCH_DOWN)
201                         {
202                                 gt801printk("%s:%d touch up\n",__FUNCTION__,i);
203                                 input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0); //Finger Size
204                                 input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0); //Touch Size
205                                 input_mt_sync(ts->input_dev);
206                                 syn_flag =1;
207                                 touch_state[touch_state_index] = TOUCH_UP;
208                         }         
209                 }
210                 else{
211                         x = ((( ((unsigned short)buf[i+ptxh] )<< 8) ) | buf[i+ptxl]);
212                         y = (((((unsigned short)buf[i+ptyh] )<< 8) )| buf[i+ptyl]);
213                         /* adjust the x and y to proper value  added by hhb@rock-chips.com*/
214                         if(x < 480){
215                                 x = 480-x;
216                         }
217
218                         if(y < 800){
219                                 y = 800-y;
220                         }
221
222                         if (ts->swap_xy){
223                                 swap(x, y);
224                         }
225                         
226                         if (verify_coord(ts,&x,&y));//goto out;
227                         
228                         gt801printk("input_report_abs--%d-%d-(%d/%d)\n", i,touch_state_index, x, y);    
229                         input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, 1); //Finger Size
230                         input_report_abs(ts->input_dev, ABS_MT_POSITION_X, x);
231                         input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, y);
232                         input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, 5); //Touch Size
233                         input_mt_sync(ts->input_dev);
234                         syn_flag = 1;
235                         touch_state[touch_state_index] = TOUCH_DOWN;
236                 }
237                 
238                 touch_state_index++;
239     }
240         
241 #endif
242
243         if(syn_flag){
244                 input_sync(ts->input_dev);
245         }
246
247 out:
248         if (ts->use_irq) {
249                 enable_irq(ts->client->irq);
250         }
251         return;
252 }
253 static enum hrtimer_restart gt801_ts_timer_func(struct hrtimer *timer)
254 {
255     struct gt801_ts_data *ts = container_of(timer, struct gt801_ts_data, timer);
256     gt801printk("%s\n",__FUNCTION__); 
257
258     queue_work(gt801_wq, &ts->work);
259
260     hrtimer_start(&ts->timer, ktime_set(0, 12500000), HRTIMER_MODE_REL);
261     return HRTIMER_NORESTART;
262 }
263
264 static irqreturn_t gt801_ts_irq_handler(int irq, void *dev_id)
265 {
266     struct gt801_ts_data *ts = dev_id;
267     gt801printk("%s=%d,%d\n",__FUNCTION__,ts->client->irq,ts->use_irq);
268         
269         if(ts->use_irq){
270         disable_irq_nosync(ts->client->irq);
271         }
272         queue_work(gt801_wq, &ts->work);
273     return IRQ_HANDLED;
274 }
275 static int __devinit setup_resetPin(struct i2c_client *client, struct gt801_ts_data *ts)
276 {
277         struct gt801_platform_data      *pdata = client->dev.platform_data;
278         int err;
279         
280         ts->gpio_reset = pdata->gpio_reset;
281     ts->gpio_reset_active_low = pdata->gpio_reset_active_low;
282     ts->resetpin_iomux_mode = pdata->resetpin_iomux_mode;
283
284     if(pdata->resetpin_iomux_name != NULL)
285             strcpy(ts->resetpin_iomux_name,pdata->resetpin_iomux_name);
286                  
287         gt801printk("%s=%d,%s,%d,%d\n",__FUNCTION__,ts->gpio_reset,ts->resetpin_iomux_name,ts->resetpin_iomux_mode,ts->gpio_reset_active_low);
288         if (!gpio_is_valid(ts->gpio_reset)) {
289                 dev_err(&client->dev, "no gpio_reset?\n");
290                 return -EINVAL;
291         }
292
293     rk29_mux_api_set(ts->resetpin_iomux_name,ts->resetpin_iomux_mode); 
294
295         err = gpio_request(ts->gpio_reset, "gt801_resetPin");
296         if (err) {
297                 dev_err(&client->dev, "failed to request resetPin GPIO%d\n",
298                                 ts->gpio_reset);
299                 return err;
300         }
301         
302         err = gpio_direction_output(ts->gpio_reset, ts->gpio_reset_active_low? GPIO_LOW:GPIO_HIGH);
303         if (err) {
304                 dev_err(&client->dev, "failed to pulldown resetPin GPIO%d,err%d\n",
305                                 ts->gpio_reset,err);
306                 gpio_free(ts->gpio_reset);
307                 return err;
308         }
309         mdelay(100);
310         gpio_set_value(ts->gpio_reset, ts->gpio_reset_active_low? GPIO_HIGH:GPIO_LOW);
311         mdelay(100);
312
313         return 0;
314 }
315
316 static int __devinit setup_pendown(struct i2c_client *client, struct gt801_ts_data *ts)
317 {
318         int err;
319         struct gt801_platform_data      *pdata = client->dev.platform_data;
320         
321         if (!client->irq) {
322                 dev_dbg(&client->dev, "no IRQ?\n");
323                 return -ENODEV;
324         }
325         
326         if (!gpio_is_valid(pdata->gpio_pendown)) {
327                 dev_err(&client->dev, "no gpio_pendown?\n");
328                 return -EINVAL;
329         }
330         
331         ts->gpio_pendown = pdata->gpio_pendown;
332         strcpy(ts->pendown_iomux_name,pdata->pendown_iomux_name);
333         ts->pendown_iomux_mode = pdata->pendown_iomux_mode;
334         
335         gt801printk("%s=%d,%s,%d\n",__FUNCTION__,ts->gpio_pendown,ts->pendown_iomux_name,ts->pendown_iomux_mode);
336         
337         if (!gpio_is_valid(ts->gpio_pendown)) {
338                 dev_err(&client->dev, "no gpio_pendown?\n");
339                 return -EINVAL;
340         }
341         
342     rk29_mux_api_set(ts->pendown_iomux_name,ts->pendown_iomux_mode); 
343         err = gpio_request(ts->gpio_pendown, "gt801_pendown");
344         if (err) {
345                 dev_err(&client->dev, "failed to request pendown GPIO%d\n",
346                                 ts->gpio_pendown);
347                 return err;
348         }
349         
350         err = gpio_pull_updown(ts->gpio_pendown, GPIOPullUp);
351         if (err) {
352                 dev_err(&client->dev, "failed to pullup pendown GPIO%d\n",
353                                 ts->gpio_pendown);
354                 gpio_free(ts->gpio_pendown);
355                 return err;
356         }
357         return 0;
358 }
359
360 static int gt801_chip_Init(struct i2c_client *client)
361 {
362         u8 i,j;
363         int ret=0;
364         u8 start_reg=0x30;
365         u8 buf[GT801_REGS_NUM];
366         
367         gt801printk("enter gt801_chip_Init!!!!\n");
368
369         for(j=0;j<2;j++)
370         {
371                 ret=gt801_write_regs(client,start_reg, GT801_RegData,GT801_REGS_NUM);   
372                 if(ret<0)
373                 {
374                         printk("\n--%s--Set Register values error !!!\n",__FUNCTION__);
375                 }
376                 
377                 ret=gt801_read_regs(client, start_reg, buf,GT801_REGS_NUM);
378                 if(ret<0)
379                 {
380                         printk("\n--%s--Read Register values error !!!\n",__FUNCTION__);
381                 }
382                         
383                 for(i=0;i<GT801_REGS_NUM-1;i++)
384                 {
385                         if(buf[i]!=GT801_RegData[i])
386                         {
387                                 printk("!!!!!!!!gt801_chip_Init err may be i2c errorat adress=%x var=%x i=%x\n",0x30+i, buf[i],i);
388                                 break;
389                         }
390                 }
391                 if(i==GT801_REGS_NUM-1)
392                         break;
393                 else if(j==1)
394                         return -1;
395                 
396                 mdelay(500);
397         }
398         mdelay(100);
399         
400         return ret;
401 }
402
403 static int gt801_ts_probe(struct i2c_client *client, const struct i2c_device_id *id)
404 {
405     struct gt801_ts_data *ts;
406         struct gt801_platform_data      *pdata = client->dev.platform_data;
407     int ret = 0;
408
409     gt801printk("%s \n",__FUNCTION__);
410         
411     if (!pdata) {
412                 dev_err(&client->dev, "empty platform_data\n");
413                 goto err_check_functionality_failed;
414     }
415     if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
416         printk(KERN_ERR "gt801_ts_probe: need I2C_FUNC_I2C\n");
417         ret = -ENODEV;
418         goto err_check_functionality_failed;
419     }
420         
421     ts = kzalloc(sizeof(*ts), GFP_KERNEL);
422     if (ts == NULL) {
423         ret = -ENOMEM;
424         goto err_alloc_data_failed;
425     }
426     INIT_WORK(&ts->work, gt801_ts_work_func);
427     ts->client = client;
428     i2c_set_clientdata(client, ts);
429
430         ret = setup_resetPin(client,ts);
431         if(ret)
432         {
433                  printk("%s:setup_resetPin fail\n",__FUNCTION__);
434                  goto err_input_dev_alloc_failed;
435         }
436         
437         ret=gt801_chip_Init(ts->client);
438         if(ret<0)
439         {
440                 printk("%s:chips init failed\n",__FUNCTION__);
441                 goto err_resetpin_failed;
442         }
443         
444     /* allocate input device */
445     ts->input_dev = input_allocate_device();
446     if (ts->input_dev == NULL) {
447         ret = -ENOMEM;
448         printk(KERN_ERR "%s: Failed to allocate input device\n",__FUNCTION__);
449         goto err_input_dev_alloc_failed;
450     }
451         
452         ts->model = pdata->model ? : 801;
453         ts->swap_xy = pdata->swap_xy;
454         ts->x_min = pdata->x_min;
455         ts->x_max = pdata->x_max;
456         ts->y_min = pdata->y_min;
457         ts->y_max = pdata->y_max;
458         snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(&client->dev));
459         snprintf(ts->name, sizeof(ts->name), "gt%d-touchscreen", ts->model);
460         ts->input_dev->phys = ts->phys;
461         ts->input_dev->name = ts->name;
462         ts->input_dev->dev.parent = &client->dev;
463
464 #if SINGLTOUCH_MODE
465         ts->input_dev->evbit[0] = BIT_MASK(EV_ABS)|BIT_MASK(EV_KEY);
466         ts->input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
467         input_set_abs_params(ts->input_dev,ABS_X,
468                     ts->x_min ? : 0,
469                         ts->x_max ? : 480,
470                         0, 0);
471         input_set_abs_params(ts->input_dev,ABS_Y,
472                         ts->y_min ? : 0,
473                         ts->y_max ? : 800,
474                         0, 0);
475
476 #else
477     ts->input_dev->evbit[0] = BIT_MASK(EV_SYN) | BIT_MASK(EV_ABS);
478   //  ts->input_dev->absbit[0] = 
479         //      BIT(ABS_MT_POSITION_X) | BIT(ABS_MT_POSITION_Y) | 
480         //      BIT(ABS_MT_TOUCH_MAJOR) | BIT(ABS_MT_WIDTH_MAJOR);  // for android
481     input_set_abs_params(ts->input_dev, ABS_MT_POSITION_X, 
482                     ts->x_min ? : 0,
483                         ts->x_max ? : 480,
484                         0, 0);
485     input_set_abs_params(ts->input_dev, ABS_MT_POSITION_Y,
486                         ts->y_min ? : 0,
487                         ts->y_max ? : 800,
488                         0, 0);
489     input_set_abs_params(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0, 1, 0, 0); //Finger Size
490     input_set_abs_params(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0, 10, 0, 0); //Touch Size
491 #endif
492     ret = input_register_device(ts->input_dev);
493     if (ret) {
494         printk(KERN_ERR "%s: Unable to register %s input device\n", __FUNCTION__,ts->input_dev->name);
495         goto err_input_register_device_failed;
496     }
497         
498         client->irq = gpio_to_irq(client->irq);
499     if (client->irq) {
500                 ret = setup_pendown(client,ts);
501                 if(ret)
502                 {
503                          printk("%s:setup_pendown fail\n",__FUNCTION__);
504                          goto err_input_register_device_failed;
505                 }
506                 
507         ret = request_irq(client->irq, gt801_ts_irq_handler, IRQF_DISABLED | IRQF_TRIGGER_LOW, client->name, ts);
508         if (ret == 0) {
509             gt801printk("%s:register ISR (irq=%d)\n", __FUNCTION__,client->irq);
510             ts->use_irq = 1;
511         }
512         else 
513                         dev_err(&client->dev, "request_irq failed\n");
514     }
515
516     if (!ts->use_irq) {
517         hrtimer_init(&ts->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
518         ts->timer.function = gt801_ts_timer_func;
519         hrtimer_start(&ts->timer, ktime_set(1, 0), HRTIMER_MODE_REL);
520     }
521 #ifdef CONFIG_HAS_EARLYSUSPEND
522     ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
523     ts->early_suspend.suspend = gt801_ts_early_suspend;
524     ts->early_suspend.resume = gt801_ts_late_resume;
525     register_early_suspend(&ts->early_suspend);
526 #endif
527
528     printk(KERN_INFO "%s: Start touchscreen %s in %s mode\n", __FUNCTION__,ts->input_dev->name, ts->use_irq ? "interrupt" : "polling");
529
530     return 0;
531
532 err_input_register_device_failed:
533     input_free_device(ts->input_dev);
534 err_resetpin_failed:
535         gpio_free(ts->gpio_reset);
536 err_input_dev_alloc_failed:
537         kfree(ts);
538 err_alloc_data_failed:
539 err_check_functionality_failed:
540         
541     return ret;
542 }
543
544 static int gt801_ts_remove(struct i2c_client *client)
545 {
546     struct gt801_ts_data *ts = i2c_get_clientdata(client);
547     unregister_early_suspend(&ts->early_suspend);
548     if (ts->use_irq)
549         free_irq(client->irq, ts);
550     else
551         hrtimer_cancel(&ts->timer);
552     input_unregister_device(ts->input_dev);
553         gpio_free(ts->gpio_pendown);
554         gpio_free(ts->gpio_reset);
555     kfree(ts);
556     return 0;
557 }
558
559 static int gt801_ts_suspend(struct i2c_client *client, pm_message_t mesg)
560 {
561     int ret;
562     struct gt801_ts_data *ts = i2c_get_clientdata(client);
563
564     printk("gt801 TS Suspend\n");
565     
566     if (ts->use_irq)
567         disable_irq(client->irq);
568     else
569         hrtimer_cancel(&ts->timer);
570
571     ret = cancel_work_sync(&ts->work);
572     if (ret && ts->use_irq) /* if work was pending disable-count is now 2 */
573         enable_irq(client->irq);
574
575         gpio_set_value(ts->gpio_reset, ts->gpio_reset_active_low? GPIO_LOW:GPIO_HIGH);
576         
577     return 0;
578 }
579
580
581 static void gt801_ts_resume_work_func(struct work_struct *work)
582 {
583         struct gt801_ts_data *ts = container_of(work, struct gt801_ts_data, work);
584         msleep(50);    //touch panel will generate an interrupt when it sleeps out,so as to avoid tihs by delaying 50ms
585         enable_irq(ts->client->irq);
586         PREPARE_WORK(&ts->work, gt801_ts_work_func);
587         printk("enabling gt801_ts IRQ %d\n", ts->client->irq);
588 }
589
590
591 static int gt801_ts_resume(struct i2c_client *client)
592 {
593     struct gt801_ts_data *ts = i2c_get_clientdata(client);
594
595     gt801_init_panel(ts);
596     
597     printk("gt801 TS Resume\n");
598         
599     gpio_set_value(ts->gpio_reset, ts->gpio_reset_active_low? GPIO_HIGH:GPIO_LOW);
600         
601     if (ts->use_irq) {
602         if(!work_pending(&ts->work)){
603                 PREPARE_WORK(&ts->work, gt801_ts_resume_work_func);
604                 queue_work(gt801_wq, &ts->work);
605         }
606     }
607     else {
608         hrtimer_start(&ts->timer, ktime_set(1, 0), HRTIMER_MODE_REL);
609     }
610
611     return 0;
612 }
613
614 #ifdef CONFIG_HAS_EARLYSUSPEND
615 static void gt801_ts_early_suspend(struct early_suspend *h)
616 {
617     struct gt801_ts_data *ts;
618     ts = container_of(h, struct gt801_ts_data, early_suspend);
619     gt801_ts_suspend(ts->client, PMSG_SUSPEND);
620 }
621
622 static void gt801_ts_late_resume(struct early_suspend *h)
623 {
624     struct gt801_ts_data *ts;
625     ts = container_of(h, struct gt801_ts_data, early_suspend);
626     gt801_ts_resume(ts->client);
627 }
628 #endif
629
630 #define gt801_TS_NAME "gt801_ts"
631
632 static const struct i2c_device_id gt801_ts_id[] = {
633     { gt801_TS_NAME, 0 },
634     { }
635 };
636
637 static struct i2c_driver gt801_ts_driver = {
638     .probe      = gt801_ts_probe,
639     .remove     = gt801_ts_remove,
640 #ifndef CONFIG_HAS_EARLYSUSPEND
641     .suspend    = gt801_ts_suspend,
642     .resume     = gt801_ts_resume,
643 #endif
644     .id_table   = gt801_ts_id,
645     .driver = {
646         .name   = gt801_TS_NAME,
647     },
648 };
649
650 static int __devinit gt801_ts_init(void)
651 {
652     printk("%s\n",__FUNCTION__);
653     gt801_wq = create_singlethread_workqueue("gt801_wq");
654     if (!gt801_wq)
655         return -ENOMEM;
656     return i2c_add_driver(&gt801_ts_driver);
657 }
658
659 static void __exit gt801_ts_exit(void)
660 {
661     printk("%s\n",__FUNCTION__);
662     i2c_del_driver(&gt801_ts_driver);
663     if (gt801_wq)
664         destroy_workqueue(gt801_wq);
665 }
666
667 module_init(gt801_ts_init);
668 module_exit(gt801_ts_exit);
669
670 MODULE_DESCRIPTION("gt801 Touchscreen Driver");
671 MODULE_LICENSE("GPL");