12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746 |
- /*
- * pt_device_access.c
- * Parade TrueTouch(TM) Standard Product Device Access Module.
- * Configuration and Test command/status user interface.
- * 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 "pt_regs.h"
- #include <linux/firmware.h>
- #include <linux/timer.h>
- #include <linux/timex.h>
- #include <linux/rtc.h>
- #define PT_CMCP_THRESHOLD_FILE_NAME "pt_thresholdfile.csv"
- #define CMCP_THRESHOLD_FILE_NAME "ttdl_cmcp_thresholdfile.csv"
- /* Max test case number */
- #define MAX_CASE_NUM (22)
- /* ASCII */
- #define ASCII_LF (0x0A)
- #define ASCII_CR (0x0D)
- #define ASCII_COMMA (0x2C)
- #define ASCII_ZERO (0x30)
- #define ASCII_NINE (0x39)
- /* Max characters of test case name */
- #define NAME_SIZE_MAX (50)
- /* Max sensor and button number */
- #define MAX_BUTTONS (PIP1_SYSINFO_MAX_BTN)
- #define MAX_SENSORS (5120)
- #define MAX_TX_SENSORS (128)
- #define MAX_RX_SENSORS (128)
- /* Multiply by 2 for double (min, max) values */
- #define TABLE_BUTTON_MAX_SIZE (MAX_BUTTONS * 2)
- #define TABLE_SENSOR_MAX_SIZE (MAX_SENSORS * 2)
- #define TABLE_TX_MAX_SIZE (MAX_TX_SENSORS*2)
- #define TABLE_RX_MAX_SIZE (MAX_RX_SENSORS*2)
- #define CM_PANEL_DATA_OFFSET (6)
- #define CM_BTN_DATA_OFFSET (6)
- #define CP_PANEL_DATA_OFFSET (6)
- #define CP_BTN_DATA_OFFSET (6)
- #define MAX_BUF_LEN (100000)
- #define RETRIEVE_PANEL_SCAN_HDR (10)
- enum print_buffer_format {
- PT_PR_FORMAT_DEFAULT = 0,
- PT_PR_FORMAT_U8_SPACE = 1,
- PT_PR_FORMAT_U16_SPACE = 2,
- PT_PR_FORMAT_U8_NO_SPACE = 3,
- PT_PR_FORMAT_U32_SPACE = 4,
- PT_PR_FORMAT_UNDEFINE
- };
- /* cmcp csv file information */
- struct configuration {
- u32 cm_range_limit_row;
- u32 cm_range_limit_col;
- u32 cm_min_limit_cal;
- u32 cm_max_limit_cal;
- u32 cm_max_delta_sensor_percent;
- u32 cm_max_delta_button_percent;
- u32 min_button;
- u32 max_button;
- u32 cp_max_delta_sensor_rx_percent;
- u32 cp_max_delta_sensor_tx_percent;
- u32 cm_min_max_table_btn[TABLE_BUTTON_MAX_SIZE];
- u32 cp_min_max_table_btn[TABLE_BUTTON_MAX_SIZE];
- u32 cm_min_max_table_sensor[TABLE_SENSOR_MAX_SIZE];
- u32 cp_min_max_table_rx[TABLE_RX_MAX_SIZE];
- u32 cp_min_max_table_tx[TABLE_TX_MAX_SIZE];
- u32 cm_min_max_table_btn_size;
- u32 cp_min_max_table_btn_size;
- u32 cm_min_max_table_sensor_size;
- u32 cp_min_max_table_rx_size;
- u32 cp_min_max_table_tx_size;
- u32 cp_max_delta_button_percent;
- u32 cm_max_table_gradient_cols_percent[TABLE_TX_MAX_SIZE];
- u32 cm_max_table_gradient_cols_percent_size;
- u32 cm_max_table_gradient_rows_percent[TABLE_RX_MAX_SIZE];
- u32 cm_max_table_gradient_rows_percent_size;
- u32 cm_excluding_row_edge;
- u32 cm_excluding_col_edge;
- u32 rx_num;
- u32 tx_num;
- u32 btn_num;
- u32 cm_enabled;
- u32 cp_enabled;
- u32 is_valid_or_not;
- };
- /* Test case search definition */
- struct test_case_search {
- char name[NAME_SIZE_MAX]; /* Test case name */
- u32 name_size; /* Test case name size */
- u32 offset; /* Test case offset */
- };
- /* Test case field definition */
- struct test_case_field {
- char *name; /* Test case name */
- u32 name_size; /* Test case name size */
- u32 type; /* Test case type */
- u32 *bufptr; /* Buffer to store value information */
- u32 exist_or_not;/* Test case exist or not */
- u32 data_num; /* Buffer data number */
- u32 line_num; /* Buffer line number */
- };
- /* Test case type */
- enum test_case_type {
- TEST_CASE_TYPE_NO,
- TEST_CASE_TYPE_ONE,
- TEST_CASE_TYPE_MUL,
- TEST_CASE_TYPE_MUL_LINES,
- };
- /* Test case order in test_case_field_array */
- enum case_order {
- CM_TEST_INPUTS,
- CM_EXCLUDING_COL_EDGE,
- CM_EXCLUDING_ROW_EDGE,
- CM_GRADIENT_CHECK_COL,
- CM_GRADIENT_CHECK_ROW,
- CM_RANGE_LIMIT_ROW,
- CM_RANGE_LIMIT_COL,
- CM_MIN_LIMIT_CAL,
- CM_MAX_LIMIT_CAL,
- CM_MAX_DELTA_SENSOR_PERCENT,
- CM_MAX_DELTA_BUTTON_PERCENT,
- PER_ELEMENT_MIN_MAX_TABLE_BUTTON,
- PER_ELEMENT_MIN_MAX_TABLE_SENSOR,
- CP_TEST_INPUTS,
- CP_MAX_DELTA_SENSOR_RX_PERCENT,
- CP_MAX_DELTA_SENSOR_TX_PERCENT,
- CP_MAX_DELTA_BUTTON_PERCENT,
- CP_PER_ELEMENT_MIN_MAX_BUTTON,
- MIN_BUTTON,
- MAX_BUTTON,
- PER_ELEMENT_MIN_MAX_RX,
- PER_ELEMENT_MIN_MAX_TX,
- CASE_ORDER_MAX,
- };
- enum cmcp_test_item {
- CMCP_FULL = 0,
- CMCP_CM_PANEL,
- CMCP_CP_PANEL,
- CMCP_CM_BTN,
- CMCP_CP_BTN,
- };
- #define CM_ENABLED 0x10
- #define CP_ENABLED 0x20
- #define CM_PANEL (0x01 | CM_ENABLED)
- #define CP_PANEL (0x02 | CP_ENABLED)
- #define CM_BTN (0x04 | CM_ENABLED)
- #define CP_BTN (0x08 | CP_ENABLED)
- #define CMCP_FULL_CASE\
- (CM_PANEL | CP_PANEL | CM_BTN | CP_BTN | CM_ENABLED | CP_ENABLED)
- #define PT_DEVICE_ACCESS_NAME "pt_device_access"
- #define PT_INPUT_ELEM_SZ (sizeof("0xHH") + 1)
- #define PIP_CMD_MAX_LENGTH ((1 << 16) - 1)
- #ifdef TTHE_TUNER_SUPPORT
- struct heatmap_param {
- bool scan_start;
- enum scan_data_type_list data_type; /* raw, base, diff */
- int num_element;
- };
- #endif
- #define ABS(x) (((x) < 0) ? -(x) : (x))
- #ifndef MIN
- #define MIN(a, b) (((a) < (b)) ? (a) : (b))
- #endif
- #define PT_MAX_CONFIG_BYTES 256
- #define PT_TTHE_TUNER_GET_PANEL_DATA_FILE_NAME "get_panel_data"
- #define TTHE_TUNER_MAX_BUF (PT_MAX_PRBUF_SIZE * 8)
- struct pt_device_access_data {
- struct device *dev;
- struct pt_sysinfo *si;
- struct mutex sysfs_lock;
- bool sysfs_nodes_created;
- struct kobject mfg_test;
- u8 panel_scan_retrieve_id;
- u8 panel_scan_type_id;
- u8 get_idac_data_id;
- u8 calibrate_sensing_mode;
- u8 calibrate_initialize_baselines;
- u8 baseline_sensing_mode;
- u8 fw_self_test_id;
- u8 fw_self_test_format;
- u16 fw_self_test_param_len;
- u8 fw_self_test_param[PT_FW_SELF_TEST_MAX_PARM];
- struct pt_cal_ext_data cal_ext_data;
- struct dentry *panel_scan_debugfs;
- int panel_scan_size;
- u8 panel_scan_data_buf[TTHE_TUNER_MAX_BUF];
- struct mutex debugfs_lock;
- #ifdef TTHE_TUNER_SUPPORT
- struct heatmap_param heatmap;
- struct dentry *tthe_get_panel_data_debugfs;
- u8 tthe_get_panel_data_is_open;
- #endif
- struct dentry *cmcp_results_debugfs;
- struct dentry *base_dentry;
- struct dentry *mfg_test_dentry;
- u8 ic_buf[PT_MAX_PRBUF_SIZE];
- u8 response_buf[PT_MAX_PRBUF_SIZE];
- struct mutex cmcp_threshold_lock;
- u8 *cmcp_threshold_data;
- int cmcp_threshold_size;
- bool cmcp_threshold_loading;
- struct work_struct cmcp_threshold_update;
- int builtin_cmcp_threshold_status;
- bool is_manual_upgrade_enabled;
- struct configuration *configs;
- struct cmcp_data *cmcp_info;
- struct result *result;
- struct test_case_search *test_search_array;
- struct test_case_field *test_field_array;
- int cmcp_test_items;
- int test_executed;
- int cmcp_range_check;
- int cmcp_force_calibrate;
- int cmcp_test_in_progress;
- };
- struct cmcp_data {
- struct gd_sensor *gd_sensor_col;
- struct gd_sensor *gd_sensor_row;
- int32_t *cm_data_panel;
- int32_t *cp_tx_data_panel;
- int32_t *cp_rx_data_panel;
- int32_t *cp_tx_cal_data_panel;
- int32_t *cp_rx_cal_data_panel;
- int32_t cp_sensor_rx_delta;
- int32_t cp_sensor_tx_delta;
- int32_t cp_button_delta;
- int32_t *cm_btn_data;
- int32_t *cp_btn_data;
- int32_t *cm_sensor_column_delta;
- int32_t *cm_sensor_row_delta;
- int32_t cp_btn_cal;
- int32_t cm_btn_cal;
- int32_t cp_button_ave;
- int32_t cm_ave_data_panel;
- int32_t cp_tx_ave_data_panel;
- int32_t cp_rx_ave_data_panel;
- int32_t cm_cal_data_panel;
- int32_t cm_ave_data_btn;
- int32_t cm_cal_data_btn;
- int32_t cm_delta_data_btn;
- int32_t cm_sensor_delta;
- int32_t tx_num;
- int32_t rx_num;
- int32_t btn_num;
- };
- struct result {
- int32_t config_ver;
- int32_t revision_ctrl;
- int32_t device_id_high;
- int32_t device_id_low;
- /* Sensor Cm validation */
- bool cm_test_pass;
- bool cm_sensor_validation_pass;
- bool cm_sensor_row_delta_pass;
- bool cm_sensor_col_delta_pass;
- bool cm_sensor_gd_row_pass;
- bool cm_sensor_gd_col_pass;
- bool cm_sensor_calibration_pass;
- bool cm_sensor_delta_pass;
- bool cm_button_validation_pass;
- bool cm_button_delta_pass;
- int32_t *cm_sensor_raw_data;
- int32_t cm_sensor_calibration;
- int32_t cm_sensor_delta;
- int32_t *cm_button_raw_data;
- int32_t cm_button_delta;
- /* Sensor Cp validation */
- bool cp_test_pass;
- bool cp_sensor_delta_pass;
- bool cp_sensor_rx_delta_pass;
- bool cp_sensor_tx_delta_pass;
- bool cp_sensor_average_pass;
- bool cp_button_delta_pass;
- bool cp_button_average_pass;
- bool cp_rx_validation_pass;
- bool cp_tx_validation_pass;
- bool cp_button_validation_pass;
- int32_t *cp_sensor_rx_raw_data;
- int32_t *cp_sensor_tx_raw_data;
- int32_t cp_sensor_rx_delta;
- int32_t cp_sensor_tx_delta;
- int32_t cp_sensor_rx_calibration;
- int32_t cp_sensor_tx_calibration;
- int32_t *cp_button_raw_data;
- int32_t cp_button_delta;
- /*other validation*/
- bool short_test_pass;
- bool test_summary;
- };
- static struct pt_core_commands *cmd;
- static struct pt_module device_access_module;
- static ssize_t pt_run_and_get_selftest_result(struct device *dev,
- int protect, char *buf, size_t buf_len, u8 test_id,
- u16 read_length, bool get_result_on_pass,
- bool print_results, u8 print_format);
- static int _pt_calibrate_idacs_cmd(struct device *dev,
- u8 sensing_mode, u8 *status);
- static int pt_perform_calibration(struct device *dev);
- /*******************************************************************************
- * FUNCTION: pt_get_device_access_data
- *
- * SUMMARY: Inline function to get pt_device_access_data.
- *
- * RETURN:
- * pointer to pt_device_access_data structure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- ******************************************************************************/
- static inline struct pt_device_access_data *pt_get_device_access_data(
- struct device *dev)
- {
- return pt_get_module_data(dev, &device_access_module);
- }
- /*******************************************************************************
- * FUNCTION: cmcp_check_config_fw_match
- *
- * SUMMARY: Checks if tx,rx and btn num of firmware match with configuration.
- *
- * RETURN:
- * 0 = match
- * !0 = doesn't match
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *configuration - pointer to configuration structure
- ******************************************************************************/
- static int cmcp_check_config_fw_match(struct device *dev,
- struct configuration *configuration)
- {
- struct pt_device_access_data *dad
- = pt_get_device_access_data(dev);
- int32_t tx_num = dad->configs->tx_num;
- int32_t rx_num = dad->configs->rx_num;
- int32_t button_num = dad->configs->btn_num;
- int ret = 0;
- if (tx_num != dad->si->sensing_conf_data.tx_num) {
- pt_debug(dev, DL_ERROR,
- "%s: TX number mismatch! CSV=%d DUT=%d\n",
- __func__, tx_num, dad->si->sensing_conf_data.tx_num);
- ret = -EINVAL;
- }
- if (rx_num != dad->si->sensing_conf_data.rx_num) {
- pt_debug(dev, DL_ERROR,
- "%s: RX number mismatch! CSV=%d DUT=%d\n",
- __func__, rx_num, dad->si->sensing_conf_data.rx_num);
- ret = -EINVAL;
- }
- if (button_num != dad->si->num_btns) {
- pt_debug(dev, DL_ERROR,
- "%s: Button number mismatch! CSV=%d DUT=%d\n",
- __func__, button_num, dad->si->num_btns);
- ret = -EINVAL;
- }
- return ret;
- }
- /*******************************************************************************
- * FUNCTION: validate_cm_test_results
- *
- * SUMMARY: Checks cm test results and outputs each test and a summary result
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *configuration - pointer to configuration structure
- * *cmcp_info - pointer to cmcp_data structure to store cmcp data from fw
- * *result - pointer to result structure
- * *pass - pointer to bool value
- * test_item - flag to store all test item are requested
- ******************************************************************************/
- static int validate_cm_test_results(struct device *dev,
- struct configuration *configuration, struct cmcp_data *cmcp_info,
- struct result *result, bool *pass, int test_item)
- {
- int32_t tx_num = cmcp_info->tx_num;
- int32_t rx_num = cmcp_info->rx_num;
- int32_t button_num = cmcp_info->btn_num;
- uint32_t sensor_num = tx_num * rx_num;
- int32_t *cm_sensor_data = cmcp_info->cm_data_panel;
- int32_t cm_button_delta;
- int32_t cm_sensor_calibration;
- int32_t *cm_button_data = cmcp_info->cm_btn_data;
- struct gd_sensor *gd_sensor_col = cmcp_info->gd_sensor_col;
- struct gd_sensor *gd_sensor_row = cmcp_info->gd_sensor_row;
- int32_t *cm_sensor_column_delta = cmcp_info->cm_sensor_column_delta;
- int32_t *cm_sensor_row_delta = cmcp_info->cm_sensor_row_delta;
- int ret = 0;
- int i, j;
- pt_debug(dev, DL_INFO, "%s: start\n", __func__);
- if ((test_item & CM_PANEL) == CM_PANEL) {
- pt_debug(dev, DL_INFO,
- "Check each sensor Cm data for min max value\n ");
- /* Check each sensor Cm data for min/max values */
- result->cm_sensor_validation_pass = true;
- for (i = 0; i < sensor_num; i++) {
- int row = i % rx_num;
- int col = i / rx_num;
- int32_t cm_sensor_min =
- configuration->cm_min_max_table_sensor[(row*tx_num+col)*2];
- int32_t cm_sensor_max =
- configuration->cm_min_max_table_sensor[(row*tx_num+col)*2+1];
- if ((cm_sensor_data[i] < cm_sensor_min) ||
- (cm_sensor_data[i] > cm_sensor_max)) {
- pt_debug(dev, DL_WARN,
- "%s: Sensor[%d,%d]:%d (%d,%d)\n",
- "Cm sensor min/max test",
- row, col,
- cm_sensor_data[i],
- cm_sensor_min, cm_sensor_max);
- result->cm_sensor_validation_pass = false;
- }
- }
- /*check cm gradient column data*/
- result->cm_sensor_gd_col_pass = true;
- for (i = 0; i < configuration->cm_max_table_gradient_cols_percent_size;
- i++) {
- if ((gd_sensor_col + i)->gradient_val >
- 10 * configuration->cm_max_table_gradient_cols_percent[i]) {
- pt_debug(dev, DL_WARN,
- "%s: cm_max_table_gradient_cols_percent[%d]:%d, gradient_val:%d\n",
- __func__, i,
- configuration->cm_max_table_gradient_cols_percent[i],
- (gd_sensor_col + i)->gradient_val);
- result->cm_sensor_gd_col_pass = false;
- }
- }
- /*check cm gradient row data*/
- result->cm_sensor_gd_row_pass = true;
- for (j = 0; j < configuration->cm_max_table_gradient_rows_percent_size;
- j++) {
- if ((gd_sensor_row + j)->gradient_val >
- 10 * configuration->cm_max_table_gradient_rows_percent[j]) {
- pt_debug(dev, DL_WARN,
- "%s: cm_max_table_gradient_rows_percent[%d]:%d, gradient_val:%d\n",
- __func__, j,
- configuration->cm_max_table_gradient_rows_percent[j],
- (gd_sensor_row + j)->gradient_val);
- result->cm_sensor_gd_row_pass = false;
- }
- }
- result->cm_sensor_row_delta_pass = true;
- result->cm_sensor_col_delta_pass = true;
- result->cm_sensor_calibration_pass = true;
- result->cm_sensor_delta_pass = true;
- /* Check each row Cm data with neighbor for difference */
- for (i = 0; i < tx_num; i++) {
- for (j = 1; j < rx_num; j++) {
- int32_t cm_sensor_row_diff =
- ABS(cm_sensor_data[i * rx_num + j] -
- cm_sensor_data[i * rx_num + j - 1]);
- cm_sensor_row_delta[i * rx_num + j - 1] =
- cm_sensor_row_diff;
- if (cm_sensor_row_diff >
- configuration->cm_range_limit_row) {
- pt_debug(dev, DL_DEBUG,
- "%s: Sensor[%d,%d]:%d (%d)\n",
- "Cm sensor row range limit test",
- j, i, cm_sensor_row_diff,
- configuration->cm_range_limit_row);
- result->cm_sensor_row_delta_pass = false;
- }
- }
- }
- /* Check each column Cm data with neighbor for difference */
- for (i = 1; i < tx_num; i++) {
- for (j = 0; j < rx_num; j++) {
- int32_t cm_sensor_col_diff =
- ABS((int)cm_sensor_data[i * rx_num + j] -
- (int)cm_sensor_data[(i - 1) * rx_num + j]);
- cm_sensor_column_delta[(i - 1) * rx_num + j] =
- cm_sensor_col_diff;
- if (cm_sensor_col_diff >
- configuration->cm_range_limit_col) {
- pt_debug(dev, DL_DEBUG,
- "%s: Sensor[%d,%d]:%d (%d)\n",
- "Cm sensor column range limit test",
- j, i, cm_sensor_col_diff,
- configuration->cm_range_limit_col);
- result->cm_sensor_col_delta_pass = false;
- }
- }
- }
- /* Check sensor calculated Cm for min/max values */
- cm_sensor_calibration = cmcp_info->cm_cal_data_panel;
- if (cm_sensor_calibration <
- configuration->cm_min_limit_cal ||
- cm_sensor_calibration > configuration->cm_max_limit_cal) {
- pt_debug(dev, DL_DEBUG, "%s: Cm_cal:%d (%d,%d)\n",
- "Cm sensor Cm_cal min/max test",
- cm_sensor_calibration,
- configuration->cm_min_limit_cal,
- configuration->cm_max_limit_cal);
- result->cm_sensor_calibration_pass = false;
- }
- /* Check sensor Cm delta for range limit */
- if (cmcp_info->cm_sensor_delta >
- (10 * configuration->cm_max_delta_sensor_percent)) {
- pt_debug(dev, DL_DEBUG,
- "%s: Cm_sensor_delta:%d (%d)\n",
- "Cm sensor delta range limit test",
- cmcp_info->cm_sensor_delta,
- configuration->cm_max_delta_sensor_percent);
- result->cm_sensor_delta_pass = false;
- }
- result->cm_test_pass = result->cm_sensor_gd_col_pass
- && result->cm_sensor_gd_row_pass
- && result->cm_sensor_validation_pass
- && result->cm_sensor_row_delta_pass
- && result->cm_sensor_col_delta_pass
- && result->cm_sensor_calibration_pass
- && result->cm_sensor_delta_pass;
- }
- if (((test_item & CM_BTN) == CM_BTN) && (cmcp_info->btn_num)) {
- /* Check each button Cm data for min/max values */
- result->cm_button_validation_pass = true;
- for (i = 0; i < button_num; i++) {
- int32_t cm_button_min =
- configuration->cm_min_max_table_btn[i * 2];
- int32_t cm_button_max =
- configuration->cm_min_max_table_btn[i * 2 + 1];
- if ((cm_button_data[i] <= cm_button_min) ||
- (cm_button_data[i] >= cm_button_max)) {
- pt_debug(dev, DL_DEBUG,
- "%s: Button[%d]:%d (%d,%d)\n",
- "Cm button min/max test",
- i, cm_button_data[i],
- cm_button_min, cm_button_max);
- result->cm_button_validation_pass = false;
- }
- }
- /* Check button Cm delta for range limit */
- result->cm_button_delta_pass = true;
- cm_button_delta = ABS((cmcp_info->cm_ave_data_btn -
- cmcp_info->cm_cal_data_btn) * 100 /
- cmcp_info->cm_ave_data_btn);
- if (cm_button_delta >
- configuration->cm_max_delta_button_percent) {
- pt_debug(dev, DL_INFO,
- "%s: Cm_button_delta:%d (%d)\n",
- "Cm button delta range limit test",
- cm_button_delta,
- configuration->cm_max_delta_button_percent);
- result->cm_button_delta_pass = false;
- }
- result->cm_test_pass = result->cm_test_pass &&
- result->cm_button_validation_pass &&
- result->cm_button_delta_pass;
- }
- if (pass)
- *pass = result->cm_test_pass;
- return ret;
- }
- /*******************************************************************************
- * FUNCTION: validate_cp_test_results
- *
- * SUMMARY: Checks cp test results and outputs each test and a summary result.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *configuration - pointer to configuration structure
- * *cmcp_info - pointer to cmcp_data structure to store cmcp data from fw
- * *result - pointer to result structure
- * *pass - pointer to bool value
- * test_item - flag to store all test item are requested
- ******************************************************************************/
- static int validate_cp_test_results(struct device *dev,
- struct configuration *configuration, struct cmcp_data *cmcp_info,
- struct result *result, bool *pass, int test_item)
- {
- int i = 0;
- uint32_t configuration_rx_num;
- uint32_t configuration_tx_num;
- int32_t *cp_sensor_tx_data = cmcp_info->cp_tx_data_panel;
- int32_t *cp_sensor_rx_data = cmcp_info->cp_rx_data_panel;
- int32_t cp_button_delta;
- int32_t cp_button_average;
- result->cp_test_pass = true;
- configuration_rx_num = configuration->cp_min_max_table_rx_size/2;
- configuration_tx_num = configuration->cp_min_max_table_tx_size/2;
- pt_debug(dev, DL_INFO, "%s start\n", __func__);
- if ((test_item & CP_PANEL) == CP_PANEL) {
- int32_t cp_sensor_tx_delta;
- int32_t cp_sensor_rx_delta;
- /* Check Sensor Cp delta for range limit */
- result->cp_sensor_delta_pass = true;
- /*check cp_sensor_tx_delta */
- for (i = 0; i < configuration_tx_num; i++) {
- cp_sensor_tx_delta =
- ABS((cmcp_info->cp_tx_cal_data_panel[i]-
- cmcp_info->cp_tx_data_panel[i]) * 100 /
- cmcp_info->cp_tx_data_panel[i]);
- if (cp_sensor_tx_delta >
- configuration->cp_max_delta_sensor_tx_percent) {
- pt_debug(dev, DL_DEBUG,
- "%s: Cp_sensor_tx_delta:%d (%d)\n",
- "Cp sensor delta range limit test",
- cp_sensor_tx_delta,
- configuration->cp_max_delta_sensor_tx_percent);
- result->cp_sensor_delta_pass = false;
- }
- }
- /*check cp_sensor_rx_delta */
- for (i = 0; i < configuration_rx_num; i++) {
- cp_sensor_rx_delta =
- ABS((cmcp_info->cp_rx_cal_data_panel[i] -
- cmcp_info->cp_rx_data_panel[i]) * 100 /
- cmcp_info->cp_rx_data_panel[i]);
- if (cp_sensor_rx_delta >
- configuration->cp_max_delta_sensor_rx_percent) {
- pt_debug(dev, DL_DEBUG,
- "%s: Cp_sensor_rx_delta:%d(%d)\n",
- "Cp sensor delta range limit test",
- cp_sensor_rx_delta,
- configuration->cp_max_delta_sensor_rx_percent);
- result->cp_sensor_delta_pass = false;
- }
- }
- /* Check sensor Cp rx for min/max values */
- result->cp_rx_validation_pass = true;
- for (i = 0; i < configuration_rx_num; i++) {
- int32_t cp_rx_min =
- configuration->cp_min_max_table_rx[i * 2];
- int32_t cp_rx_max =
- configuration->cp_min_max_table_rx[i * 2 + 1];
- if ((cp_sensor_rx_data[i] <= cp_rx_min) ||
- (cp_sensor_rx_data[i] >= cp_rx_max)) {
- pt_debug(dev, DL_DEBUG,
- "%s: Cp Rx[%d]:%d (%d,%d)\n",
- "Cp Rx min/max test",
- i, (int)cp_sensor_rx_data[i],
- cp_rx_min, cp_rx_max);
- result->cp_rx_validation_pass = false;
- }
- }
- /* Check sensor Cp tx for min/max values */
- result->cp_tx_validation_pass = true;
- for (i = 0; i < configuration_tx_num; i++) {
- int32_t cp_tx_min =
- configuration->cp_min_max_table_tx[i * 2];
- int32_t cp_tx_max =
- configuration->cp_min_max_table_tx[i * 2 + 1];
- if ((cp_sensor_tx_data[i] <= cp_tx_min) ||
- (cp_sensor_tx_data[i] >= cp_tx_max)) {
- pt_debug(dev, DL_DEBUG,
- "%s: Cp Tx[%d]:%d(%d,%d)\n",
- "Cp Tx min/max test",
- i, cp_sensor_tx_data[i],
- cp_tx_min, cp_tx_max);
- result->cp_tx_validation_pass = false;
- }
- }
- result->cp_test_pass = result->cp_test_pass
- && result->cp_sensor_delta_pass
- && result->cp_rx_validation_pass
- && result->cp_tx_validation_pass;
- }
- if (((test_item & CP_BTN) == CP_BTN) && (cmcp_info->btn_num)) {
- result->cp_button_delta_pass = true;
- /* Check button Cp delta for range limit */
- cp_button_delta = ABS((cmcp_info->cp_btn_cal
- - cmcp_info->cp_button_ave) * 100 /
- cmcp_info->cp_button_ave);
- if (cp_button_delta >
- configuration->cp_max_delta_button_percent) {
- pt_debug(dev, DL_INFO,
- "%s: Cp_button_delta:%d (%d)\n",
- "Cp button delta range limit test",
- cp_button_delta,
- configuration->cp_max_delta_button_percent);
- result->cp_button_delta_pass = false;
- }
- /* Check button Cp average for min/max values */
- result->cp_button_average_pass = true;
- cp_button_average = cmcp_info->cp_button_ave;
- if (cp_button_average < configuration->min_button ||
- cp_button_average > configuration->max_button) {
- pt_debug(dev, DL_INFO,
- "%s: Button Cp average fails min/max test\n",
- __func__);
- pt_debug(dev, DL_INFO,
- "%s: Cp_button_average:%d (%d,%d)\n",
- "Cp button average min/max test",
- cp_button_average,
- configuration->min_button,
- configuration->max_button);
- result->cp_button_average_pass = false;
- }
- /* Check each button Cp data for min/max values */
- result->cp_button_validation_pass = true;
- for (i = 0; i < cmcp_info->btn_num; i++) {
- int32_t cp_button_min =
- configuration->cp_min_max_table_btn[i * 2];
- int32_t cp_button_max =
- configuration->cp_min_max_table_btn[i * 2 + 1];
- if ((cmcp_info->cp_btn_data[i] <= cp_button_min) ||
- (cmcp_info->cp_btn_data[i] >= cp_button_max)) {
- pt_debug(dev, DL_DEBUG,
- "%s: Button[%d]:%d (%d,%d)\n",
- "Cp button min/max test",
- i, cmcp_info->cp_btn_data[i],
- cp_button_min, cp_button_max);
- result->cp_button_validation_pass = false;
- }
- }
- result->cp_test_pass = result->cp_test_pass
- && result->cp_button_delta_pass
- && result->cp_button_average_pass
- && result->cp_button_validation_pass;
- }
- if (pass)
- *pass = result->cp_test_pass;
- return 0;
- }
- /*******************************************************************************
- * FUNCTION: calculate_gradient_row
- *
- * SUMMARY: Calculates gradient value for rows.
- *
- * PARAMETERS:
- * *gd_sensor_row_head - pointer to gd_sensor structure
- * row_num - number of row
- * exclude_row_edge - flag to exclude row edge(1:exclude; 0:include)
- * exclude_col_edge - flag to exclude column edge(1:exclude; 0:include)
- ******************************************************************************/
- static void calculate_gradient_row(struct gd_sensor *gd_sensor_row_head,
- uint16_t row_num, int exclude_row_edge, int exclude_col_edge)
- {
- int i = 0;
- uint16_t cm_min_cur = 0;
- uint16_t cm_max_cur = 0;
- uint16_t cm_ave_cur = 0;
- uint16_t cm_ave_next = 0;
- uint16_t cm_ave_prev = 0;
- struct gd_sensor *p = gd_sensor_row_head;
- if (exclude_row_edge) {
- for (i = 0; i < row_num; i++) {
- if (!exclude_col_edge) {
- cm_ave_cur = (p + i)->cm_ave;
- cm_min_cur = (p + i)->cm_min;
- cm_max_cur = (p + i)->cm_max;
- if (i < (row_num-1))
- cm_ave_next = (p + i+1)->cm_ave;
- if (i > 0)
- cm_ave_prev = (p + i-1)->cm_ave;
- } else {
- cm_ave_cur = (p + i)->cm_ave_exclude_edge;
- cm_min_cur = (p + i)->cm_min_exclude_edge;
- cm_max_cur = (p + i)->cm_max_exclude_edge;
- if (i < (row_num-1))
- cm_ave_next =
- (p + i+1)->cm_ave_exclude_edge;
- if (i > 0)
- cm_ave_prev =
- (p + i-1)->cm_ave_exclude_edge;
- }
- if (cm_ave_cur == 0)
- cm_ave_cur = 1;
- /*multiple 1000 to increate accuracy*/
- if ((i == 0) || (i == (row_num-1))) {
- (p + i)->gradient_val =
- (cm_max_cur - cm_min_cur) * 1000 /
- cm_ave_cur;
- } else if (i == 1) {
- (p + i)->gradient_val = (cm_max_cur - cm_min_cur
- + ABS(cm_ave_cur - cm_ave_next)) * 1000 /
- cm_ave_cur;
- } else {
- (p + i)->gradient_val = (cm_max_cur - cm_min_cur
- + ABS(cm_ave_cur - cm_ave_prev)) * 1000 /
- cm_ave_cur;
- }
- }
- } else if (!exclude_row_edge) {
- for (i = 0; i < row_num; i++) {
- if (!exclude_col_edge) {
- cm_ave_cur = (p + i)->cm_ave;
- cm_min_cur = (p + i)->cm_min;
- cm_max_cur = (p + i)->cm_max;
- if (i < (row_num-1))
- cm_ave_next = (p + i+1)->cm_ave;
- if (i > 0)
- cm_ave_prev = (p + i-1)->cm_ave;
- } else {
- cm_ave_cur = (p + i)->cm_ave_exclude_edge;
- cm_min_cur = (p + i)->cm_min_exclude_edge;
- cm_max_cur = (p + i)->cm_max_exclude_edge;
- if (i < (row_num-1))
- cm_ave_next =
- (p + i+1)->cm_ave_exclude_edge;
- if (i > 0)
- cm_ave_prev =
- (p + i-1)->cm_ave_exclude_edge;
- }
- if (cm_ave_cur == 0)
- cm_ave_cur = 1;
- /*multiple 1000 to increate accuracy*/
- if (i <= 1)
- (p + i)->gradient_val = (cm_max_cur - cm_min_cur
- + ABS(cm_ave_cur - cm_ave_next)) * 1000 /
- cm_ave_cur;
- else
- (p + i)->gradient_val = (cm_max_cur - cm_min_cur
- + ABS(cm_ave_cur - cm_ave_prev)) * 1000 /
- cm_ave_cur;
- }
- }
- }
- /*******************************************************************************
- * FUNCTION: calculate_gradient_col
- *
- * SUMMARY: Calculates gradient value for columns.
- *
- * PARAMETERS:
- * *gd_sensor_row_head - pointer to gd_sensor structure
- * col_num - number of column
- * exclude_row_edge - flag to exclude row edge(1:exclude; 0:include)
- * exclude_col_edge - flag to exclude column edge(1:exclude; 0:include)
- ******************************************************************************/
- static void calculate_gradient_col(struct gd_sensor *gd_sensor_row_head,
- uint16_t col_num, int exclude_row_edge, int exclude_col_edge)
- {
- int i = 0;
- int32_t cm_min_cur = 0;
- int32_t cm_max_cur = 0;
- int32_t cm_ave_cur = 0;
- int32_t cm_ave_next = 0;
- int32_t cm_ave_prev = 0;
- struct gd_sensor *p = gd_sensor_row_head;
- if (!exclude_col_edge) {
- for (i = 0; i < col_num; i++) {
- if (!exclude_row_edge) {
- cm_ave_cur = (p + i)->cm_ave;
- cm_min_cur = (p + i)->cm_min;
- cm_max_cur = (p + i)->cm_max;
- if (i < (col_num-1))
- cm_ave_next = (p + i+1)->cm_ave;
- if (i > 0)
- cm_ave_prev = (p + i-1)->cm_ave;
- } else {
- cm_ave_cur = (p + i)->cm_ave_exclude_edge;
- cm_min_cur = (p + i)->cm_min_exclude_edge;
- cm_max_cur = (p + i)->cm_max_exclude_edge;
- if (i < (col_num-1))
- cm_ave_next =
- (p + i+1)->cm_ave_exclude_edge;
- if (i > 0)
- cm_ave_prev =
- (p + i-1)->cm_ave_exclude_edge;
- }
- if (cm_ave_cur == 0)
- cm_ave_cur = 1;
- /*multiple 1000 to increate accuracy*/
- if (i <= 1)
- (p + i)->gradient_val = (cm_max_cur - cm_min_cur
- + ABS(cm_ave_cur - cm_ave_next)) * 1000 /
- cm_ave_cur;
- else
- (p + i)->gradient_val = (cm_max_cur - cm_min_cur
- + ABS(cm_ave_cur - cm_ave_prev)) * 1000 /
- cm_ave_cur;
- }
- } else if (exclude_col_edge) {
- for (i = 0; i < col_num; i++) {
- if (!exclude_row_edge) {
- cm_ave_cur = (p + i)->cm_ave;
- cm_min_cur = (p + i)->cm_min;
- cm_max_cur = (p + i)->cm_max;
- if (i < (col_num-1))
- cm_ave_next = (p + i+1)->cm_ave;
- if (i > 0)
- cm_ave_prev = (p + i-1)->cm_ave;
- } else {
- cm_ave_cur = (p + i)->cm_ave_exclude_edge;
- cm_min_cur = (p + i)->cm_min_exclude_edge;
- cm_max_cur = (p + i)->cm_max_exclude_edge;
- if (i < (col_num-1))
- cm_ave_next =
- (p + i+1)->cm_ave_exclude_edge;
- if (i > 0)
- cm_ave_prev =
- (p + i-1)->cm_ave_exclude_edge;
- }
- if (cm_ave_cur == 0)
- cm_ave_cur = 1;
- /*multiple 1000 to increate accuracy*/
- if ((i == 0) || (i == (col_num - 1)))
- (p + i)->gradient_val =
- (cm_max_cur - cm_min_cur) * 1000 /
- cm_ave_cur;
- else if (i == 1)
- (p + i)->gradient_val =
- (cm_max_cur - cm_min_cur +
- ABS(cm_ave_cur - cm_ave_next))
- * 1000 / cm_ave_cur;
- else
- (p + i)->gradient_val =
- (cm_max_cur - cm_min_cur +
- ABS(cm_ave_cur - cm_ave_prev))
- * 1000 / cm_ave_cur;
- }
- }
- }
- /*******************************************************************************
- * FUNCTION: fill_gd_sensor_table
- *
- * SUMMARY: Fills cm calculation result and exclude parameter to gd_sensor
- * structure.
- *
- * PARAMETERS:
- * *head - pointer to gd_sensor structure
- * index - index of row or column
- * cm_max - maximum of cm
- * cm_min - minmum of cm
- * cm_ave - average of cm
- * cm_max_exclude_edge - maximum of cm without edge data
- * cm_min_exclude_edge - minmum of cm without edge data
- * cm_ave_exclude_edge - average of cm without edge data
- ******************************************************************************/
- static void fill_gd_sensor_table(struct gd_sensor *head, int32_t index,
- int32_t cm_max, int32_t cm_min, int32_t cm_ave,
- int32_t cm_max_exclude_edge, int32_t cm_min_exclude_edge,
- int32_t cm_ave_exclude_edge)
- {
- (head + index)->cm_max = cm_max;
- (head + index)->cm_min = cm_min;
- (head + index)->cm_ave = cm_ave;
- (head + index)->cm_ave_exclude_edge = cm_ave_exclude_edge;
- (head + index)->cm_max_exclude_edge = cm_max_exclude_edge;
- (head + index)->cm_min_exclude_edge = cm_min_exclude_edge;
- }
- /*******************************************************************************
- * FUNCTION: calculate_gd_info
- *
- * SUMMARY: Calculates gradient panel sensor column and row by calling
- * function calculate_gradient_col() & calculate_gradient_row().
- *
- * PARAMETERS:
- * *head - pointer to gd_sensor structure
- * index - index of row or column
- * cm_max - maximum of cm
- * cm_min - minmum of cm
- * cm_ave - average of cm
- * cm_max_exclude_edge - maximum of cm without edge data
- * cm_min_exclude_edge - minmum of cm without edge data
- * cm_ave_exclude_edge - average of cm without edge data
- ******************************************************************************/
- static void calculate_gd_info(struct gd_sensor *gd_sensor_col,
- struct gd_sensor *gd_sensor_row, int tx_num, int rx_num,
- int32_t *cm_sensor_data, int cm_excluding_row_edge,
- int cm_excluding_col_edge)
- {
- int32_t cm_max;
- int32_t cm_min;
- int32_t cm_ave;
- int32_t cm_max_exclude_edge;
- int32_t cm_min_exclude_edge;
- int32_t cm_ave_exclude_edge;
- int32_t cm_data;
- int i;
- int j;
- /*calculate all the gradient related info for column*/
- for (i = 0; i < tx_num; i++) {
- /*re-initialize for a new col*/
- cm_max = cm_sensor_data[i * rx_num];
- cm_min = cm_max;
- cm_ave = 0;
- cm_max_exclude_edge = cm_sensor_data[i * rx_num + 1];
- cm_min_exclude_edge = cm_max_exclude_edge;
- cm_ave_exclude_edge = 0;
- for (j = 0; j < rx_num; j++) {
- cm_data = cm_sensor_data[i * rx_num + j];
- if (cm_data > cm_max)
- cm_max = cm_data;
- if (cm_data < cm_min)
- cm_min = cm_data;
- cm_ave += cm_data;
- /*calculate exclude edge data*/
- if ((j > 0) && (j < (rx_num-1))) {
- if (cm_data > cm_max_exclude_edge)
- cm_max_exclude_edge = cm_data;
- if (cm_data < cm_min_exclude_edge)
- cm_min_exclude_edge = cm_data;
- cm_ave_exclude_edge += cm_data;
- }
- }
- cm_ave /= rx_num;
- cm_ave_exclude_edge /= (rx_num-2);
- fill_gd_sensor_table(gd_sensor_col, i, cm_max, cm_min, cm_ave,
- cm_max_exclude_edge, cm_min_exclude_edge, cm_ave_exclude_edge);
- }
- calculate_gradient_col(gd_sensor_col, tx_num, cm_excluding_row_edge,
- cm_excluding_col_edge);
- /*calculate all the gradient related info for row*/
- for (j = 0; j < rx_num; j++) {
- /*re-initialize for a new row*/
- cm_max = cm_sensor_data[j];
- cm_min = cm_max;
- cm_ave = 0;
- cm_max_exclude_edge = cm_sensor_data[rx_num + j];
- cm_min_exclude_edge = cm_max_exclude_edge;
- cm_ave_exclude_edge = 0;
- for (i = 0; i < tx_num; i++) {
- cm_data = cm_sensor_data[i * rx_num + j];
- if (cm_data > cm_max)
- cm_max = cm_data;
- if (cm_data < cm_min)
- cm_min = cm_data;
- cm_ave += cm_data;
- /*calculate exclude edge data*/
- if ((i > 0) && (i < (tx_num-1))) {
- if (cm_data > cm_max_exclude_edge)
- cm_max_exclude_edge = cm_data;
- if (cm_data < cm_min_exclude_edge)
- cm_min_exclude_edge = cm_data;
- cm_ave_exclude_edge += cm_data;
- }
- }
- cm_ave /= tx_num;
- cm_ave_exclude_edge /= (tx_num-2);
- fill_gd_sensor_table(gd_sensor_row, j, cm_max, cm_min, cm_ave,
- cm_max_exclude_edge, cm_min_exclude_edge, cm_ave_exclude_edge);
- }
- calculate_gradient_row(gd_sensor_row, rx_num, cm_excluding_row_edge,
- cm_excluding_col_edge);
- }
- /*******************************************************************************
- * FUNCTION: pt_get_cmcp_info
- *
- * SUMMARY: Function to include following work:
- * 1) run short test and get result
- * 2) run selftest to get cm_panel data, cm_cal_data_panel data, calculate
- * cm_ave_data_panel, cm_sensor_delta and gradient by column and row.
- * 3) run selftest to get cp_panel data, cp_cal_data_panel data, cacluate
- * cp_ave_data_panel, cp_sensor_delta for tx and rx.
- * 4) run selftest to get cm_btn data, cm_cal_data_btn data, cacluate
- * cm_delta_data_btn data, cm_ave_data_btn data.
- * 5) run selftest to get cp_btn data, cp_btn_cal data, cacluate
- * cp_button_delta data, cp_button_ave data.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dad - pointer to pt_device_access_data structure
- * *cmcp_info - pointer to cmcp_data structure
- ******************************************************************************/
- static int pt_get_cmcp_info(struct pt_device_access_data *dad,
- struct cmcp_data *cmcp_info)
- {
- struct device *dev;
- int32_t *cm_data_panel = cmcp_info->cm_data_panel;
- int32_t *cp_tx_data_panel = cmcp_info->cp_tx_data_panel;
- int32_t *cp_rx_data_panel = cmcp_info->cp_rx_data_panel;
- int32_t *cp_tx_cal_data_panel = cmcp_info->cp_tx_cal_data_panel;
- int32_t *cp_rx_cal_data_panel = cmcp_info->cp_rx_cal_data_panel;
- int32_t *cm_btn_data = cmcp_info->cm_btn_data;
- int32_t *cp_btn_data = cmcp_info->cp_btn_data;
- struct gd_sensor *gd_sensor_col = cmcp_info->gd_sensor_col;
- struct gd_sensor *gd_sensor_row = cmcp_info->gd_sensor_row;
- struct result *result = dad->result;
- int32_t cp_btn_cal = 0;
- int32_t cp_btn_ave = 0;
- int32_t cm_ave_data_panel = 0;
- int32_t cm_ave_data_btn = 0;
- int32_t cp_tx_ave_data_panel = 0;
- int32_t cp_rx_ave_data_panel = 0;
- u8 tmp_buf[3];
- int tx_num;
- int rx_num;
- int btn_num;
- int rc = 0;
- int i;
- dev = dad->dev;
- cmcp_info->tx_num = dad->si->sensing_conf_data.tx_num;
- cmcp_info->rx_num = dad->si->sensing_conf_data.rx_num;
- cmcp_info->btn_num = dad->si->num_btns;
- tx_num = cmcp_info->tx_num;
- rx_num = cmcp_info->rx_num;
- btn_num = cmcp_info->btn_num;
- pt_debug(dev, DL_INFO, "%s tx_num=%d", __func__, tx_num);
- pt_debug(dev, DL_INFO, "%s rx_num=%d", __func__, rx_num);
- pt_debug(dev, DL_INFO, "%s btn_num=%d", __func__, btn_num);
- /*short test*/
- result->short_test_pass = true;
- rc = pt_run_and_get_selftest_result(dev, PT_CORE_CMD_UNPROTECTED,
- tmp_buf, sizeof(tmp_buf),
- PT_ST_ID_AUTOSHORTS, PIP_CMD_MAX_LENGTH,
- PT_ST_DONT_GET_RESULTS, PT_ST_NOPRINT, PT_PR_FORMAT_DEFAULT);
- if (rc) {
- pt_debug(dev, DL_ERROR, "short test not supported");
- goto exit;
- }
- if (dad->ic_buf[1] != 0)
- result->short_test_pass = false;
- /*Get cm_panel data*/
- rc = pt_run_and_get_selftest_result(dev, PT_CORE_CMD_UNPROTECTED,
- tmp_buf, sizeof(tmp_buf),
- PT_ST_ID_CM_PANEL, PIP_CMD_MAX_LENGTH,
- PT_ST_GET_RESULTS, PT_ST_NOPRINT, PT_PR_FORMAT_DEFAULT);
- if (rc) {
- pt_debug(dev, DL_ERROR, "Get CM Panel not supported");
- goto exit;
- }
- if (cm_data_panel != NULL) {
- for (i = 0; i < tx_num * rx_num; i++) {
- cm_data_panel[i] =
- 10*(dad->ic_buf[CM_PANEL_DATA_OFFSET+i*2] + 256
- * dad->ic_buf[CM_PANEL_DATA_OFFSET+i*2+1]);
- pt_debug(dev, DL_DEBUG,
- "cm_data_panel[%d]=%d\n",
- i, cm_data_panel[i]);
- cm_ave_data_panel += cm_data_panel[i];
- }
- cm_ave_data_panel /= (tx_num * rx_num);
- cmcp_info->cm_ave_data_panel = cm_ave_data_panel;
- /* Calculate gradient panel sensor column/row here */
- calculate_gd_info(gd_sensor_col, gd_sensor_row, tx_num, rx_num,
- cm_data_panel, 1, 1);
- for (i = 0; i < tx_num; i++) {
- pt_debug(dev, DL_DEBUG,
- "i=%d max=%d,min=%d,ave=%d, gradient=%d", i,
- gd_sensor_col[i].cm_max,
- gd_sensor_col[i].cm_min,
- gd_sensor_col[i].cm_ave,
- gd_sensor_col[i].gradient_val);
- }
- for (i = 0; i < rx_num; i++) {
- pt_debug(dev, DL_DEBUG,
- "i=%d max=%d,min=%d,ave=%d, gradient=%d", i,
- gd_sensor_row[i].cm_max,
- gd_sensor_row[i].cm_min,
- gd_sensor_row[i].cm_ave,
- gd_sensor_row[i].gradient_val);
- }
- }
- /*Get cp data*/
- rc = pt_run_and_get_selftest_result(dev, PT_CORE_CMD_UNPROTECTED,
- tmp_buf, sizeof(tmp_buf),
- PT_ST_ID_CP_PANEL, PIP_CMD_MAX_LENGTH,
- PT_ST_GET_RESULTS, PT_ST_NOPRINT, PT_PR_FORMAT_DEFAULT);
- if (rc) {
- pt_debug(dev, DL_ERROR, "Get CP Panel not supported");
- goto exit;
- }
- /*Get cp_tx_data_panel*/
- if (cp_tx_data_panel != NULL) {
- for (i = 0; i < tx_num; i++) {
- cp_tx_data_panel[i] =
- 10*(dad->ic_buf[CP_PANEL_DATA_OFFSET+i*2]
- + 256 * dad->ic_buf[CP_PANEL_DATA_OFFSET+i*2+1]);
- pt_debug(dev, DL_DEBUG,
- "cp_tx_data_panel[%d]=%d\n",
- i, cp_tx_data_panel[i]);
- cp_tx_ave_data_panel += cp_tx_data_panel[i];
- }
- cp_tx_ave_data_panel /= tx_num;
- cmcp_info->cp_tx_ave_data_panel = cp_tx_ave_data_panel;
- }
- /*Get cp_tx_cal_data_panel*/
- if (cp_tx_cal_data_panel != NULL) {
- for (i = 0; i < tx_num; i++) {
- cp_tx_cal_data_panel[i] =
- 10*(dad->ic_buf[CP_PANEL_DATA_OFFSET+tx_num*2+i*2]
- + 256 * dad->ic_buf[CP_PANEL_DATA_OFFSET+tx_num*2+i*2+1]);
- pt_debug(dev, DL_DEBUG, "cp_tx_cal_data_panel[%d]=%d\n",
- i, cp_tx_cal_data_panel[i]);
- }
- /*get cp_sensor_tx_delta,using the first sensor cal value for temp */
- /*multiple 1000 to increase accuracy*/
- cmcp_info->cp_sensor_tx_delta = ABS((cp_tx_cal_data_panel[0]
- - cp_tx_ave_data_panel) * 1000 / cp_tx_ave_data_panel);
- }
- /*Get cp_rx_data_panel*/
- if (cp_rx_data_panel != NULL) {
- for (i = 0; i < rx_num; i++) {
- cp_rx_data_panel[i] =
- 10*(dad->ic_buf[CP_PANEL_DATA_OFFSET+tx_num*4+i*2] +
- 256 * dad->ic_buf[CP_PANEL_DATA_OFFSET+tx_num*4+i*2+1]);
- pt_debug(dev, DL_DEBUG,
- "cp_rx_data_panel[%d]=%d\n", i,
- cp_rx_data_panel[i]);
- cp_rx_ave_data_panel += cp_rx_data_panel[i];
- }
- cp_rx_ave_data_panel /= rx_num;
- cmcp_info->cp_rx_ave_data_panel = cp_rx_ave_data_panel;
- }
- /*Get cp_rx_cal_data_panel*/
- if (cp_rx_cal_data_panel != NULL) {
- for (i = 0; i < rx_num; i++) {
- cp_rx_cal_data_panel[i] =
- 10 * (dad->ic_buf[CP_PANEL_DATA_OFFSET+tx_num*4+rx_num*2+i*2] +
- 256 *
- dad->ic_buf[CP_PANEL_DATA_OFFSET+tx_num*4+rx_num*2+i*2+1]);
- pt_debug(dev, DL_DEBUG,
- "cp_rx_cal_data_panel[%d]=%d\n", i,
- cp_rx_cal_data_panel[i]);
- }
- /*get cp_sensor_rx_delta,using the first sensor cal value for temp */
- /*multiple 1000 to increase accuracy*/
- cmcp_info->cp_sensor_rx_delta = ABS((cp_rx_cal_data_panel[0]
- - cp_rx_ave_data_panel) * 1000 / cp_rx_ave_data_panel);
- }
- if (btn_num == 0) {
- pt_debug(dev, DL_INFO, "%s: Skip Button Test\n", __func__);
- goto skip_button_test;
- }
- /*get cm btn data*/
- rc = pt_run_and_get_selftest_result(dev, PT_CORE_CMD_UNPROTECTED,
- tmp_buf, sizeof(tmp_buf),
- PT_ST_ID_CM_BUTTON, PIP_CMD_MAX_LENGTH,
- PT_ST_GET_RESULTS, PT_ST_NOPRINT, PT_PR_FORMAT_DEFAULT);
- if (rc) {
- pt_debug(dev, DL_ERROR, "Get CM BTN not supported");
- goto exit;
- }
- if (cm_btn_data != NULL) {
- for (i = 0; i < btn_num; i++) {
- cm_btn_data[i] =
- 10 * (dad->ic_buf[CM_BTN_DATA_OFFSET+i*2] +
- 256 * dad->ic_buf[CM_BTN_DATA_OFFSET+i*2+1]);
- pt_debug(dev, DL_DEBUG,
- " cm_btn_data[%d]=%d\n",
- i, cm_btn_data[i]);
- cm_ave_data_btn += cm_btn_data[i];
- }
- cm_ave_data_btn /= btn_num;
- cmcp_info->cm_ave_data_btn = cm_ave_data_btn;
- }
- /*get cp btn data*/
- rc = pt_run_and_get_selftest_result(dev, PT_CORE_CMD_UNPROTECTED,
- tmp_buf, sizeof(tmp_buf),
- PT_ST_ID_CP_BUTTON, PIP_CMD_MAX_LENGTH,
- PT_ST_GET_RESULTS, PT_ST_NOPRINT, PT_PR_FORMAT_DEFAULT);
- if (rc) {
- pt_debug(dev, DL_ERROR, "Get CP BTN not supported");
- goto exit;
- }
- if (cp_btn_data != NULL) {
- for (i = 0; i < btn_num; i++) {
- cp_btn_data[i] =
- 10 * (dad->ic_buf[CP_BTN_DATA_OFFSET+i*2] +
- 256 * dad->ic_buf[CP_BTN_DATA_OFFSET+i*2+1]);
- cp_btn_ave += cp_btn_data[i];
- pt_debug(dev, DL_DEBUG,
- "cp_btn_data[%d]=%d\n",
- i, cp_btn_data[i]);
- }
- cp_btn_ave /= btn_num;
- cp_btn_cal = 10*(dad->ic_buf[CP_BTN_DATA_OFFSET+i*2]
- + 256 * dad->ic_buf[CP_BTN_DATA_OFFSET+i*2+1]);
- cmcp_info->cp_button_ave = cp_btn_ave;
- cmcp_info->cp_btn_cal = cp_btn_cal;
- /*multiple 1000 to increase accuracy*/
- cmcp_info->cp_button_delta = ABS((cp_btn_cal
- - cp_btn_ave) * 1000 / cp_btn_ave);
- pt_debug(dev, DL_INFO, " cp_btn_cal=%d\n",
- cp_btn_cal);
- pt_debug(dev, DL_INFO, " cp_btn_ave=%d\n",
- cp_btn_ave);
- }
- skip_button_test:
- exit:
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_get_cm_cal
- *
- * SUMMARY: Function to include following work:
- * 1) run selftest to get cm_cal_data_panel, cm_sensor_delta
- * 2) run selftest to get cm_cal_data_btn, cm_delta_data_btn
- *
- * NOTE:
- * This function depends on the calculation result of pt_get_cmcp_info()
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dad - pointer to pt_device_access_data structure
- * *cmcp_info - pointer to cmcp_data structure
- ******************************************************************************/
- static int pt_get_cm_cal(struct pt_device_access_data *dad,
- struct cmcp_data *cmcp_info)
- {
- struct device *dev;
- int32_t *cm_data_panel = cmcp_info->cm_data_panel;
- int32_t *cm_btn_data = cmcp_info->cm_btn_data;
- u8 tmp_buf[3];
- int rc = 0;
- int i;
- dev = dad->dev;
- /*Get cm_cal data*/
- rc = pt_run_and_get_selftest_result(dev, PT_CORE_CMD_UNPROTECTED,
- tmp_buf, sizeof(tmp_buf),
- PT_ST_ID_CM_PANEL, PIP_CMD_MAX_LENGTH,
- PT_ST_GET_RESULTS, PT_ST_NOPRINT, PT_PR_FORMAT_DEFAULT);
- if (rc) {
- pt_debug(dev, DL_ERROR, "Get CM Panel not supported");
- goto exit;
- }
- if (cm_data_panel != NULL) {
- i = cmcp_info->tx_num * cmcp_info->rx_num;
- cmcp_info->cm_cal_data_panel =
- 10 * (dad->ic_buf[CM_PANEL_DATA_OFFSET + i * 2] +
- 256 * dad->ic_buf[CM_PANEL_DATA_OFFSET + i * 2 + 1]);
- /*multiple 1000 to increase accuracy*/
- cmcp_info->cm_sensor_delta =
- ABS((cmcp_info->cm_ave_data_panel -
- cmcp_info->cm_cal_data_panel) *
- 1000 / cmcp_info->cm_ave_data_panel);
- }
- if (cmcp_info->btn_num == 0) {
- pt_debug(dev, DL_INFO, "%s: Skip Button Test\n", __func__);
- goto skip_button_test;
- }
- /*get cm_btn_cal data*/
- rc = pt_run_and_get_selftest_result(dev, PT_CORE_CMD_UNPROTECTED,
- tmp_buf, sizeof(tmp_buf),
- PT_ST_ID_CM_BUTTON, PIP_CMD_MAX_LENGTH,
- PT_ST_GET_RESULTS, PT_ST_NOPRINT, PT_PR_FORMAT_DEFAULT);
- if (rc) {
- pt_debug(dev, DL_ERROR, "Get CM BTN not supported");
- goto exit;
- }
- if (cm_btn_data != NULL) {
- i = cmcp_info->btn_num;
- cmcp_info->cm_cal_data_btn =
- 10 * (dad->ic_buf[CM_BTN_DATA_OFFSET + i * 2] +
- 256 * dad->ic_buf[CM_BTN_DATA_OFFSET + i * 2 + 1]);
- /*multiple 1000 to increase accuracy*/
- cmcp_info->cm_delta_data_btn = ABS(
- (cmcp_info->cm_ave_data_btn - cmcp_info->cm_cal_data_btn) *
- 1000 / cmcp_info->cm_ave_data_btn);
- pt_debug(dev, DL_INFO, " cm_btn_cal=%d\n",
- cmcp_info->cm_cal_data_btn);
- }
- skip_button_test:
- exit:
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_free_cmcp_buf
- *
- * SUMMARY: Free pointers in cmcp_data structure
- *
- * PARAMETERS:
- * *cmcp_info - pointer to cmcp_data structure
- ******************************************************************************/
- static void pt_free_cmcp_buf(struct cmcp_data *cmcp_info)
- {
- if (cmcp_info->gd_sensor_col != NULL)
- kfree(cmcp_info->gd_sensor_col);
- if (cmcp_info->gd_sensor_row != NULL)
- kfree(cmcp_info->gd_sensor_row);
- if (cmcp_info->cm_data_panel != NULL)
- kfree(cmcp_info->cm_data_panel);
- if (cmcp_info->cp_tx_data_panel != NULL)
- kfree(cmcp_info->cp_tx_data_panel);
- if (cmcp_info->cp_rx_data_panel != NULL)
- kfree(cmcp_info->cp_rx_data_panel);
- if (cmcp_info->cp_tx_cal_data_panel != NULL)
- kfree(cmcp_info->cp_tx_cal_data_panel);
- if (cmcp_info->cp_rx_cal_data_panel != NULL)
- kfree(cmcp_info->cp_rx_cal_data_panel);
- if (cmcp_info->cm_btn_data != NULL)
- kfree(cmcp_info->cm_btn_data);
- if (cmcp_info->cp_btn_data != NULL)
- kfree(cmcp_info->cp_btn_data);
- if (cmcp_info->cm_sensor_column_delta != NULL)
- kfree(cmcp_info->cm_sensor_column_delta);
- if (cmcp_info->cm_sensor_row_delta != NULL)
- kfree(cmcp_info->cm_sensor_row_delta);
- }
- /*******************************************************************************
- * FUNCTION: pt_cmcp_get_test_item
- *
- * SUMMARY: Parses enum cmcp_test_item to integer value test_item as bitwise
- * type.
- *
- * RETURN: integer value to indidate available test item with bitwise type
- *
- * PARAMETERS:
- * item_input - enum cmcp_test_item
- ******************************************************************************/
- static int pt_cmcp_get_test_item(int item_input)
- {
- int test_item = 0;
- switch (item_input) {
- case CMCP_FULL:
- test_item = CMCP_FULL_CASE;
- break;
- case CMCP_CM_PANEL:
- test_item = CM_PANEL;
- break;
- case CMCP_CP_PANEL:
- test_item = CP_PANEL;
- break;
- case CMCP_CM_BTN:
- test_item = CM_BTN;
- break;
- case CMCP_CP_BTN:
- test_item = CP_BTN;
- break;
- }
- return test_item;
- }
- /*******************************************************************************
- * FUNCTION: pt_cmcp_test_show
- *
- * SUMMARY: Show method for cmcp_test sysfs node. Allows to perform cmcp test
- * with following steps:
- * 1) Get cmcp test items which from threhold file
- * 2) Check whether cmcp test items match with firmware
- * 3) Set parameter to force single TX
- * 4) Do calibration if requested
- * 5) Get all cmcp data from FW and do calculation
- * 6) Set parameter to restore to multi tx
- * 7) Do calibration if requested
- * 8) Check scan state,try to fix if it is not right
- * 9) Start watchdog
- * 10) Validate cm and cp test results if requested
- * 11) Fill the test result
- *
- * 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_cmcp_test_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct pt_device_access_data *dad
- = pt_get_device_access_data(dev);
- struct cmcp_data *cmcp_info = dad->cmcp_info;
- struct result *result = dad->result;
- struct configuration *configuration = dad->configs;
- bool final_pass = true;
- static const char * const cmcp_test_case_array[] = {"Full Cm/Cp test",
- "Cm panel test", "Cp panel test",
- "Cm button test", "Cp button test"};
- int index = 0;
- int test_item = 0;
- int no_builtin_file = 0;
- int rc = 0;
- int self_test_result_1 = 0;
- int self_test_result_2 = 0;
- u8 sys_mode = FW_SYS_MODE_UNDEFINED;
- u8 retry = 3;
- dev = dad->dev;
- if ((configuration == NULL) || (cmcp_info == NULL))
- goto exit;
- mutex_lock(&dad->sysfs_lock);
- if (dad->cmcp_test_in_progress) {
- mutex_unlock(&dad->sysfs_lock);
- goto cmcp_not_ready;
- }
- dad->cmcp_test_in_progress = 1;
- dad->test_executed = 0;
- test_item = pt_cmcp_get_test_item(dad->cmcp_test_items);
- if (dad->builtin_cmcp_threshold_status < 0) {
- pt_debug(dev, DL_WARN, "%s: No cmcp threshold file.\n",
- __func__);
- no_builtin_file = 1;
- mutex_unlock(&dad->sysfs_lock);
- goto start_testing;
- }
- if (dad->cmcp_test_items < 0) {
- pt_debug(dev, DL_ERROR,
- "%s: Invalid test item! Should be 0~4!\n", __func__);
- mutex_unlock(&dad->sysfs_lock);
- goto invalid_item;
- }
- pt_debug(dev, DL_INFO, "%s: Test item is %s, %d\n",
- __func__, cmcp_test_case_array[dad->cmcp_test_items],
- test_item);
- if ((dad->si->num_btns == 0)
- && ((dad->cmcp_test_items == CMCP_CM_BTN)
- || (dad->cmcp_test_items == CMCP_CP_BTN))) {
- pt_debug(dev, DL_WARN,
- "%s: FW doesn't support button!\n", __func__);
- mutex_unlock(&dad->sysfs_lock);
- goto invalid_item_btn;
- }
- mutex_unlock(&dad->sysfs_lock);
- if (cmcp_check_config_fw_match(dev, configuration))
- goto mismatch;
- start_testing:
- pt_debug(dev, DL_INFO, "%s: Start Cm/Cp test!\n", __func__);
- result->cm_test_pass = true;
- result->cp_test_pass = true;
- /*stop watchdog*/
- rc = cmd->request_stop_wd(dev);
- if (rc)
- pt_debug(dev, DL_ERROR, "stop watchdog failed");
- /* Make sure the device is awake */
- pm_runtime_get_sync(dev);
- /* Resource protect */
- rc = cmd->request_exclusive(dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc) {
- pt_debug(dev, DL_ERROR,
- "%s: Error on request exclusive rc = %d\n",
- __func__, rc);
- }
- /*force single tx*/
- rc = cmd->nonhid_cmd->set_param(dev,
- PT_CORE_CMD_UNPROTECTED, 0x1F, 1, 1);
- if (rc)
- pt_debug(dev, DL_ERROR, "force single tx failed");
- /*suspend_scanning */
- rc = cmd->nonhid_cmd->suspend_scanning(dev, PT_CORE_CMD_UNPROTECTED);
- if (rc)
- pt_debug(dev, DL_ERROR, "suspend_scanning failed");
- /* Do calibration if requested */
- if (!dad->cmcp_force_calibrate) {
- pt_debug(dev, DL_INFO, "do calibration in single tx mode");
- rc = pt_perform_calibration(dev);
- if (rc)
- pt_debug(dev, DL_ERROR, "calibration failed");
- }
- /*resume_scanning */
- rc = cmd->nonhid_cmd->resume_scanning(dev, PT_CORE_CMD_UNPROTECTED);
- if (rc)
- pt_debug(dev, DL_ERROR, "resume_scanning failed");
- /*get all cmcp data from FW*/
- self_test_result_1 = pt_get_cmcp_info(dad, cmcp_info);
- if (self_test_result_1)
- pt_debug(dev, DL_ERROR, "pt_get_cmcp_info failed");
- /*restore to multi tx*/
- rc = cmd->nonhid_cmd->set_param(dev,
- PT_CORE_CMD_UNPROTECTED, 0x1F, 0, 1);
- if (rc)
- pt_debug(dev, DL_ERROR, "restore multi tx failed");
- /*suspend_scanning */
- rc = cmd->nonhid_cmd->suspend_scanning(dev, 0);
- if (rc)
- pt_debug(dev, DL_ERROR, "suspend_scanning failed");
- /* Do calibration if requested */
- if (!dad->cmcp_force_calibrate) {
- pt_debug(dev, DL_INFO, "do calibration in multi tx mode");
- rc = pt_perform_calibration(dev);
- if (rc)
- pt_debug(dev, DL_ERROR, "calibration failed");
- }
- /*resume_scanning */
- rc = cmd->nonhid_cmd->resume_scanning(dev, PT_CORE_CMD_UNPROTECTED);
- if (rc)
- pt_debug(dev, DL_ERROR, "resume_scanning failed");
- /*get cm cal data from FW*/
- self_test_result_2 = pt_get_cm_cal(dad, cmcp_info);
- if (self_test_result_2)
- pt_debug(dev, DL_ERROR, "pt_get_cm_cal failed");
- /* check scan state,try to fix if it is not right*/
- while (retry--) {
- rc = cmd->request_get_fw_mode(dev, PT_CORE_CMD_UNPROTECTED,
- &sys_mode, NULL);
- if (sys_mode != FW_SYS_MODE_SCANNING) {
- pt_debug(dev, DL_ERROR,
- "%s: fw mode: %d, retry: %d, rc = %d\n",
- __func__, sys_mode, retry, rc);
- rc = cmd->nonhid_cmd->resume_scanning(dev,
- PT_CORE_CMD_UNPROTECTED);
- }
- }
- rc = cmd->release_exclusive(dev);
- if (rc) {
- pt_debug(dev, DL_ERROR,
- "%s: Error on release exclusive rc = %d\n",
- __func__, rc);
- }
- pm_runtime_put(dev);
- /*start watchdog*/
- rc = cmd->request_start_wd(dev);
- if (rc)
- pt_debug(dev, DL_ERROR, "start watchdog failed");
- if (self_test_result_1 || self_test_result_2)
- goto self_test_failed;
- /* The tests are finished without failure */
- mutex_lock(&dad->sysfs_lock);
- dad->test_executed = 1;
- mutex_unlock(&dad->sysfs_lock);
- if (no_builtin_file)
- goto no_builtin;
- if ((test_item) & (CM_ENABLED))
- validate_cm_test_results(dev, configuration, cmcp_info,
- result, &final_pass, test_item);
- if ((test_item) & (CP_ENABLED))
- validate_cp_test_results(dev, configuration, cmcp_info,
- result, &final_pass, test_item);
- if ((dad->cmcp_test_items == CMCP_FULL)
- && (dad->cmcp_range_check == 0)) {
- /*full test and full check*/
- result->test_summary = result->cm_test_pass
- && result->cp_test_pass
- && result->short_test_pass;
- } else if ((dad->cmcp_test_items == CMCP_FULL)
- && (dad->cmcp_range_check == 1)) {
- /*full test and basic check*/
- result->test_summary = result->cm_sensor_gd_col_pass
- && result->cm_sensor_gd_row_pass
- && result->cm_sensor_validation_pass
- && result->cp_rx_validation_pass
- && result->cp_tx_validation_pass
- && result->short_test_pass;
- } else if (dad->cmcp_test_items == CMCP_CM_PANEL) {
- /*cm panel test result only*/
- result->test_summary = result->cm_sensor_gd_col_pass
- && result->cm_sensor_gd_row_pass
- && result->cm_sensor_validation_pass
- && result->cm_sensor_row_delta_pass
- && result->cm_sensor_col_delta_pass
- && result->cm_sensor_calibration_pass
- && result->cm_sensor_delta_pass;
- } else if (dad->cmcp_test_items == CMCP_CP_PANEL) {
- /*cp panel test result only*/
- result->test_summary = result->cp_sensor_delta_pass
- && result->cp_rx_validation_pass
- && result->cp_tx_validation_pass;
- } else if (dad->cmcp_test_items == CMCP_CM_BTN) {
- /*cm button test result only*/
- result->test_summary = result->cm_button_validation_pass
- && result->cm_button_delta_pass;
- } else if (dad->cmcp_test_items == CMCP_CP_BTN) {
- /*cp button test result only*/
- result->test_summary = result->cp_button_delta_pass
- && result->cp_button_average_pass
- && result->cp_button_validation_pass;
- }
- if (result->test_summary) {
- pt_debug(dev, DL_INFO,
- "%s: Finish Cm/Cp test! All Test Passed\n", __func__);
- index = scnprintf(buf, PT_MAX_PRBUF_SIZE, "Status: 1\n");
- } else {
- pt_debug(dev, DL_INFO,
- "%s: Finish Cm/Cp test! Range Check Failure\n",
- __func__);
- index = scnprintf(buf, PT_MAX_PRBUF_SIZE, "Status: 6\n");
- }
- goto cmcp_ready;
- mismatch:
- index = scnprintf(buf, PT_MAX_PRBUF_SIZE,
- "Status: 2\nInput cmcp threshold file mismatches with FW\n");
- goto cmcp_ready;
- invalid_item_btn:
- index = scnprintf(buf, PT_MAX_PRBUF_SIZE,
- "Status: 3\nFW doesn't support button!\n");
- goto cmcp_ready;
- invalid_item:
- index = scnprintf(buf, PT_MAX_PRBUF_SIZE,
- "Status: 4\nWrong test item or range check input!\nOnly support below items:\n0 - Cm/Cp Panel & Button with Gradient (Typical)\n1 - Cm Panel with Gradient\n2 - Cp Panel\n3 - Cm Button\n4 - Cp Button\nOnly support below range check:\n0 - Full Range Checking (default)\n1 - Basic Range Checking(TSG5 style)\n");
- goto cmcp_ready;
- self_test_failed:
- index = scnprintf(buf, PT_MAX_PRBUF_SIZE,
- "Status: 5\nget self test ID not supported!\n");
- goto cmcp_ready;
- cmcp_not_ready:
- index = scnprintf(buf, PT_MAX_PRBUF_SIZE, "Status: 0\n");
- goto cmcp_ready;
- no_builtin:
- index = scnprintf(buf, PT_MAX_PRBUF_SIZE,
- "Status: 7\nNo cmcp threshold file!\n");
- cmcp_ready:
- mutex_lock(&dad->sysfs_lock);
- dad->cmcp_test_in_progress = 0;
- mutex_unlock(&dad->sysfs_lock);
- exit:
- return index;
- }
- /*******************************************************************************
- * FUNCTION: pt_cmcp_test_store
- *
- * SUMMARY: The store method for cmcp_test sysfs node.Allows the user to
- * configure which cm/cp tests will be executed on the "cat" of this node.
- *
- * 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_cmcp_test_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t size)
- {
- struct pt_device_access_data *dad
- = pt_get_device_access_data(dev);
- u8 test_item = 0;
- u8 range_check = 0;
- u8 force_calibrate = 0;
- u32 input_data[4];
- int ret = 0;
- static const char * const cmcp_test_case_array[] = {"Full Cm/Cp test",
- "Cm panel test", "Cp panel test",
- "Cm button test", "Cp button test"};
- static const char * const cmcp_test_range_check_array[] = {
- "Full (default)", "Basic"};
- static const char * const cmcp_test_force_cal_array[] = {
- "Calibrate When Testing (default)", "No Calibration"};
- ssize_t length = 0;
- pm_runtime_get_sync(dev);
- mutex_lock(&dad->sysfs_lock);
- length = cmd->parse_sysfs_input(dev, buf, size, input_data,
- ARRAY_SIZE(input_data));
- if (length <= 0 || length > 3) {
- pt_debug(dev, DL_ERROR, "%s: Input format error!\n",
- __func__);
- dad->cmcp_test_items = -EINVAL;
- ret = -EINVAL;
- goto error;
- }
- /* Get test item */
- test_item = input_data[0];
- /* Get range check */
- if (length >= 2)
- range_check = input_data[1];
- /* Get force calibration */
- if (length == 3)
- force_calibrate = input_data[2];
- /*
- * Test item limitation:
- * 0: Perform all Tests
- * 1: CM Panel with Gradient
- * 2: CP Panel
- * 3: CM Button
- * 4: CP Button
- * Ranage check limitation:
- * 0: full check
- * 1: basic check
- * Force calibrate limitation:
- * 0: do calibration
- * 1: don't do calibration
- */
- if ((test_item < 0) || (test_item > 4) || (range_check > 1)
- || (force_calibrate > 1)) {
- pt_debug(dev, DL_ERROR,
- "%s: Test item should be 0~4; Range check should be 0~1; Force calibrate should be 0~1\n",
- __func__);
- dad->cmcp_test_items = -EINVAL;
- ret = -EINVAL;
- goto error;
- }
- /*
- * If it is not all Test, then range_check should be 0
- * because other test does not has concept of basic check
- */
- if (test_item > 0 && test_item < 5)
- range_check = 0;
- dad->cmcp_test_items = test_item;
- dad->cmcp_range_check = range_check;
- dad->cmcp_force_calibrate = force_calibrate;
- pt_debug(dev, DL_INFO,
- "%s: Test item=%s; Range check=%s; Force cal=%s.\n",
- __func__,
- cmcp_test_case_array[test_item],
- cmcp_test_range_check_array[range_check],
- cmcp_test_force_cal_array[force_calibrate]);
- error:
- mutex_unlock(&dad->sysfs_lock);
- pm_runtime_put(dev);
- if (ret)
- return ret;
- return size;
- }
- static DEVICE_ATTR(cmcp_test, 0600,
- pt_cmcp_test_show, pt_cmcp_test_store);
- /*******************************************************************************
- * FUNCTION: prepare_print_string
- *
- * SUMMARY: Formats input buffer to out buffer with string type,and increases
- * the index by size of formated data.
- *
- * RETURN:
- * index plus with size of formated data
- *
- * PARAMETERS:
- * *out_buf - output buffer to store formated data
- * *in_buf - input buffer to be formated
- * index - index in output buffer for appending content
- ******************************************************************************/
- int prepare_print_string(char *out_buf, char *in_buf, int index)
- {
- if ((out_buf == NULL) || (in_buf == NULL))
- return index;
- index += scnprintf(&out_buf[index], MAX_BUF_LEN - index,
- "%s", in_buf);
- return index;
- }
- /*******************************************************************************
- * FUNCTION: prepare_print_string
- *
- * SUMMARY: Formats input buffer to out buffer with decimal base,and increases
- * the index by size of formated data.
- *
- * RETURN:
- * index plus with size of formated data
- *
- * PARAMETERS:
- * *out_buf - output buffer to store formated data
- * *in_buf - input buffer to be formated
- * index - index in output buffer for appending content
- * data_num - data number in input buffer
- ******************************************************************************/
- int prepare_print_data(char *out_buf, int32_t *in_buf, int index, int data_num)
- {
- int i;
- if ((out_buf == NULL) || (in_buf == NULL))
- return index;
- for (i = 0; i < data_num; i++)
- index += scnprintf(&out_buf[index], MAX_BUF_LEN - index,
- "%d,", in_buf[i]);
- return index;
- }
- /*******************************************************************************
- * FUNCTION: save_header
- *
- * SUMMARY: Appends "header" for cmcp test result to output buffer.
- *
- * RETURN:
- * index plus with size of formated data
- *
- * PARAMETERS:
- * *out_buf - output buffer to store formated data
- * index - index in output buffer for appending content
- * *result - pointer to result structure
- ******************************************************************************/
- static int save_header(char *out_buf, int index, struct result *result)
- {
- struct rtc_time tm;
- char time_buf[100] = {0};
- #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0))
- struct timespec64 ts;
- ktime_get_real_ts64(&ts);
- rtc_time64_to_tm(ts.tv_sec, &tm);
- #else
- struct timex txc;
- do_gettimeofday(&(txc.time));
- rtc_time_to_tm(txc.time.tv_sec, &tm);
- #endif
- scnprintf(time_buf, 100, "%d/%d/%d,TIME,%d:%d:%d,", tm.tm_year+1900,
- tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
- index = prepare_print_string(out_buf, ",.header,\n", index);
- index = prepare_print_string(out_buf, ",DATE,", index);
- index = prepare_print_string(out_buf, &time_buf[0], index);
- index = prepare_print_string(out_buf, ",\n", index);
- index = prepare_print_string(out_buf, ",SW_VERSION,", index);
- index = prepare_print_string(out_buf, PT_DRIVER_VERSION, index);
- index = prepare_print_string(out_buf, ",\n", index);
- index = prepare_print_string(out_buf, ",.end,\n", index);
- index = prepare_print_string(out_buf, ",.engineering data,\n", index);
- return index;
- }
- /*******************************************************************************
- * FUNCTION: print_silicon_id
- *
- * SUMMARY: Formats input buffer(silicon id) to out buffer with
- * string type,and increases the index by size of formated data.
- *
- * RETURN:
- * index plus with size of formated data
- *
- * PARAMETERS:
- * *out_buf - output buffer to store formated data
- * *in_buf - input buffer to be formated
- * index - index in output buffer for appending content
- ******************************************************************************/
- static int print_silicon_id(char *out_buf, char *in_buf, int index)
- {
- index = prepare_print_string(out_buf, ",1,", index);
- index = prepare_print_string(out_buf, &in_buf[0], index);
- return index;
- }
- /*******************************************************************************
- * FUNCTION: save_engineering_data
- *
- * SUMMARY: Generates cmcp test result with *.csv format to output buffer, but
- * it doesn't include the header.
- *
- * RETURN:
- * index plus with size of formated data
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *out_buf - output buffer to store formated data
- * index - index in output buffer for appending content
- * *cmcp_info - pointer to cmcp_data structure
- * *configuration - pointer to configuration structure
- * *result - pointer to result structure
- * test_item - test control in bitwise
- * no_builtin_file - flag to determin if builtin-file exist
- ******************************************************************************/
- int save_engineering_data(struct device *dev, char *out_buf, int index,
- struct cmcp_data *cmcp_info, struct configuration *configuration,
- struct result *result, int test_item, int no_builtin_file)
- {
- int i;
- int j;
- int tx_num = 0;
- int rx_num = 0;
- int btn_num = 0;
- int tmp = 0;
- uint32_t fw_revision_control;
- uint32_t fw_config_ver;
- char device_id[20] = {0};
- struct pt_device_access_data *dad
- = pt_get_device_access_data(dev);
- if ((result == NULL) || (cmcp_info == NULL))
- return -EINVAL;
- tx_num = cmcp_info->tx_num;
- rx_num = cmcp_info->rx_num;
- btn_num = cmcp_info->btn_num;
- fw_revision_control = dad->si->ttdata.revctrl;
- fw_config_ver = dad->si->ttdata.fw_ver_conf;
- /*calculate silicon id*/
- result->device_id_low = 0;
- result->device_id_high = 0;
- for (i = 0; i < 4; i++)
- result->device_id_low =
- (result->device_id_low << 8) + dad->si->ttdata.mfg_id[i];
- for (i = 4; i < 8; i++)
- result->device_id_high =
- (result->device_id_high << 8) + dad->si->ttdata.mfg_id[i];
- scnprintf(device_id, 20, "%x%x",
- result->device_id_high, result->device_id_low);
- /*print test summary*/
- index = print_silicon_id(out_buf, &device_id[0], index);
- if (result->test_summary)
- index = prepare_print_string(out_buf, ",PASS,\n", index);
- else
- index = prepare_print_string(out_buf, ",FAIL,\n", index);
- /*revision ctrl number*/
- index = print_silicon_id(out_buf, &device_id[0], index);
- index = prepare_print_string(out_buf, ",FW revision Control,", index);
- index = prepare_print_data(out_buf, &fw_revision_control, index, 1);
- index = prepare_print_string(out_buf, "\n", index);
- /*config version*/
- index = print_silicon_id(out_buf, &device_id[0], index);
- index = prepare_print_string(out_buf, ",CONFIG_VER,", index);
- index = prepare_print_data(out_buf, &fw_config_ver, index, 1);
- index = prepare_print_string(out_buf, "\n", index);
- /* Shorts test */
- index = print_silicon_id(out_buf, &device_id[0], index);
- if (result->short_test_pass)
- index = prepare_print_string(out_buf, ",Shorts,PASS,\n", index);
- else
- index = prepare_print_string(out_buf, ",Shorts,FAIL,\n", index);
- if ((test_item & CM_ENABLED) == CM_ENABLED) {
- /*print BUTNS_CM_DATA_ROW00*/
- if (((test_item & CM_BTN) == CM_BTN) && (btn_num > 0)) {
- index = print_silicon_id(out_buf, &device_id[0], index);
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation,BUTNS_CM_DATA_ROW00,",
- index);
- index = prepare_print_data(out_buf,
- &cmcp_info->cm_btn_data[0],
- index,
- btn_num);
- index = prepare_print_string(out_buf, "\n", index);
- }
- if ((test_item & CM_PANEL) == CM_PANEL) {
- /*print CM_DATA_ROW*/
- for (i = 0; i < rx_num; i++) {
- index = print_silicon_id(out_buf, &device_id[0],
- index);
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation,CM_DATA_ROW",
- index);
- index = prepare_print_data(out_buf, &i,
- index, 1);
- for (j = 0; j < tx_num; j++)
- index = prepare_print_data(out_buf,
- &cmcp_info->cm_data_panel[j*rx_num+i],
- index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- }
- if (!no_builtin_file) {
- /*print CM_MAX_GRADIENT_COLS_PERCENT*/
- index = print_silicon_id(out_buf,
- &device_id[0], index);
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation,CM_MAX_GRADIENT_COLS_PERCENT,",
- index);
- for (i = 0; i < tx_num; i++) {
- char tmp_buf[10] = {0};
- scnprintf(tmp_buf, 10, "%d.%d,",
- cmcp_info->gd_sensor_col[i].gradient_val / 10,
- cmcp_info->gd_sensor_col[i].gradient_val % 10);
- index = prepare_print_string(out_buf,
- &tmp_buf[0], index);
- }
- index = prepare_print_string(out_buf,
- "\n", index);
- /*print CM_MAX_GRADIENT_ROWS_PERCENT*/
- index = print_silicon_id(out_buf,
- &device_id[0], index);
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation,CM_MAX_GRADIENT_ROWS_PERCENT,",
- index);
- for (i = 0; i < rx_num; i++) {
- char tmp_buf[10] = {0};
- scnprintf(tmp_buf, 10, "%d.%d,",
- cmcp_info->gd_sensor_row[i].gradient_val / 10,
- cmcp_info->gd_sensor_row[i].gradient_val % 10);
- index = prepare_print_string(out_buf,
- &tmp_buf[0], index);
- }
- index = prepare_print_string(out_buf,
- "\n", index);
- if (!dad->cmcp_range_check) {
- /*print CM_DELTA_COLUMN*/
- for (i = 0; i < rx_num; i++) {
- index = print_silicon_id(
- out_buf,
- &device_id[0], index);
- index = prepare_print_string(
- out_buf,
- ",Sensor Cm Validation,DELTA_COLUMNS_ROW",
- index);
- index = prepare_print_data(
- out_buf,
- &i, index, 1);
- index = prepare_print_data(
- out_buf,
- &tmp, index, 1);
- for (j = 1; j < tx_num; j++)
- index = prepare_print_data(
- out_buf,
- &cmcp_info->cm_sensor_column_delta[(j-1)*rx_num+i],
- index, 1);
- index = prepare_print_string(
- out_buf,
- "\n", index);
- }
- /*print CM_DELTA_ROW*/
- index = print_silicon_id(out_buf,
- &device_id[0],
- index);
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation,DELTA_ROWS_ROW",
- index);
- index = prepare_print_data(out_buf,
- &tmp, index, 1);
- for (j = 0; j < tx_num; j++)
- index = prepare_print_data(
- out_buf,
- &tmp, index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- for (i = 1; i < rx_num; i++) {
- index = print_silicon_id(
- out_buf,
- &device_id[0],
- index);
- index = prepare_print_string(
- out_buf,
- ",Sensor Cm Validation,DELTA_ROWS_ROW",
- index);
- index = prepare_print_data(
- out_buf, &i,
- index, 1);
- for (j = 0; j < tx_num; j++)
- index = prepare_print_data(
- out_buf,
- &cmcp_info->cm_sensor_row_delta[j*rx_num+i-1],
- index, 1);
- index = prepare_print_string(
- out_buf,
- "\n", index);
- }
- /*print pass/fail Sensor Cm Validation*/
- index = print_silicon_id(out_buf, &device_id[0],
- index);
- if (result->cm_test_pass)
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation,PASS,\n",
- index);
- else
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation,FAIL,\n",
- index);
- }
- }
- }
- if (!no_builtin_file) {
- if (((test_item & CM_BTN) == CM_BTN) && (btn_num > 0)
- && (!dad->cmcp_range_check)) {
- char tmp_buf[10] = {0};
- /*print Button Element by Element */
- index = print_silicon_id(out_buf, &device_id[0],
- index);
- if (result->cm_button_validation_pass)
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Button Element by Element,PASS\n",
- index);
- else
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Button Element by Element,FAIL\n",
- index);
- /*
- *print Sensor Cm Validation
- *- Buttons Range Buttons Range
- */
- index = print_silicon_id(out_buf,
- &device_id[0], index);
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Buttons Range,Buttons Range,",
- index);
- scnprintf(tmp_buf, 10, "%d.%d,",
- cmcp_info->cm_delta_data_btn / 10,
- cmcp_info->cm_delta_data_btn % 10);
- index = prepare_print_string(out_buf,
- &tmp_buf[0], index);
- index = prepare_print_string(out_buf,
- "\n", index);
- /*print Sensor Cm Validation
- *-Buttons Range Cm_button_avg
- */
- index = print_silicon_id(out_buf,
- &device_id[0], index);
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Buttons Range,Cm_button_avg,",
- index);
- index = prepare_print_data(out_buf,
- &cmcp_info->cm_ave_data_btn,
- index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- /*print Sensor Cm Validation
- * -Buttons Range Cm_button_avg
- */
- index = print_silicon_id(out_buf,
- &device_id[0], index);
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Buttons Range,Cm_button_cal,",
- index);
- index = prepare_print_data(out_buf,
- &cmcp_info->cm_cal_data_btn,
- index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- /*print Sensor Cm Validation
- *-Buttons Range pass/fail
- */
- index = print_silicon_id(out_buf,
- &device_id[0], index);
- if (result->cm_button_delta_pass)
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Buttons Range,PASS,LIMITS,",
- index);
- else
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Buttons Range,FAIL,LIMITS,",
- index);
- index = prepare_print_data(out_buf,
- &configuration->cm_max_delta_button_percent,
- index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- }
- if ((test_item & CM_PANEL) == CM_PANEL &&
- !dad->cmcp_range_check) {
- char tmp_buf[10] = {0};
- /*print Cm_sensor_cal */
- index = print_silicon_id(out_buf,
- &device_id[0], index);
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Calibration,Cm_sensor_cal,",
- index);
- index = prepare_print_data(out_buf,
- &cmcp_info->cm_cal_data_panel,
- index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- /*print Cm_sensor_cal limit*/
- index = print_silicon_id(out_buf,
- &device_id[0], index);
- if (result->cm_sensor_calibration_pass)
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Calibration,PASS,LIMITS,",
- index);
- else
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Calibration,FAIL,LIMITS,",
- index);
- index = prepare_print_data(out_buf,
- &configuration->cm_min_limit_cal,
- index, 1);
- index = prepare_print_data(out_buf,
- &configuration->cm_max_limit_cal,
- index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- /*print Columns Delta Matrix*/
- index = print_silicon_id(out_buf,
- &device_id[0], index);
- if (result->cm_sensor_col_delta_pass)
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Columns Delta Matrix,PASS,LIMITS,",
- index);
- else
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Columns Delta Matrix,FAIL,LIMITS,",
- index);
- index = prepare_print_data(out_buf,
- &configuration->cm_range_limit_col,
- index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- /*print Cm Validation - Element by Element*/
- index = print_silicon_id(out_buf,
- &device_id[0], index);
- if (result->cm_sensor_validation_pass)
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Element by Element,PASS,",
- index);
- else
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Element by Element,FAIL,",
- index);
- index = prepare_print_string(out_buf,
- "\n", index);
- /*print Cm Validation -Gradient Cols*/
- index = print_silicon_id(out_buf,
- &device_id[0], index);
- if (result->cm_sensor_gd_col_pass)
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Gradient Cols,PASS,",
- index);
- else
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Gradient Cols,FAIL,",
- index);
- index = prepare_print_string(out_buf,
- "\n", index);
- /*print Cm Validation -Gradient Rows*/
- index = print_silicon_id(out_buf,
- &device_id[0], index);
- if (result->cm_sensor_gd_row_pass)
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Gradient Rows,PASS,",
- index);
- else
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Gradient Rows,FAIL,",
- index);
- index = prepare_print_string(out_buf,
- "\n", index);
- /*
- * Print Sensor Cm Validation
- * -Rows Delta Matrix
- */
- index = print_silicon_id(out_buf,
- &device_id[0], index);
- if (result->cm_sensor_row_delta_pass)
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Rows Delta Matrix,PASS,LIMITS,",
- index);
- else
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Rows Delta Matrix,FAIL,LIMITS,",
- index);
- index = prepare_print_data(out_buf,
- &configuration->cm_range_limit_row,
- index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- /*print Cm_sensor_avg */
- index = print_silicon_id(out_buf,
- &device_id[0], index);
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Sensor Range,Cm_sensor_avg,",
- index);
- index = prepare_print_data(out_buf,
- &cmcp_info->cm_ave_data_panel,
- index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- /*printSensor Cm Validation -
- * Sensor Range, Sensor Range
- */
- index = print_silicon_id(out_buf,
- &device_id[0], index);
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Sensor Range,Sensor Range,",
- index);
- scnprintf(tmp_buf, 10, "%d.%d,",
- cmcp_info->cm_sensor_delta / 10,
- cmcp_info->cm_sensor_delta % 10);
- index = prepare_print_string(out_buf,
- &tmp_buf[0], index);
- index = prepare_print_string(out_buf,
- "\n", index);
- /*print Sensor Cm Validation - Sensor Range*/
- index = print_silicon_id(out_buf,
- &device_id[0], index);
- if (result->cm_sensor_delta_pass)
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Sensor Range,PASS,LIMITS,",
- index);
- else
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Sensor Range,FAIL,LIMITS,",
- index);
- index = prepare_print_data(out_buf,
- &configuration->cm_max_delta_sensor_percent,
- index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- }
- }
- }
- if ((test_item & CP_ENABLED) == CP_ENABLED) {
- if (((test_item & CP_BTN) == CP_BTN) && (btn_num > 0)) {
- /*print BUTNS_CP_DATA_ROW00 */
- index = print_silicon_id(out_buf, &device_id[0], index);
- index = prepare_print_string(out_buf,
- ",Self-cap Calibration Check,BUTNS_CP_DATA_ROW00,",
- index);
- index = prepare_print_data(out_buf,
- &cmcp_info->cp_btn_data[0],
- index, btn_num);
- index = prepare_print_string(out_buf,
- "\n", index);
- if (!no_builtin_file && !dad->cmcp_range_check) {
- /*print Cp Button Element by Element */
- index = print_silicon_id(out_buf, &device_id[0],
- index);
- if (result->cp_button_validation_pass)
- index = prepare_print_string(out_buf,
- ",Self-cap Calibration Check - Button Element by Element,PASS\n",
- index);
- else
- index = prepare_print_string(out_buf,
- ",Self-cap Calibration Check - Button Element by Element,FAIL\n",
- index);
- /*print cp_button_ave */
- index = print_silicon_id(out_buf,
- &device_id[0], index);
- index = prepare_print_string(out_buf,
- ",Self-cap Calibration Check,Cp_button_avg,",
- index);
- index = prepare_print_data(out_buf,
- &cmcp_info->cp_button_ave,
- index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- /*print Cp_button_cal */
- index = print_silicon_id(out_buf,
- &device_id[0], index);
- index = prepare_print_string(out_buf,
- ",Self-cap Calibration Check,Cp_button_cal,",
- index);
- index = prepare_print_data(out_buf,
- &cmcp_info->cp_btn_cal,
- index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- }
- }
- if ((test_item & CP_PANEL) == CP_PANEL) {
- /*print CP_DATA_RX */
- index = print_silicon_id(out_buf, &device_id[0], index);
- index = prepare_print_string(out_buf,
- ",Self-cap Calibration Check,CP_DATA_RX,", index);
- index = prepare_print_data(out_buf,
- &cmcp_info->cp_rx_data_panel[0], index, rx_num);
- index = prepare_print_string(out_buf, "\n", index);
- /*print CP_DATA_TX */
- index = print_silicon_id(out_buf, &device_id[0], index);
- index = prepare_print_string(out_buf,
- ",Self-cap Calibration Check,CP_DATA_TX,", index);
- index = prepare_print_data(out_buf,
- &cmcp_info->cp_tx_data_panel[0], index, tx_num);
- index = prepare_print_string(out_buf, "\n", index);
- }
- if (((test_item & CP_BTN) == CP_BTN) && (btn_num > 0)
- && !dad->cmcp_range_check) {
- if (!no_builtin_file) {
- char tmp_buf[10] = {0};
- /*print Cp_delta_button */
- index = print_silicon_id(out_buf, &device_id[0],
- index);
- index = prepare_print_string(out_buf,
- ",Self-cap Calibration Check,Cp_delta_button,",
- index);
- scnprintf(tmp_buf, 10, "%d.%d,",
- cmcp_info->cp_button_delta / 10,
- cmcp_info->cp_button_delta % 10);
- index = prepare_print_string(out_buf,
- &tmp_buf[0], index);
- index = prepare_print_string(out_buf, "\n",
- index);
- }
- }
- if ((test_item & CP_PANEL) == CP_PANEL &&
- !dad->cmcp_range_check) {
- if (!no_builtin_file) {
- char tmp_buf[10] = {0};
- /*print Cp_delta_rx */
- index = print_silicon_id(out_buf, &device_id[0],
- index);
- index = prepare_print_string(out_buf,
- ",Self-cap Calibration Check,Cp_delta_rx,",
- index);
- scnprintf(tmp_buf, 10, "%d.%d,",
- cmcp_info->cp_sensor_rx_delta / 10,
- cmcp_info->cp_sensor_rx_delta % 10);
- index = prepare_print_string(out_buf,
- &tmp_buf[0], index);
- index = prepare_print_string(out_buf, "\n",
- index);
- /*print Cp_delta_tx */
- index = print_silicon_id(out_buf, &device_id[0],
- index);
- index = prepare_print_string(out_buf,
- ",Self-cap Calibration Check,Cp_delta_tx,",
- index);
- scnprintf(tmp_buf, 10, "%d.%d,",
- cmcp_info->cp_sensor_tx_delta / 10,
- cmcp_info->cp_sensor_tx_delta % 10);
- index = prepare_print_string(out_buf,
- &tmp_buf[0], index);
- index = prepare_print_string(out_buf, "\n",
- index);
- /*print Cp_sensor_avg_rx */
- index = print_silicon_id(out_buf, &device_id[0],
- index);
- index = prepare_print_string(out_buf,
- ",Self-cap Calibration Check,Cp_sensor_avg_rx,",
- index);
- index = prepare_print_data(out_buf,
- &cmcp_info->cp_rx_ave_data_panel,
- index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- /*print Cp_sensor_avg_tx */
- index = print_silicon_id(out_buf,
- &device_id[0], index);
- index = prepare_print_string(out_buf,
- ",Self-cap Calibration Check,Cp_sensor_avg_tx,",
- index);
- index = prepare_print_data(out_buf,
- &cmcp_info->cp_tx_ave_data_panel,
- index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- /*print Cp_sensor_cal_rx */
- index = print_silicon_id(out_buf,
- &device_id[0], index);
- index = prepare_print_string(out_buf,
- ",Self-cap Calibration Check,Cp_sensor_cal_rx,",
- index);
- index = prepare_print_data(out_buf,
- &cmcp_info->cp_rx_cal_data_panel[0],
- index, rx_num);
- index = prepare_print_string(out_buf,
- "\n", index);
- /*print Cp_sensor_cal_tx */
- index = print_silicon_id(out_buf,
- &device_id[0], index);
- index = prepare_print_string(out_buf,
- ",Self-cap Calibration Check,Cp_sensor_cal_tx,",
- index);
- index = prepare_print_data(out_buf,
- &cmcp_info->cp_tx_cal_data_panel[0],
- index, tx_num);
- index = prepare_print_string(out_buf,
- "\n", index);
- }
- }
- if (!no_builtin_file && !dad->cmcp_range_check) {
- /*print cp test limits */
- index = print_silicon_id(out_buf, &device_id[0], index);
- if (result->cp_test_pass)
- index = prepare_print_string(out_buf,
- ",Self-cap Calibration Check,PASS, LIMITS,",
- index);
- else
- index = prepare_print_string(out_buf,
- ",Self-cap Calibration Check,FAIL, LIMITS,",
- index);
- index = prepare_print_string(out_buf,
- "CP_MAX_DELTA_SENSOR_RX_PERCENT,", index);
- index = prepare_print_data(out_buf,
- &configuration->cp_max_delta_sensor_rx_percent,
- index, 1);
- index = prepare_print_string(out_buf,
- "CP_MAX_DELTA_SENSOR_TX_PERCENT,", index);
- index = prepare_print_data(out_buf,
- &configuration->cp_max_delta_sensor_tx_percent,
- index, 1);
- index = prepare_print_string(out_buf,
- "CP_MAX_DELTA_BUTTON_PERCENT,", index);
- index = prepare_print_data(out_buf,
- &configuration->cp_max_delta_button_percent,
- index, 1);
- index = prepare_print_string(out_buf, "\n", index);
- }
- }
- if (!no_builtin_file) {
- if ((test_item & CM_ENABLED) == CM_ENABLED) {
- if ((test_item & CM_PANEL) == CM_PANEL) {
- /*print columns gradient limit*/
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation,MAX_LIMITS,CM_MAX_GRADIENT_COLS_PERCENT,",
- index);
- index = prepare_print_data(out_buf,
- &configuration->cm_max_table_gradient_cols_percent[0],
- index,
- configuration->cm_max_table_gradient_cols_percent_size);
- index = prepare_print_string(out_buf,
- "\n", index);
- /*print rows gradient limit*/
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation,MAX_LIMITS,CM_MAX_GRADIENT_ROWS_PERCENT,",
- index);
- index = prepare_print_data(out_buf,
- &configuration->cm_max_table_gradient_rows_percent[0],
- index,
- configuration->cm_max_table_gradient_rows_percent_size);
- index = prepare_print_string(out_buf,
- "\n", index);
- /*print cm max limit*/
- for (i = 0; i < rx_num; i++) {
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation,MAX_LIMITS,CM_DATA_ROW",
- index);
- index = prepare_print_data(out_buf,
- &i, index, 1);
- for (j = 0; j < tx_num; j++)
- index = prepare_print_data(
- out_buf,
- &configuration->cm_min_max_table_sensor[i*tx_num*2+j*2+1],
- index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- }
- }
- if (((test_item & CM_BTN) == CM_BTN) && (btn_num > 0)) {
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation,MAX LIMITS,M_BUTNS,",
- index);
- for (j = 0; j < btn_num; j++) {
- index = prepare_print_data(out_buf,
- &configuration->cm_min_max_table_btn[2*j+1],
- index, 1);
- }
- index = prepare_print_string(out_buf,
- "\n", index);
- }
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation MAX LIMITS\n", index);
- if ((test_item & CM_PANEL) == CM_PANEL) {
- /*print cm min limit*/
- for (i = 0; i < rx_num; i++) {
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation,MIN_LIMITS,CM_DATA_ROW",
- index);
- index = prepare_print_data(out_buf, &i,
- index, 1);
- for (j = 0; j < tx_num; j++)
- index = prepare_print_data(
- out_buf,
- &configuration->cm_min_max_table_sensor[i*tx_num*2 + j*2],
- index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- }
- }
- if (((test_item & CM_BTN) == CM_BTN) && (btn_num > 0)) {
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation,MIN LIMITS,M_BUTNS,",
- index);
- for (j = 0; j < btn_num; j++) {
- index = prepare_print_data(out_buf,
- &configuration->cm_min_max_table_btn[2*j],
- index, 1);
- }
- index = prepare_print_string(out_buf,
- "\n", index);
- }
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation MIN LIMITS\n", index);
- }
- if ((test_item & CP_ENABLED) == CP_ENABLED) {
- if ((test_item & CP_PANEL) == CP_PANEL) {
- /*print cp tx max limit*/
- index = prepare_print_string(out_buf,
- ",Self-cap Calibration Check,MAX_LIMITS,TX,",
- index);
- for (i = 0; i < tx_num; i++)
- index = prepare_print_data(out_buf,
- &configuration->cp_min_max_table_tx[i*2+1],
- index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- /*print cp rx max limit*/
- index = prepare_print_string(out_buf,
- ",Self-cap Calibration Check,MAX_LIMITS,RX,",
- index);
- for (i = 0; i < rx_num; i++)
- index = prepare_print_data(out_buf,
- &configuration->cp_min_max_table_rx[i*2+1],
- index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- }
- /*print cp btn max limit*/
- if (((test_item & CP_BTN) == CP_BTN) && (btn_num > 0)) {
- index = prepare_print_string(out_buf,
- ",Self-cap Calibration Check,MAX_LIMITS,S_BUTNS,",
- index);
- for (i = 0; i < btn_num; i++)
- index = prepare_print_data(out_buf,
- &configuration->cp_min_max_table_btn[i*2+1],
- index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- }
- if ((test_item & CP_PANEL) == CP_PANEL) {
- /*print cp tx min limit*/
- index = prepare_print_string(out_buf,
- ",Self-cap Calibration Check,MIN_LIMITS,TX,",
- index);
- for (i = 0; i < tx_num; i++)
- index = prepare_print_data(out_buf,
- &configuration->cp_min_max_table_tx[i*2],
- index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- /*print cp rx min limit*/
- index = prepare_print_string(out_buf,
- ",Self-cap Calibration Check,MIN_LIMITS,RX,",
- index);
- for (i = 0; i < rx_num; i++)
- index = prepare_print_data(out_buf,
- &configuration->cp_min_max_table_rx[i*2],
- index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- }
- /*print cp btn min limit*/
- if (((test_item & CP_BTN) == CP_BTN) && (btn_num > 0)) {
- index = prepare_print_string(out_buf,
- ",Self-cap Calibration Check,MIN_LIMITS,S_BUTNS,",
- index);
- for (i = 0; i < btn_num; i++)
- index = prepare_print_data(out_buf,
- &configuration->cp_min_max_table_btn[i*2],
- index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- }
- }
- }
- return index;
- }
- /*******************************************************************************
- * FUNCTION: result_save
- *
- * SUMMARY: Malloc memory for output buffer and populate with the cmcp test
- * header and results in the csv file format.
- *
- * NOTE: It supports simple_read_from_buffer() to read data multiple times to
- * the buffer.
- *
- * RETURN:
- * Size of data printed to "buf"
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *buf - the user space buffer to read to
- * *configuration - pointer to configuration structure
- * *result - pointer to result structure
- * *cmcp_info - pointer to cmcp_data structure
- * *ppos - the current position in the buffer
- * count - the maximum number of bytes to read
- * test_item - test control in bitwise
- * no_builtin_file - flag to determine if builtin-file exist
- ******************************************************************************/
- int result_save(struct device *dev, char *buf,
- struct configuration *configuration, struct result *result,
- struct cmcp_data *cmcp_info, loff_t *ppos, size_t count, int test_item,
- int no_builtin_file)
- {
- u8 *out_buf = NULL;
- int index = 0;
- int byte_left;
- out_buf = kzalloc(MAX_BUF_LEN, GFP_KERNEL);
- if (configuration == NULL) {
- pt_debug(dev, DL_WARN, "config is NULL");
- return -ENOMEM;
- }
- if (result == NULL) {
- pt_debug(dev, DL_WARN, "result is NULL");
- return -ENOMEM;
- }
- if (cmcp_info == NULL) {
- pt_debug(dev, DL_WARN, "cmcp_info is NULL");
- return -ENOMEM;
- }
- index = save_header(out_buf, index, result);
- index = save_engineering_data(dev, out_buf, index,
- cmcp_info, configuration, result,
- test_item, no_builtin_file);
- byte_left = simple_read_from_buffer(buf, count, ppos, out_buf, index);
- kfree(out_buf);
- return byte_left;
- }
- /*******************************************************************************
- * FUNCTION: cmcp_results_debugfs_open
- *
- * SUMMARY: Open method for cmcp_results debugfs node.
- *
- * RETURN: 0 = success
- *
- * PARAMETERS:
- * *inode - file inode number
- * *filp - file pointer to debugfs file
- ******************************************************************************/
- static int cmcp_results_debugfs_open(struct inode *inode,
- struct file *filp)
- {
- filp->private_data = inode->i_private;
- return 0;
- }
- /*******************************************************************************
- * FUNCTION: cmcp_results_debugfs_close
- *
- * SUMMARY: Close method for cmcp_results debugfs node.
- *
- * RETURN: 0 = success
- *
- * PARAMETERS:
- * *inode - file inode number
- * *filp - file pointer to debugfs file
- ******************************************************************************/
- static int cmcp_results_debugfs_close(struct inode *inode,
- struct file *filp)
- {
- filp->private_data = NULL;
- return 0;
- }
- /*******************************************************************************
- * FUNCTION: cmcp_results_debugfs_read
- *
- * SUMMARY: Read method for cmcp_results debugfs node. This function prints
- * cmcp test results 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 cmcp_results_debugfs_read(struct file *filp,
- char __user *buf, size_t count, loff_t *ppos)
- {
- struct pt_device_access_data *dad = filp->private_data;
- struct device *dev;
- struct cmcp_data *cmcp_info = dad->cmcp_info;
- struct result *result = dad->result;
- struct configuration *configuration = dad->configs;
- int ret = 0;
- int test_item;
- int no_builtin_file = 0;
- int test_executed = 0;
- dev = dad->dev;
- mutex_lock(&dad->sysfs_lock);
- test_executed = dad->test_executed;
- test_item = pt_cmcp_get_test_item(dad->cmcp_test_items);
- if (dad->builtin_cmcp_threshold_status < 0) {
- pt_debug(dev, DL_WARN,
- "%s: No cmcp threshold file.\n", __func__);
- no_builtin_file = 1;
- }
- mutex_unlock(&dad->sysfs_lock);
- if (test_executed)
- /*save result to buf*/
- ret = result_save(dev, buf, configuration, result, cmcp_info,
- ppos, count, test_item, no_builtin_file);
- else {
- char warning_info[] =
- "No test result available!\n";
- pt_debug(dev, DL_ERROR,
- "%s: No test result available!\n", __func__);
- return simple_read_from_buffer(buf, count, ppos, warning_info,
- strlen(warning_info));
- }
- return ret;
- }
- static const struct file_operations cmcp_results_debugfs_fops = {
- .open = cmcp_results_debugfs_open,
- .release = cmcp_results_debugfs_close,
- .read = cmcp_results_debugfs_read,
- .write = NULL,
- };
- /*******************************************************************************
- * FUNCTION: cmcp_return_offset_of_new_case
- *
- * SUMMARY: Returns the buffer offset of new test case
- *
- * NOTE: There are two static variable inside this function.
- *
- * RETURN: offset index for new case
- *
- * PARAMETERS:
- * *bufPtr - pointer to input buffer
- * first_time - flag to initialize some static variable
- * (0:init; 1:don't init)
- * *pFileEnd - pointer to the end of file for safe check
- ******************************************************************************/
- u32 cmcp_return_offset_of_new_case(const char *bufPtr, u32 first_time,
- const char *pFileEnd)
- {
- static u32 offset, first_search;
- if (first_time == 0) {
- first_search = 0;
- offset = 0;
- }
- if (first_search != 0) {
- /* Search one case */
- for (;;) {
- /* Search ASCII_LF */
- while (bufPtr < pFileEnd) {
- if (*bufPtr++ != ASCII_LF)
- offset++;
- else
- break;
- }
- if (bufPtr >= pFileEnd)
- break;
- offset++;
- /*
- * Single line: end loop
- * Multiple lines: continue loop
- */
- if (*bufPtr != ASCII_COMMA)
- break;
- }
- } else
- first_search = 1;
- return offset;
- }
- /*******************************************************************************
- * FUNCTION: cmcp_get_case_info_from_threshold_file
- *
- * SUMMARY: Gets test case information from cmcp threshold file
- *
- * RETURN:
- * Number of test cases
- *
- * PARAMETERS:
- * *dev - pointer to Device structure
- * *buf - pointer to input file
- * *search_array - pointer to test_case_search structure
- * file_size - size of input file for safe check
- ******************************************************************************/
- u32 cmcp_get_case_info_from_threshold_file(struct device *dev, const char *buf,
- struct test_case_search *search_array, u32 file_size)
- {
- u32 case_num = 0, buffer_offset = 0, name_count = 0, first_search = 0;
- const char *pFileEnd = buf + file_size;
- pt_debug(dev, DL_INFO, "%s: Search cmcp threshold file\n",
- __func__);
- /* Get all the test cases */
- for (case_num = 0; case_num < MAX_CASE_NUM; case_num++) {
- buffer_offset =
- cmcp_return_offset_of_new_case(&buf[buffer_offset],
- first_search, pFileEnd);
- first_search = 1;
- if (buf[buffer_offset] == 0)
- break;
- for (name_count = 0; name_count < NAME_SIZE_MAX; name_count++) {
- /* File end */
- if (buf[buffer_offset + name_count] == ASCII_COMMA)
- break;
- search_array[case_num].name[name_count] =
- buf[buffer_offset + name_count];
- }
- /* Exit when buffer offset is larger than file size */
- if (buffer_offset >= file_size)
- break;
- search_array[case_num].name_size = name_count;
- search_array[case_num].offset = buffer_offset;
- /*
- * pt_debug(dev, DL_INFO, "Find case %d: Name is %s;
- * Name size is %d; Case offset is %d\n",
- * case_num,
- * search_array[case_num].name,
- * search_array[case_num].name_size,
- * search_array[case_num].offset);
- */
- }
- return case_num;
- }
- /*******************************************************************************
- * FUNCTION: cmcp_compose_data
- *
- * SUMMARY: Composes one value based on data of each bit
- *
- * RETURN:
- * Value that composed from buffer
- *
- * PARAMETERS:
- * *buf - pointer to input file
- * count - number of data elements in *buf in decimal
- ******************************************************************************/
- int cmcp_compose_data(char *buf, u32 count)
- {
- u32 base_array[] = {1, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9};
- int value = 0;
- u32 index = 0;
- for (index = 0; index < count; index++)
- value += buf[index] * base_array[count - 1 - index];
- return value;
- }
- /*******************************************************************************
- * FUNCTION: cmcp_return_one_value
- *
- * SUMMARY: Parses csv file at a given row and offset and combines multiple
- * "bits' as a single value. Handles data over multiple lines and various
- * end-of-line characters.
- *
- * NOTE: There is a static value to calculate line count inside this function.
- *
- * RETURN:
- * Value that parsed from buffer
- *
- * PARAMETERS:
- * *dev - pointer to devices structure
- * *buf - pointer to input buffer
- * *offset - offset index of input buffer
- * *line_num - store line count
- * pFileEnd - pointer to the end of threshold file
- ******************************************************************************/
- int cmcp_return_one_value(struct device *dev, const char *buf, u32 *offset,
- u32 *line_num, const char *pFileEnd)
- {
- int value = -1;
- char tmp_buffer[10];
- u32 count = 0;
- u32 tmp_offset = *offset;
- static u32 line_count = 1;
- /* Bypass extra commas */
- while (((buf + tmp_offset + 1) < pFileEnd)
- && buf[tmp_offset] == ASCII_COMMA
- && buf[tmp_offset + 1] == ASCII_COMMA)
- tmp_offset++;
- if ((buf + tmp_offset + 1) >= pFileEnd)
- goto exit;
- /* Windows and Linux difference at the end of one line */
- if (buf[tmp_offset] == ASCII_COMMA && buf[tmp_offset + 1] == ASCII_CR) {
- if ((buf + tmp_offset + 2) < pFileEnd) {
- if (buf[tmp_offset + 2] == ASCII_LF)
- tmp_offset += 2;
- } else
- goto exit;
- } else if (buf[tmp_offset] == ASCII_COMMA &&
- buf[tmp_offset + 1] == ASCII_LF)
- tmp_offset += 1;
- else if (buf[tmp_offset] == ASCII_COMMA
- && buf[tmp_offset + 1] == ASCII_CR)
- tmp_offset += 1;
- if ((buf + tmp_offset + 1) >= pFileEnd)
- goto exit;
- /* New line for multiple lines */
- if ((buf[tmp_offset] == ASCII_LF || buf[tmp_offset] == ASCII_CR) &&
- buf[tmp_offset + 1] == ASCII_COMMA) {
- tmp_offset++;
- line_count++;
- pt_debug(dev, DL_DEBUG, "%s: Line Count = %d\n",
- __func__, line_count);
- }
- /* Beginning */
- if (buf[tmp_offset] == ASCII_COMMA) {
- tmp_offset++;
- for (;;) {
- if ((buf + tmp_offset) >= pFileEnd)
- break;
- if ((buf[tmp_offset] >= ASCII_ZERO)
- && (buf[tmp_offset] <= ASCII_NINE)) {
- tmp_buffer[count++] =
- buf[tmp_offset] - ASCII_ZERO;
- tmp_offset++;
- } else {
- if (count != 0) {
- value = cmcp_compose_data(tmp_buffer,
- count);
- /*pt_debug(dev, DL_DEBUG, */
- /* ",%d", value);*/
- } else {
- /* 0 indicates no data available */
- value = -1;
- }
- break;
- }
- }
- } else {
- /* Multiple line: line count */
- if (line_num)
- *line_num = line_count;
- /* Reset for next case */
- line_count = 1;
- }
- exit:
- *offset = tmp_offset;
- return value;
- }
- /*******************************************************************************
- * FUNCTION: cmcp_get_configuration_info
- *
- * SUMMARY: Gets cmcp configuration information.
- *
- * PARAMETERS:
- * *dev - pointer to devices structure
- * *buf - pointer to input buffer
- * *search_array - pointer to test_case_search structure
- * case_count - number of test cases
- * *field_array - pointer to test_case_field structure
- * *config - pointer to configuration structure
- * file_size - file size of threshold file
- ******************************************************************************/
- void cmcp_get_configuration_info(struct device *dev,
- const char *buf, struct test_case_search *search_array,
- u32 case_count, struct test_case_field *field_array,
- struct configuration *config, u32 file_size)
- {
- u32 count = 0, sub_count = 0;
- u32 exist_or_not = 0;
- u32 value_offset = 0;
- int retval = 0;
- u32 data_num = 0;
- u32 line_num = 1;
- const char *pFileEnd = buf + file_size;
- pt_debug(dev, DL_INFO,
- "%s: Fill configuration struct per cmcp threshold file\n",
- __func__);
- /* Search cases */
- for (count = 0; count < MAX_CASE_NUM; count++) {
- exist_or_not = 0;
- for (sub_count = 0; sub_count < case_count; sub_count++) {
- if (!strncmp(field_array[count].name,
- search_array[sub_count].name,
- field_array[count].name_size)) {
- exist_or_not = 1;
- break;
- }
- }
- field_array[count].exist_or_not = exist_or_not;
- pt_debug(dev, DL_DEBUG,
- "%s: Field Array[%d] exists: %d, type: %d\n",
- __func__, count, exist_or_not, field_array[count].type);
- /* Clear data number */
- data_num = 0;
- if (exist_or_not == 1) {
- switch (field_array[count].type) {
- case TEST_CASE_TYPE_NO:
- field_array[count].data_num = 0;
- field_array[count].line_num = 1;
- break;
- case TEST_CASE_TYPE_ONE:
- value_offset = search_array[sub_count].offset
- + search_array[sub_count].name_size;
- *field_array[count].bufptr =
- cmcp_return_one_value(dev, buf,
- &value_offset, 0, pFileEnd);
- field_array[count].data_num = 1;
- field_array[count].line_num = 1;
- break;
- case TEST_CASE_TYPE_MUL:
- case TEST_CASE_TYPE_MUL_LINES:
- line_num = 1;
- value_offset = search_array[sub_count].offset
- + search_array[sub_count].name_size;
- for (;;) {
- retval = cmcp_return_one_value(
- dev, buf, &value_offset, &line_num,
- pFileEnd);
- if (retval >= 0) {
- *field_array[count].bufptr++ =
- retval;
- data_num++;
- } else
- break;
- }
- field_array[count].data_num = data_num;
- field_array[count].line_num = line_num;
- break;
- default:
- break;
- }
- pt_debug(dev, DL_DEBUG,
- "%s: %s: Data count is %d, line number is %d\n",
- __func__,
- field_array[count].name,
- field_array[count].data_num,
- field_array[count].line_num);
- } else
- pt_debug(dev, DL_ERROR, "%s: !!! %s doesn't exist\n",
- __func__, field_array[count].name);
- }
- }
- /*******************************************************************************
- * FUNCTION: cmcp_get_basic_info
- *
- * SUMMARY: Gets basic information for cmcp test, such as available test item,
- * number of tx, rx, button.
- *
- * PARAMETERS:
- * *dev - pointer to devices structure
- * *field_array - pointer to test_case_field structure
- * *config - pointer to configuration structure
- ******************************************************************************/
- void cmcp_get_basic_info(struct device *dev,
- struct test_case_field *field_array, struct configuration *config)
- {
- u32 tx_num = 0;
- u32 index = 0;
- config->is_valid_or_not = 1; /* Set to valid by default */
- config->cm_enabled = 0;
- config->cp_enabled = 0;
- if (field_array[CM_TEST_INPUTS].exist_or_not)
- config->cm_enabled = 1;
- if (field_array[CP_TEST_INPUTS].exist_or_not)
- config->cp_enabled = 1;
- /* Get basic information only when CM and CP are enabled */
- if (config->cm_enabled && config->cp_enabled) {
- pt_debug(dev, DL_INFO,
- "%s: Find CM and CP thresholds\n", __func__);
- config->rx_num =
- field_array[PER_ELEMENT_MIN_MAX_TABLE_SENSOR].line_num;
- tx_num =
- (field_array[PER_ELEMENT_MIN_MAX_TABLE_SENSOR].data_num >> 1)
- /field_array[PER_ELEMENT_MIN_MAX_TABLE_SENSOR].line_num;
- config->tx_num = tx_num;
- config->btn_num =
- field_array[PER_ELEMENT_MIN_MAX_TABLE_BUTTON].data_num >> 1;
- config->cm_min_max_table_btn_size =
- field_array[PER_ELEMENT_MIN_MAX_TABLE_BUTTON].data_num;
- config->cm_min_max_table_sensor_size =
- field_array[PER_ELEMENT_MIN_MAX_TABLE_SENSOR].data_num;
- config->cp_min_max_table_rx_size =
- field_array[PER_ELEMENT_MIN_MAX_RX].data_num;
- config->cp_min_max_table_tx_size =
- field_array[PER_ELEMENT_MIN_MAX_TX].data_num;
- config->cm_max_table_gradient_cols_percent_size =
- field_array[CM_GRADIENT_CHECK_COL].data_num;
- config->cm_max_table_gradient_rows_percent_size =
- field_array[CM_GRADIENT_CHECK_ROW].data_num;
- config->cp_min_max_table_btn_size =
- field_array[CP_PER_ELEMENT_MIN_MAX_BUTTON].data_num;
- /* *** Detailed Debug Information *** */
- pt_debug(dev, DL_DEBUG, "%d\n",
- config->cm_excluding_col_edge);
- pt_debug(dev, DL_DEBUG, "%d\n",
- config->cm_excluding_row_edge);
- for (index = 0;
- index < config->cm_max_table_gradient_cols_percent_size;
- index++)
- pt_debug(dev, DL_DEBUG, "%d\n",
- config->cm_max_table_gradient_cols_percent[index]);
- for (index = 0;
- index < config->cm_max_table_gradient_rows_percent_size;
- index++)
- pt_debug(dev, DL_DEBUG, "%d\n",
- config->cm_max_table_gradient_rows_percent[index]);
- pt_debug(dev, DL_DEBUG, "%d\n",
- config->cm_range_limit_row);
- pt_debug(dev, DL_DEBUG, "%d\n",
- config->cm_range_limit_col);
- pt_debug(dev, DL_DEBUG, "%d\n",
- config->cm_min_limit_cal);
- pt_debug(dev, DL_DEBUG, "%d\n",
- config->cm_max_limit_cal);
- pt_debug(dev, DL_DEBUG, "%d\n",
- config->cm_max_delta_sensor_percent);
- pt_debug(dev, DL_DEBUG, "%d\n",
- config->cm_max_delta_button_percent);
- for (index = 0;
- index < config->cm_min_max_table_btn_size; index++)
- pt_debug(dev, DL_DEBUG, "%d\n",
- config->cm_min_max_table_btn[index]);
- for (index = 0;
- index < config->cm_min_max_table_sensor_size; index++)
- pt_debug(dev, DL_DEBUG, "%d\n",
- config->cm_min_max_table_sensor[index]);
- pt_debug(dev, DL_DEBUG, "%d\n",
- config->cp_max_delta_sensor_rx_percent);
- pt_debug(dev, DL_DEBUG, "%d\n",
- config->cp_max_delta_sensor_tx_percent);
- pt_debug(dev, DL_DEBUG, "%d\n",
- config->cp_max_delta_button_percent);
- pt_debug(dev, DL_DEBUG, "%d\n",
- config->min_button);
- pt_debug(dev, DL_DEBUG, "%d\n",
- config->max_button);
- for (index = 0;
- index < config->cp_min_max_table_btn_size; index++)
- pt_debug(dev, DL_DEBUG, "%d\n",
- config->cp_min_max_table_btn[index]);
- for (index = 0;
- index < config->cp_min_max_table_rx_size; index++)
- pt_debug(dev, DL_DEBUG, "%d\n",
- config->cp_min_max_table_rx[index]);
- for (index = 0;
- index < config->cp_min_max_table_tx_size; index++)
- pt_debug(dev, DL_DEBUG, "%d\n",
- config->cp_min_max_table_tx[index]);
- /* *** End of Detailed Debug Information *** */
- /* Invalid mutual data length */
- if ((field_array[PER_ELEMENT_MIN_MAX_TABLE_SENSOR].data_num >>
- 1) % field_array[PER_ELEMENT_MIN_MAX_TABLE_SENSOR].line_num) {
- config->is_valid_or_not = 0;
- pt_debug(dev, DL_ERROR, "Invalid mutual data length\n");
- }
- } else {
- if (!config->cm_enabled)
- pt_debug(dev, DL_ERROR,
- "%s: Miss CM thresholds or CM data format is wrong!\n",
- __func__);
- if (!config->cp_enabled)
- pt_debug(dev, DL_ERROR,
- "%s: Miss CP thresholds or CP data format is wrong!\n",
- __func__);
- config->rx_num = 0;
- config->tx_num = 0;
- config->btn_num = 0;
- config->is_valid_or_not = 0;
- }
- pt_debug(dev, DL_DEBUG,
- "%s:\n"
- "Input file is %s!\n"
- "CM test: %s\n"
- "CP test: %s\n"
- "rx_num is %d\n"
- "tx_num is %d\n"
- "btn_num is %d\n",
- __func__,
- config->is_valid_or_not == 1 ? "VALID" : "!!! INVALID !!!",
- config->cm_enabled == 1 ? "Found" : "Not found",
- config->cp_enabled == 1 ? "Found" : "Not found",
- config->rx_num,
- config->tx_num,
- config->btn_num);
- }
- /*******************************************************************************
- * FUNCTION: cmcp_test_case_field_init
- *
- * SUMMARY: Initialize the structure test_field_array.
- *
- * PARAMETERS:
- * *test_field_array - pointer to test_case_field structure
- * *configuration - pointer to configuration structure
- ******************************************************************************/
- void cmcp_test_case_field_init(struct test_case_field *test_field_array,
- struct configuration *configs)
- {
- struct test_case_field test_case_field_array[MAX_CASE_NUM] = {
- {"CM TEST INPUTS", 14, TEST_CASE_TYPE_NO,
- NULL, 0, 0, 0},
- {"CM_EXCLUDING_COL_EDGE", 21, TEST_CASE_TYPE_ONE,
- &configs->cm_excluding_col_edge, 0, 0, 0},
- {"CM_EXCLUDING_ROW_EDGE", 21, TEST_CASE_TYPE_ONE,
- &configs->cm_excluding_row_edge, 0, 0, 0},
- {"CM_GRADIENT_CHECK_COL", 21, TEST_CASE_TYPE_MUL,
- &configs->cm_max_table_gradient_cols_percent[0],
- 0, 0, 0},
- {"CM_GRADIENT_CHECK_ROW", 21, TEST_CASE_TYPE_MUL,
- &configs->cm_max_table_gradient_rows_percent[0],
- 0, 0, 0},
- {"CM_RANGE_LIMIT_ROW", 18, TEST_CASE_TYPE_ONE,
- &configs->cm_range_limit_row, 0, 0, 0},
- {"CM_RANGE_LIMIT_COL", 18, TEST_CASE_TYPE_ONE,
- &configs->cm_range_limit_col, 0, 0, 0},
- {"CM_MIN_LIMIT_CAL", 16, TEST_CASE_TYPE_ONE,
- &configs->cm_min_limit_cal, 0, 0, 0},
- {"CM_MAX_LIMIT_CAL", 16, TEST_CASE_TYPE_ONE,
- &configs->cm_max_limit_cal, 0, 0, 0},
- {"CM_MAX_DELTA_SENSOR_PERCENT", 27, TEST_CASE_TYPE_ONE,
- &configs->cm_max_delta_sensor_percent, 0, 0, 0},
- {"CM_MAX_DELTA_BUTTON_PERCENT", 27, TEST_CASE_TYPE_ONE,
- &configs->cm_max_delta_button_percent, 0, 0, 0},
- {"PER_ELEMENT_MIN_MAX_TABLE_BUTTON", 32, TEST_CASE_TYPE_MUL,
- &configs->cm_min_max_table_btn[0], 0, 0, 0},
- {"PER_ELEMENT_MIN_MAX_TABLE_SENSOR", 32,
- TEST_CASE_TYPE_MUL_LINES,
- &configs->cm_min_max_table_sensor[0], 0, 0, 0},
- {"CP TEST INPUTS", 14, TEST_CASE_TYPE_NO,
- NULL, 0, 0, 0},
- {"CP_PER_ELEMENT_MIN_MAX_BUTTON", 29, TEST_CASE_TYPE_MUL,
- &configs->cp_min_max_table_btn[0], 0, 0, 0},
- {"CP_MAX_DELTA_SENSOR_RX_PERCENT", 30, TEST_CASE_TYPE_ONE,
- &configs->cp_max_delta_sensor_rx_percent,
- 0, 0, 0},
- {"CP_MAX_DELTA_SENSOR_TX_PERCENT", 30, TEST_CASE_TYPE_ONE,
- &configs->cp_max_delta_sensor_tx_percent,
- 0, 0, 0},
- {"CP_MAX_DELTA_BUTTON_PERCENT", 27, TEST_CASE_TYPE_ONE,
- &configs->cp_max_delta_button_percent, 0, 0, 0},
- {"MIN_BUTTON", 10, TEST_CASE_TYPE_ONE,
- &configs->min_button, 0, 0, 0},
- {"MAX_BUTTON", 10, TEST_CASE_TYPE_ONE,
- &configs->max_button, 0, 0, 0},
- {"PER_ELEMENT_MIN_MAX_RX", 22, TEST_CASE_TYPE_MUL,
- &configs->cp_min_max_table_rx[0], 0, 0, 0},
- {"PER_ELEMENT_MIN_MAX_TX", 22, TEST_CASE_TYPE_MUL,
- &configs->cp_min_max_table_tx[0], 0, 0, 0},
- };
- memcpy(test_field_array, test_case_field_array,
- sizeof(struct test_case_field) * MAX_CASE_NUM);
- }
- /*******************************************************************************
- * FUNCTION: pt_parse_cmcp_threshold_file_common
- *
- * SUMMARY: Parses cmcp threshold file and stores to the data structure.
- *
- * PARAMETERS:
- * *dev - pointer to devices structure
- * *buf - pointer to input buffer
- * file_size - file size
- ******************************************************************************/
- static ssize_t pt_parse_cmcp_threshold_file_common(
- struct device *dev, const char *buf, u32 file_size)
- {
- struct pt_device_access_data *dad
- = pt_get_device_access_data(dev);
- ssize_t rc = 0;
- u32 case_count = 0;
- pt_debug(dev, DL_INFO,
- "%s: Start parsing cmcp threshold file. File size is %d\n",
- __func__, file_size);
- cmcp_test_case_field_init(dad->test_field_array, dad->configs);
- /* Get all the cases from .csv file */
- case_count = cmcp_get_case_info_from_threshold_file(dev,
- buf, dad->test_search_array, file_size);
- pt_debug(dev, DL_INFO,
- "%s: Number of cases found in CSV file: %d\n",
- __func__, case_count);
- /* Search cases */
- cmcp_get_configuration_info(dev,
- buf,
- dad->test_search_array, case_count, dad->test_field_array,
- dad->configs, file_size);
- /* Get basic information */
- cmcp_get_basic_info(dev, dad->test_field_array, dad->configs);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_cmcp_threshold_loading_store
- *
- * SUMMARY: The store method for the cmcp_threshold_loading sysfs node. The
- * passed in value controls if threshold loading is performed.
- *
- * 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_cmcp_threshold_loading_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t size)
- {
- struct pt_device_access_data *dad = pt_get_device_access_data(dev);
- ssize_t length;
- u32 input_data[3];
- int rc = 0;
- length = cmd->parse_sysfs_input(dev, buf, size, input_data,
- ARRAY_SIZE(input_data));
- if (length != 1) {
- pt_debug(dev, DL_WARN, "%s: Invalid number of arguments\n",
- __func__);
- rc = -EINVAL;
- goto exit;
- }
- mutex_lock(&dad->cmcp_threshold_lock);
- if (input_data[0] == 1)
- dad->cmcp_threshold_loading = true;
- else if (input_data[0] == -1)
- dad->cmcp_threshold_loading = false;
- else if (input_data[0] == 0 && dad->cmcp_threshold_loading) {
- dad->cmcp_threshold_loading = false;
- if (dad->cmcp_threshold_size == 0) {
- pt_debug(dev, DL_ERROR, "%s: No cmcp threshold data\n",
- __func__);
- goto exit_free;
- }
- /* Clear test executed flag */
- dad->test_executed = 0;
- pt_parse_cmcp_threshold_file_common(dev,
- &dad->cmcp_threshold_data[0], dad->cmcp_threshold_size);
- /* Mark valid */
- dad->builtin_cmcp_threshold_status = 0;
- /* Restore test item to default value when new file input */
- dad->cmcp_test_items = 0;
- } else {
- pt_debug(dev, DL_WARN, "%s: Invalid value\n", __func__);
- rc = -EINVAL;
- mutex_unlock(&dad->cmcp_threshold_lock);
- goto exit;
- }
- exit_free:
- kfree(dad->cmcp_threshold_data);
- dad->cmcp_threshold_data = NULL;
- dad->cmcp_threshold_size = 0;
- mutex_unlock(&dad->cmcp_threshold_lock);
- exit:
- if (rc)
- return rc;
- return size;
- }
- static DEVICE_ATTR(cmcp_threshold_loading, 0200,
- NULL, pt_cmcp_threshold_loading_store);
- /*******************************************************************************
- * FUNCTION: pt_cmcp_threshold_data_write
- *
- * SUMMARY: The write method for the cmcp_threshold_data_sysfs node. The passed
- * in data (threshold file) is written to the threshold buffer.
- *
- * RETURN: Size of passed in buffer is success
- *
- * PARAMETERS:
- * *filp - pointer to file structure
- * *kobj - pointer to kobject structure
- * *bin_attr - pointer to bin_attribute structure
- * buf - pointer to cmd input buffer
- * offset - offset index to store input buffer
- * count - size of data in buffer
- ******************************************************************************/
- static ssize_t pt_cmcp_threshold_data_write(struct file *filp,
- struct kobject *kobj, struct bin_attribute *bin_attr,
- char *buf, loff_t offset, size_t count)
- {
- struct device *dev = container_of(kobj, struct device, kobj);
- struct pt_device_access_data *dad
- = pt_get_device_access_data(dev);
- u8 *p;
- pt_debug(dev, DL_INFO, "%s: offset:%lld count:%zu\n",
- __func__, offset, count);
- mutex_lock(&dad->cmcp_threshold_lock);
- if (!dad->cmcp_threshold_loading) {
- mutex_unlock(&dad->cmcp_threshold_lock);
- return -ENODEV;
- }
- p = krealloc(dad->cmcp_threshold_data, offset + count, GFP_KERNEL);
- if (!p) {
- kfree(dad->cmcp_threshold_data);
- dad->cmcp_threshold_data = NULL;
- mutex_unlock(&dad->cmcp_threshold_lock);
- return -ENOMEM;
- }
- dad->cmcp_threshold_data = p;
- memcpy(&dad->cmcp_threshold_data[offset], buf, count);
- dad->cmcp_threshold_size += count;
- mutex_unlock(&dad->cmcp_threshold_lock);
- return count;
- }
- static struct bin_attribute bin_attr_cmcp_threshold_data = {
- .attr = {
- .name = "cmcp_threshold_data",
- .mode = 0200,
- },
- .size = 0,
- .write = pt_cmcp_threshold_data_write,
- };
- /*******************************************************************************
- * FUNCTION: pt_suspend_scan_cmd_
- *
- * SUMMARY: Non-protected wrapper function for suspend scan command
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to devices structure
- ******************************************************************************/
- static int pt_suspend_scan_cmd_(struct device *dev)
- {
- int rc;
- rc = cmd->nonhid_cmd->suspend_scanning(dev, 0);
- if (rc)
- pt_debug(dev, DL_ERROR, "%s: Suspend scan failed rc = %d\n",
- __func__, rc);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_resume_scan_cmd_
- *
- * SUMMARY: Non-protected wrapper function for resume scan command
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to devices structure
- ******************************************************************************/
- static int pt_resume_scan_cmd_(struct device *dev)
- {
- int rc;
- rc = cmd->nonhid_cmd->resume_scanning(dev, 0);
- if (rc)
- pt_debug(dev, DL_ERROR, "%s: Resume scan failed rc = %d\n",
- __func__, rc);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_exec_scan_cmd_
- *
- * SUMMARY: Non-protected wrapper function for execute scan command
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to devices structure
- * scan_type - type of panel scan to perform (PIP2 only)
- ******************************************************************************/
- static int pt_exec_scan_cmd_(struct device *dev, u8 scan_type)
- {
- int rc;
- rc = cmd->nonhid_cmd->exec_panel_scan(dev, PT_CORE_CMD_UNPROTECTED,
- scan_type);
- if (rc)
- pt_debug(dev, DL_ERROR,
- "%s: Heatmap start scan failed rc = %d\n",
- __func__, rc);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_ret_scan_data_cmd_
- *
- * SUMMARY: Non-protected wrapper function for retrieve panel data command
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * 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
- * *return_buf - pointer to the read buffer
- ******************************************************************************/
- static int pt_ret_scan_data_cmd_(struct device *dev, u16 read_offset,
- u16 read_count, u8 data_id, u8 *response, u8 *config,
- u16 *actual_read_len, u8 *return_buf)
- {
- int rc;
- rc = cmd->nonhid_cmd->retrieve_panel_scan(dev, 0, read_offset,
- read_count, data_id, response, config, actual_read_len,
- return_buf);
- if (rc)
- pt_debug(dev, DL_ERROR,
- "%s: Retrieve scan data failed rc = %d\n",
- __func__, rc);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_get_data_structure_cmd_
- *
- * SUMMARY: Non-protected wrapper function for get data structure command
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * 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_get_data_structure_cmd_(struct device *dev, u16 read_offset,
- u16 read_length, u8 data_id, u8 *status, u8 *data_format,
- u16 *actual_read_len, u8 *data)
- {
- int rc;
- rc = cmd->nonhid_cmd->get_data_structure(dev, 0, read_offset,
- read_length, data_id, status, data_format,
- actual_read_len, data);
- if (rc)
- pt_debug(dev, DL_ERROR,
- "%s: Get data structure failed rc = %d\n",
- __func__, rc);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_run_selftest_cmd_
- *
- * SUMMARY: Non-protected wrapper function for run self test command
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * 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_run_selftest_cmd_(struct device *dev, u8 test_id,
- u8 write_idacs_to_flash, u8 *status, u8 *summary_result,
- u8 *results_available)
- {
- int rc;
- rc = cmd->nonhid_cmd->run_selftest(dev, 0, test_id,
- write_idacs_to_flash, status, summary_result,
- results_available);
- if (rc)
- pt_debug(dev, DL_ERROR, "%s: Run self test failed rc = %d\n",
- __func__, rc);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_get_selftest_result_cmd_
- *
- * SUMMARY: Non-protected wrapper function for get self test result command
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * 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_get_selftest_result_cmd_(struct device *dev,
- u16 read_offset, u16 read_length, u8 test_id, u8 *status,
- u16 *actual_read_len, u8 *data)
- {
- int rc;
- rc = cmd->nonhid_cmd->get_selftest_result(dev, 0, read_offset,
- read_length, test_id, status, actual_read_len, data);
- if (rc)
- pt_debug(dev, DL_ERROR,
- "%s: Get self test result failed rc = %d\n",
- __func__, rc);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: _pt_calibrate_ext_cmd
- *
- * SUMMARY: Wrapper function to function calibrate_ext() in pt_core_commands
- * structure
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *cal_data - pointer to extended calibration data structure
- * *status - pointer to where the command response status is stored
- ******************************************************************************/
- static int _pt_calibrate_ext_cmd(struct device *dev,
- struct pt_cal_ext_data *cal_data, u8 *status)
- {
- int rc;
- rc = cmd->nonhid_cmd->calibrate_ext(dev,
- PT_CORE_CMD_UNPROTECTED, cal_data, status);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: _pt_calibrate_idacs_cmd
- *
- * SUMMARY: Wrapper function to function calibrate_idacs() in pt_core_commands
- * structure
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * sensing_mode - sense mode to calibrate (0-5)
- * *status - pointer to where the command response status is stored
- ******************************************************************************/
- static int _pt_calibrate_idacs_cmd(struct device *dev,
- u8 sensing_mode, u8 *status)
- {
- int rc;
- rc = cmd->nonhid_cmd->calibrate_idacs(dev, 0, sensing_mode, status);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: _pt_initialize_baselines_cmd
- *
- * SUMMARY: Wrapper function to call initialize_baselines() in pt_core_commands
- * structure
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * sensing_mode - enumerated ID against which to initialize the baseline
- * *status - pointer to where the command response statas is stored
- ******************************************************************************/
- static int _pt_initialize_baselines_cmd(struct device *dev,
- u8 sensing_mode, u8 *status)
- {
- int rc;
- rc = cmd->nonhid_cmd->initialize_baselines(dev, 0, sensing_mode,
- status);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_perform_calibration
- *
- * SUMMARY: For Gen5/6, Send the PIP1 Calibrate IDACs command (0x28). For TT/TC,
- * send PIP1 Extended Calibrate command (0x30).
- *
- * NOTE: Panel scan must be suspended prior to calling this function.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- ******************************************************************************/
- static int pt_perform_calibration(struct device *dev)
- {
- struct pt_cal_ext_data cal_data = {0};
- u8 dut_gen = cmd->request_dut_generation(dev);
- u8 mode;
- u8 status;
- int rc;
- if (dut_gen == DUT_PIP1_ONLY) {
- for (mode = 0; mode < 3; mode++) {
- rc = _pt_calibrate_idacs_cmd(dev, mode, &status);
- if (rc < 0) {
- pt_debug(dev, DL_ERROR,
- "%s: calibrate idac error, mode= %d, rc = %d\n",
- __func__, mode, rc);
- break;
- }
- }
- } else {
- memset(&cal_data, 0, sizeof(struct pt_cal_ext_data));
- rc = _pt_calibrate_ext_cmd(dev, &cal_data, &status);
- if (rc < 0)
- pt_debug(dev, DL_ERROR,
- "%s: extended calibrate error, rc = %d\n",
- __func__, rc);
- }
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: prepare_print_buffer
- *
- * SUMMARY: Format input buffer to out buffer with Hex base,and format "status"
- * to decimal base.
- *
- * RETURN:
- * size of formated data in output buffer
- *
- * PARAMETERS:
- * status - Indicate test result:0(STATUS_SUCCESS),-1(STATUS_FAIL)
- * *in_buf - input buffer to be formated
- * length - length of input buffer
- * *out_buf - output buffer to store formated data
- * out_buf_size - length of output buffer
- * out_format - format of output data (5 supported formats):
- * PT_PR_FORMAT_DEFAULT : format all data as a column
- * PT_PR_FORMAT_U8_SPACE : sort status bytes and self test results,
- * and format the results as a row, each element include 1 byte
- * PT_PR_FORMAT_U16_SPACE : sort status bytes and self test results,
- * and format the results as a row, each element include 2 byte
- * PT_PR_FORMAT_U8_NO_SPACE : sort status bytes and self test results,
- * and format the results as a row, no space between the elements
- * PT_PR_FORMAT_U32_SPACE : sort status bytes and self test results,
- * and format the results as a row, each element include 4 byte
- ******************************************************************************/
- static int prepare_print_buffer(int status, u8 *in_buf, int length,
- u8 *out_buf, size_t out_buf_size, u8 out_format)
- {
- int index = 0;
- int data_length;
- int i;
- index += scnprintf(out_buf, out_buf_size, "Status: %d\n", status);
- if (out_format == PT_PR_FORMAT_DEFAULT) {
- for (i = 0; i < length; i++)
- index += scnprintf(&out_buf[index],
- out_buf_size - index,
- "%02X\n", in_buf[i]);
- } else {
- index += scnprintf(&out_buf[index],
- out_buf_size - index,
- "Response Status[1-%d]: ", MIN(length, 3));
- for (i = 0; i < MIN(length, 3); i++)
- index += scnprintf(&out_buf[index],
- out_buf_size - index,
- "%02X ", in_buf[i]);
- index += scnprintf(&out_buf[index], out_buf_size - index, "\n");
- if (length <= 6) {
- goto exit;
- } else {
- data_length = get_unaligned_le16(&in_buf[4]);
- index += scnprintf(&out_buf[index],
- out_buf_size - index, "RAW_DATA: ");
- }
- if (out_format == PT_PR_FORMAT_U8_SPACE) {
- for (i = 6; i < length; i++)
- index += scnprintf(&out_buf[index],
- out_buf_size - index,
- "%02X ", in_buf[i]);
- index += scnprintf(&out_buf[index],
- out_buf_size - index,
- ":(%d bytes)\n", data_length);
- } else if (out_format == PT_PR_FORMAT_U16_SPACE) {
- for (i = 6; (i + 1) < length; i += 2)
- index += scnprintf(&out_buf[index],
- out_buf_size - index, "%04X ",
- get_unaligned_le16(&in_buf[i]));
- index += scnprintf(&out_buf[index],
- out_buf_size - index,
- ":(%d words)\n", (length-6)/2);
- } else if (out_format == PT_PR_FORMAT_U8_NO_SPACE) {
- for (i = 6; i < length; i++)
- index += scnprintf(&out_buf[index],
- out_buf_size - index,
- "%02X", in_buf[i]);
- index += scnprintf(&out_buf[index],
- out_buf_size - index,
- ":(%d bytes)\n", data_length);
- } else if (out_format == PT_PR_FORMAT_U32_SPACE) {
- for (i = 6; (i + 1) < length; i += 4)
- index += scnprintf(&out_buf[index],
- out_buf_size - index, "%08X ",
- get_unaligned_le32(&in_buf[i]));
- index += scnprintf(&out_buf[index],
- out_buf_size - index,
- ":(%d 32bit values)\n", (length-6)/4);
- }
- }
- exit:
- return index;
- }
- /*******************************************************************************
- * FUNCTION: pt_run_and_get_selftest_result
- *
- * SUMMARY: Run the selftest and store the test result in the
- * pt_device_access_data struct.
- *
- * RETURN:
- * >0 : Size of debugfs data to print
- * <0 : failure
- * 0 : success
- *
- * NOTE: "Status: x" - x will contain the first error code if any
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * protect - flag to call protected or non-protected
- * *buf - pointer to print buf of return data
- * buf_len - length of print buf of return data
- * test_id - selftest id
- * read_length - max length to stor return data
- * get_result_on_pass - indicate whether to get result when finish test
- * print_results - print results to log
- * (true:get result;false:don't get result )
- * print_format - format of print results
- ******************************************************************************/
- static ssize_t pt_run_and_get_selftest_result(struct device *dev,
- int protect, char *buf, size_t buf_len, u8 test_id,
- u16 read_length, bool get_result_on_pass, bool print_results,
- u8 print_format)
- {
- struct pt_device_access_data *dad = pt_get_device_access_data(dev);
- int status = STATUS_SUCCESS;
- u8 cmd_status = STATUS_SUCCESS;
- u8 summary_result = 0;
- u8 sys_mode = FW_SYS_MODE_UNDEFINED;
- u16 act_length = 0;
- int length = 0;
- int size = 0;
- int rc;
- mutex_lock(&dad->sysfs_lock);
- pm_runtime_get_sync(dev);
- if (protect == PT_CORE_CMD_PROTECTED) {
- rc = cmd->request_exclusive(dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc) {
- pt_debug(dev, DL_ERROR,
- "%s: Error on request exclusive rc = %d\n",
- __func__, rc);
- status = -EPERM;
- goto put_pm_runtime;
- }
- }
- /* Get the current scan state so we restore to the same at the end */
- rc = cmd->request_get_fw_mode(dev, PT_CORE_CMD_UNPROTECTED, &sys_mode,
- NULL);
- if (rc) {
- status = rc;
- goto release_exclusive;
- }
- if (sys_mode != FW_SYS_MODE_TEST) {
- rc = pt_suspend_scan_cmd_(dev);
- if (rc) {
- pt_debug(dev, DL_ERROR,
- "%s: Error on suspend scan rc = %d\n",
- __func__, rc);
- status = -EPERM;
- goto release_exclusive;
- }
- }
- /* Sleep for 20ms to allow the last scan to be available in FW */
- msleep(20);
- rc = pt_run_selftest_cmd_(dev, test_id, 0,
- &cmd_status, &summary_result, NULL);
- if (rc) {
- /* Error sending self test */
- pt_debug(dev, DL_ERROR,
- "%s: Error on run self test for test_id:%d rc = %d\n",
- __func__, test_id, rc);
- status = rc;
- goto resume_scan;
- }
- if (cmd_status) {
- /* Self test response status failure */
- pt_debug(dev, DL_WARN,
- "%s: Test ID: 0x%02X resulted in status: 0x%02X\n",
- __func__, test_id, cmd_status);
- status = cmd_status;
- }
- dad->si = cmd->request_sysinfo(dad->dev);
- if (!dad->si) {
- pt_debug(dad->dev, DL_ERROR,
- "%s: Fail get sysinfo pointer from core\n", __func__);
- if (status == STATUS_SUCCESS)
- status = -EINVAL;
- goto resume_scan;
- }
- if (IS_PIP_VER_GE(dad->si, 1, 11)) {
- /* PIP1.11+ does not report the summary_result in byte 6 */
- summary_result = cmd_status;
- }
- /* Form response buffer */
- dad->ic_buf[0] = cmd_status;
- dad->ic_buf[1] = summary_result;
- pt_debug(dev, DL_INFO, "%s: Run Self Test cmd status = %d\n",
- __func__, cmd_status);
- pt_debug(dev, DL_INFO, "%s: Run Self Test result summary = %d\n",
- __func__, summary_result);
- length = 2;
- /*
- * Get data if requested and the cmd status indicates that the test
- * completed with either a pass or a fail. All other status codes
- * indicate the test itself was not run so there is no data to retrieve
- */
- if ((cmd_status == PT_ST_RESULT_PASS ||
- cmd_status == PT_ST_RESULT_FAIL) && get_result_on_pass) {
- rc = pt_get_selftest_result_cmd_(dev, 0, read_length,
- test_id, &cmd_status, &act_length, &dad->ic_buf[6]);
- if (rc) {
- pt_debug(dev, DL_ERROR,
- "%s: Error on get self test result rc = %d\n",
- __func__, rc);
- if (status == STATUS_SUCCESS)
- status = rc;
- goto resume_scan;
- }
- pt_debug(dev, DL_INFO, "%s: Get Self Test result status = %d\n",
- __func__, cmd_status);
- /* Only store new status if no error on running self test */
- if (status == STATUS_SUCCESS)
- status = cmd_status;
- dad->ic_buf[2] = cmd_status;
- dad->ic_buf[3] = test_id;
- dad->ic_buf[4] = LOW_BYTE(act_length);
- dad->ic_buf[5] = HI_BYTE(act_length);
- length = 6 + act_length;
- }
- resume_scan:
- /* Only resume scanning if we suspended it */
- if (sys_mode == FW_SYS_MODE_SCANNING)
- pt_resume_scan_cmd_(dev);
- release_exclusive:
- if (protect == PT_CORE_CMD_PROTECTED)
- cmd->release_exclusive(dev);
- put_pm_runtime:
- pm_runtime_put(dev);
- /* Communication error */
- if (status < 0)
- length = 0;
- if (print_results) {
- size = prepare_print_buffer(status, dad->ic_buf, length,
- buf, buf_len, print_format);
- rc = size;
- }
- mutex_unlock(&dad->sysfs_lock);
- return rc;
- }
- struct pt_device_access_debugfs_data {
- struct pt_device_access_data *dad;
- ssize_t pr_buf_len;
- u8 pr_buf[10 * PT_MAX_PRBUF_SIZE];
- };
- /*******************************************************************************
- * FUNCTION: pt_device_access_debugfs_open
- *
- * SUMMARY: Open the device_access debugfs node to initialize.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *inode - pointer to inode structure
- * *filp - pointer to file structure
- ******************************************************************************/
- static int pt_device_access_debugfs_open(struct inode *inode,
- struct file *filp)
- {
- struct pt_device_access_data *dad = inode->i_private;
- struct pt_device_access_debugfs_data *data;
- data = kzalloc(sizeof(*data), GFP_KERNEL);
- if (!data)
- return -ENOMEM;
- data->dad = dad;
- filp->private_data = data;
- return nonseekable_open(inode, filp);
- }
- /*******************************************************************************
- * FUNCTION: pt_device_access_debugfs_release
- *
- * SUMMARY: Close the device_access debugfs node to free pointer.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *inode - pointer to inode structure
- * *filp - pointer to file structure
- ******************************************************************************/
- static int pt_device_access_debugfs_release(struct inode *inode,
- struct file *filp)
- {
- kfree(filp->private_data);
- return 0;
- }
- #define PT_DEBUGFS_FOPS(_name, _read, _write) \
- static const struct file_operations _name##_debugfs_fops = { \
- .open = pt_device_access_debugfs_open, \
- .release = pt_device_access_debugfs_release, \
- .read = _read, \
- .write = _write, \
- }
- /*******************************************************************************
- * FUNCTION: panel_scan_debugfs_read
- *
- * SUMMARY: This function retrieves a full panel scan by sending the following
- * PIP commands:
- * 1) Suspend Scanning
- * 2) Execute Panel Scan
- * 3) Retrieve Panel Scan (n times to retrieve full scan)
- * 4) Resume Scanning
- *
- * 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 panel_scan_debugfs_read(struct file *filp, char __user *buf,
- size_t count, loff_t *ppos)
- {
- struct pt_device_access_debugfs_data *data = filp->private_data;
- struct pt_device_access_data *dad = data->dad;
- struct device *dev = dad->dev;
- struct pt_core_data *cd = dev_get_drvdata(dev);
- int status = STATUS_FAIL;
- u8 config;
- u16 num_elem_read;
- int length = 0;
- u8 element_size = 0;
- u8 *buf_out;
- u8 *buf_offset;
- u8 sys_mode = FW_SYS_MODE_UNDEFINED;
- int elem_offset = 0;
- int rc;
- int print_idx = 0;
- int i;
- mutex_lock(&dad->debugfs_lock);
- buf_out = dad->panel_scan_data_buf;
- if (!buf_out)
- goto release_mutex;
- pm_runtime_get_sync(dev);
- /*
- * This function will re-enter if the panel_scan_size is greater than
- * count (count is the kernel page size which is typically 4096), on
- * re-entry, *ppos will retain how far the last copy to user space
- * completed
- */
- if (*ppos) {
- if (*ppos >= dad->panel_scan_size)
- goto release_mutex;
- print_idx = simple_read_from_buffer(buf, count, ppos,
- buf_out, dad->panel_scan_size);
- pt_debug(dev, DL_DEBUG, "%s: Sent %d bytes to user space\n",
- __func__, print_idx);
- goto release_mutex;
- }
- rc = cmd->request_exclusive(dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc) {
- pt_debug(dev, DL_ERROR,
- "%s: Error on request exclusive rc = %d\n",
- __func__, rc);
- goto put_pm_runtime;
- }
- /* Get the current scan state so we restore to the same at the end */
- rc = cmd->request_get_fw_mode(dev, PT_CORE_CMD_UNPROTECTED, &sys_mode,
- NULL);
- if (rc) {
- status = rc;
- goto release_exclusive;
- }
- if (sys_mode != FW_SYS_MODE_TEST) {
- rc = pt_suspend_scan_cmd_(dev);
- if (rc) {
- pt_debug(dev, DL_ERROR,
- "%s: Error on suspend scan rc = %d\n",
- __func__, rc);
- goto release_exclusive;
- }
- }
- rc = pt_exec_scan_cmd_(dev, dad->panel_scan_type_id);
- if (rc) {
- pt_debug(dev, DL_ERROR,
- "%s: Error on execute panel scan rc = %d\n",
- __func__, rc);
- goto resume_scan;
- }
- /* Set length to max to read all */
- rc = pt_ret_scan_data_cmd_(dev, 0, 0xFFFF,
- dad->panel_scan_retrieve_id, dad->ic_buf, &config,
- &num_elem_read, NULL);
- if (rc) {
- pt_debug(dev, DL_ERROR,
- "%s: Error on retrieve panel scan rc = %d\n",
- __func__, rc);
- goto resume_scan;
- }
- length = get_unaligned_le16(&dad->ic_buf[0]);
- buf_offset = dad->ic_buf + length;
- element_size = config & 0x07;
- elem_offset = num_elem_read;
- while (num_elem_read > 0) {
- rc = pt_ret_scan_data_cmd_(dev, elem_offset, 0xFFFF,
- dad->panel_scan_retrieve_id, NULL, &config,
- &num_elem_read, buf_offset);
- if (rc)
- goto resume_scan;
- length += num_elem_read * element_size;
- buf_offset = dad->ic_buf + length;
- elem_offset += num_elem_read;
- if (num_elem_read < 0x7A)
- break;
- }
- /* Reconstruct cmd header */
- put_unaligned_le16(length, &dad->ic_buf[0]);
- put_unaligned_le16(elem_offset, &dad->ic_buf[7]);
- status = STATUS_SUCCESS;
- resume_scan:
- /* Only resume scanning if we suspended it */
- if (sys_mode == FW_SYS_MODE_SCANNING)
- pt_resume_scan_cmd_(dev);
- release_exclusive:
- cmd->release_exclusive(dev);
- put_pm_runtime:
- pm_runtime_put(dev);
- if (status == STATUS_FAIL)
- length = 0;
- if (cd->show_timestamp)
- print_idx += scnprintf(buf_out + print_idx, TTHE_TUNER_MAX_BUF,
- "[%u] SCAN_DATA:", pt_get_time_stamp());
- else
- print_idx += scnprintf(buf_out + print_idx, TTHE_TUNER_MAX_BUF,
- "SCAN_DATA:");
- for (i = 0; i < length; i++)
- print_idx += scnprintf(buf_out + print_idx,
- TTHE_TUNER_MAX_BUF - print_idx,
- "%02X ", dad->ic_buf[i]);
- print_idx += scnprintf(buf_out + print_idx,
- TTHE_TUNER_MAX_BUF - print_idx,
- ":(%d bytes)\n", length);
- /*
- * Save the size of the full scan which this function uses on re-entry
- * to send the data back to user space in 'count' size chuncks
- */
- dad->panel_scan_size = print_idx;
- print_idx = simple_read_from_buffer(buf, count, ppos, buf_out,
- print_idx);
- pt_debug(dev, DL_DEBUG, "%s: Sent %d bytes to user space\n",
- __func__, print_idx);
- release_mutex:
- mutex_unlock(&dad->debugfs_lock);
- return print_idx;
- }
- /*******************************************************************************
- * FUNCTION: panel_scan_debugfs_write
- *
- * SUMMARY: Store the type of panel scan the read method will perform.
- *
- * RETURN: Size of debugfs data write
- *
- * PARAMETERS:
- * *filp - file pointer to debugfs file
- * *buf - the user space buffer to write to
- * count - the maximum number of bytes to write
- * *ppos - the current position in the buffer
- ******************************************************************************/
- static ssize_t panel_scan_debugfs_write(struct file *filp,
- const char __user *buf, size_t count, loff_t *ppos)
- {
- struct pt_device_access_debugfs_data *data = filp->private_data;
- struct pt_device_access_data *dad = data->dad;
- ssize_t length;
- u32 input_data[3];
- int rc = 0;
- rc = simple_write_to_buffer(data->pr_buf, sizeof(data->pr_buf), ppos,
- buf, count);
- if (rc < 0)
- return rc;
- count = rc;
- mutex_lock(&dad->debugfs_lock);
- length = cmd->parse_sysfs_input(dad->dev, data->pr_buf, count,
- input_data, ARRAY_SIZE(input_data));
- switch (length) {
- case 1:
- dad->panel_scan_retrieve_id = input_data[0];
- dad->panel_scan_type_id = 0;
- break;
- case 2:
- dad->panel_scan_retrieve_id = input_data[0];
- dad->panel_scan_type_id = input_data[1];
- break;
- default:
- pt_debug(dad->dev, DL_ERROR,
- "%s: Malformed input\n", __func__);
- rc = -EINVAL;
- }
- mutex_unlock(&dad->debugfs_lock);
- if (rc)
- return rc;
- return count;
- }
- /*******************************************************************************
- * FUNCTION: panel_scan_debugfs_open
- *
- * SUMMARY: Open the panel_scan debugfs node to initialize.
- *
- * RETURN: 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *inode - file inode number
- * *filp - file pointer to debugfs file
- ******************************************************************************/
- static int panel_scan_debugfs_open(struct inode *inode,
- struct file *filp)
- {
- struct pt_device_access_data *dad = inode->i_private;
- struct pt_device_access_debugfs_data *data;
- data = kzalloc(sizeof(*data), GFP_KERNEL);
- if (!data)
- return -ENOMEM;
- data->dad = dad;
- data->pr_buf_len = 4 * PT_MAX_PRBUF_SIZE;
- filp->private_data = data;
- return nonseekable_open(inode, filp);
- }
- /*******************************************************************************
- * FUNCTION: panel_scan_debugfs_close
- *
- * SUMMARY: Close the panel_scan debugfs node to free pointer.
- *
- * RETURN: 0 = success
- *
- * PARAMETERS:
- * *inode - file inode number
- * *filp - file pointer to debugfs file
- ******************************************************************************/
- static int panel_scan_debugfs_close(struct inode *inode,
- struct file *filp)
- {
- kfree(filp->private_data);
- filp->private_data = NULL;
- return 0;
- }
- static const struct file_operations panel_scan_fops = {
- .open = panel_scan_debugfs_open,
- .release = panel_scan_debugfs_close,
- .read = panel_scan_debugfs_read,
- .write = panel_scan_debugfs_write,
- };
- /*******************************************************************************
- * FUNCTION: get_idac_debugfs_read
- *
- * SUMMARY: Retrieve data structure with idac data id by sending the following
- * PIP commands:
- * 1) Suspend Scanning
- * 2) Retrieve data structure
- * 3) Resume Scanning
- * The "Status: n" this node prints, 'n' will be:
- * - zero for a full pass
- * - negative for TTDL communication errors
- * - positive for any FW status errors
- *
- * 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 get_idac_debugfs_read(struct file *filp, char __user *buf,
- size_t count, loff_t *ppos)
- {
- struct pt_device_access_debugfs_data *data = filp->private_data;
- struct pt_device_access_data *dad = data->dad;
- struct device *dev = dad->dev;
- int status = STATUS_FAIL;
- u8 cmd_status = 0;
- u8 data_format = 0;
- u16 act_length = 0;
- int length = 0;
- int rc;
- if (*ppos)
- goto exit;
- mutex_lock(&dad->sysfs_lock);
- pm_runtime_get_sync(dev);
- rc = cmd->request_exclusive(dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc) {
- status = rc;
- pt_debug(dev, DL_ERROR,
- "%s: Error on request exclusive rc = %d\n",
- __func__, rc);
- goto put_pm_runtime;
- }
- rc = pt_suspend_scan_cmd_(dev);
- if (rc) {
- status = rc;
- pt_debug(dev, DL_ERROR, "%s: Error on suspend scan rc = %d\n",
- __func__, rc);
- goto release_exclusive;
- }
- rc = pt_get_data_structure_cmd_(dev, 0, PIP_CMD_MAX_LENGTH,
- dad->get_idac_data_id, &cmd_status, &data_format,
- &act_length, &dad->ic_buf[5]);
- if (rc) {
- status = rc;
- pt_debug(dev, DL_ERROR,
- "%s: Error on get data structure rc = %d\n",
- __func__, rc);
- goto resume_scan;
- }
- dad->ic_buf[0] = cmd_status;
- dad->ic_buf[1] = dad->get_idac_data_id;
- dad->ic_buf[2] = LOW_BYTE(act_length);
- dad->ic_buf[3] = HI_BYTE(act_length);
- dad->ic_buf[4] = data_format;
- length = 5 + act_length;
- status = cmd_status;
- resume_scan:
- pt_resume_scan_cmd_(dev);
- release_exclusive:
- cmd->release_exclusive(dev);
- put_pm_runtime:
- pm_runtime_put(dev);
- if (status == STATUS_FAIL)
- length = 0;
- data->pr_buf_len = prepare_print_buffer(status, dad->ic_buf, length,
- data->pr_buf, sizeof(data->pr_buf), PT_PR_FORMAT_DEFAULT);
- mutex_unlock(&dad->sysfs_lock);
- exit:
- return simple_read_from_buffer(buf, count, ppos, data->pr_buf,
- data->pr_buf_len);
- }
- /*******************************************************************************
- * FUNCTION: get_idac_debugfs_write
- *
- * SUMMARY: Store the data id of idac,the read method will perform.
- *
- * RETURN: Size of debugfs data write
- *
- * PARAMETERS:
- * *filp - file pointer to debugfs file
- * *buf - the user space buffer to write to
- * count - the maximum number of bytes to write
- * *ppos - the current position in the buffer
- ******************************************************************************/
- static ssize_t get_idac_debugfs_write(struct file *filp,
- const char __user *buf, size_t count, loff_t *ppos)
- {
- struct pt_device_access_debugfs_data *data = filp->private_data;
- struct pt_device_access_data *dad = data->dad;
- ssize_t length;
- u32 input_data[2];
- int rc = 0;
- rc = simple_write_to_buffer(data->pr_buf, sizeof(data->pr_buf), ppos,
- buf, count);
- if (rc < 0)
- return rc;
- count = rc;
- mutex_lock(&dad->sysfs_lock);
- length = cmd->parse_sysfs_input(dad->dev, data->pr_buf, count,
- input_data, ARRAY_SIZE(input_data));
- if (length != 1) {
- pt_debug(dad->dev, DL_ERROR,
- "%s: Malformed input\n", __func__);
- rc = -EINVAL;
- goto exit_unlock;
- }
- dad->get_idac_data_id = input_data[0];
- exit_unlock:
- mutex_unlock(&dad->sysfs_lock);
- if (rc)
- return rc;
- return count;
- }
- PT_DEBUGFS_FOPS(get_idac, get_idac_debugfs_read, get_idac_debugfs_write);
- /*******************************************************************************
- * FUNCTION: calibrate_ext_debugfs_read
- *
- * SUMMARY: Perform extended calibration command(0x30) which is flexible to
- * calibrate each individual feature by adding extra parameter for calibration
- * mode.
- *
- * NOTE:
- * - This calibrate command requires the DUT to support PIP version >= 1.10
- * - The "Status:" included in the printout will be one of the following:
- * <0 - Linux error code (PIP transmission error)
- * 0 - Full pass
- * >0 - PIP error status
- *
- * 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 calibrate_ext_debugfs_read(struct file *filp, char __user *buf,
- size_t count, loff_t *ppos)
- {
- struct pt_device_access_debugfs_data *data = filp->private_data;
- struct pt_device_access_data *dad = data->dad;
- struct device *dev = dad->dev;
- int status = STATUS_FAIL;
- int length = 0;
- int rc;
- if (*ppos)
- goto exit;
- dad->si = cmd->request_sysinfo(dad->dev);
- if (!dad->si) {
- pt_debug(dad->dev, DL_ERROR,
- "%s: Fail get sysinfo pointer from core\n",
- __func__);
- status = -EIO;
- data->pr_buf_len = prepare_print_buffer(status, dad->ic_buf, 0,
- data->pr_buf, sizeof(data->pr_buf),
- PT_PR_FORMAT_DEFAULT);
- goto exit;
- }
- if (!IS_PIP_VER_GE(dad->si, 1, 10)) {
- pt_debug(dad->dev, DL_ERROR,
- "%s: extended calibration command is not supported\n",
- __func__);
- status = -EPROTONOSUPPORT;
- data->pr_buf_len = prepare_print_buffer(status, dad->ic_buf, 0,
- data->pr_buf, sizeof(data->pr_buf),
- PT_PR_FORMAT_DEFAULT);
- goto exit;
- }
- if (dad->cal_ext_data.mode == PT_CAL_EXT_MODE_UNDEFINED) {
- pt_debug(dad->dev, DL_ERROR,
- "%s: No parameters provided for calibration command\n",
- __func__);
- status = -EINVAL;
- data->pr_buf_len = prepare_print_buffer(status, dad->ic_buf, 0,
- data->pr_buf, sizeof(data->pr_buf),
- PT_PR_FORMAT_DEFAULT);
- goto exit;
- }
- mutex_lock(&dad->sysfs_lock);
- pm_runtime_get_sync(dev);
- rc = cmd->request_exclusive(dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc) {
- status = rc;
- pt_debug(dev, DL_ERROR,
- "%s: Error on request exclusive rc = %d\n",
- __func__, rc);
- goto put_pm_runtime;
- }
- rc = pt_suspend_scan_cmd_(dev);
- if (rc) {
- status = rc;
- pt_debug(dev, DL_ERROR, "%s: Error on suspend scan rc = %d\n",
- __func__, rc);
- goto release_exclusive;
- }
- rc = _pt_calibrate_ext_cmd(dev, &dad->cal_ext_data, &dad->ic_buf[0]);
- if (rc) {
- status = rc;
- pt_debug(dev, DL_ERROR,
- "%s: Error on calibrate_ext rc = %d\n",
- __func__, rc);
- goto resume_scan;
- }
- /*
- * Include PIP errors as positive status codes and report the data.
- * No PIP error "0x00" in the response indicates full success
- */
- length = 1;
- status = dad->ic_buf[0];
- resume_scan:
- pt_resume_scan_cmd_(dev);
- release_exclusive:
- cmd->release_exclusive(dev);
- put_pm_runtime:
- pm_runtime_put(dev);
- /* Negative status codes are bus transmission errors and have no data */
- if (status < 0)
- length = 0;
- data->pr_buf_len = prepare_print_buffer(status, dad->ic_buf, length,
- data->pr_buf, sizeof(data->pr_buf), PT_PR_FORMAT_DEFAULT);
- mutex_unlock(&dad->sysfs_lock);
- exit:
- return simple_read_from_buffer(buf, count, ppos, data->pr_buf,
- data->pr_buf_len);
- }
- /*******************************************************************************
- * FUNCTION: calibrate_ext_debugfs_write
- *
- * SUMMARY: Stores the calibration mode and up to three parameters to perform
- * individual features.
- *
- * RETURN: Size of debugfs data write
- *
- * PARAMETERS:
- * *filp - file pointer to debugfs file
- * *buf - the user space buffer to write to
- * count - the maximum number of bytes to write
- * *ppos - the current position in the buffer
- ******************************************************************************/
- static ssize_t calibrate_ext_debugfs_write(struct file *filp,
- const char __user *buf, size_t count, loff_t *ppos)
- {
- struct pt_device_access_debugfs_data *data = filp->private_data;
- struct pt_device_access_data *dad = data->dad;
- ssize_t length;
- u32 input_data[5];
- int rc = 0;
- int i = 0;
- rc = simple_write_to_buffer(data->pr_buf, sizeof(data->pr_buf), ppos,
- buf, count);
- if (rc < 0)
- return rc;
- count = rc;
- mutex_lock(&dad->sysfs_lock);
- length = cmd->parse_sysfs_input(dad->dev, data->pr_buf, count,
- input_data, ARRAY_SIZE(input_data));
- if ((length <= 4) && (length > 0)) {
- for (i = length; i < 4; i++)
- input_data[i] = 0;
- dad->cal_ext_data.mode = (u8)input_data[0];
- dad->cal_ext_data.data0 = (u8)input_data[1];
- dad->cal_ext_data.data1 = (u8)input_data[2];
- dad->cal_ext_data.data2 = (u8)input_data[3];
- #ifdef TTDL_DIAGNOSTICS
- pt_debug(dad->dev, DL_INFO,
- "%s: calibration mode=%d, data[0..2]=0x%02X %02X %02X\n",
- __func__,
- dad->cal_ext_data.mode, dad->cal_ext_data.data0,
- dad->cal_ext_data.data1, dad->cal_ext_data.data2);
- #endif
- } else {
- pt_debug(dad->dev, DL_ERROR,
- "%s: Malformed input\n", __func__);
- rc = -EINVAL;
- goto exit_unlock;
- }
- exit_unlock:
- mutex_unlock(&dad->sysfs_lock);
- if (rc)
- return rc;
- return count;
- }
- PT_DEBUGFS_FOPS(calibrate_ext,
- calibrate_ext_debugfs_read, calibrate_ext_debugfs_write);
- /*******************************************************************************
- * FUNCTION: calibrate_debugfs_read
- *
- * SUMMARY: Perform calibration by sending the following PIP commands:
- * 1) Suspend Scanning
- * 2) Execute calibrate
- * 3) Initialize baseline conditionally
- * 4) Resume Scanning
- *
- * 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 calibrate_debugfs_read(struct file *filp, char __user *buf,
- size_t count, loff_t *ppos)
- {
- struct pt_device_access_debugfs_data *data = filp->private_data;
- struct pt_device_access_data *dad = data->dad;
- struct device *dev = dad->dev;
- int status = STATUS_FAIL;
- int length = 0;
- int rc;
- if (*ppos)
- goto exit;
- mutex_lock(&dad->sysfs_lock);
- pm_runtime_get_sync(dev);
- rc = cmd->request_exclusive(dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc) {
- status = rc;
- pt_debug(dev, DL_ERROR,
- "%s: Error on request exclusive rc = %d\n",
- __func__, rc);
- goto put_pm_runtime;
- }
- rc = pt_suspend_scan_cmd_(dev);
- if (rc) {
- status = rc;
- pt_debug(dev, DL_ERROR, "%s: Error on suspend scan rc = %d\n",
- __func__, rc);
- goto release_exclusive;
- }
- rc = _pt_calibrate_idacs_cmd(dev, dad->calibrate_sensing_mode,
- &dad->ic_buf[0]);
- if (rc) {
- status = rc;
- pt_debug(dev, DL_ERROR,
- "%s: Error on calibrate idacs rc = %d\n",
- __func__, rc);
- goto resume_scan;
- }
- length = 1;
- /* Check if baseline initialization is requested */
- if (dad->calibrate_initialize_baselines) {
- /* Perform baseline initialization for all modes */
- rc = _pt_initialize_baselines_cmd(dev, PT_IB_SM_MUTCAP |
- PT_IB_SM_SELFCAP | PT_IB_SM_BUTTON,
- &dad->ic_buf[length]);
- if (rc) {
- status = rc;
- pt_debug(dev, DL_ERROR,
- "%s: Error on initialize baselines rc = %d\n",
- __func__, rc);
- goto resume_scan;
- }
- length++;
- }
- status = STATUS_SUCCESS;
- resume_scan:
- pt_resume_scan_cmd_(dev);
- release_exclusive:
- cmd->release_exclusive(dev);
- put_pm_runtime:
- pm_runtime_put(dev);
- if (status == STATUS_FAIL)
- length = 0;
- data->pr_buf_len = prepare_print_buffer(status, dad->ic_buf, length,
- data->pr_buf, sizeof(data->pr_buf), PT_PR_FORMAT_DEFAULT);
- mutex_unlock(&dad->sysfs_lock);
- exit:
- return simple_read_from_buffer(buf, count, ppos, data->pr_buf,
- data->pr_buf_len);
- }
- /*******************************************************************************
- * FUNCTION: calibrate_debugfs_write
- *
- * SUMMARY: Stores the calibration sense mode and a flag to control if the
- * baseline will be initialized for the read method of this node.
- *
- * RETURN: Size of debugfs data write
- *
- * PARAMETERS:
- * *filp - file pointer to debugfs file
- * *buf - the user space buffer to write to
- * count - the maximum number of bytes to write
- * *ppos - the current position in the buffer
- ******************************************************************************/
- static ssize_t calibrate_debugfs_write(struct file *filp,
- const char __user *buf, size_t count, loff_t *ppos)
- {
- struct pt_device_access_debugfs_data *data = filp->private_data;
- struct pt_device_access_data *dad = data->dad;
- ssize_t length;
- u32 input_data[3];
- int rc = 0;
- rc = simple_write_to_buffer(data->pr_buf, sizeof(data->pr_buf), ppos,
- buf, count);
- if (rc < 0)
- return rc;
- count = rc;
- mutex_lock(&dad->sysfs_lock);
- length = cmd->parse_sysfs_input(dad->dev, data->pr_buf, count,
- input_data, ARRAY_SIZE(input_data));
- if (length != 2) {
- pt_debug(dad->dev, DL_ERROR,
- "%s: Malformed input\n", __func__);
- rc = -EINVAL;
- goto exit_unlock;
- }
- dad->calibrate_sensing_mode = input_data[0];
- dad->calibrate_initialize_baselines = input_data[1];
- exit_unlock:
- mutex_unlock(&dad->sysfs_lock);
- if (rc)
- return rc;
- return count;
- }
- PT_DEBUGFS_FOPS(calibrate, calibrate_debugfs_read, calibrate_debugfs_write);
- /*******************************************************************************
- * FUNCTION: baseline_debugfs_read
- *
- * SUMMARY: Perform baseline initialization by sending the following PIP
- * commands:
- * 1) Suspend Scanning
- * 2) Execute initialize baseline
- * 3) Resume Scanning
- *
- * 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 baseline_debugfs_read(struct file *filp, char __user *buf,
- size_t count, loff_t *ppos)
- {
- struct pt_device_access_debugfs_data *data = filp->private_data;
- struct pt_device_access_data *dad = data->dad;
- struct device *dev = dad->dev;
- int status = STATUS_FAIL;
- int length = 0;
- int rc;
- if (*ppos)
- goto exit;
- mutex_lock(&dad->sysfs_lock);
- pm_runtime_get_sync(dev);
- rc = cmd->request_exclusive(dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc) {
- status = rc;
- pt_debug(dev, DL_ERROR,
- "%s: Error on request exclusive rc = %d\n",
- __func__, rc);
- goto put_pm_runtime;
- }
- rc = pt_suspend_scan_cmd_(dev);
- if (rc) {
- status = rc;
- pt_debug(dev, DL_ERROR, "%s: Error on suspend scan rc = %d\n",
- __func__, rc);
- goto release_exclusive;
- }
- rc = _pt_initialize_baselines_cmd(dev, dad->baseline_sensing_mode,
- &dad->ic_buf[0]);
- if (rc) {
- status = rc;
- pt_debug(dev, DL_ERROR,
- "%s: Error on initialize baselines rc = %d\n",
- __func__, rc);
- goto resume_scan;
- }
- length = 1;
- status = STATUS_SUCCESS;
- resume_scan:
- pt_resume_scan_cmd_(dev);
- release_exclusive:
- cmd->release_exclusive(dev);
- put_pm_runtime:
- pm_runtime_put(dev);
- if (status == STATUS_FAIL)
- length = 0;
- data->pr_buf_len = prepare_print_buffer(status, dad->ic_buf, length,
- data->pr_buf, sizeof(data->pr_buf), PT_PR_FORMAT_DEFAULT);
- mutex_unlock(&dad->sysfs_lock);
- exit:
- return simple_read_from_buffer(buf, count, ppos, data->pr_buf,
- data->pr_buf_len);
- }
- /*******************************************************************************
- * FUNCTION: baseline_debugfs_write
- *
- * SUMMARY: Store the sense mode of base initialization, the read method will
- * perform.
- *
- * RETURN: Size of debugfs data write
- *
- * PARAMETERS:
- * *filp - file pointer to debugfs file
- * *buf - the user space buffer to write to
- * count - the maximum number of bytes to write
- * *ppos - the current position in the buffer
- ******************************************************************************/
- static ssize_t baseline_debugfs_write(struct file *filp,
- const char __user *buf, size_t count, loff_t *ppos)
- {
- struct pt_device_access_debugfs_data *data = filp->private_data;
- struct pt_device_access_data *dad = data->dad;
- ssize_t length;
- u32 input_data[2];
- int rc = 0;
- rc = simple_write_to_buffer(data->pr_buf, sizeof(data->pr_buf), ppos,
- buf, count);
- if (rc < 0)
- return rc;
- count = rc;
- mutex_lock(&dad->sysfs_lock);
- length = cmd->parse_sysfs_input(dad->dev, data->pr_buf, count,
- input_data, ARRAY_SIZE(input_data));
- if (length != 1) {
- pt_debug(dad->dev, DL_ERROR,
- "%s: Malformed input\n", __func__);
- rc = -EINVAL;
- goto exit_unlock;
- }
- dad->baseline_sensing_mode = input_data[0];
- exit_unlock:
- mutex_unlock(&dad->sysfs_lock);
- if (rc)
- return rc;
- return count;
- }
- PT_DEBUGFS_FOPS(baseline, baseline_debugfs_read, baseline_debugfs_write);
- /*******************************************************************************
- * FUNCTION: auto_shorts_debugfs_read
- *
- * SUMMARY: Performs the "auto shorts" test and prints the result to the output
- * 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 auto_shorts_debugfs_read(struct file *filp, char __user *buf,
- size_t count, loff_t *ppos)
- {
- struct pt_device_access_debugfs_data *data = filp->private_data;
- if (!*ppos)
- /* Set length to PIP_CMD_MAX_LENGTH to read all */
- data->pr_buf_len = pt_run_and_get_selftest_result(
- data->dad->dev, PT_CORE_CMD_PROTECTED,
- data->pr_buf, sizeof(data->pr_buf),
- PT_ST_ID_AUTOSHORTS, PIP_CMD_MAX_LENGTH,
- PT_ST_DONT_GET_RESULTS, PT_ST_PRINT_RESULTS,
- PT_PR_FORMAT_DEFAULT);
- return simple_read_from_buffer(buf, count, ppos, data->pr_buf,
- data->pr_buf_len);
- }
- PT_DEBUGFS_FOPS(auto_shorts, auto_shorts_debugfs_read, NULL);
- /*******************************************************************************
- * FUNCTION: opens_debugfs_read
- *
- * SUMMARY: Performs the "opens" test and prints the results to the output
- * 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 opens_debugfs_read(struct file *filp, char __user *buf,
- size_t count, loff_t *ppos)
- {
- struct pt_device_access_debugfs_data *data = filp->private_data;
- if (!*ppos)
- /* Set length to PIP_CMD_MAX_LENGTH to read all */
- data->pr_buf_len = pt_run_and_get_selftest_result(
- data->dad->dev, PT_CORE_CMD_PROTECTED,
- data->pr_buf, sizeof(data->pr_buf),
- PT_ST_ID_OPENS, PIP_CMD_MAX_LENGTH,
- PT_ST_DONT_GET_RESULTS, PT_ST_PRINT_RESULTS,
- PT_PR_FORMAT_DEFAULT);
- return simple_read_from_buffer(buf, count, ppos, data->pr_buf,
- data->pr_buf_len);
- }
- PT_DEBUGFS_FOPS(opens, opens_debugfs_read, NULL);
- /*******************************************************************************
- * FUNCTION: cm_panel_debugfs_read
- *
- * SUMMARY: Performs the "CM panel" test and prints the result to the output
- * 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 cm_panel_debugfs_read(struct file *filp, char __user *buf,
- size_t count, loff_t *ppos)
- {
- struct pt_device_access_debugfs_data *data = filp->private_data;
- if (!*ppos)
- /* Set length to PIP_CMD_MAX_LENGTH to read all */
- data->pr_buf_len = pt_run_and_get_selftest_result(
- data->dad->dev, PT_CORE_CMD_PROTECTED,
- data->pr_buf, sizeof(data->pr_buf),
- PT_ST_ID_CM_PANEL, PIP_CMD_MAX_LENGTH,
- PT_ST_GET_RESULTS, PT_ST_PRINT_RESULTS,
- PT_PR_FORMAT_DEFAULT);
- return simple_read_from_buffer(buf, count, ppos, data->pr_buf,
- data->pr_buf_len);
- }
- PT_DEBUGFS_FOPS(cm_panel, cm_panel_debugfs_read, NULL);
- /*******************************************************************************
- * FUNCTION: cp_panel_debugfs_read
- *
- * SUMMARY: Performs the "CP panel" test and prints the result to the output
- * 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 cp_panel_debugfs_read(struct file *filp, char __user *buf,
- size_t count, loff_t *ppos)
- {
- struct pt_device_access_debugfs_data *data = filp->private_data;
- if (!*ppos)
- /* Set length to PIP_CMD_MAX_LENGTH to read all */
- data->pr_buf_len = pt_run_and_get_selftest_result(
- data->dad->dev, PT_CORE_CMD_PROTECTED,
- data->pr_buf, sizeof(data->pr_buf),
- PT_ST_ID_CP_PANEL, PIP_CMD_MAX_LENGTH,
- PT_ST_GET_RESULTS, PT_ST_PRINT_RESULTS,
- PT_PR_FORMAT_DEFAULT);
- return simple_read_from_buffer(buf, count, ppos, data->pr_buf,
- data->pr_buf_len);
- }
- PT_DEBUGFS_FOPS(cp_panel, cp_panel_debugfs_read, NULL);
- /*******************************************************************************
- * FUNCTION: cm_button_debugfs_read
- *
- * SUMMARY: Performs the "CM buttons" test and prints the result to the output
- * 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 cm_button_debugfs_read(struct file *filp, char __user *buf,
- size_t count, loff_t *ppos)
- {
- struct pt_device_access_debugfs_data *data = filp->private_data;
- if (!*ppos)
- /* Set length to PIP_CMD_MAX_LENGTH to read all */
- data->pr_buf_len = pt_run_and_get_selftest_result(
- data->dad->dev, PT_CORE_CMD_PROTECTED,
- data->pr_buf, sizeof(data->pr_buf),
- PT_ST_ID_CM_BUTTON, PIP_CMD_MAX_LENGTH,
- PT_ST_GET_RESULTS, PT_ST_PRINT_RESULTS,
- PT_PR_FORMAT_DEFAULT);
- return simple_read_from_buffer(buf, count, ppos, data->pr_buf,
- data->pr_buf_len);
- }
- PT_DEBUGFS_FOPS(cm_button, cm_button_debugfs_read, NULL);
- /*******************************************************************************
- * FUNCTION: cp_button_debugfs_read
- *
- * SUMMARY: Performs the "CP buttons" test and prints the result to the output
- * 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 cp_button_debugfs_read(struct file *filp, char __user *buf,
- size_t count, loff_t *ppos)
- {
- struct pt_device_access_debugfs_data *data = filp->private_data;
- if (!*ppos)
- /* Set length to PIP_CMD_MAX_LENGTH to read all */
- data->pr_buf_len = pt_run_and_get_selftest_result(
- data->dad->dev, PT_CORE_CMD_PROTECTED,
- data->pr_buf, sizeof(data->pr_buf),
- PT_ST_ID_CP_BUTTON, PIP_CMD_MAX_LENGTH,
- PT_ST_GET_RESULTS, PT_ST_PRINT_RESULTS,
- PT_PR_FORMAT_DEFAULT);
- return simple_read_from_buffer(buf, count, ppos, data->pr_buf,
- data->pr_buf_len);
- }
- PT_DEBUGFS_FOPS(cp_button, cp_button_debugfs_read, NULL);
- /*******************************************************************************
- * FUNCTION: fw_self_test_debugfs_read
- *
- * SUMMARY: Performs the self test by firmware and prints the results to the
- * output 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 fw_self_test_debugfs_read(struct file *filp, char __user *buf,
- size_t count, loff_t *ppos)
- {
- u8 ret_status;
- u8 ret_self_test_id;
- u8 sys_mode = FW_SYS_MODE_UNDEFINED;
- u16 ret_act_load_len;
- int rc;
- struct pt_device_access_debugfs_data *data = filp->private_data;
- struct pt_device_access_data *dad = data->dad;
- if (!*ppos) {
- if (dad->fw_self_test_id == PT_ST_ID_INVALID ||
- dad->fw_self_test_format >= PT_PR_FORMAT_UNDEFINE) {
- data->pr_buf_len = scnprintf(data->pr_buf,
- sizeof(data->pr_buf), "Status: %d\n", -EINVAL);
- pt_debug(dad->dev, DL_ERROR,
- "%s: Malformed input\n", __func__);
- goto exit;
- }
- /* only send the load parameters cmd if param data exists */
- if (dad->fw_self_test_param_len > 0) {
- rc = cmd->request_get_fw_mode(dad->dev,
- PT_CORE_CMD_UNPROTECTED, &sys_mode, NULL);
- if (rc) {
- pt_debug(dad->dev, DL_ERROR,
- "%s: ERR on request mode rc=%d\n",
- __func__, rc);
- data->pr_buf_len = scnprintf(
- data->pr_buf,
- sizeof(data->pr_buf),
- "Status: %d\n", rc);
- goto exit;
- }
- if (sys_mode != FW_SYS_MODE_TEST) {
- rc = pt_suspend_scan_cmd_(dad->dev);
- if (rc) {
- pt_debug(dad->dev, DL_ERROR,
- "%s: ERR on sus scan rc=%d\n",
- __func__, rc);
- data->pr_buf_len = scnprintf(
- data->pr_buf,
- sizeof(data->pr_buf),
- "Status: %d\n", rc);
- goto exit;
- }
- }
- cmd->nonhid_cmd->load_self_test_param(dad->dev,
- PT_CORE_CMD_PROTECTED,
- dad->fw_self_test_id, 0,
- dad->fw_self_test_param_len,
- dad->fw_self_test_param, &ret_status,
- &ret_self_test_id, &ret_act_load_len);
- if (ret_status) {
- data->pr_buf_len = scnprintf(data->pr_buf,
- sizeof(data->pr_buf),
- "Status: %d\n", -EINVAL);
- pt_debug(dad->dev, DL_ERROR,
- "%s: Load Param Malformed input\n",
- __func__);
- goto resume_scan;
- }
- }
- /* Set length to PIP_CMD_MAX_LENGTH to read all */
- data->pr_buf_len = pt_run_and_get_selftest_result(
- dad->dev, PT_CORE_CMD_PROTECTED,
- data->pr_buf, sizeof(data->pr_buf),
- dad->fw_self_test_id, PIP_CMD_MAX_LENGTH,
- PT_ST_GET_RESULTS, PT_ST_PRINT_RESULTS,
- dad->fw_self_test_format);
- /* Clear the parameters so next test won't use them */
- if (dad->fw_self_test_param_len > 0) {
- cmd->nonhid_cmd->load_self_test_param(dad->dev,
- PT_CORE_CMD_PROTECTED,
- dad->fw_self_test_id, 0, 0, NULL,
- &ret_status, &ret_self_test_id,
- &ret_act_load_len);
- }
- dad->fw_self_test_id = PT_ST_ID_INVALID;
- dad->fw_self_test_format = PT_PR_FORMAT_UNDEFINE;
- dad->fw_self_test_param_len = 0;
- resume_scan:
- /* Only resume scanning if we suspended it */
- if (sys_mode == FW_SYS_MODE_SCANNING)
- pt_resume_scan_cmd_(dad->dev);
- }
- exit:
- return simple_read_from_buffer(buf, count, ppos, data->pr_buf,
- data->pr_buf_len);
- }
- /*******************************************************************************
- * FUNCTION: fw_self_test_debugfs_write
- *
- * SUMMARY: Store the self test ID and ouptut format, the read method will
- * perform.
- *
- * RETURN: Size of debugfs data write
- *
- * PARAMETERS:
- * *filp - file pointer to debugfs file
- * *buf - the user space buffer to write to
- * count - the maximum number of bytes to write
- * *ppos - the current position in the buffer
- ******************************************************************************/
- static ssize_t fw_self_test_debugfs_write(struct file *filp,
- const char __user *buf, size_t count, loff_t *ppos)
- {
- struct pt_device_access_debugfs_data *data = filp->private_data;
- struct pt_device_access_data *dad = data->dad;
- ssize_t length;
- u32 input_data[PT_FW_SELF_TEST_MAX_PARM + 1];
- int rc = 0;
- int i;
- rc = simple_write_to_buffer(data->pr_buf, sizeof(data->pr_buf), ppos,
- buf, count);
- if (rc < 0)
- return rc;
- count = rc;
- mutex_lock(&dad->sysfs_lock);
- length = cmd->parse_sysfs_input(dad->dev, data->pr_buf, count,
- input_data, PT_FW_SELF_TEST_MAX_PARM + 1);
- if (length == 1) {
- dad->fw_self_test_id = input_data[0];
- dad->fw_self_test_format = PT_PR_FORMAT_DEFAULT;
- dad->fw_self_test_param_len = 0;
- } else if (length == 2) {
- dad->fw_self_test_id = input_data[0];
- dad->fw_self_test_format = input_data[1];
- dad->fw_self_test_param_len = 0;
- } else if (length > 2 && (length <= PT_FW_SELF_TEST_MAX_PARM)) {
- dad->fw_self_test_id = input_data[0];
- dad->fw_self_test_format = input_data[1];
- dad->fw_self_test_param_len = length - 2;
- pt_debug(dad->dev, DL_INFO,
- "%s: test_id=%d, format=%d, param_len=%d",
- __func__, dad->fw_self_test_id,
- dad->fw_self_test_format, dad->fw_self_test_param_len);
- for (i = 0; i < dad->fw_self_test_param_len; i++)
- dad->fw_self_test_param[i] = input_data[i + 2];
- } else {
- pt_debug(dad->dev, DL_ERROR,
- "%s: Malformed input\n", __func__);
- rc = -EINVAL;
- goto exit_unlock;
- }
- exit_unlock:
- mutex_unlock(&dad->sysfs_lock);
- if (rc)
- return rc;
- return count;
- }
- PT_DEBUGFS_FOPS(fw_self_test,
- fw_self_test_debugfs_read, fw_self_test_debugfs_write);
- #ifdef TTHE_TUNER_SUPPORT
- /*******************************************************************************
- * FUNCTION: tthe_get_panel_data_debugfs_read
- *
- * SUMMARY: Performs a panel scan and prints the panel data into the output
- * 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_get_panel_data_debugfs_read(struct file *filp,
- char __user *buf, size_t count, loff_t *ppos)
- {
- struct pt_device_access_data *dad = filp->private_data;
- struct device *dev;
- struct pt_core_data *cd;
- u8 config;
- u16 actual_read_len;
- u16 length = 0;
- u8 element_size = 0;
- u8 *buf_offset;
- u8 *buf_out;
- int elem;
- int elem_offset = 0;
- int print_idx = 0;
- int rc;
- int rc1;
- int i;
- mutex_lock(&dad->debugfs_lock);
- dev = dad->dev;
- cd = dev_get_drvdata(dev);
- buf_out = dad->panel_scan_data_buf;
- if (!buf_out)
- goto release_mutex;
- pm_runtime_get_sync(dev);
- rc = cmd->request_exclusive(dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc)
- goto put_runtime;
- if (dad->heatmap.scan_start) {
- /*
- * To fix CDT206291: avoid multiple scans when
- * return data is larger than 4096 bytes in one cycle
- */
- dad->heatmap.scan_start = 0;
- /* Start scan */
- rc = pt_exec_scan_cmd_(dev, 0);
- if (rc)
- goto release_exclusive;
- }
- elem = dad->heatmap.num_element;
- #if defined(PT_ENABLE_MAX_ELEN)
- if (elem > PT_MAX_ELEN) {
- rc = pt_ret_scan_data_cmd_(dev, elem_offset,
- PT_MAX_ELEN, dad->heatmap.data_type, dad->ic_buf,
- &config, &actual_read_len, NULL);
- } else {
- rc = pt_ret_scan_data_cmd_(dev, elem_offset, elem,
- dad->heatmap.data_type, dad->ic_buf, &config,
- &actual_read_len, NULL);
- }
- #else
- rc = pt_ret_scan_data_cmd_(dev, elem_offset, elem,
- dad->heatmap.data_type, dad->ic_buf, &config,
- &actual_read_len, NULL);
- #endif
- if (rc)
- goto release_exclusive;
- length = get_unaligned_le16(&dad->ic_buf[0]);
- buf_offset = dad->ic_buf + length;
- element_size = config & PT_CMD_RET_PANEL_ELMNT_SZ_MASK;
- elem -= actual_read_len;
- elem_offset = actual_read_len;
- while (elem > 0) {
- #ifdef PT_ENABLE_MAX_ELEN
- if (elem > PT_MAX_ELEN) {
- rc = pt_ret_scan_data_cmd_(dev, elem_offset,
- PT_MAX_ELEN, dad->heatmap.data_type, NULL, &config,
- &actual_read_len, buf_offset);
- } else {
- rc = pt_ret_scan_data_cmd_(dev, elem_offset, elem,
- dad->heatmap.data_type, NULL, &config,
- &actual_read_len, buf_offset);
- }
- #else
- rc = pt_ret_scan_data_cmd_(dev, elem_offset, elem,
- dad->heatmap.data_type, NULL, &config,
- &actual_read_len, buf_offset);
- #endif
- if (rc)
- goto release_exclusive;
- if (!actual_read_len)
- break;
- length += actual_read_len * element_size;
- buf_offset = dad->ic_buf + length;
- elem -= actual_read_len;
- elem_offset += actual_read_len;
- }
- /* Reconstruct cmd header */
- put_unaligned_le16(length, &dad->ic_buf[0]);
- put_unaligned_le16(elem_offset, &dad->ic_buf[7]);
- release_exclusive:
- rc1 = cmd->release_exclusive(dev);
- put_runtime:
- pm_runtime_put(dev);
- if (rc)
- goto release_mutex;
- if (cd->show_timestamp)
- print_idx += scnprintf(buf_out, TTHE_TUNER_MAX_BUF,
- "[%u] PT_DATA:", pt_get_time_stamp());
- else
- print_idx += scnprintf(buf_out, TTHE_TUNER_MAX_BUF,
- "PT_DATA:");
- for (i = 0; i < length; i++)
- print_idx += scnprintf(buf_out + print_idx,
- TTHE_TUNER_MAX_BUF - print_idx,
- "%02X ", dad->ic_buf[i]);
- print_idx += scnprintf(buf_out + print_idx,
- TTHE_TUNER_MAX_BUF - print_idx,
- ":(%d bytes)\n", length);
- rc = simple_read_from_buffer(buf, count, ppos, buf_out, print_idx);
- print_idx = rc;
- release_mutex:
- mutex_unlock(&dad->debugfs_lock);
- return print_idx;
- }
- /*******************************************************************************
- * FUNCTION: tthe_get_panel_data_debugfs_write
- *
- * SUMMARY: Store the panel data type to retrieve and size of panel data, the
- * read method will perform.
- *
- * RETURN: Size of debugfs data write
- *
- * PARAMETERS:
- * *filp - file pointer to debugfs file
- * *buf - the user space buffer to write to
- * count - the maximum number of bytes to write
- * *ppos - the current position in the buffer
- ******************************************************************************/
- static ssize_t tthe_get_panel_data_debugfs_write(struct file *filp,
- const char __user *buf, size_t count, loff_t *ppos)
- {
- struct pt_device_access_data *dad = filp->private_data;
- struct device *dev = dad->dev;
- ssize_t length;
- int max_read;
- u32 input_data[8];
- u8 *buf_in = dad->panel_scan_data_buf;
- int ret;
- mutex_lock(&dad->debugfs_lock);
- ret = copy_from_user(buf_in + (*ppos), buf, count);
- if (ret)
- goto exit;
- buf_in[count] = 0;
- length = cmd->parse_sysfs_input(dev, buf_in, count, input_data,
- ARRAY_SIZE(input_data));
- if (length <= 0) {
- pt_debug(dev, DL_ERROR,
- "%s: %s Group Data store\n",
- __func__, "Malformed input for");
- goto exit;
- }
- /* update parameter value */
- dad->heatmap.num_element = input_data[3] + (input_data[4] << 8);
- dad->heatmap.data_type = input_data[5];
- if (input_data[6] > 0)
- dad->heatmap.scan_start = true;
- else
- dad->heatmap.scan_start = false;
- /* elem can not be bigger then buffer size */
- max_read = PT_CMD_RET_PANEL_HDR;
- max_read += dad->heatmap.num_element * PT_CMD_RET_PANEL_ELMNT_SZ_MAX;
- if (max_read >= PT_MAX_PRBUF_SIZE) {
- dad->heatmap.num_element =
- (PT_MAX_PRBUF_SIZE - PT_CMD_RET_PANEL_HDR)
- / PT_CMD_RET_PANEL_ELMNT_SZ_MAX;
- pt_debug(dev, DL_INFO, "%s: Will get %d element\n",
- __func__, dad->heatmap.num_element);
- }
- exit:
- mutex_unlock(&dad->debugfs_lock);
- pt_debug(dev, DL_INFO, "%s: return count=%zu\n",
- __func__, count);
- return count;
- }
- /*******************************************************************************
- * FUNCTION: tthe_get_panel_data_debugfs_open
- *
- * SUMMARY: Open the get_panel_data debugfs node to initialize.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *inode - pointer to inode structure
- * *filp - pointer to file structure
- ******************************************************************************/
- static int tthe_get_panel_data_debugfs_open(struct inode *inode,
- struct file *filp)
- {
- struct pt_device_access_data *dad = inode->i_private;
- mutex_lock(&dad->debugfs_lock);
- if (dad->tthe_get_panel_data_is_open) {
- mutex_unlock(&dad->debugfs_lock);
- return -EBUSY;
- }
- filp->private_data = inode->i_private;
- dad->tthe_get_panel_data_is_open = 1;
- mutex_unlock(&dad->debugfs_lock);
- return 0;
- }
- /*******************************************************************************
- * FUNCTION: tthe_get_panel_data_debugfs_close
- *
- * SUMMARY: Close the get_panel_data debugfs node to free pointer.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *inode - pointer to inode structure
- * *filp - pointer to file structure
- ******************************************************************************/
- static int tthe_get_panel_data_debugfs_close(struct inode *inode,
- struct file *filp)
- {
- struct pt_device_access_data *dad = filp->private_data;
- mutex_lock(&dad->debugfs_lock);
- filp->private_data = NULL;
- dad->tthe_get_panel_data_is_open = 0;
- mutex_unlock(&dad->debugfs_lock);
- return 0;
- }
- static const struct file_operations tthe_get_panel_data_fops = {
- .open = tthe_get_panel_data_debugfs_open,
- .release = tthe_get_panel_data_debugfs_close,
- .read = tthe_get_panel_data_debugfs_read,
- .write = tthe_get_panel_data_debugfs_write,
- };
- #endif
- /*******************************************************************************
- * FUNCTION: pt_setup_sysfs
- *
- * SUMMARY: Creates all device test dependent sysfs nodes owned by the
- * device access file.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- ******************************************************************************/
- static int pt_setup_sysfs(struct device *dev)
- {
- struct pt_device_access_data *dad
- = pt_get_device_access_data(dev);
- int rc = 0;
- pt_debug(dev, DL_INFO, "Entering %s\n", __func__);
- dad->base_dentry = debugfs_create_dir(dev_name(dev), NULL);
- if (IS_ERR_OR_NULL(dad->base_dentry)) {
- pt_debug(dev, DL_ERROR,
- "%s: Error, could not create base directory\n",
- __func__);
- goto exit;
- }
- dad->mfg_test_dentry = debugfs_create_dir("mfg_test",
- dad->base_dentry);
- if (IS_ERR_OR_NULL(dad->mfg_test_dentry)) {
- pt_debug(dev, DL_ERROR,
- "%s: Error, could not create mfg_test directory\n",
- __func__);
- goto unregister_base_dir;
- }
- dad->panel_scan_debugfs = debugfs_create_file(
- "panel_scan", 0644, dad->mfg_test_dentry, dad,
- &panel_scan_fops);
- if (IS_ERR_OR_NULL(dad->panel_scan_debugfs)) {
- pt_debug(dev, DL_ERROR,
- "%s: Error, could not create panel_scan\n",
- __func__);
- goto unregister_base_dir;
- }
- if (IS_ERR_OR_NULL(debugfs_create_file("get_idac", 0600,
- dad->mfg_test_dentry, dad, &get_idac_debugfs_fops))) {
- pt_debug(dev, DL_ERROR,
- "%s: Error, could not create get_idac\n",
- __func__);
- goto unregister_base_dir;
- }
- if (IS_ERR_OR_NULL(debugfs_create_file("auto_shorts", 0400,
- dad->mfg_test_dentry, dad,
- &auto_shorts_debugfs_fops))) {
- pt_debug(dev, DL_ERROR,
- "%s: Error, could not create auto_shorts\n",
- __func__);
- goto unregister_base_dir;
- }
- if (IS_ERR_OR_NULL(debugfs_create_file("opens", 0400,
- dad->mfg_test_dentry, dad, &opens_debugfs_fops))) {
- pt_debug(dev, DL_ERROR,
- "%s: Error, could not create opens\n",
- __func__);
- goto unregister_base_dir;
- }
- if (IS_ERR_OR_NULL(debugfs_create_file("calibrate_ext",
- 0600, dad->mfg_test_dentry,
- dad, &calibrate_ext_debugfs_fops))) {
- pt_debug(dev, DL_ERROR,
- "%s: Error, could not create calibrate_ext\n",
- __func__);
- goto unregister_base_dir;
- }
- if (IS_ERR_OR_NULL(debugfs_create_file("calibrate", 0600,
- dad->mfg_test_dentry, dad, &calibrate_debugfs_fops))) {
- pt_debug(dev, DL_ERROR,
- "%s: Error, could not create calibrate\n",
- __func__);
- goto unregister_base_dir;
- }
- if (IS_ERR_OR_NULL(debugfs_create_file("baseline", 0600,
- dad->mfg_test_dentry, dad, &baseline_debugfs_fops))) {
- pt_debug(dev, DL_ERROR,
- "%s: Error, could not create baseline\n",
- __func__);
- goto unregister_base_dir;
- }
- if (IS_ERR_OR_NULL(debugfs_create_file("cm_panel", 0400,
- dad->mfg_test_dentry, dad, &cm_panel_debugfs_fops))) {
- pt_debug(dev, DL_ERROR,
- "%s: Error, could not create cm_panel\n",
- __func__);
- goto unregister_base_dir;
- }
- if (IS_ERR_OR_NULL(debugfs_create_file("cp_panel", 0400,
- dad->mfg_test_dentry, dad, &cp_panel_debugfs_fops))) {
- pt_debug(dev, DL_ERROR,
- "%s: Error, could not create cp_panel\n",
- __func__);
- goto unregister_base_dir;
- }
- if (IS_ERR_OR_NULL(debugfs_create_file("cm_button", 0400,
- dad->mfg_test_dentry, dad, &cm_button_debugfs_fops))) {
- pt_debug(dev, DL_ERROR,
- "%s: Error, could not create cm_button\n",
- __func__);
- goto unregister_base_dir;
- }
- if (IS_ERR_OR_NULL(debugfs_create_file("cp_button", 0400,
- dad->mfg_test_dentry, dad, &cp_button_debugfs_fops))) {
- pt_debug(dev, DL_ERROR,
- "%s: Error, could not create cp_button\n",
- __func__);
- goto unregister_base_dir;
- }
- if (IS_ERR_OR_NULL(debugfs_create_file("fw_self_test", 0600,
- dad->mfg_test_dentry, dad, &fw_self_test_debugfs_fops))) {
- pt_debug(dev, DL_ERROR,
- "%s: Error, could not create fw_self_test\n",
- __func__);
- goto unregister_base_dir;
- }
- dad->cmcp_results_debugfs = debugfs_create_file("cmcp_results", 0644,
- dad->mfg_test_dentry, dad, &cmcp_results_debugfs_fops);
- if (IS_ERR_OR_NULL(dad->cmcp_results_debugfs)) {
- pt_debug(dev, DL_ERROR,
- "%s: Error, could not create cmcp_results\n",
- __func__);
- dad->cmcp_results_debugfs = NULL;
- goto unregister_base_dir;
- }
- #ifdef TTHE_TUNER_SUPPORT
- dad->tthe_get_panel_data_debugfs = debugfs_create_file(
- PT_TTHE_TUNER_GET_PANEL_DATA_FILE_NAME,
- 0644, NULL, dad, &tthe_get_panel_data_fops);
- if (IS_ERR_OR_NULL(dad->tthe_get_panel_data_debugfs)) {
- pt_debug(dev, DL_ERROR,
- "%s: Error, could not create get_panel_data\n",
- __func__);
- dad->tthe_get_panel_data_debugfs = NULL;
- goto unregister_base_dir;
- }
- #endif
- rc = device_create_file(dev, &dev_attr_cmcp_test);
- if (rc) {
- pt_debug(dev, DL_ERROR,
- "%s: Error, could not create cmcp_test\n",
- __func__);
- goto unregister_base_dir;
- }
- rc = device_create_file(dev, &dev_attr_cmcp_threshold_loading);
- if (rc) {
- pt_debug(dev, DL_ERROR,
- "%s: Error, could not create cmcp_threshold_loading\n",
- __func__);
- goto unregister_cmcp_test;
- }
- rc = device_create_bin_file(dev, &bin_attr_cmcp_threshold_data);
- if (rc) {
- pt_debug(dev, DL_ERROR,
- "%s: Error, could not create cmcp_threshold_data\n",
- __func__);
- goto unregister_cmcp_thresold_loading;
- }
- dad->sysfs_nodes_created = true;
- return rc;
- unregister_cmcp_thresold_loading:
- device_remove_file(dev, &dev_attr_cmcp_threshold_loading);
- unregister_cmcp_test:
- device_remove_file(dev, &dev_attr_cmcp_test);
- unregister_base_dir:
- debugfs_remove_recursive(dad->base_dentry);
- exit:
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_setup_cmcp_attention
- *
- * SUMMARY: Function to be registered to TTDL attention list to setup sysfs and
- * parse threshold file for device test.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- ******************************************************************************/
- static int pt_setup_cmcp_attention(struct device *dev)
- {
- struct pt_device_access_data *dad
- = pt_get_device_access_data(dev);
- int rc = 0;
- dad->si = cmd->request_sysinfo(dev);
- if (!dad->si)
- return -EINVAL;
- rc = pt_setup_sysfs(dev);
- schedule_work(&dad->cmcp_threshold_update);
- cmd->unsubscribe_attention(dev, PT_ATTEN_STARTUP,
- PT_DEVICE_ACCESS_NAME, pt_setup_cmcp_attention,
- 0);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_cmcp_parse_threshold_file
- *
- * SUMMARY: Parse cmcp threshold file and store it to the structure.
- *
- * PARAMETERS:
- * *fw - pointer to firmware structure
- * *context - expected read length of the response
- ******************************************************************************/
- static void pt_cmcp_parse_threshold_file(const struct firmware *fw,
- void *context)
- {
- struct device *dev = context;
- struct pt_device_access_data *dad =
- pt_get_device_access_data(dev);
- if (!fw) {
- pt_debug(dev, DL_WARN,
- "%s: No builtin cmcp threshold file\n",
- __func__);
- goto exit;
- }
- if (!fw->data || !fw->size) {
- pt_debug(dev, DL_ERROR,
- "%s: Invalid builtin cmcp threshold file\n",
- __func__);
- goto exit;
- }
- pt_debug(dev, DL_WARN, "%s: Found cmcp threshold file.\n",
- __func__);
- pt_parse_cmcp_threshold_file_common(dev, &fw->data[0], fw->size);
- dad->builtin_cmcp_threshold_status = 0;
- release_firmware(fw);
- return;
- exit:
- if (fw)
- release_firmware(fw);
- dad->builtin_cmcp_threshold_status = -EINVAL;
- }
- /*******************************************************************************
- * FUNCTION: pt_device_access_user_command
- *
- * SUMMARY: Wrapper function to call pt_cmcp_parse_threshold_file() by firmware
- * class function.
- *
- * PARAMETERS:
- * *cmcp_threshold_update - pointer to work_struct structure
- ******************************************************************************/
- static void pt_parse_cmcp_threshold_builtin(
- struct work_struct *cmcp_threshold_update)
- {
- struct pt_device_access_data *dad =
- container_of(cmcp_threshold_update,
- struct pt_device_access_data,
- cmcp_threshold_update);
- struct device *dev = dad->dev;
- struct pt_core_data *cd = dev_get_drvdata(dev);
- const struct firmware *fw_entry = NULL;
- int retval;
- dad->si = cmd->request_sysinfo(dev);
- if (!dad->si) {
- pt_debug(dev, DL_ERROR,
- "%s: Fail get sysinfo pointer from core\n",
- __func__);
- return;
- }
- pt_debug(dev, DL_INFO,
- "%s: Enabling cmcp threshold class loader built-in\n",
- __func__);
- /* Open threshold file */
- mutex_lock(&cd->firmware_class_lock);
- #if (KERNEL_VERSION(3, 13, 0) > LINUX_VERSION_CODE)
- retval = request_firmware(&fw_entry, CMCP_THRESHOLD_FILE_NAME, dev);
- #else
- retval = request_firmware_direct(&fw_entry,
- CMCP_THRESHOLD_FILE_NAME, dev);
- #endif
- if (retval < 0) {
- pt_debug(dev, DL_WARN,
- "%s: Failed loading cmcp threshold file, attempting legacy file\n",
- __func__);
- /* Try legacy file name */
- #if (KERNEL_VERSION(3, 13, 0) > LINUX_VERSION_CODE)
- retval = request_firmware(&fw_entry,
- PT_CMCP_THRESHOLD_FILE_NAME, dev);
- #else
- retval = request_firmware_direct(&fw_entry,
- PT_CMCP_THRESHOLD_FILE_NAME, dev);
- #endif
- if (retval < 0) {
- mutex_unlock(&cd->firmware_class_lock);
- dad->builtin_cmcp_threshold_status = -EINVAL;
- pt_debug(dev, DL_WARN,
- "%s: Fail request cmcp threshold class file load\n",
- __func__);
- goto exit;
- }
- }
- pt_cmcp_parse_threshold_file(fw_entry, dev);
- mutex_unlock(&cd->firmware_class_lock);
- exit:
- return;
- }
- /*******************************************************************************
- * FUNCTION: pt_device_access_probe
- *
- * SUMMARY: The probe function for the device access
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * **data - double pointer to pt_device_access_data data to be created here
- ******************************************************************************/
- static int pt_device_access_probe(struct device *dev, void **data)
- {
- struct pt_device_access_data *dad;
- struct configuration *configurations;
- struct cmcp_data *cmcp_info;
- struct result *result;
- int tx_num = MAX_TX_SENSORS;
- int rx_num = MAX_RX_SENSORS;
- int btn_num = MAX_BUTTONS;
- struct test_case_field *test_case_field_array;
- struct test_case_search *test_case_search_array;
- int rc = 0;
- dad = kzalloc(sizeof(*dad), GFP_KERNEL);
- if (!dad) {
- rc = -ENOMEM;
- goto pt_device_access_probe_data_failed;
- }
- configurations =
- kzalloc(sizeof(*configurations), GFP_KERNEL);
- if (!configurations) {
- rc = -ENOMEM;
- goto pt_device_access_probe_configs_failed;
- }
- dad->configs = configurations;
- cmcp_info = kzalloc(sizeof(*cmcp_info), GFP_KERNEL);
- if (!cmcp_info) {
- rc = -ENOMEM;
- goto pt_device_access_probe_cmcp_info_failed;
- }
- dad->cmcp_info = cmcp_info;
- cmcp_info->tx_num = tx_num;
- cmcp_info->rx_num = rx_num;
- cmcp_info->btn_num = btn_num;
- result = kzalloc(sizeof(*result), GFP_KERNEL);
- if (!result) {
- rc = -ENOMEM;
- goto pt_device_access_probe_result_failed;
- }
- dad->result = result;
- test_case_field_array =
- kzalloc(sizeof(*test_case_field_array) * MAX_CASE_NUM,
- GFP_KERNEL);
- if (!test_case_field_array) {
- rc = -ENOMEM;
- goto pt_device_access_probe_field_array_failed;
- }
- test_case_search_array =
- kzalloc(sizeof(*test_case_search_array) * MAX_CASE_NUM,
- GFP_KERNEL);
- if (!test_case_search_array) {
- rc = -ENOMEM;
- goto pt_device_access_probe_search_array_failed;
- }
- cmcp_info->gd_sensor_col = (struct gd_sensor *)
- kzalloc(tx_num * sizeof(struct gd_sensor), GFP_KERNEL);
- if (cmcp_info->gd_sensor_col == NULL)
- goto pt_device_access_probe_gd_sensor_col_failed;
- cmcp_info->gd_sensor_row = (struct gd_sensor *)
- kzalloc(rx_num * sizeof(struct gd_sensor), GFP_KERNEL);
- if (cmcp_info->gd_sensor_row == NULL)
- goto pt_device_access_probe_gd_sensor_row_failed;
- cmcp_info->cm_data_panel =
- kzalloc((tx_num * rx_num + 1) * sizeof(int32_t), GFP_KERNEL);
- if (cmcp_info->cm_data_panel == NULL)
- goto pt_device_access_probe_cm_data_panel_failed;
- cmcp_info->cp_tx_data_panel =
- kzalloc(tx_num * sizeof(int32_t), GFP_KERNEL);
- if (cmcp_info->cp_tx_data_panel == NULL)
- goto pt_device_access_probe_cp_tx_data_panel_failed;
- cmcp_info->cp_tx_cal_data_panel =
- kzalloc(tx_num * sizeof(int32_t), GFP_KERNEL);
- if (cmcp_info->cp_tx_cal_data_panel == NULL)
- goto pt_device_access_probe_cp_tx_cal_data_panel_failed;
- cmcp_info->cp_rx_data_panel =
- kzalloc(rx_num * sizeof(int32_t), GFP_KERNEL);
- if (cmcp_info->cp_rx_data_panel == NULL)
- goto pt_device_access_probe_cp_rx_data_panel_failed;
- cmcp_info->cp_rx_cal_data_panel =
- kzalloc(rx_num * sizeof(int32_t), GFP_KERNEL);
- if (cmcp_info->cp_rx_cal_data_panel == NULL)
- goto pt_device_access_probe_cp_rx_cal_data_panel_failed;
- cmcp_info->cm_btn_data = kcalloc(btn_num, sizeof(int32_t), GFP_KERNEL);
- if (cmcp_info->cm_btn_data == NULL)
- goto pt_device_access_probe_cm_btn_data_failed;
- cmcp_info->cp_btn_data = kcalloc(btn_num, sizeof(int32_t), GFP_KERNEL);
- if (cmcp_info->cp_btn_data == NULL)
- goto pt_device_access_probe_cp_btn_data_failed;
- cmcp_info->cm_sensor_column_delta =
- kzalloc(rx_num * tx_num * sizeof(int32_t), GFP_KERNEL);
- if (cmcp_info->cm_sensor_column_delta == NULL)
- goto pt_device_access_probe_cm_sensor_column_delta_failed;
- cmcp_info->cm_sensor_row_delta =
- kzalloc(tx_num * rx_num * sizeof(int32_t), GFP_KERNEL);
- if (cmcp_info->cm_sensor_row_delta == NULL)
- goto pt_device_access_probe_cm_sensor_row_delta_failed;
- mutex_init(&dad->sysfs_lock);
- mutex_init(&dad->cmcp_threshold_lock);
- dad->dev = dev;
- #ifdef TTHE_TUNER_SUPPORT
- mutex_init(&dad->debugfs_lock);
- dad->heatmap.num_element = 200;
- #endif
- *data = dad;
- dad->test_field_array = test_case_field_array;
- dad->test_search_array = test_case_search_array;
- dad->test_executed = 0;
- dad->cal_ext_data.mode = PT_CAL_EXT_MODE_UNDEFINED;
- dad->panel_scan_retrieve_id = 0;
- dad->panel_scan_type_id = 0;
- INIT_WORK(&dad->cmcp_threshold_update, pt_parse_cmcp_threshold_builtin);
- /* get sysinfo */
- dad->si = cmd->request_sysinfo(dev);
- if (dad->si) {
- rc = pt_setup_sysfs(dev);
- if (rc)
- goto pt_device_access_setup_sysfs_failed;
- } else {
- pt_debug(dev, DL_ERROR,
- "%s: Fail get sysinfo pointer from core p=%p\n",
- __func__, dad->si);
- cmd->subscribe_attention(dev, PT_ATTEN_STARTUP,
- PT_DEVICE_ACCESS_NAME,
- pt_setup_cmcp_attention, 0);
- }
- schedule_work(&dad->cmcp_threshold_update);
- return 0;
- pt_device_access_setup_sysfs_failed:
- kfree(cmcp_info->cm_sensor_row_delta);
- pt_device_access_probe_cm_sensor_row_delta_failed:
- kfree(cmcp_info->cm_sensor_column_delta);
- pt_device_access_probe_cm_sensor_column_delta_failed:
- kfree(cmcp_info->cp_btn_data);
- pt_device_access_probe_cp_btn_data_failed:
- kfree(cmcp_info->cm_btn_data);
- pt_device_access_probe_cm_btn_data_failed:
- kfree(cmcp_info->cp_rx_cal_data_panel);
- pt_device_access_probe_cp_rx_cal_data_panel_failed:
- kfree(cmcp_info->cp_rx_data_panel);
- pt_device_access_probe_cp_rx_data_panel_failed:
- kfree(cmcp_info->cp_tx_cal_data_panel);
- pt_device_access_probe_cp_tx_cal_data_panel_failed:
- kfree(cmcp_info->cp_tx_data_panel);
- pt_device_access_probe_cp_tx_data_panel_failed:
- kfree(cmcp_info->cm_data_panel);
- pt_device_access_probe_cm_data_panel_failed:
- kfree(cmcp_info->gd_sensor_row);
- pt_device_access_probe_gd_sensor_row_failed:
- kfree(cmcp_info->gd_sensor_col);
- pt_device_access_probe_gd_sensor_col_failed:
- kfree(test_case_search_array);
- pt_device_access_probe_search_array_failed:
- kfree(test_case_field_array);
- pt_device_access_probe_field_array_failed:
- kfree(result);
- pt_device_access_probe_result_failed:
- kfree(cmcp_info);
- pt_device_access_probe_cmcp_info_failed:
- kfree(configurations);
- pt_device_access_probe_configs_failed:
- kfree(dad);
- pt_device_access_probe_data_failed:
- pt_debug(dev, DL_ERROR, "%s failed.\n", __func__);
- return rc;
- }
- /*******************************************************************************
- * FUNCTION: pt_device_access_release
- *
- * SUMMARY: Remove function for device_access module that does following
- * cleanup:
- * - Unsubscibe all registered attention tasks
- * - Removes all created sysfs nodes
- * - Frees all pointers
- *
- * PARAMETERS:
- * *dev - pointer to device structure
- * *data - pointer to the device_access data
- ******************************************************************************/
- static void pt_device_access_release(struct device *dev, void *data)
- {
- struct pt_device_access_data *dad = data;
- if (dad->sysfs_nodes_created) {
- debugfs_remove(dad->cmcp_results_debugfs);
- debugfs_remove_recursive(dad->base_dentry);
- #ifdef TTHE_TUNER_SUPPORT
- debugfs_remove(dad->tthe_get_panel_data_debugfs);
- #endif
- device_remove_file(dev, &dev_attr_cmcp_test);
- device_remove_file(dev, &dev_attr_cmcp_threshold_loading);
- device_remove_bin_file(dev, &bin_attr_cmcp_threshold_data);
- kfree(dad->cmcp_threshold_data);
- } else {
- cmd->unsubscribe_attention(dev, PT_ATTEN_STARTUP,
- PT_DEVICE_ACCESS_NAME,
- pt_setup_cmcp_attention, 0);
- }
- kfree(dad->test_search_array);
- kfree(dad->test_field_array);
- kfree(dad->configs);
- pt_free_cmcp_buf(dad->cmcp_info);
- kfree(dad->cmcp_info);
- kfree(dad->result);
- kfree(dad);
- }
- static struct pt_module device_access_module = {
- .name = PT_DEVICE_ACCESS_NAME,
- .probe = pt_device_access_probe,
- .release = pt_device_access_release,
- };
- /*******************************************************************************
- * FUNCTION: pt_device_access_init
- *
- * SUMMARY: Initialize function for device access module which to register
- * device_access_module into TTDL module list.
- *
- * RETURN:
- * 0 = success
- * !0 = failure
- ******************************************************************************/
- static int __init pt_device_access_init(void)
- {
- int rc;
- cmd = pt_get_commands();
- if (!cmd)
- return -EINVAL;
- rc = pt_register_module(&device_access_module);
- if (rc) {
- pr_err("%s: Error, failed registering module\n",
- __func__);
- return rc;
- }
- pr_info("%s: Parade TTSP Device Access Driver (Built %s) rc = %d\n",
- __func__, PT_DRIVER_VERSION, rc);
- return 0;
- }
- module_init(pt_device_access_init);
- /*******************************************************************************
- * FUNCTION: pt_device_access_exit
- *
- * SUMMARY: Exit function for device access module which to unregister
- * device_access_module from TTDL module list.
- *
- ******************************************************************************/
- static void __exit pt_device_access_exit(void)
- {
- pt_unregister_module(&device_access_module);
- }
- module_exit(pt_device_access_exit);
- MODULE_LICENSE("GPL");
- MODULE_DESCRIPTION("Parade TrueTouch(R) Standard Product Device Access Driver");
- MODULE_AUTHOR("Parade Technologies <[email protected]>");
|