drm_edid.c 119 KB

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