intel_dp.c 157 KB

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