intel_dp.c 166 KB

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