0005-ipts.patch 202 KB

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