intel_dp.c 172 KB

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