rv730_dpm.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  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 "rv730d.h"
  27. #include "r600_dpm.h"
  28. #include "rv770_dpm.h"
  29. #include "atom.h"
  30. #define MC_CG_ARB_FREQ_F0 0x0a
  31. #define MC_CG_ARB_FREQ_F1 0x0b
  32. #define MC_CG_ARB_FREQ_F2 0x0c
  33. #define MC_CG_ARB_FREQ_F3 0x0d
  34. struct rv7xx_ps *rv770_get_ps(struct radeon_ps *rps);
  35. struct rv7xx_power_info *rv770_get_pi(struct radeon_device *rdev);
  36. int rv730_populate_sclk_value(struct radeon_device *rdev,
  37. u32 engine_clock,
  38. RV770_SMC_SCLK_VALUE *sclk)
  39. {
  40. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  41. struct atom_clock_dividers dividers;
  42. u32 spll_func_cntl = pi->clk_regs.rv730.cg_spll_func_cntl;
  43. u32 spll_func_cntl_2 = pi->clk_regs.rv730.cg_spll_func_cntl_2;
  44. u32 spll_func_cntl_3 = pi->clk_regs.rv730.cg_spll_func_cntl_3;
  45. u32 cg_spll_spread_spectrum = pi->clk_regs.rv730.cg_spll_spread_spectrum;
  46. u32 cg_spll_spread_spectrum_2 = pi->clk_regs.rv730.cg_spll_spread_spectrum_2;
  47. u64 tmp;
  48. u32 reference_clock = rdev->clock.spll.reference_freq;
  49. u32 reference_divider, post_divider;
  50. u32 fbdiv;
  51. int ret;
  52. ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
  53. engine_clock, false, &dividers);
  54. if (ret)
  55. return ret;
  56. reference_divider = 1 + dividers.ref_div;
  57. if (dividers.enable_post_div)
  58. post_divider = ((dividers.post_div >> 4) & 0xf) +
  59. (dividers.post_div & 0xf) + 2;
  60. else
  61. post_divider = 1;
  62. tmp = (u64) engine_clock * reference_divider * post_divider * 16384;
  63. do_div(tmp, reference_clock);
  64. fbdiv = (u32) tmp;
  65. /* set up registers */
  66. if (dividers.enable_post_div)
  67. spll_func_cntl |= SPLL_DIVEN;
  68. else
  69. spll_func_cntl &= ~SPLL_DIVEN;
  70. spll_func_cntl &= ~(SPLL_HILEN_MASK | SPLL_LOLEN_MASK | SPLL_REF_DIV_MASK);
  71. spll_func_cntl |= SPLL_REF_DIV(dividers.ref_div);
  72. spll_func_cntl |= SPLL_HILEN((dividers.post_div >> 4) & 0xf);
  73. spll_func_cntl |= SPLL_LOLEN(dividers.post_div & 0xf);
  74. spll_func_cntl_2 &= ~SCLK_MUX_SEL_MASK;
  75. spll_func_cntl_2 |= SCLK_MUX_SEL(2);
  76. spll_func_cntl_3 &= ~SPLL_FB_DIV_MASK;
  77. spll_func_cntl_3 |= SPLL_FB_DIV(fbdiv);
  78. spll_func_cntl_3 |= SPLL_DITHEN;
  79. if (pi->sclk_ss) {
  80. struct radeon_atom_ss ss;
  81. u32 vco_freq = engine_clock * post_divider;
  82. if (radeon_atombios_get_asic_ss_info(rdev, &ss,
  83. ASIC_INTERNAL_ENGINE_SS, vco_freq)) {
  84. u32 clk_s = reference_clock * 5 / (reference_divider * ss.rate);
  85. u32 clk_v = ss.percentage * fbdiv / (clk_s * 10000);
  86. cg_spll_spread_spectrum &= ~CLK_S_MASK;
  87. cg_spll_spread_spectrum |= CLK_S(clk_s);
  88. cg_spll_spread_spectrum |= SSEN;
  89. cg_spll_spread_spectrum_2 &= ~CLK_V_MASK;
  90. cg_spll_spread_spectrum_2 |= CLK_V(clk_v);
  91. }
  92. }
  93. sclk->sclk_value = cpu_to_be32(engine_clock);
  94. sclk->vCG_SPLL_FUNC_CNTL = cpu_to_be32(spll_func_cntl);
  95. sclk->vCG_SPLL_FUNC_CNTL_2 = cpu_to_be32(spll_func_cntl_2);
  96. sclk->vCG_SPLL_FUNC_CNTL_3 = cpu_to_be32(spll_func_cntl_3);
  97. sclk->vCG_SPLL_SPREAD_SPECTRUM = cpu_to_be32(cg_spll_spread_spectrum);
  98. sclk->vCG_SPLL_SPREAD_SPECTRUM_2 = cpu_to_be32(cg_spll_spread_spectrum_2);
  99. return 0;
  100. }
  101. int rv730_populate_mclk_value(struct radeon_device *rdev,
  102. u32 engine_clock, u32 memory_clock,
  103. LPRV7XX_SMC_MCLK_VALUE mclk)
  104. {
  105. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  106. u32 mclk_pwrmgt_cntl = pi->clk_regs.rv730.mclk_pwrmgt_cntl;
  107. u32 dll_cntl = pi->clk_regs.rv730.dll_cntl;
  108. u32 mpll_func_cntl = pi->clk_regs.rv730.mpll_func_cntl;
  109. u32 mpll_func_cntl_2 = pi->clk_regs.rv730.mpll_func_cntl2;
  110. u32 mpll_func_cntl_3 = pi->clk_regs.rv730.mpll_func_cntl3;
  111. u32 mpll_ss = pi->clk_regs.rv730.mpll_ss;
  112. u32 mpll_ss2 = pi->clk_regs.rv730.mpll_ss2;
  113. struct atom_clock_dividers dividers;
  114. u32 post_divider, reference_divider;
  115. int ret;
  116. ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_MEMORY_PLL_PARAM,
  117. memory_clock, false, &dividers);
  118. if (ret)
  119. return ret;
  120. reference_divider = dividers.ref_div + 1;
  121. if (dividers.enable_post_div)
  122. post_divider = ((dividers.post_div >> 4) & 0xf) +
  123. (dividers.post_div & 0xf) + 2;
  124. else
  125. post_divider = 1;
  126. /* setup the registers */
  127. if (dividers.enable_post_div)
  128. mpll_func_cntl |= MPLL_DIVEN;
  129. else
  130. mpll_func_cntl &= ~MPLL_DIVEN;
  131. mpll_func_cntl &= ~(MPLL_REF_DIV_MASK | MPLL_HILEN_MASK | MPLL_LOLEN_MASK);
  132. mpll_func_cntl |= MPLL_REF_DIV(dividers.ref_div);
  133. mpll_func_cntl |= MPLL_HILEN((dividers.post_div >> 4) & 0xf);
  134. mpll_func_cntl |= MPLL_LOLEN(dividers.post_div & 0xf);
  135. mpll_func_cntl_3 &= ~MPLL_FB_DIV_MASK;
  136. mpll_func_cntl_3 |= MPLL_FB_DIV(dividers.fb_div);
  137. if (dividers.enable_dithen)
  138. mpll_func_cntl_3 |= MPLL_DITHEN;
  139. else
  140. mpll_func_cntl_3 &= ~MPLL_DITHEN;
  141. if (pi->mclk_ss) {
  142. struct radeon_atom_ss ss;
  143. u32 vco_freq = memory_clock * post_divider;
  144. if (radeon_atombios_get_asic_ss_info(rdev, &ss,
  145. ASIC_INTERNAL_MEMORY_SS, vco_freq)) {
  146. u32 reference_clock = rdev->clock.mpll.reference_freq;
  147. u32 clk_s = reference_clock * 5 / (reference_divider * ss.rate);
  148. u32 clk_v = ss.percentage * dividers.fb_div / (clk_s * 10000);
  149. mpll_ss &= ~CLK_S_MASK;
  150. mpll_ss |= CLK_S(clk_s);
  151. mpll_ss |= SSEN;
  152. mpll_ss2 &= ~CLK_V_MASK;
  153. mpll_ss |= CLK_V(clk_v);
  154. }
  155. }
  156. mclk->mclk730.vMCLK_PWRMGT_CNTL = cpu_to_be32(mclk_pwrmgt_cntl);
  157. mclk->mclk730.vDLL_CNTL = cpu_to_be32(dll_cntl);
  158. mclk->mclk730.mclk_value = cpu_to_be32(memory_clock);
  159. mclk->mclk730.vMPLL_FUNC_CNTL = cpu_to_be32(mpll_func_cntl);
  160. mclk->mclk730.vMPLL_FUNC_CNTL2 = cpu_to_be32(mpll_func_cntl_2);
  161. mclk->mclk730.vMPLL_FUNC_CNTL3 = cpu_to_be32(mpll_func_cntl_3);
  162. mclk->mclk730.vMPLL_SS = cpu_to_be32(mpll_ss);
  163. mclk->mclk730.vMPLL_SS2 = cpu_to_be32(mpll_ss2);
  164. return 0;
  165. }
  166. void rv730_read_clock_registers(struct radeon_device *rdev)
  167. {
  168. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  169. pi->clk_regs.rv730.cg_spll_func_cntl =
  170. RREG32(CG_SPLL_FUNC_CNTL);
  171. pi->clk_regs.rv730.cg_spll_func_cntl_2 =
  172. RREG32(CG_SPLL_FUNC_CNTL_2);
  173. pi->clk_regs.rv730.cg_spll_func_cntl_3 =
  174. RREG32(CG_SPLL_FUNC_CNTL_3);
  175. pi->clk_regs.rv730.cg_spll_spread_spectrum =
  176. RREG32(CG_SPLL_SPREAD_SPECTRUM);
  177. pi->clk_regs.rv730.cg_spll_spread_spectrum_2 =
  178. RREG32(CG_SPLL_SPREAD_SPECTRUM_2);
  179. pi->clk_regs.rv730.mclk_pwrmgt_cntl =
  180. RREG32(TCI_MCLK_PWRMGT_CNTL);
  181. pi->clk_regs.rv730.dll_cntl =
  182. RREG32(TCI_DLL_CNTL);
  183. pi->clk_regs.rv730.mpll_func_cntl =
  184. RREG32(CG_MPLL_FUNC_CNTL);
  185. pi->clk_regs.rv730.mpll_func_cntl2 =
  186. RREG32(CG_MPLL_FUNC_CNTL_2);
  187. pi->clk_regs.rv730.mpll_func_cntl3 =
  188. RREG32(CG_MPLL_FUNC_CNTL_3);
  189. pi->clk_regs.rv730.mpll_ss =
  190. RREG32(CG_TCI_MPLL_SPREAD_SPECTRUM);
  191. pi->clk_regs.rv730.mpll_ss2 =
  192. RREG32(CG_TCI_MPLL_SPREAD_SPECTRUM_2);
  193. }
  194. int rv730_populate_smc_acpi_state(struct radeon_device *rdev,
  195. RV770_SMC_STATETABLE *table)
  196. {
  197. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  198. u32 mpll_func_cntl = 0;
  199. u32 mpll_func_cntl_2 = 0 ;
  200. u32 mpll_func_cntl_3 = 0;
  201. u32 mclk_pwrmgt_cntl;
  202. u32 dll_cntl;
  203. u32 spll_func_cntl;
  204. u32 spll_func_cntl_2;
  205. u32 spll_func_cntl_3;
  206. table->ACPIState = table->initialState;
  207. table->ACPIState.flags &= ~PPSMC_SWSTATE_FLAG_DC;
  208. if (pi->acpi_vddc) {
  209. rv770_populate_vddc_value(rdev, pi->acpi_vddc,
  210. &table->ACPIState.levels[0].vddc);
  211. table->ACPIState.levels[0].gen2PCIE = pi->pcie_gen2 ?
  212. pi->acpi_pcie_gen2 : 0;
  213. table->ACPIState.levels[0].gen2XSP =
  214. pi->acpi_pcie_gen2;
  215. } else {
  216. rv770_populate_vddc_value(rdev, pi->min_vddc_in_table,
  217. &table->ACPIState.levels[0].vddc);
  218. table->ACPIState.levels[0].gen2PCIE = 0;
  219. }
  220. mpll_func_cntl = pi->clk_regs.rv730.mpll_func_cntl;
  221. mpll_func_cntl_2 = pi->clk_regs.rv730.mpll_func_cntl2;
  222. mpll_func_cntl_3 = pi->clk_regs.rv730.mpll_func_cntl3;
  223. mpll_func_cntl |= MPLL_RESET | MPLL_BYPASS_EN;
  224. mpll_func_cntl &= ~MPLL_SLEEP;
  225. mpll_func_cntl_2 &= ~MCLK_MUX_SEL_MASK;
  226. mpll_func_cntl_2 |= MCLK_MUX_SEL(1);
  227. mclk_pwrmgt_cntl = (MRDCKA_RESET |
  228. MRDCKB_RESET |
  229. MRDCKC_RESET |
  230. MRDCKD_RESET |
  231. MRDCKE_RESET |
  232. MRDCKF_RESET |
  233. MRDCKG_RESET |
  234. MRDCKH_RESET |
  235. MRDCKA_SLEEP |
  236. MRDCKB_SLEEP |
  237. MRDCKC_SLEEP |
  238. MRDCKD_SLEEP |
  239. MRDCKE_SLEEP |
  240. MRDCKF_SLEEP |
  241. MRDCKG_SLEEP |
  242. MRDCKH_SLEEP);
  243. dll_cntl = 0xff000000;
  244. spll_func_cntl = pi->clk_regs.rv730.cg_spll_func_cntl;
  245. spll_func_cntl_2 = pi->clk_regs.rv730.cg_spll_func_cntl_2;
  246. spll_func_cntl_3 = pi->clk_regs.rv730.cg_spll_func_cntl_3;
  247. spll_func_cntl |= SPLL_RESET | SPLL_BYPASS_EN;
  248. spll_func_cntl &= ~SPLL_SLEEP;
  249. spll_func_cntl_2 &= ~SCLK_MUX_SEL_MASK;
  250. spll_func_cntl_2 |= SCLK_MUX_SEL(4);
  251. table->ACPIState.levels[0].mclk.mclk730.vMPLL_FUNC_CNTL = cpu_to_be32(mpll_func_cntl);
  252. table->ACPIState.levels[0].mclk.mclk730.vMPLL_FUNC_CNTL2 = cpu_to_be32(mpll_func_cntl_2);
  253. table->ACPIState.levels[0].mclk.mclk730.vMPLL_FUNC_CNTL3 = cpu_to_be32(mpll_func_cntl_3);
  254. table->ACPIState.levels[0].mclk.mclk730.vMCLK_PWRMGT_CNTL = cpu_to_be32(mclk_pwrmgt_cntl);
  255. table->ACPIState.levels[0].mclk.mclk730.vDLL_CNTL = cpu_to_be32(dll_cntl);
  256. table->ACPIState.levels[0].mclk.mclk730.mclk_value = 0;
  257. table->ACPIState.levels[0].sclk.vCG_SPLL_FUNC_CNTL = cpu_to_be32(spll_func_cntl);
  258. table->ACPIState.levels[0].sclk.vCG_SPLL_FUNC_CNTL_2 = cpu_to_be32(spll_func_cntl_2);
  259. table->ACPIState.levels[0].sclk.vCG_SPLL_FUNC_CNTL_3 = cpu_to_be32(spll_func_cntl_3);
  260. table->ACPIState.levels[0].sclk.sclk_value = 0;
  261. rv770_populate_mvdd_value(rdev, 0, &table->ACPIState.levels[0].mvdd);
  262. table->ACPIState.levels[1] = table->ACPIState.levels[0];
  263. table->ACPIState.levels[2] = table->ACPIState.levels[0];
  264. return 0;
  265. }
  266. int rv730_populate_smc_initial_state(struct radeon_device *rdev,
  267. struct radeon_ps *radeon_state,
  268. RV770_SMC_STATETABLE *table)
  269. {
  270. struct rv7xx_ps *initial_state = rv770_get_ps(radeon_state);
  271. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  272. u32 a_t;
  273. table->initialState.levels[0].mclk.mclk730.vMPLL_FUNC_CNTL =
  274. cpu_to_be32(pi->clk_regs.rv730.mpll_func_cntl);
  275. table->initialState.levels[0].mclk.mclk730.vMPLL_FUNC_CNTL2 =
  276. cpu_to_be32(pi->clk_regs.rv730.mpll_func_cntl2);
  277. table->initialState.levels[0].mclk.mclk730.vMPLL_FUNC_CNTL3 =
  278. cpu_to_be32(pi->clk_regs.rv730.mpll_func_cntl3);
  279. table->initialState.levels[0].mclk.mclk730.vMCLK_PWRMGT_CNTL =
  280. cpu_to_be32(pi->clk_regs.rv730.mclk_pwrmgt_cntl);
  281. table->initialState.levels[0].mclk.mclk730.vDLL_CNTL =
  282. cpu_to_be32(pi->clk_regs.rv730.dll_cntl);
  283. table->initialState.levels[0].mclk.mclk730.vMPLL_SS =
  284. cpu_to_be32(pi->clk_regs.rv730.mpll_ss);
  285. table->initialState.levels[0].mclk.mclk730.vMPLL_SS2 =
  286. cpu_to_be32(pi->clk_regs.rv730.mpll_ss2);
  287. table->initialState.levels[0].mclk.mclk730.mclk_value =
  288. cpu_to_be32(initial_state->low.mclk);
  289. table->initialState.levels[0].sclk.vCG_SPLL_FUNC_CNTL =
  290. cpu_to_be32(pi->clk_regs.rv730.cg_spll_func_cntl);
  291. table->initialState.levels[0].sclk.vCG_SPLL_FUNC_CNTL_2 =
  292. cpu_to_be32(pi->clk_regs.rv730.cg_spll_func_cntl_2);
  293. table->initialState.levels[0].sclk.vCG_SPLL_FUNC_CNTL_3 =
  294. cpu_to_be32(pi->clk_regs.rv730.cg_spll_func_cntl_3);
  295. table->initialState.levels[0].sclk.vCG_SPLL_SPREAD_SPECTRUM =
  296. cpu_to_be32(pi->clk_regs.rv730.cg_spll_spread_spectrum);
  297. table->initialState.levels[0].sclk.vCG_SPLL_SPREAD_SPECTRUM_2 =
  298. cpu_to_be32(pi->clk_regs.rv730.cg_spll_spread_spectrum_2);
  299. table->initialState.levels[0].sclk.sclk_value =
  300. cpu_to_be32(initial_state->low.sclk);
  301. table->initialState.levels[0].arbValue = MC_CG_ARB_FREQ_F0;
  302. table->initialState.levels[0].seqValue =
  303. rv770_get_seq_value(rdev, &initial_state->low);
  304. rv770_populate_vddc_value(rdev,
  305. initial_state->low.vddc,
  306. &table->initialState.levels[0].vddc);
  307. rv770_populate_initial_mvdd_value(rdev,
  308. &table->initialState.levels[0].mvdd);
  309. a_t = CG_R(0xffff) | CG_L(0);
  310. table->initialState.levels[0].aT = cpu_to_be32(a_t);
  311. table->initialState.levels[0].bSP = cpu_to_be32(pi->dsp);
  312. if (pi->boot_in_gen2)
  313. table->initialState.levels[0].gen2PCIE = 1;
  314. else
  315. table->initialState.levels[0].gen2PCIE = 0;
  316. if (initial_state->low.flags & ATOM_PPLIB_R600_FLAGS_PCIEGEN2)
  317. table->initialState.levels[0].gen2XSP = 1;
  318. else
  319. table->initialState.levels[0].gen2XSP = 0;
  320. table->initialState.levels[1] = table->initialState.levels[0];
  321. table->initialState.levels[2] = table->initialState.levels[0];
  322. table->initialState.flags |= PPSMC_SWSTATE_FLAG_DC;
  323. return 0;
  324. }
  325. void rv730_program_memory_timing_parameters(struct radeon_device *rdev,
  326. struct radeon_ps *radeon_state)
  327. {
  328. struct rv7xx_ps *state = rv770_get_ps(radeon_state);
  329. u32 arb_refresh_rate = 0;
  330. u32 dram_timing = 0;
  331. u32 dram_timing2 = 0;
  332. u32 old_dram_timing = 0;
  333. u32 old_dram_timing2 = 0;
  334. arb_refresh_rate = RREG32(MC_ARB_RFSH_RATE) &
  335. ~(POWERMODE1_MASK | POWERMODE2_MASK | POWERMODE3_MASK);
  336. arb_refresh_rate |=
  337. (POWERMODE1(rv770_calculate_memory_refresh_rate(rdev, state->low.sclk)) |
  338. POWERMODE2(rv770_calculate_memory_refresh_rate(rdev, state->medium.sclk)) |
  339. POWERMODE3(rv770_calculate_memory_refresh_rate(rdev, state->high.sclk)));
  340. WREG32(MC_ARB_RFSH_RATE, arb_refresh_rate);
  341. /* save the boot dram timings */
  342. old_dram_timing = RREG32(MC_ARB_DRAM_TIMING);
  343. old_dram_timing2 = RREG32(MC_ARB_DRAM_TIMING2);
  344. radeon_atom_set_engine_dram_timings(rdev,
  345. state->high.sclk,
  346. state->high.mclk);
  347. dram_timing = RREG32(MC_ARB_DRAM_TIMING);
  348. dram_timing2 = RREG32(MC_ARB_DRAM_TIMING2);
  349. WREG32(MC_ARB_DRAM_TIMING_3, dram_timing);
  350. WREG32(MC_ARB_DRAM_TIMING2_3, dram_timing2);
  351. radeon_atom_set_engine_dram_timings(rdev,
  352. state->medium.sclk,
  353. state->medium.mclk);
  354. dram_timing = RREG32(MC_ARB_DRAM_TIMING);
  355. dram_timing2 = RREG32(MC_ARB_DRAM_TIMING2);
  356. WREG32(MC_ARB_DRAM_TIMING_2, dram_timing);
  357. WREG32(MC_ARB_DRAM_TIMING2_2, dram_timing2);
  358. radeon_atom_set_engine_dram_timings(rdev,
  359. state->low.sclk,
  360. state->low.mclk);
  361. dram_timing = RREG32(MC_ARB_DRAM_TIMING);
  362. dram_timing2 = RREG32(MC_ARB_DRAM_TIMING2);
  363. WREG32(MC_ARB_DRAM_TIMING_1, dram_timing);
  364. WREG32(MC_ARB_DRAM_TIMING2_1, dram_timing2);
  365. /* restore the boot dram timings */
  366. WREG32(MC_ARB_DRAM_TIMING, old_dram_timing);
  367. WREG32(MC_ARB_DRAM_TIMING2, old_dram_timing2);
  368. }
  369. void rv730_start_dpm(struct radeon_device *rdev)
  370. {
  371. WREG32_P(SCLK_PWRMGT_CNTL, 0, ~SCLK_PWRMGT_OFF);
  372. WREG32_P(TCI_MCLK_PWRMGT_CNTL, 0, ~MPLL_PWRMGT_OFF);
  373. WREG32_P(GENERAL_PWRMGT, GLOBAL_PWRMGT_EN, ~GLOBAL_PWRMGT_EN);
  374. }
  375. void rv730_stop_dpm(struct radeon_device *rdev)
  376. {
  377. PPSMC_Result result;
  378. result = rv770_send_msg_to_smc(rdev, PPSMC_MSG_TwoLevelsDisabled);
  379. if (result != PPSMC_Result_OK)
  380. DRM_DEBUG("Could not force DPM to low\n");
  381. WREG32_P(GENERAL_PWRMGT, 0, ~GLOBAL_PWRMGT_EN);
  382. WREG32_P(SCLK_PWRMGT_CNTL, SCLK_PWRMGT_OFF, ~SCLK_PWRMGT_OFF);
  383. WREG32_P(TCI_MCLK_PWRMGT_CNTL, MPLL_PWRMGT_OFF, ~MPLL_PWRMGT_OFF);
  384. }
  385. void rv730_program_dcodt(struct radeon_device *rdev, bool use_dcodt)
  386. {
  387. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  388. u32 i = use_dcodt ? 0 : 1;
  389. u32 mc4_io_pad_cntl;
  390. mc4_io_pad_cntl = RREG32(MC4_IO_DQ_PAD_CNTL_D0_I0);
  391. mc4_io_pad_cntl &= 0xFFFFFF00;
  392. mc4_io_pad_cntl |= pi->odt_value_0[i];
  393. WREG32(MC4_IO_DQ_PAD_CNTL_D0_I0, mc4_io_pad_cntl);
  394. WREG32(MC4_IO_DQ_PAD_CNTL_D0_I1, mc4_io_pad_cntl);
  395. mc4_io_pad_cntl = RREG32(MC4_IO_QS_PAD_CNTL_D0_I0);
  396. mc4_io_pad_cntl &= 0xFFFFFF00;
  397. mc4_io_pad_cntl |= pi->odt_value_1[i];
  398. WREG32(MC4_IO_QS_PAD_CNTL_D0_I0, mc4_io_pad_cntl);
  399. WREG32(MC4_IO_QS_PAD_CNTL_D0_I1, mc4_io_pad_cntl);
  400. }
  401. void rv730_get_odt_values(struct radeon_device *rdev)
  402. {
  403. struct rv7xx_power_info *pi = rv770_get_pi(rdev);
  404. u32 mc4_io_pad_cntl;
  405. pi->odt_value_0[0] = (u8)0;
  406. pi->odt_value_1[0] = (u8)0x80;
  407. mc4_io_pad_cntl = RREG32(MC4_IO_DQ_PAD_CNTL_D0_I0);
  408. pi->odt_value_0[1] = (u8)(mc4_io_pad_cntl & 0xff);
  409. mc4_io_pad_cntl = RREG32(MC4_IO_QS_PAD_CNTL_D0_I0);
  410. pi->odt_value_1[1] = (u8)(mc4_io_pad_cntl & 0xff);
  411. }