gt1x_update.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250
  1. /* drivers/input/touchscreen/gt1x_update.c
  2. *
  3. * 2010 - 2014 Goodix Technology.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be a reference
  11. * to you, when you are integrating the GOODiX's CTP IC into your system,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * Version: 1.0
  17. * Revision Record:
  18. * V1.0: first release. 2014/09/28.
  19. */
  20. #include <linux/interrupt.h>
  21. #include <linux/i2c.h>
  22. #include <linux/sched.h>
  23. #include <linux/kthread.h>
  24. #include <linux/wait.h>
  25. #include <linux/time.h>
  26. #include <linux/delay.h>
  27. #include <linux/namei.h>
  28. #include <linux/mount.h>
  29. #include <linux/uaccess.h>
  30. #include "gt1x_config.h"
  31. #include "include/gt1x_tpd_common.h"
  32. #if defined(CONFIG_GTP_HOTKNOT) || defined(CONFIG_GTP_HEADER_FW_UPDATE)
  33. #include "gt1x_firmware.h"
  34. #endif
  35. #define UPDATE_FILE_PATH_1 "/data/_goodix_update_.bin"
  36. #define UPDATE_FILE_PATH_2 "/sdcard/_goodix_update_.bin"
  37. #define CONFIG_FILE_PATH_1 "/data/_gt1x_config_.cfg"
  38. #define CONFIG_FILE_PATH_2 "/sdcard/_gt1x_config_.cfg"
  39. #define FOUND_FW_PATH_1 0x01
  40. #define FOUND_FW_PATH_2 0x02
  41. #define FOUND_CFG_PATH_1 0x04
  42. #define FOUND_CFG_PATH_2 0x08
  43. #define PACK_SIZE 256
  44. /*hardware register define*/
  45. #define _bRW_MISCTL__SRAM_BANK 0x4048
  46. #define _bRW_MISCTL__MEM_CD_EN 0x4049
  47. #define _bRW_MISCTL__CACHE_EN 0x404B
  48. #define _bRW_MISCTL__TMR0_EN 0x40B0
  49. #define _rRW_MISCTL__SWRST_B0_ 0x4180
  50. #define _bWO_MISCTL__CPU_SWRST_PULSE 0x4184
  51. #define _rRW_MISCTL__BOOTCTL_B0_ 0x4190
  52. #define _rRW_MISCTL__BOOT_OPT_B0_ 0x4218
  53. #define _rRW_MISCTL__BOOT_CTL_ 0x5094
  54. #define _bRW_MISCTL__DSP_MCU_PWR_ 0x4010
  55. #define _bRW_MISCTL__PATCH_AREA_EN_ 0x404D
  56. /*
  57. 1. firmware structure
  58. header: 128b
  59. offset size content
  60. 0 4 firmware length
  61. 4 2 checksum
  62. 6 6 target MASK name
  63. 12 3 target MASK version
  64. 15 6 TP subsystem PID
  65. 21 3 TP subsystem version
  66. 24 1 subsystem count
  67. 25 1 chip type 0x91: GT1X, 0x92: GT2X
  68. 26 6 reserved
  69. 32 8 subsystem info[0]
  70. 32 8 subsystem info[1]
  71. .....
  72. 120 8 subsystem info[11]
  73. body: followed header
  74. 128 N0 subsystem[0]
  75. 128+N0 N1 subsystem[1]
  76. ....
  77. 2. subsystem info structure
  78. offset size content
  79. 0 1 subsystem type
  80. 1 2 subsystem length
  81. 3 2 stored address in flash addr = value * 256
  82. 5 3 reserved
  83. */
  84. #define FW_HEAD_SIZE 128
  85. #define FW_HEAD_SUBSYSTEM_INFO_SIZE 8
  86. #define FW_HEAD_OFFSET_SUBSYSTEM_INFO_BASE 32
  87. #define FW_SECTION_TYPE_SS51_ISP 0x01
  88. #define FW_SECTION_TYPE_SS51_PATCH 0x02
  89. #define FW_SECTION_TYPE_SS51_PATCH_OVERLAY 0x03
  90. #define FW_SECTION_TYPE_DSP 0x04
  91. #define FW_SECTION_TYPE_HOTKNOT 0x05
  92. #define FW_SECTION_TYPE_GESTURE 0x06
  93. #define FW_SECTION_TYPE_GESTURE_OVERLAY 0x07
  94. #define FW_SECTION_TYPE_FLASHLESS_FAST_POWER 0x08
  95. #define UPDATE_TYPE_HEADER 0
  96. #define UPDATE_TYPE_FILE 1
  97. #define UPDATE_STATUS_IDLE 0
  98. #define UPDATE_STATUS_RUNNING 1
  99. struct fw_subsystem_info {
  100. int type;
  101. int length;
  102. u32 address;
  103. int offset;
  104. };
  105. #pragma pack(1)
  106. struct fw_info {
  107. u32 length;
  108. u16 checksum;
  109. u8 target_mask[6];
  110. u8 target_mask_version[3];
  111. u8 pid[6];
  112. u8 version[3];
  113. u8 subsystem_count;
  114. u8 chip_type;
  115. u8 reserved[6];
  116. struct fw_subsystem_info subsystem[12];
  117. };
  118. #pragma pack()
  119. struct fw_update_info update_info = {
  120. .status = UPDATE_STATUS_IDLE,
  121. .progress = 0,
  122. .max_progress = 9
  123. };
  124. /**
  125. * @return: return 0 if success, otherwise return a negative number
  126. * which contains the error code.
  127. */
  128. s32 gt1x_check_fs_mounted(char *path_name)
  129. {
  130. struct path root_path;
  131. struct path path;
  132. s32 err;
  133. err = kern_path("/", LOOKUP_FOLLOW, &root_path);
  134. if (err)
  135. return ERROR_PATH;
  136. err = kern_path(path_name, LOOKUP_FOLLOW, &path);
  137. if (err) {
  138. err = ERROR_PATH;
  139. goto check_fs_fail;
  140. }
  141. if (path.mnt->mnt_sb == root_path.mnt->mnt_sb)
  142. err = ERROR_PATH;
  143. else
  144. err = 0;
  145. path_put(&path);
  146. check_fs_fail:
  147. path_put(&root_path);
  148. return err;
  149. }
  150. int gt1x_i2c_write_with_readback(u16 addr, u8 *buffer, int length)
  151. {
  152. u8 buf[100];
  153. int ret = gt1x_i2c_write(addr, buffer, length);
  154. if (ret)
  155. return ret;
  156. ret = gt1x_i2c_read(addr, buf, length);
  157. if (ret)
  158. return ret;
  159. if (memcmp(buf, buffer, length))
  160. return ERROR_CHECK;
  161. return 0;
  162. }
  163. #define getU32(a) ((u32)getUint((u8 *)(a), 4))
  164. #define getU16(a) ((u16)getUint((u8 *)(a), 2))
  165. u32 getUint(u8 *buffer, int len)
  166. {
  167. u32 num = 0;
  168. int i;
  169. for (i = 0; i < len; i++) {
  170. num <<= 8;
  171. num += buffer[i];
  172. }
  173. return num;
  174. }
  175. #ifndef CONFIG_GTP_HEADER_FW_UPDATE
  176. static int gt1x_search_update_files(void)
  177. {
  178. int retry = 20 * 2; /*ait 10s(max) if fs is not ready*/
  179. struct file *pfile = NULL;
  180. mm_segment_t old_fs;
  181. int found = 0;
  182. old_fs = get_fs();
  183. set_fs(KERNEL_DS);
  184. GTP_INFO("Search firmware file...");
  185. while (retry-- > 0) {
  186. msleep(500);
  187. /*check if rootfs is ready*/
  188. if (gt1x_check_fs_mounted("/data")) {
  189. GTP_ERROR("filesystem is not ready!");
  190. continue;
  191. }
  192. /*search firmware*/
  193. pfile = filp_open(UPDATE_FILE_PATH_1, O_RDONLY, 0);
  194. if (IS_ERR(pfile)) {
  195. pfile = filp_open(UPDATE_FILE_PATH_2, O_RDONLY, 0);
  196. if (!IS_ERR(pfile))
  197. found |= FOUND_FW_PATH_2;
  198. } else {
  199. found |= FOUND_FW_PATH_1;
  200. }
  201. if (!IS_ERR(pfile))
  202. filp_close(pfile, NULL);
  203. /*search config file*/
  204. pfile = filp_open(CONFIG_FILE_PATH_1, O_RDONLY, 0);
  205. if (IS_ERR(pfile)) {
  206. pfile = filp_open(CONFIG_FILE_PATH_2, O_RDONLY, 0);
  207. if (!IS_ERR(pfile))
  208. found |= FOUND_CFG_PATH_2;
  209. } else {
  210. found |= FOUND_CFG_PATH_1;
  211. }
  212. if (!IS_ERR(pfile))
  213. filp_close(pfile, NULL);
  214. if (found)
  215. break;
  216. GTP_INFO("Not found firmware or config file, retry.");
  217. }
  218. set_fs(old_fs);
  219. return found;
  220. }
  221. #endif
  222. int gt1x_auto_update_proc(void *data)
  223. {
  224. #ifdef CONFIG_GTP_HEADER_FW_UPDATE
  225. GTP_INFO("Start auto update thread...");
  226. gt1x_update_firmware(NULL);
  227. #else
  228. int ret;
  229. char *filename;
  230. u8 config[GTP_CONFIG_MAX_LENGTH] = { 0 };
  231. GTP_INFO("Start auto update thread...");
  232. ret = gt1x_search_update_files();
  233. if (ret & (FOUND_FW_PATH_1 | FOUND_FW_PATH_2)) {
  234. if (ret & FOUND_FW_PATH_1)
  235. filename = UPDATE_FILE_PATH_1;
  236. else
  237. filename = UPDATE_FILE_PATH_2;
  238. gt1x_update_firmware(filename);
  239. }
  240. if (ret & (FOUND_CFG_PATH_1 | FOUND_CFG_PATH_2)) {
  241. if (ret & FOUND_CFG_PATH_1)
  242. filename = CONFIG_FILE_PATH_1;
  243. else
  244. filename = CONFIG_FILE_PATH_2;
  245. if (gt1x_parse_config(filename, config) > 0) {
  246. if (gt1x_i2c_write(GTP_REG_CONFIG_DATA, config, GTP_CONFIG_MAX_LENGTH))
  247. GTP_ERROR("Update config failed!");
  248. else
  249. GTP_INFO("Update config successfully!");
  250. }
  251. }
  252. #endif
  253. return 0;
  254. }
  255. void gt1x_enter_update_mode(void)
  256. {
  257. #ifdef CONFIG_GTP_ESD_PROTECT
  258. gt1x_esd_switch(SWITCH_OFF);
  259. #endif
  260. gt1x_irq_disable();
  261. }
  262. int gt1x_update_prepare(char *filename)
  263. {
  264. int ret = 0;
  265. int retry = 5;
  266. if (filename == NULL) {
  267. #ifdef CONFIG_GTP_HEADER_FW_UPDATE
  268. update_info.fw_name = NULL;
  269. update_info.update_type = UPDATE_TYPE_HEADER;
  270. update_info.fw_data = gt1x_default_FW;
  271. update_info.fw_length = sizeof(gt1x_default_FW);
  272. #else
  273. GTP_ERROR("No Fw in .h file!");
  274. return ERROR_FW;
  275. #endif
  276. } else {
  277. GTP_INFO("Firmware: %s", filename);
  278. update_info.old_fs = get_fs();
  279. set_fs(KERNEL_DS);
  280. update_info.fw_name = filename;
  281. update_info.update_type = UPDATE_TYPE_FILE;
  282. update_info.fw_file = filp_open(update_info.fw_name, O_RDONLY, 0);
  283. if (IS_ERR(update_info.fw_file)) {
  284. GTP_ERROR("Open update file(%s) error!", update_info.fw_name);
  285. set_fs(update_info.old_fs);
  286. return ERROR_FILE;
  287. }
  288. update_info.fw_file->f_op->llseek(update_info.fw_file, 0, SEEK_SET);
  289. update_info.fw_length = update_info.fw_file->f_op->llseek(update_info.fw_file, 0, SEEK_END);
  290. }
  291. while (retry > 0) {
  292. retry--;
  293. update_info.firmware = kzalloc(sizeof(struct fw_info), GFP_KERNEL);
  294. if (update_info.firmware == NULL) {
  295. GTP_INFO("Alloc %d bytes memory fail.", (int)(sizeof(struct fw_info)));
  296. continue;
  297. } else {
  298. GTP_INFO("Alloc %d bytes memory success.", (int)(sizeof(struct fw_info)));
  299. break;
  300. }
  301. }
  302. if (retry <= 0) {
  303. ret = ERROR_RETRY;
  304. goto gt1x_update_pre_fail1;
  305. }
  306. retry = 5;
  307. while (retry > 0) {
  308. update_info.buffer = kzalloc(1024 * 4, GFP_KERNEL);
  309. if (update_info.buffer == NULL) {
  310. GTP_ERROR("Alloc %d bytes memory fail.", 1024 * 4);
  311. continue;
  312. } else {
  313. GTP_INFO("Alloc %d bytes memory success.", 1024 * 4);
  314. break;
  315. }
  316. }
  317. if (retry <= 0) {
  318. ret = ERROR_RETRY;
  319. goto gt1x_update_pre_fail0;
  320. }
  321. return 0;
  322. gt1x_update_pre_fail0:
  323. kfree(update_info.firmware);
  324. gt1x_update_pre_fail1:
  325. filp_close(update_info.fw_file, NULL);
  326. return ret;
  327. }
  328. /**
  329. * @return: return a pointer pointed at the content of firmware
  330. * if success, otherwise return NULL.
  331. */
  332. u8 *gt1x_get_fw_data(u32 offset, int length)
  333. {
  334. int ret;
  335. if (update_info.update_type == UPDATE_TYPE_FILE) {
  336. update_info.fw_file->f_op->llseek(update_info.fw_file, offset, SEEK_SET);
  337. ret =
  338. update_info.fw_file->f_op->read(update_info.fw_file, (char *)update_info.buffer, length,
  339. &update_info.fw_file->f_pos);
  340. if (ret < 0) {
  341. GTP_ERROR("Read data error!");
  342. return NULL;
  343. }
  344. return update_info.buffer;
  345. } else {
  346. return &update_info.fw_data[offset];
  347. }
  348. }
  349. int gt1x_check_firmware(void)
  350. {
  351. u16 checksum;
  352. u16 checksum_in_header;
  353. u8 *p;
  354. struct fw_info *firmware;
  355. int i;
  356. int offset;
  357. /*compare file length with the length field in the firmware header*/
  358. if (update_info.fw_length < FW_HEAD_SIZE) {
  359. GTP_ERROR("Bad firmware!(file length: %d)", update_info.fw_length);
  360. return ERROR_CHECK;
  361. }
  362. p = gt1x_get_fw_data(0, 6);
  363. if (p == NULL)
  364. return ERROR_FW;
  365. if (getU32(p) + 6 != update_info.fw_length) {
  366. GTP_ERROR("Bad firmware!(file length: %d, header define: %d)", update_info.fw_length, getU32(p));
  367. return ERROR_CHECK;
  368. }
  369. /*check firmware's checksum*/
  370. checksum_in_header = getU16(&p[4]);
  371. checksum = 0;
  372. for (i = 6; i < update_info.fw_length; i++) {
  373. p = gt1x_get_fw_data(i, 1);
  374. if (p == NULL)
  375. return ERROR_FW;
  376. checksum += p[0];
  377. }
  378. if (checksum != checksum_in_header) {
  379. GTP_ERROR("Bad firmware!(checksum: 0x%04X, header define: 0x%04X)", checksum, checksum_in_header);
  380. return ERROR_CHECK;
  381. }
  382. /*parse firmware*/
  383. p = gt1x_get_fw_data(0, FW_HEAD_SIZE);
  384. if (p == NULL)
  385. return ERROR_FW;
  386. memcpy((u8 *) update_info.firmware, p, FW_HEAD_SIZE - 8 * 12);
  387. update_info.firmware->pid[5] = 0;
  388. p = &p[FW_HEAD_OFFSET_SUBSYSTEM_INFO_BASE];
  389. firmware = update_info.firmware;
  390. offset = FW_HEAD_SIZE;
  391. for (i = 0; i < firmware->subsystem_count; i++) {
  392. firmware->subsystem[i].type = p[i * FW_HEAD_SUBSYSTEM_INFO_SIZE];
  393. firmware->subsystem[i].length = getU16(&p[i * FW_HEAD_SUBSYSTEM_INFO_SIZE + 1]);
  394. firmware->subsystem[i].address = getU16(&p[i * FW_HEAD_SUBSYSTEM_INFO_SIZE + 3]) * 256;
  395. firmware->subsystem[i].offset = offset;
  396. offset += firmware->subsystem[i].length;
  397. }
  398. /*print update information*/
  399. GTP_INFO("Update type: %s", update_info.update_type == UPDATE_TYPE_HEADER ? "Header" : "File");
  400. GTP_INFO("Firmware length: %d", update_info.fw_length);
  401. GTP_INFO("Firmware product: GT%s", update_info.firmware->pid);
  402. GTP_INFO("Firmware patch: %02X%02X%02X", update_info.firmware->version[0], update_info.firmware->version[1],
  403. update_info.firmware->version[2]);
  404. GTP_INFO("Firmware chip: 0x%02X", update_info.firmware->chip_type);
  405. GTP_INFO("Subsystem count: %d", update_info.firmware->subsystem_count);
  406. for (i = 0; i < update_info.firmware->subsystem_count; i++) {
  407. GTP_INFO("------------------------------------------");
  408. GTP_INFO("Subsystem: %d", i);
  409. GTP_INFO("Type: %d", update_info.firmware->subsystem[i].type);
  410. GTP_INFO("Length: %d", update_info.firmware->subsystem[i].length);
  411. GTP_INFO("Address: 0x%08X", update_info.firmware->subsystem[i].address);
  412. GTP_INFO("Offset: %d", update_info.firmware->subsystem[i].offset);
  413. }
  414. return 0;
  415. }
  416. int gt1x_update_judge(void)
  417. {
  418. int ret;
  419. u8 reg_val[1];
  420. u8 retry = 3;
  421. struct gt1x_version_info ver_info;
  422. struct gt1x_version_info fw_ver_info;
  423. fw_ver_info.mask_id = (update_info.firmware->target_mask_version[0] << 16)
  424. | (update_info.firmware->target_mask_version[1] << 8)
  425. | (update_info.firmware->target_mask_version[2]);
  426. fw_ver_info.patch_id = (update_info.firmware->version[0] << 16)
  427. | (update_info.firmware->version[1] << 8)
  428. | (update_info.firmware->version[2]);
  429. memcpy(fw_ver_info.product_id, update_info.firmware->pid, 4);
  430. fw_ver_info.product_id[4] = 0;
  431. /* check register 0x41E4 */
  432. do {
  433. ret = gt1x_i2c_read_dbl_check(0x41E4, reg_val, 1);
  434. if (ret != 0) { /* read reg failed */
  435. gt1x_reset_guitar();
  436. } else {
  437. break;
  438. }
  439. }
  440. while (--retry)
  441. ;
  442. if (reg_val[0] != 0xBE) {
  443. GTP_ERROR("check 0x41E4 failed, force update!!!");
  444. return 0;
  445. }
  446. ret = gt1x_read_version(&ver_info);
  447. if (ret < 0) {
  448. GTP_ERROR("Get IC's version info failed, force update!!!");
  449. return 0;
  450. }
  451. if (memcmp(fw_ver_info.product_id, ver_info.product_id, 4)) {
  452. GTP_ERROR("Product id is not match!");
  453. return ERROR_CHECK;
  454. }
  455. if ((fw_ver_info.mask_id & 0xFFFFFF00) != (ver_info.mask_id & 0xFFFFFF00)) {
  456. GTP_ERROR("Mask id is not match!");
  457. return ERROR_CHECK;
  458. }
  459. if (fw_ver_info.patch_id <= ver_info.patch_id) {
  460. GTP_ERROR("The version of the fw is not high than the IC's!");
  461. return ERROR_CHECK;
  462. }
  463. return 0;
  464. }
  465. u16 gt1x_calc_checksum(u8 *fw, u32 length)
  466. {
  467. u32 i = 0;
  468. u32 checksum = 0;
  469. for (i = 0; i < length; i += 2) {
  470. checksum += (((int)fw[i]) << 8);
  471. checksum += fw[i + 1];
  472. }
  473. checksum &= 0xFFFF;
  474. return checksum;
  475. }
  476. int gt1x_recall_check(u8 *chk_src, u16 start_addr, u16 chk_length)
  477. {
  478. u8 rd_buf[PACK_SIZE];
  479. s32 ret = 0;
  480. u16 len = 0;
  481. u32 compared_length = 0;
  482. while (chk_length > 0) {
  483. len = (chk_length > PACK_SIZE ? PACK_SIZE : chk_length);
  484. ret = gt1x_i2c_read(start_addr + compared_length, rd_buf, len);
  485. if (ret) {
  486. GTP_ERROR("recall i2c error,exit!");
  487. return ret;
  488. }
  489. if (memcmp(rd_buf, &chk_src[compared_length], len)) {
  490. GTP_ERROR("Recall frame not equal(addr: 0x%04X)", start_addr + compared_length);
  491. GTP_DEBUG("chk_src array:");
  492. GTP_DEBUG_ARRAY(&chk_src[compared_length], len);
  493. GTP_DEBUG("recall array:");
  494. GTP_DEBUG_ARRAY(rd_buf, len);
  495. return ERROR_CHECK;
  496. }
  497. chk_length -= len;
  498. compared_length += len;
  499. }
  500. GTP_DEBUG("Recall check %d bytes(address: 0x%04X) success.", compared_length, start_addr);
  501. return 0;
  502. }
  503. int gt1x_run_ss51_isp(u8 *ss51_isp, int length)
  504. {
  505. int ret;
  506. u8 buffer[10];
  507. ret = gt1x_hold_ss51_dsp();
  508. if (ret)
  509. return ret;
  510. /*select bank4*/
  511. buffer[0] = 0x04;
  512. ret = gt1x_i2c_write_with_readback(_bRW_MISCTL__SRAM_BANK, buffer, 1);
  513. if (ret) {
  514. GTP_ERROR("select bank4 fail.");
  515. return ret;
  516. }
  517. /*enable patch area access*/
  518. buffer[0] = 0x01;
  519. ret = gt1x_i2c_write_with_readback(_bRW_MISCTL__PATCH_AREA_EN_, buffer, 1);
  520. if (ret) {
  521. GTP_ERROR("enable patch area access fail!");
  522. return ret;
  523. }
  524. GTP_INFO("ss51_isp length: %d, checksum: 0x%04X", length, gt1x_calc_checksum(ss51_isp, length));
  525. /*load ss51 isp*/
  526. ret = gt1x_i2c_write(0xC000, ss51_isp, length);
  527. if (ret) {
  528. GTP_ERROR("load ss51 isp fail!");
  529. return ret;
  530. }
  531. /*recall compare*/
  532. ret = gt1x_recall_check(ss51_isp, 0xC000, length);
  533. if (ret) {
  534. GTP_ERROR("recall check ss51 isp fail!");
  535. return ret;
  536. }
  537. memset(buffer, 0xAA, 10);
  538. ret = gt1x_i2c_write_with_readback(0x8140, buffer, 10);
  539. /*disable patch area access*/
  540. buffer[0] = 0x00;
  541. ret = gt1x_i2c_write_with_readback(_bRW_MISCTL__PATCH_AREA_EN_, buffer, 1);
  542. if (ret) {
  543. GTP_ERROR("disable patch area access fail!");
  544. return ret;
  545. }
  546. /*set 0x8006*/
  547. memset(buffer, 0x55, 8);
  548. ret = gt1x_i2c_write_with_readback(0x8006, buffer, 8);
  549. if (ret) {
  550. GTP_ERROR("set 0x8006[0~7] 0x55 fail!");
  551. return ret;
  552. }
  553. /*release ss51*/
  554. buffer[0] = 0x08;
  555. ret = gt1x_i2c_write_with_readback(_rRW_MISCTL__SWRST_B0_, buffer, 1);
  556. if (ret) {
  557. GTP_ERROR("release ss51 fail!");
  558. return ret;
  559. }
  560. msleep(100);
  561. /*check run state*/
  562. ret = gt1x_i2c_read(0x8006, buffer, 2);
  563. if (ret) {
  564. GTP_ERROR("read 0x8006 fail!");
  565. return ret;
  566. }
  567. if (!(buffer[0] == 0xAA && buffer[1] == 0xBB)) {
  568. GTP_ERROR("ERROR: isp is not running! 0x8006: %02X %02X", buffer[0], buffer[1]);
  569. return ERROR_CHECK;
  570. }
  571. return 0;
  572. }
  573. int gt1x_burn_subsystem(struct fw_subsystem_info *subsystem)
  574. {
  575. int block_len;
  576. u16 checksum;
  577. int burn_len = 0;
  578. u16 cur_addr;
  579. u32 length = subsystem->length;
  580. u8 buffer[10];
  581. int ret;
  582. int wait_time;
  583. int burn_state;
  584. int retry = 5;
  585. u8 *fw;
  586. GTP_INFO("Subsystem: %d", subsystem->type);
  587. GTP_INFO("Length: %d", subsystem->length);
  588. GTP_INFO("Address: 0x%08X", subsystem->address);
  589. while (length > 0 && retry > 0) {
  590. retry--;
  591. block_len = length > 1024 * 4 ? 1024 * 4 : length;
  592. GTP_INFO("Burn block ==> length: %d, address: 0x%08X", block_len, subsystem->address + burn_len);
  593. fw = gt1x_get_fw_data(subsystem->offset + burn_len, block_len);
  594. if (fw == NULL)
  595. return ERROR_FW;
  596. cur_addr = ((subsystem->address + burn_len) >> 8);
  597. checksum = 0;
  598. checksum += block_len;
  599. checksum += cur_addr;
  600. checksum += gt1x_calc_checksum(fw, block_len);
  601. checksum = (0 - checksum);
  602. buffer[0] = ((block_len >> 8) & 0xFF);
  603. buffer[1] = (block_len & 0xFF);
  604. buffer[2] = ((cur_addr >> 8) & 0xFF);
  605. buffer[3] = (cur_addr & 0xFF);
  606. ret = gt1x_i2c_write_with_readback(0x8100, buffer, 4);
  607. if (ret) {
  608. GTP_ERROR("write length & address fail!");
  609. continue;
  610. }
  611. ret = gt1x_i2c_write(0x8100 + 4, fw, block_len);
  612. if (ret) {
  613. GTP_ERROR("write fw data fail!");
  614. continue;
  615. }
  616. ret = gt1x_recall_check(fw, 0x8100 + 4, block_len);
  617. if (ret)
  618. continue;
  619. buffer[0] = ((checksum >> 8) & 0xFF);
  620. buffer[1] = (checksum & 0xFF);
  621. ret = gt1x_i2c_write_with_readback(0x8100 + 4 + block_len, buffer, 2);
  622. if (ret) {
  623. GTP_ERROR("write checksum fail!");
  624. continue;
  625. }
  626. buffer[0] = 0;
  627. ret = gt1x_i2c_write_with_readback(0x8022, buffer, 1);
  628. if (ret) {
  629. GTP_ERROR("clear control flag fail!");
  630. continue;
  631. }
  632. buffer[0] = subsystem->type;
  633. buffer[1] = subsystem->type;
  634. ret = gt1x_i2c_write_with_readback(0x8020, buffer, 2);
  635. if (ret) {
  636. GTP_ERROR("write subsystem type fail!");
  637. continue;
  638. }
  639. burn_state = ERROR;
  640. wait_time = 200;
  641. while (wait_time > 0) {
  642. wait_time--;
  643. msleep(20);
  644. ret = gt1x_i2c_read(0x8022, buffer, 1);
  645. if (ret)
  646. continue;
  647. if (buffer[0] == 0xAA) {
  648. GTP_INFO("burning.....");
  649. continue;
  650. } else if (buffer[0] == 0xDD) {
  651. GTP_ERROR("checksum error!");
  652. break;
  653. } else if (buffer[0] == 0xBB) {
  654. GTP_INFO("burning success.");
  655. burn_state = 0;
  656. break;
  657. } else if (buffer[0] == 0xCC) {
  658. GTP_ERROR("burning failed!");
  659. break;
  660. }
  661. GTP_INFO("unknown state!(0x8022: 0x%02X)", buffer[0]);
  662. }
  663. if (!burn_state) {
  664. length -= block_len;
  665. burn_len += block_len;
  666. retry = 5;
  667. }
  668. }
  669. if (length == 0)
  670. return 0;
  671. else
  672. return ERROR_RETRY;
  673. }
  674. int gt1x_read_flash(u32 addr, int length)
  675. {
  676. int wait_time;
  677. int ret = 0;
  678. u8 buffer[4];
  679. u16 read_addr = (addr >> 8);
  680. GTP_INFO("Read flash: 0x%04X, length: %d", addr, length);
  681. buffer[0] = 0;
  682. ret = gt1x_i2c_write_with_readback(0x8022, buffer, 1);
  683. buffer[0] = ((length >> 8) & 0xFF);
  684. buffer[1] = (length & 0xFF);
  685. buffer[2] = ((read_addr >> 8) & 0xFF);
  686. buffer[3] = (read_addr & 0xFF);
  687. ret |= gt1x_i2c_write_with_readback(0x8100, buffer, 4);
  688. buffer[0] = 0xAA;
  689. buffer[1] = 0xAA;
  690. ret |= gt1x_i2c_write(0x8020, buffer, 2);
  691. if (ret) {
  692. GTP_ERROR("Error occurred.");
  693. return ret;
  694. }
  695. wait_time = 200;
  696. while (wait_time > 0) {
  697. wait_time--;
  698. msleep(20);
  699. ret = gt1x_i2c_read(0x8022, buffer, 1);
  700. if (ret)
  701. continue;
  702. if (buffer[0] == 0xBB) {
  703. GTP_INFO("Read success(addr: 0x%04X, length: %d)", addr, length);
  704. break;
  705. }
  706. }
  707. if (wait_time == 0) {
  708. GTP_ERROR("Read Flash FAIL!");
  709. return ERROR_RETRY;
  710. }
  711. return 0;
  712. }
  713. int gt1x_check_subsystem_in_flash(struct fw_subsystem_info *subsystem)
  714. {
  715. int block_len;
  716. int checked_len = 0;
  717. u32 length = subsystem->length;
  718. int ret;
  719. int check_state = 0;
  720. int retry = 5;
  721. u8 *fw;
  722. GTP_INFO("Subsystem: %d", subsystem->type);
  723. GTP_INFO("Length: %d", subsystem->length);
  724. GTP_INFO("Address: 0x%08X", subsystem->address);
  725. while (length > 0) {
  726. block_len = length > 1024 * 4 ? 1024 * 4 : length;
  727. GTP_INFO("Check block ==> length: %d, address: 0x%08X", block_len, subsystem->address + checked_len);
  728. fw = gt1x_get_fw_data(subsystem->offset + checked_len, block_len);
  729. if (fw == NULL)
  730. return ERROR_FW;
  731. ret = gt1x_read_flash(subsystem->address + checked_len, block_len);
  732. if (ret)
  733. check_state |= ret;
  734. ret = gt1x_recall_check(fw, 0x8100, block_len);
  735. if (ret) {
  736. GTP_ERROR("Block in flash is broken!");
  737. check_state |= ret;
  738. }
  739. length -= block_len;
  740. checked_len += block_len;
  741. retry = 5;
  742. }
  743. if (check_state)
  744. GTP_ERROR("Subsystem in flash is broken!");
  745. else
  746. GTP_INFO("Subsystem in flash is correct!");
  747. return check_state;
  748. }
  749. void gt1x_update_cleanup(void)
  750. {
  751. if (update_info.update_type == UPDATE_TYPE_FILE) {
  752. if (update_info.fw_file != NULL) {
  753. filp_close(update_info.fw_file, NULL);
  754. update_info.fw_file = NULL;
  755. }
  756. set_fs(update_info.old_fs);
  757. }
  758. if (update_info.buffer != NULL) {
  759. kfree(update_info.buffer);
  760. update_info.buffer = NULL;
  761. }
  762. if (update_info.firmware != NULL) {
  763. kfree(update_info.firmware);
  764. update_info.firmware = NULL;
  765. }
  766. }
  767. int gt1x_update_firmware(char *filename)
  768. {
  769. int i = 0;
  770. int ret = 0;
  771. u8 *p;
  772. if (update_info.status != UPDATE_STATUS_IDLE) {
  773. GTP_ERROR("Update process is running!");
  774. return ERROR;
  775. }
  776. update_info.status = UPDATE_STATUS_RUNNING;
  777. update_info.max_progress = 9;
  778. update_info.progress = 0;
  779. gt1x_enter_update_mode();
  780. ret = gt1x_update_prepare(filename);
  781. if (ret) {
  782. update_info.status = UPDATE_STATUS_IDLE;
  783. return ret;
  784. }
  785. update_info.progress = 1;
  786. ret = gt1x_check_firmware();
  787. if (ret)
  788. goto gt1x_update_exit;
  789. update_info.progress = 2;
  790. ret = gt1x_update_judge();
  791. if (ret)
  792. goto gt1x_update_exit;
  793. update_info.progress = 3;
  794. p = gt1x_get_fw_data(update_info.firmware->subsystem[0].offset, update_info.firmware->subsystem[0].length);
  795. if (p == NULL) {
  796. GTP_ERROR("get isp fail");
  797. ret = ERROR_FW;
  798. goto gt1x_update_exit;
  799. }
  800. update_info.progress = 4;
  801. ret = gt1x_run_ss51_isp(p, update_info.firmware->subsystem[0].length);
  802. if (ret) {
  803. GTP_ERROR("run isp fail");
  804. goto gt1x_update_exit;
  805. }
  806. update_info.progress = 5;
  807. msleep(800);
  808. for (i = 1; i < update_info.firmware->subsystem_count; i++) {
  809. GTP_INFO("subsystem: %d", update_info.firmware->subsystem[i].type);
  810. GTP_INFO("Length: %d", update_info.firmware->subsystem[i].length);
  811. GTP_INFO("Address: %d", update_info.firmware->subsystem[i].address);
  812. ret = gt1x_burn_subsystem(&(update_info.firmware->subsystem[i]));
  813. if (ret) {
  814. GTP_ERROR("burn subsystem fail!");
  815. goto gt1x_update_exit;
  816. }
  817. }
  818. update_info.progress = 6;
  819. gt1x_reset_guitar();
  820. p = gt1x_get_fw_data(update_info.firmware->subsystem[0].offset, update_info.firmware->subsystem[0].length);
  821. if (p == NULL) {
  822. GTP_ERROR("get isp fail");
  823. ret = ERROR_FW;
  824. goto gt1x_update_exit;
  825. }
  826. update_info.progress = 7;
  827. ret = gt1x_run_ss51_isp(p, update_info.firmware->subsystem[0].length);
  828. if (ret) {
  829. GTP_ERROR("run isp fail");
  830. goto gt1x_update_exit;
  831. }
  832. update_info.progress = 8;
  833. GTP_INFO("Reset guitar & check firmware in flash.");
  834. /*heck_state = SUCCESS;*/
  835. for (i = 1; i < update_info.firmware->subsystem_count; i++) {
  836. GTP_INFO("subsystem: %d", update_info.firmware->subsystem[i].type);
  837. GTP_INFO("Length: %d", update_info.firmware->subsystem[i].length);
  838. GTP_INFO("Address: %d", update_info.firmware->subsystem[i].address);
  839. ret = gt1x_check_subsystem_in_flash(&(update_info.firmware->subsystem[i]));
  840. if (ret)
  841. break;
  842. }
  843. update_info.progress = 9;
  844. gt1x_update_exit:
  845. gt1x_update_cleanup();
  846. gt1x_leave_update_mode();
  847. gt1x_read_version(NULL);
  848. update_info.status = UPDATE_STATUS_IDLE;
  849. if (ret) {
  850. GTP_ERROR("Update firmware failed!");
  851. } else if (gt1x_init_failed) {
  852. gt1x_read_version(&gt1x_version);
  853. gt1x_init_panel();
  854. }
  855. GTP_INFO("Update firmware succeefully!");
  856. return ret;
  857. }
  858. int __gt1x_hold_ss51_dsp_20(void)
  859. {
  860. int ret = -1;
  861. int retry = 0;
  862. u8 buf[1];
  863. int hold_times = 0;
  864. while (retry++ < 2000) {
  865. /*Hold ss51 & dsp*/
  866. buf[0] = 0x0C;
  867. ret = gt1x_i2c_write(_rRW_MISCTL__SWRST_B0_, buf, 1);
  868. if (ret) {
  869. GTP_DEBUG("Hold ss51 & dsp I2C error,retry:%d", retry);
  870. continue;
  871. }
  872. /*Confirm hold*/
  873. buf[0] = 0x00;
  874. ret = gt1x_i2c_read(_rRW_MISCTL__SWRST_B0_, buf, 1);
  875. if (ret) {
  876. GTP_DEBUG("Hold ss51 & dsp I2C error,retry:%d", retry);
  877. continue;
  878. }
  879. if (0x0C == buf[0]) {
  880. if (hold_times++ < 20)
  881. continue;
  882. else
  883. break;
  884. }
  885. GTP_DEBUG("Hold ss51 & dsp confirm 0x4180 failed,value:%d", buf[0]);
  886. }
  887. if (retry >= 2000) {
  888. GTP_ERROR("Hold ss51&dsp failed!");
  889. return ERROR_RETRY;
  890. }
  891. GTP_INFO("Hold ss51&dsp successfully.");
  892. return 0;
  893. }
  894. int gt1x_hold_ss51_dsp(void)
  895. {
  896. int ret = ERROR;
  897. u8 buffer[2];
  898. gt1x_select_addr();
  899. msleep(20);
  900. /*old ss51_dsp*/
  901. ret = __gt1x_hold_ss51_dsp_20();
  902. if (ret)
  903. return ret;
  904. /*enable dsp & mcu power*/
  905. buffer[0] = 0x00;
  906. ret = gt1x_i2c_write_with_readback(_bRW_MISCTL__DSP_MCU_PWR_, buffer, 1);
  907. if (ret) {
  908. GTP_ERROR("enabel dsp & mcu power fail!");
  909. return ret;
  910. }
  911. /*disable watchdog*/
  912. buffer[0] = 0x00;
  913. ret = gt1x_i2c_write_with_readback(_bRW_MISCTL__TMR0_EN, buffer, 1);
  914. if (ret) {
  915. GTP_ERROR("disable wdt fail!");
  916. return ret;
  917. }
  918. /*clear cache*/
  919. buffer[0] = 0x00;
  920. ret = gt1x_i2c_write_with_readback(_bRW_MISCTL__CACHE_EN, buffer, 1);
  921. if (ret) {
  922. GTP_ERROR("clear cache fail!");
  923. return ret;
  924. }
  925. /*soft reset*/
  926. buffer[0] = 0x01;
  927. ret = gt1x_i2c_write(_bWO_MISCTL__CPU_SWRST_PULSE, buffer, 1);
  928. if (ret) {
  929. GTP_ERROR("software reset fail!");
  930. return ret;
  931. }
  932. /*set scramble*/
  933. buffer[0] = 0x00;
  934. ret = gt1x_i2c_write_with_readback(_rRW_MISCTL__BOOT_OPT_B0_, buffer, 1);
  935. if (ret) {
  936. GTP_ERROR("set scramble fail!");
  937. return ret;
  938. }
  939. return 0;
  940. }
  941. void gt1x_leave_update_mode(void)
  942. {
  943. GTP_DEBUG("[leave_update_mode]reset chip.");
  944. gt1x_reset_guitar();
  945. #ifdef CONFIG_GTP_ESD_PROTECT
  946. gt1x_esd_switch(SWITCH_ON);
  947. #endif
  948. gt1x_irq_enable();
  949. }
  950. void read_reg(u16 addr, int len)
  951. {
  952. int i;
  953. u8 buffer[16];
  954. int read_len = 0;
  955. int cur_len;
  956. GTP_INFO("Read address: 0x%04X, Length: %d", addr, len);
  957. while (len > 0) {
  958. cur_len = (len > 16 ? 16 : len);
  959. gt1x_i2c_read(addr + read_len, buffer, cur_len);
  960. GTP_INFO("<<GTP-INF>> ");
  961. for (i = 0; i < cur_len; i++)
  962. GTP_INFO("%02X ", buffer[i]);
  963. GTP_INFO("\n");
  964. len -= cur_len;
  965. read_len += cur_len;
  966. }
  967. }
  968. void dump_to_file(u16 addr, int length, char *filepath)
  969. {
  970. struct file *flp = NULL;
  971. u8 buf[128];
  972. const int READ_BLOCK_SIZE = 128;
  973. int read_length = 0;
  974. int len = 0;
  975. GTP_INFO("Dump(0x%04X, %d bytes) to file: %s\n", addr, length, filepath);
  976. flp = filp_open(filepath, O_RDWR | O_CREAT, 0666);
  977. if (IS_ERR(flp)) {
  978. GTP_ERROR("can not open file: %s\n", filepath);
  979. return;
  980. }
  981. flp->f_op->llseek(flp, 0, SEEK_SET);
  982. while (length > 0) {
  983. len = (length > READ_BLOCK_SIZE ? READ_BLOCK_SIZE : length);
  984. memset(buf, 0x33, len);
  985. if (gt1x_i2c_read(addr + read_length, buf, len))
  986. memset(buf, 0x33, len);
  987. flp->f_op->write(flp, (char *)buf, len, &flp->f_pos);
  988. read_length += len;
  989. length -= len;
  990. }
  991. filp_close(flp, NULL);
  992. }
  993. int gt1x_hold_ss51_dsp_no_reset(void)
  994. {
  995. int ret = ERROR;
  996. u8 buffer[2];
  997. /*old ss51_dsp*/
  998. ret = __gt1x_hold_ss51_dsp_20();
  999. if (ret)
  1000. return ret;
  1001. /*enable dsp & mcu power*/
  1002. buffer[0] = 0x00;
  1003. ret = gt1x_i2c_write_with_readback(_bRW_MISCTL__DSP_MCU_PWR_, buffer, 1);
  1004. if (ret) {
  1005. GTP_ERROR("enabel dsp & mcu power fail!");
  1006. return ret;
  1007. }
  1008. /*disable watchdog*/
  1009. buffer[0] = 0x00;
  1010. ret = gt1x_i2c_write_with_readback(_bRW_MISCTL__TMR0_EN, buffer, 1);
  1011. if (ret) {
  1012. GTP_ERROR("disable wdt fail!");
  1013. return ret;
  1014. }
  1015. /*clear cache*/
  1016. buffer[0] = 0x00;
  1017. ret = gt1x_i2c_write_with_readback(_bRW_MISCTL__CACHE_EN, buffer, 1);
  1018. if (ret) {
  1019. GTP_ERROR("clear cache fail!");
  1020. return ret;
  1021. }
  1022. /*t reset*/
  1023. buffer[0] = 0x01;
  1024. ret = gt1x_i2c_write(_bWO_MISCTL__CPU_SWRST_PULSE, buffer, 1);
  1025. if (ret) {
  1026. GTP_ERROR("software reset fail!");
  1027. return ret;
  1028. }
  1029. /*et scramble*/
  1030. buffer[0] = 0x00;
  1031. ret = gt1x_i2c_write_with_readback(_rRW_MISCTL__BOOT_OPT_B0_, buffer, 1);
  1032. if (ret) {
  1033. GTP_ERROR("set scramble fail!");
  1034. return ret;
  1035. }
  1036. return 0;
  1037. }
  1038. #define GT1X_LOAD_PACKET_SIZE (1024 * 2)
  1039. int gt1x_load_patch(u8 *patch, u32 patch_size, int offset, int bank_size)
  1040. {
  1041. s32 loaded_length = 0;
  1042. s32 len = 0;
  1043. s32 ret = 0;
  1044. u8 bank = 0, tmp;
  1045. u16 address;
  1046. GTP_INFO("Load patch code(size: %d, checksum: 0x%04X, position: 0x%04X, bank-size: %d", patch_size,
  1047. gt1x_calc_checksum(patch, patch_size), 0xC000 + offset, bank_size);
  1048. while (loaded_length != patch_size) {
  1049. if (loaded_length == 0 || (loaded_length + offset) % bank_size == 0) {
  1050. /*lect bank*/
  1051. bank = 0x04 + (loaded_length + offset) / bank_size;
  1052. ret = gt1x_i2c_write(_bRW_MISCTL__SRAM_BANK, &bank, 1);
  1053. if (ret) {
  1054. GTP_ERROR("select bank%d fail!", bank);
  1055. return ret;
  1056. }
  1057. GTP_INFO("Select bank%d success.", bank);
  1058. /*enable patch area access*/
  1059. tmp = 0x01;
  1060. ret = gt1x_i2c_write_with_readback(_bRW_MISCTL__PATCH_AREA_EN_ + bank - 4, &tmp, 1);
  1061. if (ret) {
  1062. GTP_ERROR("enable patch area access fail!");
  1063. return ret;
  1064. }
  1065. }
  1066. len =
  1067. patch_size - loaded_length >
  1068. GT1X_LOAD_PACKET_SIZE ? GT1X_LOAD_PACKET_SIZE : patch_size - loaded_length;
  1069. address = 0xC000 + (loaded_length + offset) % bank_size;
  1070. ret = gt1x_i2c_write(address, &patch[loaded_length], len);
  1071. if (ret) {
  1072. GTP_ERROR("load 0x%04X, %dbytes fail!", address, len);
  1073. return ret;
  1074. }
  1075. ret = gt1x_recall_check(&patch[loaded_length], address, len);
  1076. if (ret) {
  1077. GTP_ERROR("Recall check 0x%04X, %dbytes fail!", address, len);
  1078. return ret;
  1079. }
  1080. GTP_INFO("load code 0x%04X, %dbytes success.", address, len);
  1081. loaded_length += len;
  1082. }
  1083. return 0;
  1084. }
  1085. int gt1x_startup_patch(void)
  1086. {
  1087. s32 ret = 0;
  1088. u8 buffer[8] = { 0x55 };
  1089. buffer[0] = 0x00;
  1090. buffer[1] = 0x00;
  1091. ret |= gt1x_i2c_write(_bRW_MISCTL__PATCH_AREA_EN_, buffer, 2);
  1092. memset(buffer, 0x55, 8);
  1093. ret |= gt1x_i2c_write(GTP_REG_FLASH_PASSBY, buffer, 8);
  1094. ret |= gt1x_i2c_write(GTP_REG_VERSION, buffer, 5);
  1095. buffer[0] = 0xAA;
  1096. ret |= gt1x_i2c_write(GTP_REG_CMD, buffer, 1);
  1097. ret |= gt1x_i2c_write(GTP_REG_ESD_CHECK, buffer, 1);
  1098. buffer[0] = 0x00;
  1099. ret |= gt1x_i2c_write(_rRW_MISCTL__SWRST_B0_, buffer, 1);
  1100. msleep(200);
  1101. return ret;
  1102. }