fts.c 150 KB

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