intel_display.c 186 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055
  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 "drmP.h"
  35. #include "intel_drv.h"
  36. #include "i915_drm.h"
  37. #include "i915_drv.h"
  38. #include "i915_trace.h"
  39. #include "drm_dp_helper.h"
  40. #include "drm_crtc_helper.h"
  41. #include <linux/dma_remapping.h>
  42. #define HAS_eDP (intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))
  43. bool intel_pipe_has_type(struct drm_crtc *crtc, int type);
  44. static void intel_increase_pllclock(struct drm_crtc *crtc);
  45. static void intel_crtc_update_cursor(struct drm_crtc *crtc, bool on);
  46. typedef struct {
  47. /* given values */
  48. int n;
  49. int m1, m2;
  50. int p1, p2;
  51. /* derived values */
  52. int dot;
  53. int vco;
  54. int m;
  55. int p;
  56. } intel_clock_t;
  57. typedef struct {
  58. int min, max;
  59. } intel_range_t;
  60. typedef struct {
  61. int dot_limit;
  62. int p2_slow, p2_fast;
  63. } intel_p2_t;
  64. #define INTEL_P2_NUM 2
  65. typedef struct intel_limit intel_limit_t;
  66. struct intel_limit {
  67. intel_range_t dot, vco, n, m, m1, m2, p, p1;
  68. intel_p2_t p2;
  69. bool (* find_pll)(const intel_limit_t *, struct drm_crtc *,
  70. int, int, intel_clock_t *, intel_clock_t *);
  71. };
  72. /* FDI */
  73. #define IRONLAKE_FDI_FREQ 2700000 /* in kHz for mode->clock */
  74. static bool
  75. intel_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
  76. int target, int refclk, intel_clock_t *match_clock,
  77. intel_clock_t *best_clock);
  78. static bool
  79. intel_g4x_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
  80. int target, int refclk, intel_clock_t *match_clock,
  81. intel_clock_t *best_clock);
  82. static bool
  83. intel_find_pll_g4x_dp(const intel_limit_t *, struct drm_crtc *crtc,
  84. int target, int refclk, intel_clock_t *match_clock,
  85. intel_clock_t *best_clock);
  86. static bool
  87. intel_find_pll_ironlake_dp(const intel_limit_t *, struct drm_crtc *crtc,
  88. int target, int refclk, intel_clock_t *match_clock,
  89. intel_clock_t *best_clock);
  90. static inline u32 /* units of 100MHz */
  91. intel_fdi_link_freq(struct drm_device *dev)
  92. {
  93. if (IS_GEN5(dev)) {
  94. struct drm_i915_private *dev_priv = dev->dev_private;
  95. return (I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK) + 2;
  96. } else
  97. return 27;
  98. }
  99. static const intel_limit_t intel_limits_i8xx_dvo = {
  100. .dot = { .min = 25000, .max = 350000 },
  101. .vco = { .min = 930000, .max = 1400000 },
  102. .n = { .min = 3, .max = 16 },
  103. .m = { .min = 96, .max = 140 },
  104. .m1 = { .min = 18, .max = 26 },
  105. .m2 = { .min = 6, .max = 16 },
  106. .p = { .min = 4, .max = 128 },
  107. .p1 = { .min = 2, .max = 33 },
  108. .p2 = { .dot_limit = 165000,
  109. .p2_slow = 4, .p2_fast = 2 },
  110. .find_pll = intel_find_best_PLL,
  111. };
  112. static const intel_limit_t intel_limits_i8xx_lvds = {
  113. .dot = { .min = 25000, .max = 350000 },
  114. .vco = { .min = 930000, .max = 1400000 },
  115. .n = { .min = 3, .max = 16 },
  116. .m = { .min = 96, .max = 140 },
  117. .m1 = { .min = 18, .max = 26 },
  118. .m2 = { .min = 6, .max = 16 },
  119. .p = { .min = 4, .max = 128 },
  120. .p1 = { .min = 1, .max = 6 },
  121. .p2 = { .dot_limit = 165000,
  122. .p2_slow = 14, .p2_fast = 7 },
  123. .find_pll = intel_find_best_PLL,
  124. };
  125. static const intel_limit_t intel_limits_i9xx_sdvo = {
  126. .dot = { .min = 20000, .max = 400000 },
  127. .vco = { .min = 1400000, .max = 2800000 },
  128. .n = { .min = 1, .max = 6 },
  129. .m = { .min = 70, .max = 120 },
  130. .m1 = { .min = 10, .max = 22 },
  131. .m2 = { .min = 5, .max = 9 },
  132. .p = { .min = 5, .max = 80 },
  133. .p1 = { .min = 1, .max = 8 },
  134. .p2 = { .dot_limit = 200000,
  135. .p2_slow = 10, .p2_fast = 5 },
  136. .find_pll = intel_find_best_PLL,
  137. };
  138. static const intel_limit_t intel_limits_i9xx_lvds = {
  139. .dot = { .min = 20000, .max = 400000 },
  140. .vco = { .min = 1400000, .max = 2800000 },
  141. .n = { .min = 1, .max = 6 },
  142. .m = { .min = 70, .max = 120 },
  143. .m1 = { .min = 10, .max = 22 },
  144. .m2 = { .min = 5, .max = 9 },
  145. .p = { .min = 7, .max = 98 },
  146. .p1 = { .min = 1, .max = 8 },
  147. .p2 = { .dot_limit = 112000,
  148. .p2_slow = 14, .p2_fast = 7 },
  149. .find_pll = intel_find_best_PLL,
  150. };
  151. static const intel_limit_t intel_limits_g4x_sdvo = {
  152. .dot = { .min = 25000, .max = 270000 },
  153. .vco = { .min = 1750000, .max = 3500000},
  154. .n = { .min = 1, .max = 4 },
  155. .m = { .min = 104, .max = 138 },
  156. .m1 = { .min = 17, .max = 23 },
  157. .m2 = { .min = 5, .max = 11 },
  158. .p = { .min = 10, .max = 30 },
  159. .p1 = { .min = 1, .max = 3},
  160. .p2 = { .dot_limit = 270000,
  161. .p2_slow = 10,
  162. .p2_fast = 10
  163. },
  164. .find_pll = intel_g4x_find_best_PLL,
  165. };
  166. static const intel_limit_t intel_limits_g4x_hdmi = {
  167. .dot = { .min = 22000, .max = 400000 },
  168. .vco = { .min = 1750000, .max = 3500000},
  169. .n = { .min = 1, .max = 4 },
  170. .m = { .min = 104, .max = 138 },
  171. .m1 = { .min = 16, .max = 23 },
  172. .m2 = { .min = 5, .max = 11 },
  173. .p = { .min = 5, .max = 80 },
  174. .p1 = { .min = 1, .max = 8},
  175. .p2 = { .dot_limit = 165000,
  176. .p2_slow = 10, .p2_fast = 5 },
  177. .find_pll = intel_g4x_find_best_PLL,
  178. };
  179. static const intel_limit_t intel_limits_g4x_single_channel_lvds = {
  180. .dot = { .min = 20000, .max = 115000 },
  181. .vco = { .min = 1750000, .max = 3500000 },
  182. .n = { .min = 1, .max = 3 },
  183. .m = { .min = 104, .max = 138 },
  184. .m1 = { .min = 17, .max = 23 },
  185. .m2 = { .min = 5, .max = 11 },
  186. .p = { .min = 28, .max = 112 },
  187. .p1 = { .min = 2, .max = 8 },
  188. .p2 = { .dot_limit = 0,
  189. .p2_slow = 14, .p2_fast = 14
  190. },
  191. .find_pll = intel_g4x_find_best_PLL,
  192. };
  193. static const intel_limit_t intel_limits_g4x_dual_channel_lvds = {
  194. .dot = { .min = 80000, .max = 224000 },
  195. .vco = { .min = 1750000, .max = 3500000 },
  196. .n = { .min = 1, .max = 3 },
  197. .m = { .min = 104, .max = 138 },
  198. .m1 = { .min = 17, .max = 23 },
  199. .m2 = { .min = 5, .max = 11 },
  200. .p = { .min = 14, .max = 42 },
  201. .p1 = { .min = 2, .max = 6 },
  202. .p2 = { .dot_limit = 0,
  203. .p2_slow = 7, .p2_fast = 7
  204. },
  205. .find_pll = intel_g4x_find_best_PLL,
  206. };
  207. static const intel_limit_t intel_limits_g4x_display_port = {
  208. .dot = { .min = 161670, .max = 227000 },
  209. .vco = { .min = 1750000, .max = 3500000},
  210. .n = { .min = 1, .max = 2 },
  211. .m = { .min = 97, .max = 108 },
  212. .m1 = { .min = 0x10, .max = 0x12 },
  213. .m2 = { .min = 0x05, .max = 0x06 },
  214. .p = { .min = 10, .max = 20 },
  215. .p1 = { .min = 1, .max = 2},
  216. .p2 = { .dot_limit = 0,
  217. .p2_slow = 10, .p2_fast = 10 },
  218. .find_pll = intel_find_pll_g4x_dp,
  219. };
  220. static const intel_limit_t intel_limits_pineview_sdvo = {
  221. .dot = { .min = 20000, .max = 400000},
  222. .vco = { .min = 1700000, .max = 3500000 },
  223. /* Pineview's Ncounter is a ring counter */
  224. .n = { .min = 3, .max = 6 },
  225. .m = { .min = 2, .max = 256 },
  226. /* Pineview only has one combined m divider, which we treat as m2. */
  227. .m1 = { .min = 0, .max = 0 },
  228. .m2 = { .min = 0, .max = 254 },
  229. .p = { .min = 5, .max = 80 },
  230. .p1 = { .min = 1, .max = 8 },
  231. .p2 = { .dot_limit = 200000,
  232. .p2_slow = 10, .p2_fast = 5 },
  233. .find_pll = intel_find_best_PLL,
  234. };
  235. static const intel_limit_t intel_limits_pineview_lvds = {
  236. .dot = { .min = 20000, .max = 400000 },
  237. .vco = { .min = 1700000, .max = 3500000 },
  238. .n = { .min = 3, .max = 6 },
  239. .m = { .min = 2, .max = 256 },
  240. .m1 = { .min = 0, .max = 0 },
  241. .m2 = { .min = 0, .max = 254 },
  242. .p = { .min = 7, .max = 112 },
  243. .p1 = { .min = 1, .max = 8 },
  244. .p2 = { .dot_limit = 112000,
  245. .p2_slow = 14, .p2_fast = 14 },
  246. .find_pll = intel_find_best_PLL,
  247. };
  248. /* Ironlake / Sandybridge
  249. *
  250. * We calculate clock using (register_value + 2) for N/M1/M2, so here
  251. * the range value for them is (actual_value - 2).
  252. */
  253. static const intel_limit_t intel_limits_ironlake_dac = {
  254. .dot = { .min = 25000, .max = 350000 },
  255. .vco = { .min = 1760000, .max = 3510000 },
  256. .n = { .min = 1, .max = 5 },
  257. .m = { .min = 79, .max = 127 },
  258. .m1 = { .min = 12, .max = 22 },
  259. .m2 = { .min = 5, .max = 9 },
  260. .p = { .min = 5, .max = 80 },
  261. .p1 = { .min = 1, .max = 8 },
  262. .p2 = { .dot_limit = 225000,
  263. .p2_slow = 10, .p2_fast = 5 },
  264. .find_pll = intel_g4x_find_best_PLL,
  265. };
  266. static const intel_limit_t intel_limits_ironlake_single_lvds = {
  267. .dot = { .min = 25000, .max = 350000 },
  268. .vco = { .min = 1760000, .max = 3510000 },
  269. .n = { .min = 1, .max = 3 },
  270. .m = { .min = 79, .max = 118 },
  271. .m1 = { .min = 12, .max = 22 },
  272. .m2 = { .min = 5, .max = 9 },
  273. .p = { .min = 28, .max = 112 },
  274. .p1 = { .min = 2, .max = 8 },
  275. .p2 = { .dot_limit = 225000,
  276. .p2_slow = 14, .p2_fast = 14 },
  277. .find_pll = intel_g4x_find_best_PLL,
  278. };
  279. static const intel_limit_t intel_limits_ironlake_dual_lvds = {
  280. .dot = { .min = 25000, .max = 350000 },
  281. .vco = { .min = 1760000, .max = 3510000 },
  282. .n = { .min = 1, .max = 3 },
  283. .m = { .min = 79, .max = 127 },
  284. .m1 = { .min = 12, .max = 22 },
  285. .m2 = { .min = 5, .max = 9 },
  286. .p = { .min = 14, .max = 56 },
  287. .p1 = { .min = 2, .max = 8 },
  288. .p2 = { .dot_limit = 225000,
  289. .p2_slow = 7, .p2_fast = 7 },
  290. .find_pll = intel_g4x_find_best_PLL,
  291. };
  292. /* LVDS 100mhz refclk limits. */
  293. static const intel_limit_t intel_limits_ironlake_single_lvds_100m = {
  294. .dot = { .min = 25000, .max = 350000 },
  295. .vco = { .min = 1760000, .max = 3510000 },
  296. .n = { .min = 1, .max = 2 },
  297. .m = { .min = 79, .max = 126 },
  298. .m1 = { .min = 12, .max = 22 },
  299. .m2 = { .min = 5, .max = 9 },
  300. .p = { .min = 28, .max = 112 },
  301. .p1 = { .min = 2, .max = 8 },
  302. .p2 = { .dot_limit = 225000,
  303. .p2_slow = 14, .p2_fast = 14 },
  304. .find_pll = intel_g4x_find_best_PLL,
  305. };
  306. static const intel_limit_t intel_limits_ironlake_dual_lvds_100m = {
  307. .dot = { .min = 25000, .max = 350000 },
  308. .vco = { .min = 1760000, .max = 3510000 },
  309. .n = { .min = 1, .max = 3 },
  310. .m = { .min = 79, .max = 126 },
  311. .m1 = { .min = 12, .max = 22 },
  312. .m2 = { .min = 5, .max = 9 },
  313. .p = { .min = 14, .max = 42 },
  314. .p1 = { .min = 2, .max = 6 },
  315. .p2 = { .dot_limit = 225000,
  316. .p2_slow = 7, .p2_fast = 7 },
  317. .find_pll = intel_g4x_find_best_PLL,
  318. };
  319. static const intel_limit_t intel_limits_ironlake_display_port = {
  320. .dot = { .min = 25000, .max = 350000 },
  321. .vco = { .min = 1760000, .max = 3510000},
  322. .n = { .min = 1, .max = 2 },
  323. .m = { .min = 81, .max = 90 },
  324. .m1 = { .min = 12, .max = 22 },
  325. .m2 = { .min = 5, .max = 9 },
  326. .p = { .min = 10, .max = 20 },
  327. .p1 = { .min = 1, .max = 2},
  328. .p2 = { .dot_limit = 0,
  329. .p2_slow = 10, .p2_fast = 10 },
  330. .find_pll = intel_find_pll_ironlake_dp,
  331. };
  332. u32 intel_dpio_read(struct drm_i915_private *dev_priv, int reg)
  333. {
  334. unsigned long flags;
  335. u32 val = 0;
  336. spin_lock_irqsave(&dev_priv->dpio_lock, flags);
  337. if (wait_for_atomic_us((I915_READ(DPIO_PKT) & DPIO_BUSY) == 0, 100)) {
  338. DRM_ERROR("DPIO idle wait timed out\n");
  339. goto out_unlock;
  340. }
  341. I915_WRITE(DPIO_REG, reg);
  342. I915_WRITE(DPIO_PKT, DPIO_RID | DPIO_OP_READ | DPIO_PORTID |
  343. DPIO_BYTE);
  344. if (wait_for_atomic_us((I915_READ(DPIO_PKT) & DPIO_BUSY) == 0, 100)) {
  345. DRM_ERROR("DPIO read wait timed out\n");
  346. goto out_unlock;
  347. }
  348. val = I915_READ(DPIO_DATA);
  349. out_unlock:
  350. spin_unlock_irqrestore(&dev_priv->dpio_lock, flags);
  351. return val;
  352. }
  353. static void vlv_init_dpio(struct drm_device *dev)
  354. {
  355. struct drm_i915_private *dev_priv = dev->dev_private;
  356. /* Reset the DPIO config */
  357. I915_WRITE(DPIO_CTL, 0);
  358. POSTING_READ(DPIO_CTL);
  359. I915_WRITE(DPIO_CTL, 1);
  360. POSTING_READ(DPIO_CTL);
  361. }
  362. static int intel_dual_link_lvds_callback(const struct dmi_system_id *id)
  363. {
  364. DRM_INFO("Forcing lvds to dual link mode on %s\n", id->ident);
  365. return 1;
  366. }
  367. static const struct dmi_system_id intel_dual_link_lvds[] = {
  368. {
  369. .callback = intel_dual_link_lvds_callback,
  370. .ident = "Apple MacBook Pro (Core i5/i7 Series)",
  371. .matches = {
  372. DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
  373. DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro8,2"),
  374. },
  375. },
  376. { } /* terminating entry */
  377. };
  378. static bool is_dual_link_lvds(struct drm_i915_private *dev_priv,
  379. unsigned int reg)
  380. {
  381. unsigned int val;
  382. /* use the module option value if specified */
  383. if (i915_lvds_channel_mode > 0)
  384. return i915_lvds_channel_mode == 2;
  385. if (dmi_check_system(intel_dual_link_lvds))
  386. return true;
  387. if (dev_priv->lvds_val)
  388. val = dev_priv->lvds_val;
  389. else {
  390. /* BIOS should set the proper LVDS register value at boot, but
  391. * in reality, it doesn't set the value when the lid is closed;
  392. * we need to check "the value to be set" in VBT when LVDS
  393. * register is uninitialized.
  394. */
  395. val = I915_READ(reg);
  396. if (!(val & ~LVDS_DETECTED))
  397. val = dev_priv->bios_lvds_val;
  398. dev_priv->lvds_val = val;
  399. }
  400. return (val & LVDS_CLKB_POWER_MASK) == LVDS_CLKB_POWER_UP;
  401. }
  402. static const intel_limit_t *intel_ironlake_limit(struct drm_crtc *crtc,
  403. int refclk)
  404. {
  405. struct drm_device *dev = crtc->dev;
  406. struct drm_i915_private *dev_priv = dev->dev_private;
  407. const intel_limit_t *limit;
  408. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  409. if (is_dual_link_lvds(dev_priv, PCH_LVDS)) {
  410. /* LVDS dual channel */
  411. if (refclk == 100000)
  412. limit = &intel_limits_ironlake_dual_lvds_100m;
  413. else
  414. limit = &intel_limits_ironlake_dual_lvds;
  415. } else {
  416. if (refclk == 100000)
  417. limit = &intel_limits_ironlake_single_lvds_100m;
  418. else
  419. limit = &intel_limits_ironlake_single_lvds;
  420. }
  421. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) ||
  422. HAS_eDP)
  423. limit = &intel_limits_ironlake_display_port;
  424. else
  425. limit = &intel_limits_ironlake_dac;
  426. return limit;
  427. }
  428. static const intel_limit_t *intel_g4x_limit(struct drm_crtc *crtc)
  429. {
  430. struct drm_device *dev = crtc->dev;
  431. struct drm_i915_private *dev_priv = dev->dev_private;
  432. const intel_limit_t *limit;
  433. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  434. if (is_dual_link_lvds(dev_priv, LVDS))
  435. /* LVDS with dual channel */
  436. limit = &intel_limits_g4x_dual_channel_lvds;
  437. else
  438. /* LVDS with dual channel */
  439. limit = &intel_limits_g4x_single_channel_lvds;
  440. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI) ||
  441. intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG)) {
  442. limit = &intel_limits_g4x_hdmi;
  443. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO)) {
  444. limit = &intel_limits_g4x_sdvo;
  445. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
  446. limit = &intel_limits_g4x_display_port;
  447. } else /* The option is for other outputs */
  448. limit = &intel_limits_i9xx_sdvo;
  449. return limit;
  450. }
  451. static const intel_limit_t *intel_limit(struct drm_crtc *crtc, int refclk)
  452. {
  453. struct drm_device *dev = crtc->dev;
  454. const intel_limit_t *limit;
  455. if (HAS_PCH_SPLIT(dev))
  456. limit = intel_ironlake_limit(crtc, refclk);
  457. else if (IS_G4X(dev)) {
  458. limit = intel_g4x_limit(crtc);
  459. } else if (IS_PINEVIEW(dev)) {
  460. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  461. limit = &intel_limits_pineview_lvds;
  462. else
  463. limit = &intel_limits_pineview_sdvo;
  464. } else if (!IS_GEN2(dev)) {
  465. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  466. limit = &intel_limits_i9xx_lvds;
  467. else
  468. limit = &intel_limits_i9xx_sdvo;
  469. } else {
  470. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  471. limit = &intel_limits_i8xx_lvds;
  472. else
  473. limit = &intel_limits_i8xx_dvo;
  474. }
  475. return limit;
  476. }
  477. /* m1 is reserved as 0 in Pineview, n is a ring counter */
  478. static void pineview_clock(int refclk, intel_clock_t *clock)
  479. {
  480. clock->m = clock->m2 + 2;
  481. clock->p = clock->p1 * clock->p2;
  482. clock->vco = refclk * clock->m / clock->n;
  483. clock->dot = clock->vco / clock->p;
  484. }
  485. static void intel_clock(struct drm_device *dev, int refclk, intel_clock_t *clock)
  486. {
  487. if (IS_PINEVIEW(dev)) {
  488. pineview_clock(refclk, clock);
  489. return;
  490. }
  491. clock->m = 5 * (clock->m1 + 2) + (clock->m2 + 2);
  492. clock->p = clock->p1 * clock->p2;
  493. clock->vco = refclk * clock->m / (clock->n + 2);
  494. clock->dot = clock->vco / clock->p;
  495. }
  496. /**
  497. * Returns whether any output on the specified pipe is of the specified type
  498. */
  499. bool intel_pipe_has_type(struct drm_crtc *crtc, int type)
  500. {
  501. struct drm_device *dev = crtc->dev;
  502. struct drm_mode_config *mode_config = &dev->mode_config;
  503. struct intel_encoder *encoder;
  504. list_for_each_entry(encoder, &mode_config->encoder_list, base.head)
  505. if (encoder->base.crtc == crtc && encoder->type == type)
  506. return true;
  507. return false;
  508. }
  509. #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
  510. /**
  511. * Returns whether the given set of divisors are valid for a given refclk with
  512. * the given connectors.
  513. */
  514. static bool intel_PLL_is_valid(struct drm_device *dev,
  515. const intel_limit_t *limit,
  516. const intel_clock_t *clock)
  517. {
  518. if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
  519. INTELPllInvalid("p1 out of range\n");
  520. if (clock->p < limit->p.min || limit->p.max < clock->p)
  521. INTELPllInvalid("p out of range\n");
  522. if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
  523. INTELPllInvalid("m2 out of range\n");
  524. if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
  525. INTELPllInvalid("m1 out of range\n");
  526. if (clock->m1 <= clock->m2 && !IS_PINEVIEW(dev))
  527. INTELPllInvalid("m1 <= m2\n");
  528. if (clock->m < limit->m.min || limit->m.max < clock->m)
  529. INTELPllInvalid("m out of range\n");
  530. if (clock->n < limit->n.min || limit->n.max < clock->n)
  531. INTELPllInvalid("n out of range\n");
  532. if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
  533. INTELPllInvalid("vco out of range\n");
  534. /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
  535. * connector, etc., rather than just a single range.
  536. */
  537. if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
  538. INTELPllInvalid("dot out of range\n");
  539. return true;
  540. }
  541. static bool
  542. intel_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
  543. int target, int refclk, intel_clock_t *match_clock,
  544. intel_clock_t *best_clock)
  545. {
  546. struct drm_device *dev = crtc->dev;
  547. struct drm_i915_private *dev_priv = dev->dev_private;
  548. intel_clock_t clock;
  549. int err = target;
  550. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
  551. (I915_READ(LVDS)) != 0) {
  552. /*
  553. * For LVDS, if the panel is on, just rely on its current
  554. * settings for dual-channel. We haven't figured out how to
  555. * reliably set up different single/dual channel state, if we
  556. * even can.
  557. */
  558. if (is_dual_link_lvds(dev_priv, LVDS))
  559. clock.p2 = limit->p2.p2_fast;
  560. else
  561. clock.p2 = limit->p2.p2_slow;
  562. } else {
  563. if (target < limit->p2.dot_limit)
  564. clock.p2 = limit->p2.p2_slow;
  565. else
  566. clock.p2 = limit->p2.p2_fast;
  567. }
  568. memset(best_clock, 0, sizeof(*best_clock));
  569. for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
  570. clock.m1++) {
  571. for (clock.m2 = limit->m2.min;
  572. clock.m2 <= limit->m2.max; clock.m2++) {
  573. /* m1 is always 0 in Pineview */
  574. if (clock.m2 >= clock.m1 && !IS_PINEVIEW(dev))
  575. break;
  576. for (clock.n = limit->n.min;
  577. clock.n <= limit->n.max; clock.n++) {
  578. for (clock.p1 = limit->p1.min;
  579. clock.p1 <= limit->p1.max; clock.p1++) {
  580. int this_err;
  581. intel_clock(dev, refclk, &clock);
  582. if (!intel_PLL_is_valid(dev, limit,
  583. &clock))
  584. continue;
  585. if (match_clock &&
  586. clock.p != match_clock->p)
  587. continue;
  588. this_err = abs(clock.dot - target);
  589. if (this_err < err) {
  590. *best_clock = clock;
  591. err = this_err;
  592. }
  593. }
  594. }
  595. }
  596. }
  597. return (err != target);
  598. }
  599. static bool
  600. intel_g4x_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
  601. int target, int refclk, intel_clock_t *match_clock,
  602. intel_clock_t *best_clock)
  603. {
  604. struct drm_device *dev = crtc->dev;
  605. struct drm_i915_private *dev_priv = dev->dev_private;
  606. intel_clock_t clock;
  607. int max_n;
  608. bool found;
  609. /* approximately equals target * 0.00585 */
  610. int err_most = (target >> 8) + (target >> 9);
  611. found = false;
  612. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  613. int lvds_reg;
  614. if (HAS_PCH_SPLIT(dev))
  615. lvds_reg = PCH_LVDS;
  616. else
  617. lvds_reg = LVDS;
  618. if ((I915_READ(lvds_reg) & LVDS_CLKB_POWER_MASK) ==
  619. LVDS_CLKB_POWER_UP)
  620. clock.p2 = limit->p2.p2_fast;
  621. else
  622. clock.p2 = limit->p2.p2_slow;
  623. } else {
  624. if (target < limit->p2.dot_limit)
  625. clock.p2 = limit->p2.p2_slow;
  626. else
  627. clock.p2 = limit->p2.p2_fast;
  628. }
  629. memset(best_clock, 0, sizeof(*best_clock));
  630. max_n = limit->n.max;
  631. /* based on hardware requirement, prefer smaller n to precision */
  632. for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
  633. /* based on hardware requirement, prefere larger m1,m2 */
  634. for (clock.m1 = limit->m1.max;
  635. clock.m1 >= limit->m1.min; clock.m1--) {
  636. for (clock.m2 = limit->m2.max;
  637. clock.m2 >= limit->m2.min; clock.m2--) {
  638. for (clock.p1 = limit->p1.max;
  639. clock.p1 >= limit->p1.min; clock.p1--) {
  640. int this_err;
  641. intel_clock(dev, refclk, &clock);
  642. if (!intel_PLL_is_valid(dev, limit,
  643. &clock))
  644. continue;
  645. if (match_clock &&
  646. clock.p != match_clock->p)
  647. continue;
  648. this_err = abs(clock.dot - target);
  649. if (this_err < err_most) {
  650. *best_clock = clock;
  651. err_most = this_err;
  652. max_n = clock.n;
  653. found = true;
  654. }
  655. }
  656. }
  657. }
  658. }
  659. return found;
  660. }
  661. static bool
  662. intel_find_pll_ironlake_dp(const intel_limit_t *limit, struct drm_crtc *crtc,
  663. int target, int refclk, intel_clock_t *match_clock,
  664. intel_clock_t *best_clock)
  665. {
  666. struct drm_device *dev = crtc->dev;
  667. intel_clock_t clock;
  668. if (target < 200000) {
  669. clock.n = 1;
  670. clock.p1 = 2;
  671. clock.p2 = 10;
  672. clock.m1 = 12;
  673. clock.m2 = 9;
  674. } else {
  675. clock.n = 2;
  676. clock.p1 = 1;
  677. clock.p2 = 10;
  678. clock.m1 = 14;
  679. clock.m2 = 8;
  680. }
  681. intel_clock(dev, refclk, &clock);
  682. memcpy(best_clock, &clock, sizeof(intel_clock_t));
  683. return true;
  684. }
  685. /* DisplayPort has only two frequencies, 162MHz and 270MHz */
  686. static bool
  687. intel_find_pll_g4x_dp(const intel_limit_t *limit, struct drm_crtc *crtc,
  688. int target, int refclk, intel_clock_t *match_clock,
  689. intel_clock_t *best_clock)
  690. {
  691. intel_clock_t clock;
  692. if (target < 200000) {
  693. clock.p1 = 2;
  694. clock.p2 = 10;
  695. clock.n = 2;
  696. clock.m1 = 23;
  697. clock.m2 = 8;
  698. } else {
  699. clock.p1 = 1;
  700. clock.p2 = 10;
  701. clock.n = 1;
  702. clock.m1 = 14;
  703. clock.m2 = 2;
  704. }
  705. clock.m = 5 * (clock.m1 + 2) + (clock.m2 + 2);
  706. clock.p = (clock.p1 * clock.p2);
  707. clock.dot = 96000 * clock.m / (clock.n + 2) / clock.p;
  708. clock.vco = 0;
  709. memcpy(best_clock, &clock, sizeof(intel_clock_t));
  710. return true;
  711. }
  712. static void ironlake_wait_for_vblank(struct drm_device *dev, int pipe)
  713. {
  714. struct drm_i915_private *dev_priv = dev->dev_private;
  715. u32 frame, frame_reg = PIPEFRAME(pipe);
  716. frame = I915_READ(frame_reg);
  717. if (wait_for(I915_READ_NOTRACE(frame_reg) != frame, 50))
  718. DRM_DEBUG_KMS("vblank wait timed out\n");
  719. }
  720. /**
  721. * intel_wait_for_vblank - wait for vblank on a given pipe
  722. * @dev: drm device
  723. * @pipe: pipe to wait for
  724. *
  725. * Wait for vblank to occur on a given pipe. Needed for various bits of
  726. * mode setting code.
  727. */
  728. void intel_wait_for_vblank(struct drm_device *dev, int pipe)
  729. {
  730. struct drm_i915_private *dev_priv = dev->dev_private;
  731. int pipestat_reg = PIPESTAT(pipe);
  732. if (INTEL_INFO(dev)->gen >= 5) {
  733. ironlake_wait_for_vblank(dev, pipe);
  734. return;
  735. }
  736. /* Clear existing vblank status. Note this will clear any other
  737. * sticky status fields as well.
  738. *
  739. * This races with i915_driver_irq_handler() with the result
  740. * that either function could miss a vblank event. Here it is not
  741. * fatal, as we will either wait upon the next vblank interrupt or
  742. * timeout. Generally speaking intel_wait_for_vblank() is only
  743. * called during modeset at which time the GPU should be idle and
  744. * should *not* be performing page flips and thus not waiting on
  745. * vblanks...
  746. * Currently, the result of us stealing a vblank from the irq
  747. * handler is that a single frame will be skipped during swapbuffers.
  748. */
  749. I915_WRITE(pipestat_reg,
  750. I915_READ(pipestat_reg) | PIPE_VBLANK_INTERRUPT_STATUS);
  751. /* Wait for vblank interrupt bit to set */
  752. if (wait_for(I915_READ(pipestat_reg) &
  753. PIPE_VBLANK_INTERRUPT_STATUS,
  754. 50))
  755. DRM_DEBUG_KMS("vblank wait timed out\n");
  756. }
  757. /*
  758. * intel_wait_for_pipe_off - wait for pipe to turn off
  759. * @dev: drm device
  760. * @pipe: pipe to wait for
  761. *
  762. * After disabling a pipe, we can't wait for vblank in the usual way,
  763. * spinning on the vblank interrupt status bit, since we won't actually
  764. * see an interrupt when the pipe is disabled.
  765. *
  766. * On Gen4 and above:
  767. * wait for the pipe register state bit to turn off
  768. *
  769. * Otherwise:
  770. * wait for the display line value to settle (it usually
  771. * ends up stopping at the start of the next frame).
  772. *
  773. */
  774. void intel_wait_for_pipe_off(struct drm_device *dev, int pipe)
  775. {
  776. struct drm_i915_private *dev_priv = dev->dev_private;
  777. if (INTEL_INFO(dev)->gen >= 4) {
  778. int reg = PIPECONF(pipe);
  779. /* Wait for the Pipe State to go off */
  780. if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0,
  781. 100))
  782. DRM_DEBUG_KMS("pipe_off wait timed out\n");
  783. } else {
  784. u32 last_line, line_mask;
  785. int reg = PIPEDSL(pipe);
  786. unsigned long timeout = jiffies + msecs_to_jiffies(100);
  787. if (IS_GEN2(dev))
  788. line_mask = DSL_LINEMASK_GEN2;
  789. else
  790. line_mask = DSL_LINEMASK_GEN3;
  791. /* Wait for the display line to settle */
  792. do {
  793. last_line = I915_READ(reg) & line_mask;
  794. mdelay(5);
  795. } while (((I915_READ(reg) & line_mask) != last_line) &&
  796. time_after(timeout, jiffies));
  797. if (time_after(jiffies, timeout))
  798. DRM_DEBUG_KMS("pipe_off wait timed out\n");
  799. }
  800. }
  801. static const char *state_string(bool enabled)
  802. {
  803. return enabled ? "on" : "off";
  804. }
  805. /* Only for pre-ILK configs */
  806. static void assert_pll(struct drm_i915_private *dev_priv,
  807. enum pipe pipe, bool state)
  808. {
  809. int reg;
  810. u32 val;
  811. bool cur_state;
  812. reg = DPLL(pipe);
  813. val = I915_READ(reg);
  814. cur_state = !!(val & DPLL_VCO_ENABLE);
  815. WARN(cur_state != state,
  816. "PLL state assertion failure (expected %s, current %s)\n",
  817. state_string(state), state_string(cur_state));
  818. }
  819. #define assert_pll_enabled(d, p) assert_pll(d, p, true)
  820. #define assert_pll_disabled(d, p) assert_pll(d, p, false)
  821. /* For ILK+ */
  822. static void assert_pch_pll(struct drm_i915_private *dev_priv,
  823. struct intel_crtc *intel_crtc, bool state)
  824. {
  825. int reg;
  826. u32 val;
  827. bool cur_state;
  828. if (HAS_PCH_LPT(dev_priv->dev)) {
  829. DRM_DEBUG_DRIVER("LPT detected: skipping PCH PLL test\n");
  830. return;
  831. }
  832. if (!intel_crtc->pch_pll) {
  833. WARN(1, "asserting PCH PLL enabled with no PLL\n");
  834. return;
  835. }
  836. if (HAS_PCH_CPT(dev_priv->dev)) {
  837. u32 pch_dpll;
  838. pch_dpll = I915_READ(PCH_DPLL_SEL);
  839. /* Make sure the selected PLL is enabled to the transcoder */
  840. WARN(!((pch_dpll >> (4 * intel_crtc->pipe)) & 8),
  841. "transcoder %d PLL not enabled\n", intel_crtc->pipe);
  842. }
  843. reg = intel_crtc->pch_pll->pll_reg;
  844. val = I915_READ(reg);
  845. cur_state = !!(val & DPLL_VCO_ENABLE);
  846. WARN(cur_state != state,
  847. "PCH PLL state assertion failure (expected %s, current %s)\n",
  848. state_string(state), state_string(cur_state));
  849. }
  850. #define assert_pch_pll_enabled(d, p) assert_pch_pll(d, p, true)
  851. #define assert_pch_pll_disabled(d, p) assert_pch_pll(d, p, false)
  852. static void assert_fdi_tx(struct drm_i915_private *dev_priv,
  853. enum pipe pipe, bool state)
  854. {
  855. int reg;
  856. u32 val;
  857. bool cur_state;
  858. if (IS_HASWELL(dev_priv->dev)) {
  859. /* On Haswell, DDI is used instead of FDI_TX_CTL */
  860. reg = DDI_FUNC_CTL(pipe);
  861. val = I915_READ(reg);
  862. cur_state = !!(val & PIPE_DDI_FUNC_ENABLE);
  863. } else {
  864. reg = FDI_TX_CTL(pipe);
  865. val = I915_READ(reg);
  866. cur_state = !!(val & FDI_TX_ENABLE);
  867. }
  868. WARN(cur_state != state,
  869. "FDI TX state assertion failure (expected %s, current %s)\n",
  870. state_string(state), state_string(cur_state));
  871. }
  872. #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
  873. #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
  874. static void assert_fdi_rx(struct drm_i915_private *dev_priv,
  875. enum pipe pipe, bool state)
  876. {
  877. int reg;
  878. u32 val;
  879. bool cur_state;
  880. if (IS_HASWELL(dev_priv->dev) && pipe > 0) {
  881. DRM_ERROR("Attempting to enable FDI_RX on Haswell pipe > 0\n");
  882. return;
  883. } else {
  884. reg = FDI_RX_CTL(pipe);
  885. val = I915_READ(reg);
  886. cur_state = !!(val & FDI_RX_ENABLE);
  887. }
  888. WARN(cur_state != state,
  889. "FDI RX state assertion failure (expected %s, current %s)\n",
  890. state_string(state), state_string(cur_state));
  891. }
  892. #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
  893. #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
  894. static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv,
  895. enum pipe pipe)
  896. {
  897. int reg;
  898. u32 val;
  899. /* ILK FDI PLL is always enabled */
  900. if (dev_priv->info->gen == 5)
  901. return;
  902. /* On Haswell, DDI ports are responsible for the FDI PLL setup */
  903. if (IS_HASWELL(dev_priv->dev))
  904. return;
  905. reg = FDI_TX_CTL(pipe);
  906. val = I915_READ(reg);
  907. WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n");
  908. }
  909. static void assert_fdi_rx_pll_enabled(struct drm_i915_private *dev_priv,
  910. enum pipe pipe)
  911. {
  912. int reg;
  913. u32 val;
  914. if (IS_HASWELL(dev_priv->dev) && pipe > 0) {
  915. DRM_ERROR("Attempting to enable FDI on Haswell with pipe > 0\n");
  916. return;
  917. }
  918. reg = FDI_RX_CTL(pipe);
  919. val = I915_READ(reg);
  920. WARN(!(val & FDI_RX_PLL_ENABLE), "FDI RX PLL assertion failure, should be active but is disabled\n");
  921. }
  922. static void assert_panel_unlocked(struct drm_i915_private *dev_priv,
  923. enum pipe pipe)
  924. {
  925. int pp_reg, lvds_reg;
  926. u32 val;
  927. enum pipe panel_pipe = PIPE_A;
  928. bool locked = true;
  929. if (HAS_PCH_SPLIT(dev_priv->dev)) {
  930. pp_reg = PCH_PP_CONTROL;
  931. lvds_reg = PCH_LVDS;
  932. } else {
  933. pp_reg = PP_CONTROL;
  934. lvds_reg = LVDS;
  935. }
  936. val = I915_READ(pp_reg);
  937. if (!(val & PANEL_POWER_ON) ||
  938. ((val & PANEL_UNLOCK_REGS) == PANEL_UNLOCK_REGS))
  939. locked = false;
  940. if (I915_READ(lvds_reg) & LVDS_PIPEB_SELECT)
  941. panel_pipe = PIPE_B;
  942. WARN(panel_pipe == pipe && locked,
  943. "panel assertion failure, pipe %c regs locked\n",
  944. pipe_name(pipe));
  945. }
  946. void assert_pipe(struct drm_i915_private *dev_priv,
  947. enum pipe pipe, bool state)
  948. {
  949. int reg;
  950. u32 val;
  951. bool cur_state;
  952. /* if we need the pipe A quirk it must be always on */
  953. if (pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE)
  954. state = true;
  955. reg = PIPECONF(pipe);
  956. val = I915_READ(reg);
  957. cur_state = !!(val & PIPECONF_ENABLE);
  958. WARN(cur_state != state,
  959. "pipe %c assertion failure (expected %s, current %s)\n",
  960. pipe_name(pipe), state_string(state), state_string(cur_state));
  961. }
  962. static void assert_plane(struct drm_i915_private *dev_priv,
  963. enum plane plane, bool state)
  964. {
  965. int reg;
  966. u32 val;
  967. bool cur_state;
  968. reg = DSPCNTR(plane);
  969. val = I915_READ(reg);
  970. cur_state = !!(val & DISPLAY_PLANE_ENABLE);
  971. WARN(cur_state != state,
  972. "plane %c assertion failure (expected %s, current %s)\n",
  973. plane_name(plane), state_string(state), state_string(cur_state));
  974. }
  975. #define assert_plane_enabled(d, p) assert_plane(d, p, true)
  976. #define assert_plane_disabled(d, p) assert_plane(d, p, false)
  977. static void assert_planes_disabled(struct drm_i915_private *dev_priv,
  978. enum pipe pipe)
  979. {
  980. int reg, i;
  981. u32 val;
  982. int cur_pipe;
  983. /* Planes are fixed to pipes on ILK+ */
  984. if (HAS_PCH_SPLIT(dev_priv->dev)) {
  985. reg = DSPCNTR(pipe);
  986. val = I915_READ(reg);
  987. WARN((val & DISPLAY_PLANE_ENABLE),
  988. "plane %c assertion failure, should be disabled but not\n",
  989. plane_name(pipe));
  990. return;
  991. }
  992. /* Need to check both planes against the pipe */
  993. for (i = 0; i < 2; i++) {
  994. reg = DSPCNTR(i);
  995. val = I915_READ(reg);
  996. cur_pipe = (val & DISPPLANE_SEL_PIPE_MASK) >>
  997. DISPPLANE_SEL_PIPE_SHIFT;
  998. WARN((val & DISPLAY_PLANE_ENABLE) && pipe == cur_pipe,
  999. "plane %c assertion failure, should be off on pipe %c but is still active\n",
  1000. plane_name(i), pipe_name(pipe));
  1001. }
  1002. }
  1003. static void assert_pch_refclk_enabled(struct drm_i915_private *dev_priv)
  1004. {
  1005. u32 val;
  1006. bool enabled;
  1007. if (HAS_PCH_LPT(dev_priv->dev)) {
  1008. DRM_DEBUG_DRIVER("LPT does not has PCH refclk, skipping check\n");
  1009. return;
  1010. }
  1011. val = I915_READ(PCH_DREF_CONTROL);
  1012. enabled = !!(val & (DREF_SSC_SOURCE_MASK | DREF_NONSPREAD_SOURCE_MASK |
  1013. DREF_SUPERSPREAD_SOURCE_MASK));
  1014. WARN(!enabled, "PCH refclk assertion failure, should be active but is disabled\n");
  1015. }
  1016. static void assert_transcoder_disabled(struct drm_i915_private *dev_priv,
  1017. enum pipe pipe)
  1018. {
  1019. int reg;
  1020. u32 val;
  1021. bool enabled;
  1022. reg = TRANSCONF(pipe);
  1023. val = I915_READ(reg);
  1024. enabled = !!(val & TRANS_ENABLE);
  1025. WARN(enabled,
  1026. "transcoder assertion failed, should be off on pipe %c but is still active\n",
  1027. pipe_name(pipe));
  1028. }
  1029. static bool dp_pipe_enabled(struct drm_i915_private *dev_priv,
  1030. enum pipe pipe, u32 port_sel, u32 val)
  1031. {
  1032. if ((val & DP_PORT_EN) == 0)
  1033. return false;
  1034. if (HAS_PCH_CPT(dev_priv->dev)) {
  1035. u32 trans_dp_ctl_reg = TRANS_DP_CTL(pipe);
  1036. u32 trans_dp_ctl = I915_READ(trans_dp_ctl_reg);
  1037. if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel)
  1038. return false;
  1039. } else {
  1040. if ((val & DP_PIPE_MASK) != (pipe << 30))
  1041. return false;
  1042. }
  1043. return true;
  1044. }
  1045. static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv,
  1046. enum pipe pipe, u32 val)
  1047. {
  1048. if ((val & PORT_ENABLE) == 0)
  1049. return false;
  1050. if (HAS_PCH_CPT(dev_priv->dev)) {
  1051. if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
  1052. return false;
  1053. } else {
  1054. if ((val & TRANSCODER_MASK) != TRANSCODER(pipe))
  1055. return false;
  1056. }
  1057. return true;
  1058. }
  1059. static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv,
  1060. enum pipe pipe, u32 val)
  1061. {
  1062. if ((val & LVDS_PORT_EN) == 0)
  1063. return false;
  1064. if (HAS_PCH_CPT(dev_priv->dev)) {
  1065. if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
  1066. return false;
  1067. } else {
  1068. if ((val & LVDS_PIPE_MASK) != LVDS_PIPE(pipe))
  1069. return false;
  1070. }
  1071. return true;
  1072. }
  1073. static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv,
  1074. enum pipe pipe, u32 val)
  1075. {
  1076. if ((val & ADPA_DAC_ENABLE) == 0)
  1077. return false;
  1078. if (HAS_PCH_CPT(dev_priv->dev)) {
  1079. if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
  1080. return false;
  1081. } else {
  1082. if ((val & ADPA_PIPE_SELECT_MASK) != ADPA_PIPE_SELECT(pipe))
  1083. return false;
  1084. }
  1085. return true;
  1086. }
  1087. static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
  1088. enum pipe pipe, int reg, u32 port_sel)
  1089. {
  1090. u32 val = I915_READ(reg);
  1091. WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val),
  1092. "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
  1093. reg, pipe_name(pipe));
  1094. }
  1095. static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
  1096. enum pipe pipe, int reg)
  1097. {
  1098. u32 val = I915_READ(reg);
  1099. WARN(hdmi_pipe_enabled(dev_priv, val, pipe),
  1100. "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n",
  1101. reg, pipe_name(pipe));
  1102. }
  1103. static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
  1104. enum pipe pipe)
  1105. {
  1106. int reg;
  1107. u32 val;
  1108. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B);
  1109. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C);
  1110. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_D, TRANS_DP_PORT_SEL_D);
  1111. reg = PCH_ADPA;
  1112. val = I915_READ(reg);
  1113. WARN(adpa_pipe_enabled(dev_priv, val, pipe),
  1114. "PCH VGA enabled on transcoder %c, should be disabled\n",
  1115. pipe_name(pipe));
  1116. reg = PCH_LVDS;
  1117. val = I915_READ(reg);
  1118. WARN(lvds_pipe_enabled(dev_priv, val, pipe),
  1119. "PCH LVDS enabled on transcoder %c, should be disabled\n",
  1120. pipe_name(pipe));
  1121. assert_pch_hdmi_disabled(dev_priv, pipe, HDMIB);
  1122. assert_pch_hdmi_disabled(dev_priv, pipe, HDMIC);
  1123. assert_pch_hdmi_disabled(dev_priv, pipe, HDMID);
  1124. }
  1125. /**
  1126. * intel_enable_pll - enable a PLL
  1127. * @dev_priv: i915 private structure
  1128. * @pipe: pipe PLL to enable
  1129. *
  1130. * Enable @pipe's PLL so we can start pumping pixels from a plane. Check to
  1131. * make sure the PLL reg is writable first though, since the panel write
  1132. * protect mechanism may be enabled.
  1133. *
  1134. * Note! This is for pre-ILK only.
  1135. */
  1136. static void intel_enable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
  1137. {
  1138. int reg;
  1139. u32 val;
  1140. /* No really, not for ILK+ */
  1141. BUG_ON(dev_priv->info->gen >= 5);
  1142. /* PLL is protected by panel, make sure we can write it */
  1143. if (IS_MOBILE(dev_priv->dev) && !IS_I830(dev_priv->dev))
  1144. assert_panel_unlocked(dev_priv, pipe);
  1145. reg = DPLL(pipe);
  1146. val = I915_READ(reg);
  1147. val |= DPLL_VCO_ENABLE;
  1148. /* We do this three times for luck */
  1149. I915_WRITE(reg, val);
  1150. POSTING_READ(reg);
  1151. udelay(150); /* wait for warmup */
  1152. I915_WRITE(reg, val);
  1153. POSTING_READ(reg);
  1154. udelay(150); /* wait for warmup */
  1155. I915_WRITE(reg, val);
  1156. POSTING_READ(reg);
  1157. udelay(150); /* wait for warmup */
  1158. }
  1159. /**
  1160. * intel_disable_pll - disable a PLL
  1161. * @dev_priv: i915 private structure
  1162. * @pipe: pipe PLL to disable
  1163. *
  1164. * Disable the PLL for @pipe, making sure the pipe is off first.
  1165. *
  1166. * Note! This is for pre-ILK only.
  1167. */
  1168. static void intel_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
  1169. {
  1170. int reg;
  1171. u32 val;
  1172. /* Don't disable pipe A or pipe A PLLs if needed */
  1173. if (pipe == PIPE_A && (dev_priv->quirks & QUIRK_PIPEA_FORCE))
  1174. return;
  1175. /* Make sure the pipe isn't still relying on us */
  1176. assert_pipe_disabled(dev_priv, pipe);
  1177. reg = DPLL(pipe);
  1178. val = I915_READ(reg);
  1179. val &= ~DPLL_VCO_ENABLE;
  1180. I915_WRITE(reg, val);
  1181. POSTING_READ(reg);
  1182. }
  1183. /* SBI access */
  1184. static void
  1185. intel_sbi_write(struct drm_i915_private *dev_priv, u16 reg, u32 value)
  1186. {
  1187. unsigned long flags;
  1188. spin_lock_irqsave(&dev_priv->dpio_lock, flags);
  1189. if (wait_for((I915_READ(SBI_CTL_STAT) & SBI_READY) == 0,
  1190. 100)) {
  1191. DRM_ERROR("timeout waiting for SBI to become ready\n");
  1192. goto out_unlock;
  1193. }
  1194. I915_WRITE(SBI_ADDR,
  1195. (reg << 16));
  1196. I915_WRITE(SBI_DATA,
  1197. value);
  1198. I915_WRITE(SBI_CTL_STAT,
  1199. SBI_BUSY |
  1200. SBI_CTL_OP_CRWR);
  1201. if (wait_for((I915_READ(SBI_CTL_STAT) & (SBI_READY | SBI_RESPONSE_SUCCESS)) == 0,
  1202. 100)) {
  1203. DRM_ERROR("timeout waiting for SBI to complete write transaction\n");
  1204. goto out_unlock;
  1205. }
  1206. out_unlock:
  1207. spin_unlock_irqrestore(&dev_priv->dpio_lock, flags);
  1208. }
  1209. static u32
  1210. intel_sbi_read(struct drm_i915_private *dev_priv, u16 reg)
  1211. {
  1212. unsigned long flags;
  1213. u32 value;
  1214. spin_lock_irqsave(&dev_priv->dpio_lock, flags);
  1215. if (wait_for((I915_READ(SBI_CTL_STAT) & SBI_READY) == 0,
  1216. 100)) {
  1217. DRM_ERROR("timeout waiting for SBI to become ready\n");
  1218. goto out_unlock;
  1219. }
  1220. I915_WRITE(SBI_ADDR,
  1221. (reg << 16));
  1222. I915_WRITE(SBI_CTL_STAT,
  1223. SBI_BUSY |
  1224. SBI_CTL_OP_CRRD);
  1225. if (wait_for((I915_READ(SBI_CTL_STAT) & (SBI_READY | SBI_RESPONSE_SUCCESS)) == 0,
  1226. 100)) {
  1227. DRM_ERROR("timeout waiting for SBI to complete read transaction\n");
  1228. goto out_unlock;
  1229. }
  1230. value = I915_READ(SBI_DATA);
  1231. out_unlock:
  1232. spin_unlock_irqrestore(&dev_priv->dpio_lock, flags);
  1233. return value;
  1234. }
  1235. /**
  1236. * intel_enable_pch_pll - enable PCH PLL
  1237. * @dev_priv: i915 private structure
  1238. * @pipe: pipe PLL to enable
  1239. *
  1240. * The PCH PLL needs to be enabled before the PCH transcoder, since it
  1241. * drives the transcoder clock.
  1242. */
  1243. static void intel_enable_pch_pll(struct intel_crtc *intel_crtc)
  1244. {
  1245. struct drm_i915_private *dev_priv = intel_crtc->base.dev->dev_private;
  1246. struct intel_pch_pll *pll = intel_crtc->pch_pll;
  1247. int reg;
  1248. u32 val;
  1249. /* PCH only available on ILK+ */
  1250. BUG_ON(dev_priv->info->gen < 5);
  1251. BUG_ON(pll == NULL);
  1252. BUG_ON(pll->refcount == 0);
  1253. DRM_DEBUG_KMS("enable PCH PLL %x (active %d, on? %d)for crtc %d\n",
  1254. pll->pll_reg, pll->active, pll->on,
  1255. intel_crtc->base.base.id);
  1256. /* PCH refclock must be enabled first */
  1257. assert_pch_refclk_enabled(dev_priv);
  1258. if (pll->active++ && pll->on) {
  1259. assert_pch_pll_enabled(dev_priv, intel_crtc);
  1260. return;
  1261. }
  1262. DRM_DEBUG_KMS("enabling PCH PLL %x\n", pll->pll_reg);
  1263. reg = pll->pll_reg;
  1264. val = I915_READ(reg);
  1265. val |= DPLL_VCO_ENABLE;
  1266. I915_WRITE(reg, val);
  1267. POSTING_READ(reg);
  1268. udelay(200);
  1269. pll->on = true;
  1270. }
  1271. static void intel_disable_pch_pll(struct intel_crtc *intel_crtc)
  1272. {
  1273. struct drm_i915_private *dev_priv = intel_crtc->base.dev->dev_private;
  1274. struct intel_pch_pll *pll = intel_crtc->pch_pll;
  1275. int reg;
  1276. u32 val;
  1277. /* PCH only available on ILK+ */
  1278. BUG_ON(dev_priv->info->gen < 5);
  1279. if (pll == NULL)
  1280. return;
  1281. BUG_ON(pll->refcount == 0);
  1282. DRM_DEBUG_KMS("disable PCH PLL %x (active %d, on? %d) for crtc %d\n",
  1283. pll->pll_reg, pll->active, pll->on,
  1284. intel_crtc->base.base.id);
  1285. BUG_ON(pll->active == 0);
  1286. if (--pll->active) {
  1287. assert_pch_pll_enabled(dev_priv, intel_crtc);
  1288. return;
  1289. }
  1290. DRM_DEBUG_KMS("disabling PCH PLL %x\n", pll->pll_reg);
  1291. /* Make sure transcoder isn't still depending on us */
  1292. assert_transcoder_disabled(dev_priv, intel_crtc->pipe);
  1293. reg = pll->pll_reg;
  1294. val = I915_READ(reg);
  1295. val &= ~DPLL_VCO_ENABLE;
  1296. I915_WRITE(reg, val);
  1297. POSTING_READ(reg);
  1298. udelay(200);
  1299. pll->on = false;
  1300. }
  1301. static void intel_enable_transcoder(struct drm_i915_private *dev_priv,
  1302. enum pipe pipe)
  1303. {
  1304. int reg;
  1305. u32 val, pipeconf_val;
  1306. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  1307. /* PCH only available on ILK+ */
  1308. BUG_ON(dev_priv->info->gen < 5);
  1309. /* Make sure PCH DPLL is enabled */
  1310. assert_pch_pll_enabled(dev_priv, to_intel_crtc(crtc));
  1311. /* FDI must be feeding us bits for PCH ports */
  1312. assert_fdi_tx_enabled(dev_priv, pipe);
  1313. assert_fdi_rx_enabled(dev_priv, pipe);
  1314. if (IS_HASWELL(dev_priv->dev) && pipe > 0) {
  1315. DRM_ERROR("Attempting to enable transcoder on Haswell with pipe > 0\n");
  1316. return;
  1317. }
  1318. reg = TRANSCONF(pipe);
  1319. val = I915_READ(reg);
  1320. pipeconf_val = I915_READ(PIPECONF(pipe));
  1321. if (HAS_PCH_IBX(dev_priv->dev)) {
  1322. /*
  1323. * make the BPC in transcoder be consistent with
  1324. * that in pipeconf reg.
  1325. */
  1326. val &= ~PIPE_BPC_MASK;
  1327. val |= pipeconf_val & PIPE_BPC_MASK;
  1328. }
  1329. val &= ~TRANS_INTERLACE_MASK;
  1330. if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK)
  1331. if (HAS_PCH_IBX(dev_priv->dev) &&
  1332. intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO))
  1333. val |= TRANS_LEGACY_INTERLACED_ILK;
  1334. else
  1335. val |= TRANS_INTERLACED;
  1336. else
  1337. val |= TRANS_PROGRESSIVE;
  1338. I915_WRITE(reg, val | TRANS_ENABLE);
  1339. if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100))
  1340. DRM_ERROR("failed to enable transcoder %d\n", pipe);
  1341. }
  1342. static void intel_disable_transcoder(struct drm_i915_private *dev_priv,
  1343. enum pipe pipe)
  1344. {
  1345. int reg;
  1346. u32 val;
  1347. /* FDI relies on the transcoder */
  1348. assert_fdi_tx_disabled(dev_priv, pipe);
  1349. assert_fdi_rx_disabled(dev_priv, pipe);
  1350. /* Ports must be off as well */
  1351. assert_pch_ports_disabled(dev_priv, pipe);
  1352. reg = TRANSCONF(pipe);
  1353. val = I915_READ(reg);
  1354. val &= ~TRANS_ENABLE;
  1355. I915_WRITE(reg, val);
  1356. /* wait for PCH transcoder off, transcoder state */
  1357. if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50))
  1358. DRM_ERROR("failed to disable transcoder %d\n", pipe);
  1359. }
  1360. /**
  1361. * intel_enable_pipe - enable a pipe, asserting requirements
  1362. * @dev_priv: i915 private structure
  1363. * @pipe: pipe to enable
  1364. * @pch_port: on ILK+, is this pipe driving a PCH port or not
  1365. *
  1366. * Enable @pipe, making sure that various hardware specific requirements
  1367. * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc.
  1368. *
  1369. * @pipe should be %PIPE_A or %PIPE_B.
  1370. *
  1371. * Will wait until the pipe is actually running (i.e. first vblank) before
  1372. * returning.
  1373. */
  1374. static void intel_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe,
  1375. bool pch_port)
  1376. {
  1377. int reg;
  1378. u32 val;
  1379. /*
  1380. * A pipe without a PLL won't actually be able to drive bits from
  1381. * a plane. On ILK+ the pipe PLLs are integrated, so we don't
  1382. * need the check.
  1383. */
  1384. if (!HAS_PCH_SPLIT(dev_priv->dev))
  1385. assert_pll_enabled(dev_priv, pipe);
  1386. else {
  1387. if (pch_port) {
  1388. /* if driving the PCH, we need FDI enabled */
  1389. assert_fdi_rx_pll_enabled(dev_priv, pipe);
  1390. assert_fdi_tx_pll_enabled(dev_priv, pipe);
  1391. }
  1392. /* FIXME: assert CPU port conditions for SNB+ */
  1393. }
  1394. reg = PIPECONF(pipe);
  1395. val = I915_READ(reg);
  1396. if (val & PIPECONF_ENABLE)
  1397. return;
  1398. I915_WRITE(reg, val | PIPECONF_ENABLE);
  1399. intel_wait_for_vblank(dev_priv->dev, pipe);
  1400. }
  1401. /**
  1402. * intel_disable_pipe - disable a pipe, asserting requirements
  1403. * @dev_priv: i915 private structure
  1404. * @pipe: pipe to disable
  1405. *
  1406. * Disable @pipe, making sure that various hardware specific requirements
  1407. * are met, if applicable, e.g. plane disabled, panel fitter off, etc.
  1408. *
  1409. * @pipe should be %PIPE_A or %PIPE_B.
  1410. *
  1411. * Will wait until the pipe has shut down before returning.
  1412. */
  1413. static void intel_disable_pipe(struct drm_i915_private *dev_priv,
  1414. enum pipe pipe)
  1415. {
  1416. int reg;
  1417. u32 val;
  1418. /*
  1419. * Make sure planes won't keep trying to pump pixels to us,
  1420. * or we might hang the display.
  1421. */
  1422. assert_planes_disabled(dev_priv, pipe);
  1423. /* Don't disable pipe A or pipe A PLLs if needed */
  1424. if (pipe == PIPE_A && (dev_priv->quirks & QUIRK_PIPEA_FORCE))
  1425. return;
  1426. reg = PIPECONF(pipe);
  1427. val = I915_READ(reg);
  1428. if ((val & PIPECONF_ENABLE) == 0)
  1429. return;
  1430. I915_WRITE(reg, val & ~PIPECONF_ENABLE);
  1431. intel_wait_for_pipe_off(dev_priv->dev, pipe);
  1432. }
  1433. /*
  1434. * Plane regs are double buffered, going from enabled->disabled needs a
  1435. * trigger in order to latch. The display address reg provides this.
  1436. */
  1437. void intel_flush_display_plane(struct drm_i915_private *dev_priv,
  1438. enum plane plane)
  1439. {
  1440. I915_WRITE(DSPADDR(plane), I915_READ(DSPADDR(plane)));
  1441. I915_WRITE(DSPSURF(plane), I915_READ(DSPSURF(plane)));
  1442. }
  1443. /**
  1444. * intel_enable_plane - enable a display plane on a given pipe
  1445. * @dev_priv: i915 private structure
  1446. * @plane: plane to enable
  1447. * @pipe: pipe being fed
  1448. *
  1449. * Enable @plane on @pipe, making sure that @pipe is running first.
  1450. */
  1451. static void intel_enable_plane(struct drm_i915_private *dev_priv,
  1452. enum plane plane, enum pipe pipe)
  1453. {
  1454. int reg;
  1455. u32 val;
  1456. /* If the pipe isn't enabled, we can't pump pixels and may hang */
  1457. assert_pipe_enabled(dev_priv, pipe);
  1458. reg = DSPCNTR(plane);
  1459. val = I915_READ(reg);
  1460. if (val & DISPLAY_PLANE_ENABLE)
  1461. return;
  1462. I915_WRITE(reg, val | DISPLAY_PLANE_ENABLE);
  1463. intel_flush_display_plane(dev_priv, plane);
  1464. intel_wait_for_vblank(dev_priv->dev, pipe);
  1465. }
  1466. /**
  1467. * intel_disable_plane - disable a display plane
  1468. * @dev_priv: i915 private structure
  1469. * @plane: plane to disable
  1470. * @pipe: pipe consuming the data
  1471. *
  1472. * Disable @plane; should be an independent operation.
  1473. */
  1474. static void intel_disable_plane(struct drm_i915_private *dev_priv,
  1475. enum plane plane, enum pipe pipe)
  1476. {
  1477. int reg;
  1478. u32 val;
  1479. reg = DSPCNTR(plane);
  1480. val = I915_READ(reg);
  1481. if ((val & DISPLAY_PLANE_ENABLE) == 0)
  1482. return;
  1483. I915_WRITE(reg, val & ~DISPLAY_PLANE_ENABLE);
  1484. intel_flush_display_plane(dev_priv, plane);
  1485. intel_wait_for_vblank(dev_priv->dev, pipe);
  1486. }
  1487. static void disable_pch_dp(struct drm_i915_private *dev_priv,
  1488. enum pipe pipe, int reg, u32 port_sel)
  1489. {
  1490. u32 val = I915_READ(reg);
  1491. if (dp_pipe_enabled(dev_priv, pipe, port_sel, val)) {
  1492. DRM_DEBUG_KMS("Disabling pch dp %x on pipe %d\n", reg, pipe);
  1493. I915_WRITE(reg, val & ~DP_PORT_EN);
  1494. }
  1495. }
  1496. static void disable_pch_hdmi(struct drm_i915_private *dev_priv,
  1497. enum pipe pipe, int reg)
  1498. {
  1499. u32 val = I915_READ(reg);
  1500. if (hdmi_pipe_enabled(dev_priv, val, pipe)) {
  1501. DRM_DEBUG_KMS("Disabling pch HDMI %x on pipe %d\n",
  1502. reg, pipe);
  1503. I915_WRITE(reg, val & ~PORT_ENABLE);
  1504. }
  1505. }
  1506. /* Disable any ports connected to this transcoder */
  1507. static void intel_disable_pch_ports(struct drm_i915_private *dev_priv,
  1508. enum pipe pipe)
  1509. {
  1510. u32 reg, val;
  1511. val = I915_READ(PCH_PP_CONTROL);
  1512. I915_WRITE(PCH_PP_CONTROL, val | PANEL_UNLOCK_REGS);
  1513. disable_pch_dp(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B);
  1514. disable_pch_dp(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C);
  1515. disable_pch_dp(dev_priv, pipe, PCH_DP_D, TRANS_DP_PORT_SEL_D);
  1516. reg = PCH_ADPA;
  1517. val = I915_READ(reg);
  1518. if (adpa_pipe_enabled(dev_priv, val, pipe))
  1519. I915_WRITE(reg, val & ~ADPA_DAC_ENABLE);
  1520. reg = PCH_LVDS;
  1521. val = I915_READ(reg);
  1522. if (lvds_pipe_enabled(dev_priv, val, pipe)) {
  1523. DRM_DEBUG_KMS("disable lvds on pipe %d val 0x%08x\n", pipe, val);
  1524. I915_WRITE(reg, val & ~LVDS_PORT_EN);
  1525. POSTING_READ(reg);
  1526. udelay(100);
  1527. }
  1528. disable_pch_hdmi(dev_priv, pipe, HDMIB);
  1529. disable_pch_hdmi(dev_priv, pipe, HDMIC);
  1530. disable_pch_hdmi(dev_priv, pipe, HDMID);
  1531. }
  1532. int
  1533. intel_pin_and_fence_fb_obj(struct drm_device *dev,
  1534. struct drm_i915_gem_object *obj,
  1535. struct intel_ring_buffer *pipelined)
  1536. {
  1537. struct drm_i915_private *dev_priv = dev->dev_private;
  1538. u32 alignment;
  1539. int ret;
  1540. switch (obj->tiling_mode) {
  1541. case I915_TILING_NONE:
  1542. if (IS_BROADWATER(dev) || IS_CRESTLINE(dev))
  1543. alignment = 128 * 1024;
  1544. else if (INTEL_INFO(dev)->gen >= 4)
  1545. alignment = 4 * 1024;
  1546. else
  1547. alignment = 64 * 1024;
  1548. break;
  1549. case I915_TILING_X:
  1550. /* pin() will align the object as required by fence */
  1551. alignment = 0;
  1552. break;
  1553. case I915_TILING_Y:
  1554. /* FIXME: Is this true? */
  1555. DRM_ERROR("Y tiled not allowed for scan out buffers\n");
  1556. return -EINVAL;
  1557. default:
  1558. BUG();
  1559. }
  1560. dev_priv->mm.interruptible = false;
  1561. ret = i915_gem_object_pin_to_display_plane(obj, alignment, pipelined);
  1562. if (ret)
  1563. goto err_interruptible;
  1564. /* Install a fence for tiled scan-out. Pre-i965 always needs a
  1565. * fence, whereas 965+ only requires a fence if using
  1566. * framebuffer compression. For simplicity, we always install
  1567. * a fence as the cost is not that onerous.
  1568. */
  1569. ret = i915_gem_object_get_fence(obj);
  1570. if (ret)
  1571. goto err_unpin;
  1572. i915_gem_object_pin_fence(obj);
  1573. dev_priv->mm.interruptible = true;
  1574. return 0;
  1575. err_unpin:
  1576. i915_gem_object_unpin(obj);
  1577. err_interruptible:
  1578. dev_priv->mm.interruptible = true;
  1579. return ret;
  1580. }
  1581. void intel_unpin_fb_obj(struct drm_i915_gem_object *obj)
  1582. {
  1583. i915_gem_object_unpin_fence(obj);
  1584. i915_gem_object_unpin(obj);
  1585. }
  1586. static int i9xx_update_plane(struct drm_crtc *crtc, struct drm_framebuffer *fb,
  1587. int x, int y)
  1588. {
  1589. struct drm_device *dev = crtc->dev;
  1590. struct drm_i915_private *dev_priv = dev->dev_private;
  1591. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1592. struct intel_framebuffer *intel_fb;
  1593. struct drm_i915_gem_object *obj;
  1594. int plane = intel_crtc->plane;
  1595. unsigned long Start, Offset;
  1596. u32 dspcntr;
  1597. u32 reg;
  1598. switch (plane) {
  1599. case 0:
  1600. case 1:
  1601. break;
  1602. default:
  1603. DRM_ERROR("Can't update plane %d in SAREA\n", plane);
  1604. return -EINVAL;
  1605. }
  1606. intel_fb = to_intel_framebuffer(fb);
  1607. obj = intel_fb->obj;
  1608. reg = DSPCNTR(plane);
  1609. dspcntr = I915_READ(reg);
  1610. /* Mask out pixel format bits in case we change it */
  1611. dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
  1612. switch (fb->bits_per_pixel) {
  1613. case 8:
  1614. dspcntr |= DISPPLANE_8BPP;
  1615. break;
  1616. case 16:
  1617. if (fb->depth == 15)
  1618. dspcntr |= DISPPLANE_15_16BPP;
  1619. else
  1620. dspcntr |= DISPPLANE_16BPP;
  1621. break;
  1622. case 24:
  1623. case 32:
  1624. dspcntr |= DISPPLANE_32BPP_NO_ALPHA;
  1625. break;
  1626. default:
  1627. DRM_ERROR("Unknown color depth %d\n", fb->bits_per_pixel);
  1628. return -EINVAL;
  1629. }
  1630. if (INTEL_INFO(dev)->gen >= 4) {
  1631. if (obj->tiling_mode != I915_TILING_NONE)
  1632. dspcntr |= DISPPLANE_TILED;
  1633. else
  1634. dspcntr &= ~DISPPLANE_TILED;
  1635. }
  1636. I915_WRITE(reg, dspcntr);
  1637. Start = obj->gtt_offset;
  1638. Offset = y * fb->pitches[0] + x * (fb->bits_per_pixel / 8);
  1639. DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n",
  1640. Start, Offset, x, y, fb->pitches[0]);
  1641. I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);
  1642. if (INTEL_INFO(dev)->gen >= 4) {
  1643. I915_MODIFY_DISPBASE(DSPSURF(plane), Start);
  1644. I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
  1645. I915_WRITE(DSPADDR(plane), Offset);
  1646. } else
  1647. I915_WRITE(DSPADDR(plane), Start + Offset);
  1648. POSTING_READ(reg);
  1649. return 0;
  1650. }
  1651. static int ironlake_update_plane(struct drm_crtc *crtc,
  1652. struct drm_framebuffer *fb, int x, int y)
  1653. {
  1654. struct drm_device *dev = crtc->dev;
  1655. struct drm_i915_private *dev_priv = dev->dev_private;
  1656. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1657. struct intel_framebuffer *intel_fb;
  1658. struct drm_i915_gem_object *obj;
  1659. int plane = intel_crtc->plane;
  1660. unsigned long Start, Offset;
  1661. u32 dspcntr;
  1662. u32 reg;
  1663. switch (plane) {
  1664. case 0:
  1665. case 1:
  1666. case 2:
  1667. break;
  1668. default:
  1669. DRM_ERROR("Can't update plane %d in SAREA\n", plane);
  1670. return -EINVAL;
  1671. }
  1672. intel_fb = to_intel_framebuffer(fb);
  1673. obj = intel_fb->obj;
  1674. reg = DSPCNTR(plane);
  1675. dspcntr = I915_READ(reg);
  1676. /* Mask out pixel format bits in case we change it */
  1677. dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
  1678. switch (fb->bits_per_pixel) {
  1679. case 8:
  1680. dspcntr |= DISPPLANE_8BPP;
  1681. break;
  1682. case 16:
  1683. if (fb->depth != 16)
  1684. return -EINVAL;
  1685. dspcntr |= DISPPLANE_16BPP;
  1686. break;
  1687. case 24:
  1688. case 32:
  1689. if (fb->depth == 24)
  1690. dspcntr |= DISPPLANE_32BPP_NO_ALPHA;
  1691. else if (fb->depth == 30)
  1692. dspcntr |= DISPPLANE_32BPP_30BIT_NO_ALPHA;
  1693. else
  1694. return -EINVAL;
  1695. break;
  1696. default:
  1697. DRM_ERROR("Unknown color depth %d\n", fb->bits_per_pixel);
  1698. return -EINVAL;
  1699. }
  1700. if (obj->tiling_mode != I915_TILING_NONE)
  1701. dspcntr |= DISPPLANE_TILED;
  1702. else
  1703. dspcntr &= ~DISPPLANE_TILED;
  1704. /* must disable */
  1705. dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
  1706. I915_WRITE(reg, dspcntr);
  1707. Start = obj->gtt_offset;
  1708. Offset = y * fb->pitches[0] + x * (fb->bits_per_pixel / 8);
  1709. DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n",
  1710. Start, Offset, x, y, fb->pitches[0]);
  1711. I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);
  1712. I915_MODIFY_DISPBASE(DSPSURF(plane), Start);
  1713. I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
  1714. I915_WRITE(DSPADDR(plane), Offset);
  1715. POSTING_READ(reg);
  1716. return 0;
  1717. }
  1718. /* Assume fb object is pinned & idle & fenced and just update base pointers */
  1719. static int
  1720. intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb,
  1721. int x, int y, enum mode_set_atomic state)
  1722. {
  1723. struct drm_device *dev = crtc->dev;
  1724. struct drm_i915_private *dev_priv = dev->dev_private;
  1725. if (dev_priv->display.disable_fbc)
  1726. dev_priv->display.disable_fbc(dev);
  1727. intel_increase_pllclock(crtc);
  1728. return dev_priv->display.update_plane(crtc, fb, x, y);
  1729. }
  1730. static int
  1731. intel_finish_fb(struct drm_framebuffer *old_fb)
  1732. {
  1733. struct drm_i915_gem_object *obj = to_intel_framebuffer(old_fb)->obj;
  1734. struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
  1735. bool was_interruptible = dev_priv->mm.interruptible;
  1736. int ret;
  1737. wait_event(dev_priv->pending_flip_queue,
  1738. atomic_read(&dev_priv->mm.wedged) ||
  1739. atomic_read(&obj->pending_flip) == 0);
  1740. /* Big Hammer, we also need to ensure that any pending
  1741. * MI_WAIT_FOR_EVENT inside a user batch buffer on the
  1742. * current scanout is retired before unpinning the old
  1743. * framebuffer.
  1744. *
  1745. * This should only fail upon a hung GPU, in which case we
  1746. * can safely continue.
  1747. */
  1748. dev_priv->mm.interruptible = false;
  1749. ret = i915_gem_object_finish_gpu(obj);
  1750. dev_priv->mm.interruptible = was_interruptible;
  1751. return ret;
  1752. }
  1753. static int
  1754. intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
  1755. struct drm_framebuffer *old_fb)
  1756. {
  1757. struct drm_device *dev = crtc->dev;
  1758. struct drm_i915_private *dev_priv = dev->dev_private;
  1759. struct drm_i915_master_private *master_priv;
  1760. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1761. int ret;
  1762. /* no fb bound */
  1763. if (!crtc->fb) {
  1764. DRM_ERROR("No FB bound\n");
  1765. return 0;
  1766. }
  1767. if(intel_crtc->plane > dev_priv->num_pipe) {
  1768. DRM_ERROR("no plane for crtc: plane %d, num_pipes %d\n",
  1769. intel_crtc->plane,
  1770. dev_priv->num_pipe);
  1771. return -EINVAL;
  1772. }
  1773. mutex_lock(&dev->struct_mutex);
  1774. ret = intel_pin_and_fence_fb_obj(dev,
  1775. to_intel_framebuffer(crtc->fb)->obj,
  1776. NULL);
  1777. if (ret != 0) {
  1778. mutex_unlock(&dev->struct_mutex);
  1779. DRM_ERROR("pin & fence failed\n");
  1780. return ret;
  1781. }
  1782. if (old_fb)
  1783. intel_finish_fb(old_fb);
  1784. ret = dev_priv->display.update_plane(crtc, crtc->fb, x, y);
  1785. if (ret) {
  1786. intel_unpin_fb_obj(to_intel_framebuffer(crtc->fb)->obj);
  1787. mutex_unlock(&dev->struct_mutex);
  1788. DRM_ERROR("failed to update base address\n");
  1789. return ret;
  1790. }
  1791. if (old_fb) {
  1792. intel_wait_for_vblank(dev, intel_crtc->pipe);
  1793. intel_unpin_fb_obj(to_intel_framebuffer(old_fb)->obj);
  1794. }
  1795. intel_update_fbc(dev);
  1796. mutex_unlock(&dev->struct_mutex);
  1797. if (!dev->primary->master)
  1798. return 0;
  1799. master_priv = dev->primary->master->driver_priv;
  1800. if (!master_priv->sarea_priv)
  1801. return 0;
  1802. if (intel_crtc->pipe) {
  1803. master_priv->sarea_priv->pipeB_x = x;
  1804. master_priv->sarea_priv->pipeB_y = y;
  1805. } else {
  1806. master_priv->sarea_priv->pipeA_x = x;
  1807. master_priv->sarea_priv->pipeA_y = y;
  1808. }
  1809. return 0;
  1810. }
  1811. static void ironlake_set_pll_edp(struct drm_crtc *crtc, int clock)
  1812. {
  1813. struct drm_device *dev = crtc->dev;
  1814. struct drm_i915_private *dev_priv = dev->dev_private;
  1815. u32 dpa_ctl;
  1816. DRM_DEBUG_KMS("eDP PLL enable for clock %d\n", clock);
  1817. dpa_ctl = I915_READ(DP_A);
  1818. dpa_ctl &= ~DP_PLL_FREQ_MASK;
  1819. if (clock < 200000) {
  1820. u32 temp;
  1821. dpa_ctl |= DP_PLL_FREQ_160MHZ;
  1822. /* workaround for 160Mhz:
  1823. 1) program 0x4600c bits 15:0 = 0x8124
  1824. 2) program 0x46010 bit 0 = 1
  1825. 3) program 0x46034 bit 24 = 1
  1826. 4) program 0x64000 bit 14 = 1
  1827. */
  1828. temp = I915_READ(0x4600c);
  1829. temp &= 0xffff0000;
  1830. I915_WRITE(0x4600c, temp | 0x8124);
  1831. temp = I915_READ(0x46010);
  1832. I915_WRITE(0x46010, temp | 1);
  1833. temp = I915_READ(0x46034);
  1834. I915_WRITE(0x46034, temp | (1 << 24));
  1835. } else {
  1836. dpa_ctl |= DP_PLL_FREQ_270MHZ;
  1837. }
  1838. I915_WRITE(DP_A, dpa_ctl);
  1839. POSTING_READ(DP_A);
  1840. udelay(500);
  1841. }
  1842. static void intel_fdi_normal_train(struct drm_crtc *crtc)
  1843. {
  1844. struct drm_device *dev = crtc->dev;
  1845. struct drm_i915_private *dev_priv = dev->dev_private;
  1846. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1847. int pipe = intel_crtc->pipe;
  1848. u32 reg, temp;
  1849. /* enable normal train */
  1850. reg = FDI_TX_CTL(pipe);
  1851. temp = I915_READ(reg);
  1852. if (IS_IVYBRIDGE(dev)) {
  1853. temp &= ~FDI_LINK_TRAIN_NONE_IVB;
  1854. temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
  1855. } else {
  1856. temp &= ~FDI_LINK_TRAIN_NONE;
  1857. temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
  1858. }
  1859. I915_WRITE(reg, temp);
  1860. reg = FDI_RX_CTL(pipe);
  1861. temp = I915_READ(reg);
  1862. if (HAS_PCH_CPT(dev)) {
  1863. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  1864. temp |= FDI_LINK_TRAIN_NORMAL_CPT;
  1865. } else {
  1866. temp &= ~FDI_LINK_TRAIN_NONE;
  1867. temp |= FDI_LINK_TRAIN_NONE;
  1868. }
  1869. I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
  1870. /* wait one idle pattern time */
  1871. POSTING_READ(reg);
  1872. udelay(1000);
  1873. /* IVB wants error correction enabled */
  1874. if (IS_IVYBRIDGE(dev))
  1875. I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
  1876. FDI_FE_ERRC_ENABLE);
  1877. }
  1878. static void cpt_phase_pointer_enable(struct drm_device *dev, int pipe)
  1879. {
  1880. struct drm_i915_private *dev_priv = dev->dev_private;
  1881. u32 flags = I915_READ(SOUTH_CHICKEN1);
  1882. flags |= FDI_PHASE_SYNC_OVR(pipe);
  1883. I915_WRITE(SOUTH_CHICKEN1, flags); /* once to unlock... */
  1884. flags |= FDI_PHASE_SYNC_EN(pipe);
  1885. I915_WRITE(SOUTH_CHICKEN1, flags); /* then again to enable */
  1886. POSTING_READ(SOUTH_CHICKEN1);
  1887. }
  1888. /* The FDI link training functions for ILK/Ibexpeak. */
  1889. static void ironlake_fdi_link_train(struct drm_crtc *crtc)
  1890. {
  1891. struct drm_device *dev = crtc->dev;
  1892. struct drm_i915_private *dev_priv = dev->dev_private;
  1893. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1894. int pipe = intel_crtc->pipe;
  1895. int plane = intel_crtc->plane;
  1896. u32 reg, temp, tries;
  1897. /* FDI needs bits from pipe & plane first */
  1898. assert_pipe_enabled(dev_priv, pipe);
  1899. assert_plane_enabled(dev_priv, plane);
  1900. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  1901. for train result */
  1902. reg = FDI_RX_IMR(pipe);
  1903. temp = I915_READ(reg);
  1904. temp &= ~FDI_RX_SYMBOL_LOCK;
  1905. temp &= ~FDI_RX_BIT_LOCK;
  1906. I915_WRITE(reg, temp);
  1907. I915_READ(reg);
  1908. udelay(150);
  1909. /* enable CPU FDI TX and PCH FDI RX */
  1910. reg = FDI_TX_CTL(pipe);
  1911. temp = I915_READ(reg);
  1912. temp &= ~(7 << 19);
  1913. temp |= (intel_crtc->fdi_lanes - 1) << 19;
  1914. temp &= ~FDI_LINK_TRAIN_NONE;
  1915. temp |= FDI_LINK_TRAIN_PATTERN_1;
  1916. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  1917. reg = FDI_RX_CTL(pipe);
  1918. temp = I915_READ(reg);
  1919. temp &= ~FDI_LINK_TRAIN_NONE;
  1920. temp |= FDI_LINK_TRAIN_PATTERN_1;
  1921. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  1922. POSTING_READ(reg);
  1923. udelay(150);
  1924. /* Ironlake workaround, enable clock pointer after FDI enable*/
  1925. if (HAS_PCH_IBX(dev)) {
  1926. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
  1927. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
  1928. FDI_RX_PHASE_SYNC_POINTER_EN);
  1929. }
  1930. reg = FDI_RX_IIR(pipe);
  1931. for (tries = 0; tries < 5; tries++) {
  1932. temp = I915_READ(reg);
  1933. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  1934. if ((temp & FDI_RX_BIT_LOCK)) {
  1935. DRM_DEBUG_KMS("FDI train 1 done.\n");
  1936. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  1937. break;
  1938. }
  1939. }
  1940. if (tries == 5)
  1941. DRM_ERROR("FDI train 1 fail!\n");
  1942. /* Train 2 */
  1943. reg = FDI_TX_CTL(pipe);
  1944. temp = I915_READ(reg);
  1945. temp &= ~FDI_LINK_TRAIN_NONE;
  1946. temp |= FDI_LINK_TRAIN_PATTERN_2;
  1947. I915_WRITE(reg, temp);
  1948. reg = FDI_RX_CTL(pipe);
  1949. temp = I915_READ(reg);
  1950. temp &= ~FDI_LINK_TRAIN_NONE;
  1951. temp |= FDI_LINK_TRAIN_PATTERN_2;
  1952. I915_WRITE(reg, temp);
  1953. POSTING_READ(reg);
  1954. udelay(150);
  1955. reg = FDI_RX_IIR(pipe);
  1956. for (tries = 0; tries < 5; tries++) {
  1957. temp = I915_READ(reg);
  1958. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  1959. if (temp & FDI_RX_SYMBOL_LOCK) {
  1960. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  1961. DRM_DEBUG_KMS("FDI train 2 done.\n");
  1962. break;
  1963. }
  1964. }
  1965. if (tries == 5)
  1966. DRM_ERROR("FDI train 2 fail!\n");
  1967. DRM_DEBUG_KMS("FDI train done\n");
  1968. }
  1969. static const int snb_b_fdi_train_param[] = {
  1970. FDI_LINK_TRAIN_400MV_0DB_SNB_B,
  1971. FDI_LINK_TRAIN_400MV_6DB_SNB_B,
  1972. FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
  1973. FDI_LINK_TRAIN_800MV_0DB_SNB_B,
  1974. };
  1975. /* The FDI link training functions for SNB/Cougarpoint. */
  1976. static void gen6_fdi_link_train(struct drm_crtc *crtc)
  1977. {
  1978. struct drm_device *dev = crtc->dev;
  1979. struct drm_i915_private *dev_priv = dev->dev_private;
  1980. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1981. int pipe = intel_crtc->pipe;
  1982. u32 reg, temp, i, retry;
  1983. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  1984. for train result */
  1985. reg = FDI_RX_IMR(pipe);
  1986. temp = I915_READ(reg);
  1987. temp &= ~FDI_RX_SYMBOL_LOCK;
  1988. temp &= ~FDI_RX_BIT_LOCK;
  1989. I915_WRITE(reg, temp);
  1990. POSTING_READ(reg);
  1991. udelay(150);
  1992. /* enable CPU FDI TX and PCH FDI RX */
  1993. reg = FDI_TX_CTL(pipe);
  1994. temp = I915_READ(reg);
  1995. temp &= ~(7 << 19);
  1996. temp |= (intel_crtc->fdi_lanes - 1) << 19;
  1997. temp &= ~FDI_LINK_TRAIN_NONE;
  1998. temp |= FDI_LINK_TRAIN_PATTERN_1;
  1999. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2000. /* SNB-B */
  2001. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2002. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2003. reg = FDI_RX_CTL(pipe);
  2004. temp = I915_READ(reg);
  2005. if (HAS_PCH_CPT(dev)) {
  2006. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2007. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2008. } else {
  2009. temp &= ~FDI_LINK_TRAIN_NONE;
  2010. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2011. }
  2012. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2013. POSTING_READ(reg);
  2014. udelay(150);
  2015. if (HAS_PCH_CPT(dev))
  2016. cpt_phase_pointer_enable(dev, pipe);
  2017. for (i = 0; i < 4; i++) {
  2018. reg = FDI_TX_CTL(pipe);
  2019. temp = I915_READ(reg);
  2020. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2021. temp |= snb_b_fdi_train_param[i];
  2022. I915_WRITE(reg, temp);
  2023. POSTING_READ(reg);
  2024. udelay(500);
  2025. for (retry = 0; retry < 5; retry++) {
  2026. reg = FDI_RX_IIR(pipe);
  2027. temp = I915_READ(reg);
  2028. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2029. if (temp & FDI_RX_BIT_LOCK) {
  2030. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2031. DRM_DEBUG_KMS("FDI train 1 done.\n");
  2032. break;
  2033. }
  2034. udelay(50);
  2035. }
  2036. if (retry < 5)
  2037. break;
  2038. }
  2039. if (i == 4)
  2040. DRM_ERROR("FDI train 1 fail!\n");
  2041. /* Train 2 */
  2042. reg = FDI_TX_CTL(pipe);
  2043. temp = I915_READ(reg);
  2044. temp &= ~FDI_LINK_TRAIN_NONE;
  2045. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2046. if (IS_GEN6(dev)) {
  2047. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2048. /* SNB-B */
  2049. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2050. }
  2051. I915_WRITE(reg, temp);
  2052. reg = FDI_RX_CTL(pipe);
  2053. temp = I915_READ(reg);
  2054. if (HAS_PCH_CPT(dev)) {
  2055. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2056. temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
  2057. } else {
  2058. temp &= ~FDI_LINK_TRAIN_NONE;
  2059. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2060. }
  2061. I915_WRITE(reg, temp);
  2062. POSTING_READ(reg);
  2063. udelay(150);
  2064. for (i = 0; i < 4; i++) {
  2065. reg = FDI_TX_CTL(pipe);
  2066. temp = I915_READ(reg);
  2067. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2068. temp |= snb_b_fdi_train_param[i];
  2069. I915_WRITE(reg, temp);
  2070. POSTING_READ(reg);
  2071. udelay(500);
  2072. for (retry = 0; retry < 5; retry++) {
  2073. reg = FDI_RX_IIR(pipe);
  2074. temp = I915_READ(reg);
  2075. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2076. if (temp & FDI_RX_SYMBOL_LOCK) {
  2077. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2078. DRM_DEBUG_KMS("FDI train 2 done.\n");
  2079. break;
  2080. }
  2081. udelay(50);
  2082. }
  2083. if (retry < 5)
  2084. break;
  2085. }
  2086. if (i == 4)
  2087. DRM_ERROR("FDI train 2 fail!\n");
  2088. DRM_DEBUG_KMS("FDI train done.\n");
  2089. }
  2090. /* Manual link training for Ivy Bridge A0 parts */
  2091. static void ivb_manual_fdi_link_train(struct drm_crtc *crtc)
  2092. {
  2093. struct drm_device *dev = crtc->dev;
  2094. struct drm_i915_private *dev_priv = dev->dev_private;
  2095. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2096. int pipe = intel_crtc->pipe;
  2097. u32 reg, temp, i;
  2098. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2099. for train result */
  2100. reg = FDI_RX_IMR(pipe);
  2101. temp = I915_READ(reg);
  2102. temp &= ~FDI_RX_SYMBOL_LOCK;
  2103. temp &= ~FDI_RX_BIT_LOCK;
  2104. I915_WRITE(reg, temp);
  2105. POSTING_READ(reg);
  2106. udelay(150);
  2107. /* enable CPU FDI TX and PCH FDI RX */
  2108. reg = FDI_TX_CTL(pipe);
  2109. temp = I915_READ(reg);
  2110. temp &= ~(7 << 19);
  2111. temp |= (intel_crtc->fdi_lanes - 1) << 19;
  2112. temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
  2113. temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
  2114. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2115. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2116. temp |= FDI_COMPOSITE_SYNC;
  2117. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2118. reg = FDI_RX_CTL(pipe);
  2119. temp = I915_READ(reg);
  2120. temp &= ~FDI_LINK_TRAIN_AUTO;
  2121. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2122. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2123. temp |= FDI_COMPOSITE_SYNC;
  2124. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2125. POSTING_READ(reg);
  2126. udelay(150);
  2127. if (HAS_PCH_CPT(dev))
  2128. cpt_phase_pointer_enable(dev, pipe);
  2129. for (i = 0; i < 4; i++) {
  2130. reg = FDI_TX_CTL(pipe);
  2131. temp = I915_READ(reg);
  2132. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2133. temp |= snb_b_fdi_train_param[i];
  2134. I915_WRITE(reg, temp);
  2135. POSTING_READ(reg);
  2136. udelay(500);
  2137. reg = FDI_RX_IIR(pipe);
  2138. temp = I915_READ(reg);
  2139. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2140. if (temp & FDI_RX_BIT_LOCK ||
  2141. (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
  2142. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2143. DRM_DEBUG_KMS("FDI train 1 done.\n");
  2144. break;
  2145. }
  2146. }
  2147. if (i == 4)
  2148. DRM_ERROR("FDI train 1 fail!\n");
  2149. /* Train 2 */
  2150. reg = FDI_TX_CTL(pipe);
  2151. temp = I915_READ(reg);
  2152. temp &= ~FDI_LINK_TRAIN_NONE_IVB;
  2153. temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
  2154. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2155. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2156. I915_WRITE(reg, temp);
  2157. reg = FDI_RX_CTL(pipe);
  2158. temp = I915_READ(reg);
  2159. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2160. temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
  2161. I915_WRITE(reg, temp);
  2162. POSTING_READ(reg);
  2163. udelay(150);
  2164. for (i = 0; i < 4; i++) {
  2165. reg = FDI_TX_CTL(pipe);
  2166. temp = I915_READ(reg);
  2167. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2168. temp |= snb_b_fdi_train_param[i];
  2169. I915_WRITE(reg, temp);
  2170. POSTING_READ(reg);
  2171. udelay(500);
  2172. reg = FDI_RX_IIR(pipe);
  2173. temp = I915_READ(reg);
  2174. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2175. if (temp & FDI_RX_SYMBOL_LOCK) {
  2176. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2177. DRM_DEBUG_KMS("FDI train 2 done.\n");
  2178. break;
  2179. }
  2180. }
  2181. if (i == 4)
  2182. DRM_ERROR("FDI train 2 fail!\n");
  2183. DRM_DEBUG_KMS("FDI train done.\n");
  2184. }
  2185. static void ironlake_fdi_pll_enable(struct drm_crtc *crtc)
  2186. {
  2187. struct drm_device *dev = crtc->dev;
  2188. struct drm_i915_private *dev_priv = dev->dev_private;
  2189. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2190. int pipe = intel_crtc->pipe;
  2191. u32 reg, temp;
  2192. /* Write the TU size bits so error detection works */
  2193. I915_WRITE(FDI_RX_TUSIZE1(pipe),
  2194. I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
  2195. /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
  2196. reg = FDI_RX_CTL(pipe);
  2197. temp = I915_READ(reg);
  2198. temp &= ~((0x7 << 19) | (0x7 << 16));
  2199. temp |= (intel_crtc->fdi_lanes - 1) << 19;
  2200. temp |= (I915_READ(PIPECONF(pipe)) & PIPE_BPC_MASK) << 11;
  2201. I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
  2202. POSTING_READ(reg);
  2203. udelay(200);
  2204. /* Switch from Rawclk to PCDclk */
  2205. temp = I915_READ(reg);
  2206. I915_WRITE(reg, temp | FDI_PCDCLK);
  2207. POSTING_READ(reg);
  2208. udelay(200);
  2209. /* On Haswell, the PLL configuration for ports and pipes is handled
  2210. * separately, as part of DDI setup */
  2211. if (!IS_HASWELL(dev)) {
  2212. /* Enable CPU FDI TX PLL, always on for Ironlake */
  2213. reg = FDI_TX_CTL(pipe);
  2214. temp = I915_READ(reg);
  2215. if ((temp & FDI_TX_PLL_ENABLE) == 0) {
  2216. I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
  2217. POSTING_READ(reg);
  2218. udelay(100);
  2219. }
  2220. }
  2221. }
  2222. static void cpt_phase_pointer_disable(struct drm_device *dev, int pipe)
  2223. {
  2224. struct drm_i915_private *dev_priv = dev->dev_private;
  2225. u32 flags = I915_READ(SOUTH_CHICKEN1);
  2226. flags &= ~(FDI_PHASE_SYNC_EN(pipe));
  2227. I915_WRITE(SOUTH_CHICKEN1, flags); /* once to disable... */
  2228. flags &= ~(FDI_PHASE_SYNC_OVR(pipe));
  2229. I915_WRITE(SOUTH_CHICKEN1, flags); /* then again to lock */
  2230. POSTING_READ(SOUTH_CHICKEN1);
  2231. }
  2232. static void ironlake_fdi_disable(struct drm_crtc *crtc)
  2233. {
  2234. struct drm_device *dev = crtc->dev;
  2235. struct drm_i915_private *dev_priv = dev->dev_private;
  2236. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2237. int pipe = intel_crtc->pipe;
  2238. u32 reg, temp;
  2239. /* disable CPU FDI tx and PCH FDI rx */
  2240. reg = FDI_TX_CTL(pipe);
  2241. temp = I915_READ(reg);
  2242. I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
  2243. POSTING_READ(reg);
  2244. reg = FDI_RX_CTL(pipe);
  2245. temp = I915_READ(reg);
  2246. temp &= ~(0x7 << 16);
  2247. temp |= (I915_READ(PIPECONF(pipe)) & PIPE_BPC_MASK) << 11;
  2248. I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
  2249. POSTING_READ(reg);
  2250. udelay(100);
  2251. /* Ironlake workaround, disable clock pointer after downing FDI */
  2252. if (HAS_PCH_IBX(dev)) {
  2253. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
  2254. I915_WRITE(FDI_RX_CHICKEN(pipe),
  2255. I915_READ(FDI_RX_CHICKEN(pipe) &
  2256. ~FDI_RX_PHASE_SYNC_POINTER_EN));
  2257. } else if (HAS_PCH_CPT(dev)) {
  2258. cpt_phase_pointer_disable(dev, pipe);
  2259. }
  2260. /* still set train pattern 1 */
  2261. reg = FDI_TX_CTL(pipe);
  2262. temp = I915_READ(reg);
  2263. temp &= ~FDI_LINK_TRAIN_NONE;
  2264. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2265. I915_WRITE(reg, temp);
  2266. reg = FDI_RX_CTL(pipe);
  2267. temp = I915_READ(reg);
  2268. if (HAS_PCH_CPT(dev)) {
  2269. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2270. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2271. } else {
  2272. temp &= ~FDI_LINK_TRAIN_NONE;
  2273. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2274. }
  2275. /* BPC in FDI rx is consistent with that in PIPECONF */
  2276. temp &= ~(0x07 << 16);
  2277. temp |= (I915_READ(PIPECONF(pipe)) & PIPE_BPC_MASK) << 11;
  2278. I915_WRITE(reg, temp);
  2279. POSTING_READ(reg);
  2280. udelay(100);
  2281. }
  2282. static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
  2283. {
  2284. struct drm_device *dev = crtc->dev;
  2285. if (crtc->fb == NULL)
  2286. return;
  2287. mutex_lock(&dev->struct_mutex);
  2288. intel_finish_fb(crtc->fb);
  2289. mutex_unlock(&dev->struct_mutex);
  2290. }
  2291. static bool intel_crtc_driving_pch(struct drm_crtc *crtc)
  2292. {
  2293. struct drm_device *dev = crtc->dev;
  2294. struct drm_mode_config *mode_config = &dev->mode_config;
  2295. struct intel_encoder *encoder;
  2296. /*
  2297. * If there's a non-PCH eDP on this crtc, it must be DP_A, and that
  2298. * must be driven by its own crtc; no sharing is possible.
  2299. */
  2300. list_for_each_entry(encoder, &mode_config->encoder_list, base.head) {
  2301. if (encoder->base.crtc != crtc)
  2302. continue;
  2303. /* On Haswell, LPT PCH handles the VGA connection via FDI, and Haswell
  2304. * CPU handles all others */
  2305. if (IS_HASWELL(dev)) {
  2306. /* It is still unclear how this will work on PPT, so throw up a warning */
  2307. WARN_ON(!HAS_PCH_LPT(dev));
  2308. if (encoder->type == DRM_MODE_ENCODER_DAC) {
  2309. DRM_DEBUG_KMS("Haswell detected DAC encoder, assuming is PCH\n");
  2310. return true;
  2311. } else {
  2312. DRM_DEBUG_KMS("Haswell detected encoder %d, assuming is CPU\n",
  2313. encoder->type);
  2314. return false;
  2315. }
  2316. }
  2317. switch (encoder->type) {
  2318. case INTEL_OUTPUT_EDP:
  2319. if (!intel_encoder_is_pch_edp(&encoder->base))
  2320. return false;
  2321. continue;
  2322. }
  2323. }
  2324. return true;
  2325. }
  2326. /*
  2327. * Enable PCH resources required for PCH ports:
  2328. * - PCH PLLs
  2329. * - FDI training & RX/TX
  2330. * - update transcoder timings
  2331. * - DP transcoding bits
  2332. * - transcoder
  2333. */
  2334. static void ironlake_pch_enable(struct drm_crtc *crtc)
  2335. {
  2336. struct drm_device *dev = crtc->dev;
  2337. struct drm_i915_private *dev_priv = dev->dev_private;
  2338. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2339. int pipe = intel_crtc->pipe;
  2340. u32 reg, temp;
  2341. /* For PCH output, training FDI link */
  2342. dev_priv->display.fdi_link_train(crtc);
  2343. intel_enable_pch_pll(intel_crtc);
  2344. if (HAS_PCH_CPT(dev)) {
  2345. u32 sel;
  2346. temp = I915_READ(PCH_DPLL_SEL);
  2347. switch (pipe) {
  2348. default:
  2349. case 0:
  2350. temp |= TRANSA_DPLL_ENABLE;
  2351. sel = TRANSA_DPLLB_SEL;
  2352. break;
  2353. case 1:
  2354. temp |= TRANSB_DPLL_ENABLE;
  2355. sel = TRANSB_DPLLB_SEL;
  2356. break;
  2357. case 2:
  2358. temp |= TRANSC_DPLL_ENABLE;
  2359. sel = TRANSC_DPLLB_SEL;
  2360. break;
  2361. }
  2362. if (intel_crtc->pch_pll->pll_reg == _PCH_DPLL_B)
  2363. temp |= sel;
  2364. else
  2365. temp &= ~sel;
  2366. I915_WRITE(PCH_DPLL_SEL, temp);
  2367. }
  2368. /* set transcoder timing, panel must allow it */
  2369. assert_panel_unlocked(dev_priv, pipe);
  2370. I915_WRITE(TRANS_HTOTAL(pipe), I915_READ(HTOTAL(pipe)));
  2371. I915_WRITE(TRANS_HBLANK(pipe), I915_READ(HBLANK(pipe)));
  2372. I915_WRITE(TRANS_HSYNC(pipe), I915_READ(HSYNC(pipe)));
  2373. I915_WRITE(TRANS_VTOTAL(pipe), I915_READ(VTOTAL(pipe)));
  2374. I915_WRITE(TRANS_VBLANK(pipe), I915_READ(VBLANK(pipe)));
  2375. I915_WRITE(TRANS_VSYNC(pipe), I915_READ(VSYNC(pipe)));
  2376. I915_WRITE(TRANS_VSYNCSHIFT(pipe), I915_READ(VSYNCSHIFT(pipe)));
  2377. if (!IS_HASWELL(dev))
  2378. intel_fdi_normal_train(crtc);
  2379. /* For PCH DP, enable TRANS_DP_CTL */
  2380. if (HAS_PCH_CPT(dev) &&
  2381. (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) ||
  2382. intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) {
  2383. u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPE_BPC_MASK) >> 5;
  2384. reg = TRANS_DP_CTL(pipe);
  2385. temp = I915_READ(reg);
  2386. temp &= ~(TRANS_DP_PORT_SEL_MASK |
  2387. TRANS_DP_SYNC_MASK |
  2388. TRANS_DP_BPC_MASK);
  2389. temp |= (TRANS_DP_OUTPUT_ENABLE |
  2390. TRANS_DP_ENH_FRAMING);
  2391. temp |= bpc << 9; /* same format but at 11:9 */
  2392. if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC)
  2393. temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
  2394. if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC)
  2395. temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
  2396. switch (intel_trans_dp_port_sel(crtc)) {
  2397. case PCH_DP_B:
  2398. temp |= TRANS_DP_PORT_SEL_B;
  2399. break;
  2400. case PCH_DP_C:
  2401. temp |= TRANS_DP_PORT_SEL_C;
  2402. break;
  2403. case PCH_DP_D:
  2404. temp |= TRANS_DP_PORT_SEL_D;
  2405. break;
  2406. default:
  2407. DRM_DEBUG_KMS("Wrong PCH DP port return. Guess port B\n");
  2408. temp |= TRANS_DP_PORT_SEL_B;
  2409. break;
  2410. }
  2411. I915_WRITE(reg, temp);
  2412. }
  2413. intel_enable_transcoder(dev_priv, pipe);
  2414. }
  2415. static void intel_put_pch_pll(struct intel_crtc *intel_crtc)
  2416. {
  2417. struct intel_pch_pll *pll = intel_crtc->pch_pll;
  2418. if (pll == NULL)
  2419. return;
  2420. if (pll->refcount == 0) {
  2421. WARN(1, "bad PCH PLL refcount\n");
  2422. return;
  2423. }
  2424. --pll->refcount;
  2425. intel_crtc->pch_pll = NULL;
  2426. }
  2427. static struct intel_pch_pll *intel_get_pch_pll(struct intel_crtc *intel_crtc, u32 dpll, u32 fp)
  2428. {
  2429. struct drm_i915_private *dev_priv = intel_crtc->base.dev->dev_private;
  2430. struct intel_pch_pll *pll;
  2431. int i;
  2432. pll = intel_crtc->pch_pll;
  2433. if (pll) {
  2434. DRM_DEBUG_KMS("CRTC:%d reusing existing PCH PLL %x\n",
  2435. intel_crtc->base.base.id, pll->pll_reg);
  2436. goto prepare;
  2437. }
  2438. for (i = 0; i < dev_priv->num_pch_pll; i++) {
  2439. pll = &dev_priv->pch_plls[i];
  2440. /* Only want to check enabled timings first */
  2441. if (pll->refcount == 0)
  2442. continue;
  2443. if (dpll == (I915_READ(pll->pll_reg) & 0x7fffffff) &&
  2444. fp == I915_READ(pll->fp0_reg)) {
  2445. DRM_DEBUG_KMS("CRTC:%d sharing existing PCH PLL %x (refcount %d, ative %d)\n",
  2446. intel_crtc->base.base.id,
  2447. pll->pll_reg, pll->refcount, pll->active);
  2448. goto found;
  2449. }
  2450. }
  2451. /* Ok no matching timings, maybe there's a free one? */
  2452. for (i = 0; i < dev_priv->num_pch_pll; i++) {
  2453. pll = &dev_priv->pch_plls[i];
  2454. if (pll->refcount == 0) {
  2455. DRM_DEBUG_KMS("CRTC:%d allocated PCH PLL %x\n",
  2456. intel_crtc->base.base.id, pll->pll_reg);
  2457. goto found;
  2458. }
  2459. }
  2460. return NULL;
  2461. found:
  2462. intel_crtc->pch_pll = pll;
  2463. pll->refcount++;
  2464. DRM_DEBUG_DRIVER("using pll %d for pipe %d\n", i, intel_crtc->pipe);
  2465. prepare: /* separate function? */
  2466. DRM_DEBUG_DRIVER("switching PLL %x off\n", pll->pll_reg);
  2467. /* Wait for the clocks to stabilize before rewriting the regs */
  2468. I915_WRITE(pll->pll_reg, dpll & ~DPLL_VCO_ENABLE);
  2469. POSTING_READ(pll->pll_reg);
  2470. udelay(150);
  2471. I915_WRITE(pll->fp0_reg, fp);
  2472. I915_WRITE(pll->pll_reg, dpll & ~DPLL_VCO_ENABLE);
  2473. pll->on = false;
  2474. return pll;
  2475. }
  2476. void intel_cpt_verify_modeset(struct drm_device *dev, int pipe)
  2477. {
  2478. struct drm_i915_private *dev_priv = dev->dev_private;
  2479. int dslreg = PIPEDSL(pipe), tc2reg = TRANS_CHICKEN2(pipe);
  2480. u32 temp;
  2481. temp = I915_READ(dslreg);
  2482. udelay(500);
  2483. if (wait_for(I915_READ(dslreg) != temp, 5)) {
  2484. /* Without this, mode sets may fail silently on FDI */
  2485. I915_WRITE(tc2reg, TRANS_AUTOTRAIN_GEN_STALL_DIS);
  2486. udelay(250);
  2487. I915_WRITE(tc2reg, 0);
  2488. if (wait_for(I915_READ(dslreg) != temp, 5))
  2489. DRM_ERROR("mode set failed: pipe %d stuck\n", pipe);
  2490. }
  2491. }
  2492. static void ironlake_crtc_enable(struct drm_crtc *crtc)
  2493. {
  2494. struct drm_device *dev = crtc->dev;
  2495. struct drm_i915_private *dev_priv = dev->dev_private;
  2496. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2497. int pipe = intel_crtc->pipe;
  2498. int plane = intel_crtc->plane;
  2499. u32 temp;
  2500. bool is_pch_port;
  2501. if (intel_crtc->active)
  2502. return;
  2503. intel_crtc->active = true;
  2504. intel_update_watermarks(dev);
  2505. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  2506. temp = I915_READ(PCH_LVDS);
  2507. if ((temp & LVDS_PORT_EN) == 0)
  2508. I915_WRITE(PCH_LVDS, temp | LVDS_PORT_EN);
  2509. }
  2510. is_pch_port = intel_crtc_driving_pch(crtc);
  2511. if (is_pch_port)
  2512. ironlake_fdi_pll_enable(crtc);
  2513. else
  2514. ironlake_fdi_disable(crtc);
  2515. /* Enable panel fitting for LVDS */
  2516. if (dev_priv->pch_pf_size &&
  2517. (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) || HAS_eDP)) {
  2518. /* Force use of hard-coded filter coefficients
  2519. * as some pre-programmed values are broken,
  2520. * e.g. x201.
  2521. */
  2522. I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
  2523. I915_WRITE(PF_WIN_POS(pipe), dev_priv->pch_pf_pos);
  2524. I915_WRITE(PF_WIN_SZ(pipe), dev_priv->pch_pf_size);
  2525. }
  2526. /*
  2527. * On ILK+ LUT must be loaded before the pipe is running but with
  2528. * clocks enabled
  2529. */
  2530. intel_crtc_load_lut(crtc);
  2531. intel_enable_pipe(dev_priv, pipe, is_pch_port);
  2532. intel_enable_plane(dev_priv, plane, pipe);
  2533. if (is_pch_port)
  2534. ironlake_pch_enable(crtc);
  2535. mutex_lock(&dev->struct_mutex);
  2536. intel_update_fbc(dev);
  2537. mutex_unlock(&dev->struct_mutex);
  2538. intel_crtc_update_cursor(crtc, true);
  2539. }
  2540. static void ironlake_crtc_disable(struct drm_crtc *crtc)
  2541. {
  2542. struct drm_device *dev = crtc->dev;
  2543. struct drm_i915_private *dev_priv = dev->dev_private;
  2544. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2545. int pipe = intel_crtc->pipe;
  2546. int plane = intel_crtc->plane;
  2547. u32 reg, temp;
  2548. if (!intel_crtc->active)
  2549. return;
  2550. intel_crtc_wait_for_pending_flips(crtc);
  2551. drm_vblank_off(dev, pipe);
  2552. intel_crtc_update_cursor(crtc, false);
  2553. intel_disable_plane(dev_priv, plane, pipe);
  2554. if (dev_priv->cfb_plane == plane)
  2555. intel_disable_fbc(dev);
  2556. intel_disable_pipe(dev_priv, pipe);
  2557. /* Disable PF */
  2558. I915_WRITE(PF_CTL(pipe), 0);
  2559. I915_WRITE(PF_WIN_SZ(pipe), 0);
  2560. ironlake_fdi_disable(crtc);
  2561. /* This is a horrible layering violation; we should be doing this in
  2562. * the connector/encoder ->prepare instead, but we don't always have
  2563. * enough information there about the config to know whether it will
  2564. * actually be necessary or just cause undesired flicker.
  2565. */
  2566. intel_disable_pch_ports(dev_priv, pipe);
  2567. intel_disable_transcoder(dev_priv, pipe);
  2568. if (HAS_PCH_CPT(dev)) {
  2569. /* disable TRANS_DP_CTL */
  2570. reg = TRANS_DP_CTL(pipe);
  2571. temp = I915_READ(reg);
  2572. temp &= ~(TRANS_DP_OUTPUT_ENABLE | TRANS_DP_PORT_SEL_MASK);
  2573. temp |= TRANS_DP_PORT_SEL_NONE;
  2574. I915_WRITE(reg, temp);
  2575. /* disable DPLL_SEL */
  2576. temp = I915_READ(PCH_DPLL_SEL);
  2577. switch (pipe) {
  2578. case 0:
  2579. temp &= ~(TRANSA_DPLL_ENABLE | TRANSA_DPLLB_SEL);
  2580. break;
  2581. case 1:
  2582. temp &= ~(TRANSB_DPLL_ENABLE | TRANSB_DPLLB_SEL);
  2583. break;
  2584. case 2:
  2585. /* C shares PLL A or B */
  2586. temp &= ~(TRANSC_DPLL_ENABLE | TRANSC_DPLLB_SEL);
  2587. break;
  2588. default:
  2589. BUG(); /* wtf */
  2590. }
  2591. I915_WRITE(PCH_DPLL_SEL, temp);
  2592. }
  2593. /* disable PCH DPLL */
  2594. intel_disable_pch_pll(intel_crtc);
  2595. /* Switch from PCDclk to Rawclk */
  2596. reg = FDI_RX_CTL(pipe);
  2597. temp = I915_READ(reg);
  2598. I915_WRITE(reg, temp & ~FDI_PCDCLK);
  2599. /* Disable CPU FDI TX PLL */
  2600. reg = FDI_TX_CTL(pipe);
  2601. temp = I915_READ(reg);
  2602. I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
  2603. POSTING_READ(reg);
  2604. udelay(100);
  2605. reg = FDI_RX_CTL(pipe);
  2606. temp = I915_READ(reg);
  2607. I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
  2608. /* Wait for the clocks to turn off. */
  2609. POSTING_READ(reg);
  2610. udelay(100);
  2611. intel_crtc->active = false;
  2612. intel_update_watermarks(dev);
  2613. mutex_lock(&dev->struct_mutex);
  2614. intel_update_fbc(dev);
  2615. mutex_unlock(&dev->struct_mutex);
  2616. }
  2617. static void ironlake_crtc_dpms(struct drm_crtc *crtc, int mode)
  2618. {
  2619. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2620. int pipe = intel_crtc->pipe;
  2621. int plane = intel_crtc->plane;
  2622. /* XXX: When our outputs are all unaware of DPMS modes other than off
  2623. * and on, we should map those modes to DRM_MODE_DPMS_OFF in the CRTC.
  2624. */
  2625. switch (mode) {
  2626. case DRM_MODE_DPMS_ON:
  2627. case DRM_MODE_DPMS_STANDBY:
  2628. case DRM_MODE_DPMS_SUSPEND:
  2629. DRM_DEBUG_KMS("crtc %d/%d dpms on\n", pipe, plane);
  2630. ironlake_crtc_enable(crtc);
  2631. break;
  2632. case DRM_MODE_DPMS_OFF:
  2633. DRM_DEBUG_KMS("crtc %d/%d dpms off\n", pipe, plane);
  2634. ironlake_crtc_disable(crtc);
  2635. break;
  2636. }
  2637. }
  2638. static void ironlake_crtc_off(struct drm_crtc *crtc)
  2639. {
  2640. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2641. intel_put_pch_pll(intel_crtc);
  2642. }
  2643. static void intel_crtc_dpms_overlay(struct intel_crtc *intel_crtc, bool enable)
  2644. {
  2645. if (!enable && intel_crtc->overlay) {
  2646. struct drm_device *dev = intel_crtc->base.dev;
  2647. struct drm_i915_private *dev_priv = dev->dev_private;
  2648. mutex_lock(&dev->struct_mutex);
  2649. dev_priv->mm.interruptible = false;
  2650. (void) intel_overlay_switch_off(intel_crtc->overlay);
  2651. dev_priv->mm.interruptible = true;
  2652. mutex_unlock(&dev->struct_mutex);
  2653. }
  2654. /* Let userspace switch the overlay on again. In most cases userspace
  2655. * has to recompute where to put it anyway.
  2656. */
  2657. }
  2658. static void i9xx_crtc_enable(struct drm_crtc *crtc)
  2659. {
  2660. struct drm_device *dev = crtc->dev;
  2661. struct drm_i915_private *dev_priv = dev->dev_private;
  2662. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2663. int pipe = intel_crtc->pipe;
  2664. int plane = intel_crtc->plane;
  2665. if (intel_crtc->active)
  2666. return;
  2667. intel_crtc->active = true;
  2668. intel_update_watermarks(dev);
  2669. intel_enable_pll(dev_priv, pipe);
  2670. intel_enable_pipe(dev_priv, pipe, false);
  2671. intel_enable_plane(dev_priv, plane, pipe);
  2672. intel_crtc_load_lut(crtc);
  2673. intel_update_fbc(dev);
  2674. /* Give the overlay scaler a chance to enable if it's on this pipe */
  2675. intel_crtc_dpms_overlay(intel_crtc, true);
  2676. intel_crtc_update_cursor(crtc, true);
  2677. }
  2678. static void i9xx_crtc_disable(struct drm_crtc *crtc)
  2679. {
  2680. struct drm_device *dev = crtc->dev;
  2681. struct drm_i915_private *dev_priv = dev->dev_private;
  2682. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2683. int pipe = intel_crtc->pipe;
  2684. int plane = intel_crtc->plane;
  2685. if (!intel_crtc->active)
  2686. return;
  2687. /* Give the overlay scaler a chance to disable if it's on this pipe */
  2688. intel_crtc_wait_for_pending_flips(crtc);
  2689. drm_vblank_off(dev, pipe);
  2690. intel_crtc_dpms_overlay(intel_crtc, false);
  2691. intel_crtc_update_cursor(crtc, false);
  2692. if (dev_priv->cfb_plane == plane)
  2693. intel_disable_fbc(dev);
  2694. intel_disable_plane(dev_priv, plane, pipe);
  2695. intel_disable_pipe(dev_priv, pipe);
  2696. intel_disable_pll(dev_priv, pipe);
  2697. intel_crtc->active = false;
  2698. intel_update_fbc(dev);
  2699. intel_update_watermarks(dev);
  2700. }
  2701. static void i9xx_crtc_dpms(struct drm_crtc *crtc, int mode)
  2702. {
  2703. /* XXX: When our outputs are all unaware of DPMS modes other than off
  2704. * and on, we should map those modes to DRM_MODE_DPMS_OFF in the CRTC.
  2705. */
  2706. switch (mode) {
  2707. case DRM_MODE_DPMS_ON:
  2708. case DRM_MODE_DPMS_STANDBY:
  2709. case DRM_MODE_DPMS_SUSPEND:
  2710. i9xx_crtc_enable(crtc);
  2711. break;
  2712. case DRM_MODE_DPMS_OFF:
  2713. i9xx_crtc_disable(crtc);
  2714. break;
  2715. }
  2716. }
  2717. static void i9xx_crtc_off(struct drm_crtc *crtc)
  2718. {
  2719. }
  2720. /**
  2721. * Sets the power management mode of the pipe and plane.
  2722. */
  2723. static void intel_crtc_dpms(struct drm_crtc *crtc, int mode)
  2724. {
  2725. struct drm_device *dev = crtc->dev;
  2726. struct drm_i915_private *dev_priv = dev->dev_private;
  2727. struct drm_i915_master_private *master_priv;
  2728. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2729. int pipe = intel_crtc->pipe;
  2730. bool enabled;
  2731. if (intel_crtc->dpms_mode == mode)
  2732. return;
  2733. intel_crtc->dpms_mode = mode;
  2734. dev_priv->display.dpms(crtc, mode);
  2735. if (!dev->primary->master)
  2736. return;
  2737. master_priv = dev->primary->master->driver_priv;
  2738. if (!master_priv->sarea_priv)
  2739. return;
  2740. enabled = crtc->enabled && mode != DRM_MODE_DPMS_OFF;
  2741. switch (pipe) {
  2742. case 0:
  2743. master_priv->sarea_priv->pipeA_w = enabled ? crtc->mode.hdisplay : 0;
  2744. master_priv->sarea_priv->pipeA_h = enabled ? crtc->mode.vdisplay : 0;
  2745. break;
  2746. case 1:
  2747. master_priv->sarea_priv->pipeB_w = enabled ? crtc->mode.hdisplay : 0;
  2748. master_priv->sarea_priv->pipeB_h = enabled ? crtc->mode.vdisplay : 0;
  2749. break;
  2750. default:
  2751. DRM_ERROR("Can't update pipe %c in SAREA\n", pipe_name(pipe));
  2752. break;
  2753. }
  2754. }
  2755. static void intel_crtc_disable(struct drm_crtc *crtc)
  2756. {
  2757. struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
  2758. struct drm_device *dev = crtc->dev;
  2759. struct drm_i915_private *dev_priv = dev->dev_private;
  2760. crtc_funcs->dpms(crtc, DRM_MODE_DPMS_OFF);
  2761. dev_priv->display.off(crtc);
  2762. assert_plane_disabled(dev->dev_private, to_intel_crtc(crtc)->plane);
  2763. assert_pipe_disabled(dev->dev_private, to_intel_crtc(crtc)->pipe);
  2764. if (crtc->fb) {
  2765. mutex_lock(&dev->struct_mutex);
  2766. intel_unpin_fb_obj(to_intel_framebuffer(crtc->fb)->obj);
  2767. mutex_unlock(&dev->struct_mutex);
  2768. }
  2769. }
  2770. /* Prepare for a mode set.
  2771. *
  2772. * Note we could be a lot smarter here. We need to figure out which outputs
  2773. * will be enabled, which disabled (in short, how the config will changes)
  2774. * and perform the minimum necessary steps to accomplish that, e.g. updating
  2775. * watermarks, FBC configuration, making sure PLLs are programmed correctly,
  2776. * panel fitting is in the proper state, etc.
  2777. */
  2778. static void i9xx_crtc_prepare(struct drm_crtc *crtc)
  2779. {
  2780. i9xx_crtc_disable(crtc);
  2781. }
  2782. static void i9xx_crtc_commit(struct drm_crtc *crtc)
  2783. {
  2784. i9xx_crtc_enable(crtc);
  2785. }
  2786. static void ironlake_crtc_prepare(struct drm_crtc *crtc)
  2787. {
  2788. ironlake_crtc_disable(crtc);
  2789. }
  2790. static void ironlake_crtc_commit(struct drm_crtc *crtc)
  2791. {
  2792. ironlake_crtc_enable(crtc);
  2793. }
  2794. void intel_encoder_prepare(struct drm_encoder *encoder)
  2795. {
  2796. struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
  2797. /* lvds has its own version of prepare see intel_lvds_prepare */
  2798. encoder_funcs->dpms(encoder, DRM_MODE_DPMS_OFF);
  2799. }
  2800. void intel_encoder_commit(struct drm_encoder *encoder)
  2801. {
  2802. struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
  2803. struct drm_device *dev = encoder->dev;
  2804. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  2805. /* lvds has its own version of commit see intel_lvds_commit */
  2806. encoder_funcs->dpms(encoder, DRM_MODE_DPMS_ON);
  2807. if (HAS_PCH_CPT(dev))
  2808. intel_cpt_verify_modeset(dev, intel_crtc->pipe);
  2809. }
  2810. void intel_encoder_destroy(struct drm_encoder *encoder)
  2811. {
  2812. struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
  2813. drm_encoder_cleanup(encoder);
  2814. kfree(intel_encoder);
  2815. }
  2816. static bool intel_crtc_mode_fixup(struct drm_crtc *crtc,
  2817. struct drm_display_mode *mode,
  2818. struct drm_display_mode *adjusted_mode)
  2819. {
  2820. struct drm_device *dev = crtc->dev;
  2821. if (HAS_PCH_SPLIT(dev)) {
  2822. /* FDI link clock is fixed at 2.7G */
  2823. if (mode->clock * 3 > IRONLAKE_FDI_FREQ * 4)
  2824. return false;
  2825. }
  2826. /* All interlaced capable intel hw wants timings in frames. Note though
  2827. * that intel_lvds_mode_fixup does some funny tricks with the crtc
  2828. * timings, so we need to be careful not to clobber these.*/
  2829. if (!(adjusted_mode->private_flags & INTEL_MODE_CRTC_TIMINGS_SET))
  2830. drm_mode_set_crtcinfo(adjusted_mode, 0);
  2831. return true;
  2832. }
  2833. static int valleyview_get_display_clock_speed(struct drm_device *dev)
  2834. {
  2835. return 400000; /* FIXME */
  2836. }
  2837. static int i945_get_display_clock_speed(struct drm_device *dev)
  2838. {
  2839. return 400000;
  2840. }
  2841. static int i915_get_display_clock_speed(struct drm_device *dev)
  2842. {
  2843. return 333000;
  2844. }
  2845. static int i9xx_misc_get_display_clock_speed(struct drm_device *dev)
  2846. {
  2847. return 200000;
  2848. }
  2849. static int i915gm_get_display_clock_speed(struct drm_device *dev)
  2850. {
  2851. u16 gcfgc = 0;
  2852. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  2853. if (gcfgc & GC_LOW_FREQUENCY_ENABLE)
  2854. return 133000;
  2855. else {
  2856. switch (gcfgc & GC_DISPLAY_CLOCK_MASK) {
  2857. case GC_DISPLAY_CLOCK_333_MHZ:
  2858. return 333000;
  2859. default:
  2860. case GC_DISPLAY_CLOCK_190_200_MHZ:
  2861. return 190000;
  2862. }
  2863. }
  2864. }
  2865. static int i865_get_display_clock_speed(struct drm_device *dev)
  2866. {
  2867. return 266000;
  2868. }
  2869. static int i855_get_display_clock_speed(struct drm_device *dev)
  2870. {
  2871. u16 hpllcc = 0;
  2872. /* Assume that the hardware is in the high speed state. This
  2873. * should be the default.
  2874. */
  2875. switch (hpllcc & GC_CLOCK_CONTROL_MASK) {
  2876. case GC_CLOCK_133_200:
  2877. case GC_CLOCK_100_200:
  2878. return 200000;
  2879. case GC_CLOCK_166_250:
  2880. return 250000;
  2881. case GC_CLOCK_100_133:
  2882. return 133000;
  2883. }
  2884. /* Shouldn't happen */
  2885. return 0;
  2886. }
  2887. static int i830_get_display_clock_speed(struct drm_device *dev)
  2888. {
  2889. return 133000;
  2890. }
  2891. struct fdi_m_n {
  2892. u32 tu;
  2893. u32 gmch_m;
  2894. u32 gmch_n;
  2895. u32 link_m;
  2896. u32 link_n;
  2897. };
  2898. static void
  2899. fdi_reduce_ratio(u32 *num, u32 *den)
  2900. {
  2901. while (*num > 0xffffff || *den > 0xffffff) {
  2902. *num >>= 1;
  2903. *den >>= 1;
  2904. }
  2905. }
  2906. static void
  2907. ironlake_compute_m_n(int bits_per_pixel, int nlanes, int pixel_clock,
  2908. int link_clock, struct fdi_m_n *m_n)
  2909. {
  2910. m_n->tu = 64; /* default size */
  2911. /* BUG_ON(pixel_clock > INT_MAX / 36); */
  2912. m_n->gmch_m = bits_per_pixel * pixel_clock;
  2913. m_n->gmch_n = link_clock * nlanes * 8;
  2914. fdi_reduce_ratio(&m_n->gmch_m, &m_n->gmch_n);
  2915. m_n->link_m = pixel_clock;
  2916. m_n->link_n = link_clock;
  2917. fdi_reduce_ratio(&m_n->link_m, &m_n->link_n);
  2918. }
  2919. static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
  2920. {
  2921. if (i915_panel_use_ssc >= 0)
  2922. return i915_panel_use_ssc != 0;
  2923. return dev_priv->lvds_use_ssc
  2924. && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
  2925. }
  2926. /**
  2927. * intel_choose_pipe_bpp_dither - figure out what color depth the pipe should send
  2928. * @crtc: CRTC structure
  2929. * @mode: requested mode
  2930. *
  2931. * A pipe may be connected to one or more outputs. Based on the depth of the
  2932. * attached framebuffer, choose a good color depth to use on the pipe.
  2933. *
  2934. * If possible, match the pipe depth to the fb depth. In some cases, this
  2935. * isn't ideal, because the connected output supports a lesser or restricted
  2936. * set of depths. Resolve that here:
  2937. * LVDS typically supports only 6bpc, so clamp down in that case
  2938. * HDMI supports only 8bpc or 12bpc, so clamp to 8bpc with dither for 10bpc
  2939. * Displays may support a restricted set as well, check EDID and clamp as
  2940. * appropriate.
  2941. * DP may want to dither down to 6bpc to fit larger modes
  2942. *
  2943. * RETURNS:
  2944. * Dithering requirement (i.e. false if display bpc and pipe bpc match,
  2945. * true if they don't match).
  2946. */
  2947. static bool intel_choose_pipe_bpp_dither(struct drm_crtc *crtc,
  2948. unsigned int *pipe_bpp,
  2949. struct drm_display_mode *mode)
  2950. {
  2951. struct drm_device *dev = crtc->dev;
  2952. struct drm_i915_private *dev_priv = dev->dev_private;
  2953. struct drm_encoder *encoder;
  2954. struct drm_connector *connector;
  2955. unsigned int display_bpc = UINT_MAX, bpc;
  2956. /* Walk the encoders & connectors on this crtc, get min bpc */
  2957. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  2958. struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
  2959. if (encoder->crtc != crtc)
  2960. continue;
  2961. if (intel_encoder->type == INTEL_OUTPUT_LVDS) {
  2962. unsigned int lvds_bpc;
  2963. if ((I915_READ(PCH_LVDS) & LVDS_A3_POWER_MASK) ==
  2964. LVDS_A3_POWER_UP)
  2965. lvds_bpc = 8;
  2966. else
  2967. lvds_bpc = 6;
  2968. if (lvds_bpc < display_bpc) {
  2969. DRM_DEBUG_KMS("clamping display bpc (was %d) to LVDS (%d)\n", display_bpc, lvds_bpc);
  2970. display_bpc = lvds_bpc;
  2971. }
  2972. continue;
  2973. }
  2974. if (intel_encoder->type == INTEL_OUTPUT_EDP) {
  2975. /* Use VBT settings if we have an eDP panel */
  2976. unsigned int edp_bpc = dev_priv->edp.bpp / 3;
  2977. if (edp_bpc < display_bpc) {
  2978. DRM_DEBUG_KMS("clamping display bpc (was %d) to eDP (%d)\n", display_bpc, edp_bpc);
  2979. display_bpc = edp_bpc;
  2980. }
  2981. continue;
  2982. }
  2983. /* Not one of the known troublemakers, check the EDID */
  2984. list_for_each_entry(connector, &dev->mode_config.connector_list,
  2985. head) {
  2986. if (connector->encoder != encoder)
  2987. continue;
  2988. /* Don't use an invalid EDID bpc value */
  2989. if (connector->display_info.bpc &&
  2990. connector->display_info.bpc < display_bpc) {
  2991. DRM_DEBUG_KMS("clamping display bpc (was %d) to EDID reported max of %d\n", display_bpc, connector->display_info.bpc);
  2992. display_bpc = connector->display_info.bpc;
  2993. }
  2994. }
  2995. /*
  2996. * HDMI is either 12 or 8, so if the display lets 10bpc sneak
  2997. * through, clamp it down. (Note: >12bpc will be caught below.)
  2998. */
  2999. if (intel_encoder->type == INTEL_OUTPUT_HDMI) {
  3000. if (display_bpc > 8 && display_bpc < 12) {
  3001. DRM_DEBUG_KMS("forcing bpc to 12 for HDMI\n");
  3002. display_bpc = 12;
  3003. } else {
  3004. DRM_DEBUG_KMS("forcing bpc to 8 for HDMI\n");
  3005. display_bpc = 8;
  3006. }
  3007. }
  3008. }
  3009. if (mode->private_flags & INTEL_MODE_DP_FORCE_6BPC) {
  3010. DRM_DEBUG_KMS("Dithering DP to 6bpc\n");
  3011. display_bpc = 6;
  3012. }
  3013. /*
  3014. * We could just drive the pipe at the highest bpc all the time and
  3015. * enable dithering as needed, but that costs bandwidth. So choose
  3016. * the minimum value that expresses the full color range of the fb but
  3017. * also stays within the max display bpc discovered above.
  3018. */
  3019. switch (crtc->fb->depth) {
  3020. case 8:
  3021. bpc = 8; /* since we go through a colormap */
  3022. break;
  3023. case 15:
  3024. case 16:
  3025. bpc = 6; /* min is 18bpp */
  3026. break;
  3027. case 24:
  3028. bpc = 8;
  3029. break;
  3030. case 30:
  3031. bpc = 10;
  3032. break;
  3033. case 48:
  3034. bpc = 12;
  3035. break;
  3036. default:
  3037. DRM_DEBUG("unsupported depth, assuming 24 bits\n");
  3038. bpc = min((unsigned int)8, display_bpc);
  3039. break;
  3040. }
  3041. display_bpc = min(display_bpc, bpc);
  3042. DRM_DEBUG_KMS("setting pipe bpc to %d (max display bpc %d)\n",
  3043. bpc, display_bpc);
  3044. *pipe_bpp = display_bpc * 3;
  3045. return display_bpc != bpc;
  3046. }
  3047. static int i9xx_get_refclk(struct drm_crtc *crtc, int num_connectors)
  3048. {
  3049. struct drm_device *dev = crtc->dev;
  3050. struct drm_i915_private *dev_priv = dev->dev_private;
  3051. int refclk;
  3052. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
  3053. intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
  3054. refclk = dev_priv->lvds_ssc_freq * 1000;
  3055. DRM_DEBUG_KMS("using SSC reference clock of %d MHz\n",
  3056. refclk / 1000);
  3057. } else if (!IS_GEN2(dev)) {
  3058. refclk = 96000;
  3059. } else {
  3060. refclk = 48000;
  3061. }
  3062. return refclk;
  3063. }
  3064. static void i9xx_adjust_sdvo_tv_clock(struct drm_display_mode *adjusted_mode,
  3065. intel_clock_t *clock)
  3066. {
  3067. /* SDVO TV has fixed PLL values depend on its clock range,
  3068. this mirrors vbios setting. */
  3069. if (adjusted_mode->clock >= 100000
  3070. && adjusted_mode->clock < 140500) {
  3071. clock->p1 = 2;
  3072. clock->p2 = 10;
  3073. clock->n = 3;
  3074. clock->m1 = 16;
  3075. clock->m2 = 8;
  3076. } else if (adjusted_mode->clock >= 140500
  3077. && adjusted_mode->clock <= 200000) {
  3078. clock->p1 = 1;
  3079. clock->p2 = 10;
  3080. clock->n = 6;
  3081. clock->m1 = 12;
  3082. clock->m2 = 8;
  3083. }
  3084. }
  3085. static void i9xx_update_pll_dividers(struct drm_crtc *crtc,
  3086. intel_clock_t *clock,
  3087. intel_clock_t *reduced_clock)
  3088. {
  3089. struct drm_device *dev = crtc->dev;
  3090. struct drm_i915_private *dev_priv = dev->dev_private;
  3091. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3092. int pipe = intel_crtc->pipe;
  3093. u32 fp, fp2 = 0;
  3094. if (IS_PINEVIEW(dev)) {
  3095. fp = (1 << clock->n) << 16 | clock->m1 << 8 | clock->m2;
  3096. if (reduced_clock)
  3097. fp2 = (1 << reduced_clock->n) << 16 |
  3098. reduced_clock->m1 << 8 | reduced_clock->m2;
  3099. } else {
  3100. fp = clock->n << 16 | clock->m1 << 8 | clock->m2;
  3101. if (reduced_clock)
  3102. fp2 = reduced_clock->n << 16 | reduced_clock->m1 << 8 |
  3103. reduced_clock->m2;
  3104. }
  3105. I915_WRITE(FP0(pipe), fp);
  3106. intel_crtc->lowfreq_avail = false;
  3107. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
  3108. reduced_clock && i915_powersave) {
  3109. I915_WRITE(FP1(pipe), fp2);
  3110. intel_crtc->lowfreq_avail = true;
  3111. } else {
  3112. I915_WRITE(FP1(pipe), fp);
  3113. }
  3114. }
  3115. static void intel_update_lvds(struct drm_crtc *crtc, intel_clock_t *clock,
  3116. struct drm_display_mode *adjusted_mode)
  3117. {
  3118. struct drm_device *dev = crtc->dev;
  3119. struct drm_i915_private *dev_priv = dev->dev_private;
  3120. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3121. int pipe = intel_crtc->pipe;
  3122. u32 temp;
  3123. temp = I915_READ(LVDS);
  3124. temp |= LVDS_PORT_EN | LVDS_A0A2_CLKA_POWER_UP;
  3125. if (pipe == 1) {
  3126. temp |= LVDS_PIPEB_SELECT;
  3127. } else {
  3128. temp &= ~LVDS_PIPEB_SELECT;
  3129. }
  3130. /* set the corresponsding LVDS_BORDER bit */
  3131. temp |= dev_priv->lvds_border_bits;
  3132. /* Set the B0-B3 data pairs corresponding to whether we're going to
  3133. * set the DPLLs for dual-channel mode or not.
  3134. */
  3135. if (clock->p2 == 7)
  3136. temp |= LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP;
  3137. else
  3138. temp &= ~(LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP);
  3139. /* It would be nice to set 24 vs 18-bit mode (LVDS_A3_POWER_UP)
  3140. * appropriately here, but we need to look more thoroughly into how
  3141. * panels behave in the two modes.
  3142. */
  3143. /* set the dithering flag on LVDS as needed */
  3144. if (INTEL_INFO(dev)->gen >= 4) {
  3145. if (dev_priv->lvds_dither)
  3146. temp |= LVDS_ENABLE_DITHER;
  3147. else
  3148. temp &= ~LVDS_ENABLE_DITHER;
  3149. }
  3150. temp &= ~(LVDS_HSYNC_POLARITY | LVDS_VSYNC_POLARITY);
  3151. if (adjusted_mode->flags & DRM_MODE_FLAG_NHSYNC)
  3152. temp |= LVDS_HSYNC_POLARITY;
  3153. if (adjusted_mode->flags & DRM_MODE_FLAG_NVSYNC)
  3154. temp |= LVDS_VSYNC_POLARITY;
  3155. I915_WRITE(LVDS, temp);
  3156. }
  3157. static void i9xx_update_pll(struct drm_crtc *crtc,
  3158. struct drm_display_mode *mode,
  3159. struct drm_display_mode *adjusted_mode,
  3160. intel_clock_t *clock, intel_clock_t *reduced_clock,
  3161. int num_connectors)
  3162. {
  3163. struct drm_device *dev = crtc->dev;
  3164. struct drm_i915_private *dev_priv = dev->dev_private;
  3165. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3166. int pipe = intel_crtc->pipe;
  3167. u32 dpll;
  3168. bool is_sdvo;
  3169. is_sdvo = intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO) ||
  3170. intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI);
  3171. dpll = DPLL_VGA_MODE_DIS;
  3172. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  3173. dpll |= DPLLB_MODE_LVDS;
  3174. else
  3175. dpll |= DPLLB_MODE_DAC_SERIAL;
  3176. if (is_sdvo) {
  3177. int pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
  3178. if (pixel_multiplier > 1) {
  3179. if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev))
  3180. dpll |= (pixel_multiplier - 1) << SDVO_MULTIPLIER_SHIFT_HIRES;
  3181. }
  3182. dpll |= DPLL_DVO_HIGH_SPEED;
  3183. }
  3184. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT))
  3185. dpll |= DPLL_DVO_HIGH_SPEED;
  3186. /* compute bitmask from p1 value */
  3187. if (IS_PINEVIEW(dev))
  3188. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
  3189. else {
  3190. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  3191. if (IS_G4X(dev) && reduced_clock)
  3192. dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  3193. }
  3194. switch (clock->p2) {
  3195. case 5:
  3196. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
  3197. break;
  3198. case 7:
  3199. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
  3200. break;
  3201. case 10:
  3202. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
  3203. break;
  3204. case 14:
  3205. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
  3206. break;
  3207. }
  3208. if (INTEL_INFO(dev)->gen >= 4)
  3209. dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
  3210. if (is_sdvo && intel_pipe_has_type(crtc, INTEL_OUTPUT_TVOUT))
  3211. dpll |= PLL_REF_INPUT_TVCLKINBC;
  3212. else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_TVOUT))
  3213. /* XXX: just matching BIOS for now */
  3214. /* dpll |= PLL_REF_INPUT_TVCLKINBC; */
  3215. dpll |= 3;
  3216. else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
  3217. intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  3218. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  3219. else
  3220. dpll |= PLL_REF_INPUT_DREFCLK;
  3221. dpll |= DPLL_VCO_ENABLE;
  3222. I915_WRITE(DPLL(pipe), dpll & ~DPLL_VCO_ENABLE);
  3223. POSTING_READ(DPLL(pipe));
  3224. udelay(150);
  3225. /* The LVDS pin pair needs to be on before the DPLLs are enabled.
  3226. * This is an exception to the general rule that mode_set doesn't turn
  3227. * things on.
  3228. */
  3229. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  3230. intel_update_lvds(crtc, clock, adjusted_mode);
  3231. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT))
  3232. intel_dp_set_m_n(crtc, mode, adjusted_mode);
  3233. I915_WRITE(DPLL(pipe), dpll);
  3234. /* Wait for the clocks to stabilize. */
  3235. POSTING_READ(DPLL(pipe));
  3236. udelay(150);
  3237. if (INTEL_INFO(dev)->gen >= 4) {
  3238. u32 temp = 0;
  3239. if (is_sdvo) {
  3240. temp = intel_mode_get_pixel_multiplier(adjusted_mode);
  3241. if (temp > 1)
  3242. temp = (temp - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  3243. else
  3244. temp = 0;
  3245. }
  3246. I915_WRITE(DPLL_MD(pipe), temp);
  3247. } else {
  3248. /* The pixel multiplier can only be updated once the
  3249. * DPLL is enabled and the clocks are stable.
  3250. *
  3251. * So write it again.
  3252. */
  3253. I915_WRITE(DPLL(pipe), dpll);
  3254. }
  3255. }
  3256. static void i8xx_update_pll(struct drm_crtc *crtc,
  3257. struct drm_display_mode *adjusted_mode,
  3258. intel_clock_t *clock,
  3259. int num_connectors)
  3260. {
  3261. struct drm_device *dev = crtc->dev;
  3262. struct drm_i915_private *dev_priv = dev->dev_private;
  3263. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3264. int pipe = intel_crtc->pipe;
  3265. u32 dpll;
  3266. dpll = DPLL_VGA_MODE_DIS;
  3267. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  3268. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  3269. } else {
  3270. if (clock->p1 == 2)
  3271. dpll |= PLL_P1_DIVIDE_BY_TWO;
  3272. else
  3273. dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  3274. if (clock->p2 == 4)
  3275. dpll |= PLL_P2_DIVIDE_BY_4;
  3276. }
  3277. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_TVOUT))
  3278. /* XXX: just matching BIOS for now */
  3279. /* dpll |= PLL_REF_INPUT_TVCLKINBC; */
  3280. dpll |= 3;
  3281. else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
  3282. intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  3283. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  3284. else
  3285. dpll |= PLL_REF_INPUT_DREFCLK;
  3286. dpll |= DPLL_VCO_ENABLE;
  3287. I915_WRITE(DPLL(pipe), dpll & ~DPLL_VCO_ENABLE);
  3288. POSTING_READ(DPLL(pipe));
  3289. udelay(150);
  3290. I915_WRITE(DPLL(pipe), dpll);
  3291. /* Wait for the clocks to stabilize. */
  3292. POSTING_READ(DPLL(pipe));
  3293. udelay(150);
  3294. /* The LVDS pin pair needs to be on before the DPLLs are enabled.
  3295. * This is an exception to the general rule that mode_set doesn't turn
  3296. * things on.
  3297. */
  3298. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  3299. intel_update_lvds(crtc, clock, adjusted_mode);
  3300. /* The pixel multiplier can only be updated once the
  3301. * DPLL is enabled and the clocks are stable.
  3302. *
  3303. * So write it again.
  3304. */
  3305. I915_WRITE(DPLL(pipe), dpll);
  3306. }
  3307. static int i9xx_crtc_mode_set(struct drm_crtc *crtc,
  3308. struct drm_display_mode *mode,
  3309. struct drm_display_mode *adjusted_mode,
  3310. int x, int y,
  3311. struct drm_framebuffer *old_fb)
  3312. {
  3313. struct drm_device *dev = crtc->dev;
  3314. struct drm_i915_private *dev_priv = dev->dev_private;
  3315. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3316. int pipe = intel_crtc->pipe;
  3317. int plane = intel_crtc->plane;
  3318. int refclk, num_connectors = 0;
  3319. intel_clock_t clock, reduced_clock;
  3320. u32 dspcntr, pipeconf, vsyncshift;
  3321. bool ok, has_reduced_clock = false, is_sdvo = false;
  3322. bool is_lvds = false, is_tv = false, is_dp = false;
  3323. struct drm_mode_config *mode_config = &dev->mode_config;
  3324. struct intel_encoder *encoder;
  3325. const intel_limit_t *limit;
  3326. int ret;
  3327. list_for_each_entry(encoder, &mode_config->encoder_list, base.head) {
  3328. if (encoder->base.crtc != crtc)
  3329. continue;
  3330. switch (encoder->type) {
  3331. case INTEL_OUTPUT_LVDS:
  3332. is_lvds = true;
  3333. break;
  3334. case INTEL_OUTPUT_SDVO:
  3335. case INTEL_OUTPUT_HDMI:
  3336. is_sdvo = true;
  3337. if (encoder->needs_tv_clock)
  3338. is_tv = true;
  3339. break;
  3340. case INTEL_OUTPUT_TVOUT:
  3341. is_tv = true;
  3342. break;
  3343. case INTEL_OUTPUT_DISPLAYPORT:
  3344. is_dp = true;
  3345. break;
  3346. }
  3347. num_connectors++;
  3348. }
  3349. refclk = i9xx_get_refclk(crtc, num_connectors);
  3350. /*
  3351. * Returns a set of divisors for the desired target clock with the given
  3352. * refclk, or FALSE. The returned values represent the clock equation:
  3353. * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
  3354. */
  3355. limit = intel_limit(crtc, refclk);
  3356. ok = limit->find_pll(limit, crtc, adjusted_mode->clock, refclk, NULL,
  3357. &clock);
  3358. if (!ok) {
  3359. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  3360. return -EINVAL;
  3361. }
  3362. /* Ensure that the cursor is valid for the new mode before changing... */
  3363. intel_crtc_update_cursor(crtc, true);
  3364. if (is_lvds && dev_priv->lvds_downclock_avail) {
  3365. /*
  3366. * Ensure we match the reduced clock's P to the target clock.
  3367. * If the clocks don't match, we can't switch the display clock
  3368. * by using the FP0/FP1. In such case we will disable the LVDS
  3369. * downclock feature.
  3370. */
  3371. has_reduced_clock = limit->find_pll(limit, crtc,
  3372. dev_priv->lvds_downclock,
  3373. refclk,
  3374. &clock,
  3375. &reduced_clock);
  3376. }
  3377. if (is_sdvo && is_tv)
  3378. i9xx_adjust_sdvo_tv_clock(adjusted_mode, &clock);
  3379. i9xx_update_pll_dividers(crtc, &clock, has_reduced_clock ?
  3380. &reduced_clock : NULL);
  3381. if (IS_GEN2(dev))
  3382. i8xx_update_pll(crtc, adjusted_mode, &clock, num_connectors);
  3383. else
  3384. i9xx_update_pll(crtc, mode, adjusted_mode, &clock,
  3385. has_reduced_clock ? &reduced_clock : NULL,
  3386. num_connectors);
  3387. /* setup pipeconf */
  3388. pipeconf = I915_READ(PIPECONF(pipe));
  3389. /* Set up the display plane register */
  3390. dspcntr = DISPPLANE_GAMMA_ENABLE;
  3391. if (pipe == 0)
  3392. dspcntr &= ~DISPPLANE_SEL_PIPE_MASK;
  3393. else
  3394. dspcntr |= DISPPLANE_SEL_PIPE_B;
  3395. if (pipe == 0 && INTEL_INFO(dev)->gen < 4) {
  3396. /* Enable pixel doubling when the dot clock is > 90% of the (display)
  3397. * core speed.
  3398. *
  3399. * XXX: No double-wide on 915GM pipe B. Is that the only reason for the
  3400. * pipe == 0 check?
  3401. */
  3402. if (mode->clock >
  3403. dev_priv->display.get_display_clock_speed(dev) * 9 / 10)
  3404. pipeconf |= PIPECONF_DOUBLE_WIDE;
  3405. else
  3406. pipeconf &= ~PIPECONF_DOUBLE_WIDE;
  3407. }
  3408. /* default to 8bpc */
  3409. pipeconf &= ~(PIPECONF_BPP_MASK | PIPECONF_DITHER_EN);
  3410. if (is_dp) {
  3411. if (mode->private_flags & INTEL_MODE_DP_FORCE_6BPC) {
  3412. pipeconf |= PIPECONF_BPP_6 |
  3413. PIPECONF_DITHER_EN |
  3414. PIPECONF_DITHER_TYPE_SP;
  3415. }
  3416. }
  3417. DRM_DEBUG_KMS("Mode for pipe %c:\n", pipe == 0 ? 'A' : 'B');
  3418. drm_mode_debug_printmodeline(mode);
  3419. if (HAS_PIPE_CXSR(dev)) {
  3420. if (intel_crtc->lowfreq_avail) {
  3421. DRM_DEBUG_KMS("enabling CxSR downclocking\n");
  3422. pipeconf |= PIPECONF_CXSR_DOWNCLOCK;
  3423. } else {
  3424. DRM_DEBUG_KMS("disabling CxSR downclocking\n");
  3425. pipeconf &= ~PIPECONF_CXSR_DOWNCLOCK;
  3426. }
  3427. }
  3428. pipeconf &= ~PIPECONF_INTERLACE_MASK;
  3429. if (!IS_GEN2(dev) &&
  3430. adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
  3431. pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
  3432. /* the chip adds 2 halflines automatically */
  3433. adjusted_mode->crtc_vtotal -= 1;
  3434. adjusted_mode->crtc_vblank_end -= 1;
  3435. vsyncshift = adjusted_mode->crtc_hsync_start
  3436. - adjusted_mode->crtc_htotal/2;
  3437. } else {
  3438. pipeconf |= PIPECONF_PROGRESSIVE;
  3439. vsyncshift = 0;
  3440. }
  3441. if (!IS_GEN3(dev))
  3442. I915_WRITE(VSYNCSHIFT(pipe), vsyncshift);
  3443. I915_WRITE(HTOTAL(pipe),
  3444. (adjusted_mode->crtc_hdisplay - 1) |
  3445. ((adjusted_mode->crtc_htotal - 1) << 16));
  3446. I915_WRITE(HBLANK(pipe),
  3447. (adjusted_mode->crtc_hblank_start - 1) |
  3448. ((adjusted_mode->crtc_hblank_end - 1) << 16));
  3449. I915_WRITE(HSYNC(pipe),
  3450. (adjusted_mode->crtc_hsync_start - 1) |
  3451. ((adjusted_mode->crtc_hsync_end - 1) << 16));
  3452. I915_WRITE(VTOTAL(pipe),
  3453. (adjusted_mode->crtc_vdisplay - 1) |
  3454. ((adjusted_mode->crtc_vtotal - 1) << 16));
  3455. I915_WRITE(VBLANK(pipe),
  3456. (adjusted_mode->crtc_vblank_start - 1) |
  3457. ((adjusted_mode->crtc_vblank_end - 1) << 16));
  3458. I915_WRITE(VSYNC(pipe),
  3459. (adjusted_mode->crtc_vsync_start - 1) |
  3460. ((adjusted_mode->crtc_vsync_end - 1) << 16));
  3461. /* pipesrc and dspsize control the size that is scaled from,
  3462. * which should always be the user's requested size.
  3463. */
  3464. I915_WRITE(DSPSIZE(plane),
  3465. ((mode->vdisplay - 1) << 16) |
  3466. (mode->hdisplay - 1));
  3467. I915_WRITE(DSPPOS(plane), 0);
  3468. I915_WRITE(PIPESRC(pipe),
  3469. ((mode->hdisplay - 1) << 16) | (mode->vdisplay - 1));
  3470. I915_WRITE(PIPECONF(pipe), pipeconf);
  3471. POSTING_READ(PIPECONF(pipe));
  3472. intel_enable_pipe(dev_priv, pipe, false);
  3473. intel_wait_for_vblank(dev, pipe);
  3474. I915_WRITE(DSPCNTR(plane), dspcntr);
  3475. POSTING_READ(DSPCNTR(plane));
  3476. ret = intel_pipe_set_base(crtc, x, y, old_fb);
  3477. intel_update_watermarks(dev);
  3478. return ret;
  3479. }
  3480. /*
  3481. * Initialize reference clocks when the driver loads
  3482. */
  3483. void ironlake_init_pch_refclk(struct drm_device *dev)
  3484. {
  3485. struct drm_i915_private *dev_priv = dev->dev_private;
  3486. struct drm_mode_config *mode_config = &dev->mode_config;
  3487. struct intel_encoder *encoder;
  3488. u32 temp;
  3489. bool has_lvds = false;
  3490. bool has_cpu_edp = false;
  3491. bool has_pch_edp = false;
  3492. bool has_panel = false;
  3493. bool has_ck505 = false;
  3494. bool can_ssc = false;
  3495. /* We need to take the global config into account */
  3496. list_for_each_entry(encoder, &mode_config->encoder_list,
  3497. base.head) {
  3498. switch (encoder->type) {
  3499. case INTEL_OUTPUT_LVDS:
  3500. has_panel = true;
  3501. has_lvds = true;
  3502. break;
  3503. case INTEL_OUTPUT_EDP:
  3504. has_panel = true;
  3505. if (intel_encoder_is_pch_edp(&encoder->base))
  3506. has_pch_edp = true;
  3507. else
  3508. has_cpu_edp = true;
  3509. break;
  3510. }
  3511. }
  3512. if (HAS_PCH_IBX(dev)) {
  3513. has_ck505 = dev_priv->display_clock_mode;
  3514. can_ssc = has_ck505;
  3515. } else {
  3516. has_ck505 = false;
  3517. can_ssc = true;
  3518. }
  3519. DRM_DEBUG_KMS("has_panel %d has_lvds %d has_pch_edp %d has_cpu_edp %d has_ck505 %d\n",
  3520. has_panel, has_lvds, has_pch_edp, has_cpu_edp,
  3521. has_ck505);
  3522. /* Ironlake: try to setup display ref clock before DPLL
  3523. * enabling. This is only under driver's control after
  3524. * PCH B stepping, previous chipset stepping should be
  3525. * ignoring this setting.
  3526. */
  3527. temp = I915_READ(PCH_DREF_CONTROL);
  3528. /* Always enable nonspread source */
  3529. temp &= ~DREF_NONSPREAD_SOURCE_MASK;
  3530. if (has_ck505)
  3531. temp |= DREF_NONSPREAD_CK505_ENABLE;
  3532. else
  3533. temp |= DREF_NONSPREAD_SOURCE_ENABLE;
  3534. if (has_panel) {
  3535. temp &= ~DREF_SSC_SOURCE_MASK;
  3536. temp |= DREF_SSC_SOURCE_ENABLE;
  3537. /* SSC must be turned on before enabling the CPU output */
  3538. if (intel_panel_use_ssc(dev_priv) && can_ssc) {
  3539. DRM_DEBUG_KMS("Using SSC on panel\n");
  3540. temp |= DREF_SSC1_ENABLE;
  3541. } else
  3542. temp &= ~DREF_SSC1_ENABLE;
  3543. /* Get SSC going before enabling the outputs */
  3544. I915_WRITE(PCH_DREF_CONTROL, temp);
  3545. POSTING_READ(PCH_DREF_CONTROL);
  3546. udelay(200);
  3547. temp &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  3548. /* Enable CPU source on CPU attached eDP */
  3549. if (has_cpu_edp) {
  3550. if (intel_panel_use_ssc(dev_priv) && can_ssc) {
  3551. DRM_DEBUG_KMS("Using SSC on eDP\n");
  3552. temp |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
  3553. }
  3554. else
  3555. temp |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
  3556. } else
  3557. temp |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  3558. I915_WRITE(PCH_DREF_CONTROL, temp);
  3559. POSTING_READ(PCH_DREF_CONTROL);
  3560. udelay(200);
  3561. } else {
  3562. DRM_DEBUG_KMS("Disabling SSC entirely\n");
  3563. temp &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  3564. /* Turn off CPU output */
  3565. temp |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  3566. I915_WRITE(PCH_DREF_CONTROL, temp);
  3567. POSTING_READ(PCH_DREF_CONTROL);
  3568. udelay(200);
  3569. /* Turn off the SSC source */
  3570. temp &= ~DREF_SSC_SOURCE_MASK;
  3571. temp |= DREF_SSC_SOURCE_DISABLE;
  3572. /* Turn off SSC1 */
  3573. temp &= ~ DREF_SSC1_ENABLE;
  3574. I915_WRITE(PCH_DREF_CONTROL, temp);
  3575. POSTING_READ(PCH_DREF_CONTROL);
  3576. udelay(200);
  3577. }
  3578. }
  3579. static int ironlake_get_refclk(struct drm_crtc *crtc)
  3580. {
  3581. struct drm_device *dev = crtc->dev;
  3582. struct drm_i915_private *dev_priv = dev->dev_private;
  3583. struct intel_encoder *encoder;
  3584. struct drm_mode_config *mode_config = &dev->mode_config;
  3585. struct intel_encoder *edp_encoder = NULL;
  3586. int num_connectors = 0;
  3587. bool is_lvds = false;
  3588. list_for_each_entry(encoder, &mode_config->encoder_list, base.head) {
  3589. if (encoder->base.crtc != crtc)
  3590. continue;
  3591. switch (encoder->type) {
  3592. case INTEL_OUTPUT_LVDS:
  3593. is_lvds = true;
  3594. break;
  3595. case INTEL_OUTPUT_EDP:
  3596. edp_encoder = encoder;
  3597. break;
  3598. }
  3599. num_connectors++;
  3600. }
  3601. if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
  3602. DRM_DEBUG_KMS("using SSC reference clock of %d MHz\n",
  3603. dev_priv->lvds_ssc_freq);
  3604. return dev_priv->lvds_ssc_freq * 1000;
  3605. }
  3606. return 120000;
  3607. }
  3608. static int ironlake_crtc_mode_set(struct drm_crtc *crtc,
  3609. struct drm_display_mode *mode,
  3610. struct drm_display_mode *adjusted_mode,
  3611. int x, int y,
  3612. struct drm_framebuffer *old_fb)
  3613. {
  3614. struct drm_device *dev = crtc->dev;
  3615. struct drm_i915_private *dev_priv = dev->dev_private;
  3616. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3617. int pipe = intel_crtc->pipe;
  3618. int plane = intel_crtc->plane;
  3619. int refclk, num_connectors = 0;
  3620. intel_clock_t clock, reduced_clock;
  3621. u32 dpll, fp = 0, fp2 = 0, dspcntr, pipeconf;
  3622. bool ok, has_reduced_clock = false, is_sdvo = false;
  3623. bool is_crt = false, is_lvds = false, is_tv = false, is_dp = false;
  3624. struct drm_mode_config *mode_config = &dev->mode_config;
  3625. struct intel_encoder *encoder, *edp_encoder = NULL;
  3626. const intel_limit_t *limit;
  3627. int ret;
  3628. struct fdi_m_n m_n = {0};
  3629. u32 temp;
  3630. int target_clock, pixel_multiplier, lane, link_bw, factor;
  3631. unsigned int pipe_bpp;
  3632. bool dither;
  3633. bool is_cpu_edp = false, is_pch_edp = false;
  3634. list_for_each_entry(encoder, &mode_config->encoder_list, base.head) {
  3635. if (encoder->base.crtc != crtc)
  3636. continue;
  3637. switch (encoder->type) {
  3638. case INTEL_OUTPUT_LVDS:
  3639. is_lvds = true;
  3640. break;
  3641. case INTEL_OUTPUT_SDVO:
  3642. case INTEL_OUTPUT_HDMI:
  3643. is_sdvo = true;
  3644. if (encoder->needs_tv_clock)
  3645. is_tv = true;
  3646. break;
  3647. case INTEL_OUTPUT_TVOUT:
  3648. is_tv = true;
  3649. break;
  3650. case INTEL_OUTPUT_ANALOG:
  3651. is_crt = true;
  3652. break;
  3653. case INTEL_OUTPUT_DISPLAYPORT:
  3654. is_dp = true;
  3655. break;
  3656. case INTEL_OUTPUT_EDP:
  3657. is_dp = true;
  3658. if (intel_encoder_is_pch_edp(&encoder->base))
  3659. is_pch_edp = true;
  3660. else
  3661. is_cpu_edp = true;
  3662. edp_encoder = encoder;
  3663. break;
  3664. }
  3665. num_connectors++;
  3666. }
  3667. refclk = ironlake_get_refclk(crtc);
  3668. /*
  3669. * Returns a set of divisors for the desired target clock with the given
  3670. * refclk, or FALSE. The returned values represent the clock equation:
  3671. * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
  3672. */
  3673. limit = intel_limit(crtc, refclk);
  3674. ok = limit->find_pll(limit, crtc, adjusted_mode->clock, refclk, NULL,
  3675. &clock);
  3676. if (!ok) {
  3677. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  3678. return -EINVAL;
  3679. }
  3680. /* Ensure that the cursor is valid for the new mode before changing... */
  3681. intel_crtc_update_cursor(crtc, true);
  3682. if (is_lvds && dev_priv->lvds_downclock_avail) {
  3683. /*
  3684. * Ensure we match the reduced clock's P to the target clock.
  3685. * If the clocks don't match, we can't switch the display clock
  3686. * by using the FP0/FP1. In such case we will disable the LVDS
  3687. * downclock feature.
  3688. */
  3689. has_reduced_clock = limit->find_pll(limit, crtc,
  3690. dev_priv->lvds_downclock,
  3691. refclk,
  3692. &clock,
  3693. &reduced_clock);
  3694. }
  3695. /* SDVO TV has fixed PLL values depend on its clock range,
  3696. this mirrors vbios setting. */
  3697. if (is_sdvo && is_tv) {
  3698. if (adjusted_mode->clock >= 100000
  3699. && adjusted_mode->clock < 140500) {
  3700. clock.p1 = 2;
  3701. clock.p2 = 10;
  3702. clock.n = 3;
  3703. clock.m1 = 16;
  3704. clock.m2 = 8;
  3705. } else if (adjusted_mode->clock >= 140500
  3706. && adjusted_mode->clock <= 200000) {
  3707. clock.p1 = 1;
  3708. clock.p2 = 10;
  3709. clock.n = 6;
  3710. clock.m1 = 12;
  3711. clock.m2 = 8;
  3712. }
  3713. }
  3714. /* FDI link */
  3715. pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
  3716. lane = 0;
  3717. /* CPU eDP doesn't require FDI link, so just set DP M/N
  3718. according to current link config */
  3719. if (is_cpu_edp) {
  3720. target_clock = mode->clock;
  3721. intel_edp_link_config(edp_encoder, &lane, &link_bw);
  3722. } else {
  3723. /* [e]DP over FDI requires target mode clock
  3724. instead of link clock */
  3725. if (is_dp)
  3726. target_clock = mode->clock;
  3727. else
  3728. target_clock = adjusted_mode->clock;
  3729. /* FDI is a binary signal running at ~2.7GHz, encoding
  3730. * each output octet as 10 bits. The actual frequency
  3731. * is stored as a divider into a 100MHz clock, and the
  3732. * mode pixel clock is stored in units of 1KHz.
  3733. * Hence the bw of each lane in terms of the mode signal
  3734. * is:
  3735. */
  3736. link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10;
  3737. }
  3738. /* determine panel color depth */
  3739. temp = I915_READ(PIPECONF(pipe));
  3740. temp &= ~PIPE_BPC_MASK;
  3741. dither = intel_choose_pipe_bpp_dither(crtc, &pipe_bpp, mode);
  3742. switch (pipe_bpp) {
  3743. case 18:
  3744. temp |= PIPE_6BPC;
  3745. break;
  3746. case 24:
  3747. temp |= PIPE_8BPC;
  3748. break;
  3749. case 30:
  3750. temp |= PIPE_10BPC;
  3751. break;
  3752. case 36:
  3753. temp |= PIPE_12BPC;
  3754. break;
  3755. default:
  3756. WARN(1, "intel_choose_pipe_bpp returned invalid value %d\n",
  3757. pipe_bpp);
  3758. temp |= PIPE_8BPC;
  3759. pipe_bpp = 24;
  3760. break;
  3761. }
  3762. intel_crtc->bpp = pipe_bpp;
  3763. I915_WRITE(PIPECONF(pipe), temp);
  3764. if (!lane) {
  3765. /*
  3766. * Account for spread spectrum to avoid
  3767. * oversubscribing the link. Max center spread
  3768. * is 2.5%; use 5% for safety's sake.
  3769. */
  3770. u32 bps = target_clock * intel_crtc->bpp * 21 / 20;
  3771. lane = bps / (link_bw * 8) + 1;
  3772. }
  3773. intel_crtc->fdi_lanes = lane;
  3774. if (pixel_multiplier > 1)
  3775. link_bw *= pixel_multiplier;
  3776. ironlake_compute_m_n(intel_crtc->bpp, lane, target_clock, link_bw,
  3777. &m_n);
  3778. fp = clock.n << 16 | clock.m1 << 8 | clock.m2;
  3779. if (has_reduced_clock)
  3780. fp2 = reduced_clock.n << 16 | reduced_clock.m1 << 8 |
  3781. reduced_clock.m2;
  3782. /* Enable autotuning of the PLL clock (if permissible) */
  3783. factor = 21;
  3784. if (is_lvds) {
  3785. if ((intel_panel_use_ssc(dev_priv) &&
  3786. dev_priv->lvds_ssc_freq == 100) ||
  3787. (I915_READ(PCH_LVDS) & LVDS_CLKB_POWER_MASK) == LVDS_CLKB_POWER_UP)
  3788. factor = 25;
  3789. } else if (is_sdvo && is_tv)
  3790. factor = 20;
  3791. if (clock.m < factor * clock.n)
  3792. fp |= FP_CB_TUNE;
  3793. dpll = 0;
  3794. if (is_lvds)
  3795. dpll |= DPLLB_MODE_LVDS;
  3796. else
  3797. dpll |= DPLLB_MODE_DAC_SERIAL;
  3798. if (is_sdvo) {
  3799. int pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
  3800. if (pixel_multiplier > 1) {
  3801. dpll |= (pixel_multiplier - 1) << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
  3802. }
  3803. dpll |= DPLL_DVO_HIGH_SPEED;
  3804. }
  3805. if (is_dp && !is_cpu_edp)
  3806. dpll |= DPLL_DVO_HIGH_SPEED;
  3807. /* compute bitmask from p1 value */
  3808. dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  3809. /* also FPA1 */
  3810. dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  3811. switch (clock.p2) {
  3812. case 5:
  3813. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
  3814. break;
  3815. case 7:
  3816. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
  3817. break;
  3818. case 10:
  3819. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
  3820. break;
  3821. case 14:
  3822. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
  3823. break;
  3824. }
  3825. if (is_sdvo && is_tv)
  3826. dpll |= PLL_REF_INPUT_TVCLKINBC;
  3827. else if (is_tv)
  3828. /* XXX: just matching BIOS for now */
  3829. /* dpll |= PLL_REF_INPUT_TVCLKINBC; */
  3830. dpll |= 3;
  3831. else if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  3832. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  3833. else
  3834. dpll |= PLL_REF_INPUT_DREFCLK;
  3835. /* setup pipeconf */
  3836. pipeconf = I915_READ(PIPECONF(pipe));
  3837. /* Set up the display plane register */
  3838. dspcntr = DISPPLANE_GAMMA_ENABLE;
  3839. DRM_DEBUG_KMS("Mode for pipe %d:\n", pipe);
  3840. drm_mode_debug_printmodeline(mode);
  3841. /* CPU eDP is the only output that doesn't need a PCH PLL of its own on
  3842. * pre-Haswell/LPT generation */
  3843. if (HAS_PCH_LPT(dev)) {
  3844. DRM_DEBUG_KMS("LPT detected: no PLL for pipe %d necessary\n",
  3845. pipe);
  3846. } else if (!is_cpu_edp) {
  3847. struct intel_pch_pll *pll;
  3848. pll = intel_get_pch_pll(intel_crtc, dpll, fp);
  3849. if (pll == NULL) {
  3850. DRM_DEBUG_DRIVER("failed to find PLL for pipe %d\n",
  3851. pipe);
  3852. return -EINVAL;
  3853. }
  3854. } else
  3855. intel_put_pch_pll(intel_crtc);
  3856. /* The LVDS pin pair needs to be on before the DPLLs are enabled.
  3857. * This is an exception to the general rule that mode_set doesn't turn
  3858. * things on.
  3859. */
  3860. if (is_lvds) {
  3861. temp = I915_READ(PCH_LVDS);
  3862. temp |= LVDS_PORT_EN | LVDS_A0A2_CLKA_POWER_UP;
  3863. if (HAS_PCH_CPT(dev)) {
  3864. temp &= ~PORT_TRANS_SEL_MASK;
  3865. temp |= PORT_TRANS_SEL_CPT(pipe);
  3866. } else {
  3867. if (pipe == 1)
  3868. temp |= LVDS_PIPEB_SELECT;
  3869. else
  3870. temp &= ~LVDS_PIPEB_SELECT;
  3871. }
  3872. /* set the corresponsding LVDS_BORDER bit */
  3873. temp |= dev_priv->lvds_border_bits;
  3874. /* Set the B0-B3 data pairs corresponding to whether we're going to
  3875. * set the DPLLs for dual-channel mode or not.
  3876. */
  3877. if (clock.p2 == 7)
  3878. temp |= LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP;
  3879. else
  3880. temp &= ~(LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP);
  3881. /* It would be nice to set 24 vs 18-bit mode (LVDS_A3_POWER_UP)
  3882. * appropriately here, but we need to look more thoroughly into how
  3883. * panels behave in the two modes.
  3884. */
  3885. temp &= ~(LVDS_HSYNC_POLARITY | LVDS_VSYNC_POLARITY);
  3886. if (adjusted_mode->flags & DRM_MODE_FLAG_NHSYNC)
  3887. temp |= LVDS_HSYNC_POLARITY;
  3888. if (adjusted_mode->flags & DRM_MODE_FLAG_NVSYNC)
  3889. temp |= LVDS_VSYNC_POLARITY;
  3890. I915_WRITE(PCH_LVDS, temp);
  3891. }
  3892. pipeconf &= ~PIPECONF_DITHER_EN;
  3893. pipeconf &= ~PIPECONF_DITHER_TYPE_MASK;
  3894. if ((is_lvds && dev_priv->lvds_dither) || dither) {
  3895. pipeconf |= PIPECONF_DITHER_EN;
  3896. pipeconf |= PIPECONF_DITHER_TYPE_SP;
  3897. }
  3898. if (is_dp && !is_cpu_edp) {
  3899. intel_dp_set_m_n(crtc, mode, adjusted_mode);
  3900. } else {
  3901. /* For non-DP output, clear any trans DP clock recovery setting.*/
  3902. I915_WRITE(TRANSDATA_M1(pipe), 0);
  3903. I915_WRITE(TRANSDATA_N1(pipe), 0);
  3904. I915_WRITE(TRANSDPLINK_M1(pipe), 0);
  3905. I915_WRITE(TRANSDPLINK_N1(pipe), 0);
  3906. }
  3907. if (intel_crtc->pch_pll) {
  3908. I915_WRITE(intel_crtc->pch_pll->pll_reg, dpll);
  3909. /* Wait for the clocks to stabilize. */
  3910. POSTING_READ(intel_crtc->pch_pll->pll_reg);
  3911. udelay(150);
  3912. /* The pixel multiplier can only be updated once the
  3913. * DPLL is enabled and the clocks are stable.
  3914. *
  3915. * So write it again.
  3916. */
  3917. I915_WRITE(intel_crtc->pch_pll->pll_reg, dpll);
  3918. }
  3919. intel_crtc->lowfreq_avail = false;
  3920. if (intel_crtc->pch_pll) {
  3921. if (is_lvds && has_reduced_clock && i915_powersave) {
  3922. I915_WRITE(intel_crtc->pch_pll->fp1_reg, fp2);
  3923. intel_crtc->lowfreq_avail = true;
  3924. if (HAS_PIPE_CXSR(dev)) {
  3925. DRM_DEBUG_KMS("enabling CxSR downclocking\n");
  3926. pipeconf |= PIPECONF_CXSR_DOWNCLOCK;
  3927. }
  3928. } else {
  3929. I915_WRITE(intel_crtc->pch_pll->fp1_reg, fp);
  3930. if (HAS_PIPE_CXSR(dev)) {
  3931. DRM_DEBUG_KMS("disabling CxSR downclocking\n");
  3932. pipeconf &= ~PIPECONF_CXSR_DOWNCLOCK;
  3933. }
  3934. }
  3935. }
  3936. pipeconf &= ~PIPECONF_INTERLACE_MASK;
  3937. if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
  3938. pipeconf |= PIPECONF_INTERLACED_ILK;
  3939. /* the chip adds 2 halflines automatically */
  3940. adjusted_mode->crtc_vtotal -= 1;
  3941. adjusted_mode->crtc_vblank_end -= 1;
  3942. I915_WRITE(VSYNCSHIFT(pipe),
  3943. adjusted_mode->crtc_hsync_start
  3944. - adjusted_mode->crtc_htotal/2);
  3945. } else {
  3946. pipeconf |= PIPECONF_PROGRESSIVE;
  3947. I915_WRITE(VSYNCSHIFT(pipe), 0);
  3948. }
  3949. I915_WRITE(HTOTAL(pipe),
  3950. (adjusted_mode->crtc_hdisplay - 1) |
  3951. ((adjusted_mode->crtc_htotal - 1) << 16));
  3952. I915_WRITE(HBLANK(pipe),
  3953. (adjusted_mode->crtc_hblank_start - 1) |
  3954. ((adjusted_mode->crtc_hblank_end - 1) << 16));
  3955. I915_WRITE(HSYNC(pipe),
  3956. (adjusted_mode->crtc_hsync_start - 1) |
  3957. ((adjusted_mode->crtc_hsync_end - 1) << 16));
  3958. I915_WRITE(VTOTAL(pipe),
  3959. (adjusted_mode->crtc_vdisplay - 1) |
  3960. ((adjusted_mode->crtc_vtotal - 1) << 16));
  3961. I915_WRITE(VBLANK(pipe),
  3962. (adjusted_mode->crtc_vblank_start - 1) |
  3963. ((adjusted_mode->crtc_vblank_end - 1) << 16));
  3964. I915_WRITE(VSYNC(pipe),
  3965. (adjusted_mode->crtc_vsync_start - 1) |
  3966. ((adjusted_mode->crtc_vsync_end - 1) << 16));
  3967. /* pipesrc controls the size that is scaled from, which should
  3968. * always be the user's requested size.
  3969. */
  3970. I915_WRITE(PIPESRC(pipe),
  3971. ((mode->hdisplay - 1) << 16) | (mode->vdisplay - 1));
  3972. I915_WRITE(PIPE_DATA_M1(pipe), TU_SIZE(m_n.tu) | m_n.gmch_m);
  3973. I915_WRITE(PIPE_DATA_N1(pipe), m_n.gmch_n);
  3974. I915_WRITE(PIPE_LINK_M1(pipe), m_n.link_m);
  3975. I915_WRITE(PIPE_LINK_N1(pipe), m_n.link_n);
  3976. if (is_cpu_edp)
  3977. ironlake_set_pll_edp(crtc, adjusted_mode->clock);
  3978. I915_WRITE(PIPECONF(pipe), pipeconf);
  3979. POSTING_READ(PIPECONF(pipe));
  3980. intel_wait_for_vblank(dev, pipe);
  3981. I915_WRITE(DSPCNTR(plane), dspcntr);
  3982. POSTING_READ(DSPCNTR(plane));
  3983. ret = intel_pipe_set_base(crtc, x, y, old_fb);
  3984. intel_update_watermarks(dev);
  3985. intel_update_linetime_watermarks(dev, pipe, adjusted_mode);
  3986. return ret;
  3987. }
  3988. static int intel_crtc_mode_set(struct drm_crtc *crtc,
  3989. struct drm_display_mode *mode,
  3990. struct drm_display_mode *adjusted_mode,
  3991. int x, int y,
  3992. struct drm_framebuffer *old_fb)
  3993. {
  3994. struct drm_device *dev = crtc->dev;
  3995. struct drm_i915_private *dev_priv = dev->dev_private;
  3996. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3997. int pipe = intel_crtc->pipe;
  3998. int ret;
  3999. drm_vblank_pre_modeset(dev, pipe);
  4000. ret = dev_priv->display.crtc_mode_set(crtc, mode, adjusted_mode,
  4001. x, y, old_fb);
  4002. drm_vblank_post_modeset(dev, pipe);
  4003. if (ret)
  4004. intel_crtc->dpms_mode = DRM_MODE_DPMS_OFF;
  4005. else
  4006. intel_crtc->dpms_mode = DRM_MODE_DPMS_ON;
  4007. return ret;
  4008. }
  4009. static bool intel_eld_uptodate(struct drm_connector *connector,
  4010. int reg_eldv, uint32_t bits_eldv,
  4011. int reg_elda, uint32_t bits_elda,
  4012. int reg_edid)
  4013. {
  4014. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  4015. uint8_t *eld = connector->eld;
  4016. uint32_t i;
  4017. i = I915_READ(reg_eldv);
  4018. i &= bits_eldv;
  4019. if (!eld[0])
  4020. return !i;
  4021. if (!i)
  4022. return false;
  4023. i = I915_READ(reg_elda);
  4024. i &= ~bits_elda;
  4025. I915_WRITE(reg_elda, i);
  4026. for (i = 0; i < eld[2]; i++)
  4027. if (I915_READ(reg_edid) != *((uint32_t *)eld + i))
  4028. return false;
  4029. return true;
  4030. }
  4031. static void g4x_write_eld(struct drm_connector *connector,
  4032. struct drm_crtc *crtc)
  4033. {
  4034. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  4035. uint8_t *eld = connector->eld;
  4036. uint32_t eldv;
  4037. uint32_t len;
  4038. uint32_t i;
  4039. i = I915_READ(G4X_AUD_VID_DID);
  4040. if (i == INTEL_AUDIO_DEVBLC || i == INTEL_AUDIO_DEVCL)
  4041. eldv = G4X_ELDV_DEVCL_DEVBLC;
  4042. else
  4043. eldv = G4X_ELDV_DEVCTG;
  4044. if (intel_eld_uptodate(connector,
  4045. G4X_AUD_CNTL_ST, eldv,
  4046. G4X_AUD_CNTL_ST, G4X_ELD_ADDR,
  4047. G4X_HDMIW_HDMIEDID))
  4048. return;
  4049. i = I915_READ(G4X_AUD_CNTL_ST);
  4050. i &= ~(eldv | G4X_ELD_ADDR);
  4051. len = (i >> 9) & 0x1f; /* ELD buffer size */
  4052. I915_WRITE(G4X_AUD_CNTL_ST, i);
  4053. if (!eld[0])
  4054. return;
  4055. len = min_t(uint8_t, eld[2], len);
  4056. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  4057. for (i = 0; i < len; i++)
  4058. I915_WRITE(G4X_HDMIW_HDMIEDID, *((uint32_t *)eld + i));
  4059. i = I915_READ(G4X_AUD_CNTL_ST);
  4060. i |= eldv;
  4061. I915_WRITE(G4X_AUD_CNTL_ST, i);
  4062. }
  4063. static void ironlake_write_eld(struct drm_connector *connector,
  4064. struct drm_crtc *crtc)
  4065. {
  4066. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  4067. uint8_t *eld = connector->eld;
  4068. uint32_t eldv;
  4069. uint32_t i;
  4070. int len;
  4071. int hdmiw_hdmiedid;
  4072. int aud_config;
  4073. int aud_cntl_st;
  4074. int aud_cntrl_st2;
  4075. if (HAS_PCH_IBX(connector->dev)) {
  4076. hdmiw_hdmiedid = IBX_HDMIW_HDMIEDID_A;
  4077. aud_config = IBX_AUD_CONFIG_A;
  4078. aud_cntl_st = IBX_AUD_CNTL_ST_A;
  4079. aud_cntrl_st2 = IBX_AUD_CNTL_ST2;
  4080. } else {
  4081. hdmiw_hdmiedid = CPT_HDMIW_HDMIEDID_A;
  4082. aud_config = CPT_AUD_CONFIG_A;
  4083. aud_cntl_st = CPT_AUD_CNTL_ST_A;
  4084. aud_cntrl_st2 = CPT_AUD_CNTRL_ST2;
  4085. }
  4086. i = to_intel_crtc(crtc)->pipe;
  4087. hdmiw_hdmiedid += i * 0x100;
  4088. aud_cntl_st += i * 0x100;
  4089. aud_config += i * 0x100;
  4090. DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(i));
  4091. i = I915_READ(aud_cntl_st);
  4092. i = (i >> 29) & 0x3; /* DIP_Port_Select, 0x1 = PortB */
  4093. if (!i) {
  4094. DRM_DEBUG_DRIVER("Audio directed to unknown port\n");
  4095. /* operate blindly on all ports */
  4096. eldv = IBX_ELD_VALIDB;
  4097. eldv |= IBX_ELD_VALIDB << 4;
  4098. eldv |= IBX_ELD_VALIDB << 8;
  4099. } else {
  4100. DRM_DEBUG_DRIVER("ELD on port %c\n", 'A' + i);
  4101. eldv = IBX_ELD_VALIDB << ((i - 1) * 4);
  4102. }
  4103. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
  4104. DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
  4105. eld[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
  4106. I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */
  4107. } else
  4108. I915_WRITE(aud_config, 0);
  4109. if (intel_eld_uptodate(connector,
  4110. aud_cntrl_st2, eldv,
  4111. aud_cntl_st, IBX_ELD_ADDRESS,
  4112. hdmiw_hdmiedid))
  4113. return;
  4114. i = I915_READ(aud_cntrl_st2);
  4115. i &= ~eldv;
  4116. I915_WRITE(aud_cntrl_st2, i);
  4117. if (!eld[0])
  4118. return;
  4119. i = I915_READ(aud_cntl_st);
  4120. i &= ~IBX_ELD_ADDRESS;
  4121. I915_WRITE(aud_cntl_st, i);
  4122. len = min_t(uint8_t, eld[2], 21); /* 84 bytes of hw ELD buffer */
  4123. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  4124. for (i = 0; i < len; i++)
  4125. I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i));
  4126. i = I915_READ(aud_cntrl_st2);
  4127. i |= eldv;
  4128. I915_WRITE(aud_cntrl_st2, i);
  4129. }
  4130. void intel_write_eld(struct drm_encoder *encoder,
  4131. struct drm_display_mode *mode)
  4132. {
  4133. struct drm_crtc *crtc = encoder->crtc;
  4134. struct drm_connector *connector;
  4135. struct drm_device *dev = encoder->dev;
  4136. struct drm_i915_private *dev_priv = dev->dev_private;
  4137. connector = drm_select_eld(encoder, mode);
  4138. if (!connector)
  4139. return;
  4140. DRM_DEBUG_DRIVER("ELD on [CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  4141. connector->base.id,
  4142. drm_get_connector_name(connector),
  4143. connector->encoder->base.id,
  4144. drm_get_encoder_name(connector->encoder));
  4145. connector->eld[6] = drm_av_sync_delay(connector, mode) / 2;
  4146. if (dev_priv->display.write_eld)
  4147. dev_priv->display.write_eld(connector, crtc);
  4148. }
  4149. /** Loads the palette/gamma unit for the CRTC with the prepared values */
  4150. void intel_crtc_load_lut(struct drm_crtc *crtc)
  4151. {
  4152. struct drm_device *dev = crtc->dev;
  4153. struct drm_i915_private *dev_priv = dev->dev_private;
  4154. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4155. int palreg = PALETTE(intel_crtc->pipe);
  4156. int i;
  4157. /* The clocks have to be on to load the palette. */
  4158. if (!crtc->enabled || !intel_crtc->active)
  4159. return;
  4160. /* use legacy palette for Ironlake */
  4161. if (HAS_PCH_SPLIT(dev))
  4162. palreg = LGC_PALETTE(intel_crtc->pipe);
  4163. for (i = 0; i < 256; i++) {
  4164. I915_WRITE(palreg + 4 * i,
  4165. (intel_crtc->lut_r[i] << 16) |
  4166. (intel_crtc->lut_g[i] << 8) |
  4167. intel_crtc->lut_b[i]);
  4168. }
  4169. }
  4170. static void i845_update_cursor(struct drm_crtc *crtc, u32 base)
  4171. {
  4172. struct drm_device *dev = crtc->dev;
  4173. struct drm_i915_private *dev_priv = dev->dev_private;
  4174. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4175. bool visible = base != 0;
  4176. u32 cntl;
  4177. if (intel_crtc->cursor_visible == visible)
  4178. return;
  4179. cntl = I915_READ(_CURACNTR);
  4180. if (visible) {
  4181. /* On these chipsets we can only modify the base whilst
  4182. * the cursor is disabled.
  4183. */
  4184. I915_WRITE(_CURABASE, base);
  4185. cntl &= ~(CURSOR_FORMAT_MASK);
  4186. /* XXX width must be 64, stride 256 => 0x00 << 28 */
  4187. cntl |= CURSOR_ENABLE |
  4188. CURSOR_GAMMA_ENABLE |
  4189. CURSOR_FORMAT_ARGB;
  4190. } else
  4191. cntl &= ~(CURSOR_ENABLE | CURSOR_GAMMA_ENABLE);
  4192. I915_WRITE(_CURACNTR, cntl);
  4193. intel_crtc->cursor_visible = visible;
  4194. }
  4195. static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base)
  4196. {
  4197. struct drm_device *dev = crtc->dev;
  4198. struct drm_i915_private *dev_priv = dev->dev_private;
  4199. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4200. int pipe = intel_crtc->pipe;
  4201. bool visible = base != 0;
  4202. if (intel_crtc->cursor_visible != visible) {
  4203. uint32_t cntl = I915_READ(CURCNTR(pipe));
  4204. if (base) {
  4205. cntl &= ~(CURSOR_MODE | MCURSOR_PIPE_SELECT);
  4206. cntl |= CURSOR_MODE_64_ARGB_AX | MCURSOR_GAMMA_ENABLE;
  4207. cntl |= pipe << 28; /* Connect to correct pipe */
  4208. } else {
  4209. cntl &= ~(CURSOR_MODE | MCURSOR_GAMMA_ENABLE);
  4210. cntl |= CURSOR_MODE_DISABLE;
  4211. }
  4212. I915_WRITE(CURCNTR(pipe), cntl);
  4213. intel_crtc->cursor_visible = visible;
  4214. }
  4215. /* and commit changes on next vblank */
  4216. I915_WRITE(CURBASE(pipe), base);
  4217. }
  4218. static void ivb_update_cursor(struct drm_crtc *crtc, u32 base)
  4219. {
  4220. struct drm_device *dev = crtc->dev;
  4221. struct drm_i915_private *dev_priv = dev->dev_private;
  4222. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4223. int pipe = intel_crtc->pipe;
  4224. bool visible = base != 0;
  4225. if (intel_crtc->cursor_visible != visible) {
  4226. uint32_t cntl = I915_READ(CURCNTR_IVB(pipe));
  4227. if (base) {
  4228. cntl &= ~CURSOR_MODE;
  4229. cntl |= CURSOR_MODE_64_ARGB_AX | MCURSOR_GAMMA_ENABLE;
  4230. } else {
  4231. cntl &= ~(CURSOR_MODE | MCURSOR_GAMMA_ENABLE);
  4232. cntl |= CURSOR_MODE_DISABLE;
  4233. }
  4234. I915_WRITE(CURCNTR_IVB(pipe), cntl);
  4235. intel_crtc->cursor_visible = visible;
  4236. }
  4237. /* and commit changes on next vblank */
  4238. I915_WRITE(CURBASE_IVB(pipe), base);
  4239. }
  4240. /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */
  4241. static void intel_crtc_update_cursor(struct drm_crtc *crtc,
  4242. bool on)
  4243. {
  4244. struct drm_device *dev = crtc->dev;
  4245. struct drm_i915_private *dev_priv = dev->dev_private;
  4246. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4247. int pipe = intel_crtc->pipe;
  4248. int x = intel_crtc->cursor_x;
  4249. int y = intel_crtc->cursor_y;
  4250. u32 base, pos;
  4251. bool visible;
  4252. pos = 0;
  4253. if (on && crtc->enabled && crtc->fb) {
  4254. base = intel_crtc->cursor_addr;
  4255. if (x > (int) crtc->fb->width)
  4256. base = 0;
  4257. if (y > (int) crtc->fb->height)
  4258. base = 0;
  4259. } else
  4260. base = 0;
  4261. if (x < 0) {
  4262. if (x + intel_crtc->cursor_width < 0)
  4263. base = 0;
  4264. pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
  4265. x = -x;
  4266. }
  4267. pos |= x << CURSOR_X_SHIFT;
  4268. if (y < 0) {
  4269. if (y + intel_crtc->cursor_height < 0)
  4270. base = 0;
  4271. pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
  4272. y = -y;
  4273. }
  4274. pos |= y << CURSOR_Y_SHIFT;
  4275. visible = base != 0;
  4276. if (!visible && !intel_crtc->cursor_visible)
  4277. return;
  4278. if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) {
  4279. I915_WRITE(CURPOS_IVB(pipe), pos);
  4280. ivb_update_cursor(crtc, base);
  4281. } else {
  4282. I915_WRITE(CURPOS(pipe), pos);
  4283. if (IS_845G(dev) || IS_I865G(dev))
  4284. i845_update_cursor(crtc, base);
  4285. else
  4286. i9xx_update_cursor(crtc, base);
  4287. }
  4288. }
  4289. static int intel_crtc_cursor_set(struct drm_crtc *crtc,
  4290. struct drm_file *file,
  4291. uint32_t handle,
  4292. uint32_t width, uint32_t height)
  4293. {
  4294. struct drm_device *dev = crtc->dev;
  4295. struct drm_i915_private *dev_priv = dev->dev_private;
  4296. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4297. struct drm_i915_gem_object *obj;
  4298. uint32_t addr;
  4299. int ret;
  4300. DRM_DEBUG_KMS("\n");
  4301. /* if we want to turn off the cursor ignore width and height */
  4302. if (!handle) {
  4303. DRM_DEBUG_KMS("cursor off\n");
  4304. addr = 0;
  4305. obj = NULL;
  4306. mutex_lock(&dev->struct_mutex);
  4307. goto finish;
  4308. }
  4309. /* Currently we only support 64x64 cursors */
  4310. if (width != 64 || height != 64) {
  4311. DRM_ERROR("we currently only support 64x64 cursors\n");
  4312. return -EINVAL;
  4313. }
  4314. obj = to_intel_bo(drm_gem_object_lookup(dev, file, handle));
  4315. if (&obj->base == NULL)
  4316. return -ENOENT;
  4317. if (obj->base.size < width * height * 4) {
  4318. DRM_ERROR("buffer is to small\n");
  4319. ret = -ENOMEM;
  4320. goto fail;
  4321. }
  4322. /* we only need to pin inside GTT if cursor is non-phy */
  4323. mutex_lock(&dev->struct_mutex);
  4324. if (!dev_priv->info->cursor_needs_physical) {
  4325. if (obj->tiling_mode) {
  4326. DRM_ERROR("cursor cannot be tiled\n");
  4327. ret = -EINVAL;
  4328. goto fail_locked;
  4329. }
  4330. ret = i915_gem_object_pin_to_display_plane(obj, 0, NULL);
  4331. if (ret) {
  4332. DRM_ERROR("failed to move cursor bo into the GTT\n");
  4333. goto fail_locked;
  4334. }
  4335. ret = i915_gem_object_put_fence(obj);
  4336. if (ret) {
  4337. DRM_ERROR("failed to release fence for cursor");
  4338. goto fail_unpin;
  4339. }
  4340. addr = obj->gtt_offset;
  4341. } else {
  4342. int align = IS_I830(dev) ? 16 * 1024 : 256;
  4343. ret = i915_gem_attach_phys_object(dev, obj,
  4344. (intel_crtc->pipe == 0) ? I915_GEM_PHYS_CURSOR_0 : I915_GEM_PHYS_CURSOR_1,
  4345. align);
  4346. if (ret) {
  4347. DRM_ERROR("failed to attach phys object\n");
  4348. goto fail_locked;
  4349. }
  4350. addr = obj->phys_obj->handle->busaddr;
  4351. }
  4352. if (IS_GEN2(dev))
  4353. I915_WRITE(CURSIZE, (height << 12) | width);
  4354. finish:
  4355. if (intel_crtc->cursor_bo) {
  4356. if (dev_priv->info->cursor_needs_physical) {
  4357. if (intel_crtc->cursor_bo != obj)
  4358. i915_gem_detach_phys_object(dev, intel_crtc->cursor_bo);
  4359. } else
  4360. i915_gem_object_unpin(intel_crtc->cursor_bo);
  4361. drm_gem_object_unreference(&intel_crtc->cursor_bo->base);
  4362. }
  4363. mutex_unlock(&dev->struct_mutex);
  4364. intel_crtc->cursor_addr = addr;
  4365. intel_crtc->cursor_bo = obj;
  4366. intel_crtc->cursor_width = width;
  4367. intel_crtc->cursor_height = height;
  4368. intel_crtc_update_cursor(crtc, true);
  4369. return 0;
  4370. fail_unpin:
  4371. i915_gem_object_unpin(obj);
  4372. fail_locked:
  4373. mutex_unlock(&dev->struct_mutex);
  4374. fail:
  4375. drm_gem_object_unreference_unlocked(&obj->base);
  4376. return ret;
  4377. }
  4378. static int intel_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
  4379. {
  4380. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4381. intel_crtc->cursor_x = x;
  4382. intel_crtc->cursor_y = y;
  4383. intel_crtc_update_cursor(crtc, true);
  4384. return 0;
  4385. }
  4386. /** Sets the color ramps on behalf of RandR */
  4387. void intel_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
  4388. u16 blue, int regno)
  4389. {
  4390. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4391. intel_crtc->lut_r[regno] = red >> 8;
  4392. intel_crtc->lut_g[regno] = green >> 8;
  4393. intel_crtc->lut_b[regno] = blue >> 8;
  4394. }
  4395. void intel_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green,
  4396. u16 *blue, int regno)
  4397. {
  4398. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4399. *red = intel_crtc->lut_r[regno] << 8;
  4400. *green = intel_crtc->lut_g[regno] << 8;
  4401. *blue = intel_crtc->lut_b[regno] << 8;
  4402. }
  4403. static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
  4404. u16 *blue, uint32_t start, uint32_t size)
  4405. {
  4406. int end = (start + size > 256) ? 256 : start + size, i;
  4407. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4408. for (i = start; i < end; i++) {
  4409. intel_crtc->lut_r[i] = red[i] >> 8;
  4410. intel_crtc->lut_g[i] = green[i] >> 8;
  4411. intel_crtc->lut_b[i] = blue[i] >> 8;
  4412. }
  4413. intel_crtc_load_lut(crtc);
  4414. }
  4415. /**
  4416. * Get a pipe with a simple mode set on it for doing load-based monitor
  4417. * detection.
  4418. *
  4419. * It will be up to the load-detect code to adjust the pipe as appropriate for
  4420. * its requirements. The pipe will be connected to no other encoders.
  4421. *
  4422. * Currently this code will only succeed if there is a pipe with no encoders
  4423. * configured for it. In the future, it could choose to temporarily disable
  4424. * some outputs to free up a pipe for its use.
  4425. *
  4426. * \return crtc, or NULL if no pipes are available.
  4427. */
  4428. /* VESA 640x480x72Hz mode to set on the pipe */
  4429. static struct drm_display_mode load_detect_mode = {
  4430. DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
  4431. 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  4432. };
  4433. static struct drm_framebuffer *
  4434. intel_framebuffer_create(struct drm_device *dev,
  4435. struct drm_mode_fb_cmd2 *mode_cmd,
  4436. struct drm_i915_gem_object *obj)
  4437. {
  4438. struct intel_framebuffer *intel_fb;
  4439. int ret;
  4440. intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
  4441. if (!intel_fb) {
  4442. drm_gem_object_unreference_unlocked(&obj->base);
  4443. return ERR_PTR(-ENOMEM);
  4444. }
  4445. ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj);
  4446. if (ret) {
  4447. drm_gem_object_unreference_unlocked(&obj->base);
  4448. kfree(intel_fb);
  4449. return ERR_PTR(ret);
  4450. }
  4451. return &intel_fb->base;
  4452. }
  4453. static u32
  4454. intel_framebuffer_pitch_for_width(int width, int bpp)
  4455. {
  4456. u32 pitch = DIV_ROUND_UP(width * bpp, 8);
  4457. return ALIGN(pitch, 64);
  4458. }
  4459. static u32
  4460. intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp)
  4461. {
  4462. u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp);
  4463. return ALIGN(pitch * mode->vdisplay, PAGE_SIZE);
  4464. }
  4465. static struct drm_framebuffer *
  4466. intel_framebuffer_create_for_mode(struct drm_device *dev,
  4467. struct drm_display_mode *mode,
  4468. int depth, int bpp)
  4469. {
  4470. struct drm_i915_gem_object *obj;
  4471. struct drm_mode_fb_cmd2 mode_cmd;
  4472. obj = i915_gem_alloc_object(dev,
  4473. intel_framebuffer_size_for_mode(mode, bpp));
  4474. if (obj == NULL)
  4475. return ERR_PTR(-ENOMEM);
  4476. mode_cmd.width = mode->hdisplay;
  4477. mode_cmd.height = mode->vdisplay;
  4478. mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width,
  4479. bpp);
  4480. mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth);
  4481. return intel_framebuffer_create(dev, &mode_cmd, obj);
  4482. }
  4483. static struct drm_framebuffer *
  4484. mode_fits_in_fbdev(struct drm_device *dev,
  4485. struct drm_display_mode *mode)
  4486. {
  4487. struct drm_i915_private *dev_priv = dev->dev_private;
  4488. struct drm_i915_gem_object *obj;
  4489. struct drm_framebuffer *fb;
  4490. if (dev_priv->fbdev == NULL)
  4491. return NULL;
  4492. obj = dev_priv->fbdev->ifb.obj;
  4493. if (obj == NULL)
  4494. return NULL;
  4495. fb = &dev_priv->fbdev->ifb.base;
  4496. if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay,
  4497. fb->bits_per_pixel))
  4498. return NULL;
  4499. if (obj->base.size < mode->vdisplay * fb->pitches[0])
  4500. return NULL;
  4501. return fb;
  4502. }
  4503. bool intel_get_load_detect_pipe(struct intel_encoder *intel_encoder,
  4504. struct drm_connector *connector,
  4505. struct drm_display_mode *mode,
  4506. struct intel_load_detect_pipe *old)
  4507. {
  4508. struct intel_crtc *intel_crtc;
  4509. struct drm_crtc *possible_crtc;
  4510. struct drm_encoder *encoder = &intel_encoder->base;
  4511. struct drm_crtc *crtc = NULL;
  4512. struct drm_device *dev = encoder->dev;
  4513. struct drm_framebuffer *old_fb;
  4514. int i = -1;
  4515. DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  4516. connector->base.id, drm_get_connector_name(connector),
  4517. encoder->base.id, drm_get_encoder_name(encoder));
  4518. /*
  4519. * Algorithm gets a little messy:
  4520. *
  4521. * - if the connector already has an assigned crtc, use it (but make
  4522. * sure it's on first)
  4523. *
  4524. * - try to find the first unused crtc that can drive this connector,
  4525. * and use that if we find one
  4526. */
  4527. /* See if we already have a CRTC for this connector */
  4528. if (encoder->crtc) {
  4529. crtc = encoder->crtc;
  4530. intel_crtc = to_intel_crtc(crtc);
  4531. old->dpms_mode = intel_crtc->dpms_mode;
  4532. old->load_detect_temp = false;
  4533. /* Make sure the crtc and connector are running */
  4534. if (intel_crtc->dpms_mode != DRM_MODE_DPMS_ON) {
  4535. struct drm_encoder_helper_funcs *encoder_funcs;
  4536. struct drm_crtc_helper_funcs *crtc_funcs;
  4537. crtc_funcs = crtc->helper_private;
  4538. crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON);
  4539. encoder_funcs = encoder->helper_private;
  4540. encoder_funcs->dpms(encoder, DRM_MODE_DPMS_ON);
  4541. }
  4542. return true;
  4543. }
  4544. /* Find an unused one (if possible) */
  4545. list_for_each_entry(possible_crtc, &dev->mode_config.crtc_list, head) {
  4546. i++;
  4547. if (!(encoder->possible_crtcs & (1 << i)))
  4548. continue;
  4549. if (!possible_crtc->enabled) {
  4550. crtc = possible_crtc;
  4551. break;
  4552. }
  4553. }
  4554. /*
  4555. * If we didn't find an unused CRTC, don't use any.
  4556. */
  4557. if (!crtc) {
  4558. DRM_DEBUG_KMS("no pipe available for load-detect\n");
  4559. return false;
  4560. }
  4561. encoder->crtc = crtc;
  4562. connector->encoder = encoder;
  4563. intel_crtc = to_intel_crtc(crtc);
  4564. old->dpms_mode = intel_crtc->dpms_mode;
  4565. old->load_detect_temp = true;
  4566. old->release_fb = NULL;
  4567. if (!mode)
  4568. mode = &load_detect_mode;
  4569. old_fb = crtc->fb;
  4570. /* We need a framebuffer large enough to accommodate all accesses
  4571. * that the plane may generate whilst we perform load detection.
  4572. * We can not rely on the fbcon either being present (we get called
  4573. * during its initialisation to detect all boot displays, or it may
  4574. * not even exist) or that it is large enough to satisfy the
  4575. * requested mode.
  4576. */
  4577. crtc->fb = mode_fits_in_fbdev(dev, mode);
  4578. if (crtc->fb == NULL) {
  4579. DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
  4580. crtc->fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32);
  4581. old->release_fb = crtc->fb;
  4582. } else
  4583. DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
  4584. if (IS_ERR(crtc->fb)) {
  4585. DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
  4586. crtc->fb = old_fb;
  4587. return false;
  4588. }
  4589. if (!drm_crtc_helper_set_mode(crtc, mode, 0, 0, old_fb)) {
  4590. DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
  4591. if (old->release_fb)
  4592. old->release_fb->funcs->destroy(old->release_fb);
  4593. crtc->fb = old_fb;
  4594. return false;
  4595. }
  4596. /* let the connector get through one full cycle before testing */
  4597. intel_wait_for_vblank(dev, intel_crtc->pipe);
  4598. return true;
  4599. }
  4600. void intel_release_load_detect_pipe(struct intel_encoder *intel_encoder,
  4601. struct drm_connector *connector,
  4602. struct intel_load_detect_pipe *old)
  4603. {
  4604. struct drm_encoder *encoder = &intel_encoder->base;
  4605. struct drm_device *dev = encoder->dev;
  4606. struct drm_crtc *crtc = encoder->crtc;
  4607. struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
  4608. struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
  4609. DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  4610. connector->base.id, drm_get_connector_name(connector),
  4611. encoder->base.id, drm_get_encoder_name(encoder));
  4612. if (old->load_detect_temp) {
  4613. connector->encoder = NULL;
  4614. drm_helper_disable_unused_functions(dev);
  4615. if (old->release_fb)
  4616. old->release_fb->funcs->destroy(old->release_fb);
  4617. return;
  4618. }
  4619. /* Switch crtc and encoder back off if necessary */
  4620. if (old->dpms_mode != DRM_MODE_DPMS_ON) {
  4621. encoder_funcs->dpms(encoder, old->dpms_mode);
  4622. crtc_funcs->dpms(crtc, old->dpms_mode);
  4623. }
  4624. }
  4625. /* Returns the clock of the currently programmed mode of the given pipe. */
  4626. static int intel_crtc_clock_get(struct drm_device *dev, struct drm_crtc *crtc)
  4627. {
  4628. struct drm_i915_private *dev_priv = dev->dev_private;
  4629. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4630. int pipe = intel_crtc->pipe;
  4631. u32 dpll = I915_READ(DPLL(pipe));
  4632. u32 fp;
  4633. intel_clock_t clock;
  4634. if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
  4635. fp = I915_READ(FP0(pipe));
  4636. else
  4637. fp = I915_READ(FP1(pipe));
  4638. clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
  4639. if (IS_PINEVIEW(dev)) {
  4640. clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
  4641. clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
  4642. } else {
  4643. clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
  4644. clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
  4645. }
  4646. if (!IS_GEN2(dev)) {
  4647. if (IS_PINEVIEW(dev))
  4648. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
  4649. DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
  4650. else
  4651. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
  4652. DPLL_FPA01_P1_POST_DIV_SHIFT);
  4653. switch (dpll & DPLL_MODE_MASK) {
  4654. case DPLLB_MODE_DAC_SERIAL:
  4655. clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
  4656. 5 : 10;
  4657. break;
  4658. case DPLLB_MODE_LVDS:
  4659. clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
  4660. 7 : 14;
  4661. break;
  4662. default:
  4663. DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
  4664. "mode\n", (int)(dpll & DPLL_MODE_MASK));
  4665. return 0;
  4666. }
  4667. /* XXX: Handle the 100Mhz refclk */
  4668. intel_clock(dev, 96000, &clock);
  4669. } else {
  4670. bool is_lvds = (pipe == 1) && (I915_READ(LVDS) & LVDS_PORT_EN);
  4671. if (is_lvds) {
  4672. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
  4673. DPLL_FPA01_P1_POST_DIV_SHIFT);
  4674. clock.p2 = 14;
  4675. if ((dpll & PLL_REF_INPUT_MASK) ==
  4676. PLLB_REF_INPUT_SPREADSPECTRUMIN) {
  4677. /* XXX: might not be 66MHz */
  4678. intel_clock(dev, 66000, &clock);
  4679. } else
  4680. intel_clock(dev, 48000, &clock);
  4681. } else {
  4682. if (dpll & PLL_P1_DIVIDE_BY_TWO)
  4683. clock.p1 = 2;
  4684. else {
  4685. clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
  4686. DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
  4687. }
  4688. if (dpll & PLL_P2_DIVIDE_BY_4)
  4689. clock.p2 = 4;
  4690. else
  4691. clock.p2 = 2;
  4692. intel_clock(dev, 48000, &clock);
  4693. }
  4694. }
  4695. /* XXX: It would be nice to validate the clocks, but we can't reuse
  4696. * i830PllIsValid() because it relies on the xf86_config connector
  4697. * configuration being accurate, which it isn't necessarily.
  4698. */
  4699. return clock.dot;
  4700. }
  4701. /** Returns the currently programmed mode of the given pipe. */
  4702. struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
  4703. struct drm_crtc *crtc)
  4704. {
  4705. struct drm_i915_private *dev_priv = dev->dev_private;
  4706. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4707. int pipe = intel_crtc->pipe;
  4708. struct drm_display_mode *mode;
  4709. int htot = I915_READ(HTOTAL(pipe));
  4710. int hsync = I915_READ(HSYNC(pipe));
  4711. int vtot = I915_READ(VTOTAL(pipe));
  4712. int vsync = I915_READ(VSYNC(pipe));
  4713. mode = kzalloc(sizeof(*mode), GFP_KERNEL);
  4714. if (!mode)
  4715. return NULL;
  4716. mode->clock = intel_crtc_clock_get(dev, crtc);
  4717. mode->hdisplay = (htot & 0xffff) + 1;
  4718. mode->htotal = ((htot & 0xffff0000) >> 16) + 1;
  4719. mode->hsync_start = (hsync & 0xffff) + 1;
  4720. mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1;
  4721. mode->vdisplay = (vtot & 0xffff) + 1;
  4722. mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1;
  4723. mode->vsync_start = (vsync & 0xffff) + 1;
  4724. mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1;
  4725. drm_mode_set_name(mode);
  4726. return mode;
  4727. }
  4728. #define GPU_IDLE_TIMEOUT 500 /* ms */
  4729. /* When this timer fires, we've been idle for awhile */
  4730. static void intel_gpu_idle_timer(unsigned long arg)
  4731. {
  4732. struct drm_device *dev = (struct drm_device *)arg;
  4733. drm_i915_private_t *dev_priv = dev->dev_private;
  4734. if (!list_empty(&dev_priv->mm.active_list)) {
  4735. /* Still processing requests, so just re-arm the timer. */
  4736. mod_timer(&dev_priv->idle_timer, jiffies +
  4737. msecs_to_jiffies(GPU_IDLE_TIMEOUT));
  4738. return;
  4739. }
  4740. dev_priv->busy = false;
  4741. queue_work(dev_priv->wq, &dev_priv->idle_work);
  4742. }
  4743. #define CRTC_IDLE_TIMEOUT 1000 /* ms */
  4744. static void intel_crtc_idle_timer(unsigned long arg)
  4745. {
  4746. struct intel_crtc *intel_crtc = (struct intel_crtc *)arg;
  4747. struct drm_crtc *crtc = &intel_crtc->base;
  4748. drm_i915_private_t *dev_priv = crtc->dev->dev_private;
  4749. struct intel_framebuffer *intel_fb;
  4750. intel_fb = to_intel_framebuffer(crtc->fb);
  4751. if (intel_fb && intel_fb->obj->active) {
  4752. /* The framebuffer is still being accessed by the GPU. */
  4753. mod_timer(&intel_crtc->idle_timer, jiffies +
  4754. msecs_to_jiffies(CRTC_IDLE_TIMEOUT));
  4755. return;
  4756. }
  4757. intel_crtc->busy = false;
  4758. queue_work(dev_priv->wq, &dev_priv->idle_work);
  4759. }
  4760. static void intel_increase_pllclock(struct drm_crtc *crtc)
  4761. {
  4762. struct drm_device *dev = crtc->dev;
  4763. drm_i915_private_t *dev_priv = dev->dev_private;
  4764. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4765. int pipe = intel_crtc->pipe;
  4766. int dpll_reg = DPLL(pipe);
  4767. int dpll;
  4768. if (HAS_PCH_SPLIT(dev))
  4769. return;
  4770. if (!dev_priv->lvds_downclock_avail)
  4771. return;
  4772. dpll = I915_READ(dpll_reg);
  4773. if (!HAS_PIPE_CXSR(dev) && (dpll & DISPLAY_RATE_SELECT_FPA1)) {
  4774. DRM_DEBUG_DRIVER("upclocking LVDS\n");
  4775. assert_panel_unlocked(dev_priv, pipe);
  4776. dpll &= ~DISPLAY_RATE_SELECT_FPA1;
  4777. I915_WRITE(dpll_reg, dpll);
  4778. intel_wait_for_vblank(dev, pipe);
  4779. dpll = I915_READ(dpll_reg);
  4780. if (dpll & DISPLAY_RATE_SELECT_FPA1)
  4781. DRM_DEBUG_DRIVER("failed to upclock LVDS!\n");
  4782. }
  4783. /* Schedule downclock */
  4784. mod_timer(&intel_crtc->idle_timer, jiffies +
  4785. msecs_to_jiffies(CRTC_IDLE_TIMEOUT));
  4786. }
  4787. static void intel_decrease_pllclock(struct drm_crtc *crtc)
  4788. {
  4789. struct drm_device *dev = crtc->dev;
  4790. drm_i915_private_t *dev_priv = dev->dev_private;
  4791. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4792. if (HAS_PCH_SPLIT(dev))
  4793. return;
  4794. if (!dev_priv->lvds_downclock_avail)
  4795. return;
  4796. /*
  4797. * Since this is called by a timer, we should never get here in
  4798. * the manual case.
  4799. */
  4800. if (!HAS_PIPE_CXSR(dev) && intel_crtc->lowfreq_avail) {
  4801. int pipe = intel_crtc->pipe;
  4802. int dpll_reg = DPLL(pipe);
  4803. int dpll;
  4804. DRM_DEBUG_DRIVER("downclocking LVDS\n");
  4805. assert_panel_unlocked(dev_priv, pipe);
  4806. dpll = I915_READ(dpll_reg);
  4807. dpll |= DISPLAY_RATE_SELECT_FPA1;
  4808. I915_WRITE(dpll_reg, dpll);
  4809. intel_wait_for_vblank(dev, pipe);
  4810. dpll = I915_READ(dpll_reg);
  4811. if (!(dpll & DISPLAY_RATE_SELECT_FPA1))
  4812. DRM_DEBUG_DRIVER("failed to downclock LVDS!\n");
  4813. }
  4814. }
  4815. /**
  4816. * intel_idle_update - adjust clocks for idleness
  4817. * @work: work struct
  4818. *
  4819. * Either the GPU or display (or both) went idle. Check the busy status
  4820. * here and adjust the CRTC and GPU clocks as necessary.
  4821. */
  4822. static void intel_idle_update(struct work_struct *work)
  4823. {
  4824. drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
  4825. idle_work);
  4826. struct drm_device *dev = dev_priv->dev;
  4827. struct drm_crtc *crtc;
  4828. struct intel_crtc *intel_crtc;
  4829. if (!i915_powersave)
  4830. return;
  4831. mutex_lock(&dev->struct_mutex);
  4832. i915_update_gfx_val(dev_priv);
  4833. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  4834. /* Skip inactive CRTCs */
  4835. if (!crtc->fb)
  4836. continue;
  4837. intel_crtc = to_intel_crtc(crtc);
  4838. if (!intel_crtc->busy)
  4839. intel_decrease_pllclock(crtc);
  4840. }
  4841. mutex_unlock(&dev->struct_mutex);
  4842. }
  4843. /**
  4844. * intel_mark_busy - mark the GPU and possibly the display busy
  4845. * @dev: drm device
  4846. * @obj: object we're operating on
  4847. *
  4848. * Callers can use this function to indicate that the GPU is busy processing
  4849. * commands. If @obj matches one of the CRTC objects (i.e. it's a scanout
  4850. * buffer), we'll also mark the display as busy, so we know to increase its
  4851. * clock frequency.
  4852. */
  4853. void intel_mark_busy(struct drm_device *dev, struct drm_i915_gem_object *obj)
  4854. {
  4855. drm_i915_private_t *dev_priv = dev->dev_private;
  4856. struct drm_crtc *crtc = NULL;
  4857. struct intel_framebuffer *intel_fb;
  4858. struct intel_crtc *intel_crtc;
  4859. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  4860. return;
  4861. if (!dev_priv->busy) {
  4862. intel_sanitize_pm(dev);
  4863. dev_priv->busy = true;
  4864. } else
  4865. mod_timer(&dev_priv->idle_timer, jiffies +
  4866. msecs_to_jiffies(GPU_IDLE_TIMEOUT));
  4867. if (obj == NULL)
  4868. return;
  4869. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  4870. if (!crtc->fb)
  4871. continue;
  4872. intel_crtc = to_intel_crtc(crtc);
  4873. intel_fb = to_intel_framebuffer(crtc->fb);
  4874. if (intel_fb->obj == obj) {
  4875. if (!intel_crtc->busy) {
  4876. /* Non-busy -> busy, upclock */
  4877. intel_increase_pllclock(crtc);
  4878. intel_crtc->busy = true;
  4879. } else {
  4880. /* Busy -> busy, put off timer */
  4881. mod_timer(&intel_crtc->idle_timer, jiffies +
  4882. msecs_to_jiffies(CRTC_IDLE_TIMEOUT));
  4883. }
  4884. }
  4885. }
  4886. }
  4887. static void intel_crtc_destroy(struct drm_crtc *crtc)
  4888. {
  4889. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4890. struct drm_device *dev = crtc->dev;
  4891. struct intel_unpin_work *work;
  4892. unsigned long flags;
  4893. spin_lock_irqsave(&dev->event_lock, flags);
  4894. work = intel_crtc->unpin_work;
  4895. intel_crtc->unpin_work = NULL;
  4896. spin_unlock_irqrestore(&dev->event_lock, flags);
  4897. if (work) {
  4898. cancel_work_sync(&work->work);
  4899. kfree(work);
  4900. }
  4901. drm_crtc_cleanup(crtc);
  4902. kfree(intel_crtc);
  4903. }
  4904. static void intel_unpin_work_fn(struct work_struct *__work)
  4905. {
  4906. struct intel_unpin_work *work =
  4907. container_of(__work, struct intel_unpin_work, work);
  4908. mutex_lock(&work->dev->struct_mutex);
  4909. intel_unpin_fb_obj(work->old_fb_obj);
  4910. drm_gem_object_unreference(&work->pending_flip_obj->base);
  4911. drm_gem_object_unreference(&work->old_fb_obj->base);
  4912. intel_update_fbc(work->dev);
  4913. mutex_unlock(&work->dev->struct_mutex);
  4914. kfree(work);
  4915. }
  4916. static void do_intel_finish_page_flip(struct drm_device *dev,
  4917. struct drm_crtc *crtc)
  4918. {
  4919. drm_i915_private_t *dev_priv = dev->dev_private;
  4920. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4921. struct intel_unpin_work *work;
  4922. struct drm_i915_gem_object *obj;
  4923. struct drm_pending_vblank_event *e;
  4924. struct timeval tnow, tvbl;
  4925. unsigned long flags;
  4926. /* Ignore early vblank irqs */
  4927. if (intel_crtc == NULL)
  4928. return;
  4929. do_gettimeofday(&tnow);
  4930. spin_lock_irqsave(&dev->event_lock, flags);
  4931. work = intel_crtc->unpin_work;
  4932. if (work == NULL || !work->pending) {
  4933. spin_unlock_irqrestore(&dev->event_lock, flags);
  4934. return;
  4935. }
  4936. intel_crtc->unpin_work = NULL;
  4937. if (work->event) {
  4938. e = work->event;
  4939. e->event.sequence = drm_vblank_count_and_time(dev, intel_crtc->pipe, &tvbl);
  4940. /* Called before vblank count and timestamps have
  4941. * been updated for the vblank interval of flip
  4942. * completion? Need to increment vblank count and
  4943. * add one videorefresh duration to returned timestamp
  4944. * to account for this. We assume this happened if we
  4945. * get called over 0.9 frame durations after the last
  4946. * timestamped vblank.
  4947. *
  4948. * This calculation can not be used with vrefresh rates
  4949. * below 5Hz (10Hz to be on the safe side) without
  4950. * promoting to 64 integers.
  4951. */
  4952. if (10 * (timeval_to_ns(&tnow) - timeval_to_ns(&tvbl)) >
  4953. 9 * crtc->framedur_ns) {
  4954. e->event.sequence++;
  4955. tvbl = ns_to_timeval(timeval_to_ns(&tvbl) +
  4956. crtc->framedur_ns);
  4957. }
  4958. e->event.tv_sec = tvbl.tv_sec;
  4959. e->event.tv_usec = tvbl.tv_usec;
  4960. list_add_tail(&e->base.link,
  4961. &e->base.file_priv->event_list);
  4962. wake_up_interruptible(&e->base.file_priv->event_wait);
  4963. }
  4964. drm_vblank_put(dev, intel_crtc->pipe);
  4965. spin_unlock_irqrestore(&dev->event_lock, flags);
  4966. obj = work->old_fb_obj;
  4967. atomic_clear_mask(1 << intel_crtc->plane,
  4968. &obj->pending_flip.counter);
  4969. if (atomic_read(&obj->pending_flip) == 0)
  4970. wake_up(&dev_priv->pending_flip_queue);
  4971. schedule_work(&work->work);
  4972. trace_i915_flip_complete(intel_crtc->plane, work->pending_flip_obj);
  4973. }
  4974. void intel_finish_page_flip(struct drm_device *dev, int pipe)
  4975. {
  4976. drm_i915_private_t *dev_priv = dev->dev_private;
  4977. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  4978. do_intel_finish_page_flip(dev, crtc);
  4979. }
  4980. void intel_finish_page_flip_plane(struct drm_device *dev, int plane)
  4981. {
  4982. drm_i915_private_t *dev_priv = dev->dev_private;
  4983. struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane];
  4984. do_intel_finish_page_flip(dev, crtc);
  4985. }
  4986. void intel_prepare_page_flip(struct drm_device *dev, int plane)
  4987. {
  4988. drm_i915_private_t *dev_priv = dev->dev_private;
  4989. struct intel_crtc *intel_crtc =
  4990. to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]);
  4991. unsigned long flags;
  4992. spin_lock_irqsave(&dev->event_lock, flags);
  4993. if (intel_crtc->unpin_work) {
  4994. if ((++intel_crtc->unpin_work->pending) > 1)
  4995. DRM_ERROR("Prepared flip multiple times\n");
  4996. } else {
  4997. DRM_DEBUG_DRIVER("preparing flip with no unpin work?\n");
  4998. }
  4999. spin_unlock_irqrestore(&dev->event_lock, flags);
  5000. }
  5001. static int intel_gen2_queue_flip(struct drm_device *dev,
  5002. struct drm_crtc *crtc,
  5003. struct drm_framebuffer *fb,
  5004. struct drm_i915_gem_object *obj)
  5005. {
  5006. struct drm_i915_private *dev_priv = dev->dev_private;
  5007. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5008. unsigned long offset;
  5009. u32 flip_mask;
  5010. struct intel_ring_buffer *ring = &dev_priv->ring[RCS];
  5011. int ret;
  5012. ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
  5013. if (ret)
  5014. goto err;
  5015. /* Offset into the new buffer for cases of shared fbs between CRTCs */
  5016. offset = crtc->y * fb->pitches[0] + crtc->x * fb->bits_per_pixel/8;
  5017. ret = intel_ring_begin(ring, 6);
  5018. if (ret)
  5019. goto err_unpin;
  5020. /* Can't queue multiple flips, so wait for the previous
  5021. * one to finish before executing the next.
  5022. */
  5023. if (intel_crtc->plane)
  5024. flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
  5025. else
  5026. flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
  5027. intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask);
  5028. intel_ring_emit(ring, MI_NOOP);
  5029. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  5030. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  5031. intel_ring_emit(ring, fb->pitches[0]);
  5032. intel_ring_emit(ring, obj->gtt_offset + offset);
  5033. intel_ring_emit(ring, 0); /* aux display base address, unused */
  5034. intel_ring_advance(ring);
  5035. return 0;
  5036. err_unpin:
  5037. intel_unpin_fb_obj(obj);
  5038. err:
  5039. return ret;
  5040. }
  5041. static int intel_gen3_queue_flip(struct drm_device *dev,
  5042. struct drm_crtc *crtc,
  5043. struct drm_framebuffer *fb,
  5044. struct drm_i915_gem_object *obj)
  5045. {
  5046. struct drm_i915_private *dev_priv = dev->dev_private;
  5047. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5048. unsigned long offset;
  5049. u32 flip_mask;
  5050. struct intel_ring_buffer *ring = &dev_priv->ring[RCS];
  5051. int ret;
  5052. ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
  5053. if (ret)
  5054. goto err;
  5055. /* Offset into the new buffer for cases of shared fbs between CRTCs */
  5056. offset = crtc->y * fb->pitches[0] + crtc->x * fb->bits_per_pixel/8;
  5057. ret = intel_ring_begin(ring, 6);
  5058. if (ret)
  5059. goto err_unpin;
  5060. if (intel_crtc->plane)
  5061. flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
  5062. else
  5063. flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
  5064. intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask);
  5065. intel_ring_emit(ring, MI_NOOP);
  5066. intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 |
  5067. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  5068. intel_ring_emit(ring, fb->pitches[0]);
  5069. intel_ring_emit(ring, obj->gtt_offset + offset);
  5070. intel_ring_emit(ring, MI_NOOP);
  5071. intel_ring_advance(ring);
  5072. return 0;
  5073. err_unpin:
  5074. intel_unpin_fb_obj(obj);
  5075. err:
  5076. return ret;
  5077. }
  5078. static int intel_gen4_queue_flip(struct drm_device *dev,
  5079. struct drm_crtc *crtc,
  5080. struct drm_framebuffer *fb,
  5081. struct drm_i915_gem_object *obj)
  5082. {
  5083. struct drm_i915_private *dev_priv = dev->dev_private;
  5084. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5085. uint32_t pf, pipesrc;
  5086. struct intel_ring_buffer *ring = &dev_priv->ring[RCS];
  5087. int ret;
  5088. ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
  5089. if (ret)
  5090. goto err;
  5091. ret = intel_ring_begin(ring, 4);
  5092. if (ret)
  5093. goto err_unpin;
  5094. /* i965+ uses the linear or tiled offsets from the
  5095. * Display Registers (which do not change across a page-flip)
  5096. * so we need only reprogram the base address.
  5097. */
  5098. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  5099. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  5100. intel_ring_emit(ring, fb->pitches[0]);
  5101. intel_ring_emit(ring, obj->gtt_offset | obj->tiling_mode);
  5102. /* XXX Enabling the panel-fitter across page-flip is so far
  5103. * untested on non-native modes, so ignore it for now.
  5104. * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE;
  5105. */
  5106. pf = 0;
  5107. pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
  5108. intel_ring_emit(ring, pf | pipesrc);
  5109. intel_ring_advance(ring);
  5110. return 0;
  5111. err_unpin:
  5112. intel_unpin_fb_obj(obj);
  5113. err:
  5114. return ret;
  5115. }
  5116. static int intel_gen6_queue_flip(struct drm_device *dev,
  5117. struct drm_crtc *crtc,
  5118. struct drm_framebuffer *fb,
  5119. struct drm_i915_gem_object *obj)
  5120. {
  5121. struct drm_i915_private *dev_priv = dev->dev_private;
  5122. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5123. struct intel_ring_buffer *ring = &dev_priv->ring[RCS];
  5124. uint32_t pf, pipesrc;
  5125. int ret;
  5126. ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
  5127. if (ret)
  5128. goto err;
  5129. ret = intel_ring_begin(ring, 4);
  5130. if (ret)
  5131. goto err_unpin;
  5132. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  5133. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  5134. intel_ring_emit(ring, fb->pitches[0] | obj->tiling_mode);
  5135. intel_ring_emit(ring, obj->gtt_offset);
  5136. /* Contrary to the suggestions in the documentation,
  5137. * "Enable Panel Fitter" does not seem to be required when page
  5138. * flipping with a non-native mode, and worse causes a normal
  5139. * modeset to fail.
  5140. * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
  5141. */
  5142. pf = 0;
  5143. pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
  5144. intel_ring_emit(ring, pf | pipesrc);
  5145. intel_ring_advance(ring);
  5146. return 0;
  5147. err_unpin:
  5148. intel_unpin_fb_obj(obj);
  5149. err:
  5150. return ret;
  5151. }
  5152. /*
  5153. * On gen7 we currently use the blit ring because (in early silicon at least)
  5154. * the render ring doesn't give us interrpts for page flip completion, which
  5155. * means clients will hang after the first flip is queued. Fortunately the
  5156. * blit ring generates interrupts properly, so use it instead.
  5157. */
  5158. static int intel_gen7_queue_flip(struct drm_device *dev,
  5159. struct drm_crtc *crtc,
  5160. struct drm_framebuffer *fb,
  5161. struct drm_i915_gem_object *obj)
  5162. {
  5163. struct drm_i915_private *dev_priv = dev->dev_private;
  5164. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5165. struct intel_ring_buffer *ring = &dev_priv->ring[BCS];
  5166. int ret;
  5167. ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
  5168. if (ret)
  5169. goto err;
  5170. ret = intel_ring_begin(ring, 4);
  5171. if (ret)
  5172. goto err_unpin;
  5173. intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | (intel_crtc->plane << 19));
  5174. intel_ring_emit(ring, (fb->pitches[0] | obj->tiling_mode));
  5175. intel_ring_emit(ring, (obj->gtt_offset));
  5176. intel_ring_emit(ring, (MI_NOOP));
  5177. intel_ring_advance(ring);
  5178. return 0;
  5179. err_unpin:
  5180. intel_unpin_fb_obj(obj);
  5181. err:
  5182. return ret;
  5183. }
  5184. static int intel_default_queue_flip(struct drm_device *dev,
  5185. struct drm_crtc *crtc,
  5186. struct drm_framebuffer *fb,
  5187. struct drm_i915_gem_object *obj)
  5188. {
  5189. return -ENODEV;
  5190. }
  5191. static int intel_crtc_page_flip(struct drm_crtc *crtc,
  5192. struct drm_framebuffer *fb,
  5193. struct drm_pending_vblank_event *event)
  5194. {
  5195. struct drm_device *dev = crtc->dev;
  5196. struct drm_i915_private *dev_priv = dev->dev_private;
  5197. struct intel_framebuffer *intel_fb;
  5198. struct drm_i915_gem_object *obj;
  5199. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5200. struct intel_unpin_work *work;
  5201. unsigned long flags;
  5202. int ret;
  5203. work = kzalloc(sizeof *work, GFP_KERNEL);
  5204. if (work == NULL)
  5205. return -ENOMEM;
  5206. work->event = event;
  5207. work->dev = crtc->dev;
  5208. intel_fb = to_intel_framebuffer(crtc->fb);
  5209. work->old_fb_obj = intel_fb->obj;
  5210. INIT_WORK(&work->work, intel_unpin_work_fn);
  5211. ret = drm_vblank_get(dev, intel_crtc->pipe);
  5212. if (ret)
  5213. goto free_work;
  5214. /* We borrow the event spin lock for protecting unpin_work */
  5215. spin_lock_irqsave(&dev->event_lock, flags);
  5216. if (intel_crtc->unpin_work) {
  5217. spin_unlock_irqrestore(&dev->event_lock, flags);
  5218. kfree(work);
  5219. drm_vblank_put(dev, intel_crtc->pipe);
  5220. DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
  5221. return -EBUSY;
  5222. }
  5223. intel_crtc->unpin_work = work;
  5224. spin_unlock_irqrestore(&dev->event_lock, flags);
  5225. intel_fb = to_intel_framebuffer(fb);
  5226. obj = intel_fb->obj;
  5227. mutex_lock(&dev->struct_mutex);
  5228. /* Reference the objects for the scheduled work. */
  5229. drm_gem_object_reference(&work->old_fb_obj->base);
  5230. drm_gem_object_reference(&obj->base);
  5231. crtc->fb = fb;
  5232. work->pending_flip_obj = obj;
  5233. work->enable_stall_check = true;
  5234. /* Block clients from rendering to the new back buffer until
  5235. * the flip occurs and the object is no longer visible.
  5236. */
  5237. atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
  5238. ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
  5239. if (ret)
  5240. goto cleanup_pending;
  5241. intel_disable_fbc(dev);
  5242. intel_mark_busy(dev, obj);
  5243. mutex_unlock(&dev->struct_mutex);
  5244. trace_i915_flip_request(intel_crtc->plane, obj);
  5245. return 0;
  5246. cleanup_pending:
  5247. atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
  5248. drm_gem_object_unreference(&work->old_fb_obj->base);
  5249. drm_gem_object_unreference(&obj->base);
  5250. mutex_unlock(&dev->struct_mutex);
  5251. spin_lock_irqsave(&dev->event_lock, flags);
  5252. intel_crtc->unpin_work = NULL;
  5253. spin_unlock_irqrestore(&dev->event_lock, flags);
  5254. drm_vblank_put(dev, intel_crtc->pipe);
  5255. free_work:
  5256. kfree(work);
  5257. return ret;
  5258. }
  5259. static void intel_sanitize_modesetting(struct drm_device *dev,
  5260. int pipe, int plane)
  5261. {
  5262. struct drm_i915_private *dev_priv = dev->dev_private;
  5263. u32 reg, val;
  5264. /* Clear any frame start delays used for debugging left by the BIOS */
  5265. for_each_pipe(pipe) {
  5266. reg = PIPECONF(pipe);
  5267. I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
  5268. }
  5269. if (HAS_PCH_SPLIT(dev))
  5270. return;
  5271. /* Who knows what state these registers were left in by the BIOS or
  5272. * grub?
  5273. *
  5274. * If we leave the registers in a conflicting state (e.g. with the
  5275. * display plane reading from the other pipe than the one we intend
  5276. * to use) then when we attempt to teardown the active mode, we will
  5277. * not disable the pipes and planes in the correct order -- leaving
  5278. * a plane reading from a disabled pipe and possibly leading to
  5279. * undefined behaviour.
  5280. */
  5281. reg = DSPCNTR(plane);
  5282. val = I915_READ(reg);
  5283. if ((val & DISPLAY_PLANE_ENABLE) == 0)
  5284. return;
  5285. if (!!(val & DISPPLANE_SEL_PIPE_MASK) == pipe)
  5286. return;
  5287. /* This display plane is active and attached to the other CPU pipe. */
  5288. pipe = !pipe;
  5289. /* Disable the plane and wait for it to stop reading from the pipe. */
  5290. intel_disable_plane(dev_priv, plane, pipe);
  5291. intel_disable_pipe(dev_priv, pipe);
  5292. }
  5293. static void intel_crtc_reset(struct drm_crtc *crtc)
  5294. {
  5295. struct drm_device *dev = crtc->dev;
  5296. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5297. /* Reset flags back to the 'unknown' status so that they
  5298. * will be correctly set on the initial modeset.
  5299. */
  5300. intel_crtc->dpms_mode = -1;
  5301. /* We need to fix up any BIOS configuration that conflicts with
  5302. * our expectations.
  5303. */
  5304. intel_sanitize_modesetting(dev, intel_crtc->pipe, intel_crtc->plane);
  5305. }
  5306. static struct drm_crtc_helper_funcs intel_helper_funcs = {
  5307. .dpms = intel_crtc_dpms,
  5308. .mode_fixup = intel_crtc_mode_fixup,
  5309. .mode_set = intel_crtc_mode_set,
  5310. .mode_set_base = intel_pipe_set_base,
  5311. .mode_set_base_atomic = intel_pipe_set_base_atomic,
  5312. .load_lut = intel_crtc_load_lut,
  5313. .disable = intel_crtc_disable,
  5314. };
  5315. static const struct drm_crtc_funcs intel_crtc_funcs = {
  5316. .reset = intel_crtc_reset,
  5317. .cursor_set = intel_crtc_cursor_set,
  5318. .cursor_move = intel_crtc_cursor_move,
  5319. .gamma_set = intel_crtc_gamma_set,
  5320. .set_config = drm_crtc_helper_set_config,
  5321. .destroy = intel_crtc_destroy,
  5322. .page_flip = intel_crtc_page_flip,
  5323. };
  5324. static void intel_pch_pll_init(struct drm_device *dev)
  5325. {
  5326. drm_i915_private_t *dev_priv = dev->dev_private;
  5327. int i;
  5328. if (dev_priv->num_pch_pll == 0) {
  5329. DRM_DEBUG_KMS("No PCH PLLs on this hardware, skipping initialisation\n");
  5330. return;
  5331. }
  5332. for (i = 0; i < dev_priv->num_pch_pll; i++) {
  5333. dev_priv->pch_plls[i].pll_reg = _PCH_DPLL(i);
  5334. dev_priv->pch_plls[i].fp0_reg = _PCH_FP0(i);
  5335. dev_priv->pch_plls[i].fp1_reg = _PCH_FP1(i);
  5336. }
  5337. }
  5338. static void intel_crtc_init(struct drm_device *dev, int pipe)
  5339. {
  5340. drm_i915_private_t *dev_priv = dev->dev_private;
  5341. struct intel_crtc *intel_crtc;
  5342. int i;
  5343. intel_crtc = kzalloc(sizeof(struct intel_crtc) + (INTELFB_CONN_LIMIT * sizeof(struct drm_connector *)), GFP_KERNEL);
  5344. if (intel_crtc == NULL)
  5345. return;
  5346. drm_crtc_init(dev, &intel_crtc->base, &intel_crtc_funcs);
  5347. drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256);
  5348. for (i = 0; i < 256; i++) {
  5349. intel_crtc->lut_r[i] = i;
  5350. intel_crtc->lut_g[i] = i;
  5351. intel_crtc->lut_b[i] = i;
  5352. }
  5353. /* Swap pipes & planes for FBC on pre-965 */
  5354. intel_crtc->pipe = pipe;
  5355. intel_crtc->plane = pipe;
  5356. if (IS_MOBILE(dev) && IS_GEN3(dev)) {
  5357. DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
  5358. intel_crtc->plane = !pipe;
  5359. }
  5360. BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
  5361. dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL);
  5362. dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base;
  5363. dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base;
  5364. intel_crtc_reset(&intel_crtc->base);
  5365. intel_crtc->active = true; /* force the pipe off on setup_init_config */
  5366. intel_crtc->bpp = 24; /* default for pre-Ironlake */
  5367. if (HAS_PCH_SPLIT(dev)) {
  5368. intel_helper_funcs.prepare = ironlake_crtc_prepare;
  5369. intel_helper_funcs.commit = ironlake_crtc_commit;
  5370. } else {
  5371. intel_helper_funcs.prepare = i9xx_crtc_prepare;
  5372. intel_helper_funcs.commit = i9xx_crtc_commit;
  5373. }
  5374. drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
  5375. intel_crtc->busy = false;
  5376. setup_timer(&intel_crtc->idle_timer, intel_crtc_idle_timer,
  5377. (unsigned long)intel_crtc);
  5378. }
  5379. int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data,
  5380. struct drm_file *file)
  5381. {
  5382. struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
  5383. struct drm_mode_object *drmmode_obj;
  5384. struct intel_crtc *crtc;
  5385. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  5386. return -ENODEV;
  5387. drmmode_obj = drm_mode_object_find(dev, pipe_from_crtc_id->crtc_id,
  5388. DRM_MODE_OBJECT_CRTC);
  5389. if (!drmmode_obj) {
  5390. DRM_ERROR("no such CRTC id\n");
  5391. return -EINVAL;
  5392. }
  5393. crtc = to_intel_crtc(obj_to_crtc(drmmode_obj));
  5394. pipe_from_crtc_id->pipe = crtc->pipe;
  5395. return 0;
  5396. }
  5397. static int intel_encoder_clones(struct drm_device *dev, int type_mask)
  5398. {
  5399. struct intel_encoder *encoder;
  5400. int index_mask = 0;
  5401. int entry = 0;
  5402. list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) {
  5403. if (type_mask & encoder->clone_mask)
  5404. index_mask |= (1 << entry);
  5405. entry++;
  5406. }
  5407. return index_mask;
  5408. }
  5409. static bool has_edp_a(struct drm_device *dev)
  5410. {
  5411. struct drm_i915_private *dev_priv = dev->dev_private;
  5412. if (!IS_MOBILE(dev))
  5413. return false;
  5414. if ((I915_READ(DP_A) & DP_DETECTED) == 0)
  5415. return false;
  5416. if (IS_GEN5(dev) &&
  5417. (I915_READ(ILK_DISPLAY_CHICKEN_FUSES) & ILK_eDP_A_DISABLE))
  5418. return false;
  5419. return true;
  5420. }
  5421. static void intel_setup_outputs(struct drm_device *dev)
  5422. {
  5423. struct drm_i915_private *dev_priv = dev->dev_private;
  5424. struct intel_encoder *encoder;
  5425. bool dpd_is_edp = false;
  5426. bool has_lvds;
  5427. has_lvds = intel_lvds_init(dev);
  5428. if (!has_lvds && !HAS_PCH_SPLIT(dev)) {
  5429. /* disable the panel fitter on everything but LVDS */
  5430. I915_WRITE(PFIT_CONTROL, 0);
  5431. }
  5432. if (HAS_PCH_SPLIT(dev)) {
  5433. dpd_is_edp = intel_dpd_is_edp(dev);
  5434. if (has_edp_a(dev))
  5435. intel_dp_init(dev, DP_A);
  5436. if (dpd_is_edp && (I915_READ(PCH_DP_D) & DP_DETECTED))
  5437. intel_dp_init(dev, PCH_DP_D);
  5438. }
  5439. intel_crt_init(dev);
  5440. if (HAS_PCH_SPLIT(dev)) {
  5441. int found;
  5442. if (I915_READ(HDMIB) & PORT_DETECTED) {
  5443. /* PCH SDVOB multiplex with HDMIB */
  5444. found = intel_sdvo_init(dev, PCH_SDVOB, true);
  5445. if (!found)
  5446. intel_hdmi_init(dev, HDMIB);
  5447. if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
  5448. intel_dp_init(dev, PCH_DP_B);
  5449. }
  5450. if (I915_READ(HDMIC) & PORT_DETECTED)
  5451. intel_hdmi_init(dev, HDMIC);
  5452. if (I915_READ(HDMID) & PORT_DETECTED)
  5453. intel_hdmi_init(dev, HDMID);
  5454. if (I915_READ(PCH_DP_C) & DP_DETECTED)
  5455. intel_dp_init(dev, PCH_DP_C);
  5456. if (!dpd_is_edp && (I915_READ(PCH_DP_D) & DP_DETECTED))
  5457. intel_dp_init(dev, PCH_DP_D);
  5458. } else if (SUPPORTS_DIGITAL_OUTPUTS(dev)) {
  5459. bool found = false;
  5460. if (I915_READ(SDVOB) & SDVO_DETECTED) {
  5461. DRM_DEBUG_KMS("probing SDVOB\n");
  5462. found = intel_sdvo_init(dev, SDVOB, true);
  5463. if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) {
  5464. DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
  5465. intel_hdmi_init(dev, SDVOB);
  5466. }
  5467. if (!found && SUPPORTS_INTEGRATED_DP(dev)) {
  5468. DRM_DEBUG_KMS("probing DP_B\n");
  5469. intel_dp_init(dev, DP_B);
  5470. }
  5471. }
  5472. /* Before G4X SDVOC doesn't have its own detect register */
  5473. if (I915_READ(SDVOB) & SDVO_DETECTED) {
  5474. DRM_DEBUG_KMS("probing SDVOC\n");
  5475. found = intel_sdvo_init(dev, SDVOC, false);
  5476. }
  5477. if (!found && (I915_READ(SDVOC) & SDVO_DETECTED)) {
  5478. if (SUPPORTS_INTEGRATED_HDMI(dev)) {
  5479. DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
  5480. intel_hdmi_init(dev, SDVOC);
  5481. }
  5482. if (SUPPORTS_INTEGRATED_DP(dev)) {
  5483. DRM_DEBUG_KMS("probing DP_C\n");
  5484. intel_dp_init(dev, DP_C);
  5485. }
  5486. }
  5487. if (SUPPORTS_INTEGRATED_DP(dev) &&
  5488. (I915_READ(DP_D) & DP_DETECTED)) {
  5489. DRM_DEBUG_KMS("probing DP_D\n");
  5490. intel_dp_init(dev, DP_D);
  5491. }
  5492. } else if (IS_GEN2(dev))
  5493. intel_dvo_init(dev);
  5494. if (SUPPORTS_TV(dev))
  5495. intel_tv_init(dev);
  5496. list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) {
  5497. encoder->base.possible_crtcs = encoder->crtc_mask;
  5498. encoder->base.possible_clones =
  5499. intel_encoder_clones(dev, encoder->clone_mask);
  5500. }
  5501. /* disable all the possible outputs/crtcs before entering KMS mode */
  5502. drm_helper_disable_unused_functions(dev);
  5503. if (HAS_PCH_SPLIT(dev))
  5504. ironlake_init_pch_refclk(dev);
  5505. }
  5506. static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
  5507. {
  5508. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  5509. drm_framebuffer_cleanup(fb);
  5510. drm_gem_object_unreference_unlocked(&intel_fb->obj->base);
  5511. kfree(intel_fb);
  5512. }
  5513. static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
  5514. struct drm_file *file,
  5515. unsigned int *handle)
  5516. {
  5517. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  5518. struct drm_i915_gem_object *obj = intel_fb->obj;
  5519. return drm_gem_handle_create(file, &obj->base, handle);
  5520. }
  5521. static const struct drm_framebuffer_funcs intel_fb_funcs = {
  5522. .destroy = intel_user_framebuffer_destroy,
  5523. .create_handle = intel_user_framebuffer_create_handle,
  5524. };
  5525. int intel_framebuffer_init(struct drm_device *dev,
  5526. struct intel_framebuffer *intel_fb,
  5527. struct drm_mode_fb_cmd2 *mode_cmd,
  5528. struct drm_i915_gem_object *obj)
  5529. {
  5530. int ret;
  5531. if (obj->tiling_mode == I915_TILING_Y)
  5532. return -EINVAL;
  5533. if (mode_cmd->pitches[0] & 63)
  5534. return -EINVAL;
  5535. switch (mode_cmd->pixel_format) {
  5536. case DRM_FORMAT_RGB332:
  5537. case DRM_FORMAT_RGB565:
  5538. case DRM_FORMAT_XRGB8888:
  5539. case DRM_FORMAT_XBGR8888:
  5540. case DRM_FORMAT_ARGB8888:
  5541. case DRM_FORMAT_XRGB2101010:
  5542. case DRM_FORMAT_ARGB2101010:
  5543. /* RGB formats are common across chipsets */
  5544. break;
  5545. case DRM_FORMAT_YUYV:
  5546. case DRM_FORMAT_UYVY:
  5547. case DRM_FORMAT_YVYU:
  5548. case DRM_FORMAT_VYUY:
  5549. break;
  5550. default:
  5551. DRM_DEBUG_KMS("unsupported pixel format %u\n",
  5552. mode_cmd->pixel_format);
  5553. return -EINVAL;
  5554. }
  5555. ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs);
  5556. if (ret) {
  5557. DRM_ERROR("framebuffer init failed %d\n", ret);
  5558. return ret;
  5559. }
  5560. drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd);
  5561. intel_fb->obj = obj;
  5562. return 0;
  5563. }
  5564. static struct drm_framebuffer *
  5565. intel_user_framebuffer_create(struct drm_device *dev,
  5566. struct drm_file *filp,
  5567. struct drm_mode_fb_cmd2 *mode_cmd)
  5568. {
  5569. struct drm_i915_gem_object *obj;
  5570. obj = to_intel_bo(drm_gem_object_lookup(dev, filp,
  5571. mode_cmd->handles[0]));
  5572. if (&obj->base == NULL)
  5573. return ERR_PTR(-ENOENT);
  5574. return intel_framebuffer_create(dev, mode_cmd, obj);
  5575. }
  5576. static const struct drm_mode_config_funcs intel_mode_funcs = {
  5577. .fb_create = intel_user_framebuffer_create,
  5578. .output_poll_changed = intel_fb_output_poll_changed,
  5579. };
  5580. /* Set up chip specific display functions */
  5581. static void intel_init_display(struct drm_device *dev)
  5582. {
  5583. struct drm_i915_private *dev_priv = dev->dev_private;
  5584. /* We always want a DPMS function */
  5585. if (HAS_PCH_SPLIT(dev)) {
  5586. dev_priv->display.dpms = ironlake_crtc_dpms;
  5587. dev_priv->display.crtc_mode_set = ironlake_crtc_mode_set;
  5588. dev_priv->display.off = ironlake_crtc_off;
  5589. dev_priv->display.update_plane = ironlake_update_plane;
  5590. } else {
  5591. dev_priv->display.dpms = i9xx_crtc_dpms;
  5592. dev_priv->display.crtc_mode_set = i9xx_crtc_mode_set;
  5593. dev_priv->display.off = i9xx_crtc_off;
  5594. dev_priv->display.update_plane = i9xx_update_plane;
  5595. }
  5596. /* Returns the core display clock speed */
  5597. if (IS_VALLEYVIEW(dev))
  5598. dev_priv->display.get_display_clock_speed =
  5599. valleyview_get_display_clock_speed;
  5600. else if (IS_I945G(dev) || (IS_G33(dev) && !IS_PINEVIEW_M(dev)))
  5601. dev_priv->display.get_display_clock_speed =
  5602. i945_get_display_clock_speed;
  5603. else if (IS_I915G(dev))
  5604. dev_priv->display.get_display_clock_speed =
  5605. i915_get_display_clock_speed;
  5606. else if (IS_I945GM(dev) || IS_845G(dev) || IS_PINEVIEW_M(dev))
  5607. dev_priv->display.get_display_clock_speed =
  5608. i9xx_misc_get_display_clock_speed;
  5609. else if (IS_I915GM(dev))
  5610. dev_priv->display.get_display_clock_speed =
  5611. i915gm_get_display_clock_speed;
  5612. else if (IS_I865G(dev))
  5613. dev_priv->display.get_display_clock_speed =
  5614. i865_get_display_clock_speed;
  5615. else if (IS_I85X(dev))
  5616. dev_priv->display.get_display_clock_speed =
  5617. i855_get_display_clock_speed;
  5618. else /* 852, 830 */
  5619. dev_priv->display.get_display_clock_speed =
  5620. i830_get_display_clock_speed;
  5621. if (HAS_PCH_SPLIT(dev)) {
  5622. if (IS_GEN5(dev)) {
  5623. dev_priv->display.fdi_link_train = ironlake_fdi_link_train;
  5624. dev_priv->display.write_eld = ironlake_write_eld;
  5625. } else if (IS_GEN6(dev)) {
  5626. dev_priv->display.fdi_link_train = gen6_fdi_link_train;
  5627. dev_priv->display.write_eld = ironlake_write_eld;
  5628. } else if (IS_IVYBRIDGE(dev)) {
  5629. /* FIXME: detect B0+ stepping and use auto training */
  5630. dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
  5631. dev_priv->display.write_eld = ironlake_write_eld;
  5632. } else if (IS_HASWELL(dev)) {
  5633. dev_priv->display.fdi_link_train = hsw_fdi_link_train;
  5634. dev_priv->display.write_eld = ironlake_write_eld;
  5635. } else
  5636. dev_priv->display.update_wm = NULL;
  5637. } else if (IS_VALLEYVIEW(dev)) {
  5638. dev_priv->display.force_wake_get = vlv_force_wake_get;
  5639. dev_priv->display.force_wake_put = vlv_force_wake_put;
  5640. } else if (IS_G4X(dev)) {
  5641. dev_priv->display.write_eld = g4x_write_eld;
  5642. }
  5643. /* Default just returns -ENODEV to indicate unsupported */
  5644. dev_priv->display.queue_flip = intel_default_queue_flip;
  5645. switch (INTEL_INFO(dev)->gen) {
  5646. case 2:
  5647. dev_priv->display.queue_flip = intel_gen2_queue_flip;
  5648. break;
  5649. case 3:
  5650. dev_priv->display.queue_flip = intel_gen3_queue_flip;
  5651. break;
  5652. case 4:
  5653. case 5:
  5654. dev_priv->display.queue_flip = intel_gen4_queue_flip;
  5655. break;
  5656. case 6:
  5657. dev_priv->display.queue_flip = intel_gen6_queue_flip;
  5658. break;
  5659. case 7:
  5660. dev_priv->display.queue_flip = intel_gen7_queue_flip;
  5661. break;
  5662. }
  5663. }
  5664. /*
  5665. * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend,
  5666. * resume, or other times. This quirk makes sure that's the case for
  5667. * affected systems.
  5668. */
  5669. static void quirk_pipea_force(struct drm_device *dev)
  5670. {
  5671. struct drm_i915_private *dev_priv = dev->dev_private;
  5672. dev_priv->quirks |= QUIRK_PIPEA_FORCE;
  5673. DRM_INFO("applying pipe a force quirk\n");
  5674. }
  5675. /*
  5676. * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
  5677. */
  5678. static void quirk_ssc_force_disable(struct drm_device *dev)
  5679. {
  5680. struct drm_i915_private *dev_priv = dev->dev_private;
  5681. dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE;
  5682. DRM_INFO("applying lvds SSC disable quirk\n");
  5683. }
  5684. /*
  5685. * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
  5686. * brightness value
  5687. */
  5688. static void quirk_invert_brightness(struct drm_device *dev)
  5689. {
  5690. struct drm_i915_private *dev_priv = dev->dev_private;
  5691. dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS;
  5692. DRM_INFO("applying inverted panel brightness quirk\n");
  5693. }
  5694. struct intel_quirk {
  5695. int device;
  5696. int subsystem_vendor;
  5697. int subsystem_device;
  5698. void (*hook)(struct drm_device *dev);
  5699. };
  5700. static struct intel_quirk intel_quirks[] = {
  5701. /* HP Mini needs pipe A force quirk (LP: #322104) */
  5702. { 0x27ae, 0x103c, 0x361a, quirk_pipea_force },
  5703. /* Thinkpad R31 needs pipe A force quirk */
  5704. { 0x3577, 0x1014, 0x0505, quirk_pipea_force },
  5705. /* Toshiba Protege R-205, S-209 needs pipe A force quirk */
  5706. { 0x2592, 0x1179, 0x0001, quirk_pipea_force },
  5707. /* ThinkPad X30 needs pipe A force quirk (LP: #304614) */
  5708. { 0x3577, 0x1014, 0x0513, quirk_pipea_force },
  5709. /* ThinkPad X40 needs pipe A force quirk */
  5710. /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
  5711. { 0x2782, 0x17aa, 0x201a, quirk_pipea_force },
  5712. /* 855 & before need to leave pipe A & dpll A up */
  5713. { 0x3582, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force },
  5714. { 0x2562, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force },
  5715. /* Lenovo U160 cannot use SSC on LVDS */
  5716. { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable },
  5717. /* Sony Vaio Y cannot use SSC on LVDS */
  5718. { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable },
  5719. /* Acer Aspire 5734Z must invert backlight brightness */
  5720. { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness },
  5721. };
  5722. static void intel_init_quirks(struct drm_device *dev)
  5723. {
  5724. struct pci_dev *d = dev->pdev;
  5725. int i;
  5726. for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) {
  5727. struct intel_quirk *q = &intel_quirks[i];
  5728. if (d->device == q->device &&
  5729. (d->subsystem_vendor == q->subsystem_vendor ||
  5730. q->subsystem_vendor == PCI_ANY_ID) &&
  5731. (d->subsystem_device == q->subsystem_device ||
  5732. q->subsystem_device == PCI_ANY_ID))
  5733. q->hook(dev);
  5734. }
  5735. }
  5736. /* Disable the VGA plane that we never use */
  5737. static void i915_disable_vga(struct drm_device *dev)
  5738. {
  5739. struct drm_i915_private *dev_priv = dev->dev_private;
  5740. u8 sr1;
  5741. u32 vga_reg;
  5742. if (HAS_PCH_SPLIT(dev))
  5743. vga_reg = CPU_VGACNTRL;
  5744. else
  5745. vga_reg = VGACNTRL;
  5746. vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO);
  5747. outb(SR01, VGA_SR_INDEX);
  5748. sr1 = inb(VGA_SR_DATA);
  5749. outb(sr1 | 1<<5, VGA_SR_DATA);
  5750. vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
  5751. udelay(300);
  5752. I915_WRITE(vga_reg, VGA_DISP_DISABLE);
  5753. POSTING_READ(vga_reg);
  5754. }
  5755. static void ivb_pch_pwm_override(struct drm_device *dev)
  5756. {
  5757. struct drm_i915_private *dev_priv = dev->dev_private;
  5758. /*
  5759. * IVB has CPU eDP backlight regs too, set things up to let the
  5760. * PCH regs control the backlight
  5761. */
  5762. I915_WRITE(BLC_PWM_CPU_CTL2, PWM_ENABLE);
  5763. I915_WRITE(BLC_PWM_CPU_CTL, 0);
  5764. I915_WRITE(BLC_PWM_PCH_CTL1, PWM_ENABLE | (1<<30));
  5765. }
  5766. void intel_modeset_init_hw(struct drm_device *dev)
  5767. {
  5768. struct drm_i915_private *dev_priv = dev->dev_private;
  5769. intel_init_clock_gating(dev);
  5770. if (IS_IRONLAKE_M(dev)) {
  5771. ironlake_enable_drps(dev);
  5772. ironlake_enable_rc6(dev);
  5773. intel_init_emon(dev);
  5774. }
  5775. if ((IS_GEN6(dev) || IS_GEN7(dev)) && !IS_VALLEYVIEW(dev)) {
  5776. gen6_enable_rps(dev_priv);
  5777. gen6_update_ring_freq(dev_priv);
  5778. }
  5779. if (IS_IVYBRIDGE(dev))
  5780. ivb_pch_pwm_override(dev);
  5781. }
  5782. void intel_modeset_init(struct drm_device *dev)
  5783. {
  5784. struct drm_i915_private *dev_priv = dev->dev_private;
  5785. int i, ret;
  5786. drm_mode_config_init(dev);
  5787. dev->mode_config.min_width = 0;
  5788. dev->mode_config.min_height = 0;
  5789. dev->mode_config.preferred_depth = 24;
  5790. dev->mode_config.prefer_shadow = 1;
  5791. dev->mode_config.funcs = (void *)&intel_mode_funcs;
  5792. intel_init_quirks(dev);
  5793. intel_init_pm(dev);
  5794. intel_prepare_ddi(dev);
  5795. intel_init_display(dev);
  5796. if (IS_GEN2(dev)) {
  5797. dev->mode_config.max_width = 2048;
  5798. dev->mode_config.max_height = 2048;
  5799. } else if (IS_GEN3(dev)) {
  5800. dev->mode_config.max_width = 4096;
  5801. dev->mode_config.max_height = 4096;
  5802. } else {
  5803. dev->mode_config.max_width = 8192;
  5804. dev->mode_config.max_height = 8192;
  5805. }
  5806. dev->mode_config.fb_base = dev->agp->base;
  5807. DRM_DEBUG_KMS("%d display pipe%s available.\n",
  5808. dev_priv->num_pipe, dev_priv->num_pipe > 1 ? "s" : "");
  5809. for (i = 0; i < dev_priv->num_pipe; i++) {
  5810. intel_crtc_init(dev, i);
  5811. ret = intel_plane_init(dev, i);
  5812. if (ret)
  5813. DRM_DEBUG_KMS("plane %d init failed: %d\n", i, ret);
  5814. }
  5815. intel_pch_pll_init(dev);
  5816. /* Just disable it once at startup */
  5817. i915_disable_vga(dev);
  5818. intel_setup_outputs(dev);
  5819. INIT_WORK(&dev_priv->idle_work, intel_idle_update);
  5820. setup_timer(&dev_priv->idle_timer, intel_gpu_idle_timer,
  5821. (unsigned long)dev);
  5822. }
  5823. void intel_modeset_gem_init(struct drm_device *dev)
  5824. {
  5825. intel_modeset_init_hw(dev);
  5826. intel_setup_overlay(dev);
  5827. }
  5828. void intel_modeset_cleanup(struct drm_device *dev)
  5829. {
  5830. struct drm_i915_private *dev_priv = dev->dev_private;
  5831. struct drm_crtc *crtc;
  5832. struct intel_crtc *intel_crtc;
  5833. drm_kms_helper_poll_fini(dev);
  5834. mutex_lock(&dev->struct_mutex);
  5835. intel_unregister_dsm_handler();
  5836. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  5837. /* Skip inactive CRTCs */
  5838. if (!crtc->fb)
  5839. continue;
  5840. intel_crtc = to_intel_crtc(crtc);
  5841. intel_increase_pllclock(crtc);
  5842. }
  5843. intel_disable_fbc(dev);
  5844. if (IS_IRONLAKE_M(dev))
  5845. ironlake_disable_drps(dev);
  5846. if ((IS_GEN6(dev) || IS_GEN7(dev)) && !IS_VALLEYVIEW(dev))
  5847. gen6_disable_rps(dev);
  5848. if (IS_IRONLAKE_M(dev))
  5849. ironlake_disable_rc6(dev);
  5850. if (IS_VALLEYVIEW(dev))
  5851. vlv_init_dpio(dev);
  5852. mutex_unlock(&dev->struct_mutex);
  5853. /* Disable the irq before mode object teardown, for the irq might
  5854. * enqueue unpin/hotplug work. */
  5855. drm_irq_uninstall(dev);
  5856. cancel_work_sync(&dev_priv->hotplug_work);
  5857. cancel_work_sync(&dev_priv->rps_work);
  5858. /* flush any delayed tasks or pending work */
  5859. flush_scheduled_work();
  5860. /* Shut off idle work before the crtcs get freed. */
  5861. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  5862. intel_crtc = to_intel_crtc(crtc);
  5863. del_timer_sync(&intel_crtc->idle_timer);
  5864. }
  5865. del_timer_sync(&dev_priv->idle_timer);
  5866. cancel_work_sync(&dev_priv->idle_work);
  5867. drm_mode_config_cleanup(dev);
  5868. }
  5869. /*
  5870. * Return which encoder is currently attached for connector.
  5871. */
  5872. struct drm_encoder *intel_best_encoder(struct drm_connector *connector)
  5873. {
  5874. return &intel_attached_encoder(connector)->base;
  5875. }
  5876. void intel_connector_attach_encoder(struct intel_connector *connector,
  5877. struct intel_encoder *encoder)
  5878. {
  5879. connector->encoder = encoder;
  5880. drm_mode_connector_attach_encoder(&connector->base,
  5881. &encoder->base);
  5882. }
  5883. /*
  5884. * set vga decode state - true == enable VGA decode
  5885. */
  5886. int intel_modeset_vga_set_state(struct drm_device *dev, bool state)
  5887. {
  5888. struct drm_i915_private *dev_priv = dev->dev_private;
  5889. u16 gmch_ctrl;
  5890. pci_read_config_word(dev_priv->bridge_dev, INTEL_GMCH_CTRL, &gmch_ctrl);
  5891. if (state)
  5892. gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
  5893. else
  5894. gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
  5895. pci_write_config_word(dev_priv->bridge_dev, INTEL_GMCH_CTRL, gmch_ctrl);
  5896. return 0;
  5897. }
  5898. #ifdef CONFIG_DEBUG_FS
  5899. #include <linux/seq_file.h>
  5900. struct intel_display_error_state {
  5901. struct intel_cursor_error_state {
  5902. u32 control;
  5903. u32 position;
  5904. u32 base;
  5905. u32 size;
  5906. } cursor[2];
  5907. struct intel_pipe_error_state {
  5908. u32 conf;
  5909. u32 source;
  5910. u32 htotal;
  5911. u32 hblank;
  5912. u32 hsync;
  5913. u32 vtotal;
  5914. u32 vblank;
  5915. u32 vsync;
  5916. } pipe[2];
  5917. struct intel_plane_error_state {
  5918. u32 control;
  5919. u32 stride;
  5920. u32 size;
  5921. u32 pos;
  5922. u32 addr;
  5923. u32 surface;
  5924. u32 tile_offset;
  5925. } plane[2];
  5926. };
  5927. struct intel_display_error_state *
  5928. intel_display_capture_error_state(struct drm_device *dev)
  5929. {
  5930. drm_i915_private_t *dev_priv = dev->dev_private;
  5931. struct intel_display_error_state *error;
  5932. int i;
  5933. error = kmalloc(sizeof(*error), GFP_ATOMIC);
  5934. if (error == NULL)
  5935. return NULL;
  5936. for (i = 0; i < 2; i++) {
  5937. error->cursor[i].control = I915_READ(CURCNTR(i));
  5938. error->cursor[i].position = I915_READ(CURPOS(i));
  5939. error->cursor[i].base = I915_READ(CURBASE(i));
  5940. error->plane[i].control = I915_READ(DSPCNTR(i));
  5941. error->plane[i].stride = I915_READ(DSPSTRIDE(i));
  5942. error->plane[i].size = I915_READ(DSPSIZE(i));
  5943. error->plane[i].pos = I915_READ(DSPPOS(i));
  5944. error->plane[i].addr = I915_READ(DSPADDR(i));
  5945. if (INTEL_INFO(dev)->gen >= 4) {
  5946. error->plane[i].surface = I915_READ(DSPSURF(i));
  5947. error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
  5948. }
  5949. error->pipe[i].conf = I915_READ(PIPECONF(i));
  5950. error->pipe[i].source = I915_READ(PIPESRC(i));
  5951. error->pipe[i].htotal = I915_READ(HTOTAL(i));
  5952. error->pipe[i].hblank = I915_READ(HBLANK(i));
  5953. error->pipe[i].hsync = I915_READ(HSYNC(i));
  5954. error->pipe[i].vtotal = I915_READ(VTOTAL(i));
  5955. error->pipe[i].vblank = I915_READ(VBLANK(i));
  5956. error->pipe[i].vsync = I915_READ(VSYNC(i));
  5957. }
  5958. return error;
  5959. }
  5960. void
  5961. intel_display_print_error_state(struct seq_file *m,
  5962. struct drm_device *dev,
  5963. struct intel_display_error_state *error)
  5964. {
  5965. int i;
  5966. for (i = 0; i < 2; i++) {
  5967. seq_printf(m, "Pipe [%d]:\n", i);
  5968. seq_printf(m, " CONF: %08x\n", error->pipe[i].conf);
  5969. seq_printf(m, " SRC: %08x\n", error->pipe[i].source);
  5970. seq_printf(m, " HTOTAL: %08x\n", error->pipe[i].htotal);
  5971. seq_printf(m, " HBLANK: %08x\n", error->pipe[i].hblank);
  5972. seq_printf(m, " HSYNC: %08x\n", error->pipe[i].hsync);
  5973. seq_printf(m, " VTOTAL: %08x\n", error->pipe[i].vtotal);
  5974. seq_printf(m, " VBLANK: %08x\n", error->pipe[i].vblank);
  5975. seq_printf(m, " VSYNC: %08x\n", error->pipe[i].vsync);
  5976. seq_printf(m, "Plane [%d]:\n", i);
  5977. seq_printf(m, " CNTR: %08x\n", error->plane[i].control);
  5978. seq_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
  5979. seq_printf(m, " SIZE: %08x\n", error->plane[i].size);
  5980. seq_printf(m, " POS: %08x\n", error->plane[i].pos);
  5981. seq_printf(m, " ADDR: %08x\n", error->plane[i].addr);
  5982. if (INTEL_INFO(dev)->gen >= 4) {
  5983. seq_printf(m, " SURF: %08x\n", error->plane[i].surface);
  5984. seq_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
  5985. }
  5986. seq_printf(m, "Cursor [%d]:\n", i);
  5987. seq_printf(m, " CNTR: %08x\n", error->cursor[i].control);
  5988. seq_printf(m, " POS: %08x\n", error->cursor[i].position);
  5989. seq_printf(m, " BASE: %08x\n", error->cursor[i].base);
  5990. }
  5991. }
  5992. #endif