pt_device_access.c 197 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733
  1. /*
  2. * pt_device_access.c
  3. * Parade TrueTouch(TM) Standard Product Device Access Module.
  4. * Configuration and Test command/status user interface.
  5. * For use with Parade touchscreen controllers.
  6. * Supported parts include:
  7. * TMA5XX
  8. * TMA448
  9. * TMA445A
  10. * TT21XXX
  11. * TT31XXX
  12. * TT4XXXX
  13. * TT7XXX
  14. * TC3XXX
  15. *
  16. * Copyright (C) 2015-2020 Parade Technologies
  17. *
  18. * This program is free software; you can redistribute it and/or
  19. * modify it under the terms of the GNU General Public License
  20. * version 2, and only version 2, as published by the
  21. * Free Software Foundation.
  22. *
  23. * This program is distributed in the hope that it will be useful,
  24. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. * GNU General Public License for more details.
  27. *
  28. * Contact Parade Technologies at www.paradetech.com <[email protected]>
  29. */
  30. #include "pt_regs.h"
  31. #include <linux/firmware.h>
  32. #include <linux/timer.h>
  33. #include <linux/timex.h>
  34. #include <linux/rtc.h>
  35. #define PT_CMCP_THRESHOLD_FILE_NAME "pt_thresholdfile.csv"
  36. #define CMCP_THRESHOLD_FILE_NAME "ttdl_cmcp_thresholdfile.csv"
  37. /* Max test case number */
  38. #define MAX_CASE_NUM (22)
  39. /* ASCII */
  40. #define ASCII_LF (0x0A)
  41. #define ASCII_CR (0x0D)
  42. #define ASCII_COMMA (0x2C)
  43. #define ASCII_ZERO (0x30)
  44. #define ASCII_NINE (0x39)
  45. /* Max characters of test case name */
  46. #define NAME_SIZE_MAX (50)
  47. /* Max sensor and button number */
  48. #define MAX_BUTTONS (PIP1_SYSINFO_MAX_BTN)
  49. #define MAX_SENSORS (5120)
  50. #define MAX_TX_SENSORS (128)
  51. #define MAX_RX_SENSORS (128)
  52. /* Multiply by 2 for double (min, max) values */
  53. #define TABLE_BUTTON_MAX_SIZE (MAX_BUTTONS * 2)
  54. #define TABLE_SENSOR_MAX_SIZE (MAX_SENSORS * 2)
  55. #define TABLE_TX_MAX_SIZE (MAX_TX_SENSORS*2)
  56. #define TABLE_RX_MAX_SIZE (MAX_RX_SENSORS*2)
  57. #define CM_PANEL_DATA_OFFSET (6)
  58. #define CM_BTN_DATA_OFFSET (6)
  59. #define CP_PANEL_DATA_OFFSET (6)
  60. #define CP_BTN_DATA_OFFSET (6)
  61. #define MAX_BUF_LEN (100000)
  62. #define RETRIEVE_PANEL_SCAN_HDR (10)
  63. enum print_buffer_format {
  64. PT_PR_FORMAT_DEFAULT = 0,
  65. PT_PR_FORMAT_U8_SPACE = 1,
  66. PT_PR_FORMAT_U16_SPACE = 2,
  67. PT_PR_FORMAT_U8_NO_SPACE = 3,
  68. PT_PR_FORMAT_U32_SPACE = 4,
  69. PT_PR_FORMAT_UNDEFINE
  70. };
  71. /* cmcp csv file information */
  72. struct configuration {
  73. u32 cm_range_limit_row;
  74. u32 cm_range_limit_col;
  75. u32 cm_min_limit_cal;
  76. u32 cm_max_limit_cal;
  77. u32 cm_max_delta_sensor_percent;
  78. u32 cm_max_delta_button_percent;
  79. u32 min_button;
  80. u32 max_button;
  81. u32 cp_max_delta_sensor_rx_percent;
  82. u32 cp_max_delta_sensor_tx_percent;
  83. u32 cm_min_max_table_btn[TABLE_BUTTON_MAX_SIZE];
  84. u32 cp_min_max_table_btn[TABLE_BUTTON_MAX_SIZE];
  85. u32 cm_min_max_table_sensor[TABLE_SENSOR_MAX_SIZE];
  86. u32 cp_min_max_table_rx[TABLE_RX_MAX_SIZE];
  87. u32 cp_min_max_table_tx[TABLE_TX_MAX_SIZE];
  88. u32 cm_min_max_table_btn_size;
  89. u32 cp_min_max_table_btn_size;
  90. u32 cm_min_max_table_sensor_size;
  91. u32 cp_min_max_table_rx_size;
  92. u32 cp_min_max_table_tx_size;
  93. u32 cp_max_delta_button_percent;
  94. u32 cm_max_table_gradient_cols_percent[TABLE_TX_MAX_SIZE];
  95. u32 cm_max_table_gradient_cols_percent_size;
  96. u32 cm_max_table_gradient_rows_percent[TABLE_RX_MAX_SIZE];
  97. u32 cm_max_table_gradient_rows_percent_size;
  98. u32 cm_excluding_row_edge;
  99. u32 cm_excluding_col_edge;
  100. u32 rx_num;
  101. u32 tx_num;
  102. u32 btn_num;
  103. u32 cm_enabled;
  104. u32 cp_enabled;
  105. u32 is_valid_or_not;
  106. };
  107. /* Test case search definition */
  108. struct test_case_search {
  109. char name[NAME_SIZE_MAX]; /* Test case name */
  110. u32 name_size; /* Test case name size */
  111. u32 offset; /* Test case offset */
  112. };
  113. /* Test case field definition */
  114. struct test_case_field {
  115. char *name; /* Test case name */
  116. u32 name_size; /* Test case name size */
  117. u32 type; /* Test case type */
  118. u32 *bufptr; /* Buffer to store value information */
  119. u32 exist_or_not;/* Test case exist or not */
  120. u32 data_num; /* Buffer data number */
  121. u32 line_num; /* Buffer line number */
  122. };
  123. /* Test case type */
  124. enum test_case_type {
  125. TEST_CASE_TYPE_NO,
  126. TEST_CASE_TYPE_ONE,
  127. TEST_CASE_TYPE_MUL,
  128. TEST_CASE_TYPE_MUL_LINES,
  129. };
  130. /* Test case order in test_case_field_array */
  131. enum case_order {
  132. CM_TEST_INPUTS,
  133. CM_EXCLUDING_COL_EDGE,
  134. CM_EXCLUDING_ROW_EDGE,
  135. CM_GRADIENT_CHECK_COL,
  136. CM_GRADIENT_CHECK_ROW,
  137. CM_RANGE_LIMIT_ROW,
  138. CM_RANGE_LIMIT_COL,
  139. CM_MIN_LIMIT_CAL,
  140. CM_MAX_LIMIT_CAL,
  141. CM_MAX_DELTA_SENSOR_PERCENT,
  142. CM_MAX_DELTA_BUTTON_PERCENT,
  143. PER_ELEMENT_MIN_MAX_TABLE_BUTTON,
  144. PER_ELEMENT_MIN_MAX_TABLE_SENSOR,
  145. CP_TEST_INPUTS,
  146. CP_MAX_DELTA_SENSOR_RX_PERCENT,
  147. CP_MAX_DELTA_SENSOR_TX_PERCENT,
  148. CP_MAX_DELTA_BUTTON_PERCENT,
  149. CP_PER_ELEMENT_MIN_MAX_BUTTON,
  150. MIN_BUTTON,
  151. MAX_BUTTON,
  152. PER_ELEMENT_MIN_MAX_RX,
  153. PER_ELEMENT_MIN_MAX_TX,
  154. CASE_ORDER_MAX,
  155. };
  156. enum cmcp_test_item {
  157. CMCP_FULL = 0,
  158. CMCP_CM_PANEL,
  159. CMCP_CP_PANEL,
  160. CMCP_CM_BTN,
  161. CMCP_CP_BTN,
  162. };
  163. #define CM_ENABLED 0x10
  164. #define CP_ENABLED 0x20
  165. #define CM_PANEL (0x01 | CM_ENABLED)
  166. #define CP_PANEL (0x02 | CP_ENABLED)
  167. #define CM_BTN (0x04 | CM_ENABLED)
  168. #define CP_BTN (0x08 | CP_ENABLED)
  169. #define CMCP_FULL_CASE\
  170. (CM_PANEL | CP_PANEL | CM_BTN | CP_BTN | CM_ENABLED | CP_ENABLED)
  171. #define PT_DEVICE_ACCESS_NAME "pt_device_access"
  172. #define PT_INPUT_ELEM_SZ (sizeof("0xHH") + 1)
  173. #define PIP_CMD_MAX_LENGTH ((1 << 16) - 1)
  174. #ifdef TTHE_TUNER_SUPPORT
  175. struct heatmap_param {
  176. bool scan_start;
  177. enum scan_data_type_list data_type; /* raw, base, diff */
  178. int num_element;
  179. };
  180. #endif
  181. #define ABS(x) (((x) < 0) ? -(x) : (x))
  182. #ifndef MIN
  183. #define MIN(a, b) (((a) < (b)) ? (a) : (b))
  184. #endif
  185. #define PT_MAX_CONFIG_BYTES 256
  186. #define PT_TTHE_TUNER_GET_PANEL_DATA_FILE_NAME "get_panel_data"
  187. #define TTHE_TUNER_MAX_BUF (PT_MAX_PRBUF_SIZE * 8)
  188. struct pt_device_access_data {
  189. struct device *dev;
  190. struct pt_sysinfo *si;
  191. struct mutex sysfs_lock;
  192. bool sysfs_nodes_created;
  193. struct kobject mfg_test;
  194. u8 panel_scan_retrieve_id;
  195. u8 panel_scan_type_id;
  196. u8 get_idac_data_id;
  197. u8 calibrate_sensing_mode;
  198. u8 calibrate_initialize_baselines;
  199. u8 baseline_sensing_mode;
  200. u8 fw_self_test_id;
  201. u8 fw_self_test_format;
  202. u16 fw_self_test_param_len;
  203. u8 fw_self_test_param[PT_FW_SELF_TEST_MAX_PARM];
  204. struct pt_cal_ext_data cal_ext_data;
  205. struct dentry *panel_scan_debugfs;
  206. int panel_scan_size;
  207. u8 panel_scan_data_buf[TTHE_TUNER_MAX_BUF];
  208. struct mutex debugfs_lock;
  209. #ifdef TTHE_TUNER_SUPPORT
  210. struct heatmap_param heatmap;
  211. struct dentry *tthe_get_panel_data_debugfs;
  212. u8 tthe_get_panel_data_is_open;
  213. #endif
  214. struct dentry *cmcp_results_debugfs;
  215. struct dentry *base_dentry;
  216. struct dentry *mfg_test_dentry;
  217. u8 ic_buf[PT_MAX_PRBUF_SIZE];
  218. u8 response_buf[PT_MAX_PRBUF_SIZE];
  219. struct mutex cmcp_threshold_lock;
  220. u8 *cmcp_threshold_data;
  221. int cmcp_threshold_size;
  222. bool cmcp_threshold_loading;
  223. struct work_struct cmcp_threshold_update;
  224. int builtin_cmcp_threshold_status;
  225. bool is_manual_upgrade_enabled;
  226. struct configuration *configs;
  227. struct cmcp_data *cmcp_info;
  228. struct result *result;
  229. struct test_case_search *test_search_array;
  230. struct test_case_field *test_field_array;
  231. int cmcp_test_items;
  232. int test_executed;
  233. int cmcp_range_check;
  234. int cmcp_force_calibrate;
  235. int cmcp_test_in_progress;
  236. };
  237. struct cmcp_data {
  238. struct gd_sensor *gd_sensor_col;
  239. struct gd_sensor *gd_sensor_row;
  240. int32_t *cm_data_panel;
  241. int32_t *cp_tx_data_panel;
  242. int32_t *cp_rx_data_panel;
  243. int32_t *cp_tx_cal_data_panel;
  244. int32_t *cp_rx_cal_data_panel;
  245. int32_t cp_sensor_rx_delta;
  246. int32_t cp_sensor_tx_delta;
  247. int32_t cp_button_delta;
  248. int32_t *cm_btn_data;
  249. int32_t *cp_btn_data;
  250. int32_t *cm_sensor_column_delta;
  251. int32_t *cm_sensor_row_delta;
  252. int32_t cp_btn_cal;
  253. int32_t cm_btn_cal;
  254. int32_t cp_button_ave;
  255. int32_t cm_ave_data_panel;
  256. int32_t cp_tx_ave_data_panel;
  257. int32_t cp_rx_ave_data_panel;
  258. int32_t cm_cal_data_panel;
  259. int32_t cm_ave_data_btn;
  260. int32_t cm_cal_data_btn;
  261. int32_t cm_delta_data_btn;
  262. int32_t cm_sensor_delta;
  263. int32_t tx_num;
  264. int32_t rx_num;
  265. int32_t btn_num;
  266. };
  267. struct result {
  268. int32_t config_ver;
  269. int32_t revision_ctrl;
  270. int32_t device_id_high;
  271. int32_t device_id_low;
  272. /* Sensor Cm validation */
  273. bool cm_test_pass;
  274. bool cm_sensor_validation_pass;
  275. bool cm_sensor_row_delta_pass;
  276. bool cm_sensor_col_delta_pass;
  277. bool cm_sensor_gd_row_pass;
  278. bool cm_sensor_gd_col_pass;
  279. bool cm_sensor_calibration_pass;
  280. bool cm_sensor_delta_pass;
  281. bool cm_button_validation_pass;
  282. bool cm_button_delta_pass;
  283. int32_t *cm_sensor_raw_data;
  284. int32_t cm_sensor_calibration;
  285. int32_t cm_sensor_delta;
  286. int32_t *cm_button_raw_data;
  287. int32_t cm_button_delta;
  288. /* Sensor Cp validation */
  289. bool cp_test_pass;
  290. bool cp_sensor_delta_pass;
  291. bool cp_sensor_rx_delta_pass;
  292. bool cp_sensor_tx_delta_pass;
  293. bool cp_sensor_average_pass;
  294. bool cp_button_delta_pass;
  295. bool cp_button_average_pass;
  296. bool cp_rx_validation_pass;
  297. bool cp_tx_validation_pass;
  298. bool cp_button_validation_pass;
  299. int32_t *cp_sensor_rx_raw_data;
  300. int32_t *cp_sensor_tx_raw_data;
  301. int32_t cp_sensor_rx_delta;
  302. int32_t cp_sensor_tx_delta;
  303. int32_t cp_sensor_rx_calibration;
  304. int32_t cp_sensor_tx_calibration;
  305. int32_t *cp_button_raw_data;
  306. int32_t cp_button_delta;
  307. /*other validation*/
  308. bool short_test_pass;
  309. bool test_summary;
  310. };
  311. static struct pt_core_commands *cmd;
  312. static struct pt_module device_access_module;
  313. static ssize_t pt_run_and_get_selftest_result(struct device *dev,
  314. int protect, char *buf, size_t buf_len, u8 test_id,
  315. u16 read_length, bool get_result_on_pass,
  316. bool print_results, u8 print_format);
  317. static int _pt_calibrate_idacs_cmd(struct device *dev,
  318. u8 sensing_mode, u8 *status);
  319. static int pt_perform_calibration(struct device *dev);
  320. /*******************************************************************************
  321. * FUNCTION: pt_get_device_access_data
  322. *
  323. * SUMMARY: Inline function to get pt_device_access_data.
  324. *
  325. * RETURN:
  326. * pointer to pt_device_access_data structure
  327. *
  328. * PARAMETERS:
  329. * *dev - pointer to device structure
  330. ******************************************************************************/
  331. static inline struct pt_device_access_data *pt_get_device_access_data(
  332. struct device *dev)
  333. {
  334. return pt_get_module_data(dev, &device_access_module);
  335. }
  336. /*******************************************************************************
  337. * FUNCTION: cmcp_check_config_fw_match
  338. *
  339. * SUMMARY: Checks if tx,rx and btn num of firmware match with configuration.
  340. *
  341. * RETURN:
  342. * 0 = match
  343. * !0 = doesn't match
  344. *
  345. * PARAMETERS:
  346. * *dev - pointer to device structure
  347. * *configuration - pointer to configuration structure
  348. ******************************************************************************/
  349. static int cmcp_check_config_fw_match(struct device *dev,
  350. struct configuration *configuration)
  351. {
  352. struct pt_device_access_data *dad
  353. = pt_get_device_access_data(dev);
  354. int32_t tx_num = dad->configs->tx_num;
  355. int32_t rx_num = dad->configs->rx_num;
  356. int32_t button_num = dad->configs->btn_num;
  357. int ret = 0;
  358. if (tx_num != dad->si->sensing_conf_data.tx_num) {
  359. pt_debug(dev, DL_ERROR,
  360. "%s: TX number mismatch! CSV=%d DUT=%d\n",
  361. __func__, tx_num, dad->si->sensing_conf_data.tx_num);
  362. ret = -EINVAL;
  363. }
  364. if (rx_num != dad->si->sensing_conf_data.rx_num) {
  365. pt_debug(dev, DL_ERROR,
  366. "%s: RX number mismatch! CSV=%d DUT=%d\n",
  367. __func__, rx_num, dad->si->sensing_conf_data.rx_num);
  368. ret = -EINVAL;
  369. }
  370. if (button_num != dad->si->num_btns) {
  371. pt_debug(dev, DL_ERROR,
  372. "%s: Button number mismatch! CSV=%d DUT=%d\n",
  373. __func__, button_num, dad->si->num_btns);
  374. ret = -EINVAL;
  375. }
  376. return ret;
  377. }
  378. /*******************************************************************************
  379. * FUNCTION: validate_cm_test_results
  380. *
  381. * SUMMARY: Checks cm test results and outputs each test and a summary result
  382. *
  383. * RETURN:
  384. * 0 = success
  385. * !0 = failure
  386. *
  387. * PARAMETERS:
  388. * *dev - pointer to device structure
  389. * *configuration - pointer to configuration structure
  390. * *cmcp_info - pointer to cmcp_data structure to store cmcp data from fw
  391. * *result - pointer to result structure
  392. * *pass - pointer to bool value
  393. * test_item - flag to store all test item are requested
  394. ******************************************************************************/
  395. static int validate_cm_test_results(struct device *dev,
  396. struct configuration *configuration, struct cmcp_data *cmcp_info,
  397. struct result *result, bool *pass, int test_item)
  398. {
  399. int32_t tx_num = cmcp_info->tx_num;
  400. int32_t rx_num = cmcp_info->rx_num;
  401. int32_t button_num = cmcp_info->btn_num;
  402. uint32_t sensor_num = tx_num * rx_num;
  403. int32_t *cm_sensor_data = cmcp_info->cm_data_panel;
  404. int32_t cm_button_delta;
  405. int32_t cm_sensor_calibration;
  406. int32_t *cm_button_data = cmcp_info->cm_btn_data;
  407. struct gd_sensor *gd_sensor_col = cmcp_info->gd_sensor_col;
  408. struct gd_sensor *gd_sensor_row = cmcp_info->gd_sensor_row;
  409. int32_t *cm_sensor_column_delta = cmcp_info->cm_sensor_column_delta;
  410. int32_t *cm_sensor_row_delta = cmcp_info->cm_sensor_row_delta;
  411. int ret = 0;
  412. int i, j;
  413. pt_debug(dev, DL_INFO, "%s: start\n", __func__);
  414. if ((test_item & CM_PANEL) == CM_PANEL) {
  415. pt_debug(dev, DL_INFO,
  416. "Check each sensor Cm data for min max value\n ");
  417. /* Check each sensor Cm data for min/max values */
  418. result->cm_sensor_validation_pass = true;
  419. for (i = 0; i < sensor_num; i++) {
  420. int row = i % rx_num;
  421. int col = i / rx_num;
  422. int32_t cm_sensor_min =
  423. configuration->cm_min_max_table_sensor[(row*tx_num+col)*2];
  424. int32_t cm_sensor_max =
  425. configuration->cm_min_max_table_sensor[(row*tx_num+col)*2+1];
  426. if ((cm_sensor_data[i] < cm_sensor_min) ||
  427. (cm_sensor_data[i] > cm_sensor_max)) {
  428. pt_debug(dev, DL_WARN,
  429. "%s: Sensor[%d,%d]:%d (%d,%d)\n",
  430. "Cm sensor min/max test",
  431. row, col,
  432. cm_sensor_data[i],
  433. cm_sensor_min, cm_sensor_max);
  434. result->cm_sensor_validation_pass = false;
  435. }
  436. }
  437. /*check cm gradient column data*/
  438. result->cm_sensor_gd_col_pass = true;
  439. for (i = 0; i < configuration->cm_max_table_gradient_cols_percent_size;
  440. i++) {
  441. if ((gd_sensor_col + i)->gradient_val >
  442. 10 * configuration->cm_max_table_gradient_cols_percent[i]) {
  443. pt_debug(dev, DL_WARN,
  444. "%s: cm_max_table_gradient_cols_percent[%d]:%d, gradient_val:%d\n",
  445. __func__, i,
  446. configuration->cm_max_table_gradient_cols_percent[i],
  447. (gd_sensor_col + i)->gradient_val);
  448. result->cm_sensor_gd_col_pass = false;
  449. }
  450. }
  451. /*check cm gradient row data*/
  452. result->cm_sensor_gd_row_pass = true;
  453. for (j = 0; j < configuration->cm_max_table_gradient_rows_percent_size;
  454. j++) {
  455. if ((gd_sensor_row + j)->gradient_val >
  456. 10 * configuration->cm_max_table_gradient_rows_percent[j]) {
  457. pt_debug(dev, DL_WARN,
  458. "%s: cm_max_table_gradient_rows_percent[%d]:%d, gradient_val:%d\n",
  459. __func__, j,
  460. configuration->cm_max_table_gradient_rows_percent[j],
  461. (gd_sensor_row + j)->gradient_val);
  462. result->cm_sensor_gd_row_pass = false;
  463. }
  464. }
  465. result->cm_sensor_row_delta_pass = true;
  466. result->cm_sensor_col_delta_pass = true;
  467. result->cm_sensor_calibration_pass = true;
  468. result->cm_sensor_delta_pass = true;
  469. /* Check each row Cm data with neighbor for difference */
  470. for (i = 0; i < tx_num; i++) {
  471. for (j = 1; j < rx_num; j++) {
  472. int32_t cm_sensor_row_diff =
  473. ABS(cm_sensor_data[i * rx_num + j] -
  474. cm_sensor_data[i * rx_num + j - 1]);
  475. cm_sensor_row_delta[i * rx_num + j - 1] =
  476. cm_sensor_row_diff;
  477. if (cm_sensor_row_diff >
  478. configuration->cm_range_limit_row) {
  479. pt_debug(dev, DL_DEBUG,
  480. "%s: Sensor[%d,%d]:%d (%d)\n",
  481. "Cm sensor row range limit test",
  482. j, i, cm_sensor_row_diff,
  483. configuration->cm_range_limit_row);
  484. result->cm_sensor_row_delta_pass = false;
  485. }
  486. }
  487. }
  488. /* Check each column Cm data with neighbor for difference */
  489. for (i = 1; i < tx_num; i++) {
  490. for (j = 0; j < rx_num; j++) {
  491. int32_t cm_sensor_col_diff =
  492. ABS((int)cm_sensor_data[i * rx_num + j] -
  493. (int)cm_sensor_data[(i - 1) * rx_num + j]);
  494. cm_sensor_column_delta[(i - 1) * rx_num + j] =
  495. cm_sensor_col_diff;
  496. if (cm_sensor_col_diff >
  497. configuration->cm_range_limit_col) {
  498. pt_debug(dev, DL_DEBUG,
  499. "%s: Sensor[%d,%d]:%d (%d)\n",
  500. "Cm sensor column range limit test",
  501. j, i, cm_sensor_col_diff,
  502. configuration->cm_range_limit_col);
  503. result->cm_sensor_col_delta_pass = false;
  504. }
  505. }
  506. }
  507. /* Check sensor calculated Cm for min/max values */
  508. cm_sensor_calibration = cmcp_info->cm_cal_data_panel;
  509. if (cm_sensor_calibration <
  510. configuration->cm_min_limit_cal ||
  511. cm_sensor_calibration > configuration->cm_max_limit_cal) {
  512. pt_debug(dev, DL_DEBUG, "%s: Cm_cal:%d (%d,%d)\n",
  513. "Cm sensor Cm_cal min/max test",
  514. cm_sensor_calibration,
  515. configuration->cm_min_limit_cal,
  516. configuration->cm_max_limit_cal);
  517. result->cm_sensor_calibration_pass = false;
  518. }
  519. /* Check sensor Cm delta for range limit */
  520. if (cmcp_info->cm_sensor_delta >
  521. (10 * configuration->cm_max_delta_sensor_percent)) {
  522. pt_debug(dev, DL_DEBUG,
  523. "%s: Cm_sensor_delta:%d (%d)\n",
  524. "Cm sensor delta range limit test",
  525. cmcp_info->cm_sensor_delta,
  526. configuration->cm_max_delta_sensor_percent);
  527. result->cm_sensor_delta_pass = false;
  528. }
  529. result->cm_test_pass = result->cm_sensor_gd_col_pass
  530. && result->cm_sensor_gd_row_pass
  531. && result->cm_sensor_validation_pass
  532. && result->cm_sensor_row_delta_pass
  533. && result->cm_sensor_col_delta_pass
  534. && result->cm_sensor_calibration_pass
  535. && result->cm_sensor_delta_pass;
  536. }
  537. if (((test_item & CM_BTN) == CM_BTN) && (cmcp_info->btn_num)) {
  538. /* Check each button Cm data for min/max values */
  539. result->cm_button_validation_pass = true;
  540. for (i = 0; i < button_num; i++) {
  541. int32_t cm_button_min =
  542. configuration->cm_min_max_table_btn[i * 2];
  543. int32_t cm_button_max =
  544. configuration->cm_min_max_table_btn[i * 2 + 1];
  545. if ((cm_button_data[i] <= cm_button_min) ||
  546. (cm_button_data[i] >= cm_button_max)) {
  547. pt_debug(dev, DL_DEBUG,
  548. "%s: Button[%d]:%d (%d,%d)\n",
  549. "Cm button min/max test",
  550. i, cm_button_data[i],
  551. cm_button_min, cm_button_max);
  552. result->cm_button_validation_pass = false;
  553. }
  554. }
  555. /* Check button Cm delta for range limit */
  556. result->cm_button_delta_pass = true;
  557. cm_button_delta = ABS((cmcp_info->cm_ave_data_btn -
  558. cmcp_info->cm_cal_data_btn) * 100 /
  559. cmcp_info->cm_ave_data_btn);
  560. if (cm_button_delta >
  561. configuration->cm_max_delta_button_percent) {
  562. pt_debug(dev, DL_INFO,
  563. "%s: Cm_button_delta:%d (%d)\n",
  564. "Cm button delta range limit test",
  565. cm_button_delta,
  566. configuration->cm_max_delta_button_percent);
  567. result->cm_button_delta_pass = false;
  568. }
  569. result->cm_test_pass = result->cm_test_pass &&
  570. result->cm_button_validation_pass &&
  571. result->cm_button_delta_pass;
  572. }
  573. if (pass)
  574. *pass = result->cm_test_pass;
  575. return ret;
  576. }
  577. /*******************************************************************************
  578. * FUNCTION: validate_cp_test_results
  579. *
  580. * SUMMARY: Checks cp test results and outputs each test and a summary result.
  581. *
  582. * RETURN:
  583. * 0 = success
  584. * !0 = failure
  585. *
  586. * PARAMETERS:
  587. * *dev - pointer to device structure
  588. * *configuration - pointer to configuration structure
  589. * *cmcp_info - pointer to cmcp_data structure to store cmcp data from fw
  590. * *result - pointer to result structure
  591. * *pass - pointer to bool value
  592. * test_item - flag to store all test item are requested
  593. ******************************************************************************/
  594. static int validate_cp_test_results(struct device *dev,
  595. struct configuration *configuration, struct cmcp_data *cmcp_info,
  596. struct result *result, bool *pass, int test_item)
  597. {
  598. int i = 0;
  599. uint32_t configuration_rx_num;
  600. uint32_t configuration_tx_num;
  601. int32_t *cp_sensor_tx_data = cmcp_info->cp_tx_data_panel;
  602. int32_t *cp_sensor_rx_data = cmcp_info->cp_rx_data_panel;
  603. int32_t cp_button_delta;
  604. int32_t cp_button_average;
  605. result->cp_test_pass = true;
  606. configuration_rx_num = configuration->cp_min_max_table_rx_size/2;
  607. configuration_tx_num = configuration->cp_min_max_table_tx_size/2;
  608. pt_debug(dev, DL_INFO, "%s start\n", __func__);
  609. if ((test_item & CP_PANEL) == CP_PANEL) {
  610. int32_t cp_sensor_tx_delta;
  611. int32_t cp_sensor_rx_delta;
  612. /* Check Sensor Cp delta for range limit */
  613. result->cp_sensor_delta_pass = true;
  614. /*check cp_sensor_tx_delta */
  615. for (i = 0; i < configuration_tx_num; i++) {
  616. cp_sensor_tx_delta =
  617. ABS((cmcp_info->cp_tx_cal_data_panel[i]-
  618. cmcp_info->cp_tx_data_panel[i]) * 100 /
  619. cmcp_info->cp_tx_data_panel[i]);
  620. if (cp_sensor_tx_delta >
  621. configuration->cp_max_delta_sensor_tx_percent) {
  622. pt_debug(dev, DL_DEBUG,
  623. "%s: Cp_sensor_tx_delta:%d (%d)\n",
  624. "Cp sensor delta range limit test",
  625. cp_sensor_tx_delta,
  626. configuration->cp_max_delta_sensor_tx_percent);
  627. result->cp_sensor_delta_pass = false;
  628. }
  629. }
  630. /*check cp_sensor_rx_delta */
  631. for (i = 0; i < configuration_rx_num; i++) {
  632. cp_sensor_rx_delta =
  633. ABS((cmcp_info->cp_rx_cal_data_panel[i] -
  634. cmcp_info->cp_rx_data_panel[i]) * 100 /
  635. cmcp_info->cp_rx_data_panel[i]);
  636. if (cp_sensor_rx_delta >
  637. configuration->cp_max_delta_sensor_rx_percent) {
  638. pt_debug(dev, DL_DEBUG,
  639. "%s: Cp_sensor_rx_delta:%d(%d)\n",
  640. "Cp sensor delta range limit test",
  641. cp_sensor_rx_delta,
  642. configuration->cp_max_delta_sensor_rx_percent);
  643. result->cp_sensor_delta_pass = false;
  644. }
  645. }
  646. /* Check sensor Cp rx for min/max values */
  647. result->cp_rx_validation_pass = true;
  648. for (i = 0; i < configuration_rx_num; i++) {
  649. int32_t cp_rx_min =
  650. configuration->cp_min_max_table_rx[i * 2];
  651. int32_t cp_rx_max =
  652. configuration->cp_min_max_table_rx[i * 2 + 1];
  653. if ((cp_sensor_rx_data[i] <= cp_rx_min) ||
  654. (cp_sensor_rx_data[i] >= cp_rx_max)) {
  655. pt_debug(dev, DL_DEBUG,
  656. "%s: Cp Rx[%d]:%d (%d,%d)\n",
  657. "Cp Rx min/max test",
  658. i, (int)cp_sensor_rx_data[i],
  659. cp_rx_min, cp_rx_max);
  660. result->cp_rx_validation_pass = false;
  661. }
  662. }
  663. /* Check sensor Cp tx for min/max values */
  664. result->cp_tx_validation_pass = true;
  665. for (i = 0; i < configuration_tx_num; i++) {
  666. int32_t cp_tx_min =
  667. configuration->cp_min_max_table_tx[i * 2];
  668. int32_t cp_tx_max =
  669. configuration->cp_min_max_table_tx[i * 2 + 1];
  670. if ((cp_sensor_tx_data[i] <= cp_tx_min) ||
  671. (cp_sensor_tx_data[i] >= cp_tx_max)) {
  672. pt_debug(dev, DL_DEBUG,
  673. "%s: Cp Tx[%d]:%d(%d,%d)\n",
  674. "Cp Tx min/max test",
  675. i, cp_sensor_tx_data[i],
  676. cp_tx_min, cp_tx_max);
  677. result->cp_tx_validation_pass = false;
  678. }
  679. }
  680. result->cp_test_pass = result->cp_test_pass
  681. && result->cp_sensor_delta_pass
  682. && result->cp_rx_validation_pass
  683. && result->cp_tx_validation_pass;
  684. }
  685. if (((test_item & CP_BTN) == CP_BTN) && (cmcp_info->btn_num)) {
  686. result->cp_button_delta_pass = true;
  687. /* Check button Cp delta for range limit */
  688. cp_button_delta = ABS((cmcp_info->cp_btn_cal
  689. - cmcp_info->cp_button_ave) * 100 /
  690. cmcp_info->cp_button_ave);
  691. if (cp_button_delta >
  692. configuration->cp_max_delta_button_percent) {
  693. pt_debug(dev, DL_INFO,
  694. "%s: Cp_button_delta:%d (%d)\n",
  695. "Cp button delta range limit test",
  696. cp_button_delta,
  697. configuration->cp_max_delta_button_percent);
  698. result->cp_button_delta_pass = false;
  699. }
  700. /* Check button Cp average for min/max values */
  701. result->cp_button_average_pass = true;
  702. cp_button_average = cmcp_info->cp_button_ave;
  703. if (cp_button_average < configuration->min_button ||
  704. cp_button_average > configuration->max_button) {
  705. pt_debug(dev, DL_INFO,
  706. "%s: Button Cp average fails min/max test\n",
  707. __func__);
  708. pt_debug(dev, DL_INFO,
  709. "%s: Cp_button_average:%d (%d,%d)\n",
  710. "Cp button average min/max test",
  711. cp_button_average,
  712. configuration->min_button,
  713. configuration->max_button);
  714. result->cp_button_average_pass = false;
  715. }
  716. /* Check each button Cp data for min/max values */
  717. result->cp_button_validation_pass = true;
  718. for (i = 0; i < cmcp_info->btn_num; i++) {
  719. int32_t cp_button_min =
  720. configuration->cp_min_max_table_btn[i * 2];
  721. int32_t cp_button_max =
  722. configuration->cp_min_max_table_btn[i * 2 + 1];
  723. if ((cmcp_info->cp_btn_data[i] <= cp_button_min) ||
  724. (cmcp_info->cp_btn_data[i] >= cp_button_max)) {
  725. pt_debug(dev, DL_DEBUG,
  726. "%s: Button[%d]:%d (%d,%d)\n",
  727. "Cp button min/max test",
  728. i, cmcp_info->cp_btn_data[i],
  729. cp_button_min, cp_button_max);
  730. result->cp_button_validation_pass = false;
  731. }
  732. }
  733. result->cp_test_pass = result->cp_test_pass
  734. && result->cp_button_delta_pass
  735. && result->cp_button_average_pass
  736. && result->cp_button_validation_pass;
  737. }
  738. if (pass)
  739. *pass = result->cp_test_pass;
  740. return 0;
  741. }
  742. /*******************************************************************************
  743. * FUNCTION: calculate_gradient_row
  744. *
  745. * SUMMARY: Calculates gradient value for rows.
  746. *
  747. * PARAMETERS:
  748. * *gd_sensor_row_head - pointer to gd_sensor structure
  749. * row_num - number of row
  750. * exclude_row_edge - flag to exclude row edge(1:exclude; 0:include)
  751. * exclude_col_edge - flag to exclude column edge(1:exclude; 0:include)
  752. ******************************************************************************/
  753. static void calculate_gradient_row(struct gd_sensor *gd_sensor_row_head,
  754. uint16_t row_num, int exclude_row_edge, int exclude_col_edge)
  755. {
  756. int i = 0;
  757. uint16_t cm_min_cur = 0;
  758. uint16_t cm_max_cur = 0;
  759. uint16_t cm_ave_cur = 0;
  760. uint16_t cm_ave_next = 0;
  761. uint16_t cm_ave_prev = 0;
  762. struct gd_sensor *p = gd_sensor_row_head;
  763. if (exclude_row_edge) {
  764. for (i = 0; i < row_num; i++) {
  765. if (!exclude_col_edge) {
  766. cm_ave_cur = (p + i)->cm_ave;
  767. cm_min_cur = (p + i)->cm_min;
  768. cm_max_cur = (p + i)->cm_max;
  769. if (i < (row_num-1))
  770. cm_ave_next = (p + i+1)->cm_ave;
  771. if (i > 0)
  772. cm_ave_prev = (p + i-1)->cm_ave;
  773. } else {
  774. cm_ave_cur = (p + i)->cm_ave_exclude_edge;
  775. cm_min_cur = (p + i)->cm_min_exclude_edge;
  776. cm_max_cur = (p + i)->cm_max_exclude_edge;
  777. if (i < (row_num-1))
  778. cm_ave_next =
  779. (p + i+1)->cm_ave_exclude_edge;
  780. if (i > 0)
  781. cm_ave_prev =
  782. (p + i-1)->cm_ave_exclude_edge;
  783. }
  784. if (cm_ave_cur == 0)
  785. cm_ave_cur = 1;
  786. /*multiple 1000 to increate accuracy*/
  787. if ((i == 0) || (i == (row_num-1))) {
  788. (p + i)->gradient_val =
  789. (cm_max_cur - cm_min_cur) * 1000 /
  790. cm_ave_cur;
  791. } else if (i == 1) {
  792. (p + i)->gradient_val = (cm_max_cur - cm_min_cur
  793. + ABS(cm_ave_cur - cm_ave_next)) * 1000 /
  794. cm_ave_cur;
  795. } else {
  796. (p + i)->gradient_val = (cm_max_cur - cm_min_cur
  797. + ABS(cm_ave_cur - cm_ave_prev)) * 1000 /
  798. cm_ave_cur;
  799. }
  800. }
  801. } else if (!exclude_row_edge) {
  802. for (i = 0; i < row_num; i++) {
  803. if (!exclude_col_edge) {
  804. cm_ave_cur = (p + i)->cm_ave;
  805. cm_min_cur = (p + i)->cm_min;
  806. cm_max_cur = (p + i)->cm_max;
  807. if (i < (row_num-1))
  808. cm_ave_next = (p + i+1)->cm_ave;
  809. if (i > 0)
  810. cm_ave_prev = (p + i-1)->cm_ave;
  811. } else {
  812. cm_ave_cur = (p + i)->cm_ave_exclude_edge;
  813. cm_min_cur = (p + i)->cm_min_exclude_edge;
  814. cm_max_cur = (p + i)->cm_max_exclude_edge;
  815. if (i < (row_num-1))
  816. cm_ave_next =
  817. (p + i+1)->cm_ave_exclude_edge;
  818. if (i > 0)
  819. cm_ave_prev =
  820. (p + i-1)->cm_ave_exclude_edge;
  821. }
  822. if (cm_ave_cur == 0)
  823. cm_ave_cur = 1;
  824. /*multiple 1000 to increate accuracy*/
  825. if (i <= 1)
  826. (p + i)->gradient_val = (cm_max_cur - cm_min_cur
  827. + ABS(cm_ave_cur - cm_ave_next)) * 1000 /
  828. cm_ave_cur;
  829. else
  830. (p + i)->gradient_val = (cm_max_cur - cm_min_cur
  831. + ABS(cm_ave_cur - cm_ave_prev)) * 1000 /
  832. cm_ave_cur;
  833. }
  834. }
  835. }
  836. /*******************************************************************************
  837. * FUNCTION: calculate_gradient_col
  838. *
  839. * SUMMARY: Calculates gradient value for columns.
  840. *
  841. * PARAMETERS:
  842. * *gd_sensor_row_head - pointer to gd_sensor structure
  843. * col_num - number of column
  844. * exclude_row_edge - flag to exclude row edge(1:exclude; 0:include)
  845. * exclude_col_edge - flag to exclude column edge(1:exclude; 0:include)
  846. ******************************************************************************/
  847. static void calculate_gradient_col(struct gd_sensor *gd_sensor_row_head,
  848. uint16_t col_num, int exclude_row_edge, int exclude_col_edge)
  849. {
  850. int i = 0;
  851. int32_t cm_min_cur = 0;
  852. int32_t cm_max_cur = 0;
  853. int32_t cm_ave_cur = 0;
  854. int32_t cm_ave_next = 0;
  855. int32_t cm_ave_prev = 0;
  856. struct gd_sensor *p = gd_sensor_row_head;
  857. if (!exclude_col_edge) {
  858. for (i = 0; i < col_num; i++) {
  859. if (!exclude_row_edge) {
  860. cm_ave_cur = (p + i)->cm_ave;
  861. cm_min_cur = (p + i)->cm_min;
  862. cm_max_cur = (p + i)->cm_max;
  863. if (i < (col_num-1))
  864. cm_ave_next = (p + i+1)->cm_ave;
  865. if (i > 0)
  866. cm_ave_prev = (p + i-1)->cm_ave;
  867. } else {
  868. cm_ave_cur = (p + i)->cm_ave_exclude_edge;
  869. cm_min_cur = (p + i)->cm_min_exclude_edge;
  870. cm_max_cur = (p + i)->cm_max_exclude_edge;
  871. if (i < (col_num-1))
  872. cm_ave_next =
  873. (p + i+1)->cm_ave_exclude_edge;
  874. if (i > 0)
  875. cm_ave_prev =
  876. (p + i-1)->cm_ave_exclude_edge;
  877. }
  878. if (cm_ave_cur == 0)
  879. cm_ave_cur = 1;
  880. /*multiple 1000 to increate accuracy*/
  881. if (i <= 1)
  882. (p + i)->gradient_val = (cm_max_cur - cm_min_cur
  883. + ABS(cm_ave_cur - cm_ave_next)) * 1000 /
  884. cm_ave_cur;
  885. else
  886. (p + i)->gradient_val = (cm_max_cur - cm_min_cur
  887. + ABS(cm_ave_cur - cm_ave_prev)) * 1000 /
  888. cm_ave_cur;
  889. }
  890. } else if (exclude_col_edge) {
  891. for (i = 0; i < col_num; i++) {
  892. if (!exclude_row_edge) {
  893. cm_ave_cur = (p + i)->cm_ave;
  894. cm_min_cur = (p + i)->cm_min;
  895. cm_max_cur = (p + i)->cm_max;
  896. if (i < (col_num-1))
  897. cm_ave_next = (p + i+1)->cm_ave;
  898. if (i > 0)
  899. cm_ave_prev = (p + i-1)->cm_ave;
  900. } else {
  901. cm_ave_cur = (p + i)->cm_ave_exclude_edge;
  902. cm_min_cur = (p + i)->cm_min_exclude_edge;
  903. cm_max_cur = (p + i)->cm_max_exclude_edge;
  904. if (i < (col_num-1))
  905. cm_ave_next =
  906. (p + i+1)->cm_ave_exclude_edge;
  907. if (i > 0)
  908. cm_ave_prev =
  909. (p + i-1)->cm_ave_exclude_edge;
  910. }
  911. if (cm_ave_cur == 0)
  912. cm_ave_cur = 1;
  913. /*multiple 1000 to increate accuracy*/
  914. if ((i == 0) || (i == (col_num - 1)))
  915. (p + i)->gradient_val =
  916. (cm_max_cur - cm_min_cur) * 1000 /
  917. cm_ave_cur;
  918. else if (i == 1)
  919. (p + i)->gradient_val =
  920. (cm_max_cur - cm_min_cur +
  921. ABS(cm_ave_cur - cm_ave_next))
  922. * 1000 / cm_ave_cur;
  923. else
  924. (p + i)->gradient_val =
  925. (cm_max_cur - cm_min_cur +
  926. ABS(cm_ave_cur - cm_ave_prev))
  927. * 1000 / cm_ave_cur;
  928. }
  929. }
  930. }
  931. /*******************************************************************************
  932. * FUNCTION: fill_gd_sensor_table
  933. *
  934. * SUMMARY: Fills cm calculation result and exclude parameter to gd_sensor
  935. * structure.
  936. *
  937. * PARAMETERS:
  938. * *head - pointer to gd_sensor structure
  939. * index - index of row or column
  940. * cm_max - maximum of cm
  941. * cm_min - minmum of cm
  942. * cm_ave - average of cm
  943. * cm_max_exclude_edge - maximum of cm without edge data
  944. * cm_min_exclude_edge - minmum of cm without edge data
  945. * cm_ave_exclude_edge - average of cm without edge data
  946. ******************************************************************************/
  947. static void fill_gd_sensor_table(struct gd_sensor *head, int32_t index,
  948. int32_t cm_max, int32_t cm_min, int32_t cm_ave,
  949. int32_t cm_max_exclude_edge, int32_t cm_min_exclude_edge,
  950. int32_t cm_ave_exclude_edge)
  951. {
  952. (head + index)->cm_max = cm_max;
  953. (head + index)->cm_min = cm_min;
  954. (head + index)->cm_ave = cm_ave;
  955. (head + index)->cm_ave_exclude_edge = cm_ave_exclude_edge;
  956. (head + index)->cm_max_exclude_edge = cm_max_exclude_edge;
  957. (head + index)->cm_min_exclude_edge = cm_min_exclude_edge;
  958. }
  959. /*******************************************************************************
  960. * FUNCTION: calculate_gd_info
  961. *
  962. * SUMMARY: Calculates gradient panel sensor column and row by calling
  963. * function calculate_gradient_col() & calculate_gradient_row().
  964. *
  965. * PARAMETERS:
  966. * *head - pointer to gd_sensor structure
  967. * index - index of row or column
  968. * cm_max - maximum of cm
  969. * cm_min - minmum of cm
  970. * cm_ave - average of cm
  971. * cm_max_exclude_edge - maximum of cm without edge data
  972. * cm_min_exclude_edge - minmum of cm without edge data
  973. * cm_ave_exclude_edge - average of cm without edge data
  974. ******************************************************************************/
  975. static void calculate_gd_info(struct gd_sensor *gd_sensor_col,
  976. struct gd_sensor *gd_sensor_row, int tx_num, int rx_num,
  977. int32_t *cm_sensor_data, int cm_excluding_row_edge,
  978. int cm_excluding_col_edge)
  979. {
  980. int32_t cm_max;
  981. int32_t cm_min;
  982. int32_t cm_ave;
  983. int32_t cm_max_exclude_edge;
  984. int32_t cm_min_exclude_edge;
  985. int32_t cm_ave_exclude_edge;
  986. int32_t cm_data;
  987. int i;
  988. int j;
  989. /*calculate all the gradient related info for column*/
  990. for (i = 0; i < tx_num; i++) {
  991. /*re-initialize for a new col*/
  992. cm_max = cm_sensor_data[i * rx_num];
  993. cm_min = cm_max;
  994. cm_ave = 0;
  995. cm_max_exclude_edge = cm_sensor_data[i * rx_num + 1];
  996. cm_min_exclude_edge = cm_max_exclude_edge;
  997. cm_ave_exclude_edge = 0;
  998. for (j = 0; j < rx_num; j++) {
  999. cm_data = cm_sensor_data[i * rx_num + j];
  1000. if (cm_data > cm_max)
  1001. cm_max = cm_data;
  1002. if (cm_data < cm_min)
  1003. cm_min = cm_data;
  1004. cm_ave += cm_data;
  1005. /*calculate exclude edge data*/
  1006. if ((j > 0) && (j < (rx_num-1))) {
  1007. if (cm_data > cm_max_exclude_edge)
  1008. cm_max_exclude_edge = cm_data;
  1009. if (cm_data < cm_min_exclude_edge)
  1010. cm_min_exclude_edge = cm_data;
  1011. cm_ave_exclude_edge += cm_data;
  1012. }
  1013. }
  1014. cm_ave /= rx_num;
  1015. cm_ave_exclude_edge /= (rx_num-2);
  1016. fill_gd_sensor_table(gd_sensor_col, i, cm_max, cm_min, cm_ave,
  1017. cm_max_exclude_edge, cm_min_exclude_edge, cm_ave_exclude_edge);
  1018. }
  1019. calculate_gradient_col(gd_sensor_col, tx_num, cm_excluding_row_edge,
  1020. cm_excluding_col_edge);
  1021. /*calculate all the gradient related info for row*/
  1022. for (j = 0; j < rx_num; j++) {
  1023. /*re-initialize for a new row*/
  1024. cm_max = cm_sensor_data[j];
  1025. cm_min = cm_max;
  1026. cm_ave = 0;
  1027. cm_max_exclude_edge = cm_sensor_data[rx_num + j];
  1028. cm_min_exclude_edge = cm_max_exclude_edge;
  1029. cm_ave_exclude_edge = 0;
  1030. for (i = 0; i < tx_num; i++) {
  1031. cm_data = cm_sensor_data[i * rx_num + j];
  1032. if (cm_data > cm_max)
  1033. cm_max = cm_data;
  1034. if (cm_data < cm_min)
  1035. cm_min = cm_data;
  1036. cm_ave += cm_data;
  1037. /*calculate exclude edge data*/
  1038. if ((i > 0) && (i < (tx_num-1))) {
  1039. if (cm_data > cm_max_exclude_edge)
  1040. cm_max_exclude_edge = cm_data;
  1041. if (cm_data < cm_min_exclude_edge)
  1042. cm_min_exclude_edge = cm_data;
  1043. cm_ave_exclude_edge += cm_data;
  1044. }
  1045. }
  1046. cm_ave /= tx_num;
  1047. cm_ave_exclude_edge /= (tx_num-2);
  1048. fill_gd_sensor_table(gd_sensor_row, j, cm_max, cm_min, cm_ave,
  1049. cm_max_exclude_edge, cm_min_exclude_edge, cm_ave_exclude_edge);
  1050. }
  1051. calculate_gradient_row(gd_sensor_row, rx_num, cm_excluding_row_edge,
  1052. cm_excluding_col_edge);
  1053. }
  1054. /*******************************************************************************
  1055. * FUNCTION: pt_get_cmcp_info
  1056. *
  1057. * SUMMARY: Function to include following work:
  1058. * 1) run short test and get result
  1059. * 2) run selftest to get cm_panel data, cm_cal_data_panel data, calculate
  1060. * cm_ave_data_panel, cm_sensor_delta and gradient by column and row.
  1061. * 3) run selftest to get cp_panel data, cp_cal_data_panel data, cacluate
  1062. * cp_ave_data_panel, cp_sensor_delta for tx and rx.
  1063. * 4) run selftest to get cm_btn data, cm_cal_data_btn data, cacluate
  1064. * cm_delta_data_btn data, cm_ave_data_btn data.
  1065. * 5) run selftest to get cp_btn data, cp_btn_cal data, cacluate
  1066. * cp_button_delta data, cp_button_ave data.
  1067. *
  1068. * RETURN:
  1069. * 0 = success
  1070. * !0 = failure
  1071. *
  1072. * PARAMETERS:
  1073. * *dad - pointer to pt_device_access_data structure
  1074. * *cmcp_info - pointer to cmcp_data structure
  1075. ******************************************************************************/
  1076. static int pt_get_cmcp_info(struct pt_device_access_data *dad,
  1077. struct cmcp_data *cmcp_info)
  1078. {
  1079. struct device *dev;
  1080. int32_t *cm_data_panel = cmcp_info->cm_data_panel;
  1081. int32_t *cp_tx_data_panel = cmcp_info->cp_tx_data_panel;
  1082. int32_t *cp_rx_data_panel = cmcp_info->cp_rx_data_panel;
  1083. int32_t *cp_tx_cal_data_panel = cmcp_info->cp_tx_cal_data_panel;
  1084. int32_t *cp_rx_cal_data_panel = cmcp_info->cp_rx_cal_data_panel;
  1085. int32_t *cm_btn_data = cmcp_info->cm_btn_data;
  1086. int32_t *cp_btn_data = cmcp_info->cp_btn_data;
  1087. struct gd_sensor *gd_sensor_col = cmcp_info->gd_sensor_col;
  1088. struct gd_sensor *gd_sensor_row = cmcp_info->gd_sensor_row;
  1089. struct result *result = dad->result;
  1090. int32_t cp_btn_cal = 0;
  1091. int32_t cp_btn_ave = 0;
  1092. int32_t cm_ave_data_panel = 0;
  1093. int32_t cm_ave_data_btn = 0;
  1094. int32_t cp_tx_ave_data_panel = 0;
  1095. int32_t cp_rx_ave_data_panel = 0;
  1096. u8 tmp_buf[3];
  1097. int tx_num;
  1098. int rx_num;
  1099. int btn_num;
  1100. int rc = 0;
  1101. int i;
  1102. dev = dad->dev;
  1103. cmcp_info->tx_num = dad->si->sensing_conf_data.tx_num;
  1104. cmcp_info->rx_num = dad->si->sensing_conf_data.rx_num;
  1105. cmcp_info->btn_num = dad->si->num_btns;
  1106. tx_num = cmcp_info->tx_num;
  1107. rx_num = cmcp_info->rx_num;
  1108. btn_num = cmcp_info->btn_num;
  1109. pt_debug(dev, DL_INFO, "%s tx_num=%d", __func__, tx_num);
  1110. pt_debug(dev, DL_INFO, "%s rx_num=%d", __func__, rx_num);
  1111. pt_debug(dev, DL_INFO, "%s btn_num=%d", __func__, btn_num);
  1112. /*short test*/
  1113. result->short_test_pass = true;
  1114. rc = pt_run_and_get_selftest_result(dev, PT_CORE_CMD_UNPROTECTED,
  1115. tmp_buf, sizeof(tmp_buf),
  1116. PT_ST_ID_AUTOSHORTS, PIP_CMD_MAX_LENGTH,
  1117. PT_ST_DONT_GET_RESULTS, PT_ST_NOPRINT, PT_PR_FORMAT_DEFAULT);
  1118. if (rc) {
  1119. pt_debug(dev, DL_ERROR, "short test not supported");
  1120. goto exit;
  1121. }
  1122. if (dad->ic_buf[1] != 0)
  1123. result->short_test_pass = false;
  1124. /*Get cm_panel data*/
  1125. rc = pt_run_and_get_selftest_result(dev, PT_CORE_CMD_UNPROTECTED,
  1126. tmp_buf, sizeof(tmp_buf),
  1127. PT_ST_ID_CM_PANEL, PIP_CMD_MAX_LENGTH,
  1128. PT_ST_GET_RESULTS, PT_ST_NOPRINT, PT_PR_FORMAT_DEFAULT);
  1129. if (rc) {
  1130. pt_debug(dev, DL_ERROR, "Get CM Panel not supported");
  1131. goto exit;
  1132. }
  1133. if (cm_data_panel != NULL) {
  1134. for (i = 0; i < tx_num * rx_num; i++) {
  1135. cm_data_panel[i] =
  1136. 10*(dad->ic_buf[CM_PANEL_DATA_OFFSET+i*2] + 256
  1137. * dad->ic_buf[CM_PANEL_DATA_OFFSET+i*2+1]);
  1138. pt_debug(dev, DL_DEBUG,
  1139. "cm_data_panel[%d]=%d\n",
  1140. i, cm_data_panel[i]);
  1141. cm_ave_data_panel += cm_data_panel[i];
  1142. }
  1143. cm_ave_data_panel /= (tx_num * rx_num);
  1144. cmcp_info->cm_ave_data_panel = cm_ave_data_panel;
  1145. }
  1146. /* Calculate gradient panel sensor column/row here */
  1147. calculate_gd_info(gd_sensor_col, gd_sensor_row, tx_num, rx_num,
  1148. cm_data_panel, 1, 1);
  1149. for (i = 0; i < tx_num; i++) {
  1150. pt_debug(dev, DL_DEBUG,
  1151. "i=%d max=%d,min=%d,ave=%d, gradient=%d", i,
  1152. gd_sensor_col[i].cm_max,
  1153. gd_sensor_col[i].cm_min,
  1154. gd_sensor_col[i].cm_ave,
  1155. gd_sensor_col[i].gradient_val);
  1156. }
  1157. for (i = 0; i < rx_num; i++) {
  1158. pt_debug(dev, DL_DEBUG,
  1159. "i=%d max=%d,min=%d,ave=%d, gradient=%d", i,
  1160. gd_sensor_row[i].cm_max,
  1161. gd_sensor_row[i].cm_min,
  1162. gd_sensor_row[i].cm_ave,
  1163. gd_sensor_row[i].gradient_val);
  1164. }
  1165. /*Get cp data*/
  1166. rc = pt_run_and_get_selftest_result(dev, PT_CORE_CMD_UNPROTECTED,
  1167. tmp_buf, sizeof(tmp_buf),
  1168. PT_ST_ID_CP_PANEL, PIP_CMD_MAX_LENGTH,
  1169. PT_ST_GET_RESULTS, PT_ST_NOPRINT, PT_PR_FORMAT_DEFAULT);
  1170. if (rc) {
  1171. pt_debug(dev, DL_ERROR, "Get CP Panel not supported");
  1172. goto exit;
  1173. }
  1174. /*Get cp_tx_data_panel*/
  1175. if (cp_tx_data_panel != NULL) {
  1176. for (i = 0; i < tx_num; i++) {
  1177. cp_tx_data_panel[i] =
  1178. 10*(dad->ic_buf[CP_PANEL_DATA_OFFSET+i*2]
  1179. + 256 * dad->ic_buf[CP_PANEL_DATA_OFFSET+i*2+1]);
  1180. pt_debug(dev, DL_DEBUG,
  1181. "cp_tx_data_panel[%d]=%d\n",
  1182. i, cp_tx_data_panel[i]);
  1183. cp_tx_ave_data_panel += cp_tx_data_panel[i];
  1184. }
  1185. cp_tx_ave_data_panel /= tx_num;
  1186. cmcp_info->cp_tx_ave_data_panel = cp_tx_ave_data_panel;
  1187. }
  1188. /*Get cp_tx_cal_data_panel*/
  1189. if (cp_tx_cal_data_panel != NULL) {
  1190. for (i = 0; i < tx_num; i++) {
  1191. cp_tx_cal_data_panel[i] =
  1192. 10*(dad->ic_buf[CP_PANEL_DATA_OFFSET+tx_num*2+i*2]
  1193. + 256 * dad->ic_buf[CP_PANEL_DATA_OFFSET+tx_num*2+i*2+1]);
  1194. pt_debug(dev, DL_DEBUG, "cp_tx_cal_data_panel[%d]=%d\n",
  1195. i, cp_tx_cal_data_panel[i]);
  1196. }
  1197. }
  1198. /*get cp_sensor_tx_delta,using the first sensor cal value for temp */
  1199. /*multiple 1000 to increase accuracy*/
  1200. cmcp_info->cp_sensor_tx_delta = ABS((cp_tx_cal_data_panel[0]
  1201. - cp_tx_ave_data_panel) * 1000 / cp_tx_ave_data_panel);
  1202. /*Get cp_rx_data_panel*/
  1203. if (cp_rx_data_panel != NULL) {
  1204. for (i = 0; i < rx_num; i++) {
  1205. cp_rx_data_panel[i] =
  1206. 10*(dad->ic_buf[CP_PANEL_DATA_OFFSET+tx_num*4+i*2] +
  1207. 256 * dad->ic_buf[CP_PANEL_DATA_OFFSET+tx_num*4+i*2+1]);
  1208. pt_debug(dev, DL_DEBUG,
  1209. "cp_rx_data_panel[%d]=%d\n", i,
  1210. cp_rx_data_panel[i]);
  1211. cp_rx_ave_data_panel += cp_rx_data_panel[i];
  1212. }
  1213. cp_rx_ave_data_panel /= rx_num;
  1214. cmcp_info->cp_rx_ave_data_panel = cp_rx_ave_data_panel;
  1215. }
  1216. /*Get cp_rx_cal_data_panel*/
  1217. if (cp_rx_cal_data_panel != NULL) {
  1218. for (i = 0; i < rx_num; i++) {
  1219. cp_rx_cal_data_panel[i] =
  1220. 10 * (dad->ic_buf[CP_PANEL_DATA_OFFSET+tx_num*4+rx_num*2+i*2] +
  1221. 256 *
  1222. dad->ic_buf[CP_PANEL_DATA_OFFSET+tx_num*4+rx_num*2+i*2+1]);
  1223. pt_debug(dev, DL_DEBUG,
  1224. "cp_rx_cal_data_panel[%d]=%d\n", i,
  1225. cp_rx_cal_data_panel[i]);
  1226. }
  1227. }
  1228. /*get cp_sensor_rx_delta,using the first sensor cal value for temp */
  1229. /*multiple 1000 to increase accuracy*/
  1230. cmcp_info->cp_sensor_rx_delta = ABS((cp_rx_cal_data_panel[0]
  1231. - cp_rx_ave_data_panel) * 1000 / cp_rx_ave_data_panel);
  1232. if (btn_num == 0) {
  1233. pt_debug(dev, DL_INFO, "%s: Skip Button Test\n", __func__);
  1234. goto skip_button_test;
  1235. }
  1236. /*get cm btn data*/
  1237. rc = pt_run_and_get_selftest_result(dev, PT_CORE_CMD_UNPROTECTED,
  1238. tmp_buf, sizeof(tmp_buf),
  1239. PT_ST_ID_CM_BUTTON, PIP_CMD_MAX_LENGTH,
  1240. PT_ST_GET_RESULTS, PT_ST_NOPRINT, PT_PR_FORMAT_DEFAULT);
  1241. if (rc) {
  1242. pt_debug(dev, DL_ERROR, "Get CM BTN not supported");
  1243. goto exit;
  1244. }
  1245. if (cm_btn_data != NULL) {
  1246. for (i = 0; i < btn_num; i++) {
  1247. cm_btn_data[i] =
  1248. 10 * (dad->ic_buf[CM_BTN_DATA_OFFSET+i*2] +
  1249. 256 * dad->ic_buf[CM_BTN_DATA_OFFSET+i*2+1]);
  1250. pt_debug(dev, DL_DEBUG,
  1251. " cm_btn_data[%d]=%d\n",
  1252. i, cm_btn_data[i]);
  1253. cm_ave_data_btn += cm_btn_data[i];
  1254. }
  1255. cm_ave_data_btn /= btn_num;
  1256. cmcp_info->cm_ave_data_btn = cm_ave_data_btn;
  1257. }
  1258. /*get cp btn data*/
  1259. rc = pt_run_and_get_selftest_result(dev, PT_CORE_CMD_UNPROTECTED,
  1260. tmp_buf, sizeof(tmp_buf),
  1261. PT_ST_ID_CP_BUTTON, PIP_CMD_MAX_LENGTH,
  1262. PT_ST_GET_RESULTS, PT_ST_NOPRINT, PT_PR_FORMAT_DEFAULT);
  1263. if (rc) {
  1264. pt_debug(dev, DL_ERROR, "Get CP BTN not supported");
  1265. goto exit;
  1266. }
  1267. if (cp_btn_data != NULL) {
  1268. for (i = 0; i < btn_num; i++) {
  1269. cp_btn_data[i] =
  1270. 10 * (dad->ic_buf[CP_BTN_DATA_OFFSET+i*2] +
  1271. 256 * dad->ic_buf[CP_BTN_DATA_OFFSET+i*2+1]);
  1272. cp_btn_ave += cp_btn_data[i];
  1273. pt_debug(dev, DL_DEBUG,
  1274. "cp_btn_data[%d]=%d\n",
  1275. i, cp_btn_data[i]);
  1276. }
  1277. cp_btn_ave /= btn_num;
  1278. cp_btn_cal = 10*(dad->ic_buf[CP_BTN_DATA_OFFSET+i*2]
  1279. + 256 * dad->ic_buf[CP_BTN_DATA_OFFSET+i*2+1]);
  1280. cmcp_info->cp_button_ave = cp_btn_ave;
  1281. cmcp_info->cp_btn_cal = cp_btn_cal;
  1282. /*multiple 1000 to increase accuracy*/
  1283. cmcp_info->cp_button_delta = ABS((cp_btn_cal
  1284. - cp_btn_ave) * 1000 / cp_btn_ave);
  1285. pt_debug(dev, DL_INFO, " cp_btn_cal=%d\n",
  1286. cp_btn_cal);
  1287. pt_debug(dev, DL_INFO, " cp_btn_ave=%d\n",
  1288. cp_btn_ave);
  1289. }
  1290. skip_button_test:
  1291. exit:
  1292. return rc;
  1293. }
  1294. /*******************************************************************************
  1295. * FUNCTION: pt_get_cm_cal
  1296. *
  1297. * SUMMARY: Function to include following work:
  1298. * 1) run selftest to get cm_cal_data_panel, cm_sensor_delta
  1299. * 2) run selftest to get cm_cal_data_btn, cm_delta_data_btn
  1300. *
  1301. * NOTE:
  1302. * This function depends on the calculation result of pt_get_cmcp_info()
  1303. *
  1304. * RETURN:
  1305. * 0 = success
  1306. * !0 = failure
  1307. *
  1308. * PARAMETERS:
  1309. * *dad - pointer to pt_device_access_data structure
  1310. * *cmcp_info - pointer to cmcp_data structure
  1311. ******************************************************************************/
  1312. static int pt_get_cm_cal(struct pt_device_access_data *dad,
  1313. struct cmcp_data *cmcp_info)
  1314. {
  1315. struct device *dev;
  1316. int32_t *cm_data_panel = cmcp_info->cm_data_panel;
  1317. int32_t *cm_btn_data = cmcp_info->cm_btn_data;
  1318. u8 tmp_buf[3];
  1319. int rc = 0;
  1320. int i;
  1321. dev = dad->dev;
  1322. /*Get cm_cal data*/
  1323. rc = pt_run_and_get_selftest_result(dev, PT_CORE_CMD_UNPROTECTED,
  1324. tmp_buf, sizeof(tmp_buf),
  1325. PT_ST_ID_CM_PANEL, PIP_CMD_MAX_LENGTH,
  1326. PT_ST_GET_RESULTS, PT_ST_NOPRINT, PT_PR_FORMAT_DEFAULT);
  1327. if (rc) {
  1328. pt_debug(dev, DL_ERROR, "Get CM Panel not supported");
  1329. goto exit;
  1330. }
  1331. if (cm_data_panel != NULL) {
  1332. i = cmcp_info->tx_num * cmcp_info->rx_num;
  1333. cmcp_info->cm_cal_data_panel =
  1334. 10 * (dad->ic_buf[CM_PANEL_DATA_OFFSET + i * 2] +
  1335. 256 * dad->ic_buf[CM_PANEL_DATA_OFFSET + i * 2 + 1]);
  1336. /*multiple 1000 to increase accuracy*/
  1337. cmcp_info->cm_sensor_delta =
  1338. ABS((cmcp_info->cm_ave_data_panel -
  1339. cmcp_info->cm_cal_data_panel) *
  1340. 1000 / cmcp_info->cm_ave_data_panel);
  1341. }
  1342. if (cmcp_info->btn_num == 0) {
  1343. pt_debug(dev, DL_INFO, "%s: Skip Button Test\n", __func__);
  1344. goto skip_button_test;
  1345. }
  1346. /*get cm_btn_cal data*/
  1347. rc = pt_run_and_get_selftest_result(dev, PT_CORE_CMD_UNPROTECTED,
  1348. tmp_buf, sizeof(tmp_buf),
  1349. PT_ST_ID_CM_BUTTON, PIP_CMD_MAX_LENGTH,
  1350. PT_ST_GET_RESULTS, PT_ST_NOPRINT, PT_PR_FORMAT_DEFAULT);
  1351. if (rc) {
  1352. pt_debug(dev, DL_ERROR, "Get CM BTN not supported");
  1353. goto exit;
  1354. }
  1355. if (cm_btn_data != NULL) {
  1356. i = cmcp_info->btn_num;
  1357. cmcp_info->cm_cal_data_btn =
  1358. 10 * (dad->ic_buf[CM_BTN_DATA_OFFSET + i * 2] +
  1359. 256 * dad->ic_buf[CM_BTN_DATA_OFFSET + i * 2 + 1]);
  1360. /*multiple 1000 to increase accuracy*/
  1361. cmcp_info->cm_delta_data_btn = ABS(
  1362. (cmcp_info->cm_ave_data_btn - cmcp_info->cm_cal_data_btn) *
  1363. 1000 / cmcp_info->cm_ave_data_btn);
  1364. pt_debug(dev, DL_INFO, " cm_btn_cal=%d\n",
  1365. cmcp_info->cm_cal_data_btn);
  1366. }
  1367. skip_button_test:
  1368. exit:
  1369. return rc;
  1370. }
  1371. /*******************************************************************************
  1372. * FUNCTION: pt_free_cmcp_buf
  1373. *
  1374. * SUMMARY: Free pointers in cmcp_data structure
  1375. *
  1376. * PARAMETERS:
  1377. * *cmcp_info - pointer to cmcp_data structure
  1378. ******************************************************************************/
  1379. static void pt_free_cmcp_buf(struct cmcp_data *cmcp_info)
  1380. {
  1381. if (cmcp_info->gd_sensor_col != NULL)
  1382. kfree(cmcp_info->gd_sensor_col);
  1383. if (cmcp_info->gd_sensor_row != NULL)
  1384. kfree(cmcp_info->gd_sensor_row);
  1385. if (cmcp_info->cm_data_panel != NULL)
  1386. kfree(cmcp_info->cm_data_panel);
  1387. if (cmcp_info->cp_tx_data_panel != NULL)
  1388. kfree(cmcp_info->cp_tx_data_panel);
  1389. if (cmcp_info->cp_rx_data_panel != NULL)
  1390. kfree(cmcp_info->cp_rx_data_panel);
  1391. if (cmcp_info->cp_tx_cal_data_panel != NULL)
  1392. kfree(cmcp_info->cp_tx_cal_data_panel);
  1393. if (cmcp_info->cp_rx_cal_data_panel != NULL)
  1394. kfree(cmcp_info->cp_rx_cal_data_panel);
  1395. if (cmcp_info->cm_btn_data != NULL)
  1396. kfree(cmcp_info->cm_btn_data);
  1397. if (cmcp_info->cp_btn_data != NULL)
  1398. kfree(cmcp_info->cp_btn_data);
  1399. if (cmcp_info->cm_sensor_column_delta != NULL)
  1400. kfree(cmcp_info->cm_sensor_column_delta);
  1401. if (cmcp_info->cm_sensor_row_delta != NULL)
  1402. kfree(cmcp_info->cm_sensor_row_delta);
  1403. }
  1404. /*******************************************************************************
  1405. * FUNCTION: pt_cmcp_get_test_item
  1406. *
  1407. * SUMMARY: Parses enum cmcp_test_item to integer value test_item as bitwise
  1408. * type.
  1409. *
  1410. * RETURN: integer value to indidate available test item with bitwise type
  1411. *
  1412. * PARAMETERS:
  1413. * item_input - enum cmcp_test_item
  1414. ******************************************************************************/
  1415. static int pt_cmcp_get_test_item(int item_input)
  1416. {
  1417. int test_item = 0;
  1418. switch (item_input) {
  1419. case CMCP_FULL:
  1420. test_item = CMCP_FULL_CASE;
  1421. break;
  1422. case CMCP_CM_PANEL:
  1423. test_item = CM_PANEL;
  1424. break;
  1425. case CMCP_CP_PANEL:
  1426. test_item = CP_PANEL;
  1427. break;
  1428. case CMCP_CM_BTN:
  1429. test_item = CM_BTN;
  1430. break;
  1431. case CMCP_CP_BTN:
  1432. test_item = CP_BTN;
  1433. break;
  1434. }
  1435. return test_item;
  1436. }
  1437. /*******************************************************************************
  1438. * FUNCTION: pt_cmcp_test_show
  1439. *
  1440. * SUMMARY: Show method for cmcp_test sysfs node. Allows to perform cmcp test
  1441. * with following steps:
  1442. * 1) Get cmcp test items which from threhold file
  1443. * 2) Check whether cmcp test items match with firmware
  1444. * 3) Set parameter to force single TX
  1445. * 4) Do calibration if requested
  1446. * 5) Get all cmcp data from FW and do calculation
  1447. * 6) Set parameter to restore to multi tx
  1448. * 7) Do calibration if requested
  1449. * 8) Check scan state,try to fix if it is not right
  1450. * 9) Start watchdog
  1451. * 10) Validate cm and cp test results if requested
  1452. * 11) Fill the test result
  1453. *
  1454. * RETURN:
  1455. * 0 = success
  1456. * !0 = failure
  1457. *
  1458. * PARAMETERS:
  1459. * *dev - pointer to device structure
  1460. * *attr - pointer to device attributes
  1461. * *buf - pointer to output buffer
  1462. ******************************************************************************/
  1463. static ssize_t pt_cmcp_test_show(struct device *dev,
  1464. struct device_attribute *attr, char *buf)
  1465. {
  1466. struct pt_device_access_data *dad
  1467. = pt_get_device_access_data(dev);
  1468. struct cmcp_data *cmcp_info = dad->cmcp_info;
  1469. struct result *result = dad->result;
  1470. struct configuration *configuration = dad->configs;
  1471. bool final_pass = true;
  1472. static const char * const cmcp_test_case_array[] = {"Full Cm/Cp test",
  1473. "Cm panel test", "Cp panel test",
  1474. "Cm button test", "Cp button test"};
  1475. int index = 0;
  1476. int test_item = 0;
  1477. int no_builtin_file = 0;
  1478. int rc = 0;
  1479. int self_test_result_1 = 0;
  1480. int self_test_result_2 = 0;
  1481. u8 sys_mode = FW_SYS_MODE_UNDEFINED;
  1482. u8 retry = 3;
  1483. dev = dad->dev;
  1484. if ((configuration == NULL) || (cmcp_info == NULL))
  1485. goto exit;
  1486. mutex_lock(&dad->sysfs_lock);
  1487. if (dad->cmcp_test_in_progress) {
  1488. mutex_unlock(&dad->sysfs_lock);
  1489. goto cmcp_not_ready;
  1490. }
  1491. dad->cmcp_test_in_progress = 1;
  1492. dad->test_executed = 0;
  1493. test_item = pt_cmcp_get_test_item(dad->cmcp_test_items);
  1494. if (dad->builtin_cmcp_threshold_status < 0) {
  1495. pt_debug(dev, DL_WARN, "%s: No cmcp threshold file.\n",
  1496. __func__);
  1497. no_builtin_file = 1;
  1498. mutex_unlock(&dad->sysfs_lock);
  1499. goto start_testing;
  1500. }
  1501. if (dad->cmcp_test_items < 0) {
  1502. pt_debug(dev, DL_ERROR,
  1503. "%s: Invalid test item! Should be 0~4!\n", __func__);
  1504. mutex_unlock(&dad->sysfs_lock);
  1505. goto invalid_item;
  1506. }
  1507. pt_debug(dev, DL_INFO, "%s: Test item is %s, %d\n",
  1508. __func__, cmcp_test_case_array[dad->cmcp_test_items],
  1509. test_item);
  1510. if ((dad->si->num_btns == 0)
  1511. && ((dad->cmcp_test_items == CMCP_CM_BTN)
  1512. || (dad->cmcp_test_items == CMCP_CP_BTN))) {
  1513. pt_debug(dev, DL_WARN,
  1514. "%s: FW doesn't support button!\n", __func__);
  1515. mutex_unlock(&dad->sysfs_lock);
  1516. goto invalid_item_btn;
  1517. }
  1518. mutex_unlock(&dad->sysfs_lock);
  1519. if (cmcp_check_config_fw_match(dev, configuration))
  1520. goto mismatch;
  1521. start_testing:
  1522. pt_debug(dev, DL_INFO, "%s: Start Cm/Cp test!\n", __func__);
  1523. result->cm_test_pass = true;
  1524. result->cp_test_pass = true;
  1525. /*stop watchdog*/
  1526. rc = cmd->request_stop_wd(dev);
  1527. if (rc)
  1528. pt_debug(dev, DL_ERROR, "stop watchdog failed");
  1529. /* Make sure the device is awake */
  1530. pm_runtime_get_sync(dev);
  1531. /* Resource protect */
  1532. rc = cmd->request_exclusive(dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
  1533. if (rc) {
  1534. pt_debug(dev, DL_ERROR,
  1535. "%s: Error on request exclusive rc = %d\n",
  1536. __func__, rc);
  1537. }
  1538. /*force single tx*/
  1539. rc = cmd->nonhid_cmd->set_param(dev,
  1540. PT_CORE_CMD_UNPROTECTED, 0x1F, 1, 1);
  1541. if (rc)
  1542. pt_debug(dev, DL_ERROR, "force single tx failed");
  1543. /*suspend_scanning */
  1544. rc = cmd->nonhid_cmd->suspend_scanning(dev, PT_CORE_CMD_UNPROTECTED);
  1545. if (rc)
  1546. pt_debug(dev, DL_ERROR, "suspend_scanning failed");
  1547. /* Do calibration if requested */
  1548. if (!dad->cmcp_force_calibrate) {
  1549. pt_debug(dev, DL_INFO, "do calibration in single tx mode");
  1550. rc = pt_perform_calibration(dev);
  1551. if (rc)
  1552. pt_debug(dev, DL_ERROR, "calibration failed");
  1553. }
  1554. /*resume_scanning */
  1555. rc = cmd->nonhid_cmd->resume_scanning(dev, PT_CORE_CMD_UNPROTECTED);
  1556. if (rc)
  1557. pt_debug(dev, DL_ERROR, "resume_scanning failed");
  1558. /*get all cmcp data from FW*/
  1559. self_test_result_1 = pt_get_cmcp_info(dad, cmcp_info);
  1560. if (self_test_result_1)
  1561. pt_debug(dev, DL_ERROR, "pt_get_cmcp_info failed");
  1562. /*restore to multi tx*/
  1563. rc = cmd->nonhid_cmd->set_param(dev,
  1564. PT_CORE_CMD_UNPROTECTED, 0x1F, 0, 1);
  1565. if (rc)
  1566. pt_debug(dev, DL_ERROR, "restore multi tx failed");
  1567. /*suspend_scanning */
  1568. rc = cmd->nonhid_cmd->suspend_scanning(dev, 0);
  1569. if (rc)
  1570. pt_debug(dev, DL_ERROR, "suspend_scanning failed");
  1571. /* Do calibration if requested */
  1572. if (!dad->cmcp_force_calibrate) {
  1573. pt_debug(dev, DL_INFO, "do calibration in multi tx mode");
  1574. rc = pt_perform_calibration(dev);
  1575. if (rc)
  1576. pt_debug(dev, DL_ERROR, "calibration failed");
  1577. }
  1578. /*resume_scanning */
  1579. rc = cmd->nonhid_cmd->resume_scanning(dev, PT_CORE_CMD_UNPROTECTED);
  1580. if (rc)
  1581. pt_debug(dev, DL_ERROR, "resume_scanning failed");
  1582. /*get cm cal data from FW*/
  1583. self_test_result_2 = pt_get_cm_cal(dad, cmcp_info);
  1584. if (self_test_result_2)
  1585. pt_debug(dev, DL_ERROR, "pt_get_cm_cal failed");
  1586. /* check scan state,try to fix if it is not right*/
  1587. while (retry--) {
  1588. rc = cmd->request_get_fw_mode(dev, PT_CORE_CMD_UNPROTECTED,
  1589. &sys_mode, NULL);
  1590. if (sys_mode != FW_SYS_MODE_SCANNING) {
  1591. pt_debug(dev, DL_ERROR,
  1592. "%s: fw mode: %d, retry: %d, rc = %d\n",
  1593. __func__, sys_mode, retry, rc);
  1594. rc = cmd->nonhid_cmd->resume_scanning(dev,
  1595. PT_CORE_CMD_UNPROTECTED);
  1596. }
  1597. }
  1598. rc = cmd->release_exclusive(dev);
  1599. if (rc) {
  1600. pt_debug(dev, DL_ERROR,
  1601. "%s: Error on release exclusive rc = %d\n",
  1602. __func__, rc);
  1603. }
  1604. pm_runtime_put(dev);
  1605. /*start watchdog*/
  1606. rc = cmd->request_start_wd(dev);
  1607. if (rc)
  1608. pt_debug(dev, DL_ERROR, "start watchdog failed");
  1609. if (self_test_result_1 || self_test_result_2)
  1610. goto self_test_failed;
  1611. /* The tests are finished without failure */
  1612. mutex_lock(&dad->sysfs_lock);
  1613. dad->test_executed = 1;
  1614. mutex_unlock(&dad->sysfs_lock);
  1615. if (no_builtin_file)
  1616. goto no_builtin;
  1617. if ((test_item) & (CM_ENABLED))
  1618. validate_cm_test_results(dev, configuration, cmcp_info,
  1619. result, &final_pass, test_item);
  1620. if ((test_item) & (CP_ENABLED))
  1621. validate_cp_test_results(dev, configuration, cmcp_info,
  1622. result, &final_pass, test_item);
  1623. if ((dad->cmcp_test_items == CMCP_FULL)
  1624. && (dad->cmcp_range_check == 0)) {
  1625. /*full test and full check*/
  1626. result->test_summary = result->cm_test_pass
  1627. && result->cp_test_pass
  1628. && result->short_test_pass;
  1629. } else if ((dad->cmcp_test_items == CMCP_FULL)
  1630. && (dad->cmcp_range_check == 1)) {
  1631. /*full test and basic check*/
  1632. result->test_summary = result->cm_sensor_gd_col_pass
  1633. && result->cm_sensor_gd_row_pass
  1634. && result->cm_sensor_validation_pass
  1635. && result->cp_rx_validation_pass
  1636. && result->cp_tx_validation_pass
  1637. && result->short_test_pass;
  1638. } else if (dad->cmcp_test_items == CMCP_CM_PANEL) {
  1639. /*cm panel test result only*/
  1640. result->test_summary = result->cm_sensor_gd_col_pass
  1641. && result->cm_sensor_gd_row_pass
  1642. && result->cm_sensor_validation_pass
  1643. && result->cm_sensor_row_delta_pass
  1644. && result->cm_sensor_col_delta_pass
  1645. && result->cm_sensor_calibration_pass
  1646. && result->cm_sensor_delta_pass;
  1647. } else if (dad->cmcp_test_items == CMCP_CP_PANEL) {
  1648. /*cp panel test result only*/
  1649. result->test_summary = result->cp_sensor_delta_pass
  1650. && result->cp_rx_validation_pass
  1651. && result->cp_tx_validation_pass;
  1652. } else if (dad->cmcp_test_items == CMCP_CM_BTN) {
  1653. /*cm button test result only*/
  1654. result->test_summary = result->cm_button_validation_pass
  1655. && result->cm_button_delta_pass;
  1656. } else if (dad->cmcp_test_items == CMCP_CP_BTN) {
  1657. /*cp button test result only*/
  1658. result->test_summary = result->cp_button_delta_pass
  1659. && result->cp_button_average_pass
  1660. && result->cp_button_validation_pass;
  1661. }
  1662. if (result->test_summary) {
  1663. pt_debug(dev, DL_INFO,
  1664. "%s: Finish Cm/Cp test! All Test Passed\n", __func__);
  1665. index = scnprintf(buf, PT_MAX_PRBUF_SIZE, "Status: 1\n");
  1666. } else {
  1667. pt_debug(dev, DL_INFO,
  1668. "%s: Finish Cm/Cp test! Range Check Failure\n",
  1669. __func__);
  1670. index = scnprintf(buf, PT_MAX_PRBUF_SIZE, "Status: 6\n");
  1671. }
  1672. goto cmcp_ready;
  1673. mismatch:
  1674. index = scnprintf(buf, PT_MAX_PRBUF_SIZE,
  1675. "Status: 2\nInput cmcp threshold file mismatches with FW\n");
  1676. goto cmcp_ready;
  1677. invalid_item_btn:
  1678. index = scnprintf(buf, PT_MAX_PRBUF_SIZE,
  1679. "Status: 3\nFW doesn't support button!\n");
  1680. goto cmcp_ready;
  1681. invalid_item:
  1682. index = scnprintf(buf, PT_MAX_PRBUF_SIZE,
  1683. "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");
  1684. goto cmcp_ready;
  1685. self_test_failed:
  1686. index = scnprintf(buf, PT_MAX_PRBUF_SIZE,
  1687. "Status: 5\nget self test ID not supported!\n");
  1688. goto cmcp_ready;
  1689. cmcp_not_ready:
  1690. index = scnprintf(buf, PT_MAX_PRBUF_SIZE, "Status: 0\n");
  1691. goto cmcp_ready;
  1692. no_builtin:
  1693. index = scnprintf(buf, PT_MAX_PRBUF_SIZE,
  1694. "Status: 7\nNo cmcp threshold file!\n");
  1695. cmcp_ready:
  1696. mutex_lock(&dad->sysfs_lock);
  1697. dad->cmcp_test_in_progress = 0;
  1698. mutex_unlock(&dad->sysfs_lock);
  1699. exit:
  1700. return index;
  1701. }
  1702. /*******************************************************************************
  1703. * FUNCTION: pt_cmcp_test_store
  1704. *
  1705. * SUMMARY: The store method for cmcp_test sysfs node.Allows the user to
  1706. * configure which cm/cp tests will be executed on the "cat" of this node.
  1707. *
  1708. * RETURN: Size of passed in buffer
  1709. *
  1710. * PARAMETERS:
  1711. * *dev - pointer to device structure
  1712. * *attr - pointer to device attributes
  1713. * *buf - pointer to buffer that hold the command parameters
  1714. * size - size of buf
  1715. ******************************************************************************/
  1716. static ssize_t pt_cmcp_test_store(struct device *dev,
  1717. struct device_attribute *attr, const char *buf, size_t size)
  1718. {
  1719. struct pt_device_access_data *dad
  1720. = pt_get_device_access_data(dev);
  1721. u8 test_item = 0;
  1722. u8 range_check = 0;
  1723. u8 force_calibrate = 0;
  1724. u32 input_data[4];
  1725. int ret = 0;
  1726. static const char * const cmcp_test_case_array[] = {"Full Cm/Cp test",
  1727. "Cm panel test", "Cp panel test",
  1728. "Cm button test", "Cp button test"};
  1729. static const char * const cmcp_test_range_check_array[] = {
  1730. "Full (default)", "Basic"};
  1731. static const char * const cmcp_test_force_cal_array[] = {
  1732. "Calibrate When Testing (default)", "No Calibration"};
  1733. ssize_t length = 0;
  1734. pm_runtime_get_sync(dev);
  1735. mutex_lock(&dad->sysfs_lock);
  1736. length = cmd->parse_sysfs_input(dev, buf, size, input_data,
  1737. ARRAY_SIZE(input_data));
  1738. if (length <= 0 || length > 3) {
  1739. pt_debug(dev, DL_ERROR, "%s: Input format error!\n",
  1740. __func__);
  1741. dad->cmcp_test_items = -EINVAL;
  1742. ret = -EINVAL;
  1743. goto error;
  1744. }
  1745. /* Get test item */
  1746. test_item = input_data[0];
  1747. /* Get range check */
  1748. if (length >= 2)
  1749. range_check = input_data[1];
  1750. /* Get force calibration */
  1751. if (length == 3)
  1752. force_calibrate = input_data[2];
  1753. /*
  1754. * Test item limitation:
  1755. * 0: Perform all Tests
  1756. * 1: CM Panel with Gradient
  1757. * 2: CP Panel
  1758. * 3: CM Button
  1759. * 4: CP Button
  1760. * Ranage check limitation:
  1761. * 0: full check
  1762. * 1: basic check
  1763. * Force calibrate limitation:
  1764. * 0: do calibration
  1765. * 1: don't do calibration
  1766. */
  1767. if ((test_item < 0) || (test_item > 4) || (range_check > 1)
  1768. || (force_calibrate > 1)) {
  1769. pt_debug(dev, DL_ERROR,
  1770. "%s: Test item should be 0~4; Range check should be 0~1; Force calibrate should be 0~1\n",
  1771. __func__);
  1772. dad->cmcp_test_items = -EINVAL;
  1773. ret = -EINVAL;
  1774. goto error;
  1775. }
  1776. /*
  1777. * If it is not all Test, then range_check should be 0
  1778. * because other test does not has concept of basic check
  1779. */
  1780. if (test_item > 0 && test_item < 5)
  1781. range_check = 0;
  1782. dad->cmcp_test_items = test_item;
  1783. dad->cmcp_range_check = range_check;
  1784. dad->cmcp_force_calibrate = force_calibrate;
  1785. pt_debug(dev, DL_INFO,
  1786. "%s: Test item=%s; Range check=%s; Force cal=%s.\n",
  1787. __func__,
  1788. cmcp_test_case_array[test_item],
  1789. cmcp_test_range_check_array[range_check],
  1790. cmcp_test_force_cal_array[force_calibrate]);
  1791. error:
  1792. mutex_unlock(&dad->sysfs_lock);
  1793. pm_runtime_put(dev);
  1794. if (ret)
  1795. return ret;
  1796. return size;
  1797. }
  1798. static DEVICE_ATTR(cmcp_test, 0600,
  1799. pt_cmcp_test_show, pt_cmcp_test_store);
  1800. /*******************************************************************************
  1801. * FUNCTION: prepare_print_string
  1802. *
  1803. * SUMMARY: Formats input buffer to out buffer with string type,and increases
  1804. * the index by size of formated data.
  1805. *
  1806. * RETURN:
  1807. * index plus with size of formated data
  1808. *
  1809. * PARAMETERS:
  1810. * *out_buf - output buffer to store formated data
  1811. * *in_buf - input buffer to be formated
  1812. * index - index in output buffer for appending content
  1813. ******************************************************************************/
  1814. int prepare_print_string(char *out_buf, char *in_buf, int index)
  1815. {
  1816. if ((out_buf == NULL) || (in_buf == NULL))
  1817. return index;
  1818. index += scnprintf(&out_buf[index], MAX_BUF_LEN - index,
  1819. "%s", in_buf);
  1820. return index;
  1821. }
  1822. /*******************************************************************************
  1823. * FUNCTION: prepare_print_string
  1824. *
  1825. * SUMMARY: Formats input buffer to out buffer with decimal base,and increases
  1826. * the index by size of formated data.
  1827. *
  1828. * RETURN:
  1829. * index plus with size of formated data
  1830. *
  1831. * PARAMETERS:
  1832. * *out_buf - output buffer to store formated data
  1833. * *in_buf - input buffer to be formated
  1834. * index - index in output buffer for appending content
  1835. * data_num - data number in input buffer
  1836. ******************************************************************************/
  1837. int prepare_print_data(char *out_buf, int32_t *in_buf, int index, int data_num)
  1838. {
  1839. int i;
  1840. if ((out_buf == NULL) || (in_buf == NULL))
  1841. return index;
  1842. for (i = 0; i < data_num; i++)
  1843. index += scnprintf(&out_buf[index], MAX_BUF_LEN - index,
  1844. "%d,", in_buf[i]);
  1845. return index;
  1846. }
  1847. /*******************************************************************************
  1848. * FUNCTION: save_header
  1849. *
  1850. * SUMMARY: Appends "header" for cmcp test result to output buffer.
  1851. *
  1852. * RETURN:
  1853. * index plus with size of formated data
  1854. *
  1855. * PARAMETERS:
  1856. * *out_buf - output buffer to store formated data
  1857. * index - index in output buffer for appending content
  1858. * *result - pointer to result structure
  1859. ******************************************************************************/
  1860. static int save_header(char *out_buf, int index, struct result *result)
  1861. {
  1862. struct rtc_time tm;
  1863. char time_buf[100] = {0};
  1864. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0))
  1865. struct timespec ts;
  1866. getnstimeofday(&ts);
  1867. rtc_time_to_tm(ts.tv_sec, &tm);
  1868. #else
  1869. struct timex txc;
  1870. do_gettimeofday(&(txc.time));
  1871. rtc_time_to_tm(txc.time.tv_sec, &tm);
  1872. #endif
  1873. scnprintf(time_buf, 100, "%d/%d/%d,TIME,%d:%d:%d,", tm.tm_year+1900,
  1874. tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
  1875. index = prepare_print_string(out_buf, ",.header,\n", index);
  1876. index = prepare_print_string(out_buf, ",DATE,", index);
  1877. index = prepare_print_string(out_buf, &time_buf[0], index);
  1878. index = prepare_print_string(out_buf, ",\n", index);
  1879. index = prepare_print_string(out_buf, ",SW_VERSION,", index);
  1880. index = prepare_print_string(out_buf, PT_DRIVER_VERSION, index);
  1881. index = prepare_print_string(out_buf, ",\n", index);
  1882. index = prepare_print_string(out_buf, ",.end,\n", index);
  1883. index = prepare_print_string(out_buf, ",.engineering data,\n", index);
  1884. return index;
  1885. }
  1886. /*******************************************************************************
  1887. * FUNCTION: print_silicon_id
  1888. *
  1889. * SUMMARY: Formats input buffer(silicon id) to out buffer with
  1890. * string type,and increases the index by size of formated data.
  1891. *
  1892. * RETURN:
  1893. * index plus with size of formated data
  1894. *
  1895. * PARAMETERS:
  1896. * *out_buf - output buffer to store formated data
  1897. * *in_buf - input buffer to be formated
  1898. * index - index in output buffer for appending content
  1899. ******************************************************************************/
  1900. static int print_silicon_id(char *out_buf, char *in_buf, int index)
  1901. {
  1902. index = prepare_print_string(out_buf, ",1,", index);
  1903. index = prepare_print_string(out_buf, &in_buf[0], index);
  1904. return index;
  1905. }
  1906. /*******************************************************************************
  1907. * FUNCTION: save_engineering_data
  1908. *
  1909. * SUMMARY: Generates cmcp test result with *.csv format to output buffer, but
  1910. * it doesn't include the header.
  1911. *
  1912. * RETURN:
  1913. * index plus with size of formated data
  1914. *
  1915. * PARAMETERS:
  1916. * *dev - pointer to device structure
  1917. * *out_buf - output buffer to store formated data
  1918. * index - index in output buffer for appending content
  1919. * *cmcp_info - pointer to cmcp_data structure
  1920. * *configuration - pointer to configuration structure
  1921. * *result - pointer to result structure
  1922. * test_item - test control in bitwise
  1923. * no_builtin_file - flag to determin if builtin-file exist
  1924. ******************************************************************************/
  1925. int save_engineering_data(struct device *dev, char *out_buf, int index,
  1926. struct cmcp_data *cmcp_info, struct configuration *configuration,
  1927. struct result *result, int test_item, int no_builtin_file)
  1928. {
  1929. int i;
  1930. int j;
  1931. int tx_num = cmcp_info->tx_num;
  1932. int rx_num = cmcp_info->rx_num;
  1933. int btn_num = cmcp_info->btn_num;
  1934. int tmp = 0;
  1935. uint32_t fw_revision_control;
  1936. uint32_t fw_config_ver;
  1937. char device_id[20] = {0};
  1938. struct pt_device_access_data *dad
  1939. = pt_get_device_access_data(dev);
  1940. fw_revision_control = dad->si->ttdata.revctrl;
  1941. fw_config_ver = dad->si->ttdata.fw_ver_conf;
  1942. /*calculate silicon id*/
  1943. result->device_id_low = 0;
  1944. result->device_id_high = 0;
  1945. for (i = 0; i < 4; i++)
  1946. result->device_id_low =
  1947. (result->device_id_low << 8) + dad->si->ttdata.mfg_id[i];
  1948. for (i = 4; i < 8; i++)
  1949. result->device_id_high =
  1950. (result->device_id_high << 8) + dad->si->ttdata.mfg_id[i];
  1951. scnprintf(device_id, 20, "%x%x",
  1952. result->device_id_high, result->device_id_low);
  1953. /*print test summary*/
  1954. index = print_silicon_id(out_buf, &device_id[0], index);
  1955. if (result->test_summary)
  1956. index = prepare_print_string(out_buf, ",PASS,\n", index);
  1957. else
  1958. index = prepare_print_string(out_buf, ",FAIL,\n", index);
  1959. /*revision ctrl number*/
  1960. index = print_silicon_id(out_buf, &device_id[0], index);
  1961. index = prepare_print_string(out_buf, ",FW revision Control,", index);
  1962. index = prepare_print_data(out_buf, &fw_revision_control, index, 1);
  1963. index = prepare_print_string(out_buf, "\n", index);
  1964. /*config version*/
  1965. index = print_silicon_id(out_buf, &device_id[0], index);
  1966. index = prepare_print_string(out_buf, ",CONFIG_VER,", index);
  1967. index = prepare_print_data(out_buf, &fw_config_ver, index, 1);
  1968. index = prepare_print_string(out_buf, "\n", index);
  1969. /* Shorts test */
  1970. index = print_silicon_id(out_buf, &device_id[0], index);
  1971. if (result->short_test_pass)
  1972. index = prepare_print_string(out_buf, ",Shorts,PASS,\n", index);
  1973. else
  1974. index = prepare_print_string(out_buf, ",Shorts,FAIL,\n", index);
  1975. if ((test_item & CM_ENABLED) == CM_ENABLED) {
  1976. /*print BUTNS_CM_DATA_ROW00*/
  1977. if (((test_item & CM_BTN) == CM_BTN) && (btn_num > 0)) {
  1978. index = print_silicon_id(out_buf, &device_id[0], index);
  1979. index = prepare_print_string(out_buf,
  1980. ",Sensor Cm Validation,BUTNS_CM_DATA_ROW00,",
  1981. index);
  1982. index = prepare_print_data(out_buf,
  1983. &cmcp_info->cm_btn_data[0],
  1984. index,
  1985. btn_num);
  1986. index = prepare_print_string(out_buf, "\n", index);
  1987. }
  1988. if ((test_item & CM_PANEL) == CM_PANEL) {
  1989. /*print CM_DATA_ROW*/
  1990. for (i = 0; i < rx_num; i++) {
  1991. index = print_silicon_id(out_buf, &device_id[0],
  1992. index);
  1993. index = prepare_print_string(out_buf,
  1994. ",Sensor Cm Validation,CM_DATA_ROW",
  1995. index);
  1996. index = prepare_print_data(out_buf, &i,
  1997. index, 1);
  1998. for (j = 0; j < tx_num; j++)
  1999. index = prepare_print_data(out_buf,
  2000. &cmcp_info->cm_data_panel[j*rx_num+i],
  2001. index, 1);
  2002. index = prepare_print_string(out_buf,
  2003. "\n", index);
  2004. }
  2005. if (!no_builtin_file) {
  2006. /*print CM_MAX_GRADIENT_COLS_PERCENT*/
  2007. index = print_silicon_id(out_buf,
  2008. &device_id[0], index);
  2009. index = prepare_print_string(out_buf,
  2010. ",Sensor Cm Validation,CM_MAX_GRADIENT_COLS_PERCENT,",
  2011. index);
  2012. for (i = 0; i < tx_num; i++) {
  2013. char tmp_buf[10] = {0};
  2014. scnprintf(tmp_buf, 10, "%d.%d,",
  2015. cmcp_info->gd_sensor_col[i].gradient_val / 10,
  2016. cmcp_info->gd_sensor_col[i].gradient_val % 10);
  2017. index = prepare_print_string(out_buf,
  2018. &tmp_buf[0], index);
  2019. }
  2020. index = prepare_print_string(out_buf,
  2021. "\n", index);
  2022. /*print CM_MAX_GRADIENT_ROWS_PERCENT*/
  2023. index = print_silicon_id(out_buf,
  2024. &device_id[0], index);
  2025. index = prepare_print_string(out_buf,
  2026. ",Sensor Cm Validation,CM_MAX_GRADIENT_ROWS_PERCENT,",
  2027. index);
  2028. for (i = 0; i < rx_num; i++) {
  2029. char tmp_buf[10] = {0};
  2030. scnprintf(tmp_buf, 10, "%d.%d,",
  2031. cmcp_info->gd_sensor_row[i].gradient_val / 10,
  2032. cmcp_info->gd_sensor_row[i].gradient_val % 10);
  2033. index = prepare_print_string(out_buf,
  2034. &tmp_buf[0], index);
  2035. }
  2036. index = prepare_print_string(out_buf,
  2037. "\n", index);
  2038. if (!dad->cmcp_range_check) {
  2039. /*print CM_DELTA_COLUMN*/
  2040. for (i = 0; i < rx_num; i++) {
  2041. index = print_silicon_id(
  2042. out_buf,
  2043. &device_id[0], index);
  2044. index = prepare_print_string(
  2045. out_buf,
  2046. ",Sensor Cm Validation,DELTA_COLUMNS_ROW",
  2047. index);
  2048. index = prepare_print_data(
  2049. out_buf,
  2050. &i, index, 1);
  2051. index = prepare_print_data(
  2052. out_buf,
  2053. &tmp, index, 1);
  2054. for (j = 1; j < tx_num; j++)
  2055. index = prepare_print_data(
  2056. out_buf,
  2057. &cmcp_info->cm_sensor_column_delta[(j-1)*rx_num+i],
  2058. index, 1);
  2059. index = prepare_print_string(
  2060. out_buf,
  2061. "\n", index);
  2062. }
  2063. /*print CM_DELTA_ROW*/
  2064. index = print_silicon_id(out_buf,
  2065. &device_id[0],
  2066. index);
  2067. index = prepare_print_string(out_buf,
  2068. ",Sensor Cm Validation,DELTA_ROWS_ROW",
  2069. index);
  2070. index = prepare_print_data(out_buf,
  2071. &tmp, index, 1);
  2072. for (j = 0; j < tx_num; j++)
  2073. index = prepare_print_data(
  2074. out_buf,
  2075. &tmp, index, 1);
  2076. index = prepare_print_string(out_buf,
  2077. "\n", index);
  2078. for (i = 1; i < rx_num; i++) {
  2079. index = print_silicon_id(
  2080. out_buf,
  2081. &device_id[0],
  2082. index);
  2083. index = prepare_print_string(
  2084. out_buf,
  2085. ",Sensor Cm Validation,DELTA_ROWS_ROW",
  2086. index);
  2087. index = prepare_print_data(
  2088. out_buf, &i,
  2089. index, 1);
  2090. for (j = 0; j < tx_num; j++)
  2091. index = prepare_print_data(
  2092. out_buf,
  2093. &cmcp_info->cm_sensor_row_delta[j*rx_num+i-1],
  2094. index, 1);
  2095. index = prepare_print_string(
  2096. out_buf,
  2097. "\n", index);
  2098. }
  2099. /*print pass/fail Sensor Cm Validation*/
  2100. index = print_silicon_id(out_buf, &device_id[0],
  2101. index);
  2102. if (result->cm_test_pass)
  2103. index = prepare_print_string(out_buf,
  2104. ",Sensor Cm Validation,PASS,\n",
  2105. index);
  2106. else
  2107. index = prepare_print_string(out_buf,
  2108. ",Sensor Cm Validation,FAIL,\n",
  2109. index);
  2110. }
  2111. }
  2112. }
  2113. if (!no_builtin_file) {
  2114. if (((test_item & CM_BTN) == CM_BTN) && (btn_num > 0)
  2115. && (!dad->cmcp_range_check)) {
  2116. char tmp_buf[10] = {0};
  2117. /*print Button Element by Element */
  2118. index = print_silicon_id(out_buf, &device_id[0],
  2119. index);
  2120. if (result->cm_button_validation_pass)
  2121. index = prepare_print_string(out_buf,
  2122. ",Sensor Cm Validation - Button Element by Element,PASS\n",
  2123. index);
  2124. else
  2125. index = prepare_print_string(out_buf,
  2126. ",Sensor Cm Validation - Button Element by Element,FAIL\n",
  2127. index);
  2128. /*
  2129. *print Sensor Cm Validation
  2130. *- Buttons Range Buttons Range
  2131. */
  2132. index = print_silicon_id(out_buf,
  2133. &device_id[0], index);
  2134. index = prepare_print_string(out_buf,
  2135. ",Sensor Cm Validation - Buttons Range,Buttons Range,",
  2136. index);
  2137. scnprintf(tmp_buf, 10, "%d.%d,",
  2138. cmcp_info->cm_delta_data_btn / 10,
  2139. cmcp_info->cm_delta_data_btn % 10);
  2140. index = prepare_print_string(out_buf,
  2141. &tmp_buf[0], index);
  2142. index = prepare_print_string(out_buf,
  2143. "\n", index);
  2144. /*print Sensor Cm Validation
  2145. *-Buttons Range Cm_button_avg
  2146. */
  2147. index = print_silicon_id(out_buf,
  2148. &device_id[0], index);
  2149. index = prepare_print_string(out_buf,
  2150. ",Sensor Cm Validation - Buttons Range,Cm_button_avg,",
  2151. index);
  2152. index = prepare_print_data(out_buf,
  2153. &cmcp_info->cm_ave_data_btn,
  2154. index, 1);
  2155. index = prepare_print_string(out_buf,
  2156. "\n", index);
  2157. /*print Sensor Cm Validation
  2158. * -Buttons Range Cm_button_avg
  2159. */
  2160. index = print_silicon_id(out_buf,
  2161. &device_id[0], index);
  2162. index = prepare_print_string(out_buf,
  2163. ",Sensor Cm Validation - Buttons Range,Cm_button_cal,",
  2164. index);
  2165. index = prepare_print_data(out_buf,
  2166. &cmcp_info->cm_cal_data_btn,
  2167. index, 1);
  2168. index = prepare_print_string(out_buf,
  2169. "\n", index);
  2170. /*print Sensor Cm Validation
  2171. *-Buttons Range pass/fail
  2172. */
  2173. index = print_silicon_id(out_buf,
  2174. &device_id[0], index);
  2175. if (result->cm_button_delta_pass)
  2176. index = prepare_print_string(out_buf,
  2177. ",Sensor Cm Validation - Buttons Range,PASS,LIMITS,",
  2178. index);
  2179. else
  2180. index = prepare_print_string(out_buf,
  2181. ",Sensor Cm Validation - Buttons Range,FAIL,LIMITS,",
  2182. index);
  2183. index = prepare_print_data(out_buf,
  2184. &configuration->cm_max_delta_button_percent,
  2185. index, 1);
  2186. index = prepare_print_string(out_buf,
  2187. "\n", index);
  2188. }
  2189. if ((test_item & CM_PANEL) == CM_PANEL &&
  2190. !dad->cmcp_range_check) {
  2191. char tmp_buf[10] = {0};
  2192. /*print Cm_sensor_cal */
  2193. index = print_silicon_id(out_buf,
  2194. &device_id[0], index);
  2195. index = prepare_print_string(out_buf,
  2196. ",Sensor Cm Validation - Calibration,Cm_sensor_cal,",
  2197. index);
  2198. index = prepare_print_data(out_buf,
  2199. &cmcp_info->cm_cal_data_panel,
  2200. index, 1);
  2201. index = prepare_print_string(out_buf,
  2202. "\n", index);
  2203. /*print Cm_sensor_cal limit*/
  2204. index = print_silicon_id(out_buf,
  2205. &device_id[0], index);
  2206. if (result->cm_sensor_calibration_pass)
  2207. index = prepare_print_string(out_buf,
  2208. ",Sensor Cm Validation - Calibration,PASS,LIMITS,",
  2209. index);
  2210. else
  2211. index = prepare_print_string(out_buf,
  2212. ",Sensor Cm Validation - Calibration,FAIL,LIMITS,",
  2213. index);
  2214. index = prepare_print_data(out_buf,
  2215. &configuration->cm_min_limit_cal,
  2216. index, 1);
  2217. index = prepare_print_data(out_buf,
  2218. &configuration->cm_max_limit_cal,
  2219. index, 1);
  2220. index = prepare_print_string(out_buf,
  2221. "\n", index);
  2222. /*print Columns Delta Matrix*/
  2223. index = print_silicon_id(out_buf,
  2224. &device_id[0], index);
  2225. if (result->cm_sensor_col_delta_pass)
  2226. index = prepare_print_string(out_buf,
  2227. ",Sensor Cm Validation - Columns Delta Matrix,PASS,LIMITS,",
  2228. index);
  2229. else
  2230. index = prepare_print_string(out_buf,
  2231. ",Sensor Cm Validation - Columns Delta Matrix,FAIL,LIMITS,",
  2232. index);
  2233. index = prepare_print_data(out_buf,
  2234. &configuration->cm_range_limit_col,
  2235. index, 1);
  2236. index = prepare_print_string(out_buf,
  2237. "\n", index);
  2238. /*print Cm Validation - Element by Element*/
  2239. index = print_silicon_id(out_buf,
  2240. &device_id[0], index);
  2241. if (result->cm_sensor_validation_pass)
  2242. index = prepare_print_string(out_buf,
  2243. ",Sensor Cm Validation - Element by Element,PASS,",
  2244. index);
  2245. else
  2246. index = prepare_print_string(out_buf,
  2247. ",Sensor Cm Validation - Element by Element,FAIL,",
  2248. index);
  2249. index = prepare_print_string(out_buf,
  2250. "\n", index);
  2251. /*print Cm Validation -Gradient Cols*/
  2252. index = print_silicon_id(out_buf,
  2253. &device_id[0], index);
  2254. if (result->cm_sensor_gd_col_pass)
  2255. index = prepare_print_string(out_buf,
  2256. ",Sensor Cm Validation - Gradient Cols,PASS,",
  2257. index);
  2258. else
  2259. index = prepare_print_string(out_buf,
  2260. ",Sensor Cm Validation - Gradient Cols,FAIL,",
  2261. index);
  2262. index = prepare_print_string(out_buf,
  2263. "\n", index);
  2264. /*print Cm Validation -Gradient Rows*/
  2265. index = print_silicon_id(out_buf,
  2266. &device_id[0], index);
  2267. if (result->cm_sensor_gd_row_pass)
  2268. index = prepare_print_string(out_buf,
  2269. ",Sensor Cm Validation - Gradient Rows,PASS,",
  2270. index);
  2271. else
  2272. index = prepare_print_string(out_buf,
  2273. ",Sensor Cm Validation - Gradient Rows,FAIL,",
  2274. index);
  2275. index = prepare_print_string(out_buf,
  2276. "\n", index);
  2277. /*
  2278. * Print Sensor Cm Validation
  2279. * -Rows Delta Matrix
  2280. */
  2281. index = print_silicon_id(out_buf,
  2282. &device_id[0], index);
  2283. if (result->cm_sensor_row_delta_pass)
  2284. index = prepare_print_string(out_buf,
  2285. ",Sensor Cm Validation - Rows Delta Matrix,PASS,LIMITS,",
  2286. index);
  2287. else
  2288. index = prepare_print_string(out_buf,
  2289. ",Sensor Cm Validation - Rows Delta Matrix,FAIL,LIMITS,",
  2290. index);
  2291. index = prepare_print_data(out_buf,
  2292. &configuration->cm_range_limit_row,
  2293. index, 1);
  2294. index = prepare_print_string(out_buf,
  2295. "\n", index);
  2296. /*print Cm_sensor_avg */
  2297. index = print_silicon_id(out_buf,
  2298. &device_id[0], index);
  2299. index = prepare_print_string(out_buf,
  2300. ",Sensor Cm Validation - Sensor Range,Cm_sensor_avg,",
  2301. index);
  2302. index = prepare_print_data(out_buf,
  2303. &cmcp_info->cm_ave_data_panel,
  2304. index, 1);
  2305. index = prepare_print_string(out_buf,
  2306. "\n", index);
  2307. /*printSensor Cm Validation -
  2308. * Sensor Range, Sensor Range
  2309. */
  2310. index = print_silicon_id(out_buf,
  2311. &device_id[0], index);
  2312. index = prepare_print_string(out_buf,
  2313. ",Sensor Cm Validation - Sensor Range,Sensor Range,",
  2314. index);
  2315. scnprintf(tmp_buf, 10, "%d.%d,",
  2316. cmcp_info->cm_sensor_delta / 10,
  2317. cmcp_info->cm_sensor_delta % 10);
  2318. index = prepare_print_string(out_buf,
  2319. &tmp_buf[0], index);
  2320. index = prepare_print_string(out_buf,
  2321. "\n", index);
  2322. /*print Sensor Cm Validation - Sensor Range*/
  2323. index = print_silicon_id(out_buf,
  2324. &device_id[0], index);
  2325. if (result->cm_sensor_delta_pass)
  2326. index = prepare_print_string(out_buf,
  2327. ",Sensor Cm Validation - Sensor Range,PASS,LIMITS,",
  2328. index);
  2329. else
  2330. index = prepare_print_string(out_buf,
  2331. ",Sensor Cm Validation - Sensor Range,FAIL,LIMITS,",
  2332. index);
  2333. index = prepare_print_data(out_buf,
  2334. &configuration->cm_max_delta_sensor_percent,
  2335. index, 1);
  2336. index = prepare_print_string(out_buf,
  2337. "\n", index);
  2338. }
  2339. }
  2340. }
  2341. if ((test_item & CP_ENABLED) == CP_ENABLED) {
  2342. if (((test_item & CP_BTN) == CP_BTN) && (btn_num > 0)) {
  2343. /*print BUTNS_CP_DATA_ROW00 */
  2344. index = print_silicon_id(out_buf, &device_id[0], index);
  2345. index = prepare_print_string(out_buf,
  2346. ",Self-cap Calibration Check,BUTNS_CP_DATA_ROW00,",
  2347. index);
  2348. index = prepare_print_data(out_buf,
  2349. &cmcp_info->cp_btn_data[0],
  2350. index, btn_num);
  2351. index = prepare_print_string(out_buf,
  2352. "\n", index);
  2353. if (!no_builtin_file && !dad->cmcp_range_check) {
  2354. /*print Cp Button Element by Element */
  2355. index = print_silicon_id(out_buf, &device_id[0],
  2356. index);
  2357. if (result->cp_button_validation_pass)
  2358. index = prepare_print_string(out_buf,
  2359. ",Self-cap Calibration Check - Button Element by Element,PASS\n",
  2360. index);
  2361. else
  2362. index = prepare_print_string(out_buf,
  2363. ",Self-cap Calibration Check - Button Element by Element,FAIL\n",
  2364. index);
  2365. /*print cp_button_ave */
  2366. index = print_silicon_id(out_buf,
  2367. &device_id[0], index);
  2368. index = prepare_print_string(out_buf,
  2369. ",Self-cap Calibration Check,Cp_button_avg,",
  2370. index);
  2371. index = prepare_print_data(out_buf,
  2372. &cmcp_info->cp_button_ave,
  2373. index, 1);
  2374. index = prepare_print_string(out_buf,
  2375. "\n", index);
  2376. /*print Cp_button_cal */
  2377. index = print_silicon_id(out_buf,
  2378. &device_id[0], index);
  2379. index = prepare_print_string(out_buf,
  2380. ",Self-cap Calibration Check,Cp_button_cal,",
  2381. index);
  2382. index = prepare_print_data(out_buf,
  2383. &cmcp_info->cp_btn_cal,
  2384. index, 1);
  2385. index = prepare_print_string(out_buf,
  2386. "\n", index);
  2387. }
  2388. }
  2389. if ((test_item & CP_PANEL) == CP_PANEL) {
  2390. /*print CP_DATA_RX */
  2391. index = print_silicon_id(out_buf, &device_id[0], index);
  2392. index = prepare_print_string(out_buf,
  2393. ",Self-cap Calibration Check,CP_DATA_RX,", index);
  2394. index = prepare_print_data(out_buf,
  2395. &cmcp_info->cp_rx_data_panel[0], index, rx_num);
  2396. index = prepare_print_string(out_buf, "\n", index);
  2397. /*print CP_DATA_TX */
  2398. index = print_silicon_id(out_buf, &device_id[0], index);
  2399. index = prepare_print_string(out_buf,
  2400. ",Self-cap Calibration Check,CP_DATA_TX,", index);
  2401. index = prepare_print_data(out_buf,
  2402. &cmcp_info->cp_tx_data_panel[0], index, tx_num);
  2403. index = prepare_print_string(out_buf, "\n", index);
  2404. }
  2405. if (((test_item & CP_BTN) == CP_BTN) && (btn_num > 0)
  2406. && !dad->cmcp_range_check) {
  2407. if (!no_builtin_file) {
  2408. char tmp_buf[10] = {0};
  2409. /*print Cp_delta_button */
  2410. index = print_silicon_id(out_buf, &device_id[0],
  2411. index);
  2412. index = prepare_print_string(out_buf,
  2413. ",Self-cap Calibration Check,Cp_delta_button,",
  2414. index);
  2415. scnprintf(tmp_buf, 10, "%d.%d,",
  2416. cmcp_info->cp_button_delta / 10,
  2417. cmcp_info->cp_button_delta % 10);
  2418. index = prepare_print_string(out_buf,
  2419. &tmp_buf[0], index);
  2420. index = prepare_print_string(out_buf, "\n",
  2421. index);
  2422. }
  2423. }
  2424. if ((test_item & CP_PANEL) == CP_PANEL &&
  2425. !dad->cmcp_range_check) {
  2426. if (!no_builtin_file) {
  2427. char tmp_buf[10] = {0};
  2428. /*print Cp_delta_rx */
  2429. index = print_silicon_id(out_buf, &device_id[0],
  2430. index);
  2431. index = prepare_print_string(out_buf,
  2432. ",Self-cap Calibration Check,Cp_delta_rx,",
  2433. index);
  2434. scnprintf(tmp_buf, 10, "%d.%d,",
  2435. cmcp_info->cp_sensor_rx_delta / 10,
  2436. cmcp_info->cp_sensor_rx_delta % 10);
  2437. index = prepare_print_string(out_buf,
  2438. &tmp_buf[0], index);
  2439. index = prepare_print_string(out_buf, "\n",
  2440. index);
  2441. /*print Cp_delta_tx */
  2442. index = print_silicon_id(out_buf, &device_id[0],
  2443. index);
  2444. index = prepare_print_string(out_buf,
  2445. ",Self-cap Calibration Check,Cp_delta_tx,",
  2446. index);
  2447. scnprintf(tmp_buf, 10, "%d.%d,",
  2448. cmcp_info->cp_sensor_tx_delta / 10,
  2449. cmcp_info->cp_sensor_tx_delta % 10);
  2450. index = prepare_print_string(out_buf,
  2451. &tmp_buf[0], index);
  2452. index = prepare_print_string(out_buf, "\n",
  2453. index);
  2454. /*print Cp_sensor_avg_rx */
  2455. index = print_silicon_id(out_buf, &device_id[0],
  2456. index);
  2457. index = prepare_print_string(out_buf,
  2458. ",Self-cap Calibration Check,Cp_sensor_avg_rx,",
  2459. index);
  2460. index = prepare_print_data(out_buf,
  2461. &cmcp_info->cp_rx_ave_data_panel,
  2462. index, 1);
  2463. index = prepare_print_string(out_buf,
  2464. "\n", index);
  2465. /*print Cp_sensor_avg_tx */
  2466. index = print_silicon_id(out_buf,
  2467. &device_id[0], index);
  2468. index = prepare_print_string(out_buf,
  2469. ",Self-cap Calibration Check,Cp_sensor_avg_tx,",
  2470. index);
  2471. index = prepare_print_data(out_buf,
  2472. &cmcp_info->cp_tx_ave_data_panel,
  2473. index, 1);
  2474. index = prepare_print_string(out_buf,
  2475. "\n", index);
  2476. /*print Cp_sensor_cal_rx */
  2477. index = print_silicon_id(out_buf,
  2478. &device_id[0], index);
  2479. index = prepare_print_string(out_buf,
  2480. ",Self-cap Calibration Check,Cp_sensor_cal_rx,",
  2481. index);
  2482. index = prepare_print_data(out_buf,
  2483. &cmcp_info->cp_rx_cal_data_panel[0],
  2484. index, rx_num);
  2485. index = prepare_print_string(out_buf,
  2486. "\n", index);
  2487. /*print Cp_sensor_cal_tx */
  2488. index = print_silicon_id(out_buf,
  2489. &device_id[0], index);
  2490. index = prepare_print_string(out_buf,
  2491. ",Self-cap Calibration Check,Cp_sensor_cal_tx,",
  2492. index);
  2493. index = prepare_print_data(out_buf,
  2494. &cmcp_info->cp_tx_cal_data_panel[0],
  2495. index, tx_num);
  2496. index = prepare_print_string(out_buf,
  2497. "\n", index);
  2498. }
  2499. }
  2500. if (!no_builtin_file && !dad->cmcp_range_check) {
  2501. /*print cp test limits */
  2502. index = print_silicon_id(out_buf, &device_id[0], index);
  2503. if (result->cp_test_pass)
  2504. index = prepare_print_string(out_buf,
  2505. ",Self-cap Calibration Check,PASS, LIMITS,",
  2506. index);
  2507. else
  2508. index = prepare_print_string(out_buf,
  2509. ",Self-cap Calibration Check,FAIL, LIMITS,",
  2510. index);
  2511. index = prepare_print_string(out_buf,
  2512. "CP_MAX_DELTA_SENSOR_RX_PERCENT,", index);
  2513. index = prepare_print_data(out_buf,
  2514. &configuration->cp_max_delta_sensor_rx_percent,
  2515. index, 1);
  2516. index = prepare_print_string(out_buf,
  2517. "CP_MAX_DELTA_SENSOR_TX_PERCENT,", index);
  2518. index = prepare_print_data(out_buf,
  2519. &configuration->cp_max_delta_sensor_tx_percent,
  2520. index, 1);
  2521. index = prepare_print_string(out_buf,
  2522. "CP_MAX_DELTA_BUTTON_PERCENT,", index);
  2523. index = prepare_print_data(out_buf,
  2524. &configuration->cp_max_delta_button_percent,
  2525. index, 1);
  2526. index = prepare_print_string(out_buf, "\n", index);
  2527. }
  2528. }
  2529. if (!no_builtin_file) {
  2530. if ((test_item & CM_ENABLED) == CM_ENABLED) {
  2531. if ((test_item & CM_PANEL) == CM_PANEL) {
  2532. /*print columns gradient limit*/
  2533. index = prepare_print_string(out_buf,
  2534. ",Sensor Cm Validation,MAX_LIMITS,CM_MAX_GRADIENT_COLS_PERCENT,",
  2535. index);
  2536. index = prepare_print_data(out_buf,
  2537. &configuration->cm_max_table_gradient_cols_percent[0],
  2538. index,
  2539. configuration->cm_max_table_gradient_cols_percent_size);
  2540. index = prepare_print_string(out_buf,
  2541. "\n", index);
  2542. /*print rows gradient limit*/
  2543. index = prepare_print_string(out_buf,
  2544. ",Sensor Cm Validation,MAX_LIMITS,CM_MAX_GRADIENT_ROWS_PERCENT,",
  2545. index);
  2546. index = prepare_print_data(out_buf,
  2547. &configuration->cm_max_table_gradient_rows_percent[0],
  2548. index,
  2549. configuration->cm_max_table_gradient_rows_percent_size);
  2550. index = prepare_print_string(out_buf,
  2551. "\n", index);
  2552. /*print cm max limit*/
  2553. for (i = 0; i < rx_num; i++) {
  2554. index = prepare_print_string(out_buf,
  2555. ",Sensor Cm Validation,MAX_LIMITS,CM_DATA_ROW",
  2556. index);
  2557. index = prepare_print_data(out_buf,
  2558. &i, index, 1);
  2559. for (j = 0; j < tx_num; j++)
  2560. index = prepare_print_data(
  2561. out_buf,
  2562. &configuration->cm_min_max_table_sensor[i*tx_num*2+j*2+1],
  2563. index, 1);
  2564. index = prepare_print_string(out_buf,
  2565. "\n", index);
  2566. }
  2567. }
  2568. if (((test_item & CM_BTN) == CM_BTN) && (btn_num > 0)) {
  2569. index = prepare_print_string(out_buf,
  2570. ",Sensor Cm Validation,MAX LIMITS,M_BUTNS,",
  2571. index);
  2572. for (j = 0; j < btn_num; j++) {
  2573. index = prepare_print_data(out_buf,
  2574. &configuration->cm_min_max_table_btn[2*j+1],
  2575. index, 1);
  2576. }
  2577. index = prepare_print_string(out_buf,
  2578. "\n", index);
  2579. }
  2580. index = prepare_print_string(out_buf,
  2581. ",Sensor Cm Validation MAX LIMITS\n", index);
  2582. if ((test_item & CM_PANEL) == CM_PANEL) {
  2583. /*print cm min limit*/
  2584. for (i = 0; i < rx_num; i++) {
  2585. index = prepare_print_string(out_buf,
  2586. ",Sensor Cm Validation,MIN_LIMITS,CM_DATA_ROW",
  2587. index);
  2588. index = prepare_print_data(out_buf, &i,
  2589. index, 1);
  2590. for (j = 0; j < tx_num; j++)
  2591. index = prepare_print_data(
  2592. out_buf,
  2593. &configuration->cm_min_max_table_sensor[i*tx_num*2 + j*2],
  2594. index, 1);
  2595. index = prepare_print_string(out_buf,
  2596. "\n", index);
  2597. }
  2598. }
  2599. if (((test_item & CM_BTN) == CM_BTN) && (btn_num > 0)) {
  2600. index = prepare_print_string(out_buf,
  2601. ",Sensor Cm Validation,MIN LIMITS,M_BUTNS,",
  2602. index);
  2603. for (j = 0; j < btn_num; j++) {
  2604. index = prepare_print_data(out_buf,
  2605. &configuration->cm_min_max_table_btn[2*j],
  2606. index, 1);
  2607. }
  2608. index = prepare_print_string(out_buf,
  2609. "\n", index);
  2610. }
  2611. index = prepare_print_string(out_buf,
  2612. ",Sensor Cm Validation MIN LIMITS\n", index);
  2613. }
  2614. if ((test_item & CP_ENABLED) == CP_ENABLED) {
  2615. if ((test_item & CP_PANEL) == CP_PANEL) {
  2616. /*print cp tx max limit*/
  2617. index = prepare_print_string(out_buf,
  2618. ",Self-cap Calibration Check,MAX_LIMITS,TX,",
  2619. index);
  2620. for (i = 0; i < tx_num; i++)
  2621. index = prepare_print_data(out_buf,
  2622. &configuration->cp_min_max_table_tx[i*2+1],
  2623. index, 1);
  2624. index = prepare_print_string(out_buf,
  2625. "\n", index);
  2626. /*print cp rx max limit*/
  2627. index = prepare_print_string(out_buf,
  2628. ",Self-cap Calibration Check,MAX_LIMITS,RX,",
  2629. index);
  2630. for (i = 0; i < rx_num; i++)
  2631. index = prepare_print_data(out_buf,
  2632. &configuration->cp_min_max_table_rx[i*2+1],
  2633. index, 1);
  2634. index = prepare_print_string(out_buf,
  2635. "\n", index);
  2636. }
  2637. /*print cp btn max limit*/
  2638. if (((test_item & CP_BTN) == CP_BTN) && (btn_num > 0)) {
  2639. index = prepare_print_string(out_buf,
  2640. ",Self-cap Calibration Check,MAX_LIMITS,S_BUTNS,",
  2641. index);
  2642. for (i = 0; i < btn_num; i++)
  2643. index = prepare_print_data(out_buf,
  2644. &configuration->cp_min_max_table_btn[i*2+1],
  2645. index, 1);
  2646. index = prepare_print_string(out_buf,
  2647. "\n", index);
  2648. }
  2649. if ((test_item & CP_PANEL) == CP_PANEL) {
  2650. /*print cp tx min limit*/
  2651. index = prepare_print_string(out_buf,
  2652. ",Self-cap Calibration Check,MIN_LIMITS,TX,",
  2653. index);
  2654. for (i = 0; i < tx_num; i++)
  2655. index = prepare_print_data(out_buf,
  2656. &configuration->cp_min_max_table_tx[i*2],
  2657. index, 1);
  2658. index = prepare_print_string(out_buf,
  2659. "\n", index);
  2660. /*print cp rx min limit*/
  2661. index = prepare_print_string(out_buf,
  2662. ",Self-cap Calibration Check,MIN_LIMITS,RX,",
  2663. index);
  2664. for (i = 0; i < rx_num; i++)
  2665. index = prepare_print_data(out_buf,
  2666. &configuration->cp_min_max_table_rx[i*2],
  2667. index, 1);
  2668. index = prepare_print_string(out_buf,
  2669. "\n", index);
  2670. }
  2671. /*print cp btn min limit*/
  2672. if (((test_item & CP_BTN) == CP_BTN) && (btn_num > 0)) {
  2673. index = prepare_print_string(out_buf,
  2674. ",Self-cap Calibration Check,MIN_LIMITS,S_BUTNS,",
  2675. index);
  2676. for (i = 0; i < btn_num; i++)
  2677. index = prepare_print_data(out_buf,
  2678. &configuration->cp_min_max_table_btn[i*2],
  2679. index, 1);
  2680. index = prepare_print_string(out_buf,
  2681. "\n", index);
  2682. }
  2683. }
  2684. }
  2685. return index;
  2686. }
  2687. /*******************************************************************************
  2688. * FUNCTION: result_save
  2689. *
  2690. * SUMMARY: Malloc memory for output buffer and populate with the cmcp test
  2691. * header and results in the csv file format.
  2692. *
  2693. * NOTE: It supports simple_read_from_buffer() to read data multiple times to
  2694. * the buffer.
  2695. *
  2696. * RETURN:
  2697. * Size of data printed to "buf"
  2698. *
  2699. * PARAMETERS:
  2700. * *dev - pointer to device structure
  2701. * *buf - the user space buffer to read to
  2702. * *configuration - pointer to configuration structure
  2703. * *result - pointer to result structure
  2704. * *cmcp_info - pointer to cmcp_data structure
  2705. * *ppos - the current position in the buffer
  2706. * count - the maximum number of bytes to read
  2707. * test_item - test control in bitwise
  2708. * no_builtin_file - flag to determine if builtin-file exist
  2709. ******************************************************************************/
  2710. int result_save(struct device *dev, char *buf,
  2711. struct configuration *configuration, struct result *result,
  2712. struct cmcp_data *cmcp_info, loff_t *ppos, size_t count, int test_item,
  2713. int no_builtin_file)
  2714. {
  2715. u8 *out_buf = NULL;
  2716. int index = 0;
  2717. int byte_left;
  2718. out_buf = kzalloc(MAX_BUF_LEN, GFP_KERNEL);
  2719. if (configuration == NULL)
  2720. pt_debug(dev, DL_WARN, "config is NULL");
  2721. if (result == NULL)
  2722. pt_debug(dev, DL_WARN, "result is NULL");
  2723. if (cmcp_info == NULL)
  2724. pt_debug(dev, DL_WARN, "cmcp_info is NULL");
  2725. index = save_header(out_buf, index, result);
  2726. index = save_engineering_data(dev, out_buf, index,
  2727. cmcp_info, configuration, result,
  2728. test_item, no_builtin_file);
  2729. byte_left = simple_read_from_buffer(buf, count, ppos, out_buf, index);
  2730. kfree(out_buf);
  2731. return byte_left;
  2732. }
  2733. /*******************************************************************************
  2734. * FUNCTION: cmcp_results_debugfs_open
  2735. *
  2736. * SUMMARY: Open method for cmcp_results debugfs node.
  2737. *
  2738. * RETURN: 0 = success
  2739. *
  2740. * PARAMETERS:
  2741. * *inode - file inode number
  2742. * *filp - file pointer to debugfs file
  2743. ******************************************************************************/
  2744. static int cmcp_results_debugfs_open(struct inode *inode,
  2745. struct file *filp)
  2746. {
  2747. filp->private_data = inode->i_private;
  2748. return 0;
  2749. }
  2750. /*******************************************************************************
  2751. * FUNCTION: cmcp_results_debugfs_close
  2752. *
  2753. * SUMMARY: Close method for cmcp_results debugfs node.
  2754. *
  2755. * RETURN: 0 = success
  2756. *
  2757. * PARAMETERS:
  2758. * *inode - file inode number
  2759. * *filp - file pointer to debugfs file
  2760. ******************************************************************************/
  2761. static int cmcp_results_debugfs_close(struct inode *inode,
  2762. struct file *filp)
  2763. {
  2764. filp->private_data = NULL;
  2765. return 0;
  2766. }
  2767. /*******************************************************************************
  2768. * FUNCTION: cmcp_results_debugfs_read
  2769. *
  2770. * SUMMARY: Read method for cmcp_results debugfs node. This function prints
  2771. * cmcp test results to user buffer.
  2772. *
  2773. * RETURN: Size of debugfs data print
  2774. *
  2775. * PARAMETERS:
  2776. * *filp - file pointer to debugfs file
  2777. * *buf - the user space buffer to read to
  2778. * count - the maximum number of bytes to read
  2779. * *ppos - the current position in the buffer
  2780. ******************************************************************************/
  2781. static ssize_t cmcp_results_debugfs_read(struct file *filp,
  2782. char __user *buf, size_t count, loff_t *ppos)
  2783. {
  2784. struct pt_device_access_data *dad = filp->private_data;
  2785. struct device *dev;
  2786. struct cmcp_data *cmcp_info = dad->cmcp_info;
  2787. struct result *result = dad->result;
  2788. struct configuration *configuration = dad->configs;
  2789. int ret = 0;
  2790. int test_item;
  2791. int no_builtin_file = 0;
  2792. int test_executed = 0;
  2793. dev = dad->dev;
  2794. mutex_lock(&dad->sysfs_lock);
  2795. test_executed = dad->test_executed;
  2796. test_item = pt_cmcp_get_test_item(dad->cmcp_test_items);
  2797. if (dad->builtin_cmcp_threshold_status < 0) {
  2798. pt_debug(dev, DL_WARN,
  2799. "%s: No cmcp threshold file.\n", __func__);
  2800. no_builtin_file = 1;
  2801. }
  2802. mutex_unlock(&dad->sysfs_lock);
  2803. if (test_executed)
  2804. /*save result to buf*/
  2805. ret = result_save(dev, buf, configuration, result, cmcp_info,
  2806. ppos, count, test_item, no_builtin_file);
  2807. else {
  2808. char warning_info[] =
  2809. "No test result available!\n";
  2810. pt_debug(dev, DL_ERROR,
  2811. "%s: No test result available!\n", __func__);
  2812. return simple_read_from_buffer(buf, count, ppos, warning_info,
  2813. strlen(warning_info));
  2814. }
  2815. return ret;
  2816. }
  2817. static const struct file_operations cmcp_results_debugfs_fops = {
  2818. .open = cmcp_results_debugfs_open,
  2819. .release = cmcp_results_debugfs_close,
  2820. .read = cmcp_results_debugfs_read,
  2821. .write = NULL,
  2822. };
  2823. /*******************************************************************************
  2824. * FUNCTION: cmcp_return_offset_of_new_case
  2825. *
  2826. * SUMMARY: Returns the buffer offset of new test case
  2827. *
  2828. * NOTE: There are two static variable inside this function.
  2829. *
  2830. * RETURN: offset index for new case
  2831. *
  2832. * PARAMETERS:
  2833. * *bufPtr - pointer to input buffer
  2834. * first_time - flag to initialize some static variable
  2835. * (0:init; 1:don't init)
  2836. * *pFileEnd - pointer to the end of file for safe check
  2837. ******************************************************************************/
  2838. u32 cmcp_return_offset_of_new_case(const char *bufPtr, u32 first_time,
  2839. const char *pFileEnd)
  2840. {
  2841. static u32 offset, first_search;
  2842. if (first_time == 0) {
  2843. first_search = 0;
  2844. offset = 0;
  2845. }
  2846. if (first_search != 0) {
  2847. /* Search one case */
  2848. for (;;) {
  2849. /* Search ASCII_LF */
  2850. while (bufPtr < pFileEnd) {
  2851. if (*bufPtr++ != ASCII_LF)
  2852. offset++;
  2853. else
  2854. break;
  2855. }
  2856. if (bufPtr >= pFileEnd)
  2857. break;
  2858. offset++;
  2859. /*
  2860. * Single line: end loop
  2861. * Multiple lines: continue loop
  2862. */
  2863. if (*bufPtr != ASCII_COMMA)
  2864. break;
  2865. }
  2866. } else
  2867. first_search = 1;
  2868. return offset;
  2869. }
  2870. /*******************************************************************************
  2871. * FUNCTION: cmcp_get_case_info_from_threshold_file
  2872. *
  2873. * SUMMARY: Gets test case information from cmcp threshold file
  2874. *
  2875. * RETURN:
  2876. * Number of test cases
  2877. *
  2878. * PARAMETERS:
  2879. * *dev - pointer to Device structure
  2880. * *buf - pointer to input file
  2881. * *search_array - pointer to test_case_search structure
  2882. * file_size - size of input file for safe check
  2883. ******************************************************************************/
  2884. u32 cmcp_get_case_info_from_threshold_file(struct device *dev, const char *buf,
  2885. struct test_case_search *search_array, u32 file_size)
  2886. {
  2887. u32 case_num = 0, buffer_offset = 0, name_count = 0, first_search = 0;
  2888. const char *pFileEnd = buf + file_size;
  2889. pt_debug(dev, DL_INFO, "%s: Search cmcp threshold file\n",
  2890. __func__);
  2891. /* Get all the test cases */
  2892. for (case_num = 0; case_num < MAX_CASE_NUM; case_num++) {
  2893. buffer_offset =
  2894. cmcp_return_offset_of_new_case(&buf[buffer_offset],
  2895. first_search, pFileEnd);
  2896. first_search = 1;
  2897. if (buf[buffer_offset] == 0)
  2898. break;
  2899. for (name_count = 0; name_count < NAME_SIZE_MAX; name_count++) {
  2900. /* File end */
  2901. if (buf[buffer_offset + name_count] == ASCII_COMMA)
  2902. break;
  2903. search_array[case_num].name[name_count] =
  2904. buf[buffer_offset + name_count];
  2905. }
  2906. /* Exit when buffer offset is larger than file size */
  2907. if (buffer_offset >= file_size)
  2908. break;
  2909. search_array[case_num].name_size = name_count;
  2910. search_array[case_num].offset = buffer_offset;
  2911. /*
  2912. * pt_debug(dev, DL_INFO, "Find case %d: Name is %s;
  2913. * Name size is %d; Case offset is %d\n",
  2914. * case_num,
  2915. * search_array[case_num].name,
  2916. * search_array[case_num].name_size,
  2917. * search_array[case_num].offset);
  2918. */
  2919. }
  2920. return case_num;
  2921. }
  2922. /*******************************************************************************
  2923. * FUNCTION: cmcp_compose_data
  2924. *
  2925. * SUMMARY: Composes one value based on data of each bit
  2926. *
  2927. * RETURN:
  2928. * Value that composed from buffer
  2929. *
  2930. * PARAMETERS:
  2931. * *buf - pointer to input file
  2932. * count - number of data elements in *buf in decimal
  2933. ******************************************************************************/
  2934. int cmcp_compose_data(char *buf, u32 count)
  2935. {
  2936. u32 base_array[] = {1, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9};
  2937. int value = 0;
  2938. u32 index = 0;
  2939. for (index = 0; index < count; index++)
  2940. value += buf[index] * base_array[count - 1 - index];
  2941. return value;
  2942. }
  2943. /*******************************************************************************
  2944. * FUNCTION: cmcp_return_one_value
  2945. *
  2946. * SUMMARY: Parses csv file at a given row and offset and combines multiple
  2947. * "bits' as a single value. Handles data over multiple lines and various
  2948. * end-of-line characters.
  2949. *
  2950. * NOTE: There is a static value to calculate line count inside this function.
  2951. *
  2952. * RETURN:
  2953. * Value that parsed from buffer
  2954. *
  2955. * PARAMETERS:
  2956. * *dev - pointer to devices structure
  2957. * *buf - pointer to input buffer
  2958. * *offset - offset index of input buffer
  2959. * *line_num - store line count
  2960. * pFileEnd - pointer to the end of threshold file
  2961. ******************************************************************************/
  2962. int cmcp_return_one_value(struct device *dev, const char *buf, u32 *offset,
  2963. u32 *line_num, const char *pFileEnd)
  2964. {
  2965. int value = -1;
  2966. char tmp_buffer[10];
  2967. u32 count = 0;
  2968. u32 tmp_offset = *offset;
  2969. static u32 line_count = 1;
  2970. /* Bypass extra commas */
  2971. while (((buf + tmp_offset + 1) < pFileEnd)
  2972. && buf[tmp_offset] == ASCII_COMMA
  2973. && buf[tmp_offset + 1] == ASCII_COMMA)
  2974. tmp_offset++;
  2975. if ((buf + tmp_offset + 1) >= pFileEnd)
  2976. goto exit;
  2977. /* Windows and Linux difference at the end of one line */
  2978. if (buf[tmp_offset] == ASCII_COMMA && buf[tmp_offset + 1] == ASCII_CR) {
  2979. if ((buf + tmp_offset + 2) < pFileEnd) {
  2980. if (buf[tmp_offset + 2] == ASCII_LF)
  2981. tmp_offset += 2;
  2982. } else
  2983. goto exit;
  2984. } else if (buf[tmp_offset] == ASCII_COMMA &&
  2985. buf[tmp_offset + 1] == ASCII_LF)
  2986. tmp_offset += 1;
  2987. else if (buf[tmp_offset] == ASCII_COMMA
  2988. && buf[tmp_offset + 1] == ASCII_CR)
  2989. tmp_offset += 1;
  2990. if ((buf + tmp_offset + 1) >= pFileEnd)
  2991. goto exit;
  2992. /* New line for multiple lines */
  2993. if ((buf[tmp_offset] == ASCII_LF || buf[tmp_offset] == ASCII_CR) &&
  2994. buf[tmp_offset + 1] == ASCII_COMMA) {
  2995. tmp_offset++;
  2996. line_count++;
  2997. pt_debug(dev, DL_DEBUG, "%s: Line Count = %d\n",
  2998. __func__, line_count);
  2999. }
  3000. /* Beginning */
  3001. if (buf[tmp_offset] == ASCII_COMMA) {
  3002. tmp_offset++;
  3003. for (;;) {
  3004. if ((buf + tmp_offset) >= pFileEnd)
  3005. break;
  3006. if ((buf[tmp_offset] >= ASCII_ZERO)
  3007. && (buf[tmp_offset] <= ASCII_NINE)) {
  3008. tmp_buffer[count++] =
  3009. buf[tmp_offset] - ASCII_ZERO;
  3010. tmp_offset++;
  3011. } else {
  3012. if (count != 0) {
  3013. value = cmcp_compose_data(tmp_buffer,
  3014. count);
  3015. /*pt_debug(dev, DL_DEBUG, */
  3016. /* ",%d", value);*/
  3017. } else {
  3018. /* 0 indicates no data available */
  3019. value = -1;
  3020. }
  3021. break;
  3022. }
  3023. }
  3024. } else {
  3025. /* Multiple line: line count */
  3026. *line_num = line_count;
  3027. /* Reset for next case */
  3028. line_count = 1;
  3029. }
  3030. exit:
  3031. *offset = tmp_offset;
  3032. return value;
  3033. }
  3034. /*******************************************************************************
  3035. * FUNCTION: cmcp_get_configuration_info
  3036. *
  3037. * SUMMARY: Gets cmcp configuration information.
  3038. *
  3039. * PARAMETERS:
  3040. * *dev - pointer to devices structure
  3041. * *buf - pointer to input buffer
  3042. * *search_array - pointer to test_case_search structure
  3043. * case_count - number of test cases
  3044. * *field_array - pointer to test_case_field structure
  3045. * *config - pointer to configuration structure
  3046. * file_size - file size of threshold file
  3047. ******************************************************************************/
  3048. void cmcp_get_configuration_info(struct device *dev,
  3049. const char *buf, struct test_case_search *search_array,
  3050. u32 case_count, struct test_case_field *field_array,
  3051. struct configuration *config, u32 file_size)
  3052. {
  3053. u32 count = 0, sub_count = 0;
  3054. u32 exist_or_not = 0;
  3055. u32 value_offset = 0;
  3056. int retval = 0;
  3057. u32 data_num = 0;
  3058. u32 line_num = 1;
  3059. const char *pFileEnd = buf + file_size;
  3060. pt_debug(dev, DL_INFO,
  3061. "%s: Fill configuration struct per cmcp threshold file\n",
  3062. __func__);
  3063. /* Search cases */
  3064. for (count = 0; count < MAX_CASE_NUM; count++) {
  3065. exist_or_not = 0;
  3066. for (sub_count = 0; sub_count < case_count; sub_count++) {
  3067. if (!strncmp(field_array[count].name,
  3068. search_array[sub_count].name,
  3069. field_array[count].name_size)) {
  3070. exist_or_not = 1;
  3071. break;
  3072. }
  3073. }
  3074. field_array[count].exist_or_not = exist_or_not;
  3075. pt_debug(dev, DL_DEBUG,
  3076. "%s: Field Array[%d] exists: %d, type: %d\n",
  3077. __func__, count, exist_or_not, field_array[count].type);
  3078. /* Clear data number */
  3079. data_num = 0;
  3080. if (exist_or_not == 1) {
  3081. switch (field_array[count].type) {
  3082. case TEST_CASE_TYPE_NO:
  3083. field_array[count].data_num = 0;
  3084. field_array[count].line_num = 1;
  3085. break;
  3086. case TEST_CASE_TYPE_ONE:
  3087. value_offset = search_array[sub_count].offset
  3088. + search_array[sub_count].name_size;
  3089. *field_array[count].bufptr =
  3090. cmcp_return_one_value(dev, buf,
  3091. &value_offset, 0, pFileEnd);
  3092. field_array[count].data_num = 1;
  3093. field_array[count].line_num = 1;
  3094. break;
  3095. case TEST_CASE_TYPE_MUL:
  3096. case TEST_CASE_TYPE_MUL_LINES:
  3097. line_num = 1;
  3098. value_offset = search_array[sub_count].offset
  3099. + search_array[sub_count].name_size;
  3100. for (;;) {
  3101. retval = cmcp_return_one_value(
  3102. dev, buf, &value_offset, &line_num,
  3103. pFileEnd);
  3104. if (retval >= 0) {
  3105. *field_array[count].bufptr++ =
  3106. retval;
  3107. data_num++;
  3108. } else
  3109. break;
  3110. }
  3111. field_array[count].data_num = data_num;
  3112. field_array[count].line_num = line_num;
  3113. break;
  3114. default:
  3115. break;
  3116. }
  3117. pt_debug(dev, DL_DEBUG,
  3118. "%s: %s: Data count is %d, line number is %d\n",
  3119. __func__,
  3120. field_array[count].name,
  3121. field_array[count].data_num,
  3122. field_array[count].line_num);
  3123. } else
  3124. pt_debug(dev, DL_ERROR, "%s: !!! %s doesn't exist\n",
  3125. __func__, field_array[count].name);
  3126. }
  3127. }
  3128. /*******************************************************************************
  3129. * FUNCTION: cmcp_get_basic_info
  3130. *
  3131. * SUMMARY: Gets basic information for cmcp test, such as available test item,
  3132. * number of tx, rx, button.
  3133. *
  3134. * PARAMETERS:
  3135. * *dev - pointer to devices structure
  3136. * *field_array - pointer to test_case_field structure
  3137. * *config - pointer to configuration structure
  3138. ******************************************************************************/
  3139. void cmcp_get_basic_info(struct device *dev,
  3140. struct test_case_field *field_array, struct configuration *config)
  3141. {
  3142. u32 tx_num = 0;
  3143. u32 index = 0;
  3144. config->is_valid_or_not = 1; /* Set to valid by default */
  3145. config->cm_enabled = 0;
  3146. config->cp_enabled = 0;
  3147. if (field_array[CM_TEST_INPUTS].exist_or_not)
  3148. config->cm_enabled = 1;
  3149. if (field_array[CP_TEST_INPUTS].exist_or_not)
  3150. config->cp_enabled = 1;
  3151. /* Get basic information only when CM and CP are enabled */
  3152. if (config->cm_enabled && config->cp_enabled) {
  3153. pt_debug(dev, DL_INFO,
  3154. "%s: Find CM and CP thresholds\n", __func__);
  3155. config->rx_num =
  3156. field_array[PER_ELEMENT_MIN_MAX_TABLE_SENSOR].line_num;
  3157. tx_num =
  3158. (field_array[PER_ELEMENT_MIN_MAX_TABLE_SENSOR].data_num >> 1)
  3159. /field_array[PER_ELEMENT_MIN_MAX_TABLE_SENSOR].line_num;
  3160. config->tx_num = tx_num;
  3161. config->btn_num =
  3162. field_array[PER_ELEMENT_MIN_MAX_TABLE_BUTTON].data_num >> 1;
  3163. config->cm_min_max_table_btn_size =
  3164. field_array[PER_ELEMENT_MIN_MAX_TABLE_BUTTON].data_num;
  3165. config->cm_min_max_table_sensor_size =
  3166. field_array[PER_ELEMENT_MIN_MAX_TABLE_SENSOR].data_num;
  3167. config->cp_min_max_table_rx_size =
  3168. field_array[PER_ELEMENT_MIN_MAX_RX].data_num;
  3169. config->cp_min_max_table_tx_size =
  3170. field_array[PER_ELEMENT_MIN_MAX_TX].data_num;
  3171. config->cm_max_table_gradient_cols_percent_size =
  3172. field_array[CM_GRADIENT_CHECK_COL].data_num;
  3173. config->cm_max_table_gradient_rows_percent_size =
  3174. field_array[CM_GRADIENT_CHECK_ROW].data_num;
  3175. config->cp_min_max_table_btn_size =
  3176. field_array[CP_PER_ELEMENT_MIN_MAX_BUTTON].data_num;
  3177. /* *** Detailed Debug Information *** */
  3178. pt_debug(dev, DL_DEBUG, "%d\n",
  3179. config->cm_excluding_col_edge);
  3180. pt_debug(dev, DL_DEBUG, "%d\n",
  3181. config->cm_excluding_row_edge);
  3182. for (index = 0;
  3183. index < config->cm_max_table_gradient_cols_percent_size;
  3184. index++)
  3185. pt_debug(dev, DL_DEBUG, "%d\n",
  3186. config->cm_max_table_gradient_cols_percent[index]);
  3187. for (index = 0;
  3188. index < config->cm_max_table_gradient_rows_percent_size;
  3189. index++)
  3190. pt_debug(dev, DL_DEBUG, "%d\n",
  3191. config->cm_max_table_gradient_rows_percent[index]);
  3192. pt_debug(dev, DL_DEBUG, "%d\n",
  3193. config->cm_range_limit_row);
  3194. pt_debug(dev, DL_DEBUG, "%d\n",
  3195. config->cm_range_limit_col);
  3196. pt_debug(dev, DL_DEBUG, "%d\n",
  3197. config->cm_min_limit_cal);
  3198. pt_debug(dev, DL_DEBUG, "%d\n",
  3199. config->cm_max_limit_cal);
  3200. pt_debug(dev, DL_DEBUG, "%d\n",
  3201. config->cm_max_delta_sensor_percent);
  3202. pt_debug(dev, DL_DEBUG, "%d\n",
  3203. config->cm_max_delta_button_percent);
  3204. for (index = 0;
  3205. index < config->cm_min_max_table_btn_size; index++)
  3206. pt_debug(dev, DL_DEBUG, "%d\n",
  3207. config->cm_min_max_table_btn[index]);
  3208. for (index = 0;
  3209. index < config->cm_min_max_table_sensor_size; index++)
  3210. pt_debug(dev, DL_DEBUG, "%d\n",
  3211. config->cm_min_max_table_sensor[index]);
  3212. pt_debug(dev, DL_DEBUG, "%d\n",
  3213. config->cp_max_delta_sensor_rx_percent);
  3214. pt_debug(dev, DL_DEBUG, "%d\n",
  3215. config->cp_max_delta_sensor_tx_percent);
  3216. pt_debug(dev, DL_DEBUG, "%d\n",
  3217. config->cp_max_delta_button_percent);
  3218. pt_debug(dev, DL_DEBUG, "%d\n",
  3219. config->min_button);
  3220. pt_debug(dev, DL_DEBUG, "%d\n",
  3221. config->max_button);
  3222. for (index = 0;
  3223. index < config->cp_min_max_table_btn_size; index++)
  3224. pt_debug(dev, DL_DEBUG, "%d\n",
  3225. config->cp_min_max_table_btn[index]);
  3226. for (index = 0;
  3227. index < config->cp_min_max_table_rx_size; index++)
  3228. pt_debug(dev, DL_DEBUG, "%d\n",
  3229. config->cp_min_max_table_rx[index]);
  3230. for (index = 0;
  3231. index < config->cp_min_max_table_tx_size; index++)
  3232. pt_debug(dev, DL_DEBUG, "%d\n",
  3233. config->cp_min_max_table_tx[index]);
  3234. /* *** End of Detailed Debug Information *** */
  3235. /* Invalid mutual data length */
  3236. if ((field_array[PER_ELEMENT_MIN_MAX_TABLE_SENSOR].data_num >>
  3237. 1) % field_array[PER_ELEMENT_MIN_MAX_TABLE_SENSOR].line_num) {
  3238. config->is_valid_or_not = 0;
  3239. pt_debug(dev, DL_ERROR, "Invalid mutual data length\n");
  3240. }
  3241. } else {
  3242. if (!config->cm_enabled)
  3243. pt_debug(dev, DL_ERROR,
  3244. "%s: Miss CM thresholds or CM data format is wrong!\n",
  3245. __func__);
  3246. if (!config->cp_enabled)
  3247. pt_debug(dev, DL_ERROR,
  3248. "%s: Miss CP thresholds or CP data format is wrong!\n",
  3249. __func__);
  3250. config->rx_num = 0;
  3251. config->tx_num = 0;
  3252. config->btn_num = 0;
  3253. config->is_valid_or_not = 0;
  3254. }
  3255. pt_debug(dev, DL_DEBUG,
  3256. "%s:\n"
  3257. "Input file is %s!\n"
  3258. "CM test: %s\n"
  3259. "CP test: %s\n"
  3260. "rx_num is %d\n"
  3261. "tx_num is %d\n"
  3262. "btn_num is %d\n",
  3263. __func__,
  3264. config->is_valid_or_not == 1 ? "VALID" : "!!! INVALID !!!",
  3265. config->cm_enabled == 1 ? "Found" : "Not found",
  3266. config->cp_enabled == 1 ? "Found" : "Not found",
  3267. config->rx_num,
  3268. config->tx_num,
  3269. config->btn_num);
  3270. }
  3271. /*******************************************************************************
  3272. * FUNCTION: cmcp_test_case_field_init
  3273. *
  3274. * SUMMARY: Initialize the structure test_field_array.
  3275. *
  3276. * PARAMETERS:
  3277. * *test_field_array - pointer to test_case_field structure
  3278. * *configuration - pointer to configuration structure
  3279. ******************************************************************************/
  3280. void cmcp_test_case_field_init(struct test_case_field *test_field_array,
  3281. struct configuration *configs)
  3282. {
  3283. struct test_case_field test_case_field_array[MAX_CASE_NUM] = {
  3284. {"CM TEST INPUTS", 14, TEST_CASE_TYPE_NO,
  3285. NULL, 0, 0, 0},
  3286. {"CM_EXCLUDING_COL_EDGE", 21, TEST_CASE_TYPE_ONE,
  3287. &configs->cm_excluding_col_edge, 0, 0, 0},
  3288. {"CM_EXCLUDING_ROW_EDGE", 21, TEST_CASE_TYPE_ONE,
  3289. &configs->cm_excluding_row_edge, 0, 0, 0},
  3290. {"CM_GRADIENT_CHECK_COL", 21, TEST_CASE_TYPE_MUL,
  3291. &configs->cm_max_table_gradient_cols_percent[0],
  3292. 0, 0, 0},
  3293. {"CM_GRADIENT_CHECK_ROW", 21, TEST_CASE_TYPE_MUL,
  3294. &configs->cm_max_table_gradient_rows_percent[0],
  3295. 0, 0, 0},
  3296. {"CM_RANGE_LIMIT_ROW", 18, TEST_CASE_TYPE_ONE,
  3297. &configs->cm_range_limit_row, 0, 0, 0},
  3298. {"CM_RANGE_LIMIT_COL", 18, TEST_CASE_TYPE_ONE,
  3299. &configs->cm_range_limit_col, 0, 0, 0},
  3300. {"CM_MIN_LIMIT_CAL", 16, TEST_CASE_TYPE_ONE,
  3301. &configs->cm_min_limit_cal, 0, 0, 0},
  3302. {"CM_MAX_LIMIT_CAL", 16, TEST_CASE_TYPE_ONE,
  3303. &configs->cm_max_limit_cal, 0, 0, 0},
  3304. {"CM_MAX_DELTA_SENSOR_PERCENT", 27, TEST_CASE_TYPE_ONE,
  3305. &configs->cm_max_delta_sensor_percent, 0, 0, 0},
  3306. {"CM_MAX_DELTA_BUTTON_PERCENT", 27, TEST_CASE_TYPE_ONE,
  3307. &configs->cm_max_delta_button_percent, 0, 0, 0},
  3308. {"PER_ELEMENT_MIN_MAX_TABLE_BUTTON", 32, TEST_CASE_TYPE_MUL,
  3309. &configs->cm_min_max_table_btn[0], 0, 0, 0},
  3310. {"PER_ELEMENT_MIN_MAX_TABLE_SENSOR", 32,
  3311. TEST_CASE_TYPE_MUL_LINES,
  3312. &configs->cm_min_max_table_sensor[0], 0, 0, 0},
  3313. {"CP TEST INPUTS", 14, TEST_CASE_TYPE_NO,
  3314. NULL, 0, 0, 0},
  3315. {"CP_PER_ELEMENT_MIN_MAX_BUTTON", 29, TEST_CASE_TYPE_MUL,
  3316. &configs->cp_min_max_table_btn[0], 0, 0, 0},
  3317. {"CP_MAX_DELTA_SENSOR_RX_PERCENT", 30, TEST_CASE_TYPE_ONE,
  3318. &configs->cp_max_delta_sensor_rx_percent,
  3319. 0, 0, 0},
  3320. {"CP_MAX_DELTA_SENSOR_TX_PERCENT", 30, TEST_CASE_TYPE_ONE,
  3321. &configs->cp_max_delta_sensor_tx_percent,
  3322. 0, 0, 0},
  3323. {"CP_MAX_DELTA_BUTTON_PERCENT", 27, TEST_CASE_TYPE_ONE,
  3324. &configs->cp_max_delta_button_percent, 0, 0, 0},
  3325. {"MIN_BUTTON", 10, TEST_CASE_TYPE_ONE,
  3326. &configs->min_button, 0, 0, 0},
  3327. {"MAX_BUTTON", 10, TEST_CASE_TYPE_ONE,
  3328. &configs->max_button, 0, 0, 0},
  3329. {"PER_ELEMENT_MIN_MAX_RX", 22, TEST_CASE_TYPE_MUL,
  3330. &configs->cp_min_max_table_rx[0], 0, 0, 0},
  3331. {"PER_ELEMENT_MIN_MAX_TX", 22, TEST_CASE_TYPE_MUL,
  3332. &configs->cp_min_max_table_tx[0], 0, 0, 0},
  3333. };
  3334. memcpy(test_field_array, test_case_field_array,
  3335. sizeof(struct test_case_field) * MAX_CASE_NUM);
  3336. }
  3337. /*******************************************************************************
  3338. * FUNCTION: pt_parse_cmcp_threshold_file_common
  3339. *
  3340. * SUMMARY: Parses cmcp threshold file and stores to the data structure.
  3341. *
  3342. * PARAMETERS:
  3343. * *dev - pointer to devices structure
  3344. * *buf - pointer to input buffer
  3345. * file_size - file size
  3346. ******************************************************************************/
  3347. static ssize_t pt_parse_cmcp_threshold_file_common(
  3348. struct device *dev, const char *buf, u32 file_size)
  3349. {
  3350. struct pt_device_access_data *dad
  3351. = pt_get_device_access_data(dev);
  3352. ssize_t rc = 0;
  3353. u32 case_count = 0;
  3354. pt_debug(dev, DL_INFO,
  3355. "%s: Start parsing cmcp threshold file. File size is %d\n",
  3356. __func__, file_size);
  3357. cmcp_test_case_field_init(dad->test_field_array, dad->configs);
  3358. /* Get all the cases from .csv file */
  3359. case_count = cmcp_get_case_info_from_threshold_file(dev,
  3360. buf, dad->test_search_array, file_size);
  3361. pt_debug(dev, DL_INFO,
  3362. "%s: Number of cases found in CSV file: %d\n",
  3363. __func__, case_count);
  3364. /* Search cases */
  3365. cmcp_get_configuration_info(dev,
  3366. buf,
  3367. dad->test_search_array, case_count, dad->test_field_array,
  3368. dad->configs, file_size);
  3369. /* Get basic information */
  3370. cmcp_get_basic_info(dev, dad->test_field_array, dad->configs);
  3371. return rc;
  3372. }
  3373. /*******************************************************************************
  3374. * FUNCTION: pt_cmcp_threshold_loading_store
  3375. *
  3376. * SUMMARY: The store method for the cmcp_threshold_loading sysfs node. The
  3377. * passed in value controls if threshold loading is performed.
  3378. *
  3379. * RETURN: Size of passed in buffer is success
  3380. *
  3381. * PARAMETERS:
  3382. * *dev - pointer to device structure
  3383. * *attr - pointer to device attributes
  3384. * *buf - pointer to buffer that hold the command parameters
  3385. * size - size of buf
  3386. ******************************************************************************/
  3387. static ssize_t pt_cmcp_threshold_loading_store(struct device *dev,
  3388. struct device_attribute *attr, const char *buf, size_t size)
  3389. {
  3390. struct pt_device_access_data *dad = pt_get_device_access_data(dev);
  3391. ssize_t length;
  3392. u32 input_data[3];
  3393. int rc = 0;
  3394. length = cmd->parse_sysfs_input(dev, buf, size, input_data,
  3395. ARRAY_SIZE(input_data));
  3396. if (length != 1) {
  3397. pt_debug(dev, DL_WARN, "%s: Invalid number of arguments\n",
  3398. __func__);
  3399. rc = -EINVAL;
  3400. goto exit;
  3401. }
  3402. mutex_lock(&dad->cmcp_threshold_lock);
  3403. if (input_data[0] == 1)
  3404. dad->cmcp_threshold_loading = true;
  3405. else if (input_data[0] == -1)
  3406. dad->cmcp_threshold_loading = false;
  3407. else if (input_data[0] == 0 && dad->cmcp_threshold_loading) {
  3408. dad->cmcp_threshold_loading = false;
  3409. if (dad->cmcp_threshold_size == 0) {
  3410. pt_debug(dev, DL_ERROR, "%s: No cmcp threshold data\n",
  3411. __func__);
  3412. goto exit_free;
  3413. }
  3414. /* Clear test executed flag */
  3415. dad->test_executed = 0;
  3416. pt_parse_cmcp_threshold_file_common(dev,
  3417. &dad->cmcp_threshold_data[0], dad->cmcp_threshold_size);
  3418. /* Mark valid */
  3419. dad->builtin_cmcp_threshold_status = 0;
  3420. /* Restore test item to default value when new file input */
  3421. dad->cmcp_test_items = 0;
  3422. } else {
  3423. pt_debug(dev, DL_WARN, "%s: Invalid value\n", __func__);
  3424. rc = -EINVAL;
  3425. mutex_unlock(&dad->cmcp_threshold_lock);
  3426. goto exit;
  3427. }
  3428. exit_free:
  3429. kfree(dad->cmcp_threshold_data);
  3430. dad->cmcp_threshold_data = NULL;
  3431. dad->cmcp_threshold_size = 0;
  3432. mutex_unlock(&dad->cmcp_threshold_lock);
  3433. exit:
  3434. if (rc)
  3435. return rc;
  3436. return size;
  3437. }
  3438. static DEVICE_ATTR(cmcp_threshold_loading, 0200,
  3439. NULL, pt_cmcp_threshold_loading_store);
  3440. /*******************************************************************************
  3441. * FUNCTION: pt_cmcp_threshold_data_write
  3442. *
  3443. * SUMMARY: The write method for the cmcp_threshold_data_sysfs node. The passed
  3444. * in data (threshold file) is written to the threshold buffer.
  3445. *
  3446. * RETURN: Size of passed in buffer is success
  3447. *
  3448. * PARAMETERS:
  3449. * *filp - pointer to file structure
  3450. * *kobj - pointer to kobject structure
  3451. * *bin_attr - pointer to bin_attribute structure
  3452. * buf - pointer to cmd input buffer
  3453. * offset - offset index to store input buffer
  3454. * count - size of data in buffer
  3455. ******************************************************************************/
  3456. static ssize_t pt_cmcp_threshold_data_write(struct file *filp,
  3457. struct kobject *kobj, struct bin_attribute *bin_attr,
  3458. char *buf, loff_t offset, size_t count)
  3459. {
  3460. struct device *dev = container_of(kobj, struct device, kobj);
  3461. struct pt_device_access_data *dad
  3462. = pt_get_device_access_data(dev);
  3463. u8 *p;
  3464. pt_debug(dev, DL_INFO, "%s: offset:%lld count:%zu\n",
  3465. __func__, offset, count);
  3466. mutex_lock(&dad->cmcp_threshold_lock);
  3467. if (!dad->cmcp_threshold_loading) {
  3468. mutex_unlock(&dad->cmcp_threshold_lock);
  3469. return -ENODEV;
  3470. }
  3471. p = krealloc(dad->cmcp_threshold_data, offset + count, GFP_KERNEL);
  3472. if (!p) {
  3473. kfree(dad->cmcp_threshold_data);
  3474. dad->cmcp_threshold_data = NULL;
  3475. mutex_unlock(&dad->cmcp_threshold_lock);
  3476. return -ENOMEM;
  3477. }
  3478. dad->cmcp_threshold_data = p;
  3479. memcpy(&dad->cmcp_threshold_data[offset], buf, count);
  3480. dad->cmcp_threshold_size += count;
  3481. mutex_unlock(&dad->cmcp_threshold_lock);
  3482. return count;
  3483. }
  3484. static struct bin_attribute bin_attr_cmcp_threshold_data = {
  3485. .attr = {
  3486. .name = "cmcp_threshold_data",
  3487. .mode = 0200,
  3488. },
  3489. .size = 0,
  3490. .write = pt_cmcp_threshold_data_write,
  3491. };
  3492. /*******************************************************************************
  3493. * FUNCTION: pt_suspend_scan_cmd_
  3494. *
  3495. * SUMMARY: Non-protected wrapper function for suspend scan command
  3496. *
  3497. * RETURN:
  3498. * 0 = success
  3499. * !0 = failure
  3500. *
  3501. * PARAMETERS:
  3502. * *dev - pointer to devices structure
  3503. ******************************************************************************/
  3504. static int pt_suspend_scan_cmd_(struct device *dev)
  3505. {
  3506. int rc;
  3507. rc = cmd->nonhid_cmd->suspend_scanning(dev, 0);
  3508. if (rc)
  3509. pt_debug(dev, DL_ERROR, "%s: Suspend scan failed rc = %d\n",
  3510. __func__, rc);
  3511. return rc;
  3512. }
  3513. /*******************************************************************************
  3514. * FUNCTION: pt_resume_scan_cmd_
  3515. *
  3516. * SUMMARY: Non-protected wrapper function for resume scan command
  3517. *
  3518. * RETURN:
  3519. * 0 = success
  3520. * !0 = failure
  3521. *
  3522. * PARAMETERS:
  3523. * *dev - pointer to devices structure
  3524. ******************************************************************************/
  3525. static int pt_resume_scan_cmd_(struct device *dev)
  3526. {
  3527. int rc;
  3528. rc = cmd->nonhid_cmd->resume_scanning(dev, 0);
  3529. if (rc)
  3530. pt_debug(dev, DL_ERROR, "%s: Resume scan failed rc = %d\n",
  3531. __func__, rc);
  3532. return rc;
  3533. }
  3534. /*******************************************************************************
  3535. * FUNCTION: pt_exec_scan_cmd_
  3536. *
  3537. * SUMMARY: Non-protected wrapper function for execute scan command
  3538. *
  3539. * RETURN:
  3540. * 0 = success
  3541. * !0 = failure
  3542. *
  3543. * PARAMETERS:
  3544. * *dev - pointer to devices structure
  3545. * scan_type - type of panel scan to perform (PIP2 only)
  3546. ******************************************************************************/
  3547. static int pt_exec_scan_cmd_(struct device *dev, u8 scan_type)
  3548. {
  3549. int rc;
  3550. rc = cmd->nonhid_cmd->exec_panel_scan(dev, PT_CORE_CMD_UNPROTECTED,
  3551. scan_type);
  3552. if (rc)
  3553. pt_debug(dev, DL_ERROR,
  3554. "%s: Heatmap start scan failed rc = %d\n",
  3555. __func__, rc);
  3556. return rc;
  3557. }
  3558. /*******************************************************************************
  3559. * FUNCTION: pt_ret_scan_data_cmd_
  3560. *
  3561. * SUMMARY: Non-protected wrapper function for retrieve panel data command
  3562. *
  3563. * RETURN:
  3564. * 0 = success
  3565. * !0 = failure
  3566. *
  3567. * PARAMETERS:
  3568. * *dev - pointer to device structure
  3569. * read_offset - read pointer offset
  3570. * read_count - length of data to read
  3571. * data_id - enumerated test ID to read selftest results from
  3572. * *response - pointer to store the read response status
  3573. * *config - pointer to store config data
  3574. * *actual_read_len - pointer to store data length actually read
  3575. * *return_buf - pointer to the read buffer
  3576. ******************************************************************************/
  3577. static int pt_ret_scan_data_cmd_(struct device *dev, u16 read_offset,
  3578. u16 read_count, u8 data_id, u8 *response, u8 *config,
  3579. u16 *actual_read_len, u8 *return_buf)
  3580. {
  3581. int rc;
  3582. rc = cmd->nonhid_cmd->retrieve_panel_scan(dev, 0, read_offset,
  3583. read_count, data_id, response, config, actual_read_len,
  3584. return_buf);
  3585. if (rc)
  3586. pt_debug(dev, DL_ERROR,
  3587. "%s: Retrieve scan data failed rc = %d\n",
  3588. __func__, rc);
  3589. return rc;
  3590. }
  3591. /*******************************************************************************
  3592. * FUNCTION: pt_get_data_structure_cmd_
  3593. *
  3594. * SUMMARY: Non-protected wrapper function for get data structure command
  3595. *
  3596. * RETURN:
  3597. * 0 = success
  3598. * !0 = failure
  3599. *
  3600. * PARAMETERS:
  3601. * *dev - pointer to device structure
  3602. * read_offset - read pointer offset
  3603. * read_length - length of data to read
  3604. * data_id - data ID to read
  3605. * *status - pointer to store the read response status
  3606. * *data_format - pointer to store format of data read
  3607. * *actual_read_len - pointer to store data length actually read
  3608. * *data - pointer to store data read
  3609. ******************************************************************************/
  3610. static int pt_get_data_structure_cmd_(struct device *dev, u16 read_offset,
  3611. u16 read_length, u8 data_id, u8 *status, u8 *data_format,
  3612. u16 *actual_read_len, u8 *data)
  3613. {
  3614. int rc;
  3615. rc = cmd->nonhid_cmd->get_data_structure(dev, 0, read_offset,
  3616. read_length, data_id, status, data_format,
  3617. actual_read_len, data);
  3618. if (rc)
  3619. pt_debug(dev, DL_ERROR,
  3620. "%s: Get data structure failed rc = %d\n",
  3621. __func__, rc);
  3622. return rc;
  3623. }
  3624. /*******************************************************************************
  3625. * FUNCTION: pt_run_selftest_cmd_
  3626. *
  3627. * SUMMARY: Non-protected wrapper function for run self test command
  3628. *
  3629. * RETURN:
  3630. * 0 = success
  3631. * !0 = failure
  3632. *
  3633. * PARAMETERS:
  3634. * *dev - pointer to device structure
  3635. * test_id - enumerated test ID to run
  3636. * write_idacs_to_flash - flag whether to write new IDACS to flash
  3637. * *status - pointer to store the read response status
  3638. * *summary_results - pointer to store the results summary
  3639. * *results_available - pointer to store if results are available
  3640. ******************************************************************************/
  3641. static int pt_run_selftest_cmd_(struct device *dev, u8 test_id,
  3642. u8 write_idacs_to_flash, u8 *status, u8 *summary_result,
  3643. u8 *results_available)
  3644. {
  3645. int rc;
  3646. rc = cmd->nonhid_cmd->run_selftest(dev, 0, test_id,
  3647. write_idacs_to_flash, status, summary_result,
  3648. results_available);
  3649. if (rc)
  3650. pt_debug(dev, DL_ERROR, "%s: Run self test failed rc = %d\n",
  3651. __func__, rc);
  3652. return rc;
  3653. }
  3654. /*******************************************************************************
  3655. * FUNCTION: pt_get_selftest_result_cmd_
  3656. *
  3657. * SUMMARY: Non-protected wrapper function for get self test result command
  3658. *
  3659. * RETURN:
  3660. * 0 = success
  3661. * !0 = failure
  3662. *
  3663. * PARAMETERS:
  3664. * *dev - pointer to device structure
  3665. * read_offset - read pointer offset
  3666. * read_length - length of data to read
  3667. * test_id - enumerated test ID to read selftest results from
  3668. * *status - pointer to store the read response status
  3669. * *actual_read_len - pointer to store data length actually read
  3670. * *data - pointer to where the data read is stored
  3671. ******************************************************************************/
  3672. static int pt_get_selftest_result_cmd_(struct device *dev,
  3673. u16 read_offset, u16 read_length, u8 test_id, u8 *status,
  3674. u16 *actual_read_len, u8 *data)
  3675. {
  3676. int rc;
  3677. rc = cmd->nonhid_cmd->get_selftest_result(dev, 0, read_offset,
  3678. read_length, test_id, status, actual_read_len, data);
  3679. if (rc)
  3680. pt_debug(dev, DL_ERROR,
  3681. "%s: Get self test result failed rc = %d\n",
  3682. __func__, rc);
  3683. return rc;
  3684. }
  3685. /*******************************************************************************
  3686. * FUNCTION: _pt_calibrate_ext_cmd
  3687. *
  3688. * SUMMARY: Wrapper function to function calibrate_ext() in pt_core_commands
  3689. * structure
  3690. *
  3691. * RETURN:
  3692. * 0 = success
  3693. * !0 = failure
  3694. *
  3695. * PARAMETERS:
  3696. * *dev - pointer to device structure
  3697. * *cal_data - pointer to extended calibration data structure
  3698. * *status - pointer to where the command response status is stored
  3699. ******************************************************************************/
  3700. static int _pt_calibrate_ext_cmd(struct device *dev,
  3701. struct pt_cal_ext_data *cal_data, u8 *status)
  3702. {
  3703. int rc;
  3704. rc = cmd->nonhid_cmd->calibrate_ext(dev,
  3705. PT_CORE_CMD_UNPROTECTED, cal_data, status);
  3706. return rc;
  3707. }
  3708. /*******************************************************************************
  3709. * FUNCTION: _pt_calibrate_idacs_cmd
  3710. *
  3711. * SUMMARY: Wrapper function to function calibrate_idacs() in pt_core_commands
  3712. * structure
  3713. *
  3714. * RETURN:
  3715. * 0 = success
  3716. * !0 = failure
  3717. *
  3718. * PARAMETERS:
  3719. * *dev - pointer to device structure
  3720. * sensing_mode - sense mode to calibrate (0-5)
  3721. * *status - pointer to where the command response status is stored
  3722. ******************************************************************************/
  3723. static int _pt_calibrate_idacs_cmd(struct device *dev,
  3724. u8 sensing_mode, u8 *status)
  3725. {
  3726. int rc;
  3727. rc = cmd->nonhid_cmd->calibrate_idacs(dev, 0, sensing_mode, status);
  3728. return rc;
  3729. }
  3730. /*******************************************************************************
  3731. * FUNCTION: _pt_initialize_baselines_cmd
  3732. *
  3733. * SUMMARY: Wrapper function to call initialize_baselines() in pt_core_commands
  3734. * structure
  3735. *
  3736. * RETURN:
  3737. * 0 = success
  3738. * !0 = failure
  3739. *
  3740. * PARAMETERS:
  3741. * *dev - pointer to device structure
  3742. * sensing_mode - enumerated ID against which to initialize the baseline
  3743. * *status - pointer to where the command response statas is stored
  3744. ******************************************************************************/
  3745. static int _pt_initialize_baselines_cmd(struct device *dev,
  3746. u8 sensing_mode, u8 *status)
  3747. {
  3748. int rc;
  3749. rc = cmd->nonhid_cmd->initialize_baselines(dev, 0, sensing_mode,
  3750. status);
  3751. return rc;
  3752. }
  3753. /*******************************************************************************
  3754. * FUNCTION: pt_perform_calibration
  3755. *
  3756. * SUMMARY: For Gen5/6, Send the PIP1 Calibrate IDACs command (0x28). For TT/TC,
  3757. * send PIP1 Extended Calibrate command (0x30).
  3758. *
  3759. * NOTE: Panel scan must be suspended prior to calling this function.
  3760. *
  3761. * RETURN:
  3762. * 0 = success
  3763. * !0 = failure
  3764. *
  3765. * PARAMETERS:
  3766. * *dev - pointer to device structure
  3767. ******************************************************************************/
  3768. static int pt_perform_calibration(struct device *dev)
  3769. {
  3770. struct pt_cal_ext_data cal_data = {0};
  3771. u8 dut_gen = cmd->request_dut_generation(dev);
  3772. u8 mode;
  3773. u8 status;
  3774. int rc;
  3775. if (dut_gen == DUT_PIP1_ONLY) {
  3776. for (mode = 0; mode < 3; mode++) {
  3777. rc = _pt_calibrate_idacs_cmd(dev, mode, &status);
  3778. if (rc < 0) {
  3779. pt_debug(dev, DL_ERROR,
  3780. "%s: calibrate idac error, mode= %d, rc = %d\n",
  3781. __func__, mode, rc);
  3782. break;
  3783. }
  3784. }
  3785. } else {
  3786. memset(&cal_data, 0, sizeof(struct pt_cal_ext_data));
  3787. rc = _pt_calibrate_ext_cmd(dev, &cal_data, &status);
  3788. if (rc < 0)
  3789. pt_debug(dev, DL_ERROR,
  3790. "%s: extended calibrate error, rc = %d\n",
  3791. __func__, rc);
  3792. }
  3793. return rc;
  3794. }
  3795. /*******************************************************************************
  3796. * FUNCTION: prepare_print_buffer
  3797. *
  3798. * SUMMARY: Format input buffer to out buffer with Hex base,and format "status"
  3799. * to decimal base.
  3800. *
  3801. * RETURN:
  3802. * size of formated data in output buffer
  3803. *
  3804. * PARAMETERS:
  3805. * status - Indicate test result:0(STATUS_SUCCESS),-1(STATUS_FAIL)
  3806. * *in_buf - input buffer to be formated
  3807. * length - length of input buffer
  3808. * *out_buf - output buffer to store formated data
  3809. * out_buf_size - length of output buffer
  3810. * out_format - format of output data (5 supported formats):
  3811. * PT_PR_FORMAT_DEFAULT : format all data as a column
  3812. * PT_PR_FORMAT_U8_SPACE : sort status bytes and self test results,
  3813. * and format the results as a row, each element include 1 byte
  3814. * PT_PR_FORMAT_U16_SPACE : sort status bytes and self test results,
  3815. * and format the results as a row, each element include 2 byte
  3816. * PT_PR_FORMAT_U8_NO_SPACE : sort status bytes and self test results,
  3817. * and format the results as a row, no space between the elements
  3818. * PT_PR_FORMAT_U32_SPACE : sort status bytes and self test results,
  3819. * and format the results as a row, each element include 4 byte
  3820. ******************************************************************************/
  3821. static int prepare_print_buffer(int status, u8 *in_buf, int length,
  3822. u8 *out_buf, size_t out_buf_size, u8 out_format)
  3823. {
  3824. int index = 0;
  3825. int data_length;
  3826. int i;
  3827. index += scnprintf(out_buf, out_buf_size, "Status: %d\n", status);
  3828. if (out_format == PT_PR_FORMAT_DEFAULT) {
  3829. for (i = 0; i < length; i++)
  3830. index += scnprintf(&out_buf[index],
  3831. out_buf_size - index,
  3832. "%02X\n", in_buf[i]);
  3833. } else {
  3834. index += scnprintf(&out_buf[index],
  3835. out_buf_size - index,
  3836. "Response Status[1-%d]: ", MIN(length, 3));
  3837. for (i = 0; i < MIN(length, 3); i++)
  3838. index += scnprintf(&out_buf[index],
  3839. out_buf_size - index,
  3840. "%02X ", in_buf[i]);
  3841. index += scnprintf(&out_buf[index], out_buf_size - index, "\n");
  3842. if (length <= 6) {
  3843. goto exit;
  3844. } else {
  3845. data_length = get_unaligned_le16(&in_buf[4]);
  3846. index += scnprintf(&out_buf[index],
  3847. out_buf_size - index, "RAW_DATA: ");
  3848. }
  3849. if (out_format == PT_PR_FORMAT_U8_SPACE) {
  3850. for (i = 6; i < length; i++)
  3851. index += scnprintf(&out_buf[index],
  3852. out_buf_size - index,
  3853. "%02X ", in_buf[i]);
  3854. index += scnprintf(&out_buf[index],
  3855. out_buf_size - index,
  3856. ":(%d bytes)\n", data_length);
  3857. } else if (out_format == PT_PR_FORMAT_U16_SPACE) {
  3858. for (i = 6; (i + 1) < length; i += 2)
  3859. index += scnprintf(&out_buf[index],
  3860. out_buf_size - index, "%04X ",
  3861. get_unaligned_le16(&in_buf[i]));
  3862. index += scnprintf(&out_buf[index],
  3863. out_buf_size - index,
  3864. ":(%d words)\n", (length-6)/2);
  3865. } else if (out_format == PT_PR_FORMAT_U8_NO_SPACE) {
  3866. for (i = 6; i < length; i++)
  3867. index += scnprintf(&out_buf[index],
  3868. out_buf_size - index,
  3869. "%02X", in_buf[i]);
  3870. index += scnprintf(&out_buf[index],
  3871. out_buf_size - index,
  3872. ":(%d bytes)\n", data_length);
  3873. } else if (out_format == PT_PR_FORMAT_U32_SPACE) {
  3874. for (i = 6; (i + 1) < length; i += 4)
  3875. index += scnprintf(&out_buf[index],
  3876. out_buf_size - index, "%08X ",
  3877. get_unaligned_le32(&in_buf[i]));
  3878. index += scnprintf(&out_buf[index],
  3879. out_buf_size - index,
  3880. ":(%d 32bit values)\n", (length-6)/4);
  3881. }
  3882. }
  3883. exit:
  3884. return index;
  3885. }
  3886. /*******************************************************************************
  3887. * FUNCTION: pt_run_and_get_selftest_result
  3888. *
  3889. * SUMMARY: Run the selftest and store the test result in the
  3890. * pt_device_access_data struct.
  3891. *
  3892. * RETURN:
  3893. * >0 : Size of debugfs data to print
  3894. * <0 : failure
  3895. * 0 : success
  3896. *
  3897. * NOTE: "Status: x" - x will contain the first error code if any
  3898. *
  3899. * PARAMETERS:
  3900. * *dev - pointer to device structure
  3901. * protect - flag to call protected or non-protected
  3902. * *buf - pointer to print buf of return data
  3903. * buf_len - length of print buf of return data
  3904. * test_id - selftest id
  3905. * read_length - max length to stor return data
  3906. * get_result_on_pass - indicate whether to get result when finish test
  3907. * print_results - print results to log
  3908. * (true:get result;false:don't get result )
  3909. * print_format - format of print results
  3910. ******************************************************************************/
  3911. static ssize_t pt_run_and_get_selftest_result(struct device *dev,
  3912. int protect, char *buf, size_t buf_len, u8 test_id,
  3913. u16 read_length, bool get_result_on_pass, bool print_results,
  3914. u8 print_format)
  3915. {
  3916. struct pt_device_access_data *dad = pt_get_device_access_data(dev);
  3917. int status = STATUS_SUCCESS;
  3918. u8 cmd_status = STATUS_SUCCESS;
  3919. u8 summary_result = 0;
  3920. u8 sys_mode = FW_SYS_MODE_UNDEFINED;
  3921. u16 act_length = 0;
  3922. int length = 0;
  3923. int size = 0;
  3924. int rc;
  3925. mutex_lock(&dad->sysfs_lock);
  3926. pm_runtime_get_sync(dev);
  3927. if (protect == PT_CORE_CMD_PROTECTED) {
  3928. rc = cmd->request_exclusive(dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
  3929. if (rc) {
  3930. pt_debug(dev, DL_ERROR,
  3931. "%s: Error on request exclusive rc = %d\n",
  3932. __func__, rc);
  3933. status = -EPERM;
  3934. goto put_pm_runtime;
  3935. }
  3936. }
  3937. /* Get the current scan state so we restore to the same at the end */
  3938. rc = cmd->request_get_fw_mode(dev, PT_CORE_CMD_UNPROTECTED, &sys_mode,
  3939. NULL);
  3940. if (rc) {
  3941. status = rc;
  3942. goto release_exclusive;
  3943. }
  3944. if (sys_mode != FW_SYS_MODE_TEST) {
  3945. rc = pt_suspend_scan_cmd_(dev);
  3946. if (rc) {
  3947. pt_debug(dev, DL_ERROR,
  3948. "%s: Error on suspend scan rc = %d\n",
  3949. __func__, rc);
  3950. status = -EPERM;
  3951. goto release_exclusive;
  3952. }
  3953. }
  3954. /* Sleep for 20ms to allow the last scan to be available in FW */
  3955. msleep(20);
  3956. rc = pt_run_selftest_cmd_(dev, test_id, 0,
  3957. &cmd_status, &summary_result, NULL);
  3958. if (rc) {
  3959. /* Error sending self test */
  3960. pt_debug(dev, DL_ERROR,
  3961. "%s: Error on run self test for test_id:%d rc = %d\n",
  3962. __func__, test_id, rc);
  3963. status = rc;
  3964. goto resume_scan;
  3965. }
  3966. if (cmd_status) {
  3967. /* Self test response status failure */
  3968. pt_debug(dev, DL_WARN,
  3969. "%s: Test ID: 0x%02X resulted in status: 0x%02X\n",
  3970. __func__, test_id, cmd_status);
  3971. status = cmd_status;
  3972. }
  3973. dad->si = cmd->request_sysinfo(dad->dev);
  3974. if (!dad->si) {
  3975. pt_debug(dad->dev, DL_ERROR,
  3976. "%s: Fail get sysinfo pointer from core\n", __func__);
  3977. if (status == STATUS_SUCCESS)
  3978. status = -EINVAL;
  3979. goto resume_scan;
  3980. }
  3981. if (IS_PIP_VER_GE(dad->si, 1, 11)) {
  3982. /* PIP1.11+ does not report the summary_result in byte 6 */
  3983. summary_result = cmd_status;
  3984. }
  3985. /* Form response buffer */
  3986. dad->ic_buf[0] = cmd_status;
  3987. dad->ic_buf[1] = summary_result;
  3988. pt_debug(dev, DL_INFO, "%s: Run Self Test cmd status = %d\n",
  3989. __func__, cmd_status);
  3990. pt_debug(dev, DL_INFO, "%s: Run Self Test result summary = %d\n",
  3991. __func__, summary_result);
  3992. length = 2;
  3993. /*
  3994. * Get data if requested and the cmd status indicates that the test
  3995. * completed with either a pass or a fail. All other status codes
  3996. * indicate the test itself was not run so there is no data to retrieve
  3997. */
  3998. if ((cmd_status == PT_ST_RESULT_PASS ||
  3999. cmd_status == PT_ST_RESULT_FAIL) && get_result_on_pass) {
  4000. rc = pt_get_selftest_result_cmd_(dev, 0, read_length,
  4001. test_id, &cmd_status, &act_length, &dad->ic_buf[6]);
  4002. if (rc) {
  4003. pt_debug(dev, DL_ERROR,
  4004. "%s: Error on get self test result rc = %d\n",
  4005. __func__, rc);
  4006. if (status == STATUS_SUCCESS)
  4007. status = rc;
  4008. goto resume_scan;
  4009. }
  4010. pt_debug(dev, DL_INFO, "%s: Get Self Test result status = %d\n",
  4011. __func__, cmd_status);
  4012. /* Only store new status if no error on running self test */
  4013. if (status == STATUS_SUCCESS)
  4014. status = cmd_status;
  4015. dad->ic_buf[2] = cmd_status;
  4016. dad->ic_buf[3] = test_id;
  4017. dad->ic_buf[4] = LOW_BYTE(act_length);
  4018. dad->ic_buf[5] = HI_BYTE(act_length);
  4019. length = 6 + act_length;
  4020. }
  4021. resume_scan:
  4022. /* Only resume scanning if we suspended it */
  4023. if (sys_mode == FW_SYS_MODE_SCANNING)
  4024. pt_resume_scan_cmd_(dev);
  4025. release_exclusive:
  4026. if (protect == PT_CORE_CMD_PROTECTED)
  4027. cmd->release_exclusive(dev);
  4028. put_pm_runtime:
  4029. pm_runtime_put(dev);
  4030. /* Communication error */
  4031. if (status < 0)
  4032. length = 0;
  4033. if (print_results) {
  4034. size = prepare_print_buffer(status, dad->ic_buf, length,
  4035. buf, buf_len, print_format);
  4036. rc = size;
  4037. }
  4038. mutex_unlock(&dad->sysfs_lock);
  4039. return rc;
  4040. }
  4041. struct pt_device_access_debugfs_data {
  4042. struct pt_device_access_data *dad;
  4043. ssize_t pr_buf_len;
  4044. u8 pr_buf[10 * PT_MAX_PRBUF_SIZE];
  4045. };
  4046. /*******************************************************************************
  4047. * FUNCTION: pt_device_access_debugfs_open
  4048. *
  4049. * SUMMARY: Open the device_access debugfs node to initialize.
  4050. *
  4051. * RETURN:
  4052. * 0 = success
  4053. * !0 = failure
  4054. *
  4055. * PARAMETERS:
  4056. * *inode - pointer to inode structure
  4057. * *filp - pointer to file structure
  4058. ******************************************************************************/
  4059. static int pt_device_access_debugfs_open(struct inode *inode,
  4060. struct file *filp)
  4061. {
  4062. struct pt_device_access_data *dad = inode->i_private;
  4063. struct pt_device_access_debugfs_data *data;
  4064. data = kzalloc(sizeof(*data), GFP_KERNEL);
  4065. if (!data)
  4066. return -ENOMEM;
  4067. data->dad = dad;
  4068. filp->private_data = data;
  4069. return nonseekable_open(inode, filp);
  4070. }
  4071. /*******************************************************************************
  4072. * FUNCTION: pt_device_access_debugfs_release
  4073. *
  4074. * SUMMARY: Close the device_access debugfs node to free pointer.
  4075. *
  4076. * RETURN:
  4077. * 0 = success
  4078. * !0 = failure
  4079. *
  4080. * PARAMETERS:
  4081. * *inode - pointer to inode structure
  4082. * *filp - pointer to file structure
  4083. ******************************************************************************/
  4084. static int pt_device_access_debugfs_release(struct inode *inode,
  4085. struct file *filp)
  4086. {
  4087. kfree(filp->private_data);
  4088. return 0;
  4089. }
  4090. #define PT_DEBUGFS_FOPS(_name, _read, _write) \
  4091. static const struct file_operations _name##_debugfs_fops = { \
  4092. .open = pt_device_access_debugfs_open, \
  4093. .release = pt_device_access_debugfs_release, \
  4094. .read = _read, \
  4095. .write = _write, \
  4096. }
  4097. /*******************************************************************************
  4098. * FUNCTION: panel_scan_debugfs_read
  4099. *
  4100. * SUMMARY: This function retrieves a full panel scan by sending the following
  4101. * PIP commands:
  4102. * 1) Suspend Scanning
  4103. * 2) Execute Panel Scan
  4104. * 3) Retrieve Panel Scan (n times to retrieve full scan)
  4105. * 4) Resume Scanning
  4106. *
  4107. * RETURN: Size of debugfs data print
  4108. *
  4109. * PARAMETERS:
  4110. * *filp - file pointer to debugfs file
  4111. * *buf - the user space buffer to read to
  4112. * count - the maximum number of bytes to read
  4113. * *ppos - the current position in the buffer
  4114. ******************************************************************************/
  4115. static ssize_t panel_scan_debugfs_read(struct file *filp, char __user *buf,
  4116. size_t count, loff_t *ppos)
  4117. {
  4118. struct pt_device_access_debugfs_data *data = filp->private_data;
  4119. struct pt_device_access_data *dad = data->dad;
  4120. struct device *dev = dad->dev;
  4121. struct pt_core_data *cd = dev_get_drvdata(dev);
  4122. int status = STATUS_FAIL;
  4123. u8 config;
  4124. u16 num_elem_read;
  4125. int length = 0;
  4126. u8 element_size = 0;
  4127. u8 *buf_out;
  4128. u8 *buf_offset;
  4129. u8 sys_mode = FW_SYS_MODE_UNDEFINED;
  4130. int elem_offset = 0;
  4131. int rc;
  4132. int print_idx = 0;
  4133. int i;
  4134. mutex_lock(&dad->debugfs_lock);
  4135. buf_out = dad->panel_scan_data_buf;
  4136. if (!buf_out)
  4137. goto release_mutex;
  4138. pm_runtime_get_sync(dev);
  4139. /*
  4140. * This function will re-enter if the panel_scan_size is greater than
  4141. * count (count is the kernel page size which is typically 4096), on
  4142. * re-entry, *ppos will retain how far the last copy to user space
  4143. * completed
  4144. */
  4145. if (*ppos) {
  4146. if (*ppos >= dad->panel_scan_size)
  4147. goto release_mutex;
  4148. print_idx = simple_read_from_buffer(buf, count, ppos,
  4149. buf_out, dad->panel_scan_size);
  4150. pt_debug(dev, DL_DEBUG, "%s: Sent %d bytes to user space\n",
  4151. __func__, print_idx);
  4152. goto release_mutex;
  4153. }
  4154. rc = cmd->request_exclusive(dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
  4155. if (rc) {
  4156. pt_debug(dev, DL_ERROR,
  4157. "%s: Error on request exclusive rc = %d\n",
  4158. __func__, rc);
  4159. goto put_pm_runtime;
  4160. }
  4161. /* Get the current scan state so we restore to the same at the end */
  4162. rc = cmd->request_get_fw_mode(dev, PT_CORE_CMD_UNPROTECTED, &sys_mode,
  4163. NULL);
  4164. if (rc) {
  4165. status = rc;
  4166. goto release_exclusive;
  4167. }
  4168. if (sys_mode != FW_SYS_MODE_TEST) {
  4169. rc = pt_suspend_scan_cmd_(dev);
  4170. if (rc) {
  4171. pt_debug(dev, DL_ERROR,
  4172. "%s: Error on suspend scan rc = %d\n",
  4173. __func__, rc);
  4174. goto release_exclusive;
  4175. }
  4176. }
  4177. rc = pt_exec_scan_cmd_(dev, dad->panel_scan_type_id);
  4178. if (rc) {
  4179. pt_debug(dev, DL_ERROR,
  4180. "%s: Error on execute panel scan rc = %d\n",
  4181. __func__, rc);
  4182. goto resume_scan;
  4183. }
  4184. /* Set length to max to read all */
  4185. rc = pt_ret_scan_data_cmd_(dev, 0, 0xFFFF,
  4186. dad->panel_scan_retrieve_id, dad->ic_buf, &config,
  4187. &num_elem_read, NULL);
  4188. if (rc) {
  4189. pt_debug(dev, DL_ERROR,
  4190. "%s: Error on retrieve panel scan rc = %d\n",
  4191. __func__, rc);
  4192. goto resume_scan;
  4193. }
  4194. length = get_unaligned_le16(&dad->ic_buf[0]);
  4195. buf_offset = dad->ic_buf + length;
  4196. element_size = config & 0x07;
  4197. elem_offset = num_elem_read;
  4198. while (num_elem_read > 0) {
  4199. rc = pt_ret_scan_data_cmd_(dev, elem_offset, 0xFFFF,
  4200. dad->panel_scan_retrieve_id, NULL, &config,
  4201. &num_elem_read, buf_offset);
  4202. if (rc)
  4203. goto resume_scan;
  4204. length += num_elem_read * element_size;
  4205. buf_offset = dad->ic_buf + length;
  4206. elem_offset += num_elem_read;
  4207. if (num_elem_read < 0x7A)
  4208. break;
  4209. }
  4210. /* Reconstruct cmd header */
  4211. put_unaligned_le16(length, &dad->ic_buf[0]);
  4212. put_unaligned_le16(elem_offset, &dad->ic_buf[7]);
  4213. status = STATUS_SUCCESS;
  4214. resume_scan:
  4215. /* Only resume scanning if we suspended it */
  4216. if (sys_mode == FW_SYS_MODE_SCANNING)
  4217. pt_resume_scan_cmd_(dev);
  4218. release_exclusive:
  4219. cmd->release_exclusive(dev);
  4220. put_pm_runtime:
  4221. pm_runtime_put(dev);
  4222. if (status == STATUS_FAIL)
  4223. length = 0;
  4224. if (cd->show_timestamp)
  4225. print_idx += scnprintf(buf_out + print_idx, TTHE_TUNER_MAX_BUF,
  4226. "[%u] SCAN_DATA:", pt_get_time_stamp());
  4227. else
  4228. print_idx += scnprintf(buf_out + print_idx, TTHE_TUNER_MAX_BUF,
  4229. "SCAN_DATA:");
  4230. for (i = 0; i < length; i++)
  4231. print_idx += scnprintf(buf_out + print_idx,
  4232. TTHE_TUNER_MAX_BUF - print_idx,
  4233. "%02X ", dad->ic_buf[i]);
  4234. print_idx += scnprintf(buf_out + print_idx,
  4235. TTHE_TUNER_MAX_BUF - print_idx,
  4236. ":(%d bytes)\n", length);
  4237. /*
  4238. * Save the size of the full scan which this function uses on re-entry
  4239. * to send the data back to user space in 'count' size chuncks
  4240. */
  4241. dad->panel_scan_size = print_idx;
  4242. print_idx = simple_read_from_buffer(buf, count, ppos, buf_out,
  4243. print_idx);
  4244. pt_debug(dev, DL_DEBUG, "%s: Sent %d bytes to user space\n",
  4245. __func__, print_idx);
  4246. release_mutex:
  4247. mutex_unlock(&dad->debugfs_lock);
  4248. return print_idx;
  4249. }
  4250. /*******************************************************************************
  4251. * FUNCTION: panel_scan_debugfs_write
  4252. *
  4253. * SUMMARY: Store the type of panel scan the read method will perform.
  4254. *
  4255. * RETURN: Size of debugfs data write
  4256. *
  4257. * PARAMETERS:
  4258. * *filp - file pointer to debugfs file
  4259. * *buf - the user space buffer to write to
  4260. * count - the maximum number of bytes to write
  4261. * *ppos - the current position in the buffer
  4262. ******************************************************************************/
  4263. static ssize_t panel_scan_debugfs_write(struct file *filp,
  4264. const char __user *buf, size_t count, loff_t *ppos)
  4265. {
  4266. struct pt_device_access_debugfs_data *data = filp->private_data;
  4267. struct pt_device_access_data *dad = data->dad;
  4268. ssize_t length;
  4269. u32 input_data[3];
  4270. int rc = 0;
  4271. rc = simple_write_to_buffer(data->pr_buf, sizeof(data->pr_buf), ppos,
  4272. buf, count);
  4273. if (rc < 0)
  4274. return rc;
  4275. count = rc;
  4276. mutex_lock(&dad->debugfs_lock);
  4277. length = cmd->parse_sysfs_input(dad->dev, data->pr_buf, count,
  4278. input_data, ARRAY_SIZE(input_data));
  4279. switch (length) {
  4280. case 1:
  4281. dad->panel_scan_retrieve_id = input_data[0];
  4282. dad->panel_scan_type_id = 0;
  4283. break;
  4284. case 2:
  4285. dad->panel_scan_retrieve_id = input_data[0];
  4286. dad->panel_scan_type_id = input_data[1];
  4287. break;
  4288. default:
  4289. pt_debug(dad->dev, DL_ERROR,
  4290. "%s: Malformed input\n", __func__);
  4291. rc = -EINVAL;
  4292. }
  4293. mutex_unlock(&dad->debugfs_lock);
  4294. if (rc)
  4295. return rc;
  4296. return count;
  4297. }
  4298. /*******************************************************************************
  4299. * FUNCTION: panel_scan_debugfs_open
  4300. *
  4301. * SUMMARY: Open the panel_scan debugfs node to initialize.
  4302. *
  4303. * RETURN: 0 = success
  4304. * !0 = failure
  4305. *
  4306. * PARAMETERS:
  4307. * *inode - file inode number
  4308. * *filp - file pointer to debugfs file
  4309. ******************************************************************************/
  4310. static int panel_scan_debugfs_open(struct inode *inode,
  4311. struct file *filp)
  4312. {
  4313. struct pt_device_access_data *dad = inode->i_private;
  4314. struct pt_device_access_debugfs_data *data;
  4315. data = kzalloc(sizeof(*data), GFP_KERNEL);
  4316. if (!data)
  4317. return -ENOMEM;
  4318. data->dad = dad;
  4319. data->pr_buf_len = 4 * PT_MAX_PRBUF_SIZE;
  4320. filp->private_data = data;
  4321. return nonseekable_open(inode, filp);
  4322. }
  4323. /*******************************************************************************
  4324. * FUNCTION: panel_scan_debugfs_close
  4325. *
  4326. * SUMMARY: Close the panel_scan debugfs node to free pointer.
  4327. *
  4328. * RETURN: 0 = success
  4329. *
  4330. * PARAMETERS:
  4331. * *inode - file inode number
  4332. * *filp - file pointer to debugfs file
  4333. ******************************************************************************/
  4334. static int panel_scan_debugfs_close(struct inode *inode,
  4335. struct file *filp)
  4336. {
  4337. kfree(filp->private_data);
  4338. filp->private_data = NULL;
  4339. return 0;
  4340. }
  4341. static const struct file_operations panel_scan_fops = {
  4342. .open = panel_scan_debugfs_open,
  4343. .release = panel_scan_debugfs_close,
  4344. .read = panel_scan_debugfs_read,
  4345. .write = panel_scan_debugfs_write,
  4346. };
  4347. /*******************************************************************************
  4348. * FUNCTION: get_idac_debugfs_read
  4349. *
  4350. * SUMMARY: Retrieve data structure with idac data id by sending the following
  4351. * PIP commands:
  4352. * 1) Suspend Scanning
  4353. * 2) Retrieve data structure
  4354. * 3) Resume Scanning
  4355. * The "Status: n" this node prints, 'n' will be:
  4356. * - zero for a full pass
  4357. * - negative for TTDL communication errors
  4358. * - positive for any FW status errors
  4359. *
  4360. * RETURN: Size of debugfs data print
  4361. *
  4362. * PARAMETERS:
  4363. * *filp - file pointer to debugfs file
  4364. * *buf - the user space buffer to read to
  4365. * count - the maximum number of bytes to read
  4366. * *ppos - the current position in the buffer
  4367. ******************************************************************************/
  4368. static ssize_t get_idac_debugfs_read(struct file *filp, char __user *buf,
  4369. size_t count, loff_t *ppos)
  4370. {
  4371. struct pt_device_access_debugfs_data *data = filp->private_data;
  4372. struct pt_device_access_data *dad = data->dad;
  4373. struct device *dev = dad->dev;
  4374. int status = STATUS_FAIL;
  4375. u8 cmd_status = 0;
  4376. u8 data_format = 0;
  4377. u16 act_length = 0;
  4378. int length = 0;
  4379. int rc;
  4380. if (*ppos)
  4381. goto exit;
  4382. mutex_lock(&dad->sysfs_lock);
  4383. pm_runtime_get_sync(dev);
  4384. rc = cmd->request_exclusive(dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
  4385. if (rc) {
  4386. status = rc;
  4387. pt_debug(dev, DL_ERROR,
  4388. "%s: Error on request exclusive rc = %d\n",
  4389. __func__, rc);
  4390. goto put_pm_runtime;
  4391. }
  4392. rc = pt_suspend_scan_cmd_(dev);
  4393. if (rc) {
  4394. status = rc;
  4395. pt_debug(dev, DL_ERROR, "%s: Error on suspend scan rc = %d\n",
  4396. __func__, rc);
  4397. goto release_exclusive;
  4398. }
  4399. rc = pt_get_data_structure_cmd_(dev, 0, PIP_CMD_MAX_LENGTH,
  4400. dad->get_idac_data_id, &cmd_status, &data_format,
  4401. &act_length, &dad->ic_buf[5]);
  4402. if (rc) {
  4403. status = rc;
  4404. pt_debug(dev, DL_ERROR,
  4405. "%s: Error on get data structure rc = %d\n",
  4406. __func__, rc);
  4407. goto resume_scan;
  4408. }
  4409. dad->ic_buf[0] = cmd_status;
  4410. dad->ic_buf[1] = dad->get_idac_data_id;
  4411. dad->ic_buf[2] = LOW_BYTE(act_length);
  4412. dad->ic_buf[3] = HI_BYTE(act_length);
  4413. dad->ic_buf[4] = data_format;
  4414. length = 5 + act_length;
  4415. status = cmd_status;
  4416. resume_scan:
  4417. pt_resume_scan_cmd_(dev);
  4418. release_exclusive:
  4419. cmd->release_exclusive(dev);
  4420. put_pm_runtime:
  4421. pm_runtime_put(dev);
  4422. if (status == STATUS_FAIL)
  4423. length = 0;
  4424. data->pr_buf_len = prepare_print_buffer(status, dad->ic_buf, length,
  4425. data->pr_buf, sizeof(data->pr_buf), PT_PR_FORMAT_DEFAULT);
  4426. mutex_unlock(&dad->sysfs_lock);
  4427. exit:
  4428. return simple_read_from_buffer(buf, count, ppos, data->pr_buf,
  4429. data->pr_buf_len);
  4430. }
  4431. /*******************************************************************************
  4432. * FUNCTION: get_idac_debugfs_write
  4433. *
  4434. * SUMMARY: Store the data id of idac,the read method will perform.
  4435. *
  4436. * RETURN: Size of debugfs data write
  4437. *
  4438. * PARAMETERS:
  4439. * *filp - file pointer to debugfs file
  4440. * *buf - the user space buffer to write to
  4441. * count - the maximum number of bytes to write
  4442. * *ppos - the current position in the buffer
  4443. ******************************************************************************/
  4444. static ssize_t get_idac_debugfs_write(struct file *filp,
  4445. const char __user *buf, size_t count, loff_t *ppos)
  4446. {
  4447. struct pt_device_access_debugfs_data *data = filp->private_data;
  4448. struct pt_device_access_data *dad = data->dad;
  4449. ssize_t length;
  4450. u32 input_data[2];
  4451. int rc = 0;
  4452. rc = simple_write_to_buffer(data->pr_buf, sizeof(data->pr_buf), ppos,
  4453. buf, count);
  4454. if (rc < 0)
  4455. return rc;
  4456. count = rc;
  4457. mutex_lock(&dad->sysfs_lock);
  4458. length = cmd->parse_sysfs_input(dad->dev, data->pr_buf, count,
  4459. input_data, ARRAY_SIZE(input_data));
  4460. if (length != 1) {
  4461. pt_debug(dad->dev, DL_ERROR,
  4462. "%s: Malformed input\n", __func__);
  4463. rc = -EINVAL;
  4464. goto exit_unlock;
  4465. }
  4466. dad->get_idac_data_id = input_data[0];
  4467. exit_unlock:
  4468. mutex_unlock(&dad->sysfs_lock);
  4469. if (rc)
  4470. return rc;
  4471. return count;
  4472. }
  4473. PT_DEBUGFS_FOPS(get_idac, get_idac_debugfs_read, get_idac_debugfs_write);
  4474. /*******************************************************************************
  4475. * FUNCTION: calibrate_ext_debugfs_read
  4476. *
  4477. * SUMMARY: Perform extended calibration command(0x30) which is flexible to
  4478. * calibrate each individual feature by adding extra parameter for calibration
  4479. * mode.
  4480. *
  4481. * NOTE:
  4482. * - This calibrate command requires the DUT to support PIP version >= 1.10
  4483. * - The "Status:" included in the printout will be one of the following:
  4484. * <0 - Linux error code (PIP transmission error)
  4485. * 0 - Full pass
  4486. * >0 - PIP error status
  4487. *
  4488. * RETURN: Size of debugfs data print
  4489. *
  4490. * PARAMETERS:
  4491. * *filp - file pointer to debugfs file
  4492. * *buf - the user space buffer to read to
  4493. * count - the maximum number of bytes to read
  4494. * *ppos - the current position in the buffer
  4495. ******************************************************************************/
  4496. static ssize_t calibrate_ext_debugfs_read(struct file *filp, char __user *buf,
  4497. size_t count, loff_t *ppos)
  4498. {
  4499. struct pt_device_access_debugfs_data *data = filp->private_data;
  4500. struct pt_device_access_data *dad = data->dad;
  4501. struct device *dev = dad->dev;
  4502. int status = STATUS_FAIL;
  4503. int length = 0;
  4504. int rc;
  4505. if (*ppos)
  4506. goto exit;
  4507. dad->si = cmd->request_sysinfo(dad->dev);
  4508. if (!dad->si) {
  4509. pt_debug(dad->dev, DL_ERROR,
  4510. "%s: Fail get sysinfo pointer from core\n",
  4511. __func__);
  4512. status = -EIO;
  4513. data->pr_buf_len = prepare_print_buffer(status, dad->ic_buf, 0,
  4514. data->pr_buf, sizeof(data->pr_buf),
  4515. PT_PR_FORMAT_DEFAULT);
  4516. goto exit;
  4517. }
  4518. if (!IS_PIP_VER_GE(dad->si, 1, 10)) {
  4519. pt_debug(dad->dev, DL_ERROR,
  4520. "%s: extended calibration command is not supported\n",
  4521. __func__);
  4522. status = -EPROTONOSUPPORT;
  4523. data->pr_buf_len = prepare_print_buffer(status, dad->ic_buf, 0,
  4524. data->pr_buf, sizeof(data->pr_buf),
  4525. PT_PR_FORMAT_DEFAULT);
  4526. goto exit;
  4527. }
  4528. if (dad->cal_ext_data.mode == PT_CAL_EXT_MODE_UNDEFINED) {
  4529. pt_debug(dad->dev, DL_ERROR,
  4530. "%s: No parameters provided for calibration command\n",
  4531. __func__);
  4532. status = -EINVAL;
  4533. data->pr_buf_len = prepare_print_buffer(status, dad->ic_buf, 0,
  4534. data->pr_buf, sizeof(data->pr_buf),
  4535. PT_PR_FORMAT_DEFAULT);
  4536. goto exit;
  4537. }
  4538. mutex_lock(&dad->sysfs_lock);
  4539. pm_runtime_get_sync(dev);
  4540. rc = cmd->request_exclusive(dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
  4541. if (rc) {
  4542. status = rc;
  4543. pt_debug(dev, DL_ERROR,
  4544. "%s: Error on request exclusive rc = %d\n",
  4545. __func__, rc);
  4546. goto put_pm_runtime;
  4547. }
  4548. rc = pt_suspend_scan_cmd_(dev);
  4549. if (rc) {
  4550. status = rc;
  4551. pt_debug(dev, DL_ERROR, "%s: Error on suspend scan rc = %d\n",
  4552. __func__, rc);
  4553. goto release_exclusive;
  4554. }
  4555. rc = _pt_calibrate_ext_cmd(dev, &dad->cal_ext_data, &dad->ic_buf[0]);
  4556. if (rc) {
  4557. status = rc;
  4558. pt_debug(dev, DL_ERROR,
  4559. "%s: Error on calibrate_ext rc = %d\n",
  4560. __func__, rc);
  4561. goto resume_scan;
  4562. }
  4563. /*
  4564. * Include PIP errors as positive status codes and report the data.
  4565. * No PIP error "0x00" in the response indicates full success
  4566. */
  4567. length = 1;
  4568. status = dad->ic_buf[0];
  4569. resume_scan:
  4570. pt_resume_scan_cmd_(dev);
  4571. release_exclusive:
  4572. cmd->release_exclusive(dev);
  4573. put_pm_runtime:
  4574. pm_runtime_put(dev);
  4575. /* Negative status codes are bus transmission errors and have no data */
  4576. if (status < 0)
  4577. length = 0;
  4578. data->pr_buf_len = prepare_print_buffer(status, dad->ic_buf, length,
  4579. data->pr_buf, sizeof(data->pr_buf), PT_PR_FORMAT_DEFAULT);
  4580. mutex_unlock(&dad->sysfs_lock);
  4581. exit:
  4582. return simple_read_from_buffer(buf, count, ppos, data->pr_buf,
  4583. data->pr_buf_len);
  4584. }
  4585. /*******************************************************************************
  4586. * FUNCTION: calibrate_ext_debugfs_write
  4587. *
  4588. * SUMMARY: Stores the calibration mode and up to three parameters to perform
  4589. * individual features.
  4590. *
  4591. * RETURN: Size of debugfs data write
  4592. *
  4593. * PARAMETERS:
  4594. * *filp - file pointer to debugfs file
  4595. * *buf - the user space buffer to write to
  4596. * count - the maximum number of bytes to write
  4597. * *ppos - the current position in the buffer
  4598. ******************************************************************************/
  4599. static ssize_t calibrate_ext_debugfs_write(struct file *filp,
  4600. const char __user *buf, size_t count, loff_t *ppos)
  4601. {
  4602. struct pt_device_access_debugfs_data *data = filp->private_data;
  4603. struct pt_device_access_data *dad = data->dad;
  4604. ssize_t length;
  4605. u32 input_data[5];
  4606. int rc = 0;
  4607. int i = 0;
  4608. rc = simple_write_to_buffer(data->pr_buf, sizeof(data->pr_buf), ppos,
  4609. buf, count);
  4610. if (rc < 0)
  4611. return rc;
  4612. count = rc;
  4613. mutex_lock(&dad->sysfs_lock);
  4614. length = cmd->parse_sysfs_input(dad->dev, data->pr_buf, count,
  4615. input_data, ARRAY_SIZE(input_data));
  4616. if ((length <= 4) && (length > 0)) {
  4617. for (i = length; i < 4; i++)
  4618. input_data[i] = 0;
  4619. dad->cal_ext_data.mode = (u8)input_data[0];
  4620. dad->cal_ext_data.data0 = (u8)input_data[1];
  4621. dad->cal_ext_data.data1 = (u8)input_data[2];
  4622. dad->cal_ext_data.data2 = (u8)input_data[3];
  4623. #ifdef TTDL_DIAGNOSTICS
  4624. pt_debug(dad->dev, DL_INFO,
  4625. "%s: calibration mode=%d, data[0..2]=0x%02X %02X %02X\n",
  4626. __func__,
  4627. dad->cal_ext_data.mode, dad->cal_ext_data.data0,
  4628. dad->cal_ext_data.data1, dad->cal_ext_data.data2);
  4629. #endif
  4630. } else {
  4631. pt_debug(dad->dev, DL_ERROR,
  4632. "%s: Malformed input\n", __func__);
  4633. rc = -EINVAL;
  4634. goto exit_unlock;
  4635. }
  4636. exit_unlock:
  4637. mutex_unlock(&dad->sysfs_lock);
  4638. if (rc)
  4639. return rc;
  4640. return count;
  4641. }
  4642. PT_DEBUGFS_FOPS(calibrate_ext,
  4643. calibrate_ext_debugfs_read, calibrate_ext_debugfs_write);
  4644. /*******************************************************************************
  4645. * FUNCTION: calibrate_debugfs_read
  4646. *
  4647. * SUMMARY: Perform calibration by sending the following PIP commands:
  4648. * 1) Suspend Scanning
  4649. * 2) Execute calibrate
  4650. * 3) Initialize baseline conditionally
  4651. * 4) Resume Scanning
  4652. *
  4653. * RETURN: Size of debugfs data print
  4654. *
  4655. * PARAMETERS:
  4656. * *filp - file pointer to debugfs file
  4657. * *buf - the user space buffer to read to
  4658. * count - the maximum number of bytes to read
  4659. * *ppos - the current position in the buffer
  4660. ******************************************************************************/
  4661. static ssize_t calibrate_debugfs_read(struct file *filp, char __user *buf,
  4662. size_t count, loff_t *ppos)
  4663. {
  4664. struct pt_device_access_debugfs_data *data = filp->private_data;
  4665. struct pt_device_access_data *dad = data->dad;
  4666. struct device *dev = dad->dev;
  4667. int status = STATUS_FAIL;
  4668. int length = 0;
  4669. int rc;
  4670. if (*ppos)
  4671. goto exit;
  4672. mutex_lock(&dad->sysfs_lock);
  4673. pm_runtime_get_sync(dev);
  4674. rc = cmd->request_exclusive(dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
  4675. if (rc) {
  4676. status = rc;
  4677. pt_debug(dev, DL_ERROR,
  4678. "%s: Error on request exclusive rc = %d\n",
  4679. __func__, rc);
  4680. goto put_pm_runtime;
  4681. }
  4682. rc = pt_suspend_scan_cmd_(dev);
  4683. if (rc) {
  4684. status = rc;
  4685. pt_debug(dev, DL_ERROR, "%s: Error on suspend scan rc = %d\n",
  4686. __func__, rc);
  4687. goto release_exclusive;
  4688. }
  4689. rc = _pt_calibrate_idacs_cmd(dev, dad->calibrate_sensing_mode,
  4690. &dad->ic_buf[0]);
  4691. if (rc) {
  4692. status = rc;
  4693. pt_debug(dev, DL_ERROR,
  4694. "%s: Error on calibrate idacs rc = %d\n",
  4695. __func__, rc);
  4696. goto resume_scan;
  4697. }
  4698. length = 1;
  4699. /* Check if baseline initialization is requested */
  4700. if (dad->calibrate_initialize_baselines) {
  4701. /* Perform baseline initialization for all modes */
  4702. rc = _pt_initialize_baselines_cmd(dev, PT_IB_SM_MUTCAP |
  4703. PT_IB_SM_SELFCAP | PT_IB_SM_BUTTON,
  4704. &dad->ic_buf[length]);
  4705. if (rc) {
  4706. status = rc;
  4707. pt_debug(dev, DL_ERROR,
  4708. "%s: Error on initialize baselines rc = %d\n",
  4709. __func__, rc);
  4710. goto resume_scan;
  4711. }
  4712. length++;
  4713. }
  4714. status = STATUS_SUCCESS;
  4715. resume_scan:
  4716. pt_resume_scan_cmd_(dev);
  4717. release_exclusive:
  4718. cmd->release_exclusive(dev);
  4719. put_pm_runtime:
  4720. pm_runtime_put(dev);
  4721. if (status == STATUS_FAIL)
  4722. length = 0;
  4723. data->pr_buf_len = prepare_print_buffer(status, dad->ic_buf, length,
  4724. data->pr_buf, sizeof(data->pr_buf), PT_PR_FORMAT_DEFAULT);
  4725. mutex_unlock(&dad->sysfs_lock);
  4726. exit:
  4727. return simple_read_from_buffer(buf, count, ppos, data->pr_buf,
  4728. data->pr_buf_len);
  4729. }
  4730. /*******************************************************************************
  4731. * FUNCTION: calibrate_debugfs_write
  4732. *
  4733. * SUMMARY: Stores the calibration sense mode and a flag to control if the
  4734. * baseline will be initialized for the read method of this node.
  4735. *
  4736. * RETURN: Size of debugfs data write
  4737. *
  4738. * PARAMETERS:
  4739. * *filp - file pointer to debugfs file
  4740. * *buf - the user space buffer to write to
  4741. * count - the maximum number of bytes to write
  4742. * *ppos - the current position in the buffer
  4743. ******************************************************************************/
  4744. static ssize_t calibrate_debugfs_write(struct file *filp,
  4745. const char __user *buf, size_t count, loff_t *ppos)
  4746. {
  4747. struct pt_device_access_debugfs_data *data = filp->private_data;
  4748. struct pt_device_access_data *dad = data->dad;
  4749. ssize_t length;
  4750. u32 input_data[3];
  4751. int rc = 0;
  4752. rc = simple_write_to_buffer(data->pr_buf, sizeof(data->pr_buf), ppos,
  4753. buf, count);
  4754. if (rc < 0)
  4755. return rc;
  4756. count = rc;
  4757. mutex_lock(&dad->sysfs_lock);
  4758. length = cmd->parse_sysfs_input(dad->dev, data->pr_buf, count,
  4759. input_data, ARRAY_SIZE(input_data));
  4760. if (length != 2) {
  4761. pt_debug(dad->dev, DL_ERROR,
  4762. "%s: Malformed input\n", __func__);
  4763. rc = -EINVAL;
  4764. goto exit_unlock;
  4765. }
  4766. dad->calibrate_sensing_mode = input_data[0];
  4767. dad->calibrate_initialize_baselines = input_data[1];
  4768. exit_unlock:
  4769. mutex_unlock(&dad->sysfs_lock);
  4770. if (rc)
  4771. return rc;
  4772. return count;
  4773. }
  4774. PT_DEBUGFS_FOPS(calibrate, calibrate_debugfs_read, calibrate_debugfs_write);
  4775. /*******************************************************************************
  4776. * FUNCTION: baseline_debugfs_read
  4777. *
  4778. * SUMMARY: Perform baseline initialization by sending the following PIP
  4779. * commands:
  4780. * 1) Suspend Scanning
  4781. * 2) Execute initialize baseline
  4782. * 3) Resume Scanning
  4783. *
  4784. * RETURN: Size of debugfs data print
  4785. *
  4786. * PARAMETERS:
  4787. * *filp - file pointer to debugfs file
  4788. * *buf - the user space buffer to read to
  4789. * count - the maximum number of bytes to read
  4790. * *ppos - the current position in the buffer
  4791. ******************************************************************************/
  4792. static ssize_t baseline_debugfs_read(struct file *filp, char __user *buf,
  4793. size_t count, loff_t *ppos)
  4794. {
  4795. struct pt_device_access_debugfs_data *data = filp->private_data;
  4796. struct pt_device_access_data *dad = data->dad;
  4797. struct device *dev = dad->dev;
  4798. int status = STATUS_FAIL;
  4799. int length = 0;
  4800. int rc;
  4801. if (*ppos)
  4802. goto exit;
  4803. mutex_lock(&dad->sysfs_lock);
  4804. pm_runtime_get_sync(dev);
  4805. rc = cmd->request_exclusive(dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
  4806. if (rc) {
  4807. status = rc;
  4808. pt_debug(dev, DL_ERROR,
  4809. "%s: Error on request exclusive rc = %d\n",
  4810. __func__, rc);
  4811. goto put_pm_runtime;
  4812. }
  4813. rc = pt_suspend_scan_cmd_(dev);
  4814. if (rc) {
  4815. status = rc;
  4816. pt_debug(dev, DL_ERROR, "%s: Error on suspend scan rc = %d\n",
  4817. __func__, rc);
  4818. goto release_exclusive;
  4819. }
  4820. rc = _pt_initialize_baselines_cmd(dev, dad->baseline_sensing_mode,
  4821. &dad->ic_buf[0]);
  4822. if (rc) {
  4823. status = rc;
  4824. pt_debug(dev, DL_ERROR,
  4825. "%s: Error on initialize baselines rc = %d\n",
  4826. __func__, rc);
  4827. goto resume_scan;
  4828. }
  4829. length = 1;
  4830. status = STATUS_SUCCESS;
  4831. resume_scan:
  4832. pt_resume_scan_cmd_(dev);
  4833. release_exclusive:
  4834. cmd->release_exclusive(dev);
  4835. put_pm_runtime:
  4836. pm_runtime_put(dev);
  4837. if (status == STATUS_FAIL)
  4838. length = 0;
  4839. data->pr_buf_len = prepare_print_buffer(status, dad->ic_buf, length,
  4840. data->pr_buf, sizeof(data->pr_buf), PT_PR_FORMAT_DEFAULT);
  4841. mutex_unlock(&dad->sysfs_lock);
  4842. exit:
  4843. return simple_read_from_buffer(buf, count, ppos, data->pr_buf,
  4844. data->pr_buf_len);
  4845. }
  4846. /*******************************************************************************
  4847. * FUNCTION: baseline_debugfs_write
  4848. *
  4849. * SUMMARY: Store the sense mode of base initialization, the read method will
  4850. * perform.
  4851. *
  4852. * RETURN: Size of debugfs data write
  4853. *
  4854. * PARAMETERS:
  4855. * *filp - file pointer to debugfs file
  4856. * *buf - the user space buffer to write to
  4857. * count - the maximum number of bytes to write
  4858. * *ppos - the current position in the buffer
  4859. ******************************************************************************/
  4860. static ssize_t baseline_debugfs_write(struct file *filp,
  4861. const char __user *buf, size_t count, loff_t *ppos)
  4862. {
  4863. struct pt_device_access_debugfs_data *data = filp->private_data;
  4864. struct pt_device_access_data *dad = data->dad;
  4865. ssize_t length;
  4866. u32 input_data[2];
  4867. int rc = 0;
  4868. rc = simple_write_to_buffer(data->pr_buf, sizeof(data->pr_buf), ppos,
  4869. buf, count);
  4870. if (rc < 0)
  4871. return rc;
  4872. count = rc;
  4873. mutex_lock(&dad->sysfs_lock);
  4874. length = cmd->parse_sysfs_input(dad->dev, data->pr_buf, count,
  4875. input_data, ARRAY_SIZE(input_data));
  4876. if (length != 1) {
  4877. pt_debug(dad->dev, DL_ERROR,
  4878. "%s: Malformed input\n", __func__);
  4879. rc = -EINVAL;
  4880. goto exit_unlock;
  4881. }
  4882. dad->baseline_sensing_mode = input_data[0];
  4883. exit_unlock:
  4884. mutex_unlock(&dad->sysfs_lock);
  4885. if (rc)
  4886. return rc;
  4887. return count;
  4888. }
  4889. PT_DEBUGFS_FOPS(baseline, baseline_debugfs_read, baseline_debugfs_write);
  4890. /*******************************************************************************
  4891. * FUNCTION: auto_shorts_debugfs_read
  4892. *
  4893. * SUMMARY: Performs the "auto shorts" test and prints the result to the output
  4894. * buffer.
  4895. *
  4896. * RETURN: Size of debugfs data print
  4897. *
  4898. * PARAMETERS:
  4899. * *filp - file pointer to debugfs file
  4900. * *buf - the user space buffer to read to
  4901. * count - the maximum number of bytes to read
  4902. * *ppos - the current position in the buffer
  4903. ******************************************************************************/
  4904. static ssize_t auto_shorts_debugfs_read(struct file *filp, char __user *buf,
  4905. size_t count, loff_t *ppos)
  4906. {
  4907. struct pt_device_access_debugfs_data *data = filp->private_data;
  4908. if (!*ppos)
  4909. /* Set length to PIP_CMD_MAX_LENGTH to read all */
  4910. data->pr_buf_len = pt_run_and_get_selftest_result(
  4911. data->dad->dev, PT_CORE_CMD_PROTECTED,
  4912. data->pr_buf, sizeof(data->pr_buf),
  4913. PT_ST_ID_AUTOSHORTS, PIP_CMD_MAX_LENGTH,
  4914. PT_ST_DONT_GET_RESULTS, PT_ST_PRINT_RESULTS,
  4915. PT_PR_FORMAT_DEFAULT);
  4916. return simple_read_from_buffer(buf, count, ppos, data->pr_buf,
  4917. data->pr_buf_len);
  4918. }
  4919. PT_DEBUGFS_FOPS(auto_shorts, auto_shorts_debugfs_read, NULL);
  4920. /*******************************************************************************
  4921. * FUNCTION: opens_debugfs_read
  4922. *
  4923. * SUMMARY: Performs the "opens" test and prints the results to the output
  4924. * buffer.
  4925. *
  4926. * RETURN: Size of debugfs data print
  4927. *
  4928. * PARAMETERS:
  4929. * *filp - file pointer to debugfs file
  4930. * *buf - the user space buffer to read to
  4931. * count - the maximum number of bytes to read
  4932. * *ppos - the current position in the buffer
  4933. ******************************************************************************/
  4934. static ssize_t opens_debugfs_read(struct file *filp, char __user *buf,
  4935. size_t count, loff_t *ppos)
  4936. {
  4937. struct pt_device_access_debugfs_data *data = filp->private_data;
  4938. if (!*ppos)
  4939. /* Set length to PIP_CMD_MAX_LENGTH to read all */
  4940. data->pr_buf_len = pt_run_and_get_selftest_result(
  4941. data->dad->dev, PT_CORE_CMD_PROTECTED,
  4942. data->pr_buf, sizeof(data->pr_buf),
  4943. PT_ST_ID_OPENS, PIP_CMD_MAX_LENGTH,
  4944. PT_ST_DONT_GET_RESULTS, PT_ST_PRINT_RESULTS,
  4945. PT_PR_FORMAT_DEFAULT);
  4946. return simple_read_from_buffer(buf, count, ppos, data->pr_buf,
  4947. data->pr_buf_len);
  4948. }
  4949. PT_DEBUGFS_FOPS(opens, opens_debugfs_read, NULL);
  4950. /*******************************************************************************
  4951. * FUNCTION: cm_panel_debugfs_read
  4952. *
  4953. * SUMMARY: Performs the "CM panel" test and prints the result to the output
  4954. * buffer.
  4955. *
  4956. * RETURN: Size of debugfs data print
  4957. *
  4958. * PARAMETERS:
  4959. * *filp - file pointer to debugfs file
  4960. * *buf - the user space buffer to read to
  4961. * count - the maximum number of bytes to read
  4962. * *ppos - the current position in the buffer
  4963. ******************************************************************************/
  4964. static ssize_t cm_panel_debugfs_read(struct file *filp, char __user *buf,
  4965. size_t count, loff_t *ppos)
  4966. {
  4967. struct pt_device_access_debugfs_data *data = filp->private_data;
  4968. if (!*ppos)
  4969. /* Set length to PIP_CMD_MAX_LENGTH to read all */
  4970. data->pr_buf_len = pt_run_and_get_selftest_result(
  4971. data->dad->dev, PT_CORE_CMD_PROTECTED,
  4972. data->pr_buf, sizeof(data->pr_buf),
  4973. PT_ST_ID_CM_PANEL, PIP_CMD_MAX_LENGTH,
  4974. PT_ST_GET_RESULTS, PT_ST_PRINT_RESULTS,
  4975. PT_PR_FORMAT_DEFAULT);
  4976. return simple_read_from_buffer(buf, count, ppos, data->pr_buf,
  4977. data->pr_buf_len);
  4978. }
  4979. PT_DEBUGFS_FOPS(cm_panel, cm_panel_debugfs_read, NULL);
  4980. /*******************************************************************************
  4981. * FUNCTION: cp_panel_debugfs_read
  4982. *
  4983. * SUMMARY: Performs the "CP panel" test and prints the result to the output
  4984. * buffer.
  4985. *
  4986. * RETURN: Size of debugfs data print
  4987. *
  4988. * PARAMETERS:
  4989. * *filp - file pointer to debugfs file
  4990. * *buf - the user space buffer to read to
  4991. * count - the maximum number of bytes to read
  4992. * *ppos - the current position in the buffer
  4993. ******************************************************************************/
  4994. static ssize_t cp_panel_debugfs_read(struct file *filp, char __user *buf,
  4995. size_t count, loff_t *ppos)
  4996. {
  4997. struct pt_device_access_debugfs_data *data = filp->private_data;
  4998. if (!*ppos)
  4999. /* Set length to PIP_CMD_MAX_LENGTH to read all */
  5000. data->pr_buf_len = pt_run_and_get_selftest_result(
  5001. data->dad->dev, PT_CORE_CMD_PROTECTED,
  5002. data->pr_buf, sizeof(data->pr_buf),
  5003. PT_ST_ID_CP_PANEL, PIP_CMD_MAX_LENGTH,
  5004. PT_ST_GET_RESULTS, PT_ST_PRINT_RESULTS,
  5005. PT_PR_FORMAT_DEFAULT);
  5006. return simple_read_from_buffer(buf, count, ppos, data->pr_buf,
  5007. data->pr_buf_len);
  5008. }
  5009. PT_DEBUGFS_FOPS(cp_panel, cp_panel_debugfs_read, NULL);
  5010. /*******************************************************************************
  5011. * FUNCTION: cm_button_debugfs_read
  5012. *
  5013. * SUMMARY: Performs the "CM buttons" test and prints the result to the output
  5014. * buffer.
  5015. *
  5016. * RETURN: Size of debugfs data print
  5017. *
  5018. * PARAMETERS:
  5019. * *filp - file pointer to debugfs file
  5020. * *buf - the user space buffer to read to
  5021. * count - the maximum number of bytes to read
  5022. * *ppos - the current position in the buffer
  5023. ******************************************************************************/
  5024. static ssize_t cm_button_debugfs_read(struct file *filp, char __user *buf,
  5025. size_t count, loff_t *ppos)
  5026. {
  5027. struct pt_device_access_debugfs_data *data = filp->private_data;
  5028. if (!*ppos)
  5029. /* Set length to PIP_CMD_MAX_LENGTH to read all */
  5030. data->pr_buf_len = pt_run_and_get_selftest_result(
  5031. data->dad->dev, PT_CORE_CMD_PROTECTED,
  5032. data->pr_buf, sizeof(data->pr_buf),
  5033. PT_ST_ID_CM_BUTTON, PIP_CMD_MAX_LENGTH,
  5034. PT_ST_GET_RESULTS, PT_ST_PRINT_RESULTS,
  5035. PT_PR_FORMAT_DEFAULT);
  5036. return simple_read_from_buffer(buf, count, ppos, data->pr_buf,
  5037. data->pr_buf_len);
  5038. }
  5039. PT_DEBUGFS_FOPS(cm_button, cm_button_debugfs_read, NULL);
  5040. /*******************************************************************************
  5041. * FUNCTION: cp_button_debugfs_read
  5042. *
  5043. * SUMMARY: Performs the "CP buttons" test and prints the result to the output
  5044. * buffer.
  5045. *
  5046. * RETURN: Size of debugfs data print
  5047. *
  5048. * PARAMETERS:
  5049. * *filp - file pointer to debugfs file
  5050. * *buf - the user space buffer to read to
  5051. * count - the maximum number of bytes to read
  5052. * *ppos - the current position in the buffer
  5053. ******************************************************************************/
  5054. static ssize_t cp_button_debugfs_read(struct file *filp, char __user *buf,
  5055. size_t count, loff_t *ppos)
  5056. {
  5057. struct pt_device_access_debugfs_data *data = filp->private_data;
  5058. if (!*ppos)
  5059. /* Set length to PIP_CMD_MAX_LENGTH to read all */
  5060. data->pr_buf_len = pt_run_and_get_selftest_result(
  5061. data->dad->dev, PT_CORE_CMD_PROTECTED,
  5062. data->pr_buf, sizeof(data->pr_buf),
  5063. PT_ST_ID_CP_BUTTON, PIP_CMD_MAX_LENGTH,
  5064. PT_ST_GET_RESULTS, PT_ST_PRINT_RESULTS,
  5065. PT_PR_FORMAT_DEFAULT);
  5066. return simple_read_from_buffer(buf, count, ppos, data->pr_buf,
  5067. data->pr_buf_len);
  5068. }
  5069. PT_DEBUGFS_FOPS(cp_button, cp_button_debugfs_read, NULL);
  5070. /*******************************************************************************
  5071. * FUNCTION: fw_self_test_debugfs_read
  5072. *
  5073. * SUMMARY: Performs the self test by firmware and prints the results to the
  5074. * output buffer.
  5075. *
  5076. * RETURN: Size of debugfs data print
  5077. *
  5078. * PARAMETERS:
  5079. * *filp - file pointer to debugfs file
  5080. * *buf - the user space buffer to read to
  5081. * count - the maximum number of bytes to read
  5082. * *ppos - the current position in the buffer
  5083. ******************************************************************************/
  5084. static ssize_t fw_self_test_debugfs_read(struct file *filp, char __user *buf,
  5085. size_t count, loff_t *ppos)
  5086. {
  5087. u8 ret_status;
  5088. u8 ret_self_test_id;
  5089. u8 sys_mode = FW_SYS_MODE_UNDEFINED;
  5090. u16 ret_act_load_len;
  5091. int rc;
  5092. struct pt_device_access_debugfs_data *data = filp->private_data;
  5093. struct pt_device_access_data *dad = data->dad;
  5094. if (!*ppos) {
  5095. if (dad->fw_self_test_id == PT_ST_ID_INVALID ||
  5096. dad->fw_self_test_format >= PT_PR_FORMAT_UNDEFINE) {
  5097. data->pr_buf_len = scnprintf(data->pr_buf,
  5098. sizeof(data->pr_buf), "Status: %d\n", -EINVAL);
  5099. pt_debug(dad->dev, DL_ERROR,
  5100. "%s: Malformed input\n", __func__);
  5101. goto exit;
  5102. }
  5103. /* only send the load parameters cmd if param data exists */
  5104. if (dad->fw_self_test_param_len > 0) {
  5105. rc = cmd->request_get_fw_mode(dad->dev,
  5106. PT_CORE_CMD_UNPROTECTED, &sys_mode, NULL);
  5107. if (rc) {
  5108. pt_debug(dad->dev, DL_ERROR,
  5109. "%s: ERR on request mode rc=%d\n",
  5110. __func__, rc);
  5111. data->pr_buf_len = scnprintf(
  5112. data->pr_buf,
  5113. sizeof(data->pr_buf),
  5114. "Status: %d\n", rc);
  5115. goto exit;
  5116. }
  5117. if (sys_mode != FW_SYS_MODE_TEST) {
  5118. rc = pt_suspend_scan_cmd_(dad->dev);
  5119. if (rc) {
  5120. pt_debug(dad->dev, DL_ERROR,
  5121. "%s: ERR on sus scan rc=%d\n",
  5122. __func__, rc);
  5123. data->pr_buf_len = scnprintf(
  5124. data->pr_buf,
  5125. sizeof(data->pr_buf),
  5126. "Status: %d\n", rc);
  5127. goto exit;
  5128. }
  5129. }
  5130. cmd->nonhid_cmd->load_self_test_param(dad->dev,
  5131. PT_CORE_CMD_PROTECTED,
  5132. dad->fw_self_test_id, 0,
  5133. dad->fw_self_test_param_len,
  5134. dad->fw_self_test_param, &ret_status,
  5135. &ret_self_test_id, &ret_act_load_len);
  5136. if (ret_status) {
  5137. data->pr_buf_len = scnprintf(data->pr_buf,
  5138. sizeof(data->pr_buf),
  5139. "Status: %d\n", -EINVAL);
  5140. pt_debug(dad->dev, DL_ERROR,
  5141. "%s: Load Param Malformed input\n",
  5142. __func__);
  5143. goto resume_scan;
  5144. }
  5145. }
  5146. /* Set length to PIP_CMD_MAX_LENGTH to read all */
  5147. data->pr_buf_len = pt_run_and_get_selftest_result(
  5148. dad->dev, PT_CORE_CMD_PROTECTED,
  5149. data->pr_buf, sizeof(data->pr_buf),
  5150. dad->fw_self_test_id, PIP_CMD_MAX_LENGTH,
  5151. PT_ST_GET_RESULTS, PT_ST_PRINT_RESULTS,
  5152. dad->fw_self_test_format);
  5153. /* Clear the parameters so next test won't use them */
  5154. if (dad->fw_self_test_param_len > 0) {
  5155. cmd->nonhid_cmd->load_self_test_param(dad->dev,
  5156. PT_CORE_CMD_PROTECTED,
  5157. dad->fw_self_test_id, 0, 0, NULL,
  5158. &ret_status, &ret_self_test_id,
  5159. &ret_act_load_len);
  5160. }
  5161. dad->fw_self_test_id = PT_ST_ID_INVALID;
  5162. dad->fw_self_test_format = PT_PR_FORMAT_UNDEFINE;
  5163. dad->fw_self_test_param_len = 0;
  5164. resume_scan:
  5165. /* Only resume scanning if we suspended it */
  5166. if (sys_mode == FW_SYS_MODE_SCANNING)
  5167. pt_resume_scan_cmd_(dad->dev);
  5168. }
  5169. exit:
  5170. return simple_read_from_buffer(buf, count, ppos, data->pr_buf,
  5171. data->pr_buf_len);
  5172. }
  5173. /*******************************************************************************
  5174. * FUNCTION: fw_self_test_debugfs_write
  5175. *
  5176. * SUMMARY: Store the self test ID and ouptut format, the read method will
  5177. * perform.
  5178. *
  5179. * RETURN: Size of debugfs data write
  5180. *
  5181. * PARAMETERS:
  5182. * *filp - file pointer to debugfs file
  5183. * *buf - the user space buffer to write to
  5184. * count - the maximum number of bytes to write
  5185. * *ppos - the current position in the buffer
  5186. ******************************************************************************/
  5187. static ssize_t fw_self_test_debugfs_write(struct file *filp,
  5188. const char __user *buf, size_t count, loff_t *ppos)
  5189. {
  5190. struct pt_device_access_debugfs_data *data = filp->private_data;
  5191. struct pt_device_access_data *dad = data->dad;
  5192. ssize_t length;
  5193. u32 input_data[PT_FW_SELF_TEST_MAX_PARM + 1];
  5194. int rc = 0;
  5195. int i;
  5196. rc = simple_write_to_buffer(data->pr_buf, sizeof(data->pr_buf), ppos,
  5197. buf, count);
  5198. if (rc < 0)
  5199. return rc;
  5200. count = rc;
  5201. mutex_lock(&dad->sysfs_lock);
  5202. length = cmd->parse_sysfs_input(dad->dev, data->pr_buf, count,
  5203. input_data, PT_FW_SELF_TEST_MAX_PARM + 1);
  5204. if (length == 1) {
  5205. dad->fw_self_test_id = input_data[0];
  5206. dad->fw_self_test_format = PT_PR_FORMAT_DEFAULT;
  5207. dad->fw_self_test_param_len = 0;
  5208. } else if (length == 2) {
  5209. dad->fw_self_test_id = input_data[0];
  5210. dad->fw_self_test_format = input_data[1];
  5211. dad->fw_self_test_param_len = 0;
  5212. } else if (length > 2 && (length <= PT_FW_SELF_TEST_MAX_PARM)) {
  5213. dad->fw_self_test_id = input_data[0];
  5214. dad->fw_self_test_format = input_data[1];
  5215. dad->fw_self_test_param_len = length - 2;
  5216. pt_debug(dad->dev, DL_INFO,
  5217. "%s: test_id=%d, format=%d, param_len=%d",
  5218. __func__, dad->fw_self_test_id,
  5219. dad->fw_self_test_format, dad->fw_self_test_param_len);
  5220. for (i = 0; i < dad->fw_self_test_param_len; i++)
  5221. dad->fw_self_test_param[i] = input_data[i + 2];
  5222. } else {
  5223. pt_debug(dad->dev, DL_ERROR,
  5224. "%s: Malformed input\n", __func__);
  5225. rc = -EINVAL;
  5226. goto exit_unlock;
  5227. }
  5228. exit_unlock:
  5229. mutex_unlock(&dad->sysfs_lock);
  5230. if (rc)
  5231. return rc;
  5232. return count;
  5233. }
  5234. PT_DEBUGFS_FOPS(fw_self_test,
  5235. fw_self_test_debugfs_read, fw_self_test_debugfs_write);
  5236. #ifdef TTHE_TUNER_SUPPORT
  5237. /*******************************************************************************
  5238. * FUNCTION: tthe_get_panel_data_debugfs_read
  5239. *
  5240. * SUMMARY: Performs a panel scan and prints the panel data into the output
  5241. * buffer.
  5242. *
  5243. * RETURN: Size of debugfs data print
  5244. *
  5245. * PARAMETERS:
  5246. * *filp - file pointer to debugfs file
  5247. * *buf - the user space buffer to read to
  5248. * count - the maximum number of bytes to read
  5249. * *ppos - the current position in the buffer
  5250. ******************************************************************************/
  5251. static ssize_t tthe_get_panel_data_debugfs_read(struct file *filp,
  5252. char __user *buf, size_t count, loff_t *ppos)
  5253. {
  5254. struct pt_device_access_data *dad = filp->private_data;
  5255. struct device *dev;
  5256. struct pt_core_data *cd;
  5257. u8 config;
  5258. u16 actual_read_len;
  5259. u16 length = 0;
  5260. u8 element_size = 0;
  5261. u8 *buf_offset;
  5262. u8 *buf_out;
  5263. int elem;
  5264. int elem_offset = 0;
  5265. int print_idx = 0;
  5266. int rc;
  5267. int rc1;
  5268. int i;
  5269. mutex_lock(&dad->debugfs_lock);
  5270. dev = dad->dev;
  5271. cd = dev_get_drvdata(dev);
  5272. buf_out = dad->panel_scan_data_buf;
  5273. if (!buf_out)
  5274. goto release_mutex;
  5275. pm_runtime_get_sync(dev);
  5276. rc = cmd->request_exclusive(dev, PT_REQUEST_EXCLUSIVE_TIMEOUT);
  5277. if (rc)
  5278. goto put_runtime;
  5279. if (dad->heatmap.scan_start) {
  5280. /*
  5281. * To fix CDT206291: avoid multiple scans when
  5282. * return data is larger than 4096 bytes in one cycle
  5283. */
  5284. dad->heatmap.scan_start = 0;
  5285. /* Start scan */
  5286. rc = pt_exec_scan_cmd_(dev, 0);
  5287. if (rc)
  5288. goto release_exclusive;
  5289. }
  5290. elem = dad->heatmap.num_element;
  5291. #if defined(PT_ENABLE_MAX_ELEN)
  5292. if (elem > PT_MAX_ELEN) {
  5293. rc = pt_ret_scan_data_cmd_(dev, elem_offset,
  5294. PT_MAX_ELEN, dad->heatmap.data_type, dad->ic_buf,
  5295. &config, &actual_read_len, NULL);
  5296. } else {
  5297. rc = pt_ret_scan_data_cmd_(dev, elem_offset, elem,
  5298. dad->heatmap.data_type, dad->ic_buf, &config,
  5299. &actual_read_len, NULL);
  5300. }
  5301. #else
  5302. rc = pt_ret_scan_data_cmd_(dev, elem_offset, elem,
  5303. dad->heatmap.data_type, dad->ic_buf, &config,
  5304. &actual_read_len, NULL);
  5305. #endif
  5306. if (rc)
  5307. goto release_exclusive;
  5308. length = get_unaligned_le16(&dad->ic_buf[0]);
  5309. buf_offset = dad->ic_buf + length;
  5310. element_size = config & PT_CMD_RET_PANEL_ELMNT_SZ_MASK;
  5311. elem -= actual_read_len;
  5312. elem_offset = actual_read_len;
  5313. while (elem > 0) {
  5314. #ifdef PT_ENABLE_MAX_ELEN
  5315. if (elem > PT_MAX_ELEN) {
  5316. rc = pt_ret_scan_data_cmd_(dev, elem_offset,
  5317. PT_MAX_ELEN, dad->heatmap.data_type, NULL, &config,
  5318. &actual_read_len, buf_offset);
  5319. } else {
  5320. rc = pt_ret_scan_data_cmd_(dev, elem_offset, elem,
  5321. dad->heatmap.data_type, NULL, &config,
  5322. &actual_read_len, buf_offset);
  5323. }
  5324. #else
  5325. rc = pt_ret_scan_data_cmd_(dev, elem_offset, elem,
  5326. dad->heatmap.data_type, NULL, &config,
  5327. &actual_read_len, buf_offset);
  5328. #endif
  5329. if (rc)
  5330. goto release_exclusive;
  5331. if (!actual_read_len)
  5332. break;
  5333. length += actual_read_len * element_size;
  5334. buf_offset = dad->ic_buf + length;
  5335. elem -= actual_read_len;
  5336. elem_offset += actual_read_len;
  5337. }
  5338. /* Reconstruct cmd header */
  5339. put_unaligned_le16(length, &dad->ic_buf[0]);
  5340. put_unaligned_le16(elem_offset, &dad->ic_buf[7]);
  5341. release_exclusive:
  5342. rc1 = cmd->release_exclusive(dev);
  5343. put_runtime:
  5344. pm_runtime_put(dev);
  5345. if (rc)
  5346. goto release_mutex;
  5347. if (cd->show_timestamp)
  5348. print_idx += scnprintf(buf_out, TTHE_TUNER_MAX_BUF,
  5349. "[%u] PT_DATA:", pt_get_time_stamp());
  5350. else
  5351. print_idx += scnprintf(buf_out, TTHE_TUNER_MAX_BUF,
  5352. "PT_DATA:");
  5353. for (i = 0; i < length; i++)
  5354. print_idx += scnprintf(buf_out + print_idx,
  5355. TTHE_TUNER_MAX_BUF - print_idx,
  5356. "%02X ", dad->ic_buf[i]);
  5357. print_idx += scnprintf(buf_out + print_idx,
  5358. TTHE_TUNER_MAX_BUF - print_idx,
  5359. ":(%d bytes)\n", length);
  5360. rc = simple_read_from_buffer(buf, count, ppos, buf_out, print_idx);
  5361. print_idx = rc;
  5362. release_mutex:
  5363. mutex_unlock(&dad->debugfs_lock);
  5364. return print_idx;
  5365. }
  5366. /*******************************************************************************
  5367. * FUNCTION: tthe_get_panel_data_debugfs_write
  5368. *
  5369. * SUMMARY: Store the panel data type to retrieve and size of panel data, the
  5370. * read method will perform.
  5371. *
  5372. * RETURN: Size of debugfs data write
  5373. *
  5374. * PARAMETERS:
  5375. * *filp - file pointer to debugfs file
  5376. * *buf - the user space buffer to write to
  5377. * count - the maximum number of bytes to write
  5378. * *ppos - the current position in the buffer
  5379. ******************************************************************************/
  5380. static ssize_t tthe_get_panel_data_debugfs_write(struct file *filp,
  5381. const char __user *buf, size_t count, loff_t *ppos)
  5382. {
  5383. struct pt_device_access_data *dad = filp->private_data;
  5384. struct device *dev = dad->dev;
  5385. ssize_t length;
  5386. int max_read;
  5387. u32 input_data[8];
  5388. u8 *buf_in = dad->panel_scan_data_buf;
  5389. int ret;
  5390. mutex_lock(&dad->debugfs_lock);
  5391. ret = copy_from_user(buf_in + (*ppos), buf, count);
  5392. if (ret)
  5393. goto exit;
  5394. buf_in[count] = 0;
  5395. length = cmd->parse_sysfs_input(dev, buf_in, count, input_data,
  5396. ARRAY_SIZE(input_data));
  5397. if (length <= 0) {
  5398. pt_debug(dev, DL_ERROR,
  5399. "%s: %s Group Data store\n",
  5400. __func__, "Malformed input for");
  5401. goto exit;
  5402. }
  5403. /* update parameter value */
  5404. dad->heatmap.num_element = input_data[3] + (input_data[4] << 8);
  5405. dad->heatmap.data_type = input_data[5];
  5406. if (input_data[6] > 0)
  5407. dad->heatmap.scan_start = true;
  5408. else
  5409. dad->heatmap.scan_start = false;
  5410. /* elem can not be bigger then buffer size */
  5411. max_read = PT_CMD_RET_PANEL_HDR;
  5412. max_read += dad->heatmap.num_element * PT_CMD_RET_PANEL_ELMNT_SZ_MAX;
  5413. if (max_read >= PT_MAX_PRBUF_SIZE) {
  5414. dad->heatmap.num_element =
  5415. (PT_MAX_PRBUF_SIZE - PT_CMD_RET_PANEL_HDR)
  5416. / PT_CMD_RET_PANEL_ELMNT_SZ_MAX;
  5417. pt_debug(dev, DL_INFO, "%s: Will get %d element\n",
  5418. __func__, dad->heatmap.num_element);
  5419. }
  5420. exit:
  5421. mutex_unlock(&dad->debugfs_lock);
  5422. pt_debug(dev, DL_INFO, "%s: return count=%zu\n",
  5423. __func__, count);
  5424. return count;
  5425. }
  5426. /*******************************************************************************
  5427. * FUNCTION: tthe_get_panel_data_debugfs_open
  5428. *
  5429. * SUMMARY: Open the get_panel_data debugfs node to initialize.
  5430. *
  5431. * RETURN:
  5432. * 0 = success
  5433. * !0 = failure
  5434. *
  5435. * PARAMETERS:
  5436. * *inode - pointer to inode structure
  5437. * *filp - pointer to file structure
  5438. ******************************************************************************/
  5439. static int tthe_get_panel_data_debugfs_open(struct inode *inode,
  5440. struct file *filp)
  5441. {
  5442. struct pt_device_access_data *dad = inode->i_private;
  5443. mutex_lock(&dad->debugfs_lock);
  5444. if (dad->tthe_get_panel_data_is_open) {
  5445. mutex_unlock(&dad->debugfs_lock);
  5446. return -EBUSY;
  5447. }
  5448. filp->private_data = inode->i_private;
  5449. dad->tthe_get_panel_data_is_open = 1;
  5450. mutex_unlock(&dad->debugfs_lock);
  5451. return 0;
  5452. }
  5453. /*******************************************************************************
  5454. * FUNCTION: tthe_get_panel_data_debugfs_close
  5455. *
  5456. * SUMMARY: Close the get_panel_data debugfs node to free pointer.
  5457. *
  5458. * RETURN:
  5459. * 0 = success
  5460. * !0 = failure
  5461. *
  5462. * PARAMETERS:
  5463. * *inode - pointer to inode structure
  5464. * *filp - pointer to file structure
  5465. ******************************************************************************/
  5466. static int tthe_get_panel_data_debugfs_close(struct inode *inode,
  5467. struct file *filp)
  5468. {
  5469. struct pt_device_access_data *dad = filp->private_data;
  5470. mutex_lock(&dad->debugfs_lock);
  5471. filp->private_data = NULL;
  5472. dad->tthe_get_panel_data_is_open = 0;
  5473. mutex_unlock(&dad->debugfs_lock);
  5474. return 0;
  5475. }
  5476. static const struct file_operations tthe_get_panel_data_fops = {
  5477. .open = tthe_get_panel_data_debugfs_open,
  5478. .release = tthe_get_panel_data_debugfs_close,
  5479. .read = tthe_get_panel_data_debugfs_read,
  5480. .write = tthe_get_panel_data_debugfs_write,
  5481. };
  5482. #endif
  5483. /*******************************************************************************
  5484. * FUNCTION: pt_setup_sysfs
  5485. *
  5486. * SUMMARY: Creates all device test dependent sysfs nodes owned by the
  5487. * device access file.
  5488. *
  5489. * RETURN:
  5490. * 0 = success
  5491. * !0 = failure
  5492. *
  5493. * PARAMETERS:
  5494. * *dev - pointer to device structure
  5495. ******************************************************************************/
  5496. static int pt_setup_sysfs(struct device *dev)
  5497. {
  5498. struct pt_device_access_data *dad
  5499. = pt_get_device_access_data(dev);
  5500. int rc = 0;
  5501. pt_debug(dev, DL_INFO, "Entering %s\n", __func__);
  5502. dad->base_dentry = debugfs_create_dir(dev_name(dev), NULL);
  5503. if (IS_ERR_OR_NULL(dad->base_dentry)) {
  5504. pt_debug(dev, DL_ERROR,
  5505. "%s: Error, could not create base directory\n",
  5506. __func__);
  5507. goto exit;
  5508. }
  5509. dad->mfg_test_dentry = debugfs_create_dir("mfg_test",
  5510. dad->base_dentry);
  5511. if (IS_ERR_OR_NULL(dad->mfg_test_dentry)) {
  5512. pt_debug(dev, DL_ERROR,
  5513. "%s: Error, could not create mfg_test directory\n",
  5514. __func__);
  5515. goto unregister_base_dir;
  5516. }
  5517. dad->panel_scan_debugfs = debugfs_create_file(
  5518. "panel_scan", 0644, dad->mfg_test_dentry, dad,
  5519. &panel_scan_fops);
  5520. if (IS_ERR_OR_NULL(dad->panel_scan_debugfs)) {
  5521. pt_debug(dev, DL_ERROR,
  5522. "%s: Error, could not create panel_scan\n",
  5523. __func__);
  5524. goto unregister_base_dir;
  5525. }
  5526. if (IS_ERR_OR_NULL(debugfs_create_file("get_idac", 0600,
  5527. dad->mfg_test_dentry, dad, &get_idac_debugfs_fops))) {
  5528. pt_debug(dev, DL_ERROR,
  5529. "%s: Error, could not create get_idac\n",
  5530. __func__);
  5531. goto unregister_base_dir;
  5532. }
  5533. if (IS_ERR_OR_NULL(debugfs_create_file("auto_shorts", 0400,
  5534. dad->mfg_test_dentry, dad,
  5535. &auto_shorts_debugfs_fops))) {
  5536. pt_debug(dev, DL_ERROR,
  5537. "%s: Error, could not create auto_shorts\n",
  5538. __func__);
  5539. goto unregister_base_dir;
  5540. }
  5541. if (IS_ERR_OR_NULL(debugfs_create_file("opens", 0400,
  5542. dad->mfg_test_dentry, dad, &opens_debugfs_fops))) {
  5543. pt_debug(dev, DL_ERROR,
  5544. "%s: Error, could not create opens\n",
  5545. __func__);
  5546. goto unregister_base_dir;
  5547. }
  5548. if (IS_ERR_OR_NULL(debugfs_create_file("calibrate_ext",
  5549. 0600, dad->mfg_test_dentry,
  5550. dad, &calibrate_ext_debugfs_fops))) {
  5551. pt_debug(dev, DL_ERROR,
  5552. "%s: Error, could not create calibrate_ext\n",
  5553. __func__);
  5554. goto unregister_base_dir;
  5555. }
  5556. if (IS_ERR_OR_NULL(debugfs_create_file("calibrate", 0600,
  5557. dad->mfg_test_dentry, dad, &calibrate_debugfs_fops))) {
  5558. pt_debug(dev, DL_ERROR,
  5559. "%s: Error, could not create calibrate\n",
  5560. __func__);
  5561. goto unregister_base_dir;
  5562. }
  5563. if (IS_ERR_OR_NULL(debugfs_create_file("baseline", 0600,
  5564. dad->mfg_test_dentry, dad, &baseline_debugfs_fops))) {
  5565. pt_debug(dev, DL_ERROR,
  5566. "%s: Error, could not create baseline\n",
  5567. __func__);
  5568. goto unregister_base_dir;
  5569. }
  5570. if (IS_ERR_OR_NULL(debugfs_create_file("cm_panel", 0400,
  5571. dad->mfg_test_dentry, dad, &cm_panel_debugfs_fops))) {
  5572. pt_debug(dev, DL_ERROR,
  5573. "%s: Error, could not create cm_panel\n",
  5574. __func__);
  5575. goto unregister_base_dir;
  5576. }
  5577. if (IS_ERR_OR_NULL(debugfs_create_file("cp_panel", 0400,
  5578. dad->mfg_test_dentry, dad, &cp_panel_debugfs_fops))) {
  5579. pt_debug(dev, DL_ERROR,
  5580. "%s: Error, could not create cp_panel\n",
  5581. __func__);
  5582. goto unregister_base_dir;
  5583. }
  5584. if (IS_ERR_OR_NULL(debugfs_create_file("cm_button", 0400,
  5585. dad->mfg_test_dentry, dad, &cm_button_debugfs_fops))) {
  5586. pt_debug(dev, DL_ERROR,
  5587. "%s: Error, could not create cm_button\n",
  5588. __func__);
  5589. goto unregister_base_dir;
  5590. }
  5591. if (IS_ERR_OR_NULL(debugfs_create_file("cp_button", 0400,
  5592. dad->mfg_test_dentry, dad, &cp_button_debugfs_fops))) {
  5593. pt_debug(dev, DL_ERROR,
  5594. "%s: Error, could not create cp_button\n",
  5595. __func__);
  5596. goto unregister_base_dir;
  5597. }
  5598. if (IS_ERR_OR_NULL(debugfs_create_file("fw_self_test", 0600,
  5599. dad->mfg_test_dentry, dad, &fw_self_test_debugfs_fops))) {
  5600. pt_debug(dev, DL_ERROR,
  5601. "%s: Error, could not create fw_self_test\n",
  5602. __func__);
  5603. goto unregister_base_dir;
  5604. }
  5605. dad->cmcp_results_debugfs = debugfs_create_file("cmcp_results", 0644,
  5606. dad->mfg_test_dentry, dad, &cmcp_results_debugfs_fops);
  5607. if (IS_ERR_OR_NULL(dad->cmcp_results_debugfs)) {
  5608. pt_debug(dev, DL_ERROR,
  5609. "%s: Error, could not create cmcp_results\n",
  5610. __func__);
  5611. dad->cmcp_results_debugfs = NULL;
  5612. goto unregister_base_dir;
  5613. }
  5614. #ifdef TTHE_TUNER_SUPPORT
  5615. dad->tthe_get_panel_data_debugfs = debugfs_create_file(
  5616. PT_TTHE_TUNER_GET_PANEL_DATA_FILE_NAME,
  5617. 0644, NULL, dad, &tthe_get_panel_data_fops);
  5618. if (IS_ERR_OR_NULL(dad->tthe_get_panel_data_debugfs)) {
  5619. pt_debug(dev, DL_ERROR,
  5620. "%s: Error, could not create get_panel_data\n",
  5621. __func__);
  5622. dad->tthe_get_panel_data_debugfs = NULL;
  5623. goto unregister_base_dir;
  5624. }
  5625. #endif
  5626. rc = device_create_file(dev, &dev_attr_cmcp_test);
  5627. if (rc) {
  5628. pt_debug(dev, DL_ERROR,
  5629. "%s: Error, could not create cmcp_test\n",
  5630. __func__);
  5631. goto unregister_base_dir;
  5632. }
  5633. rc = device_create_file(dev, &dev_attr_cmcp_threshold_loading);
  5634. if (rc) {
  5635. pt_debug(dev, DL_ERROR,
  5636. "%s: Error, could not create cmcp_threshold_loading\n",
  5637. __func__);
  5638. goto unregister_cmcp_test;
  5639. }
  5640. rc = device_create_bin_file(dev, &bin_attr_cmcp_threshold_data);
  5641. if (rc) {
  5642. pt_debug(dev, DL_ERROR,
  5643. "%s: Error, could not create cmcp_threshold_data\n",
  5644. __func__);
  5645. goto unregister_cmcp_thresold_loading;
  5646. }
  5647. dad->sysfs_nodes_created = true;
  5648. return rc;
  5649. unregister_cmcp_thresold_loading:
  5650. device_remove_file(dev, &dev_attr_cmcp_threshold_loading);
  5651. unregister_cmcp_test:
  5652. device_remove_file(dev, &dev_attr_cmcp_test);
  5653. unregister_base_dir:
  5654. debugfs_remove_recursive(dad->base_dentry);
  5655. exit:
  5656. return rc;
  5657. }
  5658. /*******************************************************************************
  5659. * FUNCTION: pt_setup_cmcp_attention
  5660. *
  5661. * SUMMARY: Function to be registered to TTDL attention list to setup sysfs and
  5662. * parse threshold file for device test.
  5663. *
  5664. * RETURN:
  5665. * 0 = success
  5666. * !0 = failure
  5667. *
  5668. * PARAMETERS:
  5669. * *dev - pointer to device structure
  5670. ******************************************************************************/
  5671. static int pt_setup_cmcp_attention(struct device *dev)
  5672. {
  5673. struct pt_device_access_data *dad
  5674. = pt_get_device_access_data(dev);
  5675. int rc = 0;
  5676. dad->si = cmd->request_sysinfo(dev);
  5677. if (!dad->si)
  5678. return -EINVAL;
  5679. rc = pt_setup_sysfs(dev);
  5680. schedule_work(&dad->cmcp_threshold_update);
  5681. cmd->unsubscribe_attention(dev, PT_ATTEN_STARTUP,
  5682. PT_DEVICE_ACCESS_NAME, pt_setup_cmcp_attention,
  5683. 0);
  5684. return rc;
  5685. }
  5686. /*******************************************************************************
  5687. * FUNCTION: pt_cmcp_parse_threshold_file
  5688. *
  5689. * SUMMARY: Parse cmcp threshold file and store it to the structure.
  5690. *
  5691. * PARAMETERS:
  5692. * *fw - pointer to firmware structure
  5693. * *context - expected read length of the response
  5694. ******************************************************************************/
  5695. static void pt_cmcp_parse_threshold_file(const struct firmware *fw,
  5696. void *context)
  5697. {
  5698. struct device *dev = context;
  5699. struct pt_device_access_data *dad =
  5700. pt_get_device_access_data(dev);
  5701. if (!fw) {
  5702. pt_debug(dev, DL_WARN,
  5703. "%s: No builtin cmcp threshold file\n",
  5704. __func__);
  5705. goto exit;
  5706. }
  5707. if (!fw->data || !fw->size) {
  5708. pt_debug(dev, DL_ERROR,
  5709. "%s: Invalid builtin cmcp threshold file\n",
  5710. __func__);
  5711. goto exit;
  5712. }
  5713. pt_debug(dev, DL_WARN, "%s: Found cmcp threshold file.\n",
  5714. __func__);
  5715. pt_parse_cmcp_threshold_file_common(dev, &fw->data[0], fw->size);
  5716. dad->builtin_cmcp_threshold_status = 0;
  5717. release_firmware(fw);
  5718. return;
  5719. exit:
  5720. if (fw)
  5721. release_firmware(fw);
  5722. dad->builtin_cmcp_threshold_status = -EINVAL;
  5723. }
  5724. /*******************************************************************************
  5725. * FUNCTION: pt_device_access_user_command
  5726. *
  5727. * SUMMARY: Wrapper function to call pt_cmcp_parse_threshold_file() by firmware
  5728. * class function.
  5729. *
  5730. * PARAMETERS:
  5731. * *cmcp_threshold_update - pointer to work_struct structure
  5732. ******************************************************************************/
  5733. static void pt_parse_cmcp_threshold_builtin(
  5734. struct work_struct *cmcp_threshold_update)
  5735. {
  5736. struct pt_device_access_data *dad =
  5737. container_of(cmcp_threshold_update,
  5738. struct pt_device_access_data,
  5739. cmcp_threshold_update);
  5740. struct device *dev = dad->dev;
  5741. struct pt_core_data *cd = dev_get_drvdata(dev);
  5742. const struct firmware *fw_entry = NULL;
  5743. int retval;
  5744. dad->si = cmd->request_sysinfo(dev);
  5745. if (!dad->si) {
  5746. pt_debug(dev, DL_ERROR,
  5747. "%s: Fail get sysinfo pointer from core\n",
  5748. __func__);
  5749. return;
  5750. }
  5751. pt_debug(dev, DL_INFO,
  5752. "%s: Enabling cmcp threshold class loader built-in\n",
  5753. __func__);
  5754. /* Open threshold file */
  5755. mutex_lock(&cd->firmware_class_lock);
  5756. #if (KERNEL_VERSION(3, 13, 0) > LINUX_VERSION_CODE)
  5757. retval = request_firmware(&fw_entry, CMCP_THRESHOLD_FILE_NAME, dev);
  5758. #else
  5759. retval = request_firmware_direct(&fw_entry,
  5760. CMCP_THRESHOLD_FILE_NAME, dev);
  5761. #endif
  5762. if (retval < 0) {
  5763. pt_debug(dev, DL_WARN,
  5764. "%s: Failed loading cmcp threshold file, attempting legacy file\n",
  5765. __func__);
  5766. /* Try legacy file name */
  5767. #if (KERNEL_VERSION(3, 13, 0) > LINUX_VERSION_CODE)
  5768. retval = request_firmware(&fw_entry,
  5769. PT_CMCP_THRESHOLD_FILE_NAME, dev);
  5770. #else
  5771. retval = request_firmware_direct(&fw_entry,
  5772. PT_CMCP_THRESHOLD_FILE_NAME, dev);
  5773. #endif
  5774. if (retval < 0) {
  5775. mutex_unlock(&cd->firmware_class_lock);
  5776. dad->builtin_cmcp_threshold_status = -EINVAL;
  5777. pt_debug(dev, DL_WARN,
  5778. "%s: Fail request cmcp threshold class file load\n",
  5779. __func__);
  5780. goto exit;
  5781. }
  5782. }
  5783. pt_cmcp_parse_threshold_file(fw_entry, dev);
  5784. mutex_unlock(&cd->firmware_class_lock);
  5785. exit:
  5786. return;
  5787. }
  5788. /*******************************************************************************
  5789. * FUNCTION: pt_device_access_probe
  5790. *
  5791. * SUMMARY: The probe function for the device access
  5792. *
  5793. * PARAMETERS:
  5794. * *dev - pointer to device structure
  5795. * **data - double pointer to pt_device_access_data data to be created here
  5796. ******************************************************************************/
  5797. static int pt_device_access_probe(struct device *dev, void **data)
  5798. {
  5799. struct pt_device_access_data *dad;
  5800. struct configuration *configurations;
  5801. struct cmcp_data *cmcp_info;
  5802. struct result *result;
  5803. int tx_num = MAX_TX_SENSORS;
  5804. int rx_num = MAX_RX_SENSORS;
  5805. int btn_num = MAX_BUTTONS;
  5806. struct test_case_field *test_case_field_array;
  5807. struct test_case_search *test_case_search_array;
  5808. int rc = 0;
  5809. dad = kzalloc(sizeof(*dad), GFP_KERNEL);
  5810. if (!dad) {
  5811. rc = -ENOMEM;
  5812. goto pt_device_access_probe_data_failed;
  5813. }
  5814. configurations =
  5815. kzalloc(sizeof(*configurations), GFP_KERNEL);
  5816. if (!configurations) {
  5817. rc = -ENOMEM;
  5818. goto pt_device_access_probe_configs_failed;
  5819. }
  5820. dad->configs = configurations;
  5821. cmcp_info = kzalloc(sizeof(*cmcp_info), GFP_KERNEL);
  5822. if (!cmcp_info) {
  5823. rc = -ENOMEM;
  5824. goto pt_device_access_probe_cmcp_info_failed;
  5825. }
  5826. dad->cmcp_info = cmcp_info;
  5827. cmcp_info->tx_num = tx_num;
  5828. cmcp_info->rx_num = rx_num;
  5829. cmcp_info->btn_num = btn_num;
  5830. result = kzalloc(sizeof(*result), GFP_KERNEL);
  5831. if (!result) {
  5832. rc = -ENOMEM;
  5833. goto pt_device_access_probe_result_failed;
  5834. }
  5835. dad->result = result;
  5836. test_case_field_array =
  5837. kzalloc(sizeof(*test_case_field_array) * MAX_CASE_NUM,
  5838. GFP_KERNEL);
  5839. if (!test_case_field_array) {
  5840. rc = -ENOMEM;
  5841. goto pt_device_access_probe_field_array_failed;
  5842. }
  5843. test_case_search_array =
  5844. kzalloc(sizeof(*test_case_search_array) * MAX_CASE_NUM,
  5845. GFP_KERNEL);
  5846. if (!test_case_search_array) {
  5847. rc = -ENOMEM;
  5848. goto pt_device_access_probe_search_array_failed;
  5849. }
  5850. cmcp_info->gd_sensor_col = (struct gd_sensor *)
  5851. kzalloc(tx_num * sizeof(struct gd_sensor), GFP_KERNEL);
  5852. if (cmcp_info->gd_sensor_col == NULL)
  5853. goto pt_device_access_probe_gd_sensor_col_failed;
  5854. cmcp_info->gd_sensor_row = (struct gd_sensor *)
  5855. kzalloc(rx_num * sizeof(struct gd_sensor), GFP_KERNEL);
  5856. if (cmcp_info->gd_sensor_row == NULL)
  5857. goto pt_device_access_probe_gd_sensor_row_failed;
  5858. cmcp_info->cm_data_panel =
  5859. kzalloc((tx_num * rx_num + 1) * sizeof(int32_t), GFP_KERNEL);
  5860. if (cmcp_info->cm_data_panel == NULL)
  5861. goto pt_device_access_probe_cm_data_panel_failed;
  5862. cmcp_info->cp_tx_data_panel =
  5863. kzalloc(tx_num * sizeof(int32_t), GFP_KERNEL);
  5864. if (cmcp_info->cp_tx_data_panel == NULL)
  5865. goto pt_device_access_probe_cp_tx_data_panel_failed;
  5866. cmcp_info->cp_tx_cal_data_panel =
  5867. kzalloc(tx_num * sizeof(int32_t), GFP_KERNEL);
  5868. if (cmcp_info->cp_tx_cal_data_panel == NULL)
  5869. goto pt_device_access_probe_cp_tx_cal_data_panel_failed;
  5870. cmcp_info->cp_rx_data_panel =
  5871. kzalloc(rx_num * sizeof(int32_t), GFP_KERNEL);
  5872. if (cmcp_info->cp_rx_data_panel == NULL)
  5873. goto pt_device_access_probe_cp_rx_data_panel_failed;
  5874. cmcp_info->cp_rx_cal_data_panel =
  5875. kzalloc(rx_num * sizeof(int32_t), GFP_KERNEL);
  5876. if (cmcp_info->cp_rx_cal_data_panel == NULL)
  5877. goto pt_device_access_probe_cp_rx_cal_data_panel_failed;
  5878. cmcp_info->cm_btn_data = kcalloc(btn_num, sizeof(int32_t), GFP_KERNEL);
  5879. if (cmcp_info->cm_btn_data == NULL)
  5880. goto pt_device_access_probe_cm_btn_data_failed;
  5881. cmcp_info->cp_btn_data = kcalloc(btn_num, sizeof(int32_t), GFP_KERNEL);
  5882. if (cmcp_info->cp_btn_data == NULL)
  5883. goto pt_device_access_probe_cp_btn_data_failed;
  5884. cmcp_info->cm_sensor_column_delta =
  5885. kzalloc(rx_num * tx_num * sizeof(int32_t), GFP_KERNEL);
  5886. if (cmcp_info->cm_sensor_column_delta == NULL)
  5887. goto pt_device_access_probe_cm_sensor_column_delta_failed;
  5888. cmcp_info->cm_sensor_row_delta =
  5889. kzalloc(tx_num * rx_num * sizeof(int32_t), GFP_KERNEL);
  5890. if (cmcp_info->cm_sensor_row_delta == NULL)
  5891. goto pt_device_access_probe_cm_sensor_row_delta_failed;
  5892. mutex_init(&dad->sysfs_lock);
  5893. mutex_init(&dad->cmcp_threshold_lock);
  5894. dad->dev = dev;
  5895. #ifdef TTHE_TUNER_SUPPORT
  5896. mutex_init(&dad->debugfs_lock);
  5897. dad->heatmap.num_element = 200;
  5898. #endif
  5899. *data = dad;
  5900. dad->test_field_array = test_case_field_array;
  5901. dad->test_search_array = test_case_search_array;
  5902. dad->test_executed = 0;
  5903. dad->cal_ext_data.mode = PT_CAL_EXT_MODE_UNDEFINED;
  5904. dad->panel_scan_retrieve_id = 0;
  5905. dad->panel_scan_type_id = 0;
  5906. INIT_WORK(&dad->cmcp_threshold_update, pt_parse_cmcp_threshold_builtin);
  5907. /* get sysinfo */
  5908. dad->si = cmd->request_sysinfo(dev);
  5909. if (dad->si) {
  5910. rc = pt_setup_sysfs(dev);
  5911. if (rc)
  5912. goto pt_device_access_setup_sysfs_failed;
  5913. } else {
  5914. pt_debug(dev, DL_ERROR,
  5915. "%s: Fail get sysinfo pointer from core p=%p\n",
  5916. __func__, dad->si);
  5917. cmd->subscribe_attention(dev, PT_ATTEN_STARTUP,
  5918. PT_DEVICE_ACCESS_NAME,
  5919. pt_setup_cmcp_attention, 0);
  5920. }
  5921. schedule_work(&dad->cmcp_threshold_update);
  5922. return 0;
  5923. pt_device_access_setup_sysfs_failed:
  5924. kfree(cmcp_info->cm_sensor_row_delta);
  5925. pt_device_access_probe_cm_sensor_row_delta_failed:
  5926. kfree(cmcp_info->cm_sensor_column_delta);
  5927. pt_device_access_probe_cm_sensor_column_delta_failed:
  5928. kfree(cmcp_info->cp_btn_data);
  5929. pt_device_access_probe_cp_btn_data_failed:
  5930. kfree(cmcp_info->cm_btn_data);
  5931. pt_device_access_probe_cm_btn_data_failed:
  5932. kfree(cmcp_info->cp_rx_cal_data_panel);
  5933. pt_device_access_probe_cp_rx_cal_data_panel_failed:
  5934. kfree(cmcp_info->cp_rx_data_panel);
  5935. pt_device_access_probe_cp_rx_data_panel_failed:
  5936. kfree(cmcp_info->cp_tx_cal_data_panel);
  5937. pt_device_access_probe_cp_tx_cal_data_panel_failed:
  5938. kfree(cmcp_info->cp_tx_data_panel);
  5939. pt_device_access_probe_cp_tx_data_panel_failed:
  5940. kfree(cmcp_info->cm_data_panel);
  5941. pt_device_access_probe_cm_data_panel_failed:
  5942. kfree(cmcp_info->gd_sensor_row);
  5943. pt_device_access_probe_gd_sensor_row_failed:
  5944. kfree(cmcp_info->gd_sensor_col);
  5945. pt_device_access_probe_gd_sensor_col_failed:
  5946. kfree(test_case_search_array);
  5947. pt_device_access_probe_search_array_failed:
  5948. kfree(test_case_field_array);
  5949. pt_device_access_probe_field_array_failed:
  5950. kfree(result);
  5951. pt_device_access_probe_result_failed:
  5952. kfree(cmcp_info);
  5953. pt_device_access_probe_cmcp_info_failed:
  5954. kfree(configurations);
  5955. pt_device_access_probe_configs_failed:
  5956. kfree(dad);
  5957. pt_device_access_probe_data_failed:
  5958. pt_debug(dev, DL_ERROR, "%s failed.\n", __func__);
  5959. return rc;
  5960. }
  5961. /*******************************************************************************
  5962. * FUNCTION: pt_device_access_release
  5963. *
  5964. * SUMMARY: Remove function for device_access module that does following
  5965. * cleanup:
  5966. * - Unsubscibe all registered attention tasks
  5967. * - Removes all created sysfs nodes
  5968. * - Frees all pointers
  5969. *
  5970. * PARAMETERS:
  5971. * *dev - pointer to device structure
  5972. * *data - pointer to the device_access data
  5973. ******************************************************************************/
  5974. static void pt_device_access_release(struct device *dev, void *data)
  5975. {
  5976. struct pt_device_access_data *dad = data;
  5977. if (dad->sysfs_nodes_created) {
  5978. debugfs_remove(dad->cmcp_results_debugfs);
  5979. debugfs_remove_recursive(dad->base_dentry);
  5980. #ifdef TTHE_TUNER_SUPPORT
  5981. debugfs_remove(dad->tthe_get_panel_data_debugfs);
  5982. #endif
  5983. device_remove_file(dev, &dev_attr_cmcp_test);
  5984. device_remove_file(dev, &dev_attr_cmcp_threshold_loading);
  5985. device_remove_bin_file(dev, &bin_attr_cmcp_threshold_data);
  5986. kfree(dad->cmcp_threshold_data);
  5987. } else {
  5988. cmd->unsubscribe_attention(dev, PT_ATTEN_STARTUP,
  5989. PT_DEVICE_ACCESS_NAME,
  5990. pt_setup_cmcp_attention, 0);
  5991. }
  5992. kfree(dad->test_search_array);
  5993. kfree(dad->test_field_array);
  5994. kfree(dad->configs);
  5995. pt_free_cmcp_buf(dad->cmcp_info);
  5996. kfree(dad->cmcp_info);
  5997. kfree(dad->result);
  5998. kfree(dad);
  5999. }
  6000. static struct pt_module device_access_module = {
  6001. .name = PT_DEVICE_ACCESS_NAME,
  6002. .probe = pt_device_access_probe,
  6003. .release = pt_device_access_release,
  6004. };
  6005. /*******************************************************************************
  6006. * FUNCTION: pt_device_access_init
  6007. *
  6008. * SUMMARY: Initialize function for device access module which to register
  6009. * device_access_module into TTDL module list.
  6010. *
  6011. * RETURN:
  6012. * 0 = success
  6013. * !0 = failure
  6014. ******************************************************************************/
  6015. static int __init pt_device_access_init(void)
  6016. {
  6017. int rc;
  6018. cmd = pt_get_commands();
  6019. if (!cmd)
  6020. return -EINVAL;
  6021. rc = pt_register_module(&device_access_module);
  6022. if (rc) {
  6023. pr_err("%s: Error, failed registering module\n",
  6024. __func__);
  6025. return rc;
  6026. }
  6027. pr_info("%s: Parade TTSP Device Access Driver (Built %s) rc = %d\n",
  6028. __func__, PT_DRIVER_VERSION, rc);
  6029. return 0;
  6030. }
  6031. module_init(pt_device_access_init);
  6032. /*******************************************************************************
  6033. * FUNCTION: pt_device_access_exit
  6034. *
  6035. * SUMMARY: Exit function for device access module which to unregister
  6036. * device_access_module from TTDL module list.
  6037. *
  6038. ******************************************************************************/
  6039. static void __exit pt_device_access_exit(void)
  6040. {
  6041. pt_unregister_module(&device_access_module);
  6042. }
  6043. module_exit(pt_device_access_exit);
  6044. MODULE_LICENSE("GPL");
  6045. MODULE_DESCRIPTION("Parade TrueTouch(R) Standard Product Device Access Driver");
  6046. MODULE_AUTHOR("Parade Technologies <[email protected]>");