ic_drv_interface.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /* i2c_drv_interface.c
  2. *
  3. * Raydium TouchScreen driver.
  4. *
  5. * Copyright (c) 2021 Raydium tech Ltd.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. */
  18. #ifdef __KERNEL__
  19. #include <linux/delay.h>
  20. #include <linux/mutex.h>
  21. #include <linux/unistd.h>
  22. #include <linux/kernel.h>
  23. #include <linux/string.h>
  24. #include <linux/timer.h>
  25. #include <linux/fs.h>
  26. #include <asm/uaccess.h>
  27. #else
  28. #include <stdint.h>
  29. #include <string.h>
  30. #endif
  31. #include "ic_drv_interface.h"
  32. #include "../drv_interface.h"
  33. #include "ic_drv_global.h"
  34. #if SELFTEST_2X
  35. #include "f302_ic_control.h"
  36. #include "f302_ic_test.h"
  37. #endif
  38. #if SELFTEST_3X
  39. #include "f303_ic_control.h"
  40. #include "f303_ic_test.h"
  41. #endif
  42. #if !SELFTEST
  43. #include "f302_ic_test.h"
  44. #include "f302_ic_test_ft.h"
  45. #include "f303_ic_test.h"
  46. #include "f303_ic_test_ft.h"
  47. #include "ic_drv_global_ft.h"
  48. #include "main.h"
  49. #endif
  50. st_test_threshold g_st_test_thd;
  51. st_test_info g_st_test_info;
  52. st_test_para_resv g_st_test_para_resv;
  53. unsigned char g_u8_ic_test_state;
  54. STATUS wearable_ic_test_read_info(void)
  55. {
  56. if (read_flash_data(g_u32_dongle_flash_ini_addr, 16) != ERROR) {
  57. memcpy(&g_st_test_info, g_u8_data_buf, sizeof(g_st_test_info));
  58. } else {
  59. DEBUGOUT("Read Flash Data ERROR\r\n");
  60. return ERROR;
  61. }
  62. return SUCCESS;
  63. }
  64. STATUS wearable_ic_test_info_init(void)
  65. {
  66. #if SELFTEST
  67. g_u16_test_items_host_cmd = IC_TEST_ITEMS_SYSTEM | IC_TEST_ITEMS_OPEN | IC_TEST_ITEMS_SHORT | IC_TEST_ITEMS_UC | IC_TEST_ITEMS_UB | IC_TEST_ITEMS_BURN_CC;
  68. #endif
  69. if (!wearable_ic_test_read_info()) {
  70. DEBUGOUT("Read Info ERROR\r\n");
  71. return ERROR;
  72. }
  73. if (g_u16_test_items_host_cmd != 0)
  74. g_st_test_info.u16_ft_test_item &= g_u16_test_items_host_cmd;
  75. g_u16_panel_jig_set_test_items |= g_st_test_info.u16_ft_test_item;
  76. DEBUGOUT("TestItem:0x%x:0x%x\r\n", g_st_test_info.u16_ft_test_item, g_st_test_info.u16_ft_eng_item);
  77. DEBUGOUT("g_u16_panel_jig_set_test_items:0x%x\r\n", g_u16_panel_jig_set_test_items);
  78. if (read_flash_data(g_u32_ini_threshold_addr, 36)) {
  79. memcpy(&g_st_test_thd, g_u8_data_buf, sizeof(g_st_test_thd));
  80. } else {
  81. DEBUGOUT("Read THD Data ERROR\r\n");
  82. return ERROR;
  83. }
  84. DEBUGOUT("THD:\r\n%d,%d,%d,%d,\r\n%d,%d,%d,%d,\r\n%d,%d,%d,%d\r\n",
  85. g_st_test_thd.i16_ft_test_open_lower_thd,
  86. g_st_test_thd.i16_ft_test_short_upper_thd,
  87. g_st_test_thd.i16_ft_test_short_lower_thd,
  88. g_st_test_thd.i16_ft_test_single_cc_upper_thd,
  89. g_st_test_thd.i16_ft_test_single_cc_lower_thd,
  90. g_st_test_thd.i16_ft_test_uniformity_bl_upper_thd,
  91. g_st_test_thd.i16_ft_test_uniformity_bl_lower_thd,
  92. g_st_test_thd.i16_ft_test_uniformity_cc_upper_thd,
  93. g_st_test_thd.i16_ft_test_uniformity_cc_lower_thd,
  94. g_st_test_thd.i16_ft_test_panel_test_1_thd,
  95. g_st_test_thd.i16_ft_test_panel_test_3_thd,
  96. g_st_test_thd.i16_ft_test_panel_test_2_thd);
  97. if (read_flash_data(g_u32_ini_para_addr, 48)) {
  98. memcpy(&g_st_test_para_resv, g_u8_data_buf, sizeof(g_st_test_para_resv));
  99. } else {
  100. DEBUGOUT("Read INI Para ERROR\r\n");
  101. return ERROR;
  102. }
  103. /*
  104. * DEBUGOUT(" g_st_test_para_resv.u32_normal_fw_version = %X ,g_st_test_para_resv.u32_test_fw_version= %X \r\n",
  105. * g_st_test_para_resv.u32_normal_fw_version,
  106. * g_st_test_para_resv.u32_test_fw_version
  107. * );
  108. */
  109. if (g_u16_dev_id == DEVICE_ID_3X) {
  110. if (read_flash_data(g_u32_ini_raw_data_3_cc_addr, 128)) {
  111. memcpy(g_u16_raw_data3_golden_cc_buf, g_u8_data_buf, sizeof(g_u16_raw_data3_golden_cc_buf));
  112. } else {
  113. DEBUGOUT("read raw data 3 cc ERROR\r\n");
  114. return ERROR;
  115. }
  116. /*
  117. * DEBUGOUT(" g_u16_raw_data3_golden_cc_buf[0] = %d,g_u16_raw_data3_golden_cc_buf[1 =%d g_u16_raw_data3_golden_cc_buf[2]=%d,\r\n",
  118. * g_u16_raw_data3_golden_cc_buf[0],
  119. * g_u16_raw_data3_golden_cc_buf[1],
  120. * g_u16_raw_data3_golden_cc_buf[2]
  121. * );
  122. */
  123. if (read_flash_data(g_u32_ini_uc_cc_addr, 128)) {
  124. memcpy(g_u16_uc_golden_cc_buf, g_u8_data_buf, sizeof(g_u16_uc_golden_cc_buf));
  125. } else {
  126. DEBUGOUT("read uc cc ERROR\r\n");
  127. return ERROR;
  128. }
  129. } else if (g_u16_dev_id == DEVICE_ID_2X) {
  130. if (read_flash_data(g_u32_ini_raw_data_3_cc_addr, 72)) {
  131. memcpy(g_u16_raw_data3_golden_cc_buf, g_u8_data_buf, sizeof(g_u16_raw_data3_golden_cc_buf));
  132. } else {
  133. DEBUGOUT("read raw data 3 cc ERROR\r\n");
  134. return ERROR;
  135. }
  136. /*
  137. * DEBUGOUT(" g_u16_raw_data3_golden_cc_buf[0] = %d,g_u16_raw_data3_golden_cc_buf[1 =%d g_u16_raw_data3_golden_cc_buf[2]=%d,\r\n",
  138. * g_u16_raw_data3_golden_cc_buf[0],
  139. * g_u16_raw_data3_golden_cc_buf[1],
  140. * g_u16_raw_data3_golden_cc_buf[2]
  141. * );
  142. */
  143. if (read_flash_data(g_u32_ini_uc_cc_addr, 72)) {
  144. memcpy(g_u16_uc_golden_cc_buf, g_u8_data_buf, sizeof(g_u16_uc_golden_cc_buf));
  145. } else {
  146. DEBUGOUT("read uc cc ERROR\r\n");
  147. return ERROR;
  148. }
  149. }
  150. /* if (read_flash_data(INI_RAW_DATA2_BL_ADDR, 72))
  151. * memcpy(g_i16_raw_data2_golden_bl_buf, g_u8_data_buf, sizeof(g_i16_raw_data2_golden_bl_buf));
  152. */
  153. return SUCCESS;
  154. }
  155. STATUS wearable_ic_test_init(void)
  156. {
  157. if (!wearable_ic_test_info_init())
  158. return ERROR;
  159. if (!(g_st_test_info.u16_ft_eng_item & IC_TEST_ENG_ITEMS_PANEL_TEST_JIG))
  160. wearable_ic_test_init_buffer();
  161. return SUCCESS;
  162. }
  163. void wearable_ic_test_init_buffer(void)
  164. {
  165. g_u32_wearable_test_result = WEARABLE_FT_TEST_RESULT_IC_INIT_STATE;
  166. memset(g_u32_test_result, 0, sizeof(g_u32_test_result));
  167. memset(g_u8_test_result, 0, sizeof(g_u8_test_result));
  168. g_u8_is_normal_fw = FALSE;
  169. }
  170. STATUS handle_burn_log_to_flash(void)
  171. {
  172. STATUS u8_status = ERROR;
  173. switch (g_u16_dev_id) {
  174. #if (!SELFTEST_2X && (!SELFTEST))
  175. case DEVICE_ID_2X:
  176. burn_data_log_to_flash_2x();
  177. break;
  178. #endif
  179. #if (!SELFTEST_3X && (!SELFTEST))
  180. case DEVICE_ID_3X:
  181. b_is_auo_jig_testing = false;
  182. burn_header_log_to_flash_3x(TRUE, TRUE);
  183. memset(g_u32_save_config, 0, sizeof(g_u32_save_config));
  184. if (burn_data_log_to_flash_3x())
  185. u8_status = SUCCESS;
  186. break;
  187. #endif
  188. }
  189. return u8_status;
  190. }
  191. void handle_ic_test(void)
  192. {
  193. switch (g_u16_dev_id) {
  194. #if (SELFTEST_2X | (!SELFTEST))
  195. case DEVICE_ID_2X:
  196. do_ic_test_2x();
  197. break;
  198. #endif
  199. #if (SELFTEST_3X | (!SELFTEST))
  200. case DEVICE_ID_3X:
  201. do_ic_test_3x();
  202. break;
  203. #endif
  204. }
  205. }
  206. void handle_set_display_interface(unsigned char u8_interface)
  207. {
  208. g_u8_display_interface = u8_interface;
  209. DEBUGOUT("%s: 0x%x \r\n", __func__, u8_interface);
  210. }