drm_edid.c 129 KB

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