intel_dp.c 161 KB

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