intel_display.c 248 KB

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