intel_dp.c 180 KB

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