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