intel_dp.c 178 KB

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