intel_display.c 249 KB

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