intel_dp.c 148 KB

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