drm_edid.c 108 KB

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