intel_dp.c 169 KB

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