drm_edid.c 133 KB

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