intel_display.c 247 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249
  1. /*
  2. * Copyright © 2006-2007 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  21. * DEALINGS IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Eric Anholt <eric@anholt.net>
  25. */
  26. #include <linux/dmi.h>
  27. #include <linux/module.h>
  28. #include <linux/input.h>
  29. #include <linux/i2c.h>
  30. #include <linux/kernel.h>
  31. #include <linux/slab.h>
  32. #include <linux/vgaarb.h>
  33. #include <drm/drm_edid.h>
  34. #include <drm/drmP.h>
  35. #include "intel_drv.h"
  36. #include <drm/i915_drm.h>
  37. #include "i915_drv.h"
  38. #include "i915_trace.h"
  39. #include <drm/drm_dp_helper.h>
  40. #include <drm/drm_crtc_helper.h>
  41. #include <linux/dma_remapping.h>
  42. bool intel_pipe_has_type(struct drm_crtc *crtc, int type);
  43. static void intel_increase_pllclock(struct drm_crtc *crtc);
  44. static void intel_crtc_update_cursor(struct drm_crtc *crtc, bool on);
  45. typedef struct {
  46. /* given values */
  47. int n;
  48. int m1, m2;
  49. int p1, p2;
  50. /* derived values */
  51. int dot;
  52. int vco;
  53. int m;
  54. int p;
  55. } intel_clock_t;
  56. typedef struct {
  57. int min, max;
  58. } intel_range_t;
  59. typedef struct {
  60. int dot_limit;
  61. int p2_slow, p2_fast;
  62. } intel_p2_t;
  63. #define INTEL_P2_NUM 2
  64. typedef struct intel_limit intel_limit_t;
  65. struct intel_limit {
  66. intel_range_t dot, vco, n, m, m1, m2, p, p1;
  67. intel_p2_t p2;
  68. bool (* find_pll)(const intel_limit_t *, struct drm_crtc *,
  69. int, int, intel_clock_t *, intel_clock_t *);
  70. };
  71. /* FDI */
  72. #define IRONLAKE_FDI_FREQ 2700000 /* in kHz for mode->clock */
  73. int
  74. intel_pch_rawclk(struct drm_device *dev)
  75. {
  76. struct drm_i915_private *dev_priv = dev->dev_private;
  77. WARN_ON(!HAS_PCH_SPLIT(dev));
  78. return I915_READ(PCH_RAWCLK_FREQ) & RAWCLK_FREQ_MASK;
  79. }
  80. static bool
  81. intel_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
  82. int target, int refclk, intel_clock_t *match_clock,
  83. intel_clock_t *best_clock);
  84. static bool
  85. intel_g4x_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
  86. int target, int refclk, intel_clock_t *match_clock,
  87. intel_clock_t *best_clock);
  88. static bool
  89. intel_find_pll_g4x_dp(const intel_limit_t *, struct drm_crtc *crtc,
  90. int target, int refclk, intel_clock_t *match_clock,
  91. intel_clock_t *best_clock);
  92. static bool
  93. intel_find_pll_ironlake_dp(const intel_limit_t *, struct drm_crtc *crtc,
  94. int target, int refclk, intel_clock_t *match_clock,
  95. intel_clock_t *best_clock);
  96. static bool
  97. intel_vlv_find_best_pll(const intel_limit_t *limit, struct drm_crtc *crtc,
  98. int target, int refclk, intel_clock_t *match_clock,
  99. intel_clock_t *best_clock);
  100. static inline u32 /* units of 100MHz */
  101. intel_fdi_link_freq(struct drm_device *dev)
  102. {
  103. if (IS_GEN5(dev)) {
  104. struct drm_i915_private *dev_priv = dev->dev_private;
  105. return (I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK) + 2;
  106. } else
  107. return 27;
  108. }
  109. static const intel_limit_t intel_limits_i8xx_dvo = {
  110. .dot = { .min = 25000, .max = 350000 },
  111. .vco = { .min = 930000, .max = 1400000 },
  112. .n = { .min = 3, .max = 16 },
  113. .m = { .min = 96, .max = 140 },
  114. .m1 = { .min = 18, .max = 26 },
  115. .m2 = { .min = 6, .max = 16 },
  116. .p = { .min = 4, .max = 128 },
  117. .p1 = { .min = 2, .max = 33 },
  118. .p2 = { .dot_limit = 165000,
  119. .p2_slow = 4, .p2_fast = 2 },
  120. .find_pll = intel_find_best_PLL,
  121. };
  122. static const intel_limit_t intel_limits_i8xx_lvds = {
  123. .dot = { .min = 25000, .max = 350000 },
  124. .vco = { .min = 930000, .max = 1400000 },
  125. .n = { .min = 3, .max = 16 },
  126. .m = { .min = 96, .max = 140 },
  127. .m1 = { .min = 18, .max = 26 },
  128. .m2 = { .min = 6, .max = 16 },
  129. .p = { .min = 4, .max = 128 },
  130. .p1 = { .min = 1, .max = 6 },
  131. .p2 = { .dot_limit = 165000,
  132. .p2_slow = 14, .p2_fast = 7 },
  133. .find_pll = intel_find_best_PLL,
  134. };
  135. static const intel_limit_t intel_limits_i9xx_sdvo = {
  136. .dot = { .min = 20000, .max = 400000 },
  137. .vco = { .min = 1400000, .max = 2800000 },
  138. .n = { .min = 1, .max = 6 },
  139. .m = { .min = 70, .max = 120 },
  140. .m1 = { .min = 10, .max = 22 },
  141. .m2 = { .min = 5, .max = 9 },
  142. .p = { .min = 5, .max = 80 },
  143. .p1 = { .min = 1, .max = 8 },
  144. .p2 = { .dot_limit = 200000,
  145. .p2_slow = 10, .p2_fast = 5 },
  146. .find_pll = intel_find_best_PLL,
  147. };
  148. static const intel_limit_t intel_limits_i9xx_lvds = {
  149. .dot = { .min = 20000, .max = 400000 },
  150. .vco = { .min = 1400000, .max = 2800000 },
  151. .n = { .min = 1, .max = 6 },
  152. .m = { .min = 70, .max = 120 },
  153. .m1 = { .min = 10, .max = 22 },
  154. .m2 = { .min = 5, .max = 9 },
  155. .p = { .min = 7, .max = 98 },
  156. .p1 = { .min = 1, .max = 8 },
  157. .p2 = { .dot_limit = 112000,
  158. .p2_slow = 14, .p2_fast = 7 },
  159. .find_pll = intel_find_best_PLL,
  160. };
  161. static const intel_limit_t intel_limits_g4x_sdvo = {
  162. .dot = { .min = 25000, .max = 270000 },
  163. .vco = { .min = 1750000, .max = 3500000},
  164. .n = { .min = 1, .max = 4 },
  165. .m = { .min = 104, .max = 138 },
  166. .m1 = { .min = 17, .max = 23 },
  167. .m2 = { .min = 5, .max = 11 },
  168. .p = { .min = 10, .max = 30 },
  169. .p1 = { .min = 1, .max = 3},
  170. .p2 = { .dot_limit = 270000,
  171. .p2_slow = 10,
  172. .p2_fast = 10
  173. },
  174. .find_pll = intel_g4x_find_best_PLL,
  175. };
  176. static const intel_limit_t intel_limits_g4x_hdmi = {
  177. .dot = { .min = 22000, .max = 400000 },
  178. .vco = { .min = 1750000, .max = 3500000},
  179. .n = { .min = 1, .max = 4 },
  180. .m = { .min = 104, .max = 138 },
  181. .m1 = { .min = 16, .max = 23 },
  182. .m2 = { .min = 5, .max = 11 },
  183. .p = { .min = 5, .max = 80 },
  184. .p1 = { .min = 1, .max = 8},
  185. .p2 = { .dot_limit = 165000,
  186. .p2_slow = 10, .p2_fast = 5 },
  187. .find_pll = intel_g4x_find_best_PLL,
  188. };
  189. static const intel_limit_t intel_limits_g4x_single_channel_lvds = {
  190. .dot = { .min = 20000, .max = 115000 },
  191. .vco = { .min = 1750000, .max = 3500000 },
  192. .n = { .min = 1, .max = 3 },
  193. .m = { .min = 104, .max = 138 },
  194. .m1 = { .min = 17, .max = 23 },
  195. .m2 = { .min = 5, .max = 11 },
  196. .p = { .min = 28, .max = 112 },
  197. .p1 = { .min = 2, .max = 8 },
  198. .p2 = { .dot_limit = 0,
  199. .p2_slow = 14, .p2_fast = 14
  200. },
  201. .find_pll = intel_g4x_find_best_PLL,
  202. };
  203. static const intel_limit_t intel_limits_g4x_dual_channel_lvds = {
  204. .dot = { .min = 80000, .max = 224000 },
  205. .vco = { .min = 1750000, .max = 3500000 },
  206. .n = { .min = 1, .max = 3 },
  207. .m = { .min = 104, .max = 138 },
  208. .m1 = { .min = 17, .max = 23 },
  209. .m2 = { .min = 5, .max = 11 },
  210. .p = { .min = 14, .max = 42 },
  211. .p1 = { .min = 2, .max = 6 },
  212. .p2 = { .dot_limit = 0,
  213. .p2_slow = 7, .p2_fast = 7
  214. },
  215. .find_pll = intel_g4x_find_best_PLL,
  216. };
  217. static const intel_limit_t intel_limits_g4x_display_port = {
  218. .dot = { .min = 161670, .max = 227000 },
  219. .vco = { .min = 1750000, .max = 3500000},
  220. .n = { .min = 1, .max = 2 },
  221. .m = { .min = 97, .max = 108 },
  222. .m1 = { .min = 0x10, .max = 0x12 },
  223. .m2 = { .min = 0x05, .max = 0x06 },
  224. .p = { .min = 10, .max = 20 },
  225. .p1 = { .min = 1, .max = 2},
  226. .p2 = { .dot_limit = 0,
  227. .p2_slow = 10, .p2_fast = 10 },
  228. .find_pll = intel_find_pll_g4x_dp,
  229. };
  230. static const intel_limit_t intel_limits_pineview_sdvo = {
  231. .dot = { .min = 20000, .max = 400000},
  232. .vco = { .min = 1700000, .max = 3500000 },
  233. /* Pineview's Ncounter is a ring counter */
  234. .n = { .min = 3, .max = 6 },
  235. .m = { .min = 2, .max = 256 },
  236. /* Pineview only has one combined m divider, which we treat as m2. */
  237. .m1 = { .min = 0, .max = 0 },
  238. .m2 = { .min = 0, .max = 254 },
  239. .p = { .min = 5, .max = 80 },
  240. .p1 = { .min = 1, .max = 8 },
  241. .p2 = { .dot_limit = 200000,
  242. .p2_slow = 10, .p2_fast = 5 },
  243. .find_pll = intel_find_best_PLL,
  244. };
  245. static const intel_limit_t intel_limits_pineview_lvds = {
  246. .dot = { .min = 20000, .max = 400000 },
  247. .vco = { .min = 1700000, .max = 3500000 },
  248. .n = { .min = 3, .max = 6 },
  249. .m = { .min = 2, .max = 256 },
  250. .m1 = { .min = 0, .max = 0 },
  251. .m2 = { .min = 0, .max = 254 },
  252. .p = { .min = 7, .max = 112 },
  253. .p1 = { .min = 1, .max = 8 },
  254. .p2 = { .dot_limit = 112000,
  255. .p2_slow = 14, .p2_fast = 14 },
  256. .find_pll = intel_find_best_PLL,
  257. };
  258. /* Ironlake / Sandybridge
  259. *
  260. * We calculate clock using (register_value + 2) for N/M1/M2, so here
  261. * the range value for them is (actual_value - 2).
  262. */
  263. static const intel_limit_t intel_limits_ironlake_dac = {
  264. .dot = { .min = 25000, .max = 350000 },
  265. .vco = { .min = 1760000, .max = 3510000 },
  266. .n = { .min = 1, .max = 5 },
  267. .m = { .min = 79, .max = 127 },
  268. .m1 = { .min = 12, .max = 22 },
  269. .m2 = { .min = 5, .max = 9 },
  270. .p = { .min = 5, .max = 80 },
  271. .p1 = { .min = 1, .max = 8 },
  272. .p2 = { .dot_limit = 225000,
  273. .p2_slow = 10, .p2_fast = 5 },
  274. .find_pll = intel_g4x_find_best_PLL,
  275. };
  276. static const intel_limit_t intel_limits_ironlake_single_lvds = {
  277. .dot = { .min = 25000, .max = 350000 },
  278. .vco = { .min = 1760000, .max = 3510000 },
  279. .n = { .min = 1, .max = 3 },
  280. .m = { .min = 79, .max = 118 },
  281. .m1 = { .min = 12, .max = 22 },
  282. .m2 = { .min = 5, .max = 9 },
  283. .p = { .min = 28, .max = 112 },
  284. .p1 = { .min = 2, .max = 8 },
  285. .p2 = { .dot_limit = 225000,
  286. .p2_slow = 14, .p2_fast = 14 },
  287. .find_pll = intel_g4x_find_best_PLL,
  288. };
  289. static const intel_limit_t intel_limits_ironlake_dual_lvds = {
  290. .dot = { .min = 25000, .max = 350000 },
  291. .vco = { .min = 1760000, .max = 3510000 },
  292. .n = { .min = 1, .max = 3 },
  293. .m = { .min = 79, .max = 127 },
  294. .m1 = { .min = 12, .max = 22 },
  295. .m2 = { .min = 5, .max = 9 },
  296. .p = { .min = 14, .max = 56 },
  297. .p1 = { .min = 2, .max = 8 },
  298. .p2 = { .dot_limit = 225000,
  299. .p2_slow = 7, .p2_fast = 7 },
  300. .find_pll = intel_g4x_find_best_PLL,
  301. };
  302. /* LVDS 100mhz refclk limits. */
  303. static const intel_limit_t intel_limits_ironlake_single_lvds_100m = {
  304. .dot = { .min = 25000, .max = 350000 },
  305. .vco = { .min = 1760000, .max = 3510000 },
  306. .n = { .min = 1, .max = 2 },
  307. .m = { .min = 79, .max = 126 },
  308. .m1 = { .min = 12, .max = 22 },
  309. .m2 = { .min = 5, .max = 9 },
  310. .p = { .min = 28, .max = 112 },
  311. .p1 = { .min = 2, .max = 8 },
  312. .p2 = { .dot_limit = 225000,
  313. .p2_slow = 14, .p2_fast = 14 },
  314. .find_pll = intel_g4x_find_best_PLL,
  315. };
  316. static const intel_limit_t intel_limits_ironlake_dual_lvds_100m = {
  317. .dot = { .min = 25000, .max = 350000 },
  318. .vco = { .min = 1760000, .max = 3510000 },
  319. .n = { .min = 1, .max = 3 },
  320. .m = { .min = 79, .max = 126 },
  321. .m1 = { .min = 12, .max = 22 },
  322. .m2 = { .min = 5, .max = 9 },
  323. .p = { .min = 14, .max = 42 },
  324. .p1 = { .min = 2, .max = 6 },
  325. .p2 = { .dot_limit = 225000,
  326. .p2_slow = 7, .p2_fast = 7 },
  327. .find_pll = intel_g4x_find_best_PLL,
  328. };
  329. static const intel_limit_t intel_limits_ironlake_display_port = {
  330. .dot = { .min = 25000, .max = 350000 },
  331. .vco = { .min = 1760000, .max = 3510000},
  332. .n = { .min = 1, .max = 2 },
  333. .m = { .min = 81, .max = 90 },
  334. .m1 = { .min = 12, .max = 22 },
  335. .m2 = { .min = 5, .max = 9 },
  336. .p = { .min = 10, .max = 20 },
  337. .p1 = { .min = 1, .max = 2},
  338. .p2 = { .dot_limit = 0,
  339. .p2_slow = 10, .p2_fast = 10 },
  340. .find_pll = intel_find_pll_ironlake_dp,
  341. };
  342. static const intel_limit_t intel_limits_vlv_dac = {
  343. .dot = { .min = 25000, .max = 270000 },
  344. .vco = { .min = 4000000, .max = 6000000 },
  345. .n = { .min = 1, .max = 7 },
  346. .m = { .min = 22, .max = 450 }, /* guess */
  347. .m1 = { .min = 2, .max = 3 },
  348. .m2 = { .min = 11, .max = 156 },
  349. .p = { .min = 10, .max = 30 },
  350. .p1 = { .min = 2, .max = 3 },
  351. .p2 = { .dot_limit = 270000,
  352. .p2_slow = 2, .p2_fast = 20 },
  353. .find_pll = intel_vlv_find_best_pll,
  354. };
  355. static const intel_limit_t intel_limits_vlv_hdmi = {
  356. .dot = { .min = 20000, .max = 165000 },
  357. .vco = { .min = 4000000, .max = 5994000},
  358. .n = { .min = 1, .max = 7 },
  359. .m = { .min = 60, .max = 300 }, /* guess */
  360. .m1 = { .min = 2, .max = 3 },
  361. .m2 = { .min = 11, .max = 156 },
  362. .p = { .min = 10, .max = 30 },
  363. .p1 = { .min = 2, .max = 3 },
  364. .p2 = { .dot_limit = 270000,
  365. .p2_slow = 2, .p2_fast = 20 },
  366. .find_pll = intel_vlv_find_best_pll,
  367. };
  368. static const intel_limit_t intel_limits_vlv_dp = {
  369. .dot = { .min = 25000, .max = 270000 },
  370. .vco = { .min = 4000000, .max = 6000000 },
  371. .n = { .min = 1, .max = 7 },
  372. .m = { .min = 22, .max = 450 },
  373. .m1 = { .min = 2, .max = 3 },
  374. .m2 = { .min = 11, .max = 156 },
  375. .p = { .min = 10, .max = 30 },
  376. .p1 = { .min = 2, .max = 3 },
  377. .p2 = { .dot_limit = 270000,
  378. .p2_slow = 2, .p2_fast = 20 },
  379. .find_pll = intel_vlv_find_best_pll,
  380. };
  381. u32 intel_dpio_read(struct drm_i915_private *dev_priv, int reg)
  382. {
  383. WARN_ON(!mutex_is_locked(&dev_priv->dpio_lock));
  384. if (wait_for_atomic_us((I915_READ(DPIO_PKT) & DPIO_BUSY) == 0, 100)) {
  385. DRM_ERROR("DPIO idle wait timed out\n");
  386. return 0;
  387. }
  388. I915_WRITE(DPIO_REG, reg);
  389. I915_WRITE(DPIO_PKT, DPIO_RID | DPIO_OP_READ | DPIO_PORTID |
  390. DPIO_BYTE);
  391. if (wait_for_atomic_us((I915_READ(DPIO_PKT) & DPIO_BUSY) == 0, 100)) {
  392. DRM_ERROR("DPIO read wait timed out\n");
  393. return 0;
  394. }
  395. return I915_READ(DPIO_DATA);
  396. }
  397. static void intel_dpio_write(struct drm_i915_private *dev_priv, int reg,
  398. u32 val)
  399. {
  400. WARN_ON(!mutex_is_locked(&dev_priv->dpio_lock));
  401. if (wait_for_atomic_us((I915_READ(DPIO_PKT) & DPIO_BUSY) == 0, 100)) {
  402. DRM_ERROR("DPIO idle wait timed out\n");
  403. return;
  404. }
  405. I915_WRITE(DPIO_DATA, val);
  406. I915_WRITE(DPIO_REG, reg);
  407. I915_WRITE(DPIO_PKT, DPIO_RID | DPIO_OP_WRITE | DPIO_PORTID |
  408. DPIO_BYTE);
  409. if (wait_for_atomic_us((I915_READ(DPIO_PKT) & DPIO_BUSY) == 0, 100))
  410. DRM_ERROR("DPIO write wait timed out\n");
  411. }
  412. static void vlv_init_dpio(struct drm_device *dev)
  413. {
  414. struct drm_i915_private *dev_priv = dev->dev_private;
  415. /* Reset the DPIO config */
  416. I915_WRITE(DPIO_CTL, 0);
  417. POSTING_READ(DPIO_CTL);
  418. I915_WRITE(DPIO_CTL, 1);
  419. POSTING_READ(DPIO_CTL);
  420. }
  421. static const intel_limit_t *intel_ironlake_limit(struct drm_crtc *crtc,
  422. int refclk)
  423. {
  424. struct drm_device *dev = crtc->dev;
  425. const intel_limit_t *limit;
  426. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  427. if (intel_is_dual_link_lvds(dev)) {
  428. /* LVDS dual channel */
  429. if (refclk == 100000)
  430. limit = &intel_limits_ironlake_dual_lvds_100m;
  431. else
  432. limit = &intel_limits_ironlake_dual_lvds;
  433. } else {
  434. if (refclk == 100000)
  435. limit = &intel_limits_ironlake_single_lvds_100m;
  436. else
  437. limit = &intel_limits_ironlake_single_lvds;
  438. }
  439. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) ||
  440. intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))
  441. limit = &intel_limits_ironlake_display_port;
  442. else
  443. limit = &intel_limits_ironlake_dac;
  444. return limit;
  445. }
  446. static const intel_limit_t *intel_g4x_limit(struct drm_crtc *crtc)
  447. {
  448. struct drm_device *dev = crtc->dev;
  449. const intel_limit_t *limit;
  450. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  451. if (intel_is_dual_link_lvds(dev))
  452. /* LVDS with dual channel */
  453. limit = &intel_limits_g4x_dual_channel_lvds;
  454. else
  455. /* LVDS with dual channel */
  456. limit = &intel_limits_g4x_single_channel_lvds;
  457. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI) ||
  458. intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG)) {
  459. limit = &intel_limits_g4x_hdmi;
  460. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO)) {
  461. limit = &intel_limits_g4x_sdvo;
  462. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
  463. limit = &intel_limits_g4x_display_port;
  464. } else /* The option is for other outputs */
  465. limit = &intel_limits_i9xx_sdvo;
  466. return limit;
  467. }
  468. static const intel_limit_t *intel_limit(struct drm_crtc *crtc, int refclk)
  469. {
  470. struct drm_device *dev = crtc->dev;
  471. const intel_limit_t *limit;
  472. if (HAS_PCH_SPLIT(dev))
  473. limit = intel_ironlake_limit(crtc, refclk);
  474. else if (IS_G4X(dev)) {
  475. limit = intel_g4x_limit(crtc);
  476. } else if (IS_PINEVIEW(dev)) {
  477. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  478. limit = &intel_limits_pineview_lvds;
  479. else
  480. limit = &intel_limits_pineview_sdvo;
  481. } else if (IS_VALLEYVIEW(dev)) {
  482. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG))
  483. limit = &intel_limits_vlv_dac;
  484. else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI))
  485. limit = &intel_limits_vlv_hdmi;
  486. else
  487. limit = &intel_limits_vlv_dp;
  488. } else if (!IS_GEN2(dev)) {
  489. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  490. limit = &intel_limits_i9xx_lvds;
  491. else
  492. limit = &intel_limits_i9xx_sdvo;
  493. } else {
  494. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  495. limit = &intel_limits_i8xx_lvds;
  496. else
  497. limit = &intel_limits_i8xx_dvo;
  498. }
  499. return limit;
  500. }
  501. /* m1 is reserved as 0 in Pineview, n is a ring counter */
  502. static void pineview_clock(int refclk, intel_clock_t *clock)
  503. {
  504. clock->m = clock->m2 + 2;
  505. clock->p = clock->p1 * clock->p2;
  506. clock->vco = refclk * clock->m / clock->n;
  507. clock->dot = clock->vco / clock->p;
  508. }
  509. static void intel_clock(struct drm_device *dev, int refclk, intel_clock_t *clock)
  510. {
  511. if (IS_PINEVIEW(dev)) {
  512. pineview_clock(refclk, clock);
  513. return;
  514. }
  515. clock->m = 5 * (clock->m1 + 2) + (clock->m2 + 2);
  516. clock->p = clock->p1 * clock->p2;
  517. clock->vco = refclk * clock->m / (clock->n + 2);
  518. clock->dot = clock->vco / clock->p;
  519. }
  520. /**
  521. * Returns whether any output on the specified pipe is of the specified type
  522. */
  523. bool intel_pipe_has_type(struct drm_crtc *crtc, int type)
  524. {
  525. struct drm_device *dev = crtc->dev;
  526. struct intel_encoder *encoder;
  527. for_each_encoder_on_crtc(dev, crtc, encoder)
  528. if (encoder->type == type)
  529. return true;
  530. return false;
  531. }
  532. #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
  533. /**
  534. * Returns whether the given set of divisors are valid for a given refclk with
  535. * the given connectors.
  536. */
  537. static bool intel_PLL_is_valid(struct drm_device *dev,
  538. const intel_limit_t *limit,
  539. const intel_clock_t *clock)
  540. {
  541. if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
  542. INTELPllInvalid("p1 out of range\n");
  543. if (clock->p < limit->p.min || limit->p.max < clock->p)
  544. INTELPllInvalid("p out of range\n");
  545. if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
  546. INTELPllInvalid("m2 out of range\n");
  547. if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
  548. INTELPllInvalid("m1 out of range\n");
  549. if (clock->m1 <= clock->m2 && !IS_PINEVIEW(dev))
  550. INTELPllInvalid("m1 <= m2\n");
  551. if (clock->m < limit->m.min || limit->m.max < clock->m)
  552. INTELPllInvalid("m out of range\n");
  553. if (clock->n < limit->n.min || limit->n.max < clock->n)
  554. INTELPllInvalid("n out of range\n");
  555. if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
  556. INTELPllInvalid("vco out of range\n");
  557. /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
  558. * connector, etc., rather than just a single range.
  559. */
  560. if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
  561. INTELPllInvalid("dot out of range\n");
  562. return true;
  563. }
  564. static bool
  565. intel_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
  566. int target, int refclk, intel_clock_t *match_clock,
  567. intel_clock_t *best_clock)
  568. {
  569. struct drm_device *dev = crtc->dev;
  570. intel_clock_t clock;
  571. int err = target;
  572. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  573. /*
  574. * For LVDS just rely on its current settings for dual-channel.
  575. * We haven't figured out how to reliably set up different
  576. * single/dual channel state, if we even can.
  577. */
  578. if (intel_is_dual_link_lvds(dev))
  579. clock.p2 = limit->p2.p2_fast;
  580. else
  581. clock.p2 = limit->p2.p2_slow;
  582. } else {
  583. if (target < limit->p2.dot_limit)
  584. clock.p2 = limit->p2.p2_slow;
  585. else
  586. clock.p2 = limit->p2.p2_fast;
  587. }
  588. memset(best_clock, 0, sizeof(*best_clock));
  589. for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
  590. clock.m1++) {
  591. for (clock.m2 = limit->m2.min;
  592. clock.m2 <= limit->m2.max; clock.m2++) {
  593. /* m1 is always 0 in Pineview */
  594. if (clock.m2 >= clock.m1 && !IS_PINEVIEW(dev))
  595. break;
  596. for (clock.n = limit->n.min;
  597. clock.n <= limit->n.max; clock.n++) {
  598. for (clock.p1 = limit->p1.min;
  599. clock.p1 <= limit->p1.max; clock.p1++) {
  600. int this_err;
  601. intel_clock(dev, refclk, &clock);
  602. if (!intel_PLL_is_valid(dev, limit,
  603. &clock))
  604. continue;
  605. if (match_clock &&
  606. clock.p != match_clock->p)
  607. continue;
  608. this_err = abs(clock.dot - target);
  609. if (this_err < err) {
  610. *best_clock = clock;
  611. err = this_err;
  612. }
  613. }
  614. }
  615. }
  616. }
  617. return (err != target);
  618. }
  619. static bool
  620. intel_g4x_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
  621. int target, int refclk, intel_clock_t *match_clock,
  622. intel_clock_t *best_clock)
  623. {
  624. struct drm_device *dev = crtc->dev;
  625. intel_clock_t clock;
  626. int max_n;
  627. bool found;
  628. /* approximately equals target * 0.00585 */
  629. int err_most = (target >> 8) + (target >> 9);
  630. found = false;
  631. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  632. int lvds_reg;
  633. if (HAS_PCH_SPLIT(dev))
  634. lvds_reg = PCH_LVDS;
  635. else
  636. lvds_reg = LVDS;
  637. if (intel_is_dual_link_lvds(dev))
  638. clock.p2 = limit->p2.p2_fast;
  639. else
  640. clock.p2 = limit->p2.p2_slow;
  641. } else {
  642. if (target < limit->p2.dot_limit)
  643. clock.p2 = limit->p2.p2_slow;
  644. else
  645. clock.p2 = limit->p2.p2_fast;
  646. }
  647. memset(best_clock, 0, sizeof(*best_clock));
  648. max_n = limit->n.max;
  649. /* based on hardware requirement, prefer smaller n to precision */
  650. for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
  651. /* based on hardware requirement, prefere larger m1,m2 */
  652. for (clock.m1 = limit->m1.max;
  653. clock.m1 >= limit->m1.min; clock.m1--) {
  654. for (clock.m2 = limit->m2.max;
  655. clock.m2 >= limit->m2.min; clock.m2--) {
  656. for (clock.p1 = limit->p1.max;
  657. clock.p1 >= limit->p1.min; clock.p1--) {
  658. int this_err;
  659. intel_clock(dev, refclk, &clock);
  660. if (!intel_PLL_is_valid(dev, limit,
  661. &clock))
  662. continue;
  663. if (match_clock &&
  664. clock.p != match_clock->p)
  665. continue;
  666. this_err = abs(clock.dot - target);
  667. if (this_err < err_most) {
  668. *best_clock = clock;
  669. err_most = this_err;
  670. max_n = clock.n;
  671. found = true;
  672. }
  673. }
  674. }
  675. }
  676. }
  677. return found;
  678. }
  679. static bool
  680. intel_find_pll_ironlake_dp(const intel_limit_t *limit, struct drm_crtc *crtc,
  681. int target, int refclk, intel_clock_t *match_clock,
  682. intel_clock_t *best_clock)
  683. {
  684. struct drm_device *dev = crtc->dev;
  685. intel_clock_t clock;
  686. if (target < 200000) {
  687. clock.n = 1;
  688. clock.p1 = 2;
  689. clock.p2 = 10;
  690. clock.m1 = 12;
  691. clock.m2 = 9;
  692. } else {
  693. clock.n = 2;
  694. clock.p1 = 1;
  695. clock.p2 = 10;
  696. clock.m1 = 14;
  697. clock.m2 = 8;
  698. }
  699. intel_clock(dev, refclk, &clock);
  700. memcpy(best_clock, &clock, sizeof(intel_clock_t));
  701. return true;
  702. }
  703. /* DisplayPort has only two frequencies, 162MHz and 270MHz */
  704. static bool
  705. intel_find_pll_g4x_dp(const intel_limit_t *limit, struct drm_crtc *crtc,
  706. int target, int refclk, intel_clock_t *match_clock,
  707. intel_clock_t *best_clock)
  708. {
  709. intel_clock_t clock;
  710. if (target < 200000) {
  711. clock.p1 = 2;
  712. clock.p2 = 10;
  713. clock.n = 2;
  714. clock.m1 = 23;
  715. clock.m2 = 8;
  716. } else {
  717. clock.p1 = 1;
  718. clock.p2 = 10;
  719. clock.n = 1;
  720. clock.m1 = 14;
  721. clock.m2 = 2;
  722. }
  723. clock.m = 5 * (clock.m1 + 2) + (clock.m2 + 2);
  724. clock.p = (clock.p1 * clock.p2);
  725. clock.dot = 96000 * clock.m / (clock.n + 2) / clock.p;
  726. clock.vco = 0;
  727. memcpy(best_clock, &clock, sizeof(intel_clock_t));
  728. return true;
  729. }
  730. static bool
  731. intel_vlv_find_best_pll(const intel_limit_t *limit, struct drm_crtc *crtc,
  732. int target, int refclk, intel_clock_t *match_clock,
  733. intel_clock_t *best_clock)
  734. {
  735. u32 p1, p2, m1, m2, vco, bestn, bestm1, bestm2, bestp1, bestp2;
  736. u32 m, n, fastclk;
  737. u32 updrate, minupdate, fracbits, p;
  738. unsigned long bestppm, ppm, absppm;
  739. int dotclk, flag;
  740. flag = 0;
  741. dotclk = target * 1000;
  742. bestppm = 1000000;
  743. ppm = absppm = 0;
  744. fastclk = dotclk / (2*100);
  745. updrate = 0;
  746. minupdate = 19200;
  747. fracbits = 1;
  748. n = p = p1 = p2 = m = m1 = m2 = vco = bestn = 0;
  749. bestm1 = bestm2 = bestp1 = bestp2 = 0;
  750. /* based on hardware requirement, prefer smaller n to precision */
  751. for (n = limit->n.min; n <= ((refclk) / minupdate); n++) {
  752. updrate = refclk / n;
  753. for (p1 = limit->p1.max; p1 > limit->p1.min; p1--) {
  754. for (p2 = limit->p2.p2_fast+1; p2 > 0; p2--) {
  755. if (p2 > 10)
  756. p2 = p2 - 1;
  757. p = p1 * p2;
  758. /* based on hardware requirement, prefer bigger m1,m2 values */
  759. for (m1 = limit->m1.min; m1 <= limit->m1.max; m1++) {
  760. m2 = (((2*(fastclk * p * n / m1 )) +
  761. refclk) / (2*refclk));
  762. m = m1 * m2;
  763. vco = updrate * m;
  764. if (vco >= limit->vco.min && vco < limit->vco.max) {
  765. ppm = 1000000 * ((vco / p) - fastclk) / fastclk;
  766. absppm = (ppm > 0) ? ppm : (-ppm);
  767. if (absppm < 100 && ((p1 * p2) > (bestp1 * bestp2))) {
  768. bestppm = 0;
  769. flag = 1;
  770. }
  771. if (absppm < bestppm - 10) {
  772. bestppm = absppm;
  773. flag = 1;
  774. }
  775. if (flag) {
  776. bestn = n;
  777. bestm1 = m1;
  778. bestm2 = m2;
  779. bestp1 = p1;
  780. bestp2 = p2;
  781. flag = 0;
  782. }
  783. }
  784. }
  785. }
  786. }
  787. }
  788. best_clock->n = bestn;
  789. best_clock->m1 = bestm1;
  790. best_clock->m2 = bestm2;
  791. best_clock->p1 = bestp1;
  792. best_clock->p2 = bestp2;
  793. return true;
  794. }
  795. enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv,
  796. enum pipe pipe)
  797. {
  798. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  799. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  800. return intel_crtc->cpu_transcoder;
  801. }
  802. static void ironlake_wait_for_vblank(struct drm_device *dev, int pipe)
  803. {
  804. struct drm_i915_private *dev_priv = dev->dev_private;
  805. u32 frame, frame_reg = PIPEFRAME(pipe);
  806. frame = I915_READ(frame_reg);
  807. if (wait_for(I915_READ_NOTRACE(frame_reg) != frame, 50))
  808. DRM_DEBUG_KMS("vblank wait timed out\n");
  809. }
  810. /**
  811. * intel_wait_for_vblank - wait for vblank on a given pipe
  812. * @dev: drm device
  813. * @pipe: pipe to wait for
  814. *
  815. * Wait for vblank to occur on a given pipe. Needed for various bits of
  816. * mode setting code.
  817. */
  818. void intel_wait_for_vblank(struct drm_device *dev, int pipe)
  819. {
  820. struct drm_i915_private *dev_priv = dev->dev_private;
  821. int pipestat_reg = PIPESTAT(pipe);
  822. if (INTEL_INFO(dev)->gen >= 5) {
  823. ironlake_wait_for_vblank(dev, pipe);
  824. return;
  825. }
  826. /* Clear existing vblank status. Note this will clear any other
  827. * sticky status fields as well.
  828. *
  829. * This races with i915_driver_irq_handler() with the result
  830. * that either function could miss a vblank event. Here it is not
  831. * fatal, as we will either wait upon the next vblank interrupt or
  832. * timeout. Generally speaking intel_wait_for_vblank() is only
  833. * called during modeset at which time the GPU should be idle and
  834. * should *not* be performing page flips and thus not waiting on
  835. * vblanks...
  836. * Currently, the result of us stealing a vblank from the irq
  837. * handler is that a single frame will be skipped during swapbuffers.
  838. */
  839. I915_WRITE(pipestat_reg,
  840. I915_READ(pipestat_reg) | PIPE_VBLANK_INTERRUPT_STATUS);
  841. /* Wait for vblank interrupt bit to set */
  842. if (wait_for(I915_READ(pipestat_reg) &
  843. PIPE_VBLANK_INTERRUPT_STATUS,
  844. 50))
  845. DRM_DEBUG_KMS("vblank wait timed out\n");
  846. }
  847. /*
  848. * intel_wait_for_pipe_off - wait for pipe to turn off
  849. * @dev: drm device
  850. * @pipe: pipe to wait for
  851. *
  852. * After disabling a pipe, we can't wait for vblank in the usual way,
  853. * spinning on the vblank interrupt status bit, since we won't actually
  854. * see an interrupt when the pipe is disabled.
  855. *
  856. * On Gen4 and above:
  857. * wait for the pipe register state bit to turn off
  858. *
  859. * Otherwise:
  860. * wait for the display line value to settle (it usually
  861. * ends up stopping at the start of the next frame).
  862. *
  863. */
  864. void intel_wait_for_pipe_off(struct drm_device *dev, int pipe)
  865. {
  866. struct drm_i915_private *dev_priv = dev->dev_private;
  867. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  868. pipe);
  869. if (INTEL_INFO(dev)->gen >= 4) {
  870. int reg = PIPECONF(cpu_transcoder);
  871. /* Wait for the Pipe State to go off */
  872. if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0,
  873. 100))
  874. WARN(1, "pipe_off wait timed out\n");
  875. } else {
  876. u32 last_line, line_mask;
  877. int reg = PIPEDSL(pipe);
  878. unsigned long timeout = jiffies + msecs_to_jiffies(100);
  879. if (IS_GEN2(dev))
  880. line_mask = DSL_LINEMASK_GEN2;
  881. else
  882. line_mask = DSL_LINEMASK_GEN3;
  883. /* Wait for the display line to settle */
  884. do {
  885. last_line = I915_READ(reg) & line_mask;
  886. mdelay(5);
  887. } while (((I915_READ(reg) & line_mask) != last_line) &&
  888. time_after(timeout, jiffies));
  889. if (time_after(jiffies, timeout))
  890. WARN(1, "pipe_off wait timed out\n");
  891. }
  892. }
  893. /*
  894. * ibx_digital_port_connected - is the specified port connected?
  895. * @dev_priv: i915 private structure
  896. * @port: the port to test
  897. *
  898. * Returns true if @port is connected, false otherwise.
  899. */
  900. bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
  901. struct intel_digital_port *port)
  902. {
  903. u32 bit;
  904. if (HAS_PCH_IBX(dev_priv->dev)) {
  905. switch(port->port) {
  906. case PORT_B:
  907. bit = SDE_PORTB_HOTPLUG;
  908. break;
  909. case PORT_C:
  910. bit = SDE_PORTC_HOTPLUG;
  911. break;
  912. case PORT_D:
  913. bit = SDE_PORTD_HOTPLUG;
  914. break;
  915. default:
  916. return true;
  917. }
  918. } else {
  919. switch(port->port) {
  920. case PORT_B:
  921. bit = SDE_PORTB_HOTPLUG_CPT;
  922. break;
  923. case PORT_C:
  924. bit = SDE_PORTC_HOTPLUG_CPT;
  925. break;
  926. case PORT_D:
  927. bit = SDE_PORTD_HOTPLUG_CPT;
  928. break;
  929. default:
  930. return true;
  931. }
  932. }
  933. return I915_READ(SDEISR) & bit;
  934. }
  935. static const char *state_string(bool enabled)
  936. {
  937. return enabled ? "on" : "off";
  938. }
  939. /* Only for pre-ILK configs */
  940. static void assert_pll(struct drm_i915_private *dev_priv,
  941. enum pipe pipe, bool state)
  942. {
  943. int reg;
  944. u32 val;
  945. bool cur_state;
  946. reg = DPLL(pipe);
  947. val = I915_READ(reg);
  948. cur_state = !!(val & DPLL_VCO_ENABLE);
  949. WARN(cur_state != state,
  950. "PLL state assertion failure (expected %s, current %s)\n",
  951. state_string(state), state_string(cur_state));
  952. }
  953. #define assert_pll_enabled(d, p) assert_pll(d, p, true)
  954. #define assert_pll_disabled(d, p) assert_pll(d, p, false)
  955. /* For ILK+ */
  956. static void assert_pch_pll(struct drm_i915_private *dev_priv,
  957. struct intel_pch_pll *pll,
  958. struct intel_crtc *crtc,
  959. bool state)
  960. {
  961. u32 val;
  962. bool cur_state;
  963. if (HAS_PCH_LPT(dev_priv->dev)) {
  964. DRM_DEBUG_DRIVER("LPT detected: skipping PCH PLL test\n");
  965. return;
  966. }
  967. if (WARN (!pll,
  968. "asserting PCH PLL %s with no PLL\n", state_string(state)))
  969. return;
  970. val = I915_READ(pll->pll_reg);
  971. cur_state = !!(val & DPLL_VCO_ENABLE);
  972. WARN(cur_state != state,
  973. "PCH PLL state for reg %x assertion failure (expected %s, current %s), val=%08x\n",
  974. pll->pll_reg, state_string(state), state_string(cur_state), val);
  975. /* Make sure the selected PLL is correctly attached to the transcoder */
  976. if (crtc && HAS_PCH_CPT(dev_priv->dev)) {
  977. u32 pch_dpll;
  978. pch_dpll = I915_READ(PCH_DPLL_SEL);
  979. cur_state = pll->pll_reg == _PCH_DPLL_B;
  980. if (!WARN(((pch_dpll >> (4 * crtc->pipe)) & 1) != cur_state,
  981. "PLL[%d] not attached to this transcoder %d: %08x\n",
  982. cur_state, crtc->pipe, pch_dpll)) {
  983. cur_state = !!(val >> (4*crtc->pipe + 3));
  984. WARN(cur_state != state,
  985. "PLL[%d] not %s on this transcoder %d: %08x\n",
  986. pll->pll_reg == _PCH_DPLL_B,
  987. state_string(state),
  988. crtc->pipe,
  989. val);
  990. }
  991. }
  992. }
  993. #define assert_pch_pll_enabled(d, p, c) assert_pch_pll(d, p, c, true)
  994. #define assert_pch_pll_disabled(d, p, c) assert_pch_pll(d, p, c, false)
  995. static void assert_fdi_tx(struct drm_i915_private *dev_priv,
  996. enum pipe pipe, bool state)
  997. {
  998. int reg;
  999. u32 val;
  1000. bool cur_state;
  1001. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  1002. pipe);
  1003. if (HAS_DDI(dev_priv->dev)) {
  1004. /* DDI does not have a specific FDI_TX register */
  1005. reg = TRANS_DDI_FUNC_CTL(cpu_transcoder);
  1006. val = I915_READ(reg);
  1007. cur_state = !!(val & TRANS_DDI_FUNC_ENABLE);
  1008. } else {
  1009. reg = FDI_TX_CTL(pipe);
  1010. val = I915_READ(reg);
  1011. cur_state = !!(val & FDI_TX_ENABLE);
  1012. }
  1013. WARN(cur_state != state,
  1014. "FDI TX state assertion failure (expected %s, current %s)\n",
  1015. state_string(state), state_string(cur_state));
  1016. }
  1017. #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
  1018. #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
  1019. static void assert_fdi_rx(struct drm_i915_private *dev_priv,
  1020. enum pipe pipe, bool state)
  1021. {
  1022. int reg;
  1023. u32 val;
  1024. bool cur_state;
  1025. reg = FDI_RX_CTL(pipe);
  1026. val = I915_READ(reg);
  1027. cur_state = !!(val & FDI_RX_ENABLE);
  1028. WARN(cur_state != state,
  1029. "FDI RX state assertion failure (expected %s, current %s)\n",
  1030. state_string(state), state_string(cur_state));
  1031. }
  1032. #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
  1033. #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
  1034. static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv,
  1035. enum pipe pipe)
  1036. {
  1037. int reg;
  1038. u32 val;
  1039. /* ILK FDI PLL is always enabled */
  1040. if (dev_priv->info->gen == 5)
  1041. return;
  1042. /* On Haswell, DDI ports are responsible for the FDI PLL setup */
  1043. if (HAS_DDI(dev_priv->dev))
  1044. return;
  1045. reg = FDI_TX_CTL(pipe);
  1046. val = I915_READ(reg);
  1047. WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n");
  1048. }
  1049. static void assert_fdi_rx_pll_enabled(struct drm_i915_private *dev_priv,
  1050. enum pipe pipe)
  1051. {
  1052. int reg;
  1053. u32 val;
  1054. reg = FDI_RX_CTL(pipe);
  1055. val = I915_READ(reg);
  1056. WARN(!(val & FDI_RX_PLL_ENABLE), "FDI RX PLL assertion failure, should be active but is disabled\n");
  1057. }
  1058. static void assert_panel_unlocked(struct drm_i915_private *dev_priv,
  1059. enum pipe pipe)
  1060. {
  1061. int pp_reg, lvds_reg;
  1062. u32 val;
  1063. enum pipe panel_pipe = PIPE_A;
  1064. bool locked = true;
  1065. if (HAS_PCH_SPLIT(dev_priv->dev)) {
  1066. pp_reg = PCH_PP_CONTROL;
  1067. lvds_reg = PCH_LVDS;
  1068. } else {
  1069. pp_reg = PP_CONTROL;
  1070. lvds_reg = LVDS;
  1071. }
  1072. val = I915_READ(pp_reg);
  1073. if (!(val & PANEL_POWER_ON) ||
  1074. ((val & PANEL_UNLOCK_REGS) == PANEL_UNLOCK_REGS))
  1075. locked = false;
  1076. if (I915_READ(lvds_reg) & LVDS_PIPEB_SELECT)
  1077. panel_pipe = PIPE_B;
  1078. WARN(panel_pipe == pipe && locked,
  1079. "panel assertion failure, pipe %c regs locked\n",
  1080. pipe_name(pipe));
  1081. }
  1082. void assert_pipe(struct drm_i915_private *dev_priv,
  1083. enum pipe pipe, bool state)
  1084. {
  1085. int reg;
  1086. u32 val;
  1087. bool cur_state;
  1088. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  1089. pipe);
  1090. /* if we need the pipe A quirk it must be always on */
  1091. if (pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE)
  1092. state = true;
  1093. reg = PIPECONF(cpu_transcoder);
  1094. val = I915_READ(reg);
  1095. cur_state = !!(val & PIPECONF_ENABLE);
  1096. WARN(cur_state != state,
  1097. "pipe %c assertion failure (expected %s, current %s)\n",
  1098. pipe_name(pipe), state_string(state), state_string(cur_state));
  1099. }
  1100. static void assert_plane(struct drm_i915_private *dev_priv,
  1101. enum plane plane, bool state)
  1102. {
  1103. int reg;
  1104. u32 val;
  1105. bool cur_state;
  1106. reg = DSPCNTR(plane);
  1107. val = I915_READ(reg);
  1108. cur_state = !!(val & DISPLAY_PLANE_ENABLE);
  1109. WARN(cur_state != state,
  1110. "plane %c assertion failure (expected %s, current %s)\n",
  1111. plane_name(plane), state_string(state), state_string(cur_state));
  1112. }
  1113. #define assert_plane_enabled(d, p) assert_plane(d, p, true)
  1114. #define assert_plane_disabled(d, p) assert_plane(d, p, false)
  1115. static void assert_planes_disabled(struct drm_i915_private *dev_priv,
  1116. enum pipe pipe)
  1117. {
  1118. int reg, i;
  1119. u32 val;
  1120. int cur_pipe;
  1121. /* Planes are fixed to pipes on ILK+ */
  1122. if (HAS_PCH_SPLIT(dev_priv->dev)) {
  1123. reg = DSPCNTR(pipe);
  1124. val = I915_READ(reg);
  1125. WARN((val & DISPLAY_PLANE_ENABLE),
  1126. "plane %c assertion failure, should be disabled but not\n",
  1127. plane_name(pipe));
  1128. return;
  1129. }
  1130. /* Need to check both planes against the pipe */
  1131. for (i = 0; i < 2; i++) {
  1132. reg = DSPCNTR(i);
  1133. val = I915_READ(reg);
  1134. cur_pipe = (val & DISPPLANE_SEL_PIPE_MASK) >>
  1135. DISPPLANE_SEL_PIPE_SHIFT;
  1136. WARN((val & DISPLAY_PLANE_ENABLE) && pipe == cur_pipe,
  1137. "plane %c assertion failure, should be off on pipe %c but is still active\n",
  1138. plane_name(i), pipe_name(pipe));
  1139. }
  1140. }
  1141. static void assert_pch_refclk_enabled(struct drm_i915_private *dev_priv)
  1142. {
  1143. u32 val;
  1144. bool enabled;
  1145. if (HAS_PCH_LPT(dev_priv->dev)) {
  1146. DRM_DEBUG_DRIVER("LPT does not has PCH refclk, skipping check\n");
  1147. return;
  1148. }
  1149. val = I915_READ(PCH_DREF_CONTROL);
  1150. enabled = !!(val & (DREF_SSC_SOURCE_MASK | DREF_NONSPREAD_SOURCE_MASK |
  1151. DREF_SUPERSPREAD_SOURCE_MASK));
  1152. WARN(!enabled, "PCH refclk assertion failure, should be active but is disabled\n");
  1153. }
  1154. static void assert_transcoder_disabled(struct drm_i915_private *dev_priv,
  1155. enum pipe pipe)
  1156. {
  1157. int reg;
  1158. u32 val;
  1159. bool enabled;
  1160. reg = TRANSCONF(pipe);
  1161. val = I915_READ(reg);
  1162. enabled = !!(val & TRANS_ENABLE);
  1163. WARN(enabled,
  1164. "transcoder assertion failed, should be off on pipe %c but is still active\n",
  1165. pipe_name(pipe));
  1166. }
  1167. static bool dp_pipe_enabled(struct drm_i915_private *dev_priv,
  1168. enum pipe pipe, u32 port_sel, u32 val)
  1169. {
  1170. if ((val & DP_PORT_EN) == 0)
  1171. return false;
  1172. if (HAS_PCH_CPT(dev_priv->dev)) {
  1173. u32 trans_dp_ctl_reg = TRANS_DP_CTL(pipe);
  1174. u32 trans_dp_ctl = I915_READ(trans_dp_ctl_reg);
  1175. if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel)
  1176. return false;
  1177. } else {
  1178. if ((val & DP_PIPE_MASK) != (pipe << 30))
  1179. return false;
  1180. }
  1181. return true;
  1182. }
  1183. static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv,
  1184. enum pipe pipe, u32 val)
  1185. {
  1186. if ((val & PORT_ENABLE) == 0)
  1187. return false;
  1188. if (HAS_PCH_CPT(dev_priv->dev)) {
  1189. if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
  1190. return false;
  1191. } else {
  1192. if ((val & TRANSCODER_MASK) != TRANSCODER(pipe))
  1193. return false;
  1194. }
  1195. return true;
  1196. }
  1197. static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv,
  1198. enum pipe pipe, u32 val)
  1199. {
  1200. if ((val & LVDS_PORT_EN) == 0)
  1201. return false;
  1202. if (HAS_PCH_CPT(dev_priv->dev)) {
  1203. if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
  1204. return false;
  1205. } else {
  1206. if ((val & LVDS_PIPE_MASK) != LVDS_PIPE(pipe))
  1207. return false;
  1208. }
  1209. return true;
  1210. }
  1211. static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv,
  1212. enum pipe pipe, u32 val)
  1213. {
  1214. if ((val & ADPA_DAC_ENABLE) == 0)
  1215. return false;
  1216. if (HAS_PCH_CPT(dev_priv->dev)) {
  1217. if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
  1218. return false;
  1219. } else {
  1220. if ((val & ADPA_PIPE_SELECT_MASK) != ADPA_PIPE_SELECT(pipe))
  1221. return false;
  1222. }
  1223. return true;
  1224. }
  1225. static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
  1226. enum pipe pipe, int reg, u32 port_sel)
  1227. {
  1228. u32 val = I915_READ(reg);
  1229. WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val),
  1230. "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
  1231. reg, pipe_name(pipe));
  1232. WARN(HAS_PCH_IBX(dev_priv->dev) && (val & DP_PORT_EN) == 0
  1233. && (val & DP_PIPEB_SELECT),
  1234. "IBX PCH dp port still using transcoder B\n");
  1235. }
  1236. static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
  1237. enum pipe pipe, int reg)
  1238. {
  1239. u32 val = I915_READ(reg);
  1240. WARN(hdmi_pipe_enabled(dev_priv, pipe, val),
  1241. "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n",
  1242. reg, pipe_name(pipe));
  1243. WARN(HAS_PCH_IBX(dev_priv->dev) && (val & PORT_ENABLE) == 0
  1244. && (val & SDVO_PIPE_B_SELECT),
  1245. "IBX PCH hdmi port still using transcoder B\n");
  1246. }
  1247. static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
  1248. enum pipe pipe)
  1249. {
  1250. int reg;
  1251. u32 val;
  1252. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B);
  1253. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C);
  1254. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_D, TRANS_DP_PORT_SEL_D);
  1255. reg = PCH_ADPA;
  1256. val = I915_READ(reg);
  1257. WARN(adpa_pipe_enabled(dev_priv, pipe, val),
  1258. "PCH VGA enabled on transcoder %c, should be disabled\n",
  1259. pipe_name(pipe));
  1260. reg = PCH_LVDS;
  1261. val = I915_READ(reg);
  1262. WARN(lvds_pipe_enabled(dev_priv, pipe, val),
  1263. "PCH LVDS enabled on transcoder %c, should be disabled\n",
  1264. pipe_name(pipe));
  1265. assert_pch_hdmi_disabled(dev_priv, pipe, HDMIB);
  1266. assert_pch_hdmi_disabled(dev_priv, pipe, HDMIC);
  1267. assert_pch_hdmi_disabled(dev_priv, pipe, HDMID);
  1268. }
  1269. /**
  1270. * intel_enable_pll - enable a PLL
  1271. * @dev_priv: i915 private structure
  1272. * @pipe: pipe PLL to enable
  1273. *
  1274. * Enable @pipe's PLL so we can start pumping pixels from a plane. Check to
  1275. * make sure the PLL reg is writable first though, since the panel write
  1276. * protect mechanism may be enabled.
  1277. *
  1278. * Note! This is for pre-ILK only.
  1279. *
  1280. * Unfortunately needed by dvo_ns2501 since the dvo depends on it running.
  1281. */
  1282. static void intel_enable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
  1283. {
  1284. int reg;
  1285. u32 val;
  1286. /* No really, not for ILK+ */
  1287. BUG_ON(!IS_VALLEYVIEW(dev_priv->dev) && dev_priv->info->gen >= 5);
  1288. /* PLL is protected by panel, make sure we can write it */
  1289. if (IS_MOBILE(dev_priv->dev) && !IS_I830(dev_priv->dev))
  1290. assert_panel_unlocked(dev_priv, pipe);
  1291. reg = DPLL(pipe);
  1292. val = I915_READ(reg);
  1293. val |= DPLL_VCO_ENABLE;
  1294. /* We do this three times for luck */
  1295. I915_WRITE(reg, val);
  1296. POSTING_READ(reg);
  1297. udelay(150); /* wait for warmup */
  1298. I915_WRITE(reg, val);
  1299. POSTING_READ(reg);
  1300. udelay(150); /* wait for warmup */
  1301. I915_WRITE(reg, val);
  1302. POSTING_READ(reg);
  1303. udelay(150); /* wait for warmup */
  1304. }
  1305. /**
  1306. * intel_disable_pll - disable a PLL
  1307. * @dev_priv: i915 private structure
  1308. * @pipe: pipe PLL to disable
  1309. *
  1310. * Disable the PLL for @pipe, making sure the pipe is off first.
  1311. *
  1312. * Note! This is for pre-ILK only.
  1313. */
  1314. static void intel_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
  1315. {
  1316. int reg;
  1317. u32 val;
  1318. /* Don't disable pipe A or pipe A PLLs if needed */
  1319. if (pipe == PIPE_A && (dev_priv->quirks & QUIRK_PIPEA_FORCE))
  1320. return;
  1321. /* Make sure the pipe isn't still relying on us */
  1322. assert_pipe_disabled(dev_priv, pipe);
  1323. reg = DPLL(pipe);
  1324. val = I915_READ(reg);
  1325. val &= ~DPLL_VCO_ENABLE;
  1326. I915_WRITE(reg, val);
  1327. POSTING_READ(reg);
  1328. }
  1329. /* SBI access */
  1330. static void
  1331. intel_sbi_write(struct drm_i915_private *dev_priv, u16 reg, u32 value,
  1332. enum intel_sbi_destination destination)
  1333. {
  1334. u32 tmp;
  1335. WARN_ON(!mutex_is_locked(&dev_priv->dpio_lock));
  1336. if (wait_for((I915_READ(SBI_CTL_STAT) & SBI_BUSY) == 0,
  1337. 100)) {
  1338. DRM_ERROR("timeout waiting for SBI to become ready\n");
  1339. return;
  1340. }
  1341. I915_WRITE(SBI_ADDR, (reg << 16));
  1342. I915_WRITE(SBI_DATA, value);
  1343. if (destination == SBI_ICLK)
  1344. tmp = SBI_CTL_DEST_ICLK | SBI_CTL_OP_CRWR;
  1345. else
  1346. tmp = SBI_CTL_DEST_MPHY | SBI_CTL_OP_IOWR;
  1347. I915_WRITE(SBI_CTL_STAT, SBI_BUSY | tmp);
  1348. if (wait_for((I915_READ(SBI_CTL_STAT) & (SBI_BUSY | SBI_RESPONSE_FAIL)) == 0,
  1349. 100)) {
  1350. DRM_ERROR("timeout waiting for SBI to complete write transaction\n");
  1351. return;
  1352. }
  1353. }
  1354. static u32
  1355. intel_sbi_read(struct drm_i915_private *dev_priv, u16 reg,
  1356. enum intel_sbi_destination destination)
  1357. {
  1358. u32 value = 0;
  1359. WARN_ON(!mutex_is_locked(&dev_priv->dpio_lock));
  1360. if (wait_for((I915_READ(SBI_CTL_STAT) & SBI_BUSY) == 0,
  1361. 100)) {
  1362. DRM_ERROR("timeout waiting for SBI to become ready\n");
  1363. return 0;
  1364. }
  1365. I915_WRITE(SBI_ADDR, (reg << 16));
  1366. if (destination == SBI_ICLK)
  1367. value = SBI_CTL_DEST_ICLK | SBI_CTL_OP_CRRD;
  1368. else
  1369. value = SBI_CTL_DEST_MPHY | SBI_CTL_OP_IORD;
  1370. I915_WRITE(SBI_CTL_STAT, value | SBI_BUSY);
  1371. if (wait_for((I915_READ(SBI_CTL_STAT) & (SBI_BUSY | SBI_RESPONSE_FAIL)) == 0,
  1372. 100)) {
  1373. DRM_ERROR("timeout waiting for SBI to complete read transaction\n");
  1374. return 0;
  1375. }
  1376. return I915_READ(SBI_DATA);
  1377. }
  1378. /**
  1379. * ironlake_enable_pch_pll - enable PCH PLL
  1380. * @dev_priv: i915 private structure
  1381. * @pipe: pipe PLL to enable
  1382. *
  1383. * The PCH PLL needs to be enabled before the PCH transcoder, since it
  1384. * drives the transcoder clock.
  1385. */
  1386. static void ironlake_enable_pch_pll(struct intel_crtc *intel_crtc)
  1387. {
  1388. struct drm_i915_private *dev_priv = intel_crtc->base.dev->dev_private;
  1389. struct intel_pch_pll *pll;
  1390. int reg;
  1391. u32 val;
  1392. /* PCH PLLs only available on ILK, SNB and IVB */
  1393. BUG_ON(dev_priv->info->gen < 5);
  1394. pll = intel_crtc->pch_pll;
  1395. if (pll == NULL)
  1396. return;
  1397. if (WARN_ON(pll->refcount == 0))
  1398. return;
  1399. DRM_DEBUG_KMS("enable PCH PLL %x (active %d, on? %d)for crtc %d\n",
  1400. pll->pll_reg, pll->active, pll->on,
  1401. intel_crtc->base.base.id);
  1402. /* PCH refclock must be enabled first */
  1403. assert_pch_refclk_enabled(dev_priv);
  1404. if (pll->active++ && pll->on) {
  1405. assert_pch_pll_enabled(dev_priv, pll, NULL);
  1406. return;
  1407. }
  1408. DRM_DEBUG_KMS("enabling PCH PLL %x\n", pll->pll_reg);
  1409. reg = pll->pll_reg;
  1410. val = I915_READ(reg);
  1411. val |= DPLL_VCO_ENABLE;
  1412. I915_WRITE(reg, val);
  1413. POSTING_READ(reg);
  1414. udelay(200);
  1415. pll->on = true;
  1416. }
  1417. static void intel_disable_pch_pll(struct intel_crtc *intel_crtc)
  1418. {
  1419. struct drm_i915_private *dev_priv = intel_crtc->base.dev->dev_private;
  1420. struct intel_pch_pll *pll = intel_crtc->pch_pll;
  1421. int reg;
  1422. u32 val;
  1423. /* PCH only available on ILK+ */
  1424. BUG_ON(dev_priv->info->gen < 5);
  1425. if (pll == NULL)
  1426. return;
  1427. if (WARN_ON(pll->refcount == 0))
  1428. return;
  1429. DRM_DEBUG_KMS("disable PCH PLL %x (active %d, on? %d) for crtc %d\n",
  1430. pll->pll_reg, pll->active, pll->on,
  1431. intel_crtc->base.base.id);
  1432. if (WARN_ON(pll->active == 0)) {
  1433. assert_pch_pll_disabled(dev_priv, pll, NULL);
  1434. return;
  1435. }
  1436. if (--pll->active) {
  1437. assert_pch_pll_enabled(dev_priv, pll, NULL);
  1438. return;
  1439. }
  1440. DRM_DEBUG_KMS("disabling PCH PLL %x\n", pll->pll_reg);
  1441. /* Make sure transcoder isn't still depending on us */
  1442. assert_transcoder_disabled(dev_priv, intel_crtc->pipe);
  1443. reg = pll->pll_reg;
  1444. val = I915_READ(reg);
  1445. val &= ~DPLL_VCO_ENABLE;
  1446. I915_WRITE(reg, val);
  1447. POSTING_READ(reg);
  1448. udelay(200);
  1449. pll->on = false;
  1450. }
  1451. static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv,
  1452. enum pipe pipe)
  1453. {
  1454. struct drm_device *dev = dev_priv->dev;
  1455. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  1456. uint32_t reg, val, pipeconf_val;
  1457. /* PCH only available on ILK+ */
  1458. BUG_ON(dev_priv->info->gen < 5);
  1459. /* Make sure PCH DPLL is enabled */
  1460. assert_pch_pll_enabled(dev_priv,
  1461. to_intel_crtc(crtc)->pch_pll,
  1462. to_intel_crtc(crtc));
  1463. /* FDI must be feeding us bits for PCH ports */
  1464. assert_fdi_tx_enabled(dev_priv, pipe);
  1465. assert_fdi_rx_enabled(dev_priv, pipe);
  1466. if (HAS_PCH_CPT(dev)) {
  1467. /* Workaround: Set the timing override bit before enabling the
  1468. * pch transcoder. */
  1469. reg = TRANS_CHICKEN2(pipe);
  1470. val = I915_READ(reg);
  1471. val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
  1472. I915_WRITE(reg, val);
  1473. }
  1474. reg = TRANSCONF(pipe);
  1475. val = I915_READ(reg);
  1476. pipeconf_val = I915_READ(PIPECONF(pipe));
  1477. if (HAS_PCH_IBX(dev_priv->dev)) {
  1478. /*
  1479. * make the BPC in transcoder be consistent with
  1480. * that in pipeconf reg.
  1481. */
  1482. val &= ~PIPECONF_BPC_MASK;
  1483. val |= pipeconf_val & PIPECONF_BPC_MASK;
  1484. }
  1485. val &= ~TRANS_INTERLACE_MASK;
  1486. if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK)
  1487. if (HAS_PCH_IBX(dev_priv->dev) &&
  1488. intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO))
  1489. val |= TRANS_LEGACY_INTERLACED_ILK;
  1490. else
  1491. val |= TRANS_INTERLACED;
  1492. else
  1493. val |= TRANS_PROGRESSIVE;
  1494. I915_WRITE(reg, val | TRANS_ENABLE);
  1495. if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100))
  1496. DRM_ERROR("failed to enable transcoder %d\n", pipe);
  1497. }
  1498. static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
  1499. enum transcoder cpu_transcoder)
  1500. {
  1501. u32 val, pipeconf_val;
  1502. /* PCH only available on ILK+ */
  1503. BUG_ON(dev_priv->info->gen < 5);
  1504. /* FDI must be feeding us bits for PCH ports */
  1505. assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder);
  1506. assert_fdi_rx_enabled(dev_priv, TRANSCODER_A);
  1507. /* Workaround: set timing override bit. */
  1508. val = I915_READ(_TRANSA_CHICKEN2);
  1509. val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
  1510. I915_WRITE(_TRANSA_CHICKEN2, val);
  1511. val = TRANS_ENABLE;
  1512. pipeconf_val = I915_READ(PIPECONF(cpu_transcoder));
  1513. if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) ==
  1514. PIPECONF_INTERLACED_ILK)
  1515. val |= TRANS_INTERLACED;
  1516. else
  1517. val |= TRANS_PROGRESSIVE;
  1518. I915_WRITE(TRANSCONF(TRANSCODER_A), val);
  1519. if (wait_for(I915_READ(_TRANSACONF) & TRANS_STATE_ENABLE, 100))
  1520. DRM_ERROR("Failed to enable PCH transcoder\n");
  1521. }
  1522. static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv,
  1523. enum pipe pipe)
  1524. {
  1525. struct drm_device *dev = dev_priv->dev;
  1526. uint32_t reg, val;
  1527. /* FDI relies on the transcoder */
  1528. assert_fdi_tx_disabled(dev_priv, pipe);
  1529. assert_fdi_rx_disabled(dev_priv, pipe);
  1530. /* Ports must be off as well */
  1531. assert_pch_ports_disabled(dev_priv, pipe);
  1532. reg = TRANSCONF(pipe);
  1533. val = I915_READ(reg);
  1534. val &= ~TRANS_ENABLE;
  1535. I915_WRITE(reg, val);
  1536. /* wait for PCH transcoder off, transcoder state */
  1537. if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50))
  1538. DRM_ERROR("failed to disable transcoder %d\n", pipe);
  1539. if (!HAS_PCH_IBX(dev)) {
  1540. /* Workaround: Clear the timing override chicken bit again. */
  1541. reg = TRANS_CHICKEN2(pipe);
  1542. val = I915_READ(reg);
  1543. val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
  1544. I915_WRITE(reg, val);
  1545. }
  1546. }
  1547. static void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
  1548. {
  1549. u32 val;
  1550. val = I915_READ(_TRANSACONF);
  1551. val &= ~TRANS_ENABLE;
  1552. I915_WRITE(_TRANSACONF, val);
  1553. /* wait for PCH transcoder off, transcoder state */
  1554. if (wait_for((I915_READ(_TRANSACONF) & TRANS_STATE_ENABLE) == 0, 50))
  1555. DRM_ERROR("Failed to disable PCH transcoder\n");
  1556. /* Workaround: clear timing override bit. */
  1557. val = I915_READ(_TRANSA_CHICKEN2);
  1558. val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
  1559. I915_WRITE(_TRANSA_CHICKEN2, val);
  1560. }
  1561. /**
  1562. * intel_enable_pipe - enable a pipe, asserting requirements
  1563. * @dev_priv: i915 private structure
  1564. * @pipe: pipe to enable
  1565. * @pch_port: on ILK+, is this pipe driving a PCH port or not
  1566. *
  1567. * Enable @pipe, making sure that various hardware specific requirements
  1568. * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc.
  1569. *
  1570. * @pipe should be %PIPE_A or %PIPE_B.
  1571. *
  1572. * Will wait until the pipe is actually running (i.e. first vblank) before
  1573. * returning.
  1574. */
  1575. static void intel_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe,
  1576. bool pch_port)
  1577. {
  1578. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  1579. pipe);
  1580. enum pipe pch_transcoder;
  1581. int reg;
  1582. u32 val;
  1583. if (HAS_PCH_LPT(dev_priv->dev))
  1584. pch_transcoder = TRANSCODER_A;
  1585. else
  1586. pch_transcoder = pipe;
  1587. /*
  1588. * A pipe without a PLL won't actually be able to drive bits from
  1589. * a plane. On ILK+ the pipe PLLs are integrated, so we don't
  1590. * need the check.
  1591. */
  1592. if (!HAS_PCH_SPLIT(dev_priv->dev))
  1593. assert_pll_enabled(dev_priv, pipe);
  1594. else {
  1595. if (pch_port) {
  1596. /* if driving the PCH, we need FDI enabled */
  1597. assert_fdi_rx_pll_enabled(dev_priv, pch_transcoder);
  1598. assert_fdi_tx_pll_enabled(dev_priv,
  1599. (enum pipe) cpu_transcoder);
  1600. }
  1601. /* FIXME: assert CPU port conditions for SNB+ */
  1602. }
  1603. reg = PIPECONF(cpu_transcoder);
  1604. val = I915_READ(reg);
  1605. if (val & PIPECONF_ENABLE)
  1606. return;
  1607. I915_WRITE(reg, val | PIPECONF_ENABLE);
  1608. intel_wait_for_vblank(dev_priv->dev, pipe);
  1609. }
  1610. /**
  1611. * intel_disable_pipe - disable a pipe, asserting requirements
  1612. * @dev_priv: i915 private structure
  1613. * @pipe: pipe to disable
  1614. *
  1615. * Disable @pipe, making sure that various hardware specific requirements
  1616. * are met, if applicable, e.g. plane disabled, panel fitter off, etc.
  1617. *
  1618. * @pipe should be %PIPE_A or %PIPE_B.
  1619. *
  1620. * Will wait until the pipe has shut down before returning.
  1621. */
  1622. static void intel_disable_pipe(struct drm_i915_private *dev_priv,
  1623. enum pipe pipe)
  1624. {
  1625. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  1626. pipe);
  1627. int reg;
  1628. u32 val;
  1629. /*
  1630. * Make sure planes won't keep trying to pump pixels to us,
  1631. * or we might hang the display.
  1632. */
  1633. assert_planes_disabled(dev_priv, pipe);
  1634. /* Don't disable pipe A or pipe A PLLs if needed */
  1635. if (pipe == PIPE_A && (dev_priv->quirks & QUIRK_PIPEA_FORCE))
  1636. return;
  1637. reg = PIPECONF(cpu_transcoder);
  1638. val = I915_READ(reg);
  1639. if ((val & PIPECONF_ENABLE) == 0)
  1640. return;
  1641. I915_WRITE(reg, val & ~PIPECONF_ENABLE);
  1642. intel_wait_for_pipe_off(dev_priv->dev, pipe);
  1643. }
  1644. /*
  1645. * Plane regs are double buffered, going from enabled->disabled needs a
  1646. * trigger in order to latch. The display address reg provides this.
  1647. */
  1648. void intel_flush_display_plane(struct drm_i915_private *dev_priv,
  1649. enum plane plane)
  1650. {
  1651. if (dev_priv->info->gen >= 4)
  1652. I915_WRITE(DSPSURF(plane), I915_READ(DSPSURF(plane)));
  1653. else
  1654. I915_WRITE(DSPADDR(plane), I915_READ(DSPADDR(plane)));
  1655. }
  1656. /**
  1657. * intel_enable_plane - enable a display plane on a given pipe
  1658. * @dev_priv: i915 private structure
  1659. * @plane: plane to enable
  1660. * @pipe: pipe being fed
  1661. *
  1662. * Enable @plane on @pipe, making sure that @pipe is running first.
  1663. */
  1664. static void intel_enable_plane(struct drm_i915_private *dev_priv,
  1665. enum plane plane, enum pipe pipe)
  1666. {
  1667. int reg;
  1668. u32 val;
  1669. /* If the pipe isn't enabled, we can't pump pixels and may hang */
  1670. assert_pipe_enabled(dev_priv, pipe);
  1671. reg = DSPCNTR(plane);
  1672. val = I915_READ(reg);
  1673. if (val & DISPLAY_PLANE_ENABLE)
  1674. return;
  1675. I915_WRITE(reg, val | DISPLAY_PLANE_ENABLE);
  1676. intel_flush_display_plane(dev_priv, plane);
  1677. intel_wait_for_vblank(dev_priv->dev, pipe);
  1678. }
  1679. /**
  1680. * intel_disable_plane - disable a display plane
  1681. * @dev_priv: i915 private structure
  1682. * @plane: plane to disable
  1683. * @pipe: pipe consuming the data
  1684. *
  1685. * Disable @plane; should be an independent operation.
  1686. */
  1687. static void intel_disable_plane(struct drm_i915_private *dev_priv,
  1688. enum plane plane, enum pipe pipe)
  1689. {
  1690. int reg;
  1691. u32 val;
  1692. reg = DSPCNTR(plane);
  1693. val = I915_READ(reg);
  1694. if ((val & DISPLAY_PLANE_ENABLE) == 0)
  1695. return;
  1696. I915_WRITE(reg, val & ~DISPLAY_PLANE_ENABLE);
  1697. intel_flush_display_plane(dev_priv, plane);
  1698. intel_wait_for_vblank(dev_priv->dev, pipe);
  1699. }
  1700. int
  1701. intel_pin_and_fence_fb_obj(struct drm_device *dev,
  1702. struct drm_i915_gem_object *obj,
  1703. struct intel_ring_buffer *pipelined)
  1704. {
  1705. struct drm_i915_private *dev_priv = dev->dev_private;
  1706. u32 alignment;
  1707. int ret;
  1708. switch (obj->tiling_mode) {
  1709. case I915_TILING_NONE:
  1710. if (IS_BROADWATER(dev) || IS_CRESTLINE(dev))
  1711. alignment = 128 * 1024;
  1712. else if (INTEL_INFO(dev)->gen >= 4)
  1713. alignment = 4 * 1024;
  1714. else
  1715. alignment = 64 * 1024;
  1716. break;
  1717. case I915_TILING_X:
  1718. /* pin() will align the object as required by fence */
  1719. alignment = 0;
  1720. break;
  1721. case I915_TILING_Y:
  1722. /* FIXME: Is this true? */
  1723. DRM_ERROR("Y tiled not allowed for scan out buffers\n");
  1724. return -EINVAL;
  1725. default:
  1726. BUG();
  1727. }
  1728. dev_priv->mm.interruptible = false;
  1729. ret = i915_gem_object_pin_to_display_plane(obj, alignment, pipelined);
  1730. if (ret)
  1731. goto err_interruptible;
  1732. /* Install a fence for tiled scan-out. Pre-i965 always needs a
  1733. * fence, whereas 965+ only requires a fence if using
  1734. * framebuffer compression. For simplicity, we always install
  1735. * a fence as the cost is not that onerous.
  1736. */
  1737. ret = i915_gem_object_get_fence(obj);
  1738. if (ret)
  1739. goto err_unpin;
  1740. i915_gem_object_pin_fence(obj);
  1741. dev_priv->mm.interruptible = true;
  1742. return 0;
  1743. err_unpin:
  1744. i915_gem_object_unpin(obj);
  1745. err_interruptible:
  1746. dev_priv->mm.interruptible = true;
  1747. return ret;
  1748. }
  1749. void intel_unpin_fb_obj(struct drm_i915_gem_object *obj)
  1750. {
  1751. i915_gem_object_unpin_fence(obj);
  1752. i915_gem_object_unpin(obj);
  1753. }
  1754. /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel
  1755. * is assumed to be a power-of-two. */
  1756. unsigned long intel_gen4_compute_offset_xtiled(int *x, int *y,
  1757. unsigned int bpp,
  1758. unsigned int pitch)
  1759. {
  1760. int tile_rows, tiles;
  1761. tile_rows = *y / 8;
  1762. *y %= 8;
  1763. tiles = *x / (512/bpp);
  1764. *x %= 512/bpp;
  1765. return tile_rows * pitch * 8 + tiles * 4096;
  1766. }
  1767. static int i9xx_update_plane(struct drm_crtc *crtc, struct drm_framebuffer *fb,
  1768. int x, int y)
  1769. {
  1770. struct drm_device *dev = crtc->dev;
  1771. struct drm_i915_private *dev_priv = dev->dev_private;
  1772. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1773. struct intel_framebuffer *intel_fb;
  1774. struct drm_i915_gem_object *obj;
  1775. int plane = intel_crtc->plane;
  1776. unsigned long linear_offset;
  1777. u32 dspcntr;
  1778. u32 reg;
  1779. switch (plane) {
  1780. case 0:
  1781. case 1:
  1782. break;
  1783. default:
  1784. DRM_ERROR("Can't update plane %d in SAREA\n", plane);
  1785. return -EINVAL;
  1786. }
  1787. intel_fb = to_intel_framebuffer(fb);
  1788. obj = intel_fb->obj;
  1789. reg = DSPCNTR(plane);
  1790. dspcntr = I915_READ(reg);
  1791. /* Mask out pixel format bits in case we change it */
  1792. dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
  1793. switch (fb->pixel_format) {
  1794. case DRM_FORMAT_C8:
  1795. dspcntr |= DISPPLANE_8BPP;
  1796. break;
  1797. case DRM_FORMAT_XRGB1555:
  1798. case DRM_FORMAT_ARGB1555:
  1799. dspcntr |= DISPPLANE_BGRX555;
  1800. break;
  1801. case DRM_FORMAT_RGB565:
  1802. dspcntr |= DISPPLANE_BGRX565;
  1803. break;
  1804. case DRM_FORMAT_XRGB8888:
  1805. case DRM_FORMAT_ARGB8888:
  1806. dspcntr |= DISPPLANE_BGRX888;
  1807. break;
  1808. case DRM_FORMAT_XBGR8888:
  1809. case DRM_FORMAT_ABGR8888:
  1810. dspcntr |= DISPPLANE_RGBX888;
  1811. break;
  1812. case DRM_FORMAT_XRGB2101010:
  1813. case DRM_FORMAT_ARGB2101010:
  1814. dspcntr |= DISPPLANE_BGRX101010;
  1815. break;
  1816. case DRM_FORMAT_XBGR2101010:
  1817. case DRM_FORMAT_ABGR2101010:
  1818. dspcntr |= DISPPLANE_RGBX101010;
  1819. break;
  1820. default:
  1821. DRM_ERROR("Unknown pixel format 0x%08x\n", fb->pixel_format);
  1822. return -EINVAL;
  1823. }
  1824. if (INTEL_INFO(dev)->gen >= 4) {
  1825. if (obj->tiling_mode != I915_TILING_NONE)
  1826. dspcntr |= DISPPLANE_TILED;
  1827. else
  1828. dspcntr &= ~DISPPLANE_TILED;
  1829. }
  1830. I915_WRITE(reg, dspcntr);
  1831. linear_offset = y * fb->pitches[0] + x * (fb->bits_per_pixel / 8);
  1832. if (INTEL_INFO(dev)->gen >= 4) {
  1833. intel_crtc->dspaddr_offset =
  1834. intel_gen4_compute_offset_xtiled(&x, &y,
  1835. fb->bits_per_pixel / 8,
  1836. fb->pitches[0]);
  1837. linear_offset -= intel_crtc->dspaddr_offset;
  1838. } else {
  1839. intel_crtc->dspaddr_offset = linear_offset;
  1840. }
  1841. DRM_DEBUG_KMS("Writing base %08X %08lX %d %d %d\n",
  1842. obj->gtt_offset, linear_offset, x, y, fb->pitches[0]);
  1843. I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);
  1844. if (INTEL_INFO(dev)->gen >= 4) {
  1845. I915_MODIFY_DISPBASE(DSPSURF(plane),
  1846. obj->gtt_offset + intel_crtc->dspaddr_offset);
  1847. I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
  1848. I915_WRITE(DSPLINOFF(plane), linear_offset);
  1849. } else
  1850. I915_WRITE(DSPADDR(plane), obj->gtt_offset + linear_offset);
  1851. POSTING_READ(reg);
  1852. return 0;
  1853. }
  1854. static int ironlake_update_plane(struct drm_crtc *crtc,
  1855. struct drm_framebuffer *fb, int x, int y)
  1856. {
  1857. struct drm_device *dev = crtc->dev;
  1858. struct drm_i915_private *dev_priv = dev->dev_private;
  1859. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1860. struct intel_framebuffer *intel_fb;
  1861. struct drm_i915_gem_object *obj;
  1862. int plane = intel_crtc->plane;
  1863. unsigned long linear_offset;
  1864. u32 dspcntr;
  1865. u32 reg;
  1866. switch (plane) {
  1867. case 0:
  1868. case 1:
  1869. case 2:
  1870. break;
  1871. default:
  1872. DRM_ERROR("Can't update plane %d in SAREA\n", plane);
  1873. return -EINVAL;
  1874. }
  1875. intel_fb = to_intel_framebuffer(fb);
  1876. obj = intel_fb->obj;
  1877. reg = DSPCNTR(plane);
  1878. dspcntr = I915_READ(reg);
  1879. /* Mask out pixel format bits in case we change it */
  1880. dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
  1881. switch (fb->pixel_format) {
  1882. case DRM_FORMAT_C8:
  1883. dspcntr |= DISPPLANE_8BPP;
  1884. break;
  1885. case DRM_FORMAT_RGB565:
  1886. dspcntr |= DISPPLANE_BGRX565;
  1887. break;
  1888. case DRM_FORMAT_XRGB8888:
  1889. case DRM_FORMAT_ARGB8888:
  1890. dspcntr |= DISPPLANE_BGRX888;
  1891. break;
  1892. case DRM_FORMAT_XBGR8888:
  1893. case DRM_FORMAT_ABGR8888:
  1894. dspcntr |= DISPPLANE_RGBX888;
  1895. break;
  1896. case DRM_FORMAT_XRGB2101010:
  1897. case DRM_FORMAT_ARGB2101010:
  1898. dspcntr |= DISPPLANE_BGRX101010;
  1899. break;
  1900. case DRM_FORMAT_XBGR2101010:
  1901. case DRM_FORMAT_ABGR2101010:
  1902. dspcntr |= DISPPLANE_RGBX101010;
  1903. break;
  1904. default:
  1905. DRM_ERROR("Unknown pixel format 0x%08x\n", fb->pixel_format);
  1906. return -EINVAL;
  1907. }
  1908. if (obj->tiling_mode != I915_TILING_NONE)
  1909. dspcntr |= DISPPLANE_TILED;
  1910. else
  1911. dspcntr &= ~DISPPLANE_TILED;
  1912. /* must disable */
  1913. dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
  1914. I915_WRITE(reg, dspcntr);
  1915. linear_offset = y * fb->pitches[0] + x * (fb->bits_per_pixel / 8);
  1916. intel_crtc->dspaddr_offset =
  1917. intel_gen4_compute_offset_xtiled(&x, &y,
  1918. fb->bits_per_pixel / 8,
  1919. fb->pitches[0]);
  1920. linear_offset -= intel_crtc->dspaddr_offset;
  1921. DRM_DEBUG_KMS("Writing base %08X %08lX %d %d %d\n",
  1922. obj->gtt_offset, linear_offset, x, y, fb->pitches[0]);
  1923. I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);
  1924. I915_MODIFY_DISPBASE(DSPSURF(plane),
  1925. obj->gtt_offset + intel_crtc->dspaddr_offset);
  1926. if (IS_HASWELL(dev)) {
  1927. I915_WRITE(DSPOFFSET(plane), (y << 16) | x);
  1928. } else {
  1929. I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
  1930. I915_WRITE(DSPLINOFF(plane), linear_offset);
  1931. }
  1932. POSTING_READ(reg);
  1933. return 0;
  1934. }
  1935. /* Assume fb object is pinned & idle & fenced and just update base pointers */
  1936. static int
  1937. intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb,
  1938. int x, int y, enum mode_set_atomic state)
  1939. {
  1940. struct drm_device *dev = crtc->dev;
  1941. struct drm_i915_private *dev_priv = dev->dev_private;
  1942. if (dev_priv->display.disable_fbc)
  1943. dev_priv->display.disable_fbc(dev);
  1944. intel_increase_pllclock(crtc);
  1945. return dev_priv->display.update_plane(crtc, fb, x, y);
  1946. }
  1947. static int
  1948. intel_finish_fb(struct drm_framebuffer *old_fb)
  1949. {
  1950. struct drm_i915_gem_object *obj = to_intel_framebuffer(old_fb)->obj;
  1951. struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
  1952. bool was_interruptible = dev_priv->mm.interruptible;
  1953. int ret;
  1954. WARN_ON(waitqueue_active(&dev_priv->pending_flip_queue));
  1955. wait_event(dev_priv->pending_flip_queue,
  1956. i915_reset_in_progress(&dev_priv->gpu_error) ||
  1957. atomic_read(&obj->pending_flip) == 0);
  1958. /* Big Hammer, we also need to ensure that any pending
  1959. * MI_WAIT_FOR_EVENT inside a user batch buffer on the
  1960. * current scanout is retired before unpinning the old
  1961. * framebuffer.
  1962. *
  1963. * This should only fail upon a hung GPU, in which case we
  1964. * can safely continue.
  1965. */
  1966. dev_priv->mm.interruptible = false;
  1967. ret = i915_gem_object_finish_gpu(obj);
  1968. dev_priv->mm.interruptible = was_interruptible;
  1969. return ret;
  1970. }
  1971. static void intel_crtc_update_sarea_pos(struct drm_crtc *crtc, int x, int y)
  1972. {
  1973. struct drm_device *dev = crtc->dev;
  1974. struct drm_i915_master_private *master_priv;
  1975. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1976. if (!dev->primary->master)
  1977. return;
  1978. master_priv = dev->primary->master->driver_priv;
  1979. if (!master_priv->sarea_priv)
  1980. return;
  1981. switch (intel_crtc->pipe) {
  1982. case 0:
  1983. master_priv->sarea_priv->pipeA_x = x;
  1984. master_priv->sarea_priv->pipeA_y = y;
  1985. break;
  1986. case 1:
  1987. master_priv->sarea_priv->pipeB_x = x;
  1988. master_priv->sarea_priv->pipeB_y = y;
  1989. break;
  1990. default:
  1991. break;
  1992. }
  1993. }
  1994. static int
  1995. intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
  1996. struct drm_framebuffer *fb)
  1997. {
  1998. struct drm_device *dev = crtc->dev;
  1999. struct drm_i915_private *dev_priv = dev->dev_private;
  2000. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2001. struct drm_framebuffer *old_fb;
  2002. int ret;
  2003. /* no fb bound */
  2004. if (!fb) {
  2005. DRM_ERROR("No FB bound\n");
  2006. return 0;
  2007. }
  2008. if(intel_crtc->plane > dev_priv->num_pipe) {
  2009. DRM_ERROR("no plane for crtc: plane %d, num_pipes %d\n",
  2010. intel_crtc->plane,
  2011. dev_priv->num_pipe);
  2012. return -EINVAL;
  2013. }
  2014. mutex_lock(&dev->struct_mutex);
  2015. ret = intel_pin_and_fence_fb_obj(dev,
  2016. to_intel_framebuffer(fb)->obj,
  2017. NULL);
  2018. if (ret != 0) {
  2019. mutex_unlock(&dev->struct_mutex);
  2020. DRM_ERROR("pin & fence failed\n");
  2021. return ret;
  2022. }
  2023. if (crtc->fb)
  2024. intel_finish_fb(crtc->fb);
  2025. ret = dev_priv->display.update_plane(crtc, fb, x, y);
  2026. if (ret) {
  2027. intel_unpin_fb_obj(to_intel_framebuffer(fb)->obj);
  2028. mutex_unlock(&dev->struct_mutex);
  2029. DRM_ERROR("failed to update base address\n");
  2030. return ret;
  2031. }
  2032. old_fb = crtc->fb;
  2033. crtc->fb = fb;
  2034. crtc->x = x;
  2035. crtc->y = y;
  2036. if (old_fb) {
  2037. intel_wait_for_vblank(dev, intel_crtc->pipe);
  2038. intel_unpin_fb_obj(to_intel_framebuffer(old_fb)->obj);
  2039. }
  2040. intel_update_fbc(dev);
  2041. mutex_unlock(&dev->struct_mutex);
  2042. intel_crtc_update_sarea_pos(crtc, x, y);
  2043. return 0;
  2044. }
  2045. static void intel_fdi_normal_train(struct drm_crtc *crtc)
  2046. {
  2047. struct drm_device *dev = crtc->dev;
  2048. struct drm_i915_private *dev_priv = dev->dev_private;
  2049. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2050. int pipe = intel_crtc->pipe;
  2051. u32 reg, temp;
  2052. /* enable normal train */
  2053. reg = FDI_TX_CTL(pipe);
  2054. temp = I915_READ(reg);
  2055. if (IS_IVYBRIDGE(dev)) {
  2056. temp &= ~FDI_LINK_TRAIN_NONE_IVB;
  2057. temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
  2058. } else {
  2059. temp &= ~FDI_LINK_TRAIN_NONE;
  2060. temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
  2061. }
  2062. I915_WRITE(reg, temp);
  2063. reg = FDI_RX_CTL(pipe);
  2064. temp = I915_READ(reg);
  2065. if (HAS_PCH_CPT(dev)) {
  2066. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2067. temp |= FDI_LINK_TRAIN_NORMAL_CPT;
  2068. } else {
  2069. temp &= ~FDI_LINK_TRAIN_NONE;
  2070. temp |= FDI_LINK_TRAIN_NONE;
  2071. }
  2072. I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
  2073. /* wait one idle pattern time */
  2074. POSTING_READ(reg);
  2075. udelay(1000);
  2076. /* IVB wants error correction enabled */
  2077. if (IS_IVYBRIDGE(dev))
  2078. I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
  2079. FDI_FE_ERRC_ENABLE);
  2080. }
  2081. static void ivb_modeset_global_resources(struct drm_device *dev)
  2082. {
  2083. struct drm_i915_private *dev_priv = dev->dev_private;
  2084. struct intel_crtc *pipe_B_crtc =
  2085. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]);
  2086. struct intel_crtc *pipe_C_crtc =
  2087. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_C]);
  2088. uint32_t temp;
  2089. /* When everything is off disable fdi C so that we could enable fdi B
  2090. * with all lanes. XXX: This misses the case where a pipe is not using
  2091. * any pch resources and so doesn't need any fdi lanes. */
  2092. if (!pipe_B_crtc->base.enabled && !pipe_C_crtc->base.enabled) {
  2093. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
  2094. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
  2095. temp = I915_READ(SOUTH_CHICKEN1);
  2096. temp &= ~FDI_BC_BIFURCATION_SELECT;
  2097. DRM_DEBUG_KMS("disabling fdi C rx\n");
  2098. I915_WRITE(SOUTH_CHICKEN1, temp);
  2099. }
  2100. }
  2101. /* The FDI link training functions for ILK/Ibexpeak. */
  2102. static void ironlake_fdi_link_train(struct drm_crtc *crtc)
  2103. {
  2104. struct drm_device *dev = crtc->dev;
  2105. struct drm_i915_private *dev_priv = dev->dev_private;
  2106. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2107. int pipe = intel_crtc->pipe;
  2108. int plane = intel_crtc->plane;
  2109. u32 reg, temp, tries;
  2110. /* FDI needs bits from pipe & plane first */
  2111. assert_pipe_enabled(dev_priv, pipe);
  2112. assert_plane_enabled(dev_priv, plane);
  2113. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2114. for train result */
  2115. reg = FDI_RX_IMR(pipe);
  2116. temp = I915_READ(reg);
  2117. temp &= ~FDI_RX_SYMBOL_LOCK;
  2118. temp &= ~FDI_RX_BIT_LOCK;
  2119. I915_WRITE(reg, temp);
  2120. I915_READ(reg);
  2121. udelay(150);
  2122. /* enable CPU FDI TX and PCH FDI RX */
  2123. reg = FDI_TX_CTL(pipe);
  2124. temp = I915_READ(reg);
  2125. temp &= ~(7 << 19);
  2126. temp |= (intel_crtc->fdi_lanes - 1) << 19;
  2127. temp &= ~FDI_LINK_TRAIN_NONE;
  2128. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2129. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2130. reg = FDI_RX_CTL(pipe);
  2131. temp = I915_READ(reg);
  2132. temp &= ~FDI_LINK_TRAIN_NONE;
  2133. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2134. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2135. POSTING_READ(reg);
  2136. udelay(150);
  2137. /* Ironlake workaround, enable clock pointer after FDI enable*/
  2138. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
  2139. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
  2140. FDI_RX_PHASE_SYNC_POINTER_EN);
  2141. reg = FDI_RX_IIR(pipe);
  2142. for (tries = 0; tries < 5; tries++) {
  2143. temp = I915_READ(reg);
  2144. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2145. if ((temp & FDI_RX_BIT_LOCK)) {
  2146. DRM_DEBUG_KMS("FDI train 1 done.\n");
  2147. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2148. break;
  2149. }
  2150. }
  2151. if (tries == 5)
  2152. DRM_ERROR("FDI train 1 fail!\n");
  2153. /* Train 2 */
  2154. reg = FDI_TX_CTL(pipe);
  2155. temp = I915_READ(reg);
  2156. temp &= ~FDI_LINK_TRAIN_NONE;
  2157. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2158. I915_WRITE(reg, temp);
  2159. reg = FDI_RX_CTL(pipe);
  2160. temp = I915_READ(reg);
  2161. temp &= ~FDI_LINK_TRAIN_NONE;
  2162. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2163. I915_WRITE(reg, temp);
  2164. POSTING_READ(reg);
  2165. udelay(150);
  2166. reg = FDI_RX_IIR(pipe);
  2167. for (tries = 0; tries < 5; tries++) {
  2168. temp = I915_READ(reg);
  2169. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2170. if (temp & FDI_RX_SYMBOL_LOCK) {
  2171. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2172. DRM_DEBUG_KMS("FDI train 2 done.\n");
  2173. break;
  2174. }
  2175. }
  2176. if (tries == 5)
  2177. DRM_ERROR("FDI train 2 fail!\n");
  2178. DRM_DEBUG_KMS("FDI train done\n");
  2179. }
  2180. static const int snb_b_fdi_train_param[] = {
  2181. FDI_LINK_TRAIN_400MV_0DB_SNB_B,
  2182. FDI_LINK_TRAIN_400MV_6DB_SNB_B,
  2183. FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
  2184. FDI_LINK_TRAIN_800MV_0DB_SNB_B,
  2185. };
  2186. /* The FDI link training functions for SNB/Cougarpoint. */
  2187. static void gen6_fdi_link_train(struct drm_crtc *crtc)
  2188. {
  2189. struct drm_device *dev = crtc->dev;
  2190. struct drm_i915_private *dev_priv = dev->dev_private;
  2191. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2192. int pipe = intel_crtc->pipe;
  2193. u32 reg, temp, i, retry;
  2194. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2195. for train result */
  2196. reg = FDI_RX_IMR(pipe);
  2197. temp = I915_READ(reg);
  2198. temp &= ~FDI_RX_SYMBOL_LOCK;
  2199. temp &= ~FDI_RX_BIT_LOCK;
  2200. I915_WRITE(reg, temp);
  2201. POSTING_READ(reg);
  2202. udelay(150);
  2203. /* enable CPU FDI TX and PCH FDI RX */
  2204. reg = FDI_TX_CTL(pipe);
  2205. temp = I915_READ(reg);
  2206. temp &= ~(7 << 19);
  2207. temp |= (intel_crtc->fdi_lanes - 1) << 19;
  2208. temp &= ~FDI_LINK_TRAIN_NONE;
  2209. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2210. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2211. /* SNB-B */
  2212. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2213. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2214. I915_WRITE(FDI_RX_MISC(pipe),
  2215. FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
  2216. reg = FDI_RX_CTL(pipe);
  2217. temp = I915_READ(reg);
  2218. if (HAS_PCH_CPT(dev)) {
  2219. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2220. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2221. } else {
  2222. temp &= ~FDI_LINK_TRAIN_NONE;
  2223. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2224. }
  2225. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2226. POSTING_READ(reg);
  2227. udelay(150);
  2228. for (i = 0; i < 4; i++) {
  2229. reg = FDI_TX_CTL(pipe);
  2230. temp = I915_READ(reg);
  2231. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2232. temp |= snb_b_fdi_train_param[i];
  2233. I915_WRITE(reg, temp);
  2234. POSTING_READ(reg);
  2235. udelay(500);
  2236. for (retry = 0; retry < 5; retry++) {
  2237. reg = FDI_RX_IIR(pipe);
  2238. temp = I915_READ(reg);
  2239. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2240. if (temp & FDI_RX_BIT_LOCK) {
  2241. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2242. DRM_DEBUG_KMS("FDI train 1 done.\n");
  2243. break;
  2244. }
  2245. udelay(50);
  2246. }
  2247. if (retry < 5)
  2248. break;
  2249. }
  2250. if (i == 4)
  2251. DRM_ERROR("FDI train 1 fail!\n");
  2252. /* Train 2 */
  2253. reg = FDI_TX_CTL(pipe);
  2254. temp = I915_READ(reg);
  2255. temp &= ~FDI_LINK_TRAIN_NONE;
  2256. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2257. if (IS_GEN6(dev)) {
  2258. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2259. /* SNB-B */
  2260. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2261. }
  2262. I915_WRITE(reg, temp);
  2263. reg = FDI_RX_CTL(pipe);
  2264. temp = I915_READ(reg);
  2265. if (HAS_PCH_CPT(dev)) {
  2266. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2267. temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
  2268. } else {
  2269. temp &= ~FDI_LINK_TRAIN_NONE;
  2270. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2271. }
  2272. I915_WRITE(reg, temp);
  2273. POSTING_READ(reg);
  2274. udelay(150);
  2275. for (i = 0; i < 4; i++) {
  2276. reg = FDI_TX_CTL(pipe);
  2277. temp = I915_READ(reg);
  2278. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2279. temp |= snb_b_fdi_train_param[i];
  2280. I915_WRITE(reg, temp);
  2281. POSTING_READ(reg);
  2282. udelay(500);
  2283. for (retry = 0; retry < 5; retry++) {
  2284. reg = FDI_RX_IIR(pipe);
  2285. temp = I915_READ(reg);
  2286. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2287. if (temp & FDI_RX_SYMBOL_LOCK) {
  2288. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2289. DRM_DEBUG_KMS("FDI train 2 done.\n");
  2290. break;
  2291. }
  2292. udelay(50);
  2293. }
  2294. if (retry < 5)
  2295. break;
  2296. }
  2297. if (i == 4)
  2298. DRM_ERROR("FDI train 2 fail!\n");
  2299. DRM_DEBUG_KMS("FDI train done.\n");
  2300. }
  2301. /* Manual link training for Ivy Bridge A0 parts */
  2302. static void ivb_manual_fdi_link_train(struct drm_crtc *crtc)
  2303. {
  2304. struct drm_device *dev = crtc->dev;
  2305. struct drm_i915_private *dev_priv = dev->dev_private;
  2306. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2307. int pipe = intel_crtc->pipe;
  2308. u32 reg, temp, i;
  2309. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2310. for train result */
  2311. reg = FDI_RX_IMR(pipe);
  2312. temp = I915_READ(reg);
  2313. temp &= ~FDI_RX_SYMBOL_LOCK;
  2314. temp &= ~FDI_RX_BIT_LOCK;
  2315. I915_WRITE(reg, temp);
  2316. POSTING_READ(reg);
  2317. udelay(150);
  2318. DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
  2319. I915_READ(FDI_RX_IIR(pipe)));
  2320. /* enable CPU FDI TX and PCH FDI RX */
  2321. reg = FDI_TX_CTL(pipe);
  2322. temp = I915_READ(reg);
  2323. temp &= ~(7 << 19);
  2324. temp |= (intel_crtc->fdi_lanes - 1) << 19;
  2325. temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
  2326. temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
  2327. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2328. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2329. temp |= FDI_COMPOSITE_SYNC;
  2330. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2331. I915_WRITE(FDI_RX_MISC(pipe),
  2332. FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
  2333. reg = FDI_RX_CTL(pipe);
  2334. temp = I915_READ(reg);
  2335. temp &= ~FDI_LINK_TRAIN_AUTO;
  2336. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2337. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2338. temp |= FDI_COMPOSITE_SYNC;
  2339. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2340. POSTING_READ(reg);
  2341. udelay(150);
  2342. for (i = 0; i < 4; i++) {
  2343. reg = FDI_TX_CTL(pipe);
  2344. temp = I915_READ(reg);
  2345. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2346. temp |= snb_b_fdi_train_param[i];
  2347. I915_WRITE(reg, temp);
  2348. POSTING_READ(reg);
  2349. udelay(500);
  2350. reg = FDI_RX_IIR(pipe);
  2351. temp = I915_READ(reg);
  2352. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2353. if (temp & FDI_RX_BIT_LOCK ||
  2354. (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
  2355. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2356. DRM_DEBUG_KMS("FDI train 1 done, level %i.\n", i);
  2357. break;
  2358. }
  2359. }
  2360. if (i == 4)
  2361. DRM_ERROR("FDI train 1 fail!\n");
  2362. /* Train 2 */
  2363. reg = FDI_TX_CTL(pipe);
  2364. temp = I915_READ(reg);
  2365. temp &= ~FDI_LINK_TRAIN_NONE_IVB;
  2366. temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
  2367. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2368. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2369. I915_WRITE(reg, temp);
  2370. reg = FDI_RX_CTL(pipe);
  2371. temp = I915_READ(reg);
  2372. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2373. temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
  2374. I915_WRITE(reg, temp);
  2375. POSTING_READ(reg);
  2376. udelay(150);
  2377. for (i = 0; i < 4; i++) {
  2378. reg = FDI_TX_CTL(pipe);
  2379. temp = I915_READ(reg);
  2380. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2381. temp |= snb_b_fdi_train_param[i];
  2382. I915_WRITE(reg, temp);
  2383. POSTING_READ(reg);
  2384. udelay(500);
  2385. reg = FDI_RX_IIR(pipe);
  2386. temp = I915_READ(reg);
  2387. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2388. if (temp & FDI_RX_SYMBOL_LOCK) {
  2389. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2390. DRM_DEBUG_KMS("FDI train 2 done, level %i.\n", i);
  2391. break;
  2392. }
  2393. }
  2394. if (i == 4)
  2395. DRM_ERROR("FDI train 2 fail!\n");
  2396. DRM_DEBUG_KMS("FDI train done.\n");
  2397. }
  2398. static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc)
  2399. {
  2400. struct drm_device *dev = intel_crtc->base.dev;
  2401. struct drm_i915_private *dev_priv = dev->dev_private;
  2402. int pipe = intel_crtc->pipe;
  2403. u32 reg, temp;
  2404. /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
  2405. reg = FDI_RX_CTL(pipe);
  2406. temp = I915_READ(reg);
  2407. temp &= ~((0x7 << 19) | (0x7 << 16));
  2408. temp |= (intel_crtc->fdi_lanes - 1) << 19;
  2409. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  2410. I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
  2411. POSTING_READ(reg);
  2412. udelay(200);
  2413. /* Switch from Rawclk to PCDclk */
  2414. temp = I915_READ(reg);
  2415. I915_WRITE(reg, temp | FDI_PCDCLK);
  2416. POSTING_READ(reg);
  2417. udelay(200);
  2418. /* Enable CPU FDI TX PLL, always on for Ironlake */
  2419. reg = FDI_TX_CTL(pipe);
  2420. temp = I915_READ(reg);
  2421. if ((temp & FDI_TX_PLL_ENABLE) == 0) {
  2422. I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
  2423. POSTING_READ(reg);
  2424. udelay(100);
  2425. }
  2426. }
  2427. static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc)
  2428. {
  2429. struct drm_device *dev = intel_crtc->base.dev;
  2430. struct drm_i915_private *dev_priv = dev->dev_private;
  2431. int pipe = intel_crtc->pipe;
  2432. u32 reg, temp;
  2433. /* Switch from PCDclk to Rawclk */
  2434. reg = FDI_RX_CTL(pipe);
  2435. temp = I915_READ(reg);
  2436. I915_WRITE(reg, temp & ~FDI_PCDCLK);
  2437. /* Disable CPU FDI TX PLL */
  2438. reg = FDI_TX_CTL(pipe);
  2439. temp = I915_READ(reg);
  2440. I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
  2441. POSTING_READ(reg);
  2442. udelay(100);
  2443. reg = FDI_RX_CTL(pipe);
  2444. temp = I915_READ(reg);
  2445. I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
  2446. /* Wait for the clocks to turn off. */
  2447. POSTING_READ(reg);
  2448. udelay(100);
  2449. }
  2450. static void ironlake_fdi_disable(struct drm_crtc *crtc)
  2451. {
  2452. struct drm_device *dev = crtc->dev;
  2453. struct drm_i915_private *dev_priv = dev->dev_private;
  2454. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2455. int pipe = intel_crtc->pipe;
  2456. u32 reg, temp;
  2457. /* disable CPU FDI tx and PCH FDI rx */
  2458. reg = FDI_TX_CTL(pipe);
  2459. temp = I915_READ(reg);
  2460. I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
  2461. POSTING_READ(reg);
  2462. reg = FDI_RX_CTL(pipe);
  2463. temp = I915_READ(reg);
  2464. temp &= ~(0x7 << 16);
  2465. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  2466. I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
  2467. POSTING_READ(reg);
  2468. udelay(100);
  2469. /* Ironlake workaround, disable clock pointer after downing FDI */
  2470. if (HAS_PCH_IBX(dev)) {
  2471. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
  2472. }
  2473. /* still set train pattern 1 */
  2474. reg = FDI_TX_CTL(pipe);
  2475. temp = I915_READ(reg);
  2476. temp &= ~FDI_LINK_TRAIN_NONE;
  2477. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2478. I915_WRITE(reg, temp);
  2479. reg = FDI_RX_CTL(pipe);
  2480. temp = I915_READ(reg);
  2481. if (HAS_PCH_CPT(dev)) {
  2482. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2483. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2484. } else {
  2485. temp &= ~FDI_LINK_TRAIN_NONE;
  2486. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2487. }
  2488. /* BPC in FDI rx is consistent with that in PIPECONF */
  2489. temp &= ~(0x07 << 16);
  2490. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  2491. I915_WRITE(reg, temp);
  2492. POSTING_READ(reg);
  2493. udelay(100);
  2494. }
  2495. static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc)
  2496. {
  2497. struct drm_device *dev = crtc->dev;
  2498. struct drm_i915_private *dev_priv = dev->dev_private;
  2499. unsigned long flags;
  2500. bool pending;
  2501. if (i915_reset_in_progress(&dev_priv->gpu_error))
  2502. return false;
  2503. spin_lock_irqsave(&dev->event_lock, flags);
  2504. pending = to_intel_crtc(crtc)->unpin_work != NULL;
  2505. spin_unlock_irqrestore(&dev->event_lock, flags);
  2506. return pending;
  2507. }
  2508. static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
  2509. {
  2510. struct drm_device *dev = crtc->dev;
  2511. struct drm_i915_private *dev_priv = dev->dev_private;
  2512. if (crtc->fb == NULL)
  2513. return;
  2514. WARN_ON(waitqueue_active(&dev_priv->pending_flip_queue));
  2515. wait_event(dev_priv->pending_flip_queue,
  2516. !intel_crtc_has_pending_flip(crtc));
  2517. mutex_lock(&dev->struct_mutex);
  2518. intel_finish_fb(crtc->fb);
  2519. mutex_unlock(&dev->struct_mutex);
  2520. }
  2521. static bool ironlake_crtc_driving_pch(struct drm_crtc *crtc)
  2522. {
  2523. struct drm_device *dev = crtc->dev;
  2524. struct intel_encoder *intel_encoder;
  2525. /*
  2526. * If there's a non-PCH eDP on this crtc, it must be DP_A, and that
  2527. * must be driven by its own crtc; no sharing is possible.
  2528. */
  2529. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  2530. switch (intel_encoder->type) {
  2531. case INTEL_OUTPUT_EDP:
  2532. if (!intel_encoder_is_pch_edp(&intel_encoder->base))
  2533. return false;
  2534. continue;
  2535. }
  2536. }
  2537. return true;
  2538. }
  2539. static bool haswell_crtc_driving_pch(struct drm_crtc *crtc)
  2540. {
  2541. return intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG);
  2542. }
  2543. /* Program iCLKIP clock to the desired frequency */
  2544. static void lpt_program_iclkip(struct drm_crtc *crtc)
  2545. {
  2546. struct drm_device *dev = crtc->dev;
  2547. struct drm_i915_private *dev_priv = dev->dev_private;
  2548. u32 divsel, phaseinc, auxdiv, phasedir = 0;
  2549. u32 temp;
  2550. mutex_lock(&dev_priv->dpio_lock);
  2551. /* It is necessary to ungate the pixclk gate prior to programming
  2552. * the divisors, and gate it back when it is done.
  2553. */
  2554. I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE);
  2555. /* Disable SSCCTL */
  2556. intel_sbi_write(dev_priv, SBI_SSCCTL6,
  2557. intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK) |
  2558. SBI_SSCCTL_DISABLE,
  2559. SBI_ICLK);
  2560. /* 20MHz is a corner case which is out of range for the 7-bit divisor */
  2561. if (crtc->mode.clock == 20000) {
  2562. auxdiv = 1;
  2563. divsel = 0x41;
  2564. phaseinc = 0x20;
  2565. } else {
  2566. /* The iCLK virtual clock root frequency is in MHz,
  2567. * but the crtc->mode.clock in in KHz. To get the divisors,
  2568. * it is necessary to divide one by another, so we
  2569. * convert the virtual clock precision to KHz here for higher
  2570. * precision.
  2571. */
  2572. u32 iclk_virtual_root_freq = 172800 * 1000;
  2573. u32 iclk_pi_range = 64;
  2574. u32 desired_divisor, msb_divisor_value, pi_value;
  2575. desired_divisor = (iclk_virtual_root_freq / crtc->mode.clock);
  2576. msb_divisor_value = desired_divisor / iclk_pi_range;
  2577. pi_value = desired_divisor % iclk_pi_range;
  2578. auxdiv = 0;
  2579. divsel = msb_divisor_value - 2;
  2580. phaseinc = pi_value;
  2581. }
  2582. /* This should not happen with any sane values */
  2583. WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
  2584. ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
  2585. WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) &
  2586. ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
  2587. DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
  2588. crtc->mode.clock,
  2589. auxdiv,
  2590. divsel,
  2591. phasedir,
  2592. phaseinc);
  2593. /* Program SSCDIVINTPHASE6 */
  2594. temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
  2595. temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
  2596. temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
  2597. temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
  2598. temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
  2599. temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
  2600. temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
  2601. intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
  2602. /* Program SSCAUXDIV */
  2603. temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
  2604. temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
  2605. temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
  2606. intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
  2607. /* Enable modulator and associated divider */
  2608. temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
  2609. temp &= ~SBI_SSCCTL_DISABLE;
  2610. intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
  2611. /* Wait for initialization time */
  2612. udelay(24);
  2613. I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE);
  2614. mutex_unlock(&dev_priv->dpio_lock);
  2615. }
  2616. /*
  2617. * Enable PCH resources required for PCH ports:
  2618. * - PCH PLLs
  2619. * - FDI training & RX/TX
  2620. * - update transcoder timings
  2621. * - DP transcoding bits
  2622. * - transcoder
  2623. */
  2624. static void ironlake_pch_enable(struct drm_crtc *crtc)
  2625. {
  2626. struct drm_device *dev = crtc->dev;
  2627. struct drm_i915_private *dev_priv = dev->dev_private;
  2628. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2629. int pipe = intel_crtc->pipe;
  2630. u32 reg, temp;
  2631. assert_transcoder_disabled(dev_priv, pipe);
  2632. /* Write the TU size bits before fdi link training, so that error
  2633. * detection works. */
  2634. I915_WRITE(FDI_RX_TUSIZE1(pipe),
  2635. I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
  2636. /* For PCH output, training FDI link */
  2637. dev_priv->display.fdi_link_train(crtc);
  2638. /* XXX: pch pll's can be enabled any time before we enable the PCH
  2639. * transcoder, and we actually should do this to not upset any PCH
  2640. * transcoder that already use the clock when we share it.
  2641. *
  2642. * Note that enable_pch_pll tries to do the right thing, but get_pch_pll
  2643. * unconditionally resets the pll - we need that to have the right LVDS
  2644. * enable sequence. */
  2645. ironlake_enable_pch_pll(intel_crtc);
  2646. if (HAS_PCH_CPT(dev)) {
  2647. u32 sel;
  2648. temp = I915_READ(PCH_DPLL_SEL);
  2649. switch (pipe) {
  2650. default:
  2651. case 0:
  2652. temp |= TRANSA_DPLL_ENABLE;
  2653. sel = TRANSA_DPLLB_SEL;
  2654. break;
  2655. case 1:
  2656. temp |= TRANSB_DPLL_ENABLE;
  2657. sel = TRANSB_DPLLB_SEL;
  2658. break;
  2659. case 2:
  2660. temp |= TRANSC_DPLL_ENABLE;
  2661. sel = TRANSC_DPLLB_SEL;
  2662. break;
  2663. }
  2664. if (intel_crtc->pch_pll->pll_reg == _PCH_DPLL_B)
  2665. temp |= sel;
  2666. else
  2667. temp &= ~sel;
  2668. I915_WRITE(PCH_DPLL_SEL, temp);
  2669. }
  2670. /* set transcoder timing, panel must allow it */
  2671. assert_panel_unlocked(dev_priv, pipe);
  2672. I915_WRITE(TRANS_HTOTAL(pipe), I915_READ(HTOTAL(pipe)));
  2673. I915_WRITE(TRANS_HBLANK(pipe), I915_READ(HBLANK(pipe)));
  2674. I915_WRITE(TRANS_HSYNC(pipe), I915_READ(HSYNC(pipe)));
  2675. I915_WRITE(TRANS_VTOTAL(pipe), I915_READ(VTOTAL(pipe)));
  2676. I915_WRITE(TRANS_VBLANK(pipe), I915_READ(VBLANK(pipe)));
  2677. I915_WRITE(TRANS_VSYNC(pipe), I915_READ(VSYNC(pipe)));
  2678. I915_WRITE(TRANS_VSYNCSHIFT(pipe), I915_READ(VSYNCSHIFT(pipe)));
  2679. intel_fdi_normal_train(crtc);
  2680. /* For PCH DP, enable TRANS_DP_CTL */
  2681. if (HAS_PCH_CPT(dev) &&
  2682. (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) ||
  2683. intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) {
  2684. u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
  2685. reg = TRANS_DP_CTL(pipe);
  2686. temp = I915_READ(reg);
  2687. temp &= ~(TRANS_DP_PORT_SEL_MASK |
  2688. TRANS_DP_SYNC_MASK |
  2689. TRANS_DP_BPC_MASK);
  2690. temp |= (TRANS_DP_OUTPUT_ENABLE |
  2691. TRANS_DP_ENH_FRAMING);
  2692. temp |= bpc << 9; /* same format but at 11:9 */
  2693. if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC)
  2694. temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
  2695. if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC)
  2696. temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
  2697. switch (intel_trans_dp_port_sel(crtc)) {
  2698. case PCH_DP_B:
  2699. temp |= TRANS_DP_PORT_SEL_B;
  2700. break;
  2701. case PCH_DP_C:
  2702. temp |= TRANS_DP_PORT_SEL_C;
  2703. break;
  2704. case PCH_DP_D:
  2705. temp |= TRANS_DP_PORT_SEL_D;
  2706. break;
  2707. default:
  2708. BUG();
  2709. }
  2710. I915_WRITE(reg, temp);
  2711. }
  2712. ironlake_enable_pch_transcoder(dev_priv, pipe);
  2713. }
  2714. static void lpt_pch_enable(struct drm_crtc *crtc)
  2715. {
  2716. struct drm_device *dev = crtc->dev;
  2717. struct drm_i915_private *dev_priv = dev->dev_private;
  2718. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2719. enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
  2720. assert_transcoder_disabled(dev_priv, TRANSCODER_A);
  2721. lpt_program_iclkip(crtc);
  2722. /* Set transcoder timing. */
  2723. I915_WRITE(_TRANS_HTOTAL_A, I915_READ(HTOTAL(cpu_transcoder)));
  2724. I915_WRITE(_TRANS_HBLANK_A, I915_READ(HBLANK(cpu_transcoder)));
  2725. I915_WRITE(_TRANS_HSYNC_A, I915_READ(HSYNC(cpu_transcoder)));
  2726. I915_WRITE(_TRANS_VTOTAL_A, I915_READ(VTOTAL(cpu_transcoder)));
  2727. I915_WRITE(_TRANS_VBLANK_A, I915_READ(VBLANK(cpu_transcoder)));
  2728. I915_WRITE(_TRANS_VSYNC_A, I915_READ(VSYNC(cpu_transcoder)));
  2729. I915_WRITE(_TRANS_VSYNCSHIFT_A, I915_READ(VSYNCSHIFT(cpu_transcoder)));
  2730. lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
  2731. }
  2732. static void intel_put_pch_pll(struct intel_crtc *intel_crtc)
  2733. {
  2734. struct intel_pch_pll *pll = intel_crtc->pch_pll;
  2735. if (pll == NULL)
  2736. return;
  2737. if (pll->refcount == 0) {
  2738. WARN(1, "bad PCH PLL refcount\n");
  2739. return;
  2740. }
  2741. --pll->refcount;
  2742. intel_crtc->pch_pll = NULL;
  2743. }
  2744. static struct intel_pch_pll *intel_get_pch_pll(struct intel_crtc *intel_crtc, u32 dpll, u32 fp)
  2745. {
  2746. struct drm_i915_private *dev_priv = intel_crtc->base.dev->dev_private;
  2747. struct intel_pch_pll *pll;
  2748. int i;
  2749. pll = intel_crtc->pch_pll;
  2750. if (pll) {
  2751. DRM_DEBUG_KMS("CRTC:%d reusing existing PCH PLL %x\n",
  2752. intel_crtc->base.base.id, pll->pll_reg);
  2753. goto prepare;
  2754. }
  2755. if (HAS_PCH_IBX(dev_priv->dev)) {
  2756. /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */
  2757. i = intel_crtc->pipe;
  2758. pll = &dev_priv->pch_plls[i];
  2759. DRM_DEBUG_KMS("CRTC:%d using pre-allocated PCH PLL %x\n",
  2760. intel_crtc->base.base.id, pll->pll_reg);
  2761. goto found;
  2762. }
  2763. for (i = 0; i < dev_priv->num_pch_pll; i++) {
  2764. pll = &dev_priv->pch_plls[i];
  2765. /* Only want to check enabled timings first */
  2766. if (pll->refcount == 0)
  2767. continue;
  2768. if (dpll == (I915_READ(pll->pll_reg) & 0x7fffffff) &&
  2769. fp == I915_READ(pll->fp0_reg)) {
  2770. DRM_DEBUG_KMS("CRTC:%d sharing existing PCH PLL %x (refcount %d, ative %d)\n",
  2771. intel_crtc->base.base.id,
  2772. pll->pll_reg, pll->refcount, pll->active);
  2773. goto found;
  2774. }
  2775. }
  2776. /* Ok no matching timings, maybe there's a free one? */
  2777. for (i = 0; i < dev_priv->num_pch_pll; i++) {
  2778. pll = &dev_priv->pch_plls[i];
  2779. if (pll->refcount == 0) {
  2780. DRM_DEBUG_KMS("CRTC:%d allocated PCH PLL %x\n",
  2781. intel_crtc->base.base.id, pll->pll_reg);
  2782. goto found;
  2783. }
  2784. }
  2785. return NULL;
  2786. found:
  2787. intel_crtc->pch_pll = pll;
  2788. pll->refcount++;
  2789. DRM_DEBUG_DRIVER("using pll %d for pipe %d\n", i, intel_crtc->pipe);
  2790. prepare: /* separate function? */
  2791. DRM_DEBUG_DRIVER("switching PLL %x off\n", pll->pll_reg);
  2792. /* Wait for the clocks to stabilize before rewriting the regs */
  2793. I915_WRITE(pll->pll_reg, dpll & ~DPLL_VCO_ENABLE);
  2794. POSTING_READ(pll->pll_reg);
  2795. udelay(150);
  2796. I915_WRITE(pll->fp0_reg, fp);
  2797. I915_WRITE(pll->pll_reg, dpll & ~DPLL_VCO_ENABLE);
  2798. pll->on = false;
  2799. return pll;
  2800. }
  2801. void intel_cpt_verify_modeset(struct drm_device *dev, int pipe)
  2802. {
  2803. struct drm_i915_private *dev_priv = dev->dev_private;
  2804. int dslreg = PIPEDSL(pipe);
  2805. u32 temp;
  2806. temp = I915_READ(dslreg);
  2807. udelay(500);
  2808. if (wait_for(I915_READ(dslreg) != temp, 5)) {
  2809. if (wait_for(I915_READ(dslreg) != temp, 5))
  2810. DRM_ERROR("mode set failed: pipe %d stuck\n", pipe);
  2811. }
  2812. }
  2813. static void ironlake_crtc_enable(struct drm_crtc *crtc)
  2814. {
  2815. struct drm_device *dev = crtc->dev;
  2816. struct drm_i915_private *dev_priv = dev->dev_private;
  2817. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2818. struct intel_encoder *encoder;
  2819. int pipe = intel_crtc->pipe;
  2820. int plane = intel_crtc->plane;
  2821. u32 temp;
  2822. bool is_pch_port;
  2823. WARN_ON(!crtc->enabled);
  2824. if (intel_crtc->active)
  2825. return;
  2826. intel_crtc->active = true;
  2827. intel_update_watermarks(dev);
  2828. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  2829. temp = I915_READ(PCH_LVDS);
  2830. if ((temp & LVDS_PORT_EN) == 0)
  2831. I915_WRITE(PCH_LVDS, temp | LVDS_PORT_EN);
  2832. }
  2833. is_pch_port = ironlake_crtc_driving_pch(crtc);
  2834. if (is_pch_port) {
  2835. /* Note: FDI PLL enabling _must_ be done before we enable the
  2836. * cpu pipes, hence this is separate from all the other fdi/pch
  2837. * enabling. */
  2838. ironlake_fdi_pll_enable(intel_crtc);
  2839. } else {
  2840. assert_fdi_tx_disabled(dev_priv, pipe);
  2841. assert_fdi_rx_disabled(dev_priv, pipe);
  2842. }
  2843. for_each_encoder_on_crtc(dev, crtc, encoder)
  2844. if (encoder->pre_enable)
  2845. encoder->pre_enable(encoder);
  2846. /* Enable panel fitting for LVDS */
  2847. if (dev_priv->pch_pf_size &&
  2848. (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) ||
  2849. intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) {
  2850. /* Force use of hard-coded filter coefficients
  2851. * as some pre-programmed values are broken,
  2852. * e.g. x201.
  2853. */
  2854. if (IS_IVYBRIDGE(dev))
  2855. I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
  2856. PF_PIPE_SEL_IVB(pipe));
  2857. else
  2858. I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
  2859. I915_WRITE(PF_WIN_POS(pipe), dev_priv->pch_pf_pos);
  2860. I915_WRITE(PF_WIN_SZ(pipe), dev_priv->pch_pf_size);
  2861. }
  2862. /*
  2863. * On ILK+ LUT must be loaded before the pipe is running but with
  2864. * clocks enabled
  2865. */
  2866. intel_crtc_load_lut(crtc);
  2867. intel_enable_pipe(dev_priv, pipe, is_pch_port);
  2868. intel_enable_plane(dev_priv, plane, pipe);
  2869. if (is_pch_port)
  2870. ironlake_pch_enable(crtc);
  2871. mutex_lock(&dev->struct_mutex);
  2872. intel_update_fbc(dev);
  2873. mutex_unlock(&dev->struct_mutex);
  2874. intel_crtc_update_cursor(crtc, true);
  2875. for_each_encoder_on_crtc(dev, crtc, encoder)
  2876. encoder->enable(encoder);
  2877. if (HAS_PCH_CPT(dev))
  2878. intel_cpt_verify_modeset(dev, intel_crtc->pipe);
  2879. /*
  2880. * There seems to be a race in PCH platform hw (at least on some
  2881. * outputs) where an enabled pipe still completes any pageflip right
  2882. * away (as if the pipe is off) instead of waiting for vblank. As soon
  2883. * as the first vblank happend, everything works as expected. Hence just
  2884. * wait for one vblank before returning to avoid strange things
  2885. * happening.
  2886. */
  2887. intel_wait_for_vblank(dev, intel_crtc->pipe);
  2888. }
  2889. static void haswell_crtc_enable(struct drm_crtc *crtc)
  2890. {
  2891. struct drm_device *dev = crtc->dev;
  2892. struct drm_i915_private *dev_priv = dev->dev_private;
  2893. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2894. struct intel_encoder *encoder;
  2895. int pipe = intel_crtc->pipe;
  2896. int plane = intel_crtc->plane;
  2897. bool is_pch_port;
  2898. WARN_ON(!crtc->enabled);
  2899. if (intel_crtc->active)
  2900. return;
  2901. intel_crtc->active = true;
  2902. intel_update_watermarks(dev);
  2903. is_pch_port = haswell_crtc_driving_pch(crtc);
  2904. if (is_pch_port)
  2905. dev_priv->display.fdi_link_train(crtc);
  2906. for_each_encoder_on_crtc(dev, crtc, encoder)
  2907. if (encoder->pre_enable)
  2908. encoder->pre_enable(encoder);
  2909. intel_ddi_enable_pipe_clock(intel_crtc);
  2910. /* Enable panel fitting for eDP */
  2911. if (dev_priv->pch_pf_size &&
  2912. intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) {
  2913. /* Force use of hard-coded filter coefficients
  2914. * as some pre-programmed values are broken,
  2915. * e.g. x201.
  2916. */
  2917. I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
  2918. PF_PIPE_SEL_IVB(pipe));
  2919. I915_WRITE(PF_WIN_POS(pipe), dev_priv->pch_pf_pos);
  2920. I915_WRITE(PF_WIN_SZ(pipe), dev_priv->pch_pf_size);
  2921. }
  2922. /*
  2923. * On ILK+ LUT must be loaded before the pipe is running but with
  2924. * clocks enabled
  2925. */
  2926. intel_crtc_load_lut(crtc);
  2927. intel_ddi_set_pipe_settings(crtc);
  2928. intel_ddi_enable_pipe_func(crtc);
  2929. intel_enable_pipe(dev_priv, pipe, is_pch_port);
  2930. intel_enable_plane(dev_priv, plane, pipe);
  2931. if (is_pch_port)
  2932. lpt_pch_enable(crtc);
  2933. mutex_lock(&dev->struct_mutex);
  2934. intel_update_fbc(dev);
  2935. mutex_unlock(&dev->struct_mutex);
  2936. intel_crtc_update_cursor(crtc, true);
  2937. for_each_encoder_on_crtc(dev, crtc, encoder)
  2938. encoder->enable(encoder);
  2939. /*
  2940. * There seems to be a race in PCH platform hw (at least on some
  2941. * outputs) where an enabled pipe still completes any pageflip right
  2942. * away (as if the pipe is off) instead of waiting for vblank. As soon
  2943. * as the first vblank happend, everything works as expected. Hence just
  2944. * wait for one vblank before returning to avoid strange things
  2945. * happening.
  2946. */
  2947. intel_wait_for_vblank(dev, intel_crtc->pipe);
  2948. }
  2949. static void ironlake_crtc_disable(struct drm_crtc *crtc)
  2950. {
  2951. struct drm_device *dev = crtc->dev;
  2952. struct drm_i915_private *dev_priv = dev->dev_private;
  2953. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2954. struct intel_encoder *encoder;
  2955. int pipe = intel_crtc->pipe;
  2956. int plane = intel_crtc->plane;
  2957. u32 reg, temp;
  2958. if (!intel_crtc->active)
  2959. return;
  2960. for_each_encoder_on_crtc(dev, crtc, encoder)
  2961. encoder->disable(encoder);
  2962. intel_crtc_wait_for_pending_flips(crtc);
  2963. drm_vblank_off(dev, pipe);
  2964. intel_crtc_update_cursor(crtc, false);
  2965. intel_disable_plane(dev_priv, plane, pipe);
  2966. if (dev_priv->cfb_plane == plane)
  2967. intel_disable_fbc(dev);
  2968. intel_disable_pipe(dev_priv, pipe);
  2969. /* Disable PF */
  2970. I915_WRITE(PF_CTL(pipe), 0);
  2971. I915_WRITE(PF_WIN_SZ(pipe), 0);
  2972. for_each_encoder_on_crtc(dev, crtc, encoder)
  2973. if (encoder->post_disable)
  2974. encoder->post_disable(encoder);
  2975. ironlake_fdi_disable(crtc);
  2976. ironlake_disable_pch_transcoder(dev_priv, pipe);
  2977. if (HAS_PCH_CPT(dev)) {
  2978. /* disable TRANS_DP_CTL */
  2979. reg = TRANS_DP_CTL(pipe);
  2980. temp = I915_READ(reg);
  2981. temp &= ~(TRANS_DP_OUTPUT_ENABLE | TRANS_DP_PORT_SEL_MASK);
  2982. temp |= TRANS_DP_PORT_SEL_NONE;
  2983. I915_WRITE(reg, temp);
  2984. /* disable DPLL_SEL */
  2985. temp = I915_READ(PCH_DPLL_SEL);
  2986. switch (pipe) {
  2987. case 0:
  2988. temp &= ~(TRANSA_DPLL_ENABLE | TRANSA_DPLLB_SEL);
  2989. break;
  2990. case 1:
  2991. temp &= ~(TRANSB_DPLL_ENABLE | TRANSB_DPLLB_SEL);
  2992. break;
  2993. case 2:
  2994. /* C shares PLL A or B */
  2995. temp &= ~(TRANSC_DPLL_ENABLE | TRANSC_DPLLB_SEL);
  2996. break;
  2997. default:
  2998. BUG(); /* wtf */
  2999. }
  3000. I915_WRITE(PCH_DPLL_SEL, temp);
  3001. }
  3002. /* disable PCH DPLL */
  3003. intel_disable_pch_pll(intel_crtc);
  3004. ironlake_fdi_pll_disable(intel_crtc);
  3005. intel_crtc->active = false;
  3006. intel_update_watermarks(dev);
  3007. mutex_lock(&dev->struct_mutex);
  3008. intel_update_fbc(dev);
  3009. mutex_unlock(&dev->struct_mutex);
  3010. }
  3011. static void haswell_crtc_disable(struct drm_crtc *crtc)
  3012. {
  3013. struct drm_device *dev = crtc->dev;
  3014. struct drm_i915_private *dev_priv = dev->dev_private;
  3015. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3016. struct intel_encoder *encoder;
  3017. int pipe = intel_crtc->pipe;
  3018. int plane = intel_crtc->plane;
  3019. enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
  3020. bool is_pch_port;
  3021. if (!intel_crtc->active)
  3022. return;
  3023. is_pch_port = haswell_crtc_driving_pch(crtc);
  3024. for_each_encoder_on_crtc(dev, crtc, encoder)
  3025. encoder->disable(encoder);
  3026. intel_crtc_wait_for_pending_flips(crtc);
  3027. drm_vblank_off(dev, pipe);
  3028. intel_crtc_update_cursor(crtc, false);
  3029. intel_disable_plane(dev_priv, plane, pipe);
  3030. if (dev_priv->cfb_plane == plane)
  3031. intel_disable_fbc(dev);
  3032. intel_disable_pipe(dev_priv, pipe);
  3033. intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder);
  3034. /* Disable PF */
  3035. I915_WRITE(PF_CTL(pipe), 0);
  3036. I915_WRITE(PF_WIN_SZ(pipe), 0);
  3037. intel_ddi_disable_pipe_clock(intel_crtc);
  3038. for_each_encoder_on_crtc(dev, crtc, encoder)
  3039. if (encoder->post_disable)
  3040. encoder->post_disable(encoder);
  3041. if (is_pch_port) {
  3042. lpt_disable_pch_transcoder(dev_priv);
  3043. intel_ddi_fdi_disable(crtc);
  3044. }
  3045. intel_crtc->active = false;
  3046. intel_update_watermarks(dev);
  3047. mutex_lock(&dev->struct_mutex);
  3048. intel_update_fbc(dev);
  3049. mutex_unlock(&dev->struct_mutex);
  3050. }
  3051. static void ironlake_crtc_off(struct drm_crtc *crtc)
  3052. {
  3053. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3054. intel_put_pch_pll(intel_crtc);
  3055. }
  3056. static void haswell_crtc_off(struct drm_crtc *crtc)
  3057. {
  3058. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3059. /* Stop saying we're using TRANSCODER_EDP because some other CRTC might
  3060. * start using it. */
  3061. intel_crtc->cpu_transcoder = (enum transcoder) intel_crtc->pipe;
  3062. intel_ddi_put_crtc_pll(crtc);
  3063. }
  3064. static void intel_crtc_dpms_overlay(struct intel_crtc *intel_crtc, bool enable)
  3065. {
  3066. if (!enable && intel_crtc->overlay) {
  3067. struct drm_device *dev = intel_crtc->base.dev;
  3068. struct drm_i915_private *dev_priv = dev->dev_private;
  3069. mutex_lock(&dev->struct_mutex);
  3070. dev_priv->mm.interruptible = false;
  3071. (void) intel_overlay_switch_off(intel_crtc->overlay);
  3072. dev_priv->mm.interruptible = true;
  3073. mutex_unlock(&dev->struct_mutex);
  3074. }
  3075. /* Let userspace switch the overlay on again. In most cases userspace
  3076. * has to recompute where to put it anyway.
  3077. */
  3078. }
  3079. static void i9xx_crtc_enable(struct drm_crtc *crtc)
  3080. {
  3081. struct drm_device *dev = crtc->dev;
  3082. struct drm_i915_private *dev_priv = dev->dev_private;
  3083. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3084. struct intel_encoder *encoder;
  3085. int pipe = intel_crtc->pipe;
  3086. int plane = intel_crtc->plane;
  3087. WARN_ON(!crtc->enabled);
  3088. if (intel_crtc->active)
  3089. return;
  3090. intel_crtc->active = true;
  3091. intel_update_watermarks(dev);
  3092. intel_enable_pll(dev_priv, pipe);
  3093. intel_enable_pipe(dev_priv, pipe, false);
  3094. intel_enable_plane(dev_priv, plane, pipe);
  3095. intel_crtc_load_lut(crtc);
  3096. intel_update_fbc(dev);
  3097. /* Give the overlay scaler a chance to enable if it's on this pipe */
  3098. intel_crtc_dpms_overlay(intel_crtc, true);
  3099. intel_crtc_update_cursor(crtc, true);
  3100. for_each_encoder_on_crtc(dev, crtc, encoder)
  3101. encoder->enable(encoder);
  3102. }
  3103. static void i9xx_crtc_disable(struct drm_crtc *crtc)
  3104. {
  3105. struct drm_device *dev = crtc->dev;
  3106. struct drm_i915_private *dev_priv = dev->dev_private;
  3107. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3108. struct intel_encoder *encoder;
  3109. int pipe = intel_crtc->pipe;
  3110. int plane = intel_crtc->plane;
  3111. if (!intel_crtc->active)
  3112. return;
  3113. for_each_encoder_on_crtc(dev, crtc, encoder)
  3114. encoder->disable(encoder);
  3115. /* Give the overlay scaler a chance to disable if it's on this pipe */
  3116. intel_crtc_wait_for_pending_flips(crtc);
  3117. drm_vblank_off(dev, pipe);
  3118. intel_crtc_dpms_overlay(intel_crtc, false);
  3119. intel_crtc_update_cursor(crtc, false);
  3120. if (dev_priv->cfb_plane == plane)
  3121. intel_disable_fbc(dev);
  3122. intel_disable_plane(dev_priv, plane, pipe);
  3123. intel_disable_pipe(dev_priv, pipe);
  3124. intel_disable_pll(dev_priv, pipe);
  3125. intel_crtc->active = false;
  3126. intel_update_fbc(dev);
  3127. intel_update_watermarks(dev);
  3128. }
  3129. static void i9xx_crtc_off(struct drm_crtc *crtc)
  3130. {
  3131. }
  3132. static void intel_crtc_update_sarea(struct drm_crtc *crtc,
  3133. bool enabled)
  3134. {
  3135. struct drm_device *dev = crtc->dev;
  3136. struct drm_i915_master_private *master_priv;
  3137. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3138. int pipe = intel_crtc->pipe;
  3139. if (!dev->primary->master)
  3140. return;
  3141. master_priv = dev->primary->master->driver_priv;
  3142. if (!master_priv->sarea_priv)
  3143. return;
  3144. switch (pipe) {
  3145. case 0:
  3146. master_priv->sarea_priv->pipeA_w = enabled ? crtc->mode.hdisplay : 0;
  3147. master_priv->sarea_priv->pipeA_h = enabled ? crtc->mode.vdisplay : 0;
  3148. break;
  3149. case 1:
  3150. master_priv->sarea_priv->pipeB_w = enabled ? crtc->mode.hdisplay : 0;
  3151. master_priv->sarea_priv->pipeB_h = enabled ? crtc->mode.vdisplay : 0;
  3152. break;
  3153. default:
  3154. DRM_ERROR("Can't update pipe %c in SAREA\n", pipe_name(pipe));
  3155. break;
  3156. }
  3157. }
  3158. /**
  3159. * Sets the power management mode of the pipe and plane.
  3160. */
  3161. void intel_crtc_update_dpms(struct drm_crtc *crtc)
  3162. {
  3163. struct drm_device *dev = crtc->dev;
  3164. struct drm_i915_private *dev_priv = dev->dev_private;
  3165. struct intel_encoder *intel_encoder;
  3166. bool enable = false;
  3167. for_each_encoder_on_crtc(dev, crtc, intel_encoder)
  3168. enable |= intel_encoder->connectors_active;
  3169. if (enable)
  3170. dev_priv->display.crtc_enable(crtc);
  3171. else
  3172. dev_priv->display.crtc_disable(crtc);
  3173. intel_crtc_update_sarea(crtc, enable);
  3174. }
  3175. static void intel_crtc_noop(struct drm_crtc *crtc)
  3176. {
  3177. }
  3178. static void intel_crtc_disable(struct drm_crtc *crtc)
  3179. {
  3180. struct drm_device *dev = crtc->dev;
  3181. struct drm_connector *connector;
  3182. struct drm_i915_private *dev_priv = dev->dev_private;
  3183. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3184. /* crtc should still be enabled when we disable it. */
  3185. WARN_ON(!crtc->enabled);
  3186. intel_crtc->eld_vld = false;
  3187. dev_priv->display.crtc_disable(crtc);
  3188. intel_crtc_update_sarea(crtc, false);
  3189. dev_priv->display.off(crtc);
  3190. assert_plane_disabled(dev->dev_private, to_intel_crtc(crtc)->plane);
  3191. assert_pipe_disabled(dev->dev_private, to_intel_crtc(crtc)->pipe);
  3192. if (crtc->fb) {
  3193. mutex_lock(&dev->struct_mutex);
  3194. intel_unpin_fb_obj(to_intel_framebuffer(crtc->fb)->obj);
  3195. mutex_unlock(&dev->struct_mutex);
  3196. crtc->fb = NULL;
  3197. }
  3198. /* Update computed state. */
  3199. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  3200. if (!connector->encoder || !connector->encoder->crtc)
  3201. continue;
  3202. if (connector->encoder->crtc != crtc)
  3203. continue;
  3204. connector->dpms = DRM_MODE_DPMS_OFF;
  3205. to_intel_encoder(connector->encoder)->connectors_active = false;
  3206. }
  3207. }
  3208. void intel_modeset_disable(struct drm_device *dev)
  3209. {
  3210. struct drm_crtc *crtc;
  3211. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  3212. if (crtc->enabled)
  3213. intel_crtc_disable(crtc);
  3214. }
  3215. }
  3216. void intel_encoder_noop(struct drm_encoder *encoder)
  3217. {
  3218. }
  3219. void intel_encoder_destroy(struct drm_encoder *encoder)
  3220. {
  3221. struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
  3222. drm_encoder_cleanup(encoder);
  3223. kfree(intel_encoder);
  3224. }
  3225. /* Simple dpms helper for encodres with just one connector, no cloning and only
  3226. * one kind of off state. It clamps all !ON modes to fully OFF and changes the
  3227. * state of the entire output pipe. */
  3228. void intel_encoder_dpms(struct intel_encoder *encoder, int mode)
  3229. {
  3230. if (mode == DRM_MODE_DPMS_ON) {
  3231. encoder->connectors_active = true;
  3232. intel_crtc_update_dpms(encoder->base.crtc);
  3233. } else {
  3234. encoder->connectors_active = false;
  3235. intel_crtc_update_dpms(encoder->base.crtc);
  3236. }
  3237. }
  3238. /* Cross check the actual hw state with our own modeset state tracking (and it's
  3239. * internal consistency). */
  3240. static void intel_connector_check_state(struct intel_connector *connector)
  3241. {
  3242. if (connector->get_hw_state(connector)) {
  3243. struct intel_encoder *encoder = connector->encoder;
  3244. struct drm_crtc *crtc;
  3245. bool encoder_enabled;
  3246. enum pipe pipe;
  3247. DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
  3248. connector->base.base.id,
  3249. drm_get_connector_name(&connector->base));
  3250. WARN(connector->base.dpms == DRM_MODE_DPMS_OFF,
  3251. "wrong connector dpms state\n");
  3252. WARN(connector->base.encoder != &encoder->base,
  3253. "active connector not linked to encoder\n");
  3254. WARN(!encoder->connectors_active,
  3255. "encoder->connectors_active not set\n");
  3256. encoder_enabled = encoder->get_hw_state(encoder, &pipe);
  3257. WARN(!encoder_enabled, "encoder not enabled\n");
  3258. if (WARN_ON(!encoder->base.crtc))
  3259. return;
  3260. crtc = encoder->base.crtc;
  3261. WARN(!crtc->enabled, "crtc not enabled\n");
  3262. WARN(!to_intel_crtc(crtc)->active, "crtc not active\n");
  3263. WARN(pipe != to_intel_crtc(crtc)->pipe,
  3264. "encoder active on the wrong pipe\n");
  3265. }
  3266. }
  3267. /* Even simpler default implementation, if there's really no special case to
  3268. * consider. */
  3269. void intel_connector_dpms(struct drm_connector *connector, int mode)
  3270. {
  3271. struct intel_encoder *encoder = intel_attached_encoder(connector);
  3272. /* All the simple cases only support two dpms states. */
  3273. if (mode != DRM_MODE_DPMS_ON)
  3274. mode = DRM_MODE_DPMS_OFF;
  3275. if (mode == connector->dpms)
  3276. return;
  3277. connector->dpms = mode;
  3278. /* Only need to change hw state when actually enabled */
  3279. if (encoder->base.crtc)
  3280. intel_encoder_dpms(encoder, mode);
  3281. else
  3282. WARN_ON(encoder->connectors_active != false);
  3283. intel_modeset_check_state(connector->dev);
  3284. }
  3285. /* Simple connector->get_hw_state implementation for encoders that support only
  3286. * one connector and no cloning and hence the encoder state determines the state
  3287. * of the connector. */
  3288. bool intel_connector_get_hw_state(struct intel_connector *connector)
  3289. {
  3290. enum pipe pipe = 0;
  3291. struct intel_encoder *encoder = connector->encoder;
  3292. return encoder->get_hw_state(encoder, &pipe);
  3293. }
  3294. static bool intel_crtc_mode_fixup(struct drm_crtc *crtc,
  3295. const struct drm_display_mode *mode,
  3296. struct drm_display_mode *adjusted_mode)
  3297. {
  3298. struct drm_device *dev = crtc->dev;
  3299. if (HAS_PCH_SPLIT(dev)) {
  3300. /* FDI link clock is fixed at 2.7G */
  3301. if (mode->clock * 3 > IRONLAKE_FDI_FREQ * 4)
  3302. return false;
  3303. }
  3304. /* All interlaced capable intel hw wants timings in frames. Note though
  3305. * that intel_lvds_mode_fixup does some funny tricks with the crtc
  3306. * timings, so we need to be careful not to clobber these.*/
  3307. if (!(adjusted_mode->private_flags & INTEL_MODE_CRTC_TIMINGS_SET))
  3308. drm_mode_set_crtcinfo(adjusted_mode, 0);
  3309. /* WaPruneModeWithIncorrectHsyncOffset: Cantiga+ cannot handle modes
  3310. * with a hsync front porch of 0.
  3311. */
  3312. if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) &&
  3313. adjusted_mode->hsync_start == adjusted_mode->hdisplay)
  3314. return false;
  3315. return true;
  3316. }
  3317. static int valleyview_get_display_clock_speed(struct drm_device *dev)
  3318. {
  3319. return 400000; /* FIXME */
  3320. }
  3321. static int i945_get_display_clock_speed(struct drm_device *dev)
  3322. {
  3323. return 400000;
  3324. }
  3325. static int i915_get_display_clock_speed(struct drm_device *dev)
  3326. {
  3327. return 333000;
  3328. }
  3329. static int i9xx_misc_get_display_clock_speed(struct drm_device *dev)
  3330. {
  3331. return 200000;
  3332. }
  3333. static int i915gm_get_display_clock_speed(struct drm_device *dev)
  3334. {
  3335. u16 gcfgc = 0;
  3336. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  3337. if (gcfgc & GC_LOW_FREQUENCY_ENABLE)
  3338. return 133000;
  3339. else {
  3340. switch (gcfgc & GC_DISPLAY_CLOCK_MASK) {
  3341. case GC_DISPLAY_CLOCK_333_MHZ:
  3342. return 333000;
  3343. default:
  3344. case GC_DISPLAY_CLOCK_190_200_MHZ:
  3345. return 190000;
  3346. }
  3347. }
  3348. }
  3349. static int i865_get_display_clock_speed(struct drm_device *dev)
  3350. {
  3351. return 266000;
  3352. }
  3353. static int i855_get_display_clock_speed(struct drm_device *dev)
  3354. {
  3355. u16 hpllcc = 0;
  3356. /* Assume that the hardware is in the high speed state. This
  3357. * should be the default.
  3358. */
  3359. switch (hpllcc & GC_CLOCK_CONTROL_MASK) {
  3360. case GC_CLOCK_133_200:
  3361. case GC_CLOCK_100_200:
  3362. return 200000;
  3363. case GC_CLOCK_166_250:
  3364. return 250000;
  3365. case GC_CLOCK_100_133:
  3366. return 133000;
  3367. }
  3368. /* Shouldn't happen */
  3369. return 0;
  3370. }
  3371. static int i830_get_display_clock_speed(struct drm_device *dev)
  3372. {
  3373. return 133000;
  3374. }
  3375. static void
  3376. intel_reduce_ratio(uint32_t *num, uint32_t *den)
  3377. {
  3378. while (*num > 0xffffff || *den > 0xffffff) {
  3379. *num >>= 1;
  3380. *den >>= 1;
  3381. }
  3382. }
  3383. void
  3384. intel_link_compute_m_n(int bits_per_pixel, int nlanes,
  3385. int pixel_clock, int link_clock,
  3386. struct intel_link_m_n *m_n)
  3387. {
  3388. m_n->tu = 64;
  3389. m_n->gmch_m = bits_per_pixel * pixel_clock;
  3390. m_n->gmch_n = link_clock * nlanes * 8;
  3391. intel_reduce_ratio(&m_n->gmch_m, &m_n->gmch_n);
  3392. m_n->link_m = pixel_clock;
  3393. m_n->link_n = link_clock;
  3394. intel_reduce_ratio(&m_n->link_m, &m_n->link_n);
  3395. }
  3396. static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
  3397. {
  3398. if (i915_panel_use_ssc >= 0)
  3399. return i915_panel_use_ssc != 0;
  3400. return dev_priv->lvds_use_ssc
  3401. && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
  3402. }
  3403. /**
  3404. * intel_choose_pipe_bpp_dither - figure out what color depth the pipe should send
  3405. * @crtc: CRTC structure
  3406. * @mode: requested mode
  3407. *
  3408. * A pipe may be connected to one or more outputs. Based on the depth of the
  3409. * attached framebuffer, choose a good color depth to use on the pipe.
  3410. *
  3411. * If possible, match the pipe depth to the fb depth. In some cases, this
  3412. * isn't ideal, because the connected output supports a lesser or restricted
  3413. * set of depths. Resolve that here:
  3414. * LVDS typically supports only 6bpc, so clamp down in that case
  3415. * HDMI supports only 8bpc or 12bpc, so clamp to 8bpc with dither for 10bpc
  3416. * Displays may support a restricted set as well, check EDID and clamp as
  3417. * appropriate.
  3418. * DP may want to dither down to 6bpc to fit larger modes
  3419. *
  3420. * RETURNS:
  3421. * Dithering requirement (i.e. false if display bpc and pipe bpc match,
  3422. * true if they don't match).
  3423. */
  3424. static bool intel_choose_pipe_bpp_dither(struct drm_crtc *crtc,
  3425. struct drm_framebuffer *fb,
  3426. unsigned int *pipe_bpp,
  3427. struct drm_display_mode *mode)
  3428. {
  3429. struct drm_device *dev = crtc->dev;
  3430. struct drm_i915_private *dev_priv = dev->dev_private;
  3431. struct drm_connector *connector;
  3432. struct intel_encoder *intel_encoder;
  3433. unsigned int display_bpc = UINT_MAX, bpc;
  3434. /* Walk the encoders & connectors on this crtc, get min bpc */
  3435. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  3436. if (intel_encoder->type == INTEL_OUTPUT_LVDS) {
  3437. unsigned int lvds_bpc;
  3438. if ((I915_READ(PCH_LVDS) & LVDS_A3_POWER_MASK) ==
  3439. LVDS_A3_POWER_UP)
  3440. lvds_bpc = 8;
  3441. else
  3442. lvds_bpc = 6;
  3443. if (lvds_bpc < display_bpc) {
  3444. DRM_DEBUG_KMS("clamping display bpc (was %d) to LVDS (%d)\n", display_bpc, lvds_bpc);
  3445. display_bpc = lvds_bpc;
  3446. }
  3447. continue;
  3448. }
  3449. /* Not one of the known troublemakers, check the EDID */
  3450. list_for_each_entry(connector, &dev->mode_config.connector_list,
  3451. head) {
  3452. if (connector->encoder != &intel_encoder->base)
  3453. continue;
  3454. /* Don't use an invalid EDID bpc value */
  3455. if (connector->display_info.bpc &&
  3456. connector->display_info.bpc < display_bpc) {
  3457. DRM_DEBUG_KMS("clamping display bpc (was %d) to EDID reported max of %d\n", display_bpc, connector->display_info.bpc);
  3458. display_bpc = connector->display_info.bpc;
  3459. }
  3460. }
  3461. if (intel_encoder->type == INTEL_OUTPUT_EDP) {
  3462. /* Use VBT settings if we have an eDP panel */
  3463. unsigned int edp_bpc = dev_priv->edp.bpp / 3;
  3464. if (edp_bpc && edp_bpc < display_bpc) {
  3465. DRM_DEBUG_KMS("clamping display bpc (was %d) to eDP (%d)\n", display_bpc, edp_bpc);
  3466. display_bpc = edp_bpc;
  3467. }
  3468. continue;
  3469. }
  3470. /*
  3471. * HDMI is either 12 or 8, so if the display lets 10bpc sneak
  3472. * through, clamp it down. (Note: >12bpc will be caught below.)
  3473. */
  3474. if (intel_encoder->type == INTEL_OUTPUT_HDMI) {
  3475. if (display_bpc > 8 && display_bpc < 12) {
  3476. DRM_DEBUG_KMS("forcing bpc to 12 for HDMI\n");
  3477. display_bpc = 12;
  3478. } else {
  3479. DRM_DEBUG_KMS("forcing bpc to 8 for HDMI\n");
  3480. display_bpc = 8;
  3481. }
  3482. }
  3483. }
  3484. if (mode->private_flags & INTEL_MODE_DP_FORCE_6BPC) {
  3485. DRM_DEBUG_KMS("Dithering DP to 6bpc\n");
  3486. display_bpc = 6;
  3487. }
  3488. /*
  3489. * We could just drive the pipe at the highest bpc all the time and
  3490. * enable dithering as needed, but that costs bandwidth. So choose
  3491. * the minimum value that expresses the full color range of the fb but
  3492. * also stays within the max display bpc discovered above.
  3493. */
  3494. switch (fb->depth) {
  3495. case 8:
  3496. bpc = 8; /* since we go through a colormap */
  3497. break;
  3498. case 15:
  3499. case 16:
  3500. bpc = 6; /* min is 18bpp */
  3501. break;
  3502. case 24:
  3503. bpc = 8;
  3504. break;
  3505. case 30:
  3506. bpc = 10;
  3507. break;
  3508. case 48:
  3509. bpc = 12;
  3510. break;
  3511. default:
  3512. DRM_DEBUG("unsupported depth, assuming 24 bits\n");
  3513. bpc = min((unsigned int)8, display_bpc);
  3514. break;
  3515. }
  3516. display_bpc = min(display_bpc, bpc);
  3517. DRM_DEBUG_KMS("setting pipe bpc to %d (max display bpc %d)\n",
  3518. bpc, display_bpc);
  3519. *pipe_bpp = display_bpc * 3;
  3520. return display_bpc != bpc;
  3521. }
  3522. static int vlv_get_refclk(struct drm_crtc *crtc)
  3523. {
  3524. struct drm_device *dev = crtc->dev;
  3525. struct drm_i915_private *dev_priv = dev->dev_private;
  3526. int refclk = 27000; /* for DP & HDMI */
  3527. return 100000; /* only one validated so far */
  3528. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG)) {
  3529. refclk = 96000;
  3530. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  3531. if (intel_panel_use_ssc(dev_priv))
  3532. refclk = 100000;
  3533. else
  3534. refclk = 96000;
  3535. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) {
  3536. refclk = 100000;
  3537. }
  3538. return refclk;
  3539. }
  3540. static int i9xx_get_refclk(struct drm_crtc *crtc, int num_connectors)
  3541. {
  3542. struct drm_device *dev = crtc->dev;
  3543. struct drm_i915_private *dev_priv = dev->dev_private;
  3544. int refclk;
  3545. if (IS_VALLEYVIEW(dev)) {
  3546. refclk = vlv_get_refclk(crtc);
  3547. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
  3548. intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
  3549. refclk = dev_priv->lvds_ssc_freq * 1000;
  3550. DRM_DEBUG_KMS("using SSC reference clock of %d MHz\n",
  3551. refclk / 1000);
  3552. } else if (!IS_GEN2(dev)) {
  3553. refclk = 96000;
  3554. } else {
  3555. refclk = 48000;
  3556. }
  3557. return refclk;
  3558. }
  3559. static void i9xx_adjust_sdvo_tv_clock(struct drm_display_mode *adjusted_mode,
  3560. intel_clock_t *clock)
  3561. {
  3562. /* SDVO TV has fixed PLL values depend on its clock range,
  3563. this mirrors vbios setting. */
  3564. if (adjusted_mode->clock >= 100000
  3565. && adjusted_mode->clock < 140500) {
  3566. clock->p1 = 2;
  3567. clock->p2 = 10;
  3568. clock->n = 3;
  3569. clock->m1 = 16;
  3570. clock->m2 = 8;
  3571. } else if (adjusted_mode->clock >= 140500
  3572. && adjusted_mode->clock <= 200000) {
  3573. clock->p1 = 1;
  3574. clock->p2 = 10;
  3575. clock->n = 6;
  3576. clock->m1 = 12;
  3577. clock->m2 = 8;
  3578. }
  3579. }
  3580. static void i9xx_update_pll_dividers(struct drm_crtc *crtc,
  3581. intel_clock_t *clock,
  3582. intel_clock_t *reduced_clock)
  3583. {
  3584. struct drm_device *dev = crtc->dev;
  3585. struct drm_i915_private *dev_priv = dev->dev_private;
  3586. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3587. int pipe = intel_crtc->pipe;
  3588. u32 fp, fp2 = 0;
  3589. if (IS_PINEVIEW(dev)) {
  3590. fp = (1 << clock->n) << 16 | clock->m1 << 8 | clock->m2;
  3591. if (reduced_clock)
  3592. fp2 = (1 << reduced_clock->n) << 16 |
  3593. reduced_clock->m1 << 8 | reduced_clock->m2;
  3594. } else {
  3595. fp = clock->n << 16 | clock->m1 << 8 | clock->m2;
  3596. if (reduced_clock)
  3597. fp2 = reduced_clock->n << 16 | reduced_clock->m1 << 8 |
  3598. reduced_clock->m2;
  3599. }
  3600. I915_WRITE(FP0(pipe), fp);
  3601. intel_crtc->lowfreq_avail = false;
  3602. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
  3603. reduced_clock && i915_powersave) {
  3604. I915_WRITE(FP1(pipe), fp2);
  3605. intel_crtc->lowfreq_avail = true;
  3606. } else {
  3607. I915_WRITE(FP1(pipe), fp);
  3608. }
  3609. }
  3610. static void vlv_update_pll(struct drm_crtc *crtc,
  3611. struct drm_display_mode *mode,
  3612. struct drm_display_mode *adjusted_mode,
  3613. intel_clock_t *clock, intel_clock_t *reduced_clock,
  3614. int num_connectors)
  3615. {
  3616. struct drm_device *dev = crtc->dev;
  3617. struct drm_i915_private *dev_priv = dev->dev_private;
  3618. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3619. int pipe = intel_crtc->pipe;
  3620. u32 dpll, mdiv, pdiv;
  3621. u32 bestn, bestm1, bestm2, bestp1, bestp2;
  3622. bool is_sdvo;
  3623. u32 temp;
  3624. mutex_lock(&dev_priv->dpio_lock);
  3625. is_sdvo = intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO) ||
  3626. intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI);
  3627. dpll = DPLL_VGA_MODE_DIS;
  3628. dpll |= DPLL_EXT_BUFFER_ENABLE_VLV;
  3629. dpll |= DPLL_REFA_CLK_ENABLE_VLV;
  3630. dpll |= DPLL_INTEGRATED_CLOCK_VLV;
  3631. I915_WRITE(DPLL(pipe), dpll);
  3632. POSTING_READ(DPLL(pipe));
  3633. bestn = clock->n;
  3634. bestm1 = clock->m1;
  3635. bestm2 = clock->m2;
  3636. bestp1 = clock->p1;
  3637. bestp2 = clock->p2;
  3638. /*
  3639. * In Valleyview PLL and program lane counter registers are exposed
  3640. * through DPIO interface
  3641. */
  3642. mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
  3643. mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
  3644. mdiv |= ((bestn << DPIO_N_SHIFT));
  3645. mdiv |= (1 << DPIO_POST_DIV_SHIFT);
  3646. mdiv |= (1 << DPIO_K_SHIFT);
  3647. mdiv |= DPIO_ENABLE_CALIBRATION;
  3648. intel_dpio_write(dev_priv, DPIO_DIV(pipe), mdiv);
  3649. intel_dpio_write(dev_priv, DPIO_CORE_CLK(pipe), 0x01000000);
  3650. pdiv = (1 << DPIO_REFSEL_OVERRIDE) | (5 << DPIO_PLL_MODESEL_SHIFT) |
  3651. (3 << DPIO_BIAS_CURRENT_CTL_SHIFT) | (1<<20) |
  3652. (7 << DPIO_PLL_REFCLK_SEL_SHIFT) | (8 << DPIO_DRIVER_CTL_SHIFT) |
  3653. (5 << DPIO_CLK_BIAS_CTL_SHIFT);
  3654. intel_dpio_write(dev_priv, DPIO_REFSFR(pipe), pdiv);
  3655. intel_dpio_write(dev_priv, DPIO_LFP_COEFF(pipe), 0x005f003b);
  3656. dpll |= DPLL_VCO_ENABLE;
  3657. I915_WRITE(DPLL(pipe), dpll);
  3658. POSTING_READ(DPLL(pipe));
  3659. if (wait_for(((I915_READ(DPLL(pipe)) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1))
  3660. DRM_ERROR("DPLL %d failed to lock\n", pipe);
  3661. intel_dpio_write(dev_priv, DPIO_FASTCLK_DISABLE, 0x620);
  3662. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT))
  3663. intel_dp_set_m_n(crtc, mode, adjusted_mode);
  3664. I915_WRITE(DPLL(pipe), dpll);
  3665. /* Wait for the clocks to stabilize. */
  3666. POSTING_READ(DPLL(pipe));
  3667. udelay(150);
  3668. temp = 0;
  3669. if (is_sdvo) {
  3670. temp = intel_mode_get_pixel_multiplier(adjusted_mode);
  3671. if (temp > 1)
  3672. temp = (temp - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  3673. else
  3674. temp = 0;
  3675. }
  3676. I915_WRITE(DPLL_MD(pipe), temp);
  3677. POSTING_READ(DPLL_MD(pipe));
  3678. /* Now program lane control registers */
  3679. if(intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)
  3680. || intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI))
  3681. {
  3682. temp = 0x1000C4;
  3683. if(pipe == 1)
  3684. temp |= (1 << 21);
  3685. intel_dpio_write(dev_priv, DPIO_DATA_CHANNEL1, temp);
  3686. }
  3687. if(intel_pipe_has_type(crtc,INTEL_OUTPUT_EDP))
  3688. {
  3689. temp = 0x1000C4;
  3690. if(pipe == 1)
  3691. temp |= (1 << 21);
  3692. intel_dpio_write(dev_priv, DPIO_DATA_CHANNEL2, temp);
  3693. }
  3694. mutex_unlock(&dev_priv->dpio_lock);
  3695. }
  3696. static void i9xx_update_pll(struct drm_crtc *crtc,
  3697. struct drm_display_mode *mode,
  3698. struct drm_display_mode *adjusted_mode,
  3699. intel_clock_t *clock, intel_clock_t *reduced_clock,
  3700. int num_connectors)
  3701. {
  3702. struct drm_device *dev = crtc->dev;
  3703. struct drm_i915_private *dev_priv = dev->dev_private;
  3704. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3705. struct intel_encoder *encoder;
  3706. int pipe = intel_crtc->pipe;
  3707. u32 dpll;
  3708. bool is_sdvo;
  3709. i9xx_update_pll_dividers(crtc, clock, reduced_clock);
  3710. is_sdvo = intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO) ||
  3711. intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI);
  3712. dpll = DPLL_VGA_MODE_DIS;
  3713. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  3714. dpll |= DPLLB_MODE_LVDS;
  3715. else
  3716. dpll |= DPLLB_MODE_DAC_SERIAL;
  3717. if (is_sdvo) {
  3718. int pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
  3719. if (pixel_multiplier > 1) {
  3720. if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev))
  3721. dpll |= (pixel_multiplier - 1) << SDVO_MULTIPLIER_SHIFT_HIRES;
  3722. }
  3723. dpll |= DPLL_DVO_HIGH_SPEED;
  3724. }
  3725. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT))
  3726. dpll |= DPLL_DVO_HIGH_SPEED;
  3727. /* compute bitmask from p1 value */
  3728. if (IS_PINEVIEW(dev))
  3729. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
  3730. else {
  3731. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  3732. if (IS_G4X(dev) && reduced_clock)
  3733. dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  3734. }
  3735. switch (clock->p2) {
  3736. case 5:
  3737. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
  3738. break;
  3739. case 7:
  3740. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
  3741. break;
  3742. case 10:
  3743. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
  3744. break;
  3745. case 14:
  3746. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
  3747. break;
  3748. }
  3749. if (INTEL_INFO(dev)->gen >= 4)
  3750. dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
  3751. if (is_sdvo && intel_pipe_has_type(crtc, INTEL_OUTPUT_TVOUT))
  3752. dpll |= PLL_REF_INPUT_TVCLKINBC;
  3753. else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_TVOUT))
  3754. /* XXX: just matching BIOS for now */
  3755. /* dpll |= PLL_REF_INPUT_TVCLKINBC; */
  3756. dpll |= 3;
  3757. else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
  3758. intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  3759. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  3760. else
  3761. dpll |= PLL_REF_INPUT_DREFCLK;
  3762. dpll |= DPLL_VCO_ENABLE;
  3763. I915_WRITE(DPLL(pipe), dpll & ~DPLL_VCO_ENABLE);
  3764. POSTING_READ(DPLL(pipe));
  3765. udelay(150);
  3766. for_each_encoder_on_crtc(dev, crtc, encoder)
  3767. if (encoder->pre_pll_enable)
  3768. encoder->pre_pll_enable(encoder);
  3769. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT))
  3770. intel_dp_set_m_n(crtc, mode, adjusted_mode);
  3771. I915_WRITE(DPLL(pipe), dpll);
  3772. /* Wait for the clocks to stabilize. */
  3773. POSTING_READ(DPLL(pipe));
  3774. udelay(150);
  3775. if (INTEL_INFO(dev)->gen >= 4) {
  3776. u32 temp = 0;
  3777. if (is_sdvo) {
  3778. temp = intel_mode_get_pixel_multiplier(adjusted_mode);
  3779. if (temp > 1)
  3780. temp = (temp - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  3781. else
  3782. temp = 0;
  3783. }
  3784. I915_WRITE(DPLL_MD(pipe), temp);
  3785. } else {
  3786. /* The pixel multiplier can only be updated once the
  3787. * DPLL is enabled and the clocks are stable.
  3788. *
  3789. * So write it again.
  3790. */
  3791. I915_WRITE(DPLL(pipe), dpll);
  3792. }
  3793. }
  3794. static void i8xx_update_pll(struct drm_crtc *crtc,
  3795. struct drm_display_mode *adjusted_mode,
  3796. intel_clock_t *clock, intel_clock_t *reduced_clock,
  3797. int num_connectors)
  3798. {
  3799. struct drm_device *dev = crtc->dev;
  3800. struct drm_i915_private *dev_priv = dev->dev_private;
  3801. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3802. struct intel_encoder *encoder;
  3803. int pipe = intel_crtc->pipe;
  3804. u32 dpll;
  3805. i9xx_update_pll_dividers(crtc, clock, reduced_clock);
  3806. dpll = DPLL_VGA_MODE_DIS;
  3807. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  3808. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  3809. } else {
  3810. if (clock->p1 == 2)
  3811. dpll |= PLL_P1_DIVIDE_BY_TWO;
  3812. else
  3813. dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  3814. if (clock->p2 == 4)
  3815. dpll |= PLL_P2_DIVIDE_BY_4;
  3816. }
  3817. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_TVOUT))
  3818. /* XXX: just matching BIOS for now */
  3819. /* dpll |= PLL_REF_INPUT_TVCLKINBC; */
  3820. dpll |= 3;
  3821. else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
  3822. intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  3823. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  3824. else
  3825. dpll |= PLL_REF_INPUT_DREFCLK;
  3826. dpll |= DPLL_VCO_ENABLE;
  3827. I915_WRITE(DPLL(pipe), dpll & ~DPLL_VCO_ENABLE);
  3828. POSTING_READ(DPLL(pipe));
  3829. udelay(150);
  3830. for_each_encoder_on_crtc(dev, crtc, encoder)
  3831. if (encoder->pre_pll_enable)
  3832. encoder->pre_pll_enable(encoder);
  3833. I915_WRITE(DPLL(pipe), dpll);
  3834. /* Wait for the clocks to stabilize. */
  3835. POSTING_READ(DPLL(pipe));
  3836. udelay(150);
  3837. /* The pixel multiplier can only be updated once the
  3838. * DPLL is enabled and the clocks are stable.
  3839. *
  3840. * So write it again.
  3841. */
  3842. I915_WRITE(DPLL(pipe), dpll);
  3843. }
  3844. static void intel_set_pipe_timings(struct intel_crtc *intel_crtc,
  3845. struct drm_display_mode *mode,
  3846. struct drm_display_mode *adjusted_mode)
  3847. {
  3848. struct drm_device *dev = intel_crtc->base.dev;
  3849. struct drm_i915_private *dev_priv = dev->dev_private;
  3850. enum pipe pipe = intel_crtc->pipe;
  3851. enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
  3852. uint32_t vsyncshift;
  3853. if (!IS_GEN2(dev) && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
  3854. /* the chip adds 2 halflines automatically */
  3855. adjusted_mode->crtc_vtotal -= 1;
  3856. adjusted_mode->crtc_vblank_end -= 1;
  3857. vsyncshift = adjusted_mode->crtc_hsync_start
  3858. - adjusted_mode->crtc_htotal / 2;
  3859. } else {
  3860. vsyncshift = 0;
  3861. }
  3862. if (INTEL_INFO(dev)->gen > 3)
  3863. I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift);
  3864. I915_WRITE(HTOTAL(cpu_transcoder),
  3865. (adjusted_mode->crtc_hdisplay - 1) |
  3866. ((adjusted_mode->crtc_htotal - 1) << 16));
  3867. I915_WRITE(HBLANK(cpu_transcoder),
  3868. (adjusted_mode->crtc_hblank_start - 1) |
  3869. ((adjusted_mode->crtc_hblank_end - 1) << 16));
  3870. I915_WRITE(HSYNC(cpu_transcoder),
  3871. (adjusted_mode->crtc_hsync_start - 1) |
  3872. ((adjusted_mode->crtc_hsync_end - 1) << 16));
  3873. I915_WRITE(VTOTAL(cpu_transcoder),
  3874. (adjusted_mode->crtc_vdisplay - 1) |
  3875. ((adjusted_mode->crtc_vtotal - 1) << 16));
  3876. I915_WRITE(VBLANK(cpu_transcoder),
  3877. (adjusted_mode->crtc_vblank_start - 1) |
  3878. ((adjusted_mode->crtc_vblank_end - 1) << 16));
  3879. I915_WRITE(VSYNC(cpu_transcoder),
  3880. (adjusted_mode->crtc_vsync_start - 1) |
  3881. ((adjusted_mode->crtc_vsync_end - 1) << 16));
  3882. /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
  3883. * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
  3884. * documented on the DDI_FUNC_CTL register description, EDP Input Select
  3885. * bits. */
  3886. if (IS_HASWELL(dev) && cpu_transcoder == TRANSCODER_EDP &&
  3887. (pipe == PIPE_B || pipe == PIPE_C))
  3888. I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder)));
  3889. /* pipesrc controls the size that is scaled from, which should
  3890. * always be the user's requested size.
  3891. */
  3892. I915_WRITE(PIPESRC(pipe),
  3893. ((mode->hdisplay - 1) << 16) | (mode->vdisplay - 1));
  3894. }
  3895. static int i9xx_crtc_mode_set(struct drm_crtc *crtc,
  3896. struct drm_display_mode *mode,
  3897. struct drm_display_mode *adjusted_mode,
  3898. int x, int y,
  3899. struct drm_framebuffer *fb)
  3900. {
  3901. struct drm_device *dev = crtc->dev;
  3902. struct drm_i915_private *dev_priv = dev->dev_private;
  3903. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3904. int pipe = intel_crtc->pipe;
  3905. int plane = intel_crtc->plane;
  3906. int refclk, num_connectors = 0;
  3907. intel_clock_t clock, reduced_clock;
  3908. u32 dspcntr, pipeconf;
  3909. bool ok, has_reduced_clock = false, is_sdvo = false;
  3910. bool is_lvds = false, is_tv = false, is_dp = false;
  3911. struct intel_encoder *encoder;
  3912. const intel_limit_t *limit;
  3913. int ret;
  3914. for_each_encoder_on_crtc(dev, crtc, encoder) {
  3915. switch (encoder->type) {
  3916. case INTEL_OUTPUT_LVDS:
  3917. is_lvds = true;
  3918. break;
  3919. case INTEL_OUTPUT_SDVO:
  3920. case INTEL_OUTPUT_HDMI:
  3921. is_sdvo = true;
  3922. if (encoder->needs_tv_clock)
  3923. is_tv = true;
  3924. break;
  3925. case INTEL_OUTPUT_TVOUT:
  3926. is_tv = true;
  3927. break;
  3928. case INTEL_OUTPUT_DISPLAYPORT:
  3929. is_dp = true;
  3930. break;
  3931. }
  3932. num_connectors++;
  3933. }
  3934. refclk = i9xx_get_refclk(crtc, num_connectors);
  3935. /*
  3936. * Returns a set of divisors for the desired target clock with the given
  3937. * refclk, or FALSE. The returned values represent the clock equation:
  3938. * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
  3939. */
  3940. limit = intel_limit(crtc, refclk);
  3941. ok = limit->find_pll(limit, crtc, adjusted_mode->clock, refclk, NULL,
  3942. &clock);
  3943. if (!ok) {
  3944. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  3945. return -EINVAL;
  3946. }
  3947. /* Ensure that the cursor is valid for the new mode before changing... */
  3948. intel_crtc_update_cursor(crtc, true);
  3949. if (is_lvds && dev_priv->lvds_downclock_avail) {
  3950. /*
  3951. * Ensure we match the reduced clock's P to the target clock.
  3952. * If the clocks don't match, we can't switch the display clock
  3953. * by using the FP0/FP1. In such case we will disable the LVDS
  3954. * downclock feature.
  3955. */
  3956. has_reduced_clock = limit->find_pll(limit, crtc,
  3957. dev_priv->lvds_downclock,
  3958. refclk,
  3959. &clock,
  3960. &reduced_clock);
  3961. }
  3962. if (is_sdvo && is_tv)
  3963. i9xx_adjust_sdvo_tv_clock(adjusted_mode, &clock);
  3964. if (IS_GEN2(dev))
  3965. i8xx_update_pll(crtc, adjusted_mode, &clock,
  3966. has_reduced_clock ? &reduced_clock : NULL,
  3967. num_connectors);
  3968. else if (IS_VALLEYVIEW(dev))
  3969. vlv_update_pll(crtc, mode, adjusted_mode, &clock,
  3970. has_reduced_clock ? &reduced_clock : NULL,
  3971. num_connectors);
  3972. else
  3973. i9xx_update_pll(crtc, mode, adjusted_mode, &clock,
  3974. has_reduced_clock ? &reduced_clock : NULL,
  3975. num_connectors);
  3976. /* setup pipeconf */
  3977. pipeconf = I915_READ(PIPECONF(pipe));
  3978. /* Set up the display plane register */
  3979. dspcntr = DISPPLANE_GAMMA_ENABLE;
  3980. if (pipe == 0)
  3981. dspcntr &= ~DISPPLANE_SEL_PIPE_MASK;
  3982. else
  3983. dspcntr |= DISPPLANE_SEL_PIPE_B;
  3984. if (pipe == 0 && INTEL_INFO(dev)->gen < 4) {
  3985. /* Enable pixel doubling when the dot clock is > 90% of the (display)
  3986. * core speed.
  3987. *
  3988. * XXX: No double-wide on 915GM pipe B. Is that the only reason for the
  3989. * pipe == 0 check?
  3990. */
  3991. if (mode->clock >
  3992. dev_priv->display.get_display_clock_speed(dev) * 9 / 10)
  3993. pipeconf |= PIPECONF_DOUBLE_WIDE;
  3994. else
  3995. pipeconf &= ~PIPECONF_DOUBLE_WIDE;
  3996. }
  3997. /* default to 8bpc */
  3998. pipeconf &= ~(PIPECONF_BPC_MASK | PIPECONF_DITHER_EN);
  3999. if (is_dp) {
  4000. if (adjusted_mode->private_flags & INTEL_MODE_DP_FORCE_6BPC) {
  4001. pipeconf |= PIPECONF_6BPC |
  4002. PIPECONF_DITHER_EN |
  4003. PIPECONF_DITHER_TYPE_SP;
  4004. }
  4005. }
  4006. if (IS_VALLEYVIEW(dev) && intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) {
  4007. if (adjusted_mode->private_flags & INTEL_MODE_DP_FORCE_6BPC) {
  4008. pipeconf |= PIPECONF_6BPC |
  4009. PIPECONF_ENABLE |
  4010. I965_PIPECONF_ACTIVE;
  4011. }
  4012. }
  4013. DRM_DEBUG_KMS("Mode for pipe %c:\n", pipe == 0 ? 'A' : 'B');
  4014. drm_mode_debug_printmodeline(mode);
  4015. if (HAS_PIPE_CXSR(dev)) {
  4016. if (intel_crtc->lowfreq_avail) {
  4017. DRM_DEBUG_KMS("enabling CxSR downclocking\n");
  4018. pipeconf |= PIPECONF_CXSR_DOWNCLOCK;
  4019. } else {
  4020. DRM_DEBUG_KMS("disabling CxSR downclocking\n");
  4021. pipeconf &= ~PIPECONF_CXSR_DOWNCLOCK;
  4022. }
  4023. }
  4024. pipeconf &= ~PIPECONF_INTERLACE_MASK;
  4025. if (!IS_GEN2(dev) &&
  4026. adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
  4027. pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
  4028. else
  4029. pipeconf |= PIPECONF_PROGRESSIVE;
  4030. intel_set_pipe_timings(intel_crtc, mode, adjusted_mode);
  4031. /* pipesrc and dspsize control the size that is scaled from,
  4032. * which should always be the user's requested size.
  4033. */
  4034. I915_WRITE(DSPSIZE(plane),
  4035. ((mode->vdisplay - 1) << 16) |
  4036. (mode->hdisplay - 1));
  4037. I915_WRITE(DSPPOS(plane), 0);
  4038. I915_WRITE(PIPECONF(pipe), pipeconf);
  4039. POSTING_READ(PIPECONF(pipe));
  4040. intel_enable_pipe(dev_priv, pipe, false);
  4041. intel_wait_for_vblank(dev, pipe);
  4042. I915_WRITE(DSPCNTR(plane), dspcntr);
  4043. POSTING_READ(DSPCNTR(plane));
  4044. ret = intel_pipe_set_base(crtc, x, y, fb);
  4045. intel_update_watermarks(dev);
  4046. return ret;
  4047. }
  4048. static void ironlake_init_pch_refclk(struct drm_device *dev)
  4049. {
  4050. struct drm_i915_private *dev_priv = dev->dev_private;
  4051. struct drm_mode_config *mode_config = &dev->mode_config;
  4052. struct intel_encoder *encoder;
  4053. u32 temp;
  4054. bool has_lvds = false;
  4055. bool has_cpu_edp = false;
  4056. bool has_pch_edp = false;
  4057. bool has_panel = false;
  4058. bool has_ck505 = false;
  4059. bool can_ssc = false;
  4060. /* We need to take the global config into account */
  4061. list_for_each_entry(encoder, &mode_config->encoder_list,
  4062. base.head) {
  4063. switch (encoder->type) {
  4064. case INTEL_OUTPUT_LVDS:
  4065. has_panel = true;
  4066. has_lvds = true;
  4067. break;
  4068. case INTEL_OUTPUT_EDP:
  4069. has_panel = true;
  4070. if (intel_encoder_is_pch_edp(&encoder->base))
  4071. has_pch_edp = true;
  4072. else
  4073. has_cpu_edp = true;
  4074. break;
  4075. }
  4076. }
  4077. if (HAS_PCH_IBX(dev)) {
  4078. has_ck505 = dev_priv->display_clock_mode;
  4079. can_ssc = has_ck505;
  4080. } else {
  4081. has_ck505 = false;
  4082. can_ssc = true;
  4083. }
  4084. DRM_DEBUG_KMS("has_panel %d has_lvds %d has_pch_edp %d has_cpu_edp %d has_ck505 %d\n",
  4085. has_panel, has_lvds, has_pch_edp, has_cpu_edp,
  4086. has_ck505);
  4087. /* Ironlake: try to setup display ref clock before DPLL
  4088. * enabling. This is only under driver's control after
  4089. * PCH B stepping, previous chipset stepping should be
  4090. * ignoring this setting.
  4091. */
  4092. temp = I915_READ(PCH_DREF_CONTROL);
  4093. /* Always enable nonspread source */
  4094. temp &= ~DREF_NONSPREAD_SOURCE_MASK;
  4095. if (has_ck505)
  4096. temp |= DREF_NONSPREAD_CK505_ENABLE;
  4097. else
  4098. temp |= DREF_NONSPREAD_SOURCE_ENABLE;
  4099. if (has_panel) {
  4100. temp &= ~DREF_SSC_SOURCE_MASK;
  4101. temp |= DREF_SSC_SOURCE_ENABLE;
  4102. /* SSC must be turned on before enabling the CPU output */
  4103. if (intel_panel_use_ssc(dev_priv) && can_ssc) {
  4104. DRM_DEBUG_KMS("Using SSC on panel\n");
  4105. temp |= DREF_SSC1_ENABLE;
  4106. } else
  4107. temp &= ~DREF_SSC1_ENABLE;
  4108. /* Get SSC going before enabling the outputs */
  4109. I915_WRITE(PCH_DREF_CONTROL, temp);
  4110. POSTING_READ(PCH_DREF_CONTROL);
  4111. udelay(200);
  4112. temp &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  4113. /* Enable CPU source on CPU attached eDP */
  4114. if (has_cpu_edp) {
  4115. if (intel_panel_use_ssc(dev_priv) && can_ssc) {
  4116. DRM_DEBUG_KMS("Using SSC on eDP\n");
  4117. temp |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
  4118. }
  4119. else
  4120. temp |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
  4121. } else
  4122. temp |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  4123. I915_WRITE(PCH_DREF_CONTROL, temp);
  4124. POSTING_READ(PCH_DREF_CONTROL);
  4125. udelay(200);
  4126. } else {
  4127. DRM_DEBUG_KMS("Disabling SSC entirely\n");
  4128. temp &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  4129. /* Turn off CPU output */
  4130. temp |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  4131. I915_WRITE(PCH_DREF_CONTROL, temp);
  4132. POSTING_READ(PCH_DREF_CONTROL);
  4133. udelay(200);
  4134. /* Turn off the SSC source */
  4135. temp &= ~DREF_SSC_SOURCE_MASK;
  4136. temp |= DREF_SSC_SOURCE_DISABLE;
  4137. /* Turn off SSC1 */
  4138. temp &= ~ DREF_SSC1_ENABLE;
  4139. I915_WRITE(PCH_DREF_CONTROL, temp);
  4140. POSTING_READ(PCH_DREF_CONTROL);
  4141. udelay(200);
  4142. }
  4143. }
  4144. /* Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O. */
  4145. static void lpt_init_pch_refclk(struct drm_device *dev)
  4146. {
  4147. struct drm_i915_private *dev_priv = dev->dev_private;
  4148. struct drm_mode_config *mode_config = &dev->mode_config;
  4149. struct intel_encoder *encoder;
  4150. bool has_vga = false;
  4151. bool is_sdv = false;
  4152. u32 tmp;
  4153. list_for_each_entry(encoder, &mode_config->encoder_list, base.head) {
  4154. switch (encoder->type) {
  4155. case INTEL_OUTPUT_ANALOG:
  4156. has_vga = true;
  4157. break;
  4158. }
  4159. }
  4160. if (!has_vga)
  4161. return;
  4162. mutex_lock(&dev_priv->dpio_lock);
  4163. /* XXX: Rip out SDV support once Haswell ships for real. */
  4164. if (IS_HASWELL(dev) && (dev->pci_device & 0xFF00) == 0x0C00)
  4165. is_sdv = true;
  4166. tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
  4167. tmp &= ~SBI_SSCCTL_DISABLE;
  4168. tmp |= SBI_SSCCTL_PATHALT;
  4169. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  4170. udelay(24);
  4171. tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
  4172. tmp &= ~SBI_SSCCTL_PATHALT;
  4173. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  4174. if (!is_sdv) {
  4175. tmp = I915_READ(SOUTH_CHICKEN2);
  4176. tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
  4177. I915_WRITE(SOUTH_CHICKEN2, tmp);
  4178. if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2) &
  4179. FDI_MPHY_IOSFSB_RESET_STATUS, 100))
  4180. DRM_ERROR("FDI mPHY reset assert timeout\n");
  4181. tmp = I915_READ(SOUTH_CHICKEN2);
  4182. tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
  4183. I915_WRITE(SOUTH_CHICKEN2, tmp);
  4184. if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2) &
  4185. FDI_MPHY_IOSFSB_RESET_STATUS) == 0,
  4186. 100))
  4187. DRM_ERROR("FDI mPHY reset de-assert timeout\n");
  4188. }
  4189. tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
  4190. tmp &= ~(0xFF << 24);
  4191. tmp |= (0x12 << 24);
  4192. intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
  4193. if (!is_sdv) {
  4194. tmp = intel_sbi_read(dev_priv, 0x808C, SBI_MPHY);
  4195. tmp &= ~(0x3 << 6);
  4196. tmp |= (1 << 6) | (1 << 0);
  4197. intel_sbi_write(dev_priv, 0x808C, tmp, SBI_MPHY);
  4198. }
  4199. if (is_sdv) {
  4200. tmp = intel_sbi_read(dev_priv, 0x800C, SBI_MPHY);
  4201. tmp |= 0x7FFF;
  4202. intel_sbi_write(dev_priv, 0x800C, tmp, SBI_MPHY);
  4203. }
  4204. tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
  4205. tmp |= (1 << 11);
  4206. intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
  4207. tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
  4208. tmp |= (1 << 11);
  4209. intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
  4210. if (is_sdv) {
  4211. tmp = intel_sbi_read(dev_priv, 0x2038, SBI_MPHY);
  4212. tmp |= (0x3F << 24) | (0xF << 20) | (0xF << 16);
  4213. intel_sbi_write(dev_priv, 0x2038, tmp, SBI_MPHY);
  4214. tmp = intel_sbi_read(dev_priv, 0x2138, SBI_MPHY);
  4215. tmp |= (0x3F << 24) | (0xF << 20) | (0xF << 16);
  4216. intel_sbi_write(dev_priv, 0x2138, tmp, SBI_MPHY);
  4217. tmp = intel_sbi_read(dev_priv, 0x203C, SBI_MPHY);
  4218. tmp |= (0x3F << 8);
  4219. intel_sbi_write(dev_priv, 0x203C, tmp, SBI_MPHY);
  4220. tmp = intel_sbi_read(dev_priv, 0x213C, SBI_MPHY);
  4221. tmp |= (0x3F << 8);
  4222. intel_sbi_write(dev_priv, 0x213C, tmp, SBI_MPHY);
  4223. }
  4224. tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
  4225. tmp |= (1 << 24) | (1 << 21) | (1 << 18);
  4226. intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
  4227. tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
  4228. tmp |= (1 << 24) | (1 << 21) | (1 << 18);
  4229. intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
  4230. if (!is_sdv) {
  4231. tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
  4232. tmp &= ~(7 << 13);
  4233. tmp |= (5 << 13);
  4234. intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
  4235. tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
  4236. tmp &= ~(7 << 13);
  4237. tmp |= (5 << 13);
  4238. intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
  4239. }
  4240. tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
  4241. tmp &= ~0xFF;
  4242. tmp |= 0x1C;
  4243. intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
  4244. tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
  4245. tmp &= ~0xFF;
  4246. tmp |= 0x1C;
  4247. intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
  4248. tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
  4249. tmp &= ~(0xFF << 16);
  4250. tmp |= (0x1C << 16);
  4251. intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
  4252. tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
  4253. tmp &= ~(0xFF << 16);
  4254. tmp |= (0x1C << 16);
  4255. intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
  4256. if (!is_sdv) {
  4257. tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
  4258. tmp |= (1 << 27);
  4259. intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
  4260. tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
  4261. tmp |= (1 << 27);
  4262. intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
  4263. tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
  4264. tmp &= ~(0xF << 28);
  4265. tmp |= (4 << 28);
  4266. intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
  4267. tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
  4268. tmp &= ~(0xF << 28);
  4269. tmp |= (4 << 28);
  4270. intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
  4271. }
  4272. /* ULT uses SBI_GEN0, but ULT doesn't have VGA, so we don't care. */
  4273. tmp = intel_sbi_read(dev_priv, SBI_DBUFF0, SBI_ICLK);
  4274. tmp |= SBI_DBUFF0_ENABLE;
  4275. intel_sbi_write(dev_priv, SBI_DBUFF0, tmp, SBI_ICLK);
  4276. mutex_unlock(&dev_priv->dpio_lock);
  4277. }
  4278. /*
  4279. * Initialize reference clocks when the driver loads
  4280. */
  4281. void intel_init_pch_refclk(struct drm_device *dev)
  4282. {
  4283. if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
  4284. ironlake_init_pch_refclk(dev);
  4285. else if (HAS_PCH_LPT(dev))
  4286. lpt_init_pch_refclk(dev);
  4287. }
  4288. static int ironlake_get_refclk(struct drm_crtc *crtc)
  4289. {
  4290. struct drm_device *dev = crtc->dev;
  4291. struct drm_i915_private *dev_priv = dev->dev_private;
  4292. struct intel_encoder *encoder;
  4293. struct intel_encoder *edp_encoder = NULL;
  4294. int num_connectors = 0;
  4295. bool is_lvds = false;
  4296. for_each_encoder_on_crtc(dev, crtc, encoder) {
  4297. switch (encoder->type) {
  4298. case INTEL_OUTPUT_LVDS:
  4299. is_lvds = true;
  4300. break;
  4301. case INTEL_OUTPUT_EDP:
  4302. edp_encoder = encoder;
  4303. break;
  4304. }
  4305. num_connectors++;
  4306. }
  4307. if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
  4308. DRM_DEBUG_KMS("using SSC reference clock of %d MHz\n",
  4309. dev_priv->lvds_ssc_freq);
  4310. return dev_priv->lvds_ssc_freq * 1000;
  4311. }
  4312. return 120000;
  4313. }
  4314. static void ironlake_set_pipeconf(struct drm_crtc *crtc,
  4315. struct drm_display_mode *adjusted_mode,
  4316. bool dither)
  4317. {
  4318. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  4319. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4320. int pipe = intel_crtc->pipe;
  4321. uint32_t val;
  4322. val = I915_READ(PIPECONF(pipe));
  4323. val &= ~PIPECONF_BPC_MASK;
  4324. switch (intel_crtc->bpp) {
  4325. case 18:
  4326. val |= PIPECONF_6BPC;
  4327. break;
  4328. case 24:
  4329. val |= PIPECONF_8BPC;
  4330. break;
  4331. case 30:
  4332. val |= PIPECONF_10BPC;
  4333. break;
  4334. case 36:
  4335. val |= PIPECONF_12BPC;
  4336. break;
  4337. default:
  4338. /* Case prevented by intel_choose_pipe_bpp_dither. */
  4339. BUG();
  4340. }
  4341. val &= ~(PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_MASK);
  4342. if (dither)
  4343. val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
  4344. val &= ~PIPECONF_INTERLACE_MASK;
  4345. if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
  4346. val |= PIPECONF_INTERLACED_ILK;
  4347. else
  4348. val |= PIPECONF_PROGRESSIVE;
  4349. if (adjusted_mode->private_flags & INTEL_MODE_LIMITED_COLOR_RANGE)
  4350. val |= PIPECONF_COLOR_RANGE_SELECT;
  4351. else
  4352. val &= ~PIPECONF_COLOR_RANGE_SELECT;
  4353. I915_WRITE(PIPECONF(pipe), val);
  4354. POSTING_READ(PIPECONF(pipe));
  4355. }
  4356. static void haswell_set_pipeconf(struct drm_crtc *crtc,
  4357. struct drm_display_mode *adjusted_mode,
  4358. bool dither)
  4359. {
  4360. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  4361. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4362. enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
  4363. uint32_t val;
  4364. val = I915_READ(PIPECONF(cpu_transcoder));
  4365. val &= ~(PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_MASK);
  4366. if (dither)
  4367. val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
  4368. val &= ~PIPECONF_INTERLACE_MASK_HSW;
  4369. if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
  4370. val |= PIPECONF_INTERLACED_ILK;
  4371. else
  4372. val |= PIPECONF_PROGRESSIVE;
  4373. I915_WRITE(PIPECONF(cpu_transcoder), val);
  4374. POSTING_READ(PIPECONF(cpu_transcoder));
  4375. }
  4376. static bool ironlake_compute_clocks(struct drm_crtc *crtc,
  4377. struct drm_display_mode *adjusted_mode,
  4378. intel_clock_t *clock,
  4379. bool *has_reduced_clock,
  4380. intel_clock_t *reduced_clock)
  4381. {
  4382. struct drm_device *dev = crtc->dev;
  4383. struct drm_i915_private *dev_priv = dev->dev_private;
  4384. struct intel_encoder *intel_encoder;
  4385. int refclk;
  4386. const intel_limit_t *limit;
  4387. bool ret, is_sdvo = false, is_tv = false, is_lvds = false;
  4388. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  4389. switch (intel_encoder->type) {
  4390. case INTEL_OUTPUT_LVDS:
  4391. is_lvds = true;
  4392. break;
  4393. case INTEL_OUTPUT_SDVO:
  4394. case INTEL_OUTPUT_HDMI:
  4395. is_sdvo = true;
  4396. if (intel_encoder->needs_tv_clock)
  4397. is_tv = true;
  4398. break;
  4399. case INTEL_OUTPUT_TVOUT:
  4400. is_tv = true;
  4401. break;
  4402. }
  4403. }
  4404. refclk = ironlake_get_refclk(crtc);
  4405. /*
  4406. * Returns a set of divisors for the desired target clock with the given
  4407. * refclk, or FALSE. The returned values represent the clock equation:
  4408. * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
  4409. */
  4410. limit = intel_limit(crtc, refclk);
  4411. ret = limit->find_pll(limit, crtc, adjusted_mode->clock, refclk, NULL,
  4412. clock);
  4413. if (!ret)
  4414. return false;
  4415. if (is_lvds && dev_priv->lvds_downclock_avail) {
  4416. /*
  4417. * Ensure we match the reduced clock's P to the target clock.
  4418. * If the clocks don't match, we can't switch the display clock
  4419. * by using the FP0/FP1. In such case we will disable the LVDS
  4420. * downclock feature.
  4421. */
  4422. *has_reduced_clock = limit->find_pll(limit, crtc,
  4423. dev_priv->lvds_downclock,
  4424. refclk,
  4425. clock,
  4426. reduced_clock);
  4427. }
  4428. if (is_sdvo && is_tv)
  4429. i9xx_adjust_sdvo_tv_clock(adjusted_mode, clock);
  4430. return true;
  4431. }
  4432. static void cpt_enable_fdi_bc_bifurcation(struct drm_device *dev)
  4433. {
  4434. struct drm_i915_private *dev_priv = dev->dev_private;
  4435. uint32_t temp;
  4436. temp = I915_READ(SOUTH_CHICKEN1);
  4437. if (temp & FDI_BC_BIFURCATION_SELECT)
  4438. return;
  4439. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
  4440. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
  4441. temp |= FDI_BC_BIFURCATION_SELECT;
  4442. DRM_DEBUG_KMS("enabling fdi C rx\n");
  4443. I915_WRITE(SOUTH_CHICKEN1, temp);
  4444. POSTING_READ(SOUTH_CHICKEN1);
  4445. }
  4446. static bool ironlake_check_fdi_lanes(struct intel_crtc *intel_crtc)
  4447. {
  4448. struct drm_device *dev = intel_crtc->base.dev;
  4449. struct drm_i915_private *dev_priv = dev->dev_private;
  4450. struct intel_crtc *pipe_B_crtc =
  4451. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]);
  4452. DRM_DEBUG_KMS("checking fdi config on pipe %i, lanes %i\n",
  4453. intel_crtc->pipe, intel_crtc->fdi_lanes);
  4454. if (intel_crtc->fdi_lanes > 4) {
  4455. DRM_DEBUG_KMS("invalid fdi lane config on pipe %i: %i lanes\n",
  4456. intel_crtc->pipe, intel_crtc->fdi_lanes);
  4457. /* Clamp lanes to avoid programming the hw with bogus values. */
  4458. intel_crtc->fdi_lanes = 4;
  4459. return false;
  4460. }
  4461. if (dev_priv->num_pipe == 2)
  4462. return true;
  4463. switch (intel_crtc->pipe) {
  4464. case PIPE_A:
  4465. return true;
  4466. case PIPE_B:
  4467. if (dev_priv->pipe_to_crtc_mapping[PIPE_C]->enabled &&
  4468. intel_crtc->fdi_lanes > 2) {
  4469. DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %i: %i lanes\n",
  4470. intel_crtc->pipe, intel_crtc->fdi_lanes);
  4471. /* Clamp lanes to avoid programming the hw with bogus values. */
  4472. intel_crtc->fdi_lanes = 2;
  4473. return false;
  4474. }
  4475. if (intel_crtc->fdi_lanes > 2)
  4476. WARN_ON(I915_READ(SOUTH_CHICKEN1) & FDI_BC_BIFURCATION_SELECT);
  4477. else
  4478. cpt_enable_fdi_bc_bifurcation(dev);
  4479. return true;
  4480. case PIPE_C:
  4481. if (!pipe_B_crtc->base.enabled || pipe_B_crtc->fdi_lanes <= 2) {
  4482. if (intel_crtc->fdi_lanes > 2) {
  4483. DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %i: %i lanes\n",
  4484. intel_crtc->pipe, intel_crtc->fdi_lanes);
  4485. /* Clamp lanes to avoid programming the hw with bogus values. */
  4486. intel_crtc->fdi_lanes = 2;
  4487. return false;
  4488. }
  4489. } else {
  4490. DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
  4491. return false;
  4492. }
  4493. cpt_enable_fdi_bc_bifurcation(dev);
  4494. return true;
  4495. default:
  4496. BUG();
  4497. }
  4498. }
  4499. int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
  4500. {
  4501. /*
  4502. * Account for spread spectrum to avoid
  4503. * oversubscribing the link. Max center spread
  4504. * is 2.5%; use 5% for safety's sake.
  4505. */
  4506. u32 bps = target_clock * bpp * 21 / 20;
  4507. return bps / (link_bw * 8) + 1;
  4508. }
  4509. static void ironlake_set_m_n(struct drm_crtc *crtc,
  4510. struct drm_display_mode *mode,
  4511. struct drm_display_mode *adjusted_mode)
  4512. {
  4513. struct drm_device *dev = crtc->dev;
  4514. struct drm_i915_private *dev_priv = dev->dev_private;
  4515. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4516. enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
  4517. struct intel_encoder *intel_encoder, *edp_encoder = NULL;
  4518. struct intel_link_m_n m_n = {0};
  4519. int target_clock, pixel_multiplier, lane, link_bw;
  4520. bool is_dp = false, is_cpu_edp = false;
  4521. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  4522. switch (intel_encoder->type) {
  4523. case INTEL_OUTPUT_DISPLAYPORT:
  4524. is_dp = true;
  4525. break;
  4526. case INTEL_OUTPUT_EDP:
  4527. is_dp = true;
  4528. if (!intel_encoder_is_pch_edp(&intel_encoder->base))
  4529. is_cpu_edp = true;
  4530. edp_encoder = intel_encoder;
  4531. break;
  4532. }
  4533. }
  4534. /* FDI link */
  4535. pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
  4536. lane = 0;
  4537. /* CPU eDP doesn't require FDI link, so just set DP M/N
  4538. according to current link config */
  4539. if (is_cpu_edp) {
  4540. intel_edp_link_config(edp_encoder, &lane, &link_bw);
  4541. } else {
  4542. /* FDI is a binary signal running at ~2.7GHz, encoding
  4543. * each output octet as 10 bits. The actual frequency
  4544. * is stored as a divider into a 100MHz clock, and the
  4545. * mode pixel clock is stored in units of 1KHz.
  4546. * Hence the bw of each lane in terms of the mode signal
  4547. * is:
  4548. */
  4549. link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10;
  4550. }
  4551. /* [e]DP over FDI requires target mode clock instead of link clock. */
  4552. if (edp_encoder)
  4553. target_clock = intel_edp_target_clock(edp_encoder, mode);
  4554. else if (is_dp)
  4555. target_clock = mode->clock;
  4556. else
  4557. target_clock = adjusted_mode->clock;
  4558. if (!lane)
  4559. lane = ironlake_get_lanes_required(target_clock, link_bw,
  4560. intel_crtc->bpp);
  4561. intel_crtc->fdi_lanes = lane;
  4562. if (pixel_multiplier > 1)
  4563. link_bw *= pixel_multiplier;
  4564. intel_link_compute_m_n(intel_crtc->bpp, lane, target_clock, link_bw, &m_n);
  4565. I915_WRITE(PIPE_DATA_M1(cpu_transcoder), TU_SIZE(m_n.tu) | m_n.gmch_m);
  4566. I915_WRITE(PIPE_DATA_N1(cpu_transcoder), m_n.gmch_n);
  4567. I915_WRITE(PIPE_LINK_M1(cpu_transcoder), m_n.link_m);
  4568. I915_WRITE(PIPE_LINK_N1(cpu_transcoder), m_n.link_n);
  4569. }
  4570. static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc,
  4571. struct drm_display_mode *adjusted_mode,
  4572. intel_clock_t *clock, u32 fp)
  4573. {
  4574. struct drm_crtc *crtc = &intel_crtc->base;
  4575. struct drm_device *dev = crtc->dev;
  4576. struct drm_i915_private *dev_priv = dev->dev_private;
  4577. struct intel_encoder *intel_encoder;
  4578. uint32_t dpll;
  4579. int factor, pixel_multiplier, num_connectors = 0;
  4580. bool is_lvds = false, is_sdvo = false, is_tv = false;
  4581. bool is_dp = false, is_cpu_edp = false;
  4582. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  4583. switch (intel_encoder->type) {
  4584. case INTEL_OUTPUT_LVDS:
  4585. is_lvds = true;
  4586. break;
  4587. case INTEL_OUTPUT_SDVO:
  4588. case INTEL_OUTPUT_HDMI:
  4589. is_sdvo = true;
  4590. if (intel_encoder->needs_tv_clock)
  4591. is_tv = true;
  4592. break;
  4593. case INTEL_OUTPUT_TVOUT:
  4594. is_tv = true;
  4595. break;
  4596. case INTEL_OUTPUT_DISPLAYPORT:
  4597. is_dp = true;
  4598. break;
  4599. case INTEL_OUTPUT_EDP:
  4600. is_dp = true;
  4601. if (!intel_encoder_is_pch_edp(&intel_encoder->base))
  4602. is_cpu_edp = true;
  4603. break;
  4604. }
  4605. num_connectors++;
  4606. }
  4607. /* Enable autotuning of the PLL clock (if permissible) */
  4608. factor = 21;
  4609. if (is_lvds) {
  4610. if ((intel_panel_use_ssc(dev_priv) &&
  4611. dev_priv->lvds_ssc_freq == 100) ||
  4612. intel_is_dual_link_lvds(dev))
  4613. factor = 25;
  4614. } else if (is_sdvo && is_tv)
  4615. factor = 20;
  4616. if (clock->m < factor * clock->n)
  4617. fp |= FP_CB_TUNE;
  4618. dpll = 0;
  4619. if (is_lvds)
  4620. dpll |= DPLLB_MODE_LVDS;
  4621. else
  4622. dpll |= DPLLB_MODE_DAC_SERIAL;
  4623. if (is_sdvo) {
  4624. pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
  4625. if (pixel_multiplier > 1) {
  4626. dpll |= (pixel_multiplier - 1) << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
  4627. }
  4628. dpll |= DPLL_DVO_HIGH_SPEED;
  4629. }
  4630. if (is_dp && !is_cpu_edp)
  4631. dpll |= DPLL_DVO_HIGH_SPEED;
  4632. /* compute bitmask from p1 value */
  4633. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  4634. /* also FPA1 */
  4635. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  4636. switch (clock->p2) {
  4637. case 5:
  4638. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
  4639. break;
  4640. case 7:
  4641. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
  4642. break;
  4643. case 10:
  4644. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
  4645. break;
  4646. case 14:
  4647. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
  4648. break;
  4649. }
  4650. if (is_sdvo && is_tv)
  4651. dpll |= PLL_REF_INPUT_TVCLKINBC;
  4652. else if (is_tv)
  4653. /* XXX: just matching BIOS for now */
  4654. /* dpll |= PLL_REF_INPUT_TVCLKINBC; */
  4655. dpll |= 3;
  4656. else if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  4657. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  4658. else
  4659. dpll |= PLL_REF_INPUT_DREFCLK;
  4660. return dpll;
  4661. }
  4662. static int ironlake_crtc_mode_set(struct drm_crtc *crtc,
  4663. struct drm_display_mode *mode,
  4664. struct drm_display_mode *adjusted_mode,
  4665. int x, int y,
  4666. struct drm_framebuffer *fb)
  4667. {
  4668. struct drm_device *dev = crtc->dev;
  4669. struct drm_i915_private *dev_priv = dev->dev_private;
  4670. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4671. int pipe = intel_crtc->pipe;
  4672. int plane = intel_crtc->plane;
  4673. int num_connectors = 0;
  4674. intel_clock_t clock, reduced_clock;
  4675. u32 dpll, fp = 0, fp2 = 0;
  4676. bool ok, has_reduced_clock = false;
  4677. bool is_lvds = false, is_dp = false, is_cpu_edp = false;
  4678. struct intel_encoder *encoder;
  4679. int ret;
  4680. bool dither, fdi_config_ok;
  4681. for_each_encoder_on_crtc(dev, crtc, encoder) {
  4682. switch (encoder->type) {
  4683. case INTEL_OUTPUT_LVDS:
  4684. is_lvds = true;
  4685. break;
  4686. case INTEL_OUTPUT_DISPLAYPORT:
  4687. is_dp = true;
  4688. break;
  4689. case INTEL_OUTPUT_EDP:
  4690. is_dp = true;
  4691. if (!intel_encoder_is_pch_edp(&encoder->base))
  4692. is_cpu_edp = true;
  4693. break;
  4694. }
  4695. num_connectors++;
  4696. }
  4697. WARN(!(HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)),
  4698. "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev));
  4699. ok = ironlake_compute_clocks(crtc, adjusted_mode, &clock,
  4700. &has_reduced_clock, &reduced_clock);
  4701. if (!ok) {
  4702. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  4703. return -EINVAL;
  4704. }
  4705. /* Ensure that the cursor is valid for the new mode before changing... */
  4706. intel_crtc_update_cursor(crtc, true);
  4707. /* determine panel color depth */
  4708. dither = intel_choose_pipe_bpp_dither(crtc, fb, &intel_crtc->bpp,
  4709. adjusted_mode);
  4710. if (is_lvds && dev_priv->lvds_dither)
  4711. dither = true;
  4712. fp = clock.n << 16 | clock.m1 << 8 | clock.m2;
  4713. if (has_reduced_clock)
  4714. fp2 = reduced_clock.n << 16 | reduced_clock.m1 << 8 |
  4715. reduced_clock.m2;
  4716. dpll = ironlake_compute_dpll(intel_crtc, adjusted_mode, &clock, fp);
  4717. DRM_DEBUG_KMS("Mode for pipe %d:\n", pipe);
  4718. drm_mode_debug_printmodeline(mode);
  4719. /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
  4720. if (!is_cpu_edp) {
  4721. struct intel_pch_pll *pll;
  4722. pll = intel_get_pch_pll(intel_crtc, dpll, fp);
  4723. if (pll == NULL) {
  4724. DRM_DEBUG_DRIVER("failed to find PLL for pipe %d\n",
  4725. pipe);
  4726. return -EINVAL;
  4727. }
  4728. } else
  4729. intel_put_pch_pll(intel_crtc);
  4730. if (is_dp && !is_cpu_edp)
  4731. intel_dp_set_m_n(crtc, mode, adjusted_mode);
  4732. for_each_encoder_on_crtc(dev, crtc, encoder)
  4733. if (encoder->pre_pll_enable)
  4734. encoder->pre_pll_enable(encoder);
  4735. if (intel_crtc->pch_pll) {
  4736. I915_WRITE(intel_crtc->pch_pll->pll_reg, dpll);
  4737. /* Wait for the clocks to stabilize. */
  4738. POSTING_READ(intel_crtc->pch_pll->pll_reg);
  4739. udelay(150);
  4740. /* The pixel multiplier can only be updated once the
  4741. * DPLL is enabled and the clocks are stable.
  4742. *
  4743. * So write it again.
  4744. */
  4745. I915_WRITE(intel_crtc->pch_pll->pll_reg, dpll);
  4746. }
  4747. intel_crtc->lowfreq_avail = false;
  4748. if (intel_crtc->pch_pll) {
  4749. if (is_lvds && has_reduced_clock && i915_powersave) {
  4750. I915_WRITE(intel_crtc->pch_pll->fp1_reg, fp2);
  4751. intel_crtc->lowfreq_avail = true;
  4752. } else {
  4753. I915_WRITE(intel_crtc->pch_pll->fp1_reg, fp);
  4754. }
  4755. }
  4756. intel_set_pipe_timings(intel_crtc, mode, adjusted_mode);
  4757. /* Note, this also computes intel_crtc->fdi_lanes which is used below in
  4758. * ironlake_check_fdi_lanes. */
  4759. ironlake_set_m_n(crtc, mode, adjusted_mode);
  4760. fdi_config_ok = ironlake_check_fdi_lanes(intel_crtc);
  4761. ironlake_set_pipeconf(crtc, adjusted_mode, dither);
  4762. intel_wait_for_vblank(dev, pipe);
  4763. /* Set up the display plane register */
  4764. I915_WRITE(DSPCNTR(plane), DISPPLANE_GAMMA_ENABLE);
  4765. POSTING_READ(DSPCNTR(plane));
  4766. ret = intel_pipe_set_base(crtc, x, y, fb);
  4767. intel_update_watermarks(dev);
  4768. intel_update_linetime_watermarks(dev, pipe, adjusted_mode);
  4769. return fdi_config_ok ? ret : -EINVAL;
  4770. }
  4771. static int haswell_crtc_mode_set(struct drm_crtc *crtc,
  4772. struct drm_display_mode *mode,
  4773. struct drm_display_mode *adjusted_mode,
  4774. int x, int y,
  4775. struct drm_framebuffer *fb)
  4776. {
  4777. struct drm_device *dev = crtc->dev;
  4778. struct drm_i915_private *dev_priv = dev->dev_private;
  4779. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4780. int pipe = intel_crtc->pipe;
  4781. int plane = intel_crtc->plane;
  4782. int num_connectors = 0;
  4783. bool is_dp = false, is_cpu_edp = false;
  4784. struct intel_encoder *encoder;
  4785. int ret;
  4786. bool dither;
  4787. for_each_encoder_on_crtc(dev, crtc, encoder) {
  4788. switch (encoder->type) {
  4789. case INTEL_OUTPUT_DISPLAYPORT:
  4790. is_dp = true;
  4791. break;
  4792. case INTEL_OUTPUT_EDP:
  4793. is_dp = true;
  4794. if (!intel_encoder_is_pch_edp(&encoder->base))
  4795. is_cpu_edp = true;
  4796. break;
  4797. }
  4798. num_connectors++;
  4799. }
  4800. if (is_cpu_edp)
  4801. intel_crtc->cpu_transcoder = TRANSCODER_EDP;
  4802. else
  4803. intel_crtc->cpu_transcoder = pipe;
  4804. /* We are not sure yet this won't happen. */
  4805. WARN(!HAS_PCH_LPT(dev), "Unexpected PCH type %d\n",
  4806. INTEL_PCH_TYPE(dev));
  4807. WARN(num_connectors != 1, "%d connectors attached to pipe %c\n",
  4808. num_connectors, pipe_name(pipe));
  4809. WARN_ON(I915_READ(PIPECONF(intel_crtc->cpu_transcoder)) &
  4810. (PIPECONF_ENABLE | I965_PIPECONF_ACTIVE));
  4811. WARN_ON(I915_READ(DSPCNTR(plane)) & DISPLAY_PLANE_ENABLE);
  4812. if (!intel_ddi_pll_mode_set(crtc, adjusted_mode->clock))
  4813. return -EINVAL;
  4814. /* Ensure that the cursor is valid for the new mode before changing... */
  4815. intel_crtc_update_cursor(crtc, true);
  4816. /* determine panel color depth */
  4817. dither = intel_choose_pipe_bpp_dither(crtc, fb, &intel_crtc->bpp,
  4818. adjusted_mode);
  4819. DRM_DEBUG_KMS("Mode for pipe %d:\n", pipe);
  4820. drm_mode_debug_printmodeline(mode);
  4821. if (is_dp && !is_cpu_edp)
  4822. intel_dp_set_m_n(crtc, mode, adjusted_mode);
  4823. intel_crtc->lowfreq_avail = false;
  4824. intel_set_pipe_timings(intel_crtc, mode, adjusted_mode);
  4825. if (!is_dp || is_cpu_edp)
  4826. ironlake_set_m_n(crtc, mode, adjusted_mode);
  4827. haswell_set_pipeconf(crtc, adjusted_mode, dither);
  4828. /* Set up the display plane register */
  4829. I915_WRITE(DSPCNTR(plane), DISPPLANE_GAMMA_ENABLE);
  4830. POSTING_READ(DSPCNTR(plane));
  4831. ret = intel_pipe_set_base(crtc, x, y, fb);
  4832. intel_update_watermarks(dev);
  4833. intel_update_linetime_watermarks(dev, pipe, adjusted_mode);
  4834. return ret;
  4835. }
  4836. static int intel_crtc_mode_set(struct drm_crtc *crtc,
  4837. struct drm_display_mode *mode,
  4838. struct drm_display_mode *adjusted_mode,
  4839. int x, int y,
  4840. struct drm_framebuffer *fb)
  4841. {
  4842. struct drm_device *dev = crtc->dev;
  4843. struct drm_i915_private *dev_priv = dev->dev_private;
  4844. struct drm_encoder_helper_funcs *encoder_funcs;
  4845. struct intel_encoder *encoder;
  4846. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4847. int pipe = intel_crtc->pipe;
  4848. int ret;
  4849. drm_vblank_pre_modeset(dev, pipe);
  4850. ret = dev_priv->display.crtc_mode_set(crtc, mode, adjusted_mode,
  4851. x, y, fb);
  4852. drm_vblank_post_modeset(dev, pipe);
  4853. if (ret != 0)
  4854. return ret;
  4855. for_each_encoder_on_crtc(dev, crtc, encoder) {
  4856. DRM_DEBUG_KMS("[ENCODER:%d:%s] set [MODE:%d:%s]\n",
  4857. encoder->base.base.id,
  4858. drm_get_encoder_name(&encoder->base),
  4859. mode->base.id, mode->name);
  4860. encoder_funcs = encoder->base.helper_private;
  4861. encoder_funcs->mode_set(&encoder->base, mode, adjusted_mode);
  4862. }
  4863. return 0;
  4864. }
  4865. static bool intel_eld_uptodate(struct drm_connector *connector,
  4866. int reg_eldv, uint32_t bits_eldv,
  4867. int reg_elda, uint32_t bits_elda,
  4868. int reg_edid)
  4869. {
  4870. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  4871. uint8_t *eld = connector->eld;
  4872. uint32_t i;
  4873. i = I915_READ(reg_eldv);
  4874. i &= bits_eldv;
  4875. if (!eld[0])
  4876. return !i;
  4877. if (!i)
  4878. return false;
  4879. i = I915_READ(reg_elda);
  4880. i &= ~bits_elda;
  4881. I915_WRITE(reg_elda, i);
  4882. for (i = 0; i < eld[2]; i++)
  4883. if (I915_READ(reg_edid) != *((uint32_t *)eld + i))
  4884. return false;
  4885. return true;
  4886. }
  4887. static void g4x_write_eld(struct drm_connector *connector,
  4888. struct drm_crtc *crtc)
  4889. {
  4890. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  4891. uint8_t *eld = connector->eld;
  4892. uint32_t eldv;
  4893. uint32_t len;
  4894. uint32_t i;
  4895. i = I915_READ(G4X_AUD_VID_DID);
  4896. if (i == INTEL_AUDIO_DEVBLC || i == INTEL_AUDIO_DEVCL)
  4897. eldv = G4X_ELDV_DEVCL_DEVBLC;
  4898. else
  4899. eldv = G4X_ELDV_DEVCTG;
  4900. if (intel_eld_uptodate(connector,
  4901. G4X_AUD_CNTL_ST, eldv,
  4902. G4X_AUD_CNTL_ST, G4X_ELD_ADDR,
  4903. G4X_HDMIW_HDMIEDID))
  4904. return;
  4905. i = I915_READ(G4X_AUD_CNTL_ST);
  4906. i &= ~(eldv | G4X_ELD_ADDR);
  4907. len = (i >> 9) & 0x1f; /* ELD buffer size */
  4908. I915_WRITE(G4X_AUD_CNTL_ST, i);
  4909. if (!eld[0])
  4910. return;
  4911. len = min_t(uint8_t, eld[2], len);
  4912. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  4913. for (i = 0; i < len; i++)
  4914. I915_WRITE(G4X_HDMIW_HDMIEDID, *((uint32_t *)eld + i));
  4915. i = I915_READ(G4X_AUD_CNTL_ST);
  4916. i |= eldv;
  4917. I915_WRITE(G4X_AUD_CNTL_ST, i);
  4918. }
  4919. static void haswell_write_eld(struct drm_connector *connector,
  4920. struct drm_crtc *crtc)
  4921. {
  4922. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  4923. uint8_t *eld = connector->eld;
  4924. struct drm_device *dev = crtc->dev;
  4925. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4926. uint32_t eldv;
  4927. uint32_t i;
  4928. int len;
  4929. int pipe = to_intel_crtc(crtc)->pipe;
  4930. int tmp;
  4931. int hdmiw_hdmiedid = HSW_AUD_EDID_DATA(pipe);
  4932. int aud_cntl_st = HSW_AUD_DIP_ELD_CTRL(pipe);
  4933. int aud_config = HSW_AUD_CFG(pipe);
  4934. int aud_cntrl_st2 = HSW_AUD_PIN_ELD_CP_VLD;
  4935. DRM_DEBUG_DRIVER("HDMI: Haswell Audio initialize....\n");
  4936. /* Audio output enable */
  4937. DRM_DEBUG_DRIVER("HDMI audio: enable codec\n");
  4938. tmp = I915_READ(aud_cntrl_st2);
  4939. tmp |= (AUDIO_OUTPUT_ENABLE_A << (pipe * 4));
  4940. I915_WRITE(aud_cntrl_st2, tmp);
  4941. /* Wait for 1 vertical blank */
  4942. intel_wait_for_vblank(dev, pipe);
  4943. /* Set ELD valid state */
  4944. tmp = I915_READ(aud_cntrl_st2);
  4945. DRM_DEBUG_DRIVER("HDMI audio: pin eld vld status=0x%8x\n", tmp);
  4946. tmp |= (AUDIO_ELD_VALID_A << (pipe * 4));
  4947. I915_WRITE(aud_cntrl_st2, tmp);
  4948. tmp = I915_READ(aud_cntrl_st2);
  4949. DRM_DEBUG_DRIVER("HDMI audio: eld vld status=0x%8x\n", tmp);
  4950. /* Enable HDMI mode */
  4951. tmp = I915_READ(aud_config);
  4952. DRM_DEBUG_DRIVER("HDMI audio: audio conf: 0x%8x\n", tmp);
  4953. /* clear N_programing_enable and N_value_index */
  4954. tmp &= ~(AUD_CONFIG_N_VALUE_INDEX | AUD_CONFIG_N_PROG_ENABLE);
  4955. I915_WRITE(aud_config, tmp);
  4956. DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe));
  4957. eldv = AUDIO_ELD_VALID_A << (pipe * 4);
  4958. intel_crtc->eld_vld = true;
  4959. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
  4960. DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
  4961. eld[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
  4962. I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */
  4963. } else
  4964. I915_WRITE(aud_config, 0);
  4965. if (intel_eld_uptodate(connector,
  4966. aud_cntrl_st2, eldv,
  4967. aud_cntl_st, IBX_ELD_ADDRESS,
  4968. hdmiw_hdmiedid))
  4969. return;
  4970. i = I915_READ(aud_cntrl_st2);
  4971. i &= ~eldv;
  4972. I915_WRITE(aud_cntrl_st2, i);
  4973. if (!eld[0])
  4974. return;
  4975. i = I915_READ(aud_cntl_st);
  4976. i &= ~IBX_ELD_ADDRESS;
  4977. I915_WRITE(aud_cntl_st, i);
  4978. i = (i >> 29) & DIP_PORT_SEL_MASK; /* DIP_Port_Select, 0x1 = PortB */
  4979. DRM_DEBUG_DRIVER("port num:%d\n", i);
  4980. len = min_t(uint8_t, eld[2], 21); /* 84 bytes of hw ELD buffer */
  4981. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  4982. for (i = 0; i < len; i++)
  4983. I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i));
  4984. i = I915_READ(aud_cntrl_st2);
  4985. i |= eldv;
  4986. I915_WRITE(aud_cntrl_st2, i);
  4987. }
  4988. static void ironlake_write_eld(struct drm_connector *connector,
  4989. struct drm_crtc *crtc)
  4990. {
  4991. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  4992. uint8_t *eld = connector->eld;
  4993. uint32_t eldv;
  4994. uint32_t i;
  4995. int len;
  4996. int hdmiw_hdmiedid;
  4997. int aud_config;
  4998. int aud_cntl_st;
  4999. int aud_cntrl_st2;
  5000. int pipe = to_intel_crtc(crtc)->pipe;
  5001. if (HAS_PCH_IBX(connector->dev)) {
  5002. hdmiw_hdmiedid = IBX_HDMIW_HDMIEDID(pipe);
  5003. aud_config = IBX_AUD_CFG(pipe);
  5004. aud_cntl_st = IBX_AUD_CNTL_ST(pipe);
  5005. aud_cntrl_st2 = IBX_AUD_CNTL_ST2;
  5006. } else {
  5007. hdmiw_hdmiedid = CPT_HDMIW_HDMIEDID(pipe);
  5008. aud_config = CPT_AUD_CFG(pipe);
  5009. aud_cntl_st = CPT_AUD_CNTL_ST(pipe);
  5010. aud_cntrl_st2 = CPT_AUD_CNTRL_ST2;
  5011. }
  5012. DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe));
  5013. i = I915_READ(aud_cntl_st);
  5014. i = (i >> 29) & DIP_PORT_SEL_MASK; /* DIP_Port_Select, 0x1 = PortB */
  5015. if (!i) {
  5016. DRM_DEBUG_DRIVER("Audio directed to unknown port\n");
  5017. /* operate blindly on all ports */
  5018. eldv = IBX_ELD_VALIDB;
  5019. eldv |= IBX_ELD_VALIDB << 4;
  5020. eldv |= IBX_ELD_VALIDB << 8;
  5021. } else {
  5022. DRM_DEBUG_DRIVER("ELD on port %c\n", 'A' + i);
  5023. eldv = IBX_ELD_VALIDB << ((i - 1) * 4);
  5024. }
  5025. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
  5026. DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
  5027. eld[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
  5028. I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */
  5029. } else
  5030. I915_WRITE(aud_config, 0);
  5031. if (intel_eld_uptodate(connector,
  5032. aud_cntrl_st2, eldv,
  5033. aud_cntl_st, IBX_ELD_ADDRESS,
  5034. hdmiw_hdmiedid))
  5035. return;
  5036. i = I915_READ(aud_cntrl_st2);
  5037. i &= ~eldv;
  5038. I915_WRITE(aud_cntrl_st2, i);
  5039. if (!eld[0])
  5040. return;
  5041. i = I915_READ(aud_cntl_st);
  5042. i &= ~IBX_ELD_ADDRESS;
  5043. I915_WRITE(aud_cntl_st, i);
  5044. len = min_t(uint8_t, eld[2], 21); /* 84 bytes of hw ELD buffer */
  5045. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  5046. for (i = 0; i < len; i++)
  5047. I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i));
  5048. i = I915_READ(aud_cntrl_st2);
  5049. i |= eldv;
  5050. I915_WRITE(aud_cntrl_st2, i);
  5051. }
  5052. void intel_write_eld(struct drm_encoder *encoder,
  5053. struct drm_display_mode *mode)
  5054. {
  5055. struct drm_crtc *crtc = encoder->crtc;
  5056. struct drm_connector *connector;
  5057. struct drm_device *dev = encoder->dev;
  5058. struct drm_i915_private *dev_priv = dev->dev_private;
  5059. connector = drm_select_eld(encoder, mode);
  5060. if (!connector)
  5061. return;
  5062. DRM_DEBUG_DRIVER("ELD on [CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  5063. connector->base.id,
  5064. drm_get_connector_name(connector),
  5065. connector->encoder->base.id,
  5066. drm_get_encoder_name(connector->encoder));
  5067. connector->eld[6] = drm_av_sync_delay(connector, mode) / 2;
  5068. if (dev_priv->display.write_eld)
  5069. dev_priv->display.write_eld(connector, crtc);
  5070. }
  5071. /** Loads the palette/gamma unit for the CRTC with the prepared values */
  5072. void intel_crtc_load_lut(struct drm_crtc *crtc)
  5073. {
  5074. struct drm_device *dev = crtc->dev;
  5075. struct drm_i915_private *dev_priv = dev->dev_private;
  5076. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5077. int palreg = PALETTE(intel_crtc->pipe);
  5078. int i;
  5079. /* The clocks have to be on to load the palette. */
  5080. if (!crtc->enabled || !intel_crtc->active)
  5081. return;
  5082. /* use legacy palette for Ironlake */
  5083. if (HAS_PCH_SPLIT(dev))
  5084. palreg = LGC_PALETTE(intel_crtc->pipe);
  5085. for (i = 0; i < 256; i++) {
  5086. I915_WRITE(palreg + 4 * i,
  5087. (intel_crtc->lut_r[i] << 16) |
  5088. (intel_crtc->lut_g[i] << 8) |
  5089. intel_crtc->lut_b[i]);
  5090. }
  5091. }
  5092. static void i845_update_cursor(struct drm_crtc *crtc, u32 base)
  5093. {
  5094. struct drm_device *dev = crtc->dev;
  5095. struct drm_i915_private *dev_priv = dev->dev_private;
  5096. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5097. bool visible = base != 0;
  5098. u32 cntl;
  5099. if (intel_crtc->cursor_visible == visible)
  5100. return;
  5101. cntl = I915_READ(_CURACNTR);
  5102. if (visible) {
  5103. /* On these chipsets we can only modify the base whilst
  5104. * the cursor is disabled.
  5105. */
  5106. I915_WRITE(_CURABASE, base);
  5107. cntl &= ~(CURSOR_FORMAT_MASK);
  5108. /* XXX width must be 64, stride 256 => 0x00 << 28 */
  5109. cntl |= CURSOR_ENABLE |
  5110. CURSOR_GAMMA_ENABLE |
  5111. CURSOR_FORMAT_ARGB;
  5112. } else
  5113. cntl &= ~(CURSOR_ENABLE | CURSOR_GAMMA_ENABLE);
  5114. I915_WRITE(_CURACNTR, cntl);
  5115. intel_crtc->cursor_visible = visible;
  5116. }
  5117. static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base)
  5118. {
  5119. struct drm_device *dev = crtc->dev;
  5120. struct drm_i915_private *dev_priv = dev->dev_private;
  5121. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5122. int pipe = intel_crtc->pipe;
  5123. bool visible = base != 0;
  5124. if (intel_crtc->cursor_visible != visible) {
  5125. uint32_t cntl = I915_READ(CURCNTR(pipe));
  5126. if (base) {
  5127. cntl &= ~(CURSOR_MODE | MCURSOR_PIPE_SELECT);
  5128. cntl |= CURSOR_MODE_64_ARGB_AX | MCURSOR_GAMMA_ENABLE;
  5129. cntl |= pipe << 28; /* Connect to correct pipe */
  5130. } else {
  5131. cntl &= ~(CURSOR_MODE | MCURSOR_GAMMA_ENABLE);
  5132. cntl |= CURSOR_MODE_DISABLE;
  5133. }
  5134. I915_WRITE(CURCNTR(pipe), cntl);
  5135. intel_crtc->cursor_visible = visible;
  5136. }
  5137. /* and commit changes on next vblank */
  5138. I915_WRITE(CURBASE(pipe), base);
  5139. }
  5140. static void ivb_update_cursor(struct drm_crtc *crtc, u32 base)
  5141. {
  5142. struct drm_device *dev = crtc->dev;
  5143. struct drm_i915_private *dev_priv = dev->dev_private;
  5144. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5145. int pipe = intel_crtc->pipe;
  5146. bool visible = base != 0;
  5147. if (intel_crtc->cursor_visible != visible) {
  5148. uint32_t cntl = I915_READ(CURCNTR_IVB(pipe));
  5149. if (base) {
  5150. cntl &= ~CURSOR_MODE;
  5151. cntl |= CURSOR_MODE_64_ARGB_AX | MCURSOR_GAMMA_ENABLE;
  5152. } else {
  5153. cntl &= ~(CURSOR_MODE | MCURSOR_GAMMA_ENABLE);
  5154. cntl |= CURSOR_MODE_DISABLE;
  5155. }
  5156. I915_WRITE(CURCNTR_IVB(pipe), cntl);
  5157. intel_crtc->cursor_visible = visible;
  5158. }
  5159. /* and commit changes on next vblank */
  5160. I915_WRITE(CURBASE_IVB(pipe), base);
  5161. }
  5162. /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */
  5163. static void intel_crtc_update_cursor(struct drm_crtc *crtc,
  5164. bool on)
  5165. {
  5166. struct drm_device *dev = crtc->dev;
  5167. struct drm_i915_private *dev_priv = dev->dev_private;
  5168. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5169. int pipe = intel_crtc->pipe;
  5170. int x = intel_crtc->cursor_x;
  5171. int y = intel_crtc->cursor_y;
  5172. u32 base, pos;
  5173. bool visible;
  5174. pos = 0;
  5175. if (on && crtc->enabled && crtc->fb) {
  5176. base = intel_crtc->cursor_addr;
  5177. if (x > (int) crtc->fb->width)
  5178. base = 0;
  5179. if (y > (int) crtc->fb->height)
  5180. base = 0;
  5181. } else
  5182. base = 0;
  5183. if (x < 0) {
  5184. if (x + intel_crtc->cursor_width < 0)
  5185. base = 0;
  5186. pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
  5187. x = -x;
  5188. }
  5189. pos |= x << CURSOR_X_SHIFT;
  5190. if (y < 0) {
  5191. if (y + intel_crtc->cursor_height < 0)
  5192. base = 0;
  5193. pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
  5194. y = -y;
  5195. }
  5196. pos |= y << CURSOR_Y_SHIFT;
  5197. visible = base != 0;
  5198. if (!visible && !intel_crtc->cursor_visible)
  5199. return;
  5200. if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) {
  5201. I915_WRITE(CURPOS_IVB(pipe), pos);
  5202. ivb_update_cursor(crtc, base);
  5203. } else {
  5204. I915_WRITE(CURPOS(pipe), pos);
  5205. if (IS_845G(dev) || IS_I865G(dev))
  5206. i845_update_cursor(crtc, base);
  5207. else
  5208. i9xx_update_cursor(crtc, base);
  5209. }
  5210. }
  5211. static int intel_crtc_cursor_set(struct drm_crtc *crtc,
  5212. struct drm_file *file,
  5213. uint32_t handle,
  5214. uint32_t width, uint32_t height)
  5215. {
  5216. struct drm_device *dev = crtc->dev;
  5217. struct drm_i915_private *dev_priv = dev->dev_private;
  5218. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5219. struct drm_i915_gem_object *obj;
  5220. uint32_t addr;
  5221. int ret;
  5222. /* if we want to turn off the cursor ignore width and height */
  5223. if (!handle) {
  5224. DRM_DEBUG_KMS("cursor off\n");
  5225. addr = 0;
  5226. obj = NULL;
  5227. mutex_lock(&dev->struct_mutex);
  5228. goto finish;
  5229. }
  5230. /* Currently we only support 64x64 cursors */
  5231. if (width != 64 || height != 64) {
  5232. DRM_ERROR("we currently only support 64x64 cursors\n");
  5233. return -EINVAL;
  5234. }
  5235. obj = to_intel_bo(drm_gem_object_lookup(dev, file, handle));
  5236. if (&obj->base == NULL)
  5237. return -ENOENT;
  5238. if (obj->base.size < width * height * 4) {
  5239. DRM_ERROR("buffer is to small\n");
  5240. ret = -ENOMEM;
  5241. goto fail;
  5242. }
  5243. /* we only need to pin inside GTT if cursor is non-phy */
  5244. mutex_lock(&dev->struct_mutex);
  5245. if (!dev_priv->info->cursor_needs_physical) {
  5246. if (obj->tiling_mode) {
  5247. DRM_ERROR("cursor cannot be tiled\n");
  5248. ret = -EINVAL;
  5249. goto fail_locked;
  5250. }
  5251. ret = i915_gem_object_pin_to_display_plane(obj, 0, NULL);
  5252. if (ret) {
  5253. DRM_ERROR("failed to move cursor bo into the GTT\n");
  5254. goto fail_locked;
  5255. }
  5256. ret = i915_gem_object_put_fence(obj);
  5257. if (ret) {
  5258. DRM_ERROR("failed to release fence for cursor");
  5259. goto fail_unpin;
  5260. }
  5261. addr = obj->gtt_offset;
  5262. } else {
  5263. int align = IS_I830(dev) ? 16 * 1024 : 256;
  5264. ret = i915_gem_attach_phys_object(dev, obj,
  5265. (intel_crtc->pipe == 0) ? I915_GEM_PHYS_CURSOR_0 : I915_GEM_PHYS_CURSOR_1,
  5266. align);
  5267. if (ret) {
  5268. DRM_ERROR("failed to attach phys object\n");
  5269. goto fail_locked;
  5270. }
  5271. addr = obj->phys_obj->handle->busaddr;
  5272. }
  5273. if (IS_GEN2(dev))
  5274. I915_WRITE(CURSIZE, (height << 12) | width);
  5275. finish:
  5276. if (intel_crtc->cursor_bo) {
  5277. if (dev_priv->info->cursor_needs_physical) {
  5278. if (intel_crtc->cursor_bo != obj)
  5279. i915_gem_detach_phys_object(dev, intel_crtc->cursor_bo);
  5280. } else
  5281. i915_gem_object_unpin(intel_crtc->cursor_bo);
  5282. drm_gem_object_unreference(&intel_crtc->cursor_bo->base);
  5283. }
  5284. mutex_unlock(&dev->struct_mutex);
  5285. intel_crtc->cursor_addr = addr;
  5286. intel_crtc->cursor_bo = obj;
  5287. intel_crtc->cursor_width = width;
  5288. intel_crtc->cursor_height = height;
  5289. intel_crtc_update_cursor(crtc, true);
  5290. return 0;
  5291. fail_unpin:
  5292. i915_gem_object_unpin(obj);
  5293. fail_locked:
  5294. mutex_unlock(&dev->struct_mutex);
  5295. fail:
  5296. drm_gem_object_unreference_unlocked(&obj->base);
  5297. return ret;
  5298. }
  5299. static int intel_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
  5300. {
  5301. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5302. intel_crtc->cursor_x = x;
  5303. intel_crtc->cursor_y = y;
  5304. intel_crtc_update_cursor(crtc, true);
  5305. return 0;
  5306. }
  5307. /** Sets the color ramps on behalf of RandR */
  5308. void intel_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
  5309. u16 blue, int regno)
  5310. {
  5311. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5312. intel_crtc->lut_r[regno] = red >> 8;
  5313. intel_crtc->lut_g[regno] = green >> 8;
  5314. intel_crtc->lut_b[regno] = blue >> 8;
  5315. }
  5316. void intel_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green,
  5317. u16 *blue, int regno)
  5318. {
  5319. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5320. *red = intel_crtc->lut_r[regno] << 8;
  5321. *green = intel_crtc->lut_g[regno] << 8;
  5322. *blue = intel_crtc->lut_b[regno] << 8;
  5323. }
  5324. static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
  5325. u16 *blue, uint32_t start, uint32_t size)
  5326. {
  5327. int end = (start + size > 256) ? 256 : start + size, i;
  5328. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5329. for (i = start; i < end; i++) {
  5330. intel_crtc->lut_r[i] = red[i] >> 8;
  5331. intel_crtc->lut_g[i] = green[i] >> 8;
  5332. intel_crtc->lut_b[i] = blue[i] >> 8;
  5333. }
  5334. intel_crtc_load_lut(crtc);
  5335. }
  5336. /**
  5337. * Get a pipe with a simple mode set on it for doing load-based monitor
  5338. * detection.
  5339. *
  5340. * It will be up to the load-detect code to adjust the pipe as appropriate for
  5341. * its requirements. The pipe will be connected to no other encoders.
  5342. *
  5343. * Currently this code will only succeed if there is a pipe with no encoders
  5344. * configured for it. In the future, it could choose to temporarily disable
  5345. * some outputs to free up a pipe for its use.
  5346. *
  5347. * \return crtc, or NULL if no pipes are available.
  5348. */
  5349. /* VESA 640x480x72Hz mode to set on the pipe */
  5350. static struct drm_display_mode load_detect_mode = {
  5351. DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
  5352. 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  5353. };
  5354. static struct drm_framebuffer *
  5355. intel_framebuffer_create(struct drm_device *dev,
  5356. struct drm_mode_fb_cmd2 *mode_cmd,
  5357. struct drm_i915_gem_object *obj)
  5358. {
  5359. struct intel_framebuffer *intel_fb;
  5360. int ret;
  5361. intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
  5362. if (!intel_fb) {
  5363. drm_gem_object_unreference_unlocked(&obj->base);
  5364. return ERR_PTR(-ENOMEM);
  5365. }
  5366. ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj);
  5367. if (ret) {
  5368. drm_gem_object_unreference_unlocked(&obj->base);
  5369. kfree(intel_fb);
  5370. return ERR_PTR(ret);
  5371. }
  5372. return &intel_fb->base;
  5373. }
  5374. static u32
  5375. intel_framebuffer_pitch_for_width(int width, int bpp)
  5376. {
  5377. u32 pitch = DIV_ROUND_UP(width * bpp, 8);
  5378. return ALIGN(pitch, 64);
  5379. }
  5380. static u32
  5381. intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp)
  5382. {
  5383. u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp);
  5384. return ALIGN(pitch * mode->vdisplay, PAGE_SIZE);
  5385. }
  5386. static struct drm_framebuffer *
  5387. intel_framebuffer_create_for_mode(struct drm_device *dev,
  5388. struct drm_display_mode *mode,
  5389. int depth, int bpp)
  5390. {
  5391. struct drm_i915_gem_object *obj;
  5392. struct drm_mode_fb_cmd2 mode_cmd = { 0 };
  5393. obj = i915_gem_alloc_object(dev,
  5394. intel_framebuffer_size_for_mode(mode, bpp));
  5395. if (obj == NULL)
  5396. return ERR_PTR(-ENOMEM);
  5397. mode_cmd.width = mode->hdisplay;
  5398. mode_cmd.height = mode->vdisplay;
  5399. mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width,
  5400. bpp);
  5401. mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth);
  5402. return intel_framebuffer_create(dev, &mode_cmd, obj);
  5403. }
  5404. static struct drm_framebuffer *
  5405. mode_fits_in_fbdev(struct drm_device *dev,
  5406. struct drm_display_mode *mode)
  5407. {
  5408. struct drm_i915_private *dev_priv = dev->dev_private;
  5409. struct drm_i915_gem_object *obj;
  5410. struct drm_framebuffer *fb;
  5411. if (dev_priv->fbdev == NULL)
  5412. return NULL;
  5413. obj = dev_priv->fbdev->ifb.obj;
  5414. if (obj == NULL)
  5415. return NULL;
  5416. fb = &dev_priv->fbdev->ifb.base;
  5417. if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay,
  5418. fb->bits_per_pixel))
  5419. return NULL;
  5420. if (obj->base.size < mode->vdisplay * fb->pitches[0])
  5421. return NULL;
  5422. return fb;
  5423. }
  5424. bool intel_get_load_detect_pipe(struct drm_connector *connector,
  5425. struct drm_display_mode *mode,
  5426. struct intel_load_detect_pipe *old)
  5427. {
  5428. struct intel_crtc *intel_crtc;
  5429. struct intel_encoder *intel_encoder =
  5430. intel_attached_encoder(connector);
  5431. struct drm_crtc *possible_crtc;
  5432. struct drm_encoder *encoder = &intel_encoder->base;
  5433. struct drm_crtc *crtc = NULL;
  5434. struct drm_device *dev = encoder->dev;
  5435. struct drm_framebuffer *fb;
  5436. int i = -1;
  5437. DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  5438. connector->base.id, drm_get_connector_name(connector),
  5439. encoder->base.id, drm_get_encoder_name(encoder));
  5440. /*
  5441. * Algorithm gets a little messy:
  5442. *
  5443. * - if the connector already has an assigned crtc, use it (but make
  5444. * sure it's on first)
  5445. *
  5446. * - try to find the first unused crtc that can drive this connector,
  5447. * and use that if we find one
  5448. */
  5449. /* See if we already have a CRTC for this connector */
  5450. if (encoder->crtc) {
  5451. crtc = encoder->crtc;
  5452. old->dpms_mode = connector->dpms;
  5453. old->load_detect_temp = false;
  5454. /* Make sure the crtc and connector are running */
  5455. if (connector->dpms != DRM_MODE_DPMS_ON)
  5456. connector->funcs->dpms(connector, DRM_MODE_DPMS_ON);
  5457. return true;
  5458. }
  5459. /* Find an unused one (if possible) */
  5460. list_for_each_entry(possible_crtc, &dev->mode_config.crtc_list, head) {
  5461. i++;
  5462. if (!(encoder->possible_crtcs & (1 << i)))
  5463. continue;
  5464. if (!possible_crtc->enabled) {
  5465. crtc = possible_crtc;
  5466. break;
  5467. }
  5468. }
  5469. /*
  5470. * If we didn't find an unused CRTC, don't use any.
  5471. */
  5472. if (!crtc) {
  5473. DRM_DEBUG_KMS("no pipe available for load-detect\n");
  5474. return false;
  5475. }
  5476. intel_encoder->new_crtc = to_intel_crtc(crtc);
  5477. to_intel_connector(connector)->new_encoder = intel_encoder;
  5478. intel_crtc = to_intel_crtc(crtc);
  5479. old->dpms_mode = connector->dpms;
  5480. old->load_detect_temp = true;
  5481. old->release_fb = NULL;
  5482. if (!mode)
  5483. mode = &load_detect_mode;
  5484. /* We need a framebuffer large enough to accommodate all accesses
  5485. * that the plane may generate whilst we perform load detection.
  5486. * We can not rely on the fbcon either being present (we get called
  5487. * during its initialisation to detect all boot displays, or it may
  5488. * not even exist) or that it is large enough to satisfy the
  5489. * requested mode.
  5490. */
  5491. fb = mode_fits_in_fbdev(dev, mode);
  5492. if (fb == NULL) {
  5493. DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
  5494. fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32);
  5495. old->release_fb = fb;
  5496. } else
  5497. DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
  5498. if (IS_ERR(fb)) {
  5499. DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
  5500. return false;
  5501. }
  5502. if (intel_set_mode(crtc, mode, 0, 0, fb)) {
  5503. DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
  5504. if (old->release_fb)
  5505. old->release_fb->funcs->destroy(old->release_fb);
  5506. return false;
  5507. }
  5508. /* let the connector get through one full cycle before testing */
  5509. intel_wait_for_vblank(dev, intel_crtc->pipe);
  5510. return true;
  5511. }
  5512. void intel_release_load_detect_pipe(struct drm_connector *connector,
  5513. struct intel_load_detect_pipe *old)
  5514. {
  5515. struct intel_encoder *intel_encoder =
  5516. intel_attached_encoder(connector);
  5517. struct drm_encoder *encoder = &intel_encoder->base;
  5518. DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  5519. connector->base.id, drm_get_connector_name(connector),
  5520. encoder->base.id, drm_get_encoder_name(encoder));
  5521. if (old->load_detect_temp) {
  5522. struct drm_crtc *crtc = encoder->crtc;
  5523. to_intel_connector(connector)->new_encoder = NULL;
  5524. intel_encoder->new_crtc = NULL;
  5525. intel_set_mode(crtc, NULL, 0, 0, NULL);
  5526. if (old->release_fb)
  5527. old->release_fb->funcs->destroy(old->release_fb);
  5528. return;
  5529. }
  5530. /* Switch crtc and encoder back off if necessary */
  5531. if (old->dpms_mode != DRM_MODE_DPMS_ON)
  5532. connector->funcs->dpms(connector, old->dpms_mode);
  5533. }
  5534. /* Returns the clock of the currently programmed mode of the given pipe. */
  5535. static int intel_crtc_clock_get(struct drm_device *dev, struct drm_crtc *crtc)
  5536. {
  5537. struct drm_i915_private *dev_priv = dev->dev_private;
  5538. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5539. int pipe = intel_crtc->pipe;
  5540. u32 dpll = I915_READ(DPLL(pipe));
  5541. u32 fp;
  5542. intel_clock_t clock;
  5543. if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
  5544. fp = I915_READ(FP0(pipe));
  5545. else
  5546. fp = I915_READ(FP1(pipe));
  5547. clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
  5548. if (IS_PINEVIEW(dev)) {
  5549. clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
  5550. clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
  5551. } else {
  5552. clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
  5553. clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
  5554. }
  5555. if (!IS_GEN2(dev)) {
  5556. if (IS_PINEVIEW(dev))
  5557. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
  5558. DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
  5559. else
  5560. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
  5561. DPLL_FPA01_P1_POST_DIV_SHIFT);
  5562. switch (dpll & DPLL_MODE_MASK) {
  5563. case DPLLB_MODE_DAC_SERIAL:
  5564. clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
  5565. 5 : 10;
  5566. break;
  5567. case DPLLB_MODE_LVDS:
  5568. clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
  5569. 7 : 14;
  5570. break;
  5571. default:
  5572. DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
  5573. "mode\n", (int)(dpll & DPLL_MODE_MASK));
  5574. return 0;
  5575. }
  5576. /* XXX: Handle the 100Mhz refclk */
  5577. intel_clock(dev, 96000, &clock);
  5578. } else {
  5579. bool is_lvds = (pipe == 1) && (I915_READ(LVDS) & LVDS_PORT_EN);
  5580. if (is_lvds) {
  5581. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
  5582. DPLL_FPA01_P1_POST_DIV_SHIFT);
  5583. clock.p2 = 14;
  5584. if ((dpll & PLL_REF_INPUT_MASK) ==
  5585. PLLB_REF_INPUT_SPREADSPECTRUMIN) {
  5586. /* XXX: might not be 66MHz */
  5587. intel_clock(dev, 66000, &clock);
  5588. } else
  5589. intel_clock(dev, 48000, &clock);
  5590. } else {
  5591. if (dpll & PLL_P1_DIVIDE_BY_TWO)
  5592. clock.p1 = 2;
  5593. else {
  5594. clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
  5595. DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
  5596. }
  5597. if (dpll & PLL_P2_DIVIDE_BY_4)
  5598. clock.p2 = 4;
  5599. else
  5600. clock.p2 = 2;
  5601. intel_clock(dev, 48000, &clock);
  5602. }
  5603. }
  5604. /* XXX: It would be nice to validate the clocks, but we can't reuse
  5605. * i830PllIsValid() because it relies on the xf86_config connector
  5606. * configuration being accurate, which it isn't necessarily.
  5607. */
  5608. return clock.dot;
  5609. }
  5610. /** Returns the currently programmed mode of the given pipe. */
  5611. struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
  5612. struct drm_crtc *crtc)
  5613. {
  5614. struct drm_i915_private *dev_priv = dev->dev_private;
  5615. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5616. enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
  5617. struct drm_display_mode *mode;
  5618. int htot = I915_READ(HTOTAL(cpu_transcoder));
  5619. int hsync = I915_READ(HSYNC(cpu_transcoder));
  5620. int vtot = I915_READ(VTOTAL(cpu_transcoder));
  5621. int vsync = I915_READ(VSYNC(cpu_transcoder));
  5622. mode = kzalloc(sizeof(*mode), GFP_KERNEL);
  5623. if (!mode)
  5624. return NULL;
  5625. mode->clock = intel_crtc_clock_get(dev, crtc);
  5626. mode->hdisplay = (htot & 0xffff) + 1;
  5627. mode->htotal = ((htot & 0xffff0000) >> 16) + 1;
  5628. mode->hsync_start = (hsync & 0xffff) + 1;
  5629. mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1;
  5630. mode->vdisplay = (vtot & 0xffff) + 1;
  5631. mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1;
  5632. mode->vsync_start = (vsync & 0xffff) + 1;
  5633. mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1;
  5634. drm_mode_set_name(mode);
  5635. return mode;
  5636. }
  5637. static void intel_increase_pllclock(struct drm_crtc *crtc)
  5638. {
  5639. struct drm_device *dev = crtc->dev;
  5640. drm_i915_private_t *dev_priv = dev->dev_private;
  5641. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5642. int pipe = intel_crtc->pipe;
  5643. int dpll_reg = DPLL(pipe);
  5644. int dpll;
  5645. if (HAS_PCH_SPLIT(dev))
  5646. return;
  5647. if (!dev_priv->lvds_downclock_avail)
  5648. return;
  5649. dpll = I915_READ(dpll_reg);
  5650. if (!HAS_PIPE_CXSR(dev) && (dpll & DISPLAY_RATE_SELECT_FPA1)) {
  5651. DRM_DEBUG_DRIVER("upclocking LVDS\n");
  5652. assert_panel_unlocked(dev_priv, pipe);
  5653. dpll &= ~DISPLAY_RATE_SELECT_FPA1;
  5654. I915_WRITE(dpll_reg, dpll);
  5655. intel_wait_for_vblank(dev, pipe);
  5656. dpll = I915_READ(dpll_reg);
  5657. if (dpll & DISPLAY_RATE_SELECT_FPA1)
  5658. DRM_DEBUG_DRIVER("failed to upclock LVDS!\n");
  5659. }
  5660. }
  5661. static void intel_decrease_pllclock(struct drm_crtc *crtc)
  5662. {
  5663. struct drm_device *dev = crtc->dev;
  5664. drm_i915_private_t *dev_priv = dev->dev_private;
  5665. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5666. if (HAS_PCH_SPLIT(dev))
  5667. return;
  5668. if (!dev_priv->lvds_downclock_avail)
  5669. return;
  5670. /*
  5671. * Since this is called by a timer, we should never get here in
  5672. * the manual case.
  5673. */
  5674. if (!HAS_PIPE_CXSR(dev) && intel_crtc->lowfreq_avail) {
  5675. int pipe = intel_crtc->pipe;
  5676. int dpll_reg = DPLL(pipe);
  5677. int dpll;
  5678. DRM_DEBUG_DRIVER("downclocking LVDS\n");
  5679. assert_panel_unlocked(dev_priv, pipe);
  5680. dpll = I915_READ(dpll_reg);
  5681. dpll |= DISPLAY_RATE_SELECT_FPA1;
  5682. I915_WRITE(dpll_reg, dpll);
  5683. intel_wait_for_vblank(dev, pipe);
  5684. dpll = I915_READ(dpll_reg);
  5685. if (!(dpll & DISPLAY_RATE_SELECT_FPA1))
  5686. DRM_DEBUG_DRIVER("failed to downclock LVDS!\n");
  5687. }
  5688. }
  5689. void intel_mark_busy(struct drm_device *dev)
  5690. {
  5691. i915_update_gfx_val(dev->dev_private);
  5692. }
  5693. void intel_mark_idle(struct drm_device *dev)
  5694. {
  5695. }
  5696. void intel_mark_fb_busy(struct drm_i915_gem_object *obj)
  5697. {
  5698. struct drm_device *dev = obj->base.dev;
  5699. struct drm_crtc *crtc;
  5700. if (!i915_powersave)
  5701. return;
  5702. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  5703. if (!crtc->fb)
  5704. continue;
  5705. if (to_intel_framebuffer(crtc->fb)->obj == obj)
  5706. intel_increase_pllclock(crtc);
  5707. }
  5708. }
  5709. void intel_mark_fb_idle(struct drm_i915_gem_object *obj)
  5710. {
  5711. struct drm_device *dev = obj->base.dev;
  5712. struct drm_crtc *crtc;
  5713. if (!i915_powersave)
  5714. return;
  5715. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  5716. if (!crtc->fb)
  5717. continue;
  5718. if (to_intel_framebuffer(crtc->fb)->obj == obj)
  5719. intel_decrease_pllclock(crtc);
  5720. }
  5721. }
  5722. static void intel_crtc_destroy(struct drm_crtc *crtc)
  5723. {
  5724. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5725. struct drm_device *dev = crtc->dev;
  5726. struct intel_unpin_work *work;
  5727. unsigned long flags;
  5728. spin_lock_irqsave(&dev->event_lock, flags);
  5729. work = intel_crtc->unpin_work;
  5730. intel_crtc->unpin_work = NULL;
  5731. spin_unlock_irqrestore(&dev->event_lock, flags);
  5732. if (work) {
  5733. cancel_work_sync(&work->work);
  5734. kfree(work);
  5735. }
  5736. drm_crtc_cleanup(crtc);
  5737. kfree(intel_crtc);
  5738. }
  5739. static void intel_unpin_work_fn(struct work_struct *__work)
  5740. {
  5741. struct intel_unpin_work *work =
  5742. container_of(__work, struct intel_unpin_work, work);
  5743. struct drm_device *dev = work->crtc->dev;
  5744. mutex_lock(&dev->struct_mutex);
  5745. intel_unpin_fb_obj(work->old_fb_obj);
  5746. drm_gem_object_unreference(&work->pending_flip_obj->base);
  5747. drm_gem_object_unreference(&work->old_fb_obj->base);
  5748. intel_update_fbc(dev);
  5749. mutex_unlock(&dev->struct_mutex);
  5750. BUG_ON(atomic_read(&to_intel_crtc(work->crtc)->unpin_work_count) == 0);
  5751. atomic_dec(&to_intel_crtc(work->crtc)->unpin_work_count);
  5752. kfree(work);
  5753. }
  5754. static void do_intel_finish_page_flip(struct drm_device *dev,
  5755. struct drm_crtc *crtc)
  5756. {
  5757. drm_i915_private_t *dev_priv = dev->dev_private;
  5758. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5759. struct intel_unpin_work *work;
  5760. struct drm_i915_gem_object *obj;
  5761. unsigned long flags;
  5762. /* Ignore early vblank irqs */
  5763. if (intel_crtc == NULL)
  5764. return;
  5765. spin_lock_irqsave(&dev->event_lock, flags);
  5766. work = intel_crtc->unpin_work;
  5767. /* Ensure we don't miss a work->pending update ... */
  5768. smp_rmb();
  5769. if (work == NULL || atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
  5770. spin_unlock_irqrestore(&dev->event_lock, flags);
  5771. return;
  5772. }
  5773. /* and that the unpin work is consistent wrt ->pending. */
  5774. smp_rmb();
  5775. intel_crtc->unpin_work = NULL;
  5776. if (work->event)
  5777. drm_send_vblank_event(dev, intel_crtc->pipe, work->event);
  5778. drm_vblank_put(dev, intel_crtc->pipe);
  5779. spin_unlock_irqrestore(&dev->event_lock, flags);
  5780. obj = work->old_fb_obj;
  5781. wake_up_all(&dev_priv->pending_flip_queue);
  5782. queue_work(dev_priv->wq, &work->work);
  5783. trace_i915_flip_complete(intel_crtc->plane, work->pending_flip_obj);
  5784. }
  5785. void intel_finish_page_flip(struct drm_device *dev, int pipe)
  5786. {
  5787. drm_i915_private_t *dev_priv = dev->dev_private;
  5788. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  5789. do_intel_finish_page_flip(dev, crtc);
  5790. }
  5791. void intel_finish_page_flip_plane(struct drm_device *dev, int plane)
  5792. {
  5793. drm_i915_private_t *dev_priv = dev->dev_private;
  5794. struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane];
  5795. do_intel_finish_page_flip(dev, crtc);
  5796. }
  5797. void intel_prepare_page_flip(struct drm_device *dev, int plane)
  5798. {
  5799. drm_i915_private_t *dev_priv = dev->dev_private;
  5800. struct intel_crtc *intel_crtc =
  5801. to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]);
  5802. unsigned long flags;
  5803. /* NB: An MMIO update of the plane base pointer will also
  5804. * generate a page-flip completion irq, i.e. every modeset
  5805. * is also accompanied by a spurious intel_prepare_page_flip().
  5806. */
  5807. spin_lock_irqsave(&dev->event_lock, flags);
  5808. if (intel_crtc->unpin_work)
  5809. atomic_inc_not_zero(&intel_crtc->unpin_work->pending);
  5810. spin_unlock_irqrestore(&dev->event_lock, flags);
  5811. }
  5812. inline static void intel_mark_page_flip_active(struct intel_crtc *intel_crtc)
  5813. {
  5814. /* Ensure that the work item is consistent when activating it ... */
  5815. smp_wmb();
  5816. atomic_set(&intel_crtc->unpin_work->pending, INTEL_FLIP_PENDING);
  5817. /* and that it is marked active as soon as the irq could fire. */
  5818. smp_wmb();
  5819. }
  5820. static int intel_gen2_queue_flip(struct drm_device *dev,
  5821. struct drm_crtc *crtc,
  5822. struct drm_framebuffer *fb,
  5823. struct drm_i915_gem_object *obj)
  5824. {
  5825. struct drm_i915_private *dev_priv = dev->dev_private;
  5826. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5827. u32 flip_mask;
  5828. struct intel_ring_buffer *ring = &dev_priv->ring[RCS];
  5829. int ret;
  5830. ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
  5831. if (ret)
  5832. goto err;
  5833. ret = intel_ring_begin(ring, 6);
  5834. if (ret)
  5835. goto err_unpin;
  5836. /* Can't queue multiple flips, so wait for the previous
  5837. * one to finish before executing the next.
  5838. */
  5839. if (intel_crtc->plane)
  5840. flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
  5841. else
  5842. flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
  5843. intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask);
  5844. intel_ring_emit(ring, MI_NOOP);
  5845. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  5846. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  5847. intel_ring_emit(ring, fb->pitches[0]);
  5848. intel_ring_emit(ring, obj->gtt_offset + intel_crtc->dspaddr_offset);
  5849. intel_ring_emit(ring, 0); /* aux display base address, unused */
  5850. intel_mark_page_flip_active(intel_crtc);
  5851. intel_ring_advance(ring);
  5852. return 0;
  5853. err_unpin:
  5854. intel_unpin_fb_obj(obj);
  5855. err:
  5856. return ret;
  5857. }
  5858. static int intel_gen3_queue_flip(struct drm_device *dev,
  5859. struct drm_crtc *crtc,
  5860. struct drm_framebuffer *fb,
  5861. struct drm_i915_gem_object *obj)
  5862. {
  5863. struct drm_i915_private *dev_priv = dev->dev_private;
  5864. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5865. u32 flip_mask;
  5866. struct intel_ring_buffer *ring = &dev_priv->ring[RCS];
  5867. int ret;
  5868. ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
  5869. if (ret)
  5870. goto err;
  5871. ret = intel_ring_begin(ring, 6);
  5872. if (ret)
  5873. goto err_unpin;
  5874. if (intel_crtc->plane)
  5875. flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
  5876. else
  5877. flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
  5878. intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask);
  5879. intel_ring_emit(ring, MI_NOOP);
  5880. intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 |
  5881. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  5882. intel_ring_emit(ring, fb->pitches[0]);
  5883. intel_ring_emit(ring, obj->gtt_offset + intel_crtc->dspaddr_offset);
  5884. intel_ring_emit(ring, MI_NOOP);
  5885. intel_mark_page_flip_active(intel_crtc);
  5886. intel_ring_advance(ring);
  5887. return 0;
  5888. err_unpin:
  5889. intel_unpin_fb_obj(obj);
  5890. err:
  5891. return ret;
  5892. }
  5893. static int intel_gen4_queue_flip(struct drm_device *dev,
  5894. struct drm_crtc *crtc,
  5895. struct drm_framebuffer *fb,
  5896. struct drm_i915_gem_object *obj)
  5897. {
  5898. struct drm_i915_private *dev_priv = dev->dev_private;
  5899. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5900. uint32_t pf, pipesrc;
  5901. struct intel_ring_buffer *ring = &dev_priv->ring[RCS];
  5902. int ret;
  5903. ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
  5904. if (ret)
  5905. goto err;
  5906. ret = intel_ring_begin(ring, 4);
  5907. if (ret)
  5908. goto err_unpin;
  5909. /* i965+ uses the linear or tiled offsets from the
  5910. * Display Registers (which do not change across a page-flip)
  5911. * so we need only reprogram the base address.
  5912. */
  5913. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  5914. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  5915. intel_ring_emit(ring, fb->pitches[0]);
  5916. intel_ring_emit(ring,
  5917. (obj->gtt_offset + intel_crtc->dspaddr_offset) |
  5918. obj->tiling_mode);
  5919. /* XXX Enabling the panel-fitter across page-flip is so far
  5920. * untested on non-native modes, so ignore it for now.
  5921. * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE;
  5922. */
  5923. pf = 0;
  5924. pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
  5925. intel_ring_emit(ring, pf | pipesrc);
  5926. intel_mark_page_flip_active(intel_crtc);
  5927. intel_ring_advance(ring);
  5928. return 0;
  5929. err_unpin:
  5930. intel_unpin_fb_obj(obj);
  5931. err:
  5932. return ret;
  5933. }
  5934. static int intel_gen6_queue_flip(struct drm_device *dev,
  5935. struct drm_crtc *crtc,
  5936. struct drm_framebuffer *fb,
  5937. struct drm_i915_gem_object *obj)
  5938. {
  5939. struct drm_i915_private *dev_priv = dev->dev_private;
  5940. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5941. struct intel_ring_buffer *ring = &dev_priv->ring[RCS];
  5942. uint32_t pf, pipesrc;
  5943. int ret;
  5944. ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
  5945. if (ret)
  5946. goto err;
  5947. ret = intel_ring_begin(ring, 4);
  5948. if (ret)
  5949. goto err_unpin;
  5950. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  5951. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  5952. intel_ring_emit(ring, fb->pitches[0] | obj->tiling_mode);
  5953. intel_ring_emit(ring, obj->gtt_offset + intel_crtc->dspaddr_offset);
  5954. /* Contrary to the suggestions in the documentation,
  5955. * "Enable Panel Fitter" does not seem to be required when page
  5956. * flipping with a non-native mode, and worse causes a normal
  5957. * modeset to fail.
  5958. * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
  5959. */
  5960. pf = 0;
  5961. pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
  5962. intel_ring_emit(ring, pf | pipesrc);
  5963. intel_mark_page_flip_active(intel_crtc);
  5964. intel_ring_advance(ring);
  5965. return 0;
  5966. err_unpin:
  5967. intel_unpin_fb_obj(obj);
  5968. err:
  5969. return ret;
  5970. }
  5971. /*
  5972. * On gen7 we currently use the blit ring because (in early silicon at least)
  5973. * the render ring doesn't give us interrpts for page flip completion, which
  5974. * means clients will hang after the first flip is queued. Fortunately the
  5975. * blit ring generates interrupts properly, so use it instead.
  5976. */
  5977. static int intel_gen7_queue_flip(struct drm_device *dev,
  5978. struct drm_crtc *crtc,
  5979. struct drm_framebuffer *fb,
  5980. struct drm_i915_gem_object *obj)
  5981. {
  5982. struct drm_i915_private *dev_priv = dev->dev_private;
  5983. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5984. struct intel_ring_buffer *ring = &dev_priv->ring[BCS];
  5985. uint32_t plane_bit = 0;
  5986. int ret;
  5987. ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
  5988. if (ret)
  5989. goto err;
  5990. switch(intel_crtc->plane) {
  5991. case PLANE_A:
  5992. plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_A;
  5993. break;
  5994. case PLANE_B:
  5995. plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_B;
  5996. break;
  5997. case PLANE_C:
  5998. plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_C;
  5999. break;
  6000. default:
  6001. WARN_ONCE(1, "unknown plane in flip command\n");
  6002. ret = -ENODEV;
  6003. goto err_unpin;
  6004. }
  6005. ret = intel_ring_begin(ring, 4);
  6006. if (ret)
  6007. goto err_unpin;
  6008. intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | plane_bit);
  6009. intel_ring_emit(ring, (fb->pitches[0] | obj->tiling_mode));
  6010. intel_ring_emit(ring, obj->gtt_offset + intel_crtc->dspaddr_offset);
  6011. intel_ring_emit(ring, (MI_NOOP));
  6012. intel_mark_page_flip_active(intel_crtc);
  6013. intel_ring_advance(ring);
  6014. return 0;
  6015. err_unpin:
  6016. intel_unpin_fb_obj(obj);
  6017. err:
  6018. return ret;
  6019. }
  6020. static int intel_default_queue_flip(struct drm_device *dev,
  6021. struct drm_crtc *crtc,
  6022. struct drm_framebuffer *fb,
  6023. struct drm_i915_gem_object *obj)
  6024. {
  6025. return -ENODEV;
  6026. }
  6027. static int intel_crtc_page_flip(struct drm_crtc *crtc,
  6028. struct drm_framebuffer *fb,
  6029. struct drm_pending_vblank_event *event)
  6030. {
  6031. struct drm_device *dev = crtc->dev;
  6032. struct drm_i915_private *dev_priv = dev->dev_private;
  6033. struct intel_framebuffer *intel_fb;
  6034. struct drm_i915_gem_object *obj;
  6035. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6036. struct intel_unpin_work *work;
  6037. unsigned long flags;
  6038. int ret;
  6039. /* Can't change pixel format via MI display flips. */
  6040. if (fb->pixel_format != crtc->fb->pixel_format)
  6041. return -EINVAL;
  6042. /*
  6043. * TILEOFF/LINOFF registers can't be changed via MI display flips.
  6044. * Note that pitch changes could also affect these register.
  6045. */
  6046. if (INTEL_INFO(dev)->gen > 3 &&
  6047. (fb->offsets[0] != crtc->fb->offsets[0] ||
  6048. fb->pitches[0] != crtc->fb->pitches[0]))
  6049. return -EINVAL;
  6050. work = kzalloc(sizeof *work, GFP_KERNEL);
  6051. if (work == NULL)
  6052. return -ENOMEM;
  6053. work->event = event;
  6054. work->crtc = crtc;
  6055. intel_fb = to_intel_framebuffer(crtc->fb);
  6056. work->old_fb_obj = intel_fb->obj;
  6057. INIT_WORK(&work->work, intel_unpin_work_fn);
  6058. ret = drm_vblank_get(dev, intel_crtc->pipe);
  6059. if (ret)
  6060. goto free_work;
  6061. /* We borrow the event spin lock for protecting unpin_work */
  6062. spin_lock_irqsave(&dev->event_lock, flags);
  6063. if (intel_crtc->unpin_work) {
  6064. spin_unlock_irqrestore(&dev->event_lock, flags);
  6065. kfree(work);
  6066. drm_vblank_put(dev, intel_crtc->pipe);
  6067. DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
  6068. return -EBUSY;
  6069. }
  6070. intel_crtc->unpin_work = work;
  6071. spin_unlock_irqrestore(&dev->event_lock, flags);
  6072. intel_fb = to_intel_framebuffer(fb);
  6073. obj = intel_fb->obj;
  6074. if (atomic_read(&intel_crtc->unpin_work_count) >= 2)
  6075. flush_workqueue(dev_priv->wq);
  6076. ret = i915_mutex_lock_interruptible(dev);
  6077. if (ret)
  6078. goto cleanup;
  6079. /* Reference the objects for the scheduled work. */
  6080. drm_gem_object_reference(&work->old_fb_obj->base);
  6081. drm_gem_object_reference(&obj->base);
  6082. crtc->fb = fb;
  6083. work->pending_flip_obj = obj;
  6084. work->enable_stall_check = true;
  6085. atomic_inc(&intel_crtc->unpin_work_count);
  6086. ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
  6087. if (ret)
  6088. goto cleanup_pending;
  6089. intel_disable_fbc(dev);
  6090. intel_mark_fb_busy(obj);
  6091. mutex_unlock(&dev->struct_mutex);
  6092. trace_i915_flip_request(intel_crtc->plane, obj);
  6093. return 0;
  6094. cleanup_pending:
  6095. atomic_dec(&intel_crtc->unpin_work_count);
  6096. drm_gem_object_unreference(&work->old_fb_obj->base);
  6097. drm_gem_object_unreference(&obj->base);
  6098. mutex_unlock(&dev->struct_mutex);
  6099. cleanup:
  6100. spin_lock_irqsave(&dev->event_lock, flags);
  6101. intel_crtc->unpin_work = NULL;
  6102. spin_unlock_irqrestore(&dev->event_lock, flags);
  6103. drm_vblank_put(dev, intel_crtc->pipe);
  6104. free_work:
  6105. kfree(work);
  6106. return ret;
  6107. }
  6108. static struct drm_crtc_helper_funcs intel_helper_funcs = {
  6109. .mode_set_base_atomic = intel_pipe_set_base_atomic,
  6110. .load_lut = intel_crtc_load_lut,
  6111. .disable = intel_crtc_noop,
  6112. };
  6113. bool intel_encoder_check_is_cloned(struct intel_encoder *encoder)
  6114. {
  6115. struct intel_encoder *other_encoder;
  6116. struct drm_crtc *crtc = &encoder->new_crtc->base;
  6117. if (WARN_ON(!crtc))
  6118. return false;
  6119. list_for_each_entry(other_encoder,
  6120. &crtc->dev->mode_config.encoder_list,
  6121. base.head) {
  6122. if (&other_encoder->new_crtc->base != crtc ||
  6123. encoder == other_encoder)
  6124. continue;
  6125. else
  6126. return true;
  6127. }
  6128. return false;
  6129. }
  6130. static bool intel_encoder_crtc_ok(struct drm_encoder *encoder,
  6131. struct drm_crtc *crtc)
  6132. {
  6133. struct drm_device *dev;
  6134. struct drm_crtc *tmp;
  6135. int crtc_mask = 1;
  6136. WARN(!crtc, "checking null crtc?\n");
  6137. dev = crtc->dev;
  6138. list_for_each_entry(tmp, &dev->mode_config.crtc_list, head) {
  6139. if (tmp == crtc)
  6140. break;
  6141. crtc_mask <<= 1;
  6142. }
  6143. if (encoder->possible_crtcs & crtc_mask)
  6144. return true;
  6145. return false;
  6146. }
  6147. /**
  6148. * intel_modeset_update_staged_output_state
  6149. *
  6150. * Updates the staged output configuration state, e.g. after we've read out the
  6151. * current hw state.
  6152. */
  6153. static void intel_modeset_update_staged_output_state(struct drm_device *dev)
  6154. {
  6155. struct intel_encoder *encoder;
  6156. struct intel_connector *connector;
  6157. list_for_each_entry(connector, &dev->mode_config.connector_list,
  6158. base.head) {
  6159. connector->new_encoder =
  6160. to_intel_encoder(connector->base.encoder);
  6161. }
  6162. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  6163. base.head) {
  6164. encoder->new_crtc =
  6165. to_intel_crtc(encoder->base.crtc);
  6166. }
  6167. }
  6168. /**
  6169. * intel_modeset_commit_output_state
  6170. *
  6171. * This function copies the stage display pipe configuration to the real one.
  6172. */
  6173. static void intel_modeset_commit_output_state(struct drm_device *dev)
  6174. {
  6175. struct intel_encoder *encoder;
  6176. struct intel_connector *connector;
  6177. list_for_each_entry(connector, &dev->mode_config.connector_list,
  6178. base.head) {
  6179. connector->base.encoder = &connector->new_encoder->base;
  6180. }
  6181. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  6182. base.head) {
  6183. encoder->base.crtc = &encoder->new_crtc->base;
  6184. }
  6185. }
  6186. static struct drm_display_mode *
  6187. intel_modeset_adjusted_mode(struct drm_crtc *crtc,
  6188. struct drm_display_mode *mode)
  6189. {
  6190. struct drm_device *dev = crtc->dev;
  6191. struct drm_display_mode *adjusted_mode;
  6192. struct drm_encoder_helper_funcs *encoder_funcs;
  6193. struct intel_encoder *encoder;
  6194. adjusted_mode = drm_mode_duplicate(dev, mode);
  6195. if (!adjusted_mode)
  6196. return ERR_PTR(-ENOMEM);
  6197. /* Pass our mode to the connectors and the CRTC to give them a chance to
  6198. * adjust it according to limitations or connector properties, and also
  6199. * a chance to reject the mode entirely.
  6200. */
  6201. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  6202. base.head) {
  6203. if (&encoder->new_crtc->base != crtc)
  6204. continue;
  6205. encoder_funcs = encoder->base.helper_private;
  6206. if (!(encoder_funcs->mode_fixup(&encoder->base, mode,
  6207. adjusted_mode))) {
  6208. DRM_DEBUG_KMS("Encoder fixup failed\n");
  6209. goto fail;
  6210. }
  6211. }
  6212. if (!(intel_crtc_mode_fixup(crtc, mode, adjusted_mode))) {
  6213. DRM_DEBUG_KMS("CRTC fixup failed\n");
  6214. goto fail;
  6215. }
  6216. DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id);
  6217. return adjusted_mode;
  6218. fail:
  6219. drm_mode_destroy(dev, adjusted_mode);
  6220. return ERR_PTR(-EINVAL);
  6221. }
  6222. /* Computes which crtcs are affected and sets the relevant bits in the mask. For
  6223. * simplicity we use the crtc's pipe number (because it's easier to obtain). */
  6224. static void
  6225. intel_modeset_affected_pipes(struct drm_crtc *crtc, unsigned *modeset_pipes,
  6226. unsigned *prepare_pipes, unsigned *disable_pipes)
  6227. {
  6228. struct intel_crtc *intel_crtc;
  6229. struct drm_device *dev = crtc->dev;
  6230. struct intel_encoder *encoder;
  6231. struct intel_connector *connector;
  6232. struct drm_crtc *tmp_crtc;
  6233. *disable_pipes = *modeset_pipes = *prepare_pipes = 0;
  6234. /* Check which crtcs have changed outputs connected to them, these need
  6235. * to be part of the prepare_pipes mask. We don't (yet) support global
  6236. * modeset across multiple crtcs, so modeset_pipes will only have one
  6237. * bit set at most. */
  6238. list_for_each_entry(connector, &dev->mode_config.connector_list,
  6239. base.head) {
  6240. if (connector->base.encoder == &connector->new_encoder->base)
  6241. continue;
  6242. if (connector->base.encoder) {
  6243. tmp_crtc = connector->base.encoder->crtc;
  6244. *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe;
  6245. }
  6246. if (connector->new_encoder)
  6247. *prepare_pipes |=
  6248. 1 << connector->new_encoder->new_crtc->pipe;
  6249. }
  6250. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  6251. base.head) {
  6252. if (encoder->base.crtc == &encoder->new_crtc->base)
  6253. continue;
  6254. if (encoder->base.crtc) {
  6255. tmp_crtc = encoder->base.crtc;
  6256. *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe;
  6257. }
  6258. if (encoder->new_crtc)
  6259. *prepare_pipes |= 1 << encoder->new_crtc->pipe;
  6260. }
  6261. /* Check for any pipes that will be fully disabled ... */
  6262. list_for_each_entry(intel_crtc, &dev->mode_config.crtc_list,
  6263. base.head) {
  6264. bool used = false;
  6265. /* Don't try to disable disabled crtcs. */
  6266. if (!intel_crtc->base.enabled)
  6267. continue;
  6268. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  6269. base.head) {
  6270. if (encoder->new_crtc == intel_crtc)
  6271. used = true;
  6272. }
  6273. if (!used)
  6274. *disable_pipes |= 1 << intel_crtc->pipe;
  6275. }
  6276. /* set_mode is also used to update properties on life display pipes. */
  6277. intel_crtc = to_intel_crtc(crtc);
  6278. if (crtc->enabled)
  6279. *prepare_pipes |= 1 << intel_crtc->pipe;
  6280. /* We only support modeset on one single crtc, hence we need to do that
  6281. * only for the passed in crtc iff we change anything else than just
  6282. * disable crtcs.
  6283. *
  6284. * This is actually not true, to be fully compatible with the old crtc
  6285. * helper we automatically disable _any_ output (i.e. doesn't need to be
  6286. * connected to the crtc we're modesetting on) if it's disconnected.
  6287. * Which is a rather nutty api (since changed the output configuration
  6288. * without userspace's explicit request can lead to confusion), but
  6289. * alas. Hence we currently need to modeset on all pipes we prepare. */
  6290. if (*prepare_pipes)
  6291. *modeset_pipes = *prepare_pipes;
  6292. /* ... and mask these out. */
  6293. *modeset_pipes &= ~(*disable_pipes);
  6294. *prepare_pipes &= ~(*disable_pipes);
  6295. }
  6296. static bool intel_crtc_in_use(struct drm_crtc *crtc)
  6297. {
  6298. struct drm_encoder *encoder;
  6299. struct drm_device *dev = crtc->dev;
  6300. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head)
  6301. if (encoder->crtc == crtc)
  6302. return true;
  6303. return false;
  6304. }
  6305. static void
  6306. intel_modeset_update_state(struct drm_device *dev, unsigned prepare_pipes)
  6307. {
  6308. struct intel_encoder *intel_encoder;
  6309. struct intel_crtc *intel_crtc;
  6310. struct drm_connector *connector;
  6311. list_for_each_entry(intel_encoder, &dev->mode_config.encoder_list,
  6312. base.head) {
  6313. if (!intel_encoder->base.crtc)
  6314. continue;
  6315. intel_crtc = to_intel_crtc(intel_encoder->base.crtc);
  6316. if (prepare_pipes & (1 << intel_crtc->pipe))
  6317. intel_encoder->connectors_active = false;
  6318. }
  6319. intel_modeset_commit_output_state(dev);
  6320. /* Update computed state. */
  6321. list_for_each_entry(intel_crtc, &dev->mode_config.crtc_list,
  6322. base.head) {
  6323. intel_crtc->base.enabled = intel_crtc_in_use(&intel_crtc->base);
  6324. }
  6325. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  6326. if (!connector->encoder || !connector->encoder->crtc)
  6327. continue;
  6328. intel_crtc = to_intel_crtc(connector->encoder->crtc);
  6329. if (prepare_pipes & (1 << intel_crtc->pipe)) {
  6330. struct drm_property *dpms_property =
  6331. dev->mode_config.dpms_property;
  6332. connector->dpms = DRM_MODE_DPMS_ON;
  6333. drm_object_property_set_value(&connector->base,
  6334. dpms_property,
  6335. DRM_MODE_DPMS_ON);
  6336. intel_encoder = to_intel_encoder(connector->encoder);
  6337. intel_encoder->connectors_active = true;
  6338. }
  6339. }
  6340. }
  6341. #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \
  6342. list_for_each_entry((intel_crtc), \
  6343. &(dev)->mode_config.crtc_list, \
  6344. base.head) \
  6345. if (mask & (1 <<(intel_crtc)->pipe)) \
  6346. void
  6347. intel_modeset_check_state(struct drm_device *dev)
  6348. {
  6349. struct intel_crtc *crtc;
  6350. struct intel_encoder *encoder;
  6351. struct intel_connector *connector;
  6352. list_for_each_entry(connector, &dev->mode_config.connector_list,
  6353. base.head) {
  6354. /* This also checks the encoder/connector hw state with the
  6355. * ->get_hw_state callbacks. */
  6356. intel_connector_check_state(connector);
  6357. WARN(&connector->new_encoder->base != connector->base.encoder,
  6358. "connector's staged encoder doesn't match current encoder\n");
  6359. }
  6360. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  6361. base.head) {
  6362. bool enabled = false;
  6363. bool active = false;
  6364. enum pipe pipe, tracked_pipe;
  6365. DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
  6366. encoder->base.base.id,
  6367. drm_get_encoder_name(&encoder->base));
  6368. WARN(&encoder->new_crtc->base != encoder->base.crtc,
  6369. "encoder's stage crtc doesn't match current crtc\n");
  6370. WARN(encoder->connectors_active && !encoder->base.crtc,
  6371. "encoder's active_connectors set, but no crtc\n");
  6372. list_for_each_entry(connector, &dev->mode_config.connector_list,
  6373. base.head) {
  6374. if (connector->base.encoder != &encoder->base)
  6375. continue;
  6376. enabled = true;
  6377. if (connector->base.dpms != DRM_MODE_DPMS_OFF)
  6378. active = true;
  6379. }
  6380. WARN(!!encoder->base.crtc != enabled,
  6381. "encoder's enabled state mismatch "
  6382. "(expected %i, found %i)\n",
  6383. !!encoder->base.crtc, enabled);
  6384. WARN(active && !encoder->base.crtc,
  6385. "active encoder with no crtc\n");
  6386. WARN(encoder->connectors_active != active,
  6387. "encoder's computed active state doesn't match tracked active state "
  6388. "(expected %i, found %i)\n", active, encoder->connectors_active);
  6389. active = encoder->get_hw_state(encoder, &pipe);
  6390. WARN(active != encoder->connectors_active,
  6391. "encoder's hw state doesn't match sw tracking "
  6392. "(expected %i, found %i)\n",
  6393. encoder->connectors_active, active);
  6394. if (!encoder->base.crtc)
  6395. continue;
  6396. tracked_pipe = to_intel_crtc(encoder->base.crtc)->pipe;
  6397. WARN(active && pipe != tracked_pipe,
  6398. "active encoder's pipe doesn't match"
  6399. "(expected %i, found %i)\n",
  6400. tracked_pipe, pipe);
  6401. }
  6402. list_for_each_entry(crtc, &dev->mode_config.crtc_list,
  6403. base.head) {
  6404. bool enabled = false;
  6405. bool active = false;
  6406. DRM_DEBUG_KMS("[CRTC:%d]\n",
  6407. crtc->base.base.id);
  6408. WARN(crtc->active && !crtc->base.enabled,
  6409. "active crtc, but not enabled in sw tracking\n");
  6410. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  6411. base.head) {
  6412. if (encoder->base.crtc != &crtc->base)
  6413. continue;
  6414. enabled = true;
  6415. if (encoder->connectors_active)
  6416. active = true;
  6417. }
  6418. WARN(active != crtc->active,
  6419. "crtc's computed active state doesn't match tracked active state "
  6420. "(expected %i, found %i)\n", active, crtc->active);
  6421. WARN(enabled != crtc->base.enabled,
  6422. "crtc's computed enabled state doesn't match tracked enabled state "
  6423. "(expected %i, found %i)\n", enabled, crtc->base.enabled);
  6424. assert_pipe(dev->dev_private, crtc->pipe, crtc->active);
  6425. }
  6426. }
  6427. int intel_set_mode(struct drm_crtc *crtc,
  6428. struct drm_display_mode *mode,
  6429. int x, int y, struct drm_framebuffer *fb)
  6430. {
  6431. struct drm_device *dev = crtc->dev;
  6432. drm_i915_private_t *dev_priv = dev->dev_private;
  6433. struct drm_display_mode *adjusted_mode, *saved_mode, *saved_hwmode;
  6434. struct intel_crtc *intel_crtc;
  6435. unsigned disable_pipes, prepare_pipes, modeset_pipes;
  6436. int ret = 0;
  6437. saved_mode = kmalloc(2 * sizeof(*saved_mode), GFP_KERNEL);
  6438. if (!saved_mode)
  6439. return -ENOMEM;
  6440. saved_hwmode = saved_mode + 1;
  6441. intel_modeset_affected_pipes(crtc, &modeset_pipes,
  6442. &prepare_pipes, &disable_pipes);
  6443. DRM_DEBUG_KMS("set mode pipe masks: modeset: %x, prepare: %x, disable: %x\n",
  6444. modeset_pipes, prepare_pipes, disable_pipes);
  6445. for_each_intel_crtc_masked(dev, disable_pipes, intel_crtc)
  6446. intel_crtc_disable(&intel_crtc->base);
  6447. *saved_hwmode = crtc->hwmode;
  6448. *saved_mode = crtc->mode;
  6449. /* Hack: Because we don't (yet) support global modeset on multiple
  6450. * crtcs, we don't keep track of the new mode for more than one crtc.
  6451. * Hence simply check whether any bit is set in modeset_pipes in all the
  6452. * pieces of code that are not yet converted to deal with mutliple crtcs
  6453. * changing their mode at the same time. */
  6454. adjusted_mode = NULL;
  6455. if (modeset_pipes) {
  6456. adjusted_mode = intel_modeset_adjusted_mode(crtc, mode);
  6457. if (IS_ERR(adjusted_mode)) {
  6458. ret = PTR_ERR(adjusted_mode);
  6459. goto out;
  6460. }
  6461. }
  6462. for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) {
  6463. if (intel_crtc->base.enabled)
  6464. dev_priv->display.crtc_disable(&intel_crtc->base);
  6465. }
  6466. /* crtc->mode is already used by the ->mode_set callbacks, hence we need
  6467. * to set it here already despite that we pass it down the callchain.
  6468. */
  6469. if (modeset_pipes)
  6470. crtc->mode = *mode;
  6471. /* Only after disabling all output pipelines that will be changed can we
  6472. * update the the output configuration. */
  6473. intel_modeset_update_state(dev, prepare_pipes);
  6474. if (dev_priv->display.modeset_global_resources)
  6475. dev_priv->display.modeset_global_resources(dev);
  6476. /* Set up the DPLL and any encoders state that needs to adjust or depend
  6477. * on the DPLL.
  6478. */
  6479. for_each_intel_crtc_masked(dev, modeset_pipes, intel_crtc) {
  6480. ret = intel_crtc_mode_set(&intel_crtc->base,
  6481. mode, adjusted_mode,
  6482. x, y, fb);
  6483. if (ret)
  6484. goto done;
  6485. }
  6486. /* Now enable the clocks, plane, pipe, and connectors that we set up. */
  6487. for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc)
  6488. dev_priv->display.crtc_enable(&intel_crtc->base);
  6489. if (modeset_pipes) {
  6490. /* Store real post-adjustment hardware mode. */
  6491. crtc->hwmode = *adjusted_mode;
  6492. /* Calculate and store various constants which
  6493. * are later needed by vblank and swap-completion
  6494. * timestamping. They are derived from true hwmode.
  6495. */
  6496. drm_calc_timestamping_constants(crtc);
  6497. }
  6498. /* FIXME: add subpixel order */
  6499. done:
  6500. drm_mode_destroy(dev, adjusted_mode);
  6501. if (ret && crtc->enabled) {
  6502. crtc->hwmode = *saved_hwmode;
  6503. crtc->mode = *saved_mode;
  6504. } else {
  6505. intel_modeset_check_state(dev);
  6506. }
  6507. out:
  6508. kfree(saved_mode);
  6509. return ret;
  6510. }
  6511. void intel_crtc_restore_mode(struct drm_crtc *crtc)
  6512. {
  6513. intel_set_mode(crtc, &crtc->mode, crtc->x, crtc->y, crtc->fb);
  6514. }
  6515. #undef for_each_intel_crtc_masked
  6516. static void intel_set_config_free(struct intel_set_config *config)
  6517. {
  6518. if (!config)
  6519. return;
  6520. kfree(config->save_connector_encoders);
  6521. kfree(config->save_encoder_crtcs);
  6522. kfree(config);
  6523. }
  6524. static int intel_set_config_save_state(struct drm_device *dev,
  6525. struct intel_set_config *config)
  6526. {
  6527. struct drm_encoder *encoder;
  6528. struct drm_connector *connector;
  6529. int count;
  6530. config->save_encoder_crtcs =
  6531. kcalloc(dev->mode_config.num_encoder,
  6532. sizeof(struct drm_crtc *), GFP_KERNEL);
  6533. if (!config->save_encoder_crtcs)
  6534. return -ENOMEM;
  6535. config->save_connector_encoders =
  6536. kcalloc(dev->mode_config.num_connector,
  6537. sizeof(struct drm_encoder *), GFP_KERNEL);
  6538. if (!config->save_connector_encoders)
  6539. return -ENOMEM;
  6540. /* Copy data. Note that driver private data is not affected.
  6541. * Should anything bad happen only the expected state is
  6542. * restored, not the drivers personal bookkeeping.
  6543. */
  6544. count = 0;
  6545. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  6546. config->save_encoder_crtcs[count++] = encoder->crtc;
  6547. }
  6548. count = 0;
  6549. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  6550. config->save_connector_encoders[count++] = connector->encoder;
  6551. }
  6552. return 0;
  6553. }
  6554. static void intel_set_config_restore_state(struct drm_device *dev,
  6555. struct intel_set_config *config)
  6556. {
  6557. struct intel_encoder *encoder;
  6558. struct intel_connector *connector;
  6559. int count;
  6560. count = 0;
  6561. list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) {
  6562. encoder->new_crtc =
  6563. to_intel_crtc(config->save_encoder_crtcs[count++]);
  6564. }
  6565. count = 0;
  6566. list_for_each_entry(connector, &dev->mode_config.connector_list, base.head) {
  6567. connector->new_encoder =
  6568. to_intel_encoder(config->save_connector_encoders[count++]);
  6569. }
  6570. }
  6571. static void
  6572. intel_set_config_compute_mode_changes(struct drm_mode_set *set,
  6573. struct intel_set_config *config)
  6574. {
  6575. /* We should be able to check here if the fb has the same properties
  6576. * and then just flip_or_move it */
  6577. if (set->crtc->fb != set->fb) {
  6578. /* If we have no fb then treat it as a full mode set */
  6579. if (set->crtc->fb == NULL) {
  6580. DRM_DEBUG_KMS("crtc has no fb, full mode set\n");
  6581. config->mode_changed = true;
  6582. } else if (set->fb == NULL) {
  6583. config->mode_changed = true;
  6584. } else if (set->fb->depth != set->crtc->fb->depth) {
  6585. config->mode_changed = true;
  6586. } else if (set->fb->bits_per_pixel !=
  6587. set->crtc->fb->bits_per_pixel) {
  6588. config->mode_changed = true;
  6589. } else
  6590. config->fb_changed = true;
  6591. }
  6592. if (set->fb && (set->x != set->crtc->x || set->y != set->crtc->y))
  6593. config->fb_changed = true;
  6594. if (set->mode && !drm_mode_equal(set->mode, &set->crtc->mode)) {
  6595. DRM_DEBUG_KMS("modes are different, full mode set\n");
  6596. drm_mode_debug_printmodeline(&set->crtc->mode);
  6597. drm_mode_debug_printmodeline(set->mode);
  6598. config->mode_changed = true;
  6599. }
  6600. }
  6601. static int
  6602. intel_modeset_stage_output_state(struct drm_device *dev,
  6603. struct drm_mode_set *set,
  6604. struct intel_set_config *config)
  6605. {
  6606. struct drm_crtc *new_crtc;
  6607. struct intel_connector *connector;
  6608. struct intel_encoder *encoder;
  6609. int count, ro;
  6610. /* The upper layers ensure that we either disabl a crtc or have a list
  6611. * of connectors. For paranoia, double-check this. */
  6612. WARN_ON(!set->fb && (set->num_connectors != 0));
  6613. WARN_ON(set->fb && (set->num_connectors == 0));
  6614. count = 0;
  6615. list_for_each_entry(connector, &dev->mode_config.connector_list,
  6616. base.head) {
  6617. /* Otherwise traverse passed in connector list and get encoders
  6618. * for them. */
  6619. for (ro = 0; ro < set->num_connectors; ro++) {
  6620. if (set->connectors[ro] == &connector->base) {
  6621. connector->new_encoder = connector->encoder;
  6622. break;
  6623. }
  6624. }
  6625. /* If we disable the crtc, disable all its connectors. Also, if
  6626. * the connector is on the changing crtc but not on the new
  6627. * connector list, disable it. */
  6628. if ((!set->fb || ro == set->num_connectors) &&
  6629. connector->base.encoder &&
  6630. connector->base.encoder->crtc == set->crtc) {
  6631. connector->new_encoder = NULL;
  6632. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n",
  6633. connector->base.base.id,
  6634. drm_get_connector_name(&connector->base));
  6635. }
  6636. if (&connector->new_encoder->base != connector->base.encoder) {
  6637. DRM_DEBUG_KMS("encoder changed, full mode switch\n");
  6638. config->mode_changed = true;
  6639. }
  6640. }
  6641. /* connector->new_encoder is now updated for all connectors. */
  6642. /* Update crtc of enabled connectors. */
  6643. count = 0;
  6644. list_for_each_entry(connector, &dev->mode_config.connector_list,
  6645. base.head) {
  6646. if (!connector->new_encoder)
  6647. continue;
  6648. new_crtc = connector->new_encoder->base.crtc;
  6649. for (ro = 0; ro < set->num_connectors; ro++) {
  6650. if (set->connectors[ro] == &connector->base)
  6651. new_crtc = set->crtc;
  6652. }
  6653. /* Make sure the new CRTC will work with the encoder */
  6654. if (!intel_encoder_crtc_ok(&connector->new_encoder->base,
  6655. new_crtc)) {
  6656. return -EINVAL;
  6657. }
  6658. connector->encoder->new_crtc = to_intel_crtc(new_crtc);
  6659. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n",
  6660. connector->base.base.id,
  6661. drm_get_connector_name(&connector->base),
  6662. new_crtc->base.id);
  6663. }
  6664. /* Check for any encoders that needs to be disabled. */
  6665. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  6666. base.head) {
  6667. list_for_each_entry(connector,
  6668. &dev->mode_config.connector_list,
  6669. base.head) {
  6670. if (connector->new_encoder == encoder) {
  6671. WARN_ON(!connector->new_encoder->new_crtc);
  6672. goto next_encoder;
  6673. }
  6674. }
  6675. encoder->new_crtc = NULL;
  6676. next_encoder:
  6677. /* Only now check for crtc changes so we don't miss encoders
  6678. * that will be disabled. */
  6679. if (&encoder->new_crtc->base != encoder->base.crtc) {
  6680. DRM_DEBUG_KMS("crtc changed, full mode switch\n");
  6681. config->mode_changed = true;
  6682. }
  6683. }
  6684. /* Now we've also updated encoder->new_crtc for all encoders. */
  6685. return 0;
  6686. }
  6687. static int intel_crtc_set_config(struct drm_mode_set *set)
  6688. {
  6689. struct drm_device *dev;
  6690. struct drm_mode_set save_set;
  6691. struct intel_set_config *config;
  6692. int ret;
  6693. BUG_ON(!set);
  6694. BUG_ON(!set->crtc);
  6695. BUG_ON(!set->crtc->helper_private);
  6696. if (!set->mode)
  6697. set->fb = NULL;
  6698. /* The fb helper likes to play gross jokes with ->mode_set_config.
  6699. * Unfortunately the crtc helper doesn't do much at all for this case,
  6700. * so we have to cope with this madness until the fb helper is fixed up. */
  6701. if (set->fb && set->num_connectors == 0)
  6702. return 0;
  6703. if (set->fb) {
  6704. DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n",
  6705. set->crtc->base.id, set->fb->base.id,
  6706. (int)set->num_connectors, set->x, set->y);
  6707. } else {
  6708. DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set->crtc->base.id);
  6709. }
  6710. dev = set->crtc->dev;
  6711. ret = -ENOMEM;
  6712. config = kzalloc(sizeof(*config), GFP_KERNEL);
  6713. if (!config)
  6714. goto out_config;
  6715. ret = intel_set_config_save_state(dev, config);
  6716. if (ret)
  6717. goto out_config;
  6718. save_set.crtc = set->crtc;
  6719. save_set.mode = &set->crtc->mode;
  6720. save_set.x = set->crtc->x;
  6721. save_set.y = set->crtc->y;
  6722. save_set.fb = set->crtc->fb;
  6723. /* Compute whether we need a full modeset, only an fb base update or no
  6724. * change at all. In the future we might also check whether only the
  6725. * mode changed, e.g. for LVDS where we only change the panel fitter in
  6726. * such cases. */
  6727. intel_set_config_compute_mode_changes(set, config);
  6728. ret = intel_modeset_stage_output_state(dev, set, config);
  6729. if (ret)
  6730. goto fail;
  6731. if (config->mode_changed) {
  6732. if (set->mode) {
  6733. DRM_DEBUG_KMS("attempting to set mode from"
  6734. " userspace\n");
  6735. drm_mode_debug_printmodeline(set->mode);
  6736. }
  6737. ret = intel_set_mode(set->crtc, set->mode,
  6738. set->x, set->y, set->fb);
  6739. if (ret) {
  6740. DRM_ERROR("failed to set mode on [CRTC:%d], err = %d\n",
  6741. set->crtc->base.id, ret);
  6742. goto fail;
  6743. }
  6744. } else if (config->fb_changed) {
  6745. ret = intel_pipe_set_base(set->crtc,
  6746. set->x, set->y, set->fb);
  6747. }
  6748. intel_set_config_free(config);
  6749. return 0;
  6750. fail:
  6751. intel_set_config_restore_state(dev, config);
  6752. /* Try to restore the config */
  6753. if (config->mode_changed &&
  6754. intel_set_mode(save_set.crtc, save_set.mode,
  6755. save_set.x, save_set.y, save_set.fb))
  6756. DRM_ERROR("failed to restore config after modeset failure\n");
  6757. out_config:
  6758. intel_set_config_free(config);
  6759. return ret;
  6760. }
  6761. static const struct drm_crtc_funcs intel_crtc_funcs = {
  6762. .cursor_set = intel_crtc_cursor_set,
  6763. .cursor_move = intel_crtc_cursor_move,
  6764. .gamma_set = intel_crtc_gamma_set,
  6765. .set_config = intel_crtc_set_config,
  6766. .destroy = intel_crtc_destroy,
  6767. .page_flip = intel_crtc_page_flip,
  6768. };
  6769. static void intel_cpu_pll_init(struct drm_device *dev)
  6770. {
  6771. if (HAS_DDI(dev))
  6772. intel_ddi_pll_init(dev);
  6773. }
  6774. static void intel_pch_pll_init(struct drm_device *dev)
  6775. {
  6776. drm_i915_private_t *dev_priv = dev->dev_private;
  6777. int i;
  6778. if (dev_priv->num_pch_pll == 0) {
  6779. DRM_DEBUG_KMS("No PCH PLLs on this hardware, skipping initialisation\n");
  6780. return;
  6781. }
  6782. for (i = 0; i < dev_priv->num_pch_pll; i++) {
  6783. dev_priv->pch_plls[i].pll_reg = _PCH_DPLL(i);
  6784. dev_priv->pch_plls[i].fp0_reg = _PCH_FP0(i);
  6785. dev_priv->pch_plls[i].fp1_reg = _PCH_FP1(i);
  6786. }
  6787. }
  6788. static void intel_crtc_init(struct drm_device *dev, int pipe)
  6789. {
  6790. drm_i915_private_t *dev_priv = dev->dev_private;
  6791. struct intel_crtc *intel_crtc;
  6792. int i;
  6793. intel_crtc = kzalloc(sizeof(struct intel_crtc) + (INTELFB_CONN_LIMIT * sizeof(struct drm_connector *)), GFP_KERNEL);
  6794. if (intel_crtc == NULL)
  6795. return;
  6796. drm_crtc_init(dev, &intel_crtc->base, &intel_crtc_funcs);
  6797. drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256);
  6798. for (i = 0; i < 256; i++) {
  6799. intel_crtc->lut_r[i] = i;
  6800. intel_crtc->lut_g[i] = i;
  6801. intel_crtc->lut_b[i] = i;
  6802. }
  6803. /* Swap pipes & planes for FBC on pre-965 */
  6804. intel_crtc->pipe = pipe;
  6805. intel_crtc->plane = pipe;
  6806. intel_crtc->cpu_transcoder = pipe;
  6807. if (IS_MOBILE(dev) && IS_GEN3(dev)) {
  6808. DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
  6809. intel_crtc->plane = !pipe;
  6810. }
  6811. BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
  6812. dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL);
  6813. dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base;
  6814. dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base;
  6815. intel_crtc->bpp = 24; /* default for pre-Ironlake */
  6816. drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
  6817. }
  6818. int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data,
  6819. struct drm_file *file)
  6820. {
  6821. struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
  6822. struct drm_mode_object *drmmode_obj;
  6823. struct intel_crtc *crtc;
  6824. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  6825. return -ENODEV;
  6826. drmmode_obj = drm_mode_object_find(dev, pipe_from_crtc_id->crtc_id,
  6827. DRM_MODE_OBJECT_CRTC);
  6828. if (!drmmode_obj) {
  6829. DRM_ERROR("no such CRTC id\n");
  6830. return -EINVAL;
  6831. }
  6832. crtc = to_intel_crtc(obj_to_crtc(drmmode_obj));
  6833. pipe_from_crtc_id->pipe = crtc->pipe;
  6834. return 0;
  6835. }
  6836. static int intel_encoder_clones(struct intel_encoder *encoder)
  6837. {
  6838. struct drm_device *dev = encoder->base.dev;
  6839. struct intel_encoder *source_encoder;
  6840. int index_mask = 0;
  6841. int entry = 0;
  6842. list_for_each_entry(source_encoder,
  6843. &dev->mode_config.encoder_list, base.head) {
  6844. if (encoder == source_encoder)
  6845. index_mask |= (1 << entry);
  6846. /* Intel hw has only one MUX where enocoders could be cloned. */
  6847. if (encoder->cloneable && source_encoder->cloneable)
  6848. index_mask |= (1 << entry);
  6849. entry++;
  6850. }
  6851. return index_mask;
  6852. }
  6853. static bool has_edp_a(struct drm_device *dev)
  6854. {
  6855. struct drm_i915_private *dev_priv = dev->dev_private;
  6856. if (!IS_MOBILE(dev))
  6857. return false;
  6858. if ((I915_READ(DP_A) & DP_DETECTED) == 0)
  6859. return false;
  6860. if (IS_GEN5(dev) &&
  6861. (I915_READ(ILK_DISPLAY_CHICKEN_FUSES) & ILK_eDP_A_DISABLE))
  6862. return false;
  6863. return true;
  6864. }
  6865. static void intel_setup_outputs(struct drm_device *dev)
  6866. {
  6867. struct drm_i915_private *dev_priv = dev->dev_private;
  6868. struct intel_encoder *encoder;
  6869. bool dpd_is_edp = false;
  6870. bool has_lvds;
  6871. has_lvds = intel_lvds_init(dev);
  6872. if (!has_lvds && !HAS_PCH_SPLIT(dev)) {
  6873. /* disable the panel fitter on everything but LVDS */
  6874. I915_WRITE(PFIT_CONTROL, 0);
  6875. }
  6876. if (!(HAS_DDI(dev) && (I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)))
  6877. intel_crt_init(dev);
  6878. if (HAS_DDI(dev)) {
  6879. int found;
  6880. /* Haswell uses DDI functions to detect digital outputs */
  6881. found = I915_READ(DDI_BUF_CTL_A) & DDI_INIT_DISPLAY_DETECTED;
  6882. /* DDI A only supports eDP */
  6883. if (found)
  6884. intel_ddi_init(dev, PORT_A);
  6885. /* DDI B, C and D detection is indicated by the SFUSE_STRAP
  6886. * register */
  6887. found = I915_READ(SFUSE_STRAP);
  6888. if (found & SFUSE_STRAP_DDIB_DETECTED)
  6889. intel_ddi_init(dev, PORT_B);
  6890. if (found & SFUSE_STRAP_DDIC_DETECTED)
  6891. intel_ddi_init(dev, PORT_C);
  6892. if (found & SFUSE_STRAP_DDID_DETECTED)
  6893. intel_ddi_init(dev, PORT_D);
  6894. } else if (HAS_PCH_SPLIT(dev)) {
  6895. int found;
  6896. dpd_is_edp = intel_dpd_is_edp(dev);
  6897. if (has_edp_a(dev))
  6898. intel_dp_init(dev, DP_A, PORT_A);
  6899. if (I915_READ(HDMIB) & PORT_DETECTED) {
  6900. /* PCH SDVOB multiplex with HDMIB */
  6901. found = intel_sdvo_init(dev, PCH_SDVOB, true);
  6902. if (!found)
  6903. intel_hdmi_init(dev, HDMIB, PORT_B);
  6904. if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
  6905. intel_dp_init(dev, PCH_DP_B, PORT_B);
  6906. }
  6907. if (I915_READ(HDMIC) & PORT_DETECTED)
  6908. intel_hdmi_init(dev, HDMIC, PORT_C);
  6909. if (!dpd_is_edp && I915_READ(HDMID) & PORT_DETECTED)
  6910. intel_hdmi_init(dev, HDMID, PORT_D);
  6911. if (I915_READ(PCH_DP_C) & DP_DETECTED)
  6912. intel_dp_init(dev, PCH_DP_C, PORT_C);
  6913. if (I915_READ(PCH_DP_D) & DP_DETECTED)
  6914. intel_dp_init(dev, PCH_DP_D, PORT_D);
  6915. } else if (IS_VALLEYVIEW(dev)) {
  6916. int found;
  6917. /* Check for built-in panel first. Shares lanes with HDMI on SDVOC */
  6918. if (I915_READ(DP_C) & DP_DETECTED)
  6919. intel_dp_init(dev, DP_C, PORT_C);
  6920. if (I915_READ(SDVOB) & PORT_DETECTED) {
  6921. /* SDVOB multiplex with HDMIB */
  6922. found = intel_sdvo_init(dev, SDVOB, true);
  6923. if (!found)
  6924. intel_hdmi_init(dev, SDVOB, PORT_B);
  6925. if (!found && (I915_READ(DP_B) & DP_DETECTED))
  6926. intel_dp_init(dev, DP_B, PORT_B);
  6927. }
  6928. if (I915_READ(SDVOC) & PORT_DETECTED)
  6929. intel_hdmi_init(dev, SDVOC, PORT_C);
  6930. } else if (SUPPORTS_DIGITAL_OUTPUTS(dev)) {
  6931. bool found = false;
  6932. if (I915_READ(SDVOB) & SDVO_DETECTED) {
  6933. DRM_DEBUG_KMS("probing SDVOB\n");
  6934. found = intel_sdvo_init(dev, SDVOB, true);
  6935. if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) {
  6936. DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
  6937. intel_hdmi_init(dev, SDVOB, PORT_B);
  6938. }
  6939. if (!found && SUPPORTS_INTEGRATED_DP(dev)) {
  6940. DRM_DEBUG_KMS("probing DP_B\n");
  6941. intel_dp_init(dev, DP_B, PORT_B);
  6942. }
  6943. }
  6944. /* Before G4X SDVOC doesn't have its own detect register */
  6945. if (I915_READ(SDVOB) & SDVO_DETECTED) {
  6946. DRM_DEBUG_KMS("probing SDVOC\n");
  6947. found = intel_sdvo_init(dev, SDVOC, false);
  6948. }
  6949. if (!found && (I915_READ(SDVOC) & SDVO_DETECTED)) {
  6950. if (SUPPORTS_INTEGRATED_HDMI(dev)) {
  6951. DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
  6952. intel_hdmi_init(dev, SDVOC, PORT_C);
  6953. }
  6954. if (SUPPORTS_INTEGRATED_DP(dev)) {
  6955. DRM_DEBUG_KMS("probing DP_C\n");
  6956. intel_dp_init(dev, DP_C, PORT_C);
  6957. }
  6958. }
  6959. if (SUPPORTS_INTEGRATED_DP(dev) &&
  6960. (I915_READ(DP_D) & DP_DETECTED)) {
  6961. DRM_DEBUG_KMS("probing DP_D\n");
  6962. intel_dp_init(dev, DP_D, PORT_D);
  6963. }
  6964. } else if (IS_GEN2(dev))
  6965. intel_dvo_init(dev);
  6966. if (SUPPORTS_TV(dev))
  6967. intel_tv_init(dev);
  6968. list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) {
  6969. encoder->base.possible_crtcs = encoder->crtc_mask;
  6970. encoder->base.possible_clones =
  6971. intel_encoder_clones(encoder);
  6972. }
  6973. intel_init_pch_refclk(dev);
  6974. drm_helper_move_panel_connectors_to_head(dev);
  6975. }
  6976. static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
  6977. {
  6978. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  6979. drm_framebuffer_cleanup(fb);
  6980. drm_gem_object_unreference_unlocked(&intel_fb->obj->base);
  6981. kfree(intel_fb);
  6982. }
  6983. static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
  6984. struct drm_file *file,
  6985. unsigned int *handle)
  6986. {
  6987. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  6988. struct drm_i915_gem_object *obj = intel_fb->obj;
  6989. return drm_gem_handle_create(file, &obj->base, handle);
  6990. }
  6991. static const struct drm_framebuffer_funcs intel_fb_funcs = {
  6992. .destroy = intel_user_framebuffer_destroy,
  6993. .create_handle = intel_user_framebuffer_create_handle,
  6994. };
  6995. int intel_framebuffer_init(struct drm_device *dev,
  6996. struct intel_framebuffer *intel_fb,
  6997. struct drm_mode_fb_cmd2 *mode_cmd,
  6998. struct drm_i915_gem_object *obj)
  6999. {
  7000. int ret;
  7001. if (obj->tiling_mode == I915_TILING_Y)
  7002. return -EINVAL;
  7003. if (mode_cmd->pitches[0] & 63)
  7004. return -EINVAL;
  7005. /* FIXME <= Gen4 stride limits are bit unclear */
  7006. if (mode_cmd->pitches[0] > 32768)
  7007. return -EINVAL;
  7008. if (obj->tiling_mode != I915_TILING_NONE &&
  7009. mode_cmd->pitches[0] != obj->stride)
  7010. return -EINVAL;
  7011. /* Reject formats not supported by any plane early. */
  7012. switch (mode_cmd->pixel_format) {
  7013. case DRM_FORMAT_C8:
  7014. case DRM_FORMAT_RGB565:
  7015. case DRM_FORMAT_XRGB8888:
  7016. case DRM_FORMAT_ARGB8888:
  7017. break;
  7018. case DRM_FORMAT_XRGB1555:
  7019. case DRM_FORMAT_ARGB1555:
  7020. if (INTEL_INFO(dev)->gen > 3)
  7021. return -EINVAL;
  7022. break;
  7023. case DRM_FORMAT_XBGR8888:
  7024. case DRM_FORMAT_ABGR8888:
  7025. case DRM_FORMAT_XRGB2101010:
  7026. case DRM_FORMAT_ARGB2101010:
  7027. case DRM_FORMAT_XBGR2101010:
  7028. case DRM_FORMAT_ABGR2101010:
  7029. if (INTEL_INFO(dev)->gen < 4)
  7030. return -EINVAL;
  7031. break;
  7032. case DRM_FORMAT_YUYV:
  7033. case DRM_FORMAT_UYVY:
  7034. case DRM_FORMAT_YVYU:
  7035. case DRM_FORMAT_VYUY:
  7036. if (INTEL_INFO(dev)->gen < 6)
  7037. return -EINVAL;
  7038. break;
  7039. default:
  7040. DRM_DEBUG_KMS("unsupported pixel format 0x%08x\n", mode_cmd->pixel_format);
  7041. return -EINVAL;
  7042. }
  7043. /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
  7044. if (mode_cmd->offsets[0] != 0)
  7045. return -EINVAL;
  7046. ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs);
  7047. if (ret) {
  7048. DRM_ERROR("framebuffer init failed %d\n", ret);
  7049. return ret;
  7050. }
  7051. drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd);
  7052. intel_fb->obj = obj;
  7053. return 0;
  7054. }
  7055. static struct drm_framebuffer *
  7056. intel_user_framebuffer_create(struct drm_device *dev,
  7057. struct drm_file *filp,
  7058. struct drm_mode_fb_cmd2 *mode_cmd)
  7059. {
  7060. struct drm_i915_gem_object *obj;
  7061. obj = to_intel_bo(drm_gem_object_lookup(dev, filp,
  7062. mode_cmd->handles[0]));
  7063. if (&obj->base == NULL)
  7064. return ERR_PTR(-ENOENT);
  7065. return intel_framebuffer_create(dev, mode_cmd, obj);
  7066. }
  7067. static const struct drm_mode_config_funcs intel_mode_funcs = {
  7068. .fb_create = intel_user_framebuffer_create,
  7069. .output_poll_changed = intel_fb_output_poll_changed,
  7070. };
  7071. /* Set up chip specific display functions */
  7072. static void intel_init_display(struct drm_device *dev)
  7073. {
  7074. struct drm_i915_private *dev_priv = dev->dev_private;
  7075. /* We always want a DPMS function */
  7076. if (HAS_DDI(dev)) {
  7077. dev_priv->display.crtc_mode_set = haswell_crtc_mode_set;
  7078. dev_priv->display.crtc_enable = haswell_crtc_enable;
  7079. dev_priv->display.crtc_disable = haswell_crtc_disable;
  7080. dev_priv->display.off = haswell_crtc_off;
  7081. dev_priv->display.update_plane = ironlake_update_plane;
  7082. } else if (HAS_PCH_SPLIT(dev)) {
  7083. dev_priv->display.crtc_mode_set = ironlake_crtc_mode_set;
  7084. dev_priv->display.crtc_enable = ironlake_crtc_enable;
  7085. dev_priv->display.crtc_disable = ironlake_crtc_disable;
  7086. dev_priv->display.off = ironlake_crtc_off;
  7087. dev_priv->display.update_plane = ironlake_update_plane;
  7088. } else {
  7089. dev_priv->display.crtc_mode_set = i9xx_crtc_mode_set;
  7090. dev_priv->display.crtc_enable = i9xx_crtc_enable;
  7091. dev_priv->display.crtc_disable = i9xx_crtc_disable;
  7092. dev_priv->display.off = i9xx_crtc_off;
  7093. dev_priv->display.update_plane = i9xx_update_plane;
  7094. }
  7095. /* Returns the core display clock speed */
  7096. if (IS_VALLEYVIEW(dev))
  7097. dev_priv->display.get_display_clock_speed =
  7098. valleyview_get_display_clock_speed;
  7099. else if (IS_I945G(dev) || (IS_G33(dev) && !IS_PINEVIEW_M(dev)))
  7100. dev_priv->display.get_display_clock_speed =
  7101. i945_get_display_clock_speed;
  7102. else if (IS_I915G(dev))
  7103. dev_priv->display.get_display_clock_speed =
  7104. i915_get_display_clock_speed;
  7105. else if (IS_I945GM(dev) || IS_845G(dev) || IS_PINEVIEW_M(dev))
  7106. dev_priv->display.get_display_clock_speed =
  7107. i9xx_misc_get_display_clock_speed;
  7108. else if (IS_I915GM(dev))
  7109. dev_priv->display.get_display_clock_speed =
  7110. i915gm_get_display_clock_speed;
  7111. else if (IS_I865G(dev))
  7112. dev_priv->display.get_display_clock_speed =
  7113. i865_get_display_clock_speed;
  7114. else if (IS_I85X(dev))
  7115. dev_priv->display.get_display_clock_speed =
  7116. i855_get_display_clock_speed;
  7117. else /* 852, 830 */
  7118. dev_priv->display.get_display_clock_speed =
  7119. i830_get_display_clock_speed;
  7120. if (HAS_PCH_SPLIT(dev)) {
  7121. if (IS_GEN5(dev)) {
  7122. dev_priv->display.fdi_link_train = ironlake_fdi_link_train;
  7123. dev_priv->display.write_eld = ironlake_write_eld;
  7124. } else if (IS_GEN6(dev)) {
  7125. dev_priv->display.fdi_link_train = gen6_fdi_link_train;
  7126. dev_priv->display.write_eld = ironlake_write_eld;
  7127. } else if (IS_IVYBRIDGE(dev)) {
  7128. /* FIXME: detect B0+ stepping and use auto training */
  7129. dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
  7130. dev_priv->display.write_eld = ironlake_write_eld;
  7131. dev_priv->display.modeset_global_resources =
  7132. ivb_modeset_global_resources;
  7133. } else if (IS_HASWELL(dev)) {
  7134. dev_priv->display.fdi_link_train = hsw_fdi_link_train;
  7135. dev_priv->display.write_eld = haswell_write_eld;
  7136. }
  7137. } else if (IS_G4X(dev)) {
  7138. dev_priv->display.write_eld = g4x_write_eld;
  7139. }
  7140. /* Default just returns -ENODEV to indicate unsupported */
  7141. dev_priv->display.queue_flip = intel_default_queue_flip;
  7142. switch (INTEL_INFO(dev)->gen) {
  7143. case 2:
  7144. dev_priv->display.queue_flip = intel_gen2_queue_flip;
  7145. break;
  7146. case 3:
  7147. dev_priv->display.queue_flip = intel_gen3_queue_flip;
  7148. break;
  7149. case 4:
  7150. case 5:
  7151. dev_priv->display.queue_flip = intel_gen4_queue_flip;
  7152. break;
  7153. case 6:
  7154. dev_priv->display.queue_flip = intel_gen6_queue_flip;
  7155. break;
  7156. case 7:
  7157. dev_priv->display.queue_flip = intel_gen7_queue_flip;
  7158. break;
  7159. }
  7160. }
  7161. /*
  7162. * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend,
  7163. * resume, or other times. This quirk makes sure that's the case for
  7164. * affected systems.
  7165. */
  7166. static void quirk_pipea_force(struct drm_device *dev)
  7167. {
  7168. struct drm_i915_private *dev_priv = dev->dev_private;
  7169. dev_priv->quirks |= QUIRK_PIPEA_FORCE;
  7170. DRM_INFO("applying pipe a force quirk\n");
  7171. }
  7172. /*
  7173. * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
  7174. */
  7175. static void quirk_ssc_force_disable(struct drm_device *dev)
  7176. {
  7177. struct drm_i915_private *dev_priv = dev->dev_private;
  7178. dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE;
  7179. DRM_INFO("applying lvds SSC disable quirk\n");
  7180. }
  7181. /*
  7182. * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
  7183. * brightness value
  7184. */
  7185. static void quirk_invert_brightness(struct drm_device *dev)
  7186. {
  7187. struct drm_i915_private *dev_priv = dev->dev_private;
  7188. dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS;
  7189. DRM_INFO("applying inverted panel brightness quirk\n");
  7190. }
  7191. struct intel_quirk {
  7192. int device;
  7193. int subsystem_vendor;
  7194. int subsystem_device;
  7195. void (*hook)(struct drm_device *dev);
  7196. };
  7197. /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
  7198. struct intel_dmi_quirk {
  7199. void (*hook)(struct drm_device *dev);
  7200. const struct dmi_system_id (*dmi_id_list)[];
  7201. };
  7202. static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
  7203. {
  7204. DRM_INFO("Backlight polarity reversed on %s\n", id->ident);
  7205. return 1;
  7206. }
  7207. static const struct intel_dmi_quirk intel_dmi_quirks[] = {
  7208. {
  7209. .dmi_id_list = &(const struct dmi_system_id[]) {
  7210. {
  7211. .callback = intel_dmi_reverse_brightness,
  7212. .ident = "NCR Corporation",
  7213. .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
  7214. DMI_MATCH(DMI_PRODUCT_NAME, ""),
  7215. },
  7216. },
  7217. { } /* terminating entry */
  7218. },
  7219. .hook = quirk_invert_brightness,
  7220. },
  7221. };
  7222. static struct intel_quirk intel_quirks[] = {
  7223. /* HP Mini needs pipe A force quirk (LP: #322104) */
  7224. { 0x27ae, 0x103c, 0x361a, quirk_pipea_force },
  7225. /* Toshiba Protege R-205, S-209 needs pipe A force quirk */
  7226. { 0x2592, 0x1179, 0x0001, quirk_pipea_force },
  7227. /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
  7228. { 0x2782, 0x17aa, 0x201a, quirk_pipea_force },
  7229. /* 830/845 need to leave pipe A & dpll A up */
  7230. { 0x2562, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force },
  7231. { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force },
  7232. /* Lenovo U160 cannot use SSC on LVDS */
  7233. { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable },
  7234. /* Sony Vaio Y cannot use SSC on LVDS */
  7235. { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable },
  7236. /* Acer Aspire 5734Z must invert backlight brightness */
  7237. { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness },
  7238. /* Acer/eMachines G725 */
  7239. { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness },
  7240. /* Acer/eMachines e725 */
  7241. { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness },
  7242. /* Acer/Packard Bell NCL20 */
  7243. { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness },
  7244. };
  7245. static void intel_init_quirks(struct drm_device *dev)
  7246. {
  7247. struct pci_dev *d = dev->pdev;
  7248. int i;
  7249. for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) {
  7250. struct intel_quirk *q = &intel_quirks[i];
  7251. if (d->device == q->device &&
  7252. (d->subsystem_vendor == q->subsystem_vendor ||
  7253. q->subsystem_vendor == PCI_ANY_ID) &&
  7254. (d->subsystem_device == q->subsystem_device ||
  7255. q->subsystem_device == PCI_ANY_ID))
  7256. q->hook(dev);
  7257. }
  7258. for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) {
  7259. if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0)
  7260. intel_dmi_quirks[i].hook(dev);
  7261. }
  7262. }
  7263. /* Disable the VGA plane that we never use */
  7264. static void i915_disable_vga(struct drm_device *dev)
  7265. {
  7266. struct drm_i915_private *dev_priv = dev->dev_private;
  7267. u8 sr1;
  7268. u32 vga_reg;
  7269. if (HAS_PCH_SPLIT(dev))
  7270. vga_reg = CPU_VGACNTRL;
  7271. else
  7272. vga_reg = VGACNTRL;
  7273. vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO);
  7274. outb(SR01, VGA_SR_INDEX);
  7275. sr1 = inb(VGA_SR_DATA);
  7276. outb(sr1 | 1<<5, VGA_SR_DATA);
  7277. vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
  7278. udelay(300);
  7279. I915_WRITE(vga_reg, VGA_DISP_DISABLE);
  7280. POSTING_READ(vga_reg);
  7281. }
  7282. void intel_modeset_init_hw(struct drm_device *dev)
  7283. {
  7284. /* We attempt to init the necessary power wells early in the initialization
  7285. * time, so the subsystems that expect power to be enabled can work.
  7286. */
  7287. intel_init_power_wells(dev);
  7288. intel_prepare_ddi(dev);
  7289. intel_init_clock_gating(dev);
  7290. mutex_lock(&dev->struct_mutex);
  7291. intel_enable_gt_powersave(dev);
  7292. mutex_unlock(&dev->struct_mutex);
  7293. }
  7294. void intel_modeset_init(struct drm_device *dev)
  7295. {
  7296. struct drm_i915_private *dev_priv = dev->dev_private;
  7297. int i, ret;
  7298. drm_mode_config_init(dev);
  7299. dev->mode_config.min_width = 0;
  7300. dev->mode_config.min_height = 0;
  7301. dev->mode_config.preferred_depth = 24;
  7302. dev->mode_config.prefer_shadow = 1;
  7303. dev->mode_config.funcs = &intel_mode_funcs;
  7304. intel_init_quirks(dev);
  7305. intel_init_pm(dev);
  7306. intel_init_display(dev);
  7307. if (IS_GEN2(dev)) {
  7308. dev->mode_config.max_width = 2048;
  7309. dev->mode_config.max_height = 2048;
  7310. } else if (IS_GEN3(dev)) {
  7311. dev->mode_config.max_width = 4096;
  7312. dev->mode_config.max_height = 4096;
  7313. } else {
  7314. dev->mode_config.max_width = 8192;
  7315. dev->mode_config.max_height = 8192;
  7316. }
  7317. dev->mode_config.fb_base = dev_priv->gtt.mappable_base;
  7318. DRM_DEBUG_KMS("%d display pipe%s available.\n",
  7319. dev_priv->num_pipe, dev_priv->num_pipe > 1 ? "s" : "");
  7320. for (i = 0; i < dev_priv->num_pipe; i++) {
  7321. intel_crtc_init(dev, i);
  7322. ret = intel_plane_init(dev, i);
  7323. if (ret)
  7324. DRM_DEBUG_KMS("plane %d init failed: %d\n", i, ret);
  7325. }
  7326. intel_cpu_pll_init(dev);
  7327. intel_pch_pll_init(dev);
  7328. /* Just disable it once at startup */
  7329. i915_disable_vga(dev);
  7330. intel_setup_outputs(dev);
  7331. /* Just in case the BIOS is doing something questionable. */
  7332. intel_disable_fbc(dev);
  7333. }
  7334. static void
  7335. intel_connector_break_all_links(struct intel_connector *connector)
  7336. {
  7337. connector->base.dpms = DRM_MODE_DPMS_OFF;
  7338. connector->base.encoder = NULL;
  7339. connector->encoder->connectors_active = false;
  7340. connector->encoder->base.crtc = NULL;
  7341. }
  7342. static void intel_enable_pipe_a(struct drm_device *dev)
  7343. {
  7344. struct intel_connector *connector;
  7345. struct drm_connector *crt = NULL;
  7346. struct intel_load_detect_pipe load_detect_temp;
  7347. /* We can't just switch on the pipe A, we need to set things up with a
  7348. * proper mode and output configuration. As a gross hack, enable pipe A
  7349. * by enabling the load detect pipe once. */
  7350. list_for_each_entry(connector,
  7351. &dev->mode_config.connector_list,
  7352. base.head) {
  7353. if (connector->encoder->type == INTEL_OUTPUT_ANALOG) {
  7354. crt = &connector->base;
  7355. break;
  7356. }
  7357. }
  7358. if (!crt)
  7359. return;
  7360. if (intel_get_load_detect_pipe(crt, NULL, &load_detect_temp))
  7361. intel_release_load_detect_pipe(crt, &load_detect_temp);
  7362. }
  7363. static bool
  7364. intel_check_plane_mapping(struct intel_crtc *crtc)
  7365. {
  7366. struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
  7367. u32 reg, val;
  7368. if (dev_priv->num_pipe == 1)
  7369. return true;
  7370. reg = DSPCNTR(!crtc->plane);
  7371. val = I915_READ(reg);
  7372. if ((val & DISPLAY_PLANE_ENABLE) &&
  7373. (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe))
  7374. return false;
  7375. return true;
  7376. }
  7377. static void intel_sanitize_crtc(struct intel_crtc *crtc)
  7378. {
  7379. struct drm_device *dev = crtc->base.dev;
  7380. struct drm_i915_private *dev_priv = dev->dev_private;
  7381. u32 reg;
  7382. /* Clear any frame start delays used for debugging left by the BIOS */
  7383. reg = PIPECONF(crtc->cpu_transcoder);
  7384. I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
  7385. /* We need to sanitize the plane -> pipe mapping first because this will
  7386. * disable the crtc (and hence change the state) if it is wrong. Note
  7387. * that gen4+ has a fixed plane -> pipe mapping. */
  7388. if (INTEL_INFO(dev)->gen < 4 && !intel_check_plane_mapping(crtc)) {
  7389. struct intel_connector *connector;
  7390. bool plane;
  7391. DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n",
  7392. crtc->base.base.id);
  7393. /* Pipe has the wrong plane attached and the plane is active.
  7394. * Temporarily change the plane mapping and disable everything
  7395. * ... */
  7396. plane = crtc->plane;
  7397. crtc->plane = !plane;
  7398. dev_priv->display.crtc_disable(&crtc->base);
  7399. crtc->plane = plane;
  7400. /* ... and break all links. */
  7401. list_for_each_entry(connector, &dev->mode_config.connector_list,
  7402. base.head) {
  7403. if (connector->encoder->base.crtc != &crtc->base)
  7404. continue;
  7405. intel_connector_break_all_links(connector);
  7406. }
  7407. WARN_ON(crtc->active);
  7408. crtc->base.enabled = false;
  7409. }
  7410. if (dev_priv->quirks & QUIRK_PIPEA_FORCE &&
  7411. crtc->pipe == PIPE_A && !crtc->active) {
  7412. /* BIOS forgot to enable pipe A, this mostly happens after
  7413. * resume. Force-enable the pipe to fix this, the update_dpms
  7414. * call below we restore the pipe to the right state, but leave
  7415. * the required bits on. */
  7416. intel_enable_pipe_a(dev);
  7417. }
  7418. /* Adjust the state of the output pipe according to whether we
  7419. * have active connectors/encoders. */
  7420. intel_crtc_update_dpms(&crtc->base);
  7421. if (crtc->active != crtc->base.enabled) {
  7422. struct intel_encoder *encoder;
  7423. /* This can happen either due to bugs in the get_hw_state
  7424. * functions or because the pipe is force-enabled due to the
  7425. * pipe A quirk. */
  7426. DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n",
  7427. crtc->base.base.id,
  7428. crtc->base.enabled ? "enabled" : "disabled",
  7429. crtc->active ? "enabled" : "disabled");
  7430. crtc->base.enabled = crtc->active;
  7431. /* Because we only establish the connector -> encoder ->
  7432. * crtc links if something is active, this means the
  7433. * crtc is now deactivated. Break the links. connector
  7434. * -> encoder links are only establish when things are
  7435. * actually up, hence no need to break them. */
  7436. WARN_ON(crtc->active);
  7437. for_each_encoder_on_crtc(dev, &crtc->base, encoder) {
  7438. WARN_ON(encoder->connectors_active);
  7439. encoder->base.crtc = NULL;
  7440. }
  7441. }
  7442. }
  7443. static void intel_sanitize_encoder(struct intel_encoder *encoder)
  7444. {
  7445. struct intel_connector *connector;
  7446. struct drm_device *dev = encoder->base.dev;
  7447. /* We need to check both for a crtc link (meaning that the
  7448. * encoder is active and trying to read from a pipe) and the
  7449. * pipe itself being active. */
  7450. bool has_active_crtc = encoder->base.crtc &&
  7451. to_intel_crtc(encoder->base.crtc)->active;
  7452. if (encoder->connectors_active && !has_active_crtc) {
  7453. DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
  7454. encoder->base.base.id,
  7455. drm_get_encoder_name(&encoder->base));
  7456. /* Connector is active, but has no active pipe. This is
  7457. * fallout from our resume register restoring. Disable
  7458. * the encoder manually again. */
  7459. if (encoder->base.crtc) {
  7460. DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
  7461. encoder->base.base.id,
  7462. drm_get_encoder_name(&encoder->base));
  7463. encoder->disable(encoder);
  7464. }
  7465. /* Inconsistent output/port/pipe state happens presumably due to
  7466. * a bug in one of the get_hw_state functions. Or someplace else
  7467. * in our code, like the register restore mess on resume. Clamp
  7468. * things to off as a safer default. */
  7469. list_for_each_entry(connector,
  7470. &dev->mode_config.connector_list,
  7471. base.head) {
  7472. if (connector->encoder != encoder)
  7473. continue;
  7474. intel_connector_break_all_links(connector);
  7475. }
  7476. }
  7477. /* Enabled encoders without active connectors will be fixed in
  7478. * the crtc fixup. */
  7479. }
  7480. static void i915_redisable_vga(struct drm_device *dev)
  7481. {
  7482. struct drm_i915_private *dev_priv = dev->dev_private;
  7483. u32 vga_reg;
  7484. if (HAS_PCH_SPLIT(dev))
  7485. vga_reg = CPU_VGACNTRL;
  7486. else
  7487. vga_reg = VGACNTRL;
  7488. if (I915_READ(vga_reg) != VGA_DISP_DISABLE) {
  7489. DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
  7490. I915_WRITE(vga_reg, VGA_DISP_DISABLE);
  7491. POSTING_READ(vga_reg);
  7492. }
  7493. }
  7494. /* Scan out the current hw modeset state, sanitizes it and maps it into the drm
  7495. * and i915 state tracking structures. */
  7496. void intel_modeset_setup_hw_state(struct drm_device *dev,
  7497. bool force_restore)
  7498. {
  7499. struct drm_i915_private *dev_priv = dev->dev_private;
  7500. enum pipe pipe;
  7501. u32 tmp;
  7502. struct intel_crtc *crtc;
  7503. struct intel_encoder *encoder;
  7504. struct intel_connector *connector;
  7505. if (HAS_DDI(dev)) {
  7506. tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
  7507. if (tmp & TRANS_DDI_FUNC_ENABLE) {
  7508. switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
  7509. case TRANS_DDI_EDP_INPUT_A_ON:
  7510. case TRANS_DDI_EDP_INPUT_A_ONOFF:
  7511. pipe = PIPE_A;
  7512. break;
  7513. case TRANS_DDI_EDP_INPUT_B_ONOFF:
  7514. pipe = PIPE_B;
  7515. break;
  7516. case TRANS_DDI_EDP_INPUT_C_ONOFF:
  7517. pipe = PIPE_C;
  7518. break;
  7519. }
  7520. crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  7521. crtc->cpu_transcoder = TRANSCODER_EDP;
  7522. DRM_DEBUG_KMS("Pipe %c using transcoder EDP\n",
  7523. pipe_name(pipe));
  7524. }
  7525. }
  7526. for_each_pipe(pipe) {
  7527. crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  7528. tmp = I915_READ(PIPECONF(crtc->cpu_transcoder));
  7529. if (tmp & PIPECONF_ENABLE)
  7530. crtc->active = true;
  7531. else
  7532. crtc->active = false;
  7533. crtc->base.enabled = crtc->active;
  7534. DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n",
  7535. crtc->base.base.id,
  7536. crtc->active ? "enabled" : "disabled");
  7537. }
  7538. if (HAS_DDI(dev))
  7539. intel_ddi_setup_hw_pll_state(dev);
  7540. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  7541. base.head) {
  7542. pipe = 0;
  7543. if (encoder->get_hw_state(encoder, &pipe)) {
  7544. encoder->base.crtc =
  7545. dev_priv->pipe_to_crtc_mapping[pipe];
  7546. } else {
  7547. encoder->base.crtc = NULL;
  7548. }
  7549. encoder->connectors_active = false;
  7550. DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe=%i\n",
  7551. encoder->base.base.id,
  7552. drm_get_encoder_name(&encoder->base),
  7553. encoder->base.crtc ? "enabled" : "disabled",
  7554. pipe);
  7555. }
  7556. list_for_each_entry(connector, &dev->mode_config.connector_list,
  7557. base.head) {
  7558. if (connector->get_hw_state(connector)) {
  7559. connector->base.dpms = DRM_MODE_DPMS_ON;
  7560. connector->encoder->connectors_active = true;
  7561. connector->base.encoder = &connector->encoder->base;
  7562. } else {
  7563. connector->base.dpms = DRM_MODE_DPMS_OFF;
  7564. connector->base.encoder = NULL;
  7565. }
  7566. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
  7567. connector->base.base.id,
  7568. drm_get_connector_name(&connector->base),
  7569. connector->base.encoder ? "enabled" : "disabled");
  7570. }
  7571. /* HW state is read out, now we need to sanitize this mess. */
  7572. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  7573. base.head) {
  7574. intel_sanitize_encoder(encoder);
  7575. }
  7576. for_each_pipe(pipe) {
  7577. crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  7578. intel_sanitize_crtc(crtc);
  7579. }
  7580. if (force_restore) {
  7581. for_each_pipe(pipe) {
  7582. intel_crtc_restore_mode(dev_priv->pipe_to_crtc_mapping[pipe]);
  7583. }
  7584. i915_redisable_vga(dev);
  7585. } else {
  7586. intel_modeset_update_staged_output_state(dev);
  7587. }
  7588. intel_modeset_check_state(dev);
  7589. drm_mode_config_reset(dev);
  7590. }
  7591. void intel_modeset_gem_init(struct drm_device *dev)
  7592. {
  7593. intel_modeset_init_hw(dev);
  7594. intel_setup_overlay(dev);
  7595. intel_modeset_setup_hw_state(dev, false);
  7596. }
  7597. void intel_modeset_cleanup(struct drm_device *dev)
  7598. {
  7599. struct drm_i915_private *dev_priv = dev->dev_private;
  7600. struct drm_crtc *crtc;
  7601. struct intel_crtc *intel_crtc;
  7602. drm_kms_helper_poll_fini(dev);
  7603. mutex_lock(&dev->struct_mutex);
  7604. intel_unregister_dsm_handler();
  7605. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  7606. /* Skip inactive CRTCs */
  7607. if (!crtc->fb)
  7608. continue;
  7609. intel_crtc = to_intel_crtc(crtc);
  7610. intel_increase_pllclock(crtc);
  7611. }
  7612. intel_disable_fbc(dev);
  7613. intel_disable_gt_powersave(dev);
  7614. ironlake_teardown_rc6(dev);
  7615. if (IS_VALLEYVIEW(dev))
  7616. vlv_init_dpio(dev);
  7617. mutex_unlock(&dev->struct_mutex);
  7618. /* Disable the irq before mode object teardown, for the irq might
  7619. * enqueue unpin/hotplug work. */
  7620. drm_irq_uninstall(dev);
  7621. cancel_work_sync(&dev_priv->hotplug_work);
  7622. cancel_work_sync(&dev_priv->rps.work);
  7623. /* flush any delayed tasks or pending work */
  7624. flush_scheduled_work();
  7625. drm_mode_config_cleanup(dev);
  7626. intel_cleanup_overlay(dev);
  7627. }
  7628. /*
  7629. * Return which encoder is currently attached for connector.
  7630. */
  7631. struct drm_encoder *intel_best_encoder(struct drm_connector *connector)
  7632. {
  7633. return &intel_attached_encoder(connector)->base;
  7634. }
  7635. void intel_connector_attach_encoder(struct intel_connector *connector,
  7636. struct intel_encoder *encoder)
  7637. {
  7638. connector->encoder = encoder;
  7639. drm_mode_connector_attach_encoder(&connector->base,
  7640. &encoder->base);
  7641. }
  7642. /*
  7643. * set vga decode state - true == enable VGA decode
  7644. */
  7645. int intel_modeset_vga_set_state(struct drm_device *dev, bool state)
  7646. {
  7647. struct drm_i915_private *dev_priv = dev->dev_private;
  7648. u16 gmch_ctrl;
  7649. pci_read_config_word(dev_priv->bridge_dev, INTEL_GMCH_CTRL, &gmch_ctrl);
  7650. if (state)
  7651. gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
  7652. else
  7653. gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
  7654. pci_write_config_word(dev_priv->bridge_dev, INTEL_GMCH_CTRL, gmch_ctrl);
  7655. return 0;
  7656. }
  7657. #ifdef CONFIG_DEBUG_FS
  7658. #include <linux/seq_file.h>
  7659. struct intel_display_error_state {
  7660. struct intel_cursor_error_state {
  7661. u32 control;
  7662. u32 position;
  7663. u32 base;
  7664. u32 size;
  7665. } cursor[I915_MAX_PIPES];
  7666. struct intel_pipe_error_state {
  7667. u32 conf;
  7668. u32 source;
  7669. u32 htotal;
  7670. u32 hblank;
  7671. u32 hsync;
  7672. u32 vtotal;
  7673. u32 vblank;
  7674. u32 vsync;
  7675. } pipe[I915_MAX_PIPES];
  7676. struct intel_plane_error_state {
  7677. u32 control;
  7678. u32 stride;
  7679. u32 size;
  7680. u32 pos;
  7681. u32 addr;
  7682. u32 surface;
  7683. u32 tile_offset;
  7684. } plane[I915_MAX_PIPES];
  7685. };
  7686. struct intel_display_error_state *
  7687. intel_display_capture_error_state(struct drm_device *dev)
  7688. {
  7689. drm_i915_private_t *dev_priv = dev->dev_private;
  7690. struct intel_display_error_state *error;
  7691. enum transcoder cpu_transcoder;
  7692. int i;
  7693. error = kmalloc(sizeof(*error), GFP_ATOMIC);
  7694. if (error == NULL)
  7695. return NULL;
  7696. for_each_pipe(i) {
  7697. cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, i);
  7698. error->cursor[i].control = I915_READ(CURCNTR(i));
  7699. error->cursor[i].position = I915_READ(CURPOS(i));
  7700. error->cursor[i].base = I915_READ(CURBASE(i));
  7701. error->plane[i].control = I915_READ(DSPCNTR(i));
  7702. error->plane[i].stride = I915_READ(DSPSTRIDE(i));
  7703. error->plane[i].size = I915_READ(DSPSIZE(i));
  7704. error->plane[i].pos = I915_READ(DSPPOS(i));
  7705. error->plane[i].addr = I915_READ(DSPADDR(i));
  7706. if (INTEL_INFO(dev)->gen >= 4) {
  7707. error->plane[i].surface = I915_READ(DSPSURF(i));
  7708. error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
  7709. }
  7710. error->pipe[i].conf = I915_READ(PIPECONF(cpu_transcoder));
  7711. error->pipe[i].source = I915_READ(PIPESRC(i));
  7712. error->pipe[i].htotal = I915_READ(HTOTAL(cpu_transcoder));
  7713. error->pipe[i].hblank = I915_READ(HBLANK(cpu_transcoder));
  7714. error->pipe[i].hsync = I915_READ(HSYNC(cpu_transcoder));
  7715. error->pipe[i].vtotal = I915_READ(VTOTAL(cpu_transcoder));
  7716. error->pipe[i].vblank = I915_READ(VBLANK(cpu_transcoder));
  7717. error->pipe[i].vsync = I915_READ(VSYNC(cpu_transcoder));
  7718. }
  7719. return error;
  7720. }
  7721. void
  7722. intel_display_print_error_state(struct seq_file *m,
  7723. struct drm_device *dev,
  7724. struct intel_display_error_state *error)
  7725. {
  7726. drm_i915_private_t *dev_priv = dev->dev_private;
  7727. int i;
  7728. seq_printf(m, "Num Pipes: %d\n", dev_priv->num_pipe);
  7729. for_each_pipe(i) {
  7730. seq_printf(m, "Pipe [%d]:\n", i);
  7731. seq_printf(m, " CONF: %08x\n", error->pipe[i].conf);
  7732. seq_printf(m, " SRC: %08x\n", error->pipe[i].source);
  7733. seq_printf(m, " HTOTAL: %08x\n", error->pipe[i].htotal);
  7734. seq_printf(m, " HBLANK: %08x\n", error->pipe[i].hblank);
  7735. seq_printf(m, " HSYNC: %08x\n", error->pipe[i].hsync);
  7736. seq_printf(m, " VTOTAL: %08x\n", error->pipe[i].vtotal);
  7737. seq_printf(m, " VBLANK: %08x\n", error->pipe[i].vblank);
  7738. seq_printf(m, " VSYNC: %08x\n", error->pipe[i].vsync);
  7739. seq_printf(m, "Plane [%d]:\n", i);
  7740. seq_printf(m, " CNTR: %08x\n", error->plane[i].control);
  7741. seq_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
  7742. seq_printf(m, " SIZE: %08x\n", error->plane[i].size);
  7743. seq_printf(m, " POS: %08x\n", error->plane[i].pos);
  7744. seq_printf(m, " ADDR: %08x\n", error->plane[i].addr);
  7745. if (INTEL_INFO(dev)->gen >= 4) {
  7746. seq_printf(m, " SURF: %08x\n", error->plane[i].surface);
  7747. seq_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
  7748. }
  7749. seq_printf(m, "Cursor [%d]:\n", i);
  7750. seq_printf(m, " CNTR: %08x\n", error->cursor[i].control);
  7751. seq_printf(m, " POS: %08x\n", error->cursor[i].position);
  7752. seq_printf(m, " BASE: %08x\n", error->cursor[i].base);
  7753. }
  7754. }
  7755. #endif