drm_edid.c 134 KB

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