18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright 2011 Advanced Micro Devices, Inc. 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 58c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 68c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation 78c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 88c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 98c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 108c2ecf20Sopenharmony_ci * 118c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice shall be included in 128c2ecf20Sopenharmony_ci * all copies or substantial portions of the Software. 138c2ecf20Sopenharmony_ci * 148c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 158c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 168c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 178c2ecf20Sopenharmony_ci * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 188c2ecf20Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 198c2ecf20Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 208c2ecf20Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE. 218c2ecf20Sopenharmony_ci * 228c2ecf20Sopenharmony_ci * Authors: Alex Deucher 238c2ecf20Sopenharmony_ci */ 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci#include "radeon.h" 268c2ecf20Sopenharmony_ci#include "rv740d.h" 278c2ecf20Sopenharmony_ci#include "r600_dpm.h" 288c2ecf20Sopenharmony_ci#include "rv770_dpm.h" 298c2ecf20Sopenharmony_ci#include "atom.h" 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_cistruct rv7xx_power_info *rv770_get_pi(struct radeon_device *rdev); 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ciu32 rv740_get_decoded_reference_divider(u32 encoded_ref) 348c2ecf20Sopenharmony_ci{ 358c2ecf20Sopenharmony_ci u32 ref = 0; 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci switch (encoded_ref) { 388c2ecf20Sopenharmony_ci case 0: 398c2ecf20Sopenharmony_ci ref = 1; 408c2ecf20Sopenharmony_ci break; 418c2ecf20Sopenharmony_ci case 16: 428c2ecf20Sopenharmony_ci ref = 2; 438c2ecf20Sopenharmony_ci break; 448c2ecf20Sopenharmony_ci case 17: 458c2ecf20Sopenharmony_ci ref = 3; 468c2ecf20Sopenharmony_ci break; 478c2ecf20Sopenharmony_ci case 18: 488c2ecf20Sopenharmony_ci ref = 2; 498c2ecf20Sopenharmony_ci break; 508c2ecf20Sopenharmony_ci case 19: 518c2ecf20Sopenharmony_ci ref = 3; 528c2ecf20Sopenharmony_ci break; 538c2ecf20Sopenharmony_ci case 20: 548c2ecf20Sopenharmony_ci ref = 4; 558c2ecf20Sopenharmony_ci break; 568c2ecf20Sopenharmony_ci case 21: 578c2ecf20Sopenharmony_ci ref = 5; 588c2ecf20Sopenharmony_ci break; 598c2ecf20Sopenharmony_ci default: 608c2ecf20Sopenharmony_ci DRM_ERROR("Invalid encoded Reference Divider\n"); 618c2ecf20Sopenharmony_ci ref = 0; 628c2ecf20Sopenharmony_ci break; 638c2ecf20Sopenharmony_ci } 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci return ref; 668c2ecf20Sopenharmony_ci} 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_cistruct dll_speed_setting { 698c2ecf20Sopenharmony_ci u16 min; 708c2ecf20Sopenharmony_ci u16 max; 718c2ecf20Sopenharmony_ci u32 dll_speed; 728c2ecf20Sopenharmony_ci}; 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_cistatic struct dll_speed_setting dll_speed_table[16] = 758c2ecf20Sopenharmony_ci{ 768c2ecf20Sopenharmony_ci { 270, 320, 0x0f }, 778c2ecf20Sopenharmony_ci { 240, 270, 0x0e }, 788c2ecf20Sopenharmony_ci { 200, 240, 0x0d }, 798c2ecf20Sopenharmony_ci { 180, 200, 0x0c }, 808c2ecf20Sopenharmony_ci { 160, 180, 0x0b }, 818c2ecf20Sopenharmony_ci { 140, 160, 0x0a }, 828c2ecf20Sopenharmony_ci { 120, 140, 0x09 }, 838c2ecf20Sopenharmony_ci { 110, 120, 0x08 }, 848c2ecf20Sopenharmony_ci { 95, 110, 0x07 }, 858c2ecf20Sopenharmony_ci { 85, 95, 0x06 }, 868c2ecf20Sopenharmony_ci { 78, 85, 0x05 }, 878c2ecf20Sopenharmony_ci { 70, 78, 0x04 }, 888c2ecf20Sopenharmony_ci { 65, 70, 0x03 }, 898c2ecf20Sopenharmony_ci { 60, 65, 0x02 }, 908c2ecf20Sopenharmony_ci { 42, 60, 0x01 }, 918c2ecf20Sopenharmony_ci { 00, 42, 0x00 } 928c2ecf20Sopenharmony_ci}; 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ciu32 rv740_get_dll_speed(bool is_gddr5, u32 memory_clock) 958c2ecf20Sopenharmony_ci{ 968c2ecf20Sopenharmony_ci int i; 978c2ecf20Sopenharmony_ci u32 factor; 988c2ecf20Sopenharmony_ci u16 data_rate; 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci if (is_gddr5) 1018c2ecf20Sopenharmony_ci factor = 4; 1028c2ecf20Sopenharmony_ci else 1038c2ecf20Sopenharmony_ci factor = 2; 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci data_rate = (u16)(memory_clock * factor / 1000); 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci if (data_rate < dll_speed_table[0].max) { 1088c2ecf20Sopenharmony_ci for (i = 0; i < 16; i++) { 1098c2ecf20Sopenharmony_ci if (data_rate > dll_speed_table[i].min && 1108c2ecf20Sopenharmony_ci data_rate <= dll_speed_table[i].max) 1118c2ecf20Sopenharmony_ci return dll_speed_table[i].dll_speed; 1128c2ecf20Sopenharmony_ci } 1138c2ecf20Sopenharmony_ci } 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci DRM_DEBUG_KMS("Target MCLK greater than largest MCLK in DLL speed table\n"); 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci return 0x0f; 1188c2ecf20Sopenharmony_ci} 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_ciint rv740_populate_sclk_value(struct radeon_device *rdev, u32 engine_clock, 1218c2ecf20Sopenharmony_ci RV770_SMC_SCLK_VALUE *sclk) 1228c2ecf20Sopenharmony_ci{ 1238c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 1248c2ecf20Sopenharmony_ci struct atom_clock_dividers dividers; 1258c2ecf20Sopenharmony_ci u32 spll_func_cntl = pi->clk_regs.rv770.cg_spll_func_cntl; 1268c2ecf20Sopenharmony_ci u32 spll_func_cntl_2 = pi->clk_regs.rv770.cg_spll_func_cntl_2; 1278c2ecf20Sopenharmony_ci u32 spll_func_cntl_3 = pi->clk_regs.rv770.cg_spll_func_cntl_3; 1288c2ecf20Sopenharmony_ci u32 cg_spll_spread_spectrum = pi->clk_regs.rv770.cg_spll_spread_spectrum; 1298c2ecf20Sopenharmony_ci u32 cg_spll_spread_spectrum_2 = pi->clk_regs.rv770.cg_spll_spread_spectrum_2; 1308c2ecf20Sopenharmony_ci u64 tmp; 1318c2ecf20Sopenharmony_ci u32 reference_clock = rdev->clock.spll.reference_freq; 1328c2ecf20Sopenharmony_ci u32 reference_divider; 1338c2ecf20Sopenharmony_ci u32 fbdiv; 1348c2ecf20Sopenharmony_ci int ret; 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM, 1378c2ecf20Sopenharmony_ci engine_clock, false, ÷rs); 1388c2ecf20Sopenharmony_ci if (ret) 1398c2ecf20Sopenharmony_ci return ret; 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_ci reference_divider = 1 + dividers.ref_div; 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_ci tmp = (u64) engine_clock * reference_divider * dividers.post_div * 16384; 1448c2ecf20Sopenharmony_ci do_div(tmp, reference_clock); 1458c2ecf20Sopenharmony_ci fbdiv = (u32) tmp; 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci spll_func_cntl &= ~(SPLL_PDIV_A_MASK | SPLL_REF_DIV_MASK); 1488c2ecf20Sopenharmony_ci spll_func_cntl |= SPLL_REF_DIV(dividers.ref_div); 1498c2ecf20Sopenharmony_ci spll_func_cntl |= SPLL_PDIV_A(dividers.post_div); 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ci spll_func_cntl_2 &= ~SCLK_MUX_SEL_MASK; 1528c2ecf20Sopenharmony_ci spll_func_cntl_2 |= SCLK_MUX_SEL(2); 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_ci spll_func_cntl_3 &= ~SPLL_FB_DIV_MASK; 1558c2ecf20Sopenharmony_ci spll_func_cntl_3 |= SPLL_FB_DIV(fbdiv); 1568c2ecf20Sopenharmony_ci spll_func_cntl_3 |= SPLL_DITHEN; 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_ci if (pi->sclk_ss) { 1598c2ecf20Sopenharmony_ci struct radeon_atom_ss ss; 1608c2ecf20Sopenharmony_ci u32 vco_freq = engine_clock * dividers.post_div; 1618c2ecf20Sopenharmony_ci 1628c2ecf20Sopenharmony_ci if (radeon_atombios_get_asic_ss_info(rdev, &ss, 1638c2ecf20Sopenharmony_ci ASIC_INTERNAL_ENGINE_SS, vco_freq)) { 1648c2ecf20Sopenharmony_ci u32 clk_s = reference_clock * 5 / (reference_divider * ss.rate); 1658c2ecf20Sopenharmony_ci u32 clk_v = 4 * ss.percentage * fbdiv / (clk_s * 10000); 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_ci cg_spll_spread_spectrum &= ~CLK_S_MASK; 1688c2ecf20Sopenharmony_ci cg_spll_spread_spectrum |= CLK_S(clk_s); 1698c2ecf20Sopenharmony_ci cg_spll_spread_spectrum |= SSEN; 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_ci cg_spll_spread_spectrum_2 &= ~CLK_V_MASK; 1728c2ecf20Sopenharmony_ci cg_spll_spread_spectrum_2 |= CLK_V(clk_v); 1738c2ecf20Sopenharmony_ci } 1748c2ecf20Sopenharmony_ci } 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci sclk->sclk_value = cpu_to_be32(engine_clock); 1778c2ecf20Sopenharmony_ci sclk->vCG_SPLL_FUNC_CNTL = cpu_to_be32(spll_func_cntl); 1788c2ecf20Sopenharmony_ci sclk->vCG_SPLL_FUNC_CNTL_2 = cpu_to_be32(spll_func_cntl_2); 1798c2ecf20Sopenharmony_ci sclk->vCG_SPLL_FUNC_CNTL_3 = cpu_to_be32(spll_func_cntl_3); 1808c2ecf20Sopenharmony_ci sclk->vCG_SPLL_SPREAD_SPECTRUM = cpu_to_be32(cg_spll_spread_spectrum); 1818c2ecf20Sopenharmony_ci sclk->vCG_SPLL_SPREAD_SPECTRUM_2 = cpu_to_be32(cg_spll_spread_spectrum_2); 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_ci return 0; 1848c2ecf20Sopenharmony_ci} 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_ciint rv740_populate_mclk_value(struct radeon_device *rdev, 1878c2ecf20Sopenharmony_ci u32 engine_clock, u32 memory_clock, 1888c2ecf20Sopenharmony_ci RV7XX_SMC_MCLK_VALUE *mclk) 1898c2ecf20Sopenharmony_ci{ 1908c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 1918c2ecf20Sopenharmony_ci u32 mpll_ad_func_cntl = pi->clk_regs.rv770.mpll_ad_func_cntl; 1928c2ecf20Sopenharmony_ci u32 mpll_ad_func_cntl_2 = pi->clk_regs.rv770.mpll_ad_func_cntl_2; 1938c2ecf20Sopenharmony_ci u32 mpll_dq_func_cntl = pi->clk_regs.rv770.mpll_dq_func_cntl; 1948c2ecf20Sopenharmony_ci u32 mpll_dq_func_cntl_2 = pi->clk_regs.rv770.mpll_dq_func_cntl_2; 1958c2ecf20Sopenharmony_ci u32 mclk_pwrmgt_cntl = pi->clk_regs.rv770.mclk_pwrmgt_cntl; 1968c2ecf20Sopenharmony_ci u32 dll_cntl = pi->clk_regs.rv770.dll_cntl; 1978c2ecf20Sopenharmony_ci u32 mpll_ss1 = pi->clk_regs.rv770.mpll_ss1; 1988c2ecf20Sopenharmony_ci u32 mpll_ss2 = pi->clk_regs.rv770.mpll_ss2; 1998c2ecf20Sopenharmony_ci struct atom_clock_dividers dividers; 2008c2ecf20Sopenharmony_ci u32 ibias; 2018c2ecf20Sopenharmony_ci u32 dll_speed; 2028c2ecf20Sopenharmony_ci int ret; 2038c2ecf20Sopenharmony_ci 2048c2ecf20Sopenharmony_ci ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_MEMORY_PLL_PARAM, 2058c2ecf20Sopenharmony_ci memory_clock, false, ÷rs); 2068c2ecf20Sopenharmony_ci if (ret) 2078c2ecf20Sopenharmony_ci return ret; 2088c2ecf20Sopenharmony_ci 2098c2ecf20Sopenharmony_ci ibias = rv770_map_clkf_to_ibias(rdev, dividers.whole_fb_div); 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_ci mpll_ad_func_cntl &= ~(CLKR_MASK | 2128c2ecf20Sopenharmony_ci YCLK_POST_DIV_MASK | 2138c2ecf20Sopenharmony_ci CLKF_MASK | 2148c2ecf20Sopenharmony_ci CLKFRAC_MASK | 2158c2ecf20Sopenharmony_ci IBIAS_MASK); 2168c2ecf20Sopenharmony_ci mpll_ad_func_cntl |= CLKR(dividers.ref_div); 2178c2ecf20Sopenharmony_ci mpll_ad_func_cntl |= YCLK_POST_DIV(dividers.post_div); 2188c2ecf20Sopenharmony_ci mpll_ad_func_cntl |= CLKF(dividers.whole_fb_div); 2198c2ecf20Sopenharmony_ci mpll_ad_func_cntl |= CLKFRAC(dividers.frac_fb_div); 2208c2ecf20Sopenharmony_ci mpll_ad_func_cntl |= IBIAS(ibias); 2218c2ecf20Sopenharmony_ci 2228c2ecf20Sopenharmony_ci if (dividers.vco_mode) 2238c2ecf20Sopenharmony_ci mpll_ad_func_cntl_2 |= VCO_MODE; 2248c2ecf20Sopenharmony_ci else 2258c2ecf20Sopenharmony_ci mpll_ad_func_cntl_2 &= ~VCO_MODE; 2268c2ecf20Sopenharmony_ci 2278c2ecf20Sopenharmony_ci if (pi->mem_gddr5) { 2288c2ecf20Sopenharmony_ci mpll_dq_func_cntl &= ~(CLKR_MASK | 2298c2ecf20Sopenharmony_ci YCLK_POST_DIV_MASK | 2308c2ecf20Sopenharmony_ci CLKF_MASK | 2318c2ecf20Sopenharmony_ci CLKFRAC_MASK | 2328c2ecf20Sopenharmony_ci IBIAS_MASK); 2338c2ecf20Sopenharmony_ci mpll_dq_func_cntl |= CLKR(dividers.ref_div); 2348c2ecf20Sopenharmony_ci mpll_dq_func_cntl |= YCLK_POST_DIV(dividers.post_div); 2358c2ecf20Sopenharmony_ci mpll_dq_func_cntl |= CLKF(dividers.whole_fb_div); 2368c2ecf20Sopenharmony_ci mpll_dq_func_cntl |= CLKFRAC(dividers.frac_fb_div); 2378c2ecf20Sopenharmony_ci mpll_dq_func_cntl |= IBIAS(ibias); 2388c2ecf20Sopenharmony_ci 2398c2ecf20Sopenharmony_ci if (dividers.vco_mode) 2408c2ecf20Sopenharmony_ci mpll_dq_func_cntl_2 |= VCO_MODE; 2418c2ecf20Sopenharmony_ci else 2428c2ecf20Sopenharmony_ci mpll_dq_func_cntl_2 &= ~VCO_MODE; 2438c2ecf20Sopenharmony_ci } 2448c2ecf20Sopenharmony_ci 2458c2ecf20Sopenharmony_ci if (pi->mclk_ss) { 2468c2ecf20Sopenharmony_ci struct radeon_atom_ss ss; 2478c2ecf20Sopenharmony_ci u32 vco_freq = memory_clock * dividers.post_div; 2488c2ecf20Sopenharmony_ci 2498c2ecf20Sopenharmony_ci if (radeon_atombios_get_asic_ss_info(rdev, &ss, 2508c2ecf20Sopenharmony_ci ASIC_INTERNAL_MEMORY_SS, vco_freq)) { 2518c2ecf20Sopenharmony_ci u32 reference_clock = rdev->clock.mpll.reference_freq; 2528c2ecf20Sopenharmony_ci u32 decoded_ref = rv740_get_decoded_reference_divider(dividers.ref_div); 2538c2ecf20Sopenharmony_ci u32 clk_s, clk_v; 2548c2ecf20Sopenharmony_ci 2558c2ecf20Sopenharmony_ci if (!decoded_ref) 2568c2ecf20Sopenharmony_ci return -EINVAL; 2578c2ecf20Sopenharmony_ci clk_s = reference_clock * 5 / (decoded_ref * ss.rate); 2588c2ecf20Sopenharmony_ci clk_v = 0x40000 * ss.percentage * 2598c2ecf20Sopenharmony_ci (dividers.whole_fb_div + (dividers.frac_fb_div / 8)) / (clk_s * 10000); 2608c2ecf20Sopenharmony_ci 2618c2ecf20Sopenharmony_ci mpll_ss1 &= ~CLKV_MASK; 2628c2ecf20Sopenharmony_ci mpll_ss1 |= CLKV(clk_v); 2638c2ecf20Sopenharmony_ci 2648c2ecf20Sopenharmony_ci mpll_ss2 &= ~CLKS_MASK; 2658c2ecf20Sopenharmony_ci mpll_ss2 |= CLKS(clk_s); 2668c2ecf20Sopenharmony_ci } 2678c2ecf20Sopenharmony_ci } 2688c2ecf20Sopenharmony_ci 2698c2ecf20Sopenharmony_ci dll_speed = rv740_get_dll_speed(pi->mem_gddr5, 2708c2ecf20Sopenharmony_ci memory_clock); 2718c2ecf20Sopenharmony_ci 2728c2ecf20Sopenharmony_ci mclk_pwrmgt_cntl &= ~DLL_SPEED_MASK; 2738c2ecf20Sopenharmony_ci mclk_pwrmgt_cntl |= DLL_SPEED(dll_speed); 2748c2ecf20Sopenharmony_ci 2758c2ecf20Sopenharmony_ci mclk->mclk770.mclk_value = cpu_to_be32(memory_clock); 2768c2ecf20Sopenharmony_ci mclk->mclk770.vMPLL_AD_FUNC_CNTL = cpu_to_be32(mpll_ad_func_cntl); 2778c2ecf20Sopenharmony_ci mclk->mclk770.vMPLL_AD_FUNC_CNTL_2 = cpu_to_be32(mpll_ad_func_cntl_2); 2788c2ecf20Sopenharmony_ci mclk->mclk770.vMPLL_DQ_FUNC_CNTL = cpu_to_be32(mpll_dq_func_cntl); 2798c2ecf20Sopenharmony_ci mclk->mclk770.vMPLL_DQ_FUNC_CNTL_2 = cpu_to_be32(mpll_dq_func_cntl_2); 2808c2ecf20Sopenharmony_ci mclk->mclk770.vMCLK_PWRMGT_CNTL = cpu_to_be32(mclk_pwrmgt_cntl); 2818c2ecf20Sopenharmony_ci mclk->mclk770.vDLL_CNTL = cpu_to_be32(dll_cntl); 2828c2ecf20Sopenharmony_ci mclk->mclk770.vMPLL_SS = cpu_to_be32(mpll_ss1); 2838c2ecf20Sopenharmony_ci mclk->mclk770.vMPLL_SS2 = cpu_to_be32(mpll_ss2); 2848c2ecf20Sopenharmony_ci 2858c2ecf20Sopenharmony_ci return 0; 2868c2ecf20Sopenharmony_ci} 2878c2ecf20Sopenharmony_ci 2888c2ecf20Sopenharmony_civoid rv740_read_clock_registers(struct radeon_device *rdev) 2898c2ecf20Sopenharmony_ci{ 2908c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 2918c2ecf20Sopenharmony_ci 2928c2ecf20Sopenharmony_ci pi->clk_regs.rv770.cg_spll_func_cntl = 2938c2ecf20Sopenharmony_ci RREG32(CG_SPLL_FUNC_CNTL); 2948c2ecf20Sopenharmony_ci pi->clk_regs.rv770.cg_spll_func_cntl_2 = 2958c2ecf20Sopenharmony_ci RREG32(CG_SPLL_FUNC_CNTL_2); 2968c2ecf20Sopenharmony_ci pi->clk_regs.rv770.cg_spll_func_cntl_3 = 2978c2ecf20Sopenharmony_ci RREG32(CG_SPLL_FUNC_CNTL_3); 2988c2ecf20Sopenharmony_ci pi->clk_regs.rv770.cg_spll_spread_spectrum = 2998c2ecf20Sopenharmony_ci RREG32(CG_SPLL_SPREAD_SPECTRUM); 3008c2ecf20Sopenharmony_ci pi->clk_regs.rv770.cg_spll_spread_spectrum_2 = 3018c2ecf20Sopenharmony_ci RREG32(CG_SPLL_SPREAD_SPECTRUM_2); 3028c2ecf20Sopenharmony_ci 3038c2ecf20Sopenharmony_ci pi->clk_regs.rv770.mpll_ad_func_cntl = 3048c2ecf20Sopenharmony_ci RREG32(MPLL_AD_FUNC_CNTL); 3058c2ecf20Sopenharmony_ci pi->clk_regs.rv770.mpll_ad_func_cntl_2 = 3068c2ecf20Sopenharmony_ci RREG32(MPLL_AD_FUNC_CNTL_2); 3078c2ecf20Sopenharmony_ci pi->clk_regs.rv770.mpll_dq_func_cntl = 3088c2ecf20Sopenharmony_ci RREG32(MPLL_DQ_FUNC_CNTL); 3098c2ecf20Sopenharmony_ci pi->clk_regs.rv770.mpll_dq_func_cntl_2 = 3108c2ecf20Sopenharmony_ci RREG32(MPLL_DQ_FUNC_CNTL_2); 3118c2ecf20Sopenharmony_ci pi->clk_regs.rv770.mclk_pwrmgt_cntl = 3128c2ecf20Sopenharmony_ci RREG32(MCLK_PWRMGT_CNTL); 3138c2ecf20Sopenharmony_ci pi->clk_regs.rv770.dll_cntl = RREG32(DLL_CNTL); 3148c2ecf20Sopenharmony_ci pi->clk_regs.rv770.mpll_ss1 = RREG32(MPLL_SS1); 3158c2ecf20Sopenharmony_ci pi->clk_regs.rv770.mpll_ss2 = RREG32(MPLL_SS2); 3168c2ecf20Sopenharmony_ci} 3178c2ecf20Sopenharmony_ci 3188c2ecf20Sopenharmony_ciint rv740_populate_smc_acpi_state(struct radeon_device *rdev, 3198c2ecf20Sopenharmony_ci RV770_SMC_STATETABLE *table) 3208c2ecf20Sopenharmony_ci{ 3218c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 3228c2ecf20Sopenharmony_ci u32 mpll_ad_func_cntl = pi->clk_regs.rv770.mpll_ad_func_cntl; 3238c2ecf20Sopenharmony_ci u32 mpll_ad_func_cntl_2 = pi->clk_regs.rv770.mpll_ad_func_cntl_2; 3248c2ecf20Sopenharmony_ci u32 mpll_dq_func_cntl = pi->clk_regs.rv770.mpll_dq_func_cntl; 3258c2ecf20Sopenharmony_ci u32 mpll_dq_func_cntl_2 = pi->clk_regs.rv770.mpll_dq_func_cntl_2; 3268c2ecf20Sopenharmony_ci u32 spll_func_cntl = pi->clk_regs.rv770.cg_spll_func_cntl; 3278c2ecf20Sopenharmony_ci u32 spll_func_cntl_2 = pi->clk_regs.rv770.cg_spll_func_cntl_2; 3288c2ecf20Sopenharmony_ci u32 spll_func_cntl_3 = pi->clk_regs.rv770.cg_spll_func_cntl_3; 3298c2ecf20Sopenharmony_ci u32 mclk_pwrmgt_cntl = pi->clk_regs.rv770.mclk_pwrmgt_cntl; 3308c2ecf20Sopenharmony_ci u32 dll_cntl = pi->clk_regs.rv770.dll_cntl; 3318c2ecf20Sopenharmony_ci 3328c2ecf20Sopenharmony_ci table->ACPIState = table->initialState; 3338c2ecf20Sopenharmony_ci 3348c2ecf20Sopenharmony_ci table->ACPIState.flags &= ~PPSMC_SWSTATE_FLAG_DC; 3358c2ecf20Sopenharmony_ci 3368c2ecf20Sopenharmony_ci if (pi->acpi_vddc) { 3378c2ecf20Sopenharmony_ci rv770_populate_vddc_value(rdev, pi->acpi_vddc, 3388c2ecf20Sopenharmony_ci &table->ACPIState.levels[0].vddc); 3398c2ecf20Sopenharmony_ci table->ACPIState.levels[0].gen2PCIE = 3408c2ecf20Sopenharmony_ci pi->pcie_gen2 ? 3418c2ecf20Sopenharmony_ci pi->acpi_pcie_gen2 : 0; 3428c2ecf20Sopenharmony_ci table->ACPIState.levels[0].gen2XSP = 3438c2ecf20Sopenharmony_ci pi->acpi_pcie_gen2; 3448c2ecf20Sopenharmony_ci } else { 3458c2ecf20Sopenharmony_ci rv770_populate_vddc_value(rdev, pi->min_vddc_in_table, 3468c2ecf20Sopenharmony_ci &table->ACPIState.levels[0].vddc); 3478c2ecf20Sopenharmony_ci table->ACPIState.levels[0].gen2PCIE = 0; 3488c2ecf20Sopenharmony_ci } 3498c2ecf20Sopenharmony_ci 3508c2ecf20Sopenharmony_ci mpll_ad_func_cntl_2 |= BIAS_GEN_PDNB | RESET_EN; 3518c2ecf20Sopenharmony_ci 3528c2ecf20Sopenharmony_ci mpll_dq_func_cntl_2 |= BYPASS | BIAS_GEN_PDNB | RESET_EN; 3538c2ecf20Sopenharmony_ci 3548c2ecf20Sopenharmony_ci mclk_pwrmgt_cntl |= (MRDCKA0_RESET | 3558c2ecf20Sopenharmony_ci MRDCKA1_RESET | 3568c2ecf20Sopenharmony_ci MRDCKB0_RESET | 3578c2ecf20Sopenharmony_ci MRDCKB1_RESET | 3588c2ecf20Sopenharmony_ci MRDCKC0_RESET | 3598c2ecf20Sopenharmony_ci MRDCKC1_RESET | 3608c2ecf20Sopenharmony_ci MRDCKD0_RESET | 3618c2ecf20Sopenharmony_ci MRDCKD1_RESET); 3628c2ecf20Sopenharmony_ci 3638c2ecf20Sopenharmony_ci dll_cntl |= (MRDCKA0_BYPASS | 3648c2ecf20Sopenharmony_ci MRDCKA1_BYPASS | 3658c2ecf20Sopenharmony_ci MRDCKB0_BYPASS | 3668c2ecf20Sopenharmony_ci MRDCKB1_BYPASS | 3678c2ecf20Sopenharmony_ci MRDCKC0_BYPASS | 3688c2ecf20Sopenharmony_ci MRDCKC1_BYPASS | 3698c2ecf20Sopenharmony_ci MRDCKD0_BYPASS | 3708c2ecf20Sopenharmony_ci MRDCKD1_BYPASS); 3718c2ecf20Sopenharmony_ci 3728c2ecf20Sopenharmony_ci spll_func_cntl |= SPLL_RESET | SPLL_SLEEP | SPLL_BYPASS_EN; 3738c2ecf20Sopenharmony_ci 3748c2ecf20Sopenharmony_ci spll_func_cntl_2 &= ~SCLK_MUX_SEL_MASK; 3758c2ecf20Sopenharmony_ci spll_func_cntl_2 |= SCLK_MUX_SEL(4); 3768c2ecf20Sopenharmony_ci 3778c2ecf20Sopenharmony_ci table->ACPIState.levels[0].mclk.mclk770.vMPLL_AD_FUNC_CNTL = cpu_to_be32(mpll_ad_func_cntl); 3788c2ecf20Sopenharmony_ci table->ACPIState.levels[0].mclk.mclk770.vMPLL_AD_FUNC_CNTL_2 = cpu_to_be32(mpll_ad_func_cntl_2); 3798c2ecf20Sopenharmony_ci table->ACPIState.levels[0].mclk.mclk770.vMPLL_DQ_FUNC_CNTL = cpu_to_be32(mpll_dq_func_cntl); 3808c2ecf20Sopenharmony_ci table->ACPIState.levels[0].mclk.mclk770.vMPLL_DQ_FUNC_CNTL_2 = cpu_to_be32(mpll_dq_func_cntl_2); 3818c2ecf20Sopenharmony_ci table->ACPIState.levels[0].mclk.mclk770.vMCLK_PWRMGT_CNTL = cpu_to_be32(mclk_pwrmgt_cntl); 3828c2ecf20Sopenharmony_ci table->ACPIState.levels[0].mclk.mclk770.vDLL_CNTL = cpu_to_be32(dll_cntl); 3838c2ecf20Sopenharmony_ci 3848c2ecf20Sopenharmony_ci table->ACPIState.levels[0].mclk.mclk770.mclk_value = 0; 3858c2ecf20Sopenharmony_ci 3868c2ecf20Sopenharmony_ci table->ACPIState.levels[0].sclk.vCG_SPLL_FUNC_CNTL = cpu_to_be32(spll_func_cntl); 3878c2ecf20Sopenharmony_ci table->ACPIState.levels[0].sclk.vCG_SPLL_FUNC_CNTL_2 = cpu_to_be32(spll_func_cntl_2); 3888c2ecf20Sopenharmony_ci table->ACPIState.levels[0].sclk.vCG_SPLL_FUNC_CNTL_3 = cpu_to_be32(spll_func_cntl_3); 3898c2ecf20Sopenharmony_ci 3908c2ecf20Sopenharmony_ci table->ACPIState.levels[0].sclk.sclk_value = 0; 3918c2ecf20Sopenharmony_ci 3928c2ecf20Sopenharmony_ci table->ACPIState.levels[1] = table->ACPIState.levels[0]; 3938c2ecf20Sopenharmony_ci table->ACPIState.levels[2] = table->ACPIState.levels[0]; 3948c2ecf20Sopenharmony_ci 3958c2ecf20Sopenharmony_ci rv770_populate_mvdd_value(rdev, 0, &table->ACPIState.levels[0].mvdd); 3968c2ecf20Sopenharmony_ci 3978c2ecf20Sopenharmony_ci return 0; 3988c2ecf20Sopenharmony_ci} 3998c2ecf20Sopenharmony_ci 4008c2ecf20Sopenharmony_civoid rv740_enable_mclk_spread_spectrum(struct radeon_device *rdev, 4018c2ecf20Sopenharmony_ci bool enable) 4028c2ecf20Sopenharmony_ci{ 4038c2ecf20Sopenharmony_ci if (enable) 4048c2ecf20Sopenharmony_ci WREG32_P(MPLL_CNTL_MODE, SS_SSEN, ~SS_SSEN); 4058c2ecf20Sopenharmony_ci else 4068c2ecf20Sopenharmony_ci WREG32_P(MPLL_CNTL_MODE, 0, ~SS_SSEN); 4078c2ecf20Sopenharmony_ci} 4088c2ecf20Sopenharmony_ci 4098c2ecf20Sopenharmony_ciu8 rv740_get_mclk_frequency_ratio(u32 memory_clock) 4108c2ecf20Sopenharmony_ci{ 4118c2ecf20Sopenharmony_ci u8 mc_para_index; 4128c2ecf20Sopenharmony_ci 4138c2ecf20Sopenharmony_ci if ((memory_clock < 10000) || (memory_clock > 47500)) 4148c2ecf20Sopenharmony_ci mc_para_index = 0x00; 4158c2ecf20Sopenharmony_ci else 4168c2ecf20Sopenharmony_ci mc_para_index = (u8)((memory_clock - 10000) / 2500); 4178c2ecf20Sopenharmony_ci 4188c2ecf20Sopenharmony_ci return mc_para_index; 4198c2ecf20Sopenharmony_ci} 420