intel_display.c 248 KB

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