intel_dp.c 172 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251
  1. /*
  2. * Copyright © 2008 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 DEALINGS
  21. * IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Keith Packard <keithp@keithp.com>
  25. *
  26. */
  27. #include <linux/i2c.h>
  28. #include <linux/slab.h>
  29. #include <linux/export.h>
  30. #include <linux/types.h>
  31. #include <linux/notifier.h>
  32. #include <linux/reboot.h>
  33. #include <asm/byteorder.h>
  34. #include <drm/drmP.h>
  35. #include <drm/drm_atomic_helper.h>
  36. #include <drm/drm_crtc.h>
  37. #include <drm/drm_crtc_helper.h>
  38. #include <drm/drm_edid.h>
  39. #include "intel_drv.h"
  40. #include <drm/i915_drm.h>
  41. #include "i915_drv.h"
  42. #define DP_LINK_CHECK_TIMEOUT (10 * 1000)
  43. /* Compliance test status bits */
  44. #define INTEL_DP_RESOLUTION_SHIFT_MASK 0
  45. #define INTEL_DP_RESOLUTION_PREFERRED (1 << INTEL_DP_RESOLUTION_SHIFT_MASK)
  46. #define INTEL_DP_RESOLUTION_STANDARD (2 << INTEL_DP_RESOLUTION_SHIFT_MASK)
  47. #define INTEL_DP_RESOLUTION_FAILSAFE (3 << INTEL_DP_RESOLUTION_SHIFT_MASK)
  48. struct dp_link_dpll {
  49. int clock;
  50. struct dpll dpll;
  51. };
  52. static const struct dp_link_dpll gen4_dpll[] = {
  53. { 162000,
  54. { .p1 = 2, .p2 = 10, .n = 2, .m1 = 23, .m2 = 8 } },
  55. { 270000,
  56. { .p1 = 1, .p2 = 10, .n = 1, .m1 = 14, .m2 = 2 } }
  57. };
  58. static const struct dp_link_dpll pch_dpll[] = {
  59. { 162000,
  60. { .p1 = 2, .p2 = 10, .n = 1, .m1 = 12, .m2 = 9 } },
  61. { 270000,
  62. { .p1 = 1, .p2 = 10, .n = 2, .m1 = 14, .m2 = 8 } }
  63. };
  64. static const struct dp_link_dpll vlv_dpll[] = {
  65. { 162000,
  66. { .p1 = 3, .p2 = 2, .n = 5, .m1 = 3, .m2 = 81 } },
  67. { 270000,
  68. { .p1 = 2, .p2 = 2, .n = 1, .m1 = 2, .m2 = 27 } }
  69. };
  70. /*
  71. * CHV supports eDP 1.4 that have more link rates.
  72. * Below only provides the fixed rate but exclude variable rate.
  73. */
  74. static const struct dp_link_dpll chv_dpll[] = {
  75. /*
  76. * CHV requires to program fractional division for m2.
  77. * m2 is stored in fixed point format using formula below
  78. * (m2_int << 22) | m2_fraction
  79. */
  80. { 162000, /* m2_int = 32, m2_fraction = 1677722 */
  81. { .p1 = 4, .p2 = 2, .n = 1, .m1 = 2, .m2 = 0x819999a } },
  82. { 270000, /* m2_int = 27, m2_fraction = 0 */
  83. { .p1 = 4, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } },
  84. { 540000, /* m2_int = 27, m2_fraction = 0 */
  85. { .p1 = 2, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } }
  86. };
  87. static const int bxt_rates[] = { 162000, 216000, 243000, 270000,
  88. 324000, 432000, 540000 };
  89. static const int skl_rates[] = { 162000, 216000, 270000,
  90. 324000, 432000, 540000 };
  91. static const int default_rates[] = { 162000, 270000, 540000 };
  92. /**
  93. * is_edp - is the given port attached to an eDP panel (either CPU or PCH)
  94. * @intel_dp: DP struct
  95. *
  96. * If a CPU or PCH DP output is attached to an eDP panel, this function
  97. * will return true, and false otherwise.
  98. */
  99. static bool is_edp(struct intel_dp *intel_dp)
  100. {
  101. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  102. return intel_dig_port->base.type == INTEL_OUTPUT_EDP;
  103. }
  104. static struct drm_device *intel_dp_to_dev(struct intel_dp *intel_dp)
  105. {
  106. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  107. return intel_dig_port->base.base.dev;
  108. }
  109. static struct intel_dp *intel_attached_dp(struct drm_connector *connector)
  110. {
  111. return enc_to_intel_dp(&intel_attached_encoder(connector)->base);
  112. }
  113. static void intel_dp_link_down(struct intel_dp *intel_dp);
  114. static bool edp_panel_vdd_on(struct intel_dp *intel_dp);
  115. static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync);
  116. static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp);
  117. static void vlv_steal_power_sequencer(struct drm_device *dev,
  118. enum pipe pipe);
  119. static void intel_dp_unset_edid(struct intel_dp *intel_dp);
  120. static int intel_dp_num_rates(u8 link_bw_code)
  121. {
  122. switch (link_bw_code) {
  123. default:
  124. WARN(1, "invalid max DP link bw val %x, using 1.62Gbps\n",
  125. link_bw_code);
  126. case DP_LINK_BW_1_62:
  127. return 1;
  128. case DP_LINK_BW_2_7:
  129. return 2;
  130. case DP_LINK_BW_5_4:
  131. return 3;
  132. }
  133. }
  134. /* update sink rates from dpcd */
  135. static void intel_dp_set_sink_rates(struct intel_dp *intel_dp)
  136. {
  137. int i, num_rates;
  138. num_rates = intel_dp_num_rates(intel_dp->dpcd[DP_MAX_LINK_RATE]);
  139. for (i = 0; i < num_rates; i++)
  140. intel_dp->sink_rates[i] = default_rates[i];
  141. intel_dp->num_sink_rates = num_rates;
  142. }
  143. /* Theoretical max between source and sink */
  144. static int intel_dp_max_common_rate(struct intel_dp *intel_dp)
  145. {
  146. return intel_dp->common_rates[intel_dp->num_common_rates - 1];
  147. }
  148. /* Theoretical max between source and sink */
  149. static int intel_dp_max_common_lane_count(struct intel_dp *intel_dp)
  150. {
  151. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  152. int source_max = intel_dig_port->max_lanes;
  153. int sink_max = drm_dp_max_lane_count(intel_dp->dpcd);
  154. return min(source_max, sink_max);
  155. }
  156. int intel_dp_max_lane_count(struct intel_dp *intel_dp)
  157. {
  158. return intel_dp->max_link_lane_count;
  159. }
  160. int
  161. intel_dp_link_required(int pixel_clock, int bpp)
  162. {
  163. /* pixel_clock is in kHz, divide bpp by 8 for bit to Byte conversion */
  164. return DIV_ROUND_UP(pixel_clock * bpp, 8);
  165. }
  166. int
  167. intel_dp_max_data_rate(int max_link_clock, int max_lanes)
  168. {
  169. /* max_link_clock is the link symbol clock (LS_Clk) in kHz and not the
  170. * link rate that is generally expressed in Gbps. Since, 8 bits of data
  171. * is transmitted every LS_Clk per lane, there is no need to account for
  172. * the channel encoding that is done in the PHY layer here.
  173. */
  174. return max_link_clock * max_lanes;
  175. }
  176. static int
  177. intel_dp_downstream_max_dotclock(struct intel_dp *intel_dp)
  178. {
  179. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  180. struct intel_encoder *encoder = &intel_dig_port->base;
  181. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  182. int max_dotclk = dev_priv->max_dotclk_freq;
  183. int ds_max_dotclk;
  184. int type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
  185. if (type != DP_DS_PORT_TYPE_VGA)
  186. return max_dotclk;
  187. ds_max_dotclk = drm_dp_downstream_max_clock(intel_dp->dpcd,
  188. intel_dp->downstream_ports);
  189. if (ds_max_dotclk != 0)
  190. max_dotclk = min(max_dotclk, ds_max_dotclk);
  191. return max_dotclk;
  192. }
  193. static void
  194. intel_dp_set_source_rates(struct intel_dp *intel_dp)
  195. {
  196. struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
  197. struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
  198. const int *source_rates;
  199. int size;
  200. /* This should only be done once */
  201. WARN_ON(intel_dp->source_rates || intel_dp->num_source_rates);
  202. if (IS_GEN9_LP(dev_priv)) {
  203. source_rates = bxt_rates;
  204. size = ARRAY_SIZE(bxt_rates);
  205. } else if (IS_GEN9_BC(dev_priv)) {
  206. source_rates = skl_rates;
  207. size = ARRAY_SIZE(skl_rates);
  208. } else {
  209. source_rates = default_rates;
  210. size = ARRAY_SIZE(default_rates);
  211. }
  212. /* This depends on the fact that 5.4 is last value in the array */
  213. if (!intel_dp_source_supports_hbr2(intel_dp))
  214. size--;
  215. intel_dp->source_rates = source_rates;
  216. intel_dp->num_source_rates = size;
  217. }
  218. static int intersect_rates(const int *source_rates, int source_len,
  219. const int *sink_rates, int sink_len,
  220. int *common_rates)
  221. {
  222. int i = 0, j = 0, k = 0;
  223. while (i < source_len && j < sink_len) {
  224. if (source_rates[i] == sink_rates[j]) {
  225. if (WARN_ON(k >= DP_MAX_SUPPORTED_RATES))
  226. return k;
  227. common_rates[k] = source_rates[i];
  228. ++k;
  229. ++i;
  230. ++j;
  231. } else if (source_rates[i] < sink_rates[j]) {
  232. ++i;
  233. } else {
  234. ++j;
  235. }
  236. }
  237. return k;
  238. }
  239. /* return index of rate in rates array, or -1 if not found */
  240. static int intel_dp_rate_index(const int *rates, int len, int rate)
  241. {
  242. int i;
  243. for (i = 0; i < len; i++)
  244. if (rate == rates[i])
  245. return i;
  246. return -1;
  247. }
  248. static void intel_dp_set_common_rates(struct intel_dp *intel_dp)
  249. {
  250. WARN_ON(!intel_dp->num_source_rates || !intel_dp->num_sink_rates);
  251. intel_dp->num_common_rates = intersect_rates(intel_dp->source_rates,
  252. intel_dp->num_source_rates,
  253. intel_dp->sink_rates,
  254. intel_dp->num_sink_rates,
  255. intel_dp->common_rates);
  256. /* Paranoia, there should always be something in common. */
  257. if (WARN_ON(intel_dp->num_common_rates == 0)) {
  258. intel_dp->common_rates[0] = default_rates[0];
  259. intel_dp->num_common_rates = 1;
  260. }
  261. }
  262. /* get length of common rates potentially limited by max_rate */
  263. static int intel_dp_common_len_rate_limit(struct intel_dp *intel_dp,
  264. int max_rate)
  265. {
  266. const int *common_rates = intel_dp->common_rates;
  267. int i, common_len = intel_dp->num_common_rates;
  268. /* Limit results by potentially reduced max rate */
  269. for (i = 0; i < common_len; i++) {
  270. if (common_rates[common_len - i - 1] <= max_rate)
  271. return common_len - i;
  272. }
  273. return 0;
  274. }
  275. static bool intel_dp_link_params_valid(struct intel_dp *intel_dp)
  276. {
  277. /*
  278. * FIXME: we need to synchronize the current link parameters with
  279. * hardware readout. Currently fast link training doesn't work on
  280. * boot-up.
  281. */
  282. if (intel_dp->link_rate == 0 ||
  283. intel_dp->link_rate > intel_dp->max_link_rate)
  284. return false;
  285. if (intel_dp->lane_count == 0 ||
  286. intel_dp->lane_count > intel_dp_max_lane_count(intel_dp))
  287. return false;
  288. return true;
  289. }
  290. int intel_dp_get_link_train_fallback_values(struct intel_dp *intel_dp,
  291. int link_rate, uint8_t lane_count)
  292. {
  293. int index;
  294. index = intel_dp_rate_index(intel_dp->common_rates,
  295. intel_dp->num_common_rates,
  296. link_rate);
  297. if (index > 0) {
  298. intel_dp->max_link_rate = intel_dp->common_rates[index - 1];
  299. intel_dp->max_link_lane_count = lane_count;
  300. } else if (lane_count > 1) {
  301. intel_dp->max_link_rate = intel_dp_max_common_rate(intel_dp);
  302. intel_dp->max_link_lane_count = lane_count >> 1;
  303. } else {
  304. DRM_ERROR("Link Training Unsuccessful\n");
  305. return -1;
  306. }
  307. return 0;
  308. }
  309. static enum drm_mode_status
  310. intel_dp_mode_valid(struct drm_connector *connector,
  311. struct drm_display_mode *mode)
  312. {
  313. struct intel_dp *intel_dp = intel_attached_dp(connector);
  314. struct intel_connector *intel_connector = to_intel_connector(connector);
  315. struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
  316. int target_clock = mode->clock;
  317. int max_rate, mode_rate, max_lanes, max_link_clock;
  318. int max_dotclk;
  319. max_dotclk = intel_dp_downstream_max_dotclock(intel_dp);
  320. if (is_edp(intel_dp) && fixed_mode) {
  321. if (mode->hdisplay > fixed_mode->hdisplay)
  322. return MODE_PANEL;
  323. if (mode->vdisplay > fixed_mode->vdisplay)
  324. return MODE_PANEL;
  325. target_clock = fixed_mode->clock;
  326. }
  327. max_link_clock = intel_dp_max_link_rate(intel_dp);
  328. max_lanes = intel_dp_max_lane_count(intel_dp);
  329. max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
  330. mode_rate = intel_dp_link_required(target_clock, 18);
  331. if (mode_rate > max_rate || target_clock > max_dotclk)
  332. return MODE_CLOCK_HIGH;
  333. if (mode->clock < 10000)
  334. return MODE_CLOCK_LOW;
  335. if (mode->flags & DRM_MODE_FLAG_DBLCLK)
  336. return MODE_H_ILLEGAL;
  337. return MODE_OK;
  338. }
  339. uint32_t intel_dp_pack_aux(const uint8_t *src, int src_bytes)
  340. {
  341. int i;
  342. uint32_t v = 0;
  343. if (src_bytes > 4)
  344. src_bytes = 4;
  345. for (i = 0; i < src_bytes; i++)
  346. v |= ((uint32_t) src[i]) << ((3-i) * 8);
  347. return v;
  348. }
  349. static void intel_dp_unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
  350. {
  351. int i;
  352. if (dst_bytes > 4)
  353. dst_bytes = 4;
  354. for (i = 0; i < dst_bytes; i++)
  355. dst[i] = src >> ((3-i) * 8);
  356. }
  357. static void
  358. intel_dp_init_panel_power_sequencer(struct drm_device *dev,
  359. struct intel_dp *intel_dp);
  360. static void
  361. intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
  362. struct intel_dp *intel_dp,
  363. bool force_disable_vdd);
  364. static void
  365. intel_dp_pps_init(struct drm_device *dev, struct intel_dp *intel_dp);
  366. static void pps_lock(struct intel_dp *intel_dp)
  367. {
  368. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  369. struct intel_encoder *encoder = &intel_dig_port->base;
  370. struct drm_device *dev = encoder->base.dev;
  371. struct drm_i915_private *dev_priv = to_i915(dev);
  372. /*
  373. * See vlv_power_sequencer_reset() why we need
  374. * a power domain reference here.
  375. */
  376. intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
  377. mutex_lock(&dev_priv->pps_mutex);
  378. }
  379. static void pps_unlock(struct intel_dp *intel_dp)
  380. {
  381. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  382. struct intel_encoder *encoder = &intel_dig_port->base;
  383. struct drm_device *dev = encoder->base.dev;
  384. struct drm_i915_private *dev_priv = to_i915(dev);
  385. mutex_unlock(&dev_priv->pps_mutex);
  386. intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
  387. }
  388. static void
  389. vlv_power_sequencer_kick(struct intel_dp *intel_dp)
  390. {
  391. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  392. struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
  393. enum pipe pipe = intel_dp->pps_pipe;
  394. bool pll_enabled, release_cl_override = false;
  395. enum dpio_phy phy = DPIO_PHY(pipe);
  396. enum dpio_channel ch = vlv_pipe_to_channel(pipe);
  397. uint32_t DP;
  398. if (WARN(I915_READ(intel_dp->output_reg) & DP_PORT_EN,
  399. "skipping pipe %c power seqeuncer kick due to port %c being active\n",
  400. pipe_name(pipe), port_name(intel_dig_port->port)))
  401. return;
  402. DRM_DEBUG_KMS("kicking pipe %c power sequencer for port %c\n",
  403. pipe_name(pipe), port_name(intel_dig_port->port));
  404. /* Preserve the BIOS-computed detected bit. This is
  405. * supposed to be read-only.
  406. */
  407. DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
  408. DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
  409. DP |= DP_PORT_WIDTH(1);
  410. DP |= DP_LINK_TRAIN_PAT_1;
  411. if (IS_CHERRYVIEW(dev_priv))
  412. DP |= DP_PIPE_SELECT_CHV(pipe);
  413. else if (pipe == PIPE_B)
  414. DP |= DP_PIPEB_SELECT;
  415. pll_enabled = I915_READ(DPLL(pipe)) & DPLL_VCO_ENABLE;
  416. /*
  417. * The DPLL for the pipe must be enabled for this to work.
  418. * So enable temporarily it if it's not already enabled.
  419. */
  420. if (!pll_enabled) {
  421. release_cl_override = IS_CHERRYVIEW(dev_priv) &&
  422. !chv_phy_powergate_ch(dev_priv, phy, ch, true);
  423. if (vlv_force_pll_on(dev_priv, pipe, IS_CHERRYVIEW(dev_priv) ?
  424. &chv_dpll[0].dpll : &vlv_dpll[0].dpll)) {
  425. DRM_ERROR("Failed to force on pll for pipe %c!\n",
  426. pipe_name(pipe));
  427. return;
  428. }
  429. }
  430. /*
  431. * Similar magic as in intel_dp_enable_port().
  432. * We _must_ do this port enable + disable trick
  433. * to make this power seqeuencer lock onto the port.
  434. * Otherwise even VDD force bit won't work.
  435. */
  436. I915_WRITE(intel_dp->output_reg, DP);
  437. POSTING_READ(intel_dp->output_reg);
  438. I915_WRITE(intel_dp->output_reg, DP | DP_PORT_EN);
  439. POSTING_READ(intel_dp->output_reg);
  440. I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
  441. POSTING_READ(intel_dp->output_reg);
  442. if (!pll_enabled) {
  443. vlv_force_pll_off(dev_priv, pipe);
  444. if (release_cl_override)
  445. chv_phy_powergate_ch(dev_priv, phy, ch, false);
  446. }
  447. }
  448. static enum pipe vlv_find_free_pps(struct drm_i915_private *dev_priv)
  449. {
  450. struct intel_encoder *encoder;
  451. unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B);
  452. /*
  453. * We don't have power sequencer currently.
  454. * Pick one that's not used by other ports.
  455. */
  456. for_each_intel_encoder(&dev_priv->drm, encoder) {
  457. struct intel_dp *intel_dp;
  458. if (encoder->type != INTEL_OUTPUT_DP &&
  459. encoder->type != INTEL_OUTPUT_EDP)
  460. continue;
  461. intel_dp = enc_to_intel_dp(&encoder->base);
  462. if (encoder->type == INTEL_OUTPUT_EDP) {
  463. WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
  464. intel_dp->active_pipe != intel_dp->pps_pipe);
  465. if (intel_dp->pps_pipe != INVALID_PIPE)
  466. pipes &= ~(1 << intel_dp->pps_pipe);
  467. } else {
  468. WARN_ON(intel_dp->pps_pipe != INVALID_PIPE);
  469. if (intel_dp->active_pipe != INVALID_PIPE)
  470. pipes &= ~(1 << intel_dp->active_pipe);
  471. }
  472. }
  473. if (pipes == 0)
  474. return INVALID_PIPE;
  475. return ffs(pipes) - 1;
  476. }
  477. static enum pipe
  478. vlv_power_sequencer_pipe(struct intel_dp *intel_dp)
  479. {
  480. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  481. struct drm_device *dev = intel_dig_port->base.base.dev;
  482. struct drm_i915_private *dev_priv = to_i915(dev);
  483. enum pipe pipe;
  484. lockdep_assert_held(&dev_priv->pps_mutex);
  485. /* We should never land here with regular DP ports */
  486. WARN_ON(!is_edp(intel_dp));
  487. WARN_ON(intel_dp->active_pipe != INVALID_PIPE &&
  488. intel_dp->active_pipe != intel_dp->pps_pipe);
  489. if (intel_dp->pps_pipe != INVALID_PIPE)
  490. return intel_dp->pps_pipe;
  491. pipe = vlv_find_free_pps(dev_priv);
  492. /*
  493. * Didn't find one. This should not happen since there
  494. * are two power sequencers and up to two eDP ports.
  495. */
  496. if (WARN_ON(pipe == INVALID_PIPE))
  497. pipe = PIPE_A;
  498. vlv_steal_power_sequencer(dev, pipe);
  499. intel_dp->pps_pipe = pipe;
  500. DRM_DEBUG_KMS("picked pipe %c power sequencer for port %c\n",
  501. pipe_name(intel_dp->pps_pipe),
  502. port_name(intel_dig_port->port));
  503. /* init power sequencer on this pipe and port */
  504. intel_dp_init_panel_power_sequencer(dev, intel_dp);
  505. intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, true);
  506. /*
  507. * Even vdd force doesn't work until we've made
  508. * the power sequencer lock in on the port.
  509. */
  510. vlv_power_sequencer_kick(intel_dp);
  511. return intel_dp->pps_pipe;
  512. }
  513. static int
  514. bxt_power_sequencer_idx(struct intel_dp *intel_dp)
  515. {
  516. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  517. struct drm_device *dev = intel_dig_port->base.base.dev;
  518. struct drm_i915_private *dev_priv = to_i915(dev);
  519. lockdep_assert_held(&dev_priv->pps_mutex);
  520. /* We should never land here with regular DP ports */
  521. WARN_ON(!is_edp(intel_dp));
  522. /*
  523. * TODO: BXT has 2 PPS instances. The correct port->PPS instance
  524. * mapping needs to be retrieved from VBT, for now just hard-code to
  525. * use instance #0 always.
  526. */
  527. if (!intel_dp->pps_reset)
  528. return 0;
  529. intel_dp->pps_reset = false;
  530. /*
  531. * Only the HW needs to be reprogrammed, the SW state is fixed and
  532. * has been setup during connector init.
  533. */
  534. intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
  535. return 0;
  536. }
  537. typedef bool (*vlv_pipe_check)(struct drm_i915_private *dev_priv,
  538. enum pipe pipe);
  539. static bool vlv_pipe_has_pp_on(struct drm_i915_private *dev_priv,
  540. enum pipe pipe)
  541. {
  542. return I915_READ(PP_STATUS(pipe)) & PP_ON;
  543. }
  544. static bool vlv_pipe_has_vdd_on(struct drm_i915_private *dev_priv,
  545. enum pipe pipe)
  546. {
  547. return I915_READ(PP_CONTROL(pipe)) & EDP_FORCE_VDD;
  548. }
  549. static bool vlv_pipe_any(struct drm_i915_private *dev_priv,
  550. enum pipe pipe)
  551. {
  552. return true;
  553. }
  554. static enum pipe
  555. vlv_initial_pps_pipe(struct drm_i915_private *dev_priv,
  556. enum port port,
  557. vlv_pipe_check pipe_check)
  558. {
  559. enum pipe pipe;
  560. for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) {
  561. u32 port_sel = I915_READ(PP_ON_DELAYS(pipe)) &
  562. PANEL_PORT_SELECT_MASK;
  563. if (port_sel != PANEL_PORT_SELECT_VLV(port))
  564. continue;
  565. if (!pipe_check(dev_priv, pipe))
  566. continue;
  567. return pipe;
  568. }
  569. return INVALID_PIPE;
  570. }
  571. static void
  572. vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp)
  573. {
  574. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  575. struct drm_device *dev = intel_dig_port->base.base.dev;
  576. struct drm_i915_private *dev_priv = to_i915(dev);
  577. enum port port = intel_dig_port->port;
  578. lockdep_assert_held(&dev_priv->pps_mutex);
  579. /* try to find a pipe with this port selected */
  580. /* first pick one where the panel is on */
  581. intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
  582. vlv_pipe_has_pp_on);
  583. /* didn't find one? pick one where vdd is on */
  584. if (intel_dp->pps_pipe == INVALID_PIPE)
  585. intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
  586. vlv_pipe_has_vdd_on);
  587. /* didn't find one? pick one with just the correct port */
  588. if (intel_dp->pps_pipe == INVALID_PIPE)
  589. intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
  590. vlv_pipe_any);
  591. /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */
  592. if (intel_dp->pps_pipe == INVALID_PIPE) {
  593. DRM_DEBUG_KMS("no initial power sequencer for port %c\n",
  594. port_name(port));
  595. return;
  596. }
  597. DRM_DEBUG_KMS("initial power sequencer for port %c: pipe %c\n",
  598. port_name(port), pipe_name(intel_dp->pps_pipe));
  599. intel_dp_init_panel_power_sequencer(dev, intel_dp);
  600. intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
  601. }
  602. void intel_power_sequencer_reset(struct drm_i915_private *dev_priv)
  603. {
  604. struct drm_device *dev = &dev_priv->drm;
  605. struct intel_encoder *encoder;
  606. if (WARN_ON(!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
  607. !IS_GEN9_LP(dev_priv)))
  608. return;
  609. /*
  610. * We can't grab pps_mutex here due to deadlock with power_domain
  611. * mutex when power_domain functions are called while holding pps_mutex.
  612. * That also means that in order to use pps_pipe the code needs to
  613. * hold both a power domain reference and pps_mutex, and the power domain
  614. * reference get/put must be done while _not_ holding pps_mutex.
  615. * pps_{lock,unlock}() do these steps in the correct order, so one
  616. * should use them always.
  617. */
  618. for_each_intel_encoder(dev, encoder) {
  619. struct intel_dp *intel_dp;
  620. if (encoder->type != INTEL_OUTPUT_DP &&
  621. encoder->type != INTEL_OUTPUT_EDP)
  622. continue;
  623. intel_dp = enc_to_intel_dp(&encoder->base);
  624. WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
  625. if (encoder->type != INTEL_OUTPUT_EDP)
  626. continue;
  627. if (IS_GEN9_LP(dev_priv))
  628. intel_dp->pps_reset = true;
  629. else
  630. intel_dp->pps_pipe = INVALID_PIPE;
  631. }
  632. }
  633. struct pps_registers {
  634. i915_reg_t pp_ctrl;
  635. i915_reg_t pp_stat;
  636. i915_reg_t pp_on;
  637. i915_reg_t pp_off;
  638. i915_reg_t pp_div;
  639. };
  640. static void intel_pps_get_registers(struct drm_i915_private *dev_priv,
  641. struct intel_dp *intel_dp,
  642. struct pps_registers *regs)
  643. {
  644. int pps_idx = 0;
  645. memset(regs, 0, sizeof(*regs));
  646. if (IS_GEN9_LP(dev_priv))
  647. pps_idx = bxt_power_sequencer_idx(intel_dp);
  648. else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
  649. pps_idx = vlv_power_sequencer_pipe(intel_dp);
  650. regs->pp_ctrl = PP_CONTROL(pps_idx);
  651. regs->pp_stat = PP_STATUS(pps_idx);
  652. regs->pp_on = PP_ON_DELAYS(pps_idx);
  653. regs->pp_off = PP_OFF_DELAYS(pps_idx);
  654. if (!IS_GEN9_LP(dev_priv))
  655. regs->pp_div = PP_DIVISOR(pps_idx);
  656. }
  657. static i915_reg_t
  658. _pp_ctrl_reg(struct intel_dp *intel_dp)
  659. {
  660. struct pps_registers regs;
  661. intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
  662. &regs);
  663. return regs.pp_ctrl;
  664. }
  665. static i915_reg_t
  666. _pp_stat_reg(struct intel_dp *intel_dp)
  667. {
  668. struct pps_registers regs;
  669. intel_pps_get_registers(to_i915(intel_dp_to_dev(intel_dp)), intel_dp,
  670. &regs);
  671. return regs.pp_stat;
  672. }
  673. /* Reboot notifier handler to shutdown panel power to guarantee T12 timing
  674. This function only applicable when panel PM state is not to be tracked */
  675. static int edp_notify_handler(struct notifier_block *this, unsigned long code,
  676. void *unused)
  677. {
  678. struct intel_dp *intel_dp = container_of(this, typeof(* intel_dp),
  679. edp_notifier);
  680. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  681. struct drm_i915_private *dev_priv = to_i915(dev);
  682. if (!is_edp(intel_dp) || code != SYS_RESTART)
  683. return 0;
  684. pps_lock(intel_dp);
  685. if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
  686. enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
  687. i915_reg_t pp_ctrl_reg, pp_div_reg;
  688. u32 pp_div;
  689. pp_ctrl_reg = PP_CONTROL(pipe);
  690. pp_div_reg = PP_DIVISOR(pipe);
  691. pp_div = I915_READ(pp_div_reg);
  692. pp_div &= PP_REFERENCE_DIVIDER_MASK;
  693. /* 0x1F write to PP_DIV_REG sets max cycle delay */
  694. I915_WRITE(pp_div_reg, pp_div | 0x1F);
  695. I915_WRITE(pp_ctrl_reg, PANEL_UNLOCK_REGS | PANEL_POWER_OFF);
  696. msleep(intel_dp->panel_power_cycle_delay);
  697. }
  698. pps_unlock(intel_dp);
  699. return 0;
  700. }
  701. static bool edp_have_panel_power(struct intel_dp *intel_dp)
  702. {
  703. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  704. struct drm_i915_private *dev_priv = to_i915(dev);
  705. lockdep_assert_held(&dev_priv->pps_mutex);
  706. if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
  707. intel_dp->pps_pipe == INVALID_PIPE)
  708. return false;
  709. return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0;
  710. }
  711. static bool edp_have_panel_vdd(struct intel_dp *intel_dp)
  712. {
  713. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  714. struct drm_i915_private *dev_priv = to_i915(dev);
  715. lockdep_assert_held(&dev_priv->pps_mutex);
  716. if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
  717. intel_dp->pps_pipe == INVALID_PIPE)
  718. return false;
  719. return I915_READ(_pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD;
  720. }
  721. static void
  722. intel_dp_check_edp(struct intel_dp *intel_dp)
  723. {
  724. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  725. struct drm_i915_private *dev_priv = to_i915(dev);
  726. if (!is_edp(intel_dp))
  727. return;
  728. if (!edp_have_panel_power(intel_dp) && !edp_have_panel_vdd(intel_dp)) {
  729. WARN(1, "eDP powered off while attempting aux channel communication.\n");
  730. DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
  731. I915_READ(_pp_stat_reg(intel_dp)),
  732. I915_READ(_pp_ctrl_reg(intel_dp)));
  733. }
  734. }
  735. static uint32_t
  736. intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq)
  737. {
  738. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  739. struct drm_device *dev = intel_dig_port->base.base.dev;
  740. struct drm_i915_private *dev_priv = to_i915(dev);
  741. i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
  742. uint32_t status;
  743. bool done;
  744. #define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
  745. if (has_aux_irq)
  746. done = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
  747. msecs_to_jiffies_timeout(10));
  748. else
  749. done = wait_for(C, 10) == 0;
  750. if (!done)
  751. DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n",
  752. has_aux_irq);
  753. #undef C
  754. return status;
  755. }
  756. static uint32_t g4x_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
  757. {
  758. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  759. struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
  760. if (index)
  761. return 0;
  762. /*
  763. * The clock divider is based off the hrawclk, and would like to run at
  764. * 2MHz. So, take the hrawclk value and divide by 2000 and use that
  765. */
  766. return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
  767. }
  768. static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
  769. {
  770. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  771. struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
  772. if (index)
  773. return 0;
  774. /*
  775. * The clock divider is based off the cdclk or PCH rawclk, and would
  776. * like to run at 2MHz. So, take the cdclk or PCH rawclk value and
  777. * divide by 2000 and use that
  778. */
  779. if (intel_dig_port->port == PORT_A)
  780. return DIV_ROUND_CLOSEST(dev_priv->cdclk.hw.cdclk, 2000);
  781. else
  782. return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
  783. }
  784. static uint32_t hsw_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
  785. {
  786. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  787. struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
  788. if (intel_dig_port->port != PORT_A && HAS_PCH_LPT_H(dev_priv)) {
  789. /* Workaround for non-ULT HSW */
  790. switch (index) {
  791. case 0: return 63;
  792. case 1: return 72;
  793. default: return 0;
  794. }
  795. }
  796. return ilk_get_aux_clock_divider(intel_dp, index);
  797. }
  798. static uint32_t skl_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
  799. {
  800. /*
  801. * SKL doesn't need us to program the AUX clock divider (Hardware will
  802. * derive the clock from CDCLK automatically). We still implement the
  803. * get_aux_clock_divider vfunc to plug-in into the existing code.
  804. */
  805. return index ? 0 : 1;
  806. }
  807. static uint32_t g4x_get_aux_send_ctl(struct intel_dp *intel_dp,
  808. bool has_aux_irq,
  809. int send_bytes,
  810. uint32_t aux_clock_divider)
  811. {
  812. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  813. struct drm_i915_private *dev_priv =
  814. to_i915(intel_dig_port->base.base.dev);
  815. uint32_t precharge, timeout;
  816. if (IS_GEN6(dev_priv))
  817. precharge = 3;
  818. else
  819. precharge = 5;
  820. if (IS_BROADWELL(dev_priv) && intel_dig_port->port == PORT_A)
  821. timeout = DP_AUX_CH_CTL_TIME_OUT_600us;
  822. else
  823. timeout = DP_AUX_CH_CTL_TIME_OUT_400us;
  824. return DP_AUX_CH_CTL_SEND_BUSY |
  825. DP_AUX_CH_CTL_DONE |
  826. (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
  827. DP_AUX_CH_CTL_TIME_OUT_ERROR |
  828. timeout |
  829. DP_AUX_CH_CTL_RECEIVE_ERROR |
  830. (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
  831. (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
  832. (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT);
  833. }
  834. static uint32_t skl_get_aux_send_ctl(struct intel_dp *intel_dp,
  835. bool has_aux_irq,
  836. int send_bytes,
  837. uint32_t unused)
  838. {
  839. return DP_AUX_CH_CTL_SEND_BUSY |
  840. DP_AUX_CH_CTL_DONE |
  841. (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
  842. DP_AUX_CH_CTL_TIME_OUT_ERROR |
  843. DP_AUX_CH_CTL_TIME_OUT_1600us |
  844. DP_AUX_CH_CTL_RECEIVE_ERROR |
  845. (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
  846. DP_AUX_CH_CTL_FW_SYNC_PULSE_SKL(32) |
  847. DP_AUX_CH_CTL_SYNC_PULSE_SKL(32);
  848. }
  849. static int
  850. intel_dp_aux_ch(struct intel_dp *intel_dp,
  851. const uint8_t *send, int send_bytes,
  852. uint8_t *recv, int recv_size)
  853. {
  854. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  855. struct drm_i915_private *dev_priv =
  856. to_i915(intel_dig_port->base.base.dev);
  857. i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
  858. uint32_t aux_clock_divider;
  859. int i, ret, recv_bytes;
  860. uint32_t status;
  861. int try, clock = 0;
  862. bool has_aux_irq = HAS_AUX_IRQ(dev_priv);
  863. bool vdd;
  864. pps_lock(intel_dp);
  865. /*
  866. * We will be called with VDD already enabled for dpcd/edid/oui reads.
  867. * In such cases we want to leave VDD enabled and it's up to upper layers
  868. * to turn it off. But for eg. i2c-dev access we need to turn it on/off
  869. * ourselves.
  870. */
  871. vdd = edp_panel_vdd_on(intel_dp);
  872. /* dp aux is extremely sensitive to irq latency, hence request the
  873. * lowest possible wakeup latency and so prevent the cpu from going into
  874. * deep sleep states.
  875. */
  876. pm_qos_update_request(&dev_priv->pm_qos, 0);
  877. intel_dp_check_edp(intel_dp);
  878. /* Try to wait for any previous AUX channel activity */
  879. for (try = 0; try < 3; try++) {
  880. status = I915_READ_NOTRACE(ch_ctl);
  881. if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
  882. break;
  883. msleep(1);
  884. }
  885. if (try == 3) {
  886. static u32 last_status = -1;
  887. const u32 status = I915_READ(ch_ctl);
  888. if (status != last_status) {
  889. WARN(1, "dp_aux_ch not started status 0x%08x\n",
  890. status);
  891. last_status = status;
  892. }
  893. ret = -EBUSY;
  894. goto out;
  895. }
  896. /* Only 5 data registers! */
  897. if (WARN_ON(send_bytes > 20 || recv_size > 20)) {
  898. ret = -E2BIG;
  899. goto out;
  900. }
  901. while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) {
  902. u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp,
  903. has_aux_irq,
  904. send_bytes,
  905. aux_clock_divider);
  906. /* Must try at least 3 times according to DP spec */
  907. for (try = 0; try < 5; try++) {
  908. /* Load the send data into the aux channel data registers */
  909. for (i = 0; i < send_bytes; i += 4)
  910. I915_WRITE(intel_dp->aux_ch_data_reg[i >> 2],
  911. intel_dp_pack_aux(send + i,
  912. send_bytes - i));
  913. /* Send the command and wait for it to complete */
  914. I915_WRITE(ch_ctl, send_ctl);
  915. status = intel_dp_aux_wait_done(intel_dp, has_aux_irq);
  916. /* Clear done status and any errors */
  917. I915_WRITE(ch_ctl,
  918. status |
  919. DP_AUX_CH_CTL_DONE |
  920. DP_AUX_CH_CTL_TIME_OUT_ERROR |
  921. DP_AUX_CH_CTL_RECEIVE_ERROR);
  922. if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR)
  923. continue;
  924. /* DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2
  925. * 400us delay required for errors and timeouts
  926. * Timeout errors from the HW already meet this
  927. * requirement so skip to next iteration
  928. */
  929. if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
  930. usleep_range(400, 500);
  931. continue;
  932. }
  933. if (status & DP_AUX_CH_CTL_DONE)
  934. goto done;
  935. }
  936. }
  937. if ((status & DP_AUX_CH_CTL_DONE) == 0) {
  938. DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
  939. ret = -EBUSY;
  940. goto out;
  941. }
  942. done:
  943. /* Check for timeout or receive error.
  944. * Timeouts occur when the sink is not connected
  945. */
  946. if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
  947. DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
  948. ret = -EIO;
  949. goto out;
  950. }
  951. /* Timeouts occur when the device isn't connected, so they're
  952. * "normal" -- don't fill the kernel log with these */
  953. if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
  954. DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
  955. ret = -ETIMEDOUT;
  956. goto out;
  957. }
  958. /* Unload any bytes sent back from the other side */
  959. recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
  960. DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
  961. /*
  962. * By BSpec: "Message sizes of 0 or >20 are not allowed."
  963. * We have no idea of what happened so we return -EBUSY so
  964. * drm layer takes care for the necessary retries.
  965. */
  966. if (recv_bytes == 0 || recv_bytes > 20) {
  967. DRM_DEBUG_KMS("Forbidden recv_bytes = %d on aux transaction\n",
  968. recv_bytes);
  969. /*
  970. * FIXME: This patch was created on top of a series that
  971. * organize the retries at drm level. There EBUSY should
  972. * also take care for 1ms wait before retrying.
  973. * That aux retries re-org is still needed and after that is
  974. * merged we remove this sleep from here.
  975. */
  976. usleep_range(1000, 1500);
  977. ret = -EBUSY;
  978. goto out;
  979. }
  980. if (recv_bytes > recv_size)
  981. recv_bytes = recv_size;
  982. for (i = 0; i < recv_bytes; i += 4)
  983. intel_dp_unpack_aux(I915_READ(intel_dp->aux_ch_data_reg[i >> 2]),
  984. recv + i, recv_bytes - i);
  985. ret = recv_bytes;
  986. out:
  987. pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE);
  988. if (vdd)
  989. edp_panel_vdd_off(intel_dp, false);
  990. pps_unlock(intel_dp);
  991. return ret;
  992. }
  993. #define BARE_ADDRESS_SIZE 3
  994. #define HEADER_SIZE (BARE_ADDRESS_SIZE + 1)
  995. static ssize_t
  996. intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
  997. {
  998. struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux);
  999. uint8_t txbuf[20], rxbuf[20];
  1000. size_t txsize, rxsize;
  1001. int ret;
  1002. txbuf[0] = (msg->request << 4) |
  1003. ((msg->address >> 16) & 0xf);
  1004. txbuf[1] = (msg->address >> 8) & 0xff;
  1005. txbuf[2] = msg->address & 0xff;
  1006. txbuf[3] = msg->size - 1;
  1007. switch (msg->request & ~DP_AUX_I2C_MOT) {
  1008. case DP_AUX_NATIVE_WRITE:
  1009. case DP_AUX_I2C_WRITE:
  1010. case DP_AUX_I2C_WRITE_STATUS_UPDATE:
  1011. txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE;
  1012. rxsize = 2; /* 0 or 1 data bytes */
  1013. if (WARN_ON(txsize > 20))
  1014. return -E2BIG;
  1015. WARN_ON(!msg->buffer != !msg->size);
  1016. if (msg->buffer)
  1017. memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
  1018. ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
  1019. if (ret > 0) {
  1020. msg->reply = rxbuf[0] >> 4;
  1021. if (ret > 1) {
  1022. /* Number of bytes written in a short write. */
  1023. ret = clamp_t(int, rxbuf[1], 0, msg->size);
  1024. } else {
  1025. /* Return payload size. */
  1026. ret = msg->size;
  1027. }
  1028. }
  1029. break;
  1030. case DP_AUX_NATIVE_READ:
  1031. case DP_AUX_I2C_READ:
  1032. txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE;
  1033. rxsize = msg->size + 1;
  1034. if (WARN_ON(rxsize > 20))
  1035. return -E2BIG;
  1036. ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
  1037. if (ret > 0) {
  1038. msg->reply = rxbuf[0] >> 4;
  1039. /*
  1040. * Assume happy day, and copy the data. The caller is
  1041. * expected to check msg->reply before touching it.
  1042. *
  1043. * Return payload size.
  1044. */
  1045. ret--;
  1046. memcpy(msg->buffer, rxbuf + 1, ret);
  1047. }
  1048. break;
  1049. default:
  1050. ret = -EINVAL;
  1051. break;
  1052. }
  1053. return ret;
  1054. }
  1055. static enum port intel_aux_port(struct drm_i915_private *dev_priv,
  1056. enum port port)
  1057. {
  1058. const struct ddi_vbt_port_info *info =
  1059. &dev_priv->vbt.ddi_port_info[port];
  1060. enum port aux_port;
  1061. if (!info->alternate_aux_channel) {
  1062. DRM_DEBUG_KMS("using AUX %c for port %c (platform default)\n",
  1063. port_name(port), port_name(port));
  1064. return port;
  1065. }
  1066. switch (info->alternate_aux_channel) {
  1067. case DP_AUX_A:
  1068. aux_port = PORT_A;
  1069. break;
  1070. case DP_AUX_B:
  1071. aux_port = PORT_B;
  1072. break;
  1073. case DP_AUX_C:
  1074. aux_port = PORT_C;
  1075. break;
  1076. case DP_AUX_D:
  1077. aux_port = PORT_D;
  1078. break;
  1079. default:
  1080. MISSING_CASE(info->alternate_aux_channel);
  1081. aux_port = PORT_A;
  1082. break;
  1083. }
  1084. DRM_DEBUG_KMS("using AUX %c for port %c (VBT)\n",
  1085. port_name(aux_port), port_name(port));
  1086. return aux_port;
  1087. }
  1088. static i915_reg_t g4x_aux_ctl_reg(struct drm_i915_private *dev_priv,
  1089. enum port port)
  1090. {
  1091. switch (port) {
  1092. case PORT_B:
  1093. case PORT_C:
  1094. case PORT_D:
  1095. return DP_AUX_CH_CTL(port);
  1096. default:
  1097. MISSING_CASE(port);
  1098. return DP_AUX_CH_CTL(PORT_B);
  1099. }
  1100. }
  1101. static i915_reg_t g4x_aux_data_reg(struct drm_i915_private *dev_priv,
  1102. enum port port, int index)
  1103. {
  1104. switch (port) {
  1105. case PORT_B:
  1106. case PORT_C:
  1107. case PORT_D:
  1108. return DP_AUX_CH_DATA(port, index);
  1109. default:
  1110. MISSING_CASE(port);
  1111. return DP_AUX_CH_DATA(PORT_B, index);
  1112. }
  1113. }
  1114. static i915_reg_t ilk_aux_ctl_reg(struct drm_i915_private *dev_priv,
  1115. enum port port)
  1116. {
  1117. switch (port) {
  1118. case PORT_A:
  1119. return DP_AUX_CH_CTL(port);
  1120. case PORT_B:
  1121. case PORT_C:
  1122. case PORT_D:
  1123. return PCH_DP_AUX_CH_CTL(port);
  1124. default:
  1125. MISSING_CASE(port);
  1126. return DP_AUX_CH_CTL(PORT_A);
  1127. }
  1128. }
  1129. static i915_reg_t ilk_aux_data_reg(struct drm_i915_private *dev_priv,
  1130. enum port port, int index)
  1131. {
  1132. switch (port) {
  1133. case PORT_A:
  1134. return DP_AUX_CH_DATA(port, index);
  1135. case PORT_B:
  1136. case PORT_C:
  1137. case PORT_D:
  1138. return PCH_DP_AUX_CH_DATA(port, index);
  1139. default:
  1140. MISSING_CASE(port);
  1141. return DP_AUX_CH_DATA(PORT_A, index);
  1142. }
  1143. }
  1144. static i915_reg_t skl_aux_ctl_reg(struct drm_i915_private *dev_priv,
  1145. enum port port)
  1146. {
  1147. switch (port) {
  1148. case PORT_A:
  1149. case PORT_B:
  1150. case PORT_C:
  1151. case PORT_D:
  1152. return DP_AUX_CH_CTL(port);
  1153. default:
  1154. MISSING_CASE(port);
  1155. return DP_AUX_CH_CTL(PORT_A);
  1156. }
  1157. }
  1158. static i915_reg_t skl_aux_data_reg(struct drm_i915_private *dev_priv,
  1159. enum port port, int index)
  1160. {
  1161. switch (port) {
  1162. case PORT_A:
  1163. case PORT_B:
  1164. case PORT_C:
  1165. case PORT_D:
  1166. return DP_AUX_CH_DATA(port, index);
  1167. default:
  1168. MISSING_CASE(port);
  1169. return DP_AUX_CH_DATA(PORT_A, index);
  1170. }
  1171. }
  1172. static i915_reg_t intel_aux_ctl_reg(struct drm_i915_private *dev_priv,
  1173. enum port port)
  1174. {
  1175. if (INTEL_INFO(dev_priv)->gen >= 9)
  1176. return skl_aux_ctl_reg(dev_priv, port);
  1177. else if (HAS_PCH_SPLIT(dev_priv))
  1178. return ilk_aux_ctl_reg(dev_priv, port);
  1179. else
  1180. return g4x_aux_ctl_reg(dev_priv, port);
  1181. }
  1182. static i915_reg_t intel_aux_data_reg(struct drm_i915_private *dev_priv,
  1183. enum port port, int index)
  1184. {
  1185. if (INTEL_INFO(dev_priv)->gen >= 9)
  1186. return skl_aux_data_reg(dev_priv, port, index);
  1187. else if (HAS_PCH_SPLIT(dev_priv))
  1188. return ilk_aux_data_reg(dev_priv, port, index);
  1189. else
  1190. return g4x_aux_data_reg(dev_priv, port, index);
  1191. }
  1192. static void intel_aux_reg_init(struct intel_dp *intel_dp)
  1193. {
  1194. struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
  1195. enum port port = intel_aux_port(dev_priv,
  1196. dp_to_dig_port(intel_dp)->port);
  1197. int i;
  1198. intel_dp->aux_ch_ctl_reg = intel_aux_ctl_reg(dev_priv, port);
  1199. for (i = 0; i < ARRAY_SIZE(intel_dp->aux_ch_data_reg); i++)
  1200. intel_dp->aux_ch_data_reg[i] = intel_aux_data_reg(dev_priv, port, i);
  1201. }
  1202. static void
  1203. intel_dp_aux_fini(struct intel_dp *intel_dp)
  1204. {
  1205. kfree(intel_dp->aux.name);
  1206. }
  1207. static void
  1208. intel_dp_aux_init(struct intel_dp *intel_dp)
  1209. {
  1210. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  1211. enum port port = intel_dig_port->port;
  1212. intel_aux_reg_init(intel_dp);
  1213. drm_dp_aux_init(&intel_dp->aux);
  1214. /* Failure to allocate our preferred name is not critical */
  1215. intel_dp->aux.name = kasprintf(GFP_KERNEL, "DPDDC-%c", port_name(port));
  1216. intel_dp->aux.transfer = intel_dp_aux_transfer;
  1217. }
  1218. bool intel_dp_source_supports_hbr2(struct intel_dp *intel_dp)
  1219. {
  1220. struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
  1221. struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
  1222. if ((IS_HASWELL(dev_priv) && !IS_HSW_ULX(dev_priv)) ||
  1223. IS_BROADWELL(dev_priv) || (INTEL_GEN(dev_priv) >= 9))
  1224. return true;
  1225. else
  1226. return false;
  1227. }
  1228. static void
  1229. intel_dp_set_clock(struct intel_encoder *encoder,
  1230. struct intel_crtc_state *pipe_config)
  1231. {
  1232. struct drm_device *dev = encoder->base.dev;
  1233. struct drm_i915_private *dev_priv = to_i915(dev);
  1234. const struct dp_link_dpll *divisor = NULL;
  1235. int i, count = 0;
  1236. if (IS_G4X(dev_priv)) {
  1237. divisor = gen4_dpll;
  1238. count = ARRAY_SIZE(gen4_dpll);
  1239. } else if (HAS_PCH_SPLIT(dev_priv)) {
  1240. divisor = pch_dpll;
  1241. count = ARRAY_SIZE(pch_dpll);
  1242. } else if (IS_CHERRYVIEW(dev_priv)) {
  1243. divisor = chv_dpll;
  1244. count = ARRAY_SIZE(chv_dpll);
  1245. } else if (IS_VALLEYVIEW(dev_priv)) {
  1246. divisor = vlv_dpll;
  1247. count = ARRAY_SIZE(vlv_dpll);
  1248. }
  1249. if (divisor && count) {
  1250. for (i = 0; i < count; i++) {
  1251. if (pipe_config->port_clock == divisor[i].clock) {
  1252. pipe_config->dpll = divisor[i].dpll;
  1253. pipe_config->clock_set = true;
  1254. break;
  1255. }
  1256. }
  1257. }
  1258. }
  1259. static void snprintf_int_array(char *str, size_t len,
  1260. const int *array, int nelem)
  1261. {
  1262. int i;
  1263. str[0] = '\0';
  1264. for (i = 0; i < nelem; i++) {
  1265. int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]);
  1266. if (r >= len)
  1267. return;
  1268. str += r;
  1269. len -= r;
  1270. }
  1271. }
  1272. static void intel_dp_print_rates(struct intel_dp *intel_dp)
  1273. {
  1274. char str[128]; /* FIXME: too big for stack? */
  1275. if ((drm_debug & DRM_UT_KMS) == 0)
  1276. return;
  1277. snprintf_int_array(str, sizeof(str),
  1278. intel_dp->source_rates, intel_dp->num_source_rates);
  1279. DRM_DEBUG_KMS("source rates: %s\n", str);
  1280. snprintf_int_array(str, sizeof(str),
  1281. intel_dp->sink_rates, intel_dp->num_sink_rates);
  1282. DRM_DEBUG_KMS("sink rates: %s\n", str);
  1283. snprintf_int_array(str, sizeof(str),
  1284. intel_dp->common_rates, intel_dp->num_common_rates);
  1285. DRM_DEBUG_KMS("common rates: %s\n", str);
  1286. }
  1287. bool
  1288. __intel_dp_read_desc(struct intel_dp *intel_dp, struct intel_dp_desc *desc)
  1289. {
  1290. u32 base = drm_dp_is_branch(intel_dp->dpcd) ? DP_BRANCH_OUI :
  1291. DP_SINK_OUI;
  1292. return drm_dp_dpcd_read(&intel_dp->aux, base, desc, sizeof(*desc)) ==
  1293. sizeof(*desc);
  1294. }
  1295. bool intel_dp_read_desc(struct intel_dp *intel_dp)
  1296. {
  1297. struct intel_dp_desc *desc = &intel_dp->desc;
  1298. bool oui_sup = intel_dp->dpcd[DP_DOWN_STREAM_PORT_COUNT] &
  1299. DP_OUI_SUPPORT;
  1300. int dev_id_len;
  1301. if (!__intel_dp_read_desc(intel_dp, desc))
  1302. return false;
  1303. dev_id_len = strnlen(desc->device_id, sizeof(desc->device_id));
  1304. DRM_DEBUG_KMS("DP %s: OUI %*phD%s dev-ID %*pE HW-rev %d.%d SW-rev %d.%d\n",
  1305. drm_dp_is_branch(intel_dp->dpcd) ? "branch" : "sink",
  1306. (int)sizeof(desc->oui), desc->oui, oui_sup ? "" : "(NS)",
  1307. dev_id_len, desc->device_id,
  1308. desc->hw_rev >> 4, desc->hw_rev & 0xf,
  1309. desc->sw_major_rev, desc->sw_minor_rev);
  1310. return true;
  1311. }
  1312. int
  1313. intel_dp_max_link_rate(struct intel_dp *intel_dp)
  1314. {
  1315. int len;
  1316. len = intel_dp_common_len_rate_limit(intel_dp, intel_dp->max_link_rate);
  1317. if (WARN_ON(len <= 0))
  1318. return 162000;
  1319. return intel_dp->common_rates[len - 1];
  1320. }
  1321. int intel_dp_rate_select(struct intel_dp *intel_dp, int rate)
  1322. {
  1323. int i = intel_dp_rate_index(intel_dp->sink_rates,
  1324. intel_dp->num_sink_rates, rate);
  1325. if (WARN_ON(i < 0))
  1326. i = 0;
  1327. return i;
  1328. }
  1329. void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock,
  1330. uint8_t *link_bw, uint8_t *rate_select)
  1331. {
  1332. /* eDP 1.4 rate select method. */
  1333. if (intel_dp->use_rate_select) {
  1334. *link_bw = 0;
  1335. *rate_select =
  1336. intel_dp_rate_select(intel_dp, port_clock);
  1337. } else {
  1338. *link_bw = drm_dp_link_rate_to_bw_code(port_clock);
  1339. *rate_select = 0;
  1340. }
  1341. }
  1342. static int intel_dp_compute_bpp(struct intel_dp *intel_dp,
  1343. struct intel_crtc_state *pipe_config)
  1344. {
  1345. int bpp, bpc;
  1346. bpp = pipe_config->pipe_bpp;
  1347. bpc = drm_dp_downstream_max_bpc(intel_dp->dpcd, intel_dp->downstream_ports);
  1348. if (bpc > 0)
  1349. bpp = min(bpp, 3*bpc);
  1350. /* For DP Compliance we override the computed bpp for the pipe */
  1351. if (intel_dp->compliance.test_data.bpc != 0) {
  1352. pipe_config->pipe_bpp = 3*intel_dp->compliance.test_data.bpc;
  1353. pipe_config->dither_force_disable = pipe_config->pipe_bpp == 6*3;
  1354. DRM_DEBUG_KMS("Setting pipe_bpp to %d\n",
  1355. pipe_config->pipe_bpp);
  1356. }
  1357. return bpp;
  1358. }
  1359. bool
  1360. intel_dp_compute_config(struct intel_encoder *encoder,
  1361. struct intel_crtc_state *pipe_config,
  1362. struct drm_connector_state *conn_state)
  1363. {
  1364. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  1365. struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
  1366. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  1367. enum port port = dp_to_dig_port(intel_dp)->port;
  1368. struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
  1369. struct intel_connector *intel_connector = intel_dp->attached_connector;
  1370. int lane_count, clock;
  1371. int min_lane_count = 1;
  1372. int max_lane_count = intel_dp_max_lane_count(intel_dp);
  1373. /* Conveniently, the link BW constants become indices with a shift...*/
  1374. int min_clock = 0;
  1375. int max_clock;
  1376. int bpp, mode_rate;
  1377. int link_avail, link_clock;
  1378. int common_len;
  1379. uint8_t link_bw, rate_select;
  1380. common_len = intel_dp_common_len_rate_limit(intel_dp,
  1381. intel_dp->max_link_rate);
  1382. /* No common link rates between source and sink */
  1383. WARN_ON(common_len <= 0);
  1384. max_clock = common_len - 1;
  1385. if (HAS_PCH_SPLIT(dev_priv) && !HAS_DDI(dev_priv) && port != PORT_A)
  1386. pipe_config->has_pch_encoder = true;
  1387. pipe_config->has_drrs = false;
  1388. pipe_config->has_audio = intel_dp->has_audio && port != PORT_A;
  1389. if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
  1390. intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
  1391. adjusted_mode);
  1392. if (INTEL_GEN(dev_priv) >= 9) {
  1393. int ret;
  1394. ret = skl_update_scaler_crtc(pipe_config);
  1395. if (ret)
  1396. return ret;
  1397. }
  1398. if (HAS_GMCH_DISPLAY(dev_priv))
  1399. intel_gmch_panel_fitting(intel_crtc, pipe_config,
  1400. intel_connector->panel.fitting_mode);
  1401. else
  1402. intel_pch_panel_fitting(intel_crtc, pipe_config,
  1403. intel_connector->panel.fitting_mode);
  1404. }
  1405. if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
  1406. return false;
  1407. /* Use values requested by Compliance Test Request */
  1408. if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
  1409. int index;
  1410. index = intel_dp_rate_index(intel_dp->common_rates,
  1411. intel_dp->num_common_rates,
  1412. intel_dp->compliance.test_link_rate);
  1413. if (index >= 0)
  1414. min_clock = max_clock = index;
  1415. min_lane_count = max_lane_count = intel_dp->compliance.test_lane_count;
  1416. }
  1417. DRM_DEBUG_KMS("DP link computation with max lane count %i "
  1418. "max bw %d pixel clock %iKHz\n",
  1419. max_lane_count, intel_dp->common_rates[max_clock],
  1420. adjusted_mode->crtc_clock);
  1421. /* Walk through all bpp values. Luckily they're all nicely spaced with 2
  1422. * bpc in between. */
  1423. bpp = intel_dp_compute_bpp(intel_dp, pipe_config);
  1424. if (is_edp(intel_dp)) {
  1425. /* Get bpp from vbt only for panels that dont have bpp in edid */
  1426. if (intel_connector->base.display_info.bpc == 0 &&
  1427. (dev_priv->vbt.edp.bpp && dev_priv->vbt.edp.bpp < bpp)) {
  1428. DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
  1429. dev_priv->vbt.edp.bpp);
  1430. bpp = dev_priv->vbt.edp.bpp;
  1431. }
  1432. /*
  1433. * Use the maximum clock and number of lanes the eDP panel
  1434. * advertizes being capable of. The panels are generally
  1435. * designed to support only a single clock and lane
  1436. * configuration, and typically these values correspond to the
  1437. * native resolution of the panel.
  1438. */
  1439. min_lane_count = max_lane_count;
  1440. min_clock = max_clock;
  1441. }
  1442. for (; bpp >= 6*3; bpp -= 2*3) {
  1443. mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
  1444. bpp);
  1445. for (clock = min_clock; clock <= max_clock; clock++) {
  1446. for (lane_count = min_lane_count;
  1447. lane_count <= max_lane_count;
  1448. lane_count <<= 1) {
  1449. link_clock = intel_dp->common_rates[clock];
  1450. link_avail = intel_dp_max_data_rate(link_clock,
  1451. lane_count);
  1452. if (mode_rate <= link_avail) {
  1453. goto found;
  1454. }
  1455. }
  1456. }
  1457. }
  1458. return false;
  1459. found:
  1460. if (intel_dp->color_range_auto) {
  1461. /*
  1462. * See:
  1463. * CEA-861-E - 5.1 Default Encoding Parameters
  1464. * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
  1465. */
  1466. pipe_config->limited_color_range =
  1467. bpp != 18 &&
  1468. drm_default_rgb_quant_range(adjusted_mode) ==
  1469. HDMI_QUANTIZATION_RANGE_LIMITED;
  1470. } else {
  1471. pipe_config->limited_color_range =
  1472. intel_dp->limited_color_range;
  1473. }
  1474. pipe_config->lane_count = lane_count;
  1475. pipe_config->pipe_bpp = bpp;
  1476. pipe_config->port_clock = intel_dp->common_rates[clock];
  1477. intel_dp_compute_rate(intel_dp, pipe_config->port_clock,
  1478. &link_bw, &rate_select);
  1479. DRM_DEBUG_KMS("DP link bw %02x rate select %02x lane count %d clock %d bpp %d\n",
  1480. link_bw, rate_select, pipe_config->lane_count,
  1481. pipe_config->port_clock, bpp);
  1482. DRM_DEBUG_KMS("DP link bw required %i available %i\n",
  1483. mode_rate, link_avail);
  1484. intel_link_compute_m_n(bpp, lane_count,
  1485. adjusted_mode->crtc_clock,
  1486. pipe_config->port_clock,
  1487. &pipe_config->dp_m_n);
  1488. if (intel_connector->panel.downclock_mode != NULL &&
  1489. dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) {
  1490. pipe_config->has_drrs = true;
  1491. intel_link_compute_m_n(bpp, lane_count,
  1492. intel_connector->panel.downclock_mode->clock,
  1493. pipe_config->port_clock,
  1494. &pipe_config->dp_m2_n2);
  1495. }
  1496. /*
  1497. * DPLL0 VCO may need to be adjusted to get the correct
  1498. * clock for eDP. This will affect cdclk as well.
  1499. */
  1500. if (is_edp(intel_dp) && IS_GEN9_BC(dev_priv)) {
  1501. int vco;
  1502. switch (pipe_config->port_clock / 2) {
  1503. case 108000:
  1504. case 216000:
  1505. vco = 8640000;
  1506. break;
  1507. default:
  1508. vco = 8100000;
  1509. break;
  1510. }
  1511. to_intel_atomic_state(pipe_config->base.state)->cdclk.logical.vco = vco;
  1512. }
  1513. if (!HAS_DDI(dev_priv))
  1514. intel_dp_set_clock(encoder, pipe_config);
  1515. return true;
  1516. }
  1517. void intel_dp_set_link_params(struct intel_dp *intel_dp,
  1518. int link_rate, uint8_t lane_count,
  1519. bool link_mst)
  1520. {
  1521. intel_dp->link_rate = link_rate;
  1522. intel_dp->lane_count = lane_count;
  1523. intel_dp->link_mst = link_mst;
  1524. }
  1525. static void intel_dp_prepare(struct intel_encoder *encoder,
  1526. struct intel_crtc_state *pipe_config)
  1527. {
  1528. struct drm_device *dev = encoder->base.dev;
  1529. struct drm_i915_private *dev_priv = to_i915(dev);
  1530. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  1531. enum port port = dp_to_dig_port(intel_dp)->port;
  1532. struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
  1533. const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
  1534. intel_dp_set_link_params(intel_dp, pipe_config->port_clock,
  1535. pipe_config->lane_count,
  1536. intel_crtc_has_type(pipe_config,
  1537. INTEL_OUTPUT_DP_MST));
  1538. /*
  1539. * There are four kinds of DP registers:
  1540. *
  1541. * IBX PCH
  1542. * SNB CPU
  1543. * IVB CPU
  1544. * CPT PCH
  1545. *
  1546. * IBX PCH and CPU are the same for almost everything,
  1547. * except that the CPU DP PLL is configured in this
  1548. * register
  1549. *
  1550. * CPT PCH is quite different, having many bits moved
  1551. * to the TRANS_DP_CTL register instead. That
  1552. * configuration happens (oddly) in ironlake_pch_enable
  1553. */
  1554. /* Preserve the BIOS-computed detected bit. This is
  1555. * supposed to be read-only.
  1556. */
  1557. intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
  1558. /* Handle DP bits in common between all three register formats */
  1559. intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
  1560. intel_dp->DP |= DP_PORT_WIDTH(pipe_config->lane_count);
  1561. /* Split out the IBX/CPU vs CPT settings */
  1562. if (IS_GEN7(dev_priv) && port == PORT_A) {
  1563. if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
  1564. intel_dp->DP |= DP_SYNC_HS_HIGH;
  1565. if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
  1566. intel_dp->DP |= DP_SYNC_VS_HIGH;
  1567. intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
  1568. if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
  1569. intel_dp->DP |= DP_ENHANCED_FRAMING;
  1570. intel_dp->DP |= crtc->pipe << 29;
  1571. } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
  1572. u32 trans_dp;
  1573. intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
  1574. trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
  1575. if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
  1576. trans_dp |= TRANS_DP_ENH_FRAMING;
  1577. else
  1578. trans_dp &= ~TRANS_DP_ENH_FRAMING;
  1579. I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp);
  1580. } else {
  1581. if (IS_G4X(dev_priv) && pipe_config->limited_color_range)
  1582. intel_dp->DP |= DP_COLOR_RANGE_16_235;
  1583. if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
  1584. intel_dp->DP |= DP_SYNC_HS_HIGH;
  1585. if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
  1586. intel_dp->DP |= DP_SYNC_VS_HIGH;
  1587. intel_dp->DP |= DP_LINK_TRAIN_OFF;
  1588. if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
  1589. intel_dp->DP |= DP_ENHANCED_FRAMING;
  1590. if (IS_CHERRYVIEW(dev_priv))
  1591. intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe);
  1592. else if (crtc->pipe == PIPE_B)
  1593. intel_dp->DP |= DP_PIPEB_SELECT;
  1594. }
  1595. }
  1596. #define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
  1597. #define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
  1598. #define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
  1599. #define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
  1600. #define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
  1601. #define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
  1602. static void intel_pps_verify_state(struct drm_i915_private *dev_priv,
  1603. struct intel_dp *intel_dp);
  1604. static void wait_panel_status(struct intel_dp *intel_dp,
  1605. u32 mask,
  1606. u32 value)
  1607. {
  1608. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  1609. struct drm_i915_private *dev_priv = to_i915(dev);
  1610. i915_reg_t pp_stat_reg, pp_ctrl_reg;
  1611. lockdep_assert_held(&dev_priv->pps_mutex);
  1612. intel_pps_verify_state(dev_priv, intel_dp);
  1613. pp_stat_reg = _pp_stat_reg(intel_dp);
  1614. pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
  1615. DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
  1616. mask, value,
  1617. I915_READ(pp_stat_reg),
  1618. I915_READ(pp_ctrl_reg));
  1619. if (intel_wait_for_register(dev_priv,
  1620. pp_stat_reg, mask, value,
  1621. 5000))
  1622. DRM_ERROR("Panel status timeout: status %08x control %08x\n",
  1623. I915_READ(pp_stat_reg),
  1624. I915_READ(pp_ctrl_reg));
  1625. DRM_DEBUG_KMS("Wait complete\n");
  1626. }
  1627. static void wait_panel_on(struct intel_dp *intel_dp)
  1628. {
  1629. DRM_DEBUG_KMS("Wait for panel power on\n");
  1630. wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
  1631. }
  1632. static void wait_panel_off(struct intel_dp *intel_dp)
  1633. {
  1634. DRM_DEBUG_KMS("Wait for panel power off time\n");
  1635. wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
  1636. }
  1637. static void wait_panel_power_cycle(struct intel_dp *intel_dp)
  1638. {
  1639. ktime_t panel_power_on_time;
  1640. s64 panel_power_off_duration;
  1641. DRM_DEBUG_KMS("Wait for panel power cycle\n");
  1642. /* take the difference of currrent time and panel power off time
  1643. * and then make panel wait for t11_t12 if needed. */
  1644. panel_power_on_time = ktime_get_boottime();
  1645. panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->panel_power_off_time);
  1646. /* When we disable the VDD override bit last we have to do the manual
  1647. * wait. */
  1648. if (panel_power_off_duration < (s64)intel_dp->panel_power_cycle_delay)
  1649. wait_remaining_ms_from_jiffies(jiffies,
  1650. intel_dp->panel_power_cycle_delay - panel_power_off_duration);
  1651. wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
  1652. }
  1653. static void wait_backlight_on(struct intel_dp *intel_dp)
  1654. {
  1655. wait_remaining_ms_from_jiffies(intel_dp->last_power_on,
  1656. intel_dp->backlight_on_delay);
  1657. }
  1658. static void edp_wait_backlight_off(struct intel_dp *intel_dp)
  1659. {
  1660. wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off,
  1661. intel_dp->backlight_off_delay);
  1662. }
  1663. /* Read the current pp_control value, unlocking the register if it
  1664. * is locked
  1665. */
  1666. static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
  1667. {
  1668. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  1669. struct drm_i915_private *dev_priv = to_i915(dev);
  1670. u32 control;
  1671. lockdep_assert_held(&dev_priv->pps_mutex);
  1672. control = I915_READ(_pp_ctrl_reg(intel_dp));
  1673. if (WARN_ON(!HAS_DDI(dev_priv) &&
  1674. (control & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS)) {
  1675. control &= ~PANEL_UNLOCK_MASK;
  1676. control |= PANEL_UNLOCK_REGS;
  1677. }
  1678. return control;
  1679. }
  1680. /*
  1681. * Must be paired with edp_panel_vdd_off().
  1682. * Must hold pps_mutex around the whole on/off sequence.
  1683. * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
  1684. */
  1685. static bool edp_panel_vdd_on(struct intel_dp *intel_dp)
  1686. {
  1687. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  1688. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  1689. struct drm_i915_private *dev_priv = to_i915(dev);
  1690. u32 pp;
  1691. i915_reg_t pp_stat_reg, pp_ctrl_reg;
  1692. bool need_to_disable = !intel_dp->want_panel_vdd;
  1693. lockdep_assert_held(&dev_priv->pps_mutex);
  1694. if (!is_edp(intel_dp))
  1695. return false;
  1696. cancel_delayed_work(&intel_dp->panel_vdd_work);
  1697. intel_dp->want_panel_vdd = true;
  1698. if (edp_have_panel_vdd(intel_dp))
  1699. return need_to_disable;
  1700. intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
  1701. DRM_DEBUG_KMS("Turning eDP port %c VDD on\n",
  1702. port_name(intel_dig_port->port));
  1703. if (!edp_have_panel_power(intel_dp))
  1704. wait_panel_power_cycle(intel_dp);
  1705. pp = ironlake_get_pp_control(intel_dp);
  1706. pp |= EDP_FORCE_VDD;
  1707. pp_stat_reg = _pp_stat_reg(intel_dp);
  1708. pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
  1709. I915_WRITE(pp_ctrl_reg, pp);
  1710. POSTING_READ(pp_ctrl_reg);
  1711. DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
  1712. I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
  1713. /*
  1714. * If the panel wasn't on, delay before accessing aux channel
  1715. */
  1716. if (!edp_have_panel_power(intel_dp)) {
  1717. DRM_DEBUG_KMS("eDP port %c panel power wasn't enabled\n",
  1718. port_name(intel_dig_port->port));
  1719. msleep(intel_dp->panel_power_up_delay);
  1720. }
  1721. return need_to_disable;
  1722. }
  1723. /*
  1724. * Must be paired with intel_edp_panel_vdd_off() or
  1725. * intel_edp_panel_off().
  1726. * Nested calls to these functions are not allowed since
  1727. * we drop the lock. Caller must use some higher level
  1728. * locking to prevent nested calls from other threads.
  1729. */
  1730. void intel_edp_panel_vdd_on(struct intel_dp *intel_dp)
  1731. {
  1732. bool vdd;
  1733. if (!is_edp(intel_dp))
  1734. return;
  1735. pps_lock(intel_dp);
  1736. vdd = edp_panel_vdd_on(intel_dp);
  1737. pps_unlock(intel_dp);
  1738. I915_STATE_WARN(!vdd, "eDP port %c VDD already requested on\n",
  1739. port_name(dp_to_dig_port(intel_dp)->port));
  1740. }
  1741. static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp)
  1742. {
  1743. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  1744. struct drm_i915_private *dev_priv = to_i915(dev);
  1745. struct intel_digital_port *intel_dig_port =
  1746. dp_to_dig_port(intel_dp);
  1747. u32 pp;
  1748. i915_reg_t pp_stat_reg, pp_ctrl_reg;
  1749. lockdep_assert_held(&dev_priv->pps_mutex);
  1750. WARN_ON(intel_dp->want_panel_vdd);
  1751. if (!edp_have_panel_vdd(intel_dp))
  1752. return;
  1753. DRM_DEBUG_KMS("Turning eDP port %c VDD off\n",
  1754. port_name(intel_dig_port->port));
  1755. pp = ironlake_get_pp_control(intel_dp);
  1756. pp &= ~EDP_FORCE_VDD;
  1757. pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
  1758. pp_stat_reg = _pp_stat_reg(intel_dp);
  1759. I915_WRITE(pp_ctrl_reg, pp);
  1760. POSTING_READ(pp_ctrl_reg);
  1761. /* Make sure sequencer is idle before allowing subsequent activity */
  1762. DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
  1763. I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
  1764. if ((pp & PANEL_POWER_ON) == 0)
  1765. intel_dp->panel_power_off_time = ktime_get_boottime();
  1766. intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
  1767. }
  1768. static void edp_panel_vdd_work(struct work_struct *__work)
  1769. {
  1770. struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
  1771. struct intel_dp, panel_vdd_work);
  1772. pps_lock(intel_dp);
  1773. if (!intel_dp->want_panel_vdd)
  1774. edp_panel_vdd_off_sync(intel_dp);
  1775. pps_unlock(intel_dp);
  1776. }
  1777. static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp)
  1778. {
  1779. unsigned long delay;
  1780. /*
  1781. * Queue the timer to fire a long time from now (relative to the power
  1782. * down delay) to keep the panel power up across a sequence of
  1783. * operations.
  1784. */
  1785. delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5);
  1786. schedule_delayed_work(&intel_dp->panel_vdd_work, delay);
  1787. }
  1788. /*
  1789. * Must be paired with edp_panel_vdd_on().
  1790. * Must hold pps_mutex around the whole on/off sequence.
  1791. * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
  1792. */
  1793. static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
  1794. {
  1795. struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
  1796. lockdep_assert_held(&dev_priv->pps_mutex);
  1797. if (!is_edp(intel_dp))
  1798. return;
  1799. I915_STATE_WARN(!intel_dp->want_panel_vdd, "eDP port %c VDD not forced on",
  1800. port_name(dp_to_dig_port(intel_dp)->port));
  1801. intel_dp->want_panel_vdd = false;
  1802. if (sync)
  1803. edp_panel_vdd_off_sync(intel_dp);
  1804. else
  1805. edp_panel_vdd_schedule_off(intel_dp);
  1806. }
  1807. static void edp_panel_on(struct intel_dp *intel_dp)
  1808. {
  1809. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  1810. struct drm_i915_private *dev_priv = to_i915(dev);
  1811. u32 pp;
  1812. i915_reg_t pp_ctrl_reg;
  1813. lockdep_assert_held(&dev_priv->pps_mutex);
  1814. if (!is_edp(intel_dp))
  1815. return;
  1816. DRM_DEBUG_KMS("Turn eDP port %c panel power on\n",
  1817. port_name(dp_to_dig_port(intel_dp)->port));
  1818. if (WARN(edp_have_panel_power(intel_dp),
  1819. "eDP port %c panel power already on\n",
  1820. port_name(dp_to_dig_port(intel_dp)->port)))
  1821. return;
  1822. wait_panel_power_cycle(intel_dp);
  1823. pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
  1824. pp = ironlake_get_pp_control(intel_dp);
  1825. if (IS_GEN5(dev_priv)) {
  1826. /* ILK workaround: disable reset around power sequence */
  1827. pp &= ~PANEL_POWER_RESET;
  1828. I915_WRITE(pp_ctrl_reg, pp);
  1829. POSTING_READ(pp_ctrl_reg);
  1830. }
  1831. pp |= PANEL_POWER_ON;
  1832. if (!IS_GEN5(dev_priv))
  1833. pp |= PANEL_POWER_RESET;
  1834. I915_WRITE(pp_ctrl_reg, pp);
  1835. POSTING_READ(pp_ctrl_reg);
  1836. wait_panel_on(intel_dp);
  1837. intel_dp->last_power_on = jiffies;
  1838. if (IS_GEN5(dev_priv)) {
  1839. pp |= PANEL_POWER_RESET; /* restore panel reset bit */
  1840. I915_WRITE(pp_ctrl_reg, pp);
  1841. POSTING_READ(pp_ctrl_reg);
  1842. }
  1843. }
  1844. void intel_edp_panel_on(struct intel_dp *intel_dp)
  1845. {
  1846. if (!is_edp(intel_dp))
  1847. return;
  1848. pps_lock(intel_dp);
  1849. edp_panel_on(intel_dp);
  1850. pps_unlock(intel_dp);
  1851. }
  1852. static void edp_panel_off(struct intel_dp *intel_dp)
  1853. {
  1854. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  1855. struct drm_i915_private *dev_priv = to_i915(dev);
  1856. u32 pp;
  1857. i915_reg_t pp_ctrl_reg;
  1858. lockdep_assert_held(&dev_priv->pps_mutex);
  1859. if (!is_edp(intel_dp))
  1860. return;
  1861. DRM_DEBUG_KMS("Turn eDP port %c panel power off\n",
  1862. port_name(dp_to_dig_port(intel_dp)->port));
  1863. WARN(!intel_dp->want_panel_vdd, "Need eDP port %c VDD to turn off panel\n",
  1864. port_name(dp_to_dig_port(intel_dp)->port));
  1865. pp = ironlake_get_pp_control(intel_dp);
  1866. /* We need to switch off panel power _and_ force vdd, for otherwise some
  1867. * panels get very unhappy and cease to work. */
  1868. pp &= ~(PANEL_POWER_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
  1869. EDP_BLC_ENABLE);
  1870. pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
  1871. intel_dp->want_panel_vdd = false;
  1872. I915_WRITE(pp_ctrl_reg, pp);
  1873. POSTING_READ(pp_ctrl_reg);
  1874. intel_dp->panel_power_off_time = ktime_get_boottime();
  1875. wait_panel_off(intel_dp);
  1876. /* We got a reference when we enabled the VDD. */
  1877. intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
  1878. }
  1879. void intel_edp_panel_off(struct intel_dp *intel_dp)
  1880. {
  1881. if (!is_edp(intel_dp))
  1882. return;
  1883. pps_lock(intel_dp);
  1884. edp_panel_off(intel_dp);
  1885. pps_unlock(intel_dp);
  1886. }
  1887. /* Enable backlight in the panel power control. */
  1888. static void _intel_edp_backlight_on(struct intel_dp *intel_dp)
  1889. {
  1890. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  1891. struct drm_device *dev = intel_dig_port->base.base.dev;
  1892. struct drm_i915_private *dev_priv = to_i915(dev);
  1893. u32 pp;
  1894. i915_reg_t pp_ctrl_reg;
  1895. /*
  1896. * If we enable the backlight right away following a panel power
  1897. * on, we may see slight flicker as the panel syncs with the eDP
  1898. * link. So delay a bit to make sure the image is solid before
  1899. * allowing it to appear.
  1900. */
  1901. wait_backlight_on(intel_dp);
  1902. pps_lock(intel_dp);
  1903. pp = ironlake_get_pp_control(intel_dp);
  1904. pp |= EDP_BLC_ENABLE;
  1905. pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
  1906. I915_WRITE(pp_ctrl_reg, pp);
  1907. POSTING_READ(pp_ctrl_reg);
  1908. pps_unlock(intel_dp);
  1909. }
  1910. /* Enable backlight PWM and backlight PP control. */
  1911. void intel_edp_backlight_on(struct intel_dp *intel_dp)
  1912. {
  1913. if (!is_edp(intel_dp))
  1914. return;
  1915. DRM_DEBUG_KMS("\n");
  1916. intel_panel_enable_backlight(intel_dp->attached_connector);
  1917. _intel_edp_backlight_on(intel_dp);
  1918. }
  1919. /* Disable backlight in the panel power control. */
  1920. static void _intel_edp_backlight_off(struct intel_dp *intel_dp)
  1921. {
  1922. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  1923. struct drm_i915_private *dev_priv = to_i915(dev);
  1924. u32 pp;
  1925. i915_reg_t pp_ctrl_reg;
  1926. if (!is_edp(intel_dp))
  1927. return;
  1928. pps_lock(intel_dp);
  1929. pp = ironlake_get_pp_control(intel_dp);
  1930. pp &= ~EDP_BLC_ENABLE;
  1931. pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
  1932. I915_WRITE(pp_ctrl_reg, pp);
  1933. POSTING_READ(pp_ctrl_reg);
  1934. pps_unlock(intel_dp);
  1935. intel_dp->last_backlight_off = jiffies;
  1936. edp_wait_backlight_off(intel_dp);
  1937. }
  1938. /* Disable backlight PP control and backlight PWM. */
  1939. void intel_edp_backlight_off(struct intel_dp *intel_dp)
  1940. {
  1941. if (!is_edp(intel_dp))
  1942. return;
  1943. DRM_DEBUG_KMS("\n");
  1944. _intel_edp_backlight_off(intel_dp);
  1945. intel_panel_disable_backlight(intel_dp->attached_connector);
  1946. }
  1947. /*
  1948. * Hook for controlling the panel power control backlight through the bl_power
  1949. * sysfs attribute. Take care to handle multiple calls.
  1950. */
  1951. static void intel_edp_backlight_power(struct intel_connector *connector,
  1952. bool enable)
  1953. {
  1954. struct intel_dp *intel_dp = intel_attached_dp(&connector->base);
  1955. bool is_enabled;
  1956. pps_lock(intel_dp);
  1957. is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE;
  1958. pps_unlock(intel_dp);
  1959. if (is_enabled == enable)
  1960. return;
  1961. DRM_DEBUG_KMS("panel power control backlight %s\n",
  1962. enable ? "enable" : "disable");
  1963. if (enable)
  1964. _intel_edp_backlight_on(intel_dp);
  1965. else
  1966. _intel_edp_backlight_off(intel_dp);
  1967. }
  1968. static void assert_dp_port(struct intel_dp *intel_dp, bool state)
  1969. {
  1970. struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
  1971. struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
  1972. bool cur_state = I915_READ(intel_dp->output_reg) & DP_PORT_EN;
  1973. I915_STATE_WARN(cur_state != state,
  1974. "DP port %c state assertion failure (expected %s, current %s)\n",
  1975. port_name(dig_port->port),
  1976. onoff(state), onoff(cur_state));
  1977. }
  1978. #define assert_dp_port_disabled(d) assert_dp_port((d), false)
  1979. static void assert_edp_pll(struct drm_i915_private *dev_priv, bool state)
  1980. {
  1981. bool cur_state = I915_READ(DP_A) & DP_PLL_ENABLE;
  1982. I915_STATE_WARN(cur_state != state,
  1983. "eDP PLL state assertion failure (expected %s, current %s)\n",
  1984. onoff(state), onoff(cur_state));
  1985. }
  1986. #define assert_edp_pll_enabled(d) assert_edp_pll((d), true)
  1987. #define assert_edp_pll_disabled(d) assert_edp_pll((d), false)
  1988. static void ironlake_edp_pll_on(struct intel_dp *intel_dp,
  1989. struct intel_crtc_state *pipe_config)
  1990. {
  1991. struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
  1992. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  1993. assert_pipe_disabled(dev_priv, crtc->pipe);
  1994. assert_dp_port_disabled(intel_dp);
  1995. assert_edp_pll_disabled(dev_priv);
  1996. DRM_DEBUG_KMS("enabling eDP PLL for clock %d\n",
  1997. pipe_config->port_clock);
  1998. intel_dp->DP &= ~DP_PLL_FREQ_MASK;
  1999. if (pipe_config->port_clock == 162000)
  2000. intel_dp->DP |= DP_PLL_FREQ_162MHZ;
  2001. else
  2002. intel_dp->DP |= DP_PLL_FREQ_270MHZ;
  2003. I915_WRITE(DP_A, intel_dp->DP);
  2004. POSTING_READ(DP_A);
  2005. udelay(500);
  2006. /*
  2007. * [DevILK] Work around required when enabling DP PLL
  2008. * while a pipe is enabled going to FDI:
  2009. * 1. Wait for the start of vertical blank on the enabled pipe going to FDI
  2010. * 2. Program DP PLL enable
  2011. */
  2012. if (IS_GEN5(dev_priv))
  2013. intel_wait_for_vblank_if_active(dev_priv, !crtc->pipe);
  2014. intel_dp->DP |= DP_PLL_ENABLE;
  2015. I915_WRITE(DP_A, intel_dp->DP);
  2016. POSTING_READ(DP_A);
  2017. udelay(200);
  2018. }
  2019. static void ironlake_edp_pll_off(struct intel_dp *intel_dp)
  2020. {
  2021. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  2022. struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
  2023. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  2024. assert_pipe_disabled(dev_priv, crtc->pipe);
  2025. assert_dp_port_disabled(intel_dp);
  2026. assert_edp_pll_enabled(dev_priv);
  2027. DRM_DEBUG_KMS("disabling eDP PLL\n");
  2028. intel_dp->DP &= ~DP_PLL_ENABLE;
  2029. I915_WRITE(DP_A, intel_dp->DP);
  2030. POSTING_READ(DP_A);
  2031. udelay(200);
  2032. }
  2033. /* If the sink supports it, try to set the power state appropriately */
  2034. void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
  2035. {
  2036. int ret, i;
  2037. /* Should have a valid DPCD by this point */
  2038. if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
  2039. return;
  2040. if (mode != DRM_MODE_DPMS_ON) {
  2041. ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
  2042. DP_SET_POWER_D3);
  2043. } else {
  2044. struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
  2045. /*
  2046. * When turning on, we need to retry for 1ms to give the sink
  2047. * time to wake up.
  2048. */
  2049. for (i = 0; i < 3; i++) {
  2050. ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
  2051. DP_SET_POWER_D0);
  2052. if (ret == 1)
  2053. break;
  2054. msleep(1);
  2055. }
  2056. if (ret == 1 && lspcon->active)
  2057. lspcon_wait_pcon_mode(lspcon);
  2058. }
  2059. if (ret != 1)
  2060. DRM_DEBUG_KMS("failed to %s sink power state\n",
  2061. mode == DRM_MODE_DPMS_ON ? "enable" : "disable");
  2062. }
  2063. static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
  2064. enum pipe *pipe)
  2065. {
  2066. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  2067. enum port port = dp_to_dig_port(intel_dp)->port;
  2068. struct drm_device *dev = encoder->base.dev;
  2069. struct drm_i915_private *dev_priv = to_i915(dev);
  2070. u32 tmp;
  2071. bool ret;
  2072. if (!intel_display_power_get_if_enabled(dev_priv,
  2073. encoder->power_domain))
  2074. return false;
  2075. ret = false;
  2076. tmp = I915_READ(intel_dp->output_reg);
  2077. if (!(tmp & DP_PORT_EN))
  2078. goto out;
  2079. if (IS_GEN7(dev_priv) && port == PORT_A) {
  2080. *pipe = PORT_TO_PIPE_CPT(tmp);
  2081. } else if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
  2082. enum pipe p;
  2083. for_each_pipe(dev_priv, p) {
  2084. u32 trans_dp = I915_READ(TRANS_DP_CTL(p));
  2085. if (TRANS_DP_PIPE_TO_PORT(trans_dp) == port) {
  2086. *pipe = p;
  2087. ret = true;
  2088. goto out;
  2089. }
  2090. }
  2091. DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
  2092. i915_mmio_reg_offset(intel_dp->output_reg));
  2093. } else if (IS_CHERRYVIEW(dev_priv)) {
  2094. *pipe = DP_PORT_TO_PIPE_CHV(tmp);
  2095. } else {
  2096. *pipe = PORT_TO_PIPE(tmp);
  2097. }
  2098. ret = true;
  2099. out:
  2100. intel_display_power_put(dev_priv, encoder->power_domain);
  2101. return ret;
  2102. }
  2103. static void intel_dp_get_config(struct intel_encoder *encoder,
  2104. struct intel_crtc_state *pipe_config)
  2105. {
  2106. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  2107. u32 tmp, flags = 0;
  2108. struct drm_device *dev = encoder->base.dev;
  2109. struct drm_i915_private *dev_priv = to_i915(dev);
  2110. enum port port = dp_to_dig_port(intel_dp)->port;
  2111. struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
  2112. tmp = I915_READ(intel_dp->output_reg);
  2113. pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A;
  2114. if (HAS_PCH_CPT(dev_priv) && port != PORT_A) {
  2115. u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
  2116. if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH)
  2117. flags |= DRM_MODE_FLAG_PHSYNC;
  2118. else
  2119. flags |= DRM_MODE_FLAG_NHSYNC;
  2120. if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH)
  2121. flags |= DRM_MODE_FLAG_PVSYNC;
  2122. else
  2123. flags |= DRM_MODE_FLAG_NVSYNC;
  2124. } else {
  2125. if (tmp & DP_SYNC_HS_HIGH)
  2126. flags |= DRM_MODE_FLAG_PHSYNC;
  2127. else
  2128. flags |= DRM_MODE_FLAG_NHSYNC;
  2129. if (tmp & DP_SYNC_VS_HIGH)
  2130. flags |= DRM_MODE_FLAG_PVSYNC;
  2131. else
  2132. flags |= DRM_MODE_FLAG_NVSYNC;
  2133. }
  2134. pipe_config->base.adjusted_mode.flags |= flags;
  2135. if (IS_G4X(dev_priv) && tmp & DP_COLOR_RANGE_16_235)
  2136. pipe_config->limited_color_range = true;
  2137. pipe_config->lane_count =
  2138. ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1;
  2139. intel_dp_get_m_n(crtc, pipe_config);
  2140. if (port == PORT_A) {
  2141. if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_162MHZ)
  2142. pipe_config->port_clock = 162000;
  2143. else
  2144. pipe_config->port_clock = 270000;
  2145. }
  2146. pipe_config->base.adjusted_mode.crtc_clock =
  2147. intel_dotclock_calculate(pipe_config->port_clock,
  2148. &pipe_config->dp_m_n);
  2149. if (is_edp(intel_dp) && dev_priv->vbt.edp.bpp &&
  2150. pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
  2151. /*
  2152. * This is a big fat ugly hack.
  2153. *
  2154. * Some machines in UEFI boot mode provide us a VBT that has 18
  2155. * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
  2156. * unknown we fail to light up. Yet the same BIOS boots up with
  2157. * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
  2158. * max, not what it tells us to use.
  2159. *
  2160. * Note: This will still be broken if the eDP panel is not lit
  2161. * up by the BIOS, and thus we can't get the mode at module
  2162. * load.
  2163. */
  2164. DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
  2165. pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
  2166. dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
  2167. }
  2168. }
  2169. static void intel_disable_dp(struct intel_encoder *encoder,
  2170. struct intel_crtc_state *old_crtc_state,
  2171. struct drm_connector_state *old_conn_state)
  2172. {
  2173. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  2174. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  2175. if (old_crtc_state->has_audio)
  2176. intel_audio_codec_disable(encoder);
  2177. if (HAS_PSR(dev_priv) && !HAS_DDI(dev_priv))
  2178. intel_psr_disable(intel_dp);
  2179. /* Make sure the panel is off before trying to change the mode. But also
  2180. * ensure that we have vdd while we switch off the panel. */
  2181. intel_edp_panel_vdd_on(intel_dp);
  2182. intel_edp_backlight_off(intel_dp);
  2183. intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
  2184. intel_edp_panel_off(intel_dp);
  2185. /* disable the port before the pipe on g4x */
  2186. if (INTEL_GEN(dev_priv) < 5)
  2187. intel_dp_link_down(intel_dp);
  2188. }
  2189. static void ilk_post_disable_dp(struct intel_encoder *encoder,
  2190. struct intel_crtc_state *old_crtc_state,
  2191. struct drm_connector_state *old_conn_state)
  2192. {
  2193. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  2194. enum port port = dp_to_dig_port(intel_dp)->port;
  2195. intel_dp_link_down(intel_dp);
  2196. /* Only ilk+ has port A */
  2197. if (port == PORT_A)
  2198. ironlake_edp_pll_off(intel_dp);
  2199. }
  2200. static void vlv_post_disable_dp(struct intel_encoder *encoder,
  2201. struct intel_crtc_state *old_crtc_state,
  2202. struct drm_connector_state *old_conn_state)
  2203. {
  2204. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  2205. intel_dp_link_down(intel_dp);
  2206. }
  2207. static void chv_post_disable_dp(struct intel_encoder *encoder,
  2208. struct intel_crtc_state *old_crtc_state,
  2209. struct drm_connector_state *old_conn_state)
  2210. {
  2211. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  2212. struct drm_device *dev = encoder->base.dev;
  2213. struct drm_i915_private *dev_priv = to_i915(dev);
  2214. intel_dp_link_down(intel_dp);
  2215. mutex_lock(&dev_priv->sb_lock);
  2216. /* Assert data lane reset */
  2217. chv_data_lane_soft_reset(encoder, true);
  2218. mutex_unlock(&dev_priv->sb_lock);
  2219. }
  2220. static void
  2221. _intel_dp_set_link_train(struct intel_dp *intel_dp,
  2222. uint32_t *DP,
  2223. uint8_t dp_train_pat)
  2224. {
  2225. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  2226. struct drm_device *dev = intel_dig_port->base.base.dev;
  2227. struct drm_i915_private *dev_priv = to_i915(dev);
  2228. enum port port = intel_dig_port->port;
  2229. if (dp_train_pat & DP_TRAINING_PATTERN_MASK)
  2230. DRM_DEBUG_KMS("Using DP training pattern TPS%d\n",
  2231. dp_train_pat & DP_TRAINING_PATTERN_MASK);
  2232. if (HAS_DDI(dev_priv)) {
  2233. uint32_t temp = I915_READ(DP_TP_CTL(port));
  2234. if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
  2235. temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
  2236. else
  2237. temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
  2238. temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
  2239. switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
  2240. case DP_TRAINING_PATTERN_DISABLE:
  2241. temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
  2242. break;
  2243. case DP_TRAINING_PATTERN_1:
  2244. temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
  2245. break;
  2246. case DP_TRAINING_PATTERN_2:
  2247. temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
  2248. break;
  2249. case DP_TRAINING_PATTERN_3:
  2250. temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
  2251. break;
  2252. }
  2253. I915_WRITE(DP_TP_CTL(port), temp);
  2254. } else if ((IS_GEN7(dev_priv) && port == PORT_A) ||
  2255. (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
  2256. *DP &= ~DP_LINK_TRAIN_MASK_CPT;
  2257. switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
  2258. case DP_TRAINING_PATTERN_DISABLE:
  2259. *DP |= DP_LINK_TRAIN_OFF_CPT;
  2260. break;
  2261. case DP_TRAINING_PATTERN_1:
  2262. *DP |= DP_LINK_TRAIN_PAT_1_CPT;
  2263. break;
  2264. case DP_TRAINING_PATTERN_2:
  2265. *DP |= DP_LINK_TRAIN_PAT_2_CPT;
  2266. break;
  2267. case DP_TRAINING_PATTERN_3:
  2268. DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
  2269. *DP |= DP_LINK_TRAIN_PAT_2_CPT;
  2270. break;
  2271. }
  2272. } else {
  2273. if (IS_CHERRYVIEW(dev_priv))
  2274. *DP &= ~DP_LINK_TRAIN_MASK_CHV;
  2275. else
  2276. *DP &= ~DP_LINK_TRAIN_MASK;
  2277. switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
  2278. case DP_TRAINING_PATTERN_DISABLE:
  2279. *DP |= DP_LINK_TRAIN_OFF;
  2280. break;
  2281. case DP_TRAINING_PATTERN_1:
  2282. *DP |= DP_LINK_TRAIN_PAT_1;
  2283. break;
  2284. case DP_TRAINING_PATTERN_2:
  2285. *DP |= DP_LINK_TRAIN_PAT_2;
  2286. break;
  2287. case DP_TRAINING_PATTERN_3:
  2288. if (IS_CHERRYVIEW(dev_priv)) {
  2289. *DP |= DP_LINK_TRAIN_PAT_3_CHV;
  2290. } else {
  2291. DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
  2292. *DP |= DP_LINK_TRAIN_PAT_2;
  2293. }
  2294. break;
  2295. }
  2296. }
  2297. }
  2298. static void intel_dp_enable_port(struct intel_dp *intel_dp,
  2299. struct intel_crtc_state *old_crtc_state)
  2300. {
  2301. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  2302. struct drm_i915_private *dev_priv = to_i915(dev);
  2303. /* enable with pattern 1 (as per spec) */
  2304. intel_dp_program_link_training_pattern(intel_dp, DP_TRAINING_PATTERN_1);
  2305. /*
  2306. * Magic for VLV/CHV. We _must_ first set up the register
  2307. * without actually enabling the port, and then do another
  2308. * write to enable the port. Otherwise link training will
  2309. * fail when the power sequencer is freshly used for this port.
  2310. */
  2311. intel_dp->DP |= DP_PORT_EN;
  2312. if (old_crtc_state->has_audio)
  2313. intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
  2314. I915_WRITE(intel_dp->output_reg, intel_dp->DP);
  2315. POSTING_READ(intel_dp->output_reg);
  2316. }
  2317. static void intel_enable_dp(struct intel_encoder *encoder,
  2318. struct intel_crtc_state *pipe_config,
  2319. struct drm_connector_state *conn_state)
  2320. {
  2321. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  2322. struct drm_device *dev = encoder->base.dev;
  2323. struct drm_i915_private *dev_priv = to_i915(dev);
  2324. struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
  2325. uint32_t dp_reg = I915_READ(intel_dp->output_reg);
  2326. enum pipe pipe = crtc->pipe;
  2327. if (WARN_ON(dp_reg & DP_PORT_EN))
  2328. return;
  2329. pps_lock(intel_dp);
  2330. if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
  2331. vlv_init_panel_power_sequencer(intel_dp);
  2332. intel_dp_enable_port(intel_dp, pipe_config);
  2333. edp_panel_vdd_on(intel_dp);
  2334. edp_panel_on(intel_dp);
  2335. edp_panel_vdd_off(intel_dp, true);
  2336. pps_unlock(intel_dp);
  2337. if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
  2338. unsigned int lane_mask = 0x0;
  2339. if (IS_CHERRYVIEW(dev_priv))
  2340. lane_mask = intel_dp_unused_lane_mask(pipe_config->lane_count);
  2341. vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp),
  2342. lane_mask);
  2343. }
  2344. intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
  2345. intel_dp_start_link_train(intel_dp);
  2346. intel_dp_stop_link_train(intel_dp);
  2347. if (pipe_config->has_audio) {
  2348. DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
  2349. pipe_name(pipe));
  2350. intel_audio_codec_enable(encoder, pipe_config, conn_state);
  2351. }
  2352. }
  2353. static void g4x_enable_dp(struct intel_encoder *encoder,
  2354. struct intel_crtc_state *pipe_config,
  2355. struct drm_connector_state *conn_state)
  2356. {
  2357. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  2358. intel_enable_dp(encoder, pipe_config, conn_state);
  2359. intel_edp_backlight_on(intel_dp);
  2360. }
  2361. static void vlv_enable_dp(struct intel_encoder *encoder,
  2362. struct intel_crtc_state *pipe_config,
  2363. struct drm_connector_state *conn_state)
  2364. {
  2365. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  2366. intel_edp_backlight_on(intel_dp);
  2367. intel_psr_enable(intel_dp);
  2368. }
  2369. static void g4x_pre_enable_dp(struct intel_encoder *encoder,
  2370. struct intel_crtc_state *pipe_config,
  2371. struct drm_connector_state *conn_state)
  2372. {
  2373. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  2374. enum port port = dp_to_dig_port(intel_dp)->port;
  2375. intel_dp_prepare(encoder, pipe_config);
  2376. /* Only ilk+ has port A */
  2377. if (port == PORT_A)
  2378. ironlake_edp_pll_on(intel_dp, pipe_config);
  2379. }
  2380. static void vlv_detach_power_sequencer(struct intel_dp *intel_dp)
  2381. {
  2382. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  2383. struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
  2384. enum pipe pipe = intel_dp->pps_pipe;
  2385. i915_reg_t pp_on_reg = PP_ON_DELAYS(pipe);
  2386. WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
  2387. if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
  2388. return;
  2389. edp_panel_vdd_off_sync(intel_dp);
  2390. /*
  2391. * VLV seems to get confused when multiple power seqeuencers
  2392. * have the same port selected (even if only one has power/vdd
  2393. * enabled). The failure manifests as vlv_wait_port_ready() failing
  2394. * CHV on the other hand doesn't seem to mind having the same port
  2395. * selected in multiple power seqeuencers, but let's clear the
  2396. * port select always when logically disconnecting a power sequencer
  2397. * from a port.
  2398. */
  2399. DRM_DEBUG_KMS("detaching pipe %c power sequencer from port %c\n",
  2400. pipe_name(pipe), port_name(intel_dig_port->port));
  2401. I915_WRITE(pp_on_reg, 0);
  2402. POSTING_READ(pp_on_reg);
  2403. intel_dp->pps_pipe = INVALID_PIPE;
  2404. }
  2405. static void vlv_steal_power_sequencer(struct drm_device *dev,
  2406. enum pipe pipe)
  2407. {
  2408. struct drm_i915_private *dev_priv = to_i915(dev);
  2409. struct intel_encoder *encoder;
  2410. lockdep_assert_held(&dev_priv->pps_mutex);
  2411. for_each_intel_encoder(dev, encoder) {
  2412. struct intel_dp *intel_dp;
  2413. enum port port;
  2414. if (encoder->type != INTEL_OUTPUT_DP &&
  2415. encoder->type != INTEL_OUTPUT_EDP)
  2416. continue;
  2417. intel_dp = enc_to_intel_dp(&encoder->base);
  2418. port = dp_to_dig_port(intel_dp)->port;
  2419. WARN(intel_dp->active_pipe == pipe,
  2420. "stealing pipe %c power sequencer from active (e)DP port %c\n",
  2421. pipe_name(pipe), port_name(port));
  2422. if (intel_dp->pps_pipe != pipe)
  2423. continue;
  2424. DRM_DEBUG_KMS("stealing pipe %c power sequencer from port %c\n",
  2425. pipe_name(pipe), port_name(port));
  2426. /* make sure vdd is off before we steal it */
  2427. vlv_detach_power_sequencer(intel_dp);
  2428. }
  2429. }
  2430. static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp)
  2431. {
  2432. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  2433. struct intel_encoder *encoder = &intel_dig_port->base;
  2434. struct drm_device *dev = encoder->base.dev;
  2435. struct drm_i915_private *dev_priv = to_i915(dev);
  2436. struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
  2437. lockdep_assert_held(&dev_priv->pps_mutex);
  2438. WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
  2439. if (intel_dp->pps_pipe != INVALID_PIPE &&
  2440. intel_dp->pps_pipe != crtc->pipe) {
  2441. /*
  2442. * If another power sequencer was being used on this
  2443. * port previously make sure to turn off vdd there while
  2444. * we still have control of it.
  2445. */
  2446. vlv_detach_power_sequencer(intel_dp);
  2447. }
  2448. /*
  2449. * We may be stealing the power
  2450. * sequencer from another port.
  2451. */
  2452. vlv_steal_power_sequencer(dev, crtc->pipe);
  2453. intel_dp->active_pipe = crtc->pipe;
  2454. if (!is_edp(intel_dp))
  2455. return;
  2456. /* now it's all ours */
  2457. intel_dp->pps_pipe = crtc->pipe;
  2458. DRM_DEBUG_KMS("initializing pipe %c power sequencer for port %c\n",
  2459. pipe_name(intel_dp->pps_pipe), port_name(intel_dig_port->port));
  2460. /* init power sequencer on this pipe and port */
  2461. intel_dp_init_panel_power_sequencer(dev, intel_dp);
  2462. intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, true);
  2463. }
  2464. static void vlv_pre_enable_dp(struct intel_encoder *encoder,
  2465. struct intel_crtc_state *pipe_config,
  2466. struct drm_connector_state *conn_state)
  2467. {
  2468. vlv_phy_pre_encoder_enable(encoder);
  2469. intel_enable_dp(encoder, pipe_config, conn_state);
  2470. }
  2471. static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder,
  2472. struct intel_crtc_state *pipe_config,
  2473. struct drm_connector_state *conn_state)
  2474. {
  2475. intel_dp_prepare(encoder, pipe_config);
  2476. vlv_phy_pre_pll_enable(encoder);
  2477. }
  2478. static void chv_pre_enable_dp(struct intel_encoder *encoder,
  2479. struct intel_crtc_state *pipe_config,
  2480. struct drm_connector_state *conn_state)
  2481. {
  2482. chv_phy_pre_encoder_enable(encoder);
  2483. intel_enable_dp(encoder, pipe_config, conn_state);
  2484. /* Second common lane will stay alive on its own now */
  2485. chv_phy_release_cl2_override(encoder);
  2486. }
  2487. static void chv_dp_pre_pll_enable(struct intel_encoder *encoder,
  2488. struct intel_crtc_state *pipe_config,
  2489. struct drm_connector_state *conn_state)
  2490. {
  2491. intel_dp_prepare(encoder, pipe_config);
  2492. chv_phy_pre_pll_enable(encoder);
  2493. }
  2494. static void chv_dp_post_pll_disable(struct intel_encoder *encoder,
  2495. struct intel_crtc_state *pipe_config,
  2496. struct drm_connector_state *conn_state)
  2497. {
  2498. chv_phy_post_pll_disable(encoder);
  2499. }
  2500. /*
  2501. * Fetch AUX CH registers 0x202 - 0x207 which contain
  2502. * link status information
  2503. */
  2504. bool
  2505. intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
  2506. {
  2507. return drm_dp_dpcd_read(&intel_dp->aux, DP_LANE0_1_STATUS, link_status,
  2508. DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;
  2509. }
  2510. static bool intel_dp_get_y_cord_status(struct intel_dp *intel_dp)
  2511. {
  2512. uint8_t psr_caps = 0;
  2513. if (drm_dp_dpcd_readb(&intel_dp->aux, DP_PSR_CAPS, &psr_caps) != 1)
  2514. return false;
  2515. return psr_caps & DP_PSR2_SU_Y_COORDINATE_REQUIRED;
  2516. }
  2517. static bool intel_dp_get_colorimetry_status(struct intel_dp *intel_dp)
  2518. {
  2519. uint8_t dprx = 0;
  2520. if (drm_dp_dpcd_readb(&intel_dp->aux, DP_DPRX_FEATURE_ENUMERATION_LIST,
  2521. &dprx) != 1)
  2522. return false;
  2523. return dprx & DP_VSC_SDP_EXT_FOR_COLORIMETRY_SUPPORTED;
  2524. }
  2525. static bool intel_dp_get_alpm_status(struct intel_dp *intel_dp)
  2526. {
  2527. uint8_t alpm_caps = 0;
  2528. if (drm_dp_dpcd_readb(&intel_dp->aux, DP_RECEIVER_ALPM_CAP,
  2529. &alpm_caps) != 1)
  2530. return false;
  2531. return alpm_caps & DP_ALPM_CAP;
  2532. }
  2533. /* These are source-specific values. */
  2534. uint8_t
  2535. intel_dp_voltage_max(struct intel_dp *intel_dp)
  2536. {
  2537. struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
  2538. enum port port = dp_to_dig_port(intel_dp)->port;
  2539. if (IS_GEN9_LP(dev_priv))
  2540. return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
  2541. else if (INTEL_GEN(dev_priv) >= 9) {
  2542. struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
  2543. return intel_ddi_dp_voltage_max(encoder);
  2544. } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
  2545. return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
  2546. else if (IS_GEN7(dev_priv) && port == PORT_A)
  2547. return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
  2548. else if (HAS_PCH_CPT(dev_priv) && port != PORT_A)
  2549. return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
  2550. else
  2551. return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
  2552. }
  2553. uint8_t
  2554. intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
  2555. {
  2556. struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
  2557. enum port port = dp_to_dig_port(intel_dp)->port;
  2558. if (INTEL_GEN(dev_priv) >= 9) {
  2559. switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2560. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2561. return DP_TRAIN_PRE_EMPH_LEVEL_3;
  2562. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2563. return DP_TRAIN_PRE_EMPH_LEVEL_2;
  2564. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
  2565. return DP_TRAIN_PRE_EMPH_LEVEL_1;
  2566. case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
  2567. return DP_TRAIN_PRE_EMPH_LEVEL_0;
  2568. default:
  2569. return DP_TRAIN_PRE_EMPH_LEVEL_0;
  2570. }
  2571. } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
  2572. switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2573. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2574. return DP_TRAIN_PRE_EMPH_LEVEL_3;
  2575. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2576. return DP_TRAIN_PRE_EMPH_LEVEL_2;
  2577. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
  2578. return DP_TRAIN_PRE_EMPH_LEVEL_1;
  2579. case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
  2580. default:
  2581. return DP_TRAIN_PRE_EMPH_LEVEL_0;
  2582. }
  2583. } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
  2584. switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2585. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2586. return DP_TRAIN_PRE_EMPH_LEVEL_3;
  2587. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2588. return DP_TRAIN_PRE_EMPH_LEVEL_2;
  2589. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
  2590. return DP_TRAIN_PRE_EMPH_LEVEL_1;
  2591. case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
  2592. default:
  2593. return DP_TRAIN_PRE_EMPH_LEVEL_0;
  2594. }
  2595. } else if (IS_GEN7(dev_priv) && port == PORT_A) {
  2596. switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2597. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2598. return DP_TRAIN_PRE_EMPH_LEVEL_2;
  2599. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2600. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
  2601. return DP_TRAIN_PRE_EMPH_LEVEL_1;
  2602. default:
  2603. return DP_TRAIN_PRE_EMPH_LEVEL_0;
  2604. }
  2605. } else {
  2606. switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2607. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2608. return DP_TRAIN_PRE_EMPH_LEVEL_2;
  2609. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2610. return DP_TRAIN_PRE_EMPH_LEVEL_2;
  2611. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
  2612. return DP_TRAIN_PRE_EMPH_LEVEL_1;
  2613. case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
  2614. default:
  2615. return DP_TRAIN_PRE_EMPH_LEVEL_0;
  2616. }
  2617. }
  2618. }
  2619. static uint32_t vlv_signal_levels(struct intel_dp *intel_dp)
  2620. {
  2621. struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
  2622. unsigned long demph_reg_value, preemph_reg_value,
  2623. uniqtranscale_reg_value;
  2624. uint8_t train_set = intel_dp->train_set[0];
  2625. switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
  2626. case DP_TRAIN_PRE_EMPH_LEVEL_0:
  2627. preemph_reg_value = 0x0004000;
  2628. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2629. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2630. demph_reg_value = 0x2B405555;
  2631. uniqtranscale_reg_value = 0x552AB83A;
  2632. break;
  2633. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2634. demph_reg_value = 0x2B404040;
  2635. uniqtranscale_reg_value = 0x5548B83A;
  2636. break;
  2637. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
  2638. demph_reg_value = 0x2B245555;
  2639. uniqtranscale_reg_value = 0x5560B83A;
  2640. break;
  2641. case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
  2642. demph_reg_value = 0x2B405555;
  2643. uniqtranscale_reg_value = 0x5598DA3A;
  2644. break;
  2645. default:
  2646. return 0;
  2647. }
  2648. break;
  2649. case DP_TRAIN_PRE_EMPH_LEVEL_1:
  2650. preemph_reg_value = 0x0002000;
  2651. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2652. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2653. demph_reg_value = 0x2B404040;
  2654. uniqtranscale_reg_value = 0x5552B83A;
  2655. break;
  2656. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2657. demph_reg_value = 0x2B404848;
  2658. uniqtranscale_reg_value = 0x5580B83A;
  2659. break;
  2660. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
  2661. demph_reg_value = 0x2B404040;
  2662. uniqtranscale_reg_value = 0x55ADDA3A;
  2663. break;
  2664. default:
  2665. return 0;
  2666. }
  2667. break;
  2668. case DP_TRAIN_PRE_EMPH_LEVEL_2:
  2669. preemph_reg_value = 0x0000000;
  2670. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2671. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2672. demph_reg_value = 0x2B305555;
  2673. uniqtranscale_reg_value = 0x5570B83A;
  2674. break;
  2675. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2676. demph_reg_value = 0x2B2B4040;
  2677. uniqtranscale_reg_value = 0x55ADDA3A;
  2678. break;
  2679. default:
  2680. return 0;
  2681. }
  2682. break;
  2683. case DP_TRAIN_PRE_EMPH_LEVEL_3:
  2684. preemph_reg_value = 0x0006000;
  2685. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2686. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2687. demph_reg_value = 0x1B405555;
  2688. uniqtranscale_reg_value = 0x55ADDA3A;
  2689. break;
  2690. default:
  2691. return 0;
  2692. }
  2693. break;
  2694. default:
  2695. return 0;
  2696. }
  2697. vlv_set_phy_signal_level(encoder, demph_reg_value, preemph_reg_value,
  2698. uniqtranscale_reg_value, 0);
  2699. return 0;
  2700. }
  2701. static uint32_t chv_signal_levels(struct intel_dp *intel_dp)
  2702. {
  2703. struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
  2704. u32 deemph_reg_value, margin_reg_value;
  2705. bool uniq_trans_scale = false;
  2706. uint8_t train_set = intel_dp->train_set[0];
  2707. switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
  2708. case DP_TRAIN_PRE_EMPH_LEVEL_0:
  2709. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2710. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2711. deemph_reg_value = 128;
  2712. margin_reg_value = 52;
  2713. break;
  2714. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2715. deemph_reg_value = 128;
  2716. margin_reg_value = 77;
  2717. break;
  2718. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
  2719. deemph_reg_value = 128;
  2720. margin_reg_value = 102;
  2721. break;
  2722. case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
  2723. deemph_reg_value = 128;
  2724. margin_reg_value = 154;
  2725. uniq_trans_scale = true;
  2726. break;
  2727. default:
  2728. return 0;
  2729. }
  2730. break;
  2731. case DP_TRAIN_PRE_EMPH_LEVEL_1:
  2732. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2733. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2734. deemph_reg_value = 85;
  2735. margin_reg_value = 78;
  2736. break;
  2737. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2738. deemph_reg_value = 85;
  2739. margin_reg_value = 116;
  2740. break;
  2741. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
  2742. deemph_reg_value = 85;
  2743. margin_reg_value = 154;
  2744. break;
  2745. default:
  2746. return 0;
  2747. }
  2748. break;
  2749. case DP_TRAIN_PRE_EMPH_LEVEL_2:
  2750. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2751. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2752. deemph_reg_value = 64;
  2753. margin_reg_value = 104;
  2754. break;
  2755. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2756. deemph_reg_value = 64;
  2757. margin_reg_value = 154;
  2758. break;
  2759. default:
  2760. return 0;
  2761. }
  2762. break;
  2763. case DP_TRAIN_PRE_EMPH_LEVEL_3:
  2764. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2765. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2766. deemph_reg_value = 43;
  2767. margin_reg_value = 154;
  2768. break;
  2769. default:
  2770. return 0;
  2771. }
  2772. break;
  2773. default:
  2774. return 0;
  2775. }
  2776. chv_set_phy_signal_level(encoder, deemph_reg_value,
  2777. margin_reg_value, uniq_trans_scale);
  2778. return 0;
  2779. }
  2780. static uint32_t
  2781. gen4_signal_levels(uint8_t train_set)
  2782. {
  2783. uint32_t signal_levels = 0;
  2784. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2785. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2786. default:
  2787. signal_levels |= DP_VOLTAGE_0_4;
  2788. break;
  2789. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2790. signal_levels |= DP_VOLTAGE_0_6;
  2791. break;
  2792. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
  2793. signal_levels |= DP_VOLTAGE_0_8;
  2794. break;
  2795. case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
  2796. signal_levels |= DP_VOLTAGE_1_2;
  2797. break;
  2798. }
  2799. switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
  2800. case DP_TRAIN_PRE_EMPH_LEVEL_0:
  2801. default:
  2802. signal_levels |= DP_PRE_EMPHASIS_0;
  2803. break;
  2804. case DP_TRAIN_PRE_EMPH_LEVEL_1:
  2805. signal_levels |= DP_PRE_EMPHASIS_3_5;
  2806. break;
  2807. case DP_TRAIN_PRE_EMPH_LEVEL_2:
  2808. signal_levels |= DP_PRE_EMPHASIS_6;
  2809. break;
  2810. case DP_TRAIN_PRE_EMPH_LEVEL_3:
  2811. signal_levels |= DP_PRE_EMPHASIS_9_5;
  2812. break;
  2813. }
  2814. return signal_levels;
  2815. }
  2816. /* Gen6's DP voltage swing and pre-emphasis control */
  2817. static uint32_t
  2818. gen6_edp_signal_levels(uint8_t train_set)
  2819. {
  2820. int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
  2821. DP_TRAIN_PRE_EMPHASIS_MASK);
  2822. switch (signal_levels) {
  2823. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
  2824. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
  2825. return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
  2826. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
  2827. return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
  2828. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
  2829. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
  2830. return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
  2831. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
  2832. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
  2833. return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
  2834. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
  2835. case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0:
  2836. return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
  2837. default:
  2838. DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
  2839. "0x%x\n", signal_levels);
  2840. return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
  2841. }
  2842. }
  2843. /* Gen7's DP voltage swing and pre-emphasis control */
  2844. static uint32_t
  2845. gen7_edp_signal_levels(uint8_t train_set)
  2846. {
  2847. int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
  2848. DP_TRAIN_PRE_EMPHASIS_MASK);
  2849. switch (signal_levels) {
  2850. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
  2851. return EDP_LINK_TRAIN_400MV_0DB_IVB;
  2852. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
  2853. return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
  2854. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
  2855. return EDP_LINK_TRAIN_400MV_6DB_IVB;
  2856. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
  2857. return EDP_LINK_TRAIN_600MV_0DB_IVB;
  2858. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
  2859. return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
  2860. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
  2861. return EDP_LINK_TRAIN_800MV_0DB_IVB;
  2862. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
  2863. return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
  2864. default:
  2865. DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
  2866. "0x%x\n", signal_levels);
  2867. return EDP_LINK_TRAIN_500MV_0DB_IVB;
  2868. }
  2869. }
  2870. void
  2871. intel_dp_set_signal_levels(struct intel_dp *intel_dp)
  2872. {
  2873. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  2874. enum port port = intel_dig_port->port;
  2875. struct drm_device *dev = intel_dig_port->base.base.dev;
  2876. struct drm_i915_private *dev_priv = to_i915(dev);
  2877. uint32_t signal_levels, mask = 0;
  2878. uint8_t train_set = intel_dp->train_set[0];
  2879. if (HAS_DDI(dev_priv)) {
  2880. signal_levels = ddi_signal_levels(intel_dp);
  2881. if (IS_GEN9_LP(dev_priv))
  2882. signal_levels = 0;
  2883. else
  2884. mask = DDI_BUF_EMP_MASK;
  2885. } else if (IS_CHERRYVIEW(dev_priv)) {
  2886. signal_levels = chv_signal_levels(intel_dp);
  2887. } else if (IS_VALLEYVIEW(dev_priv)) {
  2888. signal_levels = vlv_signal_levels(intel_dp);
  2889. } else if (IS_GEN7(dev_priv) && port == PORT_A) {
  2890. signal_levels = gen7_edp_signal_levels(train_set);
  2891. mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
  2892. } else if (IS_GEN6(dev_priv) && port == PORT_A) {
  2893. signal_levels = gen6_edp_signal_levels(train_set);
  2894. mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
  2895. } else {
  2896. signal_levels = gen4_signal_levels(train_set);
  2897. mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
  2898. }
  2899. if (mask)
  2900. DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
  2901. DRM_DEBUG_KMS("Using vswing level %d\n",
  2902. train_set & DP_TRAIN_VOLTAGE_SWING_MASK);
  2903. DRM_DEBUG_KMS("Using pre-emphasis level %d\n",
  2904. (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >>
  2905. DP_TRAIN_PRE_EMPHASIS_SHIFT);
  2906. intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels;
  2907. I915_WRITE(intel_dp->output_reg, intel_dp->DP);
  2908. POSTING_READ(intel_dp->output_reg);
  2909. }
  2910. void
  2911. intel_dp_program_link_training_pattern(struct intel_dp *intel_dp,
  2912. uint8_t dp_train_pat)
  2913. {
  2914. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  2915. struct drm_i915_private *dev_priv =
  2916. to_i915(intel_dig_port->base.base.dev);
  2917. _intel_dp_set_link_train(intel_dp, &intel_dp->DP, dp_train_pat);
  2918. I915_WRITE(intel_dp->output_reg, intel_dp->DP);
  2919. POSTING_READ(intel_dp->output_reg);
  2920. }
  2921. void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
  2922. {
  2923. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  2924. struct drm_device *dev = intel_dig_port->base.base.dev;
  2925. struct drm_i915_private *dev_priv = to_i915(dev);
  2926. enum port port = intel_dig_port->port;
  2927. uint32_t val;
  2928. if (!HAS_DDI(dev_priv))
  2929. return;
  2930. val = I915_READ(DP_TP_CTL(port));
  2931. val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
  2932. val |= DP_TP_CTL_LINK_TRAIN_IDLE;
  2933. I915_WRITE(DP_TP_CTL(port), val);
  2934. /*
  2935. * On PORT_A we can have only eDP in SST mode. There the only reason
  2936. * we need to set idle transmission mode is to work around a HW issue
  2937. * where we enable the pipe while not in idle link-training mode.
  2938. * In this case there is requirement to wait for a minimum number of
  2939. * idle patterns to be sent.
  2940. */
  2941. if (port == PORT_A)
  2942. return;
  2943. if (intel_wait_for_register(dev_priv,DP_TP_STATUS(port),
  2944. DP_TP_STATUS_IDLE_DONE,
  2945. DP_TP_STATUS_IDLE_DONE,
  2946. 1))
  2947. DRM_ERROR("Timed out waiting for DP idle patterns\n");
  2948. }
  2949. static void
  2950. intel_dp_link_down(struct intel_dp *intel_dp)
  2951. {
  2952. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  2953. struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
  2954. enum port port = intel_dig_port->port;
  2955. struct drm_device *dev = intel_dig_port->base.base.dev;
  2956. struct drm_i915_private *dev_priv = to_i915(dev);
  2957. uint32_t DP = intel_dp->DP;
  2958. if (WARN_ON(HAS_DDI(dev_priv)))
  2959. return;
  2960. if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
  2961. return;
  2962. DRM_DEBUG_KMS("\n");
  2963. if ((IS_GEN7(dev_priv) && port == PORT_A) ||
  2964. (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
  2965. DP &= ~DP_LINK_TRAIN_MASK_CPT;
  2966. DP |= DP_LINK_TRAIN_PAT_IDLE_CPT;
  2967. } else {
  2968. if (IS_CHERRYVIEW(dev_priv))
  2969. DP &= ~DP_LINK_TRAIN_MASK_CHV;
  2970. else
  2971. DP &= ~DP_LINK_TRAIN_MASK;
  2972. DP |= DP_LINK_TRAIN_PAT_IDLE;
  2973. }
  2974. I915_WRITE(intel_dp->output_reg, DP);
  2975. POSTING_READ(intel_dp->output_reg);
  2976. DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
  2977. I915_WRITE(intel_dp->output_reg, DP);
  2978. POSTING_READ(intel_dp->output_reg);
  2979. /*
  2980. * HW workaround for IBX, we need to move the port
  2981. * to transcoder A after disabling it to allow the
  2982. * matching HDMI port to be enabled on transcoder A.
  2983. */
  2984. if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B && port != PORT_A) {
  2985. /*
  2986. * We get CPU/PCH FIFO underruns on the other pipe when
  2987. * doing the workaround. Sweep them under the rug.
  2988. */
  2989. intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
  2990. intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
  2991. /* always enable with pattern 1 (as per spec) */
  2992. DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK);
  2993. DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1;
  2994. I915_WRITE(intel_dp->output_reg, DP);
  2995. POSTING_READ(intel_dp->output_reg);
  2996. DP &= ~DP_PORT_EN;
  2997. I915_WRITE(intel_dp->output_reg, DP);
  2998. POSTING_READ(intel_dp->output_reg);
  2999. intel_wait_for_vblank_if_active(dev_priv, PIPE_A);
  3000. intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
  3001. intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
  3002. }
  3003. msleep(intel_dp->panel_power_down_delay);
  3004. intel_dp->DP = DP;
  3005. if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
  3006. pps_lock(intel_dp);
  3007. intel_dp->active_pipe = INVALID_PIPE;
  3008. pps_unlock(intel_dp);
  3009. }
  3010. }
  3011. bool
  3012. intel_dp_read_dpcd(struct intel_dp *intel_dp)
  3013. {
  3014. if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd,
  3015. sizeof(intel_dp->dpcd)) < 0)
  3016. return false; /* aux transfer failed */
  3017. DRM_DEBUG_KMS("DPCD: %*ph\n", (int) sizeof(intel_dp->dpcd), intel_dp->dpcd);
  3018. return intel_dp->dpcd[DP_DPCD_REV] != 0;
  3019. }
  3020. static bool
  3021. intel_edp_init_dpcd(struct intel_dp *intel_dp)
  3022. {
  3023. struct drm_i915_private *dev_priv =
  3024. to_i915(dp_to_dig_port(intel_dp)->base.base.dev);
  3025. /* this function is meant to be called only once */
  3026. WARN_ON(intel_dp->dpcd[DP_DPCD_REV] != 0);
  3027. if (!intel_dp_read_dpcd(intel_dp))
  3028. return false;
  3029. intel_dp_read_desc(intel_dp);
  3030. if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
  3031. dev_priv->no_aux_handshake = intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
  3032. DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
  3033. /* Check if the panel supports PSR */
  3034. drm_dp_dpcd_read(&intel_dp->aux, DP_PSR_SUPPORT,
  3035. intel_dp->psr_dpcd,
  3036. sizeof(intel_dp->psr_dpcd));
  3037. if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) {
  3038. dev_priv->psr.sink_support = true;
  3039. DRM_DEBUG_KMS("Detected EDP PSR Panel.\n");
  3040. }
  3041. if (INTEL_GEN(dev_priv) >= 9 &&
  3042. (intel_dp->psr_dpcd[0] & DP_PSR2_IS_SUPPORTED)) {
  3043. uint8_t frame_sync_cap;
  3044. dev_priv->psr.sink_support = true;
  3045. if (drm_dp_dpcd_readb(&intel_dp->aux,
  3046. DP_SINK_DEVICE_AUX_FRAME_SYNC_CAP,
  3047. &frame_sync_cap) != 1)
  3048. frame_sync_cap = 0;
  3049. dev_priv->psr.aux_frame_sync = frame_sync_cap ? true : false;
  3050. /* PSR2 needs frame sync as well */
  3051. dev_priv->psr.psr2_support = dev_priv->psr.aux_frame_sync;
  3052. DRM_DEBUG_KMS("PSR2 %s on sink",
  3053. dev_priv->psr.psr2_support ? "supported" : "not supported");
  3054. if (dev_priv->psr.psr2_support) {
  3055. dev_priv->psr.y_cord_support =
  3056. intel_dp_get_y_cord_status(intel_dp);
  3057. dev_priv->psr.colorimetry_support =
  3058. intel_dp_get_colorimetry_status(intel_dp);
  3059. dev_priv->psr.alpm =
  3060. intel_dp_get_alpm_status(intel_dp);
  3061. }
  3062. }
  3063. /* Read the eDP Display control capabilities registers */
  3064. if ((intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] & DP_DPCD_DISPLAY_CONTROL_CAPABLE) &&
  3065. drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
  3066. intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) ==
  3067. sizeof(intel_dp->edp_dpcd))
  3068. DRM_DEBUG_KMS("EDP DPCD : %*ph\n", (int) sizeof(intel_dp->edp_dpcd),
  3069. intel_dp->edp_dpcd);
  3070. /* Intermediate frequency support */
  3071. if (intel_dp->edp_dpcd[0] >= 0x03) { /* eDp v1.4 or higher */
  3072. __le16 sink_rates[DP_MAX_SUPPORTED_RATES];
  3073. int i;
  3074. drm_dp_dpcd_read(&intel_dp->aux, DP_SUPPORTED_LINK_RATES,
  3075. sink_rates, sizeof(sink_rates));
  3076. for (i = 0; i < ARRAY_SIZE(sink_rates); i++) {
  3077. int val = le16_to_cpu(sink_rates[i]);
  3078. if (val == 0)
  3079. break;
  3080. /* Value read multiplied by 200kHz gives the per-lane
  3081. * link rate in kHz. The source rates are, however,
  3082. * stored in terms of LS_Clk kHz. The full conversion
  3083. * back to symbols is
  3084. * (val * 200kHz)*(8/10 ch. encoding)*(1/8 bit to Byte)
  3085. */
  3086. intel_dp->sink_rates[i] = (val * 200) / 10;
  3087. }
  3088. intel_dp->num_sink_rates = i;
  3089. }
  3090. if (intel_dp->num_sink_rates)
  3091. intel_dp->use_rate_select = true;
  3092. else
  3093. intel_dp_set_sink_rates(intel_dp);
  3094. intel_dp_set_common_rates(intel_dp);
  3095. return true;
  3096. }
  3097. static bool
  3098. intel_dp_get_dpcd(struct intel_dp *intel_dp)
  3099. {
  3100. u8 sink_count;
  3101. if (!intel_dp_read_dpcd(intel_dp))
  3102. return false;
  3103. /* Don't clobber cached eDP rates. */
  3104. if (!is_edp(intel_dp)) {
  3105. intel_dp_set_sink_rates(intel_dp);
  3106. intel_dp_set_common_rates(intel_dp);
  3107. }
  3108. if (drm_dp_dpcd_readb(&intel_dp->aux, DP_SINK_COUNT, &sink_count) <= 0)
  3109. return false;
  3110. /*
  3111. * Sink count can change between short pulse hpd hence
  3112. * a member variable in intel_dp will track any changes
  3113. * between short pulse interrupts.
  3114. */
  3115. intel_dp->sink_count = DP_GET_SINK_COUNT(sink_count);
  3116. /*
  3117. * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that
  3118. * a dongle is present but no display. Unless we require to know
  3119. * if a dongle is present or not, we don't need to update
  3120. * downstream port information. So, an early return here saves
  3121. * time from performing other operations which are not required.
  3122. */
  3123. if (!is_edp(intel_dp) && !intel_dp->sink_count)
  3124. return false;
  3125. if (!drm_dp_is_branch(intel_dp->dpcd))
  3126. return true; /* native DP sink */
  3127. if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
  3128. return true; /* no per-port downstream info */
  3129. if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0,
  3130. intel_dp->downstream_ports,
  3131. DP_MAX_DOWNSTREAM_PORTS) < 0)
  3132. return false; /* downstream port status fetch failed */
  3133. return true;
  3134. }
  3135. static bool
  3136. intel_dp_can_mst(struct intel_dp *intel_dp)
  3137. {
  3138. u8 mstm_cap;
  3139. if (!i915.enable_dp_mst)
  3140. return false;
  3141. if (!intel_dp->can_mst)
  3142. return false;
  3143. if (intel_dp->dpcd[DP_DPCD_REV] < 0x12)
  3144. return false;
  3145. if (drm_dp_dpcd_readb(&intel_dp->aux, DP_MSTM_CAP, &mstm_cap) != 1)
  3146. return false;
  3147. return mstm_cap & DP_MST_CAP;
  3148. }
  3149. static void
  3150. intel_dp_configure_mst(struct intel_dp *intel_dp)
  3151. {
  3152. if (!i915.enable_dp_mst)
  3153. return;
  3154. if (!intel_dp->can_mst)
  3155. return;
  3156. intel_dp->is_mst = intel_dp_can_mst(intel_dp);
  3157. if (intel_dp->is_mst)
  3158. DRM_DEBUG_KMS("Sink is MST capable\n");
  3159. else
  3160. DRM_DEBUG_KMS("Sink is not MST capable\n");
  3161. drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
  3162. intel_dp->is_mst);
  3163. }
  3164. static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp)
  3165. {
  3166. struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
  3167. struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
  3168. struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
  3169. u8 buf;
  3170. int ret = 0;
  3171. int count = 0;
  3172. int attempts = 10;
  3173. if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) {
  3174. DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
  3175. ret = -EIO;
  3176. goto out;
  3177. }
  3178. if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
  3179. buf & ~DP_TEST_SINK_START) < 0) {
  3180. DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
  3181. ret = -EIO;
  3182. goto out;
  3183. }
  3184. do {
  3185. intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
  3186. if (drm_dp_dpcd_readb(&intel_dp->aux,
  3187. DP_TEST_SINK_MISC, &buf) < 0) {
  3188. ret = -EIO;
  3189. goto out;
  3190. }
  3191. count = buf & DP_TEST_COUNT_MASK;
  3192. } while (--attempts && count);
  3193. if (attempts == 0) {
  3194. DRM_DEBUG_KMS("TIMEOUT: Sink CRC counter is not zeroed after calculation is stopped\n");
  3195. ret = -ETIMEDOUT;
  3196. }
  3197. out:
  3198. hsw_enable_ips(intel_crtc);
  3199. return ret;
  3200. }
  3201. static int intel_dp_sink_crc_start(struct intel_dp *intel_dp)
  3202. {
  3203. struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
  3204. struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
  3205. struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
  3206. u8 buf;
  3207. int ret;
  3208. if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0)
  3209. return -EIO;
  3210. if (!(buf & DP_TEST_CRC_SUPPORTED))
  3211. return -ENOTTY;
  3212. if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0)
  3213. return -EIO;
  3214. if (buf & DP_TEST_SINK_START) {
  3215. ret = intel_dp_sink_crc_stop(intel_dp);
  3216. if (ret)
  3217. return ret;
  3218. }
  3219. hsw_disable_ips(intel_crtc);
  3220. if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
  3221. buf | DP_TEST_SINK_START) < 0) {
  3222. hsw_enable_ips(intel_crtc);
  3223. return -EIO;
  3224. }
  3225. intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
  3226. return 0;
  3227. }
  3228. int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc)
  3229. {
  3230. struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
  3231. struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
  3232. struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
  3233. u8 buf;
  3234. int count, ret;
  3235. int attempts = 6;
  3236. ret = intel_dp_sink_crc_start(intel_dp);
  3237. if (ret)
  3238. return ret;
  3239. do {
  3240. intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
  3241. if (drm_dp_dpcd_readb(&intel_dp->aux,
  3242. DP_TEST_SINK_MISC, &buf) < 0) {
  3243. ret = -EIO;
  3244. goto stop;
  3245. }
  3246. count = buf & DP_TEST_COUNT_MASK;
  3247. } while (--attempts && count == 0);
  3248. if (attempts == 0) {
  3249. DRM_ERROR("Panel is unable to calculate any CRC after 6 vblanks\n");
  3250. ret = -ETIMEDOUT;
  3251. goto stop;
  3252. }
  3253. if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0) {
  3254. ret = -EIO;
  3255. goto stop;
  3256. }
  3257. stop:
  3258. intel_dp_sink_crc_stop(intel_dp);
  3259. return ret;
  3260. }
  3261. static bool
  3262. intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
  3263. {
  3264. return drm_dp_dpcd_readb(&intel_dp->aux, DP_DEVICE_SERVICE_IRQ_VECTOR,
  3265. sink_irq_vector) == 1;
  3266. }
  3267. static bool
  3268. intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector)
  3269. {
  3270. int ret;
  3271. ret = drm_dp_dpcd_read(&intel_dp->aux,
  3272. DP_SINK_COUNT_ESI,
  3273. sink_irq_vector, 14);
  3274. if (ret != 14)
  3275. return false;
  3276. return true;
  3277. }
  3278. static uint8_t intel_dp_autotest_link_training(struct intel_dp *intel_dp)
  3279. {
  3280. int status = 0;
  3281. int min_lane_count = 1;
  3282. int link_rate_index, test_link_rate;
  3283. uint8_t test_lane_count, test_link_bw;
  3284. /* (DP CTS 1.2)
  3285. * 4.3.1.11
  3286. */
  3287. /* Read the TEST_LANE_COUNT and TEST_LINK_RTAE fields (DP CTS 3.1.4) */
  3288. status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LANE_COUNT,
  3289. &test_lane_count);
  3290. if (status <= 0) {
  3291. DRM_DEBUG_KMS("Lane count read failed\n");
  3292. return DP_TEST_NAK;
  3293. }
  3294. test_lane_count &= DP_MAX_LANE_COUNT_MASK;
  3295. /* Validate the requested lane count */
  3296. if (test_lane_count < min_lane_count ||
  3297. test_lane_count > intel_dp->max_link_lane_count)
  3298. return DP_TEST_NAK;
  3299. status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LINK_RATE,
  3300. &test_link_bw);
  3301. if (status <= 0) {
  3302. DRM_DEBUG_KMS("Link Rate read failed\n");
  3303. return DP_TEST_NAK;
  3304. }
  3305. /* Validate the requested link rate */
  3306. test_link_rate = drm_dp_bw_code_to_link_rate(test_link_bw);
  3307. link_rate_index = intel_dp_rate_index(intel_dp->common_rates,
  3308. intel_dp->num_common_rates,
  3309. test_link_rate);
  3310. if (link_rate_index < 0)
  3311. return DP_TEST_NAK;
  3312. intel_dp->compliance.test_lane_count = test_lane_count;
  3313. intel_dp->compliance.test_link_rate = test_link_rate;
  3314. return DP_TEST_ACK;
  3315. }
  3316. static uint8_t intel_dp_autotest_video_pattern(struct intel_dp *intel_dp)
  3317. {
  3318. uint8_t test_pattern;
  3319. uint8_t test_misc;
  3320. __be16 h_width, v_height;
  3321. int status = 0;
  3322. /* Read the TEST_PATTERN (DP CTS 3.1.5) */
  3323. status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_PATTERN,
  3324. &test_pattern);
  3325. if (status <= 0) {
  3326. DRM_DEBUG_KMS("Test pattern read failed\n");
  3327. return DP_TEST_NAK;
  3328. }
  3329. if (test_pattern != DP_COLOR_RAMP)
  3330. return DP_TEST_NAK;
  3331. status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_H_WIDTH_HI,
  3332. &h_width, 2);
  3333. if (status <= 0) {
  3334. DRM_DEBUG_KMS("H Width read failed\n");
  3335. return DP_TEST_NAK;
  3336. }
  3337. status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_V_HEIGHT_HI,
  3338. &v_height, 2);
  3339. if (status <= 0) {
  3340. DRM_DEBUG_KMS("V Height read failed\n");
  3341. return DP_TEST_NAK;
  3342. }
  3343. status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_MISC0,
  3344. &test_misc);
  3345. if (status <= 0) {
  3346. DRM_DEBUG_KMS("TEST MISC read failed\n");
  3347. return DP_TEST_NAK;
  3348. }
  3349. if ((test_misc & DP_TEST_COLOR_FORMAT_MASK) != DP_COLOR_FORMAT_RGB)
  3350. return DP_TEST_NAK;
  3351. if (test_misc & DP_TEST_DYNAMIC_RANGE_CEA)
  3352. return DP_TEST_NAK;
  3353. switch (test_misc & DP_TEST_BIT_DEPTH_MASK) {
  3354. case DP_TEST_BIT_DEPTH_6:
  3355. intel_dp->compliance.test_data.bpc = 6;
  3356. break;
  3357. case DP_TEST_BIT_DEPTH_8:
  3358. intel_dp->compliance.test_data.bpc = 8;
  3359. break;
  3360. default:
  3361. return DP_TEST_NAK;
  3362. }
  3363. intel_dp->compliance.test_data.video_pattern = test_pattern;
  3364. intel_dp->compliance.test_data.hdisplay = be16_to_cpu(h_width);
  3365. intel_dp->compliance.test_data.vdisplay = be16_to_cpu(v_height);
  3366. /* Set test active flag here so userspace doesn't interrupt things */
  3367. intel_dp->compliance.test_active = 1;
  3368. return DP_TEST_ACK;
  3369. }
  3370. static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp)
  3371. {
  3372. uint8_t test_result = DP_TEST_ACK;
  3373. struct intel_connector *intel_connector = intel_dp->attached_connector;
  3374. struct drm_connector *connector = &intel_connector->base;
  3375. if (intel_connector->detect_edid == NULL ||
  3376. connector->edid_corrupt ||
  3377. intel_dp->aux.i2c_defer_count > 6) {
  3378. /* Check EDID read for NACKs, DEFERs and corruption
  3379. * (DP CTS 1.2 Core r1.1)
  3380. * 4.2.2.4 : Failed EDID read, I2C_NAK
  3381. * 4.2.2.5 : Failed EDID read, I2C_DEFER
  3382. * 4.2.2.6 : EDID corruption detected
  3383. * Use failsafe mode for all cases
  3384. */
  3385. if (intel_dp->aux.i2c_nack_count > 0 ||
  3386. intel_dp->aux.i2c_defer_count > 0)
  3387. DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n",
  3388. intel_dp->aux.i2c_nack_count,
  3389. intel_dp->aux.i2c_defer_count);
  3390. intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_FAILSAFE;
  3391. } else {
  3392. struct edid *block = intel_connector->detect_edid;
  3393. /* We have to write the checksum
  3394. * of the last block read
  3395. */
  3396. block += intel_connector->detect_edid->extensions;
  3397. if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_EDID_CHECKSUM,
  3398. block->checksum) <= 0)
  3399. DRM_DEBUG_KMS("Failed to write EDID checksum\n");
  3400. test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE;
  3401. intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_PREFERRED;
  3402. }
  3403. /* Set test active flag here so userspace doesn't interrupt things */
  3404. intel_dp->compliance.test_active = 1;
  3405. return test_result;
  3406. }
  3407. static uint8_t intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp)
  3408. {
  3409. uint8_t test_result = DP_TEST_NAK;
  3410. return test_result;
  3411. }
  3412. static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
  3413. {
  3414. uint8_t response = DP_TEST_NAK;
  3415. uint8_t request = 0;
  3416. int status;
  3417. status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_REQUEST, &request);
  3418. if (status <= 0) {
  3419. DRM_DEBUG_KMS("Could not read test request from sink\n");
  3420. goto update_status;
  3421. }
  3422. switch (request) {
  3423. case DP_TEST_LINK_TRAINING:
  3424. DRM_DEBUG_KMS("LINK_TRAINING test requested\n");
  3425. response = intel_dp_autotest_link_training(intel_dp);
  3426. break;
  3427. case DP_TEST_LINK_VIDEO_PATTERN:
  3428. DRM_DEBUG_KMS("TEST_PATTERN test requested\n");
  3429. response = intel_dp_autotest_video_pattern(intel_dp);
  3430. break;
  3431. case DP_TEST_LINK_EDID_READ:
  3432. DRM_DEBUG_KMS("EDID test requested\n");
  3433. response = intel_dp_autotest_edid(intel_dp);
  3434. break;
  3435. case DP_TEST_LINK_PHY_TEST_PATTERN:
  3436. DRM_DEBUG_KMS("PHY_PATTERN test requested\n");
  3437. response = intel_dp_autotest_phy_pattern(intel_dp);
  3438. break;
  3439. default:
  3440. DRM_DEBUG_KMS("Invalid test request '%02x'\n", request);
  3441. break;
  3442. }
  3443. if (response & DP_TEST_ACK)
  3444. intel_dp->compliance.test_type = request;
  3445. update_status:
  3446. status = drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_RESPONSE, response);
  3447. if (status <= 0)
  3448. DRM_DEBUG_KMS("Could not write test response to sink\n");
  3449. }
  3450. static int
  3451. intel_dp_check_mst_status(struct intel_dp *intel_dp)
  3452. {
  3453. bool bret;
  3454. if (intel_dp->is_mst) {
  3455. u8 esi[16] = { 0 };
  3456. int ret = 0;
  3457. int retry;
  3458. bool handled;
  3459. bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
  3460. go_again:
  3461. if (bret == true) {
  3462. /* check link status - esi[10] = 0x200c */
  3463. if (intel_dp->active_mst_links &&
  3464. !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) {
  3465. DRM_DEBUG_KMS("channel EQ not ok, retraining\n");
  3466. intel_dp_start_link_train(intel_dp);
  3467. intel_dp_stop_link_train(intel_dp);
  3468. }
  3469. DRM_DEBUG_KMS("got esi %3ph\n", esi);
  3470. ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled);
  3471. if (handled) {
  3472. for (retry = 0; retry < 3; retry++) {
  3473. int wret;
  3474. wret = drm_dp_dpcd_write(&intel_dp->aux,
  3475. DP_SINK_COUNT_ESI+1,
  3476. &esi[1], 3);
  3477. if (wret == 3) {
  3478. break;
  3479. }
  3480. }
  3481. bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
  3482. if (bret == true) {
  3483. DRM_DEBUG_KMS("got esi2 %3ph\n", esi);
  3484. goto go_again;
  3485. }
  3486. } else
  3487. ret = 0;
  3488. return ret;
  3489. } else {
  3490. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  3491. DRM_DEBUG_KMS("failed to get ESI - device may have failed\n");
  3492. intel_dp->is_mst = false;
  3493. drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
  3494. /* send a hotplug event */
  3495. drm_kms_helper_hotplug_event(intel_dig_port->base.base.dev);
  3496. }
  3497. }
  3498. return -EINVAL;
  3499. }
  3500. static void
  3501. intel_dp_retrain_link(struct intel_dp *intel_dp)
  3502. {
  3503. struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
  3504. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  3505. struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
  3506. /* Suppress underruns caused by re-training */
  3507. intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
  3508. if (crtc->config->has_pch_encoder)
  3509. intel_set_pch_fifo_underrun_reporting(dev_priv,
  3510. intel_crtc_pch_transcoder(crtc), false);
  3511. intel_dp_start_link_train(intel_dp);
  3512. intel_dp_stop_link_train(intel_dp);
  3513. /* Keep underrun reporting disabled until things are stable */
  3514. intel_wait_for_vblank(dev_priv, crtc->pipe);
  3515. intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
  3516. if (crtc->config->has_pch_encoder)
  3517. intel_set_pch_fifo_underrun_reporting(dev_priv,
  3518. intel_crtc_pch_transcoder(crtc), true);
  3519. }
  3520. static void
  3521. intel_dp_check_link_status(struct intel_dp *intel_dp)
  3522. {
  3523. struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
  3524. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  3525. u8 link_status[DP_LINK_STATUS_SIZE];
  3526. WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
  3527. if (!intel_dp_get_link_status(intel_dp, link_status)) {
  3528. DRM_ERROR("Failed to get link status\n");
  3529. return;
  3530. }
  3531. if (!intel_encoder->base.crtc)
  3532. return;
  3533. if (!to_intel_crtc(intel_encoder->base.crtc)->active)
  3534. return;
  3535. /*
  3536. * Validate the cached values of intel_dp->link_rate and
  3537. * intel_dp->lane_count before attempting to retrain.
  3538. */
  3539. if (!intel_dp_link_params_valid(intel_dp))
  3540. return;
  3541. /* Retrain if Channel EQ or CR not ok */
  3542. if (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
  3543. DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
  3544. intel_encoder->base.name);
  3545. intel_dp_retrain_link(intel_dp);
  3546. }
  3547. }
  3548. /*
  3549. * According to DP spec
  3550. * 5.1.2:
  3551. * 1. Read DPCD
  3552. * 2. Configure link according to Receiver Capabilities
  3553. * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
  3554. * 4. Check link status on receipt of hot-plug interrupt
  3555. *
  3556. * intel_dp_short_pulse - handles short pulse interrupts
  3557. * when full detection is not required.
  3558. * Returns %true if short pulse is handled and full detection
  3559. * is NOT required and %false otherwise.
  3560. */
  3561. static bool
  3562. intel_dp_short_pulse(struct intel_dp *intel_dp)
  3563. {
  3564. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  3565. struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
  3566. u8 sink_irq_vector = 0;
  3567. u8 old_sink_count = intel_dp->sink_count;
  3568. bool ret;
  3569. /*
  3570. * Clearing compliance test variables to allow capturing
  3571. * of values for next automated test request.
  3572. */
  3573. memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
  3574. /*
  3575. * Now read the DPCD to see if it's actually running
  3576. * If the current value of sink count doesn't match with
  3577. * the value that was stored earlier or dpcd read failed
  3578. * we need to do full detection
  3579. */
  3580. ret = intel_dp_get_dpcd(intel_dp);
  3581. if ((old_sink_count != intel_dp->sink_count) || !ret) {
  3582. /* No need to proceed if we are going to do full detect */
  3583. return false;
  3584. }
  3585. /* Try to read the source of the interrupt */
  3586. if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
  3587. intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
  3588. sink_irq_vector != 0) {
  3589. /* Clear interrupt source */
  3590. drm_dp_dpcd_writeb(&intel_dp->aux,
  3591. DP_DEVICE_SERVICE_IRQ_VECTOR,
  3592. sink_irq_vector);
  3593. if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
  3594. intel_dp_handle_test_request(intel_dp);
  3595. if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
  3596. DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
  3597. }
  3598. drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
  3599. intel_dp_check_link_status(intel_dp);
  3600. drm_modeset_unlock(&dev->mode_config.connection_mutex);
  3601. if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
  3602. DRM_DEBUG_KMS("Link Training Compliance Test requested\n");
  3603. /* Send a Hotplug Uevent to userspace to start modeset */
  3604. drm_kms_helper_hotplug_event(intel_encoder->base.dev);
  3605. }
  3606. return true;
  3607. }
  3608. /* XXX this is probably wrong for multiple downstream ports */
  3609. static enum drm_connector_status
  3610. intel_dp_detect_dpcd(struct intel_dp *intel_dp)
  3611. {
  3612. struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
  3613. uint8_t *dpcd = intel_dp->dpcd;
  3614. uint8_t type;
  3615. if (lspcon->active)
  3616. lspcon_resume(lspcon);
  3617. if (!intel_dp_get_dpcd(intel_dp))
  3618. return connector_status_disconnected;
  3619. if (is_edp(intel_dp))
  3620. return connector_status_connected;
  3621. /* if there's no downstream port, we're done */
  3622. if (!drm_dp_is_branch(dpcd))
  3623. return connector_status_connected;
  3624. /* If we're HPD-aware, SINK_COUNT changes dynamically */
  3625. if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
  3626. intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
  3627. return intel_dp->sink_count ?
  3628. connector_status_connected : connector_status_disconnected;
  3629. }
  3630. if (intel_dp_can_mst(intel_dp))
  3631. return connector_status_connected;
  3632. /* If no HPD, poke DDC gently */
  3633. if (drm_probe_ddc(&intel_dp->aux.ddc))
  3634. return connector_status_connected;
  3635. /* Well we tried, say unknown for unreliable port types */
  3636. if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
  3637. type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
  3638. if (type == DP_DS_PORT_TYPE_VGA ||
  3639. type == DP_DS_PORT_TYPE_NON_EDID)
  3640. return connector_status_unknown;
  3641. } else {
  3642. type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
  3643. DP_DWN_STRM_PORT_TYPE_MASK;
  3644. if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
  3645. type == DP_DWN_STRM_PORT_TYPE_OTHER)
  3646. return connector_status_unknown;
  3647. }
  3648. /* Anything else is out of spec, warn and ignore */
  3649. DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
  3650. return connector_status_disconnected;
  3651. }
  3652. static enum drm_connector_status
  3653. edp_detect(struct intel_dp *intel_dp)
  3654. {
  3655. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  3656. struct drm_i915_private *dev_priv = to_i915(dev);
  3657. enum drm_connector_status status;
  3658. status = intel_panel_detect(dev_priv);
  3659. if (status == connector_status_unknown)
  3660. status = connector_status_connected;
  3661. return status;
  3662. }
  3663. static bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
  3664. struct intel_digital_port *port)
  3665. {
  3666. u32 bit;
  3667. switch (port->port) {
  3668. case PORT_A:
  3669. return true;
  3670. case PORT_B:
  3671. bit = SDE_PORTB_HOTPLUG;
  3672. break;
  3673. case PORT_C:
  3674. bit = SDE_PORTC_HOTPLUG;
  3675. break;
  3676. case PORT_D:
  3677. bit = SDE_PORTD_HOTPLUG;
  3678. break;
  3679. default:
  3680. MISSING_CASE(port->port);
  3681. return false;
  3682. }
  3683. return I915_READ(SDEISR) & bit;
  3684. }
  3685. static bool cpt_digital_port_connected(struct drm_i915_private *dev_priv,
  3686. struct intel_digital_port *port)
  3687. {
  3688. u32 bit;
  3689. switch (port->port) {
  3690. case PORT_A:
  3691. return true;
  3692. case PORT_B:
  3693. bit = SDE_PORTB_HOTPLUG_CPT;
  3694. break;
  3695. case PORT_C:
  3696. bit = SDE_PORTC_HOTPLUG_CPT;
  3697. break;
  3698. case PORT_D:
  3699. bit = SDE_PORTD_HOTPLUG_CPT;
  3700. break;
  3701. case PORT_E:
  3702. bit = SDE_PORTE_HOTPLUG_SPT;
  3703. break;
  3704. default:
  3705. MISSING_CASE(port->port);
  3706. return false;
  3707. }
  3708. return I915_READ(SDEISR) & bit;
  3709. }
  3710. static bool g4x_digital_port_connected(struct drm_i915_private *dev_priv,
  3711. struct intel_digital_port *port)
  3712. {
  3713. u32 bit;
  3714. switch (port->port) {
  3715. case PORT_B:
  3716. bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
  3717. break;
  3718. case PORT_C:
  3719. bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
  3720. break;
  3721. case PORT_D:
  3722. bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
  3723. break;
  3724. default:
  3725. MISSING_CASE(port->port);
  3726. return false;
  3727. }
  3728. return I915_READ(PORT_HOTPLUG_STAT) & bit;
  3729. }
  3730. static bool gm45_digital_port_connected(struct drm_i915_private *dev_priv,
  3731. struct intel_digital_port *port)
  3732. {
  3733. u32 bit;
  3734. switch (port->port) {
  3735. case PORT_B:
  3736. bit = PORTB_HOTPLUG_LIVE_STATUS_GM45;
  3737. break;
  3738. case PORT_C:
  3739. bit = PORTC_HOTPLUG_LIVE_STATUS_GM45;
  3740. break;
  3741. case PORT_D:
  3742. bit = PORTD_HOTPLUG_LIVE_STATUS_GM45;
  3743. break;
  3744. default:
  3745. MISSING_CASE(port->port);
  3746. return false;
  3747. }
  3748. return I915_READ(PORT_HOTPLUG_STAT) & bit;
  3749. }
  3750. static bool bxt_digital_port_connected(struct drm_i915_private *dev_priv,
  3751. struct intel_digital_port *intel_dig_port)
  3752. {
  3753. struct intel_encoder *intel_encoder = &intel_dig_port->base;
  3754. enum port port;
  3755. u32 bit;
  3756. intel_hpd_pin_to_port(intel_encoder->hpd_pin, &port);
  3757. switch (port) {
  3758. case PORT_A:
  3759. bit = BXT_DE_PORT_HP_DDIA;
  3760. break;
  3761. case PORT_B:
  3762. bit = BXT_DE_PORT_HP_DDIB;
  3763. break;
  3764. case PORT_C:
  3765. bit = BXT_DE_PORT_HP_DDIC;
  3766. break;
  3767. default:
  3768. MISSING_CASE(port);
  3769. return false;
  3770. }
  3771. return I915_READ(GEN8_DE_PORT_ISR) & bit;
  3772. }
  3773. /*
  3774. * intel_digital_port_connected - is the specified port connected?
  3775. * @dev_priv: i915 private structure
  3776. * @port: the port to test
  3777. *
  3778. * Return %true if @port is connected, %false otherwise.
  3779. */
  3780. bool intel_digital_port_connected(struct drm_i915_private *dev_priv,
  3781. struct intel_digital_port *port)
  3782. {
  3783. if (HAS_PCH_IBX(dev_priv))
  3784. return ibx_digital_port_connected(dev_priv, port);
  3785. else if (HAS_PCH_SPLIT(dev_priv))
  3786. return cpt_digital_port_connected(dev_priv, port);
  3787. else if (IS_GEN9_LP(dev_priv))
  3788. return bxt_digital_port_connected(dev_priv, port);
  3789. else if (IS_GM45(dev_priv))
  3790. return gm45_digital_port_connected(dev_priv, port);
  3791. else
  3792. return g4x_digital_port_connected(dev_priv, port);
  3793. }
  3794. static struct edid *
  3795. intel_dp_get_edid(struct intel_dp *intel_dp)
  3796. {
  3797. struct intel_connector *intel_connector = intel_dp->attached_connector;
  3798. /* use cached edid if we have one */
  3799. if (intel_connector->edid) {
  3800. /* invalid edid */
  3801. if (IS_ERR(intel_connector->edid))
  3802. return NULL;
  3803. return drm_edid_duplicate(intel_connector->edid);
  3804. } else
  3805. return drm_get_edid(&intel_connector->base,
  3806. &intel_dp->aux.ddc);
  3807. }
  3808. static void
  3809. intel_dp_set_edid(struct intel_dp *intel_dp)
  3810. {
  3811. struct intel_connector *intel_connector = intel_dp->attached_connector;
  3812. struct edid *edid;
  3813. intel_dp_unset_edid(intel_dp);
  3814. edid = intel_dp_get_edid(intel_dp);
  3815. intel_connector->detect_edid = edid;
  3816. if (intel_dp->force_audio != HDMI_AUDIO_AUTO)
  3817. intel_dp->has_audio = intel_dp->force_audio == HDMI_AUDIO_ON;
  3818. else
  3819. intel_dp->has_audio = drm_detect_monitor_audio(edid);
  3820. }
  3821. static void
  3822. intel_dp_unset_edid(struct intel_dp *intel_dp)
  3823. {
  3824. struct intel_connector *intel_connector = intel_dp->attached_connector;
  3825. kfree(intel_connector->detect_edid);
  3826. intel_connector->detect_edid = NULL;
  3827. intel_dp->has_audio = false;
  3828. }
  3829. static int
  3830. intel_dp_long_pulse(struct intel_connector *intel_connector)
  3831. {
  3832. struct drm_connector *connector = &intel_connector->base;
  3833. struct intel_dp *intel_dp = intel_attached_dp(connector);
  3834. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  3835. struct intel_encoder *intel_encoder = &intel_dig_port->base;
  3836. struct drm_device *dev = connector->dev;
  3837. enum drm_connector_status status;
  3838. u8 sink_irq_vector = 0;
  3839. WARN_ON(!drm_modeset_is_locked(&connector->dev->mode_config.connection_mutex));
  3840. intel_display_power_get(to_i915(dev), intel_dp->aux_power_domain);
  3841. /* Can't disconnect eDP, but you can close the lid... */
  3842. if (is_edp(intel_dp))
  3843. status = edp_detect(intel_dp);
  3844. else if (intel_digital_port_connected(to_i915(dev),
  3845. dp_to_dig_port(intel_dp)))
  3846. status = intel_dp_detect_dpcd(intel_dp);
  3847. else
  3848. status = connector_status_disconnected;
  3849. if (status == connector_status_disconnected) {
  3850. memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
  3851. if (intel_dp->is_mst) {
  3852. DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
  3853. intel_dp->is_mst,
  3854. intel_dp->mst_mgr.mst_state);
  3855. intel_dp->is_mst = false;
  3856. drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
  3857. intel_dp->is_mst);
  3858. }
  3859. goto out;
  3860. }
  3861. if (intel_encoder->type != INTEL_OUTPUT_EDP)
  3862. intel_encoder->type = INTEL_OUTPUT_DP;
  3863. DRM_DEBUG_KMS("Display Port TPS3 support: source %s, sink %s\n",
  3864. yesno(intel_dp_source_supports_hbr2(intel_dp)),
  3865. yesno(drm_dp_tps3_supported(intel_dp->dpcd)));
  3866. if (intel_dp->reset_link_params) {
  3867. /* Initial max link lane count */
  3868. intel_dp->max_link_lane_count = intel_dp_max_common_lane_count(intel_dp);
  3869. /* Initial max link rate */
  3870. intel_dp->max_link_rate = intel_dp_max_common_rate(intel_dp);
  3871. intel_dp->reset_link_params = false;
  3872. }
  3873. intel_dp_print_rates(intel_dp);
  3874. intel_dp_read_desc(intel_dp);
  3875. intel_dp_configure_mst(intel_dp);
  3876. if (intel_dp->is_mst) {
  3877. /*
  3878. * If we are in MST mode then this connector
  3879. * won't appear connected or have anything
  3880. * with EDID on it
  3881. */
  3882. status = connector_status_disconnected;
  3883. goto out;
  3884. } else {
  3885. /*
  3886. * If display is now connected check links status,
  3887. * there has been known issues of link loss triggerring
  3888. * long pulse.
  3889. *
  3890. * Some sinks (eg. ASUS PB287Q) seem to perform some
  3891. * weird HPD ping pong during modesets. So we can apparently
  3892. * end up with HPD going low during a modeset, and then
  3893. * going back up soon after. And once that happens we must
  3894. * retrain the link to get a picture. That's in case no
  3895. * userspace component reacted to intermittent HPD dip.
  3896. */
  3897. intel_dp_check_link_status(intel_dp);
  3898. }
  3899. /*
  3900. * Clearing NACK and defer counts to get their exact values
  3901. * while reading EDID which are required by Compliance tests
  3902. * 4.2.2.4 and 4.2.2.5
  3903. */
  3904. intel_dp->aux.i2c_nack_count = 0;
  3905. intel_dp->aux.i2c_defer_count = 0;
  3906. intel_dp_set_edid(intel_dp);
  3907. if (is_edp(intel_dp) || intel_connector->detect_edid)
  3908. status = connector_status_connected;
  3909. intel_dp->detect_done = true;
  3910. /* Try to read the source of the interrupt */
  3911. if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
  3912. intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
  3913. sink_irq_vector != 0) {
  3914. /* Clear interrupt source */
  3915. drm_dp_dpcd_writeb(&intel_dp->aux,
  3916. DP_DEVICE_SERVICE_IRQ_VECTOR,
  3917. sink_irq_vector);
  3918. if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
  3919. intel_dp_handle_test_request(intel_dp);
  3920. if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
  3921. DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
  3922. }
  3923. out:
  3924. if (status != connector_status_connected && !intel_dp->is_mst)
  3925. intel_dp_unset_edid(intel_dp);
  3926. intel_display_power_put(to_i915(dev), intel_dp->aux_power_domain);
  3927. return status;
  3928. }
  3929. static int
  3930. intel_dp_detect(struct drm_connector *connector,
  3931. struct drm_modeset_acquire_ctx *ctx,
  3932. bool force)
  3933. {
  3934. struct intel_dp *intel_dp = intel_attached_dp(connector);
  3935. int status = connector->status;
  3936. DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
  3937. connector->base.id, connector->name);
  3938. /* If full detect is not performed yet, do a full detect */
  3939. if (!intel_dp->detect_done)
  3940. status = intel_dp_long_pulse(intel_dp->attached_connector);
  3941. intel_dp->detect_done = false;
  3942. return status;
  3943. }
  3944. static void
  3945. intel_dp_force(struct drm_connector *connector)
  3946. {
  3947. struct intel_dp *intel_dp = intel_attached_dp(connector);
  3948. struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
  3949. struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
  3950. DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
  3951. connector->base.id, connector->name);
  3952. intel_dp_unset_edid(intel_dp);
  3953. if (connector->status != connector_status_connected)
  3954. return;
  3955. intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
  3956. intel_dp_set_edid(intel_dp);
  3957. intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
  3958. if (intel_encoder->type != INTEL_OUTPUT_EDP)
  3959. intel_encoder->type = INTEL_OUTPUT_DP;
  3960. }
  3961. static int intel_dp_get_modes(struct drm_connector *connector)
  3962. {
  3963. struct intel_connector *intel_connector = to_intel_connector(connector);
  3964. struct edid *edid;
  3965. edid = intel_connector->detect_edid;
  3966. if (edid) {
  3967. int ret = intel_connector_update_modes(connector, edid);
  3968. if (ret)
  3969. return ret;
  3970. }
  3971. /* if eDP has no EDID, fall back to fixed mode */
  3972. if (is_edp(intel_attached_dp(connector)) &&
  3973. intel_connector->panel.fixed_mode) {
  3974. struct drm_display_mode *mode;
  3975. mode = drm_mode_duplicate(connector->dev,
  3976. intel_connector->panel.fixed_mode);
  3977. if (mode) {
  3978. drm_mode_probed_add(connector, mode);
  3979. return 1;
  3980. }
  3981. }
  3982. return 0;
  3983. }
  3984. static bool
  3985. intel_dp_detect_audio(struct drm_connector *connector)
  3986. {
  3987. bool has_audio = false;
  3988. struct edid *edid;
  3989. edid = to_intel_connector(connector)->detect_edid;
  3990. if (edid)
  3991. has_audio = drm_detect_monitor_audio(edid);
  3992. return has_audio;
  3993. }
  3994. static int
  3995. intel_dp_set_property(struct drm_connector *connector,
  3996. struct drm_property *property,
  3997. uint64_t val)
  3998. {
  3999. struct drm_i915_private *dev_priv = to_i915(connector->dev);
  4000. struct intel_connector *intel_connector = to_intel_connector(connector);
  4001. struct intel_encoder *intel_encoder = intel_attached_encoder(connector);
  4002. struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
  4003. int ret;
  4004. ret = drm_object_property_set_value(&connector->base, property, val);
  4005. if (ret)
  4006. return ret;
  4007. if (property == dev_priv->force_audio_property) {
  4008. int i = val;
  4009. bool has_audio;
  4010. if (i == intel_dp->force_audio)
  4011. return 0;
  4012. intel_dp->force_audio = i;
  4013. if (i == HDMI_AUDIO_AUTO)
  4014. has_audio = intel_dp_detect_audio(connector);
  4015. else
  4016. has_audio = (i == HDMI_AUDIO_ON);
  4017. if (has_audio == intel_dp->has_audio)
  4018. return 0;
  4019. intel_dp->has_audio = has_audio;
  4020. goto done;
  4021. }
  4022. if (property == dev_priv->broadcast_rgb_property) {
  4023. bool old_auto = intel_dp->color_range_auto;
  4024. bool old_range = intel_dp->limited_color_range;
  4025. switch (val) {
  4026. case INTEL_BROADCAST_RGB_AUTO:
  4027. intel_dp->color_range_auto = true;
  4028. break;
  4029. case INTEL_BROADCAST_RGB_FULL:
  4030. intel_dp->color_range_auto = false;
  4031. intel_dp->limited_color_range = false;
  4032. break;
  4033. case INTEL_BROADCAST_RGB_LIMITED:
  4034. intel_dp->color_range_auto = false;
  4035. intel_dp->limited_color_range = true;
  4036. break;
  4037. default:
  4038. return -EINVAL;
  4039. }
  4040. if (old_auto == intel_dp->color_range_auto &&
  4041. old_range == intel_dp->limited_color_range)
  4042. return 0;
  4043. goto done;
  4044. }
  4045. if (is_edp(intel_dp) &&
  4046. property == connector->dev->mode_config.scaling_mode_property) {
  4047. if (val == DRM_MODE_SCALE_NONE) {
  4048. DRM_DEBUG_KMS("no scaling not supported\n");
  4049. return -EINVAL;
  4050. }
  4051. if (HAS_GMCH_DISPLAY(dev_priv) &&
  4052. val == DRM_MODE_SCALE_CENTER) {
  4053. DRM_DEBUG_KMS("centering not supported\n");
  4054. return -EINVAL;
  4055. }
  4056. if (intel_connector->panel.fitting_mode == val) {
  4057. /* the eDP scaling property is not changed */
  4058. return 0;
  4059. }
  4060. intel_connector->panel.fitting_mode = val;
  4061. goto done;
  4062. }
  4063. return -EINVAL;
  4064. done:
  4065. if (intel_encoder->base.crtc)
  4066. intel_crtc_restore_mode(intel_encoder->base.crtc);
  4067. return 0;
  4068. }
  4069. static int
  4070. intel_dp_connector_register(struct drm_connector *connector)
  4071. {
  4072. struct intel_dp *intel_dp = intel_attached_dp(connector);
  4073. int ret;
  4074. ret = intel_connector_register(connector);
  4075. if (ret)
  4076. return ret;
  4077. i915_debugfs_connector_add(connector);
  4078. DRM_DEBUG_KMS("registering %s bus for %s\n",
  4079. intel_dp->aux.name, connector->kdev->kobj.name);
  4080. intel_dp->aux.dev = connector->kdev;
  4081. return drm_dp_aux_register(&intel_dp->aux);
  4082. }
  4083. static void
  4084. intel_dp_connector_unregister(struct drm_connector *connector)
  4085. {
  4086. drm_dp_aux_unregister(&intel_attached_dp(connector)->aux);
  4087. intel_connector_unregister(connector);
  4088. }
  4089. static void
  4090. intel_dp_connector_destroy(struct drm_connector *connector)
  4091. {
  4092. struct intel_connector *intel_connector = to_intel_connector(connector);
  4093. kfree(intel_connector->detect_edid);
  4094. if (!IS_ERR_OR_NULL(intel_connector->edid))
  4095. kfree(intel_connector->edid);
  4096. /* Can't call is_edp() since the encoder may have been destroyed
  4097. * already. */
  4098. if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
  4099. intel_panel_fini(&intel_connector->panel);
  4100. drm_connector_cleanup(connector);
  4101. kfree(connector);
  4102. }
  4103. void intel_dp_encoder_destroy(struct drm_encoder *encoder)
  4104. {
  4105. struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
  4106. struct intel_dp *intel_dp = &intel_dig_port->dp;
  4107. intel_dp_mst_encoder_cleanup(intel_dig_port);
  4108. if (is_edp(intel_dp)) {
  4109. cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
  4110. /*
  4111. * vdd might still be enabled do to the delayed vdd off.
  4112. * Make sure vdd is actually turned off here.
  4113. */
  4114. pps_lock(intel_dp);
  4115. edp_panel_vdd_off_sync(intel_dp);
  4116. pps_unlock(intel_dp);
  4117. if (intel_dp->edp_notifier.notifier_call) {
  4118. unregister_reboot_notifier(&intel_dp->edp_notifier);
  4119. intel_dp->edp_notifier.notifier_call = NULL;
  4120. }
  4121. }
  4122. intel_dp_aux_fini(intel_dp);
  4123. drm_encoder_cleanup(encoder);
  4124. kfree(intel_dig_port);
  4125. }
  4126. void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder)
  4127. {
  4128. struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
  4129. if (!is_edp(intel_dp))
  4130. return;
  4131. /*
  4132. * vdd might still be enabled do to the delayed vdd off.
  4133. * Make sure vdd is actually turned off here.
  4134. */
  4135. cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
  4136. pps_lock(intel_dp);
  4137. edp_panel_vdd_off_sync(intel_dp);
  4138. pps_unlock(intel_dp);
  4139. }
  4140. static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp)
  4141. {
  4142. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  4143. struct drm_device *dev = intel_dig_port->base.base.dev;
  4144. struct drm_i915_private *dev_priv = to_i915(dev);
  4145. lockdep_assert_held(&dev_priv->pps_mutex);
  4146. if (!edp_have_panel_vdd(intel_dp))
  4147. return;
  4148. /*
  4149. * The VDD bit needs a power domain reference, so if the bit is
  4150. * already enabled when we boot or resume, grab this reference and
  4151. * schedule a vdd off, so we don't hold on to the reference
  4152. * indefinitely.
  4153. */
  4154. DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n");
  4155. intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
  4156. edp_panel_vdd_schedule_off(intel_dp);
  4157. }
  4158. static enum pipe vlv_active_pipe(struct intel_dp *intel_dp)
  4159. {
  4160. struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
  4161. if ((intel_dp->DP & DP_PORT_EN) == 0)
  4162. return INVALID_PIPE;
  4163. if (IS_CHERRYVIEW(dev_priv))
  4164. return DP_PORT_TO_PIPE_CHV(intel_dp->DP);
  4165. else
  4166. return PORT_TO_PIPE(intel_dp->DP);
  4167. }
  4168. void intel_dp_encoder_reset(struct drm_encoder *encoder)
  4169. {
  4170. struct drm_i915_private *dev_priv = to_i915(encoder->dev);
  4171. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  4172. struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
  4173. if (!HAS_DDI(dev_priv))
  4174. intel_dp->DP = I915_READ(intel_dp->output_reg);
  4175. if (lspcon->active)
  4176. lspcon_resume(lspcon);
  4177. intel_dp->reset_link_params = true;
  4178. pps_lock(intel_dp);
  4179. if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
  4180. intel_dp->active_pipe = vlv_active_pipe(intel_dp);
  4181. if (is_edp(intel_dp)) {
  4182. /* Reinit the power sequencer, in case BIOS did something with it. */
  4183. intel_dp_pps_init(encoder->dev, intel_dp);
  4184. intel_edp_panel_vdd_sanitize(intel_dp);
  4185. }
  4186. pps_unlock(intel_dp);
  4187. }
  4188. static const struct drm_connector_funcs intel_dp_connector_funcs = {
  4189. .dpms = drm_atomic_helper_connector_dpms,
  4190. .force = intel_dp_force,
  4191. .fill_modes = drm_helper_probe_single_connector_modes,
  4192. .set_property = intel_dp_set_property,
  4193. .atomic_get_property = intel_connector_atomic_get_property,
  4194. .late_register = intel_dp_connector_register,
  4195. .early_unregister = intel_dp_connector_unregister,
  4196. .destroy = intel_dp_connector_destroy,
  4197. .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
  4198. .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
  4199. };
  4200. static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
  4201. .detect_ctx = intel_dp_detect,
  4202. .get_modes = intel_dp_get_modes,
  4203. .mode_valid = intel_dp_mode_valid,
  4204. };
  4205. static const struct drm_encoder_funcs intel_dp_enc_funcs = {
  4206. .reset = intel_dp_encoder_reset,
  4207. .destroy = intel_dp_encoder_destroy,
  4208. };
  4209. enum irqreturn
  4210. intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd)
  4211. {
  4212. struct intel_dp *intel_dp = &intel_dig_port->dp;
  4213. struct drm_device *dev = intel_dig_port->base.base.dev;
  4214. struct drm_i915_private *dev_priv = to_i915(dev);
  4215. enum irqreturn ret = IRQ_NONE;
  4216. if (intel_dig_port->base.type != INTEL_OUTPUT_EDP &&
  4217. intel_dig_port->base.type != INTEL_OUTPUT_HDMI)
  4218. intel_dig_port->base.type = INTEL_OUTPUT_DP;
  4219. if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) {
  4220. /*
  4221. * vdd off can generate a long pulse on eDP which
  4222. * would require vdd on to handle it, and thus we
  4223. * would end up in an endless cycle of
  4224. * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..."
  4225. */
  4226. DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n",
  4227. port_name(intel_dig_port->port));
  4228. return IRQ_HANDLED;
  4229. }
  4230. DRM_DEBUG_KMS("got hpd irq on port %c - %s\n",
  4231. port_name(intel_dig_port->port),
  4232. long_hpd ? "long" : "short");
  4233. if (long_hpd) {
  4234. intel_dp->reset_link_params = true;
  4235. intel_dp->detect_done = false;
  4236. return IRQ_NONE;
  4237. }
  4238. intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
  4239. if (intel_dp->is_mst) {
  4240. if (intel_dp_check_mst_status(intel_dp) == -EINVAL) {
  4241. /*
  4242. * If we were in MST mode, and device is not
  4243. * there, get out of MST mode
  4244. */
  4245. DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
  4246. intel_dp->is_mst, intel_dp->mst_mgr.mst_state);
  4247. intel_dp->is_mst = false;
  4248. drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
  4249. intel_dp->is_mst);
  4250. intel_dp->detect_done = false;
  4251. goto put_power;
  4252. }
  4253. }
  4254. if (!intel_dp->is_mst) {
  4255. if (!intel_dp_short_pulse(intel_dp)) {
  4256. intel_dp->detect_done = false;
  4257. goto put_power;
  4258. }
  4259. }
  4260. ret = IRQ_HANDLED;
  4261. put_power:
  4262. intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
  4263. return ret;
  4264. }
  4265. /* check the VBT to see whether the eDP is on another port */
  4266. bool intel_dp_is_edp(struct drm_i915_private *dev_priv, enum port port)
  4267. {
  4268. /*
  4269. * eDP not supported on g4x. so bail out early just
  4270. * for a bit extra safety in case the VBT is bonkers.
  4271. */
  4272. if (INTEL_GEN(dev_priv) < 5)
  4273. return false;
  4274. if (INTEL_GEN(dev_priv) < 9 && port == PORT_A)
  4275. return true;
  4276. return intel_bios_is_port_edp(dev_priv, port);
  4277. }
  4278. static void
  4279. intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
  4280. {
  4281. struct intel_connector *intel_connector = to_intel_connector(connector);
  4282. intel_attach_force_audio_property(connector);
  4283. intel_attach_broadcast_rgb_property(connector);
  4284. intel_dp->color_range_auto = true;
  4285. if (is_edp(intel_dp)) {
  4286. drm_mode_create_scaling_mode_property(connector->dev);
  4287. drm_object_attach_property(
  4288. &connector->base,
  4289. connector->dev->mode_config.scaling_mode_property,
  4290. DRM_MODE_SCALE_ASPECT);
  4291. intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
  4292. }
  4293. }
  4294. static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp)
  4295. {
  4296. intel_dp->panel_power_off_time = ktime_get_boottime();
  4297. intel_dp->last_power_on = jiffies;
  4298. intel_dp->last_backlight_off = jiffies;
  4299. }
  4300. static void
  4301. intel_pps_readout_hw_state(struct drm_i915_private *dev_priv,
  4302. struct intel_dp *intel_dp, struct edp_power_seq *seq)
  4303. {
  4304. u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0;
  4305. struct pps_registers regs;
  4306. intel_pps_get_registers(dev_priv, intel_dp, &regs);
  4307. /* Workaround: Need to write PP_CONTROL with the unlock key as
  4308. * the very first thing. */
  4309. pp_ctl = ironlake_get_pp_control(intel_dp);
  4310. pp_on = I915_READ(regs.pp_on);
  4311. pp_off = I915_READ(regs.pp_off);
  4312. if (!IS_GEN9_LP(dev_priv)) {
  4313. I915_WRITE(regs.pp_ctrl, pp_ctl);
  4314. pp_div = I915_READ(regs.pp_div);
  4315. }
  4316. /* Pull timing values out of registers */
  4317. seq->t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
  4318. PANEL_POWER_UP_DELAY_SHIFT;
  4319. seq->t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
  4320. PANEL_LIGHT_ON_DELAY_SHIFT;
  4321. seq->t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
  4322. PANEL_LIGHT_OFF_DELAY_SHIFT;
  4323. seq->t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
  4324. PANEL_POWER_DOWN_DELAY_SHIFT;
  4325. if (IS_GEN9_LP(dev_priv)) {
  4326. u16 tmp = (pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >>
  4327. BXT_POWER_CYCLE_DELAY_SHIFT;
  4328. if (tmp > 0)
  4329. seq->t11_t12 = (tmp - 1) * 1000;
  4330. else
  4331. seq->t11_t12 = 0;
  4332. } else {
  4333. seq->t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
  4334. PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
  4335. }
  4336. }
  4337. static void
  4338. intel_pps_dump_state(const char *state_name, const struct edp_power_seq *seq)
  4339. {
  4340. DRM_DEBUG_KMS("%s t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
  4341. state_name,
  4342. seq->t1_t3, seq->t8, seq->t9, seq->t10, seq->t11_t12);
  4343. }
  4344. static void
  4345. intel_pps_verify_state(struct drm_i915_private *dev_priv,
  4346. struct intel_dp *intel_dp)
  4347. {
  4348. struct edp_power_seq hw;
  4349. struct edp_power_seq *sw = &intel_dp->pps_delays;
  4350. intel_pps_readout_hw_state(dev_priv, intel_dp, &hw);
  4351. if (hw.t1_t3 != sw->t1_t3 || hw.t8 != sw->t8 || hw.t9 != sw->t9 ||
  4352. hw.t10 != sw->t10 || hw.t11_t12 != sw->t11_t12) {
  4353. DRM_ERROR("PPS state mismatch\n");
  4354. intel_pps_dump_state("sw", sw);
  4355. intel_pps_dump_state("hw", &hw);
  4356. }
  4357. }
  4358. static void
  4359. intel_dp_init_panel_power_sequencer(struct drm_device *dev,
  4360. struct intel_dp *intel_dp)
  4361. {
  4362. struct drm_i915_private *dev_priv = to_i915(dev);
  4363. struct edp_power_seq cur, vbt, spec,
  4364. *final = &intel_dp->pps_delays;
  4365. lockdep_assert_held(&dev_priv->pps_mutex);
  4366. /* already initialized? */
  4367. if (final->t11_t12 != 0)
  4368. return;
  4369. intel_pps_readout_hw_state(dev_priv, intel_dp, &cur);
  4370. intel_pps_dump_state("cur", &cur);
  4371. vbt = dev_priv->vbt.edp.pps;
  4372. /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
  4373. * our hw here, which are all in 100usec. */
  4374. spec.t1_t3 = 210 * 10;
  4375. spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
  4376. spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
  4377. spec.t10 = 500 * 10;
  4378. /* This one is special and actually in units of 100ms, but zero
  4379. * based in the hw (so we need to add 100 ms). But the sw vbt
  4380. * table multiplies it with 1000 to make it in units of 100usec,
  4381. * too. */
  4382. spec.t11_t12 = (510 + 100) * 10;
  4383. intel_pps_dump_state("vbt", &vbt);
  4384. /* Use the max of the register settings and vbt. If both are
  4385. * unset, fall back to the spec limits. */
  4386. #define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \
  4387. spec.field : \
  4388. max(cur.field, vbt.field))
  4389. assign_final(t1_t3);
  4390. assign_final(t8);
  4391. assign_final(t9);
  4392. assign_final(t10);
  4393. assign_final(t11_t12);
  4394. #undef assign_final
  4395. #define get_delay(field) (DIV_ROUND_UP(final->field, 10))
  4396. intel_dp->panel_power_up_delay = get_delay(t1_t3);
  4397. intel_dp->backlight_on_delay = get_delay(t8);
  4398. intel_dp->backlight_off_delay = get_delay(t9);
  4399. intel_dp->panel_power_down_delay = get_delay(t10);
  4400. intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
  4401. #undef get_delay
  4402. DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
  4403. intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
  4404. intel_dp->panel_power_cycle_delay);
  4405. DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
  4406. intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
  4407. /*
  4408. * We override the HW backlight delays to 1 because we do manual waits
  4409. * on them. For T8, even BSpec recommends doing it. For T9, if we
  4410. * don't do this, we'll end up waiting for the backlight off delay
  4411. * twice: once when we do the manual sleep, and once when we disable
  4412. * the panel and wait for the PP_STATUS bit to become zero.
  4413. */
  4414. final->t8 = 1;
  4415. final->t9 = 1;
  4416. }
  4417. static void
  4418. intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
  4419. struct intel_dp *intel_dp,
  4420. bool force_disable_vdd)
  4421. {
  4422. struct drm_i915_private *dev_priv = to_i915(dev);
  4423. u32 pp_on, pp_off, pp_div, port_sel = 0;
  4424. int div = dev_priv->rawclk_freq / 1000;
  4425. struct pps_registers regs;
  4426. enum port port = dp_to_dig_port(intel_dp)->port;
  4427. const struct edp_power_seq *seq = &intel_dp->pps_delays;
  4428. lockdep_assert_held(&dev_priv->pps_mutex);
  4429. intel_pps_get_registers(dev_priv, intel_dp, &regs);
  4430. /*
  4431. * On some VLV machines the BIOS can leave the VDD
  4432. * enabled even on power seqeuencers which aren't
  4433. * hooked up to any port. This would mess up the
  4434. * power domain tracking the first time we pick
  4435. * one of these power sequencers for use since
  4436. * edp_panel_vdd_on() would notice that the VDD was
  4437. * already on and therefore wouldn't grab the power
  4438. * domain reference. Disable VDD first to avoid this.
  4439. * This also avoids spuriously turning the VDD on as
  4440. * soon as the new power seqeuencer gets initialized.
  4441. */
  4442. if (force_disable_vdd) {
  4443. u32 pp = ironlake_get_pp_control(intel_dp);
  4444. WARN(pp & PANEL_POWER_ON, "Panel power already on\n");
  4445. if (pp & EDP_FORCE_VDD)
  4446. DRM_DEBUG_KMS("VDD already on, disabling first\n");
  4447. pp &= ~EDP_FORCE_VDD;
  4448. I915_WRITE(regs.pp_ctrl, pp);
  4449. }
  4450. pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
  4451. (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT);
  4452. pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
  4453. (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
  4454. /* Compute the divisor for the pp clock, simply match the Bspec
  4455. * formula. */
  4456. if (IS_GEN9_LP(dev_priv)) {
  4457. pp_div = I915_READ(regs.pp_ctrl);
  4458. pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK;
  4459. pp_div |= (DIV_ROUND_UP((seq->t11_t12 + 1), 1000)
  4460. << BXT_POWER_CYCLE_DELAY_SHIFT);
  4461. } else {
  4462. pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
  4463. pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
  4464. << PANEL_POWER_CYCLE_DELAY_SHIFT);
  4465. }
  4466. /* Haswell doesn't have any port selection bits for the panel
  4467. * power sequencer any more. */
  4468. if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
  4469. port_sel = PANEL_PORT_SELECT_VLV(port);
  4470. } else if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
  4471. if (port == PORT_A)
  4472. port_sel = PANEL_PORT_SELECT_DPA;
  4473. else
  4474. port_sel = PANEL_PORT_SELECT_DPD;
  4475. }
  4476. pp_on |= port_sel;
  4477. I915_WRITE(regs.pp_on, pp_on);
  4478. I915_WRITE(regs.pp_off, pp_off);
  4479. if (IS_GEN9_LP(dev_priv))
  4480. I915_WRITE(regs.pp_ctrl, pp_div);
  4481. else
  4482. I915_WRITE(regs.pp_div, pp_div);
  4483. DRM_DEBUG_KMS("panel power sequencer register settings: PP_ON %#x, PP_OFF %#x, PP_DIV %#x\n",
  4484. I915_READ(regs.pp_on),
  4485. I915_READ(regs.pp_off),
  4486. IS_GEN9_LP(dev_priv) ?
  4487. (I915_READ(regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK) :
  4488. I915_READ(regs.pp_div));
  4489. }
  4490. static void intel_dp_pps_init(struct drm_device *dev,
  4491. struct intel_dp *intel_dp)
  4492. {
  4493. struct drm_i915_private *dev_priv = to_i915(dev);
  4494. if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
  4495. vlv_initial_power_sequencer_setup(intel_dp);
  4496. } else {
  4497. intel_dp_init_panel_power_sequencer(dev, intel_dp);
  4498. intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
  4499. }
  4500. }
  4501. /**
  4502. * intel_dp_set_drrs_state - program registers for RR switch to take effect
  4503. * @dev_priv: i915 device
  4504. * @crtc_state: a pointer to the active intel_crtc_state
  4505. * @refresh_rate: RR to be programmed
  4506. *
  4507. * This function gets called when refresh rate (RR) has to be changed from
  4508. * one frequency to another. Switches can be between high and low RR
  4509. * supported by the panel or to any other RR based on media playback (in
  4510. * this case, RR value needs to be passed from user space).
  4511. *
  4512. * The caller of this function needs to take a lock on dev_priv->drrs.
  4513. */
  4514. static void intel_dp_set_drrs_state(struct drm_i915_private *dev_priv,
  4515. struct intel_crtc_state *crtc_state,
  4516. int refresh_rate)
  4517. {
  4518. struct intel_encoder *encoder;
  4519. struct intel_digital_port *dig_port = NULL;
  4520. struct intel_dp *intel_dp = dev_priv->drrs.dp;
  4521. struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
  4522. enum drrs_refresh_rate_type index = DRRS_HIGH_RR;
  4523. if (refresh_rate <= 0) {
  4524. DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n");
  4525. return;
  4526. }
  4527. if (intel_dp == NULL) {
  4528. DRM_DEBUG_KMS("DRRS not supported.\n");
  4529. return;
  4530. }
  4531. /*
  4532. * FIXME: This needs proper synchronization with psr state for some
  4533. * platforms that cannot have PSR and DRRS enabled at the same time.
  4534. */
  4535. dig_port = dp_to_dig_port(intel_dp);
  4536. encoder = &dig_port->base;
  4537. intel_crtc = to_intel_crtc(encoder->base.crtc);
  4538. if (!intel_crtc) {
  4539. DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n");
  4540. return;
  4541. }
  4542. if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) {
  4543. DRM_DEBUG_KMS("Only Seamless DRRS supported.\n");
  4544. return;
  4545. }
  4546. if (intel_dp->attached_connector->panel.downclock_mode->vrefresh ==
  4547. refresh_rate)
  4548. index = DRRS_LOW_RR;
  4549. if (index == dev_priv->drrs.refresh_rate_type) {
  4550. DRM_DEBUG_KMS(
  4551. "DRRS requested for previously set RR...ignoring\n");
  4552. return;
  4553. }
  4554. if (!crtc_state->base.active) {
  4555. DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n");
  4556. return;
  4557. }
  4558. if (INTEL_GEN(dev_priv) >= 8 && !IS_CHERRYVIEW(dev_priv)) {
  4559. switch (index) {
  4560. case DRRS_HIGH_RR:
  4561. intel_dp_set_m_n(intel_crtc, M1_N1);
  4562. break;
  4563. case DRRS_LOW_RR:
  4564. intel_dp_set_m_n(intel_crtc, M2_N2);
  4565. break;
  4566. case DRRS_MAX_RR:
  4567. default:
  4568. DRM_ERROR("Unsupported refreshrate type\n");
  4569. }
  4570. } else if (INTEL_GEN(dev_priv) > 6) {
  4571. i915_reg_t reg = PIPECONF(crtc_state->cpu_transcoder);
  4572. u32 val;
  4573. val = I915_READ(reg);
  4574. if (index > DRRS_HIGH_RR) {
  4575. if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
  4576. val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV;
  4577. else
  4578. val |= PIPECONF_EDP_RR_MODE_SWITCH;
  4579. } else {
  4580. if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
  4581. val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV;
  4582. else
  4583. val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
  4584. }
  4585. I915_WRITE(reg, val);
  4586. }
  4587. dev_priv->drrs.refresh_rate_type = index;
  4588. DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
  4589. }
  4590. /**
  4591. * intel_edp_drrs_enable - init drrs struct if supported
  4592. * @intel_dp: DP struct
  4593. * @crtc_state: A pointer to the active crtc state.
  4594. *
  4595. * Initializes frontbuffer_bits and drrs.dp
  4596. */
  4597. void intel_edp_drrs_enable(struct intel_dp *intel_dp,
  4598. struct intel_crtc_state *crtc_state)
  4599. {
  4600. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  4601. struct drm_i915_private *dev_priv = to_i915(dev);
  4602. if (!crtc_state->has_drrs) {
  4603. DRM_DEBUG_KMS("Panel doesn't support DRRS\n");
  4604. return;
  4605. }
  4606. mutex_lock(&dev_priv->drrs.mutex);
  4607. if (WARN_ON(dev_priv->drrs.dp)) {
  4608. DRM_ERROR("DRRS already enabled\n");
  4609. goto unlock;
  4610. }
  4611. dev_priv->drrs.busy_frontbuffer_bits = 0;
  4612. dev_priv->drrs.dp = intel_dp;
  4613. unlock:
  4614. mutex_unlock(&dev_priv->drrs.mutex);
  4615. }
  4616. /**
  4617. * intel_edp_drrs_disable - Disable DRRS
  4618. * @intel_dp: DP struct
  4619. * @old_crtc_state: Pointer to old crtc_state.
  4620. *
  4621. */
  4622. void intel_edp_drrs_disable(struct intel_dp *intel_dp,
  4623. struct intel_crtc_state *old_crtc_state)
  4624. {
  4625. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  4626. struct drm_i915_private *dev_priv = to_i915(dev);
  4627. if (!old_crtc_state->has_drrs)
  4628. return;
  4629. mutex_lock(&dev_priv->drrs.mutex);
  4630. if (!dev_priv->drrs.dp) {
  4631. mutex_unlock(&dev_priv->drrs.mutex);
  4632. return;
  4633. }
  4634. if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
  4635. intel_dp_set_drrs_state(dev_priv, old_crtc_state,
  4636. intel_dp->attached_connector->panel.fixed_mode->vrefresh);
  4637. dev_priv->drrs.dp = NULL;
  4638. mutex_unlock(&dev_priv->drrs.mutex);
  4639. cancel_delayed_work_sync(&dev_priv->drrs.work);
  4640. }
  4641. static void intel_edp_drrs_downclock_work(struct work_struct *work)
  4642. {
  4643. struct drm_i915_private *dev_priv =
  4644. container_of(work, typeof(*dev_priv), drrs.work.work);
  4645. struct intel_dp *intel_dp;
  4646. mutex_lock(&dev_priv->drrs.mutex);
  4647. intel_dp = dev_priv->drrs.dp;
  4648. if (!intel_dp)
  4649. goto unlock;
  4650. /*
  4651. * The delayed work can race with an invalidate hence we need to
  4652. * recheck.
  4653. */
  4654. if (dev_priv->drrs.busy_frontbuffer_bits)
  4655. goto unlock;
  4656. if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR) {
  4657. struct drm_crtc *crtc = dp_to_dig_port(intel_dp)->base.base.crtc;
  4658. intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
  4659. intel_dp->attached_connector->panel.downclock_mode->vrefresh);
  4660. }
  4661. unlock:
  4662. mutex_unlock(&dev_priv->drrs.mutex);
  4663. }
  4664. /**
  4665. * intel_edp_drrs_invalidate - Disable Idleness DRRS
  4666. * @dev_priv: i915 device
  4667. * @frontbuffer_bits: frontbuffer plane tracking bits
  4668. *
  4669. * This function gets called everytime rendering on the given planes start.
  4670. * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR).
  4671. *
  4672. * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
  4673. */
  4674. void intel_edp_drrs_invalidate(struct drm_i915_private *dev_priv,
  4675. unsigned int frontbuffer_bits)
  4676. {
  4677. struct drm_crtc *crtc;
  4678. enum pipe pipe;
  4679. if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
  4680. return;
  4681. cancel_delayed_work(&dev_priv->drrs.work);
  4682. mutex_lock(&dev_priv->drrs.mutex);
  4683. if (!dev_priv->drrs.dp) {
  4684. mutex_unlock(&dev_priv->drrs.mutex);
  4685. return;
  4686. }
  4687. crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
  4688. pipe = to_intel_crtc(crtc)->pipe;
  4689. frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
  4690. dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits;
  4691. /* invalidate means busy screen hence upclock */
  4692. if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
  4693. intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
  4694. dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
  4695. mutex_unlock(&dev_priv->drrs.mutex);
  4696. }
  4697. /**
  4698. * intel_edp_drrs_flush - Restart Idleness DRRS
  4699. * @dev_priv: i915 device
  4700. * @frontbuffer_bits: frontbuffer plane tracking bits
  4701. *
  4702. * This function gets called every time rendering on the given planes has
  4703. * completed or flip on a crtc is completed. So DRRS should be upclocked
  4704. * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again,
  4705. * if no other planes are dirty.
  4706. *
  4707. * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
  4708. */
  4709. void intel_edp_drrs_flush(struct drm_i915_private *dev_priv,
  4710. unsigned int frontbuffer_bits)
  4711. {
  4712. struct drm_crtc *crtc;
  4713. enum pipe pipe;
  4714. if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
  4715. return;
  4716. cancel_delayed_work(&dev_priv->drrs.work);
  4717. mutex_lock(&dev_priv->drrs.mutex);
  4718. if (!dev_priv->drrs.dp) {
  4719. mutex_unlock(&dev_priv->drrs.mutex);
  4720. return;
  4721. }
  4722. crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
  4723. pipe = to_intel_crtc(crtc)->pipe;
  4724. frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
  4725. dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits;
  4726. /* flush means busy screen hence upclock */
  4727. if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
  4728. intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
  4729. dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
  4730. /*
  4731. * flush also means no more activity hence schedule downclock, if all
  4732. * other fbs are quiescent too
  4733. */
  4734. if (!dev_priv->drrs.busy_frontbuffer_bits)
  4735. schedule_delayed_work(&dev_priv->drrs.work,
  4736. msecs_to_jiffies(1000));
  4737. mutex_unlock(&dev_priv->drrs.mutex);
  4738. }
  4739. /**
  4740. * DOC: Display Refresh Rate Switching (DRRS)
  4741. *
  4742. * Display Refresh Rate Switching (DRRS) is a power conservation feature
  4743. * which enables swtching between low and high refresh rates,
  4744. * dynamically, based on the usage scenario. This feature is applicable
  4745. * for internal panels.
  4746. *
  4747. * Indication that the panel supports DRRS is given by the panel EDID, which
  4748. * would list multiple refresh rates for one resolution.
  4749. *
  4750. * DRRS is of 2 types - static and seamless.
  4751. * Static DRRS involves changing refresh rate (RR) by doing a full modeset
  4752. * (may appear as a blink on screen) and is used in dock-undock scenario.
  4753. * Seamless DRRS involves changing RR without any visual effect to the user
  4754. * and can be used during normal system usage. This is done by programming
  4755. * certain registers.
  4756. *
  4757. * Support for static/seamless DRRS may be indicated in the VBT based on
  4758. * inputs from the panel spec.
  4759. *
  4760. * DRRS saves power by switching to low RR based on usage scenarios.
  4761. *
  4762. * The implementation is based on frontbuffer tracking implementation. When
  4763. * there is a disturbance on the screen triggered by user activity or a periodic
  4764. * system activity, DRRS is disabled (RR is changed to high RR). When there is
  4765. * no movement on screen, after a timeout of 1 second, a switch to low RR is
  4766. * made.
  4767. *
  4768. * For integration with frontbuffer tracking code, intel_edp_drrs_invalidate()
  4769. * and intel_edp_drrs_flush() are called.
  4770. *
  4771. * DRRS can be further extended to support other internal panels and also
  4772. * the scenario of video playback wherein RR is set based on the rate
  4773. * requested by userspace.
  4774. */
  4775. /**
  4776. * intel_dp_drrs_init - Init basic DRRS work and mutex.
  4777. * @intel_connector: eDP connector
  4778. * @fixed_mode: preferred mode of panel
  4779. *
  4780. * This function is called only once at driver load to initialize basic
  4781. * DRRS stuff.
  4782. *
  4783. * Returns:
  4784. * Downclock mode if panel supports it, else return NULL.
  4785. * DRRS support is determined by the presence of downclock mode (apart
  4786. * from VBT setting).
  4787. */
  4788. static struct drm_display_mode *
  4789. intel_dp_drrs_init(struct intel_connector *intel_connector,
  4790. struct drm_display_mode *fixed_mode)
  4791. {
  4792. struct drm_connector *connector = &intel_connector->base;
  4793. struct drm_device *dev = connector->dev;
  4794. struct drm_i915_private *dev_priv = to_i915(dev);
  4795. struct drm_display_mode *downclock_mode = NULL;
  4796. INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work);
  4797. mutex_init(&dev_priv->drrs.mutex);
  4798. if (INTEL_GEN(dev_priv) <= 6) {
  4799. DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n");
  4800. return NULL;
  4801. }
  4802. if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) {
  4803. DRM_DEBUG_KMS("VBT doesn't support DRRS\n");
  4804. return NULL;
  4805. }
  4806. downclock_mode = intel_find_panel_downclock
  4807. (dev_priv, fixed_mode, connector);
  4808. if (!downclock_mode) {
  4809. DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n");
  4810. return NULL;
  4811. }
  4812. dev_priv->drrs.type = dev_priv->vbt.drrs_type;
  4813. dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR;
  4814. DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n");
  4815. return downclock_mode;
  4816. }
  4817. static bool intel_edp_init_connector(struct intel_dp *intel_dp,
  4818. struct intel_connector *intel_connector)
  4819. {
  4820. struct drm_connector *connector = &intel_connector->base;
  4821. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  4822. struct intel_encoder *intel_encoder = &intel_dig_port->base;
  4823. struct drm_device *dev = intel_encoder->base.dev;
  4824. struct drm_i915_private *dev_priv = to_i915(dev);
  4825. struct drm_display_mode *fixed_mode = NULL;
  4826. struct drm_display_mode *downclock_mode = NULL;
  4827. bool has_dpcd;
  4828. struct drm_display_mode *scan;
  4829. struct edid *edid;
  4830. enum pipe pipe = INVALID_PIPE;
  4831. if (!is_edp(intel_dp))
  4832. return true;
  4833. /*
  4834. * On IBX/CPT we may get here with LVDS already registered. Since the
  4835. * driver uses the only internal power sequencer available for both
  4836. * eDP and LVDS bail out early in this case to prevent interfering
  4837. * with an already powered-on LVDS power sequencer.
  4838. */
  4839. if (intel_get_lvds_encoder(dev)) {
  4840. WARN_ON(!(HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)));
  4841. DRM_INFO("LVDS was detected, not registering eDP\n");
  4842. return false;
  4843. }
  4844. pps_lock(intel_dp);
  4845. intel_dp_init_panel_power_timestamps(intel_dp);
  4846. intel_dp_pps_init(dev, intel_dp);
  4847. intel_edp_panel_vdd_sanitize(intel_dp);
  4848. pps_unlock(intel_dp);
  4849. /* Cache DPCD and EDID for edp. */
  4850. has_dpcd = intel_edp_init_dpcd(intel_dp);
  4851. if (!has_dpcd) {
  4852. /* if this fails, presume the device is a ghost */
  4853. DRM_INFO("failed to retrieve link info, disabling eDP\n");
  4854. goto out_vdd_off;
  4855. }
  4856. mutex_lock(&dev->mode_config.mutex);
  4857. edid = drm_get_edid(connector, &intel_dp->aux.ddc);
  4858. if (edid) {
  4859. if (drm_add_edid_modes(connector, edid)) {
  4860. drm_mode_connector_update_edid_property(connector,
  4861. edid);
  4862. drm_edid_to_eld(connector, edid);
  4863. } else {
  4864. kfree(edid);
  4865. edid = ERR_PTR(-EINVAL);
  4866. }
  4867. } else {
  4868. edid = ERR_PTR(-ENOENT);
  4869. }
  4870. intel_connector->edid = edid;
  4871. /* prefer fixed mode from EDID if available */
  4872. list_for_each_entry(scan, &connector->probed_modes, head) {
  4873. if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
  4874. fixed_mode = drm_mode_duplicate(dev, scan);
  4875. downclock_mode = intel_dp_drrs_init(
  4876. intel_connector, fixed_mode);
  4877. break;
  4878. }
  4879. }
  4880. /* fallback to VBT if available for eDP */
  4881. if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
  4882. fixed_mode = drm_mode_duplicate(dev,
  4883. dev_priv->vbt.lfp_lvds_vbt_mode);
  4884. if (fixed_mode) {
  4885. fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
  4886. connector->display_info.width_mm = fixed_mode->width_mm;
  4887. connector->display_info.height_mm = fixed_mode->height_mm;
  4888. }
  4889. }
  4890. mutex_unlock(&dev->mode_config.mutex);
  4891. if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
  4892. intel_dp->edp_notifier.notifier_call = edp_notify_handler;
  4893. register_reboot_notifier(&intel_dp->edp_notifier);
  4894. /*
  4895. * Figure out the current pipe for the initial backlight setup.
  4896. * If the current pipe isn't valid, try the PPS pipe, and if that
  4897. * fails just assume pipe A.
  4898. */
  4899. pipe = vlv_active_pipe(intel_dp);
  4900. if (pipe != PIPE_A && pipe != PIPE_B)
  4901. pipe = intel_dp->pps_pipe;
  4902. if (pipe != PIPE_A && pipe != PIPE_B)
  4903. pipe = PIPE_A;
  4904. DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n",
  4905. pipe_name(pipe));
  4906. }
  4907. intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode);
  4908. intel_connector->panel.backlight.power = intel_edp_backlight_power;
  4909. intel_panel_setup_backlight(connector, pipe);
  4910. return true;
  4911. out_vdd_off:
  4912. cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
  4913. /*
  4914. * vdd might still be enabled do to the delayed vdd off.
  4915. * Make sure vdd is actually turned off here.
  4916. */
  4917. pps_lock(intel_dp);
  4918. edp_panel_vdd_off_sync(intel_dp);
  4919. pps_unlock(intel_dp);
  4920. return false;
  4921. }
  4922. /* Set up the hotplug pin and aux power domain. */
  4923. static void
  4924. intel_dp_init_connector_port_info(struct intel_digital_port *intel_dig_port)
  4925. {
  4926. struct intel_encoder *encoder = &intel_dig_port->base;
  4927. struct intel_dp *intel_dp = &intel_dig_port->dp;
  4928. switch (intel_dig_port->port) {
  4929. case PORT_A:
  4930. encoder->hpd_pin = HPD_PORT_A;
  4931. intel_dp->aux_power_domain = POWER_DOMAIN_AUX_A;
  4932. break;
  4933. case PORT_B:
  4934. encoder->hpd_pin = HPD_PORT_B;
  4935. intel_dp->aux_power_domain = POWER_DOMAIN_AUX_B;
  4936. break;
  4937. case PORT_C:
  4938. encoder->hpd_pin = HPD_PORT_C;
  4939. intel_dp->aux_power_domain = POWER_DOMAIN_AUX_C;
  4940. break;
  4941. case PORT_D:
  4942. encoder->hpd_pin = HPD_PORT_D;
  4943. intel_dp->aux_power_domain = POWER_DOMAIN_AUX_D;
  4944. break;
  4945. case PORT_E:
  4946. encoder->hpd_pin = HPD_PORT_E;
  4947. /* FIXME: Check VBT for actual wiring of PORT E */
  4948. intel_dp->aux_power_domain = POWER_DOMAIN_AUX_D;
  4949. break;
  4950. default:
  4951. MISSING_CASE(intel_dig_port->port);
  4952. }
  4953. }
  4954. static void intel_dp_modeset_retry_work_fn(struct work_struct *work)
  4955. {
  4956. struct intel_connector *intel_connector;
  4957. struct drm_connector *connector;
  4958. intel_connector = container_of(work, typeof(*intel_connector),
  4959. modeset_retry_work);
  4960. connector = &intel_connector->base;
  4961. DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", connector->base.id,
  4962. connector->name);
  4963. /* Grab the locks before changing connector property*/
  4964. mutex_lock(&connector->dev->mode_config.mutex);
  4965. /* Set connector link status to BAD and send a Uevent to notify
  4966. * userspace to do a modeset.
  4967. */
  4968. drm_mode_connector_set_link_status_property(connector,
  4969. DRM_MODE_LINK_STATUS_BAD);
  4970. mutex_unlock(&connector->dev->mode_config.mutex);
  4971. /* Send Hotplug uevent so userspace can reprobe */
  4972. drm_kms_helper_hotplug_event(connector->dev);
  4973. }
  4974. bool
  4975. intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
  4976. struct intel_connector *intel_connector)
  4977. {
  4978. struct drm_connector *connector = &intel_connector->base;
  4979. struct intel_dp *intel_dp = &intel_dig_port->dp;
  4980. struct intel_encoder *intel_encoder = &intel_dig_port->base;
  4981. struct drm_device *dev = intel_encoder->base.dev;
  4982. struct drm_i915_private *dev_priv = to_i915(dev);
  4983. enum port port = intel_dig_port->port;
  4984. int type;
  4985. /* Initialize the work for modeset in case of link train failure */
  4986. INIT_WORK(&intel_connector->modeset_retry_work,
  4987. intel_dp_modeset_retry_work_fn);
  4988. if (WARN(intel_dig_port->max_lanes < 1,
  4989. "Not enough lanes (%d) for DP on port %c\n",
  4990. intel_dig_port->max_lanes, port_name(port)))
  4991. return false;
  4992. intel_dp_set_source_rates(intel_dp);
  4993. intel_dp->reset_link_params = true;
  4994. intel_dp->pps_pipe = INVALID_PIPE;
  4995. intel_dp->active_pipe = INVALID_PIPE;
  4996. /* intel_dp vfuncs */
  4997. if (INTEL_GEN(dev_priv) >= 9)
  4998. intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider;
  4999. else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
  5000. intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
  5001. else if (HAS_PCH_SPLIT(dev_priv))
  5002. intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
  5003. else
  5004. intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider;
  5005. if (INTEL_GEN(dev_priv) >= 9)
  5006. intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl;
  5007. else
  5008. intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl;
  5009. if (HAS_DDI(dev_priv))
  5010. intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain;
  5011. /* Preserve the current hw state. */
  5012. intel_dp->DP = I915_READ(intel_dp->output_reg);
  5013. intel_dp->attached_connector = intel_connector;
  5014. if (intel_dp_is_edp(dev_priv, port))
  5015. type = DRM_MODE_CONNECTOR_eDP;
  5016. else
  5017. type = DRM_MODE_CONNECTOR_DisplayPort;
  5018. if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
  5019. intel_dp->active_pipe = vlv_active_pipe(intel_dp);
  5020. /*
  5021. * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
  5022. * for DP the encoder type can be set by the caller to
  5023. * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
  5024. */
  5025. if (type == DRM_MODE_CONNECTOR_eDP)
  5026. intel_encoder->type = INTEL_OUTPUT_EDP;
  5027. /* eDP only on port B and/or C on vlv/chv */
  5028. if (WARN_ON((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
  5029. is_edp(intel_dp) && port != PORT_B && port != PORT_C))
  5030. return false;
  5031. DRM_DEBUG_KMS("Adding %s connector on port %c\n",
  5032. type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
  5033. port_name(port));
  5034. drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
  5035. drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
  5036. connector->interlace_allowed = true;
  5037. connector->doublescan_allowed = 0;
  5038. intel_dp_init_connector_port_info(intel_dig_port);
  5039. intel_dp_aux_init(intel_dp);
  5040. INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
  5041. edp_panel_vdd_work);
  5042. intel_connector_attach_encoder(intel_connector, intel_encoder);
  5043. if (HAS_DDI(dev_priv))
  5044. intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
  5045. else
  5046. intel_connector->get_hw_state = intel_connector_get_hw_state;
  5047. /* init MST on ports that can support it */
  5048. if (HAS_DP_MST(dev_priv) && !is_edp(intel_dp) &&
  5049. (port == PORT_B || port == PORT_C || port == PORT_D))
  5050. intel_dp_mst_encoder_init(intel_dig_port,
  5051. intel_connector->base.base.id);
  5052. if (!intel_edp_init_connector(intel_dp, intel_connector)) {
  5053. intel_dp_aux_fini(intel_dp);
  5054. intel_dp_mst_encoder_cleanup(intel_dig_port);
  5055. goto fail;
  5056. }
  5057. intel_dp_add_properties(intel_dp, connector);
  5058. /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
  5059. * 0xd. Failure to do so will result in spurious interrupts being
  5060. * generated on the port when a cable is not attached.
  5061. */
  5062. if (IS_G4X(dev_priv) && !IS_GM45(dev_priv)) {
  5063. u32 temp = I915_READ(PEG_BAND_GAP_DATA);
  5064. I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
  5065. }
  5066. return true;
  5067. fail:
  5068. drm_connector_cleanup(connector);
  5069. return false;
  5070. }
  5071. bool intel_dp_init(struct drm_i915_private *dev_priv,
  5072. i915_reg_t output_reg,
  5073. enum port port)
  5074. {
  5075. struct intel_digital_port *intel_dig_port;
  5076. struct intel_encoder *intel_encoder;
  5077. struct drm_encoder *encoder;
  5078. struct intel_connector *intel_connector;
  5079. intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
  5080. if (!intel_dig_port)
  5081. return false;
  5082. intel_connector = intel_connector_alloc();
  5083. if (!intel_connector)
  5084. goto err_connector_alloc;
  5085. intel_encoder = &intel_dig_port->base;
  5086. encoder = &intel_encoder->base;
  5087. if (drm_encoder_init(&dev_priv->drm, &intel_encoder->base,
  5088. &intel_dp_enc_funcs, DRM_MODE_ENCODER_TMDS,
  5089. "DP %c", port_name(port)))
  5090. goto err_encoder_init;
  5091. intel_encoder->compute_config = intel_dp_compute_config;
  5092. intel_encoder->disable = intel_disable_dp;
  5093. intel_encoder->get_hw_state = intel_dp_get_hw_state;
  5094. intel_encoder->get_config = intel_dp_get_config;
  5095. intel_encoder->suspend = intel_dp_encoder_suspend;
  5096. if (IS_CHERRYVIEW(dev_priv)) {
  5097. intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable;
  5098. intel_encoder->pre_enable = chv_pre_enable_dp;
  5099. intel_encoder->enable = vlv_enable_dp;
  5100. intel_encoder->post_disable = chv_post_disable_dp;
  5101. intel_encoder->post_pll_disable = chv_dp_post_pll_disable;
  5102. } else if (IS_VALLEYVIEW(dev_priv)) {
  5103. intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
  5104. intel_encoder->pre_enable = vlv_pre_enable_dp;
  5105. intel_encoder->enable = vlv_enable_dp;
  5106. intel_encoder->post_disable = vlv_post_disable_dp;
  5107. } else {
  5108. intel_encoder->pre_enable = g4x_pre_enable_dp;
  5109. intel_encoder->enable = g4x_enable_dp;
  5110. if (INTEL_GEN(dev_priv) >= 5)
  5111. intel_encoder->post_disable = ilk_post_disable_dp;
  5112. }
  5113. intel_dig_port->port = port;
  5114. intel_dig_port->dp.output_reg = output_reg;
  5115. intel_dig_port->max_lanes = 4;
  5116. intel_encoder->type = INTEL_OUTPUT_DP;
  5117. intel_encoder->power_domain = intel_port_to_power_domain(port);
  5118. if (IS_CHERRYVIEW(dev_priv)) {
  5119. if (port == PORT_D)
  5120. intel_encoder->crtc_mask = 1 << 2;
  5121. else
  5122. intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
  5123. } else {
  5124. intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
  5125. }
  5126. intel_encoder->cloneable = 0;
  5127. intel_encoder->port = port;
  5128. intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
  5129. dev_priv->hotplug.irq_port[port] = intel_dig_port;
  5130. if (!intel_dp_init_connector(intel_dig_port, intel_connector))
  5131. goto err_init_connector;
  5132. return true;
  5133. err_init_connector:
  5134. drm_encoder_cleanup(encoder);
  5135. err_encoder_init:
  5136. kfree(intel_connector);
  5137. err_connector_alloc:
  5138. kfree(intel_dig_port);
  5139. return false;
  5140. }
  5141. void intel_dp_mst_suspend(struct drm_device *dev)
  5142. {
  5143. struct drm_i915_private *dev_priv = to_i915(dev);
  5144. int i;
  5145. /* disable MST */
  5146. for (i = 0; i < I915_MAX_PORTS; i++) {
  5147. struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
  5148. if (!intel_dig_port || !intel_dig_port->dp.can_mst)
  5149. continue;
  5150. if (intel_dig_port->dp.is_mst)
  5151. drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr);
  5152. }
  5153. }
  5154. void intel_dp_mst_resume(struct drm_device *dev)
  5155. {
  5156. struct drm_i915_private *dev_priv = to_i915(dev);
  5157. int i;
  5158. for (i = 0; i < I915_MAX_PORTS; i++) {
  5159. struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
  5160. int ret;
  5161. if (!intel_dig_port || !intel_dig_port->dp.can_mst)
  5162. continue;
  5163. ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr);
  5164. if (ret)
  5165. intel_dp_check_mst_status(&intel_dig_port->dp);
  5166. }
  5167. }