radeon_atombios.c 139 KB

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