intel_dp.c 156 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695
  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_atomic_helper.h>
  34. #include <drm/drm_crtc.h>
  35. #include <drm/drm_crtc_helper.h>
  36. #include <drm/drm_edid.h>
  37. #include "intel_drv.h"
  38. #include <drm/i915_drm.h>
  39. #include "i915_drv.h"
  40. #define DP_LINK_CHECK_TIMEOUT (10 * 1000)
  41. /* Compliance test status bits */
  42. #define INTEL_DP_RESOLUTION_SHIFT_MASK 0
  43. #define INTEL_DP_RESOLUTION_PREFERRED (1 << INTEL_DP_RESOLUTION_SHIFT_MASK)
  44. #define INTEL_DP_RESOLUTION_STANDARD (2 << INTEL_DP_RESOLUTION_SHIFT_MASK)
  45. #define INTEL_DP_RESOLUTION_FAILSAFE (3 << INTEL_DP_RESOLUTION_SHIFT_MASK)
  46. struct dp_link_dpll {
  47. int clock;
  48. struct dpll dpll;
  49. };
  50. static const struct dp_link_dpll gen4_dpll[] = {
  51. { 162000,
  52. { .p1 = 2, .p2 = 10, .n = 2, .m1 = 23, .m2 = 8 } },
  53. { 270000,
  54. { .p1 = 1, .p2 = 10, .n = 1, .m1 = 14, .m2 = 2 } }
  55. };
  56. static const struct dp_link_dpll pch_dpll[] = {
  57. { 162000,
  58. { .p1 = 2, .p2 = 10, .n = 1, .m1 = 12, .m2 = 9 } },
  59. { 270000,
  60. { .p1 = 1, .p2 = 10, .n = 2, .m1 = 14, .m2 = 8 } }
  61. };
  62. static const struct dp_link_dpll vlv_dpll[] = {
  63. { 162000,
  64. { .p1 = 3, .p2 = 2, .n = 5, .m1 = 3, .m2 = 81 } },
  65. { 270000,
  66. { .p1 = 2, .p2 = 2, .n = 1, .m1 = 2, .m2 = 27 } }
  67. };
  68. /*
  69. * CHV supports eDP 1.4 that have more link rates.
  70. * Below only provides the fixed rate but exclude variable rate.
  71. */
  72. static const struct dp_link_dpll chv_dpll[] = {
  73. /*
  74. * CHV requires to program fractional division for m2.
  75. * m2 is stored in fixed point format using formula below
  76. * (m2_int << 22) | m2_fraction
  77. */
  78. { 162000, /* m2_int = 32, m2_fraction = 1677722 */
  79. { .p1 = 4, .p2 = 2, .n = 1, .m1 = 2, .m2 = 0x819999a } },
  80. { 270000, /* m2_int = 27, m2_fraction = 0 */
  81. { .p1 = 4, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } },
  82. { 540000, /* m2_int = 27, m2_fraction = 0 */
  83. { .p1 = 2, .p2 = 1, .n = 1, .m1 = 2, .m2 = 0x6c00000 } }
  84. };
  85. static const int bxt_rates[] = { 162000, 216000, 243000, 270000,
  86. 324000, 432000, 540000 };
  87. static const int skl_rates[] = { 162000, 216000, 270000,
  88. 324000, 432000, 540000 };
  89. static const int default_rates[] = { 162000, 270000, 540000 };
  90. /**
  91. * is_edp - is the given port attached to an eDP panel (either CPU or PCH)
  92. * @intel_dp: DP struct
  93. *
  94. * If a CPU or PCH DP output is attached to an eDP panel, this function
  95. * will return true, and false otherwise.
  96. */
  97. static bool is_edp(struct intel_dp *intel_dp)
  98. {
  99. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  100. return intel_dig_port->base.type == INTEL_OUTPUT_EDP;
  101. }
  102. static struct drm_device *intel_dp_to_dev(struct intel_dp *intel_dp)
  103. {
  104. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  105. return intel_dig_port->base.base.dev;
  106. }
  107. static struct intel_dp *intel_attached_dp(struct drm_connector *connector)
  108. {
  109. return enc_to_intel_dp(&intel_attached_encoder(connector)->base);
  110. }
  111. static void intel_dp_link_down(struct intel_dp *intel_dp);
  112. static bool edp_panel_vdd_on(struct intel_dp *intel_dp);
  113. static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync);
  114. static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp);
  115. static void vlv_steal_power_sequencer(struct drm_device *dev,
  116. enum pipe pipe);
  117. static void intel_dp_unset_edid(struct intel_dp *intel_dp);
  118. static int
  119. intel_dp_max_link_bw(struct intel_dp *intel_dp)
  120. {
  121. int max_link_bw = intel_dp->dpcd[DP_MAX_LINK_RATE];
  122. switch (max_link_bw) {
  123. case DP_LINK_BW_1_62:
  124. case DP_LINK_BW_2_7:
  125. case DP_LINK_BW_5_4:
  126. break;
  127. default:
  128. WARN(1, "invalid max DP link bw val %x, using 1.62Gbps\n",
  129. max_link_bw);
  130. max_link_bw = DP_LINK_BW_1_62;
  131. break;
  132. }
  133. return max_link_bw;
  134. }
  135. static u8 intel_dp_max_lane_count(struct intel_dp *intel_dp)
  136. {
  137. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  138. u8 source_max, sink_max;
  139. source_max = intel_dig_port->max_lanes;
  140. sink_max = drm_dp_max_lane_count(intel_dp->dpcd);
  141. return min(source_max, sink_max);
  142. }
  143. /*
  144. * The units on the numbers in the next two are... bizarre. Examples will
  145. * make it clearer; this one parallels an example in the eDP spec.
  146. *
  147. * intel_dp_max_data_rate for one lane of 2.7GHz evaluates as:
  148. *
  149. * 270000 * 1 * 8 / 10 == 216000
  150. *
  151. * The actual data capacity of that configuration is 2.16Gbit/s, so the
  152. * units are decakilobits. ->clock in a drm_display_mode is in kilohertz -
  153. * or equivalently, kilopixels per second - so for 1680x1050R it'd be
  154. * 119000. At 18bpp that's 2142000 kilobits per second.
  155. *
  156. * Thus the strange-looking division by 10 in intel_dp_link_required, to
  157. * get the result in decakilobits instead of kilobits.
  158. */
  159. static int
  160. intel_dp_link_required(int pixel_clock, int bpp)
  161. {
  162. return (pixel_clock * bpp + 9) / 10;
  163. }
  164. static int
  165. intel_dp_max_data_rate(int max_link_clock, int max_lanes)
  166. {
  167. return (max_link_clock * max_lanes * 8) / 10;
  168. }
  169. static enum drm_mode_status
  170. intel_dp_mode_valid(struct drm_connector *connector,
  171. struct drm_display_mode *mode)
  172. {
  173. struct intel_dp *intel_dp = intel_attached_dp(connector);
  174. struct intel_connector *intel_connector = to_intel_connector(connector);
  175. struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
  176. int target_clock = mode->clock;
  177. int max_rate, mode_rate, max_lanes, max_link_clock;
  178. int max_dotclk = to_i915(connector->dev)->max_dotclk_freq;
  179. if (is_edp(intel_dp) && fixed_mode) {
  180. if (mode->hdisplay > fixed_mode->hdisplay)
  181. return MODE_PANEL;
  182. if (mode->vdisplay > fixed_mode->vdisplay)
  183. return MODE_PANEL;
  184. target_clock = fixed_mode->clock;
  185. }
  186. max_link_clock = intel_dp_max_link_rate(intel_dp);
  187. max_lanes = intel_dp_max_lane_count(intel_dp);
  188. max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
  189. mode_rate = intel_dp_link_required(target_clock, 18);
  190. if (mode_rate > max_rate || target_clock > max_dotclk)
  191. return MODE_CLOCK_HIGH;
  192. if (mode->clock < 10000)
  193. return MODE_CLOCK_LOW;
  194. if (mode->flags & DRM_MODE_FLAG_DBLCLK)
  195. return MODE_H_ILLEGAL;
  196. return MODE_OK;
  197. }
  198. uint32_t intel_dp_pack_aux(const uint8_t *src, int src_bytes)
  199. {
  200. int i;
  201. uint32_t v = 0;
  202. if (src_bytes > 4)
  203. src_bytes = 4;
  204. for (i = 0; i < src_bytes; i++)
  205. v |= ((uint32_t) src[i]) << ((3-i) * 8);
  206. return v;
  207. }
  208. static void intel_dp_unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
  209. {
  210. int i;
  211. if (dst_bytes > 4)
  212. dst_bytes = 4;
  213. for (i = 0; i < dst_bytes; i++)
  214. dst[i] = src >> ((3-i) * 8);
  215. }
  216. static void
  217. intel_dp_init_panel_power_sequencer(struct drm_device *dev,
  218. struct intel_dp *intel_dp);
  219. static void
  220. intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
  221. struct intel_dp *intel_dp);
  222. static void pps_lock(struct intel_dp *intel_dp)
  223. {
  224. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  225. struct intel_encoder *encoder = &intel_dig_port->base;
  226. struct drm_device *dev = encoder->base.dev;
  227. struct drm_i915_private *dev_priv = dev->dev_private;
  228. enum intel_display_power_domain power_domain;
  229. /*
  230. * See vlv_power_sequencer_reset() why we need
  231. * a power domain reference here.
  232. */
  233. power_domain = intel_display_port_aux_power_domain(encoder);
  234. intel_display_power_get(dev_priv, power_domain);
  235. mutex_lock(&dev_priv->pps_mutex);
  236. }
  237. static void pps_unlock(struct intel_dp *intel_dp)
  238. {
  239. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  240. struct intel_encoder *encoder = &intel_dig_port->base;
  241. struct drm_device *dev = encoder->base.dev;
  242. struct drm_i915_private *dev_priv = dev->dev_private;
  243. enum intel_display_power_domain power_domain;
  244. mutex_unlock(&dev_priv->pps_mutex);
  245. power_domain = intel_display_port_aux_power_domain(encoder);
  246. intel_display_power_put(dev_priv, power_domain);
  247. }
  248. static void
  249. vlv_power_sequencer_kick(struct intel_dp *intel_dp)
  250. {
  251. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  252. struct drm_device *dev = intel_dig_port->base.base.dev;
  253. struct drm_i915_private *dev_priv = dev->dev_private;
  254. enum pipe pipe = intel_dp->pps_pipe;
  255. bool pll_enabled, release_cl_override = false;
  256. enum dpio_phy phy = DPIO_PHY(pipe);
  257. enum dpio_channel ch = vlv_pipe_to_channel(pipe);
  258. uint32_t DP;
  259. if (WARN(I915_READ(intel_dp->output_reg) & DP_PORT_EN,
  260. "skipping pipe %c power seqeuncer kick due to port %c being active\n",
  261. pipe_name(pipe), port_name(intel_dig_port->port)))
  262. return;
  263. DRM_DEBUG_KMS("kicking pipe %c power sequencer for port %c\n",
  264. pipe_name(pipe), port_name(intel_dig_port->port));
  265. /* Preserve the BIOS-computed detected bit. This is
  266. * supposed to be read-only.
  267. */
  268. DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
  269. DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
  270. DP |= DP_PORT_WIDTH(1);
  271. DP |= DP_LINK_TRAIN_PAT_1;
  272. if (IS_CHERRYVIEW(dev))
  273. DP |= DP_PIPE_SELECT_CHV(pipe);
  274. else if (pipe == PIPE_B)
  275. DP |= DP_PIPEB_SELECT;
  276. pll_enabled = I915_READ(DPLL(pipe)) & DPLL_VCO_ENABLE;
  277. /*
  278. * The DPLL for the pipe must be enabled for this to work.
  279. * So enable temporarily it if it's not already enabled.
  280. */
  281. if (!pll_enabled) {
  282. release_cl_override = IS_CHERRYVIEW(dev) &&
  283. !chv_phy_powergate_ch(dev_priv, phy, ch, true);
  284. if (vlv_force_pll_on(dev, pipe, IS_CHERRYVIEW(dev) ?
  285. &chv_dpll[0].dpll : &vlv_dpll[0].dpll)) {
  286. DRM_ERROR("Failed to force on pll for pipe %c!\n",
  287. pipe_name(pipe));
  288. return;
  289. }
  290. }
  291. /*
  292. * Similar magic as in intel_dp_enable_port().
  293. * We _must_ do this port enable + disable trick
  294. * to make this power seqeuencer lock onto the port.
  295. * Otherwise even VDD force bit won't work.
  296. */
  297. I915_WRITE(intel_dp->output_reg, DP);
  298. POSTING_READ(intel_dp->output_reg);
  299. I915_WRITE(intel_dp->output_reg, DP | DP_PORT_EN);
  300. POSTING_READ(intel_dp->output_reg);
  301. I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
  302. POSTING_READ(intel_dp->output_reg);
  303. if (!pll_enabled) {
  304. vlv_force_pll_off(dev, pipe);
  305. if (release_cl_override)
  306. chv_phy_powergate_ch(dev_priv, phy, ch, false);
  307. }
  308. }
  309. static enum pipe
  310. vlv_power_sequencer_pipe(struct intel_dp *intel_dp)
  311. {
  312. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  313. struct drm_device *dev = intel_dig_port->base.base.dev;
  314. struct drm_i915_private *dev_priv = dev->dev_private;
  315. struct intel_encoder *encoder;
  316. unsigned int pipes = (1 << PIPE_A) | (1 << PIPE_B);
  317. enum pipe pipe;
  318. lockdep_assert_held(&dev_priv->pps_mutex);
  319. /* We should never land here with regular DP ports */
  320. WARN_ON(!is_edp(intel_dp));
  321. if (intel_dp->pps_pipe != INVALID_PIPE)
  322. return intel_dp->pps_pipe;
  323. /*
  324. * We don't have power sequencer currently.
  325. * Pick one that's not used by other ports.
  326. */
  327. for_each_intel_encoder(dev, encoder) {
  328. struct intel_dp *tmp;
  329. if (encoder->type != INTEL_OUTPUT_EDP)
  330. continue;
  331. tmp = enc_to_intel_dp(&encoder->base);
  332. if (tmp->pps_pipe != INVALID_PIPE)
  333. pipes &= ~(1 << tmp->pps_pipe);
  334. }
  335. /*
  336. * Didn't find one. This should not happen since there
  337. * are two power sequencers and up to two eDP ports.
  338. */
  339. if (WARN_ON(pipes == 0))
  340. pipe = PIPE_A;
  341. else
  342. pipe = ffs(pipes) - 1;
  343. vlv_steal_power_sequencer(dev, pipe);
  344. intel_dp->pps_pipe = pipe;
  345. DRM_DEBUG_KMS("picked pipe %c power sequencer for port %c\n",
  346. pipe_name(intel_dp->pps_pipe),
  347. port_name(intel_dig_port->port));
  348. /* init power sequencer on this pipe and port */
  349. intel_dp_init_panel_power_sequencer(dev, intel_dp);
  350. intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
  351. /*
  352. * Even vdd force doesn't work until we've made
  353. * the power sequencer lock in on the port.
  354. */
  355. vlv_power_sequencer_kick(intel_dp);
  356. return intel_dp->pps_pipe;
  357. }
  358. typedef bool (*vlv_pipe_check)(struct drm_i915_private *dev_priv,
  359. enum pipe pipe);
  360. static bool vlv_pipe_has_pp_on(struct drm_i915_private *dev_priv,
  361. enum pipe pipe)
  362. {
  363. return I915_READ(VLV_PIPE_PP_STATUS(pipe)) & PP_ON;
  364. }
  365. static bool vlv_pipe_has_vdd_on(struct drm_i915_private *dev_priv,
  366. enum pipe pipe)
  367. {
  368. return I915_READ(VLV_PIPE_PP_CONTROL(pipe)) & EDP_FORCE_VDD;
  369. }
  370. static bool vlv_pipe_any(struct drm_i915_private *dev_priv,
  371. enum pipe pipe)
  372. {
  373. return true;
  374. }
  375. static enum pipe
  376. vlv_initial_pps_pipe(struct drm_i915_private *dev_priv,
  377. enum port port,
  378. vlv_pipe_check pipe_check)
  379. {
  380. enum pipe pipe;
  381. for (pipe = PIPE_A; pipe <= PIPE_B; pipe++) {
  382. u32 port_sel = I915_READ(VLV_PIPE_PP_ON_DELAYS(pipe)) &
  383. PANEL_PORT_SELECT_MASK;
  384. if (port_sel != PANEL_PORT_SELECT_VLV(port))
  385. continue;
  386. if (!pipe_check(dev_priv, pipe))
  387. continue;
  388. return pipe;
  389. }
  390. return INVALID_PIPE;
  391. }
  392. static void
  393. vlv_initial_power_sequencer_setup(struct intel_dp *intel_dp)
  394. {
  395. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  396. struct drm_device *dev = intel_dig_port->base.base.dev;
  397. struct drm_i915_private *dev_priv = dev->dev_private;
  398. enum port port = intel_dig_port->port;
  399. lockdep_assert_held(&dev_priv->pps_mutex);
  400. /* try to find a pipe with this port selected */
  401. /* first pick one where the panel is on */
  402. intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
  403. vlv_pipe_has_pp_on);
  404. /* didn't find one? pick one where vdd is on */
  405. if (intel_dp->pps_pipe == INVALID_PIPE)
  406. intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
  407. vlv_pipe_has_vdd_on);
  408. /* didn't find one? pick one with just the correct port */
  409. if (intel_dp->pps_pipe == INVALID_PIPE)
  410. intel_dp->pps_pipe = vlv_initial_pps_pipe(dev_priv, port,
  411. vlv_pipe_any);
  412. /* didn't find one? just let vlv_power_sequencer_pipe() pick one when needed */
  413. if (intel_dp->pps_pipe == INVALID_PIPE) {
  414. DRM_DEBUG_KMS("no initial power sequencer for port %c\n",
  415. port_name(port));
  416. return;
  417. }
  418. DRM_DEBUG_KMS("initial power sequencer for port %c: pipe %c\n",
  419. port_name(port), pipe_name(intel_dp->pps_pipe));
  420. intel_dp_init_panel_power_sequencer(dev, intel_dp);
  421. intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
  422. }
  423. void vlv_power_sequencer_reset(struct drm_i915_private *dev_priv)
  424. {
  425. struct drm_device *dev = dev_priv->dev;
  426. struct intel_encoder *encoder;
  427. if (WARN_ON(!IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev)))
  428. return;
  429. /*
  430. * We can't grab pps_mutex here due to deadlock with power_domain
  431. * mutex when power_domain functions are called while holding pps_mutex.
  432. * That also means that in order to use pps_pipe the code needs to
  433. * hold both a power domain reference and pps_mutex, and the power domain
  434. * reference get/put must be done while _not_ holding pps_mutex.
  435. * pps_{lock,unlock}() do these steps in the correct order, so one
  436. * should use them always.
  437. */
  438. for_each_intel_encoder(dev, encoder) {
  439. struct intel_dp *intel_dp;
  440. if (encoder->type != INTEL_OUTPUT_EDP)
  441. continue;
  442. intel_dp = enc_to_intel_dp(&encoder->base);
  443. intel_dp->pps_pipe = INVALID_PIPE;
  444. }
  445. }
  446. static i915_reg_t
  447. _pp_ctrl_reg(struct intel_dp *intel_dp)
  448. {
  449. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  450. if (IS_BROXTON(dev))
  451. return BXT_PP_CONTROL(0);
  452. else if (HAS_PCH_SPLIT(dev))
  453. return PCH_PP_CONTROL;
  454. else
  455. return VLV_PIPE_PP_CONTROL(vlv_power_sequencer_pipe(intel_dp));
  456. }
  457. static i915_reg_t
  458. _pp_stat_reg(struct intel_dp *intel_dp)
  459. {
  460. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  461. if (IS_BROXTON(dev))
  462. return BXT_PP_STATUS(0);
  463. else if (HAS_PCH_SPLIT(dev))
  464. return PCH_PP_STATUS;
  465. else
  466. return VLV_PIPE_PP_STATUS(vlv_power_sequencer_pipe(intel_dp));
  467. }
  468. /* Reboot notifier handler to shutdown panel power to guarantee T12 timing
  469. This function only applicable when panel PM state is not to be tracked */
  470. static int edp_notify_handler(struct notifier_block *this, unsigned long code,
  471. void *unused)
  472. {
  473. struct intel_dp *intel_dp = container_of(this, typeof(* intel_dp),
  474. edp_notifier);
  475. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  476. struct drm_i915_private *dev_priv = dev->dev_private;
  477. if (!is_edp(intel_dp) || code != SYS_RESTART)
  478. return 0;
  479. pps_lock(intel_dp);
  480. if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
  481. enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
  482. i915_reg_t pp_ctrl_reg, pp_div_reg;
  483. u32 pp_div;
  484. pp_ctrl_reg = VLV_PIPE_PP_CONTROL(pipe);
  485. pp_div_reg = VLV_PIPE_PP_DIVISOR(pipe);
  486. pp_div = I915_READ(pp_div_reg);
  487. pp_div &= PP_REFERENCE_DIVIDER_MASK;
  488. /* 0x1F write to PP_DIV_REG sets max cycle delay */
  489. I915_WRITE(pp_div_reg, pp_div | 0x1F);
  490. I915_WRITE(pp_ctrl_reg, PANEL_UNLOCK_REGS | PANEL_POWER_OFF);
  491. msleep(intel_dp->panel_power_cycle_delay);
  492. }
  493. pps_unlock(intel_dp);
  494. return 0;
  495. }
  496. static bool edp_have_panel_power(struct intel_dp *intel_dp)
  497. {
  498. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  499. struct drm_i915_private *dev_priv = dev->dev_private;
  500. lockdep_assert_held(&dev_priv->pps_mutex);
  501. if ((IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) &&
  502. intel_dp->pps_pipe == INVALID_PIPE)
  503. return false;
  504. return (I915_READ(_pp_stat_reg(intel_dp)) & PP_ON) != 0;
  505. }
  506. static bool edp_have_panel_vdd(struct intel_dp *intel_dp)
  507. {
  508. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  509. struct drm_i915_private *dev_priv = dev->dev_private;
  510. lockdep_assert_held(&dev_priv->pps_mutex);
  511. if ((IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) &&
  512. intel_dp->pps_pipe == INVALID_PIPE)
  513. return false;
  514. return I915_READ(_pp_ctrl_reg(intel_dp)) & EDP_FORCE_VDD;
  515. }
  516. static void
  517. intel_dp_check_edp(struct intel_dp *intel_dp)
  518. {
  519. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  520. struct drm_i915_private *dev_priv = dev->dev_private;
  521. if (!is_edp(intel_dp))
  522. return;
  523. if (!edp_have_panel_power(intel_dp) && !edp_have_panel_vdd(intel_dp)) {
  524. WARN(1, "eDP powered off while attempting aux channel communication.\n");
  525. DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
  526. I915_READ(_pp_stat_reg(intel_dp)),
  527. I915_READ(_pp_ctrl_reg(intel_dp)));
  528. }
  529. }
  530. static uint32_t
  531. intel_dp_aux_wait_done(struct intel_dp *intel_dp, bool has_aux_irq)
  532. {
  533. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  534. struct drm_device *dev = intel_dig_port->base.base.dev;
  535. struct drm_i915_private *dev_priv = dev->dev_private;
  536. i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
  537. uint32_t status;
  538. bool done;
  539. #define C (((status = I915_READ_NOTRACE(ch_ctl)) & DP_AUX_CH_CTL_SEND_BUSY) == 0)
  540. if (has_aux_irq)
  541. done = wait_event_timeout(dev_priv->gmbus_wait_queue, C,
  542. msecs_to_jiffies_timeout(10));
  543. else
  544. done = wait_for_atomic(C, 10) == 0;
  545. if (!done)
  546. DRM_ERROR("dp aux hw did not signal timeout (has irq: %i)!\n",
  547. has_aux_irq);
  548. #undef C
  549. return status;
  550. }
  551. static uint32_t g4x_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
  552. {
  553. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  554. struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
  555. if (index)
  556. return 0;
  557. /*
  558. * The clock divider is based off the hrawclk, and would like to run at
  559. * 2MHz. So, take the hrawclk value and divide by 2000 and use that
  560. */
  561. return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
  562. }
  563. static uint32_t ilk_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
  564. {
  565. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  566. struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
  567. if (index)
  568. return 0;
  569. /*
  570. * The clock divider is based off the cdclk or PCH rawclk, and would
  571. * like to run at 2MHz. So, take the cdclk or PCH rawclk value and
  572. * divide by 2000 and use that
  573. */
  574. if (intel_dig_port->port == PORT_A)
  575. return DIV_ROUND_CLOSEST(dev_priv->cdclk_freq, 2000);
  576. else
  577. return DIV_ROUND_CLOSEST(dev_priv->rawclk_freq, 2000);
  578. }
  579. static uint32_t hsw_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
  580. {
  581. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  582. struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
  583. if (intel_dig_port->port != PORT_A && HAS_PCH_LPT_H(dev_priv)) {
  584. /* Workaround for non-ULT HSW */
  585. switch (index) {
  586. case 0: return 63;
  587. case 1: return 72;
  588. default: return 0;
  589. }
  590. }
  591. return ilk_get_aux_clock_divider(intel_dp, index);
  592. }
  593. static uint32_t skl_get_aux_clock_divider(struct intel_dp *intel_dp, int index)
  594. {
  595. /*
  596. * SKL doesn't need us to program the AUX clock divider (Hardware will
  597. * derive the clock from CDCLK automatically). We still implement the
  598. * get_aux_clock_divider vfunc to plug-in into the existing code.
  599. */
  600. return index ? 0 : 1;
  601. }
  602. static uint32_t g4x_get_aux_send_ctl(struct intel_dp *intel_dp,
  603. bool has_aux_irq,
  604. int send_bytes,
  605. uint32_t aux_clock_divider)
  606. {
  607. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  608. struct drm_device *dev = intel_dig_port->base.base.dev;
  609. uint32_t precharge, timeout;
  610. if (IS_GEN6(dev))
  611. precharge = 3;
  612. else
  613. precharge = 5;
  614. if (IS_BROADWELL(dev) && intel_dig_port->port == PORT_A)
  615. timeout = DP_AUX_CH_CTL_TIME_OUT_600us;
  616. else
  617. timeout = DP_AUX_CH_CTL_TIME_OUT_400us;
  618. return DP_AUX_CH_CTL_SEND_BUSY |
  619. DP_AUX_CH_CTL_DONE |
  620. (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
  621. DP_AUX_CH_CTL_TIME_OUT_ERROR |
  622. timeout |
  623. DP_AUX_CH_CTL_RECEIVE_ERROR |
  624. (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
  625. (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
  626. (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT);
  627. }
  628. static uint32_t skl_get_aux_send_ctl(struct intel_dp *intel_dp,
  629. bool has_aux_irq,
  630. int send_bytes,
  631. uint32_t unused)
  632. {
  633. return DP_AUX_CH_CTL_SEND_BUSY |
  634. DP_AUX_CH_CTL_DONE |
  635. (has_aux_irq ? DP_AUX_CH_CTL_INTERRUPT : 0) |
  636. DP_AUX_CH_CTL_TIME_OUT_ERROR |
  637. DP_AUX_CH_CTL_TIME_OUT_1600us |
  638. DP_AUX_CH_CTL_RECEIVE_ERROR |
  639. (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
  640. DP_AUX_CH_CTL_FW_SYNC_PULSE_SKL(32) |
  641. DP_AUX_CH_CTL_SYNC_PULSE_SKL(32);
  642. }
  643. static int
  644. intel_dp_aux_ch(struct intel_dp *intel_dp,
  645. const uint8_t *send, int send_bytes,
  646. uint8_t *recv, int recv_size)
  647. {
  648. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  649. struct drm_device *dev = intel_dig_port->base.base.dev;
  650. struct drm_i915_private *dev_priv = dev->dev_private;
  651. i915_reg_t ch_ctl = intel_dp->aux_ch_ctl_reg;
  652. uint32_t aux_clock_divider;
  653. int i, ret, recv_bytes;
  654. uint32_t status;
  655. int try, clock = 0;
  656. bool has_aux_irq = HAS_AUX_IRQ(dev);
  657. bool vdd;
  658. pps_lock(intel_dp);
  659. /*
  660. * We will be called with VDD already enabled for dpcd/edid/oui reads.
  661. * In such cases we want to leave VDD enabled and it's up to upper layers
  662. * to turn it off. But for eg. i2c-dev access we need to turn it on/off
  663. * ourselves.
  664. */
  665. vdd = edp_panel_vdd_on(intel_dp);
  666. /* dp aux is extremely sensitive to irq latency, hence request the
  667. * lowest possible wakeup latency and so prevent the cpu from going into
  668. * deep sleep states.
  669. */
  670. pm_qos_update_request(&dev_priv->pm_qos, 0);
  671. intel_dp_check_edp(intel_dp);
  672. /* Try to wait for any previous AUX channel activity */
  673. for (try = 0; try < 3; try++) {
  674. status = I915_READ_NOTRACE(ch_ctl);
  675. if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
  676. break;
  677. msleep(1);
  678. }
  679. if (try == 3) {
  680. static u32 last_status = -1;
  681. const u32 status = I915_READ(ch_ctl);
  682. if (status != last_status) {
  683. WARN(1, "dp_aux_ch not started status 0x%08x\n",
  684. status);
  685. last_status = status;
  686. }
  687. ret = -EBUSY;
  688. goto out;
  689. }
  690. /* Only 5 data registers! */
  691. if (WARN_ON(send_bytes > 20 || recv_size > 20)) {
  692. ret = -E2BIG;
  693. goto out;
  694. }
  695. while ((aux_clock_divider = intel_dp->get_aux_clock_divider(intel_dp, clock++))) {
  696. u32 send_ctl = intel_dp->get_aux_send_ctl(intel_dp,
  697. has_aux_irq,
  698. send_bytes,
  699. aux_clock_divider);
  700. /* Must try at least 3 times according to DP spec */
  701. for (try = 0; try < 5; try++) {
  702. /* Load the send data into the aux channel data registers */
  703. for (i = 0; i < send_bytes; i += 4)
  704. I915_WRITE(intel_dp->aux_ch_data_reg[i >> 2],
  705. intel_dp_pack_aux(send + i,
  706. send_bytes - i));
  707. /* Send the command and wait for it to complete */
  708. I915_WRITE(ch_ctl, send_ctl);
  709. status = intel_dp_aux_wait_done(intel_dp, has_aux_irq);
  710. /* Clear done status and any errors */
  711. I915_WRITE(ch_ctl,
  712. status |
  713. DP_AUX_CH_CTL_DONE |
  714. DP_AUX_CH_CTL_TIME_OUT_ERROR |
  715. DP_AUX_CH_CTL_RECEIVE_ERROR);
  716. if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR)
  717. continue;
  718. /* DP CTS 1.2 Core Rev 1.1, 4.2.1.1 & 4.2.1.2
  719. * 400us delay required for errors and timeouts
  720. * Timeout errors from the HW already meet this
  721. * requirement so skip to next iteration
  722. */
  723. if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
  724. usleep_range(400, 500);
  725. continue;
  726. }
  727. if (status & DP_AUX_CH_CTL_DONE)
  728. goto done;
  729. }
  730. }
  731. if ((status & DP_AUX_CH_CTL_DONE) == 0) {
  732. DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
  733. ret = -EBUSY;
  734. goto out;
  735. }
  736. done:
  737. /* Check for timeout or receive error.
  738. * Timeouts occur when the sink is not connected
  739. */
  740. if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
  741. DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
  742. ret = -EIO;
  743. goto out;
  744. }
  745. /* Timeouts occur when the device isn't connected, so they're
  746. * "normal" -- don't fill the kernel log with these */
  747. if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
  748. DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
  749. ret = -ETIMEDOUT;
  750. goto out;
  751. }
  752. /* Unload any bytes sent back from the other side */
  753. recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
  754. DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
  755. /*
  756. * By BSpec: "Message sizes of 0 or >20 are not allowed."
  757. * We have no idea of what happened so we return -EBUSY so
  758. * drm layer takes care for the necessary retries.
  759. */
  760. if (recv_bytes == 0 || recv_bytes > 20) {
  761. DRM_DEBUG_KMS("Forbidden recv_bytes = %d on aux transaction\n",
  762. recv_bytes);
  763. /*
  764. * FIXME: This patch was created on top of a series that
  765. * organize the retries at drm level. There EBUSY should
  766. * also take care for 1ms wait before retrying.
  767. * That aux retries re-org is still needed and after that is
  768. * merged we remove this sleep from here.
  769. */
  770. usleep_range(1000, 1500);
  771. ret = -EBUSY;
  772. goto out;
  773. }
  774. if (recv_bytes > recv_size)
  775. recv_bytes = recv_size;
  776. for (i = 0; i < recv_bytes; i += 4)
  777. intel_dp_unpack_aux(I915_READ(intel_dp->aux_ch_data_reg[i >> 2]),
  778. recv + i, recv_bytes - i);
  779. ret = recv_bytes;
  780. out:
  781. pm_qos_update_request(&dev_priv->pm_qos, PM_QOS_DEFAULT_VALUE);
  782. if (vdd)
  783. edp_panel_vdd_off(intel_dp, false);
  784. pps_unlock(intel_dp);
  785. return ret;
  786. }
  787. #define BARE_ADDRESS_SIZE 3
  788. #define HEADER_SIZE (BARE_ADDRESS_SIZE + 1)
  789. static ssize_t
  790. intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
  791. {
  792. struct intel_dp *intel_dp = container_of(aux, struct intel_dp, aux);
  793. uint8_t txbuf[20], rxbuf[20];
  794. size_t txsize, rxsize;
  795. int ret;
  796. txbuf[0] = (msg->request << 4) |
  797. ((msg->address >> 16) & 0xf);
  798. txbuf[1] = (msg->address >> 8) & 0xff;
  799. txbuf[2] = msg->address & 0xff;
  800. txbuf[3] = msg->size - 1;
  801. switch (msg->request & ~DP_AUX_I2C_MOT) {
  802. case DP_AUX_NATIVE_WRITE:
  803. case DP_AUX_I2C_WRITE:
  804. case DP_AUX_I2C_WRITE_STATUS_UPDATE:
  805. txsize = msg->size ? HEADER_SIZE + msg->size : BARE_ADDRESS_SIZE;
  806. rxsize = 2; /* 0 or 1 data bytes */
  807. if (WARN_ON(txsize > 20))
  808. return -E2BIG;
  809. if (msg->buffer)
  810. memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
  811. else
  812. WARN_ON(msg->size);
  813. ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
  814. if (ret > 0) {
  815. msg->reply = rxbuf[0] >> 4;
  816. if (ret > 1) {
  817. /* Number of bytes written in a short write. */
  818. ret = clamp_t(int, rxbuf[1], 0, msg->size);
  819. } else {
  820. /* Return payload size. */
  821. ret = msg->size;
  822. }
  823. }
  824. break;
  825. case DP_AUX_NATIVE_READ:
  826. case DP_AUX_I2C_READ:
  827. txsize = msg->size ? HEADER_SIZE : BARE_ADDRESS_SIZE;
  828. rxsize = msg->size + 1;
  829. if (WARN_ON(rxsize > 20))
  830. return -E2BIG;
  831. ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
  832. if (ret > 0) {
  833. msg->reply = rxbuf[0] >> 4;
  834. /*
  835. * Assume happy day, and copy the data. The caller is
  836. * expected to check msg->reply before touching it.
  837. *
  838. * Return payload size.
  839. */
  840. ret--;
  841. memcpy(msg->buffer, rxbuf + 1, ret);
  842. }
  843. break;
  844. default:
  845. ret = -EINVAL;
  846. break;
  847. }
  848. return ret;
  849. }
  850. static i915_reg_t g4x_aux_ctl_reg(struct drm_i915_private *dev_priv,
  851. enum port port)
  852. {
  853. switch (port) {
  854. case PORT_B:
  855. case PORT_C:
  856. case PORT_D:
  857. return DP_AUX_CH_CTL(port);
  858. default:
  859. MISSING_CASE(port);
  860. return DP_AUX_CH_CTL(PORT_B);
  861. }
  862. }
  863. static i915_reg_t g4x_aux_data_reg(struct drm_i915_private *dev_priv,
  864. enum port port, int index)
  865. {
  866. switch (port) {
  867. case PORT_B:
  868. case PORT_C:
  869. case PORT_D:
  870. return DP_AUX_CH_DATA(port, index);
  871. default:
  872. MISSING_CASE(port);
  873. return DP_AUX_CH_DATA(PORT_B, index);
  874. }
  875. }
  876. static i915_reg_t ilk_aux_ctl_reg(struct drm_i915_private *dev_priv,
  877. enum port port)
  878. {
  879. switch (port) {
  880. case PORT_A:
  881. return DP_AUX_CH_CTL(port);
  882. case PORT_B:
  883. case PORT_C:
  884. case PORT_D:
  885. return PCH_DP_AUX_CH_CTL(port);
  886. default:
  887. MISSING_CASE(port);
  888. return DP_AUX_CH_CTL(PORT_A);
  889. }
  890. }
  891. static i915_reg_t ilk_aux_data_reg(struct drm_i915_private *dev_priv,
  892. enum port port, int index)
  893. {
  894. switch (port) {
  895. case PORT_A:
  896. return DP_AUX_CH_DATA(port, index);
  897. case PORT_B:
  898. case PORT_C:
  899. case PORT_D:
  900. return PCH_DP_AUX_CH_DATA(port, index);
  901. default:
  902. MISSING_CASE(port);
  903. return DP_AUX_CH_DATA(PORT_A, index);
  904. }
  905. }
  906. /*
  907. * On SKL we don't have Aux for port E so we rely
  908. * on VBT to set a proper alternate aux channel.
  909. */
  910. static enum port skl_porte_aux_port(struct drm_i915_private *dev_priv)
  911. {
  912. const struct ddi_vbt_port_info *info =
  913. &dev_priv->vbt.ddi_port_info[PORT_E];
  914. switch (info->alternate_aux_channel) {
  915. case DP_AUX_A:
  916. return PORT_A;
  917. case DP_AUX_B:
  918. return PORT_B;
  919. case DP_AUX_C:
  920. return PORT_C;
  921. case DP_AUX_D:
  922. return PORT_D;
  923. default:
  924. MISSING_CASE(info->alternate_aux_channel);
  925. return PORT_A;
  926. }
  927. }
  928. static i915_reg_t skl_aux_ctl_reg(struct drm_i915_private *dev_priv,
  929. enum port port)
  930. {
  931. if (port == PORT_E)
  932. port = skl_porte_aux_port(dev_priv);
  933. switch (port) {
  934. case PORT_A:
  935. case PORT_B:
  936. case PORT_C:
  937. case PORT_D:
  938. return DP_AUX_CH_CTL(port);
  939. default:
  940. MISSING_CASE(port);
  941. return DP_AUX_CH_CTL(PORT_A);
  942. }
  943. }
  944. static i915_reg_t skl_aux_data_reg(struct drm_i915_private *dev_priv,
  945. enum port port, int index)
  946. {
  947. if (port == PORT_E)
  948. port = skl_porte_aux_port(dev_priv);
  949. switch (port) {
  950. case PORT_A:
  951. case PORT_B:
  952. case PORT_C:
  953. case PORT_D:
  954. return DP_AUX_CH_DATA(port, index);
  955. default:
  956. MISSING_CASE(port);
  957. return DP_AUX_CH_DATA(PORT_A, index);
  958. }
  959. }
  960. static i915_reg_t intel_aux_ctl_reg(struct drm_i915_private *dev_priv,
  961. enum port port)
  962. {
  963. if (INTEL_INFO(dev_priv)->gen >= 9)
  964. return skl_aux_ctl_reg(dev_priv, port);
  965. else if (HAS_PCH_SPLIT(dev_priv))
  966. return ilk_aux_ctl_reg(dev_priv, port);
  967. else
  968. return g4x_aux_ctl_reg(dev_priv, port);
  969. }
  970. static i915_reg_t intel_aux_data_reg(struct drm_i915_private *dev_priv,
  971. enum port port, int index)
  972. {
  973. if (INTEL_INFO(dev_priv)->gen >= 9)
  974. return skl_aux_data_reg(dev_priv, port, index);
  975. else if (HAS_PCH_SPLIT(dev_priv))
  976. return ilk_aux_data_reg(dev_priv, port, index);
  977. else
  978. return g4x_aux_data_reg(dev_priv, port, index);
  979. }
  980. static void intel_aux_reg_init(struct intel_dp *intel_dp)
  981. {
  982. struct drm_i915_private *dev_priv = to_i915(intel_dp_to_dev(intel_dp));
  983. enum port port = dp_to_dig_port(intel_dp)->port;
  984. int i;
  985. intel_dp->aux_ch_ctl_reg = intel_aux_ctl_reg(dev_priv, port);
  986. for (i = 0; i < ARRAY_SIZE(intel_dp->aux_ch_data_reg); i++)
  987. intel_dp->aux_ch_data_reg[i] = intel_aux_data_reg(dev_priv, port, i);
  988. }
  989. static void
  990. intel_dp_aux_fini(struct intel_dp *intel_dp)
  991. {
  992. drm_dp_aux_unregister(&intel_dp->aux);
  993. kfree(intel_dp->aux.name);
  994. }
  995. static int
  996. intel_dp_aux_init(struct intel_dp *intel_dp, struct intel_connector *connector)
  997. {
  998. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  999. enum port port = intel_dig_port->port;
  1000. int ret;
  1001. intel_aux_reg_init(intel_dp);
  1002. intel_dp->aux.name = kasprintf(GFP_KERNEL, "DPDDC-%c", port_name(port));
  1003. if (!intel_dp->aux.name)
  1004. return -ENOMEM;
  1005. intel_dp->aux.dev = connector->base.kdev;
  1006. intel_dp->aux.transfer = intel_dp_aux_transfer;
  1007. DRM_DEBUG_KMS("registering %s bus for %s\n",
  1008. intel_dp->aux.name,
  1009. connector->base.kdev->kobj.name);
  1010. ret = drm_dp_aux_register(&intel_dp->aux);
  1011. if (ret < 0) {
  1012. DRM_ERROR("drm_dp_aux_register() for %s failed (%d)\n",
  1013. intel_dp->aux.name, ret);
  1014. kfree(intel_dp->aux.name);
  1015. return ret;
  1016. }
  1017. return 0;
  1018. }
  1019. static void
  1020. intel_dp_connector_unregister(struct intel_connector *intel_connector)
  1021. {
  1022. struct intel_dp *intel_dp = intel_attached_dp(&intel_connector->base);
  1023. intel_dp_aux_fini(intel_dp);
  1024. intel_connector_unregister(intel_connector);
  1025. }
  1026. static int
  1027. intel_dp_sink_rates(struct intel_dp *intel_dp, const int **sink_rates)
  1028. {
  1029. if (intel_dp->num_sink_rates) {
  1030. *sink_rates = intel_dp->sink_rates;
  1031. return intel_dp->num_sink_rates;
  1032. }
  1033. *sink_rates = default_rates;
  1034. return (intel_dp_max_link_bw(intel_dp) >> 3) + 1;
  1035. }
  1036. bool intel_dp_source_supports_hbr2(struct intel_dp *intel_dp)
  1037. {
  1038. struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
  1039. struct drm_device *dev = dig_port->base.base.dev;
  1040. /* WaDisableHBR2:skl */
  1041. if (IS_SKL_REVID(dev, 0, SKL_REVID_B0))
  1042. return false;
  1043. if ((IS_HASWELL(dev) && !IS_HSW_ULX(dev)) || IS_BROADWELL(dev) ||
  1044. (INTEL_INFO(dev)->gen >= 9))
  1045. return true;
  1046. else
  1047. return false;
  1048. }
  1049. static int
  1050. intel_dp_source_rates(struct intel_dp *intel_dp, const int **source_rates)
  1051. {
  1052. struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
  1053. struct drm_device *dev = dig_port->base.base.dev;
  1054. int size;
  1055. if (IS_BROXTON(dev)) {
  1056. *source_rates = bxt_rates;
  1057. size = ARRAY_SIZE(bxt_rates);
  1058. } else if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) {
  1059. *source_rates = skl_rates;
  1060. size = ARRAY_SIZE(skl_rates);
  1061. } else {
  1062. *source_rates = default_rates;
  1063. size = ARRAY_SIZE(default_rates);
  1064. }
  1065. /* This depends on the fact that 5.4 is last value in the array */
  1066. if (!intel_dp_source_supports_hbr2(intel_dp))
  1067. size--;
  1068. return size;
  1069. }
  1070. static void
  1071. intel_dp_set_clock(struct intel_encoder *encoder,
  1072. struct intel_crtc_state *pipe_config)
  1073. {
  1074. struct drm_device *dev = encoder->base.dev;
  1075. const struct dp_link_dpll *divisor = NULL;
  1076. int i, count = 0;
  1077. if (IS_G4X(dev)) {
  1078. divisor = gen4_dpll;
  1079. count = ARRAY_SIZE(gen4_dpll);
  1080. } else if (HAS_PCH_SPLIT(dev)) {
  1081. divisor = pch_dpll;
  1082. count = ARRAY_SIZE(pch_dpll);
  1083. } else if (IS_CHERRYVIEW(dev)) {
  1084. divisor = chv_dpll;
  1085. count = ARRAY_SIZE(chv_dpll);
  1086. } else if (IS_VALLEYVIEW(dev)) {
  1087. divisor = vlv_dpll;
  1088. count = ARRAY_SIZE(vlv_dpll);
  1089. }
  1090. if (divisor && count) {
  1091. for (i = 0; i < count; i++) {
  1092. if (pipe_config->port_clock == divisor[i].clock) {
  1093. pipe_config->dpll = divisor[i].dpll;
  1094. pipe_config->clock_set = true;
  1095. break;
  1096. }
  1097. }
  1098. }
  1099. }
  1100. static int intersect_rates(const int *source_rates, int source_len,
  1101. const int *sink_rates, int sink_len,
  1102. int *common_rates)
  1103. {
  1104. int i = 0, j = 0, k = 0;
  1105. while (i < source_len && j < sink_len) {
  1106. if (source_rates[i] == sink_rates[j]) {
  1107. if (WARN_ON(k >= DP_MAX_SUPPORTED_RATES))
  1108. return k;
  1109. common_rates[k] = source_rates[i];
  1110. ++k;
  1111. ++i;
  1112. ++j;
  1113. } else if (source_rates[i] < sink_rates[j]) {
  1114. ++i;
  1115. } else {
  1116. ++j;
  1117. }
  1118. }
  1119. return k;
  1120. }
  1121. static int intel_dp_common_rates(struct intel_dp *intel_dp,
  1122. int *common_rates)
  1123. {
  1124. const int *source_rates, *sink_rates;
  1125. int source_len, sink_len;
  1126. sink_len = intel_dp_sink_rates(intel_dp, &sink_rates);
  1127. source_len = intel_dp_source_rates(intel_dp, &source_rates);
  1128. return intersect_rates(source_rates, source_len,
  1129. sink_rates, sink_len,
  1130. common_rates);
  1131. }
  1132. static void snprintf_int_array(char *str, size_t len,
  1133. const int *array, int nelem)
  1134. {
  1135. int i;
  1136. str[0] = '\0';
  1137. for (i = 0; i < nelem; i++) {
  1138. int r = snprintf(str, len, "%s%d", i ? ", " : "", array[i]);
  1139. if (r >= len)
  1140. return;
  1141. str += r;
  1142. len -= r;
  1143. }
  1144. }
  1145. static void intel_dp_print_rates(struct intel_dp *intel_dp)
  1146. {
  1147. const int *source_rates, *sink_rates;
  1148. int source_len, sink_len, common_len;
  1149. int common_rates[DP_MAX_SUPPORTED_RATES];
  1150. char str[128]; /* FIXME: too big for stack? */
  1151. if ((drm_debug & DRM_UT_KMS) == 0)
  1152. return;
  1153. source_len = intel_dp_source_rates(intel_dp, &source_rates);
  1154. snprintf_int_array(str, sizeof(str), source_rates, source_len);
  1155. DRM_DEBUG_KMS("source rates: %s\n", str);
  1156. sink_len = intel_dp_sink_rates(intel_dp, &sink_rates);
  1157. snprintf_int_array(str, sizeof(str), sink_rates, sink_len);
  1158. DRM_DEBUG_KMS("sink rates: %s\n", str);
  1159. common_len = intel_dp_common_rates(intel_dp, common_rates);
  1160. snprintf_int_array(str, sizeof(str), common_rates, common_len);
  1161. DRM_DEBUG_KMS("common rates: %s\n", str);
  1162. }
  1163. static int rate_to_index(int find, const int *rates)
  1164. {
  1165. int i = 0;
  1166. for (i = 0; i < DP_MAX_SUPPORTED_RATES; ++i)
  1167. if (find == rates[i])
  1168. break;
  1169. return i;
  1170. }
  1171. int
  1172. intel_dp_max_link_rate(struct intel_dp *intel_dp)
  1173. {
  1174. int rates[DP_MAX_SUPPORTED_RATES] = {};
  1175. int len;
  1176. len = intel_dp_common_rates(intel_dp, rates);
  1177. if (WARN_ON(len <= 0))
  1178. return 162000;
  1179. return rates[rate_to_index(0, rates) - 1];
  1180. }
  1181. int intel_dp_rate_select(struct intel_dp *intel_dp, int rate)
  1182. {
  1183. return rate_to_index(rate, intel_dp->sink_rates);
  1184. }
  1185. void intel_dp_compute_rate(struct intel_dp *intel_dp, int port_clock,
  1186. uint8_t *link_bw, uint8_t *rate_select)
  1187. {
  1188. if (intel_dp->num_sink_rates) {
  1189. *link_bw = 0;
  1190. *rate_select =
  1191. intel_dp_rate_select(intel_dp, port_clock);
  1192. } else {
  1193. *link_bw = drm_dp_link_rate_to_bw_code(port_clock);
  1194. *rate_select = 0;
  1195. }
  1196. }
  1197. bool
  1198. intel_dp_compute_config(struct intel_encoder *encoder,
  1199. struct intel_crtc_state *pipe_config)
  1200. {
  1201. struct drm_device *dev = encoder->base.dev;
  1202. struct drm_i915_private *dev_priv = dev->dev_private;
  1203. struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
  1204. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  1205. enum port port = dp_to_dig_port(intel_dp)->port;
  1206. struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
  1207. struct intel_connector *intel_connector = intel_dp->attached_connector;
  1208. int lane_count, clock;
  1209. int min_lane_count = 1;
  1210. int max_lane_count = intel_dp_max_lane_count(intel_dp);
  1211. /* Conveniently, the link BW constants become indices with a shift...*/
  1212. int min_clock = 0;
  1213. int max_clock;
  1214. int bpp, mode_rate;
  1215. int link_avail, link_clock;
  1216. int common_rates[DP_MAX_SUPPORTED_RATES] = {};
  1217. int common_len;
  1218. uint8_t link_bw, rate_select;
  1219. common_len = intel_dp_common_rates(intel_dp, common_rates);
  1220. /* No common link rates between source and sink */
  1221. WARN_ON(common_len <= 0);
  1222. max_clock = common_len - 1;
  1223. if (HAS_PCH_SPLIT(dev) && !HAS_DDI(dev) && port != PORT_A)
  1224. pipe_config->has_pch_encoder = true;
  1225. pipe_config->has_dp_encoder = true;
  1226. pipe_config->has_drrs = false;
  1227. pipe_config->has_audio = intel_dp->has_audio && port != PORT_A;
  1228. if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
  1229. intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
  1230. adjusted_mode);
  1231. if (INTEL_INFO(dev)->gen >= 9) {
  1232. int ret;
  1233. ret = skl_update_scaler_crtc(pipe_config);
  1234. if (ret)
  1235. return ret;
  1236. }
  1237. if (HAS_GMCH_DISPLAY(dev))
  1238. intel_gmch_panel_fitting(intel_crtc, pipe_config,
  1239. intel_connector->panel.fitting_mode);
  1240. else
  1241. intel_pch_panel_fitting(intel_crtc, pipe_config,
  1242. intel_connector->panel.fitting_mode);
  1243. }
  1244. if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
  1245. return false;
  1246. DRM_DEBUG_KMS("DP link computation with max lane count %i "
  1247. "max bw %d pixel clock %iKHz\n",
  1248. max_lane_count, common_rates[max_clock],
  1249. adjusted_mode->crtc_clock);
  1250. /* Walk through all bpp values. Luckily they're all nicely spaced with 2
  1251. * bpc in between. */
  1252. bpp = pipe_config->pipe_bpp;
  1253. if (is_edp(intel_dp)) {
  1254. /* Get bpp from vbt only for panels that dont have bpp in edid */
  1255. if (intel_connector->base.display_info.bpc == 0 &&
  1256. (dev_priv->vbt.edp.bpp && dev_priv->vbt.edp.bpp < bpp)) {
  1257. DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",
  1258. dev_priv->vbt.edp.bpp);
  1259. bpp = dev_priv->vbt.edp.bpp;
  1260. }
  1261. /*
  1262. * Use the maximum clock and number of lanes the eDP panel
  1263. * advertizes being capable of. The panels are generally
  1264. * designed to support only a single clock and lane
  1265. * configuration, and typically these values correspond to the
  1266. * native resolution of the panel.
  1267. */
  1268. min_lane_count = max_lane_count;
  1269. min_clock = max_clock;
  1270. }
  1271. for (; bpp >= 6*3; bpp -= 2*3) {
  1272. mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,
  1273. bpp);
  1274. for (clock = min_clock; clock <= max_clock; clock++) {
  1275. for (lane_count = min_lane_count;
  1276. lane_count <= max_lane_count;
  1277. lane_count <<= 1) {
  1278. link_clock = common_rates[clock];
  1279. link_avail = intel_dp_max_data_rate(link_clock,
  1280. lane_count);
  1281. if (mode_rate <= link_avail) {
  1282. goto found;
  1283. }
  1284. }
  1285. }
  1286. }
  1287. return false;
  1288. found:
  1289. if (intel_dp->color_range_auto) {
  1290. /*
  1291. * See:
  1292. * CEA-861-E - 5.1 Default Encoding Parameters
  1293. * VESA DisplayPort Ver.1.2a - 5.1.1.1 Video Colorimetry
  1294. */
  1295. pipe_config->limited_color_range =
  1296. bpp != 18 && drm_match_cea_mode(adjusted_mode) > 1;
  1297. } else {
  1298. pipe_config->limited_color_range =
  1299. intel_dp->limited_color_range;
  1300. }
  1301. pipe_config->lane_count = lane_count;
  1302. pipe_config->pipe_bpp = bpp;
  1303. pipe_config->port_clock = common_rates[clock];
  1304. intel_dp_compute_rate(intel_dp, pipe_config->port_clock,
  1305. &link_bw, &rate_select);
  1306. DRM_DEBUG_KMS("DP link bw %02x rate select %02x lane count %d clock %d bpp %d\n",
  1307. link_bw, rate_select, pipe_config->lane_count,
  1308. pipe_config->port_clock, bpp);
  1309. DRM_DEBUG_KMS("DP link bw required %i available %i\n",
  1310. mode_rate, link_avail);
  1311. intel_link_compute_m_n(bpp, lane_count,
  1312. adjusted_mode->crtc_clock,
  1313. pipe_config->port_clock,
  1314. &pipe_config->dp_m_n);
  1315. if (intel_connector->panel.downclock_mode != NULL &&
  1316. dev_priv->drrs.type == SEAMLESS_DRRS_SUPPORT) {
  1317. pipe_config->has_drrs = true;
  1318. intel_link_compute_m_n(bpp, lane_count,
  1319. intel_connector->panel.downclock_mode->clock,
  1320. pipe_config->port_clock,
  1321. &pipe_config->dp_m2_n2);
  1322. }
  1323. /*
  1324. * DPLL0 VCO may need to be adjusted to get the correct
  1325. * clock for eDP. This will affect cdclk as well.
  1326. */
  1327. if (is_edp(intel_dp) &&
  1328. (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv))) {
  1329. int vco;
  1330. switch (pipe_config->port_clock / 2) {
  1331. case 108000:
  1332. case 216000:
  1333. vco = 8640000;
  1334. break;
  1335. default:
  1336. vco = 8100000;
  1337. break;
  1338. }
  1339. to_intel_atomic_state(pipe_config->base.state)->cdclk_pll_vco = vco;
  1340. }
  1341. if (!HAS_DDI(dev))
  1342. intel_dp_set_clock(encoder, pipe_config);
  1343. return true;
  1344. }
  1345. void intel_dp_set_link_params(struct intel_dp *intel_dp,
  1346. const struct intel_crtc_state *pipe_config)
  1347. {
  1348. intel_dp->link_rate = pipe_config->port_clock;
  1349. intel_dp->lane_count = pipe_config->lane_count;
  1350. }
  1351. static void intel_dp_prepare(struct intel_encoder *encoder)
  1352. {
  1353. struct drm_device *dev = encoder->base.dev;
  1354. struct drm_i915_private *dev_priv = dev->dev_private;
  1355. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  1356. enum port port = dp_to_dig_port(intel_dp)->port;
  1357. struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
  1358. const struct drm_display_mode *adjusted_mode = &crtc->config->base.adjusted_mode;
  1359. intel_dp_set_link_params(intel_dp, crtc->config);
  1360. /*
  1361. * There are four kinds of DP registers:
  1362. *
  1363. * IBX PCH
  1364. * SNB CPU
  1365. * IVB CPU
  1366. * CPT PCH
  1367. *
  1368. * IBX PCH and CPU are the same for almost everything,
  1369. * except that the CPU DP PLL is configured in this
  1370. * register
  1371. *
  1372. * CPT PCH is quite different, having many bits moved
  1373. * to the TRANS_DP_CTL register instead. That
  1374. * configuration happens (oddly) in ironlake_pch_enable
  1375. */
  1376. /* Preserve the BIOS-computed detected bit. This is
  1377. * supposed to be read-only.
  1378. */
  1379. intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
  1380. /* Handle DP bits in common between all three register formats */
  1381. intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
  1382. intel_dp->DP |= DP_PORT_WIDTH(crtc->config->lane_count);
  1383. /* Split out the IBX/CPU vs CPT settings */
  1384. if (IS_GEN7(dev) && port == PORT_A) {
  1385. if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
  1386. intel_dp->DP |= DP_SYNC_HS_HIGH;
  1387. if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
  1388. intel_dp->DP |= DP_SYNC_VS_HIGH;
  1389. intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
  1390. if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
  1391. intel_dp->DP |= DP_ENHANCED_FRAMING;
  1392. intel_dp->DP |= crtc->pipe << 29;
  1393. } else if (HAS_PCH_CPT(dev) && port != PORT_A) {
  1394. u32 trans_dp;
  1395. intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
  1396. trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
  1397. if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
  1398. trans_dp |= TRANS_DP_ENH_FRAMING;
  1399. else
  1400. trans_dp &= ~TRANS_DP_ENH_FRAMING;
  1401. I915_WRITE(TRANS_DP_CTL(crtc->pipe), trans_dp);
  1402. } else {
  1403. if (!HAS_PCH_SPLIT(dev) && !IS_VALLEYVIEW(dev) &&
  1404. !IS_CHERRYVIEW(dev) && crtc->config->limited_color_range)
  1405. intel_dp->DP |= DP_COLOR_RANGE_16_235;
  1406. if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
  1407. intel_dp->DP |= DP_SYNC_HS_HIGH;
  1408. if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
  1409. intel_dp->DP |= DP_SYNC_VS_HIGH;
  1410. intel_dp->DP |= DP_LINK_TRAIN_OFF;
  1411. if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
  1412. intel_dp->DP |= DP_ENHANCED_FRAMING;
  1413. if (IS_CHERRYVIEW(dev))
  1414. intel_dp->DP |= DP_PIPE_SELECT_CHV(crtc->pipe);
  1415. else if (crtc->pipe == PIPE_B)
  1416. intel_dp->DP |= DP_PIPEB_SELECT;
  1417. }
  1418. }
  1419. #define IDLE_ON_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
  1420. #define IDLE_ON_VALUE (PP_ON | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
  1421. #define IDLE_OFF_MASK (PP_ON | PP_SEQUENCE_MASK | 0 | 0)
  1422. #define IDLE_OFF_VALUE (0 | PP_SEQUENCE_NONE | 0 | 0)
  1423. #define IDLE_CYCLE_MASK (PP_ON | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
  1424. #define IDLE_CYCLE_VALUE (0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
  1425. static void wait_panel_status(struct intel_dp *intel_dp,
  1426. u32 mask,
  1427. u32 value)
  1428. {
  1429. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  1430. struct drm_i915_private *dev_priv = dev->dev_private;
  1431. i915_reg_t pp_stat_reg, pp_ctrl_reg;
  1432. lockdep_assert_held(&dev_priv->pps_mutex);
  1433. pp_stat_reg = _pp_stat_reg(intel_dp);
  1434. pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
  1435. DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
  1436. mask, value,
  1437. I915_READ(pp_stat_reg),
  1438. I915_READ(pp_ctrl_reg));
  1439. if (_wait_for((I915_READ(pp_stat_reg) & mask) == value,
  1440. 5 * USEC_PER_SEC, 10 * USEC_PER_MSEC))
  1441. DRM_ERROR("Panel status timeout: status %08x control %08x\n",
  1442. I915_READ(pp_stat_reg),
  1443. I915_READ(pp_ctrl_reg));
  1444. DRM_DEBUG_KMS("Wait complete\n");
  1445. }
  1446. static void wait_panel_on(struct intel_dp *intel_dp)
  1447. {
  1448. DRM_DEBUG_KMS("Wait for panel power on\n");
  1449. wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
  1450. }
  1451. static void wait_panel_off(struct intel_dp *intel_dp)
  1452. {
  1453. DRM_DEBUG_KMS("Wait for panel power off time\n");
  1454. wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
  1455. }
  1456. static void wait_panel_power_cycle(struct intel_dp *intel_dp)
  1457. {
  1458. ktime_t panel_power_on_time;
  1459. s64 panel_power_off_duration;
  1460. DRM_DEBUG_KMS("Wait for panel power cycle\n");
  1461. /* take the difference of currrent time and panel power off time
  1462. * and then make panel wait for t11_t12 if needed. */
  1463. panel_power_on_time = ktime_get_boottime();
  1464. panel_power_off_duration = ktime_ms_delta(panel_power_on_time, intel_dp->panel_power_off_time);
  1465. /* When we disable the VDD override bit last we have to do the manual
  1466. * wait. */
  1467. if (panel_power_off_duration < (s64)intel_dp->panel_power_cycle_delay)
  1468. wait_remaining_ms_from_jiffies(jiffies,
  1469. intel_dp->panel_power_cycle_delay - panel_power_off_duration);
  1470. wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
  1471. }
  1472. static void wait_backlight_on(struct intel_dp *intel_dp)
  1473. {
  1474. wait_remaining_ms_from_jiffies(intel_dp->last_power_on,
  1475. intel_dp->backlight_on_delay);
  1476. }
  1477. static void edp_wait_backlight_off(struct intel_dp *intel_dp)
  1478. {
  1479. wait_remaining_ms_from_jiffies(intel_dp->last_backlight_off,
  1480. intel_dp->backlight_off_delay);
  1481. }
  1482. /* Read the current pp_control value, unlocking the register if it
  1483. * is locked
  1484. */
  1485. static u32 ironlake_get_pp_control(struct intel_dp *intel_dp)
  1486. {
  1487. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  1488. struct drm_i915_private *dev_priv = dev->dev_private;
  1489. u32 control;
  1490. lockdep_assert_held(&dev_priv->pps_mutex);
  1491. control = I915_READ(_pp_ctrl_reg(intel_dp));
  1492. if (!IS_BROXTON(dev)) {
  1493. control &= ~PANEL_UNLOCK_MASK;
  1494. control |= PANEL_UNLOCK_REGS;
  1495. }
  1496. return control;
  1497. }
  1498. /*
  1499. * Must be paired with edp_panel_vdd_off().
  1500. * Must hold pps_mutex around the whole on/off sequence.
  1501. * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
  1502. */
  1503. static bool edp_panel_vdd_on(struct intel_dp *intel_dp)
  1504. {
  1505. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  1506. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  1507. struct intel_encoder *intel_encoder = &intel_dig_port->base;
  1508. struct drm_i915_private *dev_priv = dev->dev_private;
  1509. enum intel_display_power_domain power_domain;
  1510. u32 pp;
  1511. i915_reg_t pp_stat_reg, pp_ctrl_reg;
  1512. bool need_to_disable = !intel_dp->want_panel_vdd;
  1513. lockdep_assert_held(&dev_priv->pps_mutex);
  1514. if (!is_edp(intel_dp))
  1515. return false;
  1516. cancel_delayed_work(&intel_dp->panel_vdd_work);
  1517. intel_dp->want_panel_vdd = true;
  1518. if (edp_have_panel_vdd(intel_dp))
  1519. return need_to_disable;
  1520. power_domain = intel_display_port_aux_power_domain(intel_encoder);
  1521. intel_display_power_get(dev_priv, power_domain);
  1522. DRM_DEBUG_KMS("Turning eDP port %c VDD on\n",
  1523. port_name(intel_dig_port->port));
  1524. if (!edp_have_panel_power(intel_dp))
  1525. wait_panel_power_cycle(intel_dp);
  1526. pp = ironlake_get_pp_control(intel_dp);
  1527. pp |= EDP_FORCE_VDD;
  1528. pp_stat_reg = _pp_stat_reg(intel_dp);
  1529. pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
  1530. I915_WRITE(pp_ctrl_reg, pp);
  1531. POSTING_READ(pp_ctrl_reg);
  1532. DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
  1533. I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
  1534. /*
  1535. * If the panel wasn't on, delay before accessing aux channel
  1536. */
  1537. if (!edp_have_panel_power(intel_dp)) {
  1538. DRM_DEBUG_KMS("eDP port %c panel power wasn't enabled\n",
  1539. port_name(intel_dig_port->port));
  1540. msleep(intel_dp->panel_power_up_delay);
  1541. }
  1542. return need_to_disable;
  1543. }
  1544. /*
  1545. * Must be paired with intel_edp_panel_vdd_off() or
  1546. * intel_edp_panel_off().
  1547. * Nested calls to these functions are not allowed since
  1548. * we drop the lock. Caller must use some higher level
  1549. * locking to prevent nested calls from other threads.
  1550. */
  1551. void intel_edp_panel_vdd_on(struct intel_dp *intel_dp)
  1552. {
  1553. bool vdd;
  1554. if (!is_edp(intel_dp))
  1555. return;
  1556. pps_lock(intel_dp);
  1557. vdd = edp_panel_vdd_on(intel_dp);
  1558. pps_unlock(intel_dp);
  1559. I915_STATE_WARN(!vdd, "eDP port %c VDD already requested on\n",
  1560. port_name(dp_to_dig_port(intel_dp)->port));
  1561. }
  1562. static void edp_panel_vdd_off_sync(struct intel_dp *intel_dp)
  1563. {
  1564. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  1565. struct drm_i915_private *dev_priv = dev->dev_private;
  1566. struct intel_digital_port *intel_dig_port =
  1567. dp_to_dig_port(intel_dp);
  1568. struct intel_encoder *intel_encoder = &intel_dig_port->base;
  1569. enum intel_display_power_domain power_domain;
  1570. u32 pp;
  1571. i915_reg_t pp_stat_reg, pp_ctrl_reg;
  1572. lockdep_assert_held(&dev_priv->pps_mutex);
  1573. WARN_ON(intel_dp->want_panel_vdd);
  1574. if (!edp_have_panel_vdd(intel_dp))
  1575. return;
  1576. DRM_DEBUG_KMS("Turning eDP port %c VDD off\n",
  1577. port_name(intel_dig_port->port));
  1578. pp = ironlake_get_pp_control(intel_dp);
  1579. pp &= ~EDP_FORCE_VDD;
  1580. pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
  1581. pp_stat_reg = _pp_stat_reg(intel_dp);
  1582. I915_WRITE(pp_ctrl_reg, pp);
  1583. POSTING_READ(pp_ctrl_reg);
  1584. /* Make sure sequencer is idle before allowing subsequent activity */
  1585. DRM_DEBUG_KMS("PP_STATUS: 0x%08x PP_CONTROL: 0x%08x\n",
  1586. I915_READ(pp_stat_reg), I915_READ(pp_ctrl_reg));
  1587. if ((pp & POWER_TARGET_ON) == 0)
  1588. intel_dp->panel_power_off_time = ktime_get_boottime();
  1589. power_domain = intel_display_port_aux_power_domain(intel_encoder);
  1590. intel_display_power_put(dev_priv, power_domain);
  1591. }
  1592. static void edp_panel_vdd_work(struct work_struct *__work)
  1593. {
  1594. struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
  1595. struct intel_dp, panel_vdd_work);
  1596. pps_lock(intel_dp);
  1597. if (!intel_dp->want_panel_vdd)
  1598. edp_panel_vdd_off_sync(intel_dp);
  1599. pps_unlock(intel_dp);
  1600. }
  1601. static void edp_panel_vdd_schedule_off(struct intel_dp *intel_dp)
  1602. {
  1603. unsigned long delay;
  1604. /*
  1605. * Queue the timer to fire a long time from now (relative to the power
  1606. * down delay) to keep the panel power up across a sequence of
  1607. * operations.
  1608. */
  1609. delay = msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5);
  1610. schedule_delayed_work(&intel_dp->panel_vdd_work, delay);
  1611. }
  1612. /*
  1613. * Must be paired with edp_panel_vdd_on().
  1614. * Must hold pps_mutex around the whole on/off sequence.
  1615. * Can be nested with intel_edp_panel_vdd_{on,off}() calls.
  1616. */
  1617. static void edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
  1618. {
  1619. struct drm_i915_private *dev_priv =
  1620. intel_dp_to_dev(intel_dp)->dev_private;
  1621. lockdep_assert_held(&dev_priv->pps_mutex);
  1622. if (!is_edp(intel_dp))
  1623. return;
  1624. I915_STATE_WARN(!intel_dp->want_panel_vdd, "eDP port %c VDD not forced on",
  1625. port_name(dp_to_dig_port(intel_dp)->port));
  1626. intel_dp->want_panel_vdd = false;
  1627. if (sync)
  1628. edp_panel_vdd_off_sync(intel_dp);
  1629. else
  1630. edp_panel_vdd_schedule_off(intel_dp);
  1631. }
  1632. static void edp_panel_on(struct intel_dp *intel_dp)
  1633. {
  1634. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  1635. struct drm_i915_private *dev_priv = dev->dev_private;
  1636. u32 pp;
  1637. i915_reg_t pp_ctrl_reg;
  1638. lockdep_assert_held(&dev_priv->pps_mutex);
  1639. if (!is_edp(intel_dp))
  1640. return;
  1641. DRM_DEBUG_KMS("Turn eDP port %c panel power on\n",
  1642. port_name(dp_to_dig_port(intel_dp)->port));
  1643. if (WARN(edp_have_panel_power(intel_dp),
  1644. "eDP port %c panel power already on\n",
  1645. port_name(dp_to_dig_port(intel_dp)->port)))
  1646. return;
  1647. wait_panel_power_cycle(intel_dp);
  1648. pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
  1649. pp = ironlake_get_pp_control(intel_dp);
  1650. if (IS_GEN5(dev)) {
  1651. /* ILK workaround: disable reset around power sequence */
  1652. pp &= ~PANEL_POWER_RESET;
  1653. I915_WRITE(pp_ctrl_reg, pp);
  1654. POSTING_READ(pp_ctrl_reg);
  1655. }
  1656. pp |= POWER_TARGET_ON;
  1657. if (!IS_GEN5(dev))
  1658. pp |= PANEL_POWER_RESET;
  1659. I915_WRITE(pp_ctrl_reg, pp);
  1660. POSTING_READ(pp_ctrl_reg);
  1661. wait_panel_on(intel_dp);
  1662. intel_dp->last_power_on = jiffies;
  1663. if (IS_GEN5(dev)) {
  1664. pp |= PANEL_POWER_RESET; /* restore panel reset bit */
  1665. I915_WRITE(pp_ctrl_reg, pp);
  1666. POSTING_READ(pp_ctrl_reg);
  1667. }
  1668. }
  1669. void intel_edp_panel_on(struct intel_dp *intel_dp)
  1670. {
  1671. if (!is_edp(intel_dp))
  1672. return;
  1673. pps_lock(intel_dp);
  1674. edp_panel_on(intel_dp);
  1675. pps_unlock(intel_dp);
  1676. }
  1677. static void edp_panel_off(struct intel_dp *intel_dp)
  1678. {
  1679. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  1680. struct intel_encoder *intel_encoder = &intel_dig_port->base;
  1681. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  1682. struct drm_i915_private *dev_priv = dev->dev_private;
  1683. enum intel_display_power_domain power_domain;
  1684. u32 pp;
  1685. i915_reg_t pp_ctrl_reg;
  1686. lockdep_assert_held(&dev_priv->pps_mutex);
  1687. if (!is_edp(intel_dp))
  1688. return;
  1689. DRM_DEBUG_KMS("Turn eDP port %c panel power off\n",
  1690. port_name(dp_to_dig_port(intel_dp)->port));
  1691. WARN(!intel_dp->want_panel_vdd, "Need eDP port %c VDD to turn off panel\n",
  1692. port_name(dp_to_dig_port(intel_dp)->port));
  1693. pp = ironlake_get_pp_control(intel_dp);
  1694. /* We need to switch off panel power _and_ force vdd, for otherwise some
  1695. * panels get very unhappy and cease to work. */
  1696. pp &= ~(POWER_TARGET_ON | PANEL_POWER_RESET | EDP_FORCE_VDD |
  1697. EDP_BLC_ENABLE);
  1698. pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
  1699. intel_dp->want_panel_vdd = false;
  1700. I915_WRITE(pp_ctrl_reg, pp);
  1701. POSTING_READ(pp_ctrl_reg);
  1702. intel_dp->panel_power_off_time = ktime_get_boottime();
  1703. wait_panel_off(intel_dp);
  1704. /* We got a reference when we enabled the VDD. */
  1705. power_domain = intel_display_port_aux_power_domain(intel_encoder);
  1706. intel_display_power_put(dev_priv, power_domain);
  1707. }
  1708. void intel_edp_panel_off(struct intel_dp *intel_dp)
  1709. {
  1710. if (!is_edp(intel_dp))
  1711. return;
  1712. pps_lock(intel_dp);
  1713. edp_panel_off(intel_dp);
  1714. pps_unlock(intel_dp);
  1715. }
  1716. /* Enable backlight in the panel power control. */
  1717. static void _intel_edp_backlight_on(struct intel_dp *intel_dp)
  1718. {
  1719. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  1720. struct drm_device *dev = intel_dig_port->base.base.dev;
  1721. struct drm_i915_private *dev_priv = dev->dev_private;
  1722. u32 pp;
  1723. i915_reg_t pp_ctrl_reg;
  1724. /*
  1725. * If we enable the backlight right away following a panel power
  1726. * on, we may see slight flicker as the panel syncs with the eDP
  1727. * link. So delay a bit to make sure the image is solid before
  1728. * allowing it to appear.
  1729. */
  1730. wait_backlight_on(intel_dp);
  1731. pps_lock(intel_dp);
  1732. pp = ironlake_get_pp_control(intel_dp);
  1733. pp |= EDP_BLC_ENABLE;
  1734. pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
  1735. I915_WRITE(pp_ctrl_reg, pp);
  1736. POSTING_READ(pp_ctrl_reg);
  1737. pps_unlock(intel_dp);
  1738. }
  1739. /* Enable backlight PWM and backlight PP control. */
  1740. void intel_edp_backlight_on(struct intel_dp *intel_dp)
  1741. {
  1742. if (!is_edp(intel_dp))
  1743. return;
  1744. DRM_DEBUG_KMS("\n");
  1745. intel_panel_enable_backlight(intel_dp->attached_connector);
  1746. _intel_edp_backlight_on(intel_dp);
  1747. }
  1748. /* Disable backlight in the panel power control. */
  1749. static void _intel_edp_backlight_off(struct intel_dp *intel_dp)
  1750. {
  1751. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  1752. struct drm_i915_private *dev_priv = dev->dev_private;
  1753. u32 pp;
  1754. i915_reg_t pp_ctrl_reg;
  1755. if (!is_edp(intel_dp))
  1756. return;
  1757. pps_lock(intel_dp);
  1758. pp = ironlake_get_pp_control(intel_dp);
  1759. pp &= ~EDP_BLC_ENABLE;
  1760. pp_ctrl_reg = _pp_ctrl_reg(intel_dp);
  1761. I915_WRITE(pp_ctrl_reg, pp);
  1762. POSTING_READ(pp_ctrl_reg);
  1763. pps_unlock(intel_dp);
  1764. intel_dp->last_backlight_off = jiffies;
  1765. edp_wait_backlight_off(intel_dp);
  1766. }
  1767. /* Disable backlight PP control and backlight PWM. */
  1768. void intel_edp_backlight_off(struct intel_dp *intel_dp)
  1769. {
  1770. if (!is_edp(intel_dp))
  1771. return;
  1772. DRM_DEBUG_KMS("\n");
  1773. _intel_edp_backlight_off(intel_dp);
  1774. intel_panel_disable_backlight(intel_dp->attached_connector);
  1775. }
  1776. /*
  1777. * Hook for controlling the panel power control backlight through the bl_power
  1778. * sysfs attribute. Take care to handle multiple calls.
  1779. */
  1780. static void intel_edp_backlight_power(struct intel_connector *connector,
  1781. bool enable)
  1782. {
  1783. struct intel_dp *intel_dp = intel_attached_dp(&connector->base);
  1784. bool is_enabled;
  1785. pps_lock(intel_dp);
  1786. is_enabled = ironlake_get_pp_control(intel_dp) & EDP_BLC_ENABLE;
  1787. pps_unlock(intel_dp);
  1788. if (is_enabled == enable)
  1789. return;
  1790. DRM_DEBUG_KMS("panel power control backlight %s\n",
  1791. enable ? "enable" : "disable");
  1792. if (enable)
  1793. _intel_edp_backlight_on(intel_dp);
  1794. else
  1795. _intel_edp_backlight_off(intel_dp);
  1796. }
  1797. static void assert_dp_port(struct intel_dp *intel_dp, bool state)
  1798. {
  1799. struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
  1800. struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev);
  1801. bool cur_state = I915_READ(intel_dp->output_reg) & DP_PORT_EN;
  1802. I915_STATE_WARN(cur_state != state,
  1803. "DP port %c state assertion failure (expected %s, current %s)\n",
  1804. port_name(dig_port->port),
  1805. onoff(state), onoff(cur_state));
  1806. }
  1807. #define assert_dp_port_disabled(d) assert_dp_port((d), false)
  1808. static void assert_edp_pll(struct drm_i915_private *dev_priv, bool state)
  1809. {
  1810. bool cur_state = I915_READ(DP_A) & DP_PLL_ENABLE;
  1811. I915_STATE_WARN(cur_state != state,
  1812. "eDP PLL state assertion failure (expected %s, current %s)\n",
  1813. onoff(state), onoff(cur_state));
  1814. }
  1815. #define assert_edp_pll_enabled(d) assert_edp_pll((d), true)
  1816. #define assert_edp_pll_disabled(d) assert_edp_pll((d), false)
  1817. static void ironlake_edp_pll_on(struct intel_dp *intel_dp)
  1818. {
  1819. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  1820. struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
  1821. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  1822. assert_pipe_disabled(dev_priv, crtc->pipe);
  1823. assert_dp_port_disabled(intel_dp);
  1824. assert_edp_pll_disabled(dev_priv);
  1825. DRM_DEBUG_KMS("enabling eDP PLL for clock %d\n",
  1826. crtc->config->port_clock);
  1827. intel_dp->DP &= ~DP_PLL_FREQ_MASK;
  1828. if (crtc->config->port_clock == 162000)
  1829. intel_dp->DP |= DP_PLL_FREQ_162MHZ;
  1830. else
  1831. intel_dp->DP |= DP_PLL_FREQ_270MHZ;
  1832. I915_WRITE(DP_A, intel_dp->DP);
  1833. POSTING_READ(DP_A);
  1834. udelay(500);
  1835. /*
  1836. * [DevILK] Work around required when enabling DP PLL
  1837. * while a pipe is enabled going to FDI:
  1838. * 1. Wait for the start of vertical blank on the enabled pipe going to FDI
  1839. * 2. Program DP PLL enable
  1840. */
  1841. if (IS_GEN5(dev_priv))
  1842. intel_wait_for_vblank_if_active(dev_priv->dev, !crtc->pipe);
  1843. intel_dp->DP |= DP_PLL_ENABLE;
  1844. I915_WRITE(DP_A, intel_dp->DP);
  1845. POSTING_READ(DP_A);
  1846. udelay(200);
  1847. }
  1848. static void ironlake_edp_pll_off(struct intel_dp *intel_dp)
  1849. {
  1850. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  1851. struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
  1852. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  1853. assert_pipe_disabled(dev_priv, crtc->pipe);
  1854. assert_dp_port_disabled(intel_dp);
  1855. assert_edp_pll_enabled(dev_priv);
  1856. DRM_DEBUG_KMS("disabling eDP PLL\n");
  1857. intel_dp->DP &= ~DP_PLL_ENABLE;
  1858. I915_WRITE(DP_A, intel_dp->DP);
  1859. POSTING_READ(DP_A);
  1860. udelay(200);
  1861. }
  1862. /* If the sink supports it, try to set the power state appropriately */
  1863. void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
  1864. {
  1865. int ret, i;
  1866. /* Should have a valid DPCD by this point */
  1867. if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
  1868. return;
  1869. if (mode != DRM_MODE_DPMS_ON) {
  1870. ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
  1871. DP_SET_POWER_D3);
  1872. } else {
  1873. /*
  1874. * When turning on, we need to retry for 1ms to give the sink
  1875. * time to wake up.
  1876. */
  1877. for (i = 0; i < 3; i++) {
  1878. ret = drm_dp_dpcd_writeb(&intel_dp->aux, DP_SET_POWER,
  1879. DP_SET_POWER_D0);
  1880. if (ret == 1)
  1881. break;
  1882. msleep(1);
  1883. }
  1884. }
  1885. if (ret != 1)
  1886. DRM_DEBUG_KMS("failed to %s sink power state\n",
  1887. mode == DRM_MODE_DPMS_ON ? "enable" : "disable");
  1888. }
  1889. static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
  1890. enum pipe *pipe)
  1891. {
  1892. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  1893. enum port port = dp_to_dig_port(intel_dp)->port;
  1894. struct drm_device *dev = encoder->base.dev;
  1895. struct drm_i915_private *dev_priv = dev->dev_private;
  1896. enum intel_display_power_domain power_domain;
  1897. u32 tmp;
  1898. bool ret;
  1899. power_domain = intel_display_port_power_domain(encoder);
  1900. if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
  1901. return false;
  1902. ret = false;
  1903. tmp = I915_READ(intel_dp->output_reg);
  1904. if (!(tmp & DP_PORT_EN))
  1905. goto out;
  1906. if (IS_GEN7(dev) && port == PORT_A) {
  1907. *pipe = PORT_TO_PIPE_CPT(tmp);
  1908. } else if (HAS_PCH_CPT(dev) && port != PORT_A) {
  1909. enum pipe p;
  1910. for_each_pipe(dev_priv, p) {
  1911. u32 trans_dp = I915_READ(TRANS_DP_CTL(p));
  1912. if (TRANS_DP_PIPE_TO_PORT(trans_dp) == port) {
  1913. *pipe = p;
  1914. ret = true;
  1915. goto out;
  1916. }
  1917. }
  1918. DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n",
  1919. i915_mmio_reg_offset(intel_dp->output_reg));
  1920. } else if (IS_CHERRYVIEW(dev)) {
  1921. *pipe = DP_PORT_TO_PIPE_CHV(tmp);
  1922. } else {
  1923. *pipe = PORT_TO_PIPE(tmp);
  1924. }
  1925. ret = true;
  1926. out:
  1927. intel_display_power_put(dev_priv, power_domain);
  1928. return ret;
  1929. }
  1930. static void intel_dp_get_config(struct intel_encoder *encoder,
  1931. struct intel_crtc_state *pipe_config)
  1932. {
  1933. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  1934. u32 tmp, flags = 0;
  1935. struct drm_device *dev = encoder->base.dev;
  1936. struct drm_i915_private *dev_priv = dev->dev_private;
  1937. enum port port = dp_to_dig_port(intel_dp)->port;
  1938. struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
  1939. tmp = I915_READ(intel_dp->output_reg);
  1940. pipe_config->has_audio = tmp & DP_AUDIO_OUTPUT_ENABLE && port != PORT_A;
  1941. if (HAS_PCH_CPT(dev) && port != PORT_A) {
  1942. u32 trans_dp = I915_READ(TRANS_DP_CTL(crtc->pipe));
  1943. if (trans_dp & TRANS_DP_HSYNC_ACTIVE_HIGH)
  1944. flags |= DRM_MODE_FLAG_PHSYNC;
  1945. else
  1946. flags |= DRM_MODE_FLAG_NHSYNC;
  1947. if (trans_dp & TRANS_DP_VSYNC_ACTIVE_HIGH)
  1948. flags |= DRM_MODE_FLAG_PVSYNC;
  1949. else
  1950. flags |= DRM_MODE_FLAG_NVSYNC;
  1951. } else {
  1952. if (tmp & DP_SYNC_HS_HIGH)
  1953. flags |= DRM_MODE_FLAG_PHSYNC;
  1954. else
  1955. flags |= DRM_MODE_FLAG_NHSYNC;
  1956. if (tmp & DP_SYNC_VS_HIGH)
  1957. flags |= DRM_MODE_FLAG_PVSYNC;
  1958. else
  1959. flags |= DRM_MODE_FLAG_NVSYNC;
  1960. }
  1961. pipe_config->base.adjusted_mode.flags |= flags;
  1962. if (!HAS_PCH_SPLIT(dev) && !IS_VALLEYVIEW(dev) &&
  1963. !IS_CHERRYVIEW(dev) && tmp & DP_COLOR_RANGE_16_235)
  1964. pipe_config->limited_color_range = true;
  1965. pipe_config->has_dp_encoder = true;
  1966. pipe_config->lane_count =
  1967. ((tmp & DP_PORT_WIDTH_MASK) >> DP_PORT_WIDTH_SHIFT) + 1;
  1968. intel_dp_get_m_n(crtc, pipe_config);
  1969. if (port == PORT_A) {
  1970. if ((I915_READ(DP_A) & DP_PLL_FREQ_MASK) == DP_PLL_FREQ_162MHZ)
  1971. pipe_config->port_clock = 162000;
  1972. else
  1973. pipe_config->port_clock = 270000;
  1974. }
  1975. pipe_config->base.adjusted_mode.crtc_clock =
  1976. intel_dotclock_calculate(pipe_config->port_clock,
  1977. &pipe_config->dp_m_n);
  1978. if (is_edp(intel_dp) && dev_priv->vbt.edp.bpp &&
  1979. pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
  1980. /*
  1981. * This is a big fat ugly hack.
  1982. *
  1983. * Some machines in UEFI boot mode provide us a VBT that has 18
  1984. * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
  1985. * unknown we fail to light up. Yet the same BIOS boots up with
  1986. * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
  1987. * max, not what it tells us to use.
  1988. *
  1989. * Note: This will still be broken if the eDP panel is not lit
  1990. * up by the BIOS, and thus we can't get the mode at module
  1991. * load.
  1992. */
  1993. DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
  1994. pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
  1995. dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
  1996. }
  1997. }
  1998. static void intel_disable_dp(struct intel_encoder *encoder)
  1999. {
  2000. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  2001. struct drm_device *dev = encoder->base.dev;
  2002. struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
  2003. if (crtc->config->has_audio)
  2004. intel_audio_codec_disable(encoder);
  2005. if (HAS_PSR(dev) && !HAS_DDI(dev))
  2006. intel_psr_disable(intel_dp);
  2007. /* Make sure the panel is off before trying to change the mode. But also
  2008. * ensure that we have vdd while we switch off the panel. */
  2009. intel_edp_panel_vdd_on(intel_dp);
  2010. intel_edp_backlight_off(intel_dp);
  2011. intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
  2012. intel_edp_panel_off(intel_dp);
  2013. /* disable the port before the pipe on g4x */
  2014. if (INTEL_INFO(dev)->gen < 5)
  2015. intel_dp_link_down(intel_dp);
  2016. }
  2017. static void ilk_post_disable_dp(struct intel_encoder *encoder)
  2018. {
  2019. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  2020. enum port port = dp_to_dig_port(intel_dp)->port;
  2021. intel_dp_link_down(intel_dp);
  2022. /* Only ilk+ has port A */
  2023. if (port == PORT_A)
  2024. ironlake_edp_pll_off(intel_dp);
  2025. }
  2026. static void vlv_post_disable_dp(struct intel_encoder *encoder)
  2027. {
  2028. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  2029. intel_dp_link_down(intel_dp);
  2030. }
  2031. static void chv_post_disable_dp(struct intel_encoder *encoder)
  2032. {
  2033. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  2034. struct drm_device *dev = encoder->base.dev;
  2035. struct drm_i915_private *dev_priv = dev->dev_private;
  2036. intel_dp_link_down(intel_dp);
  2037. mutex_lock(&dev_priv->sb_lock);
  2038. /* Assert data lane reset */
  2039. chv_data_lane_soft_reset(encoder, true);
  2040. mutex_unlock(&dev_priv->sb_lock);
  2041. }
  2042. static void
  2043. _intel_dp_set_link_train(struct intel_dp *intel_dp,
  2044. uint32_t *DP,
  2045. uint8_t dp_train_pat)
  2046. {
  2047. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  2048. struct drm_device *dev = intel_dig_port->base.base.dev;
  2049. struct drm_i915_private *dev_priv = dev->dev_private;
  2050. enum port port = intel_dig_port->port;
  2051. if (HAS_DDI(dev)) {
  2052. uint32_t temp = I915_READ(DP_TP_CTL(port));
  2053. if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
  2054. temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
  2055. else
  2056. temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
  2057. temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
  2058. switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
  2059. case DP_TRAINING_PATTERN_DISABLE:
  2060. temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
  2061. break;
  2062. case DP_TRAINING_PATTERN_1:
  2063. temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
  2064. break;
  2065. case DP_TRAINING_PATTERN_2:
  2066. temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
  2067. break;
  2068. case DP_TRAINING_PATTERN_3:
  2069. temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
  2070. break;
  2071. }
  2072. I915_WRITE(DP_TP_CTL(port), temp);
  2073. } else if ((IS_GEN7(dev) && port == PORT_A) ||
  2074. (HAS_PCH_CPT(dev) && port != PORT_A)) {
  2075. *DP &= ~DP_LINK_TRAIN_MASK_CPT;
  2076. switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
  2077. case DP_TRAINING_PATTERN_DISABLE:
  2078. *DP |= DP_LINK_TRAIN_OFF_CPT;
  2079. break;
  2080. case DP_TRAINING_PATTERN_1:
  2081. *DP |= DP_LINK_TRAIN_PAT_1_CPT;
  2082. break;
  2083. case DP_TRAINING_PATTERN_2:
  2084. *DP |= DP_LINK_TRAIN_PAT_2_CPT;
  2085. break;
  2086. case DP_TRAINING_PATTERN_3:
  2087. DRM_ERROR("DP training pattern 3 not supported\n");
  2088. *DP |= DP_LINK_TRAIN_PAT_2_CPT;
  2089. break;
  2090. }
  2091. } else {
  2092. if (IS_CHERRYVIEW(dev))
  2093. *DP &= ~DP_LINK_TRAIN_MASK_CHV;
  2094. else
  2095. *DP &= ~DP_LINK_TRAIN_MASK;
  2096. switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
  2097. case DP_TRAINING_PATTERN_DISABLE:
  2098. *DP |= DP_LINK_TRAIN_OFF;
  2099. break;
  2100. case DP_TRAINING_PATTERN_1:
  2101. *DP |= DP_LINK_TRAIN_PAT_1;
  2102. break;
  2103. case DP_TRAINING_PATTERN_2:
  2104. *DP |= DP_LINK_TRAIN_PAT_2;
  2105. break;
  2106. case DP_TRAINING_PATTERN_3:
  2107. if (IS_CHERRYVIEW(dev)) {
  2108. *DP |= DP_LINK_TRAIN_PAT_3_CHV;
  2109. } else {
  2110. DRM_ERROR("DP training pattern 3 not supported\n");
  2111. *DP |= DP_LINK_TRAIN_PAT_2;
  2112. }
  2113. break;
  2114. }
  2115. }
  2116. }
  2117. static void intel_dp_enable_port(struct intel_dp *intel_dp)
  2118. {
  2119. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  2120. struct drm_i915_private *dev_priv = dev->dev_private;
  2121. struct intel_crtc *crtc =
  2122. to_intel_crtc(dp_to_dig_port(intel_dp)->base.base.crtc);
  2123. /* enable with pattern 1 (as per spec) */
  2124. _intel_dp_set_link_train(intel_dp, &intel_dp->DP,
  2125. DP_TRAINING_PATTERN_1);
  2126. I915_WRITE(intel_dp->output_reg, intel_dp->DP);
  2127. POSTING_READ(intel_dp->output_reg);
  2128. /*
  2129. * Magic for VLV/CHV. We _must_ first set up the register
  2130. * without actually enabling the port, and then do another
  2131. * write to enable the port. Otherwise link training will
  2132. * fail when the power sequencer is freshly used for this port.
  2133. */
  2134. intel_dp->DP |= DP_PORT_EN;
  2135. if (crtc->config->has_audio)
  2136. intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
  2137. I915_WRITE(intel_dp->output_reg, intel_dp->DP);
  2138. POSTING_READ(intel_dp->output_reg);
  2139. }
  2140. static void intel_enable_dp(struct intel_encoder *encoder)
  2141. {
  2142. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  2143. struct drm_device *dev = encoder->base.dev;
  2144. struct drm_i915_private *dev_priv = dev->dev_private;
  2145. struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
  2146. uint32_t dp_reg = I915_READ(intel_dp->output_reg);
  2147. enum pipe pipe = crtc->pipe;
  2148. if (WARN_ON(dp_reg & DP_PORT_EN))
  2149. return;
  2150. pps_lock(intel_dp);
  2151. if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
  2152. vlv_init_panel_power_sequencer(intel_dp);
  2153. intel_dp_enable_port(intel_dp);
  2154. edp_panel_vdd_on(intel_dp);
  2155. edp_panel_on(intel_dp);
  2156. edp_panel_vdd_off(intel_dp, true);
  2157. pps_unlock(intel_dp);
  2158. if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
  2159. unsigned int lane_mask = 0x0;
  2160. if (IS_CHERRYVIEW(dev))
  2161. lane_mask = intel_dp_unused_lane_mask(crtc->config->lane_count);
  2162. vlv_wait_port_ready(dev_priv, dp_to_dig_port(intel_dp),
  2163. lane_mask);
  2164. }
  2165. intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
  2166. intel_dp_start_link_train(intel_dp);
  2167. intel_dp_stop_link_train(intel_dp);
  2168. if (crtc->config->has_audio) {
  2169. DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
  2170. pipe_name(pipe));
  2171. intel_audio_codec_enable(encoder);
  2172. }
  2173. }
  2174. static void g4x_enable_dp(struct intel_encoder *encoder)
  2175. {
  2176. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  2177. intel_enable_dp(encoder);
  2178. intel_edp_backlight_on(intel_dp);
  2179. }
  2180. static void vlv_enable_dp(struct intel_encoder *encoder)
  2181. {
  2182. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  2183. intel_edp_backlight_on(intel_dp);
  2184. intel_psr_enable(intel_dp);
  2185. }
  2186. static void g4x_pre_enable_dp(struct intel_encoder *encoder)
  2187. {
  2188. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  2189. enum port port = dp_to_dig_port(intel_dp)->port;
  2190. intel_dp_prepare(encoder);
  2191. /* Only ilk+ has port A */
  2192. if (port == PORT_A)
  2193. ironlake_edp_pll_on(intel_dp);
  2194. }
  2195. static void vlv_detach_power_sequencer(struct intel_dp *intel_dp)
  2196. {
  2197. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  2198. struct drm_i915_private *dev_priv = intel_dig_port->base.base.dev->dev_private;
  2199. enum pipe pipe = intel_dp->pps_pipe;
  2200. i915_reg_t pp_on_reg = VLV_PIPE_PP_ON_DELAYS(pipe);
  2201. edp_panel_vdd_off_sync(intel_dp);
  2202. /*
  2203. * VLV seems to get confused when multiple power seqeuencers
  2204. * have the same port selected (even if only one has power/vdd
  2205. * enabled). The failure manifests as vlv_wait_port_ready() failing
  2206. * CHV on the other hand doesn't seem to mind having the same port
  2207. * selected in multiple power seqeuencers, but let's clear the
  2208. * port select always when logically disconnecting a power sequencer
  2209. * from a port.
  2210. */
  2211. DRM_DEBUG_KMS("detaching pipe %c power sequencer from port %c\n",
  2212. pipe_name(pipe), port_name(intel_dig_port->port));
  2213. I915_WRITE(pp_on_reg, 0);
  2214. POSTING_READ(pp_on_reg);
  2215. intel_dp->pps_pipe = INVALID_PIPE;
  2216. }
  2217. static void vlv_steal_power_sequencer(struct drm_device *dev,
  2218. enum pipe pipe)
  2219. {
  2220. struct drm_i915_private *dev_priv = dev->dev_private;
  2221. struct intel_encoder *encoder;
  2222. lockdep_assert_held(&dev_priv->pps_mutex);
  2223. if (WARN_ON(pipe != PIPE_A && pipe != PIPE_B))
  2224. return;
  2225. for_each_intel_encoder(dev, encoder) {
  2226. struct intel_dp *intel_dp;
  2227. enum port port;
  2228. if (encoder->type != INTEL_OUTPUT_EDP)
  2229. continue;
  2230. intel_dp = enc_to_intel_dp(&encoder->base);
  2231. port = dp_to_dig_port(intel_dp)->port;
  2232. if (intel_dp->pps_pipe != pipe)
  2233. continue;
  2234. DRM_DEBUG_KMS("stealing pipe %c power sequencer from port %c\n",
  2235. pipe_name(pipe), port_name(port));
  2236. WARN(encoder->base.crtc,
  2237. "stealing pipe %c power sequencer from active eDP port %c\n",
  2238. pipe_name(pipe), port_name(port));
  2239. /* make sure vdd is off before we steal it */
  2240. vlv_detach_power_sequencer(intel_dp);
  2241. }
  2242. }
  2243. static void vlv_init_panel_power_sequencer(struct intel_dp *intel_dp)
  2244. {
  2245. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  2246. struct intel_encoder *encoder = &intel_dig_port->base;
  2247. struct drm_device *dev = encoder->base.dev;
  2248. struct drm_i915_private *dev_priv = dev->dev_private;
  2249. struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
  2250. lockdep_assert_held(&dev_priv->pps_mutex);
  2251. if (!is_edp(intel_dp))
  2252. return;
  2253. if (intel_dp->pps_pipe == crtc->pipe)
  2254. return;
  2255. /*
  2256. * If another power sequencer was being used on this
  2257. * port previously make sure to turn off vdd there while
  2258. * we still have control of it.
  2259. */
  2260. if (intel_dp->pps_pipe != INVALID_PIPE)
  2261. vlv_detach_power_sequencer(intel_dp);
  2262. /*
  2263. * We may be stealing the power
  2264. * sequencer from another port.
  2265. */
  2266. vlv_steal_power_sequencer(dev, crtc->pipe);
  2267. /* now it's all ours */
  2268. intel_dp->pps_pipe = crtc->pipe;
  2269. DRM_DEBUG_KMS("initializing pipe %c power sequencer for port %c\n",
  2270. pipe_name(intel_dp->pps_pipe), port_name(intel_dig_port->port));
  2271. /* init power sequencer on this pipe and port */
  2272. intel_dp_init_panel_power_sequencer(dev, intel_dp);
  2273. intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
  2274. }
  2275. static void vlv_pre_enable_dp(struct intel_encoder *encoder)
  2276. {
  2277. vlv_phy_pre_encoder_enable(encoder);
  2278. intel_enable_dp(encoder);
  2279. }
  2280. static void vlv_dp_pre_pll_enable(struct intel_encoder *encoder)
  2281. {
  2282. intel_dp_prepare(encoder);
  2283. vlv_phy_pre_pll_enable(encoder);
  2284. }
  2285. static void chv_pre_enable_dp(struct intel_encoder *encoder)
  2286. {
  2287. chv_phy_pre_encoder_enable(encoder);
  2288. intel_enable_dp(encoder);
  2289. /* Second common lane will stay alive on its own now */
  2290. chv_phy_release_cl2_override(encoder);
  2291. }
  2292. static void chv_dp_pre_pll_enable(struct intel_encoder *encoder)
  2293. {
  2294. intel_dp_prepare(encoder);
  2295. chv_phy_pre_pll_enable(encoder);
  2296. }
  2297. static void chv_dp_post_pll_disable(struct intel_encoder *encoder)
  2298. {
  2299. chv_phy_post_pll_disable(encoder);
  2300. }
  2301. /*
  2302. * Fetch AUX CH registers 0x202 - 0x207 which contain
  2303. * link status information
  2304. */
  2305. bool
  2306. intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
  2307. {
  2308. return drm_dp_dpcd_read(&intel_dp->aux, DP_LANE0_1_STATUS, link_status,
  2309. DP_LINK_STATUS_SIZE) == DP_LINK_STATUS_SIZE;
  2310. }
  2311. /* These are source-specific values. */
  2312. uint8_t
  2313. intel_dp_voltage_max(struct intel_dp *intel_dp)
  2314. {
  2315. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  2316. struct drm_i915_private *dev_priv = dev->dev_private;
  2317. enum port port = dp_to_dig_port(intel_dp)->port;
  2318. if (IS_BROXTON(dev))
  2319. return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
  2320. else if (INTEL_INFO(dev)->gen >= 9) {
  2321. if (dev_priv->vbt.edp.low_vswing && port == PORT_A)
  2322. return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
  2323. return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
  2324. } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
  2325. return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
  2326. else if (IS_GEN7(dev) && port == PORT_A)
  2327. return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
  2328. else if (HAS_PCH_CPT(dev) && port != PORT_A)
  2329. return DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
  2330. else
  2331. return DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
  2332. }
  2333. uint8_t
  2334. intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
  2335. {
  2336. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  2337. enum port port = dp_to_dig_port(intel_dp)->port;
  2338. if (INTEL_INFO(dev)->gen >= 9) {
  2339. switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2340. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2341. return DP_TRAIN_PRE_EMPH_LEVEL_3;
  2342. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2343. return DP_TRAIN_PRE_EMPH_LEVEL_2;
  2344. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
  2345. return DP_TRAIN_PRE_EMPH_LEVEL_1;
  2346. case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
  2347. return DP_TRAIN_PRE_EMPH_LEVEL_0;
  2348. default:
  2349. return DP_TRAIN_PRE_EMPH_LEVEL_0;
  2350. }
  2351. } else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
  2352. switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2353. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2354. return DP_TRAIN_PRE_EMPH_LEVEL_3;
  2355. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2356. return DP_TRAIN_PRE_EMPH_LEVEL_2;
  2357. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
  2358. return DP_TRAIN_PRE_EMPH_LEVEL_1;
  2359. case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
  2360. default:
  2361. return DP_TRAIN_PRE_EMPH_LEVEL_0;
  2362. }
  2363. } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
  2364. switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2365. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2366. return DP_TRAIN_PRE_EMPH_LEVEL_3;
  2367. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2368. return DP_TRAIN_PRE_EMPH_LEVEL_2;
  2369. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
  2370. return DP_TRAIN_PRE_EMPH_LEVEL_1;
  2371. case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
  2372. default:
  2373. return DP_TRAIN_PRE_EMPH_LEVEL_0;
  2374. }
  2375. } else if (IS_GEN7(dev) && port == PORT_A) {
  2376. switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2377. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2378. return DP_TRAIN_PRE_EMPH_LEVEL_2;
  2379. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2380. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
  2381. return DP_TRAIN_PRE_EMPH_LEVEL_1;
  2382. default:
  2383. return DP_TRAIN_PRE_EMPH_LEVEL_0;
  2384. }
  2385. } else {
  2386. switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2387. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2388. return DP_TRAIN_PRE_EMPH_LEVEL_2;
  2389. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2390. return DP_TRAIN_PRE_EMPH_LEVEL_2;
  2391. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
  2392. return DP_TRAIN_PRE_EMPH_LEVEL_1;
  2393. case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
  2394. default:
  2395. return DP_TRAIN_PRE_EMPH_LEVEL_0;
  2396. }
  2397. }
  2398. }
  2399. static uint32_t vlv_signal_levels(struct intel_dp *intel_dp)
  2400. {
  2401. struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
  2402. unsigned long demph_reg_value, preemph_reg_value,
  2403. uniqtranscale_reg_value;
  2404. uint8_t train_set = intel_dp->train_set[0];
  2405. switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
  2406. case DP_TRAIN_PRE_EMPH_LEVEL_0:
  2407. preemph_reg_value = 0x0004000;
  2408. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2409. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2410. demph_reg_value = 0x2B405555;
  2411. uniqtranscale_reg_value = 0x552AB83A;
  2412. break;
  2413. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2414. demph_reg_value = 0x2B404040;
  2415. uniqtranscale_reg_value = 0x5548B83A;
  2416. break;
  2417. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
  2418. demph_reg_value = 0x2B245555;
  2419. uniqtranscale_reg_value = 0x5560B83A;
  2420. break;
  2421. case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
  2422. demph_reg_value = 0x2B405555;
  2423. uniqtranscale_reg_value = 0x5598DA3A;
  2424. break;
  2425. default:
  2426. return 0;
  2427. }
  2428. break;
  2429. case DP_TRAIN_PRE_EMPH_LEVEL_1:
  2430. preemph_reg_value = 0x0002000;
  2431. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2432. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2433. demph_reg_value = 0x2B404040;
  2434. uniqtranscale_reg_value = 0x5552B83A;
  2435. break;
  2436. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2437. demph_reg_value = 0x2B404848;
  2438. uniqtranscale_reg_value = 0x5580B83A;
  2439. break;
  2440. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
  2441. demph_reg_value = 0x2B404040;
  2442. uniqtranscale_reg_value = 0x55ADDA3A;
  2443. break;
  2444. default:
  2445. return 0;
  2446. }
  2447. break;
  2448. case DP_TRAIN_PRE_EMPH_LEVEL_2:
  2449. preemph_reg_value = 0x0000000;
  2450. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2451. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2452. demph_reg_value = 0x2B305555;
  2453. uniqtranscale_reg_value = 0x5570B83A;
  2454. break;
  2455. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2456. demph_reg_value = 0x2B2B4040;
  2457. uniqtranscale_reg_value = 0x55ADDA3A;
  2458. break;
  2459. default:
  2460. return 0;
  2461. }
  2462. break;
  2463. case DP_TRAIN_PRE_EMPH_LEVEL_3:
  2464. preemph_reg_value = 0x0006000;
  2465. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2466. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2467. demph_reg_value = 0x1B405555;
  2468. uniqtranscale_reg_value = 0x55ADDA3A;
  2469. break;
  2470. default:
  2471. return 0;
  2472. }
  2473. break;
  2474. default:
  2475. return 0;
  2476. }
  2477. vlv_set_phy_signal_level(encoder, demph_reg_value, preemph_reg_value,
  2478. uniqtranscale_reg_value, 0);
  2479. return 0;
  2480. }
  2481. static uint32_t chv_signal_levels(struct intel_dp *intel_dp)
  2482. {
  2483. struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base;
  2484. u32 deemph_reg_value, margin_reg_value;
  2485. bool uniq_trans_scale = false;
  2486. uint8_t train_set = intel_dp->train_set[0];
  2487. switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
  2488. case DP_TRAIN_PRE_EMPH_LEVEL_0:
  2489. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2490. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2491. deemph_reg_value = 128;
  2492. margin_reg_value = 52;
  2493. break;
  2494. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2495. deemph_reg_value = 128;
  2496. margin_reg_value = 77;
  2497. break;
  2498. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
  2499. deemph_reg_value = 128;
  2500. margin_reg_value = 102;
  2501. break;
  2502. case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
  2503. deemph_reg_value = 128;
  2504. margin_reg_value = 154;
  2505. uniq_trans_scale = true;
  2506. break;
  2507. default:
  2508. return 0;
  2509. }
  2510. break;
  2511. case DP_TRAIN_PRE_EMPH_LEVEL_1:
  2512. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2513. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2514. deemph_reg_value = 85;
  2515. margin_reg_value = 78;
  2516. break;
  2517. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2518. deemph_reg_value = 85;
  2519. margin_reg_value = 116;
  2520. break;
  2521. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
  2522. deemph_reg_value = 85;
  2523. margin_reg_value = 154;
  2524. break;
  2525. default:
  2526. return 0;
  2527. }
  2528. break;
  2529. case DP_TRAIN_PRE_EMPH_LEVEL_2:
  2530. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2531. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2532. deemph_reg_value = 64;
  2533. margin_reg_value = 104;
  2534. break;
  2535. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2536. deemph_reg_value = 64;
  2537. margin_reg_value = 154;
  2538. break;
  2539. default:
  2540. return 0;
  2541. }
  2542. break;
  2543. case DP_TRAIN_PRE_EMPH_LEVEL_3:
  2544. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2545. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2546. deemph_reg_value = 43;
  2547. margin_reg_value = 154;
  2548. break;
  2549. default:
  2550. return 0;
  2551. }
  2552. break;
  2553. default:
  2554. return 0;
  2555. }
  2556. chv_set_phy_signal_level(encoder, deemph_reg_value,
  2557. margin_reg_value, uniq_trans_scale);
  2558. return 0;
  2559. }
  2560. static uint32_t
  2561. gen4_signal_levels(uint8_t train_set)
  2562. {
  2563. uint32_t signal_levels = 0;
  2564. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  2565. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0:
  2566. default:
  2567. signal_levels |= DP_VOLTAGE_0_4;
  2568. break;
  2569. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1:
  2570. signal_levels |= DP_VOLTAGE_0_6;
  2571. break;
  2572. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2:
  2573. signal_levels |= DP_VOLTAGE_0_8;
  2574. break;
  2575. case DP_TRAIN_VOLTAGE_SWING_LEVEL_3:
  2576. signal_levels |= DP_VOLTAGE_1_2;
  2577. break;
  2578. }
  2579. switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
  2580. case DP_TRAIN_PRE_EMPH_LEVEL_0:
  2581. default:
  2582. signal_levels |= DP_PRE_EMPHASIS_0;
  2583. break;
  2584. case DP_TRAIN_PRE_EMPH_LEVEL_1:
  2585. signal_levels |= DP_PRE_EMPHASIS_3_5;
  2586. break;
  2587. case DP_TRAIN_PRE_EMPH_LEVEL_2:
  2588. signal_levels |= DP_PRE_EMPHASIS_6;
  2589. break;
  2590. case DP_TRAIN_PRE_EMPH_LEVEL_3:
  2591. signal_levels |= DP_PRE_EMPHASIS_9_5;
  2592. break;
  2593. }
  2594. return signal_levels;
  2595. }
  2596. /* Gen6's DP voltage swing and pre-emphasis control */
  2597. static uint32_t
  2598. gen6_edp_signal_levels(uint8_t train_set)
  2599. {
  2600. int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
  2601. DP_TRAIN_PRE_EMPHASIS_MASK);
  2602. switch (signal_levels) {
  2603. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
  2604. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
  2605. return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
  2606. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
  2607. return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
  2608. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
  2609. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
  2610. return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
  2611. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
  2612. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
  2613. return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
  2614. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
  2615. case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0:
  2616. return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
  2617. default:
  2618. DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
  2619. "0x%x\n", signal_levels);
  2620. return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
  2621. }
  2622. }
  2623. /* Gen7's DP voltage swing and pre-emphasis control */
  2624. static uint32_t
  2625. gen7_edp_signal_levels(uint8_t train_set)
  2626. {
  2627. int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
  2628. DP_TRAIN_PRE_EMPHASIS_MASK);
  2629. switch (signal_levels) {
  2630. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
  2631. return EDP_LINK_TRAIN_400MV_0DB_IVB;
  2632. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
  2633. return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
  2634. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
  2635. return EDP_LINK_TRAIN_400MV_6DB_IVB;
  2636. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
  2637. return EDP_LINK_TRAIN_600MV_0DB_IVB;
  2638. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
  2639. return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
  2640. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
  2641. return EDP_LINK_TRAIN_800MV_0DB_IVB;
  2642. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
  2643. return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
  2644. default:
  2645. DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
  2646. "0x%x\n", signal_levels);
  2647. return EDP_LINK_TRAIN_500MV_0DB_IVB;
  2648. }
  2649. }
  2650. void
  2651. intel_dp_set_signal_levels(struct intel_dp *intel_dp)
  2652. {
  2653. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  2654. enum port port = intel_dig_port->port;
  2655. struct drm_device *dev = intel_dig_port->base.base.dev;
  2656. struct drm_i915_private *dev_priv = to_i915(dev);
  2657. uint32_t signal_levels, mask = 0;
  2658. uint8_t train_set = intel_dp->train_set[0];
  2659. if (HAS_DDI(dev)) {
  2660. signal_levels = ddi_signal_levels(intel_dp);
  2661. if (IS_BROXTON(dev))
  2662. signal_levels = 0;
  2663. else
  2664. mask = DDI_BUF_EMP_MASK;
  2665. } else if (IS_CHERRYVIEW(dev)) {
  2666. signal_levels = chv_signal_levels(intel_dp);
  2667. } else if (IS_VALLEYVIEW(dev)) {
  2668. signal_levels = vlv_signal_levels(intel_dp);
  2669. } else if (IS_GEN7(dev) && port == PORT_A) {
  2670. signal_levels = gen7_edp_signal_levels(train_set);
  2671. mask = EDP_LINK_TRAIN_VOL_EMP_MASK_IVB;
  2672. } else if (IS_GEN6(dev) && port == PORT_A) {
  2673. signal_levels = gen6_edp_signal_levels(train_set);
  2674. mask = EDP_LINK_TRAIN_VOL_EMP_MASK_SNB;
  2675. } else {
  2676. signal_levels = gen4_signal_levels(train_set);
  2677. mask = DP_VOLTAGE_MASK | DP_PRE_EMPHASIS_MASK;
  2678. }
  2679. if (mask)
  2680. DRM_DEBUG_KMS("Using signal levels %08x\n", signal_levels);
  2681. DRM_DEBUG_KMS("Using vswing level %d\n",
  2682. train_set & DP_TRAIN_VOLTAGE_SWING_MASK);
  2683. DRM_DEBUG_KMS("Using pre-emphasis level %d\n",
  2684. (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) >>
  2685. DP_TRAIN_PRE_EMPHASIS_SHIFT);
  2686. intel_dp->DP = (intel_dp->DP & ~mask) | signal_levels;
  2687. I915_WRITE(intel_dp->output_reg, intel_dp->DP);
  2688. POSTING_READ(intel_dp->output_reg);
  2689. }
  2690. void
  2691. intel_dp_program_link_training_pattern(struct intel_dp *intel_dp,
  2692. uint8_t dp_train_pat)
  2693. {
  2694. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  2695. struct drm_i915_private *dev_priv =
  2696. to_i915(intel_dig_port->base.base.dev);
  2697. _intel_dp_set_link_train(intel_dp, &intel_dp->DP, dp_train_pat);
  2698. I915_WRITE(intel_dp->output_reg, intel_dp->DP);
  2699. POSTING_READ(intel_dp->output_reg);
  2700. }
  2701. void intel_dp_set_idle_link_train(struct intel_dp *intel_dp)
  2702. {
  2703. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  2704. struct drm_device *dev = intel_dig_port->base.base.dev;
  2705. struct drm_i915_private *dev_priv = dev->dev_private;
  2706. enum port port = intel_dig_port->port;
  2707. uint32_t val;
  2708. if (!HAS_DDI(dev))
  2709. return;
  2710. val = I915_READ(DP_TP_CTL(port));
  2711. val &= ~DP_TP_CTL_LINK_TRAIN_MASK;
  2712. val |= DP_TP_CTL_LINK_TRAIN_IDLE;
  2713. I915_WRITE(DP_TP_CTL(port), val);
  2714. /*
  2715. * On PORT_A we can have only eDP in SST mode. There the only reason
  2716. * we need to set idle transmission mode is to work around a HW issue
  2717. * where we enable the pipe while not in idle link-training mode.
  2718. * In this case there is requirement to wait for a minimum number of
  2719. * idle patterns to be sent.
  2720. */
  2721. if (port == PORT_A)
  2722. return;
  2723. if (wait_for((I915_READ(DP_TP_STATUS(port)) & DP_TP_STATUS_IDLE_DONE),
  2724. 1))
  2725. DRM_ERROR("Timed out waiting for DP idle patterns\n");
  2726. }
  2727. static void
  2728. intel_dp_link_down(struct intel_dp *intel_dp)
  2729. {
  2730. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  2731. struct intel_crtc *crtc = to_intel_crtc(intel_dig_port->base.base.crtc);
  2732. enum port port = intel_dig_port->port;
  2733. struct drm_device *dev = intel_dig_port->base.base.dev;
  2734. struct drm_i915_private *dev_priv = dev->dev_private;
  2735. uint32_t DP = intel_dp->DP;
  2736. if (WARN_ON(HAS_DDI(dev)))
  2737. return;
  2738. if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
  2739. return;
  2740. DRM_DEBUG_KMS("\n");
  2741. if ((IS_GEN7(dev) && port == PORT_A) ||
  2742. (HAS_PCH_CPT(dev) && port != PORT_A)) {
  2743. DP &= ~DP_LINK_TRAIN_MASK_CPT;
  2744. DP |= DP_LINK_TRAIN_PAT_IDLE_CPT;
  2745. } else {
  2746. if (IS_CHERRYVIEW(dev))
  2747. DP &= ~DP_LINK_TRAIN_MASK_CHV;
  2748. else
  2749. DP &= ~DP_LINK_TRAIN_MASK;
  2750. DP |= DP_LINK_TRAIN_PAT_IDLE;
  2751. }
  2752. I915_WRITE(intel_dp->output_reg, DP);
  2753. POSTING_READ(intel_dp->output_reg);
  2754. DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
  2755. I915_WRITE(intel_dp->output_reg, DP);
  2756. POSTING_READ(intel_dp->output_reg);
  2757. /*
  2758. * HW workaround for IBX, we need to move the port
  2759. * to transcoder A after disabling it to allow the
  2760. * matching HDMI port to be enabled on transcoder A.
  2761. */
  2762. if (HAS_PCH_IBX(dev) && crtc->pipe == PIPE_B && port != PORT_A) {
  2763. /*
  2764. * We get CPU/PCH FIFO underruns on the other pipe when
  2765. * doing the workaround. Sweep them under the rug.
  2766. */
  2767. intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
  2768. intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
  2769. /* always enable with pattern 1 (as per spec) */
  2770. DP &= ~(DP_PIPEB_SELECT | DP_LINK_TRAIN_MASK);
  2771. DP |= DP_PORT_EN | DP_LINK_TRAIN_PAT_1;
  2772. I915_WRITE(intel_dp->output_reg, DP);
  2773. POSTING_READ(intel_dp->output_reg);
  2774. DP &= ~DP_PORT_EN;
  2775. I915_WRITE(intel_dp->output_reg, DP);
  2776. POSTING_READ(intel_dp->output_reg);
  2777. intel_wait_for_vblank_if_active(dev_priv->dev, PIPE_A);
  2778. intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
  2779. intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
  2780. }
  2781. msleep(intel_dp->panel_power_down_delay);
  2782. intel_dp->DP = DP;
  2783. }
  2784. static bool
  2785. intel_dp_get_dpcd(struct intel_dp *intel_dp)
  2786. {
  2787. struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
  2788. struct drm_device *dev = dig_port->base.base.dev;
  2789. struct drm_i915_private *dev_priv = dev->dev_private;
  2790. if (drm_dp_dpcd_read(&intel_dp->aux, 0x000, intel_dp->dpcd,
  2791. sizeof(intel_dp->dpcd)) < 0)
  2792. return false; /* aux transfer failed */
  2793. DRM_DEBUG_KMS("DPCD: %*ph\n", (int) sizeof(intel_dp->dpcd), intel_dp->dpcd);
  2794. if (intel_dp->dpcd[DP_DPCD_REV] == 0)
  2795. return false; /* DPCD not present */
  2796. if (drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_COUNT,
  2797. &intel_dp->sink_count, 1) < 0)
  2798. return false;
  2799. /*
  2800. * Sink count can change between short pulse hpd hence
  2801. * a member variable in intel_dp will track any changes
  2802. * between short pulse interrupts.
  2803. */
  2804. intel_dp->sink_count = DP_GET_SINK_COUNT(intel_dp->sink_count);
  2805. /*
  2806. * SINK_COUNT == 0 and DOWNSTREAM_PORT_PRESENT == 1 implies that
  2807. * a dongle is present but no display. Unless we require to know
  2808. * if a dongle is present or not, we don't need to update
  2809. * downstream port information. So, an early return here saves
  2810. * time from performing other operations which are not required.
  2811. */
  2812. if (!is_edp(intel_dp) && !intel_dp->sink_count)
  2813. return false;
  2814. /* Check if the panel supports PSR */
  2815. memset(intel_dp->psr_dpcd, 0, sizeof(intel_dp->psr_dpcd));
  2816. if (is_edp(intel_dp)) {
  2817. drm_dp_dpcd_read(&intel_dp->aux, DP_PSR_SUPPORT,
  2818. intel_dp->psr_dpcd,
  2819. sizeof(intel_dp->psr_dpcd));
  2820. if (intel_dp->psr_dpcd[0] & DP_PSR_IS_SUPPORTED) {
  2821. dev_priv->psr.sink_support = true;
  2822. DRM_DEBUG_KMS("Detected EDP PSR Panel.\n");
  2823. }
  2824. if (INTEL_INFO(dev)->gen >= 9 &&
  2825. (intel_dp->psr_dpcd[0] & DP_PSR2_IS_SUPPORTED)) {
  2826. uint8_t frame_sync_cap;
  2827. dev_priv->psr.sink_support = true;
  2828. drm_dp_dpcd_read(&intel_dp->aux,
  2829. DP_SINK_DEVICE_AUX_FRAME_SYNC_CAP,
  2830. &frame_sync_cap, 1);
  2831. dev_priv->psr.aux_frame_sync = frame_sync_cap ? true : false;
  2832. /* PSR2 needs frame sync as well */
  2833. dev_priv->psr.psr2_support = dev_priv->psr.aux_frame_sync;
  2834. DRM_DEBUG_KMS("PSR2 %s on sink",
  2835. dev_priv->psr.psr2_support ? "supported" : "not supported");
  2836. }
  2837. /* Read the eDP Display control capabilities registers */
  2838. memset(intel_dp->edp_dpcd, 0, sizeof(intel_dp->edp_dpcd));
  2839. if ((intel_dp->dpcd[DP_EDP_CONFIGURATION_CAP] & DP_DPCD_DISPLAY_CONTROL_CAPABLE) &&
  2840. (drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_DPCD_REV,
  2841. intel_dp->edp_dpcd, sizeof(intel_dp->edp_dpcd)) ==
  2842. sizeof(intel_dp->edp_dpcd)))
  2843. DRM_DEBUG_KMS("EDP DPCD : %*ph\n", (int) sizeof(intel_dp->edp_dpcd),
  2844. intel_dp->edp_dpcd);
  2845. }
  2846. DRM_DEBUG_KMS("Display Port TPS3 support: source %s, sink %s\n",
  2847. yesno(intel_dp_source_supports_hbr2(intel_dp)),
  2848. yesno(drm_dp_tps3_supported(intel_dp->dpcd)));
  2849. /* Intermediate frequency support */
  2850. if (is_edp(intel_dp) && (intel_dp->edp_dpcd[0] >= 0x03)) { /* eDp v1.4 or higher */
  2851. __le16 sink_rates[DP_MAX_SUPPORTED_RATES];
  2852. int i;
  2853. drm_dp_dpcd_read(&intel_dp->aux, DP_SUPPORTED_LINK_RATES,
  2854. sink_rates, sizeof(sink_rates));
  2855. for (i = 0; i < ARRAY_SIZE(sink_rates); i++) {
  2856. int val = le16_to_cpu(sink_rates[i]);
  2857. if (val == 0)
  2858. break;
  2859. /* Value read is in kHz while drm clock is saved in deca-kHz */
  2860. intel_dp->sink_rates[i] = (val * 200) / 10;
  2861. }
  2862. intel_dp->num_sink_rates = i;
  2863. }
  2864. intel_dp_print_rates(intel_dp);
  2865. if (!(intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
  2866. DP_DWN_STRM_PORT_PRESENT))
  2867. return true; /* native DP sink */
  2868. if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
  2869. return true; /* no per-port downstream info */
  2870. if (drm_dp_dpcd_read(&intel_dp->aux, DP_DOWNSTREAM_PORT_0,
  2871. intel_dp->downstream_ports,
  2872. DP_MAX_DOWNSTREAM_PORTS) < 0)
  2873. return false; /* downstream port status fetch failed */
  2874. return true;
  2875. }
  2876. static void
  2877. intel_dp_probe_oui(struct intel_dp *intel_dp)
  2878. {
  2879. u8 buf[3];
  2880. if (!(intel_dp->dpcd[DP_DOWN_STREAM_PORT_COUNT] & DP_OUI_SUPPORT))
  2881. return;
  2882. if (drm_dp_dpcd_read(&intel_dp->aux, DP_SINK_OUI, buf, 3) == 3)
  2883. DRM_DEBUG_KMS("Sink OUI: %02hx%02hx%02hx\n",
  2884. buf[0], buf[1], buf[2]);
  2885. if (drm_dp_dpcd_read(&intel_dp->aux, DP_BRANCH_OUI, buf, 3) == 3)
  2886. DRM_DEBUG_KMS("Branch OUI: %02hx%02hx%02hx\n",
  2887. buf[0], buf[1], buf[2]);
  2888. }
  2889. static bool
  2890. intel_dp_probe_mst(struct intel_dp *intel_dp)
  2891. {
  2892. u8 buf[1];
  2893. if (!i915.enable_dp_mst)
  2894. return false;
  2895. if (!intel_dp->can_mst)
  2896. return false;
  2897. if (intel_dp->dpcd[DP_DPCD_REV] < 0x12)
  2898. return false;
  2899. if (drm_dp_dpcd_read(&intel_dp->aux, DP_MSTM_CAP, buf, 1)) {
  2900. if (buf[0] & DP_MST_CAP) {
  2901. DRM_DEBUG_KMS("Sink is MST capable\n");
  2902. intel_dp->is_mst = true;
  2903. } else {
  2904. DRM_DEBUG_KMS("Sink is not MST capable\n");
  2905. intel_dp->is_mst = false;
  2906. }
  2907. }
  2908. drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
  2909. return intel_dp->is_mst;
  2910. }
  2911. static int intel_dp_sink_crc_stop(struct intel_dp *intel_dp)
  2912. {
  2913. struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
  2914. struct drm_device *dev = dig_port->base.base.dev;
  2915. struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
  2916. u8 buf;
  2917. int ret = 0;
  2918. int count = 0;
  2919. int attempts = 10;
  2920. if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0) {
  2921. DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
  2922. ret = -EIO;
  2923. goto out;
  2924. }
  2925. if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
  2926. buf & ~DP_TEST_SINK_START) < 0) {
  2927. DRM_DEBUG_KMS("Sink CRC couldn't be stopped properly\n");
  2928. ret = -EIO;
  2929. goto out;
  2930. }
  2931. do {
  2932. intel_wait_for_vblank(dev, intel_crtc->pipe);
  2933. if (drm_dp_dpcd_readb(&intel_dp->aux,
  2934. DP_TEST_SINK_MISC, &buf) < 0) {
  2935. ret = -EIO;
  2936. goto out;
  2937. }
  2938. count = buf & DP_TEST_COUNT_MASK;
  2939. } while (--attempts && count);
  2940. if (attempts == 0) {
  2941. DRM_DEBUG_KMS("TIMEOUT: Sink CRC counter is not zeroed after calculation is stopped\n");
  2942. ret = -ETIMEDOUT;
  2943. }
  2944. out:
  2945. hsw_enable_ips(intel_crtc);
  2946. return ret;
  2947. }
  2948. static int intel_dp_sink_crc_start(struct intel_dp *intel_dp)
  2949. {
  2950. struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
  2951. struct drm_device *dev = dig_port->base.base.dev;
  2952. struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
  2953. u8 buf;
  2954. int ret;
  2955. if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK_MISC, &buf) < 0)
  2956. return -EIO;
  2957. if (!(buf & DP_TEST_CRC_SUPPORTED))
  2958. return -ENOTTY;
  2959. if (drm_dp_dpcd_readb(&intel_dp->aux, DP_TEST_SINK, &buf) < 0)
  2960. return -EIO;
  2961. if (buf & DP_TEST_SINK_START) {
  2962. ret = intel_dp_sink_crc_stop(intel_dp);
  2963. if (ret)
  2964. return ret;
  2965. }
  2966. hsw_disable_ips(intel_crtc);
  2967. if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_TEST_SINK,
  2968. buf | DP_TEST_SINK_START) < 0) {
  2969. hsw_enable_ips(intel_crtc);
  2970. return -EIO;
  2971. }
  2972. intel_wait_for_vblank(dev, intel_crtc->pipe);
  2973. return 0;
  2974. }
  2975. int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc)
  2976. {
  2977. struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
  2978. struct drm_device *dev = dig_port->base.base.dev;
  2979. struct intel_crtc *intel_crtc = to_intel_crtc(dig_port->base.base.crtc);
  2980. u8 buf;
  2981. int count, ret;
  2982. int attempts = 6;
  2983. ret = intel_dp_sink_crc_start(intel_dp);
  2984. if (ret)
  2985. return ret;
  2986. do {
  2987. intel_wait_for_vblank(dev, intel_crtc->pipe);
  2988. if (drm_dp_dpcd_readb(&intel_dp->aux,
  2989. DP_TEST_SINK_MISC, &buf) < 0) {
  2990. ret = -EIO;
  2991. goto stop;
  2992. }
  2993. count = buf & DP_TEST_COUNT_MASK;
  2994. } while (--attempts && count == 0);
  2995. if (attempts == 0) {
  2996. DRM_ERROR("Panel is unable to calculate any CRC after 6 vblanks\n");
  2997. ret = -ETIMEDOUT;
  2998. goto stop;
  2999. }
  3000. if (drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_CRC_R_CR, crc, 6) < 0) {
  3001. ret = -EIO;
  3002. goto stop;
  3003. }
  3004. stop:
  3005. intel_dp_sink_crc_stop(intel_dp);
  3006. return ret;
  3007. }
  3008. static bool
  3009. intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
  3010. {
  3011. return drm_dp_dpcd_read(&intel_dp->aux,
  3012. DP_DEVICE_SERVICE_IRQ_VECTOR,
  3013. sink_irq_vector, 1) == 1;
  3014. }
  3015. static bool
  3016. intel_dp_get_sink_irq_esi(struct intel_dp *intel_dp, u8 *sink_irq_vector)
  3017. {
  3018. int ret;
  3019. ret = drm_dp_dpcd_read(&intel_dp->aux,
  3020. DP_SINK_COUNT_ESI,
  3021. sink_irq_vector, 14);
  3022. if (ret != 14)
  3023. return false;
  3024. return true;
  3025. }
  3026. static uint8_t intel_dp_autotest_link_training(struct intel_dp *intel_dp)
  3027. {
  3028. uint8_t test_result = DP_TEST_ACK;
  3029. return test_result;
  3030. }
  3031. static uint8_t intel_dp_autotest_video_pattern(struct intel_dp *intel_dp)
  3032. {
  3033. uint8_t test_result = DP_TEST_NAK;
  3034. return test_result;
  3035. }
  3036. static uint8_t intel_dp_autotest_edid(struct intel_dp *intel_dp)
  3037. {
  3038. uint8_t test_result = DP_TEST_NAK;
  3039. struct intel_connector *intel_connector = intel_dp->attached_connector;
  3040. struct drm_connector *connector = &intel_connector->base;
  3041. if (intel_connector->detect_edid == NULL ||
  3042. connector->edid_corrupt ||
  3043. intel_dp->aux.i2c_defer_count > 6) {
  3044. /* Check EDID read for NACKs, DEFERs and corruption
  3045. * (DP CTS 1.2 Core r1.1)
  3046. * 4.2.2.4 : Failed EDID read, I2C_NAK
  3047. * 4.2.2.5 : Failed EDID read, I2C_DEFER
  3048. * 4.2.2.6 : EDID corruption detected
  3049. * Use failsafe mode for all cases
  3050. */
  3051. if (intel_dp->aux.i2c_nack_count > 0 ||
  3052. intel_dp->aux.i2c_defer_count > 0)
  3053. DRM_DEBUG_KMS("EDID read had %d NACKs, %d DEFERs\n",
  3054. intel_dp->aux.i2c_nack_count,
  3055. intel_dp->aux.i2c_defer_count);
  3056. intel_dp->compliance_test_data = INTEL_DP_RESOLUTION_FAILSAFE;
  3057. } else {
  3058. struct edid *block = intel_connector->detect_edid;
  3059. /* We have to write the checksum
  3060. * of the last block read
  3061. */
  3062. block += intel_connector->detect_edid->extensions;
  3063. if (!drm_dp_dpcd_write(&intel_dp->aux,
  3064. DP_TEST_EDID_CHECKSUM,
  3065. &block->checksum,
  3066. 1))
  3067. DRM_DEBUG_KMS("Failed to write EDID checksum\n");
  3068. test_result = DP_TEST_ACK | DP_TEST_EDID_CHECKSUM_WRITE;
  3069. intel_dp->compliance_test_data = INTEL_DP_RESOLUTION_STANDARD;
  3070. }
  3071. /* Set test active flag here so userspace doesn't interrupt things */
  3072. intel_dp->compliance_test_active = 1;
  3073. return test_result;
  3074. }
  3075. static uint8_t intel_dp_autotest_phy_pattern(struct intel_dp *intel_dp)
  3076. {
  3077. uint8_t test_result = DP_TEST_NAK;
  3078. return test_result;
  3079. }
  3080. static void intel_dp_handle_test_request(struct intel_dp *intel_dp)
  3081. {
  3082. uint8_t response = DP_TEST_NAK;
  3083. uint8_t rxdata = 0;
  3084. int status = 0;
  3085. status = drm_dp_dpcd_read(&intel_dp->aux, DP_TEST_REQUEST, &rxdata, 1);
  3086. if (status <= 0) {
  3087. DRM_DEBUG_KMS("Could not read test request from sink\n");
  3088. goto update_status;
  3089. }
  3090. switch (rxdata) {
  3091. case DP_TEST_LINK_TRAINING:
  3092. DRM_DEBUG_KMS("LINK_TRAINING test requested\n");
  3093. intel_dp->compliance_test_type = DP_TEST_LINK_TRAINING;
  3094. response = intel_dp_autotest_link_training(intel_dp);
  3095. break;
  3096. case DP_TEST_LINK_VIDEO_PATTERN:
  3097. DRM_DEBUG_KMS("TEST_PATTERN test requested\n");
  3098. intel_dp->compliance_test_type = DP_TEST_LINK_VIDEO_PATTERN;
  3099. response = intel_dp_autotest_video_pattern(intel_dp);
  3100. break;
  3101. case DP_TEST_LINK_EDID_READ:
  3102. DRM_DEBUG_KMS("EDID test requested\n");
  3103. intel_dp->compliance_test_type = DP_TEST_LINK_EDID_READ;
  3104. response = intel_dp_autotest_edid(intel_dp);
  3105. break;
  3106. case DP_TEST_LINK_PHY_TEST_PATTERN:
  3107. DRM_DEBUG_KMS("PHY_PATTERN test requested\n");
  3108. intel_dp->compliance_test_type = DP_TEST_LINK_PHY_TEST_PATTERN;
  3109. response = intel_dp_autotest_phy_pattern(intel_dp);
  3110. break;
  3111. default:
  3112. DRM_DEBUG_KMS("Invalid test request '%02x'\n", rxdata);
  3113. break;
  3114. }
  3115. update_status:
  3116. status = drm_dp_dpcd_write(&intel_dp->aux,
  3117. DP_TEST_RESPONSE,
  3118. &response, 1);
  3119. if (status <= 0)
  3120. DRM_DEBUG_KMS("Could not write test response to sink\n");
  3121. }
  3122. static int
  3123. intel_dp_check_mst_status(struct intel_dp *intel_dp)
  3124. {
  3125. bool bret;
  3126. if (intel_dp->is_mst) {
  3127. u8 esi[16] = { 0 };
  3128. int ret = 0;
  3129. int retry;
  3130. bool handled;
  3131. bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
  3132. go_again:
  3133. if (bret == true) {
  3134. /* check link status - esi[10] = 0x200c */
  3135. if (intel_dp->active_mst_links &&
  3136. !drm_dp_channel_eq_ok(&esi[10], intel_dp->lane_count)) {
  3137. DRM_DEBUG_KMS("channel EQ not ok, retraining\n");
  3138. intel_dp_start_link_train(intel_dp);
  3139. intel_dp_stop_link_train(intel_dp);
  3140. }
  3141. DRM_DEBUG_KMS("got esi %3ph\n", esi);
  3142. ret = drm_dp_mst_hpd_irq(&intel_dp->mst_mgr, esi, &handled);
  3143. if (handled) {
  3144. for (retry = 0; retry < 3; retry++) {
  3145. int wret;
  3146. wret = drm_dp_dpcd_write(&intel_dp->aux,
  3147. DP_SINK_COUNT_ESI+1,
  3148. &esi[1], 3);
  3149. if (wret == 3) {
  3150. break;
  3151. }
  3152. }
  3153. bret = intel_dp_get_sink_irq_esi(intel_dp, esi);
  3154. if (bret == true) {
  3155. DRM_DEBUG_KMS("got esi2 %3ph\n", esi);
  3156. goto go_again;
  3157. }
  3158. } else
  3159. ret = 0;
  3160. return ret;
  3161. } else {
  3162. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  3163. DRM_DEBUG_KMS("failed to get ESI - device may have failed\n");
  3164. intel_dp->is_mst = false;
  3165. drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr, intel_dp->is_mst);
  3166. /* send a hotplug event */
  3167. drm_kms_helper_hotplug_event(intel_dig_port->base.base.dev);
  3168. }
  3169. }
  3170. return -EINVAL;
  3171. }
  3172. static void
  3173. intel_dp_check_link_status(struct intel_dp *intel_dp)
  3174. {
  3175. struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
  3176. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  3177. u8 link_status[DP_LINK_STATUS_SIZE];
  3178. WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
  3179. if (!intel_dp_get_link_status(intel_dp, link_status)) {
  3180. DRM_ERROR("Failed to get link status\n");
  3181. return;
  3182. }
  3183. if (!intel_encoder->base.crtc)
  3184. return;
  3185. if (!to_intel_crtc(intel_encoder->base.crtc)->active)
  3186. return;
  3187. /* if link training is requested we should perform it always */
  3188. if ((intel_dp->compliance_test_type == DP_TEST_LINK_TRAINING) ||
  3189. (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count))) {
  3190. DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
  3191. intel_encoder->base.name);
  3192. intel_dp_start_link_train(intel_dp);
  3193. intel_dp_stop_link_train(intel_dp);
  3194. }
  3195. }
  3196. /*
  3197. * According to DP spec
  3198. * 5.1.2:
  3199. * 1. Read DPCD
  3200. * 2. Configure link according to Receiver Capabilities
  3201. * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
  3202. * 4. Check link status on receipt of hot-plug interrupt
  3203. *
  3204. * intel_dp_short_pulse - handles short pulse interrupts
  3205. * when full detection is not required.
  3206. * Returns %true if short pulse is handled and full detection
  3207. * is NOT required and %false otherwise.
  3208. */
  3209. static bool
  3210. intel_dp_short_pulse(struct intel_dp *intel_dp)
  3211. {
  3212. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  3213. u8 sink_irq_vector;
  3214. u8 old_sink_count = intel_dp->sink_count;
  3215. bool ret;
  3216. /*
  3217. * Clearing compliance test variables to allow capturing
  3218. * of values for next automated test request.
  3219. */
  3220. intel_dp->compliance_test_active = 0;
  3221. intel_dp->compliance_test_type = 0;
  3222. intel_dp->compliance_test_data = 0;
  3223. /*
  3224. * Now read the DPCD to see if it's actually running
  3225. * If the current value of sink count doesn't match with
  3226. * the value that was stored earlier or dpcd read failed
  3227. * we need to do full detection
  3228. */
  3229. ret = intel_dp_get_dpcd(intel_dp);
  3230. if ((old_sink_count != intel_dp->sink_count) || !ret) {
  3231. /* No need to proceed if we are going to do full detect */
  3232. return false;
  3233. }
  3234. /* Try to read the source of the interrupt */
  3235. if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
  3236. intel_dp_get_sink_irq(intel_dp, &sink_irq_vector)) {
  3237. /* Clear interrupt source */
  3238. drm_dp_dpcd_writeb(&intel_dp->aux,
  3239. DP_DEVICE_SERVICE_IRQ_VECTOR,
  3240. sink_irq_vector);
  3241. if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
  3242. DRM_DEBUG_DRIVER("Test request in short pulse not handled\n");
  3243. if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
  3244. DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
  3245. }
  3246. drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
  3247. intel_dp_check_link_status(intel_dp);
  3248. drm_modeset_unlock(&dev->mode_config.connection_mutex);
  3249. return true;
  3250. }
  3251. /* XXX this is probably wrong for multiple downstream ports */
  3252. static enum drm_connector_status
  3253. intel_dp_detect_dpcd(struct intel_dp *intel_dp)
  3254. {
  3255. uint8_t *dpcd = intel_dp->dpcd;
  3256. uint8_t type;
  3257. if (!intel_dp_get_dpcd(intel_dp))
  3258. return connector_status_disconnected;
  3259. if (is_edp(intel_dp))
  3260. return connector_status_connected;
  3261. /* if there's no downstream port, we're done */
  3262. if (!(dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DWN_STRM_PORT_PRESENT))
  3263. return connector_status_connected;
  3264. /* If we're HPD-aware, SINK_COUNT changes dynamically */
  3265. if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
  3266. intel_dp->downstream_ports[0] & DP_DS_PORT_HPD) {
  3267. return intel_dp->sink_count ?
  3268. connector_status_connected : connector_status_disconnected;
  3269. }
  3270. /* If no HPD, poke DDC gently */
  3271. if (drm_probe_ddc(&intel_dp->aux.ddc))
  3272. return connector_status_connected;
  3273. /* Well we tried, say unknown for unreliable port types */
  3274. if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
  3275. type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
  3276. if (type == DP_DS_PORT_TYPE_VGA ||
  3277. type == DP_DS_PORT_TYPE_NON_EDID)
  3278. return connector_status_unknown;
  3279. } else {
  3280. type = intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
  3281. DP_DWN_STRM_PORT_TYPE_MASK;
  3282. if (type == DP_DWN_STRM_PORT_TYPE_ANALOG ||
  3283. type == DP_DWN_STRM_PORT_TYPE_OTHER)
  3284. return connector_status_unknown;
  3285. }
  3286. /* Anything else is out of spec, warn and ignore */
  3287. DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
  3288. return connector_status_disconnected;
  3289. }
  3290. static enum drm_connector_status
  3291. edp_detect(struct intel_dp *intel_dp)
  3292. {
  3293. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  3294. enum drm_connector_status status;
  3295. status = intel_panel_detect(dev);
  3296. if (status == connector_status_unknown)
  3297. status = connector_status_connected;
  3298. return status;
  3299. }
  3300. static bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
  3301. struct intel_digital_port *port)
  3302. {
  3303. u32 bit;
  3304. switch (port->port) {
  3305. case PORT_A:
  3306. return true;
  3307. case PORT_B:
  3308. bit = SDE_PORTB_HOTPLUG;
  3309. break;
  3310. case PORT_C:
  3311. bit = SDE_PORTC_HOTPLUG;
  3312. break;
  3313. case PORT_D:
  3314. bit = SDE_PORTD_HOTPLUG;
  3315. break;
  3316. default:
  3317. MISSING_CASE(port->port);
  3318. return false;
  3319. }
  3320. return I915_READ(SDEISR) & bit;
  3321. }
  3322. static bool cpt_digital_port_connected(struct drm_i915_private *dev_priv,
  3323. struct intel_digital_port *port)
  3324. {
  3325. u32 bit;
  3326. switch (port->port) {
  3327. case PORT_A:
  3328. return true;
  3329. case PORT_B:
  3330. bit = SDE_PORTB_HOTPLUG_CPT;
  3331. break;
  3332. case PORT_C:
  3333. bit = SDE_PORTC_HOTPLUG_CPT;
  3334. break;
  3335. case PORT_D:
  3336. bit = SDE_PORTD_HOTPLUG_CPT;
  3337. break;
  3338. case PORT_E:
  3339. bit = SDE_PORTE_HOTPLUG_SPT;
  3340. break;
  3341. default:
  3342. MISSING_CASE(port->port);
  3343. return false;
  3344. }
  3345. return I915_READ(SDEISR) & bit;
  3346. }
  3347. static bool g4x_digital_port_connected(struct drm_i915_private *dev_priv,
  3348. struct intel_digital_port *port)
  3349. {
  3350. u32 bit;
  3351. switch (port->port) {
  3352. case PORT_B:
  3353. bit = PORTB_HOTPLUG_LIVE_STATUS_G4X;
  3354. break;
  3355. case PORT_C:
  3356. bit = PORTC_HOTPLUG_LIVE_STATUS_G4X;
  3357. break;
  3358. case PORT_D:
  3359. bit = PORTD_HOTPLUG_LIVE_STATUS_G4X;
  3360. break;
  3361. default:
  3362. MISSING_CASE(port->port);
  3363. return false;
  3364. }
  3365. return I915_READ(PORT_HOTPLUG_STAT) & bit;
  3366. }
  3367. static bool gm45_digital_port_connected(struct drm_i915_private *dev_priv,
  3368. struct intel_digital_port *port)
  3369. {
  3370. u32 bit;
  3371. switch (port->port) {
  3372. case PORT_B:
  3373. bit = PORTB_HOTPLUG_LIVE_STATUS_GM45;
  3374. break;
  3375. case PORT_C:
  3376. bit = PORTC_HOTPLUG_LIVE_STATUS_GM45;
  3377. break;
  3378. case PORT_D:
  3379. bit = PORTD_HOTPLUG_LIVE_STATUS_GM45;
  3380. break;
  3381. default:
  3382. MISSING_CASE(port->port);
  3383. return false;
  3384. }
  3385. return I915_READ(PORT_HOTPLUG_STAT) & bit;
  3386. }
  3387. static bool bxt_digital_port_connected(struct drm_i915_private *dev_priv,
  3388. struct intel_digital_port *intel_dig_port)
  3389. {
  3390. struct intel_encoder *intel_encoder = &intel_dig_port->base;
  3391. enum port port;
  3392. u32 bit;
  3393. intel_hpd_pin_to_port(intel_encoder->hpd_pin, &port);
  3394. switch (port) {
  3395. case PORT_A:
  3396. bit = BXT_DE_PORT_HP_DDIA;
  3397. break;
  3398. case PORT_B:
  3399. bit = BXT_DE_PORT_HP_DDIB;
  3400. break;
  3401. case PORT_C:
  3402. bit = BXT_DE_PORT_HP_DDIC;
  3403. break;
  3404. default:
  3405. MISSING_CASE(port);
  3406. return false;
  3407. }
  3408. return I915_READ(GEN8_DE_PORT_ISR) & bit;
  3409. }
  3410. /*
  3411. * intel_digital_port_connected - is the specified port connected?
  3412. * @dev_priv: i915 private structure
  3413. * @port: the port to test
  3414. *
  3415. * Return %true if @port is connected, %false otherwise.
  3416. */
  3417. bool intel_digital_port_connected(struct drm_i915_private *dev_priv,
  3418. struct intel_digital_port *port)
  3419. {
  3420. if (HAS_PCH_IBX(dev_priv))
  3421. return ibx_digital_port_connected(dev_priv, port);
  3422. else if (HAS_PCH_SPLIT(dev_priv))
  3423. return cpt_digital_port_connected(dev_priv, port);
  3424. else if (IS_BROXTON(dev_priv))
  3425. return bxt_digital_port_connected(dev_priv, port);
  3426. else if (IS_GM45(dev_priv))
  3427. return gm45_digital_port_connected(dev_priv, port);
  3428. else
  3429. return g4x_digital_port_connected(dev_priv, port);
  3430. }
  3431. static struct edid *
  3432. intel_dp_get_edid(struct intel_dp *intel_dp)
  3433. {
  3434. struct intel_connector *intel_connector = intel_dp->attached_connector;
  3435. /* use cached edid if we have one */
  3436. if (intel_connector->edid) {
  3437. /* invalid edid */
  3438. if (IS_ERR(intel_connector->edid))
  3439. return NULL;
  3440. return drm_edid_duplicate(intel_connector->edid);
  3441. } else
  3442. return drm_get_edid(&intel_connector->base,
  3443. &intel_dp->aux.ddc);
  3444. }
  3445. static void
  3446. intel_dp_set_edid(struct intel_dp *intel_dp)
  3447. {
  3448. struct intel_connector *intel_connector = intel_dp->attached_connector;
  3449. struct edid *edid;
  3450. intel_dp_unset_edid(intel_dp);
  3451. edid = intel_dp_get_edid(intel_dp);
  3452. intel_connector->detect_edid = edid;
  3453. if (intel_dp->force_audio != HDMI_AUDIO_AUTO)
  3454. intel_dp->has_audio = intel_dp->force_audio == HDMI_AUDIO_ON;
  3455. else
  3456. intel_dp->has_audio = drm_detect_monitor_audio(edid);
  3457. }
  3458. static void
  3459. intel_dp_unset_edid(struct intel_dp *intel_dp)
  3460. {
  3461. struct intel_connector *intel_connector = intel_dp->attached_connector;
  3462. kfree(intel_connector->detect_edid);
  3463. intel_connector->detect_edid = NULL;
  3464. intel_dp->has_audio = false;
  3465. }
  3466. static void
  3467. intel_dp_long_pulse(struct intel_connector *intel_connector)
  3468. {
  3469. struct drm_connector *connector = &intel_connector->base;
  3470. struct intel_dp *intel_dp = intel_attached_dp(connector);
  3471. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  3472. struct intel_encoder *intel_encoder = &intel_dig_port->base;
  3473. struct drm_device *dev = connector->dev;
  3474. enum drm_connector_status status;
  3475. enum intel_display_power_domain power_domain;
  3476. bool ret;
  3477. u8 sink_irq_vector;
  3478. power_domain = intel_display_port_aux_power_domain(intel_encoder);
  3479. intel_display_power_get(to_i915(dev), power_domain);
  3480. /* Can't disconnect eDP, but you can close the lid... */
  3481. if (is_edp(intel_dp))
  3482. status = edp_detect(intel_dp);
  3483. else if (intel_digital_port_connected(to_i915(dev),
  3484. dp_to_dig_port(intel_dp)))
  3485. status = intel_dp_detect_dpcd(intel_dp);
  3486. else
  3487. status = connector_status_disconnected;
  3488. if (status != connector_status_connected) {
  3489. intel_dp->compliance_test_active = 0;
  3490. intel_dp->compliance_test_type = 0;
  3491. intel_dp->compliance_test_data = 0;
  3492. if (intel_dp->is_mst) {
  3493. DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
  3494. intel_dp->is_mst,
  3495. intel_dp->mst_mgr.mst_state);
  3496. intel_dp->is_mst = false;
  3497. drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
  3498. intel_dp->is_mst);
  3499. }
  3500. goto out;
  3501. }
  3502. if (intel_encoder->type != INTEL_OUTPUT_EDP)
  3503. intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
  3504. intel_dp_probe_oui(intel_dp);
  3505. ret = intel_dp_probe_mst(intel_dp);
  3506. if (ret) {
  3507. /*
  3508. * If we are in MST mode then this connector
  3509. * won't appear connected or have anything
  3510. * with EDID on it
  3511. */
  3512. status = connector_status_disconnected;
  3513. goto out;
  3514. } else if (connector->status == connector_status_connected) {
  3515. /*
  3516. * If display was connected already and is still connected
  3517. * check links status, there has been known issues of
  3518. * link loss triggerring long pulse!!!!
  3519. */
  3520. drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
  3521. intel_dp_check_link_status(intel_dp);
  3522. drm_modeset_unlock(&dev->mode_config.connection_mutex);
  3523. goto out;
  3524. }
  3525. /*
  3526. * Clearing NACK and defer counts to get their exact values
  3527. * while reading EDID which are required by Compliance tests
  3528. * 4.2.2.4 and 4.2.2.5
  3529. */
  3530. intel_dp->aux.i2c_nack_count = 0;
  3531. intel_dp->aux.i2c_defer_count = 0;
  3532. intel_dp_set_edid(intel_dp);
  3533. status = connector_status_connected;
  3534. intel_dp->detect_done = true;
  3535. /* Try to read the source of the interrupt */
  3536. if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
  3537. intel_dp_get_sink_irq(intel_dp, &sink_irq_vector)) {
  3538. /* Clear interrupt source */
  3539. drm_dp_dpcd_writeb(&intel_dp->aux,
  3540. DP_DEVICE_SERVICE_IRQ_VECTOR,
  3541. sink_irq_vector);
  3542. if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
  3543. intel_dp_handle_test_request(intel_dp);
  3544. if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
  3545. DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
  3546. }
  3547. out:
  3548. if ((status != connector_status_connected) &&
  3549. (intel_dp->is_mst == false))
  3550. intel_dp_unset_edid(intel_dp);
  3551. intel_display_power_put(to_i915(dev), power_domain);
  3552. return;
  3553. }
  3554. static enum drm_connector_status
  3555. intel_dp_detect(struct drm_connector *connector, bool force)
  3556. {
  3557. struct intel_dp *intel_dp = intel_attached_dp(connector);
  3558. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  3559. struct intel_encoder *intel_encoder = &intel_dig_port->base;
  3560. struct intel_connector *intel_connector = to_intel_connector(connector);
  3561. DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
  3562. connector->base.id, connector->name);
  3563. if (intel_dp->is_mst) {
  3564. /* MST devices are disconnected from a monitor POV */
  3565. intel_dp_unset_edid(intel_dp);
  3566. if (intel_encoder->type != INTEL_OUTPUT_EDP)
  3567. intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
  3568. return connector_status_disconnected;
  3569. }
  3570. /* If full detect is not performed yet, do a full detect */
  3571. if (!intel_dp->detect_done)
  3572. intel_dp_long_pulse(intel_dp->attached_connector);
  3573. intel_dp->detect_done = false;
  3574. if (intel_connector->detect_edid)
  3575. return connector_status_connected;
  3576. else
  3577. return connector_status_disconnected;
  3578. }
  3579. static void
  3580. intel_dp_force(struct drm_connector *connector)
  3581. {
  3582. struct intel_dp *intel_dp = intel_attached_dp(connector);
  3583. struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
  3584. struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
  3585. enum intel_display_power_domain power_domain;
  3586. DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
  3587. connector->base.id, connector->name);
  3588. intel_dp_unset_edid(intel_dp);
  3589. if (connector->status != connector_status_connected)
  3590. return;
  3591. power_domain = intel_display_port_aux_power_domain(intel_encoder);
  3592. intel_display_power_get(dev_priv, power_domain);
  3593. intel_dp_set_edid(intel_dp);
  3594. intel_display_power_put(dev_priv, power_domain);
  3595. if (intel_encoder->type != INTEL_OUTPUT_EDP)
  3596. intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
  3597. }
  3598. static int intel_dp_get_modes(struct drm_connector *connector)
  3599. {
  3600. struct intel_connector *intel_connector = to_intel_connector(connector);
  3601. struct edid *edid;
  3602. edid = intel_connector->detect_edid;
  3603. if (edid) {
  3604. int ret = intel_connector_update_modes(connector, edid);
  3605. if (ret)
  3606. return ret;
  3607. }
  3608. /* if eDP has no EDID, fall back to fixed mode */
  3609. if (is_edp(intel_attached_dp(connector)) &&
  3610. intel_connector->panel.fixed_mode) {
  3611. struct drm_display_mode *mode;
  3612. mode = drm_mode_duplicate(connector->dev,
  3613. intel_connector->panel.fixed_mode);
  3614. if (mode) {
  3615. drm_mode_probed_add(connector, mode);
  3616. return 1;
  3617. }
  3618. }
  3619. return 0;
  3620. }
  3621. static bool
  3622. intel_dp_detect_audio(struct drm_connector *connector)
  3623. {
  3624. bool has_audio = false;
  3625. struct edid *edid;
  3626. edid = to_intel_connector(connector)->detect_edid;
  3627. if (edid)
  3628. has_audio = drm_detect_monitor_audio(edid);
  3629. return has_audio;
  3630. }
  3631. static int
  3632. intel_dp_set_property(struct drm_connector *connector,
  3633. struct drm_property *property,
  3634. uint64_t val)
  3635. {
  3636. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  3637. struct intel_connector *intel_connector = to_intel_connector(connector);
  3638. struct intel_encoder *intel_encoder = intel_attached_encoder(connector);
  3639. struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
  3640. int ret;
  3641. ret = drm_object_property_set_value(&connector->base, property, val);
  3642. if (ret)
  3643. return ret;
  3644. if (property == dev_priv->force_audio_property) {
  3645. int i = val;
  3646. bool has_audio;
  3647. if (i == intel_dp->force_audio)
  3648. return 0;
  3649. intel_dp->force_audio = i;
  3650. if (i == HDMI_AUDIO_AUTO)
  3651. has_audio = intel_dp_detect_audio(connector);
  3652. else
  3653. has_audio = (i == HDMI_AUDIO_ON);
  3654. if (has_audio == intel_dp->has_audio)
  3655. return 0;
  3656. intel_dp->has_audio = has_audio;
  3657. goto done;
  3658. }
  3659. if (property == dev_priv->broadcast_rgb_property) {
  3660. bool old_auto = intel_dp->color_range_auto;
  3661. bool old_range = intel_dp->limited_color_range;
  3662. switch (val) {
  3663. case INTEL_BROADCAST_RGB_AUTO:
  3664. intel_dp->color_range_auto = true;
  3665. break;
  3666. case INTEL_BROADCAST_RGB_FULL:
  3667. intel_dp->color_range_auto = false;
  3668. intel_dp->limited_color_range = false;
  3669. break;
  3670. case INTEL_BROADCAST_RGB_LIMITED:
  3671. intel_dp->color_range_auto = false;
  3672. intel_dp->limited_color_range = true;
  3673. break;
  3674. default:
  3675. return -EINVAL;
  3676. }
  3677. if (old_auto == intel_dp->color_range_auto &&
  3678. old_range == intel_dp->limited_color_range)
  3679. return 0;
  3680. goto done;
  3681. }
  3682. if (is_edp(intel_dp) &&
  3683. property == connector->dev->mode_config.scaling_mode_property) {
  3684. if (val == DRM_MODE_SCALE_NONE) {
  3685. DRM_DEBUG_KMS("no scaling not supported\n");
  3686. return -EINVAL;
  3687. }
  3688. if (HAS_GMCH_DISPLAY(dev_priv) &&
  3689. val == DRM_MODE_SCALE_CENTER) {
  3690. DRM_DEBUG_KMS("centering not supported\n");
  3691. return -EINVAL;
  3692. }
  3693. if (intel_connector->panel.fitting_mode == val) {
  3694. /* the eDP scaling property is not changed */
  3695. return 0;
  3696. }
  3697. intel_connector->panel.fitting_mode = val;
  3698. goto done;
  3699. }
  3700. return -EINVAL;
  3701. done:
  3702. if (intel_encoder->base.crtc)
  3703. intel_crtc_restore_mode(intel_encoder->base.crtc);
  3704. return 0;
  3705. }
  3706. static void
  3707. intel_dp_connector_destroy(struct drm_connector *connector)
  3708. {
  3709. struct intel_connector *intel_connector = to_intel_connector(connector);
  3710. kfree(intel_connector->detect_edid);
  3711. if (!IS_ERR_OR_NULL(intel_connector->edid))
  3712. kfree(intel_connector->edid);
  3713. /* Can't call is_edp() since the encoder may have been destroyed
  3714. * already. */
  3715. if (connector->connector_type == DRM_MODE_CONNECTOR_eDP)
  3716. intel_panel_fini(&intel_connector->panel);
  3717. drm_connector_cleanup(connector);
  3718. kfree(connector);
  3719. }
  3720. void intel_dp_encoder_destroy(struct drm_encoder *encoder)
  3721. {
  3722. struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
  3723. struct intel_dp *intel_dp = &intel_dig_port->dp;
  3724. intel_dp_mst_encoder_cleanup(intel_dig_port);
  3725. if (is_edp(intel_dp)) {
  3726. cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
  3727. /*
  3728. * vdd might still be enabled do to the delayed vdd off.
  3729. * Make sure vdd is actually turned off here.
  3730. */
  3731. pps_lock(intel_dp);
  3732. edp_panel_vdd_off_sync(intel_dp);
  3733. pps_unlock(intel_dp);
  3734. if (intel_dp->edp_notifier.notifier_call) {
  3735. unregister_reboot_notifier(&intel_dp->edp_notifier);
  3736. intel_dp->edp_notifier.notifier_call = NULL;
  3737. }
  3738. }
  3739. drm_encoder_cleanup(encoder);
  3740. kfree(intel_dig_port);
  3741. }
  3742. void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder)
  3743. {
  3744. struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
  3745. if (!is_edp(intel_dp))
  3746. return;
  3747. /*
  3748. * vdd might still be enabled do to the delayed vdd off.
  3749. * Make sure vdd is actually turned off here.
  3750. */
  3751. cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
  3752. pps_lock(intel_dp);
  3753. edp_panel_vdd_off_sync(intel_dp);
  3754. pps_unlock(intel_dp);
  3755. }
  3756. static void intel_edp_panel_vdd_sanitize(struct intel_dp *intel_dp)
  3757. {
  3758. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  3759. struct drm_device *dev = intel_dig_port->base.base.dev;
  3760. struct drm_i915_private *dev_priv = dev->dev_private;
  3761. enum intel_display_power_domain power_domain;
  3762. lockdep_assert_held(&dev_priv->pps_mutex);
  3763. if (!edp_have_panel_vdd(intel_dp))
  3764. return;
  3765. /*
  3766. * The VDD bit needs a power domain reference, so if the bit is
  3767. * already enabled when we boot or resume, grab this reference and
  3768. * schedule a vdd off, so we don't hold on to the reference
  3769. * indefinitely.
  3770. */
  3771. DRM_DEBUG_KMS("VDD left on by BIOS, adjusting state tracking\n");
  3772. power_domain = intel_display_port_aux_power_domain(&intel_dig_port->base);
  3773. intel_display_power_get(dev_priv, power_domain);
  3774. edp_panel_vdd_schedule_off(intel_dp);
  3775. }
  3776. void intel_dp_encoder_reset(struct drm_encoder *encoder)
  3777. {
  3778. struct intel_dp *intel_dp;
  3779. if (to_intel_encoder(encoder)->type != INTEL_OUTPUT_EDP)
  3780. return;
  3781. intel_dp = enc_to_intel_dp(encoder);
  3782. pps_lock(intel_dp);
  3783. /*
  3784. * Read out the current power sequencer assignment,
  3785. * in case the BIOS did something with it.
  3786. */
  3787. if (IS_VALLEYVIEW(encoder->dev) || IS_CHERRYVIEW(encoder->dev))
  3788. vlv_initial_power_sequencer_setup(intel_dp);
  3789. intel_edp_panel_vdd_sanitize(intel_dp);
  3790. pps_unlock(intel_dp);
  3791. }
  3792. static const struct drm_connector_funcs intel_dp_connector_funcs = {
  3793. .dpms = drm_atomic_helper_connector_dpms,
  3794. .detect = intel_dp_detect,
  3795. .force = intel_dp_force,
  3796. .fill_modes = drm_helper_probe_single_connector_modes,
  3797. .set_property = intel_dp_set_property,
  3798. .atomic_get_property = intel_connector_atomic_get_property,
  3799. .destroy = intel_dp_connector_destroy,
  3800. .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
  3801. .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
  3802. };
  3803. static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
  3804. .get_modes = intel_dp_get_modes,
  3805. .mode_valid = intel_dp_mode_valid,
  3806. .best_encoder = intel_best_encoder,
  3807. };
  3808. static const struct drm_encoder_funcs intel_dp_enc_funcs = {
  3809. .reset = intel_dp_encoder_reset,
  3810. .destroy = intel_dp_encoder_destroy,
  3811. };
  3812. enum irqreturn
  3813. intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd)
  3814. {
  3815. struct intel_dp *intel_dp = &intel_dig_port->dp;
  3816. struct intel_encoder *intel_encoder = &intel_dig_port->base;
  3817. struct drm_device *dev = intel_dig_port->base.base.dev;
  3818. struct drm_i915_private *dev_priv = dev->dev_private;
  3819. enum intel_display_power_domain power_domain;
  3820. enum irqreturn ret = IRQ_NONE;
  3821. if (intel_dig_port->base.type != INTEL_OUTPUT_EDP &&
  3822. intel_dig_port->base.type != INTEL_OUTPUT_HDMI)
  3823. intel_dig_port->base.type = INTEL_OUTPUT_DISPLAYPORT;
  3824. if (long_hpd && intel_dig_port->base.type == INTEL_OUTPUT_EDP) {
  3825. /*
  3826. * vdd off can generate a long pulse on eDP which
  3827. * would require vdd on to handle it, and thus we
  3828. * would end up in an endless cycle of
  3829. * "vdd off -> long hpd -> vdd on -> detect -> vdd off -> ..."
  3830. */
  3831. DRM_DEBUG_KMS("ignoring long hpd on eDP port %c\n",
  3832. port_name(intel_dig_port->port));
  3833. return IRQ_HANDLED;
  3834. }
  3835. DRM_DEBUG_KMS("got hpd irq on port %c - %s\n",
  3836. port_name(intel_dig_port->port),
  3837. long_hpd ? "long" : "short");
  3838. power_domain = intel_display_port_aux_power_domain(intel_encoder);
  3839. intel_display_power_get(dev_priv, power_domain);
  3840. if (long_hpd) {
  3841. /* indicate that we need to restart link training */
  3842. intel_dp->train_set_valid = false;
  3843. intel_dp_long_pulse(intel_dp->attached_connector);
  3844. if (intel_dp->is_mst)
  3845. ret = IRQ_HANDLED;
  3846. goto put_power;
  3847. } else {
  3848. if (intel_dp->is_mst) {
  3849. if (intel_dp_check_mst_status(intel_dp) == -EINVAL) {
  3850. /*
  3851. * If we were in MST mode, and device is not
  3852. * there, get out of MST mode
  3853. */
  3854. DRM_DEBUG_KMS("MST device may have disappeared %d vs %d\n",
  3855. intel_dp->is_mst, intel_dp->mst_mgr.mst_state);
  3856. intel_dp->is_mst = false;
  3857. drm_dp_mst_topology_mgr_set_mst(&intel_dp->mst_mgr,
  3858. intel_dp->is_mst);
  3859. goto put_power;
  3860. }
  3861. }
  3862. if (!intel_dp->is_mst) {
  3863. if (!intel_dp_short_pulse(intel_dp)) {
  3864. intel_dp_long_pulse(intel_dp->attached_connector);
  3865. goto put_power;
  3866. }
  3867. }
  3868. }
  3869. ret = IRQ_HANDLED;
  3870. put_power:
  3871. intel_display_power_put(dev_priv, power_domain);
  3872. return ret;
  3873. }
  3874. /* check the VBT to see whether the eDP is on another port */
  3875. bool intel_dp_is_edp(struct drm_device *dev, enum port port)
  3876. {
  3877. struct drm_i915_private *dev_priv = dev->dev_private;
  3878. /*
  3879. * eDP not supported on g4x. so bail out early just
  3880. * for a bit extra safety in case the VBT is bonkers.
  3881. */
  3882. if (INTEL_INFO(dev)->gen < 5)
  3883. return false;
  3884. if (port == PORT_A)
  3885. return true;
  3886. return intel_bios_is_port_edp(dev_priv, port);
  3887. }
  3888. void
  3889. intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
  3890. {
  3891. struct intel_connector *intel_connector = to_intel_connector(connector);
  3892. intel_attach_force_audio_property(connector);
  3893. intel_attach_broadcast_rgb_property(connector);
  3894. intel_dp->color_range_auto = true;
  3895. if (is_edp(intel_dp)) {
  3896. drm_mode_create_scaling_mode_property(connector->dev);
  3897. drm_object_attach_property(
  3898. &connector->base,
  3899. connector->dev->mode_config.scaling_mode_property,
  3900. DRM_MODE_SCALE_ASPECT);
  3901. intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
  3902. }
  3903. }
  3904. static void intel_dp_init_panel_power_timestamps(struct intel_dp *intel_dp)
  3905. {
  3906. intel_dp->panel_power_off_time = ktime_get_boottime();
  3907. intel_dp->last_power_on = jiffies;
  3908. intel_dp->last_backlight_off = jiffies;
  3909. }
  3910. static void
  3911. intel_dp_init_panel_power_sequencer(struct drm_device *dev,
  3912. struct intel_dp *intel_dp)
  3913. {
  3914. struct drm_i915_private *dev_priv = dev->dev_private;
  3915. struct edp_power_seq cur, vbt, spec,
  3916. *final = &intel_dp->pps_delays;
  3917. u32 pp_on, pp_off, pp_div = 0, pp_ctl = 0;
  3918. i915_reg_t pp_ctrl_reg, pp_on_reg, pp_off_reg, pp_div_reg;
  3919. lockdep_assert_held(&dev_priv->pps_mutex);
  3920. /* already initialized? */
  3921. if (final->t11_t12 != 0)
  3922. return;
  3923. if (IS_BROXTON(dev)) {
  3924. /*
  3925. * TODO: BXT has 2 sets of PPS registers.
  3926. * Correct Register for Broxton need to be identified
  3927. * using VBT. hardcoding for now
  3928. */
  3929. pp_ctrl_reg = BXT_PP_CONTROL(0);
  3930. pp_on_reg = BXT_PP_ON_DELAYS(0);
  3931. pp_off_reg = BXT_PP_OFF_DELAYS(0);
  3932. } else if (HAS_PCH_SPLIT(dev)) {
  3933. pp_ctrl_reg = PCH_PP_CONTROL;
  3934. pp_on_reg = PCH_PP_ON_DELAYS;
  3935. pp_off_reg = PCH_PP_OFF_DELAYS;
  3936. pp_div_reg = PCH_PP_DIVISOR;
  3937. } else {
  3938. enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
  3939. pp_ctrl_reg = VLV_PIPE_PP_CONTROL(pipe);
  3940. pp_on_reg = VLV_PIPE_PP_ON_DELAYS(pipe);
  3941. pp_off_reg = VLV_PIPE_PP_OFF_DELAYS(pipe);
  3942. pp_div_reg = VLV_PIPE_PP_DIVISOR(pipe);
  3943. }
  3944. /* Workaround: Need to write PP_CONTROL with the unlock key as
  3945. * the very first thing. */
  3946. pp_ctl = ironlake_get_pp_control(intel_dp);
  3947. pp_on = I915_READ(pp_on_reg);
  3948. pp_off = I915_READ(pp_off_reg);
  3949. if (!IS_BROXTON(dev)) {
  3950. I915_WRITE(pp_ctrl_reg, pp_ctl);
  3951. pp_div = I915_READ(pp_div_reg);
  3952. }
  3953. /* Pull timing values out of registers */
  3954. cur.t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
  3955. PANEL_POWER_UP_DELAY_SHIFT;
  3956. cur.t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
  3957. PANEL_LIGHT_ON_DELAY_SHIFT;
  3958. cur.t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
  3959. PANEL_LIGHT_OFF_DELAY_SHIFT;
  3960. cur.t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
  3961. PANEL_POWER_DOWN_DELAY_SHIFT;
  3962. if (IS_BROXTON(dev)) {
  3963. u16 tmp = (pp_ctl & BXT_POWER_CYCLE_DELAY_MASK) >>
  3964. BXT_POWER_CYCLE_DELAY_SHIFT;
  3965. if (tmp > 0)
  3966. cur.t11_t12 = (tmp - 1) * 1000;
  3967. else
  3968. cur.t11_t12 = 0;
  3969. } else {
  3970. cur.t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
  3971. PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
  3972. }
  3973. DRM_DEBUG_KMS("cur t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
  3974. cur.t1_t3, cur.t8, cur.t9, cur.t10, cur.t11_t12);
  3975. vbt = dev_priv->vbt.edp.pps;
  3976. /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
  3977. * our hw here, which are all in 100usec. */
  3978. spec.t1_t3 = 210 * 10;
  3979. spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
  3980. spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
  3981. spec.t10 = 500 * 10;
  3982. /* This one is special and actually in units of 100ms, but zero
  3983. * based in the hw (so we need to add 100 ms). But the sw vbt
  3984. * table multiplies it with 1000 to make it in units of 100usec,
  3985. * too. */
  3986. spec.t11_t12 = (510 + 100) * 10;
  3987. DRM_DEBUG_KMS("vbt t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
  3988. vbt.t1_t3, vbt.t8, vbt.t9, vbt.t10, vbt.t11_t12);
  3989. /* Use the max of the register settings and vbt. If both are
  3990. * unset, fall back to the spec limits. */
  3991. #define assign_final(field) final->field = (max(cur.field, vbt.field) == 0 ? \
  3992. spec.field : \
  3993. max(cur.field, vbt.field))
  3994. assign_final(t1_t3);
  3995. assign_final(t8);
  3996. assign_final(t9);
  3997. assign_final(t10);
  3998. assign_final(t11_t12);
  3999. #undef assign_final
  4000. #define get_delay(field) (DIV_ROUND_UP(final->field, 10))
  4001. intel_dp->panel_power_up_delay = get_delay(t1_t3);
  4002. intel_dp->backlight_on_delay = get_delay(t8);
  4003. intel_dp->backlight_off_delay = get_delay(t9);
  4004. intel_dp->panel_power_down_delay = get_delay(t10);
  4005. intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
  4006. #undef get_delay
  4007. DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
  4008. intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
  4009. intel_dp->panel_power_cycle_delay);
  4010. DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
  4011. intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
  4012. }
  4013. static void
  4014. intel_dp_init_panel_power_sequencer_registers(struct drm_device *dev,
  4015. struct intel_dp *intel_dp)
  4016. {
  4017. struct drm_i915_private *dev_priv = dev->dev_private;
  4018. u32 pp_on, pp_off, pp_div, port_sel = 0;
  4019. int div = dev_priv->rawclk_freq / 1000;
  4020. i915_reg_t pp_on_reg, pp_off_reg, pp_div_reg, pp_ctrl_reg;
  4021. enum port port = dp_to_dig_port(intel_dp)->port;
  4022. const struct edp_power_seq *seq = &intel_dp->pps_delays;
  4023. lockdep_assert_held(&dev_priv->pps_mutex);
  4024. if (IS_BROXTON(dev)) {
  4025. /*
  4026. * TODO: BXT has 2 sets of PPS registers.
  4027. * Correct Register for Broxton need to be identified
  4028. * using VBT. hardcoding for now
  4029. */
  4030. pp_ctrl_reg = BXT_PP_CONTROL(0);
  4031. pp_on_reg = BXT_PP_ON_DELAYS(0);
  4032. pp_off_reg = BXT_PP_OFF_DELAYS(0);
  4033. } else if (HAS_PCH_SPLIT(dev)) {
  4034. pp_on_reg = PCH_PP_ON_DELAYS;
  4035. pp_off_reg = PCH_PP_OFF_DELAYS;
  4036. pp_div_reg = PCH_PP_DIVISOR;
  4037. } else {
  4038. enum pipe pipe = vlv_power_sequencer_pipe(intel_dp);
  4039. pp_on_reg = VLV_PIPE_PP_ON_DELAYS(pipe);
  4040. pp_off_reg = VLV_PIPE_PP_OFF_DELAYS(pipe);
  4041. pp_div_reg = VLV_PIPE_PP_DIVISOR(pipe);
  4042. }
  4043. /*
  4044. * And finally store the new values in the power sequencer. The
  4045. * backlight delays are set to 1 because we do manual waits on them. For
  4046. * T8, even BSpec recommends doing it. For T9, if we don't do this,
  4047. * we'll end up waiting for the backlight off delay twice: once when we
  4048. * do the manual sleep, and once when we disable the panel and wait for
  4049. * the PP_STATUS bit to become zero.
  4050. */
  4051. pp_on = (seq->t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
  4052. (1 << PANEL_LIGHT_ON_DELAY_SHIFT);
  4053. pp_off = (1 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
  4054. (seq->t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
  4055. /* Compute the divisor for the pp clock, simply match the Bspec
  4056. * formula. */
  4057. if (IS_BROXTON(dev)) {
  4058. pp_div = I915_READ(pp_ctrl_reg);
  4059. pp_div &= ~BXT_POWER_CYCLE_DELAY_MASK;
  4060. pp_div |= (DIV_ROUND_UP((seq->t11_t12 + 1), 1000)
  4061. << BXT_POWER_CYCLE_DELAY_SHIFT);
  4062. } else {
  4063. pp_div = ((100 * div)/2 - 1) << PP_REFERENCE_DIVIDER_SHIFT;
  4064. pp_div |= (DIV_ROUND_UP(seq->t11_t12, 1000)
  4065. << PANEL_POWER_CYCLE_DELAY_SHIFT);
  4066. }
  4067. /* Haswell doesn't have any port selection bits for the panel
  4068. * power sequencer any more. */
  4069. if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
  4070. port_sel = PANEL_PORT_SELECT_VLV(port);
  4071. } else if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) {
  4072. if (port == PORT_A)
  4073. port_sel = PANEL_PORT_SELECT_DPA;
  4074. else
  4075. port_sel = PANEL_PORT_SELECT_DPD;
  4076. }
  4077. pp_on |= port_sel;
  4078. I915_WRITE(pp_on_reg, pp_on);
  4079. I915_WRITE(pp_off_reg, pp_off);
  4080. if (IS_BROXTON(dev))
  4081. I915_WRITE(pp_ctrl_reg, pp_div);
  4082. else
  4083. I915_WRITE(pp_div_reg, pp_div);
  4084. DRM_DEBUG_KMS("panel power sequencer register settings: PP_ON %#x, PP_OFF %#x, PP_DIV %#x\n",
  4085. I915_READ(pp_on_reg),
  4086. I915_READ(pp_off_reg),
  4087. IS_BROXTON(dev) ?
  4088. (I915_READ(pp_ctrl_reg) & BXT_POWER_CYCLE_DELAY_MASK) :
  4089. I915_READ(pp_div_reg));
  4090. }
  4091. /**
  4092. * intel_dp_set_drrs_state - program registers for RR switch to take effect
  4093. * @dev: DRM device
  4094. * @refresh_rate: RR to be programmed
  4095. *
  4096. * This function gets called when refresh rate (RR) has to be changed from
  4097. * one frequency to another. Switches can be between high and low RR
  4098. * supported by the panel or to any other RR based on media playback (in
  4099. * this case, RR value needs to be passed from user space).
  4100. *
  4101. * The caller of this function needs to take a lock on dev_priv->drrs.
  4102. */
  4103. static void intel_dp_set_drrs_state(struct drm_device *dev, int refresh_rate)
  4104. {
  4105. struct drm_i915_private *dev_priv = dev->dev_private;
  4106. struct intel_encoder *encoder;
  4107. struct intel_digital_port *dig_port = NULL;
  4108. struct intel_dp *intel_dp = dev_priv->drrs.dp;
  4109. struct intel_crtc_state *config = NULL;
  4110. struct intel_crtc *intel_crtc = NULL;
  4111. enum drrs_refresh_rate_type index = DRRS_HIGH_RR;
  4112. if (refresh_rate <= 0) {
  4113. DRM_DEBUG_KMS("Refresh rate should be positive non-zero.\n");
  4114. return;
  4115. }
  4116. if (intel_dp == NULL) {
  4117. DRM_DEBUG_KMS("DRRS not supported.\n");
  4118. return;
  4119. }
  4120. /*
  4121. * FIXME: This needs proper synchronization with psr state for some
  4122. * platforms that cannot have PSR and DRRS enabled at the same time.
  4123. */
  4124. dig_port = dp_to_dig_port(intel_dp);
  4125. encoder = &dig_port->base;
  4126. intel_crtc = to_intel_crtc(encoder->base.crtc);
  4127. if (!intel_crtc) {
  4128. DRM_DEBUG_KMS("DRRS: intel_crtc not initialized\n");
  4129. return;
  4130. }
  4131. config = intel_crtc->config;
  4132. if (dev_priv->drrs.type < SEAMLESS_DRRS_SUPPORT) {
  4133. DRM_DEBUG_KMS("Only Seamless DRRS supported.\n");
  4134. return;
  4135. }
  4136. if (intel_dp->attached_connector->panel.downclock_mode->vrefresh ==
  4137. refresh_rate)
  4138. index = DRRS_LOW_RR;
  4139. if (index == dev_priv->drrs.refresh_rate_type) {
  4140. DRM_DEBUG_KMS(
  4141. "DRRS requested for previously set RR...ignoring\n");
  4142. return;
  4143. }
  4144. if (!intel_crtc->active) {
  4145. DRM_DEBUG_KMS("eDP encoder disabled. CRTC not Active\n");
  4146. return;
  4147. }
  4148. if (INTEL_INFO(dev)->gen >= 8 && !IS_CHERRYVIEW(dev)) {
  4149. switch (index) {
  4150. case DRRS_HIGH_RR:
  4151. intel_dp_set_m_n(intel_crtc, M1_N1);
  4152. break;
  4153. case DRRS_LOW_RR:
  4154. intel_dp_set_m_n(intel_crtc, M2_N2);
  4155. break;
  4156. case DRRS_MAX_RR:
  4157. default:
  4158. DRM_ERROR("Unsupported refreshrate type\n");
  4159. }
  4160. } else if (INTEL_INFO(dev)->gen > 6) {
  4161. i915_reg_t reg = PIPECONF(intel_crtc->config->cpu_transcoder);
  4162. u32 val;
  4163. val = I915_READ(reg);
  4164. if (index > DRRS_HIGH_RR) {
  4165. if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
  4166. val |= PIPECONF_EDP_RR_MODE_SWITCH_VLV;
  4167. else
  4168. val |= PIPECONF_EDP_RR_MODE_SWITCH;
  4169. } else {
  4170. if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
  4171. val &= ~PIPECONF_EDP_RR_MODE_SWITCH_VLV;
  4172. else
  4173. val &= ~PIPECONF_EDP_RR_MODE_SWITCH;
  4174. }
  4175. I915_WRITE(reg, val);
  4176. }
  4177. dev_priv->drrs.refresh_rate_type = index;
  4178. DRM_DEBUG_KMS("eDP Refresh Rate set to : %dHz\n", refresh_rate);
  4179. }
  4180. /**
  4181. * intel_edp_drrs_enable - init drrs struct if supported
  4182. * @intel_dp: DP struct
  4183. *
  4184. * Initializes frontbuffer_bits and drrs.dp
  4185. */
  4186. void intel_edp_drrs_enable(struct intel_dp *intel_dp)
  4187. {
  4188. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  4189. struct drm_i915_private *dev_priv = dev->dev_private;
  4190. struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
  4191. struct drm_crtc *crtc = dig_port->base.base.crtc;
  4192. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4193. if (!intel_crtc->config->has_drrs) {
  4194. DRM_DEBUG_KMS("Panel doesn't support DRRS\n");
  4195. return;
  4196. }
  4197. mutex_lock(&dev_priv->drrs.mutex);
  4198. if (WARN_ON(dev_priv->drrs.dp)) {
  4199. DRM_ERROR("DRRS already enabled\n");
  4200. goto unlock;
  4201. }
  4202. dev_priv->drrs.busy_frontbuffer_bits = 0;
  4203. dev_priv->drrs.dp = intel_dp;
  4204. unlock:
  4205. mutex_unlock(&dev_priv->drrs.mutex);
  4206. }
  4207. /**
  4208. * intel_edp_drrs_disable - Disable DRRS
  4209. * @intel_dp: DP struct
  4210. *
  4211. */
  4212. void intel_edp_drrs_disable(struct intel_dp *intel_dp)
  4213. {
  4214. struct drm_device *dev = intel_dp_to_dev(intel_dp);
  4215. struct drm_i915_private *dev_priv = dev->dev_private;
  4216. struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
  4217. struct drm_crtc *crtc = dig_port->base.base.crtc;
  4218. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4219. if (!intel_crtc->config->has_drrs)
  4220. return;
  4221. mutex_lock(&dev_priv->drrs.mutex);
  4222. if (!dev_priv->drrs.dp) {
  4223. mutex_unlock(&dev_priv->drrs.mutex);
  4224. return;
  4225. }
  4226. if (dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
  4227. intel_dp_set_drrs_state(dev_priv->dev,
  4228. intel_dp->attached_connector->panel.
  4229. fixed_mode->vrefresh);
  4230. dev_priv->drrs.dp = NULL;
  4231. mutex_unlock(&dev_priv->drrs.mutex);
  4232. cancel_delayed_work_sync(&dev_priv->drrs.work);
  4233. }
  4234. static void intel_edp_drrs_downclock_work(struct work_struct *work)
  4235. {
  4236. struct drm_i915_private *dev_priv =
  4237. container_of(work, typeof(*dev_priv), drrs.work.work);
  4238. struct intel_dp *intel_dp;
  4239. mutex_lock(&dev_priv->drrs.mutex);
  4240. intel_dp = dev_priv->drrs.dp;
  4241. if (!intel_dp)
  4242. goto unlock;
  4243. /*
  4244. * The delayed work can race with an invalidate hence we need to
  4245. * recheck.
  4246. */
  4247. if (dev_priv->drrs.busy_frontbuffer_bits)
  4248. goto unlock;
  4249. if (dev_priv->drrs.refresh_rate_type != DRRS_LOW_RR)
  4250. intel_dp_set_drrs_state(dev_priv->dev,
  4251. intel_dp->attached_connector->panel.
  4252. downclock_mode->vrefresh);
  4253. unlock:
  4254. mutex_unlock(&dev_priv->drrs.mutex);
  4255. }
  4256. /**
  4257. * intel_edp_drrs_invalidate - Disable Idleness DRRS
  4258. * @dev: DRM device
  4259. * @frontbuffer_bits: frontbuffer plane tracking bits
  4260. *
  4261. * This function gets called everytime rendering on the given planes start.
  4262. * Hence DRRS needs to be Upclocked, i.e. (LOW_RR -> HIGH_RR).
  4263. *
  4264. * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
  4265. */
  4266. void intel_edp_drrs_invalidate(struct drm_device *dev,
  4267. unsigned frontbuffer_bits)
  4268. {
  4269. struct drm_i915_private *dev_priv = dev->dev_private;
  4270. struct drm_crtc *crtc;
  4271. enum pipe pipe;
  4272. if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
  4273. return;
  4274. cancel_delayed_work(&dev_priv->drrs.work);
  4275. mutex_lock(&dev_priv->drrs.mutex);
  4276. if (!dev_priv->drrs.dp) {
  4277. mutex_unlock(&dev_priv->drrs.mutex);
  4278. return;
  4279. }
  4280. crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
  4281. pipe = to_intel_crtc(crtc)->pipe;
  4282. frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
  4283. dev_priv->drrs.busy_frontbuffer_bits |= frontbuffer_bits;
  4284. /* invalidate means busy screen hence upclock */
  4285. if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
  4286. intel_dp_set_drrs_state(dev_priv->dev,
  4287. dev_priv->drrs.dp->attached_connector->panel.
  4288. fixed_mode->vrefresh);
  4289. mutex_unlock(&dev_priv->drrs.mutex);
  4290. }
  4291. /**
  4292. * intel_edp_drrs_flush - Restart Idleness DRRS
  4293. * @dev: DRM device
  4294. * @frontbuffer_bits: frontbuffer plane tracking bits
  4295. *
  4296. * This function gets called every time rendering on the given planes has
  4297. * completed or flip on a crtc is completed. So DRRS should be upclocked
  4298. * (LOW_RR -> HIGH_RR). And also Idleness detection should be started again,
  4299. * if no other planes are dirty.
  4300. *
  4301. * Dirty frontbuffers relevant to DRRS are tracked in busy_frontbuffer_bits.
  4302. */
  4303. void intel_edp_drrs_flush(struct drm_device *dev,
  4304. unsigned frontbuffer_bits)
  4305. {
  4306. struct drm_i915_private *dev_priv = dev->dev_private;
  4307. struct drm_crtc *crtc;
  4308. enum pipe pipe;
  4309. if (dev_priv->drrs.type == DRRS_NOT_SUPPORTED)
  4310. return;
  4311. cancel_delayed_work(&dev_priv->drrs.work);
  4312. mutex_lock(&dev_priv->drrs.mutex);
  4313. if (!dev_priv->drrs.dp) {
  4314. mutex_unlock(&dev_priv->drrs.mutex);
  4315. return;
  4316. }
  4317. crtc = dp_to_dig_port(dev_priv->drrs.dp)->base.base.crtc;
  4318. pipe = to_intel_crtc(crtc)->pipe;
  4319. frontbuffer_bits &= INTEL_FRONTBUFFER_ALL_MASK(pipe);
  4320. dev_priv->drrs.busy_frontbuffer_bits &= ~frontbuffer_bits;
  4321. /* flush means busy screen hence upclock */
  4322. if (frontbuffer_bits && dev_priv->drrs.refresh_rate_type == DRRS_LOW_RR)
  4323. intel_dp_set_drrs_state(dev_priv->dev,
  4324. dev_priv->drrs.dp->attached_connector->panel.
  4325. fixed_mode->vrefresh);
  4326. /*
  4327. * flush also means no more activity hence schedule downclock, if all
  4328. * other fbs are quiescent too
  4329. */
  4330. if (!dev_priv->drrs.busy_frontbuffer_bits)
  4331. schedule_delayed_work(&dev_priv->drrs.work,
  4332. msecs_to_jiffies(1000));
  4333. mutex_unlock(&dev_priv->drrs.mutex);
  4334. }
  4335. /**
  4336. * DOC: Display Refresh Rate Switching (DRRS)
  4337. *
  4338. * Display Refresh Rate Switching (DRRS) is a power conservation feature
  4339. * which enables swtching between low and high refresh rates,
  4340. * dynamically, based on the usage scenario. This feature is applicable
  4341. * for internal panels.
  4342. *
  4343. * Indication that the panel supports DRRS is given by the panel EDID, which
  4344. * would list multiple refresh rates for one resolution.
  4345. *
  4346. * DRRS is of 2 types - static and seamless.
  4347. * Static DRRS involves changing refresh rate (RR) by doing a full modeset
  4348. * (may appear as a blink on screen) and is used in dock-undock scenario.
  4349. * Seamless DRRS involves changing RR without any visual effect to the user
  4350. * and can be used during normal system usage. This is done by programming
  4351. * certain registers.
  4352. *
  4353. * Support for static/seamless DRRS may be indicated in the VBT based on
  4354. * inputs from the panel spec.
  4355. *
  4356. * DRRS saves power by switching to low RR based on usage scenarios.
  4357. *
  4358. * The implementation is based on frontbuffer tracking implementation. When
  4359. * there is a disturbance on the screen triggered by user activity or a periodic
  4360. * system activity, DRRS is disabled (RR is changed to high RR). When there is
  4361. * no movement on screen, after a timeout of 1 second, a switch to low RR is
  4362. * made.
  4363. *
  4364. * For integration with frontbuffer tracking code, intel_edp_drrs_invalidate()
  4365. * and intel_edp_drrs_flush() are called.
  4366. *
  4367. * DRRS can be further extended to support other internal panels and also
  4368. * the scenario of video playback wherein RR is set based on the rate
  4369. * requested by userspace.
  4370. */
  4371. /**
  4372. * intel_dp_drrs_init - Init basic DRRS work and mutex.
  4373. * @intel_connector: eDP connector
  4374. * @fixed_mode: preferred mode of panel
  4375. *
  4376. * This function is called only once at driver load to initialize basic
  4377. * DRRS stuff.
  4378. *
  4379. * Returns:
  4380. * Downclock mode if panel supports it, else return NULL.
  4381. * DRRS support is determined by the presence of downclock mode (apart
  4382. * from VBT setting).
  4383. */
  4384. static struct drm_display_mode *
  4385. intel_dp_drrs_init(struct intel_connector *intel_connector,
  4386. struct drm_display_mode *fixed_mode)
  4387. {
  4388. struct drm_connector *connector = &intel_connector->base;
  4389. struct drm_device *dev = connector->dev;
  4390. struct drm_i915_private *dev_priv = dev->dev_private;
  4391. struct drm_display_mode *downclock_mode = NULL;
  4392. INIT_DELAYED_WORK(&dev_priv->drrs.work, intel_edp_drrs_downclock_work);
  4393. mutex_init(&dev_priv->drrs.mutex);
  4394. if (INTEL_INFO(dev)->gen <= 6) {
  4395. DRM_DEBUG_KMS("DRRS supported for Gen7 and above\n");
  4396. return NULL;
  4397. }
  4398. if (dev_priv->vbt.drrs_type != SEAMLESS_DRRS_SUPPORT) {
  4399. DRM_DEBUG_KMS("VBT doesn't support DRRS\n");
  4400. return NULL;
  4401. }
  4402. downclock_mode = intel_find_panel_downclock
  4403. (dev, fixed_mode, connector);
  4404. if (!downclock_mode) {
  4405. DRM_DEBUG_KMS("Downclock mode is not found. DRRS not supported\n");
  4406. return NULL;
  4407. }
  4408. dev_priv->drrs.type = dev_priv->vbt.drrs_type;
  4409. dev_priv->drrs.refresh_rate_type = DRRS_HIGH_RR;
  4410. DRM_DEBUG_KMS("seamless DRRS supported for eDP panel.\n");
  4411. return downclock_mode;
  4412. }
  4413. static bool intel_edp_init_connector(struct intel_dp *intel_dp,
  4414. struct intel_connector *intel_connector)
  4415. {
  4416. struct drm_connector *connector = &intel_connector->base;
  4417. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  4418. struct intel_encoder *intel_encoder = &intel_dig_port->base;
  4419. struct drm_device *dev = intel_encoder->base.dev;
  4420. struct drm_i915_private *dev_priv = dev->dev_private;
  4421. struct drm_display_mode *fixed_mode = NULL;
  4422. struct drm_display_mode *downclock_mode = NULL;
  4423. bool has_dpcd;
  4424. struct drm_display_mode *scan;
  4425. struct edid *edid;
  4426. enum pipe pipe = INVALID_PIPE;
  4427. if (!is_edp(intel_dp))
  4428. return true;
  4429. pps_lock(intel_dp);
  4430. intel_edp_panel_vdd_sanitize(intel_dp);
  4431. pps_unlock(intel_dp);
  4432. /* Cache DPCD and EDID for edp. */
  4433. has_dpcd = intel_dp_get_dpcd(intel_dp);
  4434. if (has_dpcd) {
  4435. if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
  4436. dev_priv->no_aux_handshake =
  4437. intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
  4438. DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
  4439. } else {
  4440. /* if this fails, presume the device is a ghost */
  4441. DRM_INFO("failed to retrieve link info, disabling eDP\n");
  4442. return false;
  4443. }
  4444. /* We now know it's not a ghost, init power sequence regs. */
  4445. pps_lock(intel_dp);
  4446. intel_dp_init_panel_power_sequencer_registers(dev, intel_dp);
  4447. pps_unlock(intel_dp);
  4448. mutex_lock(&dev->mode_config.mutex);
  4449. edid = drm_get_edid(connector, &intel_dp->aux.ddc);
  4450. if (edid) {
  4451. if (drm_add_edid_modes(connector, edid)) {
  4452. drm_mode_connector_update_edid_property(connector,
  4453. edid);
  4454. drm_edid_to_eld(connector, edid);
  4455. } else {
  4456. kfree(edid);
  4457. edid = ERR_PTR(-EINVAL);
  4458. }
  4459. } else {
  4460. edid = ERR_PTR(-ENOENT);
  4461. }
  4462. intel_connector->edid = edid;
  4463. /* prefer fixed mode from EDID if available */
  4464. list_for_each_entry(scan, &connector->probed_modes, head) {
  4465. if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
  4466. fixed_mode = drm_mode_duplicate(dev, scan);
  4467. downclock_mode = intel_dp_drrs_init(
  4468. intel_connector, fixed_mode);
  4469. break;
  4470. }
  4471. }
  4472. /* fallback to VBT if available for eDP */
  4473. if (!fixed_mode && dev_priv->vbt.lfp_lvds_vbt_mode) {
  4474. fixed_mode = drm_mode_duplicate(dev,
  4475. dev_priv->vbt.lfp_lvds_vbt_mode);
  4476. if (fixed_mode) {
  4477. fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
  4478. connector->display_info.width_mm = fixed_mode->width_mm;
  4479. connector->display_info.height_mm = fixed_mode->height_mm;
  4480. }
  4481. }
  4482. mutex_unlock(&dev->mode_config.mutex);
  4483. if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
  4484. intel_dp->edp_notifier.notifier_call = edp_notify_handler;
  4485. register_reboot_notifier(&intel_dp->edp_notifier);
  4486. /*
  4487. * Figure out the current pipe for the initial backlight setup.
  4488. * If the current pipe isn't valid, try the PPS pipe, and if that
  4489. * fails just assume pipe A.
  4490. */
  4491. if (IS_CHERRYVIEW(dev))
  4492. pipe = DP_PORT_TO_PIPE_CHV(intel_dp->DP);
  4493. else
  4494. pipe = PORT_TO_PIPE(intel_dp->DP);
  4495. if (pipe != PIPE_A && pipe != PIPE_B)
  4496. pipe = intel_dp->pps_pipe;
  4497. if (pipe != PIPE_A && pipe != PIPE_B)
  4498. pipe = PIPE_A;
  4499. DRM_DEBUG_KMS("using pipe %c for initial backlight setup\n",
  4500. pipe_name(pipe));
  4501. }
  4502. intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode);
  4503. intel_connector->panel.backlight.power = intel_edp_backlight_power;
  4504. intel_panel_setup_backlight(connector, pipe);
  4505. return true;
  4506. }
  4507. bool
  4508. intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
  4509. struct intel_connector *intel_connector)
  4510. {
  4511. struct drm_connector *connector = &intel_connector->base;
  4512. struct intel_dp *intel_dp = &intel_dig_port->dp;
  4513. struct intel_encoder *intel_encoder = &intel_dig_port->base;
  4514. struct drm_device *dev = intel_encoder->base.dev;
  4515. struct drm_i915_private *dev_priv = dev->dev_private;
  4516. enum port port = intel_dig_port->port;
  4517. int type, ret;
  4518. if (WARN(intel_dig_port->max_lanes < 1,
  4519. "Not enough lanes (%d) for DP on port %c\n",
  4520. intel_dig_port->max_lanes, port_name(port)))
  4521. return false;
  4522. intel_dp->pps_pipe = INVALID_PIPE;
  4523. /* intel_dp vfuncs */
  4524. if (INTEL_INFO(dev)->gen >= 9)
  4525. intel_dp->get_aux_clock_divider = skl_get_aux_clock_divider;
  4526. else if (IS_HASWELL(dev) || IS_BROADWELL(dev))
  4527. intel_dp->get_aux_clock_divider = hsw_get_aux_clock_divider;
  4528. else if (HAS_PCH_SPLIT(dev))
  4529. intel_dp->get_aux_clock_divider = ilk_get_aux_clock_divider;
  4530. else
  4531. intel_dp->get_aux_clock_divider = g4x_get_aux_clock_divider;
  4532. if (INTEL_INFO(dev)->gen >= 9)
  4533. intel_dp->get_aux_send_ctl = skl_get_aux_send_ctl;
  4534. else
  4535. intel_dp->get_aux_send_ctl = g4x_get_aux_send_ctl;
  4536. if (HAS_DDI(dev))
  4537. intel_dp->prepare_link_retrain = intel_ddi_prepare_link_retrain;
  4538. /* Preserve the current hw state. */
  4539. intel_dp->DP = I915_READ(intel_dp->output_reg);
  4540. intel_dp->attached_connector = intel_connector;
  4541. if (intel_dp_is_edp(dev, port))
  4542. type = DRM_MODE_CONNECTOR_eDP;
  4543. else
  4544. type = DRM_MODE_CONNECTOR_DisplayPort;
  4545. /*
  4546. * For eDP we always set the encoder type to INTEL_OUTPUT_EDP, but
  4547. * for DP the encoder type can be set by the caller to
  4548. * INTEL_OUTPUT_UNKNOWN for DDI, so don't rewrite it.
  4549. */
  4550. if (type == DRM_MODE_CONNECTOR_eDP)
  4551. intel_encoder->type = INTEL_OUTPUT_EDP;
  4552. /* eDP only on port B and/or C on vlv/chv */
  4553. if (WARN_ON((IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) &&
  4554. is_edp(intel_dp) && port != PORT_B && port != PORT_C))
  4555. return false;
  4556. DRM_DEBUG_KMS("Adding %s connector on port %c\n",
  4557. type == DRM_MODE_CONNECTOR_eDP ? "eDP" : "DP",
  4558. port_name(port));
  4559. drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
  4560. drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
  4561. connector->interlace_allowed = true;
  4562. connector->doublescan_allowed = 0;
  4563. INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
  4564. edp_panel_vdd_work);
  4565. intel_connector_attach_encoder(intel_connector, intel_encoder);
  4566. drm_connector_register(connector);
  4567. if (HAS_DDI(dev))
  4568. intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
  4569. else
  4570. intel_connector->get_hw_state = intel_connector_get_hw_state;
  4571. intel_connector->unregister = intel_dp_connector_unregister;
  4572. /* Set up the hotplug pin. */
  4573. switch (port) {
  4574. case PORT_A:
  4575. intel_encoder->hpd_pin = HPD_PORT_A;
  4576. break;
  4577. case PORT_B:
  4578. intel_encoder->hpd_pin = HPD_PORT_B;
  4579. if (IS_BXT_REVID(dev, 0, BXT_REVID_A1))
  4580. intel_encoder->hpd_pin = HPD_PORT_A;
  4581. break;
  4582. case PORT_C:
  4583. intel_encoder->hpd_pin = HPD_PORT_C;
  4584. break;
  4585. case PORT_D:
  4586. intel_encoder->hpd_pin = HPD_PORT_D;
  4587. break;
  4588. case PORT_E:
  4589. intel_encoder->hpd_pin = HPD_PORT_E;
  4590. break;
  4591. default:
  4592. BUG();
  4593. }
  4594. if (is_edp(intel_dp)) {
  4595. pps_lock(intel_dp);
  4596. intel_dp_init_panel_power_timestamps(intel_dp);
  4597. if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
  4598. vlv_initial_power_sequencer_setup(intel_dp);
  4599. else
  4600. intel_dp_init_panel_power_sequencer(dev, intel_dp);
  4601. pps_unlock(intel_dp);
  4602. }
  4603. ret = intel_dp_aux_init(intel_dp, intel_connector);
  4604. if (ret)
  4605. goto fail;
  4606. /* init MST on ports that can support it */
  4607. if (HAS_DP_MST(dev) &&
  4608. (port == PORT_B || port == PORT_C || port == PORT_D))
  4609. intel_dp_mst_encoder_init(intel_dig_port,
  4610. intel_connector->base.base.id);
  4611. if (!intel_edp_init_connector(intel_dp, intel_connector)) {
  4612. intel_dp_aux_fini(intel_dp);
  4613. intel_dp_mst_encoder_cleanup(intel_dig_port);
  4614. goto fail;
  4615. }
  4616. intel_dp_add_properties(intel_dp, connector);
  4617. /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
  4618. * 0xd. Failure to do so will result in spurious interrupts being
  4619. * generated on the port when a cable is not attached.
  4620. */
  4621. if (IS_G4X(dev) && !IS_GM45(dev)) {
  4622. u32 temp = I915_READ(PEG_BAND_GAP_DATA);
  4623. I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
  4624. }
  4625. i915_debugfs_connector_add(connector);
  4626. return true;
  4627. fail:
  4628. if (is_edp(intel_dp)) {
  4629. cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
  4630. /*
  4631. * vdd might still be enabled do to the delayed vdd off.
  4632. * Make sure vdd is actually turned off here.
  4633. */
  4634. pps_lock(intel_dp);
  4635. edp_panel_vdd_off_sync(intel_dp);
  4636. pps_unlock(intel_dp);
  4637. }
  4638. drm_connector_unregister(connector);
  4639. drm_connector_cleanup(connector);
  4640. return false;
  4641. }
  4642. bool intel_dp_init(struct drm_device *dev,
  4643. i915_reg_t output_reg,
  4644. enum port port)
  4645. {
  4646. struct drm_i915_private *dev_priv = dev->dev_private;
  4647. struct intel_digital_port *intel_dig_port;
  4648. struct intel_encoder *intel_encoder;
  4649. struct drm_encoder *encoder;
  4650. struct intel_connector *intel_connector;
  4651. intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
  4652. if (!intel_dig_port)
  4653. return false;
  4654. intel_connector = intel_connector_alloc();
  4655. if (!intel_connector)
  4656. goto err_connector_alloc;
  4657. intel_encoder = &intel_dig_port->base;
  4658. encoder = &intel_encoder->base;
  4659. if (drm_encoder_init(dev, &intel_encoder->base, &intel_dp_enc_funcs,
  4660. DRM_MODE_ENCODER_TMDS, "DP %c", port_name(port)))
  4661. goto err_encoder_init;
  4662. intel_encoder->compute_config = intel_dp_compute_config;
  4663. intel_encoder->disable = intel_disable_dp;
  4664. intel_encoder->get_hw_state = intel_dp_get_hw_state;
  4665. intel_encoder->get_config = intel_dp_get_config;
  4666. intel_encoder->suspend = intel_dp_encoder_suspend;
  4667. if (IS_CHERRYVIEW(dev)) {
  4668. intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable;
  4669. intel_encoder->pre_enable = chv_pre_enable_dp;
  4670. intel_encoder->enable = vlv_enable_dp;
  4671. intel_encoder->post_disable = chv_post_disable_dp;
  4672. intel_encoder->post_pll_disable = chv_dp_post_pll_disable;
  4673. } else if (IS_VALLEYVIEW(dev)) {
  4674. intel_encoder->pre_pll_enable = vlv_dp_pre_pll_enable;
  4675. intel_encoder->pre_enable = vlv_pre_enable_dp;
  4676. intel_encoder->enable = vlv_enable_dp;
  4677. intel_encoder->post_disable = vlv_post_disable_dp;
  4678. } else {
  4679. intel_encoder->pre_enable = g4x_pre_enable_dp;
  4680. intel_encoder->enable = g4x_enable_dp;
  4681. if (INTEL_INFO(dev)->gen >= 5)
  4682. intel_encoder->post_disable = ilk_post_disable_dp;
  4683. }
  4684. intel_dig_port->port = port;
  4685. intel_dig_port->dp.output_reg = output_reg;
  4686. intel_dig_port->max_lanes = 4;
  4687. intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
  4688. if (IS_CHERRYVIEW(dev)) {
  4689. if (port == PORT_D)
  4690. intel_encoder->crtc_mask = 1 << 2;
  4691. else
  4692. intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
  4693. } else {
  4694. intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
  4695. }
  4696. intel_encoder->cloneable = 0;
  4697. intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
  4698. dev_priv->hotplug.irq_port[port] = intel_dig_port;
  4699. if (!intel_dp_init_connector(intel_dig_port, intel_connector))
  4700. goto err_init_connector;
  4701. return true;
  4702. err_init_connector:
  4703. drm_encoder_cleanup(encoder);
  4704. err_encoder_init:
  4705. kfree(intel_connector);
  4706. err_connector_alloc:
  4707. kfree(intel_dig_port);
  4708. return false;
  4709. }
  4710. void intel_dp_mst_suspend(struct drm_device *dev)
  4711. {
  4712. struct drm_i915_private *dev_priv = dev->dev_private;
  4713. int i;
  4714. /* disable MST */
  4715. for (i = 0; i < I915_MAX_PORTS; i++) {
  4716. struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
  4717. if (!intel_dig_port)
  4718. continue;
  4719. if (intel_dig_port->base.type == INTEL_OUTPUT_DISPLAYPORT) {
  4720. if (!intel_dig_port->dp.can_mst)
  4721. continue;
  4722. if (intel_dig_port->dp.is_mst)
  4723. drm_dp_mst_topology_mgr_suspend(&intel_dig_port->dp.mst_mgr);
  4724. }
  4725. }
  4726. }
  4727. void intel_dp_mst_resume(struct drm_device *dev)
  4728. {
  4729. struct drm_i915_private *dev_priv = dev->dev_private;
  4730. int i;
  4731. for (i = 0; i < I915_MAX_PORTS; i++) {
  4732. struct intel_digital_port *intel_dig_port = dev_priv->hotplug.irq_port[i];
  4733. if (!intel_dig_port)
  4734. continue;
  4735. if (intel_dig_port->base.type == INTEL_OUTPUT_DISPLAYPORT) {
  4736. int ret;
  4737. if (!intel_dig_port->dp.can_mst)
  4738. continue;
  4739. ret = drm_dp_mst_topology_mgr_resume(&intel_dig_port->dp.mst_mgr);
  4740. if (ret != 0) {
  4741. intel_dp_check_mst_status(&intel_dig_port->dp);
  4742. }
  4743. }
  4744. }
  4745. }