drm_edid.c 153 KB

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