intel_dp.c 174 KB

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