ronnie
2022-10-23 6a9ad61a324330f2c3db7a89fda429161b7d887e
add gt911 drivers
2 files modified
5926 ■■■■■ changed files
longan/kernel/linux-4.9/drivers/input/touchscreen/gt9xx/gt9xx.c 1842 ●●●● patch | view | raw | blame | history
longan/kernel/linux-4.9/drivers/input/touchscreen/gt9xxnew/gt9xx.c 4084 ●●●● patch | view | raw | blame | history
longan/kernel/linux-4.9/drivers/input/touchscreen/gt9xx/gt9xx.c
....@@ -28,18 +28,18 @@
2828 #include <linux/pm.h>
2929
3030 #if GTP_ICS_SLOT_REPORT
31
- #include <linux/input/mt.h>
31
+#include <linux/input/mt.h>
3232 #endif
3333
3434 static const char *goodix_ts_name = "gt9xx";
3535 static struct workqueue_struct *goodix_wq;
3636 struct i2c_client * i2c_connect_client = NULL;
3737 static u8 config[GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH]
38
- = {GTP_REG_CONFIG_DATA >> 8, GTP_REG_CONFIG_DATA & 0xff};
38
+= {GTP_REG_CONFIG_DATA >> 8, GTP_REG_CONFIG_DATA & 0xff};
3939
4040 #if GTP_HAVE_TOUCH_KEY
41
- static const u16 touch_key_array[] = GTP_KEY_TAB;
42
- #define GTP_MAX_KEY_NUM (sizeof(touch_key_array)/sizeof(touch_key_array[0]))
41
+static const u16 touch_key_array[] = GTP_KEY_TAB;
42
+#define GTP_MAX_KEY_NUM (sizeof(touch_key_array)/sizeof(touch_key_array[0]))
4343 #endif
4444
4545 static s8 gtp_i2c_test(struct i2c_client *client);
....@@ -50,7 +50,7 @@
5050 static void goodix_ts_early_suspend(struct early_suspend *h);
5151 static void goodix_ts_late_resume(struct early_suspend *h);
5252 #endif
53
-
53
+
5454 #if GTP_CREATE_WR_NODE
5555
5656 extern s32 init_wr_node(struct i2c_client*);
....@@ -79,11 +79,11 @@
7979 #define PRESS_MAX (255)
8080
8181
82
-static int screen_max_x = 0;
83
-static int screen_max_y = 0;
84
-static int revert_x_flag = 0;
82
+static int screen_max_x = 1280;
83
+static int screen_max_y = 800;
84
+static int revert_x_flag = 1;
8585 static int revert_y_flag = 0;
86
-static int exchange_x_y_flag = 0;
86
+static int exchange_x_y_flag = 1;
8787 static __u32 twi_id = 0;
8888 static char irq_pin_name[8];
8989
....@@ -100,7 +100,7 @@
100100 };
101101
102102 #define dprintk(level_mask,fmt,arg...) if(unlikely(debug_mask & level_mask)) \
103
- printk("***CTP***"fmt, ## arg)
103
+ printk("***CTP***"fmt, ## arg)
104104 module_param_named(debug_mask,debug_mask,int,S_IRUGO | S_IWUSR | S_IWGRP);
105105
106106 static const unsigned short normal_i2c[3] = {0x14, 0x5d, I2C_CLIENT_END};
....@@ -129,27 +129,27 @@
129129 static int ctp_detect(struct i2c_client *client, struct i2c_board_info *info)
130130 {
131131 struct i2c_adapter *adapter = client->adapter;
132
- int ret = -1;
133
-
134
- if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)){
135
- printk("======return=====\n");
136
- return -ENODEV;
137
- }
138
-
139
- if(twi_id == adapter->nr){
140
- dprintk(DEBUG_INIT,"%s: addr = %x\n", __func__, client->addr);
141
- ret = gtp_i2c_test(client);
142
- printk("detect ret %d\n",ret);
143
- if(!ret){
144
- printk("%s:I2C connection might be something wrong \n", __func__);
145
- return -ENODEV;
146
- }else{
147
- strlcpy(info->type, CTP_NAME, I2C_NAME_SIZE);
148
- printk("======detect ok !=====\n");
149
- return 0;
150
- }
132
+ int ret = -1;
133
+
134
+ if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)){
135
+ printk("======return=====\n");
136
+ return -ENODEV;
137
+ }
138
+
139
+ if(twi_id == adapter->nr){
140
+ dprintk(DEBUG_INIT,"%s: addr = %x\n", __func__, client->addr);
141
+ ret = gtp_i2c_test(client);
142
+ printk("detect ret %d\n",ret);
143
+ if(!ret){
144
+ printk("%s:I2C connection might be something wrong \n", __func__);
145
+ return -ENODEV;
146
+ }else{
147
+ strlcpy(info->type, CTP_NAME, I2C_NAME_SIZE);
148
+ printk("======detect ok !=====\n");
149
+ return 0;
150
+ }
151151 }else{
152
- return -ENODEV;
152
+ return -ENODEV;
153153 }
154154 }
155155
....@@ -208,450 +208,454 @@
208208
209209 void gtp_set_int_value(int status)
210210 {
211
- long unsigned int config;
212
-
213
- config = SUNXI_PINCFG_PACK(SUNXI_PINCFG_TYPE_FUNC,0xFFFF);
214
- pin_config_get(SUNXI_PINCTRL,irq_pin_name,&config);
211
+ long unsigned int config;
215212
216
- if (1 != SUNXI_PINCFG_UNPACK_VALUE(config)){
217
- config = SUNXI_PINCFG_PACK(SUNXI_PINCFG_TYPE_FUNC,1);
218
- pin_config_set(SUNXI_PINCTRL,irq_pin_name,config);;
219
- }
213
+ config = SUNXI_PINCFG_PACK(SUNXI_PINCFG_TYPE_FUNC,0xFFFF);
214
+ pin_config_get(SUNXI_PINCTRL,irq_pin_name,&config);
220215
221
- __gpio_set_value(CTP_IRQ_NUMBER, status);
216
+ if (1 != SUNXI_PINCFG_UNPACK_VALUE(config)){
217
+ config = SUNXI_PINCFG_PACK(SUNXI_PINCFG_TYPE_FUNC,1);
218
+ pin_config_set(SUNXI_PINCTRL,irq_pin_name,config);;
219
+ }
220
+
221
+ __gpio_set_value(CTP_IRQ_NUMBER, status);
222222 }
223223
224224 void gtp_set_io_int(void)
225225 {
226
- long unsigned int config;
227
- config = SUNXI_PINCFG_PACK(SUNXI_PINCFG_TYPE_FUNC,0xFFFF);
228
- pin_config_get(SUNXI_PINCTRL,irq_pin_name,&config);
226
+ long unsigned int config;
227
+ config = SUNXI_PINCFG_PACK(SUNXI_PINCFG_TYPE_FUNC,0xFFFF);
228
+ pin_config_get(SUNXI_PINCTRL,irq_pin_name,&config);
229229
230
- if (6 != SUNXI_PINCFG_UNPACK_VALUE(config)) {
231
- config = SUNXI_PINCFG_PACK(SUNXI_PINCFG_TYPE_FUNC, 6);
232
- pin_config_set(SUNXI_PINCTRL, irq_pin_name, config);
233
- }
234
-
230
+ if (6 != SUNXI_PINCFG_UNPACK_VALUE(config)) {
231
+ config = SUNXI_PINCFG_PACK(SUNXI_PINCFG_TYPE_FUNC, 6);
232
+ pin_config_set(SUNXI_PINCTRL, irq_pin_name, config);
233
+ }
234
+
235235 }
236236
237237 void gtp_io_init(int ms)
238238 {
239
- ctp_wakeup(0, 0);
240
- msleep(ms);
241
-
242
- gtp_set_int_value(0);
243
- msleep(2);
244
-
245
- ctp_wakeup(1, 0);
246
- msleep(6);
239
+ ctp_wakeup(0, 0);
240
+ msleep(ms);
247241
248
-
242
+ gtp_set_int_value(0);
243
+ msleep(2);
244
+
245
+ ctp_wakeup(1, 0);
246
+ msleep(6);
247
+
248
+
249249 #if GTP_ESD_PROTECT
250
- // gtp_init_ext_watchdog(client);
250
+ // gtp_init_ext_watchdog(client);
251251 #endif
252
-
252
+
253253 }
254254
255255 /*******************************************************
256256 Function:
257
- Read data from the i2c slave device.
257
+Read data from the i2c slave device.
258258
259259 Input:
260
- client: i2c device.
261
- buf[0]:operate address.
262
- buf[1]~buf[len]:read data buffer.
263
- len:operate length.
264
-
260
+client: i2c device.
261
+buf[0]:operate address.
262
+buf[1]~buf[len]:read data buffer.
263
+len:operate length.
264
+
265265 Output:
266
- numbers of i2c_msgs to transfer
267
-*********************************************************/
266
+numbers of i2c_msgs to transfer
267
+ *********************************************************/
268268 s32 gtp_i2c_read(struct i2c_client *client, u8 *buf, s32 len)
269269 {
270
- struct i2c_msg msgs[2];
271
- s32 ret = -1;
272
- s32 retries = 0;
273
-
274
- msgs[0].flags = !I2C_M_RD;
275
- msgs[0].addr = client->addr;
276
- msgs[0].len = GTP_ADDR_LENGTH;
277
- msgs[0].buf = &buf[0];
278
-
279
- msgs[1].flags = I2C_M_RD;
280
- msgs[1].addr = client->addr;
281
- msgs[1].len = len - GTP_ADDR_LENGTH;
282
- msgs[1].buf = &buf[GTP_ADDR_LENGTH];
270
+ struct i2c_msg msgs[2];
271
+ s32 ret = -1;
272
+ s32 retries = 0;
283273
284
- while(retries < 2) {
285
- ret = i2c_transfer(client->adapter, msgs, 2);
286
- if(ret == 2)
287
- break;
288
- retries++;
289
- }
274
+ msgs[0].flags = !I2C_M_RD;
275
+ msgs[0].addr = client->addr;
276
+ msgs[0].len = GTP_ADDR_LENGTH;
277
+ msgs[0].buf = &buf[0];
290278
291
- if(retries >= 2) {
292
- printk("%s:I2C retry timeout, reset chip.", __func__);
293
- }
294
- return ret;
279
+ msgs[1].flags = I2C_M_RD;
280
+ msgs[1].addr = client->addr;
281
+ msgs[1].len = len - GTP_ADDR_LENGTH;
282
+ msgs[1].buf = &buf[GTP_ADDR_LENGTH];
283
+
284
+ while(retries < 2) {
285
+ ret = i2c_transfer(client->adapter, msgs, 2);
286
+ if(ret == 2)
287
+ break;
288
+ retries++;
289
+ }
290
+
291
+ if(retries >= 2) {
292
+ printk("%s:I2C retry timeout, reset chip.", __func__);
293
+ }
294
+ return ret;
295295 }
296296
297297 /*******************************************************
298298 Function:
299
- write data to the i2c slave device.
299
+write data to the i2c slave device.
300300
301301 Input:
302
- client: i2c device.
303
- buf[0]:operate address.
304
- buf[1]~buf[len]:write data buffer.
305
- len:operate length.
306
-
302
+client: i2c device.
303
+buf[0]:operate address.
304
+buf[1]~buf[len]:write data buffer.
305
+len:operate length.
306
+
307307 Output:
308
- numbers of i2c_msgs to transfer.
309
-*********************************************************/
308
+numbers of i2c_msgs to transfer.
309
+ *********************************************************/
310310 s32 gtp_i2c_write(struct i2c_client *client,u8 *buf,s32 len)
311311 {
312
- struct i2c_msg msg;
313
- s32 ret = -1;
314
- s32 retries = 0;
315
-
316
- msg.flags = !I2C_M_RD;
317
- msg.addr = client->addr;
318
- msg.len = len;
319
- msg.buf = buf;
320
-
321
- while(retries < 2) {
322
- ret = i2c_transfer(client->adapter, &msg, 1);
323
- if (ret == 1)
324
- break;
325
- retries++;
326
- }
312
+ struct i2c_msg msg;
313
+ s32 ret = -1;
314
+ s32 retries = 0;
327315
328
- if(retries >= 2) {
329
- printk("%s:I2C retry timeout, reset chip.", __func__);
330
- }
331
- return ret;
316
+ msg.flags = !I2C_M_RD;
317
+ msg.addr = client->addr;
318
+ msg.len = len;
319
+ msg.buf = buf;
320
+
321
+ while(retries < 2) {
322
+ ret = i2c_transfer(client->adapter, &msg, 1);
323
+ if (ret == 1)
324
+ break;
325
+ retries++;
326
+ }
327
+
328
+ if(retries >= 2) {
329
+ printk("%s:I2C retry timeout, reset chip.", __func__);
330
+ }
331
+ return ret;
332332 }
333333
334334 /*******************************************************
335335 Function:
336
- Send config Function.
336
+Send config Function.
337337
338338 Input:
339
- client: i2c client.
339
+client: i2c client.
340340
341341 Output:
342
- Executive outcomes.0--success,non-0--fail.
343
-*******************************************************/
342
+Executive outcomes.0--success,non-0--fail.
343
+ *******************************************************/
344344 s32 gtp_send_cfg(struct i2c_client *client)
345345 {
346
- s32 ret = 0;
347
-
348
-#if GTP_DRIVER_SEND_CFG
349
- s32 retry = 0;
346
+ s32 ret = 0;
350347
351
- for (retry = 0; retry < 5; retry++)
352
- {
353
- //ret = gtp_i2c_write(client, config , GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH);
354
- // if (ret > 0)
355
- // {
356
- // break;
357
- // }
358
- }
348
+#if GTP_DRIVER_SEND_CFG
349
+ s32 retry = 0;
350
+
351
+ for (retry = 0; retry < 5; retry++)
352
+ {
353
+ //ret = gtp_i2c_write(client, config , GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH);
354
+ // if (ret > 0)
355
+ // {
356
+ // break;
357
+ // }
358
+ }
359359 #endif
360360
361
- return ret;
361
+ return ret;
362362 }
363363
364364 /*******************************************************
365365 Function:
366
- Disable IRQ Function.
366
+Disable IRQ Function.
367367
368368 Input:
369
- ts: i2c client private struct.
370
-
369
+ts: i2c client private struct.
370
+
371371 Output:
372
- None.
373
-*******************************************************/
372
+None.
373
+ *******************************************************/
374374 void gtp_irq_disable(struct goodix_ts_data *ts)
375375 {
376
- unsigned long irqflags;
377
- int ret;
376
+ unsigned long irqflags;
377
+ int ret;
378378
379
- dprintk(DEBUG_INT_INFO, "%s ---start!---\n", __func__);
380
- spin_lock_irqsave(&ts->irq_lock, irqflags);
381
- if (!ts->irq_is_disable) {
382
- ts->irq_is_disable = 1;
383
- ret = input_set_int_enable(&(config_info.input_type), 0);
384
- if (ret < 0)
385
- dprintk(DEBUG_OTHERS_INFO,"%s irq disable failed\n", goodix_ts_name);
386
- }
387
- spin_unlock_irqrestore(&ts->irq_lock, irqflags);
379
+ dprintk(DEBUG_INT_INFO, "%s ---start!---\n", __func__);
380
+ spin_lock_irqsave(&ts->irq_lock, irqflags);
381
+ if (!ts->irq_is_disable) {
382
+ ts->irq_is_disable = 1;
383
+ ret = input_set_int_enable(&(config_info.input_type), 0);
384
+ if (ret < 0)
385
+ dprintk(DEBUG_OTHERS_INFO,"%s irq disable failed\n", goodix_ts_name);
386
+ }
387
+ spin_unlock_irqrestore(&ts->irq_lock, irqflags);
388388 }
389389
390390 /*******************************************************
391391 Function:
392
- Disable IRQ Function.
392
+Disable IRQ Function.
393393
394394 Input:
395
- ts: i2c client private struct.
396
-
395
+ts: i2c client private struct.
396
+
397397 Output:
398
- None.
399
-*******************************************************/
398
+None.
399
+ *******************************************************/
400400 void gtp_irq_enable(struct goodix_ts_data *ts)
401401 {
402
- unsigned long irqflags = 0;
403
- int ret;
402
+ unsigned long irqflags = 0;
403
+ int ret;
404404
405
- dprintk(DEBUG_INT_INFO, "%s ---start!---\n", __func__);
406
-
407
- spin_lock_irqsave(&ts->irq_lock, irqflags);
408
- if (ts->irq_is_disable) {
409
- ts->irq_is_disable = 0;
410
- ret = input_set_int_enable(&(config_info.input_type), 1);
411
- if (ret < 0)
412
- dprintk(DEBUG_OTHERS_INFO,"%s irq enable failed\n", goodix_ts_name);
413
- }
414
- spin_unlock_irqrestore(&ts->irq_lock, irqflags);
405
+ dprintk(DEBUG_INT_INFO, "%s ---start!---\n", __func__);
406
+
407
+ spin_lock_irqsave(&ts->irq_lock, irqflags);
408
+ if (ts->irq_is_disable) {
409
+ ts->irq_is_disable = 0;
410
+ ret = input_set_int_enable(&(config_info.input_type), 1);
411
+ if (ret < 0)
412
+ dprintk(DEBUG_OTHERS_INFO,"%s irq enable failed\n", goodix_ts_name);
413
+ }
414
+ spin_unlock_irqrestore(&ts->irq_lock, irqflags);
415415 }
416416
417417 /*******************************************************
418418 Function:
419
- Touch down report function.
419
+Touch down report function.
420420
421421 Input:
422
- ts:private data.
423
- id:tracking id.
424
- x:input x.
425
- y:input y.
426
- w:input weight.
427
-
422
+ts:private data.
423
+id:tracking id.
424
+x:input x.
425
+y:input y.
426
+w:input weight.
427
+
428428 Output:
429
- None.
430
-*******************************************************/
429
+None.
430
+ *******************************************************/
431431 static void gtp_touch_down(struct goodix_ts_data* ts,s32 id,s32 x,s32 y,s32 w)
432432 {
433
- dprintk(DEBUG_X_Y_INFO, "source data:ID:%d, X:%d, Y:%d, W:%d\n", id, x, y, w);
434
-
435
- if(1 == exchange_x_y_flag){
436
- swap(x, y);
437
- }
438
-
439
- if(1 == revert_x_flag){
440
- x = SCREEN_MAX_X - x;
441
- }
442
-
443
- if(1 == revert_y_flag){
444
- y = SCREEN_MAX_Y - y;
445
- }
446
-
447
- dprintk(DEBUG_X_Y_INFO,"report data:ID:%d, X:%d, Y:%d, W:%d\n", id, x, y, w);
433
+ dprintk(DEBUG_X_Y_INFO, "source data:ID:%d, X:%d, Y:%d, W:%d\n", id, x, y, w);
434
+
435
+ //printk(KERN_ERR"revert_x_flag=%d, revert_y_flag=%d, GTP_ICS_SLOT_REPORT=%d V2 SCREEN_MAX_X:SCREEN_MAX_Y=%d:%d\n", revert_x_flag, revert_y_flag, GTP_ICS_SLOT_REPORT, SCREEN_MAX_X, SCREEN_MAX_Y);
436
+ printk(KERN_ERR"(%d,%d)--->", x, y);
437
+
438
+ if(1 == exchange_x_y_flag){
439
+ swap(x, y);
440
+ }
441
+
442
+ if(1 == revert_x_flag){
443
+ x = SCREEN_MAX_X - x;
444
+ }
445
+
446
+ if(1 == revert_y_flag){
447
+ y = SCREEN_MAX_Y - y;
448
+ }
449
+ printk(KERN_ERR"(%d,%d)\n", x, y);
450
+
451
+ dprintk(DEBUG_X_Y_INFO,"report data:ID:%d, X:%d, Y:%d, W:%d\n", id, x, y, w);
448452
449453 #if GTP_ICS_SLOT_REPORT
450
- input_mt_slot(ts->input_dev, id);
451
- input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, id);
452
- input_report_abs(ts->input_dev, ABS_MT_POSITION_X, x);
453
- input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, y);
454
- input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, w);
455
- input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, w);
454
+ input_mt_slot(ts->input_dev, id);
455
+ input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, id);
456
+ input_report_abs(ts->input_dev, ABS_MT_POSITION_X, x);
457
+ input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, y);
458
+ input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, w);
459
+ input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, w);
456460 #else
457461 input_report_key(ts->input_dev, BTN_TOUCH, 1);
458462 input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, id);
459463 input_report_abs(ts->input_dev, ABS_MT_POSITION_X, x);
460
- input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, y);
461
- input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, w);
462
- input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, w);
463
- input_mt_sync(ts->input_dev);
464
+ input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, y);
465
+ input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, w);
466
+ input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, w);
467
+ input_mt_sync(ts->input_dev);
464468 #endif
465469
466470 }
467471
468472 /*******************************************************
469473 Function:
470
- Touch up report function.
474
+Touch up report function.
471475
472476 Input:
473
- ts:private data.
474
-
477
+ts:private data.
478
+
475479 Output:
476
- None.
477
-*******************************************************/
480
+None.
481
+ *******************************************************/
478482 static void gtp_touch_up(struct goodix_ts_data* ts, s32 id)
479483 {
480484 #if GTP_ICS_SLOT_REPORT
481
- input_mt_slot(ts->input_dev, id);
482
- input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, -1);
483
- dprintk(DEBUG_X_Y_INFO, "Touch id[%2d] release!", id);
485
+ input_mt_slot(ts->input_dev, id);
486
+ input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, -1);
487
+ dprintk(DEBUG_X_Y_INFO, "Touch id[%2d] release!", id);
484488 #else
485489 input_report_key(ts->input_dev, BTN_TOUCH, 0);
486
- input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0);
487
- input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0);
488
- input_mt_sync(ts->input_dev);
490
+ input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0);
491
+ input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0);
492
+ input_mt_sync(ts->input_dev);
489493 #endif
490494 }
491495
492496 /*******************************************************
493497 Function:
494
- Goodix touchscreen work function.
498
+Goodix touchscreen work function.
495499
496500 Input:
497
- work: work_struct of goodix_wq.
498
-
501
+work: work_struct of goodix_wq.
502
+
499503 Output:
500
- None.
501
-*******************************************************/
504
+None.
505
+ *******************************************************/
502506 static void goodix_ts_work_func(struct work_struct *work)
503507 {
504
- u8 end_cmd[3] = {GTP_READ_COOR_ADDR >> 8, GTP_READ_COOR_ADDR & 0xFF, 0};
505
- u8 point_data[2 + 1 + 8 * GTP_MAX_TOUCH + 1]={GTP_READ_COOR_ADDR >> 8, GTP_READ_COOR_ADDR & 0xFF};
506
- u8 touch_num = 0;
507
- u8 finger = 0;
508
- static u16 pre_touch = 0;
509
- static u8 pre_key = 0;
510
- u8 key_value = 0;
511
- u8* coor_data = NULL;
512
- s32 input_x = 0;
513
- s32 input_y = 0;
514
- s32 input_w = 0;
515
- s32 id = 0;
516
- s32 i = 0;
517
- int j = 0;
518
- s32 ret = -1;
519
- struct goodix_ts_data *ts = NULL;
508
+ u8 end_cmd[3] = {GTP_READ_COOR_ADDR >> 8, GTP_READ_COOR_ADDR & 0xFF, 0};
509
+ u8 point_data[2 + 1 + 8 * GTP_MAX_TOUCH + 1]={GTP_READ_COOR_ADDR >> 8, GTP_READ_COOR_ADDR & 0xFF};
510
+ u8 touch_num = 0;
511
+ u8 finger = 0;
512
+ static u16 pre_touch = 0;
513
+ static u8 pre_key = 0;
514
+ u8 key_value = 0;
515
+ u8* coor_data = NULL;
516
+ s32 input_x = 0;
517
+ s32 input_y = 0;
518
+ s32 input_w = 0;
519
+ s32 id = 0;
520
+ s32 i = 0;
521
+ int j = 0;
522
+ s32 ret = -1;
523
+ struct goodix_ts_data *ts = NULL;
520524
521
- dprintk(DEBUG_X_Y_INFO,"===enter %s===\n",__func__);
525
+ dprintk(DEBUG_X_Y_INFO,"===enter %s===\n",__func__);
522526
523
- ts = container_of(work, struct goodix_ts_data, work);
524
- if (ts->enter_update){
525
- return;
526
- }
527
+ ts = container_of(work, struct goodix_ts_data, work);
528
+ if (ts->enter_update){
529
+ return;
530
+ }
527531
528
- for(j=0; j<2;j++)
529
- {
530
- ret = gtp_i2c_read(ts->client, point_data, 12);
531
- if (ret < 0){
532
- printk("I2C transfer error. errno:%d\n ", ret);
533
- goto exit_work_func;
534
- }
532
+ for(j=0; j<2;j++)
533
+ {
534
+ ret = gtp_i2c_read(ts->client, point_data, 12);
535
+ if (ret < 0){
536
+ printk("I2C transfer error. errno:%d\n ", ret);
537
+ goto exit_work_func;
535538 }
539
+ }
536540
537
- finger = point_data[GTP_ADDR_LENGTH];
538
- if((finger & 0x80) == 0) {
539
- goto exit_work_func;
540
- }
541
+ finger = point_data[GTP_ADDR_LENGTH];
542
+ if((finger & 0x80) == 0) {
543
+ goto exit_work_func;
544
+ }
541545
542
- touch_num = finger & 0x0f;
543
- if (touch_num > GTP_MAX_TOUCH) {
544
- goto exit_work_func;
545
- }
546
+ touch_num = finger & 0x0f;
547
+ if (touch_num > GTP_MAX_TOUCH) {
548
+ goto exit_work_func;
549
+ }
546550
547
- if (touch_num > 1) {
548
- u8 buf[8 * GTP_MAX_TOUCH] = {(GTP_READ_COOR_ADDR + 10) >> 8, (GTP_READ_COOR_ADDR + 10) & 0xff};
551
+ if (touch_num > 1) {
552
+ u8 buf[8 * GTP_MAX_TOUCH] = {(GTP_READ_COOR_ADDR + 10) >> 8, (GTP_READ_COOR_ADDR + 10) & 0xff};
549553
550
- ret = gtp_i2c_read(ts->client, buf, 2 + 8 * (touch_num - 1));
551
- memcpy(&point_data[12], &buf[2], 8 * (touch_num - 1));
552
- }
554
+ ret = gtp_i2c_read(ts->client, buf, 2 + 8 * (touch_num - 1));
555
+ memcpy(&point_data[12], &buf[2], 8 * (touch_num - 1));
556
+ }
553557
554558 #if GTP_HAVE_TOUCH_KEY
555
- key_value = point_data[3 + 8 * touch_num];
556
-
557
- if(key_value || pre_key) {
558
- for (i = 0; i < GTP_MAX_KEY_NUM; i++) {
559
- input_report_key(ts->input_dev, touch_key_array[i], key_value & (0x01<<i));
560
- }
561
- touch_num = 0;
562
- pre_touch = 0;
563
- }
564
-#endif
565
- pre_key = key_value;
559
+ key_value = point_data[3 + 8 * touch_num];
566560
567
- dprintk(DEBUG_X_Y_INFO, "pre_touch:%02x, finger:%02x.", pre_touch, finger);
561
+ if(key_value || pre_key) {
562
+ for (i = 0; i < GTP_MAX_KEY_NUM; i++) {
563
+ input_report_key(ts->input_dev, touch_key_array[i], key_value & (0x01<<i));
564
+ }
565
+ touch_num = 0;
566
+ pre_touch = 0;
567
+ }
568
+#endif
569
+ pre_key = key_value;
570
+
571
+ dprintk(DEBUG_X_Y_INFO, "pre_touch:%02x, finger:%02x.", pre_touch, finger);
568572
569573 #if GTP_ICS_SLOT_REPORT
570
- if (pre_touch || touch_num) {
571
- s32 pos = 0;
572
- u16 touch_index = 0;
573
- coor_data = &point_data[3];
574
-
575
- if(touch_num) {
576
- id = coor_data[pos] & 0x0F;
577
- touch_index |= (0x01<<id);
578
- }
574
+ if (pre_touch || touch_num) {
575
+ s32 pos = 0;
576
+ u16 touch_index = 0;
577
+ coor_data = &point_data[3];
579578
580
- dprintk(DEBUG_X_Y_INFO,
581
- "id=%d, touch_index=0x%x, pre_touch=0x%x\n", id, touch_index, pre_touch);
582
-
583
- for (i = 0; i < GTP_MAX_TOUCH; i++) {
584
- if (touch_index & (0x01<<i)) {
585
- input_x = coor_data[pos + 1] | coor_data[pos + 2] << 8;
586
- input_y = coor_data[pos + 3] | coor_data[pos + 4] << 8;
587
- input_w = coor_data[pos + 5] | coor_data[pos + 6] << 8;
579
+ if(touch_num) {
580
+ id = coor_data[pos] & 0x0F;
581
+ touch_index |= (0x01<<id);
582
+ }
588583
589
- gtp_touch_down(ts, id, input_x, input_y, input_w);
590
- pre_touch |= 0x01 << i;
584
+ dprintk(DEBUG_X_Y_INFO,
585
+ "id=%d, touch_index=0x%x, pre_touch=0x%x\n", id, touch_index, pre_touch);
591586
592
- pos += 8;
593
- id = coor_data[pos] & 0x0F;
594
- touch_index |= (0x01<<id);
595
- }else {// if (pre_touch & (0x01 << i))
596
-
597
- gtp_touch_up(ts, i);
598
- pre_touch &= ~(0x01 << i);
599
- }
600
- }
601
- }
587
+ for (i = 0; i < GTP_MAX_TOUCH; i++) {
588
+ if (touch_index & (0x01<<i)) {
589
+ input_x = coor_data[pos + 1] | coor_data[pos + 2] << 8;
590
+ input_y = coor_data[pos + 3] | coor_data[pos + 4] << 8;
591
+ input_w = coor_data[pos + 5] | coor_data[pos + 6] << 8;
592
+
593
+ gtp_touch_down(ts, id, input_x, input_y, input_w);
594
+ pre_touch |= 0x01 << i;
595
+
596
+ pos += 8;
597
+ id = coor_data[pos] & 0x0F;
598
+ touch_index |= (0x01<<id);
599
+ }else {// if (pre_touch & (0x01 << i))
600
+
601
+ gtp_touch_up(ts, i);
602
+ pre_touch &= ~(0x01 << i);
603
+ }
604
+ }
605
+ }
602606
603607 #else
604
- if (touch_num ) {
605
- for (i = 0; i < touch_num; i++) {
606
- coor_data = &point_data[i * 8 + 3];
608
+ if (touch_num ) {
609
+ for (i = 0; i < touch_num; i++) {
610
+ coor_data = &point_data[i * 8 + 3];
607611
608
- id = coor_data[0] & 0x0F;
609
- input_x = coor_data[1] | coor_data[2] << 8;
610
- input_y = coor_data[3] | coor_data[4] << 8;
611
- input_w = coor_data[5] | coor_data[6] << 8;
612
+ id = coor_data[0] & 0x0F;
613
+ input_x = coor_data[1] | coor_data[2] << 8;
614
+ input_y = coor_data[3] | coor_data[4] << 8;
615
+ input_w = coor_data[5] | coor_data[6] << 8;
612616
613
- gtp_touch_down(ts, id, input_x, input_y, input_w);
614
- }
615
- }else if(pre_touch){
616
- dprintk(DEBUG_X_Y_INFO, "Touch Release!");
617
- gtp_touch_up(ts, 0);
618
- }
619
-
620
- pre_touch = touch_num;
617
+ gtp_touch_down(ts, id, input_x, input_y, input_w);
618
+ }
619
+ }else if(pre_touch){
620
+ dprintk(DEBUG_X_Y_INFO, "Touch Release!");
621
+ gtp_touch_up(ts, 0);
622
+ }
623
+
624
+ pre_touch = touch_num;
621625
622626 #endif
623627
624
- input_sync(ts->input_dev);
628
+ input_sync(ts->input_dev);
625629
626630 exit_work_func:
627
- if(!ts->gtp_rawdiff_mode) {
628
- ret = gtp_i2c_write(ts->client, end_cmd, 3);
629
- if (ret < 0) {
630
- printk("I2C write end_cmd error!");
631
- }
632
- }
633
- return ;
631
+ if(!ts->gtp_rawdiff_mode) {
632
+ ret = gtp_i2c_write(ts->client, end_cmd, 3);
633
+ if (ret < 0) {
634
+ printk("I2C write end_cmd error!");
635
+ }
636
+ }
637
+ return ;
634638 }
635639
636640 /*******************************************************
637641 Function:
638
- External interrupt service routine.
642
+External interrupt service routine.
639643
640644 Input:
641
- irq: interrupt number.
642
- dev_id: private data pointer.
643
-
645
+irq: interrupt number.
646
+dev_id: private data pointer.
647
+
644648 Output:
645
- irq execute status.
646
-*******************************************************/
649
+irq execute status.
650
+ *******************************************************/
647651
648652 irqreturn_t goodix_ts_irq_handler(int irq, void *dev_id)
649653 {
650
- struct goodix_ts_data *ts = (struct goodix_ts_data *)dev_id;
651
- dprintk(DEBUG_INT_INFO, "==========------TS Interrupt-----============\n");
654
+ struct goodix_ts_data *ts = (struct goodix_ts_data *)dev_id;
655
+ dprintk(DEBUG_INT_INFO, "==========------TS Interrupt-----============\n");
652656
653
- queue_work(goodix_wq, &ts->work);
654
- return 0;
657
+ queue_work(goodix_wq, &ts->work);
658
+ return 0;
655659 }
656660
657661
....@@ -659,509 +663,509 @@
659663
660664 /*******************************************************
661665 Function:
662
- Eter sleep function.
666
+Eter sleep function.
663667
664668 Input:
665
- ts:private data.
666
-
669
+ts:private data.
670
+
667671 Output:
668
- Executive outcomes.0--success,non-0--fail.
669
-*******************************************************/
672
+Executive outcomes.0--success,non-0--fail.
673
+ *******************************************************/
670674 #if defined(CONFIG_HAS_EARLYSUSPEND) | defined(CONFIG_PM)
671675 static s8 gtp_enter_sleep(struct goodix_ts_data * ts)
672676 {
673
- s8 ret = -1;
674
- s8 retry = 0;
675
- u8 i2c_control_buf[3] = {(u8)(GTP_REG_SLEEP >> 8), (u8)GTP_REG_SLEEP, 5};
676
-
677
- dprintk(DEBUG_SUSPEND, "%s start!\n", __func__);
678
-
679
- gtp_set_int_value(0);
677
+ s8 ret = -1;
678
+ s8 retry = 0;
679
+ u8 i2c_control_buf[3] = {(u8)(GTP_REG_SLEEP >> 8), (u8)GTP_REG_SLEEP, 5};
680680
681
- while(retry++ < 2) {
682
- ret = gtp_i2c_write(ts->client, i2c_control_buf, 3);
683
- if (ret > 0) {
684
- dprintk(DEBUG_SUSPEND, "GTP enter sleep!");
685
- return ret;
686
- }
687
- msleep(10);
688
- }
689
- dprintk(DEBUG_SUSPEND, "GTP send sleep cmd failed.");
690
-
691
- return ret;
681
+ dprintk(DEBUG_SUSPEND, "%s start!\n", __func__);
682
+
683
+ gtp_set_int_value(0);
684
+
685
+ while(retry++ < 2) {
686
+ ret = gtp_i2c_write(ts->client, i2c_control_buf, 3);
687
+ if (ret > 0) {
688
+ dprintk(DEBUG_SUSPEND, "GTP enter sleep!");
689
+ return ret;
690
+ }
691
+ msleep(10);
692
+ }
693
+ dprintk(DEBUG_SUSPEND, "GTP send sleep cmd failed.");
694
+
695
+ return ret;
692696 }
693697 #endif
694698
695699 /*******************************************************
696700 Function:
697
- Wakeup from sleep mode Function.
701
+Wakeup from sleep mode Function.
698702
699703 Input:
700
- ts: private data.
701
-
704
+ts: private data.
705
+
702706 Output:
703
- Executive outcomes.0--success,non-0--fail.
704
-*******************************************************/
707
+Executive outcomes.0--success,non-0--fail.
708
+ *******************************************************/
705709 static s8 gtp_wakeup_sleep(struct goodix_ts_data * ts)
706710 {
707
- u8 retry = 0;
708
- s8 ret = -1;
709
-
710
- gtp_io_init(20);
711
- gtp_set_io_int();
712
-
711
+ u8 retry = 0;
712
+ s8 ret = -1;
713
+
714
+ gtp_io_init(20);
715
+ gtp_set_io_int();
716
+
713717 #if GTP_POWER_CTRL_SLEEP
714
- while(retry++ < 5)
715
- {
716
- ret = gtp_send_cfg(ts->client);
717
- if (ret > 0)
718
- {
719
- dprintk(DEBUG_SUSPEND, "Wakeup sleep send config success.");
720
- return ret;
721
- }
722
- }
723
-
724
- printk("GTP wakeup sleep failed.");
725
- return ret;
726
-#endif
727
-
728
-}
729
-
730
-
731
-/*******************************************************
732
-Function:
733
- GTP initialize function.
734
-
735
-Input:
736
- ts: i2c client private struct.
737
-
738
-Output:
739
- Executive outcomes.0---succeed.
740
-*******************************************************/
741
-static s32 gtp_init_panel(struct goodix_ts_data *ts)
718
+ while(retry++ < 5)
742719 {
743
- s32 ret = -1;
744
-
745
-#if GTP_DRIVER_SEND_CFG
746
- s32 i;
747
- u8 check_sum = 0;
748
- u8 rd_cfg_buf[16];
749
- int index =0;
750
-
751
-#if 1
752
- u8 cfg_info_group1[] = CTP_CFG_GROUP1;
753
- u8 cfg_info_group2[] = CTP_CFG_GROUP2;
754
- u8 cfg_info_group3[] = CTP_CFG_GROUP3;
755
- u8 cfg_info_group4[] = CTP_CFG_GROUP4;
756
- u8 cfg_info_group5[] = CTP_CFG_GROUP5;
757
- u8 cfg_info_group6[] = CTP_CFG_GROUP6;
758
-// u8 cfg_info_group7[] = CTP_CFG_GROUP7;
759
-#else
760
- u8 cfg_info_group1[] = {};
761
- u8 cfg_info_group2[] = {};
762
- u8 cfg_info_group3[] = {};
763
- u8 cfg_info_group4[] = {};
764
- u8 cfg_info_group5[] = {};
765
- u8 cfg_info_group6[] = {};
766
-// u8 cfg_info_group7[] = {};
767
-#endif
768
-
769
- u8 *send_cfg_buf[] = {cfg_info_group1,cfg_info_group2,cfg_info_group3,cfg_info_group4,cfg_info_group5,cfg_info_group6};
770
- u8 cfg_info_len[] = {sizeof(cfg_info_group1)/sizeof(cfg_info_group1[0]),\
771
- sizeof(cfg_info_group2)/sizeof(cfg_info_group2[0]),\
772
- sizeof(cfg_info_group3)/sizeof(cfg_info_group3[0]),\
773
- sizeof(cfg_info_group4)/sizeof(cfg_info_group4[0]),\
774
- sizeof(cfg_info_group5)/sizeof(cfg_info_group5[0]),\
775
- sizeof(cfg_info_group6)/sizeof(cfg_info_group6[0])};
776
- //sizeof(cfg_info_group7)/sizeof(cfg_info_group7[0])};
777
-#if 0 //gandy
778
- for(i=0; i<3; i++)
779
- {
780
- if(cfg_info_len[i] > ts->gtp_cfg_len)
781
- {
782
- ts->gtp_cfg_len = cfg_info_len[i];
783
- }
784
- }
785
-#endif
786
-
787
- GTP_DEBUG("len1=%d,len2=%d,len3=%d,send_len:%d",cfg_info_len[0],cfg_info_len[1],cfg_info_len[2],ts->gtp_cfg_len);
788
-#if 0
789
- if ((!cfg_info_len[1]) && (!cfg_info_len[2]))
790
- {
791
- rd_cfg_buf[GTP_ADDR_LENGTH] = 0;
792
- }
793
- else
794
-#endif
795
- printk("gtp_i2c_read GTP_REG_SENSOR_ID \n");
796
- {
797
- rd_cfg_buf[0] = GTP_REG_SENSOR_ID >> 8;
798
- rd_cfg_buf[1] = GTP_REG_SENSOR_ID & 0xff;
799
- ret = gtp_i2c_read(ts->client, rd_cfg_buf, 3);
800
- if (ret < 0)
801
- {
802
- GTP_ERROR("Read SENSOR ID failed,default use group1 config!");
803
- rd_cfg_buf[GTP_ADDR_LENGTH] = 0;
804
- }
805
- rd_cfg_buf[GTP_ADDR_LENGTH] &= 0x07;
806
- }
807
-
808
-#if 0
809
- if(screen_max_x == 800 && screen_max_y == 480)
810
- {
811
- if(rd_cfg_buf[GTP_ADDR_LENGTH] == 3)
812
- index = 0;
813
- else if(rd_cfg_buf[GTP_ADDR_LENGTH] == 4)
814
- index = 1;
815
- else if(rd_cfg_buf[GTP_ADDR_LENGTH] == 5)
816
- index = 3;
817
- else if(rd_cfg_buf[GTP_ADDR_LENGTH] == 0)
818
- index = 6;
819
- }
820
- else if(screen_max_x == 1024 && screen_max_y == 600)
821
- {
822
- if(rd_cfg_buf[GTP_ADDR_LENGTH] == 0)
823
- index = 5;
824
- else if(rd_cfg_buf[GTP_ADDR_LENGTH] == 3)
825
- index = 2;
826
- }
827
-#endif
828
- GTP_DEBUG("CTP name : %s\n",config_info.name);
829
- if (!strcmp(config_info.name,"gt911_805d5")){
830
- index = 0;
831
- GTP_DEBUG("gt9xx:index = %d\n",index);
832
-
833
- } else if (!strcmp(config_info.name,"gt911_g912")){
834
- index = 2;
835
- GTP_DEBUG("gt9xx:index = %d\n",index);
836
-
837
- } else if (!strcmp(config_info.name,"gt911_xw785")){
838
- index = 3;
839
- GTP_DEBUG("gt9xx:index = %d\n",index);
840
-
841
- } else {//default gt9xx_ts
842
- index = 1; //default p4
843
- GTP_DEBUG("gt9xx:index = %d\n",index);
844
- }
845
-
846
- printk("config send_cfg_buf******** \n");
847
- //index = rd_cfg_buf[GTP_ADDR_LENGTH];
848
- ts->gtp_cfg_len = cfg_info_len[index];
849
- GTP_DEBUG("gandy---SENSOR ID:%d\n", rd_cfg_buf[GTP_ADDR_LENGTH]);
850
- memset(&config[GTP_ADDR_LENGTH], 0, GTP_CONFIG_MAX_LENGTH);
851
- memcpy(&config[GTP_ADDR_LENGTH], send_cfg_buf[index], ts->gtp_cfg_len);
852
-
853
-#if GTP_CUSTOM_CFG
854
- config[RESOLUTION_LOC] = (u8)GTP_MAX_WIDTH;
855
- config[RESOLUTION_LOC + 1] = (u8)(GTP_MAX_WIDTH>>8);
856
- config[RESOLUTION_LOC + 2] = (u8)GTP_MAX_HEIGHT;
857
- config[RESOLUTION_LOC + 3] = (u8)(GTP_MAX_HEIGHT>>8);
858
-
859
- if (GTP_INT_TRIGGER == 0) //RISING
860
- {
861
- config[TRIGGER_LOC] &= 0xfe;
862
- }
863
- else if (GTP_INT_TRIGGER == 1) //FALLING
864
- {
865
- config[TRIGGER_LOC] |= 0x01;
866
- }
867
-#endif //endif GTP_CUSTOM_CFG
868
-
869
- check_sum = 0;
870
- for (i = GTP_ADDR_LENGTH; i < ts->gtp_cfg_len; i++)
871
- {
872
- check_sum += config[i];
873
- }
874
- config[ts->gtp_cfg_len] = (~check_sum) + 1;
875
-
876
-#else //else DRIVER NEED NOT SEND CONFIG
877
-
878
- if(ts->gtp_cfg_len == 0)
879
- {
880
- ts->gtp_cfg_len = GTP_CONFIG_MAX_LENGTH;
881
- }
882
- ret = gtp_i2c_read(ts->client, config, ts->gtp_cfg_len + GTP_ADDR_LENGTH);
883
- if (ret < 0)
884
- {
885
- GTP_ERROR("GTP read resolution & max_touch_num failed, use default value!");
886
- ts->abs_x_max = GTP_MAX_WIDTH;
887
- ts->abs_y_max = GTP_MAX_HEIGHT;
888
- ts->int_trigger_type = GTP_INT_TRIGGER;
889
- }
890
-#endif //endif GTP_DRIVER_SEND_CFG
891
-
892
- GTP_DEBUG_FUNC();
893
-
894
- ts->abs_x_max = (config[RESOLUTION_LOC + 1] << 8) + config[RESOLUTION_LOC];
895
- ts->abs_y_max = (config[RESOLUTION_LOC + 3] << 8) + config[RESOLUTION_LOC + 2];
896
- ts->int_trigger_type = (config[TRIGGER_LOC]) & 0x03;
897
- if ((!ts->abs_x_max)||(!ts->abs_y_max))
898
- {
899
- GTP_ERROR("GTP resolution & max_touch_num invalid, use default value!");
900
- ts->abs_x_max = GTP_MAX_WIDTH;
901
- ts->abs_y_max = GTP_MAX_HEIGHT;
902
- }
903
-
904
- msleep(100);
905720 ret = gtp_send_cfg(ts->client);
906
- if (ret < 0)
721
+ if (ret > 0)
907722 {
908
- printk("\ngandy-----send config error.ret=%d\n",ret);
909
- GTP_ERROR("Send config error.");
723
+ dprintk(DEBUG_SUSPEND, "Wakeup sleep send config success.");
724
+ return ret;
910725 }
911
- printk("X_MAX = %d,Y_MAX = %d,TRIGGER = 0x%02x",
912
- ts->abs_x_max,ts->abs_y_max,ts->int_trigger_type);
913
-
914
- msleep(10);
915
-
916
- return 0;
917726 }
918727
728
+ printk("GTP wakeup sleep failed.");
729
+ return ret;
730
+#endif
731
+
732
+}
733
+
734
+
919735 /*******************************************************
920736 Function:
921
- Read goodix touchscreen version function.
737
+GTP initialize function.
922738
923739 Input:
924
- client: i2c client struct.
925
- version:address to store version info
926
-
740
+ts: i2c client private struct.
741
+
927742 Output:
928
- Executive outcomes.0---succeed.
929
-*******************************************************/
743
+Executive outcomes.0---succeed.
744
+ *******************************************************/
745
+static s32 gtp_init_panel(struct goodix_ts_data *ts)
746
+{
747
+ s32 ret = -1;
748
+
749
+#if GTP_DRIVER_SEND_CFG
750
+ s32 i;
751
+ u8 check_sum = 0;
752
+ u8 rd_cfg_buf[16];
753
+ int index =0;
754
+
755
+#if 1
756
+ u8 cfg_info_group1[] = CTP_CFG_GROUP1;
757
+ u8 cfg_info_group2[] = CTP_CFG_GROUP2;
758
+ u8 cfg_info_group3[] = CTP_CFG_GROUP3;
759
+ u8 cfg_info_group4[] = CTP_CFG_GROUP4;
760
+ u8 cfg_info_group5[] = CTP_CFG_GROUP5;
761
+ u8 cfg_info_group6[] = CTP_CFG_GROUP6;
762
+ // u8 cfg_info_group7[] = CTP_CFG_GROUP7;
763
+#else
764
+ u8 cfg_info_group1[] = {};
765
+ u8 cfg_info_group2[] = {};
766
+ u8 cfg_info_group3[] = {};
767
+ u8 cfg_info_group4[] = {};
768
+ u8 cfg_info_group5[] = {};
769
+ u8 cfg_info_group6[] = {};
770
+ // u8 cfg_info_group7[] = {};
771
+#endif
772
+
773
+ u8 *send_cfg_buf[] = {cfg_info_group1,cfg_info_group2,cfg_info_group3,cfg_info_group4,cfg_info_group5,cfg_info_group6};
774
+ u8 cfg_info_len[] = {sizeof(cfg_info_group1)/sizeof(cfg_info_group1[0]),\
775
+ sizeof(cfg_info_group2)/sizeof(cfg_info_group2[0]),\
776
+ sizeof(cfg_info_group3)/sizeof(cfg_info_group3[0]),\
777
+ sizeof(cfg_info_group4)/sizeof(cfg_info_group4[0]),\
778
+ sizeof(cfg_info_group5)/sizeof(cfg_info_group5[0]),\
779
+ sizeof(cfg_info_group6)/sizeof(cfg_info_group6[0])};
780
+ //sizeof(cfg_info_group7)/sizeof(cfg_info_group7[0])};
781
+#if 0 //gandy
782
+for(i=0; i<3; i++)
783
+{
784
+ if(cfg_info_len[i] > ts->gtp_cfg_len)
785
+ {
786
+ ts->gtp_cfg_len = cfg_info_len[i];
787
+ }
788
+}
789
+#endif
790
+
791
+GTP_DEBUG("len1=%d,len2=%d,len3=%d,send_len:%d",cfg_info_len[0],cfg_info_len[1],cfg_info_len[2],ts->gtp_cfg_len);
792
+#if 0
793
+if ((!cfg_info_len[1]) && (!cfg_info_len[2]))
794
+{
795
+ rd_cfg_buf[GTP_ADDR_LENGTH] = 0;
796
+}
797
+else
798
+#endif
799
+printk("gtp_i2c_read GTP_REG_SENSOR_ID \n");
800
+{
801
+ rd_cfg_buf[0] = GTP_REG_SENSOR_ID >> 8;
802
+ rd_cfg_buf[1] = GTP_REG_SENSOR_ID & 0xff;
803
+ ret = gtp_i2c_read(ts->client, rd_cfg_buf, 3);
804
+ if (ret < 0)
805
+ {
806
+ GTP_ERROR("Read SENSOR ID failed,default use group1 config!");
807
+ rd_cfg_buf[GTP_ADDR_LENGTH] = 0;
808
+ }
809
+ rd_cfg_buf[GTP_ADDR_LENGTH] &= 0x07;
810
+}
811
+
812
+#if 0
813
+if(screen_max_x == 800 && screen_max_y == 480)
814
+{
815
+ if(rd_cfg_buf[GTP_ADDR_LENGTH] == 3)
816
+ index = 0;
817
+ else if(rd_cfg_buf[GTP_ADDR_LENGTH] == 4)
818
+ index = 1;
819
+ else if(rd_cfg_buf[GTP_ADDR_LENGTH] == 5)
820
+ index = 3;
821
+ else if(rd_cfg_buf[GTP_ADDR_LENGTH] == 0)
822
+ index = 6;
823
+}
824
+else if(screen_max_x == 1024 && screen_max_y == 600)
825
+{
826
+ if(rd_cfg_buf[GTP_ADDR_LENGTH] == 0)
827
+ index = 5;
828
+ else if(rd_cfg_buf[GTP_ADDR_LENGTH] == 3)
829
+ index = 2;
830
+}
831
+#endif
832
+GTP_DEBUG("CTP name : %s\n",config_info.name);
833
+if (!strcmp(config_info.name,"gt911_805d5")){
834
+ index = 0;
835
+ GTP_DEBUG("gt9xx:index = %d\n",index);
836
+
837
+} else if (!strcmp(config_info.name,"gt911_g912")){
838
+ index = 2;
839
+ GTP_DEBUG("gt9xx:index = %d\n",index);
840
+
841
+} else if (!strcmp(config_info.name,"gt911_xw785")){
842
+ index = 3;
843
+ GTP_DEBUG("gt9xx:index = %d\n",index);
844
+
845
+} else {//default gt9xx_ts
846
+ index = 1; //default p4
847
+ GTP_DEBUG("gt9xx:index = %d\n",index);
848
+}
849
+
850
+printk("config send_cfg_buf******** \n");
851
+//index = rd_cfg_buf[GTP_ADDR_LENGTH];
852
+ts->gtp_cfg_len = cfg_info_len[index];
853
+GTP_DEBUG("gandy---SENSOR ID:%d\n", rd_cfg_buf[GTP_ADDR_LENGTH]);
854
+memset(&config[GTP_ADDR_LENGTH], 0, GTP_CONFIG_MAX_LENGTH);
855
+memcpy(&config[GTP_ADDR_LENGTH], send_cfg_buf[index], ts->gtp_cfg_len);
856
+
857
+#if GTP_CUSTOM_CFG
858
+config[RESOLUTION_LOC] = (u8)GTP_MAX_WIDTH;
859
+config[RESOLUTION_LOC + 1] = (u8)(GTP_MAX_WIDTH>>8);
860
+config[RESOLUTION_LOC + 2] = (u8)GTP_MAX_HEIGHT;
861
+config[RESOLUTION_LOC + 3] = (u8)(GTP_MAX_HEIGHT>>8);
862
+
863
+if (GTP_INT_TRIGGER == 0) //RISING
864
+{
865
+ config[TRIGGER_LOC] &= 0xfe;
866
+}
867
+else if (GTP_INT_TRIGGER == 1) //FALLING
868
+{
869
+ config[TRIGGER_LOC] |= 0x01;
870
+}
871
+#endif //endif GTP_CUSTOM_CFG
872
+
873
+check_sum = 0;
874
+for (i = GTP_ADDR_LENGTH; i < ts->gtp_cfg_len; i++)
875
+{
876
+ check_sum += config[i];
877
+}
878
+config[ts->gtp_cfg_len] = (~check_sum) + 1;
879
+
880
+#else //else DRIVER NEED NOT SEND CONFIG
881
+
882
+if(ts->gtp_cfg_len == 0)
883
+{
884
+ ts->gtp_cfg_len = GTP_CONFIG_MAX_LENGTH;
885
+}
886
+ret = gtp_i2c_read(ts->client, config, ts->gtp_cfg_len + GTP_ADDR_LENGTH);
887
+if (ret < 0)
888
+{
889
+ GTP_ERROR("GTP read resolution & max_touch_num failed, use default value!");
890
+ ts->abs_x_max = GTP_MAX_WIDTH;
891
+ ts->abs_y_max = GTP_MAX_HEIGHT;
892
+ ts->int_trigger_type = GTP_INT_TRIGGER;
893
+}
894
+#endif //endif GTP_DRIVER_SEND_CFG
895
+
896
+GTP_DEBUG_FUNC();
897
+
898
+ts->abs_x_max = (config[RESOLUTION_LOC + 1] << 8) + config[RESOLUTION_LOC];
899
+ts->abs_y_max = (config[RESOLUTION_LOC + 3] << 8) + config[RESOLUTION_LOC + 2];
900
+ts->int_trigger_type = (config[TRIGGER_LOC]) & 0x03;
901
+if ((!ts->abs_x_max)||(!ts->abs_y_max))
902
+{
903
+ GTP_ERROR("GTP resolution & max_touch_num invalid, use default value!");
904
+ ts->abs_x_max = GTP_MAX_WIDTH;
905
+ ts->abs_y_max = GTP_MAX_HEIGHT;
906
+}
907
+
908
+msleep(100);
909
+ret = gtp_send_cfg(ts->client);
910
+if (ret < 0)
911
+{
912
+ printk("\ngandy-----send config error.ret=%d\n",ret);
913
+ GTP_ERROR("Send config error.");
914
+}
915
+printk("X_MAX = %d,Y_MAX = %d,TRIGGER = 0x%02x",
916
+ ts->abs_x_max,ts->abs_y_max,ts->int_trigger_type);
917
+
918
+msleep(10);
919
+
920
+return 0;
921
+}
922
+
923
+/*******************************************************
924
+Function:
925
+Read goodix touchscreen version function.
926
+
927
+Input:
928
+client: i2c client struct.
929
+version:address to store version info
930
+
931
+Output:
932
+Executive outcomes.0---succeed.
933
+ *******************************************************/
930934 s32 gtp_read_version(struct i2c_client *client, u16* version)
931935 {
932
- s32 ret = -1;
933
- u8 buf[8] = {GTP_REG_VERSION >> 8, GTP_REG_VERSION & 0xff};
936
+ s32 ret = -1;
937
+ u8 buf[8] = {GTP_REG_VERSION >> 8, GTP_REG_VERSION & 0xff};
934938
935
- dprintk(DEBUG_INIT, "%s ---start!.---\n", __func__);
939
+ dprintk(DEBUG_INIT, "%s ---start!.---\n", __func__);
936940
937
- ret = gtp_i2c_read(client, buf, sizeof(buf));
938
- if (ret < 0) {
939
- printk("GTP read version failed");
940
- return ret;
941
- }
941
+ ret = gtp_i2c_read(client, buf, sizeof(buf));
942
+ if (ret < 0) {
943
+ printk("GTP read version failed");
944
+ return ret;
945
+ }
942946
943
- if (version) {
944
- *version = (buf[7] << 8) | buf[6];
945
- }
947
+ if (version) {
948
+ *version = (buf[7] << 8) | buf[6];
949
+ }
946950
947
- if (buf[5] == 0x00) {
948
- printk("IC Version: %c%c%c_%02x%02x", buf[2], buf[3], buf[4], buf[7], buf[6]);
949
- }
950
- else {
951
- printk("IC Version: %c%c%c%c_%02x%02x", buf[2], buf[3], buf[4], buf[5], buf[7], buf[6]);
952
- }
953
- return ret;
951
+ if (buf[5] == 0x00) {
952
+ printk("IC Version: %c%c%c_%02x%02x", buf[2], buf[3], buf[4], buf[7], buf[6]);
953
+ }
954
+ else {
955
+ printk("IC Version: %c%c%c%c_%02x%02x", buf[2], buf[3], buf[4], buf[5], buf[7], buf[6]);
956
+ }
957
+ return ret;
954958 }
955959
956960 /*******************************************************
957961 Function:
958
- I2c test Function.
962
+I2c test Function.
959963
960964 Input:
961
- client:i2c client.
962
-
965
+client:i2c client.
966
+
963967 Output:
964
- Executive outcomes.0--success,non-0--fail.
965
-*******************************************************/
968
+Executive outcomes.0--success,non-0--fail.
969
+ *******************************************************/
966970 static s8 gtp_i2c_test(struct i2c_client *client)
967971 {
968
- u8 test[3] = {GTP_REG_CONFIG_DATA >> 8, GTP_REG_CONFIG_DATA & 0xff};
969
- u8 retry = 0;
970
- s8 ret = -1;
971
-
972
- while(retry++ < 2) {
973
- ret = gtp_i2c_read(client, test, 3);
974
- if (ret > 0) {
975
- return ret;
976
- }
977
- printk("GTP i2c test failed time %d.",retry);
978
- msleep(10);
979
- }
980
- return ret;
972
+ u8 test[3] = {GTP_REG_CONFIG_DATA >> 8, GTP_REG_CONFIG_DATA & 0xff};
973
+ u8 retry = 0;
974
+ s8 ret = -1;
975
+
976
+ while(retry++ < 2) {
977
+ ret = gtp_i2c_read(client, test, 3);
978
+ if (ret > 0) {
979
+ return ret;
980
+ }
981
+ printk("GTP i2c test failed time %d.",retry);
982
+ msleep(10);
983
+ }
984
+ return ret;
981985 }
982986
983987
984988 /*******************************************************
985989 Function:
986
- Request input device Function.
990
+Request input device Function.
987991
988992 Input:
989
- ts:private data.
990
-
993
+ts:private data.
994
+
991995 Output:
992
- Executive outcomes.0--success,non-0--fail.
993
-*******************************************************/
996
+Executive outcomes.0--success,non-0--fail.
997
+ *******************************************************/
994998 static s8 gtp_request_input_dev(struct goodix_ts_data *ts)
995999 {
996
- s8 ret = -1;
1000
+ s8 ret = -1;
9971001 #if GTP_HAVE_TOUCH_KEY
998
- u8 index = 0;
1002
+ u8 index = 0;
9991003 #endif
1000
-
1001
- ts->input_dev = input_allocate_device();
1002
- if (ts->input_dev == NULL) {
1003
- GTP_ERROR("Failed to allocate input device.");
1004
- return -ENOMEM;
1005
- }
10061004
1007
- ts->input_dev->evbit[0] = BIT_MASK(EV_SYN) | BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS) ;
1005
+ ts->input_dev = input_allocate_device();
1006
+ if (ts->input_dev == NULL) {
1007
+ GTP_ERROR("Failed to allocate input device.");
1008
+ return -ENOMEM;
1009
+ }
1010
+
1011
+ ts->input_dev->evbit[0] = BIT_MASK(EV_SYN) | BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS) ;
10081012 #if GTP_ICS_SLOT_REPORT
1009
- __set_bit(INPUT_PROP_DIRECT, ts->input_dev->propbit);
1010
- input_mt_init_slots(ts->input_dev, 255);
1013
+ __set_bit(INPUT_PROP_DIRECT, ts->input_dev->propbit);
1014
+ input_mt_init_slots(ts->input_dev, 255, 1);
10111015 #else
1012
- ts->input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
1016
+ ts->input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
10131017 #endif
10141018
10151019 #if GTP_HAVE_TOUCH_KEY
1016
- for (index = 0; index < GTP_MAX_KEY_NUM; index++) {
1017
- input_set_capability(ts->input_dev,EV_KEY,touch_key_array[index]);
1018
- }
1020
+ for (index = 0; index < GTP_MAX_KEY_NUM; index++) {
1021
+ input_set_capability(ts->input_dev,EV_KEY,touch_key_array[index]);
1022
+ }
10191023 #endif
10201024
1021
-//#if GTP_CHANGE_X2Y
1022
-// GTP_SWAP(ts->abs_x_max, ts->abs_y_max);
1023
-//#endif
1025
+ //#if GTP_CHANGE_X2Y
1026
+ // GTP_SWAP(ts->abs_x_max, ts->abs_y_max);
1027
+ //#endif
10241028
10251029 set_bit(ABS_MT_POSITION_X, ts->input_dev->absbit);
10261030 set_bit(ABS_MT_POSITION_Y, ts->input_dev->absbit);
10271031 set_bit(ABS_MT_TOUCH_MAJOR, ts->input_dev->absbit);
10281032 set_bit(ABS_MT_WIDTH_MAJOR, ts->input_dev->absbit);
1029
-
1030
-
1031
-
1032
- input_set_abs_params(ts->input_dev, ABS_MT_POSITION_X, 0, SCREEN_MAX_X, 0, 0);
1033
- input_set_abs_params(ts->input_dev, ABS_MT_POSITION_Y, 0, SCREEN_MAX_Y, 0, 0);
1034
- input_set_abs_params(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0, 255, 0, 0);
1035
- input_set_abs_params(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
1036
- input_set_abs_params(ts->input_dev, ABS_MT_TRACKING_ID, 0, 255, 0, 0);
1033
+
1034
+
1035
+
1036
+ input_set_abs_params(ts->input_dev, ABS_MT_POSITION_X, 0, SCREEN_MAX_X, 0, 0);
1037
+ input_set_abs_params(ts->input_dev, ABS_MT_POSITION_Y, 0, SCREEN_MAX_Y, 0, 0);
1038
+ input_set_abs_params(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0, 255, 0, 0);
1039
+ input_set_abs_params(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
1040
+ input_set_abs_params(ts->input_dev, ABS_MT_TRACKING_ID, 0, 255, 0, 0);
10371041 __set_bit(INPUT_PROP_DIRECT, ts->input_dev->propbit);
1038
-
1039
- ts->input_dev->name = CTP_NAME;
1040
- ts->input_dev->phys = "input/goodix-ts";
1041
- ts->input_dev->id.bustype = BUS_I2C;
1042
- ts->input_dev->id.vendor = 0xDEAD;
1043
- ts->input_dev->id.product = 0xBEEF;
1044
- ts->input_dev->id.version = 10427;
1045
- ret = input_register_device(ts->input_dev);
1046
- if (ret) {
1047
- printk("Register %s input device failed", ts->input_dev->name);
1048
- return -ENODEV;
1049
- }
1042
+
1043
+ ts->input_dev->name = CTP_NAME;
1044
+ ts->input_dev->phys = "input/goodix-ts";
1045
+ ts->input_dev->id.bustype = BUS_I2C;
1046
+ ts->input_dev->id.vendor = 0xDEAD;
1047
+ ts->input_dev->id.product = 0xBEEF;
1048
+ ts->input_dev->id.version = 10427;
1049
+ ret = input_register_device(ts->input_dev);
1050
+ if (ret) {
1051
+ printk("Register %s input device failed", ts->input_dev->name);
1052
+ return -ENODEV;
1053
+ }
10501054 #ifdef CONFIG_HAS_EARLYSUSPEND
1051
- ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
1052
- ts->early_suspend.suspend = goodix_ts_early_suspend;
1053
- ts->early_suspend.resume = goodix_ts_late_resume;
1054
- register_early_suspend(&ts->early_suspend);
1055
+ ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
1056
+ ts->early_suspend.suspend = goodix_ts_early_suspend;
1057
+ ts->early_suspend.resume = goodix_ts_late_resume;
1058
+ register_early_suspend(&ts->early_suspend);
10551059 #endif
1056
- return 0;
1060
+ return 0;
10571061 }
10581062
10591063
10601064 /*******************************************************
10611065 Function:
1062
- Goodix touchscreen probe function.
1066
+Goodix touchscreen probe function.
10631067
10641068 Input:
1065
- client: i2c device struct.
1066
- id:device id.
1067
-
1069
+client: i2c device struct.
1070
+id:device id.
1071
+
10681072 Output:
1069
- Executive outcomes. 0---succeed.
1070
-*******************************************************/
1073
+Executive outcomes. 0---succeed.
1074
+ *******************************************************/
10711075 static int goodix_ts_probe(struct i2c_client *client, const struct i2c_device_id *id)
10721076 {
1073
- s32 ret = -1;
1074
- struct goodix_ts_data *ts;
1075
- u16 version_info;
1076
-
1077
- dprintk(DEBUG_INIT, "GTP Driver Version:%s\n",GTP_DRIVER_VERSION);
1078
- printk("GTP I2C Address:0x%02x\n", client->addr);
1077
+ s32 ret = -1;
1078
+ struct goodix_ts_data *ts;
1079
+ u16 version_info;
10791080
1080
- i2c_connect_client = client;
1081
- if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
1082
- printk("I2C check functionality failed.\n");
1083
- return -ENODEV;
1084
- }
1085
-
1086
- ts = kzalloc(sizeof(*ts), GFP_KERNEL);
1087
- if (ts == NULL) {
1088
- printk("Alloc GFP_KERNEL memory failed.\n");
1089
- return -ENOMEM;
1090
- }
1091
-
1092
- memset(ts, 0, sizeof(*ts));
1093
- INIT_WORK(&ts->work, goodix_ts_work_func);
1094
- ts->client = client;
1095
- i2c_set_clientdata(client, ts);
1096
- //ts->irq_lock = SPIN_LOCK_UNLOCKED;
1097
- ts->gtp_rawdiff_mode = 0;
1081
+ dprintk(DEBUG_INIT, "GTP Driver Version:%s\n",GTP_DRIVER_VERSION);
1082
+ printk("GTP I2C Address:0x%02x\n", client->addr);
1083
+
1084
+ i2c_connect_client = client;
1085
+ if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
1086
+ printk("I2C check functionality failed.\n");
1087
+ return -ENODEV;
1088
+ }
1089
+
1090
+ ts = kzalloc(sizeof(*ts), GFP_KERNEL);
1091
+ if (ts == NULL) {
1092
+ printk("Alloc GFP_KERNEL memory failed.\n");
1093
+ return -ENOMEM;
1094
+ }
1095
+
1096
+ memset(ts, 0, sizeof(*ts));
1097
+ INIT_WORK(&ts->work, goodix_ts_work_func);
1098
+ ts->client = client;
1099
+ i2c_set_clientdata(client, ts);
1100
+ //ts->irq_lock = SPIN_LOCK_UNLOCKED;
1101
+ ts->gtp_rawdiff_mode = 0;
10981102
10991103
1100
- ret = gtp_i2c_test(client);
1101
- if (ret < 0){
1102
- printk("I2C communication ERROR!\n");
1103
- goto exit_device_detect;
1104
- }
1104
+ ret = gtp_i2c_test(client);
1105
+ if (ret < 0){
1106
+ printk("I2C communication ERROR!\n");
1107
+ goto exit_device_detect;
1108
+ }
11051109
1106
- printk(KERN_ALERT "create_singlethread_workqueue goodix_resume.\n");
1107
- goodix_resume_wq = create_singlethread_workqueue("goodix_resume");
1108
- if (goodix_resume_wq == NULL) {
1109
- printk("create goodix_resume_wq fail!\n");
1110
- return -ENOMEM;
1111
- }
1110
+ printk(KERN_ALERT "create_singlethread_workqueue goodix_resume.\n");
1111
+ goodix_resume_wq = create_singlethread_workqueue("goodix_resume");
1112
+ if (goodix_resume_wq == NULL) {
1113
+ printk("create goodix_resume_wq fail!\n");
1114
+ return -ENOMEM;
1115
+ }
11121116
1113
- printk(KERN_ALERT "create_singlethread_workqueue goodix_wq.\n");
1117
+ printk(KERN_ALERT "create_singlethread_workqueue goodix_wq.\n");
11141118
1115
- goodix_wq = create_singlethread_workqueue("goodix_wq");
1116
- if (!goodix_wq) {
1117
- printk(KERN_ALERT "Creat goodix_wq workqueue failed.\n");
1118
- return -ENOMEM;
1119
- }
1119
+ goodix_wq = create_singlethread_workqueue("goodix_wq");
1120
+ if (!goodix_wq) {
1121
+ printk(KERN_ALERT "Creat goodix_wq workqueue failed.\n");
1122
+ return -ENOMEM;
1123
+ }
11201124
11211125 #if GTP_AUTO_UPDATE
1122
- //ret = gup_init_update_proc(ts);
1123
- // if (ret < 0) {
1124
- // printk("Create update thread error.");
1125
- // }
1126
+ //ret = gup_init_update_proc(ts);
1127
+ // if (ret < 0) {
1128
+ // printk("Create update thread error.");
1129
+ // }
11261130 #endif
1127
- ret = gtp_init_panel(ts);
1128
- if (ret < 0) {
1129
- printk("GTP init panel failed.\n");
1130
- }
1131
+ ret = gtp_init_panel(ts);
1132
+ if (ret < 0) {
1133
+ printk("GTP init panel failed.\n");
1134
+ }
11311135
1132
-
1133
- ret = gtp_request_input_dev(ts);
1134
- if (ret < 0) {
1135
- printk("GTP request input dev failed\n");
1136
+
1137
+ ret = gtp_request_input_dev(ts);
1138
+ if (ret < 0) {
1139
+ printk("GTP request input dev failed\n");
11361140 goto exit_device_detect;
1137
- }
1141
+ }
11381142
1139
- ret = gtp_read_version(client, &version_info);
1140
- if (ret < 0) {
1141
- printk("Read version failed.");
1142
- }
1143
-
1144
- config_info.dev = &(ts->input_dev->dev);
1143
+ ret = gtp_read_version(client, &version_info);
1144
+ if (ret < 0) {
1145
+ printk("Read version failed.");
1146
+ }
11451147
1146
- ret = input_request_int(&(config_info.input_type), goodix_ts_irq_handler,CTP_IRQ_MODE, ts);
1147
- if (ret) {
1148
- printk("Request irq fail!.\n");
1149
- }
1150
-
1151
-
1152
- spin_lock_init(&ts->irq_lock);
1148
+ config_info.dev = &(ts->input_dev->dev);
1149
+
1150
+ ret = input_request_int(&(config_info.input_type), goodix_ts_irq_handler,CTP_IRQ_MODE, ts);
1151
+ if (ret) {
1152
+ printk("Request irq fail!.\n");
1153
+ }
1154
+
1155
+
1156
+ spin_lock_init(&ts->irq_lock);
11531157
11541158 #if GTP_CREATE_WR_NODE
1155
- init_wr_node(client);
1159
+ init_wr_node(client);
11561160 #endif
11571161
11581162 #if GTP_ESD_PROTECT
1159
- INIT_DELAYED_WORK(&gtp_esd_check_work, gtp_esd_check_func);
1160
- gtp_esd_check_workqueue = create_workqueue("gtp_esd_check");
1161
- queue_delayed_work(gtp_esd_check_workqueue, &gtp_esd_check_work, GTP_ESD_CHECK_CIRCLE);
1163
+ INIT_DELAYED_WORK(&gtp_esd_check_work, gtp_esd_check_func);
1164
+ gtp_esd_check_workqueue = create_workqueue("gtp_esd_check");
1165
+ queue_delayed_work(gtp_esd_check_workqueue, &gtp_esd_check_work, GTP_ESD_CHECK_CIRCLE);
11621166 #endif
11631167 dprintk(DEBUG_INIT, "gt9xx probe success!\n");
1164
- return 0;
1168
+ return 0;
11651169 exit_device_detect:
11661170 i2c_set_clientdata(client, NULL);
11671171 kfree(ts);
....@@ -1171,115 +1175,115 @@
11711175
11721176 /*******************************************************
11731177 Function:
1174
- Goodix touchscreen driver release function.
1178
+Goodix touchscreen driver release function.
11751179
11761180 Input:
1177
- client: i2c device struct.
1178
-
1181
+client: i2c device struct.
1182
+
11791183 Output:
1180
- Executive outcomes. 0---succeed.
1181
-*******************************************************/
1184
+Executive outcomes. 0---succeed.
1185
+ *******************************************************/
11821186 static int goodix_ts_remove(struct i2c_client *client)
11831187 {
1184
- struct goodix_ts_data *ts = i2c_get_clientdata(client);
1185
-
1188
+ struct goodix_ts_data *ts = i2c_get_clientdata(client);
1189
+
11861190 dprintk(DEBUG_INIT,"%s start!\n", __func__);
11871191 #ifdef CONFIG_HAS_EARLYSUSPEND
1188
- unregister_early_suspend(&ts->early_suspend);
1192
+ unregister_early_suspend(&ts->early_suspend);
11891193 #endif
11901194
11911195 #if GTP_CREATE_WR_NODE
1192
- uninit_wr_node();
1196
+ uninit_wr_node();
11931197 #endif
11941198
11951199 #if GTP_ESD_PROTECT
1196
- flush_workqueue(gtp_esd_check_workqueue);
1197
- if(gtp_esd_check_workqueue)
1198
- destroy_workqueue(gtp_esd_check_workqueue);
1200
+ flush_workqueue(gtp_esd_check_workqueue);
1201
+ if(gtp_esd_check_workqueue)
1202
+ destroy_workqueue(gtp_esd_check_workqueue);
11991203 #endif
1200
- input_free_int(&(config_info.input_type), ts);
1204
+ input_free_int(&(config_info.input_type), ts);
12011205 flush_workqueue(goodix_wq);
12021206 //cancel_work_sync(&goodix_init_work);
1203
- cancel_work_sync(&goodix_resume_work);
1207
+ cancel_work_sync(&goodix_resume_work);
12041208 if(goodix_wq)
12051209 destroy_workqueue(goodix_wq);
1206
- //destroy_workqueue(goodix_init_wq);
1207
- if(goodix_resume_wq)
1208
- destroy_workqueue(goodix_resume_wq);
1209
- i2c_set_clientdata(ts->client, NULL);
1210
+ //destroy_workqueue(goodix_init_wq);
1211
+ if(goodix_resume_wq)
1212
+ destroy_workqueue(goodix_resume_wq);
1213
+ i2c_set_clientdata(ts->client, NULL);
12101214 input_unregister_device(ts->input_dev);
12111215 kfree(ts);
1212
-
1213
- return 0;
1216
+
1217
+ return 0;
12141218 }
12151219
12161220 static void goodix_resume_events (struct work_struct *work)
12171221 {
12181222 int ret;
1219
- struct goodix_ts_data *ts = i2c_get_clientdata(i2c_connect_client);
1220
-
1221
- ret = gtp_wakeup_sleep(ts);
1222
- if (ret < 0)
1223
- printk("resume power on failed\n");
1224
- gtp_irq_enable(ts);
1223
+ struct goodix_ts_data *ts = i2c_get_clientdata(i2c_connect_client);
1224
+
1225
+ ret = gtp_wakeup_sleep(ts);
1226
+ if (ret < 0)
1227
+ printk("resume power on failed\n");
1228
+ gtp_irq_enable(ts);
12251229 }
12261230
12271231 /*******************************************************
12281232 Function:
1229
- Early suspend function.
1233
+Early suspend function.
12301234
12311235 Input:
1232
- h:early_suspend struct.
1233
-
1236
+h:early_suspend struct.
1237
+
12341238 Output:
1235
- None.
1236
-*******************************************************/
1239
+None.
1240
+ *******************************************************/
12371241 #ifdef CONFIG_HAS_EARLYSUSPEND
12381242 static void goodix_ts_early_suspend(struct early_suspend *h)
12391243 {
1240
- struct goodix_ts_data *ts;
1241
- s8 ret = -1;
1242
- ts = container_of(h, struct goodix_ts_data, early_suspend);
1244
+ struct goodix_ts_data *ts;
1245
+ s8 ret = -1;
1246
+ ts = container_of(h, struct goodix_ts_data, early_suspend);
12431247
12441248 #if GTP_ESD_PROTECT
1245
- ts->gtp_is_suspend = 1;
1246
- cancel_delayed_work_sync(&gtp_esd_check_work);
1249
+ ts->gtp_is_suspend = 1;
1250
+ cancel_delayed_work_sync(&gtp_esd_check_work);
12471251 #endif
12481252
1249
- gtp_irq_disable(ts);
1250
-
1251
-
1252
- cancel_work_sync(&goodix_resume_work);
1253
- flush_workqueue(goodix_resume_wq);
1254
- ret = cancel_work_sync(&ts->work);
1255
- flush_workqueue(goodix_wq);
1256
-
1257
- ret = gtp_enter_sleep(ts);
1258
- if (ret < 0) {
1259
- printk("GTP early suspend failed.");
1260
- }
1253
+ gtp_irq_disable(ts);
1254
+
1255
+
1256
+ cancel_work_sync(&goodix_resume_work);
1257
+ flush_workqueue(goodix_resume_wq);
1258
+ ret = cancel_work_sync(&ts->work);
1259
+ flush_workqueue(goodix_wq);
1260
+
1261
+ ret = gtp_enter_sleep(ts);
1262
+ if (ret < 0) {
1263
+ printk("GTP early suspend failed.");
1264
+ }
12611265 }
12621266
12631267 /*******************************************************
12641268 Function:
1265
- Late resume function.
1269
+Late resume function.
12661270
12671271 Input:
1268
- h:early_suspend struct.
1269
-
1272
+h:early_suspend struct.
1273
+
12701274 Output:
1271
- None.
1272
-*******************************************************/
1275
+None.
1276
+ *******************************************************/
12731277 static void goodix_ts_late_resume(struct early_suspend *h)
12741278 {
1275
- struct goodix_ts_data *ts;
1276
- ts = container_of(h, struct goodix_ts_data, early_suspend);
1277
-
1278
- queue_work(goodix_resume_wq, &goodix_resume_work);//gandy
1279
+ struct goodix_ts_data *ts;
1280
+ ts = container_of(h, struct goodix_ts_data, early_suspend);
1281
+
1282
+ queue_work(goodix_resume_wq, &goodix_resume_work);//gandy
12791283
12801284 #if GTP_ESD_PROTECT
1281
- ts->gtp_is_suspend = 0;
1282
- queue_delayed_work(gtp_esd_check_workqueue, &gtp_esd_check_work, GTP_ESD_CHECK_CIRCLE);
1285
+ ts->gtp_is_suspend = 0;
1286
+ queue_delayed_work(gtp_esd_check_workqueue, &gtp_esd_check_work, GTP_ESD_CHECK_CIRCLE);
12831287 #endif
12841288 }
12851289 #else
....@@ -1296,10 +1300,10 @@
12961300 #endif
12971301
12981302 /*
1299
- ret = input_set_int_enable(&(config_info.input_type), 0);
1300
- if (ret < 0)
1301
- dprintk(DEBUG_SUSPEND,"%s irq disable failed\n", goodix_ts_name);
1302
- */
1303
+ ret = input_set_int_enable(&(config_info.input_type), 0);
1304
+ if (ret < 0)
1305
+ dprintk(DEBUG_SUSPEND,"%s irq disable failed\n", goodix_ts_name);
1306
+ */
13031307 gtp_irq_disable(ts);
13041308 cancel_work_sync(&goodix_resume_work);
13051309 flush_workqueue(goodix_resume_wq);
....@@ -1329,7 +1333,7 @@
13291333 #if GTP_ESD_PROTECT
13301334 struct goodix_ts_data *ts = dev_get_drvdata(dev);
13311335 ts->gtp_is_suspend = 0;
1332
- queue_delayed_work(gtp_esd_check_workqueue, &gtp_esd_check_work, GTP_ESD_CHECK_CIRCLE);
1336
+ queue_delayed_work(gtp_esd_check_workqueue, &gtp_esd_check_work, GTP_ESD_CHECK_CIRCLE);
13331337 #endif
13341338 return 0;
13351339 }
....@@ -1339,80 +1343,80 @@
13391343 #if GTP_ESD_PROTECT
13401344 /*******************************************************
13411345 Function:
1342
- Initialize external watchdog for esd protect
1346
+Initialize external watchdog for esd protect
13431347 Input:
1344
- client: i2c device.
1348
+client: i2c device.
13451349 Output:
1346
- result of i2c write operation.
1347
- 1: succeed, otherwise: failed
1348
-*********************************************************/
1350
+result of i2c write operation.
1351
+1: succeed, otherwise: failed
1352
+ *********************************************************/
13491353 s32 gtp_init_ext_watchdog(struct i2c_client *client)
13501354 {
1351
- u8 opr_buffer[4] = {0x80, 0x40, 0xAA, 0xAA};
1352
- dprintk(DEBUG_INIT, "Init external watchdog...");
1353
- return gtp_i2c_write(client, opr_buffer, 4);
1355
+ u8 opr_buffer[4] = {0x80, 0x40, 0xAA, 0xAA};
1356
+ dprintk(DEBUG_INIT, "Init external watchdog...");
1357
+ return gtp_i2c_write(client, opr_buffer, 4);
13541358 }
13551359 /*******************************************************
13561360 Function:
1357
- Esd protect function.
1358
- Added external watchdog by meta, 2013/03/07
1361
+Esd protect function.
1362
+Added external watchdog by meta, 2013/03/07
13591363 Input:
1360
- work: delayed work
1364
+work: delayed work
13611365 Output:
1362
- None.
1363
-*******************************************************/
1366
+None.
1367
+ *******************************************************/
13641368 static void gtp_esd_check_func(struct work_struct *work)
13651369 {
1366
- s32 i;
1367
- s32 ret = -1;
1368
- struct goodix_ts_data *ts = NULL;
1369
- u8 test[4] = {0x80, 0x40};
1370
-
1371
- dprintk(DEBUG_INIT, "enter %s work!\n", __func__);
1370
+ s32 i;
1371
+ s32 ret = -1;
1372
+ struct goodix_ts_data *ts = NULL;
1373
+ u8 test[4] = {0x80, 0x40};
13721374
1373
- ts = i2c_get_clientdata(i2c_connect_client);
1375
+ dprintk(DEBUG_INIT, "enter %s work!\n", __func__);
13741376
1375
- if (ts->gtp_is_suspend || ts->enter_update) {
1376
- return;
1377
- }
1378
-
1379
- for (i = 0; i < 3; i++) {
1380
- ret = gtp_i2c_read(ts->client, test, 4);
1381
-
1382
- dprintk(DEBUG_INIT, "0x8040 = 0x%02X, 0x8041 = 0x%02X", test[2], test[3]);
1383
- if ((ret < 0)) {
1384
- // IC works abnormally..
1385
- continue;
1386
- }else {
1387
- if ((test[2] == 0xAA) || (test[3] != 0xAA)) {
1388
- // IC works abnormally..
1389
- i = 3;
1390
- break;
1391
- }else {
1392
- // IC works normally, Write 0x8040 0xAA
1393
- test[2] = 0xAA;
1394
- gtp_i2c_write(ts->client, test, 3);
1395
- break;
1396
- }
1397
- }
1398
- }
1399
-
1400
- if (i >= 3) {
1401
- GTP_DEBUG("IC Working ABNORMALLY, Resetting Guitar...");
1402
- // gtp_reset_guitar(ts->client, 50);
1403
- }
1377
+ ts = i2c_get_clientdata(i2c_connect_client);
14041378
1405
- if(!ts->gtp_is_suspend) {
1406
- queue_delayed_work(gtp_esd_check_workqueue, &gtp_esd_check_work, GTP_ESD_CHECK_CIRCLE);
1407
- }
1379
+ if (ts->gtp_is_suspend || ts->enter_update) {
1380
+ return;
1381
+ }
14081382
1409
- return;
1383
+ for (i = 0; i < 3; i++) {
1384
+ ret = gtp_i2c_read(ts->client, test, 4);
1385
+
1386
+ dprintk(DEBUG_INIT, "0x8040 = 0x%02X, 0x8041 = 0x%02X", test[2], test[3]);
1387
+ if ((ret < 0)) {
1388
+ // IC works abnormally..
1389
+ continue;
1390
+ }else {
1391
+ if ((test[2] == 0xAA) || (test[3] != 0xAA)) {
1392
+ // IC works abnormally..
1393
+ i = 3;
1394
+ break;
1395
+ }else {
1396
+ // IC works normally, Write 0x8040 0xAA
1397
+ test[2] = 0xAA;
1398
+ gtp_i2c_write(ts->client, test, 3);
1399
+ break;
1400
+ }
1401
+ }
1402
+ }
1403
+
1404
+ if (i >= 3) {
1405
+ GTP_DEBUG("IC Working ABNORMALLY, Resetting Guitar...");
1406
+ // gtp_reset_guitar(ts->client, 50);
1407
+ }
1408
+
1409
+ if(!ts->gtp_is_suspend) {
1410
+ queue_delayed_work(gtp_esd_check_workqueue, &gtp_esd_check_work, GTP_ESD_CHECK_CIRCLE);
1411
+ }
1412
+
1413
+ return;
14101414 }
14111415 #endif
14121416
14131417 static const struct i2c_device_id goodix_ts_id[] = {
1414
- { CTP_NAME, 0 },
1415
- { }
1418
+ { CTP_NAME, 0 },
1419
+ { }
14161420 };
14171421
14181422 #ifndef CONFIG_HAS_EARLYSUSPEND
....@@ -1420,43 +1424,45 @@
14201424 static const struct dev_pm_ops gt9xx_pm_ops = {
14211425 .suspend = goodix_ts_suspend,
14221426 .resume = goodix_ts_resume,
1423
- };
1427
+};
14241428
14251429 #define GT9XX_PM_OPS (&gt9xx_pm_ops)
14261430 #endif
14271431 #endif
14281432
14291433 static struct i2c_driver goodix_ts_driver = {
1430
- .class = I2C_CLASS_HWMON,
1431
- .probe = goodix_ts_probe,
1432
- .remove = goodix_ts_remove,
1433
- .id_table = goodix_ts_id,
1434
- .driver = {
1435
- .name = CTP_NAME,
1436
- .owner = THIS_MODULE,
1434
+ .class = I2C_CLASS_HWMON,
1435
+ .probe = goodix_ts_probe,
1436
+ .remove = goodix_ts_remove,
1437
+ .id_table = goodix_ts_id,
1438
+ .driver = {
1439
+ .name = CTP_NAME,
1440
+ .owner = THIS_MODULE,
14371441 #ifndef CONFIG_HAS_EARLYSUSPEND
14381442 #ifdef CONFIG_PM
14391443 .pm = GT9XX_PM_OPS,
14401444 #endif
14411445 #endif
1442
- },
1443
- .address_list = normal_i2c,
1446
+ },
1447
+ .address_list = normal_i2c,
14441448 };
14451449
14461450 static int ctp_get_system_config(void)
14471451 {
1448
- ctp_print_info(config_info,DEBUG_INIT);
1449
- twi_id = config_info.twi_id;
1450
- screen_max_x = config_info.screen_max_x;
1451
- screen_max_y = config_info.screen_max_y;
1452
- revert_x_flag = config_info.revert_x_flag;
1453
- revert_y_flag = config_info.revert_y_flag;
1454
- exchange_x_y_flag = config_info.exchange_x_y_flag;
1455
- if((screen_max_x == 0) || (screen_max_y == 0)){
1456
- printk("%s:read config error!\n",__func__);
1457
- return 0;
1458
- }
1459
- return 1;
1452
+ ctp_print_info(config_info,DEBUG_INIT);
1453
+ twi_id = config_info.twi_id;
1454
+/*
1455
+ screen_max_x = config_info.screen_max_x;
1456
+ screen_max_y = config_info.screen_max_y;
1457
+ revert_x_flag = config_info.revert_x_flag;
1458
+ revert_y_flag = config_info.revert_y_flag;
1459
+ exchange_x_y_flag = config_info.exchange_x_y_flag;
1460
+*/
1461
+ if((screen_max_x == 0) || (screen_max_y == 0)){
1462
+ printk("%s:read config error!\n",__func__);
1463
+ return 0;
1464
+ }
1465
+ return 1;
14601466 }
14611467
14621468 /*******************************************************
....@@ -1469,76 +1475,82 @@
14691475 * ********************************************************/
14701476 static int __init goodix_ts_init(void)
14711477 {
1472
- s32 ret = -1;
1478
+ s32 ret = -1;
14731479 int val = 0;
1474
- struct device_node *np = NULL;
1480
+ struct device_node *np = NULL;
14751481
1476
- dprintk(DEBUG_INIT,"GTP driver init\n");
1482
+ dprintk(DEBUG_INIT,"GTP driver init\n");
14771483 if (!input_sensor_startup(&(config_info.input_type))) {
14781484 ret = input_sensor_init(&(config_info.input_type));
1479
- if (ret != 0) {
1480
- pr_err("%s:ctp_ops.input_sensor_init err.\n", __func__);
1481
- return ret;
1482
- }
1483
- input_set_power_enable(&(config_info.input_type), 1);
1485
+ if (ret != 0) {
1486
+ pr_err("%s:ctp_ops.input_sensor_init err.\n", __func__);
1487
+ return ret;
1488
+ }
1489
+ input_set_power_enable(&(config_info.input_type), 1);
14841490 } else {
14851491 pr_err("%s: input_ctp_startup err.\n", __func__);
14861492 return 0;
14871493 }
1488
- if(config_info.ctp_used == 0){
1489
- printk("*** ctp_used set to 0 !\n");
1490
- printk("*** if use ctp,please put the sys_config.fex ctp_used set to 1. \n");
1491
- return 0;
1494
+ if(config_info.ctp_used == 0){
1495
+ printk("*** ctp_used set to 0 !\n");
1496
+ printk("*** if use ctp,please put the sys_config.fex ctp_used set to 1. \n");
1497
+ return 0;
14921498 }
14931499
14941500 np = of_find_node_by_name(NULL, "ctp");
14951501 if (!np) {
1496
- pr_err("ERROR! get ctp node failed, func:%s, line:%d\n",__FUNCTION__, __LINE__);
1497
- return -1;
1498
- }
1502
+ pr_err("ERROR! get ctp node failed, func:%s, line:%d\n",__FUNCTION__, __LINE__);
1503
+ return -1;
1504
+ }
14991505
15001506 ret = of_property_read_u32(np, "ctp_gesture_wakeup", &val);
15011507 if (ret) {
1502
- pr_err("get ctp_screen_max_x is fail, %d\n", ret);
1503
- }
1504
- msleep(10);
1508
+ pr_err("get ctp_screen_max_x is fail, %d\n", ret);
1509
+ }
1510
+ msleep(10);
1511
+#if 0
1512
+ if(!ctp_get_system_config()){
1513
+ printk("%s:read config fail!\n",__func__);
1514
+ return ret;
1515
+ }
1516
+#else
1517
+ //ret = of_property_read_u32(np, "ctp_screen_max_x", &screen_max_x);
1518
+ //of_property_read_u32(np, "ctp_screen_max_y", &screen_max_y);
1519
+ //of_property_read_u32(np, "ctp_revert_x_flag", &revert_x_flag);
1520
+ //of_property_read_u32(np, "ctp_revert_y_flag", &revert_y_flag);
1521
+ //of_property_read_u32(np, "ctp_exchange_x_y_flag", &exchange_x_y_flag);
1522
+#endif
1523
+ sunxi_gpio_to_name(CTP_IRQ_NUMBER,irq_pin_name);
1524
+ gtp_io_init(20);
15051525
1506
- if(!ctp_get_system_config()){
1507
- printk("%s:read config fail!\n",__func__);
1508
- return ret;
1509
- }
1510
-
1511
- sunxi_gpio_to_name(CTP_IRQ_NUMBER,irq_pin_name);
1512
- gtp_io_init(20);
1513
-
1514
- goodix_wq = create_singlethread_workqueue("goodix_wq");
1515
- if (!goodix_wq)
1516
- {
1517
- GTP_ERROR("Creat workqueue failed.");
1518
- return -ENOMEM;
1519
- }
1526
+ goodix_wq = create_singlethread_workqueue("goodix_wq");
1527
+ if (!goodix_wq)
1528
+ {
1529
+ GTP_ERROR("Creat workqueue failed.");
1530
+ return -ENOMEM;
1531
+ }
15201532 #if GTP_ESD_PROTECT
1521
- INIT_DELAYED_WORK(&gtp_esd_check_work, gtp_esd_check_func);
1522
- gtp_esd_check_workqueue = create_workqueue("gtp_esd_check");
1533
+ INIT_DELAYED_WORK(&gtp_esd_check_work, gtp_esd_check_func);
1534
+ gtp_esd_check_workqueue = create_workqueue("gtp_esd_check");
15231535 #endif
15241536 goodix_ts_driver.detect = ctp_detect;
1525
- ret = i2c_add_driver(&goodix_ts_driver);
1526
- return ret;
1537
+ ret = i2c_add_driver(&goodix_ts_driver);
1538
+ return ret;
15271539 }
15281540
15291541
15301542 /*******************************************************
15311543 Function:
1532
- Driver uninstall function.
1544
+Driver uninstall function.
15331545 Input:
1534
- None.
1546
+None.
15351547 Output:
1536
- Executive Outcomes. 0---succeed.
1537
-********************************************************/
1548
+Executive Outcomes. 0---succeed.
1549
+ ********************************************************/
15381550 static void __exit goodix_ts_exit(void)
15391551 {
1540
- printk("GTP driver exited.\n");
1541
- i2c_del_driver(&goodix_ts_driver);
1552
+ printk("GTP driver exited.\n");
1553
+ i2c_del_driver(&goodix_ts_driver);
15421554 input_sensor_free(&(config_info.input_type));
15431555 }
15441556
longan/kernel/linux-4.9/drivers/input/touchscreen/gt9xxnew/gt9xx.c
....@@ -1,102 +1,50 @@
11 /* drivers/input/touchscreen/gt9xx.c
2
- *
3
- * 2010 - 2013 Goodix Technology.
4
- *
2
+ *
3
+ * 2010 - 2012 Goodix Technology.
4
+ *
55 * This program is free software; you can redistribute it and/or modify
66 * it under the terms of the GNU General Public License as published by
77 * the Free Software Foundation; either version 2 of the License, or
88 * (at your option) any later version.
9
- *
10
- * This program is distributed in the hope that it will be a reference
11
- * to you, when you are integrating the GOODiX's CTP IC into your system,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9
+ *
10
+ * This program is distributed in the hope that it will be a reference
11
+ * to you, when you are integrating the GOODiX's CTP IC into your system,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1414 * General Public License for more details.
15
- *
16
- * Version: 2.2
17
- * Authors: andrew@goodix.com, meta@goodix.com
18
- * Release Date: 2014/01/14
15
+ *
16
+ * Version:1.4
17
+ * Author:andrew@goodix.com
18
+ * Release Date:2012/12/12
1919 * Revision record:
20
- * V1.0:
21
- * first Release. By Andrew, 2012/08/31
22
- * V1.2:
23
- * modify gtp_reset_guitar,slot report,tracking_id & 0x0F. By Andrew, 2012/10/15
24
- * V1.4:
25
- * modify gt9xx_update.c. By Andrew, 2012/12/12
26
- * V1.6:
27
- * 1. new heartbeat/esd_protect mechanism(add external watchdog)
28
- * 2. doze mode, sliding wakeup
29
- * 3. 3 more cfg_group(GT9 Sensor_ID: 0~5)
30
- * 3. config length verification
31
- * 4. names & comments
32
- * By Meta, 2013/03/11
33
- * V1.8:
34
- * 1. pen/stylus identification
35
- * 2. read double check & fixed config support
36
- * 3. new esd & slide wakeup optimization
37
- * By Meta, 2013/06/08
38
- * V2.0:
39
- * 1. compatible with GT9XXF
40
- * 2. send config after resume
41
- * By Meta, 2013/08/06
42
- * V2.2:
43
- * 1. gt9xx_config for debug
44
- * 2. gesture wakeup
45
- * 3. pen separate input device, active-pen button support
46
- * 4. coordinates & keys optimization
47
- * By Meta, 2014/01/14
20
+ * V1.0:2012/08/31,first Release
21
+ * V1.2:2012/10/15,modify gtp_reset_guitar,slot report,tracking_id & 0x0F
22
+ * V1.4:2012/12/12,modify gt9xx_update.c
23
+ *
4824 */
4925
5026 #include <linux/irq.h>
51
-#include "gt9xx.h"
52
-#include <linux/pm_runtime.h>
53
-
54
-#ifdef CONFIG_PM
27
+#include "gt9xx_ts.h"
5528 #include <linux/pm.h>
56
-#endif
5729
5830 #if GTP_ICS_SLOT_REPORT
59
- #include <linux/input/mt.h>
31
+#include <linux/input/mt.h>
6032 #endif
6133
62
-// if use i2c detect, set 1
63
-#define USE_DETECT 0
64
-static int gUseDetect;
65
-static int startup(void);
66
-
67
-#define KEY_NUM 8
68
-static const char *goodix_ts_name = "goodix-ts";
34
+static const char *goodix_ts_name = "gt9xx";
6935 static struct workqueue_struct *goodix_wq;
70
-struct i2c_client *i2c_connect_client;
71
-u8 config[GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH]
72
- = {GTP_REG_CONFIG_DATA >> 8, GTP_REG_CONFIG_DATA & 0xff};
73
-unsigned int ctp_key_list[KEY_NUM] = {KEY_SWITCHVIDEOMODE, KEY_KBDILLUMTOGGLE, KEY_KBDILLUMDOWN, KEY_KBDILLUMUP, KEY_SEND, KEY_REPLY, KEY_FORWARDMAIL, KEY_SAVE};
36
+struct i2c_client * i2c_connect_client = NULL;
37
+static u8 config[GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH]
38
+= {GTP_REG_CONFIG_DATA >> 8, GTP_REG_CONFIG_DATA & 0xff};
7439
7540 #if GTP_HAVE_TOUCH_KEY
76
- static const u16 touch_key_array[] = GTP_KEY_TAB;
77
- #define GTP_MAX_KEY_NUM (sizeof(touch_key_array)/sizeof(touch_key_array[0]))
78
-
79
-#if GTP_DEBUG_ON
80
- static const int key_codes[] = {KEY_HOME, KEY_BACK, KEY_MENU, KEY_SEARCH};
81
- static const char *key_names[] = {"Key_Home", "Key_Back", "Key_Menu", "Key_Search"};
82
-#endif
83
-
41
+static const u16 touch_key_array[] = GTP_KEY_TAB;
42
+#define GTP_MAX_KEY_NUM (sizeof(touch_key_array)/sizeof(touch_key_array[0]))
8443 #endif
8544
8645 static s8 gtp_i2c_test(struct i2c_client *client);
8746 void gtp_reset_guitar(struct i2c_client *client, s32 ms);
88
-s32 gtp_send_cfg(struct i2c_client *client);
8947 void gtp_int_sync(s32 ms);
90
-
91
-static ssize_t gt91xx_config_read_proc(struct file *, char __user *, size_t, loff_t *);
92
-static ssize_t gt91xx_config_write_proc(struct file *, const char __user *, size_t, loff_t *);
93
-
94
-static struct proc_dir_entry *gt91xx_config_proc;
95
-static const struct file_operations config_proc_ops = {
96
- .owner = THIS_MODULE,
97
- .read = gt91xx_config_read_proc,
98
- .write = gt91xx_config_write_proc,
99
-};
10048
10149 #ifdef CONFIG_HAS_EARLYSUSPEND
10250 static void goodix_ts_early_suspend(struct early_suspend *h);
....@@ -104,7 +52,8 @@
10452 #endif
10553
10654 #if GTP_CREATE_WR_NODE
107
-extern s32 init_wr_node(struct i2c_client *);
55
+
56
+extern s32 init_wr_node(struct i2c_client*);
10857 extern void uninit_wr_node(void);
10958 #endif
11059
....@@ -114,63 +63,34 @@
11463
11564 #if GTP_ESD_PROTECT
11665 static struct delayed_work gtp_esd_check_work;
117
-static struct workqueue_struct *gtp_esd_check_workqueue;
66
+static struct workqueue_struct * gtp_esd_check_workqueue = NULL;
11867 static void gtp_esd_check_func(struct work_struct *);
119
-static s32 gtp_init_ext_watchdog(struct i2c_client *client);
120
-void gtp_esd_switch(struct i2c_client *, s32);
68
+s32 gtp_init_ext_watchdog(struct i2c_client *client);
12169 #endif
12270
123
-/*********** For GT9XXF Start **********/
124
-#if GTP_COMPATIBLE_MODE
125
-extern s32 i2c_read_bytes(struct i2c_client *client, u16 addr, u8 *buf, s32 len);
126
-extern s32 i2c_write_bytes(struct i2c_client *client, u16 addr, u8 *buf, s32 len);
127
-extern s32 gup_clk_calibration(void);
128
-extern s32 gup_fw_download_proc(void *dir, u8 dwn_mode);
129
-extern u8 gup_check_fs_mounted(char *path_name);
71
+///////////////////////////////////////////////
72
+//specific tp related macro: need be configured for specific tp
13073
131
-void gtp_recovery_reset(struct i2c_client *client);
132
-static s32 gtp_esd_recovery(struct i2c_client *client);
133
-s32 gtp_fw_startup(struct i2c_client *client);
134
-static s32 gtp_main_clk_proc(struct goodix_ts_data *ts);
135
-static s32 gtp_bak_ref_proc(struct goodix_ts_data *ts, u8 mode);
136
-
137
-#endif
138
-/********** For GT9XXF End **********/
139
-
140
-/*#if GTP_GESTURE_WAKEUP*/
141
-static bool gtp_gesture_wakeup;
142
-static bool gtp_power_ctrl_sleep;
143
-static bool g_suspend_flag;
144
-
145
-typedef enum {
146
- DOZE_DISABLED = 0,
147
- DOZE_ENABLED = 1,
148
- DOZE_WAKEUP = 2,
149
-} DOZE_T;
150
-static DOZE_T doze_status = DOZE_DISABLED;
151
-static s8 gtp_enter_doze(struct goodix_ts_data *ts);
152
-/*#endif*/
153
-
154
-u8 grp_cfg_version = 0;
155
-
156
-/********************Add by zhongjian for sunxi tp***********************/
15774 #define CTP_IRQ_NUMBER (config_info.int_number)
15875 #define CTP_IRQ_MODE (IRQF_TRIGGER_FALLING)
159
-#define CTP_NAME ("gt9xxnew_ts")
76
+#define CTP_NAME ("gt9xx_ts")
16077 #define SCREEN_MAX_X (screen_max_x)
16178 #define SCREEN_MAX_Y (screen_max_y)
16279 #define PRESS_MAX (255)
163
-static int screen_max_x;
164
-static int screen_max_y;
165
-static int revert_x_flag;
166
-static int revert_y_flag;
167
-static int exchange_x_y_flag;
168
-static __u32 twi_id;
80
+
81
+
82
+static int screen_max_x = 1024;
83
+static int screen_max_y = 600;
84
+static int revert_x_flag = 0;
85
+static int revert_y_flag = 0;
86
+static int exchange_x_y_flag = 0;
87
+static __u32 twi_id = 0;
16988 static char irq_pin_name[8];
170
-//static u32 debug_mask = 0x1;
171
-static u32 debug_mask;
172
-enum {
173
- DEBUG_INIT = 1U << 0,
89
+
90
+static u32 debug_mask = 0;
91
+
92
+enum{
93
+ DEBUG_INIT = 1U << 0,
17494 DEBUG_SUSPEND = 1U << 1,
17595 DEBUG_INT_INFO = 1U << 2,
17696 DEBUG_X_Y_INFO = 1U << 3,
....@@ -178,47 +98,58 @@
17898 DEBUG_WAKEUP_INFO = 1U << 5,
17999 DEBUG_OTHERS_INFO = 1U << 6,
180100 };
181
-#define dprintk(level_mask, fmt, arg...) if(unlikely(debug_mask & level_mask)) \
182
- printk("***CTP***"fmt, ## arg)
183
-module_param_named(debug_mask, debug_mask, int, S_IRUGO | S_IWUSR | S_IWGRP);
184
-static const unsigned short normal_i2c[3] = {0x14,0x5d, I2C_CLIENT_END};
101
+
102
+#define dprintk(level_mask,fmt,arg...) if(unlikely(debug_mask & level_mask)) \
103
+ printk("***CTP***"fmt, ## arg)
104
+module_param_named(debug_mask,debug_mask,int,S_IRUGO | S_IWUSR | S_IWGRP);
105
+
106
+static const unsigned short normal_i2c[3] = {0x14, 0x5d, I2C_CLIENT_END};
107
+//static const int chip_id_value[3] = {57};
108
+//static uint8_t read_chip_value[3] = {GTP_REG_VERSION >> 8, GTP_REG_VERSION & 0xff,0};
185109 struct ctp_config_info config_info = {
186110 .input_type = CTP_TYPE,
187111 .name = NULL,
188112 .int_number = 0,
189113 };
190114
115
+//static void goodix_init_events(struct work_struct *work);
116
+static void goodix_resume_events(struct work_struct *work);
117
+static struct workqueue_struct *goodix_wq;
118
+//static struct workqueue_struct *goodix_init_wq;
119
+static struct workqueue_struct *goodix_resume_wq;
120
+//static DECLARE_WORK(goodix_init_work, goodix_init_events);
121
+static DECLARE_WORK(goodix_resume_work, goodix_resume_events);
122
+
191123 /**
192124 * ctp_detect - Device detection callback for automatic device creation
193
- * return value:
125
+ * return value:
194126 * = 0; success;
195127 * < 0; err
196128 */
197129 static int ctp_detect(struct i2c_client *client, struct i2c_board_info *info)
198130 {
199131 struct i2c_adapter *adapter = client->adapter;
200
- int ret = -1;
201
- printk("the adapter number is %d\n", adapter->nr);
132
+ int ret = -1;
202133
203
- if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
134
+ if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)){
204135 printk("======return=====\n");
205136 return -ENODEV;
206
- }
137
+ }
207138
208
- if(twi_id == adapter->nr) {
209
- printk("%s: addr = %x\n", __func__, client->addr);
210
- ret = gtp_i2c_test(client);
139
+ if(twi_id == adapter->nr){
140
+ dprintk(DEBUG_INIT,"%s: addr = %x\n", __func__, client->addr);
141
+ ret = gtp_i2c_test(client);
211142 printk("detect ret %d\n",ret);
212
- if(!ret) {
213
- printk("%s:I2C connection might be something wrong \n", __func__);
214
- return -ENODEV;
215
- } else {
143
+ if(!ret){
144
+ printk("%s:I2C connection might be something wrong \n", __func__);
145
+ return -ENODEV;
146
+ }else{
216147 strlcpy(info->type, CTP_NAME, I2C_NAME_SIZE);
217148 printk("======detect ok !=====\n");
218
- return 0;
219
- }
220
- } else {
221
- return -ENODEV;
149
+ return 0;
150
+ }
151
+ }else{
152
+ return -ENODEV;
222153 }
223154 }
224155
....@@ -229,7 +160,8 @@
229160 */
230161 void ctp_print_info(struct ctp_config_info info,int debug_level)
231162 {
232
- if(debug_level == DEBUG_INIT) {
163
+ if(debug_level == DEBUG_INIT)
164
+ {
233165 dprintk(DEBUG_INIT,"info.ctp_used:%d\n",info.ctp_used);
234166 dprintk(DEBUG_INIT,"info.twi_id:%d\n",info.twi_id);
235167 dprintk(DEBUG_INIT,"info.screen_max_x:%d\n",info.screen_max_x);
....@@ -276,3237 +208,1354 @@
276208
277209 void gtp_set_int_value(int status)
278210 {
279
- long unsigned int config;
211
+ long unsigned int config;
280212
281
- config = SUNXI_PINCFG_PACK(SUNXI_PINCFG_TYPE_FUNC,0xFFFF);
282
- pin_config_get(SUNXI_PINCTRL,irq_pin_name,&config);
213
+ config = SUNXI_PINCFG_PACK(SUNXI_PINCFG_TYPE_FUNC,0xFFFF);
214
+ pin_config_get(SUNXI_PINCTRL,irq_pin_name,&config);
283215
284
- if (1 != SUNXI_PINCFG_UNPACK_VALUE(config)) {
285
- config = SUNXI_PINCFG_PACK(SUNXI_PINCFG_TYPE_FUNC,1);
286
- pin_config_set(SUNXI_PINCTRL,irq_pin_name,config);;
287
- }
216
+ if (1 != SUNXI_PINCFG_UNPACK_VALUE(config)){
217
+ config = SUNXI_PINCFG_PACK(SUNXI_PINCFG_TYPE_FUNC,1);
218
+ pin_config_set(SUNXI_PINCTRL,irq_pin_name,config);;
219
+ }
288220
289
- __gpio_set_value(CTP_IRQ_NUMBER, status);
221
+ __gpio_set_value(CTP_IRQ_NUMBER, status);
290222 }
291223
292224 void gtp_set_io_int(void)
293225 {
294
- long unsigned int config;
295
- config = SUNXI_PINCFG_PACK(SUNXI_PINCFG_TYPE_FUNC,0xFFFF);
296
- pin_config_get(SUNXI_PINCTRL,irq_pin_name,&config);
226
+ long unsigned int config;
227
+ config = SUNXI_PINCFG_PACK(SUNXI_PINCFG_TYPE_FUNC,0xFFFF);
228
+ pin_config_get(SUNXI_PINCTRL,irq_pin_name,&config);
297229
298
- if (6 != SUNXI_PINCFG_UNPACK_VALUE(config)) {
299
- config = SUNXI_PINCFG_PACK(SUNXI_PINCFG_TYPE_FUNC,6);
300
- pin_config_set(SUNXI_PINCTRL,irq_pin_name,config);
301
- }
230
+ if (6 != SUNXI_PINCFG_UNPACK_VALUE(config)) {
231
+ config = SUNXI_PINCFG_PACK(SUNXI_PINCFG_TYPE_FUNC, 6);
232
+ pin_config_set(SUNXI_PINCTRL, irq_pin_name, config);
233
+ }
302234
303235 }
304236
305237 void gtp_io_init(int ms)
306
-{
238
+{
307239 ctp_wakeup(0, 0);
308240 msleep(ms);
241
+
309242 gtp_set_int_value(0);
310243 msleep(2);
311244
312245 ctp_wakeup(1, 0);
313246 msleep(6);
314
- gpio_direction_output(config_info.wakeup_gpio.gpio,1);
315
- gtp_int_sync(50);
247
+
248
+
249
+#if GTP_ESD_PROTECT
250
+ // gtp_init_ext_watchdog(client);
251
+#endif
252
+
316253 }
317254
318
-/*******************************************************************************/
319
-static ssize_t gtp_gesture_enable_store(struct device *dev,struct device_attribute *attr,const char *buf, size_t count)
320
-{
321
- unsigned long data;
322
- /*struct input_dev *input = dev_get_drvdata(dev);*/
323
- /*struct goodix_ts_data *ts = container_of(&input, struct goodix_ts_data, input_dev);*/
324
- data = simple_strtoul(buf, NULL, 10);
325
- dprintk(DEBUG_INIT,"%s g_suspend_flag=%d,gtp_gesture_wakeup=%d,enable=%ld\n",__func__,g_suspend_flag,gtp_gesture_wakeup,data);
326
- if (!g_suspend_flag) {
327
- if(data) {
328
- gtp_gesture_wakeup = 1;
329
- gtp_power_ctrl_sleep = 0;
330
- dprintk(DEBUG_INIT,"%s gtp_gesture_wakeup=%d,enable=%ld\n", __func__, gtp_gesture_wakeup,data);
331
- } else {
332
- gtp_gesture_wakeup = 0;
333
- gtp_power_ctrl_sleep = 1;
334
- dprintk(DEBUG_INIT,"%s gtp_gesture_wakeup=%d,enable=%ld\n", __func__, gtp_gesture_wakeup,data);
335
- }
336
- }
337
- else
338
- dprintk(DEBUG_INIT,"%s gtp is suspend!!!! gtp_gesture_wakeup cann't be set!! gtp_gesture_wakeup=%d,enable=%ld\n", __func__, gtp_gesture_wakeup, data);
339
- return count;
340
-}
341
-static ssize_t gtp_gesture_enable_show(struct device *dev,
342
- struct device_attribute *attr, char *buf)
343
-{
344
- int enable;
345
- if(gtp_gesture_wakeup)
346
- enable = 1;
347
- else
348
- enable = 0;
349
- return sprintf(buf, "%d\n", enable);
350
-}
351
-static DEVICE_ATTR(enable, S_IRUGO|S_IWUSR|S_IWGRP,
352
- gtp_gesture_enable_show, gtp_gesture_enable_store);
353
-static struct attribute *gtp_attributes[] = {
354
- &dev_attr_enable.attr,
355
- NULL
356
-};
357
-static struct attribute_group gtp_attribute_group = {
358
- .attrs = gtp_attributes
359
-};
360
-
361
-/*******************************************************
255
+/*******************************************************
362256 Function:
363
- Read data from the i2c slave device.
257
+Read data from the i2c slave device.
258
+
364259 Input:
365
- client: i2c device.
366
- buf[0~1]: read start address.
367
- buf[2~len-1]: read data buffer.
368
- len: GTP_ADDR_LENGTH + read bytes count
260
+client: i2c device.
261
+buf[0]:operate address.
262
+buf[1]~buf[len]:read data buffer.
263
+len:operate length.
264
+
369265 Output:
370
- numbers of i2c_msgs to transfer:
371
- 2: succeed, otherwise: failed
372
-*********************************************************/
266
+numbers of i2c_msgs to transfer
267
+ *********************************************************/
373268 s32 gtp_i2c_read(struct i2c_client *client, u8 *buf, s32 len)
374269 {
375
- struct i2c_msg msgs[2];
376
- s32 ret=-1;
377
- s32 retries = 0;
270
+ struct i2c_msg msgs[2];
271
+ s32 ret = -1;
272
+ s32 retries = 0;
378273
379
- GTP_DEBUG_FUNC();
274
+ msgs[0].flags = !I2C_M_RD;
275
+ msgs[0].addr = client->addr;
276
+ msgs[0].len = GTP_ADDR_LENGTH;
277
+ msgs[0].buf = &buf[0];
380278
381
- msgs[0].flags = !I2C_M_RD;
382
- msgs[0].addr = client->addr;
383
- msgs[0].len = GTP_ADDR_LENGTH;
384
- msgs[0].buf = &buf[0];
385
- /*msgs[0].scl_rate = 300 * 1000;*/ /* for Rockchip, etc.*/
279
+ msgs[1].flags = I2C_M_RD;
280
+ msgs[1].addr = client->addr;
281
+ msgs[1].len = len - GTP_ADDR_LENGTH;
282
+ msgs[1].buf = &buf[GTP_ADDR_LENGTH];
386283
387
- msgs[1].flags = I2C_M_RD;
388
- msgs[1].addr = client->addr;
389
- msgs[1].len = len - GTP_ADDR_LENGTH;
390
- msgs[1].buf = &buf[GTP_ADDR_LENGTH];
391
- /*msgs[1].scl_rate = 300 * 1000;*/
284
+ while(retries < 2) {
285
+ ret = i2c_transfer(client->adapter, msgs, 2);
286
+ if(ret == 2)
287
+ break;
288
+ retries++;
289
+ }
392290
393
- while(retries < 5)
394
- {
395
- ret = i2c_transfer(client->adapter, msgs, 2);
396
- if(ret == 2)break;
397
- retries++;
398
- }
399
- if((retries >= 5))
400
- {
401
- #if GTP_COMPATIBLE_MODE
402
- struct goodix_ts_data *ts = i2c_get_clientdata(client);
403
- #endif
404
-
405
- /*#if GTP_GESTURE_WAKEUP*/
406
- if(gtp_gesture_wakeup){
407
- /* reset chip would quit doze mode*/
408
- if (DOZE_ENABLED == doze_status)
409
- {
410
- return ret;
411
- }
412
- }
413
- /* #endif*/
414
- GTP_ERROR("I2C Read: 0x%04X, %d bytes failed, errcode: %d! Process reset.", (((u16)(buf[0] << 8)) | buf[1]), len-2, ret);
415
- #if GTP_COMPATIBLE_MODE
416
- if (CHIP_TYPE_GT9F == ts->chip_type)
417
- {
418
- gtp_recovery_reset(client);
419
- }
420
- else
421
- #endif
422
- {
423
- gtp_reset_guitar(client, 10);
424
- }
425
- }
426
- return ret;
291
+ if(retries >= 2) {
292
+ printk("%s:I2C retry timeout, reset chip.", __func__);
293
+ }
294
+ return ret;
427295 }
428296
429
-
430
-
431
-/*******************************************************
297
+/*******************************************************
432298 Function:
433
- Write data to the i2c slave device.
299
+write data to the i2c slave device.
300
+
434301 Input:
435
- client: i2c device.
436
- buf[0~1]: write start address.
437
- buf[2~len-1]: data buffer
438
- len: GTP_ADDR_LENGTH + write bytes count
302
+client: i2c device.
303
+buf[0]:operate address.
304
+buf[1]~buf[len]:write data buffer.
305
+len:operate length.
306
+
439307 Output:
440
- numbers of i2c_msgs to transfer:
441
- 1: succeed, otherwise: failed
442
-*********************************************************/
443
-s32 gtp_i2c_write(struct i2c_client *client, u8 *buf, s32 len)
308
+numbers of i2c_msgs to transfer.
309
+ *********************************************************/
310
+s32 gtp_i2c_write(struct i2c_client *client,u8 *buf,s32 len)
444311 {
445
- struct i2c_msg msg;
446
- s32 ret = -1;
447
- s32 retries = 0;
312
+ struct i2c_msg msg;
313
+ s32 ret = -1;
314
+ s32 retries = 0;
448315
449
- GTP_DEBUG_FUNC();
316
+ msg.flags = !I2C_M_RD;
317
+ msg.addr = client->addr;
318
+ msg.len = len;
319
+ msg.buf = buf;
450320
451
- msg.flags = !I2C_M_RD;
452
- msg.addr = client->addr;
453
- msg.len = len;
454
- msg.buf = buf;
455
- /*msg.scl_rate = 300 * 1000;*/ /* for Rockchip, etc*/
321
+ while(retries < 2) {
322
+ ret = i2c_transfer(client->adapter, &msg, 1);
323
+ if (ret == 1)
324
+ break;
325
+ retries++;
326
+ }
456327
457
- while(retries < 5)
458
- {
459
- ret = i2c_transfer(client->adapter, &msg, 1);
460
- if (ret == 1)break;
461
- retries++;
462
- }
463
- if((retries >= 5)) {
464
- #if GTP_COMPATIBLE_MODE
465
- struct goodix_ts_data *ts = i2c_get_clientdata(client);
466
- #endif
467
-
468
- /*#if GTP_GESTURE_WAKEUP*/
469
- if(gtp_gesture_wakeup){
470
- if (DOZE_ENABLED == doze_status)
471
- {
472
- return ret;
473
- }
474
- }
475
- /*#endif*/
476
- GTP_ERROR("I2C Write: 0x%04X, %d bytes failed, errcode: %d! Process reset.", (((u16)(buf[0] << 8)) | buf[1]), len-2, ret);
477
- #if GTP_COMPATIBLE_MODE
478
- if (CHIP_TYPE_GT9F == ts->chip_type)
479
- {
480
- gtp_recovery_reset(client);
481
- }
482
- else
483
- #endif
484
- {
485
- gtp_reset_guitar(client, 10);
486
- }
487
- }
488
- return ret;
489
-}
490
-
491
-
492
-/*******************************************************
493
-Function:
494
- i2c read twice, compare the results
495
-Input:
496
- client: i2c device
497
- addr: operate address
498
- rxbuf: read data to store, if compare successful
499
- len: bytes to read
500
-Output:
501
- FAIL: read failed
502
- SUCCESS: read successful
503
-*********************************************************/
504
-s32 gtp_i2c_read_dbl_check(struct i2c_client *client, u16 addr, u8 *rxbuf, int len)
505
-{
506
- u8 buf[16] = {0};
507
- u8 confirm_buf[16] = {0};
508
- u8 retry = 0;
509
-
510
- while (retry++ < 3)
511
- {
512
- memset(buf, 0xAA, 16);
513
- buf[0] = (u8)(addr >> 8);
514
- buf[1] = (u8)(addr & 0xFF);
515
- gtp_i2c_read(client, buf, len + 2);
516
-
517
- memset(confirm_buf, 0xAB, 16);
518
- confirm_buf[0] = (u8)(addr >> 8);
519
- confirm_buf[1] = (u8)(addr & 0xFF);
520
- gtp_i2c_read(client, confirm_buf, len + 2);
521
-
522
- if (!memcmp(buf, confirm_buf, len+2))
523
- {
524
- memcpy(rxbuf, confirm_buf+2, len);
525
- return SUCCESS;
526
- }
527
- }
528
- GTP_ERROR("I2C read 0x%04X, %d bytes, double check failed!", addr, len);
529
- return FAIL;
328
+ if(retries >= 2) {
329
+ printk("%s:I2C retry timeout, reset chip.", __func__);
330
+ }
331
+ return ret;
530332 }
531333
532334 /*******************************************************
533335 Function:
534
- Send config.
535
-Input:
536
- client: i2c device.
537
-Output:
538
- result of i2c write operation.
539
- 1: succeed, otherwise: failed
540
-*********************************************************/
336
+Send config Function.
541337
338
+Input:
339
+client: i2c client.
340
+
341
+Output:
342
+Executive outcomes.0--success,non-0--fail.
343
+ *******************************************************/
542344 s32 gtp_send_cfg(struct i2c_client *client)
543345 {
544
- s32 ret = 2;
346
+ s32 ret = 0;
545347
546348 #if GTP_DRIVER_SEND_CFG
547
- s32 retry = 0;
548
- struct goodix_ts_data *ts = i2c_get_clientdata(client);
349
+ s32 retry = 0;
549350
550
- if (ts->fixed_cfg)
551
- {
552
- GTP_INFO("Ic fixed config, no config sent!");
553
- return 0;
554
- }
555
- else if (ts->pnl_init_error)
556
- {
557
- GTP_INFO("Error occured in init_panel, no config sent");
558
- return 0;
559
- }
560
-
561
- GTP_INFO("Driver send config.");
562
- for (retry = 0; retry < 5; retry++)
563
- {
564
- ret = gtp_i2c_write(client, config , GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH);
565
- if (ret > 0)
566
- {
567
- break;
568
- }
569
- }
351
+ for (retry = 0; retry < 5; retry++)
352
+ {
353
+ //ret = gtp_i2c_write(client, config , GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH);
354
+ // if (ret > 0)
355
+ // {
356
+ // break;
357
+ // }
358
+ }
570359 #endif
571
- return ret;
360
+
361
+ return ret;
572362 }
363
+
573364 /*******************************************************
574365 Function:
575
- Disable irq function
366
+Disable IRQ Function.
367
+
576368 Input:
577
- ts: goodix i2c_client private data
369
+ts: i2c client private struct.
370
+
578371 Output:
579
- None.
580
-*********************************************************/
372
+None.
373
+ *******************************************************/
581374 void gtp_irq_disable(struct goodix_ts_data *ts)
582375 {
583
- unsigned long irqflags;
376
+ unsigned long irqflags;
584377 int ret;
585378
586
- GTP_DEBUG_FUNC();
587
-
588
- dprintk(DEBUG_INT_INFO, "%s ---start!---\n", __func__);
589
- spin_lock_irqsave(&ts->irq_lock, irqflags);
590
- if (!ts->irq_is_disable) {
591
- ts->irq_is_disable = 1;
592
- ret = input_set_int_enable(&(config_info.input_type), 0);
593
- if (ret < 0)
594
- dprintk(DEBUG_OTHERS_INFO,"%s irq disable failed\n", goodix_ts_name);
595
- }
596
- spin_unlock_irqrestore(&ts->irq_lock, irqflags);
379
+ dprintk(DEBUG_INT_INFO, "%s ---start!---\n", __func__);
380
+ spin_lock_irqsave(&ts->irq_lock, irqflags);
381
+ if (!ts->irq_is_disable) {
382
+ ts->irq_is_disable = 1;
383
+ ret = input_set_int_enable(&(config_info.input_type), 0);
384
+ if (ret < 0)
385
+ dprintk(DEBUG_OTHERS_INFO,"%s irq disable failed\n", goodix_ts_name);
386
+ }
387
+ spin_unlock_irqrestore(&ts->irq_lock, irqflags);
597388 }
598389
599390 /*******************************************************
600391 Function:
601
- Enable irq function
392
+Disable IRQ Function.
393
+
602394 Input:
603
- ts: goodix i2c_client private data
395
+ts: i2c client private struct.
396
+
604397 Output:
605
- None.
606
-*********************************************************/
398
+None.
399
+ *******************************************************/
607400 void gtp_irq_enable(struct goodix_ts_data *ts)
608401 {
609
- unsigned long irqflags = 0;
610
- int ret;
402
+ unsigned long irqflags = 0;
403
+ int ret;
611404
612
- GTP_DEBUG_FUNC();
405
+ dprintk(DEBUG_INT_INFO, "%s ---start!---\n", __func__);
613406
614
- spin_lock_irqsave(&ts->irq_lock, irqflags);
615
- if (ts->irq_is_disable) {
616
- ts->irq_is_disable = 0;
617
- ret = input_set_int_enable(&(config_info.input_type), 1);
618
- if (ret < 0)
619
- dprintk(DEBUG_OTHERS_INFO,"%s irq enable failed\n", goodix_ts_name);
620
- }
621
- spin_unlock_irqrestore(&ts->irq_lock, irqflags);
407
+ spin_lock_irqsave(&ts->irq_lock, irqflags);
408
+ if (ts->irq_is_disable) {
409
+ ts->irq_is_disable = 0;
410
+ ret = input_set_int_enable(&(config_info.input_type), 1);
411
+ if (ret < 0)
412
+ dprintk(DEBUG_OTHERS_INFO,"%s irq enable failed\n", goodix_ts_name);
413
+ }
414
+ spin_unlock_irqrestore(&ts->irq_lock, irqflags);
622415 }
623
-
624416
625417 /*******************************************************
626418 Function:
627
- Report touch point event
419
+Touch down report function.
420
+
628421 Input:
629
- ts: goodix i2c_client private data
630
- id: trackId
631
- x: input x coordinate
632
- y: input y coordinate
633
- w: input pressure
422
+ts:private data.
423
+id:tracking id.
424
+x:input x.
425
+y:input y.
426
+w:input weight.
427
+
634428 Output:
635
- None.
636
-*********************************************************/
429
+None.
430
+ *******************************************************/
637431 static void gtp_touch_down(struct goodix_ts_data* ts,s32 id,s32 x,s32 y,s32 w)
638432 {
639
- dprintk(DEBUG_X_Y_INFO, "source data:ID:%d, X:%d, Y:%d, W:%d\n", id, x, y, w);
640
- if(1 == exchange_x_y_flag){
641
- swap(x, y);
642
- }
643
- if(1 == revert_x_flag){
644
- x = SCREEN_MAX_X - x;
645
- }
646
- if(1 == revert_y_flag){
647
- y = SCREEN_MAX_Y - y;
648
- }
649
- dprintk(DEBUG_X_Y_INFO,"report data:ID:%d, X:%d, Y:%d, W:%d\n", id, x, y, w);
433
+ dprintk(DEBUG_X_Y_INFO, "source data:ID:%d, X:%d, Y:%d, W:%d\n", id, x, y, w);
434
+
435
+ //printk(KERN_ERR"revert_x_flag=%d, revert_y_flag=%d, GTP_ICS_SLOT_REPORT=%d V2 SCREEN_MAX_X:SCREEN_MAX_Y=%d:%d\n", revert_x_flag, revert_y_flag, GTP_ICS_SLOT_REPORT, SCREEN_MAX_X, SCREEN_MAX_Y);
436
+
437
+ if(1 == exchange_x_y_flag){
438
+ swap(x, y);
439
+ }
440
+
441
+ if(1 == revert_x_flag){
442
+ x = SCREEN_MAX_X - x;
443
+ }
444
+
445
+ if(1 == revert_y_flag){
446
+ y = SCREEN_MAX_Y - y;
447
+ }
448
+
449
+ dprintk(DEBUG_X_Y_INFO,"report data:ID:%d, X:%d, Y:%d, W:%d\n", id, x, y, w);
650450
651451 #if GTP_ICS_SLOT_REPORT
652
- input_mt_slot(ts->input_dev, id);
653
- input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, id);
654
- input_report_abs(ts->input_dev, ABS_MT_POSITION_X, x);
655
- input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, y);
656
- input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, w);
657
- input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, w);
452
+ input_mt_slot(ts->input_dev, id);
453
+ input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, id);
454
+ input_report_abs(ts->input_dev, ABS_MT_POSITION_X, x);
455
+ input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, y);
456
+ input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, w);
457
+ input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, w);
658458 #else
659
- input_report_key(ts->input_dev, BTN_TOUCH, 1);
660
- input_report_abs(ts->input_dev, ABS_MT_POSITION_X, x);
661
- input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, y);
662
- input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, w);
663
- input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, w);
664
- input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, id);
665
- input_mt_sync(ts->input_dev);
459
+ input_report_key(ts->input_dev, BTN_TOUCH, 1);
460
+ input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, id);
461
+ input_report_abs(ts->input_dev, ABS_MT_POSITION_X, x);
462
+ input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, y);
463
+ input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, w);
464
+ input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, w);
465
+ input_mt_sync(ts->input_dev);
666466 #endif
667467
668
- GTP_DEBUG("ID:%d, X:%d, Y:%d, W:%d", id, x, y, w);
669468 }
670469
671470 /*******************************************************
672471 Function:
673
- Report touch release event
472
+Touch up report function.
473
+
674474 Input:
675
- ts: goodix i2c_client private data
475
+ts:private data.
476
+
676477 Output:
677
- None.
678
-*********************************************************/
478
+None.
479
+ *******************************************************/
679480 static void gtp_touch_up(struct goodix_ts_data* ts, s32 id)
680481 {
681482 #if GTP_ICS_SLOT_REPORT
682
- input_mt_slot(ts->input_dev, id);
683
- input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, -1);
684
- GTP_DEBUG("Touch id[%2d] release!", id);
483
+ input_mt_slot(ts->input_dev, id);
484
+ input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, -1);
485
+ dprintk(DEBUG_X_Y_INFO, "Touch id[%2d] release!", id);
685486 #else
686
- input_report_key(ts->input_dev, BTN_TOUCH, 0);
487
+ input_report_key(ts->input_dev, BTN_TOUCH, 0);
488
+ input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0);
489
+ input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0);
490
+ input_mt_sync(ts->input_dev);
687491 #endif
688492 }
689
-
690
-#if GTP_WITH_PEN
691
-
692
-static void gtp_pen_init(struct goodix_ts_data *ts)
693
-{
694
- s32 ret = 0;
695
-
696
- GTP_INFO("Request input device for pen/stylus.");
697
-
698
- ts->pen_dev = input_allocate_device();
699
- if (ts->pen_dev == NULL)
700
- {
701
- GTP_ERROR("Failed to allocate input device for pen/stylus.");
702
- return;
703
- }
704
-
705
- ts->pen_dev->evbit[0] = BIT_MASK(EV_SYN) | BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS) ;
706
-
707
-#if GTP_ICS_SLOT_REPORT
708
- input_mt_init_slots(ts->pen_dev, 16); //
709
-#else
710
- ts->pen_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
711
-#endif
712
-
713
- set_bit(BTN_TOOL_PEN, ts->pen_dev->keybit);
714
- set_bit(INPUT_PROP_DIRECT, ts->pen_dev->propbit);
715
- //set_bit(INPUT_PROP_POINTER, ts->pen_dev->propbit);
716
-
717
-#if GTP_PEN_HAVE_BUTTON
718
- input_set_capability(ts->pen_dev, EV_KEY, BTN_STYLUS);
719
- input_set_capability(ts->pen_dev, EV_KEY, BTN_STYLUS2);
720
-#endif
721
-
722
- input_set_abs_params(ts->pen_dev, ABS_MT_POSITION_X, 0, ts->abs_x_max, 0, 0);
723
- input_set_abs_params(ts->pen_dev, ABS_MT_POSITION_Y, 0, ts->abs_y_max, 0, 0);
724
- input_set_abs_params(ts->pen_dev, ABS_MT_PRESSURE, 0, 255, 0, 0);
725
- input_set_abs_params(ts->pen_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
726
- input_set_abs_params(ts->pen_dev, ABS_MT_TRACKING_ID, 0, 255, 0, 0);
727
-
728
- ts->pen_dev->name = "goodix-pen";
729
- ts->pen_dev->id.bustype = BUS_I2C;
730
-
731
- ret = input_register_device(ts->pen_dev);
732
- if (ret)
733
- {
734
- GTP_ERROR("Register %s input device failed", ts->pen_dev->name);
735
- return;
736
- }
737
-}
738
-
739
-static void gtp_pen_down(s32 x, s32 y, s32 w, s32 id)
740
-{
741
- struct goodix_ts_data *ts = i2c_get_clientdata(i2c_connect_client);
742
-
743
-#if GTP_CHANGE_X2Y
744
- GTP_SWAP(x, y);
745
-#endif
746
-
747
- input_report_key(ts->pen_dev, BTN_TOOL_PEN, 1);
748
-#if GTP_ICS_SLOT_REPORT
749
- input_mt_slot(ts->pen_dev, id);
750
- input_report_abs(ts->pen_dev, ABS_MT_TRACKING_ID, id);
751
- input_report_abs(ts->pen_dev, ABS_MT_POSITION_X, x);
752
- input_report_abs(ts->pen_dev, ABS_MT_POSITION_Y, y);
753
- input_report_abs(ts->pen_dev, ABS_MT_PRESSURE, w);
754
- input_report_abs(ts->pen_dev, ABS_MT_TOUCH_MAJOR, w);
755
-#else
756
- input_report_key(ts->pen_dev, BTN_TOUCH, 1);
757
- input_report_abs(ts->pen_dev, ABS_MT_POSITION_X, x);
758
- input_report_abs(ts->pen_dev, ABS_MT_POSITION_Y, y);
759
- input_report_abs(ts->pen_dev, ABS_MT_PRESSURE, w);
760
- input_report_abs(ts->pen_dev, ABS_MT_TOUCH_MAJOR, w);
761
- input_report_abs(ts->pen_dev, ABS_MT_TRACKING_ID, id);
762
- input_mt_sync(ts->pen_dev);
763
-#endif
764
- GTP_DEBUG("(%d)(%d, %d)[%d]", id, x, y, w);
765
-}
766
-
767
-static void gtp_pen_up(s32 id)
768
-{
769
- struct goodix_ts_data *ts = i2c_get_clientdata(i2c_connect_client);
770
-
771
- input_report_key(ts->pen_dev, BTN_TOOL_PEN, 0);
772
-
773
-#if GTP_ICS_SLOT_REPORT
774
- input_mt_slot(ts->pen_dev, id);
775
- input_report_abs(ts->pen_dev, ABS_MT_TRACKING_ID, -1);
776
-#else
777
-
778
- input_report_key(ts->pen_dev, BTN_TOUCH, 0);
779
-#endif
780
-
781
-}
782
-#endif
783493
784494 /*******************************************************
785495 Function:
786
- Goodix touchscreen work function
496
+Goodix touchscreen work function.
497
+
787498 Input:
788
- work: work struct of goodix_workqueue
499
+work: work_struct of goodix_wq.
500
+
789501 Output:
790
- None.
791
-*********************************************************/
502
+None.
503
+ *******************************************************/
792504 static void goodix_ts_work_func(struct work_struct *work)
793505 {
794
- u8 end_cmd[3] = {GTP_READ_COOR_ADDR >> 8, GTP_READ_COOR_ADDR & 0xFF, 0};
795
- u8 point_data[2 + 1 + 8 * GTP_MAX_TOUCH + 1]={GTP_READ_COOR_ADDR >> 8, GTP_READ_COOR_ADDR & 0xFF};
796
- u8 touch_num = 0;
797
- u8 finger = 0;
798
- static u16 pre_touch = 0;
799
- static u8 pre_key = 0;
800
-#if GTP_WITH_PEN
801
- u8 pen_active = 0;
802
- static u8 pre_pen = 0;
803
-#endif
804
- u8 key_value = 0;
805
- u8* coor_data = NULL;
806
- s32 input_x = 0;
807
- s32 input_y = 0;
808
- s32 input_w = 0;
809
- s32 id = 0;
810
- s32 i = 0;
811
- s32 ret = -1;
812
- struct goodix_ts_data *ts = NULL;
506
+ u8 end_cmd[3] = {GTP_READ_COOR_ADDR >> 8, GTP_READ_COOR_ADDR & 0xFF, 0};
507
+ u8 point_data[2 + 1 + 8 * GTP_MAX_TOUCH + 1]={GTP_READ_COOR_ADDR >> 8, GTP_READ_COOR_ADDR & 0xFF};
508
+ u8 touch_num = 0;
509
+ u8 finger = 0;
510
+ static u16 pre_touch = 0;
511
+ static u8 pre_key = 0;
512
+ u8 key_value = 0;
513
+ u8* coor_data = NULL;
514
+ s32 input_x = 0;
515
+ s32 input_y = 0;
516
+ s32 input_w = 0;
517
+ s32 id = 0;
518
+ s32 i = 0;
519
+ int j = 0;
520
+ s32 ret = -1;
521
+ struct goodix_ts_data *ts = NULL;
813522
814
-#if GTP_COMPATIBLE_MODE
815
- u8 rqst_buf[3] = {0x80, 0x43}; // for GT9XXF
816
-#endif
523
+ dprintk(DEBUG_X_Y_INFO,"===enter %s===\n",__func__);
817524
818
-//#if GTP_GESTURE_WAKEUP
819
- u8 doze_buf[3] = {0x81, 0x4B};
820
-//#endif
525
+ ts = container_of(work, struct goodix_ts_data, work);
526
+ if (ts->enter_update){
527
+ return;
528
+ }
821529
822
- GTP_DEBUG_FUNC();
823
- dprintk(DEBUG_X_Y_INFO,"===enter %s===\n",__func__);
824
- ts = container_of(work, struct goodix_ts_data, work);
825
- if (ts->enter_update)
826
- {
827
- return;
828
- }
829
-//#if GTP_GESTURE_WAKEUP
830
-if(gtp_gesture_wakeup){
831
- if (DOZE_ENABLED == doze_status)
832
- {
833
- ret = gtp_i2c_read(i2c_connect_client, doze_buf, 3);
834
- GTP_DEBUG("0x814B = 0x%02X", doze_buf[2]);
835
- if (ret > 0)
836
- {
837
- if ((doze_buf[2] == 'a') || (doze_buf[2] == 'b') || (doze_buf[2] == 'c') ||
838
- (doze_buf[2] == 'd') || (doze_buf[2] == 'e') || (doze_buf[2] == 'g') ||
839
- (doze_buf[2] == 'h') || (doze_buf[2] == 'm') || (doze_buf[2] == 'o') ||
840
- (doze_buf[2] == 'q') || (doze_buf[2] == 's') || (doze_buf[2] == 'v') ||
841
- (doze_buf[2] == 'w') || (doze_buf[2] == 'y') || (doze_buf[2] == 'z') ||
842
- (doze_buf[2] == 0x5E) /* ^ */
843
- )
844
- {
845
- if (doze_buf[2] != 0x5E)
846
- {
847
- GTP_INFO("Wakeup by gesture(%c), light up the screen!", doze_buf[2]);
848
- }
849
- else
850
- {
851
- GTP_INFO("Wakeup by gesture(^), light up the screen!");
852
- }
853
- doze_status = DOZE_WAKEUP;
854
- input_report_key(ts->input_dev, KEY_POWER, 1);
855
- input_sync(ts->input_dev);
856
- input_report_key(ts->input_dev, KEY_POWER, 0);
857
- input_sync(ts->input_dev);
858
- switch(doze_buf[2]) {
859
- case 'e':
860
- input_report_key(ts->input_dev, ctp_key_list[0], 1);
861
- input_sync(ts->input_dev);
862
- input_report_key(ts->input_dev, ctp_key_list[0], 0);
863
- input_sync(ts->input_dev);
864
- break;
865
- case 'o':
866
- input_report_key(ts->input_dev, ctp_key_list[1], 1);
867
- input_sync(ts->input_dev);
868
- input_report_key(ts->input_dev, ctp_key_list[1], 0);
869
- input_sync(ts->input_dev);
870
- break;
871
- case 'w':
872
- input_report_key(ts->input_dev, ctp_key_list[3], 1);
873
- input_sync(ts->input_dev);
874
- input_report_key(ts->input_dev, ctp_key_list[3], 0);
875
- input_sync(ts->input_dev);
876
- break;
877
- case 'c':
878
- input_report_key(ts->input_dev, ctp_key_list[2], 1);
879
- input_sync(ts->input_dev);
880
- input_report_key(ts->input_dev, ctp_key_list[2], 0);
881
- input_sync(ts->input_dev);
882
- break;
883
- default:
884
- break;
530
+ for(j=0; j<2;j++)
531
+ {
532
+ ret = gtp_i2c_read(ts->client, point_data, 12);
533
+ if (ret < 0){
534
+ printk("I2C transfer error. errno:%d\n ", ret);
535
+ goto exit_work_func;
885536 }
886
- // clear 0x814B
887
- doze_buf[2] = 0x00;
888
- gtp_i2c_write(i2c_connect_client, doze_buf, 3);
889
- }
890
- else if ( (doze_buf[2] == 0xAA) || (doze_buf[2] == 0xBB) ||
891
- (doze_buf[2] == 0xAB) || (doze_buf[2] == 0xBA) )
892
- {
893
- char *direction[4] = {"Right", "Down", "Up", "Left"};
894
- u8 type = ((doze_buf[2] & 0x0F) - 0x0A) + (((doze_buf[2] >> 4) & 0x0F) - 0x0A) * 2;
537
+ }
895538
896
- GTP_INFO("%s slide to light up the screen!", direction[type]);
897
- doze_status = DOZE_WAKEUP;
898
- input_report_key(ts->input_dev, KEY_POWER, 1);
899
- input_sync(ts->input_dev);
900
- input_report_key(ts->input_dev, KEY_POWER, 0);
901
- input_sync(ts->input_dev);
902
- switch(type) {
903
- case 0:
904
- input_report_key(ts->input_dev, ctp_key_list[7], 1);
905
- input_sync(ts->input_dev);
906
- input_report_key(ts->input_dev, ctp_key_list[7], 0);
907
- input_sync(ts->input_dev);
908
- break;
909
- case 1:
910
- input_report_key(ts->input_dev, ctp_key_list[5], 1);
911
- input_sync(ts->input_dev);
912
- input_report_key(ts->input_dev, ctp_key_list[5], 0);
913
- input_sync(ts->input_dev);
914
- break;
915
- case 2:
916
- input_report_key(ts->input_dev, ctp_key_list[4], 1);
917
- input_sync(ts->input_dev);
918
- input_report_key(ts->input_dev, ctp_key_list[4], 0);
919
- input_sync(ts->input_dev);
920
- break;
921
- case 3:
922
- input_report_key(ts->input_dev, ctp_key_list[6], 1);
923
- input_sync(ts->input_dev);
924
- input_report_key(ts->input_dev, ctp_key_list[6], 0);
925
- input_sync(ts->input_dev);
926
- break;
927
- default:
928
- break;
929
- }
930
- // clear 0x814B
931
- doze_buf[2] = 0x00;
932
- gtp_i2c_write(i2c_connect_client, doze_buf, 3);
933
- }
934
- else if (0xCC == doze_buf[2])
935
- {
936
- GTP_INFO("Double click to light up the screen!");
937
- doze_status = DOZE_WAKEUP;
938
- input_report_key(ts->input_dev, KEY_POWER, 1);
939
- input_sync(ts->input_dev);
940
- input_report_key(ts->input_dev, KEY_POWER, 0);
941
- input_sync(ts->input_dev);
942
- // clear 0x814B
943
- doze_buf[2] = 0x00;
944
- gtp_i2c_write(i2c_connect_client, doze_buf, 3);
945
- }
946
- else
947
- {
948
- // clear 0x814B
949
- doze_buf[2] = 0x00;
950
- gtp_i2c_write(i2c_connect_client, doze_buf, 3);
951
- gtp_enter_doze(ts);
952
- }
953
- }
954
- if (ts->use_irq)
955
- {
956
- gtp_irq_enable(ts);
957
- }
958
- return;
959
- }
960
-}
961
-//#endif
539
+ finger = point_data[GTP_ADDR_LENGTH];
540
+ if((finger & 0x80) == 0) {
541
+ goto exit_work_func;
542
+ }
962543
963
- ret = gtp_i2c_read(ts->client, point_data, 12);
964
- if (ret < 0)
965
- {
966
- GTP_ERROR("I2C transfer error. errno:%d\n ", ret);
967
- if (ts->use_irq)
968
- {
969
- gtp_irq_enable(ts);
970
- }
971
- return;
972
- }
544
+ touch_num = finger & 0x0f;
545
+ if (touch_num > GTP_MAX_TOUCH) {
546
+ goto exit_work_func;
547
+ }
973548
974
- finger = point_data[GTP_ADDR_LENGTH];
549
+ if (touch_num > 1) {
550
+ u8 buf[8 * GTP_MAX_TOUCH] = {(GTP_READ_COOR_ADDR + 10) >> 8, (GTP_READ_COOR_ADDR + 10) & 0xff};
975551
976
-#if GTP_COMPATIBLE_MODE
977
- // GT9XXF
978
- if ((finger == 0x00) && (CHIP_TYPE_GT9F == ts->chip_type)) // request arrived
979
- {
980
- ret = gtp_i2c_read(ts->client, rqst_buf, 3);
981
- if (ret < 0)
982
- {
983
- GTP_ERROR("Read request status error!");
984
- goto exit_work_func;
985
- }
552
+ ret = gtp_i2c_read(ts->client, buf, 2 + 8 * (touch_num - 1));
553
+ memcpy(&point_data[12], &buf[2], 8 * (touch_num - 1));
554
+ }
986555
987
- switch (rqst_buf[2])
988
- {
989
- case GTP_RQST_CONFIG:
990
- GTP_INFO("Request for config.");
991
- ret = gtp_send_cfg(ts->client);
992
- if (ret < 0)
993
- {
994
- GTP_ERROR("Request for config unresponded!");
995
- }
996
- else
997
- {
998
- rqst_buf[2] = GTP_RQST_RESPONDED;
999
- gtp_i2c_write(ts->client, rqst_buf, 3);
1000
- GTP_INFO("Request for config responded!");
1001
- }
1002
- break;
556
+#if GTP_HAVE_TOUCH_KEY
557
+ key_value = point_data[3 + 8 * touch_num];
1003558
1004
- case GTP_RQST_BAK_REF:
1005
- GTP_INFO("Request for backup reference.");
1006
- ts->rqst_processing = 1;
1007
- ret = gtp_bak_ref_proc(ts, GTP_BAK_REF_SEND);
1008
- if (SUCCESS == ret)
1009
- {
1010
- rqst_buf[2] = GTP_RQST_RESPONDED;
1011
- gtp_i2c_write(ts->client, rqst_buf, 3);
1012
- ts->rqst_processing = 0;
1013
- GTP_INFO("Request for backup reference responded!");
1014
- }
1015
- else
1016
- {
1017
- GTP_ERROR("Requeset for backup reference unresponed!");
1018
- }
1019
- break;
1020
-
1021
- case GTP_RQST_RESET:
1022
- GTP_INFO("Request for reset.");
1023
- gtp_recovery_reset(ts->client);
1024
- break;
1025
-
1026
- case GTP_RQST_MAIN_CLOCK:
1027
- GTP_INFO("Request for main clock.");
1028
- ts->rqst_processing = 1;
1029
- ret = gtp_main_clk_proc(ts);
1030
- if (FAIL == ret)
1031
- {
1032
- GTP_ERROR("Request for main clock unresponded!");
1033
- }
1034
- else
1035
- {
1036
- GTP_INFO("Request for main clock responded!");
1037
- rqst_buf[2] = GTP_RQST_RESPONDED;
1038
- gtp_i2c_write(ts->client, rqst_buf, 3);
1039
- ts->rqst_processing = 0;
1040
- ts->clk_chk_fs_times = 0;
1041
- }
1042
- break;
1043
-
1044
- default:
1045
- GTP_INFO("Undefined request: 0x%02X", rqst_buf[2]);
1046
- rqst_buf[2] = GTP_RQST_RESPONDED;
1047
- gtp_i2c_write(ts->client, rqst_buf, 3);
1048
- break;
1049
- }
1050
- }
559
+ if(key_value || pre_key) {
560
+ for (i = 0; i < GTP_MAX_KEY_NUM; i++) {
561
+ input_report_key(ts->input_dev, touch_key_array[i], key_value & (0x01<<i));
562
+ }
563
+ touch_num = 0;
564
+ pre_touch = 0;
565
+ }
1051566 #endif
1052
- if (finger == 0x00)
1053
- {
1054
- if (ts->use_irq)
1055
- {
1056
- gtp_irq_enable(ts);
1057
- }
1058
- return;
1059
- }
567
+ pre_key = key_value;
1060568
1061
- if((finger & 0x80) == 0)
1062
- {
1063
- goto exit_work_func;
1064
- }
1065
-
1066
- touch_num = finger & 0x0f;
1067
- if (touch_num > GTP_MAX_TOUCH)
1068
- {
1069
- goto exit_work_func;
1070
- }
1071
-
1072
- if (touch_num > 1)
1073
- {
1074
- u8 buf[8 * GTP_MAX_TOUCH] = {(GTP_READ_COOR_ADDR + 10) >> 8, (GTP_READ_COOR_ADDR + 10) & 0xff};
1075
-
1076
- ret = gtp_i2c_read(ts->client, buf, 2 + 8 * (touch_num - 1));
1077
- memcpy(&point_data[12], &buf[2], 8 * (touch_num - 1));
1078
- }
1079
-
1080
-#if (GTP_HAVE_TOUCH_KEY || GTP_PEN_HAVE_BUTTON)
1081
- key_value = point_data[3 + 8 * touch_num];
1082
-
1083
- if(key_value || pre_key)
1084
- {
1085
- #if GTP_PEN_HAVE_BUTTON
1086
- if (key_value == 0x40)
1087
- {
1088
- GTP_DEBUG("BTN_STYLUS & BTN_STYLUS2 Down.");
1089
- input_report_key(ts->pen_dev, BTN_STYLUS, 1);
1090
- input_report_key(ts->pen_dev, BTN_STYLUS2, 1);
1091
- pen_active = 1;
1092
- }
1093
- else if (key_value == 0x10)
1094
- {
1095
- GTP_DEBUG("BTN_STYLUS Down, BTN_STYLUS2 Up.");
1096
- input_report_key(ts->pen_dev, BTN_STYLUS, 1);
1097
- input_report_key(ts->pen_dev, BTN_STYLUS2, 0);
1098
- pen_active = 1;
1099
- }
1100
- else if (key_value == 0x20)
1101
- {
1102
- GTP_DEBUG("BTN_STYLUS Up, BTN_STYLUS2 Down.");
1103
- input_report_key(ts->pen_dev, BTN_STYLUS, 0);
1104
- input_report_key(ts->pen_dev, BTN_STYLUS2, 1);
1105
- pen_active = 1;
1106
- }
1107
- else
1108
- {
1109
- GTP_DEBUG("BTN_STYLUS & BTN_STYLUS2 Up.");
1110
- input_report_key(ts->pen_dev, BTN_STYLUS, 0);
1111
- input_report_key(ts->pen_dev, BTN_STYLUS2, 0);
1112
- if ( (pre_key == 0x40) || (pre_key == 0x20) ||
1113
- (pre_key == 0x10)
1114
- )
1115
- {
1116
- pen_active = 1;
1117
- }
1118
- }
1119
- if (pen_active)
1120
- {
1121
- touch_num = 0; // shield pen point
1122
- //pre_touch = 0; // clear last pen status
1123
- }
1124
- #endif
1125
-
1126
- #if GTP_HAVE_TOUCH_KEY
1127
- if (!pre_touch)
1128
- {
1129
- for (i = 0; i < GTP_MAX_KEY_NUM; i++)
1130
- {
1131
- #if GTP_DEBUG_ON
1132
- for (ret = 0; ret < 4; ++ret)
1133
- {
1134
- if (key_codes[ret] == touch_key_array[i])
1135
- {
1136
- GTP_DEBUG("Key: %s %s", key_names[ret], (key_value & (0x01 << i)) ? "Down" : "Up");
1137
- break;
1138
- }
1139
- }
1140
- #endif
1141
- input_report_key(ts->input_dev, touch_key_array[i], key_value & (0x01<<i));
1142
- }
1143
- touch_num = 0; // shield fingers
1144
- }
1145
- #endif
1146
- }
1147
-#endif
1148
- pre_key = key_value;
1149
-
1150
- GTP_DEBUG("pre_touch:%02x, finger:%02x.", pre_touch, finger);
569
+ dprintk(DEBUG_X_Y_INFO, "pre_touch:%02x, finger:%02x.", pre_touch, finger);
1151570
1152571 #if GTP_ICS_SLOT_REPORT
572
+ if (pre_touch || touch_num) {
573
+ s32 pos = 0;
574
+ u16 touch_index = 0;
575
+ coor_data = &point_data[3];
1153576
1154
-#if GTP_WITH_PEN
1155
- if (pre_pen && (touch_num == 0))
1156
- {
1157
- GTP_DEBUG("Pen touch UP(Slot)!");
1158
- gtp_pen_up(0);
1159
- pen_active = 1;
1160
- pre_pen = 0;
1161
- }
1162
-#endif
1163
- if (pre_touch || touch_num)
1164
- {
1165
- s32 pos = 0;
1166
- u16 touch_index = 0;
1167
- u8 report_num = 0;
1168
- coor_data = &point_data[3];
577
+ if(touch_num) {
578
+ id = coor_data[pos] & 0x0F;
579
+ touch_index |= (0x01<<id);
580
+ }
1169581
1170
- if(touch_num)
1171
- {
1172
- id = coor_data[pos] & 0x0F;
582
+ dprintk(DEBUG_X_Y_INFO,
583
+ "id=%d, touch_index=0x%x, pre_touch=0x%x\n", id, touch_index, pre_touch);
1173584
1174
- #if GTP_WITH_PEN
1175
- id = coor_data[pos];
1176
- if ((id & 0x80))
1177
- {
1178
- GTP_DEBUG("Pen touch DOWN(Slot)!");
1179
- input_x = coor_data[pos + 1] | (coor_data[pos + 2] << 8);
1180
- input_y = coor_data[pos + 3] | (coor_data[pos + 4] << 8);
1181
- input_w = coor_data[pos + 5] | (coor_data[pos + 6] << 8);
585
+ for (i = 0; i < GTP_MAX_TOUCH; i++) {
586
+ if (touch_index & (0x01<<i)) {
587
+ input_x = coor_data[pos + 1] | coor_data[pos + 2] << 8;
588
+ input_y = coor_data[pos + 3] | coor_data[pos + 4] << 8;
589
+ input_w = coor_data[pos + 5] | coor_data[pos + 6] << 8;
1182590
1183
- gtp_pen_down(input_x, input_y, input_w, 0);
1184
- pre_pen = 1;
1185
- pre_touch = 0;
1186
- pen_active = 1;
1187
- }
1188
- #endif
591
+ gtp_touch_down(ts, id, input_x, input_y, input_w);
592
+ pre_touch |= 0x01 << i;
1189593
1190
- touch_index |= (0x01<<id);
1191
- }
594
+ pos += 8;
595
+ id = coor_data[pos] & 0x0F;
596
+ touch_index |= (0x01<<id);
597
+ }else {// if (pre_touch & (0x01 << i))
1192598
1193
- GTP_DEBUG("id = %d,touch_index = 0x%x, pre_touch = 0x%x\n",id, touch_index,pre_touch);
1194
- for (i = 0; i < GTP_MAX_TOUCH; i++)
1195
- {
1196
- #if GTP_WITH_PEN
1197
- if (pre_pen == 1)
1198
- {
1199
- break;
1200
- }
1201
- #endif
599
+ gtp_touch_up(ts, i);
600
+ pre_touch &= ~(0x01 << i);
601
+ }
602
+ }
603
+ }
1202604
1203
- if ((touch_index & (0x01<<i)))
1204
- {
1205
- input_x = coor_data[pos + 1] | (coor_data[pos + 2] << 8);
1206
- input_y = coor_data[pos + 3] | (coor_data[pos + 4] << 8);
1207
- input_w = coor_data[pos + 5] | (coor_data[pos + 6] << 8);
1208
-
1209
- gtp_touch_down(ts, id, input_x, input_y, input_w);
1210
- pre_touch |= 0x01 << i;
1211
-
1212
- report_num++;
1213
- if (report_num < touch_num)
1214
- {
1215
- pos += 8;
1216
- id = coor_data[pos] & 0x0F;
1217
- touch_index |= (0x01<<id);
1218
- }
1219
- }
1220
- else
1221
- {
1222
- gtp_touch_up(ts, i);
1223
- pre_touch &= ~(0x01 << i);
1224
- }
1225
- }
1226
- }
1227605 #else
606
+ if (touch_num ) {
607
+ for (i = 0; i < touch_num; i++) {
608
+ coor_data = &point_data[i * 8 + 3];
1228609
1229
- if (touch_num)
1230
- {
1231
- for (i = 0; i < touch_num; i++)
1232
- {
1233
- coor_data = &point_data[i * 8 + 3];
610
+ id = coor_data[0] & 0x0F;
611
+ input_x = coor_data[1] | coor_data[2] << 8;
612
+ input_y = coor_data[3] | coor_data[4] << 8;
613
+ input_w = coor_data[5] | coor_data[6] << 8;
1234614
1235
- id = coor_data[0] & 0x0F;
1236
- input_x = coor_data[1] | (coor_data[2] << 8);
1237
- input_y = coor_data[3] | (coor_data[4] << 8);
1238
- input_w = coor_data[5] | (coor_data[6] << 8);
615
+ gtp_touch_down(ts, id, input_x, input_y, input_w);
616
+ }
617
+ }else if(pre_touch){
618
+ dprintk(DEBUG_X_Y_INFO, "Touch Release!");
619
+ gtp_touch_up(ts, 0);
620
+ }
1239621
1240
- #if GTP_WITH_PEN
1241
- id = coor_data[0];
1242
- if (id & 0x80)
1243
- {
1244
- GTP_DEBUG("Pen touch DOWN!");
1245
- gtp_pen_down(input_x, input_y, input_w, 0);
1246
- pre_pen = 1;
1247
- pen_active = 1;
1248
- break;
1249
- }
1250
- else
1251
- #endif
1252
- {
1253
- gtp_touch_down(ts, id, input_x, input_y, input_w);
1254
- }
1255
- }
1256
- }
1257
- else if (pre_touch)
1258
- {
1259
- #if GTP_WITH_PEN
1260
- if (pre_pen == 1)
1261
- {
1262
- GTP_DEBUG("Pen touch UP!");
1263
- gtp_pen_up(0);
1264
- pre_pen = 0;
1265
- pen_active = 1;
1266
- }
1267
- else
1268
- #endif
1269
- {
1270
- GTP_DEBUG("Touch Release!");
1271
- gtp_touch_up(ts, 0);
1272
- }
1273
- }
622
+ pre_touch = touch_num;
1274623
1275
- pre_touch = touch_num;
1276624 #endif
1277625
1278
-#if GTP_WITH_PEN
1279
- if (pen_active)
1280
- {
1281
- pen_active = 0;
1282
- input_sync(ts->pen_dev);
1283
- }
1284
- else
1285
-#endif
1286
- {
1287
- input_sync(ts->input_dev);
1288
- }
626
+ input_sync(ts->input_dev);
1289627
1290628 exit_work_func:
1291
- if(!ts->gtp_rawdiff_mode)
1292
- {
1293
- ret = gtp_i2c_write(ts->client, end_cmd, 3);
1294
- if (ret < 0)
1295
- {
1296
- GTP_INFO("I2C write end_cmd error!");
1297
- }
1298
- }
1299
- if (ts->use_irq)
1300
- {
1301
- gtp_irq_enable(ts);
1302
- }
629
+ if(!ts->gtp_rawdiff_mode) {
630
+ ret = gtp_i2c_write(ts->client, end_cmd, 3);
631
+ if (ret < 0) {
632
+ printk("I2C write end_cmd error!");
633
+ }
634
+ }
635
+ return ;
1303636 }
1304637
1305638 /*******************************************************
1306639 Function:
1307
- Timer interrupt service routine for polling mode.
640
+External interrupt service routine.
641
+
1308642 Input:
1309
- timer: timer struct pointer
643
+irq: interrupt number.
644
+dev_id: private data pointer.
645
+
1310646 Output:
1311
- Timer work mode.
1312
- HRTIMER_NORESTART: no restart mode
1313
-*********************************************************/
1314
-static enum hrtimer_restart goodix_ts_timer_handler(struct hrtimer *timer)
1315
-{
1316
- struct goodix_ts_data *ts = container_of(timer, struct goodix_ts_data, timer);
647
+irq execute status.
648
+ *******************************************************/
1317649
1318
- GTP_DEBUG_FUNC();
650
+irqreturn_t goodix_ts_irq_handler(int irq, void *dev_id)
651
+{
652
+ struct goodix_ts_data *ts = (struct goodix_ts_data *)dev_id;
653
+ dprintk(DEBUG_INT_INFO, "==========------TS Interrupt-----============\n");
1319654
1320
- queue_work(goodix_wq, &ts->work);
1321
- hrtimer_start(&ts->timer, ktime_set(0, (GTP_POLL_TIME+6)*1000000), HRTIMER_MODE_REL);
1322
- return HRTIMER_NORESTART;
655
+ queue_work(goodix_wq, &ts->work);
656
+ return 0;
1323657 }
1324658
1325
-/*******************************************************
1326
-Function:
1327
- External interrupt service routine for interrupt mode.
1328
-Input:
1329
- irq: interrupt number.
1330
- dev_id: private data pointer
1331
-Output:
1332
- Handle Result.
1333
- IRQ_HANDLED: interrupt handled successfully
1334
-*********************************************************/
1335
-static irqreturn_t goodix_ts_irq_handler(int irq, void *dev_id)
1336
-{
1337
- struct goodix_ts_data *ts = dev_id;
1338659
1339
- GTP_DEBUG_FUNC();
1340
-
1341
- gtp_irq_disable(ts);
1342
-
1343
- queue_work(goodix_wq, &ts->work);
1344
-
1345
- return IRQ_HANDLED;
1346
-}
1347
-/*******************************************************
1348
-Function:
1349
- Synchronization.
1350
-Input:
1351
- ms: synchronization time in millisecond.
1352
-Output:
1353
- None.
1354
-*******************************************************/
1355
-void gtp_int_sync(s32 ms)
1356
-{
1357
- gtp_set_int_value(0);
1358
- msleep(ms);
1359
- gtp_set_io_int();
1360
-}
1361660
1362661
1363662 /*******************************************************
1364663 Function:
1365
- Reset chip.
664
+Eter sleep function.
665
+
1366666 Input:
1367
- ms: reset time in millisecond
667
+ts:private data.
668
+
1368669 Output:
1369
- None.
1370
-*******************************************************/
1371
-void gtp_reset_guitar(struct i2c_client *client, s32 ms)
1372
-{
1373
-#if GTP_COMPATIBLE_MODE
1374
- struct goodix_ts_data *ts = i2c_get_clientdata(client);
1375
-#endif
1376
-
1377
- GTP_DEBUG_FUNC();
1378
- GTP_INFO("Guitar reset");
1379
- __gpio_set_value(config_info.wakeup_gpio.gpio, 0); // begin select I2C slave addr
1380
- msleep(ms); // T2: > 10ms
1381
- // HIGH: 0x28/0x29, LOW: 0xBA/0xBB
1382
- if(client->addr == 0x14)
1383
- gtp_set_int_value(1);
1384
- else
1385
- gtp_set_int_value(0);
1386
-
1387
- msleep(2); // T3: > 100us
1388
- __gpio_set_value(config_info.wakeup_gpio.gpio, 1);
1389
-
1390
- msleep(6); // T4: > 5ms
1391
-
1392
-// gpio_direction_input(config_info.wakeup_gpio.gpio); // end select I2C slave addr
1393
-
1394
-#if GTP_COMPATIBLE_MODE
1395
- if (CHIP_TYPE_GT9F == ts->chip_type)
1396
- {
1397
- return;
1398
- }
1399
-#endif
1400
-
1401
- gtp_int_sync(50);
1402
-#if GTP_ESD_PROTECT
1403
- gtp_init_ext_watchdog(client);
1404
-#endif
1405
-}
1406
-
1407
-//#if GTP_GESTURE_WAKEUP
1408
-/*******************************************************
1409
-Function:
1410
- Enter doze mode for sliding wakeup.
1411
-Input:
1412
- ts: goodix tp private data
1413
-Output:
1414
- 1: succeed, otherwise failed
1415
-*******************************************************/
1416
-static s8 gtp_enter_doze(struct goodix_ts_data *ts)
1417
-{
1418
- s8 ret = -1;
1419
- s8 retry = 0;
1420
- u8 i2c_control_buf[3] = {(u8)(GTP_REG_SLEEP >> 8), (u8)GTP_REG_SLEEP, 8};
1421
-
1422
- GTP_DEBUG_FUNC();
1423
-
1424
- GTP_DEBUG("Entering gesture mode.");
1425
- while(retry++ < 5)
1426
- {
1427
- i2c_control_buf[0] = 0x80;
1428
- i2c_control_buf[1] = 0x46;
1429
- ret = gtp_i2c_write(ts->client, i2c_control_buf, 3);
1430
- if (ret < 0)
1431
- {
1432
- GTP_DEBUG("failed to set doze flag into 0x8046, %d", retry);
1433
- continue;
1434
- }
1435
- i2c_control_buf[0] = 0x80;
1436
- i2c_control_buf[1] = 0x40;
1437
- ret = gtp_i2c_write(ts->client, i2c_control_buf, 3);
1438
- if (ret > 0)
1439
- {
1440
- doze_status = DOZE_ENABLED;
1441
- GTP_INFO("Gesture mode enabled.");
1442
- return ret;
1443
- }
1444
- msleep(10);
1445
- }
1446
- GTP_ERROR("GTP send gesture cmd failed.");
1447
- return ret;
1448
-}
1449
-//#else
1450
-/*******************************************************
1451
-Function:
1452
- Enter sleep mode.
1453
-Input:
1454
- ts: private data.
1455
-Output:
1456
- Executive outcomes.
1457
- 1: succeed, otherwise failed.
1458
-*******************************************************/
670
+Executive outcomes.0--success,non-0--fail.
671
+ *******************************************************/
672
+#if defined(CONFIG_HAS_EARLYSUSPEND) | defined(CONFIG_PM)
1459673 static s8 gtp_enter_sleep(struct goodix_ts_data * ts)
1460674 {
1461
- s8 ret = -1;
1462
- s8 retry = 0;
1463
- u8 i2c_control_buf[3] = {(u8)(GTP_REG_SLEEP >> 8), (u8)GTP_REG_SLEEP, 5};
675
+ s8 ret = -1;
676
+ s8 retry = 0;
677
+ u8 i2c_control_buf[3] = {(u8)(GTP_REG_SLEEP >> 8), (u8)GTP_REG_SLEEP, 5};
1464678
1465
-#if GTP_COMPATIBLE_MODE
1466
- u8 status_buf[3] = {0x80, 0x44};
1467
-#endif
679
+ dprintk(DEBUG_SUSPEND, "%s start!\n", __func__);
1468680
1469
- GTP_DEBUG_FUNC();
681
+ gtp_set_int_value(0);
1470682
1471
-#if GTP_COMPATIBLE_MODE
1472
- if (CHIP_TYPE_GT9F == ts->chip_type)
1473
- {
1474
- // GT9XXF: host interact with ic
1475
- ret = gtp_i2c_read(ts->client, status_buf, 3);
1476
- if (ret < 0)
1477
- {
1478
- GTP_ERROR("failed to get backup-reference status");
1479
- }
683
+ while(retry++ < 2) {
684
+ ret = gtp_i2c_write(ts->client, i2c_control_buf, 3);
685
+ if (ret > 0) {
686
+ dprintk(DEBUG_SUSPEND, "GTP enter sleep!");
687
+ return ret;
688
+ }
689
+ msleep(10);
690
+ }
691
+ dprintk(DEBUG_SUSPEND, "GTP send sleep cmd failed.");
1480692
1481
- if (status_buf[2] & 0x80)
1482
- {
1483
- ret = gtp_bak_ref_proc(ts, GTP_BAK_REF_STORE);
1484
- if (FAIL == ret)
1485
- {
1486
- GTP_ERROR("failed to store bak_ref");
1487
- }
1488
- }
1489
- }
1490
-#endif
1491
-
1492
- gtp_set_int_value(0);
1493
- msleep(5);
1494
-
1495
- while(retry++ < 5)
1496
- {
1497
- ret = gtp_i2c_write(ts->client, i2c_control_buf, 3);
1498
- if (ret > 0)
1499
- {
1500
- GTP_INFO("GTP enter sleep!");
1501
-
1502
- return ret;
1503
- }
1504
- msleep(10);
1505
- }
1506
- GTP_ERROR("GTP send sleep cmd failed.");
1507
- return ret;
693
+ return ret;
1508694 }
1509
-//#endif
695
+#endif
696
+
1510697 /*******************************************************
1511698 Function:
1512
- Wakeup from sleep.
699
+Wakeup from sleep mode Function.
700
+
1513701 Input:
1514
- ts: private data.
702
+ts: private data.
703
+
1515704 Output:
1516
- Executive outcomes.
1517
- >0: succeed, otherwise: failed.
1518
-*******************************************************/
705
+Executive outcomes.0--success,non-0--fail.
706
+ *******************************************************/
1519707 static s8 gtp_wakeup_sleep(struct goodix_ts_data * ts)
1520708 {
1521
- u8 retry = 0;
1522
- s8 ret = -1;
709
+ u8 retry = 0;
710
+ s8 ret = -1;
1523711
1524
- GTP_DEBUG_FUNC();
712
+ gtp_io_init(20);
713
+ gtp_set_io_int();
1525714
1526
-#if GTP_COMPATIBLE_MODE
1527
- if (CHIP_TYPE_GT9F == ts->chip_type)
1528
- {
1529
- u8 opr_buf[3] = {0x41, 0x80};
1530
-
1531
- gtp_set_int_value(1);
1532
- msleep(5);
1533
-
1534
- for (retry = 0; retry < 10; ++retry)
1535
- {
1536
- // hold ss51 & dsp
1537
- opr_buf[2] = 0x0C;
1538
- ret = gtp_i2c_write(ts->client, opr_buf, 3);
1539
- if (FAIL == ret)
1540
- {
1541
- GTP_ERROR("failed to hold ss51 & dsp!");
1542
- continue;
1543
- }
1544
- opr_buf[2] = 0x00;
1545
- ret = gtp_i2c_read(ts->client, opr_buf, 3);
1546
- if (FAIL == ret)
1547
- {
1548
- GTP_ERROR("failed to get ss51 & dsp status!");
1549
- continue;
1550
- }
1551
- if (0x0C != opr_buf[2])
1552
- {
1553
- GTP_DEBUG("ss51 & dsp not been hold, %d", retry+1);
1554
- continue;
1555
- }
1556
- GTP_DEBUG("ss51 & dsp confirmed hold");
1557
-
1558
- ret = gtp_fw_startup(ts->client);
1559
- if (FAIL == ret)
1560
- {
1561
- GTP_ERROR("failed to startup GT9XXF, process recovery");
1562
- gtp_esd_recovery(ts->client);
1563
- }
1564
- break;
1565
- }
1566
- if (retry >= 10)
1567
- {
1568
- GTP_ERROR("failed to wakeup, processing esd recovery");
1569
- gtp_esd_recovery(ts->client);
1570
- }
1571
- else
1572
- {
1573
- GTP_INFO("GT9XXF gtp wakeup success");
1574
- }
1575
- return ret;
1576
- }
1577
-#endif
1578
-//#if GTP_POWER_CTRL_SLEEP
1579
-if(gtp_power_ctrl_sleep)
1580
- while(retry++ < 5)
1581
- {
1582
- gtp_reset_guitar(ts->client, 20);
1583
-
1584
- GTP_INFO("GTP wakeup sleep.");
1585
- return 1;
1586
- }
1587
-//#else
1588
-else {
1589
- while(retry++ < 10)
1590
- {
1591
- //#if GTP_GESTURE_WAKEUP
1592
- if(gtp_gesture_wakeup){
1593
- if (DOZE_WAKEUP != doze_status)
1594
- {
1595
- GTP_INFO("Powerkey wakeup.");
1596
- }
1597
- else
1598
- {
1599
- GTP_INFO("Gesture wakeup.");
1600
- }
1601
- doze_status = DOZE_DISABLED;
1602
- gtp_irq_disable(ts);
1603
- gtp_reset_guitar(ts->client, 10);
1604
- gtp_irq_enable(ts);
1605
- }
1606
- else {
1607
- //#else
1608
- gtp_set_int_value(1);
1609
- msleep(5);
1610
- //#endif
1611
- }
1612
-
1613
- ret = gtp_i2c_test(ts->client);
1614
- if (ret > 0)
1615
- {
1616
- GTP_INFO("GTP wakeup sleep.");
1617
-
1618
- // #if (!GTP_GESTURE_WAKEUP)
1619
- if(!gtp_gesture_wakeup){
1620
- {
1621
- gtp_int_sync(25);
1622
- #if GTP_ESD_PROTECT
1623
- gtp_init_ext_watchdog(ts->client);
1624
- #endif
1625
- }
1626
- }
1627
- //#endif
1628
-
1629
- return ret;
1630
- }
1631
- gtp_reset_guitar(ts->client, 20);
1632
- }
1633
-}
1634
-//#endif
1635
-
1636
- GTP_ERROR("GTP wakeup sleep failed.");
1637
- return ret;
1638
-}
1639
-
1640
-
1641
-#if GTP_DRIVER_SEND_CFG
1642
-static s32 gtp_get_info(struct goodix_ts_data *ts)
1643
-{
1644
- u8 opr_buf[6] = {0};
1645
- s32 ret = 0;
1646
-
1647
- ts->abs_x_max = GTP_MAX_WIDTH;
1648
- ts->abs_y_max = GTP_MAX_HEIGHT;
1649
- ts->int_trigger_type = GTP_INT_TRIGGER;
1650
-
1651
- opr_buf[0] = (u8)((GTP_REG_CONFIG_DATA+1) >> 8);
1652
- opr_buf[1] = (u8)((GTP_REG_CONFIG_DATA+1) & 0xFF);
1653
-
1654
- ret = gtp_i2c_read(ts->client, opr_buf, 6);
1655
- if (ret < 0)
1656
- {
1657
- return FAIL;
1658
- }
1659
-
1660
- ts->abs_x_max = (opr_buf[3] << 8) + opr_buf[2];
1661
- ts->abs_y_max = (opr_buf[5] << 8) + opr_buf[4];
1662
-
1663
- opr_buf[0] = (u8)((GTP_REG_CONFIG_DATA+6) >> 8);
1664
- opr_buf[1] = (u8)((GTP_REG_CONFIG_DATA+6) & 0xFF);
1665
-
1666
- ret = gtp_i2c_read(ts->client, opr_buf, 3);
1667
- if (ret < 0)
1668
- {
1669
- return FAIL;
1670
- }
1671
- ts->int_trigger_type = opr_buf[2] & 0x03;
1672
-
1673
- GTP_INFO("X_MAX = %d, Y_MAX = %d, TRIGGER = 0x%02x",
1674
- ts->abs_x_max,ts->abs_y_max,ts->int_trigger_type);
1675
-
1676
- return SUCCESS;
1677
-}
1678
-#endif
1679
-
1680
-/*******************************************************
1681
-Function:
1682
- Initialize gtp.
1683
-Input:
1684
- ts: goodix private data
1685
-Output:
1686
- Executive outcomes.
1687
- 0: succeed, otherwise: failed
1688
-*******************************************************/
1689
-static s32 gtp_init_panel(struct goodix_ts_data *ts)
1690
-{
1691
- s32 ret = -1;
1692
-
1693
-#if GTP_DRIVER_SEND_CFG
1694
- s32 i = 0;
1695
- u8 check_sum = 0;
1696
- u8 opr_buf[16] = {0};
1697
- u8 sensor_id = 0;
1698
-
1699
- u8 cfg_info_group1[] = CTP_CFG_GROUP1;
1700
- u8 cfg_info_group2[] = CTP_CFG_GROUP2;
1701
- u8 cfg_info_group3[] = CTP_CFG_GROUP3;
1702
- u8 cfg_info_group4[] = CTP_CFG_GROUP4;
1703
- u8 cfg_info_group5[] = CTP_CFG_GROUP5;
1704
- u8 cfg_info_group6[] = CTP_CFG_GROUP6;
1705
- u8 cfg_info_group7[] = CTP_CFG_GROUP7;
1706
- u8 cfg_info_group8[] = CTP_CFG_GROUP8;
1707
-
1708
- u8 *send_cfg_buf[] = {cfg_info_group1, cfg_info_group2, cfg_info_group3,
1709
- cfg_info_group4, cfg_info_group5, cfg_info_group6,
1710
- cfg_info_group7, cfg_info_group8};
1711
- u8 cfg_info_len[] = { CFG_GROUP_LEN(cfg_info_group1),
1712
- CFG_GROUP_LEN(cfg_info_group2),
1713
- CFG_GROUP_LEN(cfg_info_group3),
1714
- CFG_GROUP_LEN(cfg_info_group4),
1715
- CFG_GROUP_LEN(cfg_info_group5),
1716
- CFG_GROUP_LEN(cfg_info_group6),
1717
- CFG_GROUP_LEN(cfg_info_group7),
1718
- CFG_GROUP_LEN(cfg_info_group8)};
1719
-
1720
- dprintk(DEBUG_INIT,"Config Groups Lengths: %d, %d, %d, %d, %d, %d, %d, %d\n",
1721
- cfg_info_len[0], cfg_info_len[1], cfg_info_len[2], cfg_info_len[3],
1722
- cfg_info_len[4], cfg_info_len[5], cfg_info_len[6], cfg_info_len[7]);
1723
-
1724
-#if GTP_COMPATIBLE_MODE
1725
- if (CHIP_TYPE_GT9F == ts->chip_type)
1726
- {
1727
- ts->fw_error = 0;
1728
- }
1729
- else
1730
-#endif
1731
- {
1732
- ret = gtp_i2c_read_dbl_check(ts->client, 0x41E4, opr_buf, 1);
1733
- if (SUCCESS == ret)
1734
- {
1735
- if (opr_buf[0] != 0xBE)
1736
- {
1737
- ts->fw_error = 1;
1738
- printk("Firmware error, no config sent!\n");
1739
- return -1;
1740
- }
1741
- }
1742
- }
1743
-
1744
- if ((!cfg_info_len[1]) && (!cfg_info_len[2]) &&
1745
- (!cfg_info_len[3]) && (!cfg_info_len[4]) &&
1746
- (!cfg_info_len[5]) && (!cfg_info_len[6]) &&
1747
- (!cfg_info_len[7]))
1748
- {
1749
- sensor_id = 0;
1750
- }
1751
- else
1752
- {
1753
- #if GTP_COMPATIBLE_MODE
1754
- msleep(50);
1755
- #endif
1756
- // ret = gtp_i2c_read_dbl_check(ts->client, GTP_REG_SENSOR_ID, &sensor_id, 1);
1757
- dprintk(DEBUG_INIT,"CTP name : %s\n",config_info.name);
1758
- if (!strcmp(config_info.name,"gt9271_mb976a9")){
1759
- sensor_id = 0;
1760
- dprintk(DEBUG_INIT,"gt9xx:sensor_id = %d\n",sensor_id);
1761
-
1762
- } else if (!strcmp(config_info.name,"gt9110_wt097")){
1763
- sensor_id = 1;
1764
- dprintk(DEBUG_INIT,"gt9xx:sensor_id = %d\n",sensor_id);
1765
-
1766
- } else if (!strcmp(config_info.name,"gt9271_wt097")){
1767
- sensor_id = 2;
1768
- dprintk(DEBUG_INIT,"gt9xx:sensor_id = %d\n",sensor_id);
1769
-
1770
- } else if (!strcmp(config_info.name,"gt9110_g200")){
1771
- sensor_id = 3;
1772
- dprintk(DEBUG_INIT,"gt9xx:sensor_id = %d\n",sensor_id);
1773
-
1774
- } else if (!strcmp(config_info.name,"gt9271_noah")){
1775
- sensor_id = 4;
1776
- dprintk(DEBUG_INIT,"gt9xx:sensor_id = %d\n",sensor_id);
1777
- } else if (!strcmp(config_info.name,"gt9271_p2")){
1778
- sensor_id = 5;
1779
- dprintk(DEBUG_INIT,"gt9xx:sensor_id = %d\n",sensor_id);
1780
- } else if (!strcmp(config_info.name, "gt911_1060")) {
1781
- sensor_id = 6;
1782
- dprintk(DEBUG_INIT,"gt9xx:sensor_id = %d\n",sensor_id);
1783
- } else if (!strcmp(config_info.name, "gt911_784")) {
1784
- sensor_id = 7;
1785
- dprintk(DEBUG_INIT,"gt9xx:sensor_id = %d\n",sensor_id);
1786
- } else {
1787
- sensor_id = 0;
1788
- dprintk(DEBUG_INIT,"gt9xx:sensor_id = %d\n",sensor_id);
715
+#if GTP_POWER_CTRL_SLEEP
716
+ while(retry++ < 5)
717
+ {
718
+ ret = gtp_send_cfg(ts->client);
719
+ if (ret > 0)
720
+ {
721
+ dprintk(DEBUG_SUSPEND, "Wakeup sleep send config success.");
722
+ return ret;
1789723 }
1790
- ret = SUCCESS;
1791
- if (SUCCESS == ret)
1792
- {
1793
- if (sensor_id >= 0x08)
1794
- {
1795
- printk("Invalid sensor_id(0x%02X), No Config Sent!\n", sensor_id);
1796
- ts->pnl_init_error = 1;
1797
- return -1;
1798
- }
1799
- }
1800
- else
1801
- {
1802
- printk("Failed to get sensor_id, No config sent!\n");
1803
- ts->pnl_init_error = 1;
1804
- return -1;
1805
- }
1806
- dprintk(DEBUG_INIT,"Sensor_ID: %d", sensor_id);
1807
- }
1808
- ts->gtp_cfg_len = cfg_info_len[sensor_id];
1809
- dprintk(DEBUG_INIT,"CTP_CONFIG_GROUP%d used, config length: %d\n", sensor_id + 1, ts->gtp_cfg_len);
724
+ }
1810725
1811
- if (ts->gtp_cfg_len < GTP_CONFIG_MIN_LENGTH)
1812
- {
1813
- printk("Config Group%d is INVALID CONFIG GROUP(Len: %d)! NO Config Sent! You need to check you header file CFG_GROUP section!\n", sensor_id+1, ts->gtp_cfg_len);
1814
- ts->pnl_init_error = 1;
1815
- return -1;
1816
- }
1817
-
1818
-#if GTP_COMPATIBLE_MODE
1819
- if (CHIP_TYPE_GT9F == ts->chip_type)
1820
- {
1821
- ts->fixed_cfg = 0;
1822
- }
1823
- else
726
+ printk("GTP wakeup sleep failed.");
727
+ return ret;
1824728 #endif
1825
- {
1826
- ret = gtp_i2c_read_dbl_check(ts->client, GTP_REG_CONFIG_DATA, &opr_buf[0], 1);
1827729
1828
- if (ret == SUCCESS)
1829
- {
1830
- dprintk(DEBUG_INIT,"CFG_GROUP%d Config Version: %d, 0x%02X; IC Config Version: %d, 0x%02X\n", sensor_id+1,
1831
- send_cfg_buf[sensor_id][0], send_cfg_buf[sensor_id][0], opr_buf[0], opr_buf[0]);
1832
-
1833
- if (opr_buf[0] < 155)
1834
- {
1835
- grp_cfg_version = send_cfg_buf[sensor_id][0]; // backup group config version
1836
- send_cfg_buf[sensor_id][0] = 0x00;
1837
- ts->fixed_cfg = 0;
1838
- }
1839
- else // treated as fixed config, not send config
1840
- {
1841
- dprintk(DEBUG_INIT,"Ic fixed config with config version(%d, 0x%02X)\n", opr_buf[0], opr_buf[0]);
1842
- ts->fixed_cfg = 1;
1843
- gtp_get_info(ts);
1844
- return 0;
1845
- }
1846
- }
1847
- else
1848
- {
1849
- printk("Failed to get ic config version!No config sent!\n");
1850
- return -1;
1851
- }
1852
- }
1853
-
1854
- memset(&config[GTP_ADDR_LENGTH], 0, GTP_CONFIG_MAX_LENGTH);
1855
- memcpy(&config[GTP_ADDR_LENGTH], send_cfg_buf[sensor_id], ts->gtp_cfg_len);
1856
-
1857
-#if GTP_CUSTOM_CFG
1858
- config[RESOLUTION_LOC] = (u8)GTP_MAX_WIDTH;
1859
- config[RESOLUTION_LOC + 1] = (u8)(GTP_MAX_WIDTH>>8);
1860
- config[RESOLUTION_LOC + 2] = (u8)GTP_MAX_HEIGHT;
1861
- config[RESOLUTION_LOC + 3] = (u8)(GTP_MAX_HEIGHT>>8);
1862
-
1863
- if (GTP_INT_TRIGGER == 0) //RISING
1864
- {
1865
- config[TRIGGER_LOC] &= 0xfe;
1866
- }
1867
- else if (GTP_INT_TRIGGER == 1) //FALLING
1868
- {
1869
- config[TRIGGER_LOC] |= 0x01;
1870
- }
1871
-#endif // GTP_CUSTOM_CFG
1872
-
1873
- check_sum = 0;
1874
- for (i = GTP_ADDR_LENGTH; i < ts->gtp_cfg_len; i++)
1875
- {
1876
- check_sum += config[i];
1877
- }
1878
- config[ts->gtp_cfg_len] = (~check_sum) + 1;
1879
-
1880
-#else // driver not send config
1881
-
1882
- ts->gtp_cfg_len = GTP_CONFIG_MAX_LENGTH;
1883
- ret = gtp_i2c_read(ts->client, config, ts->gtp_cfg_len + GTP_ADDR_LENGTH);
1884
- if (ret < 0)
1885
- {
1886
- GTP_ERROR("Read Config Failed, Using Default Resolution & INT Trigger!");
1887
- ts->abs_x_max = GTP_MAX_WIDTH;
1888
- ts->abs_y_max = GTP_MAX_HEIGHT;
1889
- ts->int_trigger_type = GTP_INT_TRIGGER;
1890
- }
1891
-
1892
-#endif // GTP_DRIVER_SEND_CFG
1893
-
1894
- if ((ts->abs_x_max == 0) && (ts->abs_y_max == 0))
1895
- {
1896
- ts->abs_x_max = (config[RESOLUTION_LOC + 1] << 8) + config[RESOLUTION_LOC];
1897
- ts->abs_y_max = (config[RESOLUTION_LOC + 3] << 8) + config[RESOLUTION_LOC + 2];
1898
- ts->int_trigger_type = (config[TRIGGER_LOC]) & 0x03;
1899
- }
1900
-
1901
-#if GTP_COMPATIBLE_MODE
1902
- if (CHIP_TYPE_GT9F == ts->chip_type)
1903
- {
1904
- u8 sensor_num = 0;
1905
- u8 driver_num = 0;
1906
- u8 have_key = 0;
1907
-
1908
- have_key = (config[GTP_REG_HAVE_KEY - GTP_REG_CONFIG_DATA + 2] & 0x01);
1909
-
1910
- if (1 == ts->is_950)
1911
- {
1912
- driver_num = config[GTP_REG_MATRIX_DRVNUM - GTP_REG_CONFIG_DATA + 2];
1913
- sensor_num = config[GTP_REG_MATRIX_SENNUM - GTP_REG_CONFIG_DATA + 2];
1914
- if (have_key)
1915
- {
1916
- driver_num--;
1917
- }
1918
- ts->bak_ref_len = (driver_num * (sensor_num - 1) + 2) * 2 * 6;
1919
- }
1920
- else
1921
- {
1922
- driver_num = (config[CFG_LOC_DRVA_NUM] & 0x1F) + (config[CFG_LOC_DRVB_NUM]&0x1F);
1923
- if (have_key)
1924
- {
1925
- driver_num--;
1926
- }
1927
- sensor_num = (config[CFG_LOC_SENS_NUM] & 0x0F) + ((config[CFG_LOC_SENS_NUM] >> 4) & 0x0F);
1928
- ts->bak_ref_len = (driver_num * (sensor_num - 2) + 2) * 2;
1929
- }
1930
-
1931
- GTP_INFO("Drv * Sen: %d * %d(key: %d), X_MAX: %d, Y_MAX: %d, TRIGGER: 0x%02x",
1932
- driver_num, sensor_num, have_key, ts->abs_x_max,ts->abs_y_max,ts->int_trigger_type);
1933
- return 0;
1934
- }
1935
- else
1936
-#endif
1937
- {
1938
- #if GTP_DRIVER_SEND_CFG
1939
- ret = gtp_send_cfg(ts->client);
1940
- if (ret < 0)
1941
- {
1942
- GTP_ERROR("Send config error.");
1943
- }
1944
- // set config version to CTP_CFG_GROUP, for resume to send config
1945
- config[GTP_ADDR_LENGTH] = grp_cfg_version;
1946
- check_sum = 0;
1947
- for (i = GTP_ADDR_LENGTH; i < ts->gtp_cfg_len; i++)
1948
- {
1949
- check_sum += config[i];
1950
- }
1951
- config[ts->gtp_cfg_len] = (~check_sum) + 1;
1952
- #endif
1953
- GTP_INFO("X_MAX: %d, Y_MAX: %d, TRIGGER: 0x%02x", ts->abs_x_max,ts->abs_y_max,ts->int_trigger_type);
1954
- }
1955
-
1956
- msleep(10);
1957
- return 0;
1958730 }
1959731
1960
-
1961
-static ssize_t gt91xx_config_read_proc(struct file *file, char __user *page, size_t size, loff_t *ppos)
1962
-{
1963
- char *ptr = page;
1964
- char temp_data[GTP_CONFIG_MAX_LENGTH + 2] = {0x80, 0x47};
1965
- int i;
1966
-
1967
- if (*ppos)
1968
- {
1969
- return 0;
1970
- }
1971
- ptr += sprintf(ptr, "==== GT9XX config init value====\n");
1972
-
1973
- for (i = 0 ; i < GTP_CONFIG_MAX_LENGTH ; i++)
1974
- {
1975
- ptr += sprintf(ptr, "0x%02X ", config[i + 2]);
1976
-
1977
- if (i % 8 == 7)
1978
- ptr += sprintf(ptr, "\n");
1979
- }
1980
-
1981
- ptr += sprintf(ptr, "\n");
1982
-
1983
- ptr += sprintf(ptr, "==== GT9XX config real value====\n");
1984
- gtp_i2c_read(i2c_connect_client, temp_data, GTP_CONFIG_MAX_LENGTH + 2);
1985
- for (i = 0 ; i < GTP_CONFIG_MAX_LENGTH ; i++)
1986
- {
1987
- ptr += sprintf(ptr, "0x%02X ", temp_data[i+2]);
1988
-
1989
- if (i % 8 == 7)
1990
- ptr += sprintf(ptr, "\n");
1991
- }
1992
- *ppos += ptr - page;
1993
- return (ptr - page);
1994
-}
1995
-
1996
-static ssize_t gt91xx_config_write_proc(struct file *filp, const char __user *buffer, size_t count, loff_t *off)
1997
-{
1998
- s32 ret = 0;
1999
-
2000
- GTP_DEBUG("write count %u\n", count);
2001
-
2002
- if (count > GTP_CONFIG_MAX_LENGTH)
2003
- {
2004
- GTP_ERROR("size not match [%d:%u]\n", GTP_CONFIG_MAX_LENGTH, count);
2005
- return -EFAULT;
2006
- }
2007
-
2008
- if (copy_from_user(&config[2], buffer, count))
2009
- {
2010
- GTP_ERROR("copy from user fail\n");
2011
- return -EFAULT;
2012
- }
2013
-
2014
- ret = gtp_send_cfg(i2c_connect_client);
2015
-
2016
- if (ret < 0)
2017
- {
2018
- GTP_ERROR("send config failed.");
2019
- }
2020
-
2021
- return count;
2022
-}
2023
-/*******************************************************
2024
-Function:
2025
- Read chip version.
2026
-Input:
2027
- client: i2c device
2028
- version: buffer to keep ic firmware version
2029
-Output:
2030
- read operation return.
2031
- 2: succeed, otherwise: failed
2032
-*******************************************************/
2033
-s32 gtp_read_version(struct i2c_client *client, u16* version)
2034
-{
2035
- s32 ret = -1;
2036
- u8 buf[8] = {GTP_REG_VERSION >> 8, GTP_REG_VERSION & 0xff};
2037
-
2038
- GTP_DEBUG_FUNC();
2039
-
2040
- ret = gtp_i2c_read(client, buf, sizeof(buf));
2041
- if (ret < 0)
2042
- {
2043
- GTP_ERROR("GTP read version failed");
2044
- return ret;
2045
- }
2046
-
2047
- if (version)
2048
- {
2049
- *version = (buf[7] << 8) | buf[6];
2050
- }
2051
- if (buf[5] == 0x00)
2052
- {
2053
- GTP_INFO("IC Version: %c%c%c_%02x%02x", buf[2], buf[3], buf[4], buf[7], buf[6]);
2054
- }
2055
- else
2056
- {
2057
- GTP_INFO("IC Version: %c%c%c%c_%02x%02x", buf[2], buf[3], buf[4], buf[5], buf[7], buf[6]);
2058
- }
2059
- return ret;
2060
-}
2061732
2062733 /*******************************************************
2063734 Function:
2064
- I2c test Function.
735
+GTP initialize function.
736
+
2065737 Input:
2066
- client:i2c client.
738
+ts: i2c client private struct.
739
+
2067740 Output:
2068
- Executive outcomes.
2069
- 2: succeed, otherwise failed.
2070
-*******************************************************/
2071
-static s8 gtp_i2c_test(struct i2c_client *client)
2072
-{
2073
- u8 test[3] = {GTP_REG_CONFIG_DATA >> 8, GTP_REG_CONFIG_DATA & 0xff};
2074
- u8 retry = 0;
2075
- s8 ret = -1;
2076
-
2077
- GTP_DEBUG_FUNC();
2078
-
2079
- while(retry++ < 5)
2080
- {
2081
- ret = gtp_i2c_read(client, test, 3);
2082
- if (ret > 0)
2083
- {
2084
- return ret;
2085
- }
2086
- GTP_ERROR("GTP i2c test failed time %d.",retry);
2087
- msleep(10);
2088
- }
2089
- return ret;
2090
-}
2091
-
2092
-/*******************************************************
2093
-Function:
2094
- Request interrupt.
2095
-Input:
2096
- ts: private data.
2097
-Output:
2098
- Executive outcomes.
2099
- 0: succeed, -1: failed.
2100
-*******************************************************/
2101
-static s8 gtp_request_irq(struct goodix_ts_data *ts)
741
+Executive outcomes.0---succeed.
742
+ *******************************************************/
743
+static s32 gtp_init_panel(struct goodix_ts_data *ts)
2102744 {
2103745 s32 ret = -1;
2104746
2105
- ret = input_request_int(&(config_info.input_type), goodix_ts_irq_handler, CTP_IRQ_MODE, ts);
747
+#if GTP_DRIVER_SEND_CFG
748
+ s32 i;
749
+ u8 check_sum = 0;
750
+ u8 rd_cfg_buf[16];
751
+ int index =0;
2106752
2107
- if (ret) {
2108
- GTP_ERROR("Request IRQ failed!ERRNO:%d.", ret);
2109
- gtp_set_int_value(0);
2110
- //input_free_int(&(config_info.input_type), ts);
753
+#if 1
754
+ u8 cfg_info_group1[] = CTP_CFG_GROUP1;
755
+ u8 cfg_info_group2[] = CTP_CFG_GROUP2;
756
+ u8 cfg_info_group3[] = CTP_CFG_GROUP3;
757
+ u8 cfg_info_group4[] = CTP_CFG_GROUP4;
758
+ u8 cfg_info_group5[] = CTP_CFG_GROUP5;
759
+ u8 cfg_info_group6[] = CTP_CFG_GROUP6;
760
+ // u8 cfg_info_group7[] = CTP_CFG_GROUP7;
761
+#else
762
+ u8 cfg_info_group1[] = {};
763
+ u8 cfg_info_group2[] = {};
764
+ u8 cfg_info_group3[] = {};
765
+ u8 cfg_info_group4[] = {};
766
+ u8 cfg_info_group5[] = {};
767
+ u8 cfg_info_group6[] = {};
768
+ // u8 cfg_info_group7[] = {};
769
+#endif
2111770
2112
- hrtimer_init(&ts->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
2113
- ts->timer.function = goodix_ts_timer_handler;
2114
- hrtimer_start(&ts->timer, ktime_set(1, 0), HRTIMER_MODE_REL);
2115
- return -1;
2116
- } else {
2117
- gtp_irq_disable(ts);
2118
- ts->use_irq = 1;
2119
- return 0;
771
+ u8 *send_cfg_buf[] = {cfg_info_group1,cfg_info_group2,cfg_info_group3,cfg_info_group4,cfg_info_group5,cfg_info_group6};
772
+ u8 cfg_info_len[] = {sizeof(cfg_info_group1)/sizeof(cfg_info_group1[0]),\
773
+ sizeof(cfg_info_group2)/sizeof(cfg_info_group2[0]),\
774
+ sizeof(cfg_info_group3)/sizeof(cfg_info_group3[0]),\
775
+ sizeof(cfg_info_group4)/sizeof(cfg_info_group4[0]),\
776
+ sizeof(cfg_info_group5)/sizeof(cfg_info_group5[0]),\
777
+ sizeof(cfg_info_group6)/sizeof(cfg_info_group6[0])};
778
+ //sizeof(cfg_info_group7)/sizeof(cfg_info_group7[0])};
779
+#if 0 //gandy
780
+for(i=0; i<3; i++)
781
+{
782
+ if(cfg_info_len[i] > ts->gtp_cfg_len)
783
+ {
784
+ ts->gtp_cfg_len = cfg_info_len[i];
2120785 }
2121786 }
787
+#endif
788
+
789
+GTP_DEBUG("len1=%d,len2=%d,len3=%d,send_len:%d",cfg_info_len[0],cfg_info_len[1],cfg_info_len[2],ts->gtp_cfg_len);
790
+#if 0
791
+if ((!cfg_info_len[1]) && (!cfg_info_len[2]))
792
+{
793
+ rd_cfg_buf[GTP_ADDR_LENGTH] = 0;
794
+}
795
+else
796
+#endif
797
+printk("gtp_i2c_read GTP_REG_SENSOR_ID \n");
798
+{
799
+ rd_cfg_buf[0] = GTP_REG_SENSOR_ID >> 8;
800
+ rd_cfg_buf[1] = GTP_REG_SENSOR_ID & 0xff;
801
+ ret = gtp_i2c_read(ts->client, rd_cfg_buf, 3);
802
+ if (ret < 0)
803
+ {
804
+ GTP_ERROR("Read SENSOR ID failed,default use group1 config!");
805
+ rd_cfg_buf[GTP_ADDR_LENGTH] = 0;
806
+ }
807
+ rd_cfg_buf[GTP_ADDR_LENGTH] &= 0x07;
808
+}
809
+
810
+#if 0
811
+if(screen_max_x == 800 && screen_max_y == 480)
812
+{
813
+ if(rd_cfg_buf[GTP_ADDR_LENGTH] == 3)
814
+ index = 0;
815
+ else if(rd_cfg_buf[GTP_ADDR_LENGTH] == 4)
816
+ index = 1;
817
+ else if(rd_cfg_buf[GTP_ADDR_LENGTH] == 5)
818
+ index = 3;
819
+ else if(rd_cfg_buf[GTP_ADDR_LENGTH] == 0)
820
+ index = 6;
821
+}
822
+else if(screen_max_x == 1024 && screen_max_y == 600)
823
+{
824
+ if(rd_cfg_buf[GTP_ADDR_LENGTH] == 0)
825
+ index = 5;
826
+ else if(rd_cfg_buf[GTP_ADDR_LENGTH] == 3)
827
+ index = 2;
828
+}
829
+#endif
830
+GTP_DEBUG("CTP name : %s\n",config_info.name);
831
+if (!strcmp(config_info.name,"gt911_805d5")){
832
+ index = 0;
833
+ GTP_DEBUG("gt9xx:index = %d\n",index);
834
+
835
+} else if (!strcmp(config_info.name,"gt911_g912")){
836
+ index = 2;
837
+ GTP_DEBUG("gt9xx:index = %d\n",index);
838
+
839
+} else if (!strcmp(config_info.name,"gt911_xw785")){
840
+ index = 3;
841
+ GTP_DEBUG("gt9xx:index = %d\n",index);
842
+
843
+} else {//default gt9xx_ts
844
+ index = 1; //default p4
845
+ GTP_DEBUG("gt9xx:index = %d\n",index);
846
+}
847
+
848
+printk("config send_cfg_buf******** \n");
849
+//index = rd_cfg_buf[GTP_ADDR_LENGTH];
850
+ts->gtp_cfg_len = cfg_info_len[index];
851
+GTP_DEBUG("gandy---SENSOR ID:%d\n", rd_cfg_buf[GTP_ADDR_LENGTH]);
852
+memset(&config[GTP_ADDR_LENGTH], 0, GTP_CONFIG_MAX_LENGTH);
853
+memcpy(&config[GTP_ADDR_LENGTH], send_cfg_buf[index], ts->gtp_cfg_len);
854
+
855
+#if GTP_CUSTOM_CFG
856
+config[RESOLUTION_LOC] = (u8)GTP_MAX_WIDTH;
857
+config[RESOLUTION_LOC + 1] = (u8)(GTP_MAX_WIDTH>>8);
858
+config[RESOLUTION_LOC + 2] = (u8)GTP_MAX_HEIGHT;
859
+config[RESOLUTION_LOC + 3] = (u8)(GTP_MAX_HEIGHT>>8);
860
+
861
+if (GTP_INT_TRIGGER == 0) //RISING
862
+{
863
+ config[TRIGGER_LOC] &= 0xfe;
864
+}
865
+else if (GTP_INT_TRIGGER == 1) //FALLING
866
+{
867
+ config[TRIGGER_LOC] |= 0x01;
868
+}
869
+#endif //endif GTP_CUSTOM_CFG
870
+
871
+check_sum = 0;
872
+for (i = GTP_ADDR_LENGTH; i < ts->gtp_cfg_len; i++)
873
+{
874
+ check_sum += config[i];
875
+}
876
+config[ts->gtp_cfg_len] = (~check_sum) + 1;
877
+
878
+#else //else DRIVER NEED NOT SEND CONFIG
879
+
880
+if(ts->gtp_cfg_len == 0)
881
+{
882
+ ts->gtp_cfg_len = GTP_CONFIG_MAX_LENGTH;
883
+}
884
+ret = gtp_i2c_read(ts->client, config, ts->gtp_cfg_len + GTP_ADDR_LENGTH);
885
+if (ret < 0)
886
+{
887
+ GTP_ERROR("GTP read resolution & max_touch_num failed, use default value!");
888
+ ts->abs_x_max = GTP_MAX_WIDTH;
889
+ ts->abs_y_max = GTP_MAX_HEIGHT;
890
+ ts->int_trigger_type = GTP_INT_TRIGGER;
891
+}
892
+#endif //endif GTP_DRIVER_SEND_CFG
893
+
894
+GTP_DEBUG_FUNC();
895
+
896
+ts->abs_x_max = (config[RESOLUTION_LOC + 1] << 8) + config[RESOLUTION_LOC];
897
+ts->abs_y_max = (config[RESOLUTION_LOC + 3] << 8) + config[RESOLUTION_LOC + 2];
898
+ts->int_trigger_type = (config[TRIGGER_LOC]) & 0x03;
899
+if ((!ts->abs_x_max)||(!ts->abs_y_max))
900
+{
901
+ GTP_ERROR("GTP resolution & max_touch_num invalid, use default value!");
902
+ ts->abs_x_max = GTP_MAX_WIDTH;
903
+ ts->abs_y_max = GTP_MAX_HEIGHT;
904
+}
905
+
906
+msleep(100);
907
+ret = gtp_send_cfg(ts->client);
908
+if (ret < 0)
909
+{
910
+ printk("\ngandy-----send config error.ret=%d\n",ret);
911
+ GTP_ERROR("Send config error.");
912
+}
913
+printk("X_MAX = %d,Y_MAX = %d,TRIGGER = 0x%02x",
914
+ ts->abs_x_max,ts->abs_y_max,ts->int_trigger_type);
915
+
916
+msleep(10);
917
+
918
+return 0;
919
+}
2122920
2123921 /*******************************************************
2124922 Function:
2125
- Request input device Function.
923
+Read goodix touchscreen version function.
924
+
2126925 Input:
2127
- ts:private data.
926
+client: i2c client struct.
927
+version:address to store version info
928
+
2128929 Output:
2129
- Executive outcomes.
2130
- 0: succeed, otherwise: failed.
2131
-*******************************************************/
930
+Executive outcomes.0---succeed.
931
+ *******************************************************/
932
+s32 gtp_read_version(struct i2c_client *client, u16* version)
933
+{
934
+ s32 ret = -1;
935
+ u8 buf[8] = {GTP_REG_VERSION >> 8, GTP_REG_VERSION & 0xff};
936
+
937
+ dprintk(DEBUG_INIT, "%s ---start!.---\n", __func__);
938
+
939
+ ret = gtp_i2c_read(client, buf, sizeof(buf));
940
+ if (ret < 0) {
941
+ printk("GTP read version failed");
942
+ return ret;
943
+ }
944
+
945
+ if (version) {
946
+ *version = (buf[7] << 8) | buf[6];
947
+ }
948
+
949
+ if (buf[5] == 0x00) {
950
+ printk("IC Version: %c%c%c_%02x%02x", buf[2], buf[3], buf[4], buf[7], buf[6]);
951
+ }
952
+ else {
953
+ printk("IC Version: %c%c%c%c_%02x%02x", buf[2], buf[3], buf[4], buf[5], buf[7], buf[6]);
954
+ }
955
+ return ret;
956
+}
957
+
958
+/*******************************************************
959
+Function:
960
+I2c test Function.
961
+
962
+Input:
963
+client:i2c client.
964
+
965
+Output:
966
+Executive outcomes.0--success,non-0--fail.
967
+ *******************************************************/
968
+static s8 gtp_i2c_test(struct i2c_client *client)
969
+{
970
+ u8 test[3] = {GTP_REG_CONFIG_DATA >> 8, GTP_REG_CONFIG_DATA & 0xff};
971
+ u8 retry = 0;
972
+ s8 ret = -1;
973
+
974
+ while(retry++ < 2) {
975
+ ret = gtp_i2c_read(client, test, 3);
976
+ if (ret > 0) {
977
+ return ret;
978
+ }
979
+ printk("GTP i2c test failed time %d.",retry);
980
+ msleep(10);
981
+ }
982
+ return ret;
983
+}
984
+
985
+
986
+/*******************************************************
987
+Function:
988
+Request input device Function.
989
+
990
+Input:
991
+ts:private data.
992
+
993
+Output:
994
+Executive outcomes.0--success,non-0--fail.
995
+ *******************************************************/
2132996 static s8 gtp_request_input_dev(struct goodix_ts_data *ts)
2133997 {
2134
- s8 ret = -1;
2135
- s8 phys[32];
2136
- u8 index = 0;
2137
-
2138
- GTP_DEBUG_FUNC();
2139
-
2140
- ts->input_dev = input_allocate_device();
2141
- if (ts->input_dev == NULL)
2142
- {
2143
- GTP_ERROR("Failed to allocate input device.");
2144
- return -ENOMEM;
2145
- }
2146
-
2147
- ts->input_dev->evbit[0] = BIT_MASK(EV_SYN) | BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS) ;
2148
-#if GTP_ICS_SLOT_REPORT
2149
- input_mt_init_slots(ts->input_dev, 16); // in case of "out of memory"
2150
-#else
2151
- ts->input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
998
+ s8 ret = -1;
999
+#if GTP_HAVE_TOUCH_KEY
1000
+ u8 index = 0;
21521001 #endif
2153
- __set_bit(INPUT_PROP_DIRECT, ts->input_dev->propbit);
1002
+
1003
+ ts->input_dev = input_allocate_device();
1004
+ if (ts->input_dev == NULL) {
1005
+ GTP_ERROR("Failed to allocate input device.");
1006
+ return -ENOMEM;
1007
+ }
1008
+
1009
+ ts->input_dev->evbit[0] = BIT_MASK(EV_SYN) | BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS) ;
1010
+#if GTP_ICS_SLOT_REPORT
1011
+ __set_bit(INPUT_PROP_DIRECT, ts->input_dev->propbit);
1012
+ input_mt_init_slots(ts->input_dev, 255, 1);
1013
+#else
1014
+ ts->input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
1015
+#endif
21541016
21551017 #if GTP_HAVE_TOUCH_KEY
2156
- for (index = 0; index < GTP_MAX_KEY_NUM; index++)
2157
- {
2158
- input_set_capability(ts->input_dev, EV_KEY, touch_key_array[index]);
2159
- }
1018
+ for (index = 0; index < GTP_MAX_KEY_NUM; index++) {
1019
+ input_set_capability(ts->input_dev,EV_KEY,touch_key_array[index]);
1020
+ }
21601021 #endif
21611022
2162
-//#if GTP_GESTURE_WAKEUP
2163
-if(gtp_gesture_wakeup)
2164
- input_set_capability(ts->input_dev, EV_KEY, KEY_POWER);
2165
- for (index = 0; index < KEY_NUM; index++)
2166
- {
2167
- input_set_capability(ts->input_dev, EV_KEY, ctp_key_list[index]);
2168
- }
2169
-//#endif
1023
+ //#if GTP_CHANGE_X2Y
1024
+ // GTP_SWAP(ts->abs_x_max, ts->abs_y_max);
1025
+ //#endif
21701026
2171
-if(1 == exchange_x_y_flag)
2172
- swap(ts->abs_x_max, ts->abs_y_max);
1027
+ set_bit(ABS_MT_POSITION_X, ts->input_dev->absbit);
1028
+ set_bit(ABS_MT_POSITION_Y, ts->input_dev->absbit);
1029
+ set_bit(ABS_MT_TOUCH_MAJOR, ts->input_dev->absbit);
1030
+ set_bit(ABS_MT_WIDTH_MAJOR, ts->input_dev->absbit);
21731031
21741032
2175
- input_set_abs_params(ts->input_dev, ABS_MT_POSITION_X, 0, ts->abs_x_max, 0, 0);
2176
- input_set_abs_params(ts->input_dev, ABS_MT_POSITION_Y, 0, ts->abs_y_max, 0, 0);
2177
- input_set_abs_params(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0, 255, 0, 0);
2178
- input_set_abs_params(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
2179
- input_set_abs_params(ts->input_dev, ABS_MT_TRACKING_ID, 0, 255, 0, 0);
21801033
2181
- sprintf(phys, "input/ts");
2182
- ts->input_dev->name = CTP_NAME;
2183
- ts->input_dev->phys = phys;
2184
- ts->input_dev->id.bustype = BUS_I2C;
2185
- ts->input_dev->id.vendor = 0xDEAD;
2186
- ts->input_dev->id.product = 0xBEEF;
2187
- ts->input_dev->id.version = 10427;
1034
+ input_set_abs_params(ts->input_dev, ABS_MT_POSITION_X, 0, SCREEN_MAX_X, 0, 0);
1035
+ input_set_abs_params(ts->input_dev, ABS_MT_POSITION_Y, 0, SCREEN_MAX_Y, 0, 0);
1036
+ input_set_abs_params(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0, 255, 0, 0);
1037
+ input_set_abs_params(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
1038
+ input_set_abs_params(ts->input_dev, ABS_MT_TRACKING_ID, 0, 255, 0, 0);
1039
+ __set_bit(INPUT_PROP_DIRECT, ts->input_dev->propbit);
21881040
2189
- ret = input_register_device(ts->input_dev);
2190
- if (ret)
2191
- {
2192
- GTP_ERROR("Register %s input device failed", ts->input_dev->name);
2193
- return -ENODEV;
2194
- }
2195
- ret = sysfs_create_group(&ts->input_dev->dev.kobj, &gtp_attribute_group);
2196
- if(ret) {
2197
- GTP_ERROR("create sys failed\n");
2198
- }
2199
-
1041
+ ts->input_dev->name = CTP_NAME;
1042
+ ts->input_dev->phys = "input/goodix-ts";
1043
+ ts->input_dev->id.bustype = BUS_I2C;
1044
+ ts->input_dev->id.vendor = 0xDEAD;
1045
+ ts->input_dev->id.product = 0xBEEF;
1046
+ ts->input_dev->id.version = 10427;
1047
+ ret = input_register_device(ts->input_dev);
1048
+ if (ret) {
1049
+ printk("Register %s input device failed", ts->input_dev->name);
1050
+ return -ENODEV;
1051
+ }
22001052 #ifdef CONFIG_HAS_EARLYSUSPEND
2201
- ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
2202
- ts->early_suspend.suspend = goodix_ts_early_suspend;
2203
- ts->early_suspend.resume = goodix_ts_late_resume;
2204
- register_early_suspend(&ts->early_suspend);
1053
+ ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
1054
+ ts->early_suspend.suspend = goodix_ts_early_suspend;
1055
+ ts->early_suspend.resume = goodix_ts_late_resume;
1056
+ register_early_suspend(&ts->early_suspend);
22051057 #endif
2206
-
2207
-#if GTP_WITH_PEN
2208
- gtp_pen_init(ts);
2209
-#endif
2210
-
2211
- return 0;
1058
+ return 0;
22121059 }
22131060
2214
-//************** For GT9XXF Start *************//
2215
-#if GTP_COMPATIBLE_MODE
2216
-
2217
-s32 gtp_fw_startup(struct i2c_client *client)
2218
-{
2219
- u8 opr_buf[4];
2220
- s32 ret = 0;
2221
-
2222
- //init sw WDT
2223
- opr_buf[0] = 0xAA;
2224
- ret = i2c_write_bytes(client, 0x8041, opr_buf, 1);
2225
- if (ret < 0)
2226
- {
2227
- return FAIL;
2228
- }
2229
-
2230
- //release SS51 & DSP
2231
- opr_buf[0] = 0x00;
2232
- ret = i2c_write_bytes(client, 0x4180, opr_buf, 1);
2233
- if (ret < 0)
2234
- {
2235
- return FAIL;
2236
- }
2237
- //int sync
2238
- gtp_int_sync(25);
2239
-
2240
- //check fw run status
2241
- ret = i2c_read_bytes(client, 0x8041, opr_buf, 1);
2242
- if (ret < 0)
2243
- {
2244
- return FAIL;
2245
- }
2246
- if(0xAA == opr_buf[0])
2247
- {
2248
- GTP_ERROR("IC works abnormally,startup failed.");
2249
- return FAIL;
2250
- }
2251
- else
2252
- {
2253
- GTP_INFO("IC works normally, Startup success.");
2254
- opr_buf[0] = 0xAA;
2255
- i2c_write_bytes(client, 0x8041, opr_buf, 1);
2256
- return SUCCESS;
2257
- }
2258
-}
2259
-
2260
-static s32 gtp_esd_recovery(struct i2c_client *client)
2261
-{
2262
- s32 retry = 0;
2263
- s32 ret = 0;
2264
- struct goodix_ts_data *ts;
2265
-
2266
- ts = i2c_get_clientdata(client);
2267
-
2268
- gtp_irq_disable(ts);
2269
-
2270
- GTP_INFO("GT9XXF esd recovery mode");
2271
- for (retry = 0; retry < 5; retry++)
2272
- {
2273
- ret = gup_fw_download_proc(NULL, GTP_FL_ESD_RECOVERY);
2274
- if (FAIL == ret)
2275
- {
2276
- GTP_ERROR("esd recovery failed %d", retry+1);
2277
- continue;
2278
- }
2279
- ret = gtp_fw_startup(ts->client);
2280
- if (FAIL == ret)
2281
- {
2282
- GTP_ERROR("GT9XXF start up failed %d", retry+1);
2283
- continue;
2284
- }
2285
- break;
2286
- }
2287
- gtp_irq_enable(ts);
2288
-
2289
- if (retry >= 5)
2290
- {
2291
- GTP_ERROR("failed to esd recovery");
2292
- return FAIL;
2293
- }
2294
-
2295
- GTP_INFO("Esd recovery successful");
2296
- return SUCCESS;
2297
-}
2298
-
2299
-void gtp_recovery_reset(struct i2c_client *client)
2300
-{
2301
-#if GTP_ESD_PROTECT
2302
- gtp_esd_switch(client, SWITCH_OFF);
2303
-#endif
2304
- GTP_DEBUG_FUNC();
2305
-
2306
- gtp_esd_recovery(client);
2307
-
2308
-#if GTP_ESD_PROTECT
2309
- gtp_esd_switch(client, SWITCH_ON);
2310
-#endif
2311
-}
2312
-
2313
-static s32 gtp_bak_ref_proc(struct goodix_ts_data *ts, u8 mode)
2314
-{
2315
- s32 ret = 0;
2316
- s32 i = 0;
2317
- s32 j = 0;
2318
- u16 ref_sum = 0;
2319
- u16 learn_cnt = 0;
2320
- u16 chksum = 0;
2321
- s32 ref_seg_len = 0;
2322
- s32 ref_grps = 0;
2323
- struct file *ref_filp = NULL;
2324
- u8 *p_bak_ref;
2325
-
2326
- ret = gup_check_fs_mounted("/data");
2327
- if (FAIL == ret)
2328
- {
2329
- ts->ref_chk_fs_times++;
2330
- GTP_DEBUG("Ref check /data times/MAX_TIMES: %d / %d", ts->ref_chk_fs_times, GTP_CHK_FS_MNT_MAX);
2331
- if (ts->ref_chk_fs_times < GTP_CHK_FS_MNT_MAX)
2332
- {
2333
- msleep(50);
2334
- GTP_INFO("/data not mounted.");
2335
- return FAIL;
2336
- }
2337
- GTP_INFO("check /data mount timeout...");
2338
- }
2339
- else
2340
- {
2341
- GTP_INFO("/data mounted!!!(%d/%d)", ts->ref_chk_fs_times, GTP_CHK_FS_MNT_MAX);
2342
- }
2343
-
2344
- p_bak_ref = (u8 *)kzalloc(ts->bak_ref_len, GFP_KERNEL);
2345
-
2346
- if (NULL == p_bak_ref)
2347
- {
2348
- GTP_ERROR("Allocate memory for p_bak_ref failed!");
2349
- return FAIL;
2350
- }
2351
-
2352
- if (ts->is_950)
2353
- {
2354
- ref_seg_len = ts->bak_ref_len / 6;
2355
- ref_grps = 6;
2356
- }
2357
- else
2358
- {
2359
- ref_seg_len = ts->bak_ref_len;
2360
- ref_grps = 1;
2361
- }
2362
- ref_filp = filp_open(GTP_BAK_REF_PATH, O_RDWR | O_CREAT, 0666);
2363
- if (IS_ERR(ref_filp))
2364
- {
2365
- GTP_ERROR("Failed to open/create %s.", GTP_BAK_REF_PATH);
2366
- if (GTP_BAK_REF_SEND == mode)
2367
- {
2368
- goto bak_ref_default;
2369
- }
2370
- else
2371
- {
2372
- goto bak_ref_exit;
2373
- }
2374
- }
2375
-
2376
- switch (mode)
2377
- {
2378
- case GTP_BAK_REF_SEND:
2379
- GTP_INFO("Send backup-reference");
2380
- ref_filp->f_op->llseek(ref_filp, 0, SEEK_SET);
2381
- ret = ref_filp->f_op->read(ref_filp, (char*)p_bak_ref, ts->bak_ref_len, &ref_filp->f_pos);
2382
- if (ret < 0)
2383
- {
2384
- GTP_ERROR("failed to read bak_ref info from file, sending defualt bak_ref");
2385
- goto bak_ref_default;
2386
- }
2387
- for (j = 0; j < ref_grps; ++j)
2388
- {
2389
- ref_sum = 0;
2390
- for (i = 0; i < (ref_seg_len); i += 2)
2391
- {
2392
- ref_sum += (p_bak_ref[i + j * ref_seg_len] << 8) + p_bak_ref[i+1 + j * ref_seg_len];
2393
- }
2394
- learn_cnt = (p_bak_ref[j * ref_seg_len + ref_seg_len -4] << 8) + (p_bak_ref[j * ref_seg_len + ref_seg_len -3]);
2395
- chksum = (p_bak_ref[j * ref_seg_len + ref_seg_len -2] << 8) + (p_bak_ref[j * ref_seg_len + ref_seg_len -1]);
2396
- GTP_DEBUG("learn count = %d", learn_cnt);
2397
- GTP_DEBUG("chksum = %d", chksum);
2398
- GTP_DEBUG("ref_sum = 0x%04X", ref_sum & 0xFFFF);
2399
- // Sum(1~ref_seg_len) == 1
2400
- if (1 != ref_sum)
2401
- {
2402
- GTP_INFO("wrong chksum for bak_ref, reset to 0x00 bak_ref");
2403
- memset(&p_bak_ref[j * ref_seg_len], 0, ref_seg_len);
2404
- p_bak_ref[ref_seg_len + j * ref_seg_len - 1] = 0x01;
2405
- }
2406
- else
2407
- {
2408
- if (j == (ref_grps - 1))
2409
- {
2410
- GTP_INFO("backup-reference data in %s used", GTP_BAK_REF_PATH);
2411
- }
2412
- }
2413
- }
2414
- ret = i2c_write_bytes(ts->client, GTP_REG_BAK_REF, p_bak_ref, ts->bak_ref_len);
2415
- if (FAIL == ret)
2416
- {
2417
- GTP_ERROR("failed to send bak_ref because of iic comm error");
2418
- goto bak_ref_exit;
2419
- }
2420
- break;
2421
-
2422
- case GTP_BAK_REF_STORE:
2423
- GTP_INFO("Store backup-reference");
2424
- ret = i2c_read_bytes(ts->client, GTP_REG_BAK_REF, p_bak_ref, ts->bak_ref_len);
2425
- if (ret < 0)
2426
- {
2427
- GTP_ERROR("failed to read bak_ref info, sending default back-reference");
2428
- goto bak_ref_default;
2429
- }
2430
- ref_filp->f_op->llseek(ref_filp, 0, SEEK_SET);
2431
- ref_filp->f_op->write(ref_filp, (char*)p_bak_ref, ts->bak_ref_len, &ref_filp->f_pos);
2432
- break;
2433
-
2434
- default:
2435
- GTP_ERROR("invalid backup-reference request");
2436
- break;
2437
- }
2438
- ret = SUCCESS;
2439
- goto bak_ref_exit;
2440
-
2441
-bak_ref_default:
2442
-
2443
- for (j = 0; j < ref_grps; ++j)
2444
- {
2445
- memset(&p_bak_ref[j * ref_seg_len], 0, ref_seg_len);
2446
- p_bak_ref[j * ref_seg_len + ref_seg_len - 1] = 0x01; // checksum = 1
2447
- }
2448
- ret = i2c_write_bytes(ts->client, GTP_REG_BAK_REF, p_bak_ref, ts->bak_ref_len);
2449
- if (!IS_ERR(ref_filp))
2450
- {
2451
- GTP_INFO("write backup-reference data into %s", GTP_BAK_REF_PATH);
2452
- ref_filp->f_op->llseek(ref_filp, 0, SEEK_SET);
2453
- ref_filp->f_op->write(ref_filp, (char*)p_bak_ref, ts->bak_ref_len, &ref_filp->f_pos);
2454
- }
2455
- if (ret == FAIL)
2456
- {
2457
- GTP_ERROR("failed to load the default backup reference");
2458
- }
2459
-
2460
-bak_ref_exit:
2461
-
2462
- if (p_bak_ref)
2463
- {
2464
- kfree(p_bak_ref);
2465
- }
2466
- if (ref_filp && !IS_ERR(ref_filp))
2467
- {
2468
- filp_close(ref_filp, NULL);
2469
- }
2470
- return ret;
2471
-}
2472
-
2473
-
2474
-static s32 gtp_verify_main_clk(u8 *p_main_clk)
2475
-{
2476
- u8 chksum = 0;
2477
- u8 main_clock = p_main_clk[0];
2478
- s32 i = 0;
2479
-
2480
- if (main_clock < 50 || main_clock > 120)
2481
- {
2482
- return FAIL;
2483
- }
2484
-
2485
- for (i = 0; i < 5; ++i)
2486
- {
2487
- if (main_clock != p_main_clk[i])
2488
- {
2489
- return FAIL;
2490
- }
2491
- chksum += p_main_clk[i];
2492
- }
2493
- chksum += p_main_clk[5];
2494
- if ( (chksum) == 0)
2495
- {
2496
- return SUCCESS;
2497
- }
2498
- else
2499
- {
2500
- return FAIL;
2501
- }
2502
-}
2503
-
2504
-static s32 gtp_main_clk_proc(struct goodix_ts_data *ts)
2505
-{
2506
- s32 ret = 0;
2507
- s32 i = 0;
2508
- s32 clk_chksum = 0;
2509
- struct file *clk_filp = NULL;
2510
- u8 p_main_clk[6] = {0};
2511
-
2512
- ret = gup_check_fs_mounted("/data");
2513
- if (FAIL == ret)
2514
- {
2515
- ts->clk_chk_fs_times++;
2516
- GTP_DEBUG("Clock check /data times/MAX_TIMES: %d / %d", ts->clk_chk_fs_times, GTP_CHK_FS_MNT_MAX);
2517
- if (ts->clk_chk_fs_times < GTP_CHK_FS_MNT_MAX)
2518
- {
2519
- msleep(50);
2520
- GTP_INFO("/data not mounted.");
2521
- return FAIL;
2522
- }
2523
- GTP_INFO("Check /data mount timeout!");
2524
- }
2525
- else
2526
- {
2527
- GTP_INFO("/data mounted!!!(%d/%d)", ts->clk_chk_fs_times, GTP_CHK_FS_MNT_MAX);
2528
- }
2529
-
2530
- clk_filp = filp_open(GTP_MAIN_CLK_PATH, O_RDWR | O_CREAT, 0666);
2531
- if (IS_ERR(clk_filp))
2532
- {
2533
- GTP_ERROR("%s is unavailable, calculate main clock", GTP_MAIN_CLK_PATH);
2534
- }
2535
- else
2536
- {
2537
- clk_filp->f_op->llseek(clk_filp, 0, SEEK_SET);
2538
- clk_filp->f_op->read(clk_filp, (char *)p_main_clk, 6, &clk_filp->f_pos);
2539
-
2540
- ret = gtp_verify_main_clk(p_main_clk);
2541
- if (FAIL == ret)
2542
- {
2543
- // recalculate main clock & rewrite main clock data to file
2544
- GTP_ERROR("main clock data in %s is wrong, recalculate main clock", GTP_MAIN_CLK_PATH);
2545
- }
2546
- else
2547
- {
2548
- GTP_INFO("main clock data in %s used, main clock freq: %d", GTP_MAIN_CLK_PATH, p_main_clk[0]);
2549
- filp_close(clk_filp, NULL);
2550
- goto update_main_clk;
2551
- }
2552
- }
2553
-
2554
-#if GTP_ESD_PROTECT
2555
- gtp_esd_switch(ts->client, SWITCH_OFF);
2556
-#endif
2557
- ret = gup_clk_calibration();
2558
- gtp_esd_recovery(ts->client);
2559
-
2560
-#if GTP_ESD_PROTECT
2561
- gtp_esd_switch(ts->client, SWITCH_ON);
2562
-#endif
2563
-
2564
- GTP_INFO("calibrate main clock: %d", ret);
2565
- if (ret < 50 || ret > 120)
2566
- {
2567
- GTP_ERROR("wrong main clock: %d", ret);
2568
- goto exit_main_clk;
2569
- }
2570
-
2571
- // Sum{0x8020~0x8025} = 0
2572
- for (i = 0; i < 5; ++i)
2573
- {
2574
- p_main_clk[i] = ret;
2575
- clk_chksum += p_main_clk[i];
2576
- }
2577
- p_main_clk[5] = 0 - clk_chksum;
2578
-
2579
- if (!IS_ERR(clk_filp))
2580
- {
2581
- GTP_DEBUG("write main clock data into %s", GTP_MAIN_CLK_PATH);
2582
- clk_filp->f_op->llseek(clk_filp, 0, SEEK_SET);
2583
- clk_filp->f_op->write(clk_filp, (char *)p_main_clk, 6, &clk_filp->f_pos);
2584
- filp_close(clk_filp, NULL);
2585
- }
2586
-
2587
-update_main_clk:
2588
- ret = i2c_write_bytes(ts->client, GTP_REG_MAIN_CLK, p_main_clk, 6);
2589
- if (FAIL == ret)
2590
- {
2591
- GTP_ERROR("update main clock failed!");
2592
- return FAIL;
2593
- }
2594
- return SUCCESS;
2595
-
2596
-exit_main_clk:
2597
- if (!IS_ERR(clk_filp))
2598
- {
2599
- filp_close(clk_filp, NULL);
2600
- }
2601
- return FAIL;
2602
-}
2603
-
2604
-
2605
-s32 gtp_gt9xxf_init(struct i2c_client *client)
2606
-{
2607
- s32 ret = 0;
2608
-
2609
- ret = gup_fw_download_proc(NULL, GTP_FL_FW_BURN);
2610
- if (FAIL == ret)
2611
- {
2612
- return FAIL;
2613
- }
2614
-
2615
- ret = gtp_fw_startup(client);
2616
- if (FAIL == ret)
2617
- {
2618
- return FAIL;
2619
- }
2620
- return SUCCESS;
2621
-}
2622
-
2623
-void gtp_get_chip_type(struct goodix_ts_data *ts)
2624
-{
2625
- u8 opr_buf[10] = {0x00};
2626
- s32 ret = 0;
2627
-
2628
- msleep(10);
2629
-
2630
- ret = gtp_i2c_read_dbl_check(ts->client, GTP_REG_CHIP_TYPE, opr_buf, 10);
2631
-
2632
- if (FAIL == ret)
2633
- {
2634
- GTP_ERROR("Failed to get chip-type, set chip type default: GOODIX_GT9");
2635
- ts->chip_type = CHIP_TYPE_GT9;
2636
- return;
2637
- }
2638
-
2639
- if (!memcmp(opr_buf, "GOODIX_GT9", 10))
2640
- {
2641
- ts->chip_type = CHIP_TYPE_GT9;
2642
- }
2643
- else // GT9XXF
2644
- {
2645
- ts->chip_type = CHIP_TYPE_GT9F;
2646
- }
2647
- GTP_INFO("Chip Type: %s", (ts->chip_type == CHIP_TYPE_GT9) ? "GOODIX_GT9" : "GOODIX_GT9F");
2648
-}
2649
-
2650
-#endif
2651
-//************* For GT9XXF End ************//
26521061
26531062 /*******************************************************
26541063 Function:
2655
- I2c probe.
1064
+Goodix touchscreen probe function.
1065
+
26561066 Input:
2657
- client: i2c device struct.
2658
- id: device id.
1067
+client: i2c device struct.
1068
+id:device id.
1069
+
26591070 Output:
2660
- Executive outcomes.
2661
- 0: succeed.
2662
-*******************************************************/
1071
+Executive outcomes. 0---succeed.
1072
+ *******************************************************/
26631073 static int goodix_ts_probe(struct i2c_client *client, const struct i2c_device_id *id)
26641074 {
2665
- s32 ret = -1;
2666
- struct goodix_ts_data *ts;
2667
- u16 version_info;
1075
+ s32 ret = -1;
1076
+ struct goodix_ts_data *ts;
1077
+ u16 version_info;
26681078
2669
- //do NOT remove these logs
2670
- dprintk(DEBUG_INIT,"GTP Driver Version: %s", GTP_DRIVER_VERSION);
2671
- dprintk(DEBUG_INIT,"GTP I2C Address: 0x%02x", client->addr);
2672
- config_info.probed = 0;
1079
+ dprintk(DEBUG_INIT, "GTP Driver Version:%s\n",GTP_DRIVER_VERSION);
1080
+ printk("GTP I2C Address:0x%02x\n", client->addr);
26731081
2674
- i2c_connect_client = client;
2675
-
1082
+ i2c_connect_client = client;
26761083 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
26771084 printk("I2C check functionality failed.\n");
26781085 return -ENODEV;
26791086 }
2680
- if (config_info.dev == NULL)
2681
- config_info.dev = &client->dev;
26821087
2683
-#if !USE_DETECT
2684
- if (!gUseDetect && startup()) {
2685
- printk("can not startup device!\n");
2686
- goto fail;
2687
- }
2688
-#endif
26891088 ts = kzalloc(sizeof(*ts), GFP_KERNEL);
26901089 if (ts == NULL) {
26911090 printk("Alloc GFP_KERNEL memory failed.\n");
2692
- goto fail;
1091
+ return -ENOMEM;
26931092 }
26941093
2695
- memset(ts, 0, sizeof(*ts));
2696
- INIT_WORK(&ts->work, goodix_ts_work_func);
2697
- ts->client = client;
2698
- spin_lock_init(&ts->irq_lock); // 2.6.39 later
2699
- // ts->irq_lock = SPIN_LOCK_UNLOCKED; // 2.6.39 & before
2700
-#if GTP_ESD_PROTECT
2701
- ts->clk_tick_cnt = 2 * HZ; // HZ: clock ticks in 1 second generated by system
2702
- GTP_DEBUG("Clock ticks for an esd cycle: %d", ts->clk_tick_cnt);
2703
- spin_lock_init(&ts->esd_lock);
2704
- // ts->esd_lock = SPIN_LOCK_UNLOCKED;
2705
-#endif
2706
- i2c_set_clientdata(client, ts);
1094
+ memset(ts, 0, sizeof(*ts));
1095
+ INIT_WORK(&ts->work, goodix_ts_work_func);
1096
+ ts->client = client;
1097
+ i2c_set_clientdata(client, ts);
1098
+ //ts->irq_lock = SPIN_LOCK_UNLOCKED;
1099
+ ts->gtp_rawdiff_mode = 0;
27071100
2708
- ts->gtp_rawdiff_mode = 0;
2709
- ts->gtp_is_suspend = 0;
27101101
2711
-#if GTP_COMPATIBLE_MODE
2712
- gtp_get_chip_type(ts);
2713
-
2714
- if (CHIP_TYPE_GT9F == ts->chip_type)
2715
- {
2716
- ret = gtp_gt9xxf_init(ts->client);
2717
- if (FAIL == ret)
2718
- {
2719
- printk("Failed to init GT9XXF.");
2720
- }
2721
- }
2722
-#endif
2723
-#if GTP_I2C_TEST
2724
- ret = gtp_i2c_test(client);
2725
- if (ret < 0)
2726
- {
2727
- printk("I2C communication ERROR!");
2728
- goto fail;
2729
- }
2730
-#endif
2731
- ret = gtp_read_version(client, &version_info);
2732
- if (ret < 0) {
2733
- printk("Read version failed.");
1102
+ ret = gtp_i2c_test(client);
1103
+ if (ret < 0){
1104
+ printk("I2C communication ERROR!\n");
1105
+ goto exit_device_detect;
27341106 }
27351107
2736
- ret = gtp_init_panel(ts);
2737
- if (ret < 0)
2738
- {
2739
- printk("GTP init panel failed.");
2740
- }
1108
+ printk(KERN_ALERT "create_singlethread_workqueue goodix_resume.\n");
1109
+ goodix_resume_wq = create_singlethread_workqueue("goodix_resume");
1110
+ if (goodix_resume_wq == NULL) {
1111
+ printk("create goodix_resume_wq fail!\n");
1112
+ return -ENOMEM;
1113
+ }
27411114
2742
- // Create proc file system
2743
- gt91xx_config_proc = proc_create(GT91XX_CONFIG_PROC_FILE, 0666, NULL, &config_proc_ops);
2744
- if (gt91xx_config_proc == NULL)
2745
- {
2746
- GTP_ERROR("create_proc_entry %s failed\n", GT91XX_CONFIG_PROC_FILE);
2747
- }
2748
- else
2749
- {
2750
- GTP_INFO("create proc entry %s success", GT91XX_CONFIG_PROC_FILE);
2751
- }
1115
+ printk(KERN_ALERT "create_singlethread_workqueue goodix_wq.\n");
1116
+
1117
+ goodix_wq = create_singlethread_workqueue("goodix_wq");
1118
+ if (!goodix_wq) {
1119
+ printk(KERN_ALERT "Creat goodix_wq workqueue failed.\n");
1120
+ return -ENOMEM;
1121
+ }
27521122
27531123 #if GTP_AUTO_UPDATE
2754
- ret = gup_init_update_proc(ts);
2755
- if (ret < 0)
2756
- {
2757
- GTP_ERROR("Create update thread error.");
2758
- }
1124
+ //ret = gup_init_update_proc(ts);
1125
+ // if (ret < 0) {
1126
+ // printk("Create update thread error.");
1127
+ // }
27591128 #endif
1129
+ ret = gtp_init_panel(ts);
1130
+ if (ret < 0) {
1131
+ printk("GTP init panel failed.\n");
1132
+ }
1133
+
27601134
27611135 ret = gtp_request_input_dev(ts);
27621136 if (ret < 0) {
2763
- GTP_ERROR("GTP request input dev failed");
1137
+ printk("GTP request input dev failed\n");
1138
+ goto exit_device_detect;
27641139 }
27651140
2766
- ret = gtp_request_irq(ts);
2767
- if (ret < 0)
2768
- {
2769
- GTP_INFO("GTP works in polling mode.");
2770
- }
2771
- else
2772
- {
2773
- GTP_INFO("GTP works in interrupt mode.");
2774
- }
1141
+ ret = gtp_read_version(client, &version_info);
1142
+ if (ret < 0) {
1143
+ printk("Read version failed.");
1144
+ }
27751145
2776
- if (ts->use_irq)
2777
- {
2778
- gtp_irq_enable(ts);
2779
- }
1146
+ config_info.dev = &(ts->input_dev->dev);
1147
+
1148
+ ret = input_request_int(&(config_info.input_type), goodix_ts_irq_handler,CTP_IRQ_MODE, ts);
1149
+ if (ret) {
1150
+ printk("Request irq fail!.\n");
1151
+ }
1152
+
1153
+
1154
+ spin_lock_init(&ts->irq_lock);
27801155
27811156 #if GTP_CREATE_WR_NODE
2782
- init_wr_node(client);
1157
+ init_wr_node(client);
27831158 #endif
27841159
27851160 #if GTP_ESD_PROTECT
2786
- gtp_esd_switch(client, SWITCH_ON);
1161
+ INIT_DELAYED_WORK(&gtp_esd_check_work, gtp_esd_check_func);
1162
+ gtp_esd_check_workqueue = create_workqueue("gtp_esd_check");
1163
+ queue_delayed_work(gtp_esd_check_workqueue, &gtp_esd_check_work, GTP_ESD_CHECK_CIRCLE);
27871164 #endif
2788
-
2789
- pm_runtime_set_active(&client->dev);
2790
- pm_runtime_get(&client->dev);
2791
- pm_runtime_enable(&client->dev);
2792
- config_info.probed = 1;
2793
-
2794
- return 0;
2795
-
2796
-fail:
2797
- input_sensor_free(&(config_info.input_type));
2798
- return -1;
1165
+ dprintk(DEBUG_INIT, "gt9xx probe success!\n");
1166
+ return 0;
1167
+exit_device_detect:
1168
+ i2c_set_clientdata(client, NULL);
1169
+ kfree(ts);
1170
+ return ret;
27991171 }
28001172
28011173
28021174 /*******************************************************
28031175 Function:
2804
- Goodix touchscreen driver release function.
1176
+Goodix touchscreen driver release function.
1177
+
28051178 Input:
2806
- client: i2c device struct.
1179
+client: i2c device struct.
1180
+
28071181 Output:
2808
- Executive outcomes. 0---succeed.
2809
-*******************************************************/
1182
+Executive outcomes. 0---succeed.
1183
+ *******************************************************/
28101184 static int goodix_ts_remove(struct i2c_client *client)
28111185 {
2812
- struct goodix_ts_data *ts = i2c_get_clientdata(client);
1186
+ struct goodix_ts_data *ts = i2c_get_clientdata(client);
28131187
2814
- GTP_DEBUG_FUNC();
2815
-
1188
+ dprintk(DEBUG_INIT,"%s start!\n", __func__);
28161189 #ifdef CONFIG_HAS_EARLYSUSPEND
2817
- unregister_early_suspend(&ts->early_suspend);
1190
+ unregister_early_suspend(&ts->early_suspend);
28181191 #endif
28191192
28201193 #if GTP_CREATE_WR_NODE
2821
- uninit_wr_node();
1194
+ uninit_wr_node();
28221195 #endif
28231196
28241197 #if GTP_ESD_PROTECT
2825
- destroy_workqueue(gtp_esd_check_workqueue);
1198
+ flush_workqueue(gtp_esd_check_workqueue);
1199
+ if(gtp_esd_check_workqueue)
1200
+ destroy_workqueue(gtp_esd_check_workqueue);
28261201 #endif
2827
- pm_runtime_disable(&client->dev);
2828
- pm_runtime_set_suspended(&client->dev);
2829
- remove_proc_entry(GT91XX_CONFIG_PROC_FILE,NULL);
2830
- sysfs_remove_group(&ts->input_dev->dev.kobj, &gtp_attribute_group);
2831
-
2832
- if (ts)
2833
- {
2834
- if (ts->use_irq)
2835
- {
2836
- gtp_set_int_value(0);
2837
- input_free_int(&(config_info.input_type), ts);
2838
- }
2839
- else
2840
- {
2841
- hrtimer_cancel(&ts->timer);
2842
- }
2843
- }
2844
- else {
2845
- printk("error!!! ts is null!\n");
2846
- return -1;
2847
- }
2848
-
2849
-
2850
- GTP_INFO("GTP driver removing...");
2851
- i2c_set_clientdata(client, NULL);
2852
- input_unregister_device(ts->input_dev);
2853
- kfree(ts);
2854
-
2855
- return 0;
2856
-}
2857
-
2858
-#ifdef CONFIG_PM
2859
-/*******************************************************
2860
-Function:
2861
- Early suspend function.
2862
-Input:
2863
- h: early_suspend struct.
2864
-Output:
2865
- None.
2866
-*******************************************************/
2867
-static void goodix_ts_suspend(struct goodix_ts_data *ts)
2868
-{
2869
- s8 ret = -1;
2870
-
2871
- GTP_DEBUG_FUNC();
2872
- GTP_INFO("System suspend.");
2873
-
2874
- ts->gtp_is_suspend = 1;
2875
- g_suspend_flag = 1;
2876
- dprintk(DEBUG_INIT, "%s g_suspend_flag=%d\n", __func__, g_suspend_flag);
2877
-
2878
-#if GTP_ESD_PROTECT
2879
- gtp_esd_switch(ts->client, SWITCH_OFF);
2880
-#endif
2881
-
2882
- if (gtp_gesture_wakeup)
2883
- ret = gtp_enter_doze(ts);
2884
- else {
2885
- if (ts->use_irq) {
2886
- gtp_irq_disable(ts);
2887
- }
2888
- else {
2889
- hrtimer_cancel(&ts->timer);
2890
- }
2891
- ret = gtp_enter_sleep(ts);
2892
- }
2893
- if (ret < 0) {
2894
- GTP_ERROR("GTP suspend failed.");
2895
- }
2896
- /* to avoid waking up while not sleeping
2897
- delay 48 + 10ms to ensure reliability */
2898
- msleep(58);
2899
-
2900
- if (!gtp_gesture_wakeup) {
2901
- printk("ctp power off suspend!!!\n");
2902
- input_set_power_enable(&(config_info.input_type), 0);
2903
- __gpio_set_value(config_info.wakeup_gpio.gpio, 0);
2904
- }
2905
-}
2906
-
2907
-/*******************************************************
2908
-Function:
2909
- Late resume function.
2910
-Input:
2911
- h: early_suspend struct.
2912
-Output:
2913
- None.
2914
-*******************************************************/
2915
-static void goodix_ts_resume(struct goodix_ts_data *ts)
2916
-{
2917
- s8 ret = -1;
2918
- GTP_DEBUG_FUNC();
2919
-
2920
- dprintk(DEBUG_SUSPEND, "System resume\n");
2921
- if (!gtp_gesture_wakeup) {
2922
- __gpio_set_value(config_info.wakeup_gpio.gpio, 1);
2923
- dprintk(DEBUG_INIT, "ctp power on in goodix_ts_resume!!!\n");
2924
- input_set_power_enable(&(config_info.input_type), 1);
2925
- msleep(10);
2926
- }
2927
-
2928
- ret = gtp_wakeup_sleep(ts);
2929
- if (gtp_gesture_wakeup)
2930
- doze_status = DOZE_DISABLED;
2931
-
2932
- if (ret < 0) {
2933
- dprintk(DEBUG_INIT, "GTP later resume failed.");
2934
- }
2935
-#if (GTP_COMPATIBLE_MODE)
2936
- if (CHIP_TYPE_GT9F == ts->chip_type) {
2937
- /* do nothing */
2938
- }
2939
- else
2940
-#endif
2941
- {
2942
- gtp_send_cfg(ts->client);
2943
- }
2944
- printk("ts->use_irq=%d", ts->use_irq);
2945
- if (ts->use_irq) {
2946
- gtp_irq_enable(ts);
2947
- }
2948
- else {
2949
- hrtimer_start(&ts->timer, ktime_set(1, 0), HRTIMER_MODE_REL);
2950
- }
2951
-
2952
- ts->gtp_is_suspend = 0;
2953
- g_suspend_flag = 0;
2954
- dprintk(DEBUG_INIT, "%s g_suspend_flag=%d\n", __func__, g_suspend_flag);
2955
-#if GTP_ESD_PROTECT
2956
- gtp_esd_switch(ts->client, SWITCH_ON);
2957
-#endif
2958
-}
2959
-
2960
-static int gtp_pm_suspend(struct device *dev)
2961
-{
2962
- struct goodix_ts_data *ts = dev_get_drvdata(dev);
2963
- dprintk(DEBUG_SUSPEND, "CONFIG_PM:enter gtp_pm_suspend. \n");
2964
- if (pm_runtime_suspended(dev))
2965
- return 0;
2966
-
2967
- if (ts) {
2968
- goodix_ts_suspend(ts);
2969
- }
2970
-
2971
- return 0;
2972
-}
2973
-static int gtp_pm_resume(struct device *dev)
2974
-{
2975
- struct goodix_ts_data *ts = dev_get_drvdata(dev);
2976
- dprintk(DEBUG_SUSPEND, "CONFIG_PM:enter laterresume: goodix_ts_resume. \n");
2977
- if (pm_runtime_suspended(dev))
2978
- return 0;
2979
-
2980
- if (ts) {
2981
- goodix_ts_resume(ts);
2982
- }
1202
+ input_free_int(&(config_info.input_type), ts);
1203
+ flush_workqueue(goodix_wq);
1204
+ //cancel_work_sync(&goodix_init_work);
1205
+ cancel_work_sync(&goodix_resume_work);
1206
+ if(goodix_wq)
1207
+ destroy_workqueue(goodix_wq);
1208
+ //destroy_workqueue(goodix_init_wq);
1209
+ if(goodix_resume_wq)
1210
+ destroy_workqueue(goodix_resume_wq);
1211
+ i2c_set_clientdata(ts->client, NULL);
1212
+ input_unregister_device(ts->input_dev);
1213
+ kfree(ts);
29831214
29841215 return 0;
29851216 }
29861217
2987
-static struct dev_pm_ops gtp_pm_ops = {
2988
- .suspend = gtp_pm_suspend,
2989
- .resume = gtp_pm_resume,
2990
-};
2991
-#endif
1218
+static void goodix_resume_events (struct work_struct *work)
1219
+{
1220
+ int ret;
1221
+ struct goodix_ts_data *ts = i2c_get_clientdata(i2c_connect_client);
1222
+
1223
+ ret = gtp_wakeup_sleep(ts);
1224
+ if (ret < 0)
1225
+ printk("resume power on failed\n");
1226
+ gtp_irq_enable(ts);
1227
+}
1228
+
1229
+/*******************************************************
1230
+Function:
1231
+Early suspend function.
1232
+
1233
+Input:
1234
+h:early_suspend struct.
1235
+
1236
+Output:
1237
+None.
1238
+ *******************************************************/
29921239 #ifdef CONFIG_HAS_EARLYSUSPEND
2993
-/*******************************************************
2994
-Function:
2995
- Early suspend function.
2996
-Input:
2997
- h: early_suspend struct.
2998
-Output:
2999
- None.
3000
-*******************************************************/
30011240 static void goodix_ts_early_suspend(struct early_suspend *h)
30021241 {
3003
- struct goodix_ts_data *ts;
3004
- s8 ret = -1;
3005
- ts = container_of(h, struct goodix_ts_data, early_suspend);
1242
+ struct goodix_ts_data *ts;
1243
+ s8 ret = -1;
1244
+ ts = container_of(h, struct goodix_ts_data, early_suspend);
30061245
3007
- GTP_DEBUG_FUNC();
3008
-
3009
- GTP_INFO("System suspend.");
3010
-
3011
- ts->gtp_is_suspend = 1;
3012
- g_suspend_flag = 1;
3013
- dprintk(DEBUG_INIT,"%s g_suspend_flag=%d\n",__func__,g_suspend_flag);
30141246 #if GTP_ESD_PROTECT
3015
- gtp_esd_switch(ts->client, SWITCH_OFF);
1247
+ ts->gtp_is_suspend = 1;
1248
+ cancel_delayed_work_sync(&gtp_esd_check_work);
30161249 #endif
30171250
3018
-//#if GTP_GESTURE_WAKEUP
3019
-if(gtp_gesture_wakeup)
3020
- ret = gtp_enter_doze(ts);
3021
-else {
3022
-//#else
3023
- if (ts->use_irq)
3024
- {
3025
- gtp_irq_disable(ts);
3026
- }
3027
- else
3028
- {
3029
- hrtimer_cancel(&ts->timer);
3030
- }
3031
- ret = gtp_enter_sleep(ts);
3032
-}
3033
-//#endif
3034
- if (ret < 0)
3035
- {
3036
- GTP_ERROR("GTP early suspend failed.");
3037
- }
3038
- // to avoid waking up while not sleeping
3039
- // delay 48 + 10ms to ensure reliability
3040
- msleep(58);
3041
-//#if (!GTP_GESTURE_WAKEUP)
3042
-if(!gtp_gesture_wakeup){
3043
- printk("ctp power off in early suspend!!!\n");
3044
- input_set_power_enable(&(config_info.input_type), 0);
3045
- __gpio_set_value(config_info.wakeup_gpio.gpio, 0);
3046
-//#endif
3047
-}
1251
+ gtp_irq_disable(ts);
1252
+
1253
+
1254
+ cancel_work_sync(&goodix_resume_work);
1255
+ flush_workqueue(goodix_resume_wq);
1256
+ ret = cancel_work_sync(&ts->work);
1257
+ flush_workqueue(goodix_wq);
1258
+
1259
+ ret = gtp_enter_sleep(ts);
1260
+ if (ret < 0) {
1261
+ printk("GTP early suspend failed.");
1262
+ }
30481263 }
30491264
30501265 /*******************************************************
30511266 Function:
3052
- Late resume function.
1267
+Late resume function.
1268
+
30531269 Input:
3054
- h: early_suspend struct.
1270
+h:early_suspend struct.
1271
+
30551272 Output:
3056
- None.
3057
-*******************************************************/
1273
+None.
1274
+ *******************************************************/
30581275 static void goodix_ts_late_resume(struct early_suspend *h)
30591276 {
3060
- struct goodix_ts_data *ts;
3061
- s8 ret = -1;
3062
- ts = container_of(h, struct goodix_ts_data, early_suspend);
1277
+ struct goodix_ts_data *ts;
1278
+ ts = container_of(h, struct goodix_ts_data, early_suspend);
30631279
3064
- GTP_DEBUG_FUNC();
3065
-
3066
- GTP_INFO("System resume.");
3067
-//#if (!GTP_GESTURE_WAKEUP)
3068
-if(!gtp_gesture_wakeup){
3069
- __gpio_set_value(config_info.wakeup_gpio.gpio, 1);
3070
- printk("ctp power on in late resume!!!\n");
3071
- input_set_power_enable(&(config_info.input_type), 1);
3072
- msleep(10);
3073
-}
3074
-//#endif
3075
-
3076
- ret = gtp_wakeup_sleep(ts);
3077
-
3078
-//#if GTP_GESTURE_WAKEUP
3079
-if(gtp_gesture_wakeup)
3080
- doze_status = DOZE_DISABLED;
3081
-//#endif
3082
-
3083
- if (ret < 0)
3084
- {
3085
- GTP_ERROR("GTP later resume failed.");
3086
- }
3087
-#if (GTP_COMPATIBLE_MODE)
3088
- if (CHIP_TYPE_GT9F == ts->chip_type)
3089
- {
3090
- // do nothing
3091
- }
3092
- else
3093
-#endif
3094
- {
3095
- gtp_send_cfg(ts->client);
3096
- }
3097
-
3098
- if (ts->use_irq)
3099
- {
3100
- gtp_irq_enable(ts);
3101
- }
3102
- else
3103
- {
3104
- hrtimer_start(&ts->timer, ktime_set(1, 0), HRTIMER_MODE_REL);
3105
- }
3106
-
3107
- ts->gtp_is_suspend = 0;
3108
- g_suspend_flag = 0;
3109
- dprintk(DEBUG_INIT,"%s g_suspend_flag=%d\n",__func__,g_suspend_flag);
3110
-#if GTP_ESD_PROTECT
3111
- gtp_esd_switch(ts->client, SWITCH_ON);
3112
-#endif
3113
-}
3114
-#endif
3115
-
1280
+ queue_work(goodix_resume_wq, &goodix_resume_work);//gandy
31161281
31171282 #if GTP_ESD_PROTECT
3118
-s32 gtp_i2c_read_no_rst(struct i2c_client *client, u8 *buf, s32 len)
1283
+ ts->gtp_is_suspend = 0;
1284
+ queue_delayed_work(gtp_esd_check_workqueue, &gtp_esd_check_work, GTP_ESD_CHECK_CIRCLE);
1285
+#endif
1286
+}
1287
+#else
1288
+#ifdef CONFIG_PM
1289
+static int goodix_ts_suspend(struct device *dev)
31191290 {
3120
- struct i2c_msg msgs[2];
3121
- s32 ret=-1;
3122
- s32 retries = 0;
1291
+ struct goodix_ts_data *ts = dev_get_drvdata(dev);
1292
+ s8 ret = -1;
31231293
3124
- GTP_DEBUG_FUNC();
1294
+ printk("%s goodix_ts_suspend\n", goodix_ts_name);
1295
+#if GTP_ESD_PROTECT
1296
+ ts->gtp_is_suspend = 1;
1297
+ cancel_delayed_work_sync(&gtp_esd_check_work);
1298
+#endif
31251299
3126
- msgs[0].flags = !I2C_M_RD;
3127
- msgs[0].addr = client->addr;
3128
- msgs[0].len = GTP_ADDR_LENGTH;
3129
- msgs[0].buf = &buf[0];
3130
- //msgs[0].scl_rate = 300 * 1000; // for Rockchip, etc.
1300
+ /*
1301
+ ret = input_set_int_enable(&(config_info.input_type), 0);
1302
+ if (ret < 0)
1303
+ dprintk(DEBUG_SUSPEND,"%s irq disable failed\n", goodix_ts_name);
1304
+ */
1305
+ gtp_irq_disable(ts);
1306
+ cancel_work_sync(&goodix_resume_work);
1307
+ flush_workqueue(goodix_resume_wq);
1308
+ ret = cancel_work_sync(&ts->work);
1309
+ flush_workqueue(goodix_wq);
31311310
3132
- msgs[1].flags = I2C_M_RD;
3133
- msgs[1].addr = client->addr;
3134
- msgs[1].len = len - GTP_ADDR_LENGTH;
3135
- msgs[1].buf = &buf[GTP_ADDR_LENGTH];
3136
- //msgs[1].scl_rate = 300 * 1000;
1311
+ ret = gtp_enter_sleep(ts);
1312
+ if (ret < 0) {
1313
+ printk("GTP suspend failed.");
1314
+ }
31371315
3138
- while(retries < 5)
3139
- {
3140
- ret = i2c_transfer(client->adapter, msgs, 2);
3141
- if(ret == 2)break;
3142
- retries++;
3143
- }
3144
- if ((retries >= 5))
3145
- {
3146
- GTP_ERROR("I2C Read: 0x%04X, %d bytes failed, errcode: %d!", (((u16)(buf[0] << 8)) | buf[1]), len-2, ret);
3147
- }
3148
- return ret;
1316
+ msleep(58);
1317
+
1318
+ input_set_power_enable(&(config_info.input_type), 0);
1319
+ __gpio_set_value(config_info.wakeup_gpio.gpio, 0);
1320
+ return 0;
31491321 }
31501322
3151
-s32 gtp_i2c_write_no_rst(struct i2c_client *client,u8 *buf,s32 len)
1323
+static int goodix_ts_resume(struct device *dev)
31521324 {
3153
- struct i2c_msg msg;
3154
- s32 ret = -1;
3155
- s32 retries = 0;
1325
+ printk("%s goodix_ts_resume\n", goodix_ts_name);
1326
+ __gpio_set_value(config_info.wakeup_gpio.gpio, 1);
1327
+ input_set_power_enable(&(config_info.input_type), 1);
1328
+ msleep(10);
1329
+ queue_work(goodix_resume_wq, &goodix_resume_work);//gandy
31561330
3157
- GTP_DEBUG_FUNC();
1331
+#if GTP_ESD_PROTECT
1332
+ struct goodix_ts_data *ts = dev_get_drvdata(dev);
1333
+ ts->gtp_is_suspend = 0;
1334
+ queue_delayed_work(gtp_esd_check_workqueue, &gtp_esd_check_work, GTP_ESD_CHECK_CIRCLE);
1335
+#endif
1336
+ return 0;
1337
+}
1338
+#endif
1339
+#endif
31581340
3159
- msg.flags = !I2C_M_RD;
3160
- msg.addr = client->addr;
3161
- msg.len = len;
3162
- msg.buf = buf;
3163
- //msg.scl_rate = 300 * 1000; // for Rockchip, etc
3164
-
3165
- while(retries < 5)
3166
- {
3167
- ret = i2c_transfer(client->adapter, &msg, 1);
3168
- if (ret == 1)break;
3169
- retries++;
3170
- }
3171
- if((retries >= 5))
3172
- {
3173
- GTP_ERROR("I2C Write: 0x%04X, %d bytes failed, errcode: %d!", (((u16)(buf[0] << 8)) | buf[1]), len-2, ret);
3174
- }
3175
- return ret;
1341
+#if GTP_ESD_PROTECT
1342
+/*******************************************************
1343
+Function:
1344
+Initialize external watchdog for esd protect
1345
+Input:
1346
+client: i2c device.
1347
+Output:
1348
+result of i2c write operation.
1349
+1: succeed, otherwise: failed
1350
+ *********************************************************/
1351
+s32 gtp_init_ext_watchdog(struct i2c_client *client)
1352
+{
1353
+ u8 opr_buffer[4] = {0x80, 0x40, 0xAA, 0xAA};
1354
+ dprintk(DEBUG_INIT, "Init external watchdog...");
1355
+ return gtp_i2c_write(client, opr_buffer, 4);
31761356 }
31771357 /*******************************************************
31781358 Function:
3179
- switch on & off esd delayed work
1359
+Esd protect function.
1360
+Added external watchdog by meta, 2013/03/07
31801361 Input:
3181
- client: i2c device
3182
- on: SWITCH_ON / SWITCH_OFF
1362
+work: delayed work
31831363 Output:
3184
- void
3185
-*********************************************************/
3186
-void gtp_esd_switch(struct i2c_client *client, s32 on)
3187
-{
3188
- struct goodix_ts_data *ts;
3189
-
3190
- ts = i2c_get_clientdata(client);
3191
- spin_lock(&ts->esd_lock);
3192
-
3193
- if (SWITCH_ON == on) // switch on esd
3194
- {
3195
- if (!ts->esd_running)
3196
- {
3197
- ts->esd_running = 1;
3198
- spin_unlock(&ts->esd_lock);
3199
- GTP_INFO("Esd started");
3200
- queue_delayed_work(gtp_esd_check_workqueue, &gtp_esd_check_work, ts->clk_tick_cnt);
3201
- }
3202
- else
3203
- {
3204
- spin_unlock(&ts->esd_lock);
3205
- }
3206
- }
3207
- else // switch off esd
3208
- {
3209
- if (ts->esd_running)
3210
- {
3211
- ts->esd_running = 0;
3212
- spin_unlock(&ts->esd_lock);
3213
- GTP_INFO("Esd cancelled");
3214
- cancel_delayed_work_sync(&gtp_esd_check_work);
3215
- }
3216
- else
3217
- {
3218
- spin_unlock(&ts->esd_lock);
3219
- }
3220
- }
3221
-}
3222
-
3223
-/*******************************************************
3224
-Function:
3225
- Initialize external watchdog for esd protect
3226
-Input:
3227
- client: i2c device.
3228
-Output:
3229
- result of i2c write operation.
3230
- 1: succeed, otherwise: failed
3231
-*********************************************************/
3232
-static s32 gtp_init_ext_watchdog(struct i2c_client *client)
3233
-{
3234
- u8 opr_buffer[3] = {0x80, 0x41, 0xAA};
3235
- GTP_DEBUG("[Esd]Init external watchdog");
3236
- return gtp_i2c_write_no_rst(client, opr_buffer, 3);
3237
-}
3238
-
3239
-/*******************************************************
3240
-Function:
3241
- Esd protect function.
3242
- External watchdog added by meta, 2013/03/07
3243
-Input:
3244
- work: delayed work
3245
-Output:
3246
- None.
3247
-*******************************************************/
1364
+None.
1365
+ *******************************************************/
32481366 static void gtp_esd_check_func(struct work_struct *work)
32491367 {
3250
- s32 i;
3251
- s32 ret = -1;
3252
- struct goodix_ts_data *ts = NULL;
3253
- u8 esd_buf[5] = {0x80, 0x40};
1368
+ s32 i;
1369
+ s32 ret = -1;
1370
+ struct goodix_ts_data *ts = NULL;
1371
+ u8 test[4] = {0x80, 0x40};
32541372
3255
- GTP_DEBUG_FUNC();
1373
+ dprintk(DEBUG_INIT, "enter %s work!\n", __func__);
32561374
3257
- ts = i2c_get_clientdata(i2c_connect_client);
1375
+ ts = i2c_get_clientdata(i2c_connect_client);
32581376
3259
- if (ts->gtp_is_suspend)
3260
- {
3261
- GTP_INFO("Esd suspended!");
3262
- return;
3263
- }
1377
+ if (ts->gtp_is_suspend || ts->enter_update) {
1378
+ return;
1379
+ }
32641380
3265
- for (i = 0; i < 3; i++)
3266
- {
3267
- ret = gtp_i2c_read_no_rst(ts->client, esd_buf, 4);
1381
+ for (i = 0; i < 3; i++) {
1382
+ ret = gtp_i2c_read(ts->client, test, 4);
32681383
3269
- GTP_DEBUG("[Esd]0x8040 = 0x%02X, 0x8041 = 0x%02X", esd_buf[2], esd_buf[3]);
3270
- if ((ret < 0))
3271
- {
3272
- // IIC communication problem
3273
- continue;
3274
- }
3275
- else
3276
- {
3277
- if ((esd_buf[2] == 0xAA) || (esd_buf[3] != 0xAA))
3278
- {
3279
- // IC works abnormally..
3280
- u8 chk_buf[4] = {0x80, 0x40};
1384
+ dprintk(DEBUG_INIT, "0x8040 = 0x%02X, 0x8041 = 0x%02X", test[2], test[3]);
1385
+ if ((ret < 0)) {
1386
+ // IC works abnormally..
1387
+ continue;
1388
+ }else {
1389
+ if ((test[2] == 0xAA) || (test[3] != 0xAA)) {
1390
+ // IC works abnormally..
1391
+ i = 3;
1392
+ break;
1393
+ }else {
1394
+ // IC works normally, Write 0x8040 0xAA
1395
+ test[2] = 0xAA;
1396
+ gtp_i2c_write(ts->client, test, 3);
1397
+ break;
1398
+ }
1399
+ }
1400
+ }
32811401
3282
- gtp_i2c_read_no_rst(ts->client, chk_buf, 4);
1402
+ if (i >= 3) {
1403
+ GTP_DEBUG("IC Working ABNORMALLY, Resetting Guitar...");
1404
+ // gtp_reset_guitar(ts->client, 50);
1405
+ }
32831406
3284
- GTP_DEBUG("[Check]0x8040 = 0x%02X, 0x8041 = 0x%02X", chk_buf[2], chk_buf[3]);
1407
+ if(!ts->gtp_is_suspend) {
1408
+ queue_delayed_work(gtp_esd_check_workqueue, &gtp_esd_check_work, GTP_ESD_CHECK_CIRCLE);
1409
+ }
32851410
3286
- if ((chk_buf[2] == 0xAA) || (chk_buf[3] != 0xAA))
3287
- {
3288
- i = 3;
3289
- break;
3290
- }
3291
- else
3292
- {
3293
- continue;
3294
- }
3295
- }
3296
- else
3297
- {
3298
- // IC works normally, Write 0x8040 0xAA, feed the dog
3299
- esd_buf[2] = 0xAA;
3300
- gtp_i2c_write_no_rst(ts->client, esd_buf, 3);
3301
- break;
3302
- }
3303
- }
3304
- }
3305
- if (i >= 3)
3306
- {
3307
- #if GTP_COMPATIBLE_MODE
3308
- if (CHIP_TYPE_GT9F == ts->chip_type)
3309
- {
3310
- if (ts->rqst_processing)
3311
- {
3312
- GTP_INFO("Request processing, no esd recovery");
3313
- }
3314
- else
3315
- {
3316
- GTP_ERROR("IC working abnormally! Process esd recovery.");
3317
- esd_buf[0] = 0x42;
3318
- esd_buf[1] = 0x26;
3319
- esd_buf[2] = 0x01;
3320
- esd_buf[3] = 0x01;
3321
- esd_buf[4] = 0x01;
3322
- gtp_i2c_write_no_rst(ts->client, esd_buf, 5);
3323
- msleep(50);
3324
- gtp_esd_recovery(ts->client);
3325
- }
3326
- }
3327
- else
3328
- #endif
3329
- {
3330
- GTP_ERROR("IC working abnormally! Process reset guitar.");
3331
- esd_buf[0] = 0x42;
3332
- esd_buf[1] = 0x26;
3333
- esd_buf[2] = 0x01;
3334
- esd_buf[3] = 0x01;
3335
- esd_buf[4] = 0x01;
3336
- gtp_i2c_write_no_rst(ts->client, esd_buf, 5);
3337
- msleep(50);
3338
- gtp_reset_guitar(ts->client, 50);
3339
- msleep(50);
3340
- gtp_send_cfg(ts->client);
3341
- }
3342
- }
3343
-
3344
- if(!ts->gtp_is_suspend)
3345
- {
3346
- queue_delayed_work(gtp_esd_check_workqueue, &gtp_esd_check_work, ts->clk_tick_cnt);
3347
- }
3348
- else
3349
- {
3350
- GTP_INFO("Esd suspended!");
3351
- }
3352
- return;
1411
+ return;
33531412 }
33541413 #endif
33551414
33561415 static const struct i2c_device_id goodix_ts_id[] = {
3357
- { CTP_NAME, 0 },
3358
- { }
1416
+ { CTP_NAME, 0 },
1417
+ { }
33591418 };
33601419
3361
-#if !USE_DETECT
3362
-static const struct of_device_id goodix_of_match[] = {
3363
- {.compatible = "allwinner,goodix"},
3364
- {},
1420
+#ifndef CONFIG_HAS_EARLYSUSPEND
1421
+#ifdef CONFIG_PM
1422
+static const struct dev_pm_ops gt9xx_pm_ops = {
1423
+ .suspend = goodix_ts_suspend,
1424
+ .resume = goodix_ts_resume,
33651425 };
1426
+
1427
+#define GT9XX_PM_OPS (&gt9xx_pm_ops)
1428
+#endif
33661429 #endif
33671430
33681431 static struct i2c_driver goodix_ts_driver = {
3369
- .class = I2C_CLASS_HWMON,
3370
- .probe = goodix_ts_probe,
3371
- .remove = goodix_ts_remove,
3372
- .id_table = goodix_ts_id,
1432
+ .class = I2C_CLASS_HWMON,
1433
+ .probe = goodix_ts_probe,
1434
+ .remove = goodix_ts_remove,
1435
+ .id_table = goodix_ts_id,
33731436 .driver = {
3374
-#if !USE_DETECT
3375
- .of_match_table = goodix_of_match,
3376
-#endif
33771437 .name = CTP_NAME,
3378
- .owner = THIS_MODULE,
1438
+ .owner = THIS_MODULE,
33791439 #ifndef CONFIG_HAS_EARLYSUSPEND
3380
-#if defined(CONFIG_PM)
3381
- .pm = &gtp_pm_ops,
1440
+#ifdef CONFIG_PM
1441
+ .pm = GT9XX_PM_OPS,
33821442 #endif
33831443 #endif
33841444 },
33851445 .address_list = normal_i2c,
3386
-#if USE_DETECT
3387
- .detect = ctp_detect,
3388
-#endif
33891446 };
33901447
33911448 static int ctp_get_system_config(void)
3392
-{
3393
- ctp_print_info(config_info,DEBUG_INIT);
3394
- twi_id = config_info.twi_id;
3395
- screen_max_x = config_info.screen_max_x;
3396
- screen_max_y = config_info.screen_max_y;
3397
- revert_x_flag = config_info.revert_x_flag;
3398
- revert_y_flag = config_info.revert_y_flag;
3399
- exchange_x_y_flag = config_info.exchange_x_y_flag;
3400
- if((screen_max_x == 0) || (screen_max_y == 0)){
3401
- printk("%s:read config error!\n",__func__);
3402
- return 0;
3403
- }
3404
- return 1;
1449
+{
1450
+ ctp_print_info(config_info,DEBUG_INIT);
1451
+ twi_id = config_info.twi_id;
1452
+#if LVDS_1024x600
1453
+ screen_max_x = 1024;
1454
+ screen_max_y = 600;
1455
+ revert_x_flag = 0;
1456
+ revert_y_flag = 0;
1457
+ exchange_x_y_flag = 0;
1458
+#else
1459
+ screen_max_x = config_info.screen_max_x;
1460
+ screen_max_y = config_info.screen_max_y;
1461
+ revert_x_flag = config_info.revert_x_flag;
1462
+ revert_y_flag = config_info.revert_y_flag;
1463
+ exchange_x_y_flag = config_info.exchange_x_y_flag;
1464
+#endif
1465
+ if((screen_max_x == 0) || (screen_max_y == 0)){
1466
+ printk("%s:read config error!\n",__func__);
1467
+ return 0;
1468
+ }
1469
+ return 1;
34051470 }
34061471
3407
-static int startup(void)
1472
+/*******************************************************
1473
+ * Function:
1474
+ * Driver Install function.
1475
+ * Input:
1476
+ * None.
1477
+ * Output:
1478
+ * Executive Outcomes. 0---succeed.
1479
+ * ********************************************************/
1480
+static int __init goodix_ts_init(void)
34081481 {
34091482 s32 ret = -1;
1483
+ int val = 0;
1484
+ struct device_node *np = NULL;
34101485
3411
- dprintk(DEBUG_INIT, "GTP driver init\n");
1486
+ dprintk(DEBUG_INIT,"GTP driver init\n");
34121487 if (!input_sensor_startup(&(config_info.input_type))) {
34131488 ret = input_sensor_init(&(config_info.input_type));
34141489 if (ret != 0) {
34151490 pr_err("%s:ctp_ops.input_sensor_init err.\n", __func__);
3416
- return -1;
1491
+ return ret;
34171492 }
34181493 input_set_power_enable(&(config_info.input_type), 1);
34191494 } else {
34201495 pr_err("%s: input_ctp_startup err.\n", __func__);
3421
- return -1;
1496
+ return 0;
34221497 }
3423
- if (config_info.ctp_used == 0) {
1498
+ if(config_info.ctp_used == 0){
34241499 printk("*** ctp_used set to 0 !\n");
34251500 printk("*** if use ctp,please put the sys_config.fex ctp_used set to 1. \n");
3426
- return -1;
3427
- }
3428
-
3429
- if (config_info.ctp_gesture_wakeup == 1) {
3430
- gtp_gesture_wakeup = 1;
3431
- dprintk(DEBUG_INIT, "GTP driver gesture wakeup is used!\n");
3432
- }
3433
-
3434
- if (!gtp_gesture_wakeup)
3435
- gtp_power_ctrl_sleep = 1;
3436
-
3437
- if (!ctp_get_system_config()) {
3438
- printk("%s:read config fail!\n", __func__);
3439
- return -1;
3440
- }
3441
- sunxi_gpio_to_name(CTP_IRQ_NUMBER, irq_pin_name);
3442
- gtp_io_init(20);
3443
- return 0;
3444
-}
3445
-
3446
-/*******************************************************
3447
-Function:
3448
- Driver Install function.
3449
-Input:
3450
- None.
3451
-Output:
3452
- Executive Outcomes. 0---succeed.
3453
-********************************************************/
3454
-static int goodix_ts_init(void)
3455
-{
3456
-#if !USE_DETECT
3457
- struct device_node *np = NULL;
3458
- char *p = NULL;
3459
-#endif
3460
-
3461
-#if USE_DETECT
3462
- if (startup() != 0)
34631501 return 0;
3464
-#else
3465
- np = of_find_node_by_name(NULL, "ctp");
3466
- if (np && np->parent) {
3467
- p = (char *) np->parent->name;
3468
- if (strncmp(p, "twi", 3) != 0) {
3469
- gUseDetect = 1;
3470
- if (startup() != 0)
3471
- return 0;
3472
- goodix_ts_driver.detect = ctp_detect;
3473
- }
34741502 }
1503
+
1504
+ np = of_find_node_by_name(NULL, "ctp");
1505
+ if (!np) {
1506
+ pr_err("ERROR! get ctp node failed, func:%s, line:%d\n",__FUNCTION__, __LINE__);
1507
+ return -1;
1508
+ }
1509
+
1510
+ ret = of_property_read_u32(np, "ctp_gesture_wakeup", &val);
1511
+ if (ret) {
1512
+ pr_err("get ctp_screen_max_x is fail, %d\n", ret);
1513
+ }
1514
+ msleep(10);
1515
+#if 0
1516
+ if(!ctp_get_system_config()){
1517
+ printk("%s:read config fail!\n",__func__);
1518
+ return ret;
1519
+ }
1520
+#else
1521
+ //ret = of_property_read_u32(np, "ctp_screen_max_x", &screen_max_x);
1522
+ //of_property_read_u32(np, "ctp_screen_max_y", &screen_max_y);
1523
+ //of_property_read_u32(np, "ctp_revert_x_flag", &revert_x_flag);
1524
+ //of_property_read_u32(np, "ctp_revert_y_flag", &revert_y_flag);
1525
+ //of_property_read_u32(np, "ctp_exchange_x_y_flag", &exchange_x_y_flag);
1526
+ printk(KERN_ERR"------------ screen_max_x=%d, screen_max_y=%d, revert_x_flag=%d, revert_y_flag=%d, exchange_x_y_flag=%d\n", screen_max_x, screen_max_y, revert_x_flag, revert_y_flag, exchange_x_y_flag);
34751527 #endif
1528
+ sunxi_gpio_to_name(CTP_IRQ_NUMBER,irq_pin_name);
1529
+ gtp_io_init(20);
1530
+
34761531 goodix_wq = create_singlethread_workqueue("goodix_wq");
3477
- if (!goodix_wq) {
1532
+ if (!goodix_wq)
1533
+ {
34781534 GTP_ERROR("Creat workqueue failed.");
34791535 return -ENOMEM;
34801536 }
34811537 #if GTP_ESD_PROTECT
3482
- INIT_DELAYED_WORK(&gtp_esd_check_work, gtp_esd_check_func);
3483
- gtp_esd_check_workqueue = create_workqueue("gtp_esd_check");
1538
+ INIT_DELAYED_WORK(&gtp_esd_check_work, gtp_esd_check_func);
1539
+ gtp_esd_check_workqueue = create_workqueue("gtp_esd_check");
34841540 #endif
3485
-
3486
- i2c_add_driver(&goodix_ts_driver);
3487
- if (config_info.probed)
3488
- return 0;
3489
- else
3490
- return -1;
1541
+ goodix_ts_driver.detect = ctp_detect;
1542
+ ret = i2c_add_driver(&goodix_ts_driver);
1543
+ return ret;
34911544 }
34921545
3493
-/*******************************************************
1546
+
1547
+/*******************************************************
34941548 Function:
3495
- Driver uninstall function.
1549
+Driver uninstall function.
34961550 Input:
3497
- None.
1551
+None.
34981552 Output:
3499
- Executive Outcomes. 0---succeed.
3500
-********************************************************/
1553
+Executive Outcomes. 0---succeed.
1554
+ ********************************************************/
35011555 static void __exit goodix_ts_exit(void)
35021556 {
3503
- dprintk(DEBUG_INIT,"GTP driver exited.");
1557
+ printk("GTP driver exited.\n");
35041558 i2c_del_driver(&goodix_ts_driver);
3505
- if (goodix_wq)
3506
- {
3507
- destroy_workqueue(goodix_wq);
3508
- }
3509
- input_set_power_enable(&(config_info.input_type), 0);
35101559 input_sensor_free(&(config_info.input_type));
35111560 }
35121561
....@@ -3515,3 +1564,4 @@
35151564
35161565 MODULE_DESCRIPTION("GTP Series Driver");
35171566 MODULE_LICENSE("GPL");
1567
+