drm_edid.c 124 KB

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