intel_dp.c 160 KB

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