-
Notifications
You must be signed in to change notification settings - Fork 46
/
gslx680_ts.c
1237 lines (1001 loc) · 31.4 KB
/
gslx680_ts.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* drivers/input/touchscreen/gslX680.c
*
* Copyright (c) 2012 Shanghai Basewin
* Guan Yuwei<[email protected]>
* Copyright (c) 2013 Joe Burmeister
* Joe Burmeister<[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#include "ctp_platform_ops.h"
#ifdef CONFIG_HAS_EARLYSUSPEND
#include <linux/pm.h>
#include <linux/earlysuspend.h>
#endif
#include <plat/sys_config.h>
#include <linux/firmware.h>
#include <linux/input/mt.h>
static void* __iomem gpio_addr = NULL;
static int gpio_int_hdle = 0;
static int gpio_wakeup_hdle = 0;
static int gpio_io_hdle = 0;
static user_gpio_set_t gpio_int_info[1];
static char gsl_firmware[64] = {0};
#define CTP_IRQ_NO (gpio_int_info[0].port_num)
#define CTP_IRQ_MODE (NEGATIVE_EDGE)
#define GSLX680_I2C_NAME "gslx680"
#define IRQ_PORT SW_INT_IRQNO_PIO
#define GSL_DATA_REG 0x80
#define GSL_STATUS_REG 0xe0
#define GSL_PAGE_REG 0xf0
#define PRESS_MAX 255
#define MAX_FINGERS 10
#define MAX_CONTACTS 10
#define DMA_TRANS_LEN 0x20
#ifdef HAVE_TOUCH_KEY
static u16 key = 0;
static int key_state_flag = 0;
struct key_data {
u16 key;
u16 x_min;
u16 x_max;
u16 y_min;
u16 y_max;
};
const u16 key_array[]={
KEY_BACK,
KEY_HOME,
KEY_MENU,
KEY_SEARCH,
};
#define MAX_KEY_NUM (sizeof(key_array)/sizeof(key_array[0]))
struct key_data gsl_key_data[MAX_KEY_NUM] = {
{KEY_BACK, 2048, 2048, 2048, 2048},
{KEY_HOME, 2048, 2048, 2048, 2048},
{KEY_MENU, 2048, 2048, 2048, 2048},
{KEY_SEARCH, 2048, 2048, 2048, 2048},
};
#endif
struct gsl_ts_data {
u8 x_index;
u8 y_index;
u8 z_index;
u8 id_index;
u8 touch_index;
u8 data_reg;
u8 status_reg;
u8 data_size;
u8 touch_bytes;
u8 update_data;
u8 touch_meta_data;
u8 finger_size;
};
static struct gsl_ts_data devices[] = {
{
.x_index = 6,
.y_index = 4,
.z_index = 5,
.id_index = 7,
.data_reg = GSL_DATA_REG,
.status_reg = GSL_STATUS_REG,
.update_data = 0x4,
.touch_bytes = 4,
.touch_meta_data = 4,
.finger_size = 70,
},
};
struct gsl_ts {
struct i2c_client *client;
struct input_dev *input;
struct work_struct work;
struct workqueue_struct *wq;
struct gsl_ts_data *dd;
u8 *touch_data;
u8 device_id;
u8 prev_touches;
bool is_suspended;
bool int_pending;
struct mutex sus_lock;
int irq;
#if defined(CONFIG_HAS_EARLYSUSPEND)
struct early_suspend early_suspend;
#endif
#ifdef GSL_TIMER
struct timer_list gsl_timer;
#endif
};
static u32 id_sign[MAX_CONTACTS+1] = {0};
static u8 id_state_flag[MAX_CONTACTS+1] = {0};
static u8 id_state_old_flag[MAX_CONTACTS+1] = {0};
static u16 x_old[MAX_CONTACTS+1] = {0};
static u16 y_old[MAX_CONTACTS+1] = {0};
static u16 x_new = 0;
static u16 y_new = 0;
static int screen_max_x = 0;
static int screen_max_y = 0;
#define SCREEN_MAX_X (screen_max_x)
#define SCREEN_MAX_Y (screen_max_y)
static int revert_x_flag = 0;
static int revert_y_flag = 0;
static int exchange_x_y_flag = 0;
static int int_cfg_addr[]={PIO_INT_CFG0_OFFSET,PIO_INT_CFG1_OFFSET,
PIO_INT_CFG2_OFFSET, PIO_INT_CFG3_OFFSET};
static u8 gpio_init_status = 0;
static int gslX680_chip_init(void)
{
if (EGPIO_SUCCESS != gpio_write_one_pin_value(gpio_wakeup_hdle, 1, "ctp_wakeup")) {
pr_info("%s: err when operate wake gpio. \n", __func__);
return -EIO;
}
gpio_init_status |= (1 << 0);
if (EGPIO_SUCCESS != gpio_set_one_pin_pull(gpio_int_hdle, 1, "ctp_io_port")) {
pr_info("%s: err when operate int gpio. \n", __func__);
return -EIO;
}
gpio_init_status |= (1 << 1);
msleep(20);
return 0;
}
static int gslX680_shutdown_low(void)
{
if (EGPIO_SUCCESS != gpio_write_one_pin_value(gpio_wakeup_hdle, 0, "ctp_wakeup")) {
pr_info("%s: err when operate wake gpio. \n", __func__);
return -EIO;
}
return 0;
}
static int gslX680_shutdown_high(void)
{
if (EGPIO_SUCCESS != gpio_write_one_pin_value(gpio_wakeup_hdle, 1, "ctp_wakeup")) {
pr_info("%s: err when operate wake gpio. \n", __func__);
return -EIO;
}
return 0;
}
static inline u16 join_bytes(u8 a, u8 b)
{
u16 ab = 0;
ab = ab | a;
ab = ab << 8 | b;
return ab;
}
static int gsl_write_interface(struct i2c_client *client, const u8 reg, u8 *buf, u32 num)
{
struct i2c_msg xfer_msg[1];
buf[0] = reg;
xfer_msg[0].addr = client->addr;
xfer_msg[0].len = num + 1;
xfer_msg[0].flags = client->flags & I2C_M_TEN;
xfer_msg[0].buf = buf;
return i2c_transfer(client->adapter, xfer_msg, 1) == 1 ? 0 : -EFAULT;
}
static __inline__ void fw2buf(u8 *buf, const u32 *fw)
{
u32 *u32_buf = (int *)buf;
*u32_buf = *fw;
}
static int gsl_load_fw(struct i2c_client *client)
{
u8 buf[DMA_TRANS_LEN*4 + 1] = {0};
u8 send_flag = 1;
u8 *cur = buf + 1;
const struct firmware *fw = NULL;
size_t i;
int rc;
printk("=============gsl_load_fw start==============\n");
rc = request_firmware(&fw, gsl_firmware, &client->dev);
if (rc) {
dev_err(&client->dev, "Unable to open firmware %s\n", gsl_firmware);
return rc;
}
for(i=0; i < fw->size; i+=8) {
u32 *reg = (u32*)&(fw->data[i]);
u32 *value = (u32*)&(fw->data[i + 4]);
fw2buf(cur, value);
if (*reg == GSL_PAGE_REG) {
rc = gsl_write_interface(client, GSL_PAGE_REG, buf, 4);
if (rc < 0) {
pr_info("%s: gsl_write_interface failed. \n", __func__);
goto error;
}
send_flag = 1;
} else {
if (1 == send_flag % (DMA_TRANS_LEN < 0x20 ? DMA_TRANS_LEN : 0x20))
buf[0] = (u8)*reg;
cur += 4;
if (0 == send_flag % (DMA_TRANS_LEN < 0x20 ? DMA_TRANS_LEN : 0x20)) {
rc = gsl_write_interface(client, buf[0], buf, cur - buf - 1);
if (rc < 0) {
pr_info("%s: gsl_write_interface failed. \n", __func__);
goto error;
}
cur = buf + 1;
}
send_flag++;
}
}
printk("=============gsl_load_fw end==============\n");
error:
release_firmware(fw);
return rc;
}
static int gsl_ts_write(struct i2c_client *client, u8 reg, u8 *pdata, int datalen)
{
int ret = 0;
u8 tmp_buf[128];
unsigned int bytelen = 0;
if (datalen > 125) {
printk("%s too big datalen = %d!\n", __func__, datalen);
return -1;
}
tmp_buf[0] = reg;
bytelen++;
if (datalen != 0 && pdata != NULL) {
memcpy(&tmp_buf[bytelen], pdata, datalen);
bytelen += datalen;
}
ret = i2c_master_send(client, tmp_buf, bytelen);
return ret;
}
static int gsl_ts_read(struct i2c_client *client, u8 reg, u8 *pdata, unsigned int datalen)
{
int ret = 0;
if (datalen > 126) {
printk("%s too big datalen = %d!\n", __func__, datalen);
return -1;
}
ret = gsl_ts_write(client, reg, NULL, 0);
if (ret < 0) {
printk("%s set data address fail!\n", __func__);
return ret;
}
return i2c_master_recv(client, pdata, datalen);
}
static int startup_chip(struct i2c_client *client)
{
u8 tmp = 0x00;
int rc = gsl_ts_write(client, 0xe0, &tmp, 1);
msleep(10);
return rc;
}
static int reset_chip(struct i2c_client *client)
{
u8 buf[4] = {0x00};
u8 tmp = 0x88;
int rc = gsl_ts_write(client, 0xe0, &tmp, sizeof(tmp));
if (rc < 0) {
printk("%s: gsl_ts_write 1 fail!\n", __func__);
return rc;
}
msleep(10);
tmp = 0x04;
rc = gsl_ts_write(client, 0xe4, &tmp, sizeof(tmp));
if (rc < 0) {
printk("%s: gsl_ts_write 2 fail!\n", __func__);
return rc;
}
msleep(10);
rc = gsl_ts_write(client, 0xbc, buf, sizeof(buf));
if (rc < 0) {
printk("%s: gsl_ts_write 3 fail!\n", __func__);
return rc;
}
msleep(10);
return 0;
}
static int init_chip(struct i2c_client *client)
{
int rc;
rc = reset_chip(client);
if (rc < 0) {
pr_info("%s: reset_chip fail: %i\n", __func__, rc);
return rc;
}
rc = gsl_load_fw(client);
if (rc < 0) {
pr_info("%s: gsl_load_fw fail: %i\n", __func__, rc);
return rc;
}
rc = startup_chip(client);
if (rc < 0) {
pr_info("%s: startup_chip fail: %i\n", __func__, rc);
return rc;
}
rc = reset_chip(client);
if (rc < 0) {
pr_info("%s: second reset_chip fail: %i\n", __func__, rc);
return rc;
}
rc = gslX680_shutdown_low();
if (rc < 0) {
pr_info("%s: gslX680_shutdown_low fail: %i\n", __func__, rc);
return rc;
}
msleep(50);
rc = gslX680_shutdown_high();
if (rc < 0) {
pr_info("%s: gslX680_shutdown_high fail: %i\n", __func__, rc);
return rc;
}
msleep(30);
rc = gslX680_shutdown_low();
if (rc < 0) {
pr_info("%s: second gslX680_shutdown_low fail: %i\n", __func__, rc);
return rc;
}
msleep(5);
rc = gslX680_shutdown_high();
if (rc < 0) {
pr_info("%s: second gslX680_shutdown_high fail: %i\n", __func__, rc);
return rc;
}
msleep(20);
rc = reset_chip(client);
if (rc < 0) {
pr_info("%s: third reset_chip fail: %i\n", __func__, rc);
return rc;
}
rc = startup_chip(client);
if (rc < 0) {
pr_info("%s: second startup_chip fail: %i\n", __func__, rc);
return rc;
}
return 0;
}
static void record_point(u16 x, u16 y , u8 id)
{
u16 x_err =0;
u16 y_err =0;
id_sign[id]=id_sign[id]+1;
if (id_sign[id]==1) {
x_old[id]=x;
y_old[id]=y;
}
x = (x_old[id] + x)/2;
y = (y_old[id] + y)/2;
if (x>x_old[id]) {
x_err=x -x_old[id];
} else {
x_err=x_old[id]-x;
}
if (y>y_old[id]) {
y_err=y -y_old[id];
} else {
y_err=y_old[id]-y;
}
if ( (x_err > 6 && y_err > 2) || (x_err > 2 && y_err > 6) ) {
x_new = x; x_old[id] = x;
y_new = y; y_old[id] = y;
} else {
if (x_err > 6) {
x_new = x; x_old[id] = x;
} else
x_new = x_old[id];
if (y_err> 6) {
y_new = y; y_old[id] = y;
} else
y_new = y_old[id];
}
if (id_sign[id]==1) {
x_new= x_old[id];
y_new= y_old[id];
}
}
#ifdef HAVE_TOUCH_KEY
static void report_key(struct gsl_ts *ts, u16 x, u16 y)
{
u16 i = 0;
for(i = 0; i < MAX_KEY_NUM; i++) {
if ((gsl_key_data[i].x_min < x) && (x < gsl_key_data[i].x_max)&&(gsl_key_data[i].y_min < y) && (y < gsl_key_data[i].y_max)) {
key = gsl_key_data[i].key;
input_report_key(ts->input, key, 1);
input_sync(ts->input);
key_state_flag = 1;
break;
}
}
}
#endif
static void report_data(struct gsl_ts *ts, u16 x, u16 y, u8 pressure, u8 id)
{
swap(x, y);
if (x>=SCREEN_MAX_X||y>=SCREEN_MAX_Y) {
#ifdef HAVE_TOUCH_KEY
report_key(ts,x,y);
#endif
return;
}
if (exchange_x_y_flag)
swap(x, y);
if (revert_x_flag)
x=SCREEN_MAX_X-x;
if (revert_y_flag)
y=SCREEN_MAX_Y-y;
input_mt_slot(ts->input, id);
input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, 1);
input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR, pressure);
input_report_abs(ts->input, ABS_MT_POSITION_X, x);
input_report_abs(ts->input, ABS_MT_POSITION_Y, y);
input_report_abs(ts->input, ABS_MT_WIDTH_MAJOR, 1);
}
static void process_gslX680_data(struct gsl_ts *ts)
{
u8 id, touches;
u16 x, y;
int i = 0;
touches = ts->touch_data[ts->dd->touch_index];
for(i=1;i<=MAX_CONTACTS;i++) {
if (touches == 0)
id_sign[i] = 0;
id_state_flag[i] = 0;
}
for(i= 0;i < (touches > MAX_FINGERS ? MAX_FINGERS : touches);i ++) {
x = join_bytes( ( ts->touch_data[ts->dd->x_index + 4 * i + 1] & 0xf),
ts->touch_data[ts->dd->x_index + 4 * i]);
y = join_bytes(ts->touch_data[ts->dd->y_index + 4 * i + 1],
ts->touch_data[ts->dd->y_index + 4 * i ]);
id = ts->touch_data[ts->dd->id_index + 4 * i] >> 4;
if (1 <=id && id <= MAX_CONTACTS) {
record_point(x, y , id);
report_data(ts, x_new, y_new, 10, id);
id_state_flag[id] = 1;
}
}
for(i=1;i<=MAX_CONTACTS;i++) {
if ((0 != id_state_old_flag[i]) && (0 == id_state_flag[i])) {
input_mt_slot(ts->input, i);
input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
id_sign[i]=0;
}
id_state_old_flag[i] = id_state_flag[i];
}
if (0 == touches) {
#ifdef HAVE_TOUCH_KEY
if (key_state_flag) {
input_report_key(ts->input, key, 0);
input_sync(ts->input);
key_state_flag = 0;
}
#endif
}
if (touches || touches != ts->prev_touches)
{
input_mt_report_pointer_emulation(ts->input, true);
input_sync(ts->input);
}
ts->prev_touches = touches;
}
static void gsl_ts_xy_worker(struct work_struct *work)
{
int rc;
u8 read_buf[4] = {0};
struct gsl_ts *ts = container_of(work, struct gsl_ts,work);
if (ts->is_suspended == true) {
dev_dbg(&ts->client->dev, "TS is supended\n");
ts->int_pending = true;
goto schedule;
}
/* read data from DATA_REG */
rc = gsl_ts_read(ts->client, 0x80, ts->touch_data, ts->dd->data_size);
if (rc < 0) {
dev_err(&ts->client->dev, "read failed\n");
goto schedule;
}
if (ts->touch_data[ts->dd->touch_index] == 0xff) {
goto schedule;
}
rc = gsl_ts_read( ts->client, 0xbc, read_buf, sizeof(read_buf));
if (rc < 0) {
dev_err(&ts->client->dev, "read 0xbc failed\n");
goto schedule;
}
if (read_buf[3] == 0 && read_buf[2] == 0 && read_buf[1] == 0 && read_buf[0] == 0) {
process_gslX680_data(ts);
} else {
rc = reset_chip(ts->client);
if (rc < 0) {
dev_err(&ts->client->dev, "%s: reset_chip failed\n", __func__);
goto schedule;
}
rc = startup_chip(ts->client);
if (rc < 0) {
dev_err(&ts->client->dev, "%s: startup_chip failed\n", __func__);
goto schedule;
}
}
schedule:
enable_irq(ts->irq);
}
static int ctp_judge_int_occur(void)
{
int reg_val;
int ret = -1;
reg_val = readl(gpio_addr + PIO_INT_STAT_OFFSET);
if (reg_val&(1<<(CTP_IRQ_NO))) {
ret = 0;
}
return ret;
}
static irqreturn_t gsl_ts_irq(int irq, void *dev_id)
{
struct gsl_ts *ts = dev_id;
if (ctp_judge_int_occur()) {
pr_info("Other Interrupt\n");
return IRQ_NONE;
}
if (ts->is_suspended == true)
return IRQ_HANDLED;
disable_irq_nosync(ts->irq);
if (!work_pending(&ts->work))
{
queue_work(ts->wq, &ts->work);
}
return IRQ_HANDLED;
}
#ifdef GSL_TIMER
static void gsl_timer_handle(unsigned long data)
{
struct gsl_ts *ts = (struct gsl_ts *)data;
#ifdef GSL_DEBUG
printk("----------------gsl_timer_handle-----------------\n");
#endif
disable_irq_nosync(ts->irq);
check_mem_data(ts->client);
ts->gsl_timer.expires = jiffies + 3 * HZ;
add_timer(&ts->gsl_timer);
enable_irq(ts->irq);
}
#endif
static union{
unsigned short dirty_addr_buf[2];
const unsigned short normal_i2c[2];
} u_i2c_addr = {{0x00},};
static __u32 twi_id = 0;
/*
* It sucks this is duplicated for each driver right now.
* What would be better is a function that takes an array of parameter names, type of fetch, and pointer + size for result.
*/
static int _fetch_sysconfig_para(void)
{
int ret = -1;
int ctp_used = -1;
char name[I2C_NAME_SIZE];
__u32 twi_addr = 0;
script_parser_value_type_t type = SCRIPT_PARSER_VALUE_TYPE_STRING;
pr_info("%s. \n", __func__);
if (SCRIPT_PARSER_OK != script_parser_fetch("ctp_para", "ctp_used", &ctp_used, 1)) {
pr_err("%s: script_parser_fetch err. \n", __func__);
goto script_parser_fetch_err;
}
if (1 != ctp_used) {
pr_err("%s: ctp_unused. \n", __func__);
return ret;
}
if (SCRIPT_PARSER_OK != script_parser_fetch_ex("ctp_para", "ctp_name", (int *)(&name), &type, sizeof(name)/sizeof(int))) {
pr_err("%s: script_parser_fetch err. \n", __func__);
goto script_parser_fetch_err;
}
if (strcmp(GSLX680_I2C_NAME, name)) {
pr_err("%s: name %s does not match CTP_NAME. \n", __func__, name);
pr_err(GSLX680_I2C_NAME);
return ret;
}
if (SCRIPT_PARSER_OK != script_parser_fetch_ex("ctp_para", "ctp_firmware", (int *)(&gsl_firmware), &type, sizeof(gsl_firmware)/sizeof(int))) {
pr_err("%s: script_parser_fetch err. \n", name);
goto script_parser_fetch_err;
}
pr_info("%s firmware %s. \n", name, gsl_firmware);
if (SCRIPT_PARSER_OK != script_parser_fetch("ctp_para", "ctp_twi_addr", &twi_addr, sizeof(twi_addr)/sizeof(__u32))) {
pr_err("%s: script_parser_fetch err. \n", name);
goto script_parser_fetch_err;
}
u_i2c_addr.dirty_addr_buf[0] = twi_addr;
u_i2c_addr.dirty_addr_buf[1] = I2C_CLIENT_END;
pr_info("%s: after: ctp_twi_addr is 0x%x, dirty_addr_buf: 0x%hx. dirty_addr_buf[1]: 0x%hx \n", __func__, twi_addr, u_i2c_addr.dirty_addr_buf[0], u_i2c_addr.dirty_addr_buf[1]);
if (SCRIPT_PARSER_OK != script_parser_fetch("ctp_para", "ctp_twi_id", &twi_id, sizeof(twi_id)/sizeof(__u32))) {
pr_err("%s: script_parser_fetch err. \n", name);
goto script_parser_fetch_err;
}
pr_info("%s: ctp_twi_id is %d. \n", __func__, twi_id);
if (SCRIPT_PARSER_OK != script_parser_fetch("ctp_para", "ctp_screen_max_x", &screen_max_x, 1)) {
pr_err("%s: script_parser_fetch err. \n", __func__);
goto script_parser_fetch_err;
}
pr_info("%s: screen_max_x = %d. \n", __func__, screen_max_x);
if (SCRIPT_PARSER_OK != script_parser_fetch("ctp_para", "ctp_screen_max_y", &screen_max_y, 1)) {
pr_err("%s: script_parser_fetch err. \n", __func__);
goto script_parser_fetch_err;
}
pr_info("%s: screen_max_y = %d. \n", __func__, screen_max_y);
if (SCRIPT_PARSER_OK != script_parser_fetch("ctp_para", "ctp_revert_x_flag", &revert_x_flag, 1)) {
pr_err("%s: script_parser_fetch err. \n", __func__);
goto script_parser_fetch_err;
}
pr_info("%s: revert_x_flag = %d. \n", __func__, revert_x_flag);
if (SCRIPT_PARSER_OK != script_parser_fetch("ctp_para", "ctp_revert_y_flag", &revert_y_flag, 1)) {
pr_err("%s: script_parser_fetch err. \n", __func__);
goto script_parser_fetch_err;
}
pr_info("%s: revert_y_flag = %d. \n", __func__, revert_y_flag);
if (SCRIPT_PARSER_OK != script_parser_fetch("ctp_para", "ctp_exchange_x_y_flag", &exchange_x_y_flag, 1)) {
pr_err("ft5x_ts: script_parser_fetch err. \n");
goto script_parser_fetch_err;
}
pr_info("%s: exchange_x_y_flag = %d. \n", __func__, exchange_x_y_flag);
return 0;
script_parser_fetch_err:
pr_notice("=========script_parser_fetch_err============\n");
return ret;
}
static void _free_platform_resource(void)
{
if (gpio_addr) {
iounmap(gpio_addr);
}
if (gpio_int_hdle) {
gpio_release(gpio_int_hdle, 2);
}
if (gpio_wakeup_hdle) {
gpio_release(gpio_wakeup_hdle, 2);
}
if (gpio_io_hdle) {
gpio_release(gpio_io_hdle, 2);
}
return;
}
static int _init_platform_resource(void)
{
int ret = 0;
gpio_addr = ioremap(PIO_BASE_ADDRESS, PIO_RANGE_SIZE);
if (!gpio_addr) {
ret = -EIO;
goto exit_ioremap_failed;
}
gpio_wakeup_hdle = gpio_request_ex("ctp_para", "ctp_wakeup");
if (!gpio_wakeup_hdle) {
pr_warning("%s: tp_wakeup request gpio fail!\n", __func__);
}
gpio_io_hdle = gpio_request_ex("ctp_para", "ctp_io_port");
if (!gpio_io_hdle) {
pr_warning("%s: tp_io request gpio fail!\n", __func__);
}
return ret;
exit_ioremap_failed:
_free_platform_resource();
return ret;
}
static void ctp_clear_penirq(void)
{
int reg_val;
//clear the IRQ_EINT29 interrupt pending
//pr_info("clear pend irq pending\n");
reg_val = readl(gpio_addr + PIO_INT_STAT_OFFSET);
//writel(reg_val,gpio_addr + PIO_INT_STAT_OFFSET);
//writel(reg_val&(1<<(IRQ_EINT21)),gpio_addr + PIO_INT_STAT_OFFSET);
if ((reg_val = (reg_val&(1<<(CTP_IRQ_NO))))) {
pr_info("==CTP_IRQ_NO=\n");
writel(reg_val,gpio_addr + PIO_INT_STAT_OFFSET);
}
return;
}
static int ctp_set_irq_mode(char *major_key, char *subkey, ext_int_mode int_mode)
{
int ret = 0;
__u32 reg_num = 0;
__u32 reg_addr = 0;
__u32 reg_val = 0;
//config gpio to int mode
pr_info("%s: config gpio to int mode. \n", __func__);
#ifndef SYSCONFIG_GPIO_ENABLE
#else
if (gpio_int_hdle) {
gpio_release(gpio_int_hdle, 2);
}
gpio_int_hdle = gpio_request_ex(major_key, subkey);
if (!gpio_int_hdle) {
pr_info("request tp_int_port failed. \n");
ret = -1;
goto request_tp_int_port_failed;
}
gpio_get_one_pin_status(gpio_int_hdle, gpio_int_info, subkey, 1);
pr_info("%s, %d: gpio_int_info, port = %d, port_num = %d. \n", __func__, __LINE__, \
gpio_int_info[0].port, gpio_int_info[0].port_num);
#endif
#ifdef AW_GPIO_INT_API_ENABLE
#else
pr_info(" INTERRUPT CONFIG\n");
reg_num = (gpio_int_info[0].port_num)%8;
reg_addr = (gpio_int_info[0].port_num)/8;
reg_val = readl(gpio_addr + int_cfg_addr[reg_addr]);
reg_val &= (~(7 << (reg_num * 4)));
reg_val |= (int_mode << (reg_num * 4));
writel(reg_val,gpio_addr+int_cfg_addr[reg_addr]);
ctp_clear_penirq();
reg_val = readl(gpio_addr+PIO_INT_CTRL_OFFSET);
reg_val |= (1 << (gpio_int_info[0].port_num));
writel(reg_val,gpio_addr+PIO_INT_CTRL_OFFSET);
udelay(1);
#endif
request_tp_int_port_failed:
return ret;
}
static const struct i2c_device_id gslx680_ts_id[] = {
{ GSLX680_I2C_NAME, 0 },
{}
};
MODULE_DEVICE_TABLE(i2c, gslx680_ts_id);
static int gsl_ts_init_ts(struct i2c_client *client, struct gsl_ts *ts)
{
struct input_dev *input_device;
int rc = 0;
printk("[GSLX680] Enter %s\n", __func__);
ts->dd = &devices[ts->device_id];
if (ts->device_id == 0) {
ts->dd->data_size = MAX_FINGERS * ts->dd->touch_bytes + ts->dd->touch_meta_data;
ts->dd->touch_index = 0;
}
ts->touch_data = kzalloc(ts->dd->data_size, GFP_KERNEL);
if (!ts->touch_data) {
pr_err("%s: Unable to allocate memory\n", __func__);
return -ENOMEM;
}
ts->prev_touches = 0;
input_device = input_allocate_device();
if (!input_device) {
rc = -ENOMEM;
goto error_alloc_dev;
}
ts->input = input_device;
input_device->name = GSLX680_I2C_NAME;
input_device->id.bustype = BUS_I2C;
input_device->dev.parent = &client->dev;
input_set_drvdata(input_device, ts);
set_bit(EV_ABS, input_device->evbit);
set_bit(EV_KEY, input_device->evbit);
set_bit(EV_SYN, input_device->evbit);
set_bit(ABS_X, input_device->absbit);
set_bit(ABS_Y, input_device->absbit);
set_bit(ABS_PRESSURE, input_device->absbit);
set_bit(ABS_MT_POSITION_X, input_device->absbit);
set_bit(ABS_MT_POSITION_Y, input_device->absbit);
set_bit(ABS_MT_TOUCH_MAJOR, input_device->absbit);
set_bit(ABS_MT_WIDTH_MAJOR, input_device->absbit);
set_bit(BTN_TOUCH, input_device->keybit);
set_bit(BTN_TOOL_DOUBLETAP, input_device->keybit);
set_bit(BTN_TOOL_TRIPLETAP, input_device->keybit);
set_bit(BTN_TOOL_QUADTAP, input_device->keybit);
set_bit(BTN_TOOL_QUINTTAP, input_device->keybit);
input_set_abs_params(input_device, ABS_X, 0, SCREEN_MAX_X, 0, 0);
input_set_abs_params(input_device, ABS_Y, 0, SCREEN_MAX_Y, 0, 0);
input_set_abs_params(input_device, ABS_PRESSURE, 0, PRESS_MAX, 0 , 0);
input_set_abs_params(input_device, ABS_MT_POSITION_X, 0, SCREEN_MAX_X, 0, 0);
input_set_abs_params(input_device, ABS_MT_POSITION_Y, 0, SCREEN_MAX_Y, 0, 0);
input_set_abs_params(input_device, ABS_MT_TOUCH_MAJOR, 0, PRESS_MAX, 0, 0);
input_set_abs_params(input_device, ABS_MT_WIDTH_MAJOR, 0, 200, 0, 0);
input_set_abs_params(input_device, ABS_MT_TRACKING_ID, 0, (MAX_CONTACTS+1), 0, 0);
input_mt_init_slots(input_device, (MAX_CONTACTS+1));
#ifdef HAVE_TOUCH_KEY
input_device->evbit[0] = BIT_MASK(EV_KEY);
for (i = 0; i < MAX_KEY_NUM; i++)
set_bit(key_array[i], input_device->keybit);
#endif
client->irq = IRQ_PORT;
ts->irq = client->irq;
rc = ctp_set_irq_mode("ctp_para", "ctp_int_port", CTP_IRQ_MODE);
if (0 != rc) {
pr_info("%s:ctp_set_irq_mode err.\n", __func__);
goto exit_set_irq_mode;
}
ts->wq = create_singlethread_workqueue("kworkqueue_ts");
if (!ts->wq) {
dev_err(&client->dev, "Could not create workqueue\n");
goto error_wq_create;
}
flush_workqueue(ts->wq);
INIT_WORK(&ts->work, gsl_ts_xy_worker);
rc = input_register_device(input_device);
if (rc)
goto error_unreg_device;
return 0;
error_unreg_device:
destroy_workqueue(ts->wq);
error_wq_create:
input_free_device(input_device);
exit_set_irq_mode:
enable_irq(IRQ_PORT);
error_alloc_dev:
kfree(ts->touch_data);
return rc;
}
static int gsl_ts_suspend(struct i2c_client *client, pm_message_t mesg)
{
struct gsl_ts *ts = i2c_get_clientdata(client);