rv770_dpm.c 70 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586
  1. /*
  2. * Copyright 2011 Advanced Micro Devices, Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * Authors: Alex Deucher
  23. */
  24. #include "drmP.h"
  25. #include "radeon.h"
  26. #include "radeon_asic.h"
  27. #include "rv770d.h"
  28. #include "r600_dpm.h"
  29. #include "rv770_dpm.h"
  30. #include "cypress_dpm.h"
  31. #include "atom.h"
  32. #include <linux/seq_file.h>
  33. #define MC_CG_ARB_FREQ_F0 0x0a
  34. #define MC_CG_ARB_FREQ_F1 0x0b
  35. #define MC_CG_ARB_FREQ_F2 0x0c
  36. #define MC_CG_ARB_FREQ_F3 0x0d
  37. #define MC_CG_SEQ_DRAMCONF_S0 0x05
  38. #define MC_CG_SEQ_DRAMCONF_S1 0x06
  39. #define PCIE_BUS_CLK 10000
  40. #define TCLK (PCIE_BUS_CLK / 10)
  41. #define SMC_RAM_END 0xC000
  42. struct rv7xx_ps *rv770_get_ps(struct radeon_ps *rps)
  43. {
  44. struct rv7xx_ps *ps = rps->ps_priv;
  45. return ps;
  46. }
  47. struct rv7xx_power_info *rv770_get_pi(struct radeon_device *rdev)
  48. {
  49. struct rv7xx_power_info *pi = rdev->pm.dpm.priv;
  50. return pi;
  51. }
  52. struct evergreen_power_info *evergreen_get_pi(struct radeon_device *rdev)
  53. {
  54. struct evergreen_power_info *pi = rdev->pm.dpm.priv;
  55. return pi;
  56. }
  57. static void rv770_enable_bif_dynamic_pcie_gen2(struct radeon_device *rdev,
  58. bool enable)
  59. {
  60. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  61. u32 tmp;
  62. tmp = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  63. if (enable) {
  64. tmp &= ~LC_HW_VOLTAGE_IF_CONTROL_MASK;
  65. tmp |= LC_HW_VOLTAGE_IF_CONTROL(1);
  66. tmp |= LC_GEN2_EN_STRAP;
  67. } else {
  68. if (!pi->boot_in_gen2) {
  69. tmp &= ~LC_HW_VOLTAGE_IF_CONTROL_MASK;
  70. tmp &= ~LC_GEN2_EN_STRAP;
  71. }
  72. }
  73. if ((tmp & LC_OTHER_SIDE_EVER_SENT_GEN2) ||
  74. (tmp & LC_OTHER_SIDE_SUPPORTS_GEN2))
  75. WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, tmp);
  76. }
  77. static void rv770_enable_l0s(struct radeon_device *rdev)
  78. {
  79. u32 tmp;
  80. tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL) & ~LC_L0S_INACTIVITY_MASK;
  81. tmp |= LC_L0S_INACTIVITY(3);
  82. WREG32_PCIE_PORT(PCIE_LC_CNTL, tmp);
  83. }
  84. static void rv770_enable_l1(struct radeon_device *rdev)
  85. {
  86. u32 tmp;
  87. tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL);
  88. tmp &= ~LC_L1_INACTIVITY_MASK;
  89. tmp |= LC_L1_INACTIVITY(4);
  90. tmp &= ~LC_PMI_TO_L1_DIS;
  91. tmp &= ~LC_ASPM_TO_L1_DIS;
  92. WREG32_PCIE_PORT(PCIE_LC_CNTL, tmp);
  93. }
  94. static void rv770_enable_pll_sleep_in_l1(struct radeon_device *rdev)
  95. {
  96. u32 tmp;
  97. tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL) & ~LC_L1_INACTIVITY_MASK;
  98. tmp |= LC_L1_INACTIVITY(8);
  99. WREG32_PCIE_PORT(PCIE_LC_CNTL, tmp);
  100. /* NOTE, this is a PCIE indirect reg, not PCIE PORT */
  101. tmp = RREG32_PCIE(PCIE_P_CNTL);
  102. tmp |= P_PLL_PWRDN_IN_L1L23;
  103. tmp &= ~P_PLL_BUF_PDNB;
  104. tmp &= ~P_PLL_PDNB;
  105. tmp |= P_ALLOW_PRX_FRONTEND_SHUTOFF;
  106. WREG32_PCIE(PCIE_P_CNTL, tmp);
  107. }
  108. static void rv770_gfx_clock_gating_enable(struct radeon_device *rdev,
  109. bool enable)
  110. {
  111. if (enable)
  112. WREG32_P(SCLK_PWRMGT_CNTL, DYN_GFX_CLK_OFF_EN, ~DYN_GFX_CLK_OFF_EN);
  113. else {
  114. WREG32_P(SCLK_PWRMGT_CNTL, 0, ~DYN_GFX_CLK_OFF_EN);
  115. WREG32_P(SCLK_PWRMGT_CNTL, GFX_CLK_FORCE_ON, ~GFX_CLK_FORCE_ON);
  116. WREG32_P(SCLK_PWRMGT_CNTL, 0, ~GFX_CLK_FORCE_ON);
  117. RREG32(GB_TILING_CONFIG);
  118. }
  119. }
  120. static void rv770_mg_clock_gating_enable(struct radeon_device *rdev,
  121. bool enable)
  122. {
  123. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  124. if (enable) {
  125. u32 mgcg_cgtt_local0;
  126. if (rdev->family == CHIP_RV770)
  127. mgcg_cgtt_local0 = RV770_MGCGTTLOCAL0_DFLT;
  128. else
  129. mgcg_cgtt_local0 = RV7XX_MGCGTTLOCAL0_DFLT;
  130. WREG32(CG_CGTT_LOCAL_0, mgcg_cgtt_local0);
  131. WREG32(CG_CGTT_LOCAL_1, (RV770_MGCGTTLOCAL1_DFLT & 0xFFFFCFFF));
  132. if (pi->mgcgtssm)
  133. WREG32(CGTS_SM_CTRL_REG, RV770_MGCGCGTSSMCTRL_DFLT);
  134. } else {
  135. WREG32(CG_CGTT_LOCAL_0, 0xFFFFFFFF);
  136. WREG32(CG_CGTT_LOCAL_1, 0xFFFFCFFF);
  137. }
  138. }
  139. void rv770_restore_cgcg(struct radeon_device *rdev)
  140. {
  141. bool dpm_en = false, cg_en = false;
  142. if (RREG32(GENERAL_PWRMGT) & GLOBAL_PWRMGT_EN)
  143. dpm_en = true;
  144. if (RREG32(SCLK_PWRMGT_CNTL) & DYN_GFX_CLK_OFF_EN)
  145. cg_en = true;
  146. if (dpm_en && !cg_en)
  147. WREG32_P(SCLK_PWRMGT_CNTL, DYN_GFX_CLK_OFF_EN, ~DYN_GFX_CLK_OFF_EN);
  148. }
  149. static void rv770_start_dpm(struct radeon_device *rdev)
  150. {
  151. WREG32_P(SCLK_PWRMGT_CNTL, 0, ~SCLK_PWRMGT_OFF);
  152. WREG32_P(MCLK_PWRMGT_CNTL, 0, ~MPLL_PWRMGT_OFF);
  153. WREG32_P(GENERAL_PWRMGT, GLOBAL_PWRMGT_EN, ~GLOBAL_PWRMGT_EN);
  154. }
  155. void rv770_stop_dpm(struct radeon_device *rdev)
  156. {
  157. PPSMC_Result result;
  158. result = rv770_send_msg_to_smc(rdev, PPSMC_MSG_TwoLevelsDisabled);
  159. if (result != PPSMC_Result_OK)
  160. DRM_DEBUG("Could not force DPM to low.\n");
  161. WREG32_P(GENERAL_PWRMGT, 0, ~GLOBAL_PWRMGT_EN);
  162. WREG32_P(SCLK_PWRMGT_CNTL, SCLK_PWRMGT_OFF, ~SCLK_PWRMGT_OFF);
  163. WREG32_P(MCLK_PWRMGT_CNTL, MPLL_PWRMGT_OFF, ~MPLL_PWRMGT_OFF);
  164. }
  165. bool rv770_dpm_enabled(struct radeon_device *rdev)
  166. {
  167. if (RREG32(GENERAL_PWRMGT) & GLOBAL_PWRMGT_EN)
  168. return true;
  169. else
  170. return false;
  171. }
  172. void rv770_enable_thermal_protection(struct radeon_device *rdev,
  173. bool enable)
  174. {
  175. if (enable)
  176. WREG32_P(GENERAL_PWRMGT, 0, ~THERMAL_PROTECTION_DIS);
  177. else
  178. WREG32_P(GENERAL_PWRMGT, THERMAL_PROTECTION_DIS, ~THERMAL_PROTECTION_DIS);
  179. }
  180. void rv770_enable_acpi_pm(struct radeon_device *rdev)
  181. {
  182. WREG32_P(GENERAL_PWRMGT, STATIC_PM_EN, ~STATIC_PM_EN);
  183. }
  184. u8 rv770_get_seq_value(struct radeon_device *rdev,
  185. struct rv7xx_pl *pl)
  186. {
  187. return (pl->flags & ATOM_PPLIB_R600_FLAGS_LOWPOWER) ?
  188. MC_CG_SEQ_DRAMCONF_S0 : MC_CG_SEQ_DRAMCONF_S1;
  189. }
  190. #if 0
  191. int rv770_read_smc_soft_register(struct radeon_device *rdev,
  192. u16 reg_offset, u32 *value)
  193. {
  194. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  195. return rv770_read_smc_sram_dword(rdev,
  196. pi->soft_regs_start + reg_offset,
  197. value, pi->sram_end);
  198. }
  199. #endif
  200. int rv770_write_smc_soft_register(struct radeon_device *rdev,
  201. u16 reg_offset, u32 value)
  202. {
  203. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  204. return rv770_write_smc_sram_dword(rdev,
  205. pi->soft_regs_start + reg_offset,
  206. value, pi->sram_end);
  207. }
  208. int rv770_populate_smc_t(struct radeon_device *rdev,
  209. struct radeon_ps *radeon_state,
  210. RV770_SMC_SWSTATE *smc_state)
  211. {
  212. struct rv7xx_ps *state = rv770_get_ps(radeon_state);
  213. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  214. int i;
  215. int a_n;
  216. int a_d;
  217. u8 l[RV770_SMC_PERFORMANCE_LEVELS_PER_SWSTATE];
  218. u8 r[RV770_SMC_PERFORMANCE_LEVELS_PER_SWSTATE];
  219. u32 a_t;
  220. l[0] = 0;
  221. r[2] = 100;
  222. a_n = (int)state->medium.sclk * pi->lmp +
  223. (int)state->low.sclk * (R600_AH_DFLT - pi->rlp);
  224. a_d = (int)state->low.sclk * (100 - (int)pi->rlp) +
  225. (int)state->medium.sclk * pi->lmp;
  226. l[1] = (u8)(pi->lmp - (int)pi->lmp * a_n / a_d);
  227. r[0] = (u8)(pi->rlp + (100 - (int)pi->rlp) * a_n / a_d);
  228. a_n = (int)state->high.sclk * pi->lhp + (int)state->medium.sclk *
  229. (R600_AH_DFLT - pi->rmp);
  230. a_d = (int)state->medium.sclk * (100 - (int)pi->rmp) +
  231. (int)state->high.sclk * pi->lhp;
  232. l[2] = (u8)(pi->lhp - (int)pi->lhp * a_n / a_d);
  233. r[1] = (u8)(pi->rmp + (100 - (int)pi->rmp) * a_n / a_d);
  234. for (i = 0; i < (RV770_SMC_PERFORMANCE_LEVELS_PER_SWSTATE - 1); i++) {
  235. a_t = CG_R(r[i] * pi->bsp / 200) | CG_L(l[i] * pi->bsp / 200);
  236. smc_state->levels[i].aT = cpu_to_be32(a_t);
  237. }
  238. a_t = CG_R(r[RV770_SMC_PERFORMANCE_LEVELS_PER_SWSTATE - 1] * pi->pbsp / 200) |
  239. CG_L(l[RV770_SMC_PERFORMANCE_LEVELS_PER_SWSTATE - 1] * pi->pbsp / 200);
  240. smc_state->levels[RV770_SMC_PERFORMANCE_LEVELS_PER_SWSTATE - 1].aT =
  241. cpu_to_be32(a_t);
  242. return 0;
  243. }
  244. int rv770_populate_smc_sp(struct radeon_device *rdev,
  245. struct radeon_ps *radeon_state,
  246. RV770_SMC_SWSTATE *smc_state)
  247. {
  248. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  249. int i;
  250. for (i = 0; i < (RV770_SMC_PERFORMANCE_LEVELS_PER_SWSTATE - 1); i++)
  251. smc_state->levels[i].bSP = cpu_to_be32(pi->dsp);
  252. smc_state->levels[RV770_SMC_PERFORMANCE_LEVELS_PER_SWSTATE - 1].bSP =
  253. cpu_to_be32(pi->psp);
  254. return 0;
  255. }
  256. static void rv770_calculate_fractional_mpll_feedback_divider(u32 memory_clock,
  257. u32 reference_clock,
  258. bool gddr5,
  259. struct atom_clock_dividers *dividers,
  260. u32 *clkf,
  261. u32 *clkfrac)
  262. {
  263. u32 post_divider, reference_divider, feedback_divider8;
  264. u32 fyclk;
  265. if (gddr5)
  266. fyclk = (memory_clock * 8) / 2;
  267. else
  268. fyclk = (memory_clock * 4) / 2;
  269. post_divider = dividers->post_div;
  270. reference_divider = dividers->ref_div;
  271. feedback_divider8 =
  272. (8 * fyclk * reference_divider * post_divider) / reference_clock;
  273. *clkf = feedback_divider8 / 8;
  274. *clkfrac = feedback_divider8 % 8;
  275. }
  276. static int rv770_encode_yclk_post_div(u32 postdiv, u32 *encoded_postdiv)
  277. {
  278. int ret = 0;
  279. switch (postdiv) {
  280. case 1:
  281. *encoded_postdiv = 0;
  282. break;
  283. case 2:
  284. *encoded_postdiv = 1;
  285. break;
  286. case 4:
  287. *encoded_postdiv = 2;
  288. break;
  289. case 8:
  290. *encoded_postdiv = 3;
  291. break;
  292. case 16:
  293. *encoded_postdiv = 4;
  294. break;
  295. default:
  296. ret = -EINVAL;
  297. break;
  298. }
  299. return ret;
  300. }
  301. u32 rv770_map_clkf_to_ibias(struct radeon_device *rdev, u32 clkf)
  302. {
  303. if (clkf <= 0x10)
  304. return 0x4B;
  305. if (clkf <= 0x19)
  306. return 0x5B;
  307. if (clkf <= 0x21)
  308. return 0x2B;
  309. if (clkf <= 0x27)
  310. return 0x6C;
  311. if (clkf <= 0x31)
  312. return 0x9D;
  313. return 0xC6;
  314. }
  315. static int rv770_populate_mclk_value(struct radeon_device *rdev,
  316. u32 engine_clock, u32 memory_clock,
  317. RV7XX_SMC_MCLK_VALUE *mclk)
  318. {
  319. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  320. u8 encoded_reference_dividers[] = { 0, 16, 17, 20, 21 };
  321. u32 mpll_ad_func_cntl =
  322. pi->clk_regs.rv770.mpll_ad_func_cntl;
  323. u32 mpll_ad_func_cntl_2 =
  324. pi->clk_regs.rv770.mpll_ad_func_cntl_2;
  325. u32 mpll_dq_func_cntl =
  326. pi->clk_regs.rv770.mpll_dq_func_cntl;
  327. u32 mpll_dq_func_cntl_2 =
  328. pi->clk_regs.rv770.mpll_dq_func_cntl_2;
  329. u32 mclk_pwrmgt_cntl =
  330. pi->clk_regs.rv770.mclk_pwrmgt_cntl;
  331. u32 dll_cntl = pi->clk_regs.rv770.dll_cntl;
  332. struct atom_clock_dividers dividers;
  333. u32 reference_clock = rdev->clock.mpll.reference_freq;
  334. u32 clkf, clkfrac;
  335. u32 postdiv_yclk;
  336. u32 ibias;
  337. int ret;
  338. ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_MEMORY_PLL_PARAM,
  339. memory_clock, false, &dividers);
  340. if (ret)
  341. return ret;
  342. if ((dividers.ref_div < 1) || (dividers.ref_div > 5))
  343. return -EINVAL;
  344. rv770_calculate_fractional_mpll_feedback_divider(memory_clock, reference_clock,
  345. pi->mem_gddr5,
  346. &dividers, &clkf, &clkfrac);
  347. ret = rv770_encode_yclk_post_div(dividers.post_div, &postdiv_yclk);
  348. if (ret)
  349. return ret;
  350. ibias = rv770_map_clkf_to_ibias(rdev, clkf);
  351. mpll_ad_func_cntl &= ~(CLKR_MASK |
  352. YCLK_POST_DIV_MASK |
  353. CLKF_MASK |
  354. CLKFRAC_MASK |
  355. IBIAS_MASK);
  356. mpll_ad_func_cntl |= CLKR(encoded_reference_dividers[dividers.ref_div - 1]);
  357. mpll_ad_func_cntl |= YCLK_POST_DIV(postdiv_yclk);
  358. mpll_ad_func_cntl |= CLKF(clkf);
  359. mpll_ad_func_cntl |= CLKFRAC(clkfrac);
  360. mpll_ad_func_cntl |= IBIAS(ibias);
  361. if (dividers.vco_mode)
  362. mpll_ad_func_cntl_2 |= VCO_MODE;
  363. else
  364. mpll_ad_func_cntl_2 &= ~VCO_MODE;
  365. if (pi->mem_gddr5) {
  366. rv770_calculate_fractional_mpll_feedback_divider(memory_clock,
  367. reference_clock,
  368. pi->mem_gddr5,
  369. &dividers, &clkf, &clkfrac);
  370. ibias = rv770_map_clkf_to_ibias(rdev, clkf);
  371. ret = rv770_encode_yclk_post_div(dividers.post_div, &postdiv_yclk);
  372. if (ret)
  373. return ret;
  374. mpll_dq_func_cntl &= ~(CLKR_MASK |
  375. YCLK_POST_DIV_MASK |
  376. CLKF_MASK |
  377. CLKFRAC_MASK |
  378. IBIAS_MASK);
  379. mpll_dq_func_cntl |= CLKR(encoded_reference_dividers[dividers.ref_div - 1]);
  380. mpll_dq_func_cntl |= YCLK_POST_DIV(postdiv_yclk);
  381. mpll_dq_func_cntl |= CLKF(clkf);
  382. mpll_dq_func_cntl |= CLKFRAC(clkfrac);
  383. mpll_dq_func_cntl |= IBIAS(ibias);
  384. if (dividers.vco_mode)
  385. mpll_dq_func_cntl_2 |= VCO_MODE;
  386. else
  387. mpll_dq_func_cntl_2 &= ~VCO_MODE;
  388. }
  389. mclk->mclk770.mclk_value = cpu_to_be32(memory_clock);
  390. mclk->mclk770.vMPLL_AD_FUNC_CNTL = cpu_to_be32(mpll_ad_func_cntl);
  391. mclk->mclk770.vMPLL_AD_FUNC_CNTL_2 = cpu_to_be32(mpll_ad_func_cntl_2);
  392. mclk->mclk770.vMPLL_DQ_FUNC_CNTL = cpu_to_be32(mpll_dq_func_cntl);
  393. mclk->mclk770.vMPLL_DQ_FUNC_CNTL_2 = cpu_to_be32(mpll_dq_func_cntl_2);
  394. mclk->mclk770.vMCLK_PWRMGT_CNTL = cpu_to_be32(mclk_pwrmgt_cntl);
  395. mclk->mclk770.vDLL_CNTL = cpu_to_be32(dll_cntl);
  396. return 0;
  397. }
  398. static int rv770_populate_sclk_value(struct radeon_device *rdev,
  399. u32 engine_clock,
  400. RV770_SMC_SCLK_VALUE *sclk)
  401. {
  402. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  403. struct atom_clock_dividers dividers;
  404. u32 spll_func_cntl =
  405. pi->clk_regs.rv770.cg_spll_func_cntl;
  406. u32 spll_func_cntl_2 =
  407. pi->clk_regs.rv770.cg_spll_func_cntl_2;
  408. u32 spll_func_cntl_3 =
  409. pi->clk_regs.rv770.cg_spll_func_cntl_3;
  410. u32 cg_spll_spread_spectrum =
  411. pi->clk_regs.rv770.cg_spll_spread_spectrum;
  412. u32 cg_spll_spread_spectrum_2 =
  413. pi->clk_regs.rv770.cg_spll_spread_spectrum_2;
  414. u64 tmp;
  415. u32 reference_clock = rdev->clock.spll.reference_freq;
  416. u32 reference_divider, post_divider;
  417. u32 fbdiv;
  418. int ret;
  419. ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
  420. engine_clock, false, &dividers);
  421. if (ret)
  422. return ret;
  423. reference_divider = 1 + dividers.ref_div;
  424. if (dividers.enable_post_div)
  425. post_divider = (0x0f & (dividers.post_div >> 4)) + (0x0f & dividers.post_div) + 2;
  426. else
  427. post_divider = 1;
  428. tmp = (u64) engine_clock * reference_divider * post_divider * 16384;
  429. do_div(tmp, reference_clock);
  430. fbdiv = (u32) tmp;
  431. if (dividers.enable_post_div)
  432. spll_func_cntl |= SPLL_DIVEN;
  433. else
  434. spll_func_cntl &= ~SPLL_DIVEN;
  435. spll_func_cntl &= ~(SPLL_HILEN_MASK | SPLL_LOLEN_MASK | SPLL_REF_DIV_MASK);
  436. spll_func_cntl |= SPLL_REF_DIV(dividers.ref_div);
  437. spll_func_cntl |= SPLL_HILEN((dividers.post_div >> 4) & 0xf);
  438. spll_func_cntl |= SPLL_LOLEN(dividers.post_div & 0xf);
  439. spll_func_cntl_2 &= ~SCLK_MUX_SEL_MASK;
  440. spll_func_cntl_2 |= SCLK_MUX_SEL(2);
  441. spll_func_cntl_3 &= ~SPLL_FB_DIV_MASK;
  442. spll_func_cntl_3 |= SPLL_FB_DIV(fbdiv);
  443. spll_func_cntl_3 |= SPLL_DITHEN;
  444. if (pi->sclk_ss) {
  445. struct radeon_atom_ss ss;
  446. u32 vco_freq = engine_clock * post_divider;
  447. if (radeon_atombios_get_asic_ss_info(rdev, &ss,
  448. ASIC_INTERNAL_ENGINE_SS, vco_freq)) {
  449. u32 clk_s = reference_clock * 5 / (reference_divider * ss.rate);
  450. u32 clk_v = ss.percentage * fbdiv / (clk_s * 10000);
  451. cg_spll_spread_spectrum &= ~CLKS_MASK;
  452. cg_spll_spread_spectrum |= CLKS(clk_s);
  453. cg_spll_spread_spectrum |= SSEN;
  454. cg_spll_spread_spectrum_2 &= ~CLKV_MASK;
  455. cg_spll_spread_spectrum_2 |= CLKV(clk_v);
  456. }
  457. }
  458. sclk->sclk_value = cpu_to_be32(engine_clock);
  459. sclk->vCG_SPLL_FUNC_CNTL = cpu_to_be32(spll_func_cntl);
  460. sclk->vCG_SPLL_FUNC_CNTL_2 = cpu_to_be32(spll_func_cntl_2);
  461. sclk->vCG_SPLL_FUNC_CNTL_3 = cpu_to_be32(spll_func_cntl_3);
  462. sclk->vCG_SPLL_SPREAD_SPECTRUM = cpu_to_be32(cg_spll_spread_spectrum);
  463. sclk->vCG_SPLL_SPREAD_SPECTRUM_2 = cpu_to_be32(cg_spll_spread_spectrum_2);
  464. return 0;
  465. }
  466. int rv770_populate_vddc_value(struct radeon_device *rdev, u16 vddc,
  467. RV770_SMC_VOLTAGE_VALUE *voltage)
  468. {
  469. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  470. int i;
  471. if (!pi->voltage_control) {
  472. voltage->index = 0;
  473. voltage->value = 0;
  474. return 0;
  475. }
  476. for (i = 0; i < pi->valid_vddc_entries; i++) {
  477. if (vddc <= pi->vddc_table[i].vddc) {
  478. voltage->index = pi->vddc_table[i].vddc_index;
  479. voltage->value = cpu_to_be16(vddc);
  480. break;
  481. }
  482. }
  483. if (i == pi->valid_vddc_entries)
  484. return -EINVAL;
  485. return 0;
  486. }
  487. int rv770_populate_mvdd_value(struct radeon_device *rdev, u32 mclk,
  488. RV770_SMC_VOLTAGE_VALUE *voltage)
  489. {
  490. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  491. if (!pi->mvdd_control) {
  492. voltage->index = MVDD_HIGH_INDEX;
  493. voltage->value = cpu_to_be16(MVDD_HIGH_VALUE);
  494. return 0;
  495. }
  496. if (mclk <= pi->mvdd_split_frequency) {
  497. voltage->index = MVDD_LOW_INDEX;
  498. voltage->value = cpu_to_be16(MVDD_LOW_VALUE);
  499. } else {
  500. voltage->index = MVDD_HIGH_INDEX;
  501. voltage->value = cpu_to_be16(MVDD_HIGH_VALUE);
  502. }
  503. return 0;
  504. }
  505. static int rv770_convert_power_level_to_smc(struct radeon_device *rdev,
  506. struct rv7xx_pl *pl,
  507. RV770_SMC_HW_PERFORMANCE_LEVEL *level,
  508. u8 watermark_level)
  509. {
  510. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  511. int ret;
  512. level->gen2PCIE = pi->pcie_gen2 ?
  513. ((pl->flags & ATOM_PPLIB_R600_FLAGS_PCIEGEN2) ? 1 : 0) : 0;
  514. level->gen2XSP = (pl->flags & ATOM_PPLIB_R600_FLAGS_PCIEGEN2) ? 1 : 0;
  515. level->backbias = (pl->flags & ATOM_PPLIB_R600_FLAGS_BACKBIASENABLE) ? 1 : 0;
  516. level->displayWatermark = watermark_level;
  517. if (rdev->family == CHIP_RV740)
  518. ret = rv740_populate_sclk_value(rdev, pl->sclk,
  519. &level->sclk);
  520. else if ((rdev->family == CHIP_RV730) || (rdev->family == CHIP_RV710))
  521. ret = rv730_populate_sclk_value(rdev, pl->sclk,
  522. &level->sclk);
  523. else
  524. ret = rv770_populate_sclk_value(rdev, pl->sclk,
  525. &level->sclk);
  526. if (ret)
  527. return ret;
  528. if (rdev->family == CHIP_RV740) {
  529. if (pi->mem_gddr5) {
  530. if (pl->mclk <= pi->mclk_strobe_mode_threshold)
  531. level->strobeMode =
  532. rv740_get_mclk_frequency_ratio(pl->mclk) | 0x10;
  533. else
  534. level->strobeMode = 0;
  535. if (pl->mclk > pi->mclk_edc_enable_threshold)
  536. level->mcFlags = SMC_MC_EDC_RD_FLAG | SMC_MC_EDC_WR_FLAG;
  537. else
  538. level->mcFlags = 0;
  539. }
  540. ret = rv740_populate_mclk_value(rdev, pl->sclk,
  541. pl->mclk, &level->mclk);
  542. } else if ((rdev->family == CHIP_RV730) || (rdev->family == CHIP_RV710))
  543. ret = rv730_populate_mclk_value(rdev, pl->sclk,
  544. pl->mclk, &level->mclk);
  545. else
  546. ret = rv770_populate_mclk_value(rdev, pl->sclk,
  547. pl->mclk, &level->mclk);
  548. if (ret)
  549. return ret;
  550. ret = rv770_populate_vddc_value(rdev, pl->vddc,
  551. &level->vddc);
  552. if (ret)
  553. return ret;
  554. ret = rv770_populate_mvdd_value(rdev, pl->mclk, &level->mvdd);
  555. return ret;
  556. }
  557. static int rv770_convert_power_state_to_smc(struct radeon_device *rdev,
  558. struct radeon_ps *radeon_state,
  559. RV770_SMC_SWSTATE *smc_state)
  560. {
  561. struct rv7xx_ps *state = rv770_get_ps(radeon_state);
  562. int ret;
  563. if (!(radeon_state->caps & ATOM_PPLIB_DISALLOW_ON_DC))
  564. smc_state->flags |= PPSMC_SWSTATE_FLAG_DC;
  565. ret = rv770_convert_power_level_to_smc(rdev,
  566. &state->low,
  567. &smc_state->levels[0],
  568. PPSMC_DISPLAY_WATERMARK_LOW);
  569. if (ret)
  570. return ret;
  571. ret = rv770_convert_power_level_to_smc(rdev,
  572. &state->medium,
  573. &smc_state->levels[1],
  574. PPSMC_DISPLAY_WATERMARK_LOW);
  575. if (ret)
  576. return ret;
  577. ret = rv770_convert_power_level_to_smc(rdev,
  578. &state->high,
  579. &smc_state->levels[2],
  580. PPSMC_DISPLAY_WATERMARK_HIGH);
  581. if (ret)
  582. return ret;
  583. smc_state->levels[0].arbValue = MC_CG_ARB_FREQ_F1;
  584. smc_state->levels[1].arbValue = MC_CG_ARB_FREQ_F2;
  585. smc_state->levels[2].arbValue = MC_CG_ARB_FREQ_F3;
  586. smc_state->levels[0].seqValue = rv770_get_seq_value(rdev,
  587. &state->low);
  588. smc_state->levels[1].seqValue = rv770_get_seq_value(rdev,
  589. &state->medium);
  590. smc_state->levels[2].seqValue = rv770_get_seq_value(rdev,
  591. &state->high);
  592. rv770_populate_smc_sp(rdev, radeon_state, smc_state);
  593. return rv770_populate_smc_t(rdev, radeon_state, smc_state);
  594. }
  595. u32 rv770_calculate_memory_refresh_rate(struct radeon_device *rdev,
  596. u32 engine_clock)
  597. {
  598. u32 dram_rows;
  599. u32 dram_refresh_rate;
  600. u32 mc_arb_rfsh_rate;
  601. u32 tmp;
  602. tmp = (RREG32(MC_ARB_RAMCFG) & NOOFROWS_MASK) >> NOOFROWS_SHIFT;
  603. dram_rows = 1 << (tmp + 10);
  604. tmp = RREG32(MC_SEQ_MISC0) & 3;
  605. dram_refresh_rate = 1 << (tmp + 3);
  606. mc_arb_rfsh_rate = ((engine_clock * 10) * dram_refresh_rate / dram_rows - 32) / 64;
  607. return mc_arb_rfsh_rate;
  608. }
  609. static void rv770_program_memory_timing_parameters(struct radeon_device *rdev,
  610. struct radeon_ps *radeon_state)
  611. {
  612. struct rv7xx_ps *state = rv770_get_ps(radeon_state);
  613. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  614. u32 sqm_ratio;
  615. u32 arb_refresh_rate;
  616. u32 high_clock;
  617. if (state->high.sclk < (state->low.sclk * 0xFF / 0x40))
  618. high_clock = state->high.sclk;
  619. else
  620. high_clock = (state->low.sclk * 0xFF / 0x40);
  621. radeon_atom_set_engine_dram_timings(rdev, high_clock,
  622. state->high.mclk);
  623. sqm_ratio =
  624. STATE0(64 * high_clock / pi->boot_sclk) |
  625. STATE1(64 * high_clock / state->low.sclk) |
  626. STATE2(64 * high_clock / state->medium.sclk) |
  627. STATE3(64 * high_clock / state->high.sclk);
  628. WREG32(MC_ARB_SQM_RATIO, sqm_ratio);
  629. arb_refresh_rate =
  630. POWERMODE0(rv770_calculate_memory_refresh_rate(rdev, pi->boot_sclk)) |
  631. POWERMODE1(rv770_calculate_memory_refresh_rate(rdev, state->low.sclk)) |
  632. POWERMODE2(rv770_calculate_memory_refresh_rate(rdev, state->medium.sclk)) |
  633. POWERMODE3(rv770_calculate_memory_refresh_rate(rdev, state->high.sclk));
  634. WREG32(MC_ARB_RFSH_RATE, arb_refresh_rate);
  635. }
  636. void rv770_enable_backbias(struct radeon_device *rdev,
  637. bool enable)
  638. {
  639. if (enable)
  640. WREG32_P(GENERAL_PWRMGT, BACKBIAS_PAD_EN, ~BACKBIAS_PAD_EN);
  641. else
  642. WREG32_P(GENERAL_PWRMGT, 0, ~(BACKBIAS_VALUE | BACKBIAS_PAD_EN));
  643. }
  644. static void rv770_enable_spread_spectrum(struct radeon_device *rdev,
  645. bool enable)
  646. {
  647. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  648. if (enable) {
  649. if (pi->sclk_ss)
  650. WREG32_P(GENERAL_PWRMGT, DYN_SPREAD_SPECTRUM_EN, ~DYN_SPREAD_SPECTRUM_EN);
  651. if (pi->mclk_ss) {
  652. if (rdev->family == CHIP_RV740)
  653. rv740_enable_mclk_spread_spectrum(rdev, true);
  654. }
  655. } else {
  656. WREG32_P(CG_SPLL_SPREAD_SPECTRUM, 0, ~SSEN);
  657. WREG32_P(GENERAL_PWRMGT, 0, ~DYN_SPREAD_SPECTRUM_EN);
  658. WREG32_P(CG_MPLL_SPREAD_SPECTRUM, 0, ~SSEN);
  659. if (rdev->family == CHIP_RV740)
  660. rv740_enable_mclk_spread_spectrum(rdev, false);
  661. }
  662. }
  663. static void rv770_program_mpll_timing_parameters(struct radeon_device *rdev)
  664. {
  665. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  666. if ((rdev->family == CHIP_RV770) && !pi->mem_gddr5) {
  667. WREG32(MPLL_TIME,
  668. (MPLL_LOCK_TIME(R600_MPLLLOCKTIME_DFLT * pi->ref_div) |
  669. MPLL_RESET_TIME(R600_MPLLRESETTIME_DFLT)));
  670. }
  671. }
  672. void rv770_setup_bsp(struct radeon_device *rdev)
  673. {
  674. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  675. u32 xclk = radeon_get_xclk(rdev);
  676. r600_calculate_u_and_p(pi->asi,
  677. xclk,
  678. 16,
  679. &pi->bsp,
  680. &pi->bsu);
  681. r600_calculate_u_and_p(pi->pasi,
  682. xclk,
  683. 16,
  684. &pi->pbsp,
  685. &pi->pbsu);
  686. pi->dsp = BSP(pi->bsp) | BSU(pi->bsu);
  687. pi->psp = BSP(pi->pbsp) | BSU(pi->pbsu);
  688. WREG32(CG_BSP, pi->dsp);
  689. }
  690. void rv770_program_git(struct radeon_device *rdev)
  691. {
  692. WREG32_P(CG_GIT, CG_GICST(R600_GICST_DFLT), ~CG_GICST_MASK);
  693. }
  694. void rv770_program_tp(struct radeon_device *rdev)
  695. {
  696. int i;
  697. enum r600_td td = R600_TD_DFLT;
  698. for (i = 0; i < R600_PM_NUMBER_OF_TC; i++)
  699. WREG32(CG_FFCT_0 + (i * 4), (UTC_0(r600_utc[i]) | DTC_0(r600_dtc[i])));
  700. if (td == R600_TD_AUTO)
  701. WREG32_P(SCLK_PWRMGT_CNTL, 0, ~FIR_FORCE_TREND_SEL);
  702. else
  703. WREG32_P(SCLK_PWRMGT_CNTL, FIR_FORCE_TREND_SEL, ~FIR_FORCE_TREND_SEL);
  704. if (td == R600_TD_UP)
  705. WREG32_P(SCLK_PWRMGT_CNTL, 0, ~FIR_TREND_MODE);
  706. if (td == R600_TD_DOWN)
  707. WREG32_P(SCLK_PWRMGT_CNTL, FIR_TREND_MODE, ~FIR_TREND_MODE);
  708. }
  709. void rv770_program_tpp(struct radeon_device *rdev)
  710. {
  711. WREG32(CG_TPC, R600_TPC_DFLT);
  712. }
  713. void rv770_program_sstp(struct radeon_device *rdev)
  714. {
  715. WREG32(CG_SSP, (SSTU(R600_SSTU_DFLT) | SST(R600_SST_DFLT)));
  716. }
  717. void rv770_program_engine_speed_parameters(struct radeon_device *rdev)
  718. {
  719. WREG32_P(SPLL_CNTL_MODE, SPLL_DIV_SYNC, ~SPLL_DIV_SYNC);
  720. }
  721. static void rv770_enable_display_gap(struct radeon_device *rdev)
  722. {
  723. u32 tmp = RREG32(CG_DISPLAY_GAP_CNTL);
  724. tmp &= ~(DISP1_GAP_MCHG_MASK | DISP2_GAP_MCHG_MASK);
  725. tmp |= (DISP1_GAP_MCHG(R600_PM_DISPLAY_GAP_IGNORE) |
  726. DISP2_GAP_MCHG(R600_PM_DISPLAY_GAP_IGNORE));
  727. WREG32(CG_DISPLAY_GAP_CNTL, tmp);
  728. }
  729. void rv770_program_vc(struct radeon_device *rdev)
  730. {
  731. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  732. WREG32(CG_FTV, pi->vrc);
  733. }
  734. void rv770_clear_vc(struct radeon_device *rdev)
  735. {
  736. WREG32(CG_FTV, 0);
  737. }
  738. int rv770_upload_firmware(struct radeon_device *rdev)
  739. {
  740. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  741. int ret;
  742. rv770_reset_smc(rdev);
  743. rv770_stop_smc_clock(rdev);
  744. ret = rv770_load_smc_ucode(rdev, pi->sram_end);
  745. if (ret)
  746. return ret;
  747. return 0;
  748. }
  749. static int rv770_populate_smc_acpi_state(struct radeon_device *rdev,
  750. RV770_SMC_STATETABLE *table)
  751. {
  752. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  753. u32 mpll_ad_func_cntl =
  754. pi->clk_regs.rv770.mpll_ad_func_cntl;
  755. u32 mpll_ad_func_cntl_2 =
  756. pi->clk_regs.rv770.mpll_ad_func_cntl_2;
  757. u32 mpll_dq_func_cntl =
  758. pi->clk_regs.rv770.mpll_dq_func_cntl;
  759. u32 mpll_dq_func_cntl_2 =
  760. pi->clk_regs.rv770.mpll_dq_func_cntl_2;
  761. u32 spll_func_cntl =
  762. pi->clk_regs.rv770.cg_spll_func_cntl;
  763. u32 spll_func_cntl_2 =
  764. pi->clk_regs.rv770.cg_spll_func_cntl_2;
  765. u32 spll_func_cntl_3 =
  766. pi->clk_regs.rv770.cg_spll_func_cntl_3;
  767. u32 mclk_pwrmgt_cntl;
  768. u32 dll_cntl;
  769. table->ACPIState = table->initialState;
  770. table->ACPIState.flags &= ~PPSMC_SWSTATE_FLAG_DC;
  771. if (pi->acpi_vddc) {
  772. rv770_populate_vddc_value(rdev, pi->acpi_vddc,
  773. &table->ACPIState.levels[0].vddc);
  774. if (pi->pcie_gen2) {
  775. if (pi->acpi_pcie_gen2)
  776. table->ACPIState.levels[0].gen2PCIE = 1;
  777. else
  778. table->ACPIState.levels[0].gen2PCIE = 0;
  779. } else
  780. table->ACPIState.levels[0].gen2PCIE = 0;
  781. if (pi->acpi_pcie_gen2)
  782. table->ACPIState.levels[0].gen2XSP = 1;
  783. else
  784. table->ACPIState.levels[0].gen2XSP = 0;
  785. } else {
  786. rv770_populate_vddc_value(rdev, pi->min_vddc_in_table,
  787. &table->ACPIState.levels[0].vddc);
  788. table->ACPIState.levels[0].gen2PCIE = 0;
  789. }
  790. mpll_ad_func_cntl_2 |= BIAS_GEN_PDNB | RESET_EN;
  791. mpll_dq_func_cntl_2 |= BIAS_GEN_PDNB | RESET_EN;
  792. mclk_pwrmgt_cntl = (MRDCKA0_RESET |
  793. MRDCKA1_RESET |
  794. MRDCKB0_RESET |
  795. MRDCKB1_RESET |
  796. MRDCKC0_RESET |
  797. MRDCKC1_RESET |
  798. MRDCKD0_RESET |
  799. MRDCKD1_RESET);
  800. dll_cntl = 0xff000000;
  801. spll_func_cntl |= SPLL_RESET | SPLL_SLEEP | SPLL_BYPASS_EN;
  802. spll_func_cntl_2 &= ~SCLK_MUX_SEL_MASK;
  803. spll_func_cntl_2 |= SCLK_MUX_SEL(4);
  804. table->ACPIState.levels[0].mclk.mclk770.vMPLL_AD_FUNC_CNTL = cpu_to_be32(mpll_ad_func_cntl);
  805. table->ACPIState.levels[0].mclk.mclk770.vMPLL_AD_FUNC_CNTL_2 = cpu_to_be32(mpll_ad_func_cntl_2);
  806. table->ACPIState.levels[0].mclk.mclk770.vMPLL_DQ_FUNC_CNTL = cpu_to_be32(mpll_dq_func_cntl);
  807. table->ACPIState.levels[0].mclk.mclk770.vMPLL_DQ_FUNC_CNTL_2 = cpu_to_be32(mpll_dq_func_cntl_2);
  808. table->ACPIState.levels[0].mclk.mclk770.vMCLK_PWRMGT_CNTL = cpu_to_be32(mclk_pwrmgt_cntl);
  809. table->ACPIState.levels[0].mclk.mclk770.vDLL_CNTL = cpu_to_be32(dll_cntl);
  810. table->ACPIState.levels[0].mclk.mclk770.mclk_value = 0;
  811. table->ACPIState.levels[0].sclk.vCG_SPLL_FUNC_CNTL = cpu_to_be32(spll_func_cntl);
  812. table->ACPIState.levels[0].sclk.vCG_SPLL_FUNC_CNTL_2 = cpu_to_be32(spll_func_cntl_2);
  813. table->ACPIState.levels[0].sclk.vCG_SPLL_FUNC_CNTL_3 = cpu_to_be32(spll_func_cntl_3);
  814. table->ACPIState.levels[0].sclk.sclk_value = 0;
  815. rv770_populate_mvdd_value(rdev, 0, &table->ACPIState.levels[0].mvdd);
  816. table->ACPIState.levels[1] = table->ACPIState.levels[0];
  817. table->ACPIState.levels[2] = table->ACPIState.levels[0];
  818. return 0;
  819. }
  820. int rv770_populate_initial_mvdd_value(struct radeon_device *rdev,
  821. RV770_SMC_VOLTAGE_VALUE *voltage)
  822. {
  823. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  824. if ((pi->s0_vid_lower_smio_cntl & pi->mvdd_mask_low) ==
  825. (pi->mvdd_low_smio[MVDD_LOW_INDEX] & pi->mvdd_mask_low) ) {
  826. voltage->index = MVDD_LOW_INDEX;
  827. voltage->value = cpu_to_be16(MVDD_LOW_VALUE);
  828. } else {
  829. voltage->index = MVDD_HIGH_INDEX;
  830. voltage->value = cpu_to_be16(MVDD_HIGH_VALUE);
  831. }
  832. return 0;
  833. }
  834. static int rv770_populate_smc_initial_state(struct radeon_device *rdev,
  835. struct radeon_ps *radeon_state,
  836. RV770_SMC_STATETABLE *table)
  837. {
  838. struct rv7xx_ps *initial_state = rv770_get_ps(radeon_state);
  839. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  840. u32 a_t;
  841. table->initialState.levels[0].mclk.mclk770.vMPLL_AD_FUNC_CNTL =
  842. cpu_to_be32(pi->clk_regs.rv770.mpll_ad_func_cntl);
  843. table->initialState.levels[0].mclk.mclk770.vMPLL_AD_FUNC_CNTL_2 =
  844. cpu_to_be32(pi->clk_regs.rv770.mpll_ad_func_cntl_2);
  845. table->initialState.levels[0].mclk.mclk770.vMPLL_DQ_FUNC_CNTL =
  846. cpu_to_be32(pi->clk_regs.rv770.mpll_dq_func_cntl);
  847. table->initialState.levels[0].mclk.mclk770.vMPLL_DQ_FUNC_CNTL_2 =
  848. cpu_to_be32(pi->clk_regs.rv770.mpll_dq_func_cntl_2);
  849. table->initialState.levels[0].mclk.mclk770.vMCLK_PWRMGT_CNTL =
  850. cpu_to_be32(pi->clk_regs.rv770.mclk_pwrmgt_cntl);
  851. table->initialState.levels[0].mclk.mclk770.vDLL_CNTL =
  852. cpu_to_be32(pi->clk_regs.rv770.dll_cntl);
  853. table->initialState.levels[0].mclk.mclk770.vMPLL_SS =
  854. cpu_to_be32(pi->clk_regs.rv770.mpll_ss1);
  855. table->initialState.levels[0].mclk.mclk770.vMPLL_SS2 =
  856. cpu_to_be32(pi->clk_regs.rv770.mpll_ss2);
  857. table->initialState.levels[0].mclk.mclk770.mclk_value =
  858. cpu_to_be32(initial_state->low.mclk);
  859. table->initialState.levels[0].sclk.vCG_SPLL_FUNC_CNTL =
  860. cpu_to_be32(pi->clk_regs.rv770.cg_spll_func_cntl);
  861. table->initialState.levels[0].sclk.vCG_SPLL_FUNC_CNTL_2 =
  862. cpu_to_be32(pi->clk_regs.rv770.cg_spll_func_cntl_2);
  863. table->initialState.levels[0].sclk.vCG_SPLL_FUNC_CNTL_3 =
  864. cpu_to_be32(pi->clk_regs.rv770.cg_spll_func_cntl_3);
  865. table->initialState.levels[0].sclk.vCG_SPLL_SPREAD_SPECTRUM =
  866. cpu_to_be32(pi->clk_regs.rv770.cg_spll_spread_spectrum);
  867. table->initialState.levels[0].sclk.vCG_SPLL_SPREAD_SPECTRUM_2 =
  868. cpu_to_be32(pi->clk_regs.rv770.cg_spll_spread_spectrum_2);
  869. table->initialState.levels[0].sclk.sclk_value =
  870. cpu_to_be32(initial_state->low.sclk);
  871. table->initialState.levels[0].arbValue = MC_CG_ARB_FREQ_F0;
  872. table->initialState.levels[0].seqValue =
  873. rv770_get_seq_value(rdev, &initial_state->low);
  874. rv770_populate_vddc_value(rdev,
  875. initial_state->low.vddc,
  876. &table->initialState.levels[0].vddc);
  877. rv770_populate_initial_mvdd_value(rdev,
  878. &table->initialState.levels[0].mvdd);
  879. a_t = CG_R(0xffff) | CG_L(0);
  880. table->initialState.levels[0].aT = cpu_to_be32(a_t);
  881. table->initialState.levels[0].bSP = cpu_to_be32(pi->dsp);
  882. if (pi->boot_in_gen2)
  883. table->initialState.levels[0].gen2PCIE = 1;
  884. else
  885. table->initialState.levels[0].gen2PCIE = 0;
  886. if (initial_state->low.flags & ATOM_PPLIB_R600_FLAGS_PCIEGEN2)
  887. table->initialState.levels[0].gen2XSP = 1;
  888. else
  889. table->initialState.levels[0].gen2XSP = 0;
  890. if (rdev->family == CHIP_RV740) {
  891. if (pi->mem_gddr5) {
  892. if (initial_state->low.mclk <= pi->mclk_strobe_mode_threshold)
  893. table->initialState.levels[0].strobeMode =
  894. rv740_get_mclk_frequency_ratio(initial_state->low.mclk) | 0x10;
  895. else
  896. table->initialState.levels[0].strobeMode = 0;
  897. if (initial_state->low.mclk >= pi->mclk_edc_enable_threshold)
  898. table->initialState.levels[0].mcFlags = SMC_MC_EDC_RD_FLAG | SMC_MC_EDC_WR_FLAG;
  899. else
  900. table->initialState.levels[0].mcFlags = 0;
  901. }
  902. }
  903. table->initialState.levels[1] = table->initialState.levels[0];
  904. table->initialState.levels[2] = table->initialState.levels[0];
  905. table->initialState.flags |= PPSMC_SWSTATE_FLAG_DC;
  906. return 0;
  907. }
  908. static int rv770_populate_smc_vddc_table(struct radeon_device *rdev,
  909. RV770_SMC_STATETABLE *table)
  910. {
  911. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  912. int i;
  913. for (i = 0; i < pi->valid_vddc_entries; i++) {
  914. table->highSMIO[pi->vddc_table[i].vddc_index] =
  915. pi->vddc_table[i].high_smio;
  916. table->lowSMIO[pi->vddc_table[i].vddc_index] =
  917. cpu_to_be32(pi->vddc_table[i].low_smio);
  918. }
  919. table->voltageMaskTable.highMask[RV770_SMC_VOLTAGEMASK_VDDC] = 0;
  920. table->voltageMaskTable.lowMask[RV770_SMC_VOLTAGEMASK_VDDC] =
  921. cpu_to_be32(pi->vddc_mask_low);
  922. for (i = 0;
  923. ((i < pi->valid_vddc_entries) &&
  924. (pi->max_vddc_in_table >
  925. pi->vddc_table[i].vddc));
  926. i++);
  927. table->maxVDDCIndexInPPTable =
  928. pi->vddc_table[i].vddc_index;
  929. return 0;
  930. }
  931. static int rv770_populate_smc_mvdd_table(struct radeon_device *rdev,
  932. RV770_SMC_STATETABLE *table)
  933. {
  934. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  935. if (pi->mvdd_control) {
  936. table->lowSMIO[MVDD_HIGH_INDEX] |=
  937. cpu_to_be32(pi->mvdd_low_smio[MVDD_HIGH_INDEX]);
  938. table->lowSMIO[MVDD_LOW_INDEX] |=
  939. cpu_to_be32(pi->mvdd_low_smio[MVDD_LOW_INDEX]);
  940. table->voltageMaskTable.highMask[RV770_SMC_VOLTAGEMASK_MVDD] = 0;
  941. table->voltageMaskTable.lowMask[RV770_SMC_VOLTAGEMASK_MVDD] =
  942. cpu_to_be32(pi->mvdd_mask_low);
  943. }
  944. return 0;
  945. }
  946. static int rv770_init_smc_table(struct radeon_device *rdev,
  947. struct radeon_ps *radeon_boot_state)
  948. {
  949. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  950. struct rv7xx_ps *boot_state = rv770_get_ps(radeon_boot_state);
  951. RV770_SMC_STATETABLE *table = &pi->smc_statetable;
  952. int ret;
  953. memset(table, 0, sizeof(RV770_SMC_STATETABLE));
  954. pi->boot_sclk = boot_state->low.sclk;
  955. rv770_populate_smc_vddc_table(rdev, table);
  956. rv770_populate_smc_mvdd_table(rdev, table);
  957. switch (rdev->pm.int_thermal_type) {
  958. case THERMAL_TYPE_RV770:
  959. case THERMAL_TYPE_ADT7473_WITH_INTERNAL:
  960. table->thermalProtectType = PPSMC_THERMAL_PROTECT_TYPE_INTERNAL;
  961. break;
  962. case THERMAL_TYPE_NONE:
  963. table->thermalProtectType = PPSMC_THERMAL_PROTECT_TYPE_NONE;
  964. break;
  965. case THERMAL_TYPE_EXTERNAL_GPIO:
  966. default:
  967. table->thermalProtectType = PPSMC_THERMAL_PROTECT_TYPE_EXTERNAL;
  968. break;
  969. }
  970. if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_HARDWAREDC) {
  971. table->systemFlags |= PPSMC_SYSTEMFLAG_GPIO_DC;
  972. if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_DONT_WAIT_FOR_VBLANK_ON_ALERT)
  973. table->extraFlags |= PPSMC_EXTRAFLAGS_AC2DC_DONT_WAIT_FOR_VBLANK;
  974. if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_GOTO_BOOT_ON_ALERT)
  975. table->extraFlags |= PPSMC_EXTRAFLAGS_AC2DC_ACTION_GOTOINITIALSTATE;
  976. }
  977. if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_STEPVDDC)
  978. table->systemFlags |= PPSMC_SYSTEMFLAG_STEPVDDC;
  979. if (pi->mem_gddr5)
  980. table->systemFlags |= PPSMC_SYSTEMFLAG_GDDR5;
  981. if ((rdev->family == CHIP_RV730) || (rdev->family == CHIP_RV710))
  982. ret = rv730_populate_smc_initial_state(rdev, radeon_boot_state, table);
  983. else
  984. ret = rv770_populate_smc_initial_state(rdev, radeon_boot_state, table);
  985. if (ret)
  986. return ret;
  987. if (rdev->family == CHIP_RV740)
  988. ret = rv740_populate_smc_acpi_state(rdev, table);
  989. else if ((rdev->family == CHIP_RV730) || (rdev->family == CHIP_RV710))
  990. ret = rv730_populate_smc_acpi_state(rdev, table);
  991. else
  992. ret = rv770_populate_smc_acpi_state(rdev, table);
  993. if (ret)
  994. return ret;
  995. table->driverState = table->initialState;
  996. return rv770_copy_bytes_to_smc(rdev,
  997. pi->state_table_start,
  998. (const u8 *)table,
  999. sizeof(RV770_SMC_STATETABLE),
  1000. pi->sram_end);
  1001. }
  1002. static int rv770_construct_vddc_table(struct radeon_device *rdev)
  1003. {
  1004. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  1005. u16 min, max, step;
  1006. u32 steps = 0;
  1007. u8 vddc_index = 0;
  1008. u32 i;
  1009. radeon_atom_get_min_voltage(rdev, SET_VOLTAGE_TYPE_ASIC_VDDC, &min);
  1010. radeon_atom_get_max_voltage(rdev, SET_VOLTAGE_TYPE_ASIC_VDDC, &max);
  1011. radeon_atom_get_voltage_step(rdev, SET_VOLTAGE_TYPE_ASIC_VDDC, &step);
  1012. steps = (max - min) / step + 1;
  1013. if (steps > MAX_NO_VREG_STEPS)
  1014. return -EINVAL;
  1015. for (i = 0; i < steps; i++) {
  1016. u32 gpio_pins, gpio_mask;
  1017. pi->vddc_table[i].vddc = (u16)(min + i * step);
  1018. radeon_atom_get_voltage_gpio_settings(rdev,
  1019. pi->vddc_table[i].vddc,
  1020. SET_VOLTAGE_TYPE_ASIC_VDDC,
  1021. &gpio_pins, &gpio_mask);
  1022. pi->vddc_table[i].low_smio = gpio_pins & gpio_mask;
  1023. pi->vddc_table[i].high_smio = 0;
  1024. pi->vddc_mask_low = gpio_mask;
  1025. if (i > 0) {
  1026. if ((pi->vddc_table[i].low_smio !=
  1027. pi->vddc_table[i - 1].low_smio ) ||
  1028. (pi->vddc_table[i].high_smio !=
  1029. pi->vddc_table[i - 1].high_smio))
  1030. vddc_index++;
  1031. }
  1032. pi->vddc_table[i].vddc_index = vddc_index;
  1033. }
  1034. pi->valid_vddc_entries = (u8)steps;
  1035. return 0;
  1036. }
  1037. static u32 rv770_get_mclk_split_point(struct atom_memory_info *memory_info)
  1038. {
  1039. if (memory_info->mem_type == MEM_TYPE_GDDR3)
  1040. return 30000;
  1041. return 0;
  1042. }
  1043. static int rv770_get_mvdd_pin_configuration(struct radeon_device *rdev)
  1044. {
  1045. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  1046. u32 gpio_pins, gpio_mask;
  1047. radeon_atom_get_voltage_gpio_settings(rdev,
  1048. MVDD_HIGH_VALUE, SET_VOLTAGE_TYPE_ASIC_MVDDC,
  1049. &gpio_pins, &gpio_mask);
  1050. pi->mvdd_mask_low = gpio_mask;
  1051. pi->mvdd_low_smio[MVDD_HIGH_INDEX] =
  1052. gpio_pins & gpio_mask;
  1053. radeon_atom_get_voltage_gpio_settings(rdev,
  1054. MVDD_LOW_VALUE, SET_VOLTAGE_TYPE_ASIC_MVDDC,
  1055. &gpio_pins, &gpio_mask);
  1056. pi->mvdd_low_smio[MVDD_LOW_INDEX] =
  1057. gpio_pins & gpio_mask;
  1058. return 0;
  1059. }
  1060. u8 rv770_get_memory_module_index(struct radeon_device *rdev)
  1061. {
  1062. return (u8) ((RREG32(BIOS_SCRATCH_4) >> 16) & 0xff);
  1063. }
  1064. static int rv770_get_mvdd_configuration(struct radeon_device *rdev)
  1065. {
  1066. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  1067. u8 memory_module_index;
  1068. struct atom_memory_info memory_info;
  1069. memory_module_index = rv770_get_memory_module_index(rdev);
  1070. if (radeon_atom_get_memory_info(rdev, memory_module_index, &memory_info)) {
  1071. pi->mvdd_control = false;
  1072. return 0;
  1073. }
  1074. pi->mvdd_split_frequency =
  1075. rv770_get_mclk_split_point(&memory_info);
  1076. if (pi->mvdd_split_frequency == 0) {
  1077. pi->mvdd_control = false;
  1078. return 0;
  1079. }
  1080. return rv770_get_mvdd_pin_configuration(rdev);
  1081. }
  1082. void rv770_enable_voltage_control(struct radeon_device *rdev,
  1083. bool enable)
  1084. {
  1085. if (enable)
  1086. WREG32_P(GENERAL_PWRMGT, VOLT_PWRMGT_EN, ~VOLT_PWRMGT_EN);
  1087. else
  1088. WREG32_P(GENERAL_PWRMGT, 0, ~VOLT_PWRMGT_EN);
  1089. }
  1090. static void rv770_program_display_gap(struct radeon_device *rdev)
  1091. {
  1092. u32 tmp = RREG32(CG_DISPLAY_GAP_CNTL);
  1093. tmp &= ~(DISP1_GAP_MCHG_MASK | DISP2_GAP_MCHG_MASK);
  1094. if (rdev->pm.dpm.new_active_crtcs & 1) {
  1095. tmp |= DISP1_GAP_MCHG(R600_PM_DISPLAY_GAP_VBLANK);
  1096. tmp |= DISP2_GAP_MCHG(R600_PM_DISPLAY_GAP_IGNORE);
  1097. } else if (rdev->pm.dpm.new_active_crtcs & 2) {
  1098. tmp |= DISP1_GAP_MCHG(R600_PM_DISPLAY_GAP_IGNORE);
  1099. tmp |= DISP2_GAP_MCHG(R600_PM_DISPLAY_GAP_VBLANK);
  1100. } else {
  1101. tmp |= DISP1_GAP_MCHG(R600_PM_DISPLAY_GAP_IGNORE);
  1102. tmp |= DISP2_GAP_MCHG(R600_PM_DISPLAY_GAP_IGNORE);
  1103. }
  1104. WREG32(CG_DISPLAY_GAP_CNTL, tmp);
  1105. }
  1106. static void rv770_enable_dynamic_pcie_gen2(struct radeon_device *rdev,
  1107. bool enable)
  1108. {
  1109. rv770_enable_bif_dynamic_pcie_gen2(rdev, enable);
  1110. if (enable)
  1111. WREG32_P(GENERAL_PWRMGT, ENABLE_GEN2PCIE, ~ENABLE_GEN2PCIE);
  1112. else
  1113. WREG32_P(GENERAL_PWRMGT, 0, ~ENABLE_GEN2PCIE);
  1114. }
  1115. static void r7xx_program_memory_timing_parameters(struct radeon_device *rdev,
  1116. struct radeon_ps *radeon_new_state)
  1117. {
  1118. if ((rdev->family == CHIP_RV730) ||
  1119. (rdev->family == CHIP_RV710) ||
  1120. (rdev->family == CHIP_RV740))
  1121. rv730_program_memory_timing_parameters(rdev, radeon_new_state);
  1122. else
  1123. rv770_program_memory_timing_parameters(rdev, radeon_new_state);
  1124. }
  1125. static int rv770_upload_sw_state(struct radeon_device *rdev,
  1126. struct radeon_ps *radeon_new_state)
  1127. {
  1128. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  1129. u16 address = pi->state_table_start +
  1130. offsetof(RV770_SMC_STATETABLE, driverState);
  1131. RV770_SMC_SWSTATE state = { 0 };
  1132. int ret;
  1133. ret = rv770_convert_power_state_to_smc(rdev, radeon_new_state, &state);
  1134. if (ret)
  1135. return ret;
  1136. return rv770_copy_bytes_to_smc(rdev, address, (const u8 *)&state,
  1137. sizeof(RV770_SMC_SWSTATE),
  1138. pi->sram_end);
  1139. }
  1140. int rv770_halt_smc(struct radeon_device *rdev)
  1141. {
  1142. if (rv770_send_msg_to_smc(rdev, PPSMC_MSG_Halt) != PPSMC_Result_OK)
  1143. return -EINVAL;
  1144. if (rv770_wait_for_smc_inactive(rdev) != PPSMC_Result_OK)
  1145. return -EINVAL;
  1146. return 0;
  1147. }
  1148. int rv770_resume_smc(struct radeon_device *rdev)
  1149. {
  1150. if (rv770_send_msg_to_smc(rdev, PPSMC_MSG_Resume) != PPSMC_Result_OK)
  1151. return -EINVAL;
  1152. return 0;
  1153. }
  1154. int rv770_set_sw_state(struct radeon_device *rdev)
  1155. {
  1156. if (rv770_send_msg_to_smc(rdev, PPSMC_MSG_SwitchToSwState) != PPSMC_Result_OK)
  1157. DRM_DEBUG("rv770_set_sw_state failed\n");
  1158. return 0;
  1159. }
  1160. int rv770_set_boot_state(struct radeon_device *rdev)
  1161. {
  1162. if (rv770_send_msg_to_smc(rdev, PPSMC_MSG_SwitchToInitialState) != PPSMC_Result_OK)
  1163. return -EINVAL;
  1164. return 0;
  1165. }
  1166. void rv770_set_uvd_clock_before_set_eng_clock(struct radeon_device *rdev,
  1167. struct radeon_ps *new_ps,
  1168. struct radeon_ps *old_ps)
  1169. {
  1170. struct rv7xx_ps *new_state = rv770_get_ps(new_ps);
  1171. struct rv7xx_ps *current_state = rv770_get_ps(old_ps);
  1172. if ((new_ps->vclk == old_ps->vclk) &&
  1173. (new_ps->dclk == old_ps->dclk))
  1174. return;
  1175. if (new_state->high.sclk >= current_state->high.sclk)
  1176. return;
  1177. radeon_set_uvd_clocks(rdev, new_ps->vclk, new_ps->dclk);
  1178. }
  1179. void rv770_set_uvd_clock_after_set_eng_clock(struct radeon_device *rdev,
  1180. struct radeon_ps *new_ps,
  1181. struct radeon_ps *old_ps)
  1182. {
  1183. struct rv7xx_ps *new_state = rv770_get_ps(new_ps);
  1184. struct rv7xx_ps *current_state = rv770_get_ps(old_ps);
  1185. if ((new_ps->vclk == old_ps->vclk) &&
  1186. (new_ps->dclk == old_ps->dclk))
  1187. return;
  1188. if (new_state->high.sclk < current_state->high.sclk)
  1189. return;
  1190. radeon_set_uvd_clocks(rdev, new_ps->vclk, new_ps->dclk);
  1191. }
  1192. int rv770_restrict_performance_levels_before_switch(struct radeon_device *rdev)
  1193. {
  1194. if (rv770_send_msg_to_smc(rdev, (PPSMC_Msg)(PPSMC_MSG_NoForcedLevel)) != PPSMC_Result_OK)
  1195. return -EINVAL;
  1196. if (rv770_send_msg_to_smc(rdev, (PPSMC_Msg)(PPSMC_MSG_TwoLevelsDisabled)) != PPSMC_Result_OK)
  1197. return -EINVAL;
  1198. return 0;
  1199. }
  1200. int rv770_dpm_force_performance_level(struct radeon_device *rdev,
  1201. enum radeon_dpm_forced_level level)
  1202. {
  1203. PPSMC_Msg msg;
  1204. if (level == RADEON_DPM_FORCED_LEVEL_HIGH) {
  1205. if (rv770_send_msg_to_smc(rdev, PPSMC_MSG_ZeroLevelsDisabled) != PPSMC_Result_OK)
  1206. return -EINVAL;
  1207. msg = PPSMC_MSG_ForceHigh;
  1208. } else if (level == RADEON_DPM_FORCED_LEVEL_LOW) {
  1209. if (rv770_send_msg_to_smc(rdev, PPSMC_MSG_NoForcedLevel) != PPSMC_Result_OK)
  1210. return -EINVAL;
  1211. msg = (PPSMC_Msg)(PPSMC_MSG_TwoLevelsDisabled);
  1212. } else {
  1213. if (rv770_send_msg_to_smc(rdev, PPSMC_MSG_NoForcedLevel) != PPSMC_Result_OK)
  1214. return -EINVAL;
  1215. msg = (PPSMC_Msg)(PPSMC_MSG_ZeroLevelsDisabled);
  1216. }
  1217. if (rv770_send_msg_to_smc(rdev, msg) != PPSMC_Result_OK)
  1218. return -EINVAL;
  1219. rdev->pm.dpm.forced_level = level;
  1220. return 0;
  1221. }
  1222. void r7xx_start_smc(struct radeon_device *rdev)
  1223. {
  1224. rv770_start_smc(rdev);
  1225. rv770_start_smc_clock(rdev);
  1226. }
  1227. void r7xx_stop_smc(struct radeon_device *rdev)
  1228. {
  1229. rv770_reset_smc(rdev);
  1230. rv770_stop_smc_clock(rdev);
  1231. }
  1232. static void rv770_read_clock_registers(struct radeon_device *rdev)
  1233. {
  1234. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  1235. pi->clk_regs.rv770.cg_spll_func_cntl =
  1236. RREG32(CG_SPLL_FUNC_CNTL);
  1237. pi->clk_regs.rv770.cg_spll_func_cntl_2 =
  1238. RREG32(CG_SPLL_FUNC_CNTL_2);
  1239. pi->clk_regs.rv770.cg_spll_func_cntl_3 =
  1240. RREG32(CG_SPLL_FUNC_CNTL_3);
  1241. pi->clk_regs.rv770.cg_spll_spread_spectrum =
  1242. RREG32(CG_SPLL_SPREAD_SPECTRUM);
  1243. pi->clk_regs.rv770.cg_spll_spread_spectrum_2 =
  1244. RREG32(CG_SPLL_SPREAD_SPECTRUM_2);
  1245. pi->clk_regs.rv770.mpll_ad_func_cntl =
  1246. RREG32(MPLL_AD_FUNC_CNTL);
  1247. pi->clk_regs.rv770.mpll_ad_func_cntl_2 =
  1248. RREG32(MPLL_AD_FUNC_CNTL_2);
  1249. pi->clk_regs.rv770.mpll_dq_func_cntl =
  1250. RREG32(MPLL_DQ_FUNC_CNTL);
  1251. pi->clk_regs.rv770.mpll_dq_func_cntl_2 =
  1252. RREG32(MPLL_DQ_FUNC_CNTL_2);
  1253. pi->clk_regs.rv770.mclk_pwrmgt_cntl =
  1254. RREG32(MCLK_PWRMGT_CNTL);
  1255. pi->clk_regs.rv770.dll_cntl = RREG32(DLL_CNTL);
  1256. }
  1257. static void r7xx_read_clock_registers(struct radeon_device *rdev)
  1258. {
  1259. if (rdev->family == CHIP_RV740)
  1260. rv740_read_clock_registers(rdev);
  1261. else if ((rdev->family == CHIP_RV730) || (rdev->family == CHIP_RV710))
  1262. rv730_read_clock_registers(rdev);
  1263. else
  1264. rv770_read_clock_registers(rdev);
  1265. }
  1266. void rv770_read_voltage_smio_registers(struct radeon_device *rdev)
  1267. {
  1268. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  1269. pi->s0_vid_lower_smio_cntl =
  1270. RREG32(S0_VID_LOWER_SMIO_CNTL);
  1271. }
  1272. void rv770_reset_smio_status(struct radeon_device *rdev)
  1273. {
  1274. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  1275. u32 sw_smio_index, vid_smio_cntl;
  1276. sw_smio_index =
  1277. (RREG32(GENERAL_PWRMGT) & SW_SMIO_INDEX_MASK) >> SW_SMIO_INDEX_SHIFT;
  1278. switch (sw_smio_index) {
  1279. case 3:
  1280. vid_smio_cntl = RREG32(S3_VID_LOWER_SMIO_CNTL);
  1281. break;
  1282. case 2:
  1283. vid_smio_cntl = RREG32(S2_VID_LOWER_SMIO_CNTL);
  1284. break;
  1285. case 1:
  1286. vid_smio_cntl = RREG32(S1_VID_LOWER_SMIO_CNTL);
  1287. break;
  1288. case 0:
  1289. return;
  1290. default:
  1291. vid_smio_cntl = pi->s0_vid_lower_smio_cntl;
  1292. break;
  1293. }
  1294. WREG32(S0_VID_LOWER_SMIO_CNTL, vid_smio_cntl);
  1295. WREG32_P(GENERAL_PWRMGT, SW_SMIO_INDEX(0), ~SW_SMIO_INDEX_MASK);
  1296. }
  1297. void rv770_get_memory_type(struct radeon_device *rdev)
  1298. {
  1299. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  1300. u32 tmp;
  1301. tmp = RREG32(MC_SEQ_MISC0);
  1302. if (((tmp & MC_SEQ_MISC0_GDDR5_MASK) >> MC_SEQ_MISC0_GDDR5_SHIFT) ==
  1303. MC_SEQ_MISC0_GDDR5_VALUE)
  1304. pi->mem_gddr5 = true;
  1305. else
  1306. pi->mem_gddr5 = false;
  1307. }
  1308. void rv770_get_pcie_gen2_status(struct radeon_device *rdev)
  1309. {
  1310. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  1311. u32 tmp;
  1312. tmp = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
  1313. if ((tmp & LC_OTHER_SIDE_EVER_SENT_GEN2) &&
  1314. (tmp & LC_OTHER_SIDE_SUPPORTS_GEN2))
  1315. pi->pcie_gen2 = true;
  1316. else
  1317. pi->pcie_gen2 = false;
  1318. if (pi->pcie_gen2) {
  1319. if (tmp & LC_CURRENT_DATA_RATE)
  1320. pi->boot_in_gen2 = true;
  1321. else
  1322. pi->boot_in_gen2 = false;
  1323. } else
  1324. pi->boot_in_gen2 = false;
  1325. }
  1326. #if 0
  1327. static int rv770_enter_ulp_state(struct radeon_device *rdev)
  1328. {
  1329. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  1330. if (pi->gfx_clock_gating) {
  1331. WREG32_P(SCLK_PWRMGT_CNTL, 0, ~DYN_GFX_CLK_OFF_EN);
  1332. WREG32_P(SCLK_PWRMGT_CNTL, GFX_CLK_FORCE_ON, ~GFX_CLK_FORCE_ON);
  1333. WREG32_P(SCLK_PWRMGT_CNTL, 0, ~GFX_CLK_FORCE_ON);
  1334. RREG32(GB_TILING_CONFIG);
  1335. }
  1336. WREG32_P(SMC_MSG, HOST_SMC_MSG(PPSMC_MSG_SwitchToMinimumPower),
  1337. ~HOST_SMC_MSG_MASK);
  1338. udelay(7000);
  1339. return 0;
  1340. }
  1341. static int rv770_exit_ulp_state(struct radeon_device *rdev)
  1342. {
  1343. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  1344. int i;
  1345. WREG32_P(SMC_MSG, HOST_SMC_MSG(PPSMC_MSG_ResumeFromMinimumPower),
  1346. ~HOST_SMC_MSG_MASK);
  1347. udelay(7000);
  1348. for (i = 0; i < rdev->usec_timeout; i++) {
  1349. if (((RREG32(SMC_MSG) & HOST_SMC_RESP_MASK) >> HOST_SMC_RESP_SHIFT) == 1)
  1350. break;
  1351. udelay(1000);
  1352. }
  1353. if (pi->gfx_clock_gating)
  1354. WREG32_P(SCLK_PWRMGT_CNTL, DYN_GFX_CLK_OFF_EN, ~DYN_GFX_CLK_OFF_EN);
  1355. return 0;
  1356. }
  1357. #endif
  1358. static void rv770_get_mclk_odt_threshold(struct radeon_device *rdev)
  1359. {
  1360. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  1361. u8 memory_module_index;
  1362. struct atom_memory_info memory_info;
  1363. pi->mclk_odt_threshold = 0;
  1364. if ((rdev->family == CHIP_RV730) || (rdev->family == CHIP_RV710)) {
  1365. memory_module_index = rv770_get_memory_module_index(rdev);
  1366. if (radeon_atom_get_memory_info(rdev, memory_module_index, &memory_info))
  1367. return;
  1368. if (memory_info.mem_type == MEM_TYPE_DDR2 ||
  1369. memory_info.mem_type == MEM_TYPE_DDR3)
  1370. pi->mclk_odt_threshold = 30000;
  1371. }
  1372. }
  1373. void rv770_get_max_vddc(struct radeon_device *rdev)
  1374. {
  1375. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  1376. u16 vddc;
  1377. if (radeon_atom_get_max_vddc(rdev, 0, 0, &vddc))
  1378. pi->max_vddc = 0;
  1379. else
  1380. pi->max_vddc = vddc;
  1381. }
  1382. void rv770_program_response_times(struct radeon_device *rdev)
  1383. {
  1384. u32 voltage_response_time, backbias_response_time;
  1385. u32 acpi_delay_time, vbi_time_out;
  1386. u32 vddc_dly, bb_dly, acpi_dly, vbi_dly;
  1387. u32 reference_clock;
  1388. voltage_response_time = (u32)rdev->pm.dpm.voltage_response_time;
  1389. backbias_response_time = (u32)rdev->pm.dpm.backbias_response_time;
  1390. if (voltage_response_time == 0)
  1391. voltage_response_time = 1000;
  1392. if (backbias_response_time == 0)
  1393. backbias_response_time = 1000;
  1394. acpi_delay_time = 15000;
  1395. vbi_time_out = 100000;
  1396. reference_clock = radeon_get_xclk(rdev);
  1397. vddc_dly = (voltage_response_time * reference_clock) / 1600;
  1398. bb_dly = (backbias_response_time * reference_clock) / 1600;
  1399. acpi_dly = (acpi_delay_time * reference_clock) / 1600;
  1400. vbi_dly = (vbi_time_out * reference_clock) / 1600;
  1401. rv770_write_smc_soft_register(rdev,
  1402. RV770_SMC_SOFT_REGISTER_delay_vreg, vddc_dly);
  1403. rv770_write_smc_soft_register(rdev,
  1404. RV770_SMC_SOFT_REGISTER_delay_bbias, bb_dly);
  1405. rv770_write_smc_soft_register(rdev,
  1406. RV770_SMC_SOFT_REGISTER_delay_acpi, acpi_dly);
  1407. rv770_write_smc_soft_register(rdev,
  1408. RV770_SMC_SOFT_REGISTER_mclk_chg_timeout, vbi_dly);
  1409. #if 0
  1410. /* XXX look up hw revision */
  1411. if (WEKIVA_A21)
  1412. rv770_write_smc_soft_register(rdev,
  1413. RV770_SMC_SOFT_REGISTER_baby_step_timer,
  1414. 0x10);
  1415. #endif
  1416. }
  1417. static void rv770_program_dcodt_before_state_switch(struct radeon_device *rdev,
  1418. struct radeon_ps *radeon_new_state,
  1419. struct radeon_ps *radeon_current_state)
  1420. {
  1421. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  1422. struct rv7xx_ps *new_state = rv770_get_ps(radeon_new_state);
  1423. struct rv7xx_ps *current_state = rv770_get_ps(radeon_current_state);
  1424. bool current_use_dc = false;
  1425. bool new_use_dc = false;
  1426. if (pi->mclk_odt_threshold == 0)
  1427. return;
  1428. if (current_state->high.mclk <= pi->mclk_odt_threshold)
  1429. current_use_dc = true;
  1430. if (new_state->high.mclk <= pi->mclk_odt_threshold)
  1431. new_use_dc = true;
  1432. if (current_use_dc == new_use_dc)
  1433. return;
  1434. if (!current_use_dc && new_use_dc)
  1435. return;
  1436. if ((rdev->family == CHIP_RV730) || (rdev->family == CHIP_RV710))
  1437. rv730_program_dcodt(rdev, new_use_dc);
  1438. }
  1439. static void rv770_program_dcodt_after_state_switch(struct radeon_device *rdev,
  1440. struct radeon_ps *radeon_new_state,
  1441. struct radeon_ps *radeon_current_state)
  1442. {
  1443. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  1444. struct rv7xx_ps *new_state = rv770_get_ps(radeon_new_state);
  1445. struct rv7xx_ps *current_state = rv770_get_ps(radeon_current_state);
  1446. bool current_use_dc = false;
  1447. bool new_use_dc = false;
  1448. if (pi->mclk_odt_threshold == 0)
  1449. return;
  1450. if (current_state->high.mclk <= pi->mclk_odt_threshold)
  1451. current_use_dc = true;
  1452. if (new_state->high.mclk <= pi->mclk_odt_threshold)
  1453. new_use_dc = true;
  1454. if (current_use_dc == new_use_dc)
  1455. return;
  1456. if (current_use_dc && !new_use_dc)
  1457. return;
  1458. if ((rdev->family == CHIP_RV730) || (rdev->family == CHIP_RV710))
  1459. rv730_program_dcodt(rdev, new_use_dc);
  1460. }
  1461. static void rv770_retrieve_odt_values(struct radeon_device *rdev)
  1462. {
  1463. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  1464. if (pi->mclk_odt_threshold == 0)
  1465. return;
  1466. if ((rdev->family == CHIP_RV730) || (rdev->family == CHIP_RV710))
  1467. rv730_get_odt_values(rdev);
  1468. }
  1469. static void rv770_set_dpm_event_sources(struct radeon_device *rdev, u32 sources)
  1470. {
  1471. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  1472. bool want_thermal_protection;
  1473. enum radeon_dpm_event_src dpm_event_src;
  1474. switch (sources) {
  1475. case 0:
  1476. default:
  1477. want_thermal_protection = false;
  1478. break;
  1479. case (1 << RADEON_DPM_AUTO_THROTTLE_SRC_THERMAL):
  1480. want_thermal_protection = true;
  1481. dpm_event_src = RADEON_DPM_EVENT_SRC_DIGITAL;
  1482. break;
  1483. case (1 << RADEON_DPM_AUTO_THROTTLE_SRC_EXTERNAL):
  1484. want_thermal_protection = true;
  1485. dpm_event_src = RADEON_DPM_EVENT_SRC_EXTERNAL;
  1486. break;
  1487. case ((1 << RADEON_DPM_AUTO_THROTTLE_SRC_EXTERNAL) |
  1488. (1 << RADEON_DPM_AUTO_THROTTLE_SRC_THERMAL)):
  1489. want_thermal_protection = true;
  1490. dpm_event_src = RADEON_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL;
  1491. break;
  1492. }
  1493. if (want_thermal_protection) {
  1494. WREG32_P(CG_THERMAL_CTRL, DPM_EVENT_SRC(dpm_event_src), ~DPM_EVENT_SRC_MASK);
  1495. if (pi->thermal_protection)
  1496. WREG32_P(GENERAL_PWRMGT, 0, ~THERMAL_PROTECTION_DIS);
  1497. } else {
  1498. WREG32_P(GENERAL_PWRMGT, THERMAL_PROTECTION_DIS, ~THERMAL_PROTECTION_DIS);
  1499. }
  1500. }
  1501. void rv770_enable_auto_throttle_source(struct radeon_device *rdev,
  1502. enum radeon_dpm_auto_throttle_src source,
  1503. bool enable)
  1504. {
  1505. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  1506. if (enable) {
  1507. if (!(pi->active_auto_throttle_sources & (1 << source))) {
  1508. pi->active_auto_throttle_sources |= 1 << source;
  1509. rv770_set_dpm_event_sources(rdev, pi->active_auto_throttle_sources);
  1510. }
  1511. } else {
  1512. if (pi->active_auto_throttle_sources & (1 << source)) {
  1513. pi->active_auto_throttle_sources &= ~(1 << source);
  1514. rv770_set_dpm_event_sources(rdev, pi->active_auto_throttle_sources);
  1515. }
  1516. }
  1517. }
  1518. static int rv770_set_thermal_temperature_range(struct radeon_device *rdev,
  1519. int min_temp, int max_temp)
  1520. {
  1521. int low_temp = 0 * 1000;
  1522. int high_temp = 255 * 1000;
  1523. if (low_temp < min_temp)
  1524. low_temp = min_temp;
  1525. if (high_temp > max_temp)
  1526. high_temp = max_temp;
  1527. if (high_temp < low_temp) {
  1528. DRM_ERROR("invalid thermal range: %d - %d\n", low_temp, high_temp);
  1529. return -EINVAL;
  1530. }
  1531. WREG32_P(CG_THERMAL_INT, DIG_THERM_INTH(high_temp / 1000), ~DIG_THERM_INTH_MASK);
  1532. WREG32_P(CG_THERMAL_INT, DIG_THERM_INTL(low_temp / 1000), ~DIG_THERM_INTL_MASK);
  1533. WREG32_P(CG_THERMAL_CTRL, DIG_THERM_DPM(high_temp / 1000), ~DIG_THERM_DPM_MASK);
  1534. rdev->pm.dpm.thermal.min_temp = low_temp;
  1535. rdev->pm.dpm.thermal.max_temp = high_temp;
  1536. return 0;
  1537. }
  1538. int rv770_dpm_enable(struct radeon_device *rdev)
  1539. {
  1540. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  1541. struct radeon_ps *boot_ps = rdev->pm.dpm.boot_ps;
  1542. int ret;
  1543. if (pi->gfx_clock_gating)
  1544. rv770_restore_cgcg(rdev);
  1545. if (rv770_dpm_enabled(rdev))
  1546. return -EINVAL;
  1547. if (pi->voltage_control) {
  1548. rv770_enable_voltage_control(rdev, true);
  1549. ret = rv770_construct_vddc_table(rdev);
  1550. if (ret) {
  1551. DRM_ERROR("rv770_construct_vddc_table failed\n");
  1552. return ret;
  1553. }
  1554. }
  1555. if (pi->dcodt)
  1556. rv770_retrieve_odt_values(rdev);
  1557. if (pi->mvdd_control) {
  1558. ret = rv770_get_mvdd_configuration(rdev);
  1559. if (ret) {
  1560. DRM_ERROR("rv770_get_mvdd_configuration failed\n");
  1561. return ret;
  1562. }
  1563. }
  1564. if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_BACKBIAS)
  1565. rv770_enable_backbias(rdev, true);
  1566. rv770_enable_spread_spectrum(rdev, true);
  1567. if (pi->thermal_protection)
  1568. rv770_enable_thermal_protection(rdev, true);
  1569. rv770_program_mpll_timing_parameters(rdev);
  1570. rv770_setup_bsp(rdev);
  1571. rv770_program_git(rdev);
  1572. rv770_program_tp(rdev);
  1573. rv770_program_tpp(rdev);
  1574. rv770_program_sstp(rdev);
  1575. rv770_program_engine_speed_parameters(rdev);
  1576. rv770_enable_display_gap(rdev);
  1577. rv770_program_vc(rdev);
  1578. if (pi->dynamic_pcie_gen2)
  1579. rv770_enable_dynamic_pcie_gen2(rdev, true);
  1580. ret = rv770_upload_firmware(rdev);
  1581. if (ret) {
  1582. DRM_ERROR("rv770_upload_firmware failed\n");
  1583. return ret;
  1584. }
  1585. ret = rv770_init_smc_table(rdev, boot_ps);
  1586. if (ret) {
  1587. DRM_ERROR("rv770_init_smc_table failed\n");
  1588. return ret;
  1589. }
  1590. rv770_program_response_times(rdev);
  1591. r7xx_start_smc(rdev);
  1592. if ((rdev->family == CHIP_RV730) || (rdev->family == CHIP_RV710))
  1593. rv730_start_dpm(rdev);
  1594. else
  1595. rv770_start_dpm(rdev);
  1596. if (pi->gfx_clock_gating)
  1597. rv770_gfx_clock_gating_enable(rdev, true);
  1598. if (pi->mg_clock_gating)
  1599. rv770_mg_clock_gating_enable(rdev, true);
  1600. rv770_enable_auto_throttle_source(rdev, RADEON_DPM_AUTO_THROTTLE_SRC_THERMAL, true);
  1601. return 0;
  1602. }
  1603. int rv770_dpm_late_enable(struct radeon_device *rdev)
  1604. {
  1605. int ret;
  1606. if (rdev->irq.installed &&
  1607. r600_is_internal_thermal_sensor(rdev->pm.int_thermal_type)) {
  1608. PPSMC_Result result;
  1609. ret = rv770_set_thermal_temperature_range(rdev, R600_TEMP_RANGE_MIN, R600_TEMP_RANGE_MAX);
  1610. if (ret)
  1611. return ret;
  1612. rdev->irq.dpm_thermal = true;
  1613. radeon_irq_set(rdev);
  1614. result = rv770_send_msg_to_smc(rdev, PPSMC_MSG_EnableThermalInterrupt);
  1615. if (result != PPSMC_Result_OK)
  1616. DRM_DEBUG_KMS("Could not enable thermal interrupts.\n");
  1617. }
  1618. return 0;
  1619. }
  1620. void rv770_dpm_disable(struct radeon_device *rdev)
  1621. {
  1622. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  1623. if (!rv770_dpm_enabled(rdev))
  1624. return;
  1625. rv770_clear_vc(rdev);
  1626. if (pi->thermal_protection)
  1627. rv770_enable_thermal_protection(rdev, false);
  1628. rv770_enable_spread_spectrum(rdev, false);
  1629. if (pi->dynamic_pcie_gen2)
  1630. rv770_enable_dynamic_pcie_gen2(rdev, false);
  1631. if (rdev->irq.installed &&
  1632. r600_is_internal_thermal_sensor(rdev->pm.int_thermal_type)) {
  1633. rdev->irq.dpm_thermal = false;
  1634. radeon_irq_set(rdev);
  1635. }
  1636. if (pi->gfx_clock_gating)
  1637. rv770_gfx_clock_gating_enable(rdev, false);
  1638. if (pi->mg_clock_gating)
  1639. rv770_mg_clock_gating_enable(rdev, false);
  1640. if ((rdev->family == CHIP_RV730) || (rdev->family == CHIP_RV710))
  1641. rv730_stop_dpm(rdev);
  1642. else
  1643. rv770_stop_dpm(rdev);
  1644. r7xx_stop_smc(rdev);
  1645. rv770_reset_smio_status(rdev);
  1646. }
  1647. int rv770_dpm_set_power_state(struct radeon_device *rdev)
  1648. {
  1649. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  1650. struct radeon_ps *new_ps = rdev->pm.dpm.requested_ps;
  1651. struct radeon_ps *old_ps = rdev->pm.dpm.current_ps;
  1652. int ret;
  1653. ret = rv770_restrict_performance_levels_before_switch(rdev);
  1654. if (ret) {
  1655. DRM_ERROR("rv770_restrict_performance_levels_before_switch failed\n");
  1656. return ret;
  1657. }
  1658. rv770_set_uvd_clock_before_set_eng_clock(rdev, new_ps, old_ps);
  1659. ret = rv770_halt_smc(rdev);
  1660. if (ret) {
  1661. DRM_ERROR("rv770_halt_smc failed\n");
  1662. return ret;
  1663. }
  1664. ret = rv770_upload_sw_state(rdev, new_ps);
  1665. if (ret) {
  1666. DRM_ERROR("rv770_upload_sw_state failed\n");
  1667. return ret;
  1668. }
  1669. r7xx_program_memory_timing_parameters(rdev, new_ps);
  1670. if (pi->dcodt)
  1671. rv770_program_dcodt_before_state_switch(rdev, new_ps, old_ps);
  1672. ret = rv770_resume_smc(rdev);
  1673. if (ret) {
  1674. DRM_ERROR("rv770_resume_smc failed\n");
  1675. return ret;
  1676. }
  1677. ret = rv770_set_sw_state(rdev);
  1678. if (ret) {
  1679. DRM_ERROR("rv770_set_sw_state failed\n");
  1680. return ret;
  1681. }
  1682. if (pi->dcodt)
  1683. rv770_program_dcodt_after_state_switch(rdev, new_ps, old_ps);
  1684. rv770_set_uvd_clock_after_set_eng_clock(rdev, new_ps, old_ps);
  1685. return 0;
  1686. }
  1687. #if 0
  1688. void rv770_dpm_reset_asic(struct radeon_device *rdev)
  1689. {
  1690. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  1691. struct radeon_ps *boot_ps = rdev->pm.dpm.boot_ps;
  1692. rv770_restrict_performance_levels_before_switch(rdev);
  1693. if (pi->dcodt)
  1694. rv770_program_dcodt_before_state_switch(rdev, boot_ps, boot_ps);
  1695. rv770_set_boot_state(rdev);
  1696. if (pi->dcodt)
  1697. rv770_program_dcodt_after_state_switch(rdev, boot_ps, boot_ps);
  1698. }
  1699. #endif
  1700. void rv770_dpm_setup_asic(struct radeon_device *rdev)
  1701. {
  1702. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  1703. r7xx_read_clock_registers(rdev);
  1704. rv770_read_voltage_smio_registers(rdev);
  1705. rv770_get_memory_type(rdev);
  1706. if (pi->dcodt)
  1707. rv770_get_mclk_odt_threshold(rdev);
  1708. rv770_get_pcie_gen2_status(rdev);
  1709. rv770_enable_acpi_pm(rdev);
  1710. if (radeon_aspm != 0) {
  1711. if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_ASPM_L0s)
  1712. rv770_enable_l0s(rdev);
  1713. if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_ASPM_L1)
  1714. rv770_enable_l1(rdev);
  1715. if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_TURNOFFPLL_ASPML1)
  1716. rv770_enable_pll_sleep_in_l1(rdev);
  1717. }
  1718. }
  1719. void rv770_dpm_display_configuration_changed(struct radeon_device *rdev)
  1720. {
  1721. rv770_program_display_gap(rdev);
  1722. }
  1723. union power_info {
  1724. struct _ATOM_POWERPLAY_INFO info;
  1725. struct _ATOM_POWERPLAY_INFO_V2 info_2;
  1726. struct _ATOM_POWERPLAY_INFO_V3 info_3;
  1727. struct _ATOM_PPLIB_POWERPLAYTABLE pplib;
  1728. struct _ATOM_PPLIB_POWERPLAYTABLE2 pplib2;
  1729. struct _ATOM_PPLIB_POWERPLAYTABLE3 pplib3;
  1730. };
  1731. union pplib_clock_info {
  1732. struct _ATOM_PPLIB_R600_CLOCK_INFO r600;
  1733. struct _ATOM_PPLIB_RS780_CLOCK_INFO rs780;
  1734. struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO evergreen;
  1735. struct _ATOM_PPLIB_SUMO_CLOCK_INFO sumo;
  1736. };
  1737. union pplib_power_state {
  1738. struct _ATOM_PPLIB_STATE v1;
  1739. struct _ATOM_PPLIB_STATE_V2 v2;
  1740. };
  1741. static void rv7xx_parse_pplib_non_clock_info(struct radeon_device *rdev,
  1742. struct radeon_ps *rps,
  1743. struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info,
  1744. u8 table_rev)
  1745. {
  1746. rps->caps = le32_to_cpu(non_clock_info->ulCapsAndSettings);
  1747. rps->class = le16_to_cpu(non_clock_info->usClassification);
  1748. rps->class2 = le16_to_cpu(non_clock_info->usClassification2);
  1749. if (ATOM_PPLIB_NONCLOCKINFO_VER1 < table_rev) {
  1750. rps->vclk = le32_to_cpu(non_clock_info->ulVCLK);
  1751. rps->dclk = le32_to_cpu(non_clock_info->ulDCLK);
  1752. } else {
  1753. rps->vclk = 0;
  1754. rps->dclk = 0;
  1755. }
  1756. if (r600_is_uvd_state(rps->class, rps->class2)) {
  1757. if ((rps->vclk == 0) || (rps->dclk == 0)) {
  1758. rps->vclk = RV770_DEFAULT_VCLK_FREQ;
  1759. rps->dclk = RV770_DEFAULT_DCLK_FREQ;
  1760. }
  1761. }
  1762. if (rps->class & ATOM_PPLIB_CLASSIFICATION_BOOT)
  1763. rdev->pm.dpm.boot_ps = rps;
  1764. if (rps->class & ATOM_PPLIB_CLASSIFICATION_UVDSTATE)
  1765. rdev->pm.dpm.uvd_ps = rps;
  1766. }
  1767. static void rv7xx_parse_pplib_clock_info(struct radeon_device *rdev,
  1768. struct radeon_ps *rps, int index,
  1769. union pplib_clock_info *clock_info)
  1770. {
  1771. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  1772. struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
  1773. struct rv7xx_ps *ps = rv770_get_ps(rps);
  1774. u32 sclk, mclk;
  1775. struct rv7xx_pl *pl;
  1776. switch (index) {
  1777. case 0:
  1778. pl = &ps->low;
  1779. break;
  1780. case 1:
  1781. pl = &ps->medium;
  1782. break;
  1783. case 2:
  1784. default:
  1785. pl = &ps->high;
  1786. break;
  1787. }
  1788. if (rdev->family >= CHIP_CEDAR) {
  1789. sclk = le16_to_cpu(clock_info->evergreen.usEngineClockLow);
  1790. sclk |= clock_info->evergreen.ucEngineClockHigh << 16;
  1791. mclk = le16_to_cpu(clock_info->evergreen.usMemoryClockLow);
  1792. mclk |= clock_info->evergreen.ucMemoryClockHigh << 16;
  1793. pl->vddc = le16_to_cpu(clock_info->evergreen.usVDDC);
  1794. pl->vddci = le16_to_cpu(clock_info->evergreen.usVDDCI);
  1795. pl->flags = le32_to_cpu(clock_info->evergreen.ulFlags);
  1796. } else {
  1797. sclk = le16_to_cpu(clock_info->r600.usEngineClockLow);
  1798. sclk |= clock_info->r600.ucEngineClockHigh << 16;
  1799. mclk = le16_to_cpu(clock_info->r600.usMemoryClockLow);
  1800. mclk |= clock_info->r600.ucMemoryClockHigh << 16;
  1801. pl->vddc = le16_to_cpu(clock_info->r600.usVDDC);
  1802. pl->flags = le32_to_cpu(clock_info->r600.ulFlags);
  1803. }
  1804. pl->mclk = mclk;
  1805. pl->sclk = sclk;
  1806. /* patch up vddc if necessary */
  1807. if (pl->vddc == 0xff01) {
  1808. if (pi->max_vddc)
  1809. pl->vddc = pi->max_vddc;
  1810. }
  1811. if (rps->class & ATOM_PPLIB_CLASSIFICATION_ACPI) {
  1812. pi->acpi_vddc = pl->vddc;
  1813. if (rdev->family >= CHIP_CEDAR)
  1814. eg_pi->acpi_vddci = pl->vddci;
  1815. if (ps->low.flags & ATOM_PPLIB_R600_FLAGS_PCIEGEN2)
  1816. pi->acpi_pcie_gen2 = true;
  1817. else
  1818. pi->acpi_pcie_gen2 = false;
  1819. }
  1820. if (rps->class2 & ATOM_PPLIB_CLASSIFICATION2_ULV) {
  1821. if (rdev->family >= CHIP_BARTS) {
  1822. eg_pi->ulv.supported = true;
  1823. eg_pi->ulv.pl = pl;
  1824. }
  1825. }
  1826. if (pi->min_vddc_in_table > pl->vddc)
  1827. pi->min_vddc_in_table = pl->vddc;
  1828. if (pi->max_vddc_in_table < pl->vddc)
  1829. pi->max_vddc_in_table = pl->vddc;
  1830. /* patch up boot state */
  1831. if (rps->class & ATOM_PPLIB_CLASSIFICATION_BOOT) {
  1832. u16 vddc, vddci, mvdd;
  1833. radeon_atombios_get_default_voltages(rdev, &vddc, &vddci, &mvdd);
  1834. pl->mclk = rdev->clock.default_mclk;
  1835. pl->sclk = rdev->clock.default_sclk;
  1836. pl->vddc = vddc;
  1837. pl->vddci = vddci;
  1838. }
  1839. if ((rps->class & ATOM_PPLIB_CLASSIFICATION_UI_MASK) ==
  1840. ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE) {
  1841. rdev->pm.dpm.dyn_state.max_clock_voltage_on_ac.sclk = pl->sclk;
  1842. rdev->pm.dpm.dyn_state.max_clock_voltage_on_ac.mclk = pl->mclk;
  1843. rdev->pm.dpm.dyn_state.max_clock_voltage_on_ac.vddc = pl->vddc;
  1844. rdev->pm.dpm.dyn_state.max_clock_voltage_on_ac.vddci = pl->vddci;
  1845. }
  1846. }
  1847. int rv7xx_parse_power_table(struct radeon_device *rdev)
  1848. {
  1849. struct radeon_mode_info *mode_info = &rdev->mode_info;
  1850. struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
  1851. union pplib_power_state *power_state;
  1852. int i, j;
  1853. union pplib_clock_info *clock_info;
  1854. union power_info *power_info;
  1855. int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
  1856. u16 data_offset;
  1857. u8 frev, crev;
  1858. struct rv7xx_ps *ps;
  1859. if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
  1860. &frev, &crev, &data_offset))
  1861. return -EINVAL;
  1862. power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
  1863. rdev->pm.dpm.ps = kzalloc(sizeof(struct radeon_ps) *
  1864. power_info->pplib.ucNumStates, GFP_KERNEL);
  1865. if (!rdev->pm.dpm.ps)
  1866. return -ENOMEM;
  1867. for (i = 0; i < power_info->pplib.ucNumStates; i++) {
  1868. power_state = (union pplib_power_state *)
  1869. (mode_info->atom_context->bios + data_offset +
  1870. le16_to_cpu(power_info->pplib.usStateArrayOffset) +
  1871. i * power_info->pplib.ucStateEntrySize);
  1872. non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
  1873. (mode_info->atom_context->bios + data_offset +
  1874. le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset) +
  1875. (power_state->v1.ucNonClockStateIndex *
  1876. power_info->pplib.ucNonClockSize));
  1877. if (power_info->pplib.ucStateEntrySize - 1) {
  1878. u8 *idx;
  1879. ps = kzalloc(sizeof(struct rv7xx_ps), GFP_KERNEL);
  1880. if (ps == NULL) {
  1881. kfree(rdev->pm.dpm.ps);
  1882. return -ENOMEM;
  1883. }
  1884. rdev->pm.dpm.ps[i].ps_priv = ps;
  1885. rv7xx_parse_pplib_non_clock_info(rdev, &rdev->pm.dpm.ps[i],
  1886. non_clock_info,
  1887. power_info->pplib.ucNonClockSize);
  1888. idx = (u8 *)&power_state->v1.ucClockStateIndices[0];
  1889. for (j = 0; j < (power_info->pplib.ucStateEntrySize - 1); j++) {
  1890. clock_info = (union pplib_clock_info *)
  1891. (mode_info->atom_context->bios + data_offset +
  1892. le16_to_cpu(power_info->pplib.usClockInfoArrayOffset) +
  1893. (idx[j] * power_info->pplib.ucClockInfoSize));
  1894. rv7xx_parse_pplib_clock_info(rdev,
  1895. &rdev->pm.dpm.ps[i], j,
  1896. clock_info);
  1897. }
  1898. }
  1899. }
  1900. rdev->pm.dpm.num_ps = power_info->pplib.ucNumStates;
  1901. return 0;
  1902. }
  1903. void rv770_get_engine_memory_ss(struct radeon_device *rdev)
  1904. {
  1905. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  1906. struct radeon_atom_ss ss;
  1907. pi->sclk_ss = radeon_atombios_get_asic_ss_info(rdev, &ss,
  1908. ASIC_INTERNAL_ENGINE_SS, 0);
  1909. pi->mclk_ss = radeon_atombios_get_asic_ss_info(rdev, &ss,
  1910. ASIC_INTERNAL_MEMORY_SS, 0);
  1911. if (pi->sclk_ss || pi->mclk_ss)
  1912. pi->dynamic_ss = true;
  1913. else
  1914. pi->dynamic_ss = false;
  1915. }
  1916. int rv770_dpm_init(struct radeon_device *rdev)
  1917. {
  1918. struct rv7xx_power_info *pi;
  1919. struct atom_clock_dividers dividers;
  1920. int ret;
  1921. pi = kzalloc(sizeof(struct rv7xx_power_info), GFP_KERNEL);
  1922. if (pi == NULL)
  1923. return -ENOMEM;
  1924. rdev->pm.dpm.priv = pi;
  1925. rv770_get_max_vddc(rdev);
  1926. pi->acpi_vddc = 0;
  1927. pi->min_vddc_in_table = 0;
  1928. pi->max_vddc_in_table = 0;
  1929. ret = r600_get_platform_caps(rdev);
  1930. if (ret)
  1931. return ret;
  1932. ret = rv7xx_parse_power_table(rdev);
  1933. if (ret)
  1934. return ret;
  1935. if (rdev->pm.dpm.voltage_response_time == 0)
  1936. rdev->pm.dpm.voltage_response_time = R600_VOLTAGERESPONSETIME_DFLT;
  1937. if (rdev->pm.dpm.backbias_response_time == 0)
  1938. rdev->pm.dpm.backbias_response_time = R600_BACKBIASRESPONSETIME_DFLT;
  1939. ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
  1940. 0, false, &dividers);
  1941. if (ret)
  1942. pi->ref_div = dividers.ref_div + 1;
  1943. else
  1944. pi->ref_div = R600_REFERENCEDIVIDER_DFLT;
  1945. pi->mclk_strobe_mode_threshold = 30000;
  1946. pi->mclk_edc_enable_threshold = 30000;
  1947. pi->rlp = RV770_RLP_DFLT;
  1948. pi->rmp = RV770_RMP_DFLT;
  1949. pi->lhp = RV770_LHP_DFLT;
  1950. pi->lmp = RV770_LMP_DFLT;
  1951. pi->voltage_control =
  1952. radeon_atom_is_voltage_gpio(rdev, SET_VOLTAGE_TYPE_ASIC_VDDC, 0);
  1953. pi->mvdd_control =
  1954. radeon_atom_is_voltage_gpio(rdev, SET_VOLTAGE_TYPE_ASIC_MVDDC, 0);
  1955. rv770_get_engine_memory_ss(rdev);
  1956. pi->asi = RV770_ASI_DFLT;
  1957. pi->pasi = RV770_HASI_DFLT;
  1958. pi->vrc = RV770_VRC_DFLT;
  1959. pi->power_gating = false;
  1960. pi->gfx_clock_gating = true;
  1961. pi->mg_clock_gating = true;
  1962. pi->mgcgtssm = true;
  1963. pi->dynamic_pcie_gen2 = true;
  1964. if (rdev->pm.int_thermal_type != THERMAL_TYPE_NONE)
  1965. pi->thermal_protection = true;
  1966. else
  1967. pi->thermal_protection = false;
  1968. pi->display_gap = true;
  1969. if (rdev->flags & RADEON_IS_MOBILITY)
  1970. pi->dcodt = true;
  1971. else
  1972. pi->dcodt = false;
  1973. pi->ulps = true;
  1974. pi->mclk_stutter_mode_threshold = 0;
  1975. pi->sram_end = SMC_RAM_END;
  1976. pi->state_table_start = RV770_SMC_TABLE_ADDRESS;
  1977. pi->soft_regs_start = RV770_SMC_SOFT_REGISTERS_START;
  1978. return 0;
  1979. }
  1980. void rv770_dpm_print_power_state(struct radeon_device *rdev,
  1981. struct radeon_ps *rps)
  1982. {
  1983. struct rv7xx_ps *ps = rv770_get_ps(rps);
  1984. struct rv7xx_pl *pl;
  1985. r600_dpm_print_class_info(rps->class, rps->class2);
  1986. r600_dpm_print_cap_info(rps->caps);
  1987. printk("\tuvd vclk: %d dclk: %d\n", rps->vclk, rps->dclk);
  1988. if (rdev->family >= CHIP_CEDAR) {
  1989. pl = &ps->low;
  1990. printk("\t\tpower level 0 sclk: %u mclk: %u vddc: %u vddci: %u\n",
  1991. pl->sclk, pl->mclk, pl->vddc, pl->vddci);
  1992. pl = &ps->medium;
  1993. printk("\t\tpower level 1 sclk: %u mclk: %u vddc: %u vddci: %u\n",
  1994. pl->sclk, pl->mclk, pl->vddc, pl->vddci);
  1995. pl = &ps->high;
  1996. printk("\t\tpower level 2 sclk: %u mclk: %u vddc: %u vddci: %u\n",
  1997. pl->sclk, pl->mclk, pl->vddc, pl->vddci);
  1998. } else {
  1999. pl = &ps->low;
  2000. printk("\t\tpower level 0 sclk: %u mclk: %u vddc: %u\n",
  2001. pl->sclk, pl->mclk, pl->vddc);
  2002. pl = &ps->medium;
  2003. printk("\t\tpower level 1 sclk: %u mclk: %u vddc: %u\n",
  2004. pl->sclk, pl->mclk, pl->vddc);
  2005. pl = &ps->high;
  2006. printk("\t\tpower level 2 sclk: %u mclk: %u vddc: %u\n",
  2007. pl->sclk, pl->mclk, pl->vddc);
  2008. }
  2009. r600_dpm_print_ps_status(rdev, rps);
  2010. }
  2011. void rv770_dpm_debugfs_print_current_performance_level(struct radeon_device *rdev,
  2012. struct seq_file *m)
  2013. {
  2014. struct radeon_ps *rps = rdev->pm.dpm.current_ps;
  2015. struct rv7xx_ps *ps = rv770_get_ps(rps);
  2016. struct rv7xx_pl *pl;
  2017. u32 current_index =
  2018. (RREG32(TARGET_AND_CURRENT_PROFILE_INDEX) & CURRENT_PROFILE_INDEX_MASK) >>
  2019. CURRENT_PROFILE_INDEX_SHIFT;
  2020. if (current_index > 2) {
  2021. seq_printf(m, "invalid dpm profile %d\n", current_index);
  2022. } else {
  2023. if (current_index == 0)
  2024. pl = &ps->low;
  2025. else if (current_index == 1)
  2026. pl = &ps->medium;
  2027. else /* current_index == 2 */
  2028. pl = &ps->high;
  2029. seq_printf(m, "uvd vclk: %d dclk: %d\n", rps->vclk, rps->dclk);
  2030. if (rdev->family >= CHIP_CEDAR) {
  2031. seq_printf(m, "power level %d sclk: %u mclk: %u vddc: %u vddci: %u\n",
  2032. current_index, pl->sclk, pl->mclk, pl->vddc, pl->vddci);
  2033. } else {
  2034. seq_printf(m, "power level %d sclk: %u mclk: %u vddc: %u\n",
  2035. current_index, pl->sclk, pl->mclk, pl->vddc);
  2036. }
  2037. }
  2038. }
  2039. u32 rv770_dpm_get_current_sclk(struct radeon_device *rdev)
  2040. {
  2041. struct radeon_ps *rps = rdev->pm.dpm.current_ps;
  2042. struct rv7xx_ps *ps = rv770_get_ps(rps);
  2043. struct rv7xx_pl *pl;
  2044. u32 current_index =
  2045. (RREG32(TARGET_AND_CURRENT_PROFILE_INDEX) & CURRENT_PROFILE_INDEX_MASK) >>
  2046. CURRENT_PROFILE_INDEX_SHIFT;
  2047. if (current_index > 2) {
  2048. return 0;
  2049. } else {
  2050. if (current_index == 0)
  2051. pl = &ps->low;
  2052. else if (current_index == 1)
  2053. pl = &ps->medium;
  2054. else /* current_index == 2 */
  2055. pl = &ps->high;
  2056. return pl->sclk;
  2057. }
  2058. }
  2059. u32 rv770_dpm_get_current_mclk(struct radeon_device *rdev)
  2060. {
  2061. struct radeon_ps *rps = rdev->pm.dpm.current_ps;
  2062. struct rv7xx_ps *ps = rv770_get_ps(rps);
  2063. struct rv7xx_pl *pl;
  2064. u32 current_index =
  2065. (RREG32(TARGET_AND_CURRENT_PROFILE_INDEX) & CURRENT_PROFILE_INDEX_MASK) >>
  2066. CURRENT_PROFILE_INDEX_SHIFT;
  2067. if (current_index > 2) {
  2068. return 0;
  2069. } else {
  2070. if (current_index == 0)
  2071. pl = &ps->low;
  2072. else if (current_index == 1)
  2073. pl = &ps->medium;
  2074. else /* current_index == 2 */
  2075. pl = &ps->high;
  2076. return pl->mclk;
  2077. }
  2078. }
  2079. void rv770_dpm_fini(struct radeon_device *rdev)
  2080. {
  2081. int i;
  2082. for (i = 0; i < rdev->pm.dpm.num_ps; i++) {
  2083. kfree(rdev->pm.dpm.ps[i].ps_priv);
  2084. }
  2085. kfree(rdev->pm.dpm.ps);
  2086. kfree(rdev->pm.dpm.priv);
  2087. }
  2088. u32 rv770_dpm_get_sclk(struct radeon_device *rdev, bool low)
  2089. {
  2090. struct rv7xx_ps *requested_state = rv770_get_ps(rdev->pm.dpm.requested_ps);
  2091. if (low)
  2092. return requested_state->low.sclk;
  2093. else
  2094. return requested_state->high.sclk;
  2095. }
  2096. u32 rv770_dpm_get_mclk(struct radeon_device *rdev, bool low)
  2097. {
  2098. struct rv7xx_ps *requested_state = rv770_get_ps(rdev->pm.dpm.requested_ps);
  2099. if (low)
  2100. return requested_state->low.mclk;
  2101. else
  2102. return requested_state->high.mclk;
  2103. }
  2104. bool rv770_dpm_vblank_too_short(struct radeon_device *rdev)
  2105. {
  2106. u32 vblank_time = r600_dpm_get_vblank_time(rdev);
  2107. u32 switch_limit = 200; /* 300 */
  2108. /* RV770 */
  2109. /* mclk switching doesn't seem to work reliably on desktop RV770s */
  2110. if ((rdev->family == CHIP_RV770) &&
  2111. !(rdev->flags & RADEON_IS_MOBILITY))
  2112. switch_limit = 0xffffffff; /* disable mclk switching */
  2113. if (vblank_time < switch_limit)
  2114. return true;
  2115. else
  2116. return false;
  2117. }