f303_ic_control.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. /* f303_ic_control.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. #include <stdlib.h>
  31. #endif
  32. #include "../drv_interface.h"
  33. #include "ic_drv_global.h"
  34. #include "ic_drv_interface.h"
  35. #include "f303_ic_control.h"
  36. #include "f303_ic_reg.h"
  37. unsigned char check_dev_id_3x(unsigned short u16_dev_id)
  38. {
  39. unsigned int u32_read;
  40. if (handle_ic_read(REG_FLASHCTL_DEVID_ADDR, 4, (unsigned char *)(&u32_read), g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  41. return ERROR;
  42. if (((u32_read & 0xFFFF0000) >> 16) == u16_dev_id) {
  43. g_u16_dev_id = DEVICE_ID_3X;
  44. return SUCCESS;
  45. }
  46. DEBUGOUT("Device ID NG! 0x%x:0x%x\r\n", ((u32_read & 0xFFFF0000) >> 16), u16_dev_id);
  47. return ERROR;
  48. }
  49. unsigned char check_dev_sub_version_3x(unsigned char u8_version)
  50. {
  51. unsigned int u32_read;
  52. if (handle_ic_read(REG_FLASHCTL_DEVID_ADDR, 4, (unsigned char *)(&u32_read), g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  53. return ERROR;
  54. DEBUGOUT("Device Sub Version 0x%x\r\n", u32_read);
  55. if ((u32_read & 0x000000FF) == u8_version)
  56. return SUCCESS;
  57. DEBUGOUT("Device Sub Version NG! 0x%x:0x%x\r\n", (u32_read & 0x000000FF), u8_version);
  58. return ERROR;
  59. }
  60. unsigned char enable_ic_block_3x(void)
  61. {
  62. unsigned int u32_read;
  63. if (handle_ic_read(REG_SYSCON_BLKEN_ADDR, 4, (unsigned char *)(&u32_read), g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  64. return ERROR;
  65. u32_read |= 0xc8000000;
  66. /*u32_read |= (BLKEN_FIC_RB_EN | BLKEN_GPIO_RB_EN | BLKEN_SYS_RB_EN);*/
  67. if (handle_ic_write(REG_SYSCON_BLKEN_ADDR, 4, (unsigned char *)&u32_read, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  68. return ERROR;
  69. if (handle_ic_read(REG_SYSCON_MISCIER_ADDR, 4, (unsigned char *)(&u32_read), g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  70. return ERROR;
  71. u32_read |= 0x00000404;
  72. /*u32_read |= (MISCIER_RB_MCU_INTO | MISCIER_RB_MCU_INT_EN);*/
  73. if (handle_ic_write(REG_SYSCON_MISCIER_ADDR, 4, (unsigned char *)&u32_read, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  74. return ERROR;
  75. return SUCCESS;
  76. }
  77. unsigned char disable_i2c_deglitch_3x(void)
  78. {
  79. unsigned int u32_buf = 0;
  80. unsigned char u8_retry = 3, u8_comfirm_time = 3;
  81. unsigned char u8_check = 0, u8_i = 0;
  82. unsigned int u32_i2c_deglitch = I2CENG_AUTO_I2C_DGF_MODE2 | I2CENG_DGF_OSC_AUTOSEL | I2CENG_AUTO_I2C_DGF_MODE | I2CENG_I2CS_DGFEN_DLY_NUM(6);
  83. /*check I2C mode*/
  84. while (u8_retry--) {
  85. u32_buf = 0;
  86. handle_ic_read(REG_FLASHCTL_DEVID_ADDR, 4, (unsigned char *)(&u32_buf), g_u8_drv_interface, I2C_WORD_MODE);
  87. if ((u32_buf & 0xFFFF0000) == 0xF3030000)
  88. u8_check++;
  89. else
  90. break;
  91. }
  92. if (u8_check == 3) {
  93. if (!g_u8_mute_i2c_err_log)
  94. DEBUGOUT("PDA2 OK\r\n");
  95. return SUCCESS;
  96. }
  97. u8_retry = 100;
  98. while (u8_retry--) {
  99. if (handle_ic_write(REG_I2CENG_ADDR, 4, (unsigned char *)(&u32_i2c_deglitch), I2C_PDA_MODE, I2C_WORD_MODE) == ERROR) {
  100. /*DEBUGOUT("[disable_i2c_deglitch_3x] handle_ic_write I2C NG!\r\n");*/
  101. if (!g_u8_mute_i2c_err_log)
  102. DEBUGOUT("[DI2CDG]-W");
  103. continue;
  104. }
  105. u8_check = 0;
  106. for (u8_i = 0; u8_i < u8_comfirm_time; u8_i++) {
  107. /*check I2C*/
  108. u32_buf = 0;
  109. if (handle_ic_read(REG_I2CENG_ADDR, 4, (unsigned char *)(&u32_buf), I2C_PDA_MODE, I2C_WORD_MODE) == ERROR) {
  110. /*DEBUGOUT("[disable_i2c_deglitch_3x] 2.handle_ic_read I2C NG!\r\n");*/
  111. if (!g_u8_mute_i2c_err_log)
  112. DEBUGOUT("[DI2CDG]-R");
  113. break;
  114. }
  115. if (u32_buf == u32_i2c_deglitch)
  116. u8_check++;
  117. else
  118. break;
  119. }
  120. if (u8_check == u8_comfirm_time)
  121. break;
  122. }
  123. if (!g_u8_mute_i2c_err_log)
  124. DEBUGOUT("\r\n");
  125. if (u8_retry == 0)
  126. return ERROR;
  127. u32_buf = GPIO_DEGLITCH_EN(3);
  128. if (handle_ic_write(REG_GPIO_DEGLITCH_ENABLE, 4, (unsigned char *)(&u32_buf), I2C_PDA_MODE, I2C_WORD_MODE) == ERROR) {
  129. DEBUGOUT("[DI2CDG_3x] 3.handle_ic_write I2C NG!\r\n");
  130. return ERROR;
  131. }
  132. /*Enable PDA2*/
  133. u32_buf = PDA2CTL_PDA2_EN | PDA2CTL_SIE2;
  134. if (handle_ic_write(REG_PDA2CTL_ADDR, 4, (unsigned char *)(&u32_buf), I2C_PDA_MODE, I2C_WORD_MODE) == ERROR) {
  135. DEBUGOUT("[DI2CDG_3x] 4.i2c_write_pda I2C NG!\r\n");
  136. return ERROR;
  137. }
  138. /*Disable PDA*/
  139. #if SELFTEST
  140. #ifdef __KERNEL__
  141. raydium_i2c_pda_set_address(RAYDIUM_PDA_I2CREG, DISABLE);
  142. #else
  143. sysfs_mode_control(ENABLE_PDA2);
  144. #endif
  145. #else
  146. i2c_set_pda_address(I2C_EID, 0x500006, I2C_PDA2_WORD_MODE);
  147. #endif
  148. return SUCCESS;
  149. }
  150. unsigned char stop_mcu_3x(unsigned char u8_is_tp_reset)
  151. {
  152. unsigned short u16_time_out = 100;
  153. unsigned int u32_read_data;
  154. unsigned int u32_write = 0;
  155. g_u8_mute_i2c_err_log = TRUE;
  156. if (u8_is_tp_reset) {
  157. gpio_touch_hw_reset();
  158. delay_ms(35);
  159. if (disable_i2c_deglitch_3x() == ERROR) {
  160. DEBUGOUT("[%s] 2.DI2CDG NG!\r\n", __func__);
  161. goto EXIT_ERROR;
  162. }
  163. }
  164. /*DEBUGOUT("[stop_mcu_3x] 1\r\n");*/
  165. /*Stop MCU*/
  166. /*memset(wData, 0, sizeof(wData));*/
  167. u32_write = (MCU_HOLD | SKIP_LOAD);
  168. if (handle_ic_write(REG_FLASHCTL_FLASH_STATE_REG_ADDR, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  169. goto EXIT_ERROR;
  170. u32_write = BLKRST_SW_RST;
  171. if (handle_ic_write(REG_SYSCON_BLKRST_ADDR, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  172. goto EXIT_ERROR;
  173. delay_ms(20);
  174. if (disable_i2c_deglitch_3x() == ERROR) {
  175. /*DEBUGOUT("[stop_mcu_3x] 3.disable_i2c_deglitch_3x NG!\r\n");*/
  176. DEBUGOUT("[%s] 3.DI2CDG NG!\r\n", __func__);
  177. goto EXIT_ERROR;
  178. }
  179. /*DEBUGOUT("[stop_mcu_3x] 2\r\n");*/
  180. if (handle_ic_read(REG_FLASHCTL_FLASH_STATE_REG_ADDR, 4, (unsigned char *)(&u32_read_data), g_u8_drv_interface, I2C_WORD_MODE) == ERROR) {
  181. DEBUGOUT("[%s] 4.Flash State NG!\r\n", __func__);
  182. goto EXIT_ERROR;
  183. }
  184. while ((u32_read_data & MCU_HOLD_STATUS) == 0 && u16_time_out-- > 0) {
  185. delay_ms(10);
  186. if (handle_ic_read(REG_FLASHCTL_FLASH_STATE_REG_ADDR, 4, (unsigned char *)(&u32_read_data), g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  187. goto EXIT_ERROR;
  188. #if ENABLE_WDT
  189. Chip_WWDT_Feed(LPC_WWDT);/* reload the Watchdog timer*/
  190. #endif
  191. }
  192. DEBUGOUT("Stop MCU=0x%X(0x%x)(%d)!!\r\n", u32_read_data, (u32_read_data & MCU_HOLD_STATUS), u16_time_out);
  193. if ((u32_read_data & MCU_HOLD_STATUS) == 0) {
  194. DEBUGOUT("[%s] 4.STOP MCU NG!\r\n", __func__);
  195. goto EXIT_ERROR;
  196. }
  197. g_u8_mute_i2c_err_log = FALSE;
  198. return SUCCESS;
  199. EXIT_ERROR:
  200. g_u8_mute_i2c_err_log = FALSE;
  201. return ERROR;
  202. }
  203. unsigned char hardware_reset_3x(unsigned char u8_enable_ic_block)
  204. {
  205. unsigned char u8_time_out = 200;
  206. DEBUGOUT("HW Reseting...\r\n");
  207. gpio_touch_hw_reset();
  208. delay_ms(100);
  209. g_u8_mute_i2c_err_log = TRUE;
  210. if (disable_i2c_deglitch_3x() == ERROR) {
  211. /*DEBUGOUT("[hardware_reset_3x] disable_i2c_deglitch_3x NG!\r\n");*/
  212. DEBUGOUT("[%s] DI2CDG NG!\r\n, __func__");
  213. g_u8_mute_i2c_err_log = FALSE;
  214. return ERROR;
  215. }
  216. g_u8_mute_i2c_err_log = FALSE;
  217. if (u8_enable_ic_block) {
  218. if (enable_ic_block_3x() == ERROR) {
  219. DEBUGOUT("HW Reset NG!!\r\n");
  220. return ERROR;
  221. }
  222. }
  223. while (u8_time_out--) {
  224. if (gpio_touch_int_pin_state_access())
  225. break;
  226. if (u8_time_out == 0)
  227. return ERROR;
  228. delay_ms(1);
  229. }
  230. return SUCCESS;
  231. }
  232. unsigned char set_fw_system_cmd_3x(unsigned int u32_sysm_cmd)
  233. {
  234. unsigned char u8_time_out = 100, u8_value;
  235. if (handle_ic_write(FW_SYS_CMD_ADDR, 4, (unsigned char *)&u32_sysm_cmd, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  236. return ERROR;
  237. /* Wait Test Command ready*/
  238. while (--u8_time_out) {
  239. delay_ms(1);
  240. if (handle_ic_read(FW_SYS_CMD_ADDR, 1, &u8_value, g_u8_drv_interface, I2C_BYTE_MODE) == ERROR)
  241. return ERROR;
  242. else if (u8_value == 0)
  243. break;
  244. }
  245. if (u8_time_out == 0)
  246. return ERROR;
  247. return SUCCESS;
  248. }
  249. unsigned char wait_fw_state_3x(unsigned int u32_addr, unsigned int u32_state, unsigned short u16_delay, unsigned short u16_retry)
  250. {
  251. unsigned int u32_read_data = 0;
  252. do {
  253. if (handle_ic_read(u32_addr, 4, (unsigned char *)(&u32_read_data), g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  254. return ERROR;
  255. delay_ms(u16_delay);
  256. u16_retry--;
  257. #if ENABLE_WDT
  258. /* reload the Watchdog timer*/
  259. Chip_WWDT_Feed(LPC_WWDT);
  260. #endif
  261. } while ((u32_read_data != u32_state) && (u16_retry != 0));
  262. if (u32_read_data != u32_state)
  263. return ERROR;
  264. return SUCCESS;
  265. }
  266. unsigned char wait_T2D_done_state_3x(unsigned int u32_addr, unsigned short u16_delay, unsigned short u16_retry)
  267. {
  268. unsigned int u32_read_data = 0;
  269. do {
  270. if (handle_ic_read(u32_addr, 4, (unsigned char *)(&u32_read_data), g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  271. return ERROR;
  272. /*DEBUGOUT("[T2DW] ready 0x%x\r\n", u32_read_data);*/
  273. delay_ms(u16_delay);
  274. u16_retry--;
  275. } while (((u32_read_data & 0x01) == 0) && (u16_retry != 0));
  276. if ((u32_read_data & 0x01) == 0)
  277. return ERROR;
  278. return SUCCESS;
  279. }
  280. unsigned char WriteToDriver_3x(unsigned char *p_u8_data, unsigned char u8_data_length)
  281. {
  282. unsigned int u32_write = 0;
  283. if (p_u8_data != NULL) {
  284. if (p_u8_data[0] == 0xFE) {
  285. g_u8_PAGE_ADDR = p_u8_data[1];
  286. return SUCCESS;
  287. }
  288. if (p_u8_data[0] == 0x35) {
  289. u32_write = ((0x00 << 24) | (0x00 << 16) | (p_u8_data[0] << 8) | g_u8_PAGE_ADDR);
  290. if (handle_ic_write(REG_T2D_CONFIG_2, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  291. return ERROR;
  292. u32_write = 0x0000015A;
  293. if (handle_ic_write(REG_T2D_CONFIG_3, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  294. return ERROR;
  295. }
  296. if (u8_data_length == 1) /*cmd mode*/
  297. u32_write = ((0x00 << 24) | (p_u8_data[1] << 16) | (p_u8_data[0] << 8) | g_u8_PAGE_ADDR);
  298. else if (u8_data_length == 2)
  299. u32_write = ((0x01 << 24) | (p_u8_data[1] << 16) | (p_u8_data[0] << 8) | g_u8_PAGE_ADDR);
  300. else if (u8_data_length == 5) {
  301. /* 2A 2B*/
  302. u32_write = ((0x01 << 24) | (p_u8_data[1] << 16) | (p_u8_data[0] << 8) | 0x00);
  303. if (handle_ic_write(REG_T2D_CONFIG_2, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  304. return ERROR;
  305. u32_write = 0x0000015A;
  306. if (handle_ic_write(REG_T2D_CONFIG_3, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  307. return ERROR;
  308. u32_write = ((0x01 << 24) | (p_u8_data[2] << 16) | (p_u8_data[0] << 8) | 0x01);
  309. if (handle_ic_write(REG_T2D_CONFIG_2, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  310. return ERROR;
  311. u32_write = 0x0000015A;
  312. if (handle_ic_write(REG_T2D_CONFIG_3, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  313. return ERROR;
  314. u32_write = ((0x01 << 24) | (p_u8_data[3] << 16) | (p_u8_data[0] << 8) | 0x02);
  315. if (handle_ic_write(REG_T2D_CONFIG_2, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  316. return ERROR;
  317. u32_write = 0x0000015A;
  318. if (handle_ic_write(REG_T2D_CONFIG_3, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  319. return ERROR;
  320. u32_write = ((0x01 << 24) | (p_u8_data[4] << 16) | (p_u8_data[0] << 8) | 0x03);
  321. if (handle_ic_write(REG_T2D_CONFIG_2, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  322. return ERROR;
  323. u32_write = 0x0000015A;
  324. if (handle_ic_write(REG_T2D_CONFIG_3, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  325. return ERROR;
  326. return SUCCESS;
  327. }
  328. if (handle_ic_write(REG_T2D_CONFIG_2, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  329. return ERROR;
  330. u32_write = 0x0000015A;
  331. if (handle_ic_write(REG_T2D_CONFIG_3, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  332. return ERROR;
  333. }
  334. return SUCCESS;
  335. }
  336. unsigned char ReadFromDriver_3x(unsigned char *p_u8_addr, unsigned char u8_read_len, unsigned char *p_u8_output_buf)
  337. {
  338. unsigned int u32_write = 0;
  339. if ((p_u8_addr[0] == 0xFE) || (p_u8_addr[0] == 0xFF) || (u8_read_len > 1)) {
  340. DEBUGOUT("[%s] no use\r\n", __func__);
  341. return FALSE;
  342. }
  343. u32_write = ((p_u8_addr[0] << 24) | (g_u8_PAGE_ADDR << 16) | (0x01 << 8) | 0x82);
  344. DEBUGOUT("read address 0x%x\r\n", u32_write);
  345. if (handle_ic_write(REG_T2D_R_CONFIG_1, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  346. return ERROR;
  347. if (handle_ic_read(REG_T2D_R_CONFIG_2, 4, p_u8_output_buf, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  348. return ERROR;
  349. DEBUGOUT("read data 0x%x\r\n", p_u8_output_buf[0]);
  350. return TRUE;
  351. }
  352. unsigned char WriteDriverByTouchMode(const unsigned char *p_u8_data, uint16_t u16DataLength)
  353. {
  354. unsigned short TotalDataLen = (p_u8_data[3] << 8) + p_u8_data[4] - 7;/*Valid data not include 7 byte header*/
  355. unsigned short u16_i = 0/*, u8_j = 0*/;
  356. unsigned char u8_CurCmdLen = 0;
  357. unsigned int u32_write = 0;
  358. /*
  359. * unsigned char u8_read_buf[4];
  360. * signed char i8_retry_cnt = 3;
  361. * unsigned char u8_error_flag = 0;
  362. */
  363. for (u16_i = 0; u16_i < (u16DataLength - 7) && u16_i < sizeof(g_u8_data_buf); u16_i++)
  364. g_u8_data_buf[u16_i] = p_u8_data[u16_i + 7];
  365. if (p_u8_data[0] == 0xF3 && p_u8_data[1] == 0x01) {
  366. /*Check Command type*/
  367. DEBUGOUT("Write Key\r\n");
  368. u32_write = 0x015AFABC;
  369. if (handle_ic_write(REG_T2D_CONFIG_2, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  370. return ERROR;
  371. u32_write = 0x0000015A;
  372. if (handle_ic_write(REG_T2D_CONFIG_3, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  373. return ERROR;
  374. if (p_u8_data[2] == 0x01 ||
  375. p_u8_data[2] == 0x10) { /*SPI short multiple command*/
  376. for (u16_i = 0; u16_i < TotalDataLen; u16_i += (u8_CurCmdLen + 1)) {
  377. u8_CurCmdLen = g_u8_data_buf[u16_i];
  378. /*
  379. * DEBUGOUT(" i = %d\r\n", u16_i);
  380. * if (u8_CurCmdLen == 2)
  381. * DEBUGOUT("-Before Parse Data[%d] = 0x%02X, 0x%02X, 0x%02X, %d\r\n", u16_i, g_u8_data_buf[u16_i], g_u8_data_buf[u16_i + 1], g_u8_data_buf[u16_i + 2], u8_CurCmdLen);
  382. * else if (u8_CurCmdLen == 3)
  383. * DEBUGOUT("-Before Parse Data[%d] = 0x%02X, 0x%02X, 0x%02X, 0x%02X, %d\r\n", u16_i, g_u8_data_buf[u16_i], g_u8_data_buf[u16_i + 1], g_u8_data_buf[u16_i + 2], g_u8_data_b uf[u16_i + 3], u8_CurCmdLen);
  384. * else
  385. * DEBUGOUT("-Before Parse Data[%d] = 0x%02X, 0x%02X, %d\r\n", u16_i, g_u8_data_buf[u16_i], g_u8_data_buf[u16_i + 1], u8_CurCmdLen);
  386. */
  387. /*Check is Delay command*/
  388. if (g_u8_data_buf[u16_i + 1] != 0xFF) { /*Check Command ID*/
  389. if (wait_T2D_done_state_3x(0x50001220, 1, 100) == ERROR) {
  390. DEBUGOUT("[T2DW] Check T2D idle Fail\r\n");
  391. return ERROR;
  392. }
  393. WriteToDriver_3x((unsigned char *)&g_u8_data_buf[u16_i + 1], u8_CurCmdLen);
  394. /*delay_ms(1);*/
  395. /*
  396. * i8_retry_cnt = 3;
  397. * while (i8_retry_cnt) {
  398. * u8_error_flag = 0;
  399. * if (ReadFromDriver_3x((unsigned char *)&g_u8_data_buf[u16_i + 1], u8_CurCmdLen - 1 , u8_read_buf)) {
  400. * for (u8_j = 0 ; u8_j < u8_CurCmdLen - 1 ; u8_j++) {
  401. * if (g_u8_data_buf[u16_i + 2 + u8_j] != u8_read_buf[u8_j]) {
  402. * u8_error_flag = 1;
  403. * DEBUGOUT("write address:%x\r\n", g_u8_data_buf[u16_i + 1]);
  404. * DEBUGOUT("Data:%d\r\n", g_u8_data_buf[u16_i + 2 + u8_j]);
  405. * DEBUGOUT("g_u8_spi_cmd_read_buf[%d]:%x\r\n", u8_j, u8_read_buf[u8_j]);
  406. * }
  407. * }
  408. * if (u8_error_flag == 0)
  409. * break;
  410. * if (u8_error_flag == 1)
  411. * i8_retry_cnt--;
  412. * if (i8_retry_cnt == 0) {
  413. * DEBUGOUT("i8_retry_cnt error!\r\n");
  414. * return ERROR;
  415. * }
  416. * } else
  417. * break;
  418. * }
  419. */
  420. } else {
  421. DEBUGOUT("Delay\r\n");
  422. delay_ms(g_u8_data_buf[u16_i + 2]);
  423. }
  424. }
  425. } else {
  426. DEBUGOUT("[%s] command type not support\r\n", __func__);
  427. return ERROR;
  428. }
  429. u32_write = 0x0100FABC;
  430. if (handle_ic_write(REG_T2D_CONFIG_2, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  431. return ERROR;
  432. u32_write = 0x0000015A;
  433. if (handle_ic_write(REG_T2D_CONFIG_3, 4, (unsigned char *)&u32_write, g_u8_drv_interface, I2C_WORD_MODE) == ERROR)
  434. return ERROR;
  435. }
  436. return SUCCESS;
  437. }