intel_dp.c 188 KB

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