intel_dp.c 174 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267
  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. if (old_crtc_state->has_audio)
  2203. intel_audio_codec_disable(encoder);
  2204. /* Make sure the panel is off before trying to change the mode. But also
  2205. * ensure that we have vdd while we switch off the panel. */
  2206. intel_edp_panel_vdd_on(intel_dp);
  2207. intel_edp_backlight_off(old_conn_state);
  2208. intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
  2209. intel_edp_panel_off(intel_dp);
  2210. }
  2211. static void g4x_disable_dp(struct intel_encoder *encoder,
  2212. const struct intel_crtc_state *old_crtc_state,
  2213. const struct drm_connector_state *old_conn_state)
  2214. {
  2215. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  2216. intel_disable_dp(encoder, old_crtc_state, old_conn_state);
  2217. /* disable the port before the pipe on g4x */
  2218. intel_dp_link_down(intel_dp);
  2219. }
  2220. static void ilk_disable_dp(struct intel_encoder *encoder,
  2221. const struct intel_crtc_state *old_crtc_state,
  2222. const struct drm_connector_state *old_conn_state)
  2223. {
  2224. intel_disable_dp(encoder, old_crtc_state, old_conn_state);
  2225. }
  2226. static void vlv_disable_dp(struct intel_encoder *encoder,
  2227. const struct intel_crtc_state *old_crtc_state,
  2228. const struct drm_connector_state *old_conn_state)
  2229. {
  2230. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  2231. intel_psr_disable(intel_dp, old_crtc_state);
  2232. intel_disable_dp(encoder, old_crtc_state, old_conn_state);
  2233. }
  2234. static void ilk_post_disable_dp(struct intel_encoder *encoder,
  2235. const struct intel_crtc_state *old_crtc_state,
  2236. const struct drm_connector_state *old_conn_state)
  2237. {
  2238. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  2239. enum port port = dp_to_dig_port(intel_dp)->port;
  2240. intel_dp_link_down(intel_dp);
  2241. /* Only ilk+ has port A */
  2242. if (port == PORT_A)
  2243. ironlake_edp_pll_off(intel_dp);
  2244. }
  2245. static void vlv_post_disable_dp(struct intel_encoder *encoder,
  2246. const struct intel_crtc_state *old_crtc_state,
  2247. const struct drm_connector_state *old_conn_state)
  2248. {
  2249. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  2250. intel_dp_link_down(intel_dp);
  2251. }
  2252. static void chv_post_disable_dp(struct intel_encoder *encoder,
  2253. const struct intel_crtc_state *old_crtc_state,
  2254. const struct drm_connector_state *old_conn_state)
  2255. {
  2256. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  2257. struct drm_device *dev = encoder->base.dev;
  2258. struct drm_i915_private *dev_priv = to_i915(dev);
  2259. intel_dp_link_down(intel_dp);
  2260. mutex_lock(&dev_priv->sb_lock);
  2261. /* Assert data lane reset */
  2262. chv_data_lane_soft_reset(encoder, true);
  2263. mutex_unlock(&dev_priv->sb_lock);
  2264. }
  2265. static void
  2266. _intel_dp_set_link_train(struct intel_dp *intel_dp,
  2267. uint32_t *DP,
  2268. uint8_t dp_train_pat)
  2269. {
  2270. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  2271. struct drm_device *dev = intel_dig_port->base.base.dev;
  2272. struct drm_i915_private *dev_priv = to_i915(dev);
  2273. enum port port = intel_dig_port->port;
  2274. if (dp_train_pat & DP_TRAINING_PATTERN_MASK)
  2275. DRM_DEBUG_KMS("Using DP training pattern TPS%d\n",
  2276. dp_train_pat & DP_TRAINING_PATTERN_MASK);
  2277. if (HAS_DDI(dev_priv)) {
  2278. uint32_t temp = I915_READ(DP_TP_CTL(port));
  2279. if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
  2280. temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
  2281. else
  2282. temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
  2283. temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
  2284. switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
  2285. case DP_TRAINING_PATTERN_DISABLE:
  2286. temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
  2287. break;
  2288. case DP_TRAINING_PATTERN_1:
  2289. temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
  2290. break;
  2291. case DP_TRAINING_PATTERN_2:
  2292. temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
  2293. break;
  2294. case DP_TRAINING_PATTERN_3:
  2295. temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
  2296. break;
  2297. }
  2298. I915_WRITE(DP_TP_CTL(port), temp);
  2299. } else if ((IS_GEN7(dev_priv) && port == PORT_A) ||
  2300. (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
  2301. *DP &= ~DP_LINK_TRAIN_MASK_CPT;
  2302. switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
  2303. case DP_TRAINING_PATTERN_DISABLE:
  2304. *DP |= DP_LINK_TRAIN_OFF_CPT;
  2305. break;
  2306. case DP_TRAINING_PATTERN_1:
  2307. *DP |= DP_LINK_TRAIN_PAT_1_CPT;
  2308. break;
  2309. case DP_TRAINING_PATTERN_2:
  2310. *DP |= DP_LINK_TRAIN_PAT_2_CPT;
  2311. break;
  2312. case DP_TRAINING_PATTERN_3:
  2313. DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
  2314. *DP |= DP_LINK_TRAIN_PAT_2_CPT;
  2315. break;
  2316. }
  2317. } else {
  2318. if (IS_CHERRYVIEW(dev_priv))
  2319. *DP &= ~DP_LINK_TRAIN_MASK_CHV;
  2320. else
  2321. *DP &= ~DP_LINK_TRAIN_MASK;
  2322. switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
  2323. case DP_TRAINING_PATTERN_DISABLE:
  2324. *DP |= DP_LINK_TRAIN_OFF;
  2325. break;
  2326. case DP_TRAINING_PATTERN_1:
  2327. *DP |= DP_LINK_TRAIN_PAT_1;
  2328. break;
  2329. case DP_TRAINING_PATTERN_2:
  2330. *DP |= DP_LINK_TRAIN_PAT_2;
  2331. break;
  2332. case DP_TRAINING_PATTERN_3:
  2333. if (IS_CHERRYVIEW(dev_priv)) {
  2334. *DP |= DP_LINK_TRAIN_PAT_3_CHV;
  2335. } else {
  2336. DRM_DEBUG_KMS("TPS3 not supported, using TPS2 instead\n");
  2337. *DP |= DP_LINK_TRAIN_PAT_2;
  2338. }
  2339. break;
  2340. }
  2341. }
  2342. }
  2343. static void intel_dp_enable_port(struct intel_dp *intel_dp,
  2344. const struct intel_crtc_state *old_crtc_state)
  2345. {
  2346. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  2347. struct drm_i915_private *dev_priv = to_i915(dev);
  2348. /* enable with pattern 1 (as per spec) */
  2349. intel_dp_program_link_training_pattern(intel_dp, DP_TRAINING_PATTERN_1);
  2350. /*
  2351. * Magic for VLV/CHV. We _must_ first set up the register
  2352. * without actually enabling the port, and then do another
  2353. * write to enable the port. Otherwise link training will
  2354. * fail when the power sequencer is freshly used for this port.
  2355. */
  2356. intel_dp->DP |= DP_PORT_EN;
  2357. if (old_crtc_state->has_audio)
  2358. intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
  2359. I915_WRITE(intel_dp->output_reg, intel_dp->DP);
  2360. POSTING_READ(intel_dp->output_reg);
  2361. }
  2362. static void intel_enable_dp(struct intel_encoder *encoder,
  2363. const struct intel_crtc_state *pipe_config,
  2364. const struct drm_connector_state *conn_state)
  2365. {
  2366. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  2367. struct drm_device *dev = encoder->base.dev;
  2368. struct drm_i915_private *dev_priv = to_i915(dev);
  2369. struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
  2370. uint32_t dp_reg = I915_READ(intel_dp->output_reg);
  2371. enum pipe pipe = crtc->pipe;
  2372. if (WARN_ON(dp_reg & DP_PORT_EN))
  2373. return;
  2374. pps_lock(intel_dp);
  2375. if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
  2376. vlv_init_panel_power_sequencer(intel_dp);
  2377. intel_dp_enable_port(intel_dp, pipe_config);
  2378. edp_panel_vdd_on(intel_dp);
  2379. edp_panel_on(intel_dp);
  2380. edp_panel_vdd_off(intel_dp, true);
  2381. pps_unlock(intel_dp);
  2382. if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
  2383. unsigned int lane_mask = 0x0;
  2384. if (IS_CHERRYVIEW(dev_priv))
  2385. lane_mask = intel_dp_unused_lane_mask(pipe_config->lane_count);
  2386. vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp),
  2387. lane_mask);
  2388. }
  2389. intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
  2390. intel_dp_start_link_train(intel_dp);
  2391. intel_dp_stop_link_train(intel_dp);
  2392. if (pipe_config->has_audio) {
  2393. DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
  2394. pipe_name(pipe));
  2395. intel_audio_codec_enable(encoder, pipe_config, conn_state);
  2396. }
  2397. }
  2398. static void g4x_enable_dp(struct intel_encoder *encoder,
  2399. const struct intel_crtc_state *pipe_config,
  2400. const struct drm_connector_state *conn_state)
  2401. {
  2402. intel_enable_dp(encoder, pipe_config, conn_state);
  2403. intel_edp_backlight_on(pipe_config, conn_state);
  2404. }
  2405. static void vlv_enable_dp(struct intel_encoder *encoder,
  2406. const struct intel_crtc_state *pipe_config,
  2407. const struct drm_connector_state *conn_state)
  2408. {
  2409. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  2410. intel_edp_backlight_on(pipe_config, conn_state);
  2411. intel_psr_enable(intel_dp, pipe_config);
  2412. }
  2413. static void g4x_pre_enable_dp(struct intel_encoder *encoder,
  2414. const struct intel_crtc_state *pipe_config,
  2415. const struct drm_connector_state *conn_state)
  2416. {
  2417. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  2418. enum port port = dp_to_dig_port(intel_dp)->port;
  2419. intel_dp_prepare(encoder, pipe_config);
  2420. /* Only ilk+ has port A */
  2421. if (port == PORT_A)
  2422. ironlake_edp_pll_on(intel_dp, pipe_config);
  2423. }
  2424. static void vlv_detach_power_sequencer(struct intel_dp *intel_dp)
  2425. {
  2426. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  2427. struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
  2428. enum pipe pipe = intel_dp->pps_pipe;
  2429. i915_reg_t pp_on_reg = PP_ON_DELAYS(pipe);
  2430. WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
  2431. if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
  2432. return;
  2433. edp_panel_vdd_off_sync(intel_dp);
  2434. /*
  2435. * VLV seems to get confused when multiple power seqeuencers
  2436. * have the same port selected (even if only one has power/vdd
  2437. * enabled). The failure manifests as vlv_wait_port_ready() failing
  2438. * CHV on the other hand doesn't seem to mind having the same port
  2439. * selected in multiple power seqeuencers, but let's clear the
  2440. * port select always when logically disconnecting a power sequencer
  2441. * from a port.
  2442. */
  2443. DRM_DEBUG_KMS("detaching pipe %c power sequencer from port %c\n",
  2444. pipe_name(pipe), port_name(intel_dig_port->port));
  2445. I915_WRITE(pp_on_reg, 0);
  2446. POSTING_READ(pp_on_reg);
  2447. intel_dp->pps_pipe = INVALID_PIPE;
  2448. }
  2449. static void vlv_steal_power_sequencer(struct drm_device *dev,
  2450. enum pipe pipe)
  2451. {
  2452. struct drm_i915_private *dev_priv = to_i915(dev);
  2453. struct intel_encoder *encoder;
  2454. lockdep_assert_held(&dev_priv->pps_mutex);
  2455. for_each_intel_encoder(dev, encoder) {
  2456. struct intel_dp *intel_dp;
  2457. enum port port;
  2458. if (encoder->type != INTEL_OUTPUT_DP &&
  2459. encoder->type != INTEL_OUTPUT_EDP)
  2460. continue;
  2461. intel_dp = enc_to_intel_dp(&encoder->base);
  2462. port = dp_to_dig_port(intel_dp)->port;
  2463. WARN(intel_dp->active_pipe == pipe,
  2464. "stealing pipe %c power sequencer from active (e)DP port %c\n",
  2465. pipe_name(pipe), port_name(port));
  2466. if (intel_dp->pps_pipe != pipe)
  2467. continue;
  2468. DRM_DEBUG_KMS("stealing pipe %c power sequencer from port %c\n",
  2469. pipe_name(pipe), port_name(port));
  2470. /* make sure vdd is off before we steal it */
  2471. vlv_detach_power_sequencer(intel_dp);
  2472. }
  2473. }
  2474. static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp)
  2475. {
  2476. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  2477. struct intel_encoder *encoder = &intel_dig_port->base;
  2478. struct drm_device *dev = encoder->base.dev;
  2479. struct drm_i915_private *dev_priv = to_i915(dev);
  2480. struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
  2481. lockdep_assert_held(&dev_priv->pps_mutex);
  2482. WARN_ON(intel_dp->active_pipe != INVALID_PIPE);
  2483. if (intel_dp->pps_pipe != INVALID_PIPE &&
  2484. intel_dp->pps_pipe != crtc->pipe) {
  2485. /*
  2486. * If another power sequencer was being used on this
  2487. * port previously make sure to turn off vdd there while
  2488. * we still have control of it.
  2489. */
  2490. vlv_detach_power_sequencer(intel_dp);
  2491. }
  2492. /*
  2493. * We may be stealing the power
  2494. * sequencer from another port.
  2495. */
  2496. vlv_steal_power_sequencer(dev, crtc->pipe);
  2497. intel_dp->active_pipe = crtc->pipe;
  2498. if (!intel_dp_is_edp(intel_dp))
  2499. return;
  2500. /* now it's all ours */
  2501. intel_dp->pps_pipe = crtc->pipe;
  2502. DRM_DEBUG_KMS("initializing pipe %c power sequencer for port %c\n",
  2503. pipe_name(intel_dp->pps_pipe), port_name(intel_dig_port->port));
  2504. /* init power sequencer on this pipe and port */
  2505. intel_dp_init_panel_power_sequencer(dev, intel_dp);
  2506. intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, true);
  2507. }
  2508. static void vlv_pre_enable_dp(struct intel_encoder *encoder,
  2509. const struct intel_crtc_state *pipe_config,
  2510. const struct drm_connector_state *conn_state)
  2511. {
  2512. vlv_phy_pre_encoder_enable(encoder);
  2513. intel_enable_dp(encoder, pipe_config, conn_state);
  2514. }
  2515. static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder,
  2516. const struct intel_crtc_state *pipe_config,
  2517. const struct drm_connector_state *conn_state)
  2518. {
  2519. intel_dp_prepare(encoder, pipe_config);
  2520. vlv_phy_pre_pll_enable(encoder);
  2521. }
  2522. static void chv_pre_enable_dp(struct intel_encoder *encoder,
  2523. const struct intel_crtc_state *pipe_config,
  2524. const struct drm_connector_state *conn_state)
  2525. {
  2526. chv_phy_pre_encoder_enable(encoder);
  2527. intel_enable_dp(encoder, pipe_config, conn_state);
  2528. /* Second common lane will stay alive on its own now */
  2529. chv_phy_release_cl2_override(encoder);
  2530. }
  2531. static void chv_dp_pre_pll_enable(struct intel_encoder *encoder,
  2532. const struct intel_crtc_state *pipe_config,
  2533. const struct drm_connector_state *conn_state)
  2534. {
  2535. intel_dp_prepare(encoder, pipe_config);
  2536. chv_phy_pre_pll_enable(encoder);
  2537. }
  2538. static void chv_dp_post_pll_disable(struct intel_encoder *encoder,
  2539. const struct intel_crtc_state *pipe_config,
  2540. const struct drm_connector_state *conn_state)
  2541. {
  2542. chv_phy_post_pll_disable(encoder);
  2543. }
  2544. /*
  2545. * Fetch AUX CH registers 0x202 - 0x207 which contain
  2546. * link status information
  2547. */
  2548. bool
  2549. intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
  2550. {
  2551. return drm_dp_dpcd_read(&intel_dp->aux, DP_LANE0_1_STATUS, link_status,
  2552. DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;
  2553. }
  2554. static bool intel_dp_get_y_cord_status(struct intel_dp *intel_dp)
  2555. {
  2556. uint8_t psr_caps = 0;
  2557. if (drm_dp_dpcd_readb(&intel_dp->aux, DP_PSR_CAPS, &psr_caps) != 1)
  2558. return false;
  2559. return psr_caps & DP_PSR2_SU_Y_COORDINATE_REQUIRED;
  2560. }
  2561. static bool intel_dp_get_colorimetry_status(struct intel_dp *intel_dp)
  2562. {
  2563. uint8_t dprx = 0;
  2564. if (drm_dp_dpcd_readb(&intel_dp->aux, DP_DPRX_FEATURE_ENUMERATION_LIST,
  2565. &dprx) != 1)
  2566. return false;
  2567. return dprx & DP_VSC_SDP_EXT_FOR_COLORIMETRY_SUPPORTED;
  2568. }
  2569. static bool intel_dp_get_alpm_status(struct intel_dp *intel_dp)
  2570. {
  2571. uint8_t alpm_caps = 0;
  2572. if (drm_dp_dpcd_readb(&intel_dp->aux, DP_RECEIVER_ALPM_CAP,
  2573. &alpm_caps) != 1)
  2574. return false;
  2575. return alpm_caps & DP_ALPM_CAP;
  2576. }
  2577. /* These are source-specific values. */
  2578. uint8_t
  2579. intel_dp_voltage_max(struct intel_dp *intel_dp)
  2580. {
  2581. struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
  2582. enum port port = dp_to_dig_port(intel_dp)->port;
  2583. if (IS_GEN9_LP(dev_priv))
  2584. return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
  2585. else if (INTEL_GEN(dev_priv) >= 9) {
  2586. struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
  2587. return intel_ddi_dp_voltage_max(encoder);
  2588. } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
  2589. return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
  2590. else if (IS_GEN7(dev_priv) && port == PORT_A)
  2591. return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
  2592. else if (HAS_PCH_CPT(dev_priv) && port != PORT_A)
  2593. return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
  2594. else
  2595. return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
  2596. }
  2597. uint8_t
  2598. intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
  2599. {
  2600. struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
  2601. enum port port = dp_to_dig_port(intel_dp)->port;
  2602. if (INTEL_GEN(dev_priv) >= 9) {
  2603. switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2604. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2605. return DP_TRAIN_PRE_EMPH_LEVEL_3;
  2606. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2607. return DP_TRAIN_PRE_EMPH_LEVEL_2;
  2608. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
  2609. return DP_TRAIN_PRE_EMPH_LEVEL_1;
  2610. case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
  2611. return DP_TRAIN_PRE_EMPH_LEVEL_0;
  2612. default:
  2613. return DP_TRAIN_PRE_EMPH_LEVEL_0;
  2614. }
  2615. } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
  2616. switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2617. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2618. return DP_TRAIN_PRE_EMPH_LEVEL_3;
  2619. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2620. return DP_TRAIN_PRE_EMPH_LEVEL_2;
  2621. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
  2622. return DP_TRAIN_PRE_EMPH_LEVEL_1;
  2623. case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
  2624. default:
  2625. return DP_TRAIN_PRE_EMPH_LEVEL_0;
  2626. }
  2627. } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
  2628. switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2629. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2630. return DP_TRAIN_PRE_EMPH_LEVEL_3;
  2631. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2632. return DP_TRAIN_PRE_EMPH_LEVEL_2;
  2633. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
  2634. return DP_TRAIN_PRE_EMPH_LEVEL_1;
  2635. case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
  2636. default:
  2637. return DP_TRAIN_PRE_EMPH_LEVEL_0;
  2638. }
  2639. } else if (IS_GEN7(dev_priv) && port == PORT_A) {
  2640. switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2641. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2642. return DP_TRAIN_PRE_EMPH_LEVEL_2;
  2643. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2644. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
  2645. return DP_TRAIN_PRE_EMPH_LEVEL_1;
  2646. default:
  2647. return DP_TRAIN_PRE_EMPH_LEVEL_0;
  2648. }
  2649. } else {
  2650. switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2651. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2652. return DP_TRAIN_PRE_EMPH_LEVEL_2;
  2653. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2654. return DP_TRAIN_PRE_EMPH_LEVEL_2;
  2655. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
  2656. return DP_TRAIN_PRE_EMPH_LEVEL_1;
  2657. case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
  2658. default:
  2659. return DP_TRAIN_PRE_EMPH_LEVEL_0;
  2660. }
  2661. }
  2662. }
  2663. static uint32_t vlv_signal_levels(struct intel_dp *intel_dp)
  2664. {
  2665. struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
  2666. unsigned long demph_reg_value, preemph_reg_value,
  2667. uniqtranscale_reg_value;
  2668. uint8_t train_set = intel_dp->train_set[0];
  2669. switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
  2670. case DP_TRAIN_PRE_EMPH_LEVEL_0:
  2671. preemph_reg_value = 0x0004000;
  2672. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2673. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2674. demph_reg_value = 0x2B405555;
  2675. uniqtranscale_reg_value = 0x552AB83A;
  2676. break;
  2677. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2678. demph_reg_value = 0x2B404040;
  2679. uniqtranscale_reg_value = 0x5548B83A;
  2680. break;
  2681. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
  2682. demph_reg_value = 0x2B245555;
  2683. uniqtranscale_reg_value = 0x5560B83A;
  2684. break;
  2685. case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
  2686. demph_reg_value = 0x2B405555;
  2687. uniqtranscale_reg_value = 0x5598DA3A;
  2688. break;
  2689. default:
  2690. return 0;
  2691. }
  2692. break;
  2693. case DP_TRAIN_PRE_EMPH_LEVEL_1:
  2694. preemph_reg_value = 0x0002000;
  2695. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2696. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2697. demph_reg_value = 0x2B404040;
  2698. uniqtranscale_reg_value = 0x5552B83A;
  2699. break;
  2700. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2701. demph_reg_value = 0x2B404848;
  2702. uniqtranscale_reg_value = 0x5580B83A;
  2703. break;
  2704. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
  2705. demph_reg_value = 0x2B404040;
  2706. uniqtranscale_reg_value = 0x55ADDA3A;
  2707. break;
  2708. default:
  2709. return 0;
  2710. }
  2711. break;
  2712. case DP_TRAIN_PRE_EMPH_LEVEL_2:
  2713. preemph_reg_value = 0x0000000;
  2714. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2715. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2716. demph_reg_value = 0x2B305555;
  2717. uniqtranscale_reg_value = 0x5570B83A;
  2718. break;
  2719. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2720. demph_reg_value = 0x2B2B4040;
  2721. uniqtranscale_reg_value = 0x55ADDA3A;
  2722. break;
  2723. default:
  2724. return 0;
  2725. }
  2726. break;
  2727. case DP_TRAIN_PRE_EMPH_LEVEL_3:
  2728. preemph_reg_value = 0x0006000;
  2729. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2730. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2731. demph_reg_value = 0x1B405555;
  2732. uniqtranscale_reg_value = 0x55ADDA3A;
  2733. break;
  2734. default:
  2735. return 0;
  2736. }
  2737. break;
  2738. default:
  2739. return 0;
  2740. }
  2741. vlv_set_phy_signal_level(encoder, demph_reg_value, preemph_reg_value,
  2742. uniqtranscale_reg_value, 0);
  2743. return 0;
  2744. }
  2745. static uint32_t chv_signal_levels(struct intel_dp *intel_dp)
  2746. {
  2747. struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
  2748. u32 deemph_reg_value, margin_reg_value;
  2749. bool uniq_trans_scale = false;
  2750. uint8_t train_set = intel_dp->train_set[0];
  2751. switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
  2752. case DP_TRAIN_PRE_EMPH_LEVEL_0:
  2753. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2754. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2755. deemph_reg_value = 128;
  2756. margin_reg_value = 52;
  2757. break;
  2758. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2759. deemph_reg_value = 128;
  2760. margin_reg_value = 77;
  2761. break;
  2762. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
  2763. deemph_reg_value = 128;
  2764. margin_reg_value = 102;
  2765. break;
  2766. case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
  2767. deemph_reg_value = 128;
  2768. margin_reg_value = 154;
  2769. uniq_trans_scale = true;
  2770. break;
  2771. default:
  2772. return 0;
  2773. }
  2774. break;
  2775. case DP_TRAIN_PRE_EMPH_LEVEL_1:
  2776. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2777. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2778. deemph_reg_value = 85;
  2779. margin_reg_value = 78;
  2780. break;
  2781. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2782. deemph_reg_value = 85;
  2783. margin_reg_value = 116;
  2784. break;
  2785. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
  2786. deemph_reg_value = 85;
  2787. margin_reg_value = 154;
  2788. break;
  2789. default:
  2790. return 0;
  2791. }
  2792. break;
  2793. case DP_TRAIN_PRE_EMPH_LEVEL_2:
  2794. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2795. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2796. deemph_reg_value = 64;
  2797. margin_reg_value = 104;
  2798. break;
  2799. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2800. deemph_reg_value = 64;
  2801. margin_reg_value = 154;
  2802. break;
  2803. default:
  2804. return 0;
  2805. }
  2806. break;
  2807. case DP_TRAIN_PRE_EMPH_LEVEL_3:
  2808. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2809. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2810. deemph_reg_value = 43;
  2811. margin_reg_value = 154;
  2812. break;
  2813. default:
  2814. return 0;
  2815. }
  2816. break;
  2817. default:
  2818. return 0;
  2819. }
  2820. chv_set_phy_signal_level(encoder, deemph_reg_value,
  2821. margin_reg_value, uniq_trans_scale);
  2822. return 0;
  2823. }
  2824. static uint32_t
  2825. gen4_signal_levels(uint8_t train_set)
  2826. {
  2827. uint32_t signal_levels = 0;
  2828. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2829. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2830. default:
  2831. signal_levels |= DP_VOLTAGE_0_4;
  2832. break;
  2833. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2834. signal_levels |= DP_VOLTAGE_0_6;
  2835. break;
  2836. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
  2837. signal_levels |= DP_VOLTAGE_0_8;
  2838. break;
  2839. case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
  2840. signal_levels |= DP_VOLTAGE_1_2;
  2841. break;
  2842. }
  2843. switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
  2844. case DP_TRAIN_PRE_EMPH_LEVEL_0:
  2845. default:
  2846. signal_levels |= DP_PRE_EMPHASIS_0;
  2847. break;
  2848. case DP_TRAIN_PRE_EMPH_LEVEL_1:
  2849. signal_levels |= DP_PRE_EMPHASIS_3_5;
  2850. break;
  2851. case DP_TRAIN_PRE_EMPH_LEVEL_2:
  2852. signal_levels |= DP_PRE_EMPHASIS_6;
  2853. break;
  2854. case DP_TRAIN_PRE_EMPH_LEVEL_3:
  2855. signal_levels |= DP_PRE_EMPHASIS_9_5;
  2856. break;
  2857. }
  2858. return signal_levels;
  2859. }
  2860. /* Gen6's DP voltage swing and pre-emphasis control */
  2861. static uint32_t
  2862. gen6_edp_signal_levels(uint8_t train_set)
  2863. {
  2864. int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
  2865. DP_TRAIN_PRE_EMPHASIS_MASK);
  2866. switch (signal_levels) {
  2867. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
  2868. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
  2869. return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
  2870. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
  2871. return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
  2872. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
  2873. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
  2874. return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
  2875. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
  2876. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
  2877. return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
  2878. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
  2879. case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0:
  2880. return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
  2881. default:
  2882. DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
  2883. "0x%x\n", signal_levels);
  2884. return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
  2885. }
  2886. }
  2887. /* Gen7's DP voltage swing and pre-emphasis control */
  2888. static uint32_t
  2889. gen7_edp_signal_levels(uint8_t train_set)
  2890. {
  2891. int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
  2892. DP_TRAIN_PRE_EMPHASIS_MASK);
  2893. switch (signal_levels) {
  2894. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
  2895. return EDP_LINK_TRAIN_400MV_0DB_IVB;
  2896. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
  2897. return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
  2898. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
  2899. return EDP_LINK_TRAIN_400MV_6DB_IVB;
  2900. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
  2901. return EDP_LINK_TRAIN_600MV_0DB_IVB;
  2902. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
  2903. return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
  2904. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
  2905. return EDP_LINK_TRAIN_800MV_0DB_IVB;
  2906. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
  2907. return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
  2908. default:
  2909. DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
  2910. "0x%x\n", signal_levels);
  2911. return EDP_LINK_TRAIN_500MV_0DB_IVB;
  2912. }
  2913. }
  2914. void
  2915. intel_dp_set_signal_levels(struct intel_dp *intel_dp)
  2916. {
  2917. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  2918. enum port port = intel_dig_port->port;
  2919. struct drm_device *dev = intel_dig_port->base.base.dev;
  2920. struct drm_i915_private *dev_priv = to_i915(dev);
  2921. uint32_t signal_levels, mask = 0;
  2922. uint8_t train_set = intel_dp->train_set[0];
  2923. if (IS_GEN9_LP(dev_priv) || IS_CANNONLAKE(dev_priv)) {
  2924. signal_levels = bxt_signal_levels(intel_dp);
  2925. } else if (HAS_DDI(dev_priv)) {
  2926. signal_levels = ddi_signal_levels(intel_dp);
  2927. mask = DDI_BUF_EMP_MASK;
  2928. } else if (IS_CHERRYVIEW(dev_priv)) {
  2929. signal_levels = chv_signal_levels(intel_dp);
  2930. } else if (IS_VALLEYVIEW(dev_priv)) {
  2931. signal_levels = vlv_signal_levels(intel_dp);
  2932. } else if (IS_GEN7(dev_priv) && port == PORT_A) {
  2933. signal_levels = gen7_edp_signal_levels(train_set);
  2934. mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
  2935. } else if (IS_GEN6(dev_priv) && port == PORT_A) {
  2936. signal_levels = gen6_edp_signal_levels(train_set);
  2937. mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
  2938. } else {
  2939. signal_levels = gen4_signal_levels(train_set);
  2940. mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
  2941. }
  2942. if (mask)
  2943. DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
  2944. DRM_DEBUG_KMS("Using vswing level %d\n",
  2945. train_set & DP_TRAIN_VOLTAGE_SWING_MASK);
  2946. DRM_DEBUG_KMS("Using pre-emphasis level %d\n",
  2947. (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >>
  2948. DP_TRAIN_PRE_EMPHASIS_SHIFT);
  2949. intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels;
  2950. I915_WRITE(intel_dp->output_reg, intel_dp->DP);
  2951. POSTING_READ(intel_dp->output_reg);
  2952. }
  2953. void
  2954. intel_dp_program_link_training_pattern(struct intel_dp *intel_dp,
  2955. uint8_t dp_train_pat)
  2956. {
  2957. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  2958. struct drm_i915_private *dev_priv =
  2959. to_i915(intel_dig_port->base.base.dev);
  2960. _intel_dp_set_link_train(intel_dp, &intel_dp->DP, dp_train_pat);
  2961. I915_WRITE(intel_dp->output_reg, intel_dp->DP);
  2962. POSTING_READ(intel_dp->output_reg);
  2963. }
  2964. void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
  2965. {
  2966. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  2967. struct drm_device *dev = intel_dig_port->base.base.dev;
  2968. struct drm_i915_private *dev_priv = to_i915(dev);
  2969. enum port port = intel_dig_port->port;
  2970. uint32_t val;
  2971. if (!HAS_DDI(dev_priv))
  2972. return;
  2973. val = I915_READ(DP_TP_CTL(port));
  2974. val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
  2975. val |= DP_TP_CTL_LINK_TRAIN_IDLE;
  2976. I915_WRITE(DP_TP_CTL(port), val);
  2977. /*
  2978. * On PORT_A we can have only eDP in SST mode. There the only reason
  2979. * we need to set idle transmission mode is to work around a HW issue
  2980. * where we enable the pipe while not in idle link-training mode.
  2981. * In this case there is requirement to wait for a minimum number of
  2982. * idle patterns to be sent.
  2983. */
  2984. if (port == PORT_A)
  2985. return;
  2986. if (intel_wait_for_register(dev_priv,DP_TP_STATUS(port),
  2987. DP_TP_STATUS_IDLE_DONE,
  2988. DP_TP_STATUS_IDLE_DONE,
  2989. 1))
  2990. DRM_ERROR("Timed out waiting for DP idle patterns\n");
  2991. }
  2992. static void
  2993. intel_dp_link_down(struct intel_dp *intel_dp)
  2994. {
  2995. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  2996. struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
  2997. enum port port = intel_dig_port->port;
  2998. struct drm_device *dev = intel_dig_port->base.base.dev;
  2999. struct drm_i915_private *dev_priv = to_i915(dev);
  3000. uint32_t DP = intel_dp->DP;
  3001. if (WARN_ON(HAS_DDI(dev_priv)))
  3002. return;
  3003. if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
  3004. return;
  3005. DRM_DEBUG_KMS("\n");
  3006. if ((IS_GEN7(dev_priv) && port == PORT_A) ||
  3007. (HAS_PCH_CPT(dev_priv) && port != PORT_A)) {
  3008. DP &= ~DP_LINK_TRAIN_MASK_CPT;
  3009. DP |= DP_LINK_TRAIN_PAT_IDLE_CPT;
  3010. } else {
  3011. if (IS_CHERRYVIEW(dev_priv))
  3012. DP &= ~DP_LINK_TRAIN_MASK_CHV;
  3013. else
  3014. DP &= ~DP_LINK_TRAIN_MASK;
  3015. DP |= DP_LINK_TRAIN_PAT_IDLE;
  3016. }
  3017. I915_WRITE(intel_dp->output_reg, DP);
  3018. POSTING_READ(intel_dp->output_reg);
  3019. DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
  3020. I915_WRITE(intel_dp->output_reg, DP);
  3021. POSTING_READ(intel_dp->output_reg);
  3022. /*
  3023. * HW workaround for IBX, we need to move the port
  3024. * to transcoder A after disabling it to allow the
  3025. * matching HDMI port to be enabled on transcoder A.
  3026. */
  3027. if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B && port != PORT_A) {
  3028. /*
  3029. * We get CPU/PCH FIFO underruns on the other pipe when
  3030. * doing the workaround. Sweep them under the rug.
  3031. */
  3032. intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
  3033. intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
  3034. /* always enable with pattern 1 (as per spec) */
  3035. DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK);
  3036. DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1;
  3037. I915_WRITE(intel_dp->output_reg, DP);
  3038. POSTING_READ(intel_dp->output_reg);
  3039. DP &= ~DP_PORT_EN;
  3040. I915_WRITE(intel_dp->output_reg, DP);
  3041. POSTING_READ(intel_dp->output_reg);
  3042. intel_wait_for_vblank_if_active(dev_priv, PIPE_A);
  3043. intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
  3044. intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
  3045. }
  3046. msleep(intel_dp->panel_power_down_delay);
  3047. intel_dp->DP = DP;
  3048. if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
  3049. pps_lock(intel_dp);
  3050. intel_dp->active_pipe = INVALID_PIPE;
  3051. pps_unlock(intel_dp);
  3052. }
  3053. }
  3054. bool
  3055. intel_dp_read_dpcd(struct intel_dp *intel_dp)
  3056. {
  3057. if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd,
  3058. sizeof(intel_dp->dpcd)) < 0)
  3059. return false; /* aux transfer failed */
  3060. DRM_DEBUG_KMS("DPCD: %*ph\n", (int) sizeof(intel_dp->dpcd), intel_dp->dpcd);
  3061. return intel_dp->dpcd[DP_DPCD_REV] != 0;
  3062. }
  3063. static bool
  3064. intel_edp_init_dpcd(struct intel_dp *intel_dp)
  3065. {
  3066. struct drm_i915_private *dev_priv =
  3067. to_i915(dp_to_dig_port(intel_dp)->base.base.dev);
  3068. /* this function is meant to be called only once */
  3069. WARN_ON(intel_dp->dpcd[DP_DPCD_REV] != 0);
  3070. if (!intel_dp_read_dpcd(intel_dp))
  3071. return false;
  3072. drm_dp_read_desc(&intel_dp->aux, &intel_dp->desc,
  3073. drm_dp_is_branch(intel_dp->dpcd));
  3074. if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
  3075. dev_priv->no_aux_handshake = intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
  3076. DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
  3077. /* Check if the panel supports PSR */
  3078. drm_dp_dpcd_read(&intel_dp->aux, DP_PSR_SUPPORT,
  3079. intel_dp->psr_dpcd,
  3080. sizeof(intel_dp->psr_dpcd));
  3081. if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) {
  3082. dev_priv->psr.sink_support = true;
  3083. DRM_DEBUG_KMS("Detected EDP PSR Panel.\n");
  3084. }
  3085. if (INTEL_GEN(dev_priv) >= 9 &&
  3086. (intel_dp->psr_dpcd[0] & DP_PSR2_IS_SUPPORTED)) {
  3087. uint8_t frame_sync_cap;
  3088. dev_priv->psr.sink_support = true;
  3089. if (drm_dp_dpcd_readb(&intel_dp->aux,
  3090. DP_SINK_DEVICE_AUX_FRAME_SYNC_CAP,
  3091. &frame_sync_cap) != 1)
  3092. frame_sync_cap = 0;
  3093. dev_priv->psr.aux_frame_sync = frame_sync_cap ? true : false;
  3094. /* PSR2 needs frame sync as well */
  3095. dev_priv->psr.psr2_support = dev_priv->psr.aux_frame_sync;
  3096. DRM_DEBUG_KMS("PSR2 %s on sink",
  3097. dev_priv->psr.psr2_support ? "supported" : "not supported");
  3098. if (dev_priv->psr.psr2_support) {
  3099. dev_priv->psr.y_cord_support =
  3100. intel_dp_get_y_cord_status(intel_dp);
  3101. dev_priv->psr.colorimetry_support =
  3102. intel_dp_get_colorimetry_status(intel_dp);
  3103. dev_priv->psr.alpm =
  3104. intel_dp_get_alpm_status(intel_dp);
  3105. }
  3106. }
  3107. /* Read the eDP Display control capabilities registers */
  3108. if ((intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] & DP_DPCD_DISPLAY_CONTROL_CAPABLE) &&
  3109. drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
  3110. intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) ==
  3111. sizeof(intel_dp->edp_dpcd))
  3112. DRM_DEBUG_KMS("EDP DPCD : %*ph\n", (int) sizeof(intel_dp->edp_dpcd),
  3113. intel_dp->edp_dpcd);
  3114. /* Intermediate frequency support */
  3115. if (intel_dp->edp_dpcd[0] >= 0x03) { /* eDp v1.4 or higher */
  3116. __le16 sink_rates[DP_MAX_SUPPORTED_RATES];
  3117. int i;
  3118. drm_dp_dpcd_read(&intel_dp->aux, DP_SUPPORTED_LINK_RATES,
  3119. sink_rates, sizeof(sink_rates));
  3120. for (i = 0; i < ARRAY_SIZE(sink_rates); i++) {
  3121. int val = le16_to_cpu(sink_rates[i]);
  3122. if (val == 0)
  3123. break;
  3124. /* Value read multiplied by 200kHz gives the per-lane
  3125. * link rate in kHz. The source rates are, however,
  3126. * stored in terms of LS_Clk kHz. The full conversion
  3127. * back to symbols is
  3128. * (val * 200kHz)*(8/10 ch. encoding)*(1/8 bit to Byte)
  3129. */
  3130. intel_dp->sink_rates[i] = (val * 200) / 10;
  3131. }
  3132. intel_dp->num_sink_rates = i;
  3133. }
  3134. if (intel_dp->num_sink_rates)
  3135. intel_dp->use_rate_select = true;
  3136. else
  3137. intel_dp_set_sink_rates(intel_dp);
  3138. intel_dp_set_common_rates(intel_dp);
  3139. return true;
  3140. }
  3141. static bool
  3142. intel_dp_get_dpcd(struct intel_dp *intel_dp)
  3143. {
  3144. u8 sink_count;
  3145. if (!intel_dp_read_dpcd(intel_dp))
  3146. return false;
  3147. /* Don't clobber cached eDP rates. */
  3148. if (!intel_dp_is_edp(intel_dp)) {
  3149. intel_dp_set_sink_rates(intel_dp);
  3150. intel_dp_set_common_rates(intel_dp);
  3151. }
  3152. if (drm_dp_dpcd_readb(&intel_dp->aux, DP_SINK_COUNT, &sink_count) <= 0)
  3153. return false;
  3154. /*
  3155. * Sink count can change between short pulse hpd hence
  3156. * a member variable in intel_dp will track any changes
  3157. * between short pulse interrupts.
  3158. */
  3159. intel_dp->sink_count = DP_GET_SINK_COUNT(sink_count);
  3160. /*
  3161. * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that
  3162. * a dongle is present but no display. Unless we require to know
  3163. * if a dongle is present or not, we don't need to update
  3164. * downstream port information. So, an early return here saves
  3165. * time from performing other operations which are not required.
  3166. */
  3167. if (!intel_dp_is_edp(intel_dp) && !intel_dp->sink_count)
  3168. return false;
  3169. if (!drm_dp_is_branch(intel_dp->dpcd))
  3170. return true; /* native DP sink */
  3171. if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
  3172. return true; /* no per-port downstream info */
  3173. if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0,
  3174. intel_dp->downstream_ports,
  3175. DP_MAX_DOWNSTREAM_PORTS) < 0)
  3176. return false; /* downstream port status fetch failed */
  3177. return true;
  3178. }
  3179. static bool
  3180. intel_dp_can_mst(struct intel_dp *intel_dp)
  3181. {
  3182. u8 mstm_cap;
  3183. if (!i915_modparams.enable_dp_mst)
  3184. return false;
  3185. if (!intel_dp->can_mst)
  3186. return false;
  3187. if (intel_dp->dpcd[DP_DPCD_REV] < 0x12)
  3188. return false;
  3189. if (drm_dp_dpcd_readb(&intel_dp->aux, DP_MSTM_CAP, &mstm_cap) != 1)
  3190. return false;
  3191. return mstm_cap & DP_MST_CAP;
  3192. }
  3193. static void
  3194. intel_dp_configure_mst(struct intel_dp *intel_dp)
  3195. {
  3196. if (!i915_modparams.enable_dp_mst)
  3197. return;
  3198. if (!intel_dp->can_mst)
  3199. return;
  3200. intel_dp->is_mst = intel_dp_can_mst(intel_dp);
  3201. if (intel_dp->is_mst)
  3202. DRM_DEBUG_KMS("Sink is MST capable\n");
  3203. else
  3204. DRM_DEBUG_KMS("Sink is not MST capable\n");
  3205. drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
  3206. intel_dp->is_mst);
  3207. }
  3208. static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp)
  3209. {
  3210. struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
  3211. struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
  3212. struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
  3213. u8 buf;
  3214. int ret = 0;
  3215. int count = 0;
  3216. int attempts = 10;
  3217. if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) {
  3218. DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
  3219. ret = -EIO;
  3220. goto out;
  3221. }
  3222. if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
  3223. buf & ~DP_TEST_SINK_START) < 0) {
  3224. DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
  3225. ret = -EIO;
  3226. goto out;
  3227. }
  3228. do {
  3229. intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
  3230. if (drm_dp_dpcd_readb(&intel_dp->aux,
  3231. DP_TEST_SINK_MISC, &buf) < 0) {
  3232. ret = -EIO;
  3233. goto out;
  3234. }
  3235. count = buf & DP_TEST_COUNT_MASK;
  3236. } while (--attempts && count);
  3237. if (attempts == 0) {
  3238. DRM_DEBUG_KMS("TIMEOUT: Sink CRC counter is not zeroed after calculation is stopped\n");
  3239. ret = -ETIMEDOUT;
  3240. }
  3241. out:
  3242. hsw_enable_ips(intel_crtc);
  3243. return ret;
  3244. }
  3245. static int intel_dp_sink_crc_start(struct intel_dp *intel_dp)
  3246. {
  3247. struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
  3248. struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
  3249. struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
  3250. u8 buf;
  3251. int ret;
  3252. if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0)
  3253. return -EIO;
  3254. if (!(buf & DP_TEST_CRC_SUPPORTED))
  3255. return -ENOTTY;
  3256. if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0)
  3257. return -EIO;
  3258. if (buf & DP_TEST_SINK_START) {
  3259. ret = intel_dp_sink_crc_stop(intel_dp);
  3260. if (ret)
  3261. return ret;
  3262. }
  3263. hsw_disable_ips(intel_crtc);
  3264. if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
  3265. buf | DP_TEST_SINK_START) < 0) {
  3266. hsw_enable_ips(intel_crtc);
  3267. return -EIO;
  3268. }
  3269. intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
  3270. return 0;
  3271. }
  3272. int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc)
  3273. {
  3274. struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
  3275. struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
  3276. struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
  3277. u8 buf;
  3278. int count, ret;
  3279. int attempts = 6;
  3280. ret = intel_dp_sink_crc_start(intel_dp);
  3281. if (ret)
  3282. return ret;
  3283. do {
  3284. intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
  3285. if (drm_dp_dpcd_readb(&intel_dp->aux,
  3286. DP_TEST_SINK_MISC, &buf) < 0) {
  3287. ret = -EIO;
  3288. goto stop;
  3289. }
  3290. count = buf & DP_TEST_COUNT_MASK;
  3291. } while (--attempts && count == 0);
  3292. if (attempts == 0) {
  3293. DRM_ERROR("Panel is unable to calculate any CRC after 6 vblanks\n");
  3294. ret = -ETIMEDOUT;
  3295. goto stop;
  3296. }
  3297. if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0) {
  3298. ret = -EIO;
  3299. goto stop;
  3300. }
  3301. stop:
  3302. intel_dp_sink_crc_stop(intel_dp);
  3303. return ret;
  3304. }
  3305. static bool
  3306. intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
  3307. {
  3308. return drm_dp_dpcd_readb(&intel_dp->aux, DP_DEVICE_SERVICE_IRQ_VECTOR,
  3309. sink_irq_vector) == 1;
  3310. }
  3311. static bool
  3312. intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector)
  3313. {
  3314. int ret;
  3315. ret = drm_dp_dpcd_read(&intel_dp->aux,
  3316. DP_SINK_COUNT_ESI,
  3317. sink_irq_vector, 14);
  3318. if (ret != 14)
  3319. return false;
  3320. return true;
  3321. }
  3322. static uint8_t intel_dp_autotest_link_training(struct intel_dp *intel_dp)
  3323. {
  3324. int status = 0;
  3325. int test_link_rate;
  3326. uint8_t test_lane_count, test_link_bw;
  3327. /* (DP CTS 1.2)
  3328. * 4.3.1.11
  3329. */
  3330. /* Read the TEST_LANE_COUNT and TEST_LINK_RTAE fields (DP CTS 3.1.4) */
  3331. status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LANE_COUNT,
  3332. &test_lane_count);
  3333. if (status <= 0) {
  3334. DRM_DEBUG_KMS("Lane count read failed\n");
  3335. return DP_TEST_NAK;
  3336. }
  3337. test_lane_count &= DP_MAX_LANE_COUNT_MASK;
  3338. status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_LINK_RATE,
  3339. &test_link_bw);
  3340. if (status <= 0) {
  3341. DRM_DEBUG_KMS("Link Rate read failed\n");
  3342. return DP_TEST_NAK;
  3343. }
  3344. test_link_rate = drm_dp_bw_code_to_link_rate(test_link_bw);
  3345. /* Validate the requested link rate and lane count */
  3346. if (!intel_dp_link_params_valid(intel_dp, test_link_rate,
  3347. test_lane_count))
  3348. return DP_TEST_NAK;
  3349. intel_dp->compliance.test_lane_count = test_lane_count;
  3350. intel_dp->compliance.test_link_rate = test_link_rate;
  3351. return DP_TEST_ACK;
  3352. }
  3353. static uint8_t intel_dp_autotest_video_pattern(struct intel_dp *intel_dp)
  3354. {
  3355. uint8_t test_pattern;
  3356. uint8_t test_misc;
  3357. __be16 h_width, v_height;
  3358. int status = 0;
  3359. /* Read the TEST_PATTERN (DP CTS 3.1.5) */
  3360. status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_PATTERN,
  3361. &test_pattern);
  3362. if (status <= 0) {
  3363. DRM_DEBUG_KMS("Test pattern read failed\n");
  3364. return DP_TEST_NAK;
  3365. }
  3366. if (test_pattern != DP_COLOR_RAMP)
  3367. return DP_TEST_NAK;
  3368. status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_H_WIDTH_HI,
  3369. &h_width, 2);
  3370. if (status <= 0) {
  3371. DRM_DEBUG_KMS("H Width read failed\n");
  3372. return DP_TEST_NAK;
  3373. }
  3374. status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_V_HEIGHT_HI,
  3375. &v_height, 2);
  3376. if (status <= 0) {
  3377. DRM_DEBUG_KMS("V Height read failed\n");
  3378. return DP_TEST_NAK;
  3379. }
  3380. status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_MISC0,
  3381. &test_misc);
  3382. if (status <= 0) {
  3383. DRM_DEBUG_KMS("TEST MISC read failed\n");
  3384. return DP_TEST_NAK;
  3385. }
  3386. if ((test_misc & DP_TEST_COLOR_FORMAT_MASK) != DP_COLOR_FORMAT_RGB)
  3387. return DP_TEST_NAK;
  3388. if (test_misc & DP_TEST_DYNAMIC_RANGE_CEA)
  3389. return DP_TEST_NAK;
  3390. switch (test_misc & DP_TEST_BIT_DEPTH_MASK) {
  3391. case DP_TEST_BIT_DEPTH_6:
  3392. intel_dp->compliance.test_data.bpc = 6;
  3393. break;
  3394. case DP_TEST_BIT_DEPTH_8:
  3395. intel_dp->compliance.test_data.bpc = 8;
  3396. break;
  3397. default:
  3398. return DP_TEST_NAK;
  3399. }
  3400. intel_dp->compliance.test_data.video_pattern = test_pattern;
  3401. intel_dp->compliance.test_data.hdisplay = be16_to_cpu(h_width);
  3402. intel_dp->compliance.test_data.vdisplay = be16_to_cpu(v_height);
  3403. /* Set test active flag here so userspace doesn't interrupt things */
  3404. intel_dp->compliance.test_active = 1;
  3405. return DP_TEST_ACK;
  3406. }
  3407. static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp)
  3408. {
  3409. uint8_t test_result = DP_TEST_ACK;
  3410. struct intel_connector *intel_connector = intel_dp->attached_connector;
  3411. struct drm_connector *connector = &intel_connector->base;
  3412. if (intel_connector->detect_edid == NULL ||
  3413. connector->edid_corrupt ||
  3414. intel_dp->aux.i2c_defer_count > 6) {
  3415. /* Check EDID read for NACKs, DEFERs and corruption
  3416. * (DP CTS 1.2 Core r1.1)
  3417. * 4.2.2.4 : Failed EDID read, I2C_NAK
  3418. * 4.2.2.5 : Failed EDID read, I2C_DEFER
  3419. * 4.2.2.6 : EDID corruption detected
  3420. * Use failsafe mode for all cases
  3421. */
  3422. if (intel_dp->aux.i2c_nack_count > 0 ||
  3423. intel_dp->aux.i2c_defer_count > 0)
  3424. DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n",
  3425. intel_dp->aux.i2c_nack_count,
  3426. intel_dp->aux.i2c_defer_count);
  3427. intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_FAILSAFE;
  3428. } else {
  3429. struct edid *block = intel_connector->detect_edid;
  3430. /* We have to write the checksum
  3431. * of the last block read
  3432. */
  3433. block += intel_connector->detect_edid->extensions;
  3434. if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_EDID_CHECKSUM,
  3435. block->checksum) <= 0)
  3436. DRM_DEBUG_KMS("Failed to write EDID checksum\n");
  3437. test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE;
  3438. intel_dp->compliance.test_data.edid = INTEL_DP_RESOLUTION_PREFERRED;
  3439. }
  3440. /* Set test active flag here so userspace doesn't interrupt things */
  3441. intel_dp->compliance.test_active = 1;
  3442. return test_result;
  3443. }
  3444. static uint8_t intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp)
  3445. {
  3446. uint8_t test_result = DP_TEST_NAK;
  3447. return test_result;
  3448. }
  3449. static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
  3450. {
  3451. uint8_t response = DP_TEST_NAK;
  3452. uint8_t request = 0;
  3453. int status;
  3454. status = drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_REQUEST, &request);
  3455. if (status <= 0) {
  3456. DRM_DEBUG_KMS("Could not read test request from sink\n");
  3457. goto update_status;
  3458. }
  3459. switch (request) {
  3460. case DP_TEST_LINK_TRAINING:
  3461. DRM_DEBUG_KMS("LINK_TRAINING test requested\n");
  3462. response = intel_dp_autotest_link_training(intel_dp);
  3463. break;
  3464. case DP_TEST_LINK_VIDEO_PATTERN:
  3465. DRM_DEBUG_KMS("TEST_PATTERN test requested\n");
  3466. response = intel_dp_autotest_video_pattern(intel_dp);
  3467. break;
  3468. case DP_TEST_LINK_EDID_READ:
  3469. DRM_DEBUG_KMS("EDID test requested\n");
  3470. response = intel_dp_autotest_edid(intel_dp);
  3471. break;
  3472. case DP_TEST_LINK_PHY_TEST_PATTERN:
  3473. DRM_DEBUG_KMS("PHY_PATTERN test requested\n");
  3474. response = intel_dp_autotest_phy_pattern(intel_dp);
  3475. break;
  3476. default:
  3477. DRM_DEBUG_KMS("Invalid test request '%02x'\n", request);
  3478. break;
  3479. }
  3480. if (response & DP_TEST_ACK)
  3481. intel_dp->compliance.test_type = request;
  3482. update_status:
  3483. status = drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_RESPONSE, response);
  3484. if (status <= 0)
  3485. DRM_DEBUG_KMS("Could not write test response to sink\n");
  3486. }
  3487. static int
  3488. intel_dp_check_mst_status(struct intel_dp *intel_dp)
  3489. {
  3490. bool bret;
  3491. if (intel_dp->is_mst) {
  3492. u8 esi[16] = { 0 };
  3493. int ret = 0;
  3494. int retry;
  3495. bool handled;
  3496. bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
  3497. go_again:
  3498. if (bret == true) {
  3499. /* check link status - esi[10] = 0x200c */
  3500. if (intel_dp->active_mst_links &&
  3501. !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) {
  3502. DRM_DEBUG_KMS("channel EQ not ok, retraining\n");
  3503. intel_dp_start_link_train(intel_dp);
  3504. intel_dp_stop_link_train(intel_dp);
  3505. }
  3506. DRM_DEBUG_KMS("got esi %3ph\n", esi);
  3507. ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled);
  3508. if (handled) {
  3509. for (retry = 0; retry < 3; retry++) {
  3510. int wret;
  3511. wret = drm_dp_dpcd_write(&intel_dp->aux,
  3512. DP_SINK_COUNT_ESI+1,
  3513. &esi[1], 3);
  3514. if (wret == 3) {
  3515. break;
  3516. }
  3517. }
  3518. bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
  3519. if (bret == true) {
  3520. DRM_DEBUG_KMS("got esi2 %3ph\n", esi);
  3521. goto go_again;
  3522. }
  3523. } else
  3524. ret = 0;
  3525. return ret;
  3526. } else {
  3527. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  3528. DRM_DEBUG_KMS("failed to get ESI - device may have failed\n");
  3529. intel_dp->is_mst = false;
  3530. drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
  3531. /* send a hotplug event */
  3532. drm_kms_helper_hotplug_event(intel_dig_port->base.base.dev);
  3533. }
  3534. }
  3535. return -EINVAL;
  3536. }
  3537. static void
  3538. intel_dp_retrain_link(struct intel_dp *intel_dp)
  3539. {
  3540. struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
  3541. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  3542. struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
  3543. /* Suppress underruns caused by re-training */
  3544. intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
  3545. if (crtc->config->has_pch_encoder)
  3546. intel_set_pch_fifo_underrun_reporting(dev_priv,
  3547. intel_crtc_pch_transcoder(crtc), false);
  3548. intel_dp_start_link_train(intel_dp);
  3549. intel_dp_stop_link_train(intel_dp);
  3550. /* Keep underrun reporting disabled until things are stable */
  3551. intel_wait_for_vblank(dev_priv, crtc->pipe);
  3552. intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
  3553. if (crtc->config->has_pch_encoder)
  3554. intel_set_pch_fifo_underrun_reporting(dev_priv,
  3555. intel_crtc_pch_transcoder(crtc), true);
  3556. }
  3557. static void
  3558. intel_dp_check_link_status(struct intel_dp *intel_dp)
  3559. {
  3560. struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
  3561. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  3562. u8 link_status[DP_LINK_STATUS_SIZE];
  3563. WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
  3564. if (!intel_dp_get_link_status(intel_dp, link_status)) {
  3565. DRM_ERROR("Failed to get link status\n");
  3566. return;
  3567. }
  3568. if (!intel_encoder->base.crtc)
  3569. return;
  3570. if (!to_intel_crtc(intel_encoder->base.crtc)->active)
  3571. return;
  3572. /*
  3573. * Validate the cached values of intel_dp->link_rate and
  3574. * intel_dp->lane_count before attempting to retrain.
  3575. */
  3576. if (!intel_dp_link_params_valid(intel_dp, intel_dp->link_rate,
  3577. intel_dp->lane_count))
  3578. return;
  3579. /* Retrain if Channel EQ or CR not ok */
  3580. if (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
  3581. DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
  3582. intel_encoder->base.name);
  3583. intel_dp_retrain_link(intel_dp);
  3584. }
  3585. }
  3586. /*
  3587. * According to DP spec
  3588. * 5.1.2:
  3589. * 1. Read DPCD
  3590. * 2. Configure link according to Receiver Capabilities
  3591. * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
  3592. * 4. Check link status on receipt of hot-plug interrupt
  3593. *
  3594. * intel_dp_short_pulse - handles short pulse interrupts
  3595. * when full detection is not required.
  3596. * Returns %true if short pulse is handled and full detection
  3597. * is NOT required and %false otherwise.
  3598. */
  3599. static bool
  3600. intel_dp_short_pulse(struct intel_dp *intel_dp)
  3601. {
  3602. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  3603. struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
  3604. u8 sink_irq_vector = 0;
  3605. u8 old_sink_count = intel_dp->sink_count;
  3606. bool ret;
  3607. /*
  3608. * Clearing compliance test variables to allow capturing
  3609. * of values for next automated test request.
  3610. */
  3611. memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
  3612. /*
  3613. * Now read the DPCD to see if it's actually running
  3614. * If the current value of sink count doesn't match with
  3615. * the value that was stored earlier or dpcd read failed
  3616. * we need to do full detection
  3617. */
  3618. ret = intel_dp_get_dpcd(intel_dp);
  3619. if ((old_sink_count != intel_dp->sink_count) || !ret) {
  3620. /* No need to proceed if we are going to do full detect */
  3621. return false;
  3622. }
  3623. /* Try to read the source of the interrupt */
  3624. if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
  3625. intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
  3626. sink_irq_vector != 0) {
  3627. /* Clear interrupt source */
  3628. drm_dp_dpcd_writeb(&intel_dp->aux,
  3629. DP_DEVICE_SERVICE_IRQ_VECTOR,
  3630. sink_irq_vector);
  3631. if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
  3632. intel_dp_handle_test_request(intel_dp);
  3633. if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
  3634. DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
  3635. }
  3636. drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
  3637. intel_dp_check_link_status(intel_dp);
  3638. drm_modeset_unlock(&dev->mode_config.connection_mutex);
  3639. if (intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) {
  3640. DRM_DEBUG_KMS("Link Training Compliance Test requested\n");
  3641. /* Send a Hotplug Uevent to userspace to start modeset */
  3642. drm_kms_helper_hotplug_event(intel_encoder->base.dev);
  3643. }
  3644. return true;
  3645. }
  3646. /* XXX this is probably wrong for multiple downstream ports */
  3647. static enum drm_connector_status
  3648. intel_dp_detect_dpcd(struct intel_dp *intel_dp)
  3649. {
  3650. struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
  3651. uint8_t *dpcd = intel_dp->dpcd;
  3652. uint8_t type;
  3653. if (lspcon->active)
  3654. lspcon_resume(lspcon);
  3655. if (!intel_dp_get_dpcd(intel_dp))
  3656. return connector_status_disconnected;
  3657. if (intel_dp_is_edp(intel_dp))
  3658. return connector_status_connected;
  3659. /* if there's no downstream port, we're done */
  3660. if (!drm_dp_is_branch(dpcd))
  3661. return connector_status_connected;
  3662. /* If we're HPD-aware, SINK_COUNT changes dynamically */
  3663. if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
  3664. intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
  3665. return intel_dp->sink_count ?
  3666. connector_status_connected : connector_status_disconnected;
  3667. }
  3668. if (intel_dp_can_mst(intel_dp))
  3669. return connector_status_connected;
  3670. /* If no HPD, poke DDC gently */
  3671. if (drm_probe_ddc(&intel_dp->aux.ddc))
  3672. return connector_status_connected;
  3673. /* Well we tried, say unknown for unreliable port types */
  3674. if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
  3675. type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
  3676. if (type == DP_DS_PORT_TYPE_VGA ||
  3677. type == DP_DS_PORT_TYPE_NON_EDID)
  3678. return connector_status_unknown;
  3679. } else {
  3680. type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
  3681. DP_DWN_STRM_PORT_TYPE_MASK;
  3682. if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
  3683. type == DP_DWN_STRM_PORT_TYPE_OTHER)
  3684. return connector_status_unknown;
  3685. }
  3686. /* Anything else is out of spec, warn and ignore */
  3687. DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
  3688. return connector_status_disconnected;
  3689. }
  3690. static enum drm_connector_status
  3691. edp_detect(struct intel_dp *intel_dp)
  3692. {
  3693. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  3694. struct drm_i915_private *dev_priv = to_i915(dev);
  3695. enum drm_connector_status status;
  3696. status = intel_panel_detect(dev_priv);
  3697. if (status == connector_status_unknown)
  3698. status = connector_status_connected;
  3699. return status;
  3700. }
  3701. static bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
  3702. struct intel_digital_port *port)
  3703. {
  3704. u32 bit;
  3705. switch (port->port) {
  3706. case PORT_B:
  3707. bit = SDE_PORTB_HOTPLUG;
  3708. break;
  3709. case PORT_C:
  3710. bit = SDE_PORTC_HOTPLUG;
  3711. break;
  3712. case PORT_D:
  3713. bit = SDE_PORTD_HOTPLUG;
  3714. break;
  3715. default:
  3716. MISSING_CASE(port->port);
  3717. return false;
  3718. }
  3719. return I915_READ(SDEISR) & bit;
  3720. }
  3721. static bool cpt_digital_port_connected(struct drm_i915_private *dev_priv,
  3722. struct intel_digital_port *port)
  3723. {
  3724. u32 bit;
  3725. switch (port->port) {
  3726. case PORT_B:
  3727. bit = SDE_PORTB_HOTPLUG_CPT;
  3728. break;
  3729. case PORT_C:
  3730. bit = SDE_PORTC_HOTPLUG_CPT;
  3731. break;
  3732. case PORT_D:
  3733. bit = SDE_PORTD_HOTPLUG_CPT;
  3734. break;
  3735. default:
  3736. MISSING_CASE(port->port);
  3737. return false;
  3738. }
  3739. return I915_READ(SDEISR) & bit;
  3740. }
  3741. static bool spt_digital_port_connected(struct drm_i915_private *dev_priv,
  3742. struct intel_digital_port *port)
  3743. {
  3744. u32 bit;
  3745. switch (port->port) {
  3746. case PORT_A:
  3747. bit = SDE_PORTA_HOTPLUG_SPT;
  3748. break;
  3749. case PORT_E:
  3750. bit = SDE_PORTE_HOTPLUG_SPT;
  3751. break;
  3752. default:
  3753. return cpt_digital_port_connected(dev_priv, port);
  3754. }
  3755. return I915_READ(SDEISR) & bit;
  3756. }
  3757. static bool g4x_digital_port_connected(struct drm_i915_private *dev_priv,
  3758. struct intel_digital_port *port)
  3759. {
  3760. u32 bit;
  3761. switch (port->port) {
  3762. case PORT_B:
  3763. bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
  3764. break;
  3765. case PORT_C:
  3766. bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
  3767. break;
  3768. case PORT_D:
  3769. bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
  3770. break;
  3771. default:
  3772. MISSING_CASE(port->port);
  3773. return false;
  3774. }
  3775. return I915_READ(PORT_HOTPLUG_STAT) & bit;
  3776. }
  3777. static bool gm45_digital_port_connected(struct drm_i915_private *dev_priv,
  3778. struct intel_digital_port *port)
  3779. {
  3780. u32 bit;
  3781. switch (port->port) {
  3782. case PORT_B:
  3783. bit = PORTB_HOTPLUG_LIVE_STATUS_GM45;
  3784. break;
  3785. case PORT_C:
  3786. bit = PORTC_HOTPLUG_LIVE_STATUS_GM45;
  3787. break;
  3788. case PORT_D:
  3789. bit = PORTD_HOTPLUG_LIVE_STATUS_GM45;
  3790. break;
  3791. default:
  3792. MISSING_CASE(port->port);
  3793. return false;
  3794. }
  3795. return I915_READ(PORT_HOTPLUG_STAT) & bit;
  3796. }
  3797. static bool ilk_digital_port_connected(struct drm_i915_private *dev_priv,
  3798. struct intel_digital_port *port)
  3799. {
  3800. if (port->port == PORT_A)
  3801. return I915_READ(DEISR) & DE_DP_A_HOTPLUG;
  3802. else
  3803. return ibx_digital_port_connected(dev_priv, port);
  3804. }
  3805. static bool snb_digital_port_connected(struct drm_i915_private *dev_priv,
  3806. struct intel_digital_port *port)
  3807. {
  3808. if (port->port == PORT_A)
  3809. return I915_READ(DEISR) & DE_DP_A_HOTPLUG;
  3810. else
  3811. return cpt_digital_port_connected(dev_priv, port);
  3812. }
  3813. static bool ivb_digital_port_connected(struct drm_i915_private *dev_priv,
  3814. struct intel_digital_port *port)
  3815. {
  3816. if (port->port == PORT_A)
  3817. return I915_READ(DEISR) & DE_DP_A_HOTPLUG_IVB;
  3818. else
  3819. return cpt_digital_port_connected(dev_priv, port);
  3820. }
  3821. static bool bdw_digital_port_connected(struct drm_i915_private *dev_priv,
  3822. struct intel_digital_port *port)
  3823. {
  3824. if (port->port == PORT_A)
  3825. return I915_READ(GEN8_DE_PORT_ISR) & GEN8_PORT_DP_A_HOTPLUG;
  3826. else
  3827. return cpt_digital_port_connected(dev_priv, port);
  3828. }
  3829. static bool bxt_digital_port_connected(struct drm_i915_private *dev_priv,
  3830. struct intel_digital_port *intel_dig_port)
  3831. {
  3832. struct intel_encoder *intel_encoder = &intel_dig_port->base;
  3833. enum port port;
  3834. u32 bit;
  3835. port = intel_hpd_pin_to_port(intel_encoder->hpd_pin);
  3836. switch (port) {
  3837. case PORT_A:
  3838. bit = BXT_DE_PORT_HP_DDIA;
  3839. break;
  3840. case PORT_B:
  3841. bit = BXT_DE_PORT_HP_DDIB;
  3842. break;
  3843. case PORT_C:
  3844. bit = BXT_DE_PORT_HP_DDIC;
  3845. break;
  3846. default:
  3847. MISSING_CASE(port);
  3848. return false;
  3849. }
  3850. return I915_READ(GEN8_DE_PORT_ISR) & bit;
  3851. }
  3852. /*
  3853. * intel_digital_port_connected - is the specified port connected?
  3854. * @dev_priv: i915 private structure
  3855. * @port: the port to test
  3856. *
  3857. * Return %true if @port is connected, %false otherwise.
  3858. */
  3859. bool intel_digital_port_connected(struct drm_i915_private *dev_priv,
  3860. struct intel_digital_port *port)
  3861. {
  3862. if (HAS_GMCH_DISPLAY(dev_priv)) {
  3863. if (IS_GM45(dev_priv))
  3864. return gm45_digital_port_connected(dev_priv, port);
  3865. else
  3866. return g4x_digital_port_connected(dev_priv, port);
  3867. }
  3868. if (IS_GEN5(dev_priv))
  3869. return ilk_digital_port_connected(dev_priv, port);
  3870. else if (IS_GEN6(dev_priv))
  3871. return snb_digital_port_connected(dev_priv, port);
  3872. else if (IS_GEN7(dev_priv))
  3873. return ivb_digital_port_connected(dev_priv, port);
  3874. else if (IS_GEN8(dev_priv))
  3875. return bdw_digital_port_connected(dev_priv, port);
  3876. else if (IS_GEN9_LP(dev_priv))
  3877. return bxt_digital_port_connected(dev_priv, port);
  3878. else
  3879. return spt_digital_port_connected(dev_priv, port);
  3880. }
  3881. static struct edid *
  3882. intel_dp_get_edid(struct intel_dp *intel_dp)
  3883. {
  3884. struct intel_connector *intel_connector = intel_dp->attached_connector;
  3885. /* use cached edid if we have one */
  3886. if (intel_connector->edid) {
  3887. /* invalid edid */
  3888. if (IS_ERR(intel_connector->edid))
  3889. return NULL;
  3890. return drm_edid_duplicate(intel_connector->edid);
  3891. } else
  3892. return drm_get_edid(&intel_connector->base,
  3893. &intel_dp->aux.ddc);
  3894. }
  3895. static void
  3896. intel_dp_set_edid(struct intel_dp *intel_dp)
  3897. {
  3898. struct intel_connector *intel_connector = intel_dp->attached_connector;
  3899. struct edid *edid;
  3900. intel_dp_unset_edid(intel_dp);
  3901. edid = intel_dp_get_edid(intel_dp);
  3902. intel_connector->detect_edid = edid;
  3903. intel_dp->has_audio = drm_detect_monitor_audio(edid);
  3904. }
  3905. static void
  3906. intel_dp_unset_edid(struct intel_dp *intel_dp)
  3907. {
  3908. struct intel_connector *intel_connector = intel_dp->attached_connector;
  3909. kfree(intel_connector->detect_edid);
  3910. intel_connector->detect_edid = NULL;
  3911. intel_dp->has_audio = false;
  3912. }
  3913. static int
  3914. intel_dp_long_pulse(struct intel_connector *intel_connector)
  3915. {
  3916. struct drm_connector *connector = &intel_connector->base;
  3917. struct intel_dp *intel_dp = intel_attached_dp(connector);
  3918. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  3919. struct intel_encoder *intel_encoder = &intel_dig_port->base;
  3920. struct drm_device *dev = connector->dev;
  3921. enum drm_connector_status status;
  3922. u8 sink_irq_vector = 0;
  3923. WARN_ON(!drm_modeset_is_locked(&connector->dev->mode_config.connection_mutex));
  3924. intel_display_power_get(to_i915(dev), intel_dp->aux_power_domain);
  3925. /* Can't disconnect eDP, but you can close the lid... */
  3926. if (intel_dp_is_edp(intel_dp))
  3927. status = edp_detect(intel_dp);
  3928. else if (intel_digital_port_connected(to_i915(dev),
  3929. dp_to_dig_port(intel_dp)))
  3930. status = intel_dp_detect_dpcd(intel_dp);
  3931. else
  3932. status = connector_status_disconnected;
  3933. if (status == connector_status_disconnected) {
  3934. memset(&intel_dp->compliance, 0, sizeof(intel_dp->compliance));
  3935. if (intel_dp->is_mst) {
  3936. DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
  3937. intel_dp->is_mst,
  3938. intel_dp->mst_mgr.mst_state);
  3939. intel_dp->is_mst = false;
  3940. drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
  3941. intel_dp->is_mst);
  3942. }
  3943. goto out;
  3944. }
  3945. if (intel_encoder->type != INTEL_OUTPUT_EDP)
  3946. intel_encoder->type = INTEL_OUTPUT_DP;
  3947. DRM_DEBUG_KMS("Display Port TPS3 support: source %s, sink %s\n",
  3948. yesno(intel_dp_source_supports_hbr2(intel_dp)),
  3949. yesno(drm_dp_tps3_supported(intel_dp->dpcd)));
  3950. if (intel_dp->reset_link_params) {
  3951. /* Initial max link lane count */
  3952. intel_dp->max_link_lane_count = intel_dp_max_common_lane_count(intel_dp);
  3953. /* Initial max link rate */
  3954. intel_dp->max_link_rate = intel_dp_max_common_rate(intel_dp);
  3955. intel_dp->reset_link_params = false;
  3956. }
  3957. intel_dp_print_rates(intel_dp);
  3958. drm_dp_read_desc(&intel_dp->aux, &intel_dp->desc,
  3959. drm_dp_is_branch(intel_dp->dpcd));
  3960. intel_dp_configure_mst(intel_dp);
  3961. if (intel_dp->is_mst) {
  3962. /*
  3963. * If we are in MST mode then this connector
  3964. * won't appear connected or have anything
  3965. * with EDID on it
  3966. */
  3967. status = connector_status_disconnected;
  3968. goto out;
  3969. } else {
  3970. /*
  3971. * If display is now connected check links status,
  3972. * there has been known issues of link loss triggerring
  3973. * long pulse.
  3974. *
  3975. * Some sinks (eg. ASUS PB287Q) seem to perform some
  3976. * weird HPD ping pong during modesets. So we can apparently
  3977. * end up with HPD going low during a modeset, and then
  3978. * going back up soon after. And once that happens we must
  3979. * retrain the link to get a picture. That's in case no
  3980. * userspace component reacted to intermittent HPD dip.
  3981. */
  3982. intel_dp_check_link_status(intel_dp);
  3983. }
  3984. /*
  3985. * Clearing NACK and defer counts to get their exact values
  3986. * while reading EDID which are required by Compliance tests
  3987. * 4.2.2.4 and 4.2.2.5
  3988. */
  3989. intel_dp->aux.i2c_nack_count = 0;
  3990. intel_dp->aux.i2c_defer_count = 0;
  3991. intel_dp_set_edid(intel_dp);
  3992. if (intel_dp_is_edp(intel_dp) || intel_connector->detect_edid)
  3993. status = connector_status_connected;
  3994. intel_dp->detect_done = true;
  3995. /* Try to read the source of the interrupt */
  3996. if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
  3997. intel_dp_get_sink_irq(intel_dp, &sink_irq_vector) &&
  3998. sink_irq_vector != 0) {
  3999. /* Clear interrupt source */
  4000. drm_dp_dpcd_writeb(&intel_dp->aux,
  4001. DP_DEVICE_SERVICE_IRQ_VECTOR,
  4002. sink_irq_vector);
  4003. if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
  4004. intel_dp_handle_test_request(intel_dp);
  4005. if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
  4006. DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
  4007. }
  4008. out:
  4009. if (status != connector_status_connected && !intel_dp->is_mst)
  4010. intel_dp_unset_edid(intel_dp);
  4011. intel_display_power_put(to_i915(dev), intel_dp->aux_power_domain);
  4012. return status;
  4013. }
  4014. static int
  4015. intel_dp_detect(struct drm_connector *connector,
  4016. struct drm_modeset_acquire_ctx *ctx,
  4017. bool force)
  4018. {
  4019. struct intel_dp *intel_dp = intel_attached_dp(connector);
  4020. int status = connector->status;
  4021. DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
  4022. connector->base.id, connector->name);
  4023. /* If full detect is not performed yet, do a full detect */
  4024. if (!intel_dp->detect_done)
  4025. status = intel_dp_long_pulse(intel_dp->attached_connector);
  4026. intel_dp->detect_done = false;
  4027. return status;
  4028. }
  4029. static void
  4030. intel_dp_force(struct drm_connector *connector)
  4031. {
  4032. struct intel_dp *intel_dp = intel_attached_dp(connector);
  4033. struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
  4034. struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
  4035. DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
  4036. connector->base.id, connector->name);
  4037. intel_dp_unset_edid(intel_dp);
  4038. if (connector->status != connector_status_connected)
  4039. return;
  4040. intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
  4041. intel_dp_set_edid(intel_dp);
  4042. intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
  4043. if (intel_encoder->type != INTEL_OUTPUT_EDP)
  4044. intel_encoder->type = INTEL_OUTPUT_DP;
  4045. }
  4046. static int intel_dp_get_modes(struct drm_connector *connector)
  4047. {
  4048. struct intel_connector *intel_connector = to_intel_connector(connector);
  4049. struct edid *edid;
  4050. edid = intel_connector->detect_edid;
  4051. if (edid) {
  4052. int ret = intel_connector_update_modes(connector, edid);
  4053. if (ret)
  4054. return ret;
  4055. }
  4056. /* if eDP has no EDID, fall back to fixed mode */
  4057. if (intel_dp_is_edp(intel_attached_dp(connector)) &&
  4058. intel_connector->panel.fixed_mode) {
  4059. struct drm_display_mode *mode;
  4060. mode = drm_mode_duplicate(connector->dev,
  4061. intel_connector->panel.fixed_mode);
  4062. if (mode) {
  4063. drm_mode_probed_add(connector, mode);
  4064. return 1;
  4065. }
  4066. }
  4067. return 0;
  4068. }
  4069. static int
  4070. intel_dp_connector_register(struct drm_connector *connector)
  4071. {
  4072. struct intel_dp *intel_dp = intel_attached_dp(connector);
  4073. int ret;
  4074. ret = intel_connector_register(connector);
  4075. if (ret)
  4076. return ret;
  4077. i915_debugfs_connector_add(connector);
  4078. DRM_DEBUG_KMS("registering %s bus for %s\n",
  4079. intel_dp->aux.name, connector->kdev->kobj.name);
  4080. intel_dp->aux.dev = connector->kdev;
  4081. return drm_dp_aux_register(&intel_dp->aux);
  4082. }
  4083. static void
  4084. intel_dp_connector_unregister(struct drm_connector *connector)
  4085. {
  4086. drm_dp_aux_unregister(&intel_attached_dp(connector)->aux);
  4087. intel_connector_unregister(connector);
  4088. }
  4089. static void
  4090. intel_dp_connector_destroy(struct drm_connector *connector)
  4091. {
  4092. struct intel_connector *intel_connector = to_intel_connector(connector);
  4093. kfree(intel_connector->detect_edid);
  4094. if (!IS_ERR_OR_NULL(intel_connector->edid))
  4095. kfree(intel_connector->edid);
  4096. /*
  4097. * Can't call intel_dp_is_edp() since the encoder may have been
  4098. * destroyed already.
  4099. */
  4100. if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
  4101. intel_panel_fini(&intel_connector->panel);
  4102. drm_connector_cleanup(connector);
  4103. kfree(connector);
  4104. }
  4105. void intel_dp_encoder_destroy(struct drm_encoder *encoder)
  4106. {
  4107. struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
  4108. struct intel_dp *intel_dp = &intel_dig_port->dp;
  4109. intel_dp_mst_encoder_cleanup(intel_dig_port);
  4110. if (intel_dp_is_edp(intel_dp)) {
  4111. cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
  4112. /*
  4113. * vdd might still be enabled do to the delayed vdd off.
  4114. * Make sure vdd is actually turned off here.
  4115. */
  4116. pps_lock(intel_dp);
  4117. edp_panel_vdd_off_sync(intel_dp);
  4118. pps_unlock(intel_dp);
  4119. if (intel_dp->edp_notifier.notifier_call) {
  4120. unregister_reboot_notifier(&intel_dp->edp_notifier);
  4121. intel_dp->edp_notifier.notifier_call = NULL;
  4122. }
  4123. }
  4124. intel_dp_aux_fini(intel_dp);
  4125. drm_encoder_cleanup(encoder);
  4126. kfree(intel_dig_port);
  4127. }
  4128. void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder)
  4129. {
  4130. struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
  4131. if (!intel_dp_is_edp(intel_dp))
  4132. return;
  4133. /*
  4134. * vdd might still be enabled do to the delayed vdd off.
  4135. * Make sure vdd is actually turned off here.
  4136. */
  4137. cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
  4138. pps_lock(intel_dp);
  4139. edp_panel_vdd_off_sync(intel_dp);
  4140. pps_unlock(intel_dp);
  4141. }
  4142. static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp)
  4143. {
  4144. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  4145. struct drm_device *dev = intel_dig_port->base.base.dev;
  4146. struct drm_i915_private *dev_priv = to_i915(dev);
  4147. lockdep_assert_held(&dev_priv->pps_mutex);
  4148. if (!edp_have_panel_vdd(intel_dp))
  4149. return;
  4150. /*
  4151. * The VDD bit needs a power domain reference, so if the bit is
  4152. * already enabled when we boot or resume, grab this reference and
  4153. * schedule a vdd off, so we don't hold on to the reference
  4154. * indefinitely.
  4155. */
  4156. DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n");
  4157. intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
  4158. edp_panel_vdd_schedule_off(intel_dp);
  4159. }
  4160. static enum pipe vlv_active_pipe(struct intel_dp *intel_dp)
  4161. {
  4162. struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
  4163. if ((intel_dp->DP & DP_PORT_EN) == 0)
  4164. return INVALID_PIPE;
  4165. if (IS_CHERRYVIEW(dev_priv))
  4166. return DP_PORT_TO_PIPE_CHV(intel_dp->DP);
  4167. else
  4168. return PORT_TO_PIPE(intel_dp->DP);
  4169. }
  4170. void intel_dp_encoder_reset(struct drm_encoder *encoder)
  4171. {
  4172. struct drm_i915_private *dev_priv = to_i915(encoder->dev);
  4173. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  4174. struct intel_lspcon *lspcon = dp_to_lspcon(intel_dp);
  4175. if (!HAS_DDI(dev_priv))
  4176. intel_dp->DP = I915_READ(intel_dp->output_reg);
  4177. if (lspcon->active)
  4178. lspcon_resume(lspcon);
  4179. intel_dp->reset_link_params = true;
  4180. pps_lock(intel_dp);
  4181. if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
  4182. intel_dp->active_pipe = vlv_active_pipe(intel_dp);
  4183. if (intel_dp_is_edp(intel_dp)) {
  4184. /* Reinit the power sequencer, in case BIOS did something with it. */
  4185. intel_dp_pps_init(encoder->dev, intel_dp);
  4186. intel_edp_panel_vdd_sanitize(intel_dp);
  4187. }
  4188. pps_unlock(intel_dp);
  4189. }
  4190. static const struct drm_connector_funcs intel_dp_connector_funcs = {
  4191. .force = intel_dp_force,
  4192. .fill_modes = drm_helper_probe_single_connector_modes,
  4193. .atomic_get_property = intel_digital_connector_atomic_get_property,
  4194. .atomic_set_property = intel_digital_connector_atomic_set_property,
  4195. .late_register = intel_dp_connector_register,
  4196. .early_unregister = intel_dp_connector_unregister,
  4197. .destroy = intel_dp_connector_destroy,
  4198. .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
  4199. .atomic_duplicate_state = intel_digital_connector_duplicate_state,
  4200. };
  4201. static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
  4202. .detect_ctx = intel_dp_detect,
  4203. .get_modes = intel_dp_get_modes,
  4204. .mode_valid = intel_dp_mode_valid,
  4205. .atomic_check = intel_digital_connector_atomic_check,
  4206. };
  4207. static const struct drm_encoder_funcs intel_dp_enc_funcs = {
  4208. .reset = intel_dp_encoder_reset,
  4209. .destroy = intel_dp_encoder_destroy,
  4210. };
  4211. enum irqreturn
  4212. intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd)
  4213. {
  4214. struct intel_dp *intel_dp = &intel_dig_port->dp;
  4215. struct drm_device *dev = intel_dig_port->base.base.dev;
  4216. struct drm_i915_private *dev_priv = to_i915(dev);
  4217. enum irqreturn ret = IRQ_NONE;
  4218. if (intel_dig_port->base.type != INTEL_OUTPUT_EDP &&
  4219. intel_dig_port->base.type != INTEL_OUTPUT_HDMI)
  4220. intel_dig_port->base.type = INTEL_OUTPUT_DP;
  4221. if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) {
  4222. /*
  4223. * vdd off can generate a long pulse on eDP which
  4224. * would require vdd on to handle it, and thus we
  4225. * would end up in an endless cycle of
  4226. * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..."
  4227. */
  4228. DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n",
  4229. port_name(intel_dig_port->port));
  4230. return IRQ_HANDLED;
  4231. }
  4232. DRM_DEBUG_KMS("got hpd irq on port %c - %s\n",
  4233. port_name(intel_dig_port->port),
  4234. long_hpd ? "long" : "short");
  4235. if (long_hpd) {
  4236. intel_dp->reset_link_params = true;
  4237. intel_dp->detect_done = false;
  4238. return IRQ_NONE;
  4239. }
  4240. intel_display_power_get(dev_priv, intel_dp->aux_power_domain);
  4241. if (intel_dp->is_mst) {
  4242. if (intel_dp_check_mst_status(intel_dp) == -EINVAL) {
  4243. /*
  4244. * If we were in MST mode, and device is not
  4245. * there, get out of MST mode
  4246. */
  4247. DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
  4248. intel_dp->is_mst, intel_dp->mst_mgr.mst_state);
  4249. intel_dp->is_mst = false;
  4250. drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
  4251. intel_dp->is_mst);
  4252. intel_dp->detect_done = false;
  4253. goto put_power;
  4254. }
  4255. }
  4256. if (!intel_dp->is_mst) {
  4257. if (!intel_dp_short_pulse(intel_dp)) {
  4258. intel_dp->detect_done = false;
  4259. goto put_power;
  4260. }
  4261. }
  4262. ret = IRQ_HANDLED;
  4263. put_power:
  4264. intel_display_power_put(dev_priv, intel_dp->aux_power_domain);
  4265. return ret;
  4266. }
  4267. /* check the VBT to see whether the eDP is on another port */
  4268. bool intel_dp_is_port_edp(struct drm_i915_private *dev_priv, enum port port)
  4269. {
  4270. /*
  4271. * eDP not supported on g4x. so bail out early just
  4272. * for a bit extra safety in case the VBT is bonkers.
  4273. */
  4274. if (INTEL_GEN(dev_priv) < 5)
  4275. return false;
  4276. if (INTEL_GEN(dev_priv) < 9 && port == PORT_A)
  4277. return true;
  4278. return intel_bios_is_port_edp(dev_priv, port);
  4279. }
  4280. static void
  4281. intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
  4282. {
  4283. struct drm_i915_private *dev_priv = to_i915(connector->dev);
  4284. intel_attach_force_audio_property(connector);
  4285. intel_attach_broadcast_rgb_property(connector);
  4286. if (intel_dp_is_edp(intel_dp)) {
  4287. u32 allowed_scalers;
  4288. allowed_scalers = BIT(DRM_MODE_SCALE_ASPECT) | BIT(DRM_MODE_SCALE_FULLSCREEN);
  4289. if (!HAS_GMCH_DISPLAY(dev_priv))
  4290. allowed_scalers |= BIT(DRM_MODE_SCALE_CENTER);
  4291. drm_connector_attach_scaling_mode_property(connector, allowed_scalers);
  4292. connector->state->scaling_mode = DRM_MODE_SCALE_ASPECT;
  4293. }
  4294. }
  4295. static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp)
  4296. {
  4297. intel_dp->panel_power_off_time = ktime_get_boottime();
  4298. intel_dp->last_power_on = jiffies;
  4299. intel_dp->last_backlight_off = jiffies;
  4300. }
  4301. static void
  4302. intel_pps_readout_hw_state(struct drm_i915_private *dev_priv,
  4303. struct intel_dp *intel_dp, struct edp_power_seq *seq)
  4304. {
  4305. u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0;
  4306. struct pps_registers regs;
  4307. intel_pps_get_registers(dev_priv, intel_dp, &regs);
  4308. /* Workaround: Need to write PP_CONTROL with the unlock key as
  4309. * the very first thing. */
  4310. pp_ctl = ironlake_get_pp_control(intel_dp);
  4311. pp_on = I915_READ(regs.pp_on);
  4312. pp_off = I915_READ(regs.pp_off);
  4313. if (!IS_GEN9_LP(dev_priv) && !HAS_PCH_CNP(dev_priv)) {
  4314. I915_WRITE(regs.pp_ctrl, pp_ctl);
  4315. pp_div = I915_READ(regs.pp_div);
  4316. }
  4317. /* Pull timing values out of registers */
  4318. seq->t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
  4319. PANEL_POWER_UP_DELAY_SHIFT;
  4320. seq->t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
  4321. PANEL_LIGHT_ON_DELAY_SHIFT;
  4322. seq->t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
  4323. PANEL_LIGHT_OFF_DELAY_SHIFT;
  4324. seq->t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
  4325. PANEL_POWER_DOWN_DELAY_SHIFT;
  4326. if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv)) {
  4327. seq->t11_t12 = ((pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >>
  4328. BXT_POWER_CYCLE_DELAY_SHIFT) * 1000;
  4329. } else {
  4330. seq->t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
  4331. PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
  4332. }
  4333. }
  4334. static void
  4335. intel_pps_dump_state(const char *state_name, const struct edp_power_seq *seq)
  4336. {
  4337. DRM_DEBUG_KMS("%s t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
  4338. state_name,
  4339. seq->t1_t3, seq->t8, seq->t9, seq->t10, seq->t11_t12);
  4340. }
  4341. static void
  4342. intel_pps_verify_state(struct drm_i915_private *dev_priv,
  4343. struct intel_dp *intel_dp)
  4344. {
  4345. struct edp_power_seq hw;
  4346. struct edp_power_seq *sw = &intel_dp->pps_delays;
  4347. intel_pps_readout_hw_state(dev_priv, intel_dp, &hw);
  4348. if (hw.t1_t3 != sw->t1_t3 || hw.t8 != sw->t8 || hw.t9 != sw->t9 ||
  4349. hw.t10 != sw->t10 || hw.t11_t12 != sw->t11_t12) {
  4350. DRM_ERROR("PPS state mismatch\n");
  4351. intel_pps_dump_state("sw", sw);
  4352. intel_pps_dump_state("hw", &hw);
  4353. }
  4354. }
  4355. static void
  4356. intel_dp_init_panel_power_sequencer(struct drm_device *dev,
  4357. struct intel_dp *intel_dp)
  4358. {
  4359. struct drm_i915_private *dev_priv = to_i915(dev);
  4360. struct edp_power_seq cur, vbt, spec,
  4361. *final = &intel_dp->pps_delays;
  4362. lockdep_assert_held(&dev_priv->pps_mutex);
  4363. /* already initialized? */
  4364. if (final->t11_t12 != 0)
  4365. return;
  4366. intel_pps_readout_hw_state(dev_priv, intel_dp, &cur);
  4367. intel_pps_dump_state("cur", &cur);
  4368. vbt = dev_priv->vbt.edp.pps;
  4369. /* On Toshiba Satellite P50-C-18C system the VBT T12 delay
  4370. * of 500ms appears to be too short. Ocassionally the panel
  4371. * just fails to power back on. Increasing the delay to 800ms
  4372. * seems sufficient to avoid this problem.
  4373. */
  4374. if (dev_priv->quirks & QUIRK_INCREASE_T12_DELAY) {
  4375. vbt.t11_t12 = max_t(u16, vbt.t11_t12, 900 * 10);
  4376. DRM_DEBUG_KMS("Increasing T12 panel delay as per the quirk to %d\n",
  4377. vbt.t11_t12);
  4378. }
  4379. /* T11_T12 delay is special and actually in units of 100ms, but zero
  4380. * based in the hw (so we need to add 100 ms). But the sw vbt
  4381. * table multiplies it with 1000 to make it in units of 100usec,
  4382. * too. */
  4383. vbt.t11_t12 += 100 * 10;
  4384. /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
  4385. * our hw here, which are all in 100usec. */
  4386. spec.t1_t3 = 210 * 10;
  4387. spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
  4388. spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
  4389. spec.t10 = 500 * 10;
  4390. /* This one is special and actually in units of 100ms, but zero
  4391. * based in the hw (so we need to add 100 ms). But the sw vbt
  4392. * table multiplies it with 1000 to make it in units of 100usec,
  4393. * too. */
  4394. spec.t11_t12 = (510 + 100) * 10;
  4395. intel_pps_dump_state("vbt", &vbt);
  4396. /* Use the max of the register settings and vbt. If both are
  4397. * unset, fall back to the spec limits. */
  4398. #define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \
  4399. spec.field : \
  4400. max(cur.field, vbt.field))
  4401. assign_final(t1_t3);
  4402. assign_final(t8);
  4403. assign_final(t9);
  4404. assign_final(t10);
  4405. assign_final(t11_t12);
  4406. #undef assign_final
  4407. #define get_delay(field) (DIV_ROUND_UP(final->field, 10))
  4408. intel_dp->panel_power_up_delay = get_delay(t1_t3);
  4409. intel_dp->backlight_on_delay = get_delay(t8);
  4410. intel_dp->backlight_off_delay = get_delay(t9);
  4411. intel_dp->panel_power_down_delay = get_delay(t10);
  4412. intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
  4413. #undef get_delay
  4414. DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
  4415. intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
  4416. intel_dp->panel_power_cycle_delay);
  4417. DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
  4418. intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
  4419. /*
  4420. * We override the HW backlight delays to 1 because we do manual waits
  4421. * on them. For T8, even BSpec recommends doing it. For T9, if we
  4422. * don't do this, we'll end up waiting for the backlight off delay
  4423. * twice: once when we do the manual sleep, and once when we disable
  4424. * the panel and wait for the PP_STATUS bit to become zero.
  4425. */
  4426. final->t8 = 1;
  4427. final->t9 = 1;
  4428. }
  4429. static void
  4430. intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
  4431. struct intel_dp *intel_dp,
  4432. bool force_disable_vdd)
  4433. {
  4434. struct drm_i915_private *dev_priv = to_i915(dev);
  4435. u32 pp_on, pp_off, pp_div, port_sel = 0;
  4436. int div = dev_priv->rawclk_freq / 1000;
  4437. struct pps_registers regs;
  4438. enum port port = dp_to_dig_port(intel_dp)->port;
  4439. const struct edp_power_seq *seq = &intel_dp->pps_delays;
  4440. lockdep_assert_held(&dev_priv->pps_mutex);
  4441. intel_pps_get_registers(dev_priv, intel_dp, &regs);
  4442. /*
  4443. * On some VLV machines the BIOS can leave the VDD
  4444. * enabled even on power seqeuencers which aren't
  4445. * hooked up to any port. This would mess up the
  4446. * power domain tracking the first time we pick
  4447. * one of these power sequencers for use since
  4448. * edp_panel_vdd_on() would notice that the VDD was
  4449. * already on and therefore wouldn't grab the power
  4450. * domain reference. Disable VDD first to avoid this.
  4451. * This also avoids spuriously turning the VDD on as
  4452. * soon as the new power seqeuencer gets initialized.
  4453. */
  4454. if (force_disable_vdd) {
  4455. u32 pp = ironlake_get_pp_control(intel_dp);
  4456. WARN(pp & PANEL_POWER_ON, "Panel power already on\n");
  4457. if (pp & EDP_FORCE_VDD)
  4458. DRM_DEBUG_KMS("VDD already on, disabling first\n");
  4459. pp &= ~EDP_FORCE_VDD;
  4460. I915_WRITE(regs.pp_ctrl, pp);
  4461. }
  4462. pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
  4463. (seq->t8 << PANEL_LIGHT_ON_DELAY_SHIFT);
  4464. pp_off = (seq->t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
  4465. (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
  4466. /* Compute the divisor for the pp clock, simply match the Bspec
  4467. * formula. */
  4468. if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv)) {
  4469. pp_div = I915_READ(regs.pp_ctrl);
  4470. pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK;
  4471. pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
  4472. << BXT_POWER_CYCLE_DELAY_SHIFT);
  4473. } else {
  4474. pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
  4475. pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
  4476. << PANEL_POWER_CYCLE_DELAY_SHIFT);
  4477. }
  4478. /* Haswell doesn't have any port selection bits for the panel
  4479. * power sequencer any more. */
  4480. if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
  4481. port_sel = PANEL_PORT_SELECT_VLV(port);
  4482. } else if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
  4483. if (port == PORT_A)
  4484. port_sel = PANEL_PORT_SELECT_DPA;
  4485. else
  4486. port_sel = PANEL_PORT_SELECT_DPD;
  4487. }
  4488. pp_on |= port_sel;
  4489. I915_WRITE(regs.pp_on, pp_on);
  4490. I915_WRITE(regs.pp_off, pp_off);
  4491. if (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv))
  4492. I915_WRITE(regs.pp_ctrl, pp_div);
  4493. else
  4494. I915_WRITE(regs.pp_div, pp_div);
  4495. DRM_DEBUG_KMS("panel power sequencer register settings: PP_ON %#x, PP_OFF %#x, PP_DIV %#x\n",
  4496. I915_READ(regs.pp_on),
  4497. I915_READ(regs.pp_off),
  4498. (IS_GEN9_LP(dev_priv) || HAS_PCH_CNP(dev_priv)) ?
  4499. (I915_READ(regs.pp_ctrl) & BXT_POWER_CYCLE_DELAY_MASK) :
  4500. I915_READ(regs.pp_div));
  4501. }
  4502. static void intel_dp_pps_init(struct drm_device *dev,
  4503. struct intel_dp *intel_dp)
  4504. {
  4505. struct drm_i915_private *dev_priv = to_i915(dev);
  4506. if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
  4507. vlv_initial_power_sequencer_setup(intel_dp);
  4508. } else {
  4509. intel_dp_init_panel_power_sequencer(dev, intel_dp);
  4510. intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, false);
  4511. }
  4512. }
  4513. /**
  4514. * intel_dp_set_drrs_state - program registers for RR switch to take effect
  4515. * @dev_priv: i915 device
  4516. * @crtc_state: a pointer to the active intel_crtc_state
  4517. * @refresh_rate: RR to be programmed
  4518. *
  4519. * This function gets called when refresh rate (RR) has to be changed from
  4520. * one frequency to another. Switches can be between high and low RR
  4521. * supported by the panel or to any other RR based on media playback (in
  4522. * this case, RR value needs to be passed from user space).
  4523. *
  4524. * The caller of this function needs to take a lock on dev_priv->drrs.
  4525. */
  4526. static void intel_dp_set_drrs_state(struct drm_i915_private *dev_priv,
  4527. const struct intel_crtc_state *crtc_state,
  4528. int refresh_rate)
  4529. {
  4530. struct intel_encoder *encoder;
  4531. struct intel_digital_port *dig_port = NULL;
  4532. struct intel_dp *intel_dp = dev_priv->drrs.dp;
  4533. struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
  4534. enum drrs_refresh_rate_type index = DRRS_HIGH_RR;
  4535. if (refresh_rate <= 0) {
  4536. DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n");
  4537. return;
  4538. }
  4539. if (intel_dp == NULL) {
  4540. DRM_DEBUG_KMS("DRRS not supported.\n");
  4541. return;
  4542. }
  4543. dig_port = dp_to_dig_port(intel_dp);
  4544. encoder = &dig_port->base;
  4545. intel_crtc = to_intel_crtc(encoder->base.crtc);
  4546. if (!intel_crtc) {
  4547. DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n");
  4548. return;
  4549. }
  4550. if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) {
  4551. DRM_DEBUG_KMS("Only Seamless DRRS supported.\n");
  4552. return;
  4553. }
  4554. if (intel_dp->attached_connector->panel.downclock_mode->vrefresh ==
  4555. refresh_rate)
  4556. index = DRRS_LOW_RR;
  4557. if (index == dev_priv->drrs.refresh_rate_type) {
  4558. DRM_DEBUG_KMS(
  4559. "DRRS requested for previously set RR...ignoring\n");
  4560. return;
  4561. }
  4562. if (!crtc_state->base.active) {
  4563. DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n");
  4564. return;
  4565. }
  4566. if (INTEL_GEN(dev_priv) >= 8 && !IS_CHERRYVIEW(dev_priv)) {
  4567. switch (index) {
  4568. case DRRS_HIGH_RR:
  4569. intel_dp_set_m_n(intel_crtc, M1_N1);
  4570. break;
  4571. case DRRS_LOW_RR:
  4572. intel_dp_set_m_n(intel_crtc, M2_N2);
  4573. break;
  4574. case DRRS_MAX_RR:
  4575. default:
  4576. DRM_ERROR("Unsupported refreshrate type\n");
  4577. }
  4578. } else if (INTEL_GEN(dev_priv) > 6) {
  4579. i915_reg_t reg = PIPECONF(crtc_state->cpu_transcoder);
  4580. u32 val;
  4581. val = I915_READ(reg);
  4582. if (index > DRRS_HIGH_RR) {
  4583. if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
  4584. val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV;
  4585. else
  4586. val |= PIPECONF_EDP_RR_MODE_SWITCH;
  4587. } else {
  4588. if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
  4589. val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV;
  4590. else
  4591. val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
  4592. }
  4593. I915_WRITE(reg, val);
  4594. }
  4595. dev_priv->drrs.refresh_rate_type = index;
  4596. DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
  4597. }
  4598. /**
  4599. * intel_edp_drrs_enable - init drrs struct if supported
  4600. * @intel_dp: DP struct
  4601. * @crtc_state: A pointer to the active crtc state.
  4602. *
  4603. * Initializes frontbuffer_bits and drrs.dp
  4604. */
  4605. void intel_edp_drrs_enable(struct intel_dp *intel_dp,
  4606. const struct intel_crtc_state *crtc_state)
  4607. {
  4608. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  4609. struct drm_i915_private *dev_priv = to_i915(dev);
  4610. if (!crtc_state->has_drrs) {
  4611. DRM_DEBUG_KMS("Panel doesn't support DRRS\n");
  4612. return;
  4613. }
  4614. if (dev_priv->psr.enabled) {
  4615. DRM_DEBUG_KMS("PSR enabled. Not enabling DRRS.\n");
  4616. return;
  4617. }
  4618. mutex_lock(&dev_priv->drrs.mutex);
  4619. if (WARN_ON(dev_priv->drrs.dp)) {
  4620. DRM_ERROR("DRRS already enabled\n");
  4621. goto unlock;
  4622. }
  4623. dev_priv->drrs.busy_frontbuffer_bits = 0;
  4624. dev_priv->drrs.dp = intel_dp;
  4625. unlock:
  4626. mutex_unlock(&dev_priv->drrs.mutex);
  4627. }
  4628. /**
  4629. * intel_edp_drrs_disable - Disable DRRS
  4630. * @intel_dp: DP struct
  4631. * @old_crtc_state: Pointer to old crtc_state.
  4632. *
  4633. */
  4634. void intel_edp_drrs_disable(struct intel_dp *intel_dp,
  4635. const struct intel_crtc_state *old_crtc_state)
  4636. {
  4637. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  4638. struct drm_i915_private *dev_priv = to_i915(dev);
  4639. if (!old_crtc_state->has_drrs)
  4640. return;
  4641. mutex_lock(&dev_priv->drrs.mutex);
  4642. if (!dev_priv->drrs.dp) {
  4643. mutex_unlock(&dev_priv->drrs.mutex);
  4644. return;
  4645. }
  4646. if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
  4647. intel_dp_set_drrs_state(dev_priv, old_crtc_state,
  4648. intel_dp->attached_connector->panel.fixed_mode->vrefresh);
  4649. dev_priv->drrs.dp = NULL;
  4650. mutex_unlock(&dev_priv->drrs.mutex);
  4651. cancel_delayed_work_sync(&dev_priv->drrs.work);
  4652. }
  4653. static void intel_edp_drrs_downclock_work(struct work_struct *work)
  4654. {
  4655. struct drm_i915_private *dev_priv =
  4656. container_of(work, typeof(*dev_priv), drrs.work.work);
  4657. struct intel_dp *intel_dp;
  4658. mutex_lock(&dev_priv->drrs.mutex);
  4659. intel_dp = dev_priv->drrs.dp;
  4660. if (!intel_dp)
  4661. goto unlock;
  4662. /*
  4663. * The delayed work can race with an invalidate hence we need to
  4664. * recheck.
  4665. */
  4666. if (dev_priv->drrs.busy_frontbuffer_bits)
  4667. goto unlock;
  4668. if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR) {
  4669. struct drm_crtc *crtc = dp_to_dig_port(intel_dp)->base.base.crtc;
  4670. intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
  4671. intel_dp->attached_connector->panel.downclock_mode->vrefresh);
  4672. }
  4673. unlock:
  4674. mutex_unlock(&dev_priv->drrs.mutex);
  4675. }
  4676. /**
  4677. * intel_edp_drrs_invalidate - Disable Idleness DRRS
  4678. * @dev_priv: i915 device
  4679. * @frontbuffer_bits: frontbuffer plane tracking bits
  4680. *
  4681. * This function gets called everytime rendering on the given planes start.
  4682. * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR).
  4683. *
  4684. * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
  4685. */
  4686. void intel_edp_drrs_invalidate(struct drm_i915_private *dev_priv,
  4687. unsigned int frontbuffer_bits)
  4688. {
  4689. struct drm_crtc *crtc;
  4690. enum pipe pipe;
  4691. if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
  4692. return;
  4693. cancel_delayed_work(&dev_priv->drrs.work);
  4694. mutex_lock(&dev_priv->drrs.mutex);
  4695. if (!dev_priv->drrs.dp) {
  4696. mutex_unlock(&dev_priv->drrs.mutex);
  4697. return;
  4698. }
  4699. crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
  4700. pipe = to_intel_crtc(crtc)->pipe;
  4701. frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
  4702. dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits;
  4703. /* invalidate means busy screen hence upclock */
  4704. if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
  4705. intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
  4706. dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
  4707. mutex_unlock(&dev_priv->drrs.mutex);
  4708. }
  4709. /**
  4710. * intel_edp_drrs_flush - Restart Idleness DRRS
  4711. * @dev_priv: i915 device
  4712. * @frontbuffer_bits: frontbuffer plane tracking bits
  4713. *
  4714. * This function gets called every time rendering on the given planes has
  4715. * completed or flip on a crtc is completed. So DRRS should be upclocked
  4716. * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again,
  4717. * if no other planes are dirty.
  4718. *
  4719. * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
  4720. */
  4721. void intel_edp_drrs_flush(struct drm_i915_private *dev_priv,
  4722. unsigned int frontbuffer_bits)
  4723. {
  4724. struct drm_crtc *crtc;
  4725. enum pipe pipe;
  4726. if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
  4727. return;
  4728. cancel_delayed_work(&dev_priv->drrs.work);
  4729. mutex_lock(&dev_priv->drrs.mutex);
  4730. if (!dev_priv->drrs.dp) {
  4731. mutex_unlock(&dev_priv->drrs.mutex);
  4732. return;
  4733. }
  4734. crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
  4735. pipe = to_intel_crtc(crtc)->pipe;
  4736. frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
  4737. dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits;
  4738. /* flush means busy screen hence upclock */
  4739. if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
  4740. intel_dp_set_drrs_state(dev_priv, to_intel_crtc(crtc)->config,
  4741. dev_priv->drrs.dp->attached_connector->panel.fixed_mode->vrefresh);
  4742. /*
  4743. * flush also means no more activity hence schedule downclock, if all
  4744. * other fbs are quiescent too
  4745. */
  4746. if (!dev_priv->drrs.busy_frontbuffer_bits)
  4747. schedule_delayed_work(&dev_priv->drrs.work,
  4748. msecs_to_jiffies(1000));
  4749. mutex_unlock(&dev_priv->drrs.mutex);
  4750. }
  4751. /**
  4752. * DOC: Display Refresh Rate Switching (DRRS)
  4753. *
  4754. * Display Refresh Rate Switching (DRRS) is a power conservation feature
  4755. * which enables swtching between low and high refresh rates,
  4756. * dynamically, based on the usage scenario. This feature is applicable
  4757. * for internal panels.
  4758. *
  4759. * Indication that the panel supports DRRS is given by the panel EDID, which
  4760. * would list multiple refresh rates for one resolution.
  4761. *
  4762. * DRRS is of 2 types - static and seamless.
  4763. * Static DRRS involves changing refresh rate (RR) by doing a full modeset
  4764. * (may appear as a blink on screen) and is used in dock-undock scenario.
  4765. * Seamless DRRS involves changing RR without any visual effect to the user
  4766. * and can be used during normal system usage. This is done by programming
  4767. * certain registers.
  4768. *
  4769. * Support for static/seamless DRRS may be indicated in the VBT based on
  4770. * inputs from the panel spec.
  4771. *
  4772. * DRRS saves power by switching to low RR based on usage scenarios.
  4773. *
  4774. * The implementation is based on frontbuffer tracking implementation. When
  4775. * there is a disturbance on the screen triggered by user activity or a periodic
  4776. * system activity, DRRS is disabled (RR is changed to high RR). When there is
  4777. * no movement on screen, after a timeout of 1 second, a switch to low RR is
  4778. * made.
  4779. *
  4780. * For integration with frontbuffer tracking code, intel_edp_drrs_invalidate()
  4781. * and intel_edp_drrs_flush() are called.
  4782. *
  4783. * DRRS can be further extended to support other internal panels and also
  4784. * the scenario of video playback wherein RR is set based on the rate
  4785. * requested by userspace.
  4786. */
  4787. /**
  4788. * intel_dp_drrs_init - Init basic DRRS work and mutex.
  4789. * @intel_connector: eDP connector
  4790. * @fixed_mode: preferred mode of panel
  4791. *
  4792. * This function is called only once at driver load to initialize basic
  4793. * DRRS stuff.
  4794. *
  4795. * Returns:
  4796. * Downclock mode if panel supports it, else return NULL.
  4797. * DRRS support is determined by the presence of downclock mode (apart
  4798. * from VBT setting).
  4799. */
  4800. static struct drm_display_mode *
  4801. intel_dp_drrs_init(struct intel_connector *intel_connector,
  4802. struct drm_display_mode *fixed_mode)
  4803. {
  4804. struct drm_connector *connector = &intel_connector->base;
  4805. struct drm_device *dev = connector->dev;
  4806. struct drm_i915_private *dev_priv = to_i915(dev);
  4807. struct drm_display_mode *downclock_mode = NULL;
  4808. INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work);
  4809. mutex_init(&dev_priv->drrs.mutex);
  4810. if (INTEL_GEN(dev_priv) <= 6) {
  4811. DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n");
  4812. return NULL;
  4813. }
  4814. if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) {
  4815. DRM_DEBUG_KMS("VBT doesn't support DRRS\n");
  4816. return NULL;
  4817. }
  4818. downclock_mode = intel_find_panel_downclock
  4819. (dev_priv, fixed_mode, connector);
  4820. if (!downclock_mode) {
  4821. DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n");
  4822. return NULL;
  4823. }
  4824. dev_priv->drrs.type = dev_priv->vbt.drrs_type;
  4825. dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR;
  4826. DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n");
  4827. return downclock_mode;
  4828. }
  4829. static bool intel_edp_init_connector(struct intel_dp *intel_dp,
  4830. struct intel_connector *intel_connector)
  4831. {
  4832. struct drm_connector *connector = &intel_connector->base;
  4833. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  4834. struct intel_encoder *intel_encoder = &intel_dig_port->base;
  4835. struct drm_device *dev = intel_encoder->base.dev;
  4836. struct drm_i915_private *dev_priv = to_i915(dev);
  4837. struct drm_display_mode *fixed_mode = NULL;
  4838. struct drm_display_mode *alt_fixed_mode = NULL;
  4839. struct drm_display_mode *downclock_mode = NULL;
  4840. bool has_dpcd;
  4841. struct drm_display_mode *scan;
  4842. struct edid *edid;
  4843. enum pipe pipe = INVALID_PIPE;
  4844. if (!intel_dp_is_edp(intel_dp))
  4845. return true;
  4846. /*
  4847. * On IBX/CPT we may get here with LVDS already registered. Since the
  4848. * driver uses the only internal power sequencer available for both
  4849. * eDP and LVDS bail out early in this case to prevent interfering
  4850. * with an already powered-on LVDS power sequencer.
  4851. */
  4852. if (intel_get_lvds_encoder(dev)) {
  4853. WARN_ON(!(HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)));
  4854. DRM_INFO("LVDS was detected, not registering eDP\n");
  4855. return false;
  4856. }
  4857. pps_lock(intel_dp);
  4858. intel_dp_init_panel_power_timestamps(intel_dp);
  4859. intel_dp_pps_init(dev, intel_dp);
  4860. intel_edp_panel_vdd_sanitize(intel_dp);
  4861. pps_unlock(intel_dp);
  4862. /* Cache DPCD and EDID for edp. */
  4863. has_dpcd = intel_edp_init_dpcd(intel_dp);
  4864. if (!has_dpcd) {
  4865. /* if this fails, presume the device is a ghost */
  4866. DRM_INFO("failed to retrieve link info, disabling eDP\n");
  4867. goto out_vdd_off;
  4868. }
  4869. mutex_lock(&dev->mode_config.mutex);
  4870. edid = drm_get_edid(connector, &intel_dp->aux.ddc);
  4871. if (edid) {
  4872. if (drm_add_edid_modes(connector, edid)) {
  4873. drm_mode_connector_update_edid_property(connector,
  4874. edid);
  4875. drm_edid_to_eld(connector, edid);
  4876. } else {
  4877. kfree(edid);
  4878. edid = ERR_PTR(-EINVAL);
  4879. }
  4880. } else {
  4881. edid = ERR_PTR(-ENOENT);
  4882. }
  4883. intel_connector->edid = edid;
  4884. /* prefer fixed mode from EDID if available, save an alt mode also */
  4885. list_for_each_entry(scan, &connector->probed_modes, head) {
  4886. if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
  4887. fixed_mode = drm_mode_duplicate(dev, scan);
  4888. downclock_mode = intel_dp_drrs_init(
  4889. intel_connector, fixed_mode);
  4890. } else if (!alt_fixed_mode) {
  4891. alt_fixed_mode = drm_mode_duplicate(dev, scan);
  4892. }
  4893. }
  4894. /* fallback to VBT if available for eDP */
  4895. if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
  4896. fixed_mode = drm_mode_duplicate(dev,
  4897. dev_priv->vbt.lfp_lvds_vbt_mode);
  4898. if (fixed_mode) {
  4899. fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
  4900. connector->display_info.width_mm = fixed_mode->width_mm;
  4901. connector->display_info.height_mm = fixed_mode->height_mm;
  4902. }
  4903. }
  4904. mutex_unlock(&dev->mode_config.mutex);
  4905. if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
  4906. intel_dp->edp_notifier.notifier_call = edp_notify_handler;
  4907. register_reboot_notifier(&intel_dp->edp_notifier);
  4908. /*
  4909. * Figure out the current pipe for the initial backlight setup.
  4910. * If the current pipe isn't valid, try the PPS pipe, and if that
  4911. * fails just assume pipe A.
  4912. */
  4913. pipe = vlv_active_pipe(intel_dp);
  4914. if (pipe != PIPE_A && pipe != PIPE_B)
  4915. pipe = intel_dp->pps_pipe;
  4916. if (pipe != PIPE_A && pipe != PIPE_B)
  4917. pipe = PIPE_A;
  4918. DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n",
  4919. pipe_name(pipe));
  4920. }
  4921. intel_panel_init(&intel_connector->panel, fixed_mode, alt_fixed_mode,
  4922. downclock_mode);
  4923. intel_connector->panel.backlight.power = intel_edp_backlight_power;
  4924. intel_panel_setup_backlight(connector, pipe);
  4925. return true;
  4926. out_vdd_off:
  4927. cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
  4928. /*
  4929. * vdd might still be enabled do to the delayed vdd off.
  4930. * Make sure vdd is actually turned off here.
  4931. */
  4932. pps_lock(intel_dp);
  4933. edp_panel_vdd_off_sync(intel_dp);
  4934. pps_unlock(intel_dp);
  4935. return false;
  4936. }
  4937. /* Set up the hotplug pin and aux power domain. */
  4938. static void
  4939. intel_dp_init_connector_port_info(struct intel_digital_port *intel_dig_port)
  4940. {
  4941. struct intel_encoder *encoder = &intel_dig_port->base;
  4942. struct intel_dp *intel_dp = &intel_dig_port->dp;
  4943. encoder->hpd_pin = intel_hpd_pin(intel_dig_port->port);
  4944. switch (intel_dig_port->port) {
  4945. case PORT_A:
  4946. intel_dp->aux_power_domain = POWER_DOMAIN_AUX_A;
  4947. break;
  4948. case PORT_B:
  4949. intel_dp->aux_power_domain = POWER_DOMAIN_AUX_B;
  4950. break;
  4951. case PORT_C:
  4952. intel_dp->aux_power_domain = POWER_DOMAIN_AUX_C;
  4953. break;
  4954. case PORT_D:
  4955. intel_dp->aux_power_domain = POWER_DOMAIN_AUX_D;
  4956. break;
  4957. case PORT_E:
  4958. /* FIXME: Check VBT for actual wiring of PORT E */
  4959. intel_dp->aux_power_domain = POWER_DOMAIN_AUX_D;
  4960. break;
  4961. default:
  4962. MISSING_CASE(intel_dig_port->port);
  4963. }
  4964. }
  4965. static void intel_dp_modeset_retry_work_fn(struct work_struct *work)
  4966. {
  4967. struct intel_connector *intel_connector;
  4968. struct drm_connector *connector;
  4969. intel_connector = container_of(work, typeof(*intel_connector),
  4970. modeset_retry_work);
  4971. connector = &intel_connector->base;
  4972. DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", connector->base.id,
  4973. connector->name);
  4974. /* Grab the locks before changing connector property*/
  4975. mutex_lock(&connector->dev->mode_config.mutex);
  4976. /* Set connector link status to BAD and send a Uevent to notify
  4977. * userspace to do a modeset.
  4978. */
  4979. drm_mode_connector_set_link_status_property(connector,
  4980. DRM_MODE_LINK_STATUS_BAD);
  4981. mutex_unlock(&connector->dev->mode_config.mutex);
  4982. /* Send Hotplug uevent so userspace can reprobe */
  4983. drm_kms_helper_hotplug_event(connector->dev);
  4984. }
  4985. bool
  4986. intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
  4987. struct intel_connector *intel_connector)
  4988. {
  4989. struct drm_connector *connector = &intel_connector->base;
  4990. struct intel_dp *intel_dp = &intel_dig_port->dp;
  4991. struct intel_encoder *intel_encoder = &intel_dig_port->base;
  4992. struct drm_device *dev = intel_encoder->base.dev;
  4993. struct drm_i915_private *dev_priv = to_i915(dev);
  4994. enum port port = intel_dig_port->port;
  4995. int type;
  4996. /* Initialize the work for modeset in case of link train failure */
  4997. INIT_WORK(&intel_connector->modeset_retry_work,
  4998. intel_dp_modeset_retry_work_fn);
  4999. if (WARN(intel_dig_port->max_lanes < 1,
  5000. "Not enough lanes (%d) for DP on port %c\n",
  5001. intel_dig_port->max_lanes, port_name(port)))
  5002. return false;
  5003. intel_dp_set_source_rates(intel_dp);
  5004. intel_dp->reset_link_params = true;
  5005. intel_dp->pps_pipe = INVALID_PIPE;
  5006. intel_dp->active_pipe = INVALID_PIPE;
  5007. /* intel_dp vfuncs */
  5008. if (INTEL_GEN(dev_priv) >= 9)
  5009. intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider;
  5010. else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
  5011. intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
  5012. else if (HAS_PCH_SPLIT(dev_priv))
  5013. intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
  5014. else
  5015. intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider;
  5016. if (INTEL_GEN(dev_priv) >= 9)
  5017. intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl;
  5018. else
  5019. intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl;
  5020. if (HAS_DDI(dev_priv))
  5021. intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain;
  5022. /* Preserve the current hw state. */
  5023. intel_dp->DP = I915_READ(intel_dp->output_reg);
  5024. intel_dp->attached_connector = intel_connector;
  5025. if (intel_dp_is_port_edp(dev_priv, port))
  5026. type = DRM_MODE_CONNECTOR_eDP;
  5027. else
  5028. type = DRM_MODE_CONNECTOR_DisplayPort;
  5029. if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
  5030. intel_dp->active_pipe = vlv_active_pipe(intel_dp);
  5031. /*
  5032. * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
  5033. * for DP the encoder type can be set by the caller to
  5034. * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
  5035. */
  5036. if (type == DRM_MODE_CONNECTOR_eDP)
  5037. intel_encoder->type = INTEL_OUTPUT_EDP;
  5038. /* eDP only on port B and/or C on vlv/chv */
  5039. if (WARN_ON((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
  5040. intel_dp_is_edp(intel_dp) &&
  5041. port != PORT_B && port != PORT_C))
  5042. return false;
  5043. DRM_DEBUG_KMS("Adding %s connector on port %c\n",
  5044. type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
  5045. port_name(port));
  5046. drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
  5047. drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
  5048. connector->interlace_allowed = true;
  5049. connector->doublescan_allowed = 0;
  5050. intel_dp_init_connector_port_info(intel_dig_port);
  5051. intel_dp_aux_init(intel_dp);
  5052. INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
  5053. edp_panel_vdd_work);
  5054. intel_connector_attach_encoder(intel_connector, intel_encoder);
  5055. if (HAS_DDI(dev_priv))
  5056. intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
  5057. else
  5058. intel_connector->get_hw_state = intel_connector_get_hw_state;
  5059. /* init MST on ports that can support it */
  5060. if (HAS_DP_MST(dev_priv) && !intel_dp_is_edp(intel_dp) &&
  5061. (port == PORT_B || port == PORT_C || port == PORT_D))
  5062. intel_dp_mst_encoder_init(intel_dig_port,
  5063. intel_connector->base.base.id);
  5064. if (!intel_edp_init_connector(intel_dp, intel_connector)) {
  5065. intel_dp_aux_fini(intel_dp);
  5066. intel_dp_mst_encoder_cleanup(intel_dig_port);
  5067. goto fail;
  5068. }
  5069. intel_dp_add_properties(intel_dp, connector);
  5070. /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
  5071. * 0xd. Failure to do so will result in spurious interrupts being
  5072. * generated on the port when a cable is not attached.
  5073. */
  5074. if (IS_G4X(dev_priv) && !IS_GM45(dev_priv)) {
  5075. u32 temp = I915_READ(PEG_BAND_GAP_DATA);
  5076. I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
  5077. }
  5078. return true;
  5079. fail:
  5080. drm_connector_cleanup(connector);
  5081. return false;
  5082. }
  5083. bool intel_dp_init(struct drm_i915_private *dev_priv,
  5084. i915_reg_t output_reg,
  5085. enum port port)
  5086. {
  5087. struct intel_digital_port *intel_dig_port;
  5088. struct intel_encoder *intel_encoder;
  5089. struct drm_encoder *encoder;
  5090. struct intel_connector *intel_connector;
  5091. intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
  5092. if (!intel_dig_port)
  5093. return false;
  5094. intel_connector = intel_connector_alloc();
  5095. if (!intel_connector)
  5096. goto err_connector_alloc;
  5097. intel_encoder = &intel_dig_port->base;
  5098. encoder = &intel_encoder->base;
  5099. if (drm_encoder_init(&dev_priv->drm, &intel_encoder->base,
  5100. &intel_dp_enc_funcs, DRM_MODE_ENCODER_TMDS,
  5101. "DP %c", port_name(port)))
  5102. goto err_encoder_init;
  5103. intel_encoder->compute_config = intel_dp_compute_config;
  5104. intel_encoder->get_hw_state = intel_dp_get_hw_state;
  5105. intel_encoder->get_config = intel_dp_get_config;
  5106. intel_encoder->suspend = intel_dp_encoder_suspend;
  5107. if (IS_CHERRYVIEW(dev_priv)) {
  5108. intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable;
  5109. intel_encoder->pre_enable = chv_pre_enable_dp;
  5110. intel_encoder->enable = vlv_enable_dp;
  5111. intel_encoder->disable = vlv_disable_dp;
  5112. intel_encoder->post_disable = chv_post_disable_dp;
  5113. intel_encoder->post_pll_disable = chv_dp_post_pll_disable;
  5114. } else if (IS_VALLEYVIEW(dev_priv)) {
  5115. intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
  5116. intel_encoder->pre_enable = vlv_pre_enable_dp;
  5117. intel_encoder->enable = vlv_enable_dp;
  5118. intel_encoder->disable = vlv_disable_dp;
  5119. intel_encoder->post_disable = vlv_post_disable_dp;
  5120. } else if (INTEL_GEN(dev_priv) >= 5) {
  5121. intel_encoder->pre_enable = g4x_pre_enable_dp;
  5122. intel_encoder->enable = g4x_enable_dp;
  5123. intel_encoder->disable = ilk_disable_dp;
  5124. intel_encoder->post_disable = ilk_post_disable_dp;
  5125. } else {
  5126. intel_encoder->pre_enable = g4x_pre_enable_dp;
  5127. intel_encoder->enable = g4x_enable_dp;
  5128. intel_encoder->disable = g4x_disable_dp;
  5129. }
  5130. intel_dig_port->port = port;
  5131. intel_dig_port->dp.output_reg = output_reg;
  5132. intel_dig_port->max_lanes = 4;
  5133. intel_encoder->type = INTEL_OUTPUT_DP;
  5134. intel_encoder->power_domain = intel_port_to_power_domain(port);
  5135. if (IS_CHERRYVIEW(dev_priv)) {
  5136. if (port == PORT_D)
  5137. intel_encoder->crtc_mask = 1 << 2;
  5138. else
  5139. intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
  5140. } else {
  5141. intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
  5142. }
  5143. intel_encoder->cloneable = 0;
  5144. intel_encoder->port = port;
  5145. intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
  5146. dev_priv->hotplug.irq_port[port] = intel_dig_port;
  5147. if (port != PORT_A)
  5148. intel_infoframe_init(intel_dig_port);
  5149. if (!intel_dp_init_connector(intel_dig_port, intel_connector))
  5150. goto err_init_connector;
  5151. return true;
  5152. err_init_connector:
  5153. drm_encoder_cleanup(encoder);
  5154. err_encoder_init:
  5155. kfree(intel_connector);
  5156. err_connector_alloc:
  5157. kfree(intel_dig_port);
  5158. return false;
  5159. }
  5160. void intel_dp_mst_suspend(struct drm_device *dev)
  5161. {
  5162. struct drm_i915_private *dev_priv = to_i915(dev);
  5163. int i;
  5164. /* disable MST */
  5165. for (i = 0; i < I915_MAX_PORTS; i++) {
  5166. struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
  5167. if (!intel_dig_port || !intel_dig_port->dp.can_mst)
  5168. continue;
  5169. if (intel_dig_port->dp.is_mst)
  5170. drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr);
  5171. }
  5172. }
  5173. void intel_dp_mst_resume(struct drm_device *dev)
  5174. {
  5175. struct drm_i915_private *dev_priv = to_i915(dev);
  5176. int i;
  5177. for (i = 0; i < I915_MAX_PORTS; i++) {
  5178. struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
  5179. int ret;
  5180. if (!intel_dig_port || !intel_dig_port->dp.can_mst)
  5181. continue;
  5182. ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr);
  5183. if (ret)
  5184. intel_dp_check_mst_status(&intel_dig_port->dp);
  5185. }
  5186. }