c8dabff60f11005c18cf5a5c4d100f803e7d10d7
[firefly-linux-kernel-4.4.55.git] / drivers / input / touchscreen / ft5x0x.c
1 #include <linux/module.h>
2 #include <linux/delay.h>
3 #include <linux/earlysuspend.h>
4 #include <linux/hrtimer.h>
5 #include <linux/i2c.h>
6 #include <linux/input.h>
7 #include <linux/interrupt.h>
8 #include <linux/io.h>
9 #include <linux/platform_device.h>
10 #include <linux/async.h>
11 #include <mach/gpio.h>
12 #include <mach/iomux.h>
13 #include <linux/irq.h>
14 #include <mach/board.h>
15 #include <linux/kthread.h>
16 #include <linux/slab.h>
17 #include <linux/input/mt.h>
18 #include <linux/regulator/rk29-pwm-regulator.h>
19 #include <linux/regulator/machine.h>
20 #include <linux/regulator/consumer.h>
21 #include <linux/regulator/machine.h>
22
23 //#define FT5X0X_DEBUG
24 #ifdef FT5X0X_DEBUG
25 #define DBG(fmt, args...)       printk("*** " fmt, ## args)
26 #else
27 #define DBG(fmt, args...)       do{}while(0)
28 #endif
29
30 #define EV_MENU                                 KEY_MENU
31
32 #define I2C_SPEED 200*1000
33 #define MAX_POINT  5
34
35 #if defined (CONFIG_TOUCHSCREEN_1024X768)
36 #define SCREEN_MAX_X 1024
37 #define SCREEN_MAX_Y 768
38 #elif defined (CONFIG_TOUCHSCREEN_1024X600)
39 #define SCREEN_MAX_X 1024
40 #define SCREEN_MAX_Y 600
41 #elif defined (CONFIG_TOUCHSCREEN_800X600)
42 #define SCREEN_MAX_X 800
43 #define SCREEN_MAX_Y 600
44 #elif defined (CONFIG_TOUCHSCREEN_800X480)
45 #define SCREEN_MAX_X 800
46 #define SCREEN_MAX_Y 480
47 #else
48 #define SCREEN_MAX_X 800
49 #define SCREEN_MAX_Y 480
50 #endif
51
52 #define PRESS_MAX 200
53
54 #define VID_OF          0x51    //OuFei
55 #define VID_MD          0x53    //MuDong
56 #define VID_BYD         0x59
57 #define VID_BM          0x5D    //BaoMing
58 #define VID_YJ          0x80
59 #define VID_DSW         0x8C    //DingShengWei
60 #define VID_YM          0x94    //0xC0
61 static unsigned char g_vid;
62
63 #ifdef CONFIG_HAS_EARLYSUSPEND
64 static struct early_suspend ft5x0x_early_suspend;
65 #endif
66
67 #ifndef TOUCH_EN_LEVEL
68 #define TOUCH_EN_LEVEL GPIO_HIGH
69 #endif
70
71 static int  ft5x0x_probe(struct i2c_client *client, const struct i2c_device_id *id);
72
73 struct ts_event {
74     u16    flag;
75     u16    x;
76     u16    y;
77     u16    pressure;
78     u16    w;
79 };
80 static struct ts_event ts_point[MAX_POINT];
81
82 struct ft5x0x_data
83 {
84         struct i2c_client *client;
85         struct input_dev        *input_dev;
86         int             reset_gpio;
87         int             touch_en_gpio;
88         int             last_point_num;
89         struct work_struct      pen_event_work;
90         struct workqueue_struct *ts_workqueue;
91 };
92
93 struct i2c_client *g_client;
94
95 /***********************************************************************************************
96 Name    :       ft5x0x_i2c_rxdata 
97
98 Input   :       *rxdata
99                      *length
100
101 Output  :       ret
102
103 function        :       
104
105 ***********************************************************************************************/
106 int ft5x0x_i2c_Read(char * writebuf, int writelen, char *readbuf, int readlen)
107 {
108         int ret;
109
110         if(writelen > 0)
111         {
112                 struct i2c_msg msgs[] = {
113                         {
114                                 .addr   = g_client->addr,
115                                 .flags  = 0,
116                                 .len    = writelen,
117                                 .buf    = writebuf,
118                                 .scl_rate = I2C_SPEED,
119                         },
120                         {
121                                 .addr   = g_client->addr,
122                                 .flags  = I2C_M_RD,
123                                 .len    = readlen,
124                                 .buf    = readbuf,
125                                 .scl_rate = I2C_SPEED,
126                         },
127                 };
128                 ret = i2c_transfer(g_client->adapter, msgs, 2);
129                 if (ret < 0)
130                         DBG("msg %s i2c read error: %d\n", __func__, ret);
131         }
132         else
133         {
134                 struct i2c_msg msgs[] = {
135                         {
136                                 .addr   = g_client->addr,
137                                 .flags  = I2C_M_RD,
138                                 .len    = readlen,
139                                 .buf    = readbuf,
140                                 .scl_rate = I2C_SPEED,
141                         },
142                 };
143                 ret = i2c_transfer(g_client->adapter, msgs, 1);
144                 if (ret < 0)
145                         DBG("msg %s i2c read error: %d\n", __func__, ret);
146         }
147         return ret;
148 }EXPORT_SYMBOL(ft5x0x_i2c_Read);
149 /***********************************************************************************************
150 Name    :        ft5x0x_i2c_Write
151
152 Input   :       
153                      
154
155 Output  :0-write success        
156                 other-error code        
157 function        :       write data by i2c 
158
159 ***********************************************************************************************/
160 int ft5x0x_i2c_Write(char *writebuf, int writelen)
161 {
162         int ret;
163
164         struct i2c_msg msg[] = {
165                 {
166                         .addr   = g_client->addr,
167                         .flags  = 0,
168                         .len    = writelen,
169                         .buf    = writebuf,
170                         .scl_rate = I2C_SPEED,
171                 },
172         };
173
174         ret = i2c_transfer(g_client->adapter, msg, 1);
175         if (ret < 0)
176                 DBG("%s i2c write error: %d\n", __func__, ret);
177
178         return ret;
179 }EXPORT_SYMBOL(ft5x0x_i2c_Write);
180
181 int ft5x0x_rx_data(struct i2c_client *client, char *rxData, int length)
182 {
183         int ret = 0;
184         char reg = rxData[0];
185         ret = i2c_master_reg8_recv(client, reg, rxData, length, I2C_SPEED);
186         return (ret > 0)? 0 : ret;
187 }
188
189 static int ft5x0x_tx_data(struct i2c_client *client, char *txData, int length)
190 {
191         int ret = 0;
192         char reg = txData[0];
193         ret = i2c_master_reg8_send(client, reg, &txData[1], length-1, I2C_SPEED);
194         return (ret > 0)? 0 : ret;
195 }
196
197 char ft5x0x_read_reg(struct i2c_client *client, int addr)
198 {
199         char tmp;
200         int ret = 0;
201
202         tmp = addr;
203         ret = ft5x0x_rx_data(client, &tmp, 1);
204         if (ret < 0) {
205                 return ret;
206         }
207         return tmp;
208 }
209
210 int ft5x0x_write_reg(struct i2c_client *client,int addr,int value)
211 {
212         char buffer[3];
213         int ret = 0;
214
215         buffer[0] = addr;
216         buffer[1] = value;
217         ret = ft5x0x_tx_data(client, &buffer[0], 2);
218         return ret;
219 }
220
221 static void ft5x0x_power_en(struct ft5x0x_data *tsdata, int on)
222 {
223 #if defined (TOUCH_POWER_PIN)
224         if (on) {
225                 gpio_direction_output(tsdata->touch_en_gpio, TOUCH_EN_LEVEL);
226                 gpio_set_value(tsdata->touch_en_gpio, TOUCH_EN_LEVEL);
227                 mdelay(10);
228         } else {
229                 gpio_direction_output(tsdata->touch_en_gpio, !TOUCH_EN_LEVEL);
230                 gpio_set_value(tsdata->touch_en_gpio, !TOUCH_EN_LEVEL);
231                 mdelay(10);
232         }
233 #endif
234        if( tsdata->reset_gpio <= 0 ){
235                struct regulator *vcc_tp;
236                vcc_tp = regulator_get(NULL, "vaux33");   // vcc28_cif
237                if (vcc_tp == NULL || IS_ERR(vcc_tp) ){
238                     printk(">>>> get cif vaux33 ldo failed!\n");
239                     return;
240                 }
241
242                  if( on ){ //turn on
243                         regulator_set_voltage(vcc_tp, 3300000, 3300000);
244                           regulator_enable(vcc_tp);
245                           printk(" %s set  vpll vcc28_cif=%dmV end\n", __func__, regulator_get_voltage(vcc_tp));
246                           regulator_put(vcc_tp);
247                  }else{   //turn off
248                         while(regulator_is_enabled(vcc_tp)>0){
249                                        regulator_disable(vcc_tp);
250                           }
251                           printk(" %s regulator disable vcc tp \n",__func__);
252                           regulator_put(vcc_tp);
253                  }
254          }
255
256
257 }
258
259 static void ft5x0x_chip_reset(struct ft5x0x_data *tsdata)
260 {
261     gpio_direction_output(tsdata->reset_gpio, 0);
262     gpio_set_value(tsdata->reset_gpio, 1);
263         mdelay(20);
264     gpio_set_value(tsdata->reset_gpio, 0);
265         mdelay(20);
266     gpio_set_value(tsdata->reset_gpio, 1);
267 }
268
269 static int i2c_write_interface(unsigned char* pbt_buf, int dw_lenth)
270 {
271     int ret;
272     ret = i2c_master_send(g_client, pbt_buf, dw_lenth);
273     if (ret <= 0) {
274         printk("i2c_write_interface error\n");
275         return -1;
276     }
277
278     return 0;
279 }
280
281 static int ft_cmd_write(unsigned char btcmd, unsigned char btPara1, unsigned char btPara2,
282                 unsigned char btPara3, int num)
283 {
284     unsigned char write_cmd[4] = {0};
285
286     write_cmd[0] = btcmd;
287     write_cmd[1] = btPara1;
288     write_cmd[2] = btPara2;
289     write_cmd[3] = btPara3;
290     return i2c_write_interface(&write_cmd, num);
291 }
292
293
294 static int ft5x0x_chip_init(struct i2c_client * client)
295 {
296         int ret = 0;
297         int w_value;
298         char r_value;
299         int err = -1;
300         int reg;
301         int i = 0, flag = 1;
302         struct ft5x0x_data *tsdata = i2c_get_clientdata(client);
303
304        if( tsdata->reset_gpio > 0 ){
305                 gpio_free(tsdata->reset_gpio);
306                 err = gpio_request(tsdata->reset_gpio, "ft5x0x rst");
307                 if (err) {
308                         printk( "failed to request ft5x0x reset GPIO%d\n", tsdata->reset_gpio);
309                         goto exit_alloc_gpio_rst_failed;
310                 }
311        }
312         
313 #if defined (TOUCH_POWER_PIN)
314 #if defined (TOUCH_POWER_MUX_NAME)
315     rk29_mux_api_set(TOUCH_POWER_MUX_NAME, TOUCH_POWER_MUX_MODE_GPIO);
316 #endif
317         gpio_free(tsdata->touch_en_gpio);
318         err = gpio_request(tsdata->touch_en_gpio, "ft5x0x power enable");
319         if (err) {
320                 DBG( "failed to request ft5x0x power enable GPIO%d\n", tsdata->touch_en_gpio);
321                 goto exit_alloc_gpio_power_failed;
322         }
323 #endif
324
325         ft5x0x_power_en(tsdata, 0);
326         mdelay(100);
327         ft5x0x_chip_reset(tsdata);
328         ft5x0x_power_en(tsdata, 1);
329         mdelay(500);
330     ft_cmd_write(0x07,0x00,0x00,0x00,1);
331         mdelay(10);
332
333 #if 1
334         while (1) {
335                 reg = 0x88;
336                 w_value = 7; 
337                 ret = ft5x0x_write_reg(client, reg, w_value);    /* adjust frequency 70Hz */
338                 if (ret < 0) {
339                         printk(KERN_ERR "ft5x0x i2c txdata failed\n");
340                         //goto out;
341                 }
342
343                 r_value = ft5x0x_read_reg(client, reg);
344                 if (ret < 0) {
345                         printk(KERN_ERR "ft5x0x i2c rxdata failed\n");
346                         //goto out;
347                 }
348                 printk("r_value = %d\n, i = %d, flag = %d", r_value, i, flag);
349                 i++;
350
351                 if (w_value != r_value) {
352                         ret = -1;
353                         flag = 0;
354                         if (i > 10) { /* test 5 count */
355                                 break;
356                         }
357                 } else {
358                         ret = 0;
359                         break;
360                 }
361         }
362
363       if( ret == -1)
364           return ret;
365
366 #endif
367         ret = ft5x0x_read_reg(client, 0xA8);//read touchpad ID for adjust touchkey place
368         if (ret < 0) {
369                 printk(KERN_ERR "ft5x0x i2c rxdata failed\n");
370                 //goto out;
371         }
372         printk("ft5406 g_vid = 0x%X\n", ret);
373         g_vid = ret;
374
375         return ret;
376
377 exit_alloc_gpio_power_failed:
378 #if defined (TOUCH_POWER_PIN)
379         gpio_free(tsdata->touch_en_gpio);
380 #endif
381 exit_alloc_gpio_rst_failed:
382     gpio_free(tsdata->reset_gpio);
383         printk("%s error\n",__FUNCTION__);
384         return err;
385 }
386
387 static void key_led_ctrl(int on)
388 {
389 #ifdef TOUCH_KEY_LED
390         gpio_set_value(TOUCH_KEY_LED, on);
391 #endif
392 }
393
394 static int g_screen_key=0;
395
396 static int ft5x0x_process_points(struct ft5x0x_data *data)
397 {
398         struct i2c_client *client = data->client;
399         u8 start_reg = 0x0;
400         u8 buf[32] = {0};
401         int ret = -1;
402         int status = 0, id, x, y, p, w, touch_num;
403         int offset, i;
404         int back_press = 0, search_press=0, menu_press=0, home_press=0;
405         int points;
406
407         start_reg = 0;
408         buf[0] = start_reg;
409
410         //printk("ft5406 g_vid = 0x%X\n", g_vid);
411         if (MAX_POINT == 5) {
412                 ret = ft5x0x_rx_data(client, buf, 31);
413         } else {
414                 ret = ft5x0x_rx_data(client, buf, 13);
415         }
416
417     if (ret < 0) {
418                 printk("%s read_data i2c_rxdata failed: %d\n", __func__, ret);
419                 return ret;
420         }
421
422
423         if (MAX_POINT == 5) {
424                 touch_num = buf[2] & 0x07;
425         } else {
426                 touch_num = buf[2] & 0x03;
427         }
428
429         if (touch_num == 0) {
430                 for (i = 0; i < MAX_POINT; i++) {
431                         input_mt_slot(data->input_dev, i);
432                         input_mt_report_slot_state(data->input_dev, MT_TOOL_FINGER, false);
433                 }
434
435                 input_sync(data->input_dev);
436                 DBG("release all points!!!!!!\n");
437                 return 0;
438         }
439
440         points = touch_num;
441         if (data->last_point_num > touch_num) {
442                 touch_num = data->last_point_num;
443         }
444         data->last_point_num = points;
445
446         offset = 0;
447     for (i = 0; i < touch_num; i++) {        
448                 id = buf[5 + offset] >> 4;
449         status = buf[3  + offset] >> 6;
450         x = (s16)(buf[3 + offset] & 0x0F) << 8 | (s16)buf[4 + offset];
451         y = (s16)(buf[5 + offset] & 0x0F) << 8 | (s16)buf[6 + offset];
452
453         //p = buf[7 + offset];
454         //w = buf[8 + offset];
455
456         offset += 6;
457                 
458         //printk("%d-%d(%d,%d)%d-%d\n", id, status, x, y, p, w);
459                 DBG("TOUCH_NO=%d: ID=%d,(X=%d,Y=%d), status=%d, pressure=%d, w=%d\n", i, id, x, y, status, 0, 0);
460
461                 if (x < (SCREEN_MAX_X + 10)) {
462                         if (status == 1) {
463                                 input_mt_slot(data->input_dev, id);
464                                 input_mt_report_slot_state(data->input_dev, MT_TOOL_FINGER, false);
465                         } else {
466                                 input_mt_slot(data->input_dev, id);
467                                 input_mt_report_slot_state(data->input_dev, MT_TOOL_FINGER, true);
468                                 input_report_abs(data->input_dev, ABS_MT_TOUCH_MAJOR, 200);
469                                 input_report_abs(data->input_dev, ABS_MT_POSITION_X, x);
470                                 input_report_abs(data->input_dev, ABS_MT_POSITION_Y, y);
471                         }
472                 } else {
473                 }
474         }
475
476         input_sync(data->input_dev);
477
478         return 0;
479 }
480
481 static void  ft5x0x_delaywork_func(struct work_struct *work)
482 {
483         struct ft5x0x_data *ft5x0x = container_of(work, struct ft5x0x_data, pen_event_work);
484         struct i2c_client *client = ft5x0x->client;
485
486         ft5x0x_process_points(ft5x0x);
487         enable_irq(client->irq);                
488 }
489
490 static irqreturn_t ft5x0x_interrupt(int irq, void *handle)
491 {
492         struct ft5x0x_data *ft5x0x_ts = handle;
493
494         //printk("Enter:%s %d\n",__FUNCTION__,__LINE__);
495         disable_irq_nosync(irq);
496         //if (!work_pending(&ft5x0x_ts->pen_event_work)) {
497                 queue_work(ft5x0x_ts->ts_workqueue, &ft5x0x_ts->pen_event_work);
498         //}
499         return IRQ_HANDLED;
500 }
501
502
503 static int ft5x0x_remove(struct i2c_client *client)
504 {
505         struct ft5x0x_data *ft5x0x = i2c_get_clientdata(client);
506         
507     input_unregister_device(ft5x0x->input_dev);
508     input_free_device(ft5x0x->input_dev);
509     free_irq(client->irq, ft5x0x);
510     kfree(ft5x0x); 
511 #ifdef CONFIG_HAS_EARLYSUSPEND
512     unregister_early_suspend(&ft5x0x_early_suspend);
513 #endif      
514         return 0;
515 }
516
517 #ifdef CONFIG_HAS_EARLYSUSPEND
518 static void ft5x0x_suspend(struct early_suspend *h)
519 {
520         int err;
521         int w_value;
522         int reg;
523         struct ft5x0x_data *ft5x0x = i2c_get_clientdata(g_client);
524
525         printk("==ft5x0x_ts_suspend=\n");
526         key_led_ctrl(0);
527
528 #if 1
529         w_value = 3;
530         reg = 0xa5;
531         err = ft5x0x_write_reg(g_client, reg, w_value);   /* enter sleep mode */
532         if (err < 0) {
533                 printk("ft5x0x enter sleep mode failed\n");
534         }
535 #endif
536         disable_irq(g_client->irq);     
537         if( ft5x0x->reset_gpio <= 0 ){
538             ft5x0x_power_en(ft5x0x, 0);
539         }
540 }
541
542 static void ft5x0x_resume(struct early_suspend *h)
543 {
544         struct ft5x0x_data *ft5x0x = i2c_get_clientdata(g_client);
545
546         key_led_ctrl(0);
547
548         printk("==ft5x0x_ts_resume=\n");
549         if( ft5x0x->reset_gpio > 0 ){
550             ft5x0x_chip_reset(ft5x0x);
551         }else{
552             ft5x0x_power_en(ft5x0x, 1);
553         }
554
555         mdelay(100);
556
557         enable_irq(g_client->irq);              
558 }
559 #else
560 static int ft5x0x_suspend(struct i2c_client *client, pm_message_t mesg)
561 {
562         return 0;
563 }
564 static int ft5x0x_resume(struct i2c_client *client)
565 {
566         return 0;
567 }
568 #endif
569
570 static const struct i2c_device_id ft5x0x_id[] = {
571                 {"ft5x0x_ts", 0},
572                 { }
573 };
574
575 MODULE_DEVICE_TABLE(i2c, ft5x0x_id);
576
577 static struct i2c_driver ft5x0x_driver = {
578         .driver = {
579                 .name = "ft5x0x_ts",
580             },
581         .id_table       = ft5x0x_id,
582         .probe          = ft5x0x_probe,
583         .remove         = __devexit_p(ft5x0x_remove),
584 #ifndef CONFIG_HAS_EARLYSUSPEND 
585         .suspend = &ft5x0x_suspend,
586         .resume = &ft5x0x_resume,
587 #endif  
588 };
589
590 static int ft5x0x_client_init(struct i2c_client *client)
591 {
592         struct ft5x0x_data *tsdata = i2c_get_clientdata(client);
593         int ret = 0;
594
595         DBG("gpio_to_irq(%d) is %d\n", client->irq, gpio_to_irq(client->irq));
596         if ( !gpio_is_valid(client->irq)) {
597                 DBG("+++++++++++gpio_is_invalid\n");
598                 return -EINVAL;
599         }
600
601         gpio_free(client->irq);
602         ret = gpio_request(client->irq, "ft5x0x_int");
603         if (ret) {
604                 DBG( "failed to request ft5x0x GPIO%d\n", gpio_to_irq(client->irq));
605                 return ret;
606         }
607
608     ret = gpio_direction_input(client->irq);
609     if (ret) {
610         DBG("failed to set ft5x0x gpio input\n");
611                 return ret;
612     }
613
614         gpio_pull_updown(client->irq, GPIOPullUp);
615         client->irq = gpio_to_irq(client->irq);
616         //ft5x0x->irq = client->irq;
617         ret = request_irq(client->irq, ft5x0x_interrupt, IRQF_TRIGGER_FALLING, client->dev.driver->name, tsdata);
618         DBG("request irq is %d,ret is 0x%x\n", client->irq, ret);
619         if (ret ) {
620                 DBG(KERN_ERR "ft5x0x_client_init: request irq failed,ret is %d\n", ret);
621         return ret;
622         }
623         //disable_irq(client->irq);
624
625         return 0;
626 }
627
628 static int  ft5x0x_probe(struct i2c_client *client, const struct i2c_device_id *id)
629 {
630         struct ft5x0x_data *ft5x0x_ts;
631         struct ts_hw_data *pdata = client->dev.platform_data;
632         int err = 0;
633         int i;
634
635         printk("%s enter\n",__FUNCTION__);
636         ft5x0x_ts = kzalloc(sizeof(struct ft5x0x_data), GFP_KERNEL);
637         if (!ft5x0x_ts) {
638                 DBG("[ft5x0x]:alloc data failed.\n");
639                 err = -ENOMEM;
640                 goto exit_alloc_data_failed;
641         }
642     
643     memset(ts_point, 0x0, sizeof(struct ts_event) * MAX_POINT);
644
645         g_client = client;
646         ft5x0x_ts->client = client;
647         ft5x0x_ts->last_point_num = 0;
648         ft5x0x_ts->reset_gpio = pdata->reset_gpio;
649         ft5x0x_ts->touch_en_gpio = pdata->touch_en_gpio;
650         i2c_set_clientdata(client, ft5x0x_ts);
651
652         err = ft5x0x_chip_init(client);
653         if (err < 0) {
654                 printk(KERN_ERR
655                        "ft5x0x_probe: ft5x0x chip init failed\n");
656                 goto exit_request_gpio_irq_failed;
657         }
658
659         err = ft5x0x_client_init(client);
660         if (err < 0) {
661                 printk(KERN_ERR
662                        "ft5x0x_probe: ft5x0x_client_init failed\n");
663                 goto exit_request_gpio_irq_failed;
664         }
665                 
666         ft5x0x_ts->input_dev = input_allocate_device();
667         if (!ft5x0x_ts->input_dev) {
668                 err = -ENOMEM;
669                 printk(KERN_ERR
670                        "ft5x0x_probe: Failed to allocate input device\n");
671                 goto exit_input_allocate_device_failed;
672         }
673
674         ft5x0x_ts->input_dev->name = "ft5x0x-ts";
675         ft5x0x_ts->input_dev->dev.parent = &client->dev;
676
677         err = input_register_device(ft5x0x_ts->input_dev);
678         if (err < 0) {
679                 printk(KERN_ERR
680                        "ft5x0x_probe: Unable to register input device: %s\n",
681                        ft5x0x_ts->input_dev->name);
682                 goto exit_input_register_device_failed;
683         }
684
685         INIT_WORK(&ft5x0x_ts->pen_event_work, ft5x0x_delaywork_func);
686         ft5x0x_ts->ts_workqueue = create_singlethread_workqueue("ft5x0x_ts");
687         if (!ft5x0x_ts->ts_workqueue) {
688                 err = -ESRCH;
689                 goto exit_request_gpio_irq_failed;
690         }
691
692
693         __set_bit(EV_SYN, ft5x0x_ts->input_dev->evbit);
694         __set_bit(EV_KEY, ft5x0x_ts->input_dev->evbit);
695         __set_bit(EV_ABS, ft5x0x_ts->input_dev->evbit);
696         __set_bit(INPUT_PROP_DIRECT, ft5x0x_ts->input_dev->propbit);
697
698         input_mt_init_slots(ft5x0x_ts->input_dev, MAX_POINT);
699         input_set_abs_params(ft5x0x_ts->input_dev, ABS_MT_POSITION_X, 0, SCREEN_MAX_X, 0, 0);
700         input_set_abs_params(ft5x0x_ts->input_dev, ABS_MT_POSITION_Y, 0, SCREEN_MAX_Y, 0, 0);
701         input_set_abs_params(ft5x0x_ts->input_dev, ABS_MT_TOUCH_MAJOR, 0, PRESS_MAX, 0, 0);
702
703 #ifdef CONFIG_HAS_EARLYSUSPEND
704     ft5x0x_early_suspend.suspend = ft5x0x_suspend;
705     ft5x0x_early_suspend.resume = ft5x0x_resume;
706     ft5x0x_early_suspend.level = 0x2;
707     register_early_suspend(&ft5x0x_early_suspend);
708 #endif
709
710         return 0;
711
712 exit_input_register_device_failed:
713         input_free_device(ft5x0x_ts->input_dev);
714 exit_input_allocate_device_failed:
715     free_irq(client->irq, ft5x0x_ts);
716 exit_request_gpio_irq_failed:
717         kfree(ft5x0x_ts);       
718 exit_alloc_gpio_power_failed:
719 #if defined (TOUCH_POWER_PIN)
720         gpio_free(ft5x0x_ts->touch_en_gpio);
721 #endif
722 exit_alloc_gpio_rst_failed:
723     gpio_free(ft5x0x_ts->reset_gpio);
724 exit_alloc_data_failed:
725         printk("%s error\n",__FUNCTION__);
726         return err;
727 }
728
729 static void __init ft5x0x_init_async(void *unused, async_cookie_t cookie)
730 {
731         i2c_add_driver(&ft5x0x_driver);
732 }
733
734 static int __init ft5x0x_mod_init(void)
735 {
736         printk("ft5x0x module init\n");
737         async_schedule(ft5x0x_init_async, NULL);
738         return 0;
739 }
740
741 static void __exit ft5x0x_mod_exit(void)
742 {
743         i2c_del_driver(&ft5x0x_driver);
744 }
745
746 module_init(ft5x0x_mod_init);
747 module_exit(ft5x0x_mod_exit);
748
749 MODULE_DESCRIPTION("ft5406 touch driver");
750 MODULE_AUTHOR("zqqu<zqqu@yifangdigital.com>");
751 MODULE_LICENSE("GPL");
752