fts.c 149 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2016-2019, STMicroelectronics Limited.
  4. * Authors: AMG(Analog Mems Group)
  5. *
  6. * [email protected]
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/device.h>
  13. #include <linux/irq.h>
  14. #include <linux/init.h>
  15. #include <linux/kernel.h>
  16. #include <linux/module.h>
  17. #include <linux/slab.h>
  18. #include <linux/input.h>
  19. #include <linux/input/mt.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/hrtimer.h>
  22. #include <linux/delay.h>
  23. #include <linux/firmware.h>
  24. #include <linux/i2c.h>
  25. #include <linux/i2c-dev.h>
  26. #include <linux/completion.h>
  27. /*#include <linux/wakelock.h>*/
  28. #include <linux/pm_wakeup.h>
  29. #include <dt-bindings/interrupt-controller/arm-gic.h>
  30. #include <linux/of_irq.h>
  31. #include <linux/gpio.h>
  32. #include <linux/of_gpio.h>
  33. #include <linux/regulator/consumer.h>
  34. #if defined(CONFIG_FB_MSM)
  35. #include <linux/notifier.h>
  36. #include <linux/fb.h>
  37. #else
  38. #include <drm/drm_panel.h>
  39. #endif
  40. #ifdef KERNEL_ABOVE_2_6_38
  41. #include <linux/input/mt.h>
  42. #endif
  43. #include "fts.h"
  44. #include "fts_lib/ftsCompensation.h"
  45. #include "fts_lib/ftsIO.h"
  46. #include "fts_lib/ftsError.h"
  47. #include "fts_lib/ftsFlash.h"
  48. #include "fts_lib/ftsFrame.h"
  49. #include "fts_lib/ftsGesture.h"
  50. #include "fts_lib/ftsTest.h"
  51. #include "fts_lib/ftsTime.h"
  52. #include "fts_lib/ftsTool.h"
  53. #include "linux/moduleparam.h"
  54. #if defined(CONFIG_ST_TRUSTED_TOUCH)
  55. #include <linux/atomic.h>
  56. #include <linux/clk.h>
  57. #include <linux/pm_runtime.h>
  58. #include <linux/debugfs.h>
  59. #include <linux/fs.h>
  60. #include <linux/uaccess.h>
  61. #include <linux/kobject.h>
  62. #include <linux/sysfs.h>
  63. #include "linux/gunyah/gh_irq_lend.h"
  64. #include "linux/gunyah/gh_msgq.h"
  65. #include "linux/gunyah/gh_mem_notifier.h"
  66. #include "linux/gunyah/gh_rm_drv.h"
  67. #include <linux/sort.h>
  68. #endif
  69. #define LINK_KOBJ_NAME "tp"
  70. #define FTS_DVDD_VOL_MIN 1800000
  71. #define FTS_DVDD_VOL_MAX 1800000
  72. #define FTS_DVDD_LOAD 20000
  73. #define FTS_AVDD_VOL_MIN 3000000
  74. #define FTS_AVDD_VOL_MAX 3300000
  75. #define FTS_AVDD_LOAD 20000
  76. /*
  77. * Uncomment to use polling mode instead of interrupt mode.
  78. *
  79. */
  80. // #define FTS_USE_POLLING_MODE
  81. /*
  82. * Event installer helpers
  83. */
  84. #define event_id(_e) EVENTID_##_e
  85. #define handler_name(_h) fts_##_h##_event_handler
  86. #define install_handler(_i, _evt, _hnd) \
  87. (_i->event_dispatch_table[event_id(_evt)].handler = handler_name(_hnd))
  88. /*
  89. * Asyncronouns command helper
  90. */
  91. #define WAIT_WITH_TIMEOUT(_info, _timeout, _command) \
  92. do { \
  93. if (wait_for_completion_timeout(&_info->cmd_done, _timeout) == 0) { \
  94. dev_warn(_info->dev, "Waiting for %s command: timeout\n", \
  95. #_command); \
  96. } \
  97. } while (0)
  98. #ifdef KERNEL_ABOVE_2_6_38
  99. #define TYPE_B_PROTOCOL
  100. #endif
  101. #if defined(SCRIPTLESS) || defined(DRIVER_TEST)
  102. static struct class *fts_cmd_class;
  103. #endif
  104. static void fts_interrupt_disable(struct fts_ts_info *info);
  105. static void fts_interrupt_enable(struct fts_ts_info *info);
  106. static irqreturn_t fts_interrupt_handler(int irq, void *handle);
  107. static int fts_probe_delayed(struct fts_ts_info *info);
  108. #ifdef CONFIG_ST_TRUSTED_TOUCH
  109. static struct gh_acl_desc *fts_vm_get_acl(enum gh_vm_names vm_name)
  110. {
  111. struct gh_acl_desc *acl_desc;
  112. gh_vmid_t vmid;
  113. gh_rm_get_vmid(vm_name, &vmid);
  114. acl_desc = kzalloc(offsetof(struct gh_acl_desc, acl_entries[1]),
  115. GFP_KERNEL);
  116. if (!acl_desc)
  117. return ERR_PTR(ENOMEM);
  118. acl_desc->n_acl_entries = 1;
  119. acl_desc->acl_entries[0].vmid = vmid;
  120. acl_desc->acl_entries[0].perms = GH_RM_ACL_R | GH_RM_ACL_W;
  121. return acl_desc;
  122. }
  123. static struct gh_sgl_desc *fts_vm_get_sgl(struct trusted_touch_vm_info *vm_info)
  124. {
  125. struct gh_sgl_desc *sgl_desc;
  126. int i;
  127. sgl_desc = kzalloc(offsetof(struct gh_sgl_desc,
  128. sgl_entries[vm_info->iomem_list_size]), GFP_KERNEL);
  129. if (!sgl_desc)
  130. return ERR_PTR(ENOMEM);
  131. sgl_desc->n_sgl_entries = vm_info->iomem_list_size;
  132. for (i = 0; i < vm_info->iomem_list_size; i++) {
  133. sgl_desc->sgl_entries[i].ipa_base = vm_info->iomem_bases[i];
  134. sgl_desc->sgl_entries[i].size = vm_info->iomem_sizes[i];
  135. }
  136. return sgl_desc;
  137. }
  138. static int fts_populate_vm_info(struct fts_ts_info *info)
  139. {
  140. int rc = 0;
  141. struct trusted_touch_vm_info *vm_info;
  142. struct device_node *np = info->client->dev.of_node;
  143. int num_regs, num_sizes = 0;
  144. vm_info = kzalloc(sizeof(struct trusted_touch_vm_info), GFP_KERNEL);
  145. if (!vm_info) {
  146. rc = -ENOMEM;
  147. goto error;
  148. }
  149. info->vm_info = vm_info;
  150. vm_info->irq_label = GH_IRQ_LABEL_TRUSTED_TOUCH;
  151. vm_info->vm_name = GH_TRUSTED_VM;
  152. rc = of_property_read_u32(np, "st,trusted-touch-spi-irq",
  153. &vm_info->hw_irq);
  154. if (rc) {
  155. pr_err("Failed to read trusted touch SPI irq:%d\n", rc);
  156. goto vm_error;
  157. }
  158. num_regs = of_property_count_u32_elems(np,
  159. "st,trusted-touch-io-bases");
  160. if (num_regs < 0) {
  161. pr_err("Invalid number of IO regions specified\n");
  162. rc = -EINVAL;
  163. goto vm_error;
  164. }
  165. num_sizes = of_property_count_u32_elems(np,
  166. "st,trusted-touch-io-sizes");
  167. if (num_sizes < 0) {
  168. pr_err("Invalid number of IO regions specified\n");
  169. rc = -EINVAL;
  170. goto vm_error;
  171. }
  172. if (num_regs != num_sizes) {
  173. pr_err("IO bases and sizes doe not match\n");
  174. rc = -EINVAL;
  175. goto vm_error;
  176. }
  177. vm_info->iomem_list_size = num_regs;
  178. vm_info->iomem_bases = kcalloc(num_regs, sizeof(*vm_info->iomem_bases),
  179. GFP_KERNEL);
  180. if (!vm_info->iomem_bases) {
  181. rc = -ENOMEM;
  182. goto vm_error;
  183. }
  184. rc = of_property_read_u32_array(np, "st,trusted-touch-io-bases",
  185. vm_info->iomem_bases, vm_info->iomem_list_size);
  186. if (rc) {
  187. pr_err("Failed to read trusted touch io bases:%d\n", rc);
  188. goto io_bases_error;
  189. }
  190. vm_info->iomem_sizes = kzalloc(
  191. sizeof(*vm_info->iomem_sizes) * num_sizes, GFP_KERNEL);
  192. if (!vm_info->iomem_sizes) {
  193. rc = -ENOMEM;
  194. goto io_bases_error;
  195. }
  196. rc = of_property_read_u32_array(np, "st,trusted-touch-io-sizes",
  197. vm_info->iomem_sizes, vm_info->iomem_list_size);
  198. if (rc) {
  199. pr_err("Failed to read trusted touch io sizes:%d\n", rc);
  200. goto io_sizes_error;
  201. }
  202. return rc;
  203. io_sizes_error:
  204. kfree(vm_info->iomem_sizes);
  205. io_bases_error:
  206. kfree(vm_info->iomem_bases);
  207. vm_error:
  208. kfree(vm_info);
  209. error:
  210. return rc;
  211. }
  212. static void fts_destroy_vm_info(struct fts_ts_info *info)
  213. {
  214. kfree(info->vm_info->iomem_sizes);
  215. kfree(info->vm_info->iomem_bases);
  216. kfree(info->vm_info);
  217. }
  218. static void fts_vm_deinit(struct fts_ts_info *info)
  219. {
  220. if (info->vm_info->mem_cookie)
  221. gh_mem_notifier_unregister(info->vm_info->mem_cookie);
  222. fts_destroy_vm_info(info);
  223. }
  224. #ifdef CONFIG_ARCH_QTI_VM
  225. static int fts_vm_mem_release(struct fts_ts_info *info);
  226. static void fts_trusted_touch_vm_mode_disable(struct fts_ts_info *info);
  227. static int fts_sgl_cmp(const void *a, const void *b)
  228. {
  229. struct gh_sgl_entry *left = (struct gh_sgl_entry *)a;
  230. struct gh_sgl_entry *right = (struct gh_sgl_entry *)b;
  231. return (left->ipa_base - right->ipa_base);
  232. }
  233. static int fts_vm_compare_sgl_desc(struct gh_sgl_desc *expected,
  234. struct gh_sgl_desc *received)
  235. {
  236. int idx;
  237. if (expected->n_sgl_entries != received->n_sgl_entries)
  238. return -E2BIG;
  239. sort(received->sgl_entries, received->n_sgl_entries,
  240. sizeof(received->sgl_entries[0]), fts_sgl_cmp, NULL);
  241. sort(expected->sgl_entries, expected->n_sgl_entries,
  242. sizeof(expected->sgl_entries[0]), fts_sgl_cmp, NULL);
  243. for (idx = 0; idx < expected->n_sgl_entries; idx++) {
  244. struct gh_sgl_entry *left = &expected->sgl_entries[idx];
  245. struct gh_sgl_entry *right = &received->sgl_entries[idx];
  246. if ((left->ipa_base != right->ipa_base) ||
  247. (left->size != right->size)) {
  248. pr_err("sgl mismatch: left_base:%d right base:%d left size:%d right size:%d\n",
  249. left->ipa_base, right->ipa_base,
  250. left->size, right->size);
  251. return -EINVAL;
  252. }
  253. }
  254. return 0;
  255. }
  256. static int fts_vm_handle_vm_hardware(struct fts_ts_info *info)
  257. {
  258. int rc = 0;
  259. if (atomic_read(&info->delayed_vm_probe_pending)) {
  260. rc = fts_probe_delayed(info);
  261. if (rc) {
  262. pr_err(" Delayed probe failure on VM!\n");
  263. return rc;
  264. }
  265. atomic_set(&info->delayed_vm_probe_pending, 0);
  266. return rc;
  267. }
  268. queue_delayed_work(info->fwu_workqueue, &info->fwu_work,
  269. msecs_to_jiffies(EXP_FN_WORK_DELAY_MS));
  270. fts_interrupt_enable(info);
  271. return rc;
  272. }
  273. static void fts_vm_irq_on_lend_callback(void *data,
  274. unsigned long notif_type,
  275. enum gh_irq_label label)
  276. {
  277. struct fts_ts_info *info = data;
  278. struct irq_data *irq_data;
  279. int irq = 0;
  280. int const resource_timeout = msecs_to_jiffies(2000);
  281. int rc = 0;
  282. irq = gh_irq_accept(info->vm_info->irq_label, -1, IRQ_TYPE_LEVEL_HIGH);
  283. if (irq < 0) {
  284. pr_err("failed to accept irq\n");
  285. goto irq_fail;
  286. }
  287. atomic_set(&info->vm_info->tvm_owns_irq, 1);
  288. irq_data = irq_get_irq_data(irq);
  289. if (!irq_data) {
  290. pr_err("Invalid irq data for trusted touch\n");
  291. goto irq_fail;
  292. }
  293. if (!irq_data->hwirq) {
  294. pr_err("Invalid irq in irq data\n");
  295. goto irq_fail;
  296. }
  297. if (irq_data->hwirq != info->vm_info->hw_irq) {
  298. pr_err("Invalid irq lent\n");
  299. goto irq_fail;
  300. }
  301. pr_debug("irq:returned from accept:%d\n", irq);
  302. info->client->irq = irq;
  303. if (!wait_for_completion_timeout(&info->resource_checkpoint,
  304. resource_timeout)) {
  305. pr_err("Resources not acquired in TVM\n");
  306. goto irq_fail;
  307. }
  308. rc = fts_vm_handle_vm_hardware(info);
  309. if (rc) {
  310. pr_err(" Delayed probe failure on VM!\n");
  311. goto irq_fail;
  312. }
  313. atomic_set(&info->trusted_touch_enabled, 1);
  314. return;
  315. irq_fail:
  316. fts_trusted_touch_vm_mode_disable(info);
  317. }
  318. static void fts_vm_mem_on_lend_handler(enum gh_mem_notifier_tag tag,
  319. unsigned long notif_type, void *entry_data, void *notif_msg)
  320. {
  321. struct gh_rm_notif_mem_shared_payload *payload;
  322. struct gh_sgl_desc *sgl_desc, *expected_sgl_desc;
  323. struct gh_acl_desc *acl_desc;
  324. struct trusted_touch_vm_info *vm_info;
  325. struct fts_ts_info *info;
  326. int rc = 0;
  327. if (notif_type != GH_RM_NOTIF_MEM_SHARED ||
  328. tag != GH_MEM_NOTIFIER_TAG_TOUCH) {
  329. pr_err("Invalid command passed from rm\n");
  330. return;
  331. }
  332. if (!entry_data || !notif_msg) {
  333. pr_err("Invalid entry data passed from rm\n");
  334. return;
  335. }
  336. info = (struct fts_ts_info *)entry_data;
  337. vm_info = info->vm_info;
  338. if (!vm_info) {
  339. pr_err("Invalid vm_info\n");
  340. return;
  341. }
  342. payload = (struct gh_rm_notif_mem_shared_payload *)notif_msg;
  343. if (payload->trans_type != GH_RM_TRANS_TYPE_LEND ||
  344. payload->label != TRUSTED_TOUCH_MEM_LABEL) {
  345. pr_err("Invalid label or transaction type\n");
  346. goto onlend_fail;
  347. }
  348. acl_desc = fts_vm_get_acl(GH_TRUSTED_VM);
  349. if (IS_ERR(acl_desc)) {
  350. pr_err("failed to populated acl data:rc=%d\n",
  351. PTR_ERR(acl_desc));
  352. goto onlend_fail;
  353. }
  354. sgl_desc = gh_rm_mem_accept(payload->mem_handle, GH_RM_MEM_TYPE_IO,
  355. GH_RM_TRANS_TYPE_LEND,
  356. GH_RM_MEM_ACCEPT_VALIDATE_ACL_ATTRS |
  357. GH_RM_MEM_ACCEPT_VALIDATE_LABEL |
  358. GH_RM_MEM_ACCEPT_DONE, payload->label, acl_desc,
  359. NULL, NULL, 0);
  360. if (IS_ERR_OR_NULL(sgl_desc)) {
  361. pr_err("failed to do mem accept :rc=%d\n",
  362. PTR_ERR(sgl_desc));
  363. goto acl_fail;
  364. }
  365. atomic_set(&vm_info->tvm_owns_iomem, 1);
  366. /* Initiate i2c session on tvm */
  367. rc = pm_runtime_get_sync(info->client->adapter->dev.parent);
  368. if (rc < 0) {
  369. pr_err("failed to get sync rc:%d\n", rc);
  370. (void)fts_vm_mem_release(info);
  371. atomic_set(&info->vm_info->tvm_owns_iomem, 0);
  372. goto acl_fail;
  373. }
  374. complete(&info->resource_checkpoint);
  375. expected_sgl_desc = fts_vm_get_sgl(vm_info);
  376. if (fts_vm_compare_sgl_desc(expected_sgl_desc, sgl_desc)) {
  377. pr_err("IO sg list does not match\n");
  378. goto sgl_cmp_fail;
  379. }
  380. vm_info->vm_mem_handle = payload->mem_handle;
  381. kfree(expected_sgl_desc);
  382. kfree(acl_desc);
  383. return;
  384. sgl_cmp_fail:
  385. kfree(expected_sgl_desc);
  386. acl_fail:
  387. kfree(acl_desc);
  388. onlend_fail:
  389. fts_trusted_touch_vm_mode_disable(info);
  390. }
  391. static int fts_vm_mem_release(struct fts_ts_info *info)
  392. {
  393. int rc = 0;
  394. rc = gh_rm_mem_release(info->vm_info->vm_mem_handle, 0);
  395. if (rc)
  396. pr_err("VM mem release failed: rc=%d\n", rc);
  397. rc = gh_rm_mem_notify(info->vm_info->vm_mem_handle,
  398. GH_RM_MEM_NOTIFY_OWNER_RELEASED,
  399. GH_MEM_NOTIFIER_TAG_TOUCH, 0);
  400. if (rc)
  401. pr_err("Failed to notify mem release to PVM: rc=%d\n");
  402. info->vm_info->vm_mem_handle = 0;
  403. return rc;
  404. }
  405. static void fts_trusted_touch_vm_mode_disable(struct fts_ts_info *info)
  406. {
  407. int rc = 0;
  408. if (atomic_read(&info->vm_info->tvm_owns_iomem) &&
  409. atomic_read(&info->vm_info->tvm_owns_irq))
  410. fts_interrupt_disable(info);
  411. if (atomic_read(&info->vm_info->tvm_owns_iomem)) {
  412. flushFIFO();
  413. release_all_touches(info);
  414. rc = fts_vm_mem_release(info);
  415. if (rc)
  416. pr_err("Failed to release mem rc:%d\n", rc);
  417. else
  418. atomic_set(&info->vm_info->tvm_owns_iomem, 0);
  419. pm_runtime_put_sync(info->client->adapter->dev.parent);
  420. }
  421. if (atomic_read(&info->vm_info->tvm_owns_irq)) {
  422. rc = gh_irq_release(info->vm_info->irq_label);
  423. if (rc)
  424. pr_err("Failed to release irq rc:%d\n", rc);
  425. else
  426. atomic_set(&info->vm_info->tvm_owns_irq, 0);
  427. rc = gh_irq_release_notify(info->vm_info->irq_label);
  428. if (rc)
  429. pr_err("Failed to notify release irq rc:%d\n", rc);
  430. }
  431. atomic_set(&info->trusted_touch_enabled, 0);
  432. reinit_completion(&info->resource_checkpoint);
  433. pr_debug("trusted touch disabled\n");
  434. }
  435. static int fts_handle_trusted_touch_tvm(struct fts_ts_info *info, int value)
  436. {
  437. int err = 0;
  438. switch (value) {
  439. case 0:
  440. if (atomic_read(&info->trusted_touch_enabled) == 0) {
  441. pr_err("Trusted touch is already disabled\n");
  442. break;
  443. }
  444. if (atomic_read(&info->trusted_touch_mode) ==
  445. TRUSTED_TOUCH_VM_MODE) {
  446. fts_trusted_touch_vm_mode_disable(info);
  447. } else {
  448. pr_err("Unsupported trusted touch mode\n");
  449. }
  450. break;
  451. case 1:
  452. if (atomic_read(&info->trusted_touch_enabled)) {
  453. pr_err("Trusted touch usecase underway\n");
  454. err = -EBUSY;
  455. break;
  456. }
  457. if (atomic_read(&info->trusted_touch_mode) ==
  458. TRUSTED_TOUCH_VM_MODE) {
  459. pr_err("Cannot turnon trusted touch(vm mode) in VM\n");
  460. } else {
  461. pr_err("Unsupported trusted touch mode\n");
  462. }
  463. break;
  464. default:
  465. dev_err(&info->client->dev, "unsupported value: %lu\n", value);
  466. err = -EINVAL;
  467. break;
  468. }
  469. return err;
  470. }
  471. #else
  472. static int fts_clk_prepare_enable(struct fts_ts_info *info)
  473. {
  474. int ret;
  475. ret = clk_prepare_enable(info->iface_clk);
  476. if (ret) {
  477. dev_err(&info->client->dev,
  478. "error on clk_prepare_enable(iface_clk):%d\n", ret);
  479. return ret;
  480. }
  481. ret = clk_prepare_enable(info->core_clk);
  482. if (ret) {
  483. clk_disable_unprepare(info->iface_clk);
  484. dev_err(&info->client->dev,
  485. "error clk_prepare_enable(core_clk):%d\n", ret);
  486. }
  487. return ret;
  488. }
  489. static void fts_clk_disable_unprepare(struct fts_ts_info *info)
  490. {
  491. clk_disable_unprepare(info->core_clk);
  492. clk_disable_unprepare(info->iface_clk);
  493. }
  494. static int fts_bus_get(struct fts_ts_info *info)
  495. {
  496. int rc = 0;
  497. mutex_lock(&info->fts_clk_io_ctrl_mutex);
  498. rc = pm_runtime_get_sync(info->client->adapter->dev.parent);
  499. if (rc >= 0 && info->core_clk != NULL && info->iface_clk != NULL) {
  500. rc = fts_clk_prepare_enable(info);
  501. if (rc)
  502. pm_runtime_put_sync(info->client->adapter->dev.parent);
  503. }
  504. mutex_unlock(&info->fts_clk_io_ctrl_mutex);
  505. return rc;
  506. }
  507. static void fts_bus_put(struct fts_ts_info *info)
  508. {
  509. mutex_lock(&info->fts_clk_io_ctrl_mutex);
  510. if (info->core_clk != NULL && info->iface_clk != NULL)
  511. fts_clk_disable_unprepare(info);
  512. pm_runtime_put_sync(info->client->adapter->dev.parent);
  513. mutex_unlock(&info->fts_clk_io_ctrl_mutex);
  514. }
  515. static struct gh_notify_vmid_desc *fts_vm_get_vmid(gh_vmid_t vmid)
  516. {
  517. struct gh_notify_vmid_desc *vmid_desc;
  518. vmid_desc = kzalloc(offsetof(struct gh_notify_vmid_desc,
  519. vmid_entries[1]), GFP_KERNEL);
  520. if (!vmid_desc)
  521. return ERR_PTR(ENOMEM);
  522. vmid_desc->n_vmid_entries = 1;
  523. vmid_desc->vmid_entries[0].vmid = vmid;
  524. return vmid_desc;
  525. }
  526. static void fts_trusted_touch_complete(struct fts_ts_info *info)
  527. {
  528. if (atomic_read(&info->vm_info->pvm_owns_iomem) &&
  529. atomic_read(&info->vm_info->pvm_owns_irq)) {
  530. fts_interrupt_enable(info);
  531. fts_bus_put(info);
  532. complete(&info->trusted_touch_powerdown);
  533. atomic_set(&info->trusted_touch_enabled, 0);
  534. pr_debug("reenabled interrupts on PVM\n");
  535. } else {
  536. pr_err("PVM does not own irq and IOMEM\n");
  537. }
  538. }
  539. static void fts_vm_irq_on_release_callback(void *data,
  540. unsigned long notif_type,
  541. enum gh_irq_label label)
  542. {
  543. struct fts_ts_info *info = data;
  544. int rc = 0;
  545. rc = gh_irq_reclaim(info->vm_info->irq_label);
  546. if (rc)
  547. pr_err("failed to reclaim irq on pvm rc:%d\n", rc);
  548. else
  549. atomic_set(&info->vm_info->pvm_owns_irq, 1);
  550. }
  551. static void fts_vm_mem_on_release_handler(enum gh_mem_notifier_tag tag,
  552. unsigned long notif_type, void *entry_data, void *notif_msg)
  553. {
  554. struct gh_rm_notif_mem_released_payload *payload;
  555. struct trusted_touch_vm_info *vm_info;
  556. struct fts_ts_info *info;
  557. int rc = 0;
  558. if (notif_type != GH_RM_NOTIF_MEM_RELEASED ||
  559. tag != GH_MEM_NOTIFIER_TAG_TOUCH) {
  560. pr_err(" Invalid tag or command passed\n");
  561. return;
  562. }
  563. if (!entry_data || !notif_msg) {
  564. pr_err(" Invalid data or notification message\n");
  565. return;
  566. }
  567. payload = (struct gh_rm_notif_mem_released_payload *)notif_msg;
  568. info = (struct fts_ts_info *)entry_data;
  569. vm_info = info->vm_info;
  570. if (!vm_info) {
  571. pr_err(" Invalid vm_info\n");
  572. return;
  573. }
  574. if (payload->mem_handle != vm_info->vm_mem_handle) {
  575. pr_err("Invalid mem handle detected\n");
  576. return;
  577. }
  578. rc = gh_rm_mem_reclaim(payload->mem_handle, 0);
  579. if (rc) {
  580. pr_err("Trusted touch VM mem release failed rc:%d\n", rc);
  581. return;
  582. }
  583. atomic_set(&vm_info->pvm_owns_iomem, 1);
  584. vm_info->vm_mem_handle = 0;
  585. }
  586. static int fts_vm_mem_lend(struct fts_ts_info *info)
  587. {
  588. struct gh_acl_desc *acl_desc;
  589. struct gh_sgl_desc *sgl_desc;
  590. struct gh_notify_vmid_desc *vmid_desc;
  591. gh_memparcel_handle_t mem_handle;
  592. gh_vmid_t trusted_vmid;
  593. int rc = 0;
  594. acl_desc = fts_vm_get_acl(GH_TRUSTED_VM);
  595. if (IS_ERR(acl_desc)) {
  596. pr_err("Failed to get acl of IO memories for Trusted touch\n");
  597. PTR_ERR(acl_desc);
  598. return -EINVAL;
  599. }
  600. sgl_desc = fts_vm_get_sgl(info->vm_info);
  601. if (IS_ERR(sgl_desc)) {
  602. pr_err("Failed to get sgl of IO memories for Trusted touch\n");
  603. PTR_ERR(sgl_desc);
  604. rc = -EINVAL;
  605. goto sgl_error;
  606. }
  607. rc = gh_rm_mem_lend(GH_RM_MEM_TYPE_IO, 0, TRUSTED_TOUCH_MEM_LABEL,
  608. acl_desc, sgl_desc, NULL, &mem_handle);
  609. if (rc) {
  610. pr_err("Failed to lend IO memories for Trusted touch rc:%d\n",
  611. rc);
  612. goto error;
  613. }
  614. gh_rm_get_vmid(GH_TRUSTED_VM, &trusted_vmid);
  615. vmid_desc = fts_vm_get_vmid(trusted_vmid);
  616. rc = gh_rm_mem_notify(mem_handle, GH_RM_MEM_NOTIFY_RECIPIENT_SHARED,
  617. GH_MEM_NOTIFIER_TAG_TOUCH, vmid_desc);
  618. if (rc) {
  619. pr_err("Failed to notify mem lend to hypervisor rc:%d\n", rc);
  620. goto vmid_error;
  621. }
  622. info->vm_info->vm_mem_handle = mem_handle;
  623. vmid_error:
  624. kfree(vmid_desc);
  625. error:
  626. kfree(sgl_desc);
  627. sgl_error:
  628. kfree(acl_desc);
  629. return rc;
  630. }
  631. static int fts_trusted_touch_vm_mode_enable(struct fts_ts_info *info)
  632. {
  633. int rc = 0;
  634. struct trusted_touch_vm_info *vm_info = info->vm_info;
  635. /* i2c session start and resource acquire */
  636. if (fts_bus_get(info) < 0) {
  637. dev_err(&info->client->dev, "fts_bus_get failed\n");
  638. rc = -EIO;
  639. return rc;
  640. }
  641. /* flush pending interurpts from FIFO */
  642. fts_interrupt_disable(info);
  643. flushFIFO();
  644. release_all_touches(info);
  645. rc = fts_vm_mem_lend(info);
  646. if (rc) {
  647. pr_err("Failed to lend memory\n");
  648. return -EINVAL;
  649. }
  650. atomic_set(&vm_info->pvm_owns_iomem, 0);
  651. rc = gh_irq_lend_v2(vm_info->irq_label, vm_info->vm_name,
  652. info->client->irq, &fts_vm_irq_on_release_callback, info);
  653. if (rc) {
  654. pr_err("Failed to lend irq\n");
  655. return -EINVAL;
  656. }
  657. atomic_set(&vm_info->pvm_owns_irq, 0);
  658. rc = gh_irq_lend_notify(vm_info->irq_label);
  659. if (rc) {
  660. pr_err("Failed to notify irq\n");
  661. return -EINVAL;
  662. }
  663. reinit_completion(&info->trusted_touch_powerdown);
  664. atomic_set(&info->trusted_touch_enabled, 1);
  665. pr_debug("trusted touch enabled\n");
  666. return rc;
  667. }
  668. static int fts_handle_trusted_touch_pvm(struct fts_ts_info *info, int value)
  669. {
  670. int err = 0;
  671. switch (value) {
  672. case 0:
  673. if (atomic_read(&info->trusted_touch_enabled) == 0) {
  674. pr_err("Trusted touch is already disabled\n");
  675. break;
  676. }
  677. if (atomic_read(&info->trusted_touch_mode) ==
  678. TRUSTED_TOUCH_VM_MODE) {
  679. fts_trusted_touch_complete(info);
  680. } else {
  681. pr_err("Unsupported trusted touch mode\n");
  682. }
  683. break;
  684. case 1:
  685. if (atomic_read(&info->trusted_touch_enabled)) {
  686. pr_err("Trusted touch usecase underway\n");
  687. err = -EBUSY;
  688. break;
  689. }
  690. if (atomic_read(&info->trusted_touch_mode) ==
  691. TRUSTED_TOUCH_VM_MODE) {
  692. err = fts_trusted_touch_vm_mode_enable(info);
  693. } else {
  694. pr_err("Unsupported trusted touch mode\n");
  695. }
  696. break;
  697. default:
  698. dev_err(&info->client->dev, "unsupported value: %lu\n", value);
  699. err = -EINVAL;
  700. break;
  701. }
  702. return err;
  703. }
  704. #endif
  705. static int fts_vm_init(struct fts_ts_info *info)
  706. {
  707. int rc = 0;
  708. struct trusted_touch_vm_info *vm_info;
  709. void *mem_cookie;
  710. rc = fts_populate_vm_info(info);
  711. if (rc) {
  712. pr_err("Cannot setup vm pipeline\n");
  713. rc = -EINVAL;
  714. goto fail;
  715. }
  716. vm_info = info->vm_info;
  717. #ifdef CONFIG_ARCH_QTI_VM
  718. mem_cookie = gh_mem_notifier_register(GH_MEM_NOTIFIER_TAG_TOUCH,
  719. fts_vm_mem_on_lend_handler, info);
  720. if (!mem_cookie) {
  721. pr_err("Failed to register on lend mem notifier\n");
  722. rc = -EINVAL;
  723. goto init_fail;
  724. }
  725. vm_info->mem_cookie = mem_cookie;
  726. rc = gh_irq_wait_for_lend_v2(vm_info->irq_label, GH_PRIMARY_VM,
  727. &fts_vm_irq_on_lend_callback, info);
  728. atomic_set(&vm_info->tvm_owns_irq, 0);
  729. atomic_set(&vm_info->tvm_owns_iomem, 0);
  730. init_completion(&info->resource_checkpoint);
  731. #else
  732. mem_cookie = gh_mem_notifier_register(GH_MEM_NOTIFIER_TAG_TOUCH,
  733. fts_vm_mem_on_release_handler, info);
  734. if (!mem_cookie) {
  735. pr_err("Failed to register on release mem notifier\n");
  736. rc = -EINVAL;
  737. goto init_fail;
  738. }
  739. vm_info->mem_cookie = mem_cookie;
  740. atomic_set(&vm_info->pvm_owns_irq, 1);
  741. atomic_set(&vm_info->pvm_owns_iomem, 1);
  742. #endif
  743. return rc;
  744. init_fail:
  745. fts_vm_deinit(info);
  746. fail:
  747. return rc;
  748. }
  749. static void fts_dt_parse_trusted_touch_info(struct fts_ts_info *info)
  750. {
  751. struct device_node *np = info->client->dev.of_node;
  752. int rc = 0;
  753. const char *selection;
  754. const char *environment;
  755. rc = of_property_read_string(np, "st,trusted-touch-mode",
  756. &selection);
  757. if (rc) {
  758. dev_warn(&info->client->dev,
  759. "%s: No trusted touch mode selection made\n", __func__);
  760. }
  761. if (!strcmp(selection, "vm_mode")) {
  762. atomic_set(&info->trusted_touch_mode, TRUSTED_TOUCH_VM_MODE);
  763. pr_err("Selected trusted touch mode to VM mode\n");
  764. } else {
  765. atomic_set(&info->trusted_touch_mode, TRUSTED_TOUCH_MODE_NONE);
  766. pr_err("Invalid trusted_touch mode\n");
  767. }
  768. rc = of_property_read_string(np, "st,touch-environment",
  769. &environment);
  770. if (rc) {
  771. dev_warn(&info->client->dev,
  772. "%s: No trusted touch mode environment\n", __func__);
  773. }
  774. info->touch_environment = environment;
  775. pr_err("Trusted touch environment:%s\n",
  776. info->touch_environment);
  777. }
  778. static void fts_trusted_touch_init(struct fts_ts_info *info)
  779. {
  780. int rc = 0;
  781. atomic_set(&info->trusted_touch_initialized, 0);
  782. init_completion(&info->trusted_touch_powerdown);
  783. fts_dt_parse_trusted_touch_info(info);
  784. /* Get clocks */
  785. info->core_clk = devm_clk_get(info->client->dev.parent,
  786. "m-ahb");
  787. if (IS_ERR(info->core_clk)) {
  788. info->core_clk = NULL;
  789. dev_warn(&info->client->dev,
  790. "%s: core_clk is not defined\n", __func__);
  791. }
  792. info->iface_clk = devm_clk_get(info->client->dev.parent,
  793. "se-clk");
  794. if (IS_ERR(info->iface_clk)) {
  795. info->iface_clk = NULL;
  796. dev_warn(&info->client->dev,
  797. "%s: iface_clk is not defined\n", __func__);
  798. }
  799. if (atomic_read(&info->trusted_touch_mode) == TRUSTED_TOUCH_VM_MODE) {
  800. rc = fts_vm_init(info);
  801. if (rc)
  802. pr_err("Failed to init VM\n");
  803. }
  804. atomic_set(&info->trusted_touch_initialized, 1);
  805. }
  806. static ssize_t fts_trusted_touch_enable_show(struct device *dev,
  807. struct device_attribute *attr, char *buf)
  808. {
  809. struct i2c_client *client = to_i2c_client(dev);
  810. struct fts_ts_info *info;
  811. if (!client)
  812. return scnprintf(buf, PAGE_SIZE, "client is null\n");
  813. info = i2c_get_clientdata(client);
  814. if (!info) {
  815. logError(0, "info is null\n");
  816. return scnprintf(buf, PAGE_SIZE, "info is null\n");
  817. }
  818. return scnprintf(buf, PAGE_SIZE, "%d",
  819. atomic_read(&info->trusted_touch_enabled));
  820. }
  821. static ssize_t fts_trusted_touch_enable_store(struct device *dev,
  822. struct device_attribute *attr, const char *buf, size_t count)
  823. {
  824. struct i2c_client *client = to_i2c_client(dev);
  825. struct fts_ts_info *info;
  826. unsigned long value;
  827. int err = 0;
  828. if (!client)
  829. return -EIO;
  830. info = i2c_get_clientdata(client);
  831. if (!info) {
  832. logError(0, "info is null\n");
  833. return -EIO;
  834. }
  835. if (count > 2)
  836. return -EINVAL;
  837. err = kstrtoul(buf, 10, &value);
  838. if (err != 0)
  839. return err;
  840. if (!atomic_read(&info->trusted_touch_initialized))
  841. return -EIO;
  842. #ifdef CONFIG_ARCH_QTI_VM
  843. err = fts_handle_trusted_touch_tvm(info, value);
  844. if (err) {
  845. pr_err("Failed to handle trusted touch in tvm\n");
  846. return -EINVAL;
  847. }
  848. #else
  849. err = fts_handle_trusted_touch_pvm(info, value);
  850. if (err) {
  851. pr_err("Failed to handle trusted touch in pvm\n");
  852. return -EINVAL;
  853. }
  854. #endif
  855. err = count;
  856. return err;
  857. }
  858. #endif
  859. //struct chipInfo ftsInfo;
  860. /**
  861. * #ifdef PHONE_GESTURE
  862. * extern struct mutex gestureMask_mutex;
  863. * #endif
  864. */
  865. static char tag[8] = "[ FTS ]\0";
  866. static char fts_ts_phys[64];
  867. static u32 typeOfComand[CMD_STR_LEN] = {0};
  868. static int numberParameters;
  869. #ifdef USE_ONE_FILE_NODE
  870. static int feature_feasibility = ERROR_OP_NOT_ALLOW;
  871. #endif
  872. #ifdef PHONE_GESTURE
  873. static u8 mask[GESTURE_MASK_SIZE + 2];
  874. //extern u16 gesture_coordinates_x[GESTURE_COORDS_REPORT_MAX];
  875. //extern u16 gesture_coordinates_y[GESTURE_COORDS_REPORT_MAX];
  876. //extern int gesture_coords_reported;
  877. //extern struct mutex gestureMask_mutex;
  878. #ifdef USE_CUSTOM_GESTURES
  879. static int custom_gesture_res;
  880. #endif
  881. #endif
  882. #ifdef USE_NOISE_PARAM
  883. static u8 noise_params[NOISE_PARAMETERS_SIZE] = {0};
  884. #endif
  885. static void fts_interrupt_enable(struct fts_ts_info *info);
  886. static int fts_init_afterProbe(struct fts_ts_info *info);
  887. static int fts_mode_handler(struct fts_ts_info *info, int force);
  888. static int fts_command(struct fts_ts_info *info, unsigned char cmd);
  889. static int fts_chip_initialization(struct fts_ts_info *info);
  890. static int fts_enable_reg(struct fts_ts_info *info, bool enable);
  891. static struct drm_panel *active_panel;
  892. void touch_callback(unsigned int status)
  893. {
  894. /* Empty */
  895. }
  896. unsigned int le_to_uint(const unsigned char *ptr)
  897. {
  898. return (unsigned int) ptr[0] + (unsigned int) ptr[1] * 0x100;
  899. }
  900. unsigned int be_to_uint(const unsigned char *ptr)
  901. {
  902. return (unsigned int) ptr[1] + (unsigned int) ptr[0] * 0x100;
  903. }
  904. void release_all_touches(struct fts_ts_info *info)
  905. {
  906. unsigned int type = MT_TOOL_FINGER;
  907. int i;
  908. for (i = 0; i < TOUCH_ID_MAX; i++) {
  909. #ifdef STYLUS_MODE
  910. if (test_bit(i, &info->stylus_id))
  911. type = MT_TOOL_PEN;
  912. #endif
  913. input_mt_slot(info->input_dev, i);
  914. input_mt_report_slot_state(info->input_dev, type, 0);
  915. input_report_abs(info->input_dev, ABS_MT_TRACKING_ID, -1);
  916. }
  917. input_sync(info->input_dev);
  918. info->touch_id = 0;
  919. #ifdef STYLUS_MODE
  920. info->stylus_id = 0;
  921. #endif
  922. }
  923. /************************* FW UPGGRADE *********************************/
  924. /* update firmware*/
  925. /**
  926. * echo 01/00 > fwupdate perform a fw update taking the FW to burn always
  927. * from a bin file stored in /system/etc/firmware, 01= force the FW update
  928. * whicheve fw_version and config_id; 00=perform a fw update only if the fw
  929. * in the file has a greater fw_version or config_id
  930. */
  931. /**
  932. * cat fwupdate to show the result of the burning procedure
  933. * (example output in the terminal = "AA00000001BB" if the switch is enabled)
  934. */
  935. /**
  936. * echo 01/00 > fwupdate; cat fwupdate to perform both operation stated before
  937. * in just one call
  938. */
  939. static ssize_t fts_fwupdate_store(struct device *dev,
  940. struct device_attribute *attr, const char *buf, size_t count)
  941. {
  942. int ret, mode;
  943. /*const struct firmware *fw = NULL;*/
  944. /*char *firmware_name = "st_fts.bin";*/
  945. struct Firmware fwD;
  946. struct i2c_client *client = to_i2c_client(dev);
  947. struct fts_ts_info *info = i2c_get_clientdata(client);
  948. int orig_size;
  949. u8 *orig_data;
  950. /* reading out firmware upgrade mode */
  951. ret = kstrtoint(buf, 10, &mode);
  952. if (ret != 0) {
  953. pr_err("%s: ret = %d\n", __func__, ret);
  954. return -EINVAL;
  955. }
  956. fwD.data = NULL;
  957. ret = getFWdata_nocheck(PATH_FILE_FW, &orig_data, &orig_size, 0);
  958. if (ret < OK) {
  959. logError(1, "%s %s: impossible retrieve FW... ERROR %08X\n",
  960. tag, __func__, ERROR_MEMH_READ);
  961. ret = (ret | ERROR_MEMH_READ);
  962. goto END;
  963. }
  964. ret = parseBinFile(orig_data, orig_size, &fwD, !mode);
  965. if (ret < OK) {
  966. logError(1, "%s %s: impossible parse ERROR %08X\n",
  967. tag, __func__, ERROR_MEMH_READ);
  968. ret = (ret | ERROR_MEMH_READ);
  969. goto END;
  970. }
  971. logError(0, "%s Starting flashing procedure...\n", tag);
  972. ret = flash_burn(&fwD, mode, !mode);
  973. if (ret < OK && ret != (ERROR_FW_NO_UPDATE | ERROR_FLASH_BURN_FAILED))
  974. logError(0, "%s flashProcedure: ERROR %02X\n",
  975. tag, ERROR_FLASH_PROCEDURE);
  976. logError(0, "%s flashing procedure Finished!\n", tag);
  977. END:
  978. kfree(fwD.data);
  979. info->fwupdate_stat = ret;
  980. if (ret < OK)
  981. logError(1, "%s %s Unable to upgrade firmware! ERROR %08X\n",
  982. tag, __func__, ret);
  983. return count;
  984. }
  985. static ssize_t fts_fwupdate_show(struct device *dev,
  986. struct device_attribute *attr, char *buf)
  987. {
  988. struct i2c_client *client = to_i2c_client(dev);
  989. struct fts_ts_info *info = i2c_get_clientdata(client);
  990. //fwupdate_stat: ERROR code Returned by flashProcedure.
  991. return snprintf(buf, PAGE_SIZE, "AA%08XBB\n", info->fwupdate_stat);
  992. }
  993. /****UTILITIES (current fw_ver/conf_id, active mode, file fw_ver/conf_id)****/
  994. /**
  995. * cat appid show on the terminal fw_version.config_id of
  996. * the FW running in the IC
  997. */
  998. static ssize_t fts_appid_show(struct device *dev,
  999. struct device_attribute *attr, char *buf)
  1000. {
  1001. int error;
  1002. error = snprintf(buf, PAGE_SIZE, "%x.%x\n", ftsInfo.u16_fwVer,
  1003. ftsInfo.u16_cfgId);
  1004. return error;
  1005. }
  1006. /**
  1007. * cat mode_active to show the bitmask of which indicate the modes/features
  1008. * which are running on the IC in a specific istant oftime (example output in
  1009. * the terminal = "AA10000000BB" only senseOn performed)
  1010. */
  1011. static ssize_t fts_mode_active_show(struct device *dev,
  1012. struct device_attribute *attr, char *buf)
  1013. {
  1014. struct i2c_client *client = to_i2c_client(dev);
  1015. struct fts_ts_info *info = i2c_get_clientdata(client);
  1016. logError(1, "%s Current mode active = %08X\n", tag, info->mode);
  1017. //return sprintf(buf, "AA%08XBB\n", info->mode);
  1018. return snprintf(buf, PAGE_SIZE, "AA%08XBB\n", info->mode);
  1019. }
  1020. /**
  1021. * cat fw_file_test show on the terminal fw_version and config_id of the FW
  1022. * stored in the fw file/header file
  1023. */
  1024. static ssize_t fts_fw_test_show(struct device *dev,
  1025. struct device_attribute *attr, char *buf)
  1026. {
  1027. struct Firmware fw;
  1028. int ret;
  1029. fw.data = NULL;
  1030. ret = readFwFile(PATH_FILE_FW, &fw, 0);
  1031. if (ret < OK)
  1032. logError(1, "%s Error during reading FW file! ERROR %08X\n",
  1033. tag, ret);
  1034. else {
  1035. logError(1, "%s fw_version = %04X, config_version = %04X, ",
  1036. tag, fw.fw_ver, fw.config_id);
  1037. logError(1, "size = %dbytes\n", fw.data_size);
  1038. }
  1039. kfree(fw.data);
  1040. return 0;
  1041. }
  1042. /**
  1043. * cat lockdown_info to show the lockdown info on the terminal
  1044. * (example output in the terminal = "AA00000000X1X2..X10BB" )
  1045. * where first 4 bytes correspond t
  1046. */
  1047. static ssize_t fts_lockdown_info_show(struct device *dev,
  1048. struct device_attribute *attr, char *buf)
  1049. {
  1050. u8 data[LOCKDOWN_CODE_SIZE] = {0};
  1051. int ret, size = 100;
  1052. char buff[CMD_STR_LEN] = {0};
  1053. char all_strbuff[100] = {0};
  1054. ret = fts_disableInterrupt();
  1055. if (ret < OK)
  1056. goto END;
  1057. ret = lockDownInfo((u8 *)data, LOCKDOWN_CODE_SIZE);
  1058. if (ret < OK)
  1059. goto END;
  1060. END:
  1061. ret |= fts_enableInterrupt();
  1062. snprintf(buff, sizeof(buff), "%02X", 0xAA);
  1063. strlcat(all_strbuff, buff, size);
  1064. snprintf(buff, sizeof(buff), "%08X", ret);
  1065. strlcat(all_strbuff, buff, size);
  1066. if (ret >= OK) {
  1067. for (ret = 0; ret < LOCKDOWN_CODE_SIZE; ret++) {
  1068. snprintf(buff, sizeof(buff), "%02X", data[ret]);
  1069. strlcat(all_strbuff, buff, size);
  1070. }
  1071. } else {
  1072. logError(1, "%s Error while reading lockdown info = %08X\n",
  1073. tag, ret);
  1074. }
  1075. snprintf(buff, sizeof(buff), "%02X", 0xBB);
  1076. strlcat(all_strbuff, buff, size);
  1077. return snprintf(buf, TSP_BUF_SIZE, "%s\n", all_strbuff);
  1078. }
  1079. /**
  1080. * cat strength_frame to obtain strength data
  1081. * the string returned in the shell is made up as follow:
  1082. * AA = start byte
  1083. * X1X2X3X4 = 4 bytes in HEX format which represent an
  1084. * error code (00000000 no error)
  1085. *
  1086. * if error code is all 0s
  1087. * FF = 1 byte in HEX format number of rows
  1088. * SS = 1 byte in HEX format number of columns
  1089. * N1, ... = the decimal value of each node separated by a coma
  1090. *
  1091. * BB = end byte
  1092. */
  1093. static ssize_t fts_strength_frame_store(struct device *dev,
  1094. struct device_attribute *attr, const char *buf, size_t count)
  1095. {
  1096. char *p = (char *)buf;
  1097. /*unsigned int temp;*/
  1098. /*int res;*/
  1099. /*struct i2c_client *client = to_i2c_client(dev); */
  1100. /*struct fts_ts_info *info = i2c_get_clientdata(client); */
  1101. if (sscanf(p, "%x ", &typeOfComand[0]) != 1)
  1102. return -EINVAL;
  1103. logError(1, "%s %s: Type of Strength Frame selected: %d\n", tag,
  1104. __func__, typeOfComand[0]);
  1105. return count;
  1106. }
  1107. static ssize_t fts_strength_frame_show(struct device *dev,
  1108. struct device_attribute *attr, char *buf)
  1109. {
  1110. struct MutualSenseFrame frame;
  1111. int res = ERROR_OP_NOT_ALLOW, j, size = 6*2;
  1112. int count = 0;
  1113. u16 type = 0;
  1114. char *all_strbuff = NULL;
  1115. char buff[CMD_STR_LEN] = {0};
  1116. struct i2c_client *client = to_i2c_client(dev);
  1117. struct fts_ts_info *info = i2c_get_clientdata(client);
  1118. frame.node_data = NULL;
  1119. res = fts_disableInterrupt();
  1120. if (res < OK)
  1121. goto END;
  1122. res = senseOn();
  1123. #ifdef PHONE_KEY
  1124. res = keyOn();
  1125. #endif
  1126. if (res < OK) {
  1127. logError(1, "%s %s: could not start scanning! ERROR %08X\n",
  1128. tag, __func__, res);
  1129. goto END;
  1130. }
  1131. msleep(WAIT_FOR_FRESH_FRAMES);
  1132. res = senseOff();
  1133. #ifdef PHONE_KEY
  1134. res = keyOff();
  1135. #endif
  1136. if (res < OK) {
  1137. logError(1, "%s %s: could not finish scanning! ERROR %08X\n",
  1138. tag, __func__, res);
  1139. goto END;
  1140. }
  1141. /* mdelay(WAIT_AFTER_SENSEOFF); */
  1142. msleep(WAIT_AFTER_SENSEOFF);
  1143. flushFIFO();
  1144. switch (typeOfComand[0]) {
  1145. case 1:
  1146. type = ADDR_NORM_TOUCH;
  1147. break;
  1148. #ifdef PHONE_KEY
  1149. case 2:
  1150. type = ADDR_NORM_MS_KEY;
  1151. break;
  1152. #endif
  1153. default:
  1154. logError(1, "%s %s: Strength type %d not valid! ERROR %08X\n",
  1155. tag, __func__, typeOfComand[0], ERROR_OP_NOT_ALLOW);
  1156. res = ERROR_OP_NOT_ALLOW;
  1157. goto END;
  1158. }
  1159. res = getMSFrame(type, &frame, 0);
  1160. if (res < OK) {
  1161. logError(1, "%s %s: could not get the frame! ERROR %08X\n",
  1162. tag, __func__, res);
  1163. goto END;
  1164. } else {
  1165. size += (res * 6);
  1166. logError(0, "%s The frame size is %d words\n", tag, res);
  1167. res = OK;
  1168. print_frame_short("MS Strength frame =",
  1169. array1dTo2d_short(frame.node_data,
  1170. frame.node_data_size,
  1171. frame.header.sense_node),
  1172. frame.header.force_node,
  1173. frame.header.sense_node);
  1174. }
  1175. END:
  1176. flushFIFO();
  1177. release_all_touches(info);
  1178. fts_mode_handler(info, 1);
  1179. all_strbuff = kmalloc_array(size, sizeof(char), GFP_KERNEL);
  1180. if (all_strbuff != NULL) {
  1181. memset(all_strbuff, 0, size);
  1182. snprintf(buff, sizeof(buff), "%02X", 0xAA);
  1183. strlcat(all_strbuff, buff, size);
  1184. snprintf(buff, sizeof(buff), "%08X", res);
  1185. strlcat(all_strbuff, buff, size);
  1186. if (res >= OK) {
  1187. snprintf(buff, sizeof(buff), "%02X",
  1188. (u8) frame.header.force_node);
  1189. strlcat(all_strbuff, buff, size);
  1190. snprintf(buff, sizeof(buff), "%02X",
  1191. (u8) frame.header.sense_node);
  1192. strlcat(all_strbuff, buff, size);
  1193. for (j = 0; j < frame.node_data_size; j++) {
  1194. snprintf(buff, sizeof(buff), "%d,",
  1195. frame.node_data[j]);
  1196. strlcat(all_strbuff, buff, size);
  1197. }
  1198. kfree(frame.node_data);
  1199. }
  1200. snprintf(buff, sizeof(buff), "%02X", 0xBB);
  1201. strlcat(all_strbuff, buff, size);
  1202. count = snprintf(buf, TSP_BUF_SIZE, "%s\n", all_strbuff);
  1203. kfree(all_strbuff);
  1204. } else {
  1205. logError(1, "%s %s: Unable toallocate all_strbuff!ERROR %08X\n",
  1206. tag, ERROR_ALLOC);
  1207. }
  1208. fts_enableInterrupt();
  1209. return count;
  1210. }
  1211. /********** FEATURES *********************/
  1212. /**
  1213. * TODO: edit this function according to the features policy to
  1214. * allow during the screen on/off, following is shown an example
  1215. * but check always with ST for more details
  1216. */
  1217. int check_feature_feasibility(struct fts_ts_info *info, unsigned int feature)
  1218. {
  1219. int res = OK;
  1220. /**
  1221. * Example based on the status of the screen and
  1222. * on the feature that is trying to enable
  1223. */
  1224. /*Example based only on the feature that is going to be activated*/
  1225. switch (feature) {
  1226. case FEAT_GESTURE:
  1227. if (info->cover_enabled == 1) {
  1228. res = ERROR_OP_NOT_ALLOW;
  1229. logError(1, "%s %s:Feature not allowed when in Cover ",
  1230. tag, __func__);
  1231. logError(1, "mode %08X\n", res);
  1232. /**
  1233. * for example here can be place a code for
  1234. * disabling the cover mode when gesture is
  1235. * activated
  1236. */
  1237. }
  1238. break;
  1239. case FEAT_COVER:
  1240. if (info->gesture_enabled == 1) {
  1241. res = ERROR_OP_NOT_ALLOW;
  1242. /*logError(1,"Feature not allowed*/
  1243. /*when Gestures enabled!");*/
  1244. logError(1, "s %s: Feature not allowed when Gestures ",
  1245. tag, __func__);
  1246. logError(1, "enabled%08X\n", res);
  1247. /**
  1248. * for example here can be place a code for
  1249. * disabling the gesture mode when cover is
  1250. * activated (that means that cover mode has
  1251. * an higher priority on gesture mode)
  1252. */
  1253. }
  1254. break;
  1255. default:
  1256. logError(1, "%s %s: Feature Allowed!\n", tag, __func__);
  1257. }
  1258. return res;
  1259. }
  1260. #ifdef USE_ONE_FILE_NODE
  1261. /**
  1262. * echo XXXX 00/01 > feature_enable
  1263. * set the feature to disable/enable.
  1264. * XXXX = 4 bytes which identify the feature
  1265. *
  1266. * cat feature_enable
  1267. * set the enabled mode/features in the IC
  1268. * and return an error code
  1269. *
  1270. * echo XXXX 00/01 > feature_enable;
  1271. * cat feature_enable to perform both action stated
  1272. * before in just one call
  1273. */
  1274. static ssize_t fts_feature_enable_store(struct device *dev,
  1275. struct device_attribute *attr,
  1276. const char *buf, size_t count)
  1277. {
  1278. struct i2c_client *client = to_i2c_client(dev);
  1279. struct fts_ts_info *info = i2c_get_clientdata(client);
  1280. char *p = (char *)buf;
  1281. unsigned int temp;
  1282. int res = OK;
  1283. if ((count - 8 + 1) / 3 != 1) {
  1284. logError(1, "%s fts_feature_enable: ", tag);
  1285. logError(1, "Number of parameter wrong! %d > %d\n",
  1286. (count - 8 + 1) / 3, 1);
  1287. return -EINVAL;
  1288. }
  1289. if (sscanf(p, "%08X ", &temp) != 1)
  1290. return -EINVAL;
  1291. p += 9;
  1292. res = check_feature_feasibility(info, temp);
  1293. if (res < OK)
  1294. return -EINVAL;
  1295. switch (temp) {
  1296. #ifdef PHONE_GESTURE
  1297. case FEAT_GESTURE:
  1298. if (sscanf(p, "%02X ", &info->gesture_enabled) != 1)
  1299. return -EINVAL;
  1300. logError(1, "%s fts_feature_enable: Gesture Enabled = %d\n",
  1301. tag, info->gesture_enabled);
  1302. break;
  1303. #endif
  1304. #ifdef GLOVE_MODE
  1305. case FEAT_GLOVE:
  1306. if (sscanf(p, "%02X ", &info->glove_enabled) != 1)
  1307. return -EINVAL;
  1308. logError(1, "%s fts_feature_enable: Glove Enabled = %d\n",
  1309. tag, info->glove_enabled);
  1310. break;
  1311. #endif
  1312. #ifdef STYLUS_MODE
  1313. case FEAT_STYLUS:
  1314. if (sscanf(p, "%02X ", &info->stylus_enabled) != 1)
  1315. return -EINVAL;
  1316. logError(1, "%s fts_feature_enable: Stylus Enabled = %d\n",
  1317. tag, info->stylus_enabled);
  1318. break;
  1319. #endif
  1320. #ifdef COVER_MODE
  1321. case FEAT_COVER:
  1322. if (sscanf(p, "%02X ", &info->cover_enabled) != 1)
  1323. return -EINVAL;
  1324. logError(1, "%s fts_feature_enable: Cover Enabled = %d\n",
  1325. tag, info->cover_enabled);
  1326. break;
  1327. #endif
  1328. #ifdef CHARGER_MODE
  1329. case FEAT_CHARGER:
  1330. if (sscanf(p, "%02X ", &info->charger_enabled) != 1)
  1331. return -EINVAL;
  1332. logError(1, "%s fts_feature_enable: Charger Enabled= %d\n",
  1333. tag, info->charger_enabled);
  1334. break;
  1335. #endif
  1336. #ifdef VR_MODE
  1337. case FEAT_VR:
  1338. if (sscanf(p, "%02X ", &info->vr_enabled) != 1)
  1339. return -EINVAL;
  1340. logError(1, "%s fts_feature_enable: VR Enabled = %d\n",
  1341. tag, info->vr_enabled);
  1342. break;
  1343. #endif
  1344. #ifdef EDGE_REJ
  1345. case FEAT_EDGE_REJECTION:
  1346. if (sscanf(p, "%02X ", &info->edge_rej_enabled) != 1)
  1347. return -EINVAL;
  1348. logError(1, "%s %s: Edge Rejection Enabled= %d\n",
  1349. tag, __func__, info->edge_rej_enabled);
  1350. break;
  1351. #endif
  1352. #ifdef CORNER_REJ
  1353. case FEAT_CORNER_REJECTION:
  1354. if (sscanf(p, "%02X ", &info->corner_rej_enabled) != 1)
  1355. return -EINVAL;
  1356. logError(1, "%s %s: Corner Rejection Enabled= %d\n",
  1357. tag, __func__, info->corner_rej_enabled);
  1358. break;
  1359. #endif
  1360. #ifdef EDGE_PALM_REJ
  1361. case FEAT_EDGE_PALM_REJECTION:
  1362. if (sscanf(p, "%02X", &info->edge_palm_rej_enabled) != 1)
  1363. return -EINVAL;
  1364. logError(1, "%s %s:Edge Palm RejectionEnabled= %d\n",
  1365. tag, __func__, info->edge_palm_rej_enabled);
  1366. break;
  1367. #endif
  1368. default:
  1369. logError(1, "%s %s: Feature %08X not valid! ERROR %08X\n",
  1370. tag, __func__, temp, ERROR_OP_NOT_ALLOW);
  1371. res = ERROR_OP_NOT_ALLOW;
  1372. }
  1373. feature_feasibility = res;
  1374. if (feature_feasibility >= OK)
  1375. feature_feasibility = fts_mode_handler(info, 1);
  1376. else {
  1377. logError(1, "%s %s: Call echo XXXX 00/01 > feature_enable ",
  1378. tag, __func__);
  1379. logError(1, "with a correct feature! ERROR %08X\n", res);
  1380. }
  1381. return count;
  1382. }
  1383. static ssize_t fts_feature_enable_show(struct device *dev,
  1384. struct device_attribute *attr, char *buf)
  1385. {
  1386. char buff[CMD_STR_LEN] = {0};
  1387. int size = 6 * 2;
  1388. u8 *all_strbuff = NULL;
  1389. int count = 0;
  1390. if (feature_feasibility < OK) {
  1391. logError(1,
  1392. "%s %s:Call before echo 00/01 > feature_enable %08X\n",
  1393. tag, __func__, feature_feasibility);
  1394. }
  1395. all_strbuff = kmalloc(size, GFP_KERNEL);
  1396. if (all_strbuff != NULL) {
  1397. memset(all_strbuff, 0, size);
  1398. snprintf(buff, sizeof(buff), "%02X", 0xAA);
  1399. strlcat(all_strbuff, buff, size);
  1400. snprintf(buff, sizeof(buff), "%08X", feature_feasibility);
  1401. strlcat(all_strbuff, buff, size);
  1402. snprintf(buff, sizeof(buff), "%02X", 0xBB);
  1403. strlcat(all_strbuff, buff, size);
  1404. count = snprintf(buf, TSP_BUF_SIZE, "%s\n", all_strbuff);
  1405. kfree(all_strbuff);
  1406. } else {
  1407. logError(1,
  1408. "%s %s: Unable to allocate all_strbuff! ERROR %08X\n",
  1409. tag, __func__, ERROR_ALLOC);
  1410. }
  1411. feature_feasibility = ERROR_OP_NOT_ALLOW;
  1412. return count;
  1413. }
  1414. #else
  1415. #ifdef EDGE_REJ
  1416. /**
  1417. * echo 01/00 > edge_rej to enable/disable edge rejection
  1418. * cat edge_rej to show the status of the edge_rej_enabled
  1419. * switch (example output in the terminal = "AA00000001BB"
  1420. * if the switch is enabled)
  1421. *
  1422. * echo 01/00 > edge_rej; cat edge_rej to enable/disable
  1423. * edge rejection and see the switch status in just one call
  1424. */
  1425. static ssize_t fts_edge_rej_show(struct device *dev,
  1426. struct device_attribute *attr, char *buf)
  1427. {
  1428. char buff[CMD_STR_LEN] = {0};
  1429. int size = 6 * 2;
  1430. u8 *all_strbuff = NULL;
  1431. int count = 0;
  1432. struct i2c_client *client = to_i2c_client(dev);
  1433. struct fts_ts_info *info = i2c_get_clientdata(client);
  1434. logError(0, "%s %s: edge_rej_enabled = %d\n",
  1435. tag, __func__, info->edge_rej_enabled);
  1436. all_strbuff = kmalloc(size, GFP_KERNEL);
  1437. if (all_strbuff != NULL) {
  1438. memset(all_strbuff, 0, size);
  1439. snprintf(buff, sizeof(buff), "%02X", 0xAA);
  1440. strlcat(all_strbuff, buff, size);
  1441. snprintf(buff, sizeof(buff), "%08X", info->edge_rej_enabled);
  1442. strlcat(all_strbuff, buff, size);
  1443. snprintf(buff, sizeof(buff), "%02X", 0xBB);
  1444. strlcat(all_strbuff, buff, size);
  1445. count = snprintf(buf, TSP_BUF_SIZE, "%s\n", all_strbuff);
  1446. kfree(all_strbuff);
  1447. } else
  1448. logError(1,
  1449. "%s %s: Unable to allocate all_strbuff! ERROR %08X\n",
  1450. tag, __func__, ERROR_ALLOC);
  1451. return count;
  1452. }
  1453. static ssize_t fts_edge_rej_store(struct device *dev,
  1454. struct device_attribute *attr, const char *buf, size_t count)
  1455. {
  1456. char *p = (char *)buf;
  1457. unsigned int temp;
  1458. int res;
  1459. struct i2c_client *client = to_i2c_client(dev);
  1460. struct fts_ts_info *info = i2c_get_clientdata(client);
  1461. /**
  1462. * in case of a different elaboration of the input,
  1463. * just modify this initial part of the code
  1464. */
  1465. if ((count + 1) / 3 != 1) {
  1466. logError(1,
  1467. "%s %s:Number bytes of parameter wrong!%d != %d byte\n",
  1468. tag, __func__, (count + 1) / 3, 1);
  1469. return -EINVAL;
  1470. }
  1471. if (sscanf(p, "%02X ", &temp) != 1)
  1472. return -EINVAL;
  1473. p += 3;
  1474. /**
  1475. * this is a standard code that should be always
  1476. * used when a feature is enabled!
  1477. *
  1478. * first step : check if the wanted feature can be enabled
  1479. *
  1480. * second step: call fts_mode_handler to actually enable it
  1481. * NOTE: Disabling a feature is always allowed by default
  1482. */
  1483. res = check_feature_feasibility(info, FEAT_EDGE_REJECTION);
  1484. if (res < OK && temp != FEAT_DISABLE)
  1485. return -EINVAL;
  1486. info->edge_rej_enabled = temp;
  1487. res = fts_mode_handler(info, 1);
  1488. if (res < OK) {
  1489. logError(1,
  1490. "%s %s: Error during fts_mode_handler! ERROR %08X\n",
  1491. tag, __func__, res);
  1492. }
  1493. }
  1494. return count;
  1495. }
  1496. #endif
  1497. #ifdef CORNER_REJ
  1498. /**
  1499. * echo 01/00 > corner_rej to enable/disable corner rejection
  1500. * cat corner_rej to show the status of the
  1501. * corner_rej_enabled switch (example output in the terminal
  1502. * = "AA00000001BB" if the switch is enabled)
  1503. *
  1504. * echo 01/00 > corner_rej; cat corner_rej to enable/disable
  1505. * corner rejection and see the switch status in just one call
  1506. */
  1507. static ssize_t fts_corner_rej_show(struct device *dev,
  1508. struct device_attribute *attr, char *buf)
  1509. {
  1510. char buff[CMD_STR_LEN] = {0};
  1511. int size = 6 * 2;
  1512. u8 *all_strbuff = NULL;
  1513. int count = 0;
  1514. struct i2c_client *client = to_i2c_client(dev);
  1515. struct fts_ts_info *info = i2c_get_clientdata(client);
  1516. logError(0, "%s %s: corner_rej_enabled = %d\n",
  1517. tag, __func__, info->corner_rej_enabled);
  1518. all_strbuff = kmalloc(size, GFP_KERNEL);
  1519. if (all_strbuff != NULL) {
  1520. memset(all_strbuff, 0, size);
  1521. snprintf(buff, sizeof(buff), "%02X", 0xAA);
  1522. strlcat(all_strbuff, buff, size);
  1523. snprintf(buff, sizeof(buff), "%08X", info->corner_rej_enabled);
  1524. strlcat(all_strbuff, buff, size);
  1525. snprintf(buff, sizeof(buff), "%02X", 0xBB);
  1526. strlcat(all_strbuff, buff, size);
  1527. count = snprintf(buf, TSP_BUF_SIZE, "%s\n", all_strbuff);
  1528. kfree(all_strbuff);
  1529. } else {
  1530. logError(1, "%s%s:Unable to allocate all_strbuff! ERROR %08X\n",
  1531. tag, __func__, ERROR_ALLOC);
  1532. }
  1533. return count;
  1534. }
  1535. static ssize_t fts_corner_rej_store(struct device *dev,
  1536. struct device_attribute *attr, const char *buf, size_t count)
  1537. {
  1538. char *p = (char *)buf;
  1539. unsigned int temp;
  1540. int res;
  1541. struct i2c_client *client = to_i2c_client(dev);
  1542. struct fts_ts_info *info = i2c_get_clientdata(client);
  1543. /**
  1544. * in case of a different elaboration of the input,
  1545. * just modify this initial part of the code according
  1546. * to customer needs
  1547. */
  1548. if ((count + 1) / 3 != 1) {
  1549. logError(1,
  1550. "%s %s:Number bytes of parameter wrong!%d != %d byte\n",
  1551. tag, __func__, (count + 1) / 3, 1);
  1552. return -EINVAL;
  1553. }
  1554. /*sscanf(p, "%02X ", &temp);*/
  1555. if (sscanf(p, "%02X ", &temp) != 1)
  1556. return -EINVAL;
  1557. p += 3;
  1558. /**
  1559. * this is a standard code that should be always
  1560. * used when a feature is enabled!
  1561. *
  1562. * first step : check if the wanted feature
  1563. * can be enabled
  1564. *
  1565. * second step: call fts_mode_handler to
  1566. * actually enable it
  1567. *
  1568. * NOTE: Disabling a feature is always
  1569. * allowed by default
  1570. */
  1571. res = check_feature_feasibility(info, FEAT_CORNER_REJECTION);
  1572. if (res >= OK || temp == FEAT_DISABLE) {
  1573. info->corner_rej_enabled = temp;
  1574. res = fts_mode_handler(info, 1);
  1575. if (res < OK) {
  1576. logError(1,
  1577. "%s %s: During fts_mode_handler!ERROR %08X\n",
  1578. tag, __func__, res);
  1579. }
  1580. }
  1581. return count;
  1582. }
  1583. #endif
  1584. #ifdef EDGE_PALM_REJ
  1585. /**
  1586. * echo 01/00 > edge_palm_rej
  1587. * to enable/disable edge palm rejection
  1588. *
  1589. * cat edge_palm_rej to show the status of the
  1590. * edge_palm_rej_enabled switch (example output
  1591. * in the terminal = "AA00000001BB" if the switch is enabled)
  1592. *
  1593. * echo 01/00 > edge_palm_rej; cat edge_palm_rej
  1594. * to enable/disable edge palm rejection and see
  1595. * the switch status in just one call
  1596. */
  1597. static ssize_t fts_edge_palm_rej_show(struct device *dev,
  1598. struct device_attribute *attr, char *buf)
  1599. {
  1600. char buff[CMD_STR_LEN] = {0};
  1601. int size = 6 * 2;
  1602. u8 *all_strbuff = NULL;
  1603. int count = 0;
  1604. struct i2c_client *client = to_i2c_client(dev);
  1605. struct fts_ts_info *info = i2c_get_clientdata(client);
  1606. logError(0, "%s %s: edge_palm_rej_enabled = %d\n",
  1607. tag, __func__, info->edge_palm_rej_enabled);
  1608. all_strbuff = kmalloc(size, GFP_KERNEL);
  1609. if (all_strbuff != NULL) {
  1610. memset(all_strbuff, 0, size);
  1611. snprintf(buff, sizeof(buff), "%02X", 0xAA);
  1612. strlcat(all_strbuff, buff, size);
  1613. snprintf(buff, sizeof(buff), "%08X",
  1614. info->edge_palm_rej_enabled);
  1615. strlcat(all_strbuff, buff, size);
  1616. snprintf(buff, sizeof(buff), "%02X", 0xBB);
  1617. strlcat(all_strbuff, buff, size);
  1618. count = snprintf(buf, TSP_BUF_SIZE, "%s\n",
  1619. all_strbuff);
  1620. kfree(all_strbuff);
  1621. } else {
  1622. logError(1, "%s%s:Unable to allocate all_strbuff! %08X\n",
  1623. tag, __func__, ERROR_ALLOC);
  1624. }
  1625. return count;
  1626. }
  1627. static ssize_t fts_edge_palm_rej_store(struct device *dev,
  1628. struct device_attribute *attr, const char *buf, size_t count)
  1629. {
  1630. char *p = (char *)buf;
  1631. unsigned int temp;
  1632. int res;
  1633. struct i2c_client *client = to_i2c_client(dev);
  1634. struct fts_ts_info *info = i2c_get_clientdata(client);
  1635. /**
  1636. * in case of a different elaboration of the input,
  1637. * just modify this initial part of the code according
  1638. * to customer needs
  1639. */
  1640. if ((count + 1) / 3 != 1) {
  1641. logError(1,
  1642. "%s%s:Number bytes of parameter wrong! %d != %d byte\n",
  1643. tag, __func__, (count + 1) / 3, 1);
  1644. return -EINVAL;
  1645. }
  1646. /*sscanf(p, "%02X ", &temp);*/
  1647. if (sscanf(p, "%02X ", &temp) != 1)
  1648. return -EINVAL;
  1649. p += 3;
  1650. /**
  1651. * this is a standard code that should be
  1652. * always used when a feature is enabled!
  1653. *
  1654. * first step : check if the wanted feature can be enabled
  1655. *
  1656. * second step: call fts_mode_handler to actually enable it
  1657. *
  1658. * NOTE: Disabling a feature is always allowed by default
  1659. */
  1660. res = check_feature_feasibility(info, FEAT_EDGE_PALM_REJECTION);
  1661. if (res >= OK || temp == FEAT_DISABLE) {
  1662. info->edge_palm_rej_enabled = temp;
  1663. res = fts_mode_handler(info, 1);
  1664. if (res < OK) {
  1665. logError(1, "%s%s:Error in fts_mode_handler!%08X\n",
  1666. tag, __func__, res);
  1667. }
  1668. }
  1669. return count;
  1670. }
  1671. #endif
  1672. #ifdef CHARGER_MODE
  1673. /**
  1674. * echo 01/00 > charger_mode to enable/disable charger mode
  1675. *
  1676. * cat charger_mode to show the status of
  1677. * the charger_enabled switch (example output in the terminal
  1678. * = "AA00000001BB" if the switch is enabled)
  1679. *
  1680. * echo 01/00 > charger_mode; cat charger_mode
  1681. * to enable/disable charger mode and see the
  1682. * switch status in just one call
  1683. */
  1684. static ssize_t fts_charger_mode_show(struct device *dev,
  1685. struct device_attribute *attr, char *buf)
  1686. {
  1687. char buff[CMD_STR_LEN] = {0};
  1688. int size = 6 * 2;
  1689. u8 *all_strbuff = NULL;
  1690. int count = 0;
  1691. struct i2c_client *client = to_i2c_client(dev);
  1692. struct fts_ts_info *info = i2c_get_clientdata(client);
  1693. logError(0, "%s %s:charger_enabled = %d\n",
  1694. tag, __func__, info->charger_enabled);
  1695. all_strbuff = kmalloc(size, GFP_KERNEL);
  1696. if (all_strbuff != NULL) {
  1697. memset(all_strbuff, 0, size);
  1698. snprintf(buff, sizeof(buff), "%02X", 0xAA);
  1699. strlcat(all_strbuff, buff, size);
  1700. snprintf(buff, sizeof(buff), "%08X", info->charger_enabled);
  1701. strlcat(all_strbuff, buff, size);
  1702. snprintf(buff, sizeof(buff), "%02X", 0xBB);
  1703. strlcat(all_strbuff, buff, size);
  1704. count = snprintf(buf, TSP_BUF_SIZE, "%s\n", all_strbuff);
  1705. kfree(all_strbuff);
  1706. } else {
  1707. logError(1, "%s %s:Unable to allocate all_strbuff! %08X\n",
  1708. tag, __func__, ERROR_ALLOC);
  1709. }
  1710. return count;
  1711. }
  1712. static ssize_t fts_charger_mode_store(struct device *dev,
  1713. struct device_attribute *attr, const char *buf, size_t count)
  1714. {
  1715. char *p = (char *)buf;
  1716. unsigned int temp;
  1717. int res;
  1718. struct i2c_client *client = to_i2c_client(dev);
  1719. struct fts_ts_info *info = i2c_get_clientdata(client);
  1720. /**
  1721. * in case of a different elaboration of the input,
  1722. * just modify this initial part of the code
  1723. * according to customer needs
  1724. */
  1725. if ((count + 1) / 3 != 1) {
  1726. logError(1, "%s %s:Size of parameter wrong! %d != %d byte\n",
  1727. tag, __func__, (count + 1) / 3, 1);
  1728. return -EINVAL;
  1729. }
  1730. /*sscanf(p, "%02X ", &temp);*/
  1731. if (sscanf(p, "%02X ", &temp) != 1)
  1732. return -EINVAL;
  1733. p += 3;
  1734. /**
  1735. * this is a standard code that should be always
  1736. * used when a feature is enabled!
  1737. *
  1738. * first step : check if the wanted feature
  1739. * can be enabled
  1740. * second step: call fts_mode_handler to
  1741. * actually enable it
  1742. *
  1743. * NOTE: Disabling a feature is always
  1744. * allowed by default
  1745. */
  1746. res = check_feature_feasibility(info, FEAT_CHARGER);
  1747. if (res >= OK || temp == FEAT_DISABLE) {
  1748. info->charger_enabled = temp;
  1749. res = fts_mode_handler(info, 1);
  1750. if (res < OK) {
  1751. logError(1, "%s %s: Error during fts_mode_handler! ",
  1752. tag, __func__);
  1753. logError(1, "ERROR %08X\n", res);
  1754. }
  1755. }
  1756. return count;
  1757. }
  1758. #endif
  1759. #ifdef GLOVE_MODE
  1760. /**
  1761. * echo 01/00 > glove_mode
  1762. * to enable/disable glove mode
  1763. *
  1764. * cat glove_mode to show the status of
  1765. * the glove_enabled switch (example output in the
  1766. * terminal = "AA00000001BB" if the switch is enabled)
  1767. *
  1768. * echo 01/00 > glove_mode; cat glove_mode
  1769. * to enable/disable glove mode and see the
  1770. * switch status in just one call
  1771. */
  1772. static ssize_t fts_glove_mode_show(struct device *dev,
  1773. struct device_attribute *attr, char *buf)
  1774. {
  1775. char buff[CMD_STR_LEN] = {0};
  1776. int size = 6 * 2;
  1777. u8 *all_strbuff = NULL;
  1778. int count = 0;
  1779. struct i2c_client *client = to_i2c_client(dev);
  1780. struct fts_ts_info *info = i2c_get_clientdata(client);
  1781. logError(0, "%s %s:glove_enabled = %d\n",
  1782. tag, __func__, info->glove_enabled);
  1783. all_strbuff = kmalloc(size, GFP_KERNEL);
  1784. if (all_strbuff != NULL) {
  1785. memset(all_strbuff, 0, size);
  1786. snprintf(buff, sizeof(buff), "%02X", 0xAA);
  1787. strlcat(all_strbuff, buff, size);
  1788. snprintf(buff, sizeof(buff), "%08X", info->glove_enabled);
  1789. strlcat(all_strbuff, buff, size);
  1790. snprintf(buff, sizeof(buff), "%02X", 0xBB);
  1791. strlcat(all_strbuff, buff, size);
  1792. count = snprintf(buf, TSP_BUF_SIZE, "%s\n", all_strbuff);
  1793. kfree(all_strbuff);
  1794. } else {
  1795. logError(1, "%s %s:Unable to allocate all_strbuff! %08X\n",
  1796. tag, __func__, ERROR_ALLOC);
  1797. }
  1798. return count;
  1799. }
  1800. static ssize_t fts_glove_mode_store(struct device *dev,
  1801. struct device_attribute *attr, const char *buf, size_t count)
  1802. {
  1803. char *p = (char *)buf;
  1804. unsigned int temp;
  1805. int res;
  1806. struct i2c_client *client = to_i2c_client(dev);
  1807. struct fts_ts_info *info = i2c_get_clientdata(client);
  1808. /**
  1809. * in case of a different elaboration of the input,
  1810. * just modify this initial part of the code
  1811. * according to customer needs
  1812. */
  1813. if ((count + 1) / 3 != 1) {
  1814. logError(1, "%s %s:Size of parameter wrong! %d != %d byte\n",
  1815. tag, __func__, (count + 1) / 3, 1);
  1816. return -EINVAL;
  1817. }
  1818. if (sscanf(p, "%02X ", &temp) != 1)
  1819. return -EINVAL;
  1820. p += 3;
  1821. /**
  1822. * this is a standard code that should be
  1823. * always used when a feature is enabled!
  1824. *
  1825. * first step : check if the wanted feature can be enabled
  1826. *
  1827. * second step: call fts_mode_handler to actually enable it
  1828. *
  1829. * NOTE: Disabling a feature is always allowed by default
  1830. */
  1831. res = check_feature_feasibility(info, FEAT_GLOVE);
  1832. if (res >= OK || temp == FEAT_DISABLE) {
  1833. info->glove_enabled = temp;
  1834. res = fts_mode_handler(info, 1);
  1835. if (res < OK) {
  1836. logError(1, "%s %s: Error during fts_mode_handler! ",
  1837. tag, __func__);
  1838. logError(1, "ERROR %08X\n", res);
  1839. }
  1840. }
  1841. return count;
  1842. }
  1843. #endif
  1844. #ifdef VR_MODE
  1845. /**
  1846. * echo 01/00 > vr_mode to enable/disable vr mode
  1847. *
  1848. * cat vr_mode to show the status of
  1849. * the vr_enabled switch (example output in the
  1850. * terminal = "AA00000001BB" if the switch is enabled)
  1851. *
  1852. * echo 01/00 > vr_mode; cat vr_mode to enable/disable
  1853. * vr mode and see the switch status in just one call
  1854. */
  1855. static ssize_t fts_vr_mode_show(struct device *dev,
  1856. struct device_attribute *attr, char *buf)
  1857. {
  1858. char buff[CMD_STR_LEN] = {0};
  1859. int size = 6 * 2;
  1860. u8 *all_strbuff = NULL;
  1861. int count = 0;
  1862. struct i2c_client *client = to_i2c_client(dev);
  1863. struct fts_ts_info *info = i2c_get_clientdata(client);
  1864. logError(0, "%s %s: vr_enabled = %d\n",
  1865. tag, __func__, info->vr_enabled);
  1866. all_strbuff = kmalloc(size, GFP_KERNEL);
  1867. if (all_strbuff != NULL) {
  1868. memset(all_strbuff, 0, size);
  1869. snprintf(buff, sizeof(buff), "%02X", 0xAA);
  1870. strlcat(all_strbuff, buff, size);
  1871. snprintf(buff, sizeof(buff), "%08X", info->vr_enabled);
  1872. strlcat(all_strbuff, buff, size);
  1873. snprintf(buff, sizeof(buff), "%02X", 0xBB);
  1874. strlcat(all_strbuff, buff, size);
  1875. count = snprintf(buf, TSP_BUF_SIZE, "%s\n", all_strbuff);
  1876. kfree(all_strbuff);
  1877. } else {
  1878. logError(1,
  1879. "%s %s: Unable to allocate all_strbuff! ERROR %08X\n",
  1880. tag, __func__, ERROR_ALLOC);
  1881. }
  1882. return count;
  1883. }
  1884. static ssize_t fts_vr_mode_store(struct device *dev,
  1885. struct device_attribute *attr, const char *buf, size_t count)
  1886. {
  1887. char *p = (char *)buf;
  1888. unsigned int temp;
  1889. int res;
  1890. struct i2c_client *client = to_i2c_client(dev);
  1891. struct fts_ts_info *info = i2c_get_clientdata(client);
  1892. /**
  1893. * in case of a different elaboration of the input,
  1894. * just modify this initial part of the code
  1895. * according to customer needs
  1896. */
  1897. if ((count + 1) / 3 != 1) {
  1898. logError(1,
  1899. "%s %s:Number bytes of parameter wrong!%d != %d byte\n",
  1900. tag, __func__, (count + 1) / 3, 1);
  1901. return -EINVAL;
  1902. }
  1903. if (sscanf(p, "%02X ", &temp) != 1)
  1904. return -EINVAL;
  1905. p += 3;
  1906. /**
  1907. * this is a standard code that should be always
  1908. * used when a feature is enabled!
  1909. *
  1910. * first step : check if the wanted feature can be enabled
  1911. * second step: call fts_mode_handler to actually enable it
  1912. *
  1913. * NOTE: Disabling a feature is always allowed by default
  1914. */
  1915. res = check_feature_feasibility(info, FEAT_VR);
  1916. if (res >= OK || temp == FEAT_DISABLE) {
  1917. info->vr_enabled = temp;
  1918. res = fts_mode_handler(info, 1);
  1919. if (res < OK) {
  1920. logError(1, "%s %s: Error in fts_mode_handler!%08X\n",
  1921. tag, __func__, res);
  1922. }
  1923. }
  1924. return count;
  1925. }
  1926. #endif
  1927. #ifdef COVER_MODE
  1928. /**
  1929. * echo 01/00 > cover_mode to enable/disable cover mode
  1930. * cat cover_mode to show the status of the
  1931. * cover_enabled switch (example output in the
  1932. * terminal = "AA00000001BB" if the switch is enabled)
  1933. *
  1934. * echo 01/00 > cover_mode; cat cover_mode to
  1935. * enable/disable cover mode and see the switch
  1936. * status in just one call
  1937. *
  1938. * NOTE: the cover can be handled also using a notifier,
  1939. * in this case the body of these functions
  1940. * should be copied in the notifier callback
  1941. */
  1942. static ssize_t fts_cover_mode_show(struct device *dev,
  1943. struct device_attribute *attr, char *buf)
  1944. {
  1945. char buff[CMD_STR_LEN] = {0};
  1946. int size = 6 * 2;
  1947. u8 *all_strbuff = NULL;
  1948. int count = 0;
  1949. struct i2c_client *client = to_i2c_client(dev);
  1950. struct fts_ts_info *info = i2c_get_clientdata(client);
  1951. logError(0, "%s %s: cover_enabled = %d\n",
  1952. tag, __func__, info->cover_enabled);
  1953. all_strbuff = kmalloc(size, GFP_KERNEL);
  1954. if (all_strbuff != NULL) {
  1955. memset(all_strbuff, 0, size);
  1956. snprintf(buff, sizeof(buff), "%02X", 0xAA);
  1957. strlcat(all_strbuff, buff, size);
  1958. snprintf(buff, sizeof(buff), "%08X", info->cover_enabled);
  1959. strlcat(all_strbuff, buff, size);
  1960. snprintf(buff, sizeof(buff), "%02X", 0xBB);
  1961. strlcat(all_strbuff, buff, size);
  1962. count = snprintf(buf, TSP_BUF_SIZE, "%s\n", all_strbuff);
  1963. kfree(all_strbuff);
  1964. } else {
  1965. logError(1,
  1966. "%s %s:Unable to allocate all_strbuff! ERROR %08X\n",
  1967. tag, __func__, ERROR_ALLOC);
  1968. }
  1969. return count;
  1970. }
  1971. static ssize_t fts_cover_mode_store(struct device *dev,
  1972. struct device_attribute *attr, const char *buf, size_t count)
  1973. {
  1974. char *p = (char *)buf;
  1975. unsigned int temp;
  1976. int res;
  1977. struct i2c_client *client = to_i2c_client(dev);
  1978. struct fts_ts_info *info = i2c_get_clientdata(client);
  1979. /**
  1980. * in case of a different elaboration of the input,
  1981. * just modify this initial part of the code according
  1982. * to customer needs
  1983. */
  1984. if ((count + 1) / 3 != 1) {
  1985. logError(1,
  1986. "%s %s:Number bytes of parameter wrong!%d != %d byte\n",
  1987. tag, __func__, (count + 1) / 3, 1);
  1988. return -EINVAL;
  1989. }
  1990. if (sscanf(p, "%02X ", &temp) != 1)
  1991. return -EINVAL;
  1992. p += 3;
  1993. /**
  1994. * this is a standard code that should be
  1995. * always used when a feature is enabled!
  1996. *
  1997. * first step : check if the wanted feature can be enabled
  1998. * second step: call fts_mode_handler to actually enable it
  1999. * NOTE: Disabling a feature is always allowed by default
  2000. */
  2001. res = check_feature_feasibility(info, FEAT_COVER);
  2002. if (res >= OK || temp == FEAT_DISABLE) {
  2003. info->cover_enabled = temp;
  2004. res = fts_mode_handler(info, 1);
  2005. if (res < OK) {
  2006. logError(1, "%s%s:Error in fts_mode_handler!%08X\n",
  2007. tag, __func__, res);
  2008. }
  2009. }
  2010. return count;
  2011. }
  2012. #endif
  2013. #ifdef STYLUS_MODE
  2014. /**
  2015. * echo 01/00 > stylus_mode to enable/disable stylus mode
  2016. * cat stylus_mode to show the status of
  2017. * the stylus_enabled switch (example output in the
  2018. * terminal = "AA00000001BB" if the switch is enabled)
  2019. *
  2020. * echo 01/00 > stylus_mode; cat stylus_mode to
  2021. * enable/disable stylus mode and see the
  2022. * switch status in just one call
  2023. */
  2024. static ssize_t fts_stylus_mode_show(struct device *dev,
  2025. struct device_attribute *attr, char *buf)
  2026. {
  2027. char buff[CMD_STR_LEN] = {0};
  2028. int size = 6 * 2;
  2029. u8 *all_strbuff = NULL;
  2030. int count = 0;
  2031. struct i2c_client *client = to_i2c_client(dev);
  2032. struct fts_ts_info *info = i2c_get_clientdata(client);
  2033. logError(0, "%s %s: stylus_enabled = %d\n",
  2034. tag, __func__, info->stylus_enabled);
  2035. all_strbuff = kmalloc(size, GFP_KERNEL);
  2036. if (all_strbuff != NULL) {
  2037. memset(all_strbuff, 0, size);
  2038. snprintf(buff, sizeof(buff), "%02X", 0xAA);
  2039. strlcat(all_strbuff, buff, size);
  2040. snprintf(buff, sizeof(buff), "%08X", info->stylus_enabled);
  2041. strlcat(all_strbuff, buff, size);
  2042. snprintf(buff, sizeof(buff), "%02X", 0xBB);
  2043. strlcat(all_strbuff, buff, size);
  2044. count = snprintf(buf, TSP_BUF_SIZE, "%s\n", all_strbuff);
  2045. kfree(all_strbuff);
  2046. } else {
  2047. logError(1,
  2048. "%s %s: Unable to allocate all_strbuff! ERROR %08X\n",
  2049. tag, __func__, ERROR_ALLOC);
  2050. }
  2051. return count;
  2052. }
  2053. static ssize_t fts_stylus_mode_store(struct device *dev,
  2054. struct device_attribute *attr, const char *buf, size_t count)
  2055. {
  2056. char *p = (char *)buf;
  2057. unsigned int temp;
  2058. int res;
  2059. struct i2c_client *client = to_i2c_client(dev);
  2060. struct fts_ts_info *info = i2c_get_clientdata(client);
  2061. /**
  2062. * in case of a different elaboration of the input,
  2063. * just modify this initial part of the code
  2064. * according to customer needs
  2065. */
  2066. if ((count + 1) / 3 != 1) {
  2067. logError(1, "%s %s:Size of parameter wrong! %d != %d byte\n",
  2068. tag, __func__, (count + 1) / 3, 1);
  2069. return -EINVAL;
  2070. }
  2071. if (sscanf(p, "%02X ", &temp) != 1)
  2072. return -EINVAL;
  2073. p += 3;
  2074. /**
  2075. * this is a standard code that should be
  2076. * always used when a feature is enabled!
  2077. *
  2078. * first step : check if the wanted feature can be enabled
  2079. * second step: call fts_mode_handler to actually enable it
  2080. * NOTE: Disabling a feature is always allowed by default
  2081. */
  2082. res = check_feature_feasibility(info, FEAT_STYLUS);
  2083. if (res >= OK || temp == FEAT_DISABLE) {
  2084. info->stylus_enabled = temp;
  2085. res = fts_mode_handler(info, 1);
  2086. if (res < OK) {
  2087. logError(1,
  2088. "%s %s:Error during fts_mode_handler! %08X\n",
  2089. tag, __func__, res);
  2090. }
  2091. }
  2092. return count;
  2093. }
  2094. #endif
  2095. #endif
  2096. /************** GESTURES *************/
  2097. #ifdef PHONE_GESTURE
  2098. #ifdef USE_GESTURE_MASK
  2099. /**
  2100. * if this define is used, a gesture bit mask
  2101. * is used as method to select the gestures
  2102. * to enable/disable
  2103. */
  2104. /**
  2105. * echo EE X1 X2 ... X8 > gesture_mask set
  2106. * the gesture mask to disable/enable;
  2107. * EE = 00(disable) or 01(enable);
  2108. * X1 ... X8 = gesture mask (example 06 00 ... 00
  2109. * this gesture mask represent the gestures with ID = 1 and 2)
  2110. * can be specified from 1 to 8 bytes, if less than 8 bytes
  2111. * are specified the remaining bytes are kept as previous settings
  2112. *
  2113. * cat gesture_mask enable/disable the given mask,
  2114. * if one or more gestures is enabled the driver will
  2115. * automatically enable the gesture mode.
  2116. * If all the gestures are disabled the driver
  2117. * automatically will disable the gesture mode.
  2118. * At the end an error code will be printed
  2119. * (example output in the terminal = "AA00000000BB"
  2120. * if there are no errors)
  2121. *
  2122. * echo EE X1 X2 ... X8 > gesture_mask;
  2123. * cat gesture_mask perform in one
  2124. * command both actions stated before
  2125. */
  2126. static ssize_t fts_gesture_mask_show(struct device *dev,
  2127. struct device_attribute *attr, char *buf)
  2128. {
  2129. char buff[CMD_STR_LEN] = {0};
  2130. int size = 6 * 2;
  2131. u8 *all_strbuff = NULL;
  2132. int count = 0, res, temp;
  2133. struct i2c_client *client = to_i2c_client(dev);
  2134. struct fts_ts_info *info = i2c_get_clientdata(client);
  2135. if (mask[0] == 0) {
  2136. res = ERROR_OP_NOT_ALLOW;
  2137. logError(1, "%s %s:Call before echo enable/disable xx xx >",
  2138. tag, __func__);
  2139. logError(1, "%s %s: gesture_mask with a correct number of ",
  2140. tag, __func__);
  2141. logError(1, "parameters! ERROR %08X\n", res);
  2142. return -EINVAL;
  2143. }
  2144. if (mask[1] == FEAT_ENABLE || mask[1] == FEAT_DISABLE)
  2145. res = updateGestureMask(&mask[2], mask[0], mask[1]);
  2146. else
  2147. res = ERROR_OP_NOT_ALLOW;
  2148. if (res < OK) {
  2149. logError(1, "%s fts_gesture_mask_store: ERROR %08X\n",
  2150. tag, res);
  2151. }
  2152. res |= check_feature_feasibility(info, FEAT_GESTURE);
  2153. temp = isAnyGestureActive();
  2154. if (res >= OK || temp == FEAT_DISABLE)
  2155. info->gesture_enabled = temp;
  2156. logError(1, "%s fts_gesture_mask_store:Gesture Enabled = %d\n",
  2157. tag, info->gesture_enabled);
  2158. all_strbuff = kmalloc(size, GFP_KERNEL);
  2159. if (all_strbuff != NULL) {
  2160. memset(all_strbuff, 0, size);
  2161. snprintf(buff, sizeof(buff), "%02X", 0xAA);
  2162. strlcat(all_strbuff, buff, size);
  2163. snprintf(buff, sizeof(buff), "%08X", res);
  2164. strlcat(all_strbuff, buff, size);
  2165. snprintf(buff, sizeof(buff), "%02X", 0xBB);
  2166. strlcat(all_strbuff, buff, size);
  2167. count = snprintf(buf, TSP_BUF_SIZE, "%s\n", all_strbuff);
  2168. kfree(all_strbuff);
  2169. } else {
  2170. logError(1,
  2171. "%s %s:Unable to allocate all_strbuff! ERROR %08X\n",
  2172. tag, __func__, ERROR_ALLOC);
  2173. }
  2174. mask[0] = 0;
  2175. return count;
  2176. }
  2177. static ssize_t fts_gesture_mask_store(struct device *dev,
  2178. struct device_attribute *attr, const char *buf, size_t count)
  2179. {
  2180. char *p = (char *)buf;
  2181. int n;
  2182. unsigned int temp;
  2183. if ((count + 1) / 3 > GESTURE_MASK_SIZE + 1) {
  2184. logError(1, "%s %s: Number of bytes of parameter wrong! ", tag,
  2185. __func__);
  2186. logError(1, "%d > (enable/disable + %d )\n", (count + 1) / 3,
  2187. GESTURE_MASK_SIZE);
  2188. mask[0] = 0;
  2189. return -EINVAL;
  2190. }
  2191. mask[0] = ((count + 1) / 3) - 1;
  2192. for (n = 1; n <= (count + 1) / 3; n++) {
  2193. if (sscanf(p, "%02X ", &temp) != 1)
  2194. return -EINVAL;
  2195. p += 3;
  2196. mask[n] = (u8)temp;
  2197. logError(1, "%s mask[%d] = %02X\n", tag, n, mask[n]);
  2198. }
  2199. return count;
  2200. }
  2201. #else
  2202. /**
  2203. * if this define is not used,
  2204. * to select the gestures to enable/disable
  2205. * are used the IDs of the gestures
  2206. *
  2207. * echo EE X1 X2 ... > gesture_mask set
  2208. * the gesture to disable/enable; EE = 00(disable)
  2209. * or 01(enable); X1 ... = gesture IDs
  2210. * (example 01 02 05... represent the gestures with
  2211. * ID = 1, 2 and 5) there is no limit of the parameters
  2212. * that can be passed, but of course the gesture IDs
  2213. * should be valid (all the valid IDs are listed
  2214. * in ftsGesture.h)
  2215. *
  2216. * cat gesture_mask enable/disable the
  2217. * given gestures, if one or more gestures is enabled
  2218. * the driver will automatically enable the gesture mode.
  2219. * If all the gestures are disabled the driver automatically
  2220. * will disable the gesture mode. At the end an error code
  2221. * will be printed (example output in the terminal =
  2222. * "AA00000000BB" if there are no errors)
  2223. *
  2224. * echo EE X1 X2 ... > gesture_mask; cat gesture_mask
  2225. * perform in one command both actions stated before
  2226. */
  2227. static ssize_t fts_gesture_mask_show(struct device *dev,
  2228. struct device_attribute *attr, char *buf)
  2229. {
  2230. char buff[CMD_STR_LEN] = {0};
  2231. int size = 6 * 2;
  2232. u8 *all_strbuff = NULL;
  2233. int count = 0;
  2234. struct i2c_client *client = to_i2c_client(dev);
  2235. struct fts_ts_info *info = i2c_get_clientdata(client);
  2236. logError(0, "%s %s: gesture_enabled = %d\n", tag, __func__,
  2237. info->gesture_enabled);
  2238. all_strbuff = kmalloc(size, GFP_KERNEL);
  2239. if (all_strbuff != NULL) {
  2240. memset(all_strbuff, 0, size);
  2241. snprintf(buff, sizeof(buff), "%02X", 0xAA);
  2242. strlcat(all_strbuff, buff, size);
  2243. snprintf(buff, sizeof(buff), "%08X", info->gesture_enabled);
  2244. strlcat(all_strbuff, buff, size);
  2245. snprintf(buff, sizeof(buff), "%02X", 0xBB);
  2246. strlcat(all_strbuff, buff, size);
  2247. count = snprintf(buf, TSP_BUF_SIZE, "%s\n", all_strbuff);
  2248. kfree(all_strbuff);
  2249. } else {
  2250. logError(1,
  2251. "%s %s: Unable to allocate all_strbuff! ERROR %08X\n",
  2252. tag, __func__, ERROR_ALLOC);
  2253. }
  2254. return count;
  2255. }
  2256. static ssize_t fts_gesture_mask_store(struct device *dev,
  2257. struct device_attribute *attr, const char *buf, size_t count)
  2258. {
  2259. char *p = (char *)buf;
  2260. int n;
  2261. unsigned int temp;
  2262. int res;
  2263. struct i2c_client *client = to_i2c_client(dev);
  2264. struct fts_ts_info *info = i2c_get_clientdata(client);
  2265. if ((count + 1) / 3 < 2 || (count + 1) / 3 > GESTURE_MASK_SIZE + 1) {
  2266. logError(1,
  2267. "%s %s:Number bytes of parameter wrong! %d %d bytes)\n",
  2268. tag, __func__, (count + 1) / 3, GESTURE_MASK_SIZE);
  2269. mask[0] = 0;
  2270. return -EINVAL;
  2271. }
  2272. memset(mask, 0, GESTURE_MASK_SIZE + 2);
  2273. mask[0] = ((count + 1) / 3) - 1;
  2274. if (sscanf(p, "%02X ", &temp) != 1)
  2275. return -EINVAL;
  2276. p += 3;
  2277. mask[1] = (u8)temp;
  2278. for (n = 1; n < (count + 1) / 3; n++) {
  2279. /*sscanf(p, "%02X ", &temp);*/
  2280. if (sscanf(p, "%02X ", &temp) != 1)
  2281. return -EINVAL;
  2282. p += 3;
  2283. gestureIDtoGestureMask((u8)temp, &mask[2]);
  2284. }
  2285. for (n = 0; n < GESTURE_MASK_SIZE + 2; n++)
  2286. logError(1, "%s mask[%d] = %02X\n", tag, n, mask[n]);
  2287. if (mask[0] == 0) {
  2288. res = ERROR_OP_NOT_ALLOW;
  2289. logError(1, "%s %s: Call before echo enable/disable xx xx ....",
  2290. tag, __func__);
  2291. logError(1, " > gesture_mask with parameters! ERROR %08X\n",
  2292. res);
  2293. } else {
  2294. if (mask[1] == FEAT_ENABLE || mask[1] == FEAT_DISABLE)
  2295. res = updateGestureMask(&mask[2], mask[0], mask[1]);
  2296. else
  2297. res = ERROR_OP_NOT_ALLOW;
  2298. if (res < OK)
  2299. logError(1, "%s %s: ERROR %08X\n", tag, __func__, res);
  2300. }
  2301. res = check_feature_feasibility(info, FEAT_GESTURE);
  2302. temp = isAnyGestureActive();
  2303. if (res >= OK || temp == FEAT_DISABLE)
  2304. info->gesture_enabled = temp;
  2305. res = fts_mode_handler(info, 0);
  2306. return count;
  2307. }
  2308. #endif
  2309. #ifdef USE_CUSTOM_GESTURES
  2310. /**
  2311. * allow to use user defined gestures
  2312. *
  2313. * echo ID X1 Y1 X2 Y2 ... X30 Y30 >
  2314. * add_custom_gesture add a custom gesture;
  2315. * ID = 1 byte that represent the gesture ID of
  2316. * the custom gesture (can be chosen only between
  2317. * the custom IDs defined in ftsGesture.h);
  2318. * X1 Y1 ... = a series of 30 points (x,y) which
  2319. * represent the gesture template.
  2320. * The loaded gesture is enabled automatically
  2321. *
  2322. * cat add_custom_gesture/remove_custom_gesture
  2323. * Print the error code of the last operation
  2324. * performed with the custom gestures
  2325. * (example output in the terminal = "AA00000000BB"
  2326. * if there are no errors)
  2327. *
  2328. * echo ID X1 Y1 X2 Y2 ... X30 Y30 >
  2329. * add_custom_gesture; cat add_custom_gesture
  2330. * perform in one command both actions stated before
  2331. */
  2332. static ssize_t fts_add_custom_gesture_show(struct device *dev,
  2333. struct device_attribute *attr, char *buf)
  2334. {
  2335. char buff[CMD_STR_LEN] = {0};
  2336. int size = 6 * 2;
  2337. u8 *all_strbuff = NULL;
  2338. int count = 0;
  2339. logError(0, "%s %s:Last Operation Result = %08X\n",
  2340. tag, __func__, custom_gesture_res);
  2341. all_strbuff = kmalloc(size, GFP_KERNEL);
  2342. if (all_strbuff != NULL) {
  2343. memset(all_strbuff, 0, size);
  2344. snprintf(buff, sizeof(buff), "%02X", 0xAA);
  2345. strlcat(all_strbuff, buff, size);
  2346. snprintf(buff, sizeof(buff), "%08X", custom_gesture_res);
  2347. strlcat(all_strbuff, buff, size);
  2348. snprintf(buff, sizeof(buff), "%02X", 0xBB);
  2349. strlcat(all_strbuff, buff, size);
  2350. count = snprintf(buf, TSP_BUF_SIZE, "%s\n", all_strbuff);
  2351. kfree(all_strbuff);
  2352. } else {
  2353. logError(1,
  2354. "%s %s:Unable to allocate all_strbuff! ERROR %08X\n",
  2355. tag, __func__, ERROR_ALLOC);
  2356. }
  2357. return count;
  2358. }
  2359. static ssize_t fts_add_custom_gesture_store(struct device *dev,
  2360. struct device_attribute *attr, const char *buf, size_t count)
  2361. {
  2362. char *p = (char *)buf;
  2363. int n;
  2364. unsigned int temp;
  2365. u8 gestureID;
  2366. u8 gestMask[GESTURE_MASK_SIZE] = {0};
  2367. u8 template[GESTURE_CUSTOM_POINTS];
  2368. int res;
  2369. /*struct i2c_client *client = to_i2c_client(dev);*/
  2370. /*struct fts_ts_info *info = i2c_get_clientdata(client);*/
  2371. if ((count + 1) / 3 != GESTURE_CUSTOM_POINTS + 1) {
  2372. logError(1,
  2373. "%s %s: Number bytes of parameter wrong! %d != %d\n",
  2374. tag, __func__, (count + 1) / 3,
  2375. GESTURE_CUSTOM_POINTS + 1);
  2376. res = ERROR_OP_NOT_ALLOW;
  2377. return -EINVAL;
  2378. }
  2379. if (sscanf(p, "%02X ", &temp) != 1)
  2380. return -EINVAL;
  2381. p += 3;
  2382. gestureID = (u8)temp;
  2383. for (n = 1; n < (count + 1) / 3; n++) {
  2384. /*sscanf(p, "%02X ", &temp);*/
  2385. if (sscanf(p, "%02X ", &temp) != 1)
  2386. return -EINVAL;
  2387. p += 3;
  2388. template[n-1] = (u8)temp;
  2389. logError(1, "%s template[%d] = %02X\n",
  2390. tag, n-1, template[n-1]);
  2391. }
  2392. res = fts_disableInterrupt();
  2393. if (res >= OK) {
  2394. logError(1, "%s %s: Adding custom gesture ID = %02X\n",
  2395. tag, __func__, gestureID);
  2396. res = addCustomGesture(template,
  2397. GESTURE_CUSTOM_POINTS, gestureID);
  2398. if (res < OK) {
  2399. logError(1,
  2400. "%s %s:error during add custom gesture ",
  2401. tag, __func__);
  2402. logError(1, "ERROR %08X\n", res);
  2403. } else {
  2404. logError(1,
  2405. "%s %s:Enabling in the gesture mask...\n",
  2406. tag, __func__);
  2407. gestureIDtoGestureMask(gestureID, gestMask);
  2408. res = enableGesture(gestMask, GESTURE_MASK_SIZE);
  2409. if (res < OK) {
  2410. logError(1, "%s %s:error during enable gesture",
  2411. tag, __func__);
  2412. logError(1, " mask: ERROR %08X\n", res);
  2413. } else {
  2414. /*if (check_feature_feasibility(info,*/
  2415. /*FEAT_GESTURE)==OK)*/
  2416. /*info->gesture_enabled =*/
  2417. /*isAnyGestureActive();*/
  2418. /*uncomment if you want to activate*/
  2419. /* automatically*/
  2420. /*the gesture mode when a custom gesture*/
  2421. /*is loaded*/
  2422. logError(1, "%s %s:Custom Gesture enabled!\n",
  2423. tag, __func__, res);
  2424. }
  2425. }
  2426. }
  2427. res |= fts_enableInterrupt();
  2428. custom_gesture_res = res;
  2429. return count;
  2430. }
  2431. /**
  2432. * echo ID > remove_custom_gesture
  2433. * remove a custom gesture;
  2434. * ID = 1 byte that represent the gesture ID
  2435. * of the custom gesture (can be chosen only
  2436. * between the custom IDs defined in ftsGesture.h);
  2437. * the same gesture is disabled automatically
  2438. */
  2439. static ssize_t fts_remove_custom_gesture_show(struct device *dev,
  2440. struct device_attribute *attr, char *buf)
  2441. {
  2442. char buff[CMD_STR_LEN] = {0};
  2443. int size = 6 * 2;
  2444. u8 *all_strbuff = NULL;
  2445. int count = 0;
  2446. logError(0, "%s %s:Last Operation Result = %08X\n",
  2447. tag, __func__, custom_gesture_res);
  2448. all_strbuff = kmalloc(size, GFP_KERNEL);
  2449. if (all_strbuff != NULL) {
  2450. memset(all_strbuff, 0, size);
  2451. snprintf(buff, sizeof(buff), "%02X", 0xAA);
  2452. strlcat(all_strbuff, buff, size);
  2453. snprintf(buff, sizeof(buff), "%08X", custom_gesture_res);
  2454. strlcat(all_strbuff, buff, size);
  2455. snprintf(buff, sizeof(buff), "%02X", 0xBB);
  2456. strlcat(all_strbuff, buff, size);
  2457. count = snprintf(buf, TSP_BUF_SIZE, "%s\n", all_strbuff);
  2458. kfree(all_strbuff);
  2459. } else {
  2460. logError(1,
  2461. "%s %s:Unable to allocate all_strbuff! ERROR %08X\n",
  2462. tag, __func__, ERROR_ALLOC);
  2463. }
  2464. return count;
  2465. }
  2466. static ssize_t fts_remove_custom_gesture_store(struct device *dev,
  2467. struct device_attribute *attr, const char *buf, size_t count)
  2468. {
  2469. char *p = (char *)buf;
  2470. unsigned int temp;
  2471. int res;
  2472. u8 gestureID;
  2473. u8 gestMask[GESTURE_MASK_SIZE] = {0};
  2474. /*struct i2c_client *client = to_i2c_client(dev);*/
  2475. /*struct fts_ts_info *info = i2c_get_clientdata(client);*/
  2476. if ((count + 1) / 3 < 1) {
  2477. logError(1,
  2478. "%s %s:Number bytes of parameter wrong! %d != %d\n",
  2479. tag, __func__, (count + 1) / 3, 1);
  2480. res = ERROR_OP_NOT_ALLOW;
  2481. return -EINVAL;
  2482. }
  2483. if (sscanf(p, "%02X ", &temp) != 1)
  2484. return -EINVAL;
  2485. p += 3;
  2486. gestureID = (u8)temp;
  2487. res = fts_disableInterrupt();
  2488. if (res >= OK) {
  2489. logError(1,
  2490. "%s %s: Removing custom gesture ID = %02X\n",
  2491. tag, __func__, gestureID);
  2492. res = removeCustomGesture(gestureID);
  2493. if (res < OK) {
  2494. logError(1,
  2495. "%s %s:error in custom gesture:%08X\n",
  2496. tag, __func__, res);
  2497. } else {
  2498. logError(1, "%s %s: Enabling in the gesture mask...\n",
  2499. tag, __func__);
  2500. gestureIDtoGestureMask(gestureID, gestMask);
  2501. res = disableGesture(gestMask, GESTURE_MASK_SIZE);
  2502. if (res < OK) {
  2503. logError(1,
  2504. "%s %s:error in enable gesture mask:%08X\n",
  2505. tag, __func__, res);
  2506. } else {
  2507. /*if (check_feature_feasibility*/
  2508. /*(info,FEAT_GESTURE)==OK)*/
  2509. /*info->gesture_enabled = */
  2510. /*isAnyGestureActive();*/
  2511. /**
  2512. * uncomment if you want to disable
  2513. * automatically
  2514. * the gesture mode when a custom gesture is
  2515. * removed and no other gestures were enabled
  2516. */
  2517. logError(1, "%s %s: Custom Gesture disabled!\n",
  2518. tag, __func__, res);
  2519. }
  2520. }
  2521. }
  2522. res |= fts_enableInterrupt();
  2523. custom_gesture_res = res;
  2524. return count;
  2525. }
  2526. #endif
  2527. /**
  2528. * cat gesture_coordinates to obtain the gesture coordinates
  2529. * the string returned in the shell follow this up as follow:
  2530. * AA = start byte
  2531. * X1X2X3X4 = 4 bytes in HEX format
  2532. * which represent an error code (00000000 no error)
  2533. */
  2534. /**** if error code is all 0s ****/
  2535. /**
  2536. * CC = 1 byte in HEX format number of coords
  2537. * (pair of x,y) returned
  2538. *
  2539. * X1X2 Y1Y2 ... = X1X2 2 bytes in HEX format for
  2540. * x[i] and Y1Y2 2 bytes in HEX format for y[i] (MSB first)
  2541. */
  2542. /********************************/
  2543. /* BB = end byte*/
  2544. static ssize_t fts_gesture_coordinates_show(struct device *dev,
  2545. struct device_attribute *attr, char *buf)
  2546. {
  2547. char buff[CMD_STR_LEN] = {0};
  2548. int size = 6 * 2;
  2549. //u8 coords_num;
  2550. u8 *all_strbuff = NULL;
  2551. int count = 0, res, i = 0;
  2552. logError(0, "%s %s: Getting gestures coordinates...\n", tag, __func__);
  2553. if (gesture_coords_reported < OK) {
  2554. logError(1, "%s %s:invalid coordinates! ERROR %08X\n",
  2555. tag, __func__, gesture_coords_reported);
  2556. res = gesture_coords_reported;
  2557. } else {
  2558. /*coords are pairs of x,y (*2) where each coord*/
  2559. /*is a short(2bytes=4char)(*4) + 1 byte(2char) num*/
  2560. /*of coords (+2)*/
  2561. size += gesture_coords_reported * 2 * 4 + 2;
  2562. /*coords_num = res;*/
  2563. res = OK;
  2564. /*set error code to OK*/
  2565. }
  2566. all_strbuff = kmalloc(size, GFP_KERNEL);
  2567. if (all_strbuff != NULL) {
  2568. memset(all_strbuff, 0, size);
  2569. snprintf(buff, sizeof(buff), "%02X", 0xAA);
  2570. strlcat(all_strbuff, buff, size);
  2571. snprintf(buff, sizeof(buff), "%08X", res);
  2572. strlcat(all_strbuff, buff, size);
  2573. if (res >= OK) {
  2574. snprintf(buff, sizeof(buff), "%02X",
  2575. gesture_coords_reported);
  2576. strlcat(all_strbuff, buff, size);
  2577. for (i = 0; i < gesture_coords_reported; i++) {
  2578. snprintf(buff, sizeof(buff), "%04X",
  2579. gesture_coordinates_x[i]);
  2580. strlcat(all_strbuff, buff, size);
  2581. snprintf(buff, sizeof(buff), "%04X",
  2582. gesture_coordinates_y[i]);
  2583. strlcat(all_strbuff, buff, size);
  2584. }
  2585. }
  2586. snprintf(buff, sizeof(buff), "%02X", 0xBB);
  2587. strlcat(all_strbuff, buff, size);
  2588. count = snprintf(buf, TSP_BUF_SIZE, "%s\n", all_strbuff);
  2589. kfree(all_strbuff);
  2590. } else {
  2591. logError(1,
  2592. "%s %s:Unable to allocate all_strbuff! ERROR %08X\n",
  2593. tag, ERROR_ALLOC);
  2594. }
  2595. return count;
  2596. }
  2597. static ssize_t fts_gesture_coordinates_store(struct device *dev,
  2598. struct device_attribute *attr, const char *buf, size_t count)
  2599. {
  2600. return 0;
  2601. }
  2602. #endif
  2603. /***************** PRODUCTION TEST ****************/
  2604. static ssize_t fts_stm_cmd_store(struct device *dev,
  2605. struct device_attribute *attr, const char *buf, size_t count)
  2606. {
  2607. int n;
  2608. char *p = (char *) buf;
  2609. memset(typeOfComand, 0, CMD_STR_LEN * sizeof(u32));
  2610. logError(1, "%s\n", tag);
  2611. for (n = 0; n < (count + 1) / 3; n++) {
  2612. if (sscanf(p, "%02X ", &typeOfComand[n]) != 1)
  2613. return -EINVAL;
  2614. p += 3;
  2615. logError(1, "%s typeOfComand[%d] = %02X\n",
  2616. tag, n, typeOfComand[n]);
  2617. }
  2618. numberParameters = n;
  2619. logError(1, "%s Number of Parameters = %d\n", tag, numberParameters);
  2620. return count;
  2621. }
  2622. static ssize_t fts_stm_cmd_show(struct device *dev,
  2623. struct device_attribute *attr, char *buf)
  2624. {
  2625. char buff[CMD_STR_LEN] = {0};
  2626. int res, j, doClean = 0, count;
  2627. int size = 6 * 2;
  2628. u8 *all_strbuff = NULL;
  2629. struct i2c_client *client = to_i2c_client(dev);
  2630. struct fts_ts_info *info = i2c_get_clientdata(client);
  2631. struct MutualSenseData compData = {0};
  2632. struct SelfSenseData comData = {0};
  2633. struct MutualSenseFrame frameMS = {0};
  2634. struct SelfSenseFrame frameSS = {0};
  2635. /**
  2636. * struct used for defining which test
  2637. * perform during the production test
  2638. */
  2639. struct TestToDo todoDefault;
  2640. todoDefault.MutualRaw = 1;
  2641. todoDefault.MutualRawGap = 1;
  2642. todoDefault.MutualCx1 = 0;
  2643. todoDefault.MutualCx2 = 1;
  2644. todoDefault.MutualCx2Adj = 1;
  2645. todoDefault.MutualCxTotal = 0;
  2646. todoDefault.MutualCxTotalAdj = 0;
  2647. todoDefault.MutualKeyRaw = 0;
  2648. todoDefault.MutualKeyCx1 = 0;
  2649. todoDefault.MutualKeyCx2 = 0;
  2650. todoDefault.MutualKeyCxTotal = 0;
  2651. todoDefault.SelfForceRaw = 1;
  2652. todoDefault.SelfForceRawGap = 0;
  2653. todoDefault.SelfForceIx1 = 0;
  2654. todoDefault.SelfForceIx2 = 0;
  2655. todoDefault.SelfForceIx2Adj = 0;
  2656. todoDefault.SelfForceIxTotal = 1;
  2657. todoDefault.SelfForceIxTotalAdj = 0;
  2658. todoDefault.SelfForceCx1 = 0;
  2659. todoDefault.SelfForceCx2 = 0;
  2660. todoDefault.SelfForceCx2Adj = 0;
  2661. todoDefault.SelfForceCxTotal = 0;
  2662. todoDefault.SelfForceCxTotalAdj = 0;
  2663. todoDefault.SelfSenseRaw = 1;
  2664. todoDefault.SelfSenseRawGap = 0;
  2665. todoDefault.SelfSenseIx1 = 0;
  2666. todoDefault.SelfSenseIx2 = 0;
  2667. todoDefault.SelfSenseIx2Adj = 0;
  2668. todoDefault.SelfSenseIxTotal = 1;
  2669. todoDefault.SelfSenseIxTotalAdj = 0;
  2670. todoDefault.SelfSenseCx1 = 0;
  2671. todoDefault.SelfSenseCx2 = 0;
  2672. todoDefault.SelfSenseCx2Adj = 0;
  2673. todoDefault.SelfSenseCxTotal = 0;
  2674. todoDefault.SelfSenseCxTotalAdj = 0;
  2675. if (numberParameters >= 1) {
  2676. res = fts_disableInterrupt();
  2677. if (res < 0) {
  2678. logError(0, "%s fts_disableInterrupt: ERROR %08X\n",
  2679. tag, res);
  2680. res = (res | ERROR_DISABLE_INTER);
  2681. goto END;
  2682. }
  2683. #if defined(CONFIG_FB_MSM)
  2684. res = fb_unregister_client(&info->notifier);
  2685. #else
  2686. if (active_panel)
  2687. res = drm_panel_notifier_unregister(active_panel,
  2688. &info->notifier);
  2689. #endif
  2690. if (res < 0) {
  2691. logError(1, "%s ERROR: unregister notifier failed!\n",
  2692. tag);
  2693. goto END;
  2694. }
  2695. switch (typeOfComand[0]) {
  2696. /*ITO TEST*/
  2697. case 0x01:
  2698. res = production_test_ito();
  2699. break;
  2700. /*PRODUCTION TEST*/
  2701. case 0x00:
  2702. if (ftsInfo.u32_mpPassFlag != INIT_MP) {
  2703. logError(0, "%s MP Flag not set!\n", tag, res);
  2704. res = production_test_main(LIMITS_FILE, 1, 1,
  2705. &todoDefault, INIT_MP);
  2706. } else {
  2707. logError(0, "%s MP Flag set!\n", tag, res);
  2708. res = production_test_main(LIMITS_FILE, 1, 0,
  2709. &todoDefault, INIT_MP);
  2710. }
  2711. break;
  2712. /*read mutual raw*/
  2713. case 0x13:
  2714. logError(0, "%s Get 1 MS Frame\n", tag);
  2715. //res = getMSFrame(ADDR_RAW_TOUCH, &frame, 0);
  2716. res = getMSFrame2(MS_TOUCH_ACTIVE, &frameMS);
  2717. if (res < 0) {
  2718. logError(0,
  2719. "%s Error in taking MS frame.%02X\n",
  2720. tag, res);
  2721. } else {
  2722. logError(0, "%s The frame size is %d words\n",
  2723. tag, res);
  2724. size = (res * sizeof(short) + 8) * 2;
  2725. /* set res to OK because if getMSFrame is*/
  2726. /* successful res = number of words read*/
  2727. res = OK;
  2728. print_frame_short("MS frame =",
  2729. array1dTo2d_short(frameMS.node_data,
  2730. frameMS.node_data_size,
  2731. frameMS.header.sense_node),
  2732. frameMS.header.force_node,
  2733. frameMS.header.sense_node);
  2734. }
  2735. break;
  2736. /*read self raw*/
  2737. case 0x15:
  2738. logError(0, "%s Get 1 SS Frame\n", tag);
  2739. res = getSSFrame2(SS_TOUCH, &frameSS);
  2740. if (res < OK) {
  2741. logError(0,
  2742. "%s Error while taking the SS frame%02X\n",
  2743. tag, res);
  2744. } else {
  2745. logError(0, "%s The frame size is %d words\n",
  2746. tag, res);
  2747. size = (res * sizeof(short) + 8) * 2 + 1;
  2748. /**
  2749. * set res to OK because if getMSFrame is
  2750. * successful res = number of words read
  2751. */
  2752. res = OK;
  2753. print_frame_short("SS force frame =",
  2754. array1dTo2d_short(frameSS.force_data,
  2755. frameSS.header.force_node, 1),
  2756. frameSS.header.force_node, 1);
  2757. print_frame_short("SS sense frame =",
  2758. array1dTo2d_short(frameSS.sense_data,
  2759. frameSS.header.sense_node,
  2760. frameSS.header.sense_node),
  2761. 1,
  2762. frameSS.header.sense_node);
  2763. }
  2764. break;
  2765. /*read mutual comp data*/
  2766. case 0x14:
  2767. logError(0, "%s Get MS Compensation Data\n", tag);
  2768. res = readMutualSenseCompensationData(MS_TOUCH_ACTIVE,
  2769. &compData);
  2770. if (res < 0) {
  2771. logError(0,
  2772. "%s Error MS compensation data%02X\n",
  2773. tag, res);
  2774. } else {
  2775. logError(0,
  2776. "%s MS Data Reading Finished!\n",
  2777. tag);
  2778. size = ((compData.node_data_size + 9) *
  2779. sizeof(u8)) * 2;
  2780. print_frame_u8("MS Data (Cx2) =",
  2781. array1dTo2d_u8(compData.node_data,
  2782. compData.node_data_size,
  2783. compData.header.sense_node),
  2784. compData.header.force_node,
  2785. compData.header.sense_node);
  2786. }
  2787. break;
  2788. /*read self comp data*/
  2789. case 0x16:
  2790. logError(0, "%s Get SS Compensation Data...\n", tag);
  2791. res = readSelfSenseCompensationData(SS_TOUCH, &comData);
  2792. if (res < 0) {
  2793. logError(0, "%s Error reading SS data%02X\n",
  2794. tag, res);
  2795. } else {
  2796. logError(0, "%s SS Data Reading Finished!\n",
  2797. tag);
  2798. size = ((comData.header.force_node
  2799. + comData.header.sense_node) * 2 + 12);
  2800. size *= sizeof(u8) * 2;
  2801. print_frame_u8("SS Data Ix2_fm = ",
  2802. array1dTo2d_u8(comData.ix2_fm,
  2803. comData.header.force_node, 1),
  2804. comData.header.force_node,
  2805. 1);
  2806. print_frame_u8("SS Data Cx2_fm = ",
  2807. array1dTo2d_u8(comData.cx2_fm,
  2808. comData.header.force_node, 1),
  2809. comData.header.force_node,
  2810. 1);
  2811. print_frame_u8("SS Data Ix2_sn = ",
  2812. array1dTo2d_u8(comData.ix2_sn,
  2813. comData.header.sense_node,
  2814. comData.header.sense_node),
  2815. 1,
  2816. comData.header.sense_node);
  2817. print_frame_u8("SS Data Cx2_sn = ",
  2818. array1dTo2d_u8(comData.cx2_sn,
  2819. comData.header.sense_node,
  2820. comData.header.sense_node),
  2821. 1,
  2822. comData.header.sense_node);
  2823. }
  2824. break;
  2825. /* MS Raw DATA TEST */
  2826. case 0x03:
  2827. res = fts_system_reset();
  2828. if (res >= OK)
  2829. res = production_test_ms_raw(LIMITS_FILE,
  2830. 1, &todoDefault);
  2831. break;
  2832. /* MS CX DATA TEST */
  2833. case 0x04:
  2834. res = fts_system_reset();
  2835. if (res >= OK)
  2836. res = production_test_ms_cx(LIMITS_FILE,
  2837. 1, &todoDefault);
  2838. break;
  2839. /* SS RAW DATA TEST */
  2840. case 0x05:
  2841. res = fts_system_reset();
  2842. if (res >= OK)
  2843. res = production_test_ss_raw(LIMITS_FILE,
  2844. 1, &todoDefault);
  2845. break;
  2846. /* SS IX CX DATA TEST */
  2847. case 0x06:
  2848. res = fts_system_reset();
  2849. if (res >= OK)
  2850. res = production_test_ss_ix_cx(LIMITS_FILE,
  2851. 1, &todoDefault);
  2852. break;
  2853. case 0xF0:
  2854. /* TOUCH ENABLE/DISABLE */
  2855. case 0xF1:
  2856. doClean = (int) (typeOfComand[0] & 0x01);
  2857. res = cleanUp(doClean);
  2858. break;
  2859. default:
  2860. logError(1,
  2861. "%s COMMAND NOT VALID!! Insert a proper value\n",
  2862. tag);
  2863. res = ERROR_OP_NOT_ALLOW;
  2864. break;
  2865. }
  2866. doClean = fts_enableInterrupt();
  2867. if (doClean < 0) {
  2868. logError(0, "%s fts_enableInterrupt: ERROR %08X\n",
  2869. tag, (doClean|ERROR_ENABLE_INTER));
  2870. }
  2871. } else {
  2872. logError(1, "%s NO COMMAND SPECIFIED!!!\n", tag);
  2873. res = ERROR_OP_NOT_ALLOW;
  2874. }
  2875. #if defined(CONFIG_FB_MSM)
  2876. if (fb_register_client(&info->notifier) < 0)
  2877. logError(1, "%s ERROR: register notifier failed!\n", tag);
  2878. #else
  2879. if (active_panel &&
  2880. drm_panel_notifier_register(active_panel, &info->notifier) < 0)
  2881. logError(1, "%s ERROR: register notifier failed!\n", tag);
  2882. #endif
  2883. END:
  2884. /*here start the reporting phase,*/
  2885. /* assembling the data to send in the file node */
  2886. all_strbuff = kmalloc(size, GFP_KERNEL);
  2887. if (!all_strbuff)
  2888. return 0;
  2889. memset(all_strbuff, 0, size);
  2890. snprintf(buff, sizeof(buff), "%02X", 0xAA);
  2891. strlcat(all_strbuff, buff, size);
  2892. snprintf(buff, sizeof(buff), "%08X", res);
  2893. strlcat(all_strbuff, buff, size);
  2894. if (res >= OK) {
  2895. /*all the other cases are already fine printing only the res.*/
  2896. switch (typeOfComand[0]) {
  2897. case 0x13:
  2898. snprintf(buff, sizeof(buff), "%02X",
  2899. (u8) frameMS.header.force_node);
  2900. strlcat(all_strbuff, buff, size);
  2901. snprintf(buff, sizeof(buff), "%02X",
  2902. (u8) frameMS.header.sense_node);
  2903. strlcat(all_strbuff, buff, size);
  2904. for (j = 0; j < frameMS.node_data_size; j++) {
  2905. snprintf(buff, sizeof(buff), "%04X",
  2906. frameMS.node_data[j]);
  2907. strlcat(all_strbuff, buff, size);
  2908. }
  2909. kfree(frameMS.node_data);
  2910. break;
  2911. case 0x15:
  2912. snprintf(buff, sizeof(buff), "%02X",
  2913. (u8) frameSS.header.force_node);
  2914. strlcat(all_strbuff, buff, size);
  2915. snprintf(buff, sizeof(buff), "%02X",
  2916. (u8) frameSS.header.sense_node);
  2917. strlcat(all_strbuff, buff, size);
  2918. /* Copying self raw data Force */
  2919. for (j = 0; j < frameSS.header.force_node; j++) {
  2920. snprintf(buff, sizeof(buff), "%04X",
  2921. frameSS.force_data[j]);
  2922. strlcat(all_strbuff, buff, size);
  2923. }
  2924. /* Copying self raw data Sense */
  2925. for (j = 0; j < frameSS.header.sense_node; j++) {
  2926. snprintf(buff, sizeof(buff), "%04X",
  2927. frameSS.sense_data[j]);
  2928. strlcat(all_strbuff, buff, size);
  2929. }
  2930. kfree(frameSS.force_data);
  2931. kfree(frameSS.sense_data);
  2932. break;
  2933. case 0x14:
  2934. snprintf(buff, sizeof(buff), "%02X",
  2935. (u8) compData.header.force_node);
  2936. strlcat(all_strbuff, buff, size);
  2937. snprintf(buff, sizeof(buff), "%02X",
  2938. (u8) compData.header.sense_node);
  2939. strlcat(all_strbuff, buff, size);
  2940. /* Cpying CX1 value */
  2941. snprintf(buff, sizeof(buff), "%02X", compData.cx1);
  2942. strlcat(all_strbuff, buff, size);
  2943. /* Copying CX2 values */
  2944. for (j = 0; j < compData.node_data_size; j++) {
  2945. snprintf(buff, sizeof(buff), "%02X",
  2946. *(compData.node_data + j));
  2947. strlcat(all_strbuff, buff, size);
  2948. }
  2949. kfree(compData.node_data);
  2950. break;
  2951. case 0x16:
  2952. snprintf(buff, sizeof(buff), "%02X",
  2953. comData.header.force_node);
  2954. strlcat(all_strbuff, buff, size);
  2955. snprintf(buff, sizeof(buff), "%02X",
  2956. comData.header.sense_node);
  2957. strlcat(all_strbuff, buff, size);
  2958. snprintf(buff, sizeof(buff), "%02X", comData.f_ix1);
  2959. strlcat(all_strbuff, buff, size);
  2960. snprintf(buff, sizeof(buff), "%02X", comData.s_ix1);
  2961. strlcat(all_strbuff, buff, size);
  2962. snprintf(buff, sizeof(buff), "%02X", comData.f_cx1);
  2963. strlcat(all_strbuff, buff, size);
  2964. snprintf(buff, sizeof(buff), "%02X", comData.s_cx1);
  2965. strlcat(all_strbuff, buff, size);
  2966. /* Copying IX2 Force */
  2967. for (j = 0; j < comData.header.force_node; j++) {
  2968. snprintf(buff, sizeof(buff), "%02X",
  2969. comData.ix2_fm[j]);
  2970. strlcat(all_strbuff, buff, size);
  2971. }
  2972. /* Copying IX2 Sense */
  2973. for (j = 0; j < comData.header.sense_node; j++) {
  2974. snprintf(buff, sizeof(buff), "%02X",
  2975. comData.ix2_sn[j]);
  2976. strlcat(all_strbuff, buff, size);
  2977. }
  2978. /* Copying CX2 Force */
  2979. for (j = 0; j < comData.header.force_node; j++) {
  2980. snprintf(buff, sizeof(buff), "%02X",
  2981. comData.cx2_fm[j]);
  2982. strlcat(all_strbuff, buff, size);
  2983. }
  2984. /* Copying CX2 Sense */
  2985. for (j = 0; j < comData.header.sense_node; j++) {
  2986. snprintf(buff, sizeof(buff), "%02X",
  2987. comData.cx2_sn[j]);
  2988. strlcat(all_strbuff, buff, size);
  2989. }
  2990. kfree(comData.ix2_fm);
  2991. kfree(comData.ix2_sn);
  2992. kfree(comData.cx2_fm);
  2993. kfree(comData.cx2_sn);
  2994. break;
  2995. default:
  2996. break;
  2997. }
  2998. }
  2999. snprintf(buff, sizeof(buff), "%02X", 0xBB);
  3000. strlcat(all_strbuff, buff, size);
  3001. count = snprintf(buf, TSP_BUF_SIZE, "%s\n", all_strbuff);
  3002. /**
  3003. * need to reset the number of parameters
  3004. * in order to wait the next command,
  3005. * comment if you want to repeat
  3006. * the last command sent just doing a cat
  3007. */
  3008. numberParameters = 0;
  3009. /* logError(0,"%s numberParameters = %d\n",tag, numberParameters);*/
  3010. kfree(all_strbuff);
  3011. return count;
  3012. }
  3013. static DEVICE_ATTR_RW(fts_fwupdate);
  3014. static DEVICE_ATTR_RO(fts_appid);
  3015. static DEVICE_ATTR_RO(fts_mode_active);
  3016. static DEVICE_ATTR_RO(fts_lockdown_info);
  3017. static DEVICE_ATTR_RW(fts_strength_frame);
  3018. static DEVICE_ATTR_RO(fts_fw_test);
  3019. static DEVICE_ATTR_RW(fts_stm_cmd);
  3020. #ifdef USE_ONE_FILE_NODE
  3021. static DEVICE_ATTR_RW(fts_feature_enable);
  3022. #else
  3023. #ifdef EDGE_REJ
  3024. static DEVICE_ATTR_RW(fts_edge_rej);
  3025. #endif
  3026. #ifdef CORNER_REJ
  3027. static DEVICE_ATTR_RW(fts_corner_rej);
  3028. #endif
  3029. #ifdef EDGE_PALM_REJ
  3030. static DEVICE_ATTR_RW(fts_edge_palm_rej);
  3031. #endif
  3032. #ifdef CHARGER_MODE
  3033. static DEVICE_ATTR_RW(fts_charger_mode);
  3034. #endif
  3035. #ifdef GLOVE_MODE
  3036. static DEVICE_ATTR_RW(fts_glove_mode);
  3037. #endif
  3038. #ifdef VR_MODE
  3039. static DEVICE_ATTR_RW(fts_vr_mode);
  3040. #endif
  3041. #ifdef COVER_MODE
  3042. static DEVICE_ATTR_RW(fts_cover_mode);
  3043. #endif
  3044. #ifdef STYLUS_MODE
  3045. static DEVICE_ATTR_RW(fts_stylus_mode);
  3046. #endif
  3047. #endif
  3048. #ifdef PHONE_GESTURE
  3049. static DEVICE_ATTR_RW(fts_gesture_mask);
  3050. static DEVICE_ATTR_RW(fts_gesture_coordinates);
  3051. #ifdef USE_CUSTOM_GESTURES
  3052. static DEVICE_ATTR_RW(fts_add_custom_gesture);
  3053. static DEVICE_ATTR_RW(fts_remove_custom_gesture);
  3054. #endif
  3055. #endif
  3056. #ifdef CONFIG_ST_TRUSTED_TOUCH
  3057. static DEVICE_ATTR(trusted_touch_enable,
  3058. 0664,
  3059. fts_trusted_touch_enable_show,
  3060. fts_trusted_touch_enable_store);
  3061. #endif
  3062. /* /sys/devices/soc.0/f9928000.i2c/i2c-6/6-0049 */
  3063. static struct attribute *fts_attr_group[] = {
  3064. &dev_attr_fts_fwupdate.attr,
  3065. &dev_attr_fts_appid.attr,
  3066. &dev_attr_fts_mode_active.attr,
  3067. &dev_attr_fts_lockdown_info.attr,
  3068. &dev_attr_fts_strength_frame.attr,
  3069. &dev_attr_fts_fw_test.attr,
  3070. &dev_attr_fts_stm_cmd.attr,
  3071. #ifdef USE_ONE_FILE_NODE
  3072. &dev_attr_fts_feature_enable.attr,
  3073. #else
  3074. #ifdef EDGE_REJ
  3075. &dev_attr_fts_edge_rej.attr,
  3076. #endif
  3077. #ifdef CORNER_REJ
  3078. &dev_attr_fts_corner_rej.attr,
  3079. #endif
  3080. #ifdef EDGE_PALM_REJ
  3081. &dev_attr_fts_edge_palm_rej.attr,
  3082. #endif
  3083. #ifdef CHARGER_MODE
  3084. &dev_attr_fts_charger_mode.attr,
  3085. #endif
  3086. #ifdef GLOVE_MODE
  3087. &dev_attr_fts_glove_mode.attr,
  3088. #endif
  3089. #ifdef VR_MODE
  3090. &dev_attr_fts_vr_mode.attr,
  3091. #endif
  3092. #ifdef COVER_MODE
  3093. &dev_attr_fts_cover_mode.attr,
  3094. #endif
  3095. #ifdef STYLUS_MODE
  3096. &dev_attr_fts_stylus_mode.attr,
  3097. #endif
  3098. #endif
  3099. #ifdef PHONE_GESTURE
  3100. &dev_attr_fts_gesture_mask.attr,
  3101. &dev_attr_fts_gesture_coordinates.attr,
  3102. #ifdef USE_CUSTOM_GESTURES
  3103. &dev_attr_fts_add_custom_gesture.attr,
  3104. &dev_attr_fts_remove_custom_gesture.attr,
  3105. #endif
  3106. #endif
  3107. #ifdef CONFIG_ST_TRUSTED_TOUCH
  3108. &dev_attr_trusted_touch_enable.attr,
  3109. #endif
  3110. NULL,
  3111. };
  3112. static int fts_command(struct fts_ts_info *info, unsigned char cmd)
  3113. {
  3114. unsigned char regAdd;
  3115. int ret;
  3116. regAdd = cmd;
  3117. ret = fts_writeCmd(&regAdd, sizeof(regAdd)); /* 0 = ok */
  3118. logError(0, "%s Issued command 0x%02x, return value %08X\n", cmd, ret);
  3119. return ret;
  3120. }
  3121. void fts_input_report_key(struct fts_ts_info *info, int key_code)
  3122. {
  3123. mutex_lock(&info->input_report_mutex);
  3124. input_report_key(info->input_dev, key_code, 1);
  3125. input_sync(info->input_dev);
  3126. input_report_key(info->input_dev, key_code, 0);
  3127. input_sync(info->input_dev);
  3128. mutex_unlock(&info->input_report_mutex);
  3129. }
  3130. /*
  3131. * New Interrupt handle implementation
  3132. */
  3133. static inline unsigned char *fts_next_event(unsigned char *evt)
  3134. {
  3135. /* Nothing to do with this event, moving to the next one */
  3136. evt += FIFO_EVENT_SIZE;
  3137. /* the previous one was the last event ? */
  3138. return (evt[-1] & 0x1F) ? evt : NULL;
  3139. }
  3140. /* EventId : 0x00 */
  3141. static void fts_nop_event_handler(struct fts_ts_info *info,
  3142. unsigned char *event)
  3143. {
  3144. /**
  3145. * logError(1,
  3146. * "%s %s Doing nothing for event =
  3147. * %02X %02X %02X %02X %02X %02X %02X %02X\n",
  3148. * tag, __func__, event[0], event[1], event[2],
  3149. * event[3], event[4], event[5], event[6], event[7]);
  3150. */
  3151. /* return fts_next_event(event); */
  3152. }
  3153. /* EventId : 0x03 */
  3154. static void fts_enter_pointer_event_handler(struct fts_ts_info *info,
  3155. unsigned char *event)
  3156. {
  3157. unsigned char touchId, touchcount;
  3158. int x, y;
  3159. int minor;
  3160. int major, distance = 0;
  3161. u8 touchsize;
  3162. if (!info->resume_bit && !info->aoi_notify_enabled)
  3163. return;
  3164. touchId = event[1] & 0x0F;
  3165. touchcount = (event[1] & 0xF0) >> 4;
  3166. touchsize = (event[5] & 0xC0) >> 6;
  3167. major = (event[5] & 0x1F); // bit0-bit4: major
  3168. minor = event[6]; // event6:minor
  3169. __set_bit(touchId, &info->touch_id);
  3170. x = (event[2] << 4) | (event[4] & 0xF0) >> 4;
  3171. y = (event[3] << 4) | (event[4] & 0x0F);
  3172. if (info->bdata->x_flip)
  3173. x = X_AXIS_MAX - x;
  3174. if (info->bdata->y_flip)
  3175. y = Y_AXIS_MAX - y;
  3176. if (x == X_AXIS_MAX)
  3177. x--;
  3178. if (y == Y_AXIS_MAX)
  3179. y--;
  3180. if (info->sensor_sleep && info->aoi_notify_enabled)
  3181. if ((x < info->aoi_left || x > info->aoi_right)
  3182. || (y < info->aoi_top || y > info->aoi_bottom)) {
  3183. x = -x;
  3184. y = -y;
  3185. }
  3186. input_mt_slot(info->input_dev, touchId);
  3187. input_mt_report_slot_state(info->input_dev, MT_TOOL_FINGER, 1);
  3188. if (touchcount == 1) {
  3189. input_report_key(info->input_dev, BTN_TOUCH, 1);
  3190. input_report_key(info->input_dev, BTN_TOOL_FINGER, 1);
  3191. }
  3192. input_report_abs(info->input_dev, ABS_MT_POSITION_X, x);
  3193. input_report_abs(info->input_dev, ABS_MT_POSITION_Y, y);
  3194. input_report_abs(info->input_dev, ABS_MT_TOUCH_MAJOR, major);
  3195. input_report_abs(info->input_dev, ABS_MT_TOUCH_MINOR, minor);
  3196. input_report_abs(info->input_dev, ABS_MT_DISTANCE, distance);
  3197. return;
  3198. }
  3199. /* EventId : 0x04 */
  3200. static void fts_leave_pointer_event_handler(struct fts_ts_info *info,
  3201. unsigned char *event)
  3202. {
  3203. unsigned char touchId, touchcount;
  3204. u8 touchsize;
  3205. touchId = event[1] & 0x0F;
  3206. touchcount = (event[1] & 0xF0) >> 4;
  3207. touchsize = (event[5] & 0xC0) >> 6;
  3208. input_mt_slot(info->input_dev, touchId);
  3209. __clear_bit(touchId, &info->touch_id);
  3210. input_mt_report_slot_state(info->input_dev, MT_TOOL_FINGER, 0);
  3211. if (touchcount == 0) {
  3212. input_report_key(info->input_dev, BTN_TOUCH, 0);
  3213. input_report_key(info->input_dev, BTN_TOOL_FINGER, 0);
  3214. }
  3215. input_report_abs(info->input_dev, ABS_MT_TRACKING_ID, -1);
  3216. }
  3217. /* EventId : 0x05 */
  3218. #define fts_motion_pointer_event_handler fts_enter_pointer_event_handler
  3219. #ifdef PHONE_KEY
  3220. /* EventId : 0x0E */
  3221. static void fts_key_status_event_handler(struct fts_ts_info *info,
  3222. unsigned char *event)
  3223. {
  3224. int value;
  3225. logError(0,
  3226. "%s %sReceived event %02X %02X %02X %02X %02X %02X %02X %02X\n",
  3227. tag, __func__, event[0], event[1], event[2], event[3],
  3228. event[4], event[5], event[6], event[7]);
  3229. /*
  3230. * TODO: the customer should handle the events coming
  3231. * from the keys according his needs (this is an example
  3232. * that report only the single pressure of one key at time)
  3233. */
  3234. /* event[2] contain the bitmask of the keys that are actually pressed */
  3235. if (event[2] != 0) {
  3236. switch (event[2]) {
  3237. case KEY1:
  3238. value = KEY_HOMEPAGE;
  3239. logError(0, "%s %s: Button HOME!\n", tag, __func__);
  3240. break;
  3241. case KEY2:
  3242. value = KEY_BACK;
  3243. logError(0, "%s %s: Button Back !\n", tag, __func__);
  3244. break;
  3245. case KEY3:
  3246. value = KEY_MENU;
  3247. logError(0, "%s %s: Button Menu !\n", tag, __func__);
  3248. break;
  3249. default:
  3250. logError(0,
  3251. "%s %s:No valid Button ID or more than one key pressed!\n",
  3252. tag, __func__);
  3253. return;
  3254. }
  3255. fts_input_report_key(info, value);
  3256. } else {
  3257. logError(0, "%s %s: All buttons released!\n", tag, __func__);
  3258. }
  3259. }
  3260. #endif
  3261. /* EventId : 0x0F */
  3262. static void fts_error_event_handler(struct fts_ts_info *info,
  3263. unsigned char *event)
  3264. {
  3265. int error = 0;
  3266. logError(0,
  3267. "%s %sReceived event:%02X %02X %02X %02X %02X %02X %02X %02X\n",
  3268. tag, __func__, event[0], event[1], event[2], event[3],
  3269. event[4], event[5], event[6], event[7]);
  3270. switch (event[1]) {
  3271. case EVENT_TYPE_ESD_ERROR: /* esd */
  3272. /* before reset clear all slot */
  3273. release_all_touches(info);
  3274. fts_chip_powercycle(info);
  3275. error = fts_system_reset();
  3276. error |= fts_mode_handler(info, 0);
  3277. error |= fts_enableInterrupt();
  3278. if (error < OK) {
  3279. logError(1,
  3280. "%s %s Cannot restore the device ERROR %08X\n",
  3281. tag, __func__, error);
  3282. }
  3283. break;
  3284. case EVENT_TYPE_WATCHDOG_ERROR: /* watch dog timer */
  3285. /* if (event[2] == 0) { */
  3286. dumpErrorInfo();
  3287. /* before reset clear all slot */
  3288. release_all_touches(info);
  3289. error = fts_system_reset();
  3290. error |= fts_mode_handler(info, 0);
  3291. error |= fts_enableInterrupt();
  3292. if (error < OK) {
  3293. logError(1,
  3294. "%s %s Cannot reset the device ERROR %08X\n",
  3295. tag, __func__, error);
  3296. }
  3297. /* } */
  3298. break;
  3299. }
  3300. /* return fts_next_event(event); */
  3301. }
  3302. /* EventId : 0x10 */
  3303. static void fts_controller_ready_event_handler(struct fts_ts_info *info,
  3304. unsigned char *event)
  3305. {
  3306. int error;
  3307. logError(0, "%s %s Received event 0x%02x\n", tag, __func__, event[0]);
  3308. release_all_touches(info);
  3309. setSystemResettedUp(1);
  3310. setSystemResettedDown(1);
  3311. error = fts_mode_handler(info, 0);
  3312. if (error < OK) {
  3313. logError(1,
  3314. "%s %s Cannot restore the device status ERROR %08X\n",
  3315. tag, __func__, error);
  3316. }
  3317. /* return fts_next_event(event); */
  3318. }
  3319. /* EventId : 0x16 */
  3320. static void fts_status_event_handler(struct fts_ts_info *info,
  3321. unsigned char *event)
  3322. {
  3323. /* logError(1, "%s Received event 0x%02x\n", tag, event[0]); */
  3324. switch (event[1]) {
  3325. case EVENT_TYPE_MS_TUNING_CMPL:
  3326. case EVENT_TYPE_SS_TUNING_CMPL:
  3327. case FTS_FORCE_CAL_SELF_MUTUAL:
  3328. case FTS_FLASH_WRITE_CONFIG:
  3329. case FTS_FLASH_WRITE_COMP_MEMORY:
  3330. case FTS_FORCE_CAL_SELF:
  3331. case FTS_WATER_MODE_ON:
  3332. case FTS_WATER_MODE_OFF:
  3333. default:
  3334. logError(0, "%s %s Received unhandled status event = ",
  3335. tag, __func__);
  3336. logError(0, "%02X %02X %02X %02X %02X %02X %02X %02X\n",
  3337. event[0], event[1], event[2], event[3], event[4],
  3338. event[5], event[6], event[7]);
  3339. break;
  3340. }
  3341. /* return fts_next_event(event); */
  3342. }
  3343. #ifdef PHONE_GESTURE
  3344. /**
  3345. * TODO: Customer should implement their own action
  3346. * in respons of a gesture event.
  3347. * This is an example that simply print the gesture received
  3348. */
  3349. static void fts_gesture_event_handler(struct fts_ts_info *info,
  3350. unsigned char *event)
  3351. {
  3352. unsigned char touchId;
  3353. int value;
  3354. int needCoords = 0;
  3355. logError(0,
  3356. "%s gesture event: %02X %02X %02X %02X %02X %02X %02X %02X\n",
  3357. tag, event[0], event[1], event[2], event[3],
  3358. event[4], event[5], event[6], event[7]);
  3359. if (event[1] == 0x03) {
  3360. logError(1, "%s %s: Gesture ID %02X enable_status = %02X\n",
  3361. tag, __func__, event[2], event[3]);
  3362. }
  3363. if (event[1] == EVENT_TYPE_ENB && event[2] == 0x00) {
  3364. switch (event[3]) {
  3365. case GESTURE_ENABLE:
  3366. logError(1, "%s %s: Gesture Enabled! res = %02X\n",
  3367. tag, __func__, event[4]);
  3368. break;
  3369. case GESTURE_DISABLE:
  3370. logError(1, "%s %s: Gesture Disabled! res = %02X\n",
  3371. tag, __func__, event[4]);
  3372. break;
  3373. default:
  3374. logError(1, "%s %s: Event not Valid!\n", tag, __func__);
  3375. }
  3376. }
  3377. if (event[0] == EVENTID_GESTURE && (event[1] == EVENT_TYPE_GESTURE_DTC1
  3378. || event[1] == EVENT_TYPE_GESTURE_DTC2)) {
  3379. /* always use touchId zero */
  3380. touchId = 0;
  3381. __set_bit(touchId, &info->touch_id);
  3382. /* by default read the coordinates*/
  3383. /* for all gestures excluding double tap */
  3384. needCoords = 1;
  3385. switch (event[2]) {
  3386. case GES_ID_DBLTAP:
  3387. value = KEY_WAKEUP;
  3388. logError(0, "%s %s: double tap!\n", tag, __func__);
  3389. needCoords = 0;
  3390. break;
  3391. case GES_ID_AT:
  3392. value = KEY_WWW;
  3393. logError(0, "%s %s: @!\n", tag, __func__);
  3394. break;
  3395. case GES_ID_C:
  3396. value = KEY_C;
  3397. logError(0, "%s %s: C !\n", tag, __func__);
  3398. break;
  3399. case GES_ID_E:
  3400. value = KEY_E;
  3401. logError(0, "%s %s: e !\n", tag, __func__);
  3402. break;
  3403. case GES_ID_F:
  3404. value = KEY_F;
  3405. logError(0, "%s %s: F !\n", tag, __func__);
  3406. break;
  3407. case GES_ID_L:
  3408. value = KEY_L;
  3409. logError(0, "%s %s: L !\n", tag, __func__);
  3410. break;
  3411. case GES_ID_M:
  3412. value = KEY_M;
  3413. logError(0, "%s %s: M !\n", tag, __func__);
  3414. break;
  3415. case GES_ID_O:
  3416. value = KEY_O;
  3417. logError(0, "%s %s: O !\n", tag, __func__);
  3418. break;
  3419. case GES_ID_S:
  3420. value = KEY_S;
  3421. logError(0, "%s %s: S !\n", tag, __func__);
  3422. break;
  3423. case GES_ID_V:
  3424. value = KEY_V;
  3425. logError(0, "%s %s: V !\n", tag, __func__);
  3426. break;
  3427. case GES_ID_W:
  3428. value = KEY_W;
  3429. logError(0, "%s %s: W !\n", tag, __func__);
  3430. break;
  3431. case GES_ID_Z:
  3432. value = KEY_Z;
  3433. logError(0, "%s %s: Z !\n", tag, __func__);
  3434. break;
  3435. case GES_ID_HFLIP_L2R:
  3436. value = KEY_RIGHT;
  3437. logError(0, "%s %s: -> !\n", tag, __func__);
  3438. break;
  3439. case GES_ID_HFLIP_R2L:
  3440. value = KEY_LEFT;
  3441. logError(0, "%s %s: <- !\n", tag, __func__);
  3442. break;
  3443. case GES_ID_VFLIP_D2T:
  3444. value = KEY_UP;
  3445. logError(0, "%s %s: UP !\n", tag, __func__);
  3446. break;
  3447. case GES_ID_VFLIP_T2D:
  3448. value = KEY_DOWN;
  3449. logError(0, "%s %s: DOWN !\n", tag, __func__);
  3450. break;
  3451. case GES_ID_CUST1:
  3452. value = KEY_F1;
  3453. logError(0, "%s %s: F1 !\n", tag, __func__);
  3454. break;
  3455. case GES_ID_CUST2:
  3456. value = KEY_F1;
  3457. logError(0, "%s %s: F2 !\n", tag, __func__);
  3458. break;
  3459. case GES_ID_CUST3:
  3460. value = KEY_F3;
  3461. logError(0, "%s %s: F3 !\n", tag, __func__);
  3462. break;
  3463. case GES_ID_CUST4:
  3464. value = KEY_F1;
  3465. logError(0, "%s %s: F4 !\n", tag, __func__);
  3466. break;
  3467. case GES_ID_CUST5:
  3468. value = KEY_F1;
  3469. logError(0, "%s %s: F5 !\n", tag, __func__);
  3470. break;
  3471. case GES_ID_LEFTBRACE:
  3472. value = KEY_LEFTBRACE;
  3473. logError(0, "%s %s: < !\n", tag, __func__);
  3474. break;
  3475. case GES_ID_RIGHTBRACE:
  3476. value = KEY_RIGHTBRACE;
  3477. logError(0, "%s %s: > !\n", tag, __func__);
  3478. break;
  3479. default:
  3480. logError(0, "%s %s: No valid GestureID!\n",
  3481. tag, __func__);
  3482. goto gesture_done;
  3483. }
  3484. /* no coordinates for gestures reported by FW */
  3485. if (event[1] == EVENT_TYPE_GESTURE_DTC1)
  3486. needCoords = 0;
  3487. if (needCoords == 1)
  3488. readGestureCoords(event);
  3489. fts_input_report_key(info, value);
  3490. gesture_done:
  3491. /* Done with gesture event, clear bit. */
  3492. __clear_bit(touchId, &info->touch_id);
  3493. }
  3494. /* return fts_next_event(event); */
  3495. }
  3496. #endif
  3497. /* EventId : 0x05 */
  3498. #define fts_motion_pointer_event_handler fts_enter_pointer_event_handler
  3499. /*
  3500. * This handler is called each time there is at least
  3501. * one new event in the FIFO
  3502. */
  3503. static void fts_event_handler(struct work_struct *work)
  3504. {
  3505. struct fts_ts_info *info;
  3506. int error = 0, count = 0;
  3507. unsigned char regAdd;
  3508. unsigned char data[FIFO_EVENT_SIZE] = {0};
  3509. unsigned char eventId;
  3510. struct event_dispatch_handler_t event_handler;
  3511. info = container_of(work, struct fts_ts_info, work);
  3512. /*
  3513. * read all the FIFO and parsing events
  3514. */
  3515. __pm_wakeup_event(info->wakeup_source, HZ);
  3516. regAdd = FIFO_CMD_READONE;
  3517. for (count = 0; count < FIFO_DEPTH; count++) {
  3518. error = fts_readCmd(&regAdd, sizeof(regAdd), data,
  3519. FIFO_EVENT_SIZE);
  3520. if (error == OK && data[0] != EVENTID_NO_EVENT)
  3521. eventId = data[0];
  3522. else
  3523. break;
  3524. if (eventId < EVENTID_LAST) {
  3525. event_handler = info->event_dispatch_table[eventId];
  3526. event_handler.handler(info, (data));
  3527. }
  3528. }
  3529. input_sync(info->input_dev);
  3530. fts_interrupt_enable(info);
  3531. }
  3532. static void fts_fw_update_auto(struct work_struct *work)
  3533. {
  3534. u8 cmd[4] = { FTS_CMD_HW_REG_W, 0x00, 0x00, SYSTEM_RESET_VALUE };
  3535. int event_to_search[2] = {(int)EVENTID_ERROR_EVENT,
  3536. (int)EVENT_TYPE_CHECKSUM_ERROR};
  3537. u8 readData[FIFO_EVENT_SIZE] = {0};
  3538. int flag_init = 0;
  3539. int retval = 0;
  3540. int retval1 = 0;
  3541. int ret;
  3542. struct fts_ts_info *info;
  3543. struct delayed_work *fwu_work = container_of(work,
  3544. struct delayed_work, work);
  3545. int crc_status = 0;
  3546. int error = 0;
  3547. struct Firmware fwD;
  3548. int orig_size;
  3549. u8 *orig_data;
  3550. info = container_of(fwu_work, struct fts_ts_info, fwu_work);
  3551. logError(0, "%s Fw Auto Update is starting...\n", tag);
  3552. ret = getFWdata(PATH_FILE_FW, &orig_data, &orig_size, 0);
  3553. if (ret < OK) {
  3554. logError(0, "%s %s: impossible retrieve FW... ERROR %08X\n",
  3555. tag, __func__, ERROR_MEMH_READ);
  3556. ret = (ret | ERROR_MEMH_READ);
  3557. goto NO_FIRMWARE_UPDATE;
  3558. }
  3559. ret = parseBinFile(orig_data, orig_size, &fwD, 1);
  3560. if (ret < OK) {
  3561. logError(1, "%s %s: impossible parse ERROR %08X\n",
  3562. tag, __func__, ERROR_MEMH_READ);
  3563. ret = (ret | ERROR_MEMH_READ);
  3564. kfree(fwD.data);
  3565. goto NO_FIRMWARE_UPDATE;
  3566. }
  3567. fts_chip_powercycle(info);
  3568. retval = flash_burn(&fwD, crc_status, 1);
  3569. if ((retval & 0xFF000000) == ERROR_FLASH_PROCEDURE) {
  3570. logError(1, "%s %s:firmware update retry! ERROR %08X\n",
  3571. tag, __func__, retval);
  3572. fts_chip_powercycle(info);
  3573. retval1 = flash_burn(&fwD, crc_status, 1);
  3574. if ((retval1 & 0xFF000000) == ERROR_FLASH_PROCEDURE) {
  3575. logError(1, "%s %s: update failed again! ERROR %08X\n",
  3576. tag, __func__, retval1);
  3577. logError(1, "%s Fw Auto Update Failed!\n", tag);
  3578. }
  3579. }
  3580. kfree(fwD.data);
  3581. u16ToU8_be(SYSTEM_RESET_ADDRESS, &cmd[1]);
  3582. ret = fts_writeCmd(cmd, 4);
  3583. if (ret < OK) {
  3584. logError(1, "%s %s Can't send reset command! ERROR %08X\n",
  3585. tag, __func__, ret);
  3586. } else {
  3587. setSystemResettedDown(1);
  3588. setSystemResettedUp(1);
  3589. ret = pollForEvent(event_to_search, 2, readData,
  3590. GENERAL_TIMEOUT);
  3591. if (ret < OK) {
  3592. logError(0, "%s %s: No CX CRC Found!\n", tag, __func__);
  3593. } else {
  3594. if (readData[2] == CRC_CX_MEMORY) {
  3595. logError(1, "%s %s: CRC Error! ERROR:%02X\n\n",
  3596. tag, __func__, readData[2]);
  3597. flag_init = 1;
  3598. }
  3599. }
  3600. }
  3601. if (ftsInfo.u8_msScrConfigTuneVer != ftsInfo.u8_msScrCxmemTuneVer ||
  3602. ftsInfo.u8_ssTchConfigTuneVer != ftsInfo.u8_ssTchCxmemTuneVer)
  3603. ret = ERROR_GET_INIT_STATUS;
  3604. else if (((ftsInfo.u32_mpPassFlag != INIT_MP)
  3605. && (ftsInfo.u32_mpPassFlag != INIT_FIELD)) || flag_init == 1)
  3606. ret = ERROR_GET_INIT_STATUS;
  3607. else
  3608. ret = OK;
  3609. if (ret == ERROR_GET_INIT_STATUS) {
  3610. error = fts_chip_initialization(info);
  3611. if (error < OK)
  3612. logError(1, "%s %s Can't initialize chip! ERROR %08X",
  3613. tag, __func__, error);
  3614. }
  3615. NO_FIRMWARE_UPDATE:
  3616. error = fts_init_afterProbe(info);
  3617. if (error < OK)
  3618. logError(1, "%s Can't initialize hardware device ERROR %08X\n",
  3619. tag, error);
  3620. logError(0, "%s Fw Auto Update Finished!\n", tag);
  3621. }
  3622. static int fts_chip_initialization(struct fts_ts_info *info)
  3623. {
  3624. int ret2 = 0;
  3625. int retry;
  3626. int initretrycnt = 0;
  3627. struct TestToDo todoDefault;
  3628. todoDefault.MutualRaw = 1;
  3629. todoDefault.MutualRawGap = 1;
  3630. todoDefault.MutualCx1 = 0;
  3631. todoDefault.MutualCx2 = 0;
  3632. todoDefault.MutualCx2Adj = 0;
  3633. todoDefault.MutualCxTotal = 0;
  3634. todoDefault.MutualCxTotalAdj = 0;
  3635. todoDefault.MutualKeyRaw = 0;
  3636. todoDefault.MutualKeyCx1 = 0;
  3637. todoDefault.MutualKeyCx2 = 0;
  3638. todoDefault.MutualKeyCxTotal = 0;
  3639. todoDefault.SelfForceRaw = 0;
  3640. todoDefault.SelfForceRawGap = 0;
  3641. todoDefault.SelfForceIx1 = 0;
  3642. todoDefault.SelfForceIx2 = 0;
  3643. todoDefault.SelfForceIx2Adj = 0;
  3644. todoDefault.SelfForceIxTotal = 0;
  3645. todoDefault.SelfForceIxTotalAdj = 0;
  3646. todoDefault.SelfForceCx1 = 0;
  3647. todoDefault.SelfForceCx2 = 0;
  3648. todoDefault.SelfForceCx2Adj = 0;
  3649. todoDefault.SelfForceCxTotal = 0;
  3650. todoDefault.SelfForceCxTotalAdj = 0;
  3651. todoDefault.SelfSenseRaw = 1;
  3652. todoDefault.SelfSenseRawGap = 0;
  3653. todoDefault.SelfSenseIx1 = 0;
  3654. todoDefault.SelfSenseIx2 = 0;
  3655. todoDefault.SelfSenseIx2Adj = 0;
  3656. todoDefault.SelfSenseIxTotal = 0;
  3657. todoDefault.SelfSenseIxTotalAdj = 0;
  3658. todoDefault.SelfSenseCx1 = 0;
  3659. todoDefault.SelfSenseCx2 = 0;
  3660. todoDefault.SelfSenseCx2Adj = 0;
  3661. todoDefault.SelfSenseCxTotal = 0;
  3662. todoDefault.SelfSenseCxTotalAdj = 0;
  3663. for (retry = 0; retry <= INIT_FLAG_CNT; retry++) {
  3664. ret2 = production_test_main(LIMITS_FILE, 1, 1, &todoDefault,
  3665. INIT_FIELD);
  3666. if (ret2 == OK)
  3667. break;
  3668. initretrycnt++;
  3669. logError(1, "%s %s: cycle count = %04d - ERROR %08X\n",
  3670. tag, __func__, initretrycnt, ret2);
  3671. fts_chip_powercycle(info);
  3672. }
  3673. if (ret2 < OK)
  3674. logError(1, "%s failed to initializate 3 times\n", tag);
  3675. return ret2;
  3676. }
  3677. #ifdef FTS_USE_POLLING_MODE
  3678. static enum hrtimer_restart fts_timer_func(struct hrtimer *timer)
  3679. {
  3680. struct fts_ts_info *info =
  3681. container_of(timer, struct fts_ts_info, timer);
  3682. queue_work(info->event_wq, &info->work);
  3683. return HRTIMER_NORESTART;
  3684. }
  3685. #else
  3686. static irqreturn_t fts_interrupt_handler(int irq, void *handle)
  3687. {
  3688. struct fts_ts_info *info = handle;
  3689. if (!info) {
  3690. pr_err("%s: Invalid info\n", __func__);
  3691. return IRQ_HANDLED;
  3692. }
  3693. #ifdef CONFIG_ST_TRUSTED_TOUCH
  3694. #ifndef CONFIG_ARCH_QTI_VM
  3695. if (atomic_read(&info->vm_info->pvm_owns_iomem) &&
  3696. atomic_read(&info->vm_info->pvm_owns_irq) &&
  3697. atomic_read(&info->trusted_touch_enabled)) {
  3698. pr_err("%s: Cannot service interrupts in PVM while trusted touch is enabled\n",
  3699. __func__);
  3700. return IRQ_HANDLED;
  3701. }
  3702. #endif
  3703. #endif
  3704. disable_irq_nosync(info->client->irq);
  3705. queue_work(info->event_wq, &info->work);
  3706. return IRQ_HANDLED;
  3707. }
  3708. #endif
  3709. static int fts_interrupt_install(struct fts_ts_info *info)
  3710. {
  3711. int i, error = 0;
  3712. size_t len;
  3713. len = sizeof(struct event_dispatch_handler_t) * EVENTID_LAST;
  3714. info->event_dispatch_table = kzalloc(len, GFP_KERNEL);
  3715. if (!info->event_dispatch_table) {
  3716. logError(1, "%s OOM allocating event dispatch table\n", tag);
  3717. return -ENOMEM;
  3718. }
  3719. for (i = 0; i < EVENTID_LAST; i++)
  3720. info->event_dispatch_table[i].handler = fts_nop_event_handler;
  3721. install_handler(info, ENTER_POINTER, enter_pointer);
  3722. install_handler(info, LEAVE_POINTER, leave_pointer);
  3723. install_handler(info, MOTION_POINTER, motion_pointer);
  3724. install_handler(info, ERROR_EVENT, error);
  3725. install_handler(info, CONTROL_READY, controller_ready);
  3726. install_handler(info, STATUS_UPDATE, status);
  3727. #ifdef PHONE_GESTURE
  3728. install_handler(info, GESTURE, gesture);
  3729. #endif
  3730. #ifdef PHONE_KEY
  3731. install_handler(info, KEY_STATUS, key_status);
  3732. #endif
  3733. /* disable interrupts in any case */
  3734. error = fts_disableInterrupt();
  3735. #ifdef FTS_USE_POLLING_MODE
  3736. logError(0, "%s Polling Mode\n");
  3737. hrtimer_init(&info->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
  3738. info->timer.function = fts_timer_func;
  3739. hrtimer_start(&info->timer, ktime_set(1, 0), HRTIMER_MODE_REL);
  3740. #else
  3741. #ifdef CONFIG_ARCH_QTI_VM
  3742. logError(0, "%s Interrupt Mode\n", tag);
  3743. if (request_threaded_irq(info->client->irq, NULL, fts_interrupt_handler,
  3744. IRQF_TRIGGER_HIGH | IRQF_ONESHOT, info->client->name, info)) {
  3745. logError(1, "%s Request irq failed\n", tag);
  3746. kfree(info->event_dispatch_table);
  3747. error = -EBUSY;
  3748. }
  3749. #else
  3750. logError(0, "%s Interrupt Mode\n", tag);
  3751. if (request_threaded_irq(info->client->irq, NULL, fts_interrupt_handler,
  3752. IRQF_TRIGGER_LOW | IRQF_ONESHOT, info->client->name, info)) {
  3753. logError(1, "%s Request irq failed\n", tag);
  3754. kfree(info->event_dispatch_table);
  3755. error = -EBUSY;
  3756. }
  3757. #endif
  3758. #endif
  3759. return error;
  3760. }
  3761. static void fts_interrupt_uninstall(struct fts_ts_info *info)
  3762. {
  3763. fts_disableInterrupt();
  3764. kfree(info->event_dispatch_table);
  3765. #ifdef FTS_USE_POLLING_MODE
  3766. hrtimer_cancel(&info->timer);
  3767. #else
  3768. free_irq(info->client->irq, info);
  3769. #endif
  3770. }
  3771. static void fts_interrupt_enable(struct fts_ts_info *info)
  3772. {
  3773. #ifdef FTS_USE_POLLING_MODE
  3774. hrtimer_start(&info->timer, ktime_set(0, 10000000), HRTIMER_MODE_REL);
  3775. #else
  3776. enable_irq(info->client->irq);
  3777. #endif
  3778. /* enable the touch IC irq */
  3779. fts_enableInterrupt();
  3780. }
  3781. static void fts_interrupt_disable(struct fts_ts_info *info)
  3782. {
  3783. /* disable the touch IC irq */
  3784. fts_disableInterrupt();
  3785. #ifdef FTS_USE_POLLING_MODE
  3786. hrtimer_cancel(&info->timer);
  3787. #else
  3788. disable_irq(info->client->irq);
  3789. #endif
  3790. }
  3791. static int fts_init(struct fts_ts_info *info)
  3792. {
  3793. int error;
  3794. error = fts_system_reset();
  3795. if (error < OK && error != (ERROR_TIMEOUT | ERROR_SYSTEM_RESET_FAIL)) {
  3796. logError(1, "%s Cannot reset the device! ERROR %08X\n",
  3797. tag, error);
  3798. return error;
  3799. }
  3800. if (error == (ERROR_TIMEOUT | ERROR_SYSTEM_RESET_FAIL)) {
  3801. logError(1, "%s Setting default Chip INFO!\n", tag);
  3802. defaultChipInfo(0);
  3803. } else {
  3804. error = readChipInfo(0);
  3805. if (error < OK) {
  3806. logError(1, "%s Cannot read Chip Info!ERROR:%08X\n",
  3807. tag, error);
  3808. }
  3809. }
  3810. error = fts_interrupt_install(info);
  3811. if (error != OK)
  3812. logError(1, "%s Init (1) error (ERROR = %08X)\n", tag, error);
  3813. return error;
  3814. }
  3815. int fts_chip_powercycle(struct fts_ts_info *info)
  3816. {
  3817. int error = 0;
  3818. logError(0, "%s %s: Power Cycle Starting...\n", tag, __func__);
  3819. /*
  3820. * if IRQ pin is short with DVDD a call to
  3821. * the ISR will triggered when the regulator is turned off
  3822. */
  3823. logError(0, "%s %s: Disabling IRQ...\n", tag, __func__);
  3824. disable_irq_nosync(info->client->irq);
  3825. if (info->pwr_reg) {
  3826. error = regulator_disable(info->pwr_reg);
  3827. if (error < 0) {
  3828. logError(1, "%s %s: Failed to disable DVDD regulator\n",
  3829. tag, __func__);
  3830. }
  3831. }
  3832. if (info->bus_reg) {
  3833. error = regulator_disable(info->bus_reg);
  3834. if (error < 0) {
  3835. logError(1, "%s %s: Failed to disable AVDD regulator\n",
  3836. tag, __func__);
  3837. }
  3838. }
  3839. if (info->bdata->reset_gpio != GPIO_NOT_DEFINED)
  3840. gpio_set_value(info->bdata->reset_gpio, 0);
  3841. else
  3842. msleep(300);
  3843. if (info->pwr_reg) {
  3844. error = regulator_enable(info->bus_reg);
  3845. if (error < 0) {
  3846. logError(1, "%s %s: Failed to enable AVDD regulator\n",
  3847. tag, __func__);
  3848. }
  3849. }
  3850. if (info->bus_reg) {
  3851. error = regulator_enable(info->pwr_reg);
  3852. if (error < 0) {
  3853. logError(1, "%s %s: Failed to enable DVDD regulator\n",
  3854. tag, __func__);
  3855. }
  3856. }
  3857. /* time needed by the regulators for reaching the regime values */
  3858. msleep(20);
  3859. if (info->bdata->reset_gpio != GPIO_NOT_DEFINED) {
  3860. /* time to wait before bring up the reset */
  3861. /* gpio after the power up of the regulators */
  3862. msleep(20);
  3863. gpio_set_value(info->bdata->reset_gpio, 1);
  3864. /* mdelay(300); */
  3865. }
  3866. release_all_touches(info);
  3867. logError(0, "%s %s: Enabling IRQ...\n", tag, __func__);
  3868. enable_irq(info->client->irq);
  3869. logError(0, "%s %s: Power Cycle Finished! ERROR CODE = %08x\n",
  3870. tag, __func__, error);
  3871. setSystemResettedUp(1);
  3872. setSystemResettedDown(1);
  3873. return error;
  3874. }
  3875. int fts_chip_powercycle2(struct fts_ts_info *info, unsigned long sleep)
  3876. {
  3877. int error = 0;
  3878. logError(0, "%s %s: Power Cycle Starting...\n", tag, __func__);
  3879. if (info->pwr_reg) {
  3880. error = regulator_disable(info->pwr_reg);
  3881. if (error < 0) {
  3882. logError(1, "%s %s: Failed to disable DVDD regulator\n",
  3883. tag, __func__);
  3884. }
  3885. }
  3886. if (info->bus_reg) {
  3887. error = regulator_disable(info->bus_reg);
  3888. if (error < 0) {
  3889. logError(1, "%s %s: Failed to disable AVDD regulator\n",
  3890. tag, __func__);
  3891. }
  3892. }
  3893. if (info->bdata->reset_gpio != GPIO_NOT_DEFINED)
  3894. gpio_set_value(info->bdata->reset_gpio, 0);
  3895. msleep(sleep);
  3896. if (info->pwr_reg) {
  3897. error = regulator_enable(info->bus_reg);
  3898. if (error < 0) {
  3899. logError(1, "%s %s: Failed to enable AVDD regulator\n",
  3900. tag, __func__);
  3901. }
  3902. }
  3903. if (info->bus_reg) {
  3904. error = regulator_enable(info->pwr_reg);
  3905. if (error < 0) {
  3906. logError(1, "%s %s: Failed to enable DVDD regulator\n",
  3907. tag, __func__);
  3908. }
  3909. }
  3910. /* time needed by the regulators for reaching the regime values */
  3911. msleep(500);
  3912. if (info->bdata->reset_gpio != GPIO_NOT_DEFINED) {
  3913. /*
  3914. * time to wait before bring up the reset
  3915. * gpio after the power up of the regulators
  3916. */
  3917. msleep(20);
  3918. gpio_set_value(info->bdata->reset_gpio, 1);
  3919. /* msleep(300); */
  3920. }
  3921. /* before reset clear all slot */
  3922. release_all_touches(info);
  3923. logError(0, "%s %s: Power Cycle Finished! ERROR CODE = %08x\n",
  3924. tag, __func__, error);
  3925. setSystemResettedUp(1);
  3926. setSystemResettedDown(1);
  3927. return error;
  3928. }
  3929. static int fts_init_afterProbe(struct fts_ts_info *info)
  3930. {
  3931. int error = 0;
  3932. /* system reset */
  3933. error = cleanUp(0);
  3934. /* enable the features and the sensing */
  3935. error |= fts_mode_handler(info, 0);
  3936. /* enable the interrupt */
  3937. error |= fts_enableInterrupt();
  3938. #if defined(CONFIG_FB_MSM)
  3939. error |= fb_register_client(&info->notifier);
  3940. #else
  3941. if (active_panel)
  3942. error |= drm_panel_notifier_register(active_panel,
  3943. &info->notifier);
  3944. #endif
  3945. if (error < OK)
  3946. logError(1, "%s %s Init after Probe error (ERROR = %08X)\n",
  3947. tag, __func__, error);
  3948. return error;
  3949. }
  3950. /*
  3951. * TODO: change this function according with the needs
  3952. * of customer in terms of feature to enable/disable
  3953. */
  3954. static int fts_mode_handler(struct fts_ts_info *info, int force)
  3955. {
  3956. int res = OK;
  3957. int ret = OK;
  3958. /* initialize the mode to Nothing in order */
  3959. /* to be updated depending on the features enabled */
  3960. info->mode = MODE_NOTHING;
  3961. logError(0, "%s %s: Mode Handler starting...\n", tag, __func__);
  3962. switch (info->resume_bit) {
  3963. case 0:
  3964. /* screen down */
  3965. logError(0, "%s %s: Screen OFF...\n", tag, __func__);
  3966. /*
  3967. * do sense off in order to avoid the flooding
  3968. * of the fifo with touch events if someone is
  3969. * touching the panel during suspend
  3970. */
  3971. logError(0, "%s %s: Sense OFF!\n", tag, __func__);
  3972. /*
  3973. *we need to use fts_command for speed reason
  3974. * (no need to check echo in this case and interrupt
  3975. * can be enabled)
  3976. */
  3977. res |= fts_command(info, FTS_CMD_MS_MT_SENSE_OFF);
  3978. #ifdef PHONE_KEY
  3979. logError(0, "%s %s: Key OFF!\n", tag, __func__);
  3980. res |= fts_command(info, FTS_CMD_MS_KEY_OFF);
  3981. #endif
  3982. #ifdef PHONE_GESTURE
  3983. if (info->gesture_enabled == 1) {
  3984. logError(0, "%s %s: enter in gesture mode!\n",
  3985. tag, __func__);
  3986. ret = enterGestureMode(isSystemResettedDown());
  3987. if (ret >= OK) {
  3988. info->mode |= FEAT_GESTURE;
  3989. } else {
  3990. logError(1,
  3991. "%s %s:enterGestureMode failed!%08X recovery in senseOff\n",
  3992. tag, __func__, ret);
  3993. }
  3994. res |= ret;
  3995. }
  3996. #endif
  3997. if (info->mode != (FEAT_GESTURE|MODE_NOTHING)
  3998. || info->gesture_enabled == 0)
  3999. info->mode |= MODE_SENSEOFF;
  4000. setSystemResettedDown(0);
  4001. break;
  4002. case 1:
  4003. /* screen up */
  4004. logError(0, "%s %s: Screen ON...\n", tag, __func__);
  4005. #ifdef FEAT_GLOVE
  4006. if ((info->glove_enabled == FEAT_ENABLE &&
  4007. isSystemResettedUp()) || force == 1) {
  4008. logError(0, "%s %s: Glove Mode setting...\n",
  4009. tag, __func__);
  4010. ret = featureEnableDisable(info->glove_enabled,
  4011. FEAT_GLOVE);
  4012. if (ret < OK) {
  4013. logError(1,
  4014. "%s %s:error in setting GLOVE_MODE!%08X\n",
  4015. tag, __func__, ret);
  4016. }
  4017. res |= ret;
  4018. if (ret >= OK && info->glove_enabled == FEAT_ENABLE) {
  4019. info->mode |= FEAT_GLOVE;
  4020. logError(1, "%s %s: GLOVE_MODE Enabled!\n",
  4021. tag, __func__);
  4022. } else {
  4023. logError(1, "%s %s: GLOVE_MODE Disabled!\n",
  4024. tag, __func__);
  4025. }
  4026. }
  4027. #endif
  4028. #ifdef FEAT_STYLUS
  4029. if ((info->stylus_enabled == FEAT_ENABLE &&
  4030. isSystemResettedUp()) || force == 1) {
  4031. logError(0, "%s %s: Stylus Mode setting...\n",
  4032. tag, __func__);
  4033. ret = featureEnableDisable(info->stylus_enabled,
  4034. FEAT_STYLUS);
  4035. if (ret < OK) {
  4036. logError(1,
  4037. "%s %s:error in set STYLUS_MODE!%08X\n",
  4038. tag, __func__, ret);
  4039. }
  4040. res |= ret;
  4041. if (ret >= OK && info->stylus_enabled == FEAT_ENABLE) {
  4042. info->mode |= FEAT_STYLUS;
  4043. logError(1, "%s %s: STYLUS_MODE Enabled!\n",
  4044. tag, __func__);
  4045. } else {
  4046. logError(1, "%s %s: STYLUS_MODE Disabled!\n",
  4047. tag, __func__);
  4048. }
  4049. }
  4050. #endif
  4051. #ifdef FEAT_COVER
  4052. if ((info->cover_enabled == FEAT_ENABLE &&
  4053. isSystemResettedUp()) || force == 1) {
  4054. logError(0, "%s %s: Cover Mode setting...\n",
  4055. tag, __func__);
  4056. ret = featureEnableDisable(info->cover_enabled,
  4057. FEAT_COVER);
  4058. if (ret < OK) {
  4059. logError(1,
  4060. "%s %s:error setting COVER_MODE!%08X\n",
  4061. tag, __func__, ret);
  4062. }
  4063. res |= ret;
  4064. if (ret >= OK && info->cover_enabled == FEAT_ENABLE) {
  4065. info->mode |= FEAT_COVER;
  4066. logError(1, "%s %s: COVER_MODE Enabled!\n",
  4067. tag, __func__);
  4068. } else {
  4069. logError(1, "%s %s: COVER_MODE Disabled!\n",
  4070. tag, __func__);
  4071. }
  4072. }
  4073. #endif
  4074. #ifdef FEAT_CHARGER
  4075. if ((info->charger_enabled == FEAT_ENABLE &&
  4076. isSystemResettedUp()) || force == 1) {
  4077. logError(0, "%s %s: Charger Mode setting...\n",
  4078. tag, __func__);
  4079. ret = featureEnableDisable(info->charger_enabled,
  4080. FEAT_CHARGER);
  4081. if (ret < OK) {
  4082. logError(1,
  4083. "%s %s:error set CHARGER_MODE!%08X\n",
  4084. tag, __func__, ret);
  4085. }
  4086. res |= ret;
  4087. if (ret >= OK && info->charger_enabled == FEAT_ENABLE) {
  4088. info->mode |= FEAT_CHARGER;
  4089. logError(1, "%s %s: CHARGER_MODE Enabled!\n",
  4090. tag, __func__);
  4091. } else {
  4092. logError(1, "%s %s: CHARGER_MODE Disabled!\n",
  4093. tag, __func__);
  4094. }
  4095. }
  4096. #endif
  4097. #ifdef FEAT_VR
  4098. if ((info->vr_enabled == FEAT_ENABLE &&
  4099. isSystemResettedUp()) || force == 1) {
  4100. logError(0, "%s %s: Vr Mode setting\n", tag, __func__);
  4101. ret = featureEnableDisable(info->vr_enabled, FEAT_VR);
  4102. if (ret < OK) {
  4103. logError(1,
  4104. "%s %s:error setting VR_MODE!:%08X\n",
  4105. tag, __func__, ret);
  4106. }
  4107. res |= ret;
  4108. if (ret >= OK && info->vr_enabled == FEAT_ENABLE) {
  4109. info->mode |= FEAT_VR;
  4110. logError(1, "%s %s: VR_MODE Enabled!\n",
  4111. tag, __func__);
  4112. } else {
  4113. logError(1, "%s %s: VR_MODE Disabled!\n",
  4114. tag, __func__);
  4115. }
  4116. }
  4117. #endif
  4118. #ifdef FEAT_EDGE_REJECTION
  4119. if ((info->edge_rej_enabled == FEAT_ENABLE &&
  4120. isSystemResettedUp()) || force == 1) {
  4121. logError(0, "%s %s: Edge Rejection Mode setting\n",
  4122. tag, __func__);
  4123. ret = featureEnableDisable(info->edge_rej_enabled,
  4124. FEAT_EDGE_REJECTION);
  4125. if (ret < OK) {
  4126. logError(1,
  4127. "%s %s:err set EDGE_REJECTION_MODE!%08X\n",
  4128. tag, __func__, ret);
  4129. }
  4130. res |= ret;
  4131. if (ret >= OK && info->edge_rej_enabled ==
  4132. FEAT_ENABLE) {
  4133. info->mode |= FEAT_EDGE_REJECTION;
  4134. logError(1,
  4135. "%s %s:EDGE_REJECTION_MODE Enabled!\n",
  4136. tag, __func__);
  4137. } else {
  4138. logError(1,
  4139. "%s %s:EDGE_REJECTION_MODE Disabled!\n",
  4140. tag, __func__);
  4141. }
  4142. }
  4143. #endif
  4144. #ifdef FEAT_CORNER_REJECTION
  4145. if ((info->corner_rej_enabled == FEAT_ENABLE &&
  4146. isSystemResettedUp()) || force == 1) {
  4147. logError(0, "%s %s: Corner rejection Mode setting\n",
  4148. tag, __func__);
  4149. ret = featureEnableDisable(info->corner_rej_enabled,
  4150. FEAT_CORNER_REJECTION);
  4151. if (ret < OK) {
  4152. logError(1,
  4153. "%s%s:err CORNER_REJECTION_MODE!%08X\n",
  4154. tag, __func__, ret);
  4155. }
  4156. res |= ret;
  4157. if (ret >= OK && info->corner_rej_enabled ==
  4158. FEAT_ENABLE) {
  4159. info->mode |= FEAT_CORNER_REJECTION;
  4160. logError(1,
  4161. "%s%s:CORNER_REJECTION_MODE Enabled!\n",
  4162. tag, __func__);
  4163. } else {
  4164. logError(1,
  4165. "%s%s:CORNER_REJECTION_MODE Disabled\n",
  4166. tag, __func__);
  4167. }
  4168. }
  4169. #endif
  4170. #ifdef FEAT_EDGE_PALM_REJECTION
  4171. if ((info->edge_palm_rej_enabled == FEAT_ENABLE &&
  4172. isSystemResettedUp()) || force == 1) {
  4173. logError(0, "%s %s:Edge Palm rejection Mode setting\n",
  4174. tag, __func__);
  4175. ret = featureEnableDisable(info->edge_palm_rej_enabled,
  4176. FEAT_EDGE_PALM_REJECTION);
  4177. if (ret < OK) {
  4178. logError(1,
  4179. "%s %s:err EDGE_PALM_REJECTION_MODE!%08X\n",
  4180. tag, __func__, ret);
  4181. }
  4182. res |= ret;
  4183. if (ret >= OK && info->edge_palm_rej_enabled ==
  4184. FEAT_ENABLE) {
  4185. info->mode |= FEAT_EDGE_PALM_REJECTION;
  4186. logError(1,
  4187. "%s %s:EDGE_PALM_REJECTION_MODE Enabled!\n",
  4188. tag, __func__);
  4189. } else {
  4190. logError(1,
  4191. "%s %s:EDGE_PALM_REJECTION_MODE Disabled!\n",
  4192. tag, __func__);
  4193. }
  4194. }
  4195. #endif
  4196. logError(0, "%s %s: Sense ON!\n", tag, __func__);
  4197. res |= fts_command(info, FTS_CMD_MS_MT_SENSE_ON);
  4198. info->mode |= MODE_SENSEON;
  4199. #ifdef PHONE_KEY
  4200. logError(0, "%s %s: Key ON!\n", tag, __func__);
  4201. res |= fts_command(info, FTS_CMD_MS_KEY_ON);
  4202. #endif
  4203. setSystemResettedUp(0);
  4204. break;
  4205. default:
  4206. logError(1,
  4207. "%s %s: invalid resume_bit value = %d! ERROR %08X\n",
  4208. tag, __func__, info->resume_bit, ERROR_OP_NOT_ALLOW);
  4209. res = ERROR_OP_NOT_ALLOW;
  4210. }
  4211. logError(0, "%s %s: Mode Handler finished! res = %08X\n", tag, __func__,
  4212. res);
  4213. return res;
  4214. }
  4215. static int fts_chip_power_switch(struct fts_ts_info *info, bool on)
  4216. {
  4217. int error = -1;
  4218. if (info->bdata->pwr_on_suspend) {
  4219. if (!info->ts_pinctrl)
  4220. return 0;
  4221. if (on) {
  4222. error = pinctrl_select_state(info->ts_pinctrl,
  4223. info->pinctrl_state_active);
  4224. if (error < 0)
  4225. logError(1, "%s: Failed to select %s\n",
  4226. __func__, PINCTRL_STATE_ACTIVE);
  4227. } else {
  4228. error = pinctrl_select_state(info->ts_pinctrl,
  4229. info->pinctrl_state_suspend);
  4230. if (error < 0)
  4231. logError(1, "%s: Failed to select %s\n",
  4232. __func__, PINCTRL_STATE_SUSPEND);
  4233. }
  4234. return 0;
  4235. }
  4236. if (on) {
  4237. if (info->bus_reg) {
  4238. error = regulator_enable(info->bus_reg);
  4239. if (error < 0)
  4240. logError(1, "%s %s: Failed to enable AVDD\n",
  4241. tag, __func__);
  4242. }
  4243. if (info->pwr_reg) {
  4244. error = regulator_enable(info->pwr_reg);
  4245. if (error < 0)
  4246. logError(1, "%s %s: Failed to enable DVDD\n",
  4247. tag, __func__);
  4248. }
  4249. if (info->ts_pinctrl) {
  4250. if (pinctrl_select_state(info->ts_pinctrl,
  4251. info->pinctrl_state_active) < 0) {
  4252. logError(1, "%s: Failed to select %s\n",
  4253. __func__, PINCTRL_STATE_ACTIVE);
  4254. }
  4255. }
  4256. } else {
  4257. if (info->bdata->reset_gpio != GPIO_NOT_DEFINED)
  4258. gpio_set_value(info->bdata->reset_gpio, 0);
  4259. else
  4260. msleep(300);
  4261. if (info->ts_pinctrl) {
  4262. if (pinctrl_select_state(info->ts_pinctrl,
  4263. info->pinctrl_state_suspend) < 0) {
  4264. logError(1, "%s: Failed to select %s\n",
  4265. __func__, PINCTRL_STATE_SUSPEND);
  4266. }
  4267. }
  4268. if (info->pwr_reg) {
  4269. error = regulator_disable(info->pwr_reg);
  4270. if (error < 0)
  4271. logError(1, "%s %s: Failed to disable DVDD\n",
  4272. tag, __func__);
  4273. }
  4274. if (info->bus_reg) {
  4275. error = regulator_disable(info->bus_reg);
  4276. if (error < 0)
  4277. logError(1, "%s %s: Failed to disable AVDD\n",
  4278. tag, __func__);
  4279. }
  4280. }
  4281. return error;
  4282. }
  4283. static void fts_resume_work(struct work_struct *work)
  4284. {
  4285. struct fts_ts_info *info;
  4286. info = container_of(work, struct fts_ts_info, resume_work);
  4287. __pm_wakeup_event(info->wakeup_source, HZ);
  4288. fts_chip_power_switch(info, true);
  4289. info->resume_bit = 1;
  4290. fts_system_reset();
  4291. #ifdef USE_NOISE_PARAM
  4292. readNoiseParameters(noise_params);
  4293. #endif
  4294. #ifdef USE_NOISE_PARAM
  4295. writeNoiseParameters(noise_params);
  4296. #endif
  4297. release_all_touches(info);
  4298. fts_mode_handler(info, 0);
  4299. info->sensor_sleep = false;
  4300. fts_interrupt_enable(info);
  4301. }
  4302. static void fts_suspend_work(struct work_struct *work)
  4303. {
  4304. struct fts_ts_info *info;
  4305. info = container_of(work, struct fts_ts_info, suspend_work);
  4306. #ifdef CONFIG_ST_TRUSTED_TOUCH
  4307. if (atomic_read(&info->trusted_touch_enabled))
  4308. wait_for_completion_interruptible(
  4309. &info->trusted_touch_powerdown);
  4310. #endif
  4311. __pm_wakeup_event(info->wakeup_source, HZ);
  4312. info->resume_bit = 0;
  4313. fts_mode_handler(info, 0);
  4314. fts_interrupt_disable(info);
  4315. release_all_touches(info);
  4316. info->sensor_sleep = true;
  4317. fts_chip_power_switch(info, false);
  4318. }
  4319. #if defined(CONFIG_FB_MSM)
  4320. static int fts_fb_state_chg_callback(struct notifier_block *nb,
  4321. unsigned long val, void *data)
  4322. {
  4323. struct fts_ts_info *info = container_of(nb,
  4324. struct fts_ts_info, notifier);
  4325. struct fb_event *evdata = data;
  4326. unsigned int blank;
  4327. if (!evdata || (evdata->id != 0))
  4328. return 0;
  4329. if (val != FB_EVENT_BLANK)
  4330. return 0;
  4331. logError(0, "%s %s: fts notifier begin!\n", tag, __func__);
  4332. if (evdata->data && val == FB_EVENT_BLANK && info) {
  4333. blank = *(int *) (evdata->data);
  4334. switch (blank) {
  4335. case FB_BLANK_POWERDOWN:
  4336. if (info->sensor_sleep)
  4337. break;
  4338. logError(0, "%s %s: FB_BLANK_POWERDOWN\n",
  4339. tag, __func__);
  4340. queue_work(info->event_wq, &info->suspend_work);
  4341. break;
  4342. case FB_BLANK_UNBLANK:
  4343. if (!info->sensor_sleep)
  4344. break;
  4345. logError(0, "%s %s: FB_BLANK_UNBLANK\n",
  4346. tag, __func__);
  4347. queue_work(info->event_wq, &info->resume_work);
  4348. break;
  4349. default:
  4350. break;
  4351. }
  4352. }
  4353. return NOTIFY_OK;
  4354. }
  4355. #else
  4356. static int fts_fb_state_chg_callback(struct notifier_block *nb,
  4357. unsigned long val, void *data)
  4358. {
  4359. struct fts_ts_info *info = container_of(nb, struct fts_ts_info,
  4360. notifier);
  4361. struct drm_panel_notifier *evdata = data;
  4362. unsigned int blank;
  4363. if (!evdata)
  4364. return 0;
  4365. if (val != DRM_PANEL_EVENT_BLANK)
  4366. return 0;
  4367. logError(0, "%s %s: fts notifier begin!\n", tag, __func__);
  4368. if (evdata->data && val == DRM_PANEL_EVENT_BLANK && info) {
  4369. blank = *(int *) (evdata->data);
  4370. switch (blank) {
  4371. case DRM_PANEL_BLANK_POWERDOWN:
  4372. if (info->sensor_sleep && info->aoi_notify_enabled)
  4373. break;
  4374. if (info->aoi_notify_enabled)
  4375. info->aoi_wake_on_suspend = true;
  4376. else
  4377. info->aoi_wake_on_suspend = false;
  4378. if (info->aoi_wake_on_suspend) {
  4379. info->sensor_sleep = true;
  4380. __pm_stay_awake(info->wakeup_source);
  4381. } else {
  4382. queue_work(info->event_wq, &info->suspend_work);
  4383. }
  4384. break;
  4385. case DRM_PANEL_BLANK_UNBLANK:
  4386. if (info->aoi_wake_on_suspend)
  4387. __pm_relax(info->wakeup_source);
  4388. if (!info->sensor_sleep)
  4389. break;
  4390. if (!info->resume_bit)
  4391. queue_work(info->event_wq, &info->resume_work);
  4392. if (info->aoi_wake_on_suspend)
  4393. info->sensor_sleep = false;
  4394. break;
  4395. default:
  4396. break;
  4397. }
  4398. }
  4399. return NOTIFY_OK;
  4400. }
  4401. #endif
  4402. static struct notifier_block fts_noti_block = {
  4403. .notifier_call = fts_fb_state_chg_callback,
  4404. };
  4405. static int fts_pinctrl_init(struct fts_ts_info *info)
  4406. {
  4407. int retval;
  4408. /* Get pinctrl if target uses pinctrl */
  4409. info->ts_pinctrl = devm_pinctrl_get(info->dev);
  4410. if (IS_ERR_OR_NULL(info->ts_pinctrl)) {
  4411. retval = PTR_ERR(info->ts_pinctrl);
  4412. logError(1, "Target does not use pinctrl %d\n", retval);
  4413. goto err_pinctrl_get;
  4414. }
  4415. info->pinctrl_state_active
  4416. = pinctrl_lookup_state(info->ts_pinctrl, PINCTRL_STATE_ACTIVE);
  4417. if (IS_ERR_OR_NULL(info->pinctrl_state_active)) {
  4418. retval = PTR_ERR(info->pinctrl_state_active);
  4419. logError(1, "Can not lookup %s pinstate %d\n",
  4420. PINCTRL_STATE_ACTIVE, retval);
  4421. goto err_pinctrl_lookup;
  4422. }
  4423. info->pinctrl_state_suspend
  4424. = pinctrl_lookup_state(info->ts_pinctrl, PINCTRL_STATE_SUSPEND);
  4425. if (IS_ERR_OR_NULL(info->pinctrl_state_suspend)) {
  4426. retval = PTR_ERR(info->pinctrl_state_suspend);
  4427. logError(1, "Can not lookup %s pinstate %d\n",
  4428. PINCTRL_STATE_SUSPEND, retval);
  4429. goto err_pinctrl_lookup;
  4430. }
  4431. info->pinctrl_state_release
  4432. = pinctrl_lookup_state(info->ts_pinctrl, PINCTRL_STATE_RELEASE);
  4433. if (IS_ERR_OR_NULL(info->pinctrl_state_release)) {
  4434. retval = PTR_ERR(info->pinctrl_state_release);
  4435. logError(1, "Can not lookup %s pinstate %d\n",
  4436. PINCTRL_STATE_RELEASE, retval);
  4437. }
  4438. return 0;
  4439. err_pinctrl_lookup:
  4440. devm_pinctrl_put(info->ts_pinctrl);
  4441. err_pinctrl_get:
  4442. info->ts_pinctrl = NULL;
  4443. return retval;
  4444. }
  4445. static int fts_get_reg(struct fts_ts_info *info, bool get)
  4446. {
  4447. int retval;
  4448. const struct fts_i2c_platform_data *bdata = info->bdata;
  4449. if (!get) {
  4450. retval = 0;
  4451. goto regulator_put;
  4452. }
  4453. if ((bdata->pwr_reg_name != NULL) && (*bdata->pwr_reg_name != 0)) {
  4454. info->pwr_reg = regulator_get(info->dev,
  4455. bdata->pwr_reg_name);
  4456. if (IS_ERR(info->pwr_reg)) {
  4457. logError(1, "%s %s: Failed to get power regulator\n",
  4458. tag, __func__);
  4459. retval = PTR_ERR(info->pwr_reg);
  4460. goto regulator_put;
  4461. }
  4462. retval = regulator_set_load(info->pwr_reg, FTS_DVDD_LOAD);
  4463. if (retval < 0) {
  4464. logError(1, "%s %s: Failed to set power load\n",
  4465. tag, __func__);
  4466. goto regulator_put;
  4467. }
  4468. retval = regulator_set_voltage(info->pwr_reg,
  4469. FTS_DVDD_VOL_MIN, FTS_DVDD_VOL_MAX);
  4470. if (retval < 0) {
  4471. logError(1, "%s %s: Failed to set power voltage\n",
  4472. tag, __func__);
  4473. goto regulator_put;
  4474. }
  4475. }
  4476. if ((bdata->bus_reg_name != NULL) && (*bdata->bus_reg_name != 0)) {
  4477. info->bus_reg = regulator_get(info->dev,
  4478. bdata->bus_reg_name);
  4479. if (IS_ERR(info->bus_reg)) {
  4480. logError(1,
  4481. "%s %s:Failed to get bus pullup regulator\n",
  4482. tag, __func__);
  4483. retval = PTR_ERR(info->bus_reg);
  4484. goto regulator_put;
  4485. }
  4486. retval = regulator_set_load(info->bus_reg, FTS_AVDD_LOAD);
  4487. if (retval < 0) {
  4488. logError(1, "%s %s: Failed to set power load\n",
  4489. tag, __func__);
  4490. goto regulator_put;
  4491. }
  4492. retval = regulator_set_voltage(info->bus_reg,
  4493. FTS_AVDD_VOL_MIN, FTS_AVDD_VOL_MAX);
  4494. if (retval < 0) {
  4495. logError(1, "%s %s: Failed to set power voltage\n",
  4496. tag, __func__);
  4497. goto regulator_put;
  4498. }
  4499. }
  4500. return 0;
  4501. regulator_put:
  4502. if (info->pwr_reg) {
  4503. regulator_put(info->pwr_reg);
  4504. info->pwr_reg = NULL;
  4505. }
  4506. if (info->bus_reg) {
  4507. regulator_put(info->bus_reg);
  4508. info->bus_reg = NULL;
  4509. }
  4510. return retval;
  4511. }
  4512. static int fts_enable_reg(struct fts_ts_info *info,
  4513. bool enable)
  4514. {
  4515. int retval;
  4516. if (!enable) {
  4517. retval = 0;
  4518. goto disable_pwr_reg;
  4519. }
  4520. if (info->bus_reg) {
  4521. retval = regulator_enable(info->bus_reg);
  4522. if (retval < 0) {
  4523. logError(1, "%s %s: Failed to enable bus regulator\n",
  4524. tag, __func__);
  4525. goto exit;
  4526. }
  4527. }
  4528. if (info->pwr_reg) {
  4529. retval = regulator_enable(info->pwr_reg);
  4530. if (retval < 0) {
  4531. logError(1, "%s %s: Failed to enable power regulator\n",
  4532. tag, __func__);
  4533. goto disable_bus_reg;
  4534. }
  4535. }
  4536. return OK;
  4537. disable_pwr_reg:
  4538. if (info->pwr_reg)
  4539. regulator_disable(info->pwr_reg);
  4540. disable_bus_reg:
  4541. if (info->bus_reg)
  4542. regulator_disable(info->bus_reg);
  4543. exit:
  4544. return retval;
  4545. }
  4546. static int fts_gpio_setup(int gpio, bool config, int dir, int state)
  4547. {
  4548. int retval = 0;
  4549. unsigned char buf[16];
  4550. if (config) {
  4551. snprintf(buf, 16, "fts_gpio_%u\n", gpio);
  4552. retval = gpio_request(gpio, buf);
  4553. if (retval) {
  4554. logError(1, "%s %s: Failed to get gpio %d (code: %d)",
  4555. tag, __func__, gpio, retval);
  4556. return retval;
  4557. }
  4558. if (dir == 0)
  4559. retval = gpio_direction_input(gpio);
  4560. else
  4561. retval = gpio_direction_output(gpio, state);
  4562. if (retval) {
  4563. logError(1, "%s %s: Failed to set gpio %d direction",
  4564. tag, __func__, gpio);
  4565. return retval;
  4566. }
  4567. } else {
  4568. gpio_free(gpio);
  4569. }
  4570. return retval;
  4571. }
  4572. static int fts_set_gpio(struct fts_ts_info *info)
  4573. {
  4574. int retval;
  4575. const struct fts_i2c_platform_data *bdata =
  4576. info->bdata;
  4577. retval = fts_gpio_setup(bdata->irq_gpio, true, 0, 0);
  4578. if (retval < 0) {
  4579. logError(1, "%s %s: Failed to configure irq GPIO\n",
  4580. tag, __func__);
  4581. goto err_gpio_irq;
  4582. }
  4583. if (bdata->reset_gpio >= 0) {
  4584. retval = fts_gpio_setup(bdata->reset_gpio, true, 1, 0);
  4585. if (retval < 0) {
  4586. logError(1, "%s %s: Failed to configure reset GPIO\n",
  4587. tag, __func__);
  4588. goto err_gpio_reset;
  4589. }
  4590. }
  4591. if (bdata->reset_gpio >= 0) {
  4592. gpio_set_value(bdata->reset_gpio, 0);
  4593. msleep(20);
  4594. gpio_set_value(bdata->reset_gpio, 1);
  4595. }
  4596. setResetGpio(bdata->reset_gpio);
  4597. return OK;
  4598. err_gpio_reset:
  4599. fts_gpio_setup(bdata->irq_gpio, false, 0, 0);
  4600. setResetGpio(GPIO_NOT_DEFINED);
  4601. err_gpio_irq:
  4602. return retval;
  4603. }
  4604. static int parse_dt(struct device *dev,
  4605. struct fts_i2c_platform_data *bdata)
  4606. {
  4607. int retval;
  4608. const char *name;
  4609. struct device_node *np = dev->of_node;
  4610. bdata->irq_gpio = of_get_named_gpio_flags(np,
  4611. "st,irq-gpio", 0, NULL);
  4612. logError(0, "%s irq_gpio = %d\n", tag, bdata->irq_gpio);
  4613. bdata->pwr_on_suspend =
  4614. of_property_read_bool(np, "st,power_on_suspend");
  4615. retval = of_property_read_string(np, "st,regulator_dvdd", &name);
  4616. if (retval == -EINVAL)
  4617. bdata->pwr_reg_name = NULL;
  4618. else if (retval < 0)
  4619. return retval;
  4620. bdata->pwr_reg_name = name;
  4621. logError(0, "%s pwr_reg_name = %s\n", tag, name);
  4622. retval = of_property_read_string(np, "st,regulator_avdd", &name);
  4623. if (retval == -EINVAL)
  4624. bdata->bus_reg_name = NULL;
  4625. else if (retval < 0)
  4626. return retval;
  4627. bdata->bus_reg_name = name;
  4628. logError(0, "%s bus_reg_name = %s\n", tag, name);
  4629. if (of_property_read_bool(np, "st,reset-gpio")) {
  4630. bdata->reset_gpio = of_get_named_gpio_flags(np,
  4631. "st,reset-gpio", 0, NULL);
  4632. logError(0, "%s reset_gpio =%d\n", tag, bdata->reset_gpio);
  4633. } else {
  4634. bdata->reset_gpio = GPIO_NOT_DEFINED;
  4635. }
  4636. bdata->x_flip = of_property_read_bool(np, "st,x-flip");
  4637. bdata->y_flip = of_property_read_bool(np, "st,y-flip");
  4638. return OK;
  4639. }
  4640. static int check_dt(struct device_node *np)
  4641. {
  4642. int i;
  4643. int count;
  4644. struct device_node *node;
  4645. struct drm_panel *panel;
  4646. count = of_count_phandle_with_args(np, "panel", NULL);
  4647. if (count <= 0)
  4648. return OK;
  4649. for (i = 0; i < count; i++) {
  4650. node = of_parse_phandle(np, "panel", i);
  4651. panel = of_drm_find_panel(node);
  4652. of_node_put(node);
  4653. if (!IS_ERR(panel)) {
  4654. active_panel = panel;
  4655. return OK;
  4656. }
  4657. }
  4658. return PTR_ERR(panel);
  4659. }
  4660. static int check_default_tp(struct device_node *dt, const char *prop)
  4661. {
  4662. const char *active_tp;
  4663. const char *compatible;
  4664. char *start;
  4665. int ret;
  4666. ret = of_property_read_string(dt->parent, prop, &active_tp);
  4667. if (ret) {
  4668. pr_err(" %s:fail to read %s %d\n", __func__, prop, ret);
  4669. return -ENODEV;
  4670. }
  4671. ret = of_property_read_string(dt, "compatible", &compatible);
  4672. if (ret < 0) {
  4673. pr_err(" %s:fail to read %s %d\n", __func__, "compatible", ret);
  4674. return -ENODEV;
  4675. }
  4676. start = strnstr(active_tp, compatible, strlen(active_tp));
  4677. if (start == NULL) {
  4678. pr_err(" %s:no match compatible, %s, %s\n",
  4679. __func__, compatible, active_tp);
  4680. ret = -ENODEV;
  4681. }
  4682. return ret;
  4683. }
  4684. static int fts_probe_delayed(struct fts_ts_info *info)
  4685. {
  4686. int error = 0;
  4687. int retval = 0;
  4688. /* Avoid setting up hardware for TVM during probe */
  4689. #ifdef CONFIG_ST_TRUSTED_TOUCH
  4690. #ifdef CONFIG_ARCH_QTI_VM
  4691. if (!atomic_read(&info->delayed_vm_probe_pending)) {
  4692. atomic_set(&info->delayed_vm_probe_pending, 1);
  4693. return 0;
  4694. }
  4695. goto tvm_setup;
  4696. #endif
  4697. #endif
  4698. logError(0, "%s SET Regulators:\n", tag);
  4699. retval = fts_get_reg(info, true);
  4700. if (retval < 0) {
  4701. logError(1, "%s ERROR: %s: Failed to get regulators\n",
  4702. tag, __func__);
  4703. goto Exit_1;
  4704. }
  4705. retval = fts_enable_reg(info, true);
  4706. if (retval < 0) {
  4707. logError(1,
  4708. "%s %s: ERROR Failed to enable regulators\n",
  4709. tag, __func__);
  4710. goto Exit_2;
  4711. }
  4712. logError(0, "%s SET GPIOS:\n", tag);
  4713. retval = fts_set_gpio(info);
  4714. if (retval < 0) {
  4715. logError(1, "%s %s: ERROR Failed to set up GPIO's\n",
  4716. tag, __func__);
  4717. goto Exit_2;
  4718. }
  4719. info->client->irq = gpio_to_irq(info->bdata->irq_gpio);
  4720. retval = fts_pinctrl_init(info);
  4721. if (!retval && info->ts_pinctrl) {
  4722. /*
  4723. * Pinctrl handle is optional. If pinctrl handle is
  4724. * found let pins to be configured in active state.
  4725. * If not found continue further without error.
  4726. */
  4727. retval = pinctrl_select_state(info->ts_pinctrl,
  4728. info->pinctrl_state_active);
  4729. if (retval < 0) {
  4730. logError(1,
  4731. "%s: Failed to select %s pinstate %d\n",
  4732. __func__, PINCTRL_STATE_ACTIVE, retval);
  4733. }
  4734. }
  4735. #ifdef CONFIG_ARCH_QTI_VM
  4736. tvm_setup:
  4737. #endif
  4738. /* init hardware device */
  4739. logError(0, "%s Device Initialization:\n", tag);
  4740. error = fts_init(info);
  4741. if (error < OK) {
  4742. logError(1, "%s Cannot initialize the device ERROR %08X\n",
  4743. tag, error);
  4744. error = -ENODEV;
  4745. #ifdef CONFIG_ARCH_QTI_VM
  4746. return error;
  4747. #endif
  4748. goto Exit_3;
  4749. }
  4750. queue_delayed_work(info->fwu_workqueue, &info->fwu_work,
  4751. msecs_to_jiffies(EXP_FN_WORK_DELAY_MS));
  4752. return error;
  4753. Exit_3:
  4754. if (info->ts_pinctrl) {
  4755. if (IS_ERR_OR_NULL(info->pinctrl_state_release)) {
  4756. devm_pinctrl_put(info->ts_pinctrl);
  4757. info->ts_pinctrl = NULL;
  4758. } else {
  4759. if (pinctrl_select_state(info->ts_pinctrl,
  4760. info->pinctrl_state_release))
  4761. logError(1, "%s:Failed to select %s pinstate\n",
  4762. __func__, PINCTRL_STATE_RELEASE);
  4763. }
  4764. }
  4765. fts_enable_reg(info, false);
  4766. fts_gpio_setup(info->bdata->irq_gpio, false, 0, 0);
  4767. fts_gpio_setup(info->bdata->reset_gpio, false, 0, 0);
  4768. Exit_2:
  4769. fts_get_reg(info, false);
  4770. Exit_1:
  4771. return error;
  4772. }
  4773. static int fts_probe_internal(struct i2c_client *client,
  4774. const struct i2c_device_id *idp)
  4775. {
  4776. struct fts_ts_info *info = NULL;
  4777. int error = 0;
  4778. struct device_node *dp = client->dev.of_node;
  4779. int skip_5_1 = 0;
  4780. logError(0, "%s %s: driver probe begin!\n", tag, __func__);
  4781. if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
  4782. logError(1, "%s Unsupported I2C functionality\n", tag);
  4783. error = -EIO;
  4784. goto ProbeErrorExit_0;
  4785. }
  4786. openChannel(client);
  4787. info = kzalloc(sizeof(struct fts_ts_info), GFP_KERNEL);
  4788. if (!info) {
  4789. logError(1,
  4790. "%s can't allocate struct info!\n",
  4791. tag);
  4792. error = -ENOMEM;
  4793. goto ProbeErrorExit_0;
  4794. }
  4795. info->client = client;
  4796. i2c_set_clientdata(client, info);
  4797. info->i2c_data = kmalloc(I2C_DATA_MAX_LEN, GFP_KERNEL);
  4798. if (info->i2c_data == NULL) {
  4799. error = -ENOMEM;
  4800. goto ProbeErrorExit_0P1;
  4801. }
  4802. info->i2c_data_len = I2C_DATA_MAX_LEN;
  4803. logError(0, "%s i2c address: %x\n", tag, client->addr);
  4804. info->dev = &info->client->dev;
  4805. if (dp) {
  4806. info->bdata = devm_kzalloc(&client->dev,
  4807. sizeof(struct fts_i2c_platform_data),
  4808. GFP_KERNEL);
  4809. if (!info->bdata) {
  4810. logError(1, "%s ERROR:info.bdata kzalloc failed\n",
  4811. tag);
  4812. goto ProbeErrorExit_1;
  4813. }
  4814. parse_dt(&client->dev, info->bdata);
  4815. }
  4816. logError(0, "%s SET Auto Fw Update:\n", tag);
  4817. info->fwu_workqueue = alloc_workqueue("fts-fwu-queue",
  4818. WQ_UNBOUND|WQ_HIGHPRI|WQ_CPU_INTENSIVE, 1);
  4819. if (!info->fwu_workqueue) {
  4820. logError(1, "%s ERROR: Cannot create fwu work thread\n", tag);
  4821. goto ProbeErrorExit_1;
  4822. }
  4823. INIT_DELAYED_WORK(&info->fwu_work, fts_fw_update_auto);
  4824. logError(0, "%s SET Event Handler:\n", tag);
  4825. info->wakeup_source = wakeup_source_register(&client->dev,
  4826. dev_name(&client->dev));
  4827. info->event_wq = alloc_workqueue("fts-event-queue",
  4828. WQ_UNBOUND|WQ_HIGHPRI|WQ_CPU_INTENSIVE, 1);
  4829. if (!info->event_wq) {
  4830. logError(1, "%s ERROR: Cannot create work thread\n", tag);
  4831. error = -ENOMEM;
  4832. goto ProbeErrorExit_4;
  4833. }
  4834. INIT_WORK(&info->work, fts_event_handler);
  4835. INIT_WORK(&info->resume_work, fts_resume_work);
  4836. INIT_WORK(&info->suspend_work, fts_suspend_work);
  4837. logError(0, "%s SET Input Device Property:\n", tag);
  4838. /* info->dev = &info->client->dev; */
  4839. info->input_dev = input_allocate_device();
  4840. if (!info->input_dev) {
  4841. logError(1, "%s ERROR: No such input device defined!\n",
  4842. tag);
  4843. error = -ENODEV;
  4844. goto ProbeErrorExit_5;
  4845. }
  4846. info->input_dev->dev.parent = &client->dev;
  4847. info->input_dev->name = FTS_TS_DRV_NAME;
  4848. snprintf(fts_ts_phys, sizeof(fts_ts_phys), "%s/input0",
  4849. info->input_dev->name);
  4850. info->input_dev->phys = fts_ts_phys;
  4851. info->input_dev->id.bustype = BUS_I2C;
  4852. info->input_dev->id.vendor = 0x0001;
  4853. info->input_dev->id.product = 0x0002;
  4854. info->input_dev->id.version = 0x0100;
  4855. __set_bit(EV_SYN, info->input_dev->evbit);
  4856. __set_bit(EV_KEY, info->input_dev->evbit);
  4857. __set_bit(EV_ABS, info->input_dev->evbit);
  4858. __set_bit(BTN_TOUCH, info->input_dev->keybit);
  4859. __set_bit(BTN_TOOL_FINGER, info->input_dev->keybit);
  4860. input_mt_init_slots(info->input_dev, TOUCH_ID_MAX, INPUT_MT_DIRECT);
  4861. input_set_abs_params(info->input_dev, ABS_MT_POSITION_X,
  4862. X_AXIS_MIN, X_AXIS_MAX, 0, 0);
  4863. input_set_abs_params(info->input_dev, ABS_MT_POSITION_Y,
  4864. Y_AXIS_MIN, Y_AXIS_MAX, 0, 0);
  4865. input_set_abs_params(info->input_dev, ABS_MT_TOUCH_MAJOR,
  4866. AREA_MIN, AREA_MAX, 0, 0);
  4867. input_set_abs_params(info->input_dev, ABS_MT_TOUCH_MINOR,
  4868. AREA_MIN, AREA_MAX, 0, 0);
  4869. #ifdef PHONE_GESTURE
  4870. input_set_capability(info->input_dev, EV_KEY, KEY_WAKEUP);
  4871. input_set_capability(info->input_dev, EV_KEY, KEY_M);
  4872. input_set_capability(info->input_dev, EV_KEY, KEY_O);
  4873. input_set_capability(info->input_dev, EV_KEY, KEY_E);
  4874. input_set_capability(info->input_dev, EV_KEY, KEY_W);
  4875. input_set_capability(info->input_dev, EV_KEY, KEY_C);
  4876. input_set_capability(info->input_dev, EV_KEY, KEY_L);
  4877. input_set_capability(info->input_dev, EV_KEY, KEY_F);
  4878. input_set_capability(info->input_dev, EV_KEY, KEY_V);
  4879. input_set_capability(info->input_dev, EV_KEY, KEY_S);
  4880. input_set_capability(info->input_dev, EV_KEY, KEY_Z);
  4881. input_set_capability(info->input_dev, EV_KEY, KEY_WWW);
  4882. input_set_capability(info->input_dev, EV_KEY, KEY_LEFT);
  4883. input_set_capability(info->input_dev, EV_KEY, KEY_RIGHT);
  4884. input_set_capability(info->input_dev, EV_KEY, KEY_UP);
  4885. input_set_capability(info->input_dev, EV_KEY, KEY_DOWN);
  4886. input_set_capability(info->input_dev, EV_KEY, KEY_F1);
  4887. input_set_capability(info->input_dev, EV_KEY, KEY_F2);
  4888. input_set_capability(info->input_dev, EV_KEY, KEY_F3);
  4889. input_set_capability(info->input_dev, EV_KEY, KEY_F4);
  4890. input_set_capability(info->input_dev, EV_KEY, KEY_F5);
  4891. input_set_capability(info->input_dev, EV_KEY, KEY_LEFTBRACE);
  4892. input_set_capability(info->input_dev, EV_KEY, KEY_RIGHTBRACE);
  4893. #endif
  4894. #ifdef PHONE_KEY
  4895. /* KEY associated to the touch screen buttons */
  4896. input_set_capability(info->input_dev, EV_KEY, KEY_HOMEPAGE);
  4897. input_set_capability(info->input_dev, EV_KEY, KEY_BACK);
  4898. input_set_capability(info->input_dev, EV_KEY, KEY_MENU);
  4899. #endif
  4900. mutex_init(&(info->input_report_mutex));
  4901. #ifdef PHONE_GESTURE
  4902. mutex_init(&gestureMask_mutex);
  4903. #endif
  4904. /* register the multi-touch input device */
  4905. error = input_register_device(info->input_dev);
  4906. if (error) {
  4907. logError(1, "%s ERROR: No such input device\n", tag);
  4908. error = -ENODEV;
  4909. goto ProbeErrorExit_5_1;
  4910. }
  4911. skip_5_1 = 1;
  4912. /* track slots */
  4913. info->touch_id = 0;
  4914. #ifdef STYLUS_MODE
  4915. info->stylus_id = 0;
  4916. #endif
  4917. /*
  4918. * init feature switches (by default all the features
  4919. * are disable, if one feature want to be enabled from
  4920. * the start, set the corresponding value to 1)
  4921. */
  4922. info->gesture_enabled = 0;
  4923. info->glove_enabled = 0;
  4924. info->charger_enabled = 0;
  4925. info->stylus_enabled = 0;
  4926. info->vr_enabled = 0;
  4927. info->cover_enabled = 0;
  4928. info->edge_rej_enabled = 0;
  4929. info->corner_rej_enabled = 0;
  4930. info->edge_palm_rej_enabled = 0;
  4931. info->resume_bit = 1;
  4932. info->notifier = fts_noti_block;
  4933. #ifdef CONFIG_ST_TRUSTED_TOUCH
  4934. fts_trusted_touch_init(info);
  4935. mutex_init(&(info->fts_clk_io_ctrl_mutex));
  4936. #endif
  4937. logError(0, "%s SET Device File Nodes:\n", tag);
  4938. /* sysfs stuff */
  4939. info->attrs.attrs = fts_attr_group;
  4940. error = sysfs_create_group(&client->dev.kobj, &info->attrs);
  4941. if (error) {
  4942. logError(1, "%s ERROR: Cannot create sysfs structure!\n", tag);
  4943. error = -ENODEV;
  4944. goto ProbeErrorExit_7;
  4945. }
  4946. /* I2C cmd */
  4947. fts_cmd_class = class_create(THIS_MODULE, FTS_TS_DRV_NAME);
  4948. #ifdef SCRIPTLESS
  4949. info->i2c_cmd_dev = device_create(fts_cmd_class,
  4950. NULL, DCHIP_ID_0, info, "fts_i2c");
  4951. if (IS_ERR(info->i2c_cmd_dev)) {
  4952. logError(1,
  4953. "%s ERROR: Failed to create device for the sysfs!\n",
  4954. tag);
  4955. goto ProbeErrorExit_8;
  4956. }
  4957. dev_set_drvdata(info->i2c_cmd_dev, info);
  4958. error = sysfs_create_group(&info->i2c_cmd_dev->kobj,
  4959. &i2c_cmd_attr_group);
  4960. if (error) {
  4961. logError(1, "%s ERROR: Failed to create sysfs group!\n", tag);
  4962. goto ProbeErrorExit_9;
  4963. }
  4964. #endif
  4965. #ifdef DRIVER_TEST
  4966. info->test_cmd_dev = device_create(fts_cmd_class,
  4967. NULL, DCHIP_ID_0, info, "fts_driver_test");
  4968. if (IS_ERR(info->test_cmd_dev)) {
  4969. logError(1,
  4970. "%s ERROR: Failed to create device for the sysfs!\n",
  4971. tag);
  4972. goto ProbeErrorExit_10;
  4973. }
  4974. dev_set_drvdata(info->test_cmd_dev, info);
  4975. error = sysfs_create_group(&info->test_cmd_dev->kobj,
  4976. &test_cmd_attr_group);
  4977. if (error) {
  4978. logError(1, "%s ERROR: Failed to create sysfs group!\n", tag);
  4979. goto ProbeErrorExit_11;
  4980. }
  4981. #endif
  4982. info->aoi_cmd_dev = device_create(fts_cmd_class,
  4983. NULL, DCHIP_ID_0, info, "touch_aoi");
  4984. if (IS_ERR(info->aoi_cmd_dev)) {
  4985. logError(1,
  4986. "%s ERROR: Failed to create device for the sysfs\n",
  4987. tag);
  4988. goto ProbeErrorExit_10;
  4989. }
  4990. dev_set_drvdata(info->aoi_cmd_dev, info);
  4991. error = sysfs_create_group(&info->aoi_cmd_dev->kobj,
  4992. &aoi_cmd_attr_group);
  4993. if (error) {
  4994. logError(1, "%s ERROR: Failed to create sysfs group\n", tag);
  4995. goto ProbeErrorExit_11;
  4996. }
  4997. info->aoi_class = class_create(THIS_MODULE, "android_touch");
  4998. if (info->aoi_class) {
  4999. info->aoi_dev = device_create(info->aoi_class,
  5000. NULL, DCHIP_ID_0, info, "touch");
  5001. if (!IS_ERR(info->aoi_dev)) {
  5002. dev_set_drvdata(info->aoi_dev, info);
  5003. error = sysfs_create_group(&info->aoi_dev->kobj,
  5004. &aoi_enable_attr_group);
  5005. }
  5006. }
  5007. error = fts_probe_delayed(info);
  5008. if (error) {
  5009. logError(1, "%s ERROR: Failed to enable resources\n",
  5010. tag);
  5011. goto ProbeErrorExit_11;
  5012. }
  5013. logError(1, "%s Probe Finished!\n", tag);
  5014. return OK;
  5015. /* error exit path */
  5016. #ifdef DRIVER_TEST
  5017. ProbeErrorExit_11:
  5018. #ifndef SCRIPTLESS
  5019. device_destroy(fts_cmd_class, DCHIP_ID_0);
  5020. #endif
  5021. ProbeErrorExit_10:
  5022. #ifndef SCRIPTLESS
  5023. sysfs_remove_group(&client->dev.kobj, &info->attrs);
  5024. #endif
  5025. #endif
  5026. #ifdef SCRIPTLESS
  5027. ProbeErrorExit_9:
  5028. device_destroy(fts_cmd_class, DCHIP_ID_0);
  5029. ProbeErrorExit_8:
  5030. sysfs_remove_group(&client->dev.kobj, &info->attrs);
  5031. #endif
  5032. ProbeErrorExit_7:
  5033. #ifdef CONFIG_ST_TRUSTED_TOUCH
  5034. fts_vm_deinit(info);
  5035. #endif
  5036. /* fb_unregister_client(&info->notifier); */
  5037. input_unregister_device(info->input_dev);
  5038. ProbeErrorExit_5_1:
  5039. if (skip_5_1 != 1)
  5040. input_free_device(info->input_dev);
  5041. ProbeErrorExit_5:
  5042. destroy_workqueue(info->event_wq);
  5043. ProbeErrorExit_4:
  5044. destroy_workqueue(info->fwu_workqueue);
  5045. wakeup_source_unregister(info->wakeup_source);
  5046. ProbeErrorExit_1:
  5047. kfree(info->i2c_data);
  5048. ProbeErrorExit_0P1:
  5049. kfree(info);
  5050. ProbeErrorExit_0:
  5051. logError(1, "%s Probe Failed!\n", tag);
  5052. return error;
  5053. }
  5054. static int fts_probe(struct i2c_client *client, const struct i2c_device_id *idp)
  5055. {
  5056. int error = 0;
  5057. struct device_node *dp = client->dev.of_node;
  5058. error = check_dt(dp);
  5059. if (error == -EPROBE_DEFER)
  5060. return error;
  5061. if (error) {
  5062. if (!check_default_tp(dp, "qcom,i2c-touch-active"))
  5063. error = -EPROBE_DEFER;
  5064. else
  5065. error = -ENODEV;
  5066. return error;
  5067. }
  5068. device_init_wakeup(&client->dev, true);
  5069. return fts_probe_internal(client, idp);
  5070. }
  5071. static int fts_remove(struct i2c_client *client)
  5072. {
  5073. struct fts_ts_info *info = i2c_get_clientdata(client);
  5074. if (info->aoi_dev) {
  5075. sysfs_remove_group(&info->aoi_dev->kobj,
  5076. &aoi_enable_attr_group);
  5077. info->aoi_dev = NULL;
  5078. }
  5079. if (info->aoi_class) {
  5080. device_destroy(info->aoi_class, DCHIP_ID_0);
  5081. info->aoi_class = NULL;
  5082. }
  5083. #ifdef DRIVER_TEST
  5084. sysfs_remove_group(&info->test_cmd_dev->kobj,
  5085. &test_cmd_attr_group);
  5086. #endif
  5087. #ifdef SCRIPTLESS
  5088. /* I2C cmd */
  5089. sysfs_remove_group(&info->i2c_cmd_dev->kobj, &i2c_cmd_attr_group);
  5090. #endif
  5091. #if defined(SCRIPTLESS) || defined(DRIVER_TEST)
  5092. device_destroy(fts_cmd_class, DCHIP_ID_0);
  5093. #endif
  5094. /* sysfs stuff */
  5095. sysfs_remove_group(&client->dev.kobj, &info->attrs);
  5096. /* remove interrupt and event handlers */
  5097. fts_interrupt_uninstall(info);
  5098. #if defined(CONFIG_FB_MSM)
  5099. fb_unregister_client(&info->notifier);
  5100. #else
  5101. if (active_panel)
  5102. drm_panel_notifier_register(active_panel, &info->notifier);
  5103. #endif
  5104. /* unregister the device */
  5105. input_unregister_device(info->input_dev);
  5106. /* input_free_device(info->input_dev ); */
  5107. /* Empty the FIFO buffer */
  5108. fts_command(info, FIFO_CMD_FLUSH);
  5109. /* flushFIFO(); */
  5110. /* Remove the work thread */
  5111. destroy_workqueue(info->event_wq);
  5112. /* wake_lock_destroy(&info->wakelock); */
  5113. wakeup_source_unregister(info->wakeup_source);
  5114. destroy_workqueue(info->fwu_workqueue);
  5115. if (info->ts_pinctrl) {
  5116. if (IS_ERR_OR_NULL(info->pinctrl_state_release)) {
  5117. devm_pinctrl_put(info->ts_pinctrl);
  5118. info->ts_pinctrl = NULL;
  5119. } else {
  5120. pinctrl_select_state(info->ts_pinctrl,
  5121. info->pinctrl_state_release);
  5122. }
  5123. }
  5124. fts_enable_reg(info, false);
  5125. fts_gpio_setup(info->bdata->irq_gpio, false, 0, 0);
  5126. fts_gpio_setup(info->bdata->reset_gpio, false, 0, 0);
  5127. fts_get_reg(info, false);
  5128. /* free all */
  5129. kfree(info->i2c_data);
  5130. kfree(info);
  5131. device_init_wakeup(&client->dev, false);
  5132. return OK;
  5133. }
  5134. static const struct of_device_id fts_of_match_table[] = {
  5135. {
  5136. .compatible = "st,fts",
  5137. },
  5138. {},
  5139. };
  5140. static const struct i2c_device_id fts_device_id[] = {
  5141. {FTS_TS_DRV_NAME, 0},
  5142. {}
  5143. };
  5144. static struct i2c_driver fts_i2c_driver = {
  5145. .driver = {
  5146. .name = FTS_TS_DRV_NAME,
  5147. .of_match_table = fts_of_match_table,
  5148. },
  5149. .probe = fts_probe,
  5150. .remove = fts_remove,
  5151. .id_table = fts_device_id,
  5152. };
  5153. static int __init fts_driver_init(void)
  5154. {
  5155. return i2c_add_driver(&fts_i2c_driver);
  5156. }
  5157. static void __exit fts_driver_exit(void)
  5158. {
  5159. i2c_del_driver(&fts_i2c_driver);
  5160. }
  5161. module_init(fts_driver_init);
  5162. module_exit(fts_driver_exit);
  5163. MODULE_DESCRIPTION("STMicroelectronics MultiTouch IC Driver");
  5164. MODULE_LICENSE("GPL v2");