xref: /OK3568_Linux_fs/kernel/drivers/input/touchscreen/focaltech_touch/focaltech_test/focaltech_test.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  *
3  * FocalTech TouchScreen driver.
4  *
5  * Copyright (c) 2012-2018, FocalTech Systems, Ltd., all rights reserved.
6  *
7  * This software is licensed under the terms of the GNU General Public
8  * License version 2, as published by the Free Software Foundation, and
9  * may be copied, distributed, and modified under those terms.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  */
17 
18 #ifndef _TEST_LIB_H
19 #define _TEST_LIB_H
20 
21 /*****************************************************************************
22 * Included header files
23 *****************************************************************************/
24 
25 #include <linux/kernel.h>
26 #include <linux/module.h>
27 #include <linux/slab.h>
28 #include <linux/debugfs.h>
29 #include <linux/uaccess.h>
30 #include <linux/i2c.h>//iic
31 #include <linux/delay.h>//msleep
32 #include <linux/string.h>
33 #include <asm/unistd.h>
34 #include <linux/vmalloc.h>
35 
36 #include "../focaltech_core.h"
37 #include "focaltech_test_ini.h"
38 
39 /*****************************************************************************
40 * Macro definitions using #define
41 *****************************************************************************/
42 #define FTS_INI_FILE_PATH                       "/mnt/sdcard/"
43 #define FTS_CSV_FILE_NAME                       "testdata.csv"
44 #define FTS_TXT_FILE_NAME                       "testresult.txt"
45 #define false 0
46 #define true  1
47 #define TEST_ICSERIES_LEN                       (8)
48 #define TEST_ICSERIES(x)                        ((x) >> TEST_ICSERIES_LEN)
49 
50 #define TEST_OPEN_MAX_VALUE                     (255)
51 #define BYTES_PER_TIME                          (32)  /* max:128 */
52 /* CSV & TXT */
53 #define CSV_LINE1_BUFFER_LEN                    (1024*1)
54 #define CSV_LINE2_BUFFER_LEN                    (1024*2)
55 #define CSV_DATA_BUFFER_LEN                     (1024*80)
56 #define CSV_BUFFER_LEN  (CSV_LINE1_BUFFER_LEN + CSV_LINE2_BUFFER_LEN + CSV_DATA_BUFFER_LEN)
57 #define TXT_BUFFER_LEN                          (1024*80*5)
58 
59 /*-----------------------------------------------------------
60 Test Status
61 -----------------------------------------------------------*/
62 #define RESULT_NULL                             0
63 #define RESULT_PASS                             1
64 #define RESULT_NG                               2
65 
66 #define TX_NUM_MAX                              60
67 #define RX_NUM_MAX                              60
68 #define NUM_MAX                     ((TX_NUM_MAX)*(RX_NUM_MAX))
69 #define NUM_MAX_SC                              (144)
70 #define KEY_NUM_MAX                             6
71 #define TEST_ITEM_COUNT_MAX                     32
72 #define TEST_SHORT_RES_MAX                      0xFFFF
73 
74 /*
75  * factory test registers
76  */
77 #define ENTER_WORK_FACTORY_RETRIES              5
78 
79 #define START_SCAN_RETRIES_INCELL               20
80 #define START_SCAN_RETRIES_DELAY_INCELL         16
81 #define FACTORY_TEST_RETRY                      50
82 #define FACTORY_TEST_DELAY                      18
83 #define FACTORY_TEST_RETRY_DELAY                100
84 
85 #define DEVIDE_MODE_ADDR                        0x00
86 #define REG_FW_CHIP_IDL                         0x9F
87 #define REG_FW_IC_TYPE                          0xA0
88 #define REG_FW_IC_VERSION                       0xB1
89 #define REG_FW_CHIP_IDH                         0xA3
90 #define REG_FW_VERSION                          0xA6
91 #define REG_VA_TOUCH_THR                        0x80
92 #define REG_VKEY_TOUCH_THR                      0x82
93 
94 #define FACTORY_REG_LINE_ADDR                   0x01
95 #define FACTORY_REG_CHX_NUM                     0x02
96 #define FACTORY_REG_CHY_NUM                     0x03
97 #define FACTORY_REG_CLB                         0x04
98 #define FACTORY_REG_DATA_SELECT                 0x06
99 #define FACTORY_REG_RAWBUF_SELECT               0x09
100 #define FACTORY_REG_KEY_CBWIDTH                 0x0B
101 #define FACTORY_REG_PARAM_UPDATE_STATE          0x0E
102 #define FACTORY_REG_SHORT_TEST_EN               0x0F
103 #define FACTORY_REG_SHORT_TEST_STATE            0x10
104 #define FACTORY_REG_LCD_NOISE_START             0x11
105 #define FACTORY_REG_LCD_NOISE_FRAME             0x12
106 #define FACTORY_REG_LCD_NOISE_NUMBER            0x13
107 #define FACTORY_REG_LCD_NOISE_TTHR              0x14
108 #define FACTORY_REG_OPEN_START                  0x15
109 #define FACTORY_REG_OPEN_STATE                  0x16
110 #define FACTORY_REG_CB_ADDR_H                   0x18
111 #define FACTORY_REG_CB_ADDR_L                   0x19
112 #define FACTORY_REG_LCD_NOISE_STATE             0x1E
113 #define FACTORY_REG_KEYSHORT_EN                 0x2E
114 #define FACTORY_REG_KEYSHORT_STATE              0x2F
115 
116 #define FACTORY_REG_LEFT_KEY                    0x1E
117 #define FACTORY_REG_RIGHT_KEY                   0x1F
118 #define FACTORY_REG_OPEN_REG20                  0x20
119 #define FACTORY_REG_OPEN_REG21                  0x21
120 #define FACTORY_REG_OPEN_REG22                  0x22
121 #define FACTORY_REG_OPEN_REG23                  0x23
122 #define FACTORY_REG_OPEN_REG86                  0x86
123 #define FACTORY_REG_K1                          0x31
124 #define FACTORY_REG_K2                          0x32
125 #define FACTORY_REG_RAWDATA_ADDR                0x6A
126 #define FACTORY_REG_CB_ADDR                     0x6E
127 #define FACTORY_REG_SHORT_ADDR                  0x89
128 #define FACTORY_REG_RAWDATA_TEST_EN             0x9E
129 #define FACTORY_REG_CB_TEST_EN                  0x9F
130 #define FACTORY_REG_OPEN_TEST_EN                0xA0
131 
132 /* mc_sc */
133 #define FACTORY_REG_FRE_LIST                    0x0A
134 #define FACTORY_REG_NORMALIZE                   0x16
135 #define FACTORY_REG_RAWDATA_ADDR_MC_SC          0x36
136 #define FACTORY_REG_PATTERN                     0x53
137 #define FACTORY_REG_NOMAPPING                   0x54
138 #define FACTORY_REG_CHX_NUM_NOMAP               0x55
139 #define FACTORY_REG_CHY_NUM_NOMAP               0x56
140 #define FACTORY_REG_WC_SEL                      0x09
141 #define FACTORY_REG_MC_SC_MODE                  0x44
142 #define FACTORY_REG_MC_SC_CB_ADDR_OFF           0x45
143 #define FACTORY_REG_MC_SC_CB_ADDR               0x4E
144 #define FACTROY_REG_SHORT_TEST_EN               0x07
145 #define FACTROY_REG_SHORT_CA                    0x01
146 #define FACTROY_REG_SHORT_CC                    0x02
147 #define FACTROY_REG_SHORT_CG                    0x03
148 #define FACTROY_REG_SHORT_OFFSET                0x04
149 #define FACTROY_REG_SHORT_AB_CH                 0x58
150 #define FACTROY_REG_SHORT_DELAY                 0x5A
151 #define FACTORY_REG_SHORT_ADDR_MC               0xF4
152 #define FACTORY_REG_FIR                         0xFB
153 
154 /* sc */
155 #define FACTORY_REG_SCAN_ADDR2                  0x08
156 #define FACTORY_REG_CH_NUM_SC                   0x0A
157 #define FACTORY_REG_KEY_NUM_SC                  0x0B
158 #define FACTORY_REG_SC_CB_ADDR_OFF              0x33
159 #define FACTORY_REG_SC_CB_ADDR                  0x39
160 #define FACTORY_REG_RAWDATA_SADDR_SC            0x34
161 #define FACTORY_REG_RAWDATA_ADDR_SC             0x35
162 #define FACTORY_REG_CB_SEL                      0x41
163 #define FACTORY_REG_FMODE                       0xAE
164 
165 #define TEST_RETVAL_00                          0x00
166 #define TEST_RETVAL_AA                          0xAA
167 
168 /*****************************************************************************
169 * enumerations, structures and unions
170 *****************************************************************************/
171 struct csv_format {
172     u8 *buffer;
173     int length;
174     u8 *line2_buffer;
175     int line2_len;
176     int start_line;
177     int item_count;
178     u8 *data_buffer;
179     int data_len;
180 };
181 
182 /* incell */
183 struct incell_testitem {
184     u32 short_test                  : 1;
185     u32 open_test                   : 1;
186     u32 cb_test                     : 1;
187     u32 rawdata_test                : 1;
188     u32 lcdnoise_test               : 1;
189     u32 keyshort_test               : 1;
190 };
191 
192 struct incell_threshold_b {
193     int short_res_min;
194     int short_res_vk_min;
195     int open_cb_min;
196     int open_k1_check;
197     int open_k1_value;
198     int open_k2_check;
199     int open_k2_value;
200     int cb_min;
201     int cb_max;
202     int cb_vkey_check;
203     int cb_min_vk;
204     int cb_max_vk;
205     int rawdata_min;
206     int rawdata_max;
207     int rawdata_vkey_check;
208     int rawdata_min_vk;
209     int rawdata_max_vk;
210     int lcdnoise_frame;
211     int lcdnoise_coefficient;
212     int lcdnoise_coefficient_vkey;
213     int open_nmos;
214     int keyshort_k1;
215     int keyshort_cb_max;
216     int rawdata2_min;
217     int rawdata2_max;
218 };
219 
220 struct incell_threshold {
221     struct incell_threshold_b basic;
222     int *rawdata_min;
223     int *rawdata_max;
224     int *rawdata2_min;
225     int *rawdata2_max;
226     int *cb_min;
227     int *cb_max;
228 };
229 
230 struct incell_test {
231     struct incell_threshold thr;
232     union {
233         int tmp;
234         struct incell_testitem item;
235     } u;
236 };
237 
238 /* mc_sc */
239 enum mapping_type {
240     MAPPING = 0,
241     NO_MAPPING = 1,
242 };
243 
244 struct mc_sc_testitem {
245     u32 rawdata_test                : 1;
246     u32 rawdata_uniformity_test     : 1;
247     u32 scap_cb_test                : 1;
248     u32 scap_rawdata_test           : 1;
249     u32 short_test                  : 1;
250     u32 panel_differ_test           : 1;
251 };
252 
253 struct mc_sc_threshold_b {
254     int rawdata_h_min;
255     int rawdata_h_max;
256     int rawdata_set_hfreq;
257     int rawdata_l_min;
258     int rawdata_l_max;
259     int rawdata_set_lfreq;
260     int uniformity_check_tx;
261     int uniformity_check_rx;
262     int uniformity_check_min_max;
263     int uniformity_tx_hole;
264     int uniformity_rx_hole;
265     int uniformity_min_max_hole;
266     int scap_cb_off_min;
267     int scap_cb_off_max;
268     int scap_cb_wp_off_check;
269     int scap_cb_on_min;
270     int scap_cb_on_max;
271     int scap_cb_wp_on_check;
272     int scap_rawdata_off_min;
273     int scap_rawdata_off_max;
274     int scap_rawdata_wp_off_check;
275     int scap_rawdata_on_min;
276     int scap_rawdata_on_max;
277     int scap_rawdata_wp_on_check;
278     int short_cg;
279     int short_cc;
280     int panel_differ_min;
281     int panel_differ_max;
282 
283 };
284 
285 struct mc_sc_threshold {
286     struct mc_sc_threshold_b basic;
287     int *rawdata_h_min;
288     int *rawdata_h_max;
289     int *rawdata_l_min;
290     int *rawdata_l_max;
291     int *tx_linearity_max;
292     int *tx_linearity_min;
293     int *rx_linearity_max;
294     int *rx_linearity_min;
295     int *scap_cb_off_min;
296     int *scap_cb_off_max;
297     int *scap_cb_on_min;
298     int *scap_cb_on_max;
299     int *scap_rawdata_off_min;
300     int *scap_rawdata_off_max;
301     int *scap_rawdata_on_min;
302     int *scap_rawdata_on_max;
303     int *panel_differ_min;
304     int *panel_differ_max;
305 };
306 
307 struct mc_sc_test {
308     struct mc_sc_threshold thr;
309     union {
310         u32 tmp;
311         struct mc_sc_testitem item;
312     } u;
313 };
314 
315 /* sc */
316 struct sc_testitem {
317     u32 rawdata_test                : 1;
318     u32 cb_test                     : 1;
319     u32 delta_cb_test               : 1;
320 };
321 
322 struct sc_threshold_b {
323     int rawdata_min;
324     int rawdata_max;
325     int cb_min;
326     int cb_max;
327     int dcb_base;
328     int dcb_differ_max;
329     int dcb_key_check;
330     int dcb_key_differ_max;
331     int dcb_ds1;
332     int dcb_ds2;
333     int dcb_ds3;
334     int dcb_ds4;
335     int dcb_ds5;
336     int dcb_ds6;
337     int dcb_critical_check;
338     int dcb_cs1;
339     int dcb_cs2;
340     int dcb_cs3;
341     int dcb_cs4;
342     int dcb_cs5;
343     int dcb_cs6;
344 };
345 
346 struct sc_threshold {
347     struct sc_threshold_b basic;
348     int *rawdata_min;
349     int *rawdata_max;
350     int *cb_min;
351     int *cb_max;
352     int *dcb_sort;
353     int *dcb_base;
354 };
355 
356 struct sc_test {
357     struct sc_threshold thr;
358     union {
359         u32 tmp;
360         struct sc_testitem item;
361     } u;
362 };
363 
364 enum test_hw_type {
365     IC_HW_INCELL = 1,
366     IC_HW_MC_SC,
367     IC_HW_SC,
368 };
369 
370 enum test_scan_mode {
371     SCAN_NORMAL = 0,
372     SCAN_SC,
373 };
374 
375 struct fts_test_node {
376     int channel_num;
377     int tx_num;
378     int rx_num;
379     int node_num;
380     int key_num;
381 };
382 
383 struct fts_test {
384     struct fts_ts_data *ts_data;
385     struct fts_test_node node;
386     struct fts_test_node sc_node;
387     u32 ic_ver;
388     u8 fw_ver;
389     u8 va_touch_thr;
390     u8 vk_touch_thr;
391     bool key_support;
392     bool v3_pattern;
393     u8 mapping;
394     u8 normalize;
395     int test_num;
396     int *buffer;
397     int buffer_length;
398     int *node_valid;
399     int *node_valid_sc;
400     int basic_thr_count;
401     int code1;
402     int code2;
403     int offset;
404     union {
405         struct incell_test incell;
406         struct mc_sc_test mc_sc;
407         struct sc_test sc;
408     } ic;
409 
410     struct test_funcs *func;
411     struct csv_format csv;
412     char *testresult;
413     int testresult_len;
414     struct ini_data ini;
415 };
416 
417 struct test_funcs {
418     u64 ctype[FTX_MAX_COMPATIBLE_TYPE];
419     enum test_hw_type hwtype;
420     int startscan_mode;
421     int key_num_total;
422     bool rawdata2_support;
423     bool force_touch;
424     int (*param_init)(void);
425     int (*init)(void);
426     int (*start_test)(void);
427 };
428 
429 enum byte_mode {
430     DATA_ONE_BYTE,
431     DATA_TWO_BYTE,
432 };
433 /* mc_sc */
434 enum normalize_type {
435     NORMALIZE_OVERALL,
436     NORMALIZE_AUTO,
437 };
438 
439 enum wp_type {
440     WATER_PROOF_OFF = 0,
441     WATER_PROOF_ON = 1,
442     WATER_PROOF_ON_TX,
443     WATER_PROOF_ON_RX,
444     WATER_PROOF_OFF_TX,
445     WATER_PROOF_OFF_RX,
446 };
447 /* mc end */
448 
449 /* sc */
450 enum factory_mode {
451     FACTORY_NORMAL,
452     FACTORY_TESTMODE_1,
453     FACTORY_TESTMODE_2,
454 };
455 
456 enum dcb_sort_num {
457     DCB_SORT_MIN = 1,
458     DCB_SORT_MAX = 6,
459 };
460 
461 struct dcb_sort_d {
462     int ch_num;
463     int deviation;
464     int critical;
465     int min;
466     int max;
467 };
468 /* sc end */
469 
470 enum csv_itemcode_incell {
471     CODE_ENTER_FACTORY_MODE = 0,
472     CODE_RAWDATA_TEST = 7,
473     CODE_CB_TEST = 12,
474     CODE_SHORT_TEST = 14,
475     CODE_OPEN_TEST = 15,
476     CODE_LCD_NOISE_TEST = 19,
477 };
478 
479 enum csv_itemcode_mc_sc {
480     CODE_M_RAWDATA_TEST = 7,
481     CODE_M_SCAP_CB_TEST = 9,
482     CODE_M_SCAP_RAWDATA_TEST = 10,
483     CODE_M_WEAK_SHORT_CIRCUIT_TEST = 15,
484     CODE_M_PANELDIFFER_TEST = 20,
485 };
486 
487 enum csv_itemcode_sc {
488     CODE_S_RAWDATA_TEST = 7,
489     CODE_S_CB_TEST = 13,
490     CODE_S_DCB_TEST = 14,
491 };
492 
493 /*****************************************************************************
494 * Global variable or extern global variabls/functions
495 *****************************************************************************/
496 extern struct test_funcs test_func_ft8201;
497 
498 extern struct fts_test *fts_ftest;
499 
500 void sys_delay(int ms);
501 int focal_abs(int value);
502 void print_buffer(int *buffer, int length, int line_num);
503 int fts_test_read_reg(u8 addr, u8 *val);
504 int fts_test_write_reg(u8 addr, u8 val);
505 int fts_test_read(u8 addr, u8 *readbuf, int readlen);
506 int fts_test_write(u8 addr, u8 *writebuf, int writelen);
507 int enter_work_mode(void);
508 int enter_factory_mode(void);
509 int read_mass_data(u8 addr, int byte_num, int *buf);
510 int chip_clb(void);
511 int wait_state_update(u8 retval);
512 int get_cb_incell(u16 saddr, int byte_num, int *cb_buf);
513 int short_get_adcdata_incell(u8 retval, u8 ch_num, int byte_num, int *adc_buf);
514 int start_scan(void);
515 int get_rawdata(int *data);
516 int get_cb_sc(int byte_num, int *cb_buf, enum byte_mode mode);
517 bool compare_data(int *data, int min, int max, int min_vk, int max_vk, bool key);
518 bool compare_array(int *data, int *min, int *max, bool key);
519 void show_data(int *data, bool key);
520 void save_data_csv(int *data, char *name, u8 code, bool mc_sc, bool key);
521 /* mc_sc */
522 int mapping_switch(u8 mapping);
523 bool get_fw_wp(u8 wp_channel_select, enum wp_type water_proof_type);
524 int get_cb_mc_sc(u8 wp, int byte_num, int *cb_buf, enum byte_mode mode);
525 int get_rawdata_mc_sc(enum wp_type wp, int *data);
526 int get_rawdata_mc(u8 fre, u8 fir, int *rawdata);
527 void short_print_mc(int *r, int num);
528 int short_get_adc_data_mc(u8 retval, int byte_num, int *adc_buf, u8 mode);
529 bool compare_mc_sc(bool, bool, int *, int *, int *);
530 void show_data_mc_sc(int *data);
531 void *fts_malloc(size_t size);
532 void fts_free_proc(void *p);
533 int fts_test_init(struct i2c_client *client);
534 int fts_test_exit(struct i2c_client *client);
535 
536 #define fts_malloc_r(p, size) do {\
537     if (NULL == p) {\
538         p = fts_malloc(size);\
539         if (NULL == p) {\
540             return -ENOMEM;\
541         }\
542     }\
543 } while(0)
544 
545 #define fts_free(p) do {\
546     if (p) {\
547         fts_free_proc(p);\
548         p = NULL;\
549     }\
550 } while(0)
551 
552 #define TEST_IC_VERSION(idh, idl, ver1, ver0) \
553     (((idh) << 24) | ((idl) << 16) | ((ver1) << 8) | (ver0))
554 
555 #define CSV_SUPPORT             1
556 
557 #define FOCAL_TEST_DEBUG_EN     1
558 #if (FOCAL_TEST_DEBUG_EN)
559 #define FTS_TEST_DBG(fmt, args...) do {printk("[FTS][TEST]%s. line: %d.  "fmt"\n",  __FUNCTION__, __LINE__, ##args);} while (0)
560 #define FTS_TEST_FUNC_ENTER() printk("[FTS][TEST]%s: Enter(%d)\n", __func__, __LINE__)
561 #define FTS_TEST_FUNC_EXIT()  printk("[FTS][TEST]%s: Exit(%d)\n", __func__, __LINE__)
562 #else
563 #define FTS_TEST_DBG(fmt, args...) do{}while(0)
564 #define FTS_TEST_FUNC_ENTER()
565 #define FTS_TEST_FUNC_EXIT()
566 #endif
567 
568 #define FTS_TEST_INFO(fmt, args...) do { printk(KERN_ERR "[FTS][TEST][Info]%s. line: %d.  "fmt"\n",  __FUNCTION__, __LINE__, ##args);} while (0)
569 #define FTS_TEST_ERROR(fmt, args...) do { printk(KERN_ERR "[FTS][TEST][Error]%s. line: %d.  "fmt"\n",  __FUNCTION__, __LINE__, ##args);} while (0)
570 
571 #define FTS_TEST_SAVE_INFO(fmt, args...)  do { \
572     if (fts_ftest->testresult) { \
573         fts_ftest->testresult_len += snprintf( \
574         fts_ftest->testresult + fts_ftest->testresult_len, \
575         TXT_BUFFER_LEN, \
576         fmt, ##args);\
577     } \
578 } while (0)
579 
580 #define FTS_TEST_SAVE_ERR(fmt, args...)  do { \
581     if (fts_ftest->testresult) { \
582         fts_ftest->testresult_len += snprintf( \
583         fts_ftest->testresult + fts_ftest->testresult_len, \
584         TXT_BUFFER_LEN, \
585         fmt, ##args);\
586     } \
587     printk(KERN_ERR "[FTS][TEST][Error]%s. line: %d.  "fmt"",  __FUNCTION__, __LINE__, ##args);\
588 } while (0)
589 #endif
590