intel_dp.c 180 KB

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