123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570 |
- /*
- * pt_core.c
- * Parade TrueTouch(TM) Standard Product Core Module.
- * For use with Parade touchscreen controllers.
- * Supported parts include:
- * TMA5XX
- * TMA448
- * TMA445A
- * TT21XXX
- * TT31XXX
- * TT4XXXX
- * TT7XXX
- * TC3XXX
- *
- * Copyright (C) 2015-2020 Parade Technologies
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2, and only version 2, as published by the
- * Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * Contact Parade Technologies at www.paradetech.com <[email protected]>
- */
- #include <linux/i2c.h>
- #include <linux/gpio.h>
- #include <linux/kthread.h>
- #include <linux/suspend.h>
- #include <glink_interface.h>
- #include <linux/remoteproc/qcom_rproc.h>
- #include "pt_regs.h"
- #if defined(CONFIG_PANEL_NOTIFIER)
- #include <linux/soc/qcom/panel_event_notifier.h>
- #endif
- #define PINCTRL_STATE_ACTIVE "pmx_ts_active"
- #define PINCTRL_STATE_SUSPEND "pmx_ts_suspend"
- #define PINCTRL_STATE_RELEASE "pmx_ts_release"
- #define FT_VTG_MIN_UV 2800000
- #define FT_VTG_MAX_UV 2800000
- #define FT_I2C_VTG_MIN_UV 1800000
- #define FT_I2C_VTG_MAX_UV 1800000
- #define PWR_SUSPEND_LOAD_UA 165
- #define I2C_SUSPEND_LOAD_UA 100
- #define PWR_ACTIVE_LOAD_MA 12000
- #define I2C_ACTIVE_LOAD_MA 30000
- #define PT_CORE_STARTUP_RETRY_COUNT 3
- #define PT_STATUS_STR_LEN (50)
- #define PT_DATA_SIZE (2 * 256)
- #if defined(CONFIG_DRM) || defined(CONFIG_PANEL_NOTIFIER)
- static struct drm_panel *active_panel;
- #endif
- MODULE_FIRMWARE(PT_FW_FILE_NAME);
- #define ENABLE_I2C_REG_ONLY
- enum core_states {
- STATE_NONE,
- STATE_RESUME,
- STATE_SUSPEND
- };
- #ifdef ENABLE_I2C_REG_ONLY
- static int pt_enable_i2c_regulator(struct pt_core_data *cd, bool en);
- #endif
- #define PT_AMBIENT_MODE
- #ifdef PT_AMBIENT_MODE
- static int pt_device_exit(struct i2c_client *client);
- int pt_device_entry(struct device *dev,
- u16 irq, size_t xfer_buf_size);
- #endif
- static const char *pt_driver_core_name = PT_CORE_NAME;
- static const char *pt_driver_core_version = PT_DRIVER_VERSION;
- static const char *pt_driver_core_date = PT_DRIVER_DATE;
- enum core_states pt_core_state = STATE_NONE;
- uint32_t pt_slate_resp_ack;
- struct pt_hid_field {
- int report_count;
- int report_size;
- int size; /* report_count * report_size */
- int offset;
- int data_type;
- int logical_min;
- int logical_max;
- /* Usage Page (Hi 16 bit) + Usage (Lo 16 bit) */
- u32 usage_page;
- u32 collection_usage_pages[PT_HID_MAX_COLLECTIONS];
- struct pt_hid_report *report;
- bool record_field;
- };
- struct pt_hid_report {
- u8 id;
- u8 type;
- int size;
- struct pt_hid_field *fields[PT_HID_MAX_FIELDS];
- int num_fields;
- int record_field_index;
- int header_size;
- int record_size;
- u32 usage_page;
- };
- struct atten_node {
- struct list_head node;
- char *id;
- struct device *dev;
- int (*func)(struct device *dev);
- int mode;
- };
- struct param_node {
- struct list_head node;
- u8 id;
- u32 value;
- u8 size;
- };
- struct module_node {
- struct list_head node;
- struct pt_module *module;
- void *data;
- };
- struct pt_hid_cmd {
- u8 opcode;
- u8 report_type;
- union {
- u8 report_id;
- u8 power_state;
- };
- u8 has_data_register;
- size_t write_length;
- u8 *write_buf;
- u8 *read_buf;
- u8 wait_interrupt;
- u8 reset_cmd;
- u16 timeout_ms;
- };
- struct pt_hid_output {
- u8 cmd_type;
- u16 length;
- u8 command_code;
- size_t write_length;
- u8 *write_buf;
- u8 novalidate;
- u8 reset_expected;
- u16 timeout_ms;
- };
- #define SET_CMD_OPCODE(byte, opcode) SET_CMD_LOW(byte, opcode)
- #define SET_CMD_REPORT_TYPE(byte, type) SET_CMD_HIGH(byte, ((type) << 4))
- #define SET_CMD_REPORT_ID(byte, id) SET_CMD_LOW(byte, id)
- #define CREATE_PIP1_FW_CMD(command) \
- .cmd_type = PIP1_CMD_TYPE_FW, \
- .command_code = command
- #define CREATE_PIP1_BL_CMD(command) \
- .cmd_type = PIP1_CMD_TYPE_BL, \
- .command_code = command
- #define PT_MAX_PR_BUF_SIZE 2048
- /*******************************************************************************
- * FUNCTION: pt_pr_buf
- *
- * SUMMARY: Print out the contents of a buffer to kmsg based on the debug level
- *
- * RETURN: Void
- *
- * PARAMETERS:
- * *dev - pointer to Device structure
- * debug_level - requested debug level to print at
- * *buf - pointer to buffer to print
- * buf_len - size of buf
- * *data_name - Descriptive name of data prefixed to data
- ******************************************************************************/
- void pt_pr_buf(struct device *dev, u8 debug_level, u8 *buf,
- u16 buf_len, const char *data_name)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- int i;
- ssize_t pr_buf_index = 0;
- int max_size;
- /* only proceed if valid debug level and there is data to print */
- if (debug_level <= cd->debug_level && buf_len > 0) {
- char *pr_buf = kzalloc(PT_MAX_PR_BUF_SIZE, GFP_KERNEL);
- if (!pr_buf)
- return;
- /*
- * With a space each printed char takes 3 bytes, subtract
- * the length of the data_name prefix as well as 11 bytes
- * for the " [0..xxx]: " printed before the data.
- */
- max_size = (PT_MAX_PR_BUF_SIZE - sizeof(data_name) - 11) / 3;
- /* Ensure pr_buf_index stays within the 1018 size */
- pr_buf_index += scnprintf(pr_buf, PT_MAX_PR_BUF_SIZE, "%s [0..%d]: ",
- data_name);
- for (i = 0; i < buf_len && i < max_size; i++)
- pr_buf_index += scnprintf(pr_buf + pr_buf_index,
- PT_MAX_PR_BUF_SIZE, "%02X ", buf[i]);
- pt_debug(dev, debug_level, "%s\n", pr_buf);
- kfree(pr_buf);
- }
- }
- EXPORT_SYMBOL_GPL(pt_pr_buf);
- #ifdef TTHE_TUNER_SUPPORT
- /*******************************************************************************
- * FUNCTION: tthe_print
- *
- * SUMMARY: Format data name and time stamp as the header and format the
- * content of input buffer with hex base to "tthe_buf". And then wake up event
- * semaphore for tthe debugfs node.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * *buf - pointer to input buffer
- * buf_len - size of input buffer
- * *data_name - pointer to data name
- ******************************************************************************/
- static int tthe_print(struct pt_core_data *cd, u8 *buf, int buf_len,
- const u8 *data_name)
- {
- int name_len = strlen(data_name);
- int i, n;
- u8 *p;
- int remain;
- u8 data_name_with_time_stamp[100];
- /* Prepend timestamp, if requested, to data_name */
- if (cd->show_timestamp) {
- scnprintf(data_name_with_time_stamp,
- sizeof(data_name_with_time_stamp),
- "[%u] %s", pt_get_time_stamp(), data_name);
- data_name = data_name_with_time_stamp;
- name_len = strlen(data_name);
- }
- mutex_lock(&cd->tthe_lock);
- if (!cd->tthe_buf)
- goto exit;
- /* Add 1 due to the '\n' that is appended at the end */
- if (cd->tthe_buf_len + name_len + buf_len + 1 > cd->tthe_buf_size)
- goto exit;
- if (name_len + buf_len == 0)
- goto exit;
- remain = cd->tthe_buf_size - cd->tthe_buf_len;
- if (remain < name_len)
- name_len = remain;
- p = cd->tthe_buf + cd->tthe_buf_len;
- memcpy(p, data_name, name_len);
- cd->tthe_buf_len += name_len;
- p += name_len;
- remain -= name_len;
- *p = 0;
- for (i = 0; i < buf_len; i++) {
- n = scnprintf(p, remain, "%02X ", buf[i]);
- if (n <= 0)
- break;
- p += n;
- remain -= n;
- cd->tthe_buf_len += n;
- }
- n = scnprintf(p, remain, "\n");
- cd->tthe_buf_len += n;
- exit:
- wake_up(&cd->wait_q);
- mutex_unlock(&cd->tthe_lock);
- return 0;
- }
- /*******************************************************************************
- * FUNCTION: _pt_request_tthe_print
- *
- * SUMMARY: Function pointer included in core_cmds to allow other modules
- * to request to print data to the "tthe_buffer".
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- ******************************************************************************/
- static int _pt_request_tthe_print(struct device *dev, u8 *buf,
- int buf_len, const u8 *data_name)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- return tthe_print(cd, buf, buf_len, data_name);
- }
- #endif
- /*******************************************************************************
- * FUNCTION: pt_platform_detect_read
- *
- * SUMMARY: To be passed to platform dectect function to perform a read
- * operation.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to Device structure
- * *buf - pointer to buffer where the data read will be stored
- * size - size to be read
- ******************************************************************************/
- static int pt_platform_detect_read(struct device *dev, void *buf, int size)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- return pt_adap_read_default(cd, buf, size);
- }
- /*******************************************************************************
- * FUNCTION: pt_add_parameter
- *
- * SUMMARY: Adds a parameter that has been altered to the parameter linked list.
- * On every reset of the DUT this linked list is traversed and all
- * parameters in it are restored to the DUT.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * param_id - parameter ID to add
- * param_value - Value corresponding to the ID
- * param_size - Size of param_value
- ******************************************************************************/
- static int pt_add_parameter(struct pt_core_data *cd,
- u8 param_id, u32 param_value, u8 param_size)
- {
- struct param_node *param, *param_new;
- /* Check if parameter already exists in the list */
- spin_lock(&cd->spinlock);
- list_for_each_entry(param, &cd->param_list, node) {
- if (param->id == param_id) {
- /* Update parameter */
- param->value = param_value;
- pt_debug(cd->dev, DL_INFO,
- "%s: Update parameter id:%d value:%d size:%d\n",
- __func__, param_id, param_value, param_size);
- goto exit_unlock;
- }
- }
- spin_unlock(&cd->spinlock);
- param_new = kzalloc(sizeof(*param_new), GFP_KERNEL);
- if (!param_new)
- return -ENOMEM;
- param_new->id = param_id;
- param_new->value = param_value;
- param_new->size = param_size;
- pt_debug(cd->dev, DL_INFO,
- "%s: Add parameter id:%d value:%d size:%d\n",
- __func__, param_id, param_value, param_size);
- spin_lock(&cd->spinlock);
- list_add(¶m_new->node, &cd->param_list);
- exit_unlock:
- spin_unlock(&cd->spinlock);
- return 0;
- }
- #ifdef TTDL_DIAGNOSTICS
- /*******************************************************************************
- * FUNCTION: pt_erase_parameter_list
- *
- * SUMMARY: Empty out the entire parameter linked list of all parameter/value
- * pairs. In some test cases this functionality is needed to ensure DUT
- * returns to a virgin state after a reset and no parameters are restored.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- ******************************************************************************/
- static int pt_erase_parameter_list(struct pt_core_data *cd)
- {
- struct param_node *pos, *temp;
- spin_lock(&cd->spinlock);
- list_for_each_entry_safe(pos, temp, &cd->param_list, node) {
- pt_debug(cd->dev, DL_INFO,
- "%s: Parameter Restore List - remove 0x%02x\n",
- __func__, pos->id);
- list_del(&pos->node);
- kfree(pos);
- }
- spin_unlock(&cd->spinlock);
- return 0;
- }
- /*******************************************************************************
- * FUNCTION: pt_count_parameter_list
- *
- * SUMMARY: Count the items in the RAM parameter restor list
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- ******************************************************************************/
- static int pt_count_parameter_list(struct pt_core_data *cd)
- {
- struct param_node *pos, *temp;
- int entries = 0;
- spin_lock(&cd->spinlock);
- list_for_each_entry_safe(pos, temp, &cd->param_list, node)
- entries++;
- spin_unlock(&cd->spinlock);
- return entries;
- }
- #endif /* TTDL_DIAGNOSTICS */
- /*******************************************************************************
- * FUNCTION: request_exclusive
- *
- * SUMMARY: Request exclusive access to the DUT
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * *ownptr - pointer to device
- * timeout_ms - Timeout value
- ******************************************************************************/
- int request_exclusive(struct pt_core_data *cd, void *ownptr,
- int timeout_ms)
- {
- int t = msecs_to_jiffies(timeout_ms);
- bool with_timeout = (timeout_ms != 0);
- pt_debug(cd->dev, DL_INFO, "%s: Attempt to Request EXCLUSIVE t=%d\n",
- __func__, timeout_ms);
- mutex_lock(&cd->system_lock);
- if (!cd->exclusive_dev && cd->exclusive_waits == 0) {
- cd->exclusive_dev = ownptr;
- goto exit;
- }
- cd->exclusive_waits++;
- wait:
- mutex_unlock(&cd->system_lock);
- if (with_timeout) {
- t = wait_event_timeout(cd->wait_q, !cd->exclusive_dev, t);
- if (IS_TMO(t)) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: tmo waiting exclusive access\n", __func__);
- return -ETIME;
- }
- } else {
- wait_event(cd->wait_q, !cd->exclusive_dev);
- }
- mutex_lock(&cd->system_lock);
- if (cd->exclusive_dev)
- goto wait;
- cd->exclusive_dev = ownptr;
- cd->exclusive_waits--;
- exit:
- mutex_unlock(&cd->system_lock);
- pt_debug(cd->dev, DL_DEBUG, "%s: request exclusive ok=%p\n",
- __func__, ownptr);
- return 0;
- }
- /*******************************************************************************
- * FUNCTION: release_exclusive_
- *
- * SUMMARY: Release exclusive access to the DUT
- *
- * RETURN:
- * 0 = success
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * *ownptr - pointer to device
- ******************************************************************************/
- static int release_exclusive_(struct pt_core_data *cd, void *ownptr)
- {
- pt_debug(cd->dev, DL_INFO, "%s: Attempt to Release EXCLUSIVE\n",
- __func__);
- if (cd->exclusive_dev != ownptr)
- return -EINVAL;
- pt_debug(cd->dev, DL_DEBUG, "%s: exclusive_dev %p freed\n",
- __func__, cd->exclusive_dev);
- cd->exclusive_dev = NULL;
- wake_up(&cd->wait_q);
- return 0;
- }
- /*******************************************************************************
- * FUNCTION: release_exclusive
- *
- * SUMMARY: Protected wrapper to release_exclusive_()
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * *ownptr - pointer to device
- ******************************************************************************/
- int release_exclusive(struct pt_core_data *cd, void *ownptr)
- {
- int rc;
- mutex_lock(&cd->system_lock);
- rc = release_exclusive_(cd, ownptr);
- mutex_unlock(&cd->system_lock);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_hid_exec_cmd_
- *
- * SUMMARY: Send the HID command to the DUT
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * *hid_cmd - pointer to the HID command to send
- ******************************************************************************/
- static int pt_hid_exec_cmd_(struct pt_core_data *cd,
- struct pt_hid_cmd *hid_cmd)
- {
- int rc = 0;
- u8 *cmd;
- u16 cmd_length;
- u8 cmd_offset = 0;
- cmd_length = 2 /* command register */
- + 2 /* command */
- + (hid_cmd->report_id >= 0XF ? 1 : 0) /* Report ID */
- + (hid_cmd->has_data_register ? 2 : 0) /* Data register */
- + hid_cmd->write_length; /* Data length */
- if (cmd_length < 4 || cmd_length > PT_MAX_PIP1_MSG_SIZE)
- return -EPROTO;
- cmd = kzalloc(cmd_length, GFP_KERNEL);
- if (!cmd)
- return -ENOMEM;
- /* Set Command register */
- memcpy(&cmd[cmd_offset], &cd->hid_desc.command_register,
- sizeof(cd->hid_desc.command_register));
- cmd_offset += sizeof(cd->hid_desc.command_register);
- /* Set Command */
- SET_CMD_REPORT_TYPE(cmd[cmd_offset], hid_cmd->report_type);
- if (hid_cmd->report_id >= 0XF)
- SET_CMD_REPORT_ID(cmd[cmd_offset], 0xF);
- else
- SET_CMD_REPORT_ID(cmd[cmd_offset], hid_cmd->report_id);
- cmd_offset++;
- SET_CMD_OPCODE(cmd[cmd_offset], hid_cmd->opcode);
- cmd_offset++;
- if (hid_cmd->report_id >= 0XF) {
- cmd[cmd_offset] = hid_cmd->report_id;
- cmd_offset++;
- }
- /* Set Data register */
- if (hid_cmd->has_data_register) {
- memcpy(&cmd[cmd_offset], &cd->hid_desc.data_register,
- sizeof(cd->hid_desc.data_register));
- cmd_offset += sizeof(cd->hid_desc.data_register);
- }
- /* Set Data */
- if (hid_cmd->write_length && hid_cmd->write_buf) {
- memcpy(&cmd[cmd_offset], hid_cmd->write_buf,
- hid_cmd->write_length);
- cmd_offset += hid_cmd->write_length;
- }
- pt_debug(cd->dev, DL_INFO,
- ">>> %s: Write Buffer Size[%d] Cmd[0x%02X]\n",
- __func__, cmd_length, hid_cmd->report_id);
- pt_pr_buf(cd->dev, DL_DEBUG, cmd, cmd_length, ">>> CMD");
- rc = pt_adap_write_read_specific(cd, cmd_length, cmd,
- hid_cmd->read_buf);
- if (rc)
- pt_debug(cd->dev, DL_ERROR,
- "%s: Fail pt_adap_transfer\n", __func__);
- kfree(cmd);
- return rc;
- }
- #ifdef TTDL_DIAGNOSTICS
- /*******************************************************************************
- * FUNCTION: pt_toggle_err_gpio
- *
- * SUMMARY: Toggles the pre-defined error GPIO
- *
- * RETURN: n/a
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * type - type of err that occurred
- ******************************************************************************/
- void pt_toggle_err_gpio(struct pt_core_data *cd, u8 type)
- {
- pt_debug(cd->dev, DL_DEBUG, "%s called with type = %d\n",
- __func__, type);
- if (cd->err_gpio && type == cd->err_gpio_type) {
- pt_debug(cd->dev, DL_WARN, "%s: Toggle ERR GPIO\n", __func__);
- gpio_direction_output(cd->err_gpio,
- !gpio_get_value(cd->err_gpio));
- }
- }
- /*******************************************************************************
- * FUNCTION: _pt_request_toggle_err_gpio
- *
- * SUMMARY: Function pointer included in core_cmds to allow other modules
- * to request to toggle the err_gpio
- *
- * RETURN: n/a
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * type - type of err that occurred
- ******************************************************************************/
- void _pt_request_toggle_err_gpio(struct device *dev, u8 type)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- pt_toggle_err_gpio(cd, type);
- }
- #endif /* TTDL_DIAGNOSTICS */
- /*******************************************************************************
- * FUNCTION: pt_hid_exec_cmd_and_wait_
- *
- * SUMMARY: Send the HID command to the DUT and wait for the response
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * *hid_cmd - pointer to the HID command to send
- ******************************************************************************/
- static int pt_hid_exec_cmd_and_wait_(struct pt_core_data *cd,
- struct pt_hid_cmd *hid_cmd)
- {
- int rc = 0;
- int t;
- u16 timeout_ms;
- int *cmd_state;
- if (hid_cmd->reset_cmd)
- cmd_state = &cd->hid_reset_cmd_state;
- else
- cmd_state = &cd->hid_cmd_state;
- if (hid_cmd->wait_interrupt) {
- mutex_lock(&cd->system_lock);
- *cmd_state = 1;
- mutex_unlock(&cd->system_lock);
- }
- rc = pt_hid_exec_cmd_(cd, hid_cmd);
- if (rc) {
- if (hid_cmd->wait_interrupt)
- goto error;
- goto exit;
- }
- if (!hid_cmd->wait_interrupt)
- goto exit;
- if (hid_cmd->timeout_ms)
- timeout_ms = hid_cmd->timeout_ms;
- else
- timeout_ms = PT_HID_CMD_DEFAULT_TIMEOUT;
- t = wait_event_timeout(cd->wait_q, (*cmd_state == 0),
- msecs_to_jiffies(timeout_ms));
- if (IS_TMO(t)) {
- #ifdef TTDL_DIAGNOSTICS
- cd->bus_transmit_error_count++;
- pt_toggle_err_gpio(cd, PT_ERR_GPIO_I2C_TRANS);
- #endif /* TTDL_DIAGNOSTICS */
- pt_debug(cd->dev, DL_ERROR,
- "%s: HID output cmd execution timed out\n",
- __func__);
- rc = -ETIME;
- goto error;
- }
- goto exit;
- error:
- mutex_lock(&cd->system_lock);
- *cmd_state = 0;
- mutex_unlock(&cd->system_lock);
- exit:
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_hid_cmd_reset_
- *
- * SUMMARY: Send the HID RESET command to the DUT
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- ******************************************************************************/
- static int pt_hid_cmd_reset_(struct pt_core_data *cd)
- {
- struct pt_hid_cmd hid_cmd = {
- .opcode = HID_CMD_RESET,
- .wait_interrupt = 1,
- .reset_cmd = 1,
- .timeout_ms = PT_HID_CMD_DEFAULT_TIMEOUT,
- };
- return pt_hid_exec_cmd_and_wait_(cd, &hid_cmd);
- }
- /*******************************************************************************
- * FUNCTION: pt_hid_cmd_reset
- *
- * SUMMARY: Wrapper function for pt_hid_cmd_reset_ that guarantees exclusive
- * access.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- ******************************************************************************/
- static int pt_hid_cmd_reset(struct pt_core_data *cd)
- {
- int rc = 0;
- rc = request_exclusive(cd, cd->dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail get exclusive ex=%p own=%p\n",
- __func__, cd->exclusive_dev, cd->dev);
- return rc;
- }
- pt_debug(cd->dev, DL_INFO, "%s: Send HID Reset command\n", __func__);
- rc = pt_hid_cmd_reset_(cd);
- if (release_exclusive(cd, cd->dev) < 0)
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail to release exclusive\n", __func__);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_hid_cmd_set_power_
- *
- * SUMMARY: Send hid cmd to set power state for the DUT and wait for response
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * power_state - power state to set(HID_POWER_ON/HID_POWER_SLEEP)
- ******************************************************************************/
- static int pt_hid_cmd_set_power_(struct pt_core_data *cd,
- u8 power_state)
- {
- int rc = 0;
- struct pt_hid_cmd hid_cmd = {
- .opcode = HID_CMD_SET_POWER,
- .wait_interrupt = 1,
- .timeout_ms = PT_HID_CMD_DEFAULT_TIMEOUT,
- };
- hid_cmd.power_state = power_state;
- /* The chip won't give response if goes to Deep Standby */
- if (power_state == HID_POWER_STANDBY) {
- rc = pt_hid_exec_cmd_(cd, &hid_cmd);
- if (rc)
- pt_debug(cd->dev, DL_ERROR,
- "%s: Failed to set power to state:%d\n",
- __func__, power_state);
- else
- cd->fw_sys_mode_in_standby_state = true;
- return rc;
- }
- cd->fw_sys_mode_in_standby_state = false;
- rc = pt_hid_exec_cmd_and_wait_(cd, &hid_cmd);
- if (rc) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: Failed to set power to state:%d\n",
- __func__, power_state);
- return rc;
- }
- /* validate */
- if ((cd->response_buf[2] != HID_RESPONSE_REPORT_ID)
- || ((cd->response_buf[3] & 0x3) != power_state)
- || ((cd->response_buf[4] & 0xF) != HID_CMD_SET_POWER))
- rc = -EINVAL;
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_hid_cmd_set_power
- *
- * SUMMARY: Wrapper function for pt_hid_cmd_set_power_ that guarantees
- * exclusive access.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * power_state - power state to set(HID_POWER_ON/HID_POWER_SLEEP)
- ******************************************************************************/
- static int pt_hid_cmd_set_power(struct pt_core_data *cd,
- u8 power_state)
- {
- int rc;
- rc = request_exclusive(cd, cd->dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail get exclusive ex=%p own=%p\n",
- __func__, cd->exclusive_dev, cd->dev);
- return rc;
- }
- rc = pt_hid_cmd_set_power_(cd, power_state);
- if (release_exclusive(cd, cd->dev) < 0)
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail to release exclusive\n", __func__);
- return rc;
- }
- static const u16 crc_table[16] = {
- 0x0000, 0x1021, 0x2042, 0x3063,
- 0x4084, 0x50a5, 0x60c6, 0x70e7,
- 0x8108, 0x9129, 0xa14a, 0xb16b,
- 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
- };
- /*******************************************************************************
- * FUNCTION: _pt_compute_crc
- *
- * SUMMARY: Calculate CRC by CRC table.
- *
- * RETURN:
- * CRC calculation result
- *
- * PARAMETERS:
- * *buf - pointer to the data array to be calculated
- * size - size of data array
- ******************************************************************************/
- static u16 _pt_compute_crc(u8 *buf, u32 size)
- {
- u16 remainder = 0xFFFF;
- u16 xor_mask = 0x0000;
- u32 index;
- u32 byte_value;
- u32 table_index;
- u32 crc_bit_width = sizeof(u16) * 8;
- /* Divide the message by polynomial, via the table. */
- for (index = 0; index < size; index++) {
- byte_value = buf[index];
- table_index = ((byte_value >> 4) & 0x0F)
- ^ (remainder >> (crc_bit_width - 4));
- remainder = crc_table[table_index] ^ (remainder << 4);
- table_index = (byte_value & 0x0F)
- ^ (remainder >> (crc_bit_width - 4));
- remainder = crc_table[table_index] ^ (remainder << 4);
- }
- /* Perform the final remainder CRC. */
- return remainder ^ xor_mask;
- }
- u16 ccitt_Table[] = {
- 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
- 0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF,
- 0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6,
- 0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE,
- 0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485,
- 0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D,
- 0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4,
- 0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC,
- 0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823,
- 0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B,
- 0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12,
- 0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A,
- 0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41,
- 0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49,
- 0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70,
- 0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78,
- 0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F,
- 0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067,
- 0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E,
- 0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256,
- 0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D,
- 0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
- 0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C,
- 0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634,
- 0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB,
- 0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3,
- 0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A,
- 0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92,
- 0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9,
- 0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1,
- 0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8,
- 0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0,
- };
- /*******************************************************************************
- * FUNCTION: crc_ccitt_calculate
- *
- * SUMMARY: Calculate CRC with ccitt standard by CRC table.
- *
- * RETURN:
- * CRC calculation result
- *
- * PARAMETERS:
- * *q - pointer to the data array to be calculated
- * len - size of data array
- ******************************************************************************/
- static unsigned short crc_ccitt_calculate(unsigned char *q, int len)
- {
- unsigned short crc = 0xffff;
- while (len-- > 0)
- crc = ccitt_Table[(crc >> 8 ^ *q++) & 0xff] ^ (crc << 8);
- return crc;
- }
- /*******************************************************************************
- * FUNCTION: pt_pip2_cmd_calculate_crc
- *
- * SUMMARY: Calculate the CRC of a command packet
- *
- * RETURN: void
- *
- * PARAMETERS:
- * *cmd - pointer to command data
- * extra_bytes - Extra bytes included in command length
- ******************************************************************************/
- static void pt_pip2_cmd_calculate_crc(struct pip2_cmd_structure *cmd,
- u8 extra_bytes)
- {
- u8 buf[PT_MAX_PIP2_MSG_SIZE + 1] = {0};
- unsigned short crc;
- buf[0] = cmd->len & 0xff;
- buf[1] = (cmd->len & 0xff00) >> 8;
- buf[2] = cmd->seq;
- buf[3] = cmd->id;
- memcpy(&buf[4], cmd->data, cmd->len - extra_bytes);
- /* Calculate the CRC for the first 4 bytes above and the data payload */
- crc = crc_ccitt_calculate(buf, 4 + (cmd->len - extra_bytes));
- cmd->crc[0] = (crc & 0xff00) >> 8;
- cmd->crc[1] = (crc & 0xff);
- }
- /*******************************************************************************
- * FUNCTION: pt_pip2_get_next_cmd_seq
- *
- * SUMMARY: Gets the next sequence number for a PIP2 command. The sequence
- * number is a 3 bit value (bits [0-2]) but because TTDL will always have
- * the TAG bit set (bit 3), the counter starts at 0x08 and goes to 0x0F.
- * If the "force_pip2_seq" holds a valid seq value (0x08-0x0F) then do not
- * increment, just use the forced value.
- *
- * RETURN: Next command sequence number [0x08-0x0F]
- *
- * PARAMETERS:
- * *cd - pointer to core data
- ******************************************************************************/
- static u8 pt_pip2_get_next_cmd_seq(struct pt_core_data *cd)
- {
- #ifdef TTDL_DIAGNOSTICS
- if (cd->force_pip2_seq <= 0x07) {
- cd->pip2_cmd_tag_seq++;
- if (cd->pip2_cmd_tag_seq > 0x0F)
- cd->pip2_cmd_tag_seq = 0x08;
- } else {
- cd->pip2_cmd_tag_seq = cd->force_pip2_seq;
- }
- #else
- cd->pip2_cmd_tag_seq++;
- if (cd->pip2_cmd_tag_seq > 0x0F)
- cd->pip2_cmd_tag_seq = 0x08;
- #endif
- return cd->pip2_cmd_tag_seq;
- }
- /*
- * Following macros are to define the response time (the interval between PIP2
- * command finishes sending and INT pin falls). The unit is in microsecond.
- * It has different time settings between the solution GPIO polling and Bus
- * polling due to the considration for system load.
- */
- #ifdef PT_POLL_RESP_BY_BUS
- #define POLL_RETRY_DEFAULT_INTERVAL 50
- #define PIP2_RESP_DEFAULT_TIME_MIN 50
- #define PIP2_RESP_DEFAULT_TIME_MAX (PT_PIP_CMD_DEFAULT_TIMEOUT * 1000)
- #define PIP2_RESP_FILE_WRITE_TIME_MIN 220
- #define PIP2_RESP_FILE_IOCTL_TIME_MAX (PT_PIP2_CMD_FILE_ERASE_TIMEOUT * 1000)
- #else
- #define POLL_RETRY_DEFAULT_INTERVAL 20
- #define PIP2_RESP_DEFAULT_TIME_MIN 20
- #define PIP2_RESP_DEFAULT_TIME_MAX (PT_PIP_CMD_DEFAULT_TIMEOUT * 1000)
- #define PIP2_RESP_FILE_WRITE_TIME_MIN 20
- #define PIP2_RESP_FILE_IOCTL_TIME_MAX (PT_PIP2_CMD_FILE_ERASE_TIMEOUT * 1000)
- #endif
- /*
- * id: the command id defined in PIP2
- * response_len: the (maximum) length of response.
- * response_time_min: minimum response time in microsecond
- * response_time_max: maximum response time in microsecond
- */
- static const struct pip2_cmd_response_structure pip2_cmd_response[] = {
- {.id = PIP2_CMD_ID_PING,
- .response_len = 255,
- .response_time_min = PIP2_RESP_DEFAULT_TIME_MIN,
- .response_time_max = PIP2_RESP_DEFAULT_TIME_MAX},
- {.id = PIP2_CMD_ID_STATUS,
- .response_len = PIP2_EXTRA_BYTES_NUM + 5,
- .response_time_min = PIP2_RESP_DEFAULT_TIME_MIN,
- .response_time_max = PIP2_RESP_DEFAULT_TIME_MAX},
- {.id = PIP2_CMD_ID_CTRL,
- .response_len = PIP2_EXTRA_BYTES_NUM + 1,
- .response_time_min = PIP2_RESP_DEFAULT_TIME_MIN,
- .response_time_max = PT_PIP2_CMD_FILE_ERASE_TIMEOUT},
- {.id = PIP2_CMD_ID_CONFIG,
- .response_len = PIP2_EXTRA_BYTES_NUM + 1,
- .response_time_min = PIP2_RESP_DEFAULT_TIME_MIN,
- .response_time_max = PIP2_RESP_DEFAULT_TIME_MAX},
- {.id = PIP2_CMD_ID_CLEAR,
- .response_len = PIP2_EXTRA_BYTES_NUM + 0,
- .response_time_min = PIP2_RESP_DEFAULT_TIME_MIN,
- .response_time_max = PIP2_RESP_DEFAULT_TIME_MAX},
- {.id = PIP2_CMD_ID_RESET,
- .response_len = PIP2_EXTRA_BYTES_NUM + 1,
- .response_time_min = PIP2_RESP_DEFAULT_TIME_MIN,
- .response_time_max = PIP2_RESP_DEFAULT_TIME_MAX},
- {.id = PIP2_CMD_ID_VERSION,
- .response_len = PIP2_EXTRA_BYTES_NUM + 23,
- .response_time_min = PIP2_RESP_DEFAULT_TIME_MIN,
- .response_time_max = PIP2_RESP_DEFAULT_TIME_MAX},
- {.id = PIP2_CMD_ID_FILE_OPEN,
- .response_len = PIP2_EXTRA_BYTES_NUM + 2,
- .response_time_min = PIP2_RESP_DEFAULT_TIME_MIN,
- .response_time_max = PIP2_RESP_DEFAULT_TIME_MAX},
- {.id = PIP2_CMD_ID_FILE_CLOSE,
- .response_len = PIP2_EXTRA_BYTES_NUM + 1,
- .response_time_min = PIP2_RESP_DEFAULT_TIME_MIN,
- .response_time_max = PIP2_RESP_DEFAULT_TIME_MAX},
- {.id = PIP2_CMD_ID_FILE_READ,
- .response_len = 255,
- .response_time_min = PIP2_RESP_DEFAULT_TIME_MIN,
- .response_time_max = PIP2_RESP_DEFAULT_TIME_MAX},
- {.id = PIP2_CMD_ID_FILE_WRITE,
- .response_len = PIP2_EXTRA_BYTES_NUM + 1,
- .response_time_min = PIP2_RESP_FILE_WRITE_TIME_MIN,
- .response_time_max = PIP2_RESP_DEFAULT_TIME_MAX},
- {.id = PIP2_CMD_ID_FILE_IOCTL,
- .response_len = PIP2_EXTRA_BYTES_NUM + 10,
- .response_time_min = PIP2_RESP_DEFAULT_TIME_MIN,
- .response_time_max = PIP2_RESP_FILE_IOCTL_TIME_MAX},
- {.id = PIP2_CMD_ID_FLASH_INFO,
- .response_len = PIP2_EXTRA_BYTES_NUM + 17,
- .response_time_min = PIP2_RESP_DEFAULT_TIME_MIN,
- .response_time_max = PIP2_RESP_DEFAULT_TIME_MAX},
- {.id = PIP2_CMD_ID_EXECUTE,
- .response_len = PIP2_EXTRA_BYTES_NUM + 1,
- .response_time_min = PIP2_RESP_DEFAULT_TIME_MIN,
- .response_time_max = PIP2_RESP_DEFAULT_TIME_MAX},
- {.id = PIP2_CMD_ID_GET_LAST_ERRNO,
- .response_len = PIP2_EXTRA_BYTES_NUM + 3,
- .response_time_min = PIP2_RESP_DEFAULT_TIME_MIN,
- .response_time_max = PIP2_RESP_DEFAULT_TIME_MAX},
- {.id = PIP2_CMD_ID_EXIT_HOST_MODE,
- .response_len = PIP2_EXTRA_BYTES_NUM + 1,
- .response_time_min = PIP2_RESP_DEFAULT_TIME_MIN,
- .response_time_max = PIP2_RESP_DEFAULT_TIME_MAX},
- {.id = PIP2_CMD_ID_READ_GPIO,
- .response_len = PIP2_EXTRA_BYTES_NUM + 5,
- .response_time_min = PIP2_RESP_DEFAULT_TIME_MIN,
- .response_time_max = PIP2_RESP_DEFAULT_TIME_MAX},
- {.id = PIP2_CMD_EXECUTE_SCAN,
- .response_len = PIP2_EXTRA_BYTES_NUM + 1,
- .response_time_min = PIP2_RESP_DEFAULT_TIME_MIN,
- .response_time_max = PIP2_RESP_DEFAULT_TIME_MAX},
- {.id = PIP2_CMD_SET_PARAMETER,
- .response_len = PIP2_EXTRA_BYTES_NUM + 1,
- .response_time_min = PIP2_RESP_DEFAULT_TIME_MIN,
- .response_time_max = PIP2_RESP_DEFAULT_TIME_MAX},
- {.id = PIP2_CMD_GET_PARAMETER,
- .response_len = PIP2_EXTRA_BYTES_NUM + 7,
- .response_time_min = PIP2_RESP_DEFAULT_TIME_MIN,
- .response_time_max = PIP2_RESP_DEFAULT_TIME_MAX},
- {.id = PIP2_CMD_SET_DDI_REG,
- .response_len = PIP2_EXTRA_BYTES_NUM + 1,
- .response_time_min = PIP2_RESP_DEFAULT_TIME_MIN,
- .response_time_max = PIP2_RESP_DEFAULT_TIME_MAX},
- {.id = PIP2_CMD_GET_DDI_REG,
- .response_len = PIP2_EXTRA_BYTES_NUM + 249,
- .response_time_min = PIP2_RESP_DEFAULT_TIME_MIN,
- .response_time_max = PIP2_RESP_DEFAULT_TIME_MAX},
- {.id = PIP2_CMD_ID_END,
- .response_len = 255,
- .response_time_min = PIP2_RESP_DEFAULT_TIME_MIN,
- .response_time_max = PIP2_RESP_DEFAULT_TIME_MAX}
- };
- /*******************************************************************************
- * FUNCTION: pt_pip2_get_cmd_response_len
- *
- * SUMMARY: Gets the expected response length based on the command ID
- *
- * RETURN: Expected response length
- *
- * PARAMETERS:
- * id - Command ID (-1 means input ID is not in list of PIP2 command)
- ******************************************************************************/
- static int pt_pip2_get_cmd_response_len(u8 id)
- {
- const struct pip2_cmd_response_structure *p = pip2_cmd_response;
- while ((p->id != id) && (p->id != PIP2_CMD_ID_END))
- p++;
- if (p->id != PIP2_CMD_ID_END)
- return p->response_len;
- else
- return -EPERM;
- }
- /*******************************************************************************
- * FUNCTION: pt_pip2_get_cmd_resp_time_min
- *
- * SUMMARY: Gets the minimum response time (the interval between PIP2 command
- * finishes sending and INT pin falls) based on the command ID
- *
- * RETURN: Estimated minimum response time in microsecond
- *
- * PARAMETERS:
- * id - Command ID
- ******************************************************************************/
- static u32 pt_pip2_get_cmd_resp_time_min(u8 id)
- {
- const struct pip2_cmd_response_structure *p = pip2_cmd_response;
- while ((p->id != id) && (p->id != PIP2_CMD_ID_END))
- p++;
- if (p->id != PIP2_CMD_ID_END)
- return p->response_time_min;
- else
- return PIP2_RESP_DEFAULT_TIME_MIN;
- }
- /*******************************************************************************
- * FUNCTION: pt_pip2_get_cmd_resp_time_max
- *
- * SUMMARY: Gets the maximum response time (the interval between PIP2 command
- * finishes sending and INT pin falls) based on the command ID
- *
- * RETURN: Estimated maximum response time in microsecond
- *
- * PARAMETERS:
- * id - Command ID
- ******************************************************************************/
- static u32 pt_pip2_get_cmd_resp_time_max(u8 id)
- {
- const struct pip2_cmd_response_structure *p = pip2_cmd_response;
- while ((p->id != id) && (p->id != PIP2_CMD_ID_END))
- p++;
- if (p->id != PIP2_CMD_ID_END)
- return p->response_time_max;
- else
- return PIP2_RESP_DEFAULT_TIME_MAX;
- }
- /*******************************************************************************
- * FUNCTION: pt_pip2_validate_response
- *
- * SUMMARY: Validate the response of PIP2 command.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * *pip2_cmd - pointer to PIP2 command to send
- * *read_buf - pointer to response buffer
- * actual_read_len - actual read length of the response
- ******************************************************************************/
- static int pt_pip2_validate_response(struct pt_core_data *cd,
- struct pip2_cmd_structure *pip2_cmd, u8 *read_buf,
- u16 actual_read_len)
- {
- int rc = 0;
- u8 response_seq = 0;
- u8 reserved_bits = 0;
- u8 cmd_id = 0;
- u8 response_bit = 0;
- unsigned short calc_crc = 0;
- unsigned short resp_crc = 0;
- /* Verify the length of response buffer */
- if (actual_read_len < PT_MIN_PIP2_PACKET_SIZE) {
- pt_debug(cd->dev, DL_ERROR,
- "%s cmd[0x%02X] read length ERR: read_len = %d\n",
- __func__, pip2_cmd->id, actual_read_len);
- rc = -EINVAL;
- goto exit;
- }
- /* Verify the CRC */
- calc_crc = crc_ccitt_calculate(read_buf, actual_read_len - 2);
- resp_crc = read_buf[actual_read_len - 2] << 8;
- resp_crc |= read_buf[actual_read_len - 1];
- if (resp_crc != calc_crc) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: cmd[0x%02X] CRC ERR: calc=0x%04X rsp=0x%04X\n",
- __func__, pip2_cmd->id, calc_crc, resp_crc);
- #ifdef TTDL_DIAGNOSTICS
- cd->pip2_crc_error_count++;
- #endif /* TTDL_DIAGNOSTICS */
- rc = -EINVAL;
- goto exit;
- }
- /* Verify the response bit is set */
- response_bit = read_buf[PIP2_RESP_REPORT_ID_OFFSET] & 0x80;
- if (!response_bit) {
- pt_debug(cd->dev, DL_ERROR,
- "%s cmd[0x%02X] response bit ERR: response_bit = %d\n",
- __func__, pip2_cmd->id, response_bit);
- rc = -EINVAL;
- goto exit;
- }
- /* Verify the command ID matches from command to response */
- cmd_id = read_buf[PIP2_RESP_REPORT_ID_OFFSET] & 0x7F;
- if (cmd_id != pip2_cmd->id) {
- pt_debug(cd->dev, DL_ERROR,
- "%s cmd[0x%02X] command ID ERR: cmd_id = 0x%02X\n",
- __func__, pip2_cmd->id, cmd_id);
- rc = -EINVAL;
- goto exit;
- }
- /* Verify the SEQ number matches from command to response */
- response_seq = read_buf[PIP2_RESP_SEQUENCE_OFFSET] & 0x0F;
- if ((pip2_cmd->seq & 0x0F) != response_seq) {
- pt_debug(cd->dev, DL_ERROR,
- "%s cmd[0x%02X] send_seq = 0x%02X, resp_seq = 0x%02X\n",
- __func__, pip2_cmd->id,
- pip2_cmd->seq, response_seq);
- rc = -EINVAL;
- goto exit;
- }
- /* Verify the reserved bits are 0 */
- reserved_bits = read_buf[PIP2_RESP_SEQUENCE_OFFSET] & 0xF0;
- if (reserved_bits)
- pt_debug(cd->dev, DL_WARN,
- "%s cmd[0x%02X] reserved_bits = 0x%02X\n",
- __func__, pip2_cmd->id, reserved_bits);
- exit:
- if (rc)
- pt_pr_buf(cd->dev, DL_WARN, cd->input_buf, actual_read_len,
- "PIP RSP:");
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_hid_output_validate_bl_response
- *
- * SUMMARY: Validate the response of bootloader command.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * *hid_output - pointer to hid output data structure
- ******************************************************************************/
- static int pt_hid_output_validate_bl_response(
- struct pt_core_data *cd,
- struct pt_hid_output *hid_output)
- {
- u16 size;
- u16 crc;
- u8 status;
- size = get_unaligned_le16(&cd->response_buf[0]);
- if (hid_output->reset_expected && !size)
- return 0;
- if (cd->response_buf[PIP1_RESP_REPORT_ID_OFFSET]
- != PT_PIP_BL_RESPONSE_REPORT_ID) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: BL output response, wrong report_id\n", __func__);
- return -EPROTO;
- }
- if (cd->response_buf[4] != PIP1_BL_SOP) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: BL output response, wrong SOP\n", __func__);
- return -EPROTO;
- }
- if (cd->response_buf[size - 1] != PIP1_BL_EOP) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: BL output response, wrong EOP\n", __func__);
- return -EPROTO;
- }
- crc = _pt_compute_crc(&cd->response_buf[4], size - 7);
- if (cd->response_buf[size - 3] != LOW_BYTE(crc)
- || cd->response_buf[size - 2] != HI_BYTE(crc)) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: BL output response, wrong CRC 0x%X\n",
- __func__, crc);
- return -EPROTO;
- }
- status = cd->response_buf[5];
- if (status) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: BL output response, ERROR:%d\n",
- __func__, status);
- return -EPROTO;
- }
- return 0;
- }
- /*******************************************************************************
- * FUNCTION: pt_hid_output_validate_app_response
- *
- * SUMMARY: Validate the response of application command.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * *hid_output - pointer to hid output data structure
- ******************************************************************************/
- static int pt_hid_output_validate_app_response(
- struct pt_core_data *cd,
- struct pt_hid_output *hid_output)
- {
- int command_code;
- u16 size;
- size = get_unaligned_le16(&cd->response_buf[0]);
- if (hid_output->reset_expected && !size)
- return 0;
- if (cd->response_buf[PIP1_RESP_REPORT_ID_OFFSET]
- != PT_PIP_NON_HID_RESPONSE_ID) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: APP output response, wrong report_id\n", __func__);
- return -EPROTO;
- }
- command_code = cd->response_buf[PIP1_RESP_COMMAND_ID_OFFSET]
- & PIP1_RESP_COMMAND_ID_MASK;
- if (command_code != hid_output->command_code) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: APP output response, wrong command_code:%X\n",
- __func__, command_code);
- return -EPROTO;
- }
- return 0;
- }
- /*******************************************************************************
- * FUNCTION: pt_check_set_parameter
- *
- * SUMMARY: Check command input and response for Set Parameter command.And
- * store the parameter to the list for resume work if pass the check.
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * *hid_output - pointer to hid output data structure
- * raw - flag to show if output cmd is user cmd(1:user cmd)
- ******************************************************************************/
- static void pt_check_set_parameter(struct pt_core_data *cd,
- struct pt_hid_output *hid_output, bool raw)
- {
- u8 *param_buf;
- u32 param_value = 0;
- u8 param_size;
- u8 param_id;
- int i = 0;
- if (!(cd->cpdata->flags & PT_CORE_FLAG_RESTORE_PARAMETERS))
- return;
- /* Check command input for Set Parameter command */
- if (raw && hid_output->length >= 10 && hid_output->length <= 13
- && !memcmp(&hid_output->write_buf[0],
- &cd->hid_desc.output_register,
- sizeof(cd->hid_desc.output_register))
- && hid_output->write_buf[4] ==
- PT_PIP_NON_HID_COMMAND_ID
- && hid_output->write_buf[6] ==
- PIP1_CMD_ID_SET_PARAM)
- param_buf = &hid_output->write_buf[7];
- else if (!raw && hid_output->cmd_type == PIP1_CMD_TYPE_FW
- && hid_output->command_code == PIP1_CMD_ID_SET_PARAM
- && hid_output->write_length >= 3
- && hid_output->write_length <= 6)
- param_buf = &hid_output->write_buf[0];
- else
- return;
- /* Get parameter ID, size and value */
- param_id = param_buf[0];
- param_size = param_buf[1];
- if (param_size > 4) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: Invalid parameter size\n", __func__);
- return;
- }
- param_buf = ¶m_buf[2];
- while (i < param_size)
- param_value += *(param_buf++) << (8 * i++);
- /* Check command response for Set Parameter command */
- if (cd->response_buf[2] != PT_PIP_NON_HID_RESPONSE_ID
- || (cd->response_buf[4] &
- PIP1_RESP_COMMAND_ID_MASK) !=
- PIP1_CMD_ID_SET_PARAM
- || cd->response_buf[5] != param_id
- || cd->response_buf[6] != param_size) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: Set Parameter command not successful\n",
- __func__);
- return;
- }
- pt_add_parameter(cd, param_id, param_value, param_size);
- }
- /*******************************************************************************
- * FUNCTION: pt_check_command
- *
- * SUMMARY: Check the output command. The function pt_check_set_parameter() is
- * called here to check output command and store parameter to the list.
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * *hid_output - pointer to hid output data structure
- * raw - flag to show if output cmd is user cmd(1:user cmd)
- ******************************************************************************/
- static void pt_check_command(struct pt_core_data *cd,
- struct pt_hid_output *hid_output, bool raw)
- {
- pt_check_set_parameter(cd, hid_output, raw);
- }
- /*******************************************************************************
- * FUNCTION: pt_hid_output_validate_response
- *
- * SUMMARY: Validate the response of application or bootloader command.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * *hid_output - pointer to hid output data structure
- ******************************************************************************/
- static int pt_hid_output_validate_response(struct pt_core_data *cd,
- struct pt_hid_output *hid_output)
- {
- if (hid_output->cmd_type == PIP1_CMD_TYPE_BL)
- return pt_hid_output_validate_bl_response(cd, hid_output);
- return pt_hid_output_validate_app_response(cd, hid_output);
- }
- /*******************************************************************************
- * FUNCTION: pt_hid_send_output_user_
- *
- * SUMMARY: Blindly send user data to the DUT.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * *hid_output - pointer to the command to send
- ******************************************************************************/
- static int pt_hid_send_output_user_(struct pt_core_data *cd,
- struct pt_hid_output *hid_output)
- {
- int rc = 0;
- int cmd;
- if (!hid_output->length || !hid_output->write_buf)
- return -EINVAL;
- if (cd->pip2_prot_active) {
- cmd = hid_output->write_buf[PIP2_CMD_COMMAND_ID_OFFSET];
- cmd &= PIP2_CMD_COMMAND_ID_MASK;
- } else
- cmd = hid_output->write_buf[PIP1_CMD_COMMAND_ID_OFFSET];
- pt_debug(cd->dev, DL_INFO,
- ">>> %s: Write Buffer Size[%d] Cmd[0x%02X]\n",
- __func__, hid_output->length, cmd);
- pt_pr_buf(cd->dev, DL_DEBUG, hid_output->write_buf,
- hid_output->length, ">>> User CMD");
- rc = pt_adap_write_read_specific(cd, hid_output->length,
- hid_output->write_buf, NULL);
- if (rc)
- pt_debug(cd->dev, DL_ERROR,
- "%s: Fail pt_adap_transfer\n", __func__);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_hid_send_output_user_and_wait_
- *
- * SUMMARY: Blindly send user data to the DUT and wait for the response.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * *hid_output - pointer to the command to send
- ******************************************************************************/
- static int pt_hid_send_output_user_and_wait_(struct pt_core_data *cd,
- struct pt_hid_output *hid_output)
- {
- int rc = 0;
- int t;
- mutex_lock(&cd->system_lock);
- cd->hid_cmd_state = PIP1_CMD_ID_USER_CMD + 1;
- mutex_unlock(&cd->system_lock);
- rc = pt_hid_send_output_user_(cd, hid_output);
- if (rc)
- goto error;
- t = wait_event_timeout(cd->wait_q, (cd->hid_cmd_state == 0),
- msecs_to_jiffies(cd->pip_cmd_timeout));
- if (IS_TMO(t)) {
- #ifdef TTDL_DIAGNOSTICS
- cd->bus_transmit_error_count++;
- pt_toggle_err_gpio(cd, PT_ERR_GPIO_I2C_TRANS);
- #endif /* TTDL_DIAGNOSTICS */
- pt_debug(cd->dev, DL_ERROR,
- "%s: HID output cmd execution timed out\n",
- __func__);
- rc = -ETIME;
- goto error;
- }
- pt_check_command(cd, hid_output, true);
- goto exit;
- error:
- mutex_lock(&cd->system_lock);
- cd->hid_cmd_state = 0;
- mutex_unlock(&cd->system_lock);
- exit:
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_check_irq_asserted
- *
- * SUMMARY: Checks if the IRQ GPIO is asserted or not. There are times when
- * the FW can hold the INT line low ~150us after the read is complete.
- * NOTE: if irq_stat is not defined this function will return false
- *
- * RETURN:
- * true = IRQ asserted
- * false = IRQ not asserted
- *
- * PARAMETERS:
- * *cd - pointer to core data
- ******************************************************************************/
- static bool pt_check_irq_asserted(struct pt_core_data *cd)
- {
- #ifdef ENABLE_WORKAROUND_FOR_GLITCH_AFTER_BL_LAUNCH_APP
- /*
- * Workaround for FW defect, CDT165308
- * bl_launch app creates a glitch in IRQ line
- */
- if (cd->hid_cmd_state == PIP1_BL_CMD_ID_LAUNCH_APP + 1
- && cd->cpdata->irq_stat) {
- /*
- * in X1S panel and GC1546 panel, the width for the INT
- * glitch is about 4us,the normal INT width of response
- * will last more than 200us, so use 10us delay
- * for distinguish the glitch the normal INT is enough.
- */
- udelay(10);
- }
- #endif
- if (cd->cpdata->irq_stat) {
- if (cd->cpdata->irq_stat(cd->cpdata, cd->dev)
- == PT_IRQ_ASSERTED_VALUE) {
- /* Debounce to allow FW to release INT */
- usleep_range(100, 200);
- }
- if (cd->cpdata->irq_stat(cd->cpdata, cd->dev)
- == PT_IRQ_ASSERTED_VALUE)
- return true;
- else
- return false;
- }
- return true;
- }
- /*******************************************************************************
- * FUNCTION: pt_flush_bus
- *
- * SUMMARY: Force flushing the bus by reading len bytes or forced 255 bytes
- * Used if IRQ is found to be stuck low
- *
- * RETURN: Length of bytes read from bus
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * flush_type - type of flush
- * - PT_FLUSH_BUS_BASED_ON_LEN (two reads)
- * - PT_FLUSH_BUS_FULL_256_READ
- * *read_buf - pointer to store read data
- ******************************************************************************/
- static ssize_t pt_flush_bus(struct pt_core_data *cd,
- u8 flush_type, u8 *read_buf)
- {
- u8 buf[PT_MAX_PIP2_MSG_SIZE];
- u16 pip_len;
- int bytes_read;
- int rc = 0;
- if (flush_type == PT_FLUSH_BUS_BASED_ON_LEN) {
- rc = pt_adap_read_default(cd, buf, 2);
- if (rc) {
- bytes_read = 0;
- goto exit;
- }
- pip_len = get_unaligned_le16(&buf[0]);
- if (pip_len == 2 || pip_len >= PT_PIP_1P7_EMPTY_BUF) {
- #ifdef TTDL_DIAGNOSTICS
- pt_toggle_err_gpio(cd, PT_ERR_GPIO_EMPTY_PACKET);
- #endif
- bytes_read = 2;
- pt_debug(cd->dev, DL_INFO,
- "%s: Empty buf detected - len=0x%04X\n",
- __func__, pip_len);
- } else if (pip_len == 0) {
- bytes_read = 0;
- pt_debug(cd->dev, DL_INFO,
- "%s: Sentinel detected\n", __func__);
- } else if (pip_len > PT_MAX_PIP2_MSG_SIZE) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: Illegal len=0x%04x, force %d byte read\n",
- __func__, pip_len, PT_MAX_PIP2_MSG_SIZE);
- rc = pt_adap_read_default(cd, buf,
- PT_MAX_PIP2_MSG_SIZE);
- if (!rc)
- bytes_read = PT_MAX_PIP2_MSG_SIZE;
- else
- bytes_read = 0;
- } else {
- pt_debug(cd->dev, DL_INFO,
- "%s: Flush read of %d bytes...\n",
- __func__, pip_len);
- rc = pt_adap_read_default(cd, buf, pip_len);
- if (!rc)
- bytes_read = pip_len;
- else
- bytes_read = 0;
- }
- } else {
- pt_debug(cd->dev, DL_INFO,
- "%s: Forced flush of max %d bytes...\n",
- __func__, PT_MAX_PIP2_MSG_SIZE);
- rc = pt_adap_read_default(cd, buf, PT_MAX_PIP2_MSG_SIZE);
- if (!rc)
- bytes_read = PT_MAX_PIP2_MSG_SIZE;
- else
- bytes_read = 0;
- }
- if (read_buf && (bytes_read > 3))
- memcpy(read_buf, buf, bytes_read);
- exit:
- return bytes_read;
- }
- /*******************************************************************************
- * FUNCTION: pt_flush_bus_if_irq_asserted
- *
- * SUMMARY: This function will flush the active bus if the INT is found to be
- * asserted.
- *
- * RETURN: bytes cleared from bus
- *
- * PARAMETERS:
- * *cd - pointer the core data structure
- * flush_type - type of flush
- * - PT_FLUSH_BUS_BASED_ON_LEN
- * - PT_FLUSH_BUS_FULL_256_READ
- ******************************************************************************/
- static int pt_flush_bus_if_irq_asserted(struct pt_core_data *cd, u8 flush_type)
- {
- int count = 0;
- int bytes_read = 0;
- while (pt_check_irq_asserted(cd) && count < 5) {
- count++;
- bytes_read = pt_flush_bus(cd, flush_type, NULL);
- if (bytes_read) {
- pt_debug(cd->dev, DL_WARN,
- "%s: Cleared %d bytes off bus\n",
- __func__, bytes_read);
- }
- }
- if (pt_check_irq_asserted(cd)) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: IRQ still asserted, %d bytes read\n",
- __func__, bytes_read);
- } else {
- pt_debug(cd->dev, DL_INFO,
- "%s: IRQ cleared, %d bytes read\n",
- __func__, bytes_read);
- }
- return bytes_read;
- }
- /*******************************************************************************
- * FUNCTION: pt_hid_send_output_
- *
- * SUMMARY: Send a touch application command to the DUT
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * *hid_output - pointer to the command to send
- ******************************************************************************/
- static int pt_hid_send_output_(struct pt_core_data *cd,
- struct pt_hid_output *hid_output)
- {
- int rc = 0;
- u8 *cmd;
- u16 length;
- u16 crc;
- u8 report_id;
- u8 cmd_offset = 0;
- u8 cmd_allocated = 0;
- switch (hid_output->cmd_type) {
- case PIP1_CMD_TYPE_FW:
- report_id = PT_PIP_NON_HID_COMMAND_ID;
- length = 5;
- break;
- case PIP1_CMD_TYPE_BL:
- report_id = PT_PIP_BL_COMMAND_REPORT_ID;
- length = 11 /* 5 + SOP + LEN(2) + CRC(2) + EOP */;
- break;
- default:
- return -EINVAL;
- }
- length += hid_output->write_length;
- if (length + 2 > PT_PREALLOCATED_CMD_BUFFER) {
- cmd = kzalloc(length + 2, GFP_KERNEL);
- if (!cmd)
- return -ENOMEM;
- cmd_allocated = 1;
- } else {
- cmd = cd->cmd_buf;
- }
- /* Set Output register */
- memcpy(&cmd[cmd_offset], &cd->hid_desc.output_register,
- sizeof(cd->hid_desc.output_register));
- cmd_offset += sizeof(cd->hid_desc.output_register);
- cmd[cmd_offset++] = LOW_BYTE(length);
- cmd[cmd_offset++] = HI_BYTE(length);
- cmd[cmd_offset++] = report_id;
- cmd[cmd_offset++] = 0x0; /* reserved */
- if (hid_output->cmd_type == PIP1_CMD_TYPE_BL)
- cmd[cmd_offset++] = PIP1_BL_SOP;
- cmd[cmd_offset++] = hid_output->command_code;
- /* Set Data Length for bootloader */
- if (hid_output->cmd_type == PIP1_CMD_TYPE_BL) {
- cmd[cmd_offset++] = LOW_BYTE(hid_output->write_length);
- cmd[cmd_offset++] = HI_BYTE(hid_output->write_length);
- }
- /* Set Data */
- if (hid_output->write_length && hid_output->write_buf) {
- memcpy(&cmd[cmd_offset], hid_output->write_buf,
- hid_output->write_length);
- cmd_offset += hid_output->write_length;
- }
- if (hid_output->cmd_type == PIP1_CMD_TYPE_BL) {
- crc = _pt_compute_crc(&cmd[6],
- hid_output->write_length + 4);
- cmd[cmd_offset++] = LOW_BYTE(crc);
- cmd[cmd_offset++] = HI_BYTE(crc);
- cmd[cmd_offset++] = PIP1_BL_EOP;
- }
- pt_debug(cd->dev, DL_INFO,
- ">>> %s: Write Buffer Size[%d] Cmd[0x%02X]\n",
- __func__, length + 2, hid_output->command_code);
- pt_pr_buf(cd->dev, DL_DEBUG, cmd, length + 2, ">>> CMD");
- rc = pt_adap_write_read_specific(cd, length + 2, cmd, NULL);
- if (rc)
- pt_debug(cd->dev, DL_ERROR,
- "%s: Fail pt_adap_transfer rc=%d\n", __func__, rc);
- if (cmd_allocated)
- kfree(cmd);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_pip1_send_output_and_wait_
- *
- * SUMMARY: Send valid PIP1 command to the DUT and wait for the response.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * *hid_output - pointer to the command to send
- ******************************************************************************/
- static int pt_pip1_send_output_and_wait_(struct pt_core_data *cd,
- struct pt_hid_output *hid_output)
- {
- int rc = 0;
- int t;
- u16 timeout_ms;
- mutex_lock(&cd->system_lock);
- cd->hid_cmd_state = hid_output->command_code + 1;
- mutex_unlock(&cd->system_lock);
- if (hid_output->timeout_ms)
- timeout_ms = hid_output->timeout_ms;
- else
- timeout_ms = PT_PIP1_CMD_DEFAULT_TIMEOUT;
- rc = pt_hid_send_output_(cd, hid_output);
- if (rc)
- goto error;
- t = wait_event_timeout(cd->wait_q, (cd->hid_cmd_state == 0),
- msecs_to_jiffies(timeout_ms));
- if (IS_TMO(t)) {
- #ifdef TTDL_DIAGNOSTICS
- cd->bus_transmit_error_count++;
- pt_toggle_err_gpio(cd, PT_ERR_GPIO_I2C_TRANS);
- #endif /* TTDL_DIAGNOSTICS */
- pt_debug(cd->dev, DL_ERROR,
- "%s: HID output cmd execution timed out (%dms)\n",
- __func__, timeout_ms);
- rc = -ETIME;
- goto error;
- }
- if (!hid_output->novalidate)
- rc = pt_hid_output_validate_response(cd, hid_output);
- pt_check_command(cd, hid_output, false);
- goto exit;
- error:
- mutex_lock(&cd->system_lock);
- cd->hid_cmd_state = 0;
- mutex_unlock(&cd->system_lock);
- exit:
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_hid_output_user_cmd_
- *
- * SUMMARY: Load the write buffer into a HID structure and send it as a HID cmd
- * to the DUT waiting for the response and loading it into the read buffer
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * read_len - expected read length of the response
- * *read_buf - pointer to where the response will be loaded
- * write_len - length of the write buffer
- * *write_buf - pointer to the write buffer
- * *actual_read_len - pointer to the actual amount of data read back
- ******************************************************************************/
- static int pt_hid_output_user_cmd_(struct pt_core_data *cd,
- u16 read_len, u8 *read_buf, u16 write_len, u8 *write_buf,
- u16 *actual_read_len)
- {
- int rc = 0;
- u16 size;
- struct pt_hid_output hid_output = {
- .length = write_len,
- .write_buf = write_buf,
- };
- #ifdef TTHE_TUNER_SUPPORT
- if (!cd->pip2_send_user_cmd) {
- int command_code = 0;
- int len;
- /* Print up to cmd ID */
- len = PIP1_CMD_COMMAND_ID_OFFSET + 1;
- if (write_len < len)
- len = write_len;
- else
- command_code = write_buf[PIP1_CMD_COMMAND_ID_OFFSET]
- & PIP1_CMD_COMMAND_ID_MASK;
- /* Don't print EXEC_PANEL_SCAN & RETRIEVE_PANEL_SCAN commands */
- if (command_code != PIP1_CMD_ID_EXEC_PANEL_SCAN &&
- command_code != PIP1_CMD_ID_RETRIEVE_PANEL_SCAN)
- tthe_print(cd, write_buf, len, "CMD=");
- }
- #endif
- rc = pt_hid_send_output_user_and_wait_(cd, &hid_output);
- if (rc)
- return rc;
- /* Get the response size from the first 2 bytes in the response */
- size = get_unaligned_le16(&cd->response_buf[0]);
- /* Ensure size is not greater than max buffer size */
- if (size > PT_MAX_PIP2_MSG_SIZE)
- size = PT_MAX_PIP2_MSG_SIZE;
- /* Minimum size to read is the 2 byte len field */
- if (size == 0)
- size = 2;
- if (size > read_len) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: PIP2 len field=%d, requested read_len=%d\n",
- __func__, size, read_len);
- *actual_read_len = 0;
- return -EIO;
- }
- memcpy(read_buf, cd->response_buf, size);
- *actual_read_len = size;
- return 0;
- }
- /*******************************************************************************
- * FUNCTION: pt_hid_output_user_cmd
- *
- * SUMMARY: Protected call to pt_hid_output_user_cmd_ by exclusive access to
- * the DUT.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * read_len - length of data to read
- * *read_buf - pointer to store read data
- * write_len - length of data to write
- * *write_buf - pointer to buffer to write
- * *actual_read_len - pointer to store data length actually read
- ******************************************************************************/
- static int pt_hid_output_user_cmd(struct pt_core_data *cd,
- u16 read_len, u8 *read_buf, u16 write_len, u8 *write_buf,
- u16 *actual_read_len)
- {
- int rc;
- rc = request_exclusive(cd, cd->dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail get exclusive ex=%p own=%p\n",
- __func__, cd->exclusive_dev, cd->dev);
- return rc;
- }
- rc = pt_hid_output_user_cmd_(cd, read_len, read_buf,
- write_len, write_buf, actual_read_len);
- if (release_exclusive(cd, cd->dev) < 0)
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail to release exclusive\n", __func__);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: _pt_request_pip2_send_cmd
- *
- * SUMMARY: Writes a PIP2 command packet to DUT, then waits for the
- * interrupt and reads response data to read_buf
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * protect - flag to run in protected mode
- * id - ID of PIP command
- * *data - pointer to PIP data payload
- * report_body_len - report length
- * *read_buf - pointer to response buffer
- * *actual_read_len - pointer to response buffer length
- ******************************************************************************/
- static int _pt_request_pip2_send_cmd(struct device *dev,
- int protect, u8 id, u8 *data, u16 report_body_len, u8 *read_buf,
- u16 *actual_read_len)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- struct pip2_cmd_structure pip2_cmd;
- int rc = 0;
- u16 i = 0;
- u16 j = 0;
- u16 write_len;
- u8 *write_buf = NULL;
- u16 read_len;
- u8 extra_bytes;
- if (report_body_len > 247)
- return -EPROTO;
- memset(&pip2_cmd, 0, sizeof(pip2_cmd));
- /* Hard coded register for PIP2.x */
- pip2_cmd.reg[0] = 0x01;
- pip2_cmd.reg[1] = 0x01;
- /*
- * For PIP2.1+ the length field value includes itself:
- * ADD 6: 2 (LEN) + 1 (SEQ) + 1 (REPORT ID) + 2 (CRC)
- *
- * The overall write length must include only the register:
- * ADD 2: 2 (Register)
- */
- extra_bytes = 6;
- write_len = 2;
- /* PIP2 the CMD ID is a 7bit field */
- if (id > PIP2_CMD_ID_END) {
- pt_debug(dev, DL_WARN, "%s: Invalid PIP2 CMD ID 0x%02X\n",
- __func__, id);
- rc = -EINVAL;
- goto exit;
- }
- pip2_cmd.len = report_body_len + extra_bytes;
- pip2_cmd.id = id & PIP2_CMD_COMMAND_ID_MASK;
- pip2_cmd.seq = pt_pip2_get_next_cmd_seq(cd);
- pip2_cmd.data = data;
- pt_pip2_cmd_calculate_crc(&pip2_cmd, extra_bytes);
- /* Add the command length to the extra bytes based on PIP version */
- write_len += pip2_cmd.len;
- pt_debug(dev, DL_INFO, "%s Length Field: %d, Write Len: %d",
- __func__, pip2_cmd.len, write_len);
- write_buf = kzalloc(write_len, GFP_KERNEL);
- if (write_buf == NULL) {
- rc = -ENOMEM;
- goto exit;
- }
- write_buf[i++] = pip2_cmd.reg[0];
- write_buf[i++] = pip2_cmd.reg[1];
- write_buf[i++] = pip2_cmd.len & 0xff;
- write_buf[i++] = (pip2_cmd.len & 0xff00) >> 8;
- write_buf[i++] = pip2_cmd.seq;
- write_buf[i++] = pip2_cmd.id;
- for (j = i; j < i + pip2_cmd.len - extra_bytes; j++)
- write_buf[j] = pip2_cmd.data[j-i];
- write_buf[j++] = pip2_cmd.crc[0];
- write_buf[j++] = pip2_cmd.crc[1];
- read_len = pt_pip2_get_cmd_response_len(pip2_cmd.id);
- if (read_len < 0)
- read_len = 255;
- pt_debug(dev, DL_INFO,
- "%s cmd_id[0x%02X] expected response length:%d ",
- __func__, pip2_cmd.id, read_len);
- /*
- * All PIP2 commands come through this function.
- * Set flag for PIP2.x interface to allow response parsing to know
- * how to decode the protocol header.
- */
- mutex_lock(&cd->system_lock);
- cd->pip2_prot_active = true;
- cd->pip2_send_user_cmd = true;
- mutex_unlock(&cd->system_lock);
- if (protect == PT_CORE_CMD_PROTECTED)
- rc = pt_hid_output_user_cmd(cd, read_len, read_buf,
- write_len, write_buf, actual_read_len);
- else {
- rc = pt_hid_output_user_cmd_(cd, read_len, read_buf,
- write_len, write_buf, actual_read_len);
- }
- if (rc) {
- pt_debug(dev, DL_ERROR,
- "%s: nonhid_cmd->user_cmd() Error = %d\n",
- __func__, rc);
- goto exit;
- }
- rc = pt_pip2_validate_response(cd, &pip2_cmd, read_buf,
- *actual_read_len);
- exit:
- mutex_lock(&cd->system_lock);
- cd->pip2_prot_active = false;
- cd->pip2_send_user_cmd = false;
- mutex_unlock(&cd->system_lock);
- kfree(write_buf);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: _pt_pip2_send_cmd_no_int
- *
- * SUMMARY: Writes a PIP2 command packet to DUT, then poll the response and
- * reads response data to read_buf if response is available.
- *
- * NOTE:
- * Interrupt MUST be disabled before to call this function.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * protect - flag to run in protected mode
- * id - ID of PIP command
- * *data - pointer to PIP data payload
- * report_body_len - report length
- * *read_buf - pointer to response buffer
- * *actual_read_len - pointer to response buffer length
- ******************************************************************************/
- static int _pt_pip2_send_cmd_no_int(struct device *dev,
- int protect, u8 id, u8 *data, u16 report_body_len, u8 *read_buf,
- u16 *actual_read_len)
- {
- int max_retry = 0;
- int retry = 0;
- int rc = 0;
- u16 i = 0;
- u16 j = 0;
- u16 write_len;
- u8 *write_buf = NULL;
- u16 read_len;
- u16 size = 0;
- u8 response_seq = 0;
- u8 extra_bytes;
- u32 retry_interval = 0;
- u32 retry_total_time = 0;
- u32 resp_time_min = pt_pip2_get_cmd_resp_time_min(id);
- u32 resp_time_max = pt_pip2_get_cmd_resp_time_max(id);
- struct pt_core_data *cd = dev_get_drvdata(dev);
- struct pip2_cmd_structure pip2_cmd;
- if (report_body_len > 247)
- return -EPROTO;
- if (protect == PT_CORE_CMD_PROTECTED) {
- rc = request_exclusive(cd,
- cd->dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail get exclusive ex=%p own=%p\n",
- __func__, cd->exclusive_dev, cd->dev);
- return rc;
- }
- }
- memset(&pip2_cmd, 0, sizeof(pip2_cmd));
- /* Hard coded register for PIP2.x */
- pip2_cmd.reg[0] = 0x01;
- pip2_cmd.reg[1] = 0x01;
- /*
- * For PIP2.1+ the length field value includes itself:
- * ADD 6: 2 (LEN) + 1 (SEQ) + 1 (REPORT ID) + 2 (CRC)
- *
- * The overall write length must include only the register:
- * ADD 2: 2 (Register)
- */
- extra_bytes = 6;
- write_len = 2;
- pip2_cmd.len = report_body_len + extra_bytes;
- pip2_cmd.id = id;
- pip2_cmd.seq = pt_pip2_get_next_cmd_seq(cd);
- pip2_cmd.data = data;
- pt_pip2_cmd_calculate_crc(&pip2_cmd, extra_bytes);
- /* Add the command length to the extra bytes based on PIP version */
- write_len += pip2_cmd.len;
- write_buf = kzalloc(write_len, GFP_KERNEL);
- if (write_buf == NULL) {
- rc = -ENOMEM;
- goto exit;
- }
- write_buf[i++] = pip2_cmd.reg[0];
- write_buf[i++] = pip2_cmd.reg[1];
- write_buf[i++] = pip2_cmd.len & 0xff;
- write_buf[i++] = (pip2_cmd.len & 0xff00) >> 8;
- write_buf[i++] = pip2_cmd.seq;
- write_buf[i++] = pip2_cmd.id;
- for (j = i; j < i + pip2_cmd.len - extra_bytes; j++)
- write_buf[j] = pip2_cmd.data[j-i];
- write_buf[j++] = pip2_cmd.crc[0];
- write_buf[j++] = pip2_cmd.crc[1];
- read_len = pt_pip2_get_cmd_response_len(pip2_cmd.id);
- if (read_len < 0)
- read_len = 255;
- pt_debug(dev, DL_INFO,
- "%s: ATM - cmd_id[0x%02X] expected response length:%d ",
- __func__, pip2_cmd.id, read_len);
- pt_pr_buf(cd->dev, DL_DEBUG, write_buf, write_len, ">>> NO_INT CMD");
- rc = pt_adap_write_read_specific(cd, write_len, write_buf, NULL);
- if (rc) {
- pt_debug(dev, DL_ERROR,
- "%s: SPI write Error = %d\n",
- __func__, rc);
- goto exit;
- }
- #ifdef PT_POLL_RESP_BY_BUS
- /*
- * Frequent bus read can increase system load obviously. The expected
- * first bus read should be valid and timely. The tollerance for
- * usleep_range should be limited. The minimum response delay (between
- * command finishes sending and INT pin falls) is less than 50
- * microseconds. So the 10 microseconds should be maximum tollerance
- * with the consideration that the unit to calculate the response delay
- * is 10 microseconds and more precise is not necessary. Every
- * additional 10 microseconds only contribute less than 3 milliseconds
- * for whole BL.
- */
- usleep_range(resp_time_min, resp_time_min+10);
- max_retry = resp_time_max / POLL_RETRY_DEFAULT_INTERVAL;
- while ((retry < max_retry) && (retry_total_time < resp_time_max)) {
- rc = pt_adap_read_default(cd, read_buf, read_len);
- if (rc) {
- pt_debug(dev, DL_ERROR, "%s: SPI read Error = %d\n",
- __func__, rc);
- break;
- }
- response_seq = read_buf[PIP2_RESP_SEQUENCE_OFFSET];
- size = get_unaligned_le16(&read_buf[0]);
- if ((size <= read_len) &&
- (size >= PIP2_EXTRA_BYTES_NUM) &&
- (pip2_cmd.seq & 0x07) == (response_seq & 0x07)) {
- break;
- }
- /*
- * To reduce the bus and system load, increase the sleep
- * step gradually:
- * 1 ~ 19 : step=50 us, sleep_us=[50, 100, 150, 200, ..950]
- * 20 ~ 39 : step=1000 us, sleep_us=[1950, 2950, ...20950]
- * 40 ~ MAX: step=50 ms, sleep_ms=[71, 121, 191,..]
- */
- retry++;
- if (retry < 20) {
- retry_interval += POLL_RETRY_DEFAULT_INTERVAL;
- usleep_range(retry_interval,
- retry_interval + POLL_RETRY_DEFAULT_INTERVAL);
- } else if (retry < 40) {
- retry_interval += 1000;
- usleep_range(retry_interval, retry_interval + 1000);
- } else {
- retry_interval += 50000;
- msleep(retry_interval/1000);
- }
- retry_total_time += retry_interval;
- }
- #else
- /*
- * Frequent GPIO read will not increase CPU/system load heavily if the
- * interval is longer than 10 us, so it is safe to poll GPIO with a
- * fixed interval: 20 us.
- */
- usleep_range(resp_time_min, resp_time_min+10);
- max_retry = resp_time_max / POLL_RETRY_DEFAULT_INTERVAL;
- while ((retry < max_retry) && (retry_total_time < resp_time_max)) {
- if (!gpio_get_value(cd->cpdata->irq_gpio)) {
- rc = pt_adap_read_default(cd, read_buf, read_len);
- size = get_unaligned_le16(&read_buf[0]);
- if (rc)
- pt_debug(dev, DL_ERROR,
- "%s: SPI read Error = %d\n",
- __func__, rc);
- else if (size > read_len) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: PIP2 len field=%d, requested read_len=%d\n",
- __func__, size, read_len);
- rc = -EIO;
- }
- break;
- }
- /*
- * Poll GPIO with fixed interval 20 us, and tollerance is
- * limited to 10 us to speed up the process.
- */
- retry_interval = POLL_RETRY_DEFAULT_INTERVAL;
- usleep_range(retry_interval, retry_interval+10);
- retry_total_time += retry_interval;
- }
- #endif
- *actual_read_len = size;
- if (rc || (retry >= max_retry) || (retry_total_time >= resp_time_max)) {
- pt_debug(dev, DL_ERROR,
- "%s cmd[0x%02X] timed out, send_seq=0x%02X, resp_seq=0x%02X\n",
- __func__, pip2_cmd.id, pip2_cmd.seq, response_seq);
- *actual_read_len = 0;
- rc = -EINVAL;
- }
- pt_pr_buf(cd->dev, DL_DEBUG, read_buf, *actual_read_len,
- "<<< NO_INT Read");
- exit:
- kfree(write_buf);
- if (protect == PT_CORE_CMD_PROTECTED) {
- if (release_exclusive(cd, cd->dev) < 0)
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail to release exclusive\n", __func__);
- }
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_pip_null_
- *
- * SUMMARY: Send the PIP "ping"(0x00) command to the DUT and wait for response.
- * This function is used by watchdog to check if the fw corrupts.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- ******************************************************************************/
- static int pt_pip_null_(struct pt_core_data *cd)
- {
- struct pt_hid_output hid_output = {
- CREATE_PIP1_FW_CMD(PIP1_CMD_ID_NULL),
- };
- return pt_pip1_send_output_and_wait_(cd, &hid_output);
- }
- /*******************************************************************************
- * FUNCTION: pt_pip_null
- *
- * SUMMARY: Wrapper function for pt_pip_null_ that guarantees exclusive access.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- ******************************************************************************/
- static int pt_pip_null(struct pt_core_data *cd)
- {
- int rc;
- rc = request_exclusive(cd, cd->dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail get exclusive ex=%p own=%p\n",
- __func__, cd->exclusive_dev, cd->dev);
- return rc;
- }
- rc = pt_pip_null_(cd);
- if (release_exclusive(cd, cd->dev) < 0)
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail to release exclusive\n", __func__);
- return rc;
- }
- static void pt_stop_wd_timer(struct pt_core_data *cd);
- /*******************************************************************************
- * FUNCTION: pt_pip_start_bootloader_
- *
- * SUMMARY: Sends the HID command start_bootloader [PIP cmd 0x01] to the DUT
- *
- * NOTE: The WD MUST be stopped/restarted by the calling Function. Having
- * the WD active could cause this function to fail!
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- ******************************************************************************/
- static int pt_pip_start_bootloader_(struct pt_core_data *cd)
- {
- int rc = 0;
- struct pt_hid_output hid_output = {
- CREATE_PIP1_FW_CMD(PIP1_CMD_ID_START_BOOTLOADER),
- .timeout_ms = PT_PIP1_START_BOOTLOADER_TIMEOUT,
- .reset_expected = 1,
- };
- if (cd->watchdog_enabled) {
- pt_debug(cd->dev, DL_WARN,
- "%s: watchdog isn't stopped before enter bl\n",
- __func__);
- goto exit;
- }
- /* Reset startup status after entering BL, new DUT enum required */
- cd->startup_status = STARTUP_STATUS_START;
- pt_debug(cd->dev, DL_DEBUG, "%s: Startup Status Reset\n", __func__);
- rc = pt_pip1_send_output_and_wait_(cd, &hid_output);
- if (rc) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: Start BL PIP cmd failed. rc = %d\n",
- __func__, rc);
- }
- exit:
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_pip_start_bootloader
- *
- * SUMMARY: Protected function to force DUT to enter the BL
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data structure
- ******************************************************************************/
- static int pt_pip_start_bootloader(struct pt_core_data *cd)
- {
- int rc;
- rc = request_exclusive(cd, cd->dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail get exclusive ex=%p own=%p\n",
- __func__, cd->exclusive_dev, cd->dev);
- return rc;
- }
- rc = pt_pip_start_bootloader_(cd);
- if (release_exclusive(cd, cd->dev) < 0)
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail to release exclusive\n", __func__);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: _pt_request_pip_start_bl
- *
- * SUMMARY: Function pointer included in core_nonhid_cmds to allow other
- * modules to request the DUT to enter the BL
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * protect - flag to run in protected mode
- ******************************************************************************/
- static int _pt_request_pip_start_bl(struct device *dev, int protect)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- if (protect)
- return pt_pip_start_bootloader(cd);
- return pt_pip_start_bootloader_(cd);
- }
- /*******************************************************************************
- * FUNCTION: pt_pip2_ver_load_ttdata
- *
- * SUMMARY: Function to load the Version information from the PIP2 VERSION
- * command into the core data struct.
- *
- * RETURN: n/a
- *
- * PARAMETERS:
- * *cd - pointer to core data structure
- * len - Length of data in response_buf
- ******************************************************************************/
- static void pt_pip2_ver_load_ttdata(struct pt_core_data *cd, u16 len)
- {
- struct pt_ttdata *ttdata = &cd->sysinfo.ttdata;
- struct pt_pip2_version_full *full_ver;
- struct pt_pip2_version *ver;
- /*
- * The PIP2 VERSION command can return different lengths of data.
- * The additional LOT fields are included when the packet
- * size is >= 29 bytes. Older FW sends a reduced packet size.
- * NOTE:
- * - The FW would swap the BL and FW versions when reporting
- * the small packet.
- * - Sub Lot bytes 16 and 17 are reserved.
- */
- if (len >= 0x1D) {
- full_ver = (struct pt_pip2_version_full *)
- &cd->response_buf[PIP2_RESP_STATUS_OFFSET];
- ttdata->pip_ver_major = full_ver->pip2_version_msb;
- ttdata->pip_ver_minor = full_ver->pip2_version_lsb;
- ttdata->bl_ver_major = full_ver->bl_version_msb;
- ttdata->bl_ver_minor = full_ver->bl_version_lsb;
- ttdata->fw_ver_major = full_ver->fw_version_msb;
- ttdata->fw_ver_minor = full_ver->fw_version_lsb;
- /*
- * BL PIP 2.02 and greater the version fields are
- * swapped
- */
- if (ttdata->pip_ver_major >= 2 && ttdata->pip_ver_minor >= 2) {
- ttdata->chip_rev =
- get_unaligned_le16(&full_ver->chip_rev);
- ttdata->chip_id =
- get_unaligned_le16(&full_ver->chip_id);
- } else {
- ttdata->chip_rev =
- get_unaligned_le16(&full_ver->chip_id);
- ttdata->chip_id =
- get_unaligned_le16(&full_ver->chip_rev);
- }
- memcpy(ttdata->uid, full_ver->uid, PT_UID_SIZE);
- pt_pr_buf(cd->dev, DL_INFO, (u8 *)full_ver,
- sizeof(struct pt_pip2_version_full),
- "PIP2 VERSION FULL");
- } else {
- ver = (struct pt_pip2_version *)
- &cd->response_buf[PIP2_RESP_STATUS_OFFSET];
- ttdata->pip_ver_major = ver->pip2_version_msb;
- ttdata->pip_ver_minor = ver->pip2_version_lsb;
- ttdata->bl_ver_major = ver->bl_version_msb;
- ttdata->bl_ver_minor = ver->bl_version_lsb;
- ttdata->fw_ver_major = ver->fw_version_msb;
- ttdata->fw_ver_minor = ver->fw_version_lsb;
- ttdata->chip_rev = get_unaligned_le16(&ver->chip_rev);
- ttdata->chip_id = get_unaligned_le16(&ver->chip_id);
- pt_pr_buf(cd->dev, DL_INFO, (u8 *)ver,
- sizeof(struct pt_pip2_version), "PIP2 VERSION");
- }
- }
- /*******************************************************************************
- * FUNCTION: pt_si_get_ttdata
- *
- * SUMMARY: Function to load the version information from the system information
- * PIP command into the core data struct.
- *
- * RETURN: n/a
- *
- * PARAMETERS:
- * *cd - pointer to core data structure
- ******************************************************************************/
- static void pt_si_get_ttdata(struct pt_core_data *cd)
- {
- struct pt_ttdata *ttdata = &cd->sysinfo.ttdata;
- struct pt_ttdata_dev *ttdata_dev =
- (struct pt_ttdata_dev *)
- &cd->response_buf[PIP1_SYSINFO_TTDATA_OFFSET];
- ttdata->pip_ver_major = ttdata_dev->pip_ver_major;
- ttdata->pip_ver_minor = ttdata_dev->pip_ver_minor;
- ttdata->bl_ver_major = ttdata_dev->bl_ver_major;
- ttdata->bl_ver_minor = ttdata_dev->bl_ver_minor;
- ttdata->fw_ver_major = ttdata_dev->fw_ver_major;
- ttdata->fw_ver_minor = ttdata_dev->fw_ver_minor;
- ttdata->fw_pid = get_unaligned_le16(&ttdata_dev->fw_pid);
- ttdata->fw_ver_conf = get_unaligned_le16(&ttdata_dev->fw_ver_conf);
- ttdata->post_code = get_unaligned_le16(&ttdata_dev->post_code);
- ttdata->revctrl = get_unaligned_le32(&ttdata_dev->revctrl);
- ttdata->jtag_id_l = get_unaligned_le16(&ttdata_dev->jtag_si_id_l);
- ttdata->jtag_id_h = get_unaligned_le16(&ttdata_dev->jtag_si_id_h);
- memcpy(ttdata->mfg_id, ttdata_dev->mfg_id, PT_NUM_MFGID);
- pt_pr_buf(cd->dev, DL_INFO, (u8 *)ttdata_dev,
- sizeof(struct pt_ttdata_dev), "sysinfo_ttdata");
- }
- /*******************************************************************************
- * FUNCTION: pt_si_get_sensing_conf_data
- *
- * SUMMARY: Function to load the sensing information from the system information
- * PIP command into the core data struct.
- *
- * RETURN: n/a
- *
- * PARAMETERS:
- * *cd - pointer to core data structure
- ******************************************************************************/
- static void pt_si_get_sensing_conf_data(struct pt_core_data *cd)
- {
- struct pt_sensing_conf_data *scd = &cd->sysinfo.sensing_conf_data;
- struct pt_sensing_conf_data_dev *scd_dev =
- (struct pt_sensing_conf_data_dev *)
- &cd->response_buf[PIP1_SYSINFO_SENSING_OFFSET];
- scd->electrodes_x = scd_dev->electrodes_x;
- scd->electrodes_y = scd_dev->electrodes_y;
- scd->origin_x = scd_dev->origin_x;
- scd->origin_y = scd_dev->origin_y;
- /* PIP 1.4 (001-82649 *Q) add X_IS_TX bit in X_ORG */
- if (scd->origin_x & 0x02) {
- scd->tx_num = scd->electrodes_x;
- scd->rx_num = scd->electrodes_y;
- } else {
- scd->tx_num = scd->electrodes_y;
- scd->rx_num = scd->electrodes_x;
- }
- /*
- * When the Panel ID is coming from an XY pin and not a dedicated
- * GPIO, store the PID in pid_for_loader. This cannot be done for all
- * other DUTs as the loader will use cd->pid_for_loader to generate
- * the bin file name but will ignore it if pid_for_loader is still
- * set to PANEL_ID_NOT_ENABLED
- */
- if (cd->panel_id_support &
- (PT_PANEL_ID_BY_BL | PT_PANEL_ID_BY_SYS_INFO)) {
- mutex_lock(&cd->system_lock);
- cd->pid_for_loader = scd_dev->panel_id;
- mutex_unlock(&cd->system_lock);
- }
- scd->panel_id = scd_dev->panel_id;
- scd->btn = scd_dev->btn;
- scd->scan_mode = scd_dev->scan_mode;
- scd->max_tch = scd_dev->max_num_of_tch_per_refresh_cycle;
- scd->res_x = get_unaligned_le16(&scd_dev->res_x);
- scd->res_y = get_unaligned_le16(&scd_dev->res_y);
- scd->max_z = get_unaligned_le16(&scd_dev->max_z);
- scd->len_x = get_unaligned_le16(&scd_dev->len_x);
- scd->len_y = get_unaligned_le16(&scd_dev->len_y);
- pt_pr_buf(cd->dev, DL_INFO, (u8 *)scd_dev,
- sizeof(struct pt_sensing_conf_data_dev),
- "sensing_conf_data");
- }
- /*******************************************************************************
- * FUNCTION: pt_si_setup
- *
- * SUMMARY: Setup the xy_data and xy_mode by allocating the needed memory
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data structure
- ******************************************************************************/
- static int pt_si_setup(struct pt_core_data *cd)
- {
- struct pt_sysinfo *si = &cd->sysinfo;
- int max_tch = si->sensing_conf_data.max_tch;
- if (!si->xy_data)
- si->xy_data = kzalloc(max_tch * si->desc.tch_record_size,
- GFP_KERNEL);
- if (!si->xy_data)
- return -ENOMEM;
- if (!si->xy_mode)
- si->xy_mode = kzalloc(si->desc.tch_header_size, GFP_KERNEL);
- if (!si->xy_mode) {
- kfree(si->xy_data);
- return -ENOMEM;
- }
- return 0;
- }
- /*******************************************************************************
- * FUNCTION: pt_si_get_btn_data
- *
- * SUMMARY: Setup the core data button information based on the response of the
- * System Information PIP command.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data structure
- ******************************************************************************/
- static int pt_si_get_btn_data(struct pt_core_data *cd)
- {
- struct pt_sysinfo *si = &cd->sysinfo;
- int num_btns = 0;
- int num_defined_keys;
- u16 *key_table;
- int btn;
- int i;
- int rc = 0;
- unsigned int btns = cd->response_buf[PIP1_SYSINFO_BTN_OFFSET]
- & PIP1_SYSINFO_BTN_MASK;
- size_t btn_keys_size;
- pt_debug(cd->dev, DL_INFO, "%s: get btn data\n", __func__);
- for (i = 0; i < PIP1_SYSINFO_MAX_BTN; i++) {
- if (btns & (1 << i))
- num_btns++;
- }
- si->num_btns = num_btns;
- if (num_btns) {
- btn_keys_size = num_btns * sizeof(struct pt_btn);
- if (!si->btn)
- si->btn = kzalloc(btn_keys_size, GFP_KERNEL);
- if (!si->btn)
- return -ENOMEM;
- if (cd->cpdata->sett[PT_IC_GRPNUM_BTN_KEYS] == NULL)
- num_defined_keys = 0;
- else if (cd->cpdata->sett[PT_IC_GRPNUM_BTN_KEYS]->data == NULL)
- num_defined_keys = 0;
- else
- num_defined_keys = cd->cpdata->sett
- [PT_IC_GRPNUM_BTN_KEYS]->size;
- for (btn = 0; btn < num_btns && btn < num_defined_keys; btn++) {
- key_table = (u16 *)cd->cpdata->sett
- [PT_IC_GRPNUM_BTN_KEYS]->data;
- si->btn[btn].key_code = key_table[btn];
- si->btn[btn].enabled = true;
- }
- for (; btn < num_btns; btn++) {
- si->btn[btn].key_code = KEY_RESERVED;
- si->btn[btn].enabled = true;
- }
- return rc;
- }
- kfree(si->btn);
- si->btn = NULL;
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_si_put_log_data
- *
- * SUMMARY: Prints all sys info data to kmsg log
- *
- * RETURN: n/a
- *
- * PARAMETERS:
- * *cd - pointer to core data structure
- ******************************************************************************/
- static void pt_si_put_log_data(struct pt_core_data *cd)
- {
- struct pt_sysinfo *si = &cd->sysinfo;
- struct pt_ttdata *ttdata = &si->ttdata;
- struct pt_sensing_conf_data *scd = &si->sensing_conf_data;
- int i;
- pt_debug(cd->dev, DL_DEBUG, "%s: pip_ver_major = 0x%02X (%d)\n",
- __func__, ttdata->pip_ver_major, ttdata->pip_ver_major);
- pt_debug(cd->dev, DL_DEBUG, "%s: pip_ver_minor = 0x%02X (%d)\n",
- __func__, ttdata->pip_ver_minor, ttdata->pip_ver_minor);
- pt_debug(cd->dev, DL_DEBUG, "%s: fw_pid = 0x%04X (%d)\n",
- __func__, ttdata->fw_pid, ttdata->fw_pid);
- pt_debug(cd->dev, DL_DEBUG, "%s: fw_ver_major = 0x%02X (%d)\n",
- __func__, ttdata->fw_ver_major, ttdata->fw_ver_major);
- pt_debug(cd->dev, DL_DEBUG, "%s: fw_ver_minor = 0x%02X (%d)\n",
- __func__, ttdata->fw_ver_minor, ttdata->fw_ver_minor);
- pt_debug(cd->dev, DL_DEBUG, "%s: revctrl = 0x%08X (%d)\n",
- __func__, ttdata->revctrl, ttdata->revctrl);
- pt_debug(cd->dev, DL_DEBUG, "%s: fw_ver_conf = 0x%04X (%d)\n",
- __func__, ttdata->fw_ver_conf, ttdata->fw_ver_conf);
- pt_debug(cd->dev, DL_DEBUG, "%s: bl_ver_major = 0x%02X (%d)\n",
- __func__, ttdata->bl_ver_major, ttdata->bl_ver_major);
- pt_debug(cd->dev, DL_DEBUG, "%s: bl_ver_minor = 0x%02X (%d)\n",
- __func__, ttdata->bl_ver_minor, ttdata->bl_ver_minor);
- pt_debug(cd->dev, DL_DEBUG, "%s: jtag_id_h = 0x%04X (%d)\n",
- __func__, ttdata->jtag_id_h, ttdata->jtag_id_h);
- pt_debug(cd->dev, DL_DEBUG, "%s: jtag_id_l = 0x%04X (%d)\n",
- __func__, ttdata->jtag_id_l, ttdata->jtag_id_l);
- for (i = 0; i < PT_NUM_MFGID; i++)
- pt_debug(cd->dev, DL_DEBUG,
- "%s: mfg_id[%d] = 0x%02X (%d)\n",
- __func__, i, ttdata->mfg_id[i],
- ttdata->mfg_id[i]);
- pt_debug(cd->dev, DL_DEBUG, "%s: post_code = 0x%04X (%d)\n",
- __func__, ttdata->post_code, ttdata->post_code);
- pt_debug(cd->dev, DL_DEBUG, "%s: electrodes_x = 0x%02X (%d)\n",
- __func__, scd->electrodes_x, scd->electrodes_x);
- pt_debug(cd->dev, DL_DEBUG, "%s: electrodes_y = 0x%02X (%d)\n",
- __func__, scd->electrodes_y, scd->electrodes_y);
- pt_debug(cd->dev, DL_DEBUG, "%s: len_x = 0x%04X (%d)\n",
- __func__, scd->len_x, scd->len_x);
- pt_debug(cd->dev, DL_DEBUG, "%s: len_y = 0x%04X (%d)\n",
- __func__, scd->len_y, scd->len_y);
- pt_debug(cd->dev, DL_DEBUG, "%s: res_x = 0x%04X (%d)\n",
- __func__, scd->res_x, scd->res_x);
- pt_debug(cd->dev, DL_DEBUG, "%s: res_y = 0x%04X (%d)\n",
- __func__, scd->res_y, scd->res_y);
- pt_debug(cd->dev, DL_DEBUG, "%s: max_z = 0x%04X (%d)\n",
- __func__, scd->max_z, scd->max_z);
- pt_debug(cd->dev, DL_DEBUG, "%s: origin_x = 0x%02X (%d)\n",
- __func__, scd->origin_x, scd->origin_x);
- pt_debug(cd->dev, DL_DEBUG, "%s: origin_y = 0x%02X (%d)\n",
- __func__, scd->origin_y, scd->origin_y);
- pt_debug(cd->dev, DL_DEBUG, "%s: panel_id = 0x%02X (%d)\n",
- __func__, scd->panel_id, scd->panel_id);
- pt_debug(cd->dev, DL_DEBUG, "%s: btn =0x%02X (%d)\n",
- __func__, scd->btn, scd->btn);
- pt_debug(cd->dev, DL_DEBUG, "%s: scan_mode = 0x%02X (%d)\n",
- __func__, scd->scan_mode, scd->scan_mode);
- pt_debug(cd->dev, DL_DEBUG,
- "%s: max_num_of_tch_per_refresh_cycle = 0x%02X (%d)\n",
- __func__, scd->max_tch, scd->max_tch);
- pt_debug(cd->dev, DL_DEBUG, "%s: xy_mode = %p\n",
- __func__, si->xy_mode);
- pt_debug(cd->dev, DL_DEBUG, "%s: xy_data = %p\n",
- __func__, si->xy_data);
- }
- /*******************************************************************************
- * FUNCTION: pt_get_sysinfo_regs
- *
- * SUMMARY: Setup all the core data System information based on the response
- * of the System Information PIP command.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data structure
- ******************************************************************************/
- static int pt_get_sysinfo_regs(struct pt_core_data *cd)
- {
- struct pt_sysinfo *si = &cd->sysinfo;
- int rc;
- rc = pt_si_get_btn_data(cd);
- if (rc < 0)
- return rc;
- pt_si_get_ttdata(cd);
- pt_si_get_sensing_conf_data(cd);
- pt_si_setup(cd);
- pt_si_put_log_data(cd);
- si->ready = true;
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_free_si_ptrs
- *
- * SUMMARY: Frees all memory associated with the System Information within
- * core data
- *
- * RETURN: n/a
- *
- * PARAMETERS:
- * *cd - pointer to core data structure
- ******************************************************************************/
- static void pt_free_si_ptrs(struct pt_core_data *cd)
- {
- struct pt_sysinfo *si = &cd->sysinfo;
- kfree(si->btn);
- kfree(si->xy_mode);
- kfree(si->xy_data);
- }
- /*******************************************************************************
- * FUNCTION: pt_hid_output_get_sysinfo_
- *
- * SUMMARY: Sends the PIP Get SYS INFO command to the DUT and waits for the
- * response.
- *
- * RETURN::
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data structure
- ******************************************************************************/
- static int pt_hid_output_get_sysinfo_(struct pt_core_data *cd)
- {
- int rc = 0;
- struct pt_hid_output hid_output = {
- CREATE_PIP1_FW_CMD(PIP1_CMD_ID_GET_SYSINFO),
- .timeout_ms = PT_PIP1_CMD_GET_SYSINFO_TIMEOUT,
- };
- rc = pt_pip1_send_output_and_wait_(cd, &hid_output);
- if (rc)
- return rc;
- /* Parse the sysinfo data */
- rc = pt_get_sysinfo_regs(cd);
- if (rc)
- pt_free_si_ptrs(cd);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_hid_output_get_sysinfo
- *
- * SUMMARY: Protected call to pt_hid_output_get_sysinfo_
- *
- * RETURN::
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data structure
- ******************************************************************************/
- static int pt_hid_output_get_sysinfo(struct pt_core_data *cd)
- {
- int rc;
- rc = request_exclusive(cd, cd->dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail get exclusive ex=%p own=%p\n",
- __func__, cd->exclusive_dev, cd->dev);
- return rc;
- }
- rc = pt_hid_output_get_sysinfo_(cd);
- if (release_exclusive(cd, cd->dev) < 0)
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail to release exclusive\n", __func__);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_pip_suspend_scanning_
- *
- * SUMMARY: Sends the PIP Suspend Scanning command to the DUT
- *
- * RETURN::
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data structure
- ******************************************************************************/
- static int pt_pip_suspend_scanning_(struct pt_core_data *cd)
- {
- int rc = 0;
- struct pt_hid_output hid_output = {
- CREATE_PIP1_FW_CMD(PIP1_CMD_ID_SUSPEND_SCANNING),
- };
- rc = pt_pip1_send_output_and_wait_(cd, &hid_output);
- if (rc) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: Suspend Scan PIP cmd failed. rc = %d\n",
- __func__, rc);
- }
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_pip_suspend_scanning
- *
- * SUMMARY: Protected wrapper for calling pt_hid_output_suspend_scanning_
- *
- * RETURN::
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data structure
- ******************************************************************************/
- static int pt_pip_suspend_scanning(struct pt_core_data *cd)
- {
- int rc;
- rc = request_exclusive(cd, cd->dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail get exclusive ex=%p own=%p\n",
- __func__, cd->exclusive_dev, cd->dev);
- return rc;
- }
- rc = pt_pip_suspend_scanning_(cd);
- if (release_exclusive(cd, cd->dev) < 0)
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail to release exclusive\n", __func__);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: _pt_request_pip_suspend_scanning
- *
- * SUMMARY: Function pointer included in core_nonhid_cmd struct for external
- * calls to the protected or unprotected call to pt_pip_suspend_scanning
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * protect - 0 = call non-protected function
- * 1 = call protected function
- ******************************************************************************/
- static int _pt_request_pip_suspend_scanning(struct device *dev,
- int protect)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- if (protect)
- return pt_pip_suspend_scanning(cd);
- return pt_pip_suspend_scanning_(cd);
- }
- /*******************************************************************************
- * FUNCTION: pt_pip_resume_scanning_
- *
- * SUMMARY: Sends the PIP Resume Scanning command to the DUT
- *
- * RETURN::
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data structure
- ******************************************************************************/
- static int pt_pip_resume_scanning_(struct pt_core_data *cd)
- {
- int rc = 0;
- struct pt_hid_output hid_output = {
- CREATE_PIP1_FW_CMD(PIP1_CMD_ID_RESUME_SCANNING),
- };
- rc = pt_pip1_send_output_and_wait_(cd, &hid_output);
- if (rc) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: Resume Scan PIP cmd failed. rc = %d\n",
- __func__, rc);
- }
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_pip_resume_scanning
- *
- * SUMMARY: Protected wrapper for calling pt_pip_resume_scanning_
- *
- * RETURN::
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data structure
- ******************************************************************************/
- static int pt_pip_resume_scanning(struct pt_core_data *cd)
- {
- int rc;
- rc = request_exclusive(cd, cd->dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail get exclusive ex=%p own=%p\n",
- __func__, cd->exclusive_dev, cd->dev);
- return rc;
- }
- rc = pt_pip_resume_scanning_(cd);
- if (release_exclusive(cd, cd->dev) < 0)
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail to release exclusive\n", __func__);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: _pt_request_pip_resume_scanning
- *
- * SUMMARY: Function pointer included in core_nonhid_cmd struct for external
- * calls to the protected or unprotected call to pt_pip_resume_scanning
- *
- * RETURN::
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * protect - 0 = call non-protected function
- * 1 = call protected function
- ******************************************************************************/
- static int _pt_request_pip_resume_scanning(struct device *dev,
- int protect)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- if (protect)
- return pt_pip_resume_scanning(cd);
- return pt_pip_resume_scanning_(cd);
- }
- /*******************************************************************************
- * FUNCTION: pt_pip_get_param_
- *
- * SUMMARY: Sends a PIP command 0x05 Get Parameter to the DUT and returns
- * the 32bit parameter value
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * param_id - parameter ID to retrieve
- * *value - value of DUT parameter
- ******************************************************************************/
- static int pt_pip_get_param_(struct pt_core_data *cd,
- u8 param_id, u32 *value)
- {
- int write_length = 1;
- u8 param[1] = { param_id };
- u8 read_param_id;
- int param_size;
- u8 *ptr;
- int rc = 0;
- int i;
- struct pt_hid_output hid_output = {
- CREATE_PIP1_FW_CMD(PIP1_CMD_ID_GET_PARAM),
- .write_length = write_length,
- .write_buf = param,
- };
- rc = pt_pip1_send_output_and_wait_(cd, &hid_output);
- if (rc)
- return rc;
- read_param_id = cd->response_buf[5];
- if (read_param_id != param_id)
- return -EPROTO;
- param_size = cd->response_buf[6];
- ptr = &cd->response_buf[7];
- *value = 0;
- for (i = 0; i < param_size; i++)
- *value += ptr[i] << (i * 8);
- return 0;
- }
- /*******************************************************************************
- * FUNCTION: pt_pip_get_param
- *
- * SUMMARY: Protected call to pt_hid_output_get_param_ by a request exclusive
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * param_id - parameter ID to retrieve
- * *value - value of DUT parameter
- ******************************************************************************/
- static int pt_pip_get_param(struct pt_core_data *cd,
- u8 param_id, u32 *value)
- {
- int rc;
- rc = request_exclusive(cd, cd->dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail get exclusive ex=%p own=%p\n",
- __func__, cd->exclusive_dev, cd->dev);
- return rc;
- }
- rc = pt_pip_get_param_(cd, param_id, value);
- if (release_exclusive(cd, cd->dev) < 0)
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail to release exclusive\n", __func__);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: _pt_request_pip_get_param
- *
- * SUMMARY: Function pointer included in core_nonhid_cmd struct for external
- * calls to the protected or unprotected call to pt_pip_get_param
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * protect - flag to call protected or non protected function
- * param_id - parameter ID to retrieve
- * *value - value of DUT parameter
- ******************************************************************************/
- int _pt_request_pip_get_param(struct device *dev,
- int protect, u8 param_id, u32 *value)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- if (protect)
- return pt_pip_get_param(cd, param_id, value);
- return pt_pip_get_param_(cd, param_id, value);
- }
- /*******************************************************************************
- * FUNCTION: pt_pip_set_param_
- *
- * SUMMARY: Sends a PIP command 0x06 Set Parameter to the DUT writing the
- * passed in value to flash
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * param_id - parameter ID to set
- * value - value to write
- * size - size to write
- ******************************************************************************/
- static int pt_pip_set_param_(struct pt_core_data *cd,
- u8 param_id, u32 value, u8 size)
- {
- u8 write_buf[6];
- u8 *ptr = &write_buf[2];
- int rc = 0;
- int i;
- struct pt_hid_output hid_output = {
- CREATE_PIP1_FW_CMD(PIP1_CMD_ID_SET_PARAM),
- .write_buf = write_buf,
- };
- write_buf[0] = param_id;
- write_buf[1] = size;
- for (i = 0; i < size; i++) {
- ptr[i] = value & 0xFF;
- value = value >> 8;
- }
- hid_output.write_length = 2 + size;
- rc = pt_pip1_send_output_and_wait_(cd, &hid_output);
- if (rc)
- return rc;
- if (param_id != cd->response_buf[5] || size != cd->response_buf[6])
- return -EPROTO;
- return 0;
- }
- /*******************************************************************************
- * FUNCTION: pt_pip_set_param
- *
- * SUMMARY: Protected call to pt_hid_output_set_param_ by a request exclusive
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * param_id - parameter ID to set
- * value - value to write
- * size - size to write
- ******************************************************************************/
- static int pt_pip_set_param(struct pt_core_data *cd,
- u8 param_id, u32 value, u8 size)
- {
- int rc;
- rc = request_exclusive(cd, cd->dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail get exclusive ex=%p own=%p\n",
- __func__, cd->exclusive_dev, cd->dev);
- return rc;
- }
- rc = pt_pip_set_param_(cd, param_id, value, size);
- if (release_exclusive(cd, cd->dev) < 0)
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail to release exclusive\n", __func__);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: _pt_request_pip_set_param
- *
- * SUMMARY: Function pointer included in core_nonhid_cmd struct for external
- * calls to the protected or unprotected call to pt_pip_set_param
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * protect - flag to call protected or non-protected
- * param_id - parameter ID to set
- * value - value to write
- * size - size to write
- ******************************************************************************/
- int _pt_request_pip_set_param(struct device *dev, int protect,
- u8 param_id, u32 value, u8 size)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- if (protect)
- return pt_pip_set_param(cd, param_id, value, size);
- return pt_pip_set_param_(cd, param_id, value, size);
- }
- /*******************************************************************************
- * FUNCTION: _pt_pip_enter_easywake_state_
- *
- * SUMMARY: Sends a PIP command 0x09 Enter EasyWake State to the DUT
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * data - easywake guesture (Only used for PIP1.6 and earlier)
- * *return_data - return status if easywake was entered
- ******************************************************************************/
- static int pt_hid_output_enter_easywake_state_(
- struct pt_core_data *cd, u8 data, u8 *return_data)
- {
- int write_length = 1;
- u8 param[1] = { data };
- int rc = 0;
- struct pt_hid_output hid_output = {
- CREATE_PIP1_FW_CMD(PIP1_CMD_ID_ENTER_EASYWAKE_STATE),
- .write_length = write_length,
- .write_buf = param,
- };
- rc = pt_pip1_send_output_and_wait_(cd, &hid_output);
- if (rc)
- return rc;
- *return_data = cd->response_buf[5];
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_pip_verify_config_block_crc_
- *
- * SUMMARY: Sends the PIP "Verify Data Block CRC" (0x20) command to the DUT
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer the core data structure
- * ebid - enumerated block ID
- * *status - PIP command status
- * calculated_crc - calculated CRC
- * stored_crc - stored CRC in config area
- ******************************************************************************/
- static int pt_pip_verify_config_block_crc_(
- struct pt_core_data *cd, u8 ebid, u8 *status,
- u16 *calculated_crc, u16 *stored_crc)
- {
- int write_length = 1;
- u8 param[1] = { ebid };
- u8 *ptr;
- int rc = 0;
- struct pt_hid_output hid_output = {
- CREATE_PIP1_FW_CMD(PIP1_CMD_ID_VERIFY_CONFIG_BLOCK_CRC),
- .write_length = write_length,
- .write_buf = param,
- };
- rc = pt_pip1_send_output_and_wait_(cd, &hid_output);
- if (rc)
- return rc;
- ptr = &cd->response_buf[5];
- *status = ptr[0];
- *calculated_crc = get_unaligned_le16(&ptr[1]);
- *stored_crc = get_unaligned_le16(&ptr[3]);
- return 0;
- }
- /*******************************************************************************
- * FUNCTION: pt_pip_verify_config_block_crc
- *
- * SUMMARY: Protected call to pt_hid_output_verify_config_block_crc_() within
- * an exclusive access to the DUT.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer the core data structure
- * ebid - enumerated block ID
- * *status - PIP command status
- * calculated_crc - calculated CRC
- * stored_crc - stored CRC in config area
- ******************************************************************************/
- static int pt_pip_verify_config_block_crc(
- struct pt_core_data *cd, u8 ebid, u8 *status,
- u16 *calculated_crc, u16 *stored_crc)
- {
- int rc;
- rc = request_exclusive(cd, cd->dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail get exclusive ex=%p own=%p\n",
- __func__, cd->exclusive_dev, cd->dev);
- return rc;
- }
- rc = pt_pip_verify_config_block_crc_(cd, ebid, status,
- calculated_crc, stored_crc);
- if (release_exclusive(cd, cd->dev) < 0)
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail to release exclusive\n", __func__);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: _pt_request_pip_verify_config_block_crc
- *
- * SUMMARY: Function pointer included in core_nonhid_cmd struct for external
- * calls to the protected or unprotected call to
- * pt_pip_verify_config_block_crc_
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * protect - flag to call protected or non-protected
- * ebid - enumerated block ID
- * *status - PIP command status
- * calculated_crc - calculated CRC
- * stored_crc - stored CRC in config area
- ******************************************************************************/
- static int _pt_request_pip_verify_config_block_crc(
- struct device *dev, int protect, u8 ebid, u8 *status,
- u16 *calculated_crc, u16 *stored_crc)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- if (protect)
- return pt_pip_verify_config_block_crc(cd, ebid,
- status, calculated_crc, stored_crc);
- return pt_pip_verify_config_block_crc_(cd, ebid,
- status, calculated_crc, stored_crc);
- }
- /*******************************************************************************
- * FUNCTION: pt_pip_get_config_row_size_
- *
- * SUMMARY: Sends the PIP "Get Data Row Size" (0x21) command to the DUT
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * protect - flag to call protected or non-protected
- * *row_size - pointer to store the retrieved row size
- ******************************************************************************/
- static int pt_pip_get_config_row_size_(struct pt_core_data *cd,
- u16 *row_size)
- {
- int rc = 0;
- struct pt_hid_output hid_output = {
- CREATE_PIP1_FW_CMD(PIP1_CMD_ID_GET_CONFIG_ROW_SIZE),
- };
- rc = pt_pip1_send_output_and_wait_(cd, &hid_output);
- if (rc)
- return rc;
- *row_size = get_unaligned_le16(&cd->response_buf[5]);
- return 0;
- }
- /*******************************************************************************
- * FUNCTION: pt_pip_get_config_row_size
- *
- * SUMMARY: Protected call to pt_hid_output_get_config_row_size_ within
- * an exclusive access to the DUT.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * protect - flag to call protected or non-protected
- * *row_size - pointer to store the retrieved row size
- ******************************************************************************/
- static int pt_pip_get_config_row_size(struct pt_core_data *cd,
- u16 *row_size)
- {
- int rc;
- rc = request_exclusive(cd, cd->dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail get exclusive ex=%p own=%p\n",
- __func__, cd->exclusive_dev, cd->dev);
- return rc;
- }
- rc = pt_pip_get_config_row_size_(cd, row_size);
- if (release_exclusive(cd, cd->dev) < 0)
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail to release exclusive\n", __func__);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: _pt_request_pip_get_config_row_size
- *
- * SUMMARY: Function pointer included in core_nonhid_cmd struct for external
- * calls to the protected or unprotected call to
- * pt_pip_get_config_row_size_
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * protect - flag to call protected or non-protected
- * *row_size - pointer to store the retrieved row size
- ******************************************************************************/
- static int _pt_request_pip_get_config_row_size(struct device *dev,
- int protect, u16 *row_size)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- if (protect)
- return pt_pip_get_config_row_size(cd, row_size);
- return pt_pip_get_config_row_size_(cd, row_size);
- }
- /*******************************************************************************
- * FUNCTION: pt_pip1_read_data_block_
- *
- * SUMMARY: Sends the PIP "Read Data Block" (0x22) command to the DUT and print
- * output data to the "read_buf" and update "crc".
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * row_number - row number
- * length - length of data to read
- * ebid - block id
- * *actual_read_len - Actual data length read
- * *read_buf - pointer to the buffer to store read data
- * read_buf_size - size of read_buf
- * *crc - pointer to store CRC of row data
- ******************************************************************************/
- static int pt_pip1_read_data_block_(struct pt_core_data *cd,
- u16 row_number, u16 length, u8 ebid, u16 *actual_read_len,
- u8 *read_buf, u16 read_buf_size, u16 *crc)
- {
- int read_ebid;
- int status;
- int rc = 0;
- int write_length = 5;
- u8 write_buf[5];
- u8 cmd_offset = 0;
- u16 calc_crc;
- struct pt_hid_output hid_output = {
- CREATE_PIP1_FW_CMD(PIP1_CMD_ID_READ_DATA_BLOCK),
- .write_length = write_length,
- .write_buf = write_buf,
- };
- write_buf[cmd_offset++] = LOW_BYTE(row_number);
- write_buf[cmd_offset++] = HI_BYTE(row_number);
- write_buf[cmd_offset++] = LOW_BYTE(length);
- write_buf[cmd_offset++] = HI_BYTE(length);
- write_buf[cmd_offset++] = ebid;
- rc = pt_pip1_send_output_and_wait_(cd, &hid_output);
- if (rc)
- return rc;
- status = cd->response_buf[5];
- if (status)
- return status;
- read_ebid = cd->response_buf[6];
- if ((read_ebid != ebid) || (cd->response_buf[9] != 0))
- return -EPROTO;
- *actual_read_len = get_unaligned_le16(&cd->response_buf[7]);
- if (length == 0 || *actual_read_len == 0)
- return 0;
- if (read_buf_size >= *actual_read_len &&
- *actual_read_len < PT_MAX_PIP2_MSG_SIZE)
- memcpy(read_buf, &cd->response_buf[10], *actual_read_len);
- else
- return -EPROTO;
- *crc = get_unaligned_le16(&cd->response_buf[*actual_read_len + 10]);
- /* Validate Row Data CRC */
- calc_crc = _pt_compute_crc(read_buf, *actual_read_len);
- if (*crc == calc_crc) {
- return 0;
- } else {
- pt_debug(cd->dev, DL_ERROR,
- "%s: CRC Mismatch packet=0x%04X calc=0x%04X\n",
- __func__, *crc, calc_crc);
- return -EPROTO;
- }
- }
- /*******************************************************************************
- * FUNCTION: _pt_request_pip_read_data_block
- *
- * SUMMARY: Function pointer included in core_nonhid_cmd struct for external
- * calls to pt_pip1_read_data_block_
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * row_number - row number
- * length - length of data to read
- * ebid - block id
- * *actual_read_len - Actual data length read
- * *read_buf - pointer to the buffer to store read data
- * *crc - pointer to store CRC of row data
- ******************************************************************************/
- static int _pt_request_pip_read_data_block(struct device *dev,
- u16 row_number, u16 length, u8 ebid, u16 *actual_read_len,
- u8 *read_buf, u16 read_buf_size, u16 *crc)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- return pt_pip1_read_data_block_(cd, row_number, length,
- ebid, actual_read_len, read_buf, read_buf_size, crc);
- }
- /*******************************************************************************
- * FUNCTION: pt_pip1_write_data_block_
- *
- * SUMMARY: Sends the PIP "Write Data Block" (0x23) command to the DUT and
- * write data to the data block.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * row_number - row in config block to write to
- * write_length - length of data to write
- * ebid - enumerated block ID
- * *write_buf - pointer to buffer to write
- * *security_key - pointer to security key to allow write
- * *actual_write_len - pointer to store data length actually written
- ******************************************************************************/
- static int pt_pip1_write_data_block_(struct pt_core_data *cd,
- u16 row_number, u16 write_length, u8 ebid, u8 *write_buf,
- u8 *security_key, u16 *actual_write_len)
- {
- /* row_number + write_len + ebid + security_key + crc */
- u16 full_write_length = 2 + 2 + 1 + write_length + 8 + 2;
- u8 *full_write_buf;
- u8 cmd_offset = 0;
- u16 crc;
- int status;
- int rc = 0;
- int read_ebid;
- u8 *data;
- struct pt_hid_output hid_output = {
- CREATE_PIP1_FW_CMD(PIP1_CMD_ID_WRITE_DATA_BLOCK),
- .write_length = full_write_length,
- .timeout_ms = PT_PIP1_CMD_WRITE_CONF_BLOCK_TIMEOUT,
- };
- if (write_length > PT_CAL_DATA_ROW_SIZE)
- return -EINVAL;
- full_write_buf = kzalloc(full_write_length, GFP_KERNEL);
- if (!full_write_buf)
- return -ENOMEM;
- hid_output.write_buf = full_write_buf;
- full_write_buf[cmd_offset++] = LOW_BYTE(row_number);
- full_write_buf[cmd_offset++] = HI_BYTE(row_number);
- full_write_buf[cmd_offset++] = LOW_BYTE(write_length);
- full_write_buf[cmd_offset++] = HI_BYTE(write_length);
- full_write_buf[cmd_offset++] = ebid;
- data = &full_write_buf[cmd_offset];
- memcpy(data, write_buf, write_length);
- cmd_offset += write_length;
- memcpy(&full_write_buf[cmd_offset], security_key, 8);
- cmd_offset += 8;
- crc = _pt_compute_crc(data, write_length);
- full_write_buf[cmd_offset++] = LOW_BYTE(crc);
- full_write_buf[cmd_offset++] = HI_BYTE(crc);
- rc = pt_pip1_send_output_and_wait_(cd, &hid_output);
- if (rc)
- goto exit;
- status = cd->response_buf[5];
- if (status) {
- rc = -EINVAL;
- goto exit;
- }
- read_ebid = cd->response_buf[6];
- if (read_ebid != ebid) {
- rc = -EPROTO;
- goto exit;
- }
- *actual_write_len = get_unaligned_le16(&cd->response_buf[7]);
- exit:
- kfree(full_write_buf);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: _pt_request_pip_write_data_block
- *
- * SUMMARY: Function pointer included in core_nonhid_cmd struct for external
- * calls to the protected or unprotected call to pt_pip1_write_data_block_
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * protect - flag to call protected or non-protected
- * row_number - row in config block to write to
- * write_length - length of data to write
- * ebid - enumerated block ID
- * *write_buf - pointer to buffer to write
- * *security_key - pointer to security key to allow write
- * *actual_write_len - pointer to store data length actually written
- ******************************************************************************/
- static int _pt_request_pip_write_data_block(struct device *dev,
- u16 row_number, u16 write_length, u8 ebid,
- u8 *write_buf, u8 *security_key, u16 *actual_write_len)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- return pt_pip1_write_data_block_(cd, row_number,
- write_length, ebid, write_buf, security_key,
- actual_write_len);
- }
- /*******************************************************************************
- * FUNCTION: pt_pip_get_data_structure_
- *
- * SUMMARY: Sends the PIP "Retrieve Data Structure" (0x24) command to the DUT
- * returning a structure of data defined by data_id
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * read_offset - read pointer offset
- * read_length - length of data to read
- * data_id - data ID to read
- * *status - pointer to store the read response status
- * *data_format - pointer to store format of data read
- * *actual_read_len - pointer to store data length actually read
- * *data - pointer to store data read
- ******************************************************************************/
- static int pt_pip_get_data_structure_(
- struct pt_core_data *cd, u16 read_offset, u16 read_length,
- u8 data_id, u8 *status, u8 *data_format, u16 *actual_read_len,
- u8 *data)
- {
- int rc = 0;
- u16 total_read_len = 0;
- u16 read_len;
- u16 off_buf = 0;
- u8 write_buf[5];
- u8 read_data_id;
- struct pt_hid_output hid_output = {
- CREATE_PIP1_FW_CMD(PIP1_CMD_ID_GET_DATA_STRUCTURE),
- .write_length = 5,
- .write_buf = write_buf,
- };
- again:
- write_buf[0] = LOW_BYTE(read_offset);
- write_buf[1] = HI_BYTE(read_offset);
- write_buf[2] = LOW_BYTE(read_length);
- write_buf[3] = HI_BYTE(read_length);
- write_buf[4] = data_id;
- rc = pt_pip1_send_output_and_wait_(cd, &hid_output);
- if (rc)
- return rc;
- if (cd->response_buf[5] != PT_CMD_STATUS_SUCCESS)
- goto set_status;
- read_data_id = cd->response_buf[6];
- if (read_data_id != data_id)
- return -EPROTO;
- read_len = get_unaligned_le16(&cd->response_buf[7]);
- if (read_len && data) {
- memcpy(&data[off_buf], &cd->response_buf[10], read_len);
- total_read_len += read_len;
- if (read_len < read_length) {
- read_offset += read_len;
- off_buf += read_len;
- read_length -= read_len;
- goto again;
- }
- }
- if (data_format)
- *data_format = cd->response_buf[9];
- if (actual_read_len)
- *actual_read_len = total_read_len;
- set_status:
- if (status)
- *status = cd->response_buf[5];
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_pip_get_data_structure
- *
- * SUMMARY: Protected call to pt_hid_output_get_data_structure within
- * an exclusive access to the DUT.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * read_offset - read pointer offset
- * read_length - length of data to read
- * data_id - data ID to read
- * *status - pointer to store the read response status
- * *data_format - pointer to store format of data read
- * *actual_read_len - pointer to store data length actually read
- * *data - pointer to store data read
- ******************************************************************************/
- static int pt_pip_get_data_structure(
- struct pt_core_data *cd, u16 read_offset, u16 read_length,
- u8 data_id, u8 *status, u8 *data_format, u16 *actual_read_len,
- u8 *data)
- {
- int rc;
- rc = request_exclusive(cd, cd->dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail get exclusive ex=%p own=%p\n",
- __func__, cd->exclusive_dev, cd->dev);
- return rc;
- }
- rc = pt_pip_get_data_structure_(cd, read_offset,
- read_length, data_id, status, data_format,
- actual_read_len, data);
- if (release_exclusive(cd, cd->dev) < 0)
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail to release exclusive\n", __func__);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: _pt_request_pip_get_data_structure
- *
- * SUMMARY: Function pointer included in core_nonhid_cmd struct for external
- * calls to the protected or unprotected call to
- * pt_pip_get_data_structure
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * protect - flag to call protected or non-protected
- * read_offset - read pointer offset
- * read_length - length of data to read
- * data_id - data ID to read
- * *status - pointer to store the read response status
- * *data_format - pointer to store format of data read
- * *actual_read_len - pointer to store data length actually read
- * *data - pointer to store data read
- ******************************************************************************/
- static int _pt_request_pip_get_data_structure(struct device *dev,
- int protect, u16 read_offset, u16 read_length, u8 data_id,
- u8 *status, u8 *data_format, u16 *actual_read_len, u8 *data)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- if (protect)
- return pt_pip_get_data_structure(cd,
- read_offset, read_length, data_id, status,
- data_format, actual_read_len, data);
- return pt_pip_get_data_structure_(cd,
- read_offset, read_length, data_id, status,
- data_format, actual_read_len, data);
- }
- /*******************************************************************************
- * FUNCTION: _pt_manage_local_cal_data
- *
- * SUMMARY: This function manages storing or restoring a copy of the Firmware
- * CALIBRATION data. It stores it in a local static array and can be
- * cleared, loaded or used to restore the CAL data back to the running FW.
- * The CAL data is read or restored by use of the PIP1 commands:
- * - READ_DATA_BLOCK (0x22)
- * - WRITE_DATA_BLOCK (0x23)
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * action - One of the following actions:
- * - PT_CAL_DATA_SAVE
- * - PT_CAL_DATA_RESTORE
- * - PT_CAL_DATA_CLEAR
- * - PT_CAL_DATA_SIZE
- * *size - pointer to the number of bytes transferred
- * *crc - pointer to Chip ID CRC that the CAL data was retrieved from
- ******************************************************************************/
- static int _pt_manage_local_cal_data(struct device *dev, u8 action, u16 *size,
- unsigned short *crc)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- struct pt_ttdata *ttdata = &cd->sysinfo.ttdata;
- unsigned short calc_id_crc = 0;
- static u8 *cal_cache_data;
- static u16 cal_cache_len;
- static unsigned short cal_cache_chip_id;
- int rc = 0;
- u8 *tmp_data = NULL;
- u8 row_number = 0;
- u8 prefix[20];
- u16 cal_size = 0;
- u16 transfer_size;
- u16 act_trans_len = 0;
- u16 byte_offset = 0;
- u16 cal_blk_size;
- u16 total_rows;
- u16 remain_bytes;
- u16 data_block_crc;
- u16 buf_size = 12;
- pt_debug(dev, DL_INFO, "%s: ATM - CAL Cache action=%d\n",
- __func__, action);
- switch (action) {
- case PT_CAL_DATA_SAVE:
- /* Read the size of the CAL block and calculate # rows */
- tmp_data = kzalloc(buf_size, GFP_KERNEL);
- if (!tmp_data) {
- rc = -ENOMEM;
- goto exit;
- }
- /*
- * Don't check rc as doing a read size will give a false
- * error on the CRC check.
- */
- rc = pt_pip1_read_data_block_(cd, row_number, 0, PT_CAL_EBID,
- &act_trans_len, tmp_data, buf_size, &data_block_crc);
- cal_blk_size = act_trans_len;
- kfree(tmp_data);
- pt_debug(dev, DL_INFO,
- "%s: CAL Cache size=%d FW CAL Size=%d\n",
- __func__, cal_cache_len, cal_blk_size);
- /* Safety net to ensure we didn't read incorrect size */
- if (cal_blk_size > PT_CAL_DATA_MAX_SIZE) {
- pt_debug(dev, DL_ERROR, "%s: Alloc struct Failed\n",
- __func__);
- rc = 1;
- goto exit;
- }
- /* Panels could have diff CAL sizes, Re-allocate the cache */
- if (cal_blk_size != cal_cache_len) {
- kfree(cal_cache_data);
- cal_cache_data = kzalloc(cal_blk_size + 2,
- GFP_KERNEL);
- if (!cal_cache_data) {
- rc = -ENOMEM;
- goto exit;
- }
- pt_debug(dev, DL_INFO, "%s: CAL Cache Allocated\n",
- __func__);
- }
- memset(&cal_cache_data[0], 0, cal_blk_size + 2);
- /* Calculate how many rows [0-n] (PIP Transactions) */
- total_rows = (cal_blk_size / PT_CAL_DATA_ROW_SIZE) - 1;
- remain_bytes = cal_blk_size % PT_CAL_DATA_ROW_SIZE;
- /* Add row if we have a last partial row */
- if (remain_bytes > 0)
- total_rows++;
- pt_debug(dev, DL_INFO,
- "%s: CAL size=%d rows=[0-%d] partial row bytes=%d\n",
- __func__, cal_blk_size, total_rows, remain_bytes);
- /* Read all rows unless an error occurs */
- rc = 0;
- while (rc == 0 && row_number <= total_rows) {
- act_trans_len = 0;
- if (remain_bytes > 0 && row_number == total_rows)
- transfer_size = remain_bytes;
- else
- transfer_size = PT_CAL_DATA_ROW_SIZE;
- rc = pt_pip1_read_data_block_(cd, row_number,
- transfer_size, PT_CAL_EBID,
- &act_trans_len,
- &cal_cache_data[byte_offset], cal_blk_size + 2,
- &data_block_crc);
- if (rc) {
- /* Error occurred, exit loop */
- cal_size = 0;
- break;
- }
- pt_debug(dev, DL_INFO,
- "%s: CAL read rc=%d actual read len=%d\n",
- __func__, rc, act_trans_len);
- byte_offset += act_trans_len;
- cal_size = byte_offset;
- scnprintf(prefix, sizeof(prefix), "%s[%d]", "CAL DATA ROW", row_number);
- pt_pr_buf(dev, DL_INFO,
- &cal_cache_data[byte_offset - act_trans_len],
- act_trans_len, prefix);
- row_number++;
- }
- if (cal_size > 0) {
- /* Save a CRC of the chip info the CAL was saved from */
- calc_id_crc = crc_ccitt_calculate(
- (u8 *)&ttdata->chip_rev, 4 + PT_UID_SIZE);
- cal_cache_chip_id = calc_id_crc;
- cal_cache_len = cal_size;
- pt_debug(dev, DL_INFO,
- "%s: CAL Cache: CRC=0x%04X Total Size=%d\n",
- __func__, calc_id_crc, cal_size);
- }
- *size = cal_size;
- *crc = calc_id_crc;
- break;
- case PT_CAL_DATA_RESTORE:
- cal_size = cal_cache_len;
- while ((rc == 0) && (byte_offset < cal_size)) {
- if (cal_size - byte_offset > PT_CAL_DATA_ROW_SIZE)
- transfer_size = PT_CAL_DATA_ROW_SIZE;
- else
- transfer_size = cal_size - byte_offset;
- rc = pt_pip1_write_data_block_(cd, row_number,
- transfer_size, PT_CAL_EBID,
- &cal_cache_data[byte_offset],
- (u8 *)pt_data_block_security_key,
- &act_trans_len);
- byte_offset += act_trans_len;
- pt_debug(dev, DL_INFO, "%s: CAL write byte offset=%d\n",
- __func__, byte_offset);
- scnprintf(prefix, sizeof(prefix), "%s[%d]", "CAL DATA ROW", row_number);
- pt_pr_buf(dev, DL_INFO,
- &cal_cache_data[byte_offset - act_trans_len],
- act_trans_len, prefix);
- if ((byte_offset > cal_size) ||
- (act_trans_len != transfer_size))
- rc = -EIO;
- row_number++;
- }
- *size = byte_offset;
- *crc = cal_cache_chip_id;
- break;
- case PT_CAL_DATA_CLEAR:
- if (cal_cache_data)
- memset(&cal_cache_data[0], 0, cal_cache_len);
- cal_cache_len = 0;
- cal_cache_chip_id = 0;
- *size = 0;
- *crc = 0;
- break;
- case PT_CAL_DATA_INFO:
- default:
- *size = cal_cache_len;
- *crc = cal_cache_chip_id;
- pt_debug(dev, DL_INFO,
- "%s: CAL Cache: CRC=%04X Total Size=%d\n",
- __func__, cal_cache_chip_id,
- cal_cache_len);
- break;
- }
- exit:
- pt_debug(dev, DL_INFO,
- "%s: CAL Cache exit: rc=%d CRC=0x%04X Total Size=%d\n",
- __func__, rc, *crc, *size);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_pip_run_selftest_
- *
- * SUMMARY: Sends the PIP "Run Self Test" (0x26) command to the DUT
- * to execute a FW built in self test
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * test_id - enumerated test ID to run
- * write_idacs_to_flash - flag whether to write new IDACS to flash
- * *status - pointer to store the read response status
- * *summary_results - pointer to store the results summary
- * *results_available - pointer to store if results are available
- *****************************************************************************/
- static int pt_pip_run_selftest_(
- struct pt_core_data *cd, u8 test_id,
- u8 write_idacs_to_flash, u8 *status, u8 *summary_result,
- u8 *results_available)
- {
- int rc = 0;
- u8 write_buf[2];
- struct pt_hid_output hid_output = {
- CREATE_PIP1_FW_CMD(PIP1_CMD_ID_RUN_SELF_TEST),
- .write_length = 2,
- .write_buf = write_buf,
- .timeout_ms = PT_PIP1_CMD_RUN_SELF_TEST_TIMEOUT,
- };
- write_buf[0] = test_id;
- write_buf[1] = write_idacs_to_flash;
- if (cd->active_dut_generation == DUT_PIP2_CAPABLE)
- hid_output.write_length = 1;
- rc = pt_pip1_send_output_and_wait_(cd, &hid_output);
- if (rc)
- return rc;
- if (status)
- *status = cd->response_buf[5];
- if (summary_result)
- *summary_result = cd->response_buf[6];
- /* results_available only available before PIP 1.03 */
- if (cd->sysinfo.ready && !IS_PIP_VER_GE(&cd->sysinfo, 1, 3)) {
- if (results_available)
- *results_available = cd->response_buf[7];
- }
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_pip_run_selftest
- *
- * SUMMARY: Protected call to pt_hid_output_run_selftest within
- * an exclusive access to the DUT.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * test_id - enumerated test ID to run
- * write_idacs_to_flash - flag whether to write new IDACS to flash
- * *status - pointer to store the read response status
- * *summary_results - pointer to store the results summary
- * *results_available - pointer to store if results are available
- ******************************************************************************/
- static int pt_pip_run_selftest(
- struct pt_core_data *cd, u8 test_id,
- u8 write_idacs_to_flash, u8 *status, u8 *summary_result,
- u8 *results_available)
- {
- int rc;
- rc = request_exclusive(cd, cd->dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail get exclusive ex=%p own=%p\n",
- __func__, cd->exclusive_dev, cd->dev);
- return rc;
- }
- rc = pt_pip_run_selftest_(cd, test_id,
- write_idacs_to_flash, status, summary_result,
- results_available);
- if (release_exclusive(cd, cd->dev) < 0)
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail to release exclusive\n", __func__);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: _pt_request_pip_run_selftest
- *
- * SUMMARY: Function pointer included in core_nonhid_cmd struct for external
- * calls to the protected or unprotected call to pt_pip_run_selftest
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * protect - flag to call protected or non-protected
- * test_id - enumerated test ID to run
- * write_idacs_to_flash - flag whether to write new IDACS to flash
- * *status - pointer to store the read response status
- * *summary_results - pointer to store the results summary
- * *results_available - pointer to store if results are available
- ******************************************************************************/
- static int _pt_request_pip_run_selftest(struct device *dev,
- int protect, u8 test_id, u8 write_idacs_to_flash, u8 *status,
- u8 *summary_result, u8 *results_available)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- if (protect)
- return pt_pip_run_selftest(cd, test_id,
- write_idacs_to_flash, status, summary_result,
- results_available);
- return pt_pip_run_selftest_(cd, test_id,
- write_idacs_to_flash, status, summary_result,
- results_available);
- }
- /*******************************************************************************
- * FUNCTION: _pt_pip_get_selftest_result_
- *
- * SUMMARY: Sends the PIP "Get Self Test Results" (0x27) command to the DUT
- * to retrieve the self test results from the self test already executed
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * read_offset - read pointer offset
- * read_length - length of data to read
- * test_id - enumerated test ID to read selftest results from
- * *status - pointer to store the read response status
- * *actual_read_len - pointer to store data length actually read
- * *status - pointer to where the cmd response statas is stored
- ******************************************************************************/
- static int pt_pip_get_selftest_result_(
- struct pt_core_data *cd, u16 read_offset, u16 read_length,
- u8 test_id, u8 *status, u16 *actual_read_len, u8 *data)
- {
- int rc = 0;
- u16 total_read_len = 0;
- u16 read_len;
- u16 off_buf = 0;
- u8 write_buf[5];
- u8 read_test_id;
- bool repeat;
- struct pt_hid_output hid_output = {
- CREATE_PIP1_FW_CMD(PIP1_CMD_ID_GET_SELF_TEST_RESULT),
- .write_length = 5,
- .write_buf = write_buf,
- };
- /*
- * Do not repeat reading for Auto Shorts test
- * when PIP version < 1.3
- */
- repeat = IS_PIP_VER_GE(&cd->sysinfo, 1, 3)
- || test_id != PT_ST_ID_AUTOSHORTS;
- again:
- write_buf[0] = LOW_BYTE(read_offset);
- write_buf[1] = HI_BYTE(read_offset);
- write_buf[2] = LOW_BYTE(read_length);
- write_buf[3] = HI_BYTE(read_length);
- write_buf[4] = test_id;
- rc = pt_pip1_send_output_and_wait_(cd, &hid_output);
- if (rc)
- return rc;
- if (cd->response_buf[5] != PT_CMD_STATUS_SUCCESS)
- goto set_status;
- read_test_id = cd->response_buf[6];
- if (read_test_id != test_id)
- return -EPROTO;
- read_len = get_unaligned_le16(&cd->response_buf[7]);
- if (read_len && data) {
- memcpy(&data[off_buf], &cd->response_buf[10], read_len);
- total_read_len += read_len;
- if (repeat && read_len < read_length) {
- read_offset += read_len;
- off_buf += read_len;
- read_length -= read_len;
- goto again;
- }
- }
- if (actual_read_len)
- *actual_read_len = total_read_len;
- set_status:
- if (status)
- *status = cd->response_buf[5];
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: _pt_pip_get_selftest_result
- *
- * SUMMARY: Protected call to pt_hid_output_get_selftest_result by exclusive
- * access to the DUT
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * read_offset - read pointer offset
- * read_length - length of data to read
- * test_id - enumerated test ID to read selftest results from
- * *status - pointer to store the read response status
- * *actual_read_len - pointer to store data length actually read
- * *status - pointer to where the cmd response statas is stored
- ******************************************************************************/
- static int pt_pip_get_selftest_result(
- struct pt_core_data *cd, u16 read_offset, u16 read_length,
- u8 test_id, u8 *status, u16 *actual_read_len, u8 *data)
- {
- int rc;
- rc = request_exclusive(cd, cd->dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail get exclusive ex=%p own=%p\n",
- __func__, cd->exclusive_dev, cd->dev);
- return rc;
- }
- rc = pt_pip_get_selftest_result_(cd, read_offset,
- read_length, test_id, status, actual_read_len, data);
- if (release_exclusive(cd, cd->dev) < 0)
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail to release exclusive\n", __func__);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: _pt_request_pip_get_selftest_result
- *
- * SUMMARY: Function pointer included in core_nonhid_cmd struct for external
- * calls to the protected or unprotected call to pt_pip_get_selftest_result
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * protect - flag to call protected or non-protected
- * read_offset - read pointer offset
- * read_length - length of data to read
- * test_id - enumerated test ID to read selftest results from
- * *status - pointer to store the read response status
- * *actual_read_len - pointer to store data length actually read
- * *data - pointer to where the data read is stored
- ******************************************************************************/
- static int _pt_request_pip_get_selftest_result(struct device *dev,
- int protect, u16 read_offset, u16 read_length, u8 test_id,
- u8 *status, u16 *actual_read_len, u8 *data)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- if (protect)
- return pt_pip_get_selftest_result(cd, read_offset,
- read_length, test_id, status, actual_read_len,
- data);
- return pt_pip_get_selftest_result_(cd, read_offset,
- read_length, test_id, status, actual_read_len,
- data);
- }
- /*******************************************************************************
- * FUNCTION: _pt_pip_load_self_test_param
- *
- * SUMMARY: Sends the PIP "Load Self Test Parameters" (0x25) command to the DUT
- * to load parameters needed by a self test
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * self_test_id - enumerated test ID for which the parmeters belong
- * load_offset - mem offset to where to load parameters
- * load_length - length of parameter data to load
- * *parameters - pointer to list of parameter data
- * *status - pointer to store the response status
- * *ret_test_id - pointer to returned test id the parameters were stored
- * *act_load_len - pointer to store the actual load length that was writen
- ******************************************************************************/
- static int pt_pip_load_self_test_param_(struct pt_core_data *cd,
- u8 self_test_id, u16 load_offset, u16 load_length,
- u8 *parameters, u8 *status, u8 *ret_test_id, u16 *act_load_len)
- {
- int rc = 0;
- int i;
- u8 write_buf[PT_MAX_PIP1_MSG_SIZE];
- struct pt_hid_output hid_output = {
- CREATE_PIP1_FW_CMD(PIP1_CMD_ID_LOAD_SELF_TEST_PARAM),
- .write_length = 5 + load_length,
- .write_buf = write_buf,
- .timeout_ms = PT_PIP1_CMD_DEFAULT_TIMEOUT,
- };
- write_buf[0] = LOW_BYTE(load_offset);
- write_buf[1] = HI_BYTE(load_offset);
- write_buf[2] = LOW_BYTE(load_length);
- write_buf[3] = HI_BYTE(load_length);
- write_buf[4] = self_test_id;
- for (i = 0; i < load_length; i++)
- write_buf[i + 5] = parameters[i];
- rc = pt_pip1_send_output_and_wait_(cd, &hid_output);
- if (rc)
- return rc;
- if (status)
- *status = cd->response_buf[5];
- if (ret_test_id)
- *ret_test_id = cd->response_buf[6];
- if (act_load_len)
- *act_load_len = get_unaligned_le16(&cd->response_buf[7]);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_pip_load_self_test_param
- *
- * SUMMARY: Protected call to pt_pip_load_self_test_param_ within an exclusive
- * access to the DUT.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * self_test_id - enumerated test ID for which the parmeters belong
- * load_offset - mem offset to where to load parameters
- * load_length - length of parameter data to load
- * *parameters - pointer to list of parameter data
- * *status - pointer to store the response status
- * *ret_test_id - pointer to returned test id the parameters were stored
- * *act_load_len - pointer to store the actual load length that was writen
- ******************************************************************************/
- static int pt_pip_load_self_test_param(struct pt_core_data *cd,
- u8 self_test_id, u16 load_offset, u16 load_length,
- u8 *parameters, u8 *status, u8 *ret_test_id, u16 *act_load_len)
- {
- int rc;
- rc = request_exclusive(cd, cd->dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail get exclusive ex=%p own=%p\n",
- __func__, cd->exclusive_dev, cd->dev);
- return rc;
- }
- rc = pt_pip_load_self_test_param_(cd, self_test_id, load_offset,
- load_length, parameters, status, ret_test_id, act_load_len);
- if (release_exclusive(cd, cd->dev) < 0)
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail to release exclusive\n", __func__);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: _pt_request_pip_load_self_test_param
- *
- * SUMMARY: Function pointer included in core_nonhid_cmd struct for external
- * calls to the protected or unprotected call to
- * pt_pip_load_self_test_param
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * protect - flag to call protected or non-protected
- * self_test_id - enumerated test ID for which the parmeters belong
- * load_offset - mem offset to where to load parameters
- * load_length - length of parameter data to load
- * *parameters - pointer to list of parameter data
- * *status - pointer to store the response status
- * *ret_test_id - pointer to returned test id the parameters were stored
- * *act_load_len - pointer to store the actual load length that was writen
- ******************************************************************************/
- static int _pt_request_pip_load_self_test_param(struct device *dev,
- int protect, u8 self_test_id, u16 load_offset, u16 load_length,
- u8 *parameters, u8 *status, u8 *ret_test_id, u16 *act_load_len)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- if (protect)
- return pt_pip_load_self_test_param(cd, self_test_id,
- load_offset, load_length, parameters, status, ret_test_id,
- act_load_len);
- return pt_pip_load_self_test_param_(cd, self_test_id, load_offset,
- load_length, parameters, status, ret_test_id, act_load_len);
- }
- /*******************************************************************************
- * FUNCTION: pt_pip_calibrate_ext_
- *
- * SUMMARY: Send the PIP1 Extended Calibrate command (0x30) to the DUT waiting
- * for the response
- *
- * NOTE: This calibrate command requires the DUT to support PIP version >= 1.10
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * *cal_data - pointer to extended calibration data structure
- * *status - pointer to where the command response status is stored
- ******************************************************************************/
- static int pt_pip_calibrate_ext_(struct pt_core_data *cd,
- struct pt_cal_ext_data *cal_data, u8 *status)
- {
- int rc = 0;
- int write_length = 4;
- u8 write_buf[4];
- u16 size = 0;
- unsigned short crc = 0;
- struct pt_hid_output hid_output = {
- CREATE_PIP1_FW_CMD(PIP1_CMD_ID_CALIBRATE_DEVICE_EXTENDED),
- .write_length = write_length,
- .write_buf = write_buf,
- .timeout_ms = PT_PIP1_CMD_CALIBRATE_EXT_TIMEOUT,
- };
- if (cal_data == NULL)
- return -EINVAL;
- memcpy(write_buf, cal_data, sizeof(struct pt_cal_ext_data));
- rc = pt_pip1_send_output_and_wait_(cd, &hid_output);
- if (rc)
- return rc;
- if (status)
- *status = cd->response_buf[5];
- /*
- * When doing a calibration on a flashless DUT, save CAL data in
- * the TTDL cache on any successful calibration
- */
- if (cd->response_buf[5] == 0 && cd->cal_cache_in_host) {
- pt_debug(cd->dev, DL_INFO, "%s: Retrieve and Save CAL\n",
- __func__);
- rc = _pt_manage_local_cal_data(cd->dev, PT_CAL_DATA_SAVE,
- &size, &crc);
- if (rc)
- pt_debug(cd->dev, DL_ERROR,
- "%s: Error Saving CAL rc=%d\n", __func__, rc);
- else
- pt_debug(cd->dev, DL_INFO,
- "%s: Saved CAL: chip ID=0x%04X size=%d\n",
- __func__, crc, size);
- }
- return 0;
- }
- /*******************************************************************************
- * FUNCTION: pt_pip_calibrate_ext
- *
- * SUMMARY: Protected call to pt_pip_calibrate_ext_ by exclusive access to the
- * DUT
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * *cal_data - pointer to extended calibration data structure
- * *status - pointer to where the command response status is stored
- ******************************************************************************/
- static int pt_pip_calibrate_ext(struct pt_core_data *cd,
- struct pt_cal_ext_data *cal_data, u8 *status)
- {
- int rc;
- rc = request_exclusive(cd, cd->dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail get exclusive ex=%p own=%p\n",
- __func__, cd->exclusive_dev, cd->dev);
- return rc;
- }
- rc = pt_pip_calibrate_ext_(cd, cal_data, status);
- if (release_exclusive(cd, cd->dev) < 0)
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail to release exclusive\n", __func__);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: _pt_request_pip_calibrate_ext
- *
- * SUMMARY: Function pointer included in core_nonhid_cmd struct for external
- * calls to the protected or unprotected call to pt_pip_calibrate_ext
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * protect - flag to call protected or non-protected
- * *cal_data - pointer to extended calibration data structure
- * *status - pointer to where the command response status is stored
- ******************************************************************************/
- static int _pt_request_pip_calibrate_ext(struct device *dev,
- int protect, struct pt_cal_ext_data *cal_data, u8 *status)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- if (protect)
- return pt_pip_calibrate_ext(cd, cal_data, status);
- return pt_pip_calibrate_ext_(cd, cal_data, status);
- }
- /*******************************************************************************
- * FUNCTION: pt_pip_calibrate_idacs_
- *
- * SUMMARY: Send the PIP Calibrate IDACs command (0x28) to the DUT waiting
- * for the response
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * mode - sense mode to calibrate (0-5)
- * *status - pointer to where the command response status is stored
- ******************************************************************************/
- static int pt_pip_calibrate_idacs_(struct pt_core_data *cd,
- u8 mode, u8 *status)
- {
- int rc = 0;
- int write_length = 1;
- u8 write_buf[1];
- u8 cmd_offset = 0;
- struct pt_hid_output hid_output = {
- CREATE_PIP1_FW_CMD(PIP1_CMD_ID_CALIBRATE_IDACS),
- .write_length = write_length,
- .write_buf = write_buf,
- .timeout_ms = PT_PIP1_CMD_CALIBRATE_IDAC_TIMEOUT,
- };
- write_buf[cmd_offset++] = mode;
- rc = pt_pip1_send_output_and_wait_(cd, &hid_output);
- if (rc)
- return rc;
- *status = cd->response_buf[5];
- if (*status)
- return -EINVAL;
- return 0;
- }
- /*******************************************************************************
- * FUNCTION: pt_pip_calibrate_idacs
- *
- * SUMMARY: Protected call to pt_hid_output_calibrate_idacs_ by exclusive
- * access to the DUT
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * mode - sense mode to calibrate (0-5)
- * *status - pointer to where the command response status is stored
- ******************************************************************************/
- static int pt_pip_calibrate_idacs(struct pt_core_data *cd,
- u8 mode, u8 *status)
- {
- int rc;
- rc = request_exclusive(cd, cd->dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail get exclusive ex=%p own=%p\n",
- __func__, cd->exclusive_dev, cd->dev);
- return rc;
- }
- rc = pt_pip_calibrate_idacs_(cd, mode, status);
- if (release_exclusive(cd, cd->dev) < 0)
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail to release exclusive\n", __func__);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: _pt_request_pip_calibrate_idacs
- *
- * SUMMARY: Function pointer included in core_nonhid_cmd struct for external
- * calls to the protected or unprotected call to pt_pip_calibrate_idacs
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * protect - flag to call protected or non-protected
- * mode - sense mode to calibrate (0-5)
- * *status - pointer to where the command response status is stored
- ******************************************************************************/
- static int _pt_request_pip_calibrate_idacs(struct device *dev,
- int protect, u8 mode, u8 *status)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- if (protect)
- return pt_pip_calibrate_idacs(cd, mode, status);
- return pt_pip_calibrate_idacs_(cd, mode, status);
- }
- /*******************************************************************************
- * FUNCTION: pt_hid_output_initialize_baselines_
- *
- * SUMMARY: Send the PIP "Initialize Baselines" command (0x29) to the DUT
- * waiting for the response.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * test_id - bit type flag to allow initialize baseline MUT,BTN,SELG
- * each or together with a single command.
- * *status - pointer to where the command response status is stored
- ******************************************************************************/
- static int pt_hid_output_initialize_baselines_(
- struct pt_core_data *cd, u8 test_id, u8 *status)
- {
- int rc = 0;
- int write_length = 1;
- u8 write_buf[1];
- u8 cmd_offset = 0;
- struct pt_hid_output hid_output = {
- CREATE_PIP1_FW_CMD(PIP1_CMD_ID_INITIALIZE_BASELINES),
- .write_length = write_length,
- .write_buf = write_buf,
- };
- write_buf[cmd_offset++] = test_id;
- rc = pt_pip1_send_output_and_wait_(cd, &hid_output);
- if (rc)
- return rc;
- *status = cd->response_buf[5];
- if (*status)
- return -EINVAL;
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_hid_output_initialize_baselines
- *
- * SUMMARY: Protected call to pt_hid_output_initialize_baselines_ by exclusive
- * access to the DUT
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * test_id - enumerated ID against which to initialize the baseline
- * *status - pointer to where the command response status is stored
- ******************************************************************************/
- static int pt_hid_output_initialize_baselines(struct pt_core_data *cd,
- u8 test_id, u8 *status)
- {
- int rc;
- rc = request_exclusive(cd, cd->dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail get exclusive ex=%p own=%p\n",
- __func__, cd->exclusive_dev, cd->dev);
- return rc;
- }
- rc = pt_hid_output_initialize_baselines_(cd, test_id, status);
- if (release_exclusive(cd, cd->dev) < 0)
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail to release exclusive\n", __func__);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: _pt_request_pip_initialize_baselines
- *
- * SUMMARY: Function pointer included in core_nonhid_cmd struct for external
- * calls to the protected or unprotected call to
- * pt_pip_initialize_baselines
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * protect - flag to call protected or non-protected
- * test_id - enumerated ID against which to initialize the baseline
- * *status - pointer to where the command response status is stored
- ******************************************************************************/
- static int _pt_request_pip_initialize_baselines(struct device *dev,
- int protect, u8 test_id, u8 *status)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- if (protect)
- return pt_hid_output_initialize_baselines(cd, test_id,
- status);
- return pt_hid_output_initialize_baselines_(cd, test_id, status);
- }
- /*******************************************************************************
- * FUNCTION: pt_hid_output_exec_panel_scan_
- *
- * SUMMARY: Sends the PIP "Execute Panel Scan" (0x2A) to the DUT and waits for
- * the response
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- ******************************************************************************/
- static int pt_hid_output_exec_panel_scan_(struct pt_core_data *cd)
- {
- struct pt_hid_output hid_output = {
- CREATE_PIP1_FW_CMD(PIP1_CMD_ID_EXEC_PANEL_SCAN),
- };
- return pt_pip1_send_output_and_wait_(cd, &hid_output);
- }
- /*******************************************************************************
- * FUNCTION: pt_hid_output_exec_panel_scan
- *
- * SUMMARY: Protected call to pt_hid_output_exec_panel_scan_ by exclusive
- * access to the DUT.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- ******************************************************************************/
- static int pt_hid_output_exec_panel_scan(struct pt_core_data *cd)
- {
- int rc;
- rc = request_exclusive(cd, cd->dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail get exclusive ex=%p own=%p\n",
- __func__, cd->exclusive_dev, cd->dev);
- return rc;
- }
- rc = pt_hid_output_exec_panel_scan_(cd);
- if (release_exclusive(cd, cd->dev) < 0)
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail to release exclusive\n", __func__);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_pip2_exec_panel_scan_
- *
- * SUMMARY: Send the PIP2 "Execute Panel Scan" (0x21) to the DUT and waits for
- * the response
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * scan_type - type of panel scan to perform (PIP2 only)
- ******************************************************************************/
- static int pt_pip2_exec_panel_scan_(struct pt_core_data *cd, u8 scan_type)
- {
- int rc = 0;
- u8 data[2];
- u8 read_buf[10];
- u16 actual_read_len;
- pt_debug(cd->dev, DL_DEBUG, "%s: PIP2 Execute Scan %d\n",
- __func__, scan_type);
- data[0] = scan_type;
- rc = _pt_request_pip2_send_cmd(cd->dev,
- PT_CORE_CMD_UNPROTECTED, PIP2_CMD_EXECUTE_SCAN,
- data, 1, read_buf, &actual_read_len);
- if (rc) {
- pt_debug(cd->dev, DL_ERROR,
- "%s EXECUTE_SCAN command for type %d failed. rc=%d\n",
- __func__, scan_type, rc);
- }
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_pip2_exec_panel_scan
- *
- * SUMMARY: Protected call to pt_pip2_exec_panel_scan_ by exclusive
- * access to the DUT.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * scan_type - type of panel scan to perform (PIP2 only)
- ******************************************************************************/
- static int pt_pip2_exec_panel_scan(struct pt_core_data *cd, u8 scan_type)
- {
- int rc;
- rc = request_exclusive(cd, cd->dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail get exclusive ex=%p own=%p\n",
- __func__, cd->exclusive_dev, cd->dev);
- return rc;
- }
- rc = pt_pip2_exec_panel_scan_(cd, scan_type);
- if (release_exclusive(cd, cd->dev) < 0)
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail to release exclusive\n", __func__);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: _pt_request_pip_exec_panel_scan
- *
- * SUMMARY: Function pointer included in core_nonhid_cmd struct for external
- * calls to the protected or unprotected call to
- * pt_pip2_exec_panel_scan or pt_hid_output_exec_panel_scan
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * protect - flag to call protected or non-protected
- * scan_type - type of panel scan to perform (PIP2 only)
- ******************************************************************************/
- static int _pt_request_pip_exec_panel_scan(struct device *dev,
- int protect, u8 scan_type)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- if (cd->sysinfo.ready && IS_PIP_VER_GE(&cd->sysinfo, 1, 12)) {
- if (protect)
- return pt_pip2_exec_panel_scan(cd, scan_type);
- return pt_pip2_exec_panel_scan_(cd, scan_type);
- }
- if (protect)
- return pt_hid_output_exec_panel_scan(cd);
- return pt_hid_output_exec_panel_scan_(cd);
- }
- /*******************************************************************************
- * FUNCTION: pt_hid_output_retrieve_panel_scan_
- *
- * SUMMARY: Sends the PIP "Retrieve Panel Scan" (0x2B) command to the DUT
- * to retrieve the specified data type for a the last successful Execute
- * Panel Scan command.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * protect - flag to call protected or non-protected
- * read_offset - read pointer offset
- * read_count - length of data to read
- * data_id - enumerated test ID to read selftest results from
- * *response - pointer to store the read response status
- * *config - pointer to store config data
- * *actual_read_len - pointer to store data length actually read
- * *read_buf - pointer to the read buffer
- ******************************************************************************/
- static int pt_hid_output_retrieve_panel_scan_(
- struct pt_core_data *cd, u16 read_offset, u16 read_count,
- u8 data_id, u8 *response, u8 *config, u16 *actual_read_len,
- u8 *read_buf)
- {
- int status;
- u8 read_data_id;
- int rc = 0;
- int write_length = 5;
- u8 write_buf[5];
- u8 cmd_offset = 0;
- u8 data_elem_size;
- int size;
- int data_size;
- struct pt_hid_output hid_output = {
- CREATE_PIP1_FW_CMD(PIP1_CMD_ID_RETRIEVE_PANEL_SCAN),
- .write_length = write_length,
- .write_buf = write_buf,
- };
- write_buf[cmd_offset++] = LOW_BYTE(read_offset);
- write_buf[cmd_offset++] = HI_BYTE(read_offset);
- write_buf[cmd_offset++] = LOW_BYTE(read_count);
- write_buf[cmd_offset++] = HI_BYTE(read_count);
- write_buf[cmd_offset++] = data_id;
- rc = pt_pip1_send_output_and_wait_(cd, &hid_output);
- if (rc)
- return rc;
- status = cd->response_buf[5];
- if (status)
- return -EINVAL;
- read_data_id = cd->response_buf[6];
- if (read_data_id != data_id)
- return -EPROTO;
- size = get_unaligned_le16(&cd->response_buf[0]);
- *actual_read_len = get_unaligned_le16(&cd->response_buf[7]);
- *config = cd->response_buf[9];
- data_elem_size = *config & 0x07;
- data_size = *actual_read_len * data_elem_size;
- if (read_buf)
- memcpy(read_buf, &cd->response_buf[10], data_size);
- if (response)
- memcpy(response, cd->response_buf, size);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_hid_output_retrieve_panel_scan
- *
- * SUMMARY: Protected call to pt_hid_output_retrieve_panel_scan_ by exclusive
- * access to the DUT.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * protect - flag to call protected or non-protected
- * read_offset - read pointer offset
- * read_count - length of data to read
- * data_id - enumerated test ID to read selftest results from
- * *response - pointer to store the read response status
- * *config - pointer to store config data
- * *actual_read_len - pointer to store data length actually read
- * *read_buf - pointer to the read buffer
- ******************************************************************************/
- static int pt_hid_output_retrieve_panel_scan(
- struct pt_core_data *cd, u16 read_offset, u16 read_count,
- u8 data_id, u8 *response, u8 *config, u16 *actual_read_len,
- u8 *read_buf)
- {
- int rc;
- rc = request_exclusive(cd, cd->dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail get exclusive ex=%p own=%p\n",
- __func__, cd->exclusive_dev, cd->dev);
- return rc;
- }
- rc = pt_hid_output_retrieve_panel_scan_(cd, read_offset,
- read_count, data_id, response, config,
- actual_read_len, read_buf);
- if (release_exclusive(cd, cd->dev) < 0)
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail to release exclusive\n", __func__);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: _pt_request_pip_retrieve_panel_scan
- *
- * SUMMARY: Function pointer included in core_nonhid_cmd struct for external
- * calls to the protected or unprotected call to
- * pt_hid_output_retrieve_panel_scan
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * protect - flag to call protected or non-protected
- * read_offset - read pointer offset
- * read_count - length of data to read
- * data_id - enumerated test ID to read selftest results from
- * *response - pointer to store the read response status
- * *config - pointer to store config data
- * *actual_read_len - pointer to store data length actually read
- * *read_buf - pointer to the read buffer
- ******************************************************************************/
- static int _pt_request_pip_retrieve_panel_scan(struct device *dev,
- int protect, u16 read_offset, u16 read_count, u8 data_id,
- u8 *response, u8 *config, u16 *actual_read_len, u8 *read_buf)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- if (protect)
- return pt_hid_output_retrieve_panel_scan(cd,
- read_offset, read_count, data_id, response,
- config, actual_read_len, read_buf);
- return pt_hid_output_retrieve_panel_scan_(cd,
- read_offset, read_count, data_id, response,
- config, actual_read_len, read_buf);
- }
- /*******************************************************************************
- * FUNCTION: _pt_request_pip_user_cmd
- *
- * SUMMARY: Function pointer included in core_nonhid_cmd struct for external
- * calls to the protected or unprotected call to
- * pt_hid_output_user_cmd
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * protect - flag to call protected or non-protected
- * read_len - length of data to read
- * *read_buf - pointer to store read data
- * write_len - length of data to write
- * *write_buf - pointer to buffer to write
- * *actual_read_len - pointer to store data length actually read
- ******************************************************************************/
- static int _pt_request_pip_user_cmd(struct device *dev,
- int protect, u16 read_len, u8 *read_buf, u16 write_len,
- u8 *write_buf, u16 *actual_read_len)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- if (protect)
- return pt_hid_output_user_cmd(cd, read_len, read_buf,
- write_len, write_buf, actual_read_len);
- return pt_hid_output_user_cmd_(cd, read_len, read_buf,
- write_len, write_buf, actual_read_len);
- }
- /*******************************************************************************
- * FUNCTION: pt_hid_output_bl_get_information_
- *
- * SUMMARY: Sends the PIP "Get Bootloader Information" (0x38) command to the
- * DUT to retrieve bootloader version and chip identification information.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * *return_data - pointer to store the return data
- *****************************************************************************/
- static int pt_hid_output_bl_get_information_(struct pt_core_data *cd,
- u8 *return_data)
- {
- int rc;
- int data_len;
- struct pt_hid_output hid_output = {
- CREATE_PIP1_BL_CMD(PIP1_BL_CMD_ID_GET_INFO),
- };
- rc = pt_pip1_send_output_and_wait_(cd, &hid_output);
- if (rc)
- return rc;
- data_len = get_unaligned_le16(&cd->input_buf[6]);
- if (!data_len)
- return -EPROTO;
- memcpy(return_data, &cd->response_buf[8], data_len);
- return 0;
- }
- /*******************************************************************************
- * FUNCTION: pt_hid_output_bl_get_information
- *
- * SUMMARY: Protected call to pt_hid_output_bl_get_information_ by exclusive
- * access to the DUT.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * *return_data - pointer to store the return data
- ******************************************************************************/
- static int pt_hid_output_bl_get_information(struct pt_core_data *cd,
- u8 *return_data)
- {
- int rc;
- rc = request_exclusive(cd, cd->dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail get exclusive ex=%p own=%p\n",
- __func__, cd->exclusive_dev, cd->dev);
- return rc;
- }
- rc = pt_hid_output_bl_get_information_(cd, return_data);
- if (release_exclusive(cd, cd->dev) < 0)
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail to release exclusive\n", __func__);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: _pt_request_pip_bl_get_information
- *
- * SUMMARY: Function pointer included in core_nonhid_cmd struct for external
- * calls to the protected or unprotected call to
- * pt_hid_output_bl_get_information
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * protect - flag to call protected or non-protected
- * *return_data - pointer to store bl data
- ******************************************************************************/
- static int _pt_request_pip_bl_get_information(struct device *dev,
- int protect, u8 *return_data)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- if (protect)
- return pt_hid_output_bl_get_information(cd, return_data);
- return pt_hid_output_bl_get_information_(cd, return_data);
- }
- /*******************************************************************************
- * FUNCTION: pt_hid_output_bl_initiate_bl_
- *
- * SUMMARY: Sends the PIP "Get Bootloader Information" (0x48) command to the
- * DUT to erases the entire TrueTouch application, Configuration Data block,
- * and Design Data block in flash and enables the host to execute the Program
- * and Verify Row command to bootload the application image and data.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * protect - flag to call protected or non-protected
- * key_size - size of key
- * *key_buf - pointer to key data to allow operation
- * row_size - size of the meta data row
- * *metadata_row_buf - pointer to meta data to write
- ******************************************************************************/
- static int pt_hid_output_bl_initiate_bl_(struct pt_core_data *cd,
- u16 key_size, u8 *key_buf, u16 row_size, u8 *metadata_row_buf)
- {
- u16 write_length = key_size + row_size;
- u8 *write_buf;
- int rc = 0;
- struct pt_hid_output hid_output = {
- CREATE_PIP1_BL_CMD(PIP1_BL_CMD_ID_INITIATE_BL),
- .write_length = write_length,
- .timeout_ms = PT_PIP1_CMD_INITIATE_BL_TIMEOUT,
- };
- write_buf = kzalloc(write_length, GFP_KERNEL);
- if (!write_buf)
- return -ENOMEM;
- hid_output.write_buf = write_buf;
- if (key_size)
- memcpy(write_buf, key_buf, key_size);
- if (row_size)
- memcpy(&write_buf[key_size], metadata_row_buf, row_size);
- rc = pt_pip1_send_output_and_wait_(cd, &hid_output);
- kfree(write_buf);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_hid_output_bl_initiate_bl
- *
- * SUMMARY: Protected call to pt_hid_output_bl_initiate_bl_ by exclusive
- * access to the DUT.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * key_size - size of key
- * *key_buf - pointer to key data to allow operation
- * row_size - size of the meta data row
- * *metadata_row_buf - pointer to meta data to write
- ******************************************************************************/
- static int pt_hid_output_bl_initiate_bl(struct pt_core_data *cd,
- u16 key_size, u8 *key_buf, u16 row_size, u8 *metadata_row_buf)
- {
- int rc;
- rc = request_exclusive(cd, cd->dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail get exclusive ex=%p own=%p\n",
- __func__, cd->exclusive_dev, cd->dev);
- return rc;
- }
- rc = pt_hid_output_bl_initiate_bl_(cd, key_size, key_buf,
- row_size, metadata_row_buf);
- if (release_exclusive(cd, cd->dev) < 0)
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail to release exclusive\n", __func__);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: _pt_request_pip_bl_initiate_bl
- *
- * SUMMARY: Function pointer included in core_nonhid_cmd struct for external
- * calls to the protected or unprotected call to
- * pt_hid_output_bl_initiate_bl
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * protect - flag to call protected or non-protected
- * key_size - size of key
- * *key_buf - pointer to key data to allow operation
- * row_size - size of the meta data row
- * *metadata_row_buf - pointer to meta data to write
- ******************************************************************************/
- static int _pt_request_pip_bl_initiate_bl(struct device *dev,
- int protect, u16 key_size, u8 *key_buf, u16 row_size,
- u8 *metadata_row_buf)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- if (protect)
- return pt_hid_output_bl_initiate_bl(cd, key_size, key_buf,
- row_size, metadata_row_buf);
- return pt_hid_output_bl_initiate_bl_(cd, key_size, key_buf,
- row_size, metadata_row_buf);
- }
- /*******************************************************************************
- * FUNCTION: pt_hid_output_bl_program_and_verify_
- *
- * SUMMARY: Sends the PIP "Get Bootloader Information" (0x39) command to upload
- * and program a 128-byte row into the flash, and then verifies written data.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * data_len - length of data_buf
- * *data_buf - firmware image to program
- ******************************************************************************/
- static int pt_hid_output_bl_program_and_verify_(
- struct pt_core_data *cd, u16 data_len, u8 *data_buf)
- {
- struct pt_hid_output hid_output = {
- CREATE_PIP1_BL_CMD(PIP1_BL_CMD_ID_PROGRAM_AND_VERIFY),
- .write_length = data_len,
- .write_buf = data_buf,
- .timeout_ms = PT_PIP1_CMD_PROGRAM_AND_VERIFY_TIMEOUT,
- };
- return pt_pip1_send_output_and_wait_(cd, &hid_output);
- }
- /*******************************************************************************
- * FUNCTION: pt_hid_output_bl_program_and_verify
- *
- * SUMMARY: Protected call to pt_hid_output_bl_program_and_verify_ by exclusive
- * access to the DUT.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * data_len - length of data_buf
- * *data_buf - firmware image to program
- ******************************************************************************/
- static int pt_hid_output_bl_program_and_verify(
- struct pt_core_data *cd, u16 data_len, u8 *data_buf)
- {
- int rc;
- rc = request_exclusive(cd, cd->dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail get exclusive ex=%p own=%p\n",
- __func__, cd->exclusive_dev, cd->dev);
- return rc;
- }
- rc = pt_hid_output_bl_program_and_verify_(cd, data_len, data_buf);
- if (release_exclusive(cd, cd->dev) < 0)
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail to release exclusive\n", __func__);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: _pt_request_pip_bl_program_and_verify
- *
- * SUMMARY: Function pointer included in core_nonhid_cmds to allow other modules
- * to request to have the BL program and verify a FW image
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * protect - boolean to determine to call the protected function
- * data_len - length of data_buf
- * *data_buf - firmware image to program
- ******************************************************************************/
- static int _pt_request_pip_bl_program_and_verify(
- struct device *dev, int protect, u16 data_len, u8 *data_buf)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- if (protect)
- return pt_hid_output_bl_program_and_verify(cd, data_len,
- data_buf);
- return pt_hid_output_bl_program_and_verify_(cd, data_len,
- data_buf);
- }
- /*******************************************************************************
- * FUNCTION: pt_hid_output_bl_verify_app_integrity_
- *
- * SUMMARY: Sends the PIP "Get Bootloader Information" (0x31) command to
- * perform a full verification of the application integrity by calculating the
- * CRC of the image in flash and compare it to the expected CRC stored in the
- * Metadata row.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * *result - pointer to store result
- ******************************************************************************/
- static int pt_hid_output_bl_verify_app_integrity_(
- struct pt_core_data *cd, u8 *result)
- {
- int rc;
- struct pt_hid_output hid_output = {
- CREATE_PIP1_BL_CMD(PIP1_BL_CMD_ID_VERIFY_APP_INTEGRITY),
- };
- rc = pt_pip1_send_output_and_wait_(cd, &hid_output);
- if (rc) {
- *result = 0;
- return rc;
- }
- *result = cd->response_buf[8];
- return 0;
- }
- /*******************************************************************************
- * FUNCTION: pt_hid_output_bl_verify_app_integrity
- *
- * SUMMARY: Protected call to pt_hid_output_bl_verify_app_integrity_ by
- * exclusive access to the DUT.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * *result - pointer to store result
- ******************************************************************************/
- static int pt_hid_output_bl_verify_app_integrity(
- struct pt_core_data *cd, u8 *result)
- {
- int rc;
- rc = request_exclusive(cd, cd->dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail get exclusive ex=%p own=%p\n",
- __func__, cd->exclusive_dev, cd->dev);
- return rc;
- }
- rc = pt_hid_output_bl_verify_app_integrity_(cd, result);
- if (release_exclusive(cd, cd->dev) < 0)
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail to release exclusive\n", __func__);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: _pt_request_pip_bl_verify_app_integrity
- *
- * SUMMARY: Function pointer included in core_nonhid_cmds to allow other modules
- * to request to have the BL verify the application integrity (PIP1.x only)
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * protect - boolean to determine to call the protected function
- * *result - pointer to store result
- ******************************************************************************/
- static int _pt_request_pip_bl_verify_app_integrity(
- struct device *dev, int protect, u8 *result)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- if (protect)
- return pt_hid_output_bl_verify_app_integrity(cd, result);
- return pt_hid_output_bl_verify_app_integrity_(cd, result);
- }
- /*******************************************************************************
- * FUNCTION: pt_hid_output_bl_launch_app_
- *
- * SUMMARY: Sends the PIP "Launch Application" (0x3B) command to launch the
- * application from bootloader (PIP1.x only).
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- ******************************************************************************/
- static int pt_hid_output_bl_launch_app_(struct pt_core_data *cd)
- {
- struct pt_hid_output hid_output = {
- CREATE_PIP1_BL_CMD(PIP1_BL_CMD_ID_LAUNCH_APP),
- .reset_expected = 1,
- };
- return pt_pip1_send_output_and_wait_(cd, &hid_output);
- }
- /*******************************************************************************
- * FUNCTION: pt_hid_output_bl_launch_app
- *
- * SUMMARY: Protected call to pt_hid_output_bl_launch_app_ by exclusive access
- * to the DUT.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- ******************************************************************************/
- static int pt_hid_output_bl_launch_app(struct pt_core_data *cd)
- {
- int rc;
- rc = request_exclusive(cd, cd->dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail get exclusive ex=%p own=%p\n",
- __func__, cd->exclusive_dev, cd->dev);
- return rc;
- }
- rc = pt_hid_output_bl_launch_app_(cd);
- if (release_exclusive(cd, cd->dev) < 0)
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail to release exclusive\n", __func__);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: _pt_request_pip_launch_app
- *
- * SUMMARY: Function pointer included in core_nonhid_cmds to allow other modules
- * to request to have the BL launch the application. (PIP1.x only)
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * protect - boolean to determine to call the protected function
- ******************************************************************************/
- static int _pt_request_pip_launch_app(struct device *dev,
- int protect)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- if (protect)
- return pt_hid_output_bl_launch_app(cd);
- return pt_hid_output_bl_launch_app_(cd);
- }
- /*******************************************************************************
- * FUNCTION: pt_hid_output_bl_get_panel_id_
- *
- * SUMMARY: Sends the PIP "Get Panel ID" (0x3E) command to return the Panel ID
- * value store in the System Information.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * *panel_id - pointer to where the panel ID will be stored
- ******************************************************************************/
- static int pt_hid_output_bl_get_panel_id_(
- struct pt_core_data *cd, u8 *panel_id)
- {
- int rc;
- struct pt_hid_output hid_output = {
- CREATE_PIP1_BL_CMD(PIP1_BL_CMD_ID_GET_PANEL_ID),
- };
- rc = pt_pip1_send_output_and_wait_(cd, &hid_output);
- if (rc == -EPROTO && cd->response_buf[5] == ERROR_COMMAND) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: Get Panel ID command not supported\n",
- __func__);
- *panel_id = PANEL_ID_NOT_ENABLED;
- return 0;
- } else if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: Error on Get Panel ID command\n", __func__);
- return rc;
- }
- *panel_id = cd->response_buf[8];
- return 0;
- }
- /*******************************************************************************
- * FUNCTION: pt_hid_output_bl_get_panel_id
- *
- * SUMMARY: Protected call to pt_hid_output_bl_get_panel_id_ by exclusive access
- * to the DUT.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * *panel_id - pointer to where the panel ID will be stored
- ******************************************************************************/
- static int pt_hid_output_bl_get_panel_id(
- struct pt_core_data *cd, u8 *panel_id)
- {
- int rc;
- rc = request_exclusive(cd, cd->dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail get exclusive ex=%p own=%p\n",
- __func__, cd->exclusive_dev, cd->dev);
- return rc;
- }
- rc = pt_hid_output_bl_get_panel_id_(cd, panel_id);
- if (release_exclusive(cd, cd->dev) < 0)
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail to release exclusive\n", __func__);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: _pt_request_pip_bl_get_panel_id
- *
- * SUMMARY: Function pointer included in core_nonhid_cmds to allow other modules
- * to have the BL retrieve the panel ID
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * protect - flag to run in protected mode
- * *panel_id - pointer to where the panel ID will be stored
- ******************************************************************************/
- static int _pt_request_pip_bl_get_panel_id(
- struct device *dev, int protect, u8 *panel_id)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- if (protect)
- return pt_hid_output_bl_get_panel_id(cd, panel_id);
- return pt_hid_output_bl_get_panel_id_(cd, panel_id);
- }
- /*******************************************************************************
- * FUNCTION: pt_pip2_get_mode_sysmode_
- *
- * SUMMARY: Determine the current mode and system mode of the DUT by use of the
- * PIP2 STATUS command.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data structure
- * *mode - pointer to store the retrieved mode
- * *sys_mode - pointer to store the FW system mode
- ******************************************************************************/
- static int pt_pip2_get_mode_sysmode_(struct pt_core_data *cd,
- u8 *mode, u8 *sys_mode)
- {
- u16 actual_read_len;
- u8 read_buf[12];
- u8 status, boot;
- int rc = 0;
- rc = _pt_request_pip2_send_cmd(cd->dev, PT_CORE_CMD_UNPROTECTED,
- PIP2_CMD_ID_STATUS, NULL, 0, read_buf, &actual_read_len);
- pt_debug(cd->dev, DL_INFO, "%s: PIP2 STATUS command rc = %d\n",
- __func__, rc);
- if (!rc) {
- pt_pr_buf(cd->dev, DL_DEBUG, read_buf, actual_read_len,
- "PIP2 STATUS");
- status = read_buf[PIP2_RESP_STATUS_OFFSET];
- boot = read_buf[PIP2_RESP_BODY_OFFSET] & 0x01;
- if (sys_mode) {
- if (status == PIP2_RSP_ERR_NONE &&
- boot == PIP2_STATUS_APP_EXEC)
- *sys_mode = read_buf[PIP2_RESP_BODY_OFFSET + 1];
- else
- *sys_mode = FW_SYS_MODE_UNDEFINED;
- }
- if (mode) {
- if (status == PIP2_RSP_ERR_NONE &&
- boot == PIP2_STATUS_BOOT_EXEC)
- *mode = PT_MODE_BOOTLOADER;
- else if (status == PIP2_RSP_ERR_NONE &&
- boot == PIP2_STATUS_APP_EXEC)
- *mode = PT_MODE_OPERATIONAL;
- else
- *mode = PT_MODE_UNKNOWN;
- }
- } else {
- if (mode)
- *mode = PT_MODE_UNKNOWN;
- if (sys_mode)
- *sys_mode = FW_SYS_MODE_UNDEFINED;
- pt_debug(cd->dev, DL_WARN,
- "%s: Mode and sys_mode could not be determined\n",
- __func__);
- }
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_pip2_get_mode_sysmode
- *
- * SUMMARY: Protected call to pt_pip2_get_mode_sysmode_ by exclusive
- * access to the DUT.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data structure
- * *mode - pointer to store the retrieved mode
- * *sys_mode - pointer to store the FW system mode
- ******************************************************************************/
- static int pt_pip2_get_mode_sysmode(struct pt_core_data *cd,
- u8 *mode, u8 *sys_mode)
- {
- int rc;
- rc = request_exclusive(cd, cd->dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail get exclusive ex=%p own=%p\n",
- __func__, cd->exclusive_dev, cd->dev);
- return rc;
- }
- rc = pt_pip2_get_mode_sysmode_(cd, mode, sys_mode);
- if (release_exclusive(cd, cd->dev) < 0)
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail to release exclusive\n", __func__);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: _pt_request_pip2_get_mode_sysmode
- *
- * SUMMARY: Function pointer included in core_commands struct for external
- * calls to the protected or unprotected call to
- * pt_pip2_get_mode_sysmode
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *mode - pointer to store the retrieved mode
- * *sys_mode - pointer to store the FW system mode
- ******************************************************************************/
- static int _pt_request_pip2_get_mode_sysmode(struct device *dev,
- int protect, u8 *mode, u8 *sys_mode)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- if (protect)
- return pt_pip2_get_mode_sysmode(cd, mode, sys_mode);
- return pt_pip2_get_mode_sysmode_(cd, mode, sys_mode);
- }
- /*******************************************************************************
- * FUNCTION: _pt_poll_for_fw_exit_boot_mode
- *
- * SUMMARY: Verify and or poll for the FW to exit BOOT mode. During the FW BOOT
- * mode only the following PIP commands will be serviced, any other PIP
- * command the FW will respond with an "Invalid PIP Command" response.
- * - Get HID Descriptor (Register 0x0001, no command ID)
- * - Reset (Register 0x0005, RESET HID request)
- * - Ping (Register 0x0004, Command ID 0x00
- * - Get System Information (Register 0x0004, Command ID 0x02)
- * - PIP2 Status (Register 0x0101, Command ID 0x01)
- * - PIP2 Version (Register 0x0101, Command ID 0x07)
- * This function will loop on the results of the STATUS command until
- * the FW reports it is out of BOOT mode.
- *
- * NOTE:
- * - This function will update cd->fw_system_mode
- * - The STATUS cmd only supports this functionality for PIP 1.11+
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * timeout - max time (ms) to wait for FW to exit BOOT mode
- * actual_wait - pointer to actual time waited for FW to exit BOOT mode
- ******************************************************************************/
- static int _pt_poll_for_fw_exit_boot_mode(struct pt_core_data *cd, int timeout,
- int *actual_wait)
- {
- int loop = 0;
- u8 sys_mode = cd->fw_system_mode;
- u8 pause = 10; /* in ms */
- int rc = 0;
- int max_loop = (timeout / pause) + 1; /* Add 1 due to int math */
- if (cd->sysinfo.ready && !IS_PIP_VER_GE(&cd->sysinfo, 1, 11)) {
- /*
- * For PIP <1.11, no support for polling wait so do a hard
- * coded wait and assume the FW is out of BOOT. Added 1 to
- * timeout to make it clear in kmsg if non polling was done.
- */
- *actual_wait = PT_FW_EXIT_BOOT_MODE_TIMEOUT + 1;
- pt_debug(cd->dev, DL_ERROR,
- "%s: PIP %d.%d no support for ext STATUS, sleep %d\n",
- __func__,
- cd->sysinfo.ttdata.pip_ver_major,
- cd->sysinfo.ttdata.pip_ver_minor, *actual_wait);
- msleep(*actual_wait);
- sys_mode = FW_SYS_MODE_SCANNING;
- }
- if (sys_mode == FW_SYS_MODE_BOOT) {
- while (!rc && loop <= max_loop &&
- (sys_mode == FW_SYS_MODE_BOOT)) {
- loop++;
- usleep_range(9000, pause * 1000);
- rc = pt_pip2_get_mode_sysmode_(cd, NULL, &sys_mode);
- pt_debug(cd->dev, DL_DEBUG,
- "%s: FW in BOOT mode-sleep %dms, sys_mode=%d\n",
- __func__, loop * pause, sys_mode);
- }
- *actual_wait = (int)(loop * pause);
- pt_debug(cd->dev, DL_WARN,
- "%s: FW exited BOOT mode in %dms, sys_mode=%d\n",
- __func__, *actual_wait, sys_mode);
- if (rc)
- sys_mode = FW_SYS_MODE_UNDEFINED;
- else if (sys_mode == FW_SYS_MODE_BOOT ||
- sys_mode == FW_SYS_MODE_UNDEFINED)
- rc = -EBUSY;
- }
- mutex_lock(&cd->system_lock);
- cd->fw_system_mode = sys_mode;
- mutex_unlock(&cd->system_lock);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_poll_for_fw_exit_boot_mode
- *
- * SUMMARY: Protected call to _pt_poll_for_fw_exit_boot_mode by exclusive
- * access to the DUT.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * timeout - max time (ms) to wait for FW to exit BOOT mode
- * actual_wait - pointer to actual time waited for FW to exit BOOT mode
- ******************************************************************************/
- static int pt_poll_for_fw_exit_boot_mode(struct pt_core_data *cd, int timeout,
- int *actual_wait)
- {
- int rc;
- rc = request_exclusive(cd, cd->dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail get exclusive ex=%p own=%p\n",
- __func__, cd->exclusive_dev, cd->dev);
- return rc;
- }
- rc = _pt_poll_for_fw_exit_boot_mode(cd, timeout, actual_wait);
- if (release_exclusive(cd, cd->dev) < 0)
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail to release exclusive\n", __func__);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: _pt_get_fw_sys_mode
- *
- * SUMMARY: Determine the FW system mode. For PIP 1.11+ the
- * PIP2 STATUS command is used to directly query the FW system mode. For older
- * PIP versions, there is no direct PIP commamnd that will directly provide this
- * information but any PIP command above 0x1F requires scanning to be disabled
- * before it will be operational. If scanning was not disabled before sending
- * these PIP commands the FW will respond with a 6 byte error response. So to
- * safely determine the scanning state, a PIP message that will not affect the
- * operation of the FW was chosen:
- * "Verify Data Block CRC (ID 0x20)" is sent and if a 6 byte error code is
- * received scanning is active.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * *sys_mode - pointer to FW System mode
- * *mode - pointer to mode (BL/FW)
- ******************************************************************************/
- static int _pt_get_fw_sys_mode(struct pt_core_data *cd, u8 *sys_mode, u8 *mode)
- {
- int write_length = 1;
- int report_length;
- int rc = 0;
- u8 tmp_sys_mode = FW_SYS_MODE_UNDEFINED;
- u8 tmp_mode = PT_MODE_UNKNOWN;
- u8 param[1] = { PT_TCH_PARM_EBID };
- struct pt_hid_output hid_output = {
- CREATE_PIP1_FW_CMD(PIP1_CMD_ID_VERIFY_CONFIG_BLOCK_CRC),
- .write_length = write_length,
- .write_buf = param,
- .novalidate = true,
- };
- /* AFter PIP1.11 the preferred method is using STATUS cmd */
- if (IS_PIP_VER_GE(&cd->sysinfo, 1, 11)) {
- rc = pt_pip2_get_mode_sysmode_(cd, &tmp_mode, &tmp_sys_mode);
- pt_debug(cd->dev, DL_DEBUG, "%s: tmp_sys_mode=%d tmp_mode=%d\n",
- __func__, tmp_sys_mode, tmp_mode);
- if (!rc) {
- if (tmp_mode != PT_MODE_OPERATIONAL)
- tmp_sys_mode = FW_SYS_MODE_UNDEFINED;
- }
- goto exit;
- }
- /* Older systems use PIP1 CONFIG_BLOCK_CRC to best determine sys_mode */
- if (cd->mode != PT_MODE_OPERATIONAL) {
- tmp_mode = cd->mode;
- goto exit;
- }
- rc = pt_pip1_send_output_and_wait_(cd, &hid_output);
- if (rc)
- goto exit;
- report_length = (cd->response_buf[1] << 8) | (cd->response_buf[0]);
- if ((report_length == 0x06) &&
- ((cd->response_buf[4] & PIP1_RESP_COMMAND_ID_MASK) == 0x00) &&
- (cd->response_buf[5] == PIP1_CMD_ID_VERIFY_CONFIG_BLOCK_CRC)) {
- tmp_mode = PIP2_STATUS_APP_EXEC;
- tmp_sys_mode = FW_SYS_MODE_SCANNING;
- } else if ((report_length == 0x0A) &&
- ((cd->response_buf[4] & PIP1_RESP_COMMAND_ID_MASK) ==
- PIP1_CMD_ID_VERIFY_CONFIG_BLOCK_CRC)) {
- tmp_mode = PIP2_STATUS_APP_EXEC;
- tmp_sys_mode = FW_SYS_MODE_TEST;
- }
- exit:
- if (mode)
- *mode = tmp_mode;
- if (sys_mode)
- *sys_mode = tmp_sys_mode;
- pt_debug(cd->dev, DL_INFO, "%s: Return Mode=%d sys_mode=%d\n",
- __func__, tmp_mode, tmp_sys_mode);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_get_fw_sys_mode
- *
- * SUMMARY: Protected call to _pt_get_fw_sys_mode() to determine if FW scanning
- * is active or not.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * *sys_mode - pointer to fw system mode
- * *mode - pointer to mode
- ******************************************************************************/
- static int pt_get_fw_sys_mode(struct pt_core_data *cd, u8 *sys_mode, u8 *mode)
- {
- int rc;
- rc = request_exclusive(cd, cd->dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail get exclusive ex=%p own=%p\n",
- __func__, cd->exclusive_dev, cd->dev);
- return rc;
- }
- rc = _pt_get_fw_sys_mode(cd, sys_mode, mode);
- if (release_exclusive(cd, cd->dev) < 0)
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail to release exclusive\n", __func__);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: _pt_request_get_fw_sys_mode
- *
- * SUMMARY: Function pointer included in core_cmds to allow other modules
- * to request to get scan state
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * protect - flag to call protected or non-protected
- * *sys_mode - pointer to FW system mode
- * *mode - pointer to mode
- ******************************************************************************/
- static int _pt_request_get_fw_sys_mode(struct device *dev, int protect,
- u8 *sys_mode, u8 *mode)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- if (protect)
- return pt_get_fw_sys_mode(cd, sys_mode, mode);
- return _pt_get_fw_sys_mode(cd, sys_mode, mode);
- }
- /* Default hid descriptor to provide basic register map */
- const struct pt_hid_desc hid_desc_default = {
- 230, /* hid_desc_len */
- HID_APP_REPORT_ID, /* packet_id */
- 0x00, /* reserved_byte */
- 0x0100, /* bcd_version */
- 0x00EC, /* report_desc_len */
- 0x0002, /* report_desc_register */
- 0x0003, /* input_register */
- 0x00FE, /* max_input_len */
- 0x0004, /* output_register */
- 0x00FE, /* max_output_len */
- 0x0005, /* command_register */
- 0x0006, /* data_register */
- 0x04B4, /* vendor_id */
- 0xC101, /* product_id */
- 0x0100, /* version_id */
- {0x00, 0x00, 0x00, 0x00} /* reserved[4] */
- };
- /*******************************************************************************
- * FUNCTION: pt_init_hid_descriptor
- *
- * SUMMARY: Setup default values for HID descriptor structure
- *
- *
- * PARAMETERS:
- * *desc - pointer to the HID descriptor data read back from DUT
- ******************************************************************************/
- static inline void pt_init_hid_descriptor(struct pt_hid_desc *desc)
- {
- memcpy(desc, &hid_desc_default, sizeof(hid_desc_default));
- }
- /*******************************************************************************
- * FUNCTION: pt_get_hid_descriptor_
- *
- * SUMMARY: Send the get HID descriptor command to the DUT and load the response
- * into the HID descriptor structure
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * *desc - pointer to the HID descriptor data read back from DUT
- ******************************************************************************/
- static int pt_get_hid_descriptor_(struct pt_core_data *cd,
- struct pt_hid_desc *desc)
- {
- struct device *dev = cd->dev;
- int rc = 0;
- int t;
- u8 cmd[2];
- /*
- * During startup the HID descriptor is required for all future
- * processing. If IRQ is already asserted due to an early touch report
- * the report must be cleared before sending command.
- */
- pt_flush_bus_if_irq_asserted(cd, PT_FLUSH_BUS_BASED_ON_LEN);
- /* Read HID descriptor length and version */
- mutex_lock(&cd->system_lock);
- cd->hid_cmd_state = 1;
- mutex_unlock(&cd->system_lock);
- /* Set HID descriptor register */
- memcpy(cmd, &cd->hid_core.hid_desc_register,
- sizeof(cd->hid_core.hid_desc_register));
- pt_debug(cd->dev, DL_INFO, ">>> %s: Write Buffer [%zu]",
- __func__, sizeof(cmd));
- pt_pr_buf(cd->dev, DL_DEBUG, cmd, sizeof(cmd), ">>> Get HID Desc");
- rc = pt_adap_write_read_specific(cd, 2, cmd, NULL);
- if (rc) {
- pt_debug(dev, DL_ERROR,
- "%s: failed to get HID descriptor, rc=%d\n",
- __func__, rc);
- goto error;
- }
- t = wait_event_timeout(cd->wait_q, (cd->hid_cmd_state == 0),
- msecs_to_jiffies(PT_GET_HID_DESCRIPTOR_TIMEOUT));
- if (IS_TMO(t)) {
- #ifdef TTDL_DIAGNOSTICS
- cd->bus_transmit_error_count++;
- pt_toggle_err_gpio(cd, PT_ERR_GPIO_I2C_TRANS);
- #endif /* TTDL_DIAGNOSTICS */
- pt_debug(cd->dev, DL_ERROR,
- "%s: HID get descriptor timed out\n", __func__);
- rc = -ETIME;
- goto error;
- } else {
- cd->hw_detected = true;
- }
- /* Load the HID descriptor including all registers */
- memcpy((u8 *)desc, cd->response_buf, sizeof(struct pt_hid_desc));
- /* Check HID descriptor length and version */
- pt_debug(dev, DL_INFO, "%s: HID len:%X HID ver:%X\n", __func__,
- le16_to_cpu(desc->hid_desc_len),
- le16_to_cpu(desc->bcd_version));
- if (le16_to_cpu(desc->hid_desc_len) != sizeof(*desc) ||
- le16_to_cpu(desc->bcd_version) != HID_VERSION) {
- pt_debug(dev, DL_ERROR, "%s: Unsupported HID version\n",
- __func__);
- return -ENODEV;
- }
- goto exit;
- error:
- mutex_lock(&cd->system_lock);
- cd->hid_cmd_state = 0;
- mutex_unlock(&cd->system_lock);
- exit:
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_get_hid_descriptor
- *
- * SUMMARY: Protected call to pt_get_hid_descriptor_()
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * *desc - pointer to the HID descriptor data read back from DUT
- ******************************************************************************/
- static int pt_get_hid_descriptor(struct pt_core_data *cd,
- struct pt_hid_desc *desc)
- {
- int rc;
- rc = request_exclusive(cd, cd->dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail get exclusive ex=%p own=%p\n",
- __func__, cd->exclusive_dev, cd->dev);
- return rc;
- }
- rc = pt_get_hid_descriptor_(cd, desc);
- if (release_exclusive(cd, cd->dev) < 0)
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail to release exclusive\n", __func__);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_pip2_get_version_
- *
- * SUMMARY: Sends a PIP2 VERSION command to the DUT and stores the data in
- * cd-ttdata
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- ******************************************************************************/
- static int pt_pip2_get_version_(struct pt_core_data *cd)
- {
- int rc = 0;
- int status;
- u8 read_buf[64];
- u16 actual_read_len;
- rc = _pt_request_pip2_send_cmd(cd->dev,
- PT_CORE_CMD_UNPROTECTED, PIP2_CMD_ID_VERSION,
- NULL, 0, read_buf, &actual_read_len);
- if (rc) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: Error Sending PIP2 VERSION Cmd rc=%d\n",
- __func__, rc);
- return rc;
- }
- status = read_buf[PIP2_RESP_STATUS_OFFSET];
- if (status == 0) {
- /* Parse the PIP2 VERSION response into ttdata */
- pt_pip2_ver_load_ttdata(cd, actual_read_len);
- } else {
- pt_debug(cd->dev, DL_ERROR,
- "%s: Error in PIP2 VERSION Cmd status=%d\n",
- __func__, status);
- return status;
- }
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_pip2_get_version
- *
- * SUMMARY: Protected call to pt_pip2_get_version_ by exclusive
- * access to the DUT.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data structure
- ******************************************************************************/
- static int pt_pip2_get_version(struct pt_core_data *cd)
- {
- int rc;
- rc = request_exclusive(cd, cd->dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail get exclusive ex=%p own=%p\n",
- __func__, cd->exclusive_dev, cd->dev);
- return rc;
- }
- rc = pt_pip2_get_version_(cd);
- if (release_exclusive(cd, cd->dev) < 0)
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail to release exclusive\n", __func__);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: _pt_request_active_pip_protocol
- *
- * SUMMARY: Get active PIP protocol version using the PIP2 version command.
- * Function will return PIP version of BL or application based on
- * when it's called.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * protect - flag to run in protected mode
- * *pip_version_major - pointer to store PIP major version
- * *pip_version_minor - pointer to store PIP minor version
- ******************************************************************************/
- int _pt_request_active_pip_protocol(struct device *dev, int protect,
- u8 *pip_version_major, u8 *pip_version_minor)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- struct pt_ttdata *ttdata = &cd->sysinfo.ttdata;
- int rc = 0;
- struct pt_hid_output sys_info = {
- CREATE_PIP1_FW_CMD(PIP1_CMD_ID_GET_SYSINFO),
- .timeout_ms = PT_PIP1_CMD_GET_SYSINFO_TIMEOUT,
- };
- pt_flush_bus_if_irq_asserted(cd, PT_FLUSH_BUS_BASED_ON_LEN);
- /* Skip PIP2 command if DUT generation is confirmed */
- if (cd->active_dut_generation == DUT_PIP1_ONLY)
- goto skip_pip2_command;
- rc = pt_pip2_get_version_(cd);
- if (!rc) {
- *pip_version_major = ttdata->pip_ver_major;
- *pip_version_minor = ttdata->pip_ver_minor;
- pt_debug(dev, DL_INFO,
- "%s: pip_version = %d.%d\n", __func__,
- *pip_version_major, *pip_version_minor);
- } else {
- /*
- * Legacy products do not support the pip2 protocol to get
- * pip version. However, they do support the "get sysinfo"
- * command to get pip version from FW, but the bootloader
- * does not support it. This function will try "get sysinfo"
- * command if the pip2 command failed but this cmd could also
- * fail if DUT is stuck in bootloader mode.
- */
- pt_debug(dev, DL_INFO,
- "%s: PIP2 no response rc = %d, try legacy cmd\n",
- __func__, rc);
- skip_pip2_command:
- rc = pt_pip1_send_output_and_wait_(cd, &sys_info);
- if (!rc) {
- *pip_version_minor =
- cd->response_buf[PIP1_SYSINFO_TTDATA_OFFSET + 1];
- *pip_version_major =
- cd->response_buf[PIP1_SYSINFO_TTDATA_OFFSET];
- pt_debug(dev, DL_INFO,
- "%s: pip_version = %d.%d\n", __func__,
- *pip_version_major, *pip_version_minor);
- } else {
- *pip_version_major = 0;
- *pip_version_minor = 0;
- pt_debug(dev, DL_ERROR,
- "%s: pip_version Not Detected\n", __func__);
- }
- }
- return rc;
- }
- EXPORT_SYMBOL_GPL(_pt_request_active_pip_protocol);
- /*******************************************************************************
- * FUNCTION: _pt_detect_dut_generation
- *
- * SUMMARY: Determine the generation of device that we are communicating with:
- * DUT_PIP1_ONLY (Gen5 or Gen6)
- * DUT_PIP2_CAPABLE (TC33xx or TT7xxx)
- * The HID_DESC command is supported in Gen5/6 BL and FW as well as
- * TT/TC FW. The packet ID in the descriptor, however, is unique when
- * coming form the BL or the FW:
- * Packet_ID in BL = HID_BL_REPORT_ID (0xFF)
- * Packet_ID in FW = HID_APP_REPORT_ID (0xF7)
- * This function will return a modified status if it detects the DUT
- * is in the BL. In the case of a Gen5/6 BL, which also sends out a FW
- * reset sentinel, the status is "corrected" from a FW to BL sentinel.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *status - pointer to status bitmask
- * *dut_gen - pointer to store the dut_generation
- * *mode - pointer to store the PT_MODE
- ******************************************************************************/
- static int _pt_detect_dut_generation(struct device *dev,
- u32 *status, u8 *dut_gen, enum pt_mode *mode)
- {
- int rc = 0;
- u8 dut_gen_tmp = DUT_UNKNOWN;
- u8 mode_tmp = PT_MODE_UNKNOWN;
- u8 attempt = 1;
- u32 status_tmp = STARTUP_STATUS_START;
- struct pt_core_data *cd = dev_get_drvdata(dev);
- struct pt_hid_desc hid_desc;
- memset(&hid_desc, 0, sizeof(hid_desc));
- rc = pt_get_hid_descriptor_(cd, &hid_desc);
- while (rc && attempt < 3) {
- attempt++;
- usleep_range(2000, 5000);
- rc = pt_get_hid_descriptor_(cd, &hid_desc);
- }
- if (!rc && hid_desc.packet_id == HID_BL_REPORT_ID) {
- dut_gen_tmp = DUT_PIP1_ONLY; /* Gen5/6 BL */
- mode_tmp = PT_MODE_BOOTLOADER;
- status_tmp = STARTUP_STATUS_BL_RESET_SENTINEL;
- } else if (!rc && hid_desc.packet_id == HID_APP_REPORT_ID) {
- rc = pt_pip2_get_version_(cd);
- if (!rc)
- dut_gen_tmp = DUT_PIP2_CAPABLE; /* TT/TC FW */
- else
- dut_gen_tmp = DUT_PIP1_ONLY; /* Gen5/6 FW */
- mode_tmp = PT_MODE_OPERATIONAL;
- status_tmp = STARTUP_STATUS_FW_RESET_SENTINEL;
- rc = 0; /* To return success instead of error code */
- } else if (rc) {
- rc = pt_pip2_get_version_(cd);
- if (!rc) {
- dut_gen_tmp = DUT_PIP2_CAPABLE; /* TT/TC BL */
- mode_tmp = PT_MODE_BOOTLOADER;
- status_tmp = STARTUP_STATUS_BL_RESET_SENTINEL;
- }
- }
- mutex_lock(&cd->system_lock);
- if (dut_gen)
- *dut_gen = dut_gen_tmp;
- if (mode)
- *mode = mode_tmp;
- if (status)
- *status = status_tmp;
- mutex_unlock(&cd->system_lock);
- #ifdef TTDL_DIAGNOSTICS
- pt_debug(cd->dev, DL_INFO, "%s: Generation=%d Mode=%d\n",
- __func__, dut_gen_tmp, mode_tmp);
- #endif /* TTDL_DIAGNOSTICS */
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: _pt_request_dut_generation
- *
- * SUMMARY: Function pointer included in core_cmds to allow other modules
- * to get current dut generation.
- *
- * NOTE: This function WILL NOT try to determine dut generation.
- *
- * RETURN:
- * The current dut generation.
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- ******************************************************************************/
- static int _pt_request_dut_generation(struct device *dev)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- return cd->active_dut_generation;
- }
- #define HW_VERSION_LEN_MAX 13
- /*******************************************************************************
- * FUNCTION: _legacy_generate_hw_version
- *
- * SUMMARY: Format chip information from struct ttdata (maintained by PIP1
- * SYSINFO command) or struct bl_info (maintained by PIP1 BL INFORMATION
- * command) to the hw_version.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * *hw_version - pointer to store the hardware version
- ******************************************************************************/
- static int _legacy_generate_hw_version(struct pt_core_data *cd,
- char *hw_version)
- {
- struct pt_ttdata *ttdata = &cd->sysinfo.ttdata;
- if (cd->sysinfo.ready) {
- scnprintf(hw_version, HW_VERSION_LEN_MAX, "%04X.FFFF.%02X",
- ttdata->jtag_id_h, cd->pid_for_loader);
- return 0;
- } else if (cd->bl_info.ready) {
- scnprintf(hw_version, HW_VERSION_LEN_MAX, "%04X.FFFF.%02X",
- cd->bl_info.chip_id, cd->pid_for_loader);
- return 0;
- } else {
- snprintf(hw_version, HW_VERSION_LEN_MAX, "FFFF.FFFF.FF");
- pt_debug(cd->dev, DL_ERROR,
- "%s: SYSINFO and BL_INFO are not ready\n", __func__);
- return -ENODATA;
- }
- }
- /*******************************************************************************
- * FUNCTION: _pip2_generate_hw_version
- *
- * SUMMARY: Format chip information from struct ttdata (maintained by PIP2
- * VERSION command) to the hw_version.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * *hw_version - pointer to store the hardware version
- ******************************************************************************/
- static int _pip2_generate_hw_version(struct pt_core_data *cd, char *hw_version)
- {
- struct pt_ttdata *ttdata = &cd->sysinfo.ttdata;
- if (cd->app_pip_ver_ready | cd->bl_pip_ver_ready) {
- snprintf(hw_version, HW_VERSION_LEN_MAX, "%04X.%04X.%02X",
- ttdata->chip_id, ttdata->chip_rev, cd->pid_for_loader);
- return 0;
- } else {
- snprintf(hw_version, HW_VERSION_LEN_MAX, "FFFF.FFFF.FF");
- pt_debug(cd->dev, DL_ERROR,
- "%s: PIP Version are not ready\n", __func__);
- return -ENODATA;
- }
- }
- /*******************************************************************************
- * FUNCTION: pt_generate_hw_version
- *
- * SUMMARY: Wraaper function for both legacy and TT/TC products generate the
- * hw_version from static data.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * *hw_version - pointer to store the hardware version
- ******************************************************************************/
- static int pt_generate_hw_version(struct pt_core_data *cd, char *hw_version)
- {
- int rc = 0;
- if (!hw_version)
- return -ENOMEM;
- if (cd->active_dut_generation == DUT_PIP1_ONLY)
- rc = _legacy_generate_hw_version(cd, hw_version);
- else if (cd->active_dut_generation == DUT_PIP2_CAPABLE)
- rc = _pip2_generate_hw_version(cd, hw_version);
- else {
- snprintf(hw_version, HW_VERSION_LEN_MAX, "FFFF.FFFF.FF");
- rc = -ENODATA;
- }
- return rc;
- }
- /*******************************************************************************
- * SUMMARY: Attempt to retrieve the HW version of the connected DUT
- *
- * NOTE: The calling function must ensure to free *hw_version
- *
- * RETURN:
- * 0 = success
- * !0 = Failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *hw_version - pointer to where the hw_version string will be stored
- ******************************************************************************/
- static int _pt_request_hw_version(struct device *dev, char *hw_version)
- {
- int rc = 0;
- u16 actual_read_len;
- u16 pip_ver;
- u8 rd_buf[256];
- u8 status;
- u8 index = PIP2_RESP_STATUS_OFFSET;
- u8 return_data[8];
- u8 panel_id;
- struct pt_core_data *cd = dev_get_drvdata(dev);
- struct pt_ttdata *ttdata = &cd->sysinfo.ttdata;
- if (!hw_version)
- return -ENOMEM;
- if (!cd->hw_detected) {
- /* No HW detected */
- rc = -ENODEV;
- pt_debug(dev, DL_ERROR, "%s: no hardware is detected!\n",
- __func__);
- goto exit_error;
- }
- memset(return_data, 0, ARRAY_SIZE(return_data));
- /* For Parade TC or TT parts */
- if (cd->active_dut_generation == DUT_PIP2_CAPABLE) {
- rc = _pt_request_pip2_send_cmd(dev,
- PT_CORE_CMD_UNPROTECTED, PIP2_CMD_ID_VERSION,
- NULL, 0, rd_buf, &actual_read_len);
- if (rc) {
- pt_debug(dev, DL_ERROR,
- "%s: Failed to send PIP2 VERSION cmd\n",
- __func__);
- goto exit_error;
- }
- status = rd_buf[index];
- if (status == 0) {
- pip_ver = 256 * rd_buf[index + 2] + rd_buf[index + 1];
- /*
- * BL PIP 2.02 and greater the version fields are
- * swapped
- */
- if (pip_ver >= 0x0202) {
- snprintf(hw_version, HW_VERSION_LEN_MAX,
- "%02X%02X.%02X%02X.FF",
- rd_buf[index + 10], rd_buf[index + 9],
- rd_buf[index + 8], rd_buf[index + 7]);
- } else {
- snprintf(hw_version, HW_VERSION_LEN_MAX,
- "%02X%02X.%02X%02X.FF",
- rd_buf[index + 8], rd_buf[index + 7],
- rd_buf[index + 10], rd_buf[index + 9]);
- }
- return STATUS_SUCCESS;
- } else {
- rc = status;
- pt_debug(dev, DL_WARN,
- "%s: PIP2 VERSION cmd response error\n",
- __func__);
- }
- } else if (cd->active_dut_generation == DUT_PIP1_ONLY) {
- /*
- * For Parade/Cypress legacy parts the RevID and FamilyID are
- * hard coded to FFFF
- */
- if (cd->mode == PT_MODE_OPERATIONAL) {
- rc = pt_hid_output_get_sysinfo(cd);
- if (!rc) {
- panel_id =
- cd->sysinfo.sensing_conf_data.panel_id;
- } else {
- panel_id = PANEL_ID_NOT_ENABLED;
- }
- /* In FW - simply retrieve from ttdata struct */
- snprintf(hw_version, HW_VERSION_LEN_MAX,
- "%04X.FFFF.%02X",
- ttdata->jtag_id_h,
- panel_id);
- return STATUS_SUCCESS;
- } else {
- /*
- * Return the stored value if PT_PANEL_ID_BY_BL
- * is not supported while other feature is.
- */
- if (cd->panel_id_support & PT_PANEL_ID_BY_BL) {
- rc = pt_hid_output_bl_get_information(
- cd, return_data);
- if (!rc) {
- rc = pt_hid_output_bl_get_panel_id(
- cd, &panel_id);
- }
- } else
- panel_id = cd->pid_for_loader;
- if (!rc) {
- snprintf(hw_version,
- HW_VERSION_LEN_MAX,
- "%02X%02X.FFFF.%02X",
- return_data[3], return_data[2],
- panel_id);
- return STATUS_SUCCESS;
- }
- }
- } else {
- /* Unknown generation */
- rc = -ENODEV;
- pt_debug(dev, DL_ERROR, "%s: generation is unknown!\n",
- __func__);
- }
- exit_error:
- snprintf(hw_version, HW_VERSION_LEN_MAX, "FFFF.FFFF.FF");
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_start_wd_timer
- *
- * SUMMARY: Starts the TTDL watchdog timer if the timer interval is > 0
- *
- * RETURN: void
- *
- * PARAMETERS:
- * *cd - pointer to core data
- ******************************************************************************/
- static void pt_start_wd_timer(struct pt_core_data *cd)
- {
- if (cd->watchdog_interval < 100) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: WARNING: Invalid watchdog interval: %d\n",
- __func__, cd->watchdog_interval);
- return;
- }
- if (cd->watchdog_force_stop) {
- pt_debug(cd->dev, DL_INFO,
- "%s: TTDL WD Forced stop\n", __func__);
- return;
- }
- mod_timer(&cd->watchdog_timer, jiffies +
- msecs_to_jiffies(cd->watchdog_interval));
- cd->watchdog_enabled = 1;
- pt_debug(cd->dev, DL_INFO, "%s: TTDL WD Started\n", __func__);
- }
- /*******************************************************************************
- * FUNCTION: pt_stop_wd_timer
- *
- * SUMMARY: Stops the TTDL watchdog timer if the timer interval is > 0
- *
- * RETURN: void
- *
- * PARAMETERS:
- * *cd - pointer to core data
- ******************************************************************************/
- static void pt_stop_wd_timer(struct pt_core_data *cd)
- {
- if (!cd->watchdog_interval)
- return;
- /*
- * Ensure we wait until the watchdog timer
- * running on a different CPU finishes
- */
- del_timer_sync(&cd->watchdog_timer);
- cancel_work_sync(&cd->watchdog_work);
- del_timer_sync(&cd->watchdog_timer);
- cd->watchdog_enabled = 0;
- pt_debug(cd->dev, DL_INFO, "%s: TTDL WD Stopped\n", __func__);
- }
- /*******************************************************************************
- * FUNCTION: pt_hw_soft_reset
- *
- * SUMMARY: Sends a PIP reset command to the DUT. Disable/re-enable the
- * TTDL watchdog around the reset to ensure the WD doesn't happen to
- * schedule an enum if it fires when the DUT is being reset.
- * This can cause a double reset.
- *
- * NOTE: The WD MUST be stopped/restarted by the calling Function. Having
- * the WD active could cause this function to fail!
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data struct
- * protect - flag to call protected or non-protected
- ******************************************************************************/
- static int pt_hw_soft_reset(struct pt_core_data *cd, int protect)
- {
- int rc = 0;
- mutex_lock(&cd->system_lock);
- cd->startup_status = STARTUP_STATUS_START;
- pt_debug(cd->dev, DL_DEBUG, "%s: Startup Status Reset\n", __func__);
- mutex_unlock(&cd->system_lock);
- if (protect)
- rc = pt_hid_cmd_reset(cd);
- else
- rc = pt_hid_cmd_reset_(cd);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: FAILED to execute SOFT reset\n", __func__);
- return rc;
- }
- pt_debug(cd->dev, DL_INFO, "%s: SOFT reset successful\n",
- __func__);
- return 0;
- }
- /*******************************************************************************
- * FUNCTION: pt_hw_hard_reset
- *
- * SUMMARY: Calls the platform xres function if it exists to perform a hard
- * reset on the DUT by toggling the XRES gpio. Disable/re-enable the
- * TTDL watchdog around the reset to ensure the WD doesn't happen to
- * schedule an enum if it fires when the DUT is being reset.
- * This can cause a double reset.
- *
- * NOTE: The WD MUST be stopped/restarted by the calling Function. Having
- * the WD active could cause this function to fail!
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data struct
- ******************************************************************************/
- static int pt_hw_hard_reset(struct pt_core_data *cd)
- {
- if (cd->cpdata->xres) {
- cd->startup_status = STARTUP_STATUS_START;
- pt_debug(cd->dev, DL_DEBUG, "%s: Startup Status Reset\n",
- __func__);
- cd->cpdata->xres(cd->cpdata, cd->dev);
- pt_debug(cd->dev, DL_WARN, "%s: executed HARD reset\n",
- __func__);
- return 0;
- }
- pt_debug(cd->dev, DL_ERROR,
- "%s: FAILED to execute HARD reset\n", __func__);
- return -ENODEV;
- }
- /*******************************************************************************
- * FUNCTION: pt_dut_reset
- *
- * SUMMARY: Attempts to reset the DUT by a hard reset and if that fails a
- * soft reset.
- *
- * NOTE: The WD MUST be stopped/restarted by the calling Function. Having
- * the WD active could cause this function to fail!
- * NOTE: "protect" flag is only used for soft reset.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data structure
- * protect - flag to call protected or non-protected
- ******************************************************************************/
- static int pt_dut_reset(struct pt_core_data *cd, int protect)
- {
- int rc = 0;
- pt_debug(cd->dev, DL_INFO, "%s: reset hw...\n", __func__);
- mutex_lock(&cd->system_lock);
- cd->hid_reset_cmd_state = 1;
- rc = pt_hw_hard_reset(cd);
- mutex_unlock(&cd->system_lock);
- if (rc == -ENODEV) {
- mutex_lock(&cd->system_lock);
- cd->hid_reset_cmd_state = 0;
- mutex_unlock(&cd->system_lock);
- pt_debug(cd->dev, DL_ERROR,
- "%s: Hard reset failed, try soft reset\n", __func__);
- rc = pt_hw_soft_reset(cd, protect);
- }
- if (rc)
- pt_debug(cd->dev, DL_ERROR, "%s: %s dev='%s' r=%d\n",
- __func__, "Fail hw reset", dev_name(cd->dev), rc);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_dut_reset_and_wait
- *
- * SUMMARY: Wrapper function for pt_dut_reset that waits for the reset to
- * complete
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data structure
- ******************************************************************************/
- static int pt_dut_reset_and_wait(struct pt_core_data *cd)
- {
- int rc = 0;
- int t;
- rc = pt_dut_reset(cd, PT_CORE_CMD_UNPROTECTED);
- if (rc < 0)
- goto exit;
- t = wait_event_timeout(cd->wait_q,
- (cd->hid_reset_cmd_state == 0),
- msecs_to_jiffies(PT_HID_CMD_DEFAULT_TIMEOUT));
- if (IS_TMO(t)) {
- #ifdef TTDL_DIAGNOSTICS
- cd->bus_transmit_error_count++;
- pt_toggle_err_gpio(cd, PT_ERR_GPIO_I2C_TRANS);
- #endif /* TTDL_DIAGNOSTICS */
- pt_debug(cd->dev, DL_ERROR, "%s: reset timed out\n",
- __func__);
- rc = -ETIME;
- goto exit;
- }
- exit:
- return rc;
- }
- /*
- * touch default parameters (from report descriptor) to resolve protocol for
- * touch report
- */
- const struct pt_tch_abs_params tch_hdr_default[PT_TCH_NUM_HDR] = {
- /* byte offset, size, min, max, bit offset, report */
- {0x00, 0x02, 0x00, 0x10000, 0x00, 0x01}, /* SCAN TIME */
- {0x02, 0x01, 0x00, 0x20, 0x00, 0x01}, /* NUMBER OF RECORDS */
- {0x02, 0x01, 0x00, 0x02, 0x05, 0x01}, /* LARGE OBJECT */
- {0x03, 0x01, 0x00, 0x08, 0x00, 0x01}, /* NOISE EFFECT */
- {0x03, 0x01, 0x00, 0x04, 0x06, 0x01}, /* REPORT_COUNTER */
- };
- /*
- * button default parameters (from report descriptor) to resolve protocol for
- * button report
- */
- const struct pt_tch_abs_params tch_abs_default[PT_TCH_NUM_ABS] = {
- /* byte offset, size, min, max, bit offset, report */
- {0x02, 0x02, 0x00, 0x10000, 0x00, 0x01}, /* X */
- {0x04, 0x02, 0x00, 0x10000, 0x00, 0x01}, /* Y */
- {0x06, 0x01, 0x00, 0x100, 0x00, 0x01}, /* P (Z) */
- {0x01, 0x01, 0x00, 0x20, 0x00, 0x01}, /* TOUCH ID */
- {0x01, 0x01, 0x00, 0x04, 0x05, 0x01}, /* EVENT ID */
- {0x00, 0x01, 0x00, 0x08, 0x00, 0x01}, /* OBJECT ID */
- {0x01, 0x01, 0x00, 0x02, 0x07, 0x01}, /* LIFTOFF */
- {0x07, 0x01, 0x00, 0x100, 0x00, 0x01}, /* TOUCH_MAJOR */
- {0x08, 0x01, 0x00, 0x100, 0x00, 0x01}, /* TOUCH_MINOR */
- {0x09, 0x01, 0x00, 0x100, 0x00, 0x01}, /* ORIENTATION */
- };
- /*******************************************************************************
- * FUNCTION: pt_init_pip_report_fields
- *
- * SUMMARY: Setup default values for touch/button report parsing.
- *
- * PARAMETERS:
- * *cd - pointer to core data structure
- ******************************************************************************/
- static void pt_init_pip_report_fields(struct pt_core_data *cd)
- {
- struct pt_sysinfo *si = &cd->sysinfo;
- memcpy(si->tch_hdr, tch_hdr_default, sizeof(tch_hdr_default));
- memcpy(si->tch_abs, tch_abs_default, sizeof(tch_abs_default));
- si->desc.tch_report_id = PT_PIP_TOUCH_REPORT_ID;
- si->desc.tch_record_size = TOUCH_REPORT_SIZE;
- si->desc.tch_header_size = TOUCH_INPUT_HEADER_SIZE;
- si->desc.btn_report_id = PT_PIP_CAPSENSE_BTN_REPORT_ID;
- cd->features.easywake = 1;
- cd->features.noise_metric = 1;
- cd->features.tracking_heatmap = 1;
- cd->features.sensor_data = 1;
- }
- /*******************************************************************************
- * FUNCTION: pt_get_mode
- *
- * SUMMARY: Determine the current mode from the contents of a HID descriptor
- * message
- *
- * RETURN: Enum of the current mode
- *
- * PARAMETERS:
- * *cd - pointer to the Core Data structure
- * protect - run command in protected mode
- * *mode - pointer to store the retrieved mode
- ******************************************************************************/
- static int pt_get_mode(struct pt_core_data *cd, struct pt_hid_desc *desc)
- {
- if (desc->packet_id == HID_APP_REPORT_ID)
- return PT_MODE_OPERATIONAL;
- else if (desc->packet_id == HID_BL_REPORT_ID)
- return PT_MODE_BOOTLOADER;
- return PT_MODE_UNKNOWN;
- }
- /*******************************************************************************
- * FUNCTION: _pt_request_get_mode
- *
- * SUMMARY: Function pointer included in core_cmds to allow other modules
- * to determine the current mode of the DUT by use of the Get HID
- * Descriptor command.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * protect - run command in protected mode
- * *mode - pointer to store the retrieved mode
- ******************************************************************************/
- static int _pt_request_get_mode(struct device *dev, int protect, u8 *mode)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- struct pt_hid_desc hid_desc;
- int rc = 0;
- memset(&hid_desc, 0, sizeof(hid_desc));
- if (protect)
- rc = pt_get_hid_descriptor(cd, &hid_desc);
- else
- rc = pt_get_hid_descriptor_(cd, &hid_desc);
- if (rc)
- *mode = PT_MODE_UNKNOWN;
- else
- *mode = pt_get_mode(cd, &hid_desc);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_queue_enum_
- *
- * SUMMARY: Queues a TTDL enum by scheduling work with the pt_enum_with_dut()
- * function. It won't try to add/delete sysfs node or modules.
- *
- * RETURN: void
- *
- * PARAMETERS:
- * *cd - pointer to core data
- ******************************************************************************/
- static void pt_queue_enum_(struct pt_core_data *cd)
- {
- if (cd->startup_state == STARTUP_NONE) {
- cd->startup_state = STARTUP_QUEUED;
- #ifdef TTDL_DIAGNOSTICS
- if (!cd->bridge_mode)
- schedule_work(&cd->enum_work);
- else
- cd->startup_state = STARTUP_NONE;
- #else
- schedule_work(&cd->enum_work);
- #endif
- pt_debug(cd->dev, DL_INFO,
- "%s: enum_work queued\n", __func__);
- } else {
- pt_debug(cd->dev, DL_WARN,
- "%s: Enum not queued - startup_state = %d\n",
- __func__, cd->startup_state);
- }
- }
- /*******************************************************************************
- * FUNCTION: pt_queue_enum
- *
- * SUMMARY: Queues a TTDL enum within a mutex lock
- *
- * RETURN: void
- *
- * PARAMETERS:
- * *cd - pointer to core data
- ******************************************************************************/
- static void pt_queue_enum(struct pt_core_data *cd)
- {
- mutex_lock(&cd->system_lock);
- pt_queue_enum_(cd);
- mutex_unlock(&cd->system_lock);
- }
- static void remove_sysfs_and_modules(struct device *dev);
- /*******************************************************************************
- * FUNCTION: pt_queue_restart
- *
- * SUMMARY: Queues a TTDL restart within a mutex lock
- *
- * RETURN: void
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * remove_sysfs_module - True: remove all DUT relative sysfs nodes and modules
- * False: will not perform remove action
- ******************************************************************************/
- static void pt_queue_restart(struct pt_core_data *cd)
- {
- mutex_lock(&cd->system_lock);
- if (cd->startup_state == STARTUP_NONE) {
- cd->startup_state = STARTUP_QUEUED;
- schedule_work(&cd->ttdl_restart_work);
- pt_debug(cd->dev, DL_INFO,
- "%s: pt_ttdl_restart queued\n", __func__);
- } else {
- pt_debug(cd->dev, DL_INFO, "%s: startup_state = %d\n",
- __func__, cd->startup_state);
- }
- mutex_unlock(&cd->system_lock);
- }
- /*******************************************************************************
- * FUNCTION: call_atten_cb
- *
- * SUMMARY: Iterate over attention list call the function that registered.
- *
- * RETURN: void
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * type - type of attention list
- * mode - condition for execution
- ******************************************************************************/
- static void call_atten_cb(struct pt_core_data *cd,
- enum pt_atten_type type, int mode)
- {
- struct atten_node *atten, *atten_n;
- pt_debug(cd->dev, DL_DEBUG, "%s: check list type=%d mode=%d\n",
- __func__, type, mode);
- spin_lock(&cd->spinlock);
- list_for_each_entry_safe(atten, atten_n,
- &cd->atten_list[type], node) {
- if (!mode || atten->mode & mode) {
- spin_unlock(&cd->spinlock);
- pt_debug(cd->dev, DL_DEBUG,
- "%s: attention for '%s'",
- __func__, dev_name(atten->dev));
- atten->func(atten->dev);
- spin_lock(&cd->spinlock);
- }
- }
- spin_unlock(&cd->spinlock);
- }
- /*******************************************************************************
- * FUNCTION: start_fw_upgrade
- *
- * SUMMARY: Calling "PT_ATTEN_LOADER" attention list that loader registered to
- * start firmware upgrade.
- *
- * RETURN:
- * 0 = success
- *
- * PARAMETERS:
- * *data - pointer to core data
- ******************************************************************************/
- static int start_fw_upgrade(void *data)
- {
- struct pt_core_data *cd = (struct pt_core_data *)data;
- call_atten_cb(cd, PT_ATTEN_LOADER, 0);
- return 0;
- }
- /*******************************************************************************
- * FUNCTION: pt_put_device_into_easy_wakeup_
- *
- * SUMMARY: Call the enter_easywake_state function and set the device into easy
- * wake up state.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- ******************************************************************************/
- static int pt_put_device_into_easy_wakeup_(struct pt_core_data *cd)
- {
- int rc = 0;
- u8 status = 0;
- rc = pt_hid_output_enter_easywake_state_(cd,
- cd->easy_wakeup_gesture, &status);
- if (rc || status == 0)
- return -EBUSY;
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_put_device_into_deep_sleep_
- *
- * SUMMARY: Call the set_power function and set the DUT to deep sleep
- *
- * RETURN:
- * 0 = success
- * !0 = error
- *
- * PARAMETERS:
- * *cd - pointer to core data
- ******************************************************************************/
- static int pt_put_device_into_deep_sleep_(struct pt_core_data *cd)
- {
- int rc = 0;
- rc = pt_hid_cmd_set_power_(cd, HID_POWER_SLEEP);
- if (rc)
- rc = -EBUSY;
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_put_device_into_deep_standby_
- *
- * SUMMARY: Call the set_power function and set the DUT to Deep Standby
- *
- * RETURN:
- * 0 = success
- * !0 = error
- *
- * PARAMETERS:
- * *cd - pointer to core data
- ******************************************************************************/
- static int pt_put_device_into_deep_standby_(struct pt_core_data *cd)
- {
- int rc = 0;
- rc = pt_hid_cmd_set_power_(cd, HID_POWER_STANDBY);
- if (rc)
- rc = -EBUSY;
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_core_poweroff_device_
- *
- * SUMMARY: Disable IRQ and HW power down the device.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- ******************************************************************************/
- static int pt_core_poweroff_device_(struct pt_core_data *cd)
- {
- int rc;
- if (cd->irq_enabled) {
- cd->irq_enabled = false;
- disable_irq_nosync(cd->irq);
- }
- rc = cd->cpdata->power(cd->cpdata, 0, cd->dev, 0);
- if (rc < 0)
- pt_debug(cd->dev, DL_ERROR, "%s: HW Power down fails r=%d\n",
- __func__, rc);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_core_sleep_
- *
- * SUMMARY: Suspend the device with power off or deep sleep based on the
- * configuration in the core platform data structure.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- ******************************************************************************/
- static int pt_core_sleep_(struct pt_core_data *cd)
- {
- int rc = 0;
- mutex_lock(&cd->system_lock);
- pt_debug(cd->dev, DL_INFO, "%s - sleep_state %d\n", __func__, cd->sleep_state);
- if (cd->sleep_state == SS_SLEEP_ON || cd->sleep_state == SS_SLEEPING) {
- mutex_unlock(&cd->system_lock);
- pt_debug(cd->dev, DL_INFO,
- "%s - Skip slee[ state %d\n", __func__, cd->sleep_state);
- return 0;
- } else {
- cd->sleep_state = SS_SLEEPING;
- }
- mutex_unlock(&cd->system_lock);
- /* Ensure watchdog and startup works stopped */
- pt_stop_wd_timer(cd);
- cancel_work_sync(&cd->enum_work);
- pt_stop_wd_timer(cd);
- if (cd->cpdata->flags & PT_CORE_FLAG_POWEROFF_ON_SLEEP) {
- pt_debug(cd->dev, DL_INFO, "%s: Entering into power off mode:\n", __func__);
- rc = pt_core_poweroff_device_(cd);
- if (rc)
- pr_err("%s: Power off error detected :rc=%d\n", __func__, rc);
- } else if (cd->cpdata->flags & PT_CORE_FLAG_DEEP_STANDBY) {
- pt_debug(cd->dev, DL_INFO,
- "%s: Entering into deep standby mode:\n", __func__);
- rc = pt_put_device_into_deep_standby_(cd);
- if (rc)
- pr_err("%s: Deep standby error detected :rc=%d\n", __func__, rc);
- } else {
- pt_debug(cd->dev, DL_INFO,
- "%s: Entering into deep sleep mode:\n", __func__);
- rc = pt_put_device_into_deep_sleep_(cd);
- if (rc)
- pr_err("%s: Deep sleep error detected :rc=%d\n", __func__, rc);
- }
- mutex_lock(&cd->system_lock);
- cd->sleep_state = SS_SLEEP_ON;
- mutex_unlock(&cd->system_lock);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_core_easywake_on_
- *
- * SUMMARY: Suspend the device with easy wake on the
- * configuration in the core platform data structure.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- ******************************************************************************/
- static int pt_core_easywake_on_(struct pt_core_data *cd)
- {
- int rc = 0;
- mutex_lock(&cd->system_lock);
- if (cd->sleep_state == SS_EASY_WAKING_ON) {
- mutex_unlock(&cd->system_lock);
- pt_debug(cd->dev, DL_INFO, "%s - Skip sleep state %d\n",
- __func__, cd->sleep_state);
- return 0;
- }
- mutex_unlock(&cd->system_lock);
- /* Ensure watchdog and startup works stopped */
- pt_stop_wd_timer(cd);
- cancel_work_sync(&cd->enum_work);
- pt_stop_wd_timer(cd);
- if (IS_EASY_WAKE_CONFIGURED(cd->easy_wakeup_gesture)) {
- rc = pt_put_device_into_easy_wakeup_(cd);
- pt_debug(cd->dev, DL_INFO, "%s :Entering into easywakeup: rc=%d\n", __func__, rc);
- if (rc)
- pr_err("%s: Easy wakeup error detected :rc=%d\n", __func__, rc);
- }
- mutex_lock(&cd->system_lock);
- cd->sleep_state = SS_EASY_WAKING_ON;
- mutex_unlock(&cd->system_lock);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_core_easywake_on
- *
- * SUMMARY: Protected call to pt_core_easywake_on_ by exclusive access to the DUT.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- ******************************************************************************/
- static int pt_core_easywake_on(struct pt_core_data *cd)
- {
- int rc = 0;
- rc = request_exclusive(cd, cd->dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail get exclusive ex=%p own=%p\n",
- __func__, cd->exclusive_dev, cd->dev);
- return rc;
- }
- rc = pt_core_easywake_on_(cd);
- if (release_exclusive(cd, cd->dev) < 0)
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail to release exclusive\n", __func__);
- else
- pt_debug(cd->dev, DL_DEBUG, "%s: pass release exclusive\n",
- __func__);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_core_sleep
- *
- * SUMMARY: Protected call to pt_core_sleep_ by exclusive access to the DUT.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- ******************************************************************************/
- static int pt_core_sleep(struct pt_core_data *cd)
- {
- int rc = 0;
- rc = request_exclusive(cd, cd->dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail get exclusive ex=%p own=%p\n",
- __func__, cd->exclusive_dev, cd->dev);
- return rc;
- }
- rc = pt_core_sleep_(cd);
- if (release_exclusive(cd, cd->dev) < 0)
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail to release exclusive\n", __func__);
- else
- pt_debug(cd->dev, DL_DEBUG, "%s: pass release exclusive\n",
- __func__);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_wakeup_host
- *
- * SUMMARY: Check wake up report and call the PT_ATTEN_WAKE attention list.
- *
- * NOTE: TSG5 EasyWake and TSG6 EasyWake use different protocol.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- ******************************************************************************/
- static int pt_wakeup_host(struct pt_core_data *cd)
- {
- #ifndef EASYWAKE_TSG6
- /* TSG5 EasyWake */
- int rc = 0;
- int event_id;
- int size = get_unaligned_le16(&cd->input_buf[0]);
- /* Validate report */
- if (size != 4 || cd->input_buf[2] != 4)
- rc = -EINVAL;
- event_id = cd->input_buf[3];
- pt_debug(cd->dev, DL_INFO, "%s: e=%d, rc=%d\n",
- __func__, event_id, rc);
- if (rc) {
- pt_core_sleep_(cd);
- goto exit;
- }
- /* attention WAKE */
- call_atten_cb(cd, PT_ATTEN_WAKE, 0);
- exit:
- return rc;
- #else
- /* TSG6 FW1.3 EasyWake */
- int rc = 0;
- int i = 0;
- int report_length;
- /* Validate report */
- if (cd->input_buf[2] != PT_PIP_WAKEUP_REPORT_ID) {
- rc = -EINVAL;
- pt_core_sleep_(cd);
- goto exit;
- }
- /* Get gesture id and gesture data length */
- cd->gesture_id = cd->input_buf[3];
- report_length = (cd->input_buf[1] << 8) | (cd->input_buf[0]);
- cd->gesture_data_length = report_length - 4;
- pt_debug(cd->dev, DL_INFO,
- "%s: gesture_id = %d, gesture_data_length = %d\n",
- __func__, cd->gesture_id, cd->gesture_data_length);
- for (i = 0; i < cd->gesture_data_length; i++)
- cd->gesture_data[i] = cd->input_buf[4 + i];
- /* attention WAKE */
- call_atten_cb(cd, PT_ATTEN_WAKE, 0);
- exit:
- return rc;
- #endif
- }
- /*******************************************************************************
- * FUNCTION: pt_get_touch_axis
- *
- * SUMMARY: Function to calculate touch axis
- *
- * PARAMETERS:
- * *cd - pointer to core data structure
- * *axis - pointer to axis calculation result
- * size - size in bytes
- * max - max value of result
- * *xy_data - pointer to input data to be parsed
- * bofs - bit offset
- ******************************************************************************/
- static void pt_get_touch_axis(struct pt_core_data *cd,
- int *axis, int size, int max, u8 *data, int bofs)
- {
- int nbyte;
- int next;
- for (nbyte = 0, *axis = 0, next = 0; nbyte < size; nbyte++) {
- *axis = *axis + ((data[next] >> bofs) << (nbyte * 8));
- next++;
- }
- *axis &= max - 1;
- }
- /*******************************************************************************
- * FUNCTION: move_tracking_heatmap_data
- *
- * SUMMARY: Move the valid tracking heatmap data from the input buffer into the
- * system information structure, xy_mode and xy_data.
- * - If TTHE_TUNER_SUPPORT is defined print the raw sensor data into
- * the tthe_tuner sysfs node under the label "THM"
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * *si - pointer to the system information structure
- ******************************************************************************/
- static int move_tracking_heatmap_data(struct pt_core_data *cd,
- struct pt_sysinfo *si)
- {
- #ifdef TTHE_TUNER_SUPPORT
- int size = get_unaligned_le16(&cd->input_buf[0]);
- if (size)
- tthe_print(cd, cd->input_buf, size, "THM=");
- #endif
- memcpy(si->xy_mode, cd->input_buf, SENSOR_HEADER_SIZE);
- return 0;
- }
- /*******************************************************************************
- * FUNCTION: move_sensor_data
- *
- * SUMMARY: Move the valid sensor data from the input buffer into the system
- * information structure, xy_mode and xy_data.
- * - If TTHE_TUNER_SUPPORT is defined print the raw sensor data into
- * the tthe_tuner sysfs node under the label "sensor_monitor"
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * *si - pointer to the system information structure
- ******************************************************************************/
- static int move_sensor_data(struct pt_core_data *cd,
- struct pt_sysinfo *si)
- {
- #ifdef TTHE_TUNER_SUPPORT
- int size = get_unaligned_le16(&cd->input_buf[0]);
- if (size)
- tthe_print(cd, cd->input_buf, size, "sensor_monitor=");
- #endif
- memcpy(si->xy_mode, cd->input_buf, SENSOR_HEADER_SIZE);
- return 0;
- }
- /*******************************************************************************
- * FUNCTION: move_button_data
- *
- * SUMMARY: Move the valid button data from the input buffer into the system
- * information structure, xy_mode and xy_data.
- * - If TTHE_TUNER_SUPPORT is defined print the raw button data into
- * the tthe_tuner sysfs node under the label "OpModeData"
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * *si - pointer to the system information structure
- ******************************************************************************/
- static int move_button_data(struct pt_core_data *cd,
- struct pt_sysinfo *si)
- {
- #ifdef TTHE_TUNER_SUPPORT
- int size = get_unaligned_le16(&cd->input_buf[0]);
- if (size)
- tthe_print(cd, cd->input_buf, size, "OpModeData=");
- #endif
- memcpy(si->xy_mode, cd->input_buf, BTN_INPUT_HEADER_SIZE);
- pt_pr_buf(cd->dev, DL_INFO, (u8 *)si->xy_mode, BTN_INPUT_HEADER_SIZE,
- "xy_mode");
- memcpy(si->xy_data, &cd->input_buf[BTN_INPUT_HEADER_SIZE],
- BTN_REPORT_SIZE);
- pt_pr_buf(cd->dev, DL_INFO, (u8 *)si->xy_data, BTN_REPORT_SIZE,
- "xy_data");
- return 0;
- }
- /*******************************************************************************
- * FUNCTION: move_touch_data
- *
- * SUMMARY: Move the valid touch data from the input buffer into the system
- * information structure, xy_mode and xy_data.
- * - If TTHE_TUNER_SUPPORT is defined print the raw touch data into
- * the tthe_tuner sysfs node under the label "OpModeData"
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * *si - pointer to the system information structure
- ******************************************************************************/
- static int move_touch_data(struct pt_core_data *cd, struct pt_sysinfo *si)
- {
- int max_tch = si->sensing_conf_data.max_tch;
- int num_cur_tch;
- int length;
- struct pt_tch_abs_params *tch = &si->tch_hdr[PT_TCH_NUM];
- #ifdef TTHE_TUNER_SUPPORT
- int size = get_unaligned_le16(&cd->input_buf[0]);
- if (size)
- tthe_print(cd, cd->input_buf, size, "OpModeData=");
- #endif
- memcpy(si->xy_mode, cd->input_buf, si->desc.tch_header_size);
- pt_pr_buf(cd->dev, DL_INFO, (u8 *)si->xy_mode,
- si->desc.tch_header_size, "xy_mode");
- pt_get_touch_axis(cd, &num_cur_tch, tch->size,
- tch->max, si->xy_mode + 3 + tch->ofs, tch->bofs);
- if (unlikely(num_cur_tch > max_tch))
- num_cur_tch = max_tch;
- length = num_cur_tch * si->desc.tch_record_size;
- memcpy(si->xy_data, &cd->input_buf[si->desc.tch_header_size], length);
- pt_pr_buf(cd->dev, DL_INFO, (u8 *)si->xy_data, length, "xy_data");
- return 0;
- }
- /*******************************************************************************
- * FUNCTION: move_hid_pen_data
- *
- * SUMMARY: TODO Move the valid pen data from the input buffer into the system
- * information structure, xy_mode and xy_data.
- * - If TTHE_TUNER_SUPPORT is defined print the raw pen data into
- * the tthe_tuner sysfs node under the label "HID" starting with the
- * report ID.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * *si - pointer to the system information structure
- ******************************************************************************/
- static int move_hid_pen_data(struct pt_core_data *cd, struct pt_sysinfo *si)
- {
- #ifdef TTHE_TUNER_SUPPORT
- int size = get_unaligned_le16(&cd->input_buf[0]);
- if (size) {
- /*
- * HID over USB does not require the two byte length field, so
- * this should print from input_buf[2] but to keep both finger
- * and pen reports the same the length is included
- */
- if (cd->tthe_hid_usb_format == PT_FEATURE_ENABLE)
- tthe_print(cd, &(cd->input_buf[2]), size - 2,
- "HID-USB=");
- else
- tthe_print(cd, &(cd->input_buf[0]), size,
- "HID-I2C=");
- }
- #endif
- pt_pr_buf(cd->dev, DL_INFO, (u8 *)&(cd->input_buf[0]), size, "HID Pen");
- return 0;
- }
- /*******************************************************************************
- * FUNCTION: parse_touch_input
- *
- * SUMMARY: Parse the touch report and take action based on the touch
- * report_id.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * size - size of touch record
- ******************************************************************************/
- static int parse_touch_input(struct pt_core_data *cd, int size)
- {
- struct pt_sysinfo *si = &cd->sysinfo;
- int report_id = cd->input_buf[2];
- int rc = -EINVAL;
- pt_debug(cd->dev, DL_DEBUG, "%s: Received touch report\n",
- __func__);
- if (!si->ready) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: Need system information to parse touches\n",
- __func__);
- return 0;
- }
- if (!si->xy_mode || !si->xy_data)
- return rc;
- if (report_id == PT_PIP_TOUCH_REPORT_ID)
- rc = move_touch_data(cd, si);
- else if (report_id == PT_HID_PEN_REPORT_ID)
- rc = move_hid_pen_data(cd, si);
- else if (report_id == PT_PIP_CAPSENSE_BTN_REPORT_ID)
- rc = move_button_data(cd, si);
- else if (report_id == PT_PIP_SENSOR_DATA_REPORT_ID)
- rc = move_sensor_data(cd, si);
- else if (report_id == PT_PIP_TRACKING_HEATMAP_REPORT_ID)
- rc = move_tracking_heatmap_data(cd, si);
- if (rc)
- return rc;
- /* attention IRQ */
- call_atten_cb(cd, PT_ATTEN_IRQ, cd->mode);
- return 0;
- }
- /*******************************************************************************
- * FUNCTION: parse_command_input
- *
- * SUMMARY: Move the response data from the input buffer to the response buffer
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * size - size of response data
- ******************************************************************************/
- static int parse_command_input(struct pt_core_data *cd, int size)
- {
- pt_debug(cd->dev, DL_DEBUG, "%s: Received cmd interrupt\n",
- __func__);
- memcpy(cd->response_buf, cd->input_buf, size);
- #if defined(TTHE_TUNER_SUPPORT) && defined(TTDL_DIAGNOSTICS)
- if (size && cd->show_tt_data) {
- if (cd->pip2_prot_active)
- tthe_print(cd, cd->input_buf, size, "TT_DATA_PIP2=");
- else
- tthe_print(cd, cd->input_buf, size, "TT_DATA=");
- }
- #endif
- mutex_lock(&cd->system_lock);
- cd->hid_cmd_state = 0;
- mutex_unlock(&cd->system_lock);
- wake_up(&cd->wait_q);
- return 0;
- }
- /*******************************************************************************
- * FUNCTION: pt_allow_enumeration
- *
- * SUMMARY: Determine if an enumeration or fully re-probe should perform when
- * FW sentinel is seen.
- *
- * RETURN:
- * true = allow enumeration or fully re-probe
- * false = skip enumeration and fully re-probe
- *
- * PARAMETERS:
- * *cd - pointer to core data
- ******************************************************************************/
- static inline bool pt_allow_enumeration(struct pt_core_data *cd)
- {
- if ((cd->panel_id_support & PT_PANEL_ID_BY_SYS_INFO) &&
- (!cd->hid_reset_cmd_state) &&
- (cd->core_probe_complete) &&
- (cd->hid_cmd_state != PIP1_CMD_ID_START_BOOTLOADER + 1) &&
- (cd->hid_cmd_state != PIP1_BL_CMD_ID_LAUNCH_APP + 1) &&
- (cd->mode == PT_MODE_OPERATIONAL)) {
- return true;
- }
- if ((!cd->hid_reset_cmd_state) &&
- (cd->core_probe_complete) &&
- (cd->hid_cmd_state != PIP1_CMD_ID_START_BOOTLOADER + 1) &&
- (cd->hid_cmd_state != PIP1_BL_CMD_ID_LAUNCH_APP + 1) &&
- (cd->active_dut_generation != DUT_PIP1_ONLY)) {
- return true;
- }
- pt_debug(cd->dev, DL_INFO,
- "%s: Dissallow - %s=%d %s=%d %s=0x%02X %s=%d\n",
- __func__,
- "hid_reset_cmd_state(0)", cd->hid_reset_cmd_state,
- "core_probe_complete(1)", cd->core_probe_complete,
- "hid_cmd_state(Not 0x02 or 0x39)", cd->hid_cmd_state,
- "active_dut_gen(0,2)", cd->active_dut_generation);
- return false;
- }
- /*******************************************************************************
- * FUNCTION: pt_is_touch_report
- *
- * SUMMARY: Determine if a report ID should be treated as a touch report
- *
- * RETURN:
- * true = report ID is a touch report
- * false = report ID is not a touch report
- *
- * PARAMETERS:
- * id - Report ID
- ******************************************************************************/
- static bool pt_is_touch_report(int id)
- {
- if (id == PT_PIP_TOUCH_REPORT_ID ||
- id == PT_HID_PEN_REPORT_ID ||
- id == PT_PIP_CAPSENSE_BTN_REPORT_ID ||
- id == PT_PIP_SENSOR_DATA_REPORT_ID ||
- id == PT_PIP_TRACKING_HEATMAP_REPORT_ID)
- return true;
- else
- return false;
- }
- /*******************************************************************************
- * FUNCTION: pt_parse_input
- *
- * SUMMARY: Parse the input data read from DUT due to IRQ. Handle data based
- * on if its a response to a command or asynchronous touch data / reset
- * sentinel. PIP2.x messages have additional error checking that is
- * parsed (SEQ match from cmd to rsp, CRC valid).
- * Look for special packets based on unique lengths:
- * 0 bytes - APP(FW) reset sentinel or Gen5/6 BL sentinel
- * 2 bytes - Empty buffer (PIP 1.7 and earlier)
- * 11 bytes - possible PIP2.x reset sentinel (TAG and SEQ must = 0)
- * 0xFFXX - Empty buffer (PIP 1.7+)
- * Queue a startup after any asynchronous FW reset sentinel is seen, unless
- * the initial probe has not yet been done.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- ******************************************************************************/
- static int pt_parse_input(struct pt_core_data *cd)
- {
- int report_id;
- int cmd_id;
- int is_command = 0;
- int size;
- int print_size;
- bool touch_report = true;
- unsigned short calc_crc;
- unsigned short resp_crc;
- cd->fw_sys_mode_in_standby_state = false;
- size = get_unaligned_le16(&cd->input_buf[0]);
- print_size = size;
- pt_debug(cd->dev, DL_DEBUG, "<<< %s: IRQ Triggered, read len [%d]\n",
- __func__, print_size);
- if (print_size <= PT_MAX_INPUT)
- pt_pr_buf(cd->dev, DL_DEBUG, cd->input_buf, print_size,
- "<<< Read buf");
- if (size == 0 ||
- (size == 11 &&
- (cd->input_buf[PIP2_RESP_SEQUENCE_OFFSET] &
- PIP2_RESP_SEQUENCE_MASK) == 0 &&
- (cd->input_buf[PIP2_RESP_REPORT_ID_OFFSET] &
- PIP2_CMD_COMMAND_ID_MASK) ==
- PIP2_CMD_ID_STATUS)) {
- touch_report = false;
- cd->hw_detected = true;
- cd->bl_pip_ver_ready = false;
- cd->app_pip_ver_ready = false;
- if (size == 0) {
- mutex_lock(&cd->system_lock);
- cd->pip2_prot_active = false;
- if (cd->active_dut_generation == DUT_PIP1_ONLY) {
- /*
- * For Gen5/6 this sentinel could be from
- * the BL or FW. Attempt to set the correct
- * mode based on the previous PIP command.
- */
- if (cd->hid_cmd_state ==
- PIP1_BL_CMD_ID_LAUNCH_APP + 1) {
- cd->mode = PT_MODE_OPERATIONAL;
- cd->startup_status =
- STARTUP_STATUS_FW_RESET_SENTINEL;
- } else if (cd->hid_cmd_state ==
- PIP1_CMD_ID_START_BOOTLOADER + 1 ||
- cd->hid_reset_cmd_state) {
- cd->mode = PT_MODE_BOOTLOADER;
- cd->startup_status =
- STARTUP_STATUS_BL_RESET_SENTINEL;
- } else {
- cd->mode = PT_MODE_UNKNOWN;
- cd->startup_status =
- STARTUP_STATUS_START;
- }
- cd->fw_system_mode = FW_SYS_MODE_UNDEFINED;
- pt_debug(cd->dev, DL_INFO,
- "%s: ATM Gen5/6 %s sentinel received\n",
- __func__,
- (cd->mode == PT_MODE_OPERATIONAL ?
- "FW" :
- (cd->mode == PT_MODE_BOOTLOADER ?
- "BL" : "Unknown")));
- } else {
- cd->mode = PT_MODE_OPERATIONAL;
- cd->fw_system_mode = FW_SYS_MODE_BOOT;
- cd->startup_status =
- STARTUP_STATUS_FW_RESET_SENTINEL;
- pt_debug(cd->dev, DL_INFO,
- "%s: ATM PT/TT FW sentinel received\n",
- __func__);
- }
- mutex_unlock(&cd->system_lock);
- if (pt_allow_enumeration(cd)) {
- if (cd->active_dut_generation == DUT_UNKNOWN) {
- pt_debug(cd->dev, DL_INFO,
- "%s: Queue Restart\n", __func__);
- pt_queue_restart(cd);
- } else {
- pt_debug(cd->dev, DL_INFO,
- "%s: Queue Enum\n", __func__);
- pt_queue_enum(cd);
- }
- } else {
- pt_debug(cd->dev, DL_INFO,
- "%s: Sentinel - No Queued Action\n",
- __func__);
- }
- } else {
- /* Sentinel must be from TT/TC BL */
- mutex_lock(&cd->system_lock);
- cd->pip2_prot_active = true;
- cd->startup_status = STARTUP_STATUS_BL_RESET_SENTINEL;
- cd->mode = PT_MODE_BOOTLOADER;
- cd->sysinfo.ready = false;
- mutex_unlock(&cd->system_lock);
- pt_debug(cd->dev, DL_INFO,
- "%s: BL Reset sentinel received\n", __func__);
- if (cd->flashless_dut &&
- cd->flashless_auto_bl == PT_ALLOW_AUTO_BL) {
- pt_debug(cd->dev, DL_INFO,
- "%s: BL to RAM for flashless DUT\n",
- __func__);
- kthread_run(start_fw_upgrade, cd, "pt_loader");
- }
- }
- mutex_lock(&cd->system_lock);
- memcpy(cd->response_buf, cd->input_buf, 2);
- if (!cd->hid_reset_cmd_state && !cd->hid_cmd_state) {
- mutex_unlock(&cd->system_lock);
- pt_debug(cd->dev, DL_WARN,
- "%s: Device Initiated Reset\n", __func__);
- wake_up(&cd->wait_q);
- return 0;
- }
- cd->hid_reset_cmd_state = 0;
- if (cd->hid_cmd_state == PIP1_CMD_ID_START_BOOTLOADER + 1 ||
- cd->hid_cmd_state == PIP1_BL_CMD_ID_LAUNCH_APP + 1 ||
- cd->hid_cmd_state == PIP1_CMD_ID_USER_CMD + 1)
- cd->hid_cmd_state = 0;
- wake_up(&cd->wait_q);
- mutex_unlock(&cd->system_lock);
- return 0;
- } else if (size == 2 || size >= PT_PIP_1P7_EMPTY_BUF) {
- /*
- * This debug message below is used by PBATS to calculate the
- * time from the last lift off IRQ to when FW exits LFT mode.
- */
- touch_report = false;
- pt_debug(cd->dev, DL_WARN,
- "%s: DUT - Empty buffer detected\n", __func__);
- return 0;
- } else if (size > PT_MAX_INPUT || size < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: DUT - Unexpected len field in active bus data!\n",
- __func__);
- return -EINVAL;
- }
- if (cd->pip2_prot_active) {
- pt_debug(cd->dev, DL_DEBUG,
- "%s: Decode PIP2.x Response\n", __func__);
- /* PIP2 does not have a report id, hard code it */
- report_id = 0x00;
- cmd_id = cd->input_buf[PIP2_RESP_COMMAND_ID_OFFSET];
- calc_crc = crc_ccitt_calculate(cd->input_buf, size - 2);
- resp_crc = cd->input_buf[size - 2] << 8;
- resp_crc |= cd->input_buf[size - 1];
- if ((cd->pip2_cmd_tag_seq !=
- (cd->input_buf[PIP2_RESP_SEQUENCE_OFFSET] & 0x0F)) &&
- (resp_crc != calc_crc) &&
- ((cd->input_buf[PIP1_RESP_REPORT_ID_OFFSET]
- == PT_PIP_TOUCH_REPORT_ID) ||
- (cd->input_buf[PIP1_RESP_REPORT_ID_OFFSET]
- == PT_PIP_CAPSENSE_BTN_REPORT_ID))) {
- pt_debug(cd->dev, DL_WARN,
- "%s: %s %d %s\n",
- __func__,
- "Received PIP1 report id =",
- cd->input_buf[PIP1_RESP_REPORT_ID_OFFSET],
- "when expecting a PIP2 report - IGNORE report");
- return 0;
- }
- is_command = 1;
- touch_report = false;
- } else {
- report_id = cd->input_buf[PIP1_RESP_REPORT_ID_OFFSET];
- cmd_id = cd->input_buf[PIP1_RESP_COMMAND_ID_OFFSET];
- }
- #ifdef TTDL_DIAGNOSTICS
- pt_debug(cd->dev, DL_DEBUG,
- "%s: pip2 = %d report_id: 0x%02X, cmd_code: 0x%02X\n",
- __func__, cd->pip2_prot_active, report_id,
- (cmd_id & PIP2_CMD_COMMAND_ID_MASK));
- #endif /* TTDL_DIAGNOSTICS */
- if (report_id == PT_PIP_WAKEUP_REPORT_ID) {
- pt_wakeup_host(cd);
- #ifdef TTHE_TUNER_SUPPORT
- tthe_print(cd, cd->input_buf, size, "TT_WAKEUP=");
- #endif
- return 0;
- }
- mod_timer_pending(&cd->watchdog_timer, jiffies +
- msecs_to_jiffies(cd->watchdog_interval));
- /*
- * If it is PIP2 response, the report_id has been set to 0,
- * so it will not be parsed as a touch packet.
- */
- if (!pt_is_touch_report(report_id)) {
- is_command = 1;
- touch_report = false;
- }
- if (unlikely(is_command)) {
- parse_command_input(cd, size);
- return 0;
- }
- if (touch_report)
- parse_touch_input(cd, size);
- return 0;
- }
- /*******************************************************************************
- * FUNCTION: pt_read_input
- *
- * SUMMARY: Reads incoming data off of the active bus
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- ******************************************************************************/
- static int pt_read_input(struct pt_core_data *cd)
- {
- struct device *dev = cd->dev;
- int rc = 0;
- int t;
- int retry = PT_BUS_READ_INPUT_RETRY_COUNT;
- /*
- * Workaround for easywake failure
- * Interrupt for easywake, wait for bus controller to wake
- */
- mutex_lock(&cd->system_lock);
- if (IS_EASY_WAKE_CONFIGURED(cd->easy_wakeup_gesture)) {
- if (cd->sleep_state == SS_SLEEP_ON || cd->sleep_state == SS_EASY_WAKING_ON) {
- mutex_unlock(&cd->system_lock);
- if (!dev->power.is_suspended)
- goto read;
- t = wait_event_timeout(cd->wait_q,
- (cd->wait_until_wake == 1),
- msecs_to_jiffies(2000));
- #ifdef TTDL_DIAGNOSTICS
- if (IS_TMO(t)) {
- cd->bus_transmit_error_count++;
- pt_toggle_err_gpio(cd, PT_ERR_GPIO_I2C_TRANS);
- pt_debug(dev, DL_ERROR,
- "%s: !!!I2C Transmission Error %d\n",
- __func__,
- cd->bus_transmit_error_count);
- }
- #else
- if (IS_TMO(t))
- pt_queue_enum(cd);
- #endif /* TTDL_DIAGNOSTICS */
- goto read;
- }
- }
- mutex_unlock(&cd->system_lock);
- read:
- /* Try reading up to 'retry' times */
- while (retry-- != 0) {
- rc = pt_adap_read_default_nosize(cd, cd->input_buf,
- PT_MAX_INPUT);
- if (!rc) {
- pt_debug(dev, DL_DEBUG,
- "%s: Read input successfully\n", __func__);
- goto read_exit;
- }
- usleep_range(1000, 2000);
- }
- pt_debug(dev, DL_ERROR,
- "%s: Error getting report, rc=%d\n", __func__, rc);
- read_exit:
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_irq
- *
- * SUMMARY: Process all detected interrupts
- *
- * RETURN:
- * IRQ_HANDLED - Finished processing the interrupt
- *
- * PARAMETERS:
- * irq - IRQ number
- * *handle - pointer to core data struct
- ******************************************************************************/
- irqreturn_t pt_irq(int irq, void *handle)
- {
- struct pt_core_data *cd = handle;
- int rc = 0;
- if (!pt_check_irq_asserted(cd))
- return IRQ_HANDLED;
- rc = pt_read_input(cd);
- #ifdef TTDL_DIAGNOSTICS
- cd->irq_count++;
- /* Used to calculate T-Refresh */
- if (cd->t_refresh_active) {
- if (cd->t_refresh_count == 0) {
- cd->t_refresh_time = jiffies;
- cd->t_refresh_count++;
- } else if (cd->t_refresh_count < cd->t_refresh_total) {
- cd->t_refresh_count++;
- } else {
- cd->t_refresh_active = 0;
- cd->t_refresh_time =
- jiffies_to_msecs(jiffies - cd->t_refresh_time);
- }
- }
- #endif /* TTDL_DIAGNOSTICS */
- if (!rc)
- pt_parse_input(cd);
- return IRQ_HANDLED;
- }
- /*******************************************************************************
- * FUNCTION: _pt_subscribe_attention
- *
- * SUMMARY: Function pointer included in core_cmds to allow other modules
- * to subscribe themselves into the TTDL attention list
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * type - attention type enum
- * *id - ID of the module calling this function
- * *func - callback function pointer to be called when notified
- * mode - attention mode
- ******************************************************************************/
- int _pt_subscribe_attention(struct device *dev,
- enum pt_atten_type type, char *id, int (*func)(struct device *),
- int mode)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- struct atten_node *atten, *atten_new;
- atten_new = kzalloc(sizeof(*atten_new), GFP_KERNEL);
- if (!atten_new)
- return -ENOMEM;
- pt_debug(cd->dev, DL_INFO, "%s from '%s'\n", __func__,
- dev_name(cd->dev));
- spin_lock(&cd->spinlock);
- list_for_each_entry(atten, &cd->atten_list[type], node) {
- if (atten->id == id && atten->mode == mode) {
- spin_unlock(&cd->spinlock);
- kfree(atten_new);
- pt_debug(cd->dev, DL_INFO, "%s: %s=%p %s=%d\n",
- __func__,
- "already subscribed attention",
- dev, "mode", mode);
- return 0;
- }
- }
- atten_new->id = id;
- atten_new->dev = dev;
- atten_new->mode = mode;
- atten_new->func = func;
- list_add(&atten_new->node, &cd->atten_list[type]);
- spin_unlock(&cd->spinlock);
- return 0;
- }
- /*******************************************************************************
- * FUNCTION: _pt_unsubscribe_attention
- *
- * SUMMARY: Function pointer included in core_cmds to allow other modules
- * to unsubscribe themselves from the TTDL attention list
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * type - attention type enum
- * *id - ID of the module calling this function
- * *func - function pointer
- * mode - attention mode
- ******************************************************************************/
- int _pt_unsubscribe_attention(struct device *dev,
- enum pt_atten_type type, char *id, int (*func)(struct device *),
- int mode)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- struct atten_node *atten, *atten_n;
- spin_lock(&cd->spinlock);
- list_for_each_entry_safe(atten, atten_n, &cd->atten_list[type], node) {
- if (atten->id == id && atten->mode == mode) {
- list_del(&atten->node);
- spin_unlock(&cd->spinlock);
- pt_debug(cd->dev, DL_DEBUG, "%s: %s=%p %s=%d\n",
- __func__,
- "unsub for atten->dev", atten->dev,
- "atten->mode", atten->mode);
- kfree(atten);
- return 0;
- }
- }
- spin_unlock(&cd->spinlock);
- return -ENODEV;
- }
- /*******************************************************************************
- * FUNCTION: _pt_request_exclusive
- *
- * SUMMARY: Function pointer included in core_cmds to allow other modules
- * to request exclusive access
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * timeout_ms - timeout to wait for exclusive access
- ******************************************************************************/
- static int _pt_request_exclusive(struct device *dev,
- int timeout_ms)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- return request_exclusive(cd, (void *)dev, timeout_ms);
- }
- /*******************************************************************************
- * FUNCTION: _pt_release_exclusive
- *
- * SUMMARY: Function pointer included in core_cmds to allow other modules
- * to release exclusive access
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- ******************************************************************************/
- static int _pt_release_exclusive(struct device *dev)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- return release_exclusive(cd, (void *)dev);
- }
- /*******************************************************************************
- * FUNCTION: _pt_request_reset
- *
- * SUMMARY: Function pointer included in core_cmds to allow other modules
- * to request the DUT to be reset. Function returns err if refused or
- * timeout occurs (Note: core uses fixed timeout period).
- *
- * NOTE: Function blocks until ISR occurs.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * protect - flag to call protected or non-protected
- ******************************************************************************/
- static int _pt_request_reset(struct device *dev, int protect)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- int rc;
- rc = pt_dut_reset(cd, protect);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR, "%s: Error on h/w reset r=%d\n",
- __func__, rc);
- }
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: _pt_request_enum
- *
- * SUMMARY: Function pointer included in core_cmds to allow other modules
- * to request TTDL to queue an enum. This function will return err
- * if refused; if no error then enum has completed and system is in
- * normal operation mode.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * wait - boolean to determine if to wait for startup event
- ******************************************************************************/
- static int _pt_request_enum(struct device *dev, bool wait)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- pt_queue_enum(cd);
- if (wait)
- wait_event_timeout(cd->wait_q,
- cd->startup_state == STARTUP_NONE,
- msecs_to_jiffies(PT_REQUEST_ENUM_TIMEOUT));
- return 0;
- }
- /*******************************************************************************
- * FUNCTION: _pt_request_sysinfo
- *
- * SUMMARY: Function pointer included in core_cmds to allow other modules
- * to request the pointer to the system information structure. This
- * function will return NULL if sysinfo has not been acquired from the
- * DUT yet.
- *
- * RETURN: Pointer to the system information struct
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- ******************************************************************************/
- struct pt_sysinfo *_pt_request_sysinfo(struct device *dev)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- int rc = 0;
- /* Attempt to get sysinfo if not ready and panel_id is from XY pin */
- if ((cd->panel_id_support & PT_PANEL_ID_BY_SYS_INFO) &&
- !cd->sysinfo.ready) {
- rc = pt_hid_output_get_sysinfo_(cd);
- if (rc) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: Error getting sysinfo rc=%d\n",
- __func__, rc);
- }
- }
- if (cd->sysinfo.ready)
- return &cd->sysinfo;
- return NULL;
- }
- /*******************************************************************************
- * FUNCTION: _pt_request_loader_pdata
- *
- * SUMMARY: Function pointer included in core_cmds to allow other modules
- * to request the pointer to the loader platform data
- *
- * RETURN: Pointer to the loader platform data struct
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- ******************************************************************************/
- static struct pt_loader_platform_data *_pt_request_loader_pdata(
- struct device *dev)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- return cd->pdata->loader_pdata;
- }
- /*******************************************************************************
- * FUNCTION: _pt_request_start_wd
- *
- * SUMMARY: Function pointer included in core_cmds to allow other modules
- * to request to start the TTDL watchdog
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- ******************************************************************************/
- static int _pt_request_start_wd(struct device *dev)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- pt_start_wd_timer(cd);
- return 0;
- }
- /*******************************************************************************
- * FUNCTION: _pt_request_stop_wd
- *
- * SUMMARY: Function pointer included in core_cmds to allow other modules
- * to request to stop the TTDL watchdog
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- ******************************************************************************/
- static int _pt_request_stop_wd(struct device *dev)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- pt_stop_wd_timer(cd);
- return 0;
- }
- /*******************************************************************************
- * FUNCTION: pt_pip2_launch_app
- *
- * SUMMARY: Sends the PIP2 EXECUTE command to launch the APP and then wait for
- * the FW reset sentinel to indicate the function succeeded.
- *
- * NOTE: Calling this function when the DUT is in Application mode WILL result
- * in a timeout delay and with the DUT being reset with an XRES.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data structure
- * protect - flag to call protected or non-protected
- ******************************************************************************/
- static int pt_pip2_launch_app(struct device *dev, int protect)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- u16 actual_read_len;
- u16 tmp_startup_status = cd->startup_status;
- u8 read_buf[12];
- u8 status;
- int time = 0;
- int rc = 0;
- mutex_lock(&cd->system_lock);
- cd->startup_status = STARTUP_STATUS_START;
- pt_debug(dev, DL_DEBUG, "%s: Startup Status Reset\n", __func__);
- mutex_unlock(&cd->system_lock);
- rc = _pt_request_pip2_send_cmd(dev, protect,
- PIP2_CMD_ID_EXECUTE, NULL, 0, read_buf,
- &actual_read_len);
- if (rc) {
- pt_debug(dev, DL_ERROR,
- "%s: PIP2 EXECUTE cmd failed rc = %d\n",
- __func__, rc);
- } else {
- status = read_buf[PIP2_RESP_STATUS_OFFSET];
- /* Test for no or invalid image in FLASH, no point to reset */
- if (status == PIP2_RSP_ERR_INVALID_IMAGE) {
- rc = status;
- goto exit;
- }
- /* Any other boot failure */
- if (status != 0) {
- pt_debug(dev, DL_ERROR,
- "%s: FW did not EXECUTE, status = %d\n",
- __func__, status);
- rc = status;
- }
- }
- if (rc) {
- pt_debug(dev, DL_ERROR,
- "%s: Failed to launch APP, XRES DUT rc = %d\n",
- __func__, rc);
- goto exit;
- }
- while ((cd->startup_status == STARTUP_STATUS_START) && time < 240) {
- msleep(20);
- pt_debug(cd->dev, DL_INFO, "%s: wait for %d for enum=0x%04X\n",
- __func__, time, cd->startup_status);
- time += 20;
- }
- if (cd->startup_status == STARTUP_STATUS_START) {
- pt_debug(cd->dev, DL_WARN,
- "%s: TMO waiting for FW reset sentinel\n", __func__);
- rc = -ETIME;
- }
- exit:
- if (cd->startup_status == STARTUP_STATUS_START) {
- /* Reset to original state because we could be stuck in BL */
- mutex_lock(&cd->system_lock);
- cd->startup_status = tmp_startup_status;
- mutex_unlock(&cd->system_lock);
- }
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: _pt_request_pip2_launch_app
- *
- * SUMMARY: Calls pt_pip2_launch_app() when configured to. A small delay is
- * inserted to ensure the reset has allowed the BL reset sentinel to be
- * consumed.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data structure
- ******************************************************************************/
- static int _pt_request_pip2_launch_app(struct device *dev, int protect)
- {
- return pt_pip2_launch_app(dev, protect);
- }
- /*******************************************************************************
- * FUNCTION: _pt_request_wait_for_enum_state
- *
- * SUMMARY: Loops for up to timeout waiting for the startup_status to reach
- * the state passed in or STARTUP_STATUS_COMPLETE whichever comes first
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data structure
- * timeout - timeout for how long to wait
- * state - enum state to wait for
- ******************************************************************************/
- static int _pt_request_wait_for_enum_state(struct device *dev, int timeout,
- int state)
- {
- int rc = 0;
- int t;
- struct pt_core_data *cd = dev_get_drvdata(dev);
- t = wait_event_timeout(cd->wait_q,
- (cd->startup_status & state) || (cd->startup_status & 0x0100),
- msecs_to_jiffies(timeout));
- if (IS_TMO(t)) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: TMO waiting for enum state 0x%04X in %dms\n",
- __func__, state, timeout);
- pt_debug(cd->dev, DL_WARN,
- "%s: enum state reached 0x%04X\n",
- __func__, cd->startup_status);
- rc = -ETIME;
- } else if (cd->startup_status & state) {
- pt_debug(cd->dev, DL_INFO,
- "%s: Enum state reached: enum=0x%04X in %dms\n",
- __func__, cd->startup_status,
- (t == 1) ? timeout : (timeout - jiffies_to_msecs(t)));
- } else {
- if (t == 1) {
- pt_debug(
- cd->dev, DL_ERROR,
- "%s: TMO waiting for enum state 0x%04X in %dms\n",
- __func__, state, timeout);
- rc = -ETIME;
- } else {
- pt_debug(
- cd->dev, DL_ERROR,
- "%s: Enum state 0x%04X not reached in %dms\n",
- __func__, state, timeout - jiffies_to_msecs(t));
- rc = -EINVAL;
- }
- pt_debug(cd->dev, DL_INFO, "%s: enum state reached 0x%04X\n",
- __func__, cd->startup_status);
- }
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_core_wake_device_from_deep_sleep_
- *
- * SUMMARY: Call the set_power function and set the DUT to wake up from
- * deep sleep.
- *
- * RETURN:
- * 0 = success
- * !0 = error
- *
- * PARAMETERS:
- * *cd - pointer to core data
- ******************************************************************************/
- static int pt_core_wake_device_from_deep_sleep_(
- struct pt_core_data *cd)
- {
- int rc;
- rc = pt_hid_cmd_set_power_(cd, HID_POWER_ON);
- if (rc)
- rc = -EAGAIN;
- /* Prevent failure on sequential wake/sleep requests from OS */
- msleep(20);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_core_wake_device_from_easy_wake_
- *
- * SUMMARY: Wake up device from Easy-Wake state.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- ******************************************************************************/
- static int pt_core_wake_device_from_easy_wake_(struct pt_core_data *cd)
- {
- int rc = 0;
- rc = pt_core_wake_device_from_deep_sleep_(cd);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_restore_parameters_
- *
- * SUMMARY: This function sends all RAM parameters stored in the linked list
- * back to the DUT
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer the core data structure
- ******************************************************************************/
- static int pt_restore_parameters_(struct pt_core_data *cd)
- {
- struct param_node *param;
- int rc = 0;
- if (!(cd->cpdata->flags & PT_CORE_FLAG_RESTORE_PARAMETERS))
- goto exit;
- spin_lock(&cd->spinlock);
- list_for_each_entry(param, &cd->param_list, node) {
- spin_unlock(&cd->spinlock);
- pt_debug(cd->dev, DL_INFO, "%s: Parameter id:%d value:%d\n",
- __func__, param->id, param->value);
- rc = pt_pip_set_param_(cd, param->id,
- param->value, param->size);
- if (rc)
- goto exit;
- spin_lock(&cd->spinlock);
- }
- spin_unlock(&cd->spinlock);
- exit:
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_pip2_exit_bl_
- *
- * SUMMARY: Attempt to exit the BL and run the application, taking into account
- * a DUT that may not have flash and will need FW to be loaded into RAM
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer the core data structure
- * *status_str - pointer to optional status string buffer
- * buf_size - size of status_str buffer
- ******************************************************************************/
- int pt_pip2_exit_bl_(struct pt_core_data *cd, u8 *status_str, int buf_size)
- {
- int rc;
- int wait_time = 0;
- u8 mode = PT_MODE_UNKNOWN;
- bool load_status_str = false;
- /*
- * Below function has protective call to ensure no enum is still on
- * going, while this kind of protection should be applied widely in
- * future (TODO).
- */
- rc = pt_pip2_get_mode_sysmode(cd, &mode, NULL);
- if (status_str && buf_size <= 50)
- load_status_str = true;
- if (mode == PT_MODE_BOOTLOADER) {
- if (cd->flashless_dut == 1) {
- rc = pt_hw_hard_reset(cd);
- } else {
- rc = pt_pip2_launch_app(cd->dev,
- PT_CORE_CMD_UNPROTECTED);
- if (rc == PIP2_RSP_ERR_INVALID_IMAGE) {
- pt_debug(cd->dev, DL_ERROR, "%s: %s = %d\n",
- __func__, "Invalid image in FLASH rc", rc);
- } else if (rc) {
- pt_debug(cd->dev, DL_ERROR, "%s: %s = %d\n",
- __func__, "Failed to launch app rc", rc);
- }
- }
- if (!rc) {
- if (cd->flashless_dut == 1) {
- /* Wait for BL to complete before enum */
- rc = _pt_request_wait_for_enum_state(cd->dev,
- 4000, STARTUP_STATUS_FW_RESET_SENTINEL);
- if (rc && load_status_str) {
- strlcpy(status_str, "No FW sentinel after BL",
- sizeof(*status_str)*PT_STATUS_STR_LEN);
- goto exit;
- }
- }
- /*
- * If the host wants to interact with the FW or do a
- * forced calibration, the FW must be out of BOOT mode
- * and the system information must have been retrieved.
- * Reaching the FW_OUT_OF_BOOT state guarantees both.
- * If, however, the enumeration does not reach this
- * point, the DUT may still be in APP mode so test
- * for all conditions.
- */
- rc = _pt_request_wait_for_enum_state(cd->dev, 4500,
- STARTUP_STATUS_FW_OUT_OF_BOOT);
- if (!rc || cd->startup_status >=
- STARTUP_STATUS_FW_RESET_SENTINEL) {
- mutex_lock(&cd->system_lock);
- cd->mode = PT_MODE_OPERATIONAL;
- mutex_unlock(&cd->system_lock);
- }
- if (rc) {
- pt_debug(cd->dev, DL_WARN, "%s: %s: 0x%04X\n",
- __func__, "Failed to enum with DUT",
- cd->startup_status);
- if (load_status_str && !(cd->startup_status &
- STARTUP_STATUS_FW_OUT_OF_BOOT)) {
- strlcpy(status_str, "FW Stuck in Boot mode",
- sizeof(*status_str)*PT_STATUS_STR_LEN);
- goto exit;
- }
- }
- /*
- * The coming FW sentinel could wake up the event
- * queue, which has chance to be taken by next command
- * wrongly. Following delay is a workaround to avoid
- * this issue for most situations.
- */
- msleep(20);
- pt_start_wd_timer(cd);
- }
- if (load_status_str) {
- if (rc == PIP2_RSP_ERR_INVALID_IMAGE)
- strlcpy(status_str, "Failed - Invalid image in FLASH",
- sizeof(*status_str)*PT_STATUS_STR_LEN);
- else if (!rc)
- strlcpy(status_str, "Entered APP from BL mode",
- sizeof(*status_str)*PT_STATUS_STR_LEN);
- else
- strlcpy(status_str, "Failed to enter APP from BL mode",
- sizeof(*status_str)*PT_STATUS_STR_LEN);
- }
- } else if (mode == PT_MODE_OPERATIONAL) {
- mutex_lock(&cd->system_lock);
- cd->mode = mode;
- mutex_unlock(&cd->system_lock);
- rc = pt_poll_for_fw_exit_boot_mode(cd, 1500, &wait_time);
- if (load_status_str) {
- if (!rc)
- strlcpy(status_str, "Already in APP mode",
- sizeof(*status_str)*PT_STATUS_STR_LEN);
- else
- strlcpy(status_str, "Already in APP mode - FW stuck in Boot mode",
- sizeof(*status_str)*PT_STATUS_STR_LEN);
- }
- } else if (rc || mode == PT_MODE_UNKNOWN) {
- mutex_lock(&cd->system_lock);
- cd->mode = mode;
- mutex_unlock(&cd->system_lock);
- if (load_status_str)
- strlcpy(status_str, "Failed to determine active mode",
- sizeof(*status_str)*PT_STATUS_STR_LEN);
- }
- exit:
- if (!rc)
- pt_start_wd_timer(cd);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_pip2_exit_bl
- *
- * SUMMARY: Wrapper function for _pt_pip2_exit_bl that guarantees exclusive
- * access.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer the core data structure
- * *status_str - pointer to optional status string buffer
- * buf_size - size of status_str buffer
- ******************************************************************************/
- int pt_pip2_exit_bl(struct pt_core_data *cd, u8 *status_str, int buf_size)
- {
- int rc;
- rc = request_exclusive(cd, cd->dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail get exclusive ex=%p own=%p\n", __func__,
- cd->exclusive_dev, cd->dev);
- return rc;
- }
- rc = pt_pip2_exit_bl_(cd, status_str, buf_size);
- if (release_exclusive(cd, cd->dev) < 0)
- pt_debug(cd->dev, DL_ERROR, "%s: fail to release exclusive\n",
- __func__);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: _fast_startup
- *
- * SUMMARY: Perform fast startup after resume device by power on/off stratergy.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer the core data structure
- ******************************************************************************/
- static int _fast_startup(struct pt_core_data *cd)
- {
- int retry = PT_CORE_STARTUP_RETRY_COUNT;
- int rc = 0;
- u8 mode = PT_MODE_UNKNOWN;
- struct pt_hid_desc hid_desc;
- int wait_time = 0;
- memset(&hid_desc, 0, sizeof(hid_desc));
- reset:
- if (retry != PT_CORE_STARTUP_RETRY_COUNT)
- pt_debug(cd->dev, DL_INFO, "%s: Retry %d\n", __func__,
- PT_CORE_STARTUP_RETRY_COUNT - retry);
- if (cd->active_dut_generation == DUT_PIP1_ONLY) {
- pt_debug(cd->dev, DL_INFO, "%s: PIP1 Enumeration start\n",
- __func__);
- pt_flush_bus_if_irq_asserted(cd, PT_FLUSH_BUS_BASED_ON_LEN);
- rc = pt_get_hid_descriptor_(cd, &hid_desc);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: Error on getting HID descriptor r=%d\n",
- __func__, rc);
- if (retry--)
- goto reset;
- goto exit;
- }
- cd->mode = pt_get_mode(cd, &hid_desc);
- if (cd->mode == PT_MODE_BOOTLOADER) {
- pt_debug(cd->dev, DL_INFO, "%s: Bootloader mode\n",
- __func__);
- rc = pt_hid_output_bl_launch_app_(cd);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: Error on launch app r=%d\n",
- __func__, rc);
- if (retry--)
- goto reset;
- goto exit;
- }
- rc = pt_get_hid_descriptor_(cd, &hid_desc);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: Error on getting HID descriptor r=%d\n",
- __func__, rc);
- if (retry--)
- goto reset;
- goto exit;
- }
- cd->mode = pt_get_mode(cd, &hid_desc);
- if (cd->mode == PT_MODE_BOOTLOADER) {
- if (retry--)
- goto reset;
- goto exit;
- }
- }
- cd->startup_status |= STARTUP_STATUS_GET_DESC;
- cd->startup_status |= STARTUP_STATUS_FW_OUT_OF_BOOT;
- } else {
- pt_debug(cd->dev, DL_INFO, "%s: PIP2 Enumeration start\n",
- __func__);
- if (retry == PT_CORE_STARTUP_RETRY_COUNT) {
- /* Wait for any sentinel before first try */
- rc = _pt_request_wait_for_enum_state(
- cd->dev, 150,
- STARTUP_STATUS_BL_RESET_SENTINEL |
- STARTUP_STATUS_FW_RESET_SENTINEL);
- if (rc)
- pt_debug(cd->dev, DL_ERROR,
- "%s: No Sentinel detected rc = %d\n",
- __func__, rc);
- } else
- pt_flush_bus_if_irq_asserted(cd,
- PT_FLUSH_BUS_BASED_ON_LEN);
- rc = pt_pip2_get_mode_sysmode_(cd, &mode, NULL);
- if (rc) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: Get mode failed, mode unknown\n",
- __func__);
- mode = PT_MODE_UNKNOWN;
- }
- cd->mode = mode;
- if (cd->mode == PT_MODE_BOOTLOADER) {
- pt_debug(cd->dev, DL_INFO, "%s: Bootloader mode\n",
- __func__);
- rc = pt_pip2_exit_bl_(cd, NULL, 0);
- if (rc) {
- pt_debug(cd->dev, DL_ERROR,
- "%s Failed to exit bootloader\n",
- __func__);
- msleep(50);
- rc = -ENODEV;
- if (retry--)
- goto reset;
- goto exit;
- } else {
- pt_debug(cd->dev, DL_INFO,
- "%s: Exit bootloader successfully\n",
- __func__);
- }
- if (cd->mode != PT_MODE_OPERATIONAL) {
- pt_debug(cd->dev, DL_WARN,
- "%s: restore mode failure mode = %d\n",
- __func__, cd->mode);
- if (retry--)
- goto reset;
- goto exit;
- }
- }
- cd->startup_status |= STARTUP_STATUS_GET_DESC;
- }
- /* FW cannot handle most PIP cmds when it is still in BOOT mode */
- rc = _pt_poll_for_fw_exit_boot_mode(cd, 500, &wait_time);
- if (!rc) {
- cd->startup_status |= STARTUP_STATUS_FW_OUT_OF_BOOT;
- pt_debug(cd->dev, DL_WARN,
- "%s: Exit FW BOOT Mode after %dms\n",
- __func__, wait_time);
- } else {
- pt_debug(cd->dev, DL_WARN,
- "%s: FW stuck in BOOT Mode after %dms\n",
- __func__, wait_time);
- goto exit;
- }
- if (!cd->sysinfo.ready) {
- rc = pt_hid_output_get_sysinfo_(cd);
- if (rc) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: Error on getting sysinfo r=%d\n",
- __func__, rc);
- if (retry--)
- goto reset;
- goto exit;
- }
- }
- cd->startup_status |= STARTUP_STATUS_GET_SYS_INFO;
- rc = pt_restore_parameters_(cd);
- if (rc)
- pt_debug(cd->dev, DL_ERROR,
- "%s: failed to restore parameters rc=%d\n",
- __func__, rc);
- else
- cd->startup_status |= STARTUP_STATUS_RESTORE_PARM;
- exit:
- cd->startup_status |= STARTUP_STATUS_COMPLETE;
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_core_poweron_device_
- *
- * SUMMARY: Power on device, enable IRQ, and then perform a fast startup.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- ******************************************************************************/
- static int pt_core_poweron_device_(struct pt_core_data *cd)
- {
- struct device *dev = cd->dev;
- int rc = 0;
- /*
- * After power on action, the chip can general FW sentinel. It can
- * trigger an enumeration without hid_reset_cmd_state flag. Since the
- * _fast_startup() can perform a quick enumeration too, here doesn't
- * need another enumeration.
- */
- mutex_lock(&cd->system_lock);
- cd->startup_status = STARTUP_STATUS_START;
- cd->hid_reset_cmd_state = 1;
- mutex_unlock(&cd->system_lock);
- rc = cd->cpdata->power(cd->cpdata, 1, dev, 0);
- if (rc < 0) {
- pt_debug(dev, DL_ERROR, "%s: HW Power up fails r=%d\n",
- __func__, rc);
- goto exit;
- }
- if (!cd->irq_enabled) {
- cd->irq_enabled = true;
- enable_irq(cd->irq);
- }
- /* TBD: following function doesn't update startup_status */
- rc = _fast_startup(cd);
- exit:
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_core_wake_device_from_deep_standby_
- *
- * SUMMARY: Reset device, and then trigger a full enumeration.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- ******************************************************************************/
- static int pt_core_wake_device_from_deep_standby_(struct pt_core_data *cd)
- {
- int rc;
- rc = pt_dut_reset_and_wait(cd);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR, "%s: Error on h/w reset r=%d\n",
- __func__, rc);
- goto exit;
- }
- rc = _fast_startup(cd);
- exit:
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_core_easywake_off_
- *
- * SUMMARY: Resume the device with a power on or wake from deep sleep based on
- * the configuration in the core platform data structure.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- ******************************************************************************/
- static int pt_core_easywake_off_(struct pt_core_data *cd)
- {
- int rc = 0;
- mutex_lock(&cd->system_lock);
- if (cd->sleep_state == SS_EASY_WAKING_OFF) {
- mutex_unlock(&cd->system_lock);
- pt_debug(cd->dev, DL_INFO,
- "%s - %d skip wakeoff\n", __func__, cd->sleep_state);
- return 0;
- }
- mutex_unlock(&cd->system_lock);
- if (!(cd->cpdata->flags & PT_CORE_FLAG_SKIP_RESUME)) {
- if (IS_EASY_WAKE_CONFIGURED(cd->easy_wakeup_gesture))
- rc = pt_core_wake_device_from_easy_wake_(cd);
- if (rc < 0)
- pt_debug(cd->dev, DL_ERROR,
- "%s - %d failed %d\n", __func__, rc);
- }
- mutex_lock(&cd->system_lock);
- cd->sleep_state = SS_EASY_WAKING_OFF;
- mutex_unlock(&cd->system_lock);
- pt_start_wd_timer(cd);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_core_easywake_off
- *
- * SUMMARY: Protected call to pt_core_easywake_off by exclusive access to the DUT.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- ******************************************************************************/
- static int pt_core_easywake_off(struct pt_core_data *cd)
- {
- int rc;
- rc = request_exclusive(cd, cd->dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail get exclusive ex=%p own=%p\n",
- __func__, cd->exclusive_dev, cd->dev);
- return rc;
- }
- rc = pt_core_easywake_off_(cd);
- if (release_exclusive(cd, cd->dev) < 0)
- pt_debug(cd->dev, DL_ERROR, "%s: fail to release exclusive\n",
- __func__);
- else
- pt_debug(cd->dev, DL_DEBUG, "%s: pass release exclusive\n",
- __func__);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_core_wake_
- *
- * SUMMARY: Resume the device with a power on or wake from deep sleep based on
- * the configuration in the core platform data structure.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- ******************************************************************************/
- static int pt_core_wake_(struct pt_core_data *cd)
- {
- int rc = 0;
- mutex_lock(&cd->system_lock);
- if (cd->sleep_state == SS_SLEEP_OFF || cd->sleep_state == SS_WAKING) {
- mutex_unlock(&cd->system_lock);
- pt_debug(cd->dev, DL_INFO,
- "%s - skip wake sleep state %d\n", __func__, cd->sleep_state);
- return 0;
- } else {
- cd->sleep_state = SS_WAKING;
- }
- mutex_unlock(&cd->system_lock);
- if (!(cd->cpdata->flags & PT_CORE_FLAG_SKIP_RESUME)) {
- if (cd->cpdata->flags & PT_CORE_FLAG_POWEROFF_ON_SLEEP) {
- pt_debug(cd->dev, DL_INFO,
- "%s: Entering into poweron mode:\n", __func__);
- rc = pt_core_poweron_device_(cd);
- if (rc < 0)
- pr_err("%s: Poweron error detected: rc=%d\n",
- __func__, rc);
- }
- else if (cd->cpdata->flags & PT_CORE_FLAG_DEEP_STANDBY)
- rc = pt_core_wake_device_from_deep_standby_(cd);
- else /* Default action to exit DeepSleep */
- rc = pt_core_wake_device_from_deep_sleep_(cd);
- }
- mutex_lock(&cd->system_lock);
- cd->sleep_state = SS_SLEEP_OFF;
- mutex_unlock(&cd->system_lock);
- pt_start_wd_timer(cd);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_core_wake_
- *
- * SUMMARY: Protected call to pt_core_wake_ by exclusive access to the DUT.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- ******************************************************************************/
- static int pt_core_wake(struct pt_core_data *cd)
- {
- int rc = 0;
- rc = request_exclusive(cd, cd->dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail get exclusive ex=%p own=%p\n",
- __func__, cd->exclusive_dev, cd->dev);
- return rc;
- }
- rc = pt_core_wake_(cd);
- if (release_exclusive(cd, cd->dev) < 0)
- pt_debug(cd->dev, DL_ERROR, "%s: fail to release exclusive\n",
- __func__);
- else
- pt_debug(cd->dev, DL_DEBUG, "%s: pass release exclusive\n",
- __func__);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_get_ic_crc_
- *
- * SUMMARY: This function retrieves the config block CRC
- *
- * NOTE: The post condition of calling this function will be that the DUT will
- * be in SCANNINING mode if no failures occur
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer the core data structure
- * ebid - enumerated block ID
- ******************************************************************************/
- static int pt_get_ic_crc_(struct pt_core_data *cd, u8 ebid)
- {
- struct pt_sysinfo *si = &cd->sysinfo;
- int rc = 0;
- u8 status;
- u16 calculated_crc = 0;
- u16 stored_crc = 0;
- rc = pt_pip_suspend_scanning_(cd);
- if (rc)
- goto error;
- rc = pt_pip_verify_config_block_crc_(cd, ebid, &status,
- &calculated_crc, &stored_crc);
- if (rc)
- goto exit;
- if (status) {
- rc = -EINVAL;
- goto exit;
- }
- si->ttconfig.crc = stored_crc;
- exit:
- pt_pip_resume_scanning_(cd);
- error:
- pt_debug(cd->dev, DL_INFO,
- "%s: CRC: ebid:%d, calc:0x%04X, stored:0x%04X, rc=%d\n",
- __func__, ebid, calculated_crc, stored_crc, rc);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_pip2_read_gpio
- *
- * SUMMARY: Sends a PIP2 READ_GPIO command to the DUT and stores the 32 gpio
- * bits into the passed in variable
- *
- * NOTE: PIP2 READ_GPIO command is only supported in bootloader
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *status - pointer to where the command response status is stored
- * *gpio - pointer to device attributes structure
- ******************************************************************************/
- static int pt_pip2_read_gpio(struct device *dev, u8 *status, u32 *gpio)
- {
- int rc = 0;
- u16 actual_read_len;
- u8 read_buf[12];
- u8 tmp_status = 0;
- u8 index = PIP2_RESP_STATUS_OFFSET;
- memset(read_buf, 0, ARRAY_SIZE(read_buf));
- rc = _pt_request_pip2_send_cmd(dev,
- PT_CORE_CMD_UNPROTECTED, PIP2_CMD_ID_READ_GPIO,
- NULL, 0, read_buf, &actual_read_len);
- if (rc) {
- pt_debug(dev, DL_ERROR,
- "%s: Failed to send PIP2 READ_GPIO cmd\n", __func__);
- rc = -ECOMM;
- } else {
- tmp_status = read_buf[index];
- }
- if (status)
- *status = tmp_status;
- if (!rc && gpio && (tmp_status == 0)) {
- *gpio = ((read_buf[index + 4] << 24) |
- (read_buf[index + 3] << 16) |
- (read_buf[index + 2] << 8) |
- (read_buf[index + 1]));
- }
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: _pt_pip2_get_panel_id_by_gpio
- *
- * SUMMARY: Wrapper function to call pt_pip2_read_gpio() to get panel ID
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer the core data structure
- * *pid - pointer to store panel ID
- ******************************************************************************/
- static int _pt_pip2_get_panel_id_by_gpio(struct pt_core_data *cd, u8 *pid)
- {
- u32 gpio_value = 0;
- u8 status = 0;
- u8 panel_id = PANEL_ID_NOT_ENABLED;
- int rc = 0;
- if (!pid)
- return -ENOMEM;
- rc = pt_pip2_read_gpio(cd->dev, &status, &gpio_value);
- if (!rc) {
- if (status == 0) {
- panel_id = (gpio_value & PT_PANEL_ID_BITMASK) >>
- PT_PANEL_ID_SHIFT;
- pt_debug(cd->dev, DL_INFO, "%s: %s=0x%02X %s=0x%08X\n",
- __func__,
- "BL mode PID", panel_id, "gpio", gpio_value);
- *pid = panel_id;
- } else {
- pt_debug(cd->dev, DL_ERROR, "%s: %s=%d\n",
- __func__,
- "BL read gpio failed status", status);
- }
- } else {
- pt_debug(cd->dev, DL_ERROR, "%s: %s=%d\n",
- __func__,
- "BL read gpio failed status", status);
- }
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_enum_with_dut_
- *
- * SUMMARY: This function does the full enumeration of the DUT with TTDL.
- * The core data (cd) startup_status will store, as a bitmask, each
- * state of the enumeration process. The startup will be attempted
- * PT_CORE_STARTUP_RETRY_COUNT times before giving up.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer the core data structure
- * reset - Flag to reset the DUT before attempting to enumerate
- * *status - poionter to store the enum status bitmask flags
- ******************************************************************************/
- static int pt_enum_with_dut_(struct pt_core_data *cd, bool reset,
- u32 *enum_status)
- {
- int try = 1;
- int rc = 0;
- int wait_time = 0;
- bool detected = false;
- u8 return_data[8];
- u8 mode = PT_MODE_UNKNOWN;
- u8 pid = PANEL_ID_NOT_ENABLED;
- u8 sys_mode = FW_SYS_MODE_UNDEFINED;
- struct pt_hid_desc hid_desc;
- memset(&hid_desc, 0, sizeof(hid_desc));
- #ifdef TTHE_TUNER_SUPPORT
- tthe_print(cd, NULL, 0, "enter startup");
- #endif
- pt_debug(cd->dev, DL_INFO, "%s: Start enum... 0x%04X, reset=%d\n",
- __func__, cd->startup_status, reset);
- pt_stop_wd_timer(cd);
- reset:
- if (try > 1)
- pt_debug(cd->dev, DL_WARN, "%s: DUT Enum Attempt %d\n",
- __func__, try);
- pt_flush_bus_if_irq_asserted(cd, PT_FLUSH_BUS_BASED_ON_LEN);
- if (cd->active_dut_generation == DUT_PIP1_ONLY) {
- pt_debug(cd->dev, DL_INFO,
- "%s: PIP1 Enumeration start\n", __func__);
- /* Only reset the DUT after the first try */
- if (reset || (try > 1)) {
- /*
- * Reset hardware only for Legacy parts. Skip for TT/TC
- * parts because if the FW image was loaded directly
- * to SRAM issueing a reset ill wipe out what was just
- * loaded.
- */
- rc = pt_dut_reset_and_wait(cd);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: Error on h/w reset r=%d\n",
- __func__, rc);
- if (try++ < PT_CORE_STARTUP_RETRY_COUNT)
- goto reset;
- goto exit;
- }
- /* sleep to allow FW to be launched if available */
- msleep(120);
- }
- rc = pt_get_hid_descriptor_(cd, &hid_desc);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: Error getting HID Descriptor r=%d\n",
- __func__, rc);
- if (try++ < PT_CORE_STARTUP_RETRY_COUNT)
- goto reset;
- rc = -EIO;
- goto exit;
- }
- detected = true;
- cd->mode = pt_get_mode(cd, &hid_desc);
- /*
- * Most systems do not use an XY pin as the panel_id and so
- * the BL is used to retrieve the panel_id, however for
- * systems that do use an XY pin, the panel_id MUST be
- * retrieved from the system information when running FW
- * (done below) and so this section of code is skipped.
- * Entering the BL here is only needed on XY_PIN systems.
- */
- if (cd->panel_id_support & PT_PANEL_ID_BY_BL) {
- if (cd->mode == PT_MODE_OPERATIONAL) {
- rc = pt_pip_start_bootloader_(cd);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: Error on start bootloader r=%d\n",
- __func__, rc);
- if (try++ < PT_CORE_STARTUP_RETRY_COUNT)
- goto reset;
- goto exit;
- }
- cd->mode = PT_MODE_BOOTLOADER;
- pt_debug(cd->dev, DL_INFO, "%s: Bootloader mode\n",
- __func__);
- }
- rc = pt_hid_output_bl_get_information_(cd, return_data);
- if (!rc) {
- cd->bl_info.ready = true;
- cd->bl_info.chip_id =
- get_unaligned_le16(&return_data[2]);
- pt_debug(cd->dev, DL_INFO, "%s: chip ID %04X\n",
- __func__, cd->bl_info.chip_id);
- } else {
- pt_debug(cd->dev, DL_ERROR,
- "%s: failed to get chip ID, r=%d\n",
- __func__, rc);
- }
- rc = pt_hid_output_bl_get_panel_id_(cd, &pid);
- mutex_lock(&cd->system_lock);
- if (!rc) {
- cd->pid_for_loader = pid;
- pt_debug(cd->dev, DL_INFO, "%s: Panel ID: 0x%02X\n",
- __func__, cd->pid_for_loader);
- } else {
- cd->pid_for_loader = PANEL_ID_NOT_ENABLED;
- pt_debug(cd->dev, DL_WARN,
- "%s: Read Failed, disable Panel ID: 0x%02X\n",
- __func__, cd->pid_for_loader);
- }
- mutex_unlock(&cd->system_lock);
- }
- /* Exit BL due to XY_PIN case or any other cause to be in BL */
- if (cd->mode == PT_MODE_BOOTLOADER) {
- rc = pt_hid_output_bl_launch_app_(cd);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: Error on launch app r=%d\n",
- __func__, rc);
- if (try++ < PT_CORE_STARTUP_RETRY_COUNT)
- goto reset;
- rc = -ENODEV;
- goto exit;
- }
- /* sleep to allow FW to be launched if available */
- msleep(120);
- /* Ensure the DUT is now in Application mode */
- rc = pt_get_hid_descriptor_(cd, &hid_desc);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: Error getting HID Desc r=%d\n",
- __func__, rc);
- if (try++ < PT_CORE_STARTUP_RETRY_COUNT)
- goto reset;
- rc = -EIO;
- goto exit;
- }
- cd->mode = pt_get_mode(cd, &hid_desc);
- if (cd->mode == PT_MODE_BOOTLOADER) {
- pt_debug(cd->dev, DL_WARN,
- "%s: Error confiming exit BL\n",
- __func__);
- if (try++ < PT_CORE_STARTUP_RETRY_COUNT)
- goto reset;
- rc = -ENODEV;
- goto exit;
- }
- }
- pt_debug(cd->dev, DL_INFO, "%s: Operational mode\n", __func__);
- cd->mode = PT_MODE_OPERATIONAL;
- *enum_status |= STARTUP_STATUS_GET_DESC;
- *enum_status |= STARTUP_STATUS_FW_OUT_OF_BOOT;
- } else {
- /* Generation is PIP2 Capable */
- pt_debug(cd->dev, DL_INFO,
- "%s: PIP2 Enumeration start\n", __func__);
- rc = pt_pip2_get_mode_sysmode_(cd, &mode, NULL);
- if (rc) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: Get mode failed, mode unknown\n",
- __func__);
- mode = PT_MODE_UNKNOWN;
- } else
- detected = true;
- cd->mode = mode;
- switch (cd->mode) {
- case PT_MODE_OPERATIONAL:
- pt_debug(cd->dev, DL_INFO,
- "%s: Operational mode\n", __func__);
- if (cd->app_pip_ver_ready == false) {
- rc = pt_pip2_get_version_(cd);
- if (!rc)
- cd->app_pip_ver_ready = true;
- else {
- if (try++ < PT_CORE_STARTUP_RETRY_COUNT)
- goto reset;
- goto exit;
- }
- }
- break;
- case PT_MODE_BOOTLOADER:
- pt_debug(cd->dev, DL_INFO,
- "%s: Bootloader mode\n", __func__);
- if (cd->panel_id_support & PT_PANEL_ID_BY_BL) {
- rc = _pt_pip2_get_panel_id_by_gpio(cd, &pid);
- mutex_lock(&cd->system_lock);
- if (!rc) {
- cd->pid_for_loader = pid;
- pt_debug(cd->dev, DL_INFO,
- "%s: Panel ID: 0x%02X\n",
- __func__, cd->pid_for_loader);
- } else {
- cd->pid_for_loader =
- PANEL_ID_NOT_ENABLED;
- pt_debug(cd->dev, DL_WARN,
- "%s: Read Failed, disable Panel ID: 0x%02X\n",
- __func__, cd->pid_for_loader);
- }
- mutex_unlock(&cd->system_lock);
- }
- if (cd->bl_pip_ver_ready == false) {
- rc = pt_pip2_get_version_(cd);
- if (!rc)
- cd->bl_pip_ver_ready = true;
- else {
- if (try++ < PT_CORE_STARTUP_RETRY_COUNT)
- goto reset;
- goto exit;
- }
- }
- /*
- * Launch app command will fail in flashless mode.
- * Skip launch app command here to save time for
- * enumeration flow.
- */
- if (cd->flashless_dut)
- goto exit;
- /*
- * pt_pip2_launch_app() is needed here instead of
- * pt_pip2_exit_bl() because exit_bl will cause several
- * hw_resets to occur and the auto BL on a flashless
- * DUT will fail.
- */
- rc = pt_pip2_launch_app(cd->dev,
- PT_CORE_CMD_UNPROTECTED);
- if (rc) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: Error on launch app r=%d\n",
- __func__, rc);
- msleep(50);
- if (try++ < PT_CORE_STARTUP_RETRY_COUNT)
- goto reset;
- goto exit;
- }
- /*
- * IRQ thread can be delayed if the serial log print is
- * enabled. It causes next command to get wrong response
- * Here the delay is to ensure pt_parse_input() to be
- * finished.
- */
- msleep(60);
- /* Check and update the mode */
- rc = pt_pip2_get_mode_sysmode_(cd, &mode, NULL);
- if (rc) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: Get mode failed, mode unknown\n",
- __func__);
- mode = PT_MODE_UNKNOWN;
- }
- cd->mode = mode;
- if (cd->mode == PT_MODE_OPERATIONAL) {
- pt_debug(cd->dev, DL_INFO,
- "%s: Launched to Operational mode\n",
- __func__);
- } else if (cd->mode == PT_MODE_BOOTLOADER) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: Launch failed, Bootloader mode\n",
- __func__);
- goto exit;
- } else if (cd->mode == PT_MODE_UNKNOWN) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: Launch failed, Unknown mode\n",
- __func__);
- if (try++ < PT_CORE_STARTUP_RETRY_COUNT)
- goto reset;
- goto exit;
- }
- if (cd->app_pip_ver_ready == false) {
- rc = pt_pip2_get_version_(cd);
- if (!rc)
- cd->app_pip_ver_ready = true;
- else {
- if (try++ < PT_CORE_STARTUP_RETRY_COUNT)
- goto reset;
- goto exit;
- }
- }
- break;
- default:
- pt_debug(cd->dev, DL_ERROR,
- "%s: Unknown mode\n", __func__);
- if (try++ < PT_CORE_STARTUP_RETRY_COUNT)
- goto reset;
- goto exit;
- }
- *enum_status |= STARTUP_STATUS_GET_DESC;
- }
- pt_init_pip_report_fields(cd);
- *enum_status |= STARTUP_STATUS_GET_RPT_DESC;
- if (!cd->features.easywake)
- cd->easy_wakeup_gesture = PT_CORE_EWG_NONE;
- pt_debug(cd->dev, DL_INFO, "%s: Reading sysinfo\n", __func__);
- rc = pt_hid_output_get_sysinfo_(cd);
- if (rc) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: Error on getting sysinfo r=%d\n", __func__, rc);
- if (try++ < PT_CORE_STARTUP_RETRY_COUNT)
- goto reset;
- goto exit;
- }
- *enum_status |= STARTUP_STATUS_GET_SYS_INFO;
- /* FW cannot handle most PIP cmds when it is still in BOOT mode */
- rc = _pt_poll_for_fw_exit_boot_mode(cd, 10000, &wait_time);
- if (!rc) {
- *enum_status |= STARTUP_STATUS_FW_OUT_OF_BOOT;
- pt_debug(cd->dev, DL_WARN,
- "%s: Exit FW BOOT Mode after %dms\n",
- __func__, wait_time);
- } else {
- pt_debug(cd->dev, DL_WARN,
- "%s: FW stuck in BOOT Mode after %dms\n",
- __func__, wait_time);
- goto exit;
- }
- pt_debug(cd->dev, DL_INFO, "%s pt Prot Version: %d.%d\n",
- __func__,
- cd->sysinfo.ttdata.pip_ver_major,
- cd->sysinfo.ttdata.pip_ver_minor);
- rc = pt_get_ic_crc_(cd, PT_TCH_PARM_EBID);
- if (rc) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: DUT Config block CRC failure rc=%d\n",
- __func__, rc);
- if (try++ < PT_CORE_STARTUP_RETRY_COUNT)
- goto reset;
- } else {
- _pt_get_fw_sys_mode(cd, &sys_mode, NULL);
- if (sys_mode != FW_SYS_MODE_SCANNING) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: scan state: %d, retry: %d\n",
- __func__, sys_mode, try);
- if (try++ < PT_CORE_STARTUP_RETRY_COUNT)
- goto reset;
- } else
- *enum_status |= STARTUP_STATUS_GET_CFG_CRC;
- }
- rc = pt_restore_parameters_(cd);
- if (rc) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: Failed to restore parameters rc=%d\n",
- __func__, rc);
- } else
- *enum_status |= STARTUP_STATUS_RESTORE_PARM;
- call_atten_cb(cd, PT_ATTEN_STARTUP, 0);
- cd->watchdog_interval = PT_WATCHDOG_TIMEOUT;
- cd->startup_retry_count = 0;
- exit:
- /* Generate the HW Version of the connected DUT and store in cd */
- pt_generate_hw_version(cd, cd->hw_version);
- pt_debug(cd->dev, DL_WARN, "%s: HW Version: %s\n", __func__,
- cd->hw_version);
- pt_start_wd_timer(cd);
- if (!detected)
- rc = -ENODEV;
- #ifdef TTHE_TUNER_SUPPORT
- tthe_print(cd, NULL, 0, "exit startup");
- #endif
- pt_debug(cd->dev, DL_WARN,
- "%s: Completed Enumeration rc=%d On Attempt %d\n",
- __func__, rc, try);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_enum_with_dut
- *
- * SUMMARY: This is the safe function wrapper for pt_enum_with_dut_() by
- * requesting exclusive access around the call.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer the core data structure
- * reset - Flag to reset the DUT before attempting to enumerate
- * *status - pointer to store the enum status bitmask flags
- ******************************************************************************/
- static int pt_enum_with_dut(struct pt_core_data *cd, bool reset, u32 *status)
- {
- int rc = 0;
- mutex_lock(&cd->system_lock);
- cd->startup_state = STARTUP_RUNNING;
- mutex_unlock(&cd->system_lock);
- rc = request_exclusive(cd, cd->dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail get exclusive ex=%p own=%p\n",
- __func__, cd->exclusive_dev, cd->dev);
- goto exit;
- }
- rc = pt_enum_with_dut_(cd, reset, status);
- if (release_exclusive(cd, cd->dev) < 0)
- /* Don't return fail code, mode is already changed. */
- pt_debug(cd->dev, DL_ERROR, "%s: fail to release exclusive\n",
- __func__);
- else
- pt_debug(cd->dev, DL_DEBUG, "%s: pass release exclusive\n",
- __func__);
- exit:
- mutex_lock(&cd->system_lock);
- /* Clear startup state for any tasks waiting for startup completion */
- cd->startup_state = STARTUP_NONE;
- mutex_unlock(&cd->system_lock);
- /* Set STATUS_COMPLETE bit to indicate the status is ready to be read */
- *status |= STARTUP_STATUS_COMPLETE;
- /* Wake the waiters for end of startup */
- wake_up(&cd->wait_q);
- return rc;
- }
- static int add_sysfs_interfaces(struct device *dev);
- static void remove_sysfs_interfaces(struct device *dev);
- static void remove_sysfs_and_modules(struct device *dev);
- static void pt_release_modules(struct pt_core_data *cd);
- static void pt_probe_modules(struct pt_core_data *cd);
- /*******************************************************************************
- * FUNCTION: _pt_ttdl_restart
- *
- * SUMMARY: Restarts TTDL enumeration with the DUT and re-probes all modules
- *
- * NOTE: The function DOSE NOT remove sysfs and modules. Trying to create
- * existing sysfs nodes will produce an error.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to core device
- ******************************************************************************/
- static int _pt_ttdl_restart(struct device *dev)
- {
- int rc = 0;
- struct pt_core_data *cd = dev_get_drvdata(dev);
- #ifdef CONFIG_TOUCHSCREEN_PARADE_I2C
- struct i2c_client *client =
- (struct i2c_client *)container_of(dev, struct i2c_client, dev);
- #endif
- /*
- * Make sure the device is awake, pt_mt_release function will
- * cause pm sleep function and lead to deadlock.
- */
- pm_runtime_get_sync(dev);
- /* Use ttdl_restart_lock to avoid reentry */
- mutex_lock(&cd->ttdl_restart_lock);
- remove_sysfs_and_modules(cd->dev);
- #ifdef CONFIG_TOUCHSCREEN_PARADE_I2C
- if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
- pt_debug(dev, DL_ERROR,
- "%s I2C functionality not Supported\n", __func__);
- rc = -EIO;
- goto ttdl_no_error;
- }
- #endif
- if (cd->active_dut_generation == DUT_UNKNOWN) {
- rc = _pt_detect_dut_generation(cd->dev,
- &cd->startup_status, &cd->active_dut_generation,
- &cd->mode);
- if ((cd->active_dut_generation == DUT_UNKNOWN) || (rc)) {
- pt_debug(dev, DL_ERROR,
- "%s: Error, Unknown DUT Generation rc=%d\n",
- __func__, rc);
- }
- }
- rc = add_sysfs_interfaces(cd->dev);
- if (rc < 0)
- pt_debug(cd->dev, DL_ERROR,
- "%s: Error, failed sysfs nodes rc=%d\n",
- __func__, rc);
- if (!(cd->startup_status & STARTUP_STATUS_BL_RESET_SENTINEL)) {
- pt_debug(dev, DL_INFO, "%s: Call pt_enum_with_dut\n", __func__);
- rc = pt_enum_with_dut(cd, true, &cd->startup_status);
- if (rc < 0)
- pt_debug(dev, DL_ERROR,
- "%s: Error, Failed to Enumerate\n", __func__);
- }
- rc = pt_mt_probe(dev);
- if (rc < 0) {
- pt_debug(dev, DL_ERROR,
- "%s: Error, fail mt probe\n", __func__);
- }
- rc = pt_btn_probe(dev);
- if (rc < 0) {
- pt_debug(dev, DL_ERROR,
- "%s: Error, fail btn probe\n", __func__);
- }
- pt_probe_modules(cd);
- pt_debug(cd->dev, DL_WARN,
- "%s: Well Done! TTDL Restart Completed\n", __func__);
- rc = 0;
- #ifdef CONFIG_TOUCHSCREEN_PARADE_I2C
- ttdl_no_error:
- #endif
- mutex_unlock(&cd->ttdl_restart_lock);
- mutex_lock(&cd->system_lock);
- cd->startup_status |= STARTUP_STATUS_COMPLETE;
- cd->startup_state = STARTUP_NONE;
- mutex_unlock(&cd->system_lock);
- pm_runtime_put(dev);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_restart_work_function
- *
- * SUMMARY: This is the wrapper function placed in a work queue to call
- * _pt_ttdl_restart()
- *
- * RETURN: none
- *
- * PARAMETERS:
- * *work - pointer to the work_struct
- ******************************************************************************/
- static void pt_restart_work_function(struct work_struct *work)
- {
- struct pt_core_data *cd = container_of(work,
- struct pt_core_data, ttdl_restart_work);
- int rc = 0;
- rc = _pt_ttdl_restart(cd->dev);
- if (rc < 0)
- pt_debug(cd->dev, DL_ERROR, "%s: Fail queued startup r=%d\n",
- __func__, rc);
- }
- /*******************************************************************************
- * FUNCTION: pt_enum_work_function
- *
- * SUMMARY: This is the wrapper function placed in a work queue to call
- * pt_enum_with_dut()
- *
- * RETURN: none
- *
- * PARAMETERS:
- * *work - pointer to the work_struct
- ******************************************************************************/
- static void pt_enum_work_function(struct work_struct *work)
- {
- struct pt_core_data *cd = container_of(work,
- struct pt_core_data, enum_work);
- int rc;
- rc = pt_enum_with_dut(cd, false, &cd->startup_status);
- if (rc < 0)
- pt_debug(cd->dev, DL_ERROR, "%s: Fail queued startup r=%d\n",
- __func__, rc);
- }
- static int pt_get_regulator(struct pt_core_data *cd, bool get)
- {
- int rc;
- if (!get) {
- rc = 0;
- goto regulator_put;
- }
- cd->vdd = regulator_get(cd->dev, "vdd");
- if (IS_ERR(cd->vdd)) {
- rc = PTR_ERR(cd->vdd);
- dev_err(cd->dev,
- "Regulator get failed vdd rc=%d\n", rc);
- goto regulator_put;
- }
- cd->vcc_i2c = regulator_get(cd->dev, "vcc_i2c");
- if (IS_ERR(cd->vcc_i2c)) {
- rc = PTR_ERR(cd->vcc_i2c);
- dev_err(cd->dev,
- "Regulator get failed vcc_i2c rc=%d\n", rc);
- goto regulator_put;
- }
- return 0;
- regulator_put:
- if (cd->vdd) {
- regulator_put(cd->vdd);
- cd->vdd = NULL;
- }
- if (cd->vcc_i2c) {
- regulator_put(cd->vcc_i2c);
- cd->vcc_i2c = NULL;
- }
- return rc;
- }
- #ifdef ENABLE_I2C_REG_ONLY
- static int pt_enable_i2c_regulator(struct pt_core_data *cd, bool en)
- {
- int rc = 0;
- pt_debug(cd->dev, DL_INFO, "%s: Enter flag = %d\n", __func__, en);
- if (!en) {
- rc = 0;
- goto disable_vcc_i2c_reg_only;
- }
- if (cd->vcc_i2c) {
- rc = regulator_set_load(cd->vcc_i2c, I2C_ACTIVE_LOAD_MA);
- if (rc < 0)
- pt_debug(cd->dev, DL_INFO,
- "%s: I2c unable to set active current rc = %d\n", __func__, rc);
- pt_debug(cd->dev, DL_INFO, "%s: i2c set I2C_ACTIVE_LOAD_MA rc = %d\n",
- __func__, rc);
- }
- return 0;
- disable_vcc_i2c_reg_only:
- if (cd->vcc_i2c) {
- rc = regulator_set_load(cd->vcc_i2c, I2C_SUSPEND_LOAD_UA);
- if (rc < 0)
- pt_debug(cd->dev, DL_INFO, "%s: i2c unable to set 0 uAm rc = %d\n",
- __func__, rc);
- }
- pt_debug(cd->dev, DL_INFO, "%s: Exit rc = %d I2C_SUSPEND_LOAD_UA\n", __func__, rc);
- return rc;
- }
- #endif
- static int pt_enable_regulator(struct pt_core_data *cd, bool en)
- {
- int rc;
- if (!en) {
- rc = 0;
- goto disable_vcc_i2c_reg;
- }
- if (cd->vdd) {
- if (regulator_count_voltages(cd->vdd) > 0) {
- rc = regulator_set_voltage(cd->vdd, FT_VTG_MIN_UV,
- FT_VTG_MAX_UV);
- if (rc) {
- dev_err(cd->dev,
- "Regulator set_vtg failed vdd rc=%d\n", rc);
- goto exit;
- }
- }
- rc = regulator_enable(cd->vdd);
- if (rc) {
- dev_err(cd->dev,
- "Regulator vdd enable failed rc=%d\n", rc);
- goto exit;
- }
- dev_info(cd->dev, "%s: VDD regulator enabled:\n", __func__);
- }
- if (cd->vcc_i2c) {
- if (regulator_count_voltages(cd->vcc_i2c) > 0) {
- rc = regulator_set_voltage(cd->vcc_i2c, FT_I2C_VTG_MIN_UV,
- FT_I2C_VTG_MAX_UV);
- if (rc) {
- dev_err(cd->dev,
- "Regulator set_vtg failed vcc_i2c rc=%d\n", rc);
- goto disable_vdd_reg;
- }
- }
- rc = regulator_enable(cd->vcc_i2c);
- if (rc) {
- dev_err(cd->dev,
- "Regulator vcc_i2c enable failed rc=%d\n", rc);
- goto disable_vdd_reg;
- }
- dev_info(cd->dev, "%s: VCC I2C regulator enabled:\n", __func__);
- }
- return 0;
- disable_vcc_i2c_reg:
- if (cd->vcc_i2c) {
- if (regulator_count_voltages(cd->vcc_i2c) > 0)
- regulator_set_voltage(cd->vcc_i2c, FT_I2C_VTG_MIN_UV,
- FT_I2C_VTG_MAX_UV);
- regulator_disable(cd->vcc_i2c);
- dev_info(cd->dev, "%s: VCC I2C regulator disabled:\n", __func__);
- }
- disable_vdd_reg:
- if (cd->vdd) {
- if (regulator_count_voltages(cd->vdd) > 0)
- regulator_set_voltage(cd->vdd, FT_VTG_MIN_UV,
- FT_VTG_MAX_UV);
- regulator_disable(cd->vdd);
- dev_info(cd->dev, "%s: VDD regulator disabled:\n", __func__);
- }
- exit:
- return rc;
- }
- #if (KERNEL_VERSION(3, 19, 0) <= LINUX_VERSION_CODE)
- #define KERNEL_VER_GT_3_19
- #endif
- #if defined(CONFIG_PM_RUNTIME) || defined(KERNEL_VER_GT_3_19)
- /* CONFIG_PM_RUNTIME option is removed in 3.19.0 */
- #if defined(CONFIG_PM_SLEEP)
- /*******************************************************************************
- * FUNCTION: pt_core_rt_suspend
- *
- * SUMMARY: Wrapper function with PM Runtime stratergy to call pt_core_sleep.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to core device
- ******************************************************************************/
- static int pt_core_rt_suspend(struct device *dev)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- pt_debug(dev, DL_DEBUG, "%s Skip - probe state %d\n",
- __func__, cd->core_probe_complete);
- return 0;
- }
- /*******************************************************************************
- * FUNCTION: pt_core_rt_resume
- *
- * SUMMARY: Wrapper function with PM Runtime stratergy to call pt_core_wake.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to core device
- ******************************************************************************/
- static int pt_core_rt_resume(struct device *dev)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- pt_debug(dev, DL_DEBUG, "%s Skip - probe state %d\n",
- __func__, cd->core_probe_complete);
- return 0;
- }
- #endif /* CONFIG_PM_SLEEP */
- #endif /* CONFIG_PM_RUNTIME || LINUX_VERSION_CODE */
- #if defined(CONFIG_PM_SLEEP)
- /*******************************************************************************
- * FUNCTION: pt_core_suspend_
- *
- * SUMMARY: Wrapper function with device suspend/resume stratergy to call
- * pt_core_sleep. This function may disable IRQ during sleep state.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to core device
- ******************************************************************************/
- static int pt_core_suspend_(struct device *dev)
- {
- int rc;
- struct pt_core_data *cd = dev_get_drvdata(dev);
- pt_debug(dev, DL_INFO, "%s: Enter\n", __func__);
- rc = pt_core_sleep(cd);
- if (rc) {
- pt_debug(dev, DL_ERROR, "%s: Error on sleep rc =%d\n",
- __func__, rc);
- return -EAGAIN;
- }
- rc = pt_enable_regulator(cd, false);
- if (!IS_EASY_WAKE_CONFIGURED(cd->easy_wakeup_gesture))
- return 0;
- /* Required to prevent interrupts before bus awake */
- disable_irq(cd->irq);
- cd->irq_disabled = 1;
- if (device_may_wakeup(dev)) {
- pt_debug(dev, DL_WARN, "%s Device MAY wakeup\n",
- __func__);
- if (!enable_irq_wake(cd->irq))
- cd->irq_wake = 1;
- } else {
- pt_debug(dev, DL_WARN, "%s Device MAY NOT wakeup\n",
- __func__);
- }
- pt_debug(dev, DL_INFO, "%s: Exit :\n", __func__);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_core_suspend
- *
- * SUMMARY: Wrapper function of pt_core_suspend_() to help avoid TP from being
- * woke up or put to sleep based on Kernel power state even when the display
- * is off based on the check of TTDL core platform flag.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to core device
- ******************************************************************************/
- static int pt_core_suspend(struct device *dev)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- int rc = 0;
- if (cd->drv_debug_suspend || (cd->cpdata->flags & PT_CORE_FLAG_SKIP_SYS_SLEEP))
- return 0;
- if (pt_core_state == STATE_SUSPEND)
- {
- pt_debug(cd->dev, DL_INFO, "%s Already in Suspend state\n", __func__);
- return 0;
- }
- pt_debug(cd->dev, DL_INFO, "%s Suspend start\n", __func__);
- cancel_work_sync(&cd->resume_work);
- cancel_work_sync(&cd->suspend_work);
- mutex_lock(&cd->system_lock);
- cd->wait_until_wake = 0;
- mutex_unlock(&cd->system_lock);
- if (pm_suspend_via_firmware() || cd->touch_offload) {
- rc = pt_core_suspend_(cd->dev);
- cd->quick_boot = true;
- } else {
- rc = pt_enable_i2c_regulator(cd, false);
- if (rc < 0)
- pt_debug(cd->dev, DL_ERROR,
- "%s: Error on disabling i2c regulator\n", __func__);
- }
- pt_debug(cd->dev, DL_INFO, "%s Suspend exit - rc = %d\n", __func__, rc);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_core_resume_
- *
- * SUMMARY: Wrapper function with device suspend/resume stratergy to call
- * pt_core_wake. This function may enable IRQ before wake up.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to core device
- ******************************************************************************/
- static int pt_core_resume_(struct device *dev)
- {
- int rc = 0;
- struct pt_core_data *cd = dev_get_drvdata(dev);
- dev_info(dev, "%s: Entering into resume mode:\n",
- __func__);
- rc = pt_enable_regulator(cd, true);
- dev_info(dev, "%s: Voltage regulator enabled: rc=%d\n",
- __func__, rc);
- if (!IS_EASY_WAKE_CONFIGURED(cd->easy_wakeup_gesture))
- goto exit;
- /*
- * Bus pm does not call suspend if device runtime suspended
- * This flag is covers that case
- */
- if (cd->irq_disabled) {
- enable_irq(cd->irq);
- cd->irq_disabled = 0;
- }
- if (device_may_wakeup(dev)) {
- pt_debug(dev, DL_WARN, "%s Device MAY wakeup\n",
- __func__);
- if (cd->irq_wake) {
- disable_irq_wake(cd->irq);
- cd->irq_wake = 0;
- }
- } else {
- pt_debug(dev, DL_WARN, "%s Device MAY NOT wakeup\n",
- __func__);
- }
- exit:
- rc = pt_core_wake(cd);
- if (rc) {
- dev_err(dev, "%s: Failed to wake up: rc=%d\n",
- __func__, rc);
- return -EAGAIN;
- }
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_core_restore
- *
- * SUMMARY: Wrapper function with device suspend/resume stratergy to call
- * pt_core_wake. This function may enable IRQ before wake up.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to core device
- ******************************************************************************/
- static int pt_core_restore(struct device *dev)
- {
- int rc = 0;
- struct pt_core_data *cd = dev_get_drvdata(dev);
- dev_info(dev, "%s: Entering into resume mode:\n",
- __func__);
- queue_work(cd->pt_workqueue, &cd->resume_offload_work);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: suspend_offload_work
- *
- * SUMMARY: Wrapper function of pt_core_suspend() to avoid TP to be waken/slept
- * along with kernel power state even the display is off based on the check of
- * TTDL core platform flag.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to core device
- ******************************************************************************/
- static void pt_suspend_offload_work(struct work_struct *work)
- {
- int rc = 0;
- struct pt_core_data *cd = container_of(work, struct pt_core_data,
- suspend_offload_work);
- pt_debug(cd->dev, DL_INFO, "%s start\n", __func__);
- if (cd->cpdata->flags & PT_CORE_FLAG_SKIP_SYS_SLEEP)
- return;
- rc = pt_core_suspend_(cd->dev);
- pt_debug(cd->dev, DL_WARN, "%s Exit - rc = %d\n", __func__, rc);
- }
- /*******************************************************************************
- * FUNCTION: resume_offload_work
- *
- * SUMMARY: Wrapper function of pt_core_resume_() to avoid TP to be waken/slept
- * along with kernel power state even the display is off based on the check of
- * TTDL core platform flag.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to core device
- ******************************************************************************/
- static void pt_resume_offload_work(struct work_struct *work)
- {
- int rc = 0;
- int retry_count = 1000;
- struct pt_core_data *pt_data = container_of(work, struct pt_core_data,
- resume_offload_work);
- pt_debug(pt_data->dev, DL_INFO, "%s start\n", __func__);
- do {
- retry_count--;
- rc = pt_core_resume_(pt_data->dev);
- if (rc < 0)
- pt_debug(pt_data->dev, DL_ERROR,
- "%s: Error on wake\n", __func__);
- } while (retry_count && rc < 0);
- if (rc < 0){
- pt_debug(pt_data->dev, DL_ERROR, "%s: Error on wake\n", __func__);
- return;
- }
- #ifdef TOUCH_TO_WAKE_POWER_FEATURE_WORK_AROUND
- rc = pt_core_easywake_on(pt_data);
- if (rc < 0) {
- pt_debug(pt_data->dev, DL_ERROR,
- "%s: Error on enable touch to wake key\n",
- __func__);
- return;
- }
- pt_data->fb_state = FB_OFF;
- pt_debug(pt_data->dev, DL_INFO, "%s End\n", __func__);
- #endif
- pt_data->quick_boot = false;
- pt_debug(pt_data->dev, DL_INFO, "%s Exit\n", __func__);
- }
- /*******************************************************************************
- * FUNCTION: pt_core_resume
- *
- * SUMMARY: Wrapper function of pt_core_resume_() to avoid TP to be waken/slept
- * along with kernel power state even the display is off based on the check of
- * TTDL core platform flag.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to core device
- ******************************************************************************/
- static int pt_core_resume(struct device *dev)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- int rc = 0;
- if (cd->drv_debug_suspend || (cd->cpdata->flags & PT_CORE_FLAG_SKIP_SYS_SLEEP))
- return 0;
- if (pm_suspend_via_firmware() || cd->touch_offload) {
- rc = pt_core_restore(cd->dev);
- } else {
- pt_debug(cd->dev, DL_INFO, "%s start\n", __func__);
- rc = pt_enable_i2c_regulator(cd, true);
- pt_debug(cd->dev, DL_INFO, "%s i2c regulator rc %d\n", __func__, rc);
- }
- mutex_lock(&cd->system_lock);
- cd->wait_until_wake = 1;
- mutex_unlock(&cd->system_lock);
- wake_up(&cd->wait_q);
- pt_debug(cd->dev, DL_INFO, "%s End rc = %d\n", __func__, rc);
- return rc;
- }
- #endif
- #ifdef NEED_SUSPEND_NOTIFIER
- /*******************************************************************************
- * FUNCTION: pt_pm_notifier
- *
- * SUMMARY: This function is registered to notifier chain and will perform
- * suspend operation if match event PM_SUSPEND_PREPARE.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *nb - pointer to notifier_block structure
- * action - notifier event type
- * *data - void pointer
- ******************************************************************************/
- static int pt_pm_notifier(struct notifier_block *nb,
- unsigned long action, void *data)
- {
- struct pt_core_data *cd = container_of(nb,
- struct pt_core_data, pm_notifier);
- if (action == PM_SUSPEND_PREPARE) {
- pt_debug(cd->dev, DL_INFO, "%s: Suspend prepare\n",
- __func__);
- /*
- * If PM runtime is not suspended, either call runtime
- * PM suspend callback or wait until it finishes
- */
- if (!pm_runtime_suspended(cd->dev))
- pm_runtime_suspend(cd->dev);
- (void) pt_core_suspend(cd->dev);
- }
- return NOTIFY_DONE;
- }
- #endif
- const struct dev_pm_ops pt_pm_ops = {
- SET_SYSTEM_SLEEP_PM_OPS(pt_core_suspend, pt_core_resume)
- .freeze = pt_core_suspend,
- .restore = pt_core_restore,
- SET_RUNTIME_PM_OPS(pt_core_rt_suspend, pt_core_rt_resume,
- NULL)
- };
- EXPORT_SYMBOL_GPL(pt_pm_ops);
- /*******************************************************************************
- * FUNCTION: _pt_request_pip2_enter_bl
- *
- * SUMMARY: Force the DUT to enter the BL by resetting the DUT by use of the
- * XRES pin or a soft reset.
- *
- * NOTE: The WD MUST be stopped/restarted by the calling Function. Having
- * the WD active could cause this function to fail!
- * NOTE: If start_mode is passed in as PT_MODE_IGNORE, this function
- * will not try to determine the current mode but will proceed with
- * resetting the DUT and entering the BL.
- *
- * NOTE: The definition of result code:
- * PT_ENTER_BL_PASS (0)
- * PT_ENTER_BL_ERROR (1)
- * PT_ENTER_BL_RESET_FAIL (2)
- * PT_ENTER_BL_HID_START_BL_FAIL (3)
- * PT_ENTER_BL_CONFIRM_FAIL (4)
- * PT_ENTER_BL_GET_FLASH_INFO_FAIL (5)
- *
- * RETURNS:
- * 0 = success
- * !0 = failure
- *
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *start_mode - pointer to the mode the DUT was in when this function
- * starts
- * *result - pointer to store the result when to enter BL
- ******************************************************************************/
- int _pt_request_pip2_enter_bl(struct device *dev, u8 *start_mode, int *result)
- {
- int rc = 0;
- int t;
- int tmp_result = PT_ENTER_BL_ERROR;
- int flash_info_retry = 2;
- u8 mode = PT_MODE_UNKNOWN;
- u8 sys_mode = FW_SYS_MODE_UNDEFINED;
- u8 read_buf[32];
- u16 actual_read_len;
- struct pt_core_data *cd = dev_get_drvdata(dev);
- u8 host_mode_cmd[4] = {0xA5, 0xA5, 0xA5, 0xA5};
- u8 time = 0;
- u8 saved_flashless_auto_bl_mode = cd->flashless_auto_bl;
- if (cd->watchdog_enabled) {
- pt_debug(dev, DL_WARN,
- "%s: Watchdog must be stopped before entering BL\n",
- __func__);
- goto exit;
- }
- cancel_work_sync(&cd->enum_work);
- cancel_work_sync(&cd->watchdog_work);
- /* if undefined assume operational/test to bypass all checks */
- if (*start_mode == PT_MODE_IGNORE) {
- mode = PT_MODE_OPERATIONAL;
- sys_mode = FW_SYS_MODE_TEST;
- pt_debug(dev, DL_INFO, "%s: Assume Mode = %d", __func__, mode);
- } else if (*start_mode == PT_MODE_UNKNOWN) {
- rc = pt_pip2_get_mode_sysmode_(cd, &mode, &sys_mode);
- if (rc) {
- pt_debug(dev, DL_ERROR,
- "%s: Get mode failed, mode unknown\n",
- __func__);
- }
- *start_mode = mode;
- pt_debug(dev, DL_INFO, "%s: Get Mode = %d", __func__, mode);
- } else if (*start_mode == PT_MODE_OPERATIONAL) {
- /* Assume SCANNIING mode to avoid doing an extra get_mode */
- sys_mode = FW_SYS_MODE_SCANNING;
- }
- _retry:
- /* For Flashless DUTs - Suppress auto BL on next BL sentinel */
- pt_debug(dev, DL_INFO, "%s: Flashless Auto_BL - SUPPRESS\n", __func__);
- cd->flashless_auto_bl = PT_SUPPRESS_AUTO_BL;
- switch (mode) {
- case PT_MODE_UNKNOWN:
- /*
- * When the mode could not be determined the DUT could be
- * in App mode running corrupted FW or FW that is not
- * responding to the mode request, assume no communication
- * and do a hard reset
- */
- mutex_lock(&cd->system_lock);
- cd->startup_status = STARTUP_STATUS_START;
- pt_debug(dev, DL_DEBUG, "%s: Startup Status Reset\n", __func__);
- mutex_unlock(&cd->system_lock);
- rc = pt_dut_reset(cd, PT_CORE_CMD_UNPROTECTED);
- if (rc) {
- tmp_result = PT_ENTER_BL_RESET_FAIL;
- goto exit;
- }
- break;
- case PT_MODE_OPERATIONAL:
- if (sys_mode == FW_SYS_MODE_SCANNING) {
- pt_debug(dev, DL_INFO, "%s: Suspend Scanning\n",
- __func__);
- rc = pt_pip_suspend_scanning_(cd);
- if (rc) {
- /*
- * Print to log but don't exit, the FW could be
- * running but be hung or fail to respond to
- * this request
- */
- pt_debug(dev, DL_ERROR,
- "%s Suspend Scan Failed\n", __func__);
- }
- /* sleep to allow the suspend scan to be processed */
- usleep_range(1000, 2000);
- }
- mutex_lock(&cd->system_lock);
- cd->startup_status = STARTUP_STATUS_START;
- pt_debug(dev, DL_DEBUG, "%s: Startup Status Reset\n", __func__);
- mutex_unlock(&cd->system_lock);
- /* Reset device to enter the BL */
- rc = pt_dut_reset(cd, PT_CORE_CMD_UNPROTECTED);
- if (rc) {
- tmp_result = PT_ENTER_BL_RESET_FAIL;
- goto exit;
- }
- break;
- case PT_MODE_BOOTLOADER:
- /* Do nothing as we are already in the BL */
- tmp_result = PT_ENTER_BL_PASS;
- goto exit;
- default:
- /* Should NEVER get here */
- tmp_result = PT_ENTER_BL_ERROR;
- pt_debug(dev, DL_ERROR, "%s: Unknown mode code\n", __func__);
- goto exit;
- }
- if (!cd->flashless_dut &&
- (mode == PT_MODE_UNKNOWN || mode == PT_MODE_OPERATIONAL)) {
- /*
- * Sending the special "Host Mode" command will instruct the
- * BL to not execute the FW it has loaded into RAM.
- * The command must be sent within a 40ms window from releasing
- * the XRES pin. If the messages is sent too early it will NAK,
- * so keep sending it every 2ms until it is accepted by the BL.
- * A no-flash DUT does not require this command as there is no
- * FW for the BL to load and execute.
- */
- usleep_range(4000, 6000);
- pt_debug(cd->dev, DL_INFO,
- ">>> %s: Write Buffer Size[%d] Stay in BL\n",
- __func__, (int)sizeof(host_mode_cmd));
- pt_pr_buf(cd->dev, DL_DEBUG, host_mode_cmd,
- (int)sizeof(host_mode_cmd), ">>> User CMD");
- rc = 1;
- while (rc && time < 34) {
- rc = pt_adap_write_read_specific(cd, 4,
- host_mode_cmd, NULL);
- usleep_range(1800, 2000);
- time += 2;
- }
- /* Sleep to allow the BL to come up */
- usleep_range(1000, 2000);
- }
- /*
- * To avoid the case that next PIP command can be confused by BL/FW
- * sentinel's "wakeup" event, chekcing hid_reset_cmd_state which is
- * followed by "wakeup event" function can lower the failure rate.
- */
- t = wait_event_timeout(cd->wait_q,
- ((cd->startup_status != STARTUP_STATUS_START)
- && (cd->hid_reset_cmd_state == 0)),
- msecs_to_jiffies(300));
- if (IS_TMO(t)) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: TMO waiting for BL sentinel\n", __func__);
- }
- /* Check if device is now in BL mode */
- rc = pt_pip2_get_mode_sysmode_(cd, &mode, NULL);
- pt_debug(dev, DL_INFO, "%s: Mode=%d, Status=0x%04X\n", __func__, mode,
- cd->startup_status);
- if (!rc && mode == PT_MODE_BOOTLOADER) {
- pt_debug(dev, DL_INFO, "%s In bootloader mode now\n", __func__);
- mutex_lock(&cd->system_lock);
- cd->pip2_prot_active = true;
- cd->mode = PT_MODE_BOOTLOADER;
- mutex_unlock(&cd->system_lock);
- tmp_result = PT_ENTER_BL_PASS;
- } else {
- /*
- * If the device doesn't enter BL mode as expected and rc is
- * tested pass by above function pt_pip2_get_mode_sysmode_(),
- * the function should return an error code to indicate this
- * failure PT_ENTER_BL_CONFIRM_FAIL.
- */
- if (!rc)
- rc = -EINVAL;
- tmp_result = PT_ENTER_BL_CONFIRM_FAIL;
- mutex_lock(&cd->system_lock);
- cd->mode = mode;
- mutex_unlock(&cd->system_lock);
- pt_debug(dev, DL_ERROR,
- "%s ERROR: Not in BL as expected", __func__);
- }
- exit:
- if (!cd->flashless_dut && (tmp_result == PT_ENTER_BL_PASS)) {
- /* Check to get (buffered) flash information */
- rc = _pt_request_pip2_send_cmd(dev, PT_CORE_CMD_UNPROTECTED,
- PIP2_CMD_ID_FLASH_INFO, NULL, 0,
- read_buf, &actual_read_len);
- if (!rc) {
- if (read_buf[PIP2_RESP_BODY_OFFSET] == 0) {
- pt_debug(
- dev, DL_WARN,
- "%s Unavailable Manufacturer ID: 0x%02x\n",
- __func__,
- read_buf[PIP2_RESP_BODY_OFFSET]);
- /*
- * If the BL was unable to cache the correct
- * values when entering the first time due to
- * the Flash part not having been powered up
- * long enough, re-enter the BL to trigger the
- * BL to re-attempt to cache the values.
- */
- if (flash_info_retry-- > 0) {
- mode = PT_MODE_UNKNOWN;
- pt_debug(dev, DL_WARN,
- "%s Assume mode to UNKNOWN to enter BL again, retry=%d\n",
- __func__, flash_info_retry);
- goto _retry;
- } else {
- pt_debug(dev, DL_WARN,
- "%s Manufacturer ID Unknown\n",
- __func__);
- tmp_result = PT_ENTER_BL_PASS;
- }
- }
- } else {
- tmp_result = PT_ENTER_BL_GET_FLASH_INFO_FAIL;
- pt_debug(
- dev, DL_ERROR,
- "%s: Failed to send PIP2 READ_FLASH_INFO cmd\n",
- __func__);
- }
- }
- pt_debug(dev, DL_INFO, "%s Flashless Auto_BL - %s\n", __func__,
- saved_flashless_auto_bl_mode == PT_ALLOW_AUTO_BL ? "ALLOW" :
- "SUPPRESS");
- cd->flashless_auto_bl = saved_flashless_auto_bl_mode;
- if (result)
- *result = tmp_result;
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: _pt_pip2_file_open
- *
- * SUMMARY: Using the BL PIP2 commands open a file and return the file handle
- *
- * NOTE: The DUT must be in BL mode for this command to work
- *
- * RETURNS:
- * <0 = Error
- * >0 = file handle opened
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * file_no - PIP2 file number to open
- ******************************************************************************/
- int _pt_pip2_file_open(struct device *dev, u8 file_no)
- {
- int ret = 0;
- u16 status;
- u16 actual_read_len;
- u8 file_handle;
- u8 data[2];
- u8 read_buf[10];
- pt_debug(dev, DL_DEBUG, "%s: OPEN file %d\n", __func__, file_no);
- data[0] = file_no;
- ret = _pt_request_pip2_send_cmd(dev,
- PT_CORE_CMD_UNPROTECTED, PIP2_CMD_ID_FILE_OPEN,
- data, 1, read_buf, &actual_read_len);
- if (ret) {
- pt_debug(dev, DL_ERROR,
- "%s ROM BL FILE_OPEN timeout for file = %d\n",
- __func__, file_no);
- return -PIP2_RSP_ERR_NOT_OPEN;
- }
- status = read_buf[PIP2_RESP_STATUS_OFFSET];
- file_handle = read_buf[PIP2_RESP_BODY_OFFSET];
- if (ret || ((status != 0x00) && (status != 0x03)) ||
- (file_handle != file_no)) {
- pt_debug(dev, DL_ERROR,
- "%s ROM BL FILE_OPEN failure: 0x%02X for file = %d\n",
- __func__, status, file_handle);
- return -status;
- }
- return file_handle;
- }
- /*******************************************************************************
- * FUNCTION: _pt_pip2_file_close
- *
- * SUMMARY: Using the BL PIP2 commands close a file
- *
- * NOTE: The DUT must be in BL mode for this command to work
- *
- * RETURNS:
- * <0 = Error
- * >0 = file handle closed
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * file_handle - handle to the file to be closed
- ******************************************************************************/
- int _pt_pip2_file_close(struct device *dev, u8 file_handle)
- {
- int ret = 0;
- u16 status;
- u16 actual_read_len;
- u8 data[2];
- u8 read_buf[32];
- pt_debug(dev, DL_DEBUG, "%s: CLOSE file %d\n", __func__, file_handle);
- data[0] = file_handle;
- ret = _pt_request_pip2_send_cmd(dev,
- PT_CORE_CMD_UNPROTECTED, PIP2_CMD_ID_FILE_CLOSE,
- data, 1, read_buf, &actual_read_len);
- if (ret) {
- pt_debug(dev, DL_ERROR,
- "%s ROM BL FILE_CLOSE timeout for file = %d\n",
- __func__, file_handle);
- return -ETIME;
- }
- status = read_buf[PIP2_RESP_STATUS_OFFSET];
- if (status != 0x00) {
- pt_debug(dev, DL_ERROR,
- "%s ROM BL FILE_CLOSE failure: 0x%02X for file = %d\n",
- __func__, status, file_handle);
- return -status;
- }
- return file_handle;
- }
- /*******************************************************************************
- * FUNCTION: _pt_pip2_file_erase
- *
- * SUMMARY: Using the BL PIP2 commands erase a file
- *
- * NOTE: The DUT must be in BL mode for this command to work
- * NOTE: Some FLASH parts can time out while erasing one or more sectors,
- * one retry is attempted for each sector in a file.
- *
- * RETURNS:
- * <0 = Error
- * >0 = file handle closed
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * file_handle - handle to the file to be erased
- * *status - PIP2 erase status code
- ******************************************************************************/
- static int _pt_pip2_file_erase(struct device *dev, u8 file_handle, int *status)
- {
- int ret = 0;
- int max_retry = PT_PIP2_MAX_FILE_SIZE/PT_PIP2_FILE_SECTOR_SIZE;
- int retry = 1;
- u16 actual_read_len;
- u8 data[2];
- u8 read_buf[10];
- struct pt_core_data *cd = dev_get_drvdata(dev);
- pt_debug(dev, DL_DEBUG, "%s: ERASE file %d\n", __func__, file_handle);
- data[0] = file_handle;
- data[1] = PIP2_FILE_IOCTL_CODE_ERASE_FILE;
- *status = PIP2_RSP_ERR_TIMEOUT;
- /* Increase waiting time for large file erase */
- mutex_lock(&cd->system_lock);
- cd->pip_cmd_timeout = PT_PIP2_CMD_FILE_ERASE_TIMEOUT;
- mutex_unlock(&cd->system_lock);
- while (*status == PIP2_RSP_ERR_TIMEOUT && retry < max_retry) {
- ret = _pt_request_pip2_send_cmd(dev,
- PT_CORE_CMD_UNPROTECTED, PIP2_CMD_ID_FILE_IOCTL,
- data, 2, read_buf, &actual_read_len);
- if (ret)
- break;
- *status = read_buf[PIP2_RESP_STATUS_OFFSET];
- if (*status == PIP2_RSP_ERR_TIMEOUT) {
- #ifdef TTDL_DIAGNOSTICS
- cd->file_erase_timeout_count++;
- #endif
- pt_debug(dev, DL_WARN,
- "%s: ERASE timeout %d for file = %d\n",
- __func__, retry, file_handle);
- }
- retry++;
- }
- mutex_lock(&cd->system_lock);
- cd->pip_cmd_timeout = cd->pip_cmd_timeout_default;
- mutex_unlock(&cd->system_lock);
- if (ret) {
- pt_debug(dev, DL_ERROR,
- "%s ROM FILE_ERASE cmd failure: %d for file = %d\n",
- __func__, ret, file_handle);
- return -EIO;
- }
- if (*status != 0x00) {
- pt_debug(dev, DL_ERROR,
- "%s ROM FILE_ERASE failure: 0x%02X for file = %d\n",
- __func__, *status, file_handle);
- return -EIO;
- }
- return file_handle;
- }
- /*******************************************************************************
- * FUNCTION: _pt_pip2_file_read
- *
- * SUMMARY: Using the BL PIP2 commands read n bytes from a already opened file
- *
- * NOTE: The DUT must be in BL mode for this command to work
- *
- * RETURNS:
- * <0 = Error
- * >0 = number of bytes read
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * file_handle - File handle to read from
- * num_bytes - number of bytes to read
- ******************************************************************************/
- int _pt_pip2_file_read(struct device *dev, u8 file_handle, u16 num_bytes,
- u8 *read_buf)
- {
- int ret = 0;
- u16 status;
- u16 actual_read_len;
- u8 data[3];
- data[0] = file_handle;
- data[1] = (num_bytes & 0x00FF);
- data[2] = (num_bytes & 0xFF00) >> 8;
- ret = _pt_request_pip2_send_cmd(dev,
- PT_CORE_CMD_UNPROTECTED, PIP2_CMD_ID_FILE_READ,
- data, 3, read_buf, &actual_read_len);
- status = read_buf[PIP2_RESP_STATUS_OFFSET];
- if (ret || ((status != 0x00) && (status != 0x03))) {
- pt_debug(dev, DL_ERROR,
- "%s File open failure with error code = %d\n",
- __func__, status);
- return -EPERM;
- }
- ret = num_bytes;
- return ret;
- }
- /*******************************************************************************
- * FUNCTION: _pt_read_us_file
- *
- * SUMMARY: Open a user space file and read 'size' bytes into buf. If size = 0
- * then read the entire file.
- * NOTE: The file size must be less than PT_PIP2_MAX_FILE_SIZE
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *file_path - pointer to the file path
- * *buf - pointer to the buffer to store the file contents
- * *size - pointer to the size of the file
- ******************************************************************************/
- int _pt_read_us_file(struct device *dev, u8 *file_path, u8 *buf, int *size)
- {
- struct file *filp = NULL;
- struct inode *inode = NULL;
- unsigned int file_len = 0;
- unsigned int read_len = 0;
- mm_segment_t oldfs;
- int rc = 0;
- if (file_path == NULL || buf == NULL) {
- pt_debug(dev, DL_ERROR, "%s: path || buf is NULL.\n", __func__);
- return -EINVAL;
- }
- pt_debug(dev, DL_WARN, "%s: path = %s\n", __func__, file_path);
- oldfs = force_uaccess_begin();
- filp = filp_open_block(file_path, O_RDONLY, 0400);
- if (IS_ERR(filp)) {
- pt_debug(dev, DL_ERROR, "%s: Failed to open %s\n", __func__,
- file_path);
- rc = -ENOENT;
- goto err;
- }
- if (filp->f_op == NULL) {
- pt_debug(dev, DL_ERROR, "%s: File Operation Method Error\n",
- __func__);
- rc = -EINVAL;
- goto exit;
- }
- inode = filp->f_path.dentry->d_inode;
- if (inode == NULL) {
- pt_debug(dev, DL_ERROR, "%s: Get inode from filp failed\n",
- __func__);
- rc = -EINVAL;
- goto exit;
- }
- file_len = i_size_read(inode->i_mapping->host);
- if (file_len == 0) {
- pt_debug(dev, DL_ERROR, "%s: file size error,file_len = %d\n",
- __func__, file_len);
- rc = -EINVAL;
- goto exit;
- }
- if (*size == 0)
- read_len = file_len;
- else
- read_len = *size;
- if (read_len > PT_PIP2_MAX_FILE_SIZE) {
- pt_debug(dev, DL_ERROR, "%s: file size ( %d ) exception.\n",
- __func__, read_len);
- rc = -EINVAL;
- goto exit;
- }
- filp->private_data = inode->i_private;
- #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0))
- if (filp->f_op->read(filp, buf, read_len, &(filp->f_pos)) != read_len) {
- #else
- if (vfs_read(filp, buf, read_len, &(filp->f_pos)) != read_len) {
- #endif
- pt_debug(dev, DL_ERROR, "%s: file read error.\n", __func__);
- rc = -EINVAL;
- goto exit;
- }
- *size = read_len;
- exit:
- if (filp_close(filp, NULL) != 0)
- pt_debug(dev, DL_ERROR, "%s: file close error.\n", __func__);
- err:
- force_uaccess_end(oldfs);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: _pt_request_pip2_bin_hdr
- *
- * SUMMARY: Read the stored bin file header from Flash or the User Space file
- * in the case of a flashless DUT, and parse the contents
- *
- * RETURNS:
- * 0 = Success
- * !0 = Error condition
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- ******************************************************************************/
- int _pt_request_pip2_bin_hdr(struct device *dev, struct pt_bin_file_hdr *hdr)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- u8 file_handle;
- u8 read_buf[255];
- u8 hdr_len = 0;
- u8 i;
- int bytes_read;
- int read_size;
- int ret = 0;
- int rc = 0;
- bool load_hdr_struct = false;
- if (cd->flashless_dut) {
- read_size = sizeof(read_buf);
- rc = _pt_read_us_file(dev, cd->pip2_us_file_path,
- read_buf, &read_size);
- if (rc) {
- ret = rc;
- pt_debug(dev, DL_ERROR,
- "%s Failed to read fw image from US, rc=%d\n",
- __func__, rc);
- goto exit;
- }
- load_hdr_struct = true;
- hdr_len = read_buf[0];
- i = 0;
- } else {
- if (cd->mode != PT_MODE_BOOTLOADER) {
- ret = -EPERM;
- goto exit;
- }
- /* Open the bin file in Flash */
- pt_debug(dev, DL_INFO, "%s Open File 1\n", __func__);
- file_handle = _pt_pip2_file_open(dev, PIP2_FW_FILE);
- if (file_handle != PIP2_FW_FILE) {
- ret = -ENOENT;
- pt_debug(dev, DL_ERROR,
- "%s Failed to open bin file\n", __func__);
- goto exit;
- }
- /* Read the header length from the file */
- pt_debug(dev, DL_INFO, "%s Read length of header\n", __func__);
- read_size = 1;
- bytes_read = _pt_pip2_file_read(dev, file_handle, read_size,
- read_buf);
- if (bytes_read != read_size) {
- ret = -EX_ERR_FREAD;
- pt_debug(dev, DL_ERROR,
- "%s Failed to bin file header len\n", __func__);
- goto exit_close_file;
- }
- hdr_len = read_buf[PIP2_RESP_BODY_OFFSET];
- if (hdr_len == 0xFF) {
- ret = -EX_ERR_FLEN;
- pt_debug(dev, DL_ERROR,
- "%s Bin header len is invalid\n", __func__);
- goto exit_close_file;
- }
- /* Read the rest of the header from the bin file */
- pt_debug(dev, DL_INFO, "%s Read bin file header\n", __func__);
- memset(read_buf, 0, sizeof(read_buf));
- bytes_read = _pt_pip2_file_read(dev, file_handle, hdr_len,
- read_buf);
- if (bytes_read != hdr_len) {
- ret = -EX_ERR_FREAD;
- pt_debug(dev, DL_ERROR,
- "%s Failed to read bin file\n", __func__);
- goto exit_close_file;
- }
- load_hdr_struct = true;
- exit_close_file:
- /* Close the file */
- if (file_handle != _pt_pip2_file_close(dev, file_handle)) {
- ret = -EX_ERR_FCLOSE;
- pt_debug(dev, DL_ERROR,
- "%s Failed to close bin file\n", __func__);
- }
- /*
- * The length was already read so subtract 1 to make the rest of
- * the offsets match the spec
- */
- i = PIP2_RESP_BODY_OFFSET - 1;
- }
- if (load_hdr_struct) {
- hdr->length = hdr_len;
- hdr->ttpid = (read_buf[i+1] << 8) | read_buf[i+2];
- hdr->fw_major = (read_buf[i+3]);
- hdr->fw_minor = (read_buf[i+4]);
- hdr->fw_crc = (read_buf[i+5] << 24) |
- (read_buf[i+6] << 16) |
- (read_buf[i+7] << 8) |
- (read_buf[i+8]);
- hdr->fw_rev_ctrl = (read_buf[i+9] << 24) |
- (read_buf[i+10] << 16) |
- (read_buf[i+11] << 8) |
- (read_buf[i+12]);
- hdr->si_rev = (read_buf[i+14] << 8) | (read_buf[i+13]);
- hdr->si_id = (read_buf[i+16] << 8) | (read_buf[i+15]);
- hdr->config_ver = (read_buf[i+17] << 8) | (read_buf[i+18]);
- if (hdr_len >= 22) {
- hdr->hex_file_size = (read_buf[i+19] << 24) |
- (read_buf[i+20] << 16) |
- (read_buf[i+21] << 8) |
- (read_buf[i+22]);
- } else {
- hdr->hex_file_size = 0;
- }
- }
- exit:
- return ret;
- }
- /*******************************************************************************
- * FUNCTION: _pt_pip2_file_get_stats
- *
- * SUMMARY: Using the BL PIP2 commands get file information from an already
- * opened file
- *
- * NOTE: The DUT must be in BL mode for this command to work
- *
- * RETURNS:
- * !0 = Error
- * 0 = Success
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * file_handle - File handle to read from
- * *address - pointer to store address of file
- * *file_size _ pointer to store size of file
- ******************************************************************************/
- int _pt_pip2_file_get_stats(struct device *dev, u8 file_handle, u32 *address,
- u32 *file_size)
- {
- int ret = 1;
- u16 status;
- u16 actual_read_len;
- u8 data[2];
- u8 read_buf[16];
- data[0] = file_handle;
- data[1] = PIP2_FILE_IOCTL_CODE_FILE_STATS;
- ret = _pt_request_pip2_send_cmd(dev,
- PT_CORE_CMD_UNPROTECTED, PIP2_CMD_ID_FILE_IOCTL,
- data, 2, read_buf, &actual_read_len);
- status = read_buf[PIP2_RESP_STATUS_OFFSET];
- if (ret || (status != 0x00)) {
- pt_debug(dev, DL_ERROR,
- "%s ROM FILE_STATS failure: 0x%02X for file = %d, ret = %d\n",
- __func__, status, file_handle, ret);
- ret = -EIO;
- goto exit;
- }
- pt_debug(dev, DL_DEBUG,
- "%s --- FILE %d Information ---\n", __func__, file_handle);
- if (address) {
- *address = read_buf[PIP2_RESP_BODY_OFFSET] +
- (read_buf[PIP2_RESP_BODY_OFFSET + 1] << 8) +
- (read_buf[PIP2_RESP_BODY_OFFSET + 2] << 16) +
- (read_buf[PIP2_RESP_BODY_OFFSET + 3] << 24);
- pt_debug(dev, DL_DEBUG, "%s Address: 0x%08x\n",
- __func__, *address);
- }
- if (file_size) {
- *file_size = read_buf[PIP2_RESP_BODY_OFFSET + 4] +
- (read_buf[PIP2_RESP_BODY_OFFSET + 5] << 8) +
- (read_buf[PIP2_RESP_BODY_OFFSET + 6] << 16) +
- (read_buf[PIP2_RESP_BODY_OFFSET + 7] << 24);
- pt_debug(dev, DL_DEBUG, "%s Size : 0x%08x\n",
- __func__, *file_size);
- }
- exit:
- return ret;
- }
- /*******************************************************************************
- * FUNCTION: _pt_pip2_file_seek_offset
- *
- * SUMMARY: Using the BL PIP2 commands seek read/write offset for an already
- * opened file
- *
- * NOTE: The DUT must be in BL mode for this command to work
- * NOTE: File open/erase command can reset the offset
- *
- * RETURNS:
- * !0 = Error
- * 0 = Success
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * file_handle - File handle to read from
- * read_offset - read offset of file
- * write_offset - write offset of file
- ******************************************************************************/
- int _pt_pip2_file_seek_offset(struct device *dev, u8 file_handle,
- u32 read_offset, u32 write_offset)
- {
- int ret = 1;
- u16 status;
- u16 actual_read_len;
- u8 data[10];
- u8 read_buf[16];
- data[0] = file_handle;
- data[1] = PIP2_FILE_IOCTL_CODE_SEEK_POINTER;
- data[2] = 0xff & read_offset;
- data[3] = 0xff & (read_offset >> 8);
- data[4] = 0xff & (read_offset >> 16);
- data[5] = 0xff & (read_offset >> 24);
- data[6] = 0xff & write_offset;
- data[7] = 0xff & (write_offset >> 8);
- data[8] = 0xff & (write_offset >> 16);
- data[9] = 0xff & (write_offset >> 24);
- ret = _pt_request_pip2_send_cmd(dev,
- PT_CORE_CMD_UNPROTECTED, PIP2_CMD_ID_FILE_IOCTL,
- data, 10, read_buf, &actual_read_len);
- status = read_buf[PIP2_RESP_STATUS_OFFSET];
- if (ret || (status != 0x00)) {
- pt_debug(dev, DL_ERROR,
- "%s ROM FILE_SEEK failure: 0x%02X for file = %d, ret = %d\n",
- __func__, status, ret, file_handle);
- ret = -EIO;
- }
- return ret;
- }
- /*******************************************************************************
- * FUNCTION: _pt_pip2_file_crc
- *
- * SUMMARY: Using the BL PIP2 commands to calculate CRC for a file or portion of
- * the file.
- *
- * NOTE: The DUT must be in BL mode for this command to work
- * NOTE: This command only can be used for BL version 1.8 or greater.
- * BL version 1.8 added this change according to PGV-173.
- *
- * RETURNS:
- * !0 = Error
- * 0 = Success
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * file_handle - File handle to read from
- * offset - start offset for CRC calculation
- * length - number of bytes to calculate CRC over
- * read_buf - pointer to the read buffer
- ******************************************************************************/
- int _pt_pip2_file_crc(struct device *dev, u8 file_handle,
- u32 offset, u32 length, u8 *read_buf)
- {
- int rc = 1;
- u16 actual_read_len;
- u8 data[10];
- data[0] = file_handle;
- data[1] = PIP2_FILE_IOCTL_CODE_FILE_CRC;
- data[2] = 0xff & offset;
- data[3] = 0xff & (offset >> 8);
- data[4] = 0xff & (offset >> 16);
- data[5] = 0xff & (offset >> 24);
- data[6] = 0xff & length;
- data[7] = 0xff & (length >> 8);
- data[8] = 0xff & (length >> 16);
- data[9] = 0xff & (length >> 24);
- rc = _pt_request_pip2_send_cmd(dev,
- PT_CORE_CMD_UNPROTECTED, PIP2_CMD_ID_FILE_IOCTL,
- data, 10, read_buf, &actual_read_len);
- if (rc)
- pt_debug(dev, DL_ERROR,
- "%s Return FILE_CRC failure, rc = %d\n",
- __func__, rc);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_pip2_ping_test
- *
- * SUMMARY: BIST type test that uses the PIP2 PING command and ramps up the
- * optional payload from 0 bytes to max_bytes and ensures the PIP2
- * response payload matches what was sent.
- * The max payload size is 247:
- * (255 - 2 byte reg address - 4 byte header - 2 byte CRC)
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *attr - pointer to device attributes
- * *buf - pointer to output buffer
- ******************************************************************************/
- int pt_pip2_ping_test(struct device *dev, int max_bytes, int *last_packet_size)
- {
- u16 actual_read_len;
- u8 *read_buf = NULL;
- u8 *data = NULL;
- int data_offset = PIP2_RESP_STATUS_OFFSET;
- int i = 1;
- int j = 0;
- int rc = 0;
- read_buf = kzalloc(PT_MAX_PIP2_MSG_SIZE, GFP_KERNEL);
- if (!read_buf)
- goto ping_test_exit;
- data = kzalloc(PT_MAX_PIP2_MSG_SIZE, GFP_KERNEL);
- if (!data)
- goto ping_test_exit;
- /* Load data payload with an array of walking 1's */
- for (i = 0; i < 255; i++)
- data[i] = 0x01 << (i % 8);
- /* Send 'max_bytes' PING cmds using 'i' bytes as payload for each */
- for (i = 0; i <= max_bytes; i++) {
- rc = _pt_request_pip2_send_cmd(dev, PT_CORE_CMD_UNPROTECTED,
- PIP2_CMD_ID_PING, data, i, read_buf,
- &actual_read_len);
- if (rc) {
- pt_debug(dev, DL_ERROR,
- "%s: PING failed with %d byte payload\n",
- __func__, i);
- break;
- }
- /* Verify data returned matches data sent */
- for (j = 0; j < i; j++) {
- if (read_buf[data_offset + j] != data[j]) {
- pt_debug(dev, DL_DEBUG,
- "%s: PING packet size %d: sent[%d]=0x%02X recv[%d]=0x%02X\n",
- __func__, i, j, data[j], j,
- read_buf[data_offset + j]);
- goto ping_test_exit;
- }
- }
- }
- ping_test_exit:
- *last_packet_size = i - 1;
- kfree(read_buf);
- kfree(data);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: _pt_ic_parse_input_hex
- *
- * SUMMARY: Parse a char data array as space delimited hex values into
- * an int array.
- *
- * NOTE: _pt_ic_parse_input() function may have similar work while the type of
- * buffer to store data is "u32". This function is still needed by the
- * "command" sysfs node because the buffer type to store data is "u8".
- *
- * RETURN: Length of parsed data
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *buf - pointer to buffer that holds the input array to parse
- * buf_size - size of buf
- * *ic_buf - pointer to array to store parsed data
- * ic_buf_size - max size of ic_buf
- ******************************************************************************/
- static int _pt_ic_parse_input_hex(struct device *dev, const char *buf,
- size_t buf_size, u8 *ic_buf, size_t ic_buf_size)
- {
- const char *pbuf = buf;
- unsigned long value;
- char scan_buf[PT_MAX_PIP2_MSG_SIZE + 1];
- u32 i = 0;
- u32 j;
- int last = 0;
- int ret;
- pt_debug(dev, DL_DEBUG,
- "%s: pbuf=%p buf=%p size=%zu %s=%d buf=%s\n",
- __func__, pbuf, buf, buf_size, "scan buf size",
- PT_MAX_PIP2_MSG_SIZE, buf);
- while (pbuf <= (buf + buf_size)) {
- if (i >= PT_MAX_PIP2_MSG_SIZE) {
- pt_debug(dev, DL_ERROR, "%s: %s size=%d max=%d\n",
- __func__, "Max cmd size exceeded", i,
- PT_MAX_PIP2_MSG_SIZE);
- return -EINVAL;
- }
- if (i >= ic_buf_size) {
- pt_debug(dev, DL_ERROR, "%s: %s size=%d buf_size=%zu\n",
- __func__, "Buffer size exceeded", i,
- ic_buf_size);
- return -EINVAL;
- }
- while (((*pbuf == ' ') || (*pbuf == ','))
- && (pbuf < (buf + buf_size))) {
- last = *pbuf;
- pbuf++;
- }
- if (pbuf >= (buf + buf_size))
- break;
- memset(scan_buf, 0, PT_MAX_PIP2_MSG_SIZE);
- if ((last == ',') && (*pbuf == ',')) {
- pt_debug(dev, DL_ERROR, "%s: %s \",,\" not allowed.\n",
- __func__, "Invalid data format.");
- return -EINVAL;
- }
- for (j = 0; j < (PT_MAX_PIP2_MSG_SIZE - 1)
- && (pbuf < (buf + buf_size))
- && (*pbuf != ' ')
- && (*pbuf != ','); j++) {
- last = *pbuf;
- scan_buf[j] = *pbuf++;
- }
- ret = kstrtoul(scan_buf, 16, &value);
- if (ret < 0) {
- pt_debug(dev, DL_ERROR,
- "%s: %s '%s' %s%s i=%d r=%d\n", __func__,
- "Invalid data format. ", scan_buf,
- "Use \"0xHH,...,0xHH\"", " instead.",
- i, ret);
- return ret;
- }
- ic_buf[i] = value;
- pt_debug(dev, DL_DEBUG, "%s: item = %d, value = 0x%02lx",
- __func__, i, value);
- i++;
- }
- return i;
- }
- /*******************************************************************************
- * FUNCTION: _pt_ic_parse_input
- *
- * SUMMARY: Parse user sysfs input data as a space or comma delimited list of
- * hex values or dec values into an int array with the following rules:
- * 1) Hex values must have a "0x" prefix for each element or the first element
- * only
- * 2) Dec values do not have any prefix
- * 3) It is not allowed to have a mix of dec and hex values in the user input
- * string
- *
- * RETURN: Number of values parsed
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *buf - pointer to buffer that holds the input array to parse
- * buf_size - size of buf
- * *out_buf - pointer to array to store parsed data
- * out_buf_size - max size of buffer to be stored
- ******************************************************************************/
- static int _pt_ic_parse_input(struct device *dev,
- const char *buf, size_t buf_size,
- u32 *out_buf, size_t out_buf_size)
- {
- const char *pbuf = buf;
- unsigned long value;
- char scan_buf[PT_MAX_PIP2_MSG_SIZE + 1];
- u32 i = 0;
- u32 j;
- int last = 0;
- int ret = 0;
- u8 str_base = 0;
- pt_debug(dev, DL_DEBUG,
- "%s: in_buf_size=%zu out_buf_size=%zu %s=%d buf=%s\n",
- __func__, buf_size, out_buf_size, "scan buf size",
- PT_MAX_PIP2_MSG_SIZE, buf);
- while (pbuf <= (buf + buf_size)) {
- if (i >= PT_MAX_PIP2_MSG_SIZE) {
- pt_debug(dev, DL_ERROR, "%s: %s size=%d max=%d\n",
- __func__, "Max cmd size exceeded", i,
- PT_MAX_PIP2_MSG_SIZE);
- ret = -EINVAL;
- goto error;
- }
- if (i >= out_buf_size) {
- pt_debug(dev, DL_ERROR, "%s: %s size=%d buf_size=%zu\n",
- __func__, "Buffer size exceeded", i,
- out_buf_size);
- ret = -EINVAL;
- goto error;
- }
- while (((*pbuf == ' ') || (*pbuf == ','))
- && (pbuf < (buf + buf_size))) {
- last = *pbuf;
- pbuf++;
- }
- if (pbuf >= (buf + buf_size))
- break;
- memset(scan_buf, 0, PT_MAX_PIP2_MSG_SIZE);
- if ((last == ',') && (*pbuf == ',')) {
- pt_debug(dev, DL_ERROR, "%s: %s \",,\" not allowed.\n",
- __func__, "Invalid data format.");
- ret = -EINVAL;
- goto error;
- }
- for (j = 0; j < (PT_MAX_PIP2_MSG_SIZE - 1)
- && (pbuf < (buf + buf_size))
- && (*pbuf != ' ')
- && (*pbuf != ','); j++) {
- last = *pbuf;
- scan_buf[j] = *pbuf++;
- }
- if (i == 0) {
- if ((strncmp(scan_buf, "0x", 2) == 0) ||
- (strncmp(scan_buf, "0X", 2) == 0))
- str_base = 16;
- else
- str_base = 10;
- } else {
- if (((strncmp(scan_buf, "0x", 2) == 0) ||
- (strncmp(scan_buf, "0X", 2) == 0)) &&
- (str_base == 10)) {
- pt_debug(dev, DL_ERROR,
- "%s: Decimal and Heximal data mixed\n",
- __func__);
- ret = -EINVAL;
- goto error;
- }
- }
- ret = kstrtoul(scan_buf, str_base, &value);
- if (ret < 0) {
- pt_debug(dev, DL_ERROR,
- "%s: %s '%s' %s%s i=%d r=%d\n", __func__,
- "Invalid data format. ", scan_buf,
- "Use \"0xHH,...,0xHH\" or \"DD DD DD ... DD\"",
- " instead.", i, ret);
- goto error;
- }
- out_buf[i] = value;
- pt_debug(dev, DL_DEBUG, "%s: item = %d, value = 0x%02lx(%lu)",
- __func__, i, value, value);
- i++;
- }
- ret = i;
- error:
- return ret;
- }
- #ifdef TTHE_TUNER_SUPPORT
- /*******************************************************************************
- * FUNCTION: tthe_debugfs_open
- *
- * SUMMARY: Open method for tthe_tuner debugfs node. On some hosts the size of
- * PT_MAX_PRBUF_SIZE (equal to PAGE_SIZE) is not large enough to handle
- * printing a large number of fingers and sensor data without overflowing
- * the buffer. tthe_tuner needs ~4K and so the buffer is sized to some
- * even multiple of PAGE_SIZE
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *inode - file inode number
- * *filp - file pointer to debugfs file
- ******************************************************************************/
- static int tthe_debugfs_open(struct inode *inode, struct file *filp)
- {
- struct pt_core_data *cd = inode->i_private;
- u32 buf_size = PT_MAX_PRBUF_SIZE;
- filp->private_data = inode->i_private;
- if (cd->tthe_buf)
- return -EBUSY;
- while (buf_size < 4096)
- buf_size = buf_size << 1;
- pt_debug(cd->dev, DL_INFO, "%s:PT_MAX_BRBUF_SIZE=%d buf_size=%d\n",
- __func__, (int)PT_MAX_PRBUF_SIZE, (int)buf_size);
- cd->tthe_buf_size = buf_size;
- cd->tthe_buf = kzalloc(cd->tthe_buf_size, GFP_KERNEL);
- if (!cd->tthe_buf)
- return -ENOMEM;
- return 0;
- }
- /*******************************************************************************
- * FUNCTION: tthe_debugfs_close
- *
- * SUMMARY: Close method for tthe_tuner debugfs node.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *inode - file inode number
- * *filp - file pointer to debugfs file
- ******************************************************************************/
- static int tthe_debugfs_close(struct inode *inode, struct file *filp)
- {
- struct pt_core_data *cd = filp->private_data;
- filp->private_data = NULL;
- kfree(cd->tthe_buf);
- cd->tthe_buf = NULL;
- return 0;
- }
- /*******************************************************************************
- * FUNCTION: tthe_debugfs_read
- *
- * SUMMARY: Read method for tthe_tuner debugfs node. This function prints
- * tthe_buf to user buffer.
- *
- * RETURN: Size of debugfs data print
- *
- * PARAMETERS:
- * *filp - file pointer to debugfs file
- * *buf - the user space buffer to read to
- * count - the maximum number of bytes to read
- * *ppos - the current position in the buffer
- ******************************************************************************/
- static ssize_t tthe_debugfs_read(struct file *filp, char __user *buf,
- size_t count, loff_t *ppos)
- {
- struct pt_core_data *cd = filp->private_data;
- int size;
- int ret;
- static int partial_read;
- wait_event_interruptible(cd->wait_q,
- cd->tthe_buf_len != 0 || cd->tthe_exit);
- mutex_lock(&cd->tthe_lock);
- if (cd->tthe_exit) {
- mutex_unlock(&cd->tthe_lock);
- return 0;
- }
- if (count > cd->tthe_buf_len)
- size = cd->tthe_buf_len;
- else
- size = count;
- if (!size) {
- mutex_unlock(&cd->tthe_lock);
- return 0;
- }
- if (partial_read) {
- ret = copy_to_user(buf, cd->tthe_buf + partial_read, size);
- partial_read = 0;
- } else {
- ret = copy_to_user(buf, cd->tthe_buf, size);
- }
- if (size == count)
- partial_read = count;
- if (ret == size)
- return -EFAULT;
- size -= ret;
- cd->tthe_buf_len -= size;
- mutex_unlock(&cd->tthe_lock);
- *ppos += size;
- return size;
- }
- static const struct file_operations tthe_debugfs_fops = {
- .open = tthe_debugfs_open,
- .release = tthe_debugfs_close,
- .read = tthe_debugfs_read,
- };
- #endif
- static struct pt_core_nonhid_cmd _pt_core_nonhid_cmd = {
- .start_bl = _pt_request_pip_start_bl,
- .suspend_scanning = _pt_request_pip_suspend_scanning,
- .resume_scanning = _pt_request_pip_resume_scanning,
- .get_param = _pt_request_pip_get_param,
- .set_param = _pt_request_pip_set_param,
- .verify_cfg_block_crc = _pt_request_pip_verify_config_block_crc,
- .get_config_row_size = _pt_request_pip_get_config_row_size,
- .get_data_structure = _pt_request_pip_get_data_structure,
- .run_selftest = _pt_request_pip_run_selftest,
- .get_selftest_result = _pt_request_pip_get_selftest_result,
- .load_self_test_param = _pt_request_pip_load_self_test_param,
- .calibrate_idacs = _pt_request_pip_calibrate_idacs,
- .calibrate_ext = _pt_request_pip_calibrate_ext,
- .initialize_baselines = _pt_request_pip_initialize_baselines,
- .exec_panel_scan = _pt_request_pip_exec_panel_scan,
- .retrieve_panel_scan = _pt_request_pip_retrieve_panel_scan,
- .read_data_block = _pt_request_pip_read_data_block,
- .write_data_block = _pt_request_pip_write_data_block,
- .user_cmd = _pt_request_pip_user_cmd,
- .get_bl_info = _pt_request_pip_bl_get_information,
- .initiate_bl = _pt_request_pip_bl_initiate_bl,
- .launch_app = _pt_request_pip_launch_app,
- .prog_and_verify = _pt_request_pip_bl_program_and_verify,
- .verify_app_integrity = _pt_request_pip_bl_verify_app_integrity,
- .get_panel_id = _pt_request_pip_bl_get_panel_id,
- .pip2_send_cmd = _pt_request_pip2_send_cmd,
- .pip2_send_cmd_no_int = _pt_pip2_send_cmd_no_int,
- .pip2_file_open = _pt_pip2_file_open,
- .pip2_file_close = _pt_pip2_file_close,
- .pip2_file_erase = _pt_pip2_file_erase,
- .read_us_file = _pt_read_us_file,
- .manage_cal_data = _pt_manage_local_cal_data,
- .calc_crc = crc_ccitt_calculate,
- #ifdef TTDL_DIAGNOSTICS
- .pip2_file_read = _pt_pip2_file_read,
- .pip2_file_seek_offset = _pt_pip2_file_seek_offset,
- .pip2_file_get_stats = _pt_pip2_file_get_stats,
- .pip2_file_crc = _pt_pip2_file_crc,
- #endif
- };
- static struct pt_core_commands _pt_core_commands = {
- .subscribe_attention = _pt_subscribe_attention,
- .unsubscribe_attention = _pt_unsubscribe_attention,
- .request_exclusive = _pt_request_exclusive,
- .release_exclusive = _pt_release_exclusive,
- .request_reset = _pt_request_reset,
- .request_pip2_launch_app = _pt_request_pip2_launch_app,
- .request_enum = _pt_request_enum,
- .request_sysinfo = _pt_request_sysinfo,
- .request_loader_pdata = _pt_request_loader_pdata,
- .request_stop_wd = _pt_request_stop_wd,
- .request_start_wd = _pt_request_start_wd,
- .request_get_mode = _pt_request_get_mode,
- .request_active_pip_prot = _pt_request_active_pip_protocol,
- .request_pip2_get_mode_sysmode = _pt_request_pip2_get_mode_sysmode,
- .request_pip2_enter_bl = _pt_request_pip2_enter_bl,
- .request_pip2_bin_hdr = _pt_request_pip2_bin_hdr,
- .request_dut_generation = _pt_request_dut_generation,
- .request_hw_version = _pt_request_hw_version,
- .parse_sysfs_input = _pt_ic_parse_input,
- #ifdef TTHE_TUNER_SUPPORT
- .request_tthe_print = _pt_request_tthe_print,
- #endif
- #ifdef TTDL_DIAGNOSTICS
- .request_toggle_err_gpio = _pt_request_toggle_err_gpio,
- #endif
- .nonhid_cmd = &_pt_core_nonhid_cmd,
- .request_get_fw_mode = _pt_request_get_fw_sys_mode,
- };
- struct pt_core_commands *pt_get_commands(void)
- {
- return &_pt_core_commands;
- }
- EXPORT_SYMBOL_GPL(pt_get_commands);
- static DEFINE_MUTEX(core_list_lock);
- static LIST_HEAD(core_list);
- static DEFINE_MUTEX(module_list_lock);
- static LIST_HEAD(module_list);
- static int core_number;
- /*******************************************************************************
- * FUNCTION: pt_probe_module
- *
- * SUMMARY: Add the module pointer to module_node and call the probe pointer.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * *module - pointer to module structure
- ******************************************************************************/
- static int pt_probe_module(struct pt_core_data *cd,
- struct pt_module *module)
- {
- struct module_node *module_node;
- int rc = 0;
- module_node = kzalloc(sizeof(*module_node), GFP_KERNEL);
- if (!module_node)
- return -ENOMEM;
- module_node->module = module;
- mutex_lock(&cd->module_list_lock);
- list_add(&module_node->node, &cd->module_list);
- mutex_unlock(&cd->module_list_lock);
- rc = module->probe(cd->dev, &module_node->data);
- if (rc) {
- /*
- * Remove from the list when probe fails
- * in order not to call release
- */
- mutex_lock(&cd->module_list_lock);
- list_del(&module_node->node);
- mutex_unlock(&cd->module_list_lock);
- kfree(module_node);
- goto exit;
- }
- exit:
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_release_module
- *
- * SUMMARY: Call the release pointer and remove the module pointer from
- * module_list.
- *
- * PARAMETERS:
- * *cd - pointer to core data
- * *module - pointer to module structure
- ******************************************************************************/
- static void pt_release_module(struct pt_core_data *cd,
- struct pt_module *module)
- {
- struct module_node *m, *m_n;
- mutex_lock(&cd->module_list_lock);
- list_for_each_entry_safe(m, m_n, &cd->module_list, node)
- if (m->module == module) {
- module->release(cd->dev, m->data);
- list_del(&m->node);
- kfree(m);
- break;
- }
- mutex_unlock(&cd->module_list_lock);
- }
- /*******************************************************************************
- * FUNCTION: pt_probe_modules
- *
- * SUMMARY: Iterate module_list and probe each module.
- *
- * PARAMETERS:
- * *cd - pointer to core data
- ******************************************************************************/
- static void pt_probe_modules(struct pt_core_data *cd)
- {
- struct pt_module *m;
- int rc = 0;
- mutex_lock(&module_list_lock);
- list_for_each_entry(m, &module_list, node) {
- pt_debug(cd->dev, DL_ERROR, "%s: Probe module %s\n",
- __func__, m->name);
- rc = pt_probe_module(cd, m);
- if (rc)
- pt_debug(cd->dev, DL_ERROR,
- "%s: Probe fails for module %s\n",
- __func__, m->name);
- }
- mutex_unlock(&module_list_lock);
- }
- /*******************************************************************************
- * FUNCTION: pt_release_modules
- *
- * SUMMARY: Iterate module_list and remove each module.
- *
- * PARAMETERS:
- * *cd - pointer to core data
- ******************************************************************************/
- static void pt_release_modules(struct pt_core_data *cd)
- {
- struct pt_module *m;
- mutex_lock(&module_list_lock);
- list_for_each_entry(m, &module_list, node)
- pt_release_module(cd, m);
- mutex_unlock(&module_list_lock);
- }
- /*******************************************************************************
- * FUNCTION: pt_get_core_data
- *
- * SUMMARY: Iterate core_list and get core data.
- *
- * RETURN:
- * pointer to core data or null pointer if fail
- *
- * PARAMETERS:
- * *id - pointer to core id
- ******************************************************************************/
- struct pt_core_data *pt_get_core_data(char *id)
- {
- struct pt_core_data *d;
- list_for_each_entry(d, &core_list, node)
- if (!strncmp(d->core_id, id, 20))
- return d;
- return NULL;
- }
- EXPORT_SYMBOL_GPL(pt_get_core_data);
- /*******************************************************************************
- * FUNCTION: pt_add_core
- *
- * SUMMARY: Add core data to the core_list.
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- ******************************************************************************/
- static void pt_add_core(struct device *dev)
- {
- struct pt_core_data *d;
- struct pt_core_data *cd = dev_get_drvdata(dev);
- mutex_lock(&core_list_lock);
- list_for_each_entry(d, &core_list, node)
- if (d->dev == dev)
- goto unlock;
- list_add(&cd->node, &core_list);
- unlock:
- mutex_unlock(&core_list_lock);
- }
- /*******************************************************************************
- * FUNCTION: pt_del_core
- *
- * SUMMARY: Remove core data from the core_list.
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- ******************************************************************************/
- static void pt_del_core(struct device *dev)
- {
- struct pt_core_data *d, *d_n;
- mutex_lock(&core_list_lock);
- list_for_each_entry_safe(d, d_n, &core_list, node)
- if (d->dev == dev) {
- list_del(&d->node);
- goto unlock;
- }
- unlock:
- mutex_unlock(&core_list_lock);
- }
- /*******************************************************************************
- * FUNCTION: pt_register_module
- *
- * SUMMARY: Register the module to module_list and probe the module for each
- * core.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *module - pointer to module structure
- ******************************************************************************/
- int pt_register_module(struct pt_module *module)
- {
- struct pt_module *m;
- struct pt_core_data *cd;
- int rc = 0;
- if (!module || !module->probe || !module->release)
- return -EINVAL;
- mutex_lock(&module_list_lock);
- list_for_each_entry(m, &module_list, node)
- if (m == module) {
- rc = -EEXIST;
- goto unlock;
- }
- list_add(&module->node, &module_list);
- /* Probe the module for each core */
- mutex_lock(&core_list_lock);
- list_for_each_entry(cd, &core_list, node)
- pt_probe_module(cd, module);
- mutex_unlock(&core_list_lock);
- unlock:
- mutex_unlock(&module_list_lock);
- return rc;
- }
- EXPORT_SYMBOL_GPL(pt_register_module);
- /*******************************************************************************
- * FUNCTION: pt_unregister_module
- *
- * SUMMARY: Release the module for each core and remove the module from
- * module_list.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *module - pointer to module structure
- ******************************************************************************/
- void pt_unregister_module(struct pt_module *module)
- {
- struct pt_module *m, *m_n;
- struct pt_core_data *cd;
- if (!module)
- return;
- mutex_lock(&module_list_lock);
- /* Release the module for each core */
- mutex_lock(&core_list_lock);
- list_for_each_entry(cd, &core_list, node)
- pt_release_module(cd, module);
- mutex_unlock(&core_list_lock);
- list_for_each_entry_safe(m, m_n, &module_list, node)
- if (m == module) {
- list_del(&m->node);
- break;
- }
- mutex_unlock(&module_list_lock);
- }
- EXPORT_SYMBOL_GPL(pt_unregister_module);
- /*******************************************************************************
- * FUNCTION: pt_get_module_data
- *
- * SUMMARY: Get module data from module_node by module_list.
- *
- * RETURN:
- * pointer to module data
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *module - pointer to module structure
- ******************************************************************************/
- void *pt_get_module_data(struct device *dev, struct pt_module *module)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- struct module_node *m;
- void *data = NULL;
- mutex_lock(&cd->module_list_lock);
- list_for_each_entry(m, &cd->module_list, node)
- if (m->module == module) {
- data = m->data;
- break;
- }
- mutex_unlock(&cd->module_list_lock);
- return data;
- }
- EXPORT_SYMBOL(pt_get_module_data);
- #ifdef CONFIG_HAS_EARLYSUSPEND
- /*******************************************************************************
- * FUNCTION: pt_early_suspend
- *
- * SUMMARY: Android PM architecture function that will call "PT_ATTEN_SUSPEND"
- * attention list.
- *
- * PARAMETERS:
- * *h - pointer to early_suspend structure
- ******************************************************************************/
- static void pt_early_suspend(struct early_suspend *h)
- {
- struct pt_core_data *cd =
- container_of(h, struct pt_core_data, es);
- call_atten_cb(cd, PT_ATTEN_SUSPEND, 0);
- }
- /*******************************************************************************
- * FUNCTION: pt_late_resume
- *
- * SUMMARY: Android PM architecture function that will call "PT_ATTEN_RESUME"
- * attention list.
- *
- * PARAMETERS:
- * *h - pointer to early_suspend structure
- ******************************************************************************/
- static void pt_late_resume(struct early_suspend *h)
- {
- struct pt_core_data *cd =
- container_of(h, struct pt_core_data, es);
- call_atten_cb(cd, PT_ATTEN_RESUME, 0);
- }
- /*******************************************************************************
- * FUNCTION: pt_setup_early_suspend
- *
- * SUMMARY: Register early/suspend function to the system.
- *
- * PARAMETERS:
- * *cd - pointer to core data
- ******************************************************************************/
- static void pt_setup_early_suspend(struct pt_core_data *cd)
- {
- cd->es.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
- cd->es.suspend = pt_early_suspend;
- cd->es.resume = pt_late_resume;
- register_early_suspend(&cd->es);
- }
- #elif defined(CONFIG_DRM)
- static void pt_resume_work(struct work_struct *work)
- {
- struct pt_core_data *pt_data = container_of(work, struct pt_core_data,
- resume_work);
- int rc = 0;
- pt_debug(pt_data->dev, DL_INFO, "%s start ", __func__);
- if (pt_data->cpdata->flags & PT_CORE_FLAG_SKIP_RUNTIME)
- return;
- rc = pt_core_easywake_off(pt_data);
- if (rc < 0) {
- pt_debug(pt_data->dev, DL_ERROR,
- "%s: Error on wake\n", __func__);
- }
- pt_debug(pt_data->dev, DL_INFO, "%s touch to wake disabled ", __func__);
- return;
- }
- static void pt_suspend_work(struct work_struct *work)
- {
- struct pt_core_data *pt_data = container_of(work, struct pt_core_data,
- suspend_work);
- int rc = 0;
- pt_debug(pt_data->dev, DL_INFO, "%s start\n", __func__);
- if (pt_data->cpdata->flags & PT_CORE_FLAG_SKIP_RUNTIME)
- return;
- rc = pt_core_easywake_on(pt_data);
- if (rc < 0) {
- pt_debug(pt_data->dev, DL_ERROR, "%s: Error on sleep\n", __func__);
- return;
- }
- pt_debug(pt_data->dev, DL_INFO, "%s Exit touch to wake enabled\n", __func__);
- return;
- }
- #if defined(CONFIG_PANEL_NOTIFIER)
- /*******************************************************************************
- * FUNCTION: panel_event_notifier_callback
- *
- * SUMMARY: Call back function for Panel Event notifier to allow to call
- * resume/suspend attention list.
- *
- * PARAMETERS:
- * tag - type of input panel.
- * *notification - pointer to notification details.
- * *client_data - pointer to core data
- ******************************************************************************/
- static void panel_event_notifier_callback(enum panel_event_notifier_tag tag,
- struct panel_event_notification *notification, void *client_data)
- {
- struct pt_core_data *cd = client_data;
- if(!notification)
- {
- pt_debug(cd->dev,DL_INFO, "%s: Invalid notification\n", __func__);
- return;
- }
- pt_debug(cd->dev, DL_INFO, "%s: DRM notifier called!\n", __func__);
- if (cd->quick_boot || cd->drv_debug_suspend)
- goto exit;
- pt_debug(cd->dev, DL_INFO, "%s: DRM event:%d,fb_state %d",
- __func__, notification->notif_type, cd->fb_state);
- pt_debug(cd->dev, DL_INFO, "%s: DRM Power - %s - FB state %d ",
- __func__, (notification->notif_type == DRM_PANEL_EVENT_UNBLANK)?"UP":"DOWN", cd->fb_state);
- if (notification->notif_type == DRM_PANEL_EVENT_UNBLANK) {
- pt_debug(cd->dev, DL_INFO, "%s: UNBLANK!\n", __func__);
- if (notification->notif_data.early_trigger) {
- pr_err("%s: resume: event = %d, not care\n", __func__, notification->notif_type);
- pt_debug(cd->dev, DL_INFO, "%s: resume: event = %d, not care\n",
- __func__, notification->notif_type);
- } else {
- pt_debug(cd->dev, DL_INFO, "%s: Resume notifier called!\n",
- __func__);
- cancel_work_sync(&cd->resume_offload_work);
- cancel_work_sync(&cd->suspend_offload_work);
- cancel_work_sync(&cd->resume_work);
- cancel_work_sync(&cd->suspend_work);
- queue_work(cd->pt_workqueue, &cd->resume_work);
- #if defined(CONFIG_PM_SLEEP)
- pt_debug(cd->dev, DL_INFO, "%s: Resume notifier called!\n",
- __func__);
- if (cd->cpdata->flags & PT_CORE_FLAG_SKIP_RUNTIME)
- pt_core_resume_(cd->dev);
- #endif
- cd->fb_state = FB_ON;
- pt_debug(cd->dev, DL_INFO, "%s: Resume notified!\n", __func__);
- }
- } else if (notification->notif_type == DRM_PANEL_EVENT_BLANK) {
- pt_debug(cd->dev, DL_INFO, "%s: BLANK!\n", __func__);
- if (notification->notif_data.early_trigger) {
- #if defined(CONFIG_PM_SLEEP)
- pt_debug(cd->dev, DL_INFO, "%s: Suspend notifier called!\n",
- __func__);
- if (cd->cpdata->flags & PT_CORE_FLAG_SKIP_RUNTIME)
- pt_core_suspend_(cd->dev);
- #endif
- cancel_work_sync(&cd->resume_offload_work);
- cancel_work_sync(&cd->suspend_offload_work);
- cancel_work_sync(&cd->resume_work);
- cancel_work_sync(&cd->suspend_work);
- queue_work(cd->pt_workqueue, &cd->suspend_work);
- cd->fb_state = FB_OFF;
- pt_debug(cd->dev, DL_INFO, "%s: Suspend notified!\n", __func__);
- } else {
- pt_debug(cd->dev, DL_INFO, "%s: suspend: event = %d, not care\n",
- __func__, notification->notif_type);
- }
- } else if (notification->notif_type == DRM_PANEL_EVENT_BLANK_LP) {
- pt_debug(cd->dev, DL_INFO, "%s: LOWPOWER!\n", __func__);
- if (notification->notif_data.early_trigger) {
- #if defined(CONFIG_PM_SLEEP)
- pt_debug(cd->dev, DL_INFO, "%s: Suspend notifier called!\n", __func__);
- if (cd->cpdata->flags & PT_CORE_FLAG_SKIP_RUNTIME)
- pt_core_suspend_(cd->dev);
- #endif
- cancel_work_sync(&cd->resume_offload_work);
- cancel_work_sync(&cd->suspend_offload_work);
- cancel_work_sync(&cd->resume_work);
- cancel_work_sync(&cd->suspend_work);
- queue_work(cd->pt_workqueue, &cd->suspend_work);
- cd->fb_state = FB_OFF;
- pt_debug(cd->dev, DL_INFO, "%s: Suspend notified!\n", __func__);
- } else {
- pt_debug(cd->dev, DL_INFO, "%s: suspend: event = %d, not care\n",
- __func__, notification->notif_type);
- }
- } else {
- pt_debug(cd->dev, DL_INFO, "%s: DRM BLANK(%d) do not need process\n",
- __func__, notification->notif_type);
- }
- exit:
- return;
- }
- /*******************************************************************************
- * FUNCTION: pt_setup_panel_event_notifier
- *
- * SUMMARY: Set up call back function into drm notifier.
- *
- * PARAMETERS:
- * *cd - pointer to core data
- ******************************************************************************/
- static void pt_setup_panel_event_notifier(struct pt_core_data *cd)
- {
- void *cookie = NULL;
- if (!active_panel)
- pt_debug(cd->dev, DL_ERROR,
- "%s: Active panel not registered!\n", __func__);
- cd->pt_workqueue = create_singlethread_workqueue("ts_wq");
- if (!cd->pt_workqueue) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: worker thread creation failed !\n", __func__);
- }
- if (cd->pt_workqueue) {
- INIT_WORK(&cd->resume_work, pt_resume_work);
- INIT_WORK(&cd->suspend_work, pt_suspend_work);
- }
- cookie = panel_event_notifier_register(PANEL_EVENT_NOTIFICATION_PRIMARY,
- PANEL_EVENT_NOTIFIER_CLIENT_PRIMARY_TOUCH,
- active_panel,&panel_event_notifier_callback, cd);
- if (active_panel && !cookie)
- {
- pt_debug(cd->dev, DL_ERROR,
- "%s: Register notifier failed!\n", __func__);
- }
- cd->entry = cookie;
- }
- #else
- /*******************************************************************************
- * FUNCTION: drm_notifier_callback
- *
- * SUMMARY: Call back function for DRM notifier to allow to call
- * resume/suspend attention list.
- *
- * RETURN:
- * 0 = success
- *
- * PARAMETERS:
- * *self - pointer to notifier_block structure
- * event - event type of fb notifier
- * *data - pointer to fb_event structure
- ******************************************************************************/
- static int drm_notifier_callback(struct notifier_block *self,
- unsigned long event, void *data)
- {
- struct pt_core_data *cd =
- container_of(self, struct pt_core_data, fb_notifier);
- struct drm_panel_notifier *evdata = data;
- int *blank;
- pt_debug(cd->dev, DL_INFO, "%s: DRM notifier called!\n", __func__);
- if (!evdata)
- goto exit;
- if (!(event == DRM_PANEL_EARLY_EVENT_BLANK ||
- event == DRM_PANEL_EVENT_BLANK)) {
- pt_debug(cd->dev, DL_INFO, "%s: Event(%lu) do not need process\n",
- __func__, event);
- goto exit;
- }
- if (cd->quick_boot || cd->drv_debug_suspend)
- goto exit;
- blank = evdata->data;
- pt_debug(cd->dev, DL_INFO, "%s: DRM event:%lu,blank:%d fb_state %d sleep state %d ",
- __func__, event, *blank, cd->fb_state, cd->sleep_state);
- pt_debug(cd->dev, DL_INFO, "%s: DRM Power - %s - FB state %d ",
- __func__, (*blank == DRM_PANEL_BLANK_UNBLANK)?"UP":"DOWN", cd->fb_state);
- if (*blank == DRM_PANEL_BLANK_UNBLANK) {
- pt_debug(cd->dev, DL_INFO, "%s: UNBLANK!\n", __func__);
- if (event == DRM_PANEL_EARLY_EVENT_BLANK) {
- pt_debug(cd->dev, DL_INFO, "%s: resume: event = %lu, not care\n",
- __func__, event);
- } else if (event == DRM_PANEL_EVENT_BLANK) {
- if (cd->fb_state != FB_ON) {
- pt_debug(cd->dev, DL_INFO, "%s: Resume notifier called!\n",
- __func__);
- cancel_work_sync(&cd->resume_offload_work);
- cancel_work_sync(&cd->suspend_offload_work);
- cancel_work_sync(&cd->resume_work);
- cancel_work_sync(&cd->suspend_work);
- queue_work(cd->pt_workqueue, &cd->resume_work);
- #if defined(CONFIG_PM_SLEEP)
- pt_debug(cd->dev, DL_INFO, "%s: Resume notifier called!\n",
- __func__);
- if (cd->cpdata->flags & PT_CORE_FLAG_SKIP_RUNTIME)
- pt_core_resume_(cd->dev);
- #endif
- cd->fb_state = FB_ON;
- pt_debug(cd->dev, DL_INFO, "%s: Resume notified!\n", __func__);
- }
- }
- } else if (*blank == DRM_PANEL_BLANK_LP || *blank == DRM_PANEL_BLANK_POWERDOWN) {
- pt_debug(cd->dev, DL_INFO, "%s: LOWPOWER!\n", __func__);
- if (event == DRM_PANEL_EARLY_EVENT_BLANK) {
- if (cd->fb_state != FB_OFF) {
- #if defined(CONFIG_PM_SLEEP)
- pt_debug(cd->dev, DL_INFO, "%s: Suspend notifier called!\n",
- __func__);
- if (cd->cpdata->flags & PT_CORE_FLAG_SKIP_RUNTIME)
- pt_core_suspend_(cd->dev);
- #endif
- cancel_work_sync(&cd->resume_offload_work);
- cancel_work_sync(&cd->suspend_offload_work);
- cancel_work_sync(&cd->resume_work);
- cancel_work_sync(&cd->suspend_work);
- queue_work(cd->pt_workqueue, &cd->suspend_work);
- cd->fb_state = FB_OFF;
- pt_debug(cd->dev, DL_INFO, "%s: Suspend notified!\n", __func__);
- }
- } else if (event == DRM_PANEL_EVENT_BLANK) {
- pt_debug(cd->dev, DL_INFO, "%s: suspend: event = %lu, not care\n",
- __func__, event);
- }
- } else {
- pt_debug(cd->dev, DL_INFO, "%s: DRM BLANK(%d) do not need process\n",
- __func__, *blank);
- }
- exit:
- return 0;
- }
- /*******************************************************************************
- * FUNCTION: pt_setup_drm_notifier
- *
- * SUMMARY: Set up call back function into drm notifier.
- *
- * PARAMETERS:
- * *cd - pointer to core data
- ******************************************************************************/
- static void pt_setup_drm_notifier(struct pt_core_data *cd)
- {
- cd->fb_state = FB_NONE;
- cd->fb_notifier.notifier_call = drm_notifier_callback;
- pt_debug(cd->dev, DL_INFO, "%s: Setting up drm notifier\n", __func__);
- if (!active_panel)
- pt_debug(cd->dev, DL_ERROR,
- "%s: Active panel not registered!\n", __func__);
- cd->pt_workqueue = create_singlethread_workqueue("ts_wq");
- if (!cd->pt_workqueue) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: worker thread creation failed !\n", __func__);
- }
- if (cd->pt_workqueue) {
- INIT_WORK(&cd->resume_work, pt_resume_work);
- INIT_WORK(&cd->suspend_work, pt_suspend_work);
- }
- if (active_panel &&
- drm_panel_notifier_register(active_panel,
- &cd->fb_notifier) < 0)
- pt_debug(cd->dev, DL_ERROR,
- "%s: Register notifier failed!\n", __func__);
- }
- #endif
- #elif defined(CONFIG_FB)
- /*******************************************************************************
- * FUNCTION: fb_notifier_callback
- *
- * SUMMARY: Call back function for FrameBuffer notifier to allow to call
- * resume/suspend attention list.
- *
- * RETURN:
- * 0 = success
- *
- * PARAMETERS:
- * *self - pointer to notifier_block structure
- * event - event type of fb notifier
- * *data - pointer to fb_event structure
- ******************************************************************************/
- static int fb_notifier_callback(struct notifier_block *self,
- unsigned long event, void *data)
- {
- struct pt_core_data *cd =
- container_of(self, struct pt_core_data, fb_notifier);
- struct fb_event *evdata = data;
- int *blank;
- if (event != FB_EVENT_BLANK || !evdata)
- goto exit;
- blank = evdata->data;
- if (*blank == FB_BLANK_UNBLANK) {
- pt_debug(cd->dev, DL_INFO, "%s: UNBLANK!\n", __func__);
- if (cd->fb_state != FB_ON) {
- call_atten_cb(cd, PT_ATTEN_RESUME, 0);
- #if defined(CONFIG_PM_SLEEP)
- if (cd->cpdata->flags & PT_CORE_FLAG_SKIP_RUNTIME)
- pt_core_resume_(cd->dev);
- #endif
- cd->fb_state = FB_ON;
- }
- } else if (*blank == FB_BLANK_POWERDOWN) {
- pt_debug(cd->dev, DL_INFO, "%s: POWERDOWN!\n", __func__);
- if (cd->fb_state != FB_OFF) {
- #if defined(CONFIG_PM_SLEEP)
- if (cd->cpdata->flags & PT_CORE_FLAG_SKIP_RUNTIME)
- pt_core_suspend_(cd->dev);
- #endif
- call_atten_cb(cd, PT_ATTEN_SUSPEND, 0);
- cd->fb_state = FB_OFF;
- }
- }
- exit:
- return 0;
- }
- /*******************************************************************************
- * FUNCTION: pt_setup_fb_notifier
- *
- * SUMMARY: Set up call back function into fb notifier.
- *
- * PARAMETERS:
- * *cd - pointer to core data
- ******************************************************************************/
- static void pt_setup_fb_notifier(struct pt_core_data *cd)
- {
- int rc = 0;
- cd->fb_state = FB_ON;
- cd->fb_notifier.notifier_call = fb_notifier_callback;
- rc = fb_register_client(&cd->fb_notifier);
- if (rc)
- pt_debug(cd->dev, DL_ERROR,
- "Unable to register fb_notifier: %d\n", rc);
- }
- #endif
- /*******************************************************************************
- * FUNCTION: pt_watchdog_work
- *
- * SUMMARY: This is where the watchdog work is done except if the DUT is
- * sleeping then this function simply returns. If the DUT is awake the
- * first thing is to ensure the IRQ is not stuck asserted meaning that
- * somehow a response is waiting on the DUT that has not been read. If
- * this occurs the message is simply consumed. If or once the IRQ is
- * cleared, a PIP PING message is sent to the DUT and if the response
- * is received the watchdog succeeds and exits, if no response is seen
- * a startup is queued unless the maximum number of startups have already
- * been attempted, in that case a BL is attempted.
- *
- * NOTE: pt_stop_wd_timer() cannot be called within the context of this
- * work thread
- *
- * RETURN: void
- *
- * PARAMETERS:
- * *work - pointer to a work structure for the watchdog work queue
- ******************************************************************************/
- static void pt_watchdog_work(struct work_struct *work)
- {
- int rc = 0;
- struct pt_core_data *cd = container_of(work,
- struct pt_core_data, watchdog_work);
- /*
- * if found the current sleep_state is SS_SLEEPING
- * then no need to request_exclusive, directly return
- */
- if (cd->sleep_state == SS_SLEEPING)
- return;
- #ifdef TTDL_DIAGNOSTICS
- cd->watchdog_count++;
- #endif /* TTDL_DIAGNOSTICS */
- /*
- * The first WD interval was extended to allow DDI to come up.
- * If the WD interval is not the default then adjust timer to the
- * current setting. The user can override value with drv_debug sysfs.
- */
- if (cd->watchdog_interval != PT_WATCHDOG_TIMEOUT) {
- mod_timer_pending(&cd->watchdog_timer, jiffies +
- msecs_to_jiffies(cd->watchdog_interval));
- }
- if (pt_check_irq_asserted(cd)) {
- #ifdef TTDL_DIAGNOSTICS
- cd->watchdog_irq_stuck_count++;
- pt_toggle_err_gpio(cd, PT_ERR_GPIO_IRQ_STUCK);
- #endif /* TTDL_DIAGNOSTICS */
- pt_debug(cd->dev, DL_ERROR,
- "%s: TTDL WD found IRQ asserted, attempt to clear\n",
- __func__);
- pt_flush_bus(cd, PT_FLUSH_BUS_BASED_ON_LEN, NULL);
- }
- rc = request_exclusive(cd, cd->dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail get exclusive ex=%p own=%p\n",
- __func__, cd->exclusive_dev, cd->dev);
- goto queue_startup;
- }
- rc = pt_pip_null_(cd);
- if (release_exclusive(cd, cd->dev) < 0)
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail to release exclusive\n", __func__);
- queue_startup:
- if (rc) {
- #ifdef TTDL_DIAGNOSTICS
- cd->watchdog_failed_access_count++;
- pt_toggle_err_gpio(cd, PT_ERR_GPIO_EXCLUSIVE_ACCESS);
- #endif /* TTDL_DIAGNOSTICS */
- pt_debug(cd->dev, DL_ERROR,
- "%s: failed to access device in WD, retry count=%d\n",
- __func__, cd->startup_retry_count);
- /* Already tried FW upgrade because of watchdog but failed */
- if (cd->startup_retry_count > PT_WATCHDOG_RETRY_COUNT)
- return;
- if (cd->startup_retry_count++ < PT_WATCHDOG_RETRY_COUNT) {
- /*
- * Any wrapper function that trys to disable the
- * WD killing this worker cannot be called here.
- */
- rc = request_exclusive(cd, cd->dev,
- PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail get exclusive ex=%p own=%p\n",
- __func__, cd->exclusive_dev, cd->dev);
- goto exit;
- }
- cd->hw_detected = false;
- cd->startup_status = STARTUP_STATUS_START;
- pt_debug(cd->dev, DL_DEBUG,
- "%s: Startup Status Reset\n", __func__);
- rc = pt_dut_reset_and_wait(cd);
- if (release_exclusive(cd, cd->dev) < 0)
- pt_debug(cd->dev, DL_ERROR,
- "%s: fail to release exclusive\n",
- __func__);
- if (!rc) {
- cd->hw_detected = true;
- if (!cd->flashless_dut)
- pt_queue_enum(cd);
- }
- #ifdef TTDL_DIAGNOSTICS
- cd->wd_xres_count++;
- pt_debug(cd->dev, DL_ERROR,
- "%s: Comm Failed - DUT reset [#%d]\n",
- __func__, cd->wd_xres_count);
- #endif /* TTDL_DIAGNOSTICS */
- } else {
- /*
- * After trying PT_WATCHDOG_RETRY_COUNT times to
- * reset the part to regain communications, try to BL
- */
- pt_debug(cd->dev, DL_ERROR,
- "%s: WD DUT access failure, Start FW Upgrade\n",
- __func__);
- #ifdef TTDL_DIAGNOSTICS
- /*
- * When diagnostics is enabled allow TTDL to keep
- * trying to find the DUT. This allows the DUT to be
- * hot swap-able while the host stays running. In
- * production this may not be wanted as a customer
- * may have several touch drivers and any driver
- * that doesn't match the current DUT should give
- * up trying and give up using the bus.
- */
- pt_debug(cd->dev, DL_INFO,
- "%s: Resetting startup_retry_count\n",
- __func__);
- cd->startup_retry_count = 0;
- #endif /* TTDL_DIAGNOSTICS */
- /*
- * Since fw may be broken,reset sysinfo ready flag
- * to let upgrade function work.
- */
- mutex_lock(&cd->system_lock);
- cd->sysinfo.ready = false;
- mutex_unlock(&cd->system_lock);
- if (cd->active_dut_generation == DUT_UNKNOWN) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: Queue Restart\n", __func__);
- pt_queue_restart(cd);
- } else
- kthread_run(start_fw_upgrade, cd, "pt_loader");
- }
- } else {
- cd->hw_detected = true;
- if (cd->startup_status <= (STARTUP_STATUS_FW_RESET_SENTINEL |
- STARTUP_STATUS_BL_RESET_SENTINEL)) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: HW detected but not enumerated\n",
- __func__);
- pt_queue_enum(cd);
- }
- }
- exit:
- pt_start_wd_timer(cd);
- }
- #if (KERNEL_VERSION(4, 14, 0) > LINUX_VERSION_CODE)
- /*******************************************************************************
- * FUNCTION: pt_watchdog_timer
- *
- * SUMMARY: The function that is called when the WD timer expires. If the
- * watchdog work is not already busy schedule the watchdog work queue.
- *
- * RETURN: void
- *
- * PARAMETERS:
- * handle - Handle to the watchdog timer
- ******************************************************************************/
- static void pt_watchdog_timer(unsigned long handle)
- {
- struct pt_core_data *cd = (struct pt_core_data *)handle;
- if (!cd)
- return;
- pt_debug(cd->dev, DL_DEBUG, "%s: Watchdog timer triggered\n",
- __func__);
- if (!work_pending(&cd->watchdog_work))
- schedule_work(&cd->watchdog_work);
- }
- #else
- /*******************************************************************************
- * FUNCTION: pt_watchdog_timer
- *
- * SUMMARY: The function that is called when the WD timer expires. If the
- * watchdog work is not already busy schedule the watchdog work queue.
- *
- * RETURN: void
- *
- * PARAMETERS:
- * *t - Pointer to timer list
- ******************************************************************************/
- static void pt_watchdog_timer(struct timer_list *t)
- {
- struct pt_core_data *cd = from_timer(cd, t, watchdog_timer);
- if (!cd)
- return;
- pt_debug(cd->dev, DL_DEBUG, "%s: Watchdog timer triggered\n",
- __func__);
- if (!work_pending(&cd->watchdog_work))
- schedule_work(&cd->watchdog_work);
- }
- #endif
- /*******************************************************************************
- * Core sysfs show and store functions
- ******************************************************************************/
- /*******************************************************************************
- * FUNCTION: pt_hw_version_show
- *
- * SUMMARY: Gets the HW version for either PIP1.x or PIP2.x DUTS
- * Output data format: [SiliconID].[RevID FamilyID].[PanelID]
- *
- * RETURN: size of data written to sysfs node
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *attr - pointer to device attributes structure
- * *buf - pointer to print output buffer
- ******************************************************************************/
- static ssize_t pt_hw_version_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- _pt_request_hw_version(dev, cd->hw_version);
- return scnprintf(buf, PT_MAX_PRBUF_SIZE, "%s\n", cd->hw_version);
- }
- static DEVICE_ATTR(hw_version, 0444, pt_hw_version_show, NULL);
- /*******************************************************************************
- * FUNCTION: pt_drv_version_show
- *
- * SUMMARY: Show method for the drv_version sysfs node that will show the
- * TTDL version information
- *
- * RETURN: Char buffer with printed TTDL version information
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *attr - pointer to device attributes
- * *buf - pointer to output buffer
- ******************************************************************************/
- static ssize_t pt_drv_version_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- return scnprintf(buf, PT_MAX_PRBUF_SIZE,
- "Driver: %s\nVersion: %s\nDate: %s\n",
- pt_driver_core_name, pt_driver_core_version,
- pt_driver_core_date);
- }
- static DEVICE_ATTR(drv_version, 0444, pt_drv_version_show, NULL);
- static DEVICE_ATTR(drv_ver, 0444, pt_drv_version_show, NULL);
- /*******************************************************************************
- * FUNCTION: pt_fw_version_show
- *
- * SUMMARY: Show method for the fw_version sysfs node that will
- * show the firmware, bootloader and PIP version information
- *
- * RETURN: Size of printed buffer
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *attr - pointer to device attributes
- * *buf - pointer to output buffer
- ******************************************************************************/
- static ssize_t pt_fw_version_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- struct pt_ttdata *ttdata;
- int rc = 0;
- if (cd->mode == PT_MODE_OPERATIONAL)
- rc = pt_hid_output_get_sysinfo_(cd);
- pt_debug(cd->dev, DL_INFO, "%s: mode = %d sysinfo.ready = %d\n",
- __func__, cd->mode, cd->sysinfo.ready);
- if (cd->sysinfo.ready)
- ttdata = &cd->sysinfo.ttdata;
- else
- rc = -ENODATA;
- if (!rc) {
- return scnprintf(buf, strlen(buf),
- "Status: %d\n"
- "FW : %d.%d.%d\n"
- "Config: %d\n"
- "BL : %d.%d\n"
- "PIP : %d.%d\n",
- rc,
- ttdata->fw_ver_major, ttdata->fw_ver_minor,
- ttdata->revctrl,
- ttdata->fw_ver_conf,
- ttdata->bl_ver_major, ttdata->bl_ver_minor,
- ttdata->pip_ver_major, ttdata->pip_ver_minor);
- } else {
- return scnprintf(buf, strlen(buf),
- "Status: %d\n"
- "FW : n/a\n"
- "Config: n/a\n"
- "BL : n/a\n"
- "PIP : n/a\n",
- rc);
- }
- }
- static DEVICE_ATTR(fw_version, 0444, pt_fw_version_show, NULL);
- /*******************************************************************************
- * FUNCTION: pt_sysinfo_show
- *
- * SUMMARY: Show method for the sysinfo sysfs node that will
- * show all the information from get system information command.
- *
- * RETURN: Size of printed buffer
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *attr - pointer to device attributes
- * *buf - pointer to output buffer
- ******************************************************************************/
- static ssize_t pt_sysinfo_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- struct pt_sysinfo *si;
- struct pt_ttdata *ttdata = NULL;
- struct pt_sensing_conf_data *scd = NULL;
- int rc = 0;
- if (cd->mode == PT_MODE_OPERATIONAL) {
- rc = pt_hid_output_get_sysinfo_(cd);
- if (cd->sysinfo.ready) {
- si = &cd->sysinfo;
- ttdata = &si->ttdata;
- scd = &si->sensing_conf_data;
- } else
- rc = -ENODATA;
- } else
- rc = -EPERM;
- pt_debug(cd->dev, DL_INFO, "%s: mode = %d sysinfo.ready = %d\n",
- __func__, cd->mode, cd->sysinfo.ready);
- if (!rc && ttdata && scd) {
- return scnprintf(buf, strlen(buf),
- "Status: %d\n"
- "pip_ver_major: 0x%02X\n"
- "pip_ver_minor: 0x%02X\n"
- "fw_pid : 0x%04X\n"
- "fw_ver_major : 0x%02X\n"
- "fw_ver_minor : 0x%02X\n"
- "revctrl : 0x%08X\n"
- "fw_ver_conf : 0x%04X\n"
- "bl_ver_major : 0x%02X\n"
- "bl_ver_minor : 0x%02X\n"
- "jtag_id_h : 0x%04X\n"
- "jtag_id_l : 0x%04X\n"
- "mfg_id[0] : 0x%02X\n"
- "mfg_id[1] : 0x%02X\n"
- "mfg_id[2] : 0x%02X\n"
- "mfg_id[3] : 0x%02X\n"
- "mfg_id[4] : 0x%02X\n"
- "mfg_id[5] : 0x%02X\n"
- "mfg_id[6] : 0x%02X\n"
- "mfg_id[7] : 0x%02X\n"
- "post_code : 0x%04X\n"
- "electrodes_x : 0x%02X\n"
- "electrodes_y : 0x%02X\n"
- "len_x : 0x%04X\n"
- "len_y : 0x%04X\n"
- "res_x : 0x%04X\n"
- "res_y : 0x%04X\n"
- "max_z : 0x%04X\n"
- "origin_x : 0x%02X\n"
- "origin_y : 0x%02X\n"
- "panel_id : 0x%02X\n"
- "btn : 0x%02X\n"
- "scan_mode : 0x%02X\n"
- "max_num_of_tch_per_refresh_cycle: 0x%02X\n",
- rc,
- ttdata->pip_ver_major,
- ttdata->pip_ver_minor,
- ttdata->fw_pid,
- ttdata->fw_ver_major,
- ttdata->fw_ver_minor,
- ttdata->revctrl,
- ttdata->fw_ver_conf,
- ttdata->bl_ver_major,
- ttdata->bl_ver_minor,
- ttdata->jtag_id_h,
- ttdata->jtag_id_l,
- ttdata->mfg_id[0],
- ttdata->mfg_id[1],
- ttdata->mfg_id[2],
- ttdata->mfg_id[3],
- ttdata->mfg_id[4],
- ttdata->mfg_id[5],
- ttdata->mfg_id[6],
- ttdata->mfg_id[7],
- ttdata->post_code,
- scd->electrodes_x,
- scd->electrodes_y,
- scd->len_x,
- scd->len_y,
- scd->res_x,
- scd->res_y,
- scd->max_z,
- scd->origin_x,
- scd->origin_y,
- scd->panel_id,
- scd->btn,
- scd->scan_mode,
- scd->max_tch);
- } else {
- return scnprintf(buf, strlen(buf),
- "Status: %d\n",
- rc);
- }
- }
- static DEVICE_ATTR(sysinfo, 0444, pt_sysinfo_show, NULL);
- /*******************************************************************************
- * FUNCTION: pt_hw_reset_show
- *
- * SUMMARY: The show method for the hw_reset sysfs node that does a hw reset
- * by toggling the XRES line and then calls the startup function to
- * allow TTDL to re-enumerate the DUT.
- * The printed value reflects the status of the full reset/enum.
- *
- * PARAMETERS:
- * *dev - pointer to Device structure
- * *attr - pointer to the device attribute structure
- * *buf - pointer to buffer to print
- ******************************************************************************/
- static ssize_t pt_hw_reset_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- int rc = 0;
- int time = 0;
- u8 reset_status = 0;
- int t;
- struct pt_hid_desc hid_desc;
- memset(&hid_desc, 0, sizeof(hid_desc));
- /* Only allow DUT reset if no active BL in progress */
- mutex_lock(&cd->firmware_class_lock);
- mutex_lock(&cd->system_lock);
- cd->startup_state = STARTUP_NONE;
- mutex_unlock(&(cd->system_lock));
- pt_stop_wd_timer(cd);
- /* ensure no left over exclusive access is still locked */
- release_exclusive(cd, cd->dev);
- rc = pt_dut_reset(cd, PT_CORE_CMD_PROTECTED);
- if (rc) {
- mutex_unlock(&cd->firmware_class_lock);
- pt_debug(cd->dev, DL_ERROR,
- "%s: HW reset failed rc = %d\n", __func__, rc);
- goto exit_hw_reset;
- }
- reset_status |= 0x01 << 0;
- if (cd->flashless_dut) {
- mutex_unlock(&cd->firmware_class_lock);
- t = wait_event_timeout(cd->wait_q, (cd->fw_updating == true),
- msecs_to_jiffies(200));
- if (IS_TMO(t)) {
- pt_debug(dev, DL_ERROR,
- "%s: Timeout waiting for FW update",
- __func__);
- rc = -ETIME;
- goto exit_hw_reset;
- } else {
- pt_debug(dev, DL_INFO,
- "%s: ----- Wait FW Loading ----",
- __func__);
- rc = _pt_request_wait_for_enum_state(
- dev, 4000, STARTUP_STATUS_FW_RESET_SENTINEL);
- if (rc) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: No FW Sentinel detected rc = %d\n",
- __func__, rc);
- goto exit_hw_reset;
- }
- reset_status |= 0x01 << 1;
- }
- } else {
- /* Wait for any sentinel */
- rc = _pt_request_wait_for_enum_state(dev, 150,
- STARTUP_STATUS_BL_RESET_SENTINEL |
- STARTUP_STATUS_FW_RESET_SENTINEL);
- if (rc) {
- mutex_unlock(&cd->firmware_class_lock);
- pt_debug(cd->dev, DL_ERROR,
- "%s: No Sentinel detected rc = %d\n",
- __func__, rc);
- goto exit_hw_reset;
- }
- /* sleep needed to ensure no cmd is sent while DUT will NAK */
- msleep(30);
- if (cd->active_dut_generation == DUT_PIP1_ONLY) {
- rc = pt_get_hid_descriptor_(cd, &hid_desc);
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: Error on getting HID descriptor r=%d\n",
- __func__, rc);
- goto exit_hw_reset;
- }
- cd->mode = pt_get_mode(cd, &hid_desc);
- if (cd->mode == PT_MODE_BOOTLOADER)
- rc = pt_hid_output_bl_launch_app_(cd);
- } else {
- if (cd->mode == PT_MODE_BOOTLOADER)
- rc = pt_pip2_launch_app(dev,
- PT_CORE_CMD_UNPROTECTED);
- }
- if (rc) {
- mutex_unlock(&cd->firmware_class_lock);
- pt_debug(cd->dev, DL_ERROR,
- "%s: PIP launch app failed rc = %d\n",
- __func__, rc);
- goto exit_hw_reset;
- }
- mutex_unlock(&cd->firmware_class_lock);
- reset_status |= 0x01 << 1;
- msleep(20);
- if ((cd->active_dut_generation == DUT_UNKNOWN) ||
- (cd->mode != PT_MODE_OPERATIONAL))
- pt_queue_restart(cd);
- else
- pt_queue_enum(cd);
- }
- while (!(cd->startup_status & STARTUP_STATUS_COMPLETE) && time < 2000) {
- msleep(50);
- pt_debug(cd->dev, DL_INFO,
- "%s: wait %dms for 0x%04X, current enum=0x%04X\n",
- __func__, time, STARTUP_STATUS_COMPLETE,
- cd->startup_status);
- time += 50;
- }
- if (!(cd->startup_status & STARTUP_STATUS_COMPLETE)) {
- rc = -ETIME;
- goto exit_hw_reset;
- }
- pt_debug(cd->dev, DL_INFO, "%s: HW Reset complete. enum=0x%04X\n",
- __func__, cd->startup_status);
- reset_status |= 0x01 << 2;
- pt_start_wd_timer(cd);
- exit_hw_reset:
- return scnprintf(buf, strlen(buf),
- "Status: %d\n"
- "Reset Status: 0x%02X\n", rc, reset_status);
- }
- static DEVICE_ATTR(hw_reset, 0444, pt_hw_reset_show, NULL);
- /*******************************************************************************
- * FUNCTION: pt_pip2_cmd_rsp_store
- *
- * SUMMARY: This is the store method for the raw PIP2 cmd/rsp sysfs node. Any
- * raw PIP2 command echo'd to this node will be sent directly to the DUT.
- * Command byte order:
- * Byte [0] - PIP2 command ID
- * Byte [1-n] - PIP2 command payload
- *
- * RETURN: Size of passed in buffer
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *attr - pointer to device attributes
- * *buf - pointer to buffer that hold the command parameters
- * size - size of buf
- ******************************************************************************/
- static ssize_t pt_pip2_cmd_rsp_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t size)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- u16 actual_read_len;
- u8 input_data[PT_MAX_PIP2_MSG_SIZE + 1];
- u8 read_buf[PT_MAX_PIP2_MSG_SIZE + 1];
- u8 pip2_cmd_id = 0x00;
- u8 *pip2_cmd_data = NULL;
- int data_len = 0;
- int length;
- int rc = 0;
- /* clear shared data */
- mutex_lock(&cd->sysfs_lock);
- cd->raw_cmd_status = 0;
- cd->cmd_rsp_buf_len = 0;
- memset(cd->cmd_rsp_buf, 0, sizeof(cd->cmd_rsp_buf));
- mutex_unlock(&cd->sysfs_lock);
- length = _pt_ic_parse_input_hex(dev, buf, size,
- input_data, PT_MAX_PIP2_MSG_SIZE);
- if (length <= 0 || length > (PT_MAX_PIP2_MSG_SIZE - 2)) {
- pt_debug(dev, DL_ERROR, "%s: Invalid number of arguments\n",
- __func__);
- rc = -EINVAL;
- goto exit;
- }
- /* Send PIP2 command if enough data was provided */
- if (length >= 1) {
- pip2_cmd_id = input_data[0];
- pip2_cmd_data = &input_data[1];
- data_len = length - 1;
- rc = _pt_request_pip2_send_cmd(dev, PT_CORE_CMD_PROTECTED,
- pip2_cmd_id, pip2_cmd_data, data_len,
- read_buf, &actual_read_len);
- cd->raw_cmd_status = rc;
- if (rc) {
- pt_debug(dev, DL_ERROR,
- "%s: PIP2 cmd 0x%02x failed rc = %d\n",
- __func__, pip2_cmd_id, rc);
- goto exit;
- } else {
- cd->cmd_rsp_buf_len = actual_read_len;
- memcpy(cd->cmd_rsp_buf, read_buf, actual_read_len);
- pt_debug(dev, DL_ERROR,
- "%s: PIP2 actual_read_len = %d\n",
- __func__, actual_read_len);
- }
- } else {
- rc = -EINVAL;
- pt_debug(dev, DL_ERROR,
- "%s: Insufficient data provided for PIP2 cmd\n",
- __func__);
- }
- exit:
- if (rc)
- return rc;
- return size;
- }
- /*******************************************************************************
- * FUNCTION: pt_pip2_cmd_rsp_show
- *
- * SUMMARY: The show method for the raw pip2_cmd_rsp sysfs node. Any PIP2
- * response generated after using the store method of the pip2_cmd_rsp
- * sysfs node, are available to be read here.
- *
- * PARAMETERS:
- * *dev - pointer to Device structure
- * *attr - pointer to the device attribute structure
- * *buf - pointer to buffer to print
- ******************************************************************************/
- static ssize_t pt_pip2_cmd_rsp_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- int i;
- ssize_t data_len;
- int index;
- mutex_lock(&cd->sysfs_lock);
- index = scnprintf(buf, PT_MAX_PRBUF_SIZE,
- "Status: %d\n", cd->raw_cmd_status);
- if (cd->raw_cmd_status)
- goto error;
- /* Remove the CRC from the length of the response */
- data_len = cd->cmd_rsp_buf_len - 2;
- /* Start printing from the data payload */
- for (i = PIP1_RESP_COMMAND_ID_OFFSET; i < data_len; i++)
- index += scnprintf(buf + index, PT_MAX_PRBUF_SIZE - index,
- "%02X ", cd->cmd_rsp_buf[i]);
- if (data_len >= PIP1_RESP_COMMAND_ID_OFFSET) {
- index += scnprintf(buf + index, PT_MAX_PRBUF_SIZE - index,
- "\n(%zd bytes)\n",
- data_len - PIP1_RESP_COMMAND_ID_OFFSET);
- } else {
- index += scnprintf(buf + index, PT_MAX_PRBUF_SIZE - index,
- "\n(%zd bytes)\n", 0);
- }
- error:
- mutex_unlock(&cd->sysfs_lock);
- return index;
- }
- static DEVICE_ATTR(pip2_cmd_rsp, 0644, pt_pip2_cmd_rsp_show,
- pt_pip2_cmd_rsp_store);
- /*******************************************************************************
- * FUNCTION: pt_command_store
- *
- * SUMMARY: This is the store method for the raw PIP command sysfs node. Any
- * raw PIP command echo'd to this node will be sent directly to the DUT.
- * TTDL will not parse the command.
- *
- * RETURN: Size of passed in buffer
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *attr - pointer to device attributes
- * *buf - pointer to buffer that hold the command parameters
- * size - size of buf
- ******************************************************************************/
- static ssize_t pt_command_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t size)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- unsigned short crc;
- u16 actual_read_len;
- u8 input_data[PT_MAX_PIP2_MSG_SIZE + 1];
- int length;
- int len_field;
- int rc = 0;
- mutex_lock(&cd->sysfs_lock);
- cd->cmd_rsp_buf_len = 0;
- memset(cd->cmd_rsp_buf, 0, sizeof(cd->cmd_rsp_buf));
- mutex_unlock(&cd->sysfs_lock);
- length = _pt_ic_parse_input_hex(dev, buf, size,
- input_data, PT_MAX_PIP2_MSG_SIZE);
- if (length <= 0 || length > PT_MAX_PIP2_MSG_SIZE) {
- pt_debug(dev, DL_ERROR, "%s: Invalid number of arguments\n",
- __func__);
- rc = -EINVAL;
- goto pt_command_store_exit;
- }
- /* PIP2 messages begin with 01 01 */
- if (length >= 2 && input_data[0] == 0x01 && input_data[1] == 0x01) {
- cd->pip2_prot_active = 1;
- /* Override next seq tag with what was sent */
- cd->pip2_cmd_tag_seq = input_data[4] & 0x0F;
- /* For PIP2 cmd if length does not include crc, add it */
- len_field = (input_data[3] << 8) | input_data[2];
- if (len_field == length && length <= 254) {
- crc = crc_ccitt_calculate(&input_data[2],
- length - 2);
- pt_debug(dev, DL_ERROR, "%s: len=%d crc=0x%02X\n",
- __func__, length, crc);
- input_data[length] = (crc & 0xFF00) >> 8;
- input_data[length + 1] = crc & 0x00FF;
- length = length + 2;
- }
- }
- /* write PIP command to log */
- pt_pr_buf(dev, DL_INFO, input_data, length, "command_buf");
- pm_runtime_get_sync(dev);
- rc = pt_hid_output_user_cmd(cd, PT_MAX_INPUT, cd->cmd_rsp_buf,
- length, input_data, &actual_read_len);
- pm_runtime_put(dev);
- mutex_lock(&cd->sysfs_lock);
- cd->raw_cmd_status = rc;
- if (rc) {
- cd->cmd_rsp_buf_len = 0;
- pt_debug(dev, DL_ERROR, "%s: Failed to send command: %s\n",
- __func__, buf);
- } else {
- cd->cmd_rsp_buf_len = actual_read_len;
- }
- cd->pip2_prot_active = 0;
- mutex_unlock(&cd->sysfs_lock);
- pt_command_store_exit:
- if (rc)
- return rc;
- return size;
- }
- static DEVICE_ATTR(command, 0220, NULL, pt_command_store);
- /*******************************************************************************
- * FUNCTION: pt_response_show
- *
- * SUMMARY: The show method for the raw PIP response sysfs node. Any PIP
- * response generated after using the pt_command_store sysfs node, are
- * available to be read here.
- *
- * PARAMETERS:
- * *dev - pointer to Device structure
- * *attr - pointer to the device attribute structure
- * *buf - pointer to buffer to print
- ******************************************************************************/
- static ssize_t pt_response_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- int i;
- ssize_t num_read;
- int index;
- mutex_lock(&cd->sysfs_lock);
- index = scnprintf(buf, PT_MAX_PRBUF_SIZE,
- "Status: %d\n", cd->raw_cmd_status);
- if (cd->raw_cmd_status)
- goto error;
- num_read = cd->cmd_rsp_buf_len;
- for (i = 0; i < num_read; i++)
- index += scnprintf(buf + index, PT_MAX_PRBUF_SIZE - index,
- "0x%02X\n", cd->cmd_rsp_buf[i]);
- index += scnprintf(buf + index, PT_MAX_PRBUF_SIZE - index,
- "(%zd bytes)\n", num_read);
- error:
- mutex_unlock(&cd->sysfs_lock);
- return index;
- }
- static DEVICE_ATTR(response, 0444, pt_response_show, NULL);
- /*******************************************************************************
- * FUNCTION: pt_dut_debug_show
- *
- * SUMMARY: Show method for the dut_debug sysfs node. Shows what parameters
- * are available for the store method.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *attr - pointer to device attributes
- * *buf - pointer to output buffer
- ******************************************************************************/
- static ssize_t pt_dut_debug_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- ssize_t ret;
- ret = scnprintf(buf, strlen(buf),
- "Status: 0\n"
- "dut_debug sends the following commands to the DUT:\n"
- "%d %s \t- %s\n"
- "%d %s \t- %s\n"
- "%d %s \t- %s\n"
- "%d %s \t- %s\n"
- "%d %s \t- %s\n"
- "%d %s \t- %s\n"
- "%d %s \t- %s\n"
- "%d %s \t- %s\n"
- "%d %s \t- %s\n"
- "%d %s \t- %s\n"
- "%d %s \t- %s\n"
- "%d %s \t- %s\n"
- "%d %s \t- %s\n"
- "%d %s \t- %s\n"
- "%d %s \t- %s\n"
- "%d %s \t- %s\n"
- "%d %s \t- %s\n"
- ,
- PIP1_BL_CMD_ID_VERIFY_APP_INTEGRITY, "", "BL Verify APP",
- PT_DUT_DBG_HID_RESET, "", "HID Reset",
- PT_DUT_DBG_HID_SET_POWER_ON, "", "HID SET_POWER ON",
- PT_DUT_DBG_HID_SET_POWER_SLEEP, "", "HID SET_POWER SLEEP",
- PT_DUT_DBG_HID_SET_POWER_STANDBY, "", "HID SET_POWER STANDBY",
- PIP1_BL_CMD_ID_GET_INFO, "", "BL Get Info",
- PIP1_BL_CMD_ID_PROGRAM_AND_VERIFY, "", "BL Program & Verify",
- PIP1_BL_CMD_ID_LAUNCH_APP, "", "BL Launch APP",
- PIP1_BL_CMD_ID_INITIATE_BL, "", "BL Initiate BL",
- PT_DUT_DBG_PIP_SOFT_RESET, "", "PIP Soft Reset",
- PT_DUT_DBG_RESET, "", "Toggle the TP_XRES GPIO",
- PT_DUT_DBG_PIP_NULL, "", "PIP NULL (PING)",
- PT_DUT_DBG_PIP_ENTER_BL, "", "PIP enter BL",
- PT_DUT_DBG_HID_SYSINFO, "", "HID system info",
- PT_DUT_DBG_PIP_SUSPEND_SCAN, "", "Suspend Scan",
- PT_DUT_DBG_PIP_RESUME_SCAN, "", "Resume Scan",
- PT_DUT_DBG_HID_DESC, "", "Get HID Desc"
- );
- return ret;
- }
- /*******************************************************************************
- * FUNCTION: pt_drv_debug_show
- *
- * SUMMARY: Show method for the drv_debug sysfs node. Shows what parameters
- * are available for the store method.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *attr - pointer to device attributes
- * *buf - pointer to output buffer
- ******************************************************************************/
- static ssize_t pt_drv_debug_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- ssize_t ret;
- ret = scnprintf(buf, strlen(buf),
- "Status: 0\n"
- "drv_debug supports the following values:\n"
- "%d %s \t- %s\n"
- "%d %s \t- %s\n"
- "%d %s \t- %s\n"
- "%d %s \t- %s\n"
- "%d %s \t- %s\n"
- "%d %s \t- %s\n"
- "%d %s \t- %s\n"
- "%d %s \t- %s\n"
- "%d %s \t- %s\n"
- "%d %s - %s\n"
- "%d %s \t- %s\n"
- "%d %s \t- %s\n"
- #ifdef TTDL_DIAGNOSTICS
- "%d %s \t- %s\n"
- "%d %s \t- %s\n"
- "%d %s \t- %s\n"
- #endif /* TTDL_DIAGNOSTICS */
- "%d %s \t- %s\n"
- #ifdef TTDL_DIAGNOSTICS
- "%d %s \t- %s\n"
- "%d %s \t- %s\n"
- "%d %s \t- %s\n"
- "%d %s \t- %s\n"
- "%d %s \t- %s\n"
- "%d %s \t- %s\n"
- "%d %s \t- %s\n"
- "%d %s \t- %s\n"
- "%d %s \t- %s\n"
- #endif /* TTDL_DIAGNOSTICS */
- ,
- PT_DRV_DBG_SUSPEND, " ", "Suspend TTDL responding to INT",
- PT_DRV_DBG_RESUME, " ", "Resume TTDL responding to INT",
- PT_DRV_DBG_STOP_WD, " ", "Stop TTDL WD",
- PT_DRV_DBG_START_WD, " ", "Start TTDL WD",
- PT_DRV_DBG_TTHE_TUNER_EXIT, " ", "Exit TTHE Tuner Logging",
- PT_DRV_DBG_TTHE_BUF_CLEAN, " ", "Clear TTHE Tuner buffer",
- PT_DRV_DBG_CLEAR_PARM_LIST, " ", "Clear RAM Param list",
- PT_DRV_DBG_FORCE_BUS_READ, " ", "Force bus read",
- PT_DRV_DBG_CLEAR_CAL_DATA, " ", "Clear CAL Cache",
- PT_DRV_DBG_REPORT_LEVEL, "[0|1|2|3|4]", "Set TTDL Debug Level",
- PT_DRV_DBG_WATCHDOG_INTERVAL, "[n] ", "TTDL WD Interval in ms",
- PT_DRV_DBG_SHOW_TIMESTAMP, "[0|1]", "Show Timestamps"
- #ifdef TTDL_DIAGNOSTICS
- , PT_DRV_DBG_SETUP_PWR, "[0|1]", "Power DUT up/down",
- PT_DRV_DBG_GET_PUT_SYNC, "[0|1]", "Get/Put Linux Sleep",
- PT_DRV_DBG_SET_TT_DATA, "[0|1]", "Display TT_DATA"
- #endif /* TTDL_DIAGNOSTICS */
- , PT_DRV_DBG_SET_GENERATION, "[0|1|2]", "Set DUT generation"
- #ifdef TTDL_DIAGNOSTICS
- , PT_DRV_DBG_SET_BRIDGE_MODE, "[0|1]", "On/Off Bridge Mode",
- PT_DRV_DBG_SET_I2C_ADDRESS, "[0-127]", "I2C DUT Address",
- PT_DRV_DBG_SET_FLASHLESS_DUT, "[0|1]", "Flashless DUT yes/no",
- PT_DRV_DBG_SET_FORCE_SEQ, "[8-15]", "Force PIP2 Sequence #",
- PT_DRV_DBG_BL_WITH_NO_INT, "[0|1]", "BL with no INT",
- PT_DRV_DBG_CAL_CACHE_IN_HOST, "[0|1]", "CAL Cache in host",
- PT_DRV_DBG_MULTI_CHIP, "[0|1]", "Multi Chip Support",
- PT_DRV_DBG_PIP_TIMEOUT, "[100-7000]", "PIP Resp Timeout (ms)",
- PT_DRV_DBG_TTHE_HID_USB_FORMAT, "[0|1]",
- "TTHE_TUNER HID USB Format"
- #endif /* TTDL_DIAGNOSTICS */
- );
- return ret;
- }
- /*******************************************************************************
- * FUNCTION: pt_drv_debug_store
- *
- * SUMMARY: Currently the store method for both sysfs nodes: drv_debug and
- * dut_debug. Drv_debug will contain all functionality that can be run
- * without a DUT preset and is available anytime TTDL is running.
- * Dut_debug requires a DUT to be available and will only be created after
- * a DUT has been detected.
- * This function will eventually be split into two but until the overlap
- * has been depricated this function contains all commands that can be
- * used for TTDL/DUT debugging status and control.
- * All commands require at least one value to be passed in *buf with some
- * requiring two.
- *
- * RETURN: Size of passed in buffer
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *attr - pointer to device attributes
- * *buf - pointer to buffer that hold the command parameters
- * size - size of buf
- ******************************************************************************/
- static ssize_t pt_drv_debug_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t size)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- unsigned long value;
- int rc = 0;
- u8 return_data[8];
- static u8 wd_disabled;
- u32 input_data[3];
- int length;
- #ifdef TTDL_DIAGNOSTICS
- struct i2c_client *client = to_i2c_client(dev);
- unsigned short crc = 0;
- u16 cal_size;
- #endif
- input_data[0] = 0;
- input_data[1] = 0;
- /* Maximmum input is two elements */
- length = _pt_ic_parse_input(dev, buf, size,
- input_data, ARRAY_SIZE(input_data));
- if (length < 1 || length > 2) {
- pt_debug(dev, DL_ERROR, "%s: Invalid number of arguments\n",
- __func__);
- rc = -EINVAL;
- goto pt_drv_debug_store_exit;
- }
- value = input_data[0];
- if (length == 1) {
- pt_debug(dev, DL_DEBUG,
- "%s: Debug Cmd Received (id=%d)\n",
- __func__, input_data[0]);
- } else if (length == 2) {
- pt_debug(dev, DL_DEBUG,
- "%s: Debug Cmd Received (id=%d, data=%d)\n",
- __func__, input_data[0], input_data[1]);
- } else {
- pt_debug(dev, DL_DEBUG,
- "%s: Invalid arguments received\n", __func__);
- rc = -EINVAL;
- goto pt_drv_debug_store_exit;
- }
- /* Start watchdog timer command */
- if (value == PT_DRV_DBG_START_WD) {
- pt_debug(dev, DL_INFO, "%s: Cmd: Start Watchdog\n", __func__);
- wd_disabled = 0;
- cd->watchdog_force_stop = false;
- pt_start_wd_timer(cd);
- goto pt_drv_debug_store_exit;
- }
- /* Stop watchdog timer temporarily */
- pt_stop_wd_timer(cd);
- if (value == PT_DRV_DBG_STOP_WD) {
- pt_debug(dev, DL_INFO, "%s: Cmd: Stop Watchdog\n", __func__);
- wd_disabled = 1;
- cd->watchdog_force_stop = true;
- goto pt_drv_debug_store_exit;
- }
- switch (value) {
- case PT_DRV_DBG_SUSPEND: /* 4 */
- pt_debug(dev, DL_INFO, "%s: TTDL: Core Sleep\n", __func__);
- wd_disabled = 1;
- rc = pt_core_suspend_(cd->dev);
- if (rc)
- pt_debug(dev, DL_ERROR, "%s: Suspend failed rc=%d\n",
- __func__, rc);
- else {
- pt_debug(dev, DL_INFO, "%s: Suspend succeeded\n",
- __func__);
- cd->drv_debug_suspend = true;
- pt_debug(dev, DL_INFO, "%s: Debugfs flag set:\n", __func__);
- }
- break;
- case PT_DRV_DBG_RESUME: /* 5 */
- pt_debug(dev, DL_INFO, "%s: TTDL: Wake\n", __func__);
- rc = pt_core_resume_(cd->dev);
- if (rc)
- pt_debug(dev, DL_ERROR, "%s: Resume failed rc=%d\n",
- __func__, rc);
- else {
- pt_debug(dev, DL_INFO, "%s: Resume succeeded\n",
- __func__);
- cd->drv_debug_suspend = false;
- pt_debug(dev, DL_INFO, "%s: Debugfs flag reset:\n", __func__);
- }
- break;
- case PIP1_BL_CMD_ID_VERIFY_APP_INTEGRITY: /* BL - 49 */
- pt_debug(dev, DL_INFO, "%s: Cmd: verify app integ\n", __func__);
- pt_hid_output_bl_verify_app_integrity(cd, &return_data[0]);
- break;
- case PT_DUT_DBG_HID_RESET: /* 50 */
- pt_debug(dev, DL_INFO, "%s: Cmd: hid_reset\n", __func__);
- pt_hid_cmd_reset(cd);
- break;
- case PT_DUT_DBG_HID_SET_POWER_ON: /* 53 */
- pt_debug(dev, DL_INFO, "%s: Cmd: hid_set_power_on\n", __func__);
- pt_hid_cmd_set_power(cd, HID_POWER_ON);
- wd_disabled = 0;
- break;
- case PT_DUT_DBG_HID_SET_POWER_SLEEP: /* 54 */
- pt_debug(dev, DL_INFO, "%s: Cmd: hid_set_power_off\n",
- __func__);
- wd_disabled = 1;
- pt_hid_cmd_set_power(cd, HID_POWER_SLEEP);
- break;
- case PT_DUT_DBG_HID_SET_POWER_STANDBY: /* 55 */
- pt_debug(dev, DL_INFO, "%s: Cmd: hid_set_power_standby\n",
- __func__);
- wd_disabled = 1;
- pt_hid_cmd_set_power(cd, HID_POWER_STANDBY);
- break;
- case PIP1_BL_CMD_ID_GET_INFO: /* BL - 56 */
- pt_debug(dev, DL_INFO, "%s: Cmd: bl get info\n", __func__);
- pt_hid_output_bl_get_information(cd, return_data);
- break;
- case PIP1_BL_CMD_ID_PROGRAM_AND_VERIFY: /* BL - 57 */
- pt_debug(dev, DL_INFO, "%s: Cmd: program and verify\n",
- __func__);
- pt_hid_output_bl_program_and_verify(cd, 0, NULL);
- break;
- case PIP1_BL_CMD_ID_LAUNCH_APP: /* BL - 59 */
- pt_debug(dev, DL_INFO, "%s: Cmd: launch app\n", __func__);
- pt_hid_output_bl_launch_app(cd);
- break;
- case PIP1_BL_CMD_ID_INITIATE_BL: /* BL - 72 */
- pt_debug(dev, DL_INFO, "%s: Cmd: initiate bl\n", __func__);
- pt_hid_output_bl_initiate_bl(cd, 0, NULL, 0, NULL);
- break;
- case PT_DUT_DBG_PIP_SOFT_RESET: /* 97 */
- pt_debug(dev, DL_INFO, "%s: Cmd: Soft Reset\n", __func__);
- rc = pt_hw_soft_reset(cd, PT_CORE_CMD_PROTECTED);
- break;
- case PT_DUT_DBG_RESET: /* 98 */
- pt_debug(dev, DL_INFO, "%s: Cmd: Hard Reset\n", __func__);
- rc = pt_hw_hard_reset(cd);
- break;
- case PT_DUT_DBG_PIP_NULL: /* 100 */
- pt_debug(dev, DL_INFO, "%s: Cmd: Ping (null)\n", __func__);
- pt_pip_null(cd);
- break;
- case PT_DUT_DBG_PIP_ENTER_BL: /* 101 */
- pt_debug(dev, DL_INFO, "%s: Cmd: start_bootloader\n", __func__);
- rc = pt_pip_start_bootloader(cd);
- if (!rc) {
- cd->startup_status = STARTUP_STATUS_BL_RESET_SENTINEL;
- cd->mode = PT_MODE_BOOTLOADER;
- }
- break;
- case PT_DUT_DBG_HID_SYSINFO: /* 102 */
- pt_debug(dev, DL_INFO, "%s: Cmd: get_sysinfo\n", __func__);
- pt_hid_output_get_sysinfo(cd);
- break;
- case PT_DUT_DBG_PIP_SUSPEND_SCAN: /* 103 */
- pt_debug(dev, DL_INFO, "%s: Cmd: suspend_scanning\n", __func__);
- pt_pip_suspend_scanning(cd);
- break;
- case PT_DUT_DBG_PIP_RESUME_SCAN: /* 104 */
- pt_debug(dev, DL_INFO, "%s: Cmd: resume_scanning\n", __func__);
- pt_pip_resume_scanning(cd);
- break;
- #ifdef TTHE_TUNER_SUPPORT
- case PT_DRV_DBG_TTHE_TUNER_EXIT: /* 107 */
- cd->tthe_exit = 1;
- wake_up(&cd->wait_q);
- kfree(cd->tthe_buf);
- cd->tthe_buf = NULL;
- cd->tthe_exit = 0;
- break;
- case PT_DRV_DBG_TTHE_BUF_CLEAN: /* 108 */
- if (cd->tthe_buf)
- memset(cd->tthe_buf, 0, PT_MAX_PRBUF_SIZE);
- else
- pt_debug(dev, DL_INFO, "%s : tthe_buf not existed\n",
- __func__);
- break;
- #endif
- #ifdef TTDL_DIAGNOSTICS
- case PT_DUT_DBG_HID_DESC: /* 109 */
- pt_debug(dev, DL_INFO, "%s: Cmd: get_hid_desc\n", __func__);
- pt_get_hid_descriptor(cd, &cd->hid_desc);
- break;
- case PT_DRV_DBG_CLEAR_PARM_LIST: /* 110 */
- pt_debug(dev, DL_INFO, "%s: TTDL: Clear Parameter List\n",
- __func__);
- pt_erase_parameter_list(cd);
- break;
- case PT_DRV_DBG_FORCE_BUS_READ: /* 111 */
- rc = pt_read_input(cd);
- if (!rc)
- pt_parse_input(cd);
- break;
- case PT_DRV_DBG_CLEAR_CAL_DATA: /* 112 */
- rc = _pt_manage_local_cal_data(dev, PT_CAL_DATA_CLEAR,
- &cal_size, &crc);
- if (rc)
- pt_debug(dev, DL_ERROR,
- "%s: CAL Data clear failed rc=%d\n",
- __func__, rc);
- else
- pt_debug(dev, DL_INFO,
- "%s: CAL Cleared, Chip ID=0x%04X size=%d\n",
- __func__, crc, size);
- break;
- case PT_DRV_DBG_REPORT_LEVEL: /* 200 */
- mutex_lock(&cd->system_lock);
- if (input_data[1] >= 0 && input_data[1] < DL_MAX) {
- cd->debug_level = input_data[1];
- pt_debug(dev, DL_INFO, "%s: Set debug_level: %d\n",
- __func__, cd->debug_level);
- } else {
- rc = -EINVAL;
- pt_debug(dev, DL_ERROR, "%s: Invalid debug_level: %d\n",
- __func__, input_data[1]);
- }
- mutex_unlock(&(cd->system_lock));
- break;
- #endif
- case PT_DRV_DBG_WATCHDOG_INTERVAL: /* 201 */
- mutex_lock(&cd->system_lock);
- if (input_data[1] > 100) {
- cd->watchdog_interval = input_data[1];
- pt_debug(dev, DL_INFO,
- "%s: Set watchdog_ interval to: %d\n",
- __func__, cd->watchdog_interval);
- pt_start_wd_timer(cd);
- } else {
- rc = -EINVAL;
- pt_debug(dev, DL_ERROR,
- "%s: Invalid watchdog interval: %d\n",
- __func__, input_data[1]);
- }
- mutex_unlock(&(cd->system_lock));
- break;
- #ifdef TTDL_DIAGNOSTICS
- case PT_DRV_DBG_SHOW_TIMESTAMP: /* 202 */
- mutex_lock(&cd->system_lock);
- if (input_data[1] == 0) {
- cd->show_timestamp = 0;
- pt_debug(dev, DL_INFO, "%s: Disable show_timestamp\n",
- __func__);
- } else if (input_data[1] == 1) {
- cd->show_timestamp = 1;
- pt_debug(dev, DL_INFO, "%s: Enable show_timestamp\n",
- __func__);
- } else {
- rc = -EINVAL;
- pt_debug(dev, DL_ERROR,
- "%s: Invalid parameter: %d\n",
- __func__, input_data[1]);
- }
- mutex_unlock(&(cd->system_lock));
- break;
- case PT_DRV_DBG_SETUP_PWR: /* 205 */
- if (input_data[1] == 0) {
- cd->cpdata->setup_power(cd->cpdata,
- PT_MT_POWER_OFF, cd->dev);
- pt_debug(dev, DL_INFO,
- "%s: Initiate Power Off\n", __func__);
- } else if (input_data[1] == 1) {
- cd->cpdata->setup_power(cd->cpdata,
- PT_MT_POWER_ON, cd->dev);
- pt_debug(dev, DL_INFO,
- "%s: Initiate Power On\n", __func__);
- } else {
- rc = -EINVAL;
- pt_debug(dev, DL_ERROR,
- "%s: Invalid parameter: %d\n",
- __func__, input_data[1]);
- }
- break;
- case PT_DRV_DBG_GET_PUT_SYNC: /* 206 */
- if (input_data[1] == 0) {
- pm_runtime_put(dev);
- pt_debug(dev, DL_ERROR,
- "%s: Force call pm_runtime_put()\n", __func__);
- } else if (input_data[1] == 1) {
- pm_runtime_get_sync(dev);
- pt_debug(dev, DL_ERROR,
- "%s: Force call pm_runtime_get_sync()\n",
- __func__);
- } else {
- rc = -EINVAL;
- pt_debug(dev, DL_ERROR,
- "%s: WARNING: Invalid parameter: %d\n",
- __func__, input_data[1]);
- }
- break;
- case PT_DRV_DBG_SET_TT_DATA: /* 208 */
- mutex_lock(&cd->system_lock);
- if (input_data[1] == 0) {
- cd->show_tt_data = false;
- pt_debug(dev, DL_INFO,
- "%s: Disable TT_DATA\n", __func__);
- } else if (input_data[1] == 1) {
- cd->show_tt_data = true;
- pt_debug(dev, DL_INFO,
- "%s: Enable TT_DATA\n", __func__);
- } else {
- rc = -EINVAL;
- pt_debug(dev, DL_ERROR,
- "%s: Invalid parameter: %d\n",
- __func__, input_data[1]);
- }
- mutex_unlock(&(cd->system_lock));
- break;
- case PT_DRV_DBG_SET_GENERATION: /* 210 */
- if (input_data[1] == cd->active_dut_generation) {
- mutex_lock(&cd->system_lock);
- cd->set_dut_generation = true;
- mutex_unlock(&(cd->system_lock));
- } else {
- mutex_lock(&cd->system_lock);
- if (input_data[1] == 0) {
- cd->active_dut_generation = DUT_UNKNOWN;
- cd->set_dut_generation = false;
- } else if (input_data[1] == 1) {
- cd->active_dut_generation = DUT_PIP1_ONLY;
- cd->set_dut_generation = true;
- } else if (input_data[1] == 2) {
- cd->active_dut_generation = DUT_PIP2_CAPABLE;
- cd->set_dut_generation = true;
- } else {
- rc = -EINVAL;
- pt_debug(dev, DL_ERROR,
- "%s: Invalid parameter: %d\n",
- __func__, input_data[1]);
- break;
- }
- cd->startup_status = STARTUP_STATUS_START;
- pt_debug(cd->dev, DL_DEBUG,
- "%s: Startup Status Reset\n", __func__);
- mutex_unlock(&(cd->system_lock));
- pt_debug(dev, DL_INFO,
- "%s: Active DUT Generation Set to: %d\n",
- __func__, cd->active_dut_generation);
- /* Changing DUT generations full restart needed */
- pt_queue_restart(cd);
- }
- break;
- case PT_DRV_DBG_SET_BRIDGE_MODE: /* 211 */
- mutex_lock(&cd->system_lock);
- if (input_data[1] == 0) {
- cd->bridge_mode = false;
- pt_debug(dev, DL_INFO,
- "%s: Disable Bridge Mode\n", __func__);
- } else if (input_data[1] == 1) {
- cd->bridge_mode = true;
- pt_debug(dev, DL_INFO,
- "%s: Enable Bridge Mode\n", __func__);
- } else {
- rc = -EINVAL;
- pt_debug(dev, DL_ERROR, "%s: Invalid parameter: %d\n",
- __func__, input_data[1]);
- }
- mutex_unlock(&(cd->system_lock));
- break;
- case PT_DRV_DBG_SET_I2C_ADDRESS: /* 212 */
- mutex_lock(&cd->system_lock);
- /* Only a 7bit address is valid */
- if (input_data[1] >= 0 && input_data[1] <= 0x7F) {
- client->addr = input_data[1];
- pt_debug(dev, DL_INFO,
- "%s: Set I2C Address: 0x%2X\n",
- __func__, client->addr);
- } else {
- rc = -EINVAL;
- pt_debug(dev, DL_ERROR, "%s: Invalid I2C Address %d\n",
- __func__, input_data[1]);
- client->addr = 0x24;
- }
- mutex_unlock(&(cd->system_lock));
- break;
- case PT_DRV_DBG_SET_FLASHLESS_DUT: /* 213 */
- mutex_lock(&cd->system_lock);
- if (input_data[1] == 0) {
- cd->flashless_dut = 0;
- cd->flashless_auto_bl = PT_SUPPRESS_AUTO_BL;
- pt_debug(dev, DL_INFO, "%s: Disable FLAHLESS DUT\n",
- __func__);
- } else if (input_data[1] == 1) {
- cd->flashless_dut = 1;
- cd->flashless_auto_bl = PT_ALLOW_AUTO_BL;
- pt_debug(dev, DL_INFO, "%s: Enable FLAHLESS DUT\n",
- __func__);
- }
- mutex_unlock(&(cd->system_lock));
- break;
- case PT_DRV_DBG_SET_FORCE_SEQ: /* 214 */
- mutex_lock(&cd->system_lock);
- if (input_data[1] >= 0x8 && input_data[1] <= 0xF) {
- cd->force_pip2_seq = input_data[1];
- cd->pip2_cmd_tag_seq = input_data[1];
- pt_debug(dev, DL_INFO,
- "%s: Force PIP2 Seq to: 0x%02X\n",
- __func__, input_data[1]);
- } else {
- cd->force_pip2_seq = 0;
- pt_debug(dev, DL_INFO,
- "%s: Clear Forced PIP2 Seq\n", __func__);
- }
- mutex_unlock(&(cd->system_lock));
- break;
- case PT_DRV_DBG_BL_WITH_NO_INT: /* 215 */
- mutex_lock(&cd->system_lock);
- if (input_data[1] == 0) {
- cd->bl_with_no_int = 0;
- pt_debug(dev, DL_INFO, "%s: BL using IRQ\n", __func__);
- } else if (input_data[1] == 1) {
- cd->bl_with_no_int = 1;
- pt_debug(dev, DL_INFO, "%s: BL using Polling\n",
- __func__);
- } else {
- rc = -EINVAL;
- pt_debug(dev, DL_ERROR, "%s: Invalid parameter: %d\n",
- __func__, input_data[1]);
- }
- mutex_unlock(&(cd->system_lock));
- break;
- case PT_DRV_DBG_CAL_CACHE_IN_HOST: /* 216 */
- mutex_lock(&cd->system_lock);
- if (input_data[1] == 0) {
- cd->cal_cache_in_host = PT_FEATURE_DISABLE;
- pt_debug(dev, DL_INFO,
- "%s: Disable Calibration cache in host\n",
- __func__);
- } else if (input_data[1] == 1) {
- cd->cal_cache_in_host = PT_FEATURE_ENABLE;
- pt_debug(dev, DL_INFO,
- "%s: Enable Calibration cache in host\n",
- __func__);
- } else {
- rc = -EINVAL;
- pt_debug(dev, DL_ERROR, "%s: Invalid parameter: %d\n",
- __func__, input_data[1]);
- }
- mutex_unlock(&(cd->system_lock));
- break;
- case PT_DRV_DBG_MULTI_CHIP: /* 217 */
- mutex_lock(&cd->system_lock);
- if (input_data[1] == 0) {
- cd->multi_chip = PT_FEATURE_DISABLE;
- cd->ttdl_bist_select = 0x07;
- pt_debug(dev, DL_INFO,
- "%s: Disable Multi-chip support\n", __func__);
- } else if (input_data[1] == 1) {
- cd->multi_chip = PT_FEATURE_ENABLE;
- cd->ttdl_bist_select = 0x3F;
- pt_debug(dev, DL_INFO,
- "%s: Enable Multi-chip support\n", __func__);
- } else {
- rc = -EINVAL;
- pt_debug(dev, DL_ERROR, "%s: Invalid parameter: %d\n",
- __func__, input_data[1]);
- }
- mutex_unlock(&(cd->system_lock));
- break;
- case PT_DRV_DBG_SET_PANEL_ID_TYPE: /* 218 */
- mutex_lock(&cd->system_lock);
- if (input_data[1] <= 0x07) {
- cd->panel_id_support = input_data[1];
- pt_debug(dev, DL_INFO,
- "%s: Set panel_id_support to %d\n",
- __func__, cd->panel_id_support);
- } else {
- rc = -EINVAL;
- pt_debug(dev, DL_ERROR, "%s: Invalid parameter: %d\n",
- __func__, input_data[1]);
- }
- mutex_unlock(&(cd->system_lock));
- break;
- case PT_DRV_DBG_PIP_TIMEOUT: /* 219 */
- mutex_lock(&cd->system_lock);
- if (input_data[1] >= 100 && input_data[1] <= 7000) {
- /*
- * The timeout is changed for some cases so the
- * pip_cmd_timeout_default is used to retore back to
- * what the user requested as the new timeout.
- */
- cd->pip_cmd_timeout_default = input_data[1];
- cd->pip_cmd_timeout = input_data[1];
- pt_debug(dev, DL_INFO,
- "%s: PIP Timeout = %d\n", __func__,
- cd->pip_cmd_timeout_default);
- } else {
- rc = -EINVAL;
- pt_debug(dev, DL_ERROR, "%s: Invalid parameter: %d\n",
- __func__, input_data[1]);
- }
- mutex_unlock(&(cd->system_lock));
- break;
- case PT_DRV_DBG_TTHE_HID_USB_FORMAT: /* 220 */
- mutex_lock(&cd->system_lock);
- if (input_data[1] == 0) {
- cd->tthe_hid_usb_format = PT_FEATURE_DISABLE;
- pt_debug(dev, DL_INFO,
- "%s: Disable tthe_tuner HID-USB format\n",
- __func__);
- } else if (input_data[1] == 1) {
- cd->tthe_hid_usb_format = PT_FEATURE_ENABLE;
- pt_debug(dev, DL_INFO,
- "%s: Enable tthe_tuner HID-USB format\n",
- __func__);
- } else {
- rc = -EINVAL;
- pt_debug(dev, DL_ERROR, "%s: Invalid parameter: %d\n",
- __func__, input_data[1]);
- }
- mutex_unlock(&(cd->system_lock));
- break;
- #endif /* TTDL_DIAGNOSTICS */
- default:
- rc = -EINVAL;
- pt_debug(dev, DL_ERROR, "%s: Invalid value\n", __func__);
- }
- /* Enable watchdog timer */
- if (!wd_disabled)
- pt_start_wd_timer(cd);
- pt_drv_debug_store_exit:
- if (rc)
- return rc;
- return size;
- }
- static DEVICE_ATTR(drv_debug, 0644, pt_drv_debug_show,
- pt_drv_debug_store);
- /*******************************************************************************
- * FUNCTION: pt_sleep_status_show
- *
- * SUMMARY: Show method for the sleep_status sysfs node that will show the
- * sleep status as either ON or OFF
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *attr - pointer to device attributes
- * *buf - pointer to output buffer
- ******************************************************************************/
- static ssize_t pt_sleep_status_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- ssize_t ret;
- mutex_lock(&cd->system_lock);
- if (cd->sleep_state == SS_SLEEP_ON)
- ret = scnprintf(buf, PT_MAX_PRBUF_SIZE, "off\n");
- else
- ret = scnprintf(buf, PT_MAX_PRBUF_SIZE, "on\n");
- mutex_unlock(&cd->system_lock);
- return ret;
- }
- /*******************************************************************************
- * FUNCTION: pt_panel_id_show
- *
- * SUMMARY: Show method for the panel_id sysfs node that will show the
- * detected panel ID from the DUT
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *attr - pointer to device attributes
- * *buf - pointer to output buffer
- ******************************************************************************/
- static ssize_t pt_panel_id_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- ssize_t ret;
- u8 pid = PANEL_ID_NOT_ENABLED;
- int rc = 0;
- if (cd->active_dut_generation == DUT_PIP1_ONLY) {
- /*
- * The DUT should report the same panel ID from both the BL and
- * the FW unless the panel_id feature is set to only
- * PT_PANEL_ID_BY_SYS_INFO, in which case the BL is not able
- * to retrieve the panel_id.
- */
- if (cd->mode == PT_MODE_BOOTLOADER) {
- /*
- * Return the stored value if PT_PANEL_ID_BY_BL
- * is not supported while other feature exits.
- */
- if (cd->panel_id_support & PT_PANEL_ID_BY_BL) {
- rc = pt_hid_output_bl_get_panel_id_(cd, &pid);
- if (rc) {
- pt_debug(dev, DL_ERROR, "%s: %s %s\n",
- "Failed to retrieve Panel ID. ",
- "Using cached value\n",
- __func__);
- }
- }
- } else if (cd->mode == PT_MODE_OPERATIONAL) {
- if (cd->panel_id_support &
- (PT_PANEL_ID_BY_BL | PT_PANEL_ID_BY_SYS_INFO)) {
- /* For all systems sysinfo has the panel_id */
- rc = pt_hid_output_get_sysinfo(cd);
- if (!rc)
- pid =
- cd->sysinfo.sensing_conf_data.panel_id;
- pt_debug(dev, DL_ERROR,
- "%s: Gen6 FW mode rc=%d PID=0x%02X\n",
- __func__, rc, pid);
- }
- } else {
- pt_debug(dev, DL_ERROR, "%s: Active mode unknown\n",
- __func__);
- rc = -EPERM;
- }
- } else if (cd->active_dut_generation == DUT_PIP2_CAPABLE) {
- if (cd->mode == PT_MODE_BOOTLOADER) {
- if (cd->panel_id_support & PT_PANEL_ID_BY_BL) {
- rc = _pt_pip2_get_panel_id_by_gpio(cd, &pid);
- if (rc) {
- pt_debug(dev, DL_ERROR,
- "%s: BL get panel ID failed rc=%d\n",
- __func__, rc);
- }
- }
- } else if (cd->mode == PT_MODE_OPERATIONAL) {
- if (cd->panel_id_support &
- (PT_PANEL_ID_BY_BL | PT_PANEL_ID_BY_SYS_INFO)) {
- rc = pt_hid_output_get_sysinfo(cd);
- if (!rc)
- pid =
- cd->sysinfo.sensing_conf_data.panel_id;
- pt_debug(dev, DL_ERROR,
- "%s: TT/TC FW mode rc=%d PID=0x%02X\n",
- __func__, rc, pid);
- }
- } else {
- pt_debug(dev, DL_ERROR, "%s: Active mode unknown\n",
- __func__);
- rc = -EPERM;
- }
- } else {
- pt_debug(dev, DL_ERROR, "%s: Dut generation is unknown\n",
- __func__);
- rc = -EPERM;
- }
- ret = scnprintf(buf, PT_MAX_PRBUF_SIZE, "Status: %d\n0x%02X\n",
- rc, pid);
- return ret;
- }
- /*******************************************************************************
- * FUNCTION: pt_get_param_store
- *
- * SUMMARY: Store method for the get_param sysfs node. Stores what parameter
- * ID to retrieve with the show method.
- *
- * NOTE: This sysfs node is only available after a DUT has been enumerated
- *
- * RETURN: Size of passed in buffer if successful
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *attr - pointer to device attributes
- * *buf - pointer to output buffer
- * size - size of buf
- ******************************************************************************/
- static ssize_t pt_get_param_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t size)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- u32 input_data[2];
- int length;
- int rc = 0;
- /* Maximum input of one value */
- length = _pt_ic_parse_input(dev, buf, size, input_data,
- ARRAY_SIZE(input_data));
- if (length != 1) {
- pt_debug(dev, DL_ERROR, "%s: Invalid number of arguments\n",
- __func__);
- rc = -EINVAL;
- goto exit;
- }
- mutex_lock(&cd->system_lock);
- cd->get_param_id = input_data[0];
- mutex_unlock(&(cd->system_lock));
- exit:
- if (rc)
- return rc;
- return size;
- }
- /*******************************************************************************
- * FUNCTION: pt_get_param_show
- *
- * SUMMARY: Show method for the get_param sysfs node. Retrieves the
- * parameter data from the DUT based on the ID stored in the core
- * data variable "get_param_id". If the ID is invalid, the DUT cannot
- * communicate or some other error occures, an error status is returned
- * with no value following.
- * Output is in the form:
- * Status: x
- * 0xyyyyyyyy
- * The 32bit data will only follow the status code if the status == 0
- *
- * NOTE: This sysfs node is only available after a DUT has been enumerated
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *attr - pointer to device attributes
- * *buf - pointer to output buffer
- ******************************************************************************/
- static ssize_t pt_get_param_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- ssize_t ret = 0;
- int status;
- u32 value = 0;
- status = pt_pip_get_param(cd, cd->get_param_id, &value);
- if (status) {
- pt_debug(dev, DL_ERROR, "%s: %s Failed, status = %d\n",
- __func__, "pt_get_param", status);
- ret = scnprintf(buf, strlen(buf),
- "%s %d\n",
- "Status:", status);
- } else {
- pt_debug(dev, DL_DEBUG, "%s: Param [%d] = 0x%04X\n",
- __func__, cd->get_param_id, value);
- ret = scnprintf(buf, strlen(buf),
- "Status: %d\n"
- "0x%04X\n",
- status, value);
- }
- return ret;
- }
- /*******************************************************************************
- * FUNCTION: pt_ttdl_restart_show
- *
- * SUMMARY: Show method for ttdl_restart sysfs node. This node releases all
- * probed modules, calls startup() and then re-probes modules.
- *
- * RETURN: size of data written to sysfs node
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *attr - pointer to device attributes structure
- * *buf - pointer to print output buffer
- ******************************************************************************/
- static ssize_t pt_ttdl_restart_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- int t;
- int rc = 0;
- mutex_lock(&cd->system_lock);
- cd->startup_state = STARTUP_NONE;
- mutex_unlock(&(cd->system_lock));
- /* ensure no left over exclusive access is still locked */
- release_exclusive(cd, cd->dev);
- pt_queue_restart(cd);
- t = wait_event_timeout(cd->wait_q,
- (cd->startup_status >= STARTUP_STATUS_COMPLETE),
- msecs_to_jiffies(PT_REQUEST_ENUM_TIMEOUT));
- if (IS_TMO(t)) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: TMO waiting for FW sentinel\n", __func__);
- rc = -ETIME;
- }
- return scnprintf(buf, strlen(buf),
- "Status: %d\n"
- "Enum Status: 0x%04X\n", rc, cd->startup_status);
- }
- static DEVICE_ATTR(ttdl_restart, 0444, pt_ttdl_restart_show, NULL);
- /*******************************************************************************
- * FUNCTION: pt_pip2_gpio_read_show
- *
- * SUMMARY: Sends a PIP2 READ_GPIO command to the DUT and prints the
- * contents of the response to the passed in output buffer.
- *
- * RETURN: size of data written to sysfs node
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *attr - pointer to device attributes structure
- * *buf - pointer to print output buffer
- ******************************************************************************/
- static ssize_t pt_pip2_gpio_read_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- u8 status = 0;
- u32 gpio_value = 0;
- int rc = 0;
- /* This functionality is only available in the BL */
- if (cd->mode == PT_MODE_BOOTLOADER)
- rc = pt_pip2_read_gpio(dev, &status, &gpio_value);
- else
- rc = -EPERM;
- if (!rc) {
- if (status == 0)
- return scnprintf(buf, PT_MAX_PRBUF_SIZE,
- "Status: %d\n"
- "DUT GPIO Reg: 0x%08X\n",
- rc, gpio_value);
- else
- return scnprintf(buf, PT_MAX_PRBUF_SIZE,
- "Status: %d\n"
- "DUT GPIO Reg: n/a\n",
- status);
- } else
- return scnprintf(buf, PT_MAX_PRBUF_SIZE,
- "Status: %d\n"
- "DUT GPIO Reg: n/a\n",
- rc);
- }
- /*******************************************************************************
- * FUNCTION: pt_device_exit
- *
- * SUMMARY: Remove functon for the I2C module
- *
- * PARAMETERS:
- * *client - pointer to i2c client structure
- ******************************************************************************/
- #ifdef PT_AMBIENT_MODE
- static int pt_device_exit(struct i2c_client *client)
- {
- struct pt_core_data *cd = i2c_get_clientdata(client);
- struct device *dev = cd->dev;
- void *glink_pt_send_msg;
- int glink_touch_enter = TOUCH_ENTER;
- pt_debug(dev, DL_INFO,"%s: Start pt_device_exit\n", __func__);
- glink_pt_send_msg = &glink_touch_enter;
- pt_debug(dev, DL_INFO, "[touch]glink_pt_send_msg = %0x\n", glink_pt_send_msg);
- glink_touch_tx_msg(glink_pt_send_msg, TOUCH_MSG_SIZE);
- if (active_panel)
- panel_event_notifier_unregister(cd->entry);
- pt_core_state = STATE_SUSPEND;
- pm_runtime_suspend(dev);
- pm_runtime_disable(dev);
- pt_stop_wd_timer(cd);
- call_atten_cb(cd, PT_ATTEN_CANCEL_LOADER, 0);
- cancel_work_sync(&cd->ttdl_restart_work);
- cancel_work_sync(&cd->enum_work);
- cancel_work_sync(&cd->resume_offload_work);
- cancel_work_sync(&cd->suspend_offload_work);
- cancel_work_sync(&cd->resume_work);
- cancel_work_sync(&cd->suspend_work);
- pt_stop_wd_timer(cd);
- device_init_wakeup(dev, 0);
- disable_irq_nosync(cd->irq);
- if (cd->cpdata->setup_irq)
- cd->cpdata->setup_irq(cd->cpdata, PT_MT_IRQ_FREE, dev);
- if (cd->cpdata->init)
- cd->cpdata->init(cd->cpdata, PT_MT_POWER_OFF, dev);
- if (cd->cpdata->setup_power)
- cd->cpdata->setup_power(cd->cpdata, PT_MT_POWER_OFF, dev);
- pt_debug(dev, DL_INFO,"%s: End pt_device_exit \n", __func__);
- return 0;
- }
- #endif
- /*******************************************************************************
- * FUNCTION: pt_touch_offload_store
- *
- * SUMMARY: The store method for the touch_offload sysfs node that allows the TTDL
- * to be enabled/disabled.
- *
- * RETURN: Size of passed in buffer
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *attr - pointer to device attributes
- * *buf - pointer to buffer that hold the command parameters
- * size - size of buf
- ******************************************************************************/
- static ssize_t pt_touch_offload_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t size)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- struct i2c_client *client = to_i2c_client(dev);
- u32 input_data[2];
- int length;
- int rc = 0;
- /* Maximum input of one value */
- length = _pt_ic_parse_input(dev, buf, size, input_data, ARRAY_SIZE(input_data));
- if (length != 1) {
- pt_debug(dev, DL_ERROR, "%s: Invalid number of arguments\n", __func__);
- rc = -EINVAL;
- goto exit;
- }
- switch (input_data[0]) {
- case 0:
- pt_debug(dev, DL_ERROR, "%s: TTDL: Core Touch Offload OFF\n", __func__);
- cd->touch_offload = true;
- rc = pt_device_exit(client);
- if (rc)
- pt_debug(dev, DL_ERROR, "%s: Power off error detected rc=%d\n",
- __func__, rc);
- else {
- cd->touch_offload = true;
- pt_debug(dev, DL_ERROR, "%s: Debugfs PT DEVICE EXIT flag set:\n",
- __func__);
- }
- break;
- case 1:
- pt_debug(dev, DL_ERROR, "%s: TTDL: Core Touch Offload ON\n", __func__);
- rc = pt_device_entry(&client->dev, client->irq, PT_DATA_SIZE);
- if (rc)
- pt_debug(dev, DL_ERROR, "%s: Power on error detected rc=%d\n",
- __func__, rc);
- else {
- cd->touch_offload = false;
- pt_debug(dev, DL_ERROR, "%s: Debugfs PT DEVICE ENTRY flag set:\n",
- __func__);
- }
- break;
- default:
- rc = -EINVAL;
- pt_debug(dev, DL_ERROR, "%s: Invalid value\n", __func__);
- }
- exit:
- if (rc)
- return rc;
- return size;
- }
- /*******************************************************************************
- * FUNCTION: pt_touch_offload_show
- *
- * SUMMARY: The show method for the touch_offload sysfs node that allows the TTDL
- * to verify touch offload enable or disabled.
- *
- * RETURN: size of data written to sysfs node
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *attr - pointer to device attributes
- * *buf - pointer to print output buffer
- ******************************************************************************/
- static ssize_t pt_touch_offload_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- return scnprintf(buf, PT_MAX_PRBUF_SIZE,
- "Touch offload : %s\n",
- (cd->touch_offload)? "Enabled" : "Disabled");
- }
- /*******************************************************************************
- * FUNCTION: pt_pip2_version_show
- *
- * SUMMARY: Sends a PIP2 VERSION command to the DUT and prints the
- * contents of the response to the passed in output buffer.
- *
- * RETURN: size of data written to sysfs node
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *attr - pointer to device attributes structure
- * *buf - pointer to print output buffer
- ******************************************************************************/
- static ssize_t pt_pip2_version_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- int rc = 0;
- struct pt_core_data *cd = dev_get_drvdata(dev);
- struct pt_ttdata *ttdata = &cd->sysinfo.ttdata;
- rc = pt_pip2_get_version(cd);
- if (!rc) {
- return scnprintf(buf, PT_MAX_PRBUF_SIZE,
- "PIP VERSION : %02X.%02X\n"
- "BL VERSION : %02X.%02X\n"
- "FW VERSION : %02X.%02X\n"
- "SILICON ID : %04X.%04X\n"
- "UID : 0x%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X\n",
- ttdata->pip_ver_major, ttdata->pip_ver_minor,
- ttdata->bl_ver_major, ttdata->bl_ver_minor,
- ttdata->fw_ver_major, ttdata->fw_ver_minor,
- ttdata->chip_id, ttdata->chip_rev,
- ttdata->uid[0], ttdata->uid[1],
- ttdata->uid[2], ttdata->uid[3],
- ttdata->uid[4], ttdata->uid[5],
- ttdata->uid[6], ttdata->uid[7],
- ttdata->uid[8], ttdata->uid[9],
- ttdata->uid[10], ttdata->uid[11]);
- } else {
- pt_debug(dev, DL_ERROR,
- "%s: Failed to retriev PIP2 VERSION data\n", __func__);
- return scnprintf(buf, PT_MAX_PRBUF_SIZE,
- "PIP VERSION : -\n"
- "BL VERSION : -\n"
- "FW VERSION : -\n"
- "SILICON ID : -\n"
- "UID : -\n");
- }
- }
- #ifdef TTDL_DIAGNOSTICS
- /*******************************************************************************
- * FUNCTION: pt_ttdl_status_show
- *
- * SUMMARY: Show method for the ttdl_status sysfs node. Displays TTDL internal
- * variable states and GPIO levels. Additional information printed when
- * TTDL_DIAGNOSTICS is enabled.
- *
- * NOTE: All counters will be reset to 0 when this function is called.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *attr - pointer to device attributes
- * *buf - pointer to output buffer
- ******************************************************************************/
- static ssize_t pt_ttdl_status_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- struct pt_platform_data *pdata = dev_get_platdata(dev);
- struct i2c_client *client = to_i2c_client(dev);
- ssize_t ret;
- u16 cal_size = 0;
- unsigned short crc = 0;
- if (cd->cal_cache_in_host)
- _pt_manage_local_cal_data(dev,
- PT_CAL_DATA_INFO, &cal_size, &crc);
- ret = scnprintf(buf, strlen(buf),
- "%s: 0x%04X\n"
- "%s: %d\n"
- "%s: %s\n"
- "%s: %s %s\n"
- "%s: %s\n"
- "%s: 0x%02X\n"
- "%s: %s\n"
- "%s: %s\n"
- "%s: %s\n"
- "%s: %s\n"
- "%s: %d\n"
- "%s: %d\n"
- "%s: %s\n"
- "%s: %s\n"
- "%s: %d\n"
- #ifdef TTDL_DIAGNOSTICS
- "%s: %d\n"
- "%s: %d\n"
- "%s: %d\n"
- "%s: %d\n"
- "%s: %d\n"
- "%s: %d\n"
- "%s: %d\n"
- "%s: %d\n"
- "%s: %d\n"
- "%s: %d\n"
- "%s: %s\n"
- "%s: %s\n"
- "%s: %s\n"
- "%s: %d\n"
- "%s: 0x%04X\n"
- "%s: %s\n"
- #endif /* TTDL_DIAGNOSTICS */
- ,
- "Startup Status ", cd->startup_status,
- "TTDL Debug Level ", cd->debug_level,
- "Mode ",
- cd->mode ? (cd->mode == PT_MODE_OPERATIONAL ?
- "Operational" : "BL") : "Unknown",
- "DUT Generation ",
- cd->active_dut_generation ?
- (cd->active_dut_generation == DUT_PIP2_CAPABLE ?
- "PT TC/TT" : "Gen5/6") : "Unknown",
- cd->active_dut_generation ?
- (cd->set_dut_generation == true ?
- "(Set)" : "(Detected)") : "",
- "HW Detected ",
- cd->hw_detected ? "True" : "False",
- "I2C Address ",
- cd->bus_ops->bustype == BUS_I2C ? client->addr : 0,
- "Active Bus Module ",
- cd->bus_ops->bustype == BUS_I2C ? "I2C" : "SPI",
- "Flashless Mode ",
- cd->flashless_dut == 1 ? "Yes" : "No",
- "GPIO state - IRQ ",
- cd->cpdata->irq_stat ?
- (cd->cpdata->irq_stat(cd->cpdata, dev) ?
- "High" : "Low") : "not defined",
- "GPIO state - TP_XRES ",
- pdata->core_pdata->rst_gpio ?
- (gpio_get_value(pdata->core_pdata->rst_gpio) ?
- "High" : "Low") : "not defined",
- "RAM Parm restore list ", pt_count_parameter_list(cd),
- "Startup Retry Count ", cd->startup_retry_count,
- "WD - Manual Force Stop ",
- cd->watchdog_force_stop ? "True" : "False",
- "WD - Enabled ",
- cd->watchdog_enabled ? "True" : "False",
- "WD - Interval (ms) ", cd->watchdog_interval
- #ifdef TTDL_DIAGNOSTICS
- , "WD - Triggered Count ", cd->watchdog_count,
- "WD - IRQ Stuck low count ", cd->watchdog_irq_stuck_count,
- "WD - Device Access Errors ", cd->watchdog_failed_access_count,
- "WD - XRES Count ", cd->wd_xres_count,
- "IRQ Triggered Count ", cd->irq_count,
- "BL Packet Retry Count ", cd->bl_retry_packet_count,
- "PIP2 CRC Error Count ", cd->pip2_crc_error_count,
- "Bus Transmit Error Count ", cd->bus_transmit_error_count,
- "File Erase Timeout Count ", cd->file_erase_timeout_count,
- "Error GPIO trigger type ", cd->err_gpio_type,
- "Exclusive Access Lock ", cd->exclusive_dev ? "Set":"Free",
- "Suppress No-Flash Auto BL ",
- cd->flashless_auto_bl == PT_SUPPRESS_AUTO_BL ?
- "Yes" : "No",
- "Calibration Cache on host ",
- cd->cal_cache_in_host == PT_FEATURE_ENABLE ?
- "Yes" : "No",
- "Calibration Cache size ", cal_size,
- "Calibration Cache chip ID ", crc,
- "Multi-Chip Support ",
- cd->multi_chip == PT_FEATURE_ENABLE ? "Yes" : "No"
- #endif /* TTDL_DIAGNOSTICS */
- );
- #ifdef TTDL_DIAGNOSTICS
- /* Reset all diagnostic counters */
- cd->watchdog_count = 0;
- cd->watchdog_irq_stuck_count = 0;
- cd->watchdog_failed_access_count = 0;
- cd->wd_xres_count = 0;
- cd->irq_count = 0;
- cd->bl_retry_packet_count = 0;
- cd->pip2_crc_error_count = 0;
- cd->bus_transmit_error_count = 0;
- #endif
- return ret;
- }
- static DEVICE_ATTR(ttdl_status, 0444, pt_ttdl_status_show, NULL);
- /*******************************************************************************
- * FUNCTION: pt_pip2_enter_bl_show
- *
- * SUMMARY: Show method for the pip2_enter_bl sysfs node that will force
- * the DUT into the BL and show the success or failure of entering the BL
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *attr - pointer to device attributes
- * *buf - pointer to output buffer
- ******************************************************************************/
- static ssize_t pt_pip2_enter_bl_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- ssize_t ret = 0;
- int rc = 0;
- int result = 0;
- u8 mode = PT_MODE_UNKNOWN;
- struct pt_core_data *cd = dev_get_drvdata(dev);
- /* Turn off the TTDL WD before enter bootloader */
- pt_stop_wd_timer(cd);
- /* Ensure NO enumeration work is queued or will be queued */
- cancel_work_sync(&cd->enum_work);
- mutex_lock(&cd->system_lock);
- cd->bridge_mode = true;
- mutex_unlock(&cd->system_lock);
- /* set mode to operational to avoid any extra PIP traffic */
- rc = _pt_request_pip2_enter_bl(dev, &mode, &result);
- switch (result) {
- case PT_ENTER_BL_PASS:
- ret = scnprintf(buf, PT_MAX_PRBUF_SIZE,
- "Status: %d\nEntered BL\n", PT_ENTER_BL_PASS);
- break;
- case PT_ENTER_BL_ERROR:
- ret = scnprintf(buf, PT_MAX_PRBUF_SIZE, "Status: %d\n%s\n",
- rc,
- " Unknown Error");
- break;
- case PT_ENTER_BL_RESET_FAIL:
- ret = scnprintf(buf, PT_MAX_PRBUF_SIZE, "Status: %d\n%s\n",
- rc,
- " Soft Reset Failed");
- break;
- case PT_ENTER_BL_HID_START_BL_FAIL:
- ret = scnprintf(buf, PT_MAX_PRBUF_SIZE, "Status: %d\n%s\n",
- rc,
- " PIP Start BL Cmd Failed");
- break;
- case PT_ENTER_BL_CONFIRM_FAIL:
- ret = scnprintf(buf, PT_MAX_PRBUF_SIZE, "Status: %d\n%s\n",
- rc,
- " Error confirming DUT entered BL");
- break;
- default:
- ret = scnprintf(buf, PT_MAX_PRBUF_SIZE, "Status: %d\n%s\n",
- rc, " Unknown Error");
- break;
- };
- /* Allow enumeration work to be queued again */
- cd->bridge_mode = false;
- return ret;
- }
- static DEVICE_ATTR(pip2_enter_bl, 0444, pt_pip2_enter_bl_show, NULL);
- /*******************************************************************************
- * FUNCTION: pt_pip2_exit_bl_show
- *
- * SUMMARY: Show method for the pip2_exit_bl sysfs node that will attempt to
- * launch the APP and put the DUT Application mode
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *attr - pointer to device attributes
- * *buf - pointer to output buffer
- ******************************************************************************/
- static ssize_t pt_pip2_exit_bl_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- ssize_t ret = 0;
- int rc = 0;
- u8 status_str[PT_STATUS_STR_LEN];
- rc = pt_pip2_exit_bl_(cd, status_str, PT_STATUS_STR_LEN);
- /*
- * Perform enum if startup_status doesn't reach to
- * STARTUP_STATUS_FW_OUT_OF_BOOT.
- */
- if (!rc && (!(cd->startup_status & STARTUP_STATUS_FW_OUT_OF_BOOT))) {
- rc = pt_enum_with_dut(cd, false, &cd->startup_status);
- if (!(cd->startup_status & STARTUP_STATUS_FW_OUT_OF_BOOT)) {
- strlcpy(status_str,
- "Already in APP mode - FW stuck in Boot mode", sizeof(status_str));
- }
- }
- ret = scnprintf(buf, PT_MAX_PRBUF_SIZE, "Status: %d\n%s\n",
- rc, status_str);
- return ret;
- }
- static DEVICE_ATTR(pip2_exit_bl, 0444, pt_pip2_exit_bl_show, NULL);
- #endif
- #ifdef EASYWAKE_TSG6
- /*******************************************************************************
- * FUNCTION: pt_easy_wakeup_gesture_show
- *
- * SUMMARY: Show method for the easy_wakeup_gesture sysfs node that will show
- * current easy wakeup gesture
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *attr - pointer to device attributes
- * *buf - pointer to output buffer
- ******************************************************************************/
- static ssize_t pt_easy_wakeup_gesture_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- ssize_t ret;
- mutex_lock(&cd->system_lock);
- ret = scnprintf(buf, PT_MAX_PRBUF_SIZE, "0x%02X\n",
- cd->easy_wakeup_gesture);
- mutex_unlock(&cd->system_lock);
- return ret;
- }
- /*******************************************************************************
- * FUNCTION: pt_easy_wakeup_gesture_store
- *
- * SUMMARY: The store method for the easy_wakeup_gesture sysfs node that
- * allows the wake gesture to be set to a custom value.
- *
- * RETURN: Size of passed in buffer is success
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *attr - pointer to device attributes
- * *buf - pointer to buffer that hold the command parameters
- * size - size of buf
- ******************************************************************************/
- static ssize_t pt_easy_wakeup_gesture_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t size)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- u32 input_data[2];
- int length;
- int rc = 0;
- /* Maximum input of one value */
- length = _pt_ic_parse_input(dev, buf, size, input_data,
- ARRAY_SIZE(input_data));
- if (length != 1) {
- pt_debug(dev, DL_ERROR, "%s: Invalid number of arguments\n",
- __func__);
- rc = -EINVAL;
- goto exit;
- }
- pt_debug(dev, DL_INFO, "%s: features.easywake = 0x%02X\n",
- __func__, cd->features.easywake);
- if (!cd->features.easywake || input_data[0] > 0xFF) {
- rc = -EINVAL;
- goto exit;
- }
- pm_runtime_get_sync(dev);
- mutex_lock(&cd->system_lock);
- if (cd->sysinfo.ready && IS_PIP_VER_GE(&cd->sysinfo, 1, 2)) {
- cd->easy_wakeup_gesture = (u8)input_data[0];
- pt_debug(dev, DL_INFO,
- "%s: Updated easy_wakeup_gesture = 0x%02X\n",
- __func__, cd->easy_wakeup_gesture);
- } else
- rc = -ENODEV;
- mutex_unlock(&cd->system_lock);
- pm_runtime_put(dev);
- exit:
- if (rc)
- return rc;
- return size;
- }
- /*******************************************************************************
- * FUNCTION: pt_easy_wakeup_gesture_id_show
- *
- * SUMMARY: Show method for the easy_wakeup_gesture_id sysfs node that will
- * show the TSG6 easywake gesture ID
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *attr - pointer to device attributes
- * *buf - pointer to output buffer
- ******************************************************************************/
- static ssize_t pt_easy_wakeup_gesture_id_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- ssize_t ret;
- mutex_lock(&cd->system_lock);
- ret = scnprintf(buf, PT_MAX_PRBUF_SIZE, "Status: 0\n0x%02X\n",
- cd->gesture_id);
- mutex_unlock(&cd->system_lock);
- return ret;
- }
- /*******************************************************************************
- * FUNCTION: pt_easy_wakeup_gesture_data_show
- *
- * SUMMARY: Show method for the easy_wakeup_gesture_data sysfs node that will
- * show the TSG6 easywake gesture data in the following format:
- * x1(LSB),x1(MSB), y1(LSB),y1(MSB), x2(LSB),x2(MSB), y2(LSB),y2(MSB),...
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *attr - pointer to device attributes
- * *buf - pointer to output buffer
- ******************************************************************************/
- static ssize_t pt_easy_wakeup_gesture_data_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- ssize_t ret = 0;
- int i;
- mutex_lock(&cd->system_lock);
- ret += scnprintf(buf + ret, PT_MAX_PRBUF_SIZE - ret, "Status: %d\n", 0);
- for (i = 0; i < cd->gesture_data_length; i++)
- ret += scnprintf(buf + ret, PT_MAX_PRBUF_SIZE - ret,
- "0x%02X\n", cd->gesture_data[i]);
- ret += scnprintf(buf + ret, PT_MAX_PRBUF_SIZE - ret,
- "(%d bytes)\n", cd->gesture_data_length);
- mutex_unlock(&cd->system_lock);
- return ret;
- }
- #endif /* EASYWAKE_TSG6 */
- #ifdef TTDL_DIAGNOSTICS
- /*******************************************************************************
- * FUNCTION: pt_err_gpio_show
- *
- * SUMMARY: Show method for the err_gpio sysfs node that will show if
- * setting up the gpio was successful
- *
- * RETURN: Char buffer with printed GPIO creation state
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *attr - pointer to device attributes
- * *buf - pointer to output buffer
- ******************************************************************************/
- static ssize_t pt_err_gpio_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- return scnprintf(buf, strlen(buf), "Status: 0\n"
- "Err GPIO (%d) : %s\n"
- "Err GPIO trig type: %d\n",
- cd->err_gpio,
- (cd->err_gpio ? (gpio_get_value(cd->err_gpio) ?
- "HIGH" : "low") : "not defined"),
- cd->err_gpio_type);
- }
- /*******************************************************************************
- * FUNCTION: pt_err_gpio_store
- *
- * SUMMARY: The store method for the err_gpio sysfs node that allows any
- * available host GPIO to be used to trigger when TTDL detects a PIP
- * command/response timeout.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *attr - pointer to device attributes
- * *buf - pointer to buffer that hold the command parameters
- * size - size of buf
- ******************************************************************************/
- static ssize_t pt_err_gpio_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t size)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- unsigned long gpio;
- int rc = 0;
- u32 input_data[3];
- int length;
- u8 err_type;
- input_data[0] = 0;
- input_data[1] = 0;
- /* Maximmum input is two elements */
- length = _pt_ic_parse_input(dev, buf, size,
- input_data, ARRAY_SIZE(input_data));
- if (length < 1 || length > 2) {
- pt_debug(dev, DL_ERROR, "%s: Invalid number of arguments\n",
- __func__);
- rc = -EINVAL;
- goto exit;
- }
- gpio = input_data[0];
- err_type = (u8)input_data[1];
- if (err_type < 0 || err_type > PT_ERR_GPIO_MAX_TYPE) {
- rc = -EINVAL;
- goto exit;
- }
- mutex_lock(&cd->system_lock);
- gpio_free(gpio);
- rc = gpio_request(gpio, NULL);
- if (rc) {
- pt_debug(dev, DL_ERROR, "error requesting gpio %lu\n", gpio);
- rc = -ENODEV;
- } else {
- cd->err_gpio = gpio;
- cd->err_gpio_type = err_type;
- gpio_direction_output(gpio, 0);
- }
- mutex_unlock(&cd->system_lock);
- exit:
- if (rc)
- return rc;
- return size;
- }
- static DEVICE_ATTR(err_gpio, 0644, pt_err_gpio_show,
- pt_err_gpio_store);
- /*******************************************************************************
- * FUNCTION: pt_drv_irq_show
- *
- * SUMMARY: Show method for the drv_irq sysfs node that will show if the
- * TTDL interrupt is enabled/disabled
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *attr - pointer to device attributes
- * *buf - pointer to output buffer
- ******************************************************************************/
- static ssize_t pt_drv_irq_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- ssize_t ret = 0;
- mutex_lock(&cd->system_lock);
- ret += scnprintf(buf, PT_MAX_PRBUF_SIZE, "Status: %d\n", 0);
- if (cd->irq_enabled)
- ret += scnprintf(buf + ret, PT_MAX_PRBUF_SIZE - ret,
- "Driver interrupt: ENABLED\n");
- else
- ret += scnprintf(buf + ret, PT_MAX_PRBUF_SIZE - ret,
- "Driver interrupt: DISABLED\n");
- mutex_unlock(&cd->system_lock);
- return ret;
- }
- /*******************************************************************************
- * FUNCTION: pt_drv_irq_store
- *
- * SUMMARY: The store method for the drv_irq sysfs node that allows the TTDL
- * IRQ to be enabled/disabled.
- *
- * RETURN: Size of passed in buffer
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *attr - pointer to device attributes
- * *buf - pointer to buffer that hold the command parameters
- * size - size of buf
- ******************************************************************************/
- static ssize_t pt_drv_irq_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t size)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- u32 input_data[2];
- int length;
- int rc = 0;
- /* Maximum input of one value */
- length = _pt_ic_parse_input(dev, buf, size, input_data,
- ARRAY_SIZE(input_data));
- if (length != 1) {
- pt_debug(dev, DL_ERROR, "%s: Invalid number of arguments\n",
- __func__);
- rc = -EINVAL;
- goto exit;
- }
- mutex_lock(&cd->system_lock);
- switch (input_data[0]) {
- case 0:
- if (cd->irq_enabled) {
- cd->irq_enabled = false;
- /* Disable IRQ has no return value to check */
- disable_irq_nosync(cd->irq);
- pt_debug(dev, DL_INFO,
- "%s: Driver IRQ now disabled\n",
- __func__);
- } else
- pt_debug(dev, DL_INFO,
- "%s: Driver IRQ already disabled\n",
- __func__);
- break;
- case 1:
- if (cd->irq_enabled == false) {
- cd->irq_enabled = true;
- enable_irq(cd->irq);
- pt_debug(dev, DL_INFO,
- "%s: Driver IRQ now enabled\n",
- __func__);
- } else
- pt_debug(dev, DL_INFO,
- "%s: Driver IRQ already enabled\n",
- __func__);
- break;
- default:
- rc = -EINVAL;
- pt_debug(dev, DL_ERROR, "%s: Invalid value\n", __func__);
- }
- mutex_unlock(&(cd->system_lock));
- exit:
- if (rc)
- return rc;
- return size;
- }
- /*******************************************************************************
- * FUNCTION: pt_pip2_bin_hdr_show
- *
- * SUMMARY: Show method for the pip2_bin_hdr sysfs node that will read
- * the bin file header from flash and show each field
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *attr - pointer to device attributes
- * *buf - pointer to output buffer
- ******************************************************************************/
- static ssize_t pt_pip2_bin_hdr_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- ssize_t ret = 0;
- struct pt_bin_file_hdr hdr = {0};
- int rc;
- rc = _pt_request_pip2_bin_hdr(dev, &hdr);
- ret = scnprintf(buf, strlen(buf),
- "%s: %d\n"
- "%s: %d\n"
- "%s: 0x%04X\n"
- "%s: %d\n"
- "%s: %d\n"
- "%s: %d\n"
- "%s: 0x%08X\n"
- "%s: 0x%04X\n"
- "%s: 0x%04X\n"
- "%s: %d\n"
- "%s: %d\n",
- "Status", rc,
- "Header Length ", hdr.length,
- "TTPID ", hdr.ttpid,
- "FW Major Ver ", hdr.fw_major,
- "FW Minor Ver ", hdr.fw_minor,
- "FW Rev Control ", hdr.fw_rev_ctrl,
- "FW CRC ", hdr.fw_crc,
- "Silicon Rev ", hdr.si_rev,
- "Silicon ID ", hdr.si_id,
- "Config Ver ", hdr.config_ver,
- "HEX File Size ", hdr.hex_file_size
- );
- return ret;
- }
- /*******************************************************************************
- * FUNCTION: pt_platform_data_show
- *
- * SUMMARY: Show method for the platform_data sysfs node that will show the
- * active platform data including: GPIOs, Vendor and Product IDs,
- * Virtual Key coordinates, Core/MT/Loader flags, Level trigger delay,
- * HID registers, and Easy wake gesture
- *
- * RETURN: Size of printed data
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *attr - pointer to device attributes
- * *buf - pointer to output buffer
- ******************************************************************************/
- static ssize_t pt_platform_data_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct pt_platform_data *pdata = dev_get_platdata(dev);
- struct pt_core_data *cd = dev_get_drvdata(dev);
- ssize_t ret;
- ret = scnprintf(buf, strlen(buf),
- "%s: %d\n"
- "%s: %d\n"
- "%s: %d\n"
- "%s: %d\n"
- "%s: %d\n"
- "%s: %d\n"
- "%s: %d\n"
- "%s: %d\n"
- "%s: %d\n"
- "%s: %d\n"
- "%s: %d\n"
- "%s: %d\n"
- "%s: %d\n"
- "%s: %d\n"
- "%s: %d\n"
- "%s: %d\n"
- "%s: %d\n"
- "%s: %d\n"
- "%s: %d\n"
- "%s: %d\n"
- "%s: %d\n"
- "%s: %d\n"
- "%s: %d\n"
- "%s: %d\n"
- "%s: %d\n"
- "%s: %d\n"
- "%s: %d\n"
- "%s: %s\n"
- "%s: %s\n"
- "%s: %d\n",
- "Status", 0,
- "Interrupt GPIO ", pdata->core_pdata->irq_gpio,
- "Interrupt GPIO Value ",
- pdata->core_pdata->irq_gpio ?
- gpio_get_value(pdata->core_pdata->irq_gpio) : 0,
- "Reset GPIO ", pdata->core_pdata->rst_gpio,
- "Reset GPIO Value ",
- pdata->core_pdata->rst_gpio ?
- gpio_get_value(pdata->core_pdata->rst_gpio) : 0,
- "DDI Reset GPIO ", pdata->core_pdata->ddi_rst_gpio,
- "DDI Reset GPIO Value ",
- pdata->core_pdata->ddi_rst_gpio ?
- gpio_get_value(pdata->core_pdata->ddi_rst_gpio) : 0,
- "VDDI GPIO ", pdata->core_pdata->vddi_gpio,
- "VDDI GPIO Value ",
- pdata->core_pdata->vddi_gpio ?
- gpio_get_value(pdata->core_pdata->vddi_gpio) : 0,
- "VCC GPIO ", pdata->core_pdata->vcc_gpio,
- "VCC GPIO Value ",
- pdata->core_pdata->vcc_gpio ?
- gpio_get_value(pdata->core_pdata->vcc_gpio) : 0,
- "AVDD GPIO ", pdata->core_pdata->avdd_gpio,
- "AVDD GPIO Value ",
- pdata->core_pdata->avdd_gpio ?
- gpio_get_value(pdata->core_pdata->avdd_gpio) : 0,
- "AVEE GPIO ", pdata->core_pdata->avee_gpio,
- "AVEE GPIO Value ",
- pdata->core_pdata->avee_gpio ?
- gpio_get_value(pdata->core_pdata->avee_gpio) : 0,
- "Vendor ID ", pdata->core_pdata->vendor_id,
- "Product ID ", pdata->core_pdata->product_id,
- "Vkeys x ", pdata->mt_pdata->vkeys_x,
- "Vkeys y ", pdata->mt_pdata->vkeys_y,
- "Core data flags ", pdata->core_pdata->flags,
- "MT data flags ", pdata->mt_pdata->flags,
- "Loader data flags ", pdata->loader_pdata->flags,
- "Level trigger delay (us) ",
- pdata->core_pdata->level_irq_udelay,
- "HID Descriptor Register ",
- pdata->core_pdata->hid_desc_register,
- "HID Output Register ",
- cd->hid_desc.output_register,
- "HID Command Register ",
- cd->hid_desc.command_register,
- "Easy wakeup gesture ",
- pdata->core_pdata->easy_wakeup_gesture,
- "Config DUT generation ",
- pdata->core_pdata->config_dut_generation ?
- (pdata->core_pdata->config_dut_generation ==
- CONFIG_DUT_PIP2_CAPABLE ?
- "PT TC/TT" : "Gen5/6") : "Auto",
- "Watchdog Force Stop ",
- pdata->core_pdata->watchdog_force_stop ?
- "True" : "False",
- "Panel ID Support ",
- pdata->core_pdata->panel_id_support);
- return ret;
- }
- #define PT_ERR_STR_SIZE 64
- /*******************************************************************************
- * FUNCTION: pt_bist_bus_test
- *
- * SUMMARY: Tests the connectivity of the active bus pins:
- * I2C - SDA and SCL
- * SPI - MOSI, MISO, CLK
- *
- * Disable TTDL interrupts, send a PIP cmd and then manually read the
- * bus. If any data is read we know the I2C/SPI pins are connected
- *
- * RETURN:
- * 0 = Success
- * !0 = Failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *net_toggled - pointer to where to store if bus toggled
- * *err_str - pointer to error string buffer
- ******************************************************************************/
- static int pt_bist_bus_test(struct device *dev, u8 *net_toggled, u8 *err_str)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- u8 ver_cmd[8] = {0x01, 0x01, 0x06, 0x00, 0x0E, 0x07, 0xF0, 0xB1};
- u8 *read_buf = NULL;
- int bytes_read = 0;
- int rc = 0;
- read_buf = kzalloc(PT_MAX_PIP1_MSG_SIZE, GFP_KERNEL);
- if (read_buf == NULL) {
- rc = -ENOMEM;
- goto exit;
- }
- bytes_read = pt_flush_bus(cd, PT_FLUSH_BUS_BASED_ON_LEN, NULL);
- pt_debug(dev, DL_INFO, "%s: TTDL Core Suspend\n", __func__);
- disable_irq(cd->irq);
- mutex_lock(&cd->system_lock);
- cd->irq_disabled = true;
- mutex_unlock(&cd->system_lock);
- /*
- * Sleep >4ms to allow any pending TTDL IRQ to finish. Without this
- * the disable_irq_nosync() could cause the IRQ to get stuck asserted
- */
- usleep_range(5000, 6000);
- pt_debug(cd->dev, DL_INFO, ">>> %s: Write Buffer Size[%d] VERSION\n",
- __func__, (int)sizeof(ver_cmd));
- pt_pr_buf(cd->dev, DL_DEBUG, ver_cmd, (int)sizeof(ver_cmd),
- ">>> User CMD");
- rc = pt_adap_write_read_specific(cd, sizeof(ver_cmd), ver_cmd, NULL);
- if (rc) {
- pt_debug(dev, DL_ERROR,
- "%s: BUS Test - Failed to send VER cmd\n", __func__);
- *net_toggled = 0;
- strlcpy(err_str,
- "- Write failed, bus open or shorted or DUT in reset", PT_ERR_STR_SIZE);
- goto exit_enable_irq;
- }
- usleep_range(4000, 5000);
- bytes_read = pt_flush_bus(cd, PT_FLUSH_BUS_BASED_ON_LEN, read_buf);
- pt_debug(dev, DL_INFO, "%s: BUS Test - %d bytes forced read\n",
- __func__, bytes_read);
- if (bytes_read == 0) {
- *net_toggled = 0;
- pt_debug(dev, DL_INFO, "%s: BUS Read Failed, 0 bytes read\n",
- __func__);
- strlcpy(err_str,
- "- Bus open, shorted or DUT in reset", PT_ERR_STR_SIZE);
- rc = -EIO;
- goto exit_enable_irq;
- } else {
- if (cd->bus_ops->bustype == BUS_I2C)
- *net_toggled = 1;
- else {
- if ((bytes_read > 3) &&
- (read_buf[3] & PIP2_CMD_COMMAND_ID_MASK) ==
- PIP2_CMD_ID_VERSION)
- *net_toggled = 1;
- else {
- *net_toggled = 0;
- pt_debug(dev, DL_INFO,
- "%s: BUS Read Failed, %d bytes read\n",
- __func__, bytes_read);
- strlcpy(err_str,
- "- Bus open, shorted or DUT in reset", PT_ERR_STR_SIZE);
- }
- }
- }
- exit_enable_irq:
- enable_irq(cd->irq);
- usleep_range(5000, 6000);
- mutex_lock(&cd->system_lock);
- cd->irq_disabled = false;
- mutex_unlock(&cd->system_lock);
- pt_debug(dev, DL_INFO, "%s: TTDL Core Resumed\n", __func__);
- exit:
- kfree(read_buf);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_bist_irq_test
- *
- * SUMMARY: Tests the connectivity of the IRQ net
- *
- * This test will ensure there is a good connection between the host
- * and the DUT on the irq pin. First determine if the IRQ is stuck
- * asserted and if so keep reading messages off of the bus until
- * it de-asserts. Possible outcomes:
- * - IRQ was already de-asserted: Send a PIP command and if an
- * interrupt is generated the test passes.
- * - IRQ was asserted: Reading off the bus de-assertes the IRQ,
- * test passes.
- * - IRQ stays asserted: After reading the bus multiple times
- * the IRQ stays asserted. Likely open or shorted to GND
- *
- * RETURN:
- * 0 = Success
- * !0 = Failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *bus_toggled - pointer to where to store if bus toggled
- * *irq_toggled - pointer to where to store if IRQ toggled
- * *xres_toggled - pointer to where to store if XRES toggled
- * *err_str - pointer to error string buffer
- ******************************************************************************/
- static int pt_bist_irq_test(struct device *dev,
- u8 *bus_toggled, u8 *irq_toggled, u8 *xres_toggled, u8 *err_str)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- u8 *read_buf = NULL;
- u8 mode = PT_MODE_UNKNOWN;
- u16 actual_read_len;
- int bytes_read = 0;
- int count = 0;
- int rc = 0;
- read_buf = kzalloc(PT_MAX_PIP1_MSG_SIZE, GFP_KERNEL);
- if (read_buf == NULL) {
- rc = -ENOMEM;
- goto exit;
- }
- /* Clear IRQ triggered count, and re-evaluate at the end of test */
- cd->irq_count = 0;
- /*
- * Check if IRQ is stuck asserted, if so try a non forced flush of
- * the bus based on the 2 byte initial length read. Try up to 5x.
- */
- while (pt_check_irq_asserted(cd) && count < 5) {
- count++;
- bytes_read += pt_flush_bus(cd, PT_FLUSH_BUS_BASED_ON_LEN, NULL);
- }
- if (count > 1 && count < 5 && bytes_read > 0) {
- /*
- * IRQ was stuck but data was successfully read from the
- * bus releasing the IRQ line.
- */
- pt_debug(dev, DL_INFO, "%s: count=%d bytes_read=%d\n",
- __func__, count, bytes_read);
- *bus_toggled = 1;
- *irq_toggled = 1;
- goto exit;
- }
- if (count == 5 && bytes_read == 0) {
- /*
- * Looped 5x and read nothing off the bus yet the IRQ is still
- * asserted. Possible conditions:
- * - IRQ open circuit
- * - IRQ shorted to GND
- * - I2C/SPI bus is disconnected
- * - FW holding the pin low
- * Try entering the BL to see if communication works there.
- */
- mode = PT_MODE_IGNORE;
- rc = _pt_request_pip2_enter_bl(dev, &mode, NULL);
- if (rc) {
- pt_debug(dev, DL_ERROR,
- "%s Failed to enter BL\n", __func__);
- strlcpy(err_str,
- "- likely shorted to GND or FW holding it.", PT_ERR_STR_SIZE);
- *irq_toggled = 0;
- goto exit;
- }
- /*
- * If original mode was operational and we successfully
- * entered the BL, then the XRES net must have toggled
- */
- if (mode == PT_MODE_OPERATIONAL)
- *xres_toggled = 1;
- rc = _pt_request_pip2_send_cmd(dev, PT_CORE_CMD_PROTECTED,
- PIP2_CMD_ID_VERSION, NULL, 0, read_buf,
- &actual_read_len);
- if (rc) {
- /*
- * Could not communicate to DUT in BL mode. Save the
- * error string, slim chance but the XRES test below may
- * show the IRQ is actually working.
- */
- strlcpy(err_str, "- likely shorted to GND.", PT_ERR_STR_SIZE);
- pt_debug(dev, DL_ERROR,
- "%s: %s, count=%d bytes_read=%d\n",
- __func__, err_str, count, bytes_read);
- *irq_toggled = 0;
- rc = pt_pip2_exit_bl_(cd, NULL, 0);
- goto exit;
- } else {
- *bus_toggled = 1;
- *irq_toggled = 1;
- goto exit;
- }
- }
- if (pt_check_irq_asserted(cd)) {
- strlcpy(err_str, "- likely shorted to GND", PT_ERR_STR_SIZE);
- rc = -EIO;
- *irq_toggled = 0;
- goto exit;
- }
- /* Try sending a PIP command to see if we get a response */
- rc = _pt_request_pip2_send_cmd(dev, PT_CORE_CMD_PROTECTED,
- PIP2_CMD_ID_VERSION, NULL, 0, read_buf, &actual_read_len);
- if (rc) {
- /*
- * Potential IRQ issue, no communication in App mode, attempt
- * the same command in the BL
- */
- mode = PT_MODE_IGNORE;
- rc = _pt_request_pip2_enter_bl(dev, &mode, NULL);
- if (rc) {
- pt_debug(dev, DL_ERROR,
- "%s Failed to enter BL\n", __func__);
- *irq_toggled = 0;
- strlcpy(err_str, "- likely open or shorted to VDDI.", PT_ERR_STR_SIZE);
- goto exit;
- }
- /*
- * If original mode was operational and we successfully
- * entered the BL, this will be useful info for the tp_xres
- * test below.
- */
- if (mode == PT_MODE_OPERATIONAL)
- *xres_toggled = 1;
- rc = _pt_request_pip2_send_cmd(dev, PT_CORE_CMD_PROTECTED,
- PIP2_CMD_ID_VERSION, NULL, 0, read_buf,
- &actual_read_len);
- if (rc) {
- /*
- * Could not communicate in FW mode or BL mode. Save the
- * error string, slim chance but the XRES test below may
- * show the IRQ is actually working.
- */
- strlcpy(err_str, "- likely open or shorted to VDDI.", PT_ERR_STR_SIZE);
- pt_debug(dev, DL_ERROR,
- "%s: request_active_pip_prot failed\n",
- __func__);
- *irq_toggled = 0;
- goto exit;
- }
- }
- if (cd->irq_count > 0) {
- pt_debug(dev, DL_INFO, "%s: irq_count=%d\n", __func__,
- cd->irq_count);
- *bus_toggled = 1;
- *irq_toggled = 1;
- goto exit;
- }
- exit:
- kfree(read_buf);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_bist_xres_test
- *
- * SUMMARY: Tests the connectivity of the TP_XRES net
- *
- * This test will ensure there is a good connection between the host
- * and the DUT on the tp_xres pin. The pin will be toggled to
- * generate a TP reset which will cause the DUT to output a reset
- * sentinel. If the reset sentinel is seen the test passes. If it is
- * not seen the test will attempt to send a soft reset to simply gain
- * some additional information on the failure:
- * - soft reset fails to send: XRES and IRQ likely open
- * - soft reset passes: XRES likely open or stuck de-asserted
- * - soft reset fails: XRES likely stuck asserted
- *
- * RETURN:
- * 0 = Success
- * !0 = Failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *bus_toggled - pointer to where to store if bus toggled
- * *irq_toggled - pointer to where to store if IRQ toggled
- * *xres_toggled - pointer to where to store if XRES toggled
- * *err_str - pointer to error string buffer
- ******************************************************************************/
- static int pt_bist_xres_test(struct device *dev,
- u8 *bus_toggled, u8 *irq_toggled, u8 *xres_toggled, u8 *err_str)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- struct pt_platform_data *pdata = dev_get_platdata(dev);
- u8 *read_buf = NULL;
- u8 mode = PT_MODE_UNKNOWN;
- int rc = 0;
- int t = 0;
- int timeout = 300;
- read_buf = kzalloc(PT_MAX_PIP1_MSG_SIZE, GFP_KERNEL);
- if (read_buf == NULL) {
- rc = -ENOMEM;
- goto exit;
- }
- /* Clear the startup bit mask, reset and enum will re-populate it */
- cd->startup_status = STARTUP_STATUS_START;
- pt_debug(dev, DL_DEBUG, "%s: Startup Status Reset\n", __func__);
- if ((!pdata->core_pdata->rst_gpio) || (!pdata->core_pdata->xres)) {
- strlcpy(err_str, "- Net not configured or available", PT_ERR_STR_SIZE);
- rc = -ENODEV;
- goto exit;
- }
- /* Ensure we have nothing pending on active bus */
- pt_flush_bus_if_irq_asserted(cd, PT_FLUSH_BUS_BASED_ON_LEN);
- /* Perform a hard XRES toggle and wait for reset sentinel */
- mutex_lock(&cd->system_lock);
- cd->hid_reset_cmd_state = 1;
- mutex_unlock(&cd->system_lock);
- pt_debug(dev, DL_INFO, "%s: Perform a hard reset\n", __func__);
- rc = pt_hw_hard_reset(cd);
- /* Set timeout to 1s for the flashless case where a BL could be done */
- if (cd->flashless_dut)
- timeout = 1000;
- /*
- * To avoid the case that next PIP command can be confused by BL/FW
- * sentinel's "wakeup" event, chekcing hid_reset_cmd_state which is
- * followed by "wakeup event" function can lower the failure rate.
- */
- t = wait_event_timeout(cd->wait_q,
- ((cd->startup_status != STARTUP_STATUS_START)
- && (cd->hid_reset_cmd_state == 0)),
- msecs_to_jiffies(timeout));
- if (IS_TMO(t)) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: TMO waiting for sentinel\n", __func__);
- *xres_toggled = 0;
- strlcpy(err_str, "- likely open. (No Reset Sentinel)", PT_ERR_STR_SIZE);
- /*
- * Possibly bad FW, Try entering BL and wait for reset sentinel.
- * To enter the BL we need to generate an XRES so first try to
- * launch the applicaiton
- */
- if (cd->mode == PT_MODE_BOOTLOADER)
- pt_pip2_launch_app(dev, PT_CORE_CMD_PROTECTED);
- pt_debug(dev, DL_INFO, "%s: Enter BL with a hard reset\n",
- __func__);
- mode = PT_MODE_IGNORE;
- rc = _pt_request_pip2_enter_bl(dev, &mode, NULL);
- if (rc) {
- pt_debug(dev, DL_ERROR, "%s Failed to enter BL\n",
- __func__);
- *xres_toggled = 0;
- strlcpy(err_str, "- likely open or shorted to VDDI.", PT_ERR_STR_SIZE);
- goto exit;
- } else {
- /* Wait for the BL sentinel */
- t = wait_event_timeout(cd->wait_q,
- (cd->startup_status != STARTUP_STATUS_START),
- msecs_to_jiffies(500));
- if (IS_TMO(t)) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: TMO waiting for BL sentinel\n",
- __func__);
- *xres_toggled = 0;
- strlcpy(err_str,
- "- likely open or shorted to VDDI.", PT_ERR_STR_SIZE);
- rc = -ETIME;
- goto exit;
- }
- }
- }
- mutex_lock(&cd->system_lock);
- cd->hid_reset_cmd_state = 0;
- mutex_unlock(&cd->system_lock);
- /* Look for BL or FW reset sentinels */
- if (!rc && ((cd->startup_status & STARTUP_STATUS_BL_RESET_SENTINEL) ||
- (cd->startup_status & STARTUP_STATUS_FW_RESET_SENTINEL))) {
- pt_debug(dev, DL_INFO, "%s: hard XRES pass\n", __func__);
- /* If a sentinel was seen, all nets are working */
- *xres_toggled = 1;
- *irq_toggled = 1;
- /*
- * For SPI test, bus read result can be confused as FW sentinel
- * if MISO(slave) is connected to MISO(host).
- */
- if (cd->bus_ops->bustype == BUS_I2C)
- *bus_toggled = 1;
- } else {
- /*
- * Hard reset failed, however some additional information
- * could be determined. Try a soft reset to see if DUT resets
- * with the possible outcomes:
- * - if it resets the line is not stuck asserted
- * - if it does not reset the line could be stuck asserted
- */
- *xres_toggled = 0;
- rc = pt_hw_soft_reset(cd, PT_CORE_CMD_PROTECTED);
- msleep(30);
- pt_debug(dev, DL_INFO, "%s: TP_XRES BIST soft reset rc=%d",
- __func__, rc);
- if (rc) {
- strlcpy(err_str, "- likely open.", PT_ERR_STR_SIZE);
- pt_debug(dev, DL_ERROR,
- "%s: Hard reset failed, soft reset failed %s\n",
- __func__, err_str);
- goto exit;
- }
- if (cd->startup_status & STARTUP_STATUS_BL_RESET_SENTINEL ||
- cd->startup_status & STARTUP_STATUS_FW_RESET_SENTINEL) {
- strlcpy(err_str,
- "- likely open or stuck high, soft reset OK", PT_ERR_STR_SIZE);
- pt_debug(dev, DL_ERROR,
- "%s: Hard reset failed, soft reset passed-%s\n",
- __func__, err_str);
- } else if (cd->startup_status == 0) {
- strlcpy(err_str, "- likely stuck high.", PT_ERR_STR_SIZE);
- pt_debug(dev, DL_ERROR,
- "%s: Hard reset failed, soft reset failed-%s\n",
- __func__, err_str);
- } else {
- strlcpy(err_str, "- open or stuck.", PT_ERR_STR_SIZE);
- pt_debug(dev, DL_ERROR,
- "%s: Hard and Soft reset failed - %s\n",
- __func__, err_str);
- }
- }
- exit:
- kfree(read_buf);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_bist_slave_irq_test
- *
- * SUMMARY: Tests the connectivity of the Master/Slave IRQ net
- *
- * This test will ensure there is a good IRQ connection between the master
- * DUT and the slave DUT(s). After power up the STATUS command is sent
- * and the 'Slave Detect' bits are verified to ensure the master DUT
- * saw each slave trigger the IRQ with it's reset sentinel.
- *
- * RETURN:
- * 0 = Success
- * !0 = Failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *slave_irq_toggled - pointer to where to store if slave IRQ toggled
- * *slave_bus_toggled - pointer to where to store if slave Bus toggled
- * *err_str - pointer to error string buffer
- * *slave_detect - pointer to slave detect buffer
- * *boot_err - pointer to boot_err buffer
- ******************************************************************************/
- static int pt_bist_slave_irq_test(struct device *dev,
- u8 *slave_irq_toggled, u8 *slave_bus_toggled, u8 *err_str,
- u8 *slave_detect, u8 *boot_err)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- u8 mode = PT_MODE_UNKNOWN;
- u8 status;
- u8 boot;
- u8 read_buf[12];
- u8 detected = 0;
- u8 last_err = -1;
- u16 actual_read_len;
- int result = 0;
- int rc = 0;
- /*
- * Ensure DUT is in the BL where the STATUS cmd will report the slave
- * detect bits. If the DUT was in FW, entering the BL will cause an
- * XRES signal which will inadvertently test the XRES net as well
- */
- rc = _pt_request_pip2_enter_bl(dev, &mode, &result);
- if (rc) {
- pt_debug(cd->dev, DL_ERROR, "%s: Error entering BL rc=%d\n",
- __func__, rc);
- strlcpy(err_str, "- State could not be determined.", PT_ERR_STR_SIZE);
- goto exit;
- }
- /* Use the STATUS command to retrieve the slave detect bit(s) */
- rc = _pt_request_pip2_send_cmd(cd->dev, PT_CORE_CMD_UNPROTECTED,
- PIP2_CMD_ID_STATUS, NULL, 0, read_buf,
- &actual_read_len);
- if (!rc) {
- pt_pr_buf(cd->dev, DL_INFO, read_buf, actual_read_len,
- "PIP2 STATUS");
- status = read_buf[PIP2_RESP_STATUS_OFFSET];
- boot = read_buf[PIP2_RESP_BODY_OFFSET] & 0x01;
- /* Slave detect is only valid if status ok and in boot exec */
- if (status == PIP2_RSP_ERR_NONE &&
- boot == PIP2_STATUS_BOOT_EXEC) {
- detected = read_buf[PIP2_RESP_BODY_OFFSET + 2] &
- SLAVE_DETECT_MASK;
- } else {
- strlcpy(err_str, "- State could not be determined", PT_ERR_STR_SIZE);
- rc = -EPERM;
- }
- } else {
- pt_debug(cd->dev, DL_ERROR, "%s: STATUS cmd failure\n",
- __func__);
- strlcpy(err_str, "- State could not be determined.", PT_ERR_STR_SIZE);
- goto exit;
- }
- /*
- * Retrieve boot error regardless of the state of the slave detect
- * bit because the IRQ could have been stuck high or low.
- */
- rc = _pt_request_pip2_send_cmd(cd->dev, PT_CORE_CMD_UNPROTECTED,
- PIP2_CMD_ID_GET_LAST_ERRNO, NULL, 0,
- read_buf, &actual_read_len);
- if (!rc) {
- pt_pr_buf(cd->dev, DL_INFO, read_buf, actual_read_len,
- "PIP2 GET_LAST_ERRNO");
- status = read_buf[PIP2_RESP_STATUS_OFFSET];
- last_err = read_buf[PIP2_RESP_BODY_OFFSET];
- if (last_err) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: Master Boot Last Err = 0x%02X\n",
- __func__, last_err);
- }
- } else {
- pt_debug(cd->dev, DL_ERROR,
- "%s: GET_LAST_ERRNO cmd failure\n", __func__);
- strlcpy(err_str, "- stuck, likely shorted to GND.", PT_ERR_STR_SIZE);
- }
- exit:
- pt_debug(cd->dev, DL_INFO,
- "%s: rc=%d detected=0x%02X boot_err=0x%02X\n",
- __func__, rc, detected, last_err);
- if (err_str && last_err) {
- if (detected)
- scnprintf(err_str, PT_ERR_STR_SIZE, "%s 0x%02X",
- "- Likely stuck low. Boot Error:",
- last_err);
- else
- scnprintf(err_str, PT_ERR_STR_SIZE, "%s 0x%02X",
- "- Likely stuck high. Boot Error:",
- last_err);
- }
- /* Ignore an invalid image error as BIST doesn't need valid FW */
- if (last_err == PIP2_RSP_ERR_INVALID_IMAGE)
- last_err = PIP2_RSP_ERR_NONE;
- if (slave_irq_toggled)
- *slave_irq_toggled = (detected && !last_err) ? true : false;
- if (slave_bus_toggled) {
- /* Leave as UNTEST if slave not detected */
- if (detected)
- *slave_bus_toggled = !last_err ? true : false;
- }
- if (slave_detect)
- *slave_detect = detected;
- if (boot_err)
- *boot_err = last_err;
- if (slave_irq_toggled && slave_bus_toggled)
- pt_debug(cd->dev, DL_INFO, "%s: %s=0x%02X, %s=0x%02X, %s=0x%02X\n",
- __func__,
- "Detected", detected,
- "slave_irq_toggled", *slave_irq_toggled,
- "slave_bus_toggled", *slave_bus_toggled);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_bist_slave_xres_test
- *
- * SUMMARY: Tests the connectivity of the Master/Slave TP_XRES net
- *
- * This test will ensure there is a good TP_XRES connection between the
- * master DUT and the slave DUT(s). After toggling the XRES pin to the
- * master, the STATUS command is sent and the 'Slave Detect' bits are
- * verified to ensure the master DUT saw each slave trigger the IRQ with
- * it's reset sentinel.
- *
- * RETURN:
- * 0 = Success
- * !0 = Failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *slave_irq_toggled - pointer to where to store if slave IRQ toggled
- * *slave_bus_toggled - pointer to where to store if slave Bus toggled
- * *slave_xres_toggled - pointer to where to store if slave XRES toggled
- * *err_str - pointer to error string buffer
- ******************************************************************************/
- static int pt_bist_slave_xres_test(struct device *dev,
- u8 *slave_irq_toggled, u8 *slave_bus_toggled, u8 *slave_xres_toggled,
- u8 *err_str)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- u8 slave_detect = 0;
- u8 boot_err = 0;
- int rc = 0;
- /* Force a reset to force the 'slave detect' bits to be re-acquired */
- mutex_lock(&cd->system_lock);
- cd->hid_reset_cmd_state = 1;
- mutex_unlock(&cd->system_lock);
- pt_debug(dev, DL_INFO, "%s: Perform a hard reset\n", __func__);
- pt_hw_hard_reset(cd);
- msleep(100);
- rc = pt_bist_slave_irq_test(dev, slave_irq_toggled,
- slave_bus_toggled, err_str, &slave_detect, &boot_err);
- pt_debug(dev, DL_INFO, "%s: IRQ test rc = %d\n", __func__, rc);
- if (!rc && *slave_irq_toggled == false) {
- /*
- * If the slave IRQ did not toggle, either the slave_detect
- * bit was not set or we had a boot error. If the slave
- * detect was not set the slave did not reset causing a boot
- * error.
- */
- if (!slave_detect)
- strlcpy(err_str, "- likely open.", PT_ERR_STR_SIZE);
- else
- scnprintf(err_str, PT_ERR_STR_SIZE, "%s 0x%02X",
- "- likely open or an IRQ issue. Boot Error:",
- boot_err);
- }
- if (slave_xres_toggled) {
- if (!rc)
- *slave_xres_toggled = *slave_irq_toggled ? true : false;
- else
- *slave_xres_toggled = false;
- }
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_bist_slave_bus_test
- *
- * SUMMARY: Tests the connectivity of the Master/Slave SPI bus net
- *
- * This test will ensure a good SPI bus connection between the
- * master DUT and the slave DUT(s). This bus connection is ensured by
- * opening file 0 (SRAM loader). If there is a slave and the open fails
- * then there is a master/slave communication issue. Opening file 0 on
- * the master will open it on the slave as well if the slave was detected.
- *
- * RETURN:
- * 0 = Success
- * !0 = Failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *slave_irq_toggled - pointer to where to store if slave IRQ toggled
- * *slave_bus_toggled - pointer to where to store if slave Bus toggled
- * *err_str - pointer to error string buffer
- ******************************************************************************/
- static int pt_bist_slave_bus_test(struct device *dev,
- u8 *slave_irq_toggled, u8 *slave_bus_toggled, u8 *err_str)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- u8 mode = PT_MODE_UNKNOWN;
- u8 bus_toggled = false;
- u8 file_handle;
- int result = 0;
- int rc = 0;
- rc = _pt_request_pip2_enter_bl(dev, &mode, &result);
- if (rc) {
- pt_debug(cd->dev, DL_ERROR, "%s: Error entering BL rc=%d\n",
- __func__, rc);
- strlcpy(err_str, "- State could not be determined.", PT_ERR_STR_SIZE);
- goto exit;
- }
- pt_debug(dev, DL_INFO, "%s Attempt open file 0\n", __func__);
- file_handle = _pt_pip2_file_open(dev, PIP2_RAM_FILE);
- if (file_handle != PIP2_RAM_FILE) {
- rc = -ENOENT;
- bus_toggled = false;
- pt_debug(dev, DL_ERROR,
- "%s Failed to open bin file\n", __func__);
- strlcpy(err_str, "- Bus open, shorted or DUT in reset", PT_ERR_STR_SIZE);
- goto exit;
- } else {
- bus_toggled = true;
- if (file_handle != _pt_pip2_file_close(dev, file_handle)) {
- pt_debug(dev, DL_ERROR,
- "%s: File Close failed, file_handle=%d\n",
- __func__, file_handle);
- }
- }
- exit:
- /* If the master was able to send/recv a PIP msg, the IRQ must be ok */
- if (slave_irq_toggled)
- *slave_irq_toggled = bus_toggled;
- if (slave_bus_toggled)
- *slave_bus_toggled = bus_toggled;
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_ttdl_bist_show
- *
- * SUMMARY: Show method for the ttdl_bist sysfs node. This built in self test
- * will test that I2C/SPI, IRQ and TP_XRES pins are operational.
- *
- * NOTE: This function will reset the DUT and the startup_status bit
- * mask. A pt_enum will be queued after completion.
- *
- * NOTE: The order of the net tests is done to optimize the time it takes
- * to run. The first test is capable of verifying all nets, each subsequent
- * test is only run if the previous was not able to see all nets toggle.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *attr - pointer to device attributes
- * *buf - pointer to output buffer
- ******************************************************************************/
- static ssize_t pt_ttdl_bist_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- ssize_t ret;
- char *bus_err_str = NULL;
- char *irq_err_str = NULL;
- char *xres_err_str = NULL;
- char *slave_bus_err_str = NULL;
- char *slave_irq_err_str = NULL;
- char *slave_xres_err_str = NULL;
- u8 tests;
- int rc = 0;
- int num_tests = 0;
- int status = 1; /* 0 = Pass, !0 = fail */
- u8 bus_toggled = 0x0F; /* default to untested */
- u8 i2c_toggled = 0x0F; /* default to untested */
- u8 spi_toggled = 0x0F; /* default to untested */
- u8 irq_toggled = 0x0F; /* default to untested */
- u8 xres_toggled = 0x0F; /* default to untested */
- u8 slave_bus_toggled = 0x0F; /* default to untested */
- u8 slave_irq_toggled = 0x0F; /* default to untested */
- u8 slave_xres_toggled = 0x0F; /* default to untested */
- bus_err_str = kzalloc(PT_ERR_STR_SIZE, GFP_KERNEL);
- irq_err_str = kzalloc(PT_ERR_STR_SIZE, GFP_KERNEL);
- xres_err_str = kzalloc(PT_ERR_STR_SIZE, GFP_KERNEL);
- if (!bus_err_str || !irq_err_str || !xres_err_str)
- goto print_results;
- memset(xres_err_str, 0, PT_ERR_STR_SIZE);
- memset(irq_err_str, 0, PT_ERR_STR_SIZE);
- memset(bus_err_str, 0, PT_ERR_STR_SIZE);
- if (cd->multi_chip) {
- slave_bus_err_str = kzalloc(PT_ERR_STR_SIZE, GFP_KERNEL);
- slave_irq_err_str = kzalloc(PT_ERR_STR_SIZE, GFP_KERNEL);
- slave_xres_err_str = kzalloc(PT_ERR_STR_SIZE, GFP_KERNEL);
- if (!slave_bus_err_str ||
- !slave_irq_err_str ||
- !slave_xres_err_str)
- goto print_results;
- memset(slave_bus_err_str, 0, PT_ERR_STR_SIZE);
- memset(slave_irq_err_str, 0, PT_ERR_STR_SIZE);
- memset(slave_xres_err_str, 0, PT_ERR_STR_SIZE);
- }
- /* Turn off the TTDL WD during the test */
- pt_stop_wd_timer(cd);
- /* Shorten default PIP cmd timeout while running BIST */
- cd->pip_cmd_timeout = 200;
- /* Count the number of tests to run */
- tests = cd->ttdl_bist_select;
- while (tests) {
- num_tests += tests & 1;
- tests >>= 1;
- }
- pt_debug(dev, DL_ERROR, "%s: BIST select = 0x%02X, run %d tests\n",
- __func__, cd->ttdl_bist_select, num_tests);
- /* Suppress auto BL to avoid loader thread sending PIP during xres */
- if (cd->flashless_dut) {
- pt_debug(dev, DL_INFO, "%s Flashless Auto_BL - SUPPRESS\n",
- __func__);
- mutex_lock(&cd->system_lock);
- cd->flashless_auto_bl = PT_SUPPRESS_AUTO_BL;
- mutex_unlock(&cd->system_lock);
- }
- /* --------------- TP_XRES BIST TEST --------------- */
- if ((cd->ttdl_bist_select & PT_TTDL_BIST_TP_XRES_TEST) != 0) {
- pt_debug(dev, DL_INFO,
- "%s: ----- Start TP_XRES BIST -----", __func__);
- rc = pt_bist_xres_test(dev, &bus_toggled, &irq_toggled,
- &xres_toggled, xres_err_str);
- /* Done if the rest of all nets toggled */
- if (bus_toggled == 1 && irq_toggled == 1 && xres_toggled == 1)
- goto host_nets_complete;
- }
- /* Flush bus in case a PIP response is waiting from previous test */
- pt_flush_bus(cd, PT_FLUSH_BUS_BASED_ON_LEN, NULL);
- /* --------------- IRQ BIST TEST --------------- */
- if ((cd->ttdl_bist_select & PT_TTDL_BIST_IRQ_TEST) != 0) {
- pt_debug(dev, DL_INFO,
- "%s: ----- Start IRQ BIST -----", __func__);
- bus_toggled = 0xFF;
- irq_toggled = 0xFF;
- rc = pt_bist_irq_test(dev, &bus_toggled, &irq_toggled,
- &xres_toggled, irq_err_str);
- /* If this net failed clear results from previous net */
- if (irq_toggled != 1) {
- xres_toggled = 0x0F;
- memset(xres_err_str, 0, PT_ERR_STR_SIZE);
- }
- if (bus_toggled == 1 && irq_toggled == 1)
- goto host_nets_complete;
- }
- /* Flush bus in case a PIP response is waiting from previous test */
- pt_flush_bus(cd, PT_FLUSH_BUS_BASED_ON_LEN, NULL);
- /* --------------- BUS BIST TEST --------------- */
- if ((cd->ttdl_bist_select & PT_TTDL_BIST_BUS_TEST) != 0) {
- pt_debug(dev, DL_INFO,
- "%s: ----- Start BUS BIST -----", __func__);
- bus_toggled = 0xFF;
- rc = pt_bist_bus_test(dev, &bus_toggled, bus_err_str);
- /* If this net failed clear results from previous net */
- if (bus_toggled == 0) {
- irq_toggled = 0x0F;
- memset(irq_err_str, 0, PT_ERR_STR_SIZE);
- }
- }
- host_nets_complete:
- /* --------------- SLAVE XRES BIST TEST --------------- */
- if (cd->multi_chip &&
- (cd->ttdl_bist_select & PT_TTDL_BIST_SLAVE_XRES_TEST) != 0) {
- pt_debug(dev, DL_INFO,
- "%s: ----- Start Slave XRES BIST -----", __func__);
- slave_xres_toggled = 0xFF;
- rc = pt_bist_slave_xres_test(dev, &slave_irq_toggled,
- &slave_bus_toggled, &slave_xres_toggled,
- slave_xres_err_str);
- if ((slave_bus_toggled == 1 && slave_irq_toggled == 1 &&
- slave_xres_toggled == 1) || slave_xres_toggled == 0)
- goto print_results;
- }
- /* --------------- SLAVE IRQ BIST TEST --------------- */
- if (cd->multi_chip &&
- (cd->ttdl_bist_select & PT_TTDL_BIST_SLAVE_IRQ_TEST) != 0) {
- pt_debug(dev, DL_INFO,
- "%s: ----- Start Slave IRQ BIST -----", __func__);
- slave_irq_toggled = 0xFF;
- rc = pt_bist_slave_irq_test(dev, &slave_irq_toggled,
- &slave_bus_toggled, slave_irq_err_str, NULL, NULL);
- pt_debug(dev, DL_INFO, "%s: slave_irq_toggled = 0x%02X\n",
- __func__, slave_irq_toggled);
- if (slave_irq_toggled == 1) {
- slave_bus_toggled = 1;
- goto print_results;
- }
- }
- /* --------------- SLAVE BUS BIST TEST --------------- */
- if (cd->multi_chip &&
- (cd->ttdl_bist_select & PT_TTDL_BIST_SLAVE_BUS_TEST) != 0) {
- pt_debug(dev, DL_INFO,
- "%s: ----- Start Slave BUS BIST -----", __func__);
- slave_bus_toggled = 0xFF;
- rc = pt_bist_slave_bus_test(dev, &slave_irq_toggled,
- &slave_bus_toggled, slave_bus_err_str);
- }
- print_results:
- /* Restore PIP command timeout */
- cd->pip_cmd_timeout = cd->pip_cmd_timeout_default;
- /*
- * We're done! - Perform a hard XRES toggle, allowing BL
- * to load FW if there is any in Flash
- */
- mutex_lock(&cd->system_lock);
- cd->hid_reset_cmd_state = 0;
- mutex_unlock(&cd->system_lock);
- pt_debug(dev, DL_INFO,
- "%s: TTDL BIST Complete - Final reset\n", __func__);
- if (cd->flashless_dut) {
- /*
- * For Flashless solution, FW update is triggered after BL is
- * seen that several miliseconds delay is needed.
- */
- pt_debug(dev, DL_INFO, "%s Flashless Auto_BL - ALLOW\n",
- __func__);
- mutex_lock(&cd->system_lock);
- cd->flashless_auto_bl = PT_ALLOW_AUTO_BL;
- mutex_unlock(&cd->system_lock);
- /* Reset DUT and wait 100ms to see if loader started */
- pt_hw_hard_reset(cd);
- msleep(100);
- if (cd->fw_updating) {
- pt_debug(dev, DL_INFO,
- "%s: ----- BIST Wait FW Loading ----",
- __func__);
- rc = _pt_request_wait_for_enum_state(
- dev, 4000, STARTUP_STATUS_COMPLETE);
- }
- } else {
- if (cd->mode == PT_MODE_BOOTLOADER) {
- rc = pt_pip2_launch_app(dev, PT_CORE_CMD_PROTECTED);
- if (rc) {
- pt_debug(dev, DL_ERROR,
- "%s Failed to launch app\n", __func__);
- rc = pt_hw_hard_reset(cd);
- }
- }
- /*
- * If FW exists the BL may have just started or will start soon,
- * so the FW sentinel may be on it's way but with no FW it will
- * not arrive, wait for it before deciding if we need to queue
- * an enum.
- */
- rc = _pt_request_wait_for_enum_state(
- dev, 400, STARTUP_STATUS_FW_RESET_SENTINEL);
- if ((cd->startup_status & STARTUP_STATUS_FW_RESET_SENTINEL) &&
- (cd->startup_status & STARTUP_STATUS_COMPLETE) == 0) {
- pt_debug(dev, DL_INFO, "%s: ----- BIST Enum ----",
- __func__);
- pt_queue_enum(cd);
- rc = _pt_request_wait_for_enum_state(
- dev, 2000, STARTUP_STATUS_COMPLETE);
- }
- }
- msleep(20);
- /* --------------- PRINT OUT BIST RESULTS ---------------*/
- pt_debug(dev, DL_INFO, "%s: ----- BIST Print Results ----", __func__);
- pt_start_wd_timer(cd);
- /* Canned print if any memory allocation issues */
- if (!bus_err_str || !irq_err_str || !xres_err_str) {
- ret = scnprintf(buf, strlen(buf),
- "Status: %d\n"
- "I2C (SDA,SCL): [UNTEST]\n"
- "SPI (MISO,MOSI,CS,CLK): [UNTEST]\n"
- "IRQ connection: [UNTEST]\n"
- "TP_XRES connection: [UNTEST]\n", -ENOMEM);
- if (cd->multi_chip) {
- ret += scnprintf(buf + ret, strlen(buf),
- "I/P SPI (MISO,MOSI,CS,CLK): [UNTEST]\n"
- "I/P IRQ connection: [UNTEST]\n"
- "I/P TP_XRES connection: [UNTEST]\n");
- }
- } else {
- status = 0;
- if (bus_toggled == 1)
- memset(bus_err_str, 0, PT_ERR_STR_SIZE);
- if (irq_toggled == 1)
- memset(irq_err_str, 0, PT_ERR_STR_SIZE);
- if (xres_toggled == 1)
- memset(xres_err_str, 0, PT_ERR_STR_SIZE);
- if (cd->ttdl_bist_select & PT_TTDL_BIST_BUS_TEST)
- status += bus_toggled;
- if (cd->ttdl_bist_select & PT_TTDL_BIST_IRQ_TEST)
- status += irq_toggled;
- if (cd->ttdl_bist_select & PT_TTDL_BIST_TP_XRES_TEST)
- status += xres_toggled;
- pt_debug(dev, DL_ERROR, "%s: status = %d (%d,%d,%d)\n",
- __func__, status, bus_toggled, irq_toggled,
- xres_toggled);
- if (cd->multi_chip) {
- if (slave_irq_toggled == 1)
- memset(slave_irq_err_str, 0, PT_ERR_STR_SIZE);
- if (slave_xres_toggled == 1)
- memset(slave_xres_err_str, 0, PT_ERR_STR_SIZE);
- if (slave_bus_toggled == 1)
- memset(slave_bus_err_str, 0, PT_ERR_STR_SIZE);
- if (cd->ttdl_bist_select & PT_TTDL_BIST_SLAVE_BUS_TEST)
- status += slave_bus_toggled;
- if (cd->ttdl_bist_select & PT_TTDL_BIST_SLAVE_IRQ_TEST)
- status += slave_irq_toggled;
- if (cd->ttdl_bist_select & PT_TTDL_BIST_SLAVE_XRES_TEST)
- status += slave_xres_toggled;
- pt_debug(dev, DL_ERROR,
- "%s: status = %d (%d,%d,%d,%d,%d,%d)\n",
- __func__, status, bus_toggled, irq_toggled,
- xres_toggled, slave_bus_toggled,
- slave_irq_toggled, slave_xres_toggled);
- }
- if (cd->bus_ops->bustype == BUS_I2C)
- i2c_toggled = bus_toggled;
- else
- spi_toggled = bus_toggled;
- ret = scnprintf(buf, strlen(buf),
- "Status: %d\n"
- "I2C (SDA,SCL): %s %s\n"
- "SPI (MISO,MOSI,CS,CLK): %s %s\n"
- "IRQ connection: %s %s\n"
- "TP_XRES connection: %s %s\n",
- status == num_tests ? 0 : 1,
- i2c_toggled == 0x0F ? "[UNTEST]" :
- i2c_toggled == 1 ? "[ OK ]" : "[FAILED]",
- i2c_toggled == 0x0F ? "" : bus_err_str,
- spi_toggled == 0x0F ? "[UNTEST]" :
- spi_toggled == 1 ? "[ OK ]" : "[FAILED]",
- spi_toggled == 0x0F ? "" : bus_err_str,
- irq_toggled == 0x0F ? "[UNTEST]" :
- irq_toggled == 1 ? "[ OK ]" : "[FAILED]",
- irq_err_str,
- xres_toggled == 0x0F ? "[UNTEST]" :
- xres_toggled == 1 ? "[ OK ]" : "[FAILED]",
- xres_err_str);
- if (cd->multi_chip) {
- ret += scnprintf(buf + ret, strlen(buf),
- "I/P SPI (MISO,MOSI,CS,CLK): %s %s\n"
- "I/P IRQ connection: %s %s\n"
- "I/P TP_XRES connection: %s %s\n",
- slave_bus_toggled == 0x0F ? "[UNTEST]" :
- slave_bus_toggled == 1 ? "[ OK ]" :
- "[FAILED]", slave_bus_err_str,
- slave_irq_toggled == 0x0F ? "[UNTEST]" :
- slave_irq_toggled == 1 ? "[ OK ]" :
- "[FAILED]", slave_irq_err_str,
- slave_xres_toggled == 0x0F ? "[UNTEST]" :
- slave_xres_toggled == 1 ? "[ OK ]" :
- "[FAILED]", slave_xres_err_str);
- }
- }
- /* Put TTDL back into a known state, issue a ttdl enum if needed */
- pt_debug(dev, DL_INFO, "%s: Startup_status = 0x%04X\n",
- __func__, cd->startup_status);
- kfree(bus_err_str);
- kfree(irq_err_str);
- kfree(xres_err_str);
- return ret;
- }
- /*******************************************************************************
- * FUNCTION: pt_ttdl_bist_store
- *
- * SUMMARY: Store method for the ttdl_bist sysfs node.
- *
- * RETURN: Size of passed in buffer if successful
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *attr - pointer to device attributes
- * *buf - pointer to command buffer
- * size - size of buf
- ******************************************************************************/
- static ssize_t pt_ttdl_bist_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t size)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- u32 input_data[2] = {0};
- int length;
- int rc = 0;
- /* Maximum input of one value */
- length = _pt_ic_parse_input(dev, buf, size, input_data,
- ARRAY_SIZE(input_data));
- if (length != 1) {
- pt_debug(dev, DL_ERROR, "%s: Invalid number of arguments\n",
- __func__);
- rc = -EINVAL;
- goto exit;
- } else {
- mutex_lock(&cd->system_lock);
- cd->ttdl_bist_select = input_data[0];
- mutex_unlock(&cd->system_lock);
- }
- exit:
- if (rc)
- return rc;
- return size;
- }
- static DEVICE_ATTR(ttdl_bist, 0644, pt_ttdl_bist_show,
- pt_ttdl_bist_store);
- /*******************************************************************************
- * FUNCTION: pt_flush_bus_store
- *
- * SUMMARY: Store method for the flush_bus sysfs node.
- *
- * RETURN: Size of passed in buffer if successful
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *attr - pointer to device attributes
- * *buf - pointer to command buffer
- * size - size of buf
- ******************************************************************************/
- static ssize_t pt_flush_bus_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t size)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- u32 input_data[2] = {0};
- int length;
- int rc = 0;
- /* Maximum input of one value */
- length = _pt_ic_parse_input(dev, buf, size, input_data,
- ARRAY_SIZE(input_data));
- if (length != 1) {
- pt_debug(dev, DL_ERROR, "%s: Invalid number of arguments\n",
- __func__);
- rc = -EINVAL;
- goto exit;
- }
- mutex_lock(&cd->system_lock);
- if (input_data[0] == 0)
- cd->flush_bus_type = PT_FLUSH_BUS_BASED_ON_LEN;
- else if (input_data[0] == 1)
- cd->flush_bus_type = PT_FLUSH_BUS_FULL_256_READ;
- else
- rc = -EINVAL;
- mutex_unlock(&cd->system_lock);
- exit:
- if (rc)
- return rc;
- return size;
- }
- /*******************************************************************************
- * FUNCTION: pt_flush_bus_show
- *
- * SUMMARY: Show method for the flush_bus sysfs node that flushes the active bus
- * based on either the size of the first two bytes or a blind 256 bytes.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *attr - pointer to device attributes
- * *buf - pointer to output buffer
- ******************************************************************************/
- static ssize_t pt_flush_bus_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- ssize_t ret = 0;
- ssize_t bytes = 0;
- struct pt_core_data *cd = dev_get_drvdata(dev);
- mutex_lock(&cd->system_lock);
- bytes = pt_flush_bus(cd, cd->flush_bus_type, NULL);
- ret = scnprintf(buf, strlen(buf),
- "Status: 0\n"
- "%s: %zd\n",
- "Bytes flushed", bytes);
- mutex_unlock(&cd->system_lock);
- return ret;
- }
- static DEVICE_ATTR(flush_bus, 0644, pt_flush_bus_show,
- pt_flush_bus_store);
- /*******************************************************************************
- * FUNCTION: pt_pip2_ping_test_store
- *
- * SUMMARY: Store method for the pip2_ping_test sysfs node.
- *
- * NOTE: The max PIP2 packet size is 255 (payload for PING 247) however
- * someone may want to test sending invalid packet lengths so any values
- * up to 255 are allowed.
- *
- * RETURN: Size of passed in buffer if successful
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *attr - pointer to device attributes
- * *buf - pointer to command buffer
- * size - size of buf
- ******************************************************************************/
- static ssize_t pt_pip2_ping_test_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t size)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- u32 input_data[2];
- int length;
- int rc = 0;
- /* Maximum input of one value */
- length = _pt_ic_parse_input(dev, buf, size, input_data,
- ARRAY_SIZE(input_data));
- if (length != 1) {
- pt_debug(dev, DL_ERROR, "%s: Invalid number of arguments\n",
- __func__);
- rc = -EINVAL;
- goto exit;
- }
- mutex_lock(&cd->system_lock);
- if (input_data[1] >= 0 && input_data[0] <= PT_MAX_PIP2_MSG_SIZE)
- cd->ping_test_size = input_data[0];
- else
- rc = -EINVAL;
- mutex_unlock(&cd->system_lock);
- exit:
- if (rc)
- return rc;
- return size;
- }
- /*******************************************************************************
- * FUNCTION: pt_ping_test_show
- *
- * SUMMARY: Show method for the ping_test_show sysfs node that sends the PIP2
- * PING command and ramps up the optional payload from 0 to
- * ping_test_size.
- * The max payload size is 247:
- * (255 - 2 byte reg address - 4 byte header - 2 byte CRC)
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *attr - pointer to device attributes
- * *buf - pointer to output buffer
- ******************************************************************************/
- static ssize_t pt_pip2_ping_test_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- ssize_t ret;
- int last_packet_size;
- int rc = 0;
- rc = pt_pip2_ping_test(dev, cd->ping_test_size, &last_packet_size);
- if (rc) {
- ret = scnprintf(buf, strlen(buf), "Status: %d\n", rc);
- return ret;
- }
- ret = scnprintf(buf, strlen(buf),
- "Status: %d\n"
- "PING payload test passed with packet sizes 0 - %d\n",
- (last_packet_size == cd->ping_test_size ? 0 : 1),
- last_packet_size);
- return ret;
- }
- /*******************************************************************************
- * FUNCTION: pt_t_refresh_store
- *
- * SUMMARY: Store method for the t-refresh sysfs node that will takes a passed
- * in integer as the number of interrupts to count. A timer is started to
- * calculate the total time it takes to see that number of interrupts.
- *
- * RETURN: Size of passed in buffer if successful
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *attr - pointer to device attributes
- * *buf - pointer to buffer that hold the command parameters
- * size - size of buf
- ******************************************************************************/
- static ssize_t pt_t_refresh_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t size)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- u32 input_data[2];
- int length;
- int rc = 0;
- /* Maximum input of one value */
- length = _pt_ic_parse_input(dev, buf, size, input_data,
- ARRAY_SIZE(input_data));
- if (length != 1) {
- pt_debug(dev, DL_ERROR, "%s: Invalid number of arguments\n",
- __func__);
- rc = -EINVAL;
- goto exit;
- }
- mutex_lock(&cd->system_lock);
- pt_debug(dev, DL_INFO, "%s: Input value: %d\n", __func__,
- input_data[0]);
- if (input_data[0] >= 0 && input_data[0] <= 1000) {
- cd->t_refresh_total = input_data[0];
- cd->t_refresh_count = 0;
- cd->t_refresh_active = 1;
- } else {
- pt_debug(dev, DL_ERROR, "%s: Invalid value\n", __func__);
- rc = -EINVAL;
- }
- mutex_unlock(&cd->system_lock);
- exit:
- pt_debug(dev, DL_ERROR, "%s: rc = %d\n", __func__, rc);
- if (rc)
- return rc;
- return size;
- }
- /*******************************************************************************
- * FUNCTION: pt_t_refresh_show
- *
- * SUMMARY: Show method for the t-refresh sysfs node that will show the results
- * of the T-Refresh timer counting the time it takes to see a user defined
- * number of interrupts.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *attr - pointer to device attributes
- * *buf - pointer to output buffer
- ******************************************************************************/
- static ssize_t pt_t_refresh_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- ssize_t ret = 0;
- struct pt_core_data *cd = dev_get_drvdata(dev);
- u32 whole;
- u16 fraction;
- mutex_lock(&cd->system_lock);
- /* Check if we have counted the number requested */
- if (cd->t_refresh_count != cd->t_refresh_total) {
- ret = scnprintf(buf, strlen(buf),
- "Status: 0\n"
- "%s: %d\n",
- "Still counting... current IRQ count",
- cd->t_refresh_count);
- } else {
- /* Ensure T-Refresh is de-activated */
- cd->t_refresh_active = 0;
- whole = cd->t_refresh_time / cd->t_refresh_count;
- fraction = cd->t_refresh_time % cd->t_refresh_count;
- fraction = fraction * 1000 / cd->t_refresh_count;
- ret = scnprintf(buf, strlen(buf),
- "Status: 0\n"
- "%s: %d\n"
- "%s: %d\n"
- "%s: %d\n"
- "%s: %d.%02d\n",
- "Requested IRQ Count ", cd->t_refresh_total,
- "IRQ Counted ", cd->t_refresh_count,
- "Total Time Elapsed (ms) ", (int)cd->t_refresh_time,
- "Average T-Refresh (ms) ", whole, fraction);
- }
- mutex_unlock(&cd->system_lock);
- return ret;
- }
- /*******************************************************************************
- * FUNCTION: pt_dut_status_show
- *
- * SUMMARY: Show method for DUT status sysfs node. Display DUT's scan state, and
- * more items such as operation mode,easywake state are added in the future.
- *
- * RETURN: Char buffer with printed scan status information
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *attr - pointer to device attributes
- * *buf - pointer to output buffer
- ******************************************************************************/
- static ssize_t pt_dut_status_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- u8 sys_mode = FW_SYS_MODE_UNDEFINED;
- u8 mode = PT_MODE_UNKNOWN;
- char *outputstring[7] = {"BOOT", "SCANNING", "DEEP_SLEEP",
- "TEST", "DEEP_STANDBY", "UNDEFINED", "n/a"};
- struct pt_core_data *cd = dev_get_drvdata(dev);
- ssize_t ret;
- u16 calculated_crc = 0;
- u16 stored_crc = 0;
- u8 status;
- int rc = 0;
- /* In STANDBY the DUT will not repond to any PIP cmd */
- if (cd->fw_sys_mode_in_standby_state) {
- mode = PT_MODE_OPERATIONAL;
- sys_mode = FW_SYS_MODE_DEEP_STANDBY;
- goto print_limited_results;
- }
- /* Retrieve mode and FW system mode which can only be 0-4 */
- rc = pt_get_fw_sys_mode(cd, &sys_mode, &mode);
- if (rc || mode == PT_MODE_UNKNOWN) {
- ret = scnprintf(buf, PT_MAX_PRBUF_SIZE,
- "%s: %d\n"
- "%s: n/a\n"
- "%s: n/a\n"
- "%s: n/a\n"
- "%s: n/a\n",
- "Status", rc,
- "Active Exec ",
- "FW System Mode ",
- "Stored CRC ",
- "Calculated CRC ");
- return ret;
- } else {
- if (mode == PT_MODE_OPERATIONAL) {
- if (sys_mode > FW_SYS_MODE_MAX)
- sys_mode = FW_SYS_MODE_UNDEFINED;
- if (sys_mode != FW_SYS_MODE_TEST)
- goto print_limited_results;
- rc = pt_pip_verify_config_block_crc_(cd,
- PT_TCH_PARM_EBID, &status,
- &calculated_crc, &stored_crc);
- if (rc)
- goto print_limited_results;
- ret = scnprintf(buf, PT_MAX_PRBUF_SIZE,
- "%s: %d\n"
- "%s: %s\n"
- "%s: %s\n"
- "%s: 0x%04X\n"
- "%s: 0x%04X\n",
- "Status", rc,
- "Active Exec ", "FW",
- "FW System Mode ", outputstring[sys_mode],
- "Stored CRC ", stored_crc,
- "Calculated CRC ", calculated_crc);
- return ret;
- } else {
- /* When in BL or unknon mode Active Exec is "n/a" */
- sys_mode = FW_SYS_MODE_UNDEFINED + 1;
- }
- }
- print_limited_results:
- ret = scnprintf(buf, PT_MAX_PRBUF_SIZE,
- "%s: %d\n"
- "%s: %s\n"
- "%s: %s\n"
- "%s: n/a\n"
- "%s: n/a\n",
- "Status", rc,
- "Active Exec ",
- mode == PT_MODE_OPERATIONAL ? "FW" : "BL",
- "FW System Mode ", outputstring[sys_mode],
- "Stored CRC ",
- "Calculated CRC ");
- return ret;
- }
- #endif /* TTDL_DIAGNOSTICS */
- /*******************************************************************************
- * Structures of sysfs attributes for all DUT dependent sysfs node
- ******************************************************************************/
- static struct attribute *early_attrs[] = {
- &dev_attr_hw_version.attr,
- &dev_attr_drv_version.attr,
- &dev_attr_drv_ver.attr,
- &dev_attr_fw_version.attr,
- &dev_attr_sysinfo.attr,
- &dev_attr_pip2_cmd_rsp.attr,
- &dev_attr_command.attr,
- &dev_attr_drv_debug.attr,
- &dev_attr_hw_reset.attr,
- &dev_attr_response.attr,
- &dev_attr_ttdl_restart.attr,
- #ifdef TTDL_DIAGNOSTICS
- &dev_attr_ttdl_status.attr,
- &dev_attr_pip2_enter_bl.attr,
- &dev_attr_pip2_exit_bl.attr,
- &dev_attr_err_gpio.attr,
- &dev_attr_flush_bus.attr,
- &dev_attr_ttdl_bist.attr,
- #endif /* TTDL_DIAGNOSTICS */
- NULL,
- };
- static struct attribute_group early_attr_group = {
- .attrs = early_attrs,
- };
- static struct device_attribute pip2_attributes[] = {
- __ATTR(pip2_version, 0444, pt_pip2_version_show, NULL),
- __ATTR(pip2_gpio_read, 0444, pt_pip2_gpio_read_show, NULL),
- #ifdef TTDL_DIAGNOSTICS
- __ATTR(pip2_bin_hdr, 0444, pt_pip2_bin_hdr_show, NULL),
- __ATTR(pip2_ping_test, 0644, pt_pip2_ping_test_show,
- pt_pip2_ping_test_store),
- #endif
- };
- static struct device_attribute attributes[] = {
- __ATTR(dut_debug, 0644,
- pt_dut_debug_show, pt_drv_debug_store),
- __ATTR(sleep_status, 0444, pt_sleep_status_show, NULL),
- __ATTR(panel_id, 0444, pt_panel_id_show, NULL),
- __ATTR(get_param, 0644,
- pt_get_param_show, pt_get_param_store),
- __ATTR(pt_touch_offload, 0644,
- pt_touch_offload_show, pt_touch_offload_store),
- #ifdef EASYWAKE_TSG6
- __ATTR(easy_wakeup_gesture, 0644, pt_easy_wakeup_gesture_show,
- pt_easy_wakeup_gesture_store),
- __ATTR(easy_wakeup_gesture_id, 0444,
- pt_easy_wakeup_gesture_id_show, NULL),
- __ATTR(easy_wakeup_gesture_data, 0444,
- pt_easy_wakeup_gesture_data_show, NULL),
- #endif
- #ifdef TTDL_DIAGNOSTICS
- __ATTR(platform_data, 0444, pt_platform_data_show, NULL),
- __ATTR(drv_irq, 0644, pt_drv_irq_show, pt_drv_irq_store),
- __ATTR(dut_status, 0444, pt_dut_status_show, NULL),
- __ATTR(t_refresh, 0644, pt_t_refresh_show, pt_t_refresh_store),
- #endif /* TTDL_DIAGNOSTICS */
- };
- /*******************************************************************************
- * FUNCTION: add_sysfs_interfaces
- *
- * SUMMARY: Creates all DUT dependent sysfs nodes owned by the core
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- ******************************************************************************/
- static int add_sysfs_interfaces(struct device *dev)
- {
- int i;
- int j = 0;
- struct pt_core_data *cd = dev_get_drvdata(dev);
- for (i = 0; i < ARRAY_SIZE(attributes); i++) {
- if (device_create_file(dev, attributes + i))
- goto undo;
- }
- pt_debug(dev, DL_INFO, "%s: Active DUT Generation: %d",
- __func__, cd->active_dut_generation);
- if (cd->active_dut_generation == DUT_PIP2_CAPABLE) {
- for (j = 0; j < ARRAY_SIZE(pip2_attributes); j++) {
- if (device_create_file(dev, pip2_attributes + j))
- goto undo;
- }
- }
- return 0;
- undo:
- for (i--; i >= 0; i--)
- device_remove_file(dev, attributes + i);
- for (j--; j >= 0; j--)
- device_remove_file(dev, pip2_attributes + j);
- pt_debug(dev, DL_ERROR, "%s: failed to create sysfs interface\n",
- __func__);
- return -ENODEV;
- }
- /*******************************************************************************
- * FUNCTION: remove_sysfs_interfaces
- *
- * SUMMARY: Removes all DUT dependent sysfs nodes owned by the core
- *
- * RETURN: void
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- ******************************************************************************/
- static void remove_sysfs_interfaces(struct device *dev)
- {
- int i;
- for (i = 0; i < ARRAY_SIZE(attributes); i++)
- device_remove_file(dev, attributes + i);
- for (i = 0; i < ARRAY_SIZE(pip2_attributes); i++)
- device_remove_file(dev, pip2_attributes + i);
- }
- /*******************************************************************************
- * FUNCTION: remove_sysfs_and_modules
- *
- * SUMMARY: Removes all DUT dependent sysfs nodes and modules
- *
- * RETURN: void
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- ******************************************************************************/
- static void remove_sysfs_and_modules(struct device *dev)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- /* Queued work should be removed before to release loader module */
- call_atten_cb(cd, PT_ATTEN_CANCEL_LOADER, 0);
- pt_release_modules(cd);
- pt_btn_release(dev);
- pt_mt_release(dev);
- remove_sysfs_interfaces(dev);
- }
- static int pt_ts_pinctrl_init(struct pt_core_data *cd)
- {
- int retval;
- /* Get pinctrl if target uses pinctrl */
- cd->ts_pinctrl = devm_pinctrl_get(cd->dev);
- if (IS_ERR_OR_NULL(cd->ts_pinctrl)) {
- retval = PTR_ERR(cd->ts_pinctrl);
- dev_dbg(cd->dev,
- "Target does not use pinctrl %d\n", retval);
- goto err_pinctrl_get;
- }
- cd->pinctrl_state_active
- = pinctrl_lookup_state(cd->ts_pinctrl,
- PINCTRL_STATE_ACTIVE);
- if (IS_ERR_OR_NULL(cd->pinctrl_state_active)) {
- retval = PTR_ERR(cd->pinctrl_state_active);
- dev_err(cd->dev,
- "Can not lookup %s pinstate %d\n",
- PINCTRL_STATE_ACTIVE, retval);
- goto err_pinctrl_lookup;
- }
- cd->pinctrl_state_suspend
- = pinctrl_lookup_state(cd->ts_pinctrl,
- PINCTRL_STATE_SUSPEND);
- if (IS_ERR_OR_NULL(cd->pinctrl_state_suspend)) {
- retval = PTR_ERR(cd->pinctrl_state_suspend);
- dev_err(cd->dev,
- "Can not lookup %s pinstate %d\n",
- PINCTRL_STATE_SUSPEND, retval);
- goto err_pinctrl_lookup;
- }
- cd->pinctrl_state_release
- = pinctrl_lookup_state(cd->ts_pinctrl,
- PINCTRL_STATE_RELEASE);
- if (IS_ERR_OR_NULL(cd->pinctrl_state_release)) {
- retval = PTR_ERR(cd->pinctrl_state_release);
- dev_dbg(cd->dev,
- "Can not lookup %s pinstate %d\n",
- PINCTRL_STATE_RELEASE, retval);
- }
- return 0;
- err_pinctrl_lookup:
- devm_pinctrl_put(cd->ts_pinctrl);
- err_pinctrl_get:
- cd->ts_pinctrl = NULL;
- return retval;
- }
- void touch_notify_glink_pt_channel_state(bool state)
- {
- pr_info("%s:[touch] touch_notify_glink\n", __func__);
- }
- void glink_touch_pt_rx_msg(void *data, int len)
- {
- int rc = 0;
- pr_info("%s: TOUCH_RX_MSG Start:\n", __func__);
- if (len > TOUCH_GLINK_INTENT_SIZE) {
- pr_err("Invalid TOUCH glink intent size\n");
- return;
- }
- /* check SLATE response */
- pt_slate_resp_ack = *(uint32_t *)&data[8];
- if (pt_slate_resp_ack == 0x01) {
- pr_err("Bad SLATE response\n");
- rc = -EINVAL;
- goto err_ret;
- }
- pr_info("%s: TOUCH_RX_MSG End:\n", __func__);
- err_ret:
- return;
- }
- /*******************************************************************************
- *******************************************************************************
- * FUNCTION: pt_probe
- *
- * SUMMARY: Probe of the core module.
- *
- * NOTE: For the Parade Technologies development platform (PtSBC) the
- * probe functionality is split into two functions; pt_probe() and
- * pt_probe_complete(). the initial setup is done in this function which
- * then creates a WORK task which runs after the probe timer expires. This
- * ensures the I2C/SPI is up on the PtSBC in time for TTDL.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *ops - pointer to the bus
- * *dev - pointer to the device structure
- * irq - IRQ
- * xfer_buf_size - size of the buffer
- ******************************************************************************/
- int pt_probe(const struct pt_bus_ops *ops, struct device *dev,
- u16 irq, size_t xfer_buf_size)
- {
- struct pt_core_data *cd;
- struct pt_platform_data *pdata = dev_get_platdata(dev);
- enum pt_atten_type type;
- struct i2c_client *client = to_i2c_client(dev);
- int rc = 0;
- u8 pip_ver_major;
- u8 pip_ver_minor;
- u32 status = STARTUP_STATUS_START;
- if (!pdata || !pdata->core_pdata || !pdata->mt_pdata) {
- pt_debug(dev, DL_ERROR, "%s: Missing platform data\n",
- __func__);
- rc = -ENODEV;
- goto error_no_pdata;
- }
- if (pdata->core_pdata->flags & PT_CORE_FLAG_POWEROFF_ON_SLEEP) {
- if (!pdata->core_pdata->power) {
- pt_debug(dev, DL_ERROR,
- "%s: Missing platform data function\n",
- __func__);
- rc = -ENODEV;
- goto error_no_pdata;
- }
- }
- /* get context and debug print buffers */
- cd = kzalloc(sizeof(*cd), GFP_KERNEL);
- if (!cd) {
- rc = -ENOMEM;
- goto error_no_pdata;
- }
- /* Initialize device info */
- cd->dev = dev;
- cd->pdata = pdata;
- cd->cpdata = pdata->core_pdata;
- cd->bus_ops = ops;
- cd->debug_level = PT_INITIAL_DEBUG_LEVEL;
- cd->show_timestamp = PT_INITIAL_SHOW_TIME_STAMP;
- scnprintf(cd->core_id, 20, "%s%d", PT_CORE_NAME, core_number++);
- cd->hw_detected = false;
- cd->pip2_prot_active = false;
- cd->pip2_send_user_cmd = false;
- cd->bl_pip_ver_ready = false;
- cd->app_pip_ver_ready = false;
- cd->pip2_cmd_tag_seq = 0x08; /* PIP2 TAG=1 and 3 bit SEQ=0 */
- cd->get_param_id = 0;
- cd->watchdog_enabled = 0;
- cd->startup_retry_count = 0;
- cd->core_probe_complete = 0;
- cd->fw_system_mode = FW_SYS_MODE_BOOT;
- cd->pip_cmd_timeout = PT_PIP_CMD_DEFAULT_TIMEOUT;
- cd->pip_cmd_timeout_default = PT_PIP_CMD_DEFAULT_TIMEOUT;
- cd->flashless_dut = 0;
- cd->flashless_auto_bl = PT_SUPPRESS_AUTO_BL;
- cd->bl_with_no_int = 0;
- cd->cal_cache_in_host = PT_FEATURE_DISABLE;
- cd->multi_chip = PT_FEATURE_DISABLE;
- cd->tthe_hid_usb_format = PT_FEATURE_DISABLE;
- cd->sleep_state = SS_SLEEP_NONE;
- cd->quick_boot = false;
- cd->drv_debug_suspend = false;
- cd->touch_offload = false;
- if (cd->cpdata->config_dut_generation == CONFIG_DUT_PIP2_CAPABLE) {
- cd->set_dut_generation = true;
- cd->active_dut_generation = DUT_PIP2_CAPABLE;
- } else if (cd->cpdata->config_dut_generation == CONFIG_DUT_PIP1_ONLY) {
- cd->set_dut_generation = true;
- cd->active_dut_generation = DUT_PIP1_ONLY;
- } else {
- cd->set_dut_generation = false;
- cd->active_dut_generation = DUT_UNKNOWN;
- }
- /* Initialize with platform data */
- cd->watchdog_force_stop = cd->cpdata->watchdog_force_stop;
- cd->watchdog_interval = PT_WATCHDOG_TIMEOUT;
- cd->hid_cmd_state = 1;
- cd->fw_updating = false;
- cd->multi_chip = 0;
- #ifdef TTDL_DIAGNOSTICS
- cd->t_refresh_active = 0;
- cd->t_refresh_count = 0;
- cd->pip2_crc_error_count = 0;
- cd->wd_xres_count = 0;
- cd->bl_retry_packet_count = 0;
- cd->file_erase_timeout_count = 0;
- cd->show_tt_data = false;
- cd->flush_bus_type = PT_FLUSH_BUS_BASED_ON_LEN;
- cd->err_gpio = 0;
- cd->err_gpio_type = PT_ERR_GPIO_NONE;
- cd->ttdl_bist_select = 0x07;
- cd->force_pip2_seq = 0;
- #endif /* TTDL_DIAGNOSTICS */
- memset(cd->pip2_us_file_path, 0, PT_MAX_PATH_SIZE);
- memcpy(cd->pip2_us_file_path, PT_PIP2_BIN_FILE_PATH,
- sizeof(PT_PIP2_BIN_FILE_PATH));
- pt_init_hid_descriptor(&cd->hid_desc);
- /* Read and store the descriptor lengths */
- cd->hid_core.hid_report_desc_len =
- le16_to_cpu(cd->hid_desc.report_desc_len);
- cd->hid_core.hid_max_input_len =
- le16_to_cpu(cd->hid_desc.max_input_len);
- cd->hid_core.hid_max_output_len =
- le16_to_cpu(cd->hid_desc.max_output_len);
- /* Initialize mutexes and spinlocks */
- mutex_init(&cd->module_list_lock);
- mutex_init(&cd->system_lock);
- mutex_init(&cd->sysfs_lock);
- mutex_init(&cd->ttdl_restart_lock);
- mutex_init(&cd->firmware_class_lock);
- spin_lock_init(&cd->spinlock);
- /* Initialize module list */
- INIT_LIST_HEAD(&cd->module_list);
- /* Initialize attention lists */
- for (type = 0; type < PT_ATTEN_NUM_ATTEN; type++)
- INIT_LIST_HEAD(&cd->atten_list[type]);
- /* Initialize parameter list */
- INIT_LIST_HEAD(&cd->param_list);
- /* Initialize wait queue */
- init_waitqueue_head(&cd->wait_q);
- rc = pt_ts_pinctrl_init(cd);
- if (!rc && cd->ts_pinctrl) {
- /*
- * Pinctrl handle is optional. If pinctrl handle is found
- * let pins to be configured in active state. If not
- * found continue further without error.
- */
- rc = pinctrl_select_state(cd->ts_pinctrl,
- cd->pinctrl_state_active);
- if (rc < 0)
- dev_err(&client->dev, "failed to select pin to active state\n");
- }
- rc = pt_get_regulator(cd, true);
- if (rc) {
- dev_err(&client->dev, "Failed to get voltage regulators\n");
- goto error_alloc_data;
- }
- rc = pt_enable_regulator(cd, true);
- if (rc) {
- dev_err(dev, "Failed to enable regulators: rc=%d\n", rc);
- goto error_get_regulator;
- }
- /* Initialize works */
- INIT_WORK(&cd->enum_work, pt_enum_work_function);
- INIT_WORK(&cd->ttdl_restart_work, pt_restart_work_function);
- INIT_WORK(&cd->watchdog_work, pt_watchdog_work);
- /* Initialize HID specific data */
- cd->hid_core.hid_vendor_id = (cd->cpdata->vendor_id) ?
- cd->cpdata->vendor_id : HID_VENDOR_ID;
- cd->hid_core.hid_product_id = (cd->cpdata->product_id) ?
- cd->cpdata->product_id : HID_APP_PRODUCT_ID;
- cd->hid_core.hid_desc_register =
- cpu_to_le16(cd->cpdata->hid_desc_register);
- /* Set platform easywake value */
- cd->easy_wakeup_gesture = cd->cpdata->easy_wakeup_gesture;
- #if defined(CONFIG_DRM) || defined(CONFIG_PANEL_NOTIFIER)
- /* Setup active dsi panel */
- active_panel = cd->cpdata->active_panel;
- #endif
- /* Set platform panel_id value */
- cd->panel_id_support = cd->cpdata->panel_id_support;
- if (cd->panel_id_support & PT_PANEL_ID_BY_SYS_INFO)
- /* Set Panel ID to default to 0 */
- cd->pid_for_loader = PT_PANEL_ID_DEFAULT;
- else
- /* Set Panel ID to Not Enabled */
- cd->pid_for_loader = PANEL_ID_NOT_ENABLED;
- /* Initialize hw_version default to FFFF.FFFF.FF */
- snprintf(cd->hw_version, HW_VERSION_LEN_MAX, "FFFF.FFFF.FF");
- dev_set_drvdata(dev, cd);
- /* PtSBC builds will call this function in pt_probe_complete() */
- pt_add_core(dev);
- rc = sysfs_create_group(&dev->kobj, &early_attr_group);
- if (rc) {
- pt_debug(cd->dev, DL_ERROR, "%s:create early attrs failed\n",
- __func__);
- goto error_enable_regulator;
- }
- /*
- * Save the pointer to a global value, which will be used
- * in ttdl_restart function
- */
- cd->bus_ops = ops;
- glink_touch_channel_init(&touch_notify_glink_pt_channel_state, &glink_touch_pt_rx_msg);
- /*
- * When the IRQ GPIO is not direclty accessible and no function is
- * defined to get the IRQ status, the IRQ passed in must be assigned
- * directly as the gpio_to_irq will not work. e.g. CHROMEOS
- */
- if (!cd->cpdata->irq_stat) {
- cd->irq = irq;
- pt_debug(cd->dev, DL_ERROR, "%s:No irq_stat, Set cd->irq = %d\n",
- __func__, cd->irq);
- }
- /* Call platform init function before setting up the GPIO's */
- if (cd->cpdata->init) {
- pt_debug(cd->dev, DL_INFO, "%s: Init HW\n", __func__);
- rc = cd->cpdata->init(cd->cpdata, PT_MT_POWER_ON, cd->dev);
- } else {
- pt_debug(cd->dev, DL_ERROR, "%s: No HW INIT function\n",
- __func__);
- rc = 0;
- }
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR, "%s: HW Init fail r=%d\n",
- __func__, rc);
- }
- /* Power on any needed regulator(s) */
- if (cd->cpdata->setup_power) {
- pt_debug(cd->dev, DL_INFO, "%s: Device power on!\n", __func__);
- rc = cd->cpdata->setup_power(cd->cpdata,
- PT_MT_POWER_ON, cd->dev);
- } else {
- pt_debug(cd->dev, DL_ERROR, "%s: No setup power function\n",
- __func__);
- rc = 0;
- }
- if (rc < 0)
- pt_debug(cd->dev, DL_ERROR, "%s: Setup power on fail r=%d\n",
- __func__, rc);
- #ifdef TTDL_DIAGNOSTICS
- cd->watchdog_irq_stuck_count = 0;
- cd->bus_transmit_error_count = 0;
- #endif /* TTDL_DIAGNOSTICS */
- if (cd->cpdata->detect) {
- pt_debug(cd->dev, DL_INFO, "%s: Detect HW\n", __func__);
- rc = cd->cpdata->detect(cd->cpdata, cd->dev,
- pt_platform_detect_read);
- if (!rc) {
- cd->hw_detected = true;
- pt_debug(cd->dev, DL_INFO,
- "%s: HW detected\n", __func__);
- } else {
- cd->hw_detected = false;
- pt_debug(cd->dev, DL_INFO,
- "%s: No HW detected\n", __func__);
- rc = -ENODEV;
- goto error_detect;
- }
- } else {
- pt_debug(dev, DL_ERROR,
- "%s: PARADE No HW detect function pointer\n",
- __func__);
- /*
- * "hw_reset" is not needed in the "if" statement,
- * because "hw_reset" is already included in "hw_detect"
- * function.
- */
- rc = pt_hw_hard_reset(cd);
- if (rc)
- pt_debug(cd->dev, DL_ERROR,
- "%s: FAILED to execute HARD reset\n",
- __func__);
- }
- if (cd->cpdata->setup_irq) {
- pt_debug(cd->dev, DL_INFO, "%s: setup IRQ\n", __func__);
- rc = cd->cpdata->setup_irq(cd->cpdata, PT_MT_IRQ_REG, cd->dev);
- if (rc) {
- pt_debug(dev, DL_ERROR,
- "%s: Error, couldn't setup IRQ\n", __func__);
- goto error_setup_irq;
- }
- } else {
- pt_debug(dev, DL_ERROR,
- "%s: IRQ function pointer not setup\n",
- __func__);
- goto error_setup_irq;
- }
- #if (KERNEL_VERSION(4, 14, 0) > LINUX_VERSION_CODE)
- setup_timer(&cd->watchdog_timer, pt_watchdog_timer,
- (unsigned long)cd);
- #else
- timer_setup(&cd->watchdog_timer, pt_watchdog_timer, 0);
- #endif
- pt_stop_wd_timer(cd);
- #ifdef TTHE_TUNER_SUPPORT
- mutex_init(&cd->tthe_lock);
- cd->tthe_debugfs = debugfs_create_file(PT_TTHE_TUNER_FILE_NAME,
- 0644, NULL, cd, &tthe_debugfs_fops);
- #endif
- rc = device_init_wakeup(dev, 1);
- if (rc < 0)
- pt_debug(dev, DL_ERROR, "%s: Error, device_init_wakeup rc:%d\n",
- __func__, rc);
- if (!enable_irq_wake(cd->irq)) {
- cd->irq_wake = 1;
- pt_debug(cd->dev, DL_WARN, "%s Device MAY wakeup\n", __func__);
- }
- pm_runtime_get_noresume(dev);
- pm_runtime_set_active(dev);
- pm_runtime_enable(dev);
- /* If IRQ asserted, read out all from buffer to release INT pin */
- if (cd->cpdata->irq_stat) {
- pt_flush_bus_if_irq_asserted(cd, PT_FLUSH_BUS_BASED_ON_LEN);
- } else {
- /* Force a read in case the reset sentinel already arrived */
- rc = pt_read_input(cd);
- if (!rc)
- pt_parse_input(cd);
- }
- /* Without sleep DUT is not ready and will NAK the first write */
- msleep(150);
- /* Attempt to set the DUT generation if not yet set */
- if (cd->active_dut_generation == DUT_UNKNOWN) {
- if (cd->bl_pip_ver_ready ||
- (cd->app_pip_ver_ready &&
- IS_PIP_VER_GE(&cd->sysinfo, 1, 12))) {
- cd->active_dut_generation = DUT_PIP2_CAPABLE;
- pt_debug(dev, DL_INFO, "%s: dut generation is %d\n",
- __func__, cd->active_dut_generation);
- } else {
- rc = _pt_detect_dut_generation(cd->dev,
- &status, &cd->active_dut_generation,
- &cd->mode);
- if ((cd->active_dut_generation == DUT_UNKNOWN)
- || rc) {
- pt_debug(cd->dev, DL_ERROR,
- " === DUT Gen unknown, Skip Enum ===\n");
- goto skip_enum;
- }
- }
- }
- _pt_request_active_pip_protocol(cd->dev, PT_CORE_CMD_PROTECTED,
- &pip_ver_major, &pip_ver_minor);
- if (pip_ver_major == 2) {
- cd->bl_pip_ver_ready = true;
- pt_debug(dev, DL_ERROR,
- " === PIP2.%d Detected, Attempt to launch APP ===\n",
- pip_ver_minor);
- cd->hw_detected = true;
- } else if (pip_ver_major == 1) {
- cd->app_pip_ver_ready = true;
- pt_debug(dev, DL_ERROR,
- " === PIP1.%d Detected ===\n", pip_ver_minor);
- cd->hw_detected = true;
- } else {
- cd->sysinfo.ttdata.pip_ver_major = 0;
- cd->sysinfo.ttdata.pip_ver_minor = 0;
- cd->app_pip_ver_ready = false;
- cd->hw_detected = false;
- pt_debug(dev, DL_ERROR,
- " === PIP Version Not Detected, Skip Enum ===\n");
- /* For legacy DUTS proceed, enum will attempt to launch app */
- if (cd->active_dut_generation != DUT_PIP1_ONLY)
- goto skip_enum;
- }
- rc = pt_enum_with_dut(cd, false, &status);
- pt_debug(dev, DL_ERROR, "%s: cd->startup_status=0x%04X status=0x%04X\n",
- __func__, cd->startup_status, status);
- if (rc == -ENODEV) {
- pt_debug(cd->dev, DL_ERROR,
- "%s: Enumeration Failed r=%d\n", __func__, rc);
- /* For PtSBC don't error out, allow TTDL to stay up */
- rc = -EPROBE_DEFER;
- goto error_after_startup;
- }
- /* Suspend scanning until probe is complete to avoid asyc touches */
- pt_pip_suspend_scanning_(cd);
- if (cd->hw_detected) {
- pt_debug(dev, DL_INFO, "%s: Add sysfs interfaces\n",
- __func__);
- rc = add_sysfs_interfaces(dev);
- if (rc < 0) {
- pt_debug(dev, DL_ERROR,
- "%s: Error, fail sysfs init\n", __func__);
- goto error_after_startup;
- }
- } else {
- pt_debug(dev, DL_ERROR,
- "%s: No HW detected, sysfs interfaces not added\n",
- __func__);
- }
- skip_enum:
- pm_runtime_put_sync(dev);
- pt_debug(dev, DL_INFO, "%s: Probe: MT, BTN\n", __func__);
- rc = pt_mt_probe(dev);
- if (rc < 0) {
- pt_debug(dev, DL_ERROR, "%s: Error, fail mt probe\n",
- __func__);
- goto error_after_sysfs_create;
- }
- rc = pt_btn_probe(dev);
- if (rc < 0) {
- pt_debug(dev, DL_ERROR, "%s: Error, fail btn probe\n",
- __func__);
- goto error_after_startup_mt;
- }
- pt_probe_modules(cd);
- #ifdef CONFIG_HAS_EARLYSUSPEND
- pt_setup_early_suspend(cd);
- #elif defined(CONFIG_PANEL_NOTIFIER)
- pt_debug(dev, DL_ERROR, "%s: Probe: Setup Panel Event notifier\n", __func__);
- pt_setup_panel_event_notifier(cd);
- INIT_WORK(&cd->resume_offload_work, pt_resume_offload_work);
- INIT_WORK(&cd->suspend_offload_work, pt_suspend_offload_work);
- #elif defined(CONFIG_DRM)
- pt_debug(dev, DL_ERROR, "%s: Probe: Setup drm notifier\n", __func__);
- pt_setup_drm_notifier(cd);
- INIT_WORK(&cd->resume_offload_work, pt_resume_offload_work);
- INIT_WORK(&cd->suspend_offload_work, pt_suspend_offload_work);
- #elif defined(CONFIG_FB)
- pt_setup_fb_notifier(cd);
- #endif
- #ifdef NEED_SUSPEND_NOTIFIER
- cd->pm_notifier.notifier_call = pt_pm_notifier;
- register_pm_notifier(&cd->pm_notifier);
- #endif
- pt_pip_resume_scanning_(cd);
- mutex_lock(&cd->system_lock);
- cd->startup_status |= status;
- cd->core_probe_complete = 1;
- mutex_unlock(&cd->system_lock);
- pt_core_state = STATE_RESUME;
- pt_debug(dev, DL_ERROR, "%s: TTDL Core Probe Completed Successfully\n",
- __func__);
- return 0;
- error_after_startup_mt:
- pr_err("%s PARADE error_after_startup_mt\n", __func__);
- pt_mt_release(dev);
- error_after_sysfs_create:
- pr_err("%s PARADE error_after_sysfs_create\n", __func__);
- pm_runtime_disable(dev);
- #if (KERNEL_VERSION(3, 16, 0) > LINUX_VERSION_CODE)
- device_wakeup_disable(dev);
- #endif
- device_init_wakeup(dev, 0);
- cancel_work_sync(&cd->enum_work);
- pt_stop_wd_timer(cd);
- pt_free_si_ptrs(cd);
- remove_sysfs_interfaces(dev);
- error_after_startup:
- pr_err("%s PARADE error_after_startup\n", __func__);
- del_timer(&cd->watchdog_timer);
- if (cd->cpdata->setup_irq)
- cd->cpdata->setup_irq(cd->cpdata, PT_MT_IRQ_FREE, dev);
- error_setup_irq:
- error_detect:
- if (cd->cpdata->init)
- cd->cpdata->init(cd->cpdata, PT_MT_POWER_OFF, dev);
- if (cd->cpdata->setup_power)
- cd->cpdata->setup_power(cd->cpdata, PT_MT_POWER_OFF, dev);
- sysfs_remove_group(&dev->kobj, &early_attr_group);
- error_enable_regulator:
- pt_del_core(dev);
- dev_set_drvdata(dev, NULL);
- pt_enable_regulator(cd, false);
- error_get_regulator:
- pt_get_regulator(cd, false);
- error_alloc_data:
- kfree(cd);
- error_no_pdata:
- pr_err("%s failed.\n", __func__);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_device_entry
- *
- * SUMMARY: Wrapper function of pt_core_suspend_() to help avoid TP from being
- * woke up or put to sleep based on Kernel power state even when the display
- * is off based on the check of TTDL core platform flag.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to core device
- ******************************************************************************/
- #ifdef PT_AMBIENT_MODE
- int pt_device_entry(struct device *dev,
- u16 irq, size_t xfer_buf_size)
- {
- struct pt_core_data *cd = dev_get_drvdata(dev);
- struct pt_platform_data *pdata = dev_get_platdata(dev);
- struct i2c_client *client = to_i2c_client(dev);
- int rc = 0;
- void *glink_pt_send_msg;
- int glink_touch_exit = TOUCH_EXIT;
- pt_debug(dev, DL_INFO, "%s: Start pt_device_entry\n", __func__);
- cd->dev = dev;
- cd->pdata = pdata;
- cd->cpdata = pdata->core_pdata;
- glink_pt_send_msg = &glink_touch_exit;
- pt_debug(dev, DL_INFO, "[touch]glink_pt_send_msg = %d\n", glink_pt_send_msg);
- glink_touch_tx_msg(glink_pt_send_msg, TOUCH_MSG_SIZE);
- msleep(150);
- if (!rc && cd->ts_pinctrl) {
- /*
- * Pinctrl handle is optional. If pinctrl handle is found
- * let pins to be configured in active state. If not
- * found continue further without error.
- */
- rc = pinctrl_select_state(cd->ts_pinctrl, cd->pinctrl_state_active);
- if (rc < 0)
- dev_err(&client->dev, "failed to select pin to active state\n");
- }
- /* Set platform easywake value */
- cd->easy_wakeup_gesture = cd->cpdata->easy_wakeup_gesture;
- /*
- * When the IRQ GPIO is not direclty accessible and no function is
- * defined to get the IRQ status, the IRQ passed in must be assigned
- * directly as the gpio_to_irq will not work. e.g. CHROMEOS
- */
- if (!cd->cpdata->irq_stat) {
- cd->irq = irq;
- pt_debug(cd->dev, DL_ERROR, "%s:No irq_stat, Set cd->irq = %d\n", __func__, cd->irq);
- }
- /* Call platform init function before setting up the GPIO's */
- if (cd->cpdata->init) {
- pt_debug(cd->dev, DL_INFO, "%s: Init HW\n", __func__);
- rc = cd->cpdata->init(cd->cpdata, PT_MT_POWER_ON, cd->dev);
- } else {
- pt_debug(cd->dev, DL_ERROR, "%s: No HW INIT function\n", __func__);
- rc = 0;
- }
- if (rc < 0) {
- pt_debug(cd->dev, DL_ERROR, "%s: HW Init fail r=%d\n", __func__, rc);
- }
- /* Power on any needed regulator(s) */
- if (cd->cpdata->setup_power) {
- pt_debug(cd->dev, DL_INFO, "%s: Device power on!\n", __func__);
- rc = cd->cpdata->setup_power(cd->cpdata, PT_MT_POWER_ON, cd->dev);
- } else {
- pt_debug(cd->dev, DL_ERROR, "%s: No setup power function\n", __func__);
- rc = 0;
- }
- if (rc < 0)
- pt_debug(cd->dev, DL_ERROR, "%s: Setup power on fail r=%d\n", __func__, rc);
- if (cd->cpdata->detect) {
- pt_debug(cd->dev, DL_INFO, "%s: Detect HW\n", __func__);
- rc = cd->cpdata->detect(cd->cpdata, cd->dev, pt_platform_detect_read);
- if (!rc) {
- cd->hw_detected = true;
- pt_debug(cd->dev, DL_INFO, "%s: HW detected\n", __func__);
- } else {
- cd->hw_detected = false;
- pt_debug(cd->dev, DL_INFO, "%s: No HW detected\n", __func__);
- rc = -ENODEV;
- goto pt_error_detect;
- }
- } else {
- pt_debug(dev, DL_ERROR, "%s: PARADE No HW detect function pointer\n", __func__);
- /*
- * "hw_reset" is not needed in the "if" statement,
- * because "hw_reset" is already included in "hw_detect"
- * function.
- */
- rc = pt_hw_hard_reset(cd);
- if (rc)
- pt_debug(cd->dev, DL_ERROR, "%s: FAILED to execute HARD reset\n", __func__);
- }
- if (cd->cpdata->setup_irq) {
- pt_debug(cd->dev, DL_INFO, "%s: setup IRQ\n", __func__);
- rc = cd->cpdata->setup_irq(cd->cpdata, PT_MT_IRQ_REG, cd->dev);
- if (rc) {
- pt_debug(dev, DL_ERROR, "%s: Error, couldn't setup IRQ\n", __func__);
- goto pt_error_setup_irq;
- }
- } else {
- pt_debug(dev, DL_ERROR, "%s: IRQ function pointer not setup\n", __func__);
- goto pt_error_setup_irq;
- }
- rc = device_init_wakeup(dev, 1);
- if (rc < 0)
- pt_debug(dev, DL_ERROR, "%s: Error, device_init_wakeup rc:%d\n", __func__, rc);
- if (!enable_irq_wake(cd->irq)) {
- cd->irq_wake = 1;
- pt_debug(cd->dev, DL_WARN, "%s Device MAY wakeup\n", __func__);
- }
- pm_runtime_get_noresume(dev);
- pm_runtime_set_active(dev);
- pm_runtime_enable(dev);
- /* Without sleep DUT is not ready and will NAK the first write */
- msleep(150);
- pm_runtime_put_sync(dev);
- #if defined(CONFIG_PANEL_NOTIFIER)
- /* Setup active dsi panel */
- active_panel = cd->cpdata->active_panel;
- pt_debug(dev, DL_ERROR, "%s: Probe: Setup Panel Event notifier\n", __func__);
- pt_setup_panel_event_notifier(cd);
- #endif
- mutex_lock(&cd->system_lock);
- cd->core_probe_complete = 1;
- mutex_unlock(&cd->system_lock);
- pt_debug(dev, DL_INFO, "%s: ####TTDL Core Device Probe Completed Successfully\n", __func__);
- pt_core_state = STATE_RESUME;
- return 0;
- pt_error_setup_irq:
- device_init_wakeup(dev, 0);
- pt_error_detect:
- if (cd->cpdata->init)
- cd->cpdata->init(cd->cpdata, PT_MT_POWER_OFF, dev);
- if (cd->cpdata->setup_power)
- cd->cpdata->setup_power(cd->cpdata, PT_MT_POWER_OFF, dev);
- return rc;
- }
- #endif
- EXPORT_SYMBOL_GPL(pt_probe);
- /*******************************************************************************
- * FUNCTION: pt_release
- *
- * SUMMARY: This function does the following cleanup:
- * - Releases all probed modules
- * - Stops the watchdog
- * - Cancels all pending work tasks
- * - Removes all created sysfs nodes
- * - Removes all created debugfs nodes
- * - Frees the IRQ
- * - Deletes the core
- * - Frees all pointers and HID reports
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *cd - pointer to the core data structure
- ******************************************************************************/
- int pt_release(struct pt_core_data *cd)
- {
- struct device *dev = cd->dev;
- /*
- * Suspend the device before freeing the startup_work and stopping
- * the watchdog since sleep function restarts watchdog on failure
- */
- pm_runtime_suspend(dev);
- pm_runtime_disable(dev);
- /*
- * Any 'work' that can trigger a new thread should be canceled first.
- * The watchdog is also stopped again because another thread could have
- * restarted it. The irq_work is cancelled last because it is used for
- * all I2C/SPI communication.
- */
- pt_stop_wd_timer(cd);
- call_atten_cb(cd, PT_ATTEN_CANCEL_LOADER, 0);
- cancel_work_sync(&cd->ttdl_restart_work);
- cancel_work_sync(&cd->enum_work);
- cancel_work_sync(&cd->resume_offload_work);
- cancel_work_sync(&cd->suspend_offload_work);
- cancel_work_sync(&cd->resume_work);
- cancel_work_sync(&cd->suspend_work);
- destroy_workqueue(cd->pt_workqueue);
- pt_stop_wd_timer(cd);
- pt_release_modules(cd);
- pt_proximity_release(dev);
- pt_btn_release(dev);
- pt_mt_release(dev);
- #ifdef CONFIG_HAS_EARLYSUSPEND
- unregister_early_suspend(&cd->es);
- #elif defined(CONFIG_PANEL_NOTIFIER)
- if (active_panel)
- panel_event_notifier_unregister(cd->entry);
- #elif defined(CONFIG_DRM)
- if (active_panel)
- drm_panel_notifier_unregister(active_panel, &cd->fb_notifier);
- #elif defined(CONFIG_FB)
- fb_unregister_client(&cd->fb_notifier);
- #endif
- #ifdef NEED_SUSPEND_NOTIFIER
- unregister_pm_notifier(&cd->pm_notifier);
- #endif
- #if (KERNEL_VERSION(3, 16, 0) > LINUX_VERSION_CODE)
- device_wakeup_disable(dev);
- #endif
- device_init_wakeup(dev, 0);
- #ifdef TTHE_TUNER_SUPPORT
- mutex_lock(&cd->tthe_lock);
- cd->tthe_exit = 1;
- wake_up(&cd->wait_q);
- mutex_unlock(&cd->tthe_lock);
- debugfs_remove(cd->tthe_debugfs);
- #endif
- sysfs_remove_group(&dev->kobj, &early_attr_group);
- remove_sysfs_interfaces(dev);
- disable_irq_nosync(cd->irq);
- if (cd->cpdata->setup_irq)
- cd->cpdata->setup_irq(cd->cpdata, PT_MT_IRQ_FREE, dev);
- if (cd->cpdata->init)
- cd->cpdata->init(cd->cpdata, PT_MT_POWER_OFF, dev);
- if (cd->cpdata->setup_power)
- cd->cpdata->setup_power(cd->cpdata, PT_MT_POWER_OFF, dev);
- dev_set_drvdata(dev, NULL);
- pt_del_core(dev);
- if (cd->vcc_i2c)
- regulator_set_load(cd->vcc_i2c, 0);
- if (cd->vdd)
- regulator_set_load(cd->vdd, 0);
- pt_enable_regulator(cd, false);
- pt_get_regulator(cd, false);
- pt_free_si_ptrs(cd);
- kfree(cd);
- return 0;
- }
- EXPORT_SYMBOL_GPL(pt_release);
- MODULE_LICENSE("GPL");
- MODULE_DESCRIPTION("Parade TrueTouch(R) Standard Product Core Driver");
- MODULE_AUTHOR("Parade Technologies <[email protected]>");
|