1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733 |
- /*
- * 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 timespec ts;
- getnstimeofday(&ts);
- rtc_time_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 = cmcp_info->tx_num;
- int rx_num = cmcp_info->rx_num;
- int btn_num = cmcp_info->btn_num;
- 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);
- 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");
- if (result == NULL)
- pt_debug(dev, DL_WARN, "result is NULL");
- if (cmcp_info == NULL)
- pt_debug(dev, DL_WARN, "cmcp_info is NULL");
- 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 */
- *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]>");
|