drm_edid.c 130 KB

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