drm_edid.c 230 KB

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