drm_edid.c 152 KB

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