nt36xxx_mp_ctrlram.c 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2010 - 2018 Novatek, Inc.
  4. *
  5. * $Revision: 47247 $
  6. * $Date: 2019-07-10 10:41:36 +0800 (Wed, 10 Jul 2019) $
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  16. * more details.
  17. *
  18. */
  19. #include <linux/proc_fs.h>
  20. #include <linux/seq_file.h>
  21. #include <linux/slab.h>
  22. #include "nt36xxx.h"
  23. #include "nt36xxx_mp_ctrlram.h"
  24. #if NVT_TOUCH_MP
  25. #define NORMAL_MODE 0x00
  26. #define TEST_MODE_1 0x21
  27. #define TEST_MODE_2 0x22
  28. #define MP_MODE_CC 0x41
  29. #define FREQ_HOP_DISABLE 0x66
  30. #define FREQ_HOP_ENABLE 0x65
  31. #define SHORT_TEST_CSV_FILE "/data/local/tmp/ShortTest.csv"
  32. #define OPEN_TEST_CSV_FILE "/data/local/tmp/OpenTest.csv"
  33. #define FW_RAWDATA_CSV_FILE "/data/local/tmp/FWMutualTest.csv"
  34. #define FW_CC_CSV_FILE "/data/local/tmp/FWCCTest.csv"
  35. #define NOISE_TEST_CSV_FILE "/data/local/tmp/NoiseTest.csv"
  36. #define nvt_mp_seq_printf(m, fmt, args...) do { \
  37. seq_printf(m, fmt, ##args); \
  38. if (!nvt_mp_test_result_printed) \
  39. printk(fmt, ##args); \
  40. } while (0)
  41. static uint8_t *RecordResult_Short = NULL;
  42. static uint8_t *RecordResult_Open = NULL;
  43. static uint8_t *RecordResult_FWMutual = NULL;
  44. static uint8_t *RecordResult_FW_CC = NULL;
  45. static uint8_t *RecordResult_FW_DiffMax = NULL;
  46. static uint8_t *RecordResult_FW_DiffMin = NULL;
  47. static int32_t TestResult_Short = 0;
  48. static int32_t TestResult_Open = 0;
  49. static int32_t TestResult_FW_Rawdata = 0;
  50. static int32_t TestResult_FWMutual = 0;
  51. static int32_t TestResult_FW_CC = 0;
  52. static int32_t TestResult_Noise = 0;
  53. static int32_t TestResult_FW_DiffMax = 0;
  54. static int32_t TestResult_FW_DiffMin = 0;
  55. static int32_t *RawData_Short = NULL;
  56. static int32_t *RawData_Open = NULL;
  57. static int32_t *RawData_Diff = NULL;
  58. static int32_t *RawData_Diff_Min = NULL;
  59. static int32_t *RawData_Diff_Max = NULL;
  60. static int32_t *RawData_FWMutual = NULL;
  61. static int32_t *RawData_FW_CC = NULL;
  62. static struct proc_dir_entry *NVT_proc_selftest_entry = NULL;
  63. static int8_t nvt_mp_test_result_printed = 0;
  64. static uint8_t fw_ver = 0;
  65. extern void nvt_change_mode(uint8_t mode);
  66. extern uint8_t nvt_get_fw_pipe(void);
  67. extern void nvt_read_mdata(uint32_t xdata_addr, uint32_t xdata_btn_addr);
  68. extern void nvt_get_mdata(int32_t *buf, uint8_t *m_x_num, uint8_t *m_y_num);
  69. int32_t nvt_mp_parse_dt(struct device_node *root, const char *node_compatible);
  70. /*******************************************************
  71. Description:
  72. Novatek touchscreen allocate buffer for mp selftest.
  73. return:
  74. Executive outcomes. 0---succeed. -12---Out of memory
  75. *******************************************************/
  76. static int nvt_mp_buffer_init(void)
  77. {
  78. size_t RecordResult_BufSize = IC_X_CFG_SIZE * IC_Y_CFG_SIZE + IC_KEY_CFG_SIZE;
  79. size_t RawData_BufSize = (IC_X_CFG_SIZE * IC_Y_CFG_SIZE + IC_KEY_CFG_SIZE) * sizeof(int32_t);
  80. RecordResult_Short = kzalloc(RecordResult_BufSize, GFP_KERNEL);
  81. if (!RecordResult_Short) {
  82. NVT_ERR("kzalloc for RecordResult_Short failed!\n");
  83. return -ENOMEM;
  84. }
  85. RecordResult_Open = kzalloc(RecordResult_BufSize, GFP_KERNEL);
  86. if (!RecordResult_Open) {
  87. NVT_ERR("kzalloc for RecordResult_Open failed!\n");
  88. return -ENOMEM;
  89. }
  90. RecordResult_FWMutual = kzalloc(RecordResult_BufSize, GFP_KERNEL);
  91. if (!RecordResult_FWMutual) {
  92. NVT_ERR("kzalloc for RecordResult_FWMutual failed!\n");
  93. return -ENOMEM;
  94. }
  95. RecordResult_FW_CC = kzalloc(RecordResult_BufSize, GFP_KERNEL);
  96. if (!RecordResult_FW_CC) {
  97. NVT_ERR("kzalloc for RecordResult_FW_CC failed!\n");
  98. return -ENOMEM;
  99. }
  100. RecordResult_FW_DiffMax = kzalloc(RecordResult_BufSize, GFP_KERNEL);
  101. if (!RecordResult_FW_DiffMax) {
  102. NVT_ERR("kzalloc for RecordResult_FW_DiffMax failed!\n");
  103. return -ENOMEM;
  104. }
  105. RecordResult_FW_DiffMin = kzalloc(RecordResult_BufSize, GFP_KERNEL);
  106. if (!RecordResult_FW_DiffMin) {
  107. NVT_ERR("kzalloc for RecordResult_FW_DiffMin failed!\n");
  108. return -ENOMEM;
  109. }
  110. RawData_Short = kzalloc(RawData_BufSize, GFP_KERNEL);
  111. if (!RawData_Short) {
  112. NVT_ERR("kzalloc for RawData_Short failed!\n");
  113. return -ENOMEM;
  114. }
  115. RawData_Open = kzalloc(RawData_BufSize, GFP_KERNEL);
  116. if (!RawData_Open) {
  117. NVT_ERR("kzalloc for RawData_Open failed!\n");
  118. return -ENOMEM;
  119. }
  120. RawData_Diff = kzalloc(RawData_BufSize, GFP_KERNEL);
  121. if (!RawData_Diff) {
  122. NVT_ERR("kzalloc for RawData_Diff failed!\n");
  123. return -ENOMEM;
  124. }
  125. RawData_Diff_Min = kzalloc(RawData_BufSize, GFP_KERNEL);
  126. if (!RawData_Diff_Min) {
  127. NVT_ERR("kzalloc for RawData_Diff_Min failed!\n");
  128. return -ENOMEM;
  129. }
  130. RawData_Diff_Max = kzalloc(RawData_BufSize, GFP_KERNEL);
  131. if (!RawData_Diff_Max) {
  132. NVT_ERR("kzalloc for RawData_Diff_Max failed!\n");
  133. return -ENOMEM;
  134. }
  135. RawData_FWMutual = kzalloc(RawData_BufSize, GFP_KERNEL);
  136. if (!RawData_FWMutual) {
  137. NVT_ERR("kzalloc for RawData_FWMutual failed!\n");
  138. return -ENOMEM;
  139. }
  140. RawData_FW_CC = kzalloc(RawData_BufSize, GFP_KERNEL);
  141. if (!RawData_FW_CC) {
  142. NVT_ERR("kzalloc for RawData_FW_CC failed!\n");
  143. return -ENOMEM;
  144. }
  145. return 0;
  146. }
  147. /*******************************************************
  148. Description:
  149. Novatek touchscreen free buffer for mp selftest.
  150. return:
  151. n.a.
  152. *******************************************************/
  153. static void nvt_mp_buffer_deinit(void)
  154. {
  155. if (RecordResult_Short) {
  156. kfree(RecordResult_Short);
  157. RecordResult_Short = NULL;
  158. }
  159. if (RecordResult_Open) {
  160. kfree(RecordResult_Open);
  161. RecordResult_Open = NULL;
  162. }
  163. if (RecordResult_FWMutual) {
  164. kfree(RecordResult_FWMutual);
  165. RecordResult_FWMutual = NULL;
  166. }
  167. if (RecordResult_FW_CC) {
  168. kfree(RecordResult_FW_CC);
  169. RecordResult_FW_CC = NULL;
  170. }
  171. if (RecordResult_FW_DiffMax) {
  172. kfree(RecordResult_FW_DiffMax);
  173. RecordResult_FW_DiffMax = NULL;
  174. }
  175. if (RecordResult_FW_DiffMin) {
  176. kfree(RecordResult_FW_DiffMin);
  177. RecordResult_FW_DiffMin = NULL;
  178. }
  179. if (RawData_Short) {
  180. kfree(RawData_Short);
  181. RawData_Short = NULL;
  182. }
  183. if (RawData_Open) {
  184. kfree(RawData_Open);
  185. RawData_Open = NULL;
  186. }
  187. if (RawData_Diff) {
  188. kfree(RawData_Diff);
  189. RawData_Diff = NULL;
  190. }
  191. if (RawData_Diff_Min) {
  192. kfree(RawData_Diff_Min);
  193. RawData_Diff_Min = NULL;
  194. }
  195. if (RawData_Diff_Max) {
  196. kfree(RawData_Diff_Max);
  197. RawData_Diff_Max = NULL;
  198. }
  199. if (RawData_FWMutual) {
  200. kfree(RawData_FWMutual);
  201. RawData_FWMutual = NULL;
  202. }
  203. if (RawData_FW_CC) {
  204. kfree(RawData_FW_CC);
  205. RawData_FW_CC = NULL;
  206. }
  207. }
  208. static void nvt_print_data_log_in_one_line(int32_t *data, int32_t data_num)
  209. {
  210. char *tmp_log = NULL;
  211. int32_t i = 0;
  212. int32_t count = data_num * 7 + 1;
  213. tmp_log = kzalloc(count, GFP_KERNEL);
  214. if (!tmp_log) {
  215. NVT_ERR("kzalloc for tmp_log failed!\n ");
  216. return;
  217. }
  218. for (i = 0; i < data_num; i++) {
  219. snprintf(tmp_log + i * 7, count - i * 7, "%5d, ", data[i]);
  220. }
  221. tmp_log[data_num * 7] = '\0';
  222. printk("%s", tmp_log);
  223. if (tmp_log) {
  224. kfree(tmp_log);
  225. tmp_log = NULL;
  226. }
  227. return;
  228. }
  229. static void nvt_print_result_log_in_one_line(uint8_t *result, int32_t result_num)
  230. {
  231. char *tmp_log = NULL;
  232. int32_t i = 0;
  233. int32_t count = 0;
  234. count = result_num * 6 + 1;
  235. tmp_log = kzalloc(count, GFP_KERNEL);
  236. if (!tmp_log) {
  237. NVT_ERR("kzalloc for tmp_log failed!\n ");
  238. return;
  239. }
  240. for (i = 0; i < result_num; i++) {
  241. snprintf(tmp_log + i * 6, count - i * 6, "0x%02X, ", result[i]);
  242. }
  243. tmp_log[result_num * 6] = '\0';
  244. printk("%s", tmp_log);
  245. if (tmp_log) {
  246. kfree(tmp_log);
  247. tmp_log = NULL;
  248. }
  249. return;
  250. }
  251. /*******************************************************
  252. Description:
  253. Novatek touchscreen self-test criteria print function.
  254. return:
  255. n.a.
  256. *******************************************************/
  257. static void nvt_print_lmt_array(int32_t *array, int32_t x_ch, int32_t y_ch)
  258. {
  259. int32_t j = 0;
  260. for (j = 0; j < y_ch; j++) {
  261. nvt_print_data_log_in_one_line(array + j * x_ch, x_ch);
  262. printk("\n");
  263. }
  264. #if TOUCH_KEY_NUM > 0
  265. nvt_print_data_log_in_one_line(array + y_ch * x_ch, Key_Channel);
  266. printk("\n");
  267. #endif /* #if TOUCH_KEY_NUM > 0 */
  268. }
  269. static void nvt_print_criteria(void)
  270. {
  271. NVT_LOG("++\n");
  272. //---PS_Config_Lmt_Short_Rawdata---
  273. printk("PS_Config_Lmt_Short_Rawdata_P:\n");
  274. nvt_print_lmt_array(PS_Config_Lmt_Short_Rawdata_P, X_Channel, Y_Channel);
  275. printk("PS_Config_Lmt_Short_Rawdata_N:\n");
  276. nvt_print_lmt_array(PS_Config_Lmt_Short_Rawdata_N, X_Channel, Y_Channel);
  277. //---PS_Config_Lmt_Open_Rawdata---
  278. printk("PS_Config_Lmt_Open_Rawdata_P:\n");
  279. nvt_print_lmt_array(PS_Config_Lmt_Open_Rawdata_P, X_Channel, Y_Channel);
  280. printk("PS_Config_Lmt_Open_Rawdata_N:\n");
  281. nvt_print_lmt_array(PS_Config_Lmt_Open_Rawdata_N, X_Channel, Y_Channel);
  282. //---PS_Config_Lmt_FW_Rawdata---
  283. printk("PS_Config_Lmt_FW_Rawdata_P:\n");
  284. nvt_print_lmt_array(PS_Config_Lmt_FW_Rawdata_P, X_Channel, Y_Channel);
  285. printk("PS_Config_Lmt_FW_Rawdata_N:\n");
  286. nvt_print_lmt_array(PS_Config_Lmt_FW_Rawdata_N, X_Channel, Y_Channel);
  287. //---PS_Config_Lmt_FW_CC---
  288. printk("PS_Config_Lmt_FW_CC_P:\n");
  289. nvt_print_lmt_array(PS_Config_Lmt_FW_CC_P, X_Channel, Y_Channel);
  290. printk("PS_Config_Lmt_FW_CC_N:\n");
  291. nvt_print_lmt_array(PS_Config_Lmt_FW_CC_N, X_Channel, Y_Channel);
  292. //---PS_Config_Lmt_FW_Diff---
  293. printk("PS_Config_Lmt_FW_Diff_P:\n");
  294. nvt_print_lmt_array(PS_Config_Lmt_FW_Diff_P, X_Channel, Y_Channel);
  295. printk("PS_Config_Lmt_FW_Diff_N:\n");
  296. nvt_print_lmt_array(PS_Config_Lmt_FW_Diff_N, X_Channel, Y_Channel);
  297. NVT_LOG("--\n");
  298. }
  299. static int32_t nvt_polling_hand_shake_status(void)
  300. {
  301. uint8_t buf[8] = {0};
  302. int32_t i = 0;
  303. const int32_t retry = 70;
  304. for (i = 0; i < retry; i++) {
  305. //---set xdata index to EVENT BUF ADDR---
  306. nvt_set_page(I2C_FW_Address, ts->mmap->EVENT_BUF_ADDR | EVENT_MAP_HANDSHAKING_or_SUB_CMD_BYTE);
  307. //---read fw status---
  308. buf[0] = EVENT_MAP_HANDSHAKING_or_SUB_CMD_BYTE;
  309. buf[1] = 0x00;
  310. CTP_I2C_READ(ts->client, I2C_FW_Address, buf, 2);
  311. if ((buf[1] == 0xA0) || (buf[1] == 0xA1))
  312. break;
  313. usleep_range(10000, 10000);
  314. }
  315. if (i >= retry) {
  316. NVT_ERR("polling hand shake status failed, buf[1]=0x%02X\n", buf[1]);
  317. // Read back 5 bytes from offset EVENT_MAP_HOST_CMD for debug check
  318. nvt_set_page(I2C_FW_Address, ts->mmap->EVENT_BUF_ADDR | EVENT_MAP_HOST_CMD);
  319. buf[0] = EVENT_MAP_HOST_CMD;
  320. buf[1] = 0x00;
  321. buf[2] = 0x00;
  322. buf[3] = 0x00;
  323. buf[4] = 0x00;
  324. buf[5] = 0x00;
  325. CTP_I2C_READ(ts->client, I2C_FW_Address, buf, 6);
  326. 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]);
  327. return -1;
  328. } else {
  329. return 0;
  330. }
  331. }
  332. static int8_t nvt_switch_FreqHopEnDis(uint8_t FreqHopEnDis)
  333. {
  334. uint8_t buf[8] = {0};
  335. uint8_t retry = 0;
  336. int8_t ret = 0;
  337. NVT_LOG("++\n");
  338. for (retry = 0; retry < 20; retry++) {
  339. //---set xdata index to EVENT BUF ADDR---
  340. nvt_set_page(I2C_FW_Address, ts->mmap->EVENT_BUF_ADDR | EVENT_MAP_HOST_CMD);
  341. //---switch FreqHopEnDis---
  342. buf[0] = EVENT_MAP_HOST_CMD;
  343. buf[1] = FreqHopEnDis;
  344. CTP_I2C_WRITE(ts->client, I2C_FW_Address, buf, 2);
  345. msleep(35);
  346. buf[0] = EVENT_MAP_HOST_CMD;
  347. buf[1] = 0xFF;
  348. CTP_I2C_READ(ts->client, I2C_FW_Address, buf, 2);
  349. if (buf[1] == 0x00)
  350. break;
  351. }
  352. if (unlikely(retry == 20)) {
  353. NVT_ERR("switch FreqHopEnDis 0x%02X failed, buf[1]=0x%02X\n", FreqHopEnDis, buf[1]);
  354. ret = -1;
  355. }
  356. NVT_LOG("--\n");
  357. return ret;
  358. }
  359. static int32_t nvt_read_baseline(int32_t *xdata)
  360. {
  361. uint8_t x_num = 0;
  362. uint8_t y_num = 0;
  363. uint32_t x = 0;
  364. uint32_t y = 0;
  365. int32_t iArrayIndex = 0;
  366. #if TOUCH_KEY_NUM > 0
  367. int32_t k = 0;
  368. #endif /* #if TOUCH_KEY_NUM > 0 */
  369. NVT_LOG("++\n");
  370. nvt_read_mdata(ts->mmap->BASELINE_ADDR, ts->mmap->BASELINE_BTN_ADDR);
  371. nvt_get_mdata(xdata, &x_num, &y_num);
  372. for (y = 0; y < y_num; y++) {
  373. for (x = 0; x < x_num; x++) {
  374. iArrayIndex = y * x_num + x;
  375. xdata[iArrayIndex] = (int16_t)xdata[iArrayIndex];
  376. }
  377. }
  378. #if TOUCH_KEY_NUM > 0
  379. for (k = 0; k < Key_Channel; k++) {
  380. iArrayIndex = Y_Channel * X_Channel + k;
  381. xdata[iArrayIndex] = (int16_t)xdata[iArrayIndex];
  382. }
  383. #endif /* #if TOUCH_KEY_NUM > 0 */
  384. NVT_LOG("--\n");
  385. return 0;
  386. }
  387. static int32_t nvt_read_CC(int32_t *xdata)
  388. {
  389. uint8_t x_num = 0;
  390. uint8_t y_num = 0;
  391. uint32_t x = 0;
  392. uint32_t y = 0;
  393. int32_t iArrayIndex = 0;
  394. #if TOUCH_KEY_NUM > 0
  395. int32_t k = 0;
  396. #endif /* #if TOUCH_KEY_NUM > 0 */
  397. NVT_LOG("++\n");
  398. if (nvt_get_fw_pipe() == 0)
  399. nvt_read_mdata(ts->mmap->DIFF_PIPE1_ADDR, ts->mmap->DIFF_BTN_PIPE1_ADDR);
  400. else
  401. nvt_read_mdata(ts->mmap->DIFF_PIPE0_ADDR, ts->mmap->DIFF_BTN_PIPE0_ADDR);
  402. nvt_get_mdata(xdata, &x_num, &y_num);
  403. for (y = 0; y < y_num; y++) {
  404. for (x = 0; x < x_num; x++) {
  405. iArrayIndex = y * x_num + x;
  406. xdata[iArrayIndex] = (int16_t)xdata[iArrayIndex];
  407. }
  408. }
  409. #if TOUCH_KEY_NUM > 0
  410. for (k = 0; k < Key_Channel; k++) {
  411. iArrayIndex = Y_Channel * X_Channel + k;
  412. xdata[iArrayIndex] = (int16_t)xdata[iArrayIndex];
  413. }
  414. #endif /* #if TOUCH_KEY_NUM > 0 */
  415. NVT_LOG("--\n");
  416. return 0;
  417. }
  418. static void nvt_enable_noise_collect(int32_t frame_num)
  419. {
  420. uint8_t buf[8] = {0};
  421. //---set xdata index to EVENT BUF ADDR---
  422. nvt_set_page(I2C_FW_Address, ts->mmap->EVENT_BUF_ADDR | EVENT_MAP_HOST_CMD);
  423. //---enable noise collect---
  424. buf[0] = EVENT_MAP_HOST_CMD;
  425. buf[1] = 0x47;
  426. buf[2] = 0xAA;
  427. buf[3] = frame_num;
  428. buf[4] = 0x00;
  429. CTP_I2C_WRITE(ts->client, I2C_FW_Address, buf, 5);
  430. }
  431. static int32_t nvt_read_fw_noise(int32_t *xdata)
  432. {
  433. uint8_t x_num = 0;
  434. uint8_t y_num = 0;
  435. uint32_t x = 0;
  436. uint32_t y = 0;
  437. int32_t iArrayIndex = 0;
  438. int32_t frame_num = 0;
  439. #if TOUCH_KEY_NUM > 0
  440. int32_t k = 0;
  441. #endif /* #if TOUCH_KEY_NUM > 0 */
  442. NVT_LOG("++\n");
  443. //---Enter Test Mode---
  444. if (nvt_clear_fw_status()) {
  445. return -EAGAIN;
  446. }
  447. frame_num = PS_Config_Diff_Test_Frame / 10;
  448. if (frame_num <= 0)
  449. frame_num = 1;
  450. printk("%s: frame_num=%d\n", __func__, frame_num);
  451. nvt_enable_noise_collect(frame_num);
  452. // need wait PS_Config_Diff_Test_Frame * 8.3ms
  453. msleep(frame_num * 83);
  454. if (nvt_polling_hand_shake_status()) {
  455. return -EAGAIN;
  456. }
  457. if (nvt_get_fw_info()) {
  458. return -EAGAIN;
  459. }
  460. if (nvt_get_fw_pipe() == 0)
  461. nvt_read_mdata(ts->mmap->DIFF_PIPE0_ADDR, ts->mmap->DIFF_BTN_PIPE0_ADDR);
  462. else
  463. nvt_read_mdata(ts->mmap->DIFF_PIPE1_ADDR, ts->mmap->DIFF_BTN_PIPE1_ADDR);
  464. nvt_get_mdata(xdata, &x_num, &y_num);
  465. for (y = 0; y < y_num; y++) {
  466. for (x = 0; x < x_num; x++) {
  467. iArrayIndex = y * x_num + x;
  468. RawData_Diff_Max[iArrayIndex] = (int8_t)((xdata[iArrayIndex] >> 8) & 0xFF);
  469. RawData_Diff_Min[iArrayIndex] = (int8_t)(xdata[iArrayIndex] & 0xFF);
  470. }
  471. }
  472. #if TOUCH_KEY_NUM > 0
  473. for (k = 0; k < Key_Channel; k++) {
  474. iArrayIndex = Y_Channel * X_Channel + k;
  475. RawData_Diff_Max[iArrayIndex] = (int8_t)((xdata[iArrayIndex] >> 8) & 0xFF);
  476. RawData_Diff_Min[iArrayIndex] = (int8_t)(xdata[iArrayIndex] & 0xFF);
  477. }
  478. #endif /* #if TOUCH_KEY_NUM > 0 */
  479. //---Leave Test Mode---
  480. nvt_change_mode(NORMAL_MODE);
  481. NVT_LOG("--\n");
  482. return 0;
  483. }
  484. static void nvt_enable_open_test(void)
  485. {
  486. uint8_t buf[8] = {0};
  487. //---set xdata index to EVENT BUF ADDR---
  488. nvt_set_page(I2C_FW_Address, ts->mmap->EVENT_BUF_ADDR | EVENT_MAP_HOST_CMD);
  489. //---enable open test---
  490. buf[0] = EVENT_MAP_HOST_CMD;
  491. buf[1] = 0x45;
  492. buf[2] = 0xAA;
  493. buf[3] = 0x02;
  494. buf[4] = 0x00;
  495. CTP_I2C_WRITE(ts->client, I2C_FW_Address, buf, 5);
  496. }
  497. static void nvt_enable_short_test(void)
  498. {
  499. uint8_t buf[8] = {0};
  500. //---set xdata index to EVENT BUF ADDR---
  501. nvt_set_page(I2C_FW_Address, ts->mmap->EVENT_BUF_ADDR | EVENT_MAP_HOST_CMD);
  502. //---enable short test---
  503. buf[0] = EVENT_MAP_HOST_CMD;
  504. buf[1] = 0x43;
  505. buf[2] = 0xAA;
  506. buf[3] = 0x02;
  507. buf[4] = 0x00;
  508. CTP_I2C_WRITE(ts->client, I2C_FW_Address, buf, 5);
  509. }
  510. static int32_t nvt_read_fw_open(int32_t *xdata)
  511. {
  512. uint32_t raw_pipe_addr = 0;
  513. uint8_t *rawdata_buf = NULL;
  514. uint32_t x = 0;
  515. uint32_t y = 0;
  516. uint8_t buf[128] = {0};
  517. #if TOUCH_KEY_NUM > 0
  518. uint32_t raw_btn_pipe_addr = 0;
  519. int32_t k = 0;
  520. #endif /* #if TOUCH_KEY_NUM > 0 */
  521. NVT_LOG("++\n");
  522. //---Enter Test Mode---
  523. if (nvt_clear_fw_status()) {
  524. return -EAGAIN;
  525. }
  526. nvt_enable_open_test();
  527. if (nvt_polling_hand_shake_status()) {
  528. return -EAGAIN;
  529. }
  530. #if TOUCH_KEY_NUM > 0
  531. rawdata_buf = kzalloc((IC_X_CFG_SIZE * IC_Y_CFG_SIZE + IC_KEY_CFG_SIZE) * 2, GFP_KERNEL);
  532. #else
  533. rawdata_buf = kzalloc(IC_X_CFG_SIZE * IC_Y_CFG_SIZE * 2, GFP_KERNEL);
  534. #endif /* #if TOUCH_KEY_NUM > 0 */
  535. if (!rawdata_buf) {
  536. NVT_ERR("kzalloc for rawdata_buf failed!\n");
  537. return -ENOMEM;
  538. }
  539. if (nvt_get_fw_pipe() == 0)
  540. raw_pipe_addr = ts->mmap->RAW_PIPE0_ADDR;
  541. else
  542. raw_pipe_addr = ts->mmap->RAW_PIPE1_ADDR;
  543. for (y = 0; y < IC_Y_CFG_SIZE; y++) {
  544. //---change xdata index---
  545. nvt_set_page(I2C_FW_Address, raw_pipe_addr + y * IC_X_CFG_SIZE * 2);
  546. buf[0] = (uint8_t)((raw_pipe_addr + y * IC_X_CFG_SIZE * 2) & 0xFF);
  547. CTP_I2C_READ(ts->client, I2C_FW_Address, buf, IC_X_CFG_SIZE * 2 + 1);
  548. memcpy(rawdata_buf + y * IC_X_CFG_SIZE * 2, buf + 1, IC_X_CFG_SIZE * 2);
  549. }
  550. #if TOUCH_KEY_NUM > 0
  551. if (nvt_get_fw_pipe() == 0)
  552. raw_btn_pipe_addr = ts->mmap->RAW_BTN_PIPE0_ADDR;
  553. else
  554. raw_btn_pipe_addr = ts->mmap->RAW_BTN_PIPE1_ADDR;
  555. //---change xdata index---
  556. nvt_set_page(I2C_FW_Address, raw_btn_pipe_addr);
  557. buf[0] = (uint8_t)(raw_btn_pipe_addr & 0xFF);
  558. CTP_I2C_READ(ts->client, I2C_FW_Address, buf, IC_KEY_CFG_SIZE * 2 + 1);
  559. memcpy(rawdata_buf + IC_Y_CFG_SIZE * IC_X_CFG_SIZE * 2, buf + 1, IC_KEY_CFG_SIZE * 2);
  560. #endif /* #if TOUCH_KEY_NUM > 0 */
  561. for (y = 0; y < IC_Y_CFG_SIZE; y++) {
  562. for (x = 0; x < IC_X_CFG_SIZE; x++) {
  563. if ((AIN_Y[y] != 0xFF) && (AIN_X[x] != 0xFF)) {
  564. 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]));
  565. }
  566. }
  567. }
  568. #if TOUCH_KEY_NUM > 0
  569. for (k = 0; k < IC_KEY_CFG_SIZE; k++) {
  570. if (AIN_KEY[k] != 0xFF)
  571. 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]);
  572. }
  573. #endif /* #if TOUCH_KEY_NUM > 0 */
  574. if (rawdata_buf) {
  575. kfree(rawdata_buf);
  576. rawdata_buf = NULL;
  577. }
  578. //---Leave Test Mode---
  579. nvt_change_mode(NORMAL_MODE);
  580. NVT_LOG("--\n");
  581. return 0;
  582. }
  583. static int32_t nvt_read_fw_short(int32_t *xdata)
  584. {
  585. uint32_t raw_pipe_addr = 0;
  586. uint8_t *rawdata_buf = NULL;
  587. uint32_t x = 0;
  588. uint32_t y = 0;
  589. uint8_t buf[128] = {0};
  590. int32_t iArrayIndex = 0;
  591. #if TOUCH_KEY_NUM > 0
  592. uint32_t raw_btn_pipe_addr = 0;
  593. int32_t k = 0;
  594. #endif /* #if TOUCH_KEY_NUM > 0 */
  595. NVT_LOG("++\n");
  596. //---Enter Test Mode---
  597. if (nvt_clear_fw_status()) {
  598. return -EAGAIN;
  599. }
  600. nvt_enable_short_test();
  601. if (nvt_polling_hand_shake_status()) {
  602. return -EAGAIN;
  603. }
  604. #if TOUCH_KEY_NUM > 0
  605. rawdata_buf = kzalloc((X_Channel * Y_Channel + Key_Channel) * 2, GFP_KERNEL);
  606. #else
  607. rawdata_buf = kzalloc(X_Channel * Y_Channel * 2, GFP_KERNEL);
  608. #endif /* #if TOUCH_KEY_NUM > 0 */
  609. if (!rawdata_buf) {
  610. NVT_ERR("kzalloc for rawdata_buf failed!\n");
  611. return -ENOMEM;
  612. }
  613. if (nvt_get_fw_pipe() == 0)
  614. raw_pipe_addr = ts->mmap->RAW_PIPE0_ADDR;
  615. else
  616. raw_pipe_addr = ts->mmap->RAW_PIPE1_ADDR;
  617. for (y = 0; y < Y_Channel; y++) {
  618. //---change xdata index---
  619. nvt_set_page(I2C_FW_Address, raw_pipe_addr + y * X_Channel * 2);
  620. buf[0] = (uint8_t)((raw_pipe_addr + y * X_Channel * 2) & 0xFF);
  621. CTP_I2C_READ(ts->client, I2C_FW_Address, buf, X_Channel * 2 + 1);
  622. memcpy(rawdata_buf + y * X_Channel * 2, buf + 1, X_Channel * 2);
  623. }
  624. #if TOUCH_KEY_NUM > 0
  625. if (nvt_get_fw_pipe() == 0)
  626. raw_btn_pipe_addr = ts->mmap->RAW_BTN_PIPE0_ADDR;
  627. else
  628. raw_btn_pipe_addr = ts->mmap->RAW_BTN_PIPE1_ADDR;
  629. //---change xdata index---
  630. nvt_set_page(I2C_FW_Address, raw_btn_pipe_addr);
  631. buf[0] = (uint8_t)(raw_btn_pipe_addr & 0xFF);
  632. CTP_I2C_READ(ts->client, I2C_FW_Address, buf, Key_Channel * 2 + 1);
  633. memcpy(rawdata_buf + Y_Channel * X_Channel * 2, buf + 1, Key_Channel * 2);
  634. #endif /* #if TOUCH_KEY_NUM > 0 */
  635. for (y = 0; y < Y_Channel; y++) {
  636. for (x = 0; x < X_Channel; x++) {
  637. iArrayIndex = y * X_Channel + x;
  638. xdata[iArrayIndex] = (int16_t)(rawdata_buf[iArrayIndex * 2] + 256 * rawdata_buf[iArrayIndex * 2 + 1]);
  639. }
  640. }
  641. #if TOUCH_KEY_NUM > 0
  642. for (k = 0; k < Key_Channel; k++) {
  643. iArrayIndex = Y_Channel * X_Channel + k;
  644. xdata[iArrayIndex] = (int16_t)(rawdata_buf[iArrayIndex * 2] + 256 * rawdata_buf[iArrayIndex * 2 + 1]);
  645. }
  646. #endif /* #if TOUCH_KEY_NUM > 0 */
  647. if (rawdata_buf) {
  648. kfree(rawdata_buf);
  649. rawdata_buf = NULL;
  650. }
  651. //---Leave Test Mode---
  652. nvt_change_mode(NORMAL_MODE);
  653. NVT_LOG("--\n");
  654. return 0;
  655. }
  656. /*******************************************************
  657. Description:
  658. Novatek touchscreen raw data test for each single point function.
  659. return:
  660. Executive outcomes. 0---passed. negative---failed.
  661. *******************************************************/
  662. 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[])
  663. {
  664. int32_t i = 0;
  665. int32_t j = 0;
  666. #if TOUCH_KEY_NUM > 0
  667. int32_t k = 0;
  668. #endif /* #if TOUCH_KEY_NUM > 0 */
  669. int32_t iArrayIndex = 0;
  670. bool isPass = true;
  671. for (j = 0; j < y_ch; j++) {
  672. for (i = 0; i < x_ch; i++) {
  673. iArrayIndex = j * x_ch + i;
  674. RecordResult[iArrayIndex] = 0x00; // default value for PASS
  675. if(rawdata[iArrayIndex] > Rawdata_Limit_Postive[iArrayIndex])
  676. RecordResult[iArrayIndex] |= 0x01;
  677. if(rawdata[iArrayIndex] < Rawdata_Limit_Negative[iArrayIndex])
  678. RecordResult[iArrayIndex] |= 0x02;
  679. }
  680. }
  681. #if TOUCH_KEY_NUM > 0
  682. for (k = 0; k < Key_Channel; k++) {
  683. iArrayIndex = y_ch * x_ch + k;
  684. RecordResult[iArrayIndex] = 0x00; // default value for PASS
  685. if(rawdata[iArrayIndex] > Rawdata_Limit_Postive[iArrayIndex])
  686. RecordResult[iArrayIndex] |= 0x01;
  687. if(rawdata[iArrayIndex] < Rawdata_Limit_Negative[iArrayIndex])
  688. RecordResult[iArrayIndex] |= 0x02;
  689. }
  690. #endif /* #if TOUCH_KEY_NUM > 0 */
  691. //---Check RecordResult---
  692. for (j = 0; j < y_ch; j++) {
  693. for (i = 0; i < x_ch; i++) {
  694. if (RecordResult[j * x_ch + i] != 0) {
  695. isPass = false;
  696. break;
  697. }
  698. }
  699. }
  700. #if TOUCH_KEY_NUM > 0
  701. for (k = 0; k < Key_Channel; k++) {
  702. iArrayIndex = y_ch * x_ch + k;
  703. if (RecordResult[iArrayIndex] != 0) {
  704. isPass = false;
  705. break;
  706. }
  707. }
  708. #endif /* #if TOUCH_KEY_NUM > 0 */
  709. if (!isPass) {
  710. return -1; // FAIL
  711. } else {
  712. return 0; // PASS
  713. }
  714. }
  715. /*******************************************************
  716. Description:
  717. Novatek touchscreen print self-test result function.
  718. return:
  719. n.a.
  720. *******************************************************/
  721. 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)
  722. {
  723. int32_t i = 0;
  724. int32_t j = 0;
  725. int32_t iArrayIndex = 0;
  726. #if TOUCH_KEY_NUM > 0
  727. int32_t k = 0;
  728. #endif /* #if TOUCH_KEY_NUM > 0 */
  729. switch (TestResult) {
  730. case 0:
  731. nvt_mp_seq_printf(m, " PASS!\n");
  732. break;
  733. case 1:
  734. nvt_mp_seq_printf(m, " ERROR! Read Data FAIL!\n");
  735. break;
  736. case -1:
  737. nvt_mp_seq_printf(m, " FAIL!\n");
  738. nvt_mp_seq_printf(m, "RecordResult:\n");
  739. for (i = 0; i < y_len; i++) {
  740. for (j = 0; j < x_len; j++) {
  741. iArrayIndex = i * x_len + j;
  742. seq_printf(m, "0x%02X, ", RecordResult[iArrayIndex]);
  743. }
  744. if (!nvt_mp_test_result_printed)
  745. nvt_print_result_log_in_one_line(RecordResult + i * x_len, x_len);
  746. nvt_mp_seq_printf(m, "\n");
  747. }
  748. #if TOUCH_KEY_NUM > 0
  749. for (k = 0; k < Key_Channel; k++) {
  750. iArrayIndex = y_len * x_len + k;
  751. seq_printf(m, "0x%02X, ", RecordResult[iArrayIndex]);
  752. }
  753. if (!nvt_mp_test_result_printed)
  754. nvt_print_result_log_in_one_line(RecordResult + y_len * x_len, Key_Channel);
  755. nvt_mp_seq_printf(m, "\n");
  756. #endif /* #if TOUCH_KEY_NUM > 0 */
  757. nvt_mp_seq_printf(m, "ReadData:\n");
  758. for (i = 0; i < y_len; i++) {
  759. for (j = 0; j < x_len; j++) {
  760. iArrayIndex = i * x_len + j;
  761. seq_printf(m, "%5d, ", rawdata[iArrayIndex]);
  762. }
  763. if (!nvt_mp_test_result_printed)
  764. nvt_print_data_log_in_one_line(rawdata + i * x_len, x_len);
  765. nvt_mp_seq_printf(m, "\n");
  766. }
  767. #if TOUCH_KEY_NUM > 0
  768. for (k = 0; k < Key_Channel; k++) {
  769. iArrayIndex = y_len * x_len + k;
  770. seq_printf(m, "%5d, ", rawdata[iArrayIndex]);
  771. }
  772. if (!nvt_mp_test_result_printed)
  773. nvt_print_data_log_in_one_line(rawdata + y_len * x_len, Key_Channel);
  774. nvt_mp_seq_printf(m, "\n");
  775. #endif /* #if TOUCH_KEY_NUM > 0 */
  776. break;
  777. }
  778. nvt_mp_seq_printf(m, "\n");
  779. }
  780. /*******************************************************
  781. Description:
  782. Novatek touchscreen self-test sequence print show
  783. function.
  784. return:
  785. Executive outcomes. 0---succeed.
  786. *******************************************************/
  787. static int32_t c_show_selftest(struct seq_file *m, void *v)
  788. {
  789. NVT_LOG("++\n");
  790. nvt_mp_seq_printf(m, "FW Version: %d\n\n", fw_ver);
  791. nvt_mp_seq_printf(m, "Short Test");
  792. print_selftest_result(m, TestResult_Short, RecordResult_Short, RawData_Short, X_Channel, Y_Channel);
  793. nvt_mp_seq_printf(m, "Open Test");
  794. print_selftest_result(m, TestResult_Open, RecordResult_Open, RawData_Open, X_Channel, Y_Channel);
  795. nvt_mp_seq_printf(m, "FW Rawdata Test");
  796. if ((TestResult_FW_Rawdata == 0) || (TestResult_FW_Rawdata == 1)) {
  797. print_selftest_result(m, TestResult_FWMutual, RecordResult_FWMutual, RawData_FWMutual, X_Channel, Y_Channel);
  798. } else { // TestResult_FW_Rawdata is -1
  799. nvt_mp_seq_printf(m, " FAIL!\n");
  800. if (TestResult_FWMutual == -1) {
  801. nvt_mp_seq_printf(m, "FW Mutual");
  802. print_selftest_result(m, TestResult_FWMutual, RecordResult_FWMutual, RawData_FWMutual, X_Channel, Y_Channel);
  803. }
  804. if (TestResult_FW_CC == -1) {
  805. nvt_mp_seq_printf(m, "FW CC");
  806. print_selftest_result(m, TestResult_FW_CC, RecordResult_FW_CC, RawData_FW_CC, X_Channel, Y_Channel);
  807. }
  808. }
  809. nvt_mp_seq_printf(m, "Noise Test");
  810. if ((TestResult_Noise == 0) || (TestResult_Noise == 1)) {
  811. print_selftest_result(m, TestResult_FW_DiffMax, RecordResult_FW_DiffMax, RawData_Diff_Max, X_Channel, Y_Channel);
  812. } else { // TestResult_Noise is -1
  813. nvt_mp_seq_printf(m, " FAIL!\n");
  814. if (TestResult_FW_DiffMax == -1) {
  815. nvt_mp_seq_printf(m, "FW Diff Max");
  816. print_selftest_result(m, TestResult_FW_DiffMax, RecordResult_FW_DiffMax, RawData_Diff_Max, X_Channel, Y_Channel);
  817. }
  818. if (TestResult_FW_DiffMin == -1) {
  819. nvt_mp_seq_printf(m, "FW Diff Min");
  820. print_selftest_result(m, TestResult_FW_DiffMin, RecordResult_FW_DiffMin, RawData_Diff_Min, X_Channel, Y_Channel);
  821. }
  822. }
  823. nvt_mp_test_result_printed = 1;
  824. NVT_LOG("--\n");
  825. return 0;
  826. }
  827. /*******************************************************
  828. Description:
  829. Novatek touchscreen self-test sequence print start
  830. function.
  831. return:
  832. Executive outcomes. 1---call next function.
  833. NULL---not call next function and sequence loop
  834. stop.
  835. *******************************************************/
  836. static void *c_start(struct seq_file *m, loff_t *pos)
  837. {
  838. return *pos < 1 ? (void *)1 : NULL;
  839. }
  840. /*******************************************************
  841. Description:
  842. Novatek touchscreen self-test sequence print next
  843. function.
  844. return:
  845. Executive outcomes. NULL---no next and call sequence
  846. stop function.
  847. *******************************************************/
  848. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  849. {
  850. ++*pos;
  851. return NULL;
  852. }
  853. /*******************************************************
  854. Description:
  855. Novatek touchscreen self-test sequence print stop
  856. function.
  857. return:
  858. n.a.
  859. *******************************************************/
  860. static void c_stop(struct seq_file *m, void *v)
  861. {
  862. return;
  863. }
  864. const struct seq_operations nvt_selftest_seq_ops = {
  865. .start = c_start,
  866. .next = c_next,
  867. .stop = c_stop,
  868. .show = c_show_selftest
  869. };
  870. /*******************************************************
  871. Description:
  872. Novatek touchscreen /proc/nvt_selftest open function.
  873. return:
  874. Executive outcomes. 0---succeed. negative---failed.
  875. *******************************************************/
  876. static int32_t nvt_selftest_open(struct inode *inode, struct file *file)
  877. {
  878. struct device_node *np = ts->client->dev.of_node;
  879. unsigned char mpcriteria[PAGE_SIZE] = {0}; //novatek-mp-criteria-default
  880. TestResult_Short = 0;
  881. TestResult_Open = 0;
  882. TestResult_FW_Rawdata = 0;
  883. TestResult_FWMutual = 0;
  884. TestResult_FW_CC = 0;
  885. TestResult_Noise = 0;
  886. TestResult_FW_DiffMax = 0;
  887. TestResult_FW_DiffMin = 0;
  888. NVT_LOG("++\n");
  889. if (mutex_lock_interruptible(&ts->lock)) {
  890. return -ERESTARTSYS;
  891. }
  892. #if NVT_TOUCH_ESD_PROTECT
  893. nvt_esd_check_enable(false);
  894. #endif /* #if NVT_TOUCH_ESD_PROTECT */
  895. if (nvt_get_fw_info()) {
  896. mutex_unlock(&ts->lock);
  897. NVT_ERR("get fw info failed!\n");
  898. return -EAGAIN;
  899. }
  900. fw_ver = ts->fw_ver;
  901. /* Parsing criteria from dts */
  902. if(of_property_read_bool(np, "novatek,mp-support-dt")) {
  903. /*
  904. * Parsing Criteria by Novatek PID
  905. * The string rule is "novatek-mp-criteria-<nvt_pid>"
  906. * nvt_pid is 2 bytes (show hex).
  907. *
  908. * Ex. nvt_pid = 500A
  909. * mpcriteria = "novatek-mp-criteria-500A"
  910. */
  911. snprintf(mpcriteria, PAGE_SIZE, "novatek-mp-criteria-%04X", ts->nvt_pid);
  912. if (nvt_mp_parse_dt(np, mpcriteria)) {
  913. mutex_unlock(&ts->lock);
  914. NVT_ERR("mp parse device tree failed!\n");
  915. return -EINVAL;
  916. }
  917. } else {
  918. NVT_LOG("Not found novatek,mp-support-dt, use default setting\n");
  919. //---Print Test Criteria---
  920. nvt_print_criteria();
  921. }
  922. if (nvt_switch_FreqHopEnDis(FREQ_HOP_DISABLE)) {
  923. mutex_unlock(&ts->lock);
  924. NVT_ERR("switch frequency hopping disable failed!\n");
  925. return -EAGAIN;
  926. }
  927. if (nvt_check_fw_reset_state(RESET_STATE_NORMAL_RUN)) {
  928. mutex_unlock(&ts->lock);
  929. NVT_ERR("check fw reset state failed!\n");
  930. return -EAGAIN;
  931. }
  932. msleep(100);
  933. //---Enter Test Mode---
  934. if (nvt_clear_fw_status()) {
  935. mutex_unlock(&ts->lock);
  936. NVT_ERR("clear fw status failed!\n");
  937. return -EAGAIN;
  938. }
  939. nvt_change_mode(MP_MODE_CC);
  940. if (nvt_check_fw_status()) {
  941. mutex_unlock(&ts->lock);
  942. NVT_ERR("check fw status failed!\n");
  943. return -EAGAIN;
  944. }
  945. //---FW Rawdata Test---
  946. if (nvt_read_baseline(RawData_FWMutual) != 0) {
  947. TestResult_FWMutual = 1;
  948. } else {
  949. TestResult_FWMutual = RawDataTest_SinglePoint_Sub(RawData_FWMutual, RecordResult_FWMutual, X_Channel, Y_Channel,
  950. PS_Config_Lmt_FW_Rawdata_P, PS_Config_Lmt_FW_Rawdata_N);
  951. }
  952. if (nvt_read_CC(RawData_FW_CC) != 0) {
  953. TestResult_FW_CC = 1;
  954. } else {
  955. TestResult_FW_CC = RawDataTest_SinglePoint_Sub(RawData_FW_CC, RecordResult_FW_CC, X_Channel, Y_Channel,
  956. PS_Config_Lmt_FW_CC_P, PS_Config_Lmt_FW_CC_N);
  957. }
  958. if ((TestResult_FWMutual == 1) || (TestResult_FW_CC == 1)) {
  959. TestResult_FW_Rawdata = 1;
  960. } else {
  961. if ((TestResult_FWMutual == -1) || (TestResult_FW_CC == -1))
  962. TestResult_FW_Rawdata = -1;
  963. else
  964. TestResult_FW_Rawdata = 0;
  965. }
  966. //---Leave Test Mode---
  967. nvt_change_mode(NORMAL_MODE);
  968. //---Noise Test---
  969. if (nvt_read_fw_noise(RawData_Diff) != 0) {
  970. TestResult_Noise = 1; // 1: ERROR
  971. TestResult_FW_DiffMax = 1;
  972. TestResult_FW_DiffMin = 1;
  973. } else {
  974. TestResult_FW_DiffMax = RawDataTest_SinglePoint_Sub(RawData_Diff_Max, RecordResult_FW_DiffMax, X_Channel, Y_Channel,
  975. PS_Config_Lmt_FW_Diff_P, PS_Config_Lmt_FW_Diff_N);
  976. TestResult_FW_DiffMin = RawDataTest_SinglePoint_Sub(RawData_Diff_Min, RecordResult_FW_DiffMin, X_Channel, Y_Channel,
  977. PS_Config_Lmt_FW_Diff_P, PS_Config_Lmt_FW_Diff_N);
  978. if ((TestResult_FW_DiffMax == -1) || (TestResult_FW_DiffMin == -1))
  979. TestResult_Noise = -1;
  980. else
  981. TestResult_Noise = 0;
  982. }
  983. //--Short Test---
  984. if (nvt_read_fw_short(RawData_Short) != 0) {
  985. TestResult_Short = 1; // 1:ERROR
  986. } else {
  987. //---Self Test Check --- // 0:PASS, -1:FAIL
  988. TestResult_Short = RawDataTest_SinglePoint_Sub(RawData_Short, RecordResult_Short, X_Channel, Y_Channel,
  989. PS_Config_Lmt_Short_Rawdata_P, PS_Config_Lmt_Short_Rawdata_N);
  990. }
  991. //---Open Test---
  992. if (nvt_read_fw_open(RawData_Open) != 0) {
  993. TestResult_Open = 1; // 1:ERROR
  994. } else {
  995. //---Self Test Check --- // 0:PASS, -1:FAIL
  996. TestResult_Open = RawDataTest_SinglePoint_Sub(RawData_Open, RecordResult_Open, X_Channel, Y_Channel,
  997. PS_Config_Lmt_Open_Rawdata_P, PS_Config_Lmt_Open_Rawdata_N);
  998. }
  999. //---Reset IC---
  1000. nvt_bootloader_reset();
  1001. mutex_unlock(&ts->lock);
  1002. NVT_LOG("--\n");
  1003. nvt_mp_test_result_printed = 0;
  1004. return seq_open(file, &nvt_selftest_seq_ops);
  1005. }
  1006. static const struct proc_ops nvt_selftest_fops = {
  1007. .proc_open = nvt_selftest_open,
  1008. .proc_read = seq_read,
  1009. .proc_lseek = seq_lseek,
  1010. .proc_release = seq_release,
  1011. };
  1012. #ifdef CONFIG_OF
  1013. /*******************************************************
  1014. Description:
  1015. Novatek touchscreen parse AIN setting for array type.
  1016. return:
  1017. n.a.
  1018. *******************************************************/
  1019. int32_t nvt_mp_parse_ain(struct device_node *np, const char *name, uint8_t *array, int32_t size)
  1020. {
  1021. struct property *data;
  1022. int32_t len, ret;
  1023. int32_t tmp[40];
  1024. int32_t i;
  1025. data = of_find_property(np, name, &len);
  1026. len /= sizeof(u32);
  1027. if ((!data) || (!len) || (len != size)) {
  1028. NVT_ERR("error find %s. len=%d\n", name, len);
  1029. return -1;
  1030. } else {
  1031. NVT_LOG("%s. len=%d\n", name, len);
  1032. ret = of_property_read_u32_array(np, name, tmp, len);
  1033. if (ret) {
  1034. NVT_ERR("error reading %s. ret=%d\n", name, ret);
  1035. return -1;
  1036. }
  1037. for (i = 0; i < len; i++)
  1038. array[i] = tmp[i];
  1039. #if NVT_DEBUG
  1040. printk("[NVT-ts] %s = ", name);
  1041. nvt_print_result_log_in_one_line(array, len);
  1042. printk("\n");
  1043. #endif
  1044. }
  1045. return 0;
  1046. }
  1047. /*******************************************************
  1048. Description:
  1049. Novatek touchscreen parse criterion for u32 type.
  1050. return:
  1051. n.a.
  1052. *******************************************************/
  1053. int32_t nvt_mp_parse_u32(struct device_node *np, const char *name, int32_t *para)
  1054. {
  1055. int32_t ret;
  1056. ret = of_property_read_u32(np, name, para);
  1057. if (ret) {
  1058. NVT_ERR("error reading %s. ret=%d\n", name, ret);
  1059. return -1;
  1060. } else {
  1061. #if NVT_DEBUG
  1062. NVT_LOG("%s=%d\n", name, *para);
  1063. #endif
  1064. }
  1065. return 0;
  1066. }
  1067. /*******************************************************
  1068. Description:
  1069. Novatek touchscreen parse criterion for array type.
  1070. return:
  1071. n.a.
  1072. *******************************************************/
  1073. int32_t nvt_mp_parse_array(struct device_node *np, const char *name, int32_t *array,
  1074. int32_t size)
  1075. {
  1076. struct property *data;
  1077. int32_t len, ret;
  1078. #if NVT_DEBUG
  1079. int32_t j = 0;
  1080. #endif
  1081. data = of_find_property(np, name, &len);
  1082. len /= sizeof(u32);
  1083. if ((!data) || (!len) || (len < size)) {
  1084. NVT_ERR("error find %s. len=%d\n", name, len);
  1085. return -1;
  1086. } else {
  1087. NVT_LOG("%s. len=%d\n", name, len);
  1088. ret = of_property_read_u32_array(np, name, array, len);
  1089. if (ret) {
  1090. NVT_ERR("error reading %s. ret=%d\n", name, ret);
  1091. return -1;
  1092. }
  1093. #if NVT_DEBUG
  1094. NVT_LOG("%s =\n", name);
  1095. for (j = 0; j < Y_Channel; j++) {
  1096. nvt_print_data_log_in_one_line(array + j * X_Channel, X_Channel);
  1097. printk("\n");
  1098. }
  1099. #if TOUCH_KEY_NUM > 0
  1100. nvt_print_data_log_in_one_line(array + Y_Channel * X_Channel, Key_Channel);
  1101. printk("\n");
  1102. #endif
  1103. #endif
  1104. }
  1105. return 0;
  1106. }
  1107. /*******************************************************
  1108. Description:
  1109. Novatek touchscreen parse device tree mp function.
  1110. return:
  1111. n.a.
  1112. *******************************************************/
  1113. int32_t nvt_mp_parse_dt(struct device_node *root, const char *node_compatible)
  1114. {
  1115. struct device_node *np = root;
  1116. struct device_node *child = NULL;
  1117. NVT_LOG("Parse mp criteria for node %s\n", node_compatible);
  1118. /* find each MP sub-nodes */
  1119. for_each_child_of_node(root, child) {
  1120. /* find the specified node */
  1121. if (of_device_is_compatible(child, node_compatible)) {
  1122. NVT_LOG("found child node %s\n", node_compatible);
  1123. np = child;
  1124. break;
  1125. }
  1126. }
  1127. if (child == NULL) {
  1128. NVT_ERR("Not found compatible node %s!\n", node_compatible);
  1129. return -1;
  1130. }
  1131. /* MP Config*/
  1132. if (nvt_mp_parse_u32(np, "IC_X_CFG_SIZE", &IC_X_CFG_SIZE))
  1133. return -1;
  1134. if (nvt_mp_parse_u32(np, "IC_Y_CFG_SIZE", &IC_Y_CFG_SIZE))
  1135. return -1;
  1136. #if TOUCH_KEY_NUM > 0
  1137. if (nvt_mp_parse_u32(np, "IC_KEY_CFG_SIZE", &IC_KEY_CFG_SIZE))
  1138. return -1;
  1139. #endif
  1140. if (nvt_mp_parse_u32(np, "X_Channel", &X_Channel))
  1141. return -1;
  1142. if (nvt_mp_parse_u32(np, "Y_Channel", &Y_Channel))
  1143. return -1;
  1144. if (nvt_mp_parse_ain(np, "AIN_X", AIN_X, IC_X_CFG_SIZE))
  1145. return -1;
  1146. if (nvt_mp_parse_ain(np, "AIN_Y", AIN_Y, IC_Y_CFG_SIZE))
  1147. return -1;
  1148. #if TOUCH_KEY_NUM > 0
  1149. if (nvt_mp_parse_ain(np, "AIN_KEY", AIN_KEY, IC_KEY_CFG_SIZE))
  1150. return -1;
  1151. #endif
  1152. /* MP Criteria */
  1153. if (nvt_mp_parse_array(np, "PS_Config_Lmt_Short_Rawdata_P", PS_Config_Lmt_Short_Rawdata_P,
  1154. X_Channel * Y_Channel + Key_Channel))
  1155. return -1;
  1156. if (nvt_mp_parse_array(np, "PS_Config_Lmt_Short_Rawdata_N", PS_Config_Lmt_Short_Rawdata_N,
  1157. X_Channel * Y_Channel + Key_Channel))
  1158. return -1;
  1159. if (nvt_mp_parse_array(np, "PS_Config_Lmt_Open_Rawdata_P", PS_Config_Lmt_Open_Rawdata_P,
  1160. X_Channel * Y_Channel + Key_Channel))
  1161. return -1;
  1162. if (nvt_mp_parse_array(np, "PS_Config_Lmt_Open_Rawdata_N", PS_Config_Lmt_Open_Rawdata_N,
  1163. X_Channel * Y_Channel + Key_Channel))
  1164. return -1;
  1165. if (nvt_mp_parse_array(np, "PS_Config_Lmt_FW_Rawdata_P", PS_Config_Lmt_FW_Rawdata_P,
  1166. X_Channel * Y_Channel + Key_Channel))
  1167. return -1;
  1168. if (nvt_mp_parse_array(np, "PS_Config_Lmt_FW_Rawdata_N", PS_Config_Lmt_FW_Rawdata_N,
  1169. X_Channel * Y_Channel + Key_Channel))
  1170. return -1;
  1171. if (nvt_mp_parse_array(np, "PS_Config_Lmt_FW_CC_P", PS_Config_Lmt_FW_CC_P,
  1172. X_Channel * Y_Channel + Key_Channel))
  1173. return -1;
  1174. if (nvt_mp_parse_array(np, "PS_Config_Lmt_FW_CC_N", PS_Config_Lmt_FW_CC_N,
  1175. X_Channel * Y_Channel + Key_Channel))
  1176. return -1;
  1177. if (nvt_mp_parse_array(np, "PS_Config_Lmt_FW_Diff_P", PS_Config_Lmt_FW_Diff_P,
  1178. X_Channel * Y_Channel + Key_Channel))
  1179. return -1;
  1180. if (nvt_mp_parse_array(np, "PS_Config_Lmt_FW_Diff_N", PS_Config_Lmt_FW_Diff_N,
  1181. X_Channel * Y_Channel + Key_Channel))
  1182. return -1;
  1183. if (nvt_mp_parse_u32(np, "PS_Config_Diff_Test_Frame", &PS_Config_Diff_Test_Frame))
  1184. return -1;
  1185. NVT_LOG("Parse mp criteria done!\n");
  1186. return 0;
  1187. }
  1188. #endif /* #ifdef CONFIG_OF */
  1189. /*******************************************************
  1190. Description:
  1191. Novatek touchscreen MP function proc. file node
  1192. initial function.
  1193. return:
  1194. Executive outcomes. 0---succeed. -1---failed.
  1195. *******************************************************/
  1196. int32_t nvt_mp_proc_init(void)
  1197. {
  1198. NVT_proc_selftest_entry = proc_create("nvt_selftest", 0444, NULL, &nvt_selftest_fops);
  1199. if (NVT_proc_selftest_entry == NULL) {
  1200. NVT_ERR("create /proc/nvt_selftest Failed!\n");
  1201. return -1;
  1202. } else {
  1203. if(nvt_mp_buffer_init()) {
  1204. NVT_ERR("Allocate mp memory failed\n");
  1205. return -1;
  1206. }
  1207. else {
  1208. NVT_LOG("create /proc/nvt_selftest Succeeded!\n");
  1209. }
  1210. return 0;
  1211. }
  1212. }
  1213. /*******************************************************
  1214. Description:
  1215. Novatek touchscreen MP function proc. file node
  1216. deinitial function.
  1217. return:
  1218. n.a.
  1219. *******************************************************/
  1220. void nvt_mp_proc_deinit(void)
  1221. {
  1222. nvt_mp_buffer_deinit();
  1223. if (NVT_proc_selftest_entry != NULL) {
  1224. remove_proc_entry("nvt_selftest", NULL);
  1225. NVT_proc_selftest_entry = NULL;
  1226. NVT_LOG("Removed /proc/%s\n", "nvt_selftest");
  1227. }
  1228. }
  1229. #endif /* #if NVT_TOUCH_MP */