drm_edid.c 114 KB

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