drm_edid.c 113 KB

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