intel_display.c 249 KB

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