intel_display.c 248 KB

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