-
Notifications
You must be signed in to change notification settings - Fork 0
/
goodix_ts_inspect.c
2987 lines (2662 loc) · 82.9 KB
/
goodix_ts_inspect.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
/*
* Goodix Touchscreen Driver
* Copyright (C) 2020 - 2021 Goodix, Inc.
*
* Copyright (C) 2022 XiaoMi, Inc.
*
* 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 a reference
* to you, when you are integrating the GOODiX's CTP IC into your system,
* 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 "goodix_ts_core.h"
#include <linux/rtc.h>
#include <linux/timer.h>
#include <linux/version.h>
#include <linux/fs.h>
#include <asm/uaccess.h>
#include <linux/string.h>
/* test config */
#define TOTAL_FRAME_NUM 16 /* rawdata test frames */
#define NOISEDATA_TEST_TIMES 10 /* noise test frames */
#define SAVE_IN_CSV
#define GOODIX_RESULT_SAVE_PATH "/data/misc/tp_selftest_data/Test_Data.csv"
#define GOODIX_TEST_FILE_NAME "goodix"
#define MAX_DATA_BUFFER 28000
#define MAX_SHORT_NUM 15
#define MAX_LINE_LEN (1024 * 3 * 7)
#define MAX_DRV_NUM 52
#define MAX_SEN_NUM 75
#define STATISTICS_DATA_LEN 32
#define MAX_STR_LEN 32
#define MAX_TEST_ITEMS 10 /* 0P-1P-2P-3P-5P total test items */
#define GTP_CAP_TEST 1
#define GTP_DELTA_TEST 2
#define GTP_NOISE_TEST 3
#define GTP_SHORT_TEST 5
#define GTP_SELFCAP_TEST 6
#define GTP_SELFNOISE_TEST 7
#define GTP_TEST_PASS 1
#define GTP_PANEL_REASON 2
#define SYS_SOFTWARE_REASON 3
#define CHN_VDD 0xFF
#define CHN_GND 0x7F
#define DRV_CHANNEL_FLAG 0x80
#define CSV_TP_SPECIAL_RAW_MIN "special_raw_min"
#define CSV_TP_SPECIAL_RAW_MAX "special_raw_max"
#define CSV_TP_SPECIAL_RAW_DELTA "special_raw_delta"
#define CSV_TP_SHORT_THRESHOLD "shortciurt_threshold"
#define CSV_TP_SPECIAL_SELFRAW_MAX "special_selfraw_max"
#define CSV_TP_SPECIAL_SELFRAW_MIN "special_selfraw_min"
#define CSV_TP_NOISE_LIMIT "noise_data_limit"
#define CSV_TP_SELFNOISE_LIMIT "noise_selfdata_limit"
#define CSV_TP_TEST_CONFIG "test_config"
#define MAX_TEST_TIME_MS 15000
#define DEFAULT_TEST_TIME_MS 7000
/* berlin A */
#define MAX_DRV_NUM_BRA 21
#define MAX_SEN_NUM_BRA 42
#define SHORT_TEST_TIME_REG_BRA 0x11FF2
#define DFT_ADC_DUMP_NUM_BRA 1396
#define DFT_SHORT_THRESHOLD_BRA 16
#define DFT_DIFFCODE_SHORT_THRESHOLD_BRA 16
#define SHORT_TEST_STATUS_REG_BRA 0x10400
#define SHORT_TEST_RESULT_REG_BRA 0x10410
#define DRV_DRV_SELFCODE_REG_BRA 0x1045E
#define SEN_SEN_SELFCODE_REG_BRA 0x1084E
#define DRV_SEN_SELFCODE_REG_BRA 0x11712
#define DIFF_CODE_DATA_REG_BRA 0x11F72
/* berlin B */
#define MAX_DRV_NUM_BRB 52
#define MAX_SEN_NUM_BRB 75
#define SHORT_TEST_TIME_REG_BRB 0x26AE0
#define DFT_ADC_DUMP_NUM_BRB 762
#define DFT_SHORT_THRESHOLD_BRB 100
#define DFT_DIFFCODE_SHORT_THRESHOLD_BRB 32
#define SHORT_TEST_STATUS_REG_BRB 0x20400
#define SHORT_TEST_RESULT_REG_BRB 0x20410
#define DRV_DRV_SELFCODE_REG_BRB 0x2049A
#define SEN_SEN_SELFCODE_REG_BRB 0x21AF2
#define DRV_SEN_SELFCODE_REG_BRB 0x248A6
#define DIFF_CODE_DATA_REG_BRB 0x269E0
/* berlinD */
#define MAX_DRV_NUM_BRD 20
#define MAX_SEN_NUM_BRD 40
#define SHORT_TEST_TIME_REG_BRD 0x14D7A
#define DFT_ADC_DUMP_NUM_BRD 762
#define DFT_SHORT_THRESHOLD_BRD 100
#define DFT_DIFFCODE_SHORT_THRESHOLD_BRD 32
#define SHORT_TEST_STATUS_REG_BRD 0x13400
#define SHORT_TEST_RESULT_REG_BRD 0x13408
#define DRV_DRV_SELFCODE_REG_BRD 0x1344E
#define SEN_SEN_SELFCODE_REG_BRD 0x137E6
#define DRV_SEN_SELFCODE_REG_BRD 0x14556
#define DIFF_CODE_DATA_REG_BRD 0x14D00
#define ABS(val) ((val < 0)? -(val) : val)
#define MAX(a, b) ((a > b)? a : b)
static bool module_initialized;
/* berlin A drv-sen map */
static u8 brl_a_drv_map[] = {
42, 43, 44, 45, 46, 47, 48, 49,
50, 51, 52, 53, 54, 55, 56, 57,
58, 59, 60, 61, 62
};
static u8 brl_a_sen_map[] = {
0, 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
};
/* berlin B drv-sen map */
static u8 brl_b_drv_map[] = {
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
};
static u8 brl_b_sen_map[] = {
0, 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
};
/* berlin D drv-sen map */
static u8 brl_d_drv_map[] = {
40, 41, 42, 43, 44, 45, 46, 47,
48, 49, 50, 51, 52, 53, 54, 55,
56, 57, 58, 59,
};
static u8 brl_d_sen_map[] = {
0, 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,
};
typedef struct __attribute__((packed)) {
u8 result;
u8 drv_drv_num;
u8 sen_sen_num;
u8 drv_sen_num;
u8 drv_gnd_avdd_num;
u8 sen_gnd_avdd_num;
u16 checksum;
} test_result_t;
struct params_info_t {
u32 max_drv_num;
u32 max_sen_num;
u8 *drv_map;
u8 *sen_map;
u32 short_test_time_reg;
u32 short_test_status_reg;
u32 short_test_result_reg;
u32 drv_drv_selfcode_reg;
u32 sen_sen_selfcode_reg;
u32 drv_sen_selfcode_reg;
u32 diffcode_data_reg;
u16 short_test_dump_num;
u16 dft_short_threshold;
u16 short_diffcode_threshold;
};
struct params_info_t params_bra = {
MAX_DRV_NUM_BRA,
MAX_SEN_NUM_BRA,
brl_a_drv_map,
brl_a_sen_map,
SHORT_TEST_TIME_REG_BRA,
SHORT_TEST_STATUS_REG_BRA,
SHORT_TEST_RESULT_REG_BRA,
DRV_DRV_SELFCODE_REG_BRA,
SEN_SEN_SELFCODE_REG_BRA,
DRV_SEN_SELFCODE_REG_BRA,
DIFF_CODE_DATA_REG_BRA,
DFT_ADC_DUMP_NUM_BRA,
DFT_SHORT_THRESHOLD_BRA,
DFT_DIFFCODE_SHORT_THRESHOLD_BRA,
};
struct params_info_t params_brb = {
MAX_DRV_NUM_BRB,
MAX_SEN_NUM_BRB,
brl_b_drv_map,
brl_b_sen_map,
SHORT_TEST_TIME_REG_BRB,
SHORT_TEST_STATUS_REG_BRB,
SHORT_TEST_RESULT_REG_BRB,
DRV_DRV_SELFCODE_REG_BRB,
SEN_SEN_SELFCODE_REG_BRB,
DRV_SEN_SELFCODE_REG_BRB,
DIFF_CODE_DATA_REG_BRB,
DFT_ADC_DUMP_NUM_BRB,
DFT_SHORT_THRESHOLD_BRB,
DFT_DIFFCODE_SHORT_THRESHOLD_BRB,
};
struct params_info_t params_brd = {
MAX_DRV_NUM_BRD,
MAX_SEN_NUM_BRD,
brl_d_drv_map,
brl_d_sen_map,
SHORT_TEST_TIME_REG_BRD,
SHORT_TEST_STATUS_REG_BRD,
SHORT_TEST_RESULT_REG_BRD,
DRV_DRV_SELFCODE_REG_BRD,
SEN_SEN_SELFCODE_REG_BRD,
DRV_SEN_SELFCODE_REG_BRD,
DIFF_CODE_DATA_REG_BRD,
DFT_ADC_DUMP_NUM_BRD,
DFT_SHORT_THRESHOLD_BRD,
DFT_DIFFCODE_SHORT_THRESHOLD_BRD,
};
struct ts_test_params {
bool test_items[MAX_TEST_ITEMS];
u32 rawdata_addr;
u32 noisedata_addr;
u32 self_rawdata_addr;
u32 self_noisedata_addr;
u32 drv_num;
u32 sen_num;
struct params_info_t *params_info;
s32 cfg_buf[GOODIX_CFG_MAX_SIZE];
s32 max_limits[MAX_DRV_NUM * MAX_SEN_NUM];
s32 min_limits[MAX_DRV_NUM * MAX_SEN_NUM];
s32 deviation_limits[MAX_DRV_NUM * MAX_SEN_NUM];
s32 self_max_limits[MAX_DRV_NUM + MAX_SEN_NUM];
s32 self_min_limits[MAX_DRV_NUM + MAX_SEN_NUM];
s32 noise_threshold;
s32 self_noise_threshold;
u32 short_threshold;
u32 r_drv_drv_threshold;
u32 r_drv_sen_threshold;
u32 r_sen_sen_threshold;
u32 r_drv_gnd_threshold;
u32 r_sen_gnd_threshold;
u32 avdd_value;
};
struct ts_test_rawdata {
s16 data[MAX_DRV_NUM * MAX_SEN_NUM];
u32 size;
};
struct ts_test_self_rawdata {
s16 data[MAX_DRV_NUM + MAX_SEN_NUM];
u32 size;
};
struct ts_short_res {
u8 short_num;
s16 short_msg[4 * MAX_SHORT_NUM];
};
struct ts_open_res {
u8 beyond_max_limit_cnt[MAX_DRV_NUM * MAX_SEN_NUM];
u8 beyond_min_limit_cnt[MAX_DRV_NUM * MAX_SEN_NUM];
u8 beyond_accord_limit_cnt[MAX_DRV_NUM * MAX_SEN_NUM];
};
struct goodix_ts_test {
struct goodix_ts_core *ts;
struct ts_test_params test_params;
struct ts_test_rawdata rawdata[TOTAL_FRAME_NUM];
struct ts_test_rawdata accord_arr[TOTAL_FRAME_NUM];
struct ts_test_rawdata noisedata[NOISEDATA_TEST_TIMES];
struct goodix_ic_config test_config;
struct ts_test_self_rawdata self_rawdata;
struct ts_test_self_rawdata self_noisedata;
struct ts_short_res short_res;
struct ts_open_res open_res;
/*[0][0][0][0][0].. 0 without test; 1 pass, 2 panel failed; 3 software failed */
char test_result[MAX_TEST_ITEMS];
char test_info[TS_RAWDATA_RESULT_MAX];
};
static int cal_cha_to_cha_res(struct goodix_ts_test *ts_test, int v1, int v2)
{
if (ts_test->ts->bus->ic_type == IC_TYPE_BERLIN_A)
return (v1 - v2) * 63 / v2;
else if (ts_test->ts->bus->ic_type == IC_TYPE_BERLIN_B)
return (v1 - v2) * 74 / v2 + 20;
else if (ts_test->ts->bus->ic_type == IC_TYPE_BERLIN_D)
return (v1 / v2 - 1) * 70 + 59;
else
return (v1 / v2 - 1) * 55 + 45;
}
static int cal_cha_to_avdd_res(struct goodix_ts_test *ts_test, int v1, int v2)
{
if (ts_test->ts->bus->ic_type == IC_TYPE_BERLIN_A)
return 64 * (2 * v2 - 25) * 40 / v1 - 40;
else if (ts_test->ts->bus->ic_type == IC_TYPE_BERLIN_B)
return 64 * (2 * v2 - 25) * 99 / v1 - 60;
else if (ts_test->ts->bus->ic_type == IC_TYPE_BERLIN_D)
return 64 * (2 * v2 - 25) * 93 / v1 - 20;
else
return 64 * (2 * v2 - 25) * 76 / v1 - 15;
}
static int cal_cha_to_gnd_res(struct goodix_ts_test *ts_test, int v)
{
if (ts_test->ts->bus->ic_type == IC_TYPE_BERLIN_A)
return 64148 / v - 40;
else if (ts_test->ts->bus->ic_type == IC_TYPE_BERLIN_B)
return 150500 / v - 60;
else if (ts_test->ts->bus->ic_type == IC_TYPE_BERLIN_D)
return 145000 / v - 15;
else
return 120000 / v - 16;
}
static int ts_test_reset(struct goodix_ts_test *ts_test,
u32 delay_ms)
{
return ts_test->ts->hw_ops->reset(ts_test->ts, delay_ms);
}
static int ts_test_read(struct goodix_ts_test *ts_test,
u32 addr, u8 *data, u32 len)
{
return ts_test->ts->hw_ops->read(ts_test->ts, addr, data, len);
}
static int ts_test_write(struct goodix_ts_test *ts_test,
u32 addr, u8 *data, u32 len)
{
return ts_test->ts->hw_ops->write(ts_test->ts, addr, data, len);
}
static int ts_test_send_cmd(struct goodix_ts_test *ts_test,
struct goodix_ts_cmd *cmd)
{
return ts_test->ts->hw_ops->send_cmd(ts_test->ts, cmd);
}
static int ts_test_irq_enable(struct goodix_ts_test *ts_test,
bool flag)
{
return ts_test->ts->hw_ops->irq_enable(ts_test->ts, flag);
}
static int ts_test_send_config(struct goodix_ts_test *ts_test,
int type)
{
struct goodix_ic_config *cfg;
if (type >= GOODIX_MAX_CONFIG_GROUP) {
ts_err("unsupproted config type %d", type);
return -EINVAL;
}
cfg = ts_test->ts->ic_configs[type];
if (!cfg || cfg->len <= 0) {
ts_err("no valid normal config found");
return -EINVAL;
}
return ts_test->ts->hw_ops->send_config(ts_test->ts, cfg->data, cfg->len);
}
static int ts_test_read_version(struct goodix_ts_test *ts_test,
struct goodix_fw_version *version)
{
return ts_test->ts->hw_ops->read_version(ts_test->ts, version);
}
static void goto_next_line(char **ptr)
{
do {
*ptr = *ptr + 1;
} while (**ptr != '\n' && **ptr != '\0');
if (**ptr == '\0') {
return;
}
*ptr = *ptr + 1;
}
static void copy_this_line(char *dest, char *src)
{
char *copy_from;
char *copy_to;
copy_from = src;
copy_to = dest;
do {
*copy_to = *copy_from;
copy_from++;
copy_to++;
} while((*copy_from != '\n') && (*copy_from != '\r') && (*copy_from != '\0'));
*copy_to = '\0';
}
static int getrid_space(s8* data, s32 len)
{
u8* buf = NULL;
s32 i;
u32 count = 0;
buf = (char*)vmalloc(len + 5);
memset(buf,0,sizeof(*buf));
if (buf == NULL){
ts_err("get space vmalloc error");
return -ESRCH;
}
for (i = 0; i < len; i++)
{
if (data[i] == ' ' || data[i] == '\r' || data[i] == '\n')
{
continue;
}
buf[count++] = data[i];
}
buf[count++] = '\0';
memcpy(data, buf, count);
vfree(buf);
return count;
}
static int parse_valid_data(char *buf_start, loff_t buf_size,
char *ptr, s32 *data, s32 rows)
{
int i = 0;
int j = 0;
char *token = NULL;
char *tok_ptr = NULL;
char *row_data = NULL;
long temp_val;
if (!ptr) {
ts_err("ptr is NULL");
return -EINVAL;
}
if (!data) {
ts_err("data is NULL");
return -EINVAL;
}
row_data = (char*)vmalloc(MAX_LINE_LEN);
memset(row_data,0,sizeof(*row_data));
if (!row_data) {
ts_err("alloc bytes %d failed.", MAX_LINE_LEN);
return -ENOMEM;
}
for (i = 0; i < rows; i++) {
memset(row_data, 0, MAX_LINE_LEN);
copy_this_line(row_data, ptr);
getrid_space(row_data, strlen(row_data));
tok_ptr = row_data;
while ((token = strsep(&tok_ptr,","))) {
if (strlen(token) == 0)
continue;
if (kstrtol(token, 0, &temp_val)) {
vfree(row_data);
return -EINVAL;
}
data[j++] = (s32)temp_val;
}
if (i == rows - 1)
break;
goto_next_line(&ptr); //next row
if(!ptr || (0 == strlen(ptr)) || (ptr >= (buf_start + buf_size))) {
ts_info("invalid ptr, return");
vfree(row_data);
row_data = NULL;
return -EPERM;
}
}
vfree(row_data);
return j;
}
static int parse_csvfile(char *buf, size_t size, char *target_name,
s32 *data, s32 rows, s32 col)
{
int ret = 0;
char *ptr = NULL;
int read_ret;
read_ret = size;
if (read_ret > 0) {
ptr = buf;
ptr = strstr(ptr, target_name);
if (!ptr) {
ts_info("load %s failed 1, maybe not this item", target_name);
return -EINTR;
}
goto_next_line(&ptr);
if (!ptr || (0 == strlen(ptr))) {
ts_err("load %s failed 2!", target_name);
return -EIO;
}
if (data) {
ret = parse_valid_data(buf, size, ptr, data, rows);
} else {
ts_err("load %s failed 3!", target_name);
return -EINTR;
}
} else {
ts_err("ret=%d, read_ret=%d", ret, read_ret);
ret = -ENXIO;
}
return ret;
}
static void goodix_init_params(struct goodix_ts_test *ts_test)
{
struct goodix_ts_core *ts = ts_test->ts;
struct ts_test_params *test_params = &ts_test->test_params;
test_params->rawdata_addr = ts->ic_info.misc.mutual_rawdata_addr;
test_params->noisedata_addr = ts->ic_info.misc.mutual_diffdata_addr;
test_params->self_rawdata_addr = ts->ic_info.misc.self_rawdata_addr;
test_params->self_noisedata_addr = ts->ic_info.misc.self_diffdata_addr;
test_params->drv_num = ts->ic_info.parm.drv_num;
test_params->sen_num = ts->ic_info.parm.sen_num;
if (ts_test->ts->bus->ic_type == IC_TYPE_BERLIN_A)
test_params->params_info = ¶ms_bra;
else if (ts_test->ts->bus->ic_type == IC_TYPE_BERLIN_B)
test_params->params_info = ¶ms_brb;
else
test_params->params_info = ¶ms_brd;
}
static int goodix_init_testlimits(struct goodix_ts_test *ts_test)
{
int ret;
int i;
u32 data_buf[10] = {0};
char *temp_buf = NULL;
struct ts_test_params *test_params = &ts_test->test_params;
struct goodix_ts_core *ts_core = ts_test->ts;
const struct firmware *firmware = NULL;
struct device *dev = &ts_core->pdev->dev;
char limit_file[100] = {0};
u32 tx = test_params->drv_num;
u32 rx = test_params->sen_num;
sprintf(limit_file, "%s_test_limits_%d.csv", GOODIX_TEST_FILE_NAME,
ts_core->fw_version.sensor_id);
ts_info("limit_file_name:%s", limit_file);
ret = request_firmware(&firmware, limit_file, dev);
if (ret < 0) {
ts_err("limits file [%s] not available", limit_file);
return -EINVAL;
}
if (firmware->size <= 0) {
ts_err("request_firmware, limits param length error,len:%zu",
firmware->size);
ret = -EINVAL;
goto exit_free;
}
temp_buf = vmalloc(firmware->size + 1);
memset(temp_buf,0,sizeof(*temp_buf));
if (!temp_buf) {
ts_err("vmalloc bytes failed.");
ret = -ENOMEM;
goto exit_free;
}
memcpy(temp_buf, firmware->data, firmware->size);
/* obtain config data */
ret = parse_csvfile(temp_buf, firmware->size, CSV_TP_TEST_CONFIG,
test_params->cfg_buf, 1, GOODIX_CFG_MAX_SIZE);
if (ret < 0) {
ts_info("Can't find %s", CSV_TP_TEST_CONFIG);
} else {
ts_info("parse_csvfile %s OK, cfg_len:%d", CSV_TP_TEST_CONFIG, ret);
for (i = 0; i < ret; i++)
ts_test->test_config.data[i] = (u8)test_params->cfg_buf[i];
ts_test->test_config.len = ret;
}
/* obtain mutual_raw min */
ret = parse_csvfile(temp_buf, firmware->size, CSV_TP_SPECIAL_RAW_MIN,
test_params->min_limits, rx, tx);
if (ret < 0) {
ts_err("Failed get min_limits");
goto exit_free;
} else {
ts_info("parse_csvfile %s OK", CSV_TP_SPECIAL_RAW_MIN);
}
/* obtain mutual_raw max */
ret = parse_csvfile(temp_buf, firmware->size, CSV_TP_SPECIAL_RAW_MAX,
test_params->max_limits, rx, tx);
if (ret < 0) {
ts_err("Failed get max_limits");
goto exit_free;
} else {
ts_info("parse_csvfile %s OK", CSV_TP_SPECIAL_RAW_MAX);
}
/* obtain delta limit */
ret = parse_csvfile(temp_buf, firmware->size, CSV_TP_SPECIAL_RAW_DELTA,
test_params->deviation_limits, rx, tx);
if (ret < 0) {
ts_err("Failed get delta limit");
goto exit_free;
} else {
ts_info("parse_csvfile %s OK", CSV_TP_SPECIAL_RAW_DELTA);
}
/* obtain self_raw min */
ret = parse_csvfile(temp_buf, firmware->size, CSV_TP_SPECIAL_SELFRAW_MIN,
test_params->self_min_limits, 1, tx + rx);
/* obtain self_raw max */
ret |= parse_csvfile(temp_buf, firmware->size, CSV_TP_SPECIAL_SELFRAW_MAX,
test_params->self_max_limits, 1, tx + rx);
if (ret < 0) {
ts_info("Can't find self_min_max_limits, ship this item");
ret = 0;
test_params->test_items[GTP_SELFCAP_TEST] = false;
} else {
ts_info("parse_csvfile %s OK", CSV_TP_SPECIAL_SELFRAW_MIN);
ts_info("parse_csvfile %s OK", CSV_TP_SPECIAL_SELFRAW_MAX);
test_params->test_items[GTP_SELFCAP_TEST] = true;
}
/* obtain noise_threshold */
ret = parse_csvfile(temp_buf, firmware->size, CSV_TP_NOISE_LIMIT,
&test_params->noise_threshold, 1, 1);
if (ret < 0) {
ts_info("Can't find noise_threshold, skip this item");
ret = 0;
test_params->test_items[GTP_NOISE_TEST] = false;
} else {
ts_info("parse_csvfile %s OK", CSV_TP_NOISE_LIMIT);
test_params->test_items[GTP_NOISE_TEST] = true;
}
/* obtain self_noise_threshold */
ret = parse_csvfile(temp_buf, firmware->size, CSV_TP_SELFNOISE_LIMIT,
&test_params->self_noise_threshold, 1, 1);
if (ret < 0) {
ts_info("Can't find self_noise_threshold, skip this item");
ret = 0;
test_params->test_items[GTP_SELFNOISE_TEST] = false;
} else {
ts_info("parse_csvfile %s OK", CSV_TP_SELFNOISE_LIMIT);
test_params->test_items[GTP_SELFNOISE_TEST] = true;
}
/* obtain short_params */
ret = parse_csvfile(temp_buf, firmware->size, CSV_TP_SHORT_THRESHOLD,
(s32 *)data_buf, 1, 7);
if (ret < 0) {
ts_info("Can't find short shortciurt_threshold, skip this item");
ret = 0;
test_params->test_items[GTP_SHORT_TEST] = false;
} else {
ts_info("parse_csvfile %s OK", CSV_TP_SHORT_THRESHOLD);
test_params->test_items[GTP_SHORT_TEST] = true;
test_params->short_threshold = data_buf[0];
test_params->r_drv_drv_threshold = data_buf[1];
test_params->r_drv_sen_threshold = data_buf[2];
test_params->r_sen_sen_threshold = data_buf[3];
test_params->r_drv_gnd_threshold = data_buf[4];
test_params->r_sen_gnd_threshold = data_buf[5];
test_params->avdd_value = data_buf[6];
}
exit_free:
vfree(temp_buf);
if (firmware)
release_firmware(firmware);
return ret;
}
static int goodix_tptest_prepare(struct goodix_ts_test *ts_test)
{
int ret;
struct goodix_ic_config *cfg = &ts_test->test_config;
ts_info("TP test prepare IN");
goodix_init_params(ts_test);
/* parse test limits from csv */
ret = goodix_init_testlimits(ts_test);
if (ret < 0) {
ts_err("Failed to init testlimits from csv.");
return ret;
}
/* disable irq */
ts_test_irq_enable(ts_test, false);
/* close esd */
goodix_ts_blocking_notify(NOTIFY_ESD_OFF, NULL);
/* send test config if exist */
if (cfg->len > 0) {
ts_info("Test config exists and send it");
ret = ts_test->ts->hw_ops->send_config(ts_test->ts, cfg->data, cfg->len);
if (ret < 0) {
ts_err("Send test config failed, exit");
goodix_ts_blocking_notify(NOTIFY_ESD_ON, NULL);
ts_test_irq_enable(ts_test, true);
return ret;
}
}
return 0;
}
static void goodix_tptest_finish(struct goodix_ts_test *ts_test)
{
ts_info("TP test finish IN");
/* reset chip */
ts_test_reset(ts_test, 100);
/* send normal config */
if (ts_test->test_config.len > 0) {
if (ts_test_send_config(ts_test, CONFIG_TYPE_NORMAL))
ts_err("Send normal config failed");
}
/* open esd */
goodix_ts_blocking_notify(NOTIFY_ESD_ON, NULL);
/* enable irq */
ts_test_irq_enable(ts_test, true);
}
#define SHORT_TEST_RUN_REG 0x10400
#define SHORT_TEST_RUN_FLAG 0xAA
#define INSPECT_FW_SWITCH_CMD 0x85
#define TEST_FW_PID "OST"
static int goodix_short_test_prepare(struct goodix_ts_test *ts_test)
{
struct goodix_ts_cmd tmp_cmd;
struct goodix_fw_version fw_ver;
int ret;
int retry = 3;
int resend = 3;
u8 status;
ts_info("short test prepare IN");
ts_test->test_result[GTP_SHORT_TEST] = SYS_SOFTWARE_REASON;
tmp_cmd.len = 4;
tmp_cmd.cmd = INSPECT_FW_SWITCH_CMD;
resend_cmd:
ret = ts_test_send_cmd(ts_test, &tmp_cmd);
if (ret < 0) {
ts_err("send test mode failed");
return ret;
}
retry = 3;
while (retry--) {
msleep(40);
if (ts_test->ts->bus->ic_type == IC_TYPE_BERLIN_A) {
ret = ts_test_read_version(ts_test, &fw_ver);
if (ret < 0) {
ts_err("read test version failed");
return ret;
}
ret = memcmp(&(fw_ver.patch_pid[3]), TEST_FW_PID, strlen(TEST_FW_PID));
if (ret == 0)
return 0;
else
ts_info("patch ID dismatch %s != %s", fw_ver.patch_pid, TEST_FW_PID);
} else {
ret = ts_test_read(ts_test, SHORT_TEST_RUN_REG, &status, 1);
if (!ret && status == SHORT_TEST_RUN_FLAG)
return 0;
ts_info("short_mode_status=0x%02x ret=%d", status, ret);
}
}
if (resend--) {
ts_test_reset(ts_test,100);
goto resend_cmd;
}
return -EINVAL;
}
static u32 map_die2pin(struct ts_test_params *test_params, u32 chn_num)
{
int i = 0;
u32 res = 255;
if (chn_num & DRV_CHANNEL_FLAG)
chn_num = (chn_num & ~DRV_CHANNEL_FLAG) + test_params->params_info->max_sen_num;
for (i = 0; i < test_params->params_info->max_sen_num; i++) {
if (test_params->params_info->sen_map[i] == chn_num) {
res = i;
break;
}
}
/* res != 255 mean found the corresponding channel num */
if (res != 255)
return res;
/* if cannot find in SenMap try find in DrvMap */
for (i = 0; i < test_params->params_info->max_drv_num; i++) {
if (test_params->params_info->drv_map[i] == chn_num) {
res = i;
break;
}
}
if (i >= test_params->params_info->max_drv_num)
ts_err("Faild found corrresponding channel num:%d", chn_num);
else
res |= DRV_CHANNEL_FLAG;
return res;
}
static void goodix_save_short_res(struct ts_test_params *params,
u16 chn1, u16 chn2, int r)
{
int i;
u8 repeat_cnt = 0;
u8 repeat = 0;
struct goodix_ts_test *ts_test = container_of(params,
struct goodix_ts_test, test_params);
struct ts_short_res *short_res = &ts_test->short_res;
if (chn1 == chn2 || short_res->short_num >= MAX_SHORT_NUM)
return;
for (i = 0; i < short_res->short_num; i++) {
repeat_cnt = 0;
if (short_res->short_msg[4 * i] == chn1)
repeat_cnt++;
if (short_res->short_msg[4 * i] == chn2)
repeat_cnt++;
if (short_res->short_msg[4 * i + 1] == chn1)
repeat_cnt++;
if (short_res->short_msg[4 * i + 1] == chn2)
repeat_cnt++;
if (repeat_cnt >= 2){
repeat = 1;
break;
}
}
if (repeat == 0) {
short_res->short_msg[4 * short_res->short_num + 0] = chn1;
short_res->short_msg[4 * short_res->short_num + 1] = chn2;
short_res->short_msg[4 * short_res->short_num + 2] = (r >> 8) & 0xFF;
short_res->short_msg[4 * short_res->short_num + 3] = r & 0xFF;
if (short_res->short_num < MAX_SHORT_NUM)
short_res->short_num++;
}
}
static int gdix_check_tx_tx_shortcircut(struct goodix_ts_test *ts_test,
u8 short_ch_num)
{
int ret = 0, err = 0;
u32 r_threshold = 0, short_r = 0;
int size = 0, i = 0, j = 0;
u16 adc_signal = 0;
u8 master_pin_num, slave_pin_num;
u8 *data_buf;
u32 data_reg;
struct ts_test_params *test_params = &ts_test->test_params;
int max_drv_num = test_params->params_info->max_drv_num;
int max_sen_num = test_params->params_info->max_sen_num;
u16 self_capdata, short_die_num = 0;
size = 4 + max_drv_num * 2 + 2;
data_buf = vmalloc(size);
memset(data_buf,0,sizeof(*data_buf));
if (!data_buf) {
ts_err("Failed to alloc memory");
return -ENOMEM;
}
/* drv&drv shortcircut check */
data_reg = test_params->params_info->drv_drv_selfcode_reg;
for (i = 0; i < short_ch_num; i++) {
ret = ts_test_read(ts_test, data_reg, data_buf, size);
if (ret < 0) {
ts_err("Failed read Drv-to-Drv short rawdata");
err = -EINVAL;
break;
}
if (checksum_cmp(data_buf, size, CHECKSUM_MODE_U8_LE)) {
ts_err("Drv-to-Drv adc data checksum error");
err = -EINVAL;
break;
}
r_threshold = test_params->r_drv_drv_threshold;
short_die_num = le16_to_cpup((__le16 *)&data_buf[0]);
short_die_num -= max_sen_num;
if (short_die_num >= max_drv_num) {
ts_info("invalid short pad num:%d",
short_die_num + max_sen_num);
continue;
}
/* TODO: j start position need recheck */
self_capdata = le16_to_cpup((__le16 *)&data_buf[2]);
if (self_capdata == 0xffff || self_capdata == 0) {
ts_info("invalid self_capdata:0x%x", self_capdata);
continue;
}
for (j = short_die_num + 1; j < max_drv_num; j++) {
adc_signal = le16_to_cpup((__le16 *)&data_buf[4 + j * 2]);
if (adc_signal < test_params->short_threshold)
continue;
short_r = (u32)cal_cha_to_cha_res(ts_test, self_capdata, adc_signal);
if (short_r < r_threshold) {
master_pin_num =
map_die2pin(test_params, short_die_num + max_sen_num);
slave_pin_num =
map_die2pin(test_params, j + max_sen_num);
if (master_pin_num == 0xFF || slave_pin_num == 0xFF) {
ts_info("WARNNING invalid pin");
continue;
}
goodix_save_short_res(test_params, master_pin_num,
slave_pin_num, short_r);
ts_err("short circut:R=%dK,R_Threshold=%dK",
short_r, r_threshold);
ts_err("%s%d--%s%d shortcircut",
(master_pin_num & DRV_CHANNEL_FLAG) ? "DRV" : "SEN",
(master_pin_num & ~DRV_CHANNEL_FLAG),
(slave_pin_num & DRV_CHANNEL_FLAG) ? "DRV" : "SEN",
(slave_pin_num & ~DRV_CHANNEL_FLAG));
err = -EINVAL;
}
}
data_reg += size;
}
vfree(data_buf);
return err;
}
static int gdix_check_rx_rx_shortcircut(struct goodix_ts_test *ts_test,
u8 short_ch_num)
{
int ret = 0, err = 0;
u32 r_threshold = 0, short_r = 0;
int size = 0, i = 0, j = 0;
u16 adc_signal = 0;
u8 master_pin_num, slave_pin_num;
u8 *data_buf;
u32 data_reg;
struct ts_test_params *test_params = &ts_test->test_params;
int max_sen_num = test_params->params_info->max_sen_num;
u16 self_capdata, short_die_num = 0;
size = 4 + max_sen_num * 2 + 2;