0005-ipts.patch 211 KB

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