intel_dp.c 148 KB

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