drm_edid.c 157 KB

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