gt9xx_update.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829
  1. /* drivers/input/touchscreen/gt813_827_828_update.c
  2. *
  3. * 2010 - 2012 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.2
  17. * V1.0:2012/08/31,first release.
  18. * V1.2:2012/10/15,add force update,GT9110P pid map
  19. */
  20. #include "tpd.h"
  21. #include <linux/interrupt.h>
  22. #include <linux/i2c.h>
  23. #include <linux/sched.h>
  24. #include <linux/kthread.h>
  25. #include <linux/rtpm_prio.h>
  26. #include <linux/wait.h>
  27. #include <linux/time.h>
  28. #include <linux/delay.h>
  29. #include <linux/namei.h>
  30. #include <linux/mount.h>
  31. #include <asm/uaccess.h>
  32. #define GUP_FW_INFO
  33. #include "tpd_custom_gt9xx.h"
  34. #define GUP_REG_HW_INFO 0x4220
  35. #define GUP_REG_FW_MSG 0x41E4
  36. #define GUP_REG_PID_VID 0x8140
  37. /* #define GTP_BOOT_FW_CONFIG_SD_UPDATE */
  38. #define GUP_SEARCH_FILE_TIMES 50
  39. #define UPDATE_FILE_PATH_2 "/data/goodix/_goodix_update_.bin"
  40. #define UPDATE_FILE_PATH_1 "/sdcard/goodix/_goodix_update_.bin"
  41. #define CONFIG_FILE_PATH_2 "/data/goodix/_goodix_config_.cfg"
  42. #define CONFIG_FILE_PATH_1 "/sdcard/goodix/_goodix_config_.cfg"
  43. #define FW_HEAD_LENGTH 14
  44. #define FW_SECTION_LENGTH 0x2000
  45. #define FW_DSP_ISP_LENGTH 0x1000
  46. #define FW_DSP_LENGTH 0x1000
  47. #define FW_BOOT_LENGTH 0x800
  48. #define FW_DOWNLOAD_LENGTH 0x4000
  49. #define FW_LENGTH (4*FW_SECTION_LENGTH+FW_DSP_ISP_LENGTH+FW_DSP_LENGTH+FW_BOOT_LENGTH)
  50. #define PACK_SIZE 256
  51. #define MAX_FRAME_CHECK_TIME 5
  52. #define _bRW_MISCTL__SRAM_BANK 0x4048
  53. #define _bRW_MISCTL__MEM_CD_EN 0x4049
  54. #define _bRW_MISCTL__CACHE_EN 0x404B
  55. #define _bRW_MISCTL__TMR0_EN 0x40B0
  56. #define _rRW_MISCTL__SWRST_B0_ 0x4180
  57. #define _bWO_MISCTL__CPU_SWRST_PULSE 0x4184
  58. #define _rRW_MISCTL__BOOTCTL_B0_ 0x4190
  59. #define _rRW_MISCTL__BOOT_OPT_B0_ 0x4218
  60. #define _rRW_MISCTL__BOOT_CTL_ 0x5094
  61. #define FAIL 0
  62. #define SUCCESS 1
  63. #pragma pack(1)
  64. struct st_fw_head {
  65. u8 hw_info[4]; /* hardware info// */
  66. u8 pid[8]; /* product id // */
  67. u16 vid; /* version id // */
  68. };
  69. #pragma pack()
  70. struct st_update_msg {
  71. u8 force_update;
  72. u8 fw_flag;
  73. struct file *file;
  74. struct file *cfg_file;
  75. struct st_fw_head ic_fw_msg;
  76. mm_segment_t old_fs;
  77. };
  78. struct st_update_msg update_msg;
  79. struct i2c_client *guitar_client = NULL;
  80. u16 show_len;
  81. u16 total_len;
  82. u8 *fw_buf;
  83. static u8 gup_get_ic_msg(struct i2c_client *client, u16 addr, u8 *msg, s32 len)
  84. {
  85. s32 i = 0;
  86. msg[0] = (addr >> 8) & 0xff;
  87. msg[1] = addr & 0xff;
  88. for (i = 0; i < 5; i++) {
  89. if (gtp_i2c_read(client, msg, GTP_ADDR_LENGTH + len) > 0)
  90. break;
  91. }
  92. if (i >= 5) {
  93. GTP_ERROR("Read data from 0x%02x%02x failed!", msg[0], msg[1]);
  94. return FAIL;
  95. }
  96. return SUCCESS;
  97. }
  98. static u8 gup_set_ic_msg(struct i2c_client *client, u16 addr, u8 val)
  99. {
  100. s32 i = 0;
  101. u8 msg[3];
  102. msg[0] = (addr >> 8) & 0xff;
  103. msg[1] = addr & 0xff;
  104. msg[2] = val;
  105. for (i = 0; i < 5; i++) {
  106. if (gtp_i2c_write(client, msg, GTP_ADDR_LENGTH + 1) > 0)
  107. break;
  108. }
  109. if (i >= 5) {
  110. GTP_ERROR("Set data to 0x%02x%02x failed!", msg[0], msg[1]);
  111. return FAIL;
  112. }
  113. return SUCCESS;
  114. }
  115. static u8 gup_get_ic_fw_msg(struct i2c_client *client)
  116. {
  117. s32 ret = -1;
  118. u8 retry = 0;
  119. u8 buf[16];
  120. u8 i;
  121. /* step1:get hardware info */
  122. ret = gup_get_ic_msg(client, GUP_REG_HW_INFO, buf, 4);
  123. if (FAIL == ret) {
  124. GTP_ERROR("Read hardware info fail.");
  125. return ret;
  126. }
  127. memcpy(update_msg.ic_fw_msg.hw_info, &buf[GTP_ADDR_LENGTH], 4);
  128. for (i = 0; i < 4; i++)
  129. update_msg.ic_fw_msg.hw_info[i] = buf[GTP_ADDR_LENGTH + 3 - i];
  130. GTP_DEBUG("IC Hardware info:%02x%02x%02x%02x", update_msg.ic_fw_msg.hw_info[0],
  131. update_msg.ic_fw_msg.hw_info[1], update_msg.ic_fw_msg.hw_info[2],
  132. update_msg.ic_fw_msg.hw_info[3]);
  133. /* step2:get firmware message */
  134. for (retry = 0; retry < 2; retry++) {
  135. ret = gup_get_ic_msg(client, GUP_REG_FW_MSG, buf, 1);
  136. if (FAIL == ret) {
  137. GTP_ERROR("Read firmware message fail.");
  138. return ret;
  139. }
  140. update_msg.force_update = buf[GTP_ADDR_LENGTH];
  141. if ((0xBE != update_msg.force_update) && (!retry)) {
  142. GTP_INFO("The check sum in ic is error.");
  143. GTP_INFO("The IC will be updated by force.");
  144. continue;
  145. }
  146. break;
  147. }
  148. GTP_DEBUG("IC force update flag:0x%x", update_msg.force_update);
  149. /* step3:get pid & vid */
  150. ret = gup_get_ic_msg(client, GUP_REG_PID_VID, buf, 6);
  151. if (FAIL == ret) {
  152. GTP_ERROR("Read product id & version id fail.");
  153. return ret;
  154. }
  155. memset(update_msg.ic_fw_msg.pid, 0, sizeof(update_msg.ic_fw_msg.pid));
  156. memcpy(update_msg.ic_fw_msg.pid, &buf[GTP_ADDR_LENGTH], 4);
  157. GTP_DEBUG("IC Product id:%s", update_msg.ic_fw_msg.pid);
  158. /* GT9XX PID MAPPING */
  159. /*|-----FLASH-----RAM-----|
  160. |------918------918-----|
  161. |------968------968-----|
  162. |------913------913-----|
  163. |------913P-----913P----|
  164. |------927------927-----|
  165. |------927P-----927P----|
  166. |------9110-----9110----|
  167. |------9110P----9111----| */
  168. if (update_msg.ic_fw_msg.pid[0] != 0) {
  169. if (!memcmp(update_msg.ic_fw_msg.pid, "9111", 4)) {
  170. GTP_DEBUG("IC Mapping Product id:%s", update_msg.ic_fw_msg.pid);
  171. memcpy(update_msg.ic_fw_msg.pid, "9110P", 5);
  172. }
  173. }
  174. update_msg.ic_fw_msg.vid = buf[GTP_ADDR_LENGTH + 4] + (buf[GTP_ADDR_LENGTH + 5] << 8);
  175. GTP_DEBUG("IC version id:%04x", update_msg.ic_fw_msg.vid);
  176. return SUCCESS;
  177. }
  178. s32 gup_enter_update_mode(struct i2c_client *client)
  179. {
  180. s32 ret = -1;
  181. s32 retry = 0;
  182. u8 rd_buf[3];
  183. /* step1:RST output low last at least 2ms */
  184. tpd_gpio_output(GTP_RST_PORT, 0);/* DELETE->gpio_direction_output(tpd_rst_gpio_number, 0); */
  185. msleep(20);
  186. /* step2:select I2C slave addr,INT:0--0xBA;1--0x28. */
  187. /* gpio_direction_output(tpd_int_gpio_number, (client->addr == 0x14)); */
  188. tpd_gpio_output(GTP_INT_PORT, (client->addr == 0x14));
  189. msleep(20);
  190. /* step3:RST output high reset guitar */
  191. tpd_gpio_output(GTP_RST_PORT, 0);/* DELETE->gpio_direction_output(tpd_rst_gpio_number, 1); */
  192. /* 20121211 modify start */
  193. msleep(20);
  194. while (retry++ < 200) {
  195. /* step4:Hold ss51 & dsp */
  196. ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x0C);
  197. if (ret <= 0) {
  198. GTP_DEBUG("Hold ss51 & dsp I2C error,retry:%d", retry);
  199. continue;
  200. }
  201. /* step5:Confirm hold */
  202. ret = gup_get_ic_msg(client, _rRW_MISCTL__SWRST_B0_, rd_buf, 1);
  203. if (ret <= 0) {
  204. GTP_DEBUG("Hold ss51 & dsp I2C error,retry:%d", retry);
  205. continue;
  206. }
  207. if (0x0C == rd_buf[GTP_ADDR_LENGTH]) {
  208. GTP_DEBUG("Hold ss51 & dsp confirm SUCCESS");
  209. break;
  210. }
  211. GTP_DEBUG("Hold ss51 & dsp confirm 0x4180 failed,value:%d",
  212. rd_buf[GTP_ADDR_LENGTH]);
  213. }
  214. if (retry >= 200) {
  215. GTP_ERROR("Enter update Hold ss51 failed.");
  216. return FAIL;
  217. }
  218. /* step6:DSP_CK and DSP_ALU_CK PowerOn */
  219. ret = gup_set_ic_msg(client, 0x4010, 0x00);
  220. /* 20121211 modify end */
  221. return ret;
  222. }
  223. void gup_leave_update_mode(void)
  224. {
  225. s32 ret = 0;
  226. /* GTP_GPIO_AS_INT(tpd_int_gpio_number); */
  227. GTP_DEBUG("[leave_update_mode]reset chip.");
  228. gtp_reset_guitar(guitar_client, 20);
  229. msleep(100);
  230. GTP_DEBUG("[update_proc]send config.");
  231. ret = gtp_send_cfg(guitar_client);
  232. if (ret < 0)
  233. GTP_ERROR("[update_proc]send config fail.");
  234. }
  235. static u8 gup_enter_upadte_judge(struct st_fw_head *fw_head)
  236. {
  237. u16 u16_tmp;
  238. /* Get the correct nvram data */
  239. /* The correct conditions: */
  240. /* 1. the hardware info is the same */
  241. /* 2. the product id is the same */
  242. /* 3. the firmware version in update file is greater than the firmware version in ic */
  243. /* or the check sum in ic is wrong */
  244. u16_tmp = fw_head->vid;
  245. fw_head->vid = (u16) (u16_tmp >> 8) + (u16) (u16_tmp << 8);
  246. GTP_DEBUG("FILE HARDWARE INFO:%02x%02x%02x%02x", fw_head->hw_info[0], fw_head->hw_info[1],
  247. fw_head->hw_info[2], fw_head->hw_info[3]);
  248. GTP_DEBUG("FILE PID:%s", fw_head->pid);
  249. GTP_DEBUG("FILE VID:%04x", fw_head->vid);
  250. GTP_DEBUG("IC HARDWARE INFO:%02x%02x%02x%02x", update_msg.ic_fw_msg.hw_info[0],
  251. update_msg.ic_fw_msg.hw_info[1], update_msg.ic_fw_msg.hw_info[2],
  252. update_msg.ic_fw_msg.hw_info[3]);
  253. GTP_DEBUG("IC PID:%s", update_msg.ic_fw_msg.pid);
  254. GTP_DEBUG("IC VID:%04x", update_msg.ic_fw_msg.vid);
  255. /* First two conditions */
  256. if (!memcmp
  257. (fw_head->hw_info, update_msg.ic_fw_msg.hw_info,
  258. sizeof(update_msg.ic_fw_msg.hw_info))) {
  259. GTP_DEBUG("Get the same hardware info.");
  260. if (update_msg.force_update != 0xBE) {
  261. GTP_INFO("FW chksum error,need enter update.");
  262. return SUCCESS;
  263. }
  264. if ((!memcmp
  265. (fw_head->pid, update_msg.ic_fw_msg.pid, strlen(update_msg.ic_fw_msg.pid)))
  266. || (!memcmp(update_msg.ic_fw_msg.pid, "91XX", 4))
  267. || (!memcmp(fw_head->pid, "91XX", 4))) {
  268. if (!memcmp(fw_head->pid, "91XX", 4))
  269. GTP_DEBUG("Force none same pid update mode.");
  270. else
  271. GTP_DEBUG("Get the same pid.");
  272. /* The third condition */
  273. if (fw_head->vid > update_msg.ic_fw_msg.vid) {
  274. GTP_INFO("Need enter update.");
  275. return SUCCESS;
  276. }
  277. GTP_ERROR("Don't meet the third condition.");
  278. }
  279. }
  280. return FAIL;
  281. }
  282. #ifdef GTP_BOOT_FW_CONFIG_SD_UPDATE
  283. static u8 ascii2hex(u8 a)
  284. {
  285. s8 value = 0;
  286. if (a >= '0' && a <= '9')
  287. value = a - '0';
  288. else if (a >= 'A' && a <= 'F')
  289. value = a - 'A' + 0x0A;
  290. else if (a >= 'a' && a <= 'f')
  291. value = a - 'a' + 0x0A;
  292. else
  293. value = 0xff;
  294. return value;
  295. }
  296. static s8 gup_update_config(struct i2c_client *client)
  297. {
  298. s32 file_len = 0;
  299. s32 ret = 0;
  300. s32 i = 0;
  301. s32 file_cfg_len = 0;
  302. s32 chip_cfg_len = 0;
  303. s32 count = 0;
  304. u8 *buf;
  305. u8 *pre_buf;
  306. u8 *file_config;
  307. /* u8 checksum = 0; */
  308. if (IS_ERR(update_msg.cfg_file)) {
  309. GTP_ERROR("[update_cfg]No need to upgrade config!");
  310. return FAIL;
  311. }
  312. file_len = update_msg.cfg_file->f_op->llseek(update_msg.cfg_file, 0, SEEK_END);
  313. chip_cfg_len = 186;
  314. if (!memcmp(update_msg.ic_fw_msg.pid, "968", 3))
  315. chip_cfg_len = 228;
  316. GTP_DEBUG("[update_cfg]config file len:%d", file_len);
  317. GTP_DEBUG("[update_cfg]need config len:%d", chip_cfg_len);
  318. if ((file_len + 5) < chip_cfg_len * 5) {
  319. GTP_ERROR("Config length error");
  320. return -1;
  321. }
  322. buf = kzalloc(file_len, GFP_KERNEL);
  323. pre_buf = kzalloc(file_len, GFP_KERNEL);
  324. file_config = kzalloc(chip_cfg_len + GTP_ADDR_LENGTH, GFP_KERNEL);
  325. update_msg.cfg_file->f_op->llseek(update_msg.cfg_file, 0, SEEK_SET);
  326. GTP_DEBUG("[update_cfg]Read config from file.");
  327. ret =
  328. update_msg.cfg_file->f_op->read(update_msg.cfg_file, (char *)pre_buf, file_len,
  329. &update_msg.cfg_file->f_pos);
  330. if (ret < 0) {
  331. GTP_ERROR("[update_cfg]Read config file failed.");
  332. goto update_cfg_file_failed;
  333. }
  334. GTP_DEBUG("[update_cfg]Delete illgal character.");
  335. for (i = 0, count = 0; i < file_len; i++) {
  336. if (pre_buf[i] == ' ' || pre_buf[i] == '\r' || pre_buf[i] == '\n')
  337. continue;
  338. buf[count++] = pre_buf[i];
  339. }
  340. GTP_DEBUG("[update_cfg]Ascii to hex.");
  341. file_config[0] = GTP_REG_CONFIG_DATA >> 8;
  342. file_config[1] = GTP_REG_CONFIG_DATA & 0xff;
  343. for (i = 0, file_cfg_len = GTP_ADDR_LENGTH; i < count; i += 5) {
  344. if ((buf[i] == '0') && ((buf[i + 1] == 'x') || (buf[i + 1] == 'X'))) {
  345. u8 high, low;
  346. high = ascii2hex(buf[i + 2]);
  347. low = ascii2hex(buf[i + 3]);
  348. if ((high == 0xFF) || (low == 0xFF)) {
  349. ret = 0;
  350. GTP_ERROR("[update_cfg]Illegal config file.");
  351. goto update_cfg_file_failed;
  352. }
  353. file_config[file_cfg_len++] = (high << 4) + low;
  354. } else {
  355. ret = 0;
  356. GTP_ERROR("[update_cfg]Illegal config file.");
  357. goto update_cfg_file_failed;
  358. }
  359. }
  360. GTP_DEBUG("config:");
  361. GTP_DEBUG_ARRAY(file_config, file_cfg_len);
  362. /* cal checksum */
  363. #if 0
  364. for (i = GTP_ADDR_LENGTH; i < chip_cfg_len; i++)
  365. checksum += file_config[i];
  366. file_config[chip_cfg_len] = (~checksum) + 1;
  367. #endif
  368. i = 0;
  369. while (i++ < 5) {
  370. ret = gtp_i2c_write(client, file_config, file_cfg_len);
  371. if (ret > 0) {
  372. GTP_INFO("[update_cfg]Send config SUCCESS.");
  373. break;
  374. }
  375. GTP_ERROR("[update_cfg]Send config i2c error.");
  376. }
  377. update_cfg_file_failed:
  378. kfree(pre_buf);
  379. kfree(buf);
  380. kfree(file_config);
  381. return ret;
  382. }
  383. #endif
  384. static u8 gup_load_update_file(struct st_fw_head *fw_head)
  385. {
  386. s32 ret = 0;
  387. mm_segment_t fs = get_fs();
  388. set_fs(KERNEL_DS);
  389. ret = update_msg.file->f_op->llseek(update_msg.file, 0, SEEK_SET);
  390. /* update_msg.file->f_pos = 0; */
  391. ret =
  392. update_msg.file->f_op->read(update_msg.file, (char *)fw_head, FW_HEAD_LENGTH,
  393. &update_msg.file->f_pos);
  394. if (ret < 0) {
  395. GTP_ERROR("Read firmware head in update file error.");
  396. return FAIL;
  397. }
  398. /* memcpy(fw_head, buf, FW_HEAD_LENGTH); */
  399. update_msg.file->f_pos = FW_HEAD_LENGTH + 0;
  400. ret =
  401. update_msg.file->f_op->read(update_msg.file, (char *)fw_buf, FW_LENGTH,
  402. &update_msg.file->f_pos);
  403. if (ret < 0) {
  404. GTP_ERROR("Read firmware file fail.");
  405. return FAIL;
  406. }
  407. set_fs(fs);
  408. return SUCCESS;
  409. }
  410. static u8 gup_check_update_file(struct i2c_client *client, struct st_fw_head *fw_head, u8 *path)
  411. {
  412. s32 ret = 0;
  413. s32 i = 0;
  414. s32 fw_checksum = 0;
  415. u8 empty_test = 0;
  416. update_msg.file = NULL;
  417. if (path) {
  418. GTP_DEBUG("Update File path:%s, %d", path, (int)strlen(path));
  419. update_msg.file = filp_open(path, O_RDONLY, 0644);
  420. if (IS_ERR(update_msg.file)) {
  421. GTP_ERROR("Open update file(%s) error!", path);
  422. return FAIL;
  423. }
  424. }
  425. #ifdef GTP_BOOT_FW_CONFIG_SD_UPDATE
  426. else {
  427. /* Begin to search update file,the config file
  428. & firmware file must be in the same path,single or double. */
  429. for (i = 0; i < GUP_SEARCH_FILE_TIMES; i++) {
  430. update_msg.file = filp_open(UPDATE_FILE_PATH_1, O_RDWR, 0444);
  431. if (IS_ERR(update_msg.file)) {
  432. update_msg.file = filp_open(UPDATE_FILE_PATH_2, O_RDWR, 0664);
  433. if (IS_ERR(update_msg.file)) {
  434. GTP_DEBUG("%3d:Searching file...", i);
  435. msleep(1000);
  436. continue;
  437. } else {
  438. GTP_DEBUG("Find UPDATE_FILE_PATH_2");
  439. break;
  440. }
  441. } else {
  442. GTP_DEBUG("Find UPDATE_FILE_PATH_1");
  443. i = GUP_SEARCH_FILE_TIMES;
  444. break;
  445. }
  446. }
  447. /* make sure check config file at least once */
  448. if (i == GUP_SEARCH_FILE_TIMES)
  449. i--;
  450. for (; i < GUP_SEARCH_FILE_TIMES; i++) {
  451. update_msg.cfg_file = filp_open(CONFIG_FILE_PATH_1, O_RDWR, 0444);
  452. if (IS_ERR(update_msg.cfg_file)) {
  453. update_msg.cfg_file = filp_open(CONFIG_FILE_PATH_2, O_RDWR, 0664);
  454. if (IS_ERR(update_msg.cfg_file)) {
  455. GTP_DEBUG("%3d:Searching file...", i);
  456. msleep(1000);
  457. continue;
  458. } else {
  459. GTP_DEBUG("Find CONFIG_FILE_PATH_2");
  460. break;
  461. }
  462. } else {
  463. GTP_DEBUG("Find CONFIG_FILE_PATH_1");
  464. break;
  465. }
  466. }
  467. if (!IS_ERR(update_msg.cfg_file)) {
  468. GTP_DEBUG("Got the update config file.");
  469. ret = gup_update_config(client);
  470. if (ret <= 0)
  471. GTP_ERROR("Update config failed.");
  472. filp_close(update_msg.cfg_file, NULL);
  473. }
  474. }
  475. #endif /* end BOOT_FW_CONFIG_SD_UPDATE */
  476. if ((!IS_ERR(update_msg.file)) && (update_msg.file != NULL)) {
  477. ret = gup_load_update_file(fw_head);
  478. filp_close(update_msg.file, NULL);
  479. if (ret == FAIL)
  480. return FAIL;
  481. }
  482. else { /* default FW */
  483. GTP_DEBUG("Load Default FW.");
  484. memcpy(fw_head, gtp_default_FW, FW_HEAD_LENGTH);
  485. memcpy(fw_buf, gtp_default_FW + FW_HEAD_LENGTH, FW_LENGTH);
  486. }
  487. /* check firmware legality */
  488. fw_checksum = 0;
  489. for (i = 0; i < FW_SECTION_LENGTH * 4 + FW_DSP_ISP_LENGTH + FW_DSP_LENGTH + FW_BOOT_LENGTH;
  490. i += 2) {
  491. u16 temp;
  492. /* GTP_DEBUG("BUF[0]:%x", buf[0]); */
  493. empty_test |= fw_buf[i];
  494. empty_test |= fw_buf[i + 1];
  495. temp = (fw_buf[i] << 8) + fw_buf[i + 1];
  496. fw_checksum += temp;
  497. }
  498. GTP_DEBUG("firmware checksum:%x empty_test:%x", (fw_checksum & 0xFFFF), empty_test);
  499. if ((fw_checksum & 0xFFFF) || (empty_test == 0)) {
  500. GTP_ERROR("Illegal or empty firmware file.");
  501. GTP_ERROR("Load Default FW.");
  502. memcpy(fw_head, gtp_default_FW, FW_HEAD_LENGTH);
  503. memcpy(fw_buf, gtp_default_FW + FW_HEAD_LENGTH, FW_LENGTH);
  504. }
  505. return SUCCESS;
  506. }
  507. static u8 gup_burn_proc(struct i2c_client *client, u8 *burn_buf, u16 start_addr, u16 total_length)
  508. {
  509. s32 ret = 0;
  510. u16 burn_addr = start_addr;
  511. u16 frame_length = 0;
  512. u16 burn_length = 0;
  513. u8 wr_buf[PACK_SIZE + GTP_ADDR_LENGTH];
  514. u8 rd_buf[PACK_SIZE + GTP_ADDR_LENGTH];
  515. u8 retry = 0;
  516. GTP_DEBUG("Begin burn %dk data to addr 0x%x", (total_length / 1024), start_addr);
  517. while (burn_length < total_length) {
  518. GTP_DEBUG("B/T:%04d/%04d", burn_length, total_length);
  519. frame_length =
  520. ((total_length - burn_length) >
  521. PACK_SIZE) ? PACK_SIZE : (total_length - burn_length);
  522. wr_buf[0] = (u8) (burn_addr >> 8);
  523. rd_buf[0] = wr_buf[0];
  524. wr_buf[1] = (u8) burn_addr;
  525. rd_buf[1] = wr_buf[1];
  526. memcpy(&wr_buf[GTP_ADDR_LENGTH], &burn_buf[burn_length], frame_length);
  527. for (retry = 0; retry < MAX_FRAME_CHECK_TIME; retry++) {
  528. ret = gtp_i2c_write(client, wr_buf, GTP_ADDR_LENGTH + frame_length);
  529. if (ret <= 0) {
  530. GTP_ERROR("Write frame data i2c error.");
  531. continue;
  532. }
  533. ret = gtp_i2c_read(client, rd_buf, GTP_ADDR_LENGTH + frame_length);
  534. if (ret <= 0) {
  535. GTP_ERROR("Read back frame data i2c error.");
  536. continue;
  537. }
  538. if (memcmp
  539. (&wr_buf[GTP_ADDR_LENGTH], &rd_buf[GTP_ADDR_LENGTH], frame_length)) {
  540. GTP_ERROR("Check frame data fail,not equal.");
  541. GTP_DEBUG("write array:");
  542. GTP_DEBUG_ARRAY(&wr_buf[GTP_ADDR_LENGTH], frame_length);
  543. GTP_DEBUG("read array:");
  544. GTP_DEBUG_ARRAY(&rd_buf[GTP_ADDR_LENGTH], frame_length);
  545. continue;
  546. } else {
  547. /* GTP_DEBUG("Check frame data success."); */
  548. break;
  549. }
  550. }
  551. if (retry >= MAX_FRAME_CHECK_TIME) {
  552. GTP_ERROR("Burn frame data time out,exit.");
  553. return FAIL;
  554. }
  555. burn_length += frame_length;
  556. burn_addr += frame_length;
  557. }
  558. return SUCCESS;
  559. }
  560. static u8 gup_load_section_file(u8 *buf, u16 offset, u16 length)
  561. {
  562. memcpy(buf, fw_buf + offset, length);
  563. return SUCCESS;
  564. }
  565. static u8 gup_recall_check(struct i2c_client *client, u8 *chk_src, u16 start_rd_addr,
  566. u16 chk_length)
  567. {
  568. u8 rd_buf[PACK_SIZE + GTP_ADDR_LENGTH];
  569. s32 ret = 0;
  570. u16 recall_addr = start_rd_addr;
  571. u16 recall_length = 0;
  572. u16 frame_length = 0;
  573. while (recall_length < chk_length) {
  574. frame_length =
  575. ((chk_length - recall_length) >
  576. PACK_SIZE) ? PACK_SIZE : (chk_length - recall_length);
  577. ret = gup_get_ic_msg(client, recall_addr, rd_buf, frame_length);
  578. if (ret <= 0) {
  579. GTP_ERROR("recall i2c error,exit");
  580. return FAIL;
  581. }
  582. if (memcmp(&rd_buf[GTP_ADDR_LENGTH], &chk_src[recall_length], frame_length)) {
  583. GTP_ERROR("Recall frame data fail,not equal.");
  584. GTP_DEBUG("chk_src array:");
  585. GTP_DEBUG_ARRAY(&chk_src[recall_length], frame_length);
  586. GTP_DEBUG("recall array:");
  587. GTP_DEBUG_ARRAY(&rd_buf[GTP_ADDR_LENGTH], frame_length);
  588. return FAIL;
  589. }
  590. recall_length += frame_length;
  591. recall_addr += frame_length;
  592. }
  593. GTP_DEBUG("Recall check %dk firmware success.", (chk_length / 1024));
  594. return SUCCESS;
  595. }
  596. static u8 gup_burn_fw_section(struct i2c_client *client, u8 *fw_section, u16 start_addr,
  597. u8 bank_cmd)
  598. {
  599. s32 ret = 0;
  600. u8 rd_buf[5];
  601. /* step1:hold ss51 & dsp */
  602. ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x0C);
  603. if (ret <= 0) {
  604. GTP_ERROR("[burn_fw_section]hold ss51 & dsp fail.");
  605. return FAIL;
  606. }
  607. /* step2:set scramble */
  608. ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_OPT_B0_, 0x00);
  609. if (ret <= 0) {
  610. GTP_ERROR("[burn_fw_section]set scramble fail.");
  611. return FAIL;
  612. }
  613. /* step3:select bank */
  614. ret = gup_set_ic_msg(client, _bRW_MISCTL__SRAM_BANK, (bank_cmd >> 4) & 0x0F);
  615. if (ret <= 0) {
  616. GTP_ERROR("[burn_fw_section]select bank %d fail.", (bank_cmd >> 4) & 0x0F);
  617. return FAIL;
  618. }
  619. /* step4:enable accessing code */
  620. ret = gup_set_ic_msg(client, _bRW_MISCTL__MEM_CD_EN, 0x01);
  621. if (ret <= 0) {
  622. GTP_ERROR("[burn_fw_section]enable accessing code fail.");
  623. return FAIL;
  624. }
  625. /* step5:burn 8k fw section */
  626. ret = gup_burn_proc(client, fw_section, start_addr, FW_SECTION_LENGTH);
  627. if (FAIL == ret) {
  628. GTP_ERROR("[burn_fw_section]burn fw_section fail.");
  629. return FAIL;
  630. }
  631. /* step6:hold ss51 & release dsp */
  632. ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x04);
  633. if (ret <= 0) {
  634. GTP_ERROR("[burn_fw_section]hold ss51 & release dsp fail.");
  635. return FAIL;
  636. }
  637. /* must delay */
  638. msleep(20);
  639. /* step7:send burn cmd to move data to flash from sram */
  640. ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, bank_cmd & 0x0f);
  641. if (ret <= 0) {
  642. GTP_ERROR("[burn_fw_section]send burn cmd fail.");
  643. return FAIL;
  644. }
  645. GTP_DEBUG("[burn_fw_section]Wait for the burn is complete......");
  646. do {
  647. ret = gup_get_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, rd_buf, 1);
  648. if (ret <= 0) {
  649. GTP_ERROR("[burn_fw_section]Get burn state fail");
  650. return FAIL;
  651. }
  652. msleep(20);
  653. /* GTP_DEBUG("[burn_fw_section]Get burn state:%d.", rd_buf[GTP_ADDR_LENGTH]); */
  654. } while (rd_buf[GTP_ADDR_LENGTH]);
  655. /* step8:select bank */
  656. ret = gup_set_ic_msg(client, _bRW_MISCTL__SRAM_BANK, (bank_cmd >> 4) & 0x0F);
  657. if (ret <= 0) {
  658. GTP_ERROR("[burn_fw_section]select bank %d fail.", (bank_cmd >> 4) & 0x0F);
  659. return FAIL;
  660. }
  661. /* step9:enable accessing code */
  662. ret = gup_set_ic_msg(client, _bRW_MISCTL__MEM_CD_EN, 0x01);
  663. if (ret <= 0) {
  664. GTP_ERROR("[burn_fw_section]enable accessing code fail.");
  665. return FAIL;
  666. }
  667. /* step10:recall 8k fw section */
  668. ret = gup_recall_check(client, fw_section, start_addr, FW_SECTION_LENGTH);
  669. if (FAIL == ret) {
  670. GTP_ERROR("[burn_fw_section]recall check 8k firmware fail.");
  671. return FAIL;
  672. }
  673. /* step11:disable accessing code */
  674. ret = gup_set_ic_msg(client, _bRW_MISCTL__MEM_CD_EN, 0x00);
  675. if (ret <= 0) {
  676. GTP_ERROR("[burn_fw_section]disable accessing code fail.");
  677. return FAIL;
  678. }
  679. return SUCCESS;
  680. }
  681. static u8 gup_burn_dsp_isp(struct i2c_client *client)
  682. {
  683. s32 ret = 0;
  684. u8 *fw_dsp_isp = NULL;
  685. u8 retry = 0;
  686. GTP_DEBUG("[burn_dsp_isp]Begin burn dsp isp---->>");
  687. /* step1:alloc memory */
  688. GTP_DEBUG("[burn_dsp_isp]step1:alloc memory");
  689. while (retry++ < 5) {
  690. fw_dsp_isp = kzalloc(FW_DSP_ISP_LENGTH, GFP_KERNEL);
  691. if (fw_dsp_isp == NULL) {
  692. continue;
  693. } else {
  694. GTP_INFO("[burn_dsp_isp]Alloc %dk byte memory success.",
  695. (FW_DSP_ISP_LENGTH / 1024));
  696. break;
  697. }
  698. }
  699. if (retry >= 5) {
  700. GTP_ERROR("[burn_dsp_isp]Alloc memory fail,exit.");
  701. return FAIL;
  702. }
  703. /* step2:load dsp isp file data */
  704. GTP_DEBUG("[burn_dsp_isp]step2:load dsp isp file data");
  705. ret =
  706. gup_load_section_file(fw_dsp_isp,
  707. (4 * FW_SECTION_LENGTH + FW_DSP_LENGTH + FW_BOOT_LENGTH),
  708. FW_DSP_ISP_LENGTH);
  709. if (FAIL == ret) {
  710. GTP_ERROR("[burn_dsp_isp]load firmware dsp_isp fail.");
  711. goto exit_burn_dsp_isp;
  712. }
  713. /* step3:disable wdt,clear cache enable */
  714. GTP_DEBUG("[burn_dsp_isp]step3:disable wdt,clear cache enable");
  715. ret = gup_set_ic_msg(client, _bRW_MISCTL__TMR0_EN, 0x00);
  716. if (ret <= 0) {
  717. GTP_ERROR("[burn_dsp_isp]disable wdt fail.");
  718. ret = FAIL;
  719. goto exit_burn_dsp_isp;
  720. }
  721. ret = gup_set_ic_msg(client, _bRW_MISCTL__CACHE_EN, 0x00);
  722. if (ret <= 0) {
  723. GTP_ERROR("[burn_dsp_isp]clear cache enable fail.");
  724. ret = FAIL;
  725. goto exit_burn_dsp_isp;
  726. }
  727. /* step4:hold ss51 & dsp */
  728. GTP_DEBUG("[burn_dsp_isp]step4:hold ss51 & dsp");
  729. ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x0C);
  730. if (ret <= 0) {
  731. GTP_ERROR("[burn_dsp_isp]hold ss51 & dsp fail.");
  732. ret = FAIL;
  733. goto exit_burn_dsp_isp;
  734. }
  735. /* step5:set boot from sram */
  736. GTP_DEBUG("[burn_dsp_isp]step5:set boot from sram");
  737. ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOTCTL_B0_, 0x02);
  738. if (ret <= 0) {
  739. GTP_ERROR("[burn_dsp_isp]set boot from sram fail.");
  740. ret = FAIL;
  741. goto exit_burn_dsp_isp;
  742. }
  743. /* step6:software reboot */
  744. GTP_DEBUG("[burn_dsp_isp]step6:software reboot");
  745. ret = gup_set_ic_msg(client, _bWO_MISCTL__CPU_SWRST_PULSE, 0x01);
  746. if (ret <= 0) {
  747. GTP_ERROR("[burn_dsp_isp]software reboot fail.");
  748. ret = FAIL;
  749. goto exit_burn_dsp_isp;
  750. }
  751. /* step7:select bank2 */
  752. GTP_DEBUG("[burn_dsp_isp]step7:select bank2");
  753. ret = gup_set_ic_msg(client, _bRW_MISCTL__SRAM_BANK, 0x02);
  754. if (ret <= 0) {
  755. GTP_ERROR("[burn_dsp_isp]select bank2 fail.");
  756. ret = FAIL;
  757. goto exit_burn_dsp_isp;
  758. }
  759. /* step8:enable accessing code */
  760. GTP_DEBUG("[burn_dsp_isp]step8:enable accessing code");
  761. ret = gup_set_ic_msg(client, _bRW_MISCTL__MEM_CD_EN, 0x01);
  762. if (ret <= 0) {
  763. GTP_ERROR("[burn_dsp_isp]enable accessing code fail.");
  764. ret = FAIL;
  765. goto exit_burn_dsp_isp;
  766. }
  767. /* step9:burn 4k dsp_isp */
  768. GTP_DEBUG("[burn_dsp_isp]step9:burn 4k dsp_isp");
  769. ret = gup_burn_proc(client, fw_dsp_isp, 0xC000, FW_DSP_ISP_LENGTH);
  770. if (FAIL == ret) {
  771. GTP_ERROR("[burn_dsp_isp]burn dsp_isp fail.");
  772. goto exit_burn_dsp_isp;
  773. }
  774. /* step10:set scramble */
  775. GTP_DEBUG("[burn_dsp_isp]step10:set scramble");
  776. ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_OPT_B0_, 0x00);
  777. if (ret <= 0) {
  778. GTP_ERROR("[burn_dsp_isp]set scramble fail.");
  779. ret = FAIL;
  780. goto exit_burn_dsp_isp;
  781. }
  782. ret = SUCCESS;
  783. exit_burn_dsp_isp:
  784. kfree(fw_dsp_isp);
  785. return ret;
  786. }
  787. static u8 gup_burn_fw_ss51(struct i2c_client *client)
  788. {
  789. u8 *fw_ss51 = NULL;
  790. u8 retry = 0;
  791. s32 ret = 0;
  792. GTP_DEBUG("[burn_fw_ss51]Begin burn ss51 firmware---->>");
  793. /* step1:alloc memory */
  794. GTP_DEBUG("[burn_fw_ss51]step1:alloc memory");
  795. while (retry++ < 5) {
  796. fw_ss51 = kzalloc(FW_SECTION_LENGTH, GFP_KERNEL);
  797. if (fw_ss51 == NULL) {
  798. continue;
  799. } else {
  800. GTP_INFO("[burn_fw_ss51]Alloc %dk byte memory success.",
  801. (FW_SECTION_LENGTH / 1024));
  802. break;
  803. }
  804. }
  805. if (retry >= 5) {
  806. GTP_ERROR("[burn_fw_ss51]Alloc memory fail,exit.");
  807. return FAIL;
  808. }
  809. /* step2:load ss51 firmware section 1 file data */
  810. GTP_DEBUG("[burn_fw_ss51]step2:load ss51 firmware section 1 file data");
  811. ret = gup_load_section_file(fw_ss51, 0, FW_SECTION_LENGTH);
  812. if (FAIL == ret) {
  813. GTP_ERROR("[burn_fw_ss51]load ss51 firmware section 1 fail.");
  814. goto exit_burn_fw_ss51;
  815. }
  816. /* step3:clear control flag */
  817. GTP_DEBUG("[burn_fw_ss51]step3:clear control flag");
  818. ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, 0x00);
  819. if (ret <= 0) {
  820. GTP_ERROR("[burn_fw_ss51]clear control flag fail.");
  821. ret = FAIL;
  822. goto exit_burn_fw_ss51;
  823. }
  824. /* step4:burn ss51 firmware section 1 */
  825. GTP_DEBUG("[burn_fw_ss51]step4:burn ss51 firmware section 1");
  826. ret = gup_burn_fw_section(client, fw_ss51, 0xC000, 0x01);
  827. if (FAIL == ret) {
  828. GTP_ERROR("[burn_fw_ss51]burn ss51 firmware section 1 fail.");
  829. goto exit_burn_fw_ss51;
  830. }
  831. /* step5:load ss51 firmware section 2 file data */
  832. GTP_DEBUG("[burn_fw_ss51]step5:load ss51 firmware section 2 file data");
  833. ret = gup_load_section_file(fw_ss51, FW_SECTION_LENGTH, FW_SECTION_LENGTH);
  834. if (FAIL == ret) {
  835. GTP_ERROR("[burn_fw_ss51]load ss51 firmware section 2 fail.");
  836. goto exit_burn_fw_ss51;
  837. }
  838. /* step6:burn ss51 firmware section 2 */
  839. GTP_DEBUG("[burn_fw_ss51]step6:burn ss51 firmware section 2");
  840. ret = gup_burn_fw_section(client, fw_ss51, 0xE000, 0x02);
  841. if (FAIL == ret) {
  842. GTP_ERROR("[burn_fw_ss51]burn ss51 firmware section 2 fail.");
  843. goto exit_burn_fw_ss51;
  844. }
  845. /* step7:load ss51 firmware section 3 file data */
  846. GTP_DEBUG("[burn_fw_ss51]step7:load ss51 firmware section 3 file data");
  847. ret = gup_load_section_file(fw_ss51, 2 * FW_SECTION_LENGTH, FW_SECTION_LENGTH);
  848. if (FAIL == ret) {
  849. GTP_ERROR("[burn_fw_ss51]load ss51 firmware section 3 fail.");
  850. goto exit_burn_fw_ss51;
  851. }
  852. /* step8:burn ss51 firmware section 3 */
  853. GTP_DEBUG("[burn_fw_ss51]step8:burn ss51 firmware section 3");
  854. ret = gup_burn_fw_section(client, fw_ss51, 0xC000, 0x13);
  855. if (FAIL == ret) {
  856. GTP_ERROR("[burn_fw_ss51]burn ss51 firmware section 3 fail.");
  857. goto exit_burn_fw_ss51;
  858. }
  859. /* step9:load ss51 firmware section 4 file data */
  860. GTP_DEBUG("[burn_fw_ss51]step9:load ss51 firmware section 4 file data");
  861. ret = gup_load_section_file(fw_ss51, 3 * FW_SECTION_LENGTH, FW_SECTION_LENGTH);
  862. if (FAIL == ret) {
  863. GTP_ERROR("[burn_fw_ss51]load ss51 firmware section 4 fail.");
  864. goto exit_burn_fw_ss51;
  865. }
  866. /* step10:burn ss51 firmware section 4 */
  867. GTP_DEBUG("[burn_fw_ss51]step10:burn ss51 firmware section 4");
  868. ret = gup_burn_fw_section(client, fw_ss51, 0xE000, 0x14);
  869. if (FAIL == ret) {
  870. GTP_ERROR("[burn_fw_ss51]burn ss51 firmware section 4 fail.");
  871. goto exit_burn_fw_ss51;
  872. }
  873. ret = SUCCESS;
  874. exit_burn_fw_ss51:
  875. kfree(fw_ss51);
  876. return ret;
  877. }
  878. static u8 gup_burn_fw_dsp(struct i2c_client *client)
  879. {
  880. s32 ret = 0;
  881. u8 *fw_dsp = NULL;
  882. u8 retry = 0;
  883. u8 rd_buf[5];
  884. GTP_DEBUG("[burn_fw_dsp]Begin burn dsp firmware---->>");
  885. /* step1:alloc memory */
  886. GTP_DEBUG("[burn_fw_dsp]step1:alloc memory");
  887. while (retry++ < 5) {
  888. fw_dsp = kzalloc(FW_DSP_LENGTH, GFP_KERNEL);
  889. if (fw_dsp == NULL) {
  890. continue;
  891. } else {
  892. GTP_INFO("[burn_fw_dsp]Alloc %dk byte memory success.",
  893. (FW_SECTION_LENGTH / 1024));
  894. break;
  895. }
  896. }
  897. if (retry >= 5) {
  898. GTP_ERROR("[burn_fw_dsp]Alloc memory fail,exit.");
  899. return FAIL;
  900. }
  901. /* step2:load firmware dsp */
  902. GTP_DEBUG("[burn_fw_dsp]step2:load firmware dsp");
  903. ret = gup_load_section_file(fw_dsp, 4 * FW_SECTION_LENGTH, FW_DSP_LENGTH);
  904. if (FAIL == ret) {
  905. GTP_ERROR("[burn_fw_dsp]load firmware dsp fail.");
  906. goto exit_burn_fw_dsp;
  907. }
  908. /* step3:select bank3 */
  909. GTP_DEBUG("[burn_fw_dsp]step3:select bank3");
  910. ret = gup_set_ic_msg(client, _bRW_MISCTL__SRAM_BANK, 0x03);
  911. if (ret <= 0) {
  912. GTP_ERROR("[burn_fw_dsp]select bank3 fail.");
  913. ret = FAIL;
  914. goto exit_burn_fw_dsp;
  915. }
  916. /* step4:hold ss51 & dsp */
  917. GTP_DEBUG("[burn_fw_dsp]step4:hold ss51 & dsp");
  918. ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x0C);
  919. if (ret <= 0) {
  920. GTP_ERROR("[burn_fw_dsp]hold ss51 & dsp fail.");
  921. ret = FAIL;
  922. goto exit_burn_fw_dsp;
  923. }
  924. /* step5:set scramble */
  925. GTP_DEBUG("[burn_fw_dsp]step5:set scramble");
  926. ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_OPT_B0_, 0x00);
  927. if (ret <= 0) {
  928. GTP_ERROR("[burn_fw_dsp]set scramble fail.");
  929. ret = FAIL;
  930. goto exit_burn_fw_dsp;
  931. }
  932. /* step6:release ss51 & dsp */
  933. GTP_DEBUG("[burn_fw_dsp]step6:release ss51 & dsp");
  934. ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x00);
  935. if (ret <= 0) {
  936. GTP_ERROR("[burn_fw_dsp]release ss51 & dsp fail.");
  937. ret = FAIL;
  938. goto exit_burn_fw_dsp;
  939. }
  940. /* must delay */
  941. msleep(20);
  942. /* step7:burn 4k dsp firmware */
  943. GTP_DEBUG("[burn_fw_dsp]step7:burn 4k dsp firmware");
  944. ret = gup_burn_proc(client, fw_dsp, 0x9000, FW_DSP_LENGTH);
  945. if (FAIL == ret) {
  946. GTP_ERROR("[burn_fw_dsp]burn fw_section fail.");
  947. goto exit_burn_fw_dsp;
  948. }
  949. /* step8:send burn cmd to move data to flash from sram */
  950. GTP_DEBUG("[burn_fw_dsp]step8:send burn cmd to move data to flash from sram");
  951. ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, 0x05);
  952. if (ret <= 0) {
  953. GTP_ERROR("[burn_fw_dsp]send burn cmd fail.");
  954. goto exit_burn_fw_dsp;
  955. }
  956. GTP_DEBUG("[burn_fw_dsp]Wait for the burn is complete......");
  957. do {
  958. ret = gup_get_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, rd_buf, 1);
  959. if (ret <= 0) {
  960. GTP_ERROR("[burn_fw_dsp]Get burn state fail");
  961. goto exit_burn_fw_dsp;
  962. }
  963. msleep(20);
  964. /* GTP_DEBUG("[burn_fw_dsp]Get burn state:%d.", rd_buf[GTP_ADDR_LENGTH]); */
  965. } while (rd_buf[GTP_ADDR_LENGTH]);
  966. /* step9:recall check 4k dsp firmware */
  967. GTP_DEBUG("[burn_fw_dsp]step9:recall check 4k dsp firmware");
  968. ret = gup_recall_check(client, fw_dsp, 0x9000, FW_DSP_LENGTH);
  969. if (FAIL == ret) {
  970. GTP_ERROR("[burn_fw_dsp]recall check 4k dsp firmware fail.");
  971. goto exit_burn_fw_dsp;
  972. }
  973. ret = SUCCESS;
  974. exit_burn_fw_dsp:
  975. kfree(fw_dsp);
  976. return ret;
  977. }
  978. static u8 gup_burn_fw_boot(struct i2c_client *client)
  979. {
  980. s32 ret = 0;
  981. u8 *fw_boot = NULL;
  982. u8 retry = 0;
  983. u8 rd_buf[5];
  984. GTP_DEBUG("[burn_fw_boot]Begin burn bootloader firmware---->>");
  985. /* step1:Alloc memory */
  986. GTP_DEBUG("[burn_fw_boot]step1:Alloc memory");
  987. while (retry++ < 5) {
  988. fw_boot = kzalloc(FW_BOOT_LENGTH, GFP_KERNEL);
  989. if (fw_boot == NULL) {
  990. continue;
  991. } else {
  992. GTP_INFO("[burn_fw_boot]Alloc %dk byte memory success.",
  993. (FW_BOOT_LENGTH / 1024));
  994. break;
  995. }
  996. }
  997. if (retry >= 5) {
  998. GTP_ERROR("[burn_fw_boot]Alloc memory fail,exit.");
  999. return FAIL;
  1000. }
  1001. /* step2:load firmware bootloader */
  1002. GTP_DEBUG("[burn_fw_boot]step2:load firmware bootloader");
  1003. ret =
  1004. gup_load_section_file(fw_boot, (4 * FW_SECTION_LENGTH + FW_DSP_LENGTH), FW_BOOT_LENGTH);
  1005. if (FAIL == ret) {
  1006. GTP_ERROR("[burn_fw_boot]load firmware dsp fail.");
  1007. goto exit_burn_fw_boot;
  1008. }
  1009. /* step3:hold ss51 & dsp */
  1010. GTP_DEBUG("[burn_fw_boot]step3:hold ss51 & dsp");
  1011. ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x0C);
  1012. if (ret <= 0) {
  1013. GTP_ERROR("[burn_fw_boot]hold ss51 & dsp fail.");
  1014. ret = FAIL;
  1015. goto exit_burn_fw_boot;
  1016. }
  1017. /* step4:set scramble */
  1018. GTP_DEBUG("[burn_fw_boot]step4:set scramble");
  1019. ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_OPT_B0_, 0x00);
  1020. if (ret <= 0) {
  1021. GTP_ERROR("[burn_fw_boot]set scramble fail.");
  1022. ret = FAIL;
  1023. goto exit_burn_fw_boot;
  1024. }
  1025. /* step5:release ss51 & dsp */
  1026. GTP_DEBUG("[burn_fw_boot]step5:release ss51 & dsp");
  1027. ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x00);
  1028. if (ret <= 0) {
  1029. GTP_ERROR("[burn_fw_boot]release ss51 & dsp fail.");
  1030. ret = FAIL;
  1031. goto exit_burn_fw_boot;
  1032. }
  1033. /* must delay */
  1034. msleep(20);
  1035. /* step6:burn 2k bootloader firmware */
  1036. GTP_DEBUG("[burn_fw_boot]step6:burn 2k bootloader firmware");
  1037. ret = gup_burn_proc(client, fw_boot, 0x9000, FW_BOOT_LENGTH);
  1038. if (FAIL == ret) {
  1039. GTP_ERROR("[burn_fw_boot]burn fw_section fail.");
  1040. goto exit_burn_fw_boot;
  1041. }
  1042. /* step7:send burn cmd to move data to flash from sram */
  1043. GTP_DEBUG("[burn_fw_boot]step7:send burn cmd to move data to flash from sram");
  1044. ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, 0x06);
  1045. if (ret <= 0) {
  1046. GTP_ERROR("[burn_fw_boot]send burn cmd fail.");
  1047. goto exit_burn_fw_boot;
  1048. }
  1049. GTP_DEBUG("[burn_fw_boot]Wait for the burn is complete......");
  1050. do {
  1051. ret = gup_get_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, rd_buf, 1);
  1052. if (ret <= 0) {
  1053. GTP_ERROR("[burn_fw_boot]Get burn state fail");
  1054. goto exit_burn_fw_boot;
  1055. }
  1056. msleep(20);
  1057. /* GTP_DEBUG("[burn_fw_boot]Get burn state:%d.", rd_buf[GTP_ADDR_LENGTH]); */
  1058. } while (rd_buf[GTP_ADDR_LENGTH]);
  1059. /* step8:recall check 2k bootloader firmware */
  1060. GTP_DEBUG("[burn_fw_boot]step8:recall check 2k bootloader firmware");
  1061. ret = gup_recall_check(client, fw_boot, 0x9000, FW_BOOT_LENGTH);
  1062. if (FAIL == ret) {
  1063. GTP_ERROR("[burn_fw_boot]recall check 4k dsp firmware fail.");
  1064. goto exit_burn_fw_boot;
  1065. }
  1066. /* step9:enable download DSP code */
  1067. GTP_DEBUG("[burn_fw_boot]step9:enable download DSP code ");
  1068. ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, 0x99);
  1069. if (ret <= 0) {
  1070. GTP_ERROR("[burn_fw_boot]enable download DSP code fail.");
  1071. ret = FAIL;
  1072. goto exit_burn_fw_boot;
  1073. }
  1074. /* step10:release ss51 & hold dsp */
  1075. GTP_DEBUG("[burn_fw_boot]step10:release ss51 & hold dsp");
  1076. ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x08);
  1077. if (ret <= 0) {
  1078. GTP_ERROR("[burn_fw_boot]release ss51 & hold dsp fail.");
  1079. ret = FAIL;
  1080. goto exit_burn_fw_boot;
  1081. }
  1082. ret = SUCCESS;
  1083. exit_burn_fw_boot:
  1084. kfree(fw_boot);
  1085. return ret;
  1086. }
  1087. s32 gup_update_proc(void *dir)
  1088. {
  1089. s32 ret = 0;
  1090. u8 retry = 0;
  1091. struct st_fw_head fw_head;
  1092. GTP_DEBUG("[update_proc]Begin update ......");
  1093. fw_buf = kzalloc(FW_LENGTH, GFP_KERNEL);
  1094. show_len = 1;
  1095. total_len = 100;
  1096. if (dir == NULL)
  1097. msleep(3000); /* wait main thread to be completed */
  1098. if (guitar_client == NULL) /* 20121212 */
  1099. guitar_client = i2c_client_point;
  1100. ret = gup_check_update_file(guitar_client, &fw_head, (u8 *) dir); /* 20121212 */
  1101. if (FAIL == ret) {
  1102. GTP_ERROR("[update_proc]check update file fail.");
  1103. goto update_fail;
  1104. }
  1105. /* gtp_reset_guitar(guitar_client, 20); //no need 20130419 */
  1106. ret = gup_get_ic_fw_msg(guitar_client);
  1107. if (FAIL == ret) {
  1108. GTP_ERROR("[update_proc]get ic message fail.");
  1109. goto update_fail;
  1110. }
  1111. ret = gup_enter_upadte_judge(&fw_head); /* 20121212 */
  1112. #ifdef GTP_FORCE_UPDATE_FW
  1113. ret = SUCCESS; /* for test */
  1114. #endif
  1115. if (FAIL == ret) {
  1116. GTP_ERROR("[update_proc]check update file fail.");
  1117. goto update_fail;
  1118. }
  1119. ret = gup_enter_update_mode(guitar_client);
  1120. if (FAIL == ret) {
  1121. GTP_ERROR("[update_proc]enter update mode fail.");
  1122. goto update_fail;
  1123. }
  1124. while (retry++ < 5) {
  1125. show_len = 10;
  1126. total_len = 100;
  1127. ret = gup_burn_dsp_isp(guitar_client);
  1128. if (FAIL == ret) {
  1129. GTP_ERROR("[update_proc]burn dsp isp fail.");
  1130. continue;
  1131. }
  1132. show_len += 10;
  1133. ret = gup_burn_fw_ss51(guitar_client);
  1134. if (FAIL == ret) {
  1135. GTP_ERROR("[update_proc]burn ss51 firmware fail.");
  1136. continue;
  1137. }
  1138. show_len += 40;
  1139. ret = gup_burn_fw_dsp(guitar_client);
  1140. if (FAIL == ret) {
  1141. GTP_ERROR("[update_proc]burn dsp firmware fail.");
  1142. continue;
  1143. }
  1144. show_len += 20;
  1145. ret = gup_burn_fw_boot(guitar_client);
  1146. if (FAIL == ret) {
  1147. GTP_ERROR("[update_proc]burn bootloader firmware fail.");
  1148. continue;
  1149. }
  1150. show_len += 10;
  1151. GTP_INFO("[update_proc]UPDATE SUCCESS.");
  1152. break;
  1153. }
  1154. if (retry >= 5) {
  1155. GTP_ERROR("[update_proc]retry timeout,UPDATE FAIL.");
  1156. goto update_fail;
  1157. }
  1158. /* original source code */
  1159. /*
  1160. GTP_DEBUG("[update_proc]leave update mode.");
  1161. gup_leave_update_mode();
  1162. */
  1163. /* Modified by Andrew --start */
  1164. /* GTP_DEBUG("[update_proc]reset chip."); */
  1165. /* gtp_reset_guitar(guitar_client, 20); */
  1166. /* Modified by Andrew --end */
  1167. #if 0
  1168. msleep(100);
  1169. GTP_DEBUG("[update_proc]send config.");
  1170. ret = gtp_send_cfg(guitar_client);
  1171. if (ret < 0)
  1172. GTP_ERROR("[update_proc]send config fail.");
  1173. #endif
  1174. show_len = 100;
  1175. total_len = 100;
  1176. kfree(fw_buf);
  1177. /* Modified by Andrew --start */
  1178. GTP_DEBUG("[update_proc]leave update mode.");
  1179. gup_leave_update_mode();
  1180. /* Modified by Andrew --end */
  1181. return SUCCESS;
  1182. update_fail:
  1183. show_len = 200;
  1184. total_len = 100;
  1185. kfree(fw_buf);
  1186. return FAIL;
  1187. }
  1188. u8 gup_init_update_proc(struct i2c_client *client)
  1189. {
  1190. struct task_struct *thread = NULL;
  1191. GTP_INFO("Ready to run update thread.");
  1192. guitar_client = client;
  1193. GTP_INFO("Ready to run update thread");
  1194. thread = kthread_run(gup_update_proc, (void *)NULL, "guitar_update");
  1195. if (IS_ERR(thread)) {
  1196. GTP_ERROR("Failed to create update thread.\n");
  1197. return -1;
  1198. }
  1199. return 0;
  1200. }
  1201. static u8 gup_download_fw_ss51(struct i2c_client *client)
  1202. {
  1203. u8 *fw_ss51 = NULL;
  1204. u8 retry = 0;
  1205. s32 ret = 0;
  1206. GTP_INFO("[download_fw_ss51]Begin burn ss51 firmware---->>");
  1207. /* step1:alloc memory */
  1208. GTP_DEBUG("[download_fw_ss51]step1:alloc memory");
  1209. while (retry++ < 5) {
  1210. fw_ss51 = kzalloc(2 * FW_DOWNLOAD_LENGTH, GFP_KERNEL);
  1211. if (fw_ss51 == NULL) {
  1212. continue;
  1213. } else {
  1214. GTP_INFO("[download_fw_ss51]Alloc %dk byte memory success.",
  1215. (FW_DOWNLOAD_LENGTH / 1024));
  1216. break;
  1217. }
  1218. }
  1219. if (retry >= 5) {
  1220. GTP_ERROR("[download_fw_ss51]Alloc memory fail,exit.");
  1221. return FAIL;
  1222. }
  1223. /* step2:clear control flag */
  1224. GTP_DEBUG("[download_fw_ss51]step2:clear control flag");
  1225. ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, 0x00);
  1226. if (ret <= 0) {
  1227. GTP_ERROR("[download_fw_ss51]clear control flag fail.");
  1228. ret = FAIL;
  1229. goto exit_download_fw_ss51;
  1230. }
  1231. /* step3:disable wdt,clear cache enable */
  1232. GTP_DEBUG("[download_fw_ss51]step3:disable wdt,clear cache enable");
  1233. ret = gup_set_ic_msg(client, _bRW_MISCTL__TMR0_EN, 0x00);
  1234. if (ret <= 0) {
  1235. GTP_ERROR("[download_fw_ss51]disable wdt fail.");
  1236. ret = FAIL;
  1237. goto exit_download_fw_ss51;
  1238. }
  1239. ret = gup_set_ic_msg(client, _bRW_MISCTL__CACHE_EN, 0x00);
  1240. if (ret <= 0) {
  1241. GTP_ERROR("[download_fw_ss51]clear cache enable fail.");
  1242. ret = FAIL;
  1243. goto exit_download_fw_ss51;
  1244. }
  1245. /* step4:hold ss51 & dsp */
  1246. GTP_DEBUG("[download_fw_ss51]step4:hold ss51 & dsp");
  1247. ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x0C);
  1248. if (ret <= 0) {
  1249. GTP_ERROR("[download_fw_ss51]hold ss51 & dsp fail.");
  1250. ret = FAIL;
  1251. goto exit_download_fw_ss51;
  1252. }
  1253. msleep(20);
  1254. /* step5:set boot from sram */
  1255. GTP_DEBUG("[download_fw_ss51]step5:set boot from sram");
  1256. ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOTCTL_B0_, 0x02);
  1257. if (ret <= 0) {
  1258. GTP_ERROR("[download_fw_ss51]set boot from sram fail.");
  1259. ret = FAIL;
  1260. goto exit_download_fw_ss51;
  1261. }
  1262. /* step6:software reboot */
  1263. GTP_DEBUG("[download_fw_ss51]step6:software reboot");
  1264. ret = gup_set_ic_msg(client, _bWO_MISCTL__CPU_SWRST_PULSE, 0x01);
  1265. if (ret <= 0) {
  1266. GTP_ERROR("[download_fw_ss51]software reboot fail.");
  1267. ret = FAIL;
  1268. goto exit_download_fw_ss51;
  1269. }
  1270. msleep(20);
  1271. /* step7:load ss51 firmware section 1 file data */
  1272. GTP_DEBUG("[download_fw_ss51]step7:load ss51 firmware section 1 file data");
  1273. ret = gup_load_section_file(fw_ss51, 0, 2 * FW_DOWNLOAD_LENGTH);
  1274. if (FAIL == ret) {
  1275. GTP_ERROR("[download_fw_ss51]load ss51 firmware section 1 fail.");
  1276. goto exit_download_fw_ss51;
  1277. }
  1278. ret = gup_set_ic_msg(guitar_client, _bRW_MISCTL__SRAM_BANK, 0x00);
  1279. ret = gup_set_ic_msg(guitar_client, _bRW_MISCTL__MEM_CD_EN, 0x01);
  1280. ret = i2c_write_bytes(client, 0xC000, fw_ss51, FW_DOWNLOAD_LENGTH); /* write the first bank */
  1281. if (ret == -1) {
  1282. GTP_ERROR("[download_fw_dsp]download FW section 1 fail.");
  1283. goto exit_download_fw_ss51;
  1284. }
  1285. ret = gup_set_ic_msg(guitar_client, _bRW_MISCTL__SRAM_BANK, 0x01);
  1286. ret = gup_set_ic_msg(guitar_client, _bRW_MISCTL__MEM_CD_EN, 0x01);
  1287. ret = i2c_write_bytes(client, 0xC000,
  1288. &fw_ss51[FW_DOWNLOAD_LENGTH], FW_DOWNLOAD_LENGTH); /* write the second bank */
  1289. if (ret == -1) {
  1290. GTP_ERROR("[download_fw_dsp]download FW section 2 fail.");
  1291. goto exit_download_fw_ss51;
  1292. }
  1293. ret = SUCCESS;
  1294. exit_download_fw_ss51:
  1295. kfree(fw_ss51);
  1296. return ret;
  1297. }
  1298. static u8 gup_download_fw_dsp(struct i2c_client *client)
  1299. {
  1300. s32 ret = 0;
  1301. u8 *fw_dsp = NULL;
  1302. u8 retry = 0;
  1303. GTP_INFO("[download_fw_dsp]Begin download dsp firmware---->>");
  1304. /* step1:alloc memory */
  1305. GTP_DEBUG("[download_fw_dsp]step1:alloc memory");
  1306. while (retry++ < 5) {
  1307. fw_dsp = kzalloc(FW_DSP_LENGTH, GFP_KERNEL);
  1308. if (fw_dsp == NULL) {
  1309. continue;
  1310. } else {
  1311. GTP_INFO("[download_fw_dsp]Alloc %dk byte memory success.",
  1312. (FW_SECTION_LENGTH / 1024));
  1313. break;
  1314. }
  1315. }
  1316. if (retry >= 5) {
  1317. GTP_ERROR("[download_fw_dsp]Alloc memory fail,exit.");
  1318. return FAIL;
  1319. }
  1320. /* step2:load firmware dsp */
  1321. GTP_DEBUG("[download_fw_dsp]step2:load firmware dsp");
  1322. ret = gup_load_section_file(fw_dsp, 4 * FW_SECTION_LENGTH, FW_DSP_LENGTH);
  1323. if (FAIL == ret) {
  1324. GTP_ERROR("[download_fw_dsp]load firmware dsp fail.");
  1325. goto exit_download_fw_dsp;
  1326. }
  1327. /* step3:select bank2 */
  1328. GTP_DEBUG("[download_fw_dsp]step3:select bank2");
  1329. ret = gup_set_ic_msg(client, _bRW_MISCTL__SRAM_BANK, 0x02);
  1330. if (ret <= 0) {
  1331. GTP_ERROR("[download_fw_dsp]select bank2 fail.");
  1332. ret = FAIL;
  1333. goto exit_download_fw_dsp;
  1334. }
  1335. /* step4:enable accessing code */
  1336. ret = gup_set_ic_msg(client, _bRW_MISCTL__MEM_CD_EN, 0x01);
  1337. if (ret <= 0) {
  1338. GTP_ERROR("[download_fw_dsp]enable accessing code fail.");
  1339. ret = FAIL;
  1340. goto exit_download_fw_dsp;
  1341. }
  1342. ret = i2c_write_bytes(client, 0xC000, fw_dsp, FW_DSP_LENGTH); /* write the second bank */
  1343. ret = SUCCESS;
  1344. exit_download_fw_dsp:
  1345. kfree(fw_dsp);
  1346. return ret;
  1347. }
  1348. s32 gup_fw_download_proc(void *dir)
  1349. {
  1350. u8 buf[3];
  1351. s32 ret = 0;
  1352. u8 retry = 0;
  1353. struct st_fw_head fw_head;
  1354. GTP_INFO("[fw_download_proc]Begin fw download ......");
  1355. fw_buf = kzalloc(FW_LENGTH, GFP_KERNEL);
  1356. if (dir == NULL)
  1357. msleep(2000); /* wait main thread to be completed */
  1358. if (guitar_client == NULL) { /* 20121212 */
  1359. guitar_client = i2c_client_point;
  1360. }
  1361. download:
  1362. ret = gup_check_update_file(guitar_client, &fw_head, (u8 *) dir);
  1363. if (FAIL == ret) {
  1364. GTP_ERROR("[fw_download_proc]check update file fail.");
  1365. goto download_fail;
  1366. }
  1367. /* gtp_reset_guitar(guitar_client, 20); //no need 20130419 */
  1368. ret = gup_get_ic_fw_msg(guitar_client);
  1369. if (FAIL == ret) {
  1370. GTP_ERROR("[fw_download_proc]get ic message fail.");
  1371. goto download_fail;
  1372. }
  1373. ret = gup_enter_upadte_judge(&fw_head); /* 20121212 */
  1374. if (FAIL == ret) {
  1375. GTP_ERROR("[update_proc]Check *.bin file fail.");
  1376. goto download_fail;
  1377. }
  1378. ret = gup_enter_update_mode(guitar_client); /* 20121212 */
  1379. if (FAIL == ret) {
  1380. GTP_ERROR("[fw_download_proc]check update file fail.");
  1381. goto download_fail;
  1382. }
  1383. while (retry++ < 5) {
  1384. ret = gup_download_fw_ss51(guitar_client);
  1385. if (FAIL == ret) {
  1386. GTP_ERROR("[fw_download_proc]burn ss51 firmware fail.");
  1387. continue;
  1388. }
  1389. ret = gup_download_fw_dsp(guitar_client);
  1390. if (FAIL == ret) {
  1391. GTP_ERROR("[fw_download_proc]burn dsp firmware fail.");
  1392. continue;
  1393. }
  1394. GTP_INFO("[fw_download_proc]UPDATE SUCCESS.");
  1395. break;
  1396. }
  1397. if (retry >= 5) {
  1398. GTP_ERROR("[fw_download_proc]retry timeout,UPDATE FAIL.");
  1399. goto download_fail;
  1400. }
  1401. /* -- set scramble */
  1402. GTP_DEBUG("[download_fw_dsp]step5:set scramble");
  1403. ret = gup_set_ic_msg(guitar_client, _rRW_MISCTL__BOOT_OPT_B0_, 0x00);
  1404. if (ret <= 0) {
  1405. GTP_ERROR("[download_fw_dsp]set scramble fail.");
  1406. ret = FAIL;
  1407. goto download_fail;
  1408. }
  1409. /* -- clear control flag */
  1410. GTP_DEBUG("[burn_fw_ss51]step3:clear control flag");
  1411. ret = gup_set_ic_msg(guitar_client, _rRW_MISCTL__BOOT_CTL_, 0xAA);
  1412. if (ret <= 0) {
  1413. GTP_ERROR("[burn_fw_ss51]clear control flag fail.");
  1414. ret = FAIL;
  1415. goto download_fail;
  1416. }
  1417. /* -- hold ss51 & dsp */
  1418. GTP_DEBUG("[download_fw_dsp]step4:hold ss51 & dsp");
  1419. ret = gup_set_ic_msg(guitar_client, _rRW_MISCTL__SWRST_B0_, 0x00);
  1420. if (ret <= 0) {
  1421. GTP_ERROR("[download_fw_dsp]hold ss51 & dsp fail.");
  1422. ret = FAIL;
  1423. goto download_fail;
  1424. }
  1425. msleep(20);
  1426. gup_get_ic_msg(guitar_client, GUP_REG_FW_MSG, buf, 1);
  1427. GTP_DEBUG("[fw_download_proc] BOOT Status %02X\n", buf[2]);
  1428. if (buf[2] != 0xBE)
  1429. goto download;
  1430. #if 0
  1431. GTP_DEBUG("[fw_download_proc]send config.");
  1432. ret = gtp_send_cfg(guitar_client);
  1433. if (ret < 0)
  1434. GTP_ERROR("[fw_download_proc]send config fail.");
  1435. #endif
  1436. gtp_int_sync();
  1437. kfree(fw_buf);
  1438. return SUCCESS;
  1439. download_fail:
  1440. kfree(fw_buf);
  1441. return FAIL;
  1442. }
  1443. u8 gup_init_fw_proc(struct i2c_client *client)
  1444. {
  1445. struct task_struct *thread = NULL;
  1446. GTP_INFO("Ready to run fw download thread.");
  1447. guitar_client = client;
  1448. GTP_INFO("Ready to run fw download thread.");
  1449. thread = kthread_run(gup_fw_download_proc, (void *)NULL, "guitar_fw_download");
  1450. if (IS_ERR(thread)) {
  1451. GTP_ERROR("Failed to create fw download thread.\n");
  1452. return -1;
  1453. }
  1454. return 0;
  1455. }