drm_edid.c 135 KB

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