intel_display.c 262 KB

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