intel_dp.c 172 KB

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