radeon_atombios.c 142 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438
  1. /*
  2. * Copyright 2007-8 Advanced Micro Devices, Inc.
  3. * Copyright 2008 Red Hat Inc.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  19. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  20. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. * OTHER DEALINGS IN THE SOFTWARE.
  22. *
  23. * Authors: Dave Airlie
  24. * Alex Deucher
  25. */
  26. #include <drm/drmP.h>
  27. #include <drm/radeon_drm.h>
  28. #include "radeon.h"
  29. #include "atom.h"
  30. #include "atom-bits.h"
  31. extern void
  32. radeon_add_atom_encoder(struct drm_device *dev, uint32_t encoder_enum,
  33. uint32_t supported_device, u16 caps);
  34. /* from radeon_legacy_encoder.c */
  35. extern void
  36. radeon_add_legacy_encoder(struct drm_device *dev, uint32_t encoder_enum,
  37. uint32_t supported_device);
  38. union atom_supported_devices {
  39. struct _ATOM_SUPPORTED_DEVICES_INFO info;
  40. struct _ATOM_SUPPORTED_DEVICES_INFO_2 info_2;
  41. struct _ATOM_SUPPORTED_DEVICES_INFO_2d1 info_2d1;
  42. };
  43. static void radeon_lookup_i2c_gpio_quirks(struct radeon_device *rdev,
  44. ATOM_GPIO_I2C_ASSIGMENT *gpio,
  45. u8 index)
  46. {
  47. /* r4xx mask is technically not used by the hw, so patch in the legacy mask bits */
  48. if ((rdev->family == CHIP_R420) ||
  49. (rdev->family == CHIP_R423) ||
  50. (rdev->family == CHIP_RV410)) {
  51. if ((le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x0018) ||
  52. (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x0019) ||
  53. (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x001a)) {
  54. gpio->ucClkMaskShift = 0x19;
  55. gpio->ucDataMaskShift = 0x18;
  56. }
  57. }
  58. /* some evergreen boards have bad data for this entry */
  59. if (ASIC_IS_DCE4(rdev)) {
  60. if ((index == 7) &&
  61. (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x1936) &&
  62. (gpio->sucI2cId.ucAccess == 0)) {
  63. gpio->sucI2cId.ucAccess = 0x97;
  64. gpio->ucDataMaskShift = 8;
  65. gpio->ucDataEnShift = 8;
  66. gpio->ucDataY_Shift = 8;
  67. gpio->ucDataA_Shift = 8;
  68. }
  69. }
  70. /* some DCE3 boards have bad data for this entry */
  71. if (ASIC_IS_DCE3(rdev)) {
  72. if ((index == 4) &&
  73. (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x1fda) &&
  74. (gpio->sucI2cId.ucAccess == 0x94))
  75. gpio->sucI2cId.ucAccess = 0x14;
  76. }
  77. }
  78. static struct radeon_i2c_bus_rec radeon_get_bus_rec_for_i2c_gpio(ATOM_GPIO_I2C_ASSIGMENT *gpio)
  79. {
  80. struct radeon_i2c_bus_rec i2c;
  81. memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
  82. i2c.mask_clk_reg = le16_to_cpu(gpio->usClkMaskRegisterIndex) * 4;
  83. i2c.mask_data_reg = le16_to_cpu(gpio->usDataMaskRegisterIndex) * 4;
  84. i2c.en_clk_reg = le16_to_cpu(gpio->usClkEnRegisterIndex) * 4;
  85. i2c.en_data_reg = le16_to_cpu(gpio->usDataEnRegisterIndex) * 4;
  86. i2c.y_clk_reg = le16_to_cpu(gpio->usClkY_RegisterIndex) * 4;
  87. i2c.y_data_reg = le16_to_cpu(gpio->usDataY_RegisterIndex) * 4;
  88. i2c.a_clk_reg = le16_to_cpu(gpio->usClkA_RegisterIndex) * 4;
  89. i2c.a_data_reg = le16_to_cpu(gpio->usDataA_RegisterIndex) * 4;
  90. i2c.mask_clk_mask = (1 << gpio->ucClkMaskShift);
  91. i2c.mask_data_mask = (1 << gpio->ucDataMaskShift);
  92. i2c.en_clk_mask = (1 << gpio->ucClkEnShift);
  93. i2c.en_data_mask = (1 << gpio->ucDataEnShift);
  94. i2c.y_clk_mask = (1 << gpio->ucClkY_Shift);
  95. i2c.y_data_mask = (1 << gpio->ucDataY_Shift);
  96. i2c.a_clk_mask = (1 << gpio->ucClkA_Shift);
  97. i2c.a_data_mask = (1 << gpio->ucDataA_Shift);
  98. if (gpio->sucI2cId.sbfAccess.bfHW_Capable)
  99. i2c.hw_capable = true;
  100. else
  101. i2c.hw_capable = false;
  102. if (gpio->sucI2cId.ucAccess == 0xa0)
  103. i2c.mm_i2c = true;
  104. else
  105. i2c.mm_i2c = false;
  106. i2c.i2c_id = gpio->sucI2cId.ucAccess;
  107. if (i2c.mask_clk_reg)
  108. i2c.valid = true;
  109. else
  110. i2c.valid = false;
  111. return i2c;
  112. }
  113. static struct radeon_i2c_bus_rec radeon_lookup_i2c_gpio(struct radeon_device *rdev,
  114. uint8_t id)
  115. {
  116. struct atom_context *ctx = rdev->mode_info.atom_context;
  117. ATOM_GPIO_I2C_ASSIGMENT *gpio;
  118. struct radeon_i2c_bus_rec i2c;
  119. int index = GetIndexIntoMasterTable(DATA, GPIO_I2C_Info);
  120. struct _ATOM_GPIO_I2C_INFO *i2c_info;
  121. uint16_t data_offset, size;
  122. int i, num_indices;
  123. memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
  124. i2c.valid = false;
  125. if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
  126. i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
  127. num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
  128. sizeof(ATOM_GPIO_I2C_ASSIGMENT);
  129. gpio = &i2c_info->asGPIO_Info[0];
  130. for (i = 0; i < num_indices; i++) {
  131. radeon_lookup_i2c_gpio_quirks(rdev, gpio, i);
  132. if (gpio->sucI2cId.ucAccess == id) {
  133. i2c = radeon_get_bus_rec_for_i2c_gpio(gpio);
  134. break;
  135. }
  136. gpio = (ATOM_GPIO_I2C_ASSIGMENT *)
  137. ((u8 *)gpio + sizeof(ATOM_GPIO_I2C_ASSIGMENT));
  138. }
  139. }
  140. return i2c;
  141. }
  142. void radeon_atombios_i2c_init(struct radeon_device *rdev)
  143. {
  144. struct atom_context *ctx = rdev->mode_info.atom_context;
  145. ATOM_GPIO_I2C_ASSIGMENT *gpio;
  146. struct radeon_i2c_bus_rec i2c;
  147. int index = GetIndexIntoMasterTable(DATA, GPIO_I2C_Info);
  148. struct _ATOM_GPIO_I2C_INFO *i2c_info;
  149. uint16_t data_offset, size;
  150. int i, num_indices;
  151. char stmp[32];
  152. if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
  153. i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
  154. num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
  155. sizeof(ATOM_GPIO_I2C_ASSIGMENT);
  156. gpio = &i2c_info->asGPIO_Info[0];
  157. for (i = 0; i < num_indices; i++) {
  158. radeon_lookup_i2c_gpio_quirks(rdev, gpio, i);
  159. i2c = radeon_get_bus_rec_for_i2c_gpio(gpio);
  160. if (i2c.valid) {
  161. sprintf(stmp, "0x%x", i2c.i2c_id);
  162. rdev->i2c_bus[i] = radeon_i2c_create(rdev->ddev, &i2c, stmp);
  163. }
  164. gpio = (ATOM_GPIO_I2C_ASSIGMENT *)
  165. ((u8 *)gpio + sizeof(ATOM_GPIO_I2C_ASSIGMENT));
  166. }
  167. }
  168. }
  169. static struct radeon_gpio_rec radeon_lookup_gpio(struct radeon_device *rdev,
  170. u8 id)
  171. {
  172. struct atom_context *ctx = rdev->mode_info.atom_context;
  173. struct radeon_gpio_rec gpio;
  174. int index = GetIndexIntoMasterTable(DATA, GPIO_Pin_LUT);
  175. struct _ATOM_GPIO_PIN_LUT *gpio_info;
  176. ATOM_GPIO_PIN_ASSIGNMENT *pin;
  177. u16 data_offset, size;
  178. int i, num_indices;
  179. memset(&gpio, 0, sizeof(struct radeon_gpio_rec));
  180. gpio.valid = false;
  181. if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
  182. gpio_info = (struct _ATOM_GPIO_PIN_LUT *)(ctx->bios + data_offset);
  183. num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
  184. sizeof(ATOM_GPIO_PIN_ASSIGNMENT);
  185. pin = gpio_info->asGPIO_Pin;
  186. for (i = 0; i < num_indices; i++) {
  187. if (id == pin->ucGPIO_ID) {
  188. gpio.id = pin->ucGPIO_ID;
  189. gpio.reg = le16_to_cpu(pin->usGpioPin_AIndex) * 4;
  190. gpio.mask = (1 << pin->ucGpioPinBitShift);
  191. gpio.valid = true;
  192. break;
  193. }
  194. pin = (ATOM_GPIO_PIN_ASSIGNMENT *)
  195. ((u8 *)pin + sizeof(ATOM_GPIO_PIN_ASSIGNMENT));
  196. }
  197. }
  198. return gpio;
  199. }
  200. static struct radeon_hpd radeon_atom_get_hpd_info_from_gpio(struct radeon_device *rdev,
  201. struct radeon_gpio_rec *gpio)
  202. {
  203. struct radeon_hpd hpd;
  204. u32 reg;
  205. memset(&hpd, 0, sizeof(struct radeon_hpd));
  206. if (ASIC_IS_DCE6(rdev))
  207. reg = SI_DC_GPIO_HPD_A;
  208. else if (ASIC_IS_DCE4(rdev))
  209. reg = EVERGREEN_DC_GPIO_HPD_A;
  210. else
  211. reg = AVIVO_DC_GPIO_HPD_A;
  212. hpd.gpio = *gpio;
  213. if (gpio->reg == reg) {
  214. switch(gpio->mask) {
  215. case (1 << 0):
  216. hpd.hpd = RADEON_HPD_1;
  217. break;
  218. case (1 << 8):
  219. hpd.hpd = RADEON_HPD_2;
  220. break;
  221. case (1 << 16):
  222. hpd.hpd = RADEON_HPD_3;
  223. break;
  224. case (1 << 24):
  225. hpd.hpd = RADEON_HPD_4;
  226. break;
  227. case (1 << 26):
  228. hpd.hpd = RADEON_HPD_5;
  229. break;
  230. case (1 << 28):
  231. hpd.hpd = RADEON_HPD_6;
  232. break;
  233. default:
  234. hpd.hpd = RADEON_HPD_NONE;
  235. break;
  236. }
  237. } else
  238. hpd.hpd = RADEON_HPD_NONE;
  239. return hpd;
  240. }
  241. static bool radeon_atom_apply_quirks(struct drm_device *dev,
  242. uint32_t supported_device,
  243. int *connector_type,
  244. struct radeon_i2c_bus_rec *i2c_bus,
  245. uint16_t *line_mux,
  246. struct radeon_hpd *hpd)
  247. {
  248. /* Asus M2A-VM HDMI board lists the DVI port as HDMI */
  249. if ((dev->pdev->device == 0x791e) &&
  250. (dev->pdev->subsystem_vendor == 0x1043) &&
  251. (dev->pdev->subsystem_device == 0x826d)) {
  252. if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
  253. (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
  254. *connector_type = DRM_MODE_CONNECTOR_DVID;
  255. }
  256. /* Asrock RS600 board lists the DVI port as HDMI */
  257. if ((dev->pdev->device == 0x7941) &&
  258. (dev->pdev->subsystem_vendor == 0x1849) &&
  259. (dev->pdev->subsystem_device == 0x7941)) {
  260. if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) &&
  261. (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
  262. *connector_type = DRM_MODE_CONNECTOR_DVID;
  263. }
  264. /* MSI K9A2GM V2/V3 board has no HDMI or DVI */
  265. if ((dev->pdev->device == 0x796e) &&
  266. (dev->pdev->subsystem_vendor == 0x1462) &&
  267. (dev->pdev->subsystem_device == 0x7302)) {
  268. if ((supported_device == ATOM_DEVICE_DFP2_SUPPORT) ||
  269. (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
  270. return false;
  271. }
  272. /* a-bit f-i90hd - ciaranm on #radeonhd - this board has no DVI */
  273. if ((dev->pdev->device == 0x7941) &&
  274. (dev->pdev->subsystem_vendor == 0x147b) &&
  275. (dev->pdev->subsystem_device == 0x2412)) {
  276. if (*connector_type == DRM_MODE_CONNECTOR_DVII)
  277. return false;
  278. }
  279. /* Falcon NW laptop lists vga ddc line for LVDS */
  280. if ((dev->pdev->device == 0x5653) &&
  281. (dev->pdev->subsystem_vendor == 0x1462) &&
  282. (dev->pdev->subsystem_device == 0x0291)) {
  283. if (*connector_type == DRM_MODE_CONNECTOR_LVDS) {
  284. i2c_bus->valid = false;
  285. *line_mux = 53;
  286. }
  287. }
  288. /* HIS X1300 is DVI+VGA, not DVI+DVI */
  289. if ((dev->pdev->device == 0x7146) &&
  290. (dev->pdev->subsystem_vendor == 0x17af) &&
  291. (dev->pdev->subsystem_device == 0x2058)) {
  292. if (supported_device == ATOM_DEVICE_DFP1_SUPPORT)
  293. return false;
  294. }
  295. /* Gigabyte X1300 is DVI+VGA, not DVI+DVI */
  296. if ((dev->pdev->device == 0x7142) &&
  297. (dev->pdev->subsystem_vendor == 0x1458) &&
  298. (dev->pdev->subsystem_device == 0x2134)) {
  299. if (supported_device == ATOM_DEVICE_DFP1_SUPPORT)
  300. return false;
  301. }
  302. /* Funky macbooks */
  303. if ((dev->pdev->device == 0x71C5) &&
  304. (dev->pdev->subsystem_vendor == 0x106b) &&
  305. (dev->pdev->subsystem_device == 0x0080)) {
  306. if ((supported_device == ATOM_DEVICE_CRT1_SUPPORT) ||
  307. (supported_device == ATOM_DEVICE_DFP2_SUPPORT))
  308. return false;
  309. if (supported_device == ATOM_DEVICE_CRT2_SUPPORT)
  310. *line_mux = 0x90;
  311. }
  312. /* mac rv630, rv730, others */
  313. if ((supported_device == ATOM_DEVICE_TV1_SUPPORT) &&
  314. (*connector_type == DRM_MODE_CONNECTOR_DVII)) {
  315. *connector_type = DRM_MODE_CONNECTOR_9PinDIN;
  316. *line_mux = CONNECTOR_7PIN_DIN_ENUM_ID1;
  317. }
  318. /* ASUS HD 3600 XT board lists the DVI port as HDMI */
  319. if ((dev->pdev->device == 0x9598) &&
  320. (dev->pdev->subsystem_vendor == 0x1043) &&
  321. (dev->pdev->subsystem_device == 0x01da)) {
  322. if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
  323. *connector_type = DRM_MODE_CONNECTOR_DVII;
  324. }
  325. }
  326. /* ASUS HD 3600 board lists the DVI port as HDMI */
  327. if ((dev->pdev->device == 0x9598) &&
  328. (dev->pdev->subsystem_vendor == 0x1043) &&
  329. (dev->pdev->subsystem_device == 0x01e4)) {
  330. if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
  331. *connector_type = DRM_MODE_CONNECTOR_DVII;
  332. }
  333. }
  334. /* ASUS HD 3450 board lists the DVI port as HDMI */
  335. if ((dev->pdev->device == 0x95C5) &&
  336. (dev->pdev->subsystem_vendor == 0x1043) &&
  337. (dev->pdev->subsystem_device == 0x01e2)) {
  338. if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
  339. *connector_type = DRM_MODE_CONNECTOR_DVII;
  340. }
  341. }
  342. /* some BIOSes seem to report DAC on HDMI - usually this is a board with
  343. * HDMI + VGA reporting as HDMI
  344. */
  345. if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) {
  346. if (supported_device & (ATOM_DEVICE_CRT_SUPPORT)) {
  347. *connector_type = DRM_MODE_CONNECTOR_VGA;
  348. *line_mux = 0;
  349. }
  350. }
  351. /* Acer laptop (Acer TravelMate 5730/5730G) has an HDMI port
  352. * on the laptop and a DVI port on the docking station and
  353. * both share the same encoder, hpd pin, and ddc line.
  354. * So while the bios table is technically correct,
  355. * we drop the DVI port here since xrandr has no concept of
  356. * encoders and will try and drive both connectors
  357. * with different crtcs which isn't possible on the hardware
  358. * side and leaves no crtcs for LVDS or VGA.
  359. */
  360. if (((dev->pdev->device == 0x95c4) || (dev->pdev->device == 0x9591)) &&
  361. (dev->pdev->subsystem_vendor == 0x1025) &&
  362. (dev->pdev->subsystem_device == 0x013c)) {
  363. if ((*connector_type == DRM_MODE_CONNECTOR_DVII) &&
  364. (supported_device == ATOM_DEVICE_DFP1_SUPPORT)) {
  365. /* actually it's a DVI-D port not DVI-I */
  366. *connector_type = DRM_MODE_CONNECTOR_DVID;
  367. return false;
  368. }
  369. }
  370. /* XFX Pine Group device rv730 reports no VGA DDC lines
  371. * even though they are wired up to record 0x93
  372. */
  373. if ((dev->pdev->device == 0x9498) &&
  374. (dev->pdev->subsystem_vendor == 0x1682) &&
  375. (dev->pdev->subsystem_device == 0x2452) &&
  376. (i2c_bus->valid == false) &&
  377. !(supported_device & (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT))) {
  378. struct radeon_device *rdev = dev->dev_private;
  379. *i2c_bus = radeon_lookup_i2c_gpio(rdev, 0x93);
  380. }
  381. /* Fujitsu D3003-S2 board lists DVI-I as DVI-D and VGA */
  382. if (((dev->pdev->device == 0x9802) || (dev->pdev->device == 0x9806)) &&
  383. (dev->pdev->subsystem_vendor == 0x1734) &&
  384. (dev->pdev->subsystem_device == 0x11bd)) {
  385. if (*connector_type == DRM_MODE_CONNECTOR_VGA) {
  386. *connector_type = DRM_MODE_CONNECTOR_DVII;
  387. *line_mux = 0x3103;
  388. } else if (*connector_type == DRM_MODE_CONNECTOR_DVID) {
  389. *connector_type = DRM_MODE_CONNECTOR_DVII;
  390. }
  391. }
  392. /* Fujitsu D3003-S2 board lists DVI-I as DVI-I and VGA */
  393. if ((dev->pdev->device == 0x9805) &&
  394. (dev->pdev->subsystem_vendor == 0x1734) &&
  395. (dev->pdev->subsystem_device == 0x11bd)) {
  396. if (*connector_type == DRM_MODE_CONNECTOR_VGA)
  397. return false;
  398. }
  399. return true;
  400. }
  401. static const int supported_devices_connector_convert[] = {
  402. DRM_MODE_CONNECTOR_Unknown,
  403. DRM_MODE_CONNECTOR_VGA,
  404. DRM_MODE_CONNECTOR_DVII,
  405. DRM_MODE_CONNECTOR_DVID,
  406. DRM_MODE_CONNECTOR_DVIA,
  407. DRM_MODE_CONNECTOR_SVIDEO,
  408. DRM_MODE_CONNECTOR_Composite,
  409. DRM_MODE_CONNECTOR_LVDS,
  410. DRM_MODE_CONNECTOR_Unknown,
  411. DRM_MODE_CONNECTOR_Unknown,
  412. DRM_MODE_CONNECTOR_HDMIA,
  413. DRM_MODE_CONNECTOR_HDMIB,
  414. DRM_MODE_CONNECTOR_Unknown,
  415. DRM_MODE_CONNECTOR_Unknown,
  416. DRM_MODE_CONNECTOR_9PinDIN,
  417. DRM_MODE_CONNECTOR_DisplayPort
  418. };
  419. static const uint16_t supported_devices_connector_object_id_convert[] = {
  420. CONNECTOR_OBJECT_ID_NONE,
  421. CONNECTOR_OBJECT_ID_VGA,
  422. CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I, /* not all boards support DL */
  423. CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D, /* not all boards support DL */
  424. CONNECTOR_OBJECT_ID_VGA, /* technically DVI-A */
  425. CONNECTOR_OBJECT_ID_COMPOSITE,
  426. CONNECTOR_OBJECT_ID_SVIDEO,
  427. CONNECTOR_OBJECT_ID_LVDS,
  428. CONNECTOR_OBJECT_ID_9PIN_DIN,
  429. CONNECTOR_OBJECT_ID_9PIN_DIN,
  430. CONNECTOR_OBJECT_ID_DISPLAYPORT,
  431. CONNECTOR_OBJECT_ID_HDMI_TYPE_A,
  432. CONNECTOR_OBJECT_ID_HDMI_TYPE_B,
  433. CONNECTOR_OBJECT_ID_SVIDEO
  434. };
  435. static const int object_connector_convert[] = {
  436. DRM_MODE_CONNECTOR_Unknown,
  437. DRM_MODE_CONNECTOR_DVII,
  438. DRM_MODE_CONNECTOR_DVII,
  439. DRM_MODE_CONNECTOR_DVID,
  440. DRM_MODE_CONNECTOR_DVID,
  441. DRM_MODE_CONNECTOR_VGA,
  442. DRM_MODE_CONNECTOR_Composite,
  443. DRM_MODE_CONNECTOR_SVIDEO,
  444. DRM_MODE_CONNECTOR_Unknown,
  445. DRM_MODE_CONNECTOR_Unknown,
  446. DRM_MODE_CONNECTOR_9PinDIN,
  447. DRM_MODE_CONNECTOR_Unknown,
  448. DRM_MODE_CONNECTOR_HDMIA,
  449. DRM_MODE_CONNECTOR_HDMIB,
  450. DRM_MODE_CONNECTOR_LVDS,
  451. DRM_MODE_CONNECTOR_9PinDIN,
  452. DRM_MODE_CONNECTOR_Unknown,
  453. DRM_MODE_CONNECTOR_Unknown,
  454. DRM_MODE_CONNECTOR_Unknown,
  455. DRM_MODE_CONNECTOR_DisplayPort,
  456. DRM_MODE_CONNECTOR_eDP,
  457. DRM_MODE_CONNECTOR_Unknown
  458. };
  459. bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
  460. {
  461. struct radeon_device *rdev = dev->dev_private;
  462. struct radeon_mode_info *mode_info = &rdev->mode_info;
  463. struct atom_context *ctx = mode_info->atom_context;
  464. int index = GetIndexIntoMasterTable(DATA, Object_Header);
  465. u16 size, data_offset;
  466. u8 frev, crev;
  467. ATOM_CONNECTOR_OBJECT_TABLE *con_obj;
  468. ATOM_ENCODER_OBJECT_TABLE *enc_obj;
  469. ATOM_OBJECT_TABLE *router_obj;
  470. ATOM_DISPLAY_OBJECT_PATH_TABLE *path_obj;
  471. ATOM_OBJECT_HEADER *obj_header;
  472. int i, j, k, path_size, device_support;
  473. int connector_type;
  474. u16 igp_lane_info, conn_id, connector_object_id;
  475. struct radeon_i2c_bus_rec ddc_bus;
  476. struct radeon_router router;
  477. struct radeon_gpio_rec gpio;
  478. struct radeon_hpd hpd;
  479. if (!atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset))
  480. return false;
  481. if (crev < 2)
  482. return false;
  483. obj_header = (ATOM_OBJECT_HEADER *) (ctx->bios + data_offset);
  484. path_obj = (ATOM_DISPLAY_OBJECT_PATH_TABLE *)
  485. (ctx->bios + data_offset +
  486. le16_to_cpu(obj_header->usDisplayPathTableOffset));
  487. con_obj = (ATOM_CONNECTOR_OBJECT_TABLE *)
  488. (ctx->bios + data_offset +
  489. le16_to_cpu(obj_header->usConnectorObjectTableOffset));
  490. enc_obj = (ATOM_ENCODER_OBJECT_TABLE *)
  491. (ctx->bios + data_offset +
  492. le16_to_cpu(obj_header->usEncoderObjectTableOffset));
  493. router_obj = (ATOM_OBJECT_TABLE *)
  494. (ctx->bios + data_offset +
  495. le16_to_cpu(obj_header->usRouterObjectTableOffset));
  496. device_support = le16_to_cpu(obj_header->usDeviceSupport);
  497. path_size = 0;
  498. for (i = 0; i < path_obj->ucNumOfDispPath; i++) {
  499. uint8_t *addr = (uint8_t *) path_obj->asDispPath;
  500. ATOM_DISPLAY_OBJECT_PATH *path;
  501. addr += path_size;
  502. path = (ATOM_DISPLAY_OBJECT_PATH *) addr;
  503. path_size += le16_to_cpu(path->usSize);
  504. if (device_support & le16_to_cpu(path->usDeviceTag)) {
  505. uint8_t con_obj_id, con_obj_num, con_obj_type;
  506. con_obj_id =
  507. (le16_to_cpu(path->usConnObjectId) & OBJECT_ID_MASK)
  508. >> OBJECT_ID_SHIFT;
  509. con_obj_num =
  510. (le16_to_cpu(path->usConnObjectId) & ENUM_ID_MASK)
  511. >> ENUM_ID_SHIFT;
  512. con_obj_type =
  513. (le16_to_cpu(path->usConnObjectId) &
  514. OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
  515. /* TODO CV support */
  516. if (le16_to_cpu(path->usDeviceTag) ==
  517. ATOM_DEVICE_CV_SUPPORT)
  518. continue;
  519. /* IGP chips */
  520. if ((rdev->flags & RADEON_IS_IGP) &&
  521. (con_obj_id ==
  522. CONNECTOR_OBJECT_ID_PCIE_CONNECTOR)) {
  523. uint16_t igp_offset = 0;
  524. ATOM_INTEGRATED_SYSTEM_INFO_V2 *igp_obj;
  525. index =
  526. GetIndexIntoMasterTable(DATA,
  527. IntegratedSystemInfo);
  528. if (atom_parse_data_header(ctx, index, &size, &frev,
  529. &crev, &igp_offset)) {
  530. if (crev >= 2) {
  531. igp_obj =
  532. (ATOM_INTEGRATED_SYSTEM_INFO_V2
  533. *) (ctx->bios + igp_offset);
  534. if (igp_obj) {
  535. uint32_t slot_config, ct;
  536. if (con_obj_num == 1)
  537. slot_config =
  538. igp_obj->
  539. ulDDISlot1Config;
  540. else
  541. slot_config =
  542. igp_obj->
  543. ulDDISlot2Config;
  544. ct = (slot_config >> 16) & 0xff;
  545. connector_type =
  546. object_connector_convert
  547. [ct];
  548. connector_object_id = ct;
  549. igp_lane_info =
  550. slot_config & 0xffff;
  551. } else
  552. continue;
  553. } else
  554. continue;
  555. } else {
  556. igp_lane_info = 0;
  557. connector_type =
  558. object_connector_convert[con_obj_id];
  559. connector_object_id = con_obj_id;
  560. }
  561. } else {
  562. igp_lane_info = 0;
  563. connector_type =
  564. object_connector_convert[con_obj_id];
  565. connector_object_id = con_obj_id;
  566. }
  567. if (connector_type == DRM_MODE_CONNECTOR_Unknown)
  568. continue;
  569. router.ddc_valid = false;
  570. router.cd_valid = false;
  571. for (j = 0; j < ((le16_to_cpu(path->usSize) - 8) / 2); j++) {
  572. uint8_t grph_obj_id, grph_obj_num, grph_obj_type;
  573. grph_obj_id =
  574. (le16_to_cpu(path->usGraphicObjIds[j]) &
  575. OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
  576. grph_obj_num =
  577. (le16_to_cpu(path->usGraphicObjIds[j]) &
  578. ENUM_ID_MASK) >> ENUM_ID_SHIFT;
  579. grph_obj_type =
  580. (le16_to_cpu(path->usGraphicObjIds[j]) &
  581. OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
  582. if (grph_obj_type == GRAPH_OBJECT_TYPE_ENCODER) {
  583. for (k = 0; k < enc_obj->ucNumberOfObjects; k++) {
  584. u16 encoder_obj = le16_to_cpu(enc_obj->asObjects[k].usObjectID);
  585. if (le16_to_cpu(path->usGraphicObjIds[j]) == encoder_obj) {
  586. ATOM_COMMON_RECORD_HEADER *record = (ATOM_COMMON_RECORD_HEADER *)
  587. (ctx->bios + data_offset +
  588. le16_to_cpu(enc_obj->asObjects[k].usRecordOffset));
  589. ATOM_ENCODER_CAP_RECORD *cap_record;
  590. u16 caps = 0;
  591. while (record->ucRecordSize > 0 &&
  592. record->ucRecordType > 0 &&
  593. record->ucRecordType <= ATOM_MAX_OBJECT_RECORD_NUMBER) {
  594. switch (record->ucRecordType) {
  595. case ATOM_ENCODER_CAP_RECORD_TYPE:
  596. cap_record =(ATOM_ENCODER_CAP_RECORD *)
  597. record;
  598. caps = le16_to_cpu(cap_record->usEncoderCap);
  599. break;
  600. }
  601. record = (ATOM_COMMON_RECORD_HEADER *)
  602. ((char *)record + record->ucRecordSize);
  603. }
  604. radeon_add_atom_encoder(dev,
  605. encoder_obj,
  606. le16_to_cpu
  607. (path->
  608. usDeviceTag),
  609. caps);
  610. }
  611. }
  612. } else if (grph_obj_type == GRAPH_OBJECT_TYPE_ROUTER) {
  613. for (k = 0; k < router_obj->ucNumberOfObjects; k++) {
  614. u16 router_obj_id = le16_to_cpu(router_obj->asObjects[k].usObjectID);
  615. if (le16_to_cpu(path->usGraphicObjIds[j]) == router_obj_id) {
  616. ATOM_COMMON_RECORD_HEADER *record = (ATOM_COMMON_RECORD_HEADER *)
  617. (ctx->bios + data_offset +
  618. le16_to_cpu(router_obj->asObjects[k].usRecordOffset));
  619. ATOM_I2C_RECORD *i2c_record;
  620. ATOM_I2C_ID_CONFIG_ACCESS *i2c_config;
  621. ATOM_ROUTER_DDC_PATH_SELECT_RECORD *ddc_path;
  622. ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD *cd_path;
  623. ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *router_src_dst_table =
  624. (ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *)
  625. (ctx->bios + data_offset +
  626. le16_to_cpu(router_obj->asObjects[k].usSrcDstTableOffset));
  627. u8 *num_dst_objs = (u8 *)
  628. ((u8 *)router_src_dst_table + 1 +
  629. (router_src_dst_table->ucNumberOfSrc * 2));
  630. u16 *dst_objs = (u16 *)(num_dst_objs + 1);
  631. int enum_id;
  632. router.router_id = router_obj_id;
  633. for (enum_id = 0; enum_id < (*num_dst_objs); enum_id++) {
  634. if (le16_to_cpu(path->usConnObjectId) ==
  635. le16_to_cpu(dst_objs[enum_id]))
  636. break;
  637. }
  638. while (record->ucRecordSize > 0 &&
  639. record->ucRecordType > 0 &&
  640. record->ucRecordType <= ATOM_MAX_OBJECT_RECORD_NUMBER) {
  641. switch (record->ucRecordType) {
  642. case ATOM_I2C_RECORD_TYPE:
  643. i2c_record =
  644. (ATOM_I2C_RECORD *)
  645. record;
  646. i2c_config =
  647. (ATOM_I2C_ID_CONFIG_ACCESS *)
  648. &i2c_record->sucI2cId;
  649. router.i2c_info =
  650. radeon_lookup_i2c_gpio(rdev,
  651. i2c_config->
  652. ucAccess);
  653. router.i2c_addr = i2c_record->ucI2CAddr >> 1;
  654. break;
  655. case ATOM_ROUTER_DDC_PATH_SELECT_RECORD_TYPE:
  656. ddc_path = (ATOM_ROUTER_DDC_PATH_SELECT_RECORD *)
  657. record;
  658. router.ddc_valid = true;
  659. router.ddc_mux_type = ddc_path->ucMuxType;
  660. router.ddc_mux_control_pin = ddc_path->ucMuxControlPin;
  661. router.ddc_mux_state = ddc_path->ucMuxState[enum_id];
  662. break;
  663. case ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD_TYPE:
  664. cd_path = (ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD *)
  665. record;
  666. router.cd_valid = true;
  667. router.cd_mux_type = cd_path->ucMuxType;
  668. router.cd_mux_control_pin = cd_path->ucMuxControlPin;
  669. router.cd_mux_state = cd_path->ucMuxState[enum_id];
  670. break;
  671. }
  672. record = (ATOM_COMMON_RECORD_HEADER *)
  673. ((char *)record + record->ucRecordSize);
  674. }
  675. }
  676. }
  677. }
  678. }
  679. /* look up gpio for ddc, hpd */
  680. ddc_bus.valid = false;
  681. hpd.hpd = RADEON_HPD_NONE;
  682. if ((le16_to_cpu(path->usDeviceTag) &
  683. (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT)) == 0) {
  684. for (j = 0; j < con_obj->ucNumberOfObjects; j++) {
  685. if (le16_to_cpu(path->usConnObjectId) ==
  686. le16_to_cpu(con_obj->asObjects[j].
  687. usObjectID)) {
  688. ATOM_COMMON_RECORD_HEADER
  689. *record =
  690. (ATOM_COMMON_RECORD_HEADER
  691. *)
  692. (ctx->bios + data_offset +
  693. le16_to_cpu(con_obj->
  694. asObjects[j].
  695. usRecordOffset));
  696. ATOM_I2C_RECORD *i2c_record;
  697. ATOM_HPD_INT_RECORD *hpd_record;
  698. ATOM_I2C_ID_CONFIG_ACCESS *i2c_config;
  699. while (record->ucRecordSize > 0 &&
  700. record->ucRecordType > 0 &&
  701. record->ucRecordType <= ATOM_MAX_OBJECT_RECORD_NUMBER) {
  702. switch (record->ucRecordType) {
  703. case ATOM_I2C_RECORD_TYPE:
  704. i2c_record =
  705. (ATOM_I2C_RECORD *)
  706. record;
  707. i2c_config =
  708. (ATOM_I2C_ID_CONFIG_ACCESS *)
  709. &i2c_record->sucI2cId;
  710. ddc_bus = radeon_lookup_i2c_gpio(rdev,
  711. i2c_config->
  712. ucAccess);
  713. break;
  714. case ATOM_HPD_INT_RECORD_TYPE:
  715. hpd_record =
  716. (ATOM_HPD_INT_RECORD *)
  717. record;
  718. gpio = radeon_lookup_gpio(rdev,
  719. hpd_record->ucHPDIntGPIOID);
  720. hpd = radeon_atom_get_hpd_info_from_gpio(rdev, &gpio);
  721. hpd.plugged_state = hpd_record->ucPlugged_PinState;
  722. break;
  723. }
  724. record =
  725. (ATOM_COMMON_RECORD_HEADER
  726. *) ((char *)record
  727. +
  728. record->
  729. ucRecordSize);
  730. }
  731. break;
  732. }
  733. }
  734. }
  735. /* needed for aux chan transactions */
  736. ddc_bus.hpd = hpd.hpd;
  737. conn_id = le16_to_cpu(path->usConnObjectId);
  738. if (!radeon_atom_apply_quirks
  739. (dev, le16_to_cpu(path->usDeviceTag), &connector_type,
  740. &ddc_bus, &conn_id, &hpd))
  741. continue;
  742. radeon_add_atom_connector(dev,
  743. conn_id,
  744. le16_to_cpu(path->
  745. usDeviceTag),
  746. connector_type, &ddc_bus,
  747. igp_lane_info,
  748. connector_object_id,
  749. &hpd,
  750. &router);
  751. }
  752. }
  753. radeon_link_encoder_connector(dev);
  754. return true;
  755. }
  756. static uint16_t atombios_get_connector_object_id(struct drm_device *dev,
  757. int connector_type,
  758. uint16_t devices)
  759. {
  760. struct radeon_device *rdev = dev->dev_private;
  761. if (rdev->flags & RADEON_IS_IGP) {
  762. return supported_devices_connector_object_id_convert
  763. [connector_type];
  764. } else if (((connector_type == DRM_MODE_CONNECTOR_DVII) ||
  765. (connector_type == DRM_MODE_CONNECTOR_DVID)) &&
  766. (devices & ATOM_DEVICE_DFP2_SUPPORT)) {
  767. struct radeon_mode_info *mode_info = &rdev->mode_info;
  768. struct atom_context *ctx = mode_info->atom_context;
  769. int index = GetIndexIntoMasterTable(DATA, XTMDS_Info);
  770. uint16_t size, data_offset;
  771. uint8_t frev, crev;
  772. ATOM_XTMDS_INFO *xtmds;
  773. if (atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset)) {
  774. xtmds = (ATOM_XTMDS_INFO *)(ctx->bios + data_offset);
  775. if (xtmds->ucSupportedLink & ATOM_XTMDS_SUPPORTED_DUALLINK) {
  776. if (connector_type == DRM_MODE_CONNECTOR_DVII)
  777. return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I;
  778. else
  779. return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D;
  780. } else {
  781. if (connector_type == DRM_MODE_CONNECTOR_DVII)
  782. return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I;
  783. else
  784. return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D;
  785. }
  786. } else
  787. return supported_devices_connector_object_id_convert
  788. [connector_type];
  789. } else {
  790. return supported_devices_connector_object_id_convert
  791. [connector_type];
  792. }
  793. }
  794. struct bios_connector {
  795. bool valid;
  796. uint16_t line_mux;
  797. uint16_t devices;
  798. int connector_type;
  799. struct radeon_i2c_bus_rec ddc_bus;
  800. struct radeon_hpd hpd;
  801. };
  802. bool radeon_get_atom_connector_info_from_supported_devices_table(struct
  803. drm_device
  804. *dev)
  805. {
  806. struct radeon_device *rdev = dev->dev_private;
  807. struct radeon_mode_info *mode_info = &rdev->mode_info;
  808. struct atom_context *ctx = mode_info->atom_context;
  809. int index = GetIndexIntoMasterTable(DATA, SupportedDevicesInfo);
  810. uint16_t size, data_offset;
  811. uint8_t frev, crev;
  812. uint16_t device_support;
  813. uint8_t dac;
  814. union atom_supported_devices *supported_devices;
  815. int i, j, max_device;
  816. struct bios_connector *bios_connectors;
  817. size_t bc_size = sizeof(*bios_connectors) * ATOM_MAX_SUPPORTED_DEVICE;
  818. struct radeon_router router;
  819. router.ddc_valid = false;
  820. router.cd_valid = false;
  821. bios_connectors = kzalloc(bc_size, GFP_KERNEL);
  822. if (!bios_connectors)
  823. return false;
  824. if (!atom_parse_data_header(ctx, index, &size, &frev, &crev,
  825. &data_offset)) {
  826. kfree(bios_connectors);
  827. return false;
  828. }
  829. supported_devices =
  830. (union atom_supported_devices *)(ctx->bios + data_offset);
  831. device_support = le16_to_cpu(supported_devices->info.usDeviceSupport);
  832. if (frev > 1)
  833. max_device = ATOM_MAX_SUPPORTED_DEVICE;
  834. else
  835. max_device = ATOM_MAX_SUPPORTED_DEVICE_INFO;
  836. for (i = 0; i < max_device; i++) {
  837. ATOM_CONNECTOR_INFO_I2C ci =
  838. supported_devices->info.asConnInfo[i];
  839. bios_connectors[i].valid = false;
  840. if (!(device_support & (1 << i))) {
  841. continue;
  842. }
  843. if (i == ATOM_DEVICE_CV_INDEX) {
  844. DRM_DEBUG_KMS("Skipping Component Video\n");
  845. continue;
  846. }
  847. bios_connectors[i].connector_type =
  848. supported_devices_connector_convert[ci.sucConnectorInfo.
  849. sbfAccess.
  850. bfConnectorType];
  851. if (bios_connectors[i].connector_type ==
  852. DRM_MODE_CONNECTOR_Unknown)
  853. continue;
  854. dac = ci.sucConnectorInfo.sbfAccess.bfAssociatedDAC;
  855. bios_connectors[i].line_mux =
  856. ci.sucI2cId.ucAccess;
  857. /* give tv unique connector ids */
  858. if (i == ATOM_DEVICE_TV1_INDEX) {
  859. bios_connectors[i].ddc_bus.valid = false;
  860. bios_connectors[i].line_mux = 50;
  861. } else if (i == ATOM_DEVICE_TV2_INDEX) {
  862. bios_connectors[i].ddc_bus.valid = false;
  863. bios_connectors[i].line_mux = 51;
  864. } else if (i == ATOM_DEVICE_CV_INDEX) {
  865. bios_connectors[i].ddc_bus.valid = false;
  866. bios_connectors[i].line_mux = 52;
  867. } else
  868. bios_connectors[i].ddc_bus =
  869. radeon_lookup_i2c_gpio(rdev,
  870. bios_connectors[i].line_mux);
  871. if ((crev > 1) && (frev > 1)) {
  872. u8 isb = supported_devices->info_2d1.asIntSrcInfo[i].ucIntSrcBitmap;
  873. switch (isb) {
  874. case 0x4:
  875. bios_connectors[i].hpd.hpd = RADEON_HPD_1;
  876. break;
  877. case 0xa:
  878. bios_connectors[i].hpd.hpd = RADEON_HPD_2;
  879. break;
  880. default:
  881. bios_connectors[i].hpd.hpd = RADEON_HPD_NONE;
  882. break;
  883. }
  884. } else {
  885. if (i == ATOM_DEVICE_DFP1_INDEX)
  886. bios_connectors[i].hpd.hpd = RADEON_HPD_1;
  887. else if (i == ATOM_DEVICE_DFP2_INDEX)
  888. bios_connectors[i].hpd.hpd = RADEON_HPD_2;
  889. else
  890. bios_connectors[i].hpd.hpd = RADEON_HPD_NONE;
  891. }
  892. /* Always set the connector type to VGA for CRT1/CRT2. if they are
  893. * shared with a DVI port, we'll pick up the DVI connector when we
  894. * merge the outputs. Some bioses incorrectly list VGA ports as DVI.
  895. */
  896. if (i == ATOM_DEVICE_CRT1_INDEX || i == ATOM_DEVICE_CRT2_INDEX)
  897. bios_connectors[i].connector_type =
  898. DRM_MODE_CONNECTOR_VGA;
  899. if (!radeon_atom_apply_quirks
  900. (dev, (1 << i), &bios_connectors[i].connector_type,
  901. &bios_connectors[i].ddc_bus, &bios_connectors[i].line_mux,
  902. &bios_connectors[i].hpd))
  903. continue;
  904. bios_connectors[i].valid = true;
  905. bios_connectors[i].devices = (1 << i);
  906. if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom)
  907. radeon_add_atom_encoder(dev,
  908. radeon_get_encoder_enum(dev,
  909. (1 << i),
  910. dac),
  911. (1 << i),
  912. 0);
  913. else
  914. radeon_add_legacy_encoder(dev,
  915. radeon_get_encoder_enum(dev,
  916. (1 << i),
  917. dac),
  918. (1 << i));
  919. }
  920. /* combine shared connectors */
  921. for (i = 0; i < max_device; i++) {
  922. if (bios_connectors[i].valid) {
  923. for (j = 0; j < max_device; j++) {
  924. if (bios_connectors[j].valid && (i != j)) {
  925. if (bios_connectors[i].line_mux ==
  926. bios_connectors[j].line_mux) {
  927. /* make sure not to combine LVDS */
  928. if (bios_connectors[i].devices & (ATOM_DEVICE_LCD_SUPPORT)) {
  929. bios_connectors[i].line_mux = 53;
  930. bios_connectors[i].ddc_bus.valid = false;
  931. continue;
  932. }
  933. if (bios_connectors[j].devices & (ATOM_DEVICE_LCD_SUPPORT)) {
  934. bios_connectors[j].line_mux = 53;
  935. bios_connectors[j].ddc_bus.valid = false;
  936. continue;
  937. }
  938. /* combine analog and digital for DVI-I */
  939. if (((bios_connectors[i].devices & (ATOM_DEVICE_DFP_SUPPORT)) &&
  940. (bios_connectors[j].devices & (ATOM_DEVICE_CRT_SUPPORT))) ||
  941. ((bios_connectors[j].devices & (ATOM_DEVICE_DFP_SUPPORT)) &&
  942. (bios_connectors[i].devices & (ATOM_DEVICE_CRT_SUPPORT)))) {
  943. bios_connectors[i].devices |=
  944. bios_connectors[j].devices;
  945. bios_connectors[i].connector_type =
  946. DRM_MODE_CONNECTOR_DVII;
  947. if (bios_connectors[j].devices & (ATOM_DEVICE_DFP_SUPPORT))
  948. bios_connectors[i].hpd =
  949. bios_connectors[j].hpd;
  950. bios_connectors[j].valid = false;
  951. }
  952. }
  953. }
  954. }
  955. }
  956. }
  957. /* add the connectors */
  958. for (i = 0; i < max_device; i++) {
  959. if (bios_connectors[i].valid) {
  960. uint16_t connector_object_id =
  961. atombios_get_connector_object_id(dev,
  962. bios_connectors[i].connector_type,
  963. bios_connectors[i].devices);
  964. radeon_add_atom_connector(dev,
  965. bios_connectors[i].line_mux,
  966. bios_connectors[i].devices,
  967. bios_connectors[i].
  968. connector_type,
  969. &bios_connectors[i].ddc_bus,
  970. 0,
  971. connector_object_id,
  972. &bios_connectors[i].hpd,
  973. &router);
  974. }
  975. }
  976. radeon_link_encoder_connector(dev);
  977. kfree(bios_connectors);
  978. return true;
  979. }
  980. union firmware_info {
  981. ATOM_FIRMWARE_INFO info;
  982. ATOM_FIRMWARE_INFO_V1_2 info_12;
  983. ATOM_FIRMWARE_INFO_V1_3 info_13;
  984. ATOM_FIRMWARE_INFO_V1_4 info_14;
  985. ATOM_FIRMWARE_INFO_V2_1 info_21;
  986. ATOM_FIRMWARE_INFO_V2_2 info_22;
  987. };
  988. bool radeon_atom_get_clock_info(struct drm_device *dev)
  989. {
  990. struct radeon_device *rdev = dev->dev_private;
  991. struct radeon_mode_info *mode_info = &rdev->mode_info;
  992. int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
  993. union firmware_info *firmware_info;
  994. uint8_t frev, crev;
  995. struct radeon_pll *p1pll = &rdev->clock.p1pll;
  996. struct radeon_pll *p2pll = &rdev->clock.p2pll;
  997. struct radeon_pll *dcpll = &rdev->clock.dcpll;
  998. struct radeon_pll *spll = &rdev->clock.spll;
  999. struct radeon_pll *mpll = &rdev->clock.mpll;
  1000. uint16_t data_offset;
  1001. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1002. &frev, &crev, &data_offset)) {
  1003. firmware_info =
  1004. (union firmware_info *)(mode_info->atom_context->bios +
  1005. data_offset);
  1006. /* pixel clocks */
  1007. p1pll->reference_freq =
  1008. le16_to_cpu(firmware_info->info.usReferenceClock);
  1009. p1pll->reference_div = 0;
  1010. if (crev < 2)
  1011. p1pll->pll_out_min =
  1012. le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Output);
  1013. else
  1014. p1pll->pll_out_min =
  1015. le32_to_cpu(firmware_info->info_12.ulMinPixelClockPLL_Output);
  1016. p1pll->pll_out_max =
  1017. le32_to_cpu(firmware_info->info.ulMaxPixelClockPLL_Output);
  1018. if (crev >= 4) {
  1019. p1pll->lcd_pll_out_min =
  1020. le16_to_cpu(firmware_info->info_14.usLcdMinPixelClockPLL_Output) * 100;
  1021. if (p1pll->lcd_pll_out_min == 0)
  1022. p1pll->lcd_pll_out_min = p1pll->pll_out_min;
  1023. p1pll->lcd_pll_out_max =
  1024. le16_to_cpu(firmware_info->info_14.usLcdMaxPixelClockPLL_Output) * 100;
  1025. if (p1pll->lcd_pll_out_max == 0)
  1026. p1pll->lcd_pll_out_max = p1pll->pll_out_max;
  1027. } else {
  1028. p1pll->lcd_pll_out_min = p1pll->pll_out_min;
  1029. p1pll->lcd_pll_out_max = p1pll->pll_out_max;
  1030. }
  1031. if (p1pll->pll_out_min == 0) {
  1032. if (ASIC_IS_AVIVO(rdev))
  1033. p1pll->pll_out_min = 64800;
  1034. else
  1035. p1pll->pll_out_min = 20000;
  1036. }
  1037. p1pll->pll_in_min =
  1038. le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Input);
  1039. p1pll->pll_in_max =
  1040. le16_to_cpu(firmware_info->info.usMaxPixelClockPLL_Input);
  1041. *p2pll = *p1pll;
  1042. /* system clock */
  1043. if (ASIC_IS_DCE4(rdev))
  1044. spll->reference_freq =
  1045. le16_to_cpu(firmware_info->info_21.usCoreReferenceClock);
  1046. else
  1047. spll->reference_freq =
  1048. le16_to_cpu(firmware_info->info.usReferenceClock);
  1049. spll->reference_div = 0;
  1050. spll->pll_out_min =
  1051. le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Output);
  1052. spll->pll_out_max =
  1053. le32_to_cpu(firmware_info->info.ulMaxEngineClockPLL_Output);
  1054. /* ??? */
  1055. if (spll->pll_out_min == 0) {
  1056. if (ASIC_IS_AVIVO(rdev))
  1057. spll->pll_out_min = 64800;
  1058. else
  1059. spll->pll_out_min = 20000;
  1060. }
  1061. spll->pll_in_min =
  1062. le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Input);
  1063. spll->pll_in_max =
  1064. le16_to_cpu(firmware_info->info.usMaxEngineClockPLL_Input);
  1065. /* memory clock */
  1066. if (ASIC_IS_DCE4(rdev))
  1067. mpll->reference_freq =
  1068. le16_to_cpu(firmware_info->info_21.usMemoryReferenceClock);
  1069. else
  1070. mpll->reference_freq =
  1071. le16_to_cpu(firmware_info->info.usReferenceClock);
  1072. mpll->reference_div = 0;
  1073. mpll->pll_out_min =
  1074. le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Output);
  1075. mpll->pll_out_max =
  1076. le32_to_cpu(firmware_info->info.ulMaxMemoryClockPLL_Output);
  1077. /* ??? */
  1078. if (mpll->pll_out_min == 0) {
  1079. if (ASIC_IS_AVIVO(rdev))
  1080. mpll->pll_out_min = 64800;
  1081. else
  1082. mpll->pll_out_min = 20000;
  1083. }
  1084. mpll->pll_in_min =
  1085. le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Input);
  1086. mpll->pll_in_max =
  1087. le16_to_cpu(firmware_info->info.usMaxMemoryClockPLL_Input);
  1088. rdev->clock.default_sclk =
  1089. le32_to_cpu(firmware_info->info.ulDefaultEngineClock);
  1090. rdev->clock.default_mclk =
  1091. le32_to_cpu(firmware_info->info.ulDefaultMemoryClock);
  1092. if (ASIC_IS_DCE4(rdev)) {
  1093. rdev->clock.default_dispclk =
  1094. le32_to_cpu(firmware_info->info_21.ulDefaultDispEngineClkFreq);
  1095. if (rdev->clock.default_dispclk == 0) {
  1096. if (ASIC_IS_DCE6(rdev))
  1097. rdev->clock.default_dispclk = 60000; /* 600 Mhz */
  1098. else if (ASIC_IS_DCE5(rdev))
  1099. rdev->clock.default_dispclk = 54000; /* 540 Mhz */
  1100. else
  1101. rdev->clock.default_dispclk = 60000; /* 600 Mhz */
  1102. }
  1103. /* set a reasonable default for DP */
  1104. if (ASIC_IS_DCE6(rdev) && (rdev->clock.default_dispclk < 53900)) {
  1105. DRM_INFO("Changing default dispclk from %dMhz to 600Mhz\n",
  1106. rdev->clock.default_dispclk / 100);
  1107. rdev->clock.default_dispclk = 60000;
  1108. }
  1109. rdev->clock.dp_extclk =
  1110. le16_to_cpu(firmware_info->info_21.usUniphyDPModeExtClkFreq);
  1111. rdev->clock.current_dispclk = rdev->clock.default_dispclk;
  1112. }
  1113. *dcpll = *p1pll;
  1114. rdev->clock.max_pixel_clock = le16_to_cpu(firmware_info->info.usMaxPixelClock);
  1115. if (rdev->clock.max_pixel_clock == 0)
  1116. rdev->clock.max_pixel_clock = 40000;
  1117. /* not technically a clock, but... */
  1118. rdev->mode_info.firmware_flags =
  1119. le16_to_cpu(firmware_info->info.usFirmwareCapability.susAccess);
  1120. return true;
  1121. }
  1122. return false;
  1123. }
  1124. union igp_info {
  1125. struct _ATOM_INTEGRATED_SYSTEM_INFO info;
  1126. struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 info_2;
  1127. struct _ATOM_INTEGRATED_SYSTEM_INFO_V6 info_6;
  1128. struct _ATOM_INTEGRATED_SYSTEM_INFO_V1_7 info_7;
  1129. struct _ATOM_INTEGRATED_SYSTEM_INFO_V1_8 info_8;
  1130. };
  1131. bool radeon_atombios_sideport_present(struct radeon_device *rdev)
  1132. {
  1133. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1134. int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
  1135. union igp_info *igp_info;
  1136. u8 frev, crev;
  1137. u16 data_offset;
  1138. /* sideport is AMD only */
  1139. if (rdev->family == CHIP_RS600)
  1140. return false;
  1141. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1142. &frev, &crev, &data_offset)) {
  1143. igp_info = (union igp_info *)(mode_info->atom_context->bios +
  1144. data_offset);
  1145. switch (crev) {
  1146. case 1:
  1147. if (le32_to_cpu(igp_info->info.ulBootUpMemoryClock))
  1148. return true;
  1149. break;
  1150. case 2:
  1151. if (le32_to_cpu(igp_info->info_2.ulBootUpSidePortClock))
  1152. return true;
  1153. break;
  1154. default:
  1155. DRM_ERROR("Unsupported IGP table: %d %d\n", frev, crev);
  1156. break;
  1157. }
  1158. }
  1159. return false;
  1160. }
  1161. bool radeon_atombios_get_tmds_info(struct radeon_encoder *encoder,
  1162. struct radeon_encoder_int_tmds *tmds)
  1163. {
  1164. struct drm_device *dev = encoder->base.dev;
  1165. struct radeon_device *rdev = dev->dev_private;
  1166. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1167. int index = GetIndexIntoMasterTable(DATA, TMDS_Info);
  1168. uint16_t data_offset;
  1169. struct _ATOM_TMDS_INFO *tmds_info;
  1170. uint8_t frev, crev;
  1171. uint16_t maxfreq;
  1172. int i;
  1173. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1174. &frev, &crev, &data_offset)) {
  1175. tmds_info =
  1176. (struct _ATOM_TMDS_INFO *)(mode_info->atom_context->bios +
  1177. data_offset);
  1178. maxfreq = le16_to_cpu(tmds_info->usMaxFrequency);
  1179. for (i = 0; i < 4; i++) {
  1180. tmds->tmds_pll[i].freq =
  1181. le16_to_cpu(tmds_info->asMiscInfo[i].usFrequency);
  1182. tmds->tmds_pll[i].value =
  1183. tmds_info->asMiscInfo[i].ucPLL_ChargePump & 0x3f;
  1184. tmds->tmds_pll[i].value |=
  1185. (tmds_info->asMiscInfo[i].
  1186. ucPLL_VCO_Gain & 0x3f) << 6;
  1187. tmds->tmds_pll[i].value |=
  1188. (tmds_info->asMiscInfo[i].
  1189. ucPLL_DutyCycle & 0xf) << 12;
  1190. tmds->tmds_pll[i].value |=
  1191. (tmds_info->asMiscInfo[i].
  1192. ucPLL_VoltageSwing & 0xf) << 16;
  1193. DRM_DEBUG_KMS("TMDS PLL From ATOMBIOS %u %x\n",
  1194. tmds->tmds_pll[i].freq,
  1195. tmds->tmds_pll[i].value);
  1196. if (maxfreq == tmds->tmds_pll[i].freq) {
  1197. tmds->tmds_pll[i].freq = 0xffffffff;
  1198. break;
  1199. }
  1200. }
  1201. return true;
  1202. }
  1203. return false;
  1204. }
  1205. bool radeon_atombios_get_ppll_ss_info(struct radeon_device *rdev,
  1206. struct radeon_atom_ss *ss,
  1207. int id)
  1208. {
  1209. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1210. int index = GetIndexIntoMasterTable(DATA, PPLL_SS_Info);
  1211. uint16_t data_offset, size;
  1212. struct _ATOM_SPREAD_SPECTRUM_INFO *ss_info;
  1213. struct _ATOM_SPREAD_SPECTRUM_ASSIGNMENT *ss_assign;
  1214. uint8_t frev, crev;
  1215. int i, num_indices;
  1216. memset(ss, 0, sizeof(struct radeon_atom_ss));
  1217. if (atom_parse_data_header(mode_info->atom_context, index, &size,
  1218. &frev, &crev, &data_offset)) {
  1219. ss_info =
  1220. (struct _ATOM_SPREAD_SPECTRUM_INFO *)(mode_info->atom_context->bios + data_offset);
  1221. num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
  1222. sizeof(ATOM_SPREAD_SPECTRUM_ASSIGNMENT);
  1223. ss_assign = (struct _ATOM_SPREAD_SPECTRUM_ASSIGNMENT*)
  1224. ((u8 *)&ss_info->asSS_Info[0]);
  1225. for (i = 0; i < num_indices; i++) {
  1226. if (ss_assign->ucSS_Id == id) {
  1227. ss->percentage =
  1228. le16_to_cpu(ss_assign->usSpreadSpectrumPercentage);
  1229. ss->type = ss_assign->ucSpreadSpectrumType;
  1230. ss->step = ss_assign->ucSS_Step;
  1231. ss->delay = ss_assign->ucSS_Delay;
  1232. ss->range = ss_assign->ucSS_Range;
  1233. ss->refdiv = ss_assign->ucRecommendedRef_Div;
  1234. return true;
  1235. }
  1236. ss_assign = (struct _ATOM_SPREAD_SPECTRUM_ASSIGNMENT*)
  1237. ((u8 *)ss_assign + sizeof(struct _ATOM_SPREAD_SPECTRUM_ASSIGNMENT));
  1238. }
  1239. }
  1240. return false;
  1241. }
  1242. static void radeon_atombios_get_igp_ss_overrides(struct radeon_device *rdev,
  1243. struct radeon_atom_ss *ss,
  1244. int id)
  1245. {
  1246. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1247. int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
  1248. u16 data_offset, size;
  1249. union igp_info *igp_info;
  1250. u8 frev, crev;
  1251. u16 percentage = 0, rate = 0;
  1252. /* get any igp specific overrides */
  1253. if (atom_parse_data_header(mode_info->atom_context, index, &size,
  1254. &frev, &crev, &data_offset)) {
  1255. igp_info = (union igp_info *)
  1256. (mode_info->atom_context->bios + data_offset);
  1257. switch (crev) {
  1258. case 6:
  1259. switch (id) {
  1260. case ASIC_INTERNAL_SS_ON_TMDS:
  1261. percentage = le16_to_cpu(igp_info->info_6.usDVISSPercentage);
  1262. rate = le16_to_cpu(igp_info->info_6.usDVISSpreadRateIn10Hz);
  1263. break;
  1264. case ASIC_INTERNAL_SS_ON_HDMI:
  1265. percentage = le16_to_cpu(igp_info->info_6.usHDMISSPercentage);
  1266. rate = le16_to_cpu(igp_info->info_6.usHDMISSpreadRateIn10Hz);
  1267. break;
  1268. case ASIC_INTERNAL_SS_ON_LVDS:
  1269. percentage = le16_to_cpu(igp_info->info_6.usLvdsSSPercentage);
  1270. rate = le16_to_cpu(igp_info->info_6.usLvdsSSpreadRateIn10Hz);
  1271. break;
  1272. }
  1273. break;
  1274. case 7:
  1275. switch (id) {
  1276. case ASIC_INTERNAL_SS_ON_TMDS:
  1277. percentage = le16_to_cpu(igp_info->info_7.usDVISSPercentage);
  1278. rate = le16_to_cpu(igp_info->info_7.usDVISSpreadRateIn10Hz);
  1279. break;
  1280. case ASIC_INTERNAL_SS_ON_HDMI:
  1281. percentage = le16_to_cpu(igp_info->info_7.usHDMISSPercentage);
  1282. rate = le16_to_cpu(igp_info->info_7.usHDMISSpreadRateIn10Hz);
  1283. break;
  1284. case ASIC_INTERNAL_SS_ON_LVDS:
  1285. percentage = le16_to_cpu(igp_info->info_7.usLvdsSSPercentage);
  1286. rate = le16_to_cpu(igp_info->info_7.usLvdsSSpreadRateIn10Hz);
  1287. break;
  1288. }
  1289. break;
  1290. case 8:
  1291. switch (id) {
  1292. case ASIC_INTERNAL_SS_ON_TMDS:
  1293. percentage = le16_to_cpu(igp_info->info_8.usDVISSPercentage);
  1294. rate = le16_to_cpu(igp_info->info_8.usDVISSpreadRateIn10Hz);
  1295. break;
  1296. case ASIC_INTERNAL_SS_ON_HDMI:
  1297. percentage = le16_to_cpu(igp_info->info_8.usHDMISSPercentage);
  1298. rate = le16_to_cpu(igp_info->info_8.usHDMISSpreadRateIn10Hz);
  1299. break;
  1300. case ASIC_INTERNAL_SS_ON_LVDS:
  1301. percentage = le16_to_cpu(igp_info->info_8.usLvdsSSPercentage);
  1302. rate = le16_to_cpu(igp_info->info_8.usLvdsSSpreadRateIn10Hz);
  1303. break;
  1304. }
  1305. break;
  1306. default:
  1307. DRM_ERROR("Unsupported IGP table: %d %d\n", frev, crev);
  1308. break;
  1309. }
  1310. if (percentage)
  1311. ss->percentage = percentage;
  1312. if (rate)
  1313. ss->rate = rate;
  1314. }
  1315. }
  1316. union asic_ss_info {
  1317. struct _ATOM_ASIC_INTERNAL_SS_INFO info;
  1318. struct _ATOM_ASIC_INTERNAL_SS_INFO_V2 info_2;
  1319. struct _ATOM_ASIC_INTERNAL_SS_INFO_V3 info_3;
  1320. };
  1321. union asic_ss_assignment {
  1322. struct _ATOM_ASIC_SS_ASSIGNMENT v1;
  1323. struct _ATOM_ASIC_SS_ASSIGNMENT_V2 v2;
  1324. struct _ATOM_ASIC_SS_ASSIGNMENT_V3 v3;
  1325. };
  1326. bool radeon_atombios_get_asic_ss_info(struct radeon_device *rdev,
  1327. struct radeon_atom_ss *ss,
  1328. int id, u32 clock)
  1329. {
  1330. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1331. int index = GetIndexIntoMasterTable(DATA, ASIC_InternalSS_Info);
  1332. uint16_t data_offset, size;
  1333. union asic_ss_info *ss_info;
  1334. union asic_ss_assignment *ss_assign;
  1335. uint8_t frev, crev;
  1336. int i, num_indices;
  1337. if (id == ASIC_INTERNAL_MEMORY_SS) {
  1338. if (!(rdev->mode_info.firmware_flags & ATOM_BIOS_INFO_MEMORY_CLOCK_SS_SUPPORT))
  1339. return false;
  1340. }
  1341. if (id == ASIC_INTERNAL_ENGINE_SS) {
  1342. if (!(rdev->mode_info.firmware_flags & ATOM_BIOS_INFO_ENGINE_CLOCK_SS_SUPPORT))
  1343. return false;
  1344. }
  1345. memset(ss, 0, sizeof(struct radeon_atom_ss));
  1346. if (atom_parse_data_header(mode_info->atom_context, index, &size,
  1347. &frev, &crev, &data_offset)) {
  1348. ss_info =
  1349. (union asic_ss_info *)(mode_info->atom_context->bios + data_offset);
  1350. switch (frev) {
  1351. case 1:
  1352. num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
  1353. sizeof(ATOM_ASIC_SS_ASSIGNMENT);
  1354. ss_assign = (union asic_ss_assignment *)((u8 *)&ss_info->info.asSpreadSpectrum[0]);
  1355. for (i = 0; i < num_indices; i++) {
  1356. if ((ss_assign->v1.ucClockIndication == id) &&
  1357. (clock <= le32_to_cpu(ss_assign->v1.ulTargetClockRange))) {
  1358. ss->percentage =
  1359. le16_to_cpu(ss_assign->v1.usSpreadSpectrumPercentage);
  1360. ss->type = ss_assign->v1.ucSpreadSpectrumMode;
  1361. ss->rate = le16_to_cpu(ss_assign->v1.usSpreadRateInKhz);
  1362. ss->percentage_divider = 100;
  1363. return true;
  1364. }
  1365. ss_assign = (union asic_ss_assignment *)
  1366. ((u8 *)ss_assign + sizeof(ATOM_ASIC_SS_ASSIGNMENT));
  1367. }
  1368. break;
  1369. case 2:
  1370. num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
  1371. sizeof(ATOM_ASIC_SS_ASSIGNMENT_V2);
  1372. ss_assign = (union asic_ss_assignment *)((u8 *)&ss_info->info_2.asSpreadSpectrum[0]);
  1373. for (i = 0; i < num_indices; i++) {
  1374. if ((ss_assign->v2.ucClockIndication == id) &&
  1375. (clock <= le32_to_cpu(ss_assign->v2.ulTargetClockRange))) {
  1376. ss->percentage =
  1377. le16_to_cpu(ss_assign->v2.usSpreadSpectrumPercentage);
  1378. ss->type = ss_assign->v2.ucSpreadSpectrumMode;
  1379. ss->rate = le16_to_cpu(ss_assign->v2.usSpreadRateIn10Hz);
  1380. ss->percentage_divider = 100;
  1381. if ((crev == 2) &&
  1382. ((id == ASIC_INTERNAL_ENGINE_SS) ||
  1383. (id == ASIC_INTERNAL_MEMORY_SS)))
  1384. ss->rate /= 100;
  1385. return true;
  1386. }
  1387. ss_assign = (union asic_ss_assignment *)
  1388. ((u8 *)ss_assign + sizeof(ATOM_ASIC_SS_ASSIGNMENT_V2));
  1389. }
  1390. break;
  1391. case 3:
  1392. num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
  1393. sizeof(ATOM_ASIC_SS_ASSIGNMENT_V3);
  1394. ss_assign = (union asic_ss_assignment *)((u8 *)&ss_info->info_3.asSpreadSpectrum[0]);
  1395. for (i = 0; i < num_indices; i++) {
  1396. if ((ss_assign->v3.ucClockIndication == id) &&
  1397. (clock <= le32_to_cpu(ss_assign->v3.ulTargetClockRange))) {
  1398. ss->percentage =
  1399. le16_to_cpu(ss_assign->v3.usSpreadSpectrumPercentage);
  1400. ss->type = ss_assign->v3.ucSpreadSpectrumMode;
  1401. ss->rate = le16_to_cpu(ss_assign->v3.usSpreadRateIn10Hz);
  1402. if (ss_assign->v3.ucSpreadSpectrumMode &
  1403. SS_MODE_V3_PERCENTAGE_DIV_BY_1000_MASK)
  1404. ss->percentage_divider = 1000;
  1405. else
  1406. ss->percentage_divider = 100;
  1407. if ((id == ASIC_INTERNAL_ENGINE_SS) ||
  1408. (id == ASIC_INTERNAL_MEMORY_SS))
  1409. ss->rate /= 100;
  1410. if (rdev->flags & RADEON_IS_IGP)
  1411. radeon_atombios_get_igp_ss_overrides(rdev, ss, id);
  1412. return true;
  1413. }
  1414. ss_assign = (union asic_ss_assignment *)
  1415. ((u8 *)ss_assign + sizeof(ATOM_ASIC_SS_ASSIGNMENT_V3));
  1416. }
  1417. break;
  1418. default:
  1419. DRM_ERROR("Unsupported ASIC_InternalSS_Info table: %d %d\n", frev, crev);
  1420. break;
  1421. }
  1422. }
  1423. return false;
  1424. }
  1425. union lvds_info {
  1426. struct _ATOM_LVDS_INFO info;
  1427. struct _ATOM_LVDS_INFO_V12 info_12;
  1428. };
  1429. struct radeon_encoder_atom_dig *radeon_atombios_get_lvds_info(struct
  1430. radeon_encoder
  1431. *encoder)
  1432. {
  1433. struct drm_device *dev = encoder->base.dev;
  1434. struct radeon_device *rdev = dev->dev_private;
  1435. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1436. int index = GetIndexIntoMasterTable(DATA, LVDS_Info);
  1437. uint16_t data_offset, misc;
  1438. union lvds_info *lvds_info;
  1439. uint8_t frev, crev;
  1440. struct radeon_encoder_atom_dig *lvds = NULL;
  1441. int encoder_enum = (encoder->encoder_enum & ENUM_ID_MASK) >> ENUM_ID_SHIFT;
  1442. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1443. &frev, &crev, &data_offset)) {
  1444. lvds_info =
  1445. (union lvds_info *)(mode_info->atom_context->bios + data_offset);
  1446. lvds =
  1447. kzalloc(sizeof(struct radeon_encoder_atom_dig), GFP_KERNEL);
  1448. if (!lvds)
  1449. return NULL;
  1450. lvds->native_mode.clock =
  1451. le16_to_cpu(lvds_info->info.sLCDTiming.usPixClk) * 10;
  1452. lvds->native_mode.hdisplay =
  1453. le16_to_cpu(lvds_info->info.sLCDTiming.usHActive);
  1454. lvds->native_mode.vdisplay =
  1455. le16_to_cpu(lvds_info->info.sLCDTiming.usVActive);
  1456. lvds->native_mode.htotal = lvds->native_mode.hdisplay +
  1457. le16_to_cpu(lvds_info->info.sLCDTiming.usHBlanking_Time);
  1458. lvds->native_mode.hsync_start = lvds->native_mode.hdisplay +
  1459. le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncOffset);
  1460. lvds->native_mode.hsync_end = lvds->native_mode.hsync_start +
  1461. le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncWidth);
  1462. lvds->native_mode.vtotal = lvds->native_mode.vdisplay +
  1463. le16_to_cpu(lvds_info->info.sLCDTiming.usVBlanking_Time);
  1464. lvds->native_mode.vsync_start = lvds->native_mode.vdisplay +
  1465. le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncOffset);
  1466. lvds->native_mode.vsync_end = lvds->native_mode.vsync_start +
  1467. le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncWidth);
  1468. lvds->panel_pwr_delay =
  1469. le16_to_cpu(lvds_info->info.usOffDelayInMs);
  1470. lvds->lcd_misc = lvds_info->info.ucLVDS_Misc;
  1471. misc = le16_to_cpu(lvds_info->info.sLCDTiming.susModeMiscInfo.usAccess);
  1472. if (misc & ATOM_VSYNC_POLARITY)
  1473. lvds->native_mode.flags |= DRM_MODE_FLAG_NVSYNC;
  1474. if (misc & ATOM_HSYNC_POLARITY)
  1475. lvds->native_mode.flags |= DRM_MODE_FLAG_NHSYNC;
  1476. if (misc & ATOM_COMPOSITESYNC)
  1477. lvds->native_mode.flags |= DRM_MODE_FLAG_CSYNC;
  1478. if (misc & ATOM_INTERLACE)
  1479. lvds->native_mode.flags |= DRM_MODE_FLAG_INTERLACE;
  1480. if (misc & ATOM_DOUBLE_CLOCK_MODE)
  1481. lvds->native_mode.flags |= DRM_MODE_FLAG_DBLSCAN;
  1482. lvds->native_mode.width_mm = le16_to_cpu(lvds_info->info.sLCDTiming.usImageHSize);
  1483. lvds->native_mode.height_mm = le16_to_cpu(lvds_info->info.sLCDTiming.usImageVSize);
  1484. /* set crtc values */
  1485. drm_mode_set_crtcinfo(&lvds->native_mode, CRTC_INTERLACE_HALVE_V);
  1486. lvds->lcd_ss_id = lvds_info->info.ucSS_Id;
  1487. encoder->native_mode = lvds->native_mode;
  1488. if (encoder_enum == 2)
  1489. lvds->linkb = true;
  1490. else
  1491. lvds->linkb = false;
  1492. /* parse the lcd record table */
  1493. if (le16_to_cpu(lvds_info->info.usModePatchTableOffset)) {
  1494. ATOM_FAKE_EDID_PATCH_RECORD *fake_edid_record;
  1495. ATOM_PANEL_RESOLUTION_PATCH_RECORD *panel_res_record;
  1496. bool bad_record = false;
  1497. u8 *record;
  1498. if ((frev == 1) && (crev < 2))
  1499. /* absolute */
  1500. record = (u8 *)(mode_info->atom_context->bios +
  1501. le16_to_cpu(lvds_info->info.usModePatchTableOffset));
  1502. else
  1503. /* relative */
  1504. record = (u8 *)(mode_info->atom_context->bios +
  1505. data_offset +
  1506. le16_to_cpu(lvds_info->info.usModePatchTableOffset));
  1507. while (*record != ATOM_RECORD_END_TYPE) {
  1508. switch (*record) {
  1509. case LCD_MODE_PATCH_RECORD_MODE_TYPE:
  1510. record += sizeof(ATOM_PATCH_RECORD_MODE);
  1511. break;
  1512. case LCD_RTS_RECORD_TYPE:
  1513. record += sizeof(ATOM_LCD_RTS_RECORD);
  1514. break;
  1515. case LCD_CAP_RECORD_TYPE:
  1516. record += sizeof(ATOM_LCD_MODE_CONTROL_CAP);
  1517. break;
  1518. case LCD_FAKE_EDID_PATCH_RECORD_TYPE:
  1519. fake_edid_record = (ATOM_FAKE_EDID_PATCH_RECORD *)record;
  1520. if (fake_edid_record->ucFakeEDIDLength) {
  1521. struct edid *edid;
  1522. int edid_size =
  1523. max((int)EDID_LENGTH, (int)fake_edid_record->ucFakeEDIDLength);
  1524. edid = kmalloc(edid_size, GFP_KERNEL);
  1525. if (edid) {
  1526. memcpy((u8 *)edid, (u8 *)&fake_edid_record->ucFakeEDIDString[0],
  1527. fake_edid_record->ucFakeEDIDLength);
  1528. if (drm_edid_is_valid(edid)) {
  1529. rdev->mode_info.bios_hardcoded_edid = edid;
  1530. rdev->mode_info.bios_hardcoded_edid_size = edid_size;
  1531. } else
  1532. kfree(edid);
  1533. }
  1534. }
  1535. record += fake_edid_record->ucFakeEDIDLength ?
  1536. fake_edid_record->ucFakeEDIDLength + 2 :
  1537. sizeof(ATOM_FAKE_EDID_PATCH_RECORD);
  1538. break;
  1539. case LCD_PANEL_RESOLUTION_RECORD_TYPE:
  1540. panel_res_record = (ATOM_PANEL_RESOLUTION_PATCH_RECORD *)record;
  1541. lvds->native_mode.width_mm = panel_res_record->usHSize;
  1542. lvds->native_mode.height_mm = panel_res_record->usVSize;
  1543. record += sizeof(ATOM_PANEL_RESOLUTION_PATCH_RECORD);
  1544. break;
  1545. default:
  1546. DRM_ERROR("Bad LCD record %d\n", *record);
  1547. bad_record = true;
  1548. break;
  1549. }
  1550. if (bad_record)
  1551. break;
  1552. }
  1553. }
  1554. }
  1555. return lvds;
  1556. }
  1557. struct radeon_encoder_primary_dac *
  1558. radeon_atombios_get_primary_dac_info(struct radeon_encoder *encoder)
  1559. {
  1560. struct drm_device *dev = encoder->base.dev;
  1561. struct radeon_device *rdev = dev->dev_private;
  1562. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1563. int index = GetIndexIntoMasterTable(DATA, CompassionateData);
  1564. uint16_t data_offset;
  1565. struct _COMPASSIONATE_DATA *dac_info;
  1566. uint8_t frev, crev;
  1567. uint8_t bg, dac;
  1568. struct radeon_encoder_primary_dac *p_dac = NULL;
  1569. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1570. &frev, &crev, &data_offset)) {
  1571. dac_info = (struct _COMPASSIONATE_DATA *)
  1572. (mode_info->atom_context->bios + data_offset);
  1573. p_dac = kzalloc(sizeof(struct radeon_encoder_primary_dac), GFP_KERNEL);
  1574. if (!p_dac)
  1575. return NULL;
  1576. bg = dac_info->ucDAC1_BG_Adjustment;
  1577. dac = dac_info->ucDAC1_DAC_Adjustment;
  1578. p_dac->ps2_pdac_adj = (bg << 8) | (dac);
  1579. }
  1580. return p_dac;
  1581. }
  1582. bool radeon_atom_get_tv_timings(struct radeon_device *rdev, int index,
  1583. struct drm_display_mode *mode)
  1584. {
  1585. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1586. ATOM_ANALOG_TV_INFO *tv_info;
  1587. ATOM_ANALOG_TV_INFO_V1_2 *tv_info_v1_2;
  1588. ATOM_DTD_FORMAT *dtd_timings;
  1589. int data_index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
  1590. u8 frev, crev;
  1591. u16 data_offset, misc;
  1592. if (!atom_parse_data_header(mode_info->atom_context, data_index, NULL,
  1593. &frev, &crev, &data_offset))
  1594. return false;
  1595. switch (crev) {
  1596. case 1:
  1597. tv_info = (ATOM_ANALOG_TV_INFO *)(mode_info->atom_context->bios + data_offset);
  1598. if (index >= MAX_SUPPORTED_TV_TIMING)
  1599. return false;
  1600. mode->crtc_htotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Total);
  1601. mode->crtc_hdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Disp);
  1602. mode->crtc_hsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart);
  1603. mode->crtc_hsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart) +
  1604. le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncWidth);
  1605. mode->crtc_vtotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Total);
  1606. mode->crtc_vdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Disp);
  1607. mode->crtc_vsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart);
  1608. mode->crtc_vsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart) +
  1609. le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncWidth);
  1610. mode->flags = 0;
  1611. misc = le16_to_cpu(tv_info->aModeTimings[index].susModeMiscInfo.usAccess);
  1612. if (misc & ATOM_VSYNC_POLARITY)
  1613. mode->flags |= DRM_MODE_FLAG_NVSYNC;
  1614. if (misc & ATOM_HSYNC_POLARITY)
  1615. mode->flags |= DRM_MODE_FLAG_NHSYNC;
  1616. if (misc & ATOM_COMPOSITESYNC)
  1617. mode->flags |= DRM_MODE_FLAG_CSYNC;
  1618. if (misc & ATOM_INTERLACE)
  1619. mode->flags |= DRM_MODE_FLAG_INTERLACE;
  1620. if (misc & ATOM_DOUBLE_CLOCK_MODE)
  1621. mode->flags |= DRM_MODE_FLAG_DBLSCAN;
  1622. mode->crtc_clock = mode->clock =
  1623. le16_to_cpu(tv_info->aModeTimings[index].usPixelClock) * 10;
  1624. if (index == 1) {
  1625. /* PAL timings appear to have wrong values for totals */
  1626. mode->crtc_htotal -= 1;
  1627. mode->crtc_vtotal -= 1;
  1628. }
  1629. break;
  1630. case 2:
  1631. tv_info_v1_2 = (ATOM_ANALOG_TV_INFO_V1_2 *)(mode_info->atom_context->bios + data_offset);
  1632. if (index >= MAX_SUPPORTED_TV_TIMING_V1_2)
  1633. return false;
  1634. dtd_timings = &tv_info_v1_2->aModeTimings[index];
  1635. mode->crtc_htotal = le16_to_cpu(dtd_timings->usHActive) +
  1636. le16_to_cpu(dtd_timings->usHBlanking_Time);
  1637. mode->crtc_hdisplay = le16_to_cpu(dtd_timings->usHActive);
  1638. mode->crtc_hsync_start = le16_to_cpu(dtd_timings->usHActive) +
  1639. le16_to_cpu(dtd_timings->usHSyncOffset);
  1640. mode->crtc_hsync_end = mode->crtc_hsync_start +
  1641. le16_to_cpu(dtd_timings->usHSyncWidth);
  1642. mode->crtc_vtotal = le16_to_cpu(dtd_timings->usVActive) +
  1643. le16_to_cpu(dtd_timings->usVBlanking_Time);
  1644. mode->crtc_vdisplay = le16_to_cpu(dtd_timings->usVActive);
  1645. mode->crtc_vsync_start = le16_to_cpu(dtd_timings->usVActive) +
  1646. le16_to_cpu(dtd_timings->usVSyncOffset);
  1647. mode->crtc_vsync_end = mode->crtc_vsync_start +
  1648. le16_to_cpu(dtd_timings->usVSyncWidth);
  1649. mode->flags = 0;
  1650. misc = le16_to_cpu(dtd_timings->susModeMiscInfo.usAccess);
  1651. if (misc & ATOM_VSYNC_POLARITY)
  1652. mode->flags |= DRM_MODE_FLAG_NVSYNC;
  1653. if (misc & ATOM_HSYNC_POLARITY)
  1654. mode->flags |= DRM_MODE_FLAG_NHSYNC;
  1655. if (misc & ATOM_COMPOSITESYNC)
  1656. mode->flags |= DRM_MODE_FLAG_CSYNC;
  1657. if (misc & ATOM_INTERLACE)
  1658. mode->flags |= DRM_MODE_FLAG_INTERLACE;
  1659. if (misc & ATOM_DOUBLE_CLOCK_MODE)
  1660. mode->flags |= DRM_MODE_FLAG_DBLSCAN;
  1661. mode->crtc_clock = mode->clock =
  1662. le16_to_cpu(dtd_timings->usPixClk) * 10;
  1663. break;
  1664. }
  1665. return true;
  1666. }
  1667. enum radeon_tv_std
  1668. radeon_atombios_get_tv_info(struct radeon_device *rdev)
  1669. {
  1670. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1671. int index = GetIndexIntoMasterTable(DATA, AnalogTV_Info);
  1672. uint16_t data_offset;
  1673. uint8_t frev, crev;
  1674. struct _ATOM_ANALOG_TV_INFO *tv_info;
  1675. enum radeon_tv_std tv_std = TV_STD_NTSC;
  1676. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1677. &frev, &crev, &data_offset)) {
  1678. tv_info = (struct _ATOM_ANALOG_TV_INFO *)
  1679. (mode_info->atom_context->bios + data_offset);
  1680. switch (tv_info->ucTV_BootUpDefaultStandard) {
  1681. case ATOM_TV_NTSC:
  1682. tv_std = TV_STD_NTSC;
  1683. DRM_DEBUG_KMS("Default TV standard: NTSC\n");
  1684. break;
  1685. case ATOM_TV_NTSCJ:
  1686. tv_std = TV_STD_NTSC_J;
  1687. DRM_DEBUG_KMS("Default TV standard: NTSC-J\n");
  1688. break;
  1689. case ATOM_TV_PAL:
  1690. tv_std = TV_STD_PAL;
  1691. DRM_DEBUG_KMS("Default TV standard: PAL\n");
  1692. break;
  1693. case ATOM_TV_PALM:
  1694. tv_std = TV_STD_PAL_M;
  1695. DRM_DEBUG_KMS("Default TV standard: PAL-M\n");
  1696. break;
  1697. case ATOM_TV_PALN:
  1698. tv_std = TV_STD_PAL_N;
  1699. DRM_DEBUG_KMS("Default TV standard: PAL-N\n");
  1700. break;
  1701. case ATOM_TV_PALCN:
  1702. tv_std = TV_STD_PAL_CN;
  1703. DRM_DEBUG_KMS("Default TV standard: PAL-CN\n");
  1704. break;
  1705. case ATOM_TV_PAL60:
  1706. tv_std = TV_STD_PAL_60;
  1707. DRM_DEBUG_KMS("Default TV standard: PAL-60\n");
  1708. break;
  1709. case ATOM_TV_SECAM:
  1710. tv_std = TV_STD_SECAM;
  1711. DRM_DEBUG_KMS("Default TV standard: SECAM\n");
  1712. break;
  1713. default:
  1714. tv_std = TV_STD_NTSC;
  1715. DRM_DEBUG_KMS("Unknown TV standard; defaulting to NTSC\n");
  1716. break;
  1717. }
  1718. }
  1719. return tv_std;
  1720. }
  1721. struct radeon_encoder_tv_dac *
  1722. radeon_atombios_get_tv_dac_info(struct radeon_encoder *encoder)
  1723. {
  1724. struct drm_device *dev = encoder->base.dev;
  1725. struct radeon_device *rdev = dev->dev_private;
  1726. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1727. int index = GetIndexIntoMasterTable(DATA, CompassionateData);
  1728. uint16_t data_offset;
  1729. struct _COMPASSIONATE_DATA *dac_info;
  1730. uint8_t frev, crev;
  1731. uint8_t bg, dac;
  1732. struct radeon_encoder_tv_dac *tv_dac = NULL;
  1733. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  1734. &frev, &crev, &data_offset)) {
  1735. dac_info = (struct _COMPASSIONATE_DATA *)
  1736. (mode_info->atom_context->bios + data_offset);
  1737. tv_dac = kzalloc(sizeof(struct radeon_encoder_tv_dac), GFP_KERNEL);
  1738. if (!tv_dac)
  1739. return NULL;
  1740. bg = dac_info->ucDAC2_CRT2_BG_Adjustment;
  1741. dac = dac_info->ucDAC2_CRT2_DAC_Adjustment;
  1742. tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20);
  1743. bg = dac_info->ucDAC2_PAL_BG_Adjustment;
  1744. dac = dac_info->ucDAC2_PAL_DAC_Adjustment;
  1745. tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20);
  1746. bg = dac_info->ucDAC2_NTSC_BG_Adjustment;
  1747. dac = dac_info->ucDAC2_NTSC_DAC_Adjustment;
  1748. tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20);
  1749. tv_dac->tv_std = radeon_atombios_get_tv_info(rdev);
  1750. }
  1751. return tv_dac;
  1752. }
  1753. static const char *thermal_controller_names[] = {
  1754. "NONE",
  1755. "lm63",
  1756. "adm1032",
  1757. "adm1030",
  1758. "max6649",
  1759. "lm63", /* lm64 */
  1760. "f75375",
  1761. "asc7xxx",
  1762. };
  1763. static const char *pp_lib_thermal_controller_names[] = {
  1764. "NONE",
  1765. "lm63",
  1766. "adm1032",
  1767. "adm1030",
  1768. "max6649",
  1769. "lm63", /* lm64 */
  1770. "f75375",
  1771. "RV6xx",
  1772. "RV770",
  1773. "adt7473",
  1774. "NONE",
  1775. "External GPIO",
  1776. "Evergreen",
  1777. "emc2103",
  1778. "Sumo",
  1779. "Northern Islands",
  1780. "Southern Islands",
  1781. "lm96163",
  1782. "Sea Islands",
  1783. };
  1784. union power_info {
  1785. struct _ATOM_POWERPLAY_INFO info;
  1786. struct _ATOM_POWERPLAY_INFO_V2 info_2;
  1787. struct _ATOM_POWERPLAY_INFO_V3 info_3;
  1788. struct _ATOM_PPLIB_POWERPLAYTABLE pplib;
  1789. struct _ATOM_PPLIB_POWERPLAYTABLE2 pplib2;
  1790. struct _ATOM_PPLIB_POWERPLAYTABLE3 pplib3;
  1791. };
  1792. union pplib_clock_info {
  1793. struct _ATOM_PPLIB_R600_CLOCK_INFO r600;
  1794. struct _ATOM_PPLIB_RS780_CLOCK_INFO rs780;
  1795. struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO evergreen;
  1796. struct _ATOM_PPLIB_SUMO_CLOCK_INFO sumo;
  1797. struct _ATOM_PPLIB_SI_CLOCK_INFO si;
  1798. struct _ATOM_PPLIB_CI_CLOCK_INFO ci;
  1799. };
  1800. union pplib_power_state {
  1801. struct _ATOM_PPLIB_STATE v1;
  1802. struct _ATOM_PPLIB_STATE_V2 v2;
  1803. };
  1804. static void radeon_atombios_parse_misc_flags_1_3(struct radeon_device *rdev,
  1805. int state_index,
  1806. u32 misc, u32 misc2)
  1807. {
  1808. rdev->pm.power_state[state_index].misc = misc;
  1809. rdev->pm.power_state[state_index].misc2 = misc2;
  1810. /* order matters! */
  1811. if (misc & ATOM_PM_MISCINFO_POWER_SAVING_MODE)
  1812. rdev->pm.power_state[state_index].type =
  1813. POWER_STATE_TYPE_POWERSAVE;
  1814. if (misc & ATOM_PM_MISCINFO_DEFAULT_DC_STATE_ENTRY_TRUE)
  1815. rdev->pm.power_state[state_index].type =
  1816. POWER_STATE_TYPE_BATTERY;
  1817. if (misc & ATOM_PM_MISCINFO_DEFAULT_LOW_DC_STATE_ENTRY_TRUE)
  1818. rdev->pm.power_state[state_index].type =
  1819. POWER_STATE_TYPE_BATTERY;
  1820. if (misc & ATOM_PM_MISCINFO_LOAD_BALANCE_EN)
  1821. rdev->pm.power_state[state_index].type =
  1822. POWER_STATE_TYPE_BALANCED;
  1823. if (misc & ATOM_PM_MISCINFO_3D_ACCELERATION_EN) {
  1824. rdev->pm.power_state[state_index].type =
  1825. POWER_STATE_TYPE_PERFORMANCE;
  1826. rdev->pm.power_state[state_index].flags &=
  1827. ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1828. }
  1829. if (misc2 & ATOM_PM_MISCINFO2_SYSTEM_AC_LITE_MODE)
  1830. rdev->pm.power_state[state_index].type =
  1831. POWER_STATE_TYPE_BALANCED;
  1832. if (misc & ATOM_PM_MISCINFO_DRIVER_DEFAULT_MODE) {
  1833. rdev->pm.power_state[state_index].type =
  1834. POWER_STATE_TYPE_DEFAULT;
  1835. rdev->pm.default_power_state_index = state_index;
  1836. rdev->pm.power_state[state_index].default_clock_mode =
  1837. &rdev->pm.power_state[state_index].clock_info[0];
  1838. } else if (state_index == 0) {
  1839. rdev->pm.power_state[state_index].clock_info[0].flags |=
  1840. RADEON_PM_MODE_NO_DISPLAY;
  1841. }
  1842. }
  1843. static int radeon_atombios_parse_power_table_1_3(struct radeon_device *rdev)
  1844. {
  1845. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1846. u32 misc, misc2 = 0;
  1847. int num_modes = 0, i;
  1848. int state_index = 0;
  1849. struct radeon_i2c_bus_rec i2c_bus;
  1850. union power_info *power_info;
  1851. int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
  1852. u16 data_offset;
  1853. u8 frev, crev;
  1854. if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
  1855. &frev, &crev, &data_offset))
  1856. return state_index;
  1857. power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
  1858. /* add the i2c bus for thermal/fan chip */
  1859. if ((power_info->info.ucOverdriveThermalController > 0) &&
  1860. (power_info->info.ucOverdriveThermalController < ARRAY_SIZE(thermal_controller_names))) {
  1861. DRM_INFO("Possible %s thermal controller at 0x%02x\n",
  1862. thermal_controller_names[power_info->info.ucOverdriveThermalController],
  1863. power_info->info.ucOverdriveControllerAddress >> 1);
  1864. i2c_bus = radeon_lookup_i2c_gpio(rdev, power_info->info.ucOverdriveI2cLine);
  1865. rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
  1866. if (rdev->pm.i2c_bus) {
  1867. struct i2c_board_info info = { };
  1868. const char *name = thermal_controller_names[power_info->info.
  1869. ucOverdriveThermalController];
  1870. info.addr = power_info->info.ucOverdriveControllerAddress >> 1;
  1871. strlcpy(info.type, name, sizeof(info.type));
  1872. i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
  1873. }
  1874. }
  1875. num_modes = power_info->info.ucNumOfPowerModeEntries;
  1876. if (num_modes > ATOM_MAX_NUMBEROF_POWER_BLOCK)
  1877. num_modes = ATOM_MAX_NUMBEROF_POWER_BLOCK;
  1878. if (num_modes == 0)
  1879. return state_index;
  1880. rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state) * num_modes, GFP_KERNEL);
  1881. if (!rdev->pm.power_state)
  1882. return state_index;
  1883. /* last mode is usually default, array is low to high */
  1884. for (i = 0; i < num_modes; i++) {
  1885. rdev->pm.power_state[state_index].clock_info =
  1886. kzalloc(sizeof(struct radeon_pm_clock_info) * 1, GFP_KERNEL);
  1887. if (!rdev->pm.power_state[state_index].clock_info)
  1888. return state_index;
  1889. rdev->pm.power_state[state_index].num_clock_modes = 1;
  1890. rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
  1891. switch (frev) {
  1892. case 1:
  1893. rdev->pm.power_state[state_index].clock_info[0].mclk =
  1894. le16_to_cpu(power_info->info.asPowerPlayInfo[i].usMemoryClock);
  1895. rdev->pm.power_state[state_index].clock_info[0].sclk =
  1896. le16_to_cpu(power_info->info.asPowerPlayInfo[i].usEngineClock);
  1897. /* skip invalid modes */
  1898. if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
  1899. (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
  1900. continue;
  1901. rdev->pm.power_state[state_index].pcie_lanes =
  1902. power_info->info.asPowerPlayInfo[i].ucNumPciELanes;
  1903. misc = le32_to_cpu(power_info->info.asPowerPlayInfo[i].ulMiscInfo);
  1904. if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
  1905. (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
  1906. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1907. VOLTAGE_GPIO;
  1908. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
  1909. radeon_lookup_gpio(rdev,
  1910. power_info->info.asPowerPlayInfo[i].ucVoltageDropIndex);
  1911. if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
  1912. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1913. true;
  1914. else
  1915. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1916. false;
  1917. } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
  1918. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1919. VOLTAGE_VDDC;
  1920. rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
  1921. power_info->info.asPowerPlayInfo[i].ucVoltageDropIndex;
  1922. }
  1923. rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1924. radeon_atombios_parse_misc_flags_1_3(rdev, state_index, misc, 0);
  1925. state_index++;
  1926. break;
  1927. case 2:
  1928. rdev->pm.power_state[state_index].clock_info[0].mclk =
  1929. le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMemoryClock);
  1930. rdev->pm.power_state[state_index].clock_info[0].sclk =
  1931. le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulEngineClock);
  1932. /* skip invalid modes */
  1933. if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
  1934. (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
  1935. continue;
  1936. rdev->pm.power_state[state_index].pcie_lanes =
  1937. power_info->info_2.asPowerPlayInfo[i].ucNumPciELanes;
  1938. misc = le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMiscInfo);
  1939. misc2 = le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMiscInfo2);
  1940. if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
  1941. (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
  1942. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1943. VOLTAGE_GPIO;
  1944. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
  1945. radeon_lookup_gpio(rdev,
  1946. power_info->info_2.asPowerPlayInfo[i].ucVoltageDropIndex);
  1947. if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
  1948. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1949. true;
  1950. else
  1951. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1952. false;
  1953. } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
  1954. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1955. VOLTAGE_VDDC;
  1956. rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
  1957. power_info->info_2.asPowerPlayInfo[i].ucVoltageDropIndex;
  1958. }
  1959. rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  1960. radeon_atombios_parse_misc_flags_1_3(rdev, state_index, misc, misc2);
  1961. state_index++;
  1962. break;
  1963. case 3:
  1964. rdev->pm.power_state[state_index].clock_info[0].mclk =
  1965. le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMemoryClock);
  1966. rdev->pm.power_state[state_index].clock_info[0].sclk =
  1967. le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulEngineClock);
  1968. /* skip invalid modes */
  1969. if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) ||
  1970. (rdev->pm.power_state[state_index].clock_info[0].sclk == 0))
  1971. continue;
  1972. rdev->pm.power_state[state_index].pcie_lanes =
  1973. power_info->info_3.asPowerPlayInfo[i].ucNumPciELanes;
  1974. misc = le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMiscInfo);
  1975. misc2 = le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMiscInfo2);
  1976. if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) ||
  1977. (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) {
  1978. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1979. VOLTAGE_GPIO;
  1980. rdev->pm.power_state[state_index].clock_info[0].voltage.gpio =
  1981. radeon_lookup_gpio(rdev,
  1982. power_info->info_3.asPowerPlayInfo[i].ucVoltageDropIndex);
  1983. if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)
  1984. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1985. true;
  1986. else
  1987. rdev->pm.power_state[state_index].clock_info[0].voltage.active_high =
  1988. false;
  1989. } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) {
  1990. rdev->pm.power_state[state_index].clock_info[0].voltage.type =
  1991. VOLTAGE_VDDC;
  1992. rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id =
  1993. power_info->info_3.asPowerPlayInfo[i].ucVoltageDropIndex;
  1994. if (misc2 & ATOM_PM_MISCINFO2_VDDCI_DYNAMIC_VOLTAGE_EN) {
  1995. rdev->pm.power_state[state_index].clock_info[0].voltage.vddci_enabled =
  1996. true;
  1997. rdev->pm.power_state[state_index].clock_info[0].voltage.vddci_id =
  1998. power_info->info_3.asPowerPlayInfo[i].ucVDDCI_VoltageDropIndex;
  1999. }
  2000. }
  2001. rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  2002. radeon_atombios_parse_misc_flags_1_3(rdev, state_index, misc, misc2);
  2003. state_index++;
  2004. break;
  2005. }
  2006. }
  2007. /* last mode is usually default */
  2008. if (rdev->pm.default_power_state_index == -1) {
  2009. rdev->pm.power_state[state_index - 1].type =
  2010. POWER_STATE_TYPE_DEFAULT;
  2011. rdev->pm.default_power_state_index = state_index - 1;
  2012. rdev->pm.power_state[state_index - 1].default_clock_mode =
  2013. &rdev->pm.power_state[state_index - 1].clock_info[0];
  2014. rdev->pm.power_state[state_index].flags &=
  2015. ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  2016. rdev->pm.power_state[state_index].misc = 0;
  2017. rdev->pm.power_state[state_index].misc2 = 0;
  2018. }
  2019. return state_index;
  2020. }
  2021. static void radeon_atombios_add_pplib_thermal_controller(struct radeon_device *rdev,
  2022. ATOM_PPLIB_THERMALCONTROLLER *controller)
  2023. {
  2024. struct radeon_i2c_bus_rec i2c_bus;
  2025. /* add the i2c bus for thermal/fan chip */
  2026. if (controller->ucType > 0) {
  2027. if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV6xx) {
  2028. DRM_INFO("Internal thermal controller %s fan control\n",
  2029. (controller->ucFanParameters &
  2030. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  2031. rdev->pm.int_thermal_type = THERMAL_TYPE_RV6XX;
  2032. } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV770) {
  2033. DRM_INFO("Internal thermal controller %s fan control\n",
  2034. (controller->ucFanParameters &
  2035. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  2036. rdev->pm.int_thermal_type = THERMAL_TYPE_RV770;
  2037. } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_EVERGREEN) {
  2038. DRM_INFO("Internal thermal controller %s fan control\n",
  2039. (controller->ucFanParameters &
  2040. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  2041. rdev->pm.int_thermal_type = THERMAL_TYPE_EVERGREEN;
  2042. } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_SUMO) {
  2043. DRM_INFO("Internal thermal controller %s fan control\n",
  2044. (controller->ucFanParameters &
  2045. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  2046. rdev->pm.int_thermal_type = THERMAL_TYPE_SUMO;
  2047. } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_NISLANDS) {
  2048. DRM_INFO("Internal thermal controller %s fan control\n",
  2049. (controller->ucFanParameters &
  2050. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  2051. rdev->pm.int_thermal_type = THERMAL_TYPE_NI;
  2052. } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_SISLANDS) {
  2053. DRM_INFO("Internal thermal controller %s fan control\n",
  2054. (controller->ucFanParameters &
  2055. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  2056. rdev->pm.int_thermal_type = THERMAL_TYPE_SI;
  2057. } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_CISLANDS) {
  2058. DRM_INFO("Internal thermal controller %s fan control\n",
  2059. (controller->ucFanParameters &
  2060. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  2061. rdev->pm.int_thermal_type = THERMAL_TYPE_CI;
  2062. } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_KAVERI) {
  2063. DRM_INFO("Internal thermal controller %s fan control\n",
  2064. (controller->ucFanParameters &
  2065. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  2066. rdev->pm.int_thermal_type = THERMAL_TYPE_KV;
  2067. } else if (controller->ucType ==
  2068. ATOM_PP_THERMALCONTROLLER_EXTERNAL_GPIO) {
  2069. DRM_INFO("External GPIO thermal controller %s fan control\n",
  2070. (controller->ucFanParameters &
  2071. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  2072. rdev->pm.int_thermal_type = THERMAL_TYPE_EXTERNAL_GPIO;
  2073. } else if (controller->ucType ==
  2074. ATOM_PP_THERMALCONTROLLER_ADT7473_WITH_INTERNAL) {
  2075. DRM_INFO("ADT7473 with internal thermal controller %s fan control\n",
  2076. (controller->ucFanParameters &
  2077. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  2078. rdev->pm.int_thermal_type = THERMAL_TYPE_ADT7473_WITH_INTERNAL;
  2079. } else if (controller->ucType ==
  2080. ATOM_PP_THERMALCONTROLLER_EMC2103_WITH_INTERNAL) {
  2081. DRM_INFO("EMC2103 with internal thermal controller %s fan control\n",
  2082. (controller->ucFanParameters &
  2083. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  2084. rdev->pm.int_thermal_type = THERMAL_TYPE_EMC2103_WITH_INTERNAL;
  2085. } else if (controller->ucType < ARRAY_SIZE(pp_lib_thermal_controller_names)) {
  2086. DRM_INFO("Possible %s thermal controller at 0x%02x %s fan control\n",
  2087. pp_lib_thermal_controller_names[controller->ucType],
  2088. controller->ucI2cAddress >> 1,
  2089. (controller->ucFanParameters &
  2090. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  2091. rdev->pm.int_thermal_type = THERMAL_TYPE_EXTERNAL;
  2092. i2c_bus = radeon_lookup_i2c_gpio(rdev, controller->ucI2cLine);
  2093. rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus);
  2094. if (rdev->pm.i2c_bus) {
  2095. struct i2c_board_info info = { };
  2096. const char *name = pp_lib_thermal_controller_names[controller->ucType];
  2097. info.addr = controller->ucI2cAddress >> 1;
  2098. strlcpy(info.type, name, sizeof(info.type));
  2099. i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
  2100. }
  2101. } else {
  2102. DRM_INFO("Unknown thermal controller type %d at 0x%02x %s fan control\n",
  2103. controller->ucType,
  2104. controller->ucI2cAddress >> 1,
  2105. (controller->ucFanParameters &
  2106. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  2107. }
  2108. }
  2109. }
  2110. void radeon_atombios_get_default_voltages(struct radeon_device *rdev,
  2111. u16 *vddc, u16 *vddci, u16 *mvdd)
  2112. {
  2113. struct radeon_mode_info *mode_info = &rdev->mode_info;
  2114. int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
  2115. u8 frev, crev;
  2116. u16 data_offset;
  2117. union firmware_info *firmware_info;
  2118. *vddc = 0;
  2119. *vddci = 0;
  2120. *mvdd = 0;
  2121. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  2122. &frev, &crev, &data_offset)) {
  2123. firmware_info =
  2124. (union firmware_info *)(mode_info->atom_context->bios +
  2125. data_offset);
  2126. *vddc = le16_to_cpu(firmware_info->info_14.usBootUpVDDCVoltage);
  2127. if ((frev == 2) && (crev >= 2)) {
  2128. *vddci = le16_to_cpu(firmware_info->info_22.usBootUpVDDCIVoltage);
  2129. *mvdd = le16_to_cpu(firmware_info->info_22.usBootUpMVDDCVoltage);
  2130. }
  2131. }
  2132. }
  2133. static void radeon_atombios_parse_pplib_non_clock_info(struct radeon_device *rdev,
  2134. int state_index, int mode_index,
  2135. struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info)
  2136. {
  2137. int j;
  2138. u32 misc = le32_to_cpu(non_clock_info->ulCapsAndSettings);
  2139. u32 misc2 = le16_to_cpu(non_clock_info->usClassification);
  2140. u16 vddc, vddci, mvdd;
  2141. radeon_atombios_get_default_voltages(rdev, &vddc, &vddci, &mvdd);
  2142. rdev->pm.power_state[state_index].misc = misc;
  2143. rdev->pm.power_state[state_index].misc2 = misc2;
  2144. rdev->pm.power_state[state_index].pcie_lanes =
  2145. ((misc & ATOM_PPLIB_PCIE_LINK_WIDTH_MASK) >>
  2146. ATOM_PPLIB_PCIE_LINK_WIDTH_SHIFT) + 1;
  2147. switch (misc2 & ATOM_PPLIB_CLASSIFICATION_UI_MASK) {
  2148. case ATOM_PPLIB_CLASSIFICATION_UI_BATTERY:
  2149. rdev->pm.power_state[state_index].type =
  2150. POWER_STATE_TYPE_BATTERY;
  2151. break;
  2152. case ATOM_PPLIB_CLASSIFICATION_UI_BALANCED:
  2153. rdev->pm.power_state[state_index].type =
  2154. POWER_STATE_TYPE_BALANCED;
  2155. break;
  2156. case ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE:
  2157. rdev->pm.power_state[state_index].type =
  2158. POWER_STATE_TYPE_PERFORMANCE;
  2159. break;
  2160. case ATOM_PPLIB_CLASSIFICATION_UI_NONE:
  2161. if (misc2 & ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE)
  2162. rdev->pm.power_state[state_index].type =
  2163. POWER_STATE_TYPE_PERFORMANCE;
  2164. break;
  2165. }
  2166. rdev->pm.power_state[state_index].flags = 0;
  2167. if (misc & ATOM_PPLIB_SINGLE_DISPLAY_ONLY)
  2168. rdev->pm.power_state[state_index].flags |=
  2169. RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
  2170. if (misc2 & ATOM_PPLIB_CLASSIFICATION_BOOT) {
  2171. rdev->pm.power_state[state_index].type =
  2172. POWER_STATE_TYPE_DEFAULT;
  2173. rdev->pm.default_power_state_index = state_index;
  2174. rdev->pm.power_state[state_index].default_clock_mode =
  2175. &rdev->pm.power_state[state_index].clock_info[mode_index - 1];
  2176. if ((rdev->family >= CHIP_BARTS) && !(rdev->flags & RADEON_IS_IGP)) {
  2177. /* NI chips post without MC ucode, so default clocks are strobe mode only */
  2178. rdev->pm.default_sclk = rdev->pm.power_state[state_index].clock_info[0].sclk;
  2179. rdev->pm.default_mclk = rdev->pm.power_state[state_index].clock_info[0].mclk;
  2180. rdev->pm.default_vddc = rdev->pm.power_state[state_index].clock_info[0].voltage.voltage;
  2181. rdev->pm.default_vddci = rdev->pm.power_state[state_index].clock_info[0].voltage.vddci;
  2182. } else {
  2183. u16 max_vddci = 0;
  2184. if (ASIC_IS_DCE4(rdev))
  2185. radeon_atom_get_max_voltage(rdev,
  2186. SET_VOLTAGE_TYPE_ASIC_VDDCI,
  2187. &max_vddci);
  2188. /* patch the table values with the default sclk/mclk from firmware info */
  2189. for (j = 0; j < mode_index; j++) {
  2190. rdev->pm.power_state[state_index].clock_info[j].mclk =
  2191. rdev->clock.default_mclk;
  2192. rdev->pm.power_state[state_index].clock_info[j].sclk =
  2193. rdev->clock.default_sclk;
  2194. if (vddc)
  2195. rdev->pm.power_state[state_index].clock_info[j].voltage.voltage =
  2196. vddc;
  2197. if (max_vddci)
  2198. rdev->pm.power_state[state_index].clock_info[j].voltage.vddci =
  2199. max_vddci;
  2200. }
  2201. }
  2202. }
  2203. }
  2204. static bool radeon_atombios_parse_pplib_clock_info(struct radeon_device *rdev,
  2205. int state_index, int mode_index,
  2206. union pplib_clock_info *clock_info)
  2207. {
  2208. u32 sclk, mclk;
  2209. u16 vddc;
  2210. if (rdev->flags & RADEON_IS_IGP) {
  2211. if (rdev->family >= CHIP_PALM) {
  2212. sclk = le16_to_cpu(clock_info->sumo.usEngineClockLow);
  2213. sclk |= clock_info->sumo.ucEngineClockHigh << 16;
  2214. rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
  2215. } else {
  2216. sclk = le16_to_cpu(clock_info->rs780.usLowEngineClockLow);
  2217. sclk |= clock_info->rs780.ucLowEngineClockHigh << 16;
  2218. rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
  2219. }
  2220. } else if (rdev->family >= CHIP_BONAIRE) {
  2221. sclk = le16_to_cpu(clock_info->ci.usEngineClockLow);
  2222. sclk |= clock_info->ci.ucEngineClockHigh << 16;
  2223. mclk = le16_to_cpu(clock_info->ci.usMemoryClockLow);
  2224. mclk |= clock_info->ci.ucMemoryClockHigh << 16;
  2225. rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
  2226. rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
  2227. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
  2228. VOLTAGE_NONE;
  2229. } else if (rdev->family >= CHIP_TAHITI) {
  2230. sclk = le16_to_cpu(clock_info->si.usEngineClockLow);
  2231. sclk |= clock_info->si.ucEngineClockHigh << 16;
  2232. mclk = le16_to_cpu(clock_info->si.usMemoryClockLow);
  2233. mclk |= clock_info->si.ucMemoryClockHigh << 16;
  2234. rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
  2235. rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
  2236. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
  2237. VOLTAGE_SW;
  2238. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
  2239. le16_to_cpu(clock_info->si.usVDDC);
  2240. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.vddci =
  2241. le16_to_cpu(clock_info->si.usVDDCI);
  2242. } else if (rdev->family >= CHIP_CEDAR) {
  2243. sclk = le16_to_cpu(clock_info->evergreen.usEngineClockLow);
  2244. sclk |= clock_info->evergreen.ucEngineClockHigh << 16;
  2245. mclk = le16_to_cpu(clock_info->evergreen.usMemoryClockLow);
  2246. mclk |= clock_info->evergreen.ucMemoryClockHigh << 16;
  2247. rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
  2248. rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
  2249. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
  2250. VOLTAGE_SW;
  2251. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
  2252. le16_to_cpu(clock_info->evergreen.usVDDC);
  2253. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.vddci =
  2254. le16_to_cpu(clock_info->evergreen.usVDDCI);
  2255. } else {
  2256. sclk = le16_to_cpu(clock_info->r600.usEngineClockLow);
  2257. sclk |= clock_info->r600.ucEngineClockHigh << 16;
  2258. mclk = le16_to_cpu(clock_info->r600.usMemoryClockLow);
  2259. mclk |= clock_info->r600.ucMemoryClockHigh << 16;
  2260. rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
  2261. rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
  2262. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
  2263. VOLTAGE_SW;
  2264. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
  2265. le16_to_cpu(clock_info->r600.usVDDC);
  2266. }
  2267. /* patch up vddc if necessary */
  2268. switch (rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage) {
  2269. case ATOM_VIRTUAL_VOLTAGE_ID0:
  2270. case ATOM_VIRTUAL_VOLTAGE_ID1:
  2271. case ATOM_VIRTUAL_VOLTAGE_ID2:
  2272. case ATOM_VIRTUAL_VOLTAGE_ID3:
  2273. case ATOM_VIRTUAL_VOLTAGE_ID4:
  2274. case ATOM_VIRTUAL_VOLTAGE_ID5:
  2275. case ATOM_VIRTUAL_VOLTAGE_ID6:
  2276. case ATOM_VIRTUAL_VOLTAGE_ID7:
  2277. if (radeon_atom_get_max_vddc(rdev, VOLTAGE_TYPE_VDDC,
  2278. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage,
  2279. &vddc) == 0)
  2280. rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage = vddc;
  2281. break;
  2282. default:
  2283. break;
  2284. }
  2285. if (rdev->flags & RADEON_IS_IGP) {
  2286. /* skip invalid modes */
  2287. if (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0)
  2288. return false;
  2289. } else {
  2290. /* skip invalid modes */
  2291. if ((rdev->pm.power_state[state_index].clock_info[mode_index].mclk == 0) ||
  2292. (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0))
  2293. return false;
  2294. }
  2295. return true;
  2296. }
  2297. static int radeon_atombios_parse_power_table_4_5(struct radeon_device *rdev)
  2298. {
  2299. struct radeon_mode_info *mode_info = &rdev->mode_info;
  2300. struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
  2301. union pplib_power_state *power_state;
  2302. int i, j;
  2303. int state_index = 0, mode_index = 0;
  2304. union pplib_clock_info *clock_info;
  2305. bool valid;
  2306. union power_info *power_info;
  2307. int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
  2308. u16 data_offset;
  2309. u8 frev, crev;
  2310. if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
  2311. &frev, &crev, &data_offset))
  2312. return state_index;
  2313. power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
  2314. radeon_atombios_add_pplib_thermal_controller(rdev, &power_info->pplib.sThermalController);
  2315. if (power_info->pplib.ucNumStates == 0)
  2316. return state_index;
  2317. rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state) *
  2318. power_info->pplib.ucNumStates, GFP_KERNEL);
  2319. if (!rdev->pm.power_state)
  2320. return state_index;
  2321. /* first mode is usually default, followed by low to high */
  2322. for (i = 0; i < power_info->pplib.ucNumStates; i++) {
  2323. mode_index = 0;
  2324. power_state = (union pplib_power_state *)
  2325. (mode_info->atom_context->bios + data_offset +
  2326. le16_to_cpu(power_info->pplib.usStateArrayOffset) +
  2327. i * power_info->pplib.ucStateEntrySize);
  2328. non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
  2329. (mode_info->atom_context->bios + data_offset +
  2330. le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset) +
  2331. (power_state->v1.ucNonClockStateIndex *
  2332. power_info->pplib.ucNonClockSize));
  2333. rdev->pm.power_state[i].clock_info = kzalloc(sizeof(struct radeon_pm_clock_info) *
  2334. ((power_info->pplib.ucStateEntrySize - 1) ?
  2335. (power_info->pplib.ucStateEntrySize - 1) : 1),
  2336. GFP_KERNEL);
  2337. if (!rdev->pm.power_state[i].clock_info)
  2338. return state_index;
  2339. if (power_info->pplib.ucStateEntrySize - 1) {
  2340. for (j = 0; j < (power_info->pplib.ucStateEntrySize - 1); j++) {
  2341. clock_info = (union pplib_clock_info *)
  2342. (mode_info->atom_context->bios + data_offset +
  2343. le16_to_cpu(power_info->pplib.usClockInfoArrayOffset) +
  2344. (power_state->v1.ucClockStateIndices[j] *
  2345. power_info->pplib.ucClockInfoSize));
  2346. valid = radeon_atombios_parse_pplib_clock_info(rdev,
  2347. state_index, mode_index,
  2348. clock_info);
  2349. if (valid)
  2350. mode_index++;
  2351. }
  2352. } else {
  2353. rdev->pm.power_state[state_index].clock_info[0].mclk =
  2354. rdev->clock.default_mclk;
  2355. rdev->pm.power_state[state_index].clock_info[0].sclk =
  2356. rdev->clock.default_sclk;
  2357. mode_index++;
  2358. }
  2359. rdev->pm.power_state[state_index].num_clock_modes = mode_index;
  2360. if (mode_index) {
  2361. radeon_atombios_parse_pplib_non_clock_info(rdev, state_index, mode_index,
  2362. non_clock_info);
  2363. state_index++;
  2364. }
  2365. }
  2366. /* if multiple clock modes, mark the lowest as no display */
  2367. for (i = 0; i < state_index; i++) {
  2368. if (rdev->pm.power_state[i].num_clock_modes > 1)
  2369. rdev->pm.power_state[i].clock_info[0].flags |=
  2370. RADEON_PM_MODE_NO_DISPLAY;
  2371. }
  2372. /* first mode is usually default */
  2373. if (rdev->pm.default_power_state_index == -1) {
  2374. rdev->pm.power_state[0].type =
  2375. POWER_STATE_TYPE_DEFAULT;
  2376. rdev->pm.default_power_state_index = 0;
  2377. rdev->pm.power_state[0].default_clock_mode =
  2378. &rdev->pm.power_state[0].clock_info[0];
  2379. }
  2380. return state_index;
  2381. }
  2382. static int radeon_atombios_parse_power_table_6(struct radeon_device *rdev)
  2383. {
  2384. struct radeon_mode_info *mode_info = &rdev->mode_info;
  2385. struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
  2386. union pplib_power_state *power_state;
  2387. int i, j, non_clock_array_index, clock_array_index;
  2388. int state_index = 0, mode_index = 0;
  2389. union pplib_clock_info *clock_info;
  2390. struct _StateArray *state_array;
  2391. struct _ClockInfoArray *clock_info_array;
  2392. struct _NonClockInfoArray *non_clock_info_array;
  2393. bool valid;
  2394. union power_info *power_info;
  2395. int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
  2396. u16 data_offset;
  2397. u8 frev, crev;
  2398. u8 *power_state_offset;
  2399. if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
  2400. &frev, &crev, &data_offset))
  2401. return state_index;
  2402. power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
  2403. radeon_atombios_add_pplib_thermal_controller(rdev, &power_info->pplib.sThermalController);
  2404. state_array = (struct _StateArray *)
  2405. (mode_info->atom_context->bios + data_offset +
  2406. le16_to_cpu(power_info->pplib.usStateArrayOffset));
  2407. clock_info_array = (struct _ClockInfoArray *)
  2408. (mode_info->atom_context->bios + data_offset +
  2409. le16_to_cpu(power_info->pplib.usClockInfoArrayOffset));
  2410. non_clock_info_array = (struct _NonClockInfoArray *)
  2411. (mode_info->atom_context->bios + data_offset +
  2412. le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset));
  2413. if (state_array->ucNumEntries == 0)
  2414. return state_index;
  2415. rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state) *
  2416. state_array->ucNumEntries, GFP_KERNEL);
  2417. if (!rdev->pm.power_state)
  2418. return state_index;
  2419. power_state_offset = (u8 *)state_array->states;
  2420. for (i = 0; i < state_array->ucNumEntries; i++) {
  2421. mode_index = 0;
  2422. power_state = (union pplib_power_state *)power_state_offset;
  2423. non_clock_array_index = power_state->v2.nonClockInfoIndex;
  2424. non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
  2425. &non_clock_info_array->nonClockInfo[non_clock_array_index];
  2426. rdev->pm.power_state[i].clock_info = kzalloc(sizeof(struct radeon_pm_clock_info) *
  2427. (power_state->v2.ucNumDPMLevels ?
  2428. power_state->v2.ucNumDPMLevels : 1),
  2429. GFP_KERNEL);
  2430. if (!rdev->pm.power_state[i].clock_info)
  2431. return state_index;
  2432. if (power_state->v2.ucNumDPMLevels) {
  2433. for (j = 0; j < power_state->v2.ucNumDPMLevels; j++) {
  2434. clock_array_index = power_state->v2.clockInfoIndex[j];
  2435. clock_info = (union pplib_clock_info *)
  2436. &clock_info_array->clockInfo[clock_array_index * clock_info_array->ucEntrySize];
  2437. valid = radeon_atombios_parse_pplib_clock_info(rdev,
  2438. state_index, mode_index,
  2439. clock_info);
  2440. if (valid)
  2441. mode_index++;
  2442. }
  2443. } else {
  2444. rdev->pm.power_state[state_index].clock_info[0].mclk =
  2445. rdev->clock.default_mclk;
  2446. rdev->pm.power_state[state_index].clock_info[0].sclk =
  2447. rdev->clock.default_sclk;
  2448. mode_index++;
  2449. }
  2450. rdev->pm.power_state[state_index].num_clock_modes = mode_index;
  2451. if (mode_index) {
  2452. radeon_atombios_parse_pplib_non_clock_info(rdev, state_index, mode_index,
  2453. non_clock_info);
  2454. state_index++;
  2455. }
  2456. power_state_offset += 2 + power_state->v2.ucNumDPMLevels;
  2457. }
  2458. /* if multiple clock modes, mark the lowest as no display */
  2459. for (i = 0; i < state_index; i++) {
  2460. if (rdev->pm.power_state[i].num_clock_modes > 1)
  2461. rdev->pm.power_state[i].clock_info[0].flags |=
  2462. RADEON_PM_MODE_NO_DISPLAY;
  2463. }
  2464. /* first mode is usually default */
  2465. if (rdev->pm.default_power_state_index == -1) {
  2466. rdev->pm.power_state[0].type =
  2467. POWER_STATE_TYPE_DEFAULT;
  2468. rdev->pm.default_power_state_index = 0;
  2469. rdev->pm.power_state[0].default_clock_mode =
  2470. &rdev->pm.power_state[0].clock_info[0];
  2471. }
  2472. return state_index;
  2473. }
  2474. void radeon_atombios_get_power_modes(struct radeon_device *rdev)
  2475. {
  2476. struct radeon_mode_info *mode_info = &rdev->mode_info;
  2477. int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
  2478. u16 data_offset;
  2479. u8 frev, crev;
  2480. int state_index = 0;
  2481. rdev->pm.default_power_state_index = -1;
  2482. if (atom_parse_data_header(mode_info->atom_context, index, NULL,
  2483. &frev, &crev, &data_offset)) {
  2484. switch (frev) {
  2485. case 1:
  2486. case 2:
  2487. case 3:
  2488. state_index = radeon_atombios_parse_power_table_1_3(rdev);
  2489. break;
  2490. case 4:
  2491. case 5:
  2492. state_index = radeon_atombios_parse_power_table_4_5(rdev);
  2493. break;
  2494. case 6:
  2495. state_index = radeon_atombios_parse_power_table_6(rdev);
  2496. break;
  2497. default:
  2498. break;
  2499. }
  2500. }
  2501. if (state_index == 0) {
  2502. rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state), GFP_KERNEL);
  2503. if (rdev->pm.power_state) {
  2504. rdev->pm.power_state[0].clock_info =
  2505. kzalloc(sizeof(struct radeon_pm_clock_info) * 1, GFP_KERNEL);
  2506. if (rdev->pm.power_state[0].clock_info) {
  2507. /* add the default mode */
  2508. rdev->pm.power_state[state_index].type =
  2509. POWER_STATE_TYPE_DEFAULT;
  2510. rdev->pm.power_state[state_index].num_clock_modes = 1;
  2511. rdev->pm.power_state[state_index].clock_info[0].mclk = rdev->clock.default_mclk;
  2512. rdev->pm.power_state[state_index].clock_info[0].sclk = rdev->clock.default_sclk;
  2513. rdev->pm.power_state[state_index].default_clock_mode =
  2514. &rdev->pm.power_state[state_index].clock_info[0];
  2515. rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
  2516. rdev->pm.power_state[state_index].pcie_lanes = 16;
  2517. rdev->pm.default_power_state_index = state_index;
  2518. rdev->pm.power_state[state_index].flags = 0;
  2519. state_index++;
  2520. }
  2521. }
  2522. }
  2523. rdev->pm.num_power_states = state_index;
  2524. rdev->pm.current_power_state_index = rdev->pm.default_power_state_index;
  2525. rdev->pm.current_clock_mode_index = 0;
  2526. if (rdev->pm.default_power_state_index >= 0)
  2527. rdev->pm.current_vddc =
  2528. rdev->pm.power_state[rdev->pm.default_power_state_index].clock_info[0].voltage.voltage;
  2529. else
  2530. rdev->pm.current_vddc = 0;
  2531. }
  2532. union get_clock_dividers {
  2533. struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS v1;
  2534. struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_V2 v2;
  2535. struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_V3 v3;
  2536. struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_V4 v4;
  2537. struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_V5 v5;
  2538. struct _COMPUTE_GPU_CLOCK_INPUT_PARAMETERS_V1_6 v6_in;
  2539. struct _COMPUTE_GPU_CLOCK_OUTPUT_PARAMETERS_V1_6 v6_out;
  2540. };
  2541. int radeon_atom_get_clock_dividers(struct radeon_device *rdev,
  2542. u8 clock_type,
  2543. u32 clock,
  2544. bool strobe_mode,
  2545. struct atom_clock_dividers *dividers)
  2546. {
  2547. union get_clock_dividers args;
  2548. int index = GetIndexIntoMasterTable(COMMAND, ComputeMemoryEnginePLL);
  2549. u8 frev, crev;
  2550. memset(&args, 0, sizeof(args));
  2551. memset(dividers, 0, sizeof(struct atom_clock_dividers));
  2552. if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
  2553. return -EINVAL;
  2554. switch (crev) {
  2555. case 1:
  2556. /* r4xx, r5xx */
  2557. args.v1.ucAction = clock_type;
  2558. args.v1.ulClock = cpu_to_le32(clock); /* 10 khz */
  2559. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2560. dividers->post_div = args.v1.ucPostDiv;
  2561. dividers->fb_div = args.v1.ucFbDiv;
  2562. dividers->enable_post_div = true;
  2563. break;
  2564. case 2:
  2565. case 3:
  2566. case 5:
  2567. /* r6xx, r7xx, evergreen, ni, si */
  2568. if (rdev->family <= CHIP_RV770) {
  2569. args.v2.ucAction = clock_type;
  2570. args.v2.ulClock = cpu_to_le32(clock); /* 10 khz */
  2571. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2572. dividers->post_div = args.v2.ucPostDiv;
  2573. dividers->fb_div = le16_to_cpu(args.v2.usFbDiv);
  2574. dividers->ref_div = args.v2.ucAction;
  2575. if (rdev->family == CHIP_RV770) {
  2576. dividers->enable_post_div = (le32_to_cpu(args.v2.ulClock) & (1 << 24)) ?
  2577. true : false;
  2578. dividers->vco_mode = (le32_to_cpu(args.v2.ulClock) & (1 << 25)) ? 1 : 0;
  2579. } else
  2580. dividers->enable_post_div = (dividers->fb_div & 1) ? true : false;
  2581. } else {
  2582. if (clock_type == COMPUTE_ENGINE_PLL_PARAM) {
  2583. args.v3.ulClockParams = cpu_to_le32((clock_type << 24) | clock);
  2584. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2585. dividers->post_div = args.v3.ucPostDiv;
  2586. dividers->enable_post_div = (args.v3.ucCntlFlag &
  2587. ATOM_PLL_CNTL_FLAG_PLL_POST_DIV_EN) ? true : false;
  2588. dividers->enable_dithen = (args.v3.ucCntlFlag &
  2589. ATOM_PLL_CNTL_FLAG_FRACTION_DISABLE) ? false : true;
  2590. dividers->whole_fb_div = le16_to_cpu(args.v3.ulFbDiv.usFbDiv);
  2591. dividers->frac_fb_div = le16_to_cpu(args.v3.ulFbDiv.usFbDivFrac);
  2592. dividers->ref_div = args.v3.ucRefDiv;
  2593. dividers->vco_mode = (args.v3.ucCntlFlag &
  2594. ATOM_PLL_CNTL_FLAG_MPLL_VCO_MODE) ? 1 : 0;
  2595. } else {
  2596. /* for SI we use ComputeMemoryClockParam for memory plls */
  2597. if (rdev->family >= CHIP_TAHITI)
  2598. return -EINVAL;
  2599. args.v5.ulClockParams = cpu_to_le32((clock_type << 24) | clock);
  2600. if (strobe_mode)
  2601. args.v5.ucInputFlag = ATOM_PLL_INPUT_FLAG_PLL_STROBE_MODE_EN;
  2602. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2603. dividers->post_div = args.v5.ucPostDiv;
  2604. dividers->enable_post_div = (args.v5.ucCntlFlag &
  2605. ATOM_PLL_CNTL_FLAG_PLL_POST_DIV_EN) ? true : false;
  2606. dividers->enable_dithen = (args.v5.ucCntlFlag &
  2607. ATOM_PLL_CNTL_FLAG_FRACTION_DISABLE) ? false : true;
  2608. dividers->whole_fb_div = le16_to_cpu(args.v5.ulFbDiv.usFbDiv);
  2609. dividers->frac_fb_div = le16_to_cpu(args.v5.ulFbDiv.usFbDivFrac);
  2610. dividers->ref_div = args.v5.ucRefDiv;
  2611. dividers->vco_mode = (args.v5.ucCntlFlag &
  2612. ATOM_PLL_CNTL_FLAG_MPLL_VCO_MODE) ? 1 : 0;
  2613. }
  2614. }
  2615. break;
  2616. case 4:
  2617. /* fusion */
  2618. args.v4.ulClock = cpu_to_le32(clock); /* 10 khz */
  2619. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2620. dividers->post_divider = dividers->post_div = args.v4.ucPostDiv;
  2621. dividers->real_clock = le32_to_cpu(args.v4.ulClock);
  2622. break;
  2623. case 6:
  2624. /* CI */
  2625. /* COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK, COMPUTE_GPUCLK_INPUT_FLAG_SCLK */
  2626. args.v6_in.ulClock.ulComputeClockFlag = clock_type;
  2627. args.v6_in.ulClock.ulClockFreq = cpu_to_le32(clock); /* 10 khz */
  2628. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2629. dividers->whole_fb_div = le16_to_cpu(args.v6_out.ulFbDiv.usFbDiv);
  2630. dividers->frac_fb_div = le16_to_cpu(args.v6_out.ulFbDiv.usFbDivFrac);
  2631. dividers->ref_div = args.v6_out.ucPllRefDiv;
  2632. dividers->post_div = args.v6_out.ucPllPostDiv;
  2633. dividers->flags = args.v6_out.ucPllCntlFlag;
  2634. dividers->real_clock = le32_to_cpu(args.v6_out.ulClock.ulClock);
  2635. dividers->post_divider = args.v6_out.ulClock.ucPostDiv;
  2636. break;
  2637. default:
  2638. return -EINVAL;
  2639. }
  2640. return 0;
  2641. }
  2642. int radeon_atom_get_memory_pll_dividers(struct radeon_device *rdev,
  2643. u32 clock,
  2644. bool strobe_mode,
  2645. struct atom_mpll_param *mpll_param)
  2646. {
  2647. COMPUTE_MEMORY_CLOCK_PARAM_PARAMETERS_V2_1 args;
  2648. int index = GetIndexIntoMasterTable(COMMAND, ComputeMemoryClockParam);
  2649. u8 frev, crev;
  2650. memset(&args, 0, sizeof(args));
  2651. memset(mpll_param, 0, sizeof(struct atom_mpll_param));
  2652. if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
  2653. return -EINVAL;
  2654. switch (frev) {
  2655. case 2:
  2656. switch (crev) {
  2657. case 1:
  2658. /* SI */
  2659. args.ulClock = cpu_to_le32(clock); /* 10 khz */
  2660. args.ucInputFlag = 0;
  2661. if (strobe_mode)
  2662. args.ucInputFlag |= MPLL_INPUT_FLAG_STROBE_MODE_EN;
  2663. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2664. mpll_param->clkfrac = le16_to_cpu(args.ulFbDiv.usFbDivFrac);
  2665. mpll_param->clkf = le16_to_cpu(args.ulFbDiv.usFbDiv);
  2666. mpll_param->post_div = args.ucPostDiv;
  2667. mpll_param->dll_speed = args.ucDllSpeed;
  2668. mpll_param->bwcntl = args.ucBWCntl;
  2669. mpll_param->vco_mode =
  2670. (args.ucPllCntlFlag & MPLL_CNTL_FLAG_VCO_MODE_MASK);
  2671. mpll_param->yclk_sel =
  2672. (args.ucPllCntlFlag & MPLL_CNTL_FLAG_BYPASS_DQ_PLL) ? 1 : 0;
  2673. mpll_param->qdr =
  2674. (args.ucPllCntlFlag & MPLL_CNTL_FLAG_QDR_ENABLE) ? 1 : 0;
  2675. mpll_param->half_rate =
  2676. (args.ucPllCntlFlag & MPLL_CNTL_FLAG_AD_HALF_RATE) ? 1 : 0;
  2677. break;
  2678. default:
  2679. return -EINVAL;
  2680. }
  2681. break;
  2682. default:
  2683. return -EINVAL;
  2684. }
  2685. return 0;
  2686. }
  2687. void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable)
  2688. {
  2689. DYNAMIC_CLOCK_GATING_PS_ALLOCATION args;
  2690. int index = GetIndexIntoMasterTable(COMMAND, DynamicClockGating);
  2691. args.ucEnable = enable;
  2692. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2693. }
  2694. uint32_t radeon_atom_get_engine_clock(struct radeon_device *rdev)
  2695. {
  2696. GET_ENGINE_CLOCK_PS_ALLOCATION args;
  2697. int index = GetIndexIntoMasterTable(COMMAND, GetEngineClock);
  2698. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2699. return le32_to_cpu(args.ulReturnEngineClock);
  2700. }
  2701. uint32_t radeon_atom_get_memory_clock(struct radeon_device *rdev)
  2702. {
  2703. GET_MEMORY_CLOCK_PS_ALLOCATION args;
  2704. int index = GetIndexIntoMasterTable(COMMAND, GetMemoryClock);
  2705. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2706. return le32_to_cpu(args.ulReturnMemoryClock);
  2707. }
  2708. void radeon_atom_set_engine_clock(struct radeon_device *rdev,
  2709. uint32_t eng_clock)
  2710. {
  2711. SET_ENGINE_CLOCK_PS_ALLOCATION args;
  2712. int index = GetIndexIntoMasterTable(COMMAND, SetEngineClock);
  2713. args.ulTargetEngineClock = cpu_to_le32(eng_clock); /* 10 khz */
  2714. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2715. }
  2716. void radeon_atom_set_memory_clock(struct radeon_device *rdev,
  2717. uint32_t mem_clock)
  2718. {
  2719. SET_MEMORY_CLOCK_PS_ALLOCATION args;
  2720. int index = GetIndexIntoMasterTable(COMMAND, SetMemoryClock);
  2721. if (rdev->flags & RADEON_IS_IGP)
  2722. return;
  2723. args.ulTargetMemoryClock = cpu_to_le32(mem_clock); /* 10 khz */
  2724. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2725. }
  2726. void radeon_atom_set_engine_dram_timings(struct radeon_device *rdev,
  2727. u32 eng_clock, u32 mem_clock)
  2728. {
  2729. SET_ENGINE_CLOCK_PS_ALLOCATION args;
  2730. int index = GetIndexIntoMasterTable(COMMAND, DynamicMemorySettings);
  2731. u32 tmp;
  2732. memset(&args, 0, sizeof(args));
  2733. tmp = eng_clock & SET_CLOCK_FREQ_MASK;
  2734. tmp |= (COMPUTE_ENGINE_PLL_PARAM << 24);
  2735. args.ulTargetEngineClock = cpu_to_le32(tmp);
  2736. if (mem_clock)
  2737. args.sReserved.ulClock = cpu_to_le32(mem_clock & SET_CLOCK_FREQ_MASK);
  2738. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2739. }
  2740. void radeon_atom_update_memory_dll(struct radeon_device *rdev,
  2741. u32 mem_clock)
  2742. {
  2743. u32 args;
  2744. int index = GetIndexIntoMasterTable(COMMAND, DynamicMemorySettings);
  2745. args = cpu_to_le32(mem_clock); /* 10 khz */
  2746. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2747. }
  2748. void radeon_atom_set_ac_timing(struct radeon_device *rdev,
  2749. u32 mem_clock)
  2750. {
  2751. SET_MEMORY_CLOCK_PS_ALLOCATION args;
  2752. int index = GetIndexIntoMasterTable(COMMAND, DynamicMemorySettings);
  2753. u32 tmp = mem_clock | (COMPUTE_MEMORY_PLL_PARAM << 24);
  2754. args.ulTargetMemoryClock = cpu_to_le32(tmp); /* 10 khz */
  2755. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2756. }
  2757. union set_voltage {
  2758. struct _SET_VOLTAGE_PS_ALLOCATION alloc;
  2759. struct _SET_VOLTAGE_PARAMETERS v1;
  2760. struct _SET_VOLTAGE_PARAMETERS_V2 v2;
  2761. struct _SET_VOLTAGE_PARAMETERS_V1_3 v3;
  2762. };
  2763. void radeon_atom_set_voltage(struct radeon_device *rdev, u16 voltage_level, u8 voltage_type)
  2764. {
  2765. union set_voltage args;
  2766. int index = GetIndexIntoMasterTable(COMMAND, SetVoltage);
  2767. u8 frev, crev, volt_index = voltage_level;
  2768. if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
  2769. return;
  2770. /* 0xff01 is a flag rather then an actual voltage */
  2771. if (voltage_level == 0xff01)
  2772. return;
  2773. switch (crev) {
  2774. case 1:
  2775. args.v1.ucVoltageType = voltage_type;
  2776. args.v1.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_ALL_SOURCE;
  2777. args.v1.ucVoltageIndex = volt_index;
  2778. break;
  2779. case 2:
  2780. args.v2.ucVoltageType = voltage_type;
  2781. args.v2.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_SET_VOLTAGE;
  2782. args.v2.usVoltageLevel = cpu_to_le16(voltage_level);
  2783. break;
  2784. case 3:
  2785. args.v3.ucVoltageType = voltage_type;
  2786. args.v3.ucVoltageMode = ATOM_SET_VOLTAGE;
  2787. args.v3.usVoltageLevel = cpu_to_le16(voltage_level);
  2788. break;
  2789. default:
  2790. DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
  2791. return;
  2792. }
  2793. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2794. }
  2795. int radeon_atom_get_max_vddc(struct radeon_device *rdev, u8 voltage_type,
  2796. u16 voltage_id, u16 *voltage)
  2797. {
  2798. union set_voltage args;
  2799. int index = GetIndexIntoMasterTable(COMMAND, SetVoltage);
  2800. u8 frev, crev;
  2801. if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
  2802. return -EINVAL;
  2803. switch (crev) {
  2804. case 1:
  2805. return -EINVAL;
  2806. case 2:
  2807. args.v2.ucVoltageType = SET_VOLTAGE_GET_MAX_VOLTAGE;
  2808. args.v2.ucVoltageMode = 0;
  2809. args.v2.usVoltageLevel = 0;
  2810. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2811. *voltage = le16_to_cpu(args.v2.usVoltageLevel);
  2812. break;
  2813. case 3:
  2814. args.v3.ucVoltageType = voltage_type;
  2815. args.v3.ucVoltageMode = ATOM_GET_VOLTAGE_LEVEL;
  2816. args.v3.usVoltageLevel = cpu_to_le16(voltage_id);
  2817. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2818. *voltage = le16_to_cpu(args.v3.usVoltageLevel);
  2819. break;
  2820. default:
  2821. DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
  2822. return -EINVAL;
  2823. }
  2824. return 0;
  2825. }
  2826. int radeon_atom_get_leakage_vddc_based_on_leakage_idx(struct radeon_device *rdev,
  2827. u16 *voltage,
  2828. u16 leakage_idx)
  2829. {
  2830. return radeon_atom_get_max_vddc(rdev, VOLTAGE_TYPE_VDDC, leakage_idx, voltage);
  2831. }
  2832. int radeon_atom_get_leakage_id_from_vbios(struct radeon_device *rdev,
  2833. u16 *leakage_id)
  2834. {
  2835. union set_voltage args;
  2836. int index = GetIndexIntoMasterTable(COMMAND, SetVoltage);
  2837. u8 frev, crev;
  2838. if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
  2839. return -EINVAL;
  2840. switch (crev) {
  2841. case 3:
  2842. case 4:
  2843. args.v3.ucVoltageType = 0;
  2844. args.v3.ucVoltageMode = ATOM_GET_LEAKAGE_ID;
  2845. args.v3.usVoltageLevel = 0;
  2846. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2847. *leakage_id = le16_to_cpu(args.v3.usVoltageLevel);
  2848. break;
  2849. default:
  2850. DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
  2851. return -EINVAL;
  2852. }
  2853. return 0;
  2854. }
  2855. int radeon_atom_get_leakage_vddc_based_on_leakage_params(struct radeon_device *rdev,
  2856. u16 *vddc, u16 *vddci,
  2857. u16 virtual_voltage_id,
  2858. u16 vbios_voltage_id)
  2859. {
  2860. int index = GetIndexIntoMasterTable(DATA, ASIC_ProfilingInfo);
  2861. u8 frev, crev;
  2862. u16 data_offset, size;
  2863. int i, j;
  2864. ATOM_ASIC_PROFILING_INFO_V2_1 *profile;
  2865. u16 *leakage_bin, *vddc_id_buf, *vddc_buf, *vddci_id_buf, *vddci_buf;
  2866. *vddc = 0;
  2867. *vddci = 0;
  2868. if (!atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
  2869. &frev, &crev, &data_offset))
  2870. return -EINVAL;
  2871. profile = (ATOM_ASIC_PROFILING_INFO_V2_1 *)
  2872. (rdev->mode_info.atom_context->bios + data_offset);
  2873. switch (frev) {
  2874. case 1:
  2875. return -EINVAL;
  2876. case 2:
  2877. switch (crev) {
  2878. case 1:
  2879. if (size < sizeof(ATOM_ASIC_PROFILING_INFO_V2_1))
  2880. return -EINVAL;
  2881. leakage_bin = (u16 *)
  2882. (rdev->mode_info.atom_context->bios + data_offset +
  2883. le16_to_cpu(profile->usLeakageBinArrayOffset));
  2884. vddc_id_buf = (u16 *)
  2885. (rdev->mode_info.atom_context->bios + data_offset +
  2886. le16_to_cpu(profile->usElbVDDC_IdArrayOffset));
  2887. vddc_buf = (u16 *)
  2888. (rdev->mode_info.atom_context->bios + data_offset +
  2889. le16_to_cpu(profile->usElbVDDC_LevelArrayOffset));
  2890. vddci_id_buf = (u16 *)
  2891. (rdev->mode_info.atom_context->bios + data_offset +
  2892. le16_to_cpu(profile->usElbVDDCI_IdArrayOffset));
  2893. vddci_buf = (u16 *)
  2894. (rdev->mode_info.atom_context->bios + data_offset +
  2895. le16_to_cpu(profile->usElbVDDCI_LevelArrayOffset));
  2896. if (profile->ucElbVDDC_Num > 0) {
  2897. for (i = 0; i < profile->ucElbVDDC_Num; i++) {
  2898. if (vddc_id_buf[i] == virtual_voltage_id) {
  2899. for (j = 0; j < profile->ucLeakageBinNum; j++) {
  2900. if (vbios_voltage_id <= leakage_bin[j]) {
  2901. *vddc = vddc_buf[j * profile->ucElbVDDC_Num + i];
  2902. break;
  2903. }
  2904. }
  2905. break;
  2906. }
  2907. }
  2908. }
  2909. if (profile->ucElbVDDCI_Num > 0) {
  2910. for (i = 0; i < profile->ucElbVDDCI_Num; i++) {
  2911. if (vddci_id_buf[i] == virtual_voltage_id) {
  2912. for (j = 0; j < profile->ucLeakageBinNum; j++) {
  2913. if (vbios_voltage_id <= leakage_bin[j]) {
  2914. *vddci = vddci_buf[j * profile->ucElbVDDCI_Num + i];
  2915. break;
  2916. }
  2917. }
  2918. break;
  2919. }
  2920. }
  2921. }
  2922. break;
  2923. default:
  2924. DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
  2925. return -EINVAL;
  2926. }
  2927. break;
  2928. default:
  2929. DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
  2930. return -EINVAL;
  2931. }
  2932. return 0;
  2933. }
  2934. union get_voltage_info {
  2935. struct _GET_VOLTAGE_INFO_INPUT_PARAMETER_V1_2 in;
  2936. struct _GET_EVV_VOLTAGE_INFO_OUTPUT_PARAMETER_V1_2 evv_out;
  2937. };
  2938. int radeon_atom_get_voltage_evv(struct radeon_device *rdev,
  2939. u16 virtual_voltage_id,
  2940. u16 *voltage)
  2941. {
  2942. int index = GetIndexIntoMasterTable(COMMAND, GetVoltageInfo);
  2943. u32 entry_id;
  2944. u32 count = rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk.count;
  2945. union get_voltage_info args;
  2946. for (entry_id = 0; entry_id < count; entry_id++) {
  2947. if (rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk.entries[entry_id].v ==
  2948. virtual_voltage_id)
  2949. break;
  2950. }
  2951. if (entry_id >= count)
  2952. return -EINVAL;
  2953. args.in.ucVoltageType = VOLTAGE_TYPE_VDDC;
  2954. args.in.ucVoltageMode = ATOM_GET_VOLTAGE_EVV_VOLTAGE;
  2955. args.in.usVoltageLevel = cpu_to_le16(virtual_voltage_id);
  2956. args.in.ulSCLKFreq =
  2957. cpu_to_le32(rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk.entries[entry_id].clk);
  2958. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2959. *voltage = le16_to_cpu(args.evv_out.usVoltageLevel);
  2960. return 0;
  2961. }
  2962. int radeon_atom_get_voltage_gpio_settings(struct radeon_device *rdev,
  2963. u16 voltage_level, u8 voltage_type,
  2964. u32 *gpio_value, u32 *gpio_mask)
  2965. {
  2966. union set_voltage args;
  2967. int index = GetIndexIntoMasterTable(COMMAND, SetVoltage);
  2968. u8 frev, crev;
  2969. if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev))
  2970. return -EINVAL;
  2971. switch (crev) {
  2972. case 1:
  2973. return -EINVAL;
  2974. case 2:
  2975. args.v2.ucVoltageType = voltage_type;
  2976. args.v2.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_GET_GPIOMASK;
  2977. args.v2.usVoltageLevel = cpu_to_le16(voltage_level);
  2978. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2979. *gpio_mask = le32_to_cpu(*(u32 *)&args.v2);
  2980. args.v2.ucVoltageType = voltage_type;
  2981. args.v2.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_GET_GPIOVAL;
  2982. args.v2.usVoltageLevel = cpu_to_le16(voltage_level);
  2983. atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
  2984. *gpio_value = le32_to_cpu(*(u32 *)&args.v2);
  2985. break;
  2986. default:
  2987. DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
  2988. return -EINVAL;
  2989. }
  2990. return 0;
  2991. }
  2992. union voltage_object_info {
  2993. struct _ATOM_VOLTAGE_OBJECT_INFO v1;
  2994. struct _ATOM_VOLTAGE_OBJECT_INFO_V2 v2;
  2995. struct _ATOM_VOLTAGE_OBJECT_INFO_V3_1 v3;
  2996. };
  2997. union voltage_object {
  2998. struct _ATOM_VOLTAGE_OBJECT v1;
  2999. struct _ATOM_VOLTAGE_OBJECT_V2 v2;
  3000. union _ATOM_VOLTAGE_OBJECT_V3 v3;
  3001. };
  3002. static ATOM_VOLTAGE_OBJECT *atom_lookup_voltage_object_v1(ATOM_VOLTAGE_OBJECT_INFO *v1,
  3003. u8 voltage_type)
  3004. {
  3005. u32 size = le16_to_cpu(v1->sHeader.usStructureSize);
  3006. u32 offset = offsetof(ATOM_VOLTAGE_OBJECT_INFO, asVoltageObj[0]);
  3007. u8 *start = (u8 *)v1;
  3008. while (offset < size) {
  3009. ATOM_VOLTAGE_OBJECT *vo = (ATOM_VOLTAGE_OBJECT *)(start + offset);
  3010. if (vo->ucVoltageType == voltage_type)
  3011. return vo;
  3012. offset += offsetof(ATOM_VOLTAGE_OBJECT, asFormula.ucVIDAdjustEntries) +
  3013. vo->asFormula.ucNumOfVoltageEntries;
  3014. }
  3015. return NULL;
  3016. }
  3017. static ATOM_VOLTAGE_OBJECT_V2 *atom_lookup_voltage_object_v2(ATOM_VOLTAGE_OBJECT_INFO_V2 *v2,
  3018. u8 voltage_type)
  3019. {
  3020. u32 size = le16_to_cpu(v2->sHeader.usStructureSize);
  3021. u32 offset = offsetof(ATOM_VOLTAGE_OBJECT_INFO_V2, asVoltageObj[0]);
  3022. u8 *start = (u8*)v2;
  3023. while (offset < size) {
  3024. ATOM_VOLTAGE_OBJECT_V2 *vo = (ATOM_VOLTAGE_OBJECT_V2 *)(start + offset);
  3025. if (vo->ucVoltageType == voltage_type)
  3026. return vo;
  3027. offset += offsetof(ATOM_VOLTAGE_OBJECT_V2, asFormula.asVIDAdjustEntries) +
  3028. (vo->asFormula.ucNumOfVoltageEntries * sizeof(VOLTAGE_LUT_ENTRY));
  3029. }
  3030. return NULL;
  3031. }
  3032. static ATOM_VOLTAGE_OBJECT_V3 *atom_lookup_voltage_object_v3(ATOM_VOLTAGE_OBJECT_INFO_V3_1 *v3,
  3033. u8 voltage_type, u8 voltage_mode)
  3034. {
  3035. u32 size = le16_to_cpu(v3->sHeader.usStructureSize);
  3036. u32 offset = offsetof(ATOM_VOLTAGE_OBJECT_INFO_V3_1, asVoltageObj[0]);
  3037. u8 *start = (u8*)v3;
  3038. while (offset < size) {
  3039. ATOM_VOLTAGE_OBJECT_V3 *vo = (ATOM_VOLTAGE_OBJECT_V3 *)(start + offset);
  3040. if ((vo->asGpioVoltageObj.sHeader.ucVoltageType == voltage_type) &&
  3041. (vo->asGpioVoltageObj.sHeader.ucVoltageMode == voltage_mode))
  3042. return vo;
  3043. offset += le16_to_cpu(vo->asGpioVoltageObj.sHeader.usSize);
  3044. }
  3045. return NULL;
  3046. }
  3047. bool
  3048. radeon_atom_is_voltage_gpio(struct radeon_device *rdev,
  3049. u8 voltage_type, u8 voltage_mode)
  3050. {
  3051. int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo);
  3052. u8 frev, crev;
  3053. u16 data_offset, size;
  3054. union voltage_object_info *voltage_info;
  3055. union voltage_object *voltage_object = NULL;
  3056. if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
  3057. &frev, &crev, &data_offset)) {
  3058. voltage_info = (union voltage_object_info *)
  3059. (rdev->mode_info.atom_context->bios + data_offset);
  3060. switch (frev) {
  3061. case 1:
  3062. case 2:
  3063. switch (crev) {
  3064. case 1:
  3065. voltage_object = (union voltage_object *)
  3066. atom_lookup_voltage_object_v1(&voltage_info->v1, voltage_type);
  3067. if (voltage_object &&
  3068. (voltage_object->v1.asControl.ucVoltageControlId == VOLTAGE_CONTROLLED_BY_GPIO))
  3069. return true;
  3070. break;
  3071. case 2:
  3072. voltage_object = (union voltage_object *)
  3073. atom_lookup_voltage_object_v2(&voltage_info->v2, voltage_type);
  3074. if (voltage_object &&
  3075. (voltage_object->v2.asControl.ucVoltageControlId == VOLTAGE_CONTROLLED_BY_GPIO))
  3076. return true;
  3077. break;
  3078. default:
  3079. DRM_ERROR("unknown voltage object table\n");
  3080. return false;
  3081. }
  3082. break;
  3083. case 3:
  3084. switch (crev) {
  3085. case 1:
  3086. if (atom_lookup_voltage_object_v3(&voltage_info->v3,
  3087. voltage_type, voltage_mode))
  3088. return true;
  3089. break;
  3090. default:
  3091. DRM_ERROR("unknown voltage object table\n");
  3092. return false;
  3093. }
  3094. break;
  3095. default:
  3096. DRM_ERROR("unknown voltage object table\n");
  3097. return false;
  3098. }
  3099. }
  3100. return false;
  3101. }
  3102. int radeon_atom_get_svi2_info(struct radeon_device *rdev,
  3103. u8 voltage_type,
  3104. u8 *svd_gpio_id, u8 *svc_gpio_id)
  3105. {
  3106. int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo);
  3107. u8 frev, crev;
  3108. u16 data_offset, size;
  3109. union voltage_object_info *voltage_info;
  3110. union voltage_object *voltage_object = NULL;
  3111. if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
  3112. &frev, &crev, &data_offset)) {
  3113. voltage_info = (union voltage_object_info *)
  3114. (rdev->mode_info.atom_context->bios + data_offset);
  3115. switch (frev) {
  3116. case 3:
  3117. switch (crev) {
  3118. case 1:
  3119. voltage_object = (union voltage_object *)
  3120. atom_lookup_voltage_object_v3(&voltage_info->v3,
  3121. voltage_type,
  3122. VOLTAGE_OBJ_SVID2);
  3123. if (voltage_object) {
  3124. *svd_gpio_id = voltage_object->v3.asSVID2Obj.ucSVDGpioId;
  3125. *svc_gpio_id = voltage_object->v3.asSVID2Obj.ucSVCGpioId;
  3126. } else {
  3127. return -EINVAL;
  3128. }
  3129. break;
  3130. default:
  3131. DRM_ERROR("unknown voltage object table\n");
  3132. return -EINVAL;
  3133. }
  3134. break;
  3135. default:
  3136. DRM_ERROR("unknown voltage object table\n");
  3137. return -EINVAL;
  3138. }
  3139. }
  3140. return 0;
  3141. }
  3142. int radeon_atom_get_max_voltage(struct radeon_device *rdev,
  3143. u8 voltage_type, u16 *max_voltage)
  3144. {
  3145. int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo);
  3146. u8 frev, crev;
  3147. u16 data_offset, size;
  3148. union voltage_object_info *voltage_info;
  3149. union voltage_object *voltage_object = NULL;
  3150. if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
  3151. &frev, &crev, &data_offset)) {
  3152. voltage_info = (union voltage_object_info *)
  3153. (rdev->mode_info.atom_context->bios + data_offset);
  3154. switch (crev) {
  3155. case 1:
  3156. voltage_object = (union voltage_object *)
  3157. atom_lookup_voltage_object_v1(&voltage_info->v1, voltage_type);
  3158. if (voltage_object) {
  3159. ATOM_VOLTAGE_FORMULA *formula =
  3160. &voltage_object->v1.asFormula;
  3161. if (formula->ucFlag & 1)
  3162. *max_voltage =
  3163. le16_to_cpu(formula->usVoltageBaseLevel) +
  3164. formula->ucNumOfVoltageEntries / 2 *
  3165. le16_to_cpu(formula->usVoltageStep);
  3166. else
  3167. *max_voltage =
  3168. le16_to_cpu(formula->usVoltageBaseLevel) +
  3169. (formula->ucNumOfVoltageEntries - 1) *
  3170. le16_to_cpu(formula->usVoltageStep);
  3171. return 0;
  3172. }
  3173. break;
  3174. case 2:
  3175. voltage_object = (union voltage_object *)
  3176. atom_lookup_voltage_object_v2(&voltage_info->v2, voltage_type);
  3177. if (voltage_object) {
  3178. ATOM_VOLTAGE_FORMULA_V2 *formula =
  3179. &voltage_object->v2.asFormula;
  3180. if (formula->ucNumOfVoltageEntries) {
  3181. VOLTAGE_LUT_ENTRY *lut = (VOLTAGE_LUT_ENTRY *)
  3182. ((u8 *)&formula->asVIDAdjustEntries[0] +
  3183. (sizeof(VOLTAGE_LUT_ENTRY) * (formula->ucNumOfVoltageEntries - 1)));
  3184. *max_voltage =
  3185. le16_to_cpu(lut->usVoltageValue);
  3186. return 0;
  3187. }
  3188. }
  3189. break;
  3190. default:
  3191. DRM_ERROR("unknown voltage object table\n");
  3192. return -EINVAL;
  3193. }
  3194. }
  3195. return -EINVAL;
  3196. }
  3197. int radeon_atom_get_min_voltage(struct radeon_device *rdev,
  3198. u8 voltage_type, u16 *min_voltage)
  3199. {
  3200. int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo);
  3201. u8 frev, crev;
  3202. u16 data_offset, size;
  3203. union voltage_object_info *voltage_info;
  3204. union voltage_object *voltage_object = NULL;
  3205. if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
  3206. &frev, &crev, &data_offset)) {
  3207. voltage_info = (union voltage_object_info *)
  3208. (rdev->mode_info.atom_context->bios + data_offset);
  3209. switch (crev) {
  3210. case 1:
  3211. voltage_object = (union voltage_object *)
  3212. atom_lookup_voltage_object_v1(&voltage_info->v1, voltage_type);
  3213. if (voltage_object) {
  3214. ATOM_VOLTAGE_FORMULA *formula =
  3215. &voltage_object->v1.asFormula;
  3216. *min_voltage =
  3217. le16_to_cpu(formula->usVoltageBaseLevel);
  3218. return 0;
  3219. }
  3220. break;
  3221. case 2:
  3222. voltage_object = (union voltage_object *)
  3223. atom_lookup_voltage_object_v2(&voltage_info->v2, voltage_type);
  3224. if (voltage_object) {
  3225. ATOM_VOLTAGE_FORMULA_V2 *formula =
  3226. &voltage_object->v2.asFormula;
  3227. if (formula->ucNumOfVoltageEntries) {
  3228. *min_voltage =
  3229. le16_to_cpu(formula->asVIDAdjustEntries[
  3230. 0
  3231. ].usVoltageValue);
  3232. return 0;
  3233. }
  3234. }
  3235. break;
  3236. default:
  3237. DRM_ERROR("unknown voltage object table\n");
  3238. return -EINVAL;
  3239. }
  3240. }
  3241. return -EINVAL;
  3242. }
  3243. int radeon_atom_get_voltage_step(struct radeon_device *rdev,
  3244. u8 voltage_type, u16 *voltage_step)
  3245. {
  3246. int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo);
  3247. u8 frev, crev;
  3248. u16 data_offset, size;
  3249. union voltage_object_info *voltage_info;
  3250. union voltage_object *voltage_object = NULL;
  3251. if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
  3252. &frev, &crev, &data_offset)) {
  3253. voltage_info = (union voltage_object_info *)
  3254. (rdev->mode_info.atom_context->bios + data_offset);
  3255. switch (crev) {
  3256. case 1:
  3257. voltage_object = (union voltage_object *)
  3258. atom_lookup_voltage_object_v1(&voltage_info->v1, voltage_type);
  3259. if (voltage_object) {
  3260. ATOM_VOLTAGE_FORMULA *formula =
  3261. &voltage_object->v1.asFormula;
  3262. if (formula->ucFlag & 1)
  3263. *voltage_step =
  3264. (le16_to_cpu(formula->usVoltageStep) + 1) / 2;
  3265. else
  3266. *voltage_step =
  3267. le16_to_cpu(formula->usVoltageStep);
  3268. return 0;
  3269. }
  3270. break;
  3271. case 2:
  3272. return -EINVAL;
  3273. default:
  3274. DRM_ERROR("unknown voltage object table\n");
  3275. return -EINVAL;
  3276. }
  3277. }
  3278. return -EINVAL;
  3279. }
  3280. int radeon_atom_round_to_true_voltage(struct radeon_device *rdev,
  3281. u8 voltage_type,
  3282. u16 nominal_voltage,
  3283. u16 *true_voltage)
  3284. {
  3285. u16 min_voltage, max_voltage, voltage_step;
  3286. if (radeon_atom_get_max_voltage(rdev, voltage_type, &max_voltage))
  3287. return -EINVAL;
  3288. if (radeon_atom_get_min_voltage(rdev, voltage_type, &min_voltage))
  3289. return -EINVAL;
  3290. if (radeon_atom_get_voltage_step(rdev, voltage_type, &voltage_step))
  3291. return -EINVAL;
  3292. if (nominal_voltage <= min_voltage)
  3293. *true_voltage = min_voltage;
  3294. else if (nominal_voltage >= max_voltage)
  3295. *true_voltage = max_voltage;
  3296. else
  3297. *true_voltage = min_voltage +
  3298. ((nominal_voltage - min_voltage) / voltage_step) *
  3299. voltage_step;
  3300. return 0;
  3301. }
  3302. int radeon_atom_get_voltage_table(struct radeon_device *rdev,
  3303. u8 voltage_type, u8 voltage_mode,
  3304. struct atom_voltage_table *voltage_table)
  3305. {
  3306. int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo);
  3307. u8 frev, crev;
  3308. u16 data_offset, size;
  3309. int i, ret;
  3310. union voltage_object_info *voltage_info;
  3311. union voltage_object *voltage_object = NULL;
  3312. if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
  3313. &frev, &crev, &data_offset)) {
  3314. voltage_info = (union voltage_object_info *)
  3315. (rdev->mode_info.atom_context->bios + data_offset);
  3316. switch (frev) {
  3317. case 1:
  3318. case 2:
  3319. switch (crev) {
  3320. case 1:
  3321. DRM_ERROR("old table version %d, %d\n", frev, crev);
  3322. return -EINVAL;
  3323. case 2:
  3324. voltage_object = (union voltage_object *)
  3325. atom_lookup_voltage_object_v2(&voltage_info->v2, voltage_type);
  3326. if (voltage_object) {
  3327. ATOM_VOLTAGE_FORMULA_V2 *formula =
  3328. &voltage_object->v2.asFormula;
  3329. VOLTAGE_LUT_ENTRY *lut;
  3330. if (formula->ucNumOfVoltageEntries > MAX_VOLTAGE_ENTRIES)
  3331. return -EINVAL;
  3332. lut = &formula->asVIDAdjustEntries[0];
  3333. for (i = 0; i < formula->ucNumOfVoltageEntries; i++) {
  3334. voltage_table->entries[i].value =
  3335. le16_to_cpu(lut->usVoltageValue);
  3336. ret = radeon_atom_get_voltage_gpio_settings(rdev,
  3337. voltage_table->entries[i].value,
  3338. voltage_type,
  3339. &voltage_table->entries[i].smio_low,
  3340. &voltage_table->mask_low);
  3341. if (ret)
  3342. return ret;
  3343. lut = (VOLTAGE_LUT_ENTRY *)
  3344. ((u8 *)lut + sizeof(VOLTAGE_LUT_ENTRY));
  3345. }
  3346. voltage_table->count = formula->ucNumOfVoltageEntries;
  3347. return 0;
  3348. }
  3349. break;
  3350. default:
  3351. DRM_ERROR("unknown voltage object table\n");
  3352. return -EINVAL;
  3353. }
  3354. break;
  3355. case 3:
  3356. switch (crev) {
  3357. case 1:
  3358. voltage_object = (union voltage_object *)
  3359. atom_lookup_voltage_object_v3(&voltage_info->v3,
  3360. voltage_type, voltage_mode);
  3361. if (voltage_object) {
  3362. ATOM_GPIO_VOLTAGE_OBJECT_V3 *gpio =
  3363. &voltage_object->v3.asGpioVoltageObj;
  3364. VOLTAGE_LUT_ENTRY_V2 *lut;
  3365. if (gpio->ucGpioEntryNum > MAX_VOLTAGE_ENTRIES)
  3366. return -EINVAL;
  3367. lut = &gpio->asVolGpioLut[0];
  3368. for (i = 0; i < gpio->ucGpioEntryNum; i++) {
  3369. voltage_table->entries[i].value =
  3370. le16_to_cpu(lut->usVoltageValue);
  3371. voltage_table->entries[i].smio_low =
  3372. le32_to_cpu(lut->ulVoltageId);
  3373. lut = (VOLTAGE_LUT_ENTRY_V2 *)
  3374. ((u8 *)lut + sizeof(VOLTAGE_LUT_ENTRY_V2));
  3375. }
  3376. voltage_table->mask_low = le32_to_cpu(gpio->ulGpioMaskVal);
  3377. voltage_table->count = gpio->ucGpioEntryNum;
  3378. voltage_table->phase_delay = gpio->ucPhaseDelay;
  3379. return 0;
  3380. }
  3381. break;
  3382. default:
  3383. DRM_ERROR("unknown voltage object table\n");
  3384. return -EINVAL;
  3385. }
  3386. break;
  3387. default:
  3388. DRM_ERROR("unknown voltage object table\n");
  3389. return -EINVAL;
  3390. }
  3391. }
  3392. return -EINVAL;
  3393. }
  3394. union vram_info {
  3395. struct _ATOM_VRAM_INFO_V3 v1_3;
  3396. struct _ATOM_VRAM_INFO_V4 v1_4;
  3397. struct _ATOM_VRAM_INFO_HEADER_V2_1 v2_1;
  3398. };
  3399. int radeon_atom_get_memory_info(struct radeon_device *rdev,
  3400. u8 module_index, struct atom_memory_info *mem_info)
  3401. {
  3402. int index = GetIndexIntoMasterTable(DATA, VRAM_Info);
  3403. u8 frev, crev, i;
  3404. u16 data_offset, size;
  3405. union vram_info *vram_info;
  3406. memset(mem_info, 0, sizeof(struct atom_memory_info));
  3407. if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
  3408. &frev, &crev, &data_offset)) {
  3409. vram_info = (union vram_info *)
  3410. (rdev->mode_info.atom_context->bios + data_offset);
  3411. switch (frev) {
  3412. case 1:
  3413. switch (crev) {
  3414. case 3:
  3415. /* r6xx */
  3416. if (module_index < vram_info->v1_3.ucNumOfVRAMModule) {
  3417. ATOM_VRAM_MODULE_V3 *vram_module =
  3418. (ATOM_VRAM_MODULE_V3 *)vram_info->v1_3.aVramInfo;
  3419. for (i = 0; i < module_index; i++) {
  3420. if (le16_to_cpu(vram_module->usSize) == 0)
  3421. return -EINVAL;
  3422. vram_module = (ATOM_VRAM_MODULE_V3 *)
  3423. ((u8 *)vram_module + le16_to_cpu(vram_module->usSize));
  3424. }
  3425. mem_info->mem_vendor = vram_module->asMemory.ucMemoryVenderID & 0xf;
  3426. mem_info->mem_type = vram_module->asMemory.ucMemoryType & 0xf0;
  3427. } else
  3428. return -EINVAL;
  3429. break;
  3430. case 4:
  3431. /* r7xx, evergreen */
  3432. if (module_index < vram_info->v1_4.ucNumOfVRAMModule) {
  3433. ATOM_VRAM_MODULE_V4 *vram_module =
  3434. (ATOM_VRAM_MODULE_V4 *)vram_info->v1_4.aVramInfo;
  3435. for (i = 0; i < module_index; i++) {
  3436. if (le16_to_cpu(vram_module->usModuleSize) == 0)
  3437. return -EINVAL;
  3438. vram_module = (ATOM_VRAM_MODULE_V4 *)
  3439. ((u8 *)vram_module + le16_to_cpu(vram_module->usModuleSize));
  3440. }
  3441. mem_info->mem_vendor = vram_module->ucMemoryVenderID & 0xf;
  3442. mem_info->mem_type = vram_module->ucMemoryType & 0xf0;
  3443. } else
  3444. return -EINVAL;
  3445. break;
  3446. default:
  3447. DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
  3448. return -EINVAL;
  3449. }
  3450. break;
  3451. case 2:
  3452. switch (crev) {
  3453. case 1:
  3454. /* ni */
  3455. if (module_index < vram_info->v2_1.ucNumOfVRAMModule) {
  3456. ATOM_VRAM_MODULE_V7 *vram_module =
  3457. (ATOM_VRAM_MODULE_V7 *)vram_info->v2_1.aVramInfo;
  3458. for (i = 0; i < module_index; i++) {
  3459. if (le16_to_cpu(vram_module->usModuleSize) == 0)
  3460. return -EINVAL;
  3461. vram_module = (ATOM_VRAM_MODULE_V7 *)
  3462. ((u8 *)vram_module + le16_to_cpu(vram_module->usModuleSize));
  3463. }
  3464. mem_info->mem_vendor = vram_module->ucMemoryVenderID & 0xf;
  3465. mem_info->mem_type = vram_module->ucMemoryType & 0xf0;
  3466. } else
  3467. return -EINVAL;
  3468. break;
  3469. default:
  3470. DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
  3471. return -EINVAL;
  3472. }
  3473. break;
  3474. default:
  3475. DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
  3476. return -EINVAL;
  3477. }
  3478. return 0;
  3479. }
  3480. return -EINVAL;
  3481. }
  3482. int radeon_atom_get_mclk_range_table(struct radeon_device *rdev,
  3483. bool gddr5, u8 module_index,
  3484. struct atom_memory_clock_range_table *mclk_range_table)
  3485. {
  3486. int index = GetIndexIntoMasterTable(DATA, VRAM_Info);
  3487. u8 frev, crev, i;
  3488. u16 data_offset, size;
  3489. union vram_info *vram_info;
  3490. u32 mem_timing_size = gddr5 ?
  3491. sizeof(ATOM_MEMORY_TIMING_FORMAT_V2) : sizeof(ATOM_MEMORY_TIMING_FORMAT);
  3492. memset(mclk_range_table, 0, sizeof(struct atom_memory_clock_range_table));
  3493. if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
  3494. &frev, &crev, &data_offset)) {
  3495. vram_info = (union vram_info *)
  3496. (rdev->mode_info.atom_context->bios + data_offset);
  3497. switch (frev) {
  3498. case 1:
  3499. switch (crev) {
  3500. case 3:
  3501. DRM_ERROR("old table version %d, %d\n", frev, crev);
  3502. return -EINVAL;
  3503. case 4:
  3504. /* r7xx, evergreen */
  3505. if (module_index < vram_info->v1_4.ucNumOfVRAMModule) {
  3506. ATOM_VRAM_MODULE_V4 *vram_module =
  3507. (ATOM_VRAM_MODULE_V4 *)vram_info->v1_4.aVramInfo;
  3508. ATOM_MEMORY_TIMING_FORMAT *format;
  3509. for (i = 0; i < module_index; i++) {
  3510. if (le16_to_cpu(vram_module->usModuleSize) == 0)
  3511. return -EINVAL;
  3512. vram_module = (ATOM_VRAM_MODULE_V4 *)
  3513. ((u8 *)vram_module + le16_to_cpu(vram_module->usModuleSize));
  3514. }
  3515. mclk_range_table->num_entries = (u8)
  3516. ((le16_to_cpu(vram_module->usModuleSize) - offsetof(ATOM_VRAM_MODULE_V4, asMemTiming)) /
  3517. mem_timing_size);
  3518. format = &vram_module->asMemTiming[0];
  3519. for (i = 0; i < mclk_range_table->num_entries; i++) {
  3520. mclk_range_table->mclk[i] = le32_to_cpu(format->ulClkRange);
  3521. format = (ATOM_MEMORY_TIMING_FORMAT *)
  3522. ((u8 *)format + mem_timing_size);
  3523. }
  3524. } else
  3525. return -EINVAL;
  3526. break;
  3527. default:
  3528. DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
  3529. return -EINVAL;
  3530. }
  3531. break;
  3532. case 2:
  3533. DRM_ERROR("new table version %d, %d\n", frev, crev);
  3534. return -EINVAL;
  3535. default:
  3536. DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
  3537. return -EINVAL;
  3538. }
  3539. return 0;
  3540. }
  3541. return -EINVAL;
  3542. }
  3543. #define MEM_ID_MASK 0xff000000
  3544. #define MEM_ID_SHIFT 24
  3545. #define CLOCK_RANGE_MASK 0x00ffffff
  3546. #define CLOCK_RANGE_SHIFT 0
  3547. #define LOW_NIBBLE_MASK 0xf
  3548. #define DATA_EQU_PREV 0
  3549. #define DATA_FROM_TABLE 4
  3550. int radeon_atom_init_mc_reg_table(struct radeon_device *rdev,
  3551. u8 module_index,
  3552. struct atom_mc_reg_table *reg_table)
  3553. {
  3554. int index = GetIndexIntoMasterTable(DATA, VRAM_Info);
  3555. u8 frev, crev, num_entries, t_mem_id, num_ranges = 0;
  3556. u32 i = 0, j;
  3557. u16 data_offset, size;
  3558. union vram_info *vram_info;
  3559. memset(reg_table, 0, sizeof(struct atom_mc_reg_table));
  3560. if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size,
  3561. &frev, &crev, &data_offset)) {
  3562. vram_info = (union vram_info *)
  3563. (rdev->mode_info.atom_context->bios + data_offset);
  3564. switch (frev) {
  3565. case 1:
  3566. DRM_ERROR("old table version %d, %d\n", frev, crev);
  3567. return -EINVAL;
  3568. case 2:
  3569. switch (crev) {
  3570. case 1:
  3571. if (module_index < vram_info->v2_1.ucNumOfVRAMModule) {
  3572. ATOM_INIT_REG_BLOCK *reg_block =
  3573. (ATOM_INIT_REG_BLOCK *)
  3574. ((u8 *)vram_info + le16_to_cpu(vram_info->v2_1.usMemClkPatchTblOffset));
  3575. ATOM_MEMORY_SETTING_DATA_BLOCK *reg_data =
  3576. (ATOM_MEMORY_SETTING_DATA_BLOCK *)
  3577. ((u8 *)reg_block + (2 * sizeof(u16)) +
  3578. le16_to_cpu(reg_block->usRegIndexTblSize));
  3579. ATOM_INIT_REG_INDEX_FORMAT *format = &reg_block->asRegIndexBuf[0];
  3580. num_entries = (u8)((le16_to_cpu(reg_block->usRegIndexTblSize)) /
  3581. sizeof(ATOM_INIT_REG_INDEX_FORMAT)) - 1;
  3582. if (num_entries > VBIOS_MC_REGISTER_ARRAY_SIZE)
  3583. return -EINVAL;
  3584. while (i < num_entries) {
  3585. if (format->ucPreRegDataLength & ACCESS_PLACEHOLDER)
  3586. break;
  3587. reg_table->mc_reg_address[i].s1 =
  3588. (u16)(le16_to_cpu(format->usRegIndex));
  3589. reg_table->mc_reg_address[i].pre_reg_data =
  3590. (u8)(format->ucPreRegDataLength);
  3591. i++;
  3592. format = (ATOM_INIT_REG_INDEX_FORMAT *)
  3593. ((u8 *)format + sizeof(ATOM_INIT_REG_INDEX_FORMAT));
  3594. }
  3595. reg_table->last = i;
  3596. while ((le32_to_cpu(*(u32 *)reg_data) != END_OF_REG_DATA_BLOCK) &&
  3597. (num_ranges < VBIOS_MAX_AC_TIMING_ENTRIES)) {
  3598. t_mem_id = (u8)((le32_to_cpu(*(u32 *)reg_data) & MEM_ID_MASK)
  3599. >> MEM_ID_SHIFT);
  3600. if (module_index == t_mem_id) {
  3601. reg_table->mc_reg_table_entry[num_ranges].mclk_max =
  3602. (u32)((le32_to_cpu(*(u32 *)reg_data) & CLOCK_RANGE_MASK)
  3603. >> CLOCK_RANGE_SHIFT);
  3604. for (i = 0, j = 1; i < reg_table->last; i++) {
  3605. if ((reg_table->mc_reg_address[i].pre_reg_data & LOW_NIBBLE_MASK) == DATA_FROM_TABLE) {
  3606. reg_table->mc_reg_table_entry[num_ranges].mc_data[i] =
  3607. (u32)le32_to_cpu(*((u32 *)reg_data + j));
  3608. j++;
  3609. } else if ((reg_table->mc_reg_address[i].pre_reg_data & LOW_NIBBLE_MASK) == DATA_EQU_PREV) {
  3610. reg_table->mc_reg_table_entry[num_ranges].mc_data[i] =
  3611. reg_table->mc_reg_table_entry[num_ranges].mc_data[i - 1];
  3612. }
  3613. }
  3614. num_ranges++;
  3615. }
  3616. reg_data = (ATOM_MEMORY_SETTING_DATA_BLOCK *)
  3617. ((u8 *)reg_data + le16_to_cpu(reg_block->usRegDataBlkSize));
  3618. }
  3619. if (le32_to_cpu(*(u32 *)reg_data) != END_OF_REG_DATA_BLOCK)
  3620. return -EINVAL;
  3621. reg_table->num_entries = num_ranges;
  3622. } else
  3623. return -EINVAL;
  3624. break;
  3625. default:
  3626. DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
  3627. return -EINVAL;
  3628. }
  3629. break;
  3630. default:
  3631. DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
  3632. return -EINVAL;
  3633. }
  3634. return 0;
  3635. }
  3636. return -EINVAL;
  3637. }
  3638. void radeon_atom_initialize_bios_scratch_regs(struct drm_device *dev)
  3639. {
  3640. struct radeon_device *rdev = dev->dev_private;
  3641. uint32_t bios_2_scratch, bios_6_scratch;
  3642. if (rdev->family >= CHIP_R600) {
  3643. bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
  3644. bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
  3645. } else {
  3646. bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
  3647. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  3648. }
  3649. /* let the bios control the backlight */
  3650. bios_2_scratch &= ~ATOM_S2_VRI_BRIGHT_ENABLE;
  3651. /* tell the bios not to handle mode switching */
  3652. bios_6_scratch |= ATOM_S6_ACC_BLOCK_DISPLAY_SWITCH;
  3653. /* clear the vbios dpms state */
  3654. if (ASIC_IS_DCE4(rdev))
  3655. bios_2_scratch &= ~ATOM_S2_DEVICE_DPMS_STATE;
  3656. if (rdev->family >= CHIP_R600) {
  3657. WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
  3658. WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
  3659. } else {
  3660. WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
  3661. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  3662. }
  3663. }
  3664. void radeon_save_bios_scratch_regs(struct radeon_device *rdev)
  3665. {
  3666. uint32_t scratch_reg;
  3667. int i;
  3668. if (rdev->family >= CHIP_R600)
  3669. scratch_reg = R600_BIOS_0_SCRATCH;
  3670. else
  3671. scratch_reg = RADEON_BIOS_0_SCRATCH;
  3672. for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
  3673. rdev->bios_scratch[i] = RREG32(scratch_reg + (i * 4));
  3674. }
  3675. void radeon_restore_bios_scratch_regs(struct radeon_device *rdev)
  3676. {
  3677. uint32_t scratch_reg;
  3678. int i;
  3679. if (rdev->family >= CHIP_R600)
  3680. scratch_reg = R600_BIOS_0_SCRATCH;
  3681. else
  3682. scratch_reg = RADEON_BIOS_0_SCRATCH;
  3683. for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++)
  3684. WREG32(scratch_reg + (i * 4), rdev->bios_scratch[i]);
  3685. }
  3686. void radeon_atom_output_lock(struct drm_encoder *encoder, bool lock)
  3687. {
  3688. struct drm_device *dev = encoder->dev;
  3689. struct radeon_device *rdev = dev->dev_private;
  3690. uint32_t bios_6_scratch;
  3691. if (rdev->family >= CHIP_R600)
  3692. bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
  3693. else
  3694. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  3695. if (lock) {
  3696. bios_6_scratch |= ATOM_S6_CRITICAL_STATE;
  3697. bios_6_scratch &= ~ATOM_S6_ACC_MODE;
  3698. } else {
  3699. bios_6_scratch &= ~ATOM_S6_CRITICAL_STATE;
  3700. bios_6_scratch |= ATOM_S6_ACC_MODE;
  3701. }
  3702. if (rdev->family >= CHIP_R600)
  3703. WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
  3704. else
  3705. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  3706. }
  3707. /* at some point we may want to break this out into individual functions */
  3708. void
  3709. radeon_atombios_connected_scratch_regs(struct drm_connector *connector,
  3710. struct drm_encoder *encoder,
  3711. bool connected)
  3712. {
  3713. struct drm_device *dev = connector->dev;
  3714. struct radeon_device *rdev = dev->dev_private;
  3715. struct radeon_connector *radeon_connector =
  3716. to_radeon_connector(connector);
  3717. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  3718. uint32_t bios_0_scratch, bios_3_scratch, bios_6_scratch;
  3719. if (rdev->family >= CHIP_R600) {
  3720. bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH);
  3721. bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
  3722. bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH);
  3723. } else {
  3724. bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH);
  3725. bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
  3726. bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH);
  3727. }
  3728. if ((radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) &&
  3729. (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT)) {
  3730. if (connected) {
  3731. DRM_DEBUG_KMS("TV1 connected\n");
  3732. bios_3_scratch |= ATOM_S3_TV1_ACTIVE;
  3733. bios_6_scratch |= ATOM_S6_ACC_REQ_TV1;
  3734. } else {
  3735. DRM_DEBUG_KMS("TV1 disconnected\n");
  3736. bios_0_scratch &= ~ATOM_S0_TV1_MASK;
  3737. bios_3_scratch &= ~ATOM_S3_TV1_ACTIVE;
  3738. bios_6_scratch &= ~ATOM_S6_ACC_REQ_TV1;
  3739. }
  3740. }
  3741. if ((radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) &&
  3742. (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT)) {
  3743. if (connected) {
  3744. DRM_DEBUG_KMS("CV connected\n");
  3745. bios_3_scratch |= ATOM_S3_CV_ACTIVE;
  3746. bios_6_scratch |= ATOM_S6_ACC_REQ_CV;
  3747. } else {
  3748. DRM_DEBUG_KMS("CV disconnected\n");
  3749. bios_0_scratch &= ~ATOM_S0_CV_MASK;
  3750. bios_3_scratch &= ~ATOM_S3_CV_ACTIVE;
  3751. bios_6_scratch &= ~ATOM_S6_ACC_REQ_CV;
  3752. }
  3753. }
  3754. if ((radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) &&
  3755. (radeon_connector->devices & ATOM_DEVICE_LCD1_SUPPORT)) {
  3756. if (connected) {
  3757. DRM_DEBUG_KMS("LCD1 connected\n");
  3758. bios_0_scratch |= ATOM_S0_LCD1;
  3759. bios_3_scratch |= ATOM_S3_LCD1_ACTIVE;
  3760. bios_6_scratch |= ATOM_S6_ACC_REQ_LCD1;
  3761. } else {
  3762. DRM_DEBUG_KMS("LCD1 disconnected\n");
  3763. bios_0_scratch &= ~ATOM_S0_LCD1;
  3764. bios_3_scratch &= ~ATOM_S3_LCD1_ACTIVE;
  3765. bios_6_scratch &= ~ATOM_S6_ACC_REQ_LCD1;
  3766. }
  3767. }
  3768. if ((radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) &&
  3769. (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)) {
  3770. if (connected) {
  3771. DRM_DEBUG_KMS("CRT1 connected\n");
  3772. bios_0_scratch |= ATOM_S0_CRT1_COLOR;
  3773. bios_3_scratch |= ATOM_S3_CRT1_ACTIVE;
  3774. bios_6_scratch |= ATOM_S6_ACC_REQ_CRT1;
  3775. } else {
  3776. DRM_DEBUG_KMS("CRT1 disconnected\n");
  3777. bios_0_scratch &= ~ATOM_S0_CRT1_MASK;
  3778. bios_3_scratch &= ~ATOM_S3_CRT1_ACTIVE;
  3779. bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT1;
  3780. }
  3781. }
  3782. if ((radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) &&
  3783. (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)) {
  3784. if (connected) {
  3785. DRM_DEBUG_KMS("CRT2 connected\n");
  3786. bios_0_scratch |= ATOM_S0_CRT2_COLOR;
  3787. bios_3_scratch |= ATOM_S3_CRT2_ACTIVE;
  3788. bios_6_scratch |= ATOM_S6_ACC_REQ_CRT2;
  3789. } else {
  3790. DRM_DEBUG_KMS("CRT2 disconnected\n");
  3791. bios_0_scratch &= ~ATOM_S0_CRT2_MASK;
  3792. bios_3_scratch &= ~ATOM_S3_CRT2_ACTIVE;
  3793. bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT2;
  3794. }
  3795. }
  3796. if ((radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) &&
  3797. (radeon_connector->devices & ATOM_DEVICE_DFP1_SUPPORT)) {
  3798. if (connected) {
  3799. DRM_DEBUG_KMS("DFP1 connected\n");
  3800. bios_0_scratch |= ATOM_S0_DFP1;
  3801. bios_3_scratch |= ATOM_S3_DFP1_ACTIVE;
  3802. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP1;
  3803. } else {
  3804. DRM_DEBUG_KMS("DFP1 disconnected\n");
  3805. bios_0_scratch &= ~ATOM_S0_DFP1;
  3806. bios_3_scratch &= ~ATOM_S3_DFP1_ACTIVE;
  3807. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP1;
  3808. }
  3809. }
  3810. if ((radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) &&
  3811. (radeon_connector->devices & ATOM_DEVICE_DFP2_SUPPORT)) {
  3812. if (connected) {
  3813. DRM_DEBUG_KMS("DFP2 connected\n");
  3814. bios_0_scratch |= ATOM_S0_DFP2;
  3815. bios_3_scratch |= ATOM_S3_DFP2_ACTIVE;
  3816. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP2;
  3817. } else {
  3818. DRM_DEBUG_KMS("DFP2 disconnected\n");
  3819. bios_0_scratch &= ~ATOM_S0_DFP2;
  3820. bios_3_scratch &= ~ATOM_S3_DFP2_ACTIVE;
  3821. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP2;
  3822. }
  3823. }
  3824. if ((radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) &&
  3825. (radeon_connector->devices & ATOM_DEVICE_DFP3_SUPPORT)) {
  3826. if (connected) {
  3827. DRM_DEBUG_KMS("DFP3 connected\n");
  3828. bios_0_scratch |= ATOM_S0_DFP3;
  3829. bios_3_scratch |= ATOM_S3_DFP3_ACTIVE;
  3830. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP3;
  3831. } else {
  3832. DRM_DEBUG_KMS("DFP3 disconnected\n");
  3833. bios_0_scratch &= ~ATOM_S0_DFP3;
  3834. bios_3_scratch &= ~ATOM_S3_DFP3_ACTIVE;
  3835. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP3;
  3836. }
  3837. }
  3838. if ((radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) &&
  3839. (radeon_connector->devices & ATOM_DEVICE_DFP4_SUPPORT)) {
  3840. if (connected) {
  3841. DRM_DEBUG_KMS("DFP4 connected\n");
  3842. bios_0_scratch |= ATOM_S0_DFP4;
  3843. bios_3_scratch |= ATOM_S3_DFP4_ACTIVE;
  3844. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP4;
  3845. } else {
  3846. DRM_DEBUG_KMS("DFP4 disconnected\n");
  3847. bios_0_scratch &= ~ATOM_S0_DFP4;
  3848. bios_3_scratch &= ~ATOM_S3_DFP4_ACTIVE;
  3849. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP4;
  3850. }
  3851. }
  3852. if ((radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) &&
  3853. (radeon_connector->devices & ATOM_DEVICE_DFP5_SUPPORT)) {
  3854. if (connected) {
  3855. DRM_DEBUG_KMS("DFP5 connected\n");
  3856. bios_0_scratch |= ATOM_S0_DFP5;
  3857. bios_3_scratch |= ATOM_S3_DFP5_ACTIVE;
  3858. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP5;
  3859. } else {
  3860. DRM_DEBUG_KMS("DFP5 disconnected\n");
  3861. bios_0_scratch &= ~ATOM_S0_DFP5;
  3862. bios_3_scratch &= ~ATOM_S3_DFP5_ACTIVE;
  3863. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP5;
  3864. }
  3865. }
  3866. if ((radeon_encoder->devices & ATOM_DEVICE_DFP6_SUPPORT) &&
  3867. (radeon_connector->devices & ATOM_DEVICE_DFP6_SUPPORT)) {
  3868. if (connected) {
  3869. DRM_DEBUG_KMS("DFP6 connected\n");
  3870. bios_0_scratch |= ATOM_S0_DFP6;
  3871. bios_3_scratch |= ATOM_S3_DFP6_ACTIVE;
  3872. bios_6_scratch |= ATOM_S6_ACC_REQ_DFP6;
  3873. } else {
  3874. DRM_DEBUG_KMS("DFP6 disconnected\n");
  3875. bios_0_scratch &= ~ATOM_S0_DFP6;
  3876. bios_3_scratch &= ~ATOM_S3_DFP6_ACTIVE;
  3877. bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP6;
  3878. }
  3879. }
  3880. if (rdev->family >= CHIP_R600) {
  3881. WREG32(R600_BIOS_0_SCRATCH, bios_0_scratch);
  3882. WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
  3883. WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch);
  3884. } else {
  3885. WREG32(RADEON_BIOS_0_SCRATCH, bios_0_scratch);
  3886. WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
  3887. WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch);
  3888. }
  3889. }
  3890. void
  3891. radeon_atombios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc)
  3892. {
  3893. struct drm_device *dev = encoder->dev;
  3894. struct radeon_device *rdev = dev->dev_private;
  3895. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  3896. uint32_t bios_3_scratch;
  3897. if (ASIC_IS_DCE4(rdev))
  3898. return;
  3899. if (rdev->family >= CHIP_R600)
  3900. bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
  3901. else
  3902. bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH);
  3903. if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
  3904. bios_3_scratch &= ~ATOM_S3_TV1_CRTC_ACTIVE;
  3905. bios_3_scratch |= (crtc << 18);
  3906. }
  3907. if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
  3908. bios_3_scratch &= ~ATOM_S3_CV_CRTC_ACTIVE;
  3909. bios_3_scratch |= (crtc << 24);
  3910. }
  3911. if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
  3912. bios_3_scratch &= ~ATOM_S3_CRT1_CRTC_ACTIVE;
  3913. bios_3_scratch |= (crtc << 16);
  3914. }
  3915. if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
  3916. bios_3_scratch &= ~ATOM_S3_CRT2_CRTC_ACTIVE;
  3917. bios_3_scratch |= (crtc << 20);
  3918. }
  3919. if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
  3920. bios_3_scratch &= ~ATOM_S3_LCD1_CRTC_ACTIVE;
  3921. bios_3_scratch |= (crtc << 17);
  3922. }
  3923. if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
  3924. bios_3_scratch &= ~ATOM_S3_DFP1_CRTC_ACTIVE;
  3925. bios_3_scratch |= (crtc << 19);
  3926. }
  3927. if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
  3928. bios_3_scratch &= ~ATOM_S3_DFP2_CRTC_ACTIVE;
  3929. bios_3_scratch |= (crtc << 23);
  3930. }
  3931. if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
  3932. bios_3_scratch &= ~ATOM_S3_DFP3_CRTC_ACTIVE;
  3933. bios_3_scratch |= (crtc << 25);
  3934. }
  3935. if (rdev->family >= CHIP_R600)
  3936. WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
  3937. else
  3938. WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch);
  3939. }
  3940. void
  3941. radeon_atombios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on)
  3942. {
  3943. struct drm_device *dev = encoder->dev;
  3944. struct radeon_device *rdev = dev->dev_private;
  3945. struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
  3946. uint32_t bios_2_scratch;
  3947. if (ASIC_IS_DCE4(rdev))
  3948. return;
  3949. if (rdev->family >= CHIP_R600)
  3950. bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
  3951. else
  3952. bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH);
  3953. if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) {
  3954. if (on)
  3955. bios_2_scratch &= ~ATOM_S2_TV1_DPMS_STATE;
  3956. else
  3957. bios_2_scratch |= ATOM_S2_TV1_DPMS_STATE;
  3958. }
  3959. if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) {
  3960. if (on)
  3961. bios_2_scratch &= ~ATOM_S2_CV_DPMS_STATE;
  3962. else
  3963. bios_2_scratch |= ATOM_S2_CV_DPMS_STATE;
  3964. }
  3965. if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) {
  3966. if (on)
  3967. bios_2_scratch &= ~ATOM_S2_CRT1_DPMS_STATE;
  3968. else
  3969. bios_2_scratch |= ATOM_S2_CRT1_DPMS_STATE;
  3970. }
  3971. if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) {
  3972. if (on)
  3973. bios_2_scratch &= ~ATOM_S2_CRT2_DPMS_STATE;
  3974. else
  3975. bios_2_scratch |= ATOM_S2_CRT2_DPMS_STATE;
  3976. }
  3977. if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) {
  3978. if (on)
  3979. bios_2_scratch &= ~ATOM_S2_LCD1_DPMS_STATE;
  3980. else
  3981. bios_2_scratch |= ATOM_S2_LCD1_DPMS_STATE;
  3982. }
  3983. if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) {
  3984. if (on)
  3985. bios_2_scratch &= ~ATOM_S2_DFP1_DPMS_STATE;
  3986. else
  3987. bios_2_scratch |= ATOM_S2_DFP1_DPMS_STATE;
  3988. }
  3989. if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) {
  3990. if (on)
  3991. bios_2_scratch &= ~ATOM_S2_DFP2_DPMS_STATE;
  3992. else
  3993. bios_2_scratch |= ATOM_S2_DFP2_DPMS_STATE;
  3994. }
  3995. if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) {
  3996. if (on)
  3997. bios_2_scratch &= ~ATOM_S2_DFP3_DPMS_STATE;
  3998. else
  3999. bios_2_scratch |= ATOM_S2_DFP3_DPMS_STATE;
  4000. }
  4001. if (radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) {
  4002. if (on)
  4003. bios_2_scratch &= ~ATOM_S2_DFP4_DPMS_STATE;
  4004. else
  4005. bios_2_scratch |= ATOM_S2_DFP4_DPMS_STATE;
  4006. }
  4007. if (radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) {
  4008. if (on)
  4009. bios_2_scratch &= ~ATOM_S2_DFP5_DPMS_STATE;
  4010. else
  4011. bios_2_scratch |= ATOM_S2_DFP5_DPMS_STATE;
  4012. }
  4013. if (rdev->family >= CHIP_R600)
  4014. WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch);
  4015. else
  4016. WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch);
  4017. }