drm_edid.c 158 KB

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