intel_dp.c 180 KB

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