drm_edid.c 154 KB

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