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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
|
/*
* Copyright (C) 2010,Imagis Technology Co. Ltd. All Rights Reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include <linux/version.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/input.h>
#include <linux/interrupt.h>
#include <linux/i2c.h>
#include <linux/delay.h>
#include <linux/slab.h>
#include <linux/platform_device.h>
#include <linux/device.h>
#include <linux/mutex.h>
#include <linux/input/mt.h>
#include <linux/pm_runtime.h>
#if CONFIG_EXTCON_S2MM001B
#include <linux/extcon.h>
#endif
#include "ist30xxc.h"
#include "ist30xxc_update.h"
#include "ist30xxc_tracking.h"
#ifdef CONFIG_OF
#include <linux/of.h>
#include <linux/of_gpio.h>
#include <linux/of_device.h>
#endif
#if IST30XX_DEBUG
#include "ist30xxc_misc.h"
#endif
#if IST30XX_CMCS_TEST
#include "ist30xxc_cmcs.h"
#endif
#define MAX_ERR_CNT (100)
#define EVENT_TIMER_INTERVAL (HZ * timer_period_ms / 1000)
u32 event_ms = 0, timer_ms = 0;
static struct timer_list event_timer;
static struct timespec t_current; // ns
int timer_period_ms = 500; // 0.5sec
#if IST30XX_USE_KEY
int ist30xx_key_code[] = { 0, KEY_APPSELECT, KEY_BACK };
#endif
char *ist_vdd_name = "vddsim2";
struct ist30xx_data *ts_data;
EXPORT_SYMBOL(ts_data);
DEFINE_MUTEX(ist30xx_mutex);
#ifdef CONFIG_ARM64
struct class *sec_class;
EXPORT_SYMBOL(sec_class);
#endif
int ist30xx_dbg_level = IST30XX_DEBUG_LEVEL;
void tsp_printk(int level, const char *fmt, ...)
{
struct va_format vaf;
va_list args;
if (ist30xx_dbg_level < level)
return;
va_start(args, fmt);
vaf.fmt = fmt;
vaf.va = &args;
printk("%s %pV", IST30XX_DEBUG_TAG, &vaf);
va_end(args);
}
long get_milli_second(void)
{
ktime_get_ts(&t_current);
return t_current.tv_sec * 1000 + t_current.tv_nsec / 1000000;
}
int ist30xx_intr_wait(struct ist30xx_data *data, long ms)
{
long start_ms = get_milli_second();
long curr_ms = 0;
while (1) {
if (!data->irq_working)
break;
curr_ms = get_milli_second();
if ((curr_ms < 0) || (start_ms < 0) || (curr_ms - start_ms > ms)) {
tsp_info("%s() timeout(%dms)\n", __func__, ms);
return -EPERM;
}
msleep(2);
}
return 0;
}
void ist30xx_disable_irq(struct ist30xx_data *data)
{
if (likely(data->irq_enabled)) {
ist30xx_tracking(TRACK_INTR_DISABLE);
disable_irq(data->client->irq);
data->irq_enabled = 0;
data->status.event_mode = false;
}
}
void ist30xx_enable_irq(struct ist30xx_data *data)
{
if (likely(!data->irq_enabled)) {
ist30xx_tracking(TRACK_INTR_ENABLE);
enable_irq(data->client->irq);
msleep(10);
data->irq_enabled = 1;
data->status.event_mode = true;
}
}
void ist30xx_scheduled_reset(struct ist30xx_data *data)
{
if (likely(data->initialized))
schedule_delayed_work(&data->work_reset_check, 0);
}
static void ist30xx_request_reset(struct ist30xx_data *data)
{
data->irq_err_cnt++;
if (unlikely(data->irq_err_cnt >= data->max_irq_err_cnt)) {
tsp_info("%s()\n", __func__);
ist30xx_scheduled_reset(data);
data->irq_err_cnt = 0;
}
}
#define NOISE_MODE_TA (0)
#define NOISE_MODE_CALL (1)
#define NOISE_MODE_COVER (2)
#define NOISE_MODE_POWER (8)
void ist30xx_start(struct ist30xx_data *data)
{
if (data->initialized) {
data->scan_count = 0;
data->scan_retry = 0;
mod_timer(&event_timer, get_jiffies_64() + EVENT_TIMER_INTERVAL * 2);
}
ist30xx_write_cmd(data->client, IST30XX_HIB_CMD,
((eHCOM_SET_MODE_SPECIAL << 16) | (data->noise_mode & 0xFFFF)));
ist30xx_write_cmd(data->client, IST30XX_HIB_CMD,
((eHCOM_SET_LOCAL_MODEL << 16) | (TSP_LOCAL_CODE & 0xFFFF)));
tsp_info("%s(), local : %d, mode : 0x%x\n", __func__,
TSP_LOCAL_CODE & 0xFFFF, data->noise_mode & 0xFFFF);
if (data->report_rate >= 0) {
ist30xx_write_cmd(data->client, IST30XX_HIB_CMD,
((eHCOM_SET_TIME_ACTIVE << 16) | (data->report_rate & 0xFFFF)));
tsp_info(" active rate : %dus\n", data->report_rate);
}
if (data->idle_rate >= 0) {
ist30xx_write_cmd(data->client, IST30XX_HIB_CMD,
((eHCOM_SET_TIME_IDLE << 16) | (data->idle_rate & 0xFFFF)));
tsp_info(" idle rate : %dus\n", data->idle_rate);
}
#if IST30XX_JIG_MODE
if (data->jig_mode) {
ist30xx_write_cmd(data->client, IST30XX_HIB_CMD,
(eHCOM_SET_JIG_MODE << 16) | (IST30XX_JIG_TOUCH & 0xFFFF));
tsp_info(" jig mode start\n");
}
if (data->debug_mode || data->jig_mode) {
#else
if (data->debug_mode) {
#endif
ist30xx_write_cmd(data->client, IST30XX_HIB_CMD,
(eHCOM_SLEEP_MODE_EN << 16) | (IST30XX_DISABLE & 0xFFFF));
tsp_info(" debug mode start\n");
}
ist30xx_cmd_start_scan(data);
}
int ist30xx_get_ver_info(struct ist30xx_data *data)
{
int ret;
data->fw.prev.main_ver = data->fw.cur.main_ver;
data->fw.prev.fw_ver = data->fw.cur.fw_ver;
data->fw.prev.core_ver = data->fw.cur.core_ver;
data->fw.prev.test_ver = data->fw.cur.test_ver;
data->fw.cur.main_ver = 0;
data->fw.cur.fw_ver = 0;
data->fw.cur.core_ver = 0;
data->fw.cur.test_ver = 0;
ret = ist30xx_cmd_hold(data->client, 1);
if (unlikely(ret))
return ret;
ret = ist30xx_read_reg(data->client,
IST30XX_DA_ADDR(eHCOM_GET_VER_MAIN), &data->fw.cur.main_ver);
if (unlikely(ret))
goto err_get_ver;
ret = ist30xx_read_reg(data->client,
IST30XX_DA_ADDR(eHCOM_GET_VER_FW), &data->fw.cur.fw_ver);
if (unlikely(ret))
goto err_get_ver;
ret = ist30xx_read_reg(data->client,
IST30XX_DA_ADDR(eHCOM_GET_VER_CORE), &data->fw.cur.core_ver);
if (unlikely(ret))
goto err_get_ver;
ret = ist30xx_read_reg(data->client,
IST30XX_DA_ADDR(eHCOM_GET_VER_TEST), &data->fw.cur.test_ver);
if (unlikely(ret))
goto err_get_ver;
ret = ist30xx_cmd_hold(data->client, 0);
if (unlikely(ret))
goto err_get_ver;
tsp_info("IC version main: %x, fw: %x, test: %x, core: %x\n",
data->fw.cur.main_ver, data->fw.cur.fw_ver, data->fw.cur.test_ver,
data->fw.cur.core_ver);
return 0;
err_get_ver:
ist30xx_reset(data, false);
return ret;
}
#define CALIB_MSG_MASK (0xF0000FFF)
#define CALIB_MSG_VALID (0x80000CAB)
#define TRACKING_INTR_VALID (0x127EA597)
u32 tracking_intr_value = TRACKING_INTR_VALID;
int ist30xx_get_info(struct ist30xx_data *data)
{
int ret;
u32 calib_msg;
u32 ms;
mutex_lock(&ist30xx_mutex);
ist30xx_disable_irq(data);
#if IST30XX_INTERNAL_BIN
#if IST30XX_UPDATE_BY_WORKQUEUE
ist30xx_get_update_info(data, data->fw.buf, data->fw.buf_size);
#endif
ist30xx_get_tsp_info(data);
#else
ret = ist30xx_get_ver_info(data);
if (unlikely(ret))
goto get_info_end;
ret = ist30xx_get_tsp_info(data);
if (unlikely(ret))
goto get_info_end;
#endif // IST30XX_INTERNAL_BIN
ist30xx_print_info(data);
ret = ist30xx_read_cmd(data, eHCOM_GET_CAL_RESULT, &calib_msg);
if (likely(ret == 0)) {
tsp_info("calib status: 0x%08x\n", calib_msg);
ms = get_milli_second();
ist30xx_put_track_ms(ms);
ist30xx_put_track(&tracking_intr_value, 1);
ist30xx_put_track(&calib_msg, 1);
if ((calib_msg & CALIB_MSG_MASK) != CALIB_MSG_VALID ||
CALIB_TO_STATUS(calib_msg) > 0) {
ist30xx_calibrate(data, IST30XX_MAX_RETRY_CNT);
}
}
#if IST30XX_CHECK_CALIB
if (likely(!data->status.update)) {
ret = ist30xx_cmd_check_calib(data->client);
if (likely(!ret)) {
data->status.calib = 1;
data->status.calib_msg = 0;
event_ms = (u32)get_milli_second();
data->status.event_mode = true;
}
}
#else
ist30xx_start(data);
#endif
#if !(IST30XX_INTERNAL_BIN)
get_info_end:
#endif
ist30xx_enable_irq(data);
mutex_unlock(&ist30xx_mutex);
return ret;
}
#if IST30XX_GESTURE
#define GESTURE_MAGIC_STRING (0x4170CF00)
#define GESTURE_MAGIC_MASK (0xFFFFFF00)
#define GESTURE_MESSAGE_MASK (~GESTURE_MAGIC_MASK)
#define PARSE_GESTURE_MESSAGE(n) \
((n & GESTURE_MAGIC_MASK) == GESTURE_MAGIC_STRING ? \
(n & GESTURE_MESSAGE_MASK) : -EINVAL)
void ist30xx_gesture_cmd(struct ist30xx_data *data, int cmd)
{
tsp_info("Gesture cmd: %d\n", cmd);
switch (cmd) {
case 0x01:
input_report_key(data->input_dev, KEY_VOLUMEUP, 1);
input_sync(data->input_dev);
input_report_key(data->input_dev, KEY_VOLUMEUP, 0);
input_sync(data->input_dev);
break;
case 0x02:
input_report_key(data->input_dev, KEY_VOLUMEDOWN, 1);
input_sync(data->input_dev);
input_report_key(data->input_dev, KEY_VOLUMEDOWN, 0);
input_sync(data->input_dev);
break;
case 0x03:
input_report_key(data->input_dev, KEY_PREVIOUSSONG, 1);
input_sync(data->input_dev);
input_report_key(data->input_dev, KEY_PREVIOUSSONG, 0);
input_sync(data->input_dev);
break;
case 0x04:
input_report_key(data->input_dev, KEY_NEXTSONG, 1);
input_sync(data->input_dev);
input_report_key(data->input_dev, KEY_NEXTSONG, 0);
input_sync(data->input_dev);
break;
case 0x11:
input_report_key(data->input_dev, KEY_PLAYPAUSE, 1);
input_sync(data->input_dev);
input_report_key(data->input_dev, KEY_PLAYPAUSE, 0);
input_sync(data->input_dev);
break;
case 0x12:
input_report_key(data->input_dev, KEY_SCREENLOCK, 1);
input_sync(data->input_dev);
input_report_key(data->input_dev, KEY_SCREENLOCK, 0);
input_sync(data->input_dev);
break;
case 0x13:
input_report_key(data->input_dev, KEY_PLAYPAUSE, 1);
input_sync(data->input_dev);
input_report_key(data->input_dev, KEY_PLAYPAUSE, 0);
input_sync(data->input_dev);
break;
case 0x14:
input_report_key(data->input_dev, KEY_PLAYPAUSE, 1);
input_sync(data->input_dev);
input_report_key(data->input_dev, KEY_PLAYPAUSE, 0);
input_sync(data->input_dev);
break;
case 0x21:
input_report_key(data->input_dev, KEY_MUTE, 1);
input_sync(data->input_dev);
input_report_key(data->input_dev, KEY_MUTE, 0);
input_sync(data->input_dev);
break;
default:
break;
}
}
#endif
#define PRESS_MSG_MASK (0x01)
#define MULTI_MSG_MASK (0x02)
#define TOUCH_DOWN_MESSAGE ("p")
#define TOUCH_UP_MESSAGE ("r")
#define TOUCH_MOVE_MESSAGE (" ")
bool tsp_touched[IST30XX_MAX_MT_FINGERS] = { false, };
void print_tsp_event(struct ist30xx_data *data, finger_info *finger)
{
int idx = finger->bit_field.id - 1;
bool press;
press = PRESSED_FINGER(data->t_status, finger->bit_field.id);
if (press) {
if (tsp_touched[idx] == false) { // touch down
tsp_noti("%s%d (%d, %d)\n",
TOUCH_DOWN_MESSAGE, finger->bit_field.id,
finger->bit_field.x, finger->bit_field.y);
tsp_touched[idx] = true;
} else { // touch move
tsp_debug("%s%d (%d, %d)\n",
TOUCH_MOVE_MESSAGE, finger->bit_field.id,
finger->bit_field.x, finger->bit_field.y);
}
} else {
if (tsp_touched[idx] == true) { // touch up
tsp_noti("%s%d\n", TOUCH_UP_MESSAGE, finger->bit_field.id);
tsp_touched[idx] = false;
}
}
}
#if IST30XX_USE_KEY
#define PRESS_MSG_KEY (0x06)
bool tkey_pressed[IST30XX_MAX_KEYS] = { false, };
void print_tkey_event(struct ist30xx_data *data, int id)
{
int idx = id - 1;
bool press = PRESSED_KEY(data->t_status, id);
if (press) {
if (tkey_pressed[idx] == false) { // tkey down
tsp_noti("k %s%d\n", TOUCH_DOWN_MESSAGE, id);
tkey_pressed[idx] = true;
}
} else {
if (tkey_pressed[idx] == true) { // tkey up
tsp_noti("k %s%d\n", TOUCH_UP_MESSAGE, id);
tkey_pressed[idx] = false;
}
}
}
#endif
static void release_finger(struct ist30xx_data *data, int id)
{
input_mt_slot(data->input_dev, id - 1);
input_mt_report_slot_state(data->input_dev, MT_TOOL_FINGER, false);
ist30xx_tracking(TRACK_POS_FINGER + id);
tsp_info("%s() %d\n", __func__, id);
tsp_touched[id - 1] = false;
input_sync(data->input_dev);
}
#if IST30XX_USE_KEY
#define CANCEL_KEY (0xFF)
#define RELEASE_KEY (0)
static void release_key(struct ist30xx_data *data, int id, u8 key_status)
{
input_report_key(data->input_dev, ist30xx_key_code[id], key_status);
ist30xx_tracking(TRACK_POS_KEY + id);
tsp_info("%s() key%d, status: %d\n", __func__, id, key_status);
tkey_pressed[id - 1] = false;
input_sync(data->input_dev);
}
#endif
static void clear_input_data(struct ist30xx_data *data)
{
int id = 1;
u32 status;
status = PARSE_FINGER_STATUS(data->t_status);
while (status) {
if (status & 1)
release_finger(data, id);
status >>= 1;
id++;
}
#if IST30XX_USE_KEY
id = 1;
status = PARSE_KEY_STATUS(data->t_status);
while (status) {
if (status & 1)
release_key(data, id, RELEASE_KEY);
status >>= 1;
id++;
}
#endif
data->t_status = 0;
}
static int check_report_fingers(struct ist30xx_data *data, int finger_counts)
{
int i;
finger_info *fingers = (finger_info *)data->fingers;
/* current finger info */
for (i = 0; i < finger_counts; i++) {
if (unlikely((fingers[i].bit_field.x >= IST30XX_MAX_X) ||
(fingers[i].bit_field.y >= IST30XX_MAX_Y))) {
tsp_warn("Invalid touch data - %d: %d(%d, %d), 0x%08x\n", i,
fingers[i].bit_field.id,
fingers[i].bit_field.x,
fingers[i].bit_field.y,
fingers[i].full_field);
fingers[i].bit_field.id = 0;
ist30xx_tracking(TRACK_POS_UNKNOWN);
return -EPERM;
}
}
return 0;
}
static int check_valid_coord(u32 *msg, int cnt)
{
u8 *buf = (u8 *)msg;
u8 chksum1 = msg[0] >> 24;
u8 chksum2 = 0;
u32 tmp = msg[0];
msg[0] &= 0x00FFFFFF;
cnt *= IST30XX_DATA_LEN;
while (cnt--)
chksum2 += *buf++;
msg[0] = tmp;
if (chksum1 != chksum2) {
tsp_err("intr chksum: %02x, %02x\n", chksum1, chksum2);
return -EPERM;
}
return 0;
}
static void report_input_data(struct ist30xx_data *data, int finger_counts,
int key_counts)
{
int id;
bool press = false;
finger_info *fingers = (finger_info *)data->fingers;
#if IST30XX_JIG_MODE
u32 *z_values = (u32 *)data->z_values;
#endif
int idx = 0;
u32 status;
status = PARSE_FINGER_STATUS(data->t_status);
for (id = 0; id < IST30XX_MAX_MT_FINGERS; id++) {
press = (status & (1 << id)) ? true : false;
input_mt_slot(data->input_dev, id);
input_mt_report_slot_state(data->input_dev, MT_TOOL_FINGER, press);
fingers[idx].bit_field.id = id + 1;
print_tsp_event(data, &fingers[idx]);
if (press == false)
continue;
input_report_abs(data->input_dev, ABS_MT_POSITION_X,
fingers[idx].bit_field.x);
input_report_abs(data->input_dev, ABS_MT_POSITION_Y,
fingers[idx].bit_field.y);
input_report_abs(data->input_dev, ABS_MT_TOUCH_MAJOR,
fingers[idx].bit_field.area);
#if IST30XX_JIG_MODE
if (data->jig_mode)
input_report_abs(data->input_dev, ABS_MT_PRESSURE, z_values[idx]);
#endif
idx++;
}
#if IST30XX_USE_KEY
status = PARSE_KEY_STATUS(data->t_status);
for (id = 0; id < IST30XX_MAX_KEYS; id++) {
press = (status & (1 << id)) ? true : false;
input_report_key(data->input_dev, ist30xx_key_code[id + 1], press);
print_tkey_event(data, id + 1);
}
#endif // IST30XX_USE_KEY
data->irq_err_cnt = 0;
data->scan_retry = 0;
input_sync(data->input_dev);
}
/*
* CMD : CMD_GET_COORD
*
* 1st [31:24] [23:21] [20:16] [15:12] [11:10] [9:0]
* Checksum KeyCnt KeyStatus FingerCnt Rsvd. FingerStatus
* 2nd [31:28] [27:24] [23:12] [11:0]
* ID Area X Y
*/
#define TRACKING_INTR_DEBUG1_VALID (0x127A6E81)
#define TRACKING_INTR_DEBUG2_VALID (0x127A6E82)
#define TRACKING_INTR_DEBUG3_VALID (0x127A6E83)
u32 tracking_intr_debug_value = 0;
u32 intr_debug_addr, intr_debug2_addr, intr_debug3_addr = 0;
u32 intr_debug_size, intr_debug2_size, intr_debug3_size = 0;
static irqreturn_t ist30xx_irq_thread(int irq, void *ptr)
{
int i, ret;
int key_cnt, finger_cnt, read_cnt;
struct ist30xx_data *data = (struct ist30xx_data *)ptr;
int offset = 1;
#if IST30XX_STATUS_DEBUG
u32 touch_status;
#endif
u32 t_status;
u32 msg[IST30XX_MAX_MT_FINGERS * 2 + offset];
u32 ms;
data->irq_working = true;
if (unlikely(!data->irq_enabled))
goto irq_end;
ms = get_milli_second();
if (intr_debug_addr >= 0 && intr_debug_size > 0) {
tsp_noti("Intr_debug (addr: 0x%08x)\n", intr_debug_addr);
ist30xx_burst_read(data->client, IST30XX_DA_ADDR(intr_debug_addr),
&msg[0], intr_debug_size, true);
for (i = 0; i < intr_debug_size; i++) {
tsp_noti("\t%08x\n", msg[i]);
}
tracking_intr_debug_value = TRACKING_INTR_DEBUG1_VALID;
ist30xx_put_track_ms(ms);
ist30xx_put_track(&tracking_intr_debug_value, 1);
ist30xx_put_track(msg, intr_debug_size);
}
if (intr_debug2_addr >= 0 && intr_debug2_size > 0) {
tsp_noti("Intr_debug2 (addr: 0x%08x)\n", intr_debug2_addr);
ist30xx_burst_read(data->client, IST30XX_DA_ADDR(intr_debug2_addr),
&msg[0], intr_debug2_size, true);
for (i = 0; i < intr_debug2_size; i++) {
tsp_noti("\t%08x\n", msg[i]);
}
tracking_intr_debug_value = TRACKING_INTR_DEBUG2_VALID;
ist30xx_put_track_ms(ms);
ist30xx_put_track(&tracking_intr_debug_value, 1);
ist30xx_put_track(msg, intr_debug2_size);
}
memset(msg, 0, sizeof(msg));
ret = ist30xx_read_reg(data->client, IST30XX_HIB_INTR_MSG, msg);
if (unlikely(ret))
goto irq_err;
tsp_verb("intr msg: 0x%08x\n", *msg);
// TSP IC Exception
if (unlikely((*msg & IST30XX_EXCEPT_MASK) == IST30XX_EXCEPT_VALUE)) {
tsp_err("Occured IC exception(0x%02X)\n", *msg & 0xFF);
#if I2C_BURST_MODE
ret = ist30xx_burst_read(data->client,
IST30XX_HIB_COORD, &msg[offset], IST30XX_MAX_EXCEPT_SIZE, true);
#else
for (i = 0; i < IST30XX_MAX_EXCEPT_SIZE; i++) {
ret = ist30xx_read_reg(data->client,
IST30XX_HIB_COORD + (i * 4), &msg[i + offset]);
}
#endif
if (unlikely(ret))
tsp_err(" exception value read error(%d)\n", ret);
else
tsp_err(" exception value : 0x%08X, 0x%08X\n", msg[1], msg[2]);
goto irq_ic_err;
}
if (unlikely(*msg == 0 || *msg == 0xFFFFFFFF)) // Unknown CMD
goto irq_err;
event_ms = ms;
ist30xx_put_track_ms(event_ms);
ist30xx_put_track(&tracking_intr_value, 1);
ist30xx_put_track(msg, 1);
if (unlikely((*msg & CALIB_MSG_MASK) == CALIB_MSG_VALID)) {
data->status.calib_msg = *msg;
tsp_info("calib status: 0x%08x\n", data->status.calib_msg);
goto irq_end;
}
#if IST30XX_CMCS_TEST
if (unlikely(*msg == IST30XX_CMCS_MSG_VALID)) {
data->status.cmcs = 1;
tsp_info("cmcs status: 0x%08x\n", *msg);
goto irq_end;
}
#endif
#if IST30XX_GESTURE
ret = PARSE_GESTURE_MESSAGE(*msg);
if (unlikely(ret > 0)) {
tsp_info("Gesture ID: %d (0x%08x)\n", ret, *msg);
ist30xx_gesture_cmd(data, ret);
goto irq_end;
}
#endif
#if IST30XX_STATUS_DEBUG
ret = ist30xx_read_reg(data->client,
IST30XX_HIB_TOUCH_STATUS, &touch_status);
if (ret == 0) {
tsp_debug("ALG : 0x%08X\n", touch_status);
}
memset(data->fingers, 0, sizeof(data->fingers));
#endif
/* Unknown interrupt data for extend coordinate */
if (unlikely(!CHECK_INTR_STATUS(*msg)))
goto irq_err;
t_status = *msg;
key_cnt = PARSE_KEY_CNT(t_status);
finger_cnt = PARSE_FINGER_CNT(t_status);
if (unlikely((finger_cnt > data->max_fingers) ||
(key_cnt > data->max_keys))) {
tsp_warn("Invalid touch count - finger: %d(%d), key: %d(%d)\n",
finger_cnt, data->max_fingers, key_cnt, data->max_keys);
goto irq_err;
}
if (finger_cnt > 0) {
#if I2C_BURST_MODE
ret = ist30xx_burst_read(data->client,
IST30XX_HIB_COORD, &msg[offset], finger_cnt, true);
if (unlikely(ret))
goto irq_err;
for (i = 0; i < finger_cnt; i++)
data->fingers[i].full_field = msg[i + offset];
#else
for (i = 0; i < finger_cnt; i++) {
ret = ist30xx_read_reg(data->client,
IST30XX_HIB_COORD + (i * 4), &msg[i + offset]);
if (unlikely(ret))
goto irq_err;
data->fingers[i].full_field = msg[i + offset];
}
#endif // I2C_BURST_MODE
#if IST30XX_JIG_MODE
if (data->jig_mode) {
// z-values ram address define
ret = ist30xx_burst_read(data->client,
IST30XX_DA_ADDR(data->tags.zvalue_base),
data->z_values, finger_cnt, true);
}
#endif
ist30xx_put_track(msg + offset, finger_cnt);
for (i = 0; i < finger_cnt; i++) {
#if IST30XX_JIG_MODE
if (data->jig_mode)
tsp_verb("intr msg(%d): 0x%08x, %d\n",
i + offset, msg[i + offset], data->z_values[i]);
else
#endif
tsp_verb("intr msg(%d): 0x%08x\n", i + offset, msg[i + offset]);
}
}
read_cnt = finger_cnt + 1;
ret = check_valid_coord(&msg[0], read_cnt);
if (unlikely(ret))
goto irq_err;
ret = check_report_fingers(data, finger_cnt);
if (unlikely(ret))
goto irq_err;
data->t_status = t_status;
report_input_data(data, finger_cnt, key_cnt);
if (intr_debug3_addr >= 0 && intr_debug3_size > 0) {
tsp_noti("Intr_debug3 (addr: 0x%08x)\n", intr_debug3_addr);
ist30xx_burst_read(data->client, IST30XX_DA_ADDR(intr_debug3_addr),
&msg[0], intr_debug3_size, true);
for (i = 0; i < intr_debug3_size; i++) {
tsp_noti("\t%08x\n", msg[i]);
}
tracking_intr_debug_value = TRACKING_INTR_DEBUG3_VALID;
ist30xx_put_track_ms(ms);
ist30xx_put_track(&tracking_intr_debug_value, 1);
ist30xx_put_track(msg, intr_debug3_size);
}
goto irq_end;
irq_err:
tsp_err("intr msg: 0x%08x, ret: %d\n", msg[0], ret);
ist30xx_request_reset(data);
irq_end:
data->irq_working = false;
event_ms = (u32)get_milli_second();
return IRQ_HANDLED;
irq_ic_err:
ist30xx_scheduled_reset(data);
data->irq_working = false;
event_ms = (u32)get_milli_second();
return IRQ_HANDLED;
}
static int ist30xx_suspend(struct device *dev)
{
struct i2c_client *client = to_i2c_client(dev);
struct ist30xx_data *data = i2c_get_clientdata(client);
del_timer(&event_timer);
cancel_delayed_work_sync(&data->work_noise_protect);
cancel_delayed_work_sync(&data->work_reset_check);
cancel_delayed_work_sync(&data->work_debug_algorithm);
mutex_lock(&ist30xx_mutex);
ist30xx_disable_irq(data);
ist30xx_internal_suspend(data);
clear_input_data(data);
#if IST30XX_GESTURE
if (data->gesture) {
ist30xx_start(data);
data->status.noise_mode = false;
ist30xx_enable_irq(data);
}
#endif
mutex_unlock(&ist30xx_mutex);
return 0;
}
static int ist30xx_resume(struct device *dev)
{
struct i2c_client *client = to_i2c_client(dev);
struct ist30xx_data *data = i2c_get_clientdata(client);
data->noise_mode |= (1 << NOISE_MODE_POWER);
mutex_lock(&ist30xx_mutex);
ist30xx_internal_resume(data);
ist30xx_start(data);
ist30xx_enable_irq(data);
mutex_unlock(&ist30xx_mutex);
return 0;
}
#ifdef CONFIG_HAS_EARLYSUSPEND
static void ist30xx_early_suspend(struct early_suspend *h)
{
struct ist30xx_data *data = container_of(h, struct ist30xx_data,
early_suspend);
ist30xx_suspend(&data->client->dev);
}
static void ist30xx_late_resume(struct early_suspend *h)
{
struct ist30xx_data *data = container_of(h, struct ist30xx_data,
early_suspend);
ist30xx_resume(&data->client->dev);
}
#endif
void ist30xx_set_ta_mode(bool mode)
{
tsp_info("%s(), mode = %d\n", __func__, mode);
if (unlikely(mode == ((ts_data->noise_mode >> NOISE_MODE_TA) & 1)))
return;
if (mode)
ts_data->noise_mode |= (1 << NOISE_MODE_TA);
else
ts_data->noise_mode &= ~(1 << NOISE_MODE_TA);
#if IST30XX_TA_RESET
if (unlikely(ts_data->initialized))
ist30xx_scheduled_reset(ts_data);
#else
ist30xx_write_cmd(ts_data->client, IST30XX_HIB_CMD,
((eHCOM_SET_MODE_SPECIAL << 16) | (ts_data->noise_mode & 0xFFFF)));
#endif
ist30xx_tracking(mode ? TRACK_CMD_TACON : TRACK_CMD_TADISCON);
}
EXPORT_SYMBOL(ist30xx_set_ta_mode);
void ist30xx_set_call_mode(int mode)
{
tsp_info("%s(), mode = %d\n", __func__, mode);
if (unlikely(mode == ((ts_data->noise_mode >> NOISE_MODE_CALL) & 1)))
return;
if (mode)
ts_data->noise_mode |= (1 << NOISE_MODE_CALL);
else
ts_data->noise_mode &= ~(1 << NOISE_MODE_CALL);
#if IST30XX_TA_RESET
if (unlikely(ts_data->initialized))
ist30xx_scheduled_reset(ts_data);
#else
ist30xx_write_cmd(ts_data->client, IST30XX_HIB_CMD,
((eHCOM_SET_MODE_SPECIAL << 16) | (ts_data->noise_mode & 0xFFFF)));
#endif
ist30xx_tracking(mode ? TRACK_CMD_CALL : TRACK_CMD_NOTCALL);
}
EXPORT_SYMBOL(ist30xx_set_call_mode);
void ist30xx_set_cover_mode(int mode)
{
tsp_info("%s(), mode = %d\n", __func__, mode);
if (unlikely(mode == ((ts_data->noise_mode >> NOISE_MODE_COVER) & 1)))
return;
if (mode)
ts_data->noise_mode |= (1 << NOISE_MODE_COVER);
else
ts_data->noise_mode &= ~(1 << NOISE_MODE_COVER);
#if IST30XX_TA_RESET
if (unlikely(ts_data->initialized))
ist30xx_scheduled_reset(ts_data);
#else
ist30xx_write_cmd(ts_data->client, IST30XX_HIB_CMD,
((eHCOM_SET_MODE_SPECIAL << 16) | (ts_data->noise_mode & 0xFFFF)));
#endif
ist30xx_tracking(mode ? TRACK_CMD_COVER : TRACK_CMD_NOTCOVER);
}
EXPORT_SYMBOL(ist30xx_set_cover_mode);
static void reset_work_func(struct work_struct *work)
{
struct delayed_work *delayed_work = to_delayed_work(work);
struct ist30xx_data *data = container_of(delayed_work,
struct ist30xx_data, work_reset_check);
if (unlikely((data == NULL) || (data->client == NULL)))
return;
tsp_info("Request reset function\n");
if (likely((data->initialized == 1) && (data->status.power == 1) &&
(data->status.update != 1) && (data->status.calib != 1))) {
mutex_lock(&ist30xx_mutex);
ist30xx_disable_irq(data);
#if IST30XX_GESTURE
if (data->suspend)
ist30xx_internal_suspend(data);
else
#endif
ist30xx_reset(data, false);
clear_input_data(data);
ist30xx_start(data);
#if IST30XX_GESTURE
if (data->gesture && data->suspend)
data->status.noise_mode = false;
#endif
ist30xx_enable_irq(data);
mutex_unlock(&ist30xx_mutex);
}
}
#if IST30XX_INTERNAL_BIN
#if IST30XX_UPDATE_BY_WORKQUEUE
static void fw_update_func(struct work_struct *work)
{
struct delayed_work *delayed_work = to_delayed_work(work);
struct ist30xx_data *data = container_of(delayed_work,
struct ist30xx_data, work_fw_update);
if (unlikely((data == NULL) || (data->client == NULL)))
return;
tsp_info("FW update function\n");
if (likely(ist30xx_auto_bin_update(data)))
ist30xx_disable_irq(data);
}
#endif // IST30XX_UPDATE_BY_WORKQUEUE
#endif // IST30XX_INTERNAL_BIN
#define TOUCH_STATUS_MAGIC (0x00000075)
#define TOUCH_STATUS_MASK (0x000000FF)
#define FINGER_ENABLE_MASK (0x00100000)
#define SCAN_CNT_MASK (0xFFE00000)
#define GET_FINGER_ENABLE(n) ((n & FINGER_ENABLE_MASK) >> 20)
#define GET_SCAN_CNT(n) ((n & SCAN_CNT_MASK) >> 21)
u32 ist30xx_algr_addr = 0, ist30xx_algr_size = 0;
static void noise_work_func(struct work_struct *work)
{
int ret;
u32 touch_status = 0;
u32 scan_count = 0;
struct delayed_work *delayed_work = to_delayed_work(work);
struct ist30xx_data *data = container_of(delayed_work,
struct ist30xx_data, work_noise_protect);
ret = ist30xx_read_reg(data->client,
IST30XX_HIB_TOUCH_STATUS, &touch_status);
if (unlikely(ret)) {
tsp_warn("Touch status read fail!\n");
goto retry_timer;
}
ist30xx_put_track_ms(timer_ms);
ist30xx_put_track(&touch_status, 1);
tsp_verb("Touch Info: 0x%08x\n", touch_status);
/* Check valid scan count */
if (unlikely((touch_status & TOUCH_STATUS_MASK) != TOUCH_STATUS_MAGIC)) {
tsp_warn("Touch status is not corrected! (0x%08x)\n", touch_status);
goto retry_timer;
}
/* Status of IC is idle */
if (GET_FINGER_ENABLE(touch_status) == 0) {
if ((PARSE_FINGER_CNT(data->t_status) > 0) ||
(PARSE_KEY_CNT(data->t_status) > 0))
clear_input_data(data);
}
scan_count = GET_SCAN_CNT(touch_status);
/* Status of IC is lock-up */
if (unlikely(scan_count == data->scan_count)) {
tsp_warn("TSP IC is not responded! (0x%08x)\n", scan_count);
goto retry_timer;
}
data->scan_retry = 0;
data->scan_count = scan_count;
return;
retry_timer:
data->scan_retry++;
tsp_warn("Retry touch status!(%d)\n", data->scan_retry);
if (unlikely(data->scan_retry == data->max_scan_retry)) {
ist30xx_scheduled_reset(data);
data->scan_retry = 0;
}
}
static void debug_work_func(struct work_struct *work)
{
#if IST30XX_ALGORITHM_MODE
int ret = -EPERM;
int i;
u32 *buf32;
struct delayed_work *delayed_work = to_delayed_work(work);
struct ist30xx_data *data = container_of(delayed_work,
struct ist30xx_data, work_debug_algorithm);
buf32 = kzalloc(ist30xx_algr_size, GFP_KERNEL);
for (i = 0; i < ist30xx_algr_size; i++) {
ret = ist30xx_read_buf(data->client,
ist30xx_algr_addr + IST30XX_DATA_LEN * i, &buf32[i], 1);
if (ret) {
tsp_warn("Algorithm mem addr read fail!\n");
return;
}
}
ist30xx_put_track(buf32, ist30xx_algr_size);
tsp_debug(" 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
buf32[0], buf32[1], buf32[2], buf32[3], buf32[4]);
#endif
}
void timer_handler(unsigned long timer_data)
{
struct ist30xx_data *data = (struct ist30xx_data *)timer_data;
struct ist30xx_status *status = &data->status;
if (data->irq_working)
goto restart_timer;
if (status->event_mode) {
if (likely((status->power == 1) && (status->update != 1))) {
timer_ms = (u32)get_milli_second();
if (unlikely(status->calib == 1)) { // Check calibration
if ((status->calib_msg & CALIB_MSG_MASK) == CALIB_MSG_VALID) {
tsp_info("Calibration check OK!!\n");
schedule_delayed_work(&data->work_reset_check, 0);
status->calib = 0;
} else if (timer_ms - event_ms >= 3000) { // 3second
tsp_info("calibration timeout over 3sec\n");
schedule_delayed_work(&data->work_reset_check, 0);
status->calib = 0;
}
} else if (likely(status->noise_mode)) {
if (timer_ms - event_ms > 100) // 100ms after last interrupt
schedule_delayed_work(&data->work_noise_protect, 0);
}
#if IST30XX_ALGORITHM_MODE
if ((ist30xx_algr_addr >= IST30XX_DIRECT_ACCESS) &&
(ist30xx_algr_size > 0)) {
if (timer_ms - event_ms > 100) // 100ms after last interrupt
schedule_delayed_work(&data->work_debug_algorithm, 0);
}
#endif
}
}
restart_timer:
mod_timer(&event_timer, get_jiffies_64() + EVENT_TIMER_INTERVAL);
}
extern struct class *ist30xx_class;
#if SEC_FACTORY_MODE
extern struct class *sec_class;
extern int sec_touch_sysfs(struct ist30xx_data *data);
extern int sec_fac_cmd_init(struct ist30xx_data *data);
#endif
static int ist30xx_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
int ret;
int retry = 3;
#ifdef CONFIG_OF
struct device_node *np = client->dev.of_node;
struct ist30xx_platform_data *pdata;
#endif
struct ist30xx_data *data;
struct input_dev *input_dev;
int ist_gpio = 0;
tsp_info("### IMAGIS probe(ver:%s, protocol:%X, addr:0x%02X) ###\n",
IMAGIS_DD_VERSION, IMAGIS_PROTOCOL_B, client->addr);
if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
printk(KERN_INFO "i2c_check_functionality error\n");
return -EIO;
}
data = kzalloc(sizeof(*data), GFP_KERNEL);
if (!data)
return -ENOMEM;
#ifdef CONFIG_OF
// TODO: load device tree
tsp_info("the client->dev.of_node=0x%x\n", client->dev.of_node);
if (client->dev.of_node){
ist_gpio = of_get_gpio(np, 0);
of_property_read_string(np, "tsp_pwr_name", &ist_vdd_name);
tsp_info("gpio id=%d,power name:%s\n", ist_gpio,ist_vdd_name);
}
#endif
input_dev = input_allocate_device();
if (unlikely(!input_dev)) {
ret = -ENOMEM;
tsp_err("%s(), input_allocate_device failed (%d)\n",
__func__, ret);
goto err_alloc_dev;
}
#ifndef CONFIG_OF
ist_gpio = 82;
ist_vdd_name = "vddsim2";
#endif
/* configure touchscreen interrupt gpio */
ret = gpio_request(ist_gpio, "ist30xx_irq_gpio");
printk("[TSP]request gpio id = %d\n", ist_gpio);
if (ret) {
tsp_err("unable to request gpio.(%s)\r\n",input_dev->name);
goto err_init_drv;
}
client->irq = gpio_to_irq(ist_gpio);
tsp_info("client->irq : %d\n", client->irq);
data->max_fingers = IST30XX_MAX_MT_FINGERS;
data->max_keys = IST30XX_MAX_KEYS;
data->irq_enabled = 1;
data->client = client;
data->input_dev = input_dev;
i2c_set_clientdata(client, data);
input_mt_init_slots(input_dev, IST30XX_MAX_MT_FINGERS, 0);
input_dev->name = "ist30xx_ts_input";
input_dev->id.bustype = BUS_I2C;
input_dev->dev.parent = &client->dev;
set_bit(EV_ABS, input_dev->evbit);
set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
input_set_abs_params(data->input_dev, ABS_MT_POSITION_X,
0, IST30XX_MAX_X - 1, 0, 0);
input_set_abs_params(data->input_dev, ABS_MT_POSITION_Y,
0, IST30XX_MAX_Y - 1, 0, 0);
input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, IST30XX_MAX_W, 0, 0);
#if IST30XX_JIG_MODE
input_set_abs_params(input_dev, ABS_MT_PRESSURE, 0, 0, 0, 0);
#endif
#if IST30XX_USE_KEY
{
int i;
set_bit(EV_KEY, input_dev->evbit);
set_bit(EV_SYN, input_dev->evbit);
for (i = 1; i < ARRAY_SIZE(ist30xx_key_code); i++)
set_bit(ist30xx_key_code[i], input_dev->keybit);
}
#if IST30XX_GESTURE
input_set_capability(input_dev, EV_KEY, KEY_POWER);
input_set_capability(input_dev, EV_KEY, KEY_PLAYPAUSE);
input_set_capability(input_dev, EV_KEY, KEY_NEXTSONG);
input_set_capability(input_dev, EV_KEY, KEY_PREVIOUSSONG);
input_set_capability(input_dev, EV_KEY, KEY_VOLUMEUP);
input_set_capability(input_dev, EV_KEY, KEY_VOLUMEDOWN);
input_set_capability(input_dev, EV_KEY, KEY_MUTE);
#endif
#endif
input_set_drvdata(input_dev, data);
ret = input_register_device(input_dev);
if (unlikely(ret)) {
input_free_device(input_dev);
goto err_reg_dev;
}
#ifdef CONFIG_HAS_EARLYSUSPEND
data->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
data->early_suspend.suspend = ist30xx_early_suspend;
data->early_suspend.resume = ist30xx_late_resume;
register_early_suspend(&data->early_suspend);
#endif
ts_data = data;
ret = ist30xx_init_system(data);
if (unlikely(ret)) {
tsp_err("chip initialization failed\n");
goto err_init_drv;
}
ret = request_threaded_irq(client->irq, NULL, ist30xx_irq_thread,
IRQF_TRIGGER_FALLING | IRQF_ONESHOT, "ist30xx_ts", data);
if (unlikely(ret))
goto err_init_drv;
ist30xx_disable_irq(data);
while (retry-- > 0) {
ret = ist30xx_read_cmd(data, IST30XX_REG_CHIPID, &data->chip_id);
data->chip_id &= 0xFFFF;
if (unlikely(ret == 0)) {
if ((data->chip_id == IST30XX_CHIP_ID) ||
(data->chip_id == IST30XXC_DEFAULT_CHIP_ID) ||
(data->chip_id == IST3048C_DEFAULT_CHIP_ID)) {
break;
}
} else if (unlikely(retry == 0)) {
goto err_irq;
}
ist30xx_reset(data, false);
}
#if (IMAGIS_TSP_IC < IMAGIS_IST3038C)
retry = 3;
data->tsp_type = TSP_TYPE_UNKNOWN;
while (retry-- > 0) {
ret = ist30xx_read_cmd(data, IST30XX_REG_TSPTYPE, &data->tsp_type);
if (likely(ret == 0)) {
data->tsp_type = IST30XX_PARSE_TSPTYPE(data->tsp_type);
tsp_info("tsptype: %x\n", data->tsp_type);
break;
}
if (unlikely(retry == 0))
goto err_irq;
}
tsp_info("TSP IC: %x, TSP Vendor: %x\n", data->chip_id, data->tsp_type);
#else
tsp_info("TSP IC: %x\n", data->chip_id);
#endif
data->status.event_mode = false;
#if IST30XX_INTERNAL_BIN
#if IST30XX_UPDATE_BY_WORKQUEUE
INIT_DELAYED_WORK(&data->work_fw_update, fw_update_func);
schedule_delayed_work(&data->work_fw_update, IST30XX_UPDATE_DELAY);
#else
ret = ist30xx_auto_bin_update(data);
if (unlikely(ret != 0))
goto err_irq;
#endif // IST30XX_UPDATE_BY_WORKQUEUE
#endif // IST30XX_INTERNAL_BIN
ret = ist30xx_init_update_sysfs(data);
if (unlikely(ret))
goto err_sysfs;
#if IST30XX_DEBUG
ret = ist30xx_init_misc_sysfs(data);
if (unlikely(ret))
goto err_sysfs;
#endif
#if IST30XX_CMCS_TEST
ret = ist30xx_init_cmcs_sysfs(data);
if (unlikely(ret))
goto err_sysfs;
#endif
#if IST30XX_TRACKING_MODE
ret = ist30xx_init_tracking_sysfs();
if (unlikely(ret))
goto err_sysfs;
#endif
#if SEC_FACTORY_MODE
ret = sec_fac_cmd_init(data);
if (unlikely(ret))
goto err_sysfs;
ret = sec_touch_sysfs(data);
if (unlikely(ret))
goto err_sysfs;
#endif
// INIT VARIABLE (DEFAULT)
#if IST30XX_GESTURE
data->suspend = false;
data->gesture = false;
#endif
data->irq_working = false;
data->max_scan_retry = 2;
data->max_irq_err_cnt = MAX_ERR_CNT;
data->report_rate = -1;
data->idle_rate = -1;
INIT_DELAYED_WORK(&data->work_reset_check, reset_work_func);
INIT_DELAYED_WORK(&data->work_noise_protect, noise_work_func);
INIT_DELAYED_WORK(&data->work_debug_algorithm, debug_work_func);
init_timer(&event_timer);
event_timer.data = (unsigned long)data;
event_timer.function = timer_handler;
event_timer.expires = jiffies_64 + (EVENT_TIMER_INTERVAL);
mod_timer(&event_timer, get_jiffies_64() + EVENT_TIMER_INTERVAL * 2);
ret = ist30xx_get_info(data);
tsp_info("Get info: %s\n", (ret == 0 ? "success" : "fail"));
data->initialized = true;
pm_runtime_enable(&client->dev);
tsp_info("### IMAGIS probe success ###\n");
return 0;
err_sysfs:
class_destroy(ist30xx_class);
err_irq:
tsp_info("ChipID: %x\n", data->chip_id);
ist30xx_disable_irq(data);
free_irq(client->irq, data);
err_init_drv:
data->status.event_mode = false;
ist30xx_power_off(data);
#ifdef CONFIG_HAS_EARLYSUSPEND
unregister_early_suspend(&data->early_suspend);
#endif
input_unregister_device(input_dev);
err_reg_dev:
err_alloc_dev:
kfree(data);
tsp_err("Error, ist30xx init driver\n");
return -ENODEV;
}
static int ist30xx_remove(struct i2c_client *client)
{
struct ist30xx_data *data = i2c_get_clientdata(client);
#ifdef CONFIG_HAS_EARLYSUSPEND
unregister_early_suspend(&data->early_suspend);
#endif
ist30xx_disable_irq(data);
free_irq(client->irq, data);
ist30xx_power_off(data);
input_unregister_device(data->input_dev);
kfree(data);
return 0;
}
static void ist30xx_shutdown(struct i2c_client *client)
{
struct ist30xx_data *data = i2c_get_clientdata(client);
del_timer(&event_timer);
cancel_delayed_work_sync(&data->work_noise_protect);
cancel_delayed_work_sync(&data->work_reset_check);
cancel_delayed_work_sync(&data->work_debug_algorithm);
mutex_lock(&ist30xx_mutex);
ist30xx_disable_irq(data);
ist30xx_internal_suspend(data);
clear_input_data(data);
mutex_unlock(&ist30xx_mutex);
}
static struct i2c_device_id ist30xx_idtable[] = {
{ IST30XX_DEV_NAME, 0 },
{},
};
MODULE_DEVICE_TABLE(i2c, ist30xx_idtable);
#ifdef CONFIG_OF
static struct of_device_id ist30xx_match_table[] = {
{ .compatible = "Imagis,IST30XXC", },
{ },
};
#else
#define ist30xx_match_table NULL
#endif
#ifndef CONFIG_HAS_EARLYSUSPEND
static const struct dev_pm_ops ist30xx_pm_ops = {
SET_RUNTIME_PM_OPS(ist30xx_suspend, ist30xx_resume, NULL)
};
#endif
static struct i2c_driver ist30xx_i2c_driver = {
.id_table = ist30xx_idtable,
.probe = ist30xx_probe,
.remove = ist30xx_remove,
.shutdown = ist30xx_shutdown,
.driver = {
.owner = THIS_MODULE,
.name = IST30XX_DEV_NAME,
.of_match_table = ist30xx_match_table,
#ifndef CONFIG_HAS_EARLYSUSPEND
.pm = &ist30xx_pm_ops,
#endif
},
};
static int __init ist30xx_init(void)
{
#ifdef CONFIG_ARM64
sec_class = class_create(THIS_MODULE, "sec");
if (IS_ERR(sec_class)) {
pr_err("Failed to create class(sec)!\n");
printk("Failed create class \n");
return PTR_ERR(sec_class);
}
#endif
return i2c_add_driver(&ist30xx_i2c_driver);
}
static void __exit ist30xx_exit(void)
{
i2c_del_driver(&ist30xx_i2c_driver);
}
module_init(ist30xx_init);
module_exit(ist30xx_exit);
#if CONFIG_EXTCON_S2MM001B
static int extcon_notifier(struct notifier_block *nb,
unsigned long state, void *edev)
{
ist30xx_set_ta_mode(extcon_get_state(edev));
return NOTIFY_OK;
}
static int ta_init_detect(void)
{
struct extcon_dev *edev = NULL;
static struct notifier_block nb;
if (!ts_data)
return -EPERM;
edev = extcon_get_extcon_dev("s2mm001b");
if (!edev) {
pr_err("Failed to get extcon dev\n");
return -ENXIO;
}
nb.notifier_call = extcon_notifier;
extcon_register_notifier(edev, &nb);
return 0;
}
late_initcall(ta_init_detect);
#endif
MODULE_DESCRIPTION("Imagis IST30XX touch driver");
MODULE_LICENSE("GPL");
|