intel_display.c 247 KB

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