drm_edid.c 227 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511
  1. /*
  2. * Copyright (c) 2006 Luc Verhaegen (quirks list)
  3. * Copyright (c) 2007-2008 Intel Corporation
  4. * Jesse Barnes <jesse.barnes@intel.com>
  5. * Copyright 2010 Red Hat, Inc.
  6. *
  7. * DDC probing routines (drm_ddc_read & drm_do_probe_ddc_edid) originally from
  8. * FB layer.
  9. * Copyright (C) 2006 Dennis Munsie <dmunsie@cecropia.com>
  10. *
  11. * Permission is hereby granted, free of charge, to any person obtaining a
  12. * copy of this software and associated documentation files (the "Software"),
  13. * to deal in the Software without restriction, including without limitation
  14. * the rights to use, copy, modify, merge, publish, distribute, sub license,
  15. * and/or sell copies of the Software, and to permit persons to whom the
  16. * Software is furnished to do so, subject to the following conditions:
  17. *
  18. * The above copyright notice and this permission notice (including the
  19. * next paragraph) shall be included in all copies or substantial portions
  20. * of the Software.
  21. *
  22. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  23. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  24. * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  25. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  26. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  27. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  28. * DEALINGS IN THE SOFTWARE.
  29. */
  30. #include <linux/bitfield.h>
  31. #include <linux/byteorder/generic.h>
  32. #include <linux/cec.h>
  33. #include <linux/hdmi.h>
  34. #include <linux/i2c.h>
  35. #include <linux/kernel.h>
  36. #include <linux/module.h>
  37. #include <linux/pci.h>
  38. #include <linux/seq_buf.h>
  39. #include <linux/slab.h>
  40. #include <linux/vga_switcheroo.h>
  41. #include <drm/drm_drv.h>
  42. #include <drm/drm_edid.h>
  43. #include <drm/drm_eld.h>
  44. #include <drm/drm_encoder.h>
  45. #include <drm/drm_print.h>
  46. #include "drm_crtc_internal.h"
  47. #include "drm_displayid_internal.h"
  48. #include "drm_internal.h"
  49. static int oui(u8 first, u8 second, u8 third)
  50. {
  51. return (first << 16) | (second << 8) | third;
  52. }
  53. #define EDID_EST_TIMINGS 16
  54. #define EDID_STD_TIMINGS 8
  55. #define EDID_DETAILED_TIMINGS 4
  56. /*
  57. * EDID blocks out in the wild have a variety of bugs, try to collect
  58. * them here (note that userspace may work around broken monitors first,
  59. * but fixes should make their way here so that the kernel "just works"
  60. * on as many displays as possible).
  61. */
  62. /* First detailed mode wrong, use largest 60Hz mode */
  63. #define EDID_QUIRK_PREFER_LARGE_60 (1 << 0)
  64. /* Reported 135MHz pixel clock is too high, needs adjustment */
  65. #define EDID_QUIRK_135_CLOCK_TOO_HIGH (1 << 1)
  66. /* Prefer the largest mode at 75 Hz */
  67. #define EDID_QUIRK_PREFER_LARGE_75 (1 << 2)
  68. /* Detail timing is in cm not mm */
  69. #define EDID_QUIRK_DETAILED_IN_CM (1 << 3)
  70. /* Detailed timing descriptors have bogus size values, so just take the
  71. * maximum size and use that.
  72. */
  73. #define EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE (1 << 4)
  74. /* use +hsync +vsync for detailed mode */
  75. #define EDID_QUIRK_DETAILED_SYNC_PP (1 << 6)
  76. /* Force reduced-blanking timings for detailed modes */
  77. #define EDID_QUIRK_FORCE_REDUCED_BLANKING (1 << 7)
  78. /* Force 8bpc */
  79. #define EDID_QUIRK_FORCE_8BPC (1 << 8)
  80. /* Force 12bpc */
  81. #define EDID_QUIRK_FORCE_12BPC (1 << 9)
  82. /* Force 6bpc */
  83. #define EDID_QUIRK_FORCE_6BPC (1 << 10)
  84. /* Force 10bpc */
  85. #define EDID_QUIRK_FORCE_10BPC (1 << 11)
  86. /* Non desktop display (i.e. HMD) */
  87. #define EDID_QUIRK_NON_DESKTOP (1 << 12)
  88. /* Cap the DSC target bitrate to 15bpp */
  89. #define EDID_QUIRK_CAP_DSC_15BPP (1 << 13)
  90. #define MICROSOFT_IEEE_OUI 0xca125c
  91. struct detailed_mode_closure {
  92. struct drm_connector *connector;
  93. const struct drm_edid *drm_edid;
  94. bool preferred;
  95. int modes;
  96. };
  97. struct drm_edid_match_closure {
  98. const struct drm_edid_ident *ident;
  99. bool matched;
  100. };
  101. #define LEVEL_DMT 0
  102. #define LEVEL_GTF 1
  103. #define LEVEL_GTF2 2
  104. #define LEVEL_CVT 3
  105. #define EDID_QUIRK(vend_chr_0, vend_chr_1, vend_chr_2, product_id, _quirks) \
  106. { \
  107. .ident = { \
  108. .panel_id = drm_edid_encode_panel_id(vend_chr_0, vend_chr_1, \
  109. vend_chr_2, product_id), \
  110. }, \
  111. .quirks = _quirks \
  112. }
  113. static const struct edid_quirk {
  114. const struct drm_edid_ident ident;
  115. u32 quirks;
  116. } edid_quirk_list[] = {
  117. /* Acer AL1706 */
  118. EDID_QUIRK('A', 'C', 'R', 44358, EDID_QUIRK_PREFER_LARGE_60),
  119. /* Acer F51 */
  120. EDID_QUIRK('A', 'P', 'I', 0x7602, EDID_QUIRK_PREFER_LARGE_60),
  121. /* AEO model 0 reports 8 bpc, but is a 6 bpc panel */
  122. EDID_QUIRK('A', 'E', 'O', 0, EDID_QUIRK_FORCE_6BPC),
  123. /* BenQ GW2765 */
  124. EDID_QUIRK('B', 'N', 'Q', 0x78d6, EDID_QUIRK_FORCE_8BPC),
  125. /* BOE model on HP Pavilion 15-n233sl reports 8 bpc, but is a 6 bpc panel */
  126. EDID_QUIRK('B', 'O', 'E', 0x78b, EDID_QUIRK_FORCE_6BPC),
  127. /* CPT panel of Asus UX303LA reports 8 bpc, but is a 6 bpc panel */
  128. EDID_QUIRK('C', 'P', 'T', 0x17df, EDID_QUIRK_FORCE_6BPC),
  129. /* SDC panel of Lenovo B50-80 reports 8 bpc, but is a 6 bpc panel */
  130. EDID_QUIRK('S', 'D', 'C', 0x3652, EDID_QUIRK_FORCE_6BPC),
  131. /* BOE model 0x0771 reports 8 bpc, but is a 6 bpc panel */
  132. EDID_QUIRK('B', 'O', 'E', 0x0771, EDID_QUIRK_FORCE_6BPC),
  133. /* Belinea 10 15 55 */
  134. EDID_QUIRK('M', 'A', 'X', 1516, EDID_QUIRK_PREFER_LARGE_60),
  135. EDID_QUIRK('M', 'A', 'X', 0x77e, EDID_QUIRK_PREFER_LARGE_60),
  136. /* Envision Peripherals, Inc. EN-7100e */
  137. EDID_QUIRK('E', 'P', 'I', 59264, EDID_QUIRK_135_CLOCK_TOO_HIGH),
  138. /* Envision EN2028 */
  139. EDID_QUIRK('E', 'P', 'I', 8232, EDID_QUIRK_PREFER_LARGE_60),
  140. /* Funai Electronics PM36B */
  141. EDID_QUIRK('F', 'C', 'M', 13600, EDID_QUIRK_PREFER_LARGE_75 |
  142. EDID_QUIRK_DETAILED_IN_CM),
  143. /* LG 27GP950 */
  144. EDID_QUIRK('G', 'S', 'M', 0x5bbf, EDID_QUIRK_CAP_DSC_15BPP),
  145. /* LG 27GN950 */
  146. EDID_QUIRK('G', 'S', 'M', 0x5b9a, EDID_QUIRK_CAP_DSC_15BPP),
  147. /* LGD panel of HP zBook 17 G2, eDP 10 bpc, but reports unknown bpc */
  148. EDID_QUIRK('L', 'G', 'D', 764, EDID_QUIRK_FORCE_10BPC),
  149. /* LG Philips LCD LP154W01-A5 */
  150. EDID_QUIRK('L', 'P', 'L', 0, EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE),
  151. EDID_QUIRK('L', 'P', 'L', 0x2a00, EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE),
  152. /* Samsung SyncMaster 205BW. Note: irony */
  153. EDID_QUIRK('S', 'A', 'M', 541, EDID_QUIRK_DETAILED_SYNC_PP),
  154. /* Samsung SyncMaster 22[5-6]BW */
  155. EDID_QUIRK('S', 'A', 'M', 596, EDID_QUIRK_PREFER_LARGE_60),
  156. EDID_QUIRK('S', 'A', 'M', 638, EDID_QUIRK_PREFER_LARGE_60),
  157. /* Sony PVM-2541A does up to 12 bpc, but only reports max 8 bpc */
  158. EDID_QUIRK('S', 'N', 'Y', 0x2541, EDID_QUIRK_FORCE_12BPC),
  159. /* ViewSonic VA2026w */
  160. EDID_QUIRK('V', 'S', 'C', 5020, EDID_QUIRK_FORCE_REDUCED_BLANKING),
  161. /* Medion MD 30217 PG */
  162. EDID_QUIRK('M', 'E', 'D', 0x7b8, EDID_QUIRK_PREFER_LARGE_75),
  163. /* Lenovo G50 */
  164. EDID_QUIRK('S', 'D', 'C', 18514, EDID_QUIRK_FORCE_6BPC),
  165. /* Panel in Samsung NP700G7A-S01PL notebook reports 6bpc */
  166. EDID_QUIRK('S', 'E', 'C', 0xd033, EDID_QUIRK_FORCE_8BPC),
  167. /* Rotel RSX-1058 forwards sink's EDID but only does HDMI 1.1*/
  168. EDID_QUIRK('E', 'T', 'R', 13896, EDID_QUIRK_FORCE_8BPC),
  169. /* Valve Index Headset */
  170. EDID_QUIRK('V', 'L', 'V', 0x91a8, EDID_QUIRK_NON_DESKTOP),
  171. EDID_QUIRK('V', 'L', 'V', 0x91b0, EDID_QUIRK_NON_DESKTOP),
  172. EDID_QUIRK('V', 'L', 'V', 0x91b1, EDID_QUIRK_NON_DESKTOP),
  173. EDID_QUIRK('V', 'L', 'V', 0x91b2, EDID_QUIRK_NON_DESKTOP),
  174. EDID_QUIRK('V', 'L', 'V', 0x91b3, EDID_QUIRK_NON_DESKTOP),
  175. EDID_QUIRK('V', 'L', 'V', 0x91b4, EDID_QUIRK_NON_DESKTOP),
  176. EDID_QUIRK('V', 'L', 'V', 0x91b5, EDID_QUIRK_NON_DESKTOP),
  177. EDID_QUIRK('V', 'L', 'V', 0x91b6, EDID_QUIRK_NON_DESKTOP),
  178. EDID_QUIRK('V', 'L', 'V', 0x91b7, EDID_QUIRK_NON_DESKTOP),
  179. EDID_QUIRK('V', 'L', 'V', 0x91b8, EDID_QUIRK_NON_DESKTOP),
  180. EDID_QUIRK('V', 'L', 'V', 0x91b9, EDID_QUIRK_NON_DESKTOP),
  181. EDID_QUIRK('V', 'L', 'V', 0x91ba, EDID_QUIRK_NON_DESKTOP),
  182. EDID_QUIRK('V', 'L', 'V', 0x91bb, EDID_QUIRK_NON_DESKTOP),
  183. EDID_QUIRK('V', 'L', 'V', 0x91bc, EDID_QUIRK_NON_DESKTOP),
  184. EDID_QUIRK('V', 'L', 'V', 0x91bd, EDID_QUIRK_NON_DESKTOP),
  185. EDID_QUIRK('V', 'L', 'V', 0x91be, EDID_QUIRK_NON_DESKTOP),
  186. EDID_QUIRK('V', 'L', 'V', 0x91bf, EDID_QUIRK_NON_DESKTOP),
  187. /* HTC Vive and Vive Pro VR Headsets */
  188. EDID_QUIRK('H', 'V', 'R', 0xaa01, EDID_QUIRK_NON_DESKTOP),
  189. EDID_QUIRK('H', 'V', 'R', 0xaa02, EDID_QUIRK_NON_DESKTOP),
  190. /* Oculus Rift DK1, DK2, CV1 and Rift S VR Headsets */
  191. EDID_QUIRK('O', 'V', 'R', 0x0001, EDID_QUIRK_NON_DESKTOP),
  192. EDID_QUIRK('O', 'V', 'R', 0x0003, EDID_QUIRK_NON_DESKTOP),
  193. EDID_QUIRK('O', 'V', 'R', 0x0004, EDID_QUIRK_NON_DESKTOP),
  194. EDID_QUIRK('O', 'V', 'R', 0x0012, EDID_QUIRK_NON_DESKTOP),
  195. /* Windows Mixed Reality Headsets */
  196. EDID_QUIRK('A', 'C', 'R', 0x7fce, EDID_QUIRK_NON_DESKTOP),
  197. EDID_QUIRK('L', 'E', 'N', 0x0408, EDID_QUIRK_NON_DESKTOP),
  198. EDID_QUIRK('F', 'U', 'J', 0x1970, EDID_QUIRK_NON_DESKTOP),
  199. EDID_QUIRK('D', 'E', 'L', 0x7fce, EDID_QUIRK_NON_DESKTOP),
  200. EDID_QUIRK('S', 'E', 'C', 0x144a, EDID_QUIRK_NON_DESKTOP),
  201. EDID_QUIRK('A', 'U', 'S', 0xc102, EDID_QUIRK_NON_DESKTOP),
  202. /* Sony PlayStation VR Headset */
  203. EDID_QUIRK('S', 'N', 'Y', 0x0704, EDID_QUIRK_NON_DESKTOP),
  204. /* Sensics VR Headsets */
  205. EDID_QUIRK('S', 'E', 'N', 0x1019, EDID_QUIRK_NON_DESKTOP),
  206. /* OSVR HDK and HDK2 VR Headsets */
  207. EDID_QUIRK('S', 'V', 'R', 0x1019, EDID_QUIRK_NON_DESKTOP),
  208. EDID_QUIRK('A', 'U', 'O', 0x1111, EDID_QUIRK_NON_DESKTOP),
  209. };
  210. /*
  211. * Autogenerated from the DMT spec.
  212. * This table is copied from xfree86/modes/xf86EdidModes.c.
  213. */
  214. static const struct drm_display_mode drm_dmt_modes[] = {
  215. /* 0x01 - 640x350@85Hz */
  216. { DRM_MODE("640x350", DRM_MODE_TYPE_DRIVER, 31500, 640, 672,
  217. 736, 832, 0, 350, 382, 385, 445, 0,
  218. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  219. /* 0x02 - 640x400@85Hz */
  220. { DRM_MODE("640x400", DRM_MODE_TYPE_DRIVER, 31500, 640, 672,
  221. 736, 832, 0, 400, 401, 404, 445, 0,
  222. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  223. /* 0x03 - 720x400@85Hz */
  224. { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 35500, 720, 756,
  225. 828, 936, 0, 400, 401, 404, 446, 0,
  226. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  227. /* 0x04 - 640x480@60Hz */
  228. { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
  229. 752, 800, 0, 480, 490, 492, 525, 0,
  230. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
  231. /* 0x05 - 640x480@72Hz */
  232. { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 664,
  233. 704, 832, 0, 480, 489, 492, 520, 0,
  234. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
  235. /* 0x06 - 640x480@75Hz */
  236. { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 656,
  237. 720, 840, 0, 480, 481, 484, 500, 0,
  238. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
  239. /* 0x07 - 640x480@85Hz */
  240. { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 36000, 640, 696,
  241. 752, 832, 0, 480, 481, 484, 509, 0,
  242. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
  243. /* 0x08 - 800x600@56Hz */
  244. { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 36000, 800, 824,
  245. 896, 1024, 0, 600, 601, 603, 625, 0,
  246. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  247. /* 0x09 - 800x600@60Hz */
  248. { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840,
  249. 968, 1056, 0, 600, 601, 605, 628, 0,
  250. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  251. /* 0x0a - 800x600@72Hz */
  252. { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 50000, 800, 856,
  253. 976, 1040, 0, 600, 637, 643, 666, 0,
  254. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  255. /* 0x0b - 800x600@75Hz */
  256. { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 49500, 800, 816,
  257. 896, 1056, 0, 600, 601, 604, 625, 0,
  258. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  259. /* 0x0c - 800x600@85Hz */
  260. { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 56250, 800, 832,
  261. 896, 1048, 0, 600, 601, 604, 631, 0,
  262. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  263. /* 0x0d - 800x600@120Hz RB */
  264. { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 73250, 800, 848,
  265. 880, 960, 0, 600, 603, 607, 636, 0,
  266. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  267. /* 0x0e - 848x480@60Hz */
  268. { DRM_MODE("848x480", DRM_MODE_TYPE_DRIVER, 33750, 848, 864,
  269. 976, 1088, 0, 480, 486, 494, 517, 0,
  270. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  271. /* 0x0f - 1024x768@43Hz, interlace */
  272. { DRM_MODE("1024x768i", DRM_MODE_TYPE_DRIVER, 44900, 1024, 1032,
  273. 1208, 1264, 0, 768, 768, 776, 817, 0,
  274. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
  275. DRM_MODE_FLAG_INTERLACE) },
  276. /* 0x10 - 1024x768@60Hz */
  277. { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048,
  278. 1184, 1344, 0, 768, 771, 777, 806, 0,
  279. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
  280. /* 0x11 - 1024x768@70Hz */
  281. { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 75000, 1024, 1048,
  282. 1184, 1328, 0, 768, 771, 777, 806, 0,
  283. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
  284. /* 0x12 - 1024x768@75Hz */
  285. { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 78750, 1024, 1040,
  286. 1136, 1312, 0, 768, 769, 772, 800, 0,
  287. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  288. /* 0x13 - 1024x768@85Hz */
  289. { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 94500, 1024, 1072,
  290. 1168, 1376, 0, 768, 769, 772, 808, 0,
  291. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  292. /* 0x14 - 1024x768@120Hz RB */
  293. { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 115500, 1024, 1072,
  294. 1104, 1184, 0, 768, 771, 775, 813, 0,
  295. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  296. /* 0x15 - 1152x864@75Hz */
  297. { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216,
  298. 1344, 1600, 0, 864, 865, 868, 900, 0,
  299. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  300. /* 0x55 - 1280x720@60Hz */
  301. { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1390,
  302. 1430, 1650, 0, 720, 725, 730, 750, 0,
  303. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  304. /* 0x16 - 1280x768@60Hz RB */
  305. { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 68250, 1280, 1328,
  306. 1360, 1440, 0, 768, 771, 778, 790, 0,
  307. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  308. /* 0x17 - 1280x768@60Hz */
  309. { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 79500, 1280, 1344,
  310. 1472, 1664, 0, 768, 771, 778, 798, 0,
  311. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  312. /* 0x18 - 1280x768@75Hz */
  313. { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 102250, 1280, 1360,
  314. 1488, 1696, 0, 768, 771, 778, 805, 0,
  315. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  316. /* 0x19 - 1280x768@85Hz */
  317. { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 117500, 1280, 1360,
  318. 1496, 1712, 0, 768, 771, 778, 809, 0,
  319. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  320. /* 0x1a - 1280x768@120Hz RB */
  321. { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 140250, 1280, 1328,
  322. 1360, 1440, 0, 768, 771, 778, 813, 0,
  323. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  324. /* 0x1b - 1280x800@60Hz RB */
  325. { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 71000, 1280, 1328,
  326. 1360, 1440, 0, 800, 803, 809, 823, 0,
  327. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  328. /* 0x1c - 1280x800@60Hz */
  329. { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 83500, 1280, 1352,
  330. 1480, 1680, 0, 800, 803, 809, 831, 0,
  331. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  332. /* 0x1d - 1280x800@75Hz */
  333. { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 106500, 1280, 1360,
  334. 1488, 1696, 0, 800, 803, 809, 838, 0,
  335. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  336. /* 0x1e - 1280x800@85Hz */
  337. { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 122500, 1280, 1360,
  338. 1496, 1712, 0, 800, 803, 809, 843, 0,
  339. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  340. /* 0x1f - 1280x800@120Hz RB */
  341. { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 146250, 1280, 1328,
  342. 1360, 1440, 0, 800, 803, 809, 847, 0,
  343. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  344. /* 0x20 - 1280x960@60Hz */
  345. { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1376,
  346. 1488, 1800, 0, 960, 961, 964, 1000, 0,
  347. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  348. /* 0x21 - 1280x960@85Hz */
  349. { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1344,
  350. 1504, 1728, 0, 960, 961, 964, 1011, 0,
  351. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  352. /* 0x22 - 1280x960@120Hz RB */
  353. { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 175500, 1280, 1328,
  354. 1360, 1440, 0, 960, 963, 967, 1017, 0,
  355. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  356. /* 0x23 - 1280x1024@60Hz */
  357. { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1328,
  358. 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
  359. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  360. /* 0x24 - 1280x1024@75Hz */
  361. { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 135000, 1280, 1296,
  362. 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
  363. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  364. /* 0x25 - 1280x1024@85Hz */
  365. { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 157500, 1280, 1344,
  366. 1504, 1728, 0, 1024, 1025, 1028, 1072, 0,
  367. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  368. /* 0x26 - 1280x1024@120Hz RB */
  369. { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 187250, 1280, 1328,
  370. 1360, 1440, 0, 1024, 1027, 1034, 1084, 0,
  371. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  372. /* 0x27 - 1360x768@60Hz */
  373. { DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER, 85500, 1360, 1424,
  374. 1536, 1792, 0, 768, 771, 777, 795, 0,
  375. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  376. /* 0x28 - 1360x768@120Hz RB */
  377. { DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER, 148250, 1360, 1408,
  378. 1440, 1520, 0, 768, 771, 776, 813, 0,
  379. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  380. /* 0x51 - 1366x768@60Hz */
  381. { DRM_MODE("1366x768", DRM_MODE_TYPE_DRIVER, 85500, 1366, 1436,
  382. 1579, 1792, 0, 768, 771, 774, 798, 0,
  383. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  384. /* 0x56 - 1366x768@60Hz */
  385. { DRM_MODE("1366x768", DRM_MODE_TYPE_DRIVER, 72000, 1366, 1380,
  386. 1436, 1500, 0, 768, 769, 772, 800, 0,
  387. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  388. /* 0x29 - 1400x1050@60Hz RB */
  389. { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 101000, 1400, 1448,
  390. 1480, 1560, 0, 1050, 1053, 1057, 1080, 0,
  391. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  392. /* 0x2a - 1400x1050@60Hz */
  393. { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 121750, 1400, 1488,
  394. 1632, 1864, 0, 1050, 1053, 1057, 1089, 0,
  395. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  396. /* 0x2b - 1400x1050@75Hz */
  397. { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 156000, 1400, 1504,
  398. 1648, 1896, 0, 1050, 1053, 1057, 1099, 0,
  399. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  400. /* 0x2c - 1400x1050@85Hz */
  401. { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 179500, 1400, 1504,
  402. 1656, 1912, 0, 1050, 1053, 1057, 1105, 0,
  403. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  404. /* 0x2d - 1400x1050@120Hz RB */
  405. { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 208000, 1400, 1448,
  406. 1480, 1560, 0, 1050, 1053, 1057, 1112, 0,
  407. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  408. /* 0x2e - 1440x900@60Hz RB */
  409. { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 88750, 1440, 1488,
  410. 1520, 1600, 0, 900, 903, 909, 926, 0,
  411. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  412. /* 0x2f - 1440x900@60Hz */
  413. { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 106500, 1440, 1520,
  414. 1672, 1904, 0, 900, 903, 909, 934, 0,
  415. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  416. /* 0x30 - 1440x900@75Hz */
  417. { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 136750, 1440, 1536,
  418. 1688, 1936, 0, 900, 903, 909, 942, 0,
  419. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  420. /* 0x31 - 1440x900@85Hz */
  421. { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 157000, 1440, 1544,
  422. 1696, 1952, 0, 900, 903, 909, 948, 0,
  423. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  424. /* 0x32 - 1440x900@120Hz RB */
  425. { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 182750, 1440, 1488,
  426. 1520, 1600, 0, 900, 903, 909, 953, 0,
  427. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  428. /* 0x53 - 1600x900@60Hz */
  429. { DRM_MODE("1600x900", DRM_MODE_TYPE_DRIVER, 108000, 1600, 1624,
  430. 1704, 1800, 0, 900, 901, 904, 1000, 0,
  431. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  432. /* 0x33 - 1600x1200@60Hz */
  433. { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 162000, 1600, 1664,
  434. 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
  435. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  436. /* 0x34 - 1600x1200@65Hz */
  437. { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 175500, 1600, 1664,
  438. 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
  439. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  440. /* 0x35 - 1600x1200@70Hz */
  441. { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 189000, 1600, 1664,
  442. 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
  443. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  444. /* 0x36 - 1600x1200@75Hz */
  445. { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 202500, 1600, 1664,
  446. 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
  447. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  448. /* 0x37 - 1600x1200@85Hz */
  449. { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 229500, 1600, 1664,
  450. 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
  451. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  452. /* 0x38 - 1600x1200@120Hz RB */
  453. { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 268250, 1600, 1648,
  454. 1680, 1760, 0, 1200, 1203, 1207, 1271, 0,
  455. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  456. /* 0x39 - 1680x1050@60Hz RB */
  457. { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 119000, 1680, 1728,
  458. 1760, 1840, 0, 1050, 1053, 1059, 1080, 0,
  459. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  460. /* 0x3a - 1680x1050@60Hz */
  461. { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 146250, 1680, 1784,
  462. 1960, 2240, 0, 1050, 1053, 1059, 1089, 0,
  463. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  464. /* 0x3b - 1680x1050@75Hz */
  465. { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 187000, 1680, 1800,
  466. 1976, 2272, 0, 1050, 1053, 1059, 1099, 0,
  467. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  468. /* 0x3c - 1680x1050@85Hz */
  469. { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 214750, 1680, 1808,
  470. 1984, 2288, 0, 1050, 1053, 1059, 1105, 0,
  471. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  472. /* 0x3d - 1680x1050@120Hz RB */
  473. { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 245500, 1680, 1728,
  474. 1760, 1840, 0, 1050, 1053, 1059, 1112, 0,
  475. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  476. /* 0x3e - 1792x1344@60Hz */
  477. { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 204750, 1792, 1920,
  478. 2120, 2448, 0, 1344, 1345, 1348, 1394, 0,
  479. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  480. /* 0x3f - 1792x1344@75Hz */
  481. { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 261000, 1792, 1888,
  482. 2104, 2456, 0, 1344, 1345, 1348, 1417, 0,
  483. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  484. /* 0x40 - 1792x1344@120Hz RB */
  485. { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 333250, 1792, 1840,
  486. 1872, 1952, 0, 1344, 1347, 1351, 1423, 0,
  487. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  488. /* 0x41 - 1856x1392@60Hz */
  489. { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 218250, 1856, 1952,
  490. 2176, 2528, 0, 1392, 1393, 1396, 1439, 0,
  491. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  492. /* 0x42 - 1856x1392@75Hz */
  493. { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 288000, 1856, 1984,
  494. 2208, 2560, 0, 1392, 1393, 1396, 1500, 0,
  495. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  496. /* 0x43 - 1856x1392@120Hz RB */
  497. { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 356500, 1856, 1904,
  498. 1936, 2016, 0, 1392, 1395, 1399, 1474, 0,
  499. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  500. /* 0x52 - 1920x1080@60Hz */
  501. { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
  502. 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
  503. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
  504. /* 0x44 - 1920x1200@60Hz RB */
  505. { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 154000, 1920, 1968,
  506. 2000, 2080, 0, 1200, 1203, 1209, 1235, 0,
  507. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  508. /* 0x45 - 1920x1200@60Hz */
  509. { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 193250, 1920, 2056,
  510. 2256, 2592, 0, 1200, 1203, 1209, 1245, 0,
  511. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  512. /* 0x46 - 1920x1200@75Hz */
  513. { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 245250, 1920, 2056,
  514. 2264, 2608, 0, 1200, 1203, 1209, 1255, 0,
  515. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  516. /* 0x47 - 1920x1200@85Hz */
  517. { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 281250, 1920, 2064,
  518. 2272, 2624, 0, 1200, 1203, 1209, 1262, 0,
  519. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  520. /* 0x48 - 1920x1200@120Hz RB */
  521. { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 317000, 1920, 1968,
  522. 2000, 2080, 0, 1200, 1203, 1209, 1271, 0,
  523. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  524. /* 0x49 - 1920x1440@60Hz */
  525. { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 234000, 1920, 2048,
  526. 2256, 2600, 0, 1440, 1441, 1444, 1500, 0,
  527. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  528. /* 0x4a - 1920x1440@75Hz */
  529. { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2064,
  530. 2288, 2640, 0, 1440, 1441, 1444, 1500, 0,
  531. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  532. /* 0x4b - 1920x1440@120Hz RB */
  533. { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 380500, 1920, 1968,
  534. 2000, 2080, 0, 1440, 1443, 1447, 1525, 0,
  535. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  536. /* 0x54 - 2048x1152@60Hz */
  537. { DRM_MODE("2048x1152", DRM_MODE_TYPE_DRIVER, 162000, 2048, 2074,
  538. 2154, 2250, 0, 1152, 1153, 1156, 1200, 0,
  539. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  540. /* 0x4c - 2560x1600@60Hz RB */
  541. { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 268500, 2560, 2608,
  542. 2640, 2720, 0, 1600, 1603, 1609, 1646, 0,
  543. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  544. /* 0x4d - 2560x1600@60Hz */
  545. { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 348500, 2560, 2752,
  546. 3032, 3504, 0, 1600, 1603, 1609, 1658, 0,
  547. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  548. /* 0x4e - 2560x1600@75Hz */
  549. { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 443250, 2560, 2768,
  550. 3048, 3536, 0, 1600, 1603, 1609, 1672, 0,
  551. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  552. /* 0x4f - 2560x1600@85Hz */
  553. { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 505250, 2560, 2768,
  554. 3048, 3536, 0, 1600, 1603, 1609, 1682, 0,
  555. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  556. /* 0x50 - 2560x1600@120Hz RB */
  557. { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 552750, 2560, 2608,
  558. 2640, 2720, 0, 1600, 1603, 1609, 1694, 0,
  559. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  560. /* 0x57 - 4096x2160@60Hz RB */
  561. { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 556744, 4096, 4104,
  562. 4136, 4176, 0, 2160, 2208, 2216, 2222, 0,
  563. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  564. /* 0x58 - 4096x2160@59.94Hz RB */
  565. { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 556188, 4096, 4104,
  566. 4136, 4176, 0, 2160, 2208, 2216, 2222, 0,
  567. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  568. };
  569. /*
  570. * These more or less come from the DMT spec. The 720x400 modes are
  571. * inferred from historical 80x25 practice. The 640x480@67 and 832x624@75
  572. * modes are old-school Mac modes. The EDID spec says the 1152x864@75 mode
  573. * should be 1152x870, again for the Mac, but instead we use the x864 DMT
  574. * mode.
  575. *
  576. * The DMT modes have been fact-checked; the rest are mild guesses.
  577. */
  578. static const struct drm_display_mode edid_est_modes[] = {
  579. { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840,
  580. 968, 1056, 0, 600, 601, 605, 628, 0,
  581. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@60Hz */
  582. { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 36000, 800, 824,
  583. 896, 1024, 0, 600, 601, 603, 625, 0,
  584. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@56Hz */
  585. { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 656,
  586. 720, 840, 0, 480, 481, 484, 500, 0,
  587. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@75Hz */
  588. { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 664,
  589. 704, 832, 0, 480, 489, 492, 520, 0,
  590. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@72Hz */
  591. { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 30240, 640, 704,
  592. 768, 864, 0, 480, 483, 486, 525, 0,
  593. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@67Hz */
  594. { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
  595. 752, 800, 0, 480, 490, 492, 525, 0,
  596. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@60Hz */
  597. { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 35500, 720, 738,
  598. 846, 900, 0, 400, 421, 423, 449, 0,
  599. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 720x400@88Hz */
  600. { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 28320, 720, 738,
  601. 846, 900, 0, 400, 412, 414, 449, 0,
  602. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 720x400@70Hz */
  603. { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 135000, 1280, 1296,
  604. 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
  605. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1280x1024@75Hz */
  606. { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 78750, 1024, 1040,
  607. 1136, 1312, 0, 768, 769, 772, 800, 0,
  608. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1024x768@75Hz */
  609. { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 75000, 1024, 1048,
  610. 1184, 1328, 0, 768, 771, 777, 806, 0,
  611. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 1024x768@70Hz */
  612. { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048,
  613. 1184, 1344, 0, 768, 771, 777, 806, 0,
  614. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 1024x768@60Hz */
  615. { DRM_MODE("1024x768i", DRM_MODE_TYPE_DRIVER,44900, 1024, 1032,
  616. 1208, 1264, 0, 768, 768, 776, 817, 0,
  617. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_INTERLACE) }, /* 1024x768@43Hz */
  618. { DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER, 57284, 832, 864,
  619. 928, 1152, 0, 624, 625, 628, 667, 0,
  620. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 832x624@75Hz */
  621. { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 49500, 800, 816,
  622. 896, 1056, 0, 600, 601, 604, 625, 0,
  623. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@75Hz */
  624. { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 50000, 800, 856,
  625. 976, 1040, 0, 600, 637, 643, 666, 0,
  626. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@72Hz */
  627. { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216,
  628. 1344, 1600, 0, 864, 865, 868, 900, 0,
  629. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1152x864@75Hz */
  630. };
  631. struct minimode {
  632. short w;
  633. short h;
  634. short r;
  635. short rb;
  636. };
  637. static const struct minimode est3_modes[] = {
  638. /* byte 6 */
  639. { 640, 350, 85, 0 },
  640. { 640, 400, 85, 0 },
  641. { 720, 400, 85, 0 },
  642. { 640, 480, 85, 0 },
  643. { 848, 480, 60, 0 },
  644. { 800, 600, 85, 0 },
  645. { 1024, 768, 85, 0 },
  646. { 1152, 864, 75, 0 },
  647. /* byte 7 */
  648. { 1280, 768, 60, 1 },
  649. { 1280, 768, 60, 0 },
  650. { 1280, 768, 75, 0 },
  651. { 1280, 768, 85, 0 },
  652. { 1280, 960, 60, 0 },
  653. { 1280, 960, 85, 0 },
  654. { 1280, 1024, 60, 0 },
  655. { 1280, 1024, 85, 0 },
  656. /* byte 8 */
  657. { 1360, 768, 60, 0 },
  658. { 1440, 900, 60, 1 },
  659. { 1440, 900, 60, 0 },
  660. { 1440, 900, 75, 0 },
  661. { 1440, 900, 85, 0 },
  662. { 1400, 1050, 60, 1 },
  663. { 1400, 1050, 60, 0 },
  664. { 1400, 1050, 75, 0 },
  665. /* byte 9 */
  666. { 1400, 1050, 85, 0 },
  667. { 1680, 1050, 60, 1 },
  668. { 1680, 1050, 60, 0 },
  669. { 1680, 1050, 75, 0 },
  670. { 1680, 1050, 85, 0 },
  671. { 1600, 1200, 60, 0 },
  672. { 1600, 1200, 65, 0 },
  673. { 1600, 1200, 70, 0 },
  674. /* byte 10 */
  675. { 1600, 1200, 75, 0 },
  676. { 1600, 1200, 85, 0 },
  677. { 1792, 1344, 60, 0 },
  678. { 1792, 1344, 75, 0 },
  679. { 1856, 1392, 60, 0 },
  680. { 1856, 1392, 75, 0 },
  681. { 1920, 1200, 60, 1 },
  682. { 1920, 1200, 60, 0 },
  683. /* byte 11 */
  684. { 1920, 1200, 75, 0 },
  685. { 1920, 1200, 85, 0 },
  686. { 1920, 1440, 60, 0 },
  687. { 1920, 1440, 75, 0 },
  688. };
  689. static const struct minimode extra_modes[] = {
  690. { 1024, 576, 60, 0 },
  691. { 1366, 768, 60, 0 },
  692. { 1600, 900, 60, 0 },
  693. { 1680, 945, 60, 0 },
  694. { 1920, 1080, 60, 0 },
  695. { 2048, 1152, 60, 0 },
  696. { 2048, 1536, 60, 0 },
  697. };
  698. /*
  699. * From CEA/CTA-861 spec.
  700. *
  701. * Do not access directly, instead always use cea_mode_for_vic().
  702. */
  703. static const struct drm_display_mode edid_cea_modes_1[] = {
  704. /* 1 - 640x480@60Hz 4:3 */
  705. { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
  706. 752, 800, 0, 480, 490, 492, 525, 0,
  707. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  708. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  709. /* 2 - 720x480@60Hz 4:3 */
  710. { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 27000, 720, 736,
  711. 798, 858, 0, 480, 489, 495, 525, 0,
  712. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  713. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  714. /* 3 - 720x480@60Hz 16:9 */
  715. { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 27000, 720, 736,
  716. 798, 858, 0, 480, 489, 495, 525, 0,
  717. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  718. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  719. /* 4 - 1280x720@60Hz 16:9 */
  720. { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1390,
  721. 1430, 1650, 0, 720, 725, 730, 750, 0,
  722. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  723. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  724. /* 5 - 1920x1080i@60Hz 16:9 */
  725. { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2008,
  726. 2052, 2200, 0, 1080, 1084, 1094, 1125, 0,
  727. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
  728. DRM_MODE_FLAG_INTERLACE),
  729. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  730. /* 6 - 720(1440)x480i@60Hz 4:3 */
  731. { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
  732. 801, 858, 0, 480, 488, 494, 525, 0,
  733. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
  734. DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
  735. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  736. /* 7 - 720(1440)x480i@60Hz 16:9 */
  737. { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
  738. 801, 858, 0, 480, 488, 494, 525, 0,
  739. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
  740. DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
  741. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  742. /* 8 - 720(1440)x240@60Hz 4:3 */
  743. { DRM_MODE("720x240", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
  744. 801, 858, 0, 240, 244, 247, 262, 0,
  745. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
  746. DRM_MODE_FLAG_DBLCLK),
  747. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  748. /* 9 - 720(1440)x240@60Hz 16:9 */
  749. { DRM_MODE("720x240", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
  750. 801, 858, 0, 240, 244, 247, 262, 0,
  751. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
  752. DRM_MODE_FLAG_DBLCLK),
  753. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  754. /* 10 - 2880x480i@60Hz 4:3 */
  755. { DRM_MODE("2880x480i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
  756. 3204, 3432, 0, 480, 488, 494, 525, 0,
  757. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
  758. DRM_MODE_FLAG_INTERLACE),
  759. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  760. /* 11 - 2880x480i@60Hz 16:9 */
  761. { DRM_MODE("2880x480i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
  762. 3204, 3432, 0, 480, 488, 494, 525, 0,
  763. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
  764. DRM_MODE_FLAG_INTERLACE),
  765. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  766. /* 12 - 2880x240@60Hz 4:3 */
  767. { DRM_MODE("2880x240", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
  768. 3204, 3432, 0, 240, 244, 247, 262, 0,
  769. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  770. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  771. /* 13 - 2880x240@60Hz 16:9 */
  772. { DRM_MODE("2880x240", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
  773. 3204, 3432, 0, 240, 244, 247, 262, 0,
  774. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  775. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  776. /* 14 - 1440x480@60Hz 4:3 */
  777. { DRM_MODE("1440x480", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1472,
  778. 1596, 1716, 0, 480, 489, 495, 525, 0,
  779. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  780. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  781. /* 15 - 1440x480@60Hz 16:9 */
  782. { DRM_MODE("1440x480", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1472,
  783. 1596, 1716, 0, 480, 489, 495, 525, 0,
  784. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  785. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  786. /* 16 - 1920x1080@60Hz 16:9 */
  787. { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
  788. 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
  789. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  790. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  791. /* 17 - 720x576@50Hz 4:3 */
  792. { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
  793. 796, 864, 0, 576, 581, 586, 625, 0,
  794. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  795. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  796. /* 18 - 720x576@50Hz 16:9 */
  797. { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
  798. 796, 864, 0, 576, 581, 586, 625, 0,
  799. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  800. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  801. /* 19 - 1280x720@50Hz 16:9 */
  802. { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1720,
  803. 1760, 1980, 0, 720, 725, 730, 750, 0,
  804. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  805. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  806. /* 20 - 1920x1080i@50Hz 16:9 */
  807. { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2448,
  808. 2492, 2640, 0, 1080, 1084, 1094, 1125, 0,
  809. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
  810. DRM_MODE_FLAG_INTERLACE),
  811. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  812. /* 21 - 720(1440)x576i@50Hz 4:3 */
  813. { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
  814. 795, 864, 0, 576, 580, 586, 625, 0,
  815. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
  816. DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
  817. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  818. /* 22 - 720(1440)x576i@50Hz 16:9 */
  819. { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
  820. 795, 864, 0, 576, 580, 586, 625, 0,
  821. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
  822. DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
  823. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  824. /* 23 - 720(1440)x288@50Hz 4:3 */
  825. { DRM_MODE("720x288", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
  826. 795, 864, 0, 288, 290, 293, 312, 0,
  827. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
  828. DRM_MODE_FLAG_DBLCLK),
  829. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  830. /* 24 - 720(1440)x288@50Hz 16:9 */
  831. { DRM_MODE("720x288", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
  832. 795, 864, 0, 288, 290, 293, 312, 0,
  833. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
  834. DRM_MODE_FLAG_DBLCLK),
  835. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  836. /* 25 - 2880x576i@50Hz 4:3 */
  837. { DRM_MODE("2880x576i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
  838. 3180, 3456, 0, 576, 580, 586, 625, 0,
  839. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
  840. DRM_MODE_FLAG_INTERLACE),
  841. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  842. /* 26 - 2880x576i@50Hz 16:9 */
  843. { DRM_MODE("2880x576i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
  844. 3180, 3456, 0, 576, 580, 586, 625, 0,
  845. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
  846. DRM_MODE_FLAG_INTERLACE),
  847. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  848. /* 27 - 2880x288@50Hz 4:3 */
  849. { DRM_MODE("2880x288", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
  850. 3180, 3456, 0, 288, 290, 293, 312, 0,
  851. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  852. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  853. /* 28 - 2880x288@50Hz 16:9 */
  854. { DRM_MODE("2880x288", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
  855. 3180, 3456, 0, 288, 290, 293, 312, 0,
  856. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  857. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  858. /* 29 - 1440x576@50Hz 4:3 */
  859. { DRM_MODE("1440x576", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1464,
  860. 1592, 1728, 0, 576, 581, 586, 625, 0,
  861. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  862. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  863. /* 30 - 1440x576@50Hz 16:9 */
  864. { DRM_MODE("1440x576", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1464,
  865. 1592, 1728, 0, 576, 581, 586, 625, 0,
  866. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  867. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  868. /* 31 - 1920x1080@50Hz 16:9 */
  869. { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2448,
  870. 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
  871. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  872. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  873. /* 32 - 1920x1080@24Hz 16:9 */
  874. { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2558,
  875. 2602, 2750, 0, 1080, 1084, 1089, 1125, 0,
  876. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  877. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  878. /* 33 - 1920x1080@25Hz 16:9 */
  879. { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2448,
  880. 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
  881. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  882. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  883. /* 34 - 1920x1080@30Hz 16:9 */
  884. { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2008,
  885. 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
  886. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  887. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  888. /* 35 - 2880x480@60Hz 4:3 */
  889. { DRM_MODE("2880x480", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2944,
  890. 3192, 3432, 0, 480, 489, 495, 525, 0,
  891. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  892. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  893. /* 36 - 2880x480@60Hz 16:9 */
  894. { DRM_MODE("2880x480", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2944,
  895. 3192, 3432, 0, 480, 489, 495, 525, 0,
  896. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  897. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  898. /* 37 - 2880x576@50Hz 4:3 */
  899. { DRM_MODE("2880x576", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2928,
  900. 3184, 3456, 0, 576, 581, 586, 625, 0,
  901. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  902. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  903. /* 38 - 2880x576@50Hz 16:9 */
  904. { DRM_MODE("2880x576", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2928,
  905. 3184, 3456, 0, 576, 581, 586, 625, 0,
  906. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  907. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  908. /* 39 - 1920x1080i@50Hz 16:9 */
  909. { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 72000, 1920, 1952,
  910. 2120, 2304, 0, 1080, 1126, 1136, 1250, 0,
  911. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC |
  912. DRM_MODE_FLAG_INTERLACE),
  913. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  914. /* 40 - 1920x1080i@100Hz 16:9 */
  915. { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2448,
  916. 2492, 2640, 0, 1080, 1084, 1094, 1125, 0,
  917. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
  918. DRM_MODE_FLAG_INTERLACE),
  919. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  920. /* 41 - 1280x720@100Hz 16:9 */
  921. { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1720,
  922. 1760, 1980, 0, 720, 725, 730, 750, 0,
  923. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  924. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  925. /* 42 - 720x576@100Hz 4:3 */
  926. { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
  927. 796, 864, 0, 576, 581, 586, 625, 0,
  928. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  929. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  930. /* 43 - 720x576@100Hz 16:9 */
  931. { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
  932. 796, 864, 0, 576, 581, 586, 625, 0,
  933. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  934. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  935. /* 44 - 720(1440)x576i@100Hz 4:3 */
  936. { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
  937. 795, 864, 0, 576, 580, 586, 625, 0,
  938. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
  939. DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
  940. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  941. /* 45 - 720(1440)x576i@100Hz 16:9 */
  942. { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
  943. 795, 864, 0, 576, 580, 586, 625, 0,
  944. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
  945. DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
  946. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  947. /* 46 - 1920x1080i@120Hz 16:9 */
  948. { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
  949. 2052, 2200, 0, 1080, 1084, 1094, 1125, 0,
  950. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
  951. DRM_MODE_FLAG_INTERLACE),
  952. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  953. /* 47 - 1280x720@120Hz 16:9 */
  954. { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1390,
  955. 1430, 1650, 0, 720, 725, 730, 750, 0,
  956. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  957. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  958. /* 48 - 720x480@120Hz 4:3 */
  959. { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 54000, 720, 736,
  960. 798, 858, 0, 480, 489, 495, 525, 0,
  961. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  962. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  963. /* 49 - 720x480@120Hz 16:9 */
  964. { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 54000, 720, 736,
  965. 798, 858, 0, 480, 489, 495, 525, 0,
  966. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  967. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  968. /* 50 - 720(1440)x480i@120Hz 4:3 */
  969. { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 27000, 720, 739,
  970. 801, 858, 0, 480, 488, 494, 525, 0,
  971. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
  972. DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
  973. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  974. /* 51 - 720(1440)x480i@120Hz 16:9 */
  975. { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 27000, 720, 739,
  976. 801, 858, 0, 480, 488, 494, 525, 0,
  977. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
  978. DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
  979. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  980. /* 52 - 720x576@200Hz 4:3 */
  981. { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 108000, 720, 732,
  982. 796, 864, 0, 576, 581, 586, 625, 0,
  983. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  984. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  985. /* 53 - 720x576@200Hz 16:9 */
  986. { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 108000, 720, 732,
  987. 796, 864, 0, 576, 581, 586, 625, 0,
  988. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  989. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  990. /* 54 - 720(1440)x576i@200Hz 4:3 */
  991. { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
  992. 795, 864, 0, 576, 580, 586, 625, 0,
  993. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
  994. DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
  995. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  996. /* 55 - 720(1440)x576i@200Hz 16:9 */
  997. { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
  998. 795, 864, 0, 576, 580, 586, 625, 0,
  999. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
  1000. DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
  1001. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  1002. /* 56 - 720x480@240Hz 4:3 */
  1003. { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 108000, 720, 736,
  1004. 798, 858, 0, 480, 489, 495, 525, 0,
  1005. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  1006. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  1007. /* 57 - 720x480@240Hz 16:9 */
  1008. { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 108000, 720, 736,
  1009. 798, 858, 0, 480, 489, 495, 525, 0,
  1010. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  1011. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  1012. /* 58 - 720(1440)x480i@240Hz 4:3 */
  1013. { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 54000, 720, 739,
  1014. 801, 858, 0, 480, 488, 494, 525, 0,
  1015. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
  1016. DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
  1017. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  1018. /* 59 - 720(1440)x480i@240Hz 16:9 */
  1019. { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 54000, 720, 739,
  1020. 801, 858, 0, 480, 488, 494, 525, 0,
  1021. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
  1022. DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
  1023. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  1024. /* 60 - 1280x720@24Hz 16:9 */
  1025. { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 59400, 1280, 3040,
  1026. 3080, 3300, 0, 720, 725, 730, 750, 0,
  1027. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1028. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  1029. /* 61 - 1280x720@25Hz 16:9 */
  1030. { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3700,
  1031. 3740, 3960, 0, 720, 725, 730, 750, 0,
  1032. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1033. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  1034. /* 62 - 1280x720@30Hz 16:9 */
  1035. { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3040,
  1036. 3080, 3300, 0, 720, 725, 730, 750, 0,
  1037. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1038. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  1039. /* 63 - 1920x1080@120Hz 16:9 */
  1040. { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2008,
  1041. 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
  1042. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1043. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  1044. /* 64 - 1920x1080@100Hz 16:9 */
  1045. { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2448,
  1046. 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
  1047. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1048. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  1049. /* 65 - 1280x720@24Hz 64:27 */
  1050. { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 59400, 1280, 3040,
  1051. 3080, 3300, 0, 720, 725, 730, 750, 0,
  1052. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1053. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1054. /* 66 - 1280x720@25Hz 64:27 */
  1055. { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3700,
  1056. 3740, 3960, 0, 720, 725, 730, 750, 0,
  1057. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1058. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1059. /* 67 - 1280x720@30Hz 64:27 */
  1060. { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3040,
  1061. 3080, 3300, 0, 720, 725, 730, 750, 0,
  1062. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1063. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1064. /* 68 - 1280x720@50Hz 64:27 */
  1065. { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1720,
  1066. 1760, 1980, 0, 720, 725, 730, 750, 0,
  1067. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1068. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1069. /* 69 - 1280x720@60Hz 64:27 */
  1070. { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1390,
  1071. 1430, 1650, 0, 720, 725, 730, 750, 0,
  1072. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1073. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1074. /* 70 - 1280x720@100Hz 64:27 */
  1075. { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1720,
  1076. 1760, 1980, 0, 720, 725, 730, 750, 0,
  1077. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1078. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1079. /* 71 - 1280x720@120Hz 64:27 */
  1080. { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1390,
  1081. 1430, 1650, 0, 720, 725, 730, 750, 0,
  1082. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1083. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1084. /* 72 - 1920x1080@24Hz 64:27 */
  1085. { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2558,
  1086. 2602, 2750, 0, 1080, 1084, 1089, 1125, 0,
  1087. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1088. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1089. /* 73 - 1920x1080@25Hz 64:27 */
  1090. { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2448,
  1091. 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
  1092. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1093. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1094. /* 74 - 1920x1080@30Hz 64:27 */
  1095. { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2008,
  1096. 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
  1097. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1098. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1099. /* 75 - 1920x1080@50Hz 64:27 */
  1100. { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2448,
  1101. 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
  1102. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1103. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1104. /* 76 - 1920x1080@60Hz 64:27 */
  1105. { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
  1106. 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
  1107. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1108. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1109. /* 77 - 1920x1080@100Hz 64:27 */
  1110. { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2448,
  1111. 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
  1112. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1113. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1114. /* 78 - 1920x1080@120Hz 64:27 */
  1115. { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2008,
  1116. 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
  1117. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1118. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1119. /* 79 - 1680x720@24Hz 64:27 */
  1120. { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 59400, 1680, 3040,
  1121. 3080, 3300, 0, 720, 725, 730, 750, 0,
  1122. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1123. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1124. /* 80 - 1680x720@25Hz 64:27 */
  1125. { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 59400, 1680, 2908,
  1126. 2948, 3168, 0, 720, 725, 730, 750, 0,
  1127. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1128. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1129. /* 81 - 1680x720@30Hz 64:27 */
  1130. { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 59400, 1680, 2380,
  1131. 2420, 2640, 0, 720, 725, 730, 750, 0,
  1132. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1133. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1134. /* 82 - 1680x720@50Hz 64:27 */
  1135. { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 82500, 1680, 1940,
  1136. 1980, 2200, 0, 720, 725, 730, 750, 0,
  1137. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1138. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1139. /* 83 - 1680x720@60Hz 64:27 */
  1140. { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 99000, 1680, 1940,
  1141. 1980, 2200, 0, 720, 725, 730, 750, 0,
  1142. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1143. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1144. /* 84 - 1680x720@100Hz 64:27 */
  1145. { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 165000, 1680, 1740,
  1146. 1780, 2000, 0, 720, 725, 730, 825, 0,
  1147. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1148. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1149. /* 85 - 1680x720@120Hz 64:27 */
  1150. { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 198000, 1680, 1740,
  1151. 1780, 2000, 0, 720, 725, 730, 825, 0,
  1152. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1153. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1154. /* 86 - 2560x1080@24Hz 64:27 */
  1155. { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 99000, 2560, 3558,
  1156. 3602, 3750, 0, 1080, 1084, 1089, 1100, 0,
  1157. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1158. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1159. /* 87 - 2560x1080@25Hz 64:27 */
  1160. { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 90000, 2560, 3008,
  1161. 3052, 3200, 0, 1080, 1084, 1089, 1125, 0,
  1162. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1163. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1164. /* 88 - 2560x1080@30Hz 64:27 */
  1165. { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 118800, 2560, 3328,
  1166. 3372, 3520, 0, 1080, 1084, 1089, 1125, 0,
  1167. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1168. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1169. /* 89 - 2560x1080@50Hz 64:27 */
  1170. { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 185625, 2560, 3108,
  1171. 3152, 3300, 0, 1080, 1084, 1089, 1125, 0,
  1172. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1173. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1174. /* 90 - 2560x1080@60Hz 64:27 */
  1175. { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 198000, 2560, 2808,
  1176. 2852, 3000, 0, 1080, 1084, 1089, 1100, 0,
  1177. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1178. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1179. /* 91 - 2560x1080@100Hz 64:27 */
  1180. { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 371250, 2560, 2778,
  1181. 2822, 2970, 0, 1080, 1084, 1089, 1250, 0,
  1182. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1183. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1184. /* 92 - 2560x1080@120Hz 64:27 */
  1185. { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 495000, 2560, 3108,
  1186. 3152, 3300, 0, 1080, 1084, 1089, 1250, 0,
  1187. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1188. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1189. /* 93 - 3840x2160@24Hz 16:9 */
  1190. { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 5116,
  1191. 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
  1192. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1193. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  1194. /* 94 - 3840x2160@25Hz 16:9 */
  1195. { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4896,
  1196. 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
  1197. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1198. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  1199. /* 95 - 3840x2160@30Hz 16:9 */
  1200. { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4016,
  1201. 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
  1202. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1203. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  1204. /* 96 - 3840x2160@50Hz 16:9 */
  1205. { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4896,
  1206. 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
  1207. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1208. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  1209. /* 97 - 3840x2160@60Hz 16:9 */
  1210. { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4016,
  1211. 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
  1212. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1213. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  1214. /* 98 - 4096x2160@24Hz 256:135 */
  1215. { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000, 4096, 5116,
  1216. 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
  1217. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1218. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
  1219. /* 99 - 4096x2160@25Hz 256:135 */
  1220. { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000, 4096, 5064,
  1221. 5152, 5280, 0, 2160, 2168, 2178, 2250, 0,
  1222. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1223. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
  1224. /* 100 - 4096x2160@30Hz 256:135 */
  1225. { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000, 4096, 4184,
  1226. 4272, 4400, 0, 2160, 2168, 2178, 2250, 0,
  1227. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1228. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
  1229. /* 101 - 4096x2160@50Hz 256:135 */
  1230. { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 594000, 4096, 5064,
  1231. 5152, 5280, 0, 2160, 2168, 2178, 2250, 0,
  1232. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1233. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
  1234. /* 102 - 4096x2160@60Hz 256:135 */
  1235. { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 594000, 4096, 4184,
  1236. 4272, 4400, 0, 2160, 2168, 2178, 2250, 0,
  1237. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1238. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
  1239. /* 103 - 3840x2160@24Hz 64:27 */
  1240. { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 5116,
  1241. 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
  1242. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1243. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1244. /* 104 - 3840x2160@25Hz 64:27 */
  1245. { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4896,
  1246. 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
  1247. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1248. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1249. /* 105 - 3840x2160@30Hz 64:27 */
  1250. { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4016,
  1251. 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
  1252. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1253. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1254. /* 106 - 3840x2160@50Hz 64:27 */
  1255. { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4896,
  1256. 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
  1257. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1258. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1259. /* 107 - 3840x2160@60Hz 64:27 */
  1260. { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4016,
  1261. 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
  1262. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1263. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1264. /* 108 - 1280x720@48Hz 16:9 */
  1265. { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 90000, 1280, 2240,
  1266. 2280, 2500, 0, 720, 725, 730, 750, 0,
  1267. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1268. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  1269. /* 109 - 1280x720@48Hz 64:27 */
  1270. { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 90000, 1280, 2240,
  1271. 2280, 2500, 0, 720, 725, 730, 750, 0,
  1272. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1273. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1274. /* 110 - 1680x720@48Hz 64:27 */
  1275. { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 99000, 1680, 2490,
  1276. 2530, 2750, 0, 720, 725, 730, 750, 0,
  1277. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1278. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1279. /* 111 - 1920x1080@48Hz 16:9 */
  1280. { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2558,
  1281. 2602, 2750, 0, 1080, 1084, 1089, 1125, 0,
  1282. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1283. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  1284. /* 112 - 1920x1080@48Hz 64:27 */
  1285. { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2558,
  1286. 2602, 2750, 0, 1080, 1084, 1089, 1125, 0,
  1287. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1288. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1289. /* 113 - 2560x1080@48Hz 64:27 */
  1290. { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 198000, 2560, 3558,
  1291. 3602, 3750, 0, 1080, 1084, 1089, 1100, 0,
  1292. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1293. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1294. /* 114 - 3840x2160@48Hz 16:9 */
  1295. { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 5116,
  1296. 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
  1297. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1298. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  1299. /* 115 - 4096x2160@48Hz 256:135 */
  1300. { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 594000, 4096, 5116,
  1301. 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
  1302. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1303. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
  1304. /* 116 - 3840x2160@48Hz 64:27 */
  1305. { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 5116,
  1306. 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
  1307. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1308. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1309. /* 117 - 3840x2160@100Hz 16:9 */
  1310. { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 1188000, 3840, 4896,
  1311. 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
  1312. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1313. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  1314. /* 118 - 3840x2160@120Hz 16:9 */
  1315. { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 1188000, 3840, 4016,
  1316. 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
  1317. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1318. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  1319. /* 119 - 3840x2160@100Hz 64:27 */
  1320. { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 1188000, 3840, 4896,
  1321. 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
  1322. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1323. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1324. /* 120 - 3840x2160@120Hz 64:27 */
  1325. { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 1188000, 3840, 4016,
  1326. 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
  1327. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1328. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1329. /* 121 - 5120x2160@24Hz 64:27 */
  1330. { DRM_MODE("5120x2160", DRM_MODE_TYPE_DRIVER, 396000, 5120, 7116,
  1331. 7204, 7500, 0, 2160, 2168, 2178, 2200, 0,
  1332. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1333. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1334. /* 122 - 5120x2160@25Hz 64:27 */
  1335. { DRM_MODE("5120x2160", DRM_MODE_TYPE_DRIVER, 396000, 5120, 6816,
  1336. 6904, 7200, 0, 2160, 2168, 2178, 2200, 0,
  1337. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1338. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1339. /* 123 - 5120x2160@30Hz 64:27 */
  1340. { DRM_MODE("5120x2160", DRM_MODE_TYPE_DRIVER, 396000, 5120, 5784,
  1341. 5872, 6000, 0, 2160, 2168, 2178, 2200, 0,
  1342. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1343. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1344. /* 124 - 5120x2160@48Hz 64:27 */
  1345. { DRM_MODE("5120x2160", DRM_MODE_TYPE_DRIVER, 742500, 5120, 5866,
  1346. 5954, 6250, 0, 2160, 2168, 2178, 2475, 0,
  1347. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1348. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1349. /* 125 - 5120x2160@50Hz 64:27 */
  1350. { DRM_MODE("5120x2160", DRM_MODE_TYPE_DRIVER, 742500, 5120, 6216,
  1351. 6304, 6600, 0, 2160, 2168, 2178, 2250, 0,
  1352. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1353. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1354. /* 126 - 5120x2160@60Hz 64:27 */
  1355. { DRM_MODE("5120x2160", DRM_MODE_TYPE_DRIVER, 742500, 5120, 5284,
  1356. 5372, 5500, 0, 2160, 2168, 2178, 2250, 0,
  1357. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1358. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1359. /* 127 - 5120x2160@100Hz 64:27 */
  1360. { DRM_MODE("5120x2160", DRM_MODE_TYPE_DRIVER, 1485000, 5120, 6216,
  1361. 6304, 6600, 0, 2160, 2168, 2178, 2250, 0,
  1362. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1363. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1364. };
  1365. /*
  1366. * From CEA/CTA-861 spec.
  1367. *
  1368. * Do not access directly, instead always use cea_mode_for_vic().
  1369. */
  1370. static const struct drm_display_mode edid_cea_modes_193[] = {
  1371. /* 193 - 5120x2160@120Hz 64:27 */
  1372. { DRM_MODE("5120x2160", DRM_MODE_TYPE_DRIVER, 1485000, 5120, 5284,
  1373. 5372, 5500, 0, 2160, 2168, 2178, 2250, 0,
  1374. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1375. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1376. /* 194 - 7680x4320@24Hz 16:9 */
  1377. { DRM_MODE("7680x4320", DRM_MODE_TYPE_DRIVER, 1188000, 7680, 10232,
  1378. 10408, 11000, 0, 4320, 4336, 4356, 4500, 0,
  1379. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1380. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  1381. /* 195 - 7680x4320@25Hz 16:9 */
  1382. { DRM_MODE("7680x4320", DRM_MODE_TYPE_DRIVER, 1188000, 7680, 10032,
  1383. 10208, 10800, 0, 4320, 4336, 4356, 4400, 0,
  1384. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1385. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  1386. /* 196 - 7680x4320@30Hz 16:9 */
  1387. { DRM_MODE("7680x4320", DRM_MODE_TYPE_DRIVER, 1188000, 7680, 8232,
  1388. 8408, 9000, 0, 4320, 4336, 4356, 4400, 0,
  1389. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1390. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  1391. /* 197 - 7680x4320@48Hz 16:9 */
  1392. { DRM_MODE("7680x4320", DRM_MODE_TYPE_DRIVER, 2376000, 7680, 10232,
  1393. 10408, 11000, 0, 4320, 4336, 4356, 4500, 0,
  1394. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1395. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  1396. /* 198 - 7680x4320@50Hz 16:9 */
  1397. { DRM_MODE("7680x4320", DRM_MODE_TYPE_DRIVER, 2376000, 7680, 10032,
  1398. 10208, 10800, 0, 4320, 4336, 4356, 4400, 0,
  1399. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1400. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  1401. /* 199 - 7680x4320@60Hz 16:9 */
  1402. { DRM_MODE("7680x4320", DRM_MODE_TYPE_DRIVER, 2376000, 7680, 8232,
  1403. 8408, 9000, 0, 4320, 4336, 4356, 4400, 0,
  1404. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1405. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  1406. /* 200 - 7680x4320@100Hz 16:9 */
  1407. { DRM_MODE("7680x4320", DRM_MODE_TYPE_DRIVER, 4752000, 7680, 9792,
  1408. 9968, 10560, 0, 4320, 4336, 4356, 4500, 0,
  1409. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1410. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  1411. /* 201 - 7680x4320@120Hz 16:9 */
  1412. { DRM_MODE("7680x4320", DRM_MODE_TYPE_DRIVER, 4752000, 7680, 8032,
  1413. 8208, 8800, 0, 4320, 4336, 4356, 4500, 0,
  1414. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1415. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  1416. /* 202 - 7680x4320@24Hz 64:27 */
  1417. { DRM_MODE("7680x4320", DRM_MODE_TYPE_DRIVER, 1188000, 7680, 10232,
  1418. 10408, 11000, 0, 4320, 4336, 4356, 4500, 0,
  1419. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1420. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1421. /* 203 - 7680x4320@25Hz 64:27 */
  1422. { DRM_MODE("7680x4320", DRM_MODE_TYPE_DRIVER, 1188000, 7680, 10032,
  1423. 10208, 10800, 0, 4320, 4336, 4356, 4400, 0,
  1424. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1425. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1426. /* 204 - 7680x4320@30Hz 64:27 */
  1427. { DRM_MODE("7680x4320", DRM_MODE_TYPE_DRIVER, 1188000, 7680, 8232,
  1428. 8408, 9000, 0, 4320, 4336, 4356, 4400, 0,
  1429. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1430. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1431. /* 205 - 7680x4320@48Hz 64:27 */
  1432. { DRM_MODE("7680x4320", DRM_MODE_TYPE_DRIVER, 2376000, 7680, 10232,
  1433. 10408, 11000, 0, 4320, 4336, 4356, 4500, 0,
  1434. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1435. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1436. /* 206 - 7680x4320@50Hz 64:27 */
  1437. { DRM_MODE("7680x4320", DRM_MODE_TYPE_DRIVER, 2376000, 7680, 10032,
  1438. 10208, 10800, 0, 4320, 4336, 4356, 4400, 0,
  1439. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1440. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1441. /* 207 - 7680x4320@60Hz 64:27 */
  1442. { DRM_MODE("7680x4320", DRM_MODE_TYPE_DRIVER, 2376000, 7680, 8232,
  1443. 8408, 9000, 0, 4320, 4336, 4356, 4400, 0,
  1444. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1445. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1446. /* 208 - 7680x4320@100Hz 64:27 */
  1447. { DRM_MODE("7680x4320", DRM_MODE_TYPE_DRIVER, 4752000, 7680, 9792,
  1448. 9968, 10560, 0, 4320, 4336, 4356, 4500, 0,
  1449. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1450. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1451. /* 209 - 7680x4320@120Hz 64:27 */
  1452. { DRM_MODE("7680x4320", DRM_MODE_TYPE_DRIVER, 4752000, 7680, 8032,
  1453. 8208, 8800, 0, 4320, 4336, 4356, 4500, 0,
  1454. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1455. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1456. /* 210 - 10240x4320@24Hz 64:27 */
  1457. { DRM_MODE("10240x4320", DRM_MODE_TYPE_DRIVER, 1485000, 10240, 11732,
  1458. 11908, 12500, 0, 4320, 4336, 4356, 4950, 0,
  1459. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1460. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1461. /* 211 - 10240x4320@25Hz 64:27 */
  1462. { DRM_MODE("10240x4320", DRM_MODE_TYPE_DRIVER, 1485000, 10240, 12732,
  1463. 12908, 13500, 0, 4320, 4336, 4356, 4400, 0,
  1464. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1465. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1466. /* 212 - 10240x4320@30Hz 64:27 */
  1467. { DRM_MODE("10240x4320", DRM_MODE_TYPE_DRIVER, 1485000, 10240, 10528,
  1468. 10704, 11000, 0, 4320, 4336, 4356, 4500, 0,
  1469. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1470. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1471. /* 213 - 10240x4320@48Hz 64:27 */
  1472. { DRM_MODE("10240x4320", DRM_MODE_TYPE_DRIVER, 2970000, 10240, 11732,
  1473. 11908, 12500, 0, 4320, 4336, 4356, 4950, 0,
  1474. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1475. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1476. /* 214 - 10240x4320@50Hz 64:27 */
  1477. { DRM_MODE("10240x4320", DRM_MODE_TYPE_DRIVER, 2970000, 10240, 12732,
  1478. 12908, 13500, 0, 4320, 4336, 4356, 4400, 0,
  1479. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1480. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1481. /* 215 - 10240x4320@60Hz 64:27 */
  1482. { DRM_MODE("10240x4320", DRM_MODE_TYPE_DRIVER, 2970000, 10240, 10528,
  1483. 10704, 11000, 0, 4320, 4336, 4356, 4500, 0,
  1484. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1485. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1486. /* 216 - 10240x4320@100Hz 64:27 */
  1487. { DRM_MODE("10240x4320", DRM_MODE_TYPE_DRIVER, 5940000, 10240, 12432,
  1488. 12608, 13200, 0, 4320, 4336, 4356, 4500, 0,
  1489. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1490. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1491. /* 217 - 10240x4320@120Hz 64:27 */
  1492. { DRM_MODE("10240x4320", DRM_MODE_TYPE_DRIVER, 5940000, 10240, 10528,
  1493. 10704, 11000, 0, 4320, 4336, 4356, 4500, 0,
  1494. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1495. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1496. /* 218 - 4096x2160@100Hz 256:135 */
  1497. { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 1188000, 4096, 4896,
  1498. 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
  1499. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1500. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
  1501. /* 219 - 4096x2160@120Hz 256:135 */
  1502. { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 1188000, 4096, 4184,
  1503. 4272, 4400, 0, 2160, 2168, 2178, 2250, 0,
  1504. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1505. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
  1506. };
  1507. /*
  1508. * HDMI 1.4 4k modes. Index using the VIC.
  1509. */
  1510. static const struct drm_display_mode edid_4k_modes[] = {
  1511. /* 0 - dummy, VICs start at 1 */
  1512. { },
  1513. /* 1 - 3840x2160@30Hz */
  1514. { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
  1515. 3840, 4016, 4104, 4400, 0,
  1516. 2160, 2168, 2178, 2250, 0,
  1517. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1518. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  1519. /* 2 - 3840x2160@25Hz */
  1520. { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
  1521. 3840, 4896, 4984, 5280, 0,
  1522. 2160, 2168, 2178, 2250, 0,
  1523. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1524. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  1525. /* 3 - 3840x2160@24Hz */
  1526. { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
  1527. 3840, 5116, 5204, 5500, 0,
  1528. 2160, 2168, 2178, 2250, 0,
  1529. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1530. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  1531. /* 4 - 4096x2160@24Hz (SMPTE) */
  1532. { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000,
  1533. 4096, 5116, 5204, 5500, 0,
  1534. 2160, 2168, 2178, 2250, 0,
  1535. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1536. .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
  1537. };
  1538. /*** DDC fetch and block validation ***/
  1539. /*
  1540. * The opaque EDID type, internal to drm_edid.c.
  1541. */
  1542. struct drm_edid {
  1543. /* Size allocated for edid */
  1544. size_t size;
  1545. const struct edid *edid;
  1546. };
  1547. static int edid_hfeeodb_extension_block_count(const struct edid *edid);
  1548. static int edid_hfeeodb_block_count(const struct edid *edid)
  1549. {
  1550. int eeodb = edid_hfeeodb_extension_block_count(edid);
  1551. return eeodb ? eeodb + 1 : 0;
  1552. }
  1553. static int edid_extension_block_count(const struct edid *edid)
  1554. {
  1555. return edid->extensions;
  1556. }
  1557. static int edid_block_count(const struct edid *edid)
  1558. {
  1559. return edid_extension_block_count(edid) + 1;
  1560. }
  1561. static int edid_size_by_blocks(int num_blocks)
  1562. {
  1563. return num_blocks * EDID_LENGTH;
  1564. }
  1565. static int edid_size(const struct edid *edid)
  1566. {
  1567. return edid_size_by_blocks(edid_block_count(edid));
  1568. }
  1569. static const void *edid_block_data(const struct edid *edid, int index)
  1570. {
  1571. BUILD_BUG_ON(sizeof(*edid) != EDID_LENGTH);
  1572. return edid + index;
  1573. }
  1574. static const void *edid_extension_block_data(const struct edid *edid, int index)
  1575. {
  1576. return edid_block_data(edid, index + 1);
  1577. }
  1578. /* EDID block count indicated in EDID, may exceed allocated size */
  1579. static int __drm_edid_block_count(const struct drm_edid *drm_edid)
  1580. {
  1581. int num_blocks;
  1582. /* Starting point */
  1583. num_blocks = edid_block_count(drm_edid->edid);
  1584. /* HF-EEODB override */
  1585. if (drm_edid->size >= edid_size_by_blocks(2)) {
  1586. int eeodb;
  1587. /*
  1588. * Note: HF-EEODB may specify a smaller extension count than the
  1589. * regular one. Unlike in buffer allocation, here we can use it.
  1590. */
  1591. eeodb = edid_hfeeodb_block_count(drm_edid->edid);
  1592. if (eeodb)
  1593. num_blocks = eeodb;
  1594. }
  1595. return num_blocks;
  1596. }
  1597. /* EDID block count, limited by allocated size */
  1598. static int drm_edid_block_count(const struct drm_edid *drm_edid)
  1599. {
  1600. /* Limit by allocated size */
  1601. return min(__drm_edid_block_count(drm_edid),
  1602. (int)drm_edid->size / EDID_LENGTH);
  1603. }
  1604. /* EDID extension block count, limited by allocated size */
  1605. static int drm_edid_extension_block_count(const struct drm_edid *drm_edid)
  1606. {
  1607. return drm_edid_block_count(drm_edid) - 1;
  1608. }
  1609. static const void *drm_edid_block_data(const struct drm_edid *drm_edid, int index)
  1610. {
  1611. return edid_block_data(drm_edid->edid, index);
  1612. }
  1613. static const void *drm_edid_extension_block_data(const struct drm_edid *drm_edid,
  1614. int index)
  1615. {
  1616. return edid_extension_block_data(drm_edid->edid, index);
  1617. }
  1618. /*
  1619. * Initializer helper for legacy interfaces, where we have no choice but to
  1620. * trust edid size. Not for general purpose use.
  1621. */
  1622. static const struct drm_edid *drm_edid_legacy_init(struct drm_edid *drm_edid,
  1623. const struct edid *edid)
  1624. {
  1625. if (!edid)
  1626. return NULL;
  1627. memset(drm_edid, 0, sizeof(*drm_edid));
  1628. drm_edid->edid = edid;
  1629. drm_edid->size = edid_size(edid);
  1630. return drm_edid;
  1631. }
  1632. /*
  1633. * EDID base and extension block iterator.
  1634. *
  1635. * struct drm_edid_iter iter;
  1636. * const u8 *block;
  1637. *
  1638. * drm_edid_iter_begin(drm_edid, &iter);
  1639. * drm_edid_iter_for_each(block, &iter) {
  1640. * // do stuff with block
  1641. * }
  1642. * drm_edid_iter_end(&iter);
  1643. */
  1644. struct drm_edid_iter {
  1645. const struct drm_edid *drm_edid;
  1646. /* Current block index. */
  1647. int index;
  1648. };
  1649. static void drm_edid_iter_begin(const struct drm_edid *drm_edid,
  1650. struct drm_edid_iter *iter)
  1651. {
  1652. memset(iter, 0, sizeof(*iter));
  1653. iter->drm_edid = drm_edid;
  1654. }
  1655. static const void *__drm_edid_iter_next(struct drm_edid_iter *iter)
  1656. {
  1657. const void *block = NULL;
  1658. if (!iter->drm_edid)
  1659. return NULL;
  1660. if (iter->index < drm_edid_block_count(iter->drm_edid))
  1661. block = drm_edid_block_data(iter->drm_edid, iter->index++);
  1662. return block;
  1663. }
  1664. #define drm_edid_iter_for_each(__block, __iter) \
  1665. while (((__block) = __drm_edid_iter_next(__iter)))
  1666. static void drm_edid_iter_end(struct drm_edid_iter *iter)
  1667. {
  1668. memset(iter, 0, sizeof(*iter));
  1669. }
  1670. static const u8 edid_header[] = {
  1671. 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00
  1672. };
  1673. static void edid_header_fix(void *edid)
  1674. {
  1675. memcpy(edid, edid_header, sizeof(edid_header));
  1676. }
  1677. /**
  1678. * drm_edid_header_is_valid - sanity check the header of the base EDID block
  1679. * @_edid: pointer to raw base EDID block
  1680. *
  1681. * Sanity check the header of the base EDID block.
  1682. *
  1683. * Return: 8 if the header is perfect, down to 0 if it's totally wrong.
  1684. */
  1685. int drm_edid_header_is_valid(const void *_edid)
  1686. {
  1687. const struct edid *edid = _edid;
  1688. int i, score = 0;
  1689. for (i = 0; i < sizeof(edid_header); i++) {
  1690. if (edid->header[i] == edid_header[i])
  1691. score++;
  1692. }
  1693. return score;
  1694. }
  1695. EXPORT_SYMBOL(drm_edid_header_is_valid);
  1696. static int edid_fixup __read_mostly = 6;
  1697. module_param_named(edid_fixup, edid_fixup, int, 0400);
  1698. MODULE_PARM_DESC(edid_fixup,
  1699. "Minimum number of valid EDID header bytes (0-8, default 6)");
  1700. static int edid_block_compute_checksum(const void *_block)
  1701. {
  1702. const u8 *block = _block;
  1703. int i;
  1704. u8 csum = 0, crc = 0;
  1705. for (i = 0; i < EDID_LENGTH - 1; i++)
  1706. csum += block[i];
  1707. crc = 0x100 - csum;
  1708. return crc;
  1709. }
  1710. static int edid_block_get_checksum(const void *_block)
  1711. {
  1712. const struct edid *block = _block;
  1713. return block->checksum;
  1714. }
  1715. static int edid_block_tag(const void *_block)
  1716. {
  1717. const u8 *block = _block;
  1718. return block[0];
  1719. }
  1720. static bool edid_block_is_zero(const void *edid)
  1721. {
  1722. return mem_is_zero(edid, EDID_LENGTH);
  1723. }
  1724. static bool drm_edid_eq(const struct drm_edid *drm_edid,
  1725. const void *raw_edid, size_t raw_edid_size)
  1726. {
  1727. bool edid1_present = drm_edid && drm_edid->edid && drm_edid->size;
  1728. bool edid2_present = raw_edid && raw_edid_size;
  1729. if (edid1_present != edid2_present)
  1730. return false;
  1731. if (edid1_present) {
  1732. if (drm_edid->size != raw_edid_size)
  1733. return false;
  1734. if (memcmp(drm_edid->edid, raw_edid, drm_edid->size))
  1735. return false;
  1736. }
  1737. return true;
  1738. }
  1739. enum edid_block_status {
  1740. EDID_BLOCK_OK = 0,
  1741. EDID_BLOCK_READ_FAIL,
  1742. EDID_BLOCK_NULL,
  1743. EDID_BLOCK_ZERO,
  1744. EDID_BLOCK_HEADER_CORRUPT,
  1745. EDID_BLOCK_HEADER_REPAIR,
  1746. EDID_BLOCK_HEADER_FIXED,
  1747. EDID_BLOCK_CHECKSUM,
  1748. EDID_BLOCK_VERSION,
  1749. };
  1750. static enum edid_block_status edid_block_check(const void *_block,
  1751. bool is_base_block)
  1752. {
  1753. const struct edid *block = _block;
  1754. if (!block)
  1755. return EDID_BLOCK_NULL;
  1756. if (is_base_block) {
  1757. int score = drm_edid_header_is_valid(block);
  1758. if (score < clamp(edid_fixup, 0, 8)) {
  1759. if (edid_block_is_zero(block))
  1760. return EDID_BLOCK_ZERO;
  1761. else
  1762. return EDID_BLOCK_HEADER_CORRUPT;
  1763. }
  1764. if (score < 8)
  1765. return EDID_BLOCK_HEADER_REPAIR;
  1766. }
  1767. if (edid_block_compute_checksum(block) != edid_block_get_checksum(block)) {
  1768. if (edid_block_is_zero(block))
  1769. return EDID_BLOCK_ZERO;
  1770. else
  1771. return EDID_BLOCK_CHECKSUM;
  1772. }
  1773. if (is_base_block) {
  1774. if (block->version != 1)
  1775. return EDID_BLOCK_VERSION;
  1776. }
  1777. return EDID_BLOCK_OK;
  1778. }
  1779. static bool edid_block_status_valid(enum edid_block_status status, int tag)
  1780. {
  1781. return status == EDID_BLOCK_OK ||
  1782. status == EDID_BLOCK_HEADER_FIXED ||
  1783. (status == EDID_BLOCK_CHECKSUM && tag == CEA_EXT);
  1784. }
  1785. static bool edid_block_valid(const void *block, bool base)
  1786. {
  1787. return edid_block_status_valid(edid_block_check(block, base),
  1788. edid_block_tag(block));
  1789. }
  1790. static void edid_block_status_print(enum edid_block_status status,
  1791. const struct edid *block,
  1792. int block_num)
  1793. {
  1794. switch (status) {
  1795. case EDID_BLOCK_OK:
  1796. break;
  1797. case EDID_BLOCK_READ_FAIL:
  1798. pr_debug("EDID block %d read failed\n", block_num);
  1799. break;
  1800. case EDID_BLOCK_NULL:
  1801. pr_debug("EDID block %d pointer is NULL\n", block_num);
  1802. break;
  1803. case EDID_BLOCK_ZERO:
  1804. pr_notice("EDID block %d is all zeroes\n", block_num);
  1805. break;
  1806. case EDID_BLOCK_HEADER_CORRUPT:
  1807. pr_notice("EDID has corrupt header\n");
  1808. break;
  1809. case EDID_BLOCK_HEADER_REPAIR:
  1810. pr_debug("EDID corrupt header needs repair\n");
  1811. break;
  1812. case EDID_BLOCK_HEADER_FIXED:
  1813. pr_debug("EDID corrupt header fixed\n");
  1814. break;
  1815. case EDID_BLOCK_CHECKSUM:
  1816. if (edid_block_status_valid(status, edid_block_tag(block))) {
  1817. pr_debug("EDID block %d (tag 0x%02x) checksum is invalid, remainder is %d, ignoring\n",
  1818. block_num, edid_block_tag(block),
  1819. edid_block_compute_checksum(block));
  1820. } else {
  1821. pr_notice("EDID block %d (tag 0x%02x) checksum is invalid, remainder is %d\n",
  1822. block_num, edid_block_tag(block),
  1823. edid_block_compute_checksum(block));
  1824. }
  1825. break;
  1826. case EDID_BLOCK_VERSION:
  1827. pr_notice("EDID has major version %d, instead of 1\n",
  1828. block->version);
  1829. break;
  1830. default:
  1831. WARN(1, "EDID block %d unknown edid block status code %d\n",
  1832. block_num, status);
  1833. break;
  1834. }
  1835. }
  1836. static void edid_block_dump(const char *level, const void *block, int block_num)
  1837. {
  1838. enum edid_block_status status;
  1839. char prefix[20];
  1840. status = edid_block_check(block, block_num == 0);
  1841. if (status == EDID_BLOCK_ZERO)
  1842. sprintf(prefix, "\t[%02x] ZERO ", block_num);
  1843. else if (!edid_block_status_valid(status, edid_block_tag(block)))
  1844. sprintf(prefix, "\t[%02x] BAD ", block_num);
  1845. else
  1846. sprintf(prefix, "\t[%02x] GOOD ", block_num);
  1847. print_hex_dump(level, prefix, DUMP_PREFIX_NONE, 16, 1,
  1848. block, EDID_LENGTH, false);
  1849. }
  1850. /*
  1851. * Validate a base or extension EDID block and optionally dump bad blocks to
  1852. * the console.
  1853. */
  1854. static bool drm_edid_block_valid(void *_block, int block_num, bool print_bad_edid,
  1855. bool *edid_corrupt)
  1856. {
  1857. struct edid *block = _block;
  1858. enum edid_block_status status;
  1859. bool is_base_block = block_num == 0;
  1860. bool valid;
  1861. if (WARN_ON(!block))
  1862. return false;
  1863. status = edid_block_check(block, is_base_block);
  1864. if (status == EDID_BLOCK_HEADER_REPAIR) {
  1865. DRM_DEBUG_KMS("Fixing EDID header, your hardware may be failing\n");
  1866. edid_header_fix(block);
  1867. /* Retry with fixed header, update status if that worked. */
  1868. status = edid_block_check(block, is_base_block);
  1869. if (status == EDID_BLOCK_OK)
  1870. status = EDID_BLOCK_HEADER_FIXED;
  1871. }
  1872. if (edid_corrupt) {
  1873. /*
  1874. * Unknown major version isn't corrupt but we can't use it. Only
  1875. * the base block can reset edid_corrupt to false.
  1876. */
  1877. if (is_base_block &&
  1878. (status == EDID_BLOCK_OK || status == EDID_BLOCK_VERSION))
  1879. *edid_corrupt = false;
  1880. else if (status != EDID_BLOCK_OK)
  1881. *edid_corrupt = true;
  1882. }
  1883. edid_block_status_print(status, block, block_num);
  1884. /* Determine whether we can use this block with this status. */
  1885. valid = edid_block_status_valid(status, edid_block_tag(block));
  1886. if (!valid && print_bad_edid && status != EDID_BLOCK_ZERO) {
  1887. pr_notice("Raw EDID:\n");
  1888. edid_block_dump(KERN_NOTICE, block, block_num);
  1889. }
  1890. return valid;
  1891. }
  1892. /**
  1893. * drm_edid_is_valid - sanity check EDID data
  1894. * @edid: EDID data
  1895. *
  1896. * Sanity-check an entire EDID record (including extensions)
  1897. *
  1898. * Return: True if the EDID data is valid, false otherwise.
  1899. */
  1900. bool drm_edid_is_valid(struct edid *edid)
  1901. {
  1902. int i;
  1903. if (!edid)
  1904. return false;
  1905. for (i = 0; i < edid_block_count(edid); i++) {
  1906. void *block = (void *)edid_block_data(edid, i);
  1907. if (!drm_edid_block_valid(block, i, true, NULL))
  1908. return false;
  1909. }
  1910. return true;
  1911. }
  1912. EXPORT_SYMBOL(drm_edid_is_valid);
  1913. /**
  1914. * drm_edid_valid - sanity check EDID data
  1915. * @drm_edid: EDID data
  1916. *
  1917. * Sanity check an EDID. Cross check block count against allocated size and
  1918. * checksum the blocks.
  1919. *
  1920. * Return: True if the EDID data is valid, false otherwise.
  1921. */
  1922. bool drm_edid_valid(const struct drm_edid *drm_edid)
  1923. {
  1924. int i;
  1925. if (!drm_edid)
  1926. return false;
  1927. if (edid_size_by_blocks(__drm_edid_block_count(drm_edid)) != drm_edid->size)
  1928. return false;
  1929. for (i = 0; i < drm_edid_block_count(drm_edid); i++) {
  1930. const void *block = drm_edid_block_data(drm_edid, i);
  1931. if (!edid_block_valid(block, i == 0))
  1932. return false;
  1933. }
  1934. return true;
  1935. }
  1936. EXPORT_SYMBOL(drm_edid_valid);
  1937. static struct edid *edid_filter_invalid_blocks(struct edid *edid,
  1938. size_t *alloc_size)
  1939. {
  1940. struct edid *new;
  1941. int i, valid_blocks = 0;
  1942. /*
  1943. * Note: If the EDID uses HF-EEODB, but has invalid blocks, we'll revert
  1944. * back to regular extension count here. We don't want to start
  1945. * modifying the HF-EEODB extension too.
  1946. */
  1947. for (i = 0; i < edid_block_count(edid); i++) {
  1948. const void *src_block = edid_block_data(edid, i);
  1949. if (edid_block_valid(src_block, i == 0)) {
  1950. void *dst_block = (void *)edid_block_data(edid, valid_blocks);
  1951. memmove(dst_block, src_block, EDID_LENGTH);
  1952. valid_blocks++;
  1953. }
  1954. }
  1955. /* We already trusted the base block to be valid here... */
  1956. if (WARN_ON(!valid_blocks)) {
  1957. kfree(edid);
  1958. return NULL;
  1959. }
  1960. edid->extensions = valid_blocks - 1;
  1961. edid->checksum = edid_block_compute_checksum(edid);
  1962. *alloc_size = edid_size_by_blocks(valid_blocks);
  1963. new = krealloc(edid, *alloc_size, GFP_KERNEL);
  1964. if (!new)
  1965. kfree(edid);
  1966. return new;
  1967. }
  1968. #define DDC_SEGMENT_ADDR 0x30
  1969. /**
  1970. * drm_do_probe_ddc_edid() - get EDID information via I2C
  1971. * @data: I2C device adapter
  1972. * @buf: EDID data buffer to be filled
  1973. * @block: 128 byte EDID block to start fetching from
  1974. * @len: EDID data buffer length to fetch
  1975. *
  1976. * Try to fetch EDID information by calling I2C driver functions.
  1977. *
  1978. * Return: 0 on success or -1 on failure.
  1979. */
  1980. static int
  1981. drm_do_probe_ddc_edid(void *data, u8 *buf, unsigned int block, size_t len)
  1982. {
  1983. struct i2c_adapter *adapter = data;
  1984. unsigned char start = block * EDID_LENGTH;
  1985. unsigned char segment = block >> 1;
  1986. unsigned char xfers = segment ? 3 : 2;
  1987. int ret, retries = 5;
  1988. /*
  1989. * The core I2C driver will automatically retry the transfer if the
  1990. * adapter reports EAGAIN. However, we find that bit-banging transfers
  1991. * are susceptible to errors under a heavily loaded machine and
  1992. * generate spurious NAKs and timeouts. Retrying the transfer
  1993. * of the individual block a few times seems to overcome this.
  1994. */
  1995. do {
  1996. struct i2c_msg msgs[] = {
  1997. {
  1998. .addr = DDC_SEGMENT_ADDR,
  1999. .flags = 0,
  2000. .len = 1,
  2001. .buf = &segment,
  2002. }, {
  2003. .addr = DDC_ADDR,
  2004. .flags = 0,
  2005. .len = 1,
  2006. .buf = &start,
  2007. }, {
  2008. .addr = DDC_ADDR,
  2009. .flags = I2C_M_RD,
  2010. .len = len,
  2011. .buf = buf,
  2012. }
  2013. };
  2014. /*
  2015. * Avoid sending the segment addr to not upset non-compliant
  2016. * DDC monitors.
  2017. */
  2018. ret = i2c_transfer(adapter, &msgs[3 - xfers], xfers);
  2019. if (ret == -ENXIO) {
  2020. DRM_DEBUG_KMS("drm: skipping non-existent adapter %s\n",
  2021. adapter->name);
  2022. break;
  2023. }
  2024. } while (ret != xfers && --retries);
  2025. return ret == xfers ? 0 : -1;
  2026. }
  2027. static void connector_bad_edid(struct drm_connector *connector,
  2028. const struct edid *edid, int num_blocks)
  2029. {
  2030. int i;
  2031. u8 last_block;
  2032. /*
  2033. * 0x7e in the EDID is the number of extension blocks. The EDID
  2034. * is 1 (base block) + num_ext_blocks big. That means we can think
  2035. * of 0x7e in the EDID of the _index_ of the last block in the
  2036. * combined chunk of memory.
  2037. */
  2038. last_block = edid->extensions;
  2039. /* Calculate real checksum for the last edid extension block data */
  2040. if (last_block < num_blocks)
  2041. connector->real_edid_checksum =
  2042. edid_block_compute_checksum(edid + last_block);
  2043. if (connector->bad_edid_counter++ && !drm_debug_enabled(DRM_UT_KMS))
  2044. return;
  2045. drm_dbg_kms(connector->dev, "[CONNECTOR:%d:%s] EDID is invalid:\n",
  2046. connector->base.id, connector->name);
  2047. for (i = 0; i < num_blocks; i++)
  2048. edid_block_dump(KERN_DEBUG, edid + i, i);
  2049. }
  2050. /* Get override or firmware EDID */
  2051. static const struct drm_edid *drm_edid_override_get(struct drm_connector *connector)
  2052. {
  2053. const struct drm_edid *override = NULL;
  2054. mutex_lock(&connector->edid_override_mutex);
  2055. if (connector->edid_override)
  2056. override = drm_edid_dup(connector->edid_override);
  2057. mutex_unlock(&connector->edid_override_mutex);
  2058. if (!override)
  2059. override = drm_edid_load_firmware(connector);
  2060. return IS_ERR(override) ? NULL : override;
  2061. }
  2062. /* For debugfs edid_override implementation */
  2063. int drm_edid_override_show(struct drm_connector *connector, struct seq_file *m)
  2064. {
  2065. const struct drm_edid *drm_edid;
  2066. mutex_lock(&connector->edid_override_mutex);
  2067. drm_edid = connector->edid_override;
  2068. if (drm_edid)
  2069. seq_write(m, drm_edid->edid, drm_edid->size);
  2070. mutex_unlock(&connector->edid_override_mutex);
  2071. return 0;
  2072. }
  2073. /* For debugfs edid_override implementation */
  2074. int drm_edid_override_set(struct drm_connector *connector, const void *edid,
  2075. size_t size)
  2076. {
  2077. const struct drm_edid *drm_edid;
  2078. drm_edid = drm_edid_alloc(edid, size);
  2079. if (!drm_edid_valid(drm_edid)) {
  2080. drm_dbg_kms(connector->dev, "[CONNECTOR:%d:%s] EDID override invalid\n",
  2081. connector->base.id, connector->name);
  2082. drm_edid_free(drm_edid);
  2083. return -EINVAL;
  2084. }
  2085. drm_dbg_kms(connector->dev, "[CONNECTOR:%d:%s] EDID override set\n",
  2086. connector->base.id, connector->name);
  2087. mutex_lock(&connector->edid_override_mutex);
  2088. drm_edid_free(connector->edid_override);
  2089. connector->edid_override = drm_edid;
  2090. mutex_unlock(&connector->edid_override_mutex);
  2091. return 0;
  2092. }
  2093. /* For debugfs edid_override implementation */
  2094. int drm_edid_override_reset(struct drm_connector *connector)
  2095. {
  2096. drm_dbg_kms(connector->dev, "[CONNECTOR:%d:%s] EDID override reset\n",
  2097. connector->base.id, connector->name);
  2098. mutex_lock(&connector->edid_override_mutex);
  2099. drm_edid_free(connector->edid_override);
  2100. connector->edid_override = NULL;
  2101. mutex_unlock(&connector->edid_override_mutex);
  2102. return 0;
  2103. }
  2104. /**
  2105. * drm_edid_override_connector_update - add modes from override/firmware EDID
  2106. * @connector: connector we're probing
  2107. *
  2108. * Add modes from the override/firmware EDID, if available. Only to be used from
  2109. * drm_helper_probe_single_connector_modes() as a fallback for when DDC probe
  2110. * failed during drm_get_edid() and caused the override/firmware EDID to be
  2111. * skipped.
  2112. *
  2113. * Return: The number of modes added or 0 if we couldn't find any.
  2114. */
  2115. int drm_edid_override_connector_update(struct drm_connector *connector)
  2116. {
  2117. const struct drm_edid *override;
  2118. int num_modes = 0;
  2119. override = drm_edid_override_get(connector);
  2120. if (override) {
  2121. if (drm_edid_connector_update(connector, override) == 0)
  2122. num_modes = drm_edid_connector_add_modes(connector);
  2123. drm_edid_free(override);
  2124. drm_dbg_kms(connector->dev,
  2125. "[CONNECTOR:%d:%s] adding %d modes via fallback override/firmware EDID\n",
  2126. connector->base.id, connector->name, num_modes);
  2127. }
  2128. return num_modes;
  2129. }
  2130. EXPORT_SYMBOL(drm_edid_override_connector_update);
  2131. typedef int read_block_fn(void *context, u8 *buf, unsigned int block, size_t len);
  2132. static enum edid_block_status edid_block_read(void *block, unsigned int block_num,
  2133. read_block_fn read_block,
  2134. void *context)
  2135. {
  2136. enum edid_block_status status;
  2137. bool is_base_block = block_num == 0;
  2138. int try;
  2139. for (try = 0; try < 4; try++) {
  2140. if (read_block(context, block, block_num, EDID_LENGTH))
  2141. return EDID_BLOCK_READ_FAIL;
  2142. status = edid_block_check(block, is_base_block);
  2143. if (status == EDID_BLOCK_HEADER_REPAIR) {
  2144. edid_header_fix(block);
  2145. /* Retry with fixed header, update status if that worked. */
  2146. status = edid_block_check(block, is_base_block);
  2147. if (status == EDID_BLOCK_OK)
  2148. status = EDID_BLOCK_HEADER_FIXED;
  2149. }
  2150. if (edid_block_status_valid(status, edid_block_tag(block)))
  2151. break;
  2152. /* Fail early for unrepairable base block all zeros. */
  2153. if (try == 0 && is_base_block && status == EDID_BLOCK_ZERO)
  2154. break;
  2155. }
  2156. return status;
  2157. }
  2158. static struct edid *_drm_do_get_edid(struct drm_connector *connector,
  2159. read_block_fn read_block, void *context,
  2160. size_t *size)
  2161. {
  2162. enum edid_block_status status;
  2163. int i, num_blocks, invalid_blocks = 0;
  2164. const struct drm_edid *override;
  2165. struct edid *edid, *new;
  2166. size_t alloc_size = EDID_LENGTH;
  2167. override = drm_edid_override_get(connector);
  2168. if (override) {
  2169. alloc_size = override->size;
  2170. edid = kmemdup(override->edid, alloc_size, GFP_KERNEL);
  2171. drm_edid_free(override);
  2172. if (!edid)
  2173. return NULL;
  2174. goto ok;
  2175. }
  2176. edid = kmalloc(alloc_size, GFP_KERNEL);
  2177. if (!edid)
  2178. return NULL;
  2179. status = edid_block_read(edid, 0, read_block, context);
  2180. edid_block_status_print(status, edid, 0);
  2181. if (status == EDID_BLOCK_READ_FAIL)
  2182. goto fail;
  2183. /* FIXME: Clarify what a corrupt EDID actually means. */
  2184. if (status == EDID_BLOCK_OK || status == EDID_BLOCK_VERSION)
  2185. connector->edid_corrupt = false;
  2186. else
  2187. connector->edid_corrupt = true;
  2188. if (!edid_block_status_valid(status, edid_block_tag(edid))) {
  2189. if (status == EDID_BLOCK_ZERO)
  2190. connector->null_edid_counter++;
  2191. connector_bad_edid(connector, edid, 1);
  2192. goto fail;
  2193. }
  2194. if (!edid_extension_block_count(edid))
  2195. goto ok;
  2196. alloc_size = edid_size(edid);
  2197. new = krealloc(edid, alloc_size, GFP_KERNEL);
  2198. if (!new)
  2199. goto fail;
  2200. edid = new;
  2201. num_blocks = edid_block_count(edid);
  2202. for (i = 1; i < num_blocks; i++) {
  2203. void *block = (void *)edid_block_data(edid, i);
  2204. status = edid_block_read(block, i, read_block, context);
  2205. edid_block_status_print(status, block, i);
  2206. if (!edid_block_status_valid(status, edid_block_tag(block))) {
  2207. if (status == EDID_BLOCK_READ_FAIL)
  2208. goto fail;
  2209. invalid_blocks++;
  2210. } else if (i == 1) {
  2211. /*
  2212. * If the first EDID extension is a CTA extension, and
  2213. * the first Data Block is HF-EEODB, override the
  2214. * extension block count.
  2215. *
  2216. * Note: HF-EEODB could specify a smaller extension
  2217. * count too, but we can't risk allocating a smaller
  2218. * amount.
  2219. */
  2220. int eeodb = edid_hfeeodb_block_count(edid);
  2221. if (eeodb > num_blocks) {
  2222. num_blocks = eeodb;
  2223. alloc_size = edid_size_by_blocks(num_blocks);
  2224. new = krealloc(edid, alloc_size, GFP_KERNEL);
  2225. if (!new)
  2226. goto fail;
  2227. edid = new;
  2228. }
  2229. }
  2230. }
  2231. if (invalid_blocks) {
  2232. connector_bad_edid(connector, edid, num_blocks);
  2233. edid = edid_filter_invalid_blocks(edid, &alloc_size);
  2234. }
  2235. ok:
  2236. if (size)
  2237. *size = alloc_size;
  2238. return edid;
  2239. fail:
  2240. kfree(edid);
  2241. return NULL;
  2242. }
  2243. /**
  2244. * drm_edid_raw - Get a pointer to the raw EDID data.
  2245. * @drm_edid: drm_edid container
  2246. *
  2247. * Get a pointer to the raw EDID data.
  2248. *
  2249. * This is for transition only. Avoid using this like the plague.
  2250. *
  2251. * Return: Pointer to raw EDID data.
  2252. */
  2253. const struct edid *drm_edid_raw(const struct drm_edid *drm_edid)
  2254. {
  2255. if (!drm_edid || !drm_edid->size)
  2256. return NULL;
  2257. /*
  2258. * Do not return pointers where relying on EDID extension count would
  2259. * lead to buffer overflow.
  2260. */
  2261. if (WARN_ON(edid_size(drm_edid->edid) > drm_edid->size))
  2262. return NULL;
  2263. return drm_edid->edid;
  2264. }
  2265. EXPORT_SYMBOL(drm_edid_raw);
  2266. /* Allocate struct drm_edid container *without* duplicating the edid data */
  2267. static const struct drm_edid *_drm_edid_alloc(const void *edid, size_t size)
  2268. {
  2269. struct drm_edid *drm_edid;
  2270. if (!edid || !size || size < EDID_LENGTH)
  2271. return NULL;
  2272. drm_edid = kzalloc(sizeof(*drm_edid), GFP_KERNEL);
  2273. if (drm_edid) {
  2274. drm_edid->edid = edid;
  2275. drm_edid->size = size;
  2276. }
  2277. return drm_edid;
  2278. }
  2279. /**
  2280. * drm_edid_alloc - Allocate a new drm_edid container
  2281. * @edid: Pointer to raw EDID data
  2282. * @size: Size of memory allocated for EDID
  2283. *
  2284. * Allocate a new drm_edid container. Do not calculate edid size from edid, pass
  2285. * the actual size that has been allocated for the data. There is no validation
  2286. * of the raw EDID data against the size, but at least the EDID base block must
  2287. * fit in the buffer.
  2288. *
  2289. * The returned pointer must be freed using drm_edid_free().
  2290. *
  2291. * Return: drm_edid container, or NULL on errors
  2292. */
  2293. const struct drm_edid *drm_edid_alloc(const void *edid, size_t size)
  2294. {
  2295. const struct drm_edid *drm_edid;
  2296. if (!edid || !size || size < EDID_LENGTH)
  2297. return NULL;
  2298. edid = kmemdup(edid, size, GFP_KERNEL);
  2299. if (!edid)
  2300. return NULL;
  2301. drm_edid = _drm_edid_alloc(edid, size);
  2302. if (!drm_edid)
  2303. kfree(edid);
  2304. return drm_edid;
  2305. }
  2306. EXPORT_SYMBOL(drm_edid_alloc);
  2307. /**
  2308. * drm_edid_dup - Duplicate a drm_edid container
  2309. * @drm_edid: EDID to duplicate
  2310. *
  2311. * The returned pointer must be freed using drm_edid_free().
  2312. *
  2313. * Returns: drm_edid container copy, or NULL on errors
  2314. */
  2315. const struct drm_edid *drm_edid_dup(const struct drm_edid *drm_edid)
  2316. {
  2317. if (!drm_edid)
  2318. return NULL;
  2319. return drm_edid_alloc(drm_edid->edid, drm_edid->size);
  2320. }
  2321. EXPORT_SYMBOL(drm_edid_dup);
  2322. /**
  2323. * drm_edid_free - Free the drm_edid container
  2324. * @drm_edid: EDID to free
  2325. */
  2326. void drm_edid_free(const struct drm_edid *drm_edid)
  2327. {
  2328. if (!drm_edid)
  2329. return;
  2330. kfree(drm_edid->edid);
  2331. kfree(drm_edid);
  2332. }
  2333. EXPORT_SYMBOL(drm_edid_free);
  2334. /**
  2335. * drm_probe_ddc() - probe DDC presence
  2336. * @adapter: I2C adapter to probe
  2337. *
  2338. * Return: True on success, false on failure.
  2339. */
  2340. bool
  2341. drm_probe_ddc(struct i2c_adapter *adapter)
  2342. {
  2343. unsigned char out;
  2344. return (drm_do_probe_ddc_edid(adapter, &out, 0, 1) == 0);
  2345. }
  2346. EXPORT_SYMBOL(drm_probe_ddc);
  2347. /**
  2348. * drm_get_edid - get EDID data, if available
  2349. * @connector: connector we're probing
  2350. * @adapter: I2C adapter to use for DDC
  2351. *
  2352. * Poke the given I2C channel to grab EDID data if possible. If found,
  2353. * attach it to the connector.
  2354. *
  2355. * Return: Pointer to valid EDID or NULL if we couldn't find any.
  2356. */
  2357. struct edid *drm_get_edid(struct drm_connector *connector,
  2358. struct i2c_adapter *adapter)
  2359. {
  2360. struct edid *edid;
  2361. if (connector->force == DRM_FORCE_OFF)
  2362. return NULL;
  2363. if (connector->force == DRM_FORCE_UNSPECIFIED && !drm_probe_ddc(adapter))
  2364. return NULL;
  2365. edid = _drm_do_get_edid(connector, drm_do_probe_ddc_edid, adapter, NULL);
  2366. drm_connector_update_edid_property(connector, edid);
  2367. return edid;
  2368. }
  2369. EXPORT_SYMBOL(drm_get_edid);
  2370. /**
  2371. * drm_edid_read_custom - Read EDID data using given EDID block read function
  2372. * @connector: Connector to use
  2373. * @read_block: EDID block read function
  2374. * @context: Private data passed to the block read function
  2375. *
  2376. * When the I2C adapter connected to the DDC bus is hidden behind a device that
  2377. * exposes a different interface to read EDID blocks this function can be used
  2378. * to get EDID data using a custom block read function.
  2379. *
  2380. * As in the general case the DDC bus is accessible by the kernel at the I2C
  2381. * level, drivers must make all reasonable efforts to expose it as an I2C
  2382. * adapter and use drm_edid_read() or drm_edid_read_ddc() instead of abusing
  2383. * this function.
  2384. *
  2385. * The EDID may be overridden using debugfs override_edid or firmware EDID
  2386. * (drm_edid_load_firmware() and drm.edid_firmware parameter), in this priority
  2387. * order. Having either of them bypasses actual EDID reads.
  2388. *
  2389. * The returned pointer must be freed using drm_edid_free().
  2390. *
  2391. * Return: Pointer to EDID, or NULL if probe/read failed.
  2392. */
  2393. const struct drm_edid *drm_edid_read_custom(struct drm_connector *connector,
  2394. read_block_fn read_block,
  2395. void *context)
  2396. {
  2397. const struct drm_edid *drm_edid;
  2398. struct edid *edid;
  2399. size_t size = 0;
  2400. edid = _drm_do_get_edid(connector, read_block, context, &size);
  2401. if (!edid)
  2402. return NULL;
  2403. /* Sanity check for now */
  2404. drm_WARN_ON(connector->dev, !size);
  2405. drm_edid = _drm_edid_alloc(edid, size);
  2406. if (!drm_edid)
  2407. kfree(edid);
  2408. return drm_edid;
  2409. }
  2410. EXPORT_SYMBOL(drm_edid_read_custom);
  2411. /**
  2412. * drm_edid_read_ddc - Read EDID data using given I2C adapter
  2413. * @connector: Connector to use
  2414. * @adapter: I2C adapter to use for DDC
  2415. *
  2416. * Read EDID using the given I2C adapter.
  2417. *
  2418. * The EDID may be overridden using debugfs override_edid or firmware EDID
  2419. * (drm_edid_load_firmware() and drm.edid_firmware parameter), in this priority
  2420. * order. Having either of them bypasses actual EDID reads.
  2421. *
  2422. * Prefer initializing connector->ddc with drm_connector_init_with_ddc() and
  2423. * using drm_edid_read() instead of this function.
  2424. *
  2425. * The returned pointer must be freed using drm_edid_free().
  2426. *
  2427. * Return: Pointer to EDID, or NULL if probe/read failed.
  2428. */
  2429. const struct drm_edid *drm_edid_read_ddc(struct drm_connector *connector,
  2430. struct i2c_adapter *adapter)
  2431. {
  2432. const struct drm_edid *drm_edid;
  2433. if (connector->force == DRM_FORCE_OFF)
  2434. return NULL;
  2435. if (connector->force == DRM_FORCE_UNSPECIFIED && !drm_probe_ddc(adapter))
  2436. return NULL;
  2437. drm_edid = drm_edid_read_custom(connector, drm_do_probe_ddc_edid, adapter);
  2438. /* Note: Do *not* call connector updates here. */
  2439. return drm_edid;
  2440. }
  2441. EXPORT_SYMBOL(drm_edid_read_ddc);
  2442. /**
  2443. * drm_edid_read - Read EDID data using connector's I2C adapter
  2444. * @connector: Connector to use
  2445. *
  2446. * Read EDID using the connector's I2C adapter.
  2447. *
  2448. * The EDID may be overridden using debugfs override_edid or firmware EDID
  2449. * (drm_edid_load_firmware() and drm.edid_firmware parameter), in this priority
  2450. * order. Having either of them bypasses actual EDID reads.
  2451. *
  2452. * The returned pointer must be freed using drm_edid_free().
  2453. *
  2454. * Return: Pointer to EDID, or NULL if probe/read failed.
  2455. */
  2456. const struct drm_edid *drm_edid_read(struct drm_connector *connector)
  2457. {
  2458. if (drm_WARN_ON(connector->dev, !connector->ddc))
  2459. return NULL;
  2460. return drm_edid_read_ddc(connector, connector->ddc);
  2461. }
  2462. EXPORT_SYMBOL(drm_edid_read);
  2463. /**
  2464. * drm_edid_get_product_id - Get the vendor and product identification
  2465. * @drm_edid: EDID
  2466. * @id: Where to place the product id
  2467. */
  2468. void drm_edid_get_product_id(const struct drm_edid *drm_edid,
  2469. struct drm_edid_product_id *id)
  2470. {
  2471. if (drm_edid && drm_edid->edid && drm_edid->size >= EDID_LENGTH)
  2472. memcpy(id, &drm_edid->edid->product_id, sizeof(*id));
  2473. else
  2474. memset(id, 0, sizeof(*id));
  2475. }
  2476. EXPORT_SYMBOL(drm_edid_get_product_id);
  2477. static void decode_date(struct seq_buf *s, const struct drm_edid_product_id *id)
  2478. {
  2479. int week = id->week_of_manufacture;
  2480. int year = id->year_of_manufacture + 1990;
  2481. if (week == 0xff)
  2482. seq_buf_printf(s, "model year: %d", year);
  2483. else if (!week)
  2484. seq_buf_printf(s, "year of manufacture: %d", year);
  2485. else
  2486. seq_buf_printf(s, "week/year of manufacture: %d/%d", week, year);
  2487. }
  2488. /**
  2489. * drm_edid_print_product_id - Print decoded product id to printer
  2490. * @p: drm printer
  2491. * @id: EDID product id
  2492. * @raw: If true, also print the raw hex
  2493. *
  2494. * See VESA E-EDID 1.4 section 3.4.
  2495. */
  2496. void drm_edid_print_product_id(struct drm_printer *p,
  2497. const struct drm_edid_product_id *id, bool raw)
  2498. {
  2499. DECLARE_SEQ_BUF(date, 40);
  2500. char vend[4];
  2501. drm_edid_decode_mfg_id(be16_to_cpu(id->manufacturer_name), vend);
  2502. decode_date(&date, id);
  2503. drm_printf(p, "manufacturer name: %s, product code: %u, serial number: %u, %s\n",
  2504. vend, le16_to_cpu(id->product_code),
  2505. le32_to_cpu(id->serial_number), seq_buf_str(&date));
  2506. if (raw)
  2507. drm_printf(p, "raw product id: %*ph\n", (int)sizeof(*id), id);
  2508. WARN_ON(seq_buf_has_overflowed(&date));
  2509. }
  2510. EXPORT_SYMBOL(drm_edid_print_product_id);
  2511. /**
  2512. * drm_edid_get_panel_id - Get a panel's ID from EDID
  2513. * @drm_edid: EDID that contains panel ID.
  2514. *
  2515. * This function uses the first block of the EDID of a panel and (assuming
  2516. * that the EDID is valid) extracts the ID out of it. The ID is a 32-bit value
  2517. * (16 bits of manufacturer ID and 16 bits of per-manufacturer ID) that's
  2518. * supposed to be different for each different modem of panel.
  2519. *
  2520. * Return: A 32-bit ID that should be different for each make/model of panel.
  2521. * See the functions drm_edid_encode_panel_id() and
  2522. * drm_edid_decode_panel_id() for some details on the structure of this
  2523. * ID. Return 0 if the EDID size is less than a base block.
  2524. */
  2525. u32 drm_edid_get_panel_id(const struct drm_edid *drm_edid)
  2526. {
  2527. const struct edid *edid = drm_edid->edid;
  2528. if (drm_edid->size < EDID_LENGTH)
  2529. return 0;
  2530. /*
  2531. * We represent the ID as a 32-bit number so it can easily be compared
  2532. * with "==".
  2533. *
  2534. * NOTE that we deal with endianness differently for the top half
  2535. * of this ID than for the bottom half. The bottom half (the product
  2536. * id) gets decoded as little endian by the EDID_PRODUCT_ID because
  2537. * that's how everyone seems to interpret it. The top half (the mfg_id)
  2538. * gets stored as big endian because that makes
  2539. * drm_edid_encode_panel_id() and drm_edid_decode_panel_id() easier
  2540. * to write (it's easier to extract the ASCII). It doesn't really
  2541. * matter, though, as long as the number here is unique.
  2542. */
  2543. return (u32)edid->mfg_id[0] << 24 |
  2544. (u32)edid->mfg_id[1] << 16 |
  2545. (u32)EDID_PRODUCT_ID(edid);
  2546. }
  2547. EXPORT_SYMBOL(drm_edid_get_panel_id);
  2548. /**
  2549. * drm_edid_read_base_block - Get a panel's EDID base block
  2550. * @adapter: I2C adapter to use for DDC
  2551. *
  2552. * This function returns the drm_edid containing the first block of the EDID of
  2553. * a panel.
  2554. *
  2555. * This function is intended to be used during early probing on devices where
  2556. * more than one panel might be present. Because of its intended use it must
  2557. * assume that the EDID of the panel is correct, at least as far as the base
  2558. * block is concerned (in other words, we don't process any overrides here).
  2559. *
  2560. * Caller should call drm_edid_free() after use.
  2561. *
  2562. * NOTE: it's expected that this function and drm_do_get_edid() will both
  2563. * be read the EDID, but there is no caching between them. Since we're only
  2564. * reading the first block, hopefully this extra overhead won't be too big.
  2565. *
  2566. * WARNING: Only use this function when the connector is unknown. For example,
  2567. * during the early probe of panel. The EDID read from the function is temporary
  2568. * and should be replaced by the full EDID returned from other drm_edid_read.
  2569. *
  2570. * Return: Pointer to allocated EDID base block, or NULL on any failure.
  2571. */
  2572. const struct drm_edid *drm_edid_read_base_block(struct i2c_adapter *adapter)
  2573. {
  2574. enum edid_block_status status;
  2575. void *base_block;
  2576. base_block = kzalloc(EDID_LENGTH, GFP_KERNEL);
  2577. if (!base_block)
  2578. return NULL;
  2579. status = edid_block_read(base_block, 0, drm_do_probe_ddc_edid, adapter);
  2580. edid_block_status_print(status, base_block, 0);
  2581. if (!edid_block_status_valid(status, edid_block_tag(base_block))) {
  2582. edid_block_dump(KERN_NOTICE, base_block, 0);
  2583. kfree(base_block);
  2584. return NULL;
  2585. }
  2586. return _drm_edid_alloc(base_block, EDID_LENGTH);
  2587. }
  2588. EXPORT_SYMBOL(drm_edid_read_base_block);
  2589. /**
  2590. * drm_get_edid_switcheroo - get EDID data for a vga_switcheroo output
  2591. * @connector: connector we're probing
  2592. * @adapter: I2C adapter to use for DDC
  2593. *
  2594. * Wrapper around drm_get_edid() for laptops with dual GPUs using one set of
  2595. * outputs. The wrapper adds the requisite vga_switcheroo calls to temporarily
  2596. * switch DDC to the GPU which is retrieving EDID.
  2597. *
  2598. * Return: Pointer to valid EDID or %NULL if we couldn't find any.
  2599. */
  2600. struct edid *drm_get_edid_switcheroo(struct drm_connector *connector,
  2601. struct i2c_adapter *adapter)
  2602. {
  2603. struct drm_device *dev = connector->dev;
  2604. struct pci_dev *pdev = to_pci_dev(dev->dev);
  2605. struct edid *edid;
  2606. if (drm_WARN_ON_ONCE(dev, !dev_is_pci(dev->dev)))
  2607. return NULL;
  2608. vga_switcheroo_lock_ddc(pdev);
  2609. edid = drm_get_edid(connector, adapter);
  2610. vga_switcheroo_unlock_ddc(pdev);
  2611. return edid;
  2612. }
  2613. EXPORT_SYMBOL(drm_get_edid_switcheroo);
  2614. /**
  2615. * drm_edid_read_switcheroo - get EDID data for a vga_switcheroo output
  2616. * @connector: connector we're probing
  2617. * @adapter: I2C adapter to use for DDC
  2618. *
  2619. * Wrapper around drm_edid_read_ddc() for laptops with dual GPUs using one set
  2620. * of outputs. The wrapper adds the requisite vga_switcheroo calls to
  2621. * temporarily switch DDC to the GPU which is retrieving EDID.
  2622. *
  2623. * Return: Pointer to valid EDID or %NULL if we couldn't find any.
  2624. */
  2625. const struct drm_edid *drm_edid_read_switcheroo(struct drm_connector *connector,
  2626. struct i2c_adapter *adapter)
  2627. {
  2628. struct drm_device *dev = connector->dev;
  2629. struct pci_dev *pdev = to_pci_dev(dev->dev);
  2630. const struct drm_edid *drm_edid;
  2631. if (drm_WARN_ON_ONCE(dev, !dev_is_pci(dev->dev)))
  2632. return NULL;
  2633. vga_switcheroo_lock_ddc(pdev);
  2634. drm_edid = drm_edid_read_ddc(connector, adapter);
  2635. vga_switcheroo_unlock_ddc(pdev);
  2636. return drm_edid;
  2637. }
  2638. EXPORT_SYMBOL(drm_edid_read_switcheroo);
  2639. /**
  2640. * drm_edid_duplicate - duplicate an EDID and the extensions
  2641. * @edid: EDID to duplicate
  2642. *
  2643. * Return: Pointer to duplicated EDID or NULL on allocation failure.
  2644. */
  2645. struct edid *drm_edid_duplicate(const struct edid *edid)
  2646. {
  2647. if (!edid)
  2648. return NULL;
  2649. return kmemdup(edid, edid_size(edid), GFP_KERNEL);
  2650. }
  2651. EXPORT_SYMBOL(drm_edid_duplicate);
  2652. /*** EDID parsing ***/
  2653. /**
  2654. * edid_get_quirks - return quirk flags for a given EDID
  2655. * @drm_edid: EDID to process
  2656. *
  2657. * This tells subsequent routines what fixes they need to apply.
  2658. *
  2659. * Return: A u32 represents the quirks to apply.
  2660. */
  2661. static u32 edid_get_quirks(const struct drm_edid *drm_edid)
  2662. {
  2663. const struct edid_quirk *quirk;
  2664. int i;
  2665. for (i = 0; i < ARRAY_SIZE(edid_quirk_list); i++) {
  2666. quirk = &edid_quirk_list[i];
  2667. if (drm_edid_match(drm_edid, &quirk->ident))
  2668. return quirk->quirks;
  2669. }
  2670. return 0;
  2671. }
  2672. #define MODE_SIZE(m) ((m)->hdisplay * (m)->vdisplay)
  2673. #define MODE_REFRESH_DIFF(c,t) (abs((c) - (t)))
  2674. /*
  2675. * Walk the mode list for connector, clearing the preferred status on existing
  2676. * modes and setting it anew for the right mode ala quirks.
  2677. */
  2678. static void edid_fixup_preferred(struct drm_connector *connector)
  2679. {
  2680. const struct drm_display_info *info = &connector->display_info;
  2681. struct drm_display_mode *t, *cur_mode, *preferred_mode;
  2682. int target_refresh = 0;
  2683. int cur_vrefresh, preferred_vrefresh;
  2684. if (list_empty(&connector->probed_modes))
  2685. return;
  2686. if (info->quirks & EDID_QUIRK_PREFER_LARGE_60)
  2687. target_refresh = 60;
  2688. if (info->quirks & EDID_QUIRK_PREFER_LARGE_75)
  2689. target_refresh = 75;
  2690. preferred_mode = list_first_entry(&connector->probed_modes,
  2691. struct drm_display_mode, head);
  2692. list_for_each_entry_safe(cur_mode, t, &connector->probed_modes, head) {
  2693. cur_mode->type &= ~DRM_MODE_TYPE_PREFERRED;
  2694. if (cur_mode == preferred_mode)
  2695. continue;
  2696. /* Largest mode is preferred */
  2697. if (MODE_SIZE(cur_mode) > MODE_SIZE(preferred_mode))
  2698. preferred_mode = cur_mode;
  2699. cur_vrefresh = drm_mode_vrefresh(cur_mode);
  2700. preferred_vrefresh = drm_mode_vrefresh(preferred_mode);
  2701. /* At a given size, try to get closest to target refresh */
  2702. if ((MODE_SIZE(cur_mode) == MODE_SIZE(preferred_mode)) &&
  2703. MODE_REFRESH_DIFF(cur_vrefresh, target_refresh) <
  2704. MODE_REFRESH_DIFF(preferred_vrefresh, target_refresh)) {
  2705. preferred_mode = cur_mode;
  2706. }
  2707. }
  2708. preferred_mode->type |= DRM_MODE_TYPE_PREFERRED;
  2709. }
  2710. static bool
  2711. mode_is_rb(const struct drm_display_mode *mode)
  2712. {
  2713. return (mode->htotal - mode->hdisplay == 160) &&
  2714. (mode->hsync_end - mode->hdisplay == 80) &&
  2715. (mode->hsync_end - mode->hsync_start == 32) &&
  2716. (mode->vsync_start - mode->vdisplay == 3);
  2717. }
  2718. /*
  2719. * drm_mode_find_dmt - Create a copy of a mode if present in DMT
  2720. * @dev: Device to duplicate against
  2721. * @hsize: Mode width
  2722. * @vsize: Mode height
  2723. * @fresh: Mode refresh rate
  2724. * @rb: Mode reduced-blanking-ness
  2725. *
  2726. * Walk the DMT mode list looking for a match for the given parameters.
  2727. *
  2728. * Return: A newly allocated copy of the mode, or NULL if not found.
  2729. */
  2730. struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
  2731. int hsize, int vsize, int fresh,
  2732. bool rb)
  2733. {
  2734. int i;
  2735. for (i = 0; i < ARRAY_SIZE(drm_dmt_modes); i++) {
  2736. const struct drm_display_mode *ptr = &drm_dmt_modes[i];
  2737. if (hsize != ptr->hdisplay)
  2738. continue;
  2739. if (vsize != ptr->vdisplay)
  2740. continue;
  2741. if (fresh != drm_mode_vrefresh(ptr))
  2742. continue;
  2743. if (rb != mode_is_rb(ptr))
  2744. continue;
  2745. return drm_mode_duplicate(dev, ptr);
  2746. }
  2747. return NULL;
  2748. }
  2749. EXPORT_SYMBOL(drm_mode_find_dmt);
  2750. static bool is_display_descriptor(const struct detailed_timing *descriptor, u8 type)
  2751. {
  2752. BUILD_BUG_ON(offsetof(typeof(*descriptor), pixel_clock) != 0);
  2753. BUILD_BUG_ON(offsetof(typeof(*descriptor), data.other_data.pad1) != 2);
  2754. BUILD_BUG_ON(offsetof(typeof(*descriptor), data.other_data.type) != 3);
  2755. return descriptor->pixel_clock == 0 &&
  2756. descriptor->data.other_data.pad1 == 0 &&
  2757. descriptor->data.other_data.type == type;
  2758. }
  2759. static bool is_detailed_timing_descriptor(const struct detailed_timing *descriptor)
  2760. {
  2761. BUILD_BUG_ON(offsetof(typeof(*descriptor), pixel_clock) != 0);
  2762. return descriptor->pixel_clock != 0;
  2763. }
  2764. typedef void detailed_cb(const struct detailed_timing *timing, void *closure);
  2765. static void
  2766. cea_for_each_detailed_block(const u8 *ext, detailed_cb *cb, void *closure)
  2767. {
  2768. int i, n;
  2769. u8 d = ext[0x02];
  2770. const u8 *det_base = ext + d;
  2771. if (d < 4 || d > 127)
  2772. return;
  2773. n = (127 - d) / 18;
  2774. for (i = 0; i < n; i++)
  2775. cb((const struct detailed_timing *)(det_base + 18 * i), closure);
  2776. }
  2777. static void
  2778. vtb_for_each_detailed_block(const u8 *ext, detailed_cb *cb, void *closure)
  2779. {
  2780. unsigned int i, n = min((int)ext[0x02], 6);
  2781. const u8 *det_base = ext + 5;
  2782. if (ext[0x01] != 1)
  2783. return; /* unknown version */
  2784. for (i = 0; i < n; i++)
  2785. cb((const struct detailed_timing *)(det_base + 18 * i), closure);
  2786. }
  2787. static void drm_for_each_detailed_block(const struct drm_edid *drm_edid,
  2788. detailed_cb *cb, void *closure)
  2789. {
  2790. struct drm_edid_iter edid_iter;
  2791. const u8 *ext;
  2792. int i;
  2793. if (!drm_edid)
  2794. return;
  2795. for (i = 0; i < EDID_DETAILED_TIMINGS; i++)
  2796. cb(&drm_edid->edid->detailed_timings[i], closure);
  2797. drm_edid_iter_begin(drm_edid, &edid_iter);
  2798. drm_edid_iter_for_each(ext, &edid_iter) {
  2799. switch (*ext) {
  2800. case CEA_EXT:
  2801. cea_for_each_detailed_block(ext, cb, closure);
  2802. break;
  2803. case VTB_EXT:
  2804. vtb_for_each_detailed_block(ext, cb, closure);
  2805. break;
  2806. default:
  2807. break;
  2808. }
  2809. }
  2810. drm_edid_iter_end(&edid_iter);
  2811. }
  2812. static void
  2813. is_rb(const struct detailed_timing *descriptor, void *data)
  2814. {
  2815. bool *res = data;
  2816. if (!is_display_descriptor(descriptor, EDID_DETAIL_MONITOR_RANGE))
  2817. return;
  2818. BUILD_BUG_ON(offsetof(typeof(*descriptor), data.other_data.data.range.flags) != 10);
  2819. BUILD_BUG_ON(offsetof(typeof(*descriptor), data.other_data.data.range.formula.cvt.flags) != 15);
  2820. if (descriptor->data.other_data.data.range.flags == DRM_EDID_CVT_SUPPORT_FLAG &&
  2821. descriptor->data.other_data.data.range.formula.cvt.flags & DRM_EDID_CVT_FLAGS_REDUCED_BLANKING)
  2822. *res = true;
  2823. }
  2824. /* EDID 1.4 defines this explicitly. For EDID 1.3, we guess, badly. */
  2825. static bool
  2826. drm_monitor_supports_rb(const struct drm_edid *drm_edid)
  2827. {
  2828. if (drm_edid->edid->revision >= 4) {
  2829. bool ret = false;
  2830. drm_for_each_detailed_block(drm_edid, is_rb, &ret);
  2831. return ret;
  2832. }
  2833. return drm_edid_is_digital(drm_edid);
  2834. }
  2835. static void
  2836. find_gtf2(const struct detailed_timing *descriptor, void *data)
  2837. {
  2838. const struct detailed_timing **res = data;
  2839. if (!is_display_descriptor(descriptor, EDID_DETAIL_MONITOR_RANGE))
  2840. return;
  2841. BUILD_BUG_ON(offsetof(typeof(*descriptor), data.other_data.data.range.flags) != 10);
  2842. if (descriptor->data.other_data.data.range.flags == DRM_EDID_SECONDARY_GTF_SUPPORT_FLAG)
  2843. *res = descriptor;
  2844. }
  2845. /* Secondary GTF curve kicks in above some break frequency */
  2846. static int
  2847. drm_gtf2_hbreak(const struct drm_edid *drm_edid)
  2848. {
  2849. const struct detailed_timing *descriptor = NULL;
  2850. drm_for_each_detailed_block(drm_edid, find_gtf2, &descriptor);
  2851. BUILD_BUG_ON(offsetof(typeof(*descriptor), data.other_data.data.range.formula.gtf2.hfreq_start_khz) != 12);
  2852. return descriptor ? descriptor->data.other_data.data.range.formula.gtf2.hfreq_start_khz * 2 : 0;
  2853. }
  2854. static int
  2855. drm_gtf2_2c(const struct drm_edid *drm_edid)
  2856. {
  2857. const struct detailed_timing *descriptor = NULL;
  2858. drm_for_each_detailed_block(drm_edid, find_gtf2, &descriptor);
  2859. BUILD_BUG_ON(offsetof(typeof(*descriptor), data.other_data.data.range.formula.gtf2.c) != 13);
  2860. return descriptor ? descriptor->data.other_data.data.range.formula.gtf2.c : 0;
  2861. }
  2862. static int
  2863. drm_gtf2_m(const struct drm_edid *drm_edid)
  2864. {
  2865. const struct detailed_timing *descriptor = NULL;
  2866. drm_for_each_detailed_block(drm_edid, find_gtf2, &descriptor);
  2867. BUILD_BUG_ON(offsetof(typeof(*descriptor), data.other_data.data.range.formula.gtf2.m) != 14);
  2868. return descriptor ? le16_to_cpu(descriptor->data.other_data.data.range.formula.gtf2.m) : 0;
  2869. }
  2870. static int
  2871. drm_gtf2_k(const struct drm_edid *drm_edid)
  2872. {
  2873. const struct detailed_timing *descriptor = NULL;
  2874. drm_for_each_detailed_block(drm_edid, find_gtf2, &descriptor);
  2875. BUILD_BUG_ON(offsetof(typeof(*descriptor), data.other_data.data.range.formula.gtf2.k) != 16);
  2876. return descriptor ? descriptor->data.other_data.data.range.formula.gtf2.k : 0;
  2877. }
  2878. static int
  2879. drm_gtf2_2j(const struct drm_edid *drm_edid)
  2880. {
  2881. const struct detailed_timing *descriptor = NULL;
  2882. drm_for_each_detailed_block(drm_edid, find_gtf2, &descriptor);
  2883. BUILD_BUG_ON(offsetof(typeof(*descriptor), data.other_data.data.range.formula.gtf2.j) != 17);
  2884. return descriptor ? descriptor->data.other_data.data.range.formula.gtf2.j : 0;
  2885. }
  2886. static void
  2887. get_timing_level(const struct detailed_timing *descriptor, void *data)
  2888. {
  2889. int *res = data;
  2890. if (!is_display_descriptor(descriptor, EDID_DETAIL_MONITOR_RANGE))
  2891. return;
  2892. BUILD_BUG_ON(offsetof(typeof(*descriptor), data.other_data.data.range.flags) != 10);
  2893. switch (descriptor->data.other_data.data.range.flags) {
  2894. case DRM_EDID_DEFAULT_GTF_SUPPORT_FLAG:
  2895. *res = LEVEL_GTF;
  2896. break;
  2897. case DRM_EDID_SECONDARY_GTF_SUPPORT_FLAG:
  2898. *res = LEVEL_GTF2;
  2899. break;
  2900. case DRM_EDID_CVT_SUPPORT_FLAG:
  2901. *res = LEVEL_CVT;
  2902. break;
  2903. default:
  2904. break;
  2905. }
  2906. }
  2907. /* Get standard timing level (CVT/GTF/DMT). */
  2908. static int standard_timing_level(const struct drm_edid *drm_edid)
  2909. {
  2910. const struct edid *edid = drm_edid->edid;
  2911. if (edid->revision >= 4) {
  2912. /*
  2913. * If the range descriptor doesn't
  2914. * indicate otherwise default to CVT
  2915. */
  2916. int ret = LEVEL_CVT;
  2917. drm_for_each_detailed_block(drm_edid, get_timing_level, &ret);
  2918. return ret;
  2919. } else if (edid->revision >= 3 && drm_gtf2_hbreak(drm_edid)) {
  2920. return LEVEL_GTF2;
  2921. } else if (edid->revision >= 2) {
  2922. return LEVEL_GTF;
  2923. } else {
  2924. return LEVEL_DMT;
  2925. }
  2926. }
  2927. /*
  2928. * 0 is reserved. The spec says 0x01 fill for unused timings. Some old
  2929. * monitors fill with ascii space (0x20) instead.
  2930. */
  2931. static int
  2932. bad_std_timing(u8 a, u8 b)
  2933. {
  2934. return (a == 0x00 && b == 0x00) ||
  2935. (a == 0x01 && b == 0x01) ||
  2936. (a == 0x20 && b == 0x20);
  2937. }
  2938. static int drm_mode_hsync(const struct drm_display_mode *mode)
  2939. {
  2940. if (mode->htotal <= 0)
  2941. return 0;
  2942. return DIV_ROUND_CLOSEST(mode->clock, mode->htotal);
  2943. }
  2944. static struct drm_display_mode *
  2945. drm_gtf2_mode(struct drm_device *dev,
  2946. const struct drm_edid *drm_edid,
  2947. int hsize, int vsize, int vrefresh_rate)
  2948. {
  2949. struct drm_display_mode *mode;
  2950. /*
  2951. * This is potentially wrong if there's ever a monitor with
  2952. * more than one ranges section, each claiming a different
  2953. * secondary GTF curve. Please don't do that.
  2954. */
  2955. mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0);
  2956. if (!mode)
  2957. return NULL;
  2958. if (drm_mode_hsync(mode) > drm_gtf2_hbreak(drm_edid)) {
  2959. drm_mode_destroy(dev, mode);
  2960. mode = drm_gtf_mode_complex(dev, hsize, vsize,
  2961. vrefresh_rate, 0, 0,
  2962. drm_gtf2_m(drm_edid),
  2963. drm_gtf2_2c(drm_edid),
  2964. drm_gtf2_k(drm_edid),
  2965. drm_gtf2_2j(drm_edid));
  2966. }
  2967. return mode;
  2968. }
  2969. /*
  2970. * Take the standard timing params (in this case width, aspect, and refresh)
  2971. * and convert them into a real mode using CVT/GTF/DMT.
  2972. */
  2973. static struct drm_display_mode *drm_mode_std(struct drm_connector *connector,
  2974. const struct drm_edid *drm_edid,
  2975. const struct std_timing *t)
  2976. {
  2977. struct drm_device *dev = connector->dev;
  2978. struct drm_display_mode *m, *mode = NULL;
  2979. int hsize, vsize;
  2980. int vrefresh_rate;
  2981. unsigned aspect_ratio = (t->vfreq_aspect & EDID_TIMING_ASPECT_MASK)
  2982. >> EDID_TIMING_ASPECT_SHIFT;
  2983. unsigned vfreq = (t->vfreq_aspect & EDID_TIMING_VFREQ_MASK)
  2984. >> EDID_TIMING_VFREQ_SHIFT;
  2985. int timing_level = standard_timing_level(drm_edid);
  2986. if (bad_std_timing(t->hsize, t->vfreq_aspect))
  2987. return NULL;
  2988. /* According to the EDID spec, the hdisplay = hsize * 8 + 248 */
  2989. hsize = t->hsize * 8 + 248;
  2990. /* vrefresh_rate = vfreq + 60 */
  2991. vrefresh_rate = vfreq + 60;
  2992. /* the vdisplay is calculated based on the aspect ratio */
  2993. if (aspect_ratio == 0) {
  2994. if (drm_edid->edid->revision < 3)
  2995. vsize = hsize;
  2996. else
  2997. vsize = (hsize * 10) / 16;
  2998. } else if (aspect_ratio == 1)
  2999. vsize = (hsize * 3) / 4;
  3000. else if (aspect_ratio == 2)
  3001. vsize = (hsize * 4) / 5;
  3002. else
  3003. vsize = (hsize * 9) / 16;
  3004. /* HDTV hack, part 1 */
  3005. if (vrefresh_rate == 60 &&
  3006. ((hsize == 1360 && vsize == 765) ||
  3007. (hsize == 1368 && vsize == 769))) {
  3008. hsize = 1366;
  3009. vsize = 768;
  3010. }
  3011. /*
  3012. * If this connector already has a mode for this size and refresh
  3013. * rate (because it came from detailed or CVT info), use that
  3014. * instead. This way we don't have to guess at interlace or
  3015. * reduced blanking.
  3016. */
  3017. list_for_each_entry(m, &connector->probed_modes, head)
  3018. if (m->hdisplay == hsize && m->vdisplay == vsize &&
  3019. drm_mode_vrefresh(m) == vrefresh_rate)
  3020. return NULL;
  3021. /* HDTV hack, part 2 */
  3022. if (hsize == 1366 && vsize == 768 && vrefresh_rate == 60) {
  3023. mode = drm_cvt_mode(dev, 1366, 768, vrefresh_rate, 0, 0,
  3024. false);
  3025. if (!mode)
  3026. return NULL;
  3027. mode->hdisplay = 1366;
  3028. mode->hsync_start = mode->hsync_start - 1;
  3029. mode->hsync_end = mode->hsync_end - 1;
  3030. return mode;
  3031. }
  3032. /* check whether it can be found in default mode table */
  3033. if (drm_monitor_supports_rb(drm_edid)) {
  3034. mode = drm_mode_find_dmt(dev, hsize, vsize, vrefresh_rate,
  3035. true);
  3036. if (mode)
  3037. return mode;
  3038. }
  3039. mode = drm_mode_find_dmt(dev, hsize, vsize, vrefresh_rate, false);
  3040. if (mode)
  3041. return mode;
  3042. /* okay, generate it */
  3043. switch (timing_level) {
  3044. case LEVEL_DMT:
  3045. break;
  3046. case LEVEL_GTF:
  3047. mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0);
  3048. break;
  3049. case LEVEL_GTF2:
  3050. mode = drm_gtf2_mode(dev, drm_edid, hsize, vsize, vrefresh_rate);
  3051. break;
  3052. case LEVEL_CVT:
  3053. mode = drm_cvt_mode(dev, hsize, vsize, vrefresh_rate, 0, 0,
  3054. false);
  3055. break;
  3056. }
  3057. return mode;
  3058. }
  3059. /*
  3060. * EDID is delightfully ambiguous about how interlaced modes are to be
  3061. * encoded. Our internal representation is of frame height, but some
  3062. * HDTV detailed timings are encoded as field height.
  3063. *
  3064. * The format list here is from CEA, in frame size. Technically we
  3065. * should be checking refresh rate too. Whatever.
  3066. */
  3067. static void
  3068. drm_mode_do_interlace_quirk(struct drm_display_mode *mode,
  3069. const struct detailed_pixel_timing *pt)
  3070. {
  3071. int i;
  3072. static const struct {
  3073. int w, h;
  3074. } cea_interlaced[] = {
  3075. { 1920, 1080 },
  3076. { 720, 480 },
  3077. { 1440, 480 },
  3078. { 2880, 480 },
  3079. { 720, 576 },
  3080. { 1440, 576 },
  3081. { 2880, 576 },
  3082. };
  3083. if (!(pt->misc & DRM_EDID_PT_INTERLACED))
  3084. return;
  3085. for (i = 0; i < ARRAY_SIZE(cea_interlaced); i++) {
  3086. if ((mode->hdisplay == cea_interlaced[i].w) &&
  3087. (mode->vdisplay == cea_interlaced[i].h / 2)) {
  3088. mode->vdisplay *= 2;
  3089. mode->vsync_start *= 2;
  3090. mode->vsync_end *= 2;
  3091. mode->vtotal *= 2;
  3092. mode->vtotal |= 1;
  3093. }
  3094. }
  3095. mode->flags |= DRM_MODE_FLAG_INTERLACE;
  3096. }
  3097. /*
  3098. * Create a new mode from an EDID detailed timing section. An EDID detailed
  3099. * timing block contains enough info for us to create and return a new struct
  3100. * drm_display_mode.
  3101. */
  3102. static struct drm_display_mode *drm_mode_detailed(struct drm_connector *connector,
  3103. const struct drm_edid *drm_edid,
  3104. const struct detailed_timing *timing)
  3105. {
  3106. const struct drm_display_info *info = &connector->display_info;
  3107. struct drm_device *dev = connector->dev;
  3108. struct drm_display_mode *mode;
  3109. const struct detailed_pixel_timing *pt = &timing->data.pixel_data;
  3110. unsigned hactive = (pt->hactive_hblank_hi & 0xf0) << 4 | pt->hactive_lo;
  3111. unsigned vactive = (pt->vactive_vblank_hi & 0xf0) << 4 | pt->vactive_lo;
  3112. unsigned hblank = (pt->hactive_hblank_hi & 0xf) << 8 | pt->hblank_lo;
  3113. unsigned vblank = (pt->vactive_vblank_hi & 0xf) << 8 | pt->vblank_lo;
  3114. unsigned hsync_offset = (pt->hsync_vsync_offset_pulse_width_hi & 0xc0) << 2 | pt->hsync_offset_lo;
  3115. unsigned hsync_pulse_width = (pt->hsync_vsync_offset_pulse_width_hi & 0x30) << 4 | pt->hsync_pulse_width_lo;
  3116. unsigned vsync_offset = (pt->hsync_vsync_offset_pulse_width_hi & 0xc) << 2 | pt->vsync_offset_pulse_width_lo >> 4;
  3117. unsigned vsync_pulse_width = (pt->hsync_vsync_offset_pulse_width_hi & 0x3) << 4 | (pt->vsync_offset_pulse_width_lo & 0xf);
  3118. /* ignore tiny modes */
  3119. if (hactive < 64 || vactive < 64)
  3120. return NULL;
  3121. if (pt->misc & DRM_EDID_PT_STEREO) {
  3122. drm_dbg_kms(dev, "[CONNECTOR:%d:%s] Stereo mode not supported\n",
  3123. connector->base.id, connector->name);
  3124. return NULL;
  3125. }
  3126. if (!(pt->misc & DRM_EDID_PT_SEPARATE_SYNC)) {
  3127. drm_dbg_kms(dev, "[CONNECTOR:%d:%s] Composite sync not supported\n",
  3128. connector->base.id, connector->name);
  3129. }
  3130. /* it is incorrect if hsync/vsync width is zero */
  3131. if (!hsync_pulse_width || !vsync_pulse_width) {
  3132. drm_dbg_kms(dev, "[CONNECTOR:%d:%s] Incorrect Detailed timing. Wrong Hsync/Vsync pulse width\n",
  3133. connector->base.id, connector->name);
  3134. return NULL;
  3135. }
  3136. if (info->quirks & EDID_QUIRK_FORCE_REDUCED_BLANKING) {
  3137. mode = drm_cvt_mode(dev, hactive, vactive, 60, true, false, false);
  3138. if (!mode)
  3139. return NULL;
  3140. goto set_size;
  3141. }
  3142. mode = drm_mode_create(dev);
  3143. if (!mode)
  3144. return NULL;
  3145. if (info->quirks & EDID_QUIRK_135_CLOCK_TOO_HIGH)
  3146. mode->clock = 1088 * 10;
  3147. else
  3148. mode->clock = le16_to_cpu(timing->pixel_clock) * 10;
  3149. mode->hdisplay = hactive;
  3150. mode->hsync_start = mode->hdisplay + hsync_offset;
  3151. mode->hsync_end = mode->hsync_start + hsync_pulse_width;
  3152. mode->htotal = mode->hdisplay + hblank;
  3153. mode->vdisplay = vactive;
  3154. mode->vsync_start = mode->vdisplay + vsync_offset;
  3155. mode->vsync_end = mode->vsync_start + vsync_pulse_width;
  3156. mode->vtotal = mode->vdisplay + vblank;
  3157. /* Some EDIDs have bogus h/vsync_end values */
  3158. if (mode->hsync_end > mode->htotal) {
  3159. drm_dbg_kms(dev, "[CONNECTOR:%d:%s] reducing hsync_end %d->%d\n",
  3160. connector->base.id, connector->name,
  3161. mode->hsync_end, mode->htotal);
  3162. mode->hsync_end = mode->htotal;
  3163. }
  3164. if (mode->vsync_end > mode->vtotal) {
  3165. drm_dbg_kms(dev, "[CONNECTOR:%d:%s] reducing vsync_end %d->%d\n",
  3166. connector->base.id, connector->name,
  3167. mode->vsync_end, mode->vtotal);
  3168. mode->vsync_end = mode->vtotal;
  3169. }
  3170. drm_mode_do_interlace_quirk(mode, pt);
  3171. if (info->quirks & EDID_QUIRK_DETAILED_SYNC_PP) {
  3172. mode->flags |= DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC;
  3173. } else {
  3174. mode->flags |= (pt->misc & DRM_EDID_PT_HSYNC_POSITIVE) ?
  3175. DRM_MODE_FLAG_PHSYNC : DRM_MODE_FLAG_NHSYNC;
  3176. mode->flags |= (pt->misc & DRM_EDID_PT_VSYNC_POSITIVE) ?
  3177. DRM_MODE_FLAG_PVSYNC : DRM_MODE_FLAG_NVSYNC;
  3178. }
  3179. set_size:
  3180. mode->width_mm = pt->width_mm_lo | (pt->width_height_mm_hi & 0xf0) << 4;
  3181. mode->height_mm = pt->height_mm_lo | (pt->width_height_mm_hi & 0xf) << 8;
  3182. if (info->quirks & EDID_QUIRK_DETAILED_IN_CM) {
  3183. mode->width_mm *= 10;
  3184. mode->height_mm *= 10;
  3185. }
  3186. if (info->quirks & EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE) {
  3187. mode->width_mm = drm_edid->edid->width_cm * 10;
  3188. mode->height_mm = drm_edid->edid->height_cm * 10;
  3189. }
  3190. mode->type = DRM_MODE_TYPE_DRIVER;
  3191. drm_mode_set_name(mode);
  3192. return mode;
  3193. }
  3194. static bool
  3195. mode_in_hsync_range(const struct drm_display_mode *mode,
  3196. const struct edid *edid, const u8 *t)
  3197. {
  3198. int hsync, hmin, hmax;
  3199. hmin = t[7];
  3200. if (edid->revision >= 4)
  3201. hmin += ((t[4] & 0x04) ? 255 : 0);
  3202. hmax = t[8];
  3203. if (edid->revision >= 4)
  3204. hmax += ((t[4] & 0x08) ? 255 : 0);
  3205. hsync = drm_mode_hsync(mode);
  3206. return (hsync <= hmax && hsync >= hmin);
  3207. }
  3208. static bool
  3209. mode_in_vsync_range(const struct drm_display_mode *mode,
  3210. const struct edid *edid, const u8 *t)
  3211. {
  3212. int vsync, vmin, vmax;
  3213. vmin = t[5];
  3214. if (edid->revision >= 4)
  3215. vmin += ((t[4] & 0x01) ? 255 : 0);
  3216. vmax = t[6];
  3217. if (edid->revision >= 4)
  3218. vmax += ((t[4] & 0x02) ? 255 : 0);
  3219. vsync = drm_mode_vrefresh(mode);
  3220. return (vsync <= vmax && vsync >= vmin);
  3221. }
  3222. static u32
  3223. range_pixel_clock(const struct edid *edid, const u8 *t)
  3224. {
  3225. /* unspecified */
  3226. if (t[9] == 0 || t[9] == 255)
  3227. return 0;
  3228. /* 1.4 with CVT support gives us real precision, yay */
  3229. if (edid->revision >= 4 && t[10] == DRM_EDID_CVT_SUPPORT_FLAG)
  3230. return (t[9] * 10000) - ((t[12] >> 2) * 250);
  3231. /* 1.3 is pathetic, so fuzz up a bit */
  3232. return t[9] * 10000 + 5001;
  3233. }
  3234. static bool mode_in_range(const struct drm_display_mode *mode,
  3235. const struct drm_edid *drm_edid,
  3236. const struct detailed_timing *timing)
  3237. {
  3238. const struct edid *edid = drm_edid->edid;
  3239. u32 max_clock;
  3240. const u8 *t = (const u8 *)timing;
  3241. if (!mode_in_hsync_range(mode, edid, t))
  3242. return false;
  3243. if (!mode_in_vsync_range(mode, edid, t))
  3244. return false;
  3245. max_clock = range_pixel_clock(edid, t);
  3246. if (max_clock)
  3247. if (mode->clock > max_clock)
  3248. return false;
  3249. /* 1.4 max horizontal check */
  3250. if (edid->revision >= 4 && t[10] == DRM_EDID_CVT_SUPPORT_FLAG)
  3251. if (t[13] && mode->hdisplay > 8 * (t[13] + (256 * (t[12]&0x3))))
  3252. return false;
  3253. if (mode_is_rb(mode) && !drm_monitor_supports_rb(drm_edid))
  3254. return false;
  3255. return true;
  3256. }
  3257. static bool valid_inferred_mode(const struct drm_connector *connector,
  3258. const struct drm_display_mode *mode)
  3259. {
  3260. const struct drm_display_mode *m;
  3261. bool ok = false;
  3262. list_for_each_entry(m, &connector->probed_modes, head) {
  3263. if (mode->hdisplay == m->hdisplay &&
  3264. mode->vdisplay == m->vdisplay &&
  3265. drm_mode_vrefresh(mode) == drm_mode_vrefresh(m))
  3266. return false; /* duplicated */
  3267. if (mode->hdisplay <= m->hdisplay &&
  3268. mode->vdisplay <= m->vdisplay)
  3269. ok = true;
  3270. }
  3271. return ok;
  3272. }
  3273. static int drm_dmt_modes_for_range(struct drm_connector *connector,
  3274. const struct drm_edid *drm_edid,
  3275. const struct detailed_timing *timing)
  3276. {
  3277. int i, modes = 0;
  3278. struct drm_display_mode *newmode;
  3279. struct drm_device *dev = connector->dev;
  3280. for (i = 0; i < ARRAY_SIZE(drm_dmt_modes); i++) {
  3281. if (mode_in_range(drm_dmt_modes + i, drm_edid, timing) &&
  3282. valid_inferred_mode(connector, drm_dmt_modes + i)) {
  3283. newmode = drm_mode_duplicate(dev, &drm_dmt_modes[i]);
  3284. if (newmode) {
  3285. drm_mode_probed_add(connector, newmode);
  3286. modes++;
  3287. }
  3288. }
  3289. }
  3290. return modes;
  3291. }
  3292. /* fix up 1366x768 mode from 1368x768;
  3293. * GFT/CVT can't express 1366 width which isn't dividable by 8
  3294. */
  3295. void drm_mode_fixup_1366x768(struct drm_display_mode *mode)
  3296. {
  3297. if (mode->hdisplay == 1368 && mode->vdisplay == 768) {
  3298. mode->hdisplay = 1366;
  3299. mode->hsync_start--;
  3300. mode->hsync_end--;
  3301. drm_mode_set_name(mode);
  3302. }
  3303. }
  3304. static int drm_gtf_modes_for_range(struct drm_connector *connector,
  3305. const struct drm_edid *drm_edid,
  3306. const struct detailed_timing *timing)
  3307. {
  3308. int i, modes = 0;
  3309. struct drm_display_mode *newmode;
  3310. struct drm_device *dev = connector->dev;
  3311. for (i = 0; i < ARRAY_SIZE(extra_modes); i++) {
  3312. const struct minimode *m = &extra_modes[i];
  3313. newmode = drm_gtf_mode(dev, m->w, m->h, m->r, 0, 0);
  3314. if (!newmode)
  3315. return modes;
  3316. drm_mode_fixup_1366x768(newmode);
  3317. if (!mode_in_range(newmode, drm_edid, timing) ||
  3318. !valid_inferred_mode(connector, newmode)) {
  3319. drm_mode_destroy(dev, newmode);
  3320. continue;
  3321. }
  3322. drm_mode_probed_add(connector, newmode);
  3323. modes++;
  3324. }
  3325. return modes;
  3326. }
  3327. static int drm_gtf2_modes_for_range(struct drm_connector *connector,
  3328. const struct drm_edid *drm_edid,
  3329. const struct detailed_timing *timing)
  3330. {
  3331. int i, modes = 0;
  3332. struct drm_display_mode *newmode;
  3333. struct drm_device *dev = connector->dev;
  3334. for (i = 0; i < ARRAY_SIZE(extra_modes); i++) {
  3335. const struct minimode *m = &extra_modes[i];
  3336. newmode = drm_gtf2_mode(dev, drm_edid, m->w, m->h, m->r);
  3337. if (!newmode)
  3338. return modes;
  3339. drm_mode_fixup_1366x768(newmode);
  3340. if (!mode_in_range(newmode, drm_edid, timing) ||
  3341. !valid_inferred_mode(connector, newmode)) {
  3342. drm_mode_destroy(dev, newmode);
  3343. continue;
  3344. }
  3345. drm_mode_probed_add(connector, newmode);
  3346. modes++;
  3347. }
  3348. return modes;
  3349. }
  3350. static int drm_cvt_modes_for_range(struct drm_connector *connector,
  3351. const struct drm_edid *drm_edid,
  3352. const struct detailed_timing *timing)
  3353. {
  3354. int i, modes = 0;
  3355. struct drm_display_mode *newmode;
  3356. struct drm_device *dev = connector->dev;
  3357. bool rb = drm_monitor_supports_rb(drm_edid);
  3358. for (i = 0; i < ARRAY_SIZE(extra_modes); i++) {
  3359. const struct minimode *m = &extra_modes[i];
  3360. newmode = drm_cvt_mode(dev, m->w, m->h, m->r, rb, 0, 0);
  3361. if (!newmode)
  3362. return modes;
  3363. drm_mode_fixup_1366x768(newmode);
  3364. if (!mode_in_range(newmode, drm_edid, timing) ||
  3365. !valid_inferred_mode(connector, newmode)) {
  3366. drm_mode_destroy(dev, newmode);
  3367. continue;
  3368. }
  3369. drm_mode_probed_add(connector, newmode);
  3370. modes++;
  3371. }
  3372. return modes;
  3373. }
  3374. static void
  3375. do_inferred_modes(const struct detailed_timing *timing, void *c)
  3376. {
  3377. struct detailed_mode_closure *closure = c;
  3378. const struct detailed_non_pixel *data = &timing->data.other_data;
  3379. const struct detailed_data_monitor_range *range = &data->data.range;
  3380. if (!is_display_descriptor(timing, EDID_DETAIL_MONITOR_RANGE))
  3381. return;
  3382. closure->modes += drm_dmt_modes_for_range(closure->connector,
  3383. closure->drm_edid,
  3384. timing);
  3385. if (closure->drm_edid->edid->revision < 2)
  3386. return; /* GTF not defined yet */
  3387. switch (range->flags) {
  3388. case DRM_EDID_SECONDARY_GTF_SUPPORT_FLAG:
  3389. closure->modes += drm_gtf2_modes_for_range(closure->connector,
  3390. closure->drm_edid,
  3391. timing);
  3392. break;
  3393. case DRM_EDID_DEFAULT_GTF_SUPPORT_FLAG:
  3394. closure->modes += drm_gtf_modes_for_range(closure->connector,
  3395. closure->drm_edid,
  3396. timing);
  3397. break;
  3398. case DRM_EDID_CVT_SUPPORT_FLAG:
  3399. if (closure->drm_edid->edid->revision < 4)
  3400. break;
  3401. closure->modes += drm_cvt_modes_for_range(closure->connector,
  3402. closure->drm_edid,
  3403. timing);
  3404. break;
  3405. case DRM_EDID_RANGE_LIMITS_ONLY_FLAG:
  3406. default:
  3407. break;
  3408. }
  3409. }
  3410. static int add_inferred_modes(struct drm_connector *connector,
  3411. const struct drm_edid *drm_edid)
  3412. {
  3413. struct detailed_mode_closure closure = {
  3414. .connector = connector,
  3415. .drm_edid = drm_edid,
  3416. };
  3417. if (drm_edid->edid->revision >= 1)
  3418. drm_for_each_detailed_block(drm_edid, do_inferred_modes, &closure);
  3419. return closure.modes;
  3420. }
  3421. static int
  3422. drm_est3_modes(struct drm_connector *connector, const struct detailed_timing *timing)
  3423. {
  3424. int i, j, m, modes = 0;
  3425. struct drm_display_mode *mode;
  3426. const u8 *est = ((const u8 *)timing) + 6;
  3427. for (i = 0; i < 6; i++) {
  3428. for (j = 7; j >= 0; j--) {
  3429. m = (i * 8) + (7 - j);
  3430. if (m >= ARRAY_SIZE(est3_modes))
  3431. break;
  3432. if (est[i] & (1 << j)) {
  3433. mode = drm_mode_find_dmt(connector->dev,
  3434. est3_modes[m].w,
  3435. est3_modes[m].h,
  3436. est3_modes[m].r,
  3437. est3_modes[m].rb);
  3438. if (mode) {
  3439. drm_mode_probed_add(connector, mode);
  3440. modes++;
  3441. }
  3442. }
  3443. }
  3444. }
  3445. return modes;
  3446. }
  3447. static void
  3448. do_established_modes(const struct detailed_timing *timing, void *c)
  3449. {
  3450. struct detailed_mode_closure *closure = c;
  3451. if (!is_display_descriptor(timing, EDID_DETAIL_EST_TIMINGS))
  3452. return;
  3453. closure->modes += drm_est3_modes(closure->connector, timing);
  3454. }
  3455. /*
  3456. * Get established modes from EDID and add them. Each EDID block contains a
  3457. * bitmap of the supported "established modes" list (defined above). Tease them
  3458. * out and add them to the global modes list.
  3459. */
  3460. static int add_established_modes(struct drm_connector *connector,
  3461. const struct drm_edid *drm_edid)
  3462. {
  3463. struct drm_device *dev = connector->dev;
  3464. const struct edid *edid = drm_edid->edid;
  3465. unsigned long est_bits = edid->established_timings.t1 |
  3466. (edid->established_timings.t2 << 8) |
  3467. ((edid->established_timings.mfg_rsvd & 0x80) << 9);
  3468. int i, modes = 0;
  3469. struct detailed_mode_closure closure = {
  3470. .connector = connector,
  3471. .drm_edid = drm_edid,
  3472. };
  3473. for (i = 0; i <= EDID_EST_TIMINGS; i++) {
  3474. if (est_bits & (1<<i)) {
  3475. struct drm_display_mode *newmode;
  3476. newmode = drm_mode_duplicate(dev, &edid_est_modes[i]);
  3477. if (newmode) {
  3478. drm_mode_probed_add(connector, newmode);
  3479. modes++;
  3480. }
  3481. }
  3482. }
  3483. if (edid->revision >= 1)
  3484. drm_for_each_detailed_block(drm_edid, do_established_modes,
  3485. &closure);
  3486. return modes + closure.modes;
  3487. }
  3488. static void
  3489. do_standard_modes(const struct detailed_timing *timing, void *c)
  3490. {
  3491. struct detailed_mode_closure *closure = c;
  3492. const struct detailed_non_pixel *data = &timing->data.other_data;
  3493. struct drm_connector *connector = closure->connector;
  3494. int i;
  3495. if (!is_display_descriptor(timing, EDID_DETAIL_STD_MODES))
  3496. return;
  3497. for (i = 0; i < 6; i++) {
  3498. const struct std_timing *std = &data->data.timings[i];
  3499. struct drm_display_mode *newmode;
  3500. newmode = drm_mode_std(connector, closure->drm_edid, std);
  3501. if (newmode) {
  3502. drm_mode_probed_add(connector, newmode);
  3503. closure->modes++;
  3504. }
  3505. }
  3506. }
  3507. /*
  3508. * Get standard modes from EDID and add them. Standard modes can be calculated
  3509. * using the appropriate standard (DMT, GTF, or CVT). Grab them from EDID and
  3510. * add them to the list.
  3511. */
  3512. static int add_standard_modes(struct drm_connector *connector,
  3513. const struct drm_edid *drm_edid)
  3514. {
  3515. int i, modes = 0;
  3516. struct detailed_mode_closure closure = {
  3517. .connector = connector,
  3518. .drm_edid = drm_edid,
  3519. };
  3520. for (i = 0; i < EDID_STD_TIMINGS; i++) {
  3521. struct drm_display_mode *newmode;
  3522. newmode = drm_mode_std(connector, drm_edid,
  3523. &drm_edid->edid->standard_timings[i]);
  3524. if (newmode) {
  3525. drm_mode_probed_add(connector, newmode);
  3526. modes++;
  3527. }
  3528. }
  3529. if (drm_edid->edid->revision >= 1)
  3530. drm_for_each_detailed_block(drm_edid, do_standard_modes,
  3531. &closure);
  3532. /* XXX should also look for standard codes in VTB blocks */
  3533. return modes + closure.modes;
  3534. }
  3535. static int drm_cvt_modes(struct drm_connector *connector,
  3536. const struct detailed_timing *timing)
  3537. {
  3538. int i, j, modes = 0;
  3539. struct drm_display_mode *newmode;
  3540. struct drm_device *dev = connector->dev;
  3541. const struct cvt_timing *cvt;
  3542. static const int rates[] = { 60, 85, 75, 60, 50 };
  3543. const u8 empty[3] = { 0, 0, 0 };
  3544. for (i = 0; i < 4; i++) {
  3545. int width, height;
  3546. cvt = &(timing->data.other_data.data.cvt[i]);
  3547. if (!memcmp(cvt->code, empty, 3))
  3548. continue;
  3549. height = (cvt->code[0] + ((cvt->code[1] & 0xf0) << 4) + 1) * 2;
  3550. switch (cvt->code[1] & 0x0c) {
  3551. /* default - because compiler doesn't see that we've enumerated all cases */
  3552. default:
  3553. case 0x00:
  3554. width = height * 4 / 3;
  3555. break;
  3556. case 0x04:
  3557. width = height * 16 / 9;
  3558. break;
  3559. case 0x08:
  3560. width = height * 16 / 10;
  3561. break;
  3562. case 0x0c:
  3563. width = height * 15 / 9;
  3564. break;
  3565. }
  3566. for (j = 1; j < 5; j++) {
  3567. if (cvt->code[2] & (1 << j)) {
  3568. newmode = drm_cvt_mode(dev, width, height,
  3569. rates[j], j == 0,
  3570. false, false);
  3571. if (newmode) {
  3572. drm_mode_probed_add(connector, newmode);
  3573. modes++;
  3574. }
  3575. }
  3576. }
  3577. }
  3578. return modes;
  3579. }
  3580. static void
  3581. do_cvt_mode(const struct detailed_timing *timing, void *c)
  3582. {
  3583. struct detailed_mode_closure *closure = c;
  3584. if (!is_display_descriptor(timing, EDID_DETAIL_CVT_3BYTE))
  3585. return;
  3586. closure->modes += drm_cvt_modes(closure->connector, timing);
  3587. }
  3588. static int
  3589. add_cvt_modes(struct drm_connector *connector, const struct drm_edid *drm_edid)
  3590. {
  3591. struct detailed_mode_closure closure = {
  3592. .connector = connector,
  3593. .drm_edid = drm_edid,
  3594. };
  3595. if (drm_edid->edid->revision >= 3)
  3596. drm_for_each_detailed_block(drm_edid, do_cvt_mode, &closure);
  3597. /* XXX should also look for CVT codes in VTB blocks */
  3598. return closure.modes;
  3599. }
  3600. static void fixup_detailed_cea_mode_clock(struct drm_connector *connector,
  3601. struct drm_display_mode *mode);
  3602. static void
  3603. do_detailed_mode(const struct detailed_timing *timing, void *c)
  3604. {
  3605. struct detailed_mode_closure *closure = c;
  3606. struct drm_display_mode *newmode;
  3607. if (!is_detailed_timing_descriptor(timing))
  3608. return;
  3609. newmode = drm_mode_detailed(closure->connector,
  3610. closure->drm_edid, timing);
  3611. if (!newmode)
  3612. return;
  3613. if (closure->preferred)
  3614. newmode->type |= DRM_MODE_TYPE_PREFERRED;
  3615. /*
  3616. * Detailed modes are limited to 10kHz pixel clock resolution,
  3617. * so fix up anything that looks like CEA/HDMI mode, but the clock
  3618. * is just slightly off.
  3619. */
  3620. fixup_detailed_cea_mode_clock(closure->connector, newmode);
  3621. drm_mode_probed_add(closure->connector, newmode);
  3622. closure->modes++;
  3623. closure->preferred = false;
  3624. }
  3625. /*
  3626. * add_detailed_modes - Add modes from detailed timings
  3627. * @connector: attached connector
  3628. * @drm_edid: EDID block to scan
  3629. */
  3630. static int add_detailed_modes(struct drm_connector *connector,
  3631. const struct drm_edid *drm_edid)
  3632. {
  3633. struct detailed_mode_closure closure = {
  3634. .connector = connector,
  3635. .drm_edid = drm_edid,
  3636. };
  3637. if (drm_edid->edid->revision >= 4)
  3638. closure.preferred = true; /* first detailed timing is always preferred */
  3639. else
  3640. closure.preferred =
  3641. drm_edid->edid->features & DRM_EDID_FEATURE_PREFERRED_TIMING;
  3642. drm_for_each_detailed_block(drm_edid, do_detailed_mode, &closure);
  3643. return closure.modes;
  3644. }
  3645. /* CTA-861-H Table 60 - CTA Tag Codes */
  3646. #define CTA_DB_AUDIO 1
  3647. #define CTA_DB_VIDEO 2
  3648. #define CTA_DB_VENDOR 3
  3649. #define CTA_DB_SPEAKER 4
  3650. #define CTA_DB_EXTENDED_TAG 7
  3651. /* CTA-861-H Table 62 - CTA Extended Tag Codes */
  3652. #define CTA_EXT_DB_VIDEO_CAP 0
  3653. #define CTA_EXT_DB_VENDOR 1
  3654. #define CTA_EXT_DB_HDR_STATIC_METADATA 6
  3655. #define CTA_EXT_DB_420_VIDEO_DATA 14
  3656. #define CTA_EXT_DB_420_VIDEO_CAP_MAP 15
  3657. #define CTA_EXT_DB_HF_EEODB 0x78
  3658. #define CTA_EXT_DB_HF_SCDB 0x79
  3659. #define EDID_BASIC_AUDIO (1 << 6)
  3660. #define EDID_CEA_YCRCB444 (1 << 5)
  3661. #define EDID_CEA_YCRCB422 (1 << 4)
  3662. #define EDID_CEA_VCDB_QS (1 << 6)
  3663. /*
  3664. * Search EDID for CEA extension block.
  3665. *
  3666. * FIXME: Prefer not returning pointers to raw EDID data.
  3667. */
  3668. const u8 *drm_edid_find_extension(const struct drm_edid *drm_edid,
  3669. int ext_id, int *ext_index)
  3670. {
  3671. const u8 *edid_ext = NULL;
  3672. int i;
  3673. /* No EDID or EDID extensions */
  3674. if (!drm_edid || !drm_edid_extension_block_count(drm_edid))
  3675. return NULL;
  3676. /* Find CEA extension */
  3677. for (i = *ext_index; i < drm_edid_extension_block_count(drm_edid); i++) {
  3678. edid_ext = drm_edid_extension_block_data(drm_edid, i);
  3679. if (edid_block_tag(edid_ext) == ext_id)
  3680. break;
  3681. }
  3682. if (i >= drm_edid_extension_block_count(drm_edid))
  3683. return NULL;
  3684. *ext_index = i + 1;
  3685. return edid_ext;
  3686. }
  3687. /* Return true if the EDID has a CTA extension or a DisplayID CTA data block */
  3688. static bool drm_edid_has_cta_extension(const struct drm_edid *drm_edid)
  3689. {
  3690. const struct displayid_block *block;
  3691. struct displayid_iter iter;
  3692. struct drm_edid_iter edid_iter;
  3693. const u8 *ext;
  3694. bool found = false;
  3695. /* Look for a top level CEA extension block */
  3696. drm_edid_iter_begin(drm_edid, &edid_iter);
  3697. drm_edid_iter_for_each(ext, &edid_iter) {
  3698. if (ext[0] == CEA_EXT) {
  3699. found = true;
  3700. break;
  3701. }
  3702. }
  3703. drm_edid_iter_end(&edid_iter);
  3704. if (found)
  3705. return true;
  3706. /* CEA blocks can also be found embedded in a DisplayID block */
  3707. displayid_iter_edid_begin(drm_edid, &iter);
  3708. displayid_iter_for_each(block, &iter) {
  3709. if (block->tag == DATA_BLOCK_CTA) {
  3710. found = true;
  3711. break;
  3712. }
  3713. }
  3714. displayid_iter_end(&iter);
  3715. return found;
  3716. }
  3717. static __always_inline const struct drm_display_mode *cea_mode_for_vic(u8 vic)
  3718. {
  3719. BUILD_BUG_ON(1 + ARRAY_SIZE(edid_cea_modes_1) - 1 != 127);
  3720. BUILD_BUG_ON(193 + ARRAY_SIZE(edid_cea_modes_193) - 1 != 219);
  3721. if (vic >= 1 && vic < 1 + ARRAY_SIZE(edid_cea_modes_1))
  3722. return &edid_cea_modes_1[vic - 1];
  3723. if (vic >= 193 && vic < 193 + ARRAY_SIZE(edid_cea_modes_193))
  3724. return &edid_cea_modes_193[vic - 193];
  3725. return NULL;
  3726. }
  3727. static u8 cea_num_vics(void)
  3728. {
  3729. return 193 + ARRAY_SIZE(edid_cea_modes_193);
  3730. }
  3731. static u8 cea_next_vic(u8 vic)
  3732. {
  3733. if (++vic == 1 + ARRAY_SIZE(edid_cea_modes_1))
  3734. vic = 193;
  3735. return vic;
  3736. }
  3737. /*
  3738. * Calculate the alternate clock for the CEA mode
  3739. * (60Hz vs. 59.94Hz etc.)
  3740. */
  3741. static unsigned int
  3742. cea_mode_alternate_clock(const struct drm_display_mode *cea_mode)
  3743. {
  3744. unsigned int clock = cea_mode->clock;
  3745. if (drm_mode_vrefresh(cea_mode) % 6 != 0)
  3746. return clock;
  3747. /*
  3748. * edid_cea_modes contains the 59.94Hz
  3749. * variant for 240 and 480 line modes,
  3750. * and the 60Hz variant otherwise.
  3751. */
  3752. if (cea_mode->vdisplay == 240 || cea_mode->vdisplay == 480)
  3753. clock = DIV_ROUND_CLOSEST(clock * 1001, 1000);
  3754. else
  3755. clock = DIV_ROUND_CLOSEST(clock * 1000, 1001);
  3756. return clock;
  3757. }
  3758. static bool
  3759. cea_mode_alternate_timings(u8 vic, struct drm_display_mode *mode)
  3760. {
  3761. /*
  3762. * For certain VICs the spec allows the vertical
  3763. * front porch to vary by one or two lines.
  3764. *
  3765. * cea_modes[] stores the variant with the shortest
  3766. * vertical front porch. We can adjust the mode to
  3767. * get the other variants by simply increasing the
  3768. * vertical front porch length.
  3769. */
  3770. BUILD_BUG_ON(cea_mode_for_vic(8)->vtotal != 262 ||
  3771. cea_mode_for_vic(9)->vtotal != 262 ||
  3772. cea_mode_for_vic(12)->vtotal != 262 ||
  3773. cea_mode_for_vic(13)->vtotal != 262 ||
  3774. cea_mode_for_vic(23)->vtotal != 312 ||
  3775. cea_mode_for_vic(24)->vtotal != 312 ||
  3776. cea_mode_for_vic(27)->vtotal != 312 ||
  3777. cea_mode_for_vic(28)->vtotal != 312);
  3778. if (((vic == 8 || vic == 9 ||
  3779. vic == 12 || vic == 13) && mode->vtotal < 263) ||
  3780. ((vic == 23 || vic == 24 ||
  3781. vic == 27 || vic == 28) && mode->vtotal < 314)) {
  3782. mode->vsync_start++;
  3783. mode->vsync_end++;
  3784. mode->vtotal++;
  3785. return true;
  3786. }
  3787. return false;
  3788. }
  3789. static u8 drm_match_cea_mode_clock_tolerance(const struct drm_display_mode *to_match,
  3790. unsigned int clock_tolerance)
  3791. {
  3792. unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
  3793. u8 vic;
  3794. if (!to_match->clock)
  3795. return 0;
  3796. if (to_match->picture_aspect_ratio)
  3797. match_flags |= DRM_MODE_MATCH_ASPECT_RATIO;
  3798. for (vic = 1; vic < cea_num_vics(); vic = cea_next_vic(vic)) {
  3799. struct drm_display_mode cea_mode;
  3800. unsigned int clock1, clock2;
  3801. drm_mode_init(&cea_mode, cea_mode_for_vic(vic));
  3802. /* Check both 60Hz and 59.94Hz */
  3803. clock1 = cea_mode.clock;
  3804. clock2 = cea_mode_alternate_clock(&cea_mode);
  3805. if (abs(to_match->clock - clock1) > clock_tolerance &&
  3806. abs(to_match->clock - clock2) > clock_tolerance)
  3807. continue;
  3808. do {
  3809. if (drm_mode_match(to_match, &cea_mode, match_flags))
  3810. return vic;
  3811. } while (cea_mode_alternate_timings(vic, &cea_mode));
  3812. }
  3813. return 0;
  3814. }
  3815. /**
  3816. * drm_match_cea_mode - look for a CEA mode matching given mode
  3817. * @to_match: display mode
  3818. *
  3819. * Return: The CEA Video ID (VIC) of the mode or 0 if it isn't a CEA-861
  3820. * mode.
  3821. */
  3822. u8 drm_match_cea_mode(const struct drm_display_mode *to_match)
  3823. {
  3824. unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
  3825. u8 vic;
  3826. if (!to_match->clock)
  3827. return 0;
  3828. if (to_match->picture_aspect_ratio)
  3829. match_flags |= DRM_MODE_MATCH_ASPECT_RATIO;
  3830. for (vic = 1; vic < cea_num_vics(); vic = cea_next_vic(vic)) {
  3831. struct drm_display_mode cea_mode;
  3832. unsigned int clock1, clock2;
  3833. drm_mode_init(&cea_mode, cea_mode_for_vic(vic));
  3834. /* Check both 60Hz and 59.94Hz */
  3835. clock1 = cea_mode.clock;
  3836. clock2 = cea_mode_alternate_clock(&cea_mode);
  3837. if (KHZ2PICOS(to_match->clock) != KHZ2PICOS(clock1) &&
  3838. KHZ2PICOS(to_match->clock) != KHZ2PICOS(clock2))
  3839. continue;
  3840. do {
  3841. if (drm_mode_match(to_match, &cea_mode, match_flags))
  3842. return vic;
  3843. } while (cea_mode_alternate_timings(vic, &cea_mode));
  3844. }
  3845. return 0;
  3846. }
  3847. EXPORT_SYMBOL(drm_match_cea_mode);
  3848. static bool drm_valid_cea_vic(u8 vic)
  3849. {
  3850. return cea_mode_for_vic(vic) != NULL;
  3851. }
  3852. static enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code)
  3853. {
  3854. const struct drm_display_mode *mode = cea_mode_for_vic(video_code);
  3855. if (mode)
  3856. return mode->picture_aspect_ratio;
  3857. return HDMI_PICTURE_ASPECT_NONE;
  3858. }
  3859. static enum hdmi_picture_aspect drm_get_hdmi_aspect_ratio(const u8 video_code)
  3860. {
  3861. return edid_4k_modes[video_code].picture_aspect_ratio;
  3862. }
  3863. /*
  3864. * Calculate the alternate clock for HDMI modes (those from the HDMI vendor
  3865. * specific block).
  3866. */
  3867. static unsigned int
  3868. hdmi_mode_alternate_clock(const struct drm_display_mode *hdmi_mode)
  3869. {
  3870. return cea_mode_alternate_clock(hdmi_mode);
  3871. }
  3872. static u8 drm_match_hdmi_mode_clock_tolerance(const struct drm_display_mode *to_match,
  3873. unsigned int clock_tolerance)
  3874. {
  3875. unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
  3876. u8 vic;
  3877. if (!to_match->clock)
  3878. return 0;
  3879. if (to_match->picture_aspect_ratio)
  3880. match_flags |= DRM_MODE_MATCH_ASPECT_RATIO;
  3881. for (vic = 1; vic < ARRAY_SIZE(edid_4k_modes); vic++) {
  3882. const struct drm_display_mode *hdmi_mode = &edid_4k_modes[vic];
  3883. unsigned int clock1, clock2;
  3884. /* Make sure to also match alternate clocks */
  3885. clock1 = hdmi_mode->clock;
  3886. clock2 = hdmi_mode_alternate_clock(hdmi_mode);
  3887. if (abs(to_match->clock - clock1) > clock_tolerance &&
  3888. abs(to_match->clock - clock2) > clock_tolerance)
  3889. continue;
  3890. if (drm_mode_match(to_match, hdmi_mode, match_flags))
  3891. return vic;
  3892. }
  3893. return 0;
  3894. }
  3895. /*
  3896. * drm_match_hdmi_mode - look for a HDMI mode matching given mode
  3897. * @to_match: display mode
  3898. *
  3899. * An HDMI mode is one defined in the HDMI vendor specific block.
  3900. *
  3901. * Returns the HDMI Video ID (VIC) of the mode or 0 if it isn't one.
  3902. */
  3903. static u8 drm_match_hdmi_mode(const struct drm_display_mode *to_match)
  3904. {
  3905. unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
  3906. u8 vic;
  3907. if (!to_match->clock)
  3908. return 0;
  3909. if (to_match->picture_aspect_ratio)
  3910. match_flags |= DRM_MODE_MATCH_ASPECT_RATIO;
  3911. for (vic = 1; vic < ARRAY_SIZE(edid_4k_modes); vic++) {
  3912. const struct drm_display_mode *hdmi_mode = &edid_4k_modes[vic];
  3913. unsigned int clock1, clock2;
  3914. /* Make sure to also match alternate clocks */
  3915. clock1 = hdmi_mode->clock;
  3916. clock2 = hdmi_mode_alternate_clock(hdmi_mode);
  3917. if ((KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock1) ||
  3918. KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock2)) &&
  3919. drm_mode_match(to_match, hdmi_mode, match_flags))
  3920. return vic;
  3921. }
  3922. return 0;
  3923. }
  3924. static bool drm_valid_hdmi_vic(u8 vic)
  3925. {
  3926. return vic > 0 && vic < ARRAY_SIZE(edid_4k_modes);
  3927. }
  3928. static int add_alternate_cea_modes(struct drm_connector *connector,
  3929. const struct drm_edid *drm_edid)
  3930. {
  3931. struct drm_device *dev = connector->dev;
  3932. struct drm_display_mode *mode, *tmp;
  3933. LIST_HEAD(list);
  3934. int modes = 0;
  3935. /* Don't add CTA modes if the CTA extension block is missing */
  3936. if (!drm_edid_has_cta_extension(drm_edid))
  3937. return 0;
  3938. /*
  3939. * Go through all probed modes and create a new mode
  3940. * with the alternate clock for certain CEA modes.
  3941. */
  3942. list_for_each_entry(mode, &connector->probed_modes, head) {
  3943. const struct drm_display_mode *cea_mode = NULL;
  3944. struct drm_display_mode *newmode;
  3945. u8 vic = drm_match_cea_mode(mode);
  3946. unsigned int clock1, clock2;
  3947. if (drm_valid_cea_vic(vic)) {
  3948. cea_mode = cea_mode_for_vic(vic);
  3949. clock2 = cea_mode_alternate_clock(cea_mode);
  3950. } else {
  3951. vic = drm_match_hdmi_mode(mode);
  3952. if (drm_valid_hdmi_vic(vic)) {
  3953. cea_mode = &edid_4k_modes[vic];
  3954. clock2 = hdmi_mode_alternate_clock(cea_mode);
  3955. }
  3956. }
  3957. if (!cea_mode)
  3958. continue;
  3959. clock1 = cea_mode->clock;
  3960. if (clock1 == clock2)
  3961. continue;
  3962. if (mode->clock != clock1 && mode->clock != clock2)
  3963. continue;
  3964. newmode = drm_mode_duplicate(dev, cea_mode);
  3965. if (!newmode)
  3966. continue;
  3967. /* Carry over the stereo flags */
  3968. newmode->flags |= mode->flags & DRM_MODE_FLAG_3D_MASK;
  3969. /*
  3970. * The current mode could be either variant. Make
  3971. * sure to pick the "other" clock for the new mode.
  3972. */
  3973. if (mode->clock != clock1)
  3974. newmode->clock = clock1;
  3975. else
  3976. newmode->clock = clock2;
  3977. list_add_tail(&newmode->head, &list);
  3978. }
  3979. list_for_each_entry_safe(mode, tmp, &list, head) {
  3980. list_del(&mode->head);
  3981. drm_mode_probed_add(connector, mode);
  3982. modes++;
  3983. }
  3984. return modes;
  3985. }
  3986. static u8 svd_to_vic(u8 svd)
  3987. {
  3988. /* 0-6 bit vic, 7th bit native mode indicator */
  3989. if ((svd >= 1 && svd <= 64) || (svd >= 129 && svd <= 192))
  3990. return svd & 127;
  3991. return svd;
  3992. }
  3993. /*
  3994. * Return a display mode for the 0-based vic_index'th VIC across all CTA VDBs in
  3995. * the EDID, or NULL on errors.
  3996. */
  3997. static struct drm_display_mode *
  3998. drm_display_mode_from_vic_index(struct drm_connector *connector, int vic_index)
  3999. {
  4000. const struct drm_display_info *info = &connector->display_info;
  4001. struct drm_device *dev = connector->dev;
  4002. if (!info->vics || vic_index >= info->vics_len || !info->vics[vic_index])
  4003. return NULL;
  4004. return drm_display_mode_from_cea_vic(dev, info->vics[vic_index]);
  4005. }
  4006. /*
  4007. * do_y420vdb_modes - Parse YCBCR 420 only modes
  4008. * @connector: connector corresponding to the HDMI sink
  4009. * @svds: start of the data block of CEA YCBCR 420 VDB
  4010. * @len: length of the CEA YCBCR 420 VDB
  4011. *
  4012. * Parse the CEA-861-F YCBCR 420 Video Data Block (Y420VDB)
  4013. * which contains modes which can be supported in YCBCR 420
  4014. * output format only.
  4015. */
  4016. static int do_y420vdb_modes(struct drm_connector *connector,
  4017. const u8 *svds, u8 svds_len)
  4018. {
  4019. struct drm_device *dev = connector->dev;
  4020. int modes = 0, i;
  4021. for (i = 0; i < svds_len; i++) {
  4022. u8 vic = svd_to_vic(svds[i]);
  4023. struct drm_display_mode *newmode;
  4024. if (!drm_valid_cea_vic(vic))
  4025. continue;
  4026. newmode = drm_mode_duplicate(dev, cea_mode_for_vic(vic));
  4027. if (!newmode)
  4028. break;
  4029. drm_mode_probed_add(connector, newmode);
  4030. modes++;
  4031. }
  4032. return modes;
  4033. }
  4034. /**
  4035. * drm_display_mode_from_cea_vic() - return a mode for CEA VIC
  4036. * @dev: DRM device
  4037. * @video_code: CEA VIC of the mode
  4038. *
  4039. * Creates a new mode matching the specified CEA VIC.
  4040. *
  4041. * Returns: A new drm_display_mode on success or NULL on failure
  4042. */
  4043. struct drm_display_mode *
  4044. drm_display_mode_from_cea_vic(struct drm_device *dev,
  4045. u8 video_code)
  4046. {
  4047. const struct drm_display_mode *cea_mode;
  4048. struct drm_display_mode *newmode;
  4049. cea_mode = cea_mode_for_vic(video_code);
  4050. if (!cea_mode)
  4051. return NULL;
  4052. newmode = drm_mode_duplicate(dev, cea_mode);
  4053. if (!newmode)
  4054. return NULL;
  4055. return newmode;
  4056. }
  4057. EXPORT_SYMBOL(drm_display_mode_from_cea_vic);
  4058. /* Add modes based on VICs parsed in parse_cta_vdb() */
  4059. static int add_cta_vdb_modes(struct drm_connector *connector)
  4060. {
  4061. const struct drm_display_info *info = &connector->display_info;
  4062. int i, modes = 0;
  4063. if (!info->vics)
  4064. return 0;
  4065. for (i = 0; i < info->vics_len; i++) {
  4066. struct drm_display_mode *mode;
  4067. mode = drm_display_mode_from_vic_index(connector, i);
  4068. if (mode) {
  4069. drm_mode_probed_add(connector, mode);
  4070. modes++;
  4071. }
  4072. }
  4073. return modes;
  4074. }
  4075. struct stereo_mandatory_mode {
  4076. int width, height, vrefresh;
  4077. unsigned int flags;
  4078. };
  4079. static const struct stereo_mandatory_mode stereo_mandatory_modes[] = {
  4080. { 1920, 1080, 24, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
  4081. { 1920, 1080, 24, DRM_MODE_FLAG_3D_FRAME_PACKING },
  4082. { 1920, 1080, 50,
  4083. DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF },
  4084. { 1920, 1080, 60,
  4085. DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF },
  4086. { 1280, 720, 50, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
  4087. { 1280, 720, 50, DRM_MODE_FLAG_3D_FRAME_PACKING },
  4088. { 1280, 720, 60, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
  4089. { 1280, 720, 60, DRM_MODE_FLAG_3D_FRAME_PACKING }
  4090. };
  4091. static bool
  4092. stereo_match_mandatory(const struct drm_display_mode *mode,
  4093. const struct stereo_mandatory_mode *stereo_mode)
  4094. {
  4095. unsigned int interlaced = mode->flags & DRM_MODE_FLAG_INTERLACE;
  4096. return mode->hdisplay == stereo_mode->width &&
  4097. mode->vdisplay == stereo_mode->height &&
  4098. interlaced == (stereo_mode->flags & DRM_MODE_FLAG_INTERLACE) &&
  4099. drm_mode_vrefresh(mode) == stereo_mode->vrefresh;
  4100. }
  4101. static int add_hdmi_mandatory_stereo_modes(struct drm_connector *connector)
  4102. {
  4103. struct drm_device *dev = connector->dev;
  4104. const struct drm_display_mode *mode;
  4105. struct list_head stereo_modes;
  4106. int modes = 0, i;
  4107. INIT_LIST_HEAD(&stereo_modes);
  4108. list_for_each_entry(mode, &connector->probed_modes, head) {
  4109. for (i = 0; i < ARRAY_SIZE(stereo_mandatory_modes); i++) {
  4110. const struct stereo_mandatory_mode *mandatory;
  4111. struct drm_display_mode *new_mode;
  4112. if (!stereo_match_mandatory(mode,
  4113. &stereo_mandatory_modes[i]))
  4114. continue;
  4115. mandatory = &stereo_mandatory_modes[i];
  4116. new_mode = drm_mode_duplicate(dev, mode);
  4117. if (!new_mode)
  4118. continue;
  4119. new_mode->flags |= mandatory->flags;
  4120. list_add_tail(&new_mode->head, &stereo_modes);
  4121. modes++;
  4122. }
  4123. }
  4124. list_splice_tail(&stereo_modes, &connector->probed_modes);
  4125. return modes;
  4126. }
  4127. static int add_hdmi_mode(struct drm_connector *connector, u8 vic)
  4128. {
  4129. struct drm_device *dev = connector->dev;
  4130. struct drm_display_mode *newmode;
  4131. if (!drm_valid_hdmi_vic(vic)) {
  4132. drm_err(connector->dev, "[CONNECTOR:%d:%s] Unknown HDMI VIC: %d\n",
  4133. connector->base.id, connector->name, vic);
  4134. return 0;
  4135. }
  4136. newmode = drm_mode_duplicate(dev, &edid_4k_modes[vic]);
  4137. if (!newmode)
  4138. return 0;
  4139. drm_mode_probed_add(connector, newmode);
  4140. return 1;
  4141. }
  4142. static int add_3d_struct_modes(struct drm_connector *connector, u16 structure,
  4143. int vic_index)
  4144. {
  4145. struct drm_display_mode *newmode;
  4146. int modes = 0;
  4147. if (structure & (1 << 0)) {
  4148. newmode = drm_display_mode_from_vic_index(connector, vic_index);
  4149. if (newmode) {
  4150. newmode->flags |= DRM_MODE_FLAG_3D_FRAME_PACKING;
  4151. drm_mode_probed_add(connector, newmode);
  4152. modes++;
  4153. }
  4154. }
  4155. if (structure & (1 << 6)) {
  4156. newmode = drm_display_mode_from_vic_index(connector, vic_index);
  4157. if (newmode) {
  4158. newmode->flags |= DRM_MODE_FLAG_3D_TOP_AND_BOTTOM;
  4159. drm_mode_probed_add(connector, newmode);
  4160. modes++;
  4161. }
  4162. }
  4163. if (structure & (1 << 8)) {
  4164. newmode = drm_display_mode_from_vic_index(connector, vic_index);
  4165. if (newmode) {
  4166. newmode->flags |= DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF;
  4167. drm_mode_probed_add(connector, newmode);
  4168. modes++;
  4169. }
  4170. }
  4171. return modes;
  4172. }
  4173. static bool hdmi_vsdb_latency_present(const u8 *db)
  4174. {
  4175. return db[8] & BIT(7);
  4176. }
  4177. static bool hdmi_vsdb_i_latency_present(const u8 *db)
  4178. {
  4179. return hdmi_vsdb_latency_present(db) && db[8] & BIT(6);
  4180. }
  4181. static int hdmi_vsdb_latency_length(const u8 *db)
  4182. {
  4183. if (hdmi_vsdb_i_latency_present(db))
  4184. return 4;
  4185. else if (hdmi_vsdb_latency_present(db))
  4186. return 2;
  4187. else
  4188. return 0;
  4189. }
  4190. /*
  4191. * do_hdmi_vsdb_modes - Parse the HDMI Vendor Specific data block
  4192. * @connector: connector corresponding to the HDMI sink
  4193. * @db: start of the CEA vendor specific block
  4194. * @len: length of the CEA block payload, ie. one can access up to db[len]
  4195. *
  4196. * Parses the HDMI VSDB looking for modes to add to @connector. This function
  4197. * also adds the stereo 3d modes when applicable.
  4198. */
  4199. static int
  4200. do_hdmi_vsdb_modes(struct drm_connector *connector, const u8 *db, u8 len)
  4201. {
  4202. int modes = 0, offset = 0, i, multi_present = 0, multi_len;
  4203. u8 vic_len, hdmi_3d_len = 0;
  4204. u16 mask;
  4205. u16 structure_all;
  4206. if (len < 8)
  4207. goto out;
  4208. /* no HDMI_Video_Present */
  4209. if (!(db[8] & (1 << 5)))
  4210. goto out;
  4211. offset += hdmi_vsdb_latency_length(db);
  4212. /* the declared length is not long enough for the 2 first bytes
  4213. * of additional video format capabilities */
  4214. if (len < (8 + offset + 2))
  4215. goto out;
  4216. /* 3D_Present */
  4217. offset++;
  4218. if (db[8 + offset] & (1 << 7)) {
  4219. modes += add_hdmi_mandatory_stereo_modes(connector);
  4220. /* 3D_Multi_present */
  4221. multi_present = (db[8 + offset] & 0x60) >> 5;
  4222. }
  4223. offset++;
  4224. vic_len = db[8 + offset] >> 5;
  4225. hdmi_3d_len = db[8 + offset] & 0x1f;
  4226. for (i = 0; i < vic_len && len >= (9 + offset + i); i++) {
  4227. u8 vic;
  4228. vic = db[9 + offset + i];
  4229. modes += add_hdmi_mode(connector, vic);
  4230. }
  4231. offset += 1 + vic_len;
  4232. if (multi_present == 1)
  4233. multi_len = 2;
  4234. else if (multi_present == 2)
  4235. multi_len = 4;
  4236. else
  4237. multi_len = 0;
  4238. if (len < (8 + offset + hdmi_3d_len - 1))
  4239. goto out;
  4240. if (hdmi_3d_len < multi_len)
  4241. goto out;
  4242. if (multi_present == 1 || multi_present == 2) {
  4243. /* 3D_Structure_ALL */
  4244. structure_all = (db[8 + offset] << 8) | db[9 + offset];
  4245. /* check if 3D_MASK is present */
  4246. if (multi_present == 2)
  4247. mask = (db[10 + offset] << 8) | db[11 + offset];
  4248. else
  4249. mask = 0xffff;
  4250. for (i = 0; i < 16; i++) {
  4251. if (mask & (1 << i))
  4252. modes += add_3d_struct_modes(connector,
  4253. structure_all, i);
  4254. }
  4255. }
  4256. offset += multi_len;
  4257. for (i = 0; i < (hdmi_3d_len - multi_len); i++) {
  4258. int vic_index;
  4259. struct drm_display_mode *newmode = NULL;
  4260. unsigned int newflag = 0;
  4261. bool detail_present;
  4262. detail_present = ((db[8 + offset + i] & 0x0f) > 7);
  4263. if (detail_present && (i + 1 == hdmi_3d_len - multi_len))
  4264. break;
  4265. /* 2D_VIC_order_X */
  4266. vic_index = db[8 + offset + i] >> 4;
  4267. /* 3D_Structure_X */
  4268. switch (db[8 + offset + i] & 0x0f) {
  4269. case 0:
  4270. newflag = DRM_MODE_FLAG_3D_FRAME_PACKING;
  4271. break;
  4272. case 6:
  4273. newflag = DRM_MODE_FLAG_3D_TOP_AND_BOTTOM;
  4274. break;
  4275. case 8:
  4276. /* 3D_Detail_X */
  4277. if ((db[9 + offset + i] >> 4) == 1)
  4278. newflag = DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF;
  4279. break;
  4280. }
  4281. if (newflag != 0) {
  4282. newmode = drm_display_mode_from_vic_index(connector,
  4283. vic_index);
  4284. if (newmode) {
  4285. newmode->flags |= newflag;
  4286. drm_mode_probed_add(connector, newmode);
  4287. modes++;
  4288. }
  4289. }
  4290. if (detail_present)
  4291. i++;
  4292. }
  4293. out:
  4294. return modes;
  4295. }
  4296. static int
  4297. cea_revision(const u8 *cea)
  4298. {
  4299. /*
  4300. * FIXME is this correct for the DispID variant?
  4301. * The DispID spec doesn't really specify whether
  4302. * this is the revision of the CEA extension or
  4303. * the DispID CEA data block. And the only value
  4304. * given as an example is 0.
  4305. */
  4306. return cea[1];
  4307. }
  4308. /*
  4309. * CTA Data Block iterator.
  4310. *
  4311. * Iterate through all CTA Data Blocks in both EDID CTA Extensions and DisplayID
  4312. * CTA Data Blocks.
  4313. *
  4314. * struct cea_db *db:
  4315. * struct cea_db_iter iter;
  4316. *
  4317. * cea_db_iter_edid_begin(edid, &iter);
  4318. * cea_db_iter_for_each(db, &iter) {
  4319. * // do stuff with db
  4320. * }
  4321. * cea_db_iter_end(&iter);
  4322. */
  4323. struct cea_db_iter {
  4324. struct drm_edid_iter edid_iter;
  4325. struct displayid_iter displayid_iter;
  4326. /* Current Data Block Collection. */
  4327. const u8 *collection;
  4328. /* Current Data Block index in current collection. */
  4329. int index;
  4330. /* End index in current collection. */
  4331. int end;
  4332. };
  4333. /* CTA-861-H section 7.4 CTA Data BLock Collection */
  4334. struct cea_db {
  4335. u8 tag_length;
  4336. u8 data[];
  4337. } __packed;
  4338. static int cea_db_tag(const struct cea_db *db)
  4339. {
  4340. return db->tag_length >> 5;
  4341. }
  4342. static int cea_db_payload_len(const void *_db)
  4343. {
  4344. /* FIXME: Transition to passing struct cea_db * everywhere. */
  4345. const struct cea_db *db = _db;
  4346. return db->tag_length & 0x1f;
  4347. }
  4348. static const void *cea_db_data(const struct cea_db *db)
  4349. {
  4350. return db->data;
  4351. }
  4352. static bool cea_db_is_extended_tag(const struct cea_db *db, int tag)
  4353. {
  4354. return cea_db_tag(db) == CTA_DB_EXTENDED_TAG &&
  4355. cea_db_payload_len(db) >= 1 &&
  4356. db->data[0] == tag;
  4357. }
  4358. static bool cea_db_is_vendor(const struct cea_db *db, int vendor_oui)
  4359. {
  4360. const u8 *data = cea_db_data(db);
  4361. return cea_db_tag(db) == CTA_DB_VENDOR &&
  4362. cea_db_payload_len(db) >= 3 &&
  4363. oui(data[2], data[1], data[0]) == vendor_oui;
  4364. }
  4365. static void cea_db_iter_edid_begin(const struct drm_edid *drm_edid,
  4366. struct cea_db_iter *iter)
  4367. {
  4368. memset(iter, 0, sizeof(*iter));
  4369. drm_edid_iter_begin(drm_edid, &iter->edid_iter);
  4370. displayid_iter_edid_begin(drm_edid, &iter->displayid_iter);
  4371. }
  4372. static const struct cea_db *
  4373. __cea_db_iter_current_block(const struct cea_db_iter *iter)
  4374. {
  4375. const struct cea_db *db;
  4376. if (!iter->collection)
  4377. return NULL;
  4378. db = (const struct cea_db *)&iter->collection[iter->index];
  4379. if (iter->index + sizeof(*db) <= iter->end &&
  4380. iter->index + sizeof(*db) + cea_db_payload_len(db) <= iter->end)
  4381. return db;
  4382. return NULL;
  4383. }
  4384. /*
  4385. * References:
  4386. * - CTA-861-H section 7.3.3 CTA Extension Version 3
  4387. */
  4388. static int cea_db_collection_size(const u8 *cta)
  4389. {
  4390. u8 d = cta[2];
  4391. if (d < 4 || d > 127)
  4392. return 0;
  4393. return d - 4;
  4394. }
  4395. /*
  4396. * References:
  4397. * - VESA E-EDID v1.4
  4398. * - CTA-861-H section 7.3.3 CTA Extension Version 3
  4399. */
  4400. static const void *__cea_db_iter_edid_next(struct cea_db_iter *iter)
  4401. {
  4402. const u8 *ext;
  4403. drm_edid_iter_for_each(ext, &iter->edid_iter) {
  4404. int size;
  4405. /* Only support CTA Extension revision 3+ */
  4406. if (ext[0] != CEA_EXT || cea_revision(ext) < 3)
  4407. continue;
  4408. size = cea_db_collection_size(ext);
  4409. if (!size)
  4410. continue;
  4411. iter->index = 4;
  4412. iter->end = iter->index + size;
  4413. return ext;
  4414. }
  4415. return NULL;
  4416. }
  4417. /*
  4418. * References:
  4419. * - DisplayID v1.3 Appendix C: CEA Data Block within a DisplayID Data Block
  4420. * - DisplayID v2.0 section 4.10 CTA DisplayID Data Block
  4421. *
  4422. * Note that the above do not specify any connection between DisplayID Data
  4423. * Block revision and CTA Extension versions.
  4424. */
  4425. static const void *__cea_db_iter_displayid_next(struct cea_db_iter *iter)
  4426. {
  4427. const struct displayid_block *block;
  4428. displayid_iter_for_each(block, &iter->displayid_iter) {
  4429. if (block->tag != DATA_BLOCK_CTA)
  4430. continue;
  4431. /*
  4432. * The displayid iterator has already verified the block bounds
  4433. * in displayid_iter_block().
  4434. */
  4435. iter->index = sizeof(*block);
  4436. iter->end = iter->index + block->num_bytes;
  4437. return block;
  4438. }
  4439. return NULL;
  4440. }
  4441. static const struct cea_db *__cea_db_iter_next(struct cea_db_iter *iter)
  4442. {
  4443. const struct cea_db *db;
  4444. if (iter->collection) {
  4445. /* Current collection should always be valid. */
  4446. db = __cea_db_iter_current_block(iter);
  4447. if (WARN_ON(!db)) {
  4448. iter->collection = NULL;
  4449. return NULL;
  4450. }
  4451. /* Next block in CTA Data Block Collection */
  4452. iter->index += sizeof(*db) + cea_db_payload_len(db);
  4453. db = __cea_db_iter_current_block(iter);
  4454. if (db)
  4455. return db;
  4456. }
  4457. for (;;) {
  4458. /*
  4459. * Find the next CTA Data Block Collection. First iterate all
  4460. * the EDID CTA Extensions, then all the DisplayID CTA blocks.
  4461. *
  4462. * Per DisplayID v1.3 Appendix B: DisplayID as an EDID
  4463. * Extension, it's recommended that DisplayID extensions are
  4464. * exposed after all of the CTA Extensions.
  4465. */
  4466. iter->collection = __cea_db_iter_edid_next(iter);
  4467. if (!iter->collection)
  4468. iter->collection = __cea_db_iter_displayid_next(iter);
  4469. if (!iter->collection)
  4470. return NULL;
  4471. db = __cea_db_iter_current_block(iter);
  4472. if (db)
  4473. return db;
  4474. }
  4475. }
  4476. #define cea_db_iter_for_each(__db, __iter) \
  4477. while (((__db) = __cea_db_iter_next(__iter)))
  4478. static void cea_db_iter_end(struct cea_db_iter *iter)
  4479. {
  4480. displayid_iter_end(&iter->displayid_iter);
  4481. drm_edid_iter_end(&iter->edid_iter);
  4482. memset(iter, 0, sizeof(*iter));
  4483. }
  4484. static bool cea_db_is_hdmi_vsdb(const struct cea_db *db)
  4485. {
  4486. return cea_db_is_vendor(db, HDMI_IEEE_OUI) &&
  4487. cea_db_payload_len(db) >= 5;
  4488. }
  4489. static bool cea_db_is_hdmi_forum_vsdb(const struct cea_db *db)
  4490. {
  4491. return cea_db_is_vendor(db, HDMI_FORUM_IEEE_OUI) &&
  4492. cea_db_payload_len(db) >= 7;
  4493. }
  4494. static bool cea_db_is_hdmi_forum_eeodb(const void *db)
  4495. {
  4496. return cea_db_is_extended_tag(db, CTA_EXT_DB_HF_EEODB) &&
  4497. cea_db_payload_len(db) >= 2;
  4498. }
  4499. static bool cea_db_is_microsoft_vsdb(const struct cea_db *db)
  4500. {
  4501. return cea_db_is_vendor(db, MICROSOFT_IEEE_OUI) &&
  4502. cea_db_payload_len(db) == 21;
  4503. }
  4504. static bool cea_db_is_vcdb(const struct cea_db *db)
  4505. {
  4506. return cea_db_is_extended_tag(db, CTA_EXT_DB_VIDEO_CAP) &&
  4507. cea_db_payload_len(db) == 2;
  4508. }
  4509. static bool cea_db_is_hdmi_forum_scdb(const struct cea_db *db)
  4510. {
  4511. return cea_db_is_extended_tag(db, CTA_EXT_DB_HF_SCDB) &&
  4512. cea_db_payload_len(db) >= 7;
  4513. }
  4514. static bool cea_db_is_y420cmdb(const struct cea_db *db)
  4515. {
  4516. return cea_db_is_extended_tag(db, CTA_EXT_DB_420_VIDEO_CAP_MAP);
  4517. }
  4518. static bool cea_db_is_y420vdb(const struct cea_db *db)
  4519. {
  4520. return cea_db_is_extended_tag(db, CTA_EXT_DB_420_VIDEO_DATA);
  4521. }
  4522. static bool cea_db_is_hdmi_hdr_metadata_block(const struct cea_db *db)
  4523. {
  4524. return cea_db_is_extended_tag(db, CTA_EXT_DB_HDR_STATIC_METADATA) &&
  4525. cea_db_payload_len(db) >= 3;
  4526. }
  4527. /*
  4528. * Get the HF-EEODB override extension block count from EDID.
  4529. *
  4530. * The passed in EDID may be partially read, as long as it has at least two
  4531. * blocks (base block and one extension block) if EDID extension count is > 0.
  4532. *
  4533. * Note that this is *not* how you should parse CTA Data Blocks in general; this
  4534. * is only to handle partially read EDIDs. Normally, use the CTA Data Block
  4535. * iterators instead.
  4536. *
  4537. * References:
  4538. * - HDMI 2.1 section 10.3.6 HDMI Forum EDID Extension Override Data Block
  4539. */
  4540. static int edid_hfeeodb_extension_block_count(const struct edid *edid)
  4541. {
  4542. const u8 *cta;
  4543. /* No extensions according to base block, no HF-EEODB. */
  4544. if (!edid_extension_block_count(edid))
  4545. return 0;
  4546. /* HF-EEODB is always in the first EDID extension block only */
  4547. cta = edid_extension_block_data(edid, 0);
  4548. if (edid_block_tag(cta) != CEA_EXT || cea_revision(cta) < 3)
  4549. return 0;
  4550. /* Need to have the data block collection, and at least 3 bytes. */
  4551. if (cea_db_collection_size(cta) < 3)
  4552. return 0;
  4553. /*
  4554. * Sinks that include the HF-EEODB in their E-EDID shall include one and
  4555. * only one instance of the HF-EEODB in the E-EDID, occupying bytes 4
  4556. * through 6 of Block 1 of the E-EDID.
  4557. */
  4558. if (!cea_db_is_hdmi_forum_eeodb(&cta[4]))
  4559. return 0;
  4560. return cta[4 + 2];
  4561. }
  4562. /*
  4563. * CTA-861 YCbCr 4:2:0 Capability Map Data Block (CTA Y420CMDB)
  4564. *
  4565. * Y420CMDB contains a bitmap which gives the index of CTA modes from CTA VDB,
  4566. * which can support YCBCR 420 sampling output also (apart from RGB/YCBCR444
  4567. * etc). For example, if the bit 0 in bitmap is set, first mode in VDB can
  4568. * support YCBCR420 output too.
  4569. */
  4570. static void parse_cta_y420cmdb(struct drm_connector *connector,
  4571. const struct cea_db *db, u64 *y420cmdb_map)
  4572. {
  4573. struct drm_display_info *info = &connector->display_info;
  4574. int i, map_len = cea_db_payload_len(db) - 1;
  4575. const u8 *data = cea_db_data(db) + 1;
  4576. u64 map = 0;
  4577. if (map_len == 0) {
  4578. /* All CEA modes support ycbcr420 sampling also.*/
  4579. map = U64_MAX;
  4580. goto out;
  4581. }
  4582. /*
  4583. * This map indicates which of the existing CEA block modes
  4584. * from VDB can support YCBCR420 output too. So if bit=0 is
  4585. * set, first mode from VDB can support YCBCR420 output too.
  4586. * We will parse and keep this map, before parsing VDB itself
  4587. * to avoid going through the same block again and again.
  4588. *
  4589. * Spec is not clear about max possible size of this block.
  4590. * Clamping max bitmap block size at 8 bytes. Every byte can
  4591. * address 8 CEA modes, in this way this map can address
  4592. * 8*8 = first 64 SVDs.
  4593. */
  4594. if (WARN_ON_ONCE(map_len > 8))
  4595. map_len = 8;
  4596. for (i = 0; i < map_len; i++)
  4597. map |= (u64)data[i] << (8 * i);
  4598. out:
  4599. if (map)
  4600. info->color_formats |= DRM_COLOR_FORMAT_YCBCR420;
  4601. *y420cmdb_map = map;
  4602. }
  4603. static int add_cea_modes(struct drm_connector *connector,
  4604. const struct drm_edid *drm_edid)
  4605. {
  4606. const struct cea_db *db;
  4607. struct cea_db_iter iter;
  4608. int modes;
  4609. /* CTA VDB block VICs parsed earlier */
  4610. modes = add_cta_vdb_modes(connector);
  4611. cea_db_iter_edid_begin(drm_edid, &iter);
  4612. cea_db_iter_for_each(db, &iter) {
  4613. if (cea_db_is_hdmi_vsdb(db)) {
  4614. modes += do_hdmi_vsdb_modes(connector, (const u8 *)db,
  4615. cea_db_payload_len(db));
  4616. } else if (cea_db_is_y420vdb(db)) {
  4617. const u8 *vdb420 = cea_db_data(db) + 1;
  4618. /* Add 4:2:0(only) modes present in EDID */
  4619. modes += do_y420vdb_modes(connector, vdb420,
  4620. cea_db_payload_len(db) - 1);
  4621. }
  4622. }
  4623. cea_db_iter_end(&iter);
  4624. return modes;
  4625. }
  4626. static void fixup_detailed_cea_mode_clock(struct drm_connector *connector,
  4627. struct drm_display_mode *mode)
  4628. {
  4629. const struct drm_display_mode *cea_mode;
  4630. int clock1, clock2, clock;
  4631. u8 vic;
  4632. const char *type;
  4633. /*
  4634. * allow 5kHz clock difference either way to account for
  4635. * the 10kHz clock resolution limit of detailed timings.
  4636. */
  4637. vic = drm_match_cea_mode_clock_tolerance(mode, 5);
  4638. if (drm_valid_cea_vic(vic)) {
  4639. type = "CEA";
  4640. cea_mode = cea_mode_for_vic(vic);
  4641. clock1 = cea_mode->clock;
  4642. clock2 = cea_mode_alternate_clock(cea_mode);
  4643. } else {
  4644. vic = drm_match_hdmi_mode_clock_tolerance(mode, 5);
  4645. if (drm_valid_hdmi_vic(vic)) {
  4646. type = "HDMI";
  4647. cea_mode = &edid_4k_modes[vic];
  4648. clock1 = cea_mode->clock;
  4649. clock2 = hdmi_mode_alternate_clock(cea_mode);
  4650. } else {
  4651. return;
  4652. }
  4653. }
  4654. /* pick whichever is closest */
  4655. if (abs(mode->clock - clock1) < abs(mode->clock - clock2))
  4656. clock = clock1;
  4657. else
  4658. clock = clock2;
  4659. if (mode->clock == clock)
  4660. return;
  4661. drm_dbg_kms(connector->dev,
  4662. "[CONNECTOR:%d:%s] detailed mode matches %s VIC %d, adjusting clock %d -> %d\n",
  4663. connector->base.id, connector->name,
  4664. type, vic, mode->clock, clock);
  4665. mode->clock = clock;
  4666. }
  4667. static void drm_calculate_luminance_range(struct drm_connector *connector)
  4668. {
  4669. struct hdr_static_metadata *hdr_metadata = &connector->hdr_sink_metadata.hdmi_type1;
  4670. struct drm_luminance_range_info *luminance_range =
  4671. &connector->display_info.luminance_range;
  4672. static const u8 pre_computed_values[] = {
  4673. 50, 51, 52, 53, 55, 56, 57, 58, 59, 61, 62, 63, 65, 66, 68, 69,
  4674. 71, 72, 74, 75, 77, 79, 81, 82, 84, 86, 88, 90, 92, 94, 96, 98
  4675. };
  4676. u32 max_avg, min_cll, max, min, q, r;
  4677. if (!(hdr_metadata->metadata_type & BIT(HDMI_STATIC_METADATA_TYPE1)))
  4678. return;
  4679. max_avg = hdr_metadata->max_fall;
  4680. min_cll = hdr_metadata->min_cll;
  4681. /*
  4682. * From the specification (CTA-861-G), for calculating the maximum
  4683. * luminance we need to use:
  4684. * Luminance = 50*2**(CV/32)
  4685. * Where CV is a one-byte value.
  4686. * For calculating this expression we may need float point precision;
  4687. * to avoid this complexity level, we take advantage that CV is divided
  4688. * by a constant. From the Euclids division algorithm, we know that CV
  4689. * can be written as: CV = 32*q + r. Next, we replace CV in the
  4690. * Luminance expression and get 50*(2**q)*(2**(r/32)), hence we just
  4691. * need to pre-compute the value of r/32. For pre-computing the values
  4692. * We just used the following Ruby line:
  4693. * (0...32).each {|cv| puts (50*2**(cv/32.0)).round}
  4694. * The results of the above expressions can be verified at
  4695. * pre_computed_values.
  4696. */
  4697. q = max_avg >> 5;
  4698. r = max_avg % 32;
  4699. max = (1 << q) * pre_computed_values[r];
  4700. /* min luminance: maxLum * (CV/255)^2 / 100 */
  4701. q = DIV_ROUND_CLOSEST(min_cll, 255);
  4702. min = max * DIV_ROUND_CLOSEST((q * q), 100);
  4703. luminance_range->min_luminance = min;
  4704. luminance_range->max_luminance = max;
  4705. }
  4706. static uint8_t eotf_supported(const u8 *edid_ext)
  4707. {
  4708. return edid_ext[2] &
  4709. (BIT(HDMI_EOTF_TRADITIONAL_GAMMA_SDR) |
  4710. BIT(HDMI_EOTF_TRADITIONAL_GAMMA_HDR) |
  4711. BIT(HDMI_EOTF_SMPTE_ST2084) |
  4712. BIT(HDMI_EOTF_BT_2100_HLG));
  4713. }
  4714. static uint8_t hdr_metadata_type(const u8 *edid_ext)
  4715. {
  4716. return edid_ext[3] &
  4717. BIT(HDMI_STATIC_METADATA_TYPE1);
  4718. }
  4719. static void
  4720. drm_parse_hdr_metadata_block(struct drm_connector *connector, const u8 *db)
  4721. {
  4722. u16 len;
  4723. len = cea_db_payload_len(db);
  4724. connector->hdr_sink_metadata.hdmi_type1.eotf =
  4725. eotf_supported(db);
  4726. connector->hdr_sink_metadata.hdmi_type1.metadata_type =
  4727. hdr_metadata_type(db);
  4728. if (len >= 4)
  4729. connector->hdr_sink_metadata.hdmi_type1.max_cll = db[4];
  4730. if (len >= 5)
  4731. connector->hdr_sink_metadata.hdmi_type1.max_fall = db[5];
  4732. if (len >= 6) {
  4733. connector->hdr_sink_metadata.hdmi_type1.min_cll = db[6];
  4734. /* Calculate only when all values are available */
  4735. drm_calculate_luminance_range(connector);
  4736. }
  4737. }
  4738. /* HDMI Vendor-Specific Data Block (HDMI VSDB, H14b-VSDB) */
  4739. static void
  4740. drm_parse_hdmi_vsdb_audio(struct drm_connector *connector, const u8 *db)
  4741. {
  4742. u8 len = cea_db_payload_len(db);
  4743. if (len >= 6 && (db[6] & (1 << 7)))
  4744. connector->eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= DRM_ELD_SUPPORTS_AI;
  4745. if (len >= 10 && hdmi_vsdb_latency_present(db)) {
  4746. connector->latency_present[0] = true;
  4747. connector->video_latency[0] = db[9];
  4748. connector->audio_latency[0] = db[10];
  4749. }
  4750. if (len >= 12 && hdmi_vsdb_i_latency_present(db)) {
  4751. connector->latency_present[1] = true;
  4752. connector->video_latency[1] = db[11];
  4753. connector->audio_latency[1] = db[12];
  4754. }
  4755. drm_dbg_kms(connector->dev,
  4756. "[CONNECTOR:%d:%s] HDMI: latency present %d %d, video latency %d %d, audio latency %d %d\n",
  4757. connector->base.id, connector->name,
  4758. connector->latency_present[0], connector->latency_present[1],
  4759. connector->video_latency[0], connector->video_latency[1],
  4760. connector->audio_latency[0], connector->audio_latency[1]);
  4761. }
  4762. static void
  4763. match_identity(const struct detailed_timing *timing, void *data)
  4764. {
  4765. struct drm_edid_match_closure *closure = data;
  4766. unsigned int i;
  4767. const char *name = closure->ident->name;
  4768. unsigned int name_len = strlen(name);
  4769. const char *desc = timing->data.other_data.data.str.str;
  4770. unsigned int desc_len = ARRAY_SIZE(timing->data.other_data.data.str.str);
  4771. if (name_len > desc_len ||
  4772. !(is_display_descriptor(timing, EDID_DETAIL_MONITOR_NAME) ||
  4773. is_display_descriptor(timing, EDID_DETAIL_MONITOR_STRING)))
  4774. return;
  4775. if (strncmp(name, desc, name_len))
  4776. return;
  4777. for (i = name_len; i < desc_len; i++) {
  4778. if (desc[i] == '\n')
  4779. break;
  4780. /* Allow white space before EDID string terminator. */
  4781. if (!isspace(desc[i]))
  4782. return;
  4783. }
  4784. closure->matched = true;
  4785. }
  4786. /**
  4787. * drm_edid_match - match drm_edid with given identity
  4788. * @drm_edid: EDID
  4789. * @ident: the EDID identity to match with
  4790. *
  4791. * Check if the EDID matches with the given identity.
  4792. *
  4793. * Return: True if the given identity matched with EDID, false otherwise.
  4794. */
  4795. bool drm_edid_match(const struct drm_edid *drm_edid,
  4796. const struct drm_edid_ident *ident)
  4797. {
  4798. if (!drm_edid || drm_edid_get_panel_id(drm_edid) != ident->panel_id)
  4799. return false;
  4800. /* Match with name only if it's not NULL. */
  4801. if (ident->name) {
  4802. struct drm_edid_match_closure closure = {
  4803. .ident = ident,
  4804. .matched = false,
  4805. };
  4806. drm_for_each_detailed_block(drm_edid, match_identity, &closure);
  4807. return closure.matched;
  4808. }
  4809. return true;
  4810. }
  4811. EXPORT_SYMBOL(drm_edid_match);
  4812. static void
  4813. monitor_name(const struct detailed_timing *timing, void *data)
  4814. {
  4815. const char **res = data;
  4816. if (!is_display_descriptor(timing, EDID_DETAIL_MONITOR_NAME))
  4817. return;
  4818. *res = timing->data.other_data.data.str.str;
  4819. }
  4820. static int get_monitor_name(const struct drm_edid *drm_edid, char name[13])
  4821. {
  4822. const char *edid_name = NULL;
  4823. int mnl;
  4824. if (!drm_edid || !name)
  4825. return 0;
  4826. drm_for_each_detailed_block(drm_edid, monitor_name, &edid_name);
  4827. for (mnl = 0; edid_name && mnl < 13; mnl++) {
  4828. if (edid_name[mnl] == 0x0a)
  4829. break;
  4830. name[mnl] = edid_name[mnl];
  4831. }
  4832. return mnl;
  4833. }
  4834. /**
  4835. * drm_edid_get_monitor_name - fetch the monitor name from the edid
  4836. * @edid: monitor EDID information
  4837. * @name: pointer to a character array to hold the name of the monitor
  4838. * @bufsize: The size of the name buffer (should be at least 14 chars.)
  4839. *
  4840. */
  4841. void drm_edid_get_monitor_name(const struct edid *edid, char *name, int bufsize)
  4842. {
  4843. int name_length = 0;
  4844. if (bufsize <= 0)
  4845. return;
  4846. if (edid) {
  4847. char buf[13];
  4848. struct drm_edid drm_edid = {
  4849. .edid = edid,
  4850. .size = edid_size(edid),
  4851. };
  4852. name_length = min(get_monitor_name(&drm_edid, buf), bufsize - 1);
  4853. memcpy(name, buf, name_length);
  4854. }
  4855. name[name_length] = '\0';
  4856. }
  4857. EXPORT_SYMBOL(drm_edid_get_monitor_name);
  4858. static void clear_eld(struct drm_connector *connector)
  4859. {
  4860. mutex_lock(&connector->eld_mutex);
  4861. memset(connector->eld, 0, sizeof(connector->eld));
  4862. mutex_unlock(&connector->eld_mutex);
  4863. connector->latency_present[0] = false;
  4864. connector->latency_present[1] = false;
  4865. connector->video_latency[0] = 0;
  4866. connector->audio_latency[0] = 0;
  4867. connector->video_latency[1] = 0;
  4868. connector->audio_latency[1] = 0;
  4869. }
  4870. /*
  4871. * Get 3-byte SAD buffer from struct cea_sad.
  4872. */
  4873. void drm_edid_cta_sad_get(const struct cea_sad *cta_sad, u8 *sad)
  4874. {
  4875. sad[0] = cta_sad->format << 3 | cta_sad->channels;
  4876. sad[1] = cta_sad->freq;
  4877. sad[2] = cta_sad->byte2;
  4878. }
  4879. /*
  4880. * Set struct cea_sad from 3-byte SAD buffer.
  4881. */
  4882. void drm_edid_cta_sad_set(struct cea_sad *cta_sad, const u8 *sad)
  4883. {
  4884. cta_sad->format = (sad[0] & 0x78) >> 3;
  4885. cta_sad->channels = sad[0] & 0x07;
  4886. cta_sad->freq = sad[1] & 0x7f;
  4887. cta_sad->byte2 = sad[2];
  4888. }
  4889. /*
  4890. * drm_edid_to_eld - build ELD from EDID
  4891. * @connector: connector corresponding to the HDMI/DP sink
  4892. * @drm_edid: EDID to parse
  4893. *
  4894. * Fill the ELD (EDID-Like Data) buffer for passing to the audio driver. The
  4895. * HDCP and Port_ID ELD fields are left for the graphics driver to fill in.
  4896. */
  4897. static void drm_edid_to_eld(struct drm_connector *connector,
  4898. const struct drm_edid *drm_edid)
  4899. {
  4900. const struct drm_display_info *info = &connector->display_info;
  4901. const struct cea_db *db;
  4902. struct cea_db_iter iter;
  4903. uint8_t *eld = connector->eld;
  4904. int total_sad_count = 0;
  4905. int mnl;
  4906. if (!drm_edid)
  4907. return;
  4908. mutex_lock(&connector->eld_mutex);
  4909. mnl = get_monitor_name(drm_edid, &eld[DRM_ELD_MONITOR_NAME_STRING]);
  4910. drm_dbg_kms(connector->dev, "[CONNECTOR:%d:%s] ELD monitor %s\n",
  4911. connector->base.id, connector->name,
  4912. &eld[DRM_ELD_MONITOR_NAME_STRING]);
  4913. eld[DRM_ELD_CEA_EDID_VER_MNL] = info->cea_rev << DRM_ELD_CEA_EDID_VER_SHIFT;
  4914. eld[DRM_ELD_CEA_EDID_VER_MNL] |= mnl;
  4915. eld[DRM_ELD_VER] = DRM_ELD_VER_CEA861D;
  4916. eld[DRM_ELD_MANUFACTURER_NAME0] = drm_edid->edid->mfg_id[0];
  4917. eld[DRM_ELD_MANUFACTURER_NAME1] = drm_edid->edid->mfg_id[1];
  4918. eld[DRM_ELD_PRODUCT_CODE0] = drm_edid->edid->prod_code[0];
  4919. eld[DRM_ELD_PRODUCT_CODE1] = drm_edid->edid->prod_code[1];
  4920. cea_db_iter_edid_begin(drm_edid, &iter);
  4921. cea_db_iter_for_each(db, &iter) {
  4922. const u8 *data = cea_db_data(db);
  4923. int len = cea_db_payload_len(db);
  4924. int sad_count;
  4925. switch (cea_db_tag(db)) {
  4926. case CTA_DB_AUDIO:
  4927. /* Audio Data Block, contains SADs */
  4928. sad_count = min(len / 3, 15 - total_sad_count);
  4929. if (sad_count >= 1)
  4930. memcpy(&eld[DRM_ELD_CEA_SAD(mnl, total_sad_count)],
  4931. data, sad_count * 3);
  4932. total_sad_count += sad_count;
  4933. break;
  4934. case CTA_DB_SPEAKER:
  4935. /* Speaker Allocation Data Block */
  4936. if (len >= 1)
  4937. eld[DRM_ELD_SPEAKER] = data[0];
  4938. break;
  4939. case CTA_DB_VENDOR:
  4940. /* HDMI Vendor-Specific Data Block */
  4941. if (cea_db_is_hdmi_vsdb(db))
  4942. drm_parse_hdmi_vsdb_audio(connector, (const u8 *)db);
  4943. break;
  4944. default:
  4945. break;
  4946. }
  4947. }
  4948. cea_db_iter_end(&iter);
  4949. eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= total_sad_count << DRM_ELD_SAD_COUNT_SHIFT;
  4950. if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
  4951. connector->connector_type == DRM_MODE_CONNECTOR_eDP)
  4952. eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= DRM_ELD_CONN_TYPE_DP;
  4953. else
  4954. eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= DRM_ELD_CONN_TYPE_HDMI;
  4955. eld[DRM_ELD_BASELINE_ELD_LEN] =
  4956. DIV_ROUND_UP(drm_eld_calc_baseline_block_size(eld), 4);
  4957. drm_dbg_kms(connector->dev, "[CONNECTOR:%d:%s] ELD size %d, SAD count %d\n",
  4958. connector->base.id, connector->name,
  4959. drm_eld_size(eld), total_sad_count);
  4960. mutex_unlock(&connector->eld_mutex);
  4961. }
  4962. static int _drm_edid_to_sad(const struct drm_edid *drm_edid,
  4963. struct cea_sad **psads)
  4964. {
  4965. const struct cea_db *db;
  4966. struct cea_db_iter iter;
  4967. int count = 0;
  4968. cea_db_iter_edid_begin(drm_edid, &iter);
  4969. cea_db_iter_for_each(db, &iter) {
  4970. if (cea_db_tag(db) == CTA_DB_AUDIO) {
  4971. struct cea_sad *sads;
  4972. int i;
  4973. count = cea_db_payload_len(db) / 3; /* SAD is 3B */
  4974. sads = kcalloc(count, sizeof(*sads), GFP_KERNEL);
  4975. *psads = sads;
  4976. if (!sads)
  4977. return -ENOMEM;
  4978. for (i = 0; i < count; i++)
  4979. drm_edid_cta_sad_set(&sads[i], &db->data[i * 3]);
  4980. break;
  4981. }
  4982. }
  4983. cea_db_iter_end(&iter);
  4984. DRM_DEBUG_KMS("Found %d Short Audio Descriptors\n", count);
  4985. return count;
  4986. }
  4987. /**
  4988. * drm_edid_to_sad - extracts SADs from EDID
  4989. * @edid: EDID to parse
  4990. * @sads: pointer that will be set to the extracted SADs
  4991. *
  4992. * Looks for CEA EDID block and extracts SADs (Short Audio Descriptors) from it.
  4993. *
  4994. * Note: The returned pointer needs to be freed using kfree().
  4995. *
  4996. * Return: The number of found SADs or negative number on error.
  4997. */
  4998. int drm_edid_to_sad(const struct edid *edid, struct cea_sad **sads)
  4999. {
  5000. struct drm_edid drm_edid;
  5001. return _drm_edid_to_sad(drm_edid_legacy_init(&drm_edid, edid), sads);
  5002. }
  5003. EXPORT_SYMBOL(drm_edid_to_sad);
  5004. static int _drm_edid_to_speaker_allocation(const struct drm_edid *drm_edid,
  5005. u8 **sadb)
  5006. {
  5007. const struct cea_db *db;
  5008. struct cea_db_iter iter;
  5009. int count = 0;
  5010. cea_db_iter_edid_begin(drm_edid, &iter);
  5011. cea_db_iter_for_each(db, &iter) {
  5012. if (cea_db_tag(db) == CTA_DB_SPEAKER &&
  5013. cea_db_payload_len(db) == 3) {
  5014. *sadb = kmemdup(db->data, cea_db_payload_len(db),
  5015. GFP_KERNEL);
  5016. if (!*sadb)
  5017. return -ENOMEM;
  5018. count = cea_db_payload_len(db);
  5019. break;
  5020. }
  5021. }
  5022. cea_db_iter_end(&iter);
  5023. DRM_DEBUG_KMS("Found %d Speaker Allocation Data Blocks\n", count);
  5024. return count;
  5025. }
  5026. /**
  5027. * drm_edid_to_speaker_allocation - extracts Speaker Allocation Data Blocks from EDID
  5028. * @edid: EDID to parse
  5029. * @sadb: pointer to the speaker block
  5030. *
  5031. * Looks for CEA EDID block and extracts the Speaker Allocation Data Block from it.
  5032. *
  5033. * Note: The returned pointer needs to be freed using kfree().
  5034. *
  5035. * Return: The number of found Speaker Allocation Blocks or negative number on
  5036. * error.
  5037. */
  5038. int drm_edid_to_speaker_allocation(const struct edid *edid, u8 **sadb)
  5039. {
  5040. struct drm_edid drm_edid;
  5041. return _drm_edid_to_speaker_allocation(drm_edid_legacy_init(&drm_edid, edid),
  5042. sadb);
  5043. }
  5044. EXPORT_SYMBOL(drm_edid_to_speaker_allocation);
  5045. /**
  5046. * drm_av_sync_delay - compute the HDMI/DP sink audio-video sync delay
  5047. * @connector: connector associated with the HDMI/DP sink
  5048. * @mode: the display mode
  5049. *
  5050. * Return: The HDMI/DP sink's audio-video sync delay in milliseconds or 0 if
  5051. * the sink doesn't support audio or video.
  5052. */
  5053. int drm_av_sync_delay(struct drm_connector *connector,
  5054. const struct drm_display_mode *mode)
  5055. {
  5056. int i = !!(mode->flags & DRM_MODE_FLAG_INTERLACE);
  5057. int a, v;
  5058. if (!connector->latency_present[0])
  5059. return 0;
  5060. if (!connector->latency_present[1])
  5061. i = 0;
  5062. a = connector->audio_latency[i];
  5063. v = connector->video_latency[i];
  5064. /*
  5065. * HDMI/DP sink doesn't support audio or video?
  5066. */
  5067. if (a == 255 || v == 255)
  5068. return 0;
  5069. /*
  5070. * Convert raw EDID values to millisecond.
  5071. * Treat unknown latency as 0ms.
  5072. */
  5073. if (a)
  5074. a = min(2 * (a - 1), 500);
  5075. if (v)
  5076. v = min(2 * (v - 1), 500);
  5077. return max(v - a, 0);
  5078. }
  5079. EXPORT_SYMBOL(drm_av_sync_delay);
  5080. static bool _drm_detect_hdmi_monitor(const struct drm_edid *drm_edid)
  5081. {
  5082. const struct cea_db *db;
  5083. struct cea_db_iter iter;
  5084. bool hdmi = false;
  5085. /*
  5086. * Because HDMI identifier is in Vendor Specific Block,
  5087. * search it from all data blocks of CEA extension.
  5088. */
  5089. cea_db_iter_edid_begin(drm_edid, &iter);
  5090. cea_db_iter_for_each(db, &iter) {
  5091. if (cea_db_is_hdmi_vsdb(db)) {
  5092. hdmi = true;
  5093. break;
  5094. }
  5095. }
  5096. cea_db_iter_end(&iter);
  5097. return hdmi;
  5098. }
  5099. /**
  5100. * drm_detect_hdmi_monitor - detect whether monitor is HDMI
  5101. * @edid: monitor EDID information
  5102. *
  5103. * Parse the CEA extension according to CEA-861-B.
  5104. *
  5105. * Drivers that have added the modes parsed from EDID to drm_display_info
  5106. * should use &drm_display_info.is_hdmi instead of calling this function.
  5107. *
  5108. * Return: True if the monitor is HDMI, false if not or unknown.
  5109. */
  5110. bool drm_detect_hdmi_monitor(const struct edid *edid)
  5111. {
  5112. struct drm_edid drm_edid;
  5113. return _drm_detect_hdmi_monitor(drm_edid_legacy_init(&drm_edid, edid));
  5114. }
  5115. EXPORT_SYMBOL(drm_detect_hdmi_monitor);
  5116. static bool _drm_detect_monitor_audio(const struct drm_edid *drm_edid)
  5117. {
  5118. struct drm_edid_iter edid_iter;
  5119. const struct cea_db *db;
  5120. struct cea_db_iter iter;
  5121. const u8 *edid_ext;
  5122. bool has_audio = false;
  5123. drm_edid_iter_begin(drm_edid, &edid_iter);
  5124. drm_edid_iter_for_each(edid_ext, &edid_iter) {
  5125. if (edid_ext[0] == CEA_EXT) {
  5126. has_audio = edid_ext[3] & EDID_BASIC_AUDIO;
  5127. if (has_audio)
  5128. break;
  5129. }
  5130. }
  5131. drm_edid_iter_end(&edid_iter);
  5132. if (has_audio) {
  5133. DRM_DEBUG_KMS("Monitor has basic audio support\n");
  5134. goto end;
  5135. }
  5136. cea_db_iter_edid_begin(drm_edid, &iter);
  5137. cea_db_iter_for_each(db, &iter) {
  5138. if (cea_db_tag(db) == CTA_DB_AUDIO) {
  5139. const u8 *data = cea_db_data(db);
  5140. int i;
  5141. for (i = 0; i < cea_db_payload_len(db); i += 3)
  5142. DRM_DEBUG_KMS("CEA audio format %d\n",
  5143. (data[i] >> 3) & 0xf);
  5144. has_audio = true;
  5145. break;
  5146. }
  5147. }
  5148. cea_db_iter_end(&iter);
  5149. end:
  5150. return has_audio;
  5151. }
  5152. /**
  5153. * drm_detect_monitor_audio - check monitor audio capability
  5154. * @edid: EDID block to scan
  5155. *
  5156. * Monitor should have CEA extension block.
  5157. * If monitor has 'basic audio', but no CEA audio blocks, it's 'basic
  5158. * audio' only. If there is any audio extension block and supported
  5159. * audio format, assume at least 'basic audio' support, even if 'basic
  5160. * audio' is not defined in EDID.
  5161. *
  5162. * Return: True if the monitor supports audio, false otherwise.
  5163. */
  5164. bool drm_detect_monitor_audio(const struct edid *edid)
  5165. {
  5166. struct drm_edid drm_edid;
  5167. return _drm_detect_monitor_audio(drm_edid_legacy_init(&drm_edid, edid));
  5168. }
  5169. EXPORT_SYMBOL(drm_detect_monitor_audio);
  5170. /**
  5171. * drm_default_rgb_quant_range - default RGB quantization range
  5172. * @mode: display mode
  5173. *
  5174. * Determine the default RGB quantization range for the mode,
  5175. * as specified in CEA-861.
  5176. *
  5177. * Return: The default RGB quantization range for the mode
  5178. */
  5179. enum hdmi_quantization_range
  5180. drm_default_rgb_quant_range(const struct drm_display_mode *mode)
  5181. {
  5182. /* All CEA modes other than VIC 1 use limited quantization range. */
  5183. return drm_match_cea_mode(mode) > 1 ?
  5184. HDMI_QUANTIZATION_RANGE_LIMITED :
  5185. HDMI_QUANTIZATION_RANGE_FULL;
  5186. }
  5187. EXPORT_SYMBOL(drm_default_rgb_quant_range);
  5188. /* CTA-861 Video Data Block (CTA VDB) */
  5189. static void parse_cta_vdb(struct drm_connector *connector, const struct cea_db *db)
  5190. {
  5191. struct drm_display_info *info = &connector->display_info;
  5192. int i, vic_index, len = cea_db_payload_len(db);
  5193. const u8 *svds = cea_db_data(db);
  5194. u8 *vics;
  5195. if (!len)
  5196. return;
  5197. /* Gracefully handle multiple VDBs, however unlikely that is */
  5198. vics = krealloc(info->vics, info->vics_len + len, GFP_KERNEL);
  5199. if (!vics)
  5200. return;
  5201. vic_index = info->vics_len;
  5202. info->vics_len += len;
  5203. info->vics = vics;
  5204. for (i = 0; i < len; i++) {
  5205. u8 vic = svd_to_vic(svds[i]);
  5206. if (!drm_valid_cea_vic(vic))
  5207. vic = 0;
  5208. info->vics[vic_index++] = vic;
  5209. }
  5210. }
  5211. /*
  5212. * Update y420_cmdb_modes based on previously parsed CTA VDB and Y420CMDB.
  5213. *
  5214. * Translate the y420cmdb_map based on VIC indexes to y420_cmdb_modes indexed
  5215. * using the VICs themselves.
  5216. */
  5217. static void update_cta_y420cmdb(struct drm_connector *connector, u64 y420cmdb_map)
  5218. {
  5219. struct drm_display_info *info = &connector->display_info;
  5220. struct drm_hdmi_info *hdmi = &info->hdmi;
  5221. int i, len = min_t(int, info->vics_len, BITS_PER_TYPE(y420cmdb_map));
  5222. for (i = 0; i < len; i++) {
  5223. u8 vic = info->vics[i];
  5224. if (vic && y420cmdb_map & BIT_ULL(i))
  5225. bitmap_set(hdmi->y420_cmdb_modes, vic, 1);
  5226. }
  5227. }
  5228. static bool cta_vdb_has_vic(const struct drm_connector *connector, u8 vic)
  5229. {
  5230. const struct drm_display_info *info = &connector->display_info;
  5231. int i;
  5232. if (!vic || !info->vics)
  5233. return false;
  5234. for (i = 0; i < info->vics_len; i++) {
  5235. if (info->vics[i] == vic)
  5236. return true;
  5237. }
  5238. return false;
  5239. }
  5240. /* CTA-861-H YCbCr 4:2:0 Video Data Block (CTA Y420VDB) */
  5241. static void parse_cta_y420vdb(struct drm_connector *connector,
  5242. const struct cea_db *db)
  5243. {
  5244. struct drm_display_info *info = &connector->display_info;
  5245. struct drm_hdmi_info *hdmi = &info->hdmi;
  5246. const u8 *svds = cea_db_data(db) + 1;
  5247. int i;
  5248. for (i = 0; i < cea_db_payload_len(db) - 1; i++) {
  5249. u8 vic = svd_to_vic(svds[i]);
  5250. if (!drm_valid_cea_vic(vic))
  5251. continue;
  5252. bitmap_set(hdmi->y420_vdb_modes, vic, 1);
  5253. info->color_formats |= DRM_COLOR_FORMAT_YCBCR420;
  5254. }
  5255. }
  5256. static void drm_parse_vcdb(struct drm_connector *connector, const u8 *db)
  5257. {
  5258. struct drm_display_info *info = &connector->display_info;
  5259. drm_dbg_kms(connector->dev, "[CONNECTOR:%d:%s] CEA VCDB 0x%02x\n",
  5260. connector->base.id, connector->name, db[2]);
  5261. if (db[2] & EDID_CEA_VCDB_QS)
  5262. info->rgb_quant_range_selectable = true;
  5263. }
  5264. static
  5265. void drm_get_max_frl_rate(int max_frl_rate, u8 *max_lanes, u8 *max_rate_per_lane)
  5266. {
  5267. switch (max_frl_rate) {
  5268. case 1:
  5269. *max_lanes = 3;
  5270. *max_rate_per_lane = 3;
  5271. break;
  5272. case 2:
  5273. *max_lanes = 3;
  5274. *max_rate_per_lane = 6;
  5275. break;
  5276. case 3:
  5277. *max_lanes = 4;
  5278. *max_rate_per_lane = 6;
  5279. break;
  5280. case 4:
  5281. *max_lanes = 4;
  5282. *max_rate_per_lane = 8;
  5283. break;
  5284. case 5:
  5285. *max_lanes = 4;
  5286. *max_rate_per_lane = 10;
  5287. break;
  5288. case 6:
  5289. *max_lanes = 4;
  5290. *max_rate_per_lane = 12;
  5291. break;
  5292. case 0:
  5293. default:
  5294. *max_lanes = 0;
  5295. *max_rate_per_lane = 0;
  5296. }
  5297. }
  5298. static void drm_parse_ycbcr420_deep_color_info(struct drm_connector *connector,
  5299. const u8 *db)
  5300. {
  5301. u8 dc_mask;
  5302. struct drm_hdmi_info *hdmi = &connector->display_info.hdmi;
  5303. dc_mask = db[7] & DRM_EDID_YCBCR420_DC_MASK;
  5304. hdmi->y420_dc_modes = dc_mask;
  5305. }
  5306. static void drm_parse_dsc_info(struct drm_hdmi_dsc_cap *hdmi_dsc,
  5307. const u8 *hf_scds)
  5308. {
  5309. hdmi_dsc->v_1p2 = hf_scds[11] & DRM_EDID_DSC_1P2;
  5310. if (!hdmi_dsc->v_1p2)
  5311. return;
  5312. hdmi_dsc->native_420 = hf_scds[11] & DRM_EDID_DSC_NATIVE_420;
  5313. hdmi_dsc->all_bpp = hf_scds[11] & DRM_EDID_DSC_ALL_BPP;
  5314. if (hf_scds[11] & DRM_EDID_DSC_16BPC)
  5315. hdmi_dsc->bpc_supported = 16;
  5316. else if (hf_scds[11] & DRM_EDID_DSC_12BPC)
  5317. hdmi_dsc->bpc_supported = 12;
  5318. else if (hf_scds[11] & DRM_EDID_DSC_10BPC)
  5319. hdmi_dsc->bpc_supported = 10;
  5320. else
  5321. /* Supports min 8 BPC if DSC 1.2 is supported*/
  5322. hdmi_dsc->bpc_supported = 8;
  5323. if (cea_db_payload_len(hf_scds) >= 12 && hf_scds[12]) {
  5324. u8 dsc_max_slices;
  5325. u8 dsc_max_frl_rate;
  5326. dsc_max_frl_rate = (hf_scds[12] & DRM_EDID_DSC_MAX_FRL_RATE_MASK) >> 4;
  5327. drm_get_max_frl_rate(dsc_max_frl_rate, &hdmi_dsc->max_lanes,
  5328. &hdmi_dsc->max_frl_rate_per_lane);
  5329. dsc_max_slices = hf_scds[12] & DRM_EDID_DSC_MAX_SLICES;
  5330. switch (dsc_max_slices) {
  5331. case 1:
  5332. hdmi_dsc->max_slices = 1;
  5333. hdmi_dsc->clk_per_slice = 340;
  5334. break;
  5335. case 2:
  5336. hdmi_dsc->max_slices = 2;
  5337. hdmi_dsc->clk_per_slice = 340;
  5338. break;
  5339. case 3:
  5340. hdmi_dsc->max_slices = 4;
  5341. hdmi_dsc->clk_per_slice = 340;
  5342. break;
  5343. case 4:
  5344. hdmi_dsc->max_slices = 8;
  5345. hdmi_dsc->clk_per_slice = 340;
  5346. break;
  5347. case 5:
  5348. hdmi_dsc->max_slices = 8;
  5349. hdmi_dsc->clk_per_slice = 400;
  5350. break;
  5351. case 6:
  5352. hdmi_dsc->max_slices = 12;
  5353. hdmi_dsc->clk_per_slice = 400;
  5354. break;
  5355. case 7:
  5356. hdmi_dsc->max_slices = 16;
  5357. hdmi_dsc->clk_per_slice = 400;
  5358. break;
  5359. case 0:
  5360. default:
  5361. hdmi_dsc->max_slices = 0;
  5362. hdmi_dsc->clk_per_slice = 0;
  5363. }
  5364. }
  5365. if (cea_db_payload_len(hf_scds) >= 13 && hf_scds[13])
  5366. hdmi_dsc->total_chunk_kbytes = hf_scds[13] & DRM_EDID_DSC_TOTAL_CHUNK_KBYTES;
  5367. }
  5368. /* Sink Capability Data Structure */
  5369. static void drm_parse_hdmi_forum_scds(struct drm_connector *connector,
  5370. const u8 *hf_scds)
  5371. {
  5372. struct drm_display_info *info = &connector->display_info;
  5373. struct drm_hdmi_info *hdmi = &info->hdmi;
  5374. struct drm_hdmi_dsc_cap *hdmi_dsc = &hdmi->dsc_cap;
  5375. int max_tmds_clock = 0;
  5376. u8 max_frl_rate = 0;
  5377. bool dsc_support = false;
  5378. info->has_hdmi_infoframe = true;
  5379. if (hf_scds[6] & 0x80) {
  5380. hdmi->scdc.supported = true;
  5381. if (hf_scds[6] & 0x40)
  5382. hdmi->scdc.read_request = true;
  5383. }
  5384. /*
  5385. * All HDMI 2.0 monitors must support scrambling at rates > 340 MHz.
  5386. * And as per the spec, three factors confirm this:
  5387. * * Availability of a HF-VSDB block in EDID (check)
  5388. * * Non zero Max_TMDS_Char_Rate filed in HF-VSDB (let's check)
  5389. * * SCDC support available (let's check)
  5390. * Lets check it out.
  5391. */
  5392. if (hf_scds[5]) {
  5393. struct drm_scdc *scdc = &hdmi->scdc;
  5394. /* max clock is 5000 KHz times block value */
  5395. max_tmds_clock = hf_scds[5] * 5000;
  5396. if (max_tmds_clock > 340000) {
  5397. info->max_tmds_clock = max_tmds_clock;
  5398. }
  5399. if (scdc->supported) {
  5400. scdc->scrambling.supported = true;
  5401. /* Few sinks support scrambling for clocks < 340M */
  5402. if ((hf_scds[6] & 0x8))
  5403. scdc->scrambling.low_rates = true;
  5404. }
  5405. }
  5406. if (hf_scds[7]) {
  5407. max_frl_rate = (hf_scds[7] & DRM_EDID_MAX_FRL_RATE_MASK) >> 4;
  5408. drm_get_max_frl_rate(max_frl_rate, &hdmi->max_lanes,
  5409. &hdmi->max_frl_rate_per_lane);
  5410. }
  5411. drm_parse_ycbcr420_deep_color_info(connector, hf_scds);
  5412. if (cea_db_payload_len(hf_scds) >= 11 && hf_scds[11]) {
  5413. drm_parse_dsc_info(hdmi_dsc, hf_scds);
  5414. dsc_support = true;
  5415. }
  5416. drm_dbg_kms(connector->dev,
  5417. "[CONNECTOR:%d:%s] HF-VSDB: max TMDS clock: %d KHz, HDMI 2.1 support: %s, DSC 1.2 support: %s\n",
  5418. connector->base.id, connector->name,
  5419. max_tmds_clock, str_yes_no(max_frl_rate), str_yes_no(dsc_support));
  5420. }
  5421. static void drm_parse_hdmi_deep_color_info(struct drm_connector *connector,
  5422. const u8 *hdmi)
  5423. {
  5424. struct drm_display_info *info = &connector->display_info;
  5425. unsigned int dc_bpc = 0;
  5426. /* HDMI supports at least 8 bpc */
  5427. info->bpc = 8;
  5428. if (cea_db_payload_len(hdmi) < 6)
  5429. return;
  5430. if (hdmi[6] & DRM_EDID_HDMI_DC_30) {
  5431. dc_bpc = 10;
  5432. info->edid_hdmi_rgb444_dc_modes |= DRM_EDID_HDMI_DC_30;
  5433. drm_dbg_kms(connector->dev, "[CONNECTOR:%d:%s] HDMI sink does deep color 30.\n",
  5434. connector->base.id, connector->name);
  5435. }
  5436. if (hdmi[6] & DRM_EDID_HDMI_DC_36) {
  5437. dc_bpc = 12;
  5438. info->edid_hdmi_rgb444_dc_modes |= DRM_EDID_HDMI_DC_36;
  5439. drm_dbg_kms(connector->dev, "[CONNECTOR:%d:%s] HDMI sink does deep color 36.\n",
  5440. connector->base.id, connector->name);
  5441. }
  5442. if (hdmi[6] & DRM_EDID_HDMI_DC_48) {
  5443. dc_bpc = 16;
  5444. info->edid_hdmi_rgb444_dc_modes |= DRM_EDID_HDMI_DC_48;
  5445. drm_dbg_kms(connector->dev, "[CONNECTOR:%d:%s] HDMI sink does deep color 48.\n",
  5446. connector->base.id, connector->name);
  5447. }
  5448. if (dc_bpc == 0) {
  5449. drm_dbg_kms(connector->dev, "[CONNECTOR:%d:%s] No deep color support on this HDMI sink.\n",
  5450. connector->base.id, connector->name);
  5451. return;
  5452. }
  5453. drm_dbg_kms(connector->dev, "[CONNECTOR:%d:%s] Assigning HDMI sink color depth as %d bpc.\n",
  5454. connector->base.id, connector->name, dc_bpc);
  5455. info->bpc = dc_bpc;
  5456. /* YCRCB444 is optional according to spec. */
  5457. if (hdmi[6] & DRM_EDID_HDMI_DC_Y444) {
  5458. info->edid_hdmi_ycbcr444_dc_modes = info->edid_hdmi_rgb444_dc_modes;
  5459. drm_dbg_kms(connector->dev, "[CONNECTOR:%d:%s] HDMI sink does YCRCB444 in deep color.\n",
  5460. connector->base.id, connector->name);
  5461. }
  5462. /*
  5463. * Spec says that if any deep color mode is supported at all,
  5464. * then deep color 36 bit must be supported.
  5465. */
  5466. if (!(hdmi[6] & DRM_EDID_HDMI_DC_36)) {
  5467. drm_dbg_kms(connector->dev, "[CONNECTOR:%d:%s] HDMI sink should do DC_36, but does not!\n",
  5468. connector->base.id, connector->name);
  5469. }
  5470. }
  5471. /* HDMI Vendor-Specific Data Block (HDMI VSDB, H14b-VSDB) */
  5472. static void
  5473. drm_parse_hdmi_vsdb_video(struct drm_connector *connector, const u8 *db)
  5474. {
  5475. struct drm_display_info *info = &connector->display_info;
  5476. u8 len = cea_db_payload_len(db);
  5477. info->is_hdmi = true;
  5478. info->source_physical_address = (db[4] << 8) | db[5];
  5479. if (len >= 6)
  5480. info->dvi_dual = db[6] & 1;
  5481. if (len >= 7)
  5482. info->max_tmds_clock = db[7] * 5000;
  5483. /*
  5484. * Try to infer whether the sink supports HDMI infoframes.
  5485. *
  5486. * HDMI infoframe support was first added in HDMI 1.4. Assume the sink
  5487. * supports infoframes if HDMI_Video_present is set.
  5488. */
  5489. if (len >= 8 && db[8] & BIT(5))
  5490. info->has_hdmi_infoframe = true;
  5491. drm_dbg_kms(connector->dev, "[CONNECTOR:%d:%s] HDMI: DVI dual %d, max TMDS clock %d kHz\n",
  5492. connector->base.id, connector->name,
  5493. info->dvi_dual, info->max_tmds_clock);
  5494. drm_parse_hdmi_deep_color_info(connector, db);
  5495. }
  5496. /*
  5497. * See EDID extension for head-mounted and specialized monitors, specified at:
  5498. * https://docs.microsoft.com/en-us/windows-hardware/drivers/display/specialized-monitors-edid-extension
  5499. */
  5500. static void drm_parse_microsoft_vsdb(struct drm_connector *connector,
  5501. const u8 *db)
  5502. {
  5503. struct drm_display_info *info = &connector->display_info;
  5504. u8 version = db[4];
  5505. bool desktop_usage = db[5] & BIT(6);
  5506. /* Version 1 and 2 for HMDs, version 3 flags desktop usage explicitly */
  5507. if (version == 1 || version == 2 || (version == 3 && !desktop_usage))
  5508. info->non_desktop = true;
  5509. drm_dbg_kms(connector->dev,
  5510. "[CONNECTOR:%d:%s] HMD or specialized display VSDB version %u: 0x%02x\n",
  5511. connector->base.id, connector->name, version, db[5]);
  5512. }
  5513. static void drm_parse_cea_ext(struct drm_connector *connector,
  5514. const struct drm_edid *drm_edid)
  5515. {
  5516. struct drm_display_info *info = &connector->display_info;
  5517. struct drm_edid_iter edid_iter;
  5518. const struct cea_db *db;
  5519. struct cea_db_iter iter;
  5520. const u8 *edid_ext;
  5521. u64 y420cmdb_map = 0;
  5522. drm_edid_iter_begin(drm_edid, &edid_iter);
  5523. drm_edid_iter_for_each(edid_ext, &edid_iter) {
  5524. if (edid_ext[0] != CEA_EXT)
  5525. continue;
  5526. if (!info->cea_rev)
  5527. info->cea_rev = edid_ext[1];
  5528. if (info->cea_rev != edid_ext[1])
  5529. drm_dbg_kms(connector->dev,
  5530. "[CONNECTOR:%d:%s] CEA extension version mismatch %u != %u\n",
  5531. connector->base.id, connector->name,
  5532. info->cea_rev, edid_ext[1]);
  5533. /* The existence of a CTA extension should imply RGB support */
  5534. info->color_formats = DRM_COLOR_FORMAT_RGB444;
  5535. if (edid_ext[3] & EDID_CEA_YCRCB444)
  5536. info->color_formats |= DRM_COLOR_FORMAT_YCBCR444;
  5537. if (edid_ext[3] & EDID_CEA_YCRCB422)
  5538. info->color_formats |= DRM_COLOR_FORMAT_YCBCR422;
  5539. if (edid_ext[3] & EDID_BASIC_AUDIO)
  5540. info->has_audio = true;
  5541. }
  5542. drm_edid_iter_end(&edid_iter);
  5543. cea_db_iter_edid_begin(drm_edid, &iter);
  5544. cea_db_iter_for_each(db, &iter) {
  5545. /* FIXME: convert parsers to use struct cea_db */
  5546. const u8 *data = (const u8 *)db;
  5547. if (cea_db_is_hdmi_vsdb(db))
  5548. drm_parse_hdmi_vsdb_video(connector, data);
  5549. else if (cea_db_is_hdmi_forum_vsdb(db) ||
  5550. cea_db_is_hdmi_forum_scdb(db))
  5551. drm_parse_hdmi_forum_scds(connector, data);
  5552. else if (cea_db_is_microsoft_vsdb(db))
  5553. drm_parse_microsoft_vsdb(connector, data);
  5554. else if (cea_db_is_y420cmdb(db))
  5555. parse_cta_y420cmdb(connector, db, &y420cmdb_map);
  5556. else if (cea_db_is_y420vdb(db))
  5557. parse_cta_y420vdb(connector, db);
  5558. else if (cea_db_is_vcdb(db))
  5559. drm_parse_vcdb(connector, data);
  5560. else if (cea_db_is_hdmi_hdr_metadata_block(db))
  5561. drm_parse_hdr_metadata_block(connector, data);
  5562. else if (cea_db_tag(db) == CTA_DB_VIDEO)
  5563. parse_cta_vdb(connector, db);
  5564. else if (cea_db_tag(db) == CTA_DB_AUDIO)
  5565. info->has_audio = true;
  5566. }
  5567. cea_db_iter_end(&iter);
  5568. if (y420cmdb_map)
  5569. update_cta_y420cmdb(connector, y420cmdb_map);
  5570. }
  5571. static
  5572. void get_monitor_range(const struct detailed_timing *timing, void *c)
  5573. {
  5574. struct detailed_mode_closure *closure = c;
  5575. struct drm_display_info *info = &closure->connector->display_info;
  5576. struct drm_monitor_range_info *monitor_range = &info->monitor_range;
  5577. const struct detailed_non_pixel *data = &timing->data.other_data;
  5578. const struct detailed_data_monitor_range *range = &data->data.range;
  5579. const struct edid *edid = closure->drm_edid->edid;
  5580. if (!is_display_descriptor(timing, EDID_DETAIL_MONITOR_RANGE))
  5581. return;
  5582. /*
  5583. * These limits are used to determine the VRR refresh
  5584. * rate range. Only the "range limits only" variant
  5585. * of the range descriptor seems to guarantee that
  5586. * any and all timings are accepted by the sink, as
  5587. * opposed to just timings conforming to the indicated
  5588. * formula (GTF/GTF2/CVT). Thus other variants of the
  5589. * range descriptor are not accepted here.
  5590. */
  5591. if (range->flags != DRM_EDID_RANGE_LIMITS_ONLY_FLAG)
  5592. return;
  5593. monitor_range->min_vfreq = range->min_vfreq;
  5594. monitor_range->max_vfreq = range->max_vfreq;
  5595. if (edid->revision >= 4) {
  5596. if (data->pad2 & DRM_EDID_RANGE_OFFSET_MIN_VFREQ)
  5597. monitor_range->min_vfreq += 255;
  5598. if (data->pad2 & DRM_EDID_RANGE_OFFSET_MAX_VFREQ)
  5599. monitor_range->max_vfreq += 255;
  5600. }
  5601. }
  5602. static void drm_get_monitor_range(struct drm_connector *connector,
  5603. const struct drm_edid *drm_edid)
  5604. {
  5605. const struct drm_display_info *info = &connector->display_info;
  5606. struct detailed_mode_closure closure = {
  5607. .connector = connector,
  5608. .drm_edid = drm_edid,
  5609. };
  5610. if (drm_edid->edid->revision < 4)
  5611. return;
  5612. if (!(drm_edid->edid->features & DRM_EDID_FEATURE_CONTINUOUS_FREQ))
  5613. return;
  5614. drm_for_each_detailed_block(drm_edid, get_monitor_range, &closure);
  5615. drm_dbg_kms(connector->dev,
  5616. "[CONNECTOR:%d:%s] Supported Monitor Refresh rate range is %d Hz - %d Hz\n",
  5617. connector->base.id, connector->name,
  5618. info->monitor_range.min_vfreq, info->monitor_range.max_vfreq);
  5619. }
  5620. static void drm_parse_vesa_mso_data(struct drm_connector *connector,
  5621. const struct displayid_block *block)
  5622. {
  5623. struct displayid_vesa_vendor_specific_block *vesa =
  5624. (struct displayid_vesa_vendor_specific_block *)block;
  5625. struct drm_display_info *info = &connector->display_info;
  5626. if (block->num_bytes < 3) {
  5627. drm_dbg_kms(connector->dev,
  5628. "[CONNECTOR:%d:%s] Unexpected vendor block size %u\n",
  5629. connector->base.id, connector->name, block->num_bytes);
  5630. return;
  5631. }
  5632. if (oui(vesa->oui[0], vesa->oui[1], vesa->oui[2]) != VESA_IEEE_OUI)
  5633. return;
  5634. if (sizeof(*vesa) != sizeof(*block) + block->num_bytes) {
  5635. drm_dbg_kms(connector->dev,
  5636. "[CONNECTOR:%d:%s] Unexpected VESA vendor block size\n",
  5637. connector->base.id, connector->name);
  5638. return;
  5639. }
  5640. switch (FIELD_GET(DISPLAYID_VESA_MSO_MODE, vesa->mso)) {
  5641. default:
  5642. drm_dbg_kms(connector->dev, "[CONNECTOR:%d:%s] Reserved MSO mode value\n",
  5643. connector->base.id, connector->name);
  5644. fallthrough;
  5645. case 0:
  5646. info->mso_stream_count = 0;
  5647. break;
  5648. case 1:
  5649. info->mso_stream_count = 2; /* 2 or 4 links */
  5650. break;
  5651. case 2:
  5652. info->mso_stream_count = 4; /* 4 links */
  5653. break;
  5654. }
  5655. if (!info->mso_stream_count) {
  5656. info->mso_pixel_overlap = 0;
  5657. return;
  5658. }
  5659. info->mso_pixel_overlap = FIELD_GET(DISPLAYID_VESA_MSO_OVERLAP, vesa->mso);
  5660. if (info->mso_pixel_overlap > 8) {
  5661. drm_dbg_kms(connector->dev,
  5662. "[CONNECTOR:%d:%s] Reserved MSO pixel overlap value %u\n",
  5663. connector->base.id, connector->name,
  5664. info->mso_pixel_overlap);
  5665. info->mso_pixel_overlap = 8;
  5666. }
  5667. drm_dbg_kms(connector->dev,
  5668. "[CONNECTOR:%d:%s] MSO stream count %u, pixel overlap %u\n",
  5669. connector->base.id, connector->name,
  5670. info->mso_stream_count, info->mso_pixel_overlap);
  5671. }
  5672. static void drm_update_mso(struct drm_connector *connector,
  5673. const struct drm_edid *drm_edid)
  5674. {
  5675. const struct displayid_block *block;
  5676. struct displayid_iter iter;
  5677. displayid_iter_edid_begin(drm_edid, &iter);
  5678. displayid_iter_for_each(block, &iter) {
  5679. if (block->tag == DATA_BLOCK_2_VENDOR_SPECIFIC)
  5680. drm_parse_vesa_mso_data(connector, block);
  5681. }
  5682. displayid_iter_end(&iter);
  5683. }
  5684. /* A connector has no EDID information, so we've got no EDID to compute quirks from. Reset
  5685. * all of the values which would have been set from EDID
  5686. */
  5687. static void drm_reset_display_info(struct drm_connector *connector)
  5688. {
  5689. struct drm_display_info *info = &connector->display_info;
  5690. info->width_mm = 0;
  5691. info->height_mm = 0;
  5692. info->bpc = 0;
  5693. info->color_formats = 0;
  5694. info->cea_rev = 0;
  5695. info->max_tmds_clock = 0;
  5696. info->dvi_dual = false;
  5697. info->is_hdmi = false;
  5698. info->has_audio = false;
  5699. info->has_hdmi_infoframe = false;
  5700. info->rgb_quant_range_selectable = false;
  5701. memset(&info->hdmi, 0, sizeof(info->hdmi));
  5702. memset(&connector->hdr_sink_metadata, 0, sizeof(connector->hdr_sink_metadata));
  5703. info->edid_hdmi_rgb444_dc_modes = 0;
  5704. info->edid_hdmi_ycbcr444_dc_modes = 0;
  5705. info->non_desktop = 0;
  5706. memset(&info->monitor_range, 0, sizeof(info->monitor_range));
  5707. memset(&info->luminance_range, 0, sizeof(info->luminance_range));
  5708. info->mso_stream_count = 0;
  5709. info->mso_pixel_overlap = 0;
  5710. info->max_dsc_bpp = 0;
  5711. kfree(info->vics);
  5712. info->vics = NULL;
  5713. info->vics_len = 0;
  5714. info->quirks = 0;
  5715. info->source_physical_address = CEC_PHYS_ADDR_INVALID;
  5716. }
  5717. static void update_displayid_info(struct drm_connector *connector,
  5718. const struct drm_edid *drm_edid)
  5719. {
  5720. struct drm_display_info *info = &connector->display_info;
  5721. const struct displayid_block *block;
  5722. struct displayid_iter iter;
  5723. displayid_iter_edid_begin(drm_edid, &iter);
  5724. displayid_iter_for_each(block, &iter) {
  5725. drm_dbg_kms(connector->dev,
  5726. "[CONNECTOR:%d:%s] DisplayID extension version 0x%02x, primary use 0x%02x\n",
  5727. connector->base.id, connector->name,
  5728. displayid_version(&iter),
  5729. displayid_primary_use(&iter));
  5730. if (displayid_version(&iter) == DISPLAY_ID_STRUCTURE_VER_20 &&
  5731. (displayid_primary_use(&iter) == PRIMARY_USE_HEAD_MOUNTED_VR ||
  5732. displayid_primary_use(&iter) == PRIMARY_USE_HEAD_MOUNTED_AR))
  5733. info->non_desktop = true;
  5734. /*
  5735. * We're only interested in the base section here, no need to
  5736. * iterate further.
  5737. */
  5738. break;
  5739. }
  5740. displayid_iter_end(&iter);
  5741. }
  5742. static void update_display_info(struct drm_connector *connector,
  5743. const struct drm_edid *drm_edid)
  5744. {
  5745. struct drm_display_info *info = &connector->display_info;
  5746. const struct edid *edid;
  5747. drm_reset_display_info(connector);
  5748. clear_eld(connector);
  5749. if (!drm_edid)
  5750. return;
  5751. edid = drm_edid->edid;
  5752. info->quirks = edid_get_quirks(drm_edid);
  5753. info->width_mm = edid->width_cm * 10;
  5754. info->height_mm = edid->height_cm * 10;
  5755. drm_get_monitor_range(connector, drm_edid);
  5756. if (edid->revision < 3)
  5757. goto out;
  5758. if (!drm_edid_is_digital(drm_edid))
  5759. goto out;
  5760. info->color_formats |= DRM_COLOR_FORMAT_RGB444;
  5761. drm_parse_cea_ext(connector, drm_edid);
  5762. update_displayid_info(connector, drm_edid);
  5763. /*
  5764. * Digital sink with "DFP 1.x compliant TMDS" according to EDID 1.3?
  5765. *
  5766. * For such displays, the DFP spec 1.0, section 3.10 "EDID support"
  5767. * tells us to assume 8 bpc color depth if the EDID doesn't have
  5768. * extensions which tell otherwise.
  5769. */
  5770. if (info->bpc == 0 && edid->revision == 3 &&
  5771. edid->input & DRM_EDID_DIGITAL_DFP_1_X) {
  5772. info->bpc = 8;
  5773. drm_dbg_kms(connector->dev,
  5774. "[CONNECTOR:%d:%s] Assigning DFP sink color depth as %d bpc.\n",
  5775. connector->base.id, connector->name, info->bpc);
  5776. }
  5777. /* Only defined for 1.4 with digital displays */
  5778. if (edid->revision < 4)
  5779. goto out;
  5780. switch (edid->input & DRM_EDID_DIGITAL_DEPTH_MASK) {
  5781. case DRM_EDID_DIGITAL_DEPTH_6:
  5782. info->bpc = 6;
  5783. break;
  5784. case DRM_EDID_DIGITAL_DEPTH_8:
  5785. info->bpc = 8;
  5786. break;
  5787. case DRM_EDID_DIGITAL_DEPTH_10:
  5788. info->bpc = 10;
  5789. break;
  5790. case DRM_EDID_DIGITAL_DEPTH_12:
  5791. info->bpc = 12;
  5792. break;
  5793. case DRM_EDID_DIGITAL_DEPTH_14:
  5794. info->bpc = 14;
  5795. break;
  5796. case DRM_EDID_DIGITAL_DEPTH_16:
  5797. info->bpc = 16;
  5798. break;
  5799. case DRM_EDID_DIGITAL_DEPTH_UNDEF:
  5800. default:
  5801. info->bpc = 0;
  5802. break;
  5803. }
  5804. drm_dbg_kms(connector->dev,
  5805. "[CONNECTOR:%d:%s] Assigning EDID-1.4 digital sink color depth as %d bpc.\n",
  5806. connector->base.id, connector->name, info->bpc);
  5807. if (edid->features & DRM_EDID_FEATURE_RGB_YCRCB444)
  5808. info->color_formats |= DRM_COLOR_FORMAT_YCBCR444;
  5809. if (edid->features & DRM_EDID_FEATURE_RGB_YCRCB422)
  5810. info->color_formats |= DRM_COLOR_FORMAT_YCBCR422;
  5811. drm_update_mso(connector, drm_edid);
  5812. out:
  5813. if (info->quirks & EDID_QUIRK_NON_DESKTOP) {
  5814. drm_dbg_kms(connector->dev, "[CONNECTOR:%d:%s] Non-desktop display%s\n",
  5815. connector->base.id, connector->name,
  5816. info->non_desktop ? " (redundant quirk)" : "");
  5817. info->non_desktop = true;
  5818. }
  5819. if (info->quirks & EDID_QUIRK_CAP_DSC_15BPP)
  5820. info->max_dsc_bpp = 15;
  5821. if (info->quirks & EDID_QUIRK_FORCE_6BPC)
  5822. info->bpc = 6;
  5823. if (info->quirks & EDID_QUIRK_FORCE_8BPC)
  5824. info->bpc = 8;
  5825. if (info->quirks & EDID_QUIRK_FORCE_10BPC)
  5826. info->bpc = 10;
  5827. if (info->quirks & EDID_QUIRK_FORCE_12BPC)
  5828. info->bpc = 12;
  5829. /* Depends on info->cea_rev set by drm_parse_cea_ext() above */
  5830. drm_edid_to_eld(connector, drm_edid);
  5831. }
  5832. static struct drm_display_mode *drm_mode_displayid_detailed(struct drm_device *dev,
  5833. struct displayid_detailed_timings_1 *timings,
  5834. bool type_7)
  5835. {
  5836. struct drm_display_mode *mode;
  5837. unsigned pixel_clock = (timings->pixel_clock[0] |
  5838. (timings->pixel_clock[1] << 8) |
  5839. (timings->pixel_clock[2] << 16)) + 1;
  5840. unsigned hactive = (timings->hactive[0] | timings->hactive[1] << 8) + 1;
  5841. unsigned hblank = (timings->hblank[0] | timings->hblank[1] << 8) + 1;
  5842. unsigned hsync = (timings->hsync[0] | (timings->hsync[1] & 0x7f) << 8) + 1;
  5843. unsigned hsync_width = (timings->hsw[0] | timings->hsw[1] << 8) + 1;
  5844. unsigned vactive = (timings->vactive[0] | timings->vactive[1] << 8) + 1;
  5845. unsigned vblank = (timings->vblank[0] | timings->vblank[1] << 8) + 1;
  5846. unsigned vsync = (timings->vsync[0] | (timings->vsync[1] & 0x7f) << 8) + 1;
  5847. unsigned vsync_width = (timings->vsw[0] | timings->vsw[1] << 8) + 1;
  5848. bool hsync_positive = (timings->hsync[1] >> 7) & 0x1;
  5849. bool vsync_positive = (timings->vsync[1] >> 7) & 0x1;
  5850. mode = drm_mode_create(dev);
  5851. if (!mode)
  5852. return NULL;
  5853. /* resolution is kHz for type VII, and 10 kHz for type I */
  5854. mode->clock = type_7 ? pixel_clock : pixel_clock * 10;
  5855. mode->hdisplay = hactive;
  5856. mode->hsync_start = mode->hdisplay + hsync;
  5857. mode->hsync_end = mode->hsync_start + hsync_width;
  5858. mode->htotal = mode->hdisplay + hblank;
  5859. mode->vdisplay = vactive;
  5860. mode->vsync_start = mode->vdisplay + vsync;
  5861. mode->vsync_end = mode->vsync_start + vsync_width;
  5862. mode->vtotal = mode->vdisplay + vblank;
  5863. mode->flags = 0;
  5864. mode->flags |= hsync_positive ? DRM_MODE_FLAG_PHSYNC : DRM_MODE_FLAG_NHSYNC;
  5865. mode->flags |= vsync_positive ? DRM_MODE_FLAG_PVSYNC : DRM_MODE_FLAG_NVSYNC;
  5866. mode->type = DRM_MODE_TYPE_DRIVER;
  5867. if (timings->flags & 0x80)
  5868. mode->type |= DRM_MODE_TYPE_PREFERRED;
  5869. drm_mode_set_name(mode);
  5870. return mode;
  5871. }
  5872. static int add_displayid_detailed_1_modes(struct drm_connector *connector,
  5873. const struct displayid_block *block)
  5874. {
  5875. struct displayid_detailed_timing_block *det = (struct displayid_detailed_timing_block *)block;
  5876. int i;
  5877. int num_timings;
  5878. struct drm_display_mode *newmode;
  5879. int num_modes = 0;
  5880. bool type_7 = block->tag == DATA_BLOCK_2_TYPE_7_DETAILED_TIMING;
  5881. /* blocks must be multiple of 20 bytes length */
  5882. if (block->num_bytes % 20)
  5883. return 0;
  5884. num_timings = block->num_bytes / 20;
  5885. for (i = 0; i < num_timings; i++) {
  5886. struct displayid_detailed_timings_1 *timings = &det->timings[i];
  5887. newmode = drm_mode_displayid_detailed(connector->dev, timings, type_7);
  5888. if (!newmode)
  5889. continue;
  5890. drm_mode_probed_add(connector, newmode);
  5891. num_modes++;
  5892. }
  5893. return num_modes;
  5894. }
  5895. static int add_displayid_detailed_modes(struct drm_connector *connector,
  5896. const struct drm_edid *drm_edid)
  5897. {
  5898. const struct displayid_block *block;
  5899. struct displayid_iter iter;
  5900. int num_modes = 0;
  5901. displayid_iter_edid_begin(drm_edid, &iter);
  5902. displayid_iter_for_each(block, &iter) {
  5903. if (block->tag == DATA_BLOCK_TYPE_1_DETAILED_TIMING ||
  5904. block->tag == DATA_BLOCK_2_TYPE_7_DETAILED_TIMING)
  5905. num_modes += add_displayid_detailed_1_modes(connector, block);
  5906. }
  5907. displayid_iter_end(&iter);
  5908. return num_modes;
  5909. }
  5910. static int _drm_edid_connector_add_modes(struct drm_connector *connector,
  5911. const struct drm_edid *drm_edid)
  5912. {
  5913. const struct drm_display_info *info = &connector->display_info;
  5914. int num_modes = 0;
  5915. if (!drm_edid)
  5916. return 0;
  5917. /*
  5918. * EDID spec says modes should be preferred in this order:
  5919. * - preferred detailed mode
  5920. * - other detailed modes from base block
  5921. * - detailed modes from extension blocks
  5922. * - CVT 3-byte code modes
  5923. * - standard timing codes
  5924. * - established timing codes
  5925. * - modes inferred from GTF or CVT range information
  5926. *
  5927. * We get this pretty much right.
  5928. *
  5929. * XXX order for additional mode types in extension blocks?
  5930. */
  5931. num_modes += add_detailed_modes(connector, drm_edid);
  5932. num_modes += add_cvt_modes(connector, drm_edid);
  5933. num_modes += add_standard_modes(connector, drm_edid);
  5934. num_modes += add_established_modes(connector, drm_edid);
  5935. num_modes += add_cea_modes(connector, drm_edid);
  5936. num_modes += add_alternate_cea_modes(connector, drm_edid);
  5937. num_modes += add_displayid_detailed_modes(connector, drm_edid);
  5938. if (drm_edid->edid->features & DRM_EDID_FEATURE_CONTINUOUS_FREQ)
  5939. num_modes += add_inferred_modes(connector, drm_edid);
  5940. if (info->quirks & (EDID_QUIRK_PREFER_LARGE_60 | EDID_QUIRK_PREFER_LARGE_75))
  5941. edid_fixup_preferred(connector);
  5942. return num_modes;
  5943. }
  5944. static void _drm_update_tile_info(struct drm_connector *connector,
  5945. const struct drm_edid *drm_edid);
  5946. static int _drm_edid_connector_property_update(struct drm_connector *connector,
  5947. const struct drm_edid *drm_edid)
  5948. {
  5949. struct drm_device *dev = connector->dev;
  5950. int ret;
  5951. if (connector->edid_blob_ptr) {
  5952. const void *old_edid = connector->edid_blob_ptr->data;
  5953. size_t old_edid_size = connector->edid_blob_ptr->length;
  5954. if (old_edid && !drm_edid_eq(drm_edid, old_edid, old_edid_size)) {
  5955. connector->epoch_counter++;
  5956. drm_dbg_kms(dev, "[CONNECTOR:%d:%s] EDID changed, epoch counter %llu\n",
  5957. connector->base.id, connector->name,
  5958. connector->epoch_counter);
  5959. }
  5960. }
  5961. ret = drm_property_replace_global_blob(dev,
  5962. &connector->edid_blob_ptr,
  5963. drm_edid ? drm_edid->size : 0,
  5964. drm_edid ? drm_edid->edid : NULL,
  5965. &connector->base,
  5966. dev->mode_config.edid_property);
  5967. if (ret) {
  5968. drm_dbg_kms(dev, "[CONNECTOR:%d:%s] EDID property update failed (%d)\n",
  5969. connector->base.id, connector->name, ret);
  5970. goto out;
  5971. }
  5972. ret = drm_object_property_set_value(&connector->base,
  5973. dev->mode_config.non_desktop_property,
  5974. connector->display_info.non_desktop);
  5975. if (ret) {
  5976. drm_dbg_kms(dev, "[CONNECTOR:%d:%s] Non-desktop property update failed (%d)\n",
  5977. connector->base.id, connector->name, ret);
  5978. goto out;
  5979. }
  5980. ret = drm_connector_set_tile_property(connector);
  5981. if (ret) {
  5982. drm_dbg_kms(dev, "[CONNECTOR:%d:%s] Tile property update failed (%d)\n",
  5983. connector->base.id, connector->name, ret);
  5984. goto out;
  5985. }
  5986. out:
  5987. return ret;
  5988. }
  5989. /* For sysfs edid show implementation */
  5990. ssize_t drm_edid_connector_property_show(struct drm_connector *connector,
  5991. char *buf, loff_t off, size_t count)
  5992. {
  5993. const void *edid;
  5994. size_t size;
  5995. ssize_t ret = 0;
  5996. mutex_lock(&connector->dev->mode_config.mutex);
  5997. if (!connector->edid_blob_ptr)
  5998. goto unlock;
  5999. edid = connector->edid_blob_ptr->data;
  6000. size = connector->edid_blob_ptr->length;
  6001. if (!edid)
  6002. goto unlock;
  6003. if (off >= size)
  6004. goto unlock;
  6005. if (off + count > size)
  6006. count = size - off;
  6007. memcpy(buf, edid + off, count);
  6008. ret = count;
  6009. unlock:
  6010. mutex_unlock(&connector->dev->mode_config.mutex);
  6011. return ret;
  6012. }
  6013. /**
  6014. * drm_edid_connector_update - Update connector information from EDID
  6015. * @connector: Connector
  6016. * @drm_edid: EDID
  6017. *
  6018. * Update the connector display info, ELD, HDR metadata, relevant properties,
  6019. * etc. from the passed in EDID.
  6020. *
  6021. * If EDID is NULL, reset the information.
  6022. *
  6023. * Must be called before calling drm_edid_connector_add_modes().
  6024. *
  6025. * Return: 0 on success, negative error on errors.
  6026. */
  6027. int drm_edid_connector_update(struct drm_connector *connector,
  6028. const struct drm_edid *drm_edid)
  6029. {
  6030. update_display_info(connector, drm_edid);
  6031. _drm_update_tile_info(connector, drm_edid);
  6032. return _drm_edid_connector_property_update(connector, drm_edid);
  6033. }
  6034. EXPORT_SYMBOL(drm_edid_connector_update);
  6035. /**
  6036. * drm_edid_connector_add_modes - Update probed modes from the EDID property
  6037. * @connector: Connector
  6038. *
  6039. * Add the modes from the previously updated EDID property to the connector
  6040. * probed modes list.
  6041. *
  6042. * drm_edid_connector_update() must have been called before this to update the
  6043. * EDID property.
  6044. *
  6045. * Return: The number of modes added, or 0 if we couldn't find any.
  6046. */
  6047. int drm_edid_connector_add_modes(struct drm_connector *connector)
  6048. {
  6049. const struct drm_edid *drm_edid = NULL;
  6050. int count;
  6051. if (connector->edid_blob_ptr)
  6052. drm_edid = drm_edid_alloc(connector->edid_blob_ptr->data,
  6053. connector->edid_blob_ptr->length);
  6054. count = _drm_edid_connector_add_modes(connector, drm_edid);
  6055. drm_edid_free(drm_edid);
  6056. return count;
  6057. }
  6058. EXPORT_SYMBOL(drm_edid_connector_add_modes);
  6059. /**
  6060. * drm_connector_update_edid_property - update the edid property of a connector
  6061. * @connector: drm connector
  6062. * @edid: new value of the edid property
  6063. *
  6064. * This function creates a new blob modeset object and assigns its id to the
  6065. * connector's edid property.
  6066. * Since we also parse tile information from EDID's displayID block, we also
  6067. * set the connector's tile property here. See drm_connector_set_tile_property()
  6068. * for more details.
  6069. *
  6070. * This function is deprecated. Use drm_edid_connector_update() instead.
  6071. *
  6072. * Returns:
  6073. * Zero on success, negative errno on failure.
  6074. */
  6075. int drm_connector_update_edid_property(struct drm_connector *connector,
  6076. const struct edid *edid)
  6077. {
  6078. struct drm_edid drm_edid;
  6079. return drm_edid_connector_update(connector, drm_edid_legacy_init(&drm_edid, edid));
  6080. }
  6081. EXPORT_SYMBOL(drm_connector_update_edid_property);
  6082. /**
  6083. * drm_add_edid_modes - add modes from EDID data, if available
  6084. * @connector: connector we're probing
  6085. * @edid: EDID data
  6086. *
  6087. * Add the specified modes to the connector's mode list. Also fills out the
  6088. * &drm_display_info structure and ELD in @connector with any information which
  6089. * can be derived from the edid.
  6090. *
  6091. * This function is deprecated. Use drm_edid_connector_add_modes() instead.
  6092. *
  6093. * Return: The number of modes added or 0 if we couldn't find any.
  6094. */
  6095. int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid)
  6096. {
  6097. struct drm_edid _drm_edid;
  6098. const struct drm_edid *drm_edid;
  6099. if (edid && !drm_edid_is_valid(edid)) {
  6100. drm_warn(connector->dev, "[CONNECTOR:%d:%s] EDID invalid.\n",
  6101. connector->base.id, connector->name);
  6102. edid = NULL;
  6103. }
  6104. drm_edid = drm_edid_legacy_init(&_drm_edid, edid);
  6105. update_display_info(connector, drm_edid);
  6106. return _drm_edid_connector_add_modes(connector, drm_edid);
  6107. }
  6108. EXPORT_SYMBOL(drm_add_edid_modes);
  6109. /**
  6110. * drm_add_modes_noedid - add modes for the connectors without EDID
  6111. * @connector: connector we're probing
  6112. * @hdisplay: the horizontal display limit
  6113. * @vdisplay: the vertical display limit
  6114. *
  6115. * Add the specified modes to the connector's mode list. Only when the
  6116. * hdisplay/vdisplay is not beyond the given limit, it will be added.
  6117. *
  6118. * Return: The number of modes added or 0 if we couldn't find any.
  6119. */
  6120. int drm_add_modes_noedid(struct drm_connector *connector,
  6121. int hdisplay, int vdisplay)
  6122. {
  6123. int i, count, num_modes = 0;
  6124. struct drm_display_mode *mode;
  6125. struct drm_device *dev = connector->dev;
  6126. count = ARRAY_SIZE(drm_dmt_modes);
  6127. if (hdisplay < 0)
  6128. hdisplay = 0;
  6129. if (vdisplay < 0)
  6130. vdisplay = 0;
  6131. for (i = 0; i < count; i++) {
  6132. const struct drm_display_mode *ptr = &drm_dmt_modes[i];
  6133. if (hdisplay && vdisplay) {
  6134. /*
  6135. * Only when two are valid, they will be used to check
  6136. * whether the mode should be added to the mode list of
  6137. * the connector.
  6138. */
  6139. if (ptr->hdisplay > hdisplay ||
  6140. ptr->vdisplay > vdisplay)
  6141. continue;
  6142. }
  6143. if (drm_mode_vrefresh(ptr) > 61)
  6144. continue;
  6145. mode = drm_mode_duplicate(dev, ptr);
  6146. if (mode) {
  6147. drm_mode_probed_add(connector, mode);
  6148. num_modes++;
  6149. }
  6150. }
  6151. return num_modes;
  6152. }
  6153. EXPORT_SYMBOL(drm_add_modes_noedid);
  6154. static bool is_hdmi2_sink(const struct drm_connector *connector)
  6155. {
  6156. /*
  6157. * FIXME: sil-sii8620 doesn't have a connector around when
  6158. * we need one, so we have to be prepared for a NULL connector.
  6159. */
  6160. if (!connector)
  6161. return true;
  6162. return connector->display_info.hdmi.scdc.supported ||
  6163. connector->display_info.color_formats & DRM_COLOR_FORMAT_YCBCR420;
  6164. }
  6165. static u8 drm_mode_hdmi_vic(const struct drm_connector *connector,
  6166. const struct drm_display_mode *mode)
  6167. {
  6168. bool has_hdmi_infoframe = connector ?
  6169. connector->display_info.has_hdmi_infoframe : false;
  6170. if (!has_hdmi_infoframe)
  6171. return 0;
  6172. /* No HDMI VIC when signalling 3D video format */
  6173. if (mode->flags & DRM_MODE_FLAG_3D_MASK)
  6174. return 0;
  6175. return drm_match_hdmi_mode(mode);
  6176. }
  6177. static u8 drm_mode_cea_vic(const struct drm_connector *connector,
  6178. const struct drm_display_mode *mode)
  6179. {
  6180. /*
  6181. * HDMI spec says if a mode is found in HDMI 1.4b 4K modes
  6182. * we should send its VIC in vendor infoframes, else send the
  6183. * VIC in AVI infoframes. Lets check if this mode is present in
  6184. * HDMI 1.4b 4K modes
  6185. */
  6186. if (drm_mode_hdmi_vic(connector, mode))
  6187. return 0;
  6188. return drm_match_cea_mode(mode);
  6189. }
  6190. /*
  6191. * Avoid sending VICs defined in HDMI 2.0 in AVI infoframes to sinks that
  6192. * conform to HDMI 1.4.
  6193. *
  6194. * HDMI 1.4 (CTA-861-D) VIC range: [1..64]
  6195. * HDMI 2.0 (CTA-861-F) VIC range: [1..107]
  6196. *
  6197. * If the sink lists the VIC in CTA VDB, assume it's fine, regardless of HDMI
  6198. * version.
  6199. */
  6200. static u8 vic_for_avi_infoframe(const struct drm_connector *connector, u8 vic)
  6201. {
  6202. if (!is_hdmi2_sink(connector) && vic > 64 &&
  6203. !cta_vdb_has_vic(connector, vic))
  6204. return 0;
  6205. return vic;
  6206. }
  6207. /**
  6208. * drm_hdmi_avi_infoframe_from_display_mode() - fill an HDMI AVI infoframe with
  6209. * data from a DRM display mode
  6210. * @frame: HDMI AVI infoframe
  6211. * @connector: the connector
  6212. * @mode: DRM display mode
  6213. *
  6214. * Return: 0 on success or a negative error code on failure.
  6215. */
  6216. int
  6217. drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
  6218. const struct drm_connector *connector,
  6219. const struct drm_display_mode *mode)
  6220. {
  6221. enum hdmi_picture_aspect picture_aspect;
  6222. u8 vic, hdmi_vic;
  6223. if (!frame || !mode)
  6224. return -EINVAL;
  6225. hdmi_avi_infoframe_init(frame);
  6226. if (mode->flags & DRM_MODE_FLAG_DBLCLK)
  6227. frame->pixel_repeat = 1;
  6228. vic = drm_mode_cea_vic(connector, mode);
  6229. hdmi_vic = drm_mode_hdmi_vic(connector, mode);
  6230. frame->picture_aspect = HDMI_PICTURE_ASPECT_NONE;
  6231. /*
  6232. * As some drivers don't support atomic, we can't use connector state.
  6233. * So just initialize the frame with default values, just the same way
  6234. * as it's done with other properties here.
  6235. */
  6236. frame->content_type = HDMI_CONTENT_TYPE_GRAPHICS;
  6237. frame->itc = 0;
  6238. /*
  6239. * Populate picture aspect ratio from either
  6240. * user input (if specified) or from the CEA/HDMI mode lists.
  6241. */
  6242. picture_aspect = mode->picture_aspect_ratio;
  6243. if (picture_aspect == HDMI_PICTURE_ASPECT_NONE) {
  6244. if (vic)
  6245. picture_aspect = drm_get_cea_aspect_ratio(vic);
  6246. else if (hdmi_vic)
  6247. picture_aspect = drm_get_hdmi_aspect_ratio(hdmi_vic);
  6248. }
  6249. /*
  6250. * The infoframe can't convey anything but none, 4:3
  6251. * and 16:9, so if the user has asked for anything else
  6252. * we can only satisfy it by specifying the right VIC.
  6253. */
  6254. if (picture_aspect > HDMI_PICTURE_ASPECT_16_9) {
  6255. if (vic) {
  6256. if (picture_aspect != drm_get_cea_aspect_ratio(vic))
  6257. return -EINVAL;
  6258. } else if (hdmi_vic) {
  6259. if (picture_aspect != drm_get_hdmi_aspect_ratio(hdmi_vic))
  6260. return -EINVAL;
  6261. } else {
  6262. return -EINVAL;
  6263. }
  6264. picture_aspect = HDMI_PICTURE_ASPECT_NONE;
  6265. }
  6266. frame->video_code = vic_for_avi_infoframe(connector, vic);
  6267. frame->picture_aspect = picture_aspect;
  6268. frame->active_aspect = HDMI_ACTIVE_ASPECT_PICTURE;
  6269. frame->scan_mode = HDMI_SCAN_MODE_UNDERSCAN;
  6270. return 0;
  6271. }
  6272. EXPORT_SYMBOL(drm_hdmi_avi_infoframe_from_display_mode);
  6273. /**
  6274. * drm_hdmi_avi_infoframe_quant_range() - fill the HDMI AVI infoframe
  6275. * quantization range information
  6276. * @frame: HDMI AVI infoframe
  6277. * @connector: the connector
  6278. * @mode: DRM display mode
  6279. * @rgb_quant_range: RGB quantization range (Q)
  6280. */
  6281. void
  6282. drm_hdmi_avi_infoframe_quant_range(struct hdmi_avi_infoframe *frame,
  6283. const struct drm_connector *connector,
  6284. const struct drm_display_mode *mode,
  6285. enum hdmi_quantization_range rgb_quant_range)
  6286. {
  6287. const struct drm_display_info *info = &connector->display_info;
  6288. /*
  6289. * CEA-861:
  6290. * "A Source shall not send a non-zero Q value that does not correspond
  6291. * to the default RGB Quantization Range for the transmitted Picture
  6292. * unless the Sink indicates support for the Q bit in a Video
  6293. * Capabilities Data Block."
  6294. *
  6295. * HDMI 2.0 recommends sending non-zero Q when it does match the
  6296. * default RGB quantization range for the mode, even when QS=0.
  6297. */
  6298. if (info->rgb_quant_range_selectable ||
  6299. rgb_quant_range == drm_default_rgb_quant_range(mode))
  6300. frame->quantization_range = rgb_quant_range;
  6301. else
  6302. frame->quantization_range = HDMI_QUANTIZATION_RANGE_DEFAULT;
  6303. /*
  6304. * CEA-861-F:
  6305. * "When transmitting any RGB colorimetry, the Source should set the
  6306. * YQ-field to match the RGB Quantization Range being transmitted
  6307. * (e.g., when Limited Range RGB, set YQ=0 or when Full Range RGB,
  6308. * set YQ=1) and the Sink shall ignore the YQ-field."
  6309. *
  6310. * Unfortunate certain sinks (eg. VIZ Model 67/E261VA) get confused
  6311. * by non-zero YQ when receiving RGB. There doesn't seem to be any
  6312. * good way to tell which version of CEA-861 the sink supports, so
  6313. * we limit non-zero YQ to HDMI 2.0 sinks only as HDMI 2.0 is based
  6314. * on CEA-861-F.
  6315. */
  6316. if (!is_hdmi2_sink(connector) ||
  6317. rgb_quant_range == HDMI_QUANTIZATION_RANGE_LIMITED)
  6318. frame->ycc_quantization_range =
  6319. HDMI_YCC_QUANTIZATION_RANGE_LIMITED;
  6320. else
  6321. frame->ycc_quantization_range =
  6322. HDMI_YCC_QUANTIZATION_RANGE_FULL;
  6323. }
  6324. EXPORT_SYMBOL(drm_hdmi_avi_infoframe_quant_range);
  6325. static enum hdmi_3d_structure
  6326. s3d_structure_from_display_mode(const struct drm_display_mode *mode)
  6327. {
  6328. u32 layout = mode->flags & DRM_MODE_FLAG_3D_MASK;
  6329. switch (layout) {
  6330. case DRM_MODE_FLAG_3D_FRAME_PACKING:
  6331. return HDMI_3D_STRUCTURE_FRAME_PACKING;
  6332. case DRM_MODE_FLAG_3D_FIELD_ALTERNATIVE:
  6333. return HDMI_3D_STRUCTURE_FIELD_ALTERNATIVE;
  6334. case DRM_MODE_FLAG_3D_LINE_ALTERNATIVE:
  6335. return HDMI_3D_STRUCTURE_LINE_ALTERNATIVE;
  6336. case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_FULL:
  6337. return HDMI_3D_STRUCTURE_SIDE_BY_SIDE_FULL;
  6338. case DRM_MODE_FLAG_3D_L_DEPTH:
  6339. return HDMI_3D_STRUCTURE_L_DEPTH;
  6340. case DRM_MODE_FLAG_3D_L_DEPTH_GFX_GFX_DEPTH:
  6341. return HDMI_3D_STRUCTURE_L_DEPTH_GFX_GFX_DEPTH;
  6342. case DRM_MODE_FLAG_3D_TOP_AND_BOTTOM:
  6343. return HDMI_3D_STRUCTURE_TOP_AND_BOTTOM;
  6344. case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF:
  6345. return HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF;
  6346. default:
  6347. return HDMI_3D_STRUCTURE_INVALID;
  6348. }
  6349. }
  6350. /**
  6351. * drm_hdmi_vendor_infoframe_from_display_mode() - fill an HDMI infoframe with
  6352. * data from a DRM display mode
  6353. * @frame: HDMI vendor infoframe
  6354. * @connector: the connector
  6355. * @mode: DRM display mode
  6356. *
  6357. * Note that there's is a need to send HDMI vendor infoframes only when using a
  6358. * 4k or stereoscopic 3D mode. So when giving any other mode as input this
  6359. * function will return -EINVAL, error that can be safely ignored.
  6360. *
  6361. * Return: 0 on success or a negative error code on failure.
  6362. */
  6363. int
  6364. drm_hdmi_vendor_infoframe_from_display_mode(struct hdmi_vendor_infoframe *frame,
  6365. const struct drm_connector *connector,
  6366. const struct drm_display_mode *mode)
  6367. {
  6368. /*
  6369. * FIXME: sil-sii8620 doesn't have a connector around when
  6370. * we need one, so we have to be prepared for a NULL connector.
  6371. */
  6372. bool has_hdmi_infoframe = connector ?
  6373. connector->display_info.has_hdmi_infoframe : false;
  6374. int err;
  6375. if (!frame || !mode)
  6376. return -EINVAL;
  6377. if (!has_hdmi_infoframe)
  6378. return -EINVAL;
  6379. err = hdmi_vendor_infoframe_init(frame);
  6380. if (err < 0)
  6381. return err;
  6382. /*
  6383. * Even if it's not absolutely necessary to send the infoframe
  6384. * (ie.vic==0 and s3d_struct==0) we will still send it if we
  6385. * know that the sink can handle it. This is based on a
  6386. * suggestion in HDMI 2.0 Appendix F. Apparently some sinks
  6387. * have trouble realizing that they should switch from 3D to 2D
  6388. * mode if the source simply stops sending the infoframe when
  6389. * it wants to switch from 3D to 2D.
  6390. */
  6391. frame->vic = drm_mode_hdmi_vic(connector, mode);
  6392. frame->s3d_struct = s3d_structure_from_display_mode(mode);
  6393. return 0;
  6394. }
  6395. EXPORT_SYMBOL(drm_hdmi_vendor_infoframe_from_display_mode);
  6396. static void drm_parse_tiled_block(struct drm_connector *connector,
  6397. const struct displayid_block *block)
  6398. {
  6399. const struct displayid_tiled_block *tile = (struct displayid_tiled_block *)block;
  6400. u16 w, h;
  6401. u8 tile_v_loc, tile_h_loc;
  6402. u8 num_v_tile, num_h_tile;
  6403. struct drm_tile_group *tg;
  6404. w = tile->tile_size[0] | tile->tile_size[1] << 8;
  6405. h = tile->tile_size[2] | tile->tile_size[3] << 8;
  6406. num_v_tile = (tile->topo[0] & 0xf) | (tile->topo[2] & 0x30);
  6407. num_h_tile = (tile->topo[0] >> 4) | ((tile->topo[2] >> 2) & 0x30);
  6408. tile_v_loc = (tile->topo[1] & 0xf) | ((tile->topo[2] & 0x3) << 4);
  6409. tile_h_loc = (tile->topo[1] >> 4) | (((tile->topo[2] >> 2) & 0x3) << 4);
  6410. connector->has_tile = true;
  6411. if (tile->tile_cap & 0x80)
  6412. connector->tile_is_single_monitor = true;
  6413. connector->num_h_tile = num_h_tile + 1;
  6414. connector->num_v_tile = num_v_tile + 1;
  6415. connector->tile_h_loc = tile_h_loc;
  6416. connector->tile_v_loc = tile_v_loc;
  6417. connector->tile_h_size = w + 1;
  6418. connector->tile_v_size = h + 1;
  6419. drm_dbg_kms(connector->dev,
  6420. "[CONNECTOR:%d:%s] tile cap 0x%x, size %dx%d, num tiles %dx%d, location %dx%d, vend %c%c%c",
  6421. connector->base.id, connector->name,
  6422. tile->tile_cap,
  6423. connector->tile_h_size, connector->tile_v_size,
  6424. connector->num_h_tile, connector->num_v_tile,
  6425. connector->tile_h_loc, connector->tile_v_loc,
  6426. tile->topology_id[0], tile->topology_id[1], tile->topology_id[2]);
  6427. tg = drm_mode_get_tile_group(connector->dev, tile->topology_id);
  6428. if (!tg)
  6429. tg = drm_mode_create_tile_group(connector->dev, tile->topology_id);
  6430. if (!tg)
  6431. return;
  6432. if (connector->tile_group != tg) {
  6433. /* if we haven't got a pointer,
  6434. take the reference, drop ref to old tile group */
  6435. if (connector->tile_group)
  6436. drm_mode_put_tile_group(connector->dev, connector->tile_group);
  6437. connector->tile_group = tg;
  6438. } else {
  6439. /* if same tile group, then release the ref we just took. */
  6440. drm_mode_put_tile_group(connector->dev, tg);
  6441. }
  6442. }
  6443. static bool displayid_is_tiled_block(const struct displayid_iter *iter,
  6444. const struct displayid_block *block)
  6445. {
  6446. return (displayid_version(iter) < DISPLAY_ID_STRUCTURE_VER_20 &&
  6447. block->tag == DATA_BLOCK_TILED_DISPLAY) ||
  6448. (displayid_version(iter) == DISPLAY_ID_STRUCTURE_VER_20 &&
  6449. block->tag == DATA_BLOCK_2_TILED_DISPLAY_TOPOLOGY);
  6450. }
  6451. static void _drm_update_tile_info(struct drm_connector *connector,
  6452. const struct drm_edid *drm_edid)
  6453. {
  6454. const struct displayid_block *block;
  6455. struct displayid_iter iter;
  6456. connector->has_tile = false;
  6457. displayid_iter_edid_begin(drm_edid, &iter);
  6458. displayid_iter_for_each(block, &iter) {
  6459. if (displayid_is_tiled_block(&iter, block))
  6460. drm_parse_tiled_block(connector, block);
  6461. }
  6462. displayid_iter_end(&iter);
  6463. if (!connector->has_tile && connector->tile_group) {
  6464. drm_mode_put_tile_group(connector->dev, connector->tile_group);
  6465. connector->tile_group = NULL;
  6466. }
  6467. }
  6468. /**
  6469. * drm_edid_is_digital - is digital?
  6470. * @drm_edid: The EDID
  6471. *
  6472. * Return true if input is digital.
  6473. */
  6474. bool drm_edid_is_digital(const struct drm_edid *drm_edid)
  6475. {
  6476. return drm_edid && drm_edid->edid &&
  6477. drm_edid->edid->input & DRM_EDID_INPUT_DIGITAL;
  6478. }
  6479. EXPORT_SYMBOL(drm_edid_is_digital);