intel_dp.c 138 KB

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