gt9xx_update.c 88 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530
  1. /*
  2. * Copyright (C) 2010 - 2016 Goodix., Ltd.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be a reference
  10. * to you, when you are integrating the GOODiX's CTP IC into your system,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * Version: V2.6.0.3
  16. */
  17. #include "include/tpd_gt9xx_common.h"
  18. #include "tpd.h"
  19. #include <linux/delay.h>
  20. #include <linux/firmware.h>
  21. #include <linux/i2c.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/kthread.h>
  24. #include <linux/mount.h>
  25. #include <linux/namei.h>
  26. #include <linux/sched.h>
  27. #include <linux/time.h>
  28. #include <linux/uaccess.h>
  29. #include <linux/wait.h>
  30. #ifdef CONFIG_GTP_REQUEST_FW_UPDATE
  31. #define GT9XX_FW_NAME "gt9xx_fw.bin"
  32. #endif
  33. #ifdef CONFIG_GTP_HOTKNOT
  34. #define GT9XX_HN_AUTH_FW_NAME "gt9xx_hn_auth_fw.bin"
  35. #define GT9XX_HN_TRANS_FW_NAME "gt9xx_hn_trans_fw.bin"
  36. #endif
  37. #define GUP_REG_HW_INFO 0x4220
  38. #define GUP_REG_FW_MSG 0x41E4
  39. #define GUP_REG_PID_VID 0x8140
  40. #define GUP_SEARCH_FILE_TIMES 50
  41. #define UPDATE_FILE_PATH_1 "/data/_goodix_update_.bin"
  42. #define UPDATE_FILE_PATH_2 "/sdcard/_goodix_update_.bin"
  43. #define CONFIG_FILE_PATH_1 "/data/_goodix_config_.cfg"
  44. #define CONFIG_FILE_PATH_2 "/sdcard/_goodix_config_.cfg"
  45. #define FW_HEAD_LENGTH 14
  46. #define FW_DOWNLOAD_LENGTH 0x4000
  47. #define FW_SECTION_LENGTH 0x2000
  48. #define FW_DSP_ISP_LENGTH 0x1000
  49. #define FW_DSP_LENGTH 0x1000
  50. #define FW_BOOT_LENGTH 0x800
  51. #define FW_SS51_LENGTH (4 * FW_SECTION_LENGTH)
  52. #define FW_BOOT_ISP_LENGTH 0x800 /* 2k */
  53. #define FW_LINK_LENGTH 0x3000 /* 12k */
  54. #define FW_APP_CODE_LENGTH (4 * FW_SECTION_LENGTH) /* 32k */
  55. #define FIRMWARE_LENGTH \
  56. (FW_SS51_LENGTH + FW_DSP_LENGTH + FW_BOOT_LENGTH + FW_DSP_ISP_LENGTH + \
  57. FW_BOOT_ISP_LENGTH + FW_APP_CODE_LENGTH)
  58. #define FW_HOTKNOT_LENGTH 0x3000
  59. #define PACK_SIZE 256
  60. #define MAX_FRAME_CHECK_TIME 5
  61. #define _bRW_MISCTL__SRAM_BANK 0x4048
  62. #define _bRW_MISCTL__MEM_CD_EN 0x4049
  63. #define _bRW_MISCTL__CACHE_EN 0x404B
  64. #define _bRW_MISCTL__TMR0_EN 0x40B0
  65. #define _rRW_MISCTL__SWRST_B0_ 0x4180
  66. #define _bWO_MISCTL__CPU_SWRST_PULSE 0x4184
  67. #define _rRW_MISCTL__BOOTCTL_B0_ 0x4190
  68. #define _rRW_MISCTL__BOOT_OPT_B0_ 0x4218
  69. #define _rRW_MISCTL__BOOT_CTL_ 0x5094
  70. #define AUTO_SEARCH_BIN 0x01
  71. #define AUTO_SEARCH_CFG 0x02
  72. #define BIN_FILE_READY 0x80
  73. #define CFG_FILE_READY 0x08
  74. #define HEADER_FW_READY 0x01
  75. #define FAIL 0
  76. #define SUCCESS 1
  77. #pragma pack(1)
  78. struct st_fw_head {
  79. u8 hw_info[4]; /* hardware info */
  80. u8 pid[8]; /* product id */
  81. u16 vid; /* version id */
  82. };
  83. #pragma pack()
  84. struct st_update_msg {
  85. u8 force_update;
  86. u8 fw_flag;
  87. const struct firmware *fw; // 0705
  88. struct file *file;
  89. struct file *cfg_file;
  90. struct st_fw_head ic_fw_msg;
  91. mm_segment_t old_fs;
  92. u32 fw_total_len;
  93. u32 fw_burned_len;
  94. } st_update_msg;
  95. static struct st_update_msg update_msg;
  96. u16 show_len;
  97. u16 total_len;
  98. u8 searching_file;
  99. u8 got_file_flag;
  100. u8 gtp_loading_fw;
  101. #if defined(CONFIG_GTP_COMPATIBLE_MODE) || defined(CONFIG_GTP_HOTKNOT)
  102. static u8 gup_check_and_repair(struct i2c_client *, s32, u8 *, u32);
  103. #endif
  104. #define _CLOSE_FILE(p_file) \
  105. { \
  106. if (p_file && !IS_ERR(p_file)) \
  107. filp_close(p_file, NULL); \
  108. }
  109. static u8 gup_burn_fw_app_section(struct i2c_client *client, u8 *fw_section,
  110. u16 start_addr, u32 len, u8 bank_cmd);
  111. static s32 gup_i2c_read(struct i2c_client *client, u8 *buf, s32 len)
  112. {
  113. s32 ret = -1;
  114. u16 addr = (buf[0] << 8) + buf[1];
  115. ret = i2c_read_bytes(client, addr, &buf[2], len - 2);
  116. if (!ret)
  117. return 2;
  118. return ret;
  119. }
  120. static s32 gup_i2c_write(struct i2c_client *client, u8 *buf, s32 len)
  121. {
  122. s32 ret = -1;
  123. u16 addr = (buf[0] << 8) + buf[1];
  124. ret = i2c_write_bytes(client, addr, &buf[2], len - 2);
  125. if (!ret)
  126. return 1;
  127. return ret;
  128. }
  129. static u8 gup_get_ic_msg(struct i2c_client *client, u16 addr, u8 *msg, s32 len)
  130. {
  131. s32 i = 0;
  132. msg[0] = (addr >> 8) & 0xff;
  133. msg[1] = addr & 0xff;
  134. for (i = 0; i < 5; i++) {
  135. if (gup_i2c_read(client, msg, GTP_ADDR_LENGTH + len) > 0)
  136. break;
  137. }
  138. if (i >= 5) {
  139. GTP_ERROR("Read data from 0x%02x%02x failed!", msg[0], msg[1]);
  140. return FAIL;
  141. }
  142. return SUCCESS;
  143. }
  144. static u8 gup_set_ic_msg(struct i2c_client *client, u16 addr, u8 val)
  145. {
  146. s32 i = 0;
  147. u8 msg[3];
  148. msg[0] = (addr >> 8) & 0xff;
  149. msg[1] = addr & 0xff;
  150. msg[2] = val;
  151. for (i = 0; i < 5; i++) {
  152. if (gup_i2c_write(client, msg, GTP_ADDR_LENGTH + 1) > 0)
  153. break;
  154. }
  155. if (i >= 5) {
  156. GTP_ERROR("Set data to 0x%02x%02x failed!", msg[0], msg[1]);
  157. return FAIL;
  158. }
  159. return SUCCESS;
  160. }
  161. static u8 gup_get_ic_fw_msg(struct i2c_client *client)
  162. {
  163. s32 ret = -1;
  164. u8 retry = 0;
  165. u8 buf[16];
  166. u8 i;
  167. /* step1:get hardware info */
  168. ret = gtp_i2c_read_dbl_check(client, GUP_REG_HW_INFO,
  169. &buf[GTP_ADDR_LENGTH], 4);
  170. if (ret == FAIL) {
  171. GTP_ERROR("[get_ic_fw_msg]get hw_info failed,exit");
  172. return FAIL;
  173. }
  174. /* buf[2~5]: 00 06 90 00 */
  175. /* hw_info: 00 90 06 00 */
  176. for (i = 0; i < 4; i++)
  177. update_msg.ic_fw_msg.hw_info[i] = buf[GTP_ADDR_LENGTH + 3 - i];
  178. GTP_INFO("IC Hardware info:%02x%02x%02x%02x",
  179. update_msg.ic_fw_msg.hw_info[0],
  180. update_msg.ic_fw_msg.hw_info[1],
  181. update_msg.ic_fw_msg.hw_info[2],
  182. update_msg.ic_fw_msg.hw_info[3]);
  183. /* step2:get firmware message */
  184. for (retry = 0; retry < 2; retry++) {
  185. ret = gup_get_ic_msg(client, GUP_REG_FW_MSG, buf, 1);
  186. if (ret == FAIL) {
  187. GTP_ERROR("Read firmware message fail.");
  188. return ret;
  189. }
  190. update_msg.force_update = buf[GTP_ADDR_LENGTH];
  191. if (update_msg.force_update != 0xBE) {
  192. GTP_INFO("The check sum in ic is error.");
  193. GTP_INFO("The IC will be updated by force.");
  194. continue;
  195. }
  196. break;
  197. }
  198. GTP_INFO("IC force update flag:0x%x", update_msg.force_update);
  199. /* step3:get pid & vid */
  200. ret = gtp_i2c_read_dbl_check(client, GUP_REG_PID_VID,
  201. &buf[GTP_ADDR_LENGTH], 6);
  202. if (ret == FAIL) {
  203. GTP_ERROR("[get_ic_fw_msg]get pid & vid failed,exit");
  204. return FAIL;
  205. }
  206. memset(update_msg.ic_fw_msg.pid, 0, sizeof(update_msg.ic_fw_msg.pid));
  207. memcpy(update_msg.ic_fw_msg.pid, &buf[GTP_ADDR_LENGTH], 4);
  208. /*
  209. * GT9XX PID MAPPING
  210. * |-----FLASH-----RAM-----|
  211. * |------918------918-----|
  212. * |------968------968-----|
  213. * |------913------913-----|
  214. * |------913P-----913P----|
  215. * |------927------927-----|
  216. * |------927P-----927P----|
  217. * |------9110-----9110----|
  218. * |------9110P----9111----|
  219. */
  220. if (update_msg.ic_fw_msg.pid[0] != 0) {
  221. if (!memcmp(update_msg.ic_fw_msg.pid, "9111", 4)) {
  222. GTP_INFO("IC Mapping Product id:%s",
  223. update_msg.ic_fw_msg.pid);
  224. memcpy(update_msg.ic_fw_msg.pid, "9110P", 5);
  225. }
  226. }
  227. update_msg.ic_fw_msg.vid =
  228. buf[GTP_ADDR_LENGTH + 4] + (buf[GTP_ADDR_LENGTH + 5] << 8);
  229. return SUCCESS;
  230. }
  231. s32 gup_enter_update_mode(struct i2c_client *client)
  232. {
  233. s32 ret = -1;
  234. s32 retry = 0;
  235. u8 rd_buf[3];
  236. /* step1:RST output low last at least 2ms */
  237. gtp_gpio_output(GTP_RST_GPIO, 0);
  238. msleep(20);
  239. /* step2:select I2C slave addr,INT:0--0xBA;1--0x28. */
  240. gtp_gpio_output(GTP_IRQ_GPIO, (client->addr == 0x14));
  241. msleep(20);
  242. /* step3:RST output high reset guitar */
  243. gtp_gpio_output(GTP_RST_GPIO, 1);
  244. /* 20121211 modify start */
  245. msleep(20);
  246. while (retry++ < 200) {
  247. /* step4:Hold ss51 & dsp */
  248. ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x0C);
  249. if (ret <= 0) {
  250. GTP_DEBUG("Hold ss51 & dsp I2C error,retry:%d", retry);
  251. continue;
  252. }
  253. /* step5:Confirm hold */
  254. ret = gup_get_ic_msg(client, _rRW_MISCTL__SWRST_B0_, rd_buf, 1);
  255. if (ret <= 0) {
  256. GTP_DEBUG("Hold ss51 & dsp I2C error,retry:%d", retry);
  257. continue;
  258. }
  259. if (rd_buf[GTP_ADDR_LENGTH] == 0x0C) {
  260. GTP_DEBUG("Hold ss51 & dsp confirm SUCCESS");
  261. break;
  262. }
  263. GTP_DEBUG("Hold ss51 & dsp confirm 0x4180 failed,value:%d",
  264. rd_buf[GTP_ADDR_LENGTH]);
  265. }
  266. if (retry >= 200) {
  267. GTP_ERROR("Enter update Hold ss51 failed.");
  268. return FAIL;
  269. }
  270. /* step6:DSP_CK and DSP_ALU_CK PowerOn */
  271. ret = gup_set_ic_msg(client, 0x4010, 0x00);
  272. /* 20121211 modify end */
  273. return ret;
  274. }
  275. void gup_leave_update_mode(void)
  276. {
  277. GTP_DEBUG("[leave_update_mode]reset chip.");
  278. #ifdef CONFIG_GTP_COMPATIBLE_MODE
  279. if (gtp_chip_type == CHIP_TYPE_GT9F) {
  280. force_reset_guitar();
  281. GTP_INFO("User layer reset GT9XXF.");
  282. return;
  283. }
  284. #endif
  285. gtp_reset_guitar(i2c_client_point, 20);
  286. }
  287. static u8 gup_enter_update_judge(struct st_fw_head *fw_head)
  288. {
  289. u16 u16_tmp;
  290. s32 i = 0;
  291. u32 fw_len = 0;
  292. s32 pid_cmp_len = 0;
  293. /* Get the correct nvram data */
  294. /* The correct conditions: */
  295. /* 1. the hardware info is the same */
  296. /* 2. the product id is the same */
  297. /* 3. the firmware version in update file is */
  298. /* greater than the firmware version in ic */
  299. /* or the check sum in ic is wrong */
  300. u16_tmp = fw_head->vid;
  301. fw_head->vid = (u16)(u16_tmp >> 8) + (u16)(u16_tmp << 8);
  302. GTP_INFO("FILE HARDWARE INFO:%02x%02x%02x%02x", fw_head->hw_info[0],
  303. fw_head->hw_info[1], fw_head->hw_info[2], fw_head->hw_info[3]);
  304. GTP_INFO("FILE PID:%s", fw_head->pid);
  305. GTP_INFO("FILE VID:%04x", fw_head->vid);
  306. GTP_INFO("IC HARDWARE INFO:%02x%02x%02x%02x",
  307. update_msg.ic_fw_msg.hw_info[0],
  308. update_msg.ic_fw_msg.hw_info[1],
  309. update_msg.ic_fw_msg.hw_info[2],
  310. update_msg.ic_fw_msg.hw_info[3]);
  311. GTP_INFO("IC PID:%s", update_msg.ic_fw_msg.pid);
  312. GTP_INFO("IC VID:%04x", update_msg.ic_fw_msg.vid);
  313. if (!memcmp(fw_head->hw_info, update_msg.ic_fw_msg.hw_info,
  314. sizeof(update_msg.ic_fw_msg.hw_info))) {
  315. fw_len = 42 * 1024;
  316. } else {
  317. fw_len = fw_head->hw_info[3];
  318. fw_len += (((u32)fw_head->hw_info[2]) << 8);
  319. fw_len += (((u32)fw_head->hw_info[1]) << 16);
  320. fw_len += (((u32)fw_head->hw_info[0]) << 24);
  321. }
  322. if (update_msg.fw_total_len != fw_len) {
  323. GTP_ERROR(
  324. "Inconsistent firmware size, Update aborted! Default size: %d(%dK), actual size: %d(%dK)",
  325. fw_len, fw_len / 1024, update_msg.fw_total_len,
  326. update_msg.fw_total_len / 1024);
  327. return FAIL;
  328. }
  329. if ((update_msg.fw_total_len < 36 * 1024) ||
  330. (update_msg.fw_total_len > 128 * 1024)) {
  331. GTP_ERROR("Invalid firmware length(%d), update aborted!",
  332. update_msg.fw_total_len);
  333. return FAIL;
  334. }
  335. GTP_INFO("Firmware length:%d(%dK)", update_msg.fw_total_len,
  336. update_msg.fw_total_len / 1024);
  337. if (update_msg.force_update != 0xBE) {
  338. GTP_INFO("FW chksum error,need enter update.");
  339. return SUCCESS;
  340. }
  341. /* 20130523 start */
  342. if (strlen(update_msg.ic_fw_msg.pid) < 3) {
  343. GTP_INFO("Illegal IC pid, need enter update");
  344. return SUCCESS;
  345. }
  346. for (i = 0; i < 3; i++) {
  347. if ((update_msg.ic_fw_msg.pid[i] < 0x30) ||
  348. (update_msg.ic_fw_msg.pid[i] > 0x39)) {
  349. GTP_INFO(
  350. "Illegal IC pid, out of bound, need enter update");
  351. return SUCCESS;
  352. }
  353. }
  354. /* 20130523 end */
  355. pid_cmp_len = strlen(fw_head->pid);
  356. if (pid_cmp_len < strlen(update_msg.ic_fw_msg.pid))
  357. pid_cmp_len = strlen(update_msg.ic_fw_msg.pid);
  358. if ((!memcmp(fw_head->pid, update_msg.ic_fw_msg.pid, pid_cmp_len)) ||
  359. (!memcmp(update_msg.ic_fw_msg.pid, "91XX", 4)) ||
  360. (!memcmp(fw_head->pid, "91XX", 4))) {
  361. if (!memcmp(fw_head->pid, "91XX", 4))
  362. GTP_DEBUG("Force none same pid update mode.");
  363. else
  364. GTP_DEBUG("Get the same pid.");
  365. /* The third condition */
  366. if (fw_head->vid > update_msg.ic_fw_msg.vid) {
  367. GTP_INFO("Need enter update.");
  368. return SUCCESS;
  369. }
  370. GTP_INFO("Don't meet the third condition.");
  371. GTP_ERROR("File VID <= IC VID, update aborted!");
  372. } else {
  373. GTP_ERROR("File PID != IC PID, update aborted!");
  374. }
  375. return FAIL;
  376. }
  377. #ifdef CONFIG_GTP_AUTO_UPDATE_CFG
  378. static u8 ascii2hex(u8 a)
  379. {
  380. s8 value = 0;
  381. if (a >= '0' && a <= '9')
  382. value = a - '0';
  383. else if (a >= 'A' && a <= 'F')
  384. value = a - 'A' + 0x0A;
  385. else if (a >= 'a' && a <= 'f')
  386. value = a - 'a' + 0x0A;
  387. else
  388. value = 0xff;
  389. return value;
  390. }
  391. static s8 gup_update_config(struct i2c_client *client)
  392. {
  393. s32 file_len = 0;
  394. s32 ret = 0;
  395. s32 i = 0;
  396. s32 file_cfg_len = 0;
  397. s32 chip_cfg_len = 0;
  398. s32 count = 0;
  399. u8 *buf;
  400. u8 *pre_buf;
  401. u8 *file_config;
  402. /* u8 checksum = 0; */
  403. if (update_msg.cfg_file == NULL) {
  404. GTP_ERROR("[update_cfg]No need to upgrade config!");
  405. return FAIL;
  406. }
  407. file_len = update_msg.cfg_file->f_op->llseek(update_msg.cfg_file, 0,
  408. SEEK_END);
  409. chip_cfg_len = cfg_len;
  410. GTP_DEBUG("[update_cfg]config file len:%d", file_len);
  411. GTP_DEBUG("[update_cfg]need config len:%d", chip_cfg_len);
  412. if ((file_len + 5) < chip_cfg_len * 5) {
  413. GTP_ERROR("Config length error");
  414. return -1;
  415. }
  416. buf = kzalloc(file_len, GFP_KERNEL);
  417. pre_buf = kzalloc(file_len, GFP_KERNEL);
  418. file_config = kzalloc(chip_cfg_len + GTP_ADDR_LENGTH, GFP_KERNEL);
  419. update_msg.cfg_file->f_op->llseek(update_msg.cfg_file, 0, SEEK_SET);
  420. GTP_DEBUG("[update_cfg]Read config from file.");
  421. ret = update_msg.cfg_file->f_op->read(update_msg.cfg_file,
  422. (char *)pre_buf, file_len,
  423. &update_msg.cfg_file->f_pos);
  424. if (ret < 0) {
  425. GTP_ERROR("[update_cfg]Read config file failed.");
  426. goto update_cfg_file_failed;
  427. }
  428. GTP_DEBUG("[update_cfg]Delete illgal character.");
  429. for (i = 0, count = 0; i < file_len; i++) {
  430. if (pre_buf[i] == ' ' || pre_buf[i] == '\r' ||
  431. pre_buf[i] == '\n')
  432. continue;
  433. buf[count++] = pre_buf[i];
  434. }
  435. GTP_DEBUG("[update_cfg]Ascii to hex.");
  436. file_config[0] = GTP_REG_CONFIG_DATA >> 8;
  437. file_config[1] = GTP_REG_CONFIG_DATA & 0xff;
  438. for (i = 0, file_cfg_len = GTP_ADDR_LENGTH; i < count; i += 5) {
  439. if ((buf[i] == '0') &&
  440. ((buf[i + 1] == 'x') || (buf[i + 1] == 'X'))) {
  441. u8 high, low;
  442. high = ascii2hex(buf[i + 2]);
  443. low = ascii2hex(buf[i + 3]);
  444. if ((high == 0xFF) || (low == 0xFF)) {
  445. ret = 0;
  446. GTP_ERROR("[update_cfg]Illegal config file.");
  447. goto update_cfg_file_failed;
  448. }
  449. file_config[file_cfg_len++] = (high << 4) + low;
  450. } else {
  451. ret = 0;
  452. GTP_ERROR("[update_cfg]Illegal config file.");
  453. goto update_cfg_file_failed;
  454. }
  455. }
  456. GTP_DEBUG("config:");
  457. GTP_DEBUG_ARRAY(file_config + 2, file_cfg_len);
  458. i = 0;
  459. while (i++ < 5) {
  460. ret = gup_i2c_write(client, file_config, file_cfg_len);
  461. if (ret > 0) {
  462. GTP_INFO("[update_cfg]Send config SUCCESS.");
  463. break;
  464. }
  465. GTP_ERROR("[update_cfg]Send config i2c error.");
  466. }
  467. update_cfg_file_failed:
  468. kfree(pre_buf);
  469. kfree(buf);
  470. kfree(file_config);
  471. return ret;
  472. }
  473. #endif
  474. #if (defined(CONFIG_GTP_AUTO_UPDATE) && \
  475. !defined(CONFIG_GTP_REQUEST_FW_UPDATE) || \
  476. defined(CONFIG_GTP_AUTO_UPDATE_CFG))
  477. static void gup_search_file(s32 search_type)
  478. {
  479. s32 i = 0;
  480. struct file *pfile = NULL;
  481. got_file_flag = 0x00;
  482. searching_file = 1;
  483. for (i = 0; i < GUP_SEARCH_FILE_TIMES; ++i) {
  484. if (searching_file == 0) {
  485. GTP_INFO("Force exiting file searching");
  486. got_file_flag = 0x00;
  487. return;
  488. }
  489. if (search_type & AUTO_SEARCH_BIN) {
  490. GTP_DEBUG("Search for %s, %s for fw update.(%d/%d)",
  491. UPDATE_FILE_PATH_1, UPDATE_FILE_PATH_2, i + 1,
  492. GUP_SEARCH_FILE_TIMES);
  493. pfile = filp_open(UPDATE_FILE_PATH_1, O_RDONLY, 0);
  494. if (IS_ERR(pfile)) {
  495. pfile = filp_open(UPDATE_FILE_PATH_2, O_RDONLY,
  496. 0);
  497. if (!IS_ERR(pfile)) {
  498. GTP_INFO("Bin file: %s for fw update.",
  499. UPDATE_FILE_PATH_2);
  500. got_file_flag |= BIN_FILE_READY;
  501. update_msg.file = pfile;
  502. }
  503. } else {
  504. GTP_INFO("Bin file: %s for fw update.",
  505. UPDATE_FILE_PATH_1);
  506. got_file_flag |= BIN_FILE_READY;
  507. update_msg.file = pfile;
  508. }
  509. if (got_file_flag & BIN_FILE_READY) {
  510. #ifdef CONFIG_GTP_AUTO_UPDATE_CFG
  511. if (search_type & AUTO_SEARCH_CFG) {
  512. /*Bin & Cfg File required to be in the */
  513. /* same directory*/
  514. i = GUP_SEARCH_FILE_TIMES;
  515. } else
  516. #endif
  517. {
  518. searching_file = 0;
  519. return;
  520. }
  521. }
  522. }
  523. #ifdef CONFIG_GTP_AUTO_UPDATE_CFG
  524. if ((search_type & AUTO_SEARCH_CFG) &&
  525. !(got_file_flag & CFG_FILE_READY)) {
  526. GTP_DEBUG("Search for %s, %s for config update.(%d/%d)",
  527. CONFIG_FILE_PATH_1, CONFIG_FILE_PATH_2, i + 1,
  528. GUP_SEARCH_FILE_TIMES);
  529. pfile = filp_open(CONFIG_FILE_PATH_1, O_RDONLY, 0);
  530. if (IS_ERR(pfile)) {
  531. pfile = filp_open(CONFIG_FILE_PATH_2, O_RDONLY,
  532. 0);
  533. if (!IS_ERR(pfile)) {
  534. GTP_INFO(
  535. "Cfg file: %s for config update.",
  536. CONFIG_FILE_PATH_2);
  537. got_file_flag |= CFG_FILE_READY;
  538. update_msg.cfg_file = pfile;
  539. }
  540. } else {
  541. GTP_INFO("Cfg file: %s for config update.",
  542. CONFIG_FILE_PATH_1);
  543. got_file_flag |= CFG_FILE_READY;
  544. update_msg.cfg_file = pfile;
  545. }
  546. if (got_file_flag & CFG_FILE_READY) {
  547. searching_file = 0;
  548. return;
  549. }
  550. }
  551. #endif
  552. msleep(3000);
  553. }
  554. searching_file = 0;
  555. }
  556. #endif
  557. static u8 gup_check_update_file(struct i2c_client *client,
  558. struct st_fw_head *fw_head, u8 *path)
  559. {
  560. s32 ret = 0;
  561. s32 i = 0;
  562. s32 fw_checksum = 0;
  563. u8 buf[FW_HEAD_LENGTH];
  564. got_file_flag = 0x00;
  565. if (path) {
  566. /*GTP_DEBUG("Update File path:%s, %d", path, strlen(path));*/
  567. update_msg.file = filp_open(path, O_RDONLY, 0);
  568. if (IS_ERR(update_msg.file)) {
  569. GTP_ERROR("Open update file(%s) error!", path);
  570. return FAIL;
  571. }
  572. got_file_flag = BIN_FILE_READY;
  573. } else {
  574. #ifdef CONFIG_GTP_AUTO_UPDATE
  575. #ifdef CONFIG_GTP_REQUEST_FW_UPDATE
  576. GTP_INFO("Request firmware...");
  577. ret = request_firmware(&update_msg.fw, GT9XX_FW_NAME,
  578. &client->dev);
  579. if (ret < 0) {
  580. GTP_ERROR("Request firmware failed - %s (%d)\n",
  581. GT9XX_FW_NAME, ret);
  582. return FAIL;
  583. }
  584. GTP_INFO("Firmware size: %zd", update_msg.fw->size);
  585. if (update_msg.fw->size <
  586. (FW_HEAD_LENGTH + FW_SECTION_LENGTH * 4 +
  587. FW_DSP_ISP_LENGTH + FW_DSP_LENGTH + FW_BOOT_LENGTH)) {
  588. GTP_ERROR("INVALID firmware!");
  589. return FAIL;
  590. }
  591. update_msg.fw_total_len = update_msg.fw->size - FW_HEAD_LENGTH;
  592. GTP_DEBUG("Firmware actual size: %d(%dK)",
  593. update_msg.fw_total_len,
  594. update_msg.fw_total_len / 1024);
  595. memcpy(fw_head, &update_msg.fw->data[0], FW_HEAD_LENGTH);
  596. /*check firmware legality */
  597. fw_checksum = 0;
  598. for (i = 0; i < update_msg.fw_total_len; i += 2) {
  599. fw_checksum +=
  600. (update_msg.fw->data[FW_HEAD_LENGTH + i] << 8) +
  601. update_msg.fw->data[FW_HEAD_LENGTH + i + 1];
  602. }
  603. GTP_DEBUG("firmware checksum:%x", fw_checksum & 0xFFFF);
  604. if (fw_checksum & 0xFFFF) {
  605. GTP_ERROR("Illegal firmware file.");
  606. return FAIL;
  607. }
  608. got_file_flag = HEADER_FW_READY;
  609. return SUCCESS;
  610. #else
  611. #ifdef CONFIG_GTP_AUTO_UPDATE_CFG
  612. gup_search_file(AUTO_SEARCH_BIN | AUTO_SEARCH_CFG);
  613. if (got_file_flag & CFG_FILE_READY) {
  614. ret = gup_update_config(client);
  615. if (ret <= 0)
  616. GTP_ERROR("Update config failed!");
  617. _CLOSE_FILE(update_msg.cfg_file);
  618. msleep(500); /* waiting config to be stored in FLASH. */
  619. }
  620. #else
  621. gup_search_file(AUTO_SEARCH_BIN);
  622. #endif
  623. if (!(got_file_flag & BIN_FILE_READY)) {
  624. GTP_ERROR("No bin file for fw Update");
  625. return FAIL;
  626. }
  627. #endif
  628. #else
  629. {
  630. GTP_ERROR("NULL file for fw update!");
  631. return FAIL;
  632. }
  633. #endif
  634. }
  635. update_msg.old_fs = get_fs();
  636. set_fs(KERNEL_DS);
  637. update_msg.file->f_op->llseek(update_msg.file, 0, SEEK_SET);
  638. update_msg.fw_total_len =
  639. update_msg.file->f_op->llseek(update_msg.file, 0, SEEK_END);
  640. update_msg.fw_total_len -= FW_HEAD_LENGTH;
  641. GTP_DEBUG("Bin firmware actual size: %d(%dK)", update_msg.fw_total_len,
  642. update_msg.fw_total_len / 1024);
  643. update_msg.file->f_op->llseek(update_msg.file, 0, SEEK_SET);
  644. ret = update_msg.file->f_op->read(update_msg.file, (char *)buf,
  645. FW_HEAD_LENGTH,
  646. &update_msg.file->f_pos);
  647. if (ret < 0) {
  648. GTP_ERROR("Read firmware head in update file error.");
  649. goto load_failed;
  650. }
  651. memcpy(fw_head, buf, FW_HEAD_LENGTH);
  652. /* check firmware legality */
  653. fw_checksum = 0;
  654. for (i = 0; i < update_msg.fw_total_len; i += 2) {
  655. u16 temp;
  656. ret = update_msg.file->f_op->read(update_msg.file, (char *)buf,
  657. 2, &update_msg.file->f_pos);
  658. if (ret < 0) {
  659. GTP_ERROR("Read firmware file error.");
  660. goto load_failed;
  661. }
  662. /* GTP_DEBUG("BUF[0]:%x", buf[0]); */
  663. temp = (buf[0] << 8) + buf[1];
  664. fw_checksum += temp;
  665. }
  666. GTP_DEBUG("firmware checksum:%x", fw_checksum & 0xFFFF);
  667. if (fw_checksum & 0xFFFF) {
  668. GTP_ERROR("Illegal firmware file.");
  669. goto load_failed;
  670. }
  671. return SUCCESS;
  672. load_failed:
  673. set_fs(update_msg.old_fs);
  674. _CLOSE_FILE(update_msg.file);
  675. return FAIL;
  676. }
  677. static u8 gup_burn_proc(struct i2c_client *client, u8 *burn_buf, u16 start_addr,
  678. u16 total_length)
  679. {
  680. s32 ret = 0;
  681. u16 burn_addr = start_addr;
  682. u16 frame_length = 0;
  683. u16 burn_length = 0;
  684. u8 wr_buf[PACK_SIZE + GTP_ADDR_LENGTH];
  685. u8 rd_buf[PACK_SIZE + GTP_ADDR_LENGTH];
  686. u8 retry = 0;
  687. GTP_DEBUG("Begin burn %dk data to addr 0x%x", (total_length / 1024),
  688. start_addr);
  689. while (burn_length < total_length) {
  690. GTP_DEBUG("B/T:%04d/%04d", burn_length, total_length);
  691. frame_length = ((total_length - burn_length) > PACK_SIZE)
  692. ? PACK_SIZE
  693. : (total_length - burn_length);
  694. wr_buf[0] = (u8)(burn_addr >> 8);
  695. rd_buf[0] = wr_buf[0];
  696. wr_buf[1] = (u8)burn_addr;
  697. rd_buf[1] = wr_buf[1];
  698. memcpy(&wr_buf[GTP_ADDR_LENGTH], &burn_buf[burn_length],
  699. frame_length);
  700. for (retry = 0; retry < MAX_FRAME_CHECK_TIME; retry++) {
  701. ret = gup_i2c_write(client, wr_buf,
  702. GTP_ADDR_LENGTH + frame_length);
  703. if (ret <= 0) {
  704. GTP_ERROR("Write frame data i2c error.");
  705. continue;
  706. }
  707. ret = gup_i2c_read(client, rd_buf,
  708. GTP_ADDR_LENGTH + frame_length);
  709. if (ret <= 0) {
  710. GTP_ERROR("Read back frame data i2c error.");
  711. continue;
  712. }
  713. if (memcmp(&wr_buf[GTP_ADDR_LENGTH],
  714. &rd_buf[GTP_ADDR_LENGTH], frame_length)) {
  715. GTP_ERROR("Check frame data fail,not equal.");
  716. GTP_DEBUG("write array:");
  717. GTP_DEBUG_ARRAY(&wr_buf[GTP_ADDR_LENGTH],
  718. frame_length);
  719. GTP_DEBUG("read array:");
  720. GTP_DEBUG_ARRAY(&rd_buf[GTP_ADDR_LENGTH],
  721. frame_length);
  722. continue;
  723. } else {
  724. /* GTP_DEBUG("Check frame data success."); */
  725. break;
  726. }
  727. }
  728. if (retry > MAX_FRAME_CHECK_TIME) {
  729. GTP_ERROR("Burn frame data time out,exit.");
  730. return FAIL;
  731. }
  732. burn_length += frame_length;
  733. burn_addr += frame_length;
  734. }
  735. return SUCCESS;
  736. }
  737. static u8 gup_load_section_file(u8 *buf, u32 offset, u16 length, u8 set_or_end)
  738. {
  739. #if defined(CONFIG_GTP_AUTO_UPDATE) && defined(CONFIG_GTP_REQUEST_FW_UPDATE)
  740. if (got_file_flag == HEADER_FW_READY) {
  741. if (set_or_end == SEEK_SET)
  742. memcpy(buf,
  743. &update_msg.fw->data[FW_HEAD_LENGTH + offset],
  744. length);
  745. else /*seek end*/
  746. memcpy(buf,
  747. &update_msg.fw->data[update_msg.fw_total_len +
  748. FW_HEAD_LENGTH - offset],
  749. length);
  750. return SUCCESS;
  751. }
  752. #endif
  753. {
  754. s32 ret = 0;
  755. if ((update_msg.file == NULL) || IS_ERR(update_msg.file)) {
  756. GTP_ERROR(
  757. "cannot find update file,load section file fail.");
  758. return FAIL;
  759. }
  760. if (set_or_end == SEEK_SET)
  761. update_msg.file->f_pos = FW_HEAD_LENGTH + offset;
  762. else /* seek end */
  763. update_msg.file->f_pos = update_msg.fw_total_len +
  764. FW_HEAD_LENGTH - offset;
  765. ret = update_msg.file->f_op->read(update_msg.file, (char *)buf,
  766. length,
  767. &update_msg.file->f_pos);
  768. if (ret < 0) {
  769. GTP_ERROR("Read update file fail.");
  770. return FAIL;
  771. }
  772. return SUCCESS;
  773. }
  774. }
  775. static u8 gup_recall_check(struct i2c_client *client, u8 *chk_src,
  776. u16 start_rd_addr, u16 chk_length)
  777. {
  778. u8 rd_buf[PACK_SIZE + GTP_ADDR_LENGTH];
  779. s32 ret = 0;
  780. u16 recall_addr = start_rd_addr;
  781. u16 recall_length = 0;
  782. u16 frame_length = 0;
  783. while (recall_length < chk_length) {
  784. frame_length = ((chk_length - recall_length) > PACK_SIZE)
  785. ? PACK_SIZE
  786. : (chk_length - recall_length);
  787. ret = gup_get_ic_msg(client, recall_addr, rd_buf, frame_length);
  788. if (ret <= 0) {
  789. GTP_ERROR("recall i2c error,exit");
  790. return FAIL;
  791. }
  792. if (memcmp(&rd_buf[GTP_ADDR_LENGTH], &chk_src[recall_length],
  793. frame_length)) {
  794. GTP_ERROR("Recall frame data fail,not equal.");
  795. GTP_DEBUG("chk_src array:");
  796. GTP_DEBUG_ARRAY(&chk_src[recall_length], frame_length);
  797. GTP_DEBUG("recall array:");
  798. GTP_DEBUG_ARRAY(&rd_buf[GTP_ADDR_LENGTH], frame_length);
  799. return FAIL;
  800. }
  801. recall_length += frame_length;
  802. recall_addr += frame_length;
  803. }
  804. GTP_DEBUG("Recall check %dk firmware success.", (chk_length / 1024));
  805. return SUCCESS;
  806. }
  807. static u8 gup_burn_fw_section(struct i2c_client *client, u8 *fw_section,
  808. u16 start_addr, u8 bank_cmd)
  809. {
  810. s32 ret = 0;
  811. u8 rd_buf[5];
  812. /* step1:hold ss51 & dsp */
  813. ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x0C);
  814. if (ret <= 0) {
  815. GTP_ERROR("[burn_fw_section]hold ss51 & dsp fail.");
  816. return FAIL;
  817. }
  818. /* step2:set scramble */
  819. ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_OPT_B0_, 0x00);
  820. if (ret <= 0) {
  821. GTP_ERROR("[burn_fw_section]set scramble fail.");
  822. return FAIL;
  823. }
  824. /* step3:select bank */
  825. ret = gup_set_ic_msg(client, _bRW_MISCTL__SRAM_BANK,
  826. (bank_cmd >> 4) & 0x0F);
  827. if (ret <= 0) {
  828. GTP_ERROR("[burn_fw_section]select bank %d fail.",
  829. (bank_cmd >> 4) & 0x0F);
  830. return FAIL;
  831. }
  832. /* step4:enable accessing code */
  833. ret = gup_set_ic_msg(client, _bRW_MISCTL__MEM_CD_EN, 0x01);
  834. if (ret <= 0) {
  835. GTP_ERROR("[burn_fw_section]enable accessing code fail.");
  836. return FAIL;
  837. }
  838. /* step5:burn 8k fw section */
  839. ret = gup_burn_proc(client, fw_section, start_addr, FW_SECTION_LENGTH);
  840. if (ret == FAIL) {
  841. GTP_ERROR("[burn_fw_section]burn fw_section fail.");
  842. return FAIL;
  843. }
  844. /* step6:hold ss51 & release dsp */
  845. ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x04);
  846. if (ret <= 0) {
  847. GTP_ERROR("[burn_fw_section]hold ss51 & release dsp fail.");
  848. return FAIL;
  849. }
  850. /* must delay */
  851. msleep(20);
  852. /* step7:send burn cmd to move data to flash from sram */
  853. ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, bank_cmd & 0x0f);
  854. if (ret <= 0) {
  855. GTP_ERROR("[burn_fw_section]send burn cmd fail.");
  856. return FAIL;
  857. }
  858. GTP_DEBUG("[burn_fw_section]Wait for the burn is complete......");
  859. do {
  860. ret = gup_get_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, rd_buf, 1);
  861. if (ret <= 0) {
  862. GTP_ERROR("[burn_fw_section]Get burn state fail");
  863. return FAIL;
  864. }
  865. msleep(20);
  866. /* GTP_DEBUG("[burn_fw_section]Get burn state:%d.", */
  867. /* rd_buf[GTP_ADDR_LENGTH]); */
  868. } while (rd_buf[GTP_ADDR_LENGTH]);
  869. /* step8:select bank */
  870. ret = gup_set_ic_msg(client, _bRW_MISCTL__SRAM_BANK,
  871. (bank_cmd >> 4) & 0x0F);
  872. if (ret <= 0) {
  873. GTP_ERROR("[burn_fw_section]select bank %d fail.",
  874. (bank_cmd >> 4) & 0x0F);
  875. return FAIL;
  876. }
  877. /* step9:enable accessing code */
  878. ret = gup_set_ic_msg(client, _bRW_MISCTL__MEM_CD_EN, 0x01);
  879. if (ret <= 0) {
  880. GTP_ERROR("[burn_fw_section]enable accessing code fail.");
  881. return FAIL;
  882. }
  883. /* step10:recall 8k fw section */
  884. ret = gup_recall_check(client, fw_section, start_addr,
  885. FW_SECTION_LENGTH);
  886. if (ret == FAIL) {
  887. GTP_ERROR("[burn_fw_section]recall check %dk firmware fail.",
  888. FW_SECTION_LENGTH / 1024);
  889. return FAIL;
  890. }
  891. /* step11:disable accessing code */
  892. ret = gup_set_ic_msg(client, _bRW_MISCTL__MEM_CD_EN, 0x00);
  893. if (ret <= 0) {
  894. GTP_ERROR("[burn_fw_section]disable accessing code fail.");
  895. return FAIL;
  896. }
  897. return SUCCESS;
  898. }
  899. static u8 gup_burn_dsp_isp(struct i2c_client *client)
  900. {
  901. s32 ret = 0;
  902. u8 *fw_dsp_isp = NULL;
  903. u8 retry = 0;
  904. /* u32 offset; */
  905. GTP_INFO("[burn_dsp_isp]Begin burn dsp isp---->>");
  906. /* step1:alloc memory */
  907. GTP_DEBUG("[burn_dsp_isp]step1:alloc memory");
  908. while (retry++ < 5) {
  909. fw_dsp_isp = kzalloc(FW_DSP_ISP_LENGTH, GFP_KERNEL);
  910. if (fw_dsp_isp == NULL) {
  911. continue;
  912. } else {
  913. GTP_INFO("[burn_dsp_isp]Alloc %dk byte memory success.",
  914. (FW_DSP_ISP_LENGTH / 1024));
  915. break;
  916. }
  917. }
  918. if (retry >= 5) {
  919. GTP_ERROR("[burn_dsp_isp]Alloc memory fail,exit.");
  920. return FAIL;
  921. }
  922. /* step2:load dsp isp file data */
  923. GTP_DEBUG("[burn_dsp_isp]step2:load dsp isp file data");
  924. ret = gup_load_section_file(fw_dsp_isp, FW_DSP_ISP_LENGTH,
  925. FW_DSP_ISP_LENGTH, SEEK_END);
  926. if (ret == FAIL) {
  927. GTP_ERROR("[burn_dsp_isp]load firmware dsp_isp fail.");
  928. goto exit_burn_dsp_isp;
  929. }
  930. /* step3:disable wdt,clear cache enable */
  931. GTP_DEBUG("[burn_dsp_isp]step3:disable wdt,clear cache enable");
  932. ret = gup_set_ic_msg(client, _bRW_MISCTL__TMR0_EN, 0x00);
  933. if (ret <= 0) {
  934. GTP_ERROR("[burn_dsp_isp]disable wdt fail.");
  935. ret = FAIL;
  936. goto exit_burn_dsp_isp;
  937. }
  938. ret = gup_set_ic_msg(client, _bRW_MISCTL__CACHE_EN, 0x00);
  939. if (ret <= 0) {
  940. GTP_ERROR("[burn_dsp_isp]clear cache enable fail.");
  941. ret = FAIL;
  942. goto exit_burn_dsp_isp;
  943. }
  944. /* step4:hold ss51 & dsp */
  945. GTP_DEBUG("[burn_dsp_isp]step4:hold ss51 & dsp");
  946. ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x0C);
  947. if (ret <= 0) {
  948. GTP_ERROR("[burn_dsp_isp]hold ss51 & dsp fail.");
  949. ret = FAIL;
  950. goto exit_burn_dsp_isp;
  951. }
  952. /* step5:set boot from sram */
  953. GTP_DEBUG("[burn_dsp_isp]step5:set boot from sram");
  954. ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOTCTL_B0_, 0x02);
  955. if (ret <= 0) {
  956. GTP_ERROR("[burn_dsp_isp]set boot from sram fail.");
  957. ret = FAIL;
  958. goto exit_burn_dsp_isp;
  959. }
  960. /* step6:software reboot */
  961. GTP_DEBUG("[burn_dsp_isp]step6:software reboot");
  962. ret = gup_set_ic_msg(client, _bWO_MISCTL__CPU_SWRST_PULSE, 0x01);
  963. if (ret <= 0) {
  964. GTP_ERROR("[burn_dsp_isp]software reboot fail.");
  965. ret = FAIL;
  966. goto exit_burn_dsp_isp;
  967. }
  968. /* step7:select bank2 */
  969. GTP_DEBUG("[burn_dsp_isp]step7:select bank2");
  970. ret = gup_set_ic_msg(client, _bRW_MISCTL__SRAM_BANK, 0x02);
  971. if (ret <= 0) {
  972. GTP_ERROR("[burn_dsp_isp]select bank2 fail.");
  973. ret = FAIL;
  974. goto exit_burn_dsp_isp;
  975. }
  976. /* step8:enable accessing code */
  977. GTP_DEBUG("[burn_dsp_isp]step8:enable accessing code");
  978. ret = gup_set_ic_msg(client, _bRW_MISCTL__MEM_CD_EN, 0x01);
  979. if (ret <= 0) {
  980. GTP_ERROR("[burn_dsp_isp]enable accessing code fail.");
  981. ret = FAIL;
  982. goto exit_burn_dsp_isp;
  983. }
  984. /* step9:burn 4k dsp_isp */
  985. GTP_DEBUG("[burn_dsp_isp]step9:burn 4k dsp_isp");
  986. ret = gup_burn_proc(client, fw_dsp_isp, 0xC000, FW_DSP_ISP_LENGTH);
  987. if (ret == FAIL) {
  988. GTP_ERROR("[burn_dsp_isp]burn dsp_isp fail.");
  989. goto exit_burn_dsp_isp;
  990. }
  991. /* step10:set scramble */
  992. GTP_DEBUG("[burn_dsp_isp]step10:set scramble");
  993. ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_OPT_B0_, 0x00);
  994. if (ret <= 0) {
  995. GTP_ERROR("[burn_dsp_isp]set scramble fail.");
  996. ret = FAIL;
  997. goto exit_burn_dsp_isp;
  998. }
  999. update_msg.fw_burned_len += FW_DSP_ISP_LENGTH;
  1000. GTP_DEBUG("[burn_dsp_isp]Burned length:%d", update_msg.fw_burned_len);
  1001. ret = SUCCESS;
  1002. exit_burn_dsp_isp:
  1003. kfree(fw_dsp_isp);
  1004. return ret;
  1005. }
  1006. static u8 gup_burn_fw_ss51(struct i2c_client *client)
  1007. {
  1008. u8 *fw_ss51 = NULL;
  1009. u8 retry = 0;
  1010. s32 ret = 0;
  1011. GTP_INFO("[burn_fw_ss51]Begin burn ss51 firmware---->>");
  1012. /* step1:alloc memory */
  1013. GTP_DEBUG("[burn_fw_ss51]step1:alloc memory");
  1014. while (retry++ < 5) {
  1015. fw_ss51 = kzalloc(FW_SECTION_LENGTH, GFP_KERNEL);
  1016. if (fw_ss51 == NULL) {
  1017. continue;
  1018. } else {
  1019. GTP_INFO("[burn_fw_ss51]Alloc %dk byte memory success.",
  1020. (FW_SECTION_LENGTH / 1024));
  1021. break;
  1022. }
  1023. }
  1024. if (retry >= 5) {
  1025. GTP_ERROR("[burn_fw_ss51]Alloc memory fail,exit.");
  1026. return FAIL;
  1027. }
  1028. GTP_INFO("[burn_fw_ss51]Reset first 8K of ss51 to 0xFF.");
  1029. GTP_DEBUG("[burn_fw_ss51]step2: reset bank0 0xC000~0xD000");
  1030. memset(fw_ss51, 0xFF, FW_SECTION_LENGTH);
  1031. /* step3:clear control flag */
  1032. GTP_DEBUG("[burn_fw_ss51]step3:clear control flag");
  1033. ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, 0x00);
  1034. if (ret <= 0) {
  1035. GTP_ERROR("[burn_fw_ss51]clear control flag fail.");
  1036. ret = FAIL;
  1037. goto exit_burn_fw_ss51;
  1038. }
  1039. /* step4:burn ss51 firmware section 1 */
  1040. GTP_DEBUG("[burn_fw_ss51]step4:burn ss51 firmware section 1");
  1041. ret = gup_burn_fw_section(client, fw_ss51, 0xC000, 0x01);
  1042. if (ret == FAIL) {
  1043. GTP_ERROR("[burn_fw_ss51]burn ss51 firmware section 1 fail.");
  1044. goto exit_burn_fw_ss51;
  1045. }
  1046. /* step5:load ss51 firmware section 2 file data */
  1047. GTP_DEBUG("[burn_fw_ss51]step5:load ss51 firmware section 2 file data");
  1048. ret = gup_load_section_file(fw_ss51, FW_SECTION_LENGTH,
  1049. FW_SECTION_LENGTH, SEEK_SET);
  1050. if (ret == FAIL) {
  1051. GTP_ERROR("[burn_fw_ss51]load ss51 firmware section 2 fail.");
  1052. goto exit_burn_fw_ss51;
  1053. }
  1054. /* step6:burn ss51 firmware section 2 */
  1055. GTP_DEBUG("[burn_fw_ss51]step6:burn ss51 firmware section 2");
  1056. ret = gup_burn_fw_section(client, fw_ss51, 0xE000, 0x02);
  1057. if (ret == FAIL) {
  1058. GTP_ERROR("[burn_fw_ss51]burn ss51 firmware section 2 fail.");
  1059. goto exit_burn_fw_ss51;
  1060. }
  1061. /* step7:load ss51 firmware section 3 file data */
  1062. GTP_DEBUG("[burn_fw_ss51]step7:load ss51 firmware section 3 file data");
  1063. ret = gup_load_section_file(fw_ss51, 2 * FW_SECTION_LENGTH,
  1064. FW_SECTION_LENGTH, SEEK_SET);
  1065. if (ret == FAIL) {
  1066. GTP_ERROR("[burn_fw_ss51]load ss51 firmware section 3 fail.");
  1067. goto exit_burn_fw_ss51;
  1068. }
  1069. /* step8:burn ss51 firmware section 3 */
  1070. GTP_DEBUG("[burn_fw_ss51]step8:burn ss51 firmware section 3");
  1071. ret = gup_burn_fw_section(client, fw_ss51, 0xC000, 0x13);
  1072. if (ret == FAIL) {
  1073. GTP_ERROR("[burn_fw_ss51]burn ss51 firmware section 3 fail.");
  1074. goto exit_burn_fw_ss51;
  1075. }
  1076. /* step9:load ss51 firmware section 4 file data */
  1077. GTP_DEBUG("[burn_fw_ss51]step9:load ss51 firmware section 4 file data");
  1078. ret = gup_load_section_file(fw_ss51, 3 * FW_SECTION_LENGTH,
  1079. FW_SECTION_LENGTH, SEEK_SET);
  1080. if (ret == FAIL) {
  1081. GTP_ERROR("[burn_fw_ss51]load ss51 firmware section 4 fail.");
  1082. goto exit_burn_fw_ss51;
  1083. }
  1084. /* step10:burn ss51 firmware section 4 */
  1085. GTP_DEBUG("[burn_fw_ss51]step10:burn ss51 firmware section 4");
  1086. ret = gup_burn_fw_section(client, fw_ss51, 0xE000, 0x14);
  1087. if (ret == FAIL) {
  1088. GTP_ERROR("[burn_fw_ss51]burn ss51 firmware section 4 fail.");
  1089. goto exit_burn_fw_ss51;
  1090. }
  1091. update_msg.fw_burned_len += (FW_SECTION_LENGTH * 4);
  1092. GTP_DEBUG("[burn_fw_ss51]Burned length:%d", update_msg.fw_burned_len);
  1093. ret = SUCCESS;
  1094. exit_burn_fw_ss51:
  1095. kfree(fw_ss51);
  1096. return ret;
  1097. }
  1098. static u8 gup_burn_fw_dsp(struct i2c_client *client)
  1099. {
  1100. s32 ret = 0;
  1101. u8 *fw_dsp = NULL;
  1102. u8 retry = 0;
  1103. u8 rd_buf[5];
  1104. GTP_INFO("[burn_fw_dsp]Begin burn dsp firmware---->>");
  1105. /* step1:alloc memory */
  1106. GTP_DEBUG("[burn_fw_dsp]step1:alloc memory");
  1107. while (retry++ < 5) {
  1108. fw_dsp = kzalloc(FW_DSP_LENGTH, GFP_KERNEL);
  1109. if (fw_dsp == NULL) {
  1110. continue;
  1111. } else {
  1112. GTP_INFO("[burn_fw_dsp]Alloc %dk byte memory success.",
  1113. (FW_SECTION_LENGTH / 1024));
  1114. break;
  1115. }
  1116. }
  1117. if (retry >= 5) {
  1118. GTP_ERROR("[burn_fw_dsp]Alloc memory fail,exit.");
  1119. return FAIL;
  1120. }
  1121. /* step2:load firmware dsp */
  1122. GTP_DEBUG("[burn_fw_dsp]step2:load firmware dsp");
  1123. ret = gup_load_section_file(fw_dsp, 4 * FW_SECTION_LENGTH,
  1124. FW_DSP_LENGTH, SEEK_SET);
  1125. if (ret == FAIL) {
  1126. GTP_ERROR("[burn_fw_dsp]load firmware dsp fail.");
  1127. goto exit_burn_fw_dsp;
  1128. }
  1129. /* step3:select bank3 */
  1130. GTP_DEBUG("[burn_fw_dsp]step3:select bank3");
  1131. ret = gup_set_ic_msg(client, _bRW_MISCTL__SRAM_BANK, 0x03);
  1132. if (ret <= 0) {
  1133. GTP_ERROR("[burn_fw_dsp]select bank3 fail.");
  1134. ret = FAIL;
  1135. goto exit_burn_fw_dsp;
  1136. }
  1137. /* step4:hold ss51 & dsp */
  1138. GTP_DEBUG("[burn_fw_dsp]step4:hold ss51 & dsp");
  1139. ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x0C);
  1140. if (ret <= 0) {
  1141. GTP_ERROR("[burn_fw_dsp]hold ss51 & dsp fail.");
  1142. ret = FAIL;
  1143. goto exit_burn_fw_dsp;
  1144. }
  1145. /* step5:set scramble */
  1146. GTP_DEBUG("[burn_fw_dsp]step5:set scramble");
  1147. ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_OPT_B0_, 0x00);
  1148. if (ret <= 0) {
  1149. GTP_ERROR("[burn_fw_dsp]set scramble fail.");
  1150. ret = FAIL;
  1151. goto exit_burn_fw_dsp;
  1152. }
  1153. /* step6:release ss51 & dsp */
  1154. GTP_DEBUG("[burn_fw_dsp]step6:release ss51 & dsp");
  1155. ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_,
  1156. 0x04); /* 20121212 */
  1157. if (ret <= 0) {
  1158. GTP_ERROR("[burn_fw_dsp]release ss51 & dsp fail.");
  1159. ret = FAIL;
  1160. goto exit_burn_fw_dsp;
  1161. }
  1162. /* must delay */
  1163. msleep(20);
  1164. /* step7:burn 4k dsp firmware */
  1165. GTP_DEBUG("[burn_fw_dsp]step7:burn 4k dsp firmware");
  1166. ret = gup_burn_proc(client, fw_dsp, 0x9000, FW_DSP_LENGTH);
  1167. if (ret == FAIL) {
  1168. GTP_ERROR("[burn_fw_dsp]burn fw_section fail.");
  1169. goto exit_burn_fw_dsp;
  1170. }
  1171. /* step8:send burn cmd to move data to flash from sram */
  1172. GTP_DEBUG(
  1173. "[burn_fw_dsp]step8:send burn cmd to move data to flash from sram");
  1174. ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, 0x05);
  1175. if (ret <= 0) {
  1176. GTP_ERROR("[burn_fw_dsp]send burn cmd fail.");
  1177. goto exit_burn_fw_dsp;
  1178. }
  1179. GTP_DEBUG("[burn_fw_dsp]Wait for the burn is complete......");
  1180. do {
  1181. ret = gup_get_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, rd_buf, 1);
  1182. if (ret <= 0) {
  1183. GTP_ERROR("[burn_fw_dsp]Get burn state fail");
  1184. goto exit_burn_fw_dsp;
  1185. }
  1186. msleep(20);
  1187. /* GTP_DEBUG("[burn_fw_dsp]Get burn state:%d.", */
  1188. /* rd_buf[GTP_ADDR_LENGTH]); */
  1189. } while (rd_buf[GTP_ADDR_LENGTH]);
  1190. /* step9:recall check 4k dsp firmware */
  1191. GTP_DEBUG("[burn_fw_dsp]step9:recall check 4k dsp firmware");
  1192. ret = gup_recall_check(client, fw_dsp, 0x9000, FW_DSP_LENGTH);
  1193. if (ret == FAIL) {
  1194. GTP_ERROR("[burn_fw_dsp]recall check 4k dsp firmware fail.");
  1195. goto exit_burn_fw_dsp;
  1196. }
  1197. update_msg.fw_burned_len += FW_DSP_LENGTH;
  1198. GTP_DEBUG("[burn_fw_dsp]Burned length:%d", update_msg.fw_burned_len);
  1199. ret = SUCCESS;
  1200. exit_burn_fw_dsp:
  1201. kfree(fw_dsp);
  1202. return ret;
  1203. }
  1204. static u8 gup_burn_fw_boot(struct i2c_client *client)
  1205. {
  1206. s32 ret = 0;
  1207. u8 *fw_boot = NULL;
  1208. u8 retry = 0;
  1209. u8 rd_buf[5];
  1210. GTP_DEBUG("[burn_fw_boot]Begin burn bootloader firmware---->>");
  1211. /* step1:Alloc memory */
  1212. GTP_DEBUG("[burn_fw_boot]step1:Alloc memory");
  1213. while (retry++ < 5) {
  1214. fw_boot = kzalloc(FW_BOOT_LENGTH, GFP_KERNEL);
  1215. if (fw_boot == NULL) {
  1216. continue;
  1217. } else {
  1218. GTP_INFO("[burn_fw_boot]Alloc %dk byte memory success.",
  1219. (FW_BOOT_LENGTH / 1024));
  1220. break;
  1221. }
  1222. }
  1223. if (retry >= 5) {
  1224. GTP_ERROR("[burn_fw_boot]Alloc memory fail,exit.");
  1225. return FAIL;
  1226. }
  1227. /* step2:load firmware bootloader */
  1228. GTP_DEBUG("[burn_fw_boot]step2:load firmware bootloader");
  1229. ret = gup_load_section_file(fw_boot,
  1230. (4 * FW_SECTION_LENGTH + FW_DSP_LENGTH),
  1231. FW_BOOT_LENGTH, SEEK_SET);
  1232. if (ret == FAIL) {
  1233. GTP_ERROR("[burn_fw_boot]load firmware bootcode fail.");
  1234. goto exit_burn_fw_boot;
  1235. }
  1236. /* step3:hold ss51 & dsp */
  1237. GTP_DEBUG("[burn_fw_boot]step3:hold ss51 & dsp");
  1238. ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x0C);
  1239. if (ret <= 0) {
  1240. GTP_ERROR("[burn_fw_boot]hold ss51 & dsp fail.");
  1241. ret = FAIL;
  1242. goto exit_burn_fw_boot;
  1243. }
  1244. /* step4:set scramble */
  1245. GTP_DEBUG("[burn_fw_boot]step4:set scramble");
  1246. ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_OPT_B0_, 0x00);
  1247. if (ret <= 0) {
  1248. GTP_ERROR("[burn_fw_boot]set scramble fail.");
  1249. ret = FAIL;
  1250. goto exit_burn_fw_boot;
  1251. }
  1252. /* step5:hold ss51 & release dsp */
  1253. GTP_DEBUG("[burn_fw_boot]step5:hold ss51 & release dsp");
  1254. ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_,
  1255. 0x04); /* 20121211 */
  1256. if (ret <= 0) {
  1257. GTP_ERROR("[burn_fw_boot]release ss51 & dsp fail.");
  1258. ret = FAIL;
  1259. goto exit_burn_fw_boot;
  1260. }
  1261. /* must delay */
  1262. msleep(20);
  1263. /* step6:select bank3 */
  1264. GTP_DEBUG("[burn_fw_boot]step6:select bank3");
  1265. ret = gup_set_ic_msg(client, _bRW_MISCTL__SRAM_BANK, 0x03);
  1266. if (ret <= 0) {
  1267. GTP_ERROR("[burn_fw_boot]select bank3 fail.");
  1268. ret = FAIL;
  1269. goto exit_burn_fw_boot;
  1270. }
  1271. /* step7:burn 2k bootloader firmware */
  1272. GTP_DEBUG("[burn_fw_boot]step7:burn 2k bootloader firmware");
  1273. ret = gup_burn_proc(client, fw_boot, 0x9000, FW_BOOT_LENGTH);
  1274. if (ret == FAIL) {
  1275. GTP_ERROR("[burn_fw_boot]burn fw_boot fail.");
  1276. goto exit_burn_fw_boot;
  1277. }
  1278. /* step7:send burn cmd to move data to flash from sram */
  1279. GTP_DEBUG(
  1280. "[burn_fw_boot]step7:send burn cmd to move data to flash from sram");
  1281. ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, 0x06);
  1282. if (ret <= 0) {
  1283. GTP_ERROR("[burn_fw_boot]send burn cmd fail.");
  1284. goto exit_burn_fw_boot;
  1285. }
  1286. GTP_DEBUG("[burn_fw_boot]Wait for the burn is complete......");
  1287. do {
  1288. ret = gup_get_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, rd_buf, 1);
  1289. if (ret <= 0) {
  1290. GTP_ERROR("[burn_fw_boot]Get burn state fail");
  1291. goto exit_burn_fw_boot;
  1292. }
  1293. msleep(20);
  1294. /* GTP_DEBUG("[burn_fw_boot]Get burn state:%d.", */
  1295. /* rd_buf[GTP_ADDR_LENGTH]); */
  1296. } while (rd_buf[GTP_ADDR_LENGTH]);
  1297. /* step8:recall check 2k bootloader firmware */
  1298. GTP_DEBUG("[burn_fw_boot]step8:recall check 2k bootloader firmware");
  1299. ret = gup_recall_check(client, fw_boot, 0x9000, FW_BOOT_LENGTH);
  1300. if (ret == FAIL) {
  1301. GTP_ERROR(
  1302. "[burn_fw_boot]recall check 2k bootcode firmware fail.");
  1303. goto exit_burn_fw_boot;
  1304. }
  1305. update_msg.fw_burned_len += FW_BOOT_LENGTH;
  1306. GTP_DEBUG("[burn_fw_boot]Burned length:%d", update_msg.fw_burned_len);
  1307. ret = SUCCESS;
  1308. exit_burn_fw_boot:
  1309. kfree(fw_boot);
  1310. return ret;
  1311. }
  1312. static u8 gup_burn_fw_boot_isp(struct i2c_client *client)
  1313. {
  1314. s32 ret = 0;
  1315. u8 *fw_boot_isp = NULL;
  1316. u8 retry = 0;
  1317. u8 rd_buf[5];
  1318. if (update_msg.fw_burned_len >= update_msg.fw_total_len) {
  1319. GTP_INFO("No need to upgrade the boot_isp code!");
  1320. return SUCCESS;
  1321. }
  1322. GTP_DEBUG("[burn_fw_boot_isp]Begin burn bootloader firmware---->>");
  1323. /* step1:Alloc memory */
  1324. GTP_DEBUG("[burn_fw_boot_isp]step1:Alloc memory");
  1325. while (retry++ < 5) {
  1326. fw_boot_isp = kzalloc(FW_BOOT_ISP_LENGTH, GFP_KERNEL);
  1327. if (fw_boot_isp == NULL) {
  1328. continue;
  1329. } else {
  1330. GTP_INFO(
  1331. "[burn_fw_boot_isp]Alloc %dk byte memory success.",
  1332. (FW_BOOT_ISP_LENGTH / 1024));
  1333. break;
  1334. }
  1335. }
  1336. if (retry >= 5) {
  1337. GTP_ERROR("[burn_fw_boot_isp]Alloc memory fail,exit.");
  1338. return FAIL;
  1339. }
  1340. /* step2:load firmware bootloader */
  1341. GTP_DEBUG("[burn_fw_boot_isp]step2:load firmware bootloader isp");
  1342. ret = gup_load_section_file(
  1343. fw_boot_isp, (update_msg.fw_burned_len - FW_DSP_ISP_LENGTH),
  1344. FW_BOOT_ISP_LENGTH, SEEK_SET);
  1345. if (ret == FAIL) {
  1346. GTP_ERROR("[burn_fw_boot_isp]load firmware boot_isp fail.");
  1347. goto exit_burn_fw_boot_isp;
  1348. }
  1349. /* step3:hold ss51 & dsp */
  1350. GTP_DEBUG("[burn_fw_boot_isp]step3:hold ss51 & dsp");
  1351. ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x0C);
  1352. if (ret <= 0) {
  1353. GTP_ERROR("[burn_fw_boot_isp]hold ss51 & dsp fail.");
  1354. ret = FAIL;
  1355. goto exit_burn_fw_boot_isp;
  1356. }
  1357. /* step4:set scramble */
  1358. GTP_DEBUG("[burn_fw_boot_isp]step4:set scramble");
  1359. ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_OPT_B0_, 0x00);
  1360. if (ret <= 0) {
  1361. GTP_ERROR("[burn_fw_boot_isp]set scramble fail.");
  1362. ret = FAIL;
  1363. goto exit_burn_fw_boot_isp;
  1364. }
  1365. /* step5:hold ss51 & release dsp */
  1366. GTP_DEBUG("[burn_fw_boot_isp]step5:hold ss51 & release dsp");
  1367. ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_,
  1368. 0x04); /* 20121211 */
  1369. if (ret <= 0) {
  1370. GTP_ERROR("[burn_fw_boot_isp]release ss51 & dsp fail.");
  1371. ret = FAIL;
  1372. goto exit_burn_fw_boot_isp;
  1373. }
  1374. /* must delay */
  1375. msleep(20);
  1376. /* step6:select bank3 */
  1377. GTP_DEBUG("[burn_fw_boot_isp]step6:select bank3");
  1378. ret = gup_set_ic_msg(client, _bRW_MISCTL__SRAM_BANK, 0x03);
  1379. if (ret <= 0) {
  1380. GTP_ERROR("[burn_fw_boot_isp]select bank3 fail.");
  1381. ret = FAIL;
  1382. goto exit_burn_fw_boot_isp;
  1383. }
  1384. /* step7:burn 2k bootload_isp firmware */
  1385. GTP_DEBUG("[burn_fw_boot_isp]step7:burn 2k bootloader firmware");
  1386. ret = gup_burn_proc(client, fw_boot_isp, 0x9000, FW_BOOT_ISP_LENGTH);
  1387. if (ret == FAIL) {
  1388. GTP_ERROR("[burn_fw_boot_isp]burn fw_section fail.");
  1389. goto exit_burn_fw_boot_isp;
  1390. }
  1391. /* step7:send burn cmd to move data to flash from sram */
  1392. GTP_DEBUG(
  1393. "[burn_fw_boot_isp]step7:send burn cmd to move data to flash from sram");
  1394. ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, 0x07);
  1395. if (ret <= 0) {
  1396. GTP_ERROR("[burn_fw_boot_isp]send burn cmd fail.");
  1397. goto exit_burn_fw_boot_isp;
  1398. }
  1399. GTP_DEBUG("[burn_fw_boot_isp]Wait for the burn is complete......");
  1400. do {
  1401. ret = gup_get_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, rd_buf, 1);
  1402. if (ret <= 0) {
  1403. GTP_ERROR("[burn_fw_boot_isp]Get burn state fail");
  1404. goto exit_burn_fw_boot_isp;
  1405. }
  1406. msleep(20);
  1407. /* GTP_DEBUG("[burn_fw_boot_isp]Get burn state:%d.", */
  1408. /* rd_buf[GTP_ADDR_LENGTH]); */
  1409. } while (rd_buf[GTP_ADDR_LENGTH]);
  1410. /* step8:recall check 2k bootload_isp firmware */
  1411. GTP_DEBUG(
  1412. "[burn_fw_boot_isp]step8:recall check 2k bootloader firmware");
  1413. ret = gup_recall_check(client, fw_boot_isp, 0x9000, FW_BOOT_ISP_LENGTH);
  1414. if (ret == FAIL) {
  1415. GTP_ERROR(
  1416. "[burn_fw_boot_isp]recall check 2k bootcode_isp firmware fail.");
  1417. goto exit_burn_fw_boot_isp;
  1418. }
  1419. update_msg.fw_burned_len += FW_BOOT_ISP_LENGTH;
  1420. GTP_DEBUG("[burn_fw_boot_isp]Burned length:%d",
  1421. update_msg.fw_burned_len);
  1422. ret = SUCCESS;
  1423. exit_burn_fw_boot_isp:
  1424. kfree(fw_boot_isp);
  1425. return ret;
  1426. }
  1427. static u8 gup_burn_fw_link(struct i2c_client *client)
  1428. {
  1429. s32 ret = 0;
  1430. u8 *fw_link = NULL;
  1431. u8 retry = 0;
  1432. u32 offset;
  1433. if (update_msg.fw_burned_len >= update_msg.fw_total_len) {
  1434. GTP_INFO("No need to upgrade the link code!");
  1435. return SUCCESS;
  1436. }
  1437. GTP_DEBUG("[burn_fw_link]Begin burn link firmware---->>");
  1438. /* step1:Alloc memory */
  1439. GTP_DEBUG("[burn_fw_link]step1:Alloc memory");
  1440. while (retry++ < 5) {
  1441. fw_link = kzalloc(FW_SECTION_LENGTH, GFP_KERNEL);
  1442. if (fw_link == NULL) {
  1443. continue;
  1444. } else {
  1445. GTP_INFO("[burn_fw_link]Alloc %dk byte memory success.",
  1446. (FW_SECTION_LENGTH / 1024));
  1447. break;
  1448. }
  1449. }
  1450. if (retry >= 5) {
  1451. GTP_ERROR("[burn_fw_link]Alloc memory fail,exit.");
  1452. return FAIL;
  1453. }
  1454. /* step2:load firmware link section 1 */
  1455. GTP_DEBUG("[burn_fw_link]step2:load firmware link section 1");
  1456. offset = update_msg.fw_burned_len - FW_DSP_ISP_LENGTH;
  1457. ret = gup_load_section_file(fw_link, offset, FW_SECTION_LENGTH,
  1458. SEEK_SET);
  1459. if (ret == FAIL) {
  1460. GTP_ERROR("[burn_fw_link]load firmware link section 1 fail.");
  1461. goto exit_burn_fw_link;
  1462. }
  1463. /* step3:burn link firmware section 1 */
  1464. GTP_DEBUG("[burn_fw_link]step3:burn link firmware section 1");
  1465. ret = gup_burn_fw_app_section(client, fw_link, 0x9000,
  1466. FW_SECTION_LENGTH, 0x38);
  1467. if (ret == FAIL) {
  1468. GTP_ERROR("[burn_fw_link]burn link firmware section 1 fail.");
  1469. goto exit_burn_fw_link;
  1470. }
  1471. /* step4:load link firmware section 2 file data */
  1472. GTP_DEBUG("[burn_fw_link]step4:load link firmware section 2 file data");
  1473. offset += FW_SECTION_LENGTH;
  1474. ret = gup_load_section_file(
  1475. fw_link, offset, FW_LINK_LENGTH - FW_SECTION_LENGTH, SEEK_SET);
  1476. if (ret == FAIL) {
  1477. GTP_ERROR("[burn_fw_link]load link firmware section 2 fail.");
  1478. goto exit_burn_fw_link;
  1479. }
  1480. /* step5:burn link firmware section 2 */
  1481. GTP_DEBUG("[burn_fw_link]step4:burn link firmware section 2");
  1482. ret = gup_burn_fw_app_section(client, fw_link, 0x9000,
  1483. FW_LINK_LENGTH - FW_SECTION_LENGTH, 0x39);
  1484. if (ret == FAIL) {
  1485. GTP_ERROR("[burn_fw_link]burn link firmware section 2 fail.");
  1486. goto exit_burn_fw_link;
  1487. }
  1488. update_msg.fw_burned_len += FW_LINK_LENGTH;
  1489. GTP_DEBUG("[burn_fw_link]Burned length:%d", update_msg.fw_burned_len);
  1490. ret = SUCCESS;
  1491. exit_burn_fw_link:
  1492. kfree(fw_link);
  1493. return ret;
  1494. }
  1495. static u8 gup_burn_fw_app_section(struct i2c_client *client, u8 *fw_section,
  1496. u16 start_addr, u32 len, u8 bank_cmd)
  1497. {
  1498. s32 ret = 0;
  1499. u8 rd_buf[5];
  1500. /* step1:hold ss51 & dsp */
  1501. ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x0C);
  1502. if (ret <= 0) {
  1503. GTP_ERROR("[burn_fw_app_section]hold ss51 & dsp fail.");
  1504. return FAIL;
  1505. }
  1506. /* step2:set scramble */
  1507. ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_OPT_B0_, 0x00);
  1508. if (ret <= 0) {
  1509. GTP_ERROR("[burn_fw_app_section]set scramble fail.");
  1510. return FAIL;
  1511. }
  1512. /* step3:hold ss51 & release dsp */
  1513. ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x04);
  1514. if (ret <= 0) {
  1515. GTP_ERROR("[burn_fw_app_section]hold ss51 & release dsp fail.");
  1516. return FAIL;
  1517. }
  1518. /* must delay */
  1519. msleep(20);
  1520. /* step4:select bank */
  1521. ret = gup_set_ic_msg(client, _bRW_MISCTL__SRAM_BANK,
  1522. (bank_cmd >> 4) & 0x0F);
  1523. if (ret <= 0) {
  1524. GTP_ERROR("[burn_fw_section]select bank %d fail.",
  1525. (bank_cmd >> 4) & 0x0F);
  1526. return FAIL;
  1527. }
  1528. /* step5:burn fw section */
  1529. ret = gup_burn_proc(client, fw_section, start_addr, len);
  1530. if (ret == FAIL) {
  1531. GTP_ERROR("[burn_fw_app_section]burn fw_section fail.");
  1532. return FAIL;
  1533. }
  1534. /* step6:send burn cmd to move data to flash from sram */
  1535. ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, bank_cmd & 0x0F);
  1536. if (ret <= 0) {
  1537. GTP_ERROR("[burn_fw_app_section]send burn cmd fail.");
  1538. return FAIL;
  1539. }
  1540. GTP_DEBUG("[burn_fw_section]Wait for the burn is complete......");
  1541. do {
  1542. ret = gup_get_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, rd_buf, 1);
  1543. if (ret <= 0) {
  1544. GTP_ERROR("[burn_fw_app_section]Get burn state fail");
  1545. return FAIL;
  1546. }
  1547. msleep(20);
  1548. /* GTP_DEBUG("[burn_fw_app_section]Get burn state:%d.", */
  1549. /* rd_buf[GTP_ADDR_LENGTH]); */
  1550. } while (rd_buf[GTP_ADDR_LENGTH]);
  1551. /* step7:recall fw section */
  1552. ret = gup_recall_check(client, fw_section, start_addr, len);
  1553. if (ret == FAIL) {
  1554. GTP_ERROR(
  1555. "[burn_fw_app_section]recall check %dk firmware fail.",
  1556. len / 1024);
  1557. return FAIL;
  1558. }
  1559. return SUCCESS;
  1560. }
  1561. static u8 gup_burn_fw_app_code(struct i2c_client *client)
  1562. {
  1563. u8 *fw_app_code = NULL;
  1564. u8 retry = 0;
  1565. s32 ret = 0;
  1566. u16 start_index = 4 * FW_SECTION_LENGTH + FW_DSP_LENGTH +
  1567. FW_BOOT_LENGTH + FW_BOOT_ISP_LENGTH +
  1568. FW_LINK_LENGTH; /* 32 + 4 + 2 + 4 = 42K */
  1569. /* u16 start_index; */
  1570. if (update_msg.fw_burned_len >= update_msg.fw_total_len) {
  1571. GTP_INFO("No need to upgrade the app code!");
  1572. return SUCCESS;
  1573. }
  1574. /* start_index = update_msg.fw_burned_len - FW_DSP_ISP_LENGTH; */
  1575. GTP_DEBUG("[burn_fw_app_code]Begin burn app_code firmware---->>");
  1576. /* step1:alloc memory */
  1577. GTP_DEBUG("[burn_fw_app_code]step1:alloc memory");
  1578. while (retry++ < 5) {
  1579. fw_app_code = kzalloc(FW_SECTION_LENGTH, GFP_KERNEL);
  1580. if (fw_app_code == NULL) {
  1581. continue;
  1582. } else {
  1583. GTP_INFO(
  1584. "[burn_fw_app_code]Alloc %dk byte memory success.",
  1585. (FW_SECTION_LENGTH / 1024));
  1586. break;
  1587. }
  1588. }
  1589. if (retry >= 5) {
  1590. GTP_ERROR("[burn_fw_app_code]Alloc memory fail,exit.");
  1591. return FAIL;
  1592. }
  1593. /* clear control flag */
  1594. ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, 0x00);
  1595. if (ret <= 0) {
  1596. GTP_ERROR("[burn_fw_finish]clear control flag fail.");
  1597. goto exit_burn_fw_app_code;
  1598. }
  1599. /* step2:load app_code firmware section 1 file data */
  1600. GTP_DEBUG(
  1601. "[burn_fw_app_code]step2:load app_code firmware section 1 file data");
  1602. ret = gup_load_section_file(fw_app_code, start_index, FW_SECTION_LENGTH,
  1603. SEEK_SET);
  1604. if (ret == FAIL) {
  1605. GTP_ERROR(
  1606. "[burn_fw_app_code]load app_code firmware section 1 fail.");
  1607. goto exit_burn_fw_app_code;
  1608. }
  1609. /* step3:burn app_code firmware section 1 */
  1610. GTP_DEBUG("[burn_fw_app_code]step3:burn app_code firmware section 1");
  1611. ret = gup_burn_fw_app_section(client, fw_app_code, 0x9000,
  1612. FW_SECTION_LENGTH, 0x3A);
  1613. if (ret == FAIL) {
  1614. GTP_ERROR(
  1615. "[burn_fw_app_code]burn app_code firmware section 1 fail.");
  1616. goto exit_burn_fw_app_code;
  1617. }
  1618. /* step5:load app_code firmware section 2 file data */
  1619. GTP_DEBUG(
  1620. "[burn_fw_app_code]step5:load app_code firmware section 2 file data");
  1621. ret = gup_load_section_file(fw_app_code,
  1622. start_index + FW_SECTION_LENGTH,
  1623. FW_SECTION_LENGTH, SEEK_SET);
  1624. if (ret == FAIL) {
  1625. GTP_ERROR(
  1626. "[burn_fw_app_code]load app_code firmware section 2 fail.");
  1627. goto exit_burn_fw_app_code;
  1628. }
  1629. /* step6:burn app_code firmware section 2 */
  1630. GTP_DEBUG("[burn_fw_app_code]step6:burn app_code firmware section 2");
  1631. ret = gup_burn_fw_app_section(client, fw_app_code, 0x9000,
  1632. FW_SECTION_LENGTH, 0x3B);
  1633. if (ret == FAIL) {
  1634. GTP_ERROR(
  1635. "[burn_fw_app_code]burn app_code firmware section 2 fail.");
  1636. goto exit_burn_fw_app_code;
  1637. }
  1638. /* step7:load app_code firmware section 3 file data */
  1639. GTP_DEBUG(
  1640. "[burn_fw_app_code]step7:load app_code firmware section 3 file data");
  1641. ret = gup_load_section_file(fw_app_code,
  1642. start_index + 2 * FW_SECTION_LENGTH,
  1643. FW_SECTION_LENGTH, SEEK_SET);
  1644. if (ret == FAIL) {
  1645. GTP_ERROR(
  1646. "[burn_fw_app_code]load app_code firmware section 3 fail.");
  1647. goto exit_burn_fw_app_code;
  1648. }
  1649. /* step8:burn app_code firmware section 3 */
  1650. GTP_DEBUG("[burn_fw_app_code]step8:burn app_code firmware section 3");
  1651. ret = gup_burn_fw_app_section(client, fw_app_code, 0x9000,
  1652. FW_SECTION_LENGTH, 0x3C);
  1653. if (ret == FAIL) {
  1654. GTP_ERROR(
  1655. "[burn_fw_app_code]burn app_code firmware section 3 fail.");
  1656. goto exit_burn_fw_app_code;
  1657. }
  1658. /* step9:load app_code firmware section 4 file data */
  1659. GTP_DEBUG(
  1660. "[burn_fw_app_code]step9:load app_code firmware section 4 file data");
  1661. ret = gup_load_section_file(fw_app_code,
  1662. start_index + 3 * FW_SECTION_LENGTH,
  1663. FW_SECTION_LENGTH, SEEK_SET);
  1664. if (ret == FAIL) {
  1665. GTP_ERROR(
  1666. "[burn_fw_app_code]load app_code firmware section 4 fail.");
  1667. goto exit_burn_fw_app_code;
  1668. }
  1669. /* step10:burn app_code firmware section 4 */
  1670. GTP_DEBUG("[burn_fw_app_code]step10:burn app_code firmware section 4");
  1671. ret = gup_burn_fw_app_section(client, fw_app_code, 0x9000,
  1672. FW_SECTION_LENGTH, 0x3D);
  1673. if (ret == FAIL) {
  1674. GTP_ERROR(
  1675. "[burn_fw_app_code]burn app_code firmware section 4 fail.");
  1676. goto exit_burn_fw_app_code;
  1677. }
  1678. /* update_msg.fw_burned_len += FW_APP_CODE_LENGTH; */
  1679. GTP_DEBUG("[burn_fw_gwake]Burned length:%d", update_msg.fw_burned_len);
  1680. ret = SUCCESS;
  1681. exit_burn_fw_app_code:
  1682. kfree(fw_app_code);
  1683. return ret;
  1684. }
  1685. static u8 gup_burn_fw_finish(struct i2c_client *client)
  1686. {
  1687. u8 *fw_ss51 = NULL;
  1688. u8 retry = 0;
  1689. s32 ret = 0;
  1690. GTP_INFO("[burn_fw_finish]burn first 8K of ss51 and finish update.");
  1691. /* step1:alloc memory */
  1692. GTP_DEBUG("[burn_fw_finish]step1:alloc memory");
  1693. while (retry++ < 5) {
  1694. fw_ss51 = kzalloc(FW_SECTION_LENGTH, GFP_KERNEL);
  1695. if (fw_ss51 == NULL) {
  1696. continue;
  1697. } else {
  1698. GTP_DEBUG(
  1699. "[burn_fw_finish]Alloc %dk byte memory success.",
  1700. (FW_SECTION_LENGTH / 1024));
  1701. break;
  1702. }
  1703. }
  1704. if (retry >= 5) {
  1705. GTP_ERROR("[burn_fw_finish]Alloc memory fail,exit.");
  1706. return FAIL;
  1707. }
  1708. GTP_DEBUG("[burn_fw_finish]step2: burn ss51 first 8K.");
  1709. ret = gup_load_section_file(fw_ss51, 0, FW_SECTION_LENGTH, SEEK_SET);
  1710. if (ret == FAIL) {
  1711. GTP_ERROR("[burn_fw_finish]load ss51 firmware section 1 fail.");
  1712. goto exit_burn_fw_finish;
  1713. }
  1714. GTP_DEBUG("[burn_fw_finish]step3:clear control flag");
  1715. ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, 0x00);
  1716. if (ret <= 0) {
  1717. GTP_ERROR("[burn_fw_finish]clear control flag fail.");
  1718. goto exit_burn_fw_finish;
  1719. }
  1720. GTP_DEBUG("[burn_fw_finish]step4:burn ss51 firmware section 1");
  1721. ret = gup_burn_fw_section(client, fw_ss51, 0xC000, 0x01);
  1722. if (ret == FAIL) {
  1723. GTP_ERROR("[burn_fw_finish]burn ss51 firmware section 1 fail.");
  1724. goto exit_burn_fw_finish;
  1725. }
  1726. /* step11:enable download DSP code */
  1727. GTP_DEBUG("[burn_fw_finish]step5:enable download DSP code ");
  1728. ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, 0x99);
  1729. if (ret <= 0) {
  1730. GTP_ERROR("[burn_fw_finish]enable download DSP code fail.");
  1731. goto exit_burn_fw_finish;
  1732. }
  1733. /* step12:release ss51 & hold dsp */
  1734. GTP_DEBUG("[burn_fw_finish]step6:release ss51 & hold dsp");
  1735. ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x08);
  1736. if (ret <= 0) {
  1737. GTP_ERROR("[burn_fw_finish]release ss51 & hold dsp fail.");
  1738. goto exit_burn_fw_finish;
  1739. }
  1740. kfree(fw_ss51);
  1741. return SUCCESS;
  1742. exit_burn_fw_finish:
  1743. kfree(fw_ss51);
  1744. return FAIL;
  1745. }
  1746. s32 gup_update_proc(void *dir)
  1747. {
  1748. s32 ret = 0;
  1749. u8 retry = 0;
  1750. s32 update_ret = FAIL;
  1751. struct st_fw_head fw_head;
  1752. GTP_INFO("[update_proc]Begin update ......");
  1753. #ifdef CONFIG_GTP_AUTO_UPDATE
  1754. if (searching_file == 1) {
  1755. u8 timeout = 0;
  1756. searching_file = 0; /* exit .bin update file searching */
  1757. GTP_INFO("Exiting searching file for auto update.");
  1758. while ((show_len != 200) && (show_len != 100) &&
  1759. (timeout++ < 150))
  1760. /* wait for auto update quitted completely */
  1761. msleep(100);
  1762. }
  1763. #endif
  1764. show_len = 1;
  1765. total_len = 100;
  1766. #ifdef CONFIG_GTP_COMPATIBLE_MODE
  1767. if (gtp_chip_type == CHIP_TYPE_GT9F)
  1768. return gup_fw_download_proc(dir, GTP_FL_FW_BURN);
  1769. #endif
  1770. update_msg.file = NULL;
  1771. update_msg.fw = NULL;
  1772. ret = gup_check_update_file(i2c_client_point, &fw_head,
  1773. (u8 *)dir); /* 20121212 */
  1774. if (ret == FAIL) {
  1775. GTP_ERROR("[update_proc]check update file fail.");
  1776. goto file_fail;
  1777. }
  1778. /* gtp_reset_guitar(i2c_client_point, 20); */
  1779. ret = gup_get_ic_fw_msg(i2c_client_point);
  1780. if (ret == FAIL) {
  1781. GTP_ERROR("[update_proc]get ic message fail.");
  1782. goto file_fail;
  1783. }
  1784. ret = gup_enter_update_judge(&fw_head); /* 20121212 */
  1785. if (ret == FAIL) {
  1786. GTP_ERROR("[update_proc]Check *.bin file fail.");
  1787. goto file_fail;
  1788. }
  1789. gtp_loading_fw = 1;
  1790. gtp_irq_disable();
  1791. #ifdef CONFIG_GTP_ESD_PROTECT
  1792. gtp_esd_switch(i2c_client_point, SWITCH_OFF);
  1793. #endif
  1794. #ifdef CONFIG_GTP_CHARGER_DETECT
  1795. gtp_charger_switch(0);
  1796. #endif
  1797. ret = gup_enter_update_mode(i2c_client_point);
  1798. if (ret == FAIL) {
  1799. GTP_ERROR("[update_proc]enter update mode fail.");
  1800. goto update_fail;
  1801. }
  1802. while (retry++ < 5) {
  1803. show_len = 10;
  1804. total_len = 100;
  1805. update_msg.fw_burned_len = 0;
  1806. GTP_DEBUG("[update_proc]Burned length:%d",
  1807. update_msg.fw_burned_len);
  1808. ret = gup_burn_dsp_isp(i2c_client_point);
  1809. if (ret == FAIL) {
  1810. GTP_ERROR("[update_proc]burn dsp isp fail.");
  1811. continue;
  1812. }
  1813. show_len = 20;
  1814. ret = gup_burn_fw_app_code(i2c_client_point);
  1815. if (ret == FAIL) {
  1816. GTP_ERROR("[update_proc]burn app_code firmware fail.");
  1817. continue;
  1818. }
  1819. show_len = 30;
  1820. ret = gup_burn_fw_ss51(i2c_client_point);
  1821. if (ret == FAIL) {
  1822. GTP_ERROR("[update_proc]burn ss51 firmware fail.");
  1823. continue;
  1824. }
  1825. show_len = 40;
  1826. ret = gup_burn_fw_dsp(i2c_client_point);
  1827. if (ret == FAIL) {
  1828. GTP_ERROR("[update_proc]burn dsp firmware fail.");
  1829. continue;
  1830. }
  1831. show_len = 50;
  1832. ret = gup_burn_fw_boot(i2c_client_point);
  1833. if (ret == FAIL) {
  1834. GTP_ERROR(
  1835. "[update_proc]burn bootloader firmware fail.");
  1836. continue;
  1837. }
  1838. show_len = 60;
  1839. ret = gup_burn_fw_boot_isp(i2c_client_point);
  1840. if (ret == FAIL) {
  1841. GTP_ERROR("[update_proc]burn boot_isp firmware fail.");
  1842. continue;
  1843. }
  1844. show_len = 70;
  1845. ret = gup_burn_fw_link(i2c_client_point);
  1846. if (ret == FAIL) {
  1847. GTP_ERROR("[update_proc]burn link firmware fail.");
  1848. continue;
  1849. }
  1850. show_len = 90;
  1851. ret = gup_burn_fw_finish(i2c_client_point);
  1852. if (ret == FAIL) {
  1853. GTP_ERROR("[update_proc]burn finish fail.");
  1854. continue;
  1855. }
  1856. show_len = 95;
  1857. GTP_INFO("[update_proc]UPDATE SUCCESS.");
  1858. break;
  1859. }
  1860. if (retry >= 5) {
  1861. GTP_ERROR("[update_proc]retry timeout,UPDATE FAIL.");
  1862. update_ret = FAIL;
  1863. } else {
  1864. update_ret = SUCCESS;
  1865. }
  1866. update_fail:
  1867. GTP_DEBUG("[update_proc]leave update mode.");
  1868. gup_leave_update_mode();
  1869. if (update_ret == SUCCESS) {
  1870. GTP_DEBUG("[update_proc]send config.");
  1871. ret = gtp_init_panel(i2c_client_point);
  1872. if (ret < 0)
  1873. GTP_ERROR("[update_proc]send config fail.");
  1874. }
  1875. gtp_loading_fw = 0;
  1876. #ifdef CONFIG_GTP_ESD_PROTECT
  1877. gtp_esd_switch(i2c_client_point, SWITCH_ON);
  1878. #endif
  1879. #ifdef CONFIG_GTP_CHARGER_DETECT
  1880. gtp_charger_switch(1);
  1881. #endif
  1882. file_fail:
  1883. gtp_irq_enable();
  1884. #ifdef CONFIG_GTP_REQUEST_FW_UPDATE
  1885. if (update_msg.fw != NULL) {
  1886. release_firmware(update_msg.fw);
  1887. update_msg.fw = NULL;
  1888. }
  1889. #endif
  1890. if (update_msg.file && !IS_ERR(update_msg.file)) {
  1891. if (update_msg.old_fs)
  1892. set_fs(update_msg.old_fs);
  1893. filp_close(update_msg.file, NULL);
  1894. }
  1895. #if (defined(CONFIG_GTP_AUTO_UPDATE) && defined(CONFIG_GTP_AUTO_UPDATE_CFG) && \
  1896. defined(CONFIG_GTP_REQUEST_FW_UPDATE))
  1897. if (dir == NULL) {
  1898. gup_search_file(AUTO_SEARCH_CFG);
  1899. if (got_file_flag & CFG_FILE_READY) {
  1900. ret = gup_update_config(i2c_client_point);
  1901. if (ret == FAIL)
  1902. GTP_ERROR("Update config failed!");
  1903. }
  1904. }
  1905. #endif
  1906. total_len = 100;
  1907. if (update_ret == SUCCESS) {
  1908. show_len = 100;
  1909. return SUCCESS;
  1910. }
  1911. show_len = 200;
  1912. return FAIL;
  1913. }
  1914. u8 gup_init_update_proc(struct i2c_client *client)
  1915. {
  1916. struct task_struct *thread = NULL;
  1917. GTP_INFO("Ready to run auto update thread");
  1918. #ifdef CONFIG_GTP_COMPATIBLE_MODE
  1919. if (gtp_chip_type == CHIP_TYPE_GT9F)
  1920. thread = kthread_run(gup_update_proc, "update",
  1921. "fl_auto_update");
  1922. else
  1923. #endif
  1924. thread = kthread_run(gup_update_proc, (void *)NULL,
  1925. "guitar_update");
  1926. if (IS_ERR(thread)) {
  1927. GTP_ERROR("Failed to create update thread.\n");
  1928. return -1;
  1929. }
  1930. return 0;
  1931. }
  1932. /* ******************* For GT9XXF Start *********************/
  1933. #define FL_UPDATE_PATH "/data/_fl_update_.bin"
  1934. #define FL_UPDATE_PATH_SD "/sdcard/_fl_update_.bin"
  1935. #define GUP_FW_CHK_SIZE 256
  1936. #define MAX_CHECK_TIMES 128 /* max: 2 * (16 * 1024) / 256 = 128 */
  1937. /* for clk cal */
  1938. #define PULSE_LENGTH (200)
  1939. #define INIT_CLK_DAC (50)
  1940. #define MAX_CLK_DAC (120)
  1941. #define CLK_AVG_TIME (1)
  1942. #define MILLION 1000000
  1943. #define _wRW_MISCTL__RG_DMY 0x4282
  1944. #define _bRW_MISCTL__RG_OSC_CALIB 0x4268
  1945. #define _fRW_MISCTL__GIO0 0x41e9
  1946. #define _fRW_MISCTL__GIO1 0x41ed
  1947. #define _fRW_MISCTL__GIO2 0x41f1
  1948. #define _fRW_MISCTL__GIO3 0x41f5
  1949. #define _fRW_MISCTL__GIO4 0x41f9
  1950. #define _fRW_MISCTL__GIO5 0x41fd
  1951. #define _fRW_MISCTL__GIO6 0x4201
  1952. #define _fRW_MISCTL__GIO7 0x4205
  1953. #define _fRW_MISCTL__GIO8 0x4209
  1954. #define _fRW_MISCTL__GIO9 0x420d
  1955. #define _fRW_MISCTL__MEA 0x41a0
  1956. #define _bRW_MISCTL__MEA_MODE 0x41a1
  1957. #define _wRW_MISCTL__MEA_MAX_NUM 0x41a4
  1958. #define _dRO_MISCTL__MEA_VAL 0x41b0
  1959. #define _bRW_MISCTL__MEA_SRCSEL 0x41a3
  1960. #define _bRO_MISCTL__MEA_RDY 0x41a8
  1961. #define _rRW_MISCTL__ANA_RXADC_B0_ 0x4250
  1962. #define _bRW_MISCTL__RG_LDO_A18_PWD 0x426f
  1963. #define _bRW_MISCTL__RG_BG_PWD 0x426a
  1964. #define _bRW_MISCTL__RG_CLKGEN_PWD 0x4269
  1965. #define _fRW_MISCTL__RG_RXADC_PWD 0x426a
  1966. #define _bRW_MISCTL__OSC_CK_SEL 0x4030
  1967. #define _rRW_MISCTL_RG_DMY83 0x4283
  1968. #define _rRW_MISCTL__GIO1CTL_B2_ 0x41ee
  1969. #define _rRW_MISCTL__GIO1CTL_B1_ 0x41ed
  1970. #if defined(CONFIG_GTP_COMPATIBLE_MODE) || defined(CONFIG_GTP_HOTKNOT)
  1971. u8 gup_check_fs_mounted(char *path_name)
  1972. {
  1973. struct path root_path;
  1974. struct path path;
  1975. int err;
  1976. err = kern_path("/", LOOKUP_FOLLOW, &root_path);
  1977. if (err)
  1978. return FAIL;
  1979. err = kern_path(path_name, LOOKUP_FOLLOW, &path);
  1980. if (err) {
  1981. err = FAIL;
  1982. goto exit_chk;
  1983. }
  1984. if (path.mnt->mnt_sb == root_path.mnt->mnt_sb)
  1985. /* not mounted */
  1986. err = FAIL;
  1987. else
  1988. err = SUCCESS;
  1989. path_put(&path);
  1990. exit_chk:
  1991. path_put(&root_path);
  1992. return err;
  1993. }
  1994. s32 gup_hold_ss51_dsp(struct i2c_client *client)
  1995. {
  1996. s32 ret = -1;
  1997. s32 retry = 0;
  1998. u8 rd_buf[3];
  1999. while (retry++ < 200) {
  2000. /* step4:Hold ss51 & dsp */
  2001. ret = gup_set_ic_msg(client, _rRW_MISCTL__SWRST_B0_, 0x0C);
  2002. if (ret <= 0) {
  2003. GTP_DEBUG("Hold ss51 & dsp I2C error,retry:%d", retry);
  2004. continue;
  2005. }
  2006. /* step5:Confirm hold */
  2007. ret = gup_get_ic_msg(client, _rRW_MISCTL__SWRST_B0_, rd_buf, 1);
  2008. if (ret <= 0) {
  2009. GTP_DEBUG("Hold ss51 & dsp I2C error,retry:%d", retry);
  2010. continue;
  2011. }
  2012. if (rd_buf[GTP_ADDR_LENGTH] == 0x0C) {
  2013. GTP_DEBUG(
  2014. "[enter_update_mode]Hold ss51 & dsp confirm SUCCESS");
  2015. break;
  2016. }
  2017. GTP_DEBUG("Hold ss51 & dsp confirm 0x4180 failed,value:%d",
  2018. rd_buf[GTP_ADDR_LENGTH]);
  2019. }
  2020. if (retry >= 200) {
  2021. GTP_ERROR("Enter update Hold ss51 failed.");
  2022. return FAIL;
  2023. }
  2024. /* DSP_CK and DSP_ALU_CK PowerOn */
  2025. ret = gup_set_ic_msg(client, 0x4010, 0x00);
  2026. if (ret <= 0) {
  2027. GTP_ERROR(
  2028. "[enter_update_mode]DSP_CK and DSP_ALU_CK PowerOn fail.");
  2029. return FAIL;
  2030. }
  2031. /* disable wdt */
  2032. ret = gup_set_ic_msg(client, _bRW_MISCTL__TMR0_EN, 0x00);
  2033. if (ret <= 0) {
  2034. GTP_ERROR("[enter_update_mode]disable wdt fail.");
  2035. return FAIL;
  2036. }
  2037. /* clear cache enable */
  2038. ret = gup_set_ic_msg(client, _bRW_MISCTL__CACHE_EN, 0x00);
  2039. if (ret <= 0) {
  2040. GTP_ERROR("[enter_update_mode]clear cache enable fail.");
  2041. return FAIL;
  2042. }
  2043. /* set boot from sram */
  2044. ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOTCTL_B0_, 0x02);
  2045. if (ret <= 0) {
  2046. GTP_ERROR("[enter_update_mode]set boot from sram fail.");
  2047. return FAIL;
  2048. }
  2049. /* software reboot */
  2050. ret = gup_set_ic_msg(client, _bWO_MISCTL__CPU_SWRST_PULSE, 0x01);
  2051. if (ret <= 0) {
  2052. GTP_ERROR("[enter_update_mode]software reboot fail.");
  2053. return FAIL;
  2054. }
  2055. return SUCCESS;
  2056. }
  2057. #ifdef CONFIG_GTP_COMPATIBLE_MODE
  2058. s32 gup_enter_update_mode_fl(struct i2c_client *client)
  2059. {
  2060. s32 ret = -1;
  2061. /* s32 retry = 0; */
  2062. /* u8 rd_buf[3]; */
  2063. /* step1:RST output low last at least 2ms */
  2064. gtp_gpio_output(GTP_RST_GPIO, 0);
  2065. msleep(20);
  2066. /* step2:select I2C slave addr,INT:0--0xBA;1--0x28. */
  2067. gtp_gpio_output(GTP_IRQ_GPIO, (client->addr == 0x14));
  2068. msleep(20);
  2069. /* step3:RST output high reset guitar */
  2070. gtp_gpio_output(GTP_RST_GPIO, 1);
  2071. msleep(20);
  2072. /* select addr & hold ss51_dsp */
  2073. ret = gup_hold_ss51_dsp(client);
  2074. if (ret <= 0) {
  2075. GTP_ERROR("[enter_update_mode]hold ss51 & dsp failed.");
  2076. return FAIL;
  2077. }
  2078. /* clear control flag */
  2079. ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_CTL_, 0x00);
  2080. if (ret <= 0) {
  2081. GTP_ERROR("[enter_update_mode]clear control flag fail.");
  2082. return FAIL;
  2083. }
  2084. /* set scramble */
  2085. ret = gup_set_ic_msg(client, _rRW_MISCTL__BOOT_OPT_B0_, 0x00);
  2086. if (ret <= 0) {
  2087. GTP_ERROR("[enter_update_mode]set scramble fail.");
  2088. return FAIL;
  2089. }
  2090. /* enable accessing code */
  2091. ret = gup_set_ic_msg(client, _bRW_MISCTL__MEM_CD_EN, 0x01);
  2092. if (ret <= 0) {
  2093. GTP_ERROR("[enter_update_mode]enable accessing code fail.");
  2094. return FAIL;
  2095. }
  2096. return SUCCESS;
  2097. }
  2098. static u8 gup_check_update_file_fl(struct i2c_client *client,
  2099. struct st_fw_head *fw_head, char *path)
  2100. {
  2101. s32 i = 0;
  2102. s32 fw_checksum = 0;
  2103. if (!update_msg.fw)
  2104. return FAIL;
  2105. memcpy(fw_head, &update_msg.fw->data[0], FW_HEAD_LENGTH);
  2106. update_msg.fw_total_len = update_msg.fw->size;
  2107. GTP_INFO("FILE HARDWARE INFO:%02x%02x%02x%02x", fw_head->hw_info[0],
  2108. fw_head->hw_info[1], fw_head->hw_info[2], fw_head->hw_info[3]);
  2109. GTP_INFO("FILE PID:%s", fw_head->pid);
  2110. fw_head->vid =
  2111. ((fw_head->vid & 0xFF00) >> 8) + ((fw_head->vid & 0x00FF) << 8);
  2112. GTP_INFO("FILE VID:%04x", fw_head->vid);
  2113. /* check firmware legality */
  2114. fw_checksum = 0;
  2115. for (i = FW_HEAD_LENGTH; i < update_msg.fw_total_len; i += 2)
  2116. fw_checksum += (update_msg.fw->data[i] << 8) +
  2117. update_msg.fw->data[i + 1];
  2118. GTP_DEBUG("firmware checksum:%x", fw_checksum & 0xFFFF);
  2119. if (fw_checksum & 0xFFFF) {
  2120. GTP_ERROR("Illegal firmware file.");
  2121. return FAIL;
  2122. }
  2123. return SUCCESS;
  2124. }
  2125. static u8 gup_download_fw_ss51(struct i2c_client *client, u8 dwn_mode)
  2126. {
  2127. s32 ret = 0;
  2128. if (!update_msg.fw)
  2129. return FAIL;
  2130. if (dwn_mode == GTP_FL_FW_BURN)
  2131. GTP_INFO(
  2132. "[download_fw_ss51]Begin download ss51 firmware---->>");
  2133. else
  2134. GTP_INFO("[download_fw_ss51]Begin check ss51 firmware----->>");
  2135. /* step1:download FW section 1 */
  2136. GTP_DEBUG("[download_fw_ss51]step1:download FW section 1");
  2137. ret = gup_set_ic_msg(i2c_client_point, _bRW_MISCTL__SRAM_BANK, 0x00);
  2138. if (ret <= 0) {
  2139. GTP_ERROR("[download_fw_ss51]select bank0 fail.");
  2140. ret = FAIL;
  2141. goto exit_download_fw_ss51;
  2142. }
  2143. ret = i2c_write_bytes(client, 0xC000,
  2144. (u8 *)&update_msg.fw->data[FW_HEAD_LENGTH],
  2145. FW_DOWNLOAD_LENGTH); /* write the first bank */
  2146. if (ret == -1) {
  2147. GTP_ERROR("[download_fw_ss51]download FW section 1 fail.");
  2148. ret = FAIL;
  2149. goto exit_download_fw_ss51;
  2150. }
  2151. if (dwn_mode == GTP_FL_FW_BURN) {
  2152. ret = gup_check_and_repair(
  2153. i2c_client_point, 0xC000,
  2154. (u8 *)&update_msg.fw->data[FW_HEAD_LENGTH],
  2155. FW_DOWNLOAD_LENGTH);
  2156. if (ret == FAIL) {
  2157. GTP_ERROR(
  2158. "[download_fw_ss51]Checked FW section 1 fail.");
  2159. goto exit_download_fw_ss51;
  2160. }
  2161. }
  2162. /* step2:download FW section 2 */
  2163. GTP_DEBUG("[download_fw_ss51]step2:download FW section 1");
  2164. ret = gup_set_ic_msg(i2c_client_point, _bRW_MISCTL__SRAM_BANK, 0x01);
  2165. if (ret <= 0) {
  2166. GTP_ERROR("[download_fw_ss51]select bank1 fail.");
  2167. ret = FAIL;
  2168. goto exit_download_fw_ss51;
  2169. }
  2170. ret = i2c_write_bytes(
  2171. client, 0xC000,
  2172. (u8 *)&update_msg.fw->data[FW_HEAD_LENGTH + FW_DOWNLOAD_LENGTH],
  2173. FW_DOWNLOAD_LENGTH);
  2174. if (ret == -1) {
  2175. GTP_ERROR("[download_fw_ss51]download FW section 2 fail.");
  2176. ret = FAIL;
  2177. goto exit_download_fw_ss51;
  2178. }
  2179. if (dwn_mode == GTP_FL_FW_BURN) {
  2180. ret = gup_check_and_repair(
  2181. i2c_client_point, 0xC000,
  2182. (u8 *)&update_msg.fw
  2183. ->data[FW_HEAD_LENGTH + FW_DOWNLOAD_LENGTH],
  2184. FW_DOWNLOAD_LENGTH);
  2185. if (ret == FAIL) {
  2186. GTP_ERROR(
  2187. "[download_fw_ss51]Checked FW section 2 fail.");
  2188. goto exit_download_fw_ss51;
  2189. }
  2190. }
  2191. ret = SUCCESS;
  2192. exit_download_fw_ss51:
  2193. return ret;
  2194. }
  2195. #endif /* CONFIG_GTP_COMPATIBLE_MODE */
  2196. #ifndef CONFIG_GTP_SUPPORT_I2C_DMA
  2197. static s32 i2c_auto_read(struct i2c_client *client, u8 *rxbuf, int len)
  2198. {
  2199. u8 retry;
  2200. u16 left = len;
  2201. u16 offset = 0;
  2202. struct i2c_msg msg = {
  2203. #ifdef CONFIG_MTK_I2C_EXTENSION
  2204. .addr = ((client->addr & I2C_MASK_FLAG) | (I2C_ENEXT_FLAG)),
  2205. #else
  2206. .addr = client->addr,
  2207. #endif
  2208. .flags = I2C_M_RD,
  2209. #ifdef CONFIG_MTK_I2C_EXTENSION
  2210. .timing = I2C_MASTER_CLOCK
  2211. #endif
  2212. };
  2213. if (rxbuf == NULL)
  2214. return -1;
  2215. while (left > 0) {
  2216. msg.buf = &rxbuf[offset];
  2217. if (left > MAX_TRANSACTION_LENGTH) {
  2218. msg.len = MAX_TRANSACTION_LENGTH;
  2219. left -= MAX_TRANSACTION_LENGTH;
  2220. offset += MAX_TRANSACTION_LENGTH;
  2221. } else {
  2222. msg.len = left;
  2223. left = 0;
  2224. }
  2225. retry = 0;
  2226. while (i2c_transfer(client->adapter, &msg, 1) != 1) {
  2227. retry++;
  2228. if (retry == 20) {
  2229. GTP_ERROR("I2C read 0x%X length=%d failed\n",
  2230. offset, len);
  2231. return -1;
  2232. }
  2233. }
  2234. }
  2235. return 0;
  2236. }
  2237. #endif
  2238. static u8 gup_check_and_repair(struct i2c_client *client, s32 chk_start_addr,
  2239. u8 *target_fw, u32 chk_total_length)
  2240. {
  2241. s32 ret = 0;
  2242. u32 checked_len = 0;
  2243. u8 checked_times = 0;
  2244. u32 chk_addr = 0;
  2245. u8 chk_buf[GUP_FW_CHK_SIZE];
  2246. u32 rd_size = 0;
  2247. u8 flag_err = 0;
  2248. s32 i = 0;
  2249. chk_addr = chk_start_addr;
  2250. while ((checked_times < MAX_CHECK_TIMES) &&
  2251. (checked_len < chk_total_length)) {
  2252. rd_size = chk_total_length - checked_len;
  2253. if (rd_size >= GUP_FW_CHK_SIZE)
  2254. rd_size = GUP_FW_CHK_SIZE;
  2255. #ifdef CONFIG_GTP_SUPPORT_I2C_DMA
  2256. ret = i2c_read_bytes(client, chk_addr, chk_buf, rd_size);
  2257. #else
  2258. if (!i)
  2259. ret = i2c_read_bytes(client, chk_addr, chk_buf,
  2260. rd_size);
  2261. else
  2262. ret = i2c_auto_read(client, chk_buf, rd_size);
  2263. #endif
  2264. if (-1 == ret) {
  2265. GTP_ERROR("Read chk ram fw i2c error");
  2266. checked_times++;
  2267. continue;
  2268. }
  2269. for (i = 0; i < rd_size; i++) {
  2270. if (chk_buf[i] != target_fw[i]) {
  2271. GTP_ERROR(
  2272. "Ram pos[0x%04x] checked failed,rewrite.",
  2273. chk_addr + i);
  2274. i2c_write_bytes(client, chk_addr + i,
  2275. &target_fw[i], rd_size - i);
  2276. flag_err = 1;
  2277. i = 0;
  2278. break;
  2279. }
  2280. }
  2281. if (!flag_err) {
  2282. checked_len += rd_size;
  2283. target_fw += rd_size;
  2284. chk_addr += rd_size;
  2285. } else {
  2286. flag_err = 0;
  2287. checked_times++;
  2288. }
  2289. }
  2290. if (checked_times >= MAX_CHECK_TIMES) {
  2291. GTP_ERROR("Ram data check failed.");
  2292. return FAIL;
  2293. }
  2294. return SUCCESS;
  2295. }
  2296. #ifdef CONFIG_GTP_COMPATIBLE_MODE
  2297. static u8 gup_download_fw_dsp(struct i2c_client *client, u8 dwn_mode)
  2298. {
  2299. s32 ret = 0;
  2300. if (!update_msg.fw)
  2301. return FAIL;
  2302. if (dwn_mode == GTP_FL_FW_BURN)
  2303. GTP_INFO("[download_fw_dsp]Begin download dsp fw---->>");
  2304. else
  2305. GTP_INFO("[download_fw_dsp]Begin check dsp fw---->>");
  2306. /* step1:select bank2 */
  2307. GTP_DEBUG("[download_fw_dsp]step1:select bank2");
  2308. ret = gup_set_ic_msg(client, _bRW_MISCTL__SRAM_BANK, 0x02);
  2309. if (ret <= 0) {
  2310. GTP_ERROR("[download_fw_dsp]select bank2 fail.");
  2311. ret = FAIL;
  2312. goto exit_download_fw_dsp;
  2313. }
  2314. ret = i2c_write_bytes(
  2315. client, 0xC000,
  2316. (u8 *)&update_msg.fw
  2317. ->data[FW_HEAD_LENGTH + 2 * FW_DOWNLOAD_LENGTH],
  2318. FW_DSP_LENGTH); /* write the second bank */
  2319. if (ret == -1) {
  2320. GTP_ERROR("[download_fw_dsp]download FW dsp fail.");
  2321. ret = FAIL;
  2322. goto exit_download_fw_dsp;
  2323. }
  2324. if (dwn_mode == GTP_FL_FW_BURN) {
  2325. ret = gup_check_and_repair(
  2326. client, 0xC000,
  2327. (u8 *)&update_msg.fw
  2328. ->data[FW_HEAD_LENGTH + 2 * FW_DOWNLOAD_LENGTH],
  2329. FW_DSP_LENGTH);
  2330. if (ret == FAIL) {
  2331. GTP_ERROR("[download_fw_dsp]Checked FW dsp fail.");
  2332. goto exit_download_fw_dsp;
  2333. }
  2334. }
  2335. ret = SUCCESS;
  2336. exit_download_fw_dsp:
  2337. return ret;
  2338. }
  2339. s32 gup_fw_download_proc(void *dir, u8 dwn_mode)
  2340. {
  2341. s32 ret = 0;
  2342. u8 retry = 0;
  2343. struct st_fw_head fw_head;
  2344. if (dwn_mode == GTP_FL_FW_BURN)
  2345. GTP_INFO("[fw_download_proc]Begin fw download ......");
  2346. else
  2347. GTP_INFO("[fw_download_proc]Begin fw check ......");
  2348. show_len = 0;
  2349. total_len = 100;
  2350. GTP_INFO("Request firmware...");
  2351. ret = request_firmware(&update_msg.fw, GT9XX_FW_NAME,
  2352. &i2c_client_point->dev);
  2353. if (ret < 0) {
  2354. GTP_ERROR("Request firmware failed - %s (%d)\n", GT9XX_FW_NAME,
  2355. ret);
  2356. total_len = 200;
  2357. return FAIL;
  2358. }
  2359. GTP_INFO("Firmware size: %zd", update_msg.fw->size);
  2360. if (update_msg.fw->size <
  2361. (FW_HEAD_LENGTH + FW_SECTION_LENGTH * 4 + FW_DSP_ISP_LENGTH +
  2362. FW_DSP_LENGTH + FW_BOOT_LENGTH)) {
  2363. GTP_ERROR("INVALID firmware!");
  2364. goto err_fw;
  2365. }
  2366. ret = gup_check_update_file_fl(i2c_client_point, &fw_head, (char *)dir);
  2367. if (ret == FAIL) {
  2368. GTP_ERROR("[fw_download_proc]check update file fail.");
  2369. goto err_fw;
  2370. }
  2371. show_len = 10;
  2372. gtp_irq_disable();
  2373. if (dir != NULL) {
  2374. #ifdef CONFIG_GTP_ESD_PROTECT
  2375. gtp_esd_switch(i2c_client_point, SWITCH_OFF);
  2376. #endif
  2377. #ifdef CONFIG_GTP_CHARGER_DETECT
  2378. gtp_charger_switch(0);
  2379. #endif
  2380. }
  2381. ret = gup_enter_update_mode_fl(i2c_client_point);
  2382. show_len = 20;
  2383. if (ret == FAIL) {
  2384. GTP_ERROR("[fw_download_proc]enter update mode fail.");
  2385. goto download_fail;
  2386. }
  2387. while (retry++ < 5) {
  2388. ret = gup_download_fw_ss51(i2c_client_point, dwn_mode);
  2389. if (ret == FAIL) {
  2390. GTP_ERROR("[fw_download_proc]burn ss51 firmware fail.");
  2391. continue;
  2392. }
  2393. show_len = 60;
  2394. ret = gup_download_fw_dsp(i2c_client_point, dwn_mode);
  2395. if (ret == FAIL) {
  2396. GTP_ERROR("[fw_download_proc]burn dsp firmware fail.");
  2397. continue;
  2398. }
  2399. show_len = 80;
  2400. GTP_INFO("[fw_download_proc]UPDATE SUCCESS.");
  2401. break;
  2402. }
  2403. if (retry >= 5) {
  2404. GTP_ERROR("[fw_download_proc]retry timeout,UPDATE FAIL.");
  2405. goto download_fail;
  2406. }
  2407. if (dir != NULL) {
  2408. gtp_fw_startup(i2c_client_point);
  2409. #ifdef CONFIG_GTP_ESD_PROTECT
  2410. gtp_esd_switch(i2c_client_point, SWITCH_ON);
  2411. #endif
  2412. #ifdef CONFIG_GTP_CHARGER_DETECT
  2413. gtp_charger_switch(1);
  2414. #endif
  2415. }
  2416. show_len = 100;
  2417. gtp_irq_enable();
  2418. release_firmware(update_msg.fw);
  2419. update_msg.fw = NULL;
  2420. return SUCCESS;
  2421. download_fail:
  2422. if (dir != NULL) {
  2423. gtp_fw_startup(i2c_client_point);
  2424. #ifdef CONFIG_GTP_ESD_PROTECT
  2425. gtp_esd_switch(i2c_client_point, SWITCH_ON);
  2426. #endif
  2427. #ifdef CONFIG_GTP_CHARGER_DETECT
  2428. gtp_charger_switch(1);
  2429. #endif
  2430. }
  2431. err_fw:
  2432. release_firmware(update_msg.fw);
  2433. update_msg.fw = NULL;
  2434. show_len = 200;
  2435. gtp_irq_enable();
  2436. return FAIL;
  2437. }
  2438. #endif
  2439. static void gup_bit_write(s32 addr, s32 bit, s32 val)
  2440. {
  2441. u8 buf;
  2442. i2c_read_bytes(i2c_client_point, addr, &buf, 1);
  2443. buf = (buf & (~((u8)1 << bit))) | ((u8)val << bit);
  2444. i2c_write_bytes(i2c_client_point, addr, &buf, 1);
  2445. }
  2446. static void gup_clk_count_init(s32 bCh, s32 bCNT)
  2447. {
  2448. u8 buf;
  2449. /* _fRW_MISCTL__MEA_EN = 0; //Frequency measure enable */
  2450. gup_bit_write(_fRW_MISCTL__MEA, 0, 0);
  2451. /* _fRW_MISCTL__MEA_CLR = 1; //Frequency measure clear */
  2452. gup_bit_write(_fRW_MISCTL__MEA, 1, 1);
  2453. /* _bRW_MISCTL__MEA_MODE = 0; //Pulse mode */
  2454. buf = 0;
  2455. i2c_write_bytes(i2c_client_point, _bRW_MISCTL__MEA_MODE, &buf, 1);
  2456. /* _bRW_MISCTL__MEA_SRCSEL = 8 + bCh; //From GIO1 */
  2457. buf = 8 + bCh;
  2458. i2c_write_bytes(i2c_client_point, _bRW_MISCTL__MEA_SRCSEL, &buf, 1);
  2459. /* _wRW_MISCTL__MEA_MAX_NUM = bCNT; //Set the Measure Counts = 1 */
  2460. buf = bCNT;
  2461. i2c_write_bytes(i2c_client_point, _wRW_MISCTL__MEA_MAX_NUM, &buf, 1);
  2462. /* _fRW_MISCTL__MEA_CLR = 0; //Frequency measure not clear */
  2463. gup_bit_write(_fRW_MISCTL__MEA, 1, 0);
  2464. /* _fRW_MISCTL__MEA_EN = 1; */
  2465. gup_bit_write(_fRW_MISCTL__MEA, 0, 1);
  2466. }
  2467. static u32 gup_clk_count_get(void)
  2468. {
  2469. s32 ready = 0;
  2470. s32 temp;
  2471. s8 buf[4];
  2472. while ((ready == 0)) /* Wait for measurement complete */ {
  2473. i2c_read_bytes(i2c_client_point, _bRO_MISCTL__MEA_RDY, buf, 1);
  2474. ready = buf[0];
  2475. }
  2476. udelay(50);
  2477. /* _fRW_MISCTL__MEA_EN = 0; */
  2478. gup_bit_write(_fRW_MISCTL__MEA, 0, 0);
  2479. i2c_read_bytes(i2c_client_point, _dRO_MISCTL__MEA_VAL, buf, 4);
  2480. GTP_INFO("Clk_count 0: %2X", buf[0]);
  2481. GTP_INFO("Clk_count 1: %2X", buf[1]);
  2482. GTP_INFO("Clk_count 2: %2X", buf[2]);
  2483. GTP_INFO("Clk_count 3: %2X", buf[3]);
  2484. temp = (s32)buf[0] + ((s32)buf[1] << 8) + ((s32)buf[2] << 16) +
  2485. ((s32)buf[3] << 24);
  2486. GTP_INFO("Clk_count : %d", temp);
  2487. return temp;
  2488. }
  2489. u8 gup_clk_dac_setting(int dac)
  2490. {
  2491. s8 buf1, buf2;
  2492. i2c_read_bytes(i2c_client_point, _wRW_MISCTL__RG_DMY, &buf1, 1);
  2493. i2c_read_bytes(i2c_client_point, _bRW_MISCTL__RG_OSC_CALIB, &buf2, 1);
  2494. buf1 = (buf1 & 0xFFCF) | ((dac & 0x03) << 4);
  2495. buf2 = (dac >> 2) & 0x3f;
  2496. i2c_write_bytes(i2c_client_point, _wRW_MISCTL__RG_DMY, &buf1, 1);
  2497. i2c_write_bytes(i2c_client_point, _bRW_MISCTL__RG_OSC_CALIB, &buf2, 1);
  2498. return 0;
  2499. }
  2500. static u8 gup_clk_calibration_pin_select(s32 bCh)
  2501. {
  2502. s32 i2c_addr;
  2503. switch (bCh) {
  2504. case 0:
  2505. i2c_addr = _fRW_MISCTL__GIO0;
  2506. break;
  2507. case 1:
  2508. i2c_addr = _fRW_MISCTL__GIO1;
  2509. break;
  2510. case 2:
  2511. i2c_addr = _fRW_MISCTL__GIO2;
  2512. break;
  2513. case 3:
  2514. i2c_addr = _fRW_MISCTL__GIO3;
  2515. break;
  2516. case 4:
  2517. i2c_addr = _fRW_MISCTL__GIO4;
  2518. break;
  2519. case 5:
  2520. i2c_addr = _fRW_MISCTL__GIO5;
  2521. break;
  2522. case 6:
  2523. i2c_addr = _fRW_MISCTL__GIO6;
  2524. break;
  2525. case 7:
  2526. i2c_addr = _fRW_MISCTL__GIO7;
  2527. break;
  2528. case 8:
  2529. i2c_addr = _fRW_MISCTL__GIO8;
  2530. break;
  2531. case 9:
  2532. i2c_addr = _fRW_MISCTL__GIO9;
  2533. break;
  2534. }
  2535. gup_bit_write(i2c_addr, 1, 0);
  2536. return 0;
  2537. }
  2538. void gup_output_pulse(int t)
  2539. {
  2540. unsigned long flags;
  2541. /* s32 i; */
  2542. gtp_gpio_output(GTP_IRQ_GPIO, 0);
  2543. udelay(10);
  2544. local_irq_save(flags);
  2545. gtp_gpio_output(GTP_IRQ_GPIO, 1);
  2546. udelay(50);
  2547. gtp_gpio_output(GTP_IRQ_GPIO, 0);
  2548. udelay(t - 50);
  2549. gtp_gpio_output(GTP_IRQ_GPIO, 1);
  2550. local_irq_restore(flags);
  2551. udelay(20);
  2552. gtp_gpio_output(GTP_IRQ_GPIO, 0);
  2553. }
  2554. static void gup_sys_clk_init(void)
  2555. {
  2556. u8 buf;
  2557. /* _fRW_MISCTL__RG_RXADC_CKMUX = 0; */
  2558. gup_bit_write(_rRW_MISCTL__ANA_RXADC_B0_, 5, 0);
  2559. /* _bRW_MISCTL__RG_LDO_A18_PWD = 0; //DrvMISCTL_A18_PowerON */
  2560. buf = 0;
  2561. i2c_write_bytes(i2c_client_point, _bRW_MISCTL__RG_LDO_A18_PWD, &buf, 1);
  2562. /* _bRW_MISCTL__RG_BG_PWD = 0; //DrvMISCTL_BG_PowerON */
  2563. buf = 0;
  2564. i2c_write_bytes(i2c_client_point, _bRW_MISCTL__RG_BG_PWD, &buf, 1);
  2565. /* _bRW_MISCTL__RG_CLKGEN_PWD = 0; //DrvMISCTL_CLKGEN_PowerON */
  2566. buf = 0;
  2567. i2c_write_bytes(i2c_client_point, _bRW_MISCTL__RG_CLKGEN_PWD, &buf, 1);
  2568. /* _fRW_MISCTL__RG_RXADC_PWD = 0; //DrvMISCTL_RX_ADC_PowerON */
  2569. gup_bit_write(_rRW_MISCTL__ANA_RXADC_B0_, 0, 0);
  2570. /* _fRW_MISCTL__RG_RXADC_REF_PWD = 0; //DrvMISCTL_RX_ADCREF_PowerON */
  2571. gup_bit_write(_rRW_MISCTL__ANA_RXADC_B0_, 1, 0);
  2572. /* gup_clk_dac_setting(60); */
  2573. /* _bRW_MISCTL__OSC_CK_SEL = 1;; */
  2574. buf = 1;
  2575. i2c_write_bytes(i2c_client_point, _bRW_MISCTL__OSC_CK_SEL, &buf, 1);
  2576. }
  2577. u8 gup_clk_calibration(void)
  2578. {
  2579. /* u8 buf; */
  2580. /* u8 trigger; */
  2581. s32 i;
  2582. struct timeval start, end;
  2583. s32 count;
  2584. s32 count_ref;
  2585. s32 sec;
  2586. s32 usec;
  2587. s32 ret = 0;
  2588. /* unsigned long flags; */
  2589. /* buf = 0x0C; // hold ss51 and dsp */
  2590. /* i2c_write_bytes(i2c_client_point, _rRW_MISCTL__SWRST_B0_, &buf, 1);
  2591. */
  2592. ret = gup_hold_ss51_dsp(i2c_client_point);
  2593. if (ret <= 0) {
  2594. GTP_ERROR("[gup clk_calibration]hold ss51 & dsp failed.");
  2595. return FAIL;
  2596. }
  2597. /* _fRW_MISCTL__CLK_BIAS = 0; //disable clock bias */
  2598. gup_bit_write(_rRW_MISCTL_RG_DMY83, 7, 0);
  2599. /* _fRW_MISCTL__GIO1_PU = 0; //set TOUCH INT PIN MODE as input */
  2600. gup_bit_write(_rRW_MISCTL__GIO1CTL_B2_, 0, 0);
  2601. /* _fRW_MISCTL__GIO1_OE = 0; //set TOUCH INT PIN MODE as input */
  2602. gup_bit_write(_rRW_MISCTL__GIO1CTL_B1_, 1, 0);
  2603. /* buf = 0x00; */
  2604. /* i2c_write_bytes(i2c_client_point, _rRW_MISCTL__SWRST_B0_, &buf, 1);
  2605. */
  2606. /* msleep(1000); */
  2607. GTP_INFO("CLK calibration GO");
  2608. gup_sys_clk_init();
  2609. gup_clk_calibration_pin_select(1); /* use GIO1 to do the calibration */
  2610. gtp_gpio_output(GTP_IRQ_GPIO, 0);
  2611. for (i = INIT_CLK_DAC; i < MAX_CLK_DAC; i++) {
  2612. if (tpd_halt) {
  2613. /* if sleeping while calibrating main clock, set it */
  2614. /* default 80 */
  2615. i = 72;
  2616. break;
  2617. }
  2618. GTP_INFO("CLK calibration DAC %d", i);
  2619. gup_clk_dac_setting(i);
  2620. gup_clk_count_init(1, CLK_AVG_TIME);
  2621. #if 0
  2622. gup_output_pulse(PULSE_LENGTH);
  2623. count = gup_clk_count_get();
  2624. if (count > PULSE_LENGTH * 60)/* 60= 60Mhz * 1us */
  2625. break;
  2626. #else
  2627. gtp_gpio_output(GTP_IRQ_GPIO, 0);
  2628. /* local_irq_save(flags); */
  2629. do_gettimeofday(&start);
  2630. gtp_gpio_output(GTP_IRQ_GPIO, 1);
  2631. /* local_irq_restore(flags); */
  2632. msleep(20);
  2633. gtp_gpio_output(GTP_IRQ_GPIO, 0);
  2634. msleep(20);
  2635. /* local_irq_save(flags); */
  2636. do_gettimeofday(&end);
  2637. gtp_gpio_output(GTP_IRQ_GPIO, 1);
  2638. /* local_irq_restore(flags); */
  2639. count = gup_clk_count_get();
  2640. udelay(20);
  2641. gtp_gpio_output(GTP_IRQ_GPIO, 0);
  2642. usec = end.tv_usec - start.tv_usec;
  2643. sec = end.tv_sec - start.tv_sec;
  2644. count_ref = 60 * (usec + sec * MILLION);
  2645. GTP_DEBUG("== time %d, %d, %d", sec, usec, count_ref);
  2646. if (count > count_ref) {
  2647. GTP_DEBUG("== count_diff %d", count - count_ref);
  2648. break;
  2649. }
  2650. #endif
  2651. }
  2652. /* clk_dac = i; */
  2653. /* gtp_reset_guitar(i2c_client_point, 20); */
  2654. #if 0 /* for debug */
  2655. /* -- output clk to GPIO 4 */
  2656. buf = 0x00;
  2657. i2c_write_bytes(i2c_client_point, 0x41FA, &buf, 1);
  2658. buf = 0x00;
  2659. i2c_write_bytes(i2c_client_point, 0x4104, &buf, 1);
  2660. buf = 0x00;
  2661. i2c_write_bytes(i2c_client_point, 0x4105, &buf, 1);
  2662. buf = 0x00;
  2663. i2c_write_bytes(i2c_client_point, 0x4106, &buf, 1);
  2664. buf = 0x01;
  2665. i2c_write_bytes(i2c_client_point, 0x4107, &buf, 1);
  2666. buf = 0x06;
  2667. i2c_write_bytes(i2c_client_point, 0x41F8, &buf, 1);
  2668. buf = 0x02;
  2669. i2c_write_bytes(i2c_client_point, 0x41F9, &buf, 1);
  2670. #endif
  2671. gtp_gpio_input(GTP_IRQ_GPIO);
  2672. return i;
  2673. }
  2674. #endif
  2675. #ifdef CONFIG_GTP_HOTKNOT
  2676. #define BANK_LENGTH (16 * 1024)
  2677. #define CALIBRATION_HEADER_LEN 14
  2678. s32 gup_check_section(const u8 *section, u32 length)
  2679. {
  2680. u32 i = 0;
  2681. u32 section_checksum = 0;
  2682. u16 temp;
  2683. for (i = 0; i < length; i += 2) {
  2684. temp = (section[i] << 8) + section[i + 1];
  2685. section_checksum += temp;
  2686. }
  2687. GTP_DEBUG("section checksum: %4X", section_checksum & 0xFFFF);
  2688. if (section_checksum & 0xFFFF)
  2689. return FAIL;
  2690. return SUCCESS;
  2691. }
  2692. s32 gup_enter_update_mode_noreset(void)
  2693. {
  2694. s32 ret = FAIL;
  2695. /* disable watchdog */
  2696. ret = gup_set_ic_msg(i2c_client_point, _bRW_MISCTL__TMR0_EN, 0x00);
  2697. if (ret <= 0) {
  2698. GTP_ERROR("[enter_update_mode]disable wdt fail.");
  2699. return FAIL;
  2700. }
  2701. /* select addr & hold ss51_dsp */
  2702. ret = gup_hold_ss51_dsp(i2c_client_point);
  2703. if (ret <= 0) {
  2704. GTP_ERROR("[enter_update_mode]hold ss51 & dsp failed.");
  2705. return FAIL;
  2706. }
  2707. /* clear control flag */
  2708. ret = gup_set_ic_msg(i2c_client_point, _rRW_MISCTL__BOOT_CTL_, 0x00);
  2709. if (ret <= 0) {
  2710. GTP_ERROR("[enter_update_mode]clear control flag fail.");
  2711. return FAIL;
  2712. }
  2713. /* set scramble */
  2714. ret = gup_set_ic_msg(i2c_client_point, _rRW_MISCTL__BOOT_OPT_B0_, 0x00);
  2715. if (ret <= 0) {
  2716. GTP_ERROR("[enter_update_mode]set scramble fail.");
  2717. return FAIL;
  2718. }
  2719. /* enable accessing code */
  2720. ret = gup_set_ic_msg(i2c_client_point, _bRW_MISCTL__MEM_CD_EN, 0x01);
  2721. if (ret <= 0) {
  2722. GTP_ERROR("[enter_update_mode]enable accessing code fail.");
  2723. return FAIL;
  2724. }
  2725. return SUCCESS;
  2726. }
  2727. s32 gup_load_by_bank(u8 bank, u8 need_check, const u8 *fw, u32 length)
  2728. {
  2729. s32 ret = FAIL;
  2730. s32 retry = 0;
  2731. GTP_DEBUG("[load_by_bank]begin load [bank:%d,length:%d].", bank,
  2732. length);
  2733. while (retry++ < 5) {
  2734. ret = gup_set_ic_msg(i2c_client_point, _bRW_MISCTL__SRAM_BANK,
  2735. bank);
  2736. if (ret <= 0) {
  2737. GTP_ERROR("[load_by_bank]select bank fail.");
  2738. continue;
  2739. }
  2740. ret = i2c_write_bytes(i2c_client_point, 0xC000, (u8 *)fw,
  2741. length);
  2742. if (ret == -1) {
  2743. GTP_ERROR("[load_by_bank]load bank fail.");
  2744. continue;
  2745. }
  2746. if (need_check) {
  2747. ret = gup_check_and_repair(i2c_client_point, 0xC000,
  2748. (u8 *)fw, length);
  2749. if (ret == FAIL) {
  2750. GTP_ERROR("[load_by_bank]checked bank fail.");
  2751. continue;
  2752. }
  2753. }
  2754. break;
  2755. }
  2756. if (retry < 5)
  2757. return SUCCESS;
  2758. else
  2759. return FAIL;
  2760. }
  2761. s32 gup_load_calibration(const u8 *data, s32 length, u8 need_check)
  2762. {
  2763. s32 ret = -1;
  2764. u8 bank = 0;
  2765. /* disable irq & ESD protect */
  2766. gtp_irq_disable();
  2767. #ifdef CONFIG_GTP_ESD_PROTECT
  2768. gtp_esd_switch(i2c_client_point, SWITCH_OFF);
  2769. #endif
  2770. #ifdef CONFIG_GTP_CHARGER_DETECT
  2771. gtp_charger_switch(0);
  2772. #endif
  2773. ret = gup_enter_update_mode_noreset();
  2774. if (ret == FAIL)
  2775. goto gup_load_calibration_exit;
  2776. GTP_DEBUG("enter update mode success.");
  2777. while (length > 0) {
  2778. u32 len = length > BANK_LENGTH ? BANK_LENGTH : length;
  2779. ret = gup_load_by_bank(bank, need_check,
  2780. &data[bank * BANK_LENGTH], len);
  2781. if (ret == FAIL)
  2782. goto gup_load_calibration_exit;
  2783. GTP_DEBUG("load bank%d length:%d success.", bank, len);
  2784. bank++;
  2785. length -= len;
  2786. }
  2787. ret = gtp_fw_startup(i2c_client_point);
  2788. gup_load_calibration_exit:
  2789. #ifdef CONFIG_GTP_ESD_PROTECT
  2790. gtp_esd_switch(i2c_client_point, SWITCH_ON);
  2791. #endif
  2792. #ifdef CONFIG_GTP_CHARGER_DETECT
  2793. gtp_charger_switch(1);
  2794. #endif
  2795. gtp_irq_enable();
  2796. return ret;
  2797. }
  2798. s32 gup_load_authorization_fw(void)
  2799. {
  2800. s32 ret = -1;
  2801. const u8 *section = NULL;
  2802. u32 length = 0;
  2803. int retry = 20;
  2804. GTP_INFO("[gup load_authorization_fw] Load calibration2.");
  2805. while (gtp_loading_fw && retry--) {
  2806. GTP_DEBUG("%s: Waiting for fw loading finished", __func__);
  2807. ssleep(2);
  2808. }
  2809. GTP_INFO("Request firmware...");
  2810. ret = request_firmware(&update_msg.fw, GT9XX_HN_AUTH_FW_NAME,
  2811. &i2c_client_point->dev);
  2812. if (ret < 0) {
  2813. GTP_ERROR("Request firmware failed - %s (%d)\n",
  2814. GT9XX_HN_AUTH_FW_NAME, ret);
  2815. return FAIL;
  2816. }
  2817. GTP_INFO("Firmware size: %zd", update_msg.fw->size);
  2818. section = update_msg.fw->data;
  2819. length = section[0] * 256 * 256 * 256 + section[1] * 256 * 256 +
  2820. section[2] * 256 + section[3];
  2821. if (length > 32 * 1024 || length < 4 * 1024) {
  2822. GTP_ERROR(
  2823. "[gup load_authorization_fw]calibration2's length is invalid.");
  2824. goto load_calibration2_exit;
  2825. }
  2826. ret = gup_check_section(&section[CALIBRATION_HEADER_LEN], length);
  2827. if (ret == FAIL) {
  2828. GTP_ERROR(
  2829. "[gup load_authorization_fw]calibration2's checksum is error.");
  2830. goto load_calibration2_exit;
  2831. }
  2832. ret = gup_load_calibration(&section[CALIBRATION_HEADER_LEN], length, 1);
  2833. load_calibration2_exit:
  2834. release_firmware(update_msg.fw);
  2835. update_msg.fw = NULL;
  2836. return ret;
  2837. }
  2838. s32 gup_load_hotknot_fw(void)
  2839. {
  2840. s32 ret = -1;
  2841. const u8 *section = NULL;
  2842. u32 length = 0;
  2843. gtp_loading_fw = 1;
  2844. #ifdef CONFIG_GTP_ESD_PROTECT
  2845. gtp_esd_switch(i2c_client_point, SWITCH_OFF);
  2846. #endif
  2847. #ifdef CONFIG_GTP_CHARGER_DETECT
  2848. gtp_charger_switch(0);
  2849. #endif
  2850. GTP_INFO("Load hotknot transfer fw.");
  2851. GTP_INFO("Request firmware...");
  2852. ret = request_firmware(&update_msg.fw, GT9XX_HN_TRANS_FW_NAME,
  2853. &i2c_client_point->dev);
  2854. if (ret < 0) {
  2855. GTP_ERROR("Request firmware failed - %s (%d)\n", GT9XX_FW_NAME,
  2856. ret);
  2857. return FAIL;
  2858. }
  2859. GTP_INFO("Firmware size: %zd", update_msg.fw->size);
  2860. section = update_msg.fw->data;
  2861. length = section[0] * 256 * 256 * 256 + section[1] * 256 * 256 +
  2862. section[2] * 256 + section[3];
  2863. if (length > 32 * 1024 || length < 4 * 1024) {
  2864. GTP_ERROR("length of fw is invalid.");
  2865. goto gup_load_hotknot_fw_exit;
  2866. }
  2867. ret = gup_check_section(&section[CALIBRATION_HEADER_LEN], length);
  2868. if (ret == FAIL) {
  2869. GTP_ERROR("checksum error.");
  2870. goto gup_load_hotknot_fw_exit;
  2871. }
  2872. ret = gup_load_calibration(&section[CALIBRATION_HEADER_LEN], length, 0);
  2873. gup_load_hotknot_fw_exit:
  2874. release_firmware(update_msg.fw);
  2875. update_msg.fw = NULL;
  2876. gtp_loading_fw = 0;
  2877. return ret;
  2878. }
  2879. s32 gup_recovery_touch(void)
  2880. {
  2881. s32 ret = -1;
  2882. const u8 *section = NULL;
  2883. u32 length = 0;
  2884. GTP_INFO("[recovery_calibration0] Recovery calibration0.");
  2885. if (gtp_chip_type == CHIP_TYPE_GT9) {
  2886. gtp_loading_fw = 0;
  2887. gtp_reset_guitar(i2c_client_point, 10);
  2888. return SUCCESS;
  2889. }
  2890. gtp_loading_fw = 1;
  2891. GTP_INFO("Request firmware...");
  2892. ret = request_firmware(&update_msg.fw, GT9XX_FW_NAME,
  2893. &i2c_client_point->dev);
  2894. if (ret < 0) {
  2895. GTP_ERROR("Request firmware failed - %s (%d)\n", GT9XX_FW_NAME,
  2896. ret);
  2897. return FAIL;
  2898. }
  2899. GTP_INFO("Firmware size: %zd", update_msg.fw->size);
  2900. section = update_msg.fw->data;
  2901. if (section[0] == 0x00 && section[1] == 0x90 && section[2] == 0x06 &&
  2902. section[3] == 0x00)
  2903. length = 36 * 1024;
  2904. else
  2905. length = section[0] * 256 * 256 * 256 + section[1] * 256 * 256 +
  2906. section[2] * 256 + section[3];
  2907. if (length > 36 * 1024 || length < 16 * 1024) {
  2908. GTP_ERROR(
  2909. "[recovery_calibration0]calibration0's length is invalid.");
  2910. goto recovery_calibration0_exit;
  2911. }
  2912. ret = gup_check_section(&section[CALIBRATION_HEADER_LEN], length);
  2913. if (ret == FAIL) {
  2914. GTP_ERROR(
  2915. "[recovery_calibration0]calibration0's checksum is error.");
  2916. goto recovery_calibration0_exit;
  2917. }
  2918. GTP_INFO("[recovery_calibration0] Recovery length: %d.", length);
  2919. ret = gup_load_calibration(&section[CALIBRATION_HEADER_LEN], length, 0);
  2920. #ifdef CONFIG_GTP_ESD_PROTECT
  2921. gtp_esd_switch(i2c_client_point, SWITCH_ON);
  2922. #endif
  2923. #ifdef CONFIG_GTP_CHARGER_DETECT
  2924. gtp_charger_switch(1);
  2925. #endif
  2926. recovery_calibration0_exit:
  2927. release_firmware(update_msg.fw);
  2928. update_msg.fw = NULL;
  2929. gtp_loading_fw = 0;
  2930. return ret;
  2931. }
  2932. s32 gup_load_touch_fw(char *filepath)
  2933. {
  2934. s32 ret = -1;
  2935. const u8 *section = NULL;
  2936. u32 length = 0;
  2937. GTP_INFO("[load_calibration0] Load calibration0.");
  2938. GTP_INFO("Request firmware...");
  2939. ret = request_firmware(&update_msg.fw, GT9XX_FW_NAME,
  2940. &i2c_client_point->dev);
  2941. if (ret < 0) {
  2942. GTP_ERROR("Request firmware failed - %s (%d)\n", GT9XX_FW_NAME,
  2943. ret);
  2944. return FAIL;
  2945. }
  2946. GTP_INFO("Firmware size: %zd", update_msg.fw->size);
  2947. section = update_msg.fw->data;
  2948. if (section[0] == 0x00 && section[1] == 0x90 && section[2] == 0x06 &&
  2949. section[3] == 0x00) {
  2950. length = 36 * 1024;
  2951. } else {
  2952. length = section[0] * 256 * 256 * 256 + section[1] * 256 * 256 +
  2953. section[2] * 256 + section[3];
  2954. if (length > 36 * 1024)
  2955. length = 36 * 1024;
  2956. }
  2957. ret = gup_check_section(&section[CALIBRATION_HEADER_LEN], length);
  2958. if (ret == FAIL) {
  2959. GTP_ERROR(
  2960. "[load_calibration0]calibration0's checksum is error.");
  2961. goto load_calibration0_exit;
  2962. }
  2963. GTP_INFO("[load_calibration0]calibration0 length: %d.", length);
  2964. ret = gup_load_calibration(&section[CALIBRATION_HEADER_LEN], length, 1);
  2965. #ifdef CONFIG_GTP_ESD_PROTECT
  2966. gtp_esd_switch(i2c_client_point, SWITCH_ON);
  2967. #endif
  2968. #ifdef CONFIG_GTP_CHARGER_DETECT
  2969. gtp_charger_switch(1);
  2970. #endif
  2971. load_calibration0_exit:
  2972. release_firmware(update_msg.fw);
  2973. update_msg.fw = NULL;
  2974. return ret;
  2975. }
  2976. #endif