intel_dp.c 136 KB

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