intel_dp.c 173 KB

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