radeon_atombios.c 134 KB

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