intel_dp.c 137 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849
  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. static void
  710. intel_dp_set_m2_n2(struct intel_crtc *crtc, struct intel_link_m_n *m_n)
  711. {
  712. struct drm_device *dev = crtc->base.dev;
  713. struct drm_i915_private *dev_priv = dev->dev_private;
  714. enum transcoder transcoder = crtc->config.cpu_transcoder;
  715. I915_WRITE(PIPE_DATA_M2(transcoder),
  716. TU_SIZE(m_n->tu) | m_n->gmch_m);
  717. I915_WRITE(PIPE_DATA_N2(transcoder), m_n->gmch_n);
  718. I915_WRITE(PIPE_LINK_M2(transcoder), m_n->link_m);
  719. I915_WRITE(PIPE_LINK_N2(transcoder), m_n->link_n);
  720. }
  721. bool
  722. intel_dp_compute_config(struct intel_encoder *encoder,
  723. struct intel_crtc_config *pipe_config)
  724. {
  725. struct drm_device *dev = encoder->base.dev;
  726. struct drm_i915_private *dev_priv = dev->dev_private;
  727. struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
  728. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  729. enum port port = dp_to_dig_port(intel_dp)->port;
  730. struct intel_crtc *intel_crtc = encoder->new_crtc;
  731. struct intel_connector *intel_connector = intel_dp->attached_connector;
  732. int lane_count, clock;
  733. int min_lane_count = 1;
  734. int max_lane_count = intel_dp_max_lane_count(intel_dp);
  735. /* Conveniently, the link BW constants become indices with a shift...*/
  736. int min_clock = 0;
  737. int max_clock = intel_dp_max_link_bw(intel_dp) >> 3;
  738. int bpp, mode_rate;
  739. static int bws[] = { DP_LINK_BW_1_62, DP_LINK_BW_2_7, DP_LINK_BW_5_4 };
  740. int link_avail, link_clock;
  741. if (HAS_PCH_SPLIT(dev) && !HAS_DDI(dev) && port != PORT_A)
  742. pipe_config->has_pch_encoder = true;
  743. pipe_config->has_dp_encoder = true;
  744. pipe_config->has_audio = intel_dp->has_audio;
  745. if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
  746. intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
  747. adjusted_mode);
  748. if (!HAS_PCH_SPLIT(dev))
  749. intel_gmch_panel_fitting(intel_crtc, pipe_config,
  750. intel_connector->panel.fitting_mode);
  751. else
  752. intel_pch_panel_fitting(intel_crtc, pipe_config,
  753. intel_connector->panel.fitting_mode);
  754. }
  755. if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
  756. return false;
  757. DRM_DEBUG_KMS("DP link computation with max lane count %i "
  758. "max bw %02x pixel clock %iKHz\n",
  759. max_lane_count, bws[max_clock],
  760. adjusted_mode->crtc_clock);
  761. /* Walk through all bpp values. Luckily they're all nicely spaced with 2
  762. * bpc in between. */
  763. bpp = pipe_config->pipe_bpp;
  764. if (is_edp(intel_dp)) {
  765. if (dev_priv->vbt.edp_bpp && dev_priv->vbt.edp_bpp < bpp) {
  766. DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
  767. dev_priv->vbt.edp_bpp);
  768. bpp = dev_priv->vbt.edp_bpp;
  769. }
  770. if (IS_BROADWELL(dev)) {
  771. /* Yes, it's an ugly hack. */
  772. min_lane_count = max_lane_count;
  773. DRM_DEBUG_KMS("forcing lane count to max (%u) on BDW\n",
  774. min_lane_count);
  775. } else if (dev_priv->vbt.edp_lanes) {
  776. min_lane_count = min(dev_priv->vbt.edp_lanes,
  777. max_lane_count);
  778. DRM_DEBUG_KMS("using min %u lanes per VBT\n",
  779. min_lane_count);
  780. }
  781. if (dev_priv->vbt.edp_rate) {
  782. min_clock = min(dev_priv->vbt.edp_rate >> 3, max_clock);
  783. DRM_DEBUG_KMS("using min %02x link bw per VBT\n",
  784. bws[min_clock]);
  785. }
  786. }
  787. for (; bpp >= 6*3; bpp -= 2*3) {
  788. mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
  789. bpp);
  790. for (clock = min_clock; clock <= max_clock; clock++) {
  791. for (lane_count = min_lane_count; lane_count <= max_lane_count; lane_count <<= 1) {
  792. link_clock = drm_dp_bw_code_to_link_rate(bws[clock]);
  793. link_avail = intel_dp_max_data_rate(link_clock,
  794. lane_count);
  795. if (mode_rate <= link_avail) {
  796. goto found;
  797. }
  798. }
  799. }
  800. }
  801. return false;
  802. found:
  803. if (intel_dp->color_range_auto) {
  804. /*
  805. * See:
  806. * CEA-861-E - 5.1 Default Encoding Parameters
  807. * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
  808. */
  809. if (bpp != 18 && drm_match_cea_mode(adjusted_mode) > 1)
  810. intel_dp->color_range = DP_COLOR_RANGE_16_235;
  811. else
  812. intel_dp->color_range = 0;
  813. }
  814. if (intel_dp->color_range)
  815. pipe_config->limited_color_range = true;
  816. intel_dp->link_bw = bws[clock];
  817. intel_dp->lane_count = lane_count;
  818. pipe_config->pipe_bpp = bpp;
  819. pipe_config->port_clock = drm_dp_bw_code_to_link_rate(intel_dp->link_bw);
  820. DRM_DEBUG_KMS("DP link bw %02x lane count %d clock %d bpp %d\n",
  821. intel_dp->link_bw, intel_dp->lane_count,
  822. pipe_config->port_clock, bpp);
  823. DRM_DEBUG_KMS("DP link bw required %i available %i\n",
  824. mode_rate, link_avail);
  825. intel_link_compute_m_n(bpp, lane_count,
  826. adjusted_mode->crtc_clock,
  827. pipe_config->port_clock,
  828. &pipe_config->dp_m_n);
  829. if (intel_connector->panel.downclock_mode != NULL &&
  830. intel_dp->drrs_state.type == SEAMLESS_DRRS_SUPPORT) {
  831. intel_link_compute_m_n(bpp, lane_count,
  832. intel_connector->panel.downclock_mode->clock,
  833. pipe_config->port_clock,
  834. &pipe_config->dp_m2_n2);
  835. }
  836. if (HAS_DDI(dev))
  837. hsw_dp_set_ddi_pll_sel(pipe_config, intel_dp->link_bw);
  838. else
  839. intel_dp_set_clock(encoder, pipe_config, intel_dp->link_bw);
  840. return true;
  841. }
  842. static void ironlake_set_pll_cpu_edp(struct intel_dp *intel_dp)
  843. {
  844. struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
  845. struct intel_crtc *crtc = to_intel_crtc(dig_port->base.base.crtc);
  846. struct drm_device *dev = crtc->base.dev;
  847. struct drm_i915_private *dev_priv = dev->dev_private;
  848. u32 dpa_ctl;
  849. DRM_DEBUG_KMS("eDP PLL enable for clock %d\n", crtc->config.port_clock);
  850. dpa_ctl = I915_READ(DP_A);
  851. dpa_ctl &= ~DP_PLL_FREQ_MASK;
  852. if (crtc->config.port_clock == 162000) {
  853. /* For a long time we've carried around a ILK-DevA w/a for the
  854. * 160MHz clock. If we're really unlucky, it's still required.
  855. */
  856. DRM_DEBUG_KMS("160MHz cpu eDP clock, might need ilk devA w/a\n");
  857. dpa_ctl |= DP_PLL_FREQ_160MHZ;
  858. intel_dp->DP |= DP_PLL_FREQ_160MHZ;
  859. } else {
  860. dpa_ctl |= DP_PLL_FREQ_270MHZ;
  861. intel_dp->DP |= DP_PLL_FREQ_270MHZ;
  862. }
  863. I915_WRITE(DP_A, dpa_ctl);
  864. POSTING_READ(DP_A);
  865. udelay(500);
  866. }
  867. static void intel_dp_prepare(struct intel_encoder *encoder)
  868. {
  869. struct drm_device *dev = encoder->base.dev;
  870. struct drm_i915_private *dev_priv = dev->dev_private;
  871. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  872. enum port port = dp_to_dig_port(intel_dp)->port;
  873. struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
  874. struct drm_display_mode *adjusted_mode = &crtc->config.adjusted_mode;
  875. /*
  876. * There are four kinds of DP registers:
  877. *
  878. * IBX PCH
  879. * SNB CPU
  880. * IVB CPU
  881. * CPT PCH
  882. *
  883. * IBX PCH and CPU are the same for almost everything,
  884. * except that the CPU DP PLL is configured in this
  885. * register
  886. *
  887. * CPT PCH is quite different, having many bits moved
  888. * to the TRANS_DP_CTL register instead. That
  889. * configuration happens (oddly) in ironlake_pch_enable
  890. */
  891. /* Preserve the BIOS-computed detected bit. This is
  892. * supposed to be read-only.
  893. */
  894. intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
  895. /* Handle DP bits in common between all three register formats */
  896. intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
  897. intel_dp->DP |= DP_PORT_WIDTH(intel_dp->lane_count);
  898. if (crtc->config.has_audio) {
  899. DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
  900. pipe_name(crtc->pipe));
  901. intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
  902. intel_write_eld(&encoder->base, adjusted_mode);
  903. }
  904. /* Split out the IBX/CPU vs CPT settings */
  905. if (port == PORT_A && IS_GEN7(dev) && !IS_VALLEYVIEW(dev)) {
  906. if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
  907. intel_dp->DP |= DP_SYNC_HS_HIGH;
  908. if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
  909. intel_dp->DP |= DP_SYNC_VS_HIGH;
  910. intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
  911. if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
  912. intel_dp->DP |= DP_ENHANCED_FRAMING;
  913. intel_dp->DP |= crtc->pipe << 29;
  914. } else if (!HAS_PCH_CPT(dev) || port == PORT_A) {
  915. if (!HAS_PCH_SPLIT(dev) && !IS_VALLEYVIEW(dev))
  916. intel_dp->DP |= intel_dp->color_range;
  917. if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
  918. intel_dp->DP |= DP_SYNC_HS_HIGH;
  919. if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
  920. intel_dp->DP |= DP_SYNC_VS_HIGH;
  921. intel_dp->DP |= DP_LINK_TRAIN_OFF;
  922. if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
  923. intel_dp->DP |= DP_ENHANCED_FRAMING;
  924. if (!IS_CHERRYVIEW(dev)) {
  925. if (crtc->pipe == 1)
  926. intel_dp->DP |= DP_PIPEB_SELECT;
  927. } else {
  928. intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe);
  929. }
  930. } else {
  931. intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
  932. }
  933. }
  934. #define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
  935. #define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
  936. #define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
  937. #define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
  938. #define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
  939. #define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
  940. static void wait_panel_status(struct intel_dp *intel_dp,
  941. u32 mask,
  942. u32 value)
  943. {
  944. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  945. struct drm_i915_private *dev_priv = dev->dev_private;
  946. u32 pp_stat_reg, pp_ctrl_reg;
  947. pp_stat_reg = _pp_stat_reg(intel_dp);
  948. pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
  949. DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
  950. mask, value,
  951. I915_READ(pp_stat_reg),
  952. I915_READ(pp_ctrl_reg));
  953. if (_wait_for((I915_READ(pp_stat_reg) & mask) == value, 5000, 10)) {
  954. DRM_ERROR("Panel status timeout: status %08x control %08x\n",
  955. I915_READ(pp_stat_reg),
  956. I915_READ(pp_ctrl_reg));
  957. }
  958. DRM_DEBUG_KMS("Wait complete\n");
  959. }
  960. static void wait_panel_on(struct intel_dp *intel_dp)
  961. {
  962. DRM_DEBUG_KMS("Wait for panel power on\n");
  963. wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
  964. }
  965. static void wait_panel_off(struct intel_dp *intel_dp)
  966. {
  967. DRM_DEBUG_KMS("Wait for panel power off time\n");
  968. wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
  969. }
  970. static void wait_panel_power_cycle(struct intel_dp *intel_dp)
  971. {
  972. DRM_DEBUG_KMS("Wait for panel power cycle\n");
  973. /* When we disable the VDD override bit last we have to do the manual
  974. * wait. */
  975. wait_remaining_ms_from_jiffies(intel_dp->last_power_cycle,
  976. intel_dp->panel_power_cycle_delay);
  977. wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
  978. }
  979. static void wait_backlight_on(struct intel_dp *intel_dp)
  980. {
  981. wait_remaining_ms_from_jiffies(intel_dp->last_power_on,
  982. intel_dp->backlight_on_delay);
  983. }
  984. static void edp_wait_backlight_off(struct intel_dp *intel_dp)
  985. {
  986. wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off,
  987. intel_dp->backlight_off_delay);
  988. }
  989. /* Read the current pp_control value, unlocking the register if it
  990. * is locked
  991. */
  992. static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
  993. {
  994. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  995. struct drm_i915_private *dev_priv = dev->dev_private;
  996. u32 control;
  997. control = I915_READ(_pp_ctrl_reg(intel_dp));
  998. control &= ~PANEL_UNLOCK_MASK;
  999. control |= PANEL_UNLOCK_REGS;
  1000. return control;
  1001. }
  1002. static bool _edp_panel_vdd_on(struct intel_dp *intel_dp)
  1003. {
  1004. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  1005. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  1006. struct intel_encoder *intel_encoder = &intel_dig_port->base;
  1007. struct drm_i915_private *dev_priv = dev->dev_private;
  1008. enum intel_display_power_domain power_domain;
  1009. u32 pp;
  1010. u32 pp_stat_reg, pp_ctrl_reg;
  1011. bool need_to_disable = !intel_dp->want_panel_vdd;
  1012. if (!is_edp(intel_dp))
  1013. return false;
  1014. intel_dp->want_panel_vdd = true;
  1015. if (edp_have_panel_vdd(intel_dp))
  1016. return need_to_disable;
  1017. power_domain = intel_display_port_power_domain(intel_encoder);
  1018. intel_display_power_get(dev_priv, power_domain);
  1019. DRM_DEBUG_KMS("Turning eDP VDD on\n");
  1020. if (!edp_have_panel_power(intel_dp))
  1021. wait_panel_power_cycle(intel_dp);
  1022. pp = ironlake_get_pp_control(intel_dp);
  1023. pp |= EDP_FORCE_VDD;
  1024. pp_stat_reg = _pp_stat_reg(intel_dp);
  1025. pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
  1026. I915_WRITE(pp_ctrl_reg, pp);
  1027. POSTING_READ(pp_ctrl_reg);
  1028. DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
  1029. I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
  1030. /*
  1031. * If the panel wasn't on, delay before accessing aux channel
  1032. */
  1033. if (!edp_have_panel_power(intel_dp)) {
  1034. DRM_DEBUG_KMS("eDP was not running\n");
  1035. msleep(intel_dp->panel_power_up_delay);
  1036. }
  1037. return need_to_disable;
  1038. }
  1039. void intel_edp_panel_vdd_on(struct intel_dp *intel_dp)
  1040. {
  1041. if (is_edp(intel_dp)) {
  1042. bool vdd = _edp_panel_vdd_on(intel_dp);
  1043. WARN(!vdd, "eDP VDD already requested on\n");
  1044. }
  1045. }
  1046. static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp)
  1047. {
  1048. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  1049. struct drm_i915_private *dev_priv = dev->dev_private;
  1050. u32 pp;
  1051. u32 pp_stat_reg, pp_ctrl_reg;
  1052. WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
  1053. if (!intel_dp->want_panel_vdd && edp_have_panel_vdd(intel_dp)) {
  1054. struct intel_digital_port *intel_dig_port =
  1055. dp_to_dig_port(intel_dp);
  1056. struct intel_encoder *intel_encoder = &intel_dig_port->base;
  1057. enum intel_display_power_domain power_domain;
  1058. DRM_DEBUG_KMS("Turning eDP VDD off\n");
  1059. pp = ironlake_get_pp_control(intel_dp);
  1060. pp &= ~EDP_FORCE_VDD;
  1061. pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
  1062. pp_stat_reg = _pp_stat_reg(intel_dp);
  1063. I915_WRITE(pp_ctrl_reg, pp);
  1064. POSTING_READ(pp_ctrl_reg);
  1065. /* Make sure sequencer is idle before allowing subsequent activity */
  1066. DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
  1067. I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
  1068. if ((pp & POWER_TARGET_ON) == 0)
  1069. intel_dp->last_power_cycle = jiffies;
  1070. power_domain = intel_display_port_power_domain(intel_encoder);
  1071. intel_display_power_put(dev_priv, power_domain);
  1072. }
  1073. }
  1074. static void edp_panel_vdd_work(struct work_struct *__work)
  1075. {
  1076. struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
  1077. struct intel_dp, panel_vdd_work);
  1078. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  1079. drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
  1080. edp_panel_vdd_off_sync(intel_dp);
  1081. drm_modeset_unlock(&dev->mode_config.connection_mutex);
  1082. }
  1083. static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp)
  1084. {
  1085. unsigned long delay;
  1086. /*
  1087. * Queue the timer to fire a long time from now (relative to the power
  1088. * down delay) to keep the panel power up across a sequence of
  1089. * operations.
  1090. */
  1091. delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5);
  1092. schedule_delayed_work(&intel_dp->panel_vdd_work, delay);
  1093. }
  1094. static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
  1095. {
  1096. if (!is_edp(intel_dp))
  1097. return;
  1098. WARN(!intel_dp->want_panel_vdd, "eDP VDD not forced on");
  1099. intel_dp->want_panel_vdd = false;
  1100. if (sync)
  1101. edp_panel_vdd_off_sync(intel_dp);
  1102. else
  1103. edp_panel_vdd_schedule_off(intel_dp);
  1104. }
  1105. void intel_edp_panel_on(struct intel_dp *intel_dp)
  1106. {
  1107. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  1108. struct drm_i915_private *dev_priv = dev->dev_private;
  1109. u32 pp;
  1110. u32 pp_ctrl_reg;
  1111. if (!is_edp(intel_dp))
  1112. return;
  1113. DRM_DEBUG_KMS("Turn eDP power on\n");
  1114. if (edp_have_panel_power(intel_dp)) {
  1115. DRM_DEBUG_KMS("eDP power already on\n");
  1116. return;
  1117. }
  1118. wait_panel_power_cycle(intel_dp);
  1119. pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
  1120. pp = ironlake_get_pp_control(intel_dp);
  1121. if (IS_GEN5(dev)) {
  1122. /* ILK workaround: disable reset around power sequence */
  1123. pp &= ~PANEL_POWER_RESET;
  1124. I915_WRITE(pp_ctrl_reg, pp);
  1125. POSTING_READ(pp_ctrl_reg);
  1126. }
  1127. pp |= POWER_TARGET_ON;
  1128. if (!IS_GEN5(dev))
  1129. pp |= PANEL_POWER_RESET;
  1130. I915_WRITE(pp_ctrl_reg, pp);
  1131. POSTING_READ(pp_ctrl_reg);
  1132. wait_panel_on(intel_dp);
  1133. intel_dp->last_power_on = jiffies;
  1134. if (IS_GEN5(dev)) {
  1135. pp |= PANEL_POWER_RESET; /* restore panel reset bit */
  1136. I915_WRITE(pp_ctrl_reg, pp);
  1137. POSTING_READ(pp_ctrl_reg);
  1138. }
  1139. }
  1140. void intel_edp_panel_off(struct intel_dp *intel_dp)
  1141. {
  1142. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  1143. struct intel_encoder *intel_encoder = &intel_dig_port->base;
  1144. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  1145. struct drm_i915_private *dev_priv = dev->dev_private;
  1146. enum intel_display_power_domain power_domain;
  1147. u32 pp;
  1148. u32 pp_ctrl_reg;
  1149. if (!is_edp(intel_dp))
  1150. return;
  1151. DRM_DEBUG_KMS("Turn eDP power off\n");
  1152. WARN(!intel_dp->want_panel_vdd, "Need VDD to turn off panel\n");
  1153. pp = ironlake_get_pp_control(intel_dp);
  1154. /* We need to switch off panel power _and_ force vdd, for otherwise some
  1155. * panels get very unhappy and cease to work. */
  1156. pp &= ~(POWER_TARGET_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
  1157. EDP_BLC_ENABLE);
  1158. pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
  1159. intel_dp->want_panel_vdd = false;
  1160. I915_WRITE(pp_ctrl_reg, pp);
  1161. POSTING_READ(pp_ctrl_reg);
  1162. intel_dp->last_power_cycle = jiffies;
  1163. wait_panel_off(intel_dp);
  1164. /* We got a reference when we enabled the VDD. */
  1165. power_domain = intel_display_port_power_domain(intel_encoder);
  1166. intel_display_power_put(dev_priv, power_domain);
  1167. }
  1168. void intel_edp_backlight_on(struct intel_dp *intel_dp)
  1169. {
  1170. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  1171. struct drm_device *dev = intel_dig_port->base.base.dev;
  1172. struct drm_i915_private *dev_priv = dev->dev_private;
  1173. u32 pp;
  1174. u32 pp_ctrl_reg;
  1175. if (!is_edp(intel_dp))
  1176. return;
  1177. DRM_DEBUG_KMS("\n");
  1178. intel_panel_enable_backlight(intel_dp->attached_connector);
  1179. /*
  1180. * If we enable the backlight right away following a panel power
  1181. * on, we may see slight flicker as the panel syncs with the eDP
  1182. * link. So delay a bit to make sure the image is solid before
  1183. * allowing it to appear.
  1184. */
  1185. wait_backlight_on(intel_dp);
  1186. pp = ironlake_get_pp_control(intel_dp);
  1187. pp |= EDP_BLC_ENABLE;
  1188. pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
  1189. I915_WRITE(pp_ctrl_reg, pp);
  1190. POSTING_READ(pp_ctrl_reg);
  1191. }
  1192. void intel_edp_backlight_off(struct intel_dp *intel_dp)
  1193. {
  1194. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  1195. struct drm_i915_private *dev_priv = dev->dev_private;
  1196. u32 pp;
  1197. u32 pp_ctrl_reg;
  1198. if (!is_edp(intel_dp))
  1199. return;
  1200. DRM_DEBUG_KMS("\n");
  1201. pp = ironlake_get_pp_control(intel_dp);
  1202. pp &= ~EDP_BLC_ENABLE;
  1203. pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
  1204. I915_WRITE(pp_ctrl_reg, pp);
  1205. POSTING_READ(pp_ctrl_reg);
  1206. intel_dp->last_backlight_off = jiffies;
  1207. edp_wait_backlight_off(intel_dp);
  1208. intel_panel_disable_backlight(intel_dp->attached_connector);
  1209. }
  1210. static void ironlake_edp_pll_on(struct intel_dp *intel_dp)
  1211. {
  1212. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  1213. struct drm_crtc *crtc = intel_dig_port->base.base.crtc;
  1214. struct drm_device *dev = crtc->dev;
  1215. struct drm_i915_private *dev_priv = dev->dev_private;
  1216. u32 dpa_ctl;
  1217. assert_pipe_disabled(dev_priv,
  1218. to_intel_crtc(crtc)->pipe);
  1219. DRM_DEBUG_KMS("\n");
  1220. dpa_ctl = I915_READ(DP_A);
  1221. WARN(dpa_ctl & DP_PLL_ENABLE, "dp pll on, should be off\n");
  1222. WARN(dpa_ctl & DP_PORT_EN, "dp port still on, should be off\n");
  1223. /* We don't adjust intel_dp->DP while tearing down the link, to
  1224. * facilitate link retraining (e.g. after hotplug). Hence clear all
  1225. * enable bits here to ensure that we don't enable too much. */
  1226. intel_dp->DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
  1227. intel_dp->DP |= DP_PLL_ENABLE;
  1228. I915_WRITE(DP_A, intel_dp->DP);
  1229. POSTING_READ(DP_A);
  1230. udelay(200);
  1231. }
  1232. static void ironlake_edp_pll_off(struct intel_dp *intel_dp)
  1233. {
  1234. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  1235. struct drm_crtc *crtc = intel_dig_port->base.base.crtc;
  1236. struct drm_device *dev = crtc->dev;
  1237. struct drm_i915_private *dev_priv = dev->dev_private;
  1238. u32 dpa_ctl;
  1239. assert_pipe_disabled(dev_priv,
  1240. to_intel_crtc(crtc)->pipe);
  1241. dpa_ctl = I915_READ(DP_A);
  1242. WARN((dpa_ctl & DP_PLL_ENABLE) == 0,
  1243. "dp pll off, should be on\n");
  1244. WARN(dpa_ctl & DP_PORT_EN, "dp port still on, should be off\n");
  1245. /* We can't rely on the value tracked for the DP register in
  1246. * intel_dp->DP because link_down must not change that (otherwise link
  1247. * re-training will fail. */
  1248. dpa_ctl &= ~DP_PLL_ENABLE;
  1249. I915_WRITE(DP_A, dpa_ctl);
  1250. POSTING_READ(DP_A);
  1251. udelay(200);
  1252. }
  1253. /* If the sink supports it, try to set the power state appropriately */
  1254. void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
  1255. {
  1256. int ret, i;
  1257. /* Should have a valid DPCD by this point */
  1258. if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
  1259. return;
  1260. if (mode != DRM_MODE_DPMS_ON) {
  1261. ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
  1262. DP_SET_POWER_D3);
  1263. if (ret != 1)
  1264. DRM_DEBUG_DRIVER("failed to write sink power state\n");
  1265. } else {
  1266. /*
  1267. * When turning on, we need to retry for 1ms to give the sink
  1268. * time to wake up.
  1269. */
  1270. for (i = 0; i < 3; i++) {
  1271. ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
  1272. DP_SET_POWER_D0);
  1273. if (ret == 1)
  1274. break;
  1275. msleep(1);
  1276. }
  1277. }
  1278. }
  1279. static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
  1280. enum pipe *pipe)
  1281. {
  1282. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  1283. enum port port = dp_to_dig_port(intel_dp)->port;
  1284. struct drm_device *dev = encoder->base.dev;
  1285. struct drm_i915_private *dev_priv = dev->dev_private;
  1286. enum intel_display_power_domain power_domain;
  1287. u32 tmp;
  1288. power_domain = intel_display_port_power_domain(encoder);
  1289. if (!intel_display_power_enabled(dev_priv, power_domain))
  1290. return false;
  1291. tmp = I915_READ(intel_dp->output_reg);
  1292. if (!(tmp & DP_PORT_EN))
  1293. return false;
  1294. if (port == PORT_A && IS_GEN7(dev) && !IS_VALLEYVIEW(dev)) {
  1295. *pipe = PORT_TO_PIPE_CPT(tmp);
  1296. } else if (IS_CHERRYVIEW(dev)) {
  1297. *pipe = DP_PORT_TO_PIPE_CHV(tmp);
  1298. } else if (!HAS_PCH_CPT(dev) || port == PORT_A) {
  1299. *pipe = PORT_TO_PIPE(tmp);
  1300. } else {
  1301. u32 trans_sel;
  1302. u32 trans_dp;
  1303. int i;
  1304. switch (intel_dp->output_reg) {
  1305. case PCH_DP_B:
  1306. trans_sel = TRANS_DP_PORT_SEL_B;
  1307. break;
  1308. case PCH_DP_C:
  1309. trans_sel = TRANS_DP_PORT_SEL_C;
  1310. break;
  1311. case PCH_DP_D:
  1312. trans_sel = TRANS_DP_PORT_SEL_D;
  1313. break;
  1314. default:
  1315. return true;
  1316. }
  1317. for_each_pipe(i) {
  1318. trans_dp = I915_READ(TRANS_DP_CTL(i));
  1319. if ((trans_dp & TRANS_DP_PORT_SEL_MASK) == trans_sel) {
  1320. *pipe = i;
  1321. return true;
  1322. }
  1323. }
  1324. DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
  1325. intel_dp->output_reg);
  1326. }
  1327. return true;
  1328. }
  1329. static void intel_dp_get_config(struct intel_encoder *encoder,
  1330. struct intel_crtc_config *pipe_config)
  1331. {
  1332. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  1333. u32 tmp, flags = 0;
  1334. struct drm_device *dev = encoder->base.dev;
  1335. struct drm_i915_private *dev_priv = dev->dev_private;
  1336. enum port port = dp_to_dig_port(intel_dp)->port;
  1337. struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
  1338. int dotclock;
  1339. tmp = I915_READ(intel_dp->output_reg);
  1340. if (tmp & DP_AUDIO_OUTPUT_ENABLE)
  1341. pipe_config->has_audio = true;
  1342. if ((port == PORT_A) || !HAS_PCH_CPT(dev)) {
  1343. if (tmp & DP_SYNC_HS_HIGH)
  1344. flags |= DRM_MODE_FLAG_PHSYNC;
  1345. else
  1346. flags |= DRM_MODE_FLAG_NHSYNC;
  1347. if (tmp & DP_SYNC_VS_HIGH)
  1348. flags |= DRM_MODE_FLAG_PVSYNC;
  1349. else
  1350. flags |= DRM_MODE_FLAG_NVSYNC;
  1351. } else {
  1352. tmp = I915_READ(TRANS_DP_CTL(crtc->pipe));
  1353. if (tmp & TRANS_DP_HSYNC_ACTIVE_HIGH)
  1354. flags |= DRM_MODE_FLAG_PHSYNC;
  1355. else
  1356. flags |= DRM_MODE_FLAG_NHSYNC;
  1357. if (tmp & TRANS_DP_VSYNC_ACTIVE_HIGH)
  1358. flags |= DRM_MODE_FLAG_PVSYNC;
  1359. else
  1360. flags |= DRM_MODE_FLAG_NVSYNC;
  1361. }
  1362. pipe_config->adjusted_mode.flags |= flags;
  1363. pipe_config->has_dp_encoder = true;
  1364. intel_dp_get_m_n(crtc, pipe_config);
  1365. if (port == PORT_A) {
  1366. if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_160MHZ)
  1367. pipe_config->port_clock = 162000;
  1368. else
  1369. pipe_config->port_clock = 270000;
  1370. }
  1371. dotclock = intel_dotclock_calculate(pipe_config->port_clock,
  1372. &pipe_config->dp_m_n);
  1373. if (HAS_PCH_SPLIT(dev_priv->dev) && port != PORT_A)
  1374. ironlake_check_encoder_dotclock(pipe_config, dotclock);
  1375. pipe_config->adjusted_mode.crtc_clock = dotclock;
  1376. if (is_edp(intel_dp) && dev_priv->vbt.edp_bpp &&
  1377. pipe_config->pipe_bpp > dev_priv->vbt.edp_bpp) {
  1378. /*
  1379. * This is a big fat ugly hack.
  1380. *
  1381. * Some machines in UEFI boot mode provide us a VBT that has 18
  1382. * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
  1383. * unknown we fail to light up. Yet the same BIOS boots up with
  1384. * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
  1385. * max, not what it tells us to use.
  1386. *
  1387. * Note: This will still be broken if the eDP panel is not lit
  1388. * up by the BIOS, and thus we can't get the mode at module
  1389. * load.
  1390. */
  1391. DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
  1392. pipe_config->pipe_bpp, dev_priv->vbt.edp_bpp);
  1393. dev_priv->vbt.edp_bpp = pipe_config->pipe_bpp;
  1394. }
  1395. }
  1396. static bool is_edp_psr(struct intel_dp *intel_dp)
  1397. {
  1398. return intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED;
  1399. }
  1400. static bool intel_edp_is_psr_enabled(struct drm_device *dev)
  1401. {
  1402. struct drm_i915_private *dev_priv = dev->dev_private;
  1403. if (!HAS_PSR(dev))
  1404. return false;
  1405. return I915_READ(EDP_PSR_CTL(dev)) & EDP_PSR_ENABLE;
  1406. }
  1407. static void intel_edp_psr_write_vsc(struct intel_dp *intel_dp,
  1408. struct edp_vsc_psr *vsc_psr)
  1409. {
  1410. struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
  1411. struct drm_device *dev = dig_port->base.base.dev;
  1412. struct drm_i915_private *dev_priv = dev->dev_private;
  1413. struct intel_crtc *crtc = to_intel_crtc(dig_port->base.base.crtc);
  1414. u32 ctl_reg = HSW_TVIDEO_DIP_CTL(crtc->config.cpu_transcoder);
  1415. u32 data_reg = HSW_TVIDEO_DIP_VSC_DATA(crtc->config.cpu_transcoder);
  1416. uint32_t *data = (uint32_t *) vsc_psr;
  1417. unsigned int i;
  1418. /* As per BSPec (Pipe Video Data Island Packet), we need to disable
  1419. the video DIP being updated before program video DIP data buffer
  1420. registers for DIP being updated. */
  1421. I915_WRITE(ctl_reg, 0);
  1422. POSTING_READ(ctl_reg);
  1423. for (i = 0; i < VIDEO_DIP_VSC_DATA_SIZE; i += 4) {
  1424. if (i < sizeof(struct edp_vsc_psr))
  1425. I915_WRITE(data_reg + i, *data++);
  1426. else
  1427. I915_WRITE(data_reg + i, 0);
  1428. }
  1429. I915_WRITE(ctl_reg, VIDEO_DIP_ENABLE_VSC_HSW);
  1430. POSTING_READ(ctl_reg);
  1431. }
  1432. static void intel_edp_psr_setup(struct intel_dp *intel_dp)
  1433. {
  1434. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  1435. struct drm_i915_private *dev_priv = dev->dev_private;
  1436. struct edp_vsc_psr psr_vsc;
  1437. /* Prepare VSC packet as per EDP 1.3 spec, Table 3.10 */
  1438. memset(&psr_vsc, 0, sizeof(psr_vsc));
  1439. psr_vsc.sdp_header.HB0 = 0;
  1440. psr_vsc.sdp_header.HB1 = 0x7;
  1441. psr_vsc.sdp_header.HB2 = 0x2;
  1442. psr_vsc.sdp_header.HB3 = 0x8;
  1443. intel_edp_psr_write_vsc(intel_dp, &psr_vsc);
  1444. /* Avoid continuous PSR exit by masking memup and hpd */
  1445. I915_WRITE(EDP_PSR_DEBUG_CTL(dev), EDP_PSR_DEBUG_MASK_MEMUP |
  1446. EDP_PSR_DEBUG_MASK_HPD | EDP_PSR_DEBUG_MASK_LPSP);
  1447. }
  1448. static void intel_edp_psr_enable_sink(struct intel_dp *intel_dp)
  1449. {
  1450. struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
  1451. struct drm_device *dev = dig_port->base.base.dev;
  1452. struct drm_i915_private *dev_priv = dev->dev_private;
  1453. uint32_t aux_clock_divider;
  1454. int precharge = 0x3;
  1455. int msg_size = 5; /* Header(4) + Message(1) */
  1456. bool only_standby = false;
  1457. aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, 0);
  1458. if (IS_BROADWELL(dev) && dig_port->port != PORT_A)
  1459. only_standby = true;
  1460. /* Enable PSR in sink */
  1461. if (intel_dp->psr_dpcd[1] & DP_PSR_NO_TRAIN_ON_EXIT || only_standby)
  1462. drm_dp_dpcd_writeb(&intel_dp->aux, DP_PSR_EN_CFG,
  1463. DP_PSR_ENABLE & ~DP_PSR_MAIN_LINK_ACTIVE);
  1464. else
  1465. drm_dp_dpcd_writeb(&intel_dp->aux, DP_PSR_EN_CFG,
  1466. DP_PSR_ENABLE | DP_PSR_MAIN_LINK_ACTIVE);
  1467. /* Setup AUX registers */
  1468. I915_WRITE(EDP_PSR_AUX_DATA1(dev), EDP_PSR_DPCD_COMMAND);
  1469. I915_WRITE(EDP_PSR_AUX_DATA2(dev), EDP_PSR_DPCD_NORMAL_OPERATION);
  1470. I915_WRITE(EDP_PSR_AUX_CTL(dev),
  1471. DP_AUX_CH_CTL_TIME_OUT_400us |
  1472. (msg_size << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
  1473. (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
  1474. (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT));
  1475. }
  1476. static void intel_edp_psr_enable_source(struct intel_dp *intel_dp)
  1477. {
  1478. struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
  1479. struct drm_device *dev = dig_port->base.base.dev;
  1480. struct drm_i915_private *dev_priv = dev->dev_private;
  1481. uint32_t max_sleep_time = 0x1f;
  1482. uint32_t idle_frames = 1;
  1483. uint32_t val = 0x0;
  1484. const uint32_t link_entry_time = EDP_PSR_MIN_LINK_ENTRY_TIME_8_LINES;
  1485. bool only_standby = false;
  1486. if (IS_BROADWELL(dev) && dig_port->port != PORT_A)
  1487. only_standby = true;
  1488. if (intel_dp->psr_dpcd[1] & DP_PSR_NO_TRAIN_ON_EXIT || only_standby) {
  1489. val |= EDP_PSR_LINK_STANDBY;
  1490. val |= EDP_PSR_TP2_TP3_TIME_0us;
  1491. val |= EDP_PSR_TP1_TIME_0us;
  1492. val |= EDP_PSR_SKIP_AUX_EXIT;
  1493. val |= IS_BROADWELL(dev) ? BDW_PSR_SINGLE_FRAME : 0;
  1494. } else
  1495. val |= EDP_PSR_LINK_DISABLE;
  1496. I915_WRITE(EDP_PSR_CTL(dev), val |
  1497. (IS_BROADWELL(dev) ? 0 : link_entry_time) |
  1498. max_sleep_time << EDP_PSR_MAX_SLEEP_TIME_SHIFT |
  1499. idle_frames << EDP_PSR_IDLE_FRAME_SHIFT |
  1500. EDP_PSR_ENABLE);
  1501. }
  1502. static bool intel_edp_psr_match_conditions(struct intel_dp *intel_dp)
  1503. {
  1504. struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
  1505. struct drm_device *dev = dig_port->base.base.dev;
  1506. struct drm_i915_private *dev_priv = dev->dev_private;
  1507. struct drm_crtc *crtc = dig_port->base.base.crtc;
  1508. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1509. lockdep_assert_held(&dev_priv->psr.lock);
  1510. WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
  1511. WARN_ON(!drm_modeset_is_locked(&crtc->mutex));
  1512. dev_priv->psr.source_ok = false;
  1513. if (IS_HASWELL(dev) && dig_port->port != PORT_A) {
  1514. DRM_DEBUG_KMS("HSW ties PSR to DDI A (eDP)\n");
  1515. return false;
  1516. }
  1517. if (!i915.enable_psr) {
  1518. DRM_DEBUG_KMS("PSR disable by flag\n");
  1519. return false;
  1520. }
  1521. /* Below limitations aren't valid for Broadwell */
  1522. if (IS_BROADWELL(dev))
  1523. goto out;
  1524. if (I915_READ(HSW_STEREO_3D_CTL(intel_crtc->config.cpu_transcoder)) &
  1525. S3D_ENABLE) {
  1526. DRM_DEBUG_KMS("PSR condition failed: Stereo 3D is Enabled\n");
  1527. return false;
  1528. }
  1529. if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
  1530. DRM_DEBUG_KMS("PSR condition failed: Interlaced is Enabled\n");
  1531. return false;
  1532. }
  1533. out:
  1534. dev_priv->psr.source_ok = true;
  1535. return true;
  1536. }
  1537. static void intel_edp_psr_do_enable(struct intel_dp *intel_dp)
  1538. {
  1539. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  1540. struct drm_device *dev = intel_dig_port->base.base.dev;
  1541. struct drm_i915_private *dev_priv = dev->dev_private;
  1542. WARN_ON(I915_READ(EDP_PSR_CTL(dev)) & EDP_PSR_ENABLE);
  1543. WARN_ON(dev_priv->psr.active);
  1544. lockdep_assert_held(&dev_priv->psr.lock);
  1545. /* Enable PSR on the panel */
  1546. intel_edp_psr_enable_sink(intel_dp);
  1547. /* Enable PSR on the host */
  1548. intel_edp_psr_enable_source(intel_dp);
  1549. dev_priv->psr.active = true;
  1550. }
  1551. void intel_edp_psr_enable(struct intel_dp *intel_dp)
  1552. {
  1553. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  1554. struct drm_i915_private *dev_priv = dev->dev_private;
  1555. if (!HAS_PSR(dev)) {
  1556. DRM_DEBUG_KMS("PSR not supported on this platform\n");
  1557. return;
  1558. }
  1559. if (!is_edp_psr(intel_dp)) {
  1560. DRM_DEBUG_KMS("PSR not supported by this panel\n");
  1561. return;
  1562. }
  1563. mutex_lock(&dev_priv->psr.lock);
  1564. if (dev_priv->psr.enabled) {
  1565. DRM_DEBUG_KMS("PSR already in use\n");
  1566. mutex_unlock(&dev_priv->psr.lock);
  1567. return;
  1568. }
  1569. dev_priv->psr.busy_frontbuffer_bits = 0;
  1570. /* Setup PSR once */
  1571. intel_edp_psr_setup(intel_dp);
  1572. if (intel_edp_psr_match_conditions(intel_dp))
  1573. dev_priv->psr.enabled = intel_dp;
  1574. mutex_unlock(&dev_priv->psr.lock);
  1575. }
  1576. void intel_edp_psr_disable(struct intel_dp *intel_dp)
  1577. {
  1578. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  1579. struct drm_i915_private *dev_priv = dev->dev_private;
  1580. mutex_lock(&dev_priv->psr.lock);
  1581. if (!dev_priv->psr.enabled) {
  1582. mutex_unlock(&dev_priv->psr.lock);
  1583. return;
  1584. }
  1585. if (dev_priv->psr.active) {
  1586. I915_WRITE(EDP_PSR_CTL(dev),
  1587. I915_READ(EDP_PSR_CTL(dev)) & ~EDP_PSR_ENABLE);
  1588. /* Wait till PSR is idle */
  1589. if (_wait_for((I915_READ(EDP_PSR_STATUS_CTL(dev)) &
  1590. EDP_PSR_STATUS_STATE_MASK) == 0, 2000, 10))
  1591. DRM_ERROR("Timed out waiting for PSR Idle State\n");
  1592. dev_priv->psr.active = false;
  1593. } else {
  1594. WARN_ON(I915_READ(EDP_PSR_CTL(dev)) & EDP_PSR_ENABLE);
  1595. }
  1596. dev_priv->psr.enabled = NULL;
  1597. mutex_unlock(&dev_priv->psr.lock);
  1598. cancel_delayed_work_sync(&dev_priv->psr.work);
  1599. }
  1600. static void intel_edp_psr_work(struct work_struct *work)
  1601. {
  1602. struct drm_i915_private *dev_priv =
  1603. container_of(work, typeof(*dev_priv), psr.work.work);
  1604. struct intel_dp *intel_dp = dev_priv->psr.enabled;
  1605. mutex_lock(&dev_priv->psr.lock);
  1606. intel_dp = dev_priv->psr.enabled;
  1607. if (!intel_dp)
  1608. goto unlock;
  1609. /*
  1610. * The delayed work can race with an invalidate hence we need to
  1611. * recheck. Since psr_flush first clears this and then reschedules we
  1612. * won't ever miss a flush when bailing out here.
  1613. */
  1614. if (dev_priv->psr.busy_frontbuffer_bits)
  1615. goto unlock;
  1616. intel_edp_psr_do_enable(intel_dp);
  1617. unlock:
  1618. mutex_unlock(&dev_priv->psr.lock);
  1619. }
  1620. static void intel_edp_psr_do_exit(struct drm_device *dev)
  1621. {
  1622. struct drm_i915_private *dev_priv = dev->dev_private;
  1623. if (dev_priv->psr.active) {
  1624. u32 val = I915_READ(EDP_PSR_CTL(dev));
  1625. WARN_ON(!(val & EDP_PSR_ENABLE));
  1626. I915_WRITE(EDP_PSR_CTL(dev), val & ~EDP_PSR_ENABLE);
  1627. dev_priv->psr.active = false;
  1628. }
  1629. }
  1630. void intel_edp_psr_invalidate(struct drm_device *dev,
  1631. unsigned frontbuffer_bits)
  1632. {
  1633. struct drm_i915_private *dev_priv = dev->dev_private;
  1634. struct drm_crtc *crtc;
  1635. enum pipe pipe;
  1636. mutex_lock(&dev_priv->psr.lock);
  1637. if (!dev_priv->psr.enabled) {
  1638. mutex_unlock(&dev_priv->psr.lock);
  1639. return;
  1640. }
  1641. crtc = dp_to_dig_port(dev_priv->psr.enabled)->base.base.crtc;
  1642. pipe = to_intel_crtc(crtc)->pipe;
  1643. intel_edp_psr_do_exit(dev);
  1644. frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
  1645. dev_priv->psr.busy_frontbuffer_bits |= frontbuffer_bits;
  1646. mutex_unlock(&dev_priv->psr.lock);
  1647. }
  1648. void intel_edp_psr_flush(struct drm_device *dev,
  1649. unsigned frontbuffer_bits)
  1650. {
  1651. struct drm_i915_private *dev_priv = dev->dev_private;
  1652. struct drm_crtc *crtc;
  1653. enum pipe pipe;
  1654. mutex_lock(&dev_priv->psr.lock);
  1655. if (!dev_priv->psr.enabled) {
  1656. mutex_unlock(&dev_priv->psr.lock);
  1657. return;
  1658. }
  1659. crtc = dp_to_dig_port(dev_priv->psr.enabled)->base.base.crtc;
  1660. pipe = to_intel_crtc(crtc)->pipe;
  1661. dev_priv->psr.busy_frontbuffer_bits &= ~frontbuffer_bits;
  1662. /*
  1663. * On Haswell sprite plane updates don't result in a psr invalidating
  1664. * signal in the hardware. Which means we need to manually fake this in
  1665. * software for all flushes, not just when we've seen a preceding
  1666. * invalidation through frontbuffer rendering.
  1667. */
  1668. if (IS_HASWELL(dev) &&
  1669. (frontbuffer_bits & INTEL_FRONTBUFFER_SPRITE(pipe)))
  1670. intel_edp_psr_do_exit(dev);
  1671. if (!dev_priv->psr.active && !dev_priv->psr.busy_frontbuffer_bits)
  1672. schedule_delayed_work(&dev_priv->psr.work,
  1673. msecs_to_jiffies(100));
  1674. mutex_unlock(&dev_priv->psr.lock);
  1675. }
  1676. void intel_edp_psr_init(struct drm_device *dev)
  1677. {
  1678. struct drm_i915_private *dev_priv = dev->dev_private;
  1679. INIT_DELAYED_WORK(&dev_priv->psr.work, intel_edp_psr_work);
  1680. mutex_init(&dev_priv->psr.lock);
  1681. }
  1682. static void intel_disable_dp(struct intel_encoder *encoder)
  1683. {
  1684. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  1685. enum port port = dp_to_dig_port(intel_dp)->port;
  1686. struct drm_device *dev = encoder->base.dev;
  1687. /* Make sure the panel is off before trying to change the mode. But also
  1688. * ensure that we have vdd while we switch off the panel. */
  1689. intel_edp_panel_vdd_on(intel_dp);
  1690. intel_edp_backlight_off(intel_dp);
  1691. intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
  1692. intel_edp_panel_off(intel_dp);
  1693. /* cpu edp my only be disable _after_ the cpu pipe/plane is disabled. */
  1694. if (!(port == PORT_A || IS_VALLEYVIEW(dev)))
  1695. intel_dp_link_down(intel_dp);
  1696. }
  1697. static void g4x_post_disable_dp(struct intel_encoder *encoder)
  1698. {
  1699. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  1700. enum port port = dp_to_dig_port(intel_dp)->port;
  1701. if (port != PORT_A)
  1702. return;
  1703. intel_dp_link_down(intel_dp);
  1704. ironlake_edp_pll_off(intel_dp);
  1705. }
  1706. static void vlv_post_disable_dp(struct intel_encoder *encoder)
  1707. {
  1708. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  1709. intel_dp_link_down(intel_dp);
  1710. }
  1711. static void chv_post_disable_dp(struct intel_encoder *encoder)
  1712. {
  1713. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  1714. struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
  1715. struct drm_device *dev = encoder->base.dev;
  1716. struct drm_i915_private *dev_priv = dev->dev_private;
  1717. struct intel_crtc *intel_crtc =
  1718. to_intel_crtc(encoder->base.crtc);
  1719. enum dpio_channel ch = vlv_dport_to_channel(dport);
  1720. enum pipe pipe = intel_crtc->pipe;
  1721. u32 val;
  1722. intel_dp_link_down(intel_dp);
  1723. mutex_lock(&dev_priv->dpio_lock);
  1724. /* Propagate soft reset to data lane reset */
  1725. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW1(ch));
  1726. val |= CHV_PCS_REQ_SOFTRESET_EN;
  1727. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW1(ch), val);
  1728. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW1(ch));
  1729. val |= CHV_PCS_REQ_SOFTRESET_EN;
  1730. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW1(ch), val);
  1731. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW0(ch));
  1732. val &= ~(DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET);
  1733. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW0(ch), val);
  1734. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW0(ch));
  1735. val &= ~(DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET);
  1736. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW0(ch), val);
  1737. mutex_unlock(&dev_priv->dpio_lock);
  1738. }
  1739. static void intel_enable_dp(struct intel_encoder *encoder)
  1740. {
  1741. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  1742. struct drm_device *dev = encoder->base.dev;
  1743. struct drm_i915_private *dev_priv = dev->dev_private;
  1744. uint32_t dp_reg = I915_READ(intel_dp->output_reg);
  1745. if (WARN_ON(dp_reg & DP_PORT_EN))
  1746. return;
  1747. intel_edp_panel_vdd_on(intel_dp);
  1748. intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
  1749. intel_dp_start_link_train(intel_dp);
  1750. intel_edp_panel_on(intel_dp);
  1751. edp_panel_vdd_off(intel_dp, true);
  1752. intel_dp_complete_link_train(intel_dp);
  1753. intel_dp_stop_link_train(intel_dp);
  1754. }
  1755. static void g4x_enable_dp(struct intel_encoder *encoder)
  1756. {
  1757. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  1758. intel_enable_dp(encoder);
  1759. intel_edp_backlight_on(intel_dp);
  1760. }
  1761. static void vlv_enable_dp(struct intel_encoder *encoder)
  1762. {
  1763. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  1764. intel_edp_backlight_on(intel_dp);
  1765. }
  1766. static void g4x_pre_enable_dp(struct intel_encoder *encoder)
  1767. {
  1768. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  1769. struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
  1770. intel_dp_prepare(encoder);
  1771. /* Only ilk+ has port A */
  1772. if (dport->port == PORT_A) {
  1773. ironlake_set_pll_cpu_edp(intel_dp);
  1774. ironlake_edp_pll_on(intel_dp);
  1775. }
  1776. }
  1777. static void vlv_pre_enable_dp(struct intel_encoder *encoder)
  1778. {
  1779. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  1780. struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
  1781. struct drm_device *dev = encoder->base.dev;
  1782. struct drm_i915_private *dev_priv = dev->dev_private;
  1783. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
  1784. enum dpio_channel port = vlv_dport_to_channel(dport);
  1785. int pipe = intel_crtc->pipe;
  1786. struct edp_power_seq power_seq;
  1787. u32 val;
  1788. mutex_lock(&dev_priv->dpio_lock);
  1789. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW8(port));
  1790. val = 0;
  1791. if (pipe)
  1792. val |= (1<<21);
  1793. else
  1794. val &= ~(1<<21);
  1795. val |= 0x001000c4;
  1796. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW8(port), val);
  1797. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW14(port), 0x00760018);
  1798. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW23(port), 0x00400888);
  1799. mutex_unlock(&dev_priv->dpio_lock);
  1800. if (is_edp(intel_dp)) {
  1801. /* init power sequencer on this pipe and port */
  1802. intel_dp_init_panel_power_sequencer(dev, intel_dp, &power_seq);
  1803. intel_dp_init_panel_power_sequencer_registers(dev, intel_dp,
  1804. &power_seq);
  1805. }
  1806. intel_enable_dp(encoder);
  1807. vlv_wait_port_ready(dev_priv, dport);
  1808. }
  1809. static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder)
  1810. {
  1811. struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
  1812. struct drm_device *dev = encoder->base.dev;
  1813. struct drm_i915_private *dev_priv = dev->dev_private;
  1814. struct intel_crtc *intel_crtc =
  1815. to_intel_crtc(encoder->base.crtc);
  1816. enum dpio_channel port = vlv_dport_to_channel(dport);
  1817. int pipe = intel_crtc->pipe;
  1818. intel_dp_prepare(encoder);
  1819. /* Program Tx lane resets to default */
  1820. mutex_lock(&dev_priv->dpio_lock);
  1821. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW0(port),
  1822. DPIO_PCS_TX_LANE2_RESET |
  1823. DPIO_PCS_TX_LANE1_RESET);
  1824. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW1(port),
  1825. DPIO_PCS_CLK_CRI_RXEB_EIOS_EN |
  1826. DPIO_PCS_CLK_CRI_RXDIGFILTSG_EN |
  1827. (1<<DPIO_PCS_CLK_DATAWIDTH_SHIFT) |
  1828. DPIO_PCS_CLK_SOFT_RESET);
  1829. /* Fix up inter-pair skew failure */
  1830. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW12(port), 0x00750f00);
  1831. vlv_dpio_write(dev_priv, pipe, VLV_TX_DW11(port), 0x00001500);
  1832. vlv_dpio_write(dev_priv, pipe, VLV_TX_DW14(port), 0x40400000);
  1833. mutex_unlock(&dev_priv->dpio_lock);
  1834. }
  1835. static void chv_pre_enable_dp(struct intel_encoder *encoder)
  1836. {
  1837. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  1838. struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
  1839. struct drm_device *dev = encoder->base.dev;
  1840. struct drm_i915_private *dev_priv = dev->dev_private;
  1841. struct edp_power_seq power_seq;
  1842. struct intel_crtc *intel_crtc =
  1843. to_intel_crtc(encoder->base.crtc);
  1844. enum dpio_channel ch = vlv_dport_to_channel(dport);
  1845. int pipe = intel_crtc->pipe;
  1846. int data, i;
  1847. u32 val;
  1848. mutex_lock(&dev_priv->dpio_lock);
  1849. /* Deassert soft data lane reset*/
  1850. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW1(ch));
  1851. val |= CHV_PCS_REQ_SOFTRESET_EN;
  1852. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW1(ch), val);
  1853. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW1(ch));
  1854. val |= CHV_PCS_REQ_SOFTRESET_EN;
  1855. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW1(ch), val);
  1856. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW0(ch));
  1857. val |= (DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET);
  1858. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW0(ch), val);
  1859. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW0(ch));
  1860. val |= (DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET);
  1861. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW0(ch), val);
  1862. /* Program Tx lane latency optimal setting*/
  1863. for (i = 0; i < 4; i++) {
  1864. /* Set the latency optimal bit */
  1865. data = (i == 1) ? 0x0 : 0x6;
  1866. vlv_dpio_write(dev_priv, pipe, CHV_TX_DW11(ch, i),
  1867. data << DPIO_FRC_LATENCY_SHFIT);
  1868. /* Set the upar bit */
  1869. data = (i == 1) ? 0x0 : 0x1;
  1870. vlv_dpio_write(dev_priv, pipe, CHV_TX_DW14(ch, i),
  1871. data << DPIO_UPAR_SHIFT);
  1872. }
  1873. /* Data lane stagger programming */
  1874. /* FIXME: Fix up value only after power analysis */
  1875. mutex_unlock(&dev_priv->dpio_lock);
  1876. if (is_edp(intel_dp)) {
  1877. /* init power sequencer on this pipe and port */
  1878. intel_dp_init_panel_power_sequencer(dev, intel_dp, &power_seq);
  1879. intel_dp_init_panel_power_sequencer_registers(dev, intel_dp,
  1880. &power_seq);
  1881. }
  1882. intel_enable_dp(encoder);
  1883. vlv_wait_port_ready(dev_priv, dport);
  1884. }
  1885. static void chv_dp_pre_pll_enable(struct intel_encoder *encoder)
  1886. {
  1887. struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
  1888. struct drm_device *dev = encoder->base.dev;
  1889. struct drm_i915_private *dev_priv = dev->dev_private;
  1890. struct intel_crtc *intel_crtc =
  1891. to_intel_crtc(encoder->base.crtc);
  1892. enum dpio_channel ch = vlv_dport_to_channel(dport);
  1893. enum pipe pipe = intel_crtc->pipe;
  1894. u32 val;
  1895. mutex_lock(&dev_priv->dpio_lock);
  1896. /* program left/right clock distribution */
  1897. if (pipe != PIPE_B) {
  1898. val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0);
  1899. val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK);
  1900. if (ch == DPIO_CH0)
  1901. val |= CHV_BUFLEFTENA1_FORCE;
  1902. if (ch == DPIO_CH1)
  1903. val |= CHV_BUFRIGHTENA1_FORCE;
  1904. vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val);
  1905. } else {
  1906. val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1);
  1907. val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK);
  1908. if (ch == DPIO_CH0)
  1909. val |= CHV_BUFLEFTENA2_FORCE;
  1910. if (ch == DPIO_CH1)
  1911. val |= CHV_BUFRIGHTENA2_FORCE;
  1912. vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val);
  1913. }
  1914. /* program clock channel usage */
  1915. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW8(ch));
  1916. val |= CHV_PCS_USEDCLKCHANNEL_OVRRIDE;
  1917. if (pipe != PIPE_B)
  1918. val &= ~CHV_PCS_USEDCLKCHANNEL;
  1919. else
  1920. val |= CHV_PCS_USEDCLKCHANNEL;
  1921. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW8(ch), val);
  1922. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW8(ch));
  1923. val |= CHV_PCS_USEDCLKCHANNEL_OVRRIDE;
  1924. if (pipe != PIPE_B)
  1925. val &= ~CHV_PCS_USEDCLKCHANNEL;
  1926. else
  1927. val |= CHV_PCS_USEDCLKCHANNEL;
  1928. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW8(ch), val);
  1929. /*
  1930. * This a a bit weird since generally CL
  1931. * matches the pipe, but here we need to
  1932. * pick the CL based on the port.
  1933. */
  1934. val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW19(ch));
  1935. if (pipe != PIPE_B)
  1936. val &= ~CHV_CMN_USEDCLKCHANNEL;
  1937. else
  1938. val |= CHV_CMN_USEDCLKCHANNEL;
  1939. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW19(ch), val);
  1940. mutex_unlock(&dev_priv->dpio_lock);
  1941. }
  1942. /*
  1943. * Native read with retry for link status and receiver capability reads for
  1944. * cases where the sink may still be asleep.
  1945. *
  1946. * Sinks are *supposed* to come up within 1ms from an off state, but we're also
  1947. * supposed to retry 3 times per the spec.
  1948. */
  1949. static ssize_t
  1950. intel_dp_dpcd_read_wake(struct drm_dp_aux *aux, unsigned int offset,
  1951. void *buffer, size_t size)
  1952. {
  1953. ssize_t ret;
  1954. int i;
  1955. for (i = 0; i < 3; i++) {
  1956. ret = drm_dp_dpcd_read(aux, offset, buffer, size);
  1957. if (ret == size)
  1958. return ret;
  1959. msleep(1);
  1960. }
  1961. return ret;
  1962. }
  1963. /*
  1964. * Fetch AUX CH registers 0x202 - 0x207 which contain
  1965. * link status information
  1966. */
  1967. static bool
  1968. intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
  1969. {
  1970. return intel_dp_dpcd_read_wake(&intel_dp->aux,
  1971. DP_LANE0_1_STATUS,
  1972. link_status,
  1973. DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;
  1974. }
  1975. /* These are source-specific values. */
  1976. static uint8_t
  1977. intel_dp_voltage_max(struct intel_dp *intel_dp)
  1978. {
  1979. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  1980. enum port port = dp_to_dig_port(intel_dp)->port;
  1981. if (IS_VALLEYVIEW(dev))
  1982. return DP_TRAIN_VOLTAGE_SWING_1200;
  1983. else if (IS_GEN7(dev) && port == PORT_A)
  1984. return DP_TRAIN_VOLTAGE_SWING_800;
  1985. else if (HAS_PCH_CPT(dev) && port != PORT_A)
  1986. return DP_TRAIN_VOLTAGE_SWING_1200;
  1987. else
  1988. return DP_TRAIN_VOLTAGE_SWING_800;
  1989. }
  1990. static uint8_t
  1991. intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
  1992. {
  1993. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  1994. enum port port = dp_to_dig_port(intel_dp)->port;
  1995. if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  1996. switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
  1997. case DP_TRAIN_VOLTAGE_SWING_400:
  1998. return DP_TRAIN_PRE_EMPHASIS_9_5;
  1999. case DP_TRAIN_VOLTAGE_SWING_600:
  2000. return DP_TRAIN_PRE_EMPHASIS_6;
  2001. case DP_TRAIN_VOLTAGE_SWING_800:
  2002. return DP_TRAIN_PRE_EMPHASIS_3_5;
  2003. case DP_TRAIN_VOLTAGE_SWING_1200:
  2004. default:
  2005. return DP_TRAIN_PRE_EMPHASIS_0;
  2006. }
  2007. } else if (IS_VALLEYVIEW(dev)) {
  2008. switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2009. case DP_TRAIN_VOLTAGE_SWING_400:
  2010. return DP_TRAIN_PRE_EMPHASIS_9_5;
  2011. case DP_TRAIN_VOLTAGE_SWING_600:
  2012. return DP_TRAIN_PRE_EMPHASIS_6;
  2013. case DP_TRAIN_VOLTAGE_SWING_800:
  2014. return DP_TRAIN_PRE_EMPHASIS_3_5;
  2015. case DP_TRAIN_VOLTAGE_SWING_1200:
  2016. default:
  2017. return DP_TRAIN_PRE_EMPHASIS_0;
  2018. }
  2019. } else if (IS_GEN7(dev) && port == PORT_A) {
  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. case DP_TRAIN_VOLTAGE_SWING_800:
  2025. return DP_TRAIN_PRE_EMPHASIS_3_5;
  2026. default:
  2027. return DP_TRAIN_PRE_EMPHASIS_0;
  2028. }
  2029. } else {
  2030. switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2031. case DP_TRAIN_VOLTAGE_SWING_400:
  2032. return DP_TRAIN_PRE_EMPHASIS_6;
  2033. case DP_TRAIN_VOLTAGE_SWING_600:
  2034. return DP_TRAIN_PRE_EMPHASIS_6;
  2035. case DP_TRAIN_VOLTAGE_SWING_800:
  2036. return DP_TRAIN_PRE_EMPHASIS_3_5;
  2037. case DP_TRAIN_VOLTAGE_SWING_1200:
  2038. default:
  2039. return DP_TRAIN_PRE_EMPHASIS_0;
  2040. }
  2041. }
  2042. }
  2043. static uint32_t intel_vlv_signal_levels(struct intel_dp *intel_dp)
  2044. {
  2045. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  2046. struct drm_i915_private *dev_priv = dev->dev_private;
  2047. struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
  2048. struct intel_crtc *intel_crtc =
  2049. to_intel_crtc(dport->base.base.crtc);
  2050. unsigned long demph_reg_value, preemph_reg_value,
  2051. uniqtranscale_reg_value;
  2052. uint8_t train_set = intel_dp->train_set[0];
  2053. enum dpio_channel port = vlv_dport_to_channel(dport);
  2054. int pipe = intel_crtc->pipe;
  2055. switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
  2056. case DP_TRAIN_PRE_EMPHASIS_0:
  2057. preemph_reg_value = 0x0004000;
  2058. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2059. case DP_TRAIN_VOLTAGE_SWING_400:
  2060. demph_reg_value = 0x2B405555;
  2061. uniqtranscale_reg_value = 0x552AB83A;
  2062. break;
  2063. case DP_TRAIN_VOLTAGE_SWING_600:
  2064. demph_reg_value = 0x2B404040;
  2065. uniqtranscale_reg_value = 0x5548B83A;
  2066. break;
  2067. case DP_TRAIN_VOLTAGE_SWING_800:
  2068. demph_reg_value = 0x2B245555;
  2069. uniqtranscale_reg_value = 0x5560B83A;
  2070. break;
  2071. case DP_TRAIN_VOLTAGE_SWING_1200:
  2072. demph_reg_value = 0x2B405555;
  2073. uniqtranscale_reg_value = 0x5598DA3A;
  2074. break;
  2075. default:
  2076. return 0;
  2077. }
  2078. break;
  2079. case DP_TRAIN_PRE_EMPHASIS_3_5:
  2080. preemph_reg_value = 0x0002000;
  2081. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2082. case DP_TRAIN_VOLTAGE_SWING_400:
  2083. demph_reg_value = 0x2B404040;
  2084. uniqtranscale_reg_value = 0x5552B83A;
  2085. break;
  2086. case DP_TRAIN_VOLTAGE_SWING_600:
  2087. demph_reg_value = 0x2B404848;
  2088. uniqtranscale_reg_value = 0x5580B83A;
  2089. break;
  2090. case DP_TRAIN_VOLTAGE_SWING_800:
  2091. demph_reg_value = 0x2B404040;
  2092. uniqtranscale_reg_value = 0x55ADDA3A;
  2093. break;
  2094. default:
  2095. return 0;
  2096. }
  2097. break;
  2098. case DP_TRAIN_PRE_EMPHASIS_6:
  2099. preemph_reg_value = 0x0000000;
  2100. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2101. case DP_TRAIN_VOLTAGE_SWING_400:
  2102. demph_reg_value = 0x2B305555;
  2103. uniqtranscale_reg_value = 0x5570B83A;
  2104. break;
  2105. case DP_TRAIN_VOLTAGE_SWING_600:
  2106. demph_reg_value = 0x2B2B4040;
  2107. uniqtranscale_reg_value = 0x55ADDA3A;
  2108. break;
  2109. default:
  2110. return 0;
  2111. }
  2112. break;
  2113. case DP_TRAIN_PRE_EMPHASIS_9_5:
  2114. preemph_reg_value = 0x0006000;
  2115. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2116. case DP_TRAIN_VOLTAGE_SWING_400:
  2117. demph_reg_value = 0x1B405555;
  2118. uniqtranscale_reg_value = 0x55ADDA3A;
  2119. break;
  2120. default:
  2121. return 0;
  2122. }
  2123. break;
  2124. default:
  2125. return 0;
  2126. }
  2127. mutex_lock(&dev_priv->dpio_lock);
  2128. vlv_dpio_write(dev_priv, pipe, VLV_TX_DW5(port), 0x00000000);
  2129. vlv_dpio_write(dev_priv, pipe, VLV_TX_DW4(port), demph_reg_value);
  2130. vlv_dpio_write(dev_priv, pipe, VLV_TX_DW2(port),
  2131. uniqtranscale_reg_value);
  2132. vlv_dpio_write(dev_priv, pipe, VLV_TX_DW3(port), 0x0C782040);
  2133. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW11(port), 0x00030000);
  2134. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW9(port), preemph_reg_value);
  2135. vlv_dpio_write(dev_priv, pipe, VLV_TX_DW5(port), 0x80000000);
  2136. mutex_unlock(&dev_priv->dpio_lock);
  2137. return 0;
  2138. }
  2139. static uint32_t intel_chv_signal_levels(struct intel_dp *intel_dp)
  2140. {
  2141. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  2142. struct drm_i915_private *dev_priv = dev->dev_private;
  2143. struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
  2144. struct intel_crtc *intel_crtc = to_intel_crtc(dport->base.base.crtc);
  2145. u32 deemph_reg_value, margin_reg_value, val;
  2146. uint8_t train_set = intel_dp->train_set[0];
  2147. enum dpio_channel ch = vlv_dport_to_channel(dport);
  2148. enum pipe pipe = intel_crtc->pipe;
  2149. int i;
  2150. switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
  2151. case DP_TRAIN_PRE_EMPHASIS_0:
  2152. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2153. case DP_TRAIN_VOLTAGE_SWING_400:
  2154. deemph_reg_value = 128;
  2155. margin_reg_value = 52;
  2156. break;
  2157. case DP_TRAIN_VOLTAGE_SWING_600:
  2158. deemph_reg_value = 128;
  2159. margin_reg_value = 77;
  2160. break;
  2161. case DP_TRAIN_VOLTAGE_SWING_800:
  2162. deemph_reg_value = 128;
  2163. margin_reg_value = 102;
  2164. break;
  2165. case DP_TRAIN_VOLTAGE_SWING_1200:
  2166. deemph_reg_value = 128;
  2167. margin_reg_value = 154;
  2168. /* FIXME extra to set for 1200 */
  2169. break;
  2170. default:
  2171. return 0;
  2172. }
  2173. break;
  2174. case DP_TRAIN_PRE_EMPHASIS_3_5:
  2175. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2176. case DP_TRAIN_VOLTAGE_SWING_400:
  2177. deemph_reg_value = 85;
  2178. margin_reg_value = 78;
  2179. break;
  2180. case DP_TRAIN_VOLTAGE_SWING_600:
  2181. deemph_reg_value = 85;
  2182. margin_reg_value = 116;
  2183. break;
  2184. case DP_TRAIN_VOLTAGE_SWING_800:
  2185. deemph_reg_value = 85;
  2186. margin_reg_value = 154;
  2187. break;
  2188. default:
  2189. return 0;
  2190. }
  2191. break;
  2192. case DP_TRAIN_PRE_EMPHASIS_6:
  2193. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2194. case DP_TRAIN_VOLTAGE_SWING_400:
  2195. deemph_reg_value = 64;
  2196. margin_reg_value = 104;
  2197. break;
  2198. case DP_TRAIN_VOLTAGE_SWING_600:
  2199. deemph_reg_value = 64;
  2200. margin_reg_value = 154;
  2201. break;
  2202. default:
  2203. return 0;
  2204. }
  2205. break;
  2206. case DP_TRAIN_PRE_EMPHASIS_9_5:
  2207. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2208. case DP_TRAIN_VOLTAGE_SWING_400:
  2209. deemph_reg_value = 43;
  2210. margin_reg_value = 154;
  2211. break;
  2212. default:
  2213. return 0;
  2214. }
  2215. break;
  2216. default:
  2217. return 0;
  2218. }
  2219. mutex_lock(&dev_priv->dpio_lock);
  2220. /* Clear calc init */
  2221. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW10(ch));
  2222. val &= ~(DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3);
  2223. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW10(ch), val);
  2224. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW10(ch));
  2225. val &= ~(DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3);
  2226. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW10(ch), val);
  2227. /* Program swing deemph */
  2228. for (i = 0; i < 4; i++) {
  2229. val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW4(ch, i));
  2230. val &= ~DPIO_SWING_DEEMPH9P5_MASK;
  2231. val |= deemph_reg_value << DPIO_SWING_DEEMPH9P5_SHIFT;
  2232. vlv_dpio_write(dev_priv, pipe, CHV_TX_DW4(ch, i), val);
  2233. }
  2234. /* Program swing margin */
  2235. for (i = 0; i < 4; i++) {
  2236. val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW2(ch, i));
  2237. val &= ~DPIO_SWING_MARGIN_MASK;
  2238. val |= margin_reg_value << DPIO_SWING_MARGIN_SHIFT;
  2239. vlv_dpio_write(dev_priv, pipe, CHV_TX_DW2(ch, i), val);
  2240. }
  2241. /* Disable unique transition scale */
  2242. for (i = 0; i < 4; i++) {
  2243. val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW3(ch, i));
  2244. val &= ~DPIO_TX_UNIQ_TRANS_SCALE_EN;
  2245. vlv_dpio_write(dev_priv, pipe, CHV_TX_DW3(ch, i), val);
  2246. }
  2247. if (((train_set & DP_TRAIN_PRE_EMPHASIS_MASK)
  2248. == DP_TRAIN_PRE_EMPHASIS_0) &&
  2249. ((train_set & DP_TRAIN_VOLTAGE_SWING_MASK)
  2250. == DP_TRAIN_VOLTAGE_SWING_1200)) {
  2251. /*
  2252. * The document said it needs to set bit 27 for ch0 and bit 26
  2253. * for ch1. Might be a typo in the doc.
  2254. * For now, for this unique transition scale selection, set bit
  2255. * 27 for ch0 and ch1.
  2256. */
  2257. for (i = 0; i < 4; i++) {
  2258. val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW3(ch, i));
  2259. val |= DPIO_TX_UNIQ_TRANS_SCALE_EN;
  2260. vlv_dpio_write(dev_priv, pipe, CHV_TX_DW3(ch, i), val);
  2261. }
  2262. for (i = 0; i < 4; i++) {
  2263. val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW2(ch, i));
  2264. val &= ~(0xff << DPIO_UNIQ_TRANS_SCALE_SHIFT);
  2265. val |= (0x9a << DPIO_UNIQ_TRANS_SCALE_SHIFT);
  2266. vlv_dpio_write(dev_priv, pipe, CHV_TX_DW2(ch, i), val);
  2267. }
  2268. }
  2269. /* Start swing calculation */
  2270. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW10(ch));
  2271. val |= DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3;
  2272. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW10(ch), val);
  2273. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW10(ch));
  2274. val |= DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3;
  2275. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW10(ch), val);
  2276. /* LRC Bypass */
  2277. val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW30);
  2278. val |= DPIO_LRC_BYPASS;
  2279. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW30, val);
  2280. mutex_unlock(&dev_priv->dpio_lock);
  2281. return 0;
  2282. }
  2283. static void
  2284. intel_get_adjust_train(struct intel_dp *intel_dp,
  2285. const uint8_t link_status[DP_LINK_STATUS_SIZE])
  2286. {
  2287. uint8_t v = 0;
  2288. uint8_t p = 0;
  2289. int lane;
  2290. uint8_t voltage_max;
  2291. uint8_t preemph_max;
  2292. for (lane = 0; lane < intel_dp->lane_count; lane++) {
  2293. uint8_t this_v = drm_dp_get_adjust_request_voltage(link_status, lane);
  2294. uint8_t this_p = drm_dp_get_adjust_request_pre_emphasis(link_status, lane);
  2295. if (this_v > v)
  2296. v = this_v;
  2297. if (this_p > p)
  2298. p = this_p;
  2299. }
  2300. voltage_max = intel_dp_voltage_max(intel_dp);
  2301. if (v >= voltage_max)
  2302. v = voltage_max | DP_TRAIN_MAX_SWING_REACHED;
  2303. preemph_max = intel_dp_pre_emphasis_max(intel_dp, v);
  2304. if (p >= preemph_max)
  2305. p = preemph_max | DP_TRAIN_MAX_PRE_EMPHASIS_REACHED;
  2306. for (lane = 0; lane < 4; lane++)
  2307. intel_dp->train_set[lane] = v | p;
  2308. }
  2309. static uint32_t
  2310. intel_gen4_signal_levels(uint8_t train_set)
  2311. {
  2312. uint32_t signal_levels = 0;
  2313. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2314. case DP_TRAIN_VOLTAGE_SWING_400:
  2315. default:
  2316. signal_levels |= DP_VOLTAGE_0_4;
  2317. break;
  2318. case DP_TRAIN_VOLTAGE_SWING_600:
  2319. signal_levels |= DP_VOLTAGE_0_6;
  2320. break;
  2321. case DP_TRAIN_VOLTAGE_SWING_800:
  2322. signal_levels |= DP_VOLTAGE_0_8;
  2323. break;
  2324. case DP_TRAIN_VOLTAGE_SWING_1200:
  2325. signal_levels |= DP_VOLTAGE_1_2;
  2326. break;
  2327. }
  2328. switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
  2329. case DP_TRAIN_PRE_EMPHASIS_0:
  2330. default:
  2331. signal_levels |= DP_PRE_EMPHASIS_0;
  2332. break;
  2333. case DP_TRAIN_PRE_EMPHASIS_3_5:
  2334. signal_levels |= DP_PRE_EMPHASIS_3_5;
  2335. break;
  2336. case DP_TRAIN_PRE_EMPHASIS_6:
  2337. signal_levels |= DP_PRE_EMPHASIS_6;
  2338. break;
  2339. case DP_TRAIN_PRE_EMPHASIS_9_5:
  2340. signal_levels |= DP_PRE_EMPHASIS_9_5;
  2341. break;
  2342. }
  2343. return signal_levels;
  2344. }
  2345. /* Gen6's DP voltage swing and pre-emphasis control */
  2346. static uint32_t
  2347. intel_gen6_edp_signal_levels(uint8_t train_set)
  2348. {
  2349. int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
  2350. DP_TRAIN_PRE_EMPHASIS_MASK);
  2351. switch (signal_levels) {
  2352. case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
  2353. case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
  2354. return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
  2355. case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
  2356. return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
  2357. case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
  2358. case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_6:
  2359. return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
  2360. case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
  2361. case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
  2362. return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
  2363. case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
  2364. case DP_TRAIN_VOLTAGE_SWING_1200 | DP_TRAIN_PRE_EMPHASIS_0:
  2365. return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
  2366. default:
  2367. DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
  2368. "0x%x\n", signal_levels);
  2369. return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
  2370. }
  2371. }
  2372. /* Gen7's DP voltage swing and pre-emphasis control */
  2373. static uint32_t
  2374. intel_gen7_edp_signal_levels(uint8_t train_set)
  2375. {
  2376. int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
  2377. DP_TRAIN_PRE_EMPHASIS_MASK);
  2378. switch (signal_levels) {
  2379. case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
  2380. return EDP_LINK_TRAIN_400MV_0DB_IVB;
  2381. case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
  2382. return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
  2383. case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
  2384. return EDP_LINK_TRAIN_400MV_6DB_IVB;
  2385. case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
  2386. return EDP_LINK_TRAIN_600MV_0DB_IVB;
  2387. case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
  2388. return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
  2389. case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
  2390. return EDP_LINK_TRAIN_800MV_0DB_IVB;
  2391. case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
  2392. return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
  2393. default:
  2394. DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
  2395. "0x%x\n", signal_levels);
  2396. return EDP_LINK_TRAIN_500MV_0DB_IVB;
  2397. }
  2398. }
  2399. /* Gen7.5's (HSW) DP voltage swing and pre-emphasis control */
  2400. static uint32_t
  2401. intel_hsw_signal_levels(uint8_t train_set)
  2402. {
  2403. int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
  2404. DP_TRAIN_PRE_EMPHASIS_MASK);
  2405. switch (signal_levels) {
  2406. case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
  2407. return DDI_BUF_EMP_400MV_0DB_HSW;
  2408. case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
  2409. return DDI_BUF_EMP_400MV_3_5DB_HSW;
  2410. case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
  2411. return DDI_BUF_EMP_400MV_6DB_HSW;
  2412. case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_9_5:
  2413. return DDI_BUF_EMP_400MV_9_5DB_HSW;
  2414. case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
  2415. return DDI_BUF_EMP_600MV_0DB_HSW;
  2416. case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
  2417. return DDI_BUF_EMP_600MV_3_5DB_HSW;
  2418. case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_6:
  2419. return DDI_BUF_EMP_600MV_6DB_HSW;
  2420. case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
  2421. return DDI_BUF_EMP_800MV_0DB_HSW;
  2422. case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
  2423. return DDI_BUF_EMP_800MV_3_5DB_HSW;
  2424. default:
  2425. DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
  2426. "0x%x\n", signal_levels);
  2427. return DDI_BUF_EMP_400MV_0DB_HSW;
  2428. }
  2429. }
  2430. /* Properly updates "DP" with the correct signal levels. */
  2431. static void
  2432. intel_dp_set_signal_levels(struct intel_dp *intel_dp, uint32_t *DP)
  2433. {
  2434. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  2435. enum port port = intel_dig_port->port;
  2436. struct drm_device *dev = intel_dig_port->base.base.dev;
  2437. uint32_t signal_levels, mask;
  2438. uint8_t train_set = intel_dp->train_set[0];
  2439. if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  2440. signal_levels = intel_hsw_signal_levels(train_set);
  2441. mask = DDI_BUF_EMP_MASK;
  2442. } else if (IS_CHERRYVIEW(dev)) {
  2443. signal_levels = intel_chv_signal_levels(intel_dp);
  2444. mask = 0;
  2445. } else if (IS_VALLEYVIEW(dev)) {
  2446. signal_levels = intel_vlv_signal_levels(intel_dp);
  2447. mask = 0;
  2448. } else if (IS_GEN7(dev) && port == PORT_A) {
  2449. signal_levels = intel_gen7_edp_signal_levels(train_set);
  2450. mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
  2451. } else if (IS_GEN6(dev) && port == PORT_A) {
  2452. signal_levels = intel_gen6_edp_signal_levels(train_set);
  2453. mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
  2454. } else {
  2455. signal_levels = intel_gen4_signal_levels(train_set);
  2456. mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
  2457. }
  2458. DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
  2459. *DP = (*DP & ~mask) | signal_levels;
  2460. }
  2461. static bool
  2462. intel_dp_set_link_train(struct intel_dp *intel_dp,
  2463. uint32_t *DP,
  2464. uint8_t dp_train_pat)
  2465. {
  2466. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  2467. struct drm_device *dev = intel_dig_port->base.base.dev;
  2468. struct drm_i915_private *dev_priv = dev->dev_private;
  2469. enum port port = intel_dig_port->port;
  2470. uint8_t buf[sizeof(intel_dp->train_set) + 1];
  2471. int ret, len;
  2472. if (HAS_DDI(dev)) {
  2473. uint32_t temp = I915_READ(DP_TP_CTL(port));
  2474. if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
  2475. temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
  2476. else
  2477. temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
  2478. temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
  2479. switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
  2480. case DP_TRAINING_PATTERN_DISABLE:
  2481. temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
  2482. break;
  2483. case DP_TRAINING_PATTERN_1:
  2484. temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
  2485. break;
  2486. case DP_TRAINING_PATTERN_2:
  2487. temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
  2488. break;
  2489. case DP_TRAINING_PATTERN_3:
  2490. temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
  2491. break;
  2492. }
  2493. I915_WRITE(DP_TP_CTL(port), temp);
  2494. } else if (HAS_PCH_CPT(dev) && (IS_GEN7(dev) || port != PORT_A)) {
  2495. *DP &= ~DP_LINK_TRAIN_MASK_CPT;
  2496. switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
  2497. case DP_TRAINING_PATTERN_DISABLE:
  2498. *DP |= DP_LINK_TRAIN_OFF_CPT;
  2499. break;
  2500. case DP_TRAINING_PATTERN_1:
  2501. *DP |= DP_LINK_TRAIN_PAT_1_CPT;
  2502. break;
  2503. case DP_TRAINING_PATTERN_2:
  2504. *DP |= DP_LINK_TRAIN_PAT_2_CPT;
  2505. break;
  2506. case DP_TRAINING_PATTERN_3:
  2507. DRM_ERROR("DP training pattern 3 not supported\n");
  2508. *DP |= DP_LINK_TRAIN_PAT_2_CPT;
  2509. break;
  2510. }
  2511. } else {
  2512. *DP &= ~DP_LINK_TRAIN_MASK;
  2513. switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
  2514. case DP_TRAINING_PATTERN_DISABLE:
  2515. *DP |= DP_LINK_TRAIN_OFF;
  2516. break;
  2517. case DP_TRAINING_PATTERN_1:
  2518. *DP |= DP_LINK_TRAIN_PAT_1;
  2519. break;
  2520. case DP_TRAINING_PATTERN_2:
  2521. *DP |= DP_LINK_TRAIN_PAT_2;
  2522. break;
  2523. case DP_TRAINING_PATTERN_3:
  2524. DRM_ERROR("DP training pattern 3 not supported\n");
  2525. *DP |= DP_LINK_TRAIN_PAT_2;
  2526. break;
  2527. }
  2528. }
  2529. I915_WRITE(intel_dp->output_reg, *DP);
  2530. POSTING_READ(intel_dp->output_reg);
  2531. buf[0] = dp_train_pat;
  2532. if ((dp_train_pat & DP_TRAINING_PATTERN_MASK) ==
  2533. DP_TRAINING_PATTERN_DISABLE) {
  2534. /* don't write DP_TRAINING_LANEx_SET on disable */
  2535. len = 1;
  2536. } else {
  2537. /* DP_TRAINING_LANEx_SET follow DP_TRAINING_PATTERN_SET */
  2538. memcpy(buf + 1, intel_dp->train_set, intel_dp->lane_count);
  2539. len = intel_dp->lane_count + 1;
  2540. }
  2541. ret = drm_dp_dpcd_write(&intel_dp->aux, DP_TRAINING_PATTERN_SET,
  2542. buf, len);
  2543. return ret == len;
  2544. }
  2545. static bool
  2546. intel_dp_reset_link_train(struct intel_dp *intel_dp, uint32_t *DP,
  2547. uint8_t dp_train_pat)
  2548. {
  2549. memset(intel_dp->train_set, 0, sizeof(intel_dp->train_set));
  2550. intel_dp_set_signal_levels(intel_dp, DP);
  2551. return intel_dp_set_link_train(intel_dp, DP, dp_train_pat);
  2552. }
  2553. static bool
  2554. intel_dp_update_link_train(struct intel_dp *intel_dp, uint32_t *DP,
  2555. const uint8_t link_status[DP_LINK_STATUS_SIZE])
  2556. {
  2557. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  2558. struct drm_device *dev = intel_dig_port->base.base.dev;
  2559. struct drm_i915_private *dev_priv = dev->dev_private;
  2560. int ret;
  2561. intel_get_adjust_train(intel_dp, link_status);
  2562. intel_dp_set_signal_levels(intel_dp, DP);
  2563. I915_WRITE(intel_dp->output_reg, *DP);
  2564. POSTING_READ(intel_dp->output_reg);
  2565. ret = drm_dp_dpcd_write(&intel_dp->aux, DP_TRAINING_LANE0_SET,
  2566. intel_dp->train_set, intel_dp->lane_count);
  2567. return ret == intel_dp->lane_count;
  2568. }
  2569. static void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
  2570. {
  2571. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  2572. struct drm_device *dev = intel_dig_port->base.base.dev;
  2573. struct drm_i915_private *dev_priv = dev->dev_private;
  2574. enum port port = intel_dig_port->port;
  2575. uint32_t val;
  2576. if (!HAS_DDI(dev))
  2577. return;
  2578. val = I915_READ(DP_TP_CTL(port));
  2579. val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
  2580. val |= DP_TP_CTL_LINK_TRAIN_IDLE;
  2581. I915_WRITE(DP_TP_CTL(port), val);
  2582. /*
  2583. * On PORT_A we can have only eDP in SST mode. There the only reason
  2584. * we need to set idle transmission mode is to work around a HW issue
  2585. * where we enable the pipe while not in idle link-training mode.
  2586. * In this case there is requirement to wait for a minimum number of
  2587. * idle patterns to be sent.
  2588. */
  2589. if (port == PORT_A)
  2590. return;
  2591. if (wait_for((I915_READ(DP_TP_STATUS(port)) & DP_TP_STATUS_IDLE_DONE),
  2592. 1))
  2593. DRM_ERROR("Timed out waiting for DP idle patterns\n");
  2594. }
  2595. /* Enable corresponding port and start training pattern 1 */
  2596. void
  2597. intel_dp_start_link_train(struct intel_dp *intel_dp)
  2598. {
  2599. struct drm_encoder *encoder = &dp_to_dig_port(intel_dp)->base.base;
  2600. struct drm_device *dev = encoder->dev;
  2601. int i;
  2602. uint8_t voltage;
  2603. int voltage_tries, loop_tries;
  2604. uint32_t DP = intel_dp->DP;
  2605. uint8_t link_config[2];
  2606. if (HAS_DDI(dev))
  2607. intel_ddi_prepare_link_retrain(encoder);
  2608. /* Write the link configuration data */
  2609. link_config[0] = intel_dp->link_bw;
  2610. link_config[1] = intel_dp->lane_count;
  2611. if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
  2612. link_config[1] |= DP_LANE_COUNT_ENHANCED_FRAME_EN;
  2613. drm_dp_dpcd_write(&intel_dp->aux, DP_LINK_BW_SET, link_config, 2);
  2614. link_config[0] = 0;
  2615. link_config[1] = DP_SET_ANSI_8B10B;
  2616. drm_dp_dpcd_write(&intel_dp->aux, DP_DOWNSPREAD_CTRL, link_config, 2);
  2617. DP |= DP_PORT_EN;
  2618. /* clock recovery */
  2619. if (!intel_dp_reset_link_train(intel_dp, &DP,
  2620. DP_TRAINING_PATTERN_1 |
  2621. DP_LINK_SCRAMBLING_DISABLE)) {
  2622. DRM_ERROR("failed to enable link training\n");
  2623. return;
  2624. }
  2625. voltage = 0xff;
  2626. voltage_tries = 0;
  2627. loop_tries = 0;
  2628. for (;;) {
  2629. uint8_t link_status[DP_LINK_STATUS_SIZE];
  2630. drm_dp_link_train_clock_recovery_delay(intel_dp->dpcd);
  2631. if (!intel_dp_get_link_status(intel_dp, link_status)) {
  2632. DRM_ERROR("failed to get link status\n");
  2633. break;
  2634. }
  2635. if (drm_dp_clock_recovery_ok(link_status, intel_dp->lane_count)) {
  2636. DRM_DEBUG_KMS("clock recovery OK\n");
  2637. break;
  2638. }
  2639. /* Check to see if we've tried the max voltage */
  2640. for (i = 0; i < intel_dp->lane_count; i++)
  2641. if ((intel_dp->train_set[i] & DP_TRAIN_MAX_SWING_REACHED) == 0)
  2642. break;
  2643. if (i == intel_dp->lane_count) {
  2644. ++loop_tries;
  2645. if (loop_tries == 5) {
  2646. DRM_ERROR("too many full retries, give up\n");
  2647. break;
  2648. }
  2649. intel_dp_reset_link_train(intel_dp, &DP,
  2650. DP_TRAINING_PATTERN_1 |
  2651. DP_LINK_SCRAMBLING_DISABLE);
  2652. voltage_tries = 0;
  2653. continue;
  2654. }
  2655. /* Check to see if we've tried the same voltage 5 times */
  2656. if ((intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK) == voltage) {
  2657. ++voltage_tries;
  2658. if (voltage_tries == 5) {
  2659. DRM_ERROR("too many voltage retries, give up\n");
  2660. break;
  2661. }
  2662. } else
  2663. voltage_tries = 0;
  2664. voltage = intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK;
  2665. /* Update training set as requested by target */
  2666. if (!intel_dp_update_link_train(intel_dp, &DP, link_status)) {
  2667. DRM_ERROR("failed to update link training\n");
  2668. break;
  2669. }
  2670. }
  2671. intel_dp->DP = DP;
  2672. }
  2673. void
  2674. intel_dp_complete_link_train(struct intel_dp *intel_dp)
  2675. {
  2676. bool channel_eq = false;
  2677. int tries, cr_tries;
  2678. uint32_t DP = intel_dp->DP;
  2679. uint32_t training_pattern = DP_TRAINING_PATTERN_2;
  2680. /* Training Pattern 3 for HBR2 ot 1.2 devices that support it*/
  2681. if (intel_dp->link_bw == DP_LINK_BW_5_4 || intel_dp->use_tps3)
  2682. training_pattern = DP_TRAINING_PATTERN_3;
  2683. /* channel equalization */
  2684. if (!intel_dp_set_link_train(intel_dp, &DP,
  2685. training_pattern |
  2686. DP_LINK_SCRAMBLING_DISABLE)) {
  2687. DRM_ERROR("failed to start channel equalization\n");
  2688. return;
  2689. }
  2690. tries = 0;
  2691. cr_tries = 0;
  2692. channel_eq = false;
  2693. for (;;) {
  2694. uint8_t link_status[DP_LINK_STATUS_SIZE];
  2695. if (cr_tries > 5) {
  2696. DRM_ERROR("failed to train DP, aborting\n");
  2697. break;
  2698. }
  2699. drm_dp_link_train_channel_eq_delay(intel_dp->dpcd);
  2700. if (!intel_dp_get_link_status(intel_dp, link_status)) {
  2701. DRM_ERROR("failed to get link status\n");
  2702. break;
  2703. }
  2704. /* Make sure clock is still ok */
  2705. if (!drm_dp_clock_recovery_ok(link_status, intel_dp->lane_count)) {
  2706. intel_dp_start_link_train(intel_dp);
  2707. intel_dp_set_link_train(intel_dp, &DP,
  2708. training_pattern |
  2709. DP_LINK_SCRAMBLING_DISABLE);
  2710. cr_tries++;
  2711. continue;
  2712. }
  2713. if (drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
  2714. channel_eq = true;
  2715. break;
  2716. }
  2717. /* Try 5 times, then try clock recovery if that fails */
  2718. if (tries > 5) {
  2719. intel_dp_link_down(intel_dp);
  2720. intel_dp_start_link_train(intel_dp);
  2721. intel_dp_set_link_train(intel_dp, &DP,
  2722. training_pattern |
  2723. DP_LINK_SCRAMBLING_DISABLE);
  2724. tries = 0;
  2725. cr_tries++;
  2726. continue;
  2727. }
  2728. /* Update training set as requested by target */
  2729. if (!intel_dp_update_link_train(intel_dp, &DP, link_status)) {
  2730. DRM_ERROR("failed to update link training\n");
  2731. break;
  2732. }
  2733. ++tries;
  2734. }
  2735. intel_dp_set_idle_link_train(intel_dp);
  2736. intel_dp->DP = DP;
  2737. if (channel_eq)
  2738. DRM_DEBUG_KMS("Channel EQ done. DP Training successful\n");
  2739. }
  2740. void intel_dp_stop_link_train(struct intel_dp *intel_dp)
  2741. {
  2742. intel_dp_set_link_train(intel_dp, &intel_dp->DP,
  2743. DP_TRAINING_PATTERN_DISABLE);
  2744. }
  2745. static void
  2746. intel_dp_link_down(struct intel_dp *intel_dp)
  2747. {
  2748. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  2749. enum port port = intel_dig_port->port;
  2750. struct drm_device *dev = intel_dig_port->base.base.dev;
  2751. struct drm_i915_private *dev_priv = dev->dev_private;
  2752. struct intel_crtc *intel_crtc =
  2753. to_intel_crtc(intel_dig_port->base.base.crtc);
  2754. uint32_t DP = intel_dp->DP;
  2755. if (WARN_ON(HAS_DDI(dev)))
  2756. return;
  2757. if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
  2758. return;
  2759. DRM_DEBUG_KMS("\n");
  2760. if (HAS_PCH_CPT(dev) && (IS_GEN7(dev) || port != PORT_A)) {
  2761. DP &= ~DP_LINK_TRAIN_MASK_CPT;
  2762. I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE_CPT);
  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 drm_device *dev = intel_dp_to_dev(intel_dp);
  2987. struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
  2988. u8 sink_irq_vector;
  2989. u8 link_status[DP_LINK_STATUS_SIZE];
  2990. WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
  2991. if (!intel_encoder->connectors_active)
  2992. return;
  2993. if (WARN_ON(!intel_encoder->base.crtc))
  2994. return;
  2995. if (!to_intel_crtc(intel_encoder->base.crtc)->active)
  2996. return;
  2997. /* Try to read receiver status if the link appears to be up */
  2998. if (!intel_dp_get_link_status(intel_dp, link_status)) {
  2999. return;
  3000. }
  3001. /* Now read the DPCD to see if it's actually running */
  3002. if (!intel_dp_get_dpcd(intel_dp)) {
  3003. return;
  3004. }
  3005. /* Try to read the source of the interrupt */
  3006. if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
  3007. intel_dp_get_sink_irq(intel_dp, &sink_irq_vector)) {
  3008. /* Clear interrupt source */
  3009. drm_dp_dpcd_writeb(&intel_dp->aux,
  3010. DP_DEVICE_SERVICE_IRQ_VECTOR,
  3011. sink_irq_vector);
  3012. if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
  3013. intel_dp_handle_test_request(intel_dp);
  3014. if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
  3015. DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
  3016. }
  3017. if (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
  3018. DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
  3019. intel_encoder->base.name);
  3020. intel_dp_start_link_train(intel_dp);
  3021. intel_dp_complete_link_train(intel_dp);
  3022. intel_dp_stop_link_train(intel_dp);
  3023. }
  3024. }
  3025. /* XXX this is probably wrong for multiple downstream ports */
  3026. static enum drm_connector_status
  3027. intel_dp_detect_dpcd(struct intel_dp *intel_dp)
  3028. {
  3029. uint8_t *dpcd = intel_dp->dpcd;
  3030. uint8_t type;
  3031. if (!intel_dp_get_dpcd(intel_dp))
  3032. return connector_status_disconnected;
  3033. /* if there's no downstream port, we're done */
  3034. if (!(dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DWN_STRM_PORT_PRESENT))
  3035. return connector_status_connected;
  3036. /* If we're HPD-aware, SINK_COUNT changes dynamically */
  3037. if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
  3038. intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
  3039. uint8_t reg;
  3040. if (intel_dp_dpcd_read_wake(&intel_dp->aux, DP_SINK_COUNT,
  3041. &reg, 1) < 0)
  3042. return connector_status_unknown;
  3043. return DP_GET_SINK_COUNT(reg) ? connector_status_connected
  3044. : connector_status_disconnected;
  3045. }
  3046. /* If no HPD, poke DDC gently */
  3047. if (drm_probe_ddc(&intel_dp->aux.ddc))
  3048. return connector_status_connected;
  3049. /* Well we tried, say unknown for unreliable port types */
  3050. if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
  3051. type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
  3052. if (type == DP_DS_PORT_TYPE_VGA ||
  3053. type == DP_DS_PORT_TYPE_NON_EDID)
  3054. return connector_status_unknown;
  3055. } else {
  3056. type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
  3057. DP_DWN_STRM_PORT_TYPE_MASK;
  3058. if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
  3059. type == DP_DWN_STRM_PORT_TYPE_OTHER)
  3060. return connector_status_unknown;
  3061. }
  3062. /* Anything else is out of spec, warn and ignore */
  3063. DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
  3064. return connector_status_disconnected;
  3065. }
  3066. static enum drm_connector_status
  3067. ironlake_dp_detect(struct intel_dp *intel_dp)
  3068. {
  3069. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  3070. struct drm_i915_private *dev_priv = dev->dev_private;
  3071. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  3072. enum drm_connector_status status;
  3073. /* Can't disconnect eDP, but you can close the lid... */
  3074. if (is_edp(intel_dp)) {
  3075. status = intel_panel_detect(dev);
  3076. if (status == connector_status_unknown)
  3077. status = connector_status_connected;
  3078. return status;
  3079. }
  3080. if (!ibx_digital_port_connected(dev_priv, intel_dig_port))
  3081. return connector_status_disconnected;
  3082. return intel_dp_detect_dpcd(intel_dp);
  3083. }
  3084. static int g4x_digital_port_connected(struct drm_device *dev,
  3085. struct intel_digital_port *intel_dig_port)
  3086. {
  3087. struct drm_i915_private *dev_priv = dev->dev_private;
  3088. uint32_t bit;
  3089. if (IS_VALLEYVIEW(dev)) {
  3090. switch (intel_dig_port->port) {
  3091. case PORT_B:
  3092. bit = PORTB_HOTPLUG_LIVE_STATUS_VLV;
  3093. break;
  3094. case PORT_C:
  3095. bit = PORTC_HOTPLUG_LIVE_STATUS_VLV;
  3096. break;
  3097. case PORT_D:
  3098. bit = PORTD_HOTPLUG_LIVE_STATUS_VLV;
  3099. break;
  3100. default:
  3101. return -EINVAL;
  3102. }
  3103. } else {
  3104. switch (intel_dig_port->port) {
  3105. case PORT_B:
  3106. bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
  3107. break;
  3108. case PORT_C:
  3109. bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
  3110. break;
  3111. case PORT_D:
  3112. bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
  3113. break;
  3114. default:
  3115. return -EINVAL;
  3116. }
  3117. }
  3118. if ((I915_READ(PORT_HOTPLUG_STAT) & bit) == 0)
  3119. return 0;
  3120. return 1;
  3121. }
  3122. static enum drm_connector_status
  3123. g4x_dp_detect(struct intel_dp *intel_dp)
  3124. {
  3125. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  3126. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  3127. int ret;
  3128. /* Can't disconnect eDP, but you can close the lid... */
  3129. if (is_edp(intel_dp)) {
  3130. enum drm_connector_status status;
  3131. status = intel_panel_detect(dev);
  3132. if (status == connector_status_unknown)
  3133. status = connector_status_connected;
  3134. return status;
  3135. }
  3136. ret = g4x_digital_port_connected(dev, intel_dig_port);
  3137. if (ret == -EINVAL)
  3138. return connector_status_unknown;
  3139. else if (ret == 0)
  3140. return connector_status_disconnected;
  3141. return intel_dp_detect_dpcd(intel_dp);
  3142. }
  3143. static struct edid *
  3144. intel_dp_get_edid(struct drm_connector *connector, struct i2c_adapter *adapter)
  3145. {
  3146. struct intel_connector *intel_connector = to_intel_connector(connector);
  3147. /* use cached edid if we have one */
  3148. if (intel_connector->edid) {
  3149. /* invalid edid */
  3150. if (IS_ERR(intel_connector->edid))
  3151. return NULL;
  3152. return drm_edid_duplicate(intel_connector->edid);
  3153. }
  3154. return drm_get_edid(connector, adapter);
  3155. }
  3156. static int
  3157. intel_dp_get_edid_modes(struct drm_connector *connector, struct i2c_adapter *adapter)
  3158. {
  3159. struct intel_connector *intel_connector = to_intel_connector(connector);
  3160. /* use cached edid if we have one */
  3161. if (intel_connector->edid) {
  3162. /* invalid edid */
  3163. if (IS_ERR(intel_connector->edid))
  3164. return 0;
  3165. return intel_connector_update_modes(connector,
  3166. intel_connector->edid);
  3167. }
  3168. return intel_ddc_get_modes(connector, adapter);
  3169. }
  3170. static enum drm_connector_status
  3171. intel_dp_detect(struct drm_connector *connector, bool force)
  3172. {
  3173. struct intel_dp *intel_dp = intel_attached_dp(connector);
  3174. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  3175. struct intel_encoder *intel_encoder = &intel_dig_port->base;
  3176. struct drm_device *dev = connector->dev;
  3177. struct drm_i915_private *dev_priv = dev->dev_private;
  3178. enum drm_connector_status status;
  3179. enum intel_display_power_domain power_domain;
  3180. struct edid *edid = NULL;
  3181. bool ret;
  3182. power_domain = intel_display_port_power_domain(intel_encoder);
  3183. intel_display_power_get(dev_priv, power_domain);
  3184. DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
  3185. connector->base.id, connector->name);
  3186. if (intel_dp->is_mst) {
  3187. /* MST devices are disconnected from a monitor POV */
  3188. if (intel_encoder->type != INTEL_OUTPUT_EDP)
  3189. intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
  3190. status = connector_status_disconnected;
  3191. goto out;
  3192. }
  3193. intel_dp->has_audio = false;
  3194. if (HAS_PCH_SPLIT(dev))
  3195. status = ironlake_dp_detect(intel_dp);
  3196. else
  3197. status = g4x_dp_detect(intel_dp);
  3198. if (status != connector_status_connected)
  3199. goto out;
  3200. intel_dp_probe_oui(intel_dp);
  3201. ret = intel_dp_probe_mst(intel_dp);
  3202. if (ret) {
  3203. /* if we are in MST mode then this connector
  3204. won't appear connected or have anything with EDID on it */
  3205. if (intel_encoder->type != INTEL_OUTPUT_EDP)
  3206. intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
  3207. status = connector_status_disconnected;
  3208. goto out;
  3209. }
  3210. if (intel_dp->force_audio != HDMI_AUDIO_AUTO) {
  3211. intel_dp->has_audio = (intel_dp->force_audio == HDMI_AUDIO_ON);
  3212. } else {
  3213. edid = intel_dp_get_edid(connector, &intel_dp->aux.ddc);
  3214. if (edid) {
  3215. intel_dp->has_audio = drm_detect_monitor_audio(edid);
  3216. kfree(edid);
  3217. }
  3218. }
  3219. if (intel_encoder->type != INTEL_OUTPUT_EDP)
  3220. intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
  3221. status = connector_status_connected;
  3222. out:
  3223. intel_display_power_put(dev_priv, power_domain);
  3224. return status;
  3225. }
  3226. static int intel_dp_get_modes(struct drm_connector *connector)
  3227. {
  3228. struct intel_dp *intel_dp = intel_attached_dp(connector);
  3229. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  3230. struct intel_encoder *intel_encoder = &intel_dig_port->base;
  3231. struct intel_connector *intel_connector = to_intel_connector(connector);
  3232. struct drm_device *dev = connector->dev;
  3233. struct drm_i915_private *dev_priv = dev->dev_private;
  3234. enum intel_display_power_domain power_domain;
  3235. int ret;
  3236. /* We should parse the EDID data and find out if it has an audio sink
  3237. */
  3238. power_domain = intel_display_port_power_domain(intel_encoder);
  3239. intel_display_power_get(dev_priv, power_domain);
  3240. ret = intel_dp_get_edid_modes(connector, &intel_dp->aux.ddc);
  3241. intel_display_power_put(dev_priv, power_domain);
  3242. if (ret)
  3243. return ret;
  3244. /* if eDP has no EDID, fall back to fixed mode */
  3245. if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
  3246. struct drm_display_mode *mode;
  3247. mode = drm_mode_duplicate(dev,
  3248. intel_connector->panel.fixed_mode);
  3249. if (mode) {
  3250. drm_mode_probed_add(connector, mode);
  3251. return 1;
  3252. }
  3253. }
  3254. return 0;
  3255. }
  3256. static bool
  3257. intel_dp_detect_audio(struct drm_connector *connector)
  3258. {
  3259. struct intel_dp *intel_dp = intel_attached_dp(connector);
  3260. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  3261. struct intel_encoder *intel_encoder = &intel_dig_port->base;
  3262. struct drm_device *dev = connector->dev;
  3263. struct drm_i915_private *dev_priv = dev->dev_private;
  3264. enum intel_display_power_domain power_domain;
  3265. struct edid *edid;
  3266. bool has_audio = false;
  3267. power_domain = intel_display_port_power_domain(intel_encoder);
  3268. intel_display_power_get(dev_priv, power_domain);
  3269. edid = intel_dp_get_edid(connector, &intel_dp->aux.ddc);
  3270. if (edid) {
  3271. has_audio = drm_detect_monitor_audio(edid);
  3272. kfree(edid);
  3273. }
  3274. intel_display_power_put(dev_priv, power_domain);
  3275. return has_audio;
  3276. }
  3277. static int
  3278. intel_dp_set_property(struct drm_connector *connector,
  3279. struct drm_property *property,
  3280. uint64_t val)
  3281. {
  3282. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  3283. struct intel_connector *intel_connector = to_intel_connector(connector);
  3284. struct intel_encoder *intel_encoder = intel_attached_encoder(connector);
  3285. struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
  3286. int ret;
  3287. ret = drm_object_property_set_value(&connector->base, property, val);
  3288. if (ret)
  3289. return ret;
  3290. if (property == dev_priv->force_audio_property) {
  3291. int i = val;
  3292. bool has_audio;
  3293. if (i == intel_dp->force_audio)
  3294. return 0;
  3295. intel_dp->force_audio = i;
  3296. if (i == HDMI_AUDIO_AUTO)
  3297. has_audio = intel_dp_detect_audio(connector);
  3298. else
  3299. has_audio = (i == HDMI_AUDIO_ON);
  3300. if (has_audio == intel_dp->has_audio)
  3301. return 0;
  3302. intel_dp->has_audio = has_audio;
  3303. goto done;
  3304. }
  3305. if (property == dev_priv->broadcast_rgb_property) {
  3306. bool old_auto = intel_dp->color_range_auto;
  3307. uint32_t old_range = intel_dp->color_range;
  3308. switch (val) {
  3309. case INTEL_BROADCAST_RGB_AUTO:
  3310. intel_dp->color_range_auto = true;
  3311. break;
  3312. case INTEL_BROADCAST_RGB_FULL:
  3313. intel_dp->color_range_auto = false;
  3314. intel_dp->color_range = 0;
  3315. break;
  3316. case INTEL_BROADCAST_RGB_LIMITED:
  3317. intel_dp->color_range_auto = false;
  3318. intel_dp->color_range = DP_COLOR_RANGE_16_235;
  3319. break;
  3320. default:
  3321. return -EINVAL;
  3322. }
  3323. if (old_auto == intel_dp->color_range_auto &&
  3324. old_range == intel_dp->color_range)
  3325. return 0;
  3326. goto done;
  3327. }
  3328. if (is_edp(intel_dp) &&
  3329. property == connector->dev->mode_config.scaling_mode_property) {
  3330. if (val == DRM_MODE_SCALE_NONE) {
  3331. DRM_DEBUG_KMS("no scaling not supported\n");
  3332. return -EINVAL;
  3333. }
  3334. if (intel_connector->panel.fitting_mode == val) {
  3335. /* the eDP scaling property is not changed */
  3336. return 0;
  3337. }
  3338. intel_connector->panel.fitting_mode = val;
  3339. goto done;
  3340. }
  3341. return -EINVAL;
  3342. done:
  3343. if (intel_encoder->base.crtc)
  3344. intel_crtc_restore_mode(intel_encoder->base.crtc);
  3345. return 0;
  3346. }
  3347. static void
  3348. intel_dp_connector_destroy(struct drm_connector *connector)
  3349. {
  3350. struct intel_connector *intel_connector = to_intel_connector(connector);
  3351. if (!IS_ERR_OR_NULL(intel_connector->edid))
  3352. kfree(intel_connector->edid);
  3353. /* Can't call is_edp() since the encoder may have been destroyed
  3354. * already. */
  3355. if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
  3356. intel_panel_fini(&intel_connector->panel);
  3357. drm_connector_cleanup(connector);
  3358. kfree(connector);
  3359. }
  3360. void intel_dp_encoder_destroy(struct drm_encoder *encoder)
  3361. {
  3362. struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
  3363. struct intel_dp *intel_dp = &intel_dig_port->dp;
  3364. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  3365. drm_dp_aux_unregister(&intel_dp->aux);
  3366. intel_dp_mst_encoder_cleanup(intel_dig_port);
  3367. drm_encoder_cleanup(encoder);
  3368. if (is_edp(intel_dp)) {
  3369. cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
  3370. drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
  3371. edp_panel_vdd_off_sync(intel_dp);
  3372. drm_modeset_unlock(&dev->mode_config.connection_mutex);
  3373. if (intel_dp->edp_notifier.notifier_call) {
  3374. unregister_reboot_notifier(&intel_dp->edp_notifier);
  3375. intel_dp->edp_notifier.notifier_call = NULL;
  3376. }
  3377. }
  3378. kfree(intel_dig_port);
  3379. }
  3380. static void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder)
  3381. {
  3382. struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
  3383. if (!is_edp(intel_dp))
  3384. return;
  3385. edp_panel_vdd_off_sync(intel_dp);
  3386. }
  3387. static void intel_dp_encoder_reset(struct drm_encoder *encoder)
  3388. {
  3389. intel_edp_panel_vdd_sanitize(to_intel_encoder(encoder));
  3390. }
  3391. static const struct drm_connector_funcs intel_dp_connector_funcs = {
  3392. .dpms = intel_connector_dpms,
  3393. .detect = intel_dp_detect,
  3394. .fill_modes = drm_helper_probe_single_connector_modes,
  3395. .set_property = intel_dp_set_property,
  3396. .destroy = intel_dp_connector_destroy,
  3397. };
  3398. static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
  3399. .get_modes = intel_dp_get_modes,
  3400. .mode_valid = intel_dp_mode_valid,
  3401. .best_encoder = intel_best_encoder,
  3402. };
  3403. static const struct drm_encoder_funcs intel_dp_enc_funcs = {
  3404. .reset = intel_dp_encoder_reset,
  3405. .destroy = intel_dp_encoder_destroy,
  3406. };
  3407. void
  3408. intel_dp_hot_plug(struct intel_encoder *intel_encoder)
  3409. {
  3410. return;
  3411. }
  3412. bool
  3413. intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd)
  3414. {
  3415. struct intel_dp *intel_dp = &intel_dig_port->dp;
  3416. struct intel_encoder *intel_encoder = &intel_dig_port->base;
  3417. struct drm_device *dev = intel_dig_port->base.base.dev;
  3418. struct drm_i915_private *dev_priv = dev->dev_private;
  3419. enum intel_display_power_domain power_domain;
  3420. bool ret = true;
  3421. if (intel_dig_port->base.type != INTEL_OUTPUT_EDP)
  3422. intel_dig_port->base.type = INTEL_OUTPUT_DISPLAYPORT;
  3423. DRM_DEBUG_KMS("got hpd irq on port %d - %s\n", intel_dig_port->port,
  3424. long_hpd ? "long" : "short");
  3425. power_domain = intel_display_port_power_domain(intel_encoder);
  3426. intel_display_power_get(dev_priv, power_domain);
  3427. if (long_hpd) {
  3428. if (HAS_PCH_SPLIT(dev)) {
  3429. if (!ibx_digital_port_connected(dev_priv, intel_dig_port))
  3430. goto mst_fail;
  3431. } else {
  3432. if (g4x_digital_port_connected(dev, intel_dig_port) != 1)
  3433. goto mst_fail;
  3434. }
  3435. if (!intel_dp_get_dpcd(intel_dp)) {
  3436. goto mst_fail;
  3437. }
  3438. intel_dp_probe_oui(intel_dp);
  3439. if (!intel_dp_probe_mst(intel_dp))
  3440. goto mst_fail;
  3441. } else {
  3442. if (intel_dp->is_mst) {
  3443. if (intel_dp_check_mst_status(intel_dp) == -EINVAL)
  3444. goto mst_fail;
  3445. }
  3446. if (!intel_dp->is_mst) {
  3447. /*
  3448. * we'll check the link status via the normal hot plug path later -
  3449. * but for short hpds we should check it now
  3450. */
  3451. drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
  3452. intel_dp_check_link_status(intel_dp);
  3453. drm_modeset_unlock(&dev->mode_config.connection_mutex);
  3454. }
  3455. }
  3456. ret = false;
  3457. goto put_power;
  3458. mst_fail:
  3459. /* if we were in MST mode, and device is not there get out of MST mode */
  3460. if (intel_dp->is_mst) {
  3461. DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n", intel_dp->is_mst, intel_dp->mst_mgr.mst_state);
  3462. intel_dp->is_mst = false;
  3463. drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
  3464. }
  3465. put_power:
  3466. intel_display_power_put(dev_priv, power_domain);
  3467. return ret;
  3468. }
  3469. /* Return which DP Port should be selected for Transcoder DP control */
  3470. int
  3471. intel_trans_dp_port_sel(struct drm_crtc *crtc)
  3472. {
  3473. struct drm_device *dev = crtc->dev;
  3474. struct intel_encoder *intel_encoder;
  3475. struct intel_dp *intel_dp;
  3476. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  3477. intel_dp = enc_to_intel_dp(&intel_encoder->base);
  3478. if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT ||
  3479. intel_encoder->type == INTEL_OUTPUT_EDP)
  3480. return intel_dp->output_reg;
  3481. }
  3482. return -1;
  3483. }
  3484. /* check the VBT to see whether the eDP is on DP-D port */
  3485. bool intel_dp_is_edp(struct drm_device *dev, enum port port)
  3486. {
  3487. struct drm_i915_private *dev_priv = dev->dev_private;
  3488. union child_device_config *p_child;
  3489. int i;
  3490. static const short port_mapping[] = {
  3491. [PORT_B] = PORT_IDPB,
  3492. [PORT_C] = PORT_IDPC,
  3493. [PORT_D] = PORT_IDPD,
  3494. };
  3495. if (port == PORT_A)
  3496. return true;
  3497. if (!dev_priv->vbt.child_dev_num)
  3498. return false;
  3499. for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
  3500. p_child = dev_priv->vbt.child_dev + i;
  3501. if (p_child->common.dvo_port == port_mapping[port] &&
  3502. (p_child->common.device_type & DEVICE_TYPE_eDP_BITS) ==
  3503. (DEVICE_TYPE_eDP & DEVICE_TYPE_eDP_BITS))
  3504. return true;
  3505. }
  3506. return false;
  3507. }
  3508. void
  3509. intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
  3510. {
  3511. struct intel_connector *intel_connector = to_intel_connector(connector);
  3512. intel_attach_force_audio_property(connector);
  3513. intel_attach_broadcast_rgb_property(connector);
  3514. intel_dp->color_range_auto = true;
  3515. if (is_edp(intel_dp)) {
  3516. drm_mode_create_scaling_mode_property(connector->dev);
  3517. drm_object_attach_property(
  3518. &connector->base,
  3519. connector->dev->mode_config.scaling_mode_property,
  3520. DRM_MODE_SCALE_ASPECT);
  3521. intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
  3522. }
  3523. }
  3524. static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp)
  3525. {
  3526. intel_dp->last_power_cycle = jiffies;
  3527. intel_dp->last_power_on = jiffies;
  3528. intel_dp->last_backlight_off = jiffies;
  3529. }
  3530. static void
  3531. intel_dp_init_panel_power_sequencer(struct drm_device *dev,
  3532. struct intel_dp *intel_dp,
  3533. struct edp_power_seq *out)
  3534. {
  3535. struct drm_i915_private *dev_priv = dev->dev_private;
  3536. struct edp_power_seq cur, vbt, spec, final;
  3537. u32 pp_on, pp_off, pp_div, pp;
  3538. int pp_ctrl_reg, pp_on_reg, pp_off_reg, pp_div_reg;
  3539. if (HAS_PCH_SPLIT(dev)) {
  3540. pp_ctrl_reg = PCH_PP_CONTROL;
  3541. pp_on_reg = PCH_PP_ON_DELAYS;
  3542. pp_off_reg = PCH_PP_OFF_DELAYS;
  3543. pp_div_reg = PCH_PP_DIVISOR;
  3544. } else {
  3545. enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
  3546. pp_ctrl_reg = VLV_PIPE_PP_CONTROL(pipe);
  3547. pp_on_reg = VLV_PIPE_PP_ON_DELAYS(pipe);
  3548. pp_off_reg = VLV_PIPE_PP_OFF_DELAYS(pipe);
  3549. pp_div_reg = VLV_PIPE_PP_DIVISOR(pipe);
  3550. }
  3551. /* Workaround: Need to write PP_CONTROL with the unlock key as
  3552. * the very first thing. */
  3553. pp = ironlake_get_pp_control(intel_dp);
  3554. I915_WRITE(pp_ctrl_reg, pp);
  3555. pp_on = I915_READ(pp_on_reg);
  3556. pp_off = I915_READ(pp_off_reg);
  3557. pp_div = I915_READ(pp_div_reg);
  3558. /* Pull timing values out of registers */
  3559. cur.t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
  3560. PANEL_POWER_UP_DELAY_SHIFT;
  3561. cur.t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
  3562. PANEL_LIGHT_ON_DELAY_SHIFT;
  3563. cur.t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
  3564. PANEL_LIGHT_OFF_DELAY_SHIFT;
  3565. cur.t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
  3566. PANEL_POWER_DOWN_DELAY_SHIFT;
  3567. cur.t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
  3568. PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
  3569. DRM_DEBUG_KMS("cur t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
  3570. cur.t1_t3, cur.t8, cur.t9, cur.t10, cur.t11_t12);
  3571. vbt = dev_priv->vbt.edp_pps;
  3572. /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
  3573. * our hw here, which are all in 100usec. */
  3574. spec.t1_t3 = 210 * 10;
  3575. spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
  3576. spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
  3577. spec.t10 = 500 * 10;
  3578. /* This one is special and actually in units of 100ms, but zero
  3579. * based in the hw (so we need to add 100 ms). But the sw vbt
  3580. * table multiplies it with 1000 to make it in units of 100usec,
  3581. * too. */
  3582. spec.t11_t12 = (510 + 100) * 10;
  3583. DRM_DEBUG_KMS("vbt t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
  3584. vbt.t1_t3, vbt.t8, vbt.t9, vbt.t10, vbt.t11_t12);
  3585. /* Use the max of the register settings and vbt. If both are
  3586. * unset, fall back to the spec limits. */
  3587. #define assign_final(field) final.field = (max(cur.field, vbt.field) == 0 ? \
  3588. spec.field : \
  3589. max(cur.field, vbt.field))
  3590. assign_final(t1_t3);
  3591. assign_final(t8);
  3592. assign_final(t9);
  3593. assign_final(t10);
  3594. assign_final(t11_t12);
  3595. #undef assign_final
  3596. #define get_delay(field) (DIV_ROUND_UP(final.field, 10))
  3597. intel_dp->panel_power_up_delay = get_delay(t1_t3);
  3598. intel_dp->backlight_on_delay = get_delay(t8);
  3599. intel_dp->backlight_off_delay = get_delay(t9);
  3600. intel_dp->panel_power_down_delay = get_delay(t10);
  3601. intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
  3602. #undef get_delay
  3603. DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
  3604. intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
  3605. intel_dp->panel_power_cycle_delay);
  3606. DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
  3607. intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
  3608. if (out)
  3609. *out = final;
  3610. }
  3611. static void
  3612. intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
  3613. struct intel_dp *intel_dp,
  3614. struct edp_power_seq *seq)
  3615. {
  3616. struct drm_i915_private *dev_priv = dev->dev_private;
  3617. u32 pp_on, pp_off, pp_div, port_sel = 0;
  3618. int div = HAS_PCH_SPLIT(dev) ? intel_pch_rawclk(dev) : intel_hrawclk(dev);
  3619. int pp_on_reg, pp_off_reg, pp_div_reg;
  3620. if (HAS_PCH_SPLIT(dev)) {
  3621. pp_on_reg = PCH_PP_ON_DELAYS;
  3622. pp_off_reg = PCH_PP_OFF_DELAYS;
  3623. pp_div_reg = PCH_PP_DIVISOR;
  3624. } else {
  3625. enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
  3626. pp_on_reg = VLV_PIPE_PP_ON_DELAYS(pipe);
  3627. pp_off_reg = VLV_PIPE_PP_OFF_DELAYS(pipe);
  3628. pp_div_reg = VLV_PIPE_PP_DIVISOR(pipe);
  3629. }
  3630. /*
  3631. * And finally store the new values in the power sequencer. The
  3632. * backlight delays are set to 1 because we do manual waits on them. For
  3633. * T8, even BSpec recommends doing it. For T9, if we don't do this,
  3634. * we'll end up waiting for the backlight off delay twice: once when we
  3635. * do the manual sleep, and once when we disable the panel and wait for
  3636. * the PP_STATUS bit to become zero.
  3637. */
  3638. pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
  3639. (1 << PANEL_LIGHT_ON_DELAY_SHIFT);
  3640. pp_off = (1 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
  3641. (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
  3642. /* Compute the divisor for the pp clock, simply match the Bspec
  3643. * formula. */
  3644. pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
  3645. pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
  3646. << PANEL_POWER_CYCLE_DELAY_SHIFT);
  3647. /* Haswell doesn't have any port selection bits for the panel
  3648. * power sequencer any more. */
  3649. if (IS_VALLEYVIEW(dev)) {
  3650. if (dp_to_dig_port(intel_dp)->port == PORT_B)
  3651. port_sel = PANEL_PORT_SELECT_DPB_VLV;
  3652. else
  3653. port_sel = PANEL_PORT_SELECT_DPC_VLV;
  3654. } else if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) {
  3655. if (dp_to_dig_port(intel_dp)->port == PORT_A)
  3656. port_sel = PANEL_PORT_SELECT_DPA;
  3657. else
  3658. port_sel = PANEL_PORT_SELECT_DPD;
  3659. }
  3660. pp_on |= port_sel;
  3661. I915_WRITE(pp_on_reg, pp_on);
  3662. I915_WRITE(pp_off_reg, pp_off);
  3663. I915_WRITE(pp_div_reg, pp_div);
  3664. DRM_DEBUG_KMS("panel power sequencer register settings: PP_ON %#x, PP_OFF %#x, PP_DIV %#x\n",
  3665. I915_READ(pp_on_reg),
  3666. I915_READ(pp_off_reg),
  3667. I915_READ(pp_div_reg));
  3668. }
  3669. void intel_dp_set_drrs_state(struct drm_device *dev, int refresh_rate)
  3670. {
  3671. struct drm_i915_private *dev_priv = dev->dev_private;
  3672. struct intel_encoder *encoder;
  3673. struct intel_dp *intel_dp = NULL;
  3674. struct intel_crtc_config *config = NULL;
  3675. struct intel_crtc *intel_crtc = NULL;
  3676. struct intel_connector *intel_connector = dev_priv->drrs.connector;
  3677. u32 reg, val;
  3678. enum edp_drrs_refresh_rate_type index = DRRS_HIGH_RR;
  3679. if (refresh_rate <= 0) {
  3680. DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n");
  3681. return;
  3682. }
  3683. if (intel_connector == NULL) {
  3684. DRM_DEBUG_KMS("DRRS supported for eDP only.\n");
  3685. return;
  3686. }
  3687. /*
  3688. * FIXME: This needs proper synchronization with psr state. But really
  3689. * hard to tell without seeing the user of this function of this code.
  3690. * Check locking and ordering once that lands.
  3691. */
  3692. if (INTEL_INFO(dev)->gen < 8 && intel_edp_is_psr_enabled(dev)) {
  3693. DRM_DEBUG_KMS("DRRS is disabled as PSR is enabled\n");
  3694. return;
  3695. }
  3696. encoder = intel_attached_encoder(&intel_connector->base);
  3697. intel_dp = enc_to_intel_dp(&encoder->base);
  3698. intel_crtc = encoder->new_crtc;
  3699. if (!intel_crtc) {
  3700. DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n");
  3701. return;
  3702. }
  3703. config = &intel_crtc->config;
  3704. if (intel_dp->drrs_state.type < SEAMLESS_DRRS_SUPPORT) {
  3705. DRM_DEBUG_KMS("Only Seamless DRRS supported.\n");
  3706. return;
  3707. }
  3708. if (intel_connector->panel.downclock_mode->vrefresh == refresh_rate)
  3709. index = DRRS_LOW_RR;
  3710. if (index == intel_dp->drrs_state.refresh_rate_type) {
  3711. DRM_DEBUG_KMS(
  3712. "DRRS requested for previously set RR...ignoring\n");
  3713. return;
  3714. }
  3715. if (!intel_crtc->active) {
  3716. DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n");
  3717. return;
  3718. }
  3719. if (INTEL_INFO(dev)->gen > 6 && INTEL_INFO(dev)->gen < 8) {
  3720. reg = PIPECONF(intel_crtc->config.cpu_transcoder);
  3721. val = I915_READ(reg);
  3722. if (index > DRRS_HIGH_RR) {
  3723. val |= PIPECONF_EDP_RR_MODE_SWITCH;
  3724. intel_dp_set_m2_n2(intel_crtc, &config->dp_m2_n2);
  3725. } else {
  3726. val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
  3727. }
  3728. I915_WRITE(reg, val);
  3729. }
  3730. /*
  3731. * mutex taken to ensure that there is no race between differnt
  3732. * drrs calls trying to update refresh rate. This scenario may occur
  3733. * in future when idleness detection based DRRS in kernel and
  3734. * possible calls from user space to set differnt RR are made.
  3735. */
  3736. mutex_lock(&intel_dp->drrs_state.mutex);
  3737. intel_dp->drrs_state.refresh_rate_type = index;
  3738. mutex_unlock(&intel_dp->drrs_state.mutex);
  3739. DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
  3740. }
  3741. static struct drm_display_mode *
  3742. intel_dp_drrs_init(struct intel_digital_port *intel_dig_port,
  3743. struct intel_connector *intel_connector,
  3744. struct drm_display_mode *fixed_mode)
  3745. {
  3746. struct drm_connector *connector = &intel_connector->base;
  3747. struct intel_dp *intel_dp = &intel_dig_port->dp;
  3748. struct drm_device *dev = intel_dig_port->base.base.dev;
  3749. struct drm_i915_private *dev_priv = dev->dev_private;
  3750. struct drm_display_mode *downclock_mode = NULL;
  3751. if (INTEL_INFO(dev)->gen <= 6) {
  3752. DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n");
  3753. return NULL;
  3754. }
  3755. if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) {
  3756. DRM_INFO("VBT doesn't support DRRS\n");
  3757. return NULL;
  3758. }
  3759. downclock_mode = intel_find_panel_downclock
  3760. (dev, fixed_mode, connector);
  3761. if (!downclock_mode) {
  3762. DRM_INFO("DRRS not supported\n");
  3763. return NULL;
  3764. }
  3765. dev_priv->drrs.connector = intel_connector;
  3766. mutex_init(&intel_dp->drrs_state.mutex);
  3767. intel_dp->drrs_state.type = dev_priv->vbt.drrs_type;
  3768. intel_dp->drrs_state.refresh_rate_type = DRRS_HIGH_RR;
  3769. DRM_INFO("seamless DRRS supported for eDP panel.\n");
  3770. return downclock_mode;
  3771. }
  3772. void intel_edp_panel_vdd_sanitize(struct intel_encoder *intel_encoder)
  3773. {
  3774. struct drm_device *dev = intel_encoder->base.dev;
  3775. struct drm_i915_private *dev_priv = dev->dev_private;
  3776. struct intel_dp *intel_dp;
  3777. enum intel_display_power_domain power_domain;
  3778. if (intel_encoder->type != INTEL_OUTPUT_EDP)
  3779. return;
  3780. intel_dp = enc_to_intel_dp(&intel_encoder->base);
  3781. if (!edp_have_panel_vdd(intel_dp))
  3782. return;
  3783. /*
  3784. * The VDD bit needs a power domain reference, so if the bit is
  3785. * already enabled when we boot or resume, grab this reference and
  3786. * schedule a vdd off, so we don't hold on to the reference
  3787. * indefinitely.
  3788. */
  3789. DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n");
  3790. power_domain = intel_display_port_power_domain(intel_encoder);
  3791. intel_display_power_get(dev_priv, power_domain);
  3792. edp_panel_vdd_schedule_off(intel_dp);
  3793. }
  3794. static bool intel_edp_init_connector(struct intel_dp *intel_dp,
  3795. struct intel_connector *intel_connector,
  3796. struct edp_power_seq *power_seq)
  3797. {
  3798. struct drm_connector *connector = &intel_connector->base;
  3799. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  3800. struct intel_encoder *intel_encoder = &intel_dig_port->base;
  3801. struct drm_device *dev = intel_encoder->base.dev;
  3802. struct drm_i915_private *dev_priv = dev->dev_private;
  3803. struct drm_display_mode *fixed_mode = NULL;
  3804. struct drm_display_mode *downclock_mode = NULL;
  3805. bool has_dpcd;
  3806. struct drm_display_mode *scan;
  3807. struct edid *edid;
  3808. intel_dp->drrs_state.type = DRRS_NOT_SUPPORTED;
  3809. if (!is_edp(intel_dp))
  3810. return true;
  3811. intel_edp_panel_vdd_sanitize(intel_encoder);
  3812. /* Cache DPCD and EDID for edp. */
  3813. intel_edp_panel_vdd_on(intel_dp);
  3814. has_dpcd = intel_dp_get_dpcd(intel_dp);
  3815. edp_panel_vdd_off(intel_dp, false);
  3816. if (has_dpcd) {
  3817. if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
  3818. dev_priv->no_aux_handshake =
  3819. intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
  3820. DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
  3821. } else {
  3822. /* if this fails, presume the device is a ghost */
  3823. DRM_INFO("failed to retrieve link info, disabling eDP\n");
  3824. return false;
  3825. }
  3826. /* We now know it's not a ghost, init power sequence regs. */
  3827. intel_dp_init_panel_power_sequencer_registers(dev, intel_dp, power_seq);
  3828. mutex_lock(&dev->mode_config.mutex);
  3829. edid = drm_get_edid(connector, &intel_dp->aux.ddc);
  3830. if (edid) {
  3831. if (drm_add_edid_modes(connector, edid)) {
  3832. drm_mode_connector_update_edid_property(connector,
  3833. edid);
  3834. drm_edid_to_eld(connector, edid);
  3835. } else {
  3836. kfree(edid);
  3837. edid = ERR_PTR(-EINVAL);
  3838. }
  3839. } else {
  3840. edid = ERR_PTR(-ENOENT);
  3841. }
  3842. intel_connector->edid = edid;
  3843. /* prefer fixed mode from EDID if available */
  3844. list_for_each_entry(scan, &connector->probed_modes, head) {
  3845. if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
  3846. fixed_mode = drm_mode_duplicate(dev, scan);
  3847. downclock_mode = intel_dp_drrs_init(
  3848. intel_dig_port,
  3849. intel_connector, fixed_mode);
  3850. break;
  3851. }
  3852. }
  3853. /* fallback to VBT if available for eDP */
  3854. if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
  3855. fixed_mode = drm_mode_duplicate(dev,
  3856. dev_priv->vbt.lfp_lvds_vbt_mode);
  3857. if (fixed_mode)
  3858. fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
  3859. }
  3860. mutex_unlock(&dev->mode_config.mutex);
  3861. if (IS_VALLEYVIEW(dev)) {
  3862. intel_dp->edp_notifier.notifier_call = edp_notify_handler;
  3863. register_reboot_notifier(&intel_dp->edp_notifier);
  3864. }
  3865. intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode);
  3866. intel_panel_setup_backlight(connector);
  3867. return true;
  3868. }
  3869. bool
  3870. intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
  3871. struct intel_connector *intel_connector)
  3872. {
  3873. struct drm_connector *connector = &intel_connector->base;
  3874. struct intel_dp *intel_dp = &intel_dig_port->dp;
  3875. struct intel_encoder *intel_encoder = &intel_dig_port->base;
  3876. struct drm_device *dev = intel_encoder->base.dev;
  3877. struct drm_i915_private *dev_priv = dev->dev_private;
  3878. enum port port = intel_dig_port->port;
  3879. struct edp_power_seq power_seq = { 0 };
  3880. int type;
  3881. /* intel_dp vfuncs */
  3882. if (IS_VALLEYVIEW(dev))
  3883. intel_dp->get_aux_clock_divider = vlv_get_aux_clock_divider;
  3884. else if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  3885. intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
  3886. else if (HAS_PCH_SPLIT(dev))
  3887. intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
  3888. else
  3889. intel_dp->get_aux_clock_divider = i9xx_get_aux_clock_divider;
  3890. intel_dp->get_aux_send_ctl = i9xx_get_aux_send_ctl;
  3891. /* Preserve the current hw state. */
  3892. intel_dp->DP = I915_READ(intel_dp->output_reg);
  3893. intel_dp->attached_connector = intel_connector;
  3894. if (intel_dp_is_edp(dev, port))
  3895. type = DRM_MODE_CONNECTOR_eDP;
  3896. else
  3897. type = DRM_MODE_CONNECTOR_DisplayPort;
  3898. /*
  3899. * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
  3900. * for DP the encoder type can be set by the caller to
  3901. * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
  3902. */
  3903. if (type == DRM_MODE_CONNECTOR_eDP)
  3904. intel_encoder->type = INTEL_OUTPUT_EDP;
  3905. DRM_DEBUG_KMS("Adding %s connector on port %c\n",
  3906. type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
  3907. port_name(port));
  3908. drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
  3909. drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
  3910. connector->interlace_allowed = true;
  3911. connector->doublescan_allowed = 0;
  3912. INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
  3913. edp_panel_vdd_work);
  3914. intel_connector_attach_encoder(intel_connector, intel_encoder);
  3915. drm_connector_register(connector);
  3916. if (HAS_DDI(dev))
  3917. intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
  3918. else
  3919. intel_connector->get_hw_state = intel_connector_get_hw_state;
  3920. intel_connector->unregister = intel_dp_connector_unregister;
  3921. /* Set up the hotplug pin. */
  3922. switch (port) {
  3923. case PORT_A:
  3924. intel_encoder->hpd_pin = HPD_PORT_A;
  3925. break;
  3926. case PORT_B:
  3927. intel_encoder->hpd_pin = HPD_PORT_B;
  3928. break;
  3929. case PORT_C:
  3930. intel_encoder->hpd_pin = HPD_PORT_C;
  3931. break;
  3932. case PORT_D:
  3933. intel_encoder->hpd_pin = HPD_PORT_D;
  3934. break;
  3935. default:
  3936. BUG();
  3937. }
  3938. if (is_edp(intel_dp)) {
  3939. intel_dp_init_panel_power_timestamps(intel_dp);
  3940. intel_dp_init_panel_power_sequencer(dev, intel_dp, &power_seq);
  3941. }
  3942. intel_dp_aux_init(intel_dp, intel_connector);
  3943. /* init MST on ports that can support it */
  3944. if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  3945. if (port == PORT_B || port == PORT_C || port == PORT_D) {
  3946. intel_dp_mst_encoder_init(intel_dig_port, intel_connector->base.base.id);
  3947. }
  3948. }
  3949. if (!intel_edp_init_connector(intel_dp, intel_connector, &power_seq)) {
  3950. drm_dp_aux_unregister(&intel_dp->aux);
  3951. if (is_edp(intel_dp)) {
  3952. cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
  3953. drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
  3954. edp_panel_vdd_off_sync(intel_dp);
  3955. drm_modeset_unlock(&dev->mode_config.connection_mutex);
  3956. }
  3957. drm_connector_unregister(connector);
  3958. drm_connector_cleanup(connector);
  3959. return false;
  3960. }
  3961. intel_dp_add_properties(intel_dp, connector);
  3962. /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
  3963. * 0xd. Failure to do so will result in spurious interrupts being
  3964. * generated on the port when a cable is not attached.
  3965. */
  3966. if (IS_G4X(dev) && !IS_GM45(dev)) {
  3967. u32 temp = I915_READ(PEG_BAND_GAP_DATA);
  3968. I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
  3969. }
  3970. return true;
  3971. }
  3972. void
  3973. intel_dp_init(struct drm_device *dev, int output_reg, enum port port)
  3974. {
  3975. struct drm_i915_private *dev_priv = dev->dev_private;
  3976. struct intel_digital_port *intel_dig_port;
  3977. struct intel_encoder *intel_encoder;
  3978. struct drm_encoder *encoder;
  3979. struct intel_connector *intel_connector;
  3980. intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
  3981. if (!intel_dig_port)
  3982. return;
  3983. intel_connector = kzalloc(sizeof(*intel_connector), GFP_KERNEL);
  3984. if (!intel_connector) {
  3985. kfree(intel_dig_port);
  3986. return;
  3987. }
  3988. intel_encoder = &intel_dig_port->base;
  3989. encoder = &intel_encoder->base;
  3990. drm_encoder_init(dev, &intel_encoder->base, &intel_dp_enc_funcs,
  3991. DRM_MODE_ENCODER_TMDS);
  3992. intel_encoder->compute_config = intel_dp_compute_config;
  3993. intel_encoder->disable = intel_disable_dp;
  3994. intel_encoder->get_hw_state = intel_dp_get_hw_state;
  3995. intel_encoder->get_config = intel_dp_get_config;
  3996. intel_encoder->suspend = intel_dp_encoder_suspend;
  3997. if (IS_CHERRYVIEW(dev)) {
  3998. intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable;
  3999. intel_encoder->pre_enable = chv_pre_enable_dp;
  4000. intel_encoder->enable = vlv_enable_dp;
  4001. intel_encoder->post_disable = chv_post_disable_dp;
  4002. } else if (IS_VALLEYVIEW(dev)) {
  4003. intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
  4004. intel_encoder->pre_enable = vlv_pre_enable_dp;
  4005. intel_encoder->enable = vlv_enable_dp;
  4006. intel_encoder->post_disable = vlv_post_disable_dp;
  4007. } else {
  4008. intel_encoder->pre_enable = g4x_pre_enable_dp;
  4009. intel_encoder->enable = g4x_enable_dp;
  4010. intel_encoder->post_disable = g4x_post_disable_dp;
  4011. }
  4012. intel_dig_port->port = port;
  4013. intel_dig_port->dp.output_reg = output_reg;
  4014. intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
  4015. if (IS_CHERRYVIEW(dev)) {
  4016. if (port == PORT_D)
  4017. intel_encoder->crtc_mask = 1 << 2;
  4018. else
  4019. intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
  4020. } else {
  4021. intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
  4022. }
  4023. intel_encoder->cloneable = 0;
  4024. intel_encoder->hot_plug = intel_dp_hot_plug;
  4025. intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
  4026. dev_priv->hpd_irq_port[port] = intel_dig_port;
  4027. if (!intel_dp_init_connector(intel_dig_port, intel_connector)) {
  4028. drm_encoder_cleanup(encoder);
  4029. kfree(intel_dig_port);
  4030. kfree(intel_connector);
  4031. }
  4032. }
  4033. void intel_dp_mst_suspend(struct drm_device *dev)
  4034. {
  4035. struct drm_i915_private *dev_priv = dev->dev_private;
  4036. int i;
  4037. /* disable MST */
  4038. for (i = 0; i < I915_MAX_PORTS; i++) {
  4039. struct intel_digital_port *intel_dig_port = dev_priv->hpd_irq_port[i];
  4040. if (!intel_dig_port)
  4041. continue;
  4042. if (intel_dig_port->base.type == INTEL_OUTPUT_DISPLAYPORT) {
  4043. if (!intel_dig_port->dp.can_mst)
  4044. continue;
  4045. if (intel_dig_port->dp.is_mst)
  4046. drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr);
  4047. }
  4048. }
  4049. }
  4050. void intel_dp_mst_resume(struct drm_device *dev)
  4051. {
  4052. struct drm_i915_private *dev_priv = dev->dev_private;
  4053. int i;
  4054. for (i = 0; i < I915_MAX_PORTS; i++) {
  4055. struct intel_digital_port *intel_dig_port = dev_priv->hpd_irq_port[i];
  4056. if (!intel_dig_port)
  4057. continue;
  4058. if (intel_dig_port->base.type == INTEL_OUTPUT_DISPLAYPORT) {
  4059. int ret;
  4060. if (!intel_dig_port->dp.can_mst)
  4061. continue;
  4062. ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr);
  4063. if (ret != 0) {
  4064. intel_dp_check_mst_status(&intel_dig_port->dp);
  4065. }
  4066. }
  4067. }
  4068. }