drm_edid.c 157 KB

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