ipts.patch 189 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108
  1. diff --git a/Documentation/devicetree/bindings/input/hid-over-i2c.txt b/Documentation/devicetree/bindings/input/hid-over-i2c.txt
  2. index 28e8bd8..4d3da9d 100644
  3. --- a/Documentation/devicetree/bindings/input/hid-over-i2c.txt
  4. +++ b/Documentation/devicetree/bindings/input/hid-over-i2c.txt
  5. @@ -31,7 +31,7 @@ device-specific compatible properties, which should be used in addition to the
  6. - vdd-supply: phandle of the regulator that provides the supply voltage.
  7. - post-power-on-delay-ms: time required by the device after enabling its regulators
  8. - before it is ready for communication. Must be used with 'vdd-supply'.
  9. + or powering it on, before it is ready for communication.
  10. Example:
  11. diff --git a/drivers/gpu/drm/i915/Makefile b/drivers/gpu/drm/i915/Makefile
  12. index 2e034ef..635b8c6 100644
  13. --- a/drivers/gpu/drm/i915/Makefile
  14. +++ b/drivers/gpu/drm/i915/Makefile
  15. @@ -120,6 +120,9 @@ i915-y += dvo_ch7017.o \
  16. intel_sdvo.o \
  17. intel_tv.o
  18. +# intel precise touch & stylus
  19. +i915-y += intel_ipts.o
  20. +
  21. # Post-mortem debug and GPU hang state capture
  22. i915-$(CONFIG_DRM_I915_CAPTURE_ERROR) += i915_gpu_error.o
  23. i915-$(CONFIG_DRM_I915_SELFTEST) += \
  24. diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
  25. index 562220e..bd9cb5c 100644
  26. --- a/drivers/gpu/drm/i915/i915_drv.c
  27. +++ b/drivers/gpu/drm/i915/i915_drv.c
  28. @@ -51,6 +51,7 @@
  29. #include "i915_vgpu.h"
  30. #include "intel_drv.h"
  31. #include "intel_uc.h"
  32. +#include "intel_ipts.h"
  33. static struct drm_driver driver;
  34. @@ -679,6 +680,9 @@ static int i915_load_modeset_init(struct drm_device *dev)
  35. drm_kms_helper_poll_init(dev);
  36. + if (INTEL_GEN(dev_priv) >= 9 && i915.enable_guc_submission)
  37. + intel_ipts_init(dev);
  38. +
  39. return 0;
  40. cleanup_gem:
  41. @@ -1373,6 +1377,9 @@ void i915_driver_unload(struct drm_device *dev)
  42. struct drm_i915_private *dev_priv = to_i915(dev);
  43. struct pci_dev *pdev = dev_priv->drm.pdev;
  44. + if (INTEL_GEN(dev_priv) >= 9 && i915.enable_guc_submission)
  45. + intel_ipts_cleanup(dev);
  46. +
  47. i915_driver_unregister(dev_priv);
  48. if (i915_gem_suspend(dev_priv))
  49. diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
  50. index 3f81841..8038f63 100644
  51. --- a/drivers/gpu/drm/i915/i915_drv.h
  52. +++ b/drivers/gpu/drm/i915/i915_drv.h
  53. @@ -3659,6 +3659,9 @@ void i915_gem_object_do_bit_17_swizzle(struct drm_i915_gem_object *obj,
  54. void i915_gem_object_save_bit_17_swizzle(struct drm_i915_gem_object *obj,
  55. struct sg_table *pages);
  56. +struct i915_gem_context *
  57. +i915_gem_context_create_ipts(struct drm_device *dev);
  58. +
  59. static inline struct i915_gem_context *
  60. __i915_gem_context_lookup_rcu(struct drm_i915_file_private *file_priv, u32 id)
  61. {
  62. diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
  63. index 3b2c053..d305bf0 100644
  64. --- a/drivers/gpu/drm/i915/i915_gem.c
  65. +++ b/drivers/gpu/drm/i915/i915_gem.c
  66. @@ -179,7 +179,7 @@ i915_gem_object_get_pages_phys(struct drm_i915_gem_object *obj)
  67. * the alignment of the buddy allocation will naturally match.
  68. */
  69. phys = drm_pci_alloc(obj->base.dev,
  70. - obj->base.size,
  71. + roundup_pow_of_two(obj->base.size),
  72. roundup_pow_of_two(obj->base.size));
  73. if (!phys)
  74. return ERR_PTR(-ENOMEM);
  75. diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c
  76. index 8afd2ce..00871aa 100644
  77. --- a/drivers/gpu/drm/i915/i915_gem_context.c
  78. +++ b/drivers/gpu/drm/i915/i915_gem_context.c
  79. @@ -418,6 +418,18 @@ i915_gem_context_create_gvt(struct drm_device *dev)
  80. return ctx;
  81. }
  82. +struct i915_gem_context *i915_gem_context_create_ipts(struct drm_device *dev)
  83. +{
  84. + struct drm_i915_private *dev_priv = dev->dev_private;
  85. + struct i915_gem_context *ctx;
  86. +
  87. + BUG_ON(!mutex_is_locked(&dev->struct_mutex));
  88. +
  89. + ctx = i915_gem_create_context(dev_priv, NULL);
  90. +
  91. + return ctx;
  92. +}
  93. +
  94. int i915_gem_contexts_init(struct drm_i915_private *dev_priv)
  95. {
  96. struct i915_gem_context *ctx;
  97. diff --git a/drivers/gpu/drm/i915/i915_guc_submission.c b/drivers/gpu/drm/i915/i915_guc_submission.c
  98. index 48a1e93..75b5cc2 100644
  99. --- a/drivers/gpu/drm/i915/i915_guc_submission.c
  100. +++ b/drivers/gpu/drm/i915/i915_guc_submission.c
  101. @@ -87,6 +87,7 @@ static inline bool is_high_priority(struct i915_guc_client* client)
  102. static int __reserve_doorbell(struct i915_guc_client *client)
  103. {
  104. + struct drm_i915_private *dev_priv = guc_to_i915(client->guc);
  105. unsigned long offset;
  106. unsigned long end;
  107. u16 id;
  108. @@ -99,10 +100,15 @@ static int __reserve_doorbell(struct i915_guc_client *client)
  109. * priority contexts, the second half for high-priority ones.
  110. */
  111. offset = 0;
  112. - end = GUC_NUM_DOORBELLS/2;
  113. - if (is_high_priority(client)) {
  114. - offset = end;
  115. - end += offset;
  116. + if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) {
  117. + end = GUC_NUM_DOORBELLS;
  118. + }
  119. + else {
  120. + end = GUC_NUM_DOORBELLS/2;
  121. + if (is_high_priority(client)) {
  122. + offset = end;
  123. + end += offset;
  124. + }
  125. }
  126. id = find_next_zero_bit(client->guc->doorbell_bitmap, end, offset);
  127. @@ -331,7 +337,14 @@ static void guc_stage_desc_init(struct intel_guc *guc,
  128. desc = __get_stage_desc(client);
  129. memset(desc, 0, sizeof(*desc));
  130. - desc->attribute = GUC_STAGE_DESC_ATTR_ACTIVE | GUC_STAGE_DESC_ATTR_KERNEL;
  131. + desc->attribute = GUC_STAGE_DESC_ATTR_ACTIVE;
  132. + if ((client->priority == GUC_CLIENT_PRIORITY_KMD_NORMAL) ||
  133. + (client->priority == GUC_CLIENT_PRIORITY_KMD_HIGH)) {
  134. + desc->attribute |= GUC_STAGE_DESC_ATTR_KERNEL;
  135. + } else {
  136. + desc->attribute |= GUC_STAGE_DESC_ATTR_PCH;
  137. + }
  138. +
  139. desc->stage_id = client->stage_id;
  140. desc->priority = client->priority;
  141. desc->db_id = client->doorbell_id;
  142. @@ -1159,7 +1172,8 @@ static void guc_interrupts_capture(struct drm_i915_private *dev_priv)
  143. I915_WRITE(RING_MODE_GEN7(engine), irqs);
  144. /* route USER_INTERRUPT to Host, all others are sent to GuC. */
  145. - irqs = GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
  146. + irqs = (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT)
  147. + << GEN8_RCS_IRQ_SHIFT |
  148. GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT;
  149. /* These three registers have the same bit definitions */
  150. I915_WRITE(GUC_BCS_RCS_IER, ~irqs);
  151. @@ -1340,3 +1354,47 @@ int intel_guc_resume(struct drm_i915_private *dev_priv)
  152. return intel_guc_send(guc, data, ARRAY_SIZE(data));
  153. }
  154. +
  155. +int i915_guc_ipts_submission_enable(struct drm_i915_private *dev_priv,
  156. + struct i915_gem_context *ctx)
  157. +{
  158. + struct intel_guc *guc = &dev_priv->guc;
  159. + struct i915_guc_client *client;
  160. +
  161. + /* client for execbuf submission */
  162. + client = guc_client_alloc(dev_priv,
  163. + INTEL_INFO(dev_priv)->ring_mask,
  164. + IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ? GUC_CLIENT_PRIORITY_HIGH : GUC_CLIENT_PRIORITY_NORMAL,
  165. + ctx);
  166. + if (!client) {
  167. + DRM_ERROR("Failed to create normal GuC client!\n");
  168. + return -ENOMEM;
  169. + }
  170. +
  171. + guc->ipts_client = client;
  172. + intel_guc_sample_forcewake(guc);
  173. + guc_init_doorbell_hw(guc);
  174. +
  175. + return 0;
  176. +}
  177. +
  178. +void i915_guc_ipts_submission_disable(struct drm_i915_private *dev_priv)
  179. +{
  180. + struct intel_guc *guc = &dev_priv->guc;
  181. +
  182. + if (!guc->ipts_client)
  183. + return;
  184. +
  185. + guc_client_free(guc->ipts_client);
  186. + guc->ipts_client = NULL;
  187. +}
  188. +
  189. +void i915_guc_ipts_reacquire_doorbell(struct drm_i915_private *dev_priv)
  190. +{
  191. + struct intel_guc *guc = &dev_priv->guc;
  192. +
  193. + int err = __guc_allocate_doorbell(guc, guc->ipts_client->stage_id);
  194. +
  195. + if (err)
  196. + DRM_ERROR("Not able to reacquire IPTS doorbell\n");
  197. +}
  198. diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
  199. index b63893e..5a0313b 100644
  200. --- a/drivers/gpu/drm/i915/i915_irq.c
  201. +++ b/drivers/gpu/drm/i915/i915_irq.c
  202. @@ -36,6 +36,7 @@
  203. #include "i915_drv.h"
  204. #include "i915_trace.h"
  205. #include "intel_drv.h"
  206. +#include "intel_ipts.h"
  207. /**
  208. * DOC: interrupt handling
  209. @@ -1319,6 +1320,9 @@ gen8_cs_irq_handler(struct intel_engine_cs *engine, u32 iir, int test_shift)
  210. tasklet |= i915.enable_guc_submission;
  211. }
  212. + if (iir & (GT_RENDER_PIPECTL_NOTIFY_INTERRUPT << test_shift))
  213. + intel_ipts_notify_complete();
  214. +
  215. if (tasklet)
  216. tasklet_hi_schedule(&engine->irq_tasklet);
  217. }
  218. @@ -3391,7 +3395,8 @@ static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv)
  219. {
  220. /* These are interrupts we'll toggle with the ring mask register */
  221. uint32_t gt_interrupts[] = {
  222. - GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
  223. + GT_RENDER_PIPECTL_NOTIFY_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
  224. + GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
  225. GT_CONTEXT_SWITCH_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
  226. GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT |
  227. GT_CONTEXT_SWITCH_INTERRUPT << GEN8_BCS_IRQ_SHIFT,
  228. diff --git a/drivers/gpu/drm/i915/i915_params.c b/drivers/gpu/drm/i915/i915_params.c
  229. index 8ab003d..3cb1ac4 100644
  230. --- a/drivers/gpu/drm/i915/i915_params.c
  231. +++ b/drivers/gpu/drm/i915/i915_params.c
  232. @@ -35,7 +35,7 @@ struct i915_params i915 __read_mostly = {
  233. .enable_rc6 = -1,
  234. .enable_dc = -1,
  235. .enable_fbc = -1,
  236. - .enable_execlists = -1,
  237. + .enable_execlists = 0,
  238. .enable_hangcheck = true,
  239. .enable_ppgtt = -1,
  240. .enable_psr = -1,
  241. @@ -56,8 +56,8 @@ struct i915_params i915 __read_mostly = {
  242. .verbose_state_checks = 1,
  243. .nuclear_pageflip = 0,
  244. .edp_vswing = 0,
  245. - .enable_guc_loading = 0,
  246. - .enable_guc_submission = 0,
  247. + .enable_guc_loading = 1,
  248. + .enable_guc_submission = 1,
  249. .guc_log_level = -1,
  250. .guc_firmware_path = NULL,
  251. .huc_firmware_path = NULL,
  252. @@ -144,7 +144,7 @@ MODULE_PARM_DESC(enable_ppgtt,
  253. module_param_named_unsafe(enable_execlists, i915.enable_execlists, int, 0400);
  254. MODULE_PARM_DESC(enable_execlists,
  255. "Override execlists usage. "
  256. - "(-1=auto [default], 0=disabled, 1=enabled)");
  257. + "(-1=auto, 0=disabled [default], 1=enabled)");
  258. module_param_named_unsafe(enable_psr, i915.enable_psr, int, 0600);
  259. MODULE_PARM_DESC(enable_psr, "Enable PSR "
  260. @@ -225,12 +225,12 @@ MODULE_PARM_DESC(edp_vswing,
  261. module_param_named_unsafe(enable_guc_loading, i915.enable_guc_loading, int, 0400);
  262. MODULE_PARM_DESC(enable_guc_loading,
  263. "Enable GuC firmware loading "
  264. - "(-1=auto, 0=never [default], 1=if available, 2=required)");
  265. + "(-1=auto, 0=never, 1=if available [default], 2=required)");
  266. module_param_named_unsafe(enable_guc_submission, i915.enable_guc_submission, int, 0400);
  267. MODULE_PARM_DESC(enable_guc_submission,
  268. "Enable GuC submission "
  269. - "(-1=auto, 0=never [default], 1=if available, 2=required)");
  270. + "(-1=auto, 0=never, 1=if available [default], 2=required)");
  271. module_param_named(guc_log_level, i915.guc_log_level, int, 0400);
  272. MODULE_PARM_DESC(guc_log_level,
  273. diff --git a/drivers/gpu/drm/i915/intel_ipts.c b/drivers/gpu/drm/i915/intel_ipts.c
  274. new file mode 100644
  275. index 0000000..f5fa111
  276. --- /dev/null
  277. +++ b/drivers/gpu/drm/i915/intel_ipts.c
  278. @@ -0,0 +1,626 @@
  279. +/*
  280. + * Copyright 2016 Intel Corporation
  281. + *
  282. + * Permission is hereby granted, free of charge, to any person obtaining a
  283. + * copy of this software and associated documentation files (the "Software"),
  284. + * to deal in the Software without restriction, including without limitation
  285. + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  286. + * and/or sell copies of the Software, and to permit persons to whom the
  287. + * Software is furnished to do so, subject to the following conditions:
  288. + *
  289. + * The above copyright notice and this permission notice (including the next
  290. + * paragraph) shall be included in all copies or substantial portions of the
  291. + * Software.
  292. + *
  293. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  294. + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  295. + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  296. + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  297. + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  298. + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  299. + * IN THE SOFTWARE.
  300. + *
  301. + */
  302. +#include <linux/kernel.h>
  303. +#include <linux/types.h>
  304. +#include <linux/module.h>
  305. +#include <linux/intel_ipts_if.h>
  306. +#include <drm/drmP.h>
  307. +
  308. +#include "i915_drv.h"
  309. +
  310. +#define SUPPORTED_IPTS_INTERFACE_VERSION 1
  311. +
  312. +#define REACQUIRE_DB_THRESHOLD 8
  313. +#define DB_LOST_CHECK_STEP1_INTERVAL 2000 /* ms */
  314. +#define DB_LOST_CHECK_STEP2_INTERVAL 500 /* ms */
  315. +
  316. +/* intel IPTS ctx for ipts support */
  317. +typedef struct intel_ipts {
  318. + struct drm_device *dev;
  319. + struct i915_gem_context *ipts_context;
  320. + intel_ipts_callback_t ipts_clbks;
  321. +
  322. + /* buffers' list */
  323. + struct {
  324. + spinlock_t lock;
  325. + struct list_head list;
  326. + } buffers;
  327. +
  328. + void *data;
  329. +
  330. + struct delayed_work reacquire_db_work;
  331. + intel_ipts_wq_info_t wq_info;
  332. + u32 old_tail;
  333. + u32 old_head;
  334. + bool need_reacquire_db;
  335. +
  336. + bool connected;
  337. + bool initialized;
  338. +} intel_ipts_t;
  339. +
  340. +intel_ipts_t intel_ipts;
  341. +
  342. +typedef struct intel_ipts_object {
  343. + struct list_head list;
  344. + struct drm_i915_gem_object *gem_obj;
  345. + void *cpu_addr;
  346. +} intel_ipts_object_t;
  347. +
  348. +static intel_ipts_object_t *ipts_object_create(size_t size, u32 flags)
  349. +{
  350. + struct drm_i915_private *dev_priv = to_i915(intel_ipts.dev);
  351. + intel_ipts_object_t *obj = NULL;
  352. + struct drm_i915_gem_object *gem_obj = NULL;
  353. + int ret = 0;
  354. +
  355. + obj = kzalloc(sizeof(*obj), GFP_KERNEL);
  356. + if (!obj)
  357. + return NULL;
  358. +
  359. + size = roundup(size, PAGE_SIZE);
  360. + if (size == 0) {
  361. + ret = -EINVAL;
  362. + goto err_out;
  363. + }
  364. +
  365. + /* Allocate the new object */
  366. + gem_obj = i915_gem_object_create(dev_priv, size);
  367. + if (gem_obj == NULL) {
  368. + ret = -ENOMEM;
  369. + goto err_out;
  370. + }
  371. +
  372. + if (flags & IPTS_BUF_FLAG_CONTIGUOUS) {
  373. + ret = i915_gem_object_attach_phys(gem_obj, PAGE_SIZE);
  374. + if (ret) {
  375. + pr_info(">> ipts no contiguous : %d\n", ret);
  376. + goto err_out;
  377. + }
  378. + }
  379. +
  380. + obj->gem_obj = gem_obj;
  381. +
  382. + spin_lock(&intel_ipts.buffers.lock);
  383. + list_add_tail(&obj->list, &intel_ipts.buffers.list);
  384. + spin_unlock(&intel_ipts.buffers.lock);
  385. +
  386. + return obj;
  387. +
  388. +err_out:
  389. + if (gem_obj)
  390. + i915_gem_free_object(&gem_obj->base);
  391. +
  392. + if (obj)
  393. + kfree(obj);
  394. +
  395. + return NULL;
  396. +}
  397. +
  398. +static void ipts_object_free(intel_ipts_object_t* obj)
  399. +{
  400. + spin_lock(&intel_ipts.buffers.lock);
  401. + list_del(&obj->list);
  402. + spin_unlock(&intel_ipts.buffers.lock);
  403. +
  404. + i915_gem_free_object(&obj->gem_obj->base);
  405. + kfree(obj);
  406. +}
  407. +
  408. +static int ipts_object_pin(intel_ipts_object_t* obj,
  409. + struct i915_gem_context *ipts_ctx)
  410. +{
  411. + struct i915_address_space *vm = NULL;
  412. + struct i915_vma *vma = NULL;
  413. + struct drm_i915_private *dev_priv = to_i915(intel_ipts.dev);
  414. + int ret = 0;
  415. +
  416. + if (ipts_ctx->ppgtt) {
  417. + vm = &ipts_ctx->ppgtt->base;
  418. + } else {
  419. + vm = &dev_priv->ggtt.base;
  420. + }
  421. +
  422. + vma = i915_vma_instance(obj->gem_obj, vm, NULL);
  423. + if (IS_ERR(vma)) {
  424. + DRM_ERROR("cannot find or create vma\n");
  425. + return -1;
  426. + }
  427. +
  428. + ret = i915_vma_pin(vma, 0, PAGE_SIZE, PIN_USER);
  429. +
  430. + return ret;
  431. +}
  432. +
  433. +static void ipts_object_unpin(intel_ipts_object_t *obj)
  434. +{
  435. + /* TBD: Add support */
  436. +}
  437. +
  438. +static void* ipts_object_map(intel_ipts_object_t *obj)
  439. +{
  440. +
  441. + return i915_gem_object_pin_map(obj->gem_obj, I915_MAP_WB);
  442. +}
  443. +
  444. +static void ipts_object_unmap(intel_ipts_object_t* obj)
  445. +{
  446. + i915_gem_object_unpin_map(obj->gem_obj);
  447. + obj->cpu_addr = NULL;
  448. +}
  449. +
  450. +static int create_ipts_context(void)
  451. +{
  452. + struct i915_gem_context *ipts_ctx = NULL;
  453. + struct drm_i915_private *dev_priv = to_i915(intel_ipts.dev);
  454. + struct intel_ring *pin_ret;
  455. + int ret = 0;
  456. +
  457. + /* Initialize the context right away.*/
  458. + ret = i915_mutex_lock_interruptible(intel_ipts.dev);
  459. + if (ret) {
  460. + DRM_ERROR("i915_mutex_lock_interruptible failed \n");
  461. + return ret;
  462. + }
  463. +
  464. + ipts_ctx = i915_gem_context_create_ipts(intel_ipts.dev);
  465. + if (IS_ERR(ipts_ctx)) {
  466. + DRM_ERROR("Failed to create IPTS context (error %ld)\n",
  467. + PTR_ERR(ipts_ctx));
  468. + ret = PTR_ERR(ipts_ctx);
  469. + goto err_unlock;
  470. + }
  471. +
  472. + ret = execlists_context_deferred_alloc(ipts_ctx, dev_priv->engine[RCS]);
  473. + if (ret) {
  474. + DRM_DEBUG("lr context allocation failed : %d\n", ret);
  475. + goto err_ctx;
  476. + }
  477. +
  478. + pin_ret = execlists_context_pin(dev_priv->engine[RCS], ipts_ctx);
  479. + if (IS_ERR(pin_ret)) {
  480. + DRM_DEBUG("lr context pinning failed : %ld\n", PTR_ERR(pin_ret));
  481. + goto err_ctx;
  482. + }
  483. +
  484. + /* Release the mutex */
  485. + mutex_unlock(&intel_ipts.dev->struct_mutex);
  486. +
  487. + spin_lock_init(&intel_ipts.buffers.lock);
  488. + INIT_LIST_HEAD(&intel_ipts.buffers.list);
  489. +
  490. + intel_ipts.ipts_context = ipts_ctx;
  491. +
  492. + return 0;
  493. +
  494. +err_ctx:
  495. + if (ipts_ctx)
  496. + i915_gem_context_put(ipts_ctx);
  497. +
  498. +err_unlock:
  499. + mutex_unlock(&intel_ipts.dev->struct_mutex);
  500. +
  501. + return ret;
  502. +}
  503. +
  504. +static void destroy_ipts_context(void)
  505. +{
  506. + struct i915_gem_context *ipts_ctx = NULL;
  507. + struct drm_i915_private *dev_priv = to_i915(intel_ipts.dev);
  508. + int ret = 0;
  509. +
  510. + ipts_ctx = intel_ipts.ipts_context;
  511. +
  512. + /* Initialize the context right away.*/
  513. + ret = i915_mutex_lock_interruptible(intel_ipts.dev);
  514. + if (ret) {
  515. + DRM_ERROR("i915_mutex_lock_interruptible failed \n");
  516. + return;
  517. + }
  518. +
  519. + execlists_context_unpin(dev_priv->engine[RCS], ipts_ctx);
  520. + i915_gem_context_put(ipts_ctx);
  521. +
  522. + mutex_unlock(&intel_ipts.dev->struct_mutex);
  523. +}
  524. +
  525. +int intel_ipts_notify_complete(void)
  526. +{
  527. + if (intel_ipts.ipts_clbks.workload_complete)
  528. + intel_ipts.ipts_clbks.workload_complete(intel_ipts.data);
  529. +
  530. + return 0;
  531. +}
  532. +
  533. +int intel_ipts_notify_backlight_status(bool backlight_on)
  534. +{
  535. + if (intel_ipts.ipts_clbks.notify_gfx_status) {
  536. + if (backlight_on) {
  537. + intel_ipts.ipts_clbks.notify_gfx_status(
  538. + IPTS_NOTIFY_STA_BACKLIGHT_ON,
  539. + intel_ipts.data);
  540. + schedule_delayed_work(&intel_ipts.reacquire_db_work,
  541. + msecs_to_jiffies(DB_LOST_CHECK_STEP1_INTERVAL));
  542. + } else {
  543. + intel_ipts.ipts_clbks.notify_gfx_status(
  544. + IPTS_NOTIFY_STA_BACKLIGHT_OFF,
  545. + intel_ipts.data);
  546. + cancel_delayed_work(&intel_ipts.reacquire_db_work);
  547. + }
  548. + }
  549. +
  550. + return 0;
  551. +}
  552. +
  553. +static void intel_ipts_reacquire_db(intel_ipts_t *intel_ipts_p)
  554. +{
  555. + int ret = 0;
  556. +
  557. + ret = i915_mutex_lock_interruptible(intel_ipts_p->dev);
  558. + if (ret) {
  559. + DRM_ERROR("i915_mutex_lock_interruptible failed \n");
  560. + return;
  561. + }
  562. +
  563. + /* Reacquire the doorbell */
  564. + i915_guc_ipts_reacquire_doorbell(intel_ipts_p->dev->dev_private);
  565. +
  566. + mutex_unlock(&intel_ipts_p->dev->struct_mutex);
  567. +
  568. + return;
  569. +}
  570. +
  571. +static int intel_ipts_get_wq_info(uint64_t gfx_handle,
  572. + intel_ipts_wq_info_t *wq_info)
  573. +{
  574. + if (gfx_handle != (uint64_t)&intel_ipts) {
  575. + DRM_ERROR("invalid gfx handle\n");
  576. + return -EINVAL;
  577. + }
  578. +
  579. + *wq_info = intel_ipts.wq_info;
  580. +
  581. + intel_ipts_reacquire_db(&intel_ipts);
  582. + schedule_delayed_work(&intel_ipts.reacquire_db_work,
  583. + msecs_to_jiffies(DB_LOST_CHECK_STEP1_INTERVAL));
  584. +
  585. + return 0;
  586. +}
  587. +
  588. +static int set_wq_info(void)
  589. +{
  590. + struct drm_i915_private *dev_priv = to_i915(intel_ipts.dev);
  591. + struct intel_guc *guc = &dev_priv->guc;
  592. + struct i915_guc_client *client;
  593. + struct guc_process_desc *desc;
  594. + void *base = NULL;
  595. + intel_ipts_wq_info_t *wq_info;
  596. + u64 phy_base = 0;
  597. +
  598. + wq_info = &intel_ipts.wq_info;
  599. +
  600. + client = guc->ipts_client;
  601. + if (!client) {
  602. + DRM_ERROR("IPTS GuC client is NOT available\n");
  603. + return -EINVAL;
  604. + }
  605. +
  606. + base = client->vaddr;
  607. + desc = (struct guc_process_desc *)((u64)base + client->proc_desc_offset);
  608. +
  609. + desc->wq_base_addr = (u64)base + client->wq_offset;
  610. + desc->db_base_addr = (u64)base + client->doorbell_offset;
  611. +
  612. + /* IPTS expects physical addresses to pass it to ME */
  613. + phy_base = sg_dma_address(client->vma->pages->sgl);
  614. +
  615. + wq_info->db_addr = desc->db_base_addr;
  616. + wq_info->db_phy_addr = phy_base + client->doorbell_offset;
  617. + wq_info->db_cookie_offset = offsetof(struct guc_doorbell_info, cookie);
  618. + wq_info->wq_addr = desc->wq_base_addr;
  619. + wq_info->wq_phy_addr = phy_base + client->wq_offset;
  620. + wq_info->wq_head_addr = (u64)&desc->head;
  621. + wq_info->wq_head_phy_addr = phy_base + client->proc_desc_offset +
  622. + offsetof(struct guc_process_desc, head);
  623. + wq_info->wq_tail_addr = (u64)&desc->tail;
  624. + wq_info->wq_tail_phy_addr = phy_base + client->proc_desc_offset +
  625. + offsetof(struct guc_process_desc, tail);
  626. + wq_info->wq_size = desc->wq_size_bytes;
  627. +
  628. + return 0;
  629. +}
  630. +
  631. +static int intel_ipts_init_wq(void)
  632. +{
  633. + int ret = 0;
  634. +
  635. + ret = i915_mutex_lock_interruptible(intel_ipts.dev);
  636. + if (ret) {
  637. + DRM_ERROR("i915_mutex_lock_interruptible failed\n");
  638. + return ret;
  639. + }
  640. +
  641. + /* disable IPTS submission */
  642. + i915_guc_ipts_submission_disable(intel_ipts.dev->dev_private);
  643. +
  644. + /* enable IPTS submission */
  645. + ret = i915_guc_ipts_submission_enable(intel_ipts.dev->dev_private,
  646. + intel_ipts.ipts_context);
  647. + if (ret) {
  648. + DRM_ERROR("i915_guc_ipts_submission_enable failed : %d\n", ret);
  649. + goto out;
  650. + }
  651. +
  652. + ret = set_wq_info();
  653. + if (ret) {
  654. + DRM_ERROR("set_wq_info failed\n");
  655. + goto out;
  656. + }
  657. +
  658. +out:
  659. + mutex_unlock(&intel_ipts.dev->struct_mutex);
  660. +
  661. + return ret;
  662. +}
  663. +
  664. +static void intel_ipts_release_wq(void)
  665. +{
  666. + int ret = 0;
  667. +
  668. + ret = i915_mutex_lock_interruptible(intel_ipts.dev);
  669. + if (ret) {
  670. + DRM_ERROR("i915_mutex_lock_interruptible failed\n");
  671. + return;
  672. + }
  673. +
  674. + /* disable IPTS submission */
  675. + i915_guc_ipts_submission_disable(intel_ipts.dev->dev_private);
  676. +
  677. + mutex_unlock(&intel_ipts.dev->struct_mutex);
  678. +}
  679. +
  680. +static int intel_ipts_map_buffer(u64 gfx_handle, intel_ipts_mapbuffer_t *mapbuf)
  681. +{
  682. + intel_ipts_object_t* obj;
  683. + struct i915_gem_context *ipts_ctx = NULL;
  684. + struct drm_i915_private *dev_priv = to_i915(intel_ipts.dev);
  685. + struct i915_address_space *vm = NULL;
  686. + struct i915_vma *vma = NULL;
  687. + int ret = 0;
  688. +
  689. + if (gfx_handle != (uint64_t)&intel_ipts) {
  690. + DRM_ERROR("invalid gfx handle\n");
  691. + return -EINVAL;
  692. + }
  693. +
  694. + /* Acquire mutex first */
  695. + ret = i915_mutex_lock_interruptible(intel_ipts.dev);
  696. + if (ret) {
  697. + DRM_ERROR("i915_mutex_lock_interruptible failed \n");
  698. + return -EINVAL;
  699. + }
  700. +
  701. + obj = ipts_object_create(mapbuf->size, mapbuf->flags);
  702. + if (!obj)
  703. + return -ENOMEM;
  704. +
  705. + ipts_ctx = intel_ipts.ipts_context;
  706. + ret = ipts_object_pin(obj, ipts_ctx);
  707. + if (ret) {
  708. + DRM_ERROR("Not able to pin iTouch obj\n");
  709. + ipts_object_free(obj);
  710. + mutex_unlock(&intel_ipts.dev->struct_mutex);
  711. + return -ENOMEM;
  712. + }
  713. +
  714. + if (mapbuf->flags & IPTS_BUF_FLAG_CONTIGUOUS) {
  715. + obj->cpu_addr = obj->gem_obj->phys_handle->vaddr;
  716. + } else {
  717. + obj->cpu_addr = ipts_object_map(obj);
  718. + }
  719. +
  720. + if (ipts_ctx->ppgtt) {
  721. + vm = &ipts_ctx->ppgtt->base;
  722. + } else {
  723. + vm = &dev_priv->ggtt.base;
  724. + }
  725. +
  726. + vma = i915_vma_instance(obj->gem_obj, vm, NULL);
  727. + if (IS_ERR(vma)) {
  728. + DRM_ERROR("cannot find or create vma\n");
  729. + return -EINVAL;
  730. + }
  731. +
  732. + mapbuf->gfx_addr = (void*)vma->node.start;
  733. + mapbuf->cpu_addr = (void*)obj->cpu_addr;
  734. + mapbuf->buf_handle = (u64)obj;
  735. + if (mapbuf->flags & IPTS_BUF_FLAG_CONTIGUOUS) {
  736. + mapbuf->phy_addr = (u64)obj->gem_obj->phys_handle->busaddr;
  737. + }
  738. +
  739. + /* Release the mutex */
  740. + mutex_unlock(&intel_ipts.dev->struct_mutex);
  741. +
  742. + return 0;
  743. +}
  744. +
  745. +static int intel_ipts_unmap_buffer(uint64_t gfx_handle, uint64_t buf_handle)
  746. +{
  747. + intel_ipts_object_t* obj = (intel_ipts_object_t*)buf_handle;
  748. +
  749. + if (gfx_handle != (uint64_t)&intel_ipts) {
  750. + DRM_ERROR("invalid gfx handle\n");
  751. + return -EINVAL;
  752. + }
  753. +
  754. + if (!obj->gem_obj->phys_handle)
  755. + ipts_object_unmap(obj);
  756. + ipts_object_unpin(obj);
  757. + ipts_object_free(obj);
  758. +
  759. + return 0;
  760. +}
  761. +
  762. +int intel_ipts_connect(intel_ipts_connect_t *ipts_connect)
  763. +{
  764. + struct drm_i915_private *dev_priv = to_i915(intel_ipts.dev);
  765. + int ret = 0;
  766. +
  767. + if (!intel_ipts.initialized)
  768. + return -EIO;
  769. +
  770. + if (ipts_connect && ipts_connect->if_version <=
  771. + SUPPORTED_IPTS_INTERFACE_VERSION) {
  772. +
  773. + /* return gpu operations for ipts */
  774. + ipts_connect->ipts_ops.get_wq_info = intel_ipts_get_wq_info;
  775. + ipts_connect->ipts_ops.map_buffer = intel_ipts_map_buffer;
  776. + ipts_connect->ipts_ops.unmap_buffer = intel_ipts_unmap_buffer;
  777. + ipts_connect->gfx_version = INTEL_INFO(dev_priv)->gen;
  778. + ipts_connect->gfx_handle = (uint64_t)&intel_ipts;
  779. +
  780. + /* save callback and data */
  781. + intel_ipts.data = ipts_connect->data;
  782. + intel_ipts.ipts_clbks = ipts_connect->ipts_cb;
  783. +
  784. + intel_ipts.connected = true;
  785. + } else {
  786. + ret = -EINVAL;
  787. + }
  788. +
  789. + return ret;
  790. +}
  791. +EXPORT_SYMBOL_GPL(intel_ipts_connect);
  792. +
  793. +void intel_ipts_disconnect(uint64_t gfx_handle)
  794. +{
  795. + if (!intel_ipts.initialized)
  796. + return;
  797. +
  798. + if (gfx_handle != (uint64_t)&intel_ipts ||
  799. + intel_ipts.connected == false) {
  800. + DRM_ERROR("invalid gfx handle\n");
  801. + return;
  802. + }
  803. +
  804. + intel_ipts.data = 0;
  805. + memset(&intel_ipts.ipts_clbks, 0, sizeof(intel_ipts_callback_t));
  806. +
  807. + intel_ipts.connected = false;
  808. +}
  809. +EXPORT_SYMBOL_GPL(intel_ipts_disconnect);
  810. +
  811. +static void reacquire_db_work_func(struct work_struct *work)
  812. +{
  813. + struct delayed_work *d_work = container_of(work, struct delayed_work,
  814. + work);
  815. + intel_ipts_t *intel_ipts_p = container_of(d_work, intel_ipts_t,
  816. + reacquire_db_work);
  817. + u32 head;
  818. + u32 tail;
  819. + u32 size;
  820. + u32 load;
  821. +
  822. + head = *(u32*)intel_ipts_p->wq_info.wq_head_addr;
  823. + tail = *(u32*)intel_ipts_p->wq_info.wq_tail_addr;
  824. + size = intel_ipts_p->wq_info.wq_size;
  825. +
  826. + if (head >= tail)
  827. + load = head - tail;
  828. + else
  829. + load = head + size - tail;
  830. +
  831. + if (load < REACQUIRE_DB_THRESHOLD) {
  832. + intel_ipts_p->need_reacquire_db = false;
  833. + goto reschedule_work;
  834. + }
  835. +
  836. + if (intel_ipts_p->need_reacquire_db) {
  837. + if (intel_ipts_p->old_head == head && intel_ipts_p->old_tail == tail)
  838. + intel_ipts_reacquire_db(intel_ipts_p);
  839. + intel_ipts_p->need_reacquire_db = false;
  840. + } else {
  841. + intel_ipts_p->old_head = head;
  842. + intel_ipts_p->old_tail = tail;
  843. + intel_ipts_p->need_reacquire_db = true;
  844. +
  845. + /* recheck */
  846. + schedule_delayed_work(&intel_ipts_p->reacquire_db_work,
  847. + msecs_to_jiffies(DB_LOST_CHECK_STEP2_INTERVAL));
  848. + return;
  849. + }
  850. +
  851. +reschedule_work:
  852. + schedule_delayed_work(&intel_ipts_p->reacquire_db_work,
  853. + msecs_to_jiffies(DB_LOST_CHECK_STEP1_INTERVAL));
  854. +}
  855. +
  856. +/**
  857. + * intel_ipts_init - Initialize ipts support
  858. + * @dev: drm device
  859. + *
  860. + * Setup the required structures for ipts.
  861. + */
  862. +int intel_ipts_init(struct drm_device *dev)
  863. +{
  864. + int ret = 0;
  865. +
  866. + pr_info("ipts: initializing ipts\n");
  867. +
  868. + intel_ipts.dev = dev;
  869. + INIT_DELAYED_WORK(&intel_ipts.reacquire_db_work, reacquire_db_work_func);
  870. +
  871. + ret = create_ipts_context();
  872. + if (ret)
  873. + return -ENOMEM;
  874. +
  875. + ret = intel_ipts_init_wq();
  876. + if (ret)
  877. + return ret;
  878. +
  879. + intel_ipts.initialized = true;
  880. + DRM_DEBUG_DRIVER("Intel iTouch framework initialized\n");
  881. +
  882. + return ret;
  883. +}
  884. +
  885. +void intel_ipts_cleanup(struct drm_device *dev)
  886. +{
  887. + intel_ipts_object_t *obj, *n;
  888. +
  889. + if (intel_ipts.dev == dev) {
  890. + list_for_each_entry_safe(obj, n, &intel_ipts.buffers.list, list) {
  891. + list_del(&obj->list);
  892. +
  893. + if (!obj->gem_obj->phys_handle)
  894. + ipts_object_unmap(obj);
  895. + ipts_object_unpin(obj);
  896. + i915_gem_free_object(&obj->gem_obj->base);
  897. + kfree(obj);
  898. + }
  899. +
  900. + intel_ipts_release_wq();
  901. + destroy_ipts_context();
  902. + cancel_delayed_work(&intel_ipts.reacquire_db_work);
  903. + }
  904. +}
  905. diff --git a/drivers/gpu/drm/i915/intel_ipts.h b/drivers/gpu/drm/i915/intel_ipts.h
  906. new file mode 100644
  907. index 0000000..a6965d1
  908. --- /dev/null
  909. +++ b/drivers/gpu/drm/i915/intel_ipts.h
  910. @@ -0,0 +1,34 @@
  911. +/*
  912. + * Copyright © 2016 Intel Corporation
  913. + *
  914. + * Permission is hereby granted, free of charge, to any person obtaining a
  915. + * copy of this software and associated documentation files (the "Software"),
  916. + * to deal in the Software without restriction, including without limitation
  917. + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  918. + * and/or sell copies of the Software, and to permit persons to whom the
  919. + * Software is furnished to do so, subject to the following conditions:
  920. + *
  921. + * The above copyright notice and this permission notice (including the next
  922. + * paragraph) shall be included in all copies or substantial portions of the
  923. + * Software.
  924. + *
  925. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  926. + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  927. + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  928. + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  929. + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  930. + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  931. + * IN THE SOFTWARE.
  932. + *
  933. + */
  934. +#ifndef _INTEL_IPTS_H_
  935. +#define _INTEL_IPTS_H_
  936. +
  937. +struct drm_device;
  938. +
  939. +int intel_ipts_init(struct drm_device *dev);
  940. +void intel_ipts_cleanup(struct drm_device *dev);
  941. +int intel_ipts_notify_backlight_status(bool backlight_on);
  942. +int intel_ipts_notify_complete(void);
  943. +
  944. +#endif //_INTEL_IPTS_H_
  945. diff --git a/drivers/gpu/drm/i915/intel_lrc.c b/drivers/gpu/drm/i915/intel_lrc.c
  946. index 6f972e6..f25a439 100644
  947. --- a/drivers/gpu/drm/i915/intel_lrc.c
  948. +++ b/drivers/gpu/drm/i915/intel_lrc.c
  949. @@ -211,8 +211,6 @@
  950. #define WA_TAIL_DWORDS 2
  951. -static int execlists_context_deferred_alloc(struct i915_gem_context *ctx,
  952. - struct intel_engine_cs *engine);
  953. static void execlists_init_reg_state(u32 *reg_state,
  954. struct i915_gem_context *ctx,
  955. struct intel_engine_cs *engine,
  956. @@ -819,7 +817,7 @@ static void execlists_schedule(struct drm_i915_gem_request *request, int prio)
  957. /* XXX Do we need to preempt to make room for us and our deps? */
  958. }
  959. -static struct intel_ring *
  960. +struct intel_ring *
  961. execlists_context_pin(struct intel_engine_cs *engine,
  962. struct i915_gem_context *ctx)
  963. {
  964. @@ -880,7 +878,7 @@ execlists_context_pin(struct intel_engine_cs *engine,
  965. return ERR_PTR(ret);
  966. }
  967. -static void execlists_context_unpin(struct intel_engine_cs *engine,
  968. +void execlists_context_unpin(struct intel_engine_cs *engine,
  969. struct i915_gem_context *ctx)
  970. {
  971. struct intel_context *ce = &ctx->engine[engine->id];
  972. @@ -1810,6 +1808,9 @@ int logical_render_ring_init(struct intel_engine_cs *engine)
  973. logical_ring_setup(engine);
  974. + engine->irq_keep_mask |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT
  975. + << GEN8_RCS_IRQ_SHIFT;
  976. +
  977. if (HAS_L3_DPF(dev_priv))
  978. engine->irq_keep_mask |= GT_RENDER_L3_PARITY_ERROR_INTERRUPT;
  979. @@ -2038,7 +2039,7 @@ populate_lr_context(struct i915_gem_context *ctx,
  980. return 0;
  981. }
  982. -static int execlists_context_deferred_alloc(struct i915_gem_context *ctx,
  983. +int execlists_context_deferred_alloc(struct i915_gem_context *ctx,
  984. struct intel_engine_cs *engine)
  985. {
  986. struct drm_i915_gem_object *ctx_obj;
  987. diff --git a/drivers/gpu/drm/i915/intel_lrc.h b/drivers/gpu/drm/i915/intel_lrc.h
  988. index 57ef583..aec97c3 100644
  989. --- a/drivers/gpu/drm/i915/intel_lrc.h
  990. +++ b/drivers/gpu/drm/i915/intel_lrc.h
  991. @@ -85,4 +85,12 @@ uint64_t intel_lr_context_descriptor(struct i915_gem_context *ctx,
  992. int intel_sanitize_enable_execlists(struct drm_i915_private *dev_priv,
  993. int enable_execlists);
  994. +struct intel_ring *
  995. +execlists_context_pin(struct intel_engine_cs *engine,
  996. + struct i915_gem_context *ctx);
  997. +void execlists_context_unpin(struct intel_engine_cs *engine,
  998. + struct i915_gem_context *ctx);
  999. +int execlists_context_deferred_alloc(struct i915_gem_context *ctx,
  1000. + struct intel_engine_cs *engine);
  1001. +
  1002. #endif /* _INTEL_LRC_H_ */
  1003. diff --git a/drivers/gpu/drm/i915/intel_panel.c b/drivers/gpu/drm/i915/intel_panel.c
  1004. index 3b1c5d7..98b64e3 100644
  1005. --- a/drivers/gpu/drm/i915/intel_panel.c
  1006. +++ b/drivers/gpu/drm/i915/intel_panel.c
  1007. @@ -34,6 +34,7 @@
  1008. #include <linux/moduleparam.h>
  1009. #include <linux/pwm.h>
  1010. #include "intel_drv.h"
  1011. +#include "intel_ipts.h"
  1012. #define CRC_PMIC_PWM_PERIOD_NS 21333
  1013. @@ -719,6 +720,9 @@ static void lpt_disable_backlight(const struct drm_connector_state *old_conn_sta
  1014. struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
  1015. u32 tmp;
  1016. + if (INTEL_GEN(dev_priv) >= 9 && i915.enable_guc_submission)
  1017. + intel_ipts_notify_backlight_status(false);
  1018. +
  1019. intel_panel_actually_set_backlight(old_conn_state, 0);
  1020. /*
  1021. @@ -906,6 +910,9 @@ static void lpt_enable_backlight(const struct intel_crtc_state *crtc_state,
  1022. /* This won't stick until the above enable. */
  1023. intel_panel_actually_set_backlight(conn_state, panel->backlight.level);
  1024. +
  1025. + if (INTEL_GEN(dev_priv) >= 9 && i915.enable_guc_submission)
  1026. + intel_ipts_notify_backlight_status(true);
  1027. }
  1028. static void pch_enable_backlight(const struct intel_crtc_state *crtc_state,
  1029. diff --git a/drivers/gpu/drm/i915/intel_uc.h b/drivers/gpu/drm/i915/intel_uc.h
  1030. index 22ae52b..c7765f9 100644
  1031. --- a/drivers/gpu/drm/i915/intel_uc.h
  1032. +++ b/drivers/gpu/drm/i915/intel_uc.h
  1033. @@ -191,6 +191,7 @@ struct intel_guc {
  1034. struct ida stage_ids;
  1035. struct i915_guc_client *execbuf_client;
  1036. + struct i915_guc_client *ipts_client;
  1037. DECLARE_BITMAP(doorbell_bitmap, GUC_NUM_DOORBELLS);
  1038. uint32_t db_cacheline; /* Cyclic counter mod pagesize */
  1039. @@ -276,4 +277,9 @@ void intel_huc_select_fw(struct intel_huc *huc);
  1040. void intel_huc_init_hw(struct intel_huc *huc);
  1041. void intel_guc_auth_huc(struct drm_i915_private *dev_priv);
  1042. +int i915_guc_ipts_submission_enable(struct drm_i915_private *dev_priv,
  1043. + struct i915_gem_context *ctx);
  1044. +void i915_guc_ipts_submission_disable(struct drm_i915_private *dev_priv);
  1045. +void i915_guc_ipts_reacquire_doorbell(struct drm_i915_private *dev_priv);
  1046. +
  1047. #endif
  1048. diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c
  1049. index 6598501..a80c018 100644
  1050. --- a/drivers/hid/hid-multitouch.c
  1051. +++ b/drivers/hid/hid-multitouch.c
  1052. @@ -140,6 +140,7 @@ struct mt_device {
  1053. static void mt_post_parse_default_settings(struct mt_device *td);
  1054. static void mt_post_parse(struct mt_device *td);
  1055. +static int cc_seen = 0;
  1056. /* classes of device behavior */
  1057. #define MT_CLS_DEFAULT 0x0001
  1058. @@ -588,8 +589,12 @@ static int mt_touch_input_mapping(struct hid_device *hdev, struct hid_input *hi,
  1059. if (field->index >= field->report->maxfield ||
  1060. usage->usage_index >= field->report_count)
  1061. return 1;
  1062. - td->cc_index = field->index;
  1063. - td->cc_value_index = usage->usage_index;
  1064. +
  1065. + if(cc_seen != 1) {
  1066. + td->cc_index = field->index;
  1067. + td->cc_value_index = usage->usage_index;
  1068. + cc_seen++;
  1069. + }
  1070. return 1;
  1071. case HID_DG_CONTACTMAX:
  1072. /* we don't set td->last_slot_field as contactcount and
  1073. @@ -626,6 +631,16 @@ static int mt_touch_input_mapping(struct hid_device *hdev, struct hid_input *hi,
  1074. return 0;
  1075. }
  1076. +static int mt_touch_input_mapped(struct hid_device *hdev, struct hid_input *hi,
  1077. + struct hid_field *field, struct hid_usage *usage,
  1078. + unsigned long **bit, int *max)
  1079. +{
  1080. + if (usage->type == EV_KEY || usage->type == EV_ABS)
  1081. + set_bit(usage->type, hi->input->evbit);
  1082. +
  1083. + return -1;
  1084. +}
  1085. +
  1086. static int mt_compute_slot(struct mt_device *td, struct input_dev *input)
  1087. {
  1088. __s32 quirks = td->mtclass.quirks;
  1089. @@ -942,9 +957,11 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
  1090. field->application != HID_DG_TOUCHSCREEN &&
  1091. field->application != HID_DG_PEN &&
  1092. field->application != HID_DG_TOUCHPAD &&
  1093. + field->application != HID_GD_MOUSE &&
  1094. field->application != HID_GD_KEYBOARD &&
  1095. field->application != HID_GD_SYSTEM_CONTROL &&
  1096. field->application != HID_CP_CONSUMER_CONTROL &&
  1097. + field->logical != HID_DG_TOUCHSCREEN &&
  1098. field->application != HID_GD_WIRELESS_RADIO_CTLS &&
  1099. !(field->application == HID_VD_ASUS_CUSTOM_MEDIA_KEYS &&
  1100. td->mtclass.quirks & MT_QUIRK_ASUS_CUSTOM_UP))
  1101. @@ -1007,10 +1024,8 @@ static int mt_input_mapped(struct hid_device *hdev, struct hid_input *hi,
  1102. return 0;
  1103. if (field->application == HID_DG_TOUCHSCREEN ||
  1104. - field->application == HID_DG_TOUCHPAD) {
  1105. - /* We own these mappings, tell hid-input to ignore them */
  1106. - return -1;
  1107. - }
  1108. + field->application == HID_DG_TOUCHPAD)
  1109. + return mt_touch_input_mapped(hdev, hi, field, usage, bit, max);
  1110. /* let hid-core decide for the others */
  1111. return 0;
  1112. @@ -1153,6 +1168,7 @@ static int mt_input_configured(struct hid_device *hdev, struct hid_input *hi)
  1113. suffix = "Pen";
  1114. /* force BTN_STYLUS to allow tablet matching in udev */
  1115. __set_bit(BTN_STYLUS, hi->input->keybit);
  1116. + __set_bit(INPUT_PROP_DIRECT, hi->input->propbit);
  1117. } else {
  1118. switch (field->application) {
  1119. case HID_GD_KEYBOARD:
  1120. @@ -1168,9 +1184,10 @@ static int mt_input_configured(struct hid_device *hdev, struct hid_input *hi)
  1121. suffix = "Pen";
  1122. /* force BTN_STYLUS to allow tablet matching in udev */
  1123. __set_bit(BTN_STYLUS, hi->input->keybit);
  1124. + __set_bit(INPUT_PROP_DIRECT, hi->input->propbit);
  1125. break;
  1126. case HID_DG_TOUCHSCREEN:
  1127. - /* we do not set suffix = "Touchscreen" */
  1128. + suffix = "Touchscreen";
  1129. break;
  1130. case HID_DG_TOUCHPAD:
  1131. suffix = "Touchpad";
  1132. @@ -1299,6 +1316,7 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
  1133. td->inputmode_value = MT_INPUTMODE_TOUCHSCREEN;
  1134. td->cc_index = -1;
  1135. td->mt_report_id = -1;
  1136. + cc_seen = 0;
  1137. hid_set_drvdata(hdev, td);
  1138. td->fields = devm_kzalloc(&hdev->dev, sizeof(struct mt_fields),
  1139. @@ -1345,7 +1363,6 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
  1140. hdev->quirks |= HID_QUIRK_NO_INIT_REPORTS;
  1141. setup_timer(&td->release_timer, mt_expired_timeout, (long)hdev);
  1142. -
  1143. ret = hid_parse(hdev);
  1144. if (ret != 0)
  1145. return ret;
  1146. diff --git a/drivers/hid/i2c-hid/i2c-hid.c b/drivers/hid/i2c-hid/i2c-hid.c
  1147. index 9145c21..71dbae5 100644
  1148. --- a/drivers/hid/i2c-hid/i2c-hid.c
  1149. +++ b/drivers/hid/i2c-hid/i2c-hid.c
  1150. @@ -929,11 +929,6 @@ static int i2c_hid_of_probe(struct i2c_client *client,
  1151. }
  1152. pdata->hid_descriptor_address = val;
  1153. - ret = of_property_read_u32(dev->of_node, "post-power-on-delay-ms",
  1154. - &val);
  1155. - if (!ret)
  1156. - pdata->post_power_delay_ms = val;
  1157. -
  1158. return 0;
  1159. }
  1160. @@ -950,6 +945,16 @@ static inline int i2c_hid_of_probe(struct i2c_client *client,
  1161. }
  1162. #endif
  1163. +static void i2c_hid_fwnode_probe(struct i2c_client *client,
  1164. + struct i2c_hid_platform_data *pdata)
  1165. +{
  1166. + u32 val;
  1167. +
  1168. + if (!device_property_read_u32(&client->dev, "post-power-on-delay-ms",
  1169. + &val))
  1170. + pdata->post_power_delay_ms = val;
  1171. +}
  1172. +
  1173. static int i2c_hid_probe(struct i2c_client *client,
  1174. const struct i2c_device_id *dev_id)
  1175. {
  1176. @@ -993,6 +998,9 @@ static int i2c_hid_probe(struct i2c_client *client,
  1177. ihid->pdata = *platform_data;
  1178. }
  1179. + /* Parse platform agnostic common properties from ACPI / device tree */
  1180. + i2c_hid_fwnode_probe(client, &ihid->pdata);
  1181. +
  1182. ihid->pdata.supply = devm_regulator_get(&client->dev, "vdd");
  1183. if (IS_ERR(ihid->pdata.supply)) {
  1184. ret = PTR_ERR(ihid->pdata.supply);
  1185. diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
  1186. index 8136dc7..3cff7be 100644
  1187. --- a/drivers/misc/Kconfig
  1188. +++ b/drivers/misc/Kconfig
  1189. @@ -513,6 +513,7 @@ source "drivers/misc/ti-st/Kconfig"
  1190. source "drivers/misc/lis3lv02d/Kconfig"
  1191. source "drivers/misc/altera-stapl/Kconfig"
  1192. source "drivers/misc/mei/Kconfig"
  1193. +source "drivers/misc/ipts/Kconfig"
  1194. source "drivers/misc/vmw_vmci/Kconfig"
  1195. source "drivers/misc/mic/Kconfig"
  1196. source "drivers/misc/genwqe/Kconfig"
  1197. diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
  1198. index ad0e64f..a574554 100644
  1199. --- a/drivers/misc/Makefile
  1200. +++ b/drivers/misc/Makefile
  1201. @@ -44,6 +44,7 @@ obj-y += lis3lv02d/
  1202. obj-$(CONFIG_USB_SWITCH_FSA9480) += fsa9480.o
  1203. obj-$(CONFIG_ALTERA_STAPL) +=altera-stapl/
  1204. obj-$(CONFIG_INTEL_MEI) += mei/
  1205. +obj-$(CONFIG_INTEL_IPTS) += ipts/
  1206. obj-$(CONFIG_VMWARE_VMCI) += vmw_vmci/
  1207. obj-$(CONFIG_LATTICE_ECP3_CONFIG) += lattice-ecp3-config.o
  1208. obj-$(CONFIG_SRAM) += sram.o
  1209. diff --git a/drivers/misc/ipts/Kconfig b/drivers/misc/ipts/Kconfig
  1210. new file mode 100644
  1211. index 0000000..360ed38
  1212. --- /dev/null
  1213. +++ b/drivers/misc/ipts/Kconfig
  1214. @@ -0,0 +1,9 @@
  1215. +config INTEL_IPTS
  1216. + tristate "Intel Precise Touch & Stylus"
  1217. + select INTEL_MEI
  1218. + depends on X86 && PCI && HID
  1219. + help
  1220. + Intel Precise Touch & Stylus support
  1221. + Supported SoCs:
  1222. + Intel Skylake
  1223. + Intel Kabylake
  1224. diff --git a/drivers/misc/ipts/Makefile b/drivers/misc/ipts/Makefile
  1225. new file mode 100644
  1226. index 0000000..1783e9c
  1227. --- /dev/null
  1228. +++ b/drivers/misc/ipts/Makefile
  1229. @@ -0,0 +1,13 @@
  1230. +#
  1231. +# Makefile - Intel Precise Touch & Stylus device driver
  1232. +# Copyright (c) 2016, Intel Corporation.
  1233. +#
  1234. +
  1235. +obj-$(CONFIG_INTEL_IPTS)+= intel-ipts.o
  1236. +intel-ipts-objs += ipts-mei.o
  1237. +intel-ipts-objs += ipts-hid.o
  1238. +intel-ipts-objs += ipts-msg-handler.o
  1239. +intel-ipts-objs += ipts-kernel.o
  1240. +intel-ipts-objs += ipts-resource.o
  1241. +intel-ipts-objs += ipts-gfx.o
  1242. +intel-ipts-$(CONFIG_DEBUG_FS) += ipts-dbgfs.o
  1243. diff --git a/drivers/misc/ipts/ipts-binary-spec.h b/drivers/misc/ipts/ipts-binary-spec.h
  1244. new file mode 100644
  1245. index 0000000..87d4bc4
  1246. --- /dev/null
  1247. +++ b/drivers/misc/ipts/ipts-binary-spec.h
  1248. @@ -0,0 +1,118 @@
  1249. +/*
  1250. + *
  1251. + * Intel Precise Touch & Stylus binary spec
  1252. + * Copyright (c) 2016 Intel Corporation.
  1253. + *
  1254. + * This program is free software; you can redistribute it and/or modify it
  1255. + * under the terms and conditions of the GNU General Public License,
  1256. + * version 2, as published by the Free Software Foundation.
  1257. + *
  1258. + * This program is distributed in the hope it will be useful, but WITHOUT
  1259. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  1260. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  1261. + * more details.
  1262. + *
  1263. + */
  1264. +
  1265. +#ifndef _IPTS_BINARY_SPEC_H
  1266. +#define _IPTS_BINARY_SPEC_H
  1267. +
  1268. +#define IPTS_BIN_HEADER_VERSION 2
  1269. +
  1270. +#pragma pack(1)
  1271. +
  1272. +/* we support 16 output buffers(1:feedback, 15:HID) */
  1273. +#define MAX_NUM_OUTPUT_BUFFERS 16
  1274. +
  1275. +typedef enum {
  1276. + IPTS_BIN_KERNEL,
  1277. + IPTS_BIN_RO_DATA,
  1278. + IPTS_BIN_RW_DATA,
  1279. + IPTS_BIN_SENSOR_FRAME,
  1280. + IPTS_BIN_OUTPUT,
  1281. + IPTS_BIN_DYNAMIC_STATE_HEAP,
  1282. + IPTS_BIN_PATCH_LOCATION_LIST,
  1283. + IPTS_BIN_ALLOCATION_LIST,
  1284. + IPTS_BIN_COMMAND_BUFFER_PACKET,
  1285. + IPTS_BIN_TAG,
  1286. +} ipts_bin_res_type_t;
  1287. +
  1288. +typedef struct ipts_bin_header {
  1289. + char str[4];
  1290. + unsigned int version;
  1291. +
  1292. +#if IPTS_BIN_HEADER_VERSION > 1
  1293. + unsigned int gfxcore;
  1294. + unsigned int revid;
  1295. +#endif
  1296. +} ipts_bin_header_t;
  1297. +
  1298. +typedef struct ipts_bin_alloc {
  1299. + unsigned int handle;
  1300. + unsigned int reserved;
  1301. +} ipts_bin_alloc_t;
  1302. +
  1303. +typedef struct ipts_bin_alloc_list {
  1304. + unsigned int num;
  1305. + ipts_bin_alloc_t alloc[];
  1306. +} ipts_bin_alloc_list_t;
  1307. +
  1308. +typedef struct ipts_bin_cmdbuf {
  1309. + unsigned int size;
  1310. + char data[];
  1311. +} ipts_bin_cmdbuf_t;
  1312. +
  1313. +typedef struct ipts_bin_res {
  1314. + unsigned int handle;
  1315. + ipts_bin_res_type_t type;
  1316. + unsigned int initialize;
  1317. + unsigned int aligned_size;
  1318. + unsigned int size;
  1319. + char data[];
  1320. +} ipts_bin_res_t;
  1321. +
  1322. +typedef enum {
  1323. + IPTS_INPUT,
  1324. + IPTS_OUTPUT,
  1325. + IPTS_CONFIGURATION,
  1326. + IPTS_CALIBRATION,
  1327. + IPTS_FEATURE,
  1328. +} ipts_bin_io_buffer_type_t;
  1329. +
  1330. +typedef struct ipts_bin_io_header {
  1331. + char str[10];
  1332. + unsigned short type;
  1333. +} ipts_bin_io_header_t;
  1334. +
  1335. +typedef struct ipts_bin_res_list {
  1336. + unsigned int num;
  1337. + ipts_bin_res_t res[];
  1338. +} ipts_bin_res_list_t;
  1339. +
  1340. +typedef struct ipts_bin_patch {
  1341. + unsigned int index;
  1342. + unsigned int reserved1[2];
  1343. + unsigned int alloc_offset;
  1344. + unsigned int patch_offset;
  1345. + unsigned int reserved2;
  1346. +} ipts_bin_patch_t;
  1347. +
  1348. +typedef struct ipts_bin_patch_list {
  1349. + unsigned int num;
  1350. + ipts_bin_patch_t patch[];
  1351. +} ipts_bin_patch_list_t;
  1352. +
  1353. +typedef struct ipts_bin_guc_wq_info {
  1354. + unsigned int batch_offset;
  1355. + unsigned int size;
  1356. + char data[];
  1357. +} ipts_bin_guc_wq_info_t;
  1358. +
  1359. +typedef struct ipts_bin_bufid_patch {
  1360. + unsigned int imm_offset;
  1361. + unsigned int mem_offset;
  1362. +} ipts_bin_bufid_patch_t;
  1363. +
  1364. +#pragma pack()
  1365. +
  1366. +#endif /* _IPTS_BINARY_SPEC_H */
  1367. diff --git a/drivers/misc/ipts/ipts-dbgfs.c b/drivers/misc/ipts/ipts-dbgfs.c
  1368. new file mode 100644
  1369. index 0000000..1c5c92f
  1370. --- /dev/null
  1371. +++ b/drivers/misc/ipts/ipts-dbgfs.c
  1372. @@ -0,0 +1,152 @@
  1373. +/*
  1374. + * Intel Precise Touch & Stylus device driver
  1375. + * Copyright (c) 2016, Intel Corporation.
  1376. + *
  1377. + * This program is free software; you can redistribute it and/or modify it
  1378. + * under the terms and conditions of the GNU General Public License,
  1379. + * version 2, as published by the Free Software Foundation.
  1380. + *
  1381. + * This program is distributed in the hope it will be useful, but WITHOUT
  1382. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  1383. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  1384. + * more details.
  1385. + *
  1386. + */
  1387. +#include <linux/debugfs.h>
  1388. +#include <linux/ctype.h>
  1389. +#include <linux/uaccess.h>
  1390. +
  1391. +#include "ipts.h"
  1392. +#include "ipts-sensor-regs.h"
  1393. +#include "ipts-msg-handler.h"
  1394. +#include "ipts-state.h"
  1395. +
  1396. +const char sensor_mode_fmt[] = "sensor mode : %01d\n";
  1397. +const char ipts_status_fmt[] = "sensor mode : %01d\nipts state : %01d\n";
  1398. +
  1399. +static ssize_t ipts_dbgfs_mode_read(struct file *fp, char __user *ubuf,
  1400. + size_t cnt, loff_t *ppos)
  1401. +{
  1402. + ipts_info_t *ipts = fp->private_data;
  1403. + char mode[80];
  1404. + int len = 0;
  1405. +
  1406. + if (cnt < sizeof(sensor_mode_fmt) - 3)
  1407. + return -EINVAL;
  1408. +
  1409. + len = scnprintf(mode, 80, sensor_mode_fmt, ipts->sensor_mode);
  1410. + if (len < 0)
  1411. + return -EIO;
  1412. +
  1413. + return simple_read_from_buffer(ubuf, cnt, ppos, mode, len);
  1414. +}
  1415. +
  1416. +static ssize_t ipts_dbgfs_mode_write(struct file *fp, const char __user *ubuf,
  1417. + size_t cnt, loff_t *ppos)
  1418. +{
  1419. + ipts_info_t *ipts = fp->private_data;
  1420. + ipts_state_t state;
  1421. + int sensor_mode, len;
  1422. + char mode[3];
  1423. +
  1424. + if (cnt == 0 || cnt > 3)
  1425. + return -EINVAL;
  1426. +
  1427. + state = ipts_get_state(ipts);
  1428. + if (state != IPTS_STA_RAW_DATA_STARTED && state != IPTS_STA_HID_STARTED) {
  1429. + return -EIO;
  1430. + }
  1431. +
  1432. + len = cnt;
  1433. + if (copy_from_user(mode, ubuf, len))
  1434. + return -EFAULT;
  1435. +
  1436. + while(len > 0 && (isspace(mode[len-1]) || mode[len-1] == '\n'))
  1437. + len--;
  1438. + mode[len] = '\0';
  1439. +
  1440. + if (sscanf(mode, "%d", &sensor_mode) != 1)
  1441. + return -EINVAL;
  1442. +
  1443. + if (sensor_mode != TOUCH_SENSOR_MODE_RAW_DATA &&
  1444. + sensor_mode != TOUCH_SENSOR_MODE_HID) {
  1445. + return -EINVAL;
  1446. + }
  1447. +
  1448. + if (sensor_mode == ipts->sensor_mode)
  1449. + return 0;
  1450. +
  1451. + ipts_switch_sensor_mode(ipts, sensor_mode);
  1452. +
  1453. + return cnt;
  1454. +}
  1455. +
  1456. +static const struct file_operations ipts_mode_dbgfs_fops = {
  1457. + .open = simple_open,
  1458. + .read = ipts_dbgfs_mode_read,
  1459. + .write = ipts_dbgfs_mode_write,
  1460. + .llseek = generic_file_llseek,
  1461. +};
  1462. +
  1463. +static ssize_t ipts_dbgfs_status_read(struct file *fp, char __user *ubuf,
  1464. + size_t cnt, loff_t *ppos)
  1465. +{
  1466. + ipts_info_t *ipts = fp->private_data;
  1467. + char status[256];
  1468. + int len = 0;
  1469. +
  1470. + if (cnt < sizeof(ipts_status_fmt) - 3)
  1471. + return -EINVAL;
  1472. +
  1473. + len = scnprintf(status, 256, ipts_status_fmt, ipts->sensor_mode,
  1474. + ipts->state);
  1475. + if (len < 0)
  1476. + return -EIO;
  1477. +
  1478. + return simple_read_from_buffer(ubuf, cnt, ppos, status, len);
  1479. +}
  1480. +
  1481. +static const struct file_operations ipts_status_dbgfs_fops = {
  1482. + .open = simple_open,
  1483. + .read = ipts_dbgfs_status_read,
  1484. + .llseek = generic_file_llseek,
  1485. +};
  1486. +
  1487. +void ipts_dbgfs_deregister(ipts_info_t* ipts)
  1488. +{
  1489. + if (!ipts->dbgfs_dir)
  1490. + return;
  1491. +
  1492. + debugfs_remove_recursive(ipts->dbgfs_dir);
  1493. + ipts->dbgfs_dir = NULL;
  1494. +}
  1495. +
  1496. +int ipts_dbgfs_register(ipts_info_t* ipts, const char *name)
  1497. +{
  1498. + struct dentry *dir, *f;
  1499. +
  1500. + dir = debugfs_create_dir(name, NULL);
  1501. + if (!dir)
  1502. + return -ENOMEM;
  1503. +
  1504. + f = debugfs_create_file("mode", S_IRUSR | S_IWUSR, dir,
  1505. + ipts, &ipts_mode_dbgfs_fops);
  1506. + if (!f) {
  1507. + ipts_err(ipts, "debugfs mode creation failed\n");
  1508. + goto err;
  1509. + }
  1510. +
  1511. + f = debugfs_create_file("status", S_IRUSR, dir,
  1512. + ipts, &ipts_status_dbgfs_fops);
  1513. + if (!f) {
  1514. + ipts_err(ipts, "debugfs status creation failed\n");
  1515. + goto err;
  1516. + }
  1517. +
  1518. + ipts->dbgfs_dir = dir;
  1519. +
  1520. + return 0;
  1521. +err:
  1522. + ipts_dbgfs_deregister(ipts);
  1523. + return -ENODEV;
  1524. +}
  1525. diff --git a/drivers/misc/ipts/ipts-gfx.c b/drivers/misc/ipts/ipts-gfx.c
  1526. new file mode 100644
  1527. index 0000000..5172777
  1528. --- /dev/null
  1529. +++ b/drivers/misc/ipts/ipts-gfx.c
  1530. @@ -0,0 +1,184 @@
  1531. +/*
  1532. + *
  1533. + * Intel Integrated Touch Gfx Interface Layer
  1534. + * Copyright (c) 2016 Intel Corporation.
  1535. + *
  1536. + * This program is free software; you can redistribute it and/or modify it
  1537. + * under the terms and conditions of the GNU General Public License,
  1538. + * version 2, as published by the Free Software Foundation.
  1539. + *
  1540. + * This program is distributed in the hope it will be useful, but WITHOUT
  1541. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  1542. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  1543. + * more details.
  1544. + *
  1545. + */
  1546. +#include <linux/kthread.h>
  1547. +#include <linux/delay.h>
  1548. +#include <linux/intel_ipts_if.h>
  1549. +
  1550. +#include "ipts.h"
  1551. +#include "ipts-msg-handler.h"
  1552. +#include "ipts-state.h"
  1553. +
  1554. +static void gfx_processing_complete(void *data)
  1555. +{
  1556. + ipts_info_t *ipts = data;
  1557. +
  1558. + if (ipts_get_state(ipts) == IPTS_STA_RAW_DATA_STARTED) {
  1559. + schedule_work(&ipts->raw_data_work);
  1560. + return;
  1561. + }
  1562. +
  1563. + ipts_dbg(ipts, "not ready to handle gfx event\n");
  1564. +}
  1565. +
  1566. +static void notify_gfx_status(u32 status, void *data)
  1567. +{
  1568. + ipts_info_t *ipts = data;
  1569. +
  1570. + ipts->gfx_status = status;
  1571. + schedule_work(&ipts->gfx_status_work);
  1572. +}
  1573. +
  1574. +static int connect_gfx(ipts_info_t *ipts)
  1575. +{
  1576. + int ret = 0;
  1577. + intel_ipts_connect_t ipts_connect;
  1578. +
  1579. + ipts_connect.if_version = IPTS_INTERFACE_V1;
  1580. + ipts_connect.ipts_cb.workload_complete = gfx_processing_complete;
  1581. + ipts_connect.ipts_cb.notify_gfx_status = notify_gfx_status;
  1582. + ipts_connect.data = (void*)ipts;
  1583. +
  1584. + ret = intel_ipts_connect(&ipts_connect);
  1585. + if (ret)
  1586. + return ret;
  1587. +
  1588. + /* TODO: gfx version check */
  1589. + ipts->gfx_info.gfx_handle = ipts_connect.gfx_handle;
  1590. + ipts->gfx_info.ipts_ops = ipts_connect.ipts_ops;
  1591. +
  1592. + return ret;
  1593. +}
  1594. +
  1595. +static void disconnect_gfx(ipts_info_t *ipts)
  1596. +{
  1597. + intel_ipts_disconnect(ipts->gfx_info.gfx_handle);
  1598. +}
  1599. +
  1600. +#ifdef RUN_DBG_THREAD
  1601. +#include "../mei/mei_dev.h"
  1602. +
  1603. +static struct task_struct *dbg_thread;
  1604. +
  1605. +static void ipts_print_dbg_info(ipts_info_t* ipts)
  1606. +{
  1607. + char fw_sts_str[MEI_FW_STATUS_STR_SZ];
  1608. + u32 *db, *head, *tail;
  1609. + intel_ipts_wq_info_t* wq_info;
  1610. +
  1611. + wq_info = &ipts->resource.wq_info;
  1612. +
  1613. + mei_fw_status_str(ipts->cldev->bus, fw_sts_str, MEI_FW_STATUS_STR_SZ);
  1614. + pr_info(">> tdt : fw status : %s\n", fw_sts_str);
  1615. +
  1616. + db = (u32*)wq_info->db_addr;
  1617. + head = (u32*)wq_info->wq_head_addr;
  1618. + tail = (u32*)wq_info->wq_tail_addr;
  1619. + pr_info(">> == DB s:%x, c:%x ==\n", *db, *(db+1));
  1620. + pr_info(">> == WQ h:%u, t:%u ==\n", *head, *tail);
  1621. +}
  1622. +
  1623. +static int ipts_dbg_thread(void *data)
  1624. +{
  1625. + ipts_info_t *ipts = (ipts_info_t *)data;
  1626. +
  1627. + pr_info(">> start debug thread\n");
  1628. +
  1629. + while (!kthread_should_stop()) {
  1630. + if (ipts_get_state(ipts) != IPTS_STA_RAW_DATA_STARTED) {
  1631. + pr_info("state is not IPTS_STA_RAW_DATA_STARTED : %d\n",
  1632. + ipts_get_state(ipts));
  1633. + msleep(5000);
  1634. + continue;
  1635. + }
  1636. +
  1637. + ipts_print_dbg_info(ipts);
  1638. +
  1639. + msleep(3000);
  1640. + }
  1641. +
  1642. + return 0;
  1643. +}
  1644. +#endif
  1645. +
  1646. +int ipts_open_gpu(ipts_info_t *ipts)
  1647. +{
  1648. + int ret = 0;
  1649. +
  1650. + ret = connect_gfx(ipts);
  1651. + if (ret) {
  1652. + ipts_dbg(ipts, "cannot connect GPU\n");
  1653. + return ret;
  1654. + }
  1655. +
  1656. + ret = ipts->gfx_info.ipts_ops.get_wq_info(ipts->gfx_info.gfx_handle,
  1657. + &ipts->resource.wq_info);
  1658. + if (ret) {
  1659. + ipts_dbg(ipts, "error in get_wq_info\n");
  1660. + return ret;
  1661. + }
  1662. +
  1663. +#ifdef RUN_DBG_THREAD
  1664. + dbg_thread = kthread_run(ipts_dbg_thread, (void *)ipts, "ipts_debug");
  1665. +#endif
  1666. +
  1667. + return 0;
  1668. +}
  1669. +
  1670. +void ipts_close_gpu(ipts_info_t *ipts)
  1671. +{
  1672. + disconnect_gfx(ipts);
  1673. +
  1674. +#ifdef RUN_DBG_THREAD
  1675. + kthread_stop(dbg_thread);
  1676. +#endif
  1677. +}
  1678. +
  1679. +intel_ipts_mapbuffer_t *ipts_map_buffer(ipts_info_t *ipts, u32 size, u32 flags)
  1680. +{
  1681. + intel_ipts_mapbuffer_t *buf;
  1682. + u64 handle;
  1683. + int ret;
  1684. +
  1685. + buf = devm_kzalloc(&ipts->cldev->dev, sizeof(*buf), GFP_KERNEL);
  1686. + if (!buf)
  1687. + return NULL;
  1688. +
  1689. + buf->size = size;
  1690. + buf->flags = flags;
  1691. +
  1692. + handle = ipts->gfx_info.gfx_handle;
  1693. + ret = ipts->gfx_info.ipts_ops.map_buffer(handle, buf);
  1694. + if (ret) {
  1695. + devm_kfree(&ipts->cldev->dev, buf);
  1696. + return NULL;
  1697. + }
  1698. +
  1699. + return buf;
  1700. +}
  1701. +
  1702. +void ipts_unmap_buffer(ipts_info_t *ipts, intel_ipts_mapbuffer_t *buf)
  1703. +{
  1704. + u64 handle;
  1705. + int ret;
  1706. +
  1707. + if (!buf)
  1708. + return;
  1709. +
  1710. + handle = ipts->gfx_info.gfx_handle;
  1711. + ret = ipts->gfx_info.ipts_ops.unmap_buffer(handle, buf->buf_handle);
  1712. +
  1713. + devm_kfree(&ipts->cldev->dev, buf);
  1714. +}
  1715. diff --git a/drivers/misc/ipts/ipts-gfx.h b/drivers/misc/ipts/ipts-gfx.h
  1716. new file mode 100644
  1717. index 0000000..03a5f35
  1718. --- /dev/null
  1719. +++ b/drivers/misc/ipts/ipts-gfx.h
  1720. @@ -0,0 +1,24 @@
  1721. +/*
  1722. + * Intel Precise Touch & Stylus gpu wrapper
  1723. + * Copyright (c) 2016, Intel Corporation.
  1724. + *
  1725. + * This program is free software; you can redistribute it and/or modify it
  1726. + * under the terms and conditions of the GNU General Public License,
  1727. + * version 2, as published by the Free Software Foundation.
  1728. + *
  1729. + * This program is distributed in the hope it will be useful, but WITHOUT
  1730. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  1731. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  1732. + * more details.
  1733. + */
  1734. +
  1735. +
  1736. +#ifndef _IPTS_GFX_H_
  1737. +#define _IPTS_GFX_H_
  1738. +
  1739. +int ipts_open_gpu(ipts_info_t *ipts);
  1740. +void ipts_close_gpu(ipts_info_t *ipts);
  1741. +intel_ipts_mapbuffer_t *ipts_map_buffer(ipts_info_t *ipts, u32 size, u32 flags);
  1742. +void ipts_unmap_buffer(ipts_info_t *ipts, intel_ipts_mapbuffer_t *buf);
  1743. +
  1744. +#endif // _IPTS_GFX_H_
  1745. diff --git a/drivers/misc/ipts/ipts-hid.c b/drivers/misc/ipts/ipts-hid.c
  1746. new file mode 100644
  1747. index 0000000..3b3be61
  1748. --- /dev/null
  1749. +++ b/drivers/misc/ipts/ipts-hid.c
  1750. @@ -0,0 +1,456 @@
  1751. +/*
  1752. + * Intel Precise Touch & Stylus HID driver
  1753. + *
  1754. + * Copyright (c) 2016, Intel Corporation.
  1755. + *
  1756. + * This program is free software; you can redistribute it and/or modify it
  1757. + * under the terms and conditions of the GNU General Public License,
  1758. + * version 2, as published by the Free Software Foundation.
  1759. + *
  1760. + * This program is distributed in the hope it will be useful, but WITHOUT
  1761. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  1762. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  1763. + * more details.
  1764. + */
  1765. +
  1766. +#include <linux/module.h>
  1767. +#include <linux/firmware.h>
  1768. +#include <linux/hid.h>
  1769. +#include <linux/vmalloc.h>
  1770. +
  1771. +#include "ipts.h"
  1772. +#include "ipts-resource.h"
  1773. +#include "ipts-sensor-regs.h"
  1774. +#include "ipts-msg-handler.h"
  1775. +
  1776. +#define BUS_MEI 0x44
  1777. +
  1778. +#define HID_DESC_INTEL "intel/ipts/intel_desc.bin"
  1779. +#define HID_DESC_VENDOR "intel/ipts/vendor_desc.bin"
  1780. +MODULE_FIRMWARE(HID_DESC_INTEL);
  1781. +MODULE_FIRMWARE(HID_DESC_VENDOR);
  1782. +
  1783. +typedef enum output_buffer_payload_type {
  1784. + OUTPUT_BUFFER_PAYLOAD_ERROR = 0,
  1785. + OUTPUT_BUFFER_PAYLOAD_HID_INPUT_REPORT,
  1786. + OUTPUT_BUFFER_PAYLOAD_HID_FEATURE_REPORT,
  1787. + OUTPUT_BUFFER_PAYLOAD_KERNEL_LOAD,
  1788. + OUTPUT_BUFFER_PAYLOAD_FEEDBACK_BUFFER
  1789. +} output_buffer_payload_type_t;
  1790. +
  1791. +typedef struct kernel_output_buffer_header {
  1792. + u16 length;
  1793. + u8 payload_type;
  1794. + u8 reserved1;
  1795. + touch_hid_private_data_t hid_private_data;
  1796. + u8 reserved2[28];
  1797. + u8 data[0];
  1798. +} kernel_output_buffer_header_t;
  1799. +
  1800. +typedef struct kernel_output_payload_error {
  1801. + u16 severity;
  1802. + u16 source;
  1803. + u8 code[4];
  1804. + char string[128];
  1805. +} kernel_output_payload_error_t;
  1806. +
  1807. +static int ipts_hid_get_hid_descriptor(ipts_info_t *ipts, u8 **desc, int *size)
  1808. +{
  1809. + u8 *buf;
  1810. + int hid_size = 0, ret = 0;
  1811. + const struct firmware *intel_desc = NULL;
  1812. + const struct firmware *vendor_desc = NULL;
  1813. + const char *intel_desc_path = HID_DESC_INTEL;
  1814. + const char *vendor_desc_path = HID_DESC_VENDOR;
  1815. +
  1816. + ret = request_firmware(&intel_desc, intel_desc_path, &ipts->cldev->dev);
  1817. + if (ret) {
  1818. + goto no_hid;
  1819. + }
  1820. + hid_size = intel_desc->size;
  1821. +
  1822. + ret = request_firmware(&vendor_desc, vendor_desc_path, &ipts->cldev->dev);
  1823. + if (ret) {
  1824. + ipts_dbg(ipts, "error in reading HID Vendor Descriptor\n");
  1825. + } else {
  1826. + hid_size += vendor_desc->size;
  1827. + }
  1828. +
  1829. + ipts_dbg(ipts, "hid size = %d\n", hid_size);
  1830. + buf = vmalloc(hid_size);
  1831. + if (buf == NULL) {
  1832. + ret = -ENOMEM;
  1833. + goto no_mem;
  1834. + }
  1835. +
  1836. + memcpy(buf, intel_desc->data, intel_desc->size);
  1837. + if (vendor_desc) {
  1838. + memcpy(&buf[intel_desc->size], vendor_desc->data,
  1839. + vendor_desc->size);
  1840. + release_firmware(vendor_desc);
  1841. + }
  1842. +
  1843. + release_firmware(intel_desc);
  1844. +
  1845. + *desc = buf;
  1846. + *size = hid_size;
  1847. +
  1848. + return 0;
  1849. +no_mem :
  1850. + if (vendor_desc)
  1851. + release_firmware(vendor_desc);
  1852. + release_firmware(intel_desc);
  1853. +
  1854. +no_hid :
  1855. + return ret;
  1856. +}
  1857. +
  1858. +static int ipts_hid_parse(struct hid_device *hid)
  1859. +{
  1860. + ipts_info_t *ipts = hid->driver_data;
  1861. + int ret = 0, size;
  1862. + u8 *buf;
  1863. +
  1864. + ipts_dbg(ipts, "ipts_hid_parse() start\n");
  1865. + ret = ipts_hid_get_hid_descriptor(ipts, &buf, &size);
  1866. + if (ret != 0) {
  1867. + ipts_dbg(ipts, "ipts_hid_ipts_get_hid_descriptor ret %d\n", ret);
  1868. + return -EIO;
  1869. + }
  1870. +
  1871. + ret = hid_parse_report(hid, buf, size);
  1872. + vfree(buf);
  1873. + if (ret) {
  1874. + ipts_err(ipts, "hid_parse_report error : %d\n", ret);
  1875. + goto out;
  1876. + }
  1877. +
  1878. + ipts->hid_desc_ready = true;
  1879. +out:
  1880. + return ret;
  1881. +}
  1882. +
  1883. +static int ipts_hid_start(struct hid_device *hid)
  1884. +{
  1885. + return 0;
  1886. +}
  1887. +
  1888. +static void ipts_hid_stop(struct hid_device *hid)
  1889. +{
  1890. + return;
  1891. +}
  1892. +
  1893. +static int ipts_hid_open(struct hid_device *hid)
  1894. +{
  1895. + return 0;
  1896. +}
  1897. +
  1898. +static void ipts_hid_close(struct hid_device *hid)
  1899. +{
  1900. + ipts_info_t *ipts = hid->driver_data;
  1901. +
  1902. + ipts->hid_desc_ready = false;
  1903. +
  1904. + return;
  1905. +}
  1906. +
  1907. +static int ipts_hid_send_hid2me_feedback(ipts_info_t *ipts, u32 fb_data_type,
  1908. + __u8 *buf, size_t count)
  1909. +{
  1910. + ipts_buffer_info_t *fb_buf;
  1911. + touch_feedback_hdr_t *feedback;
  1912. + u8 *payload;
  1913. + int header_size;
  1914. + ipts_state_t state;
  1915. +
  1916. + header_size = sizeof(touch_feedback_hdr_t);
  1917. +
  1918. + if (count > ipts->resource.hid2me_buffer_size - header_size)
  1919. + return -EINVAL;
  1920. +
  1921. + state = ipts_get_state(ipts);
  1922. + if (state != IPTS_STA_RAW_DATA_STARTED && state != IPTS_STA_HID_STARTED)
  1923. + return 0;
  1924. +
  1925. + fb_buf = ipts_get_hid2me_buffer(ipts);
  1926. + feedback = (touch_feedback_hdr_t *)fb_buf->addr;
  1927. + payload = fb_buf->addr + header_size;
  1928. + memset(feedback, 0, header_size);
  1929. +
  1930. + feedback->feedback_data_type = fb_data_type;
  1931. + feedback->feedback_cmd_type = TOUCH_FEEDBACK_CMD_TYPE_NONE;
  1932. + feedback->payload_size_bytes = count;
  1933. + feedback->buffer_id = TOUCH_HID_2_ME_BUFFER_ID;
  1934. + feedback->protocol_ver = 0;
  1935. + feedback->reserved[0] = 0xAC;
  1936. +
  1937. + /* copy payload */
  1938. + memcpy(payload, buf, count);
  1939. +
  1940. + ipts_send_feedback(ipts, TOUCH_HID_2_ME_BUFFER_ID, 0);
  1941. +
  1942. + return 0;
  1943. +}
  1944. +
  1945. +static int ipts_hid_raw_request(struct hid_device *hid,
  1946. + unsigned char report_number, __u8 *buf,
  1947. + size_t count, unsigned char report_type,
  1948. + int reqtype)
  1949. +{
  1950. + ipts_info_t *ipts = hid->driver_data;
  1951. + u32 fb_data_type;
  1952. +
  1953. + ipts_dbg(ipts, "hid raw request => report %d, request %d\n",
  1954. + (int)report_type, reqtype);
  1955. +
  1956. + if (report_type != HID_FEATURE_REPORT)
  1957. + return 0;
  1958. +
  1959. + switch (reqtype) {
  1960. + case HID_REQ_GET_REPORT:
  1961. + fb_data_type = TOUCH_FEEDBACK_DATA_TYPE_GET_FEATURES;
  1962. + break;
  1963. + case HID_REQ_SET_REPORT:
  1964. + fb_data_type = TOUCH_FEEDBACK_DATA_TYPE_SET_FEATURES;
  1965. + break;
  1966. + default:
  1967. + ipts_err(ipts, "raw request not supprted: %d\n", reqtype);
  1968. + return -EIO;
  1969. + }
  1970. +
  1971. + return ipts_hid_send_hid2me_feedback(ipts, fb_data_type, buf, count);
  1972. +}
  1973. +
  1974. +static int ipts_hid_output_report(struct hid_device *hid,
  1975. + __u8 *buf, size_t count)
  1976. +{
  1977. + ipts_info_t *ipts = hid->driver_data;
  1978. + u32 fb_data_type;
  1979. +
  1980. + ipts_dbg(ipts, "hid output report\n");
  1981. +
  1982. + fb_data_type = TOUCH_FEEDBACK_DATA_TYPE_OUTPUT_REPORT;
  1983. +
  1984. + return ipts_hid_send_hid2me_feedback(ipts, fb_data_type, buf, count);
  1985. +}
  1986. +
  1987. +static struct hid_ll_driver ipts_hid_ll_driver = {
  1988. + .parse = ipts_hid_parse,
  1989. + .start = ipts_hid_start,
  1990. + .stop = ipts_hid_stop,
  1991. + .open = ipts_hid_open,
  1992. + .close = ipts_hid_close,
  1993. + .raw_request = ipts_hid_raw_request,
  1994. + .output_report = ipts_hid_output_report,
  1995. +};
  1996. +
  1997. +int ipts_hid_init(ipts_info_t *ipts)
  1998. +{
  1999. + int ret = 0;
  2000. + struct hid_device *hid;
  2001. +
  2002. + hid = hid_allocate_device();
  2003. + if (IS_ERR(hid)) {
  2004. + ret = PTR_ERR(hid);
  2005. + goto err_dev;
  2006. + }
  2007. +
  2008. + hid->driver_data = ipts;
  2009. + hid->ll_driver = &ipts_hid_ll_driver;
  2010. + hid->dev.parent = &ipts->cldev->dev;
  2011. + hid->bus = BUS_MEI;
  2012. + hid->version = ipts->device_info.fw_rev;
  2013. + hid->vendor = ipts->device_info.vendor_id;
  2014. + hid->product = ipts->device_info.device_id;
  2015. +
  2016. + snprintf(hid->phys, sizeof(hid->phys), "heci3");
  2017. + snprintf(hid->name, sizeof(hid->name),
  2018. + "%s %04hX:%04hX", "ipts", hid->vendor, hid->product);
  2019. +
  2020. + ret = hid_add_device(hid);
  2021. + if (ret) {
  2022. + if (ret != -ENODEV)
  2023. + ipts_err(ipts, "can't add hid device: %d\n", ret);
  2024. + goto err_mem_free;
  2025. + }
  2026. +
  2027. + ipts->hid = hid;
  2028. +
  2029. + return 0;
  2030. +
  2031. +err_mem_free:
  2032. + hid_destroy_device(hid);
  2033. +err_dev:
  2034. + return ret;
  2035. +}
  2036. +
  2037. +void ipts_hid_release(ipts_info_t *ipts)
  2038. +{
  2039. + if (!ipts->hid)
  2040. + return;
  2041. + hid_destroy_device(ipts->hid);
  2042. +}
  2043. +
  2044. +int ipts_handle_hid_data(ipts_info_t *ipts,
  2045. + touch_sensor_hid_ready_for_data_rsp_data_t *hid_rsp)
  2046. +{
  2047. + touch_raw_data_hdr_t *raw_header;
  2048. + ipts_buffer_info_t *buffer_info;
  2049. + touch_feedback_hdr_t *feedback;
  2050. + u8 *raw_data;
  2051. + int touch_data_buffer_index;
  2052. + int transaction_id;
  2053. + int ret = 0;
  2054. +
  2055. + touch_data_buffer_index = (int)hid_rsp->touch_data_buffer_index;
  2056. + buffer_info = ipts_get_touch_data_buffer_hid(ipts);
  2057. + raw_header = (touch_raw_data_hdr_t *)buffer_info->addr;
  2058. + transaction_id = raw_header->hid_private_data.transaction_id;
  2059. +
  2060. + raw_data = (u8*)raw_header + sizeof(touch_raw_data_hdr_t);
  2061. + if (raw_header->data_type == TOUCH_RAW_DATA_TYPE_HID_REPORT) {
  2062. + memcpy(ipts->hid_input_report, raw_data,
  2063. + raw_header->raw_data_size_bytes);
  2064. +
  2065. + ret = hid_input_report(ipts->hid, HID_INPUT_REPORT,
  2066. + (u8*)ipts->hid_input_report,
  2067. + raw_header->raw_data_size_bytes, 1);
  2068. + if (ret) {
  2069. + ipts_err(ipts, "error in hid_input_report : %d\n", ret);
  2070. + }
  2071. + } else if (raw_header->data_type == TOUCH_RAW_DATA_TYPE_GET_FEATURES) {
  2072. + /* TODO: implement together with "get feature ioctl" */
  2073. + } else if (raw_header->data_type == TOUCH_RAW_DATA_TYPE_ERROR) {
  2074. + touch_error_t *touch_err = (touch_error_t *)raw_data;
  2075. +
  2076. + ipts_err(ipts, "error type : %d, me fw error : %x, err reg : %x\n",
  2077. + touch_err->touch_error_type,
  2078. + touch_err->touch_me_fw_error.value,
  2079. + touch_err->touch_error_register.reg_value);
  2080. + }
  2081. +
  2082. + /* send feedback data for HID mode */
  2083. + buffer_info = ipts_get_feedback_buffer(ipts, touch_data_buffer_index);
  2084. + feedback = (touch_feedback_hdr_t *)buffer_info->addr;
  2085. + memset(feedback, 0, sizeof(touch_feedback_hdr_t));
  2086. + feedback->feedback_cmd_type = TOUCH_FEEDBACK_CMD_TYPE_NONE;
  2087. + feedback->payload_size_bytes = 0;
  2088. + feedback->buffer_id = touch_data_buffer_index;
  2089. + feedback->protocol_ver = 0;
  2090. + feedback->reserved[0] = 0xAC;
  2091. +
  2092. + ret = ipts_send_feedback(ipts, touch_data_buffer_index, transaction_id);
  2093. +
  2094. + return ret;
  2095. +}
  2096. +
  2097. +static int handle_outputs(ipts_info_t *ipts, int parallel_idx)
  2098. +{
  2099. + kernel_output_buffer_header_t *out_buf_hdr;
  2100. + ipts_buffer_info_t *output_buf, *fb_buf = NULL;
  2101. + u8 *input_report, *payload;
  2102. + u32 transaction_id;
  2103. + int i, payload_size, ret = 0, header_size;
  2104. +
  2105. + header_size = sizeof(kernel_output_buffer_header_t);
  2106. + output_buf = ipts_get_output_buffers_by_parallel_id(ipts, parallel_idx);
  2107. + for (i = 0; i < ipts->resource.num_of_outputs; i++) {
  2108. + out_buf_hdr = (kernel_output_buffer_header_t*)output_buf[i].addr;
  2109. + if (out_buf_hdr->length < header_size)
  2110. + continue;
  2111. +
  2112. + payload_size = out_buf_hdr->length - header_size;
  2113. + payload = out_buf_hdr->data;
  2114. +
  2115. + switch(out_buf_hdr->payload_type) {
  2116. + case OUTPUT_BUFFER_PAYLOAD_HID_INPUT_REPORT:
  2117. + input_report = ipts->hid_input_report;
  2118. + memcpy(input_report, payload, payload_size);
  2119. + hid_input_report(ipts->hid, HID_INPUT_REPORT,
  2120. + input_report, payload_size, 1);
  2121. + break;
  2122. + case OUTPUT_BUFFER_PAYLOAD_HID_FEATURE_REPORT:
  2123. + ipts_dbg(ipts, "output hid feature report\n");
  2124. + break;
  2125. + case OUTPUT_BUFFER_PAYLOAD_KERNEL_LOAD:
  2126. + ipts_dbg(ipts, "output kernel load\n");
  2127. + break;
  2128. + case OUTPUT_BUFFER_PAYLOAD_FEEDBACK_BUFFER:
  2129. + {
  2130. + /* send feedback data for raw data mode */
  2131. + fb_buf = ipts_get_feedback_buffer(ipts,
  2132. + parallel_idx);
  2133. + transaction_id = out_buf_hdr->
  2134. + hid_private_data.transaction_id;
  2135. + memcpy(fb_buf->addr, payload, payload_size);
  2136. + break;
  2137. + }
  2138. + case OUTPUT_BUFFER_PAYLOAD_ERROR:
  2139. + {
  2140. + kernel_output_payload_error_t *err_payload;
  2141. +
  2142. + if (payload_size == 0)
  2143. + break;
  2144. +
  2145. + err_payload =
  2146. + (kernel_output_payload_error_t*)payload;
  2147. +
  2148. + ipts_err(ipts, "error : severity : %d,"
  2149. + " source : %d,"
  2150. + " code : %d:%d:%d:%d\n"
  2151. + "string %s\n",
  2152. + err_payload->severity,
  2153. + err_payload->source,
  2154. + err_payload->code[0],
  2155. + err_payload->code[1],
  2156. + err_payload->code[2],
  2157. + err_payload->code[3],
  2158. + err_payload->string);
  2159. +
  2160. + break;
  2161. + }
  2162. + default:
  2163. + ipts_err(ipts, "invalid output buffer payload\n");
  2164. + break;
  2165. + }
  2166. + }
  2167. +
  2168. + if (fb_buf) {
  2169. + ret = ipts_send_feedback(ipts, parallel_idx, transaction_id);
  2170. + if (ret)
  2171. + return ret;
  2172. + }
  2173. +
  2174. + return 0;
  2175. +}
  2176. +
  2177. +static int handle_output_buffers(ipts_info_t *ipts, int cur_idx, int end_idx)
  2178. +{
  2179. + int max_num_of_buffers = ipts_get_num_of_parallel_buffers(ipts);
  2180. +
  2181. + do {
  2182. + cur_idx++; /* cur_idx has last completed so starts with +1 */
  2183. + cur_idx %= max_num_of_buffers;
  2184. + handle_outputs(ipts, cur_idx);
  2185. + } while (cur_idx != end_idx);
  2186. +
  2187. + return 0;
  2188. +}
  2189. +
  2190. +int ipts_handle_processed_data(ipts_info_t *ipts)
  2191. +{
  2192. + int ret = 0;
  2193. + int current_buffer_idx;
  2194. + int last_buffer_idx;
  2195. +
  2196. + current_buffer_idx = *ipts->last_submitted_id;
  2197. + last_buffer_idx = ipts->last_buffer_completed;
  2198. +
  2199. + if (current_buffer_idx == last_buffer_idx)
  2200. + return 0;
  2201. +
  2202. + ipts->last_buffer_completed = current_buffer_idx;
  2203. + handle_output_buffers(ipts, last_buffer_idx, current_buffer_idx);
  2204. +
  2205. + return ret;
  2206. +}
  2207. diff --git a/drivers/misc/ipts/ipts-hid.h b/drivers/misc/ipts/ipts-hid.h
  2208. new file mode 100644
  2209. index 0000000..f1b22c9
  2210. --- /dev/null
  2211. +++ b/drivers/misc/ipts/ipts-hid.h
  2212. @@ -0,0 +1,34 @@
  2213. +/*
  2214. + * Intel Precise Touch & Stylus HID definition
  2215. + *
  2216. + * Copyright (c) 2016, Intel Corporation.
  2217. + *
  2218. + * This program is free software; you can redistribute it and/or modify it
  2219. + * under the terms and conditions of the GNU General Public License,
  2220. + * version 2, as published by the Free Software Foundation.
  2221. + *
  2222. + * This program is distributed in the hope it will be useful, but WITHOUT
  2223. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  2224. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  2225. + * more details.
  2226. + */
  2227. +
  2228. +#ifndef _IPTS_HID_H_
  2229. +#define _IPTS_HID_H_
  2230. +
  2231. +#define BUS_MEI 0x44
  2232. +
  2233. +#if 0 /* TODO : we have special report ID. will implement them */
  2234. +#define WRITE_CHANNEL_REPORT_ID 0xa
  2235. +#define READ_CHANNEL_REPORT_ID 0xb
  2236. +#define CONFIG_CHANNEL_REPORT_ID 0xd
  2237. +#define VENDOR_INFO_REPORT_ID 0xF
  2238. +#define SINGLE_TOUCH_REPORT_ID 0x40
  2239. +#endif
  2240. +
  2241. +int ipts_hid_init(ipts_info_t *ipts);
  2242. +void ipts_hid_release(ipts_info_t *ipts);
  2243. +int ipts_handle_hid_data(ipts_info_t *ipts,
  2244. + touch_sensor_hid_ready_for_data_rsp_data_t *hid_rsp);
  2245. +
  2246. +#endif /* _IPTS_HID_H_ */
  2247. diff --git a/drivers/misc/ipts/ipts-kernel.c b/drivers/misc/ipts/ipts-kernel.c
  2248. new file mode 100644
  2249. index 0000000..ca5e24c
  2250. --- /dev/null
  2251. +++ b/drivers/misc/ipts/ipts-kernel.c
  2252. @@ -0,0 +1,1050 @@
  2253. +#include <linux/module.h>
  2254. +#include <linux/firmware.h>
  2255. +#include <linux/vmalloc.h>
  2256. +#include <linux/intel_ipts_if.h>
  2257. +
  2258. +#include "ipts.h"
  2259. +#include "ipts-resource.h"
  2260. +#include "ipts-binary-spec.h"
  2261. +#include "ipts-state.h"
  2262. +#include "ipts-msg-handler.h"
  2263. +#include "ipts-gfx.h"
  2264. +
  2265. +#define MAX_IOCL_FILE_NAME_LEN 80
  2266. +#define MAX_IOCL_FILE_PATH_LEN 256
  2267. +
  2268. +#pragma pack(1)
  2269. +typedef struct bin_data_file_info {
  2270. + u32 io_buffer_type;
  2271. + u32 flags;
  2272. + char file_name[MAX_IOCL_FILE_NAME_LEN];
  2273. +} bin_data_file_info_t;
  2274. +
  2275. +typedef struct bin_fw_info {
  2276. + char fw_name[MAX_IOCL_FILE_NAME_LEN];
  2277. +
  2278. + /* list of parameters to load a kernel */
  2279. + s32 vendor_output; /* output index. -1 for no use */
  2280. + u32 num_of_data_files;
  2281. + bin_data_file_info_t data_file[];
  2282. +} bin_fw_info_t;
  2283. +
  2284. +typedef struct bin_fw_list {
  2285. + u32 num_of_fws;
  2286. + bin_fw_info_t fw_info[];
  2287. +} bin_fw_list_t;
  2288. +#pragma pack()
  2289. +
  2290. +/* OpenCL kernel */
  2291. +typedef struct bin_workload {
  2292. + int cmdbuf_index;
  2293. + int iobuf_input;
  2294. + int iobuf_output[MAX_NUM_OUTPUT_BUFFERS];
  2295. +} bin_workload_t;
  2296. +
  2297. +typedef struct bin_buffer {
  2298. + unsigned int handle;
  2299. + intel_ipts_mapbuffer_t *buf;
  2300. + bool no_unmap; /* only releasing vendor kernel unmaps output buffers */
  2301. +} bin_buffer_t;
  2302. +
  2303. +typedef struct bin_alloc_info {
  2304. + bin_buffer_t *buffs;
  2305. + int num_of_allocations;
  2306. + int num_of_outputs;
  2307. +
  2308. + int num_of_buffers;
  2309. +} bin_alloc_info_t;
  2310. +
  2311. +typedef struct bin_guc_wq_item {
  2312. + unsigned int batch_offset;
  2313. + unsigned int size;
  2314. + char data[];
  2315. +} bin_guc_wq_item_t;
  2316. +
  2317. +typedef struct bin_kernel_info {
  2318. + bin_workload_t *wl;
  2319. + bin_alloc_info_t *alloc_info;
  2320. + bin_guc_wq_item_t *guc_wq_item;
  2321. + ipts_bin_bufid_patch_t bufid_patch;
  2322. +
  2323. + bool is_vendor; /* 1: vendor, 0: postprocessing */
  2324. +} bin_kernel_info_t;
  2325. +
  2326. +typedef struct bin_kernel_list {
  2327. + intel_ipts_mapbuffer_t *bufid_buf;
  2328. + int num_of_kernels;
  2329. + bin_kernel_info_t kernels[];
  2330. +} bin_kernel_list_t;
  2331. +
  2332. +typedef struct bin_parse_info {
  2333. + u8 *data;
  2334. + int size;
  2335. + int parsed;
  2336. +
  2337. + bin_fw_info_t *fw_info;
  2338. +
  2339. + /* only used by postprocessing */
  2340. + bin_kernel_info_t *vendor_kernel;
  2341. + u32 interested_vendor_output; /* interested vendor output index */
  2342. +} bin_parse_info_t;
  2343. +
  2344. +#define BDW_SURFACE_BASE_ADDRESS 0x6101000e
  2345. +#define SURFACE_STATE_OFFSET_WORD 4
  2346. +#define SBA_OFFSET_BYTES 16384
  2347. +#define LASTSUBMITID_DEFAULT_VALUE -1
  2348. +
  2349. +#define IPTS_FW_PATH_FMT "intel/ipts/%s"
  2350. +#define IPTS_FW_CONFIG_FILE "intel/ipts/ipts_fw_config.bin"
  2351. +
  2352. +MODULE_FIRMWARE(IPTS_FW_CONFIG_FILE);
  2353. +
  2354. +#define IPTS_INPUT_ON ((u32)1 << IPTS_INPUT)
  2355. +#define IPTS_OUTPUT_ON ((u32)1 << IPTS_OUTPUT)
  2356. +#define IPTS_CONFIGURATION_ON ((u32)1 << IPTS_CONFIGURATION)
  2357. +#define IPTS_CALIBRATION_ON ((u32)1 << IPTS_CALIBRATION)
  2358. +#define IPTS_FEATURE_ON ((u32)1 << IPTS_FEATURE)
  2359. +
  2360. +#define DATA_FILE_FLAG_SHARE 0x00000001
  2361. +#define DATA_FILE_FLAG_ALLOC_CONTIGUOUS 0x00000002
  2362. +
  2363. +static int bin_read_fw(ipts_info_t *ipts, const char *fw_name,
  2364. + u8* data, int size)
  2365. +{
  2366. + const struct firmware *fw = NULL;
  2367. + char fw_path[MAX_IOCL_FILE_PATH_LEN];
  2368. + int ret = 0;
  2369. +
  2370. + snprintf(fw_path, MAX_IOCL_FILE_PATH_LEN, IPTS_FW_PATH_FMT, fw_name);
  2371. + ret = request_firmware(&fw, fw_path, &ipts->cldev->dev);
  2372. + if (ret) {
  2373. + ipts_err(ipts, "cannot read fw %s\n", fw_path);
  2374. + return ret;
  2375. + }
  2376. +
  2377. + if (fw->size > size) {
  2378. + ipts_dbg(ipts, "too small buffer to contain fw data\n");
  2379. + ret = -EINVAL;
  2380. + goto rel_return;
  2381. + }
  2382. +
  2383. + memcpy(data, fw->data, fw->size);
  2384. +
  2385. +rel_return:
  2386. + release_firmware(fw);
  2387. +
  2388. + return ret;
  2389. +}
  2390. +
  2391. +
  2392. +static bin_data_file_info_t* bin_get_data_file_info(bin_fw_info_t* fw_info,
  2393. + u32 io_buffer_type)
  2394. +{
  2395. + int i;
  2396. +
  2397. + for (i = 0; i < fw_info->num_of_data_files; i++) {
  2398. + if (fw_info->data_file[i].io_buffer_type == io_buffer_type)
  2399. + break;
  2400. + }
  2401. +
  2402. + if (i == fw_info->num_of_data_files)
  2403. + return NULL;
  2404. +
  2405. + return &fw_info->data_file[i];
  2406. +}
  2407. +
  2408. +static inline bool is_shared_data(const bin_data_file_info_t *data_file)
  2409. +{
  2410. + if (data_file)
  2411. + return (!!(data_file->flags & DATA_FILE_FLAG_SHARE));
  2412. +
  2413. + return false;
  2414. +}
  2415. +
  2416. +static inline bool is_alloc_cont_data(const bin_data_file_info_t *data_file)
  2417. +{
  2418. + if (data_file)
  2419. + return (!!(data_file->flags & DATA_FILE_FLAG_ALLOC_CONTIGUOUS));
  2420. +
  2421. + return false;
  2422. +}
  2423. +
  2424. +static inline bool is_parsing_vendor_kernel(const bin_parse_info_t *parse_info)
  2425. +{
  2426. + /* vendor_kernel == null while loading itself(vendor kernel) */
  2427. + return parse_info->vendor_kernel == NULL;
  2428. +}
  2429. +
  2430. +static int bin_read_allocation_list(ipts_info_t *ipts,
  2431. + bin_parse_info_t *parse_info,
  2432. + bin_alloc_info_t *alloc_info)
  2433. +{
  2434. + ipts_bin_alloc_list_t *alloc_list;
  2435. + int alloc_idx, parallel_idx, num_of_parallels, buf_idx, num_of_buffers;
  2436. + int parsed, size;
  2437. +
  2438. + parsed = parse_info->parsed;
  2439. + size = parse_info->size;
  2440. +
  2441. + alloc_list = (ipts_bin_alloc_list_t *)&parse_info->data[parsed];
  2442. +
  2443. + /* validation check */
  2444. + if (sizeof(alloc_list->num) > size - parsed)
  2445. + return -EINVAL;
  2446. +
  2447. + /* read the number of aloocations */
  2448. + parsed += sizeof(alloc_list->num);
  2449. +
  2450. + /* validation check */
  2451. + if (sizeof(alloc_list->alloc[0]) * alloc_list->num > size - parsed)
  2452. + return -EINVAL;
  2453. +
  2454. + num_of_parallels = ipts_get_num_of_parallel_buffers(ipts);
  2455. + num_of_buffers = num_of_parallels * alloc_list->num + num_of_parallels;
  2456. +
  2457. + alloc_info->buffs = vmalloc(sizeof(bin_buffer_t) * num_of_buffers);
  2458. + if (alloc_info->buffs == NULL)
  2459. + return -ENOMEM;
  2460. +
  2461. + memset(alloc_info->buffs, 0, sizeof(bin_buffer_t) * num_of_buffers);
  2462. + for (alloc_idx = 0; alloc_idx < alloc_list->num; alloc_idx++) {
  2463. + for (parallel_idx = 0; parallel_idx < num_of_parallels;
  2464. + parallel_idx++) {
  2465. + buf_idx = alloc_idx + (parallel_idx * alloc_list->num);
  2466. + alloc_info->buffs[buf_idx].handle =
  2467. + alloc_list->alloc[alloc_idx].handle;
  2468. +
  2469. + }
  2470. +
  2471. + parsed += sizeof(alloc_list->alloc[0]);
  2472. + }
  2473. +
  2474. + parse_info->parsed = parsed;
  2475. + alloc_info->num_of_allocations = alloc_list->num;
  2476. + alloc_info->num_of_buffers = num_of_buffers;
  2477. +
  2478. + ipts_dbg(ipts, "number of allocations = %d, buffers = %d\n",
  2479. + alloc_info->num_of_allocations,
  2480. + alloc_info->num_of_buffers);
  2481. +
  2482. + return 0;
  2483. +}
  2484. +
  2485. +static void patch_SBA(u32 *buf_addr, u64 gpu_addr, int size)
  2486. +{
  2487. + u64 *stateBase;
  2488. + u64 SBA;
  2489. + u32 inst;
  2490. + int i;
  2491. +
  2492. + SBA = gpu_addr + SBA_OFFSET_BYTES;
  2493. +
  2494. + for (i = 0; i < size/4; i++) {
  2495. + inst = buf_addr[i];
  2496. + if (inst == BDW_SURFACE_BASE_ADDRESS) {
  2497. + stateBase = (u64*)&buf_addr[i + SURFACE_STATE_OFFSET_WORD];
  2498. + *stateBase |= SBA;
  2499. + *stateBase |= 0x01; // enable
  2500. + break;
  2501. + }
  2502. + }
  2503. +}
  2504. +
  2505. +static int bin_read_cmd_buffer(ipts_info_t *ipts,
  2506. + bin_parse_info_t *parse_info,
  2507. + bin_alloc_info_t *alloc_info,
  2508. + bin_workload_t *wl)
  2509. +{
  2510. + ipts_bin_cmdbuf_t *cmd;
  2511. + intel_ipts_mapbuffer_t *buf;
  2512. + int cmdbuf_idx, size, parsed, parallel_idx, num_of_parallels;
  2513. +
  2514. + size = parse_info->size;
  2515. + parsed = parse_info->parsed;
  2516. +
  2517. + cmd = (ipts_bin_cmdbuf_t *)&parse_info->data[parsed];
  2518. +
  2519. + if (sizeof(cmd->size) > size - parsed)
  2520. + return -EINVAL;
  2521. +
  2522. + parsed += sizeof(cmd->size);
  2523. + if (cmd->size > size - parsed)
  2524. + return -EINVAL;
  2525. +
  2526. + ipts_dbg(ipts, "cmd buf size = %d\n", cmd->size);
  2527. +
  2528. + num_of_parallels = ipts_get_num_of_parallel_buffers(ipts);
  2529. + /* command buffers are located after the other allocations */
  2530. + cmdbuf_idx = num_of_parallels * alloc_info->num_of_allocations;
  2531. + for (parallel_idx = 0; parallel_idx < num_of_parallels; parallel_idx++) {
  2532. + buf = ipts_map_buffer(ipts, cmd->size, 0);
  2533. + if (buf == NULL)
  2534. + return -ENOMEM;
  2535. +
  2536. + ipts_dbg(ipts, "cmd_idx[%d] = %d, g:0x%p, c:0x%p\n", parallel_idx,
  2537. + cmdbuf_idx, buf->gfx_addr, buf->cpu_addr);
  2538. +
  2539. + memcpy((void *)buf->cpu_addr, &(cmd->data[0]), cmd->size);
  2540. + patch_SBA(buf->cpu_addr, (u64)buf->gfx_addr, cmd->size);
  2541. + alloc_info->buffs[cmdbuf_idx].buf = buf;
  2542. + wl[parallel_idx].cmdbuf_index = cmdbuf_idx;
  2543. +
  2544. + cmdbuf_idx++;
  2545. + }
  2546. +
  2547. + parsed += cmd->size;
  2548. + parse_info->parsed = parsed;
  2549. +
  2550. + return 0;
  2551. +}
  2552. +
  2553. +static int bin_find_alloc(ipts_info_t *ipts,
  2554. + bin_alloc_info_t *alloc_info,
  2555. + u32 handle)
  2556. +{
  2557. + int i;
  2558. +
  2559. + for (i = 0; i < alloc_info->num_of_allocations; i++) {
  2560. + if (alloc_info->buffs[i].handle == handle)
  2561. + return i;
  2562. + }
  2563. +
  2564. + return -1;
  2565. +}
  2566. +
  2567. +static intel_ipts_mapbuffer_t* bin_get_vendor_kernel_output(
  2568. + bin_parse_info_t *parse_info,
  2569. + int parallel_idx)
  2570. +{
  2571. + bin_kernel_info_t *vendor = parse_info->vendor_kernel;
  2572. + bin_alloc_info_t *alloc_info;
  2573. + int buf_idx, vendor_output_idx;
  2574. +
  2575. + alloc_info = vendor->alloc_info;
  2576. + vendor_output_idx = parse_info->interested_vendor_output;
  2577. +
  2578. + if (vendor_output_idx >= alloc_info->num_of_outputs)
  2579. + return NULL;
  2580. +
  2581. + buf_idx = vendor->wl[parallel_idx].iobuf_output[vendor_output_idx];
  2582. + return alloc_info->buffs[buf_idx].buf;
  2583. +}
  2584. +
  2585. +static int bin_read_res_list(ipts_info_t *ipts,
  2586. + bin_parse_info_t *parse_info,
  2587. + bin_alloc_info_t *alloc_info,
  2588. + bin_workload_t *wl)
  2589. +{
  2590. + ipts_bin_res_list_t *res_list;
  2591. + ipts_bin_res_t *res;
  2592. + intel_ipts_mapbuffer_t *buf;
  2593. + bin_data_file_info_t *data_file;
  2594. + u8 *bin_data;
  2595. + int i, size, parsed, parallel_idx, num_of_parallels, output_idx = -1;
  2596. + int buf_idx, num_of_alloc;
  2597. + u32 buf_size, flags, io_buf_type;
  2598. + bool initialize;
  2599. +
  2600. + parsed = parse_info->parsed;
  2601. + size = parse_info->size;
  2602. + bin_data = parse_info->data;
  2603. +
  2604. + res_list = (ipts_bin_res_list_t *)&parse_info->data[parsed];
  2605. + if (sizeof(res_list->num) > (size - parsed))
  2606. + return -EINVAL;
  2607. + parsed += sizeof(res_list->num);
  2608. + num_of_parallels = ipts_get_num_of_parallel_buffers(ipts);
  2609. +
  2610. + ipts_dbg(ipts, "number of resources %u\n", res_list->num);
  2611. + for (i = 0; i < res_list->num; i++) {
  2612. + initialize = false;
  2613. + io_buf_type = 0;
  2614. + flags = 0;
  2615. +
  2616. + /* initial data */
  2617. + data_file = NULL;
  2618. +
  2619. + res = (ipts_bin_res_t *)(&(bin_data[parsed]));
  2620. + if (sizeof(res[0]) > (size - parsed)) {
  2621. + return -EINVAL;
  2622. + }
  2623. +
  2624. + ipts_dbg(ipts, "Resource(%d):handle 0x%08x type %u init %u"
  2625. + " size %u alsigned %u\n",
  2626. + i, res->handle, res->type, res->initialize,
  2627. + res->size, res->aligned_size);
  2628. + parsed += sizeof(res[0]);
  2629. +
  2630. + if (res->initialize) {
  2631. + if (res->size > (size - parsed)) {
  2632. + return -EINVAL;
  2633. + }
  2634. + parsed += res->size;
  2635. + }
  2636. +
  2637. + initialize = res->initialize;
  2638. + if (initialize && res->size > sizeof(ipts_bin_io_header_t)) {
  2639. + ipts_bin_io_header_t *io_hdr;
  2640. + io_hdr = (ipts_bin_io_header_t *)(&res->data[0]);
  2641. + if (strncmp(io_hdr->str, "INTELTOUCH", 10) == 0) {
  2642. + data_file = bin_get_data_file_info(
  2643. + parse_info->fw_info,
  2644. + (u32)io_hdr->type);
  2645. + switch (io_hdr->type) {
  2646. + case IPTS_INPUT:
  2647. + ipts_dbg(ipts, "input detected\n");
  2648. + io_buf_type = IPTS_INPUT_ON;
  2649. + flags = IPTS_BUF_FLAG_CONTIGUOUS;
  2650. + break;
  2651. + case IPTS_OUTPUT:
  2652. + ipts_dbg(ipts, "output detected\n");
  2653. + io_buf_type = IPTS_OUTPUT_ON;
  2654. + output_idx++;
  2655. + break;
  2656. + default:
  2657. + if ((u32)io_hdr->type > 31) {
  2658. + ipts_err(ipts,
  2659. + "invalid io buffer : %u\n",
  2660. + (u32)io_hdr->type);
  2661. + continue;
  2662. + }
  2663. +
  2664. + if (is_alloc_cont_data(data_file))
  2665. + flags = IPTS_BUF_FLAG_CONTIGUOUS;
  2666. +
  2667. + io_buf_type = ((u32)1 << (u32)io_hdr->type);
  2668. + ipts_dbg(ipts, "special io buffer %u\n",
  2669. + io_hdr->type);
  2670. + break;
  2671. + }
  2672. +
  2673. + initialize = false;
  2674. + }
  2675. + }
  2676. +
  2677. + num_of_alloc = alloc_info->num_of_allocations;
  2678. + buf_idx = bin_find_alloc(ipts, alloc_info, res->handle);
  2679. + if (buf_idx == -1) {
  2680. + ipts_dbg(ipts, "cannot find alloc info\n");
  2681. + return -EINVAL;
  2682. + }
  2683. + for (parallel_idx = 0; parallel_idx < num_of_parallels;
  2684. + parallel_idx++, buf_idx += num_of_alloc) {
  2685. + if (!res->aligned_size)
  2686. + continue;
  2687. +
  2688. + if (!(parallel_idx == 0 ||
  2689. + (io_buf_type && !is_shared_data(data_file))))
  2690. + continue;
  2691. +
  2692. + buf_size = res->aligned_size;
  2693. + if (io_buf_type & IPTS_INPUT_ON) {
  2694. + buf_size = max_t(u32,
  2695. + ipts->device_info.frame_size,
  2696. + buf_size);
  2697. + wl[parallel_idx].iobuf_input = buf_idx;
  2698. + } else if (io_buf_type & IPTS_OUTPUT_ON) {
  2699. + wl[parallel_idx].iobuf_output[output_idx] = buf_idx;
  2700. +
  2701. + if (!is_parsing_vendor_kernel(parse_info) &&
  2702. + output_idx > 0) {
  2703. + ipts_err(ipts,
  2704. + "postproc with more than one inout"
  2705. + " is not supported : %d\n", output_idx);
  2706. + return -EINVAL;
  2707. + }
  2708. + }
  2709. +
  2710. + if (!is_parsing_vendor_kernel(parse_info) &&
  2711. + io_buf_type & IPTS_OUTPUT_ON) {
  2712. + buf = bin_get_vendor_kernel_output(
  2713. + parse_info,
  2714. + parallel_idx);
  2715. + alloc_info->buffs[buf_idx].no_unmap = true;
  2716. + } else
  2717. + buf = ipts_map_buffer(ipts, buf_size, flags);
  2718. +
  2719. + if (buf == NULL) {
  2720. + ipts_dbg(ipts, "ipts_map_buffer failed\n");
  2721. + return -ENOMEM;
  2722. + }
  2723. +
  2724. + if (initialize) {
  2725. + memcpy((void *)buf->cpu_addr, &(res->data[0]),
  2726. + res->size);
  2727. + } else {
  2728. + if (data_file && strlen(data_file->file_name)) {
  2729. + bin_read_fw(ipts, data_file->file_name,
  2730. + buf->cpu_addr, buf_size);
  2731. + } else if (is_parsing_vendor_kernel(parse_info) ||
  2732. + !(io_buf_type & IPTS_OUTPUT_ON)) {
  2733. + memset((void *)buf->cpu_addr, 0, res->size);
  2734. + }
  2735. + }
  2736. +
  2737. + alloc_info->buffs[buf_idx].buf = buf;
  2738. + }
  2739. + }
  2740. +
  2741. + alloc_info->num_of_outputs = output_idx + 1;
  2742. + parse_info->parsed = parsed;
  2743. +
  2744. + return 0;
  2745. +}
  2746. +
  2747. +static int bin_read_patch_list(ipts_info_t *ipts,
  2748. + bin_parse_info_t *parse_info,
  2749. + bin_alloc_info_t *alloc_info,
  2750. + bin_workload_t *wl)
  2751. +{
  2752. + ipts_bin_patch_list_t *patch_list;
  2753. + ipts_bin_patch_t *patch;
  2754. + intel_ipts_mapbuffer_t *cmd = NULL;
  2755. + u8 *batch;
  2756. + int parsed, size, i, parallel_idx, num_of_parallels, cmd_idx, buf_idx;
  2757. + unsigned int gtt_offset;
  2758. +
  2759. + parsed = parse_info->parsed;
  2760. + size = parse_info->size;
  2761. + patch_list = (ipts_bin_patch_list_t *)&parse_info->data[parsed];
  2762. +
  2763. + if (sizeof(patch_list->num) > (size - parsed)) {
  2764. + return -EFAULT;
  2765. + }
  2766. + parsed += sizeof(patch_list->num);
  2767. +
  2768. + num_of_parallels = ipts_get_num_of_parallel_buffers(ipts);
  2769. + patch = (ipts_bin_patch_t *)(&patch_list->patch[0]);
  2770. + for (i = 0; i < patch_list->num; i++) {
  2771. + if (sizeof(patch_list->patch[0]) > (size - parsed)) {
  2772. + return -EFAULT;
  2773. + }
  2774. +
  2775. + for (parallel_idx = 0; parallel_idx < num_of_parallels;
  2776. + parallel_idx++) {
  2777. + cmd_idx = wl[parallel_idx].cmdbuf_index;
  2778. + buf_idx = patch[i].index + parallel_idx *
  2779. + alloc_info->num_of_allocations;
  2780. +
  2781. + if (alloc_info->buffs[buf_idx].buf == NULL) {
  2782. + /* buffer shared */
  2783. + buf_idx = patch[i].index;
  2784. + }
  2785. +
  2786. + cmd = alloc_info->buffs[cmd_idx].buf;
  2787. + batch = (char *)(u64)cmd->cpu_addr;
  2788. +
  2789. + gtt_offset = 0;
  2790. + if(alloc_info->buffs[buf_idx].buf != NULL) {
  2791. + gtt_offset = (u32)(u64)
  2792. + alloc_info->buffs[buf_idx].buf->gfx_addr;
  2793. + }
  2794. + gtt_offset += patch[i].alloc_offset;
  2795. +
  2796. + batch += patch[i].patch_offset;
  2797. + *(u32*)batch = gtt_offset;
  2798. + }
  2799. +
  2800. + parsed += sizeof(patch_list->patch[0]);
  2801. + }
  2802. +
  2803. + parse_info->parsed = parsed;
  2804. +
  2805. + return 0;
  2806. +}
  2807. +
  2808. +static int bin_read_guc_wq_item(ipts_info_t *ipts,
  2809. + bin_parse_info_t *parse_info,
  2810. + bin_guc_wq_item_t **guc_wq_item)
  2811. +{
  2812. + ipts_bin_guc_wq_info_t *bin_guc_wq;
  2813. + bin_guc_wq_item_t *item;
  2814. + u8 *wi_data;
  2815. + int size, parsed, hdr_size, wi_size;
  2816. + int i, batch_offset;
  2817. +
  2818. + parsed = parse_info->parsed;
  2819. + size = parse_info->size;
  2820. + bin_guc_wq = (ipts_bin_guc_wq_info_t *)&parse_info->data[parsed];
  2821. +
  2822. + wi_size = bin_guc_wq->size;
  2823. + wi_data = bin_guc_wq->data;
  2824. + batch_offset = bin_guc_wq->batch_offset;
  2825. + ipts_dbg(ipts, "wi size = %d, bt offset = %d\n", wi_size, batch_offset);
  2826. + for (i = 0; i < wi_size / sizeof(u32); i++) {
  2827. + ipts_dbg(ipts, "wi[%d] = 0x%08x\n", i, *((u32*)wi_data + i));
  2828. + }
  2829. + hdr_size = sizeof(bin_guc_wq->size) + sizeof(bin_guc_wq->batch_offset);
  2830. +
  2831. + if (hdr_size > (size - parsed)) {
  2832. + return -EINVAL;
  2833. + }
  2834. + parsed += hdr_size;
  2835. +
  2836. + item = vmalloc(sizeof(bin_guc_wq_item_t) + wi_size);
  2837. + if (item == NULL)
  2838. + return -ENOMEM;
  2839. +
  2840. + item->size = wi_size;
  2841. + item->batch_offset = batch_offset;
  2842. + memcpy(item->data, wi_data, wi_size);
  2843. +
  2844. + *guc_wq_item = item;
  2845. +
  2846. + parsed += wi_size;
  2847. + parse_info->parsed = parsed;
  2848. +
  2849. + return 0;
  2850. +}
  2851. +
  2852. +static int bin_setup_guc_workqueue(ipts_info_t *ipts,
  2853. + bin_kernel_list_t *kernel_list)
  2854. +{
  2855. + bin_alloc_info_t *alloc_info;
  2856. + bin_workload_t *wl;
  2857. + bin_kernel_info_t *kernel;
  2858. + u8 *wq_start, *wq_addr, *wi_data;
  2859. + bin_buffer_t *bin_buf;
  2860. + int wq_size, wi_size, parallel_idx, cmd_idx, k_idx, iter_size;
  2861. + int i, num_of_parallels, batch_offset, k_num, total_workload;
  2862. +
  2863. + wq_addr = (u8*)ipts->resource.wq_info.wq_addr;
  2864. + wq_size = ipts->resource.wq_info.wq_size;
  2865. + num_of_parallels = ipts_get_num_of_parallel_buffers(ipts);
  2866. + total_workload = ipts_get_wq_item_size(ipts);
  2867. + k_num = kernel_list->num_of_kernels;
  2868. +
  2869. + iter_size = total_workload * num_of_parallels;
  2870. + if (wq_size % iter_size) {
  2871. + ipts_err(ipts, "wq item cannot fit into wq\n");
  2872. + return -EINVAL;
  2873. + }
  2874. +
  2875. + wq_start = wq_addr;
  2876. + for (parallel_idx = 0; parallel_idx < num_of_parallels;
  2877. + parallel_idx++) {
  2878. + kernel = &kernel_list->kernels[0];
  2879. + for (k_idx = 0; k_idx < k_num; k_idx++, kernel++) {
  2880. + wl = kernel->wl;
  2881. + alloc_info = kernel->alloc_info;
  2882. +
  2883. + batch_offset = kernel->guc_wq_item->batch_offset;
  2884. + wi_size = kernel->guc_wq_item->size;
  2885. + wi_data = &kernel->guc_wq_item->data[0];
  2886. +
  2887. + cmd_idx = wl[parallel_idx].cmdbuf_index;
  2888. + bin_buf = &alloc_info->buffs[cmd_idx];
  2889. +
  2890. + /* Patch the WQ Data with proper batch buffer offset */
  2891. + *(u32*)(wi_data + batch_offset) =
  2892. + (u32)(unsigned long)(bin_buf->buf->gfx_addr);
  2893. +
  2894. + memcpy(wq_addr, wi_data, wi_size);
  2895. +
  2896. + wq_addr += wi_size;
  2897. + }
  2898. + }
  2899. +
  2900. + for (i = 0; i < (wq_size / iter_size) - 1; i++) {
  2901. + memcpy(wq_addr, wq_start, iter_size);
  2902. + wq_addr += iter_size;
  2903. + }
  2904. +
  2905. + return 0;
  2906. +}
  2907. +
  2908. +static int bin_read_bufid_patch(ipts_info_t *ipts,
  2909. + bin_parse_info_t *parse_info,
  2910. + ipts_bin_bufid_patch_t *bufid_patch)
  2911. +{
  2912. + ipts_bin_bufid_patch_t *patch;
  2913. + int size, parsed;
  2914. +
  2915. + parsed = parse_info->parsed;
  2916. + size = parse_info->size;
  2917. + patch = (ipts_bin_bufid_patch_t *)&parse_info->data[parsed];
  2918. +
  2919. + if (sizeof(ipts_bin_bufid_patch_t) > (size - parsed)) {
  2920. + ipts_dbg(ipts, "invalid bufid info\n");
  2921. + return -EINVAL;
  2922. + }
  2923. + parsed += sizeof(ipts_bin_bufid_patch_t);
  2924. +
  2925. + memcpy(bufid_patch, patch, sizeof(ipts_bin_bufid_patch_t));
  2926. +
  2927. + parse_info->parsed = parsed;
  2928. +
  2929. + return 0;
  2930. +}
  2931. +
  2932. +static int bin_setup_bufid_buffer(ipts_info_t *ipts, bin_kernel_list_t *kernel_list)
  2933. +{
  2934. + intel_ipts_mapbuffer_t *buf, *cmd_buf;
  2935. + bin_kernel_info_t *last_kernel;
  2936. + bin_alloc_info_t *alloc_info;
  2937. + bin_workload_t *wl;
  2938. + u8 *batch;
  2939. + int parallel_idx, num_of_parallels, cmd_idx;
  2940. + u32 mem_offset, imm_offset;
  2941. +
  2942. + buf = ipts_map_buffer(ipts, PAGE_SIZE, 0);
  2943. + if (!buf) {
  2944. + return -ENOMEM;
  2945. + }
  2946. +
  2947. + last_kernel = &kernel_list->kernels[kernel_list->num_of_kernels - 1];
  2948. +
  2949. + mem_offset = last_kernel->bufid_patch.mem_offset;
  2950. + imm_offset = last_kernel->bufid_patch.imm_offset;
  2951. + wl = last_kernel->wl;
  2952. + alloc_info = last_kernel->alloc_info;
  2953. +
  2954. + /* Initialize the buffer with default value */
  2955. + *((u32*)buf->cpu_addr) = LASTSUBMITID_DEFAULT_VALUE;
  2956. + ipts->current_buffer_index = LASTSUBMITID_DEFAULT_VALUE;
  2957. + ipts->last_buffer_completed = LASTSUBMITID_DEFAULT_VALUE;
  2958. + ipts->last_submitted_id = (int*)buf->cpu_addr;
  2959. +
  2960. + num_of_parallels = ipts_get_num_of_parallel_buffers(ipts);
  2961. + for (parallel_idx = 0; parallel_idx < num_of_parallels; parallel_idx++) {
  2962. + cmd_idx = wl[parallel_idx].cmdbuf_index;
  2963. + cmd_buf = alloc_info->buffs[cmd_idx].buf;
  2964. + batch = (u8*)(u64)cmd_buf->cpu_addr;
  2965. +
  2966. + *((u32*)(batch + mem_offset)) = (u32)(u64)(buf->gfx_addr);
  2967. + *((u32*)(batch + imm_offset)) = parallel_idx;
  2968. + }
  2969. +
  2970. + kernel_list->bufid_buf = buf;
  2971. +
  2972. + return 0;
  2973. +}
  2974. +
  2975. +static void unmap_buffers(ipts_info_t *ipts, bin_alloc_info_t *alloc_info)
  2976. +{
  2977. + bin_buffer_t *buffs;
  2978. + int i, num_of_buffers;
  2979. +
  2980. + num_of_buffers = alloc_info->num_of_buffers;
  2981. + buffs = &alloc_info->buffs[0];
  2982. +
  2983. + for (i = 0; i < num_of_buffers; i++) {
  2984. + if (buffs[i].no_unmap != true && buffs[i].buf != NULL)
  2985. + ipts_unmap_buffer(ipts, buffs[i].buf);
  2986. + }
  2987. +}
  2988. +
  2989. +static int load_kernel(ipts_info_t *ipts, bin_parse_info_t *parse_info,
  2990. + bin_kernel_info_t *kernel)
  2991. +{
  2992. + ipts_bin_header_t *hdr;
  2993. + bin_workload_t *wl;
  2994. + bin_alloc_info_t *alloc_info;
  2995. + bin_guc_wq_item_t *guc_wq_item = NULL;
  2996. + ipts_bin_bufid_patch_t bufid_patch;
  2997. + int num_of_parallels, ret;
  2998. +
  2999. + num_of_parallels = ipts_get_num_of_parallel_buffers(ipts);
  3000. +
  3001. + /* check header version and magic numbers */
  3002. + hdr = (ipts_bin_header_t *)parse_info->data;
  3003. + if (hdr->version != IPTS_BIN_HEADER_VERSION ||
  3004. + strncmp(hdr->str, "IOCL", 4) != 0) {
  3005. + ipts_err(ipts, "binary header is not correct version = %d, "
  3006. + "string = %c%c%c%c\n", hdr->version,
  3007. + hdr->str[0], hdr->str[1],
  3008. + hdr->str[2], hdr->str[3] );
  3009. + return -EINVAL;
  3010. + }
  3011. +
  3012. + parse_info->parsed = sizeof(ipts_bin_header_t);
  3013. + wl = vmalloc(sizeof(bin_workload_t) * num_of_parallels);
  3014. + if (wl == NULL)
  3015. + return -ENOMEM;
  3016. + memset(wl, 0, sizeof(bin_workload_t) * num_of_parallels);
  3017. +
  3018. + alloc_info = vmalloc(sizeof(bin_alloc_info_t));
  3019. + if (alloc_info == NULL) {
  3020. + vfree(wl);
  3021. + return -ENOMEM;
  3022. + }
  3023. + memset(alloc_info, 0, sizeof(bin_alloc_info_t));
  3024. +
  3025. + ipts_dbg(ipts, "kernel setup(size : %d)\n", parse_info->size);
  3026. +
  3027. + ret = bin_read_allocation_list(ipts, parse_info, alloc_info);
  3028. + if (ret) {
  3029. + ipts_dbg(ipts, "error read_allocation_list\n");
  3030. + goto setup_error;
  3031. + }
  3032. +
  3033. + ret = bin_read_cmd_buffer(ipts, parse_info, alloc_info, wl);
  3034. + if (ret) {
  3035. + ipts_dbg(ipts, "error read_cmd_buffer\n");
  3036. + goto setup_error;
  3037. + }
  3038. +
  3039. + ret = bin_read_res_list(ipts, parse_info, alloc_info, wl);
  3040. + if (ret) {
  3041. + ipts_dbg(ipts, "error read_res_list\n");
  3042. + goto setup_error;
  3043. + }
  3044. +
  3045. + ret = bin_read_patch_list(ipts, parse_info, alloc_info, wl);
  3046. + if (ret) {
  3047. + ipts_dbg(ipts, "error read_patch_list\n");
  3048. + goto setup_error;
  3049. + }
  3050. +
  3051. + ret = bin_read_guc_wq_item(ipts, parse_info, &guc_wq_item);
  3052. + if (ret) {
  3053. + ipts_dbg(ipts, "error read_guc_workqueue\n");
  3054. + goto setup_error;
  3055. + }
  3056. +
  3057. + memset(&bufid_patch, 0, sizeof(bufid_patch));
  3058. + ret = bin_read_bufid_patch(ipts, parse_info, &bufid_patch);
  3059. + if (ret) {
  3060. + ipts_dbg(ipts, "error read_bufid_patch\n");
  3061. + goto setup_error;
  3062. + }
  3063. +
  3064. + kernel->wl = wl;
  3065. + kernel->alloc_info = alloc_info;
  3066. + kernel->is_vendor = is_parsing_vendor_kernel(parse_info);
  3067. + kernel->guc_wq_item = guc_wq_item;
  3068. + memcpy(&kernel->bufid_patch, &bufid_patch, sizeof(bufid_patch));
  3069. +
  3070. + return 0;
  3071. +
  3072. +setup_error:
  3073. + vfree(guc_wq_item);
  3074. +
  3075. + unmap_buffers(ipts, alloc_info);
  3076. +
  3077. + vfree(alloc_info->buffs);
  3078. + vfree(alloc_info);
  3079. + vfree(wl);
  3080. +
  3081. + return ret;
  3082. +}
  3083. +
  3084. +void bin_setup_input_output(ipts_info_t *ipts, bin_kernel_list_t *kernel_list)
  3085. +{
  3086. + bin_kernel_info_t *vendor_kernel;
  3087. + bin_workload_t *wl;
  3088. + intel_ipts_mapbuffer_t *buf;
  3089. + bin_alloc_info_t *alloc_info;
  3090. + int parallel_idx, num_of_parallels, i, buf_idx;
  3091. +
  3092. + vendor_kernel = &kernel_list->kernels[0];
  3093. +
  3094. + wl = vendor_kernel->wl;
  3095. + alloc_info = vendor_kernel->alloc_info;
  3096. + ipts->resource.num_of_outputs = alloc_info->num_of_outputs;
  3097. + num_of_parallels = ipts_get_num_of_parallel_buffers(ipts);
  3098. +
  3099. + for (parallel_idx = 0; parallel_idx < num_of_parallels; parallel_idx++) {
  3100. + buf_idx = wl[parallel_idx].iobuf_input;
  3101. + buf = alloc_info->buffs[buf_idx].buf;
  3102. +
  3103. + ipts_dbg(ipts, "in_buf[%d](%d) c:%p, p:%p, g:%p\n",
  3104. + parallel_idx, buf_idx, (void*)buf->cpu_addr,
  3105. + (void*)buf->phy_addr, (void*)buf->gfx_addr);
  3106. +
  3107. + ipts_set_input_buffer(ipts, parallel_idx, buf->cpu_addr,
  3108. + buf->phy_addr);
  3109. +
  3110. + for (i = 0; i < alloc_info->num_of_outputs; i++) {
  3111. + buf_idx = wl[parallel_idx].iobuf_output[i];
  3112. + buf = alloc_info->buffs[buf_idx].buf;
  3113. +
  3114. + ipts_dbg(ipts, "out_buf[%d][%d] c:%p, p:%p, g:%p\n",
  3115. + parallel_idx, i, (void*)buf->cpu_addr,
  3116. + (void*)buf->phy_addr, (void*)buf->gfx_addr);
  3117. +
  3118. + ipts_set_output_buffer(ipts, parallel_idx, i,
  3119. + buf->cpu_addr, buf->phy_addr);
  3120. + }
  3121. + }
  3122. +}
  3123. +
  3124. +static void unload_kernel(ipts_info_t *ipts, bin_kernel_info_t *kernel)
  3125. +{
  3126. + bin_alloc_info_t *alloc_info = kernel->alloc_info;
  3127. + bin_guc_wq_item_t *guc_wq_item = kernel->guc_wq_item;
  3128. +
  3129. + if (guc_wq_item) {
  3130. + vfree(guc_wq_item);
  3131. + }
  3132. +
  3133. + if (alloc_info) {
  3134. + unmap_buffers(ipts, alloc_info);
  3135. +
  3136. + vfree(alloc_info->buffs);
  3137. + vfree(alloc_info);
  3138. + }
  3139. +}
  3140. +
  3141. +static int setup_kernel(ipts_info_t *ipts, bin_fw_list_t *fw_list)
  3142. +{
  3143. + bin_kernel_list_t *kernel_list = NULL;
  3144. + bin_kernel_info_t *kernel = NULL;
  3145. + const struct firmware *fw = NULL;
  3146. + bin_workload_t *wl;
  3147. + bin_fw_info_t *fw_info;
  3148. + char *fw_name, *fw_data;
  3149. + bin_parse_info_t parse_info;
  3150. + int ret = 0, kernel_idx = 0, num_of_kernels = 0;
  3151. + int vendor_output_idx, total_workload = 0;
  3152. + char fw_path[MAX_IOCL_FILE_PATH_LEN];
  3153. +
  3154. + num_of_kernels = fw_list->num_of_fws;
  3155. + kernel_list = vmalloc(sizeof(*kernel) * num_of_kernels + sizeof(*kernel_list));
  3156. + if (kernel_list == NULL)
  3157. + return -ENOMEM;
  3158. +
  3159. + memset(kernel_list, 0, sizeof(*kernel) * num_of_kernels + sizeof(*kernel_list));
  3160. + kernel_list->num_of_kernels = num_of_kernels;
  3161. + kernel = &kernel_list->kernels[0];
  3162. +
  3163. + fw_data = (char *)&fw_list->fw_info[0];
  3164. + for (kernel_idx = 0; kernel_idx < num_of_kernels; kernel_idx++) {
  3165. + fw_info = (bin_fw_info_t *)fw_data;
  3166. + fw_name = &fw_info->fw_name[0];
  3167. + vendor_output_idx = fw_info->vendor_output;
  3168. + snprintf(fw_path, MAX_IOCL_FILE_PATH_LEN, IPTS_FW_PATH_FMT, fw_name);
  3169. + ret = request_firmware(&fw, (const char *)fw_path, &ipts->cldev->dev);
  3170. + if (ret) {
  3171. + ipts_err(ipts, "cannot read fw %s\n", fw_path);
  3172. + goto error_exit;
  3173. + }
  3174. +
  3175. + parse_info.data = (u8*)fw->data;
  3176. + parse_info.size = fw->size;
  3177. + parse_info.parsed = 0;
  3178. + parse_info.fw_info = fw_info;
  3179. + parse_info.vendor_kernel = (kernel_idx == 0) ? NULL : &kernel[0];
  3180. + parse_info.interested_vendor_output = vendor_output_idx;
  3181. +
  3182. + ret = load_kernel(ipts, &parse_info, &kernel[kernel_idx]);
  3183. + if (ret) {
  3184. + ipts_err(ipts, "do_setup_kernel error : %d\n", ret);
  3185. + release_firmware(fw);
  3186. + goto error_exit;
  3187. + }
  3188. +
  3189. + release_firmware(fw);
  3190. +
  3191. + total_workload += kernel[kernel_idx].guc_wq_item->size;
  3192. +
  3193. + /* advance to the next kernel */
  3194. + fw_data += sizeof(bin_fw_info_t);
  3195. + fw_data += sizeof(bin_data_file_info_t) * fw_info->num_of_data_files;
  3196. + }
  3197. +
  3198. + ipts_set_wq_item_size(ipts, total_workload);
  3199. +
  3200. + ret = bin_setup_guc_workqueue(ipts, kernel_list);
  3201. + if (ret) {
  3202. + ipts_dbg(ipts, "error setup_guc_workqueue\n");
  3203. + goto error_exit;
  3204. + }
  3205. +
  3206. + ret = bin_setup_bufid_buffer(ipts, kernel_list);
  3207. + if (ret) {
  3208. + ipts_dbg(ipts, "error setup_lastbubmit_buffer\n");
  3209. + goto error_exit;
  3210. + }
  3211. +
  3212. + bin_setup_input_output(ipts, kernel_list);
  3213. +
  3214. + /* workload is not needed during run-time so free them */
  3215. + for (kernel_idx = 0; kernel_idx < num_of_kernels; kernel_idx++) {
  3216. + wl = kernel[kernel_idx].wl;
  3217. + vfree(wl);
  3218. + }
  3219. +
  3220. + ipts->kernel_handle = (u64)kernel_list;
  3221. +
  3222. + return 0;
  3223. +
  3224. +error_exit:
  3225. +
  3226. + for (kernel_idx = 0; kernel_idx < num_of_kernels; kernel_idx++) {
  3227. + wl = kernel[kernel_idx].wl;
  3228. + vfree(wl);
  3229. + unload_kernel(ipts, &kernel[kernel_idx]);
  3230. + }
  3231. +
  3232. + vfree(kernel_list);
  3233. +
  3234. + return ret;
  3235. +}
  3236. +
  3237. +
  3238. +static void release_kernel(ipts_info_t *ipts)
  3239. +{
  3240. + bin_kernel_list_t *kernel_list;
  3241. + bin_kernel_info_t *kernel;
  3242. + int k_idx, k_num;
  3243. +
  3244. + kernel_list = (bin_kernel_list_t *)ipts->kernel_handle;
  3245. + k_num = kernel_list->num_of_kernels;
  3246. + kernel = &kernel_list->kernels[0];
  3247. +
  3248. + for (k_idx = 0; k_idx < k_num; k_idx++) {
  3249. + unload_kernel(ipts, kernel);
  3250. + kernel++;
  3251. + }
  3252. +
  3253. + ipts_unmap_buffer(ipts, kernel_list->bufid_buf);
  3254. +
  3255. + vfree(kernel_list);
  3256. + ipts->kernel_handle = 0;
  3257. +}
  3258. +
  3259. +int ipts_init_kernels(ipts_info_t *ipts)
  3260. +{
  3261. + const struct firmware *config_fw = NULL;
  3262. + const char *config_fw_path = IPTS_FW_CONFIG_FILE;
  3263. + bin_fw_list_t *fw_list;
  3264. + int ret;
  3265. +
  3266. + ret = ipts_open_gpu(ipts);
  3267. + if (ret) {
  3268. + ipts_err(ipts, "open gpu error : %d\n", ret);
  3269. + return ret;
  3270. + }
  3271. +
  3272. + ret = request_firmware(&config_fw, config_fw_path, &ipts->cldev->dev);
  3273. + if (ret) {
  3274. + ipts_err(ipts, "request firmware error : %d\n", ret);
  3275. + goto close_gpu;
  3276. + }
  3277. +
  3278. + fw_list = (bin_fw_list_t *)config_fw->data;
  3279. + ret = setup_kernel(ipts, fw_list);
  3280. + if (ret) {
  3281. + ipts_err(ipts, "setup kernel error : %d\n", ret);
  3282. + goto close_firmware;
  3283. + }
  3284. +
  3285. + release_firmware(config_fw);
  3286. +
  3287. + return ret;
  3288. +
  3289. +close_firmware:
  3290. + release_firmware(config_fw);
  3291. +
  3292. +close_gpu:
  3293. + ipts_close_gpu(ipts);
  3294. +
  3295. + return ret;
  3296. +}
  3297. +
  3298. +void ipts_release_kernels(ipts_info_t *ipts)
  3299. +{
  3300. + release_kernel(ipts);
  3301. + ipts_close_gpu(ipts);
  3302. +}
  3303. diff --git a/drivers/misc/ipts/ipts-kernel.h b/drivers/misc/ipts/ipts-kernel.h
  3304. new file mode 100644
  3305. index 0000000..0e7f139
  3306. --- /dev/null
  3307. +++ b/drivers/misc/ipts/ipts-kernel.h
  3308. @@ -0,0 +1,23 @@
  3309. +/*
  3310. + *
  3311. + * Intel Precise Touch & Stylus Linux driver
  3312. + * Copyright (c) 2016, Intel Corporation.
  3313. + *
  3314. + * This program is free software; you can redistribute it and/or modify it
  3315. + * under the terms and conditions of the GNU General Public License,
  3316. + * version 2, as published by the Free Software Foundation.
  3317. + *
  3318. + * This program is distributed in the hope it will be useful, but WITHOUT
  3319. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  3320. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  3321. + * more details.
  3322. + *
  3323. + */
  3324. +
  3325. +#ifndef _ITPS_GFX_H
  3326. +#define _ITPS_GFX_H
  3327. +
  3328. +int ipts_init_kernels(ipts_info_t *ipts);
  3329. +void ipts_release_kernels(ipts_info_t *ipts);
  3330. +
  3331. +#endif
  3332. diff --git a/drivers/misc/ipts/ipts-mei-msgs.h b/drivers/misc/ipts/ipts-mei-msgs.h
  3333. new file mode 100644
  3334. index 0000000..8ca1468
  3335. --- /dev/null
  3336. +++ b/drivers/misc/ipts/ipts-mei-msgs.h
  3337. @@ -0,0 +1,585 @@
  3338. +/*
  3339. + * Precise Touch HECI Message
  3340. + *
  3341. + * Copyright (c) 2013-2016, Intel Corporation.
  3342. + *
  3343. + * This program is free software; you can redistribute it and/or modify it
  3344. + * under the terms and conditions of the GNU General Public License,
  3345. + * version 2, as published by the Free Software Foundation.
  3346. + *
  3347. + * This program is distributed in the hope it will be useful, but WITHOUT
  3348. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  3349. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  3350. + * more details.
  3351. + */
  3352. +
  3353. +#ifndef _IPTS_MEI_MSGS_H_
  3354. +#define _IPTS_MEI_MSGS_H_
  3355. +
  3356. +#include "ipts-sensor-regs.h"
  3357. +
  3358. +#pragma pack(1)
  3359. +
  3360. +
  3361. +// Initial protocol version
  3362. +#define TOUCH_HECI_CLIENT_PROTOCOL_VERSION 10
  3363. +
  3364. +// GUID that identifies the Touch HECI client.
  3365. +#define TOUCH_HECI_CLIENT_GUID \
  3366. + {0x3e8d0870, 0x271a, 0x4208, {0x8e, 0xb5, 0x9a, 0xcb, 0x94, 0x02, 0xae, 0x04}}
  3367. +
  3368. +
  3369. +// define C_ASSERT macro to check structure size and fail compile for unexpected mismatch
  3370. +#ifndef C_ASSERT
  3371. +#define C_ASSERT(e) typedef char __C_ASSERT__[(e)?1:-1]
  3372. +#endif
  3373. +
  3374. +
  3375. +// General Type Defines for compatibility with HID driver and BIOS
  3376. +#ifndef BIT0
  3377. +#define BIT0 1
  3378. +#endif
  3379. +#ifndef BIT1
  3380. +#define BIT1 2
  3381. +#endif
  3382. +#ifndef BIT2
  3383. +#define BIT2 4
  3384. +#endif
  3385. +
  3386. +
  3387. +#define TOUCH_SENSOR_GET_DEVICE_INFO_CMD 0x00000001
  3388. +#define TOUCH_SENSOR_GET_DEVICE_INFO_RSP 0x80000001
  3389. +
  3390. +
  3391. +#define TOUCH_SENSOR_SET_MODE_CMD 0x00000002
  3392. +#define TOUCH_SENSOR_SET_MODE_RSP 0x80000002
  3393. +
  3394. +
  3395. +#define TOUCH_SENSOR_SET_MEM_WINDOW_CMD 0x00000003
  3396. +#define TOUCH_SENSOR_SET_MEM_WINDOW_RSP 0x80000003
  3397. +
  3398. +
  3399. +#define TOUCH_SENSOR_QUIESCE_IO_CMD 0x00000004
  3400. +#define TOUCH_SENSOR_QUIESCE_IO_RSP 0x80000004
  3401. +
  3402. +
  3403. +#define TOUCH_SENSOR_HID_READY_FOR_DATA_CMD 0x00000005
  3404. +#define TOUCH_SENSOR_HID_READY_FOR_DATA_RSP 0x80000005
  3405. +
  3406. +
  3407. +#define TOUCH_SENSOR_FEEDBACK_READY_CMD 0x00000006
  3408. +#define TOUCH_SENSOR_FEEDBACK_READY_RSP 0x80000006
  3409. +
  3410. +
  3411. +#define TOUCH_SENSOR_CLEAR_MEM_WINDOW_CMD 0x00000007
  3412. +#define TOUCH_SENSOR_CLEAR_MEM_WINDOW_RSP 0x80000007
  3413. +
  3414. +
  3415. +#define TOUCH_SENSOR_NOTIFY_DEV_READY_CMD 0x00000008
  3416. +#define TOUCH_SENSOR_NOTIFY_DEV_READY_RSP 0x80000008
  3417. +
  3418. +
  3419. +#define TOUCH_SENSOR_SET_POLICIES_CMD 0x00000009
  3420. +#define TOUCH_SENSOR_SET_POLICIES_RSP 0x80000009
  3421. +
  3422. +
  3423. +#define TOUCH_SENSOR_GET_POLICIES_CMD 0x0000000A
  3424. +#define TOUCH_SENSOR_GET_POLICIES_RSP 0x8000000A
  3425. +
  3426. +
  3427. +#define TOUCH_SENSOR_RESET_CMD 0x0000000B
  3428. +#define TOUCH_SENSOR_RESET_RSP 0x8000000B
  3429. +
  3430. +
  3431. +#define TOUCH_SENSOR_READ_ALL_REGS_CMD 0x0000000C
  3432. +#define TOUCH_SENSOR_READ_ALL_REGS_RSP 0x8000000C
  3433. +
  3434. +
  3435. +#define TOUCH_SENSOR_CMD_ERROR_RSP 0x8FFFFFFF // M2H: ME sends this message to indicate previous command was unrecognized/unsupported
  3436. +
  3437. +
  3438. +
  3439. +//*******************************************************************
  3440. +//
  3441. +// Touch Sensor Status Codes
  3442. +//
  3443. +//*******************************************************************
  3444. +typedef enum touch_status
  3445. +{
  3446. + TOUCH_STATUS_SUCCESS = 0, // 0 Requested operation was successful
  3447. + TOUCH_STATUS_INVALID_PARAMS, // 1 Invalid parameter(s) sent
  3448. + TOUCH_STATUS_ACCESS_DENIED, // 2 Unable to validate address range
  3449. + TOUCH_STATUS_CMD_SIZE_ERROR, // 3 HECI message incorrect size for specified command
  3450. + TOUCH_STATUS_NOT_READY, // 4 Memory window not set or device is not armed for operation
  3451. + TOUCH_STATUS_REQUEST_OUTSTANDING, // 5 There is already an outstanding message of the same type, must wait for response before sending another request of that type
  3452. + TOUCH_STATUS_NO_SENSOR_FOUND, // 6 Sensor could not be found. Either no sensor is connected, the sensor has not yet initialized, or the system is improperly configured.
  3453. + TOUCH_STATUS_OUT_OF_MEMORY, // 7 Not enough memory/storage for requested operation
  3454. + TOUCH_STATUS_INTERNAL_ERROR, // 8 Unexpected error occurred
  3455. + TOUCH_STATUS_SENSOR_DISABLED, // 9 Used in TOUCH_SENSOR_HID_READY_FOR_DATA_RSP to indicate sensor has been disabled or reset and must be reinitialized.
  3456. + TOUCH_STATUS_COMPAT_CHECK_FAIL, // 10 Used to indicate compatibility revision check between sensor and ME failed, or protocol ver between ME/HID/Kernels failed.
  3457. + TOUCH_STATUS_SENSOR_EXPECTED_RESET, // 11 Indicates sensor went through a reset initiated by ME
  3458. + TOUCH_STATUS_SENSOR_UNEXPECTED_RESET, // 12 Indicates sensor went through an unexpected reset
  3459. + TOUCH_STATUS_RESET_FAILED, // 13 Requested sensor reset failed to complete
  3460. + TOUCH_STATUS_TIMEOUT, // 14 Operation timed out
  3461. + TOUCH_STATUS_TEST_MODE_FAIL, // 15 Test mode pattern did not match expected values
  3462. + TOUCH_STATUS_SENSOR_FAIL_FATAL, // 16 Indicates sensor reported fatal error during reset sequence. Further progress is not possible.
  3463. + TOUCH_STATUS_SENSOR_FAIL_NONFATAL, // 17 Indicates sensor reported non-fatal error during reset sequence. HID/BIOS logs error and attempts to continue.
  3464. + TOUCH_STATUS_INVALID_DEVICE_CAPS, // 18 Indicates sensor reported invalid capabilities, such as not supporting required minimum frequency or I/O mode.
  3465. + TOUCH_STATUS_QUIESCE_IO_IN_PROGRESS, // 19 Indicates that command cannot be complete until ongoing Quiesce I/O flow has completed.
  3466. + TOUCH_STATUS_MAX // 20 Invalid value, never returned
  3467. +} touch_status_t;
  3468. +C_ASSERT(sizeof(touch_status_t) == 4);
  3469. +
  3470. +
  3471. +
  3472. +//*******************************************************************
  3473. +//
  3474. +// Defines for message structures used for Host to ME communication
  3475. +//
  3476. +//*******************************************************************
  3477. +
  3478. +
  3479. +typedef enum touch_sensor_mode
  3480. +{
  3481. + TOUCH_SENSOR_MODE_HID = 0, // Set mode to HID mode
  3482. + TOUCH_SENSOR_MODE_RAW_DATA, // Set mode to Raw Data mode
  3483. + TOUCH_SENSOR_MODE_SENSOR_DEBUG = 4, // Used like TOUCH_SENSOR_MODE_HID but data coming from sensor is not necessarily a HID packet.
  3484. + TOUCH_SENSOR_MODE_MAX // Invalid value
  3485. +} touch_sensor_mode_t;
  3486. +C_ASSERT(sizeof(touch_sensor_mode_t) == 4);
  3487. +
  3488. +typedef struct touch_sensor_set_mode_cmd_data
  3489. +{
  3490. + touch_sensor_mode_t sensor_mode; // Indicate desired sensor mode
  3491. + u32 Reserved[3]; // For future expansion
  3492. +} touch_sensor_set_mode_cmd_data_t;
  3493. +C_ASSERT(sizeof(touch_sensor_set_mode_cmd_data_t) == 16);
  3494. +
  3495. +
  3496. +#define TOUCH_SENSOR_MAX_DATA_BUFFERS 16
  3497. +#define TOUCH_HID_2_ME_BUFFER_ID TOUCH_SENSOR_MAX_DATA_BUFFERS
  3498. +#define TOUCH_HID_2_ME_BUFFER_SIZE_MAX 1024
  3499. +#define TOUCH_INVALID_BUFFER_ID 0xFF
  3500. +
  3501. +typedef struct touch_sensor_set_mem_window_cmd_data
  3502. +{
  3503. + u32 touch_data_buffer_addr_lower[TOUCH_SENSOR_MAX_DATA_BUFFERS]; // Lower 32 bits of Touch Data Buffer physical address. Size of each buffer should be TOUCH_SENSOR_GET_DEVICE_INFO_RSP_DATA.FrameSize
  3504. + u32 touch_data_buffer_addr_upper[TOUCH_SENSOR_MAX_DATA_BUFFERS]; // Upper 32 bits of Touch Data Buffer physical address. Size of each buffer should be TOUCH_SENSOR_GET_DEVICE_INFO_RSP_DATA.FrameSize
  3505. + u32 tail_offset_addr_lower; // Lower 32 bits of Tail Offset physical address
  3506. + u32 tail_offset_addr_upper; // Upper 32 bits of Tail Offset physical address, always 32 bit, increment by WorkQueueItemSize
  3507. + u32 doorbell_cookie_addr_lower; // Lower 32 bits of Doorbell register physical address
  3508. + u32 doorbell_cookie_addr_upper; // Upper 32 bits of Doorbell register physical address, always 32 bit, increment as integer, rollover to 1
  3509. + u32 feedback_buffer_addr_lower[TOUCH_SENSOR_MAX_DATA_BUFFERS]; // Lower 32 bits of Feedback Buffer physical address. Size of each buffer should be TOUCH_SENSOR_GET_DEVICE_INFO_RSP_DATA.FeedbackSize
  3510. + u32 feedback_buffer_addr_upper[TOUCH_SENSOR_MAX_DATA_BUFFERS]; // Upper 32 bits of Feedback Buffer physical address. Size of each buffer should be TOUCH_SENSOR_GET_DEVICE_INFO_RSP_DATA.FeedbackSize
  3511. + u32 hid2me_buffer_addr_lower; // Lower 32 bits of dedicated HID to ME communication buffer. Size is Hid2MeBufferSize.
  3512. + u32 hid2me_buffer_addr_upper; // Upper 32 bits of dedicated HID to ME communication buffer. Size is Hid2MeBufferSize.
  3513. + u32 hid2me_buffer_size; // Size in bytes of Hid2MeBuffer, can be no bigger than TOUCH_HID_2_ME_BUFFER_SIZE_MAX
  3514. + u8 reserved1; // For future expansion
  3515. + u8 work_queue_item_size; // Size in bytes of the GuC Work Queue Item pointed to by TailOffset
  3516. + u16 work_queue_size; // Size in bytes of the entire GuC Work Queue
  3517. + u32 reserved[8]; // For future expansion
  3518. +} touch_sensor_set_mem_window_cmd_data_t;
  3519. +C_ASSERT(sizeof(touch_sensor_set_mem_window_cmd_data_t) == 320);
  3520. +
  3521. +
  3522. +#define TOUCH_SENSOR_QUIESCE_FLAG_GUC_RESET BIT0 // indicates GuC got reset and ME must re-read GuC data such as TailOffset and Doorbell Cookie values
  3523. +
  3524. +typedef struct touch_sensor_quiesce_io_cmd_data
  3525. +{
  3526. + u32 quiesce_flags; // Optionally set TOUCH_SENSOR_QUIESCE_FLAG_GUC_RESET
  3527. + u32 reserved[2];
  3528. +} touch_sensor_quiesce_io_cmd_data_t;
  3529. +C_ASSERT(sizeof(touch_sensor_quiesce_io_cmd_data_t) == 12);
  3530. +
  3531. +
  3532. +typedef struct touch_sensor_feedback_ready_cmd_data
  3533. +{
  3534. + u8 feedback_index; // Index value from 0 to TOUCH_HID_2_ME_BUFFER_ID used to indicate which Feedback Buffer to use. Using special value TOUCH_HID_2_ME_BUFFER_ID
  3535. + // is an indication to ME to get feedback data from the Hid2Me buffer instead of one of the standard Feedback buffers.
  3536. + u8 reserved1[3]; // For future expansion
  3537. + u32 transaction_id; // Transaction ID that was originally passed to host in TOUCH_HID_PRIVATE_DATA. Used to track round trip of a given transaction for performance measurements.
  3538. + u32 reserved2[2]; // For future expansion
  3539. +} touch_sensor_feedback_ready_cmd_data_t;
  3540. +C_ASSERT(sizeof(touch_sensor_feedback_ready_cmd_data_t) == 16);
  3541. +
  3542. +
  3543. +#define TOUCH_DEFAULT_DOZE_TIMER_SECONDS 30
  3544. +
  3545. +typedef enum touch_freq_override
  3546. +{
  3547. + TOUCH_FREQ_OVERRIDE_NONE, // Do not apply any override
  3548. + TOUCH_FREQ_OVERRIDE_10MHZ, // Force frequency to 10MHz (not currently supported)
  3549. + TOUCH_FREQ_OVERRIDE_17MHZ, // Force frequency to 17MHz
  3550. + TOUCH_FREQ_OVERRIDE_30MHZ, // Force frequency to 30MHz
  3551. + TOUCH_FREQ_OVERRIDE_50MHZ, // Force frequency to 50MHz (not currently supported)
  3552. + TOUCH_FREQ_OVERRIDE_MAX // Invalid value
  3553. +} touch_freq_override_t;
  3554. +C_ASSERT(sizeof(touch_freq_override_t) == 4);
  3555. +
  3556. +typedef enum touch_spi_io_mode_override
  3557. +{
  3558. + TOUCH_SPI_IO_MODE_OVERRIDE_NONE, // Do not apply any override
  3559. + TOUCH_SPI_IO_MODE_OVERRIDE_SINGLE, // Force Single I/O
  3560. + TOUCH_SPI_IO_MODE_OVERRIDE_DUAL, // Force Dual I/O
  3561. + TOUCH_SPI_IO_MODE_OVERRIDE_QUAD, // Force Quad I/O
  3562. + TOUCH_SPI_IO_MODE_OVERRIDE_MAX // Invalid value
  3563. +} touch_spi_io_mode_override_t;
  3564. +C_ASSERT(sizeof(touch_spi_io_mode_override_t) == 4);
  3565. +
  3566. +// Debug Policy bits used by TOUCH_POLICY_DATA.DebugOverride
  3567. +#define TOUCH_DBG_POLICY_OVERRIDE_STARTUP_TIMER_DIS BIT0 // Disable sensor startup timer
  3568. +#define TOUCH_DBG_POLICY_OVERRIDE_SYNC_BYTE_DIS BIT1 // Disable Sync Byte check
  3569. +#define TOUCH_DBG_POLICY_OVERRIDE_ERR_RESET_DIS BIT2 // Disable error resets
  3570. +
  3571. +typedef struct touch_policy_data
  3572. +{
  3573. + u32 reserved0; // For future expansion.
  3574. + u32 doze_timer :16; // Value in seconds, after which ME will put the sensor into Doze power state if no activity occurs. Set
  3575. + // to 0 to disable Doze mode (not recommended). Value will be set to TOUCH_DEFAULT_DOZE_TIMER_SECONDS by
  3576. + // default.
  3577. + touch_freq_override_t freq_override :3; // Override frequency requested by sensor
  3578. + touch_spi_io_mode_override_t spi_io_override :3; // Override IO mode requested by sensor
  3579. + u32 reserved1 :10; // For future expansion
  3580. + u32 reserved2; // For future expansion
  3581. + u32 debug_override; // Normally all bits will be zero. Bits will be defined as needed for enabling special debug features
  3582. +} touch_policy_data_t;
  3583. +C_ASSERT(sizeof(touch_policy_data_t) == 16);
  3584. +
  3585. +typedef struct touch_sensor_set_policies_cmd_data
  3586. +{
  3587. + touch_policy_data_t policy_data; // Contains the desired policy to be set
  3588. +} touch_sensor_set_policies_cmd_data_t;
  3589. +C_ASSERT(sizeof(touch_sensor_set_policies_cmd_data_t) == 16);
  3590. +
  3591. +
  3592. +typedef enum touch_sensor_reset_type
  3593. +{
  3594. + TOUCH_SENSOR_RESET_TYPE_HARD, // Hardware Reset using dedicated GPIO pin
  3595. + TOUCH_SENSOR_RESET_TYPE_SOFT, // Software Reset using command written over SPI interface
  3596. + TOUCH_SENSOR_RESET_TYPE_MAX // Invalid value
  3597. +} touch_sensor_reset_type_t;
  3598. +C_ASSERT(sizeof(touch_sensor_reset_type_t) == 4);
  3599. +
  3600. +typedef struct touch_sensor_reset_cmd_data
  3601. +{
  3602. + touch_sensor_reset_type_t reset_type; // Indicate desired reset type
  3603. + u32 reserved; // For future expansion
  3604. +} touch_sensor_reset_cmd_data_t;
  3605. +C_ASSERT(sizeof(touch_sensor_reset_cmd_data_t) == 8);
  3606. +
  3607. +
  3608. +//
  3609. +// Host to ME message
  3610. +//
  3611. +typedef struct touch_sensor_msg_h2m
  3612. +{
  3613. + u32 command_code;
  3614. + union
  3615. + {
  3616. + touch_sensor_set_mode_cmd_data_t set_mode_cmd_data;
  3617. + touch_sensor_set_mem_window_cmd_data_t set_window_cmd_data;
  3618. + touch_sensor_quiesce_io_cmd_data_t quiesce_io_cmd_data;
  3619. + touch_sensor_feedback_ready_cmd_data_t feedback_ready_cmd_data;
  3620. + touch_sensor_set_policies_cmd_data_t set_policies_cmd_data;
  3621. + touch_sensor_reset_cmd_data_t reset_cmd_data;
  3622. + } h2m_data;
  3623. +} touch_sensor_msg_h2m_t;
  3624. +C_ASSERT(sizeof(touch_sensor_msg_h2m_t) == 324);
  3625. +
  3626. +
  3627. +//*******************************************************************
  3628. +//
  3629. +// Defines for message structures used for ME to Host communication
  3630. +//
  3631. +//*******************************************************************
  3632. +
  3633. +// I/O mode values used by TOUCH_SENSOR_GET_DEVICE_INFO_RSP_DATA.
  3634. +typedef enum touch_spi_io_mode
  3635. +{
  3636. + TOUCH_SPI_IO_MODE_SINGLE = 0, // Sensor set for Single I/O SPI
  3637. + TOUCH_SPI_IO_MODE_DUAL, // Sensor set for Dual I/O SPI
  3638. + TOUCH_SPI_IO_MODE_QUAD, // Sensor set for Quad I/O SPI
  3639. + TOUCH_SPI_IO_MODE_MAX // Invalid value
  3640. +} touch_spi_io_mode_t;
  3641. +C_ASSERT(sizeof(touch_spi_io_mode_t) == 4);
  3642. +
  3643. +//
  3644. +// TOUCH_SENSOR_GET_DEVICE_INFO_RSP code is sent in response to TOUCH_SENSOR_GET_DEVICE_INFO_CMD. This code will be followed
  3645. +// by TOUCH_SENSOR_GET_DEVICE_INFO_RSP_DATA.
  3646. +//
  3647. +// Possible Status values:
  3648. +// TOUCH_STATUS_SUCCESS: Command was processed successfully and sensor details are reported.
  3649. +// TOUCH_STATUS_CMD_SIZE_ERROR: Command sent did not match expected size. Other fields will not contain valid data.
  3650. +// TOUCH_STATUS_NO_SENSOR_FOUND: Sensor has not yet been detected. Other fields will not contain valid data.
  3651. +// TOUCH_STATUS_INVALID_DEVICE_CAPS: Indicates sensor does not support minimum required Frequency or I/O Mode. ME firmware will choose best possible option for the errant
  3652. +// field. Caller should attempt to continue.
  3653. +// TOUCH_STATUS_COMPAT_CHECK_FAIL: Indicates TouchIC/ME compatibility mismatch. Caller should attempt to continue.
  3654. +//
  3655. +typedef struct touch_sensor_get_device_info_rsp_data
  3656. +{
  3657. + u16 vendor_id; // Touch Sensor vendor ID
  3658. + u16 device_id; // Touch Sensor device ID
  3659. + u32 hw_rev; // Touch Sensor Hardware Revision
  3660. + u32 fw_rev; // Touch Sensor Firmware Revision
  3661. + u32 frame_size; // Max size of one frame returned by Touch IC in bytes. This data will be TOUCH_RAW_DATA_HDR followed
  3662. + // by a payload. The payload can be raw data or a HID structure depending on mode.
  3663. + u32 feedback_size; // Max size of one Feedback structure in bytes
  3664. + touch_sensor_mode_t sensor_mode; // Current operating mode of the sensor
  3665. + u32 max_touch_points :8; // Maximum number of simultaneous touch points that can be reported by sensor
  3666. + touch_freq_t spi_frequency :8; // SPI bus Frequency supported by sensor and ME firmware
  3667. + touch_spi_io_mode_t spi_io_mode :8; // SPI bus I/O Mode supported by sensor and ME firmware
  3668. + u32 reserved0 :8; // For future expansion
  3669. + u8 sensor_minor_eds_rev; // Minor version number of EDS spec supported by sensor (from Compat Rev ID Reg)
  3670. + u8 sensor_major_eds_rev; // Major version number of EDS spec supported by sensor (from Compat Rev ID Reg)
  3671. + u8 me_minor_eds_rev; // Minor version number of EDS spec supported by ME
  3672. + u8 me_major_eds_rev; // Major version number of EDS spec supported by ME
  3673. + u8 sensor_eds_intf_rev; // EDS Interface Revision Number supported by sensor (from Compat Rev ID Reg)
  3674. + u8 me_eds_intf_rev; // EDS Interface Revision Number supported by ME
  3675. + u8 kernel_compat_ver; // EU Kernel Compatibility Version (from Compat Rev ID Reg)
  3676. + u8 reserved1; // For future expansion
  3677. + u32 reserved2[2]; // For future expansion
  3678. +} touch_sensor_get_device_info_rsp_data_t;
  3679. +C_ASSERT(sizeof(touch_sensor_get_device_info_rsp_data_t) == 44);
  3680. +
  3681. +
  3682. +//
  3683. +// TOUCH_SENSOR_SET_MODE_RSP code is sent in response to TOUCH_SENSOR_SET_MODE_CMD. This code will be followed
  3684. +// by TOUCH_SENSOR_SET_MODE_RSP_DATA.
  3685. +//
  3686. +// Possible Status values:
  3687. +// TOUCH_STATUS_SUCCESS: Command was processed successfully and mode was set.
  3688. +// TOUCH_STATUS_CMD_SIZE_ERROR: Command sent did not match expected size. Other fields will not contain valid data.
  3689. +// TOUCH_STATUS_INVALID_PARAMS: Input parameters are out of range.
  3690. +//
  3691. +typedef struct touch_sensor_set_mode_rsp_data
  3692. +{
  3693. + u32 reserved[3]; // For future expansion
  3694. +} touch_sensor_set_mode_rsp_data_t;
  3695. +C_ASSERT(sizeof(touch_sensor_set_mode_rsp_data_t) == 12);
  3696. +
  3697. +
  3698. +//
  3699. +// TOUCH_SENSOR_SET_MEM_WINDOW_RSP code is sent in response to TOUCH_SENSOR_SET_MEM_WINDOW_CMD. This code will be followed
  3700. +// by TOUCH_SENSOR_SET_MEM_WINDOW_RSP_DATA.
  3701. +//
  3702. +// Possible Status values:
  3703. +// TOUCH_STATUS_SUCCESS: Command was processed successfully and memory window was set.
  3704. +// TOUCH_STATUS_CMD_SIZE_ERROR: Command sent did not match expected size. Other fields will not contain valid data.
  3705. +// TOUCH_STATUS_INVALID_PARAMS: Input parameters are out of range.
  3706. +// TOUCH_STATUS_ACCESS_DENIED: Unable to map host address ranges for DMA.
  3707. +// TOUCH_STATUS_OUT_OF_MEMORY: Unable to allocate enough space for needed buffers.
  3708. +//
  3709. +typedef struct touch_sensor_set_mem_window_rsp_data
  3710. +{
  3711. + u32 reserved[3]; // For future expansion
  3712. +} touch_sensor_set_mem_window_rsp_data_t;
  3713. +C_ASSERT(sizeof(touch_sensor_set_mem_window_rsp_data_t) == 12);
  3714. +
  3715. +
  3716. +//
  3717. +// TOUCH_SENSOR_QUIESCE_IO_RSP code is sent in response to TOUCH_SENSOR_QUIESCE_IO_CMD. This code will be followed
  3718. +// by TOUCH_SENSOR_QUIESCE_IO_RSP_DATA.
  3719. +//
  3720. +// Possible Status values:
  3721. +// TOUCH_STATUS_SUCCESS: Command was processed successfully and touch flow has stopped.
  3722. +// TOUCH_STATUS_CMD_SIZE_ERROR: Command sent did not match expected size. Other fields will not contain valid data.
  3723. +// TOUCH_STATUS_QUIESCE_IO_IN_PROGRESS: Indicates that Quiesce I/O is already in progress and this command cannot be accepted at this time.
  3724. +// TOUCH_STATIS_TIMEOUT: Indicates ME timed out waiting for Quiesce I/O flow to complete.
  3725. +//
  3726. +typedef struct touch_sensor_quiesce_io_rsp_data
  3727. +{
  3728. + u32 reserved[3]; // For future expansion
  3729. +} touch_sensor_quiesce_io_rsp_data_t;
  3730. +C_ASSERT(sizeof(touch_sensor_quiesce_io_rsp_data_t) == 12);
  3731. +
  3732. +
  3733. +// Reset Reason values used in TOUCH_SENSOR_HID_READY_FOR_DATA_RSP_DATA
  3734. +typedef enum touch_reset_reason
  3735. +{
  3736. + TOUCH_RESET_REASON_UNKNOWN = 0, // Reason for sensor reset is not known
  3737. + TOUCH_RESET_REASON_FEEDBACK_REQUEST, // Reset was requested as part of TOUCH_SENSOR_FEEDBACK_READY_CMD
  3738. + TOUCH_RESET_REASON_HECI_REQUEST, // Reset was requested via TOUCH_SENSOR_RESET_CMD
  3739. + TOUCH_RESET_REASON_MAX
  3740. +} touch_reset_reason_t;
  3741. +C_ASSERT(sizeof(touch_reset_reason_t) == 4);
  3742. +
  3743. +//
  3744. +// TOUCH_SENSOR_HID_READY_FOR_DATA_RSP code is sent in response to TOUCH_SENSOR_HID_READY_FOR_DATA_CMD. This code will be followed
  3745. +// by TOUCH_SENSOR_HID_READY_FOR_DATA_RSP_DATA.
  3746. +//
  3747. +// Possible Status values:
  3748. +// TOUCH_STATUS_SUCCESS: Command was processed successfully and HID data was sent by DMA. This will only be sent in HID mode.
  3749. +// TOUCH_STATUS_CMD_SIZE_ERROR: Command sent did not match expected size. Other fields will not contain valid data.
  3750. +// TOUCH_STATUS_REQUEST_OUTSTANDING: Previous request is still outstanding, ME FW cannot handle another request for the same command.
  3751. +// TOUCH_STATUS_NOT_READY: Indicates memory window has not yet been set by BIOS/HID.
  3752. +// TOUCH_STATUS_SENSOR_DISABLED: Indicates that ME to HID communication has been stopped either by TOUCH_SENSOR_QUIESCE_IO_CMD or TOUCH_SENSOR_CLEAR_MEM_WINDOW_CMD.
  3753. +// TOUCH_STATUS_SENSOR_UNEXPECTED_RESET: Sensor signaled a Reset Interrupt. ME did not expect this and has no info about why this occurred.
  3754. +// TOUCH_STATUS_SENSOR_EXPECTED_RESET: Sensor signaled a Reset Interrupt. ME either directly requested this reset, or it was expected as part of a defined flow in the EDS.
  3755. +// TOUCH_STATUS_QUIESCE_IO_IN_PROGRESS: Indicates that Quiesce I/O is already in progress and this command cannot be accepted at this time.
  3756. +// TOUCH_STATUS_TIMEOUT: Sensor did not generate a reset interrupt in the time allotted. Could indicate sensor is not connected or malfunctioning.
  3757. +//
  3758. +typedef struct touch_sensor_hid_ready_for_data_rsp_data
  3759. +{
  3760. + u32 data_size; // Size of the data the ME DMA'd into a RawDataBuffer. Valid only when Status == TOUCH_STATUS_SUCCESS
  3761. + u8 touch_data_buffer_index; // Index to indicate which RawDataBuffer was used. Valid only when Status == TOUCH_STATUS_SUCCESS
  3762. + u8 reset_reason; // If Status is TOUCH_STATUS_SENSOR_EXPECTED_RESET, ME will provide the cause. See TOUCH_RESET_REASON.
  3763. + u8 reserved1[2]; // For future expansion
  3764. + u32 reserved2[5]; // For future expansion
  3765. +} touch_sensor_hid_ready_for_data_rsp_data_t;
  3766. +C_ASSERT(sizeof(touch_sensor_hid_ready_for_data_rsp_data_t) == 28);
  3767. +
  3768. +
  3769. +//
  3770. +// TOUCH_SENSOR_FEEDBACK_READY_RSP code is sent in response to TOUCH_SENSOR_FEEDBACK_READY_CMD. This code will be followed
  3771. +// by TOUCH_SENSOR_FEEDBACK_READY_RSP_DATA.
  3772. +//
  3773. +// Possible Status values:
  3774. +// TOUCH_STATUS_SUCCESS: Command was processed successfully and any feedback or commands were sent to sensor.
  3775. +// TOUCH_STATUS_CMD_SIZE_ERROR: Command sent did not match expected size. Other fields will not contain valid data.
  3776. +// TOUCH_STATUS_INVALID_PARAMS: Input parameters are out of range.
  3777. +// TOUCH_STATUS_COMPAT_CHECK_FAIL Indicates ProtocolVer does not match ME supported version. (non-fatal error)
  3778. +// TOUCH_STATUS_INTERNAL_ERROR: Unexpected error occurred. This should not normally be seen.
  3779. +// TOUCH_STATUS_OUT_OF_MEMORY: Insufficient space to store Calibration Data
  3780. +//
  3781. +typedef struct touch_sensor_feedback_ready_rsp_data
  3782. +{
  3783. + u8 feedback_index; // Index value from 0 to TOUCH_SENSOR_MAX_DATA_BUFFERS used to indicate which Feedback Buffer to use
  3784. + u8 reserved1[3]; // For future expansion
  3785. + u32 reserved2[6]; // For future expansion
  3786. +} touch_sensor_feedback_ready_rsp_data_t;
  3787. +C_ASSERT(sizeof(touch_sensor_feedback_ready_rsp_data_t) == 28);
  3788. +
  3789. +
  3790. +//
  3791. +// TOUCH_SENSOR_CLEAR_MEM_WINDOW_RSP code is sent in response to TOUCH_SENSOR_CLEAR_MEM_WINDOW_CMD. This code will be followed
  3792. +// by TOUCH_SENSOR_CLEAR_MEM_WINDOW_RSP_DATA.
  3793. +//
  3794. +// Possible Status values:
  3795. +// TOUCH_STATUS_SUCCESS: Command was processed successfully and memory window was set.
  3796. +// TOUCH_STATUS_CMD_SIZE_ERROR: Command sent did not match expected size. Other fields will not contain valid data.
  3797. +// TOUCH_STATUS_INVALID_PARAMS: Input parameters are out of range.
  3798. +// TOUCH_STATUS_QUIESCE_IO_IN_PROGRESS: Indicates that Quiesce I/O is already in progress and this command cannot be accepted at this time.
  3799. +//
  3800. +typedef struct touch_sensor_clear_mem_window_rsp_data
  3801. +{
  3802. + u32 reserved[3]; // For future expansion
  3803. +} touch_sensor_clear_mem_window_rsp_data_t;
  3804. +C_ASSERT(sizeof(touch_sensor_clear_mem_window_rsp_data_t) == 12);
  3805. +
  3806. +
  3807. +//
  3808. +// TOUCH_SENSOR_NOTIFY_DEV_READY_RSP code is sent in response to TOUCH_SENSOR_NOTIFY_DEV_READY_CMD. This code will be followed
  3809. +// by TOUCH_SENSOR_NOTIFY_DEV_READY_RSP_DATA.
  3810. +//
  3811. +// Possible Status values:
  3812. +// TOUCH_STATUS_SUCCESS: Command was processed successfully and sensor has been detected by ME FW.
  3813. +// TOUCH_STATUS_CMD_SIZE_ERROR: Command sent did not match expected size.
  3814. +// TOUCH_STATUS_REQUEST_OUTSTANDING: Previous request is still outstanding, ME FW cannot handle another request for the same command.
  3815. +// TOUCH_STATUS_TIMEOUT: Sensor did not generate a reset interrupt in the time allotted. Could indicate sensor is not connected or malfunctioning.
  3816. +// TOUCH_STATUS_SENSOR_FAIL_FATAL: Sensor indicated a fatal error, further operation is not possible. Error details can be found in ErrReg.
  3817. +// TOUCH_STATUS_SENSOR_FAIL_NONFATAL: Sensor indicated a non-fatal error. Error should be logged by caller and init flow can continue. Error details can be found in ErrReg.
  3818. +//
  3819. +typedef struct touch_sensor_notify_dev_ready_rsp_data
  3820. +{
  3821. + touch_err_reg_t err_reg; // Value of sensor Error Register, field is only valid for Status == TOUCH_STATUS_SENSOR_FAIL_FATAL or TOUCH_STATUS_SENSOR_FAIL_NONFATAL
  3822. + u32 reserved[2]; // For future expansion
  3823. +} touch_sensor_notify_dev_ready_rsp_data_t;
  3824. +C_ASSERT(sizeof(touch_sensor_notify_dev_ready_rsp_data_t) == 12);
  3825. +
  3826. +
  3827. +//
  3828. +// TOUCH_SENSOR_SET_POLICIES_RSP code is sent in response to TOUCH_SENSOR_SET_POLICIES_CMD. This code will be followed
  3829. +// by TOUCH_SENSOR_SET_POLICIES_RSP_DATA.
  3830. +//
  3831. +// Possible Status values:
  3832. +// TOUCH_STATUS_SUCCESS: Command was processed successfully and new policies were set.
  3833. +// TOUCH_STATUS_CMD_SIZE_ERROR: Command sent did not match expected size. Other fields will not contain valid data.
  3834. +// TOUCH_STATUS_INVALID_PARAMS: Input parameters are out of range.
  3835. +//
  3836. +typedef struct touch_sensor_set_policies_rsp_data
  3837. +{
  3838. + u32 reserved[3]; // For future expansion
  3839. +} touch_sensor_set_policies_rsp_data_t;
  3840. +C_ASSERT(sizeof(touch_sensor_set_policies_rsp_data_t) == 12);
  3841. +
  3842. +
  3843. +//
  3844. +// TOUCH_SENSOR_GET_POLICIES_RSP code is sent in response to TOUCH_SENSOR_GET_POLICIES_CMD. This code will be followed
  3845. +// by TOUCH_SENSOR_GET_POLICIES_RSP_DATA.
  3846. +//
  3847. +// Possible Status values:
  3848. +// TOUCH_STATUS_SUCCESS: Command was processed successfully and new policies were set.
  3849. +// TOUCH_STATUS_CMD_SIZE_ERROR: Command sent did not match expected size. Other fields will not contain valid data.
  3850. +//
  3851. +typedef struct touch_sensor_get_policies_rsp_data
  3852. +{
  3853. + touch_policy_data_t policy_data; // Contains the current policy
  3854. +} touch_sensor_get_policies_rsp_data_t;
  3855. +C_ASSERT(sizeof(touch_sensor_get_policies_rsp_data_t) == 16);
  3856. +
  3857. +
  3858. +//
  3859. +// TOUCH_SENSOR_RESET_RSP code is sent in response to TOUCH_SENSOR_RESET_CMD. This code will be followed
  3860. +// by TOUCH_SENSOR_RESET_RSP_DATA.
  3861. +//
  3862. +// Possible Status values:
  3863. +// TOUCH_STATUS_SUCCESS: Command was processed successfully and sensor reset was completed.
  3864. +// TOUCH_STATUS_CMD_SIZE_ERROR: Command sent did not match expected size. Other fields will not contain valid data.
  3865. +// TOUCH_STATUS_INVALID_PARAMS: Input parameters are out of range.
  3866. +// TOUCH_STATUS_TIMEOUT: Sensor did not generate a reset interrupt in the time allotted. Could indicate sensor is not connected or malfunctioning.
  3867. +// TOUCH_STATUS_RESET_FAILED: Sensor generated an invalid or unexpected interrupt.
  3868. +// TOUCH_STATUS_QUIESCE_IO_IN_PROGRESS: Indicates that Quiesce I/O is already in progress and this command cannot be accepted at this time.
  3869. +//
  3870. +typedef struct touch_sensor_reset_rsp_data
  3871. +{
  3872. + u32 reserved[3]; // For future expansion
  3873. +} touch_sensor_reset_rsp_data_t;
  3874. +C_ASSERT(sizeof(touch_sensor_reset_rsp_data_t) == 12);
  3875. +
  3876. +
  3877. +//
  3878. +// TOUCH_SENSOR_READ_ALL_REGS_RSP code is sent in response to TOUCH_SENSOR_READ_ALL_REGS_CMD. This code will be followed
  3879. +// by TOUCH_SENSOR_READ_ALL_REGS_RSP_DATA.
  3880. +//
  3881. +// Possible Status values:
  3882. +// TOUCH_STATUS_SUCCESS: Command was processed successfully and new policies were set.
  3883. +// TOUCH_STATUS_CMD_SIZE_ERROR: Command sent did not match expected size. Other fields will not contain valid data.
  3884. +//
  3885. +typedef struct touch_sensor_read_all_regs_rsp_data
  3886. +{
  3887. + touch_reg_block_t sensor_regs; // Returns first 64 bytes of register space used for normal touch operation. Does not include test mode register.
  3888. + u32 reserved[4];
  3889. +} touch_sensor_read_all_regs_rsp_data_t;
  3890. +C_ASSERT(sizeof(touch_sensor_read_all_regs_rsp_data_t) == 80);
  3891. +
  3892. +//
  3893. +// ME to Host Message
  3894. +//
  3895. +typedef struct touch_sensor_msg_m2h
  3896. +{
  3897. + u32 command_code;
  3898. + touch_status_t status;
  3899. + union
  3900. + {
  3901. + touch_sensor_get_device_info_rsp_data_t device_info_rsp_data;
  3902. + touch_sensor_set_mode_rsp_data_t set_mode_rsp_data;
  3903. + touch_sensor_set_mem_window_rsp_data_t set_mem_window_rsp_data;
  3904. + touch_sensor_quiesce_io_rsp_data_t quiesce_io_rsp_data;
  3905. + touch_sensor_hid_ready_for_data_rsp_data_t hid_ready_for_data_rsp_data;
  3906. + touch_sensor_feedback_ready_rsp_data_t feedback_ready_rsp_data;
  3907. + touch_sensor_clear_mem_window_rsp_data_t clear_mem_window_rsp_data;
  3908. + touch_sensor_notify_dev_ready_rsp_data_t notify_dev_ready_rsp_data;
  3909. + touch_sensor_set_policies_rsp_data_t set_policies_rsp_data;
  3910. + touch_sensor_get_policies_rsp_data_t get_policies_rsp_data;
  3911. + touch_sensor_reset_rsp_data_t reset_rsp_data;
  3912. + touch_sensor_read_all_regs_rsp_data_t read_all_regs_rsp_data;
  3913. + } m2h_data;
  3914. +} touch_sensor_msg_m2h_t;
  3915. +C_ASSERT(sizeof(touch_sensor_msg_m2h_t) == 88);
  3916. +
  3917. +
  3918. +#define TOUCH_MSG_SIZE_MAX_BYTES (MAX(sizeof(touch_sensor_msg_m2h_t), sizeof(touch_sensor_msg_h2m_t)))
  3919. +
  3920. +#pragma pack()
  3921. +
  3922. +#endif // _IPTS_MEI_MSGS_H_
  3923. diff --git a/drivers/misc/ipts/ipts-mei.c b/drivers/misc/ipts/ipts-mei.c
  3924. new file mode 100644
  3925. index 0000000..39667e7
  3926. --- /dev/null
  3927. +++ b/drivers/misc/ipts/ipts-mei.c
  3928. @@ -0,0 +1,282 @@
  3929. +/*
  3930. + * MEI client driver for Intel Precise Touch and Stylus
  3931. + *
  3932. + * Copyright (c) 2016, Intel Corporation.
  3933. + *
  3934. + * This program is free software; you can redistribute it and/or modify it
  3935. + * under the terms and conditions of the GNU General Public License,
  3936. + * version 2, as published by the Free Software Foundation.
  3937. + *
  3938. + * This program is distributed in the hope it will be useful, but WITHOUT
  3939. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  3940. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  3941. + * more details.
  3942. + */
  3943. +
  3944. +#include <linux/mei_cl_bus.h>
  3945. +#include <linux/module.h>
  3946. +#include <linux/mod_devicetable.h>
  3947. +#include <linux/hid.h>
  3948. +#include <linux/dma-mapping.h>
  3949. +#include <linux/kthread.h>
  3950. +#include <linux/intel_ipts_if.h>
  3951. +
  3952. +#include "ipts.h"
  3953. +#include "ipts-hid.h"
  3954. +#include "ipts-msg-handler.h"
  3955. +#include "ipts-mei-msgs.h"
  3956. +#include "ipts-binary-spec.h"
  3957. +#include "ipts-state.h"
  3958. +
  3959. +#define IPTS_DRIVER_NAME "ipts"
  3960. +#define IPTS_MEI_UUID UUID_LE(0x3e8d0870, 0x271a, 0x4208, \
  3961. + 0x8e, 0xb5, 0x9a, 0xcb, 0x94, 0x02, 0xae, 0x04)
  3962. +
  3963. +static struct mei_cl_device_id ipts_mei_cl_tbl[] = {
  3964. + { "", IPTS_MEI_UUID, MEI_CL_VERSION_ANY},
  3965. + {}
  3966. +};
  3967. +
  3968. +static ssize_t sensor_mode_show(struct device *dev,
  3969. + struct device_attribute *attr, char *buf)
  3970. +{
  3971. + ipts_info_t *ipts;
  3972. + ipts = dev_get_drvdata(dev);
  3973. +
  3974. + return sprintf(buf, "%d\n", ipts->sensor_mode);
  3975. +}
  3976. +
  3977. +//TODO: Verify the function implementation
  3978. +static ssize_t sensor_mode_store(struct device *dev,
  3979. + struct device_attribute *attr, const char *buf,
  3980. + size_t count)
  3981. +{
  3982. + int ret;
  3983. + long val;
  3984. + ipts_info_t *ipts;
  3985. +
  3986. + ipts = dev_get_drvdata(dev);
  3987. + ret = kstrtol(buf, 10, &val);
  3988. + if (ret)
  3989. + return ret;
  3990. +
  3991. + ipts_dbg(ipts, "try sensor mode = %ld\n", val);
  3992. +
  3993. + switch (val) {
  3994. + case TOUCH_SENSOR_MODE_HID:
  3995. + break;
  3996. + case TOUCH_SENSOR_MODE_RAW_DATA:
  3997. + break;
  3998. + default:
  3999. + ipts_err(ipts, "sensor mode %ld is not supported\n", val);
  4000. + }
  4001. +
  4002. + return count;
  4003. +}
  4004. +
  4005. +static ssize_t device_info_show(struct device *dev,
  4006. + struct device_attribute *attr, char *buf)
  4007. +{
  4008. + ipts_info_t *ipts;
  4009. +
  4010. + ipts = dev_get_drvdata(dev);
  4011. + return sprintf(buf, "vendor id = 0x%04hX\n"
  4012. + "device id = 0x%04hX\n"
  4013. + "HW rev = 0x%08X\n"
  4014. + "firmware rev = 0x%08X\n",
  4015. + ipts->device_info.vendor_id, ipts->device_info.device_id,
  4016. + ipts->device_info.hw_rev, ipts->device_info.fw_rev);
  4017. +}
  4018. +
  4019. +static DEVICE_ATTR_RW(sensor_mode);
  4020. +static DEVICE_ATTR_RO(device_info);
  4021. +
  4022. +static struct attribute *ipts_attrs[] = {
  4023. + &dev_attr_sensor_mode.attr,
  4024. + &dev_attr_device_info.attr,
  4025. + NULL
  4026. +};
  4027. +
  4028. +static const struct attribute_group ipts_grp = {
  4029. + .attrs = ipts_attrs,
  4030. +};
  4031. +
  4032. +MODULE_DEVICE_TABLE(mei, ipts_mei_cl_tbl);
  4033. +
  4034. +static void raw_data_work_func(struct work_struct *work)
  4035. +{
  4036. + ipts_info_t *ipts = container_of(work, ipts_info_t, raw_data_work);
  4037. +
  4038. + ipts_handle_processed_data(ipts);
  4039. +}
  4040. +
  4041. +static void gfx_status_work_func(struct work_struct *work)
  4042. +{
  4043. + ipts_info_t *ipts = container_of(work, ipts_info_t, gfx_status_work);
  4044. + ipts_state_t state;
  4045. + int status = ipts->gfx_status;
  4046. +
  4047. + ipts_dbg(ipts, "notify gfx status : %d\n", status);
  4048. +
  4049. + state = ipts_get_state(ipts);
  4050. +
  4051. + if (state == IPTS_STA_RAW_DATA_STARTED || state == IPTS_STA_HID_STARTED) {
  4052. + if (status == IPTS_NOTIFY_STA_BACKLIGHT_ON &&
  4053. + ipts->display_status == false) {
  4054. + ipts_send_sensor_clear_mem_window_cmd(ipts);
  4055. + ipts->display_status = true;
  4056. + } else if (status == IPTS_NOTIFY_STA_BACKLIGHT_OFF &&
  4057. + ipts->display_status == true) {
  4058. + ipts_send_sensor_quiesce_io_cmd(ipts);
  4059. + ipts->display_status = false;
  4060. + }
  4061. + }
  4062. +}
  4063. +
  4064. +/* event loop */
  4065. +static int ipts_mei_cl_event_thread(void *data)
  4066. +{
  4067. + ipts_info_t *ipts = (ipts_info_t *)data;
  4068. + struct mei_cl_device *cldev = ipts->cldev;
  4069. + ssize_t msg_len;
  4070. + touch_sensor_msg_m2h_t m2h_msg;
  4071. +
  4072. + while (!kthread_should_stop()) {
  4073. + msg_len = mei_cldev_recv(cldev, (u8*)&m2h_msg, sizeof(m2h_msg));
  4074. + if (msg_len <= 0) {
  4075. + ipts_err(ipts, "error in reading m2h msg\n");
  4076. + continue;
  4077. + }
  4078. +
  4079. + if (ipts_handle_resp(ipts, &m2h_msg, msg_len) != 0) {
  4080. + ipts_err(ipts, "error in handling resp msg\n");
  4081. + }
  4082. + }
  4083. +
  4084. + ipts_dbg(ipts, "!! end event loop !!\n");
  4085. +
  4086. + return 0;
  4087. +}
  4088. +
  4089. +static void init_work_func(struct work_struct *work)
  4090. +{
  4091. + ipts_info_t *ipts = container_of(work, ipts_info_t, init_work);
  4092. +
  4093. + ipts->sensor_mode = TOUCH_SENSOR_MODE_RAW_DATA;
  4094. + ipts->display_status = true;
  4095. +
  4096. + ipts_start(ipts);
  4097. +}
  4098. +
  4099. +static int ipts_mei_cl_probe(struct mei_cl_device *cldev,
  4100. + const struct mei_cl_device_id *id)
  4101. +{
  4102. + int ret = 0;
  4103. + ipts_info_t *ipts = NULL;
  4104. +
  4105. + pr_info("probing Intel Precise Touch & Stylus\n");
  4106. +
  4107. + // setup the DMA BIT mask, the system will choose the best possible
  4108. + if (dma_coerce_mask_and_coherent(&cldev->dev, DMA_BIT_MASK(64)) == 0) {
  4109. + pr_info("IPTS using DMA_BIT_MASK(64)\n");
  4110. + } else if (dma_coerce_mask_and_coherent(&cldev->dev,
  4111. + DMA_BIT_MASK(32)) == 0) {
  4112. + pr_info("IPTS using DMA_BIT_MASK(32)\n");
  4113. + } else {
  4114. + pr_err("IPTS: No suitable DMA available\n");
  4115. + return -EFAULT;
  4116. + }
  4117. +
  4118. + ret = mei_cldev_enable(cldev);
  4119. + if (ret < 0) {
  4120. + pr_err("cannot enable IPTS\n");
  4121. + return ret;
  4122. + }
  4123. +
  4124. + ipts = devm_kzalloc(&cldev->dev, sizeof(ipts_info_t), GFP_KERNEL);
  4125. + if (ipts == NULL) {
  4126. + ret = -ENOMEM;
  4127. + goto disable_mei;
  4128. + }
  4129. + ipts->cldev = cldev;
  4130. + mei_cldev_set_drvdata(cldev, ipts);
  4131. +
  4132. + ipts->event_loop = kthread_run(ipts_mei_cl_event_thread, (void*)ipts,
  4133. + "ipts_event_thread");
  4134. +
  4135. + if(ipts_dbgfs_register(ipts, "ipts"))
  4136. + pr_debug("cannot register debugfs for IPTS\n");
  4137. +
  4138. + INIT_WORK(&ipts->init_work, init_work_func);
  4139. + INIT_WORK(&ipts->raw_data_work, raw_data_work_func);
  4140. + INIT_WORK(&ipts->gfx_status_work, gfx_status_work_func);
  4141. +
  4142. + ret = sysfs_create_group(&cldev->dev.kobj, &ipts_grp);
  4143. + if (ret != 0) {
  4144. + pr_debug("cannot create sysfs for IPTS\n");
  4145. + }
  4146. +
  4147. + schedule_work(&ipts->init_work);
  4148. +
  4149. + return 0;
  4150. +
  4151. +disable_mei :
  4152. + mei_cldev_disable(cldev);
  4153. +
  4154. + return ret;
  4155. +}
  4156. +
  4157. +static int ipts_mei_cl_remove(struct mei_cl_device *cldev)
  4158. +{
  4159. + ipts_info_t *ipts = mei_cldev_get_drvdata(cldev);
  4160. +
  4161. + ipts_stop(ipts);
  4162. +
  4163. + sysfs_remove_group(&cldev->dev.kobj, &ipts_grp);
  4164. + ipts_hid_release(ipts);
  4165. + ipts_dbgfs_deregister(ipts);
  4166. + mei_cldev_disable(cldev);
  4167. +
  4168. + kthread_stop(ipts->event_loop);
  4169. +
  4170. + pr_info("IPTS removed\n");
  4171. +
  4172. + return 0;
  4173. +}
  4174. +
  4175. +static struct mei_cl_driver ipts_mei_cl_driver = {
  4176. + .id_table = ipts_mei_cl_tbl,
  4177. + .name = IPTS_DRIVER_NAME,
  4178. + .probe = ipts_mei_cl_probe,
  4179. + .remove = ipts_mei_cl_remove,
  4180. +};
  4181. +
  4182. +static int ipts_mei_cl_init(void)
  4183. +{
  4184. + int ret;
  4185. +
  4186. + pr_info("IPTS %s() is called\n", __func__);
  4187. +
  4188. + ret = mei_cldev_driver_register(&ipts_mei_cl_driver);
  4189. + if (ret) {
  4190. + pr_err("unable to register IPTS mei client driver\n");
  4191. + return ret;
  4192. + }
  4193. +
  4194. + return 0;
  4195. +}
  4196. +
  4197. +static void __exit ipts_mei_cl_exit(void)
  4198. +{
  4199. + pr_info("IPTS %s() is called\n", __func__);
  4200. +
  4201. + mei_cldev_driver_unregister(&ipts_mei_cl_driver);
  4202. +}
  4203. +
  4204. +module_init(ipts_mei_cl_init);
  4205. +module_exit(ipts_mei_cl_exit);
  4206. +
  4207. +MODULE_DESCRIPTION
  4208. + ("Intel(R) Management Engine Interface Client Driver for "\
  4209. + "Intel Precision Touch and Sylus");
  4210. +MODULE_LICENSE("GPL");
  4211. diff --git a/drivers/misc/ipts/ipts-msg-handler.c b/drivers/misc/ipts/ipts-msg-handler.c
  4212. new file mode 100644
  4213. index 0000000..1396ecc
  4214. --- /dev/null
  4215. +++ b/drivers/misc/ipts/ipts-msg-handler.c
  4216. @@ -0,0 +1,431 @@
  4217. +#include <linux/mei_cl_bus.h>
  4218. +
  4219. +#include "ipts.h"
  4220. +#include "ipts-hid.h"
  4221. +#include "ipts-resource.h"
  4222. +#include "ipts-mei-msgs.h"
  4223. +
  4224. +int ipts_handle_cmd(ipts_info_t *ipts, u32 cmd, void *data, int data_size)
  4225. +{
  4226. + int ret = 0;
  4227. + touch_sensor_msg_h2m_t h2m_msg;
  4228. + int len = 0;
  4229. +
  4230. + memset(&h2m_msg, 0, sizeof(h2m_msg));
  4231. +
  4232. + h2m_msg.command_code = cmd;
  4233. + len = sizeof(h2m_msg.command_code) + data_size;
  4234. + if (data != NULL && data_size != 0)
  4235. + memcpy(&h2m_msg.h2m_data, data, data_size); /* copy payload */
  4236. +
  4237. + ret = mei_cldev_send(ipts->cldev, (u8*)&h2m_msg, len);
  4238. + if (ret < 0) {
  4239. + ipts_err(ipts, "mei_cldev_send() error 0x%X:%d\n",
  4240. + cmd, ret);
  4241. + return ret;
  4242. + }
  4243. +
  4244. + return 0;
  4245. +}
  4246. +
  4247. +int ipts_send_feedback(ipts_info_t *ipts, int buffer_idx, u32 transaction_id)
  4248. +{
  4249. + int ret;
  4250. + int cmd_len;
  4251. + touch_sensor_feedback_ready_cmd_data_t fb_ready_cmd;
  4252. +
  4253. + cmd_len = sizeof(touch_sensor_feedback_ready_cmd_data_t);
  4254. + memset(&fb_ready_cmd, 0, cmd_len);
  4255. +
  4256. + fb_ready_cmd.feedback_index = buffer_idx;
  4257. + fb_ready_cmd.transaction_id = transaction_id;
  4258. +
  4259. + ret = ipts_handle_cmd(ipts, TOUCH_SENSOR_FEEDBACK_READY_CMD,
  4260. + &fb_ready_cmd, cmd_len);
  4261. +
  4262. + return ret;
  4263. +}
  4264. +
  4265. +int ipts_send_sensor_quiesce_io_cmd(ipts_info_t *ipts)
  4266. +{
  4267. + int ret;
  4268. + int cmd_len;
  4269. + touch_sensor_quiesce_io_cmd_data_t quiesce_io_cmd;
  4270. +
  4271. + cmd_len = sizeof(touch_sensor_quiesce_io_cmd_data_t);
  4272. + memset(&quiesce_io_cmd, 0, cmd_len);
  4273. +
  4274. + ret = ipts_handle_cmd(ipts, TOUCH_SENSOR_QUIESCE_IO_CMD,
  4275. + &quiesce_io_cmd, cmd_len);
  4276. +
  4277. + return ret;
  4278. +}
  4279. +
  4280. +int ipts_send_sensor_hid_ready_for_data_cmd(ipts_info_t *ipts)
  4281. +{
  4282. + return ipts_handle_cmd(ipts, TOUCH_SENSOR_HID_READY_FOR_DATA_CMD, NULL, 0);
  4283. +}
  4284. +
  4285. +int ipts_send_sensor_clear_mem_window_cmd(ipts_info_t *ipts)
  4286. +{
  4287. + return ipts_handle_cmd(ipts, TOUCH_SENSOR_CLEAR_MEM_WINDOW_CMD, NULL, 0);
  4288. +}
  4289. +
  4290. +static int check_validity(touch_sensor_msg_m2h_t *m2h_msg, u32 msg_len)
  4291. +{
  4292. + int ret = 0;
  4293. + int valid_msg_len = sizeof(m2h_msg->command_code);
  4294. + u32 cmd_code = m2h_msg->command_code;
  4295. +
  4296. + switch (cmd_code) {
  4297. + case TOUCH_SENSOR_SET_MODE_RSP:
  4298. + valid_msg_len +=
  4299. + sizeof(touch_sensor_set_mode_rsp_data_t);
  4300. + break;
  4301. + case TOUCH_SENSOR_SET_MEM_WINDOW_RSP:
  4302. + valid_msg_len +=
  4303. + sizeof(touch_sensor_set_mem_window_rsp_data_t);
  4304. + break;
  4305. + case TOUCH_SENSOR_QUIESCE_IO_RSP:
  4306. + valid_msg_len +=
  4307. + sizeof(touch_sensor_quiesce_io_rsp_data_t);
  4308. + break;
  4309. + case TOUCH_SENSOR_HID_READY_FOR_DATA_RSP:
  4310. + valid_msg_len +=
  4311. + sizeof(touch_sensor_hid_ready_for_data_rsp_data_t);
  4312. + break;
  4313. + case TOUCH_SENSOR_FEEDBACK_READY_RSP:
  4314. + valid_msg_len +=
  4315. + sizeof(touch_sensor_feedback_ready_rsp_data_t);
  4316. + break;
  4317. + case TOUCH_SENSOR_CLEAR_MEM_WINDOW_RSP:
  4318. + valid_msg_len +=
  4319. + sizeof(touch_sensor_clear_mem_window_rsp_data_t);
  4320. + break;
  4321. + case TOUCH_SENSOR_NOTIFY_DEV_READY_RSP:
  4322. + valid_msg_len +=
  4323. + sizeof(touch_sensor_notify_dev_ready_rsp_data_t);
  4324. + break;
  4325. + case TOUCH_SENSOR_SET_POLICIES_RSP:
  4326. + valid_msg_len +=
  4327. + sizeof(touch_sensor_set_policies_rsp_data_t);
  4328. + break;
  4329. + case TOUCH_SENSOR_GET_POLICIES_RSP:
  4330. + valid_msg_len +=
  4331. + sizeof(touch_sensor_get_policies_rsp_data_t);
  4332. + break;
  4333. + case TOUCH_SENSOR_RESET_RSP:
  4334. + valid_msg_len +=
  4335. + sizeof(touch_sensor_reset_rsp_data_t);
  4336. + break;
  4337. + }
  4338. +
  4339. + if (valid_msg_len != msg_len) {
  4340. + return -EINVAL;
  4341. + }
  4342. +
  4343. + return ret;
  4344. +}
  4345. +
  4346. +int ipts_start(ipts_info_t *ipts)
  4347. +{
  4348. + int ret = 0;
  4349. + /* TODO : check if we need to do SET_POLICIES_CMD
  4350. + we need to do this when protocol version doesn't match with reported one
  4351. + how we keep vendor specific data is the first thing to solve */
  4352. +
  4353. + ipts_set_state(ipts, IPTS_STA_INIT);
  4354. + ipts->num_of_parallel_data_buffers = TOUCH_SENSOR_MAX_DATA_BUFFERS;
  4355. +
  4356. + ipts->sensor_mode = TOUCH_SENSOR_MODE_RAW_DATA; /* start with RAW_DATA */
  4357. +
  4358. + ret = ipts_handle_cmd(ipts, TOUCH_SENSOR_NOTIFY_DEV_READY_CMD, NULL, 0);
  4359. +
  4360. + return ret;
  4361. +}
  4362. +
  4363. +void ipts_stop(ipts_info_t *ipts)
  4364. +{
  4365. + ipts_state_t old_state;
  4366. +
  4367. + old_state = ipts_get_state(ipts);
  4368. + ipts_set_state(ipts, IPTS_STA_STOPPING);
  4369. +
  4370. + if (old_state < IPTS_STA_RESOURCE_READY)
  4371. + return;
  4372. +
  4373. + if (old_state == IPTS_STA_RAW_DATA_STARTED ||
  4374. + old_state == IPTS_STA_HID_STARTED) {
  4375. + ipts_free_default_resource(ipts);
  4376. + ipts_free_raw_data_resource(ipts);
  4377. +
  4378. + return;
  4379. + }
  4380. +}
  4381. +
  4382. +int ipts_restart(ipts_info_t *ipts)
  4383. +{
  4384. + int ret = 0;
  4385. +
  4386. + ipts_dbg(ipts, "ipts restart\n");
  4387. +
  4388. + ipts_stop(ipts);
  4389. +
  4390. + ipts->retry++;
  4391. + if (ipts->retry == IPTS_MAX_RETRY &&
  4392. + ipts->sensor_mode == TOUCH_SENSOR_MODE_RAW_DATA) {
  4393. + /* try with HID mode */
  4394. + ipts->sensor_mode = TOUCH_SENSOR_MODE_HID;
  4395. + } else if (ipts->retry > IPTS_MAX_RETRY) {
  4396. + return -EPERM;
  4397. + }
  4398. +
  4399. + ipts_send_sensor_quiesce_io_cmd(ipts);
  4400. + ipts->restart = true;
  4401. +
  4402. + return ret;
  4403. +}
  4404. +
  4405. +int ipts_switch_sensor_mode(ipts_info_t *ipts, int new_sensor_mode)
  4406. +{
  4407. + int ret = 0;
  4408. +
  4409. + ipts->new_sensor_mode = new_sensor_mode;
  4410. + ipts->switch_sensor_mode = true;
  4411. + ret = ipts_send_sensor_quiesce_io_cmd(ipts);
  4412. +
  4413. + return ret;
  4414. +}
  4415. +
  4416. +#define rsp_failed(ipts, cmd, status) ipts_err(ipts, \
  4417. + "0x%08x failed status = %d\n", cmd, status);
  4418. +
  4419. +int ipts_handle_resp(ipts_info_t *ipts, touch_sensor_msg_m2h_t *m2h_msg,
  4420. + u32 msg_len)
  4421. +{
  4422. + int ret = 0;
  4423. + int rsp_status = 0;
  4424. + int cmd_status = 0;
  4425. + int cmd_len = 0;
  4426. + u32 cmd;
  4427. +
  4428. + if (!check_validity(m2h_msg, msg_len)) {
  4429. + ipts_err(ipts, "wrong rsp\n");
  4430. + return -EINVAL;
  4431. + }
  4432. +
  4433. + rsp_status = m2h_msg->status;
  4434. + cmd = m2h_msg->command_code;
  4435. +
  4436. + switch (cmd) {
  4437. + case TOUCH_SENSOR_NOTIFY_DEV_READY_RSP:
  4438. + if (rsp_status != 0 &&
  4439. + rsp_status != TOUCH_STATUS_SENSOR_FAIL_NONFATAL) {
  4440. + rsp_failed(ipts, cmd, rsp_status);
  4441. + break;
  4442. + }
  4443. +
  4444. + cmd_status = ipts_handle_cmd(ipts,
  4445. + TOUCH_SENSOR_GET_DEVICE_INFO_CMD,
  4446. + NULL, 0);
  4447. + break;
  4448. + case TOUCH_SENSOR_GET_DEVICE_INFO_RSP:
  4449. + if (rsp_status != 0 &&
  4450. + rsp_status != TOUCH_STATUS_COMPAT_CHECK_FAIL) {
  4451. + rsp_failed(ipts, cmd, rsp_status);
  4452. + break;
  4453. + }
  4454. +
  4455. + memcpy(&ipts->device_info,
  4456. + &m2h_msg->m2h_data.device_info_rsp_data,
  4457. + sizeof(touch_sensor_get_device_info_rsp_data_t));
  4458. +
  4459. + /*
  4460. + TODO : support raw_request during HID init.
  4461. + Although HID init happens here, technically most of
  4462. + reports (for both direction) can be issued only
  4463. + after SET_MEM_WINDOWS_CMD since they may require
  4464. + ME or touch IC. If ipts vendor requires raw_request
  4465. + during HID init, we need to consider to move HID init.
  4466. + */
  4467. + if (ipts->hid_desc_ready == false) {
  4468. + ret = ipts_hid_init(ipts);
  4469. + if (ret)
  4470. + break;
  4471. + }
  4472. +
  4473. + cmd_status = ipts_send_sensor_clear_mem_window_cmd(ipts);
  4474. +
  4475. + break;
  4476. + case TOUCH_SENSOR_CLEAR_MEM_WINDOW_RSP:
  4477. + {
  4478. + touch_sensor_set_mode_cmd_data_t sensor_mode_cmd;
  4479. +
  4480. + if (rsp_status != 0 &&
  4481. + rsp_status != TOUCH_STATUS_TIMEOUT) {
  4482. + rsp_failed(ipts, cmd, rsp_status);
  4483. + break;
  4484. + }
  4485. +
  4486. + /* allocate default resource : common & hid only */
  4487. + if (!ipts_is_default_resource_ready(ipts)) {
  4488. + ret = ipts_allocate_default_resource(ipts);
  4489. + if (ret)
  4490. + break;
  4491. + }
  4492. +
  4493. + if (ipts->sensor_mode == TOUCH_SENSOR_MODE_RAW_DATA &&
  4494. + !ipts_is_raw_data_resource_ready(ipts)) {
  4495. + ret = ipts_allocate_raw_data_resource(ipts);
  4496. + if (ret) {
  4497. + ipts_free_default_resource(ipts);
  4498. + break;
  4499. + }
  4500. + }
  4501. +
  4502. + ipts_set_state(ipts, IPTS_STA_RESOURCE_READY);
  4503. +
  4504. + cmd_len = sizeof(touch_sensor_set_mode_cmd_data_t);
  4505. + memset(&sensor_mode_cmd, 0, cmd_len);
  4506. + sensor_mode_cmd.sensor_mode = ipts->sensor_mode;
  4507. + cmd_status = ipts_handle_cmd(ipts,
  4508. + TOUCH_SENSOR_SET_MODE_CMD,
  4509. + &sensor_mode_cmd, cmd_len);
  4510. + break;
  4511. + }
  4512. + case TOUCH_SENSOR_SET_MODE_RSP:
  4513. + {
  4514. + touch_sensor_set_mem_window_cmd_data_t smw_cmd;
  4515. +
  4516. + if (rsp_status != 0) {
  4517. + rsp_failed(ipts, cmd, rsp_status);
  4518. + break;
  4519. + }
  4520. +
  4521. + cmd_len = sizeof(touch_sensor_set_mem_window_cmd_data_t);
  4522. + memset(&smw_cmd, 0, cmd_len);
  4523. + ipts_get_set_mem_window_cmd_data(ipts, &smw_cmd);
  4524. + cmd_status = ipts_handle_cmd(ipts,
  4525. + TOUCH_SENSOR_SET_MEM_WINDOW_CMD,
  4526. + &smw_cmd, cmd_len);
  4527. + break;
  4528. + }
  4529. + case TOUCH_SENSOR_SET_MEM_WINDOW_RSP:
  4530. + if (rsp_status != 0) {
  4531. + rsp_failed(ipts, cmd, rsp_status);
  4532. + break;
  4533. + }
  4534. +
  4535. + cmd_status = ipts_send_sensor_hid_ready_for_data_cmd(ipts);
  4536. + if (cmd_status)
  4537. + break;
  4538. +
  4539. + if (ipts->sensor_mode == TOUCH_SENSOR_MODE_HID) {
  4540. + ipts_set_state(ipts, IPTS_STA_HID_STARTED);
  4541. + } else if (ipts->sensor_mode == TOUCH_SENSOR_MODE_RAW_DATA) {
  4542. + ipts_set_state(ipts, IPTS_STA_RAW_DATA_STARTED);
  4543. + }
  4544. +
  4545. + ipts_err(ipts, "touch enabled %d\n", ipts_get_state(ipts));
  4546. +
  4547. + break;
  4548. + case TOUCH_SENSOR_HID_READY_FOR_DATA_RSP:
  4549. + {
  4550. + touch_sensor_hid_ready_for_data_rsp_data_t *hid_data;
  4551. + ipts_state_t state;
  4552. +
  4553. + if (rsp_status != 0 &&
  4554. + rsp_status != TOUCH_STATUS_SENSOR_DISABLED) {
  4555. + rsp_failed(ipts, cmd, rsp_status);
  4556. + break;
  4557. + }
  4558. +
  4559. + state = ipts_get_state(ipts);
  4560. + if (ipts->sensor_mode == TOUCH_SENSOR_MODE_HID &&
  4561. + state == IPTS_STA_HID_STARTED) {
  4562. +
  4563. + hid_data = &m2h_msg->m2h_data.hid_ready_for_data_rsp_data;
  4564. +
  4565. + /* HID mode only uses buffer 0 */
  4566. + if (hid_data->touch_data_buffer_index != 0)
  4567. + break;
  4568. +
  4569. + /* handle hid data */
  4570. + ipts_handle_hid_data(ipts, hid_data);
  4571. + }
  4572. +
  4573. + break;
  4574. + }
  4575. + case TOUCH_SENSOR_FEEDBACK_READY_RSP:
  4576. + if (rsp_status != 0 &&
  4577. + rsp_status != TOUCH_STATUS_COMPAT_CHECK_FAIL) {
  4578. + rsp_failed(ipts, cmd, rsp_status);
  4579. + break;
  4580. + }
  4581. +
  4582. + if (m2h_msg->m2h_data.feedback_ready_rsp_data.
  4583. + feedback_index == TOUCH_HID_2_ME_BUFFER_ID)
  4584. + break;
  4585. +
  4586. + if (ipts->sensor_mode == TOUCH_SENSOR_MODE_HID) {
  4587. + cmd_status = ipts_handle_cmd(ipts,
  4588. + TOUCH_SENSOR_HID_READY_FOR_DATA_CMD,
  4589. + NULL, 0);
  4590. + }
  4591. +
  4592. + /* reset retry since we are getting touch data */
  4593. + ipts->retry = 0;
  4594. +
  4595. + break;
  4596. + case TOUCH_SENSOR_QUIESCE_IO_RSP:
  4597. + {
  4598. + ipts_state_t state;
  4599. +
  4600. + if (rsp_status != 0) {
  4601. + rsp_failed(ipts, cmd, rsp_status);
  4602. + break;
  4603. + }
  4604. +
  4605. + state = ipts_get_state(ipts);
  4606. + if (state == IPTS_STA_STOPPING && ipts->restart) {
  4607. + ipts_dbg(ipts, "restart\n");
  4608. + ipts_start(ipts);
  4609. + ipts->restart = 0;
  4610. + break;
  4611. + }
  4612. +
  4613. + /* support sysfs debug node for switch sensor mode */
  4614. + if (ipts->switch_sensor_mode) {
  4615. + ipts_set_state(ipts, IPTS_STA_INIT);
  4616. + ipts->sensor_mode = ipts->new_sensor_mode;
  4617. + ipts->switch_sensor_mode = false;
  4618. +
  4619. + ipts_send_sensor_clear_mem_window_cmd(ipts);
  4620. + }
  4621. +
  4622. + break;
  4623. + }
  4624. + }
  4625. +
  4626. + /* handle error in rsp_status */
  4627. + if (rsp_status != 0) {
  4628. + switch (rsp_status) {
  4629. + case TOUCH_STATUS_SENSOR_EXPECTED_RESET:
  4630. + case TOUCH_STATUS_SENSOR_UNEXPECTED_RESET:
  4631. + ipts_dbg(ipts, "sensor reset %d\n", rsp_status);
  4632. + ipts_restart(ipts);
  4633. + break;
  4634. + default:
  4635. + ipts_dbg(ipts, "cmd : 0x%08x, status %d\n",
  4636. + cmd,
  4637. + rsp_status);
  4638. + break;
  4639. + }
  4640. + }
  4641. +
  4642. + if (cmd_status) {
  4643. + ipts_restart(ipts);
  4644. + }
  4645. +
  4646. + return ret;
  4647. +}
  4648. diff --git a/drivers/misc/ipts/ipts-msg-handler.h b/drivers/misc/ipts/ipts-msg-handler.h
  4649. new file mode 100644
  4650. index 0000000..b8e27d3
  4651. --- /dev/null
  4652. +++ b/drivers/misc/ipts/ipts-msg-handler.h
  4653. @@ -0,0 +1,32 @@
  4654. +/*
  4655. + *
  4656. + * Intel Precise Touch & Stylus ME message handler
  4657. + * Copyright (c) 2016, Intel Corporation.
  4658. + *
  4659. + * This program is free software; you can redistribute it and/or modify it
  4660. + * under the terms and conditions of the GNU General Public License,
  4661. + * version 2, as published by the Free Software Foundation.
  4662. + *
  4663. + * This program is distributed in the hope it will be useful, but WITHOUT
  4664. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  4665. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  4666. + * more details.
  4667. + *
  4668. + */
  4669. +
  4670. +#ifndef _IPTS_MSG_HANDLER_H
  4671. +#define _IPTS_MSG_HANDLER_H
  4672. +
  4673. +int ipts_handle_cmd(ipts_info_t *ipts, u32 cmd, void *data, int data_size);
  4674. +int ipts_start(ipts_info_t *ipts);
  4675. +void ipts_stop(ipts_info_t *ipts);
  4676. +int ipts_switch_sensor_mode(ipts_info_t *ipts, int new_sensor_mode);
  4677. +int ipts_handle_resp(ipts_info_t *ipts, touch_sensor_msg_m2h_t *m2h_msg,
  4678. + u32 msg_len);
  4679. +int ipts_handle_processed_data(ipts_info_t *ipts);
  4680. +int ipts_send_feedback(ipts_info_t *ipts, int buffer_idx, u32 transaction_id);
  4681. +int ipts_send_sensor_quiesce_io_cmd(ipts_info_t *ipts);
  4682. +int ipts_send_sensor_hid_ready_for_data_cmd(ipts_info_t *ipts);
  4683. +int ipts_send_sensor_clear_mem_window_cmd(ipts_info_t *ipts);
  4684. +
  4685. +#endif /* _IPTS_MSG_HANDLER_H */
  4686. diff --git a/drivers/misc/ipts/ipts-resource.c b/drivers/misc/ipts/ipts-resource.c
  4687. new file mode 100644
  4688. index 0000000..47607ef
  4689. --- /dev/null
  4690. +++ b/drivers/misc/ipts/ipts-resource.c
  4691. @@ -0,0 +1,277 @@
  4692. +#include <linux/dma-mapping.h>
  4693. +
  4694. +#include "ipts.h"
  4695. +#include "ipts-mei-msgs.h"
  4696. +#include "ipts-kernel.h"
  4697. +
  4698. +static void free_common_resource(ipts_info_t *ipts)
  4699. +{
  4700. + char *addr;
  4701. + ipts_buffer_info_t *feedback_buffer;
  4702. + dma_addr_t dma_addr;
  4703. + u32 buffer_size;
  4704. + int i, num_of_parallels;
  4705. +
  4706. + if (ipts->resource.me2hid_buffer) {
  4707. + devm_kfree(&ipts->cldev->dev, ipts->resource.me2hid_buffer);
  4708. + ipts->resource.me2hid_buffer = 0;
  4709. + }
  4710. +
  4711. + addr = ipts->resource.hid2me_buffer.addr;
  4712. + dma_addr = ipts->resource.hid2me_buffer.dma_addr;
  4713. + buffer_size = ipts->resource.hid2me_buffer_size;
  4714. +
  4715. + if (ipts->resource.hid2me_buffer.addr) {
  4716. + dmam_free_coherent(&ipts->cldev->dev, buffer_size, addr, dma_addr);
  4717. + ipts->resource.hid2me_buffer.addr = 0;
  4718. + ipts->resource.hid2me_buffer.dma_addr = 0;
  4719. + ipts->resource.hid2me_buffer_size = 0;
  4720. + }
  4721. +
  4722. + feedback_buffer = ipts->resource.feedback_buffer;
  4723. + num_of_parallels = ipts_get_num_of_parallel_buffers(ipts);
  4724. + for (i = 0; i < num_of_parallels; i++) {
  4725. + if (feedback_buffer[i].addr) {
  4726. + dmam_free_coherent(&ipts->cldev->dev,
  4727. + ipts->device_info.feedback_size,
  4728. + feedback_buffer[i].addr,
  4729. + feedback_buffer[i].dma_addr);
  4730. + feedback_buffer[i].addr = 0;
  4731. + feedback_buffer[i].dma_addr = 0;
  4732. + }
  4733. + }
  4734. +}
  4735. +
  4736. +static int allocate_common_resource(ipts_info_t *ipts)
  4737. +{
  4738. + char *addr, *me2hid_addr;
  4739. + ipts_buffer_info_t *feedback_buffer;
  4740. + dma_addr_t dma_addr;
  4741. + int i, ret = 0, num_of_parallels;
  4742. + u32 buffer_size;
  4743. +
  4744. + buffer_size = ipts->device_info.feedback_size;
  4745. +
  4746. + addr = dmam_alloc_coherent(&ipts->cldev->dev,
  4747. + buffer_size,
  4748. + &dma_addr,
  4749. + GFP_ATOMIC|__GFP_ZERO);
  4750. + if (addr == NULL)
  4751. + return -ENOMEM;
  4752. +
  4753. + me2hid_addr = devm_kzalloc(&ipts->cldev->dev, buffer_size, GFP_KERNEL);
  4754. + if (me2hid_addr == NULL) {
  4755. + ret = -ENOMEM;
  4756. + goto release_resource;
  4757. + }
  4758. +
  4759. + ipts->resource.hid2me_buffer.addr = addr;
  4760. + ipts->resource.hid2me_buffer.dma_addr = dma_addr;
  4761. + ipts->resource.hid2me_buffer_size = buffer_size;
  4762. + ipts->resource.me2hid_buffer = me2hid_addr;
  4763. +
  4764. + feedback_buffer = ipts->resource.feedback_buffer;
  4765. + num_of_parallels = ipts_get_num_of_parallel_buffers(ipts);
  4766. + for (i = 0; i < num_of_parallels; i++) {
  4767. + feedback_buffer[i].addr = dmam_alloc_coherent(&ipts->cldev->dev,
  4768. + ipts->device_info.feedback_size,
  4769. + &feedback_buffer[i].dma_addr,
  4770. + GFP_ATOMIC|__GFP_ZERO);
  4771. +
  4772. + if (feedback_buffer[i].addr == NULL) {
  4773. + ret = -ENOMEM;
  4774. + goto release_resource;
  4775. + }
  4776. + }
  4777. +
  4778. + return 0;
  4779. +
  4780. +release_resource:
  4781. + free_common_resource(ipts);
  4782. +
  4783. + return ret;
  4784. +}
  4785. +
  4786. +void ipts_free_raw_data_resource(ipts_info_t *ipts)
  4787. +{
  4788. + if (ipts_is_raw_data_resource_ready(ipts)) {
  4789. + ipts->resource.raw_data_resource_ready = false;
  4790. +
  4791. + ipts_release_kernels(ipts);
  4792. + }
  4793. +}
  4794. +
  4795. +static int allocate_hid_resource(ipts_info_t *ipts)
  4796. +{
  4797. + ipts_buffer_info_t *buffer_hid;
  4798. +
  4799. + /* hid mode uses only one touch data buffer */
  4800. + buffer_hid = &ipts->resource.touch_data_buffer_hid;
  4801. + buffer_hid->addr = dmam_alloc_coherent(&ipts->cldev->dev,
  4802. + ipts->device_info.frame_size,
  4803. + &buffer_hid->dma_addr,
  4804. + GFP_ATOMIC|__GFP_ZERO);
  4805. + if (buffer_hid->addr == NULL) {
  4806. + return -ENOMEM;
  4807. + }
  4808. +
  4809. + return 0;
  4810. +}
  4811. +
  4812. +static void free_hid_resource(ipts_info_t *ipts)
  4813. +{
  4814. + ipts_buffer_info_t *buffer_hid;
  4815. +
  4816. + buffer_hid = &ipts->resource.touch_data_buffer_hid;
  4817. + if (buffer_hid->addr) {
  4818. + dmam_free_coherent(&ipts->cldev->dev,
  4819. + ipts->device_info.frame_size,
  4820. + buffer_hid->addr,
  4821. + buffer_hid->dma_addr);
  4822. + buffer_hid->addr = 0;
  4823. + buffer_hid->dma_addr = 0;
  4824. + }
  4825. +}
  4826. +
  4827. +int ipts_allocate_default_resource(ipts_info_t *ipts)
  4828. +{
  4829. + int ret;
  4830. +
  4831. + ret = allocate_common_resource(ipts);
  4832. + if (ret) {
  4833. + ipts_dbg(ipts, "cannot allocate common resource\n");
  4834. + return ret;
  4835. + }
  4836. +
  4837. + ret = allocate_hid_resource(ipts);
  4838. + if (ret) {
  4839. + ipts_dbg(ipts, "cannot allocate hid resource\n");
  4840. + free_common_resource(ipts);
  4841. + return ret;
  4842. + }
  4843. +
  4844. + ipts->resource.default_resource_ready = true;
  4845. +
  4846. + return 0;
  4847. +}
  4848. +
  4849. +void ipts_free_default_resource(ipts_info_t *ipts)
  4850. +{
  4851. + if (ipts_is_default_resource_ready(ipts)) {
  4852. + ipts->resource.default_resource_ready = false;
  4853. +
  4854. + free_hid_resource(ipts);
  4855. + free_common_resource(ipts);
  4856. + }
  4857. +}
  4858. +
  4859. +int ipts_allocate_raw_data_resource(ipts_info_t *ipts)
  4860. +{
  4861. + int ret = 0;
  4862. +
  4863. + ret = ipts_init_kernels(ipts);
  4864. + if (ret) {
  4865. + return ret;
  4866. + }
  4867. +
  4868. + ipts->resource.raw_data_resource_ready = true;
  4869. +
  4870. + return 0;
  4871. +}
  4872. +
  4873. +static void get_hid_only_smw_cmd_data(ipts_info_t *ipts,
  4874. + touch_sensor_set_mem_window_cmd_data_t *data,
  4875. + ipts_resource_t *resrc)
  4876. +{
  4877. + ipts_buffer_info_t *touch_buf;
  4878. + ipts_buffer_info_t *feedback_buf;
  4879. +
  4880. + touch_buf = &resrc->touch_data_buffer_hid;
  4881. + feedback_buf = &resrc->feedback_buffer[0];
  4882. +
  4883. + data->touch_data_buffer_addr_lower[0] =
  4884. + lower_32_bits(touch_buf->dma_addr);
  4885. + data->touch_data_buffer_addr_upper[0] =
  4886. + upper_32_bits(touch_buf->dma_addr);
  4887. + data->feedback_buffer_addr_lower[0] =
  4888. + lower_32_bits(feedback_buf->dma_addr);
  4889. + data->feedback_buffer_addr_upper[0] =
  4890. + upper_32_bits(feedback_buf->dma_addr);
  4891. +}
  4892. +
  4893. +static void get_raw_data_only_smw_cmd_data(ipts_info_t *ipts,
  4894. + touch_sensor_set_mem_window_cmd_data_t *data,
  4895. + ipts_resource_t *resrc)
  4896. +{
  4897. + u64 wq_tail_phy_addr;
  4898. + u64 cookie_phy_addr;
  4899. + ipts_buffer_info_t *touch_buf;
  4900. + ipts_buffer_info_t *feedback_buf;
  4901. + int i, num_of_parallels;
  4902. +
  4903. + touch_buf = resrc->touch_data_buffer_raw;
  4904. + feedback_buf = resrc->feedback_buffer;
  4905. +
  4906. + num_of_parallels = ipts_get_num_of_parallel_buffers(ipts);
  4907. + for (i = 0; i < num_of_parallels; i++) {
  4908. + data->touch_data_buffer_addr_lower[i] =
  4909. + lower_32_bits(touch_buf[i].dma_addr);
  4910. + data->touch_data_buffer_addr_upper[i] =
  4911. + upper_32_bits(touch_buf[i].dma_addr);
  4912. + data->feedback_buffer_addr_lower[i] =
  4913. + lower_32_bits(feedback_buf[i].dma_addr);
  4914. + data->feedback_buffer_addr_upper[i] =
  4915. + upper_32_bits(feedback_buf[i].dma_addr);
  4916. + }
  4917. +
  4918. + wq_tail_phy_addr = resrc->wq_info.wq_tail_phy_addr;
  4919. + data->tail_offset_addr_lower = lower_32_bits(wq_tail_phy_addr);
  4920. + data->tail_offset_addr_upper = upper_32_bits(wq_tail_phy_addr);
  4921. +
  4922. + cookie_phy_addr = resrc->wq_info.db_phy_addr +
  4923. + resrc->wq_info.db_cookie_offset;
  4924. + data->doorbell_cookie_addr_lower = lower_32_bits(cookie_phy_addr);
  4925. + data->doorbell_cookie_addr_upper = upper_32_bits(cookie_phy_addr);
  4926. + data->work_queue_size = resrc->wq_info.wq_size;
  4927. +
  4928. + data->work_queue_item_size = resrc->wq_item_size;
  4929. +}
  4930. +
  4931. +void ipts_get_set_mem_window_cmd_data(ipts_info_t *ipts,
  4932. + touch_sensor_set_mem_window_cmd_data_t *data)
  4933. +{
  4934. + ipts_resource_t *resrc = &ipts->resource;
  4935. +
  4936. + if (ipts->sensor_mode == TOUCH_SENSOR_MODE_RAW_DATA)
  4937. + get_raw_data_only_smw_cmd_data(ipts, data, resrc);
  4938. + else if (ipts->sensor_mode == TOUCH_SENSOR_MODE_HID)
  4939. + get_hid_only_smw_cmd_data(ipts, data, resrc);
  4940. +
  4941. + /* hid2me is common for "raw data" and "hid" */
  4942. + data->hid2me_buffer_addr_lower =
  4943. + lower_32_bits(resrc->hid2me_buffer.dma_addr);
  4944. + data->hid2me_buffer_addr_upper =
  4945. + upper_32_bits(resrc->hid2me_buffer.dma_addr);
  4946. + data->hid2me_buffer_size = resrc->hid2me_buffer_size;
  4947. +}
  4948. +
  4949. +void ipts_set_input_buffer(ipts_info_t *ipts, int parallel_idx,
  4950. + u8* cpu_addr, u64 dma_addr)
  4951. +{
  4952. + ipts_buffer_info_t *touch_buf;
  4953. +
  4954. + touch_buf = ipts->resource.touch_data_buffer_raw;
  4955. + touch_buf[parallel_idx].dma_addr = dma_addr;
  4956. + touch_buf[parallel_idx].addr = cpu_addr;
  4957. +}
  4958. +
  4959. +void ipts_set_output_buffer(ipts_info_t *ipts, int parallel_idx, int output_idx,
  4960. + u8* cpu_addr, u64 dma_addr)
  4961. +{
  4962. + ipts_buffer_info_t *output_buf;
  4963. +
  4964. + output_buf = &ipts->resource.raw_data_mode_output_buffer[parallel_idx][output_idx];
  4965. +
  4966. + output_buf->dma_addr = dma_addr;
  4967. + output_buf->addr = cpu_addr;
  4968. +}
  4969. diff --git a/drivers/misc/ipts/ipts-resource.h b/drivers/misc/ipts/ipts-resource.h
  4970. new file mode 100644
  4971. index 0000000..7d66ac7
  4972. --- /dev/null
  4973. +++ b/drivers/misc/ipts/ipts-resource.h
  4974. @@ -0,0 +1,30 @@
  4975. +/*
  4976. + * Intel Precise Touch & Stylus state codes
  4977. + *
  4978. + * Copyright (c) 2016, Intel Corporation.
  4979. + *
  4980. + * This program is free software; you can redistribute it and/or modify it
  4981. + * under the terms and conditions of the GNU General Public License,
  4982. + * version 2, as published by the Free Software Foundation.
  4983. + *
  4984. + * This program is distributed in the hope it will be useful, but WITHOUT
  4985. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  4986. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  4987. + * more details.
  4988. + */
  4989. +
  4990. +#ifndef _IPTS_RESOURCE_H_
  4991. +#define _IPTS_RESOURCE_H_
  4992. +
  4993. +int ipts_allocate_default_resource(ipts_info_t *ipts);
  4994. +void ipts_free_default_resource(ipts_info_t *ipts);
  4995. +int ipts_allocate_raw_data_resource(ipts_info_t *ipts);
  4996. +void ipts_free_raw_data_resource(ipts_info_t *ipts);
  4997. +void ipts_get_set_mem_window_cmd_data(ipts_info_t *ipts,
  4998. + touch_sensor_set_mem_window_cmd_data_t *data);
  4999. +void ipts_set_input_buffer(ipts_info_t *ipts, int parallel_idx,
  5000. + u8* cpu_addr, u64 dma_addr);
  5001. +void ipts_set_output_buffer(ipts_info_t *ipts, int parallel_idx, int output_idx,
  5002. + u8* cpu_addr, u64 dma_addr);
  5003. +
  5004. +#endif // _IPTS_RESOURCE_H_
  5005. diff --git a/drivers/misc/ipts/ipts-sensor-regs.h b/drivers/misc/ipts/ipts-sensor-regs.h
  5006. new file mode 100644
  5007. index 0000000..96812b0
  5008. --- /dev/null
  5009. +++ b/drivers/misc/ipts/ipts-sensor-regs.h
  5010. @@ -0,0 +1,700 @@
  5011. +/*
  5012. + * Touch Sensor Register definition
  5013. + *
  5014. + * Copyright (c) 2013-2016, Intel Corporation.
  5015. + *
  5016. + * This program is free software; you can redistribute it and/or modify it
  5017. + * under the terms and conditions of the GNU General Public License,
  5018. + * version 2, as published by the Free Software Foundation.
  5019. + *
  5020. + * This program is distributed in the hope it will be useful, but WITHOUT
  5021. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  5022. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  5023. + * more details.
  5024. + */
  5025. +
  5026. +
  5027. +#ifndef _TOUCH_SENSOR_REGS_H
  5028. +#define _TOUCH_SENSOR_REGS_H
  5029. +
  5030. +#pragma pack(1)
  5031. +
  5032. +// define C_ASSERT macro to check structure size and fail compile for unexpected mismatch
  5033. +#ifndef C_ASSERT
  5034. +#define C_ASSERT(e) typedef char __C_ASSERT__[(e)?1:-1]
  5035. +#endif
  5036. +
  5037. +//
  5038. +// Compatibility versions for this header file
  5039. +//
  5040. +#define TOUCH_EDS_REV_MINOR 0
  5041. +#define TOUCH_EDS_REV_MAJOR 1
  5042. +#define TOUCH_EDS_INTF_REV 1
  5043. +#define TOUCH_PROTOCOL_VER 0
  5044. +
  5045. +
  5046. +//
  5047. +// Offset 00h: TOUCH_STS: Status Register
  5048. +// This register is read by the SPI Controller immediately following an interrupt.
  5049. +//
  5050. +#define TOUCH_STS_REG_OFFSET 0x00
  5051. +
  5052. +typedef enum touch_sts_reg_int_type
  5053. +{
  5054. + TOUCH_STS_REG_INT_TYPE_DATA_AVAIL = 0, // Touch Data Available
  5055. + TOUCH_STS_REG_INT_TYPE_RESET_OCCURRED, // Reset Occurred
  5056. + TOUCH_STS_REG_INT_TYPE_ERROR_OCCURRED, // Error Occurred
  5057. + TOUCH_STS_REG_INT_TYPE_VENDOR_DATA, // Vendor specific data, treated same as raw frame
  5058. + TOUCH_STS_REG_INT_TYPE_GET_FEATURES, // Get Features response data available
  5059. + TOUCH_STS_REG_INT_TYPE_MAX
  5060. +} touch_sts_reg_int_type_t;
  5061. +C_ASSERT(sizeof(touch_sts_reg_int_type_t) == 4);
  5062. +
  5063. +typedef enum touch_sts_reg_pwr_state
  5064. +{
  5065. + TOUCH_STS_REG_PWR_STATE_SLEEP = 0, // Sleep
  5066. + TOUCH_STS_REG_PWR_STATE_DOZE, // Doze
  5067. + TOUCH_STS_REG_PWR_STATE_ARMED, // Armed
  5068. + TOUCH_STS_REG_PWR_STATE_SENSING, // Sensing
  5069. + TOUCH_STS_REG_PWR_STATE_MAX
  5070. +} touch_sts_reg_pwr_state_t;
  5071. +C_ASSERT(sizeof(touch_sts_reg_pwr_state_t) == 4);
  5072. +
  5073. +typedef enum touch_sts_reg_init_state
  5074. +{
  5075. + TOUCH_STS_REG_INIT_STATE_READY_FOR_OP = 0, // Ready for normal operation
  5076. + TOUCH_STS_REG_INIT_STATE_FW_NEEDED, // Touch IC needs its Firmware loaded
  5077. + TOUCH_STS_REG_INIT_STATE_DATA_NEEDED, // Touch IC needs its Data loaded
  5078. + TOUCH_STS_REG_INIT_STATE_INIT_ERROR, // Error info in TOUCH_ERR_REG
  5079. + TOUCH_STS_REG_INIT_STATE_MAX
  5080. +} touch_sts_reg_init_state_t;
  5081. +C_ASSERT(sizeof(touch_sts_reg_init_state_t) == 4);
  5082. +
  5083. +#define TOUCH_SYNC_BYTE_VALUE 0x5A
  5084. +
  5085. +typedef union touch_sts_reg
  5086. +{
  5087. + u32 reg_value;
  5088. +
  5089. + struct
  5090. + {
  5091. + // When set, this indicates the hardware has data that needs to be read.
  5092. + u32 int_status :1;
  5093. + // see TOUCH_STS_REG_INT_TYPE
  5094. + u32 int_type :4;
  5095. + // see TOUCH_STS_REG_PWR_STATE
  5096. + u32 pwr_state :2;
  5097. + // see TOUCH_STS_REG_INIT_STATE
  5098. + u32 init_state :2;
  5099. + // Busy bit indicates that sensor cannot accept writes at this time
  5100. + u32 busy :1;
  5101. + // Reserved
  5102. + u32 reserved :14;
  5103. + // Synchronization bit, should always be TOUCH_SYNC_BYTE_VALUE
  5104. + u32 sync_byte :8;
  5105. + } fields;
  5106. +} touch_sts_reg_t;
  5107. +C_ASSERT(sizeof(touch_sts_reg_t) == 4);
  5108. +
  5109. +
  5110. +//
  5111. +// Offset 04h: TOUCH_FRAME_CHAR: Frame Characteristics Register
  5112. +// This registers describes the characteristics of each data frame read by the SPI Controller in
  5113. +// response to a touch interrupt.
  5114. +//
  5115. +#define TOUCH_FRAME_CHAR_REG_OFFSET 0x04
  5116. +
  5117. +typedef union touch_frame_char_reg
  5118. +{
  5119. + u32 reg_value;
  5120. +
  5121. + struct
  5122. + {
  5123. + // Micro-Frame Size (MFS): Indicates the size of a touch micro-frame in byte increments.
  5124. + // When a micro-frame is to be read for processing (in data mode), this is the total number of
  5125. + // bytes that must be read per interrupt, split into multiple read commands no longer than RPS.
  5126. + // Maximum micro-frame size is 256KB.
  5127. + u32 microframe_size :18;
  5128. + // Micro-Frames per Frame (MFPF): Indicates the number of micro-frames per frame. If a
  5129. + // sensor's frame does not contain micro-frames this value will be 1. Valid values are 1-31.
  5130. + u32 microframes_per_frame :5;
  5131. + // Micro-Frame Index (MFI): Indicates the index of the micro-frame within a frame. This allows
  5132. + // the SPI Controller to maintain synchronization with the sensor and determine when the final
  5133. + // micro-frame has arrived. Valid values are 1-31.
  5134. + u32 microframe_index :5;
  5135. + // HID/Raw Data: This bit describes whether the data from the sensor is Raw data or a HID
  5136. + // report. When set, the data is a HID report.
  5137. + u32 hid_report :1;
  5138. + // Reserved
  5139. + u32 reserved :3;
  5140. + } fields;
  5141. +} touch_frame_char_reg_t;
  5142. +C_ASSERT(sizeof(touch_frame_char_reg_t) == 4);
  5143. +
  5144. +
  5145. +//
  5146. +// Offset 08h: Touch Error Register
  5147. +//
  5148. +#define TOUCH_ERR_REG_OFFSET 0x08
  5149. +
  5150. +// bit definition is vendor specific
  5151. +typedef union touch_err_reg
  5152. +{
  5153. + u32 reg_value;
  5154. +
  5155. + struct
  5156. + {
  5157. + u32 invalid_fw :1;
  5158. + u32 invalid_data :1;
  5159. + u32 self_test_failed :1;
  5160. + u32 reserved :12;
  5161. + u32 fatal_error :1;
  5162. + u32 vendor_errors :16;
  5163. + } fields;
  5164. +} touch_err_reg_t;
  5165. +C_ASSERT(sizeof(touch_err_reg_t) == 4);
  5166. +
  5167. +
  5168. +//
  5169. +// Offset 0Ch: RESERVED
  5170. +// This register is reserved for future use.
  5171. +//
  5172. +
  5173. +
  5174. +//
  5175. +// Offset 10h: Touch Identification Register
  5176. +//
  5177. +#define TOUCH_ID_REG_OFFSET 0x10
  5178. +
  5179. +#define TOUCH_ID_REG_VALUE 0x43495424
  5180. +
  5181. +// expected value is "$TIC" or 0x43495424
  5182. +typedef u32 touch_id_reg_t;
  5183. +C_ASSERT(sizeof(touch_id_reg_t) == 4);
  5184. +
  5185. +
  5186. +//
  5187. +// Offset 14h: TOUCH_DATA_SZ: Touch Data Size Register
  5188. +// This register describes the maximum size of frames and feedback data
  5189. +//
  5190. +#define TOUCH_DATA_SZ_REG_OFFSET 0x14
  5191. +
  5192. +#define TOUCH_MAX_FRAME_SIZE_INCREMENT 64
  5193. +#define TOUCH_MAX_FEEDBACK_SIZE_INCREMENT 64
  5194. +
  5195. +#define TOUCH_SENSOR_MAX_FRAME_SIZE (32 * 1024) // Max allowed frame size 32KB
  5196. +#define TOUCH_SENSOR_MAX_FEEDBACK_SIZE (16 * 1024) // Max allowed feedback size 16KB
  5197. +
  5198. +typedef union touch_data_sz_reg
  5199. +{
  5200. + u32 reg_value;
  5201. +
  5202. + struct
  5203. + {
  5204. + // This value describes the maximum frame size in 64byte increments.
  5205. + u32 max_frame_size :12;
  5206. + // This value describes the maximum feedback size in 64byte increments.
  5207. + u32 max_feedback_size :8;
  5208. + // Reserved
  5209. + u32 reserved :12;
  5210. + } fields;
  5211. +} touch_data_sz_reg_t;
  5212. +C_ASSERT(sizeof(touch_data_sz_reg_t) == 4);
  5213. +
  5214. +
  5215. +//
  5216. +// Offset 18h: TOUCH_CAPABILITIES: Touch Capabilities Register
  5217. +// This register informs the host as to the capabilities of the touch IC.
  5218. +//
  5219. +#define TOUCH_CAPS_REG_OFFSET 0x18
  5220. +
  5221. +typedef enum touch_caps_reg_read_delay_time
  5222. +{
  5223. + TOUCH_CAPS_REG_READ_DELAY_TIME_0,
  5224. + TOUCH_CAPS_REG_READ_DELAY_TIME_10uS,
  5225. + TOUCH_CAPS_REG_READ_DELAY_TIME_50uS,
  5226. + TOUCH_CAPS_REG_READ_DELAY_TIME_100uS,
  5227. + TOUCH_CAPS_REG_READ_DELAY_TIME_150uS,
  5228. + TOUCH_CAPS_REG_READ_DELAY_TIME_250uS,
  5229. + TOUCH_CAPS_REG_READ_DELAY_TIME_500uS,
  5230. + TOUCH_CAPS_REG_READ_DELAY_TIME_1mS,
  5231. +} touch_caps_reg_read_delay_time_t;
  5232. +C_ASSERT(sizeof(touch_caps_reg_read_delay_time_t) == 4);
  5233. +
  5234. +#define TOUCH_BULK_DATA_MAX_WRITE_INCREMENT 64
  5235. +
  5236. +typedef union touch_caps_reg
  5237. +{
  5238. + u32 reg_value;
  5239. +
  5240. + struct
  5241. + {
  5242. + // Reserved for future frequency
  5243. + u32 reserved0 :1;
  5244. + // 17 MHz (14 MHz on Atom) Supported: 0b - Not supported, 1b - Supported
  5245. + u32 supported_17Mhz :1;
  5246. + // 30 MHz (25MHz on Atom) Supported: 0b - Not supported, 1b - Supported
  5247. + u32 supported_30Mhz :1;
  5248. + // 50 MHz Supported: 0b - Not supported, 1b - Supported
  5249. + u32 supported_50Mhz :1;
  5250. + // Reserved
  5251. + u32 reserved1 :4;
  5252. + // Single I/O Supported: 0b - Not supported, 1b - Supported
  5253. + u32 supported_single_io :1;
  5254. + // Dual I/O Supported: 0b - Not supported, 1b - Supported
  5255. + u32 supported_dual_io :1;
  5256. + // Quad I/O Supported: 0b - Not supported, 1b - Supported
  5257. + u32 supported_quad_io :1;
  5258. + // Bulk Data Area Max Write Size: The amount of data the SPI Controller can write to the bulk
  5259. + // data area before it has to poll the busy bit. This field is in multiples of 64 bytes. The
  5260. + // SPI Controller will write the amount of data specified in this field, then check and wait
  5261. + // for the Status.Busy bit to be zero before writing the next data chunk. This field is 6 bits
  5262. + // long, allowing for 4KB of contiguous writes w/o a poll of the busy bit. If this field is
  5263. + // 0x00 the Touch IC has no limit in the amount of data the SPI Controller can write to the
  5264. + // bulk data area.
  5265. + u32 bulk_data_max_write :6;
  5266. + // Read Delay Timer Value: This field describes the delay the SPI Controller will initiate when
  5267. + // a read interrupt follows a write data command. Uses values from TOUCH_CAPS_REG_READ_DELAY_TIME
  5268. + u32 read_delay_timer_value :3;
  5269. + // Reserved
  5270. + u32 reserved2 :4;
  5271. + // Maximum Touch Points: A byte value based on the HID descriptor definition.
  5272. + u32 max_touch_points :8;
  5273. + } fields;
  5274. +} touch_caps_reg_t;
  5275. +C_ASSERT(sizeof(touch_caps_reg_t) == 4);
  5276. +
  5277. +
  5278. +//
  5279. +// Offset 1Ch: TOUCH_CFG: Touch Configuration Register
  5280. +// This register allows the SPI Controller to configure the touch sensor as needed during touch
  5281. +// operations.
  5282. +//
  5283. +#define TOUCH_CFG_REG_OFFSET 0x1C
  5284. +
  5285. +typedef enum touch_cfg_reg_bulk_xfer_size
  5286. +{
  5287. + TOUCH_CFG_REG_BULK_XFER_SIZE_4B = 0, // Bulk Data Transfer Size is 4 bytes
  5288. + TOUCH_CFG_REG_BULK_XFER_SIZE_8B, // Bulk Data Transfer Size is 8 bytes
  5289. + TOUCH_CFG_REG_BULK_XFER_SIZE_16B, // Bulk Data Transfer Size is 16 bytes
  5290. + TOUCH_CFG_REG_BULK_XFER_SIZE_32B, // Bulk Data Transfer Size is 32 bytes
  5291. + TOUCH_CFG_REG_BULK_XFER_SIZE_64B, // Bulk Data Transfer Size is 64 bytes
  5292. + TOUCH_CFG_REG_BULK_XFER_SIZE_MAX
  5293. +} touch_cfg_reg_bulk_xfer_size_t;
  5294. +C_ASSERT(sizeof(touch_cfg_reg_bulk_xfer_size_t) == 4);
  5295. +
  5296. +// Frequency values used by TOUCH_CFG_REG and TOUCH_SENSOR_GET_DEVICE_INFO_RSP_DATA.
  5297. +typedef enum touch_freq
  5298. +{
  5299. + TOUCH_FREQ_RSVD = 0, // Reserved value
  5300. + TOUCH_FREQ_17MHZ, // Sensor set for 17MHz operation (14MHz on Atom)
  5301. + TOUCH_FREQ_30MHZ, // Sensor set for 30MHz operation (25MHz on Atom)
  5302. + TOUCH_FREQ_MAX // Invalid value
  5303. +} touch_freq_t;
  5304. +C_ASSERT(sizeof(touch_freq_t) == 4);
  5305. +
  5306. +typedef union touch_cfg_reg
  5307. +{
  5308. + u32 reg_value;
  5309. +
  5310. + struct
  5311. + {
  5312. + // Touch Enable (TE): This bit is used as a HW semaphore for the Touch IC to guarantee to the
  5313. + // SPI Controller to that (when 0) no sensing operations will occur and only the Reset
  5314. + // interrupt will be generated. When TE is cleared by the SPI Controller:
  5315. + // - TICs must flush all output buffers
  5316. + // - TICs must De-assert any pending interrupt
  5317. + // - ME must throw away any partial frame and pending interrupt must be cleared/not serviced.
  5318. + // The SPI Controller will only modify the configuration of the TIC when TE is cleared. TE is
  5319. + // defaulted to 0h on a power-on reset.
  5320. + u32 touch_enable :1;
  5321. + // Data/HID Packet Mode (DHPM): Raw Data Mode: 0h, HID Packet Mode: 1h
  5322. + u32 dhpm :1;
  5323. + // Bulk Data Transfer Size: This field represents the amount of data written to the Bulk Data
  5324. + // Area (SPI Offset 0x1000-0x2FFF) in a single SPI write protocol
  5325. + u32 bulk_xfer_size :4;
  5326. + // Frequency Select: Frequency for the TouchIC to run at. Use values from TOUCH_FREQ
  5327. + u32 freq_select :3;
  5328. + // Reserved
  5329. + u32 reserved :23;
  5330. + } fields;
  5331. +} touch_cfg_reg_t;
  5332. +C_ASSERT(sizeof(touch_cfg_reg_t) == 4);
  5333. +
  5334. +
  5335. +//
  5336. +// Offset 20h: TOUCH_CMD: Touch Command Register
  5337. +// This register is used for sending commands to the Touch IC.
  5338. +//
  5339. +#define TOUCH_CMD_REG_OFFSET 0x20
  5340. +
  5341. +typedef enum touch_cmd_reg_code
  5342. +{
  5343. + TOUCH_CMD_REG_CODE_NOP = 0, // No Operation
  5344. + TOUCH_CMD_REG_CODE_SOFT_RESET, // Soft Reset
  5345. + TOUCH_CMD_REG_CODE_PREP_4_READ, // Prepare All Registers for Read
  5346. + TOUCH_CMD_REG_CODE_GEN_TEST_PACKETS, // Generate Test Packets according to value in TOUCH_TEST_CTRL_REG
  5347. + TOUCH_CMD_REG_CODE_MAX
  5348. +} touch_cmd_reg_code_t;
  5349. +C_ASSERT(sizeof(touch_cmd_reg_code_t) == 4);
  5350. +
  5351. +typedef union touch_cmd_reg
  5352. +{
  5353. + u32 reg_value;
  5354. +
  5355. + struct
  5356. + {
  5357. + // Command Code: See TOUCH_CMD_REG_CODE
  5358. + u32 command_code :8;
  5359. + // Reserved
  5360. + u32 reserved :24;
  5361. + } fields;
  5362. +} touch_cmd_reg_t;
  5363. +C_ASSERT(sizeof(touch_cmd_reg_t) == 4);
  5364. +
  5365. +
  5366. +//
  5367. +// Offset 24h: Power Management Control
  5368. +// This register is used for active power management. The Touch IC is allowed to mover from Doze or
  5369. +// Armed to Sensing after a touch has occurred. All other transitions will be made at the request
  5370. +// of the SPI Controller.
  5371. +//
  5372. +#define TOUCH_PWR_MGMT_CTRL_REG_OFFSET 0x24
  5373. +
  5374. +typedef enum touch_pwr_mgmt_ctrl_reg_cmd
  5375. +{
  5376. + TOUCH_PWR_MGMT_CTRL_REG_CMD_NOP = 0, // No change to power state
  5377. + TOUCH_PWR_MGMT_CTRL_REG_CMD_SLEEP, // Sleep - set when the system goes into connected standby
  5378. + TOUCH_PWR_MGMT_CTRL_REG_CMD_DOZE, // Doze - set after 300 seconds of inactivity
  5379. + TOUCH_PWR_MGMT_CTRL_REG_CMD_ARMED, // Armed - Set by FW when a "finger off" message is received from the EUs
  5380. + TOUCH_PWR_MGMT_CTRL_REG_CMD_SENSING, // Sensing - not typically set by FW
  5381. + TOUCH_PWR_MGMT_CTRL_REG_CMD_MAX // Values will result in no change to the power state of the Touch IC
  5382. +} touch_pwr_mgmt_ctrl_reg_cmd_t;
  5383. +C_ASSERT(sizeof(touch_pwr_mgmt_ctrl_reg_cmd_t) == 4);
  5384. +
  5385. +typedef union touch_pwr_mgmt_ctrl_reg
  5386. +{
  5387. + u32 reg_value;
  5388. +
  5389. + struct
  5390. + {
  5391. + // Power State Command: See TOUCH_PWR_MGMT_CTRL_REG_CMD
  5392. + u32 pwr_state_cmd :3;
  5393. + // Reserved
  5394. + u32 reserved :29;
  5395. + } fields;
  5396. +} touch_pwr_mgmt_ctrl_reg_t;
  5397. +C_ASSERT(sizeof(touch_pwr_mgmt_ctrl_reg_t) == 4);
  5398. +
  5399. +
  5400. +//
  5401. +// Offset 28h: Vendor HW Information Register
  5402. +// This register is used to relay Intel-assigned vendor ID information to the SPI Controller, which
  5403. +// may be forwarded to SW running on the host CPU.
  5404. +//
  5405. +#define TOUCH_VEN_HW_INFO_REG_OFFSET 0x28
  5406. +
  5407. +typedef union touch_ven_hw_info_reg
  5408. +{
  5409. + u32 reg_value;
  5410. +
  5411. + struct
  5412. + {
  5413. + // Touch Sensor Vendor ID
  5414. + u32 vendor_id :16;
  5415. + // Touch Sensor Device ID
  5416. + u32 device_id :16;
  5417. + } fields;
  5418. +} touch_ven_hw_info_reg_t;
  5419. +C_ASSERT(sizeof(touch_ven_hw_info_reg_t) == 4);
  5420. +
  5421. +
  5422. +//
  5423. +// Offset 2Ch: HW Revision ID Register
  5424. +// This register is used to relay vendor HW revision information to the SPI Controller which may be
  5425. +// forwarded to SW running on the host CPU.
  5426. +//
  5427. +#define TOUCH_HW_REV_REG_OFFSET 0x2C
  5428. +
  5429. +typedef u32 touch_hw_rev_reg_t; // bit definition is vendor specific
  5430. +C_ASSERT(sizeof(touch_hw_rev_reg_t) == 4);
  5431. +
  5432. +
  5433. +//
  5434. +// Offset 30h: FW Revision ID Register
  5435. +// This register is used to relay vendor FW revision information to the SPI Controller which may be
  5436. +// forwarded to SW running on the host CPU.
  5437. +//
  5438. +#define TOUCH_FW_REV_REG_OFFSET 0x30
  5439. +
  5440. +typedef u32 touch_fw_rev_reg_t; // bit definition is vendor specific
  5441. +C_ASSERT(sizeof(touch_fw_rev_reg_t) == 4);
  5442. +
  5443. +
  5444. +//
  5445. +// Offset 34h: Compatibility Revision ID Register
  5446. +// This register is used to relay vendor compatibility information to the SPI Controller which may
  5447. +// be forwarded to SW running on the host CPU. Compatibility Information is a numeric value given
  5448. +// by Intel to the Touch IC vendor based on the major and minor revision of the EDS supported. From
  5449. +// a nomenclature point of view in an x.y revision number of the EDS, the major version is the value
  5450. +// of x and the minor version is the value of y. For example, a Touch IC supporting an EDS version
  5451. +// of 0.61 would contain a major version of 0 and a minor version of 61 in the register.
  5452. +//
  5453. +#define TOUCH_COMPAT_REV_REG_OFFSET 0x34
  5454. +
  5455. +typedef union touch_compat_rev_reg
  5456. +{
  5457. + u32 reg_value;
  5458. +
  5459. + struct
  5460. + {
  5461. + // EDS Minor Revision
  5462. + u8 minor;
  5463. + // EDS Major Revision
  5464. + u8 major;
  5465. + // Interface Revision Number (from EDS)
  5466. + u8 intf_rev;
  5467. + // EU Kernel Compatibility Version - vendor specific value
  5468. + u8 kernel_compat_ver;
  5469. + } fields;
  5470. +} touch_compat_rev_reg_t;
  5471. +C_ASSERT(sizeof(touch_compat_rev_reg_t) == 4);
  5472. +
  5473. +
  5474. +//
  5475. +// Touch Register Block is the full set of registers from offset 0x00h to 0x3F
  5476. +// This is the entire set of registers needed for normal touch operation. It does not include test
  5477. +// registers such as TOUCH_TEST_CTRL_REG
  5478. +//
  5479. +#define TOUCH_REG_BLOCK_OFFSET TOUCH_STS_REG_OFFSET
  5480. +
  5481. +typedef struct touch_reg_block
  5482. +{
  5483. + touch_sts_reg_t sts_reg; // 0x00
  5484. + touch_frame_char_reg_t frame_char_reg; // 0x04
  5485. + touch_err_reg_t error_reg; // 0x08
  5486. + u32 reserved0; // 0x0C
  5487. + touch_id_reg_t id_reg; // 0x10
  5488. + touch_data_sz_reg_t data_size_reg; // 0x14
  5489. + touch_caps_reg_t caps_reg; // 0x18
  5490. + touch_cfg_reg_t cfg_reg; // 0x1C
  5491. + touch_cmd_reg_t cmd_reg; // 0x20
  5492. + touch_pwr_mgmt_ctrl_reg_t pwm_mgme_ctrl_reg; // 0x24
  5493. + touch_ven_hw_info_reg_t ven_hw_info_reg; // 0x28
  5494. + touch_hw_rev_reg_t hw_rev_reg; // 0x2C
  5495. + touch_fw_rev_reg_t fw_rev_reg; // 0x30
  5496. + touch_compat_rev_reg_t compat_rev_reg; // 0x34
  5497. + u32 reserved1; // 0x38
  5498. + u32 reserved2; // 0x3C
  5499. +} touch_reg_block_t;
  5500. +C_ASSERT(sizeof(touch_reg_block_t) == 64);
  5501. +
  5502. +
  5503. +//
  5504. +// Offset 40h: Test Control Register
  5505. +// This register
  5506. +//
  5507. +#define TOUCH_TEST_CTRL_REG_OFFSET 0x40
  5508. +
  5509. +typedef union touch_test_ctrl_reg
  5510. +{
  5511. + u32 reg_value;
  5512. +
  5513. + struct
  5514. + {
  5515. + // Size of Test Frame in Raw Data Mode: This field specifies the test frame size in raw data
  5516. + // mode in multiple of 64 bytes. For example, if this field value is 16, the test frame size
  5517. + // will be 16x64 = 1K.
  5518. + u32 raw_test_frame_size :16;
  5519. + // Number of Raw Data Frames or HID Report Packets Generation. This field represents the number
  5520. + // of test frames or HID reports to be generated when test mode is enabled. When multiple
  5521. + // packets/frames are generated, they need be generated at 100 Hz frequency, i.e. 10ms per
  5522. + // packet/frame.
  5523. + u32 num_test_frames :16;
  5524. + } fields;
  5525. +} touch_test_ctrl_reg_t;
  5526. +C_ASSERT(sizeof(touch_test_ctrl_reg_t) == 4);
  5527. +
  5528. +
  5529. +//
  5530. +// Offsets 0x000 to 0xFFF are reserved for Intel-defined Registers
  5531. +//
  5532. +#define TOUCH_REGISTER_LIMIT 0xFFF
  5533. +
  5534. +
  5535. +//
  5536. +// Data Window: Address 0x1000-0x1FFFF
  5537. +// The data window is reserved for writing and reading large quantities of data to and from the
  5538. +// sensor.
  5539. +//
  5540. +#define TOUCH_DATA_WINDOW_OFFSET 0x1000
  5541. +#define TOUCH_DATA_WINDOW_LIMIT 0x1FFFF
  5542. +
  5543. +#define TOUCH_SENSOR_MAX_OFFSET TOUCH_DATA_WINDOW_LIMIT
  5544. +
  5545. +
  5546. +//
  5547. +// The following data structures represent the headers defined in the Data Structures chapter of the
  5548. +// Intel Integrated Touch EDS
  5549. +//
  5550. +
  5551. +// Enumeration used in TOUCH_RAW_DATA_HDR
  5552. +typedef enum touch_raw_data_types
  5553. +{
  5554. + TOUCH_RAW_DATA_TYPE_FRAME = 0,
  5555. + TOUCH_RAW_DATA_TYPE_ERROR, // RawData will be the TOUCH_ERROR struct below
  5556. + TOUCH_RAW_DATA_TYPE_VENDOR_DATA, // Set when InterruptType is Vendor Data
  5557. + TOUCH_RAW_DATA_TYPE_HID_REPORT,
  5558. + TOUCH_RAW_DATA_TYPE_GET_FEATURES,
  5559. + TOUCH_RAW_DATA_TYPE_MAX
  5560. +} touch_raw_data_types_t;
  5561. +C_ASSERT(sizeof(touch_raw_data_types_t) == 4);
  5562. +
  5563. +// Private data structure. Kernels must copy to HID driver buffer
  5564. +typedef struct touch_hid_private_data
  5565. +{
  5566. + u32 transaction_id;
  5567. + u8 reserved[28];
  5568. +} touch_hid_private_data_t;
  5569. +C_ASSERT(sizeof(touch_hid_private_data_t) == 32);
  5570. +
  5571. +// This is the data structure sent from the PCH FW to the EU kernel
  5572. +typedef struct touch_raw_data_hdr
  5573. +{
  5574. + u32 data_type; // use values from TOUCH_RAW_DATA_TYPES
  5575. + u32 raw_data_size_bytes; // The size in bytes of the raw data read from the
  5576. + // sensor, does not include TOUCH_RAW_DATA_HDR. Will
  5577. + // be the sum of all uFrames, or size of TOUCH_ERROR
  5578. + // for if DataType is TOUCH_RAW_DATA_TYPE_ERROR
  5579. + u32 buffer_id; // An ID to qualify with the feedback data to track
  5580. + // buffer usage
  5581. + u32 protocol_ver; // Must match protocol version of the EDS
  5582. + u8 kernel_compat_id; // Copied from the Compatibility Revision ID Reg
  5583. + u8 reserved[15]; // Padding to extend header to full 64 bytes and
  5584. + // allow for growth
  5585. + touch_hid_private_data_t hid_private_data; // Private data structure. Kernels must copy to HID
  5586. + // driver buffer
  5587. +} touch_raw_data_hdr_t;
  5588. +C_ASSERT(sizeof(touch_raw_data_hdr_t) == 64);
  5589. +
  5590. +typedef struct touch_raw_data
  5591. +{
  5592. + touch_raw_data_hdr_t header;
  5593. + u8 raw_data[1]; // used to access the raw data as an array and keep the
  5594. + // compilers happy. Actual size of this array is
  5595. + // Header.RawDataSizeBytes
  5596. +} touch_raw_data_t;
  5597. +
  5598. +
  5599. +// The following section describes the data passed in TOUCH_RAW_DATA.RawData when DataType equals
  5600. +// TOUCH_RAW_DATA_TYPE_ERROR
  5601. +// Note: This data structure is also applied to HID mode
  5602. +typedef enum touch_err_types
  5603. +{
  5604. + TOUCH_RAW_DATA_ERROR = 0,
  5605. + TOUCH_RAW_ERROR_MAX
  5606. +} touch_err_types_t;
  5607. +C_ASSERT(sizeof(touch_err_types_t) == 4);
  5608. +
  5609. +typedef union touch_me_fw_error
  5610. +{
  5611. + u32 value;
  5612. +
  5613. + struct
  5614. + {
  5615. + u32 invalid_frame_characteristics : 1;
  5616. + u32 microframe_index_invalid : 1;
  5617. + u32 reserved : 30;
  5618. + } fields;
  5619. +} touch_me_fw_error_t;
  5620. +C_ASSERT(sizeof(touch_me_fw_error_t) == 4);
  5621. +
  5622. +typedef struct touch_error
  5623. +{
  5624. + u8 touch_error_type; // This must be a value from TOUCH_ERROR_TYPES
  5625. + u8 reserved[3];
  5626. + touch_me_fw_error_t touch_me_fw_error;
  5627. + touch_err_reg_t touch_error_register; // Contains the value copied from the Touch Error Reg
  5628. +} touch_error_t;
  5629. +C_ASSERT(sizeof(touch_error_t) == 12);
  5630. +
  5631. +// Enumeration used in TOUCH_FEEDBACK_BUFFER
  5632. +typedef enum touch_feedback_cmd_types
  5633. +{
  5634. + TOUCH_FEEDBACK_CMD_TYPE_NONE = 0,
  5635. + TOUCH_FEEDBACK_CMD_TYPE_SOFT_RESET,
  5636. + TOUCH_FEEDBACK_CMD_TYPE_GOTO_ARMED,
  5637. + TOUCH_FEEDBACK_CMD_TYPE_GOTO_SENSING,
  5638. + TOUCH_FEEDBACK_CMD_TYPE_GOTO_SLEEP,
  5639. + TOUCH_FEEDBACK_CMD_TYPE_GOTO_DOZE,
  5640. + TOUCH_FEEDBACK_CMD_TYPE_HARD_RESET,
  5641. + TOUCH_FEEDBACK_CMD_TYPE_MAX
  5642. +} touch_feedback_cmd_types_t;
  5643. +C_ASSERT(sizeof(touch_feedback_cmd_types_t) == 4);
  5644. +
  5645. +// Enumeration used in TOUCH_FEEDBACK_HDR
  5646. +typedef enum touch_feedback_data_types
  5647. +{
  5648. + TOUCH_FEEDBACK_DATA_TYPE_FEEDBACK = 0, // This is vendor specific feedback to be written to the sensor
  5649. + TOUCH_FEEDBACK_DATA_TYPE_SET_FEATURES, // This is a set features command to be written to the sensor
  5650. + TOUCH_FEEDBACK_DATA_TYPE_GET_FEATURES, // This is a get features command to be written to the sensor
  5651. + TOUCH_FEEDBACK_DATA_TYPE_OUTPUT_REPORT, // This is a HID output report to be written to the sensor
  5652. + TOUCH_FEEDBACK_DATA_TYPE_STORE_DATA, // This is calibration data to be written to system flash
  5653. + TOUCH_FEEDBACK_DATA_TYPE_MAX
  5654. +} touch_feedback_data_types_t;
  5655. +C_ASSERT(sizeof(touch_feedback_data_types_t) == 4);
  5656. +
  5657. +// This is the data structure sent from the EU kernels back to the ME FW.
  5658. +// In addition to "feedback" data, the FW can execute a "command" described by the command type parameter.
  5659. +// Any payload data will always be sent to the TIC first, then any command will be issued.
  5660. +typedef struct touch_feedback_hdr
  5661. +{
  5662. + u32 feedback_cmd_type; // use values from TOUCH_FEEDBACK_CMD_TYPES
  5663. + u32 payload_size_bytes; // The amount of data to be written to the sensor, not including the header
  5664. + u32 buffer_id; // The ID of the raw data buffer that generated this feedback data
  5665. + u32 protocol_ver; // Must match protocol version of the EDS
  5666. + u32 feedback_data_type; // use values from TOUCH_FEEDBACK_DATA_TYPES. This is not relevant if PayloadSizeBytes is 0
  5667. + u32 spi_offest; // The offset from TOUCH_DATA_WINDOW_OFFSET at which to write the Payload data. Maximum offset is 0x1EFFF.
  5668. + u8 reserved[40]; // Padding to extend header to full 64 bytes and allow for growth
  5669. +} touch_feedback_hdr_t;
  5670. +C_ASSERT(sizeof(touch_feedback_hdr_t) == 64);
  5671. +
  5672. +typedef struct touch_feedback_buffer
  5673. +{
  5674. + touch_feedback_hdr_t Header;
  5675. + u8 feedback_data[1]; // used to access the feedback data as an array and keep the compilers happy. Actual size of this array is Header.PayloadSizeBytes
  5676. +} touch_feedback_buffer_t;
  5677. +
  5678. +
  5679. +//
  5680. +// This data structure describes the header prepended to all data
  5681. +// written to the touch IC at the bulk data write (TOUCH_DATA_WINDOW_OFFSET + TOUCH_FEEDBACK_HDR.SpiOffest) address.
  5682. +typedef enum touch_write_data_type
  5683. +{
  5684. + TOUCH_WRITE_DATA_TYPE_FW_LOAD = 0,
  5685. + TOUCH_WRITE_DATA_TYPE_DATA_LOAD,
  5686. + TOUCH_WRITE_DATA_TYPE_FEEDBACK,
  5687. + TOUCH_WRITE_DATA_TYPE_SET_FEATURES,
  5688. + TOUCH_WRITE_DATA_TYPE_GET_FEATURES,
  5689. + TOUCH_WRITE_DATA_TYPE_OUTPUT_REPORT,
  5690. + TOUCH_WRITE_DATA_TYPE_NO_DATA_USE_DEFAULTS,
  5691. + TOUCH_WRITE_DATA_TYPE_MAX
  5692. +} touch_write_data_type_t;
  5693. +C_ASSERT(sizeof(touch_write_data_type_t) == 4);
  5694. +
  5695. +typedef struct touch_write_hdr
  5696. +{
  5697. + u32 write_data_type; // Use values from TOUCH_WRITE_DATA_TYPE
  5698. + u32 write_data_len; // This field designates the amount of data to follow
  5699. +} touch_write_hdr_t;
  5700. +C_ASSERT(sizeof(touch_write_hdr_t) == 8);
  5701. +
  5702. +typedef struct touch_write_data
  5703. +{
  5704. + touch_write_hdr_t header;
  5705. + u8 write_data[1]; // used to access the write data as an array and keep the compilers happy. Actual size of this array is Header.WriteDataLen
  5706. +} touch_write_data_t;
  5707. +
  5708. +#pragma pack()
  5709. +
  5710. +#endif // _TOUCH_SENSOR_REGS_H
  5711. diff --git a/drivers/misc/ipts/ipts-state.h b/drivers/misc/ipts/ipts-state.h
  5712. new file mode 100644
  5713. index 0000000..39a2eaf
  5714. --- /dev/null
  5715. +++ b/drivers/misc/ipts/ipts-state.h
  5716. @@ -0,0 +1,29 @@
  5717. +/*
  5718. + * Intel Precise Touch & Stylus state codes
  5719. + *
  5720. + * Copyright (c) 2016, Intel Corporation.
  5721. + *
  5722. + * This program is free software; you can redistribute it and/or modify it
  5723. + * under the terms and conditions of the GNU General Public License,
  5724. + * version 2, as published by the Free Software Foundation.
  5725. + *
  5726. + * This program is distributed in the hope it will be useful, but WITHOUT
  5727. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  5728. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  5729. + * more details.
  5730. + */
  5731. +
  5732. +#ifndef _IPTS_STATE_H_
  5733. +#define _IPTS_STATE_H_
  5734. +
  5735. +/* ipts driver states */
  5736. +typedef enum ipts_state {
  5737. + IPTS_STA_NONE,
  5738. + IPTS_STA_INIT,
  5739. + IPTS_STA_RESOURCE_READY,
  5740. + IPTS_STA_HID_STARTED,
  5741. + IPTS_STA_RAW_DATA_STARTED,
  5742. + IPTS_STA_STOPPING
  5743. +} ipts_state_t;
  5744. +
  5745. +#endif // _IPTS_STATE_H_
  5746. diff --git a/drivers/misc/ipts/ipts.h b/drivers/misc/ipts/ipts.h
  5747. new file mode 100644
  5748. index 0000000..1fcd021
  5749. --- /dev/null
  5750. +++ b/drivers/misc/ipts/ipts.h
  5751. @@ -0,0 +1,200 @@
  5752. +/*
  5753. + *
  5754. + * Intel Management Engine Interface (Intel MEI) Client Driver for IPTS
  5755. + * Copyright (c) 2016, Intel Corporation.
  5756. + *
  5757. + * This program is free software; you can redistribute it and/or modify it
  5758. + * under the terms and conditions of the GNU General Public License,
  5759. + * version 2, as published by the Free Software Foundation.
  5760. + *
  5761. + * This program is distributed in the hope it will be useful, but WITHOUT
  5762. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  5763. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  5764. + * more details.
  5765. + *
  5766. + */
  5767. +
  5768. +#ifndef _IPTS_H_
  5769. +#define _IPTS_H_
  5770. +
  5771. +#include <linux/types.h>
  5772. +#include <linux/mei_cl_bus.h>
  5773. +#include <linux/hid.h>
  5774. +#include <linux/intel_ipts_if.h>
  5775. +
  5776. +#include "ipts-mei-msgs.h"
  5777. +#include "ipts-state.h"
  5778. +#include "ipts-binary-spec.h"
  5779. +
  5780. +//#define ENABLE_IPTS_DEBUG /* enable IPTS debug */
  5781. +
  5782. +#ifdef ENABLE_IPTS_DEBUG
  5783. +
  5784. +#define ipts_info(ipts, format, arg...) do {\
  5785. + dev_info(&ipts->cldev->dev, format, ##arg);\
  5786. +} while (0)
  5787. +
  5788. +#define ipts_dbg(ipts, format, arg...) do {\
  5789. + dev_info(&ipts->cldev->dev, format, ##arg);\
  5790. +} while (0)
  5791. +
  5792. +//#define RUN_DBG_THREAD
  5793. +
  5794. +#else
  5795. +
  5796. +#define ipts_info(ipts, format, arg...) do {} while(0);
  5797. +#define ipts_dbg(ipts, format, arg...) do {} while(0);
  5798. +
  5799. +#endif
  5800. +
  5801. +#define ipts_err(ipts, format, arg...) do {\
  5802. + dev_err(&ipts->cldev->dev, format, ##arg);\
  5803. +} while (0)
  5804. +
  5805. +#define HID_PARALLEL_DATA_BUFFERS TOUCH_SENSOR_MAX_DATA_BUFFERS
  5806. +
  5807. +#define IPTS_MAX_RETRY 3
  5808. +
  5809. +typedef struct ipts_buffer_info {
  5810. + char *addr;
  5811. + dma_addr_t dma_addr;
  5812. +} ipts_buffer_info_t;
  5813. +
  5814. +typedef struct ipts_gfx_info {
  5815. + u64 gfx_handle;
  5816. + intel_ipts_ops_t ipts_ops;
  5817. +} ipts_gfx_info_t;
  5818. +
  5819. +typedef struct ipts_resource {
  5820. + /* ME & Gfx resource */
  5821. + ipts_buffer_info_t touch_data_buffer_raw[HID_PARALLEL_DATA_BUFFERS];
  5822. + ipts_buffer_info_t touch_data_buffer_hid;
  5823. +
  5824. + ipts_buffer_info_t feedback_buffer[HID_PARALLEL_DATA_BUFFERS];
  5825. +
  5826. + ipts_buffer_info_t hid2me_buffer;
  5827. + u32 hid2me_buffer_size;
  5828. +
  5829. + u8 wq_item_size;
  5830. + intel_ipts_wq_info_t wq_info;
  5831. +
  5832. + /* ME2HID buffer */
  5833. + char *me2hid_buffer;
  5834. +
  5835. + /* Gfx specific resource */
  5836. + ipts_buffer_info_t raw_data_mode_output_buffer
  5837. + [HID_PARALLEL_DATA_BUFFERS][MAX_NUM_OUTPUT_BUFFERS];
  5838. +
  5839. + int num_of_outputs;
  5840. +
  5841. + bool default_resource_ready;
  5842. + bool raw_data_resource_ready;
  5843. +} ipts_resource_t;
  5844. +
  5845. +typedef struct ipts_info {
  5846. + struct mei_cl_device *cldev;
  5847. + struct hid_device *hid;
  5848. +
  5849. + struct work_struct init_work;
  5850. + struct work_struct raw_data_work;
  5851. + struct work_struct gfx_status_work;
  5852. +
  5853. + struct task_struct *event_loop;
  5854. +
  5855. +#if IS_ENABLED(CONFIG_DEBUG_FS)
  5856. + struct dentry *dbgfs_dir;
  5857. +#endif
  5858. +
  5859. + ipts_state_t state;
  5860. +
  5861. + touch_sensor_mode_t sensor_mode;
  5862. + touch_sensor_get_device_info_rsp_data_t device_info;
  5863. + ipts_resource_t resource;
  5864. + u8 hid_input_report[HID_MAX_BUFFER_SIZE];
  5865. + int num_of_parallel_data_buffers;
  5866. + bool hid_desc_ready;
  5867. +
  5868. + int current_buffer_index;
  5869. + int last_buffer_completed;
  5870. + int *last_submitted_id;
  5871. +
  5872. + ipts_gfx_info_t gfx_info;
  5873. + u64 kernel_handle;
  5874. + int gfx_status;
  5875. + bool display_status;
  5876. +
  5877. + bool switch_sensor_mode;
  5878. + touch_sensor_mode_t new_sensor_mode;
  5879. +
  5880. + int retry;
  5881. + bool restart;
  5882. +} ipts_info_t;
  5883. +
  5884. +#if IS_ENABLED(CONFIG_DEBUG_FS)
  5885. +int ipts_dbgfs_register(ipts_info_t *ipts, const char *name);
  5886. +void ipts_dbgfs_deregister(ipts_info_t *ipts);
  5887. +#else
  5888. +static int ipts_dbgfs_register(ipts_info_t *ipts, const char *name);
  5889. +static void ipts_dbgfs_deregister(ipts_info_t *ipts);
  5890. +#endif /* CONFIG_DEBUG_FS */
  5891. +
  5892. +/* inline functions */
  5893. +static inline void ipts_set_state(ipts_info_t *ipts, ipts_state_t state)
  5894. +{
  5895. + ipts->state = state;
  5896. +}
  5897. +
  5898. +static inline ipts_state_t ipts_get_state(const ipts_info_t *ipts)
  5899. +{
  5900. + return ipts->state;
  5901. +}
  5902. +
  5903. +static inline bool ipts_is_default_resource_ready(const ipts_info_t *ipts)
  5904. +{
  5905. + return ipts->resource.default_resource_ready;
  5906. +}
  5907. +
  5908. +static inline bool ipts_is_raw_data_resource_ready(const ipts_info_t *ipts)
  5909. +{
  5910. + return ipts->resource.raw_data_resource_ready;
  5911. +}
  5912. +
  5913. +static inline ipts_buffer_info_t* ipts_get_feedback_buffer(ipts_info_t *ipts,
  5914. + int buffer_idx)
  5915. +{
  5916. + return &ipts->resource.feedback_buffer[buffer_idx];
  5917. +}
  5918. +
  5919. +static inline ipts_buffer_info_t* ipts_get_touch_data_buffer_hid(ipts_info_t *ipts)
  5920. +{
  5921. + return &ipts->resource.touch_data_buffer_hid;
  5922. +}
  5923. +
  5924. +static inline ipts_buffer_info_t* ipts_get_output_buffers_by_parallel_id(
  5925. + ipts_info_t *ipts,
  5926. + int parallel_idx)
  5927. +{
  5928. + return &ipts->resource.raw_data_mode_output_buffer[parallel_idx][0];
  5929. +}
  5930. +
  5931. +static inline ipts_buffer_info_t* ipts_get_hid2me_buffer(ipts_info_t *ipts)
  5932. +{
  5933. + return &ipts->resource.hid2me_buffer;
  5934. +}
  5935. +
  5936. +static inline void ipts_set_wq_item_size(ipts_info_t *ipts, u8 size)
  5937. +{
  5938. + ipts->resource.wq_item_size = size;
  5939. +}
  5940. +
  5941. +static inline u8 ipts_get_wq_item_size(const ipts_info_t *ipts)
  5942. +{
  5943. + return ipts->resource.wq_item_size;
  5944. +}
  5945. +
  5946. +static inline int ipts_get_num_of_parallel_buffers(const ipts_info_t *ipts)
  5947. +{
  5948. + return ipts->num_of_parallel_data_buffers;
  5949. +}
  5950. +
  5951. +#endif // _IPTS_H_
  5952. diff --git a/drivers/misc/mei/hw-me-regs.h b/drivers/misc/mei/hw-me-regs.h
  5953. index e4b10b2..883b185 100644
  5954. --- a/drivers/misc/mei/hw-me-regs.h
  5955. +++ b/drivers/misc/mei/hw-me-regs.h
  5956. @@ -119,6 +119,7 @@
  5957. #define MEI_DEV_ID_SPT 0x9D3A /* Sunrise Point */
  5958. #define MEI_DEV_ID_SPT_2 0x9D3B /* Sunrise Point 2 */
  5959. +#define MEI_DEV_ID_SPT_4 0x9D3E /* Sunrise Point 4 */
  5960. #define MEI_DEV_ID_SPT_H 0xA13A /* Sunrise Point H */
  5961. #define MEI_DEV_ID_SPT_H_2 0xA13B /* Sunrise Point H 2 */
  5962. diff --git a/drivers/misc/mei/pci-me.c b/drivers/misc/mei/pci-me.c
  5963. index c77e08c..5773a6c 100644
  5964. --- a/drivers/misc/mei/pci-me.c
  5965. +++ b/drivers/misc/mei/pci-me.c
  5966. @@ -86,6 +86,7 @@ static const struct pci_device_id mei_me_pci_tbl[] = {
  5967. {MEI_PCI_DEVICE(MEI_DEV_ID_SPT, MEI_ME_PCH8_CFG)},
  5968. {MEI_PCI_DEVICE(MEI_DEV_ID_SPT_2, MEI_ME_PCH8_CFG)},
  5969. + {MEI_PCI_DEVICE(MEI_DEV_ID_SPT_4, MEI_ME_PCH8_CFG)},
  5970. {MEI_PCI_DEVICE(MEI_DEV_ID_SPT_H, MEI_ME_PCH8_SPS_CFG)},
  5971. {MEI_PCI_DEVICE(MEI_DEV_ID_SPT_H_2, MEI_ME_PCH8_SPS_CFG)},
  5972. {MEI_PCI_DEVICE(MEI_DEV_ID_LBG, MEI_ME_PCH8_CFG)},
  5973. diff --git a/include/linux/intel_ipts_if.h b/include/linux/intel_ipts_if.h
  5974. new file mode 100644
  5975. index 0000000..f329bbf
  5976. --- /dev/null
  5977. +++ b/include/linux/intel_ipts_if.h
  5978. @@ -0,0 +1,75 @@
  5979. +/*
  5980. + *
  5981. + * GFX interface to support Intel Precise Touch & Stylus
  5982. + * Copyright (c) 2016 Intel Corporation.
  5983. + *
  5984. + * This program is free software; you can redistribute it and/or modify it
  5985. + * under the terms and conditions of the GNU General Public License,
  5986. + * version 2, as published by the Free Software Foundation.
  5987. + *
  5988. + * This program is distributed in the hope it will be useful, but WITHOUT
  5989. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  5990. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  5991. + * more details.
  5992. + *
  5993. + */
  5994. +
  5995. +#ifndef INTEL_IPTS_IF_H
  5996. +#define INTEL_IPTS_IF_H
  5997. +
  5998. +enum {
  5999. + IPTS_INTERFACE_V1 = 1,
  6000. +};
  6001. +
  6002. +#define IPTS_BUF_FLAG_CONTIGUOUS 0x01
  6003. +
  6004. +#define IPTS_NOTIFY_STA_BACKLIGHT_OFF 0x00
  6005. +#define IPTS_NOTIFY_STA_BACKLIGHT_ON 0x01
  6006. +
  6007. +typedef struct intel_ipts_mapbuffer {
  6008. + u32 size;
  6009. + u32 flags;
  6010. + void *gfx_addr;
  6011. + void *cpu_addr;
  6012. + u64 buf_handle;
  6013. + u64 phy_addr;
  6014. +} intel_ipts_mapbuffer_t;
  6015. +
  6016. +typedef struct intel_ipts_wq_info {
  6017. + u64 db_addr;
  6018. + u64 db_phy_addr;
  6019. + u32 db_cookie_offset;
  6020. + u32 wq_size;
  6021. + u64 wq_addr;
  6022. + u64 wq_phy_addr;
  6023. + u64 wq_head_addr; /* head of wq is managed by GPU */
  6024. + u64 wq_head_phy_addr; /* head of wq is managed by GPU */
  6025. + u64 wq_tail_addr; /* tail of wq is managed by CSME */
  6026. + u64 wq_tail_phy_addr; /* tail of wq is managed by CSME */
  6027. +} intel_ipts_wq_info_t;
  6028. +
  6029. +typedef struct intel_ipts_ops {
  6030. + int (*get_wq_info)(uint64_t gfx_handle, intel_ipts_wq_info_t *wq_info);
  6031. + int (*map_buffer)(uint64_t gfx_handle, intel_ipts_mapbuffer_t *mapbuffer);
  6032. + int (*unmap_buffer)(uint64_t gfx_handle, uint64_t buf_handle);
  6033. +} intel_ipts_ops_t;
  6034. +
  6035. +typedef struct intel_ipts_callback {
  6036. + void (*workload_complete)(void *data);
  6037. + void (*notify_gfx_status)(u32 status, void *data);
  6038. +} intel_ipts_callback_t;
  6039. +
  6040. +typedef struct intel_ipts_connect {
  6041. + intel_ipts_callback_t ipts_cb; /* input : callback addresses */
  6042. + void *data; /* input : callback data */
  6043. + u32 if_version; /* input : interface version */
  6044. +
  6045. + u32 gfx_version; /* output : gfx version */
  6046. + u64 gfx_handle; /* output : gfx handle */
  6047. + intel_ipts_ops_t ipts_ops; /* output : gfx ops for IPTS */
  6048. +} intel_ipts_connect_t;
  6049. +
  6050. +int intel_ipts_connect(intel_ipts_connect_t *ipts_connect);
  6051. +void intel_ipts_disconnect(uint64_t gfx_handle);
  6052. +
  6053. +#endif // INTEL_IPTS_IF_H