12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481 |
- // SPDX-License-Identifier: GPL-2.0-only
- /*
- * Copyright (C) 2010 - 2018 Novatek, Inc.
- *
- * $Revision: 47247 $
- * $Date: 2019-07-10 10:41:36 +0800 (Wed, 10 Jul 2019) $
- *
- * 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/slab.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_Open = NULL;
- static uint8_t *RecordResult_FWMutual = NULL;
- static uint8_t *RecordResult_FW_CC = 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_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_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_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 struct proc_dir_entry *NVT_proc_selftest_entry = NULL;
- static int8_t nvt_mp_test_result_printed = 0;
- static uint8_t fw_ver = 0;
- unsigned char mpcriteria[PAGE_SIZE]; //novatek-mp-criteria-default
- 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);
- int32_t 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 = kzalloc(RecordResult_BufSize, GFP_KERNEL);
- if (!RecordResult_Short) {
- NVT_ERR("kzalloc for RecordResult_Short failed!\n");
- return -ENOMEM;
- }
- RecordResult_Open = kzalloc(RecordResult_BufSize, GFP_KERNEL);
- if (!RecordResult_Open) {
- NVT_ERR("kzalloc for RecordResult_Open failed!\n");
- return -ENOMEM;
- }
- RecordResult_FWMutual = kzalloc(RecordResult_BufSize, GFP_KERNEL);
- if (!RecordResult_FWMutual) {
- NVT_ERR("kzalloc for RecordResult_FWMutual failed!\n");
- return -ENOMEM;
- }
- RecordResult_FW_CC = kzalloc(RecordResult_BufSize, GFP_KERNEL);
- if (!RecordResult_FW_CC) {
- NVT_ERR("kzalloc for RecordResult_FW_CC failed!\n");
- return -ENOMEM;
- }
- RecordResult_FW_DiffMax = kzalloc(RecordResult_BufSize, GFP_KERNEL);
- if (!RecordResult_FW_DiffMax) {
- NVT_ERR("kzalloc for RecordResult_FW_DiffMax failed!\n");
- return -ENOMEM;
- }
- RecordResult_FW_DiffMin = kzalloc(RecordResult_BufSize, GFP_KERNEL);
- if (!RecordResult_FW_DiffMin) {
- NVT_ERR("kzalloc for RecordResult_FW_DiffMin failed!\n");
- return -ENOMEM;
- }
- RawData_Short = kzalloc(RawData_BufSize, GFP_KERNEL);
- if (!RawData_Short) {
- NVT_ERR("kzalloc for RawData_Short failed!\n");
- return -ENOMEM;
- }
- RawData_Open = kzalloc(RawData_BufSize, GFP_KERNEL);
- if (!RawData_Open) {
- NVT_ERR("kzalloc for RawData_Open failed!\n");
- return -ENOMEM;
- }
- RawData_Diff = kzalloc(RawData_BufSize, GFP_KERNEL);
- if (!RawData_Diff) {
- NVT_ERR("kzalloc for RawData_Diff failed!\n");
- return -ENOMEM;
- }
- RawData_Diff_Min = kzalloc(RawData_BufSize, GFP_KERNEL);
- if (!RawData_Diff_Min) {
- NVT_ERR("kzalloc for RawData_Diff_Min failed!\n");
- return -ENOMEM;
- }
- RawData_Diff_Max = kzalloc(RawData_BufSize, GFP_KERNEL);
- if (!RawData_Diff_Max) {
- NVT_ERR("kzalloc for RawData_Diff_Max failed!\n");
- return -ENOMEM;
- }
- RawData_FWMutual = kzalloc(RawData_BufSize, GFP_KERNEL);
- if (!RawData_FWMutual) {
- NVT_ERR("kzalloc for RawData_FWMutual failed!\n");
- return -ENOMEM;
- }
- RawData_FW_CC = kzalloc(RawData_BufSize, GFP_KERNEL);
- if (!RawData_FW_CC) {
- NVT_ERR("kzalloc for RawData_FW_CC failed!\n");
- return -ENOMEM;
- }
- return 0;
- }
- /*******************************************************
- Description:
- Novatek touchscreen free buffer for mp selftest.
- return:
- n.a.
- *******************************************************/
- static void nvt_mp_buffer_deinit(void)
- {
- if (RecordResult_Short) {
- kfree(RecordResult_Short);
- RecordResult_Short = NULL;
- }
- if (RecordResult_Open) {
- kfree(RecordResult_Open);
- RecordResult_Open = NULL;
- }
- if (RecordResult_FWMutual) {
- kfree(RecordResult_FWMutual);
- RecordResult_FWMutual = NULL;
- }
- if (RecordResult_FW_CC) {
- kfree(RecordResult_FW_CC);
- RecordResult_FW_CC = NULL;
- }
- if (RecordResult_FW_DiffMax) {
- kfree(RecordResult_FW_DiffMax);
- RecordResult_FW_DiffMax = NULL;
- }
- if (RecordResult_FW_DiffMin) {
- kfree(RecordResult_FW_DiffMin);
- RecordResult_FW_DiffMin = NULL;
- }
- if (RawData_Short) {
- kfree(RawData_Short);
- RawData_Short = NULL;
- }
- if (RawData_Open) {
- kfree(RawData_Open);
- RawData_Open = NULL;
- }
- if (RawData_Diff) {
- kfree(RawData_Diff);
- RawData_Diff = NULL;
- }
- if (RawData_Diff_Min) {
- kfree(RawData_Diff_Min);
- RawData_Diff_Min = NULL;
- }
- if (RawData_Diff_Max) {
- kfree(RawData_Diff_Max);
- RawData_Diff_Max = NULL;
- }
- if (RawData_FWMutual) {
- kfree(RawData_FWMutual);
- RawData_FWMutual = NULL;
- }
- if (RawData_FW_CC) {
- kfree(RawData_FW_CC);
- RawData_FW_CC = NULL;
- }
- }
- static void nvt_print_data_log_in_one_line(int32_t *data, int32_t data_num)
- {
- char *tmp_log = NULL;
- int32_t i = 0;
- int32_t count = data_num * 7 + 1;
- tmp_log = kzalloc(count, GFP_KERNEL);
- if (!tmp_log) {
- NVT_ERR("kzalloc for tmp_log failed!\n ");
- return;
- }
- for (i = 0; i < data_num; i++) {
- snprintf(tmp_log + i * 7, count - i * 7, "%5d, ", data[i]);
- }
- tmp_log[data_num * 7] = '\0';
- printk("%s", tmp_log);
- if (tmp_log) {
- kfree(tmp_log);
- tmp_log = NULL;
- }
- return;
- }
- static void nvt_print_result_log_in_one_line(uint8_t *result, int32_t result_num)
- {
- char *tmp_log = NULL;
- int32_t i = 0;
- int32_t count = 0;
- count = result_num * 6 + 1;
- tmp_log = kzalloc(count, GFP_KERNEL);
- if (!tmp_log) {
- NVT_ERR("kzalloc for tmp_log failed!\n ");
- return;
- }
- for (i = 0; i < result_num; i++) {
- snprintf(tmp_log + i * 6, count - i * 6, "0x%02X, ", result[i]);
- }
- tmp_log[result_num * 6] = '\0';
- printk("%s", tmp_log);
- if (tmp_log) {
- kfree(tmp_log);
- tmp_log = NULL;
- }
- return;
- }
- /*******************************************************
- 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 j = 0;
- for (j = 0; j < y_ch; j++) {
- nvt_print_data_log_in_one_line(array + j * x_ch, x_ch);
- printk("\n");
- }
- #if TOUCH_KEY_NUM > 0
- nvt_print_data_log_in_one_line(array + y_ch * x_ch, Key_Channel);
- printk("\n");
- #endif /* #if TOUCH_KEY_NUM > 0 */
- }
- static void nvt_print_criteria(void)
- {
- NVT_LOG("++\n");
- //---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);
- //---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 = 70;
- for (i = 0; i < retry; i++) {
- //---set xdata index to EVENT BUF ADDR---
- nvt_set_page(I2C_FW_Address, ts->mmap->EVENT_BUF_ADDR | EVENT_MAP_HANDSHAKING_or_SUB_CMD_BYTE);
- //---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;
- usleep_range(10000, 10000);
- }
- 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
- nvt_set_page(I2C_FW_Address, ts->mmap->EVENT_BUF_ADDR | EVENT_MAP_HOST_CMD);
- 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---
- nvt_set_page(I2C_FW_Address, ts->mmap->EVENT_BUF_ADDR | EVENT_MAP_HOST_CMD);
- //---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;
- xdata[iArrayIndex] = (int16_t)xdata[iArrayIndex];
- }
- }
- #if TOUCH_KEY_NUM > 0
- for (k = 0; k < Key_Channel; k++) {
- iArrayIndex = Y_Channel * X_Channel + k;
- xdata[iArrayIndex] = (int16_t)xdata[iArrayIndex];
- }
- #endif /* #if TOUCH_KEY_NUM > 0 */
- 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;
- #if TOUCH_KEY_NUM > 0
- int32_t k = 0;
- #endif /* #if TOUCH_KEY_NUM > 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;
- xdata[iArrayIndex] = (int16_t)xdata[iArrayIndex];
- }
- }
- #if TOUCH_KEY_NUM > 0
- for (k = 0; k < Key_Channel; k++) {
- iArrayIndex = Y_Channel * X_Channel + k;
- xdata[iArrayIndex] = (int16_t)xdata[iArrayIndex];
- }
- #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---
- nvt_set_page(I2C_FW_Address, ts->mmap->EVENT_BUF_ADDR | EVENT_MAP_HOST_CMD);
- //---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;
- #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;
- 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;
- 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);
- NVT_LOG("--\n");
- return 0;
- }
- static void nvt_enable_open_test(void)
- {
- uint8_t buf[8] = {0};
- //---set xdata index to EVENT BUF ADDR---
- nvt_set_page(I2C_FW_Address, ts->mmap->EVENT_BUF_ADDR | EVENT_MAP_HOST_CMD);
- //---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---
- nvt_set_page(I2C_FW_Address, ts->mmap->EVENT_BUF_ADDR | EVENT_MAP_HOST_CMD);
- //---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 = kzalloc((IC_X_CFG_SIZE * IC_Y_CFG_SIZE + IC_KEY_CFG_SIZE) * 2, GFP_KERNEL);
- #else
- rawdata_buf = 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---
- nvt_set_page(I2C_FW_Address, raw_pipe_addr + y * IC_X_CFG_SIZE * 2);
- 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---
- nvt_set_page(I2C_FW_Address, raw_btn_pipe_addr);
- 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);
- 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 */
- 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 = kzalloc((X_Channel * Y_Channel + Key_Channel) * 2, GFP_KERNEL);
- #else
- rawdata_buf = 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 (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---
- nvt_set_page(I2C_FW_Address, raw_pipe_addr + y * X_Channel * 2);
- 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 (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---
- nvt_set_page(I2C_FW_Address, raw_btn_pipe_addr);
- 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 */
- if (rawdata_buf) {
- kfree(rawdata_buf);
- rawdata_buf = NULL;
- }
- //---Leave Test Mode---
- nvt_change_mode(NORMAL_MODE);
- 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) {
- 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)
- {
- int32_t i = 0;
- int32_t j = 0;
- int32_t iArrayIndex = 0;
- #if TOUCH_KEY_NUM > 0
- int32_t k = 0;
- #endif /* #if TOUCH_KEY_NUM > 0 */
- switch (TestResult) {
- case 0:
- nvt_mp_seq_printf(m, " PASS!\n");
- break;
- case 1:
- nvt_mp_seq_printf(m, " ERROR! Read Data FAIL!\n");
- break;
- case -1:
- nvt_mp_seq_printf(m, " FAIL!\n");
- nvt_mp_seq_printf(m, "RecordResult:\n");
- for (i = 0; i < y_len; i++) {
- for (j = 0; j < x_len; j++) {
- iArrayIndex = i * x_len + j;
- seq_printf(m, "0x%02X, ", RecordResult[iArrayIndex]);
- }
- if (!nvt_mp_test_result_printed)
- nvt_print_result_log_in_one_line(RecordResult + i * x_len, x_len);
- nvt_mp_seq_printf(m, "\n");
- }
- #if TOUCH_KEY_NUM > 0
- for (k = 0; k < Key_Channel; k++) {
- iArrayIndex = y_len * x_len + k;
- seq_printf(m, "0x%02X, ", RecordResult[iArrayIndex]);
- }
- if (!nvt_mp_test_result_printed)
- nvt_print_result_log_in_one_line(RecordResult + y_len * x_len, Key_Channel);
- nvt_mp_seq_printf(m, "\n");
- #endif /* #if TOUCH_KEY_NUM > 0 */
- nvt_mp_seq_printf(m, "ReadData:\n");
- for (i = 0; i < y_len; i++) {
- for (j = 0; j < x_len; j++) {
- iArrayIndex = i * x_len + j;
- seq_printf(m, "%5d, ", rawdata[iArrayIndex]);
- }
- if (!nvt_mp_test_result_printed)
- nvt_print_data_log_in_one_line(rawdata + i * x_len, x_len);
- nvt_mp_seq_printf(m, "\n");
- }
- #if TOUCH_KEY_NUM > 0
- for (k = 0; k < Key_Channel; k++) {
- iArrayIndex = y_len * x_len + k;
- seq_printf(m, "%5d, ", rawdata[iArrayIndex]);
- }
- if (!nvt_mp_test_result_printed)
- nvt_print_data_log_in_one_line(rawdata + y_len * x_len, Key_Channel);
- nvt_mp_seq_printf(m, "\n");
- #endif /* #if TOUCH_KEY_NUM > 0 */
- break;
- }
- nvt_mp_seq_printf(m, "\n");
- }
- /*******************************************************
- Description:
- Novatek touchscreen self-test sequence print show
- function.
- return:
- Executive outcomes. 0---succeed.
- *******************************************************/
- static int32_t c_show_selftest(struct seq_file *m, void *v)
- {
- NVT_LOG("++\n");
- nvt_mp_seq_printf(m, "FW Version: %d\n\n", fw_ver);
- nvt_mp_seq_printf(m, "Short Test");
- print_selftest_result(m, TestResult_Short, RecordResult_Short, RawData_Short, X_Channel, Y_Channel);
- nvt_mp_seq_printf(m, "Open Test");
- print_selftest_result(m, TestResult_Open, RecordResult_Open, RawData_Open, X_Channel, Y_Channel);
- nvt_mp_seq_printf(m, "FW Rawdata Test");
- if ((TestResult_FW_Rawdata == 0) || (TestResult_FW_Rawdata == 1)) {
- print_selftest_result(m, TestResult_FWMutual, RecordResult_FWMutual, RawData_FWMutual, X_Channel, Y_Channel);
- } else { // TestResult_FW_Rawdata is -1
- nvt_mp_seq_printf(m, " FAIL!\n");
- if (TestResult_FWMutual == -1) {
- nvt_mp_seq_printf(m, "FW Mutual");
- print_selftest_result(m, TestResult_FWMutual, RecordResult_FWMutual, RawData_FWMutual, X_Channel, Y_Channel);
- }
- if (TestResult_FW_CC == -1) {
- nvt_mp_seq_printf(m, "FW CC");
- print_selftest_result(m, TestResult_FW_CC, RecordResult_FW_CC, RawData_FW_CC, X_Channel, Y_Channel);
- }
- }
- nvt_mp_seq_printf(m, "Noise Test");
- if ((TestResult_Noise == 0) || (TestResult_Noise == 1)) {
- print_selftest_result(m, TestResult_FW_DiffMax, RecordResult_FW_DiffMax, RawData_Diff_Max, X_Channel, Y_Channel);
- } else { // TestResult_Noise is -1
- nvt_mp_seq_printf(m, " FAIL!\n");
- if (TestResult_FW_DiffMax == -1) {
- nvt_mp_seq_printf(m, "FW Diff Max");
- print_selftest_result(m, TestResult_FW_DiffMax, RecordResult_FW_DiffMax, RawData_Diff_Max, X_Channel, Y_Channel);
- }
- if (TestResult_FW_DiffMin == -1) {
- nvt_mp_seq_printf(m, "FW Diff Min");
- print_selftest_result(m, TestResult_FW_DiffMin, RecordResult_FW_DiffMin, RawData_Diff_Min, X_Channel, Y_Channel);
- }
- }
- nvt_mp_test_result_printed = 1;
- NVT_LOG("--\n");
- return 0;
- }
- /*******************************************************
- Description:
- Novatek touchscreen self-test sequence print start
- function.
- return:
- Executive outcomes. 1---call next function.
- NULL---not call next function and sequence loop
- stop.
- *******************************************************/
- static void *c_start(struct seq_file *m, loff_t *pos)
- {
- return *pos < 1 ? (void *)1 : NULL;
- }
- /*******************************************************
- Description:
- Novatek touchscreen self-test sequence print next
- function.
- return:
- Executive outcomes. NULL---no next and call sequence
- stop function.
- *******************************************************/
- static void *c_next(struct seq_file *m, void *v, loff_t *pos)
- {
- ++*pos;
- return NULL;
- }
- /*******************************************************
- Description:
- Novatek touchscreen self-test sequence print stop
- function.
- return:
- n.a.
- *******************************************************/
- static void c_stop(struct seq_file *m, void *v)
- {
- return;
- }
- const struct seq_operations nvt_selftest_seq_ops = {
- .start = c_start,
- .next = c_next,
- .stop = c_stop,
- .show = c_show_selftest
- };
- /*******************************************************
- Description:
- Novatek touchscreen /proc/nvt_selftest open function.
- return:
- Executive outcomes. 0---succeed. negative---failed.
- *******************************************************/
- static int32_t nvt_selftest_open(struct inode *inode, struct file *file)
- {
- struct device_node *np = ts->client->dev.of_node;
- memset(mpcriteria, 0, PAGE_SIZE * sizeof(mpcriteria[0]));
- TestResult_Short = 0;
- TestResult_Open = 0;
- TestResult_FW_Rawdata = 0;
- TestResult_FWMutual = 0;
- TestResult_FW_CC = 0;
- TestResult_Noise = 0;
- TestResult_FW_DiffMax = 0;
- TestResult_FW_DiffMin = 0;
- NVT_LOG("++\n");
- if (mutex_lock_interruptible(&ts->lock)) {
- return -ERESTARTSYS;
- }
- #if NVT_TOUCH_ESD_PROTECT
- nvt_esd_check_enable(false);
- #endif /* #if NVT_TOUCH_ESD_PROTECT */
- if (nvt_get_fw_info()) {
- mutex_unlock(&ts->lock);
- NVT_ERR("get fw info failed!\n");
- return -EAGAIN;
- }
- fw_ver = ts->fw_ver;
- /* Parsing criteria from dts */
- if(of_property_read_bool(np, "novatek,mp-support-dt")) {
- /*
- * Parsing Criteria by Novatek PID
- * The string rule is "novatek-mp-criteria-<nvt_pid>"
- * nvt_pid is 2 bytes (show hex).
- *
- * Ex. nvt_pid = 500A
- * mpcriteria = "novatek-mp-criteria-500A"
- */
- snprintf(mpcriteria, PAGE_SIZE, "novatek-mp-criteria-%04X", ts->nvt_pid);
- if (nvt_mp_parse_dt(np, mpcriteria)) {
- mutex_unlock(&ts->lock);
- NVT_ERR("mp parse device tree failed!\n");
- return -EINVAL;
- }
- } else {
- NVT_LOG("Not found novatek,mp-support-dt, use default setting\n");
- //---Print Test Criteria---
- nvt_print_criteria();
- }
- if (nvt_switch_FreqHopEnDis(FREQ_HOP_DISABLE)) {
- mutex_unlock(&ts->lock);
- NVT_ERR("switch frequency hopping disable failed!\n");
- return -EAGAIN;
- }
- if (nvt_check_fw_reset_state(RESET_STATE_NORMAL_RUN)) {
- mutex_unlock(&ts->lock);
- NVT_ERR("check fw reset state failed!\n");
- return -EAGAIN;
- }
- msleep(100);
- //---Enter Test Mode---
- if (nvt_clear_fw_status()) {
- mutex_unlock(&ts->lock);
- NVT_ERR("clear fw status failed!\n");
- return -EAGAIN;
- }
- nvt_change_mode(MP_MODE_CC);
- if (nvt_check_fw_status()) {
- mutex_unlock(&ts->lock);
- NVT_ERR("check fw status failed!\n");
- return -EAGAIN;
- }
- //---FW Rawdata Test---
- if (nvt_read_baseline(RawData_FWMutual) != 0) {
- TestResult_FWMutual = 1;
- } else {
- TestResult_FWMutual = RawDataTest_SinglePoint_Sub(RawData_FWMutual, RecordResult_FWMutual, X_Channel, Y_Channel,
- PS_Config_Lmt_FW_Rawdata_P, PS_Config_Lmt_FW_Rawdata_N);
- }
- if (nvt_read_CC(RawData_FW_CC) != 0) {
- TestResult_FW_CC = 1;
- } else {
- TestResult_FW_CC = RawDataTest_SinglePoint_Sub(RawData_FW_CC, RecordResult_FW_CC, X_Channel, Y_Channel,
- PS_Config_Lmt_FW_CC_P, PS_Config_Lmt_FW_CC_N);
- }
- if ((TestResult_FWMutual == 1) || (TestResult_FW_CC == 1)) {
- TestResult_FW_Rawdata = 1;
- } else {
- if ((TestResult_FWMutual == -1) || (TestResult_FW_CC == -1))
- TestResult_FW_Rawdata = -1;
- else
- TestResult_FW_Rawdata = 0;
- }
- //---Leave Test Mode---
- nvt_change_mode(NORMAL_MODE);
- //---Noise Test---
- if (nvt_read_fw_noise(RawData_Diff) != 0) {
- TestResult_Noise = 1; // 1: ERROR
- TestResult_FW_DiffMax = 1;
- TestResult_FW_DiffMin = 1;
- } else {
- TestResult_FW_DiffMax = RawDataTest_SinglePoint_Sub(RawData_Diff_Max, RecordResult_FW_DiffMax, X_Channel, Y_Channel,
- PS_Config_Lmt_FW_Diff_P, PS_Config_Lmt_FW_Diff_N);
- TestResult_FW_DiffMin = RawDataTest_SinglePoint_Sub(RawData_Diff_Min, RecordResult_FW_DiffMin, X_Channel, Y_Channel,
- PS_Config_Lmt_FW_Diff_P, PS_Config_Lmt_FW_Diff_N);
- if ((TestResult_FW_DiffMax == -1) || (TestResult_FW_DiffMin == -1))
- TestResult_Noise = -1;
- else
- TestResult_Noise = 0;
- }
- //--Short Test---
- if (nvt_read_fw_short(RawData_Short) != 0) {
- TestResult_Short = 1; // 1:ERROR
- } else {
- //---Self Test Check --- // 0:PASS, -1:FAIL
- TestResult_Short = RawDataTest_SinglePoint_Sub(RawData_Short, RecordResult_Short, X_Channel, Y_Channel,
- PS_Config_Lmt_Short_Rawdata_P, PS_Config_Lmt_Short_Rawdata_N);
- }
- //---Open Test---
- if (nvt_read_fw_open(RawData_Open) != 0) {
- TestResult_Open = 1; // 1:ERROR
- } else {
- //---Self Test Check --- // 0:PASS, -1:FAIL
- TestResult_Open = RawDataTest_SinglePoint_Sub(RawData_Open, RecordResult_Open, X_Channel, Y_Channel,
- PS_Config_Lmt_Open_Rawdata_P, PS_Config_Lmt_Open_Rawdata_N);
- }
- //---Reset IC---
- nvt_bootloader_reset();
- mutex_unlock(&ts->lock);
- NVT_LOG("--\n");
- nvt_mp_test_result_printed = 0;
- return seq_open(file, &nvt_selftest_seq_ops);
- }
- static const struct proc_ops nvt_selftest_fops = {
- .proc_open = nvt_selftest_open,
- .proc_read = seq_read,
- .proc_lseek = seq_lseek,
- .proc_release = seq_release,
- };
- #ifdef CONFIG_OF
- /*******************************************************
- Description:
- Novatek touchscreen parse AIN setting for array type.
- return:
- n.a.
- *******************************************************/
- int32_t nvt_mp_parse_ain(struct device_node *np, const char *name, uint8_t *array, int32_t size)
- {
- struct property *data;
- int32_t len, ret;
- int32_t tmp[40];
- int32_t i;
- data = of_find_property(np, name, &len);
- len /= sizeof(u32);
- if ((!data) || (!len) || (len != size)) {
- NVT_ERR("error find %s. len=%d\n", name, len);
- return -1;
- } else {
- NVT_LOG("%s. len=%d\n", name, len);
- ret = of_property_read_u32_array(np, name, tmp, len);
- if (ret) {
- NVT_ERR("error reading %s. ret=%d\n", name, ret);
- return -1;
- }
- for (i = 0; i < len; i++)
- array[i] = tmp[i];
- #if NVT_DEBUG
- printk("[NVT-ts] %s = ", name);
- nvt_print_result_log_in_one_line(array, len);
- printk("\n");
- #endif
- }
- return 0;
- }
- /*******************************************************
- Description:
- Novatek touchscreen parse criterion for u32 type.
- return:
- n.a.
- *******************************************************/
- int32_t nvt_mp_parse_u32(struct device_node *np, const char *name, int32_t *para)
- {
- int32_t ret;
- ret = of_property_read_u32(np, name, para);
- if (ret) {
- NVT_ERR("error reading %s. ret=%d\n", name, ret);
- return -1;
- } else {
- #if NVT_DEBUG
- NVT_LOG("%s=%d\n", name, *para);
- #endif
- }
- return 0;
- }
- /*******************************************************
- Description:
- Novatek touchscreen parse criterion for array type.
- return:
- n.a.
- *******************************************************/
- int32_t nvt_mp_parse_array(struct device_node *np, const char *name, int32_t *array,
- int32_t size)
- {
- struct property *data;
- int32_t len, ret;
- #if NVT_DEBUG
- int32_t j = 0;
- #endif
- data = of_find_property(np, name, &len);
- len /= sizeof(u32);
- if ((!data) || (!len) || (len < size)) {
- NVT_ERR("error find %s. len=%d\n", name, len);
- return -1;
- } else {
- NVT_LOG("%s. len=%d\n", name, len);
- ret = of_property_read_u32_array(np, name, array, len);
- if (ret) {
- NVT_ERR("error reading %s. ret=%d\n", name, ret);
- return -1;
- }
- #if NVT_DEBUG
- NVT_LOG("%s =\n", name);
- for (j = 0; j < Y_Channel; j++) {
- nvt_print_data_log_in_one_line(array + j * X_Channel, X_Channel);
- printk("\n");
- }
- #if TOUCH_KEY_NUM > 0
- nvt_print_data_log_in_one_line(array + Y_Channel * X_Channel, Key_Channel);
- printk("\n");
- #endif
- #endif
- }
- return 0;
- }
- /*******************************************************
- Description:
- Novatek touchscreen parse device tree mp function.
- return:
- n.a.
- *******************************************************/
- int32_t nvt_mp_parse_dt(struct device_node *root, const char *node_compatible)
- {
- struct device_node *np = root;
- struct device_node *child = NULL;
- NVT_LOG("Parse mp criteria for node %s\n", node_compatible);
- /* find each MP sub-nodes */
- for_each_child_of_node(root, child) {
- /* find the specified node */
- if (of_device_is_compatible(child, node_compatible)) {
- NVT_LOG("found child node %s\n", node_compatible);
- np = child;
- break;
- }
- }
- if (child == NULL) {
- NVT_ERR("Not found compatible node %s!\n", node_compatible);
- return -1;
- }
- /* MP Config*/
- if (nvt_mp_parse_u32(np, "IC_X_CFG_SIZE", &IC_X_CFG_SIZE))
- return -1;
- if (nvt_mp_parse_u32(np, "IC_Y_CFG_SIZE", &IC_Y_CFG_SIZE))
- return -1;
- #if TOUCH_KEY_NUM > 0
- if (nvt_mp_parse_u32(np, "IC_KEY_CFG_SIZE", &IC_KEY_CFG_SIZE))
- return -1;
- #endif
- if (nvt_mp_parse_u32(np, "X_Channel", &X_Channel))
- return -1;
- if (nvt_mp_parse_u32(np, "Y_Channel", &Y_Channel))
- return -1;
- if (nvt_mp_parse_ain(np, "AIN_X", AIN_X, IC_X_CFG_SIZE))
- return -1;
- if (nvt_mp_parse_ain(np, "AIN_Y", AIN_Y, IC_Y_CFG_SIZE))
- return -1;
- #if TOUCH_KEY_NUM > 0
- if (nvt_mp_parse_ain(np, "AIN_KEY", AIN_KEY, IC_KEY_CFG_SIZE))
- return -1;
- #endif
- /* MP Criteria */
- if (nvt_mp_parse_array(np, "PS_Config_Lmt_Short_Rawdata_P", PS_Config_Lmt_Short_Rawdata_P,
- X_Channel * Y_Channel + Key_Channel))
- return -1;
- if (nvt_mp_parse_array(np, "PS_Config_Lmt_Short_Rawdata_N", PS_Config_Lmt_Short_Rawdata_N,
- X_Channel * Y_Channel + Key_Channel))
- return -1;
- if (nvt_mp_parse_array(np, "PS_Config_Lmt_Open_Rawdata_P", PS_Config_Lmt_Open_Rawdata_P,
- X_Channel * Y_Channel + Key_Channel))
- return -1;
- if (nvt_mp_parse_array(np, "PS_Config_Lmt_Open_Rawdata_N", PS_Config_Lmt_Open_Rawdata_N,
- X_Channel * Y_Channel + Key_Channel))
- return -1;
- if (nvt_mp_parse_array(np, "PS_Config_Lmt_FW_Rawdata_P", PS_Config_Lmt_FW_Rawdata_P,
- X_Channel * Y_Channel + Key_Channel))
- return -1;
- if (nvt_mp_parse_array(np, "PS_Config_Lmt_FW_Rawdata_N", PS_Config_Lmt_FW_Rawdata_N,
- X_Channel * Y_Channel + Key_Channel))
- return -1;
- if (nvt_mp_parse_array(np, "PS_Config_Lmt_FW_CC_P", PS_Config_Lmt_FW_CC_P,
- X_Channel * Y_Channel + Key_Channel))
- return -1;
- if (nvt_mp_parse_array(np, "PS_Config_Lmt_FW_CC_N", PS_Config_Lmt_FW_CC_N,
- X_Channel * Y_Channel + Key_Channel))
- return -1;
- if (nvt_mp_parse_array(np, "PS_Config_Lmt_FW_Diff_P", PS_Config_Lmt_FW_Diff_P,
- X_Channel * Y_Channel + Key_Channel))
- return -1;
- if (nvt_mp_parse_array(np, "PS_Config_Lmt_FW_Diff_N", PS_Config_Lmt_FW_Diff_N,
- X_Channel * Y_Channel + Key_Channel))
- return -1;
- if (nvt_mp_parse_u32(np, "PS_Config_Diff_Test_Frame", &PS_Config_Diff_Test_Frame))
- return -1;
- NVT_LOG("Parse mp criteria done!\n");
- return 0;
- }
- #endif /* #ifdef CONFIG_OF */
- /*******************************************************
- Description:
- Novatek touchscreen MP function proc. file node
- initial function.
- return:
- Executive outcomes. 0---succeed. -1---failed.
- *******************************************************/
- int32_t nvt_mp_proc_init(void)
- {
- NVT_proc_selftest_entry = proc_create("nvt_selftest", 0444, NULL, &nvt_selftest_fops);
- if (NVT_proc_selftest_entry == NULL) {
- NVT_ERR("create /proc/nvt_selftest Failed!\n");
- return -1;
- } else {
- if(nvt_mp_buffer_init()) {
- NVT_ERR("Allocate mp memory failed\n");
- return -1;
- }
- else {
- NVT_LOG("create /proc/nvt_selftest Succeeded!\n");
- }
- return 0;
- }
- }
- /*******************************************************
- Description:
- Novatek touchscreen MP function proc. file node
- deinitial function.
- return:
- n.a.
- *******************************************************/
- void nvt_mp_proc_deinit(void)
- {
- nvt_mp_buffer_deinit();
- if (NVT_proc_selftest_entry != NULL) {
- remove_proc_entry("nvt_selftest", NULL);
- NVT_proc_selftest_entry = NULL;
- NVT_LOG("Removed /proc/%s\n", "nvt_selftest");
- }
- }
- #endif /* #if NVT_TOUCH_MP */
|