intel_dp.c 173 KB

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