raydium_selftest.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. /* raydium_selftest.c
  2. *
  3. * Raydium TouchScreen driver.
  4. *
  5. * This file is provided under a dual BSD/GPLv2 license. When using or
  6. * redistributing this file, you may do so under either license.
  7. * Qualcomm Innovation Center, Inc. chooses to use it under GPLv2
  8. * Copyright (c) 2021 Raydium tech Ltd.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * BSD LICENSE
  21. *
  22. * Redistribution and use in source and binary forms, with or without
  23. * modification, are permitted provided that the following conditions
  24. * are met:
  25. *
  26. * * Redistributions of source code must retain the above copyright
  27. * notice, this list of conditions and the following disclaimer.
  28. * * Redistributions in binary form must reproduce the above copyright
  29. * notice, this list of conditions and the following disclaimer in
  30. * the documentation and/or other materials provided with the
  31. * distribution.
  32. * * Neither the name of Google Inc. or Linaro Ltd. nor the names of
  33. * its contributors may be used to endorse or promote products
  34. * derived from this software without specific prior written
  35. * permission.
  36. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  37. * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  38. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  39. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  40. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  41. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  42. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  43. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  44. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  45. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  46. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  47. */
  48. #include <linux/delay.h>
  49. #include <linux/mutex.h>
  50. #include <linux/unistd.h>
  51. #include <linux/kernel.h>
  52. #include <linux/string.h>
  53. #include <linux/timer.h>
  54. #include <linux/fs.h>
  55. #include <asm/uaccess.h>
  56. #include "drv_interface.h"
  57. #include "chip_raydium/ic_drv_interface.h"
  58. #include "raydium_selftest.h"
  59. #include "chip_raydium/ic_drv_global.h"
  60. #include "tpselftest_30.h"
  61. #if defined(FW_MAPPING_EN)
  62. #include "tpselftest_21.h"
  63. #endif
  64. #define RM_SELF_TEST_CUSTOMER_VERSION 0x01
  65. #define RM_SELF_TEST_PLATFORM_VERSION 0x01
  66. #define RM_SELF_TEST_PROJECT_VERSION 0x40
  67. #define RM_SELF_TEST_MAIN_VERSION 1
  68. #define RM_SELF_TEST_SUB_VERSION 0
  69. #define RESULT_SUCCESS 0
  70. #define RESULT_NG 1
  71. #define RELATIVE_PATH 0
  72. #define RM_SELF_TEST_MAX_STR_LENGTH 1000
  73. unsigned char g_u8_normal_fw_version_buf[4];
  74. char str_ini_path[100];
  75. static int self_test_all(void)
  76. {
  77. int ret = 0;
  78. g_u8_raydium_flag |= ENG_MODE;
  79. handle_ic_test();
  80. ret = g_u32_wearable_test_result;
  81. /*g_u8_raydium_flag &= ~ENG_MODE;*/
  82. DEBUGOUT("%s\r\n", __func__);
  83. return ret;
  84. }
  85. int self_test_save_to_file(char *file_name, char *p_string, short len)
  86. {
  87. struct file *filp = NULL;
  88. mm_segment_t old_fs;
  89. filp = filp_open_block(file_name, O_RDWR | O_CREAT | O_APPEND, 0666);
  90. if (IS_ERR(filp)) {
  91. DEBUGOUT("can't open file:%s\n", RM_SELF_TEST_LOGFILE);
  92. return 0;
  93. }
  94. old_fs = force_uaccess_begin();
  95. filp->f_op->write(filp, p_string, len, &filp->f_pos);
  96. force_uaccess_end(old_fs);
  97. filp_close(filp, NULL);
  98. return 1;
  99. }
  100. #if 1
  101. static int raydium_check_ini_version(void)
  102. {
  103. int ret = 0;
  104. unsigned int u32_test_version;
  105. memcpy(&u32_test_version, &g_rad_testpara_image[4], 4);
  106. if (u32_test_version != g_st_test_para_resv.u32_test_fw_version) {
  107. DEBUGOUT("test fw versio 0x%X != ini version 0x%X\n"
  108. , u32_test_version, g_st_test_para_resv.u32_test_fw_version);
  109. ret = WEARABLE_FT_TEST_RESULT_TEST_FW_VER_NG;
  110. }
  111. if (g_u16_dev_id == DEVICE_ID_3X) {
  112. g_u32_dongle_flash_ini_addr = F303_DONGLE_FLASH_INI_ADDR;
  113. g_u32_ini_threshold_addr = F303_INI_THRESHOLD_ADDR;
  114. g_u32_ini_para_addr = F303_INI_PARA_ADDR;
  115. g_u32_ini_raw_data_3_cc_addr = F303_INI_RAW_DATA_3_CC_ADDR;
  116. g_u32_ini_uc_cc_addr = F303_INI_UC_CC_ADDR;
  117. g_u32_initial_code_start_addr = F303_INITIAL_CODE_START_ADDR;
  118. DEBUGOUT("[out_set_ic_version] F303 Set INI ADDR!\r\n");
  119. } else if (g_u16_dev_id == DEVICE_ID_2X) {
  120. g_u32_dongle_flash_ini_addr = F302_DONGLE_FLASH_INI_ADDR;
  121. g_u32_ini_threshold_addr = F302_INI_THRESHOLD_ADDR;
  122. g_u32_ini_para_addr = F302_INI_PARA_ADDR;
  123. g_u32_ini_raw_data_3_cc_addr = F302_INI_RAW_DATA_3_CC_ADDR;
  124. g_u32_ini_uc_cc_addr = F302_INI_UC_CC_ADDR;
  125. g_u32_initial_code_start_addr = F302_INITIAL_CODE_START_ADDR;
  126. DEBUGOUT("[out_set_ic_version] F302 Set INI ADDR!\r\n");
  127. }
  128. return ret;
  129. }
  130. #else
  131. static int raydium_check_ini_version(void)
  132. {
  133. int ret = 0;
  134. unsigned int u32_test_version, u32_version_20, u32_version_21;
  135. memcpy(&u32_test_version, &g_st_test_para_resv.u32_test_fw_version, 4);
  136. if (g_u16_dev_id == DEVICE_ID_2X) {
  137. switch (g_raydium_ts->id) {
  138. case RAD_SELFTEST_20:
  139. memcpy(&u32_version_20, &u8_rad_testpara_20[4], 4);
  140. DEBUGOUT("ini version 0x%X, 20 version 0x%X\n"
  141. , u32_test_version, u32_version_20);
  142. if (u32_test_version == u32_version_20)
  143. DEBUGOUT("map version= 0x%X\r\n", u32_version_20);
  144. else
  145. ret = WEARABLE_FT_TEST_RESULT_TEST_FW_VER_NG;
  146. case RAD_SELFTEST_21:
  147. memcpy(&u32_version_21, &u8_rad_testpara_21[4], 4);
  148. DEBUGOUT("ini version 0x%X, 21 version 0x%X\n"
  149. , u32_test_version, u32_version_21);
  150. if (u32_test_version == u32_version_21)
  151. DEBUGOUT("map version= 0x%X\r\n", u32_version_21);
  152. else
  153. ret = WEARABLE_FT_TEST_RESULT_TEST_FW_VER_NG;
  154. }
  155. }
  156. return ret;
  157. }
  158. #endif
  159. static int self_test_init(void)
  160. {
  161. int ret = 0;
  162. unsigned int u32_dev_id;
  163. g_u8_drv_interface = I2C_INTERFACE;
  164. g_u16_dev_id = DEVICE_ID_3X;
  165. if (handle_ic_read(RAYDIUM_CHK_I2C_CMD, 4, (unsigned char *)&u32_dev_id, g_u8_drv_interface, I2C_WORD_MODE) == ERROR) {
  166. ret = WEARABLE_FT_TEST_RESULT_SYSFS_NG;
  167. return ret;
  168. }
  169. g_u16_dev_id = ((u32_dev_id & 0xFFFF0000) >> 16);
  170. if (g_u16_dev_id == DEVICE_ID_2X) {
  171. handle_ic_read(0x00006a04, 4, g_u8_normal_fw_version_buf, g_u8_drv_interface, I2C_WORD_MODE);
  172. DEBUGOUT("FW Version=0x%.2X%.2X%.2X%.2X\n", g_u8_normal_fw_version_buf[0], g_u8_normal_fw_version_buf[1],
  173. g_u8_normal_fw_version_buf[3], g_u8_normal_fw_version_buf[2]);
  174. } else if (g_u16_dev_id == DEVICE_ID_3X) {
  175. handle_ic_read(0x00007b04, 4, g_u8_normal_fw_version_buf, g_u8_drv_interface, I2C_WORD_MODE);
  176. DEBUGOUT("FW Version=0x%.2X%.2X%.2X%.2X\n", g_u8_normal_fw_version_buf[0], g_u8_normal_fw_version_buf[1],
  177. g_u8_normal_fw_version_buf[3], g_u8_normal_fw_version_buf[2]);
  178. } else {
  179. DEBUGOUT("read ic namd fail\n");
  180. ret = WEARABLE_FT_TEST_RESULT_TEST_INIT_NG;
  181. return ret;
  182. }
  183. if (raydium_check_ini_version() != 0)
  184. ret = WEARABLE_FT_TEST_RESULT_TEST_FW_VER_NG;
  185. return ret;
  186. }
  187. int self_test_save_test_raw_data_to_file(int i32_ng_type)
  188. {
  189. /*struct tm *time_infor;*/
  190. /*time_t raw_time;*/
  191. char write_string[1000];
  192. unsigned char u8_i, u8_j;
  193. short *p_i16_buf = (short *)g_u16_raw_data_tmp;
  194. /*FW Version*/
  195. memset(write_string, 0, strlen(write_string));
  196. if (g_u16_dev_id != 0) {
  197. snprintf(write_string, RM_SELF_TEST_MAX_STR_LENGTH,
  198. "FW Version=0x%.2X%.2X%.2X%.2X\n",
  199. g_u8_normal_fw_version_buf[0], g_u8_normal_fw_version_buf[1],
  200. g_u8_normal_fw_version_buf[3], g_u8_normal_fw_version_buf[2]);
  201. }
  202. self_test_save_to_file(RM_SELF_TEST_LOGFILE, write_string, strlen(write_string));
  203. /*Version*/
  204. memset(write_string, 0, strlen(write_string));
  205. snprintf(write_string, RM_SELF_TEST_MAX_STR_LENGTH, "Selftest Version=%x.%x.%x.%x.%x\n\n",
  206. RM_SELF_TEST_CUSTOMER_VERSION, RM_SELF_TEST_PLATFORM_VERSION,
  207. RM_SELF_TEST_PROJECT_VERSION, RM_SELF_TEST_MAIN_VERSION,
  208. RM_SELF_TEST_SUB_VERSION);
  209. self_test_save_to_file(RM_SELF_TEST_LOGFILE, write_string, strlen(write_string));
  210. /*Test result*/
  211. memset(write_string, 0, strlen(write_string));
  212. snprintf(write_string, RM_SELF_TEST_MAX_STR_LENGTH, "Test Result = 0x%08X\n\n",
  213. i32_ng_type);
  214. self_test_save_to_file(RM_SELF_TEST_LOGFILE, write_string, strlen(write_string));
  215. if (i32_ng_type == 0) {
  216. memset(write_string, 0, strlen(write_string));
  217. snprintf(write_string, RM_SELF_TEST_MAX_STR_LENGTH, "All pass\n\n\n");
  218. self_test_save_to_file(RM_SELF_TEST_LOGFILE, write_string, strlen(write_string));
  219. } else {
  220. memset(write_string, 0, strlen(write_string));
  221. if (i32_ng_type & WEARABLE_FT_TEST_RESULT_SYSFS_NG) {
  222. snprintf(write_string,
  223. RM_SELF_TEST_MAX_STR_LENGTH, "System NG ");
  224. }
  225. if (i32_ng_type & WEARABLE_FT_TEST_RESULT_I2C_NG) {
  226. snprintf(write_string,
  227. RM_SELF_TEST_MAX_STR_LENGTH, "I2C NG ");
  228. }
  229. if (i32_ng_type & WEARABLE_FT_TEST_RESULT_INT_NG) {
  230. snprintf(write_string,
  231. RM_SELF_TEST_MAX_STR_LENGTH, "INT NG ");
  232. }
  233. if (i32_ng_type & WEARABLE_FT_TEST_RESULT_RESET_NG) {
  234. snprintf(write_string,
  235. RM_SELF_TEST_MAX_STR_LENGTH, "RESET NG ");
  236. }
  237. if (i32_ng_type & WEARABLE_FT_TEST_RESULT_PRAM_NG) {
  238. snprintf(write_string,
  239. RM_SELF_TEST_MAX_STR_LENGTH, "PRAM NG ");
  240. }
  241. if (i32_ng_type & WEARABLE_FT_TEST_RESULT_NORMAL_FW_NG) {
  242. snprintf(write_string,
  243. RM_SELF_TEST_MAX_STR_LENGTH, "NORMAL_FW_NG ");
  244. }
  245. if (i32_ng_type & WEARABLE_FT_TEST_RESULT_OPEN_NG) {
  246. snprintf(write_string,
  247. RM_SELF_TEST_MAX_STR_LENGTH, "OPEN NG ");
  248. }
  249. if (i32_ng_type & WEARABLE_FT_TEST_RESULT_SHORT_NG) {
  250. snprintf(write_string,
  251. RM_SELF_TEST_MAX_STR_LENGTH, "SHORT NG ");
  252. }
  253. if (i32_ng_type & WEARABLE_FT_TEST_RESULT_BURN_CC_NG) {
  254. snprintf(write_string,
  255. RM_SELF_TEST_MAX_STR_LENGTH, "BURN CC NG ");
  256. }
  257. if (i32_ng_type & WEARABLE_FT_TEST_RESULT_GET_DATA_NG) {
  258. snprintf(write_string,
  259. RM_SELF_TEST_MAX_STR_LENGTH, "GET DATA NG ");
  260. }
  261. if (i32_ng_type & WEARABLE_FT_TEST_RESULT_FLASH_ID_NG) {
  262. snprintf(write_string,
  263. RM_SELF_TEST_MAX_STR_LENGTH, "FLASH ID NG ");
  264. }
  265. if (i32_ng_type & WEARABLE_FT_TEST_RESULT_NORMAL_FW_VER_NG) {
  266. snprintf(write_string,
  267. RM_SELF_TEST_MAX_STR_LENGTH, "NORMAL FW VER NG ");
  268. }
  269. if (i32_ng_type & WEARABLE_FT_TEST_RESULT_TEST_FW_VER_NG) {
  270. snprintf(write_string,
  271. RM_SELF_TEST_MAX_STR_LENGTH, "TEST FW VER NG ");
  272. }
  273. if (i32_ng_type & WEARABLE_FT_TEST_RESULT_TEST_INIT_NG) {
  274. snprintf(write_string,
  275. RM_SELF_TEST_MAX_STR_LENGTH, "TEST INIT NG ");
  276. }
  277. if (i32_ng_type & WEARABLE_FT_TEST_RESULT_LOAD_TESTFW_NG) {
  278. snprintf(write_string,
  279. RM_SELF_TEST_MAX_STR_LENGTH, "LOAD TESTFW NG ");
  280. }
  281. if (i32_ng_type & WEARABLE_FT_TEST_RESULT_BURN_FW_NG) {
  282. snprintf(write_string,
  283. RM_SELF_TEST_MAX_STR_LENGTH, "BURN FW NG ");
  284. }
  285. if (i32_ng_type & WEARABLE_FT_TEST_RESULT_SINGLE_CC_OPEN_NG) {
  286. snprintf(write_string,
  287. RM_SELF_TEST_MAX_STR_LENGTH, "Open NG (Single Pin CC) ");
  288. }
  289. if (i32_ng_type & WEARABLE_FT_TEST_RESULT_SINGLE_CC_SHORT_NG) {
  290. snprintf(write_string,
  291. RM_SELF_TEST_MAX_STR_LENGTH, "Short NG (Single Pin CC) ");
  292. }
  293. if (i32_ng_type & WEARABLE_FT_TEST_RESULT_UB_NG) {
  294. snprintf(write_string,
  295. RM_SELF_TEST_MAX_STR_LENGTH, "Uniformity Baseline NG ");
  296. }
  297. if (i32_ng_type & WEARABLE_FT_TEST_RESULT_UC_NG) {
  298. snprintf(write_string,
  299. RM_SELF_TEST_MAX_STR_LENGTH, "Uniformity CC NG ");
  300. }
  301. snprintf(write_string, RM_SELF_TEST_MAX_STR_LENGTH, "\n");
  302. self_test_save_to_file(RM_SELF_TEST_LOGFILE, write_string, strlen(write_string));
  303. }
  304. /*Threshold*/
  305. memset(write_string, 0, strlen(write_string));
  306. /*snprintf(write_string, RM_SELF_TEST_MAX_STR_LENGTH, "0x%02X, 0x%02X\n0x%02X,
  307. 0x%02X\n0x%02X, 0x%02X\n0x%02X, 0x%02X\n0x%02X, 0x%02X\n0x%02X, 0x%02X\n0x%02X,
  308. 0x%02X\n0x%02X, 0x%02X\n0x%02X, 0x%02X\n",
  309. (g_st_test_thd.i16_ft_test_open_lower_thd >> 8) & 0xFF, (g_st_test_thd.i16_ft_test_open_lower_thd & 0xFF),
  310. (g_st_test_thd.i16_ft_test_short_upper_thd >> 8) & 0xFF, (g_st_test_thd.i16_ft_test_short_upper_thd & 0xFF),
  311. (g_st_test_thd.i16_ft_test_short_lower_thd >> 8) & 0xFF, (g_st_test_thd.i16_ft_test_short_lower_thd & 0xFF),
  312. (g_st_test_thd.i16_ft_test_single_cc_upper_thd >> 8) & 0xFF, (g_st_test_thd.i16_ft_test_single_cc_upper_thd & 0xFF),
  313. (g_st_test_thd.i16_ft_test_single_cc_lower_thd >> 8) & 0xFF, (g_st_test_thd.i16_ft_test_single_cc_lower_thd & 0xFF),
  314. (g_st_test_thd.i16_ft_test_uniformity_bl_upper_thd >> 8) & 0xFF, (g_st_test_thd.i16_ft_test_uniformity_bl_upper_thd & 0xFF),
  315. (g_st_test_thd.i16_ft_test_uniformity_bl_lower_thd >> 8) & 0xFF, (g_st_test_thd.i16_ft_test_uniformity_bl_lower_thd & 0xFF),
  316. (g_st_test_thd.i16_ft_test_uniformity_cc_upper_thd >> 8) & 0xFF, (g_st_test_thd.i16_ft_test_uniformity_cc_upper_thd & 0xFF),
  317. (g_st_test_thd.i16_ft_test_uniformity_cc_lower_thd >> 8) & 0xFF, (g_st_test_thd.i16_ft_test_uniformity_cc_lower_thd & 0xFF));*/
  318. self_test_save_to_file(RM_SELF_TEST_LOGFILE, write_string, strlen(write_string));
  319. for (u8_i = 0; u8_i < MAX_SENSING_PIN_NUM; u8_i++) {
  320. memset(write_string, 0, strlen(write_string));
  321. snprintf(write_string, RM_SELF_TEST_MAX_STR_LENGTH, "0x%2X,",
  322. g_u16_uc_golden_cc_buf[u8_i]);
  323. self_test_save_to_file(RM_SELF_TEST_LOGFILE, write_string, strlen(write_string));
  324. }
  325. memset(write_string, 0, strlen(write_string));
  326. snprintf(write_string, RM_SELF_TEST_MAX_STR_LENGTH, "\n");
  327. self_test_save_to_file(RM_SELF_TEST_LOGFILE, write_string, strlen(write_string));
  328. for (u8_i = 0; u8_i < MAX_SENSING_PIN_NUM; u8_i++) {
  329. memset(write_string, 0, strlen(write_string));
  330. snprintf(write_string, RM_SELF_TEST_MAX_STR_LENGTH, "0x%2X,",
  331. g_u16_raw_data3_golden_cc_buf[u8_i]);
  332. self_test_save_to_file(RM_SELF_TEST_LOGFILE, write_string, strlen(write_string));
  333. }
  334. memset(write_string, 0, strlen(write_string));
  335. snprintf(write_string, RM_SELF_TEST_MAX_STR_LENGTH, "\n\n\n\n\n\n\n\n\n\n\n\n\n");
  336. self_test_save_to_file(RM_SELF_TEST_LOGFILE, write_string, strlen(write_string));
  337. if ((i32_ng_type & 0xFFF0FBF8) < 4) {
  338. if ((g_st_test_info.u16_ft_test_item & (IC_TEST_ITEMS_SHORT)) != 0) {
  339. /*Raw data*/
  340. /*Raw data slow*/
  341. memset(write_string, 0, strlen(write_string));
  342. snprintf(write_string, RM_SELF_TEST_MAX_STR_LENGTH, "\r\n\n\n");
  343. self_test_save_to_file(RM_SELF_TEST_LOGFILE, write_string, strlen(write_string));
  344. memset(write_string, 0, strlen(write_string));
  345. snprintf(write_string, RM_SELF_TEST_MAX_STR_LENGTH, "Raw Data 1\n");
  346. self_test_save_to_file(RM_SELF_TEST_LOGFILE, write_string, strlen(write_string));
  347. /*Raw data1*/
  348. memset(p_i16_buf, 0, MAX_IMAGE_BUFFER_SIZE * 2);
  349. for (u8_i = 0; u8_i < MAX_IMAGE_BUFFER_SIZE; u8_i++)
  350. if (g_u8_wearable_pin_map[u8_i] != F303_NA_P)
  351. p_i16_buf[g_u8_wearable_pin_map[u8_i]] = g_i16_raw_data_1_short_buf[u8_i];
  352. for (u8_j = 0; u8_j < g_u8_channel_y; u8_j++) {
  353. for (u8_i = 0; u8_i < g_u8_channel_x; u8_i++) {
  354. memset(write_string, 0, strlen(write_string));
  355. snprintf(write_string, RM_SELF_TEST_MAX_STR_LENGTH,
  356. "%05d,", p_i16_buf[u8_i + u8_j * g_u8_channel_x]);
  357. self_test_save_to_file(RM_SELF_TEST_LOGFILE, write_string, strlen(write_string));
  358. }
  359. memset(write_string, 0, strlen(write_string));
  360. snprintf(write_string, RM_SELF_TEST_MAX_STR_LENGTH, "\r\n");
  361. self_test_save_to_file(RM_SELF_TEST_LOGFILE, write_string, strlen(write_string));
  362. }
  363. }
  364. if ((g_st_test_info.u16_ft_test_item & (IC_TEST_ITEMS_OPEN)) != 0) {
  365. memset(write_string, 0, strlen(write_string));
  366. snprintf(write_string, RM_SELF_TEST_MAX_STR_LENGTH, "\r\n\n\n");
  367. self_test_save_to_file(RM_SELF_TEST_LOGFILE, write_string, strlen(write_string));
  368. /*Raw data slow*/
  369. memset(write_string, 0, strlen(write_string));
  370. snprintf(write_string, RM_SELF_TEST_MAX_STR_LENGTH, "Raw Data 2\n");
  371. self_test_save_to_file(RM_SELF_TEST_LOGFILE, write_string, strlen(write_string));
  372. /*Raw data2*/
  373. memset(p_i16_buf, 0, MAX_IMAGE_BUFFER_SIZE * 2);
  374. for (u8_i = 0; u8_i < MAX_IMAGE_BUFFER_SIZE; u8_i++)
  375. if (g_u8_wearable_pin_map[u8_i] != F303_NA_P)
  376. p_i16_buf[g_u8_wearable_pin_map[u8_i]] = g_i16_raw_data_2_open_buf[u8_i];
  377. for (u8_j = 0; u8_j < g_u8_channel_y; u8_j++) {
  378. for (u8_i = 0; u8_i < g_u8_channel_x; u8_i++) {
  379. memset(write_string, 0, strlen(write_string));
  380. snprintf(write_string, RM_SELF_TEST_MAX_STR_LENGTH,
  381. "%05d,", p_i16_buf[u8_i + u8_j * g_u8_channel_x]);
  382. self_test_save_to_file(RM_SELF_TEST_LOGFILE, write_string, strlen(write_string));
  383. }
  384. memset(write_string, 0, strlen(write_string));
  385. snprintf(write_string, RM_SELF_TEST_MAX_STR_LENGTH, "\r\n");
  386. self_test_save_to_file(RM_SELF_TEST_LOGFILE, write_string, strlen(write_string));
  387. }
  388. }
  389. if ((g_st_test_info.u16_ft_test_item & (IC_TEST_ITEMS_OPEN | IC_TEST_ITEMS_SHORT)) != 0) {
  390. memset(write_string, 0, strlen(write_string));
  391. snprintf(write_string, RM_SELF_TEST_MAX_STR_LENGTH, "\r\n\n\n");
  392. self_test_save_to_file(RM_SELF_TEST_LOGFILE, write_string, strlen(write_string));
  393. /*Raw data 3*/
  394. memset(write_string, 0, strlen(write_string));
  395. snprintf(write_string, RM_SELF_TEST_MAX_STR_LENGTH, "Raw Data 3\n");
  396. self_test_save_to_file(RM_SELF_TEST_LOGFILE, write_string, strlen(write_string));
  397. /*Raw data3*/
  398. memset(p_i16_buf, 0, MAX_IMAGE_BUFFER_SIZE * 2);
  399. for (u8_i = 0; u8_i < MAX_IMAGE_BUFFER_SIZE; u8_i++)
  400. if (g_u8_wearable_pin_map[u8_i] != F303_NA_P)
  401. p_i16_buf[g_u8_wearable_pin_map[u8_i]] = g_u16_raw_data3_cc_buf[u8_i];
  402. for (u8_j = 0; u8_j < g_u8_channel_y; u8_j++) {
  403. for (u8_i = 0; u8_i < g_u8_channel_x; u8_i++) {
  404. memset(write_string, 0, strlen(write_string));
  405. snprintf(write_string, RM_SELF_TEST_MAX_STR_LENGTH,
  406. "%05d,", p_i16_buf[u8_i + u8_j * g_u8_channel_x]);
  407. self_test_save_to_file(RM_SELF_TEST_LOGFILE, write_string, strlen(write_string));
  408. }
  409. memset(write_string, 0, strlen(write_string));
  410. snprintf(write_string, RM_SELF_TEST_MAX_STR_LENGTH, "\r\n");
  411. self_test_save_to_file(RM_SELF_TEST_LOGFILE, write_string, strlen(write_string));
  412. }
  413. }
  414. if ((g_st_test_info.u16_ft_test_item & (IC_TEST_ITEMS_UC)) != 0) {
  415. memset(write_string, 0, strlen(write_string));
  416. snprintf(write_string, RM_SELF_TEST_MAX_STR_LENGTH, "\r\n\n\n");
  417. self_test_save_to_file(RM_SELF_TEST_LOGFILE, write_string, strlen(write_string));
  418. /*Raw data Uniformity CC*/
  419. memset(write_string, 0, strlen(write_string));
  420. snprintf(write_string, RM_SELF_TEST_MAX_STR_LENGTH, "Raw Data_UC\n");
  421. self_test_save_to_file(RM_SELF_TEST_LOGFILE, write_string, strlen(write_string));
  422. /*Raw data uc*/
  423. memset(p_i16_buf, 0, MAX_IMAGE_BUFFER_SIZE * 2);
  424. for (u8_i = 0; u8_i < MAX_IMAGE_BUFFER_SIZE; u8_i++)
  425. if (g_u8_wearable_pin_map[u8_i] != F303_NA_P)
  426. p_i16_buf[g_u8_wearable_pin_map[u8_i]] = g_u16_uc_buf[u8_i];
  427. DEBUGOUT("Image:0x%x\r\n", p_i16_buf[0]);
  428. for (u8_j = 0; u8_j < g_u8_channel_y; u8_j++) {
  429. for (u8_i = 0; u8_i < g_u8_channel_x; u8_i++) {
  430. memset(write_string, 0, strlen(write_string));
  431. snprintf(write_string, RM_SELF_TEST_MAX_STR_LENGTH,
  432. "%05d,", p_i16_buf[u8_i + u8_j * g_u8_channel_x]);
  433. self_test_save_to_file(RM_SELF_TEST_LOGFILE, write_string, strlen(write_string));
  434. }
  435. memset(write_string, 0, strlen(write_string));
  436. snprintf(write_string, RM_SELF_TEST_MAX_STR_LENGTH, "\r\n");
  437. self_test_save_to_file(RM_SELF_TEST_LOGFILE, write_string, strlen(write_string));
  438. }
  439. }
  440. }
  441. memset(write_string, 0, strlen(write_string));
  442. snprintf(write_string, RM_SELF_TEST_MAX_STR_LENGTH, "\r\n\n\n");
  443. self_test_save_to_file(RM_SELF_TEST_LOGFILE, write_string, strlen(write_string));
  444. return 1;
  445. }
  446. int self_test_read_setting_from_file(void)
  447. {
  448. unsigned short u16_offset = 0;
  449. DEBUGOUT("[touch]g_raydium_ts->id = 0x%x\r\n", g_raydium_ts->id);
  450. switch (g_raydium_ts->id) {
  451. case RAD_SELFTEST_30:
  452. u16_offset = 0;
  453. memcpy(&g_u8_ini_flash[u16_offset], &u8_test_info_30, sizeof(u8_test_info_30));
  454. u16_offset += 16;
  455. memcpy(&g_u8_ini_flash[u16_offset], &i8_ft_test_thd_30, sizeof(i8_ft_test_thd_30));
  456. u16_offset += 36;
  457. memcpy(&g_u8_ini_flash[u16_offset], &u8_test_para_30, sizeof(u8_test_para_30));
  458. u16_offset += 48;
  459. u16_offset += 128;/*reserve for BL*/
  460. memcpy(&g_u8_ini_flash[u16_offset], &u8_raw_data_3_cc_30, sizeof(u8_raw_data_3_cc_30));
  461. u16_offset += 128;
  462. memcpy(&g_u8_ini_flash[u16_offset], &u8_raw_uc_cc_30, sizeof(u8_raw_uc_cc_30));
  463. u16_offset += 128;
  464. memcpy((void *)(&g_st_test_para_resv), &u8_test_para_30[0], sizeof(g_st_test_para_resv));
  465. DEBUGOUT("ini length = %d\r\n", u16_offset);
  466. break;
  467. #if defined(FW_MAPPING_EN)
  468. case RAD_SELFTEST_31:
  469. u16_offset = 0;
  470. memcpy(&g_u8_ini_flash[u16_offset], &u8_test_info_31, sizeof(u8_test_info_31));
  471. u16_offset += 16;
  472. memcpy(&g_u8_ini_flash[u16_offset], &i8_ft_test_thd_31, sizeof(i8_ft_test_thd_31));
  473. u16_offset += 36;
  474. memcpy(&g_u8_ini_flash[u16_offset], &u8_test_para_31, sizeof(u8_test_para_31));
  475. u16_offset += 48;
  476. u16_offset += 128;/*reserve for BL*/
  477. memcpy(&g_u8_ini_flash[u16_offset], &u8_raw_data_3_cc_31, sizeof(u8_raw_data_3_cc_31));
  478. u16_offset += 128;
  479. memcpy(&g_u8_ini_flash[u16_offset], &u8_raw_uc_cc_31, sizeof(u8_raw_uc_cc_31));
  480. u16_offset += 128;
  481. memcpy((void *)(&g_st_test_para_resv), &u8_test_para_31[0], sizeof(g_st_test_para_resv));
  482. DEBUGOUT("ini length = %d\r\n", u16_offset);
  483. break;
  484. #endif
  485. }
  486. return 0;
  487. }
  488. int raydium_do_selftest(struct raydium_ts_data *ts)
  489. {
  490. int ret = RESULT_SUCCESS;
  491. unsigned int time_start, time_end, time_start2, time_end2;
  492. time_start = get_system_time();
  493. pr_info("Selftest Version=%x.%x.%x.%x.%x\n", RM_SELF_TEST_CUSTOMER_VERSION, RM_SELF_TEST_PLATFORM_VERSION,
  494. RM_SELF_TEST_PROJECT_VERSION, RM_SELF_TEST_MAIN_VERSION, RM_SELF_TEST_SUB_VERSION);
  495. self_test_read_setting_from_file();
  496. ic_drv_init();
  497. set_raydium_ts_data(ts);
  498. ret = self_test_init();
  499. if (ret != 0)
  500. DEBUGOUT("mapping ic fw fail\n");
  501. else {
  502. DEBUGOUT("Test all\n");
  503. ret |= self_test_all();
  504. }
  505. if (ret != WEARABLE_FT_TEST_RESULT_SYSFS_NG) {
  506. gpio_touch_hw_reset();
  507. g_u8_raydium_flag &= ~ENG_MODE;
  508. }
  509. raydium_i2c_mode_control(ts->client, ENABLE_TOUCH_INT);
  510. #if ENABLE_TIME_MEASURMENT
  511. time_start2 = get_system_time();
  512. #endif
  513. self_test_save_test_raw_data_to_file(ret);
  514. #if ENABLE_TIME_MEASURMENT
  515. time_end2 = get_system_time();
  516. DEBUGOUT("Write log Finish(%ums)\n", time_end2 - time_start2);
  517. #endif
  518. if (ret != 0) {
  519. DEBUGOUT("Selftest Test Result=0x%x\n", ret);
  520. ret = RESULT_NG;
  521. DEBUGOUT("Selftest Result=%d\n", ret);
  522. } else {
  523. DEBUGOUT("Selftest Pass ^_^!!!\n");
  524. ret = RESULT_SUCCESS;
  525. }
  526. time_end = get_system_time();
  527. DEBUGOUT("All Test Finish(%ums)\n", time_end - time_start);
  528. return ret;
  529. }