intel_dp.c 159 KB

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