intel_dp.c 169 KB

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