-
Notifications
You must be signed in to change notification settings - Fork 0
/
nt36xxx_mp_ctrlram.c
1863 lines (1557 loc) · 51.2 KB
/
nt36xxx_mp_ctrlram.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
/*
* Copyright (C) 2010 - 2017 Novatek, Inc.
* Copyright (C) 2019 XiaoMi, Inc.
*
* $Revision: 21288 $
* $Date: 2018-01-05 11:38:47 +0800 (週五, 05 一月 2018) $
*
* 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/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/delay.h>
#include <linux/slab.h>
#include <asm/uaccess.h>
#include "nt36xxx.h"
#include "nt36xxx_mp_ctrlram.h"
#if NVT_TOUCH_MP
#define NORMAL_MODE 0x00
#define TEST_MODE_1 0x21
#define TEST_MODE_2 0x22
#define MP_MODE_CC 0x41
#define FREQ_HOP_DISABLE 0x66
#define FREQ_HOP_ENABLE 0x65
#define SHORT_TEST_CSV_FILE "/data/local/tmp/ShortTest.csv"
#define OPEN_TEST_CSV_FILE "/data/local/tmp/OpenTest.csv"
#define FW_RAWDATA_CSV_FILE "/data/local/tmp/FWMutualTest.csv"
#define FW_CC_CSV_FILE "/data/local/tmp/FWCCTest.csv"
#define NOISE_TEST_CSV_FILE "/data/local/tmp/NoiseTest.csv"
#define nvt_mp_seq_printf(m, fmt, args...) do { \
seq_printf(m, fmt, ##args); \
if (!nvt_mp_test_result_printed) \
printk(fmt, ##args); \
} while (0)
static uint8_t *RecordResult_Short = NULL;
static uint8_t *RecordResult_Short_Diff = NULL;
static uint8_t *RecordResult_Short_Base = NULL;
static uint8_t *RecordResult_Open = NULL;
static uint8_t *RecordResult_FWMutual = NULL;
static uint8_t *RecordResult_FW_CC = NULL;
static uint8_t *RecordResult_FW_CC_I = NULL;
static uint8_t *RecordResult_FW_CC_Q = NULL;
static uint8_t *RecordResult_FW_DiffMax = NULL;
static uint8_t *RecordResult_FW_DiffMin = NULL;
static int32_t TestResult_Short = 0;
static int32_t TestResult_Short_Diff = 0;
static int32_t TestResult_Short_Base = 0;
static int32_t TestResult_Open = 0;
static int32_t TestResult_FW_Rawdata = 0;
static int32_t TestResult_FWMutual = 0;
static int32_t TestResult_FW_CC = 0;
static int32_t TestResult_FW_CC_I = 0;
static int32_t TestResult_FW_CC_Q = 0;
static int32_t TestResult_Noise = 0;
static int32_t TestResult_FW_DiffMax = 0;
static int32_t TestResult_FW_DiffMin = 0;
static int32_t *RawData_Short = NULL;
static int32_t *RawData_Short_Diff = NULL;
static int32_t *RawData_Short_Base = NULL;
static int32_t *RawData_Open = NULL;
static int32_t *RawData_Diff = NULL;
static int32_t *RawData_Diff_Min = NULL;
static int32_t *RawData_Diff_Max = NULL;
static int32_t *RawData_FWMutual = NULL;
static int32_t *RawData_FW_CC = NULL;
static int32_t *RawData_FW_CC_I = NULL;
static int32_t *RawData_FW_CC_Q = NULL;
static struct proc_dir_entry *NVT_proc_selftest_entry = NULL;
static int8_t nvt_mp_test_result_printed = 0;
extern void nvt_change_mode(uint8_t mode);
extern uint8_t nvt_get_fw_pipe(void);
extern void nvt_read_mdata(uint32_t xdata_addr, uint32_t xdata_btn_addr);
extern void nvt_get_mdata(int32_t *buf, uint8_t *m_x_num, uint8_t *m_y_num);
void nvt_mp_parse_dt(struct device_node *root, const char *node_compatible);
/*******************************************************
Description:
Novatek touchscreen allocate buffer for mp selftest.
return:
Executive outcomes. 0---succeed. -12---Out of memory
*******************************************************/
static int nvt_mp_buffer_init(void)
{
size_t RecordResult_BufSize = IC_X_CFG_SIZE * IC_Y_CFG_SIZE + IC_KEY_CFG_SIZE;
size_t RawData_BufSize = (IC_X_CFG_SIZE * IC_Y_CFG_SIZE + IC_KEY_CFG_SIZE) * sizeof(int32_t);
RecordResult_Short = (uint8_t *)kzalloc(RecordResult_BufSize, GFP_KERNEL);
if (!RecordResult_Short) {
NVT_ERR("kzalloc for RecordResult_Short failed!\n");
return -ENOMEM;
}
RecordResult_Short_Diff = RecordResult_Short;
RecordResult_Short_Base = (uint8_t *)kzalloc(RecordResult_BufSize, GFP_KERNEL);
if (!RecordResult_Short_Base) {
NVT_ERR("kzalloc for RecordResult_Short_Base failed!\n");
return -ENOMEM;
}
RecordResult_Open = (uint8_t *)kzalloc(RecordResult_BufSize, GFP_KERNEL);
if (!RecordResult_Open) {
NVT_ERR("kzalloc for RecordResult_Open failed!\n");
return -ENOMEM;
}
RecordResult_FWMutual = (uint8_t *)kzalloc(RecordResult_BufSize, GFP_KERNEL);
if (!RecordResult_FWMutual) {
NVT_ERR("kzalloc for RecordResult_FWMutual failed!\n");
return -ENOMEM;
}
RecordResult_FW_CC = (uint8_t *)kzalloc(RecordResult_BufSize, GFP_KERNEL);
if (!RecordResult_FW_CC) {
NVT_ERR("kzalloc for RecordResult_FW_CC failed!\n");
return -ENOMEM;
}
RecordResult_FW_CC_I = RecordResult_FW_CC;
RecordResult_FW_CC_Q = (uint8_t *)kzalloc(RecordResult_BufSize, GFP_KERNEL);
if (!RecordResult_FW_CC_Q) {
NVT_ERR("kzalloc for RecordResult_FW_CC_Q failed!\n");
return -ENOMEM;
}
RecordResult_FW_DiffMax = (uint8_t *)kzalloc(RecordResult_BufSize, GFP_KERNEL);
if (!RecordResult_FW_DiffMax) {
NVT_ERR("kzalloc for RecordResult_FW_DiffMax failed!\n");
return -ENOMEM;
}
RecordResult_FW_DiffMin = (uint8_t *)kzalloc(RecordResult_BufSize, GFP_KERNEL);
if (!RecordResult_FW_DiffMin) {
NVT_ERR("kzalloc for RecordResult_FW_DiffMin failed!\n");
return -ENOMEM;
}
RawData_Short = (int32_t *)kzalloc(RawData_BufSize, GFP_KERNEL);
if (!RawData_Short) {
NVT_ERR("kzalloc for RawData_Short failed!\n");
return -ENOMEM;
}
RawData_Short_Diff = RawData_Short;
RawData_Short_Base = (int32_t *)kzalloc(RawData_BufSize, GFP_KERNEL);
if (!RawData_Short_Base) {
NVT_ERR("kzalloc for RawData_Short_Base failed!\n");
return -ENOMEM;
}
RawData_Open = (int32_t *)kzalloc(RawData_BufSize, GFP_KERNEL);
if (!RawData_Open) {
NVT_ERR("kzalloc for RawData_Open failed!\n");
return -ENOMEM;
}
RawData_Diff = (int32_t *)kzalloc(RawData_BufSize, GFP_KERNEL);
if (!RawData_Diff) {
NVT_ERR("kzalloc for RawData_Diff failed!\n");
return -ENOMEM;
}
RawData_Diff_Min = (int32_t *)kzalloc(RawData_BufSize, GFP_KERNEL);
if (!RawData_Diff_Min) {
NVT_ERR("kzalloc for RawData_Diff_Min failed!\n");
return -ENOMEM;
}
RawData_Diff_Max = (int32_t *)kzalloc(RawData_BufSize, GFP_KERNEL);
if (!RawData_Diff_Max) {
NVT_ERR("kzalloc for RawData_Diff_Max failed!\n");
return -ENOMEM;
}
RawData_FWMutual = (int32_t *)kzalloc(RawData_BufSize, GFP_KERNEL);
if (!RawData_FWMutual) {
NVT_ERR("kzalloc for RawData_FWMutual failed!\n");
return -ENOMEM;
}
RawData_FW_CC = (int32_t *)kzalloc(RawData_BufSize, GFP_KERNEL);
if (!RawData_FW_CC) {
NVT_ERR("kzalloc for RawData_FW_CC failed!\n");
return -ENOMEM;
}
RawData_FW_CC_I = RawData_FW_CC;
RawData_FW_CC_Q = (int32_t *)kzalloc(RawData_BufSize, GFP_KERNEL);
if (!RawData_FW_CC_Q) {
NVT_ERR("kzalloc for RawData_FW_CC_Q failed!\n");
return -ENOMEM;
}
return 0;
}
/*******************************************************
Description:
Novatek touchscreen self-test criteria print function.
return:
n.a.
*******************************************************/
static void nvt_print_lmt_array(int32_t *array, int32_t x_ch, int32_t y_ch)
{
int32_t i = 0;
int32_t j = 0;
#if TOUCH_KEY_NUM > 0
int32_t k = 0;
#endif /* #if TOUCH_KEY_NUM > 0 */
char *buf = NULL;
ssize_t ret = 0;
buf = (char *)kzalloc(PAGE_SIZE * 2, GFP_KERNEL);
if (!buf) {
NVT_ERR("kzalloc for temp buffer failed!\n");
return;
}
for (j = 0; j < y_ch; j++) {
ret = 0;
for (i = 0; i < x_ch; i++) {
ret += snprintf(buf + ret, 8, "%5d, ", array[j * x_ch + i]);
}
buf[ret] = '\0';
printk("%s\n", buf);
}
#if TOUCH_KEY_NUM > 0
for (k = 0; k < Key_Channel; k++) {
printk("%5d, ", array[y_ch * x_ch + k]);
}
printk("\n");
#endif /* #if TOUCH_KEY_NUM > 0 */
if (buf) {
kfree(buf);
buf = NULL;
}
}
static void nvt_print_criteria(void)
{
NVT_LOG("++\n");
if (ts->carrier_system) {
/*---PS_Config_Lmt_Short_Diff---*/
printk("PS_Config_Lmt_Short_Diff_P:\n");
nvt_print_lmt_array(PS_Config_Lmt_Short_Diff_P, X_Channel, Y_Channel);
printk("PS_Config_Lmt_Short_Diff_N:\n");
nvt_print_lmt_array(PS_Config_Lmt_Short_Diff_N, X_Channel, Y_Channel);
/*---PS_Config_Lmt_Short_Base---*/
printk("PS_Config_Lmt_Short_Base_P:\n");
nvt_print_lmt_array(PS_Config_Lmt_Short_Base_P, X_Channel, Y_Channel);
printk("PS_Config_Lmt_Short_Base_N:\n");
nvt_print_lmt_array(PS_Config_Lmt_Short_Base_N, X_Channel, Y_Channel);
} else {
/*---PS_Config_Lmt_Short_Rawdata---*/
printk("PS_Config_Lmt_Short_Rawdata_P:\n");
nvt_print_lmt_array(PS_Config_Lmt_Short_Rawdata_P, X_Channel, Y_Channel);
printk("PS_Config_Lmt_Short_Rawdata_N:\n");
nvt_print_lmt_array(PS_Config_Lmt_Short_Rawdata_N, X_Channel, Y_Channel);
}
/*---PS_Config_Lmt_Open_Rawdata---*/
printk("PS_Config_Lmt_Open_Rawdata_P:\n");
nvt_print_lmt_array(PS_Config_Lmt_Open_Rawdata_P, X_Channel, Y_Channel);
printk("PS_Config_Lmt_Open_Rawdata_N:\n");
nvt_print_lmt_array(PS_Config_Lmt_Open_Rawdata_N, X_Channel, Y_Channel);
/*---PS_Config_Lmt_FW_Rawdata---*/
printk("PS_Config_Lmt_FW_Rawdata_P:\n");
nvt_print_lmt_array(PS_Config_Lmt_FW_Rawdata_P, X_Channel, Y_Channel);
printk("PS_Config_Lmt_FW_Rawdata_N:\n");
nvt_print_lmt_array(PS_Config_Lmt_FW_Rawdata_N, X_Channel, Y_Channel);
if (ts->carrier_system) {
/*---PS_Config_Lmt_FW_CC_I---*/
printk("PS_Config_Lmt_FW_CC_I_P:\n");
nvt_print_lmt_array(PS_Config_Lmt_FW_CC_I_P, X_Channel, Y_Channel);
printk("PS_Config_Lmt_FW_CC_I_N:\n");
nvt_print_lmt_array(PS_Config_Lmt_FW_CC_I_N, X_Channel, Y_Channel);
/*---PS_Config_Lmt_FW_CC_Q---*/
printk("PS_Config_Lmt_FW_CC_Q_P:\n");
nvt_print_lmt_array(PS_Config_Lmt_FW_CC_Q_P, X_Channel, Y_Channel);
printk("PS_Config_Lmt_FW_CC_Q_N:\n");
nvt_print_lmt_array(PS_Config_Lmt_FW_CC_Q_N, X_Channel, Y_Channel);
} else {
/*---PS_Config_Lmt_FW_CC---*/
printk("PS_Config_Lmt_FW_CC_P:\n");
nvt_print_lmt_array(PS_Config_Lmt_FW_CC_P, X_Channel, Y_Channel);
printk("PS_Config_Lmt_FW_CC_N:\n");
nvt_print_lmt_array(PS_Config_Lmt_FW_CC_N, X_Channel, Y_Channel);
}
/*---PS_Config_Lmt_FW_Diff---*/
printk("PS_Config_Lmt_FW_Diff_P:\n");
nvt_print_lmt_array(PS_Config_Lmt_FW_Diff_P, X_Channel, Y_Channel);
printk("PS_Config_Lmt_FW_Diff_N:\n");
nvt_print_lmt_array(PS_Config_Lmt_FW_Diff_N, X_Channel, Y_Channel);
NVT_LOG("--\n");
}
static int32_t nvt_polling_hand_shake_status(void)
{
uint8_t buf[8] = {0};
int32_t i = 0;
const int32_t retry = 50;
for (i = 0; i < retry; i++) {
/*---set xdata index to EVENT BUF ADDR---*/
buf[0] = 0xFF;
buf[1] = (ts->mmap->EVENT_BUF_ADDR >> 16) & 0xFF;
buf[2] = (ts->mmap->EVENT_BUF_ADDR >> 8) & 0xFF;
CTP_I2C_WRITE(ts->client, I2C_FW_Address, buf, 3);
/*---read fw status---*/
buf[0] = EVENT_MAP_HANDSHAKING_or_SUB_CMD_BYTE;
buf[1] = 0x00;
CTP_I2C_READ(ts->client, I2C_FW_Address, buf, 2);
if ((buf[1] == 0xA0) || (buf[1] == 0xA1))
break;
msleep(10);
}
if (i >= retry) {
NVT_ERR("polling hand shake status failed, buf[1]=0x%02X\n", buf[1]);
/* Read back 5 bytes from offset EVENT_MAP_HOST_CMD for debug check */
buf[0] = 0xFF;
buf[1] = (ts->mmap->EVENT_BUF_ADDR >> 16) & 0xFF;
buf[2] = (ts->mmap->EVENT_BUF_ADDR >> 8) & 0xFF;
CTP_I2C_WRITE(ts->client, I2C_FW_Address, buf, 3);
buf[0] = EVENT_MAP_HOST_CMD;
buf[1] = 0x00;
buf[2] = 0x00;
buf[3] = 0x00;
buf[4] = 0x00;
buf[5] = 0x00;
CTP_I2C_READ(ts->client, I2C_FW_Address, buf, 6);
NVT_ERR("Read back 5 bytes from offset EVENT_MAP_HOST_CMD: 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X\n", buf[1], buf[2], buf[3], buf[4], buf[5]);
return -1;
} else {
return 0;
}
}
static int8_t nvt_switch_FreqHopEnDis(uint8_t FreqHopEnDis)
{
uint8_t buf[8] = {0};
uint8_t retry = 0;
int8_t ret = 0;
NVT_LOG("++\n");
for (retry = 0; retry < 20; retry++) {
/*---set xdata index to EVENT BUF ADDR---*/
buf[0] = 0xFF;
buf[1] = (ts->mmap->EVENT_BUF_ADDR >> 16) & 0xFF;
buf[2] = (ts->mmap->EVENT_BUF_ADDR >> 8) & 0xFF;
CTP_I2C_WRITE(ts->client, I2C_FW_Address, buf, 3);
/*---switch FreqHopEnDis---*/
buf[0] = EVENT_MAP_HOST_CMD;
buf[1] = FreqHopEnDis;
CTP_I2C_WRITE(ts->client, I2C_FW_Address, buf, 2);
msleep(35);
buf[0] = EVENT_MAP_HOST_CMD;
buf[1] = 0xFF;
CTP_I2C_READ(ts->client, I2C_FW_Address, buf, 2);
if (buf[1] == 0x00)
break;
}
if (unlikely(retry == 20)) {
NVT_ERR("switch FreqHopEnDis 0x%02X failed, buf[1]=0x%02X\n", FreqHopEnDis, buf[1]);
ret = -1;
}
NVT_LOG("--\n");
return ret;
}
static int32_t nvt_read_baseline(int32_t *xdata)
{
uint8_t x_num = 0;
uint8_t y_num = 0;
uint32_t x = 0;
uint32_t y = 0;
int32_t iArrayIndex = 0;
#if TOUCH_KEY_NUM > 0
int32_t k = 0;
#endif /* #if TOUCH_KEY_NUM > 0 */
NVT_LOG("++\n");
nvt_read_mdata(ts->mmap->BASELINE_ADDR, ts->mmap->BASELINE_BTN_ADDR);
nvt_get_mdata(xdata, &x_num, &y_num);
for (y = 0; y < y_num; y++) {
for (x = 0; x < x_num; x++) {
iArrayIndex = y * x_num + x;
if (ts->carrier_system) {
xdata[iArrayIndex] = (uint16_t)xdata[iArrayIndex];
} else {
xdata[iArrayIndex] = (int16_t)xdata[iArrayIndex];
}
}
}
#if TOUCH_KEY_NUM > 0
for (k = 0; k < Key_Channel; k++) {
iArrayIndex = Y_Channel * X_Channel + k;
if (ts->carrier_system) {
xdata[iArrayIndex] = (uint16_t)xdata[iArrayIndex];
} else {
xdata[iArrayIndex] = (int16_t)xdata[iArrayIndex];
}
}
#endif /* #if TOUCH_KEY_NUM > 0 */
printk("%s:\n", __func__);
NVT_LOG("--\n");
return 0;
}
static int32_t nvt_read_CC(int32_t *xdata)
{
uint8_t x_num = 0;
uint8_t y_num = 0;
uint32_t x = 0;
uint32_t y = 0;
int32_t iArrayIndex = 0;
int32_t xdata_tmp = 0;
#if TOUCH_KEY_NUM > 0
int32_t k = 0;
#endif /* #if TOUCH_KEY_NUM > 0 */
uint32_t rawdata_cc_q_offset = 0;
NVT_LOG("++\n");
if (nvt_get_fw_pipe() == 0)
nvt_read_mdata(ts->mmap->DIFF_PIPE1_ADDR, ts->mmap->DIFF_BTN_PIPE1_ADDR);
else
nvt_read_mdata(ts->mmap->DIFF_PIPE0_ADDR, ts->mmap->DIFF_BTN_PIPE0_ADDR);
nvt_get_mdata(xdata, &x_num, &y_num);
for (y = 0; y < y_num; y++) {
for (x = 0; x < x_num; x++) {
iArrayIndex = y * x_num + x;
if (ts->carrier_system) {
xdata_tmp = xdata[iArrayIndex];
RawData_FW_CC_I[iArrayIndex] = (uint8_t)(xdata_tmp & 0xFF);
RawData_FW_CC_Q[iArrayIndex] = (uint8_t)((xdata_tmp >> 8) & 0xFF);
} else {
xdata[iArrayIndex] = (int16_t)xdata[iArrayIndex];
}
}
}
#if TOUCH_KEY_NUM > 0
for (k = 0; k < Key_Channel; k++) {
iArrayIndex = Y_Channel * X_Channel + k;
if (ts->carrier_system) {
xdata_tmp = xdata[iArrayIndex];
RawData_FW_CC_I[iArrayIndex] = (uint8_t)(xdata_tmp & 0xFF);
RawData_FW_CC_Q[iArrayIndex] = (uint8_t)((xdata_tmp >> 8) & 0xFF);
} else {
xdata[iArrayIndex] = (int16_t)xdata[iArrayIndex];
}
}
#endif /* #if TOUCH_KEY_NUM > 0 */
printk("%s:\n", __func__);
if (ts->carrier_system) {
printk("%s:RawData_CC_I:\n", __func__);
#if TOUCH_KEY_NUM > 0
rawdata_cc_q_offset = Y_Channel * X_Channel * 7 + Y_Channel * 2 + Key_Channel * 7 + 2;
#else
rawdata_cc_q_offset = Y_Channel * X_Channel * 7 + Y_Channel * 2;
#endif /* #if TOUCH_KEY_NUM > 0 */
}
NVT_LOG("--\n");
return 0;
}
static void nvt_enable_noise_collect(int32_t frame_num)
{
uint8_t buf[8] = {0};
/*---set xdata index to EVENT BUF ADDR---*/
buf[0] = 0xFF;
buf[1] = (ts->mmap->EVENT_BUF_ADDR >> 16) & 0xFF;
buf[2] = (ts->mmap->EVENT_BUF_ADDR >> 8) & 0xFF;
CTP_I2C_WRITE(ts->client, I2C_FW_Address, buf, 3);
/*---enable noise collect---*/
buf[0] = EVENT_MAP_HOST_CMD;
buf[1] = 0x47;
buf[2] = 0xAA;
buf[3] = frame_num;
buf[4] = 0x00;
CTP_I2C_WRITE(ts->client, I2C_FW_Address, buf, 5);
}
static int32_t nvt_read_fw_noise(int32_t *xdata)
{
uint8_t x_num = 0;
uint8_t y_num = 0;
uint32_t x = 0;
uint32_t y = 0;
int32_t iArrayIndex = 0;
int32_t frame_num = 0;
uint32_t rawdata_diff_min_offset = 0;
#if TOUCH_KEY_NUM > 0
int32_t k = 0;
#endif /* #if TOUCH_KEY_NUM > 0 */
NVT_LOG("++\n");
/*---Enter Test Mode---*/
if (nvt_clear_fw_status()) {
return -EAGAIN;
}
frame_num = PS_Config_Diff_Test_Frame / 10;
if (frame_num <= 0)
frame_num = 1;
printk("%s: frame_num=%d\n", __func__, frame_num);
nvt_enable_noise_collect(frame_num);
/* need wait PS_Config_Diff_Test_Frame * 8.3ms */
msleep(frame_num * 83);
if (nvt_polling_hand_shake_status()) {
return -EAGAIN;
}
if (nvt_get_fw_info()) {
return -EAGAIN;
}
if (nvt_get_fw_pipe() == 0)
nvt_read_mdata(ts->mmap->DIFF_PIPE0_ADDR, ts->mmap->DIFF_BTN_PIPE0_ADDR);
else
nvt_read_mdata(ts->mmap->DIFF_PIPE1_ADDR, ts->mmap->DIFF_BTN_PIPE1_ADDR);
nvt_get_mdata(xdata, &x_num, &y_num);
for (y = 0; y < y_num; y++) {
for (x = 0; x < x_num; x++) {
iArrayIndex = y * x_num + x;
if (ts->carrier_system) {
RawData_Diff_Max[iArrayIndex] = (uint16_t)xdata[iArrayIndex];
RawData_Diff_Min[iArrayIndex] = 0;
} else {
RawData_Diff_Max[iArrayIndex] = (int8_t)((xdata[iArrayIndex] >> 8) & 0xFF);
RawData_Diff_Min[iArrayIndex] = (int8_t)(xdata[iArrayIndex] & 0xFF);
}
}
}
#if TOUCH_KEY_NUM > 0
for (k = 0; k < Key_Channel; k++) {
iArrayIndex = Y_Channel * X_Channel + k;
if (ts->carrier_system) {
RawData_Diff_Max[iArrayIndex] = (uint16_t)xdata[iArrayIndex];
RawData_Diff_Min[iArrayIndex] = 0;
} else {
RawData_Diff_Max[iArrayIndex] = (int8_t)((xdata[iArrayIndex] >> 8) & 0xFF);
RawData_Diff_Min[iArrayIndex] = (int8_t)(xdata[iArrayIndex] & 0xFF);
}
}
#endif /* #if TOUCH_KEY_NUM > 0 */
/*---Leave Test Mode---*/
nvt_change_mode(NORMAL_MODE);
printk("%s:RawData_Diff_Max:\n", __func__);
if (!ts->carrier_system) {
#if TOUCH_KEY_NUM > 0
rawdata_diff_min_offset = Y_Channel * X_Channel * 7 + Y_Channel * 2 + Key_Channel * 7 + 2;
#else
rawdata_diff_min_offset = Y_Channel * X_Channel * 7 + Y_Channel * 2;
#endif /* #if TOUCH_KEY_NUM > 0 */
printk("%s:RawData_Diff_Min:\n", __func__);
}
NVT_LOG("--\n");
return 0;
}
static void nvt_enable_open_test(void)
{
uint8_t buf[8] = {0};
/*---set xdata index to EVENT BUF ADDR---*/
buf[0] = 0xFF;
buf[1] = (ts->mmap->EVENT_BUF_ADDR >> 16) & 0xFF;
buf[2] = (ts->mmap->EVENT_BUF_ADDR >> 8) & 0xFF;
CTP_I2C_WRITE(ts->client, I2C_FW_Address, buf, 3);
/*---enable open test---*/
buf[0] = EVENT_MAP_HOST_CMD;
buf[1] = 0x45;
buf[2] = 0xAA;
buf[3] = 0x02;
buf[4] = 0x00;
CTP_I2C_WRITE(ts->client, I2C_FW_Address, buf, 5);
}
static void nvt_enable_short_test(void)
{
uint8_t buf[8] = {0};
/*---set xdata index to EVENT BUF ADDR---*/
buf[0] = 0xFF;
buf[1] = (ts->mmap->EVENT_BUF_ADDR >> 16) & 0xFF;
buf[2] = (ts->mmap->EVENT_BUF_ADDR >> 8) & 0xFF;
CTP_I2C_WRITE(ts->client, I2C_FW_Address, buf, 3);
/*---enable short test---*/
buf[0] = EVENT_MAP_HOST_CMD;
buf[1] = 0x43;
buf[2] = 0xAA;
buf[3] = 0x02;
buf[4] = 0x00;
CTP_I2C_WRITE(ts->client, I2C_FW_Address, buf, 5);
}
static int32_t nvt_read_fw_open(int32_t *xdata)
{
uint32_t raw_pipe_addr = 0;
uint8_t *rawdata_buf = NULL;
uint32_t x = 0;
uint32_t y = 0;
uint8_t buf[128] = {0};
#if TOUCH_KEY_NUM > 0
uint32_t raw_btn_pipe_addr = 0;
int32_t k = 0;
#endif /* #if TOUCH_KEY_NUM > 0 */
NVT_LOG("++\n");
/*---Enter Test Mode---*/
if (nvt_clear_fw_status()) {
return -EAGAIN;
}
nvt_enable_open_test();
if (nvt_polling_hand_shake_status()) {
return -EAGAIN;
}
#if TOUCH_KEY_NUM > 0
rawdata_buf = (uint8_t *)kzalloc((IC_X_CFG_SIZE * IC_Y_CFG_SIZE + IC_KEY_CFG_SIZE) * 2, GFP_KERNEL);
#else
rawdata_buf = (uint8_t *)kzalloc(IC_X_CFG_SIZE * IC_Y_CFG_SIZE * 2, GFP_KERNEL);
#endif /* #if TOUCH_KEY_NUM > 0 */
if (!rawdata_buf) {
NVT_ERR("kzalloc for rawdata_buf failed!\n");
return -ENOMEM;
}
if (nvt_get_fw_pipe() == 0)
raw_pipe_addr = ts->mmap->RAW_PIPE0_ADDR;
else
raw_pipe_addr = ts->mmap->RAW_PIPE1_ADDR;
for (y = 0; y < IC_Y_CFG_SIZE; y++) {
/*---change xdata index---*/
buf[0] = 0xFF;
buf[1] = (uint8_t)(((raw_pipe_addr + y * IC_X_CFG_SIZE * 2) >> 16) & 0xFF);
buf[2] = (uint8_t)(((raw_pipe_addr + y * IC_X_CFG_SIZE * 2) >> 8) & 0xFF);
CTP_I2C_WRITE(ts->client, I2C_FW_Address, buf, 3);
buf[0] = (uint8_t)((raw_pipe_addr + y * IC_X_CFG_SIZE * 2) & 0xFF);
CTP_I2C_READ(ts->client, I2C_FW_Address, buf, IC_X_CFG_SIZE * 2 + 1);
memcpy(rawdata_buf + y * IC_X_CFG_SIZE * 2, buf + 1, IC_X_CFG_SIZE * 2);
}
#if TOUCH_KEY_NUM > 0
if (nvt_get_fw_pipe() == 0)
raw_btn_pipe_addr = ts->mmap->RAW_BTN_PIPE0_ADDR;
else
raw_btn_pipe_addr = ts->mmap->RAW_BTN_PIPE1_ADDR;
/*---change xdata index---*/
buf[0] = 0xFF;
buf[1] = (uint8_t)((raw_btn_pipe_addr >> 16) & 0xFF);
buf[2] = (uint8_t)((raw_btn_pipe_addr >> 8) & 0xFF);
CTP_I2C_WRITE(ts->client, I2C_FW_Address, buf, 3);
buf[0] = (uint8_t)(raw_btn_pipe_addr & 0xFF);
CTP_I2C_READ(ts->client, I2C_FW_Address, buf, IC_KEY_CFG_SIZE * 2 + 1);
memcpy(rawdata_buf + IC_Y_CFG_SIZE * IC_X_CFG_SIZE * 2, buf + 1, IC_KEY_CFG_SIZE * 2);
#endif /* #if TOUCH_KEY_NUM > 0 */
for (y = 0; y < IC_Y_CFG_SIZE; y++) {
for (x = 0; x < IC_X_CFG_SIZE; x++) {
if ((AIN_Y[y] != 0xFF) && (AIN_X[x] != 0xFF)) {
xdata[AIN_Y[y] * X_Channel + AIN_X[x]] = (int16_t)((rawdata_buf[(y * IC_X_CFG_SIZE + x) * 2] + 256 * rawdata_buf[(y * IC_X_CFG_SIZE + x) * 2 + 1]));
}
}
}
#if TOUCH_KEY_NUM > 0
for (k = 0; k < IC_KEY_CFG_SIZE; k++) {
if (AIN_KEY[k] != 0xFF)
xdata[Y_Channel * X_Channel + AIN_KEY[k]] = (int16_t)(rawdata_buf[(IC_Y_CFG_SIZE * IC_X_CFG_SIZE + k) * 2] + 256 * rawdata_buf[(IC_Y_CFG_SIZE * IC_X_CFG_SIZE + k) * 2 + 1]);
}
#endif /* #if TOUCH_KEY_NUM > 0 */
if (rawdata_buf) {
kfree(rawdata_buf);
rawdata_buf = NULL;
}
/*---Leave Test Mode---*/
nvt_change_mode(NORMAL_MODE);
printk("%s:RawData_Open\n", __func__);
NVT_LOG("--\n");
return 0;
}
static int32_t nvt_read_fw_short(int32_t *xdata)
{
uint32_t raw_pipe_addr = 0;
uint8_t *rawdata_buf = NULL;
uint32_t x = 0;
uint32_t y = 0;
uint8_t buf[128] = {0};
int32_t iArrayIndex = 0;
#if TOUCH_KEY_NUM > 0
uint32_t raw_btn_pipe_addr = 0;
int32_t k = 0;
#endif /* #if TOUCH_KEY_NUM > 0 */
uint32_t rawdata_short_base_offset = 0;
NVT_LOG("++\n");
/*---Enter Test Mode---*/
if (nvt_clear_fw_status()) {
return -EAGAIN;
}
nvt_enable_short_test();
if (nvt_polling_hand_shake_status()) {
return -EAGAIN;
}
#if TOUCH_KEY_NUM > 0
rawdata_buf = (uint8_t *)kzalloc((X_Channel * Y_Channel + Key_Channel) * 2, GFP_KERNEL);
#else
rawdata_buf = (uint8_t *)kzalloc(X_Channel * Y_Channel * 2, GFP_KERNEL);
#endif /* #if TOUCH_KEY_NUM > 0 */
if (!rawdata_buf) {
NVT_ERR("kzalloc for rawdata_buf failed!\n");
return -ENOMEM;
}
if (ts->carrier_system) {
/* to get short diff rawdata at pipe0 */
raw_pipe_addr = ts->mmap->RAW_PIPE0_ADDR;
} else {
if (nvt_get_fw_pipe() == 0)
raw_pipe_addr = ts->mmap->RAW_PIPE0_ADDR;
else
raw_pipe_addr = ts->mmap->RAW_PIPE1_ADDR;
}
for (y = 0; y < Y_Channel; y++) {
/*---change xdata index---*/
buf[0] = 0xFF;
buf[1] = (uint8_t)(((raw_pipe_addr + y * X_Channel * 2) >> 16) & 0xFF);
buf[2] = (uint8_t)(((raw_pipe_addr + y * X_Channel * 2) >> 8) & 0xFF);
CTP_I2C_WRITE(ts->client, I2C_FW_Address, buf, 3);
buf[0] = (uint8_t)((raw_pipe_addr + y * X_Channel * 2) & 0xFF);
CTP_I2C_READ(ts->client, I2C_FW_Address, buf, X_Channel * 2 + 1);
memcpy(rawdata_buf + y * X_Channel * 2, buf + 1, X_Channel * 2);
}
#if TOUCH_KEY_NUM > 0
if (ts->carrier_system) {
/* to get button short diff rawdata at pipe0 */
raw_btn_pipe_addr = ts->mmap->RAW_BTN_PIPE0_ADDR;
} else {
if (nvt_get_fw_pipe() == 0)
raw_btn_pipe_addr = ts->mmap->RAW_BTN_PIPE0_ADDR;
else
raw_btn_pipe_addr = ts->mmap->RAW_BTN_PIPE1_ADDR;
}
/*---change xdata index---*/
buf[0] = 0xFF;
buf[1] = (uint8_t)((raw_btn_pipe_addr >> 16) & 0xFF);
buf[2] = (uint8_t)((raw_btn_pipe_addr >> 8) & 0xFF);
CTP_I2C_WRITE(ts->client, I2C_FW_Address, buf, 3);
buf[0] = (uint8_t)(raw_btn_pipe_addr & 0xFF);
CTP_I2C_READ(ts->client, I2C_FW_Address, buf, Key_Channel * 2 + 1);
memcpy(rawdata_buf + Y_Channel * X_Channel * 2, buf + 1, Key_Channel * 2);
#endif /* #if TOUCH_KEY_NUM > 0 */
for (y = 0; y < Y_Channel; y++) {
for (x = 0; x < X_Channel; x++) {
iArrayIndex = y * X_Channel + x;
xdata[iArrayIndex] = (int16_t)(rawdata_buf[iArrayIndex * 2] + 256 * rawdata_buf[iArrayIndex * 2 + 1]);
}
}
#if TOUCH_KEY_NUM > 0
for (k = 0; k < Key_Channel; k++) {
iArrayIndex = Y_Channel * X_Channel + k;
xdata[iArrayIndex] = (int16_t)(rawdata_buf[iArrayIndex * 2] + 256 * rawdata_buf[iArrayIndex * 2 + 1]);
}
#endif /* #if TOUCH_KEY_NUM > 0 */
/* for carrier sensing system to get short baseline rawdata */
if (ts->carrier_system) {
/* to get short baseline rawdata at pipe1 */
raw_pipe_addr = ts->mmap->RAW_PIPE1_ADDR;
for (y = 0; y < Y_Channel; y++) {
/*---change xdata index---*/
buf[0] = 0xFF;
buf[1] = (uint8_t)(((raw_pipe_addr + y * X_Channel * 2) >> 16) & 0xFF);
buf[2] = (uint8_t)(((raw_pipe_addr + y * X_Channel * 2) >> 8) & 0xFF);
CTP_I2C_WRITE(ts->client, I2C_FW_Address, buf, 3);
buf[0] = (uint8_t)((raw_pipe_addr + y * X_Channel * 2) & 0xFF);
CTP_I2C_READ(ts->client, I2C_FW_Address, buf, X_Channel * 2 + 1);
memcpy(rawdata_buf + y * X_Channel * 2, buf + 1, X_Channel * 2);
}
#if TOUCH_KEY_NUM > 0
/* to get button short baseline rawdata at pipe1 */
raw_btn_pipe_addr = ts->mmap->RAW_BTN_PIPE1_ADDR;
/*---change xdata index---*/
buf[0] = 0xFF;
buf[1] = (uint8_t)((raw_btn_pipe_addr >> 16) & 0xFF);
buf[2] = (uint8_t)((raw_btn_pipe_addr >> 8) & 0xFF);
CTP_I2C_WRITE(ts->client, I2C_FW_Address, buf, 3);
buf[0] = (uint8_t)(raw_btn_pipe_addr & 0xFF);
CTP_I2C_READ(ts->client, I2C_FW_Address, buf, Key_Channel * 2 + 1);
memcpy(rawdata_buf + Y_Channel * X_Channel * 2, buf + 1, Key_Channel * 2);
#endif /* #if TOUCH_KEY_NUM > 0 */
for (y = 0; y < Y_Channel; y++) {
for (x = 0; x < X_Channel; x++) {
iArrayIndex = y * X_Channel + x;
RawData_Short_Base[iArrayIndex] = (int16_t)(rawdata_buf[iArrayIndex * 2] + 256 * rawdata_buf[iArrayIndex * 2 + 1]);
}
}
#if TOUCH_KEY_NUM > 0
for (k = 0; k < Key_Channel; k++) {
iArrayIndex = Y_Channel * X_Channel + k;
RawData_Short_Base[iArrayIndex] = (int16_t)(rawdata_buf[iArrayIndex * 2] + 256 * rawdata_buf[iArrayIndex * 2 + 1]);
}
#endif /* #if TOUCH_KEY_NUM > 0 */
}
if (rawdata_buf) {
kfree(rawdata_buf);
rawdata_buf = NULL;
}
/*---Leave Test Mode---*/
nvt_change_mode(NORMAL_MODE);
if (ts->carrier_system)
printk("%s:RawData_Short_Diff:\n", __func__);
else
printk("%s:RawData_Short\n", __func__);
if (ts->carrier_system) {
#if TOUCH_KEY_NUM > 0
rawdata_short_base_offset = Y_Channel * X_Channel * 7 + Y_Channel * 2 + Key_Channel * 7 + 2;
#else
rawdata_short_base_offset = Y_Channel * X_Channel * 7 + Y_Channel * 2;
#endif /* #if TOUCH_KEY_NUM > 0 */
printk("%s:RawData_Short_Base:\n", __func__);
}
NVT_LOG("--\n");
return 0;
}
/*******************************************************
Description:
Novatek touchscreen raw data test for each single point function.
return:
Executive outcomes. 0---passed. negative---failed.
*******************************************************/
static int32_t RawDataTest_SinglePoint_Sub(int32_t rawdata[], uint8_t RecordResult[], uint8_t x_ch, uint8_t y_ch, int32_t Rawdata_Limit_Postive[], int32_t Rawdata_Limit_Negative[])
{
int32_t i = 0;
int32_t j = 0;
#if TOUCH_KEY_NUM > 0
int32_t k = 0;
#endif /* #if TOUCH_KEY_NUM > 0 */
int32_t iArrayIndex = 0;
bool isPass = true;
for (j = 0; j < y_ch; j++) {
for (i = 0; i < x_ch; i++) {
iArrayIndex = j * x_ch + i;
RecordResult[iArrayIndex] = 0x00; /* default value for PASS */
if (rawdata[iArrayIndex] > Rawdata_Limit_Postive[iArrayIndex])
RecordResult[iArrayIndex] |= 0x01;
if (rawdata[iArrayIndex] < Rawdata_Limit_Negative[iArrayIndex])
RecordResult[iArrayIndex] |= 0x02;
}
}
#if TOUCH_KEY_NUM > 0
for (k = 0; k < Key_Channel; k++) {
iArrayIndex = y_ch * x_ch + k;
RecordResult[iArrayIndex] = 0x00; /* default value for PASS */
if (rawdata[iArrayIndex] > Rawdata_Limit_Postive[iArrayIndex])
RecordResult[iArrayIndex] |= 0x01;
if (rawdata[iArrayIndex] < Rawdata_Limit_Negative[iArrayIndex])
RecordResult[iArrayIndex] |= 0x02;
}
#endif /* #if TOUCH_KEY_NUM > 0 */
/*---Check RecordResult---*/
for (j = 0; j < y_ch; j++) {
for (i = 0; i < x_ch; i++) {
if (RecordResult[j * x_ch + i] != 0) {
isPass = false;
break;
}
}
}
#if TOUCH_KEY_NUM > 0
for (k = 0; k < Key_Channel; k++) {
iArrayIndex = y_ch * x_ch + k;
if (RecordResult[iArrayIndex] != 0) {
isPass = false;
break;
}
}
#endif /* #if TOUCH_KEY_NUM > 0 */
if (isPass == false) {
return -1; /* FAIL */
} else {
return 0; /* PASS */
}
}
/*******************************************************
Description:
Novatek touchscreen print self-test result function.
return:
n.a.
*******************************************************/
void print_selftest_result(struct seq_file *m, int32_t TestResult, uint8_t RecordResult[], int32_t rawdata[], uint8_t x_len, uint8_t y_len)