drm_edid.c 161 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316
  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/kernel.h>
  31. #include <linux/slab.h>
  32. #include <linux/hdmi.h>
  33. #include <linux/i2c.h>
  34. #include <linux/module.h>
  35. #include <linux/vga_switcheroo.h>
  36. #include <drm/drmP.h>
  37. #include <drm/drm_edid.h>
  38. #include <drm/drm_encoder.h>
  39. #include <drm/drm_displayid.h>
  40. #include <drm/drm_scdc_helper.h>
  41. #include "drm_crtc_internal.h"
  42. #define version_greater(edid, maj, min) \
  43. (((edid)->version > (maj)) || \
  44. ((edid)->version == (maj) && (edid)->revision > (min)))
  45. #define EDID_EST_TIMINGS 16
  46. #define EDID_STD_TIMINGS 8
  47. #define EDID_DETAILED_TIMINGS 4
  48. /*
  49. * EDID blocks out in the wild have a variety of bugs, try to collect
  50. * them here (note that userspace may work around broken monitors first,
  51. * but fixes should make their way here so that the kernel "just works"
  52. * on as many displays as possible).
  53. */
  54. /* First detailed mode wrong, use largest 60Hz mode */
  55. #define EDID_QUIRK_PREFER_LARGE_60 (1 << 0)
  56. /* Reported 135MHz pixel clock is too high, needs adjustment */
  57. #define EDID_QUIRK_135_CLOCK_TOO_HIGH (1 << 1)
  58. /* Prefer the largest mode at 75 Hz */
  59. #define EDID_QUIRK_PREFER_LARGE_75 (1 << 2)
  60. /* Detail timing is in cm not mm */
  61. #define EDID_QUIRK_DETAILED_IN_CM (1 << 3)
  62. /* Detailed timing descriptors have bogus size values, so just take the
  63. * maximum size and use that.
  64. */
  65. #define EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE (1 << 4)
  66. /* Monitor forgot to set the first detailed is preferred bit. */
  67. #define EDID_QUIRK_FIRST_DETAILED_PREFERRED (1 << 5)
  68. /* use +hsync +vsync for detailed mode */
  69. #define EDID_QUIRK_DETAILED_SYNC_PP (1 << 6)
  70. /* Force reduced-blanking timings for detailed modes */
  71. #define EDID_QUIRK_FORCE_REDUCED_BLANKING (1 << 7)
  72. /* Force 8bpc */
  73. #define EDID_QUIRK_FORCE_8BPC (1 << 8)
  74. /* Force 12bpc */
  75. #define EDID_QUIRK_FORCE_12BPC (1 << 9)
  76. /* Force 6bpc */
  77. #define EDID_QUIRK_FORCE_6BPC (1 << 10)
  78. /* Force 10bpc */
  79. #define EDID_QUIRK_FORCE_10BPC (1 << 11)
  80. /* Non desktop display (i.e. HMD) */
  81. #define EDID_QUIRK_NON_DESKTOP (1 << 12)
  82. struct detailed_mode_closure {
  83. struct drm_connector *connector;
  84. struct edid *edid;
  85. bool preferred;
  86. u32 quirks;
  87. int modes;
  88. };
  89. #define LEVEL_DMT 0
  90. #define LEVEL_GTF 1
  91. #define LEVEL_GTF2 2
  92. #define LEVEL_CVT 3
  93. static const struct edid_quirk {
  94. char vendor[4];
  95. int product_id;
  96. u32 quirks;
  97. } edid_quirk_list[] = {
  98. /* Acer AL1706 */
  99. { "ACR", 44358, EDID_QUIRK_PREFER_LARGE_60 },
  100. /* Acer F51 */
  101. { "API", 0x7602, EDID_QUIRK_PREFER_LARGE_60 },
  102. /* Unknown Acer */
  103. { "ACR", 2423, EDID_QUIRK_FIRST_DETAILED_PREFERRED },
  104. /* AEO model 0 reports 8 bpc, but is a 6 bpc panel */
  105. { "AEO", 0, EDID_QUIRK_FORCE_6BPC },
  106. /* BOE model on HP Pavilion 15-n233sl reports 8 bpc, but is a 6 bpc panel */
  107. { "BOE", 0x78b, EDID_QUIRK_FORCE_6BPC },
  108. /* CPT panel of Asus UX303LA reports 8 bpc, but is a 6 bpc panel */
  109. { "CPT", 0x17df, EDID_QUIRK_FORCE_6BPC },
  110. /* SDC panel of Lenovo B50-80 reports 8 bpc, but is a 6 bpc panel */
  111. { "SDC", 0x3652, EDID_QUIRK_FORCE_6BPC },
  112. /* BOE model 0x0771 reports 8 bpc, but is a 6 bpc panel */
  113. { "BOE", 0x0771, EDID_QUIRK_FORCE_6BPC },
  114. /* Belinea 10 15 55 */
  115. { "MAX", 1516, EDID_QUIRK_PREFER_LARGE_60 },
  116. { "MAX", 0x77e, EDID_QUIRK_PREFER_LARGE_60 },
  117. /* Envision Peripherals, Inc. EN-7100e */
  118. { "EPI", 59264, EDID_QUIRK_135_CLOCK_TOO_HIGH },
  119. /* Envision EN2028 */
  120. { "EPI", 8232, EDID_QUIRK_PREFER_LARGE_60 },
  121. /* Funai Electronics PM36B */
  122. { "FCM", 13600, EDID_QUIRK_PREFER_LARGE_75 |
  123. EDID_QUIRK_DETAILED_IN_CM },
  124. /* LGD panel of HP zBook 17 G2, eDP 10 bpc, but reports unknown bpc */
  125. { "LGD", 764, EDID_QUIRK_FORCE_10BPC },
  126. /* LG Philips LCD LP154W01-A5 */
  127. { "LPL", 0, EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE },
  128. { "LPL", 0x2a00, EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE },
  129. /* Philips 107p5 CRT */
  130. { "PHL", 57364, EDID_QUIRK_FIRST_DETAILED_PREFERRED },
  131. /* Proview AY765C */
  132. { "PTS", 765, EDID_QUIRK_FIRST_DETAILED_PREFERRED },
  133. /* Samsung SyncMaster 205BW. Note: irony */
  134. { "SAM", 541, EDID_QUIRK_DETAILED_SYNC_PP },
  135. /* Samsung SyncMaster 22[5-6]BW */
  136. { "SAM", 596, EDID_QUIRK_PREFER_LARGE_60 },
  137. { "SAM", 638, EDID_QUIRK_PREFER_LARGE_60 },
  138. /* Sony PVM-2541A does up to 12 bpc, but only reports max 8 bpc */
  139. { "SNY", 0x2541, EDID_QUIRK_FORCE_12BPC },
  140. /* ViewSonic VA2026w */
  141. { "VSC", 5020, EDID_QUIRK_FORCE_REDUCED_BLANKING },
  142. /* Medion MD 30217 PG */
  143. { "MED", 0x7b8, EDID_QUIRK_PREFER_LARGE_75 },
  144. /* Lenovo G50 */
  145. { "SDC", 18514, EDID_QUIRK_FORCE_6BPC },
  146. /* Panel in Samsung NP700G7A-S01PL notebook reports 6bpc */
  147. { "SEC", 0xd033, EDID_QUIRK_FORCE_8BPC },
  148. /* Rotel RSX-1058 forwards sink's EDID but only does HDMI 1.1*/
  149. { "ETR", 13896, EDID_QUIRK_FORCE_8BPC },
  150. /* Valve Index Headset */
  151. { "VLV", 0x91a8, EDID_QUIRK_NON_DESKTOP },
  152. { "VLV", 0x91b0, EDID_QUIRK_NON_DESKTOP },
  153. { "VLV", 0x91b1, EDID_QUIRK_NON_DESKTOP },
  154. { "VLV", 0x91b2, EDID_QUIRK_NON_DESKTOP },
  155. { "VLV", 0x91b3, EDID_QUIRK_NON_DESKTOP },
  156. { "VLV", 0x91b4, EDID_QUIRK_NON_DESKTOP },
  157. { "VLV", 0x91b5, EDID_QUIRK_NON_DESKTOP },
  158. { "VLV", 0x91b6, EDID_QUIRK_NON_DESKTOP },
  159. { "VLV", 0x91b7, EDID_QUIRK_NON_DESKTOP },
  160. { "VLV", 0x91b8, EDID_QUIRK_NON_DESKTOP },
  161. { "VLV", 0x91b9, EDID_QUIRK_NON_DESKTOP },
  162. { "VLV", 0x91ba, EDID_QUIRK_NON_DESKTOP },
  163. { "VLV", 0x91bb, EDID_QUIRK_NON_DESKTOP },
  164. { "VLV", 0x91bc, EDID_QUIRK_NON_DESKTOP },
  165. { "VLV", 0x91bd, EDID_QUIRK_NON_DESKTOP },
  166. { "VLV", 0x91be, EDID_QUIRK_NON_DESKTOP },
  167. { "VLV", 0x91bf, EDID_QUIRK_NON_DESKTOP },
  168. /* HTC Vive and Vive Pro VR Headsets */
  169. { "HVR", 0xaa01, EDID_QUIRK_NON_DESKTOP },
  170. { "HVR", 0xaa02, EDID_QUIRK_NON_DESKTOP },
  171. /* Oculus Rift DK1, DK2, and CV1 VR Headsets */
  172. { "OVR", 0x0001, EDID_QUIRK_NON_DESKTOP },
  173. { "OVR", 0x0003, EDID_QUIRK_NON_DESKTOP },
  174. { "OVR", 0x0004, EDID_QUIRK_NON_DESKTOP },
  175. /* Windows Mixed Reality Headsets */
  176. { "ACR", 0x7fce, EDID_QUIRK_NON_DESKTOP },
  177. { "HPN", 0x3515, EDID_QUIRK_NON_DESKTOP },
  178. { "LEN", 0x0408, EDID_QUIRK_NON_DESKTOP },
  179. { "LEN", 0xb800, EDID_QUIRK_NON_DESKTOP },
  180. { "FUJ", 0x1970, EDID_QUIRK_NON_DESKTOP },
  181. { "DEL", 0x7fce, EDID_QUIRK_NON_DESKTOP },
  182. { "SEC", 0x144a, EDID_QUIRK_NON_DESKTOP },
  183. { "AUS", 0xc102, EDID_QUIRK_NON_DESKTOP },
  184. /* Sony PlayStation VR Headset */
  185. { "SNY", 0x0704, EDID_QUIRK_NON_DESKTOP },
  186. /* Sensics VR Headsets */
  187. { "SEN", 0x1019, EDID_QUIRK_NON_DESKTOP },
  188. /* OSVR HDK and HDK2 VR Headsets */
  189. { "SVR", 0x1019, EDID_QUIRK_NON_DESKTOP },
  190. };
  191. /*
  192. * Autogenerated from the DMT spec.
  193. * This table is copied from xfree86/modes/xf86EdidModes.c.
  194. */
  195. static const struct drm_display_mode drm_dmt_modes[] = {
  196. /* 0x01 - 640x350@85Hz */
  197. { DRM_MODE("640x350", DRM_MODE_TYPE_DRIVER, 31500, 640, 672,
  198. 736, 832, 0, 350, 382, 385, 445, 0,
  199. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  200. /* 0x02 - 640x400@85Hz */
  201. { DRM_MODE("640x400", DRM_MODE_TYPE_DRIVER, 31500, 640, 672,
  202. 736, 832, 0, 400, 401, 404, 445, 0,
  203. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  204. /* 0x03 - 720x400@85Hz */
  205. { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 35500, 720, 756,
  206. 828, 936, 0, 400, 401, 404, 446, 0,
  207. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  208. /* 0x04 - 640x480@60Hz */
  209. { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
  210. 752, 800, 0, 480, 490, 492, 525, 0,
  211. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
  212. /* 0x05 - 640x480@72Hz */
  213. { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 664,
  214. 704, 832, 0, 480, 489, 492, 520, 0,
  215. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
  216. /* 0x06 - 640x480@75Hz */
  217. { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 656,
  218. 720, 840, 0, 480, 481, 484, 500, 0,
  219. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
  220. /* 0x07 - 640x480@85Hz */
  221. { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 36000, 640, 696,
  222. 752, 832, 0, 480, 481, 484, 509, 0,
  223. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
  224. /* 0x08 - 800x600@56Hz */
  225. { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 36000, 800, 824,
  226. 896, 1024, 0, 600, 601, 603, 625, 0,
  227. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  228. /* 0x09 - 800x600@60Hz */
  229. { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840,
  230. 968, 1056, 0, 600, 601, 605, 628, 0,
  231. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  232. /* 0x0a - 800x600@72Hz */
  233. { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 50000, 800, 856,
  234. 976, 1040, 0, 600, 637, 643, 666, 0,
  235. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  236. /* 0x0b - 800x600@75Hz */
  237. { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 49500, 800, 816,
  238. 896, 1056, 0, 600, 601, 604, 625, 0,
  239. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  240. /* 0x0c - 800x600@85Hz */
  241. { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 56250, 800, 832,
  242. 896, 1048, 0, 600, 601, 604, 631, 0,
  243. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  244. /* 0x0d - 800x600@120Hz RB */
  245. { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 73250, 800, 848,
  246. 880, 960, 0, 600, 603, 607, 636, 0,
  247. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  248. /* 0x0e - 848x480@60Hz */
  249. { DRM_MODE("848x480", DRM_MODE_TYPE_DRIVER, 33750, 848, 864,
  250. 976, 1088, 0, 480, 486, 494, 517, 0,
  251. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  252. /* 0x0f - 1024x768@43Hz, interlace */
  253. { DRM_MODE("1024x768i", DRM_MODE_TYPE_DRIVER, 44900, 1024, 1032,
  254. 1208, 1264, 0, 768, 768, 776, 817, 0,
  255. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
  256. DRM_MODE_FLAG_INTERLACE) },
  257. /* 0x10 - 1024x768@60Hz */
  258. { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048,
  259. 1184, 1344, 0, 768, 771, 777, 806, 0,
  260. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
  261. /* 0x11 - 1024x768@70Hz */
  262. { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 75000, 1024, 1048,
  263. 1184, 1328, 0, 768, 771, 777, 806, 0,
  264. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
  265. /* 0x12 - 1024x768@75Hz */
  266. { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 78750, 1024, 1040,
  267. 1136, 1312, 0, 768, 769, 772, 800, 0,
  268. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  269. /* 0x13 - 1024x768@85Hz */
  270. { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 94500, 1024, 1072,
  271. 1168, 1376, 0, 768, 769, 772, 808, 0,
  272. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  273. /* 0x14 - 1024x768@120Hz RB */
  274. { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 115500, 1024, 1072,
  275. 1104, 1184, 0, 768, 771, 775, 813, 0,
  276. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  277. /* 0x15 - 1152x864@75Hz */
  278. { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216,
  279. 1344, 1600, 0, 864, 865, 868, 900, 0,
  280. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  281. /* 0x55 - 1280x720@60Hz */
  282. { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1390,
  283. 1430, 1650, 0, 720, 725, 730, 750, 0,
  284. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  285. /* 0x16 - 1280x768@60Hz RB */
  286. { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 68250, 1280, 1328,
  287. 1360, 1440, 0, 768, 771, 778, 790, 0,
  288. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  289. /* 0x17 - 1280x768@60Hz */
  290. { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 79500, 1280, 1344,
  291. 1472, 1664, 0, 768, 771, 778, 798, 0,
  292. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  293. /* 0x18 - 1280x768@75Hz */
  294. { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 102250, 1280, 1360,
  295. 1488, 1696, 0, 768, 771, 778, 805, 0,
  296. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  297. /* 0x19 - 1280x768@85Hz */
  298. { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 117500, 1280, 1360,
  299. 1496, 1712, 0, 768, 771, 778, 809, 0,
  300. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  301. /* 0x1a - 1280x768@120Hz RB */
  302. { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 140250, 1280, 1328,
  303. 1360, 1440, 0, 768, 771, 778, 813, 0,
  304. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  305. /* 0x1b - 1280x800@60Hz RB */
  306. { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 71000, 1280, 1328,
  307. 1360, 1440, 0, 800, 803, 809, 823, 0,
  308. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  309. /* 0x1c - 1280x800@60Hz */
  310. { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 83500, 1280, 1352,
  311. 1480, 1680, 0, 800, 803, 809, 831, 0,
  312. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  313. /* 0x1d - 1280x800@75Hz */
  314. { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 106500, 1280, 1360,
  315. 1488, 1696, 0, 800, 803, 809, 838, 0,
  316. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  317. /* 0x1e - 1280x800@85Hz */
  318. { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 122500, 1280, 1360,
  319. 1496, 1712, 0, 800, 803, 809, 843, 0,
  320. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  321. /* 0x1f - 1280x800@120Hz RB */
  322. { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 146250, 1280, 1328,
  323. 1360, 1440, 0, 800, 803, 809, 847, 0,
  324. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  325. /* 0x20 - 1280x960@60Hz */
  326. { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1376,
  327. 1488, 1800, 0, 960, 961, 964, 1000, 0,
  328. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  329. /* 0x21 - 1280x960@85Hz */
  330. { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1344,
  331. 1504, 1728, 0, 960, 961, 964, 1011, 0,
  332. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  333. /* 0x22 - 1280x960@120Hz RB */
  334. { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 175500, 1280, 1328,
  335. 1360, 1440, 0, 960, 963, 967, 1017, 0,
  336. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  337. /* 0x23 - 1280x1024@60Hz */
  338. { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1328,
  339. 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
  340. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  341. /* 0x24 - 1280x1024@75Hz */
  342. { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 135000, 1280, 1296,
  343. 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
  344. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  345. /* 0x25 - 1280x1024@85Hz */
  346. { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 157500, 1280, 1344,
  347. 1504, 1728, 0, 1024, 1025, 1028, 1072, 0,
  348. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  349. /* 0x26 - 1280x1024@120Hz RB */
  350. { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 187250, 1280, 1328,
  351. 1360, 1440, 0, 1024, 1027, 1034, 1084, 0,
  352. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  353. /* 0x27 - 1360x768@60Hz */
  354. { DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER, 85500, 1360, 1424,
  355. 1536, 1792, 0, 768, 771, 777, 795, 0,
  356. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  357. /* 0x28 - 1360x768@120Hz RB */
  358. { DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER, 148250, 1360, 1408,
  359. 1440, 1520, 0, 768, 771, 776, 813, 0,
  360. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  361. /* 0x51 - 1366x768@60Hz */
  362. { DRM_MODE("1366x768", DRM_MODE_TYPE_DRIVER, 85500, 1366, 1436,
  363. 1579, 1792, 0, 768, 771, 774, 798, 0,
  364. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  365. /* 0x56 - 1366x768@60Hz */
  366. { DRM_MODE("1366x768", DRM_MODE_TYPE_DRIVER, 72000, 1366, 1380,
  367. 1436, 1500, 0, 768, 769, 772, 800, 0,
  368. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  369. /* 0x29 - 1400x1050@60Hz RB */
  370. { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 101000, 1400, 1448,
  371. 1480, 1560, 0, 1050, 1053, 1057, 1080, 0,
  372. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  373. /* 0x2a - 1400x1050@60Hz */
  374. { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 121750, 1400, 1488,
  375. 1632, 1864, 0, 1050, 1053, 1057, 1089, 0,
  376. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  377. /* 0x2b - 1400x1050@75Hz */
  378. { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 156000, 1400, 1504,
  379. 1648, 1896, 0, 1050, 1053, 1057, 1099, 0,
  380. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  381. /* 0x2c - 1400x1050@85Hz */
  382. { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 179500, 1400, 1504,
  383. 1656, 1912, 0, 1050, 1053, 1057, 1105, 0,
  384. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  385. /* 0x2d - 1400x1050@120Hz RB */
  386. { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 208000, 1400, 1448,
  387. 1480, 1560, 0, 1050, 1053, 1057, 1112, 0,
  388. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  389. /* 0x2e - 1440x900@60Hz RB */
  390. { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 88750, 1440, 1488,
  391. 1520, 1600, 0, 900, 903, 909, 926, 0,
  392. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  393. /* 0x2f - 1440x900@60Hz */
  394. { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 106500, 1440, 1520,
  395. 1672, 1904, 0, 900, 903, 909, 934, 0,
  396. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  397. /* 0x30 - 1440x900@75Hz */
  398. { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 136750, 1440, 1536,
  399. 1688, 1936, 0, 900, 903, 909, 942, 0,
  400. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  401. /* 0x31 - 1440x900@85Hz */
  402. { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 157000, 1440, 1544,
  403. 1696, 1952, 0, 900, 903, 909, 948, 0,
  404. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  405. /* 0x32 - 1440x900@120Hz RB */
  406. { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 182750, 1440, 1488,
  407. 1520, 1600, 0, 900, 903, 909, 953, 0,
  408. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  409. /* 0x53 - 1600x900@60Hz */
  410. { DRM_MODE("1600x900", DRM_MODE_TYPE_DRIVER, 108000, 1600, 1624,
  411. 1704, 1800, 0, 900, 901, 904, 1000, 0,
  412. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  413. /* 0x33 - 1600x1200@60Hz */
  414. { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 162000, 1600, 1664,
  415. 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
  416. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  417. /* 0x34 - 1600x1200@65Hz */
  418. { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 175500, 1600, 1664,
  419. 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
  420. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  421. /* 0x35 - 1600x1200@70Hz */
  422. { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 189000, 1600, 1664,
  423. 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
  424. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  425. /* 0x36 - 1600x1200@75Hz */
  426. { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 202500, 1600, 1664,
  427. 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
  428. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  429. /* 0x37 - 1600x1200@85Hz */
  430. { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 229500, 1600, 1664,
  431. 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
  432. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  433. /* 0x38 - 1600x1200@120Hz RB */
  434. { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 268250, 1600, 1648,
  435. 1680, 1760, 0, 1200, 1203, 1207, 1271, 0,
  436. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  437. /* 0x39 - 1680x1050@60Hz RB */
  438. { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 119000, 1680, 1728,
  439. 1760, 1840, 0, 1050, 1053, 1059, 1080, 0,
  440. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  441. /* 0x3a - 1680x1050@60Hz */
  442. { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 146250, 1680, 1784,
  443. 1960, 2240, 0, 1050, 1053, 1059, 1089, 0,
  444. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  445. /* 0x3b - 1680x1050@75Hz */
  446. { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 187000, 1680, 1800,
  447. 1976, 2272, 0, 1050, 1053, 1059, 1099, 0,
  448. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  449. /* 0x3c - 1680x1050@85Hz */
  450. { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 214750, 1680, 1808,
  451. 1984, 2288, 0, 1050, 1053, 1059, 1105, 0,
  452. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  453. /* 0x3d - 1680x1050@120Hz RB */
  454. { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 245500, 1680, 1728,
  455. 1760, 1840, 0, 1050, 1053, 1059, 1112, 0,
  456. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  457. /* 0x3e - 1792x1344@60Hz */
  458. { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 204750, 1792, 1920,
  459. 2120, 2448, 0, 1344, 1345, 1348, 1394, 0,
  460. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  461. /* 0x3f - 1792x1344@75Hz */
  462. { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 261000, 1792, 1888,
  463. 2104, 2456, 0, 1344, 1345, 1348, 1417, 0,
  464. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  465. /* 0x40 - 1792x1344@120Hz RB */
  466. { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 333250, 1792, 1840,
  467. 1872, 1952, 0, 1344, 1347, 1351, 1423, 0,
  468. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  469. /* 0x41 - 1856x1392@60Hz */
  470. { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 218250, 1856, 1952,
  471. 2176, 2528, 0, 1392, 1393, 1396, 1439, 0,
  472. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  473. /* 0x42 - 1856x1392@75Hz */
  474. { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 288000, 1856, 1984,
  475. 2208, 2560, 0, 1392, 1393, 1396, 1500, 0,
  476. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  477. /* 0x43 - 1856x1392@120Hz RB */
  478. { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 356500, 1856, 1904,
  479. 1936, 2016, 0, 1392, 1395, 1399, 1474, 0,
  480. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  481. /* 0x52 - 1920x1080@60Hz */
  482. { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
  483. 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
  484. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
  485. /* 0x44 - 1920x1200@60Hz RB */
  486. { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 154000, 1920, 1968,
  487. 2000, 2080, 0, 1200, 1203, 1209, 1235, 0,
  488. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  489. /* 0x45 - 1920x1200@60Hz */
  490. { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 193250, 1920, 2056,
  491. 2256, 2592, 0, 1200, 1203, 1209, 1245, 0,
  492. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  493. /* 0x46 - 1920x1200@75Hz */
  494. { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 245250, 1920, 2056,
  495. 2264, 2608, 0, 1200, 1203, 1209, 1255, 0,
  496. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  497. /* 0x47 - 1920x1200@85Hz */
  498. { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 281250, 1920, 2064,
  499. 2272, 2624, 0, 1200, 1203, 1209, 1262, 0,
  500. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  501. /* 0x48 - 1920x1200@120Hz RB */
  502. { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 317000, 1920, 1968,
  503. 2000, 2080, 0, 1200, 1203, 1209, 1271, 0,
  504. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  505. /* 0x49 - 1920x1440@60Hz */
  506. { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 234000, 1920, 2048,
  507. 2256, 2600, 0, 1440, 1441, 1444, 1500, 0,
  508. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  509. /* 0x4a - 1920x1440@75Hz */
  510. { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2064,
  511. 2288, 2640, 0, 1440, 1441, 1444, 1500, 0,
  512. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  513. /* 0x4b - 1920x1440@120Hz RB */
  514. { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 380500, 1920, 1968,
  515. 2000, 2080, 0, 1440, 1443, 1447, 1525, 0,
  516. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  517. /* 0x54 - 2048x1152@60Hz */
  518. { DRM_MODE("2048x1152", DRM_MODE_TYPE_DRIVER, 162000, 2048, 2074,
  519. 2154, 2250, 0, 1152, 1153, 1156, 1200, 0,
  520. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
  521. /* 0x4c - 2560x1600@60Hz RB */
  522. { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 268500, 2560, 2608,
  523. 2640, 2720, 0, 1600, 1603, 1609, 1646, 0,
  524. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  525. /* 0x4d - 2560x1600@60Hz */
  526. { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 348500, 2560, 2752,
  527. 3032, 3504, 0, 1600, 1603, 1609, 1658, 0,
  528. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  529. /* 0x4e - 2560x1600@75Hz */
  530. { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 443250, 2560, 2768,
  531. 3048, 3536, 0, 1600, 1603, 1609, 1672, 0,
  532. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  533. /* 0x4f - 2560x1600@85Hz */
  534. { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 505250, 2560, 2768,
  535. 3048, 3536, 0, 1600, 1603, 1609, 1682, 0,
  536. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
  537. /* 0x50 - 2560x1600@120Hz RB */
  538. { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 552750, 2560, 2608,
  539. 2640, 2720, 0, 1600, 1603, 1609, 1694, 0,
  540. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  541. /* 0x57 - 4096x2160@60Hz RB */
  542. { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 556744, 4096, 4104,
  543. 4136, 4176, 0, 2160, 2208, 2216, 2222, 0,
  544. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  545. /* 0x58 - 4096x2160@59.94Hz RB */
  546. { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 556188, 4096, 4104,
  547. 4136, 4176, 0, 2160, 2208, 2216, 2222, 0,
  548. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
  549. };
  550. /*
  551. * These more or less come from the DMT spec. The 720x400 modes are
  552. * inferred from historical 80x25 practice. The 640x480@67 and 832x624@75
  553. * modes are old-school Mac modes. The EDID spec says the 1152x864@75 mode
  554. * should be 1152x870, again for the Mac, but instead we use the x864 DMT
  555. * mode.
  556. *
  557. * The DMT modes have been fact-checked; the rest are mild guesses.
  558. */
  559. static const struct drm_display_mode edid_est_modes[] = {
  560. { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840,
  561. 968, 1056, 0, 600, 601, 605, 628, 0,
  562. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@60Hz */
  563. { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 36000, 800, 824,
  564. 896, 1024, 0, 600, 601, 603, 625, 0,
  565. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@56Hz */
  566. { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 656,
  567. 720, 840, 0, 480, 481, 484, 500, 0,
  568. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@75Hz */
  569. { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 664,
  570. 704, 832, 0, 480, 489, 492, 520, 0,
  571. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@72Hz */
  572. { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 30240, 640, 704,
  573. 768, 864, 0, 480, 483, 486, 525, 0,
  574. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@67Hz */
  575. { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
  576. 752, 800, 0, 480, 490, 492, 525, 0,
  577. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@60Hz */
  578. { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 35500, 720, 738,
  579. 846, 900, 0, 400, 421, 423, 449, 0,
  580. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 720x400@88Hz */
  581. { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 28320, 720, 738,
  582. 846, 900, 0, 400, 412, 414, 449, 0,
  583. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 720x400@70Hz */
  584. { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 135000, 1280, 1296,
  585. 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
  586. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1280x1024@75Hz */
  587. { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 78750, 1024, 1040,
  588. 1136, 1312, 0, 768, 769, 772, 800, 0,
  589. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1024x768@75Hz */
  590. { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 75000, 1024, 1048,
  591. 1184, 1328, 0, 768, 771, 777, 806, 0,
  592. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 1024x768@70Hz */
  593. { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048,
  594. 1184, 1344, 0, 768, 771, 777, 806, 0,
  595. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 1024x768@60Hz */
  596. { DRM_MODE("1024x768i", DRM_MODE_TYPE_DRIVER,44900, 1024, 1032,
  597. 1208, 1264, 0, 768, 768, 776, 817, 0,
  598. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_INTERLACE) }, /* 1024x768@43Hz */
  599. { DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER, 57284, 832, 864,
  600. 928, 1152, 0, 624, 625, 628, 667, 0,
  601. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 832x624@75Hz */
  602. { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 49500, 800, 816,
  603. 896, 1056, 0, 600, 601, 604, 625, 0,
  604. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@75Hz */
  605. { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 50000, 800, 856,
  606. 976, 1040, 0, 600, 637, 643, 666, 0,
  607. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@72Hz */
  608. { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216,
  609. 1344, 1600, 0, 864, 865, 868, 900, 0,
  610. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1152x864@75Hz */
  611. };
  612. struct minimode {
  613. short w;
  614. short h;
  615. short r;
  616. short rb;
  617. };
  618. static const struct minimode est3_modes[] = {
  619. /* byte 6 */
  620. { 640, 350, 85, 0 },
  621. { 640, 400, 85, 0 },
  622. { 720, 400, 85, 0 },
  623. { 640, 480, 85, 0 },
  624. { 848, 480, 60, 0 },
  625. { 800, 600, 85, 0 },
  626. { 1024, 768, 85, 0 },
  627. { 1152, 864, 75, 0 },
  628. /* byte 7 */
  629. { 1280, 768, 60, 1 },
  630. { 1280, 768, 60, 0 },
  631. { 1280, 768, 75, 0 },
  632. { 1280, 768, 85, 0 },
  633. { 1280, 960, 60, 0 },
  634. { 1280, 960, 85, 0 },
  635. { 1280, 1024, 60, 0 },
  636. { 1280, 1024, 85, 0 },
  637. /* byte 8 */
  638. { 1360, 768, 60, 0 },
  639. { 1440, 900, 60, 1 },
  640. { 1440, 900, 60, 0 },
  641. { 1440, 900, 75, 0 },
  642. { 1440, 900, 85, 0 },
  643. { 1400, 1050, 60, 1 },
  644. { 1400, 1050, 60, 0 },
  645. { 1400, 1050, 75, 0 },
  646. /* byte 9 */
  647. { 1400, 1050, 85, 0 },
  648. { 1680, 1050, 60, 1 },
  649. { 1680, 1050, 60, 0 },
  650. { 1680, 1050, 75, 0 },
  651. { 1680, 1050, 85, 0 },
  652. { 1600, 1200, 60, 0 },
  653. { 1600, 1200, 65, 0 },
  654. { 1600, 1200, 70, 0 },
  655. /* byte 10 */
  656. { 1600, 1200, 75, 0 },
  657. { 1600, 1200, 85, 0 },
  658. { 1792, 1344, 60, 0 },
  659. { 1792, 1344, 75, 0 },
  660. { 1856, 1392, 60, 0 },
  661. { 1856, 1392, 75, 0 },
  662. { 1920, 1200, 60, 1 },
  663. { 1920, 1200, 60, 0 },
  664. /* byte 11 */
  665. { 1920, 1200, 75, 0 },
  666. { 1920, 1200, 85, 0 },
  667. { 1920, 1440, 60, 0 },
  668. { 1920, 1440, 75, 0 },
  669. };
  670. static const struct minimode extra_modes[] = {
  671. { 1024, 576, 60, 0 },
  672. { 1366, 768, 60, 0 },
  673. { 1600, 900, 60, 0 },
  674. { 1680, 945, 60, 0 },
  675. { 1920, 1080, 60, 0 },
  676. { 2048, 1152, 60, 0 },
  677. { 2048, 1536, 60, 0 },
  678. };
  679. /*
  680. * Probably taken from CEA-861 spec.
  681. * This table is converted from xorg's hw/xfree86/modes/xf86EdidModes.c.
  682. *
  683. * Index using the VIC.
  684. */
  685. static const struct drm_display_mode edid_cea_modes[] = {
  686. /* 0 - dummy, VICs start at 1 */
  687. { },
  688. /* 1 - 640x480@60Hz 4:3 */
  689. { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
  690. 752, 800, 0, 480, 490, 492, 525, 0,
  691. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  692. .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  693. /* 2 - 720x480@60Hz 4:3 */
  694. { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 27000, 720, 736,
  695. 798, 858, 0, 480, 489, 495, 525, 0,
  696. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  697. .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  698. /* 3 - 720x480@60Hz 16:9 */
  699. { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 27000, 720, 736,
  700. 798, 858, 0, 480, 489, 495, 525, 0,
  701. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  702. .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  703. /* 4 - 1280x720@60Hz 16:9 */
  704. { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1390,
  705. 1430, 1650, 0, 720, 725, 730, 750, 0,
  706. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  707. .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  708. /* 5 - 1920x1080i@60Hz 16:9 */
  709. { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2008,
  710. 2052, 2200, 0, 1080, 1084, 1094, 1125, 0,
  711. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
  712. DRM_MODE_FLAG_INTERLACE),
  713. .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  714. /* 6 - 720(1440)x480i@60Hz 4:3 */
  715. { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
  716. 801, 858, 0, 480, 488, 494, 525, 0,
  717. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
  718. DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
  719. .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  720. /* 7 - 720(1440)x480i@60Hz 16:9 */
  721. { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
  722. 801, 858, 0, 480, 488, 494, 525, 0,
  723. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
  724. DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
  725. .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  726. /* 8 - 720(1440)x240@60Hz 4:3 */
  727. { DRM_MODE("720x240", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
  728. 801, 858, 0, 240, 244, 247, 262, 0,
  729. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
  730. DRM_MODE_FLAG_DBLCLK),
  731. .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  732. /* 9 - 720(1440)x240@60Hz 16:9 */
  733. { DRM_MODE("720x240", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
  734. 801, 858, 0, 240, 244, 247, 262, 0,
  735. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
  736. DRM_MODE_FLAG_DBLCLK),
  737. .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  738. /* 10 - 2880x480i@60Hz 4:3 */
  739. { DRM_MODE("2880x480i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
  740. 3204, 3432, 0, 480, 488, 494, 525, 0,
  741. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
  742. DRM_MODE_FLAG_INTERLACE),
  743. .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  744. /* 11 - 2880x480i@60Hz 16:9 */
  745. { DRM_MODE("2880x480i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
  746. 3204, 3432, 0, 480, 488, 494, 525, 0,
  747. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
  748. DRM_MODE_FLAG_INTERLACE),
  749. .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  750. /* 12 - 2880x240@60Hz 4:3 */
  751. { DRM_MODE("2880x240", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
  752. 3204, 3432, 0, 240, 244, 247, 262, 0,
  753. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  754. .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  755. /* 13 - 2880x240@60Hz 16:9 */
  756. { DRM_MODE("2880x240", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
  757. 3204, 3432, 0, 240, 244, 247, 262, 0,
  758. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  759. .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  760. /* 14 - 1440x480@60Hz 4:3 */
  761. { DRM_MODE("1440x480", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1472,
  762. 1596, 1716, 0, 480, 489, 495, 525, 0,
  763. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  764. .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  765. /* 15 - 1440x480@60Hz 16:9 */
  766. { DRM_MODE("1440x480", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1472,
  767. 1596, 1716, 0, 480, 489, 495, 525, 0,
  768. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  769. .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  770. /* 16 - 1920x1080@60Hz 16:9 */
  771. { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
  772. 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
  773. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  774. .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  775. /* 17 - 720x576@50Hz 4:3 */
  776. { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
  777. 796, 864, 0, 576, 581, 586, 625, 0,
  778. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  779. .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  780. /* 18 - 720x576@50Hz 16:9 */
  781. { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
  782. 796, 864, 0, 576, 581, 586, 625, 0,
  783. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  784. .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  785. /* 19 - 1280x720@50Hz 16:9 */
  786. { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1720,
  787. 1760, 1980, 0, 720, 725, 730, 750, 0,
  788. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  789. .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  790. /* 20 - 1920x1080i@50Hz 16:9 */
  791. { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2448,
  792. 2492, 2640, 0, 1080, 1084, 1094, 1125, 0,
  793. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
  794. DRM_MODE_FLAG_INTERLACE),
  795. .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  796. /* 21 - 720(1440)x576i@50Hz 4:3 */
  797. { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
  798. 795, 864, 0, 576, 580, 586, 625, 0,
  799. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
  800. DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
  801. .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  802. /* 22 - 720(1440)x576i@50Hz 16:9 */
  803. { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
  804. 795, 864, 0, 576, 580, 586, 625, 0,
  805. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
  806. DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
  807. .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  808. /* 23 - 720(1440)x288@50Hz 4:3 */
  809. { DRM_MODE("720x288", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
  810. 795, 864, 0, 288, 290, 293, 312, 0,
  811. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
  812. DRM_MODE_FLAG_DBLCLK),
  813. .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  814. /* 24 - 720(1440)x288@50Hz 16:9 */
  815. { DRM_MODE("720x288", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
  816. 795, 864, 0, 288, 290, 293, 312, 0,
  817. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
  818. DRM_MODE_FLAG_DBLCLK),
  819. .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  820. /* 25 - 2880x576i@50Hz 4:3 */
  821. { DRM_MODE("2880x576i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
  822. 3180, 3456, 0, 576, 580, 586, 625, 0,
  823. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
  824. DRM_MODE_FLAG_INTERLACE),
  825. .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  826. /* 26 - 2880x576i@50Hz 16:9 */
  827. { DRM_MODE("2880x576i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
  828. 3180, 3456, 0, 576, 580, 586, 625, 0,
  829. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
  830. DRM_MODE_FLAG_INTERLACE),
  831. .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  832. /* 27 - 2880x288@50Hz 4:3 */
  833. { DRM_MODE("2880x288", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
  834. 3180, 3456, 0, 288, 290, 293, 312, 0,
  835. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  836. .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  837. /* 28 - 2880x288@50Hz 16:9 */
  838. { DRM_MODE("2880x288", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
  839. 3180, 3456, 0, 288, 290, 293, 312, 0,
  840. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  841. .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  842. /* 29 - 1440x576@50Hz 4:3 */
  843. { DRM_MODE("1440x576", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1464,
  844. 1592, 1728, 0, 576, 581, 586, 625, 0,
  845. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  846. .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  847. /* 30 - 1440x576@50Hz 16:9 */
  848. { DRM_MODE("1440x576", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1464,
  849. 1592, 1728, 0, 576, 581, 586, 625, 0,
  850. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  851. .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  852. /* 31 - 1920x1080@50Hz 16:9 */
  853. { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2448,
  854. 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
  855. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  856. .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  857. /* 32 - 1920x1080@24Hz 16:9 */
  858. { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2558,
  859. 2602, 2750, 0, 1080, 1084, 1089, 1125, 0,
  860. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  861. .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  862. /* 33 - 1920x1080@25Hz 16:9 */
  863. { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2448,
  864. 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
  865. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  866. .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  867. /* 34 - 1920x1080@30Hz 16:9 */
  868. { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2008,
  869. 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
  870. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  871. .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  872. /* 35 - 2880x480@60Hz 4:3 */
  873. { DRM_MODE("2880x480", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2944,
  874. 3192, 3432, 0, 480, 489, 495, 525, 0,
  875. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  876. .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  877. /* 36 - 2880x480@60Hz 16:9 */
  878. { DRM_MODE("2880x480", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2944,
  879. 3192, 3432, 0, 480, 489, 495, 525, 0,
  880. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  881. .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  882. /* 37 - 2880x576@50Hz 4:3 */
  883. { DRM_MODE("2880x576", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2928,
  884. 3184, 3456, 0, 576, 581, 586, 625, 0,
  885. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  886. .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  887. /* 38 - 2880x576@50Hz 16:9 */
  888. { DRM_MODE("2880x576", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2928,
  889. 3184, 3456, 0, 576, 581, 586, 625, 0,
  890. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  891. .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  892. /* 39 - 1920x1080i@50Hz 16:9 */
  893. { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 72000, 1920, 1952,
  894. 2120, 2304, 0, 1080, 1126, 1136, 1250, 0,
  895. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC |
  896. DRM_MODE_FLAG_INTERLACE),
  897. .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  898. /* 40 - 1920x1080i@100Hz 16:9 */
  899. { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2448,
  900. 2492, 2640, 0, 1080, 1084, 1094, 1125, 0,
  901. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
  902. DRM_MODE_FLAG_INTERLACE),
  903. .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  904. /* 41 - 1280x720@100Hz 16:9 */
  905. { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1720,
  906. 1760, 1980, 0, 720, 725, 730, 750, 0,
  907. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  908. .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  909. /* 42 - 720x576@100Hz 4:3 */
  910. { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
  911. 796, 864, 0, 576, 581, 586, 625, 0,
  912. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  913. .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  914. /* 43 - 720x576@100Hz 16:9 */
  915. { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
  916. 796, 864, 0, 576, 581, 586, 625, 0,
  917. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  918. .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  919. /* 44 - 720(1440)x576i@100Hz 4:3 */
  920. { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
  921. 795, 864, 0, 576, 580, 586, 625, 0,
  922. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
  923. DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
  924. .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  925. /* 45 - 720(1440)x576i@100Hz 16:9 */
  926. { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
  927. 795, 864, 0, 576, 580, 586, 625, 0,
  928. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
  929. DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
  930. .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  931. /* 46 - 1920x1080i@120Hz 16:9 */
  932. { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
  933. 2052, 2200, 0, 1080, 1084, 1094, 1125, 0,
  934. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
  935. DRM_MODE_FLAG_INTERLACE),
  936. .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  937. /* 47 - 1280x720@120Hz 16:9 */
  938. { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1390,
  939. 1430, 1650, 0, 720, 725, 730, 750, 0,
  940. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  941. .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  942. /* 48 - 720x480@120Hz 4:3 */
  943. { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 54000, 720, 736,
  944. 798, 858, 0, 480, 489, 495, 525, 0,
  945. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  946. .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  947. /* 49 - 720x480@120Hz 16:9 */
  948. { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 54000, 720, 736,
  949. 798, 858, 0, 480, 489, 495, 525, 0,
  950. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  951. .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  952. /* 50 - 720(1440)x480i@120Hz 4:3 */
  953. { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 27000, 720, 739,
  954. 801, 858, 0, 480, 488, 494, 525, 0,
  955. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
  956. DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
  957. .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  958. /* 51 - 720(1440)x480i@120Hz 16:9 */
  959. { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 27000, 720, 739,
  960. 801, 858, 0, 480, 488, 494, 525, 0,
  961. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
  962. DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
  963. .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  964. /* 52 - 720x576@200Hz 4:3 */
  965. { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 108000, 720, 732,
  966. 796, 864, 0, 576, 581, 586, 625, 0,
  967. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  968. .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  969. /* 53 - 720x576@200Hz 16:9 */
  970. { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 108000, 720, 732,
  971. 796, 864, 0, 576, 581, 586, 625, 0,
  972. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  973. .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  974. /* 54 - 720(1440)x576i@200Hz 4:3 */
  975. { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
  976. 795, 864, 0, 576, 580, 586, 625, 0,
  977. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
  978. DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
  979. .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  980. /* 55 - 720(1440)x576i@200Hz 16:9 */
  981. { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
  982. 795, 864, 0, 576, 580, 586, 625, 0,
  983. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
  984. DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
  985. .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  986. /* 56 - 720x480@240Hz 4:3 */
  987. { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 108000, 720, 736,
  988. 798, 858, 0, 480, 489, 495, 525, 0,
  989. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  990. .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  991. /* 57 - 720x480@240Hz 16:9 */
  992. { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 108000, 720, 736,
  993. 798, 858, 0, 480, 489, 495, 525, 0,
  994. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  995. .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  996. /* 58 - 720(1440)x480i@240Hz 4:3 */
  997. { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 54000, 720, 739,
  998. 801, 858, 0, 480, 488, 494, 525, 0,
  999. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
  1000. DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
  1001. .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
  1002. /* 59 - 720(1440)x480i@240Hz 16:9 */
  1003. { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 54000, 720, 739,
  1004. 801, 858, 0, 480, 488, 494, 525, 0,
  1005. DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
  1006. DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
  1007. .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  1008. /* 60 - 1280x720@24Hz 16:9 */
  1009. { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 59400, 1280, 3040,
  1010. 3080, 3300, 0, 720, 725, 730, 750, 0,
  1011. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1012. .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  1013. /* 61 - 1280x720@25Hz 16:9 */
  1014. { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3700,
  1015. 3740, 3960, 0, 720, 725, 730, 750, 0,
  1016. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1017. .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  1018. /* 62 - 1280x720@30Hz 16:9 */
  1019. { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3040,
  1020. 3080, 3300, 0, 720, 725, 730, 750, 0,
  1021. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1022. .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  1023. /* 63 - 1920x1080@120Hz 16:9 */
  1024. { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2008,
  1025. 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
  1026. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1027. .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  1028. /* 64 - 1920x1080@100Hz 16:9 */
  1029. { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2448,
  1030. 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
  1031. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1032. .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  1033. /* 65 - 1280x720@24Hz 64:27 */
  1034. { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 59400, 1280, 3040,
  1035. 3080, 3300, 0, 720, 725, 730, 750, 0,
  1036. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1037. .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1038. /* 66 - 1280x720@25Hz 64:27 */
  1039. { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3700,
  1040. 3740, 3960, 0, 720, 725, 730, 750, 0,
  1041. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1042. .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1043. /* 67 - 1280x720@30Hz 64:27 */
  1044. { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3040,
  1045. 3080, 3300, 0, 720, 725, 730, 750, 0,
  1046. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1047. .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1048. /* 68 - 1280x720@50Hz 64:27 */
  1049. { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1720,
  1050. 1760, 1980, 0, 720, 725, 730, 750, 0,
  1051. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1052. .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1053. /* 69 - 1280x720@60Hz 64:27 */
  1054. { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1390,
  1055. 1430, 1650, 0, 720, 725, 730, 750, 0,
  1056. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1057. .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1058. /* 70 - 1280x720@100Hz 64:27 */
  1059. { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1720,
  1060. 1760, 1980, 0, 720, 725, 730, 750, 0,
  1061. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1062. .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1063. /* 71 - 1280x720@120Hz 64:27 */
  1064. { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1390,
  1065. 1430, 1650, 0, 720, 725, 730, 750, 0,
  1066. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1067. .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1068. /* 72 - 1920x1080@24Hz 64:27 */
  1069. { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2558,
  1070. 2602, 2750, 0, 1080, 1084, 1089, 1125, 0,
  1071. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1072. .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1073. /* 73 - 1920x1080@25Hz 64:27 */
  1074. { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2448,
  1075. 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
  1076. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1077. .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1078. /* 74 - 1920x1080@30Hz 64:27 */
  1079. { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2008,
  1080. 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
  1081. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1082. .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1083. /* 75 - 1920x1080@50Hz 64:27 */
  1084. { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2448,
  1085. 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
  1086. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1087. .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1088. /* 76 - 1920x1080@60Hz 64:27 */
  1089. { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
  1090. 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
  1091. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1092. .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1093. /* 77 - 1920x1080@100Hz 64:27 */
  1094. { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2448,
  1095. 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
  1096. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1097. .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1098. /* 78 - 1920x1080@120Hz 64:27 */
  1099. { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2008,
  1100. 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
  1101. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1102. .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1103. /* 79 - 1680x720@24Hz 64:27 */
  1104. { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 59400, 1680, 3040,
  1105. 3080, 3300, 0, 720, 725, 730, 750, 0,
  1106. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1107. .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1108. /* 80 - 1680x720@25Hz 64:27 */
  1109. { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 59400, 1680, 2908,
  1110. 2948, 3168, 0, 720, 725, 730, 750, 0,
  1111. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1112. .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1113. /* 81 - 1680x720@30Hz 64:27 */
  1114. { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 59400, 1680, 2380,
  1115. 2420, 2640, 0, 720, 725, 730, 750, 0,
  1116. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1117. .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1118. /* 82 - 1680x720@50Hz 64:27 */
  1119. { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 82500, 1680, 1940,
  1120. 1980, 2200, 0, 720, 725, 730, 750, 0,
  1121. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1122. .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1123. /* 83 - 1680x720@60Hz 64:27 */
  1124. { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 99000, 1680, 1940,
  1125. 1980, 2200, 0, 720, 725, 730, 750, 0,
  1126. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1127. .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1128. /* 84 - 1680x720@100Hz 64:27 */
  1129. { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 165000, 1680, 1740,
  1130. 1780, 2000, 0, 720, 725, 730, 825, 0,
  1131. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1132. .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1133. /* 85 - 1680x720@120Hz 64:27 */
  1134. { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 198000, 1680, 1740,
  1135. 1780, 2000, 0, 720, 725, 730, 825, 0,
  1136. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1137. .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1138. /* 86 - 2560x1080@24Hz 64:27 */
  1139. { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 99000, 2560, 3558,
  1140. 3602, 3750, 0, 1080, 1084, 1089, 1100, 0,
  1141. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1142. .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1143. /* 87 - 2560x1080@25Hz 64:27 */
  1144. { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 90000, 2560, 3008,
  1145. 3052, 3200, 0, 1080, 1084, 1089, 1125, 0,
  1146. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1147. .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1148. /* 88 - 2560x1080@30Hz 64:27 */
  1149. { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 118800, 2560, 3328,
  1150. 3372, 3520, 0, 1080, 1084, 1089, 1125, 0,
  1151. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1152. .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1153. /* 89 - 2560x1080@50Hz 64:27 */
  1154. { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 185625, 2560, 3108,
  1155. 3152, 3300, 0, 1080, 1084, 1089, 1125, 0,
  1156. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1157. .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1158. /* 90 - 2560x1080@60Hz 64:27 */
  1159. { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 198000, 2560, 2808,
  1160. 2852, 3000, 0, 1080, 1084, 1089, 1100, 0,
  1161. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1162. .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1163. /* 91 - 2560x1080@100Hz 64:27 */
  1164. { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 371250, 2560, 2778,
  1165. 2822, 2970, 0, 1080, 1084, 1089, 1250, 0,
  1166. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1167. .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1168. /* 92 - 2560x1080@120Hz 64:27 */
  1169. { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 495000, 2560, 3108,
  1170. 3152, 3300, 0, 1080, 1084, 1089, 1250, 0,
  1171. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1172. .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1173. /* 93 - 3840x2160@24Hz 16:9 */
  1174. { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 5116,
  1175. 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
  1176. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1177. .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  1178. /* 94 - 3840x2160@25Hz 16:9 */
  1179. { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4896,
  1180. 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
  1181. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1182. .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  1183. /* 95 - 3840x2160@30Hz 16:9 */
  1184. { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4016,
  1185. 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
  1186. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1187. .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  1188. /* 96 - 3840x2160@50Hz 16:9 */
  1189. { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4896,
  1190. 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
  1191. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1192. .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  1193. /* 97 - 3840x2160@60Hz 16:9 */
  1194. { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4016,
  1195. 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
  1196. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1197. .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
  1198. /* 98 - 4096x2160@24Hz 256:135 */
  1199. { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000, 4096, 5116,
  1200. 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
  1201. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1202. .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
  1203. /* 99 - 4096x2160@25Hz 256:135 */
  1204. { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000, 4096, 5064,
  1205. 5152, 5280, 0, 2160, 2168, 2178, 2250, 0,
  1206. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1207. .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
  1208. /* 100 - 4096x2160@30Hz 256:135 */
  1209. { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000, 4096, 4184,
  1210. 4272, 4400, 0, 2160, 2168, 2178, 2250, 0,
  1211. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1212. .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
  1213. /* 101 - 4096x2160@50Hz 256:135 */
  1214. { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 594000, 4096, 5064,
  1215. 5152, 5280, 0, 2160, 2168, 2178, 2250, 0,
  1216. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1217. .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
  1218. /* 102 - 4096x2160@60Hz 256:135 */
  1219. { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 594000, 4096, 4184,
  1220. 4272, 4400, 0, 2160, 2168, 2178, 2250, 0,
  1221. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1222. .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
  1223. /* 103 - 3840x2160@24Hz 64:27 */
  1224. { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 5116,
  1225. 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
  1226. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1227. .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1228. /* 104 - 3840x2160@25Hz 64:27 */
  1229. { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4896,
  1230. 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
  1231. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1232. .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1233. /* 105 - 3840x2160@30Hz 64:27 */
  1234. { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4016,
  1235. 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
  1236. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1237. .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1238. /* 106 - 3840x2160@50Hz 64:27 */
  1239. { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4896,
  1240. 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
  1241. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1242. .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1243. /* 107 - 3840x2160@60Hz 64:27 */
  1244. { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4016,
  1245. 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
  1246. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1247. .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
  1248. };
  1249. /*
  1250. * HDMI 1.4 4k modes. Index using the VIC.
  1251. */
  1252. static const struct drm_display_mode edid_4k_modes[] = {
  1253. /* 0 - dummy, VICs start at 1 */
  1254. { },
  1255. /* 1 - 3840x2160@30Hz */
  1256. { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
  1257. 3840, 4016, 4104, 4400, 0,
  1258. 2160, 2168, 2178, 2250, 0,
  1259. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1260. .vrefresh = 30, },
  1261. /* 2 - 3840x2160@25Hz */
  1262. { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
  1263. 3840, 4896, 4984, 5280, 0,
  1264. 2160, 2168, 2178, 2250, 0,
  1265. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1266. .vrefresh = 25, },
  1267. /* 3 - 3840x2160@24Hz */
  1268. { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
  1269. 3840, 5116, 5204, 5500, 0,
  1270. 2160, 2168, 2178, 2250, 0,
  1271. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1272. .vrefresh = 24, },
  1273. /* 4 - 4096x2160@24Hz (SMPTE) */
  1274. { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000,
  1275. 4096, 5116, 5204, 5500, 0,
  1276. 2160, 2168, 2178, 2250, 0,
  1277. DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
  1278. .vrefresh = 24, },
  1279. };
  1280. /*** DDC fetch and block validation ***/
  1281. static const u8 edid_header[] = {
  1282. 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00
  1283. };
  1284. /**
  1285. * drm_edid_header_is_valid - sanity check the header of the base EDID block
  1286. * @raw_edid: pointer to raw base EDID block
  1287. *
  1288. * Sanity check the header of the base EDID block.
  1289. *
  1290. * Return: 8 if the header is perfect, down to 0 if it's totally wrong.
  1291. */
  1292. int drm_edid_header_is_valid(const u8 *raw_edid)
  1293. {
  1294. int i, score = 0;
  1295. for (i = 0; i < sizeof(edid_header); i++)
  1296. if (raw_edid[i] == edid_header[i])
  1297. score++;
  1298. return score;
  1299. }
  1300. EXPORT_SYMBOL(drm_edid_header_is_valid);
  1301. static int edid_fixup __read_mostly = 6;
  1302. module_param_named(edid_fixup, edid_fixup, int, 0400);
  1303. MODULE_PARM_DESC(edid_fixup,
  1304. "Minimum number of valid EDID header bytes (0-8, default 6)");
  1305. static void drm_get_displayid(struct drm_connector *connector,
  1306. struct edid *edid);
  1307. static int validate_displayid(u8 *displayid, int length, int idx);
  1308. static int drm_edid_block_checksum(const u8 *raw_edid)
  1309. {
  1310. int i;
  1311. u8 csum = 0;
  1312. for (i = 0; i < EDID_LENGTH; i++)
  1313. csum += raw_edid[i];
  1314. return csum;
  1315. }
  1316. static bool drm_edid_is_zero(const u8 *in_edid, int length)
  1317. {
  1318. if (memchr_inv(in_edid, 0, length))
  1319. return false;
  1320. return true;
  1321. }
  1322. /**
  1323. * drm_edid_block_valid - Sanity check the EDID block (base or extension)
  1324. * @raw_edid: pointer to raw EDID block
  1325. * @block: type of block to validate (0 for base, extension otherwise)
  1326. * @print_bad_edid: if true, dump bad EDID blocks to the console
  1327. * @edid_corrupt: if true, the header or checksum is invalid
  1328. *
  1329. * Validate a base or extension EDID block and optionally dump bad blocks to
  1330. * the console.
  1331. *
  1332. * Return: True if the block is valid, false otherwise.
  1333. */
  1334. bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid,
  1335. bool *edid_corrupt)
  1336. {
  1337. u8 csum;
  1338. struct edid *edid = (struct edid *)raw_edid;
  1339. if (WARN_ON(!raw_edid))
  1340. return false;
  1341. if (edid_fixup > 8 || edid_fixup < 0)
  1342. edid_fixup = 6;
  1343. if (block == 0) {
  1344. int score = drm_edid_header_is_valid(raw_edid);
  1345. if (score == 8) {
  1346. if (edid_corrupt)
  1347. *edid_corrupt = false;
  1348. } else if (score >= edid_fixup) {
  1349. /* Displayport Link CTS Core 1.2 rev1.1 test 4.2.2.6
  1350. * The corrupt flag needs to be set here otherwise, the
  1351. * fix-up code here will correct the problem, the
  1352. * checksum is correct and the test fails
  1353. */
  1354. if (edid_corrupt)
  1355. *edid_corrupt = true;
  1356. DRM_DEBUG("Fixing EDID header, your hardware may be failing\n");
  1357. memcpy(raw_edid, edid_header, sizeof(edid_header));
  1358. } else {
  1359. if (edid_corrupt)
  1360. *edid_corrupt = true;
  1361. goto bad;
  1362. }
  1363. }
  1364. csum = drm_edid_block_checksum(raw_edid);
  1365. if (csum) {
  1366. if (edid_corrupt)
  1367. *edid_corrupt = true;
  1368. /* allow CEA to slide through, switches mangle this */
  1369. if (raw_edid[0] == CEA_EXT) {
  1370. DRM_DEBUG("EDID checksum is invalid, remainder is %d\n", csum);
  1371. DRM_DEBUG("Assuming a KVM switch modified the CEA block but left the original checksum\n");
  1372. } else {
  1373. if (print_bad_edid)
  1374. DRM_NOTE("EDID checksum is invalid, remainder is %d\n", csum);
  1375. goto bad;
  1376. }
  1377. }
  1378. /* per-block-type checks */
  1379. switch (raw_edid[0]) {
  1380. case 0: /* base */
  1381. if (edid->version != 1) {
  1382. DRM_NOTE("EDID has major version %d, instead of 1\n", edid->version);
  1383. goto bad;
  1384. }
  1385. if (edid->revision > 4)
  1386. DRM_DEBUG("EDID minor > 4, assuming backward compatibility\n");
  1387. break;
  1388. default:
  1389. break;
  1390. }
  1391. return true;
  1392. bad:
  1393. if (print_bad_edid) {
  1394. if (drm_edid_is_zero(raw_edid, EDID_LENGTH)) {
  1395. pr_notice("EDID block is all zeroes\n");
  1396. } else {
  1397. pr_notice("Raw EDID:\n");
  1398. print_hex_dump(KERN_NOTICE,
  1399. " \t", DUMP_PREFIX_NONE, 16, 1,
  1400. raw_edid, EDID_LENGTH, false);
  1401. }
  1402. }
  1403. return false;
  1404. }
  1405. EXPORT_SYMBOL(drm_edid_block_valid);
  1406. /**
  1407. * drm_edid_is_valid - sanity check EDID data
  1408. * @edid: EDID data
  1409. *
  1410. * Sanity-check an entire EDID record (including extensions)
  1411. *
  1412. * Return: True if the EDID data is valid, false otherwise.
  1413. */
  1414. bool drm_edid_is_valid(struct edid *edid)
  1415. {
  1416. int i;
  1417. u8 *raw = (u8 *)edid;
  1418. if (!edid)
  1419. return false;
  1420. for (i = 0; i <= edid->extensions; i++)
  1421. if (!drm_edid_block_valid(raw + i * EDID_LENGTH, i, true, NULL))
  1422. return false;
  1423. return true;
  1424. }
  1425. EXPORT_SYMBOL(drm_edid_is_valid);
  1426. #define DDC_SEGMENT_ADDR 0x30
  1427. /**
  1428. * drm_do_probe_ddc_edid() - get EDID information via I2C
  1429. * @data: I2C device adapter
  1430. * @buf: EDID data buffer to be filled
  1431. * @block: 128 byte EDID block to start fetching from
  1432. * @len: EDID data buffer length to fetch
  1433. *
  1434. * Try to fetch EDID information by calling I2C driver functions.
  1435. *
  1436. * Return: 0 on success or -1 on failure.
  1437. */
  1438. static int
  1439. drm_do_probe_ddc_edid(void *data, u8 *buf, unsigned int block, size_t len)
  1440. {
  1441. struct i2c_adapter *adapter = data;
  1442. unsigned char start = block * EDID_LENGTH;
  1443. unsigned char segment = block >> 1;
  1444. unsigned char xfers = segment ? 3 : 2;
  1445. int ret, retries = 5;
  1446. /*
  1447. * The core I2C driver will automatically retry the transfer if the
  1448. * adapter reports EAGAIN. However, we find that bit-banging transfers
  1449. * are susceptible to errors under a heavily loaded machine and
  1450. * generate spurious NAKs and timeouts. Retrying the transfer
  1451. * of the individual block a few times seems to overcome this.
  1452. */
  1453. do {
  1454. struct i2c_msg msgs[] = {
  1455. {
  1456. .addr = DDC_SEGMENT_ADDR,
  1457. .flags = 0,
  1458. .len = 1,
  1459. .buf = &segment,
  1460. }, {
  1461. .addr = DDC_ADDR,
  1462. .flags = 0,
  1463. .len = 1,
  1464. .buf = &start,
  1465. }, {
  1466. .addr = DDC_ADDR,
  1467. .flags = I2C_M_RD,
  1468. .len = len,
  1469. .buf = buf,
  1470. }
  1471. };
  1472. /*
  1473. * Avoid sending the segment addr to not upset non-compliant
  1474. * DDC monitors.
  1475. */
  1476. ret = i2c_transfer(adapter, &msgs[3 - xfers], xfers);
  1477. if (ret == -ENXIO) {
  1478. DRM_DEBUG_KMS("drm: skipping non-existent adapter %s\n",
  1479. adapter->name);
  1480. break;
  1481. }
  1482. } while (ret != xfers && --retries);
  1483. return ret == xfers ? 0 : -1;
  1484. }
  1485. static void connector_bad_edid(struct drm_connector *connector,
  1486. u8 *edid, int num_blocks)
  1487. {
  1488. int i;
  1489. if (connector->bad_edid_counter++ && !(drm_debug & DRM_UT_KMS))
  1490. return;
  1491. dev_warn(connector->dev->dev,
  1492. "%s: EDID is invalid:\n",
  1493. connector->name);
  1494. for (i = 0; i < num_blocks; i++) {
  1495. u8 *block = edid + i * EDID_LENGTH;
  1496. char prefix[20];
  1497. if (drm_edid_is_zero(block, EDID_LENGTH))
  1498. sprintf(prefix, "\t[%02x] ZERO ", i);
  1499. else if (!drm_edid_block_valid(block, i, false, NULL))
  1500. sprintf(prefix, "\t[%02x] BAD ", i);
  1501. else
  1502. sprintf(prefix, "\t[%02x] GOOD ", i);
  1503. print_hex_dump(KERN_WARNING,
  1504. prefix, DUMP_PREFIX_NONE, 16, 1,
  1505. block, EDID_LENGTH, false);
  1506. }
  1507. }
  1508. /* Get override or firmware EDID */
  1509. static struct edid *drm_get_override_edid(struct drm_connector *connector)
  1510. {
  1511. struct edid *override = NULL;
  1512. if (connector->override_edid)
  1513. override = drm_edid_duplicate(connector->edid_blob_ptr->data);
  1514. if (!override)
  1515. override = drm_load_edid_firmware(connector);
  1516. return IS_ERR(override) ? NULL : override;
  1517. }
  1518. /**
  1519. * drm_add_override_edid_modes - add modes from override/firmware EDID
  1520. * @connector: connector we're probing
  1521. *
  1522. * Add modes from the override/firmware EDID, if available. Only to be used from
  1523. * drm_helper_probe_single_connector_modes() as a fallback for when DDC probe
  1524. * failed during drm_get_edid() and caused the override/firmware EDID to be
  1525. * skipped.
  1526. *
  1527. * Return: The number of modes added or 0 if we couldn't find any.
  1528. */
  1529. int drm_add_override_edid_modes(struct drm_connector *connector)
  1530. {
  1531. struct edid *override;
  1532. int num_modes = 0;
  1533. override = drm_get_override_edid(connector);
  1534. if (override) {
  1535. drm_connector_update_edid_property(connector, override);
  1536. num_modes = drm_add_edid_modes(connector, override);
  1537. kfree(override);
  1538. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] adding %d modes via fallback override/firmware EDID\n",
  1539. connector->base.id, connector->name, num_modes);
  1540. }
  1541. return num_modes;
  1542. }
  1543. EXPORT_SYMBOL(drm_add_override_edid_modes);
  1544. /**
  1545. * drm_do_get_edid - get EDID data using a custom EDID block read function
  1546. * @connector: connector we're probing
  1547. * @get_edid_block: EDID block read function
  1548. * @data: private data passed to the block read function
  1549. *
  1550. * When the I2C adapter connected to the DDC bus is hidden behind a device that
  1551. * exposes a different interface to read EDID blocks this function can be used
  1552. * to get EDID data using a custom block read function.
  1553. *
  1554. * As in the general case the DDC bus is accessible by the kernel at the I2C
  1555. * level, drivers must make all reasonable efforts to expose it as an I2C
  1556. * adapter and use drm_get_edid() instead of abusing this function.
  1557. *
  1558. * The EDID may be overridden using debugfs override_edid or firmare EDID
  1559. * (drm_load_edid_firmware() and drm.edid_firmware parameter), in this priority
  1560. * order. Having either of them bypasses actual EDID reads.
  1561. *
  1562. * Return: Pointer to valid EDID or NULL if we couldn't find any.
  1563. */
  1564. struct edid *drm_do_get_edid(struct drm_connector *connector,
  1565. int (*get_edid_block)(void *data, u8 *buf, unsigned int block,
  1566. size_t len),
  1567. void *data)
  1568. {
  1569. int i, j = 0, valid_extensions = 0;
  1570. u8 *edid, *new;
  1571. struct edid *override;
  1572. override = drm_get_override_edid(connector);
  1573. if (override)
  1574. return override;
  1575. if ((edid = kmalloc(EDID_LENGTH, GFP_KERNEL)) == NULL)
  1576. return NULL;
  1577. /* base block fetch */
  1578. for (i = 0; i < 4; i++) {
  1579. if (get_edid_block(data, edid, 0, EDID_LENGTH))
  1580. goto out;
  1581. if (drm_edid_block_valid(edid, 0, false,
  1582. &connector->edid_corrupt))
  1583. break;
  1584. if (i == 0 && drm_edid_is_zero(edid, EDID_LENGTH)) {
  1585. connector->null_edid_counter++;
  1586. goto carp;
  1587. }
  1588. }
  1589. if (i == 4)
  1590. goto carp;
  1591. /* if there's no extensions, we're done */
  1592. valid_extensions = edid[0x7e];
  1593. if (valid_extensions == 0)
  1594. return (struct edid *)edid;
  1595. new = krealloc(edid, (valid_extensions + 1) * EDID_LENGTH, GFP_KERNEL);
  1596. if (!new)
  1597. goto out;
  1598. edid = new;
  1599. for (j = 1; j <= edid[0x7e]; j++) {
  1600. u8 *block = edid + j * EDID_LENGTH;
  1601. for (i = 0; i < 4; i++) {
  1602. if (get_edid_block(data, block, j, EDID_LENGTH))
  1603. goto out;
  1604. if (drm_edid_block_valid(block, j, false, NULL))
  1605. break;
  1606. }
  1607. if (i == 4)
  1608. valid_extensions--;
  1609. }
  1610. if (valid_extensions != edid[0x7e]) {
  1611. u8 *base;
  1612. connector_bad_edid(connector, edid, edid[0x7e] + 1);
  1613. edid[EDID_LENGTH-1] += edid[0x7e] - valid_extensions;
  1614. edid[0x7e] = valid_extensions;
  1615. new = kmalloc_array(valid_extensions + 1, EDID_LENGTH,
  1616. GFP_KERNEL);
  1617. if (!new)
  1618. goto out;
  1619. base = new;
  1620. for (i = 0; i <= edid[0x7e]; i++) {
  1621. u8 *block = edid + i * EDID_LENGTH;
  1622. if (!drm_edid_block_valid(block, i, false, NULL))
  1623. continue;
  1624. memcpy(base, block, EDID_LENGTH);
  1625. base += EDID_LENGTH;
  1626. }
  1627. kfree(edid);
  1628. edid = new;
  1629. }
  1630. return (struct edid *)edid;
  1631. carp:
  1632. connector_bad_edid(connector, edid, 1);
  1633. out:
  1634. kfree(edid);
  1635. return NULL;
  1636. }
  1637. EXPORT_SYMBOL_GPL(drm_do_get_edid);
  1638. /**
  1639. * drm_probe_ddc() - probe DDC presence
  1640. * @adapter: I2C adapter to probe
  1641. *
  1642. * Return: True on success, false on failure.
  1643. */
  1644. bool
  1645. drm_probe_ddc(struct i2c_adapter *adapter)
  1646. {
  1647. unsigned char out;
  1648. return (drm_do_probe_ddc_edid(adapter, &out, 0, 1) == 0);
  1649. }
  1650. EXPORT_SYMBOL(drm_probe_ddc);
  1651. /**
  1652. * drm_get_edid - get EDID data, if available
  1653. * @connector: connector we're probing
  1654. * @adapter: I2C adapter to use for DDC
  1655. *
  1656. * Poke the given I2C channel to grab EDID data if possible. If found,
  1657. * attach it to the connector.
  1658. *
  1659. * Return: Pointer to valid EDID or NULL if we couldn't find any.
  1660. */
  1661. struct edid *drm_get_edid(struct drm_connector *connector,
  1662. struct i2c_adapter *adapter)
  1663. {
  1664. struct edid *edid;
  1665. if (connector->force == DRM_FORCE_OFF)
  1666. return NULL;
  1667. if (connector->force == DRM_FORCE_UNSPECIFIED && !drm_probe_ddc(adapter))
  1668. return NULL;
  1669. edid = drm_do_get_edid(connector, drm_do_probe_ddc_edid, adapter);
  1670. if (edid)
  1671. drm_get_displayid(connector, edid);
  1672. return edid;
  1673. }
  1674. EXPORT_SYMBOL(drm_get_edid);
  1675. /**
  1676. * drm_get_edid_switcheroo - get EDID data for a vga_switcheroo output
  1677. * @connector: connector we're probing
  1678. * @adapter: I2C adapter to use for DDC
  1679. *
  1680. * Wrapper around drm_get_edid() for laptops with dual GPUs using one set of
  1681. * outputs. The wrapper adds the requisite vga_switcheroo calls to temporarily
  1682. * switch DDC to the GPU which is retrieving EDID.
  1683. *
  1684. * Return: Pointer to valid EDID or %NULL if we couldn't find any.
  1685. */
  1686. struct edid *drm_get_edid_switcheroo(struct drm_connector *connector,
  1687. struct i2c_adapter *adapter)
  1688. {
  1689. struct pci_dev *pdev = connector->dev->pdev;
  1690. struct edid *edid;
  1691. vga_switcheroo_lock_ddc(pdev);
  1692. edid = drm_get_edid(connector, adapter);
  1693. vga_switcheroo_unlock_ddc(pdev);
  1694. return edid;
  1695. }
  1696. EXPORT_SYMBOL(drm_get_edid_switcheroo);
  1697. /**
  1698. * drm_edid_duplicate - duplicate an EDID and the extensions
  1699. * @edid: EDID to duplicate
  1700. *
  1701. * Return: Pointer to duplicated EDID or NULL on allocation failure.
  1702. */
  1703. struct edid *drm_edid_duplicate(const struct edid *edid)
  1704. {
  1705. return kmemdup(edid, (edid->extensions + 1) * EDID_LENGTH, GFP_KERNEL);
  1706. }
  1707. EXPORT_SYMBOL(drm_edid_duplicate);
  1708. /*** EDID parsing ***/
  1709. /**
  1710. * edid_vendor - match a string against EDID's obfuscated vendor field
  1711. * @edid: EDID to match
  1712. * @vendor: vendor string
  1713. *
  1714. * Returns true if @vendor is in @edid, false otherwise
  1715. */
  1716. static bool edid_vendor(const struct edid *edid, const char *vendor)
  1717. {
  1718. char edid_vendor[3];
  1719. edid_vendor[0] = ((edid->mfg_id[0] & 0x7c) >> 2) + '@';
  1720. edid_vendor[1] = (((edid->mfg_id[0] & 0x3) << 3) |
  1721. ((edid->mfg_id[1] & 0xe0) >> 5)) + '@';
  1722. edid_vendor[2] = (edid->mfg_id[1] & 0x1f) + '@';
  1723. return !strncmp(edid_vendor, vendor, 3);
  1724. }
  1725. /**
  1726. * edid_get_quirks - return quirk flags for a given EDID
  1727. * @edid: EDID to process
  1728. *
  1729. * This tells subsequent routines what fixes they need to apply.
  1730. */
  1731. static u32 edid_get_quirks(const struct edid *edid)
  1732. {
  1733. const struct edid_quirk *quirk;
  1734. int i;
  1735. for (i = 0; i < ARRAY_SIZE(edid_quirk_list); i++) {
  1736. quirk = &edid_quirk_list[i];
  1737. if (edid_vendor(edid, quirk->vendor) &&
  1738. (EDID_PRODUCT_ID(edid) == quirk->product_id))
  1739. return quirk->quirks;
  1740. }
  1741. return 0;
  1742. }
  1743. #define MODE_SIZE(m) ((m)->hdisplay * (m)->vdisplay)
  1744. #define MODE_REFRESH_DIFF(c,t) (abs((c) - (t)))
  1745. /**
  1746. * edid_fixup_preferred - set preferred modes based on quirk list
  1747. * @connector: has mode list to fix up
  1748. * @quirks: quirks list
  1749. *
  1750. * Walk the mode list for @connector, clearing the preferred status
  1751. * on existing modes and setting it anew for the right mode ala @quirks.
  1752. */
  1753. static void edid_fixup_preferred(struct drm_connector *connector,
  1754. u32 quirks)
  1755. {
  1756. struct drm_display_mode *t, *cur_mode, *preferred_mode;
  1757. int target_refresh = 0;
  1758. int cur_vrefresh, preferred_vrefresh;
  1759. if (list_empty(&connector->probed_modes))
  1760. return;
  1761. if (quirks & EDID_QUIRK_PREFER_LARGE_60)
  1762. target_refresh = 60;
  1763. if (quirks & EDID_QUIRK_PREFER_LARGE_75)
  1764. target_refresh = 75;
  1765. preferred_mode = list_first_entry(&connector->probed_modes,
  1766. struct drm_display_mode, head);
  1767. list_for_each_entry_safe(cur_mode, t, &connector->probed_modes, head) {
  1768. cur_mode->type &= ~DRM_MODE_TYPE_PREFERRED;
  1769. if (cur_mode == preferred_mode)
  1770. continue;
  1771. /* Largest mode is preferred */
  1772. if (MODE_SIZE(cur_mode) > MODE_SIZE(preferred_mode))
  1773. preferred_mode = cur_mode;
  1774. cur_vrefresh = cur_mode->vrefresh ?
  1775. cur_mode->vrefresh : drm_mode_vrefresh(cur_mode);
  1776. preferred_vrefresh = preferred_mode->vrefresh ?
  1777. preferred_mode->vrefresh : drm_mode_vrefresh(preferred_mode);
  1778. /* At a given size, try to get closest to target refresh */
  1779. if ((MODE_SIZE(cur_mode) == MODE_SIZE(preferred_mode)) &&
  1780. MODE_REFRESH_DIFF(cur_vrefresh, target_refresh) <
  1781. MODE_REFRESH_DIFF(preferred_vrefresh, target_refresh)) {
  1782. preferred_mode = cur_mode;
  1783. }
  1784. }
  1785. preferred_mode->type |= DRM_MODE_TYPE_PREFERRED;
  1786. }
  1787. static bool
  1788. mode_is_rb(const struct drm_display_mode *mode)
  1789. {
  1790. return (mode->htotal - mode->hdisplay == 160) &&
  1791. (mode->hsync_end - mode->hdisplay == 80) &&
  1792. (mode->hsync_end - mode->hsync_start == 32) &&
  1793. (mode->vsync_start - mode->vdisplay == 3);
  1794. }
  1795. /*
  1796. * drm_mode_find_dmt - Create a copy of a mode if present in DMT
  1797. * @dev: Device to duplicate against
  1798. * @hsize: Mode width
  1799. * @vsize: Mode height
  1800. * @fresh: Mode refresh rate
  1801. * @rb: Mode reduced-blanking-ness
  1802. *
  1803. * Walk the DMT mode list looking for a match for the given parameters.
  1804. *
  1805. * Return: A newly allocated copy of the mode, or NULL if not found.
  1806. */
  1807. struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
  1808. int hsize, int vsize, int fresh,
  1809. bool rb)
  1810. {
  1811. int i;
  1812. for (i = 0; i < ARRAY_SIZE(drm_dmt_modes); i++) {
  1813. const struct drm_display_mode *ptr = &drm_dmt_modes[i];
  1814. if (hsize != ptr->hdisplay)
  1815. continue;
  1816. if (vsize != ptr->vdisplay)
  1817. continue;
  1818. if (fresh != drm_mode_vrefresh(ptr))
  1819. continue;
  1820. if (rb != mode_is_rb(ptr))
  1821. continue;
  1822. return drm_mode_duplicate(dev, ptr);
  1823. }
  1824. return NULL;
  1825. }
  1826. EXPORT_SYMBOL(drm_mode_find_dmt);
  1827. typedef void detailed_cb(struct detailed_timing *timing, void *closure);
  1828. static void
  1829. cea_for_each_detailed_block(u8 *ext, detailed_cb *cb, void *closure)
  1830. {
  1831. int i, n = 0;
  1832. u8 d = ext[0x02];
  1833. u8 *det_base = ext + d;
  1834. n = (127 - d) / 18;
  1835. for (i = 0; i < n; i++)
  1836. cb((struct detailed_timing *)(det_base + 18 * i), closure);
  1837. }
  1838. static void
  1839. vtb_for_each_detailed_block(u8 *ext, detailed_cb *cb, void *closure)
  1840. {
  1841. unsigned int i, n = min((int)ext[0x02], 6);
  1842. u8 *det_base = ext + 5;
  1843. if (ext[0x01] != 1)
  1844. return; /* unknown version */
  1845. for (i = 0; i < n; i++)
  1846. cb((struct detailed_timing *)(det_base + 18 * i), closure);
  1847. }
  1848. static void
  1849. drm_for_each_detailed_block(u8 *raw_edid, detailed_cb *cb, void *closure)
  1850. {
  1851. int i;
  1852. struct edid *edid = (struct edid *)raw_edid;
  1853. if (edid == NULL)
  1854. return;
  1855. for (i = 0; i < EDID_DETAILED_TIMINGS; i++)
  1856. cb(&(edid->detailed_timings[i]), closure);
  1857. for (i = 1; i <= raw_edid[0x7e]; i++) {
  1858. u8 *ext = raw_edid + (i * EDID_LENGTH);
  1859. switch (*ext) {
  1860. case CEA_EXT:
  1861. cea_for_each_detailed_block(ext, cb, closure);
  1862. break;
  1863. case VTB_EXT:
  1864. vtb_for_each_detailed_block(ext, cb, closure);
  1865. break;
  1866. default:
  1867. break;
  1868. }
  1869. }
  1870. }
  1871. static void
  1872. is_rb(struct detailed_timing *t, void *data)
  1873. {
  1874. u8 *r = (u8 *)t;
  1875. if (r[3] == EDID_DETAIL_MONITOR_RANGE)
  1876. if (r[15] & 0x10)
  1877. *(bool *)data = true;
  1878. }
  1879. /* EDID 1.4 defines this explicitly. For EDID 1.3, we guess, badly. */
  1880. static bool
  1881. drm_monitor_supports_rb(struct edid *edid)
  1882. {
  1883. if (edid->revision >= 4) {
  1884. bool ret = false;
  1885. drm_for_each_detailed_block((u8 *)edid, is_rb, &ret);
  1886. return ret;
  1887. }
  1888. return ((edid->input & DRM_EDID_INPUT_DIGITAL) != 0);
  1889. }
  1890. static void
  1891. find_gtf2(struct detailed_timing *t, void *data)
  1892. {
  1893. u8 *r = (u8 *)t;
  1894. if (r[3] == EDID_DETAIL_MONITOR_RANGE && r[10] == 0x02)
  1895. *(u8 **)data = r;
  1896. }
  1897. /* Secondary GTF curve kicks in above some break frequency */
  1898. static int
  1899. drm_gtf2_hbreak(struct edid *edid)
  1900. {
  1901. u8 *r = NULL;
  1902. drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
  1903. return r ? (r[12] * 2) : 0;
  1904. }
  1905. static int
  1906. drm_gtf2_2c(struct edid *edid)
  1907. {
  1908. u8 *r = NULL;
  1909. drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
  1910. return r ? r[13] : 0;
  1911. }
  1912. static int
  1913. drm_gtf2_m(struct edid *edid)
  1914. {
  1915. u8 *r = NULL;
  1916. drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
  1917. return r ? (r[15] << 8) + r[14] : 0;
  1918. }
  1919. static int
  1920. drm_gtf2_k(struct edid *edid)
  1921. {
  1922. u8 *r = NULL;
  1923. drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
  1924. return r ? r[16] : 0;
  1925. }
  1926. static int
  1927. drm_gtf2_2j(struct edid *edid)
  1928. {
  1929. u8 *r = NULL;
  1930. drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
  1931. return r ? r[17] : 0;
  1932. }
  1933. /**
  1934. * standard_timing_level - get std. timing level(CVT/GTF/DMT)
  1935. * @edid: EDID block to scan
  1936. */
  1937. static int standard_timing_level(struct edid *edid)
  1938. {
  1939. if (edid->revision >= 2) {
  1940. if (edid->revision >= 4 && (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF))
  1941. return LEVEL_CVT;
  1942. if (drm_gtf2_hbreak(edid))
  1943. return LEVEL_GTF2;
  1944. return LEVEL_GTF;
  1945. }
  1946. return LEVEL_DMT;
  1947. }
  1948. /*
  1949. * 0 is reserved. The spec says 0x01 fill for unused timings. Some old
  1950. * monitors fill with ascii space (0x20) instead.
  1951. */
  1952. static int
  1953. bad_std_timing(u8 a, u8 b)
  1954. {
  1955. return (a == 0x00 && b == 0x00) ||
  1956. (a == 0x01 && b == 0x01) ||
  1957. (a == 0x20 && b == 0x20);
  1958. }
  1959. /**
  1960. * drm_mode_std - convert standard mode info (width, height, refresh) into mode
  1961. * @connector: connector of for the EDID block
  1962. * @edid: EDID block to scan
  1963. * @t: standard timing params
  1964. *
  1965. * Take the standard timing params (in this case width, aspect, and refresh)
  1966. * and convert them into a real mode using CVT/GTF/DMT.
  1967. */
  1968. static struct drm_display_mode *
  1969. drm_mode_std(struct drm_connector *connector, struct edid *edid,
  1970. struct std_timing *t)
  1971. {
  1972. struct drm_device *dev = connector->dev;
  1973. struct drm_display_mode *m, *mode = NULL;
  1974. int hsize, vsize;
  1975. int vrefresh_rate;
  1976. unsigned aspect_ratio = (t->vfreq_aspect & EDID_TIMING_ASPECT_MASK)
  1977. >> EDID_TIMING_ASPECT_SHIFT;
  1978. unsigned vfreq = (t->vfreq_aspect & EDID_TIMING_VFREQ_MASK)
  1979. >> EDID_TIMING_VFREQ_SHIFT;
  1980. int timing_level = standard_timing_level(edid);
  1981. if (bad_std_timing(t->hsize, t->vfreq_aspect))
  1982. return NULL;
  1983. /* According to the EDID spec, the hdisplay = hsize * 8 + 248 */
  1984. hsize = t->hsize * 8 + 248;
  1985. /* vrefresh_rate = vfreq + 60 */
  1986. vrefresh_rate = vfreq + 60;
  1987. /* the vdisplay is calculated based on the aspect ratio */
  1988. if (aspect_ratio == 0) {
  1989. if (edid->revision < 3)
  1990. vsize = hsize;
  1991. else
  1992. vsize = (hsize * 10) / 16;
  1993. } else if (aspect_ratio == 1)
  1994. vsize = (hsize * 3) / 4;
  1995. else if (aspect_ratio == 2)
  1996. vsize = (hsize * 4) / 5;
  1997. else
  1998. vsize = (hsize * 9) / 16;
  1999. /* HDTV hack, part 1 */
  2000. if (vrefresh_rate == 60 &&
  2001. ((hsize == 1360 && vsize == 765) ||
  2002. (hsize == 1368 && vsize == 769))) {
  2003. hsize = 1366;
  2004. vsize = 768;
  2005. }
  2006. /*
  2007. * If this connector already has a mode for this size and refresh
  2008. * rate (because it came from detailed or CVT info), use that
  2009. * instead. This way we don't have to guess at interlace or
  2010. * reduced blanking.
  2011. */
  2012. list_for_each_entry(m, &connector->probed_modes, head)
  2013. if (m->hdisplay == hsize && m->vdisplay == vsize &&
  2014. drm_mode_vrefresh(m) == vrefresh_rate)
  2015. return NULL;
  2016. /* HDTV hack, part 2 */
  2017. if (hsize == 1366 && vsize == 768 && vrefresh_rate == 60) {
  2018. mode = drm_cvt_mode(dev, 1366, 768, vrefresh_rate, 0, 0,
  2019. false);
  2020. if (!mode)
  2021. return NULL;
  2022. mode->hdisplay = 1366;
  2023. mode->hsync_start = mode->hsync_start - 1;
  2024. mode->hsync_end = mode->hsync_end - 1;
  2025. return mode;
  2026. }
  2027. /* check whether it can be found in default mode table */
  2028. if (drm_monitor_supports_rb(edid)) {
  2029. mode = drm_mode_find_dmt(dev, hsize, vsize, vrefresh_rate,
  2030. true);
  2031. if (mode)
  2032. return mode;
  2033. }
  2034. mode = drm_mode_find_dmt(dev, hsize, vsize, vrefresh_rate, false);
  2035. if (mode)
  2036. return mode;
  2037. /* okay, generate it */
  2038. switch (timing_level) {
  2039. case LEVEL_DMT:
  2040. break;
  2041. case LEVEL_GTF:
  2042. mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0);
  2043. break;
  2044. case LEVEL_GTF2:
  2045. /*
  2046. * This is potentially wrong if there's ever a monitor with
  2047. * more than one ranges section, each claiming a different
  2048. * secondary GTF curve. Please don't do that.
  2049. */
  2050. mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0);
  2051. if (!mode)
  2052. return NULL;
  2053. if (drm_mode_hsync(mode) > drm_gtf2_hbreak(edid)) {
  2054. drm_mode_destroy(dev, mode);
  2055. mode = drm_gtf_mode_complex(dev, hsize, vsize,
  2056. vrefresh_rate, 0, 0,
  2057. drm_gtf2_m(edid),
  2058. drm_gtf2_2c(edid),
  2059. drm_gtf2_k(edid),
  2060. drm_gtf2_2j(edid));
  2061. }
  2062. break;
  2063. case LEVEL_CVT:
  2064. mode = drm_cvt_mode(dev, hsize, vsize, vrefresh_rate, 0, 0,
  2065. false);
  2066. break;
  2067. }
  2068. return mode;
  2069. }
  2070. /*
  2071. * EDID is delightfully ambiguous about how interlaced modes are to be
  2072. * encoded. Our internal representation is of frame height, but some
  2073. * HDTV detailed timings are encoded as field height.
  2074. *
  2075. * The format list here is from CEA, in frame size. Technically we
  2076. * should be checking refresh rate too. Whatever.
  2077. */
  2078. static void
  2079. drm_mode_do_interlace_quirk(struct drm_display_mode *mode,
  2080. struct detailed_pixel_timing *pt)
  2081. {
  2082. int i;
  2083. static const struct {
  2084. int w, h;
  2085. } cea_interlaced[] = {
  2086. { 1920, 1080 },
  2087. { 720, 480 },
  2088. { 1440, 480 },
  2089. { 2880, 480 },
  2090. { 720, 576 },
  2091. { 1440, 576 },
  2092. { 2880, 576 },
  2093. };
  2094. if (!(pt->misc & DRM_EDID_PT_INTERLACED))
  2095. return;
  2096. for (i = 0; i < ARRAY_SIZE(cea_interlaced); i++) {
  2097. if ((mode->hdisplay == cea_interlaced[i].w) &&
  2098. (mode->vdisplay == cea_interlaced[i].h / 2)) {
  2099. mode->vdisplay *= 2;
  2100. mode->vsync_start *= 2;
  2101. mode->vsync_end *= 2;
  2102. mode->vtotal *= 2;
  2103. mode->vtotal |= 1;
  2104. }
  2105. }
  2106. mode->flags |= DRM_MODE_FLAG_INTERLACE;
  2107. }
  2108. /**
  2109. * drm_mode_detailed - create a new mode from an EDID detailed timing section
  2110. * @dev: DRM device (needed to create new mode)
  2111. * @edid: EDID block
  2112. * @timing: EDID detailed timing info
  2113. * @quirks: quirks to apply
  2114. *
  2115. * An EDID detailed timing block contains enough info for us to create and
  2116. * return a new struct drm_display_mode.
  2117. */
  2118. static struct drm_display_mode *drm_mode_detailed(struct drm_device *dev,
  2119. struct edid *edid,
  2120. struct detailed_timing *timing,
  2121. u32 quirks)
  2122. {
  2123. struct drm_display_mode *mode;
  2124. struct detailed_pixel_timing *pt = &timing->data.pixel_data;
  2125. unsigned hactive = (pt->hactive_hblank_hi & 0xf0) << 4 | pt->hactive_lo;
  2126. unsigned vactive = (pt->vactive_vblank_hi & 0xf0) << 4 | pt->vactive_lo;
  2127. unsigned hblank = (pt->hactive_hblank_hi & 0xf) << 8 | pt->hblank_lo;
  2128. unsigned vblank = (pt->vactive_vblank_hi & 0xf) << 8 | pt->vblank_lo;
  2129. unsigned hsync_offset = (pt->hsync_vsync_offset_pulse_width_hi & 0xc0) << 2 | pt->hsync_offset_lo;
  2130. unsigned hsync_pulse_width = (pt->hsync_vsync_offset_pulse_width_hi & 0x30) << 4 | pt->hsync_pulse_width_lo;
  2131. unsigned vsync_offset = (pt->hsync_vsync_offset_pulse_width_hi & 0xc) << 2 | pt->vsync_offset_pulse_width_lo >> 4;
  2132. unsigned vsync_pulse_width = (pt->hsync_vsync_offset_pulse_width_hi & 0x3) << 4 | (pt->vsync_offset_pulse_width_lo & 0xf);
  2133. /* ignore tiny modes */
  2134. if (hactive < 64 || vactive < 64)
  2135. return NULL;
  2136. if (pt->misc & DRM_EDID_PT_STEREO) {
  2137. DRM_DEBUG_KMS("stereo mode not supported\n");
  2138. return NULL;
  2139. }
  2140. if (!(pt->misc & DRM_EDID_PT_SEPARATE_SYNC)) {
  2141. DRM_DEBUG_KMS("composite sync not supported\n");
  2142. }
  2143. /* it is incorrect if hsync/vsync width is zero */
  2144. if (!hsync_pulse_width || !vsync_pulse_width) {
  2145. DRM_DEBUG_KMS("Incorrect Detailed timing. "
  2146. "Wrong Hsync/Vsync pulse width\n");
  2147. return NULL;
  2148. }
  2149. if (quirks & EDID_QUIRK_FORCE_REDUCED_BLANKING) {
  2150. mode = drm_cvt_mode(dev, hactive, vactive, 60, true, false, false);
  2151. if (!mode)
  2152. return NULL;
  2153. goto set_size;
  2154. }
  2155. mode = drm_mode_create(dev);
  2156. if (!mode)
  2157. return NULL;
  2158. if (quirks & EDID_QUIRK_135_CLOCK_TOO_HIGH)
  2159. timing->pixel_clock = cpu_to_le16(1088);
  2160. mode->clock = le16_to_cpu(timing->pixel_clock) * 10;
  2161. mode->hdisplay = hactive;
  2162. mode->hsync_start = mode->hdisplay + hsync_offset;
  2163. mode->hsync_end = mode->hsync_start + hsync_pulse_width;
  2164. mode->htotal = mode->hdisplay + hblank;
  2165. mode->vdisplay = vactive;
  2166. mode->vsync_start = mode->vdisplay + vsync_offset;
  2167. mode->vsync_end = mode->vsync_start + vsync_pulse_width;
  2168. mode->vtotal = mode->vdisplay + vblank;
  2169. /* Some EDIDs have bogus h/vtotal values */
  2170. if (mode->hsync_end > mode->htotal)
  2171. mode->htotal = mode->hsync_end + 1;
  2172. if (mode->vsync_end > mode->vtotal)
  2173. mode->vtotal = mode->vsync_end + 1;
  2174. drm_mode_do_interlace_quirk(mode, pt);
  2175. if (quirks & EDID_QUIRK_DETAILED_SYNC_PP) {
  2176. pt->misc |= DRM_EDID_PT_HSYNC_POSITIVE | DRM_EDID_PT_VSYNC_POSITIVE;
  2177. }
  2178. mode->flags |= (pt->misc & DRM_EDID_PT_HSYNC_POSITIVE) ?
  2179. DRM_MODE_FLAG_PHSYNC : DRM_MODE_FLAG_NHSYNC;
  2180. mode->flags |= (pt->misc & DRM_EDID_PT_VSYNC_POSITIVE) ?
  2181. DRM_MODE_FLAG_PVSYNC : DRM_MODE_FLAG_NVSYNC;
  2182. set_size:
  2183. mode->width_mm = pt->width_mm_lo | (pt->width_height_mm_hi & 0xf0) << 4;
  2184. mode->height_mm = pt->height_mm_lo | (pt->width_height_mm_hi & 0xf) << 8;
  2185. if (quirks & EDID_QUIRK_DETAILED_IN_CM) {
  2186. mode->width_mm *= 10;
  2187. mode->height_mm *= 10;
  2188. }
  2189. if (quirks & EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE) {
  2190. mode->width_mm = edid->width_cm * 10;
  2191. mode->height_mm = edid->height_cm * 10;
  2192. }
  2193. mode->type = DRM_MODE_TYPE_DRIVER;
  2194. mode->vrefresh = drm_mode_vrefresh(mode);
  2195. drm_mode_set_name(mode);
  2196. return mode;
  2197. }
  2198. static bool
  2199. mode_in_hsync_range(const struct drm_display_mode *mode,
  2200. struct edid *edid, u8 *t)
  2201. {
  2202. int hsync, hmin, hmax;
  2203. hmin = t[7];
  2204. if (edid->revision >= 4)
  2205. hmin += ((t[4] & 0x04) ? 255 : 0);
  2206. hmax = t[8];
  2207. if (edid->revision >= 4)
  2208. hmax += ((t[4] & 0x08) ? 255 : 0);
  2209. hsync = drm_mode_hsync(mode);
  2210. return (hsync <= hmax && hsync >= hmin);
  2211. }
  2212. static bool
  2213. mode_in_vsync_range(const struct drm_display_mode *mode,
  2214. struct edid *edid, u8 *t)
  2215. {
  2216. int vsync, vmin, vmax;
  2217. vmin = t[5];
  2218. if (edid->revision >= 4)
  2219. vmin += ((t[4] & 0x01) ? 255 : 0);
  2220. vmax = t[6];
  2221. if (edid->revision >= 4)
  2222. vmax += ((t[4] & 0x02) ? 255 : 0);
  2223. vsync = drm_mode_vrefresh(mode);
  2224. return (vsync <= vmax && vsync >= vmin);
  2225. }
  2226. static u32
  2227. range_pixel_clock(struct edid *edid, u8 *t)
  2228. {
  2229. /* unspecified */
  2230. if (t[9] == 0 || t[9] == 255)
  2231. return 0;
  2232. /* 1.4 with CVT support gives us real precision, yay */
  2233. if (edid->revision >= 4 && t[10] == 0x04)
  2234. return (t[9] * 10000) - ((t[12] >> 2) * 250);
  2235. /* 1.3 is pathetic, so fuzz up a bit */
  2236. return t[9] * 10000 + 5001;
  2237. }
  2238. static bool
  2239. mode_in_range(const struct drm_display_mode *mode, struct edid *edid,
  2240. struct detailed_timing *timing)
  2241. {
  2242. u32 max_clock;
  2243. u8 *t = (u8 *)timing;
  2244. if (!mode_in_hsync_range(mode, edid, t))
  2245. return false;
  2246. if (!mode_in_vsync_range(mode, edid, t))
  2247. return false;
  2248. if ((max_clock = range_pixel_clock(edid, t)))
  2249. if (mode->clock > max_clock)
  2250. return false;
  2251. /* 1.4 max horizontal check */
  2252. if (edid->revision >= 4 && t[10] == 0x04)
  2253. if (t[13] && mode->hdisplay > 8 * (t[13] + (256 * (t[12]&0x3))))
  2254. return false;
  2255. if (mode_is_rb(mode) && !drm_monitor_supports_rb(edid))
  2256. return false;
  2257. return true;
  2258. }
  2259. static bool valid_inferred_mode(const struct drm_connector *connector,
  2260. const struct drm_display_mode *mode)
  2261. {
  2262. const struct drm_display_mode *m;
  2263. bool ok = false;
  2264. list_for_each_entry(m, &connector->probed_modes, head) {
  2265. if (mode->hdisplay == m->hdisplay &&
  2266. mode->vdisplay == m->vdisplay &&
  2267. drm_mode_vrefresh(mode) == drm_mode_vrefresh(m))
  2268. return false; /* duplicated */
  2269. if (mode->hdisplay <= m->hdisplay &&
  2270. mode->vdisplay <= m->vdisplay)
  2271. ok = true;
  2272. }
  2273. return ok;
  2274. }
  2275. static int
  2276. drm_dmt_modes_for_range(struct drm_connector *connector, struct edid *edid,
  2277. struct detailed_timing *timing)
  2278. {
  2279. int i, modes = 0;
  2280. struct drm_display_mode *newmode;
  2281. struct drm_device *dev = connector->dev;
  2282. for (i = 0; i < ARRAY_SIZE(drm_dmt_modes); i++) {
  2283. if (mode_in_range(drm_dmt_modes + i, edid, timing) &&
  2284. valid_inferred_mode(connector, drm_dmt_modes + i)) {
  2285. newmode = drm_mode_duplicate(dev, &drm_dmt_modes[i]);
  2286. if (newmode) {
  2287. drm_mode_probed_add(connector, newmode);
  2288. modes++;
  2289. }
  2290. }
  2291. }
  2292. return modes;
  2293. }
  2294. /* fix up 1366x768 mode from 1368x768;
  2295. * GFT/CVT can't express 1366 width which isn't dividable by 8
  2296. */
  2297. void drm_mode_fixup_1366x768(struct drm_display_mode *mode)
  2298. {
  2299. if (mode->hdisplay == 1368 && mode->vdisplay == 768) {
  2300. mode->hdisplay = 1366;
  2301. mode->hsync_start--;
  2302. mode->hsync_end--;
  2303. drm_mode_set_name(mode);
  2304. }
  2305. }
  2306. static int
  2307. drm_gtf_modes_for_range(struct drm_connector *connector, struct edid *edid,
  2308. struct detailed_timing *timing)
  2309. {
  2310. int i, modes = 0;
  2311. struct drm_display_mode *newmode;
  2312. struct drm_device *dev = connector->dev;
  2313. for (i = 0; i < ARRAY_SIZE(extra_modes); i++) {
  2314. const struct minimode *m = &extra_modes[i];
  2315. newmode = drm_gtf_mode(dev, m->w, m->h, m->r, 0, 0);
  2316. if (!newmode)
  2317. return modes;
  2318. drm_mode_fixup_1366x768(newmode);
  2319. if (!mode_in_range(newmode, edid, timing) ||
  2320. !valid_inferred_mode(connector, newmode)) {
  2321. drm_mode_destroy(dev, newmode);
  2322. continue;
  2323. }
  2324. drm_mode_probed_add(connector, newmode);
  2325. modes++;
  2326. }
  2327. return modes;
  2328. }
  2329. static int
  2330. drm_cvt_modes_for_range(struct drm_connector *connector, struct edid *edid,
  2331. struct detailed_timing *timing)
  2332. {
  2333. int i, modes = 0;
  2334. struct drm_display_mode *newmode;
  2335. struct drm_device *dev = connector->dev;
  2336. bool rb = drm_monitor_supports_rb(edid);
  2337. for (i = 0; i < ARRAY_SIZE(extra_modes); i++) {
  2338. const struct minimode *m = &extra_modes[i];
  2339. newmode = drm_cvt_mode(dev, m->w, m->h, m->r, rb, 0, 0);
  2340. if (!newmode)
  2341. return modes;
  2342. drm_mode_fixup_1366x768(newmode);
  2343. if (!mode_in_range(newmode, edid, timing) ||
  2344. !valid_inferred_mode(connector, newmode)) {
  2345. drm_mode_destroy(dev, newmode);
  2346. continue;
  2347. }
  2348. drm_mode_probed_add(connector, newmode);
  2349. modes++;
  2350. }
  2351. return modes;
  2352. }
  2353. static void
  2354. do_inferred_modes(struct detailed_timing *timing, void *c)
  2355. {
  2356. struct detailed_mode_closure *closure = c;
  2357. struct detailed_non_pixel *data = &timing->data.other_data;
  2358. struct detailed_data_monitor_range *range = &data->data.range;
  2359. if (data->type != EDID_DETAIL_MONITOR_RANGE)
  2360. return;
  2361. closure->modes += drm_dmt_modes_for_range(closure->connector,
  2362. closure->edid,
  2363. timing);
  2364. if (!version_greater(closure->edid, 1, 1))
  2365. return; /* GTF not defined yet */
  2366. switch (range->flags) {
  2367. case 0x02: /* secondary gtf, XXX could do more */
  2368. case 0x00: /* default gtf */
  2369. closure->modes += drm_gtf_modes_for_range(closure->connector,
  2370. closure->edid,
  2371. timing);
  2372. break;
  2373. case 0x04: /* cvt, only in 1.4+ */
  2374. if (!version_greater(closure->edid, 1, 3))
  2375. break;
  2376. closure->modes += drm_cvt_modes_for_range(closure->connector,
  2377. closure->edid,
  2378. timing);
  2379. break;
  2380. case 0x01: /* just the ranges, no formula */
  2381. default:
  2382. break;
  2383. }
  2384. }
  2385. static int
  2386. add_inferred_modes(struct drm_connector *connector, struct edid *edid)
  2387. {
  2388. struct detailed_mode_closure closure = {
  2389. .connector = connector,
  2390. .edid = edid,
  2391. };
  2392. if (version_greater(edid, 1, 0))
  2393. drm_for_each_detailed_block((u8 *)edid, do_inferred_modes,
  2394. &closure);
  2395. return closure.modes;
  2396. }
  2397. static int
  2398. drm_est3_modes(struct drm_connector *connector, struct detailed_timing *timing)
  2399. {
  2400. int i, j, m, modes = 0;
  2401. struct drm_display_mode *mode;
  2402. u8 *est = ((u8 *)timing) + 6;
  2403. for (i = 0; i < 6; i++) {
  2404. for (j = 7; j >= 0; j--) {
  2405. m = (i * 8) + (7 - j);
  2406. if (m >= ARRAY_SIZE(est3_modes))
  2407. break;
  2408. if (est[i] & (1 << j)) {
  2409. mode = drm_mode_find_dmt(connector->dev,
  2410. est3_modes[m].w,
  2411. est3_modes[m].h,
  2412. est3_modes[m].r,
  2413. est3_modes[m].rb);
  2414. if (mode) {
  2415. drm_mode_probed_add(connector, mode);
  2416. modes++;
  2417. }
  2418. }
  2419. }
  2420. }
  2421. return modes;
  2422. }
  2423. static void
  2424. do_established_modes(struct detailed_timing *timing, void *c)
  2425. {
  2426. struct detailed_mode_closure *closure = c;
  2427. struct detailed_non_pixel *data = &timing->data.other_data;
  2428. if (data->type == EDID_DETAIL_EST_TIMINGS)
  2429. closure->modes += drm_est3_modes(closure->connector, timing);
  2430. }
  2431. /**
  2432. * add_established_modes - get est. modes from EDID and add them
  2433. * @connector: connector to add mode(s) to
  2434. * @edid: EDID block to scan
  2435. *
  2436. * Each EDID block contains a bitmap of the supported "established modes" list
  2437. * (defined above). Tease them out and add them to the global modes list.
  2438. */
  2439. static int
  2440. add_established_modes(struct drm_connector *connector, struct edid *edid)
  2441. {
  2442. struct drm_device *dev = connector->dev;
  2443. unsigned long est_bits = edid->established_timings.t1 |
  2444. (edid->established_timings.t2 << 8) |
  2445. ((edid->established_timings.mfg_rsvd & 0x80) << 9);
  2446. int i, modes = 0;
  2447. struct detailed_mode_closure closure = {
  2448. .connector = connector,
  2449. .edid = edid,
  2450. };
  2451. for (i = 0; i <= EDID_EST_TIMINGS; i++) {
  2452. if (est_bits & (1<<i)) {
  2453. struct drm_display_mode *newmode;
  2454. newmode = drm_mode_duplicate(dev, &edid_est_modes[i]);
  2455. if (newmode) {
  2456. drm_mode_probed_add(connector, newmode);
  2457. modes++;
  2458. }
  2459. }
  2460. }
  2461. if (version_greater(edid, 1, 0))
  2462. drm_for_each_detailed_block((u8 *)edid,
  2463. do_established_modes, &closure);
  2464. return modes + closure.modes;
  2465. }
  2466. static void
  2467. do_standard_modes(struct detailed_timing *timing, void *c)
  2468. {
  2469. struct detailed_mode_closure *closure = c;
  2470. struct detailed_non_pixel *data = &timing->data.other_data;
  2471. struct drm_connector *connector = closure->connector;
  2472. struct edid *edid = closure->edid;
  2473. if (data->type == EDID_DETAIL_STD_MODES) {
  2474. int i;
  2475. for (i = 0; i < 6; i++) {
  2476. struct std_timing *std;
  2477. struct drm_display_mode *newmode;
  2478. std = &data->data.timings[i];
  2479. newmode = drm_mode_std(connector, edid, std);
  2480. if (newmode) {
  2481. drm_mode_probed_add(connector, newmode);
  2482. closure->modes++;
  2483. }
  2484. }
  2485. }
  2486. }
  2487. /**
  2488. * add_standard_modes - get std. modes from EDID and add them
  2489. * @connector: connector to add mode(s) to
  2490. * @edid: EDID block to scan
  2491. *
  2492. * Standard modes can be calculated using the appropriate standard (DMT,
  2493. * GTF or CVT. Grab them from @edid and add them to the list.
  2494. */
  2495. static int
  2496. add_standard_modes(struct drm_connector *connector, struct edid *edid)
  2497. {
  2498. int i, modes = 0;
  2499. struct detailed_mode_closure closure = {
  2500. .connector = connector,
  2501. .edid = edid,
  2502. };
  2503. for (i = 0; i < EDID_STD_TIMINGS; i++) {
  2504. struct drm_display_mode *newmode;
  2505. newmode = drm_mode_std(connector, edid,
  2506. &edid->standard_timings[i]);
  2507. if (newmode) {
  2508. drm_mode_probed_add(connector, newmode);
  2509. modes++;
  2510. }
  2511. }
  2512. if (version_greater(edid, 1, 0))
  2513. drm_for_each_detailed_block((u8 *)edid, do_standard_modes,
  2514. &closure);
  2515. /* XXX should also look for standard codes in VTB blocks */
  2516. return modes + closure.modes;
  2517. }
  2518. static int drm_cvt_modes(struct drm_connector *connector,
  2519. struct detailed_timing *timing)
  2520. {
  2521. int i, j, modes = 0;
  2522. struct drm_display_mode *newmode;
  2523. struct drm_device *dev = connector->dev;
  2524. struct cvt_timing *cvt;
  2525. const int rates[] = { 60, 85, 75, 60, 50 };
  2526. const u8 empty[3] = { 0, 0, 0 };
  2527. for (i = 0; i < 4; i++) {
  2528. int uninitialized_var(width), height;
  2529. cvt = &(timing->data.other_data.data.cvt[i]);
  2530. if (!memcmp(cvt->code, empty, 3))
  2531. continue;
  2532. height = (cvt->code[0] + ((cvt->code[1] & 0xf0) << 4) + 1) * 2;
  2533. switch (cvt->code[1] & 0x0c) {
  2534. case 0x00:
  2535. width = height * 4 / 3;
  2536. break;
  2537. case 0x04:
  2538. width = height * 16 / 9;
  2539. break;
  2540. case 0x08:
  2541. width = height * 16 / 10;
  2542. break;
  2543. case 0x0c:
  2544. width = height * 15 / 9;
  2545. break;
  2546. }
  2547. for (j = 1; j < 5; j++) {
  2548. if (cvt->code[2] & (1 << j)) {
  2549. newmode = drm_cvt_mode(dev, width, height,
  2550. rates[j], j == 0,
  2551. false, false);
  2552. if (newmode) {
  2553. drm_mode_probed_add(connector, newmode);
  2554. modes++;
  2555. }
  2556. }
  2557. }
  2558. }
  2559. return modes;
  2560. }
  2561. static void
  2562. do_cvt_mode(struct detailed_timing *timing, void *c)
  2563. {
  2564. struct detailed_mode_closure *closure = c;
  2565. struct detailed_non_pixel *data = &timing->data.other_data;
  2566. if (data->type == EDID_DETAIL_CVT_3BYTE)
  2567. closure->modes += drm_cvt_modes(closure->connector, timing);
  2568. }
  2569. static int
  2570. add_cvt_modes(struct drm_connector *connector, struct edid *edid)
  2571. {
  2572. struct detailed_mode_closure closure = {
  2573. .connector = connector,
  2574. .edid = edid,
  2575. };
  2576. if (version_greater(edid, 1, 2))
  2577. drm_for_each_detailed_block((u8 *)edid, do_cvt_mode, &closure);
  2578. /* XXX should also look for CVT codes in VTB blocks */
  2579. return closure.modes;
  2580. }
  2581. static void fixup_detailed_cea_mode_clock(struct drm_display_mode *mode);
  2582. static void
  2583. do_detailed_mode(struct detailed_timing *timing, void *c)
  2584. {
  2585. struct detailed_mode_closure *closure = c;
  2586. struct drm_display_mode *newmode;
  2587. if (timing->pixel_clock) {
  2588. newmode = drm_mode_detailed(closure->connector->dev,
  2589. closure->edid, timing,
  2590. closure->quirks);
  2591. if (!newmode)
  2592. return;
  2593. if (closure->preferred)
  2594. newmode->type |= DRM_MODE_TYPE_PREFERRED;
  2595. /*
  2596. * Detailed modes are limited to 10kHz pixel clock resolution,
  2597. * so fix up anything that looks like CEA/HDMI mode, but the clock
  2598. * is just slightly off.
  2599. */
  2600. fixup_detailed_cea_mode_clock(newmode);
  2601. drm_mode_probed_add(closure->connector, newmode);
  2602. closure->modes++;
  2603. closure->preferred = false;
  2604. }
  2605. }
  2606. /*
  2607. * add_detailed_modes - Add modes from detailed timings
  2608. * @connector: attached connector
  2609. * @edid: EDID block to scan
  2610. * @quirks: quirks to apply
  2611. */
  2612. static int
  2613. add_detailed_modes(struct drm_connector *connector, struct edid *edid,
  2614. u32 quirks)
  2615. {
  2616. struct detailed_mode_closure closure = {
  2617. .connector = connector,
  2618. .edid = edid,
  2619. .preferred = true,
  2620. .quirks = quirks,
  2621. };
  2622. if (closure.preferred && !version_greater(edid, 1, 3))
  2623. closure.preferred =
  2624. (edid->features & DRM_EDID_FEATURE_PREFERRED_TIMING);
  2625. drm_for_each_detailed_block((u8 *)edid, do_detailed_mode, &closure);
  2626. return closure.modes;
  2627. }
  2628. #define AUDIO_BLOCK 0x01
  2629. #define VIDEO_BLOCK 0x02
  2630. #define VENDOR_BLOCK 0x03
  2631. #define SPEAKER_BLOCK 0x04
  2632. #define USE_EXTENDED_TAG 0x07
  2633. #define EXT_VIDEO_CAPABILITY_BLOCK 0x00
  2634. #define EXT_VIDEO_DATA_BLOCK_420 0x0E
  2635. #define EXT_VIDEO_CAP_BLOCK_Y420CMDB 0x0F
  2636. #define EDID_BASIC_AUDIO (1 << 6)
  2637. #define EDID_CEA_YCRCB444 (1 << 5)
  2638. #define EDID_CEA_YCRCB422 (1 << 4)
  2639. #define EDID_CEA_VCDB_QS (1 << 6)
  2640. /*
  2641. * Search EDID for CEA extension block.
  2642. */
  2643. static u8 *drm_find_edid_extension(const struct edid *edid, int ext_id)
  2644. {
  2645. u8 *edid_ext = NULL;
  2646. int i;
  2647. /* No EDID or EDID extensions */
  2648. if (edid == NULL || edid->extensions == 0)
  2649. return NULL;
  2650. /* Find CEA extension */
  2651. for (i = 0; i < edid->extensions; i++) {
  2652. edid_ext = (u8 *)edid + EDID_LENGTH * (i + 1);
  2653. if (edid_ext[0] == ext_id)
  2654. break;
  2655. }
  2656. if (i == edid->extensions)
  2657. return NULL;
  2658. return edid_ext;
  2659. }
  2660. static u8 *drm_find_displayid_extension(const struct edid *edid)
  2661. {
  2662. return drm_find_edid_extension(edid, DISPLAYID_EXT);
  2663. }
  2664. static u8 *drm_find_cea_extension(const struct edid *edid)
  2665. {
  2666. int ret;
  2667. int idx = 1;
  2668. int length = EDID_LENGTH;
  2669. struct displayid_block *block;
  2670. u8 *cea;
  2671. u8 *displayid;
  2672. /* Look for a top level CEA extension block */
  2673. cea = drm_find_edid_extension(edid, CEA_EXT);
  2674. if (cea)
  2675. return cea;
  2676. /* CEA blocks can also be found embedded in a DisplayID block */
  2677. displayid = drm_find_displayid_extension(edid);
  2678. if (!displayid)
  2679. return NULL;
  2680. ret = validate_displayid(displayid, length, idx);
  2681. if (ret)
  2682. return NULL;
  2683. idx += sizeof(struct displayid_hdr);
  2684. for_each_displayid_db(displayid, block, idx, length) {
  2685. if (block->tag == DATA_BLOCK_CTA) {
  2686. cea = (u8 *)block;
  2687. break;
  2688. }
  2689. }
  2690. return cea;
  2691. }
  2692. /*
  2693. * Calculate the alternate clock for the CEA mode
  2694. * (60Hz vs. 59.94Hz etc.)
  2695. */
  2696. static unsigned int
  2697. cea_mode_alternate_clock(const struct drm_display_mode *cea_mode)
  2698. {
  2699. unsigned int clock = cea_mode->clock;
  2700. if (cea_mode->vrefresh % 6 != 0)
  2701. return clock;
  2702. /*
  2703. * edid_cea_modes contains the 59.94Hz
  2704. * variant for 240 and 480 line modes,
  2705. * and the 60Hz variant otherwise.
  2706. */
  2707. if (cea_mode->vdisplay == 240 || cea_mode->vdisplay == 480)
  2708. clock = DIV_ROUND_CLOSEST(clock * 1001, 1000);
  2709. else
  2710. clock = DIV_ROUND_CLOSEST(clock * 1000, 1001);
  2711. return clock;
  2712. }
  2713. static bool
  2714. cea_mode_alternate_timings(u8 vic, struct drm_display_mode *mode)
  2715. {
  2716. /*
  2717. * For certain VICs the spec allows the vertical
  2718. * front porch to vary by one or two lines.
  2719. *
  2720. * cea_modes[] stores the variant with the shortest
  2721. * vertical front porch. We can adjust the mode to
  2722. * get the other variants by simply increasing the
  2723. * vertical front porch length.
  2724. */
  2725. BUILD_BUG_ON(edid_cea_modes[8].vtotal != 262 ||
  2726. edid_cea_modes[9].vtotal != 262 ||
  2727. edid_cea_modes[12].vtotal != 262 ||
  2728. edid_cea_modes[13].vtotal != 262 ||
  2729. edid_cea_modes[23].vtotal != 312 ||
  2730. edid_cea_modes[24].vtotal != 312 ||
  2731. edid_cea_modes[27].vtotal != 312 ||
  2732. edid_cea_modes[28].vtotal != 312);
  2733. if (((vic == 8 || vic == 9 ||
  2734. vic == 12 || vic == 13) && mode->vtotal < 263) ||
  2735. ((vic == 23 || vic == 24 ||
  2736. vic == 27 || vic == 28) && mode->vtotal < 314)) {
  2737. mode->vsync_start++;
  2738. mode->vsync_end++;
  2739. mode->vtotal++;
  2740. return true;
  2741. }
  2742. return false;
  2743. }
  2744. static u8 drm_match_cea_mode_clock_tolerance(const struct drm_display_mode *to_match,
  2745. unsigned int clock_tolerance)
  2746. {
  2747. unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
  2748. u8 vic;
  2749. if (!to_match->clock)
  2750. return 0;
  2751. if (to_match->picture_aspect_ratio)
  2752. match_flags |= DRM_MODE_MATCH_ASPECT_RATIO;
  2753. for (vic = 1; vic < ARRAY_SIZE(edid_cea_modes); vic++) {
  2754. struct drm_display_mode cea_mode = edid_cea_modes[vic];
  2755. unsigned int clock1, clock2;
  2756. /* Check both 60Hz and 59.94Hz */
  2757. clock1 = cea_mode.clock;
  2758. clock2 = cea_mode_alternate_clock(&cea_mode);
  2759. if (abs(to_match->clock - clock1) > clock_tolerance &&
  2760. abs(to_match->clock - clock2) > clock_tolerance)
  2761. continue;
  2762. do {
  2763. if (drm_mode_match(to_match, &cea_mode, match_flags))
  2764. return vic;
  2765. } while (cea_mode_alternate_timings(vic, &cea_mode));
  2766. }
  2767. return 0;
  2768. }
  2769. /**
  2770. * drm_match_cea_mode - look for a CEA mode matching given mode
  2771. * @to_match: display mode
  2772. *
  2773. * Return: The CEA Video ID (VIC) of the mode or 0 if it isn't a CEA-861
  2774. * mode.
  2775. */
  2776. u8 drm_match_cea_mode(const struct drm_display_mode *to_match)
  2777. {
  2778. unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
  2779. u8 vic;
  2780. if (!to_match->clock)
  2781. return 0;
  2782. if (to_match->picture_aspect_ratio)
  2783. match_flags |= DRM_MODE_MATCH_ASPECT_RATIO;
  2784. for (vic = 1; vic < ARRAY_SIZE(edid_cea_modes); vic++) {
  2785. struct drm_display_mode cea_mode = edid_cea_modes[vic];
  2786. unsigned int clock1, clock2;
  2787. /* Check both 60Hz and 59.94Hz */
  2788. clock1 = cea_mode.clock;
  2789. clock2 = cea_mode_alternate_clock(&cea_mode);
  2790. if (KHZ2PICOS(to_match->clock) != KHZ2PICOS(clock1) &&
  2791. KHZ2PICOS(to_match->clock) != KHZ2PICOS(clock2))
  2792. continue;
  2793. do {
  2794. if (drm_mode_match(to_match, &cea_mode, match_flags))
  2795. return vic;
  2796. } while (cea_mode_alternate_timings(vic, &cea_mode));
  2797. }
  2798. return 0;
  2799. }
  2800. EXPORT_SYMBOL(drm_match_cea_mode);
  2801. static bool drm_valid_cea_vic(u8 vic)
  2802. {
  2803. return vic > 0 && vic < ARRAY_SIZE(edid_cea_modes);
  2804. }
  2805. /**
  2806. * drm_get_cea_aspect_ratio - get the picture aspect ratio corresponding to
  2807. * the input VIC from the CEA mode list
  2808. * @video_code: ID given to each of the CEA modes
  2809. *
  2810. * Returns picture aspect ratio
  2811. */
  2812. enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code)
  2813. {
  2814. return edid_cea_modes[video_code].picture_aspect_ratio;
  2815. }
  2816. EXPORT_SYMBOL(drm_get_cea_aspect_ratio);
  2817. /*
  2818. * Calculate the alternate clock for HDMI modes (those from the HDMI vendor
  2819. * specific block).
  2820. *
  2821. * It's almost like cea_mode_alternate_clock(), we just need to add an
  2822. * exception for the VIC 4 mode (4096x2160@24Hz): no alternate clock for this
  2823. * one.
  2824. */
  2825. static unsigned int
  2826. hdmi_mode_alternate_clock(const struct drm_display_mode *hdmi_mode)
  2827. {
  2828. if (hdmi_mode->vdisplay == 4096 && hdmi_mode->hdisplay == 2160)
  2829. return hdmi_mode->clock;
  2830. return cea_mode_alternate_clock(hdmi_mode);
  2831. }
  2832. static u8 drm_match_hdmi_mode_clock_tolerance(const struct drm_display_mode *to_match,
  2833. unsigned int clock_tolerance)
  2834. {
  2835. unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
  2836. u8 vic;
  2837. if (!to_match->clock)
  2838. return 0;
  2839. for (vic = 1; vic < ARRAY_SIZE(edid_4k_modes); vic++) {
  2840. const struct drm_display_mode *hdmi_mode = &edid_4k_modes[vic];
  2841. unsigned int clock1, clock2;
  2842. /* Make sure to also match alternate clocks */
  2843. clock1 = hdmi_mode->clock;
  2844. clock2 = hdmi_mode_alternate_clock(hdmi_mode);
  2845. if (abs(to_match->clock - clock1) > clock_tolerance &&
  2846. abs(to_match->clock - clock2) > clock_tolerance)
  2847. continue;
  2848. if (drm_mode_match(to_match, hdmi_mode, match_flags))
  2849. return vic;
  2850. }
  2851. return 0;
  2852. }
  2853. /*
  2854. * drm_match_hdmi_mode - look for a HDMI mode matching given mode
  2855. * @to_match: display mode
  2856. *
  2857. * An HDMI mode is one defined in the HDMI vendor specific block.
  2858. *
  2859. * Returns the HDMI Video ID (VIC) of the mode or 0 if it isn't one.
  2860. */
  2861. static u8 drm_match_hdmi_mode(const struct drm_display_mode *to_match)
  2862. {
  2863. unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
  2864. u8 vic;
  2865. if (!to_match->clock)
  2866. return 0;
  2867. for (vic = 1; vic < ARRAY_SIZE(edid_4k_modes); vic++) {
  2868. const struct drm_display_mode *hdmi_mode = &edid_4k_modes[vic];
  2869. unsigned int clock1, clock2;
  2870. /* Make sure to also match alternate clocks */
  2871. clock1 = hdmi_mode->clock;
  2872. clock2 = hdmi_mode_alternate_clock(hdmi_mode);
  2873. if ((KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock1) ||
  2874. KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock2)) &&
  2875. drm_mode_match(to_match, hdmi_mode, match_flags))
  2876. return vic;
  2877. }
  2878. return 0;
  2879. }
  2880. static bool drm_valid_hdmi_vic(u8 vic)
  2881. {
  2882. return vic > 0 && vic < ARRAY_SIZE(edid_4k_modes);
  2883. }
  2884. static int
  2885. add_alternate_cea_modes(struct drm_connector *connector, struct edid *edid)
  2886. {
  2887. struct drm_device *dev = connector->dev;
  2888. struct drm_display_mode *mode, *tmp;
  2889. LIST_HEAD(list);
  2890. int modes = 0;
  2891. /* Don't add CEA modes if the CEA extension block is missing */
  2892. if (!drm_find_cea_extension(edid))
  2893. return 0;
  2894. /*
  2895. * Go through all probed modes and create a new mode
  2896. * with the alternate clock for certain CEA modes.
  2897. */
  2898. list_for_each_entry(mode, &connector->probed_modes, head) {
  2899. const struct drm_display_mode *cea_mode = NULL;
  2900. struct drm_display_mode *newmode;
  2901. u8 vic = drm_match_cea_mode(mode);
  2902. unsigned int clock1, clock2;
  2903. if (drm_valid_cea_vic(vic)) {
  2904. cea_mode = &edid_cea_modes[vic];
  2905. clock2 = cea_mode_alternate_clock(cea_mode);
  2906. } else {
  2907. vic = drm_match_hdmi_mode(mode);
  2908. if (drm_valid_hdmi_vic(vic)) {
  2909. cea_mode = &edid_4k_modes[vic];
  2910. clock2 = hdmi_mode_alternate_clock(cea_mode);
  2911. }
  2912. }
  2913. if (!cea_mode)
  2914. continue;
  2915. clock1 = cea_mode->clock;
  2916. if (clock1 == clock2)
  2917. continue;
  2918. if (mode->clock != clock1 && mode->clock != clock2)
  2919. continue;
  2920. newmode = drm_mode_duplicate(dev, cea_mode);
  2921. if (!newmode)
  2922. continue;
  2923. /* Carry over the stereo flags */
  2924. newmode->flags |= mode->flags & DRM_MODE_FLAG_3D_MASK;
  2925. /*
  2926. * The current mode could be either variant. Make
  2927. * sure to pick the "other" clock for the new mode.
  2928. */
  2929. if (mode->clock != clock1)
  2930. newmode->clock = clock1;
  2931. else
  2932. newmode->clock = clock2;
  2933. list_add_tail(&newmode->head, &list);
  2934. }
  2935. list_for_each_entry_safe(mode, tmp, &list, head) {
  2936. list_del(&mode->head);
  2937. drm_mode_probed_add(connector, mode);
  2938. modes++;
  2939. }
  2940. return modes;
  2941. }
  2942. static u8 svd_to_vic(u8 svd)
  2943. {
  2944. /* 0-6 bit vic, 7th bit native mode indicator */
  2945. if ((svd >= 1 && svd <= 64) || (svd >= 129 && svd <= 192))
  2946. return svd & 127;
  2947. return svd;
  2948. }
  2949. static struct drm_display_mode *
  2950. drm_display_mode_from_vic_index(struct drm_connector *connector,
  2951. const u8 *video_db, u8 video_len,
  2952. u8 video_index)
  2953. {
  2954. struct drm_device *dev = connector->dev;
  2955. struct drm_display_mode *newmode;
  2956. u8 vic;
  2957. if (video_db == NULL || video_index >= video_len)
  2958. return NULL;
  2959. /* CEA modes are numbered 1..127 */
  2960. vic = svd_to_vic(video_db[video_index]);
  2961. if (!drm_valid_cea_vic(vic))
  2962. return NULL;
  2963. newmode = drm_mode_duplicate(dev, &edid_cea_modes[vic]);
  2964. if (!newmode)
  2965. return NULL;
  2966. newmode->vrefresh = 0;
  2967. return newmode;
  2968. }
  2969. /*
  2970. * do_y420vdb_modes - Parse YCBCR 420 only modes
  2971. * @connector: connector corresponding to the HDMI sink
  2972. * @svds: start of the data block of CEA YCBCR 420 VDB
  2973. * @len: length of the CEA YCBCR 420 VDB
  2974. *
  2975. * Parse the CEA-861-F YCBCR 420 Video Data Block (Y420VDB)
  2976. * which contains modes which can be supported in YCBCR 420
  2977. * output format only.
  2978. */
  2979. static int do_y420vdb_modes(struct drm_connector *connector,
  2980. const u8 *svds, u8 svds_len)
  2981. {
  2982. int modes = 0, i;
  2983. struct drm_device *dev = connector->dev;
  2984. struct drm_display_info *info = &connector->display_info;
  2985. struct drm_hdmi_info *hdmi = &info->hdmi;
  2986. for (i = 0; i < svds_len; i++) {
  2987. u8 vic = svd_to_vic(svds[i]);
  2988. struct drm_display_mode *newmode;
  2989. if (!drm_valid_cea_vic(vic))
  2990. continue;
  2991. newmode = drm_mode_duplicate(dev, &edid_cea_modes[vic]);
  2992. if (!newmode)
  2993. break;
  2994. bitmap_set(hdmi->y420_vdb_modes, vic, 1);
  2995. drm_mode_probed_add(connector, newmode);
  2996. modes++;
  2997. }
  2998. if (modes > 0)
  2999. info->color_formats |= DRM_COLOR_FORMAT_YCRCB420;
  3000. return modes;
  3001. }
  3002. /*
  3003. * drm_add_cmdb_modes - Add a YCBCR 420 mode into bitmap
  3004. * @connector: connector corresponding to the HDMI sink
  3005. * @vic: CEA vic for the video mode to be added in the map
  3006. *
  3007. * Makes an entry for a videomode in the YCBCR 420 bitmap
  3008. */
  3009. static void
  3010. drm_add_cmdb_modes(struct drm_connector *connector, u8 svd)
  3011. {
  3012. u8 vic = svd_to_vic(svd);
  3013. struct drm_hdmi_info *hdmi = &connector->display_info.hdmi;
  3014. if (!drm_valid_cea_vic(vic))
  3015. return;
  3016. bitmap_set(hdmi->y420_cmdb_modes, vic, 1);
  3017. }
  3018. static int
  3019. do_cea_modes(struct drm_connector *connector, const u8 *db, u8 len)
  3020. {
  3021. int i, modes = 0;
  3022. struct drm_hdmi_info *hdmi = &connector->display_info.hdmi;
  3023. for (i = 0; i < len; i++) {
  3024. struct drm_display_mode *mode;
  3025. mode = drm_display_mode_from_vic_index(connector, db, len, i);
  3026. if (mode) {
  3027. /*
  3028. * YCBCR420 capability block contains a bitmap which
  3029. * gives the index of CEA modes from CEA VDB, which
  3030. * can support YCBCR 420 sampling output also (apart
  3031. * from RGB/YCBCR444 etc).
  3032. * For example, if the bit 0 in bitmap is set,
  3033. * first mode in VDB can support YCBCR420 output too.
  3034. * Add YCBCR420 modes only if sink is HDMI 2.0 capable.
  3035. */
  3036. if (i < 64 && hdmi->y420_cmdb_map & (1ULL << i))
  3037. drm_add_cmdb_modes(connector, db[i]);
  3038. drm_mode_probed_add(connector, mode);
  3039. modes++;
  3040. }
  3041. }
  3042. return modes;
  3043. }
  3044. struct stereo_mandatory_mode {
  3045. int width, height, vrefresh;
  3046. unsigned int flags;
  3047. };
  3048. static const struct stereo_mandatory_mode stereo_mandatory_modes[] = {
  3049. { 1920, 1080, 24, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
  3050. { 1920, 1080, 24, DRM_MODE_FLAG_3D_FRAME_PACKING },
  3051. { 1920, 1080, 50,
  3052. DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF },
  3053. { 1920, 1080, 60,
  3054. DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF },
  3055. { 1280, 720, 50, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
  3056. { 1280, 720, 50, DRM_MODE_FLAG_3D_FRAME_PACKING },
  3057. { 1280, 720, 60, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
  3058. { 1280, 720, 60, DRM_MODE_FLAG_3D_FRAME_PACKING }
  3059. };
  3060. static bool
  3061. stereo_match_mandatory(const struct drm_display_mode *mode,
  3062. const struct stereo_mandatory_mode *stereo_mode)
  3063. {
  3064. unsigned int interlaced = mode->flags & DRM_MODE_FLAG_INTERLACE;
  3065. return mode->hdisplay == stereo_mode->width &&
  3066. mode->vdisplay == stereo_mode->height &&
  3067. interlaced == (stereo_mode->flags & DRM_MODE_FLAG_INTERLACE) &&
  3068. drm_mode_vrefresh(mode) == stereo_mode->vrefresh;
  3069. }
  3070. static int add_hdmi_mandatory_stereo_modes(struct drm_connector *connector)
  3071. {
  3072. struct drm_device *dev = connector->dev;
  3073. const struct drm_display_mode *mode;
  3074. struct list_head stereo_modes;
  3075. int modes = 0, i;
  3076. INIT_LIST_HEAD(&stereo_modes);
  3077. list_for_each_entry(mode, &connector->probed_modes, head) {
  3078. for (i = 0; i < ARRAY_SIZE(stereo_mandatory_modes); i++) {
  3079. const struct stereo_mandatory_mode *mandatory;
  3080. struct drm_display_mode *new_mode;
  3081. if (!stereo_match_mandatory(mode,
  3082. &stereo_mandatory_modes[i]))
  3083. continue;
  3084. mandatory = &stereo_mandatory_modes[i];
  3085. new_mode = drm_mode_duplicate(dev, mode);
  3086. if (!new_mode)
  3087. continue;
  3088. new_mode->flags |= mandatory->flags;
  3089. list_add_tail(&new_mode->head, &stereo_modes);
  3090. modes++;
  3091. }
  3092. }
  3093. list_splice_tail(&stereo_modes, &connector->probed_modes);
  3094. return modes;
  3095. }
  3096. static int add_hdmi_mode(struct drm_connector *connector, u8 vic)
  3097. {
  3098. struct drm_device *dev = connector->dev;
  3099. struct drm_display_mode *newmode;
  3100. if (!drm_valid_hdmi_vic(vic)) {
  3101. DRM_ERROR("Unknown HDMI VIC: %d\n", vic);
  3102. return 0;
  3103. }
  3104. newmode = drm_mode_duplicate(dev, &edid_4k_modes[vic]);
  3105. if (!newmode)
  3106. return 0;
  3107. drm_mode_probed_add(connector, newmode);
  3108. return 1;
  3109. }
  3110. static int add_3d_struct_modes(struct drm_connector *connector, u16 structure,
  3111. const u8 *video_db, u8 video_len, u8 video_index)
  3112. {
  3113. struct drm_display_mode *newmode;
  3114. int modes = 0;
  3115. if (structure & (1 << 0)) {
  3116. newmode = drm_display_mode_from_vic_index(connector, video_db,
  3117. video_len,
  3118. video_index);
  3119. if (newmode) {
  3120. newmode->flags |= DRM_MODE_FLAG_3D_FRAME_PACKING;
  3121. drm_mode_probed_add(connector, newmode);
  3122. modes++;
  3123. }
  3124. }
  3125. if (structure & (1 << 6)) {
  3126. newmode = drm_display_mode_from_vic_index(connector, video_db,
  3127. video_len,
  3128. video_index);
  3129. if (newmode) {
  3130. newmode->flags |= DRM_MODE_FLAG_3D_TOP_AND_BOTTOM;
  3131. drm_mode_probed_add(connector, newmode);
  3132. modes++;
  3133. }
  3134. }
  3135. if (structure & (1 << 8)) {
  3136. newmode = drm_display_mode_from_vic_index(connector, video_db,
  3137. video_len,
  3138. video_index);
  3139. if (newmode) {
  3140. newmode->flags |= DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF;
  3141. drm_mode_probed_add(connector, newmode);
  3142. modes++;
  3143. }
  3144. }
  3145. return modes;
  3146. }
  3147. /*
  3148. * do_hdmi_vsdb_modes - Parse the HDMI Vendor Specific data block
  3149. * @connector: connector corresponding to the HDMI sink
  3150. * @db: start of the CEA vendor specific block
  3151. * @len: length of the CEA block payload, ie. one can access up to db[len]
  3152. *
  3153. * Parses the HDMI VSDB looking for modes to add to @connector. This function
  3154. * also adds the stereo 3d modes when applicable.
  3155. */
  3156. static int
  3157. do_hdmi_vsdb_modes(struct drm_connector *connector, const u8 *db, u8 len,
  3158. const u8 *video_db, u8 video_len)
  3159. {
  3160. struct drm_display_info *info = &connector->display_info;
  3161. int modes = 0, offset = 0, i, multi_present = 0, multi_len;
  3162. u8 vic_len, hdmi_3d_len = 0;
  3163. u16 mask;
  3164. u16 structure_all;
  3165. if (len < 8)
  3166. goto out;
  3167. /* no HDMI_Video_Present */
  3168. if (!(db[8] & (1 << 5)))
  3169. goto out;
  3170. /* Latency_Fields_Present */
  3171. if (db[8] & (1 << 7))
  3172. offset += 2;
  3173. /* I_Latency_Fields_Present */
  3174. if (db[8] & (1 << 6))
  3175. offset += 2;
  3176. /* the declared length is not long enough for the 2 first bytes
  3177. * of additional video format capabilities */
  3178. if (len < (8 + offset + 2))
  3179. goto out;
  3180. /* 3D_Present */
  3181. offset++;
  3182. if (db[8 + offset] & (1 << 7)) {
  3183. modes += add_hdmi_mandatory_stereo_modes(connector);
  3184. /* 3D_Multi_present */
  3185. multi_present = (db[8 + offset] & 0x60) >> 5;
  3186. }
  3187. offset++;
  3188. vic_len = db[8 + offset] >> 5;
  3189. hdmi_3d_len = db[8 + offset] & 0x1f;
  3190. for (i = 0; i < vic_len && len >= (9 + offset + i); i++) {
  3191. u8 vic;
  3192. vic = db[9 + offset + i];
  3193. modes += add_hdmi_mode(connector, vic);
  3194. }
  3195. offset += 1 + vic_len;
  3196. if (multi_present == 1)
  3197. multi_len = 2;
  3198. else if (multi_present == 2)
  3199. multi_len = 4;
  3200. else
  3201. multi_len = 0;
  3202. if (len < (8 + offset + hdmi_3d_len - 1))
  3203. goto out;
  3204. if (hdmi_3d_len < multi_len)
  3205. goto out;
  3206. if (multi_present == 1 || multi_present == 2) {
  3207. /* 3D_Structure_ALL */
  3208. structure_all = (db[8 + offset] << 8) | db[9 + offset];
  3209. /* check if 3D_MASK is present */
  3210. if (multi_present == 2)
  3211. mask = (db[10 + offset] << 8) | db[11 + offset];
  3212. else
  3213. mask = 0xffff;
  3214. for (i = 0; i < 16; i++) {
  3215. if (mask & (1 << i))
  3216. modes += add_3d_struct_modes(connector,
  3217. structure_all,
  3218. video_db,
  3219. video_len, i);
  3220. }
  3221. }
  3222. offset += multi_len;
  3223. for (i = 0; i < (hdmi_3d_len - multi_len); i++) {
  3224. int vic_index;
  3225. struct drm_display_mode *newmode = NULL;
  3226. unsigned int newflag = 0;
  3227. bool detail_present;
  3228. detail_present = ((db[8 + offset + i] & 0x0f) > 7);
  3229. if (detail_present && (i + 1 == hdmi_3d_len - multi_len))
  3230. break;
  3231. /* 2D_VIC_order_X */
  3232. vic_index = db[8 + offset + i] >> 4;
  3233. /* 3D_Structure_X */
  3234. switch (db[8 + offset + i] & 0x0f) {
  3235. case 0:
  3236. newflag = DRM_MODE_FLAG_3D_FRAME_PACKING;
  3237. break;
  3238. case 6:
  3239. newflag = DRM_MODE_FLAG_3D_TOP_AND_BOTTOM;
  3240. break;
  3241. case 8:
  3242. /* 3D_Detail_X */
  3243. if ((db[9 + offset + i] >> 4) == 1)
  3244. newflag = DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF;
  3245. break;
  3246. }
  3247. if (newflag != 0) {
  3248. newmode = drm_display_mode_from_vic_index(connector,
  3249. video_db,
  3250. video_len,
  3251. vic_index);
  3252. if (newmode) {
  3253. newmode->flags |= newflag;
  3254. drm_mode_probed_add(connector, newmode);
  3255. modes++;
  3256. }
  3257. }
  3258. if (detail_present)
  3259. i++;
  3260. }
  3261. out:
  3262. if (modes > 0)
  3263. info->has_hdmi_infoframe = true;
  3264. return modes;
  3265. }
  3266. static int
  3267. cea_db_payload_len(const u8 *db)
  3268. {
  3269. return db[0] & 0x1f;
  3270. }
  3271. static int
  3272. cea_db_extended_tag(const u8 *db)
  3273. {
  3274. return db[1];
  3275. }
  3276. static int
  3277. cea_db_tag(const u8 *db)
  3278. {
  3279. return db[0] >> 5;
  3280. }
  3281. static int
  3282. cea_revision(const u8 *cea)
  3283. {
  3284. return cea[1];
  3285. }
  3286. static int
  3287. cea_db_offsets(const u8 *cea, int *start, int *end)
  3288. {
  3289. /* DisplayID CTA extension blocks and top-level CEA EDID
  3290. * block header definitions differ in the following bytes:
  3291. * 1) Byte 2 of the header specifies length differently,
  3292. * 2) Byte 3 is only present in the CEA top level block.
  3293. *
  3294. * The different definitions for byte 2 follow.
  3295. *
  3296. * DisplayID CTA extension block defines byte 2 as:
  3297. * Number of payload bytes
  3298. *
  3299. * CEA EDID block defines byte 2 as:
  3300. * Byte number (decimal) within this block where the 18-byte
  3301. * DTDs begin. If no non-DTD data is present in this extension
  3302. * block, the value should be set to 04h (the byte after next).
  3303. * If set to 00h, there are no DTDs present in this block and
  3304. * no non-DTD data.
  3305. */
  3306. if (cea[0] == DATA_BLOCK_CTA) {
  3307. *start = 3;
  3308. *end = *start + cea[2];
  3309. } else if (cea[0] == CEA_EXT) {
  3310. /* Data block offset in CEA extension block */
  3311. *start = 4;
  3312. *end = cea[2];
  3313. if (*end == 0)
  3314. *end = 127;
  3315. if (*end < 4 || *end > 127)
  3316. return -ERANGE;
  3317. } else {
  3318. return -ENOTSUPP;
  3319. }
  3320. return 0;
  3321. }
  3322. static bool cea_db_is_hdmi_vsdb(const u8 *db)
  3323. {
  3324. int hdmi_id;
  3325. if (cea_db_tag(db) != VENDOR_BLOCK)
  3326. return false;
  3327. if (cea_db_payload_len(db) < 5)
  3328. return false;
  3329. hdmi_id = db[1] | (db[2] << 8) | (db[3] << 16);
  3330. return hdmi_id == HDMI_IEEE_OUI;
  3331. }
  3332. static bool cea_db_is_hdmi_forum_vsdb(const u8 *db)
  3333. {
  3334. unsigned int oui;
  3335. if (cea_db_tag(db) != VENDOR_BLOCK)
  3336. return false;
  3337. if (cea_db_payload_len(db) < 7)
  3338. return false;
  3339. oui = db[3] << 16 | db[2] << 8 | db[1];
  3340. return oui == HDMI_FORUM_IEEE_OUI;
  3341. }
  3342. static bool cea_db_is_y420cmdb(const u8 *db)
  3343. {
  3344. if (cea_db_tag(db) != USE_EXTENDED_TAG)
  3345. return false;
  3346. if (!cea_db_payload_len(db))
  3347. return false;
  3348. if (cea_db_extended_tag(db) != EXT_VIDEO_CAP_BLOCK_Y420CMDB)
  3349. return false;
  3350. return true;
  3351. }
  3352. static bool cea_db_is_y420vdb(const u8 *db)
  3353. {
  3354. if (cea_db_tag(db) != USE_EXTENDED_TAG)
  3355. return false;
  3356. if (!cea_db_payload_len(db))
  3357. return false;
  3358. if (cea_db_extended_tag(db) != EXT_VIDEO_DATA_BLOCK_420)
  3359. return false;
  3360. return true;
  3361. }
  3362. #define for_each_cea_db(cea, i, start, end) \
  3363. for ((i) = (start); (i) < (end) && (i) + cea_db_payload_len(&(cea)[(i)]) < (end); (i) += cea_db_payload_len(&(cea)[(i)]) + 1)
  3364. static void drm_parse_y420cmdb_bitmap(struct drm_connector *connector,
  3365. const u8 *db)
  3366. {
  3367. struct drm_display_info *info = &connector->display_info;
  3368. struct drm_hdmi_info *hdmi = &info->hdmi;
  3369. u8 map_len = cea_db_payload_len(db) - 1;
  3370. u8 count;
  3371. u64 map = 0;
  3372. if (map_len == 0) {
  3373. /* All CEA modes support ycbcr420 sampling also.*/
  3374. hdmi->y420_cmdb_map = U64_MAX;
  3375. info->color_formats |= DRM_COLOR_FORMAT_YCRCB420;
  3376. return;
  3377. }
  3378. /*
  3379. * This map indicates which of the existing CEA block modes
  3380. * from VDB can support YCBCR420 output too. So if bit=0 is
  3381. * set, first mode from VDB can support YCBCR420 output too.
  3382. * We will parse and keep this map, before parsing VDB itself
  3383. * to avoid going through the same block again and again.
  3384. *
  3385. * Spec is not clear about max possible size of this block.
  3386. * Clamping max bitmap block size at 8 bytes. Every byte can
  3387. * address 8 CEA modes, in this way this map can address
  3388. * 8*8 = first 64 SVDs.
  3389. */
  3390. if (WARN_ON_ONCE(map_len > 8))
  3391. map_len = 8;
  3392. for (count = 0; count < map_len; count++)
  3393. map |= (u64)db[2 + count] << (8 * count);
  3394. if (map)
  3395. info->color_formats |= DRM_COLOR_FORMAT_YCRCB420;
  3396. hdmi->y420_cmdb_map = map;
  3397. }
  3398. static int
  3399. add_cea_modes(struct drm_connector *connector, struct edid *edid)
  3400. {
  3401. const u8 *cea = drm_find_cea_extension(edid);
  3402. const u8 *db, *hdmi = NULL, *video = NULL;
  3403. u8 dbl, hdmi_len, video_len = 0;
  3404. int modes = 0;
  3405. if (cea && cea_revision(cea) >= 3) {
  3406. int i, start, end;
  3407. if (cea_db_offsets(cea, &start, &end))
  3408. return 0;
  3409. for_each_cea_db(cea, i, start, end) {
  3410. db = &cea[i];
  3411. dbl = cea_db_payload_len(db);
  3412. if (cea_db_tag(db) == VIDEO_BLOCK) {
  3413. video = db + 1;
  3414. video_len = dbl;
  3415. modes += do_cea_modes(connector, video, dbl);
  3416. } else if (cea_db_is_hdmi_vsdb(db)) {
  3417. hdmi = db;
  3418. hdmi_len = dbl;
  3419. } else if (cea_db_is_y420vdb(db)) {
  3420. const u8 *vdb420 = &db[2];
  3421. /* Add 4:2:0(only) modes present in EDID */
  3422. modes += do_y420vdb_modes(connector,
  3423. vdb420,
  3424. dbl - 1);
  3425. }
  3426. }
  3427. }
  3428. /*
  3429. * We parse the HDMI VSDB after having added the cea modes as we will
  3430. * be patching their flags when the sink supports stereo 3D.
  3431. */
  3432. if (hdmi)
  3433. modes += do_hdmi_vsdb_modes(connector, hdmi, hdmi_len, video,
  3434. video_len);
  3435. return modes;
  3436. }
  3437. static void fixup_detailed_cea_mode_clock(struct drm_display_mode *mode)
  3438. {
  3439. const struct drm_display_mode *cea_mode;
  3440. int clock1, clock2, clock;
  3441. u8 vic;
  3442. const char *type;
  3443. /*
  3444. * allow 5kHz clock difference either way to account for
  3445. * the 10kHz clock resolution limit of detailed timings.
  3446. */
  3447. vic = drm_match_cea_mode_clock_tolerance(mode, 5);
  3448. if (drm_valid_cea_vic(vic)) {
  3449. type = "CEA";
  3450. cea_mode = &edid_cea_modes[vic];
  3451. clock1 = cea_mode->clock;
  3452. clock2 = cea_mode_alternate_clock(cea_mode);
  3453. } else {
  3454. vic = drm_match_hdmi_mode_clock_tolerance(mode, 5);
  3455. if (drm_valid_hdmi_vic(vic)) {
  3456. type = "HDMI";
  3457. cea_mode = &edid_4k_modes[vic];
  3458. clock1 = cea_mode->clock;
  3459. clock2 = hdmi_mode_alternate_clock(cea_mode);
  3460. } else {
  3461. return;
  3462. }
  3463. }
  3464. /* pick whichever is closest */
  3465. if (abs(mode->clock - clock1) < abs(mode->clock - clock2))
  3466. clock = clock1;
  3467. else
  3468. clock = clock2;
  3469. if (mode->clock == clock)
  3470. return;
  3471. DRM_DEBUG("detailed mode matches %s VIC %d, adjusting clock %d -> %d\n",
  3472. type, vic, mode->clock, clock);
  3473. mode->clock = clock;
  3474. }
  3475. static void
  3476. drm_parse_hdmi_vsdb_audio(struct drm_connector *connector, const u8 *db)
  3477. {
  3478. u8 len = cea_db_payload_len(db);
  3479. if (len >= 6 && (db[6] & (1 << 7)))
  3480. connector->eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= DRM_ELD_SUPPORTS_AI;
  3481. if (len >= 8) {
  3482. connector->latency_present[0] = db[8] >> 7;
  3483. connector->latency_present[1] = (db[8] >> 6) & 1;
  3484. }
  3485. if (len >= 9)
  3486. connector->video_latency[0] = db[9];
  3487. if (len >= 10)
  3488. connector->audio_latency[0] = db[10];
  3489. if (len >= 11)
  3490. connector->video_latency[1] = db[11];
  3491. if (len >= 12)
  3492. connector->audio_latency[1] = db[12];
  3493. DRM_DEBUG_KMS("HDMI: latency present %d %d, "
  3494. "video latency %d %d, "
  3495. "audio latency %d %d\n",
  3496. connector->latency_present[0],
  3497. connector->latency_present[1],
  3498. connector->video_latency[0],
  3499. connector->video_latency[1],
  3500. connector->audio_latency[0],
  3501. connector->audio_latency[1]);
  3502. }
  3503. static void
  3504. monitor_name(struct detailed_timing *t, void *data)
  3505. {
  3506. if (t->data.other_data.type == EDID_DETAIL_MONITOR_NAME)
  3507. *(u8 **)data = t->data.other_data.data.str.str;
  3508. }
  3509. static int get_monitor_name(struct edid *edid, char name[13])
  3510. {
  3511. char *edid_name = NULL;
  3512. int mnl;
  3513. if (!edid || !name)
  3514. return 0;
  3515. drm_for_each_detailed_block((u8 *)edid, monitor_name, &edid_name);
  3516. for (mnl = 0; edid_name && mnl < 13; mnl++) {
  3517. if (edid_name[mnl] == 0x0a)
  3518. break;
  3519. name[mnl] = edid_name[mnl];
  3520. }
  3521. return mnl;
  3522. }
  3523. /**
  3524. * drm_edid_get_monitor_name - fetch the monitor name from the edid
  3525. * @edid: monitor EDID information
  3526. * @name: pointer to a character array to hold the name of the monitor
  3527. * @bufsize: The size of the name buffer (should be at least 14 chars.)
  3528. *
  3529. */
  3530. void drm_edid_get_monitor_name(struct edid *edid, char *name, int bufsize)
  3531. {
  3532. int name_length;
  3533. char buf[13];
  3534. if (bufsize <= 0)
  3535. return;
  3536. name_length = min(get_monitor_name(edid, buf), bufsize - 1);
  3537. memcpy(name, buf, name_length);
  3538. name[name_length] = '\0';
  3539. }
  3540. EXPORT_SYMBOL(drm_edid_get_monitor_name);
  3541. static void clear_eld(struct drm_connector *connector)
  3542. {
  3543. memset(connector->eld, 0, sizeof(connector->eld));
  3544. connector->latency_present[0] = false;
  3545. connector->latency_present[1] = false;
  3546. connector->video_latency[0] = 0;
  3547. connector->audio_latency[0] = 0;
  3548. connector->video_latency[1] = 0;
  3549. connector->audio_latency[1] = 0;
  3550. }
  3551. /*
  3552. * drm_edid_to_eld - build ELD from EDID
  3553. * @connector: connector corresponding to the HDMI/DP sink
  3554. * @edid: EDID to parse
  3555. *
  3556. * Fill the ELD (EDID-Like Data) buffer for passing to the audio driver. The
  3557. * HDCP and Port_ID ELD fields are left for the graphics driver to fill in.
  3558. */
  3559. static void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid)
  3560. {
  3561. uint8_t *eld = connector->eld;
  3562. u8 *cea;
  3563. u8 *db;
  3564. int total_sad_count = 0;
  3565. int mnl;
  3566. int dbl;
  3567. clear_eld(connector);
  3568. if (!edid)
  3569. return;
  3570. cea = drm_find_cea_extension(edid);
  3571. if (!cea) {
  3572. DRM_DEBUG_KMS("ELD: no CEA Extension found\n");
  3573. return;
  3574. }
  3575. mnl = get_monitor_name(edid, &eld[DRM_ELD_MONITOR_NAME_STRING]);
  3576. DRM_DEBUG_KMS("ELD monitor %s\n", &eld[DRM_ELD_MONITOR_NAME_STRING]);
  3577. eld[DRM_ELD_CEA_EDID_VER_MNL] = cea[1] << DRM_ELD_CEA_EDID_VER_SHIFT;
  3578. eld[DRM_ELD_CEA_EDID_VER_MNL] |= mnl;
  3579. eld[DRM_ELD_VER] = DRM_ELD_VER_CEA861D;
  3580. eld[DRM_ELD_MANUFACTURER_NAME0] = edid->mfg_id[0];
  3581. eld[DRM_ELD_MANUFACTURER_NAME1] = edid->mfg_id[1];
  3582. eld[DRM_ELD_PRODUCT_CODE0] = edid->prod_code[0];
  3583. eld[DRM_ELD_PRODUCT_CODE1] = edid->prod_code[1];
  3584. if (cea_revision(cea) >= 3) {
  3585. int i, start, end;
  3586. if (cea_db_offsets(cea, &start, &end)) {
  3587. start = 0;
  3588. end = 0;
  3589. }
  3590. for_each_cea_db(cea, i, start, end) {
  3591. db = &cea[i];
  3592. dbl = cea_db_payload_len(db);
  3593. switch (cea_db_tag(db)) {
  3594. int sad_count;
  3595. case AUDIO_BLOCK:
  3596. /* Audio Data Block, contains SADs */
  3597. sad_count = min(dbl / 3, 15 - total_sad_count);
  3598. if (sad_count >= 1)
  3599. memcpy(&eld[DRM_ELD_CEA_SAD(mnl, total_sad_count)],
  3600. &db[1], sad_count * 3);
  3601. total_sad_count += sad_count;
  3602. break;
  3603. case SPEAKER_BLOCK:
  3604. /* Speaker Allocation Data Block */
  3605. if (dbl >= 1)
  3606. eld[DRM_ELD_SPEAKER] = db[1];
  3607. break;
  3608. case VENDOR_BLOCK:
  3609. /* HDMI Vendor-Specific Data Block */
  3610. if (cea_db_is_hdmi_vsdb(db))
  3611. drm_parse_hdmi_vsdb_audio(connector, db);
  3612. break;
  3613. default:
  3614. break;
  3615. }
  3616. }
  3617. }
  3618. eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= total_sad_count << DRM_ELD_SAD_COUNT_SHIFT;
  3619. if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
  3620. connector->connector_type == DRM_MODE_CONNECTOR_eDP)
  3621. eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= DRM_ELD_CONN_TYPE_DP;
  3622. else
  3623. eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= DRM_ELD_CONN_TYPE_HDMI;
  3624. eld[DRM_ELD_BASELINE_ELD_LEN] =
  3625. DIV_ROUND_UP(drm_eld_calc_baseline_block_size(eld), 4);
  3626. DRM_DEBUG_KMS("ELD size %d, SAD count %d\n",
  3627. drm_eld_size(eld), total_sad_count);
  3628. }
  3629. /**
  3630. * drm_edid_to_sad - extracts SADs from EDID
  3631. * @edid: EDID to parse
  3632. * @sads: pointer that will be set to the extracted SADs
  3633. *
  3634. * Looks for CEA EDID block and extracts SADs (Short Audio Descriptors) from it.
  3635. *
  3636. * Note: The returned pointer needs to be freed using kfree().
  3637. *
  3638. * Return: The number of found SADs or negative number on error.
  3639. */
  3640. int drm_edid_to_sad(struct edid *edid, struct cea_sad **sads)
  3641. {
  3642. int count = 0;
  3643. int i, start, end, dbl;
  3644. u8 *cea;
  3645. cea = drm_find_cea_extension(edid);
  3646. if (!cea) {
  3647. DRM_DEBUG_KMS("SAD: no CEA Extension found\n");
  3648. return -ENOENT;
  3649. }
  3650. if (cea_revision(cea) < 3) {
  3651. DRM_DEBUG_KMS("SAD: wrong CEA revision\n");
  3652. return -ENOTSUPP;
  3653. }
  3654. if (cea_db_offsets(cea, &start, &end)) {
  3655. DRM_DEBUG_KMS("SAD: invalid data block offsets\n");
  3656. return -EPROTO;
  3657. }
  3658. for_each_cea_db(cea, i, start, end) {
  3659. u8 *db = &cea[i];
  3660. if (cea_db_tag(db) == AUDIO_BLOCK) {
  3661. int j;
  3662. dbl = cea_db_payload_len(db);
  3663. count = dbl / 3; /* SAD is 3B */
  3664. *sads = kcalloc(count, sizeof(**sads), GFP_KERNEL);
  3665. if (!*sads)
  3666. return -ENOMEM;
  3667. for (j = 0; j < count; j++) {
  3668. u8 *sad = &db[1 + j * 3];
  3669. (*sads)[j].format = (sad[0] & 0x78) >> 3;
  3670. (*sads)[j].channels = sad[0] & 0x7;
  3671. (*sads)[j].freq = sad[1] & 0x7F;
  3672. (*sads)[j].byte2 = sad[2];
  3673. }
  3674. break;
  3675. }
  3676. }
  3677. return count;
  3678. }
  3679. EXPORT_SYMBOL(drm_edid_to_sad);
  3680. /**
  3681. * drm_edid_to_speaker_allocation - extracts Speaker Allocation Data Blocks from EDID
  3682. * @edid: EDID to parse
  3683. * @sadb: pointer to the speaker block
  3684. *
  3685. * Looks for CEA EDID block and extracts the Speaker Allocation Data Block from it.
  3686. *
  3687. * Note: The returned pointer needs to be freed using kfree().
  3688. *
  3689. * Return: The number of found Speaker Allocation Blocks or negative number on
  3690. * error.
  3691. */
  3692. int drm_edid_to_speaker_allocation(struct edid *edid, u8 **sadb)
  3693. {
  3694. int count = 0;
  3695. int i, start, end, dbl;
  3696. const u8 *cea;
  3697. cea = drm_find_cea_extension(edid);
  3698. if (!cea) {
  3699. DRM_DEBUG_KMS("SAD: no CEA Extension found\n");
  3700. return -ENOENT;
  3701. }
  3702. if (cea_revision(cea) < 3) {
  3703. DRM_DEBUG_KMS("SAD: wrong CEA revision\n");
  3704. return -ENOTSUPP;
  3705. }
  3706. if (cea_db_offsets(cea, &start, &end)) {
  3707. DRM_DEBUG_KMS("SAD: invalid data block offsets\n");
  3708. return -EPROTO;
  3709. }
  3710. for_each_cea_db(cea, i, start, end) {
  3711. const u8 *db = &cea[i];
  3712. if (cea_db_tag(db) == SPEAKER_BLOCK) {
  3713. dbl = cea_db_payload_len(db);
  3714. /* Speaker Allocation Data Block */
  3715. if (dbl == 3) {
  3716. *sadb = kmemdup(&db[1], dbl, GFP_KERNEL);
  3717. if (!*sadb)
  3718. return -ENOMEM;
  3719. count = dbl;
  3720. break;
  3721. }
  3722. }
  3723. }
  3724. return count;
  3725. }
  3726. EXPORT_SYMBOL(drm_edid_to_speaker_allocation);
  3727. /**
  3728. * drm_av_sync_delay - compute the HDMI/DP sink audio-video sync delay
  3729. * @connector: connector associated with the HDMI/DP sink
  3730. * @mode: the display mode
  3731. *
  3732. * Return: The HDMI/DP sink's audio-video sync delay in milliseconds or 0 if
  3733. * the sink doesn't support audio or video.
  3734. */
  3735. int drm_av_sync_delay(struct drm_connector *connector,
  3736. const struct drm_display_mode *mode)
  3737. {
  3738. int i = !!(mode->flags & DRM_MODE_FLAG_INTERLACE);
  3739. int a, v;
  3740. if (!connector->latency_present[0])
  3741. return 0;
  3742. if (!connector->latency_present[1])
  3743. i = 0;
  3744. a = connector->audio_latency[i];
  3745. v = connector->video_latency[i];
  3746. /*
  3747. * HDMI/DP sink doesn't support audio or video?
  3748. */
  3749. if (a == 255 || v == 255)
  3750. return 0;
  3751. /*
  3752. * Convert raw EDID values to millisecond.
  3753. * Treat unknown latency as 0ms.
  3754. */
  3755. if (a)
  3756. a = min(2 * (a - 1), 500);
  3757. if (v)
  3758. v = min(2 * (v - 1), 500);
  3759. return max(v - a, 0);
  3760. }
  3761. EXPORT_SYMBOL(drm_av_sync_delay);
  3762. /**
  3763. * drm_detect_hdmi_monitor - detect whether monitor is HDMI
  3764. * @edid: monitor EDID information
  3765. *
  3766. * Parse the CEA extension according to CEA-861-B.
  3767. *
  3768. * Return: True if the monitor is HDMI, false if not or unknown.
  3769. */
  3770. bool drm_detect_hdmi_monitor(struct edid *edid)
  3771. {
  3772. u8 *edid_ext;
  3773. int i;
  3774. int start_offset, end_offset;
  3775. edid_ext = drm_find_cea_extension(edid);
  3776. if (!edid_ext)
  3777. return false;
  3778. if (cea_db_offsets(edid_ext, &start_offset, &end_offset))
  3779. return false;
  3780. /*
  3781. * Because HDMI identifier is in Vendor Specific Block,
  3782. * search it from all data blocks of CEA extension.
  3783. */
  3784. for_each_cea_db(edid_ext, i, start_offset, end_offset) {
  3785. if (cea_db_is_hdmi_vsdb(&edid_ext[i]))
  3786. return true;
  3787. }
  3788. return false;
  3789. }
  3790. EXPORT_SYMBOL(drm_detect_hdmi_monitor);
  3791. /**
  3792. * drm_detect_monitor_audio - check monitor audio capability
  3793. * @edid: EDID block to scan
  3794. *
  3795. * Monitor should have CEA extension block.
  3796. * If monitor has 'basic audio', but no CEA audio blocks, it's 'basic
  3797. * audio' only. If there is any audio extension block and supported
  3798. * audio format, assume at least 'basic audio' support, even if 'basic
  3799. * audio' is not defined in EDID.
  3800. *
  3801. * Return: True if the monitor supports audio, false otherwise.
  3802. */
  3803. bool drm_detect_monitor_audio(struct edid *edid)
  3804. {
  3805. u8 *edid_ext;
  3806. int i, j;
  3807. bool has_audio = false;
  3808. int start_offset, end_offset;
  3809. edid_ext = drm_find_cea_extension(edid);
  3810. if (!edid_ext)
  3811. goto end;
  3812. has_audio = ((edid_ext[3] & EDID_BASIC_AUDIO) != 0);
  3813. if (has_audio) {
  3814. DRM_DEBUG_KMS("Monitor has basic audio support\n");
  3815. goto end;
  3816. }
  3817. if (cea_db_offsets(edid_ext, &start_offset, &end_offset))
  3818. goto end;
  3819. for_each_cea_db(edid_ext, i, start_offset, end_offset) {
  3820. if (cea_db_tag(&edid_ext[i]) == AUDIO_BLOCK) {
  3821. has_audio = true;
  3822. for (j = 1; j < cea_db_payload_len(&edid_ext[i]) + 1; j += 3)
  3823. DRM_DEBUG_KMS("CEA audio format %d\n",
  3824. (edid_ext[i + j] >> 3) & 0xf);
  3825. goto end;
  3826. }
  3827. }
  3828. end:
  3829. return has_audio;
  3830. }
  3831. EXPORT_SYMBOL(drm_detect_monitor_audio);
  3832. /**
  3833. * drm_rgb_quant_range_selectable - is RGB quantization range selectable?
  3834. * @edid: EDID block to scan
  3835. *
  3836. * Check whether the monitor reports the RGB quantization range selection
  3837. * as supported. The AVI infoframe can then be used to inform the monitor
  3838. * which quantization range (full or limited) is used.
  3839. *
  3840. * Return: True if the RGB quantization range is selectable, false otherwise.
  3841. */
  3842. bool drm_rgb_quant_range_selectable(struct edid *edid)
  3843. {
  3844. u8 *edid_ext;
  3845. int i, start, end;
  3846. edid_ext = drm_find_cea_extension(edid);
  3847. if (!edid_ext)
  3848. return false;
  3849. if (cea_db_offsets(edid_ext, &start, &end))
  3850. return false;
  3851. for_each_cea_db(edid_ext, i, start, end) {
  3852. if (cea_db_tag(&edid_ext[i]) == USE_EXTENDED_TAG &&
  3853. cea_db_payload_len(&edid_ext[i]) == 2 &&
  3854. cea_db_extended_tag(&edid_ext[i]) ==
  3855. EXT_VIDEO_CAPABILITY_BLOCK) {
  3856. DRM_DEBUG_KMS("CEA VCDB 0x%02x\n", edid_ext[i + 2]);
  3857. return edid_ext[i + 2] & EDID_CEA_VCDB_QS;
  3858. }
  3859. }
  3860. return false;
  3861. }
  3862. EXPORT_SYMBOL(drm_rgb_quant_range_selectable);
  3863. /**
  3864. * drm_default_rgb_quant_range - default RGB quantization range
  3865. * @mode: display mode
  3866. *
  3867. * Determine the default RGB quantization range for the mode,
  3868. * as specified in CEA-861.
  3869. *
  3870. * Return: The default RGB quantization range for the mode
  3871. */
  3872. enum hdmi_quantization_range
  3873. drm_default_rgb_quant_range(const struct drm_display_mode *mode)
  3874. {
  3875. /* All CEA modes other than VIC 1 use limited quantization range. */
  3876. return drm_match_cea_mode(mode) > 1 ?
  3877. HDMI_QUANTIZATION_RANGE_LIMITED :
  3878. HDMI_QUANTIZATION_RANGE_FULL;
  3879. }
  3880. EXPORT_SYMBOL(drm_default_rgb_quant_range);
  3881. static void drm_parse_ycbcr420_deep_color_info(struct drm_connector *connector,
  3882. const u8 *db)
  3883. {
  3884. u8 dc_mask;
  3885. struct drm_hdmi_info *hdmi = &connector->display_info.hdmi;
  3886. dc_mask = db[7] & DRM_EDID_YCBCR420_DC_MASK;
  3887. hdmi->y420_dc_modes = dc_mask;
  3888. }
  3889. static void drm_parse_hdmi_forum_vsdb(struct drm_connector *connector,
  3890. const u8 *hf_vsdb)
  3891. {
  3892. struct drm_display_info *display = &connector->display_info;
  3893. struct drm_hdmi_info *hdmi = &display->hdmi;
  3894. display->has_hdmi_infoframe = true;
  3895. if (hf_vsdb[6] & 0x80) {
  3896. hdmi->scdc.supported = true;
  3897. if (hf_vsdb[6] & 0x40)
  3898. hdmi->scdc.read_request = true;
  3899. }
  3900. /*
  3901. * All HDMI 2.0 monitors must support scrambling at rates > 340 MHz.
  3902. * And as per the spec, three factors confirm this:
  3903. * * Availability of a HF-VSDB block in EDID (check)
  3904. * * Non zero Max_TMDS_Char_Rate filed in HF-VSDB (let's check)
  3905. * * SCDC support available (let's check)
  3906. * Lets check it out.
  3907. */
  3908. if (hf_vsdb[5]) {
  3909. /* max clock is 5000 KHz times block value */
  3910. u32 max_tmds_clock = hf_vsdb[5] * 5000;
  3911. struct drm_scdc *scdc = &hdmi->scdc;
  3912. if (max_tmds_clock > 340000) {
  3913. display->max_tmds_clock = max_tmds_clock;
  3914. DRM_DEBUG_KMS("HF-VSDB: max TMDS clock %d kHz\n",
  3915. display->max_tmds_clock);
  3916. }
  3917. if (scdc->supported) {
  3918. scdc->scrambling.supported = true;
  3919. /* Few sinks support scrambling for cloks < 340M */
  3920. if ((hf_vsdb[6] & 0x8))
  3921. scdc->scrambling.low_rates = true;
  3922. }
  3923. }
  3924. drm_parse_ycbcr420_deep_color_info(connector, hf_vsdb);
  3925. }
  3926. static void drm_parse_hdmi_deep_color_info(struct drm_connector *connector,
  3927. const u8 *hdmi)
  3928. {
  3929. struct drm_display_info *info = &connector->display_info;
  3930. unsigned int dc_bpc = 0;
  3931. /* HDMI supports at least 8 bpc */
  3932. info->bpc = 8;
  3933. if (cea_db_payload_len(hdmi) < 6)
  3934. return;
  3935. if (hdmi[6] & DRM_EDID_HDMI_DC_30) {
  3936. dc_bpc = 10;
  3937. info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_30;
  3938. DRM_DEBUG("%s: HDMI sink does deep color 30.\n",
  3939. connector->name);
  3940. }
  3941. if (hdmi[6] & DRM_EDID_HDMI_DC_36) {
  3942. dc_bpc = 12;
  3943. info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_36;
  3944. DRM_DEBUG("%s: HDMI sink does deep color 36.\n",
  3945. connector->name);
  3946. }
  3947. if (hdmi[6] & DRM_EDID_HDMI_DC_48) {
  3948. dc_bpc = 16;
  3949. info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_48;
  3950. DRM_DEBUG("%s: HDMI sink does deep color 48.\n",
  3951. connector->name);
  3952. }
  3953. if (dc_bpc == 0) {
  3954. DRM_DEBUG("%s: No deep color support on this HDMI sink.\n",
  3955. connector->name);
  3956. return;
  3957. }
  3958. DRM_DEBUG("%s: Assigning HDMI sink color depth as %d bpc.\n",
  3959. connector->name, dc_bpc);
  3960. info->bpc = dc_bpc;
  3961. /*
  3962. * Deep color support mandates RGB444 support for all video
  3963. * modes and forbids YCRCB422 support for all video modes per
  3964. * HDMI 1.3 spec.
  3965. */
  3966. info->color_formats = DRM_COLOR_FORMAT_RGB444;
  3967. /* YCRCB444 is optional according to spec. */
  3968. if (hdmi[6] & DRM_EDID_HDMI_DC_Y444) {
  3969. info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
  3970. DRM_DEBUG("%s: HDMI sink does YCRCB444 in deep color.\n",
  3971. connector->name);
  3972. }
  3973. /*
  3974. * Spec says that if any deep color mode is supported at all,
  3975. * then deep color 36 bit must be supported.
  3976. */
  3977. if (!(hdmi[6] & DRM_EDID_HDMI_DC_36)) {
  3978. DRM_DEBUG("%s: HDMI sink should do DC_36, but does not!\n",
  3979. connector->name);
  3980. }
  3981. }
  3982. static void
  3983. drm_parse_hdmi_vsdb_video(struct drm_connector *connector, const u8 *db)
  3984. {
  3985. struct drm_display_info *info = &connector->display_info;
  3986. u8 len = cea_db_payload_len(db);
  3987. if (len >= 6)
  3988. info->dvi_dual = db[6] & 1;
  3989. if (len >= 7)
  3990. info->max_tmds_clock = db[7] * 5000;
  3991. DRM_DEBUG_KMS("HDMI: DVI dual %d, "
  3992. "max TMDS clock %d kHz\n",
  3993. info->dvi_dual,
  3994. info->max_tmds_clock);
  3995. drm_parse_hdmi_deep_color_info(connector, db);
  3996. }
  3997. static void drm_parse_cea_ext(struct drm_connector *connector,
  3998. const struct edid *edid)
  3999. {
  4000. struct drm_display_info *info = &connector->display_info;
  4001. const u8 *edid_ext;
  4002. int i, start, end;
  4003. edid_ext = drm_find_cea_extension(edid);
  4004. if (!edid_ext)
  4005. return;
  4006. info->cea_rev = edid_ext[1];
  4007. /* The existence of a CEA block should imply RGB support */
  4008. info->color_formats = DRM_COLOR_FORMAT_RGB444;
  4009. if (edid_ext[3] & EDID_CEA_YCRCB444)
  4010. info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
  4011. if (edid_ext[3] & EDID_CEA_YCRCB422)
  4012. info->color_formats |= DRM_COLOR_FORMAT_YCRCB422;
  4013. if (cea_db_offsets(edid_ext, &start, &end))
  4014. return;
  4015. for_each_cea_db(edid_ext, i, start, end) {
  4016. const u8 *db = &edid_ext[i];
  4017. if (cea_db_is_hdmi_vsdb(db))
  4018. drm_parse_hdmi_vsdb_video(connector, db);
  4019. if (cea_db_is_hdmi_forum_vsdb(db))
  4020. drm_parse_hdmi_forum_vsdb(connector, db);
  4021. if (cea_db_is_y420cmdb(db))
  4022. drm_parse_y420cmdb_bitmap(connector, db);
  4023. }
  4024. }
  4025. /* A connector has no EDID information, so we've got no EDID to compute quirks from. Reset
  4026. * all of the values which would have been set from EDID
  4027. */
  4028. void
  4029. drm_reset_display_info(struct drm_connector *connector)
  4030. {
  4031. struct drm_display_info *info = &connector->display_info;
  4032. info->width_mm = 0;
  4033. info->height_mm = 0;
  4034. info->bpc = 0;
  4035. info->color_formats = 0;
  4036. info->cea_rev = 0;
  4037. info->max_tmds_clock = 0;
  4038. info->dvi_dual = false;
  4039. info->has_hdmi_infoframe = false;
  4040. memset(&info->hdmi, 0, sizeof(info->hdmi));
  4041. info->non_desktop = 0;
  4042. }
  4043. u32 drm_add_display_info(struct drm_connector *connector, const struct edid *edid)
  4044. {
  4045. struct drm_display_info *info = &connector->display_info;
  4046. u32 quirks = edid_get_quirks(edid);
  4047. drm_reset_display_info(connector);
  4048. info->width_mm = edid->width_cm * 10;
  4049. info->height_mm = edid->height_cm * 10;
  4050. info->non_desktop = !!(quirks & EDID_QUIRK_NON_DESKTOP);
  4051. DRM_DEBUG_KMS("non_desktop set to %d\n", info->non_desktop);
  4052. if (edid->revision < 3)
  4053. return quirks;
  4054. if (!(edid->input & DRM_EDID_INPUT_DIGITAL))
  4055. return quirks;
  4056. drm_parse_cea_ext(connector, edid);
  4057. /*
  4058. * Digital sink with "DFP 1.x compliant TMDS" according to EDID 1.3?
  4059. *
  4060. * For such displays, the DFP spec 1.0, section 3.10 "EDID support"
  4061. * tells us to assume 8 bpc color depth if the EDID doesn't have
  4062. * extensions which tell otherwise.
  4063. */
  4064. if ((info->bpc == 0) && (edid->revision < 4) &&
  4065. (edid->input & DRM_EDID_DIGITAL_TYPE_DVI)) {
  4066. info->bpc = 8;
  4067. DRM_DEBUG("%s: Assigning DFP sink color depth as %d bpc.\n",
  4068. connector->name, info->bpc);
  4069. }
  4070. /* Only defined for 1.4 with digital displays */
  4071. if (edid->revision < 4)
  4072. return quirks;
  4073. switch (edid->input & DRM_EDID_DIGITAL_DEPTH_MASK) {
  4074. case DRM_EDID_DIGITAL_DEPTH_6:
  4075. info->bpc = 6;
  4076. break;
  4077. case DRM_EDID_DIGITAL_DEPTH_8:
  4078. info->bpc = 8;
  4079. break;
  4080. case DRM_EDID_DIGITAL_DEPTH_10:
  4081. info->bpc = 10;
  4082. break;
  4083. case DRM_EDID_DIGITAL_DEPTH_12:
  4084. info->bpc = 12;
  4085. break;
  4086. case DRM_EDID_DIGITAL_DEPTH_14:
  4087. info->bpc = 14;
  4088. break;
  4089. case DRM_EDID_DIGITAL_DEPTH_16:
  4090. info->bpc = 16;
  4091. break;
  4092. case DRM_EDID_DIGITAL_DEPTH_UNDEF:
  4093. default:
  4094. info->bpc = 0;
  4095. break;
  4096. }
  4097. DRM_DEBUG("%s: Assigning EDID-1.4 digital sink color depth as %d bpc.\n",
  4098. connector->name, info->bpc);
  4099. info->color_formats |= DRM_COLOR_FORMAT_RGB444;
  4100. if (edid->features & DRM_EDID_FEATURE_RGB_YCRCB444)
  4101. info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
  4102. if (edid->features & DRM_EDID_FEATURE_RGB_YCRCB422)
  4103. info->color_formats |= DRM_COLOR_FORMAT_YCRCB422;
  4104. return quirks;
  4105. }
  4106. static int validate_displayid(u8 *displayid, int length, int idx)
  4107. {
  4108. int i;
  4109. u8 csum = 0;
  4110. struct displayid_hdr *base;
  4111. base = (struct displayid_hdr *)&displayid[idx];
  4112. DRM_DEBUG_KMS("base revision 0x%x, length %d, %d %d\n",
  4113. base->rev, base->bytes, base->prod_id, base->ext_count);
  4114. if (base->bytes + 5 > length - idx)
  4115. return -EINVAL;
  4116. for (i = idx; i <= base->bytes + 5; i++) {
  4117. csum += displayid[i];
  4118. }
  4119. if (csum) {
  4120. DRM_NOTE("DisplayID checksum invalid, remainder is %d\n", csum);
  4121. return -EINVAL;
  4122. }
  4123. return 0;
  4124. }
  4125. static struct drm_display_mode *drm_mode_displayid_detailed(struct drm_device *dev,
  4126. struct displayid_detailed_timings_1 *timings)
  4127. {
  4128. struct drm_display_mode *mode;
  4129. unsigned pixel_clock = (timings->pixel_clock[0] |
  4130. (timings->pixel_clock[1] << 8) |
  4131. (timings->pixel_clock[2] << 16));
  4132. unsigned hactive = (timings->hactive[0] | timings->hactive[1] << 8) + 1;
  4133. unsigned hblank = (timings->hblank[0] | timings->hblank[1] << 8) + 1;
  4134. unsigned hsync = (timings->hsync[0] | (timings->hsync[1] & 0x7f) << 8) + 1;
  4135. unsigned hsync_width = (timings->hsw[0] | timings->hsw[1] << 8) + 1;
  4136. unsigned vactive = (timings->vactive[0] | timings->vactive[1] << 8) + 1;
  4137. unsigned vblank = (timings->vblank[0] | timings->vblank[1] << 8) + 1;
  4138. unsigned vsync = (timings->vsync[0] | (timings->vsync[1] & 0x7f) << 8) + 1;
  4139. unsigned vsync_width = (timings->vsw[0] | timings->vsw[1] << 8) + 1;
  4140. bool hsync_positive = (timings->hsync[1] >> 7) & 0x1;
  4141. bool vsync_positive = (timings->vsync[1] >> 7) & 0x1;
  4142. mode = drm_mode_create(dev);
  4143. if (!mode)
  4144. return NULL;
  4145. mode->clock = pixel_clock * 10;
  4146. mode->hdisplay = hactive;
  4147. mode->hsync_start = mode->hdisplay + hsync;
  4148. mode->hsync_end = mode->hsync_start + hsync_width;
  4149. mode->htotal = mode->hdisplay + hblank;
  4150. mode->vdisplay = vactive;
  4151. mode->vsync_start = mode->vdisplay + vsync;
  4152. mode->vsync_end = mode->vsync_start + vsync_width;
  4153. mode->vtotal = mode->vdisplay + vblank;
  4154. mode->flags = 0;
  4155. mode->flags |= hsync_positive ? DRM_MODE_FLAG_PHSYNC : DRM_MODE_FLAG_NHSYNC;
  4156. mode->flags |= vsync_positive ? DRM_MODE_FLAG_PVSYNC : DRM_MODE_FLAG_NVSYNC;
  4157. mode->type = DRM_MODE_TYPE_DRIVER;
  4158. if (timings->flags & 0x80)
  4159. mode->type |= DRM_MODE_TYPE_PREFERRED;
  4160. mode->vrefresh = drm_mode_vrefresh(mode);
  4161. drm_mode_set_name(mode);
  4162. return mode;
  4163. }
  4164. static int add_displayid_detailed_1_modes(struct drm_connector *connector,
  4165. struct displayid_block *block)
  4166. {
  4167. struct displayid_detailed_timing_block *det = (struct displayid_detailed_timing_block *)block;
  4168. int i;
  4169. int num_timings;
  4170. struct drm_display_mode *newmode;
  4171. int num_modes = 0;
  4172. /* blocks must be multiple of 20 bytes length */
  4173. if (block->num_bytes % 20)
  4174. return 0;
  4175. num_timings = block->num_bytes / 20;
  4176. for (i = 0; i < num_timings; i++) {
  4177. struct displayid_detailed_timings_1 *timings = &det->timings[i];
  4178. newmode = drm_mode_displayid_detailed(connector->dev, timings);
  4179. if (!newmode)
  4180. continue;
  4181. drm_mode_probed_add(connector, newmode);
  4182. num_modes++;
  4183. }
  4184. return num_modes;
  4185. }
  4186. static int add_displayid_detailed_modes(struct drm_connector *connector,
  4187. struct edid *edid)
  4188. {
  4189. u8 *displayid;
  4190. int ret;
  4191. int idx = 1;
  4192. int length = EDID_LENGTH;
  4193. struct displayid_block *block;
  4194. int num_modes = 0;
  4195. displayid = drm_find_displayid_extension(edid);
  4196. if (!displayid)
  4197. return 0;
  4198. ret = validate_displayid(displayid, length, idx);
  4199. if (ret)
  4200. return 0;
  4201. idx += sizeof(struct displayid_hdr);
  4202. while (block = (struct displayid_block *)&displayid[idx],
  4203. idx + sizeof(struct displayid_block) <= length &&
  4204. idx + sizeof(struct displayid_block) + block->num_bytes <= length &&
  4205. block->num_bytes > 0) {
  4206. idx += block->num_bytes + sizeof(struct displayid_block);
  4207. switch (block->tag) {
  4208. case DATA_BLOCK_TYPE_1_DETAILED_TIMING:
  4209. num_modes += add_displayid_detailed_1_modes(connector, block);
  4210. break;
  4211. }
  4212. }
  4213. return num_modes;
  4214. }
  4215. /**
  4216. * drm_add_edid_modes - add modes from EDID data, if available
  4217. * @connector: connector we're probing
  4218. * @edid: EDID data
  4219. *
  4220. * Add the specified modes to the connector's mode list. Also fills out the
  4221. * &drm_display_info structure and ELD in @connector with any information which
  4222. * can be derived from the edid.
  4223. *
  4224. * Return: The number of modes added or 0 if we couldn't find any.
  4225. */
  4226. int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid)
  4227. {
  4228. int num_modes = 0;
  4229. u32 quirks;
  4230. if (edid == NULL) {
  4231. clear_eld(connector);
  4232. return 0;
  4233. }
  4234. if (!drm_edid_is_valid(edid)) {
  4235. clear_eld(connector);
  4236. dev_warn(connector->dev->dev, "%s: EDID invalid.\n",
  4237. connector->name);
  4238. return 0;
  4239. }
  4240. drm_edid_to_eld(connector, edid);
  4241. /*
  4242. * CEA-861-F adds ycbcr capability map block, for HDMI 2.0 sinks.
  4243. * To avoid multiple parsing of same block, lets parse that map
  4244. * from sink info, before parsing CEA modes.
  4245. */
  4246. quirks = drm_add_display_info(connector, edid);
  4247. /*
  4248. * EDID spec says modes should be preferred in this order:
  4249. * - preferred detailed mode
  4250. * - other detailed modes from base block
  4251. * - detailed modes from extension blocks
  4252. * - CVT 3-byte code modes
  4253. * - standard timing codes
  4254. * - established timing codes
  4255. * - modes inferred from GTF or CVT range information
  4256. *
  4257. * We get this pretty much right.
  4258. *
  4259. * XXX order for additional mode types in extension blocks?
  4260. */
  4261. num_modes += add_detailed_modes(connector, edid, quirks);
  4262. num_modes += add_cvt_modes(connector, edid);
  4263. num_modes += add_standard_modes(connector, edid);
  4264. num_modes += add_established_modes(connector, edid);
  4265. num_modes += add_cea_modes(connector, edid);
  4266. num_modes += add_alternate_cea_modes(connector, edid);
  4267. num_modes += add_displayid_detailed_modes(connector, edid);
  4268. if (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF)
  4269. num_modes += add_inferred_modes(connector, edid);
  4270. if (quirks & (EDID_QUIRK_PREFER_LARGE_60 | EDID_QUIRK_PREFER_LARGE_75))
  4271. edid_fixup_preferred(connector, quirks);
  4272. if (quirks & EDID_QUIRK_FORCE_6BPC)
  4273. connector->display_info.bpc = 6;
  4274. if (quirks & EDID_QUIRK_FORCE_8BPC)
  4275. connector->display_info.bpc = 8;
  4276. if (quirks & EDID_QUIRK_FORCE_10BPC)
  4277. connector->display_info.bpc = 10;
  4278. if (quirks & EDID_QUIRK_FORCE_12BPC)
  4279. connector->display_info.bpc = 12;
  4280. return num_modes;
  4281. }
  4282. EXPORT_SYMBOL(drm_add_edid_modes);
  4283. /**
  4284. * drm_add_modes_noedid - add modes for the connectors without EDID
  4285. * @connector: connector we're probing
  4286. * @hdisplay: the horizontal display limit
  4287. * @vdisplay: the vertical display limit
  4288. *
  4289. * Add the specified modes to the connector's mode list. Only when the
  4290. * hdisplay/vdisplay is not beyond the given limit, it will be added.
  4291. *
  4292. * Return: The number of modes added or 0 if we couldn't find any.
  4293. */
  4294. int drm_add_modes_noedid(struct drm_connector *connector,
  4295. int hdisplay, int vdisplay)
  4296. {
  4297. int i, count, num_modes = 0;
  4298. struct drm_display_mode *mode;
  4299. struct drm_device *dev = connector->dev;
  4300. count = ARRAY_SIZE(drm_dmt_modes);
  4301. if (hdisplay < 0)
  4302. hdisplay = 0;
  4303. if (vdisplay < 0)
  4304. vdisplay = 0;
  4305. for (i = 0; i < count; i++) {
  4306. const struct drm_display_mode *ptr = &drm_dmt_modes[i];
  4307. if (hdisplay && vdisplay) {
  4308. /*
  4309. * Only when two are valid, they will be used to check
  4310. * whether the mode should be added to the mode list of
  4311. * the connector.
  4312. */
  4313. if (ptr->hdisplay > hdisplay ||
  4314. ptr->vdisplay > vdisplay)
  4315. continue;
  4316. }
  4317. if (drm_mode_vrefresh(ptr) > 61)
  4318. continue;
  4319. mode = drm_mode_duplicate(dev, ptr);
  4320. if (mode) {
  4321. drm_mode_probed_add(connector, mode);
  4322. num_modes++;
  4323. }
  4324. }
  4325. return num_modes;
  4326. }
  4327. EXPORT_SYMBOL(drm_add_modes_noedid);
  4328. /**
  4329. * drm_set_preferred_mode - Sets the preferred mode of a connector
  4330. * @connector: connector whose mode list should be processed
  4331. * @hpref: horizontal resolution of preferred mode
  4332. * @vpref: vertical resolution of preferred mode
  4333. *
  4334. * Marks a mode as preferred if it matches the resolution specified by @hpref
  4335. * and @vpref.
  4336. */
  4337. void drm_set_preferred_mode(struct drm_connector *connector,
  4338. int hpref, int vpref)
  4339. {
  4340. struct drm_display_mode *mode;
  4341. list_for_each_entry(mode, &connector->probed_modes, head) {
  4342. if (mode->hdisplay == hpref &&
  4343. mode->vdisplay == vpref)
  4344. mode->type |= DRM_MODE_TYPE_PREFERRED;
  4345. }
  4346. }
  4347. EXPORT_SYMBOL(drm_set_preferred_mode);
  4348. /**
  4349. * drm_hdmi_avi_infoframe_from_display_mode() - fill an HDMI AVI infoframe with
  4350. * data from a DRM display mode
  4351. * @frame: HDMI AVI infoframe
  4352. * @mode: DRM display mode
  4353. * @is_hdmi2_sink: Sink is HDMI 2.0 compliant
  4354. *
  4355. * Return: 0 on success or a negative error code on failure.
  4356. */
  4357. int
  4358. drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
  4359. const struct drm_display_mode *mode,
  4360. bool is_hdmi2_sink)
  4361. {
  4362. enum hdmi_picture_aspect picture_aspect;
  4363. int err;
  4364. if (!frame || !mode)
  4365. return -EINVAL;
  4366. err = hdmi_avi_infoframe_init(frame);
  4367. if (err < 0)
  4368. return err;
  4369. if (mode->flags & DRM_MODE_FLAG_DBLCLK)
  4370. frame->pixel_repeat = 1;
  4371. frame->video_code = drm_match_cea_mode(mode);
  4372. /*
  4373. * HDMI 1.4 VIC range: 1 <= VIC <= 64 (CEA-861-D) but
  4374. * HDMI 2.0 VIC range: 1 <= VIC <= 107 (CEA-861-F). So we
  4375. * have to make sure we dont break HDMI 1.4 sinks.
  4376. */
  4377. if (!is_hdmi2_sink && frame->video_code > 64)
  4378. frame->video_code = 0;
  4379. /*
  4380. * HDMI spec says if a mode is found in HDMI 1.4b 4K modes
  4381. * we should send its VIC in vendor infoframes, else send the
  4382. * VIC in AVI infoframes. Lets check if this mode is present in
  4383. * HDMI 1.4b 4K modes
  4384. */
  4385. if (frame->video_code) {
  4386. u8 vendor_if_vic = drm_match_hdmi_mode(mode);
  4387. bool is_s3d = mode->flags & DRM_MODE_FLAG_3D_MASK;
  4388. if (drm_valid_hdmi_vic(vendor_if_vic) && !is_s3d)
  4389. frame->video_code = 0;
  4390. }
  4391. frame->picture_aspect = HDMI_PICTURE_ASPECT_NONE;
  4392. /*
  4393. * As some drivers don't support atomic, we can't use connector state.
  4394. * So just initialize the frame with default values, just the same way
  4395. * as it's done with other properties here.
  4396. */
  4397. frame->content_type = HDMI_CONTENT_TYPE_GRAPHICS;
  4398. frame->itc = 0;
  4399. /*
  4400. * Populate picture aspect ratio from either
  4401. * user input (if specified) or from the CEA mode list.
  4402. */
  4403. picture_aspect = mode->picture_aspect_ratio;
  4404. if (picture_aspect == HDMI_PICTURE_ASPECT_NONE)
  4405. picture_aspect = drm_get_cea_aspect_ratio(frame->video_code);
  4406. /*
  4407. * The infoframe can't convey anything but none, 4:3
  4408. * and 16:9, so if the user has asked for anything else
  4409. * we can only satisfy it by specifying the right VIC.
  4410. */
  4411. if (picture_aspect > HDMI_PICTURE_ASPECT_16_9) {
  4412. if (picture_aspect !=
  4413. drm_get_cea_aspect_ratio(frame->video_code))
  4414. return -EINVAL;
  4415. picture_aspect = HDMI_PICTURE_ASPECT_NONE;
  4416. }
  4417. frame->picture_aspect = picture_aspect;
  4418. frame->active_aspect = HDMI_ACTIVE_ASPECT_PICTURE;
  4419. frame->scan_mode = HDMI_SCAN_MODE_UNDERSCAN;
  4420. return 0;
  4421. }
  4422. EXPORT_SYMBOL(drm_hdmi_avi_infoframe_from_display_mode);
  4423. /**
  4424. * drm_hdmi_avi_infoframe_quant_range() - fill the HDMI AVI infoframe
  4425. * quantization range information
  4426. * @frame: HDMI AVI infoframe
  4427. * @mode: DRM display mode
  4428. * @rgb_quant_range: RGB quantization range (Q)
  4429. * @rgb_quant_range_selectable: Sink support selectable RGB quantization range (QS)
  4430. * @is_hdmi2_sink: HDMI 2.0 sink, which has different default recommendations
  4431. *
  4432. * Note that @is_hdmi2_sink can be derived by looking at the
  4433. * &drm_scdc.supported flag stored in &drm_hdmi_info.scdc,
  4434. * &drm_display_info.hdmi, which can be found in &drm_connector.display_info.
  4435. */
  4436. void
  4437. drm_hdmi_avi_infoframe_quant_range(struct hdmi_avi_infoframe *frame,
  4438. const struct drm_display_mode *mode,
  4439. enum hdmi_quantization_range rgb_quant_range,
  4440. bool rgb_quant_range_selectable,
  4441. bool is_hdmi2_sink)
  4442. {
  4443. /*
  4444. * CEA-861:
  4445. * "A Source shall not send a non-zero Q value that does not correspond
  4446. * to the default RGB Quantization Range for the transmitted Picture
  4447. * unless the Sink indicates support for the Q bit in a Video
  4448. * Capabilities Data Block."
  4449. *
  4450. * HDMI 2.0 recommends sending non-zero Q when it does match the
  4451. * default RGB quantization range for the mode, even when QS=0.
  4452. */
  4453. if (rgb_quant_range_selectable ||
  4454. rgb_quant_range == drm_default_rgb_quant_range(mode))
  4455. frame->quantization_range = rgb_quant_range;
  4456. else
  4457. frame->quantization_range = HDMI_QUANTIZATION_RANGE_DEFAULT;
  4458. /*
  4459. * CEA-861-F:
  4460. * "When transmitting any RGB colorimetry, the Source should set the
  4461. * YQ-field to match the RGB Quantization Range being transmitted
  4462. * (e.g., when Limited Range RGB, set YQ=0 or when Full Range RGB,
  4463. * set YQ=1) and the Sink shall ignore the YQ-field."
  4464. *
  4465. * Unfortunate certain sinks (eg. VIZ Model 67/E261VA) get confused
  4466. * by non-zero YQ when receiving RGB. There doesn't seem to be any
  4467. * good way to tell which version of CEA-861 the sink supports, so
  4468. * we limit non-zero YQ to HDMI 2.0 sinks only as HDMI 2.0 is based
  4469. * on on CEA-861-F.
  4470. */
  4471. if (!is_hdmi2_sink ||
  4472. rgb_quant_range == HDMI_QUANTIZATION_RANGE_LIMITED)
  4473. frame->ycc_quantization_range =
  4474. HDMI_YCC_QUANTIZATION_RANGE_LIMITED;
  4475. else
  4476. frame->ycc_quantization_range =
  4477. HDMI_YCC_QUANTIZATION_RANGE_FULL;
  4478. }
  4479. EXPORT_SYMBOL(drm_hdmi_avi_infoframe_quant_range);
  4480. static enum hdmi_3d_structure
  4481. s3d_structure_from_display_mode(const struct drm_display_mode *mode)
  4482. {
  4483. u32 layout = mode->flags & DRM_MODE_FLAG_3D_MASK;
  4484. switch (layout) {
  4485. case DRM_MODE_FLAG_3D_FRAME_PACKING:
  4486. return HDMI_3D_STRUCTURE_FRAME_PACKING;
  4487. case DRM_MODE_FLAG_3D_FIELD_ALTERNATIVE:
  4488. return HDMI_3D_STRUCTURE_FIELD_ALTERNATIVE;
  4489. case DRM_MODE_FLAG_3D_LINE_ALTERNATIVE:
  4490. return HDMI_3D_STRUCTURE_LINE_ALTERNATIVE;
  4491. case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_FULL:
  4492. return HDMI_3D_STRUCTURE_SIDE_BY_SIDE_FULL;
  4493. case DRM_MODE_FLAG_3D_L_DEPTH:
  4494. return HDMI_3D_STRUCTURE_L_DEPTH;
  4495. case DRM_MODE_FLAG_3D_L_DEPTH_GFX_GFX_DEPTH:
  4496. return HDMI_3D_STRUCTURE_L_DEPTH_GFX_GFX_DEPTH;
  4497. case DRM_MODE_FLAG_3D_TOP_AND_BOTTOM:
  4498. return HDMI_3D_STRUCTURE_TOP_AND_BOTTOM;
  4499. case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF:
  4500. return HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF;
  4501. default:
  4502. return HDMI_3D_STRUCTURE_INVALID;
  4503. }
  4504. }
  4505. /**
  4506. * drm_hdmi_vendor_infoframe_from_display_mode() - fill an HDMI infoframe with
  4507. * data from a DRM display mode
  4508. * @frame: HDMI vendor infoframe
  4509. * @connector: the connector
  4510. * @mode: DRM display mode
  4511. *
  4512. * Note that there's is a need to send HDMI vendor infoframes only when using a
  4513. * 4k or stereoscopic 3D mode. So when giving any other mode as input this
  4514. * function will return -EINVAL, error that can be safely ignored.
  4515. *
  4516. * Return: 0 on success or a negative error code on failure.
  4517. */
  4518. int
  4519. drm_hdmi_vendor_infoframe_from_display_mode(struct hdmi_vendor_infoframe *frame,
  4520. struct drm_connector *connector,
  4521. const struct drm_display_mode *mode)
  4522. {
  4523. /*
  4524. * FIXME: sil-sii8620 doesn't have a connector around when
  4525. * we need one, so we have to be prepared for a NULL connector.
  4526. */
  4527. bool has_hdmi_infoframe = connector ?
  4528. connector->display_info.has_hdmi_infoframe : false;
  4529. int err;
  4530. u32 s3d_flags;
  4531. u8 vic;
  4532. if (!frame || !mode)
  4533. return -EINVAL;
  4534. if (!has_hdmi_infoframe)
  4535. return -EINVAL;
  4536. vic = drm_match_hdmi_mode(mode);
  4537. s3d_flags = mode->flags & DRM_MODE_FLAG_3D_MASK;
  4538. /*
  4539. * Even if it's not absolutely necessary to send the infoframe
  4540. * (ie.vic==0 and s3d_struct==0) we will still send it if we
  4541. * know that the sink can handle it. This is based on a
  4542. * suggestion in HDMI 2.0 Appendix F. Apparently some sinks
  4543. * have trouble realizing that they shuld switch from 3D to 2D
  4544. * mode if the source simply stops sending the infoframe when
  4545. * it wants to switch from 3D to 2D.
  4546. */
  4547. if (vic && s3d_flags)
  4548. return -EINVAL;
  4549. err = hdmi_vendor_infoframe_init(frame);
  4550. if (err < 0)
  4551. return err;
  4552. frame->vic = vic;
  4553. frame->s3d_struct = s3d_structure_from_display_mode(mode);
  4554. return 0;
  4555. }
  4556. EXPORT_SYMBOL(drm_hdmi_vendor_infoframe_from_display_mode);
  4557. static int drm_parse_tiled_block(struct drm_connector *connector,
  4558. struct displayid_block *block)
  4559. {
  4560. struct displayid_tiled_block *tile = (struct displayid_tiled_block *)block;
  4561. u16 w, h;
  4562. u8 tile_v_loc, tile_h_loc;
  4563. u8 num_v_tile, num_h_tile;
  4564. struct drm_tile_group *tg;
  4565. w = tile->tile_size[0] | tile->tile_size[1] << 8;
  4566. h = tile->tile_size[2] | tile->tile_size[3] << 8;
  4567. num_v_tile = (tile->topo[0] & 0xf) | (tile->topo[2] & 0x30);
  4568. num_h_tile = (tile->topo[0] >> 4) | ((tile->topo[2] >> 2) & 0x30);
  4569. tile_v_loc = (tile->topo[1] & 0xf) | ((tile->topo[2] & 0x3) << 4);
  4570. tile_h_loc = (tile->topo[1] >> 4) | (((tile->topo[2] >> 2) & 0x3) << 4);
  4571. connector->has_tile = true;
  4572. if (tile->tile_cap & 0x80)
  4573. connector->tile_is_single_monitor = true;
  4574. connector->num_h_tile = num_h_tile + 1;
  4575. connector->num_v_tile = num_v_tile + 1;
  4576. connector->tile_h_loc = tile_h_loc;
  4577. connector->tile_v_loc = tile_v_loc;
  4578. connector->tile_h_size = w + 1;
  4579. connector->tile_v_size = h + 1;
  4580. DRM_DEBUG_KMS("tile cap 0x%x\n", tile->tile_cap);
  4581. DRM_DEBUG_KMS("tile_size %d x %d\n", w + 1, h + 1);
  4582. DRM_DEBUG_KMS("topo num tiles %dx%d, location %dx%d\n",
  4583. num_h_tile + 1, num_v_tile + 1, tile_h_loc, tile_v_loc);
  4584. DRM_DEBUG_KMS("vend %c%c%c\n", tile->topology_id[0], tile->topology_id[1], tile->topology_id[2]);
  4585. tg = drm_mode_get_tile_group(connector->dev, tile->topology_id);
  4586. if (!tg) {
  4587. tg = drm_mode_create_tile_group(connector->dev, tile->topology_id);
  4588. }
  4589. if (!tg)
  4590. return -ENOMEM;
  4591. if (connector->tile_group != tg) {
  4592. /* if we haven't got a pointer,
  4593. take the reference, drop ref to old tile group */
  4594. if (connector->tile_group) {
  4595. drm_mode_put_tile_group(connector->dev, connector->tile_group);
  4596. }
  4597. connector->tile_group = tg;
  4598. } else
  4599. /* if same tile group, then release the ref we just took. */
  4600. drm_mode_put_tile_group(connector->dev, tg);
  4601. return 0;
  4602. }
  4603. static int drm_parse_display_id(struct drm_connector *connector,
  4604. u8 *displayid, int length,
  4605. bool is_edid_extension)
  4606. {
  4607. /* if this is an EDID extension the first byte will be 0x70 */
  4608. int idx = 0;
  4609. struct displayid_block *block;
  4610. int ret;
  4611. if (is_edid_extension)
  4612. idx = 1;
  4613. ret = validate_displayid(displayid, length, idx);
  4614. if (ret)
  4615. return ret;
  4616. idx += sizeof(struct displayid_hdr);
  4617. while (block = (struct displayid_block *)&displayid[idx],
  4618. idx + sizeof(struct displayid_block) <= length &&
  4619. idx + sizeof(struct displayid_block) + block->num_bytes <= length &&
  4620. block->num_bytes > 0) {
  4621. idx += block->num_bytes + sizeof(struct displayid_block);
  4622. DRM_DEBUG_KMS("block id 0x%x, rev %d, len %d\n",
  4623. block->tag, block->rev, block->num_bytes);
  4624. switch (block->tag) {
  4625. case DATA_BLOCK_TILED_DISPLAY:
  4626. ret = drm_parse_tiled_block(connector, block);
  4627. if (ret)
  4628. return ret;
  4629. break;
  4630. case DATA_BLOCK_TYPE_1_DETAILED_TIMING:
  4631. /* handled in mode gathering code. */
  4632. break;
  4633. case DATA_BLOCK_CTA:
  4634. /* handled in the cea parser code. */
  4635. break;
  4636. default:
  4637. DRM_DEBUG_KMS("found DisplayID tag 0x%x, unhandled\n", block->tag);
  4638. break;
  4639. }
  4640. }
  4641. return 0;
  4642. }
  4643. static void drm_get_displayid(struct drm_connector *connector,
  4644. struct edid *edid)
  4645. {
  4646. void *displayid = NULL;
  4647. int ret;
  4648. connector->has_tile = false;
  4649. displayid = drm_find_displayid_extension(edid);
  4650. if (!displayid) {
  4651. /* drop reference to any tile group we had */
  4652. goto out_drop_ref;
  4653. }
  4654. ret = drm_parse_display_id(connector, displayid, EDID_LENGTH, true);
  4655. if (ret < 0)
  4656. goto out_drop_ref;
  4657. if (!connector->has_tile)
  4658. goto out_drop_ref;
  4659. return;
  4660. out_drop_ref:
  4661. if (connector->tile_group) {
  4662. drm_mode_put_tile_group(connector->dev, connector->tile_group);
  4663. connector->tile_group = NULL;
  4664. }
  4665. return;
  4666. }