3 * Copyright (C) 2011 Goodix, Inc.
8 #include <linux/kernel.h>
9 #include <linux/module.h>
10 #include <linux/delay.h>
11 #include <linux/device.h>
12 #include <linux/interrupt.h>
14 #include <mach/gpio.h>
15 //#include <plat/gpio-cfg.h>
16 #include <linux/irq.h>
17 #include <linux/err.h>
18 #include<linux/workqueue.h>
19 #include<linux/slab.h>
20 #include <linux/goodix_touch_82x.h> //w++
22 #include <linux/input/mt.h>
24 #define READ_TOUCH_ADDR_H 0x0F
25 #define READ_TOUCH_ADDR_L 0x40
26 #define READ_KEY_ADDR_H 0x0F
27 #define READ_KEY_ADDR_L 0x41
28 #define READ_COOR_ADDR_H 0x0F
29 #define READ_COOR_ADDR_L 0x42
30 #define RESOLUTION_LOC 71
31 #define TRIGGER_LOC 66
32 //#typedef s32 int //w++
34 struct goodix_ts_data {
36 struct i2c_client *client;
37 struct input_dev *input_dev;
42 struct work_struct work;
46 s32 (*power)(struct goodix_ts_data * ts, s32 on);
47 struct early_suspend early_suspend;
57 struct goodix_ts_data *ts82x_temp; //w++
59 static struct workqueue_struct *goodix_wq;
60 static const char *goodix_ts_name ="Goodix TouchScreen of Guitar ";//"Goodix Capacitive TouchScreen";
62 static s32 goodix_ts_remove(struct i2c_client *);
64 #ifdef CONFIG_HAS_EARLYSUSPEND
65 static void goodix_ts_early_suspend(struct early_suspend *h);
66 static void goodix_ts_late_resume(struct early_suspend *h);
70 extern s32 init_wr_node(struct i2c_client*);
71 extern void uninit_wr_node(void);
74 #ifdef AUTO_UPDATE_GUITAR
75 extern s32 init_update_proc(struct goodix_ts_data *);
77 static void guitar_reset( struct goodix_ts_data *ts,u8 ms);
80 static int err_gt82x = 0; //w++记载有没有此设备的检测
81 //#define LONGPRESS_LOCK_SPECKEY
82 #ifdef LONGPRESS_LOCK_SPECKEY
83 #define KEY_LOCK KEY_F13
84 #define LOCK_LONG_PRESS_CNT 20
85 static int Origin2LockPressCnt = 0;
86 static int lockflag =0;
87 //static int touch_key_hold_press = 0;
89 ssize_t glock_status_show_gt82x(struct device *dev, char *buf)
91 return sprintf(buf, "%d", lockflag);
93 struct timer_list longkey_timer_82x;
95 #ifdef LONGPRESS_LOCK_SPECKEY
96 static DRIVER_ATTR(get_lock_status, 0777, glock_status_show_gt82x, NULL);
100 #define TOUCH_MAX_HEIGHT 1024 //w++2
101 #define TOUCH_MAX_WIDTH 768
104 u16 TOUCH_MAX_HEIGHT;
108 #define GT828_I2C_RATE 200000
110 /*Function as i2c_master_send */
111 static s32 i2c_read_bytes(struct i2c_client *client, u8 *buf, s32 len)
113 struct i2c_msg msgs[2];
116 msgs[0].flags=!I2C_M_RD;
117 msgs[0].addr=client->addr;
120 msgs[0].scl_rate=100000;
123 msgs[1].flags=I2C_M_RD;
124 msgs[1].addr=client->addr;
125 msgs[1].len=len - ADDR_LENGTH;
127 msgs[1].scl_rate=100000;
130 ret=i2c_transfer(client->adapter,msgs, 2);
135 /*Function as i2c_master_send */
136 static s32 i2c_write_bytes(struct i2c_client *client,u8 *data,s32 len)
142 msg.addr=client->addr;
147 ret=i2c_transfer(client->adapter,&msg, 1);
152 static s32 i2c_pre_cmd(struct goodix_ts_data *ts)
155 u8 pre_cmd_data[2]={0x0f, 0xff};
157 ret=i2c_write_bytes(ts->client,pre_cmd_data,2);
161 static s32 i2c_end_cmd(struct goodix_ts_data *ts)
164 u8 end_cmd_data[2]={0x80, 0x00};
166 ret=i2c_write_bytes(ts->client,end_cmd_data,2);
171 s32 goodix_init_panel(struct goodix_ts_data *ts, u8 send)
176 0x0F,0x80,/*config address*/
180 0x02,0x11,0x03,0x12,0x04,0x13,0x05,0x14,0x06,0x15,0x07,0x16,0x08,0x17,0x09,
181 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
182 0x11,0x07,0x10,0x06,0x0F,0x05,0x0E,0x04,0x0D,0x03,0xFF,0xFF,0xFF,0xFF,0xFF,
183 0xFF,0xFF,0xFF,0xFF,0xFF,0x0F,0x03,0xE0,0x10,0x10,0x21,0x00,0x00,0x09,0x00,
184 0x00,0x02,0x45,0x2D,0x1C,0x03,0x00,0x05,0x00,0x02,0x58,0x03,0x20,0x25,0x29,
185 0x27,0x2B,0x25,0x00,0x06,0x19,0x25,0x14,0x10,0x00,0x13,0x01,0x00,0x00,0x00,
186 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
187 0x00,0x00,0x00,0x00,0x00,0x00,0x01
189 //300-N3788E-A00-V1.0 1024*768
191 0x02,0x11,0x03,0x12,0x04,0x13,0x05,0x14,0x06,0x15,0x07,0x16,0x08,0x17,0x09,
192 0x18,0x0A,0x19,0xFF,0x13,0xFF,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,
193 0x12,0x08,0x11,0x07,0x10,0x06,0x0F,0x05,0x0E,0x04,0x0D,0x03,0xFF,0x00,0xFF,
194 0x0E,0x0F,0x10,0x11,0x12,0x09,0x03,0x88,0x88,0x88,0x25,0x00,0x00,0x08,0x00,
195 0x00,0x02,0x3C,0x28,0x1C,0x03,0x00,0x05,0x00,0x02,0x58,0x03,0x20,0x33,0x38,
196 0x30,0x35,0x25,0x00,0x25,0x19,0x05,0x14,0x10,0x02,0x30,0x01,0x00,0x00,0x00,
197 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
198 0x00,0x00,0x00,0x00,0x00,0x00,0x01
200 0x02,0x11,0x03,0x12,0x04,0x13,0x05,0x14,0x06,0x15,0x07,0x16,0x08,0x17,0x09,
201 0x18,0x0A,0x19,0x0B,0x1A,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
202 0x12,0x08,0x11,0x07,0x10,0x06,0x0F,0x05,0x0E,0x04,0x0D,0x03,0xFF,0xFF,0xFF,
203 0xFF,0xFF,0xFF,0xFF,0xFF,0x0F,0x03,0xE0,0x10,0x10,0x19,0x00,0x00,0x08,0x00,
204 0x00,0x02,0x45,0x2D,0x1C,0x03,0x00,0x05,0x00,0x02,0x58,0x03,0x20,0x2D,0x38,
205 0x2F,0x3B,0x25,0x00,0x06,0x19,0x25,0x14,0x10,0x00,0x01,0x01,0x00,0x00,0x00,
206 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
207 0x00,0x00,0x00,0x00,0x00,0x00,0x01
209 0x02,0x11,0x03,0x12,0x04,0x13,0x05,0x14,0x06,0x15,0x07,0x16,0x08,0x17,0x09,
210 0x18,0x0A,0x19,0x0B,0x1A,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
211 0x12,0x08,0x11,0x07,0x10,0x06,0x0F,0x05,0x0E,0x04,0x0D,0x03,0xFF,0xFF,0xFF,
212 0xFF,0xFF,0xFF,0xFF,0xFF,0x0F,0x03,0xE0,0x10,0x10,0x19,0x00,0x00,0x08,0x00,
213 0x00,0x02,0x45,0x2D,0x1C,0x03,0x00,0x05,0x00,0x02,0x58,0x03,0x20,0x2D,0x38,
214 0x2F,0x3B,0x25,0x00,0x06,0x19,0x25,0x14,0x10,0x00,0x01,0x01,0x00,0x00,0x00,
215 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
216 0x00,0x00,0x00,0x00,0x00,0x00,0x01
221 TOUCH_MAX_WIDTH = ((config_info[RESOLUTION_LOC] << 8)|config_info[RESOLUTION_LOC + 1]);
222 TOUCH_MAX_HEIGHT = ((config_info[RESOLUTION_LOC + 2] << 8)|config_info[RESOLUTION_LOC + 3]);
224 GTDEBUG_MSG("TOUCH_MAX_WIDTH : 0x%d\n", (s32)TOUCH_MAX_WIDTH);
225 GTDEBUG_MSG("TOUCH_MAX_HEIGHT : 0x%d\n", (s32)TOUCH_MAX_HEIGHT);
228 config_info[RESOLUTION_LOC] = TOUCH_MAX_WIDTH >> 8;
229 config_info[RESOLUTION_LOC + 1] = TOUCH_MAX_WIDTH & 0xff;
230 config_info[RESOLUTION_LOC + 2] = TOUCH_MAX_HEIGHT >> 8;
231 config_info[RESOLUTION_LOC + 3] = TOUCH_MAX_HEIGHT & 0xff;
235 if (INT_TRIGGER == GT_IRQ_FALLING) {
236 config_info[TRIGGER_LOC] &= 0xf7;
237 } else if (INT_TRIGGER == GT_IRQ_RISING) {
238 config_info[TRIGGER_LOC] |= 0x08;
242 ret=i2c_write_bytes(ts->client,config_info, (sizeof(config_info)/sizeof(config_info[0])));
252 static s32 touch_num(u8 value, s32 max)
256 while((tmp < max) && value) {
257 if ((value & 0x01) == 1) {
266 #ifdef LONGPRESS_LOCK_SPECKEY //w++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
267 static void open_longkey_timer_82x(unsigned long data)
269 if((++Origin2LockPressCnt>LOCK_LONG_PRESS_CNT)&&(Origin2LockPressCnt<LOCK_LONG_PRESS_CNT+2)) { //w++超过一个时间,发长按消息
270 Origin2LockPressCnt = LOCK_LONG_PRESS_CNT + 3;
272 input_report_key(ts82x_temp->input_dev, KEY_LOCK, 1);
273 lockflag = (lockflag)? 0 : 1;
274 input_sync(ts82x_temp->input_dev);
277 longkey_timer_82x.expires=jiffies+msecs_to_jiffies(100);
278 add_timer(&longkey_timer_82x);
279 printk("w++++++++ Origin2LockPressCnt = %d\n",Origin2LockPressCnt);
280 printk("lockflag = %d\n",lockflag);
284 static void goodix_ts_work_func(struct work_struct *work)
289 static u8 last_key = 0;
299 u8 touch_data[2 + 2 + 5*MAX_FINGER_NUM + 1] = {READ_TOUCH_ADDR_H,READ_TOUCH_ADDR_L,0, 0};
300 static u8 finger_last[MAX_FINGER_NUM]={0};
301 u8 finger_current[MAX_FINGER_NUM] = {0};
303 struct goodix_ts_data *ts = container_of(work, struct goodix_ts_data, work);
304 struct i2c_client *client = ts->client;
305 struct goodix_i2c_rmi_platform_data *pdata = client->dev.platform_data;
311 dev_info(&(ts->client->dev), "Because of transfer error,touchscreen stop working.\n");
315 ret=i2c_read_bytes(ts->client, touch_data,sizeof(touch_data)/sizeof(touch_data[0]));
318 dev_err(&(ts->client->dev),"I2C transfer error. Number:%d\n ", ret);
322 goto COORDINATE_POLL;
329 //TODO:Is sending config once again (to reset the chip) useful?
334 if((touch_data[2]&0xC0)!=0x80) {
339 key = touch_data[3]&0x0f; // 1, 2, 4, 8
341 if (fail == goodix_init_panel(ts, 1)) {
342 GTDEBUG_COOR("Reload config failed!\n");
344 GTDEBUG_COOR("Reload config successfully!\n");
349 finger = (u8)touch_num(touch_data[2]&0x1f, MAX_FINGER_NUM);
351 GTDEBUG_COOR("touch num:%x\n", finger);
353 for (i = 0;i < MAX_FINGER_NUM; i++) {
354 finger_current[i] = !!(touch_data[2] & (0x01<<(i)));
357 coor_point = &touch_data[4];
359 for ( i = 0; i < 5*finger; i++) {
360 chk_sum += coor_point[i];
361 //GTDEBUG_COOR("%5x", coor_point[i]);
363 //GTDEBUG_COOR("\ncheck sum:%x\n", chk_sum);
364 //GTDEBUG_COOR("check sum byte:%x\n", coor_point[5*finger]);
365 if (chk_sum != coor_point[5*finger]) {
370 for(i = 0, position=0;position < MAX_FINGER_NUM; position++) {
371 if(finger_current[position]) {
372 X_value = (coor_point[i] << 8) | coor_point[i + 1];
373 Y_value = (coor_point[i + 2] << 8) | coor_point[i + 3];
375 input_mt_slot(ts->input_dev, position);
376 input_mt_report_slot_state(ts->input_dev, MT_TOOL_FINGER, true);
377 input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, FLAG_DOWN);
379 //input_report_key(ts->input_dev, BTN_TOUCH, 1);
380 //input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, position - 1);
386 //printk("goodix_touch_82x X_value=%d,Y_value=%d\n",X_value,Y_value);
388 X_value = pdata->xmax - X_value;
390 Y_value = pdata->ymax - Y_value;
392 input_report_abs(ts->input_dev, ABS_MT_POSITION_X, X_value); //can change x-y!!!
393 input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, 600-Y_value);
394 //input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR,15);
395 //input_mt_sync(ts->input_dev);
398 //GTDEBUG_COOR("FI:%x X:%04d Y:%04d\n",position, (s32)Y_value,(s32)X_value);
399 //printk("-----------touch_num:%d;--------FI:%x----------- X:%04d ----------Y:%04d\n",finger,position, (s32)X_value,(s32)Y_value);
400 //GTDEBUG_COOR("Y:%d\n", (s32)Y_value);
401 } else if(finger_last[position]) {
402 input_mt_slot(ts->input_dev, position);
403 input_mt_report_slot_state(ts->input_dev, MT_TOOL_FINGER, false);
404 GTDEBUG_COOR(" Finger %d release!!\n",position);
408 for(position=0;position < MAX_FINGER_NUM; position++) {
409 if( finger_last[position]) {
410 input_mt_slot(ts->input_dev, position);
411 input_mt_report_slot_state(ts->input_dev, MT_TOOL_FINGER, false);
412 GTDEBUG_COOR(" Finger %d release!!\n",position);
417 input_sync(ts->input_dev);
419 for(position=0;position<MAX_FINGER_NUM; position++) {
420 finger_last[position] = finger_current[position];
425 if(ts->use_irq && ts->irq_is_disable == 1) {
426 ts->irq_is_disable = 0;
427 enable_irq(ts->client->irq);
431 static enum hrtimer_restart goodix_ts_timer_func(struct hrtimer *timer)
433 struct goodix_ts_data *ts = container_of(timer, struct goodix_ts_data, timer);
435 queue_work(goodix_wq, &ts->work);
436 hrtimer_start(&ts->timer, ktime_set(0, (POLL_TIME+6)*1000000), HRTIMER_MODE_REL);
438 return HRTIMER_NORESTART;
441 static irqreturn_t goodix_ts_irq_handler(s32 irq, void *dev_id)
443 struct goodix_ts_data *ts = (struct goodix_ts_data*)dev_id;
445 if (ts->use_irq && (!ts->irq_is_disable)) {
446 disable_irq_nosync(ts->client->irq);
447 ts->irq_is_disable = 1;
450 queue_work(goodix_wq, &ts->work);
455 //#if defined(INT_PORT) // 0 : sleep 1 wake up
456 static s32 goodix_ts_power(struct goodix_ts_data * ts, s32 on)
459 u8 i2c_control_buf[3] = {0x0f,0xf2,0xc0}; //suspend cmd
461 if(ts == NULL || !ts->use_irq)
467 ret = i2c_write_bytes(ts->client, i2c_control_buf, 3);
471 GPIO_DIRECTION_OUTPUT(ts->interrupt_port, 0);
473 GPIO_SET_VALUE(ts->interrupt_port, 1);
474 GPIO_DIRECTION_INPUT(ts->interrupt_port);
475 GPIO_PULL_UPDOWN(ts->interrupt_port, 0);
479 GTDEBUG_MSG(KERN_DEBUG "%s: Cant't support this command.", goodix_ts_name);
485 static s32 init_input_dev(struct goodix_ts_data *ts)
490 ts->input_dev = input_allocate_device();
491 if (ts->input_dev == NULL)
493 dev_dbg(&ts->client->dev,"goodix_ts_probe: Failed to allocate input device\n");
497 //ts->input_dev->evbit[0] = BIT_MASK(EV_SYN) | BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
498 //ts->input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
499 //ts->input_dev->absbit[0] = BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_PRESSURE);// absolute coor (x,y)
501 goodix_init_panel(ts, 0);
503 #ifdef GOODIX_MULTI_TOUCH
505 __set_bit(INPUT_PROP_DIRECT, ts->input_dev->propbit);
506 __set_bit(EV_ABS, ts->input_dev->evbit);
507 input_mt_init_slots(ts->input_dev, MAX_FINGER_NUM);
508 input_set_abs_params(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
509 input_set_abs_params(ts->input_dev, ABS_MT_POSITION_X, 0, TOUCH_MAX_HEIGHT, 0, 0);
510 input_set_abs_params(ts->input_dev, ABS_MT_POSITION_Y, 0, TOUCH_MAX_WIDTH, 0, 0);
513 input_mt_init_slots(ts->input_dev, MAX_FINGER_NUM);
514 input_set_abs_params(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0, 255, 0, 0);
515 input_set_abs_params(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
516 input_set_abs_params(ts->input_dev, ABS_MT_POSITION_X, 0, TOUCH_MAX_HEIGHT, 0, 0);
517 input_set_abs_params(ts->input_dev, ABS_MT_POSITION_Y, 0, TOUCH_MAX_WIDTH, 0, 0);
520 input_set_abs_params(ts->input_dev, ABS_X, 0, TOUCH_MAX_HEIGHT, 0, 0);
521 input_set_abs_params(ts->input_dev, ABS_Y, 0, TOUCH_MAX_WIDTH, 0, 0);
522 input_set_abs_params(ts->input_dev, ABS_PRESSURE, 0, 255, 0, 0);
525 memcpy(ts->phys, "input/ts", 8);
526 ts->input_dev->name = goodix_ts_name;
527 ts->input_dev->phys = ts->phys;
528 ts->input_dev->id.bustype = BUS_I2C;
529 ts->input_dev->id.vendor = 0xDEAD;
530 ts->input_dev->id.product = 0xBEEF;
531 ts->input_dev->id.version = 10427; //screen firmware version
533 #ifdef LONGPRESS_LOCK_SPECKEY //w++
534 set_bit(KEY_LOCK, ts->input_dev->keybit);
536 ret = input_register_device(ts->input_dev);
538 dev_err(&ts->client->dev,"Probe: Unable to register %s input device\n", ts->input_dev->name);
539 input_free_device(ts->input_dev);
542 GTDEBUG_MSG("Register input device successfully!\n");
547 static s32 set_pins(struct goodix_ts_data *ts)
551 //ts->client->irq=TS_INT; //If not defined in client
552 if (ts->client->irq) {
553 ret = GPIO_REQUEST(ts->interrupt_port, "TS_INT"); //Request IO
555 dev_err(&ts->client->dev, "Failed to request GPIO:%d, ERRNO:%d\n",(s32)ts->interrupt_port,ret);
556 goto err_gpio_request_failed;
558 GTDEBUG_MSG("Request int port successfully!\n");
560 GPIO_DIRECTION_INPUT(ts->interrupt_port);
561 GPIO_PULL_UPDOWN(ts->interrupt_port, 0);
562 //GPIO_CFG_PIN(INT_PORT, INT_CFG); //Set IO port function
564 ret = request_irq(gpio_to_irq(ts->interrupt_port), goodix_ts_irq_handler,
565 IRQF_TRIGGER_FALLING, ts->client->name, ts);
568 dev_err(&ts->client->dev,"Cannot allocate ts INT!ERRNO:%d\n", ret);
569 GPIO_DIRECTION_INPUT(ts->interrupt_port);
570 GPIO_FREE(ts->interrupt_port);
571 goto err_gpio_request_failed;
573 disable_irq(ts->client->irq);
575 ts->irq_is_disable = 1;
576 dev_dbg(&ts->client->dev, "Reques EIRQ %d successed on GPIO:%d\n", gpio_to_irq(ts->interrupt_port), ts->interrupt_port);
580 err_gpio_request_failed:
582 hrtimer_init(&ts->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
583 ts->timer.function = goodix_ts_timer_func;
584 hrtimer_start(&ts->timer, ktime_set(1, 0), HRTIMER_MODE_REL);
585 GTDEBUG_MSG("Use timer!\n");
588 ret = GPIO_REQUEST(ts->reset_port, "TS_RESET"); //Request IO
590 dev_err(&ts->client->dev, "Failed to request GPIO:%d, ERRNO:%d\n",(s32)ts->reset_port,ret);
593 GPIO_DIRECTION_OUTPUT(ts->reset_port,1);
594 GPIO_PULL_UPDOWN(ts->reset_port, 0);
595 GTDEBUG_MSG("Request reset port successfully!\n");
598 dev_info(&ts->client->dev,"Start %s in %s mode\n",
599 ts->input_dev->name, ts->use_irq ? "interrupt" : "polling");
604 static s32 goodix_ts_probe(struct i2c_client *client, const struct i2c_device_id *id)
608 struct goodix_ts_data *ts = NULL;
609 struct goodix_i2c_rmi_platform_data *pdata = client->dev.platform_data;
610 //struct ft5406_platform_data *pdata = pdata = client->dev.platform_data;
611 printk("w++++++goodix_ts_probe gt28x ");
613 if (pdata->init_platform_hw) {
614 pdata->init_platform_hw();
617 //printk("gt82x---0000000000000000\n");
619 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
620 dev_err(&client->dev, "Must have I2C_FUNC_I2C.\n");
624 ts = kzalloc(sizeof(*ts), GFP_KERNEL);
628 pdata = client->dev.platform_data;
630 INIT_WORK(&ts->work, goodix_ts_work_func); //init work_struct
632 ts->power = goodix_ts_power;
636 ts->irq_is_disable = 0;
637 ts->interrupt_port=pdata->gpio_irq;
638 ts->reset_port=pdata->gpio_reset;
639 i2c_set_clientdata(client, ts);
641 if (fail == init_input_dev(ts)) {
646 #ifdef CONFIG_HAS_EARLYSUSPEND
647 ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
648 ts->early_suspend.suspend = goodix_ts_early_suspend;
649 ts->early_suspend.resume = goodix_ts_late_resume;
650 register_early_suspend(&ts->early_suspend);
652 #ifdef CREATE_WR_NODE
653 init_wr_node(client);
655 #ifdef AUTO_UPDATE_GUITAR
656 if (0xff == init_update_proc(ts)) {
657 GTDEBUG_MSG("Need update!\n");
665 //Test I2C connection.
666 //GTDEBUG_MSG("GT82X++++++ Testing I2C connection...\n");
667 for(retry = 0;retry < 3; retry++) {
668 ret = i2c_pre_cmd(ts);
674 dev_err(&client->dev, "Warnning: I2C communication might be ERROR!\n");
675 GTDEBUG_MSG("I2C test failed. I2C addr:%x\n", client->addr);
676 goodix_ts_remove(ts->client);
679 //printk("gt82x---777777777777777\n");
681 for (retry = 0; retry < 3; retry++) {
682 if (success == goodix_init_panel(ts, 1)) {
683 GTDEBUG_MSG("Initialize successfully!\n");
689 GTDEBUG_MSG("Initialize failed!\n");
690 goodix_ts_remove(ts->client);
694 if(ts->use_irq && ts->irq_is_disable == 1) {
695 ts->irq_is_disable = 0;
696 enable_irq(client->irq);
702 static s32 goodix_ts_remove(struct i2c_client *client)
704 struct goodix_ts_data *ts = i2c_get_clientdata(client);
706 dev_notice(&client->dev,"The driver is removing...\n");
708 #ifdef CONFIG_HAS_EARLYSUSPEND
709 unregister_early_suspend(&ts->early_suspend);
712 #ifdef CREATE_WR_NODE
716 if (ts && ts->use_irq) {
717 free_irq(client->irq, ts);
718 GPIO_DIRECTION_INPUT(ts->interrupt_port);
719 GPIO_FREE(ts->interrupt_port);
721 hrtimer_cancel(&ts->timer);
724 if (ts && ts->use_reset) {
725 GPIO_DIRECTION_INPUT(ts->reset_port);
726 GPIO_FREE(ts->interrupt_port);
729 i2c_set_clientdata(client, NULL);
730 input_unregister_device(ts->input_dev);
731 input_free_device(ts->input_dev);
736 static s32 goodix_ts_suspend(struct i2c_client *client, pm_message_t mesg)
739 struct goodix_ts_data *ts = i2c_get_clientdata(client);
741 if (ts->irq_is_disable == 2) {
746 if (!ts->irq_is_disable) {
747 disable_irq(client->irq);
748 ts->irq_is_disable = 1;
751 hrtimer_cancel(&ts->timer);
755 ret = ts->power(ts, 0);
757 GTDEBUG_MSG(KERN_ERR "goodix_ts_resume power off failed\n");
759 printk("-----gt813------suspend.\n");
763 static s32 goodix_ts_resume(struct i2c_client *client)
766 struct goodix_ts_data *ts = i2c_get_clientdata(client);
768 if (ts->irq_is_disable == 2) {
773 ret = ts->power(ts, 1);
775 GTDEBUG_MSG(KERN_ERR "goodix_ts_resume power on failed\n");
779 ts->irq_is_disable = 0;
780 enable_irq(client->irq);
782 hrtimer_start(&ts->timer, ktime_set(1, 0), HRTIMER_MODE_REL);
784 printk("-----gt813------goodix_ts_resume.\n");
789 #ifdef CONFIG_HAS_EARLYSUSPEND
790 static void goodix_ts_early_suspend(struct early_suspend *h)
792 struct goodix_ts_data *ts;
793 ts = container_of(h, struct goodix_ts_data, early_suspend);
794 goodix_ts_suspend(ts->client, PMSG_SUSPEND);
797 static void goodix_ts_late_resume(struct early_suspend *h)
799 struct goodix_ts_data *ts;
800 ts = container_of(h, struct goodix_ts_data, early_suspend);
801 goodix_ts_resume(ts->client);
805 //******************************Begin of firmware update surpport*******************************
806 #ifndef AUTO_UPDATE_GUITAR
807 static void guitar_reset( struct goodix_ts_data *ts,u8 ms)
809 GPIO_DIRECTION_OUTPUT(ts->reset_port, 0);
810 GPIO_SET_VALUE(ts->reset_port, 0);
813 //GPIO_DIRECTION_OUTPUT(ts->reset_port);
814 GPIO_SET_VALUE(ts->reset_port, 1);
815 GPIO_PULL_UPDOWN(ts->reset_port, 0);
818 err_gpio_request_failed:
824 static const struct i2c_device_id goodix_ts_id[] = {
825 {"Goodix-TS-82X", 0 },
829 static struct i2c_driver goodix_ts_driver = {
830 .probe = goodix_ts_probe,
831 .remove = goodix_ts_remove,
832 #ifndef CONFIG_HAS_EARLYSUSPEND
833 .suspend = goodix_ts_suspend,
834 .resume = goodix_ts_resume,
836 .id_table = goodix_ts_id,
838 .name = "Goodix-TS-82X",
839 .owner = THIS_MODULE,
843 static s32 __devinit goodix_ts_init(void)
847 printk("+++++++++++++++++++++++++++++liqing.\n");
848 goodix_wq = create_workqueue("goodix_wq"); //create a work queue and worker thread
850 GTDEBUG_MSG(KERN_ALERT "creat workqueue faiked\n");
853 ret = i2c_add_driver(&goodix_ts_driver);
855 printk("Register raydium_ts driver failed gt82x.\n");
858 #ifdef LONGPRESS_LOCK_SPECKEY
859 if(err_gt82x>=0) //w++
861 ret =driver_create_file(&goodix_ts_driver.driver, &driver_attr_get_lock_status);
866 static void __exit goodix_ts_exit(void)
868 GTDEBUG_MSG(KERN_ALERT "Touchscreen driver of guitar exited.\n");
869 i2c_del_driver(&goodix_ts_driver);
871 destroy_workqueue(goodix_wq); //release our work queue
872 #ifdef LONGPRESS_LOCK_SPECKEY //w++
873 driver_remove_file(&goodix_ts_driver.driver, &driver_attr_get_lock_status);
877 module_init(goodix_ts_init);
878 module_exit(goodix_ts_exit);
880 MODULE_DESCRIPTION("Goodix Touchscreen Driver");
881 MODULE_LICENSE("GPL");