intel_display.c 247 KB

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