nt36xxx_mp_ctrlram.c 38 KB

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