intel_display.c 262 KB

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