0005-ipts.patch 193 KB

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