drm_edid.c 214 KB

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