intel_display.c 249 KB

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