intel_display.c 248 KB

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