drm_edid.c 118 KB

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