rv730_dpm.c 16 KB

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