intel_dp.c 162 KB

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