drm_edid.c 135 KB

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