pt_loader.c 156 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437
  1. /*
  2. * pt_loader.c
  3. * Parade TrueTouch(TM) Standard Product FW Loader Module.
  4. * For use with Parade touchscreen controllers.
  5. * Supported parts include:
  6. * TMA5XX
  7. * TMA448
  8. * TMA445A
  9. * TT21XXX
  10. * TT31XXX
  11. * TT4XXXX
  12. * TT7XXX
  13. * TC3XXX
  14. *
  15. * Copyright (C) 2015-2020 Parade Technologies
  16. *
  17. * This program is free software; you can redistribute it and/or
  18. * modify it under the terms of the GNU General Public License
  19. * version 2, and only version 2, as published by the
  20. * Free Software Foundation.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. *
  27. * Contact Parade Technologies at www.paradetech.com <[email protected]>
  28. */
  29. #include "pt_regs.h"
  30. #include <linux/firmware.h>
  31. #define PT_LOADER_NAME "pt_loader"
  32. #define PT_AUTO_LOAD_FOR_CORRUPTED_FW 1
  33. #define PT_LOADER_FW_UPGRADE_RETRY_COUNT 3
  34. #define PT_FW_UPGRADE \
  35. (defined(CONFIG_TOUCHSCREEN_PARADE_PLATFORM_FW_UPGRADE) \
  36. || defined(CONFIG_TOUCHSCREEN_PARADE_BINARY_FW_UPGRADE))
  37. #define PT_TTCONFIG_UPGRADE \
  38. (defined(CONFIG_TOUCHSCREEN_PARADE_PLATFORM_TTCONFIG_UPGRADE) \
  39. || defined(CONFIG_TOUCHSCREEN_PARADE_MANUAL_TTCONFIG_UPGRADE))
  40. /* Timeout values in ms. */
  41. #define PT_LDR_REQUEST_EXCLUSIVE_TIMEOUT 3000
  42. #define PT_LDR_SWITCH_TO_APP_MODE_TIMEOUT 300
  43. #define PT_MAX_STATUS_SIZE 32
  44. #define PT_DATA_MAX_ROW_SIZE 256
  45. #define PT_DATA_ROW_SIZE 128
  46. #define PT_ARRAY_ID_OFFSET 0
  47. #define PT_ROW_NUM_OFFSET 1
  48. #define PT_ROW_SIZE_OFFSET 3
  49. #define PT_ROW_DATA_OFFSET 5
  50. #define PT_POST_TT_CFG_CRC_MASK 0x2
  51. static inline struct pt_loader_data *pt_get_loader_data(
  52. struct device *dev);
  53. static struct pt_core_commands *cmd;
  54. #define PIP2_LAUNCH_APP_DELAY 400
  55. struct pip2_file_read {
  56. s8 para_num;
  57. u8 file_handle;
  58. int file_offset;
  59. int file_max_size;
  60. int file_read_size;
  61. int file_print_size;
  62. u8 *file_print_buf;
  63. int file_print_left;
  64. };
  65. #ifdef TTDL_DIAGNOSTICS
  66. struct pip2_file_crc {
  67. s8 para_num;
  68. u8 file_handle;
  69. int file_offset;
  70. int file_max_size;
  71. int file_read_size;
  72. };
  73. #endif
  74. struct pip2_loader_data {
  75. struct device *dev;
  76. struct completion pip2_fw_upgrade_complete; /* mutex for loader */
  77. u8 pip2_file_handle;
  78. };
  79. struct pt_loader_data {
  80. struct device *dev;
  81. struct pt_sysinfo *si;
  82. u8 status_buf[PT_MAX_STATUS_SIZE];
  83. struct completion int_running;
  84. struct completion calibration_complete;
  85. #ifdef CONFIG_TOUCHSCREEN_PARADE_BINARY_FW_UPGRADE
  86. int builtin_bin_fw_status;
  87. bool is_manual_upgrade_enabled;
  88. #endif
  89. struct work_struct fw_and_config_upgrade;
  90. struct work_struct calibration_work;
  91. struct pt_loader_platform_data *loader_pdata;
  92. #ifdef CONFIG_TOUCHSCREEN_PARADE_MANUAL_TTCONFIG_UPGRADE
  93. struct mutex config_lock;
  94. u8 *config_data;
  95. int config_size;
  96. bool config_loading;
  97. #endif
  98. struct pip2_loader_data *pip2_data;
  99. u8 pip2_load_file_no;
  100. bool pip2_load_builtin;
  101. u8 pip2_file_erase_file_no;
  102. struct pip2_file_read pip2_file_data;
  103. #ifdef TTDL_DIAGNOSTICS
  104. struct pip2_file_crc pip2_fcrc;
  105. #endif
  106. #ifdef CONFIG_TOUCHSCREEN_PARADE_BINARY_FW_UPGRADE
  107. struct work_struct bl_from_file;
  108. struct work_struct pip2_bl_from_file;
  109. #endif
  110. };
  111. static u8 update_fw_status;
  112. static int pip2_erase_status;
  113. static int pip2_erase_rc;
  114. /* PIP2 update fw status codes. 1-99% are "active" */
  115. enum UPDATE_FW_STATUS {
  116. UPDATE_FW_IDLE = 0,
  117. UPDATE_FW_ACTIVE_10 = 10,
  118. UPDATE_FW_ACTIVE_90 = 90,
  119. UPDATE_FW_ACTIVE_99 = 99,
  120. UPDATE_FW_COMPLETE = 100,
  121. UPDATE_FW_GENERAL_ERROR = 200,
  122. UPDATE_FW_PIP_VERSION_ERROR = 201,
  123. UPDATE_FW_VERSION_ERROR = 202,
  124. UPDATE_FW_ERASE_ERROR = 203,
  125. UPDATE_FW_FILE_CLOSE_ERROR = 204,
  126. UPDATE_FW_WRITE_ERROR = 205,
  127. UPDATE_FW_EXECUTE_ERROR = 206,
  128. UPDATE_FW_RESET_ERROR = 207,
  129. UPDATE_FW_MODE_ERROR = 208,
  130. UPDATE_FW_ENTER_BL_ERROR = 209,
  131. UPDATE_FW_FILE_OPEN_ERROR = 210,
  132. UPDATE_FW_SENTINEL_NOT_SEEN = 211,
  133. UPDATE_FW_EXCLUSIVE_ACCESS_ERROR = 212,
  134. UPDATE_FW_NO_FW_PROVIDED = 213,
  135. UPDATE_FW_INVALID_FW_IMAGE = 214,
  136. UPDATE_FW_MISALIGN_FW_IMAGE = 230,
  137. UPDATE_FW_SYSTEM_NOMEM = 231,
  138. UPDATE_FW_INIT_BL_ERROR = 232,
  139. UPDATE_FW_PARSE_ROW_ERROR = 233,
  140. UPDATE_FW_PROGRAM_ROW_ERROR = 234,
  141. UPDATE_FW_EXIT_BL_ERROR = 235,
  142. UPDATE_FW_CHECK_SUM_ERROR = 236,
  143. UPDATE_FW_NO_PLATFORM_DATA = 237,
  144. UPDATE_FW_UNDEFINED_ERROR = 255,
  145. };
  146. enum PIP2_FILE_ERASE_STATUS {
  147. PIP2_FILE_ERASE_STATUS_DUT_BUSY = 101,
  148. PIP2_FILE_ERASE_STATUS_ENTER_BL_ERROR = 102,
  149. };
  150. struct pt_dev_id {
  151. u32 silicon_id;
  152. u8 rev_id;
  153. u32 bl_ver;
  154. };
  155. struct pt_hex_image {
  156. u8 array_id;
  157. u16 row_num;
  158. u16 row_size;
  159. u8 row_data[PT_DATA_ROW_SIZE];
  160. } __packed;
  161. #ifdef CONFIG_TOUCHSCREEN_PARADE_BINARY_FW_UPGRADE
  162. static int pt_pip2_upgrade_firmware_from_builtin(struct device *dev);
  163. #endif
  164. typedef int (*PIP2_SEND_CMD)(struct device *, int,
  165. u8, u8 *, u16, u8 *, u16 *);
  166. static struct pt_module loader_module;
  167. /*******************************************************************************
  168. * FUNCTION: pt_get_loader_data
  169. *
  170. * SUMMARY: Inline function to get pt_loader_data pointer from loader module.
  171. *
  172. * RETURN:
  173. * pointer to pt_loader_data structure
  174. *
  175. * PARAMETERS:
  176. * *dev - pointer to device structure
  177. ******************************************************************************/
  178. static inline struct pt_loader_data *pt_get_loader_data(
  179. struct device *dev)
  180. {
  181. return pt_get_module_data(dev, &loader_module);
  182. }
  183. #if PT_FW_UPGRADE || PT_TTCONFIG_UPGRADE
  184. /*******************************************************************************
  185. * FUNCTION: pt_calibrate_idacs
  186. *
  187. * SUMMARY: Calibrate idac for mutual-cap,buttons,self-cap by called functions.
  188. * It needs stop panel scan during calibration.
  189. *
  190. * PARAMETERS:
  191. * *calibration_work - pointer to work_struct structure
  192. ******************************************************************************/
  193. static void pt_calibrate_idacs(struct work_struct *calibration_work)
  194. {
  195. struct pt_loader_data *ld = container_of(calibration_work,
  196. struct pt_loader_data, calibration_work);
  197. struct device *dev = ld->dev;
  198. struct pt_cal_ext_data cal_data = {0};
  199. u8 dut_gen = cmd->request_dut_generation(dev);
  200. u8 mode;
  201. u8 status;
  202. int rc;
  203. pt_debug(dev, DL_INFO, "Entering %s\n", __func__);
  204. rc = cmd->request_exclusive(dev, PT_LDR_REQUEST_EXCLUSIVE_TIMEOUT);
  205. if (rc < 0)
  206. goto exit;
  207. rc = cmd->nonhid_cmd->suspend_scanning(dev, 0);
  208. if (rc < 0)
  209. goto release;
  210. if (dut_gen == DUT_PIP1_ONLY) {
  211. for (mode = 0; mode < 3; mode++) {
  212. rc = cmd->nonhid_cmd->calibrate_idacs(dev, 0, mode,
  213. &status);
  214. if (rc < 0) {
  215. pt_debug(dev, DL_ERROR,
  216. "%s: calibrate idac error, rc = %d\n",
  217. __func__, rc);
  218. break;
  219. }
  220. }
  221. } else {
  222. /*
  223. * Manual calibration is not need after fw 3.4.932110.
  224. * Therefore, PT_LOADER_FLAG_NONE should be used to avoid
  225. * manual calibration if the FW is newer than 3.4.932110.
  226. */
  227. memset(&cal_data, 0, sizeof(struct pt_cal_ext_data));
  228. rc = cmd->nonhid_cmd->calibrate_ext(dev, 0, &cal_data,
  229. &status);
  230. if (rc < 0) {
  231. pt_debug(dev, DL_ERROR,
  232. "%s: extended calibrate error, rc = %d\n",
  233. __func__, rc);
  234. }
  235. }
  236. rc = cmd->nonhid_cmd->resume_scanning(dev, 0);
  237. if (rc < 0)
  238. goto release;
  239. pt_debug(dev, DL_WARN, "%s: Calibration Done\n", __func__);
  240. release:
  241. cmd->release_exclusive(dev);
  242. exit:
  243. complete(&ld->calibration_complete);
  244. }
  245. /*******************************************************************************
  246. * FUNCTION: pt_calibration_attention
  247. *
  248. * SUMMARY: Wrapper function to schedule calibration work used to subscribe into
  249. * TTDL attention list.Once called will unsubscribe from attention list.
  250. *
  251. * RETURN:
  252. * 0 = success
  253. * !0 = failure
  254. *
  255. * PARAMETERS:
  256. * *dev - pointer to device structure
  257. ******************************************************************************/
  258. static int pt_calibration_attention(struct device *dev)
  259. {
  260. struct pt_loader_data *ld = pt_get_loader_data(dev);
  261. int rc = 0;
  262. schedule_work(&ld->calibration_work);
  263. cmd->unsubscribe_attention(dev, PT_ATTEN_STARTUP, PT_LOADER_NAME,
  264. pt_calibration_attention, 0);
  265. return rc;
  266. }
  267. #endif /* PT_FW_UPGRADE || PT_TTCONFIG_UPGRADE */
  268. #if PT_FW_UPGRADE \
  269. || defined(CONFIG_TOUCHSCREEN_PARADE_PLATFORM_TTCONFIG_UPGRADE)
  270. /*******************************************************************************
  271. * FUNCTION: pt_get_panel_id
  272. *
  273. * SUMMARY: Get panel id from core data.
  274. *
  275. * RETURN:
  276. * panel id
  277. *
  278. * PARAMETERS:
  279. * *dev - pointer to device structure
  280. ******************************************************************************/
  281. static u8 pt_get_panel_id(struct device *dev)
  282. {
  283. struct pt_core_data *cd = dev_get_drvdata(dev);
  284. return cd->pid_for_loader;
  285. }
  286. #endif
  287. #if (PT_FW_UPGRADE || PT_TTCONFIG_UPGRADE)
  288. /*******************************************************************************
  289. * FUNCTION: pt_check_firmware_version
  290. *
  291. * SUMMARY: Compare fw's version and revision control number with fw image's.
  292. *
  293. * RETURN:
  294. * -1: Do not upgrade firmware
  295. * 0: Version info same, let caller decide
  296. * 1: Do a firmware upgrade
  297. *
  298. * PARAMETERS:
  299. * *dev - pointer to device structure
  300. * fw_ver_new - firmware version
  301. * fw_revctrl_new - firmware revision control number
  302. ******************************************************************************/
  303. static int pt_check_firmware_version(struct device *dev,
  304. u32 fw_ver_new, u32 fw_revctrl_new)
  305. {
  306. struct pt_loader_data *ld = pt_get_loader_data(dev);
  307. u32 fw_ver_img;
  308. u32 fw_revctrl_img;
  309. fw_ver_img = ld->si->ttdata.fw_ver_major << 8;
  310. fw_ver_img += ld->si->ttdata.fw_ver_minor;
  311. pt_debug(dev, DL_WARN,
  312. "%s: Current FW ver:0x%04X New FW ver:0x%04X\n", __func__,
  313. fw_ver_img, fw_ver_new);
  314. if (fw_ver_new > fw_ver_img) {
  315. pt_debug(dev, DL_WARN,
  316. "%s: Image is newer, will upgrade\n", __func__);
  317. return 1;
  318. }
  319. if (fw_ver_new < fw_ver_img) {
  320. pt_debug(dev, DL_WARN,
  321. "%s: Image is older, will NOT upgrade\n", __func__);
  322. return -EPERM;
  323. }
  324. fw_revctrl_img = ld->si->ttdata.revctrl;
  325. pt_debug(dev, DL_WARN,
  326. "%s: Current FW rev:%d New FW rev:%d\n",
  327. __func__, fw_revctrl_img, fw_revctrl_new);
  328. if (fw_revctrl_new > fw_revctrl_img) {
  329. pt_debug(dev, DL_WARN,
  330. "%s: Image is newer, will upgrade\n", __func__);
  331. return 1;
  332. }
  333. if (fw_revctrl_new < fw_revctrl_img) {
  334. pt_debug(dev, DL_WARN,
  335. "%s: Image is older, will NOT upgrade\n", __func__);
  336. return -EPERM;
  337. }
  338. return 0;
  339. }
  340. #endif /* PT_FW_UPGRADE || PT_TTCONFIG_UPGRADE */
  341. #if PT_FW_UPGRADE
  342. /*******************************************************************************
  343. * FUNCTION: pt_get_row_
  344. *
  345. * SUMMARY: Copy the image data to the "row_buf".
  346. *
  347. * RETURN:
  348. * pointer to image buffer plus copy size
  349. *
  350. * PARAMETERS:
  351. * *dev - pointer to device structure
  352. * *row_buf - pointer to written buffer to program chip
  353. * *image_buf - pointer to image buffer
  354. * size - size of written data
  355. ******************************************************************************/
  356. static u8 *pt_get_row_(struct device *dev, u8 *row_buf,
  357. u8 *image_buf, int size)
  358. {
  359. memcpy(row_buf, image_buf, size);
  360. return image_buf + size;
  361. }
  362. /*******************************************************************************
  363. * FUNCTION: pt_ldr_enter_
  364. *
  365. * SUMMARY: Enter bootloader state and update device id(silicon id, rev id,
  366. * bootloader version).
  367. *
  368. * RETURN:
  369. * 0 = success
  370. * !0 = failure
  371. *
  372. * PARAMETERS:
  373. * *dev - pointer to device structure
  374. * *dev_id - pointer to device id
  375. ******************************************************************************/
  376. static int pt_ldr_enter_(struct device *dev, struct pt_dev_id *dev_id)
  377. {
  378. int rc;
  379. u8 return_data[8];
  380. u8 mode = PT_MODE_OPERATIONAL;
  381. dev_id->silicon_id = 0;
  382. dev_id->rev_id = 0;
  383. dev_id->bl_ver = 0;
  384. /*
  385. * Reset to get to a known state, sleep to allow sentinel processing.
  386. *
  387. * NOTE: This msleep MUST be greater than the auto launch timeout
  388. * that is built into the FW.
  389. */
  390. cmd->request_reset(dev, PT_CORE_CMD_UNPROTECTED);
  391. msleep(20);
  392. rc = cmd->request_get_mode(dev, 0, &mode);
  393. pt_debug(dev, DL_INFO, "%s:request_get_mode rc=%d mode=%d\n",
  394. __func__, rc, mode);
  395. if (rc)
  396. return rc;
  397. if (mode == PT_MODE_UNKNOWN)
  398. return -EINVAL;
  399. if (mode == PT_MODE_OPERATIONAL) {
  400. rc = cmd->nonhid_cmd->start_bl(dev, PT_CORE_CMD_UNPROTECTED);
  401. pt_debug(dev, DL_INFO, "%s:start_bl rc=%d\n", __func__, rc);
  402. if (rc)
  403. return rc;
  404. rc = cmd->request_get_mode(dev, 0, &mode);
  405. pt_debug(dev, DL_INFO, "%s:request_get_mode rc=%d mode=%d\n",
  406. __func__, rc, mode);
  407. if (rc)
  408. return rc;
  409. if (mode != PT_MODE_BOOTLOADER)
  410. return -EINVAL;
  411. }
  412. rc = cmd->nonhid_cmd->get_bl_info(dev,
  413. PT_CORE_CMD_UNPROTECTED, return_data);
  414. pt_debug(dev, DL_INFO, "%s:get_bl_info rc=%d\n", __func__, rc);
  415. if (rc)
  416. return rc;
  417. dev_id->silicon_id = get_unaligned_le32(&return_data[0]);
  418. dev_id->rev_id = return_data[4];
  419. dev_id->bl_ver = return_data[5] + (return_data[6] << 8)
  420. + (return_data[7] << 16);
  421. return 0;
  422. }
  423. /*******************************************************************************
  424. * FUNCTION: pt_ldr_init_
  425. *
  426. * SUMMARY: Erase the entire TrueTouch application, Configuration Data block,
  427. * and Design Data block in flash and enables the host to execute the Program
  428. * and Verify Row command to bootload the application image and data.
  429. *
  430. * RETURN:
  431. * 0 = success
  432. * !0 = failure
  433. *
  434. * PARAMETERS:
  435. * *dev - pointer to device structure
  436. * *pt_hex_image - pointer to hex image structure
  437. ******************************************************************************/
  438. static int pt_ldr_init_(struct device *dev,
  439. struct pt_hex_image *row_image)
  440. {
  441. return cmd->nonhid_cmd->initiate_bl(dev, 0, 8,
  442. (u8 *)pt_data_block_security_key, row_image->row_size,
  443. row_image->row_data);
  444. }
  445. /*******************************************************************************
  446. * FUNCTION: pt_ldr_parse_row_
  447. *
  448. * SUMMARY: Parse and copy the row buffer data to hex image structure.
  449. *
  450. * RETURN:
  451. * 0 = success
  452. * !0 = failure
  453. *
  454. * PARAMETERS:
  455. * *dev - pointer to device structure
  456. * *row_buf - pointer to row buffer
  457. * *row_image - pointer to hex image structure
  458. ******************************************************************************/
  459. static int pt_ldr_parse_row_(struct device *dev, u8 *row_buf,
  460. struct pt_hex_image *row_image)
  461. {
  462. int rc = 0;
  463. row_image->array_id = row_buf[PT_ARRAY_ID_OFFSET];
  464. row_image->row_num = get_unaligned_be16(&row_buf[PT_ROW_NUM_OFFSET]);
  465. row_image->row_size = get_unaligned_be16(&row_buf[PT_ROW_SIZE_OFFSET]);
  466. if (row_image->row_size > ARRAY_SIZE(row_image->row_data)) {
  467. pt_debug(dev, DL_ERROR,
  468. "%s: row data buffer overflow\n", __func__);
  469. rc = -EOVERFLOW;
  470. goto pt_ldr_parse_row_exit;
  471. }
  472. memcpy(row_image->row_data, &row_buf[PT_ROW_DATA_OFFSET],
  473. row_image->row_size);
  474. pt_ldr_parse_row_exit:
  475. return rc;
  476. }
  477. /*******************************************************************************
  478. * FUNCTION: pt_ldr_prog_row_
  479. *
  480. * SUMMARY: Program one row that the hex image structure data to the chip.
  481. *
  482. * RETURN:
  483. * 0 = success
  484. * !0 = failure
  485. *
  486. * PARAMETERS:
  487. * *dev - pointer to device structure
  488. * *row_image - pointer to hex image structure
  489. ******************************************************************************/
  490. static int pt_ldr_prog_row_(struct device *dev,
  491. struct pt_hex_image *row_image)
  492. {
  493. int rc = 0;
  494. u16 length = row_image->row_size + 3;
  495. u8 *data = NULL;
  496. u8 offset = 0;
  497. if (length > PT_DATA_MAX_ROW_SIZE)
  498. return -EINVAL;
  499. data = kzalloc(length, GFP_KERNEL);
  500. if (!data)
  501. return -ENOMEM;
  502. data[offset++] = row_image->array_id;
  503. data[offset++] = LOW_BYTE(row_image->row_num);
  504. data[offset++] = HI_BYTE(row_image->row_num);
  505. memcpy(data + 3, row_image->row_data, row_image->row_size);
  506. rc = cmd->nonhid_cmd->prog_and_verify(dev, 0, length, data);
  507. kfree(data);
  508. return rc;
  509. }
  510. /*******************************************************************************
  511. * FUNCTION: pt_ldr_verify_chksum_
  512. *
  513. * SUMMARY: Perform a full verification of the application integrity by
  514. * calculating the CRC of the TrueTouch application image in flash and
  515. * comparing it to the expected CRC stored in the TrueTouch application CRC
  516. * value stored in the Metadata row.
  517. *
  518. * RETURN:
  519. * 0 = success
  520. * !0 = failure
  521. *
  522. * PARAMETERS:
  523. * *dev - pointer to device structure
  524. ******************************************************************************/
  525. static int pt_ldr_verify_chksum_(struct device *dev)
  526. {
  527. u8 result;
  528. int rc;
  529. rc = cmd->nonhid_cmd->verify_app_integrity(dev, 0, &result);
  530. if (rc)
  531. return rc;
  532. /* fail */
  533. if (result == 0)
  534. return -EINVAL;
  535. return 0;
  536. }
  537. /*******************************************************************************
  538. * FUNCTION: pt_ldr_exit_
  539. *
  540. * SUMMARY: Launch the application from bootloader.
  541. *
  542. * RETURN:
  543. * 0 = success
  544. * !0 = failure
  545. *
  546. * PARAMETERS:
  547. * *dev - pointer to device structure
  548. ******************************************************************************/
  549. static int pt_ldr_exit_(struct device *dev)
  550. {
  551. return cmd->nonhid_cmd->launch_app(dev, 0);
  552. }
  553. #define PT_NO_INC 0
  554. /*******************************************************************************
  555. * FUNCTION: _pt_pip2_update_bl_status
  556. *
  557. * SUMMARY: Update the value in the bl_status global by either setting to a
  558. * specific value or incrementing it ensuring we don't go out of bounds.
  559. *
  560. * PARAMETERS:
  561. * *dev - pointer to device structure
  562. * value - Value to force, if 0 then ignore.
  563. * inc - Value to increment, if 0 then ignore.
  564. ******************************************************************************/
  565. static u8 _pt_pip2_update_bl_status(struct device *dev, u8 value, u8 inc)
  566. {
  567. pt_debug(dev, DL_DEBUG,
  568. "%s: fw_status = %d, request val=%d, request inc=%d\n",
  569. __func__, update_fw_status, value, inc);
  570. /* Reset status if both value and inc are 0 */
  571. if (value == UPDATE_FW_IDLE && inc == 0) {
  572. update_fw_status = value;
  573. pt_debug(dev, DL_WARN, "%s: ATM - Reset BL Status to %d\n",
  574. __func__, value);
  575. return update_fw_status;
  576. }
  577. /* Set to value if valid */
  578. if (value > UPDATE_FW_IDLE && value < UPDATE_FW_UNDEFINED_ERROR) {
  579. if (value <= UPDATE_FW_COMPLETE && value > update_fw_status) {
  580. update_fw_status = value;
  581. } else if (value >= UPDATE_FW_GENERAL_ERROR) {
  582. update_fw_status = value;
  583. pt_debug(dev, DL_WARN,
  584. "%s: BL Status set to error code %d\n",
  585. __func__, value);
  586. }
  587. return update_fw_status;
  588. }
  589. if (inc > 0 && update_fw_status + inc <= UPDATE_FW_COMPLETE)
  590. update_fw_status += inc;
  591. else
  592. pt_debug(dev, DL_ERROR,
  593. "%s: Inc Request out of bounds: status=%d inc=%d\n",
  594. __func__, update_fw_status, inc);
  595. return update_fw_status;
  596. }
  597. /*******************************************************************************
  598. * FUNCTION: pt_load_app_
  599. *
  600. * SUMMARY: Program the firmware image to the chip.
  601. *
  602. * RETURN:
  603. * 0 = success
  604. * !0 = failure
  605. *
  606. * PARAMETERS:
  607. * *dev - pointer to device structure
  608. * *fw - pointer to the firmware
  609. * fw_size - size of firmware
  610. * update_status - store the update status of firmware
  611. ******************************************************************************/
  612. static int pt_load_app_(struct device *dev, const u8 *fw, int fw_size,
  613. u8 *update_status)
  614. {
  615. struct pt_core_data *cd = dev_get_drvdata(dev);
  616. struct pt_dev_id *dev_id;
  617. struct pt_hex_image *row_image;
  618. u8 *row_buf;
  619. size_t image_rec_size;
  620. size_t row_buf_size = PT_DATA_MAX_ROW_SIZE;
  621. int row_count = 0;
  622. u8 *p;
  623. u8 *last_row;
  624. int rc;
  625. int rc_tmp;
  626. int percent_cmplt;
  627. int total_row_count;
  628. if (update_status == NULL) {
  629. rc = -EINVAL;
  630. pt_debug(dev, DL_ERROR,
  631. "%s: update_status is NULL pointer %d\n",
  632. __func__, rc);
  633. return rc;
  634. } else if (*update_status > UPDATE_FW_ACTIVE_10) {
  635. pt_debug(dev, DL_WARN,
  636. "%s: update_status is illegal = %d, fixed to %d\n",
  637. __func__, *update_status, UPDATE_FW_ACTIVE_10);
  638. *update_status = UPDATE_FW_ACTIVE_10;
  639. }
  640. image_rec_size = sizeof(struct pt_hex_image);
  641. if (fw_size % image_rec_size != 0) {
  642. pt_debug(dev, DL_ERROR,
  643. "%s: Firmware image is misaligned\n", __func__);
  644. *update_status = UPDATE_FW_MISALIGN_FW_IMAGE;
  645. rc = -EINVAL;
  646. goto _pt_load_app_error;
  647. }
  648. *update_status += 1;
  649. total_row_count = fw_size / image_rec_size - 1;
  650. pt_debug(dev, DL_INFO, "%s: start load app\n", __func__);
  651. #ifdef TTHE_TUNER_SUPPORT
  652. cmd->request_tthe_print(dev, NULL, 0, "start load app");
  653. #endif
  654. row_buf = kzalloc(row_buf_size, GFP_KERNEL);
  655. row_image = kzalloc(sizeof(struct pt_hex_image), GFP_KERNEL);
  656. dev_id = kzalloc(sizeof(struct pt_dev_id), GFP_KERNEL);
  657. if (!row_buf || !row_image || !dev_id) {
  658. *update_status = UPDATE_FW_SYSTEM_NOMEM;
  659. rc = -ENOMEM;
  660. goto _pt_load_app_exit;
  661. }
  662. *update_status += 1;
  663. cmd->request_stop_wd(dev);
  664. pt_debug(dev, DL_INFO, "%s: Send BL Loader Enter\n", __func__);
  665. #ifdef TTHE_TUNER_SUPPORT
  666. cmd->request_tthe_print(dev, NULL, 0, "Send BL Loader Enter");
  667. #endif
  668. rc = pt_ldr_enter_(dev, dev_id);
  669. if (rc) {
  670. *update_status = UPDATE_FW_ENTER_BL_ERROR;
  671. pt_debug(dev, DL_ERROR, "%s: Error cannot start Loader (ret=%d)\n",
  672. __func__, rc);
  673. goto _pt_load_app_exit;
  674. }
  675. pt_debug(dev, DL_INFO,
  676. "%s: dev: silicon id=%08X rev=%02X bl=%08X\n", __func__,
  677. dev_id->silicon_id, dev_id->rev_id, dev_id->bl_ver);
  678. *update_status += 1;
  679. /*
  680. * since start loader is successful, firmware mode can be assumed
  681. * at bl mode directly. Updating this variable is helpful to detect
  682. * firmware entered application mode.
  683. */
  684. cd->mode = PT_MODE_BOOTLOADER;
  685. /* get last row */
  686. last_row = (u8 *)fw + fw_size - image_rec_size;
  687. pt_get_row_(dev, row_buf, last_row, image_rec_size);
  688. pt_ldr_parse_row_(dev, row_buf, row_image);
  689. /* initialise bootloader */
  690. rc = pt_ldr_init_(dev, row_image);
  691. if (rc) {
  692. *update_status = UPDATE_FW_ERASE_ERROR;
  693. pt_debug(dev, DL_ERROR, "%s: Error cannot init Loader (ret=%d)\n",
  694. __func__, rc);
  695. goto _pt_load_app_exit;
  696. }
  697. *update_status += 5;
  698. pt_debug(dev, DL_INFO,
  699. "%s: Send BL Loader Blocks\n", __func__);
  700. #ifdef TTHE_TUNER_SUPPORT
  701. cmd->request_tthe_print(dev, NULL, 0, "Send BL Loader Blocks");
  702. #endif
  703. p = (u8 *)fw;
  704. while (p < last_row) {
  705. /* Get row */
  706. row_count += 1;
  707. pt_debug(dev, DL_INFO, "%s: read row=%d\n",
  708. __func__, row_count);
  709. memset(row_buf, 0, row_buf_size);
  710. p = pt_get_row_(dev, row_buf, p, image_rec_size);
  711. /* Don't update BL status on every pass */
  712. if (row_count / 8 * 8 == row_count) {
  713. /* Calculate % complete for update_status sysfs */
  714. percent_cmplt = row_count * 100 / total_row_count;
  715. if (percent_cmplt > UPDATE_FW_ACTIVE_99)
  716. percent_cmplt = UPDATE_FW_ACTIVE_99;
  717. *update_status = (percent_cmplt > *update_status) ?
  718. percent_cmplt : *update_status;
  719. #ifdef TTDL_DIAGNOSTICS
  720. pt_debug(dev, DL_INFO,
  721. "Wrote row num %d of total %d\n",
  722. row_count, total_row_count);
  723. #endif
  724. }
  725. /* Parse row */
  726. pt_debug(dev, DL_INFO, "%s: p=%p buf=%p buf[0]=%02X\n",
  727. __func__, p, row_buf, row_buf[0]);
  728. rc = pt_ldr_parse_row_(dev, row_buf, row_image);
  729. pt_debug(dev, DL_INFO,
  730. "%s: array_id=%02X row_num=%04X(%d) row_size=%04X(%d)\n",
  731. __func__, row_image->array_id,
  732. row_image->row_num, row_image->row_num,
  733. row_image->row_size, row_image->row_size);
  734. if (rc) {
  735. *update_status = UPDATE_FW_PARSE_ROW_ERROR;
  736. pt_debug(dev, DL_ERROR,
  737. "%s: Parse Row Error (a=%d r=%d ret=%d\n",
  738. __func__, row_image->array_id,
  739. row_image->row_num, rc);
  740. goto _pt_load_app_exit;
  741. } else {
  742. pt_debug(dev, DL_INFO,
  743. "%s: Parse Row (a=%d r=%d ret=%d\n",
  744. __func__, row_image->array_id,
  745. row_image->row_num, rc);
  746. }
  747. /* program row */
  748. rc = pt_ldr_prog_row_(dev, row_image);
  749. if (rc) {
  750. *update_status = UPDATE_FW_PROGRAM_ROW_ERROR;
  751. pt_debug(dev, DL_ERROR,
  752. "%s: Prog Row Error (array=%d row=%d ret=%d)\n",
  753. __func__, row_image->array_id,
  754. row_image->row_num, rc);
  755. goto _pt_load_app_exit;
  756. }
  757. pt_debug(dev, DL_INFO,
  758. "%s: array=%d row_cnt=%d row_num=%04X\n",
  759. __func__, row_image->array_id, row_count,
  760. row_image->row_num);
  761. }
  762. /* exit loader */
  763. pt_debug(dev, DL_INFO, "%s: Send BL Loader Terminate\n", __func__);
  764. #ifdef TTHE_TUNER_SUPPORT
  765. cmd->request_tthe_print(dev, NULL, 0, "Send BL Loader Terminate");
  766. #endif
  767. rc = pt_ldr_exit_(dev);
  768. if (rc) {
  769. *update_status = UPDATE_FW_EXIT_BL_ERROR;
  770. pt_debug(dev, DL_ERROR, "%s: Error on exit Loader (ret=%d)\n",
  771. __func__, rc);
  772. /* verify app checksum */
  773. rc_tmp = pt_ldr_verify_chksum_(dev);
  774. if (rc_tmp) {
  775. *update_status = UPDATE_FW_CHECK_SUM_ERROR;
  776. pt_debug(dev, DL_ERROR,
  777. "%s: ldr_verify_chksum fail r=%d\n",
  778. __func__, rc_tmp);
  779. } else
  780. pt_debug(dev, DL_INFO,
  781. "%s: APP Checksum Verified\n", __func__);
  782. } else
  783. *update_status = UPDATE_FW_ACTIVE_99;
  784. _pt_load_app_exit:
  785. kfree(row_buf);
  786. kfree(row_image);
  787. kfree(dev_id);
  788. _pt_load_app_error:
  789. return rc;
  790. }
  791. /*******************************************************************************
  792. * FUNCTION: pt_upgrade_firmware
  793. *
  794. * SUMMARY: Program the firmware image and set call back for start up.
  795. *
  796. * RETURN:
  797. * 0 = success
  798. * !0 = failure
  799. *
  800. * PARAMETERS:
  801. * *dev - pointer to device structure
  802. * *fw_img - pointer to the firmware
  803. * fw_size - size of firmware
  804. * *update_status - store the update status of firmware
  805. ******************************************************************************/
  806. static int pt_upgrade_firmware(struct device *dev, const u8 *fw_img,
  807. int fw_size, u8 *update_status)
  808. {
  809. struct pt_loader_data *ld = pt_get_loader_data(dev);
  810. struct pt_core_data *cd = dev_get_drvdata(dev);
  811. int retry = PT_LOADER_FW_UPGRADE_RETRY_COUNT;
  812. bool wait_for_calibration_complete = false;
  813. int rc;
  814. int t;
  815. _pt_pip2_update_bl_status(dev, UPDATE_FW_IDLE, PT_NO_INC);
  816. if (update_status == NULL) {
  817. rc = -EINVAL;
  818. pt_debug(dev, DL_ERROR,
  819. "%s: update_status is NULL pointer %d\n",
  820. __func__, rc);
  821. return rc;
  822. } else if (*update_status > UPDATE_FW_ACTIVE_10) {
  823. pt_debug(dev, DL_WARN,
  824. "%s: update_status is illegal = %d, fixed to %d\n",
  825. __func__, *update_status, UPDATE_FW_ACTIVE_10);
  826. *update_status = UPDATE_FW_ACTIVE_10;
  827. }
  828. /* Ensure no enum task is pending */
  829. pt_debug(dev, DL_WARN, "%s: Cancel enum work thread\n", __func__);
  830. cancel_work_sync(&cd->enum_work);
  831. pm_runtime_get_sync(dev);
  832. *update_status += 1;
  833. rc = cmd->request_exclusive(dev, PT_LDR_REQUEST_EXCLUSIVE_TIMEOUT);
  834. if (rc < 0) {
  835. *update_status = UPDATE_FW_EXCLUSIVE_ACCESS_ERROR;
  836. goto exit;
  837. }
  838. *update_status += 1;
  839. t = *update_status;
  840. while (retry--) {
  841. /* Restore the update_status */
  842. *update_status = t;
  843. rc = pt_load_app_(dev, fw_img, fw_size, update_status);
  844. if (rc < 0)
  845. pt_debug(dev, DL_ERROR,
  846. "%s: Firmware update failed rc=%d, retry:%d\n",
  847. __func__, rc, retry);
  848. else
  849. break;
  850. msleep(20);
  851. }
  852. if (rc < 0) {
  853. pt_debug(dev, DL_ERROR,
  854. "%s: Firmware update failed with error code %d\n",
  855. __func__, rc);
  856. } else if (ld->loader_pdata &&
  857. (ld->loader_pdata->flags
  858. & PT_LOADER_FLAG_CALIBRATE_AFTER_FW_UPGRADE)) {
  859. #if (KERNEL_VERSION(3, 13, 0) <= LINUX_VERSION_CODE)
  860. reinit_completion(&ld->calibration_complete);
  861. #else
  862. INIT_COMPLETION(ld->calibration_complete);
  863. #endif
  864. /* set up call back for startup */
  865. pt_debug(dev, DL_INFO,
  866. "%s: Adding callback for calibration\n", __func__);
  867. rc = cmd->subscribe_attention(dev, PT_ATTEN_STARTUP,
  868. PT_LOADER_NAME, pt_calibration_attention, 0);
  869. if (rc) {
  870. pt_debug(dev, DL_ERROR,
  871. "%s: Failed adding callback for calibration\n",
  872. __func__);
  873. pt_debug(dev, DL_ERROR,
  874. "%s: No calibration will be performed\n",
  875. __func__);
  876. rc = 0;
  877. } else
  878. wait_for_calibration_complete = true;
  879. }
  880. cmd->release_exclusive(dev);
  881. exit:
  882. if (!rc) {
  883. cmd->request_enum(dev, true);
  884. /*
  885. * Wait for FW reset sentinel from reset or execute for up
  886. * to 500ms
  887. */
  888. t = wait_event_timeout(cd->wait_q,
  889. (cd->startup_status >=
  890. STARTUP_STATUS_FW_RESET_SENTINEL) &&
  891. (cd->mode == PT_MODE_OPERATIONAL),
  892. msecs_to_jiffies(PT_BL_WAIT_FOR_SENTINEL));
  893. if (IS_TMO(t)) {
  894. pt_debug(dev, DL_WARN,
  895. "%s: 0x%04X Timeout waiting for FW sentinel",
  896. __func__, cd->startup_status);
  897. }
  898. /* Double verify DUT is alive and well in Application mode */
  899. if (!(cd->startup_status & STARTUP_STATUS_FW_RESET_SENTINEL)) {
  900. pt_debug(dev, DL_ERROR,
  901. "%s FW sentinel not seen\n", __func__);
  902. *update_status = UPDATE_FW_SENTINEL_NOT_SEEN;
  903. } else if (cd->mode != PT_MODE_OPERATIONAL) {
  904. *update_status = UPDATE_FW_MODE_ERROR;
  905. pt_debug(dev, DL_ERROR,
  906. "%s ERROR: Not in App mode as expected\n",
  907. __func__);
  908. } else {
  909. *update_status = UPDATE_FW_COMPLETE;
  910. pt_debug(dev, DL_INFO,
  911. "%s == PIP1 FW upgrade finished ==\n",
  912. __func__);
  913. }
  914. } else if (*update_status < UPDATE_FW_COMPLETE) {
  915. *update_status = UPDATE_FW_UNDEFINED_ERROR;
  916. pt_debug(dev, DL_ERROR, "%s undefined error!\n", __func__);
  917. }
  918. pm_runtime_put_sync(dev);
  919. if (wait_for_calibration_complete)
  920. wait_for_completion(&ld->calibration_complete);
  921. return rc;
  922. }
  923. #endif /* PT_FW_UPGRADE */
  924. #ifdef CONFIG_TOUCHSCREEN_PARADE_PLATFORM_FW_UPGRADE
  925. /*******************************************************************************
  926. * FUNCTION: pt_check_firmware_version_platform
  927. *
  928. * SUMMARY: The caller of function pt_check_firmware_version() to determine
  929. * whether to load firmware from touch_firmware structure.
  930. *
  931. * RETURN:
  932. * 0: Don't upgrade
  933. * 1: Upgrade
  934. *
  935. * PARAMETERS:
  936. * *dev - pointer to device structure
  937. * *fw - pointer to the touch_firmware structure
  938. ******************************************************************************/
  939. static int pt_check_firmware_version_platform(struct device *dev,
  940. struct pt_touch_firmware *fw)
  941. {
  942. struct pt_loader_data *ld = pt_get_loader_data(dev);
  943. u32 fw_ver_new;
  944. u32 fw_revctrl_new;
  945. int upgrade;
  946. if (!ld->si) {
  947. pt_debug(dev, DL_WARN,
  948. "%s: No firmware info found, DUT FW may be corrupted\n",
  949. __func__);
  950. return PT_AUTO_LOAD_FOR_CORRUPTED_FW;
  951. }
  952. fw_ver_new = get_unaligned_be16(fw->ver + 2);
  953. /* 4 middle bytes are not used */
  954. fw_revctrl_new = get_unaligned_be32(fw->ver + 8);
  955. pt_debug(dev, DL_WARN, "%s: Built-in FW version 0x%04x rev %d\n",
  956. __func__, fw_ver_new, fw_revctrl_new);
  957. upgrade = pt_check_firmware_version(dev, fw_ver_new,
  958. fw_revctrl_new);
  959. if (upgrade > 0)
  960. return 1;
  961. return 0;
  962. }
  963. /*******************************************************************************
  964. * FUNCTION: pt_get_platform_firmware
  965. *
  966. * SUMMARY: To get the pointer of right touch_firmware structure by panel id.
  967. *
  968. * RETURN:
  969. * pointer to touch_firmware structure or null pointer if fail
  970. *
  971. * PARAMETERS:
  972. * *dev - pointer to device structure
  973. ******************************************************************************/
  974. static struct pt_touch_firmware *pt_get_platform_firmware(
  975. struct device *dev)
  976. {
  977. struct pt_loader_data *ld = pt_get_loader_data(dev);
  978. struct pt_touch_firmware **fws;
  979. struct pt_touch_firmware *fw;
  980. u8 panel_id;
  981. panel_id = pt_get_panel_id(dev);
  982. if (panel_id == PANEL_ID_NOT_ENABLED) {
  983. pt_debug(dev, DL_WARN,
  984. "%s: Panel ID not enabled, using legacy firmware\n",
  985. __func__);
  986. return ld->loader_pdata->fw;
  987. }
  988. fws = ld->loader_pdata->fws;
  989. if (!fws) {
  990. pt_debug(dev, DL_ERROR,
  991. "%s: No firmwares provided\n", __func__);
  992. return NULL;
  993. }
  994. /* Find FW according to the Panel ID */
  995. while ((fw = *fws++)) {
  996. if (fw->panel_id == panel_id) {
  997. pt_debug(dev, DL_WARN,
  998. "%s: Found matching fw:%p with Panel ID: 0x%02X\n",
  999. __func__, fw, fw->panel_id);
  1000. return fw;
  1001. }
  1002. pt_debug(dev, DL_WARN,
  1003. "%s: Found mismatching fw:%p with Panel ID: 0x%02X\n",
  1004. __func__, fw, fw->panel_id);
  1005. }
  1006. return NULL;
  1007. }
  1008. /*******************************************************************************
  1009. * FUNCTION: upgrade_firmware_from_platform
  1010. *
  1011. * SUMMARY: Get touch_firmware structure and perform upgrade if pass the
  1012. * firmware version check.
  1013. *
  1014. * RETURN:
  1015. * 0 = success
  1016. * !0 = failure
  1017. *
  1018. * PARAMETERS:
  1019. * *dev - pointer to device structure
  1020. * forced - flag to force upgrade(1:force to upgrade)
  1021. ******************************************************************************/
  1022. static int upgrade_firmware_from_platform(struct device *dev,
  1023. bool forced)
  1024. {
  1025. struct pt_loader_data *ld = pt_get_loader_data(dev);
  1026. struct pt_core_data *cd = dev_get_drvdata(dev);
  1027. struct pt_touch_firmware *fw;
  1028. int rc = -ENODEV;
  1029. int upgrade;
  1030. int retry = 3;
  1031. retry_bl:
  1032. if (!ld->loader_pdata) {
  1033. _pt_pip2_update_bl_status(dev, UPDATE_FW_NO_PLATFORM_DATA,
  1034. PT_NO_INC);
  1035. pt_debug(dev, DL_ERROR,
  1036. "%s: No loader platform data\n", __func__);
  1037. return rc;
  1038. }
  1039. fw = pt_get_platform_firmware(dev);
  1040. if (!fw || !fw->img || !fw->size) {
  1041. _pt_pip2_update_bl_status(dev, UPDATE_FW_NO_FW_PROVIDED,
  1042. PT_NO_INC);
  1043. pt_debug(dev, DL_ERROR,
  1044. "%s: No platform firmware\n", __func__);
  1045. return rc;
  1046. }
  1047. if (!fw->ver || !fw->vsize) {
  1048. _pt_pip2_update_bl_status(dev, UPDATE_FW_INVALID_FW_IMAGE,
  1049. PT_NO_INC);
  1050. pt_debug(dev, DL_ERROR, "%s: No platform firmware version\n",
  1051. __func__);
  1052. return rc;
  1053. }
  1054. if (forced)
  1055. upgrade = forced;
  1056. else
  1057. upgrade = pt_check_firmware_version_platform(dev, fw);
  1058. if (upgrade) {
  1059. rc = pt_upgrade_firmware(dev,
  1060. fw->img, fw->size, &update_fw_status);
  1061. /* An extra BL may be needed if default PID was wrong choice */
  1062. if ((cd->panel_id_support & PT_PANEL_ID_BY_SYS_INFO) &&
  1063. !rc && !ld->si && retry--) {
  1064. pt_debug(dev, DL_WARN, "%s: ATM - An extra BL may be needed\n",
  1065. __func__);
  1066. /* Panel_ID coming from sysinfo, ensure we have it */
  1067. ld->si = cmd->request_sysinfo(dev);
  1068. goto retry_bl;
  1069. }
  1070. }
  1071. return rc;
  1072. }
  1073. #endif /* CONFIG_TOUCHSCREEN_PARADE_PLATFORM_FW_UPGRADE */
  1074. #ifdef CONFIG_TOUCHSCREEN_PARADE_BINARY_FW_UPGRADE
  1075. /*******************************************************************************
  1076. * FUNCTION: _pt_pip1_bl_from_file
  1077. *
  1078. * SUMMARY: Wrapper function for _pt_firmware_cont() to perform bl with an
  1079. * image file from userspace.
  1080. *
  1081. * PARAMETERS:
  1082. * *fw - pointer to firmware structure
  1083. * forced - flag to force upgrade(1:force to upgrade)
  1084. ******************************************************************************/
  1085. static int _pt_pip1_bl_from_file(struct device *dev)
  1086. {
  1087. struct pt_core_data *cd = dev_get_drvdata(dev);
  1088. int fw_size = 0;
  1089. int rc = 0;
  1090. u8 *fw_img = NULL;
  1091. u8 header_size = 0;
  1092. _pt_pip2_update_bl_status(dev, UPDATE_FW_IDLE, PT_NO_INC);
  1093. fw_img = kzalloc(PT_PIP2_MAX_FILE_SIZE, GFP_KERNEL);
  1094. if (!fw_img) {
  1095. _pt_pip2_update_bl_status(dev, UPDATE_FW_SYSTEM_NOMEM,
  1096. PT_NO_INC);
  1097. rc = -ENOMEM;
  1098. goto exit;
  1099. }
  1100. rc = cmd->nonhid_cmd->read_us_file(dev, cd->pip2_us_file_path,
  1101. fw_img, &fw_size);
  1102. if (rc) {
  1103. pt_debug(dev, DL_ERROR, "%s: No firmware provided to load\n",
  1104. __func__);
  1105. _pt_pip2_update_bl_status(dev, UPDATE_FW_NO_FW_PROVIDED,
  1106. PT_NO_INC);
  1107. goto exit;
  1108. }
  1109. if (!fw_img || !fw_size) {
  1110. pt_debug(dev, DL_ERROR,
  1111. "%s: No firmware received\n", __func__);
  1112. _pt_pip2_update_bl_status(dev, UPDATE_FW_INVALID_FW_IMAGE,
  1113. PT_NO_INC);
  1114. goto exit;
  1115. }
  1116. header_size = fw_img[0];
  1117. if (header_size >= (fw_size + 1)) {
  1118. pt_debug(dev, DL_ERROR,
  1119. "%s: Firmware format is invalid\n", __func__);
  1120. _pt_pip2_update_bl_status(dev, UPDATE_FW_INVALID_FW_IMAGE,
  1121. PT_NO_INC);
  1122. goto exit;
  1123. }
  1124. pt_upgrade_firmware(dev, &(fw_img[header_size + 1]),
  1125. fw_size - (header_size + 1), &update_fw_status);
  1126. exit:
  1127. kfree(fw_img);
  1128. return rc;
  1129. }
  1130. /*******************************************************************************
  1131. * FUNCTION: _pt_firmware_cont
  1132. *
  1133. * SUMMARY: Firmware upgrade continue function that verifies the firmware size
  1134. * in the firmware class and then upgrades the firmware.
  1135. *
  1136. * PARAMETERS:
  1137. * *fw - pointer to firmware structure
  1138. * forced - flag to force upgrade(1:force to upgrade)
  1139. ******************************************************************************/
  1140. static void _pt_firmware_cont(const struct firmware *fw, void *context)
  1141. {
  1142. struct device *dev = context;
  1143. struct pt_loader_data *ld = pt_get_loader_data(dev);
  1144. u8 header_size = 0;
  1145. _pt_pip2_update_bl_status(dev, UPDATE_FW_IDLE, PT_NO_INC);
  1146. if (!fw) {
  1147. pt_debug(dev, DL_ERROR, "%s: No firmware\n", __func__);
  1148. _pt_pip2_update_bl_status(dev, UPDATE_FW_NO_FW_PROVIDED,
  1149. PT_NO_INC);
  1150. goto pt_firmware_cont_exit;
  1151. }
  1152. if (!fw->data || !fw->size) {
  1153. pt_debug(dev, DL_ERROR,
  1154. "%s: No firmware received\n", __func__);
  1155. _pt_pip2_update_bl_status(dev, UPDATE_FW_INVALID_FW_IMAGE,
  1156. PT_NO_INC);
  1157. goto pt_firmware_cont_release_exit;
  1158. }
  1159. header_size = fw->data[0];
  1160. if (header_size >= (fw->size + 1)) {
  1161. pt_debug(dev, DL_ERROR,
  1162. "%s: Firmware format is invalid\n", __func__);
  1163. _pt_pip2_update_bl_status(dev, UPDATE_FW_INVALID_FW_IMAGE,
  1164. PT_NO_INC);
  1165. goto pt_firmware_cont_release_exit;
  1166. }
  1167. pt_upgrade_firmware(dev, &(fw->data[header_size + 1]),
  1168. fw->size - (header_size + 1), &update_fw_status);
  1169. pt_firmware_cont_release_exit:
  1170. if (fw)
  1171. release_firmware(fw);
  1172. pt_firmware_cont_exit:
  1173. ld->is_manual_upgrade_enabled = 0;
  1174. }
  1175. /*******************************************************************************
  1176. * FUNCTION: pt_check_firmware_config_version
  1177. *
  1178. * SUMMARY: Compare fw's config version with fw image's. If they are differnt
  1179. * report a FW upgrade is needed.
  1180. *
  1181. * RETURN:
  1182. * -1: Do not upgrade firmware
  1183. * 0: Version info same, let caller decide
  1184. * 1: Do a firmware upgrade
  1185. *
  1186. * PARAMETERS:
  1187. * *dev - pointer to device structure
  1188. * image_config_ver - Image's firmware config version
  1189. ******************************************************************************/
  1190. static int pt_check_firmware_config_version(struct device *dev,
  1191. u16 image_config_ver)
  1192. {
  1193. struct pt_loader_data *ld = pt_get_loader_data(dev);
  1194. u16 fw_config_ver;
  1195. fw_config_ver = ld->si->ttdata.fw_ver_conf;
  1196. pt_debug(dev, DL_WARN,
  1197. "%s: Current config ver:0x%04X New config ver:0x%04X\n",
  1198. __func__, fw_config_ver, image_config_ver);
  1199. if (image_config_ver != fw_config_ver) {
  1200. pt_debug(dev, DL_WARN,
  1201. "%s: Image config ver is different, will upgrade\n",
  1202. __func__);
  1203. return 1;
  1204. }
  1205. if (image_config_ver == fw_config_ver) {
  1206. pt_debug(dev, DL_WARN,
  1207. "%s: Image config ver is the same, will NOT upgrade\n",
  1208. __func__);
  1209. return 0;
  1210. }
  1211. return -EPERM;
  1212. }
  1213. /*******************************************************************************
  1214. * FUNCTION: pt_check_firmware_version_builtin
  1215. *
  1216. * SUMMARY: The caller of function pt_check_firmware_version() to determine
  1217. * whether to load built-in firmware.
  1218. *
  1219. * RETURN:
  1220. * 0: Don't upgrade
  1221. * 1: Upgrade
  1222. *
  1223. * PARAMETERS:
  1224. * *dev - pointer to device structure
  1225. * *fw - pointer to the firmware structure
  1226. ******************************************************************************/
  1227. static int pt_check_firmware_version_builtin(struct device *dev,
  1228. const struct firmware *fw)
  1229. {
  1230. struct pt_loader_data *ld = pt_get_loader_data(dev);
  1231. u16 fw_config_ver_new;
  1232. u32 fw_ver_new;
  1233. u32 fw_revctrl_new;
  1234. int upgrade;
  1235. if (!ld->si) {
  1236. pt_debug(dev, DL_WARN,
  1237. "%s: No firmware info found, DUT FW may be corrupted\n",
  1238. __func__);
  1239. return PT_AUTO_LOAD_FOR_CORRUPTED_FW;
  1240. }
  1241. fw_ver_new = get_unaligned_be16(fw->data + 3);
  1242. /* 4 middle bytes are not used */
  1243. fw_revctrl_new = get_unaligned_be32(fw->data + 9);
  1244. /* Offset 17,18 is the TT Config version*/
  1245. fw_config_ver_new = get_unaligned_be16(fw->data + 17);
  1246. pt_debug(dev, DL_WARN,
  1247. "%s: Built-in FW version=0x%04x rev=%d config=0x%04X\n",
  1248. __func__, fw_ver_new, fw_revctrl_new, fw_config_ver_new);
  1249. upgrade = pt_check_firmware_version(dev, fw_ver_new,
  1250. fw_revctrl_new);
  1251. /* Only check config version if FW version was an exact match */
  1252. if (upgrade == 0)
  1253. upgrade = pt_check_firmware_config_version(dev,
  1254. fw_config_ver_new);
  1255. if (upgrade > 0)
  1256. return 1;
  1257. return 0;
  1258. }
  1259. /*******************************************************************************
  1260. * FUNCTION: _pt_firmware_cont_builtin
  1261. *
  1262. * SUMMARY: Perform upgrade if pass the firmware version check.
  1263. *
  1264. * PARAMETERS:
  1265. * *dev - pointer to device structure
  1266. * forced - flag to force upgrade(1:force to upgrade)
  1267. ******************************************************************************/
  1268. static void _pt_firmware_cont_builtin(const struct firmware *fw,
  1269. void *context)
  1270. {
  1271. struct device *dev = context;
  1272. struct pt_loader_data *ld = pt_get_loader_data(dev);
  1273. int upgrade;
  1274. if (!fw) {
  1275. pt_debug(dev, DL_INFO,
  1276. "%s: No builtin firmware\n", __func__);
  1277. goto _pt_firmware_cont_builtin_exit;
  1278. }
  1279. if (!fw->data || !fw->size) {
  1280. pt_debug(dev, DL_ERROR,
  1281. "%s: Invalid builtin firmware\n", __func__);
  1282. goto _pt_firmware_cont_builtin_exit;
  1283. }
  1284. pt_debug(dev, DL_WARN, "%s: Found firmware\n", __func__);
  1285. upgrade = pt_check_firmware_version_builtin(dev, fw);
  1286. if (upgrade) {
  1287. _pt_firmware_cont(fw, dev);
  1288. ld->builtin_bin_fw_status = 0;
  1289. return;
  1290. }
  1291. _pt_firmware_cont_builtin_exit:
  1292. if (fw)
  1293. release_firmware(fw);
  1294. ld->builtin_bin_fw_status = -EINVAL;
  1295. }
  1296. /*******************************************************************************
  1297. * FUNCTION: upgrade_firmware_from_class
  1298. *
  1299. * SUMMARY: Create the firmware class but don't actually load any FW to the
  1300. * DUT. This creates all the sysfs nodes needed for a user to bootload
  1301. * the DUT with their own bin file.
  1302. *
  1303. * RETURN:
  1304. * 0 = success
  1305. *
  1306. * PARAMETERS:
  1307. * *dev - pointer to device structure
  1308. ******************************************************************************/
  1309. static int upgrade_firmware_from_class(struct device *dev)
  1310. {
  1311. int retval;
  1312. pt_debug(dev, DL_INFO,
  1313. "%s: Enabling firmware class loader\n", __func__);
  1314. retval = request_firmware_nowait(THIS_MODULE, FW_ACTION_NOHOTPLUG,
  1315. dev_name(dev), dev, GFP_KERNEL, dev,
  1316. _pt_firmware_cont);
  1317. if (retval < 0) {
  1318. pt_debug(dev, DL_ERROR,
  1319. "%s: Fail request firmware class file load\n",
  1320. __func__);
  1321. return retval;
  1322. }
  1323. return 0;
  1324. }
  1325. #define FILENAME_LEN_MAX 64
  1326. /*******************************************************************************
  1327. * FUNCTION: generate_firmware_filename
  1328. *
  1329. * SUMMARY: Generate firmware file name by panel id. Generates binary FW
  1330. * filename as following:
  1331. * - Panel ID not enabled: tt_fw.bin
  1332. * - Panel ID enabled: tt_fw_pidXX.bin
  1333. *
  1334. * RETURN:
  1335. * pointer to file name or null pointer if fail
  1336. *
  1337. * PARAMETERS:
  1338. * *dev - pointer to device structure
  1339. ******************************************************************************/
  1340. static char *generate_firmware_filename(struct device *dev)
  1341. {
  1342. char *filename;
  1343. u8 panel_id;
  1344. filename = kzalloc(FILENAME_LEN_MAX, GFP_KERNEL);
  1345. if (!filename)
  1346. return NULL;
  1347. panel_id = pt_get_panel_id(dev);
  1348. if (panel_id == PANEL_ID_NOT_ENABLED)
  1349. snprintf(filename, FILENAME_LEN_MAX, "%s", PT_FW_FILE_NAME);
  1350. else
  1351. snprintf(filename, FILENAME_LEN_MAX, "%s_pid%02X%s",
  1352. PT_FW_FILE_PREFIX, panel_id, PT_FW_FILE_SUFFIX);
  1353. pt_debug(dev, DL_INFO, "%s: Filename: %s\n",
  1354. __func__, filename);
  1355. return filename;
  1356. }
  1357. /*******************************************************************************
  1358. * FUNCTION: generate_silicon_id_firmware_filename
  1359. *
  1360. * SUMMARY: Generate firmware file name with the HW version prefix followed by
  1361. * panel id. Generates binary FW filename as following (where XXXX is the
  1362. * silicon ID):
  1363. * - Panel ID not enabled: XXXX_tt_fw.bin
  1364. * - Panel ID enabled: XXXX_tt_fw_pidXX.bin
  1365. *
  1366. * RETURN:
  1367. * pointer to file name or null pointer if fail
  1368. *
  1369. * PARAMETERS:
  1370. * *dev - pointer to device structure
  1371. ******************************************************************************/
  1372. static char *generate_silicon_id_firmware_filename(struct device *dev)
  1373. {
  1374. struct pt_core_data *cd = dev_get_drvdata(dev);
  1375. char *filename;
  1376. char si_id[5] = "DEAD";
  1377. u8 panel_id;
  1378. filename = kzalloc(FILENAME_LEN_MAX, GFP_KERNEL);
  1379. if (!filename)
  1380. return NULL;
  1381. panel_id = pt_get_panel_id(dev);
  1382. memcpy(si_id, cd->hw_version, 4);
  1383. if (panel_id == PANEL_ID_NOT_ENABLED)
  1384. snprintf(filename, FILENAME_LEN_MAX, "%s_%s", si_id,
  1385. PT_FW_FILE_NAME);
  1386. else
  1387. snprintf(filename, FILENAME_LEN_MAX, "%s_%s_pid%02X%s",
  1388. si_id, PT_FW_FILE_PREFIX, panel_id, PT_FW_FILE_SUFFIX);
  1389. pt_debug(dev, DL_INFO, "%s: Filename: %s\n", __func__, filename);
  1390. return filename;
  1391. }
  1392. #define MAX_FILE_NAMES 2
  1393. /*******************************************************************************
  1394. * FUNCTION: upgrade_firmware_from_builtin
  1395. *
  1396. * SUMMARY: Create the firmware class load FW by searching the name of built-in
  1397. * file. Then perform upgrade after getting the file.
  1398. *
  1399. * RETURN:
  1400. * 0 = success
  1401. * !0 = failure
  1402. *
  1403. * PARAMETERS:
  1404. * *dev - pointer to device structure
  1405. ******************************************************************************/
  1406. static int upgrade_firmware_from_builtin(struct device *dev)
  1407. {
  1408. struct pt_loader_data *ld = pt_get_loader_data(dev);
  1409. struct pt_core_data *cd = dev_get_drvdata(dev);
  1410. char *filename[MAX_FILE_NAMES];
  1411. int index = 0;
  1412. int retval;
  1413. const struct firmware *fw_entry = NULL;
  1414. int retry = 3;
  1415. retry_bl:
  1416. pt_debug(dev, DL_WARN,
  1417. "%s: Enabling firmware class loader built-in\n",
  1418. __func__);
  1419. /* Load the supported file names in the search order */
  1420. /* 0 = Flash file name with optional PID "pt_fw<_PIDX>.bin" */
  1421. filename[0] = generate_firmware_filename(dev);
  1422. if (!filename[0]) {
  1423. pt_debug(dev, DL_ERROR,
  1424. "%s: ERROR - Could not generate filename\n", __func__);
  1425. return -ENOMEM;
  1426. }
  1427. /*
  1428. * 1 = Flash file name with Silicon ID prefix and optional PID
  1429. * "XXXX_pt_fw<_PIDX>.bin"
  1430. */
  1431. filename[1] = generate_silicon_id_firmware_filename(dev);
  1432. if (!filename[1]) {
  1433. pt_debug(dev, DL_ERROR,
  1434. "%s: ERROR - Could not generate filename\n", __func__);
  1435. return -ENOMEM;
  1436. }
  1437. mutex_lock(&cd->firmware_class_lock);
  1438. while (index < MAX_FILE_NAMES) {
  1439. pt_debug(dev, DL_WARN, "%s: Request FW file %s\n", __func__,
  1440. filename[index]);
  1441. #if (KERNEL_VERSION(3, 13, 0) > LINUX_VERSION_CODE)
  1442. retval = request_firmware(&fw_entry, filename[index], dev);
  1443. #else
  1444. retval = request_firmware_direct(&fw_entry,
  1445. filename[index], dev);
  1446. #endif
  1447. if (retval < 0) {
  1448. pt_debug(dev, DL_WARN, "%s: Fail request FW %s load\n",
  1449. __func__, filename[index]);
  1450. } else {
  1451. pt_debug(dev, DL_WARN, "%s: FW %s class file loading\n",
  1452. __func__, filename[index]);
  1453. break;
  1454. }
  1455. index++;
  1456. }
  1457. /* Proceed with the BL if a matching file was found */
  1458. if (index != MAX_FILE_NAMES) {
  1459. _pt_firmware_cont_builtin(fw_entry, dev);
  1460. /* An extra BL may be needed if default PID was wrong choice */
  1461. if ((cd->panel_id_support & PT_PANEL_ID_BY_SYS_INFO) &&
  1462. !ld->si && retry--) {
  1463. pt_debug(dev, DL_WARN, "%s: ATM - An extra BL may be needed\n",
  1464. __func__);
  1465. /* Free allocated memory */
  1466. index = 0;
  1467. while (index < MAX_FILE_NAMES)
  1468. kfree(filename[index++]);
  1469. /* Reset index to 0 */
  1470. index = 0;
  1471. mutex_unlock(&cd->firmware_class_lock);
  1472. /* Panel_ID coming from sysinfo, ensure we have it */
  1473. ld->si = cmd->request_sysinfo(dev);
  1474. goto retry_bl;
  1475. }
  1476. retval = ld->builtin_bin_fw_status;
  1477. }
  1478. index = 0;
  1479. while (index < MAX_FILE_NAMES)
  1480. kfree(filename[index++]);
  1481. mutex_unlock(&cd->firmware_class_lock);
  1482. return retval;
  1483. }
  1484. #endif /* CONFIG_TOUCHSCREEN_PARADE_BINARY_FW_UPGRADE */
  1485. #if PT_TTCONFIG_UPGRADE
  1486. /*******************************************************************************
  1487. * FUNCTION: pt_write_config_row_
  1488. *
  1489. * SUMMARY: Allow to program the data block area that includes configuration
  1490. * data, manufacturing data, design data.
  1491. *
  1492. * RETURN:
  1493. * 0 = success
  1494. * !0 = failure
  1495. *
  1496. * PARAMETERS:
  1497. * *dev - pointer to device structure
  1498. * ebid - block id to determine the block name(configuration,etc)
  1499. * row_number - row number if written block
  1500. * row_size - row size of written data
  1501. * *data - pointer to the data to write
  1502. ******************************************************************************/
  1503. static int pt_write_config_row_(struct device *dev, u8 ebid,
  1504. u16 row_number, u16 row_size, u8 *data)
  1505. {
  1506. int rc;
  1507. u16 actual_write_len;
  1508. rc = cmd->nonhid_cmd->write_data_block(dev, row_number,
  1509. row_size, ebid, data, (u8 *)pt_data_block_security_key,
  1510. &actual_write_len);
  1511. if (rc) {
  1512. pt_debug(dev, DL_ERROR,
  1513. "%s: Fail Put EBID=%d row=%d cmd fail r=%d\n",
  1514. __func__, ebid, row_number, rc);
  1515. return rc;
  1516. }
  1517. if (actual_write_len != row_size) {
  1518. pt_debug(dev, DL_ERROR,
  1519. "%s: Fail Put EBID=%d row=%d wrong write size=%d\n",
  1520. __func__, ebid, row_number, actual_write_len);
  1521. rc = -EINVAL;
  1522. }
  1523. return rc;
  1524. }
  1525. /*******************************************************************************
  1526. * FUNCTION: pt_upgrade_ttconfig
  1527. *
  1528. * SUMMARY: Program ttconfig_data with following steps:
  1529. * 1) Suspend scanning
  1530. * 2) Write data to the data block
  1531. * 3) Verify the crc for data block
  1532. * 4) Resume scanning
  1533. * 5) Set up call back for calibration if required
  1534. *
  1535. * RETURN:
  1536. * 0 = success
  1537. * !0 = failure
  1538. *
  1539. * PARAMETERS:
  1540. * *dev - pointer to device structure
  1541. * *ttconfig_data - pointer to the config data to write to data block
  1542. * ttconfig_size - size of config data to write
  1543. ******************************************************************************/
  1544. static int pt_upgrade_ttconfig(struct device *dev,
  1545. const u8 *ttconfig_data, int ttconfig_size)
  1546. {
  1547. struct pt_loader_data *ld = pt_get_loader_data(dev);
  1548. bool wait_for_calibration_complete = false;
  1549. u8 ebid = PT_TCH_PARM_EBID;
  1550. u16 row_size = PT_DATA_ROW_SIZE;
  1551. u16 table_size;
  1552. u16 row_count;
  1553. u16 residue;
  1554. u8 *row_buf;
  1555. u8 verify_crc_status;
  1556. u16 calculated_crc;
  1557. u16 stored_crc;
  1558. int rc = 0;
  1559. int i;
  1560. table_size = ttconfig_size;
  1561. row_count = table_size / row_size;
  1562. row_buf = (u8 *)ttconfig_data;
  1563. pt_debug(dev, DL_INFO, "%s: size:%d row_size=%d row_count=%d\n",
  1564. __func__, table_size, row_size, row_count);
  1565. pm_runtime_get_sync(dev);
  1566. rc = cmd->request_exclusive(dev, PT_LDR_REQUEST_EXCLUSIVE_TIMEOUT);
  1567. if (rc < 0)
  1568. goto exit;
  1569. rc = cmd->nonhid_cmd->suspend_scanning(dev, 0);
  1570. if (rc < 0)
  1571. goto release;
  1572. for (i = 0; i < row_count; i++) {
  1573. pt_debug(dev, DL_INFO, "%s: row=%d size=%d\n",
  1574. __func__, i, row_size);
  1575. rc = pt_write_config_row_(dev, ebid, i, row_size,
  1576. row_buf);
  1577. if (rc) {
  1578. pt_debug(dev, DL_ERROR, "%s: Fail put row=%d r=%d\n",
  1579. __func__, i, rc);
  1580. break;
  1581. }
  1582. row_buf += row_size;
  1583. }
  1584. if (!rc) {
  1585. residue = table_size % row_size;
  1586. pt_debug(dev, DL_WARN, "%s: row=%d size=%d\n",
  1587. __func__, i, residue);
  1588. rc = pt_write_config_row_(dev, ebid, i, residue,
  1589. row_buf);
  1590. row_count++;
  1591. if (rc)
  1592. pt_debug(dev, DL_ERROR, "%s: Fail put row=%d r=%d\n",
  1593. __func__, i, rc);
  1594. }
  1595. if (!rc)
  1596. pt_debug(dev, DL_WARN,
  1597. "%s: TT_CFG updated: rows:%d bytes:%d\n",
  1598. __func__, row_count, table_size);
  1599. rc = cmd->nonhid_cmd->verify_cfg_block_crc(dev, 0, ebid,
  1600. &verify_crc_status, &calculated_crc, &stored_crc);
  1601. if (rc || verify_crc_status)
  1602. pt_debug(dev, DL_ERROR,
  1603. "%s: CRC Failed, ebid=%d, status=%d, scrc=%X ccrc=%X\n",
  1604. __func__, ebid, verify_crc_status,
  1605. calculated_crc, stored_crc);
  1606. else
  1607. pt_debug(dev, DL_INFO,
  1608. "%s: CRC PASS, ebid=%d, status=%d, scrc=%X ccrc=%X\n",
  1609. __func__, ebid, verify_crc_status,
  1610. calculated_crc, stored_crc);
  1611. rc = cmd->nonhid_cmd->resume_scanning(dev, 0);
  1612. if (rc < 0)
  1613. goto release;
  1614. if (ld->loader_pdata &&
  1615. (ld->loader_pdata->flags
  1616. & PT_LOADER_FLAG_CALIBRATE_AFTER_TTCONFIG_UPGRADE)) {
  1617. #if (KERNEL_VERSION(3, 13, 0) <= LINUX_VERSION_CODE)
  1618. reinit_completion(&ld->calibration_complete);
  1619. #else
  1620. INIT_COMPLETION(ld->calibration_complete);
  1621. #endif
  1622. /* set up call back for startup */
  1623. pt_debug(dev, DL_INFO, "%s: Adding callback for calibration\n",
  1624. __func__);
  1625. rc = cmd->subscribe_attention(dev, PT_ATTEN_STARTUP,
  1626. PT_LOADER_NAME, pt_calibration_attention, 0);
  1627. if (rc) {
  1628. pt_debug(dev, DL_ERROR,
  1629. "%s: Failed adding callback for calibration\n",
  1630. __func__);
  1631. pt_debug(dev, DL_ERROR,
  1632. "%s: No calibration will be performed\n",
  1633. __func__);
  1634. rc = 0;
  1635. } else
  1636. wait_for_calibration_complete = true;
  1637. }
  1638. release:
  1639. cmd->release_exclusive(dev);
  1640. exit:
  1641. if (!rc)
  1642. cmd->request_enum(dev, true);
  1643. pm_runtime_put_sync(dev);
  1644. if (wait_for_calibration_complete)
  1645. wait_for_completion(&ld->calibration_complete);
  1646. return rc;
  1647. }
  1648. #endif /* PT_TTCONFIG_UPGRADE */
  1649. #ifdef CONFIG_TOUCHSCREEN_PARADE_PLATFORM_TTCONFIG_UPGRADE
  1650. /*******************************************************************************
  1651. * FUNCTION: pt_get_ttconfig_crc
  1652. *
  1653. * SUMMARY: Get crc from ttconfig data.
  1654. *
  1655. * RETURN:
  1656. * 0 = success
  1657. * !0 = failure
  1658. *
  1659. * PARAMETERS:
  1660. * *dev - pointer to device structure
  1661. * *ttconfig_data - pointer to the config data
  1662. * ttconfig_size - size of config data
  1663. * *crc - pointer to the crc of configure to be stored
  1664. ******************************************************************************/
  1665. static int pt_get_ttconfig_crc(struct device *dev,
  1666. const u8 *ttconfig_data, int ttconfig_size, u16 *crc)
  1667. {
  1668. u16 crc_loc;
  1669. crc_loc = get_unaligned_le16(&ttconfig_data[2]);
  1670. if (ttconfig_size < crc_loc + 2)
  1671. return -EINVAL;
  1672. *crc = get_unaligned_le16(&ttconfig_data[crc_loc]);
  1673. return 0;
  1674. }
  1675. /*******************************************************************************
  1676. * FUNCTION: pt_get_ttconfig_version
  1677. *
  1678. * SUMMARY: Get version number from ttconfig data.
  1679. *
  1680. * RETURN:
  1681. * 0 = success
  1682. * !0 = failure
  1683. *
  1684. * PARAMETERS:
  1685. * *dev - pointer to device structure
  1686. * *ttconfig_data - pointer to the config data
  1687. * ttconfig_size - size of config data
  1688. * *version - pointer to the version of configure to be stored
  1689. ******************************************************************************/
  1690. static int pt_get_ttconfig_version(struct device *dev,
  1691. const u8 *ttconfig_data, int ttconfig_size, u16 *version)
  1692. {
  1693. if (ttconfig_size < PT_TTCONFIG_VERSION_OFFSET
  1694. + PT_TTCONFIG_VERSION_SIZE)
  1695. return -EINVAL;
  1696. *version = get_unaligned_le16(
  1697. &ttconfig_data[PT_TTCONFIG_VERSION_OFFSET]);
  1698. return 0;
  1699. }
  1700. /*******************************************************************************
  1701. * FUNCTION: pt_check_ttconfig_version
  1702. *
  1703. * SUMMARY: Check the configure version and crc value to determine whether to
  1704. * upgrade,the upgrade conditions as following:
  1705. * 1) To upgrade if the config version is newer than current config, but
  1706. * this check is based on the flag in loader plarform data.
  1707. * 2) To upgrade if config CRC is different.
  1708. * 3) Don't upgrade when can't match any of above conditions.
  1709. *
  1710. * RETURN:
  1711. * 0: Don't upgrade
  1712. * 1: Upgrade
  1713. *
  1714. * PARAMETERS:
  1715. * *dev - pointer to device structure
  1716. * *ttconfig_data - pointer to the config data
  1717. * ttconfig_size - size of config data
  1718. ******************************************************************************/
  1719. static int pt_check_ttconfig_version(struct device *dev,
  1720. const u8 *ttconfig_data, int ttconfig_size)
  1721. {
  1722. struct pt_loader_data *ld = pt_get_loader_data(dev);
  1723. u16 cfg_crc_new;
  1724. int rc;
  1725. if (!ld->si)
  1726. return 0;
  1727. /* Check for config version */
  1728. if (ld->loader_pdata->flags &
  1729. PT_LOADER_FLAG_CHECK_TTCONFIG_VERSION) {
  1730. u16 cfg_ver_new;
  1731. rc = pt_get_ttconfig_version(dev, ttconfig_data,
  1732. ttconfig_size, &cfg_ver_new);
  1733. if (rc)
  1734. return 0;
  1735. pt_debug(dev, DL_INFO, "%s: img_ver:0x%04X new_ver:0x%04X\n",
  1736. __func__, ld->si->ttdata.fw_ver_conf, cfg_ver_new);
  1737. /* Check if config version is newer */
  1738. if (cfg_ver_new > ld->si->ttdata.fw_ver_conf) {
  1739. pt_debug(dev, DL_WARN,
  1740. "%s: Config version newer, will upgrade\n", __func__);
  1741. return 1;
  1742. }
  1743. pt_debug(dev, DL_WARN,
  1744. "%s: Config version is identical or older, will NOT upgrade\n",
  1745. __func__);
  1746. /* Check for config CRC */
  1747. } else {
  1748. rc = pt_get_ttconfig_crc(dev, ttconfig_data,
  1749. ttconfig_size, &cfg_crc_new);
  1750. if (rc)
  1751. return 0;
  1752. pt_debug(dev, DL_INFO, "%s: img_crc:0x%04X new_crc:0x%04X\n",
  1753. __func__, ld->si->ttconfig.crc, cfg_crc_new);
  1754. if (cfg_crc_new != ld->si->ttconfig.crc) {
  1755. pt_debug(dev, DL_WARN,
  1756. "%s: Config CRC different, will upgrade\n",
  1757. __func__);
  1758. return 1;
  1759. }
  1760. pt_debug(dev, DL_WARN,
  1761. "%s: Config CRC equal, will NOT upgrade\n", __func__);
  1762. }
  1763. return 0;
  1764. }
  1765. /*******************************************************************************
  1766. * FUNCTION: pt_check_ttconfig_version_platform
  1767. *
  1768. * SUMMARY: To call the function pt_check_ttconfig_version() to determine
  1769. * whether to load config if the firmware version match with current firmware.
  1770. *
  1771. * RETURN:
  1772. * 0: Don't upgrade
  1773. * 1: Upgrade
  1774. *
  1775. * PARAMETERS:
  1776. * *dev - pointer to device structure
  1777. * *ttconfig - pointer to touch_config structure
  1778. ******************************************************************************/
  1779. static int pt_check_ttconfig_version_platform(struct device *dev,
  1780. struct pt_touch_config *ttconfig)
  1781. {
  1782. struct pt_loader_data *ld = pt_get_loader_data(dev);
  1783. u32 fw_ver_config;
  1784. u32 fw_revctrl_config;
  1785. if (!ld->si) {
  1786. pt_debug(dev, DL_INFO,
  1787. "%s: No firmware info found, DUT FW may be corrupted\n",
  1788. __func__);
  1789. return 0;
  1790. }
  1791. fw_ver_config = get_unaligned_be16(ttconfig->fw_ver + 2);
  1792. /* 4 middle bytes are not used */
  1793. fw_revctrl_config = get_unaligned_be32(ttconfig->fw_ver + 8);
  1794. /* FW versions should match */
  1795. if (pt_check_firmware_version(dev, fw_ver_config,
  1796. fw_revctrl_config)) {
  1797. pt_debug(dev, DL_ERROR,
  1798. "%s: FW versions mismatch\n", __func__);
  1799. return 0;
  1800. }
  1801. /* Check PowerOn Self Test, TT_CFG CRC bit */
  1802. if ((ld->si->ttdata.post_code & PT_POST_TT_CFG_CRC_MASK) == 0) {
  1803. pt_debug(dev, DL_ERROR,
  1804. "%s: POST, TT_CFG failed (%X), will upgrade\n",
  1805. __func__, ld->si->ttdata.post_code);
  1806. return 1;
  1807. }
  1808. return pt_check_ttconfig_version(dev, ttconfig->param_regs->data,
  1809. ttconfig->param_regs->size);
  1810. }
  1811. /*******************************************************************************
  1812. * FUNCTION: pt_get_platform_ttconfig
  1813. *
  1814. * SUMMARY: To get the pointer of right touch_config structure by panel id.
  1815. *
  1816. * RETURN:
  1817. * pointer to touch_config structure or null pointer if fail
  1818. *
  1819. * PARAMETERS:
  1820. * *dev - pointer to device structure
  1821. ******************************************************************************/
  1822. static struct pt_touch_config *pt_get_platform_ttconfig(
  1823. struct device *dev)
  1824. {
  1825. struct pt_loader_data *ld = pt_get_loader_data(dev);
  1826. struct pt_touch_config **ttconfigs;
  1827. struct pt_touch_config *ttconfig;
  1828. u8 panel_id;
  1829. panel_id = pt_get_panel_id(dev);
  1830. if (panel_id == PANEL_ID_NOT_ENABLED) {
  1831. /* TODO: Make debug message */
  1832. pt_debug(dev, DL_INFO,
  1833. "%s: Panel ID not enabled, using legacy ttconfig\n",
  1834. __func__);
  1835. return ld->loader_pdata->ttconfig;
  1836. }
  1837. ttconfigs = ld->loader_pdata->ttconfigs;
  1838. if (!ttconfigs)
  1839. return NULL;
  1840. /* Find TT config according to the Panel ID */
  1841. while ((ttconfig = *ttconfigs++)) {
  1842. if (ttconfig->panel_id == panel_id) {
  1843. /* TODO: Make debug message */
  1844. pt_debug(dev, DL_INFO,
  1845. "%s: Found matching ttconfig:%p with Panel ID: 0x%02X\n",
  1846. __func__, ttconfig, ttconfig->panel_id);
  1847. return ttconfig;
  1848. }
  1849. pt_debug(dev, DL_ERROR,
  1850. "%s: Found mismatching ttconfig:%p with Panel ID: 0x%02X\n",
  1851. __func__, ttconfig, ttconfig->panel_id);
  1852. }
  1853. return NULL;
  1854. }
  1855. /*******************************************************************************
  1856. * FUNCTION: upgrade_ttconfig_from_platform
  1857. *
  1858. * SUMMARY: Get touch_firmware structure and perform upgrade if pass the
  1859. * firmware version check.
  1860. *
  1861. * RETURN:
  1862. * 0 = success
  1863. * !0 = failure
  1864. *
  1865. * PARAMETERS:
  1866. * *dev - pointer to device structure
  1867. * forced - flag to force upgrade(1:force to upgrade)
  1868. ******************************************************************************/
  1869. static int upgrade_ttconfig_from_platform(struct device *dev)
  1870. {
  1871. struct pt_loader_data *ld = pt_get_loader_data(dev);
  1872. struct pt_touch_config *ttconfig;
  1873. struct touch_settings *param_regs;
  1874. int rc = -ENODEV;
  1875. int upgrade;
  1876. if (!ld->loader_pdata) {
  1877. pt_debug(dev, DL_ERROR,
  1878. "%s: No loader platform data\n", __func__);
  1879. return rc;
  1880. }
  1881. ttconfig = pt_get_platform_ttconfig(dev);
  1882. if (!ttconfig) {
  1883. pt_debug(dev, DL_ERROR, "%s: No ttconfig data\n", __func__);
  1884. return rc;
  1885. }
  1886. param_regs = ttconfig->param_regs;
  1887. if (!param_regs) {
  1888. pt_debug(dev, DL_ERROR, "%s: No touch parameters\n",
  1889. __func__);
  1890. return rc;
  1891. }
  1892. if (!param_regs->data || !param_regs->size) {
  1893. pt_debug(dev, DL_ERROR,
  1894. "%s: Invalid touch parameters\n", __func__);
  1895. return rc;
  1896. }
  1897. if (!ttconfig->fw_ver || !ttconfig->fw_vsize) {
  1898. pt_debug(dev, DL_ERROR,
  1899. "%s: Invalid FW version for touch parameters\n",
  1900. __func__);
  1901. return rc;
  1902. }
  1903. upgrade = pt_check_ttconfig_version_platform(dev, ttconfig);
  1904. if (upgrade)
  1905. return pt_upgrade_ttconfig(dev, param_regs->data,
  1906. param_regs->size);
  1907. return rc;
  1908. }
  1909. #endif /* CONFIG_TOUCHSCREEN_PARADE_PLATFORM_TTCONFIG_UPGRADE */
  1910. #ifdef CONFIG_TOUCHSCREEN_PARADE_MANUAL_TTCONFIG_UPGRADE
  1911. /*******************************************************************************
  1912. * FUNCTION: pt_config_data_write
  1913. *
  1914. * SUMMARY: The write method for the config_data sysfs node. The passed
  1915. * in data (config file) is written to the config_data buffer.
  1916. *
  1917. * RETURN: Size of passed in buffer is success
  1918. *
  1919. * PARAMETERS:
  1920. * *filp - pointer to file structure
  1921. * *kobj - pointer to kobject structure
  1922. * *bin_attr - pointer to bin_attribute structure
  1923. * buf - pointer to cmd input buffer
  1924. * offset - offset index to store input buffer
  1925. * count - size of data in buffer
  1926. ******************************************************************************/
  1927. static ssize_t pt_config_data_write(struct file *filp,
  1928. struct kobject *kobj, struct bin_attribute *bin_attr,
  1929. char *buf, loff_t offset, size_t count)
  1930. {
  1931. struct device *dev = container_of(kobj, struct device, kobj);
  1932. struct pt_loader_data *data = pt_get_loader_data(dev);
  1933. u8 *p;
  1934. pt_debug(dev, DL_INFO, "%s: offset:%lld count:%zu\n",
  1935. __func__, offset, count);
  1936. mutex_lock(&data->config_lock);
  1937. if (!data->config_loading) {
  1938. mutex_unlock(&data->config_lock);
  1939. return -ENODEV;
  1940. }
  1941. p = krealloc(data->config_data, offset + count, GFP_KERNEL);
  1942. if (!p) {
  1943. kfree(data->config_data);
  1944. data->config_data = NULL;
  1945. mutex_unlock(&data->config_lock);
  1946. return -ENOMEM;
  1947. }
  1948. data->config_data = p;
  1949. memcpy(&data->config_data[offset], buf, count);
  1950. data->config_size += count;
  1951. mutex_unlock(&data->config_lock);
  1952. return count;
  1953. }
  1954. static struct bin_attribute bin_attr_config_data = {
  1955. .attr = {
  1956. .name = "config_data",
  1957. .mode = 0200,
  1958. },
  1959. .size = 0,
  1960. .write = pt_config_data_write,
  1961. };
  1962. /*******************************************************************************
  1963. * FUNCTION: pt_verify_ttconfig_binary
  1964. *
  1965. * SUMMARY: Perform a simple size check if the firmware version match.And
  1966. * calculate the start pointer of config data to write and the size to write.
  1967. *
  1968. * RETURN:
  1969. * 0 = success
  1970. * !0 = failure
  1971. *
  1972. * PARAMETERS:
  1973. * *dev - pointer to device structure
  1974. * *bin_config_data - pointer to binary config data
  1975. * bin_config_size - size of binary config data
  1976. * **start - double pointer to config data where to be written
  1977. * *len - pointer to the size of config data to store
  1978. ******************************************************************************/
  1979. static int pt_verify_ttconfig_binary(struct device *dev,
  1980. u8 *bin_config_data, int bin_config_size, u8 **start, int *len)
  1981. {
  1982. struct pt_loader_data *ld = pt_get_loader_data(dev);
  1983. int header_size;
  1984. u16 config_size;
  1985. u32 fw_ver_config;
  1986. u32 fw_revctrl_config;
  1987. if (!ld->si) {
  1988. pt_debug(dev, DL_ERROR,
  1989. "%s: No firmware info found, DUT FW may be corrupted\n",
  1990. __func__);
  1991. return -ENODEV;
  1992. }
  1993. /*
  1994. * We need 11 bytes for FW version control info and at
  1995. * least 6 bytes in config (Length + Max Length + CRC)
  1996. */
  1997. header_size = bin_config_data[0] + 1;
  1998. if (header_size < 11 || header_size >= bin_config_size - 6) {
  1999. pt_debug(dev, DL_ERROR,
  2000. "%s: Invalid header size %d\n", __func__,
  2001. header_size);
  2002. return -EINVAL;
  2003. }
  2004. fw_ver_config = get_unaligned_be16(&bin_config_data[1]);
  2005. /* 4 middle bytes are not used */
  2006. fw_revctrl_config = get_unaligned_be32(&bin_config_data[7]);
  2007. /* FW versions should match */
  2008. if (pt_check_firmware_version(dev, fw_ver_config,
  2009. fw_revctrl_config)) {
  2010. pt_debug(dev, DL_ERROR,
  2011. "%s: FW versions mismatch\n", __func__);
  2012. return -EINVAL;
  2013. }
  2014. config_size = get_unaligned_le16(&bin_config_data[header_size]);
  2015. /* Perform a simple size check (2 bytes for CRC) */
  2016. if (config_size != bin_config_size - header_size - 2) {
  2017. pt_debug(dev, DL_ERROR,
  2018. "%s: Config size invalid\n", __func__);
  2019. return -EINVAL;
  2020. }
  2021. *start = &bin_config_data[header_size];
  2022. *len = bin_config_size - header_size;
  2023. return 0;
  2024. }
  2025. /*
  2026. * 1: Start loading TT Config
  2027. * 0: End loading TT Config and perform upgrade
  2028. *-1: Exit loading
  2029. */
  2030. /*******************************************************************************
  2031. * FUNCTION: pt_config_loading_store
  2032. *
  2033. * SUMMARY: The store method for the config_loading sysfs node. The
  2034. * passed in value controls if config loading is performed.
  2035. *
  2036. * RETURN: Size of passed in buffer is success
  2037. *
  2038. * PARAMETERS:
  2039. * *dev - pointer to device structure
  2040. * *attr - pointer to device attributes
  2041. * *buf - pointer to buffer that hold the command parameters
  2042. * size - size of buf
  2043. ******************************************************************************/
  2044. static ssize_t pt_config_loading_store(struct device *dev,
  2045. struct device_attribute *attr, const char *buf, size_t size)
  2046. {
  2047. struct pt_loader_data *ld = pt_get_loader_data(dev);
  2048. long value;
  2049. u8 *start;
  2050. int length;
  2051. int rc;
  2052. rc = kstrtol(buf, 10, &value);
  2053. if (rc < 0 || value < -1 || value > 1) {
  2054. pt_debug(dev, DL_ERROR, "%s: Invalid value\n", __func__);
  2055. return size;
  2056. }
  2057. mutex_lock(&ld->config_lock);
  2058. if (value == 1)
  2059. ld->config_loading = true;
  2060. else if (value == -1)
  2061. ld->config_loading = false;
  2062. else if (value == 0 && ld->config_loading) {
  2063. ld->config_loading = false;
  2064. if (ld->config_size == 0) {
  2065. pt_debug(dev, DL_ERROR,
  2066. "%s: No config data\n", __func__);
  2067. goto exit_free;
  2068. }
  2069. rc = pt_verify_ttconfig_binary(dev,
  2070. ld->config_data, ld->config_size,
  2071. &start, &length);
  2072. if (rc)
  2073. goto exit_free;
  2074. rc = pt_upgrade_ttconfig(dev, start, length);
  2075. }
  2076. exit_free:
  2077. kfree(ld->config_data);
  2078. ld->config_data = NULL;
  2079. ld->config_size = 0;
  2080. mutex_unlock(&ld->config_lock);
  2081. if (rc)
  2082. return rc;
  2083. return size;
  2084. }
  2085. static DEVICE_ATTR(config_loading, 0200,
  2086. NULL, pt_config_loading_store);
  2087. #endif /* CONFIG_TOUCHSCREEN_PARADE_MANUAL_TTCONFIG_UPGRADE */
  2088. #ifdef CONFIG_TOUCHSCREEN_PARADE_PLATFORM_FW_UPGRADE
  2089. /*******************************************************************************
  2090. * FUNCTION: pt_forced_upgrade_store
  2091. *
  2092. * SUMMARY: The store method for the forced_upgrade sysfs node. The firmware
  2093. * loading is forced to performed with platform upgrade strategy.
  2094. *
  2095. * RETURN: Size of passed in buffer is success
  2096. *
  2097. * PARAMETERS:
  2098. * *dev - pointer to device structure
  2099. * *attr - pointer to device attributes
  2100. * *buf - pointer to buffer that hold the command parameters
  2101. * size - size of buf
  2102. ******************************************************************************/
  2103. static ssize_t pt_forced_upgrade_store(struct device *dev,
  2104. struct device_attribute *attr, const char *buf, size_t size)
  2105. {
  2106. int rc = upgrade_firmware_from_platform(dev, true);
  2107. if (rc)
  2108. return rc;
  2109. return size;
  2110. }
  2111. static DEVICE_ATTR(forced_upgrade, 0200,
  2112. NULL, pt_forced_upgrade_store);
  2113. #endif
  2114. #ifdef CONFIG_TOUCHSCREEN_PARADE_BINARY_FW_UPGRADE
  2115. /*******************************************************************************
  2116. * FUNCTION: pt_manual_upgrade_store
  2117. *
  2118. * SUMMARY: The store method for the forced_upgrade sysfs node that it is
  2119. * caller for function upgrade_firmware_from_class() to allow upgrade firmware
  2120. * manually.
  2121. *
  2122. * RETURN: Size of passed in buffer is success
  2123. *
  2124. * PARAMETERS:
  2125. * *dev - pointer to device structure
  2126. * *attr - pointer to device attributes
  2127. * *buf - pointer to buffer that hold the command parameters
  2128. * size - size of buf
  2129. ******************************************************************************/
  2130. static ssize_t pt_manual_upgrade_store(struct device *dev,
  2131. struct device_attribute *attr, const char *buf, size_t size)
  2132. {
  2133. struct pt_loader_data *ld = pt_get_loader_data(dev);
  2134. u32 input_data[2] = {0};
  2135. int length;
  2136. int rc = 0;
  2137. length = cmd->parse_sysfs_input(dev, buf, size, input_data,
  2138. ARRAY_SIZE(input_data));
  2139. if (length != 1) {
  2140. pt_debug(dev, DL_WARN, "%s: Invalid number of arguments\n",
  2141. __func__);
  2142. rc = -EINVAL;
  2143. goto exit;
  2144. }
  2145. if (input_data[0] < 0 || input_data[0] > 1) {
  2146. pt_debug(dev, DL_WARN, "%s: Invalid arguments\n", __func__);
  2147. rc = -EINVAL;
  2148. goto exit;
  2149. }
  2150. _pt_pip2_update_bl_status(dev, UPDATE_FW_IDLE, PT_NO_INC);
  2151. if (ld->is_manual_upgrade_enabled) {
  2152. rc = -EBUSY;
  2153. goto exit;
  2154. }
  2155. ld->is_manual_upgrade_enabled = 1;
  2156. rc = upgrade_firmware_from_class(ld->dev);
  2157. if (rc < 0)
  2158. ld->is_manual_upgrade_enabled = 0;
  2159. exit:
  2160. if (rc)
  2161. return rc;
  2162. return size;
  2163. }
  2164. static DEVICE_ATTR(manual_upgrade, 0200, NULL, pt_manual_upgrade_store);
  2165. #endif /* CONFIG_TOUCHSCREEN_PARADE_BINARY_FW_UPGRADE */
  2166. /*******************************************************************************
  2167. * FUNCTION: pt_fw_and_config_upgrade
  2168. *
  2169. * SUMMARY: Perform all methods for firmware upgrade and config upgrade
  2170. * according to the definition of macro.
  2171. *
  2172. * PARAMETERS:
  2173. * *work_struct - pointer to work_struct structure
  2174. ******************************************************************************/
  2175. static void pt_fw_and_config_upgrade(
  2176. struct work_struct *fw_and_config_upgrade)
  2177. {
  2178. struct pt_loader_data *ld = container_of(fw_and_config_upgrade,
  2179. struct pt_loader_data, fw_and_config_upgrade);
  2180. struct device *dev = ld->dev;
  2181. struct pt_core_data *cd = dev_get_drvdata(dev);
  2182. int retry = 200;
  2183. #if PT_FW_UPGRADE \
  2184. || defined(CONFIG_TOUCHSCREEN_PARADE_PLATFORM_TTCONFIG_UPGRADE)
  2185. u8 dut_gen = cmd->request_dut_generation(dev);
  2186. #endif
  2187. /*
  2188. * Since the resume_scan command in pt_probe_complete() has
  2189. * no protection,it may cause problem for the commands in fw
  2190. * upgrade process during probe. Waiting for the probe to
  2191. * complete before performing fw upgrade can avoid this failure.
  2192. */
  2193. while (!cd->core_probe_complete && retry--)
  2194. msleep(20);
  2195. ld->si = cmd->request_sysinfo(dev);
  2196. if (!ld->si)
  2197. pt_debug(dev, DL_ERROR,
  2198. "%s: Fail get sysinfo pointer from core\n",
  2199. __func__);
  2200. #if !PT_FW_UPGRADE
  2201. pt_debug(dev, DL_INFO,
  2202. "%s: No FW upgrade method selected!\n", __func__);
  2203. #endif
  2204. #ifdef CONFIG_TOUCHSCREEN_PARADE_PLATFORM_FW_UPGRADE
  2205. if (dut_gen == DUT_PIP1_ONLY) {
  2206. if (!upgrade_firmware_from_platform(dev, false))
  2207. return;
  2208. }
  2209. #endif
  2210. #ifdef CONFIG_TOUCHSCREEN_PARADE_BINARY_FW_UPGRADE
  2211. if (dut_gen == DUT_PIP2_CAPABLE) {
  2212. if (!pt_pip2_upgrade_firmware_from_builtin(dev))
  2213. return;
  2214. pt_debug(dev, DL_WARN, "%s: Builtin FW upgrade failed\n",
  2215. __func__);
  2216. } else {
  2217. if (!upgrade_firmware_from_builtin(dev))
  2218. return;
  2219. }
  2220. #endif
  2221. #ifdef CONFIG_TOUCHSCREEN_PARADE_PLATFORM_TTCONFIG_UPGRADE
  2222. if (dut_gen == DUT_PIP1_ONLY) {
  2223. if (!upgrade_ttconfig_from_platform(dev))
  2224. return;
  2225. }
  2226. #endif
  2227. }
  2228. #ifdef CONFIG_TOUCHSCREEN_PARADE_BINARY_FW_UPGRADE
  2229. #ifdef TTDL_DIAGNOSTICS
  2230. /*******************************************************************************
  2231. * FUNCTION: _pt_pip2_get_flash_info
  2232. *
  2233. * SUMMARY: Sends a FLASH_INFO command to the DUT logging the results to kmsg
  2234. *
  2235. * PARAMETERS:
  2236. * *dev - pointer to device structure
  2237. * *read_buf - pointer to the read buffer array to store the response
  2238. ******************************************************************************/
  2239. static void _pt_pip2_get_flash_info(struct device *dev,
  2240. u8 *read_buf)
  2241. {
  2242. u16 actual_read_len;
  2243. int ret;
  2244. /* Get flash info for debugging information */
  2245. ret = cmd->nonhid_cmd->pip2_send_cmd(dev,
  2246. PT_CORE_CMD_UNPROTECTED, PIP2_CMD_ID_FLASH_INFO,
  2247. NULL, 0, read_buf, &actual_read_len);
  2248. if (!ret) {
  2249. pt_debug(dev, DL_DEBUG,
  2250. "%s --- FLASH Information ---\n", __func__);
  2251. pt_debug(dev, DL_DEBUG,
  2252. "%s Manufacturer ID: 0x%02x\n",
  2253. __func__, read_buf[PIP2_RESP_BODY_OFFSET]);
  2254. pt_debug(dev, DL_DEBUG,
  2255. "%s Memory Type : 0x%02x\n",
  2256. __func__, read_buf[PIP2_RESP_BODY_OFFSET + 1]);
  2257. pt_debug(dev, DL_DEBUG,
  2258. "%s Num Sectors : 0x%02x%02x%02x%02x\n",
  2259. __func__, read_buf[PIP2_RESP_BODY_OFFSET + 2],
  2260. read_buf[PIP2_RESP_BODY_OFFSET + 3],
  2261. read_buf[PIP2_RESP_BODY_OFFSET + 4],
  2262. read_buf[PIP2_RESP_BODY_OFFSET + 5]);
  2263. pt_debug(dev, DL_DEBUG,
  2264. "%s Sectors Size : 0x%02x%02x%02x%02x\n",
  2265. __func__, read_buf[PIP2_RESP_BODY_OFFSET + 6],
  2266. read_buf[PIP2_RESP_BODY_OFFSET + 7],
  2267. read_buf[PIP2_RESP_BODY_OFFSET + 8],
  2268. read_buf[PIP2_RESP_BODY_OFFSET + 9]);
  2269. pt_debug(dev, DL_DEBUG,
  2270. "%s Page Size : 0x%02x%02x%02x%02x\n",
  2271. __func__, read_buf[PIP2_RESP_BODY_OFFSET + 10],
  2272. read_buf[PIP2_RESP_BODY_OFFSET + 11],
  2273. read_buf[PIP2_RESP_BODY_OFFSET + 12],
  2274. read_buf[PIP2_RESP_BODY_OFFSET + 13]);
  2275. if (actual_read_len > 21) {
  2276. pt_debug(dev, DL_DEBUG,
  2277. "%s Status Reg1 : 0x%02x\n",
  2278. __func__,
  2279. read_buf[PIP2_RESP_BODY_OFFSET + 14]);
  2280. pt_debug(dev, DL_DEBUG,
  2281. "%s Status Reg2 : 0x%02x\n",
  2282. __func__,
  2283. read_buf[PIP2_RESP_BODY_OFFSET + 15]);
  2284. }
  2285. }
  2286. }
  2287. #endif /* TTDL_DIAGNOSTICS */
  2288. /*******************************************************************************
  2289. * FUNCTION: _pt_pip2_log_last_error
  2290. *
  2291. * SUMMARY: Sends a STATUS command to the DUT logging the results until all
  2292. * errors are cleared. Also sends a GET_LAST_ERRNO to get any Boot errors.
  2293. * This must be sent after the STATUS flush in order not to have this
  2294. * command cause another error.
  2295. *
  2296. * NOTE: This function support No Interrupt Solution and switch "pip2_send_cmd"
  2297. * function according to the global variable "bl_with_no_int".
  2298. * RETURN:
  2299. * 0 = success
  2300. * !0 = failure
  2301. *
  2302. * PARAMETERS:
  2303. * *dev - pointer to device structure
  2304. * *read_buf - pointer to the read buffer array to store the response
  2305. ******************************************************************************/
  2306. static int _pt_pip2_log_last_error(struct device *dev,
  2307. u8 *read_buf)
  2308. {
  2309. u16 actual_read_len;
  2310. u8 loop = 5;
  2311. u8 info = 0xFF;
  2312. u8 error = 0xFF;
  2313. int ret;
  2314. PIP2_SEND_CMD pip2_send_cmd;
  2315. struct pt_core_data *cd = dev_get_drvdata(dev);
  2316. if (cd->bl_with_no_int)
  2317. pip2_send_cmd = cmd->nonhid_cmd->pip2_send_cmd_no_int;
  2318. else
  2319. pip2_send_cmd = cmd->nonhid_cmd->pip2_send_cmd;
  2320. /*
  2321. * Send the STATUS command until no errors are found.
  2322. * The BL will store an error code for each layer of the stack,
  2323. * and each read will return one error.
  2324. */
  2325. while (loop > 0 && error) {
  2326. ret = pip2_send_cmd(dev,
  2327. PT_CORE_CMD_UNPROTECTED, PIP2_CMD_ID_STATUS,
  2328. NULL, 0, read_buf, &actual_read_len);
  2329. if (!ret) {
  2330. info = (u8)read_buf[PIP2_RESP_BODY_OFFSET];
  2331. error = (u8)read_buf[PIP2_RESP_BODY_OFFSET + 1];
  2332. pt_debug(dev, DL_ERROR,
  2333. "%s: STATUS: Status=0x%02X BOOT=%d BUSY=%d INT=%d ERR_PHY=%d ERR_REG=%d ERROR=0x%02X",
  2334. __func__,
  2335. (u8)read_buf[PIP2_RESP_STATUS_OFFSET],
  2336. info & 0x01,
  2337. (info & 0x02) >> 1,
  2338. (info & 0x04) >> 2,
  2339. (info & 0x18) >> 3,
  2340. (info & 0xE0) >> 5,
  2341. error);
  2342. }
  2343. loop--;
  2344. }
  2345. /* Send the GET_LAST_ERROR command to get the last BL startup error */
  2346. ret = pip2_send_cmd(dev,
  2347. PT_CORE_CMD_UNPROTECTED, PIP2_CMD_ID_GET_LAST_ERRNO,
  2348. NULL, 0, read_buf, &actual_read_len);
  2349. if (!ret) {
  2350. pt_debug(dev, DL_ERROR,
  2351. "%s: GET_LAST_ERR: Status=0x%02X ERRNO=0x%02X BOOTMODE=%d\n",
  2352. __func__,
  2353. (u8)read_buf[PIP2_RESP_STATUS_OFFSET],
  2354. (u8)read_buf[PIP2_RESP_BODY_OFFSET],
  2355. (u8)read_buf[PIP2_RESP_BODY_OFFSET + 1]);
  2356. }
  2357. return ret;
  2358. }
  2359. /*******************************************************************************
  2360. * FUNCTION: _pt_pip2_check_fw_ver
  2361. *
  2362. * SUMMARY: Compare the FW version in the bin file to the current FW. If the
  2363. * FW version in the bin file is greater an upgrade should be done.
  2364. *
  2365. * RETURN:
  2366. * -1: Do not upgrade firmware
  2367. * 0: Version info same, let caller decide
  2368. * 1: Do a firmware upgrade
  2369. *
  2370. * PARAMETERS:
  2371. * *dev - pointer to device structure
  2372. * *fw - pointer to the new FW image to load
  2373. * *hdr - pointer to the PIP2 bin file hdr structure
  2374. ******************************************************************************/
  2375. static int _pt_pip2_check_fw_ver(struct device *dev,
  2376. const struct firmware *fw, struct pt_bin_file_hdr *hdr)
  2377. {
  2378. u8 img_app_major_ver = fw->data[3];
  2379. u8 img_app_minor_ver = fw->data[4];
  2380. u32 img_app_rev_ctrl = fw->data[9]<<24 | fw->data[10]<<16 |
  2381. fw->data[11]<<8 | fw->data[12];
  2382. pt_debug(dev, DL_WARN,
  2383. "%s ATM - BL Image Version: %02x.%02x.%d\n",
  2384. __func__, img_app_major_ver, img_app_minor_ver,
  2385. img_app_rev_ctrl);
  2386. pt_debug(dev, DL_WARN,
  2387. "%s ATM - Current FW Version: %02X.%02X.%d\n",
  2388. __func__, hdr->fw_major, hdr->fw_minor, hdr->fw_rev_ctrl);
  2389. if ((256 * img_app_major_ver + img_app_minor_ver) >
  2390. (256 * hdr->fw_major + hdr->fw_minor)) {
  2391. pt_debug(dev, DL_WARN,
  2392. "ATM - bin file version > FW, will upgrade FW");
  2393. return 1;
  2394. }
  2395. if ((256 * img_app_major_ver + img_app_minor_ver) <
  2396. (256 * hdr->fw_major + hdr->fw_minor)) {
  2397. pt_debug(dev, DL_WARN,
  2398. "ATM - bin file version < FW, will NOT upgrade FW");
  2399. return -EPERM;
  2400. }
  2401. if (img_app_rev_ctrl > hdr->fw_rev_ctrl) {
  2402. pt_debug(dev, DL_WARN,
  2403. "bin file rev ctrl > FW, will upgrade FW");
  2404. return 1;
  2405. }
  2406. if (img_app_rev_ctrl < hdr->fw_rev_ctrl) {
  2407. pt_debug(dev, DL_WARN,
  2408. "bin file rev ctrl > FW, will NOT upgrade FW");
  2409. return -EPERM;
  2410. }
  2411. return 0;
  2412. }
  2413. /*******************************************************************************
  2414. * FUNCTION: _pt_pip2_check_config_ver
  2415. *
  2416. * SUMMARY: Compare the Config version in the bin file to the current FW. If the
  2417. * config version in the bin file is greater an upgrade should be done.
  2418. *
  2419. * RETURN:
  2420. * -1: Do not upgrade firmware
  2421. * 0: Version info same, let caller decide
  2422. * 1: Do a firmware upgrade
  2423. *
  2424. * PARAMETERS:
  2425. * *dev - pointer to device structure
  2426. * *fw - pointer to the new FW image to load
  2427. * *hdr - pointer to the PIP2 bin file hdr structure
  2428. ******************************************************************************/
  2429. static int _pt_pip2_check_config_ver(struct device *dev,
  2430. const struct firmware *fw, struct pt_bin_file_hdr *hdr)
  2431. {
  2432. u16 fw_config_ver_new;
  2433. /* Offset 17,18 is the TT Config version*/
  2434. fw_config_ver_new = get_unaligned_be16(fw->data + 17);
  2435. pt_debug(dev, DL_WARN,
  2436. "%s ATM - BL Image Config Version: %d\n",
  2437. __func__, fw_config_ver_new);
  2438. pt_debug(dev, DL_WARN,
  2439. "%s ATM - Current Config Version: %d\n",
  2440. __func__, hdr->config_ver);
  2441. if (fw_config_ver_new > hdr->config_ver) {
  2442. pt_debug(dev, DL_WARN,
  2443. "ATM - bin file Config version > FW, will upgrade FW");
  2444. return 1;
  2445. } else
  2446. pt_debug(dev, DL_WARN,
  2447. "ATM - bin file Config version <= FW, will NOT upgrade FW");
  2448. return 0;
  2449. }
  2450. /*******************************************************************************
  2451. * FUNCTION: _pt_pip2_need_upgrade_due_to_fw_ver
  2452. *
  2453. * SUMMARY: Compare the FW version in the bin file to the current FW. If the
  2454. * FW version in the bin file is greater an upgrade should be done.
  2455. *
  2456. * PARAMETERS:
  2457. * *dev - pointer to device structure
  2458. * *fw - pointer to the new FW image to load
  2459. ******************************************************************************/
  2460. static u8 _pt_pip2_need_upgrade_due_to_fw_ver(struct device *dev,
  2461. const struct firmware *fw)
  2462. {
  2463. int ret;
  2464. u8 should_upgrade = 0;
  2465. struct pt_bin_file_hdr hdr = {0};
  2466. ret = cmd->request_pip2_bin_hdr(dev, &hdr);
  2467. if (ret != 0 || hdr.fw_major == 0xFF) {
  2468. pt_debug(dev, DL_WARN,
  2469. "App ver info not available, will upgrade FW");
  2470. should_upgrade = 1;
  2471. goto exit;
  2472. }
  2473. ret = _pt_pip2_check_fw_ver(dev, fw, &hdr);
  2474. if (ret == 0)
  2475. ret = _pt_pip2_check_config_ver(dev, fw, &hdr);
  2476. if (ret > 0)
  2477. should_upgrade = 1;
  2478. exit:
  2479. return should_upgrade;
  2480. }
  2481. /*******************************************************************************
  2482. * FUNCTION: _pt_calibrate_flashless_dut
  2483. *
  2484. * SUMMARY: On a flashless DUT the FW would need to re-calibrate on every power
  2485. * cycle, so to speed up the BL process the FW does the calibraiton on the
  2486. * first power up and TTDL will read and store it in RAM to be able to
  2487. * restore it on subsequent resets of the DUT.
  2488. *
  2489. * RETURN:
  2490. * 0 = success
  2491. * !0 = failure
  2492. *
  2493. * PARAMETERS:
  2494. * *dev - pointer to device structure
  2495. ******************************************************************************/
  2496. static int _pt_calibrate_flashless_dut(struct device *dev)
  2497. {
  2498. u8 rc = 0;
  2499. u8 cal_status = 1;
  2500. u16 cal_size = 0;
  2501. struct pt_cal_ext_data cal_data = {0};
  2502. struct pt_core_data *cd = dev_get_drvdata(dev);
  2503. struct pt_ttdata *ttdata = &cd->sysinfo.ttdata;
  2504. unsigned short cache_chip_id = 0;
  2505. unsigned short active_chip_id = 0;
  2506. cmd->nonhid_cmd->manage_cal_data(dev, PT_CAL_DATA_INFO, &cal_size,
  2507. &cache_chip_id);
  2508. pt_debug(dev, DL_WARN, "%s: Stored CAL ID=0x%04X size=%d\n",
  2509. __func__, cache_chip_id, cal_size);
  2510. active_chip_id = cmd->nonhid_cmd->calc_crc((u8 *)&ttdata->chip_rev,
  2511. 4 + PT_UID_SIZE);
  2512. pt_debug(dev, DL_WARN, "%s: Current Chip ID=0x%04X\n",
  2513. __func__, active_chip_id);
  2514. if (cal_size == 0 || active_chip_id != cache_chip_id) {
  2515. memset(&cal_data, 0, sizeof(struct pt_cal_ext_data));
  2516. /* Calibrate_ext will also save CAL Data in TTDL cache */
  2517. rc = cmd->nonhid_cmd->calibrate_ext(dev, 0, &cal_data,
  2518. &cal_status);
  2519. pt_debug(dev, DL_INFO,
  2520. "%s: Calibration Finished rc=%d\n", __func__, rc);
  2521. /* Afer successful calibration read the stored size */
  2522. if (!rc && cal_status == 0) {
  2523. rc = cmd->nonhid_cmd->manage_cal_data(dev,
  2524. PT_CAL_DATA_INFO, &cal_size, &cache_chip_id);
  2525. if (!rc) {
  2526. pt_debug(dev, DL_WARN,
  2527. "%s: First BL, Read %d Bytes of CAL\n",
  2528. __func__, cal_size);
  2529. } else {
  2530. pt_debug(dev, DL_ERROR,
  2531. "%s: First BL, Failed to read CAL\n",
  2532. __func__);
  2533. }
  2534. } else {
  2535. pt_debug(dev, DL_ERROR,
  2536. "%s: First BL, Calibration failed rc=%d\n",
  2537. __func__, rc);
  2538. }
  2539. rc = cmd->nonhid_cmd->resume_scanning(dev, 0);
  2540. if (rc)
  2541. pt_debug(dev, DL_ERROR,
  2542. "%s: First BL, Resume Scan failed rc=%d\n",
  2543. __func__, rc);
  2544. } else {
  2545. rc = cmd->nonhid_cmd->manage_cal_data(dev, PT_CAL_DATA_RESTORE,
  2546. &cal_size, &cache_chip_id);
  2547. if (!rc)
  2548. pt_debug(dev, DL_WARN, "%s: Restored CAL %d Bytes\n",
  2549. __func__, cal_size);
  2550. else
  2551. pt_debug(dev, DL_ERROR, "%s: Failed to restore CAL\n",
  2552. __func__);
  2553. rc = cmd->nonhid_cmd->resume_scanning(dev, 0);
  2554. if (rc)
  2555. pt_debug(dev, DL_ERROR,
  2556. "%s: Resume Scan failed rc=%d\n",
  2557. __func__, rc);
  2558. }
  2559. return rc;
  2560. }
  2561. /*******************************************************************************
  2562. * FUNCTION: _pt_pip2_firmware_cont
  2563. *
  2564. * SUMMARY: Bootload the DUT with a FW image using the PIP2 protocol. This
  2565. * includes getting the DUT into BL mode, writing the file to either SRAM
  2566. * or FLASH, and launching the application directly in SRAM or by resetting
  2567. * the DUT without the hostmode pin asserted.
  2568. *
  2569. * NOTE: Special care must be taken to support a DUT communicating in
  2570. * PIP2.0 where the length field is defined differently.
  2571. * NOTE: The write packet len is set so that the overall packet size is
  2572. * less than 255. The overhead is 9 bytes: 2 byte address (0101),
  2573. * 4 byte header, 1 byte file no. 2 byte CRC
  2574. *
  2575. * PARAMETERS:
  2576. * *fw - pointer to the new FW image to load
  2577. * *context - pointer to the device
  2578. ******************************************************************************/
  2579. static void _pt_pip2_firmware_cont(const struct firmware *fw,
  2580. void *context)
  2581. {
  2582. u8 read_buf[PT_MAX_PIP2_MSG_SIZE];
  2583. u8 buf[PT_MAX_PIP2_MSG_SIZE];
  2584. u8 *fw_img = NULL;
  2585. u16 write_len;
  2586. u8 mode = PT_MODE_UNKNOWN;
  2587. u8 retry_packet = 0;
  2588. u8 us_fw_used = 0;
  2589. u16 actual_read_len;
  2590. u16 status = 0;
  2591. u16 packet_size;
  2592. int fw_size = 0;
  2593. int remain_bytes;
  2594. int ret = 0;
  2595. int percent_cmplt;
  2596. int t;
  2597. int erase_status;
  2598. u32 max_file_size;
  2599. bool wait_for_calibration_complete = false;
  2600. PIP2_SEND_CMD pip2_send_cmd;
  2601. struct device *dev = context;
  2602. struct pt_loader_data *ld = pt_get_loader_data(dev);
  2603. struct pip2_loader_data *pip2_data = ld->pip2_data;
  2604. struct pt_core_data *cd = dev_get_drvdata(dev);
  2605. pt_debug(dev, DL_WARN, "%s: ATM - Begin BL\n", __func__);
  2606. _pt_pip2_update_bl_status(dev, UPDATE_FW_IDLE, PT_NO_INC);
  2607. if (cd->bus_ops->bustype == BUS_I2C)
  2608. packet_size = PIP2_BL_I2C_FILE_WRITE_LEN_PER_PACKET;
  2609. else
  2610. packet_size = PIP2_BL_SPI_FILE_WRITE_LEN_PER_PACKET;
  2611. ret = cmd->request_exclusive(dev, PT_LDR_REQUEST_EXCLUSIVE_TIMEOUT);
  2612. if (ret < 0) {
  2613. pt_debug(dev, DL_ERROR,
  2614. "%s: Failed to aquire exclusive access\n", __func__);
  2615. update_fw_status = UPDATE_FW_EXCLUSIVE_ACCESS_ERROR;
  2616. goto exit;
  2617. }
  2618. _pt_pip2_update_bl_status(dev, 0, 1);
  2619. if (!fw) {
  2620. if (ld->pip2_load_builtin) {
  2621. pt_debug(dev, DL_ERROR,
  2622. "%s: No builtin firmware\n", __func__);
  2623. ld->builtin_bin_fw_status = -EINVAL;
  2624. pt_debug(dev, DL_ERROR, "%s: Exit BL\n", __func__);
  2625. _pt_pip2_update_bl_status(dev,
  2626. UPDATE_FW_NO_FW_PROVIDED, PT_NO_INC);
  2627. goto exit;
  2628. } else {
  2629. fw_img = kzalloc(PT_PIP2_MAX_FILE_SIZE, GFP_KERNEL);
  2630. us_fw_used = 1;
  2631. ret = cmd->nonhid_cmd->read_us_file(dev,
  2632. cd->pip2_us_file_path, fw_img, &fw_size);
  2633. if (ret) {
  2634. pt_debug(dev, DL_ERROR,
  2635. "%s: No firmware provided to load\n",
  2636. __func__);
  2637. pt_debug(dev, DL_ERROR, "%s: Exit BL\n",
  2638. __func__);
  2639. _pt_pip2_update_bl_status(dev,
  2640. UPDATE_FW_NO_FW_PROVIDED, PT_NO_INC);
  2641. goto exit;
  2642. }
  2643. }
  2644. } else {
  2645. fw_img = (u8 *)&(fw->data[0]);
  2646. fw_size = fw->size;
  2647. }
  2648. if (!fw_img || !fw_size) {
  2649. pt_debug(dev, DL_ERROR,
  2650. "%s: Invalid fw or file size=%d\n", __func__,
  2651. (int)fw_size);
  2652. _pt_pip2_update_bl_status(dev, UPDATE_FW_INVALID_FW_IMAGE,
  2653. PT_NO_INC);
  2654. goto exit;
  2655. }
  2656. if (ld->pip2_load_file_no == PIP2_FW_FILE) {
  2657. if (fw_img[0] >= (fw_size + 1)) {
  2658. pt_debug(dev, DL_ERROR,
  2659. "%s: Firmware format is invalid\n", __func__);
  2660. _pt_pip2_update_bl_status(dev,
  2661. UPDATE_FW_INVALID_FW_IMAGE, PT_NO_INC);
  2662. goto exit;
  2663. }
  2664. }
  2665. cd->fw_updating = true;
  2666. wake_up(&cd->wait_q);
  2667. _pt_pip2_update_bl_status(dev, 0, 1);
  2668. pt_debug(dev, DL_INFO,
  2669. "%s: Found file of size: %d bytes\n", __func__, (int)fw_size);
  2670. pm_runtime_get_sync(dev);
  2671. _pt_pip2_update_bl_status(dev, 0, 1);
  2672. /* Wait for completion of FW upgrade thread before continuing */
  2673. if (!ld->pip2_load_builtin)
  2674. init_completion(&pip2_data->pip2_fw_upgrade_complete);
  2675. _pt_pip2_update_bl_status(dev, 0, 1);
  2676. cmd->request_stop_wd(dev);
  2677. if (cd->flashless_dut) {
  2678. cd->bl_pip_ver_ready = false;
  2679. cd->app_pip_ver_ready = false;
  2680. }
  2681. /*
  2682. * 'mode' is used below, if DUT was already in BL before attempting to
  2683. * enter the BL, there was either no FW to run or the FW was corrupt
  2684. * so either way force a BL
  2685. */
  2686. ret = cmd->request_pip2_enter_bl(dev, &mode, NULL);
  2687. if (ret) {
  2688. pt_debug(dev, DL_ERROR, "%s: Failed to enter BL\n",
  2689. __func__);
  2690. _pt_pip2_update_bl_status(dev, UPDATE_FW_ENTER_BL_ERROR,
  2691. PT_NO_INC);
  2692. goto exit;
  2693. }
  2694. _pt_pip2_update_bl_status(dev, 0, 1);
  2695. /* Only compare FW ver or previous mode when doing a built-in upgrade */
  2696. if (ld->pip2_load_builtin) {
  2697. if (_pt_pip2_need_upgrade_due_to_fw_ver(dev, fw) ||
  2698. mode == PT_MODE_BOOTLOADER) {
  2699. _pt_pip2_update_bl_status(dev, 0, 1);
  2700. } else {
  2701. _pt_pip2_update_bl_status(dev,
  2702. UPDATE_FW_VERSION_ERROR, PT_NO_INC);
  2703. goto exit;
  2704. }
  2705. }
  2706. pt_debug(dev, DL_INFO, "%s OPEN File %d for write\n",
  2707. __func__, ld->pip2_load_file_no);
  2708. ret = cmd->nonhid_cmd->pip2_file_open(dev, ld->pip2_load_file_no);
  2709. if (ret < 0) {
  2710. pt_debug(dev, DL_ERROR, "%s Open file %d failed\n",
  2711. __func__, ld->pip2_load_file_no);
  2712. _pt_pip2_update_bl_status(dev, UPDATE_FW_FILE_OPEN_ERROR,
  2713. PT_NO_INC);
  2714. goto exit;
  2715. }
  2716. pip2_data->pip2_file_handle = ret;
  2717. _pt_pip2_update_bl_status(dev, 0, 1);
  2718. /* Regarding to TC3315, the size of RAM_FILE is less than fw image */
  2719. if (ld->pip2_load_file_no != PIP2_RAM_FILE) {
  2720. ret = cmd->nonhid_cmd->pip2_file_get_stats(dev,
  2721. ld->pip2_load_file_no, NULL, &max_file_size);
  2722. if (ret) {
  2723. pt_debug(dev, DL_ERROR,
  2724. "%s: Failed to get_file_state ret=%d\n",
  2725. __func__, ret);
  2726. goto exit_close_file;
  2727. }
  2728. if (fw_size > max_file_size) {
  2729. pt_debug(dev, DL_ERROR,
  2730. "%s: Firmware image(%d) is over size(%d)\n",
  2731. __func__, fw_size, max_file_size);
  2732. _pt_pip2_update_bl_status(dev,
  2733. UPDATE_FW_INVALID_FW_IMAGE, PT_NO_INC);
  2734. goto exit_close_file;
  2735. }
  2736. #ifdef TTDL_DIAGNOSTICS
  2737. /* Log the Flash part info */
  2738. if (cd->debug_level >= DL_DEBUG)
  2739. _pt_pip2_get_flash_info(dev, read_buf);
  2740. #endif
  2741. /* Erase file before loading */
  2742. ret = cmd->nonhid_cmd->pip2_file_erase(dev,
  2743. ld->pip2_load_file_no, &erase_status);
  2744. if (ret < 0) {
  2745. pt_debug(dev, DL_ERROR,
  2746. "%s: File erase failed rc=%d status=%d\n",
  2747. __func__, ret, erase_status);
  2748. _pt_pip2_update_bl_status(dev,
  2749. UPDATE_FW_ERASE_ERROR, PT_NO_INC);
  2750. goto exit_close_file;
  2751. }
  2752. _pt_pip2_update_bl_status(dev, 0, 5);
  2753. }
  2754. remain_bytes = fw_size;
  2755. buf[0] = pip2_data->pip2_file_handle;
  2756. pt_debug(dev, DL_WARN,
  2757. "%s: ATM - Writing %d bytes of firmware data now\n",
  2758. __func__, fw_size);
  2759. /*
  2760. * No IRQ function is used to BL to reduce BL time due to any IRQ
  2761. * latency.
  2762. */
  2763. if (cd->bl_with_no_int) {
  2764. pip2_send_cmd = cmd->nonhid_cmd->pip2_send_cmd_no_int;
  2765. disable_irq_nosync(cd->irq);
  2766. } else
  2767. pip2_send_cmd = cmd->nonhid_cmd->pip2_send_cmd;
  2768. /* Continue writing while data remains */
  2769. while (remain_bytes > packet_size) {
  2770. write_len = packet_size;
  2771. /* Don't update BL status on every pass */
  2772. if (remain_bytes % 2000 < packet_size) {
  2773. /* Calculate % complete for update_fw_status sysfs */
  2774. percent_cmplt = (fw_size - remain_bytes) *
  2775. 100 / fw_size;
  2776. if (percent_cmplt > 0 &&
  2777. percent_cmplt > UPDATE_FW_ACTIVE_90)
  2778. percent_cmplt = UPDATE_FW_ACTIVE_90;
  2779. _pt_pip2_update_bl_status(dev, percent_cmplt,
  2780. PT_NO_INC);
  2781. #ifdef TTDL_DIAGNOSTICS
  2782. pt_debug(dev, DL_INFO,
  2783. "Wrote %d bytes with %d bytes remaining\n",
  2784. fw_size - remain_bytes - write_len,
  2785. remain_bytes);
  2786. #endif
  2787. }
  2788. if (retry_packet > 0) {
  2789. #ifdef TTDL_DIAGNOSTICS
  2790. cd->bl_retry_packet_count++;
  2791. cmd->request_toggle_err_gpio(dev,
  2792. PT_ERR_GPIO_BL_RETRY_PACKET);
  2793. pt_debug(dev, DL_WARN,
  2794. "%s: === Retry Packet #%d ===\n",
  2795. __func__, retry_packet);
  2796. #endif
  2797. /* Get and log the last error(s) */
  2798. _pt_pip2_log_last_error(dev, read_buf);
  2799. }
  2800. memcpy(&buf[1], fw_img, write_len);
  2801. ret = pip2_send_cmd(dev,
  2802. PT_CORE_CMD_UNPROTECTED, PIP2_CMD_ID_FILE_WRITE,
  2803. buf, write_len + 1, read_buf, &actual_read_len);
  2804. status = read_buf[PIP2_RESP_STATUS_OFFSET];
  2805. /* Write cmd successful with a fail status */
  2806. if (!ret && status) {
  2807. /*
  2808. * The last time through the loop when remain_bytes =
  2809. * write_len, no partial payload will remain, the last
  2810. * successful write (when writing to RAM) will respond
  2811. * with EOF status, writing to FLASH will respond with a
  2812. * standard success status of 0x00
  2813. */
  2814. if ((ld->pip2_load_file_no == PIP2_RAM_FILE) &&
  2815. (status == PIP2_RSP_ERR_END_OF_FILE) &&
  2816. (remain_bytes == write_len)) {
  2817. pt_debug(dev, DL_WARN,
  2818. "%s Last write, ret = 0x%02x\n",
  2819. __func__, status);
  2820. /* Drop out of the while loop */
  2821. break;
  2822. }
  2823. _pt_pip2_update_bl_status(dev,
  2824. UPDATE_FW_WRITE_ERROR, PT_NO_INC);
  2825. pt_debug(dev, DL_ERROR,
  2826. "%s file write failure, status = 0x%02x\n",
  2827. __func__, status);
  2828. if (retry_packet >= 3) {
  2829. /* Tripple retry error - break */
  2830. remain_bytes = 0;
  2831. pt_debug(dev, DL_ERROR,
  2832. "%s %d - Packet status error - Break\n",
  2833. __func__, status);
  2834. } else {
  2835. retry_packet++;
  2836. }
  2837. } else if (ret) {
  2838. /* Packet write failed - retry 3x */
  2839. if (retry_packet >= 3) {
  2840. remain_bytes = 0;
  2841. pt_debug(dev, DL_ERROR,
  2842. "%s %d - Packet cmd error - Break\n",
  2843. __func__, ret);
  2844. }
  2845. retry_packet++;
  2846. } else {
  2847. /* Cmd success and status success */
  2848. retry_packet = 0;
  2849. }
  2850. if (retry_packet == 0) {
  2851. fw_img += write_len;
  2852. remain_bytes -= write_len;
  2853. }
  2854. }
  2855. /* Write the remaining bytes if any remain */
  2856. if (remain_bytes > 0 && retry_packet == 0) {
  2857. pt_debug(dev, DL_INFO,
  2858. "Write last %d bytes to File = 0x%02x\n",
  2859. remain_bytes, pip2_data->pip2_file_handle);
  2860. memcpy(&buf[1], fw_img, remain_bytes);
  2861. while (remain_bytes > 0 && retry_packet <= 3) {
  2862. ret = pip2_send_cmd(dev, PT_CORE_CMD_UNPROTECTED,
  2863. PIP2_CMD_ID_FILE_WRITE, buf, remain_bytes + 1,
  2864. read_buf, &actual_read_len);
  2865. status = read_buf[PIP2_RESP_STATUS_OFFSET];
  2866. if (ret || status) {
  2867. /*
  2868. * Any non zero status when writing to FLASH is
  2869. * an error. Only when writing to RAM, the last
  2870. * packet must respond with an EOF status
  2871. */
  2872. if ((ld->pip2_load_file_no >= PIP2_FW_FILE) ||
  2873. (ld->pip2_load_file_no == PIP2_RAM_FILE &&
  2874. status != PIP2_RSP_ERR_END_OF_FILE)) {
  2875. _pt_pip2_update_bl_status(dev,
  2876. UPDATE_FW_WRITE_ERROR,
  2877. PT_NO_INC);
  2878. pt_debug(dev, DL_ERROR,
  2879. "%s Write Fail-status=0x%02x\n",
  2880. __func__, status);
  2881. retry_packet++;
  2882. } else if (ld->pip2_load_file_no ==
  2883. PIP2_RAM_FILE &&
  2884. status == PIP2_RSP_ERR_END_OF_FILE) {
  2885. /* Special case EOF writing to SRAM */
  2886. remain_bytes = 0;
  2887. status = 0;
  2888. }
  2889. } else {
  2890. remain_bytes = 0;
  2891. }
  2892. }
  2893. }
  2894. if (cd->bl_with_no_int)
  2895. enable_irq(cd->irq);
  2896. if (remain_bytes == 0 && retry_packet == 0)
  2897. _pt_pip2_update_bl_status(dev, UPDATE_FW_ACTIVE_99, PT_NO_INC);
  2898. if (retry_packet >= 3) {
  2899. /* A packet write failure occurred 3x */
  2900. pt_debug(dev, DL_ERROR,
  2901. "%s: BL terminated due to consecutive write errors\n",
  2902. __func__);
  2903. _pt_pip2_update_bl_status(dev, UPDATE_FW_WRITE_ERROR,
  2904. PT_NO_INC);
  2905. } else if (status) {
  2906. ret = status;
  2907. pt_debug(dev, DL_ERROR,
  2908. "%s: File write failed with status=%d\n",
  2909. __func__, status);
  2910. _pt_pip2_update_bl_status(dev, UPDATE_FW_WRITE_ERROR,
  2911. PT_NO_INC);
  2912. } else
  2913. pt_debug(dev, DL_INFO,
  2914. "%s: BIN file write finished successfully\n", __func__);
  2915. ret = cmd->nonhid_cmd->pip2_file_close(dev, ld->pip2_load_file_no);
  2916. if (ret != ld->pip2_load_file_no) {
  2917. pt_debug(dev, DL_ERROR,
  2918. "%s file close failure\n", __func__);
  2919. _pt_pip2_update_bl_status(dev, UPDATE_FW_FILE_CLOSE_ERROR,
  2920. PT_NO_INC);
  2921. goto exit;
  2922. }
  2923. /* When updating non FW files, stay in BL */
  2924. if (ld->pip2_load_file_no >= PIP2_CONFIG_FILE)
  2925. goto exit;
  2926. if ((ld->pip2_load_file_no == PIP2_RAM_FILE) &&
  2927. (update_fw_status < UPDATE_FW_COMPLETE)) {
  2928. /* When writing to RAM don't reset, just launch application */
  2929. pt_debug(dev, DL_INFO,
  2930. "%s Sending execute command now...\n", __func__);
  2931. cd->startup_status = STARTUP_STATUS_START;
  2932. ret = cmd->nonhid_cmd->pip2_send_cmd(dev,
  2933. PT_CORE_CMD_UNPROTECTED, PIP2_CMD_ID_EXECUTE,
  2934. NULL, 0, read_buf, &actual_read_len);
  2935. status = read_buf[PIP2_RESP_STATUS_OFFSET];
  2936. if (ret || status) {
  2937. pt_debug(dev, DL_ERROR,
  2938. "%s Execute command failure\n", __func__);
  2939. _pt_pip2_update_bl_status(dev,
  2940. UPDATE_FW_EXECUTE_ERROR, PT_NO_INC);
  2941. goto exit;
  2942. }
  2943. } else if (ld->pip2_load_file_no == PIP2_FW_FILE &&
  2944. update_fw_status < UPDATE_FW_COMPLETE) {
  2945. pt_debug(dev, DL_INFO,
  2946. "%s Toggle TP_XRES now...\n", __func__);
  2947. cmd->request_reset(dev, PT_CORE_CMD_UNPROTECTED);
  2948. }
  2949. pt_debug(dev, DL_INFO, "%s: APP launched\n", __func__);
  2950. /* If any error occurred simply close the file and exit */
  2951. if (update_fw_status > UPDATE_FW_COMPLETE)
  2952. goto exit_close_file;
  2953. /* Wait for FW reset sentinel from reset or execute for up to 500ms */
  2954. t = wait_event_timeout(cd->wait_q,
  2955. (cd->startup_status >= STARTUP_STATUS_FW_RESET_SENTINEL),
  2956. msecs_to_jiffies(PT_BL_WAIT_FOR_SENTINEL));
  2957. if (IS_TMO(t)) {
  2958. pt_debug(dev, DL_WARN,
  2959. "%s: 0x%04X Timeout waiting for FW sentinel",
  2960. __func__, cd->startup_status);
  2961. }
  2962. /* Double verify DUT is alive and well in Application mode */
  2963. if (cd->startup_status & STARTUP_STATUS_FW_RESET_SENTINEL) {
  2964. ret = cmd->request_pip2_get_mode_sysmode(dev,
  2965. PT_CORE_CMD_UNPROTECTED, &mode, NULL);
  2966. pt_debug(dev, DL_WARN, "%s: mode = %d (Expected 2)",
  2967. __func__, mode);
  2968. if (mode != PT_MODE_OPERATIONAL) {
  2969. pt_debug(dev, DL_ERROR,
  2970. "%s ERROR: Not in App mode as expected\n",
  2971. __func__);
  2972. _pt_pip2_update_bl_status(dev, UPDATE_FW_MODE_ERROR,
  2973. PT_NO_INC);
  2974. goto exit;
  2975. }
  2976. } else {
  2977. pt_debug(dev, DL_ERROR, "%s: FW sentinel not seen 0x%04X\n",
  2978. __func__, cd->startup_status);
  2979. _pt_pip2_log_last_error(dev, read_buf);
  2980. _pt_pip2_update_bl_status(dev, UPDATE_FW_SENTINEL_NOT_SEEN,
  2981. PT_NO_INC);
  2982. goto exit;
  2983. }
  2984. /* On a Flashless DUT save or restore the CAL data */
  2985. if (cd->cal_cache_in_host == PT_FEATURE_ENABLE)
  2986. _pt_calibrate_flashless_dut(dev);
  2987. /* Subscribe calibration task if calibration flag is set */
  2988. if (ld->loader_pdata
  2989. && (ld->loader_pdata->flags
  2990. & PT_LOADER_FLAG_CALIBRATE_AFTER_FW_UPGRADE)
  2991. && (cd->cal_cache_in_host == PT_FEATURE_DISABLE)) {
  2992. #if (KERNEL_VERSION(3, 13, 0) <= LINUX_VERSION_CODE)
  2993. reinit_completion(&ld->calibration_complete);
  2994. #else
  2995. INIT_COMPLETION(ld->calibration_complete);
  2996. #endif
  2997. /* set up call back for startup */
  2998. pt_debug(dev, DL_INFO, "%s: Adding callback for calibration\n",
  2999. __func__);
  3000. ret = cmd->subscribe_attention(dev, PT_ATTEN_STARTUP,
  3001. PT_LOADER_NAME, pt_calibration_attention, 0);
  3002. if (ret) {
  3003. pt_debug(dev, DL_ERROR,
  3004. "%s: Failed adding callback for calibration\n",
  3005. __func__);
  3006. ret = 0;
  3007. } else
  3008. wait_for_calibration_complete = true;
  3009. }
  3010. pt_debug(dev, DL_INFO, "%s: == PIP2 FW upgrade finished ==\n",
  3011. __func__);
  3012. goto exit;
  3013. exit_close_file:
  3014. ret = cmd->nonhid_cmd->pip2_file_close(dev, ld->pip2_load_file_no);
  3015. if (ret < 0) {
  3016. pt_debug(dev, DL_ERROR,
  3017. "%s file close failure\n", __func__);
  3018. _pt_pip2_update_bl_status(dev, UPDATE_FW_FILE_CLOSE_ERROR,
  3019. PT_NO_INC);
  3020. }
  3021. exit:
  3022. cd->fw_updating = false;
  3023. if (us_fw_used)
  3024. kfree(fw_img);
  3025. if (ld->pip2_load_file_no > PIP2_FW_FILE)
  3026. goto exit_staying_in_bl;
  3027. cmd->release_exclusive(dev);
  3028. pm_runtime_put_sync(dev);
  3029. if (fw)
  3030. release_firmware(fw);
  3031. /*
  3032. * For built-in FW update, it should not warn builtin_bin_fw_status
  3033. * for each bootup since update_fw_status would be
  3034. * UPDATE_FW_VERSION_ERROR in most situations because firmware
  3035. * should have been up to date.
  3036. */
  3037. if (ld->pip2_load_builtin) {
  3038. if ((update_fw_status == UPDATE_FW_ACTIVE_99) ||
  3039. (update_fw_status == UPDATE_FW_VERSION_ERROR))
  3040. ld->builtin_bin_fw_status = 0;
  3041. else
  3042. ld->builtin_bin_fw_status = -EINVAL;
  3043. }
  3044. if ((update_fw_status == UPDATE_FW_ACTIVE_99) ||
  3045. (update_fw_status == UPDATE_FW_VERSION_ERROR)) {
  3046. pt_debug(dev, DL_WARN, "%s: Queue ENUM\n", __func__);
  3047. cmd->request_enum(dev, true);
  3048. }
  3049. if (update_fw_status < UPDATE_FW_COMPLETE)
  3050. _pt_pip2_update_bl_status(dev, UPDATE_FW_COMPLETE, PT_NO_INC);
  3051. if (wait_for_calibration_complete)
  3052. wait_for_completion(&ld->calibration_complete);
  3053. pt_debug(dev, DL_INFO, "%s: Starting watchdog\n", __func__);
  3054. ret = cmd->request_start_wd(dev);
  3055. /*
  3056. * When in No-Flash mode allow auto BL after any BL.
  3057. * There is an issue where setting flashless mode via drv_debug
  3058. * can happen in the middle of pt_pip2_enter_bl() which will revert
  3059. * the flashless_auto_bl value back to what it was when the function
  3060. * started.
  3061. */
  3062. if (cd->flashless_dut)
  3063. cd->flashless_auto_bl = PT_ALLOW_AUTO_BL;
  3064. return;
  3065. exit_staying_in_bl:
  3066. /* When updating a non FW file, a restart is not wanted. Stay in BL */
  3067. _pt_pip2_update_bl_status(dev, UPDATE_FW_COMPLETE, PT_NO_INC);
  3068. cmd->release_exclusive(dev);
  3069. pm_runtime_put_sync(dev);
  3070. if (fw)
  3071. release_firmware(fw);
  3072. }
  3073. #define PIP2_MAX_FILE_NAMES 3
  3074. /*******************************************************************************
  3075. * FUNCTION: pt_pip2_upgrade_firmware_from_builtin
  3076. *
  3077. * SUMMARY: Bootload the DUT with a built in firmware binary image.
  3078. * Load either a SRAM image "ttdl_fw_RAM.bin" or a FLASH image
  3079. * "ttdl_fw.bin" with the priority being the SRAM image.
  3080. *
  3081. * PARAMETERS:
  3082. * *dev - pointer to the device structure
  3083. ******************************************************************************/
  3084. static int pt_pip2_upgrade_firmware_from_builtin(struct device *dev)
  3085. {
  3086. struct pt_loader_data *ld = pt_get_loader_data(dev);
  3087. struct pt_core_data *cd = dev_get_drvdata(dev);
  3088. const struct firmware *fw_entry = NULL;
  3089. int retval;
  3090. int rc = 0;
  3091. int read_size = 16;
  3092. u8 image[16];
  3093. int index = 0;
  3094. int file_count = 0;
  3095. char *filename[PIP2_MAX_FILE_NAMES];
  3096. /*
  3097. * Load the supported filenames in the correct search order
  3098. * 0 - "tt_fw<_PIDX>.bin"
  3099. * 1 - "XXXX_tt_fw<_PIDX>.bin" where XXXX = Silicon ID
  3100. * 2 - "tt_fw.bin", default FW name
  3101. */
  3102. filename[file_count++] = generate_firmware_filename(dev);
  3103. filename[file_count++] = generate_silicon_id_firmware_filename(dev);
  3104. if (pt_get_panel_id(dev) != PANEL_ID_NOT_ENABLED) {
  3105. filename[file_count] =
  3106. kzalloc(sizeof(PT_FW_FILE_NAME), GFP_KERNEL);
  3107. memcpy(filename[file_count++], PT_FW_FILE_NAME,
  3108. sizeof(PT_FW_FILE_NAME));
  3109. }
  3110. for (index = 0; index < file_count; index++) {
  3111. if (!filename[index])
  3112. return -ENOMEM;
  3113. }
  3114. if (cd->flashless_dut) {
  3115. pt_debug(dev, DL_INFO,
  3116. "%s: Proceed to BL flashless DUT\n", __func__);
  3117. ld->pip2_load_file_no = PIP2_RAM_FILE;
  3118. if (cd->pip2_us_file_path[0] == '\0') {
  3119. ld->pip2_load_builtin = true;
  3120. pt_debug(dev, DL_WARN,
  3121. "%s: US Path not defined, BL from built-in\n",
  3122. __func__);
  3123. } else {
  3124. /* Read a few bytes to see if file exists */
  3125. rc = cmd->nonhid_cmd->read_us_file(dev,
  3126. cd->pip2_us_file_path, image, &read_size);
  3127. if (!rc) {
  3128. ld->pip2_load_builtin = false;
  3129. pt_debug(dev, DL_WARN,
  3130. "%s: %s Found, BL from US\n",
  3131. __func__, cd->pip2_us_file_path);
  3132. goto ready;
  3133. } else {
  3134. ld->pip2_load_builtin = true;
  3135. pt_debug(dev, DL_WARN,
  3136. "%s: ATM - %s NOT Found, BL from built-in\n",
  3137. __func__, cd->pip2_us_file_path);
  3138. }
  3139. }
  3140. } else {
  3141. ld->pip2_load_file_no = PIP2_FW_FILE;
  3142. ld->pip2_load_builtin = true;
  3143. }
  3144. /* Look for any FW file name match and request the FW */
  3145. mutex_lock(&cd->firmware_class_lock);
  3146. index = 0;
  3147. while (index < file_count) {
  3148. pt_debug(dev, DL_INFO, "%s: Request FW class file: %s\n",
  3149. __func__, filename[index]);
  3150. retval = request_firmware_direct(&fw_entry,
  3151. filename[index], dev);
  3152. if (retval < 0) {
  3153. pt_debug(dev, DL_WARN, "%s: ATM - Fail request FW %s load\n",
  3154. __func__, filename[index]);
  3155. } else {
  3156. pt_debug(dev, DL_INFO, "%s: FW %s class file loading\n",
  3157. __func__, filename[index]);
  3158. break;
  3159. }
  3160. index++;
  3161. }
  3162. /* No matching file names found */
  3163. if (index == file_count) {
  3164. pt_debug(dev, DL_WARN, "%s: No FW is found\n", __func__);
  3165. goto exit;
  3166. }
  3167. ready:
  3168. _pt_pip2_firmware_cont(fw_entry, dev);
  3169. retval = ld->builtin_bin_fw_status;
  3170. exit:
  3171. mutex_unlock(&cd->firmware_class_lock);
  3172. index = 0;
  3173. while (index < file_count)
  3174. kfree(filename[index++]);
  3175. return retval;
  3176. }
  3177. /*******************************************************************************
  3178. * FUNCTION: pt_pip2_create_fw_class
  3179. *
  3180. * SUMMARY: Create the firmware class but don't actually laod any FW to the
  3181. * DUT. This creates all the sysfs nodes needed for a user to bootload
  3182. * the DUT with their own bin file.
  3183. *
  3184. * PARAMETERS:
  3185. * *pip2_data - pointer to the PIP2 loader data structure
  3186. ******************************************************************************/
  3187. static int pt_pip2_create_fw_class(struct pip2_loader_data *pip2_data)
  3188. {
  3189. int ret = 0;
  3190. struct device *dev = pip2_data->dev;
  3191. struct pt_loader_data *ld = pt_get_loader_data(dev);
  3192. /*
  3193. * The file name dev_name(dev) is tied with bus name and usually
  3194. * it is "x-0024". This name is wanted to keep consistency
  3195. * (e.g. /sys/class/firmware/x-0024/) for the path of fw class
  3196. * nodes with different kernel release. Also it is an invalid bin
  3197. * file name used intentionally because request_firmware_nowait
  3198. * will not find the file which is what we want and then simply
  3199. * create the fw class nodes.
  3200. */
  3201. ld->pip2_load_builtin = false;
  3202. pt_debug(dev, DL_INFO, "%s: Request FW Class", __func__);
  3203. ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_NOHOTPLUG,
  3204. dev_name(dev), dev, GFP_KERNEL, dev,
  3205. _pt_pip2_firmware_cont);
  3206. if (ret) {
  3207. pt_debug(dev, DL_ERROR,
  3208. "%s: ERROR requesting firmware class\n", __func__);
  3209. }
  3210. return ret;
  3211. }
  3212. /*******************************************************************************
  3213. * FUNCTION: pt_pip2_bl_from_file_work
  3214. *
  3215. * SUMMARY: The work function to schedule the BL work for PIP2 only.
  3216. *
  3217. * PARAMETERS:
  3218. * *bl_from_file - pointer to work_struct structure
  3219. ******************************************************************************/
  3220. static void pt_pip2_bl_from_file_work(struct work_struct *pip2_bl_from_file)
  3221. {
  3222. struct pt_loader_data *ld = container_of(pip2_bl_from_file,
  3223. struct pt_loader_data, pip2_bl_from_file);
  3224. struct device *dev = ld->dev;
  3225. const struct firmware *fw_entry = NULL;
  3226. _pt_pip2_firmware_cont(fw_entry, dev);
  3227. }
  3228. /*******************************************************************************
  3229. * FUNCTION: pt_bl_from_file_work
  3230. *
  3231. * SUMMARY: The work function to schedule the BL work for PIP2 or PIP1
  3232. * according to the active_dut_generation in core data.
  3233. *
  3234. * PARAMETERS:
  3235. * *bl_from_file - pointer to work_struct structure
  3236. ******************************************************************************/
  3237. static void pt_bl_from_file_work(struct work_struct *bl_from_file)
  3238. {
  3239. struct pt_loader_data *ld = container_of(bl_from_file,
  3240. struct pt_loader_data, bl_from_file);
  3241. struct device *dev = ld->dev;
  3242. const struct firmware *fw_entry = NULL;
  3243. u8 dut_gen = cmd->request_dut_generation(dev);
  3244. if (dut_gen == DUT_PIP2_CAPABLE)
  3245. _pt_pip2_firmware_cont(fw_entry, dev);
  3246. else if (dut_gen == DUT_PIP1_ONLY)
  3247. _pt_pip1_bl_from_file(dev);
  3248. }
  3249. /*******************************************************************************
  3250. * FUNCTION: pt_pip2_bl_from_file_show
  3251. *
  3252. * SUMMARY: The show method for the "pip2_bl_from_file" sysfs node. The
  3253. * scheduled work will perform PIP2 BL.
  3254. *
  3255. * NOTE: Since this function doesn't set pip2_load_file_no, it will use the
  3256. * value what has been stored there.
  3257. *
  3258. * PARAMETERS:
  3259. * *dev - pointer to device structure
  3260. * *attr - pointer to device attributes structure
  3261. * *buf - pointer to print output buffer
  3262. ******************************************************************************/
  3263. static ssize_t pt_pip2_bl_from_file_show(struct device *dev,
  3264. struct device_attribute *attr, char *buf)
  3265. {
  3266. struct pt_loader_data *ld = pt_get_loader_data(dev);
  3267. struct pt_core_data *cd = dev_get_drvdata(dev);
  3268. int rc = 0;
  3269. int read_size = 2;
  3270. u8 image[2];
  3271. mutex_lock(&cd->firmware_class_lock);
  3272. ld->pip2_load_builtin = false;
  3273. mutex_unlock(&cd->firmware_class_lock);
  3274. /* Read a few bytes to see if file exists */
  3275. rc = cmd->nonhid_cmd->read_us_file(dev,
  3276. cd->pip2_us_file_path, image, &read_size);
  3277. if (!rc) {
  3278. schedule_work(&ld->pip2_bl_from_file);
  3279. return scnprintf(buf, PT_MAX_PRBUF_SIZE,
  3280. "Status: %d\n"
  3281. "BL File: %s\n",
  3282. rc, cd->pip2_us_file_path);
  3283. } else {
  3284. return scnprintf(buf, PT_MAX_PRBUF_SIZE,
  3285. "Status: %d\n"
  3286. "BL File: '%s' - Does not exist\n",
  3287. rc, cd->pip2_us_file_path);
  3288. }
  3289. }
  3290. /*******************************************************************************
  3291. * FUNCTION: pt_bl_from_file_show
  3292. *
  3293. * SUMMARY: The show method for the "pt_bl_from_file" sysfs node. The scheduled
  3294. * work can perform either PIP1 BL and PIP2 BL according to the
  3295. * active_dut_generation of core data.
  3296. *
  3297. * NOTE: Since this function doesn't set pip2_load_file_no, it will use the
  3298. * value what has been stored there.
  3299. *
  3300. * PARAMETERS:
  3301. * *dev - pointer to device structure
  3302. * *attr - pointer to device attributes structure
  3303. * *buf - pointer to print output buffer
  3304. ******************************************************************************/
  3305. static ssize_t pt_bl_from_file_show(struct device *dev,
  3306. struct device_attribute *attr, char *buf)
  3307. {
  3308. struct pt_loader_data *ld = pt_get_loader_data(dev);
  3309. struct pt_core_data *cd = dev_get_drvdata(dev);
  3310. int rc = 0;
  3311. int read_size = 2;
  3312. u8 dut_gen = cmd->request_dut_generation(dev);
  3313. u8 image[2];
  3314. mutex_lock(&cd->firmware_class_lock);
  3315. ld->pip2_load_builtin = false;
  3316. mutex_unlock(&cd->firmware_class_lock);
  3317. /* Read a few bytes to see if file exists */
  3318. rc = cmd->nonhid_cmd->read_us_file(dev,
  3319. cd->pip2_us_file_path, image, &read_size);
  3320. if (dut_gen == DUT_UNKNOWN) {
  3321. rc = -EINVAL;
  3322. return scnprintf(buf, PT_MAX_PRBUF_SIZE,
  3323. "Status: %d\n"
  3324. "BL File: '%s' - Failed, DUT Generation could not be determined\n",
  3325. rc, cd->pip2_us_file_path);
  3326. } else if (!rc) {
  3327. schedule_work(&ld->bl_from_file);
  3328. return scnprintf(buf, PT_MAX_PRBUF_SIZE,
  3329. "Status: %d\n"
  3330. "BL File: %s\n",
  3331. rc, cd->pip2_us_file_path);
  3332. } else {
  3333. return scnprintf(buf, PT_MAX_PRBUF_SIZE,
  3334. "Status: %d\n"
  3335. "BL File: '%s' - Does not exist\n",
  3336. rc, cd->pip2_us_file_path);
  3337. }
  3338. }
  3339. /*******************************************************************************
  3340. * FUNCTION: pt_pip2_bl_from_file_store
  3341. *
  3342. * SUMMARY: The store method for the "pip2_bl_from_file" and "pt_bl_from_file"
  3343. * sysfs node. Used to allow any file path[necessary] and file_no[optional] to
  3344. * be used to BL, for example: "echo /data/pt_fw 1 > pip2_bl_from_file", and
  3345. * do the "cat" will perform FW loader process.
  3346. *
  3347. * NOTE: the last char of file path in buf which is a '\n' is not copied.
  3348. * NOTE: the default file_no is PIP2_RAM_FILE.
  3349. *
  3350. * PARAMETERS:
  3351. * *dev - pointer to device structure
  3352. * *attr - pointer to device attributes
  3353. * *buf - pointer to output buffer
  3354. * size - size of data in buffer
  3355. ******************************************************************************/
  3356. static ssize_t pt_pip2_bl_from_file_store(struct device *dev,
  3357. struct device_attribute *attr, const char *buf, size_t size)
  3358. {
  3359. struct pt_loader_data *ld = pt_get_loader_data(dev);
  3360. struct pt_core_data *cd = dev_get_drvdata(dev);
  3361. const char *deli_space = " ", *deli_comma = ",";
  3362. char name_space[PT_MAX_PATH_SIZE];
  3363. char *ptr_left = NULL, *ptr_right = name_space;
  3364. u8 file_no = PIP2_RAM_FILE;
  3365. u32 input_data[2];
  3366. int length;
  3367. bool file_no_set = false;
  3368. memset(name_space, 0, PT_MAX_PATH_SIZE);
  3369. memset(cd->pip2_us_file_path, 0, PT_MAX_PATH_SIZE);
  3370. if (size <= PT_MAX_PATH_SIZE) {
  3371. memcpy(name_space, buf, size);
  3372. ptr_left = strsep(&ptr_right, deli_space);
  3373. if (ptr_right == NULL) {
  3374. ptr_right = name_space;
  3375. ptr_left = strsep(&ptr_right, deli_comma);
  3376. }
  3377. if (ptr_right != NULL) {
  3378. length = cmd->parse_sysfs_input(
  3379. dev, ptr_right, strlen(ptr_right), input_data,
  3380. ARRAY_SIZE(input_data));
  3381. if (length <= 0) {
  3382. pt_debug(dev, DL_ERROR,
  3383. "%s: Input format error!\n", __func__);
  3384. return -EINVAL;
  3385. }
  3386. file_no_set = true;
  3387. file_no = input_data[0];
  3388. }
  3389. pt_debug(dev, DL_WARN, "%s:Path=%s, File_no=%s(%d)\n", __func__,
  3390. ptr_left, ptr_right, file_no);
  3391. if ((file_no_set) &&
  3392. ((file_no < PIP2_RAM_FILE) || (file_no > PIP2_FILE_MAX))) {
  3393. pt_debug(dev, DL_WARN, "%s:Invalid File_no = %d\n",
  3394. __func__, file_no);
  3395. return -EINVAL;
  3396. }
  3397. mutex_lock(&cd->firmware_class_lock);
  3398. ld->pip2_load_file_no = file_no;
  3399. mutex_unlock(&cd->firmware_class_lock);
  3400. if (ptr_left[strlen(ptr_left) - 1] == '\n')
  3401. memcpy(cd->pip2_us_file_path, ptr_left,
  3402. strlen(ptr_left) - 1);
  3403. else
  3404. memcpy(cd->pip2_us_file_path, ptr_left,
  3405. strlen(ptr_left));
  3406. }
  3407. return size;
  3408. }
  3409. static DEVICE_ATTR(pip2_bl_from_file, 0644,
  3410. pt_pip2_bl_from_file_show, pt_pip2_bl_from_file_store);
  3411. static DEVICE_ATTR(pt_bl_from_file, 0644,
  3412. pt_bl_from_file_show, pt_pip2_bl_from_file_store);
  3413. /*******************************************************************************
  3414. * FUNCTION: pt_pip2_manual_upgrade_store
  3415. *
  3416. * SUMMARY: Store method for the pip2_manual_upgrade sysfs node. Allows
  3417. * sysfs control of bootloading a new FW image to FLASH.
  3418. *
  3419. * PARAMETERS:
  3420. * *dev - pointer to device structure
  3421. * *attr - pointer to device attributes
  3422. * *buf - pointer to output buffer
  3423. * size - size of data in buffer
  3424. ******************************************************************************/
  3425. static ssize_t pt_pip2_manual_upgrade_store(struct device *dev,
  3426. struct device_attribute *attr, const char *buf, size_t size)
  3427. {
  3428. struct pt_loader_data *ld = pt_get_loader_data(dev);
  3429. u32 input_data[2] = {0};
  3430. int length;
  3431. int rc = 0;
  3432. length = cmd->parse_sysfs_input(dev, buf, size, input_data,
  3433. ARRAY_SIZE(input_data));
  3434. if (length != 1) {
  3435. pt_debug(dev, DL_WARN, "%s: Invalid number of arguments\n",
  3436. __func__);
  3437. rc = -EINVAL;
  3438. goto exit;
  3439. }
  3440. if (input_data[0] < 0 || input_data[0] > 1) {
  3441. pt_debug(dev, DL_WARN, "%s: Invalid arguments\n", __func__);
  3442. rc = -EINVAL;
  3443. goto exit;
  3444. }
  3445. _pt_pip2_update_bl_status(dev, UPDATE_FW_IDLE, PT_NO_INC);
  3446. if (ld->is_manual_upgrade_enabled) {
  3447. pt_debug(dev, DL_ERROR,
  3448. "%s: ERROR - Manual upgrade busy\n", __func__);
  3449. rc = -EBUSY;
  3450. goto exit;
  3451. }
  3452. ld->pip2_load_file_no = PIP2_FW_FILE;
  3453. pt_debug(dev, DL_DEBUG, "%s: ATM - File number is %d\n",
  3454. __func__, ld->pip2_load_file_no);
  3455. ld->is_manual_upgrade_enabled = 1;
  3456. rc = pt_pip2_create_fw_class(ld->pip2_data);
  3457. ld->is_manual_upgrade_enabled = 0;
  3458. if (rc < 0)
  3459. pt_debug(dev, DL_ERROR,
  3460. "%s: ERROR - FLASH Upgrade failed\n", __func__);
  3461. exit:
  3462. if (rc)
  3463. return rc;
  3464. return size;
  3465. }
  3466. static DEVICE_ATTR(pip2_manual_upgrade, 0200,
  3467. NULL, pt_pip2_manual_upgrade_store);
  3468. /*******************************************************************************
  3469. * FUNCTION: pt_pip2_manual_ram_upgrade_store
  3470. *
  3471. * SUMMARY: Store method for the pip2_manual_ram_upgrade sysfs node. Allows
  3472. * sysfs control of bootloading a new FW image to SRAM.
  3473. *
  3474. * PARAMETERS:
  3475. * *dev - pointer to device structure
  3476. * *attr - pointer to device attributes
  3477. * *buf - pointer to output buffer
  3478. * size - size of data in buffer
  3479. ******************************************************************************/
  3480. static ssize_t pt_pip2_manual_ram_upgrade_store(struct device *dev,
  3481. struct device_attribute *attr, const char *buf, size_t size)
  3482. {
  3483. struct pt_loader_data *ld = pt_get_loader_data(dev);
  3484. u32 input_data[2] = {0};
  3485. int length;
  3486. int rc = 0;
  3487. length = cmd->parse_sysfs_input(dev, buf, size, input_data,
  3488. ARRAY_SIZE(input_data));
  3489. if (length != 1) {
  3490. pt_debug(dev, DL_WARN, "%s: Invalid number of arguments\n",
  3491. __func__);
  3492. rc = -EINVAL;
  3493. goto exit;
  3494. }
  3495. if (input_data[0] < 0 || input_data[0] > 1) {
  3496. pt_debug(dev, DL_WARN, "%s: Invalid arguments\n", __func__);
  3497. rc = -EINVAL;
  3498. goto exit;
  3499. }
  3500. _pt_pip2_update_bl_status(dev, UPDATE_FW_IDLE, PT_NO_INC);
  3501. if (ld->is_manual_upgrade_enabled) {
  3502. pt_debug(dev, DL_ERROR,
  3503. "%s: ERROR - Manual upgrade busy\n", __func__);
  3504. rc = -EBUSY;
  3505. goto exit;
  3506. }
  3507. ld->pip2_load_file_no = PIP2_RAM_FILE;
  3508. pt_debug(dev, DL_DEBUG, "%s: ATM - File number is %d\n",
  3509. __func__, ld->pip2_load_file_no);
  3510. ld->is_manual_upgrade_enabled = 1;
  3511. rc = pt_pip2_create_fw_class(ld->pip2_data);
  3512. ld->is_manual_upgrade_enabled = 0;
  3513. if (rc < 0)
  3514. pt_debug(dev, DL_ERROR,
  3515. "%s: ERROR - RAM Upgrade failed\n", __func__);
  3516. exit:
  3517. if (rc)
  3518. return rc;
  3519. return size;
  3520. }
  3521. static DEVICE_ATTR(pip2_manual_ram_upgrade, 0200,
  3522. NULL, pt_pip2_manual_ram_upgrade_store);
  3523. /*******************************************************************************
  3524. * FUNCTION: pt_pip2_file_write_store
  3525. *
  3526. * SUMMARY: Store method for the pip2_file_write sysfs node. Allows
  3527. * sysfs control to "load" data into any file.
  3528. *
  3529. * PARAMETERS:
  3530. * *dev - pointer to device structure
  3531. * *attr - pointer to device attributes
  3532. * *buf - pointer to output buffer
  3533. * size - size of data in buffer
  3534. ******************************************************************************/
  3535. static ssize_t pt_pip2_file_write_store(struct device *dev,
  3536. struct device_attribute *attr, const char *buf, size_t size)
  3537. {
  3538. struct pt_loader_data *ld = pt_get_loader_data(dev);
  3539. int rc;
  3540. u32 input_data[3];
  3541. int length;
  3542. if (ld->is_manual_upgrade_enabled) {
  3543. pt_debug(dev, DL_ERROR,
  3544. "%s: ERROR - Manual upgrade busy\n", __func__);
  3545. rc = -EBUSY;
  3546. goto exit;
  3547. }
  3548. length = cmd->parse_sysfs_input(dev, buf, size, input_data,
  3549. ARRAY_SIZE(input_data));
  3550. if (length <= 0 || length > 2) {
  3551. pt_debug(dev, DL_ERROR, "%s: Invalid number of arguments\n",
  3552. __func__);
  3553. ld->pip2_file_data.para_num = 0;
  3554. rc = -EINVAL;
  3555. goto exit;
  3556. }
  3557. if (input_data[0] < PIP2_FW_FILE || input_data[0] > PIP2_FILE_MAX) {
  3558. pt_debug(dev, DL_ERROR, "%s: Invalid file handle\n", __func__);
  3559. ld->pip2_file_data.para_num = 0;
  3560. rc = -EINVAL;
  3561. goto exit;
  3562. }
  3563. ld->pip2_load_file_no = input_data[0];
  3564. if (length == 2)
  3565. ld->pip2_file_data.file_offset = input_data[1];
  3566. ld->is_manual_upgrade_enabled = 1;
  3567. rc = pt_pip2_create_fw_class(ld->pip2_data);
  3568. ld->is_manual_upgrade_enabled = 0;
  3569. if (rc < 0)
  3570. pt_debug(dev, DL_ERROR,
  3571. "%s: ERROR - RAM Upgrade failed\n", __func__);
  3572. exit:
  3573. if (rc)
  3574. return rc;
  3575. return size;
  3576. }
  3577. static DEVICE_ATTR(pip2_file_write, 0200, NULL, pt_pip2_file_write_store);
  3578. /*******************************************************************************
  3579. * FUNCTION: pt_update_fw_store
  3580. *
  3581. * SUMMARY: Store method for the update_fw sysfs node. This node is required
  3582. * by ChromeOS to first determine if loading is available and then perform
  3583. * the loading if required. This function is simply a wrapper to call:
  3584. * pt_pip2_manual_upgrade_store - for the TC3XXX or TT7XXX parts
  3585. * pt_manual_upgrade_store - for the legacy Gen5/6 devices.
  3586. *
  3587. * PARAMETERS:
  3588. * *dev - pointer to device structure
  3589. * *attr - pointer to device attributes
  3590. * *buf - pointer to output buffer
  3591. * size - size of data in buffer
  3592. ******************************************************************************/
  3593. static ssize_t pt_update_fw_store(struct device *dev,
  3594. struct device_attribute *attr, const char *buf, size_t size)
  3595. {
  3596. u8 dut_gen = cmd->request_dut_generation(dev);
  3597. if (dut_gen == DUT_PIP2_CAPABLE)
  3598. size = pt_pip2_manual_upgrade_store(dev, attr, buf, size);
  3599. else if (dut_gen == DUT_PIP1_ONLY)
  3600. size = pt_manual_upgrade_store(dev, attr, buf, size);
  3601. return size;
  3602. }
  3603. static DEVICE_ATTR(update_fw, 0200, NULL, pt_update_fw_store);
  3604. #endif /* CONFIG_TOUCHSCREEN_PARADE_BINARY_FW_UPGRADE */
  3605. #ifdef TTDL_DIAGNOSTICS
  3606. /*******************************************************************************
  3607. * FUNCTION: pt_pip2_file_read_show
  3608. *
  3609. * SUMMARY: The read method for the pip2_file_read sysfs node. Allows to
  3610. * perform flash read action according to stored value. This function will
  3611. * re-enter always until it returns:
  3612. * 0: No data to be written to sysfs node
  3613. * <0: Error happens
  3614. * (For kernel version large than 3.11(not tested), if the function returns
  3615. * non-zero value in previous chunk, to return 0 once can not stop re-enter.
  3616. * It needs one more time to stop read action by returned value <= 0. But for
  3617. * older version, read action will stop when returned value <= 0 once).
  3618. *
  3619. * NOTE: Up to PIP2_FILE_WRITE_LEN_PER_PACKET(245) bytes of data are read for
  3620. * each enter. When last package is read, pip2_file_data.para_num is assigned
  3621. * as negatie value(-1), then next enter can return 0 to indicate the read
  3622. * method can be finished.
  3623. *
  3624. * RETURN: Size of data written to sysfs node
  3625. *
  3626. * PARAMETERS:
  3627. * *filp - pointer to file structure
  3628. * *kobj - pointer to kobject structure
  3629. * *bin_attr - pointer to bin_attribute structure
  3630. * buf - pointer to cmd input buffer
  3631. * offset - offset index to store input buffer
  3632. * count - size of data in buffer
  3633. ******************************************************************************/
  3634. static ssize_t pt_pip2_file_read_show(struct file *filp,
  3635. struct kobject *kobj, struct bin_attribute *bin_attr,
  3636. char *buf, loff_t offset, size_t count)
  3637. {
  3638. struct device *dev = container_of(kobj, struct device, kobj);
  3639. struct pt_loader_data *ld = pt_get_loader_data(dev);
  3640. struct pt_core_data *cd = dev_get_drvdata(dev);
  3641. int rc = 0;
  3642. u8 file_handle = ld->pip2_file_data.file_handle;
  3643. u8 *pr_buf = ld->pip2_file_data.file_print_buf;
  3644. int print_idx = 0, read_size = 0, i;
  3645. u8 read_buf[PT_MAX_PIP2_MSG_SIZE];
  3646. u8 read_len;
  3647. u32 address, file_size;
  3648. if (ld->pip2_file_data.file_print_left) {
  3649. pt_debug(dev, DL_INFO, "%s: print left=%d, count=%zu\n",
  3650. __func__, ld->pip2_file_data.file_print_left, count);
  3651. print_idx = ld->pip2_file_data.file_print_left;
  3652. if (count < print_idx) {
  3653. memcpy(buf, pr_buf, count);
  3654. ld->pip2_file_data.file_print_left = print_idx - count;
  3655. for (i = 0; i < ld->pip2_file_data.file_print_left; i++)
  3656. pr_buf[i] = pr_buf[i+count];
  3657. print_idx = count;
  3658. } else {
  3659. memcpy(buf, pr_buf, print_idx);
  3660. ld->pip2_file_data.file_print_left = 0;
  3661. }
  3662. return print_idx;
  3663. }
  3664. if (ld->pip2_file_data.para_num == 0) {
  3665. /*
  3666. * When offset != 0, it means the extra call for splice out,
  3667. * don't need a warning.
  3668. */
  3669. if (offset != 0)
  3670. return 0;
  3671. print_idx += scnprintf(buf, count, "Status: %d\n"
  3672. "No input!\n", -EINVAL);
  3673. pt_debug(dev, DL_ERROR, "%s: Invalid para_num = %d!\n",
  3674. __func__, ld->pip2_file_data.para_num);
  3675. return print_idx;
  3676. } else if (ld->pip2_file_data.para_num == -1) {
  3677. ld->pip2_file_data.para_num = 0;
  3678. pt_debug(dev, DL_INFO, "%s: flash read finish!\n",
  3679. __func__);
  3680. rc = 0;
  3681. goto exit_release;
  3682. } else if (ld->pip2_file_data.para_num < -1) {
  3683. ld->pip2_file_data.para_num = 0;
  3684. pt_debug(dev, DL_ERROR, "%s: Exit directly due to errors!\n",
  3685. __func__);
  3686. return 0;
  3687. } else if (ld->pip2_file_data.para_num > 3) {
  3688. ld->pip2_file_data.para_num = 0;
  3689. pt_debug(dev, DL_ERROR,
  3690. "%s: Exit directly due to invalid parameter!\n",
  3691. __func__);
  3692. return 0;
  3693. }
  3694. if (offset == 0) {
  3695. ld->pip2_file_data.file_print_buf = kzalloc(PIPE_BUF,
  3696. GFP_KERNEL);
  3697. if (!ld->pip2_file_data.file_print_buf) {
  3698. rc = -ENOMEM;
  3699. goto exit;
  3700. }
  3701. /* This functionality is only available in the BL */
  3702. if (cd->mode != PT_MODE_BOOTLOADER) {
  3703. rc = -EPERM;
  3704. goto exit_free;
  3705. }
  3706. pr_buf = ld->pip2_file_data.file_print_buf;
  3707. rc = cmd->request_exclusive(dev,
  3708. PT_LDR_REQUEST_EXCLUSIVE_TIMEOUT);
  3709. if (rc) {
  3710. pt_debug(dev, DL_ERROR,
  3711. "%s: Failed to request exclusive rc=%d\n",
  3712. __func__, rc);
  3713. goto exit_free;
  3714. }
  3715. rc = cmd->nonhid_cmd->pip2_file_open(dev, file_handle);
  3716. if (rc < 0) {
  3717. pt_debug(dev, DL_ERROR,
  3718. "%s: Failed to file_open rc=%d\n",
  3719. __func__, rc);
  3720. goto exit_release;
  3721. }
  3722. rc = cmd->nonhid_cmd->pip2_file_get_stats(dev, file_handle,
  3723. &address, &file_size);
  3724. if (rc) {
  3725. pt_debug(dev, DL_ERROR,
  3726. "%s: Failed to get_file_state rc=%d\n",
  3727. __func__, rc);
  3728. goto exit_file_close;
  3729. }
  3730. ld->pip2_file_data.file_print_size = 0;
  3731. ld->pip2_file_data.file_max_size = file_size;
  3732. ld->pip2_file_data.file_print_left = 0;
  3733. print_idx += scnprintf(pr_buf, PIPE_BUF, "ROM_DATA:");
  3734. if (ld->pip2_file_data.para_num == 1)
  3735. ld->pip2_file_data.file_read_size = file_size;
  3736. else if (ld->pip2_file_data.para_num == 2) {
  3737. if (ld->pip2_file_data.file_offset < file_size)
  3738. ld->pip2_file_data.file_read_size = file_size -
  3739. ld->pip2_file_data.file_offset;
  3740. else {
  3741. rc = -EINVAL;
  3742. pt_debug(dev, DL_ERROR,
  3743. "%s: File read out of bounds rc=%d\n",
  3744. __func__, rc);
  3745. goto exit_file_close;
  3746. }
  3747. } else if (ld->pip2_file_data.para_num == 3) {
  3748. if ((ld->pip2_file_data.file_read_size +
  3749. ld->pip2_file_data.file_offset) > file_size) {
  3750. rc = -EINVAL;
  3751. pt_debug(dev, DL_ERROR,
  3752. "%s: File read out of bounds rc=%d\n",
  3753. __func__, rc);
  3754. goto exit_file_close;
  3755. }
  3756. } else {
  3757. pt_debug(dev, DL_ERROR,
  3758. "%s: Invalid number of parameters!\n",
  3759. __func__);
  3760. goto exit_file_close;
  3761. }
  3762. }
  3763. offset = ld->pip2_file_data.file_print_size +
  3764. ld->pip2_file_data.file_offset;
  3765. if ((offset >= ld->pip2_file_data.file_max_size) ||
  3766. (ld->pip2_file_data.file_print_size >=
  3767. ld->pip2_file_data.file_read_size))
  3768. goto exit_file_close;
  3769. else if ((ld->pip2_file_data.file_print_size +
  3770. PIP2_FILE_WRITE_LEN_PER_PACKET) >=
  3771. ld->pip2_file_data.file_read_size)
  3772. read_len = ld->pip2_file_data.file_read_size -
  3773. ld->pip2_file_data.file_print_size;
  3774. else
  3775. read_len = PIP2_FILE_WRITE_LEN_PER_PACKET;
  3776. rc = cmd->nonhid_cmd->pip2_file_seek_offset(dev,
  3777. file_handle, offset, 0);
  3778. if (rc) {
  3779. pt_debug(dev, DL_ERROR,
  3780. "%s: Failed to seek file offset rc=%d\n",
  3781. __func__, rc);
  3782. goto exit_file_close;
  3783. }
  3784. read_size = cmd->nonhid_cmd->pip2_file_read(dev,
  3785. file_handle, read_len, read_buf);
  3786. if (read_size < 0) {
  3787. pt_debug(dev, DL_ERROR, "%s: Failed to read file rc=%d\n",
  3788. __func__, read_size);
  3789. goto exit_file_close;
  3790. }
  3791. for (i = 0; i < read_size; i++)
  3792. print_idx += scnprintf(pr_buf + print_idx,
  3793. PIPE_BUF - print_idx,
  3794. "%02X ", read_buf[i + PIP2_RESP_BODY_OFFSET]);
  3795. ld->pip2_file_data.file_print_size += read_size;
  3796. if (count < print_idx) {
  3797. memcpy(buf, pr_buf, count);
  3798. ld->pip2_file_data.file_print_left = print_idx - count;
  3799. for (i = 0; i < ld->pip2_file_data.file_print_left; i++)
  3800. pr_buf[i] = pr_buf[i+count];
  3801. print_idx = count;
  3802. } else {
  3803. memcpy(buf, pr_buf, print_idx);
  3804. }
  3805. goto exit_for_next_read;
  3806. exit_file_close:
  3807. if (rc)
  3808. print_idx += scnprintf(pr_buf + print_idx,
  3809. PIPE_BUF - print_idx, "(READ ERROR)\n");
  3810. else if (ld->pip2_file_data.file_print_size)
  3811. print_idx += scnprintf(pr_buf + print_idx,
  3812. PIPE_BUF - print_idx,
  3813. ":(%d bytes)\n",
  3814. ld->pip2_file_data.file_print_size);
  3815. else
  3816. print_idx += scnprintf(pr_buf + print_idx,
  3817. PIPE_BUF - print_idx, "No Data\n");
  3818. if (count < print_idx) {
  3819. memcpy(buf, pr_buf, count);
  3820. ld->pip2_file_data.file_print_left = print_idx - count;
  3821. for (i = 0; i < ld->pip2_file_data.file_print_left; i++)
  3822. pr_buf[i] = pr_buf[i+count];
  3823. print_idx = count;
  3824. } else {
  3825. memcpy(buf, pr_buf, print_idx);
  3826. }
  3827. rc = cmd->nonhid_cmd->pip2_file_close(dev, file_handle);
  3828. if (file_handle != rc)
  3829. pt_debug(dev, DL_ERROR,
  3830. "%s Failed to close file %d, rc = %d\n", __func__,
  3831. file_handle, rc);
  3832. /*
  3833. * Mark para_num as negative value to finish read method during
  3834. * next enter.
  3835. */
  3836. ld->pip2_file_data.para_num = -1;
  3837. exit_for_next_read:
  3838. pt_debug(dev, DL_INFO,
  3839. "%s: %s=%d, %s=%d, %s=%d, %s=%d, %s=%d\n",
  3840. __func__,
  3841. "para_num", ld->pip2_file_data.para_num,
  3842. "handle", ld->pip2_file_data.file_handle,
  3843. "offset", ld->pip2_file_data.file_offset,
  3844. "read", ld->pip2_file_data.file_read_size,
  3845. "print", ld->pip2_file_data.file_print_size);
  3846. return print_idx;
  3847. exit_release:
  3848. cmd->release_exclusive(dev);
  3849. exit_free:
  3850. kfree(ld->pip2_file_data.file_print_buf);
  3851. exit:
  3852. if (rc) {
  3853. ld->pip2_file_data.para_num = -2;
  3854. print_idx = scnprintf(buf, count, "Status: %d\n", rc);
  3855. return print_idx;
  3856. } else
  3857. return 0;
  3858. }
  3859. /*******************************************************************************
  3860. * FUNCTION: pt_pip2_file_read_store
  3861. *
  3862. * SUMMARY: The write method for the pip2_file_read node. The passed
  3863. * in data is needed by read method.
  3864. *
  3865. * RETURN: Size of passed in buffer is success
  3866. *
  3867. * PARAMETERS:
  3868. * *filp - pointer to file structure
  3869. * *kobj - pointer to kobject structure
  3870. * *bin_attr - pointer to bin_attribute structure
  3871. * buf - pointer to cmd input buffer
  3872. * offset - offset index to store input buffer
  3873. * count - size of data in buffer
  3874. ******************************************************************************/
  3875. static ssize_t pt_pip2_file_read_store(struct file *filp,
  3876. struct kobject *kobj, struct bin_attribute *bin_attr,
  3877. char *buf, loff_t offset, size_t count)
  3878. {
  3879. int rc = 0;
  3880. int length;
  3881. struct device *dev = container_of(kobj, struct device, kobj);
  3882. struct pt_loader_data *ld = pt_get_loader_data(dev);
  3883. int ic_buffer[4] = {0};
  3884. length = cmd->parse_sysfs_input(dev, buf, count, ic_buffer,
  3885. ARRAY_SIZE(ic_buffer));
  3886. if (length <= 0 || length > 3) {
  3887. pt_debug(dev, DL_ERROR, "%s: Input format error!\n",
  3888. __func__);
  3889. ld->pip2_file_data.para_num = 0;
  3890. rc = -EINVAL;
  3891. goto error;
  3892. }
  3893. if (ic_buffer[0] < PIP2_FW_FILE || ic_buffer[0] > PIP2_FILE_7) {
  3894. pt_debug(dev, DL_ERROR, "%s: Invalid file handle!\n",
  3895. __func__);
  3896. ld->pip2_file_data.para_num = 0;
  3897. rc = -EINVAL;
  3898. goto error;
  3899. }
  3900. switch (length) {
  3901. case 1:
  3902. ld->pip2_file_data.file_handle = ic_buffer[0];
  3903. ld->pip2_file_data.file_offset = 0;
  3904. ld->pip2_file_data.file_read_size = 0;
  3905. break;
  3906. case 2:
  3907. ld->pip2_file_data.file_handle = ic_buffer[0];
  3908. ld->pip2_file_data.file_offset = ic_buffer[1];
  3909. ld->pip2_file_data.file_read_size = 0;
  3910. break;
  3911. case 3:
  3912. ld->pip2_file_data.file_handle = ic_buffer[0];
  3913. ld->pip2_file_data.file_offset = ic_buffer[1];
  3914. ld->pip2_file_data.file_read_size = ic_buffer[2];
  3915. break;
  3916. default:
  3917. break;
  3918. }
  3919. ld->pip2_file_data.para_num = length;
  3920. error:
  3921. pt_debug(dev, DL_INFO,
  3922. "%s: %s=%d, %s=%d, %s=%d, %s=%d, %s=%d\n",
  3923. __func__,
  3924. "para_num", ld->pip2_file_data.para_num,
  3925. "handle", ld->pip2_file_data.file_handle,
  3926. "offset", ld->pip2_file_data.file_offset,
  3927. "read", ld->pip2_file_data.file_read_size,
  3928. "print", ld->pip2_file_data.file_print_size);
  3929. if (rc)
  3930. return rc;
  3931. return count;
  3932. }
  3933. static struct bin_attribute bin_attr_pip2_file_read = {
  3934. .attr = {
  3935. .name = "pip2_file_read",
  3936. .mode = (0644),
  3937. },
  3938. .read = pt_pip2_file_read_show,
  3939. .write = pt_pip2_file_read_store,
  3940. };
  3941. /******************************************************************************
  3942. * FUNCTION: pt_pip2_file_crc_show
  3943. *
  3944. * SUMMARY: The show method for the "pip2_file_crc" sysfs node.
  3945. * Shows the CRC of a file or portion of the file.
  3946. *
  3947. * NOTE: If function is called when DUT is already in BL mode, the DUT
  3948. * will remain in BL mode when function exits, however if DUT is in
  3949. * normal mode when function is called, the DUT will be forced into BL
  3950. * mode and then returned to normal mode when function exits.
  3951. *
  3952. * NOTE: This sysfs node only can be used for BL version 1.8 or greater.
  3953. *
  3954. * PARAMETERS:
  3955. * *dev - pointer to device structure
  3956. * *attr - pointer to device attributes structure
  3957. * *buf - pointer to print output buffer
  3958. ******************************************************************************/
  3959. static ssize_t pt_pip2_file_crc_show(struct device *dev,
  3960. struct device_attribute *attr, char *buf)
  3961. {
  3962. struct pt_loader_data *ld = pt_get_loader_data(dev);
  3963. struct pt_core_data *cd = dev_get_drvdata(dev);
  3964. int rc = 0;
  3965. u8 file_handle;
  3966. int print_idx = 0;
  3967. u8 read_buf[PT_MAX_PIP2_MSG_SIZE];
  3968. u32 address, file_size;
  3969. u32 length;
  3970. u32 offset;
  3971. u16 file_crc;
  3972. u16 status;
  3973. if (ld->pip2_fcrc.para_num == 0 ||
  3974. ld->pip2_fcrc.file_handle == 0 ||
  3975. ld->pip2_fcrc.file_read_size < 0 ||
  3976. ld->pip2_fcrc.file_offset < 0) {
  3977. pt_debug(dev, DL_ERROR,
  3978. "%s: Invalid parameters!\n",
  3979. __func__);
  3980. print_idx = scnprintf(buf, PT_MAX_PRBUF_SIZE,
  3981. "Status: %d\n"
  3982. "Invalid parameters!\n", -EINVAL);
  3983. return print_idx;
  3984. }
  3985. file_handle = ld->pip2_fcrc.file_handle;
  3986. offset = ld->pip2_fcrc.file_offset;
  3987. length = ld->pip2_fcrc.file_read_size;
  3988. /* This functionality is only available in the BL */
  3989. if (cd->mode != PT_MODE_BOOTLOADER) {
  3990. rc = -EPERM;
  3991. print_idx = scnprintf(buf, PT_MAX_PRBUF_SIZE,
  3992. "Status: %d\n", rc);
  3993. goto exit;
  3994. }
  3995. rc = cmd->request_exclusive(dev, PT_LDR_REQUEST_EXCLUSIVE_TIMEOUT);
  3996. if (rc) {
  3997. pt_debug(dev, DL_ERROR,
  3998. "%s: Failed to request exclusive rc=%d\n",
  3999. __func__, rc);
  4000. print_idx = scnprintf(buf, PT_MAX_PRBUF_SIZE,
  4001. "Status: %d\n", rc);
  4002. goto exit;
  4003. }
  4004. rc = cmd->nonhid_cmd->pip2_file_open(dev, file_handle);
  4005. if (rc < 0) {
  4006. pt_debug(dev, DL_ERROR,
  4007. "%s: Failed to file_open rc=%d\n",
  4008. __func__, rc);
  4009. print_idx = scnprintf(buf, PT_MAX_PRBUF_SIZE,
  4010. "Status: %d\n", rc);
  4011. goto exit_release;
  4012. }
  4013. rc = cmd->nonhid_cmd->pip2_file_get_stats(dev, file_handle,
  4014. &address, &file_size);
  4015. if (rc) {
  4016. pt_debug(dev, DL_ERROR,
  4017. "%s: Failed to get_file_state rc=%d\n",
  4018. __func__, rc);
  4019. print_idx = scnprintf(buf, PT_MAX_PRBUF_SIZE,
  4020. "Status: %d\n", rc);
  4021. goto exit_file_close;
  4022. }
  4023. ld->pip2_fcrc.file_max_size = file_size;
  4024. if (ld->pip2_fcrc.file_read_size > file_size
  4025. || ld->pip2_fcrc.file_offset > file_size
  4026. || ((ld->pip2_fcrc.file_offset +
  4027. ld->pip2_fcrc.file_read_size) > file_size)) {
  4028. pt_debug(dev, DL_ERROR,
  4029. "%s: Invalid parameters!\n",
  4030. __func__);
  4031. print_idx = scnprintf(buf, PT_MAX_PRBUF_SIZE,
  4032. "Status: %d\n", rc);
  4033. goto exit_file_close;
  4034. }
  4035. rc = cmd->nonhid_cmd->pip2_file_crc(dev,
  4036. file_handle, offset, length, read_buf);
  4037. if (rc) {
  4038. pt_debug(dev, DL_ERROR,
  4039. "%s: Failed to get file crc, rc=%d\n",
  4040. __func__, rc);
  4041. print_idx = scnprintf(buf, PT_MAX_PRBUF_SIZE,
  4042. "Status: %d\n", rc);
  4043. } else {
  4044. status = read_buf[PIP2_RESP_STATUS_OFFSET];
  4045. if (status == PIP2_RSP_ERR_NONE) {
  4046. file_crc = get_unaligned_le16(&read_buf[5]);
  4047. print_idx = scnprintf(buf, PT_MAX_PRBUF_SIZE,
  4048. "Status: %d\n"
  4049. "FILE CRC: %04X\n",
  4050. status, file_crc);
  4051. } else
  4052. print_idx = scnprintf(buf, PT_MAX_PRBUF_SIZE,
  4053. "Status: %d\n"
  4054. "FILE CRC: n/a\n",
  4055. status);
  4056. }
  4057. exit_file_close:
  4058. rc = cmd->nonhid_cmd->pip2_file_close(dev, file_handle);
  4059. if (file_handle != rc)
  4060. pt_debug(dev, DL_ERROR,
  4061. "%s Failed to close file %d, rc = %d\n", __func__,
  4062. file_handle, rc);
  4063. exit_release:
  4064. cmd->release_exclusive(dev);
  4065. exit:
  4066. ld->pip2_fcrc.para_num = 0;
  4067. return print_idx;
  4068. }
  4069. /*******************************************************************************
  4070. * FUNCTION: pt_pip2_file_crc_store
  4071. *
  4072. * SUMMARY: The store method for the "pip2_file_crc" sysfs node. The passed in
  4073. * data including file_handle, offset and read size are needed by show method.
  4074. *
  4075. * NOTE: This sysfs node only can be used for BL version 1.8 or greater..
  4076. *
  4077. * PARAMETERS:
  4078. * *dev - pointer to device structure
  4079. * *attr - pointer to device attributes structure
  4080. * *buf - pointer to print output buffer
  4081. * size - size of buffer
  4082. ******************************************************************************/
  4083. static ssize_t pt_pip2_file_crc_store(struct device *dev,
  4084. struct device_attribute *attr, const char *buf, size_t size)
  4085. {
  4086. struct pt_loader_data *ld = pt_get_loader_data(dev);
  4087. u32 input_data[4] = {0};
  4088. int length;
  4089. int rc = 0;
  4090. ld->pip2_fcrc.file_handle = PIP2_RAM_FILE;
  4091. ld->pip2_fcrc.file_offset = -1;
  4092. ld->pip2_fcrc.file_read_size = -1;
  4093. length = cmd->parse_sysfs_input(dev, buf, size, input_data,
  4094. ARRAY_SIZE(input_data));
  4095. if (length != 3) {
  4096. pt_debug(dev, DL_WARN, "%s: Invalid number of arguments\n",
  4097. __func__);
  4098. ld->pip2_fcrc.para_num = 0;
  4099. rc = -EINVAL;
  4100. goto exit;
  4101. }
  4102. if ((input_data[0] < PIP2_FW_FILE) || (input_data[0] > PIP2_FILE_MAX)) {
  4103. pt_debug(dev, DL_WARN, "%s: Invalid file_no %d\n",
  4104. __func__, input_data[0]);
  4105. rc = -EINVAL;
  4106. goto exit;
  4107. }
  4108. ld->pip2_fcrc.file_handle = input_data[0];
  4109. ld->pip2_fcrc.file_offset = input_data[1];
  4110. ld->pip2_fcrc.file_read_size = input_data[2];
  4111. ld->pip2_fcrc.para_num = 3;
  4112. pt_debug(dev, DL_INFO,
  4113. "%s: %s=%d, %s=%d, %s=%d, %s=%d\n",
  4114. __func__,
  4115. "para_num", ld->pip2_fcrc.para_num,
  4116. "handle", ld->pip2_fcrc.file_handle,
  4117. "offset", ld->pip2_fcrc.file_offset,
  4118. "length", ld->pip2_fcrc.file_read_size);
  4119. exit:
  4120. if (rc)
  4121. return rc;
  4122. return size;
  4123. }
  4124. static DEVICE_ATTR(pip2_file_crc, 0644,
  4125. pt_pip2_file_crc_show, pt_pip2_file_crc_store);
  4126. #endif
  4127. /*******************************************************************************
  4128. * FUNCTION: pt_pip2_file_erase_show
  4129. *
  4130. * SUMMARY: The show method for the "pip2_file_erase" sysfs node.
  4131. * Prints current erase status to output buffer.
  4132. *
  4133. * PARAMETERS:
  4134. * *dev - pointer to device structure
  4135. * *attr - pointer to device attributes structure
  4136. * *buf - pointer to print output buffer
  4137. ******************************************************************************/
  4138. static ssize_t pt_pip2_file_erase_show(struct device *dev,
  4139. struct device_attribute *attr, char *buf)
  4140. {
  4141. struct pt_loader_data *ld = pt_get_loader_data(dev);
  4142. struct pt_core_data *cd = dev_get_drvdata(dev);
  4143. u8 file_handle;
  4144. u8 file = ld->pip2_file_erase_file_no;
  4145. int rc;
  4146. pip2_erase_status = -1;
  4147. pip2_erase_rc = 0;
  4148. if (file == PIP2_RAM_FILE) {
  4149. rc = -EINVAL;
  4150. goto exit;
  4151. }
  4152. /* This functionality is only available in the BL */
  4153. if (cd->mode != PT_MODE_BOOTLOADER) {
  4154. rc = -EPERM;
  4155. goto exit;
  4156. }
  4157. rc = cmd->request_exclusive(dev, PT_LDR_REQUEST_EXCLUSIVE_TIMEOUT);
  4158. if (rc < 0) {
  4159. pt_debug(dev, DL_ERROR,
  4160. "%s: Failed to get exclusive access rc=%d\n",
  4161. __func__, rc);
  4162. goto exit;
  4163. }
  4164. file_handle = cmd->nonhid_cmd->pip2_file_open(dev, file);
  4165. if (file_handle != file) {
  4166. rc = -EBADF;
  4167. goto exit_release;
  4168. }
  4169. file_handle = cmd->nonhid_cmd->pip2_file_erase(dev, file,
  4170. &pip2_erase_status);
  4171. if (file_handle < 0) {
  4172. rc = file_handle;
  4173. pt_debug(dev, DL_INFO, "%s: File erase error rc = %d\n",
  4174. __func__, rc);
  4175. } else if (file_handle == file) {
  4176. pt_debug(dev, DL_INFO, "%s: File %d erased\n",
  4177. __func__, file_handle);
  4178. } else {
  4179. rc = -EBADF;
  4180. }
  4181. file_handle = cmd->nonhid_cmd->pip2_file_close(dev, file);
  4182. if (file_handle != file && !rc)
  4183. rc = -EBADF;
  4184. exit_release:
  4185. cmd->release_exclusive(dev);
  4186. exit:
  4187. pip2_erase_rc = rc;
  4188. if (pip2_erase_status == -1) {
  4189. return scnprintf(buf, PT_MAX_PRBUF_SIZE,
  4190. "Status: %d\n"
  4191. "Erase Status: n/a\n",
  4192. pip2_erase_rc);
  4193. }
  4194. return scnprintf(buf, PT_MAX_PRBUF_SIZE,
  4195. "Status: %d\n"
  4196. "Erase Status: 0x%02X\n",
  4197. pip2_erase_rc, pip2_erase_status);
  4198. }
  4199. /*******************************************************************************
  4200. * FUNCTION: pt_pip2_file_erase_store
  4201. *
  4202. * SUMMARY: The store method for the "pip2_file_erase" sysfs node. Allows the
  4203. * caller to provide the file number to erase in FLASH.
  4204. *
  4205. * NOTE: The DUT must be in BL mode before calling this function.
  4206. *
  4207. * PARAMETERS:
  4208. * *dev - pointer to device structure
  4209. * *attr - pointer to device attributes structure
  4210. * *buf - pointer to print output buffer
  4211. * size - size of buffer
  4212. ******************************************************************************/
  4213. static ssize_t pt_pip2_file_erase_store(struct device *dev,
  4214. struct device_attribute *attr, const char *buf, size_t size)
  4215. {
  4216. struct pt_loader_data *ld = pt_get_loader_data(dev);
  4217. u32 input_data[2] = {0};
  4218. int length;
  4219. int rc = 0;
  4220. length = cmd->parse_sysfs_input(dev, buf, size, input_data,
  4221. ARRAY_SIZE(input_data));
  4222. if (length != 1) {
  4223. pt_debug(dev, DL_WARN, "%s: Invalid number of arguments\n",
  4224. __func__);
  4225. rc = -EINVAL;
  4226. goto exit;
  4227. }
  4228. /* Only allow valid files to be erased */
  4229. if (input_data[0] < PIP2_FW_FILE || input_data[0] > PIP2_FILE_MAX) {
  4230. pip2_erase_status = PIP2_RSP_ERR_BAD_FILE;
  4231. pt_debug(dev, DL_ERROR, "%s: ERROR - Invalid File\n",
  4232. __func__);
  4233. rc = -EINVAL;
  4234. goto exit;
  4235. }
  4236. ld->pip2_file_erase_file_no = input_data[0];
  4237. exit:
  4238. if (rc)
  4239. return rc;
  4240. return size;
  4241. }
  4242. static DEVICE_ATTR(pip2_file_erase, 0644,
  4243. pt_pip2_file_erase_show, pt_pip2_file_erase_store);
  4244. /*******************************************************************************
  4245. * FUNCTION: pt_pip2_bl_status_show
  4246. *
  4247. * SUMMARY: The show method for the pip2_bl_status sysfs node.
  4248. * Shows the percent completion of the current BL or an error message.
  4249. *
  4250. * PARAMETERS:
  4251. * *dev - pointer to device structure
  4252. * *attr - pointer to device attributes structure
  4253. * *buf - pointer to print output buffer
  4254. ******************************************************************************/
  4255. static ssize_t pt_pip2_bl_status_show(struct device *dev,
  4256. struct device_attribute *attr, char *buf)
  4257. {
  4258. ssize_t ret;
  4259. u8 status = update_fw_status;
  4260. if (update_fw_status <= UPDATE_FW_COMPLETE) {
  4261. pt_debug(dev, DL_DEBUG,
  4262. "%s BL_STATUS = %d\n", __func__, update_fw_status);
  4263. return scnprintf(buf, strlen(buf), "%d\n", update_fw_status);
  4264. }
  4265. switch (status) {
  4266. case UPDATE_FW_GENERAL_ERROR:
  4267. ret = scnprintf(buf, strlen(buf),
  4268. "ERROR: %d - General programming failure\n", status);
  4269. break;
  4270. case UPDATE_FW_PIP_VERSION_ERROR:
  4271. ret = scnprintf(buf, strlen(buf),
  4272. "ERROR: %d - Wrong PIP version detected\n", status);
  4273. break;
  4274. case UPDATE_FW_VERSION_ERROR:
  4275. ret = scnprintf(buf, strlen(buf),
  4276. "ERROR: %d - FW vervion newer than bin file\n", status);
  4277. break;
  4278. case UPDATE_FW_ERASE_ERROR:
  4279. ret = scnprintf(buf, strlen(buf),
  4280. "ERROR: %d - ROM BL failed to erase FW file in FLASH\n",
  4281. status);
  4282. break;
  4283. case UPDATE_FW_FILE_CLOSE_ERROR:
  4284. ret = scnprintf(buf, strlen(buf),
  4285. "ERROR: %d - ROM BL failed to close FW file in FLASH\n",
  4286. status);
  4287. break;
  4288. case UPDATE_FW_WRITE_ERROR:
  4289. ret = scnprintf(buf, strlen(buf),
  4290. "ERROR: %d - ROM BL file write failure\n", status);
  4291. break;
  4292. case UPDATE_FW_EXECUTE_ERROR:
  4293. ret = scnprintf(buf, strlen(buf),
  4294. "ERROR: %d - ROM BL failed to execute RAM image\n",
  4295. status);
  4296. break;
  4297. case UPDATE_FW_RESET_ERROR:
  4298. ret = scnprintf(buf, strlen(buf),
  4299. "ERROR: %d - Reset DUT failure\n",
  4300. status);
  4301. break;
  4302. case UPDATE_FW_MODE_ERROR:
  4303. ret = scnprintf(buf, strlen(buf),
  4304. "ERROR: %d - Program complete, Incorrect BL/APP mode detected after reset sentinel\n",
  4305. status);
  4306. break;
  4307. case UPDATE_FW_ENTER_BL_ERROR:
  4308. ret = scnprintf(buf, strlen(buf),
  4309. "ERROR: %d - Could not enter the BL\n", status);
  4310. break;
  4311. case UPDATE_FW_FILE_OPEN_ERROR:
  4312. ret = scnprintf(buf, strlen(buf),
  4313. "ERROR: %d - ROM BL failed to open FW file in FLASH\n",
  4314. status);
  4315. break;
  4316. case UPDATE_FW_SENTINEL_NOT_SEEN:
  4317. ret = scnprintf(buf, strlen(buf),
  4318. "ERROR: %d - FW Reset Sentinel not seen after XRES\n",
  4319. status);
  4320. break;
  4321. case UPDATE_FW_EXCLUSIVE_ACCESS_ERROR:
  4322. ret = scnprintf(buf, strlen(buf),
  4323. "ERROR: %d - Failed to get DUT exclusive access\n",
  4324. status);
  4325. break;
  4326. case UPDATE_FW_NO_FW_PROVIDED:
  4327. ret = scnprintf(buf, strlen(buf),
  4328. "ERROR: %d - No FW provided to load\n", status);
  4329. break;
  4330. case UPDATE_FW_INVALID_FW_IMAGE:
  4331. ret = scnprintf(buf, strlen(buf), "ERROR: %d - Invalid FW image\n", status);
  4332. break;
  4333. case UPDATE_FW_MISALIGN_FW_IMAGE:
  4334. ret = scnprintf(buf, strlen(buf),
  4335. "ERROR: %d - FW image is misaligned\n", status);
  4336. break;
  4337. case UPDATE_FW_SYSTEM_NOMEM:
  4338. ret = scnprintf(buf, strlen(buf),
  4339. "ERROR: %d - Failed to alloc memory\n", status);
  4340. break;
  4341. case UPDATE_FW_INIT_BL_ERROR:
  4342. ret = scnprintf(buf, strlen(buf),
  4343. "ERROR: %d - Failed to init bootloader\n", status);
  4344. break;
  4345. case UPDATE_FW_PARSE_ROW_ERROR:
  4346. ret = scnprintf(buf, strlen(buf),
  4347. "ERROR: %d - Failed to parse row of FW image\n",
  4348. status);
  4349. break;
  4350. case UPDATE_FW_PROGRAM_ROW_ERROR:
  4351. ret = scnprintf(buf, strlen(buf),
  4352. "ERROR: %d - Failed to progrem FW image\n", status);
  4353. break;
  4354. case UPDATE_FW_EXIT_BL_ERROR:
  4355. ret = scnprintf(buf, strlen(buf),
  4356. "ERROR: %d - Failed to exit bootloader\n", status);
  4357. break;
  4358. case UPDATE_FW_CHECK_SUM_ERROR:
  4359. ret = scnprintf(buf, strlen(buf),
  4360. "ERROR: %d - Failed to verify app checksum\n", status);
  4361. break;
  4362. case UPDATE_FW_NO_PLATFORM_DATA:
  4363. ret = scnprintf(buf, strlen(buf),
  4364. "ERROR: %d - No platform data\n", status);
  4365. break;
  4366. case UPDATE_FW_UNDEFINED_ERROR:
  4367. default:
  4368. ret = scnprintf(buf, strlen(buf), "ERROR: %d - Unknown error\n", status);
  4369. break;
  4370. }
  4371. return ret;
  4372. }
  4373. static DEVICE_ATTR(pip2_bl_status, 0444, pt_pip2_bl_status_show, NULL);
  4374. #if PT_FW_UPGRADE
  4375. static DEVICE_ATTR(update_fw_status, 0444, pt_pip2_bl_status_show, NULL);
  4376. #endif
  4377. /*******************************************************************************
  4378. * FUNCTION: pt_pip2_get_last_error_show
  4379. *
  4380. * SUMMARY: The show method for the pip2_get_last_error_show sysfs node.
  4381. * Shows the last BL error code.
  4382. *
  4383. * NOTE: If function is called when DUT is already in BL mode, the DUT
  4384. * will remain in BL mode when function exits, however if DUT is in
  4385. * normal mode when function is called, the DUT will be forced into BL
  4386. * mode and then returned to normal mode when function exits.
  4387. *
  4388. * PARAMETERS:
  4389. * *dev - pointer to device structure
  4390. * *attr - pointer to device attributes structure
  4391. * *buf - pointer to print output buffer
  4392. ******************************************************************************/
  4393. static ssize_t pt_pip2_get_last_error_show(struct device *dev,
  4394. struct device_attribute *attr, char *buf)
  4395. {
  4396. struct pt_core_data *cd = dev_get_drvdata(dev);
  4397. int rc;
  4398. u8 read_buf[256];
  4399. rc = cmd->request_exclusive(dev, PT_LDR_REQUEST_EXCLUSIVE_TIMEOUT);
  4400. if (rc)
  4401. goto exit;
  4402. cmd->request_stop_wd(dev);
  4403. /* This functionality is only available in the BL */
  4404. if (cd->mode != PT_MODE_BOOTLOADER) {
  4405. rc = -EPERM;
  4406. goto exit_release;
  4407. }
  4408. /* Get and log the last error(s) */
  4409. rc = _pt_pip2_log_last_error(dev, read_buf);
  4410. exit_release:
  4411. cmd->release_exclusive(dev);
  4412. exit:
  4413. if (rc)
  4414. return scnprintf(buf, PT_MAX_PRBUF_SIZE, "Status: %d\n", rc);
  4415. if (read_buf[PIP2_RESP_STATUS_OFFSET] == PIP2_RSP_ERR_NONE) {
  4416. return scnprintf(buf, PT_MAX_PRBUF_SIZE,
  4417. "Status: %d\n"
  4418. "Last Error No: 0x%02X\n",
  4419. PIP2_RSP_ERR_NONE,
  4420. read_buf[PIP2_RESP_BODY_OFFSET]);
  4421. } else {
  4422. return scnprintf(buf, PT_MAX_PRBUF_SIZE,
  4423. "Status: %d\n"
  4424. "Last Error No: n/a\n",
  4425. read_buf[PIP2_RESP_STATUS_OFFSET]);
  4426. }
  4427. }
  4428. static DEVICE_ATTR(pip2_get_last_error, 0444,
  4429. pt_pip2_get_last_error_show, NULL);
  4430. #if PT_FW_UPGRADE
  4431. /*******************************************************************************
  4432. * FUNCTION: pt_loader_attention
  4433. *
  4434. * SUMMARY: Function to be registered to TTDL attention list to set up
  4435. * int_running semaphore.
  4436. *
  4437. * RETURN:
  4438. * 0 = success
  4439. *
  4440. * PARAMETERS:
  4441. * *dev - pointer to device structure
  4442. ******************************************************************************/
  4443. static int pt_loader_attention(struct device *dev)
  4444. {
  4445. struct pt_loader_data *ld = pt_get_loader_data(dev);
  4446. complete(&ld->int_running);
  4447. return 0;
  4448. }
  4449. /*******************************************************************************
  4450. * FUNCTION: pt_fw_upgrade_cb
  4451. *
  4452. * SUMMARY: Function to be registered to TTDL attention list to allow upgrade
  4453. * if host cannot get response from firmware with ping command.
  4454. * RETURN:
  4455. * 0 = success
  4456. *
  4457. * PARAMETERS:
  4458. * *dev - pointer to device structure
  4459. ******************************************************************************/
  4460. static int pt_fw_upgrade_cb(struct device *dev)
  4461. {
  4462. u8 dut_gen = cmd->request_dut_generation(dev);
  4463. #ifdef CONFIG_TOUCHSCREEN_PARADE_PLATFORM_FW_UPGRADE
  4464. if (dut_gen == DUT_PIP1_ONLY) {
  4465. pt_debug(dev, DL_WARN, "%s: Upgrade Platform FW", __func__);
  4466. if (!upgrade_firmware_from_platform(dev, false))
  4467. return 0;
  4468. }
  4469. #endif
  4470. #ifdef CONFIG_TOUCHSCREEN_PARADE_BINARY_FW_UPGRADE
  4471. pt_debug(dev, DL_WARN, "%s: Upgrade Builtin FW", __func__);
  4472. if (dut_gen == DUT_PIP2_CAPABLE) {
  4473. if (!pt_pip2_upgrade_firmware_from_builtin(dev))
  4474. return 0;
  4475. pt_debug(dev, DL_WARN, "%s: Builtin FW upgrade failed",
  4476. __func__);
  4477. } else {
  4478. if (!upgrade_firmware_from_builtin(dev))
  4479. return 0;
  4480. }
  4481. #endif
  4482. return 0;
  4483. }
  4484. /*******************************************************************************
  4485. * FUNCTION: pt_cancel_fw_upgrade_cb
  4486. *
  4487. * SUMMARY: Function to be registered to TTDL attention list to allow an upgrade
  4488. * to be canceled.
  4489. * RETURN:
  4490. * 0 = success
  4491. *
  4492. * PARAMETERS:
  4493. * *dev - pointer to device structure
  4494. ******************************************************************************/
  4495. static int pt_cancel_fw_upgrade_cb(struct device *dev)
  4496. {
  4497. struct pt_loader_data *ld = pt_get_loader_data(dev);
  4498. pt_debug(dev, DL_WARN,
  4499. "%s: CANCELLING All Loader work\n", __func__);
  4500. cancel_work_sync(&ld->bl_from_file);
  4501. cancel_work_sync(&ld->pip2_bl_from_file);
  4502. cancel_work_sync(&ld->calibration_work);
  4503. cancel_work_sync(&ld->fw_and_config_upgrade);
  4504. return 0;
  4505. }
  4506. #endif /* PT_FW_UPGRADE */
  4507. /*******************************************************************************
  4508. * FUNCTION: pt_loader_probe
  4509. *
  4510. * SUMMARY: The probe function for the FW loader.
  4511. *
  4512. * PARAMETERS:
  4513. * *dev - pointer to device structure
  4514. * **data - double pointer to the loader data to be created here
  4515. ******************************************************************************/
  4516. static int pt_loader_probe(struct device *dev, void **data)
  4517. {
  4518. struct pt_loader_data *ld;
  4519. struct pip2_loader_data *pip2_data;
  4520. struct pt_platform_data *pdata = dev_get_platdata(dev);
  4521. int rc;
  4522. u8 dut_gen = cmd->request_dut_generation(dev);
  4523. #ifdef TTDL_DIAGNOSTICS
  4524. pt_debug(dev, DL_INFO,
  4525. "%s: entering %s\n", __func__, __func__);
  4526. #endif /* TTDL_DIAGNOSTICS */
  4527. ld = kzalloc(sizeof(*ld), GFP_KERNEL);
  4528. if (!ld) {
  4529. rc = -ENOMEM;
  4530. goto error_alloc_data_failed;
  4531. }
  4532. #if PT_FW_UPGRADE
  4533. /* Initialize boot loader status */
  4534. if (update_fw_status != UPDATE_FW_COMPLETE)
  4535. _pt_pip2_update_bl_status(dev, UPDATE_FW_IDLE, PT_NO_INC);
  4536. #endif
  4537. if (dut_gen == DUT_PIP2_CAPABLE) {
  4538. pip2_data = kzalloc(sizeof(*pip2_data), GFP_KERNEL);
  4539. if (!pip2_data) {
  4540. rc = -ENOMEM;
  4541. goto error_alloc_data_failed;
  4542. }
  4543. pip2_data->dev = dev;
  4544. ld->pip2_data = pip2_data;
  4545. #if PT_FW_UPGRADE
  4546. rc = device_create_file(dev, &dev_attr_update_fw_status);
  4547. if (rc) {
  4548. pt_debug(dev, DL_ERROR,
  4549. "%s: Error creating update_fw_status\n",
  4550. __func__);
  4551. goto remove_files;
  4552. }
  4553. #endif
  4554. #ifdef CONFIG_TOUCHSCREEN_PARADE_BINARY_FW_UPGRADE
  4555. rc = device_create_file(dev, &dev_attr_pt_bl_from_file);
  4556. if (rc) {
  4557. pt_debug(dev, DL_ERROR,
  4558. "%s: Error creating pt_bl_from_file\n",
  4559. __func__);
  4560. goto remove_files;
  4561. }
  4562. rc = device_create_file(dev, &dev_attr_update_fw);
  4563. if (rc) {
  4564. pt_debug(dev, DL_ERROR,
  4565. "%s: Error creating update_fw\n",
  4566. __func__);
  4567. goto remove_files;
  4568. }
  4569. #endif /* CONFIG_TOUCHSCREEN_PARADE_BINARY_FW_UPGRADE */
  4570. #ifdef CONFIG_TOUCHSCREEN_PARADE_BINARY_FW_UPGRADE
  4571. rc = device_create_file(dev, &dev_attr_pip2_manual_upgrade);
  4572. if (rc) {
  4573. pt_debug(dev, DL_ERROR,
  4574. "%s: Error creating pip2_manual_upgrade\n",
  4575. __func__);
  4576. goto remove_files;
  4577. }
  4578. rc = device_create_file(dev, &dev_attr_pip2_manual_ram_upgrade);
  4579. if (rc) {
  4580. pt_debug(dev, DL_ERROR,
  4581. "%s: Error creating pip2_manual_ram_upgrade\n",
  4582. __func__);
  4583. goto remove_files;
  4584. }
  4585. rc = device_create_file(dev, &dev_attr_pip2_file_write);
  4586. if (rc) {
  4587. pt_debug(dev, DL_ERROR,
  4588. "%s: Error creating pip2_file_write\n",
  4589. __func__);
  4590. goto remove_files;
  4591. }
  4592. rc = device_create_file(dev, &dev_attr_pip2_bl_from_file);
  4593. if (rc) {
  4594. pt_debug(dev, DL_ERROR,
  4595. "%s: Error creating pip2_bl_from_file\n",
  4596. __func__);
  4597. goto remove_files;
  4598. }
  4599. #endif /* CONFIG_TOUCHSCREEN_PARADE_BINARY_FW_UPGRADE */
  4600. rc = device_create_file(dev, &dev_attr_pip2_file_erase);
  4601. if (rc) {
  4602. pt_debug(dev, DL_ERROR,
  4603. "%s: Error creating pip2_file_erase\n",
  4604. __func__);
  4605. goto remove_files;
  4606. }
  4607. rc = device_create_file(dev, &dev_attr_pip2_bl_status);
  4608. if (rc) {
  4609. pt_debug(dev, DL_ERROR,
  4610. "%s: Error creating pip2_bl_status\n",
  4611. __func__);
  4612. goto remove_files;
  4613. }
  4614. #ifdef TTDL_DIAGNOSTICS
  4615. rc = device_create_file(dev, &dev_attr_pip2_get_last_error);
  4616. if (rc) {
  4617. pt_debug(dev, DL_ERROR,
  4618. "%s: Error creating pip2_get_last_error\n",
  4619. __func__);
  4620. goto remove_files;
  4621. }
  4622. rc = device_create_bin_file(dev, &bin_attr_pip2_file_read);
  4623. if (rc) {
  4624. pt_debug(dev, DL_ERROR,
  4625. "%s: Error creating bin_attr_pip2_file_read\n",
  4626. __func__);
  4627. goto remove_files;
  4628. }
  4629. rc = device_create_file(dev, &dev_attr_pip2_file_crc);
  4630. if (rc) {
  4631. pt_debug(dev, DL_ERROR,
  4632. "%s: Error creating pip2_file_crc\n",
  4633. __func__);
  4634. goto remove_files;
  4635. }
  4636. #endif
  4637. } else {
  4638. #if PT_FW_UPGRADE
  4639. rc = device_create_file(dev, &dev_attr_update_fw_status);
  4640. if (rc) {
  4641. pt_debug(dev, DL_ERROR,
  4642. "%s: Error creating update_fw_status\n",
  4643. __func__);
  4644. goto remove_files;
  4645. }
  4646. #endif
  4647. #ifdef CONFIG_TOUCHSCREEN_PARADE_BINARY_FW_UPGRADE
  4648. rc = device_create_file(dev, &dev_attr_pt_bl_from_file);
  4649. if (rc) {
  4650. pt_debug(dev, DL_ERROR,
  4651. "%s: Error creating pt_bl_from_file\n",
  4652. __func__);
  4653. goto remove_files;
  4654. }
  4655. rc = device_create_file(dev, &dev_attr_update_fw);
  4656. if (rc) {
  4657. pt_debug(dev, DL_ERROR,
  4658. "%s: Error creating update_fw\n",
  4659. __func__);
  4660. goto remove_files;
  4661. }
  4662. #endif /* CONFIG_TOUCHSCREEN_PARADE_BINARY_FW_UPGRADE */
  4663. #ifdef CONFIG_TOUCHSCREEN_PARADE_PLATFORM_FW_UPGRADE
  4664. rc = device_create_file(dev, &dev_attr_forced_upgrade);
  4665. if (rc) {
  4666. pt_debug(dev, DL_ERROR,
  4667. "%s: Error creating forced_upgrade\n",
  4668. __func__);
  4669. goto remove_files;
  4670. }
  4671. #endif /* CONFIG_TOUCHSCREEN_PARADE_PLATFORM_FW_UPGRADE */
  4672. #ifdef CONFIG_TOUCHSCREEN_PARADE_BINARY_FW_UPGRADE
  4673. rc = device_create_file(dev, &dev_attr_manual_upgrade);
  4674. if (rc) {
  4675. pt_debug(dev, DL_ERROR,
  4676. "%s: Error creating manual_upgrade\n",
  4677. __func__);
  4678. goto remove_files;
  4679. }
  4680. #endif /* CONFIG_TOUCHSCREEN_PARADE_BINARY_FW_UPGRADE */
  4681. #ifdef CONFIG_TOUCHSCREEN_PARADE_MANUAL_TTCONFIG_UPGRADE
  4682. rc = device_create_file(dev, &dev_attr_config_loading);
  4683. if (rc) {
  4684. pt_debug(dev, DL_ERROR,
  4685. "%s: Error creating config_loading\n",
  4686. __func__);
  4687. goto remove_files;
  4688. }
  4689. rc = device_create_bin_file(dev, &bin_attr_config_data);
  4690. if (rc) {
  4691. pt_debug(dev, DL_ERROR,
  4692. "%s: Error creating config_data\n",
  4693. __func__);
  4694. goto remove_files;
  4695. }
  4696. #endif /* CONFIG_TOUCHSCREEN_PARADE_MANUAL_TTCONFIG_UPGRADE */
  4697. }
  4698. if (!pdata || !pdata->loader_pdata) {
  4699. pt_debug(dev, DL_ERROR,
  4700. "%s: Missing platform data\n", __func__);
  4701. rc = -ENODEV;
  4702. goto error_no_pdata;
  4703. }
  4704. /* Default erase file to an invalid file */
  4705. ld->pip2_file_erase_file_no = PIP2_RAM_FILE;
  4706. ld->loader_pdata = pdata->loader_pdata;
  4707. ld->dev = dev;
  4708. *data = ld;
  4709. #ifdef CONFIG_TOUCHSCREEN_PARADE_BINARY_FW_UPGRADE
  4710. INIT_WORK(&ld->bl_from_file, pt_bl_from_file_work);
  4711. INIT_WORK(&ld->pip2_bl_from_file, pt_pip2_bl_from_file_work);
  4712. #endif /* CONFIG_TOUCHSCREEN_PARADE_MANUAL_TTCONFIG_UPGRADE */
  4713. #if PT_FW_UPGRADE
  4714. init_completion(&ld->int_running);
  4715. cmd->subscribe_attention(dev, PT_ATTEN_IRQ, PT_LOADER_NAME,
  4716. pt_loader_attention, PT_MODE_BOOTLOADER);
  4717. cmd->subscribe_attention(dev, PT_ATTEN_LOADER, PT_LOADER_NAME,
  4718. pt_fw_upgrade_cb, PT_MODE_UNKNOWN);
  4719. cmd->subscribe_attention(dev, PT_ATTEN_CANCEL_LOADER, PT_LOADER_NAME,
  4720. pt_cancel_fw_upgrade_cb, PT_MODE_UNKNOWN);
  4721. #endif
  4722. #if PT_FW_UPGRADE || PT_TTCONFIG_UPGRADE
  4723. pt_debug(dev, DL_INFO, "%s: INIT_WORK pt_calibrate_idacs\n",
  4724. __func__);
  4725. init_completion(&ld->calibration_complete);
  4726. INIT_WORK(&ld->calibration_work, pt_calibrate_idacs);
  4727. #endif
  4728. #ifdef CONFIG_TOUCHSCREEN_PARADE_MANUAL_TTCONFIG_UPGRADE
  4729. if (dut_gen == DUT_PIP1_ONLY)
  4730. mutex_init(&ld->config_lock);
  4731. #endif
  4732. pt_debug(dev, DL_INFO, "%s: Schedule FW upgrade work\n", __func__);
  4733. INIT_WORK(&ld->fw_and_config_upgrade, pt_fw_and_config_upgrade);
  4734. schedule_work(&ld->fw_and_config_upgrade);
  4735. pt_debug(dev, DL_INFO, "%s: Successful probe %s\n",
  4736. __func__, dev_name(dev));
  4737. return 0;
  4738. remove_files:
  4739. #ifdef CONFIG_TOUCHSCREEN_PARADE_MANUAL_TTCONFIG_UPGRADE
  4740. device_remove_file(dev, &dev_attr_config_loading);
  4741. #endif
  4742. #ifdef CONFIG_TOUCHSCREEN_PARADE_BINARY_FW_UPGRADE
  4743. device_remove_file(dev, &dev_attr_manual_upgrade);
  4744. #endif
  4745. #ifdef CONFIG_TOUCHSCREEN_PARADE_PLATFORM_FW_UPGRADE
  4746. device_remove_file(dev, &dev_attr_forced_upgrade);
  4747. #endif
  4748. #ifdef TTDL_DIAGNOSTICS
  4749. device_remove_file(dev, &dev_attr_pip2_get_last_error);
  4750. device_remove_bin_file(dev, &bin_attr_pip2_file_read);
  4751. device_remove_file(dev, &dev_attr_pip2_file_crc);
  4752. #endif
  4753. device_remove_file(dev, &dev_attr_pip2_bl_status);
  4754. device_remove_file(dev, &dev_attr_pip2_file_erase);
  4755. #ifdef CONFIG_TOUCHSCREEN_PARADE_BINARY_FW_UPGRADE
  4756. device_remove_file(dev, &dev_attr_pip2_bl_from_file);
  4757. device_remove_file(dev, &dev_attr_pip2_file_write);
  4758. device_remove_file(dev, &dev_attr_pt_bl_from_file);
  4759. device_remove_file(dev, &dev_attr_pip2_manual_ram_upgrade);
  4760. device_remove_file(dev, &dev_attr_pip2_manual_upgrade);
  4761. device_remove_file(dev, &dev_attr_update_fw);
  4762. device_remove_file(dev, &dev_attr_update_fw_status);
  4763. #endif /* CONFIG_TOUCHSCREEN_PARADE_BINARY_FW_UPGRADE */
  4764. kfree(ld->pip2_data);
  4765. kfree(ld);
  4766. error_alloc_data_failed:
  4767. error_no_pdata:
  4768. pt_debug(dev, DL_ERROR, "%s failed.\n", __func__);
  4769. return rc;
  4770. }
  4771. /*******************************************************************************
  4772. * FUNCTION: pt_loader_release
  4773. *
  4774. * SUMMARY: Remove function for loader module that does following cleanup:
  4775. * - Unsubscibe all registered attention tasks
  4776. * - Removes all created sysfs nodes
  4777. * - Frees all pointers
  4778. *
  4779. * PARAMETERS:
  4780. * *dev - pointer to device structure
  4781. * *data - pointer to the loader data
  4782. ******************************************************************************/
  4783. static void pt_loader_release(struct device *dev, void *data)
  4784. {
  4785. struct pt_loader_data *ld = (struct pt_loader_data *)data;
  4786. u8 dut_gen = cmd->request_dut_generation(dev);
  4787. #if PT_FW_UPGRADE
  4788. cmd->unsubscribe_attention(dev, PT_ATTEN_IRQ, PT_LOADER_NAME,
  4789. pt_loader_attention, PT_MODE_BOOTLOADER);
  4790. cmd->unsubscribe_attention(dev, PT_ATTEN_LOADER, PT_LOADER_NAME,
  4791. pt_fw_upgrade_cb, PT_MODE_UNKNOWN);
  4792. cmd->unsubscribe_attention(dev, PT_ATTEN_CANCEL_LOADER, PT_LOADER_NAME,
  4793. pt_cancel_fw_upgrade_cb, PT_MODE_UNKNOWN);
  4794. #endif
  4795. #if PT_FW_UPGRADE
  4796. device_remove_file(dev, &dev_attr_update_fw_status);
  4797. #endif
  4798. if (dut_gen == DUT_PIP2_CAPABLE) {
  4799. #ifdef CONFIG_TOUCHSCREEN_PARADE_BINARY_FW_UPGRADE
  4800. device_remove_file(dev, &dev_attr_update_fw);
  4801. #endif /* CONFIG_TOUCHSCREEN_PARADE_BINARY_FW_UPGRADE */
  4802. #ifdef TTDL_DIAGNOSTICS
  4803. device_remove_bin_file(dev, &bin_attr_pip2_file_read);
  4804. device_remove_file(dev, &dev_attr_pip2_file_crc);
  4805. #endif
  4806. device_remove_file(dev, &dev_attr_pip2_get_last_error);
  4807. device_remove_file(dev, &dev_attr_pip2_bl_status);
  4808. device_remove_file(dev, &dev_attr_pip2_file_erase);
  4809. #ifdef CONFIG_TOUCHSCREEN_PARADE_BINARY_FW_UPGRADE
  4810. device_remove_file(dev, &dev_attr_pip2_file_write);
  4811. device_remove_file(dev, &dev_attr_pip2_bl_from_file);
  4812. device_remove_file(dev, &dev_attr_pt_bl_from_file);
  4813. device_remove_file(dev, &dev_attr_pip2_manual_ram_upgrade);
  4814. device_remove_file(dev, &dev_attr_pip2_manual_upgrade);
  4815. #endif /* CONFIG_TOUCHSCREEN_PARADE_BINARY_FW_UPGRADE */
  4816. kfree(ld->pip2_data);
  4817. } else {
  4818. #ifdef CONFIG_TOUCHSCREEN_PARADE_BINARY_FW_UPGRADE
  4819. device_remove_file(dev, &dev_attr_update_fw);
  4820. #endif /* CONFIG_TOUCHSCREEN_PARADE_BINARY_FW_UPGRADE */
  4821. #ifdef CONFIG_TOUCHSCREEN_PARADE_MANUAL_TTCONFIG_UPGRADE
  4822. device_remove_bin_file(dev, &bin_attr_config_data);
  4823. device_remove_file(dev, &dev_attr_config_loading);
  4824. if (!ld->config_data)
  4825. kfree(ld->config_data);
  4826. #endif /* CONFIG_TOUCHSCREEN_PARADE_MANUAL_TTCONFIG_UPGRADE */
  4827. #ifdef CONFIG_TOUCHSCREEN_PARADE_BINARY_FW_UPGRADE
  4828. device_remove_file(dev, &dev_attr_pt_bl_from_file);
  4829. device_remove_file(dev, &dev_attr_manual_upgrade);
  4830. #endif /* CONFIG_TOUCHSCREEN_PARADE_BINARY_FW_UPGRADE */
  4831. #ifdef CONFIG_TOUCHSCREEN_PARADE_PLATFORM_FW_UPGRADE
  4832. device_remove_file(dev, &dev_attr_forced_upgrade);
  4833. #endif /* CONFIG_TOUCHSCREEN_PARADE_PLATFORM_FW_UPGRADE */
  4834. }
  4835. kfree(ld);
  4836. }
  4837. static struct pt_module loader_module = {
  4838. .name = PT_LOADER_NAME,
  4839. .probe = pt_loader_probe,
  4840. .release = pt_loader_release,
  4841. };
  4842. /*******************************************************************************
  4843. * FUNCTION: pt_loader_init
  4844. *
  4845. * SUMMARY: Initialize function for loader module which to register
  4846. * loader_module into TTDL module list.
  4847. *
  4848. * RETURN:
  4849. * 0 = success
  4850. * !0 = failure
  4851. *
  4852. * PARAMETERS:
  4853. * *dev - pointer to device structure
  4854. * *data - pointer to the loader data
  4855. ******************************************************************************/
  4856. static int __init pt_loader_init(void)
  4857. {
  4858. int rc;
  4859. cmd = pt_get_commands();
  4860. if (!cmd)
  4861. return -EINVAL;
  4862. rc = pt_register_module(&loader_module);
  4863. if (rc < 0) {
  4864. pr_err("%s: Error, failed registering module\n",
  4865. __func__);
  4866. return rc;
  4867. }
  4868. pr_info("%s: Parade FW Loader Driver (Version %s) rc=%d\n",
  4869. __func__, PT_DRIVER_VERSION, rc);
  4870. return 0;
  4871. }
  4872. module_init(pt_loader_init);
  4873. /*******************************************************************************
  4874. * FUNCTION: pt_loader_exit
  4875. *
  4876. * SUMMARY: Exit function for loader module which to unregister loader_module
  4877. * from TTDL module list.
  4878. *
  4879. ******************************************************************************/
  4880. static void __exit pt_loader_exit(void)
  4881. {
  4882. pt_unregister_module(&loader_module);
  4883. }
  4884. module_exit(pt_loader_exit);
  4885. MODULE_LICENSE("GPL");
  4886. MODULE_DESCRIPTION("Parade TrueTouch(R) Standard Product FW Loader Driver");
  4887. MODULE_AUTHOR("Parade Technologies <[email protected]>");