intel_display.c 234 KB

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