intel_dp.c 169 KB

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