intel_dp.c 180 KB

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