intel_dp.c 166 KB

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