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 "radeon_asic.h" 278c2ecf20Sopenharmony_ci#include "rv770d.h" 288c2ecf20Sopenharmony_ci#include "r600_dpm.h" 298c2ecf20Sopenharmony_ci#include "rv770_dpm.h" 308c2ecf20Sopenharmony_ci#include "cypress_dpm.h" 318c2ecf20Sopenharmony_ci#include "atom.h" 328c2ecf20Sopenharmony_ci#include <linux/seq_file.h> 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci#define MC_CG_ARB_FREQ_F0 0x0a 358c2ecf20Sopenharmony_ci#define MC_CG_ARB_FREQ_F1 0x0b 368c2ecf20Sopenharmony_ci#define MC_CG_ARB_FREQ_F2 0x0c 378c2ecf20Sopenharmony_ci#define MC_CG_ARB_FREQ_F3 0x0d 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci#define MC_CG_SEQ_DRAMCONF_S0 0x05 408c2ecf20Sopenharmony_ci#define MC_CG_SEQ_DRAMCONF_S1 0x06 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci#define PCIE_BUS_CLK 10000 438c2ecf20Sopenharmony_ci#define TCLK (PCIE_BUS_CLK / 10) 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci#define SMC_RAM_END 0xC000 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_cistruct rv7xx_ps *rv770_get_ps(struct radeon_ps *rps) 488c2ecf20Sopenharmony_ci{ 498c2ecf20Sopenharmony_ci struct rv7xx_ps *ps = rps->ps_priv; 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci return ps; 528c2ecf20Sopenharmony_ci} 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_cistruct rv7xx_power_info *rv770_get_pi(struct radeon_device *rdev) 558c2ecf20Sopenharmony_ci{ 568c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rdev->pm.dpm.priv; 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci return pi; 598c2ecf20Sopenharmony_ci} 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_cistruct evergreen_power_info *evergreen_get_pi(struct radeon_device *rdev) 628c2ecf20Sopenharmony_ci{ 638c2ecf20Sopenharmony_ci struct evergreen_power_info *pi = rdev->pm.dpm.priv; 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci return pi; 668c2ecf20Sopenharmony_ci} 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_cistatic void rv770_enable_bif_dynamic_pcie_gen2(struct radeon_device *rdev, 698c2ecf20Sopenharmony_ci bool enable) 708c2ecf20Sopenharmony_ci{ 718c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 728c2ecf20Sopenharmony_ci u32 tmp; 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci tmp = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL); 758c2ecf20Sopenharmony_ci if (enable) { 768c2ecf20Sopenharmony_ci tmp &= ~LC_HW_VOLTAGE_IF_CONTROL_MASK; 778c2ecf20Sopenharmony_ci tmp |= LC_HW_VOLTAGE_IF_CONTROL(1); 788c2ecf20Sopenharmony_ci tmp |= LC_GEN2_EN_STRAP; 798c2ecf20Sopenharmony_ci } else { 808c2ecf20Sopenharmony_ci if (!pi->boot_in_gen2) { 818c2ecf20Sopenharmony_ci tmp &= ~LC_HW_VOLTAGE_IF_CONTROL_MASK; 828c2ecf20Sopenharmony_ci tmp &= ~LC_GEN2_EN_STRAP; 838c2ecf20Sopenharmony_ci } 848c2ecf20Sopenharmony_ci } 858c2ecf20Sopenharmony_ci if ((tmp & LC_OTHER_SIDE_EVER_SENT_GEN2) || 868c2ecf20Sopenharmony_ci (tmp & LC_OTHER_SIDE_SUPPORTS_GEN2)) 878c2ecf20Sopenharmony_ci WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, tmp); 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci} 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_cistatic void rv770_enable_l0s(struct radeon_device *rdev) 928c2ecf20Sopenharmony_ci{ 938c2ecf20Sopenharmony_ci u32 tmp; 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL) & ~LC_L0S_INACTIVITY_MASK; 968c2ecf20Sopenharmony_ci tmp |= LC_L0S_INACTIVITY(3); 978c2ecf20Sopenharmony_ci WREG32_PCIE_PORT(PCIE_LC_CNTL, tmp); 988c2ecf20Sopenharmony_ci} 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_cistatic void rv770_enable_l1(struct radeon_device *rdev) 1018c2ecf20Sopenharmony_ci{ 1028c2ecf20Sopenharmony_ci u32 tmp; 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL); 1058c2ecf20Sopenharmony_ci tmp &= ~LC_L1_INACTIVITY_MASK; 1068c2ecf20Sopenharmony_ci tmp |= LC_L1_INACTIVITY(4); 1078c2ecf20Sopenharmony_ci tmp &= ~LC_PMI_TO_L1_DIS; 1088c2ecf20Sopenharmony_ci tmp &= ~LC_ASPM_TO_L1_DIS; 1098c2ecf20Sopenharmony_ci WREG32_PCIE_PORT(PCIE_LC_CNTL, tmp); 1108c2ecf20Sopenharmony_ci} 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_cistatic void rv770_enable_pll_sleep_in_l1(struct radeon_device *rdev) 1138c2ecf20Sopenharmony_ci{ 1148c2ecf20Sopenharmony_ci u32 tmp; 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_ci tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL) & ~LC_L1_INACTIVITY_MASK; 1178c2ecf20Sopenharmony_ci tmp |= LC_L1_INACTIVITY(8); 1188c2ecf20Sopenharmony_ci WREG32_PCIE_PORT(PCIE_LC_CNTL, tmp); 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_ci /* NOTE, this is a PCIE indirect reg, not PCIE PORT */ 1218c2ecf20Sopenharmony_ci tmp = RREG32_PCIE(PCIE_P_CNTL); 1228c2ecf20Sopenharmony_ci tmp |= P_PLL_PWRDN_IN_L1L23; 1238c2ecf20Sopenharmony_ci tmp &= ~P_PLL_BUF_PDNB; 1248c2ecf20Sopenharmony_ci tmp &= ~P_PLL_PDNB; 1258c2ecf20Sopenharmony_ci tmp |= P_ALLOW_PRX_FRONTEND_SHUTOFF; 1268c2ecf20Sopenharmony_ci WREG32_PCIE(PCIE_P_CNTL, tmp); 1278c2ecf20Sopenharmony_ci} 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_cistatic void rv770_gfx_clock_gating_enable(struct radeon_device *rdev, 1308c2ecf20Sopenharmony_ci bool enable) 1318c2ecf20Sopenharmony_ci{ 1328c2ecf20Sopenharmony_ci if (enable) 1338c2ecf20Sopenharmony_ci WREG32_P(SCLK_PWRMGT_CNTL, DYN_GFX_CLK_OFF_EN, ~DYN_GFX_CLK_OFF_EN); 1348c2ecf20Sopenharmony_ci else { 1358c2ecf20Sopenharmony_ci WREG32_P(SCLK_PWRMGT_CNTL, 0, ~DYN_GFX_CLK_OFF_EN); 1368c2ecf20Sopenharmony_ci WREG32_P(SCLK_PWRMGT_CNTL, GFX_CLK_FORCE_ON, ~GFX_CLK_FORCE_ON); 1378c2ecf20Sopenharmony_ci WREG32_P(SCLK_PWRMGT_CNTL, 0, ~GFX_CLK_FORCE_ON); 1388c2ecf20Sopenharmony_ci RREG32(GB_TILING_CONFIG); 1398c2ecf20Sopenharmony_ci } 1408c2ecf20Sopenharmony_ci} 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_cistatic void rv770_mg_clock_gating_enable(struct radeon_device *rdev, 1438c2ecf20Sopenharmony_ci bool enable) 1448c2ecf20Sopenharmony_ci{ 1458c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci if (enable) { 1488c2ecf20Sopenharmony_ci u32 mgcg_cgtt_local0; 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_ci if (rdev->family == CHIP_RV770) 1518c2ecf20Sopenharmony_ci mgcg_cgtt_local0 = RV770_MGCGTTLOCAL0_DFLT; 1528c2ecf20Sopenharmony_ci else 1538c2ecf20Sopenharmony_ci mgcg_cgtt_local0 = RV7XX_MGCGTTLOCAL0_DFLT; 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_ci WREG32(CG_CGTT_LOCAL_0, mgcg_cgtt_local0); 1568c2ecf20Sopenharmony_ci WREG32(CG_CGTT_LOCAL_1, (RV770_MGCGTTLOCAL1_DFLT & 0xFFFFCFFF)); 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_ci if (pi->mgcgtssm) 1598c2ecf20Sopenharmony_ci WREG32(CGTS_SM_CTRL_REG, RV770_MGCGCGTSSMCTRL_DFLT); 1608c2ecf20Sopenharmony_ci } else { 1618c2ecf20Sopenharmony_ci WREG32(CG_CGTT_LOCAL_0, 0xFFFFFFFF); 1628c2ecf20Sopenharmony_ci WREG32(CG_CGTT_LOCAL_1, 0xFFFFCFFF); 1638c2ecf20Sopenharmony_ci } 1648c2ecf20Sopenharmony_ci} 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_civoid rv770_restore_cgcg(struct radeon_device *rdev) 1678c2ecf20Sopenharmony_ci{ 1688c2ecf20Sopenharmony_ci bool dpm_en = false, cg_en = false; 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ci if (RREG32(GENERAL_PWRMGT) & GLOBAL_PWRMGT_EN) 1718c2ecf20Sopenharmony_ci dpm_en = true; 1728c2ecf20Sopenharmony_ci if (RREG32(SCLK_PWRMGT_CNTL) & DYN_GFX_CLK_OFF_EN) 1738c2ecf20Sopenharmony_ci cg_en = true; 1748c2ecf20Sopenharmony_ci 1758c2ecf20Sopenharmony_ci if (dpm_en && !cg_en) 1768c2ecf20Sopenharmony_ci WREG32_P(SCLK_PWRMGT_CNTL, DYN_GFX_CLK_OFF_EN, ~DYN_GFX_CLK_OFF_EN); 1778c2ecf20Sopenharmony_ci} 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_cistatic void rv770_start_dpm(struct radeon_device *rdev) 1808c2ecf20Sopenharmony_ci{ 1818c2ecf20Sopenharmony_ci WREG32_P(SCLK_PWRMGT_CNTL, 0, ~SCLK_PWRMGT_OFF); 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_ci WREG32_P(MCLK_PWRMGT_CNTL, 0, ~MPLL_PWRMGT_OFF); 1848c2ecf20Sopenharmony_ci 1858c2ecf20Sopenharmony_ci WREG32_P(GENERAL_PWRMGT, GLOBAL_PWRMGT_EN, ~GLOBAL_PWRMGT_EN); 1868c2ecf20Sopenharmony_ci} 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_civoid rv770_stop_dpm(struct radeon_device *rdev) 1898c2ecf20Sopenharmony_ci{ 1908c2ecf20Sopenharmony_ci PPSMC_Result result; 1918c2ecf20Sopenharmony_ci 1928c2ecf20Sopenharmony_ci result = rv770_send_msg_to_smc(rdev, PPSMC_MSG_TwoLevelsDisabled); 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_ci if (result != PPSMC_Result_OK) 1958c2ecf20Sopenharmony_ci DRM_DEBUG("Could not force DPM to low.\n"); 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_ci WREG32_P(GENERAL_PWRMGT, 0, ~GLOBAL_PWRMGT_EN); 1988c2ecf20Sopenharmony_ci 1998c2ecf20Sopenharmony_ci WREG32_P(SCLK_PWRMGT_CNTL, SCLK_PWRMGT_OFF, ~SCLK_PWRMGT_OFF); 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_ci WREG32_P(MCLK_PWRMGT_CNTL, MPLL_PWRMGT_OFF, ~MPLL_PWRMGT_OFF); 2028c2ecf20Sopenharmony_ci} 2038c2ecf20Sopenharmony_ci 2048c2ecf20Sopenharmony_cibool rv770_dpm_enabled(struct radeon_device *rdev) 2058c2ecf20Sopenharmony_ci{ 2068c2ecf20Sopenharmony_ci if (RREG32(GENERAL_PWRMGT) & GLOBAL_PWRMGT_EN) 2078c2ecf20Sopenharmony_ci return true; 2088c2ecf20Sopenharmony_ci else 2098c2ecf20Sopenharmony_ci return false; 2108c2ecf20Sopenharmony_ci} 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_civoid rv770_enable_thermal_protection(struct radeon_device *rdev, 2138c2ecf20Sopenharmony_ci bool enable) 2148c2ecf20Sopenharmony_ci{ 2158c2ecf20Sopenharmony_ci if (enable) 2168c2ecf20Sopenharmony_ci WREG32_P(GENERAL_PWRMGT, 0, ~THERMAL_PROTECTION_DIS); 2178c2ecf20Sopenharmony_ci else 2188c2ecf20Sopenharmony_ci WREG32_P(GENERAL_PWRMGT, THERMAL_PROTECTION_DIS, ~THERMAL_PROTECTION_DIS); 2198c2ecf20Sopenharmony_ci} 2208c2ecf20Sopenharmony_ci 2218c2ecf20Sopenharmony_civoid rv770_enable_acpi_pm(struct radeon_device *rdev) 2228c2ecf20Sopenharmony_ci{ 2238c2ecf20Sopenharmony_ci WREG32_P(GENERAL_PWRMGT, STATIC_PM_EN, ~STATIC_PM_EN); 2248c2ecf20Sopenharmony_ci} 2258c2ecf20Sopenharmony_ci 2268c2ecf20Sopenharmony_ciu8 rv770_get_seq_value(struct radeon_device *rdev, 2278c2ecf20Sopenharmony_ci struct rv7xx_pl *pl) 2288c2ecf20Sopenharmony_ci{ 2298c2ecf20Sopenharmony_ci return (pl->flags & ATOM_PPLIB_R600_FLAGS_LOWPOWER) ? 2308c2ecf20Sopenharmony_ci MC_CG_SEQ_DRAMCONF_S0 : MC_CG_SEQ_DRAMCONF_S1; 2318c2ecf20Sopenharmony_ci} 2328c2ecf20Sopenharmony_ci 2338c2ecf20Sopenharmony_ci#if 0 2348c2ecf20Sopenharmony_ciint rv770_read_smc_soft_register(struct radeon_device *rdev, 2358c2ecf20Sopenharmony_ci u16 reg_offset, u32 *value) 2368c2ecf20Sopenharmony_ci{ 2378c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 2388c2ecf20Sopenharmony_ci 2398c2ecf20Sopenharmony_ci return rv770_read_smc_sram_dword(rdev, 2408c2ecf20Sopenharmony_ci pi->soft_regs_start + reg_offset, 2418c2ecf20Sopenharmony_ci value, pi->sram_end); 2428c2ecf20Sopenharmony_ci} 2438c2ecf20Sopenharmony_ci#endif 2448c2ecf20Sopenharmony_ci 2458c2ecf20Sopenharmony_ciint rv770_write_smc_soft_register(struct radeon_device *rdev, 2468c2ecf20Sopenharmony_ci u16 reg_offset, u32 value) 2478c2ecf20Sopenharmony_ci{ 2488c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 2498c2ecf20Sopenharmony_ci 2508c2ecf20Sopenharmony_ci return rv770_write_smc_sram_dword(rdev, 2518c2ecf20Sopenharmony_ci pi->soft_regs_start + reg_offset, 2528c2ecf20Sopenharmony_ci value, pi->sram_end); 2538c2ecf20Sopenharmony_ci} 2548c2ecf20Sopenharmony_ci 2558c2ecf20Sopenharmony_ciint rv770_populate_smc_t(struct radeon_device *rdev, 2568c2ecf20Sopenharmony_ci struct radeon_ps *radeon_state, 2578c2ecf20Sopenharmony_ci RV770_SMC_SWSTATE *smc_state) 2588c2ecf20Sopenharmony_ci{ 2598c2ecf20Sopenharmony_ci struct rv7xx_ps *state = rv770_get_ps(radeon_state); 2608c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 2618c2ecf20Sopenharmony_ci int i; 2628c2ecf20Sopenharmony_ci int a_n; 2638c2ecf20Sopenharmony_ci int a_d; 2648c2ecf20Sopenharmony_ci u8 l[RV770_SMC_PERFORMANCE_LEVELS_PER_SWSTATE]; 2658c2ecf20Sopenharmony_ci u8 r[RV770_SMC_PERFORMANCE_LEVELS_PER_SWSTATE]; 2668c2ecf20Sopenharmony_ci u32 a_t; 2678c2ecf20Sopenharmony_ci 2688c2ecf20Sopenharmony_ci l[0] = 0; 2698c2ecf20Sopenharmony_ci r[2] = 100; 2708c2ecf20Sopenharmony_ci 2718c2ecf20Sopenharmony_ci a_n = (int)state->medium.sclk * pi->lmp + 2728c2ecf20Sopenharmony_ci (int)state->low.sclk * (R600_AH_DFLT - pi->rlp); 2738c2ecf20Sopenharmony_ci a_d = (int)state->low.sclk * (100 - (int)pi->rlp) + 2748c2ecf20Sopenharmony_ci (int)state->medium.sclk * pi->lmp; 2758c2ecf20Sopenharmony_ci 2768c2ecf20Sopenharmony_ci l[1] = (u8)(pi->lmp - (int)pi->lmp * a_n / a_d); 2778c2ecf20Sopenharmony_ci r[0] = (u8)(pi->rlp + (100 - (int)pi->rlp) * a_n / a_d); 2788c2ecf20Sopenharmony_ci 2798c2ecf20Sopenharmony_ci a_n = (int)state->high.sclk * pi->lhp + (int)state->medium.sclk * 2808c2ecf20Sopenharmony_ci (R600_AH_DFLT - pi->rmp); 2818c2ecf20Sopenharmony_ci a_d = (int)state->medium.sclk * (100 - (int)pi->rmp) + 2828c2ecf20Sopenharmony_ci (int)state->high.sclk * pi->lhp; 2838c2ecf20Sopenharmony_ci 2848c2ecf20Sopenharmony_ci l[2] = (u8)(pi->lhp - (int)pi->lhp * a_n / a_d); 2858c2ecf20Sopenharmony_ci r[1] = (u8)(pi->rmp + (100 - (int)pi->rmp) * a_n / a_d); 2868c2ecf20Sopenharmony_ci 2878c2ecf20Sopenharmony_ci for (i = 0; i < (RV770_SMC_PERFORMANCE_LEVELS_PER_SWSTATE - 1); i++) { 2888c2ecf20Sopenharmony_ci a_t = CG_R(r[i] * pi->bsp / 200) | CG_L(l[i] * pi->bsp / 200); 2898c2ecf20Sopenharmony_ci smc_state->levels[i].aT = cpu_to_be32(a_t); 2908c2ecf20Sopenharmony_ci } 2918c2ecf20Sopenharmony_ci 2928c2ecf20Sopenharmony_ci a_t = CG_R(r[RV770_SMC_PERFORMANCE_LEVELS_PER_SWSTATE - 1] * pi->pbsp / 200) | 2938c2ecf20Sopenharmony_ci CG_L(l[RV770_SMC_PERFORMANCE_LEVELS_PER_SWSTATE - 1] * pi->pbsp / 200); 2948c2ecf20Sopenharmony_ci 2958c2ecf20Sopenharmony_ci smc_state->levels[RV770_SMC_PERFORMANCE_LEVELS_PER_SWSTATE - 1].aT = 2968c2ecf20Sopenharmony_ci cpu_to_be32(a_t); 2978c2ecf20Sopenharmony_ci 2988c2ecf20Sopenharmony_ci return 0; 2998c2ecf20Sopenharmony_ci} 3008c2ecf20Sopenharmony_ci 3018c2ecf20Sopenharmony_ciint rv770_populate_smc_sp(struct radeon_device *rdev, 3028c2ecf20Sopenharmony_ci struct radeon_ps *radeon_state, 3038c2ecf20Sopenharmony_ci RV770_SMC_SWSTATE *smc_state) 3048c2ecf20Sopenharmony_ci{ 3058c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 3068c2ecf20Sopenharmony_ci int i; 3078c2ecf20Sopenharmony_ci 3088c2ecf20Sopenharmony_ci for (i = 0; i < (RV770_SMC_PERFORMANCE_LEVELS_PER_SWSTATE - 1); i++) 3098c2ecf20Sopenharmony_ci smc_state->levels[i].bSP = cpu_to_be32(pi->dsp); 3108c2ecf20Sopenharmony_ci 3118c2ecf20Sopenharmony_ci smc_state->levels[RV770_SMC_PERFORMANCE_LEVELS_PER_SWSTATE - 1].bSP = 3128c2ecf20Sopenharmony_ci cpu_to_be32(pi->psp); 3138c2ecf20Sopenharmony_ci 3148c2ecf20Sopenharmony_ci return 0; 3158c2ecf20Sopenharmony_ci} 3168c2ecf20Sopenharmony_ci 3178c2ecf20Sopenharmony_cistatic void rv770_calculate_fractional_mpll_feedback_divider(u32 memory_clock, 3188c2ecf20Sopenharmony_ci u32 reference_clock, 3198c2ecf20Sopenharmony_ci bool gddr5, 3208c2ecf20Sopenharmony_ci struct atom_clock_dividers *dividers, 3218c2ecf20Sopenharmony_ci u32 *clkf, 3228c2ecf20Sopenharmony_ci u32 *clkfrac) 3238c2ecf20Sopenharmony_ci{ 3248c2ecf20Sopenharmony_ci u32 post_divider, reference_divider, feedback_divider8; 3258c2ecf20Sopenharmony_ci u32 fyclk; 3268c2ecf20Sopenharmony_ci 3278c2ecf20Sopenharmony_ci if (gddr5) 3288c2ecf20Sopenharmony_ci fyclk = (memory_clock * 8) / 2; 3298c2ecf20Sopenharmony_ci else 3308c2ecf20Sopenharmony_ci fyclk = (memory_clock * 4) / 2; 3318c2ecf20Sopenharmony_ci 3328c2ecf20Sopenharmony_ci post_divider = dividers->post_div; 3338c2ecf20Sopenharmony_ci reference_divider = dividers->ref_div; 3348c2ecf20Sopenharmony_ci 3358c2ecf20Sopenharmony_ci feedback_divider8 = 3368c2ecf20Sopenharmony_ci (8 * fyclk * reference_divider * post_divider) / reference_clock; 3378c2ecf20Sopenharmony_ci 3388c2ecf20Sopenharmony_ci *clkf = feedback_divider8 / 8; 3398c2ecf20Sopenharmony_ci *clkfrac = feedback_divider8 % 8; 3408c2ecf20Sopenharmony_ci} 3418c2ecf20Sopenharmony_ci 3428c2ecf20Sopenharmony_cistatic int rv770_encode_yclk_post_div(u32 postdiv, u32 *encoded_postdiv) 3438c2ecf20Sopenharmony_ci{ 3448c2ecf20Sopenharmony_ci int ret = 0; 3458c2ecf20Sopenharmony_ci 3468c2ecf20Sopenharmony_ci switch (postdiv) { 3478c2ecf20Sopenharmony_ci case 1: 3488c2ecf20Sopenharmony_ci *encoded_postdiv = 0; 3498c2ecf20Sopenharmony_ci break; 3508c2ecf20Sopenharmony_ci case 2: 3518c2ecf20Sopenharmony_ci *encoded_postdiv = 1; 3528c2ecf20Sopenharmony_ci break; 3538c2ecf20Sopenharmony_ci case 4: 3548c2ecf20Sopenharmony_ci *encoded_postdiv = 2; 3558c2ecf20Sopenharmony_ci break; 3568c2ecf20Sopenharmony_ci case 8: 3578c2ecf20Sopenharmony_ci *encoded_postdiv = 3; 3588c2ecf20Sopenharmony_ci break; 3598c2ecf20Sopenharmony_ci case 16: 3608c2ecf20Sopenharmony_ci *encoded_postdiv = 4; 3618c2ecf20Sopenharmony_ci break; 3628c2ecf20Sopenharmony_ci default: 3638c2ecf20Sopenharmony_ci ret = -EINVAL; 3648c2ecf20Sopenharmony_ci break; 3658c2ecf20Sopenharmony_ci } 3668c2ecf20Sopenharmony_ci 3678c2ecf20Sopenharmony_ci return ret; 3688c2ecf20Sopenharmony_ci} 3698c2ecf20Sopenharmony_ci 3708c2ecf20Sopenharmony_ciu32 rv770_map_clkf_to_ibias(struct radeon_device *rdev, u32 clkf) 3718c2ecf20Sopenharmony_ci{ 3728c2ecf20Sopenharmony_ci if (clkf <= 0x10) 3738c2ecf20Sopenharmony_ci return 0x4B; 3748c2ecf20Sopenharmony_ci if (clkf <= 0x19) 3758c2ecf20Sopenharmony_ci return 0x5B; 3768c2ecf20Sopenharmony_ci if (clkf <= 0x21) 3778c2ecf20Sopenharmony_ci return 0x2B; 3788c2ecf20Sopenharmony_ci if (clkf <= 0x27) 3798c2ecf20Sopenharmony_ci return 0x6C; 3808c2ecf20Sopenharmony_ci if (clkf <= 0x31) 3818c2ecf20Sopenharmony_ci return 0x9D; 3828c2ecf20Sopenharmony_ci return 0xC6; 3838c2ecf20Sopenharmony_ci} 3848c2ecf20Sopenharmony_ci 3858c2ecf20Sopenharmony_cistatic int rv770_populate_mclk_value(struct radeon_device *rdev, 3868c2ecf20Sopenharmony_ci u32 engine_clock, u32 memory_clock, 3878c2ecf20Sopenharmony_ci RV7XX_SMC_MCLK_VALUE *mclk) 3888c2ecf20Sopenharmony_ci{ 3898c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 3908c2ecf20Sopenharmony_ci u8 encoded_reference_dividers[] = { 0, 16, 17, 20, 21 }; 3918c2ecf20Sopenharmony_ci u32 mpll_ad_func_cntl = 3928c2ecf20Sopenharmony_ci pi->clk_regs.rv770.mpll_ad_func_cntl; 3938c2ecf20Sopenharmony_ci u32 mpll_ad_func_cntl_2 = 3948c2ecf20Sopenharmony_ci pi->clk_regs.rv770.mpll_ad_func_cntl_2; 3958c2ecf20Sopenharmony_ci u32 mpll_dq_func_cntl = 3968c2ecf20Sopenharmony_ci pi->clk_regs.rv770.mpll_dq_func_cntl; 3978c2ecf20Sopenharmony_ci u32 mpll_dq_func_cntl_2 = 3988c2ecf20Sopenharmony_ci pi->clk_regs.rv770.mpll_dq_func_cntl_2; 3998c2ecf20Sopenharmony_ci u32 mclk_pwrmgt_cntl = 4008c2ecf20Sopenharmony_ci pi->clk_regs.rv770.mclk_pwrmgt_cntl; 4018c2ecf20Sopenharmony_ci u32 dll_cntl = pi->clk_regs.rv770.dll_cntl; 4028c2ecf20Sopenharmony_ci struct atom_clock_dividers dividers; 4038c2ecf20Sopenharmony_ci u32 reference_clock = rdev->clock.mpll.reference_freq; 4048c2ecf20Sopenharmony_ci u32 clkf, clkfrac; 4058c2ecf20Sopenharmony_ci u32 postdiv_yclk; 4068c2ecf20Sopenharmony_ci u32 ibias; 4078c2ecf20Sopenharmony_ci int ret; 4088c2ecf20Sopenharmony_ci 4098c2ecf20Sopenharmony_ci ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_MEMORY_PLL_PARAM, 4108c2ecf20Sopenharmony_ci memory_clock, false, ÷rs); 4118c2ecf20Sopenharmony_ci if (ret) 4128c2ecf20Sopenharmony_ci return ret; 4138c2ecf20Sopenharmony_ci 4148c2ecf20Sopenharmony_ci if ((dividers.ref_div < 1) || (dividers.ref_div > 5)) 4158c2ecf20Sopenharmony_ci return -EINVAL; 4168c2ecf20Sopenharmony_ci 4178c2ecf20Sopenharmony_ci rv770_calculate_fractional_mpll_feedback_divider(memory_clock, reference_clock, 4188c2ecf20Sopenharmony_ci pi->mem_gddr5, 4198c2ecf20Sopenharmony_ci ÷rs, &clkf, &clkfrac); 4208c2ecf20Sopenharmony_ci 4218c2ecf20Sopenharmony_ci ret = rv770_encode_yclk_post_div(dividers.post_div, &postdiv_yclk); 4228c2ecf20Sopenharmony_ci if (ret) 4238c2ecf20Sopenharmony_ci return ret; 4248c2ecf20Sopenharmony_ci 4258c2ecf20Sopenharmony_ci ibias = rv770_map_clkf_to_ibias(rdev, clkf); 4268c2ecf20Sopenharmony_ci 4278c2ecf20Sopenharmony_ci mpll_ad_func_cntl &= ~(CLKR_MASK | 4288c2ecf20Sopenharmony_ci YCLK_POST_DIV_MASK | 4298c2ecf20Sopenharmony_ci CLKF_MASK | 4308c2ecf20Sopenharmony_ci CLKFRAC_MASK | 4318c2ecf20Sopenharmony_ci IBIAS_MASK); 4328c2ecf20Sopenharmony_ci mpll_ad_func_cntl |= CLKR(encoded_reference_dividers[dividers.ref_div - 1]); 4338c2ecf20Sopenharmony_ci mpll_ad_func_cntl |= YCLK_POST_DIV(postdiv_yclk); 4348c2ecf20Sopenharmony_ci mpll_ad_func_cntl |= CLKF(clkf); 4358c2ecf20Sopenharmony_ci mpll_ad_func_cntl |= CLKFRAC(clkfrac); 4368c2ecf20Sopenharmony_ci mpll_ad_func_cntl |= IBIAS(ibias); 4378c2ecf20Sopenharmony_ci 4388c2ecf20Sopenharmony_ci if (dividers.vco_mode) 4398c2ecf20Sopenharmony_ci mpll_ad_func_cntl_2 |= VCO_MODE; 4408c2ecf20Sopenharmony_ci else 4418c2ecf20Sopenharmony_ci mpll_ad_func_cntl_2 &= ~VCO_MODE; 4428c2ecf20Sopenharmony_ci 4438c2ecf20Sopenharmony_ci if (pi->mem_gddr5) { 4448c2ecf20Sopenharmony_ci rv770_calculate_fractional_mpll_feedback_divider(memory_clock, 4458c2ecf20Sopenharmony_ci reference_clock, 4468c2ecf20Sopenharmony_ci pi->mem_gddr5, 4478c2ecf20Sopenharmony_ci ÷rs, &clkf, &clkfrac); 4488c2ecf20Sopenharmony_ci 4498c2ecf20Sopenharmony_ci ibias = rv770_map_clkf_to_ibias(rdev, clkf); 4508c2ecf20Sopenharmony_ci 4518c2ecf20Sopenharmony_ci ret = rv770_encode_yclk_post_div(dividers.post_div, &postdiv_yclk); 4528c2ecf20Sopenharmony_ci if (ret) 4538c2ecf20Sopenharmony_ci return ret; 4548c2ecf20Sopenharmony_ci 4558c2ecf20Sopenharmony_ci mpll_dq_func_cntl &= ~(CLKR_MASK | 4568c2ecf20Sopenharmony_ci YCLK_POST_DIV_MASK | 4578c2ecf20Sopenharmony_ci CLKF_MASK | 4588c2ecf20Sopenharmony_ci CLKFRAC_MASK | 4598c2ecf20Sopenharmony_ci IBIAS_MASK); 4608c2ecf20Sopenharmony_ci mpll_dq_func_cntl |= CLKR(encoded_reference_dividers[dividers.ref_div - 1]); 4618c2ecf20Sopenharmony_ci mpll_dq_func_cntl |= YCLK_POST_DIV(postdiv_yclk); 4628c2ecf20Sopenharmony_ci mpll_dq_func_cntl |= CLKF(clkf); 4638c2ecf20Sopenharmony_ci mpll_dq_func_cntl |= CLKFRAC(clkfrac); 4648c2ecf20Sopenharmony_ci mpll_dq_func_cntl |= IBIAS(ibias); 4658c2ecf20Sopenharmony_ci 4668c2ecf20Sopenharmony_ci if (dividers.vco_mode) 4678c2ecf20Sopenharmony_ci mpll_dq_func_cntl_2 |= VCO_MODE; 4688c2ecf20Sopenharmony_ci else 4698c2ecf20Sopenharmony_ci mpll_dq_func_cntl_2 &= ~VCO_MODE; 4708c2ecf20Sopenharmony_ci } 4718c2ecf20Sopenharmony_ci 4728c2ecf20Sopenharmony_ci mclk->mclk770.mclk_value = cpu_to_be32(memory_clock); 4738c2ecf20Sopenharmony_ci mclk->mclk770.vMPLL_AD_FUNC_CNTL = cpu_to_be32(mpll_ad_func_cntl); 4748c2ecf20Sopenharmony_ci mclk->mclk770.vMPLL_AD_FUNC_CNTL_2 = cpu_to_be32(mpll_ad_func_cntl_2); 4758c2ecf20Sopenharmony_ci mclk->mclk770.vMPLL_DQ_FUNC_CNTL = cpu_to_be32(mpll_dq_func_cntl); 4768c2ecf20Sopenharmony_ci mclk->mclk770.vMPLL_DQ_FUNC_CNTL_2 = cpu_to_be32(mpll_dq_func_cntl_2); 4778c2ecf20Sopenharmony_ci mclk->mclk770.vMCLK_PWRMGT_CNTL = cpu_to_be32(mclk_pwrmgt_cntl); 4788c2ecf20Sopenharmony_ci mclk->mclk770.vDLL_CNTL = cpu_to_be32(dll_cntl); 4798c2ecf20Sopenharmony_ci 4808c2ecf20Sopenharmony_ci return 0; 4818c2ecf20Sopenharmony_ci} 4828c2ecf20Sopenharmony_ci 4838c2ecf20Sopenharmony_cistatic int rv770_populate_sclk_value(struct radeon_device *rdev, 4848c2ecf20Sopenharmony_ci u32 engine_clock, 4858c2ecf20Sopenharmony_ci RV770_SMC_SCLK_VALUE *sclk) 4868c2ecf20Sopenharmony_ci{ 4878c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 4888c2ecf20Sopenharmony_ci struct atom_clock_dividers dividers; 4898c2ecf20Sopenharmony_ci u32 spll_func_cntl = 4908c2ecf20Sopenharmony_ci pi->clk_regs.rv770.cg_spll_func_cntl; 4918c2ecf20Sopenharmony_ci u32 spll_func_cntl_2 = 4928c2ecf20Sopenharmony_ci pi->clk_regs.rv770.cg_spll_func_cntl_2; 4938c2ecf20Sopenharmony_ci u32 spll_func_cntl_3 = 4948c2ecf20Sopenharmony_ci pi->clk_regs.rv770.cg_spll_func_cntl_3; 4958c2ecf20Sopenharmony_ci u32 cg_spll_spread_spectrum = 4968c2ecf20Sopenharmony_ci pi->clk_regs.rv770.cg_spll_spread_spectrum; 4978c2ecf20Sopenharmony_ci u32 cg_spll_spread_spectrum_2 = 4988c2ecf20Sopenharmony_ci pi->clk_regs.rv770.cg_spll_spread_spectrum_2; 4998c2ecf20Sopenharmony_ci u64 tmp; 5008c2ecf20Sopenharmony_ci u32 reference_clock = rdev->clock.spll.reference_freq; 5018c2ecf20Sopenharmony_ci u32 reference_divider, post_divider; 5028c2ecf20Sopenharmony_ci u32 fbdiv; 5038c2ecf20Sopenharmony_ci int ret; 5048c2ecf20Sopenharmony_ci 5058c2ecf20Sopenharmony_ci ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM, 5068c2ecf20Sopenharmony_ci engine_clock, false, ÷rs); 5078c2ecf20Sopenharmony_ci if (ret) 5088c2ecf20Sopenharmony_ci return ret; 5098c2ecf20Sopenharmony_ci 5108c2ecf20Sopenharmony_ci reference_divider = 1 + dividers.ref_div; 5118c2ecf20Sopenharmony_ci 5128c2ecf20Sopenharmony_ci if (dividers.enable_post_div) 5138c2ecf20Sopenharmony_ci post_divider = (0x0f & (dividers.post_div >> 4)) + (0x0f & dividers.post_div) + 2; 5148c2ecf20Sopenharmony_ci else 5158c2ecf20Sopenharmony_ci post_divider = 1; 5168c2ecf20Sopenharmony_ci 5178c2ecf20Sopenharmony_ci tmp = (u64) engine_clock * reference_divider * post_divider * 16384; 5188c2ecf20Sopenharmony_ci do_div(tmp, reference_clock); 5198c2ecf20Sopenharmony_ci fbdiv = (u32) tmp; 5208c2ecf20Sopenharmony_ci 5218c2ecf20Sopenharmony_ci if (dividers.enable_post_div) 5228c2ecf20Sopenharmony_ci spll_func_cntl |= SPLL_DIVEN; 5238c2ecf20Sopenharmony_ci else 5248c2ecf20Sopenharmony_ci spll_func_cntl &= ~SPLL_DIVEN; 5258c2ecf20Sopenharmony_ci spll_func_cntl &= ~(SPLL_HILEN_MASK | SPLL_LOLEN_MASK | SPLL_REF_DIV_MASK); 5268c2ecf20Sopenharmony_ci spll_func_cntl |= SPLL_REF_DIV(dividers.ref_div); 5278c2ecf20Sopenharmony_ci spll_func_cntl |= SPLL_HILEN((dividers.post_div >> 4) & 0xf); 5288c2ecf20Sopenharmony_ci spll_func_cntl |= SPLL_LOLEN(dividers.post_div & 0xf); 5298c2ecf20Sopenharmony_ci 5308c2ecf20Sopenharmony_ci spll_func_cntl_2 &= ~SCLK_MUX_SEL_MASK; 5318c2ecf20Sopenharmony_ci spll_func_cntl_2 |= SCLK_MUX_SEL(2); 5328c2ecf20Sopenharmony_ci 5338c2ecf20Sopenharmony_ci spll_func_cntl_3 &= ~SPLL_FB_DIV_MASK; 5348c2ecf20Sopenharmony_ci spll_func_cntl_3 |= SPLL_FB_DIV(fbdiv); 5358c2ecf20Sopenharmony_ci spll_func_cntl_3 |= SPLL_DITHEN; 5368c2ecf20Sopenharmony_ci 5378c2ecf20Sopenharmony_ci if (pi->sclk_ss) { 5388c2ecf20Sopenharmony_ci struct radeon_atom_ss ss; 5398c2ecf20Sopenharmony_ci u32 vco_freq = engine_clock * post_divider; 5408c2ecf20Sopenharmony_ci 5418c2ecf20Sopenharmony_ci if (radeon_atombios_get_asic_ss_info(rdev, &ss, 5428c2ecf20Sopenharmony_ci ASIC_INTERNAL_ENGINE_SS, vco_freq)) { 5438c2ecf20Sopenharmony_ci u32 clk_s = reference_clock * 5 / (reference_divider * ss.rate); 5448c2ecf20Sopenharmony_ci u32 clk_v = ss.percentage * fbdiv / (clk_s * 10000); 5458c2ecf20Sopenharmony_ci 5468c2ecf20Sopenharmony_ci cg_spll_spread_spectrum &= ~CLKS_MASK; 5478c2ecf20Sopenharmony_ci cg_spll_spread_spectrum |= CLKS(clk_s); 5488c2ecf20Sopenharmony_ci cg_spll_spread_spectrum |= SSEN; 5498c2ecf20Sopenharmony_ci 5508c2ecf20Sopenharmony_ci cg_spll_spread_spectrum_2 &= ~CLKV_MASK; 5518c2ecf20Sopenharmony_ci cg_spll_spread_spectrum_2 |= CLKV(clk_v); 5528c2ecf20Sopenharmony_ci } 5538c2ecf20Sopenharmony_ci } 5548c2ecf20Sopenharmony_ci 5558c2ecf20Sopenharmony_ci sclk->sclk_value = cpu_to_be32(engine_clock); 5568c2ecf20Sopenharmony_ci sclk->vCG_SPLL_FUNC_CNTL = cpu_to_be32(spll_func_cntl); 5578c2ecf20Sopenharmony_ci sclk->vCG_SPLL_FUNC_CNTL_2 = cpu_to_be32(spll_func_cntl_2); 5588c2ecf20Sopenharmony_ci sclk->vCG_SPLL_FUNC_CNTL_3 = cpu_to_be32(spll_func_cntl_3); 5598c2ecf20Sopenharmony_ci sclk->vCG_SPLL_SPREAD_SPECTRUM = cpu_to_be32(cg_spll_spread_spectrum); 5608c2ecf20Sopenharmony_ci sclk->vCG_SPLL_SPREAD_SPECTRUM_2 = cpu_to_be32(cg_spll_spread_spectrum_2); 5618c2ecf20Sopenharmony_ci 5628c2ecf20Sopenharmony_ci return 0; 5638c2ecf20Sopenharmony_ci} 5648c2ecf20Sopenharmony_ci 5658c2ecf20Sopenharmony_ciint rv770_populate_vddc_value(struct radeon_device *rdev, u16 vddc, 5668c2ecf20Sopenharmony_ci RV770_SMC_VOLTAGE_VALUE *voltage) 5678c2ecf20Sopenharmony_ci{ 5688c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 5698c2ecf20Sopenharmony_ci int i; 5708c2ecf20Sopenharmony_ci 5718c2ecf20Sopenharmony_ci if (!pi->voltage_control) { 5728c2ecf20Sopenharmony_ci voltage->index = 0; 5738c2ecf20Sopenharmony_ci voltage->value = 0; 5748c2ecf20Sopenharmony_ci return 0; 5758c2ecf20Sopenharmony_ci } 5768c2ecf20Sopenharmony_ci 5778c2ecf20Sopenharmony_ci for (i = 0; i < pi->valid_vddc_entries; i++) { 5788c2ecf20Sopenharmony_ci if (vddc <= pi->vddc_table[i].vddc) { 5798c2ecf20Sopenharmony_ci voltage->index = pi->vddc_table[i].vddc_index; 5808c2ecf20Sopenharmony_ci voltage->value = cpu_to_be16(vddc); 5818c2ecf20Sopenharmony_ci break; 5828c2ecf20Sopenharmony_ci } 5838c2ecf20Sopenharmony_ci } 5848c2ecf20Sopenharmony_ci 5858c2ecf20Sopenharmony_ci if (i == pi->valid_vddc_entries) 5868c2ecf20Sopenharmony_ci return -EINVAL; 5878c2ecf20Sopenharmony_ci 5888c2ecf20Sopenharmony_ci return 0; 5898c2ecf20Sopenharmony_ci} 5908c2ecf20Sopenharmony_ci 5918c2ecf20Sopenharmony_ciint rv770_populate_mvdd_value(struct radeon_device *rdev, u32 mclk, 5928c2ecf20Sopenharmony_ci RV770_SMC_VOLTAGE_VALUE *voltage) 5938c2ecf20Sopenharmony_ci{ 5948c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 5958c2ecf20Sopenharmony_ci 5968c2ecf20Sopenharmony_ci if (!pi->mvdd_control) { 5978c2ecf20Sopenharmony_ci voltage->index = MVDD_HIGH_INDEX; 5988c2ecf20Sopenharmony_ci voltage->value = cpu_to_be16(MVDD_HIGH_VALUE); 5998c2ecf20Sopenharmony_ci return 0; 6008c2ecf20Sopenharmony_ci } 6018c2ecf20Sopenharmony_ci 6028c2ecf20Sopenharmony_ci if (mclk <= pi->mvdd_split_frequency) { 6038c2ecf20Sopenharmony_ci voltage->index = MVDD_LOW_INDEX; 6048c2ecf20Sopenharmony_ci voltage->value = cpu_to_be16(MVDD_LOW_VALUE); 6058c2ecf20Sopenharmony_ci } else { 6068c2ecf20Sopenharmony_ci voltage->index = MVDD_HIGH_INDEX; 6078c2ecf20Sopenharmony_ci voltage->value = cpu_to_be16(MVDD_HIGH_VALUE); 6088c2ecf20Sopenharmony_ci } 6098c2ecf20Sopenharmony_ci 6108c2ecf20Sopenharmony_ci return 0; 6118c2ecf20Sopenharmony_ci} 6128c2ecf20Sopenharmony_ci 6138c2ecf20Sopenharmony_cistatic int rv770_convert_power_level_to_smc(struct radeon_device *rdev, 6148c2ecf20Sopenharmony_ci struct rv7xx_pl *pl, 6158c2ecf20Sopenharmony_ci RV770_SMC_HW_PERFORMANCE_LEVEL *level, 6168c2ecf20Sopenharmony_ci u8 watermark_level) 6178c2ecf20Sopenharmony_ci{ 6188c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 6198c2ecf20Sopenharmony_ci int ret; 6208c2ecf20Sopenharmony_ci 6218c2ecf20Sopenharmony_ci level->gen2PCIE = pi->pcie_gen2 ? 6228c2ecf20Sopenharmony_ci ((pl->flags & ATOM_PPLIB_R600_FLAGS_PCIEGEN2) ? 1 : 0) : 0; 6238c2ecf20Sopenharmony_ci level->gen2XSP = (pl->flags & ATOM_PPLIB_R600_FLAGS_PCIEGEN2) ? 1 : 0; 6248c2ecf20Sopenharmony_ci level->backbias = (pl->flags & ATOM_PPLIB_R600_FLAGS_BACKBIASENABLE) ? 1 : 0; 6258c2ecf20Sopenharmony_ci level->displayWatermark = watermark_level; 6268c2ecf20Sopenharmony_ci 6278c2ecf20Sopenharmony_ci if (rdev->family == CHIP_RV740) 6288c2ecf20Sopenharmony_ci ret = rv740_populate_sclk_value(rdev, pl->sclk, 6298c2ecf20Sopenharmony_ci &level->sclk); 6308c2ecf20Sopenharmony_ci else if ((rdev->family == CHIP_RV730) || (rdev->family == CHIP_RV710)) 6318c2ecf20Sopenharmony_ci ret = rv730_populate_sclk_value(rdev, pl->sclk, 6328c2ecf20Sopenharmony_ci &level->sclk); 6338c2ecf20Sopenharmony_ci else 6348c2ecf20Sopenharmony_ci ret = rv770_populate_sclk_value(rdev, pl->sclk, 6358c2ecf20Sopenharmony_ci &level->sclk); 6368c2ecf20Sopenharmony_ci if (ret) 6378c2ecf20Sopenharmony_ci return ret; 6388c2ecf20Sopenharmony_ci 6398c2ecf20Sopenharmony_ci if (rdev->family == CHIP_RV740) { 6408c2ecf20Sopenharmony_ci if (pi->mem_gddr5) { 6418c2ecf20Sopenharmony_ci if (pl->mclk <= pi->mclk_strobe_mode_threshold) 6428c2ecf20Sopenharmony_ci level->strobeMode = 6438c2ecf20Sopenharmony_ci rv740_get_mclk_frequency_ratio(pl->mclk) | 0x10; 6448c2ecf20Sopenharmony_ci else 6458c2ecf20Sopenharmony_ci level->strobeMode = 0; 6468c2ecf20Sopenharmony_ci 6478c2ecf20Sopenharmony_ci if (pl->mclk > pi->mclk_edc_enable_threshold) 6488c2ecf20Sopenharmony_ci level->mcFlags = SMC_MC_EDC_RD_FLAG | SMC_MC_EDC_WR_FLAG; 6498c2ecf20Sopenharmony_ci else 6508c2ecf20Sopenharmony_ci level->mcFlags = 0; 6518c2ecf20Sopenharmony_ci } 6528c2ecf20Sopenharmony_ci ret = rv740_populate_mclk_value(rdev, pl->sclk, 6538c2ecf20Sopenharmony_ci pl->mclk, &level->mclk); 6548c2ecf20Sopenharmony_ci } else if ((rdev->family == CHIP_RV730) || (rdev->family == CHIP_RV710)) 6558c2ecf20Sopenharmony_ci ret = rv730_populate_mclk_value(rdev, pl->sclk, 6568c2ecf20Sopenharmony_ci pl->mclk, &level->mclk); 6578c2ecf20Sopenharmony_ci else 6588c2ecf20Sopenharmony_ci ret = rv770_populate_mclk_value(rdev, pl->sclk, 6598c2ecf20Sopenharmony_ci pl->mclk, &level->mclk); 6608c2ecf20Sopenharmony_ci if (ret) 6618c2ecf20Sopenharmony_ci return ret; 6628c2ecf20Sopenharmony_ci 6638c2ecf20Sopenharmony_ci ret = rv770_populate_vddc_value(rdev, pl->vddc, 6648c2ecf20Sopenharmony_ci &level->vddc); 6658c2ecf20Sopenharmony_ci if (ret) 6668c2ecf20Sopenharmony_ci return ret; 6678c2ecf20Sopenharmony_ci 6688c2ecf20Sopenharmony_ci ret = rv770_populate_mvdd_value(rdev, pl->mclk, &level->mvdd); 6698c2ecf20Sopenharmony_ci 6708c2ecf20Sopenharmony_ci return ret; 6718c2ecf20Sopenharmony_ci} 6728c2ecf20Sopenharmony_ci 6738c2ecf20Sopenharmony_cistatic int rv770_convert_power_state_to_smc(struct radeon_device *rdev, 6748c2ecf20Sopenharmony_ci struct radeon_ps *radeon_state, 6758c2ecf20Sopenharmony_ci RV770_SMC_SWSTATE *smc_state) 6768c2ecf20Sopenharmony_ci{ 6778c2ecf20Sopenharmony_ci struct rv7xx_ps *state = rv770_get_ps(radeon_state); 6788c2ecf20Sopenharmony_ci int ret; 6798c2ecf20Sopenharmony_ci 6808c2ecf20Sopenharmony_ci if (!(radeon_state->caps & ATOM_PPLIB_DISALLOW_ON_DC)) 6818c2ecf20Sopenharmony_ci smc_state->flags |= PPSMC_SWSTATE_FLAG_DC; 6828c2ecf20Sopenharmony_ci 6838c2ecf20Sopenharmony_ci ret = rv770_convert_power_level_to_smc(rdev, 6848c2ecf20Sopenharmony_ci &state->low, 6858c2ecf20Sopenharmony_ci &smc_state->levels[0], 6868c2ecf20Sopenharmony_ci PPSMC_DISPLAY_WATERMARK_LOW); 6878c2ecf20Sopenharmony_ci if (ret) 6888c2ecf20Sopenharmony_ci return ret; 6898c2ecf20Sopenharmony_ci 6908c2ecf20Sopenharmony_ci ret = rv770_convert_power_level_to_smc(rdev, 6918c2ecf20Sopenharmony_ci &state->medium, 6928c2ecf20Sopenharmony_ci &smc_state->levels[1], 6938c2ecf20Sopenharmony_ci PPSMC_DISPLAY_WATERMARK_LOW); 6948c2ecf20Sopenharmony_ci if (ret) 6958c2ecf20Sopenharmony_ci return ret; 6968c2ecf20Sopenharmony_ci 6978c2ecf20Sopenharmony_ci ret = rv770_convert_power_level_to_smc(rdev, 6988c2ecf20Sopenharmony_ci &state->high, 6998c2ecf20Sopenharmony_ci &smc_state->levels[2], 7008c2ecf20Sopenharmony_ci PPSMC_DISPLAY_WATERMARK_HIGH); 7018c2ecf20Sopenharmony_ci if (ret) 7028c2ecf20Sopenharmony_ci return ret; 7038c2ecf20Sopenharmony_ci 7048c2ecf20Sopenharmony_ci smc_state->levels[0].arbValue = MC_CG_ARB_FREQ_F1; 7058c2ecf20Sopenharmony_ci smc_state->levels[1].arbValue = MC_CG_ARB_FREQ_F2; 7068c2ecf20Sopenharmony_ci smc_state->levels[2].arbValue = MC_CG_ARB_FREQ_F3; 7078c2ecf20Sopenharmony_ci 7088c2ecf20Sopenharmony_ci smc_state->levels[0].seqValue = rv770_get_seq_value(rdev, 7098c2ecf20Sopenharmony_ci &state->low); 7108c2ecf20Sopenharmony_ci smc_state->levels[1].seqValue = rv770_get_seq_value(rdev, 7118c2ecf20Sopenharmony_ci &state->medium); 7128c2ecf20Sopenharmony_ci smc_state->levels[2].seqValue = rv770_get_seq_value(rdev, 7138c2ecf20Sopenharmony_ci &state->high); 7148c2ecf20Sopenharmony_ci 7158c2ecf20Sopenharmony_ci rv770_populate_smc_sp(rdev, radeon_state, smc_state); 7168c2ecf20Sopenharmony_ci 7178c2ecf20Sopenharmony_ci return rv770_populate_smc_t(rdev, radeon_state, smc_state); 7188c2ecf20Sopenharmony_ci 7198c2ecf20Sopenharmony_ci} 7208c2ecf20Sopenharmony_ci 7218c2ecf20Sopenharmony_ciu32 rv770_calculate_memory_refresh_rate(struct radeon_device *rdev, 7228c2ecf20Sopenharmony_ci u32 engine_clock) 7238c2ecf20Sopenharmony_ci{ 7248c2ecf20Sopenharmony_ci u32 dram_rows; 7258c2ecf20Sopenharmony_ci u32 dram_refresh_rate; 7268c2ecf20Sopenharmony_ci u32 mc_arb_rfsh_rate; 7278c2ecf20Sopenharmony_ci u32 tmp; 7288c2ecf20Sopenharmony_ci 7298c2ecf20Sopenharmony_ci tmp = (RREG32(MC_ARB_RAMCFG) & NOOFROWS_MASK) >> NOOFROWS_SHIFT; 7308c2ecf20Sopenharmony_ci dram_rows = 1 << (tmp + 10); 7318c2ecf20Sopenharmony_ci tmp = RREG32(MC_SEQ_MISC0) & 3; 7328c2ecf20Sopenharmony_ci dram_refresh_rate = 1 << (tmp + 3); 7338c2ecf20Sopenharmony_ci mc_arb_rfsh_rate = ((engine_clock * 10) * dram_refresh_rate / dram_rows - 32) / 64; 7348c2ecf20Sopenharmony_ci 7358c2ecf20Sopenharmony_ci return mc_arb_rfsh_rate; 7368c2ecf20Sopenharmony_ci} 7378c2ecf20Sopenharmony_ci 7388c2ecf20Sopenharmony_cistatic void rv770_program_memory_timing_parameters(struct radeon_device *rdev, 7398c2ecf20Sopenharmony_ci struct radeon_ps *radeon_state) 7408c2ecf20Sopenharmony_ci{ 7418c2ecf20Sopenharmony_ci struct rv7xx_ps *state = rv770_get_ps(radeon_state); 7428c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 7438c2ecf20Sopenharmony_ci u32 sqm_ratio; 7448c2ecf20Sopenharmony_ci u32 arb_refresh_rate; 7458c2ecf20Sopenharmony_ci u32 high_clock; 7468c2ecf20Sopenharmony_ci 7478c2ecf20Sopenharmony_ci if (state->high.sclk < (state->low.sclk * 0xFF / 0x40)) 7488c2ecf20Sopenharmony_ci high_clock = state->high.sclk; 7498c2ecf20Sopenharmony_ci else 7508c2ecf20Sopenharmony_ci high_clock = (state->low.sclk * 0xFF / 0x40); 7518c2ecf20Sopenharmony_ci 7528c2ecf20Sopenharmony_ci radeon_atom_set_engine_dram_timings(rdev, high_clock, 7538c2ecf20Sopenharmony_ci state->high.mclk); 7548c2ecf20Sopenharmony_ci 7558c2ecf20Sopenharmony_ci sqm_ratio = 7568c2ecf20Sopenharmony_ci STATE0(64 * high_clock / pi->boot_sclk) | 7578c2ecf20Sopenharmony_ci STATE1(64 * high_clock / state->low.sclk) | 7588c2ecf20Sopenharmony_ci STATE2(64 * high_clock / state->medium.sclk) | 7598c2ecf20Sopenharmony_ci STATE3(64 * high_clock / state->high.sclk); 7608c2ecf20Sopenharmony_ci WREG32(MC_ARB_SQM_RATIO, sqm_ratio); 7618c2ecf20Sopenharmony_ci 7628c2ecf20Sopenharmony_ci arb_refresh_rate = 7638c2ecf20Sopenharmony_ci POWERMODE0(rv770_calculate_memory_refresh_rate(rdev, pi->boot_sclk)) | 7648c2ecf20Sopenharmony_ci POWERMODE1(rv770_calculate_memory_refresh_rate(rdev, state->low.sclk)) | 7658c2ecf20Sopenharmony_ci POWERMODE2(rv770_calculate_memory_refresh_rate(rdev, state->medium.sclk)) | 7668c2ecf20Sopenharmony_ci POWERMODE3(rv770_calculate_memory_refresh_rate(rdev, state->high.sclk)); 7678c2ecf20Sopenharmony_ci WREG32(MC_ARB_RFSH_RATE, arb_refresh_rate); 7688c2ecf20Sopenharmony_ci} 7698c2ecf20Sopenharmony_ci 7708c2ecf20Sopenharmony_civoid rv770_enable_backbias(struct radeon_device *rdev, 7718c2ecf20Sopenharmony_ci bool enable) 7728c2ecf20Sopenharmony_ci{ 7738c2ecf20Sopenharmony_ci if (enable) 7748c2ecf20Sopenharmony_ci WREG32_P(GENERAL_PWRMGT, BACKBIAS_PAD_EN, ~BACKBIAS_PAD_EN); 7758c2ecf20Sopenharmony_ci else 7768c2ecf20Sopenharmony_ci WREG32_P(GENERAL_PWRMGT, 0, ~(BACKBIAS_VALUE | BACKBIAS_PAD_EN)); 7778c2ecf20Sopenharmony_ci} 7788c2ecf20Sopenharmony_ci 7798c2ecf20Sopenharmony_cistatic void rv770_enable_spread_spectrum(struct radeon_device *rdev, 7808c2ecf20Sopenharmony_ci bool enable) 7818c2ecf20Sopenharmony_ci{ 7828c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 7838c2ecf20Sopenharmony_ci 7848c2ecf20Sopenharmony_ci if (enable) { 7858c2ecf20Sopenharmony_ci if (pi->sclk_ss) 7868c2ecf20Sopenharmony_ci WREG32_P(GENERAL_PWRMGT, DYN_SPREAD_SPECTRUM_EN, ~DYN_SPREAD_SPECTRUM_EN); 7878c2ecf20Sopenharmony_ci 7888c2ecf20Sopenharmony_ci if (pi->mclk_ss) { 7898c2ecf20Sopenharmony_ci if (rdev->family == CHIP_RV740) 7908c2ecf20Sopenharmony_ci rv740_enable_mclk_spread_spectrum(rdev, true); 7918c2ecf20Sopenharmony_ci } 7928c2ecf20Sopenharmony_ci } else { 7938c2ecf20Sopenharmony_ci WREG32_P(CG_SPLL_SPREAD_SPECTRUM, 0, ~SSEN); 7948c2ecf20Sopenharmony_ci 7958c2ecf20Sopenharmony_ci WREG32_P(GENERAL_PWRMGT, 0, ~DYN_SPREAD_SPECTRUM_EN); 7968c2ecf20Sopenharmony_ci 7978c2ecf20Sopenharmony_ci WREG32_P(CG_MPLL_SPREAD_SPECTRUM, 0, ~SSEN); 7988c2ecf20Sopenharmony_ci 7998c2ecf20Sopenharmony_ci if (rdev->family == CHIP_RV740) 8008c2ecf20Sopenharmony_ci rv740_enable_mclk_spread_spectrum(rdev, false); 8018c2ecf20Sopenharmony_ci } 8028c2ecf20Sopenharmony_ci} 8038c2ecf20Sopenharmony_ci 8048c2ecf20Sopenharmony_cistatic void rv770_program_mpll_timing_parameters(struct radeon_device *rdev) 8058c2ecf20Sopenharmony_ci{ 8068c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 8078c2ecf20Sopenharmony_ci 8088c2ecf20Sopenharmony_ci if ((rdev->family == CHIP_RV770) && !pi->mem_gddr5) { 8098c2ecf20Sopenharmony_ci WREG32(MPLL_TIME, 8108c2ecf20Sopenharmony_ci (MPLL_LOCK_TIME(R600_MPLLLOCKTIME_DFLT * pi->ref_div) | 8118c2ecf20Sopenharmony_ci MPLL_RESET_TIME(R600_MPLLRESETTIME_DFLT))); 8128c2ecf20Sopenharmony_ci } 8138c2ecf20Sopenharmony_ci} 8148c2ecf20Sopenharmony_ci 8158c2ecf20Sopenharmony_civoid rv770_setup_bsp(struct radeon_device *rdev) 8168c2ecf20Sopenharmony_ci{ 8178c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 8188c2ecf20Sopenharmony_ci u32 xclk = radeon_get_xclk(rdev); 8198c2ecf20Sopenharmony_ci 8208c2ecf20Sopenharmony_ci r600_calculate_u_and_p(pi->asi, 8218c2ecf20Sopenharmony_ci xclk, 8228c2ecf20Sopenharmony_ci 16, 8238c2ecf20Sopenharmony_ci &pi->bsp, 8248c2ecf20Sopenharmony_ci &pi->bsu); 8258c2ecf20Sopenharmony_ci 8268c2ecf20Sopenharmony_ci r600_calculate_u_and_p(pi->pasi, 8278c2ecf20Sopenharmony_ci xclk, 8288c2ecf20Sopenharmony_ci 16, 8298c2ecf20Sopenharmony_ci &pi->pbsp, 8308c2ecf20Sopenharmony_ci &pi->pbsu); 8318c2ecf20Sopenharmony_ci 8328c2ecf20Sopenharmony_ci pi->dsp = BSP(pi->bsp) | BSU(pi->bsu); 8338c2ecf20Sopenharmony_ci pi->psp = BSP(pi->pbsp) | BSU(pi->pbsu); 8348c2ecf20Sopenharmony_ci 8358c2ecf20Sopenharmony_ci WREG32(CG_BSP, pi->dsp); 8368c2ecf20Sopenharmony_ci 8378c2ecf20Sopenharmony_ci} 8388c2ecf20Sopenharmony_ci 8398c2ecf20Sopenharmony_civoid rv770_program_git(struct radeon_device *rdev) 8408c2ecf20Sopenharmony_ci{ 8418c2ecf20Sopenharmony_ci WREG32_P(CG_GIT, CG_GICST(R600_GICST_DFLT), ~CG_GICST_MASK); 8428c2ecf20Sopenharmony_ci} 8438c2ecf20Sopenharmony_ci 8448c2ecf20Sopenharmony_civoid rv770_program_tp(struct radeon_device *rdev) 8458c2ecf20Sopenharmony_ci{ 8468c2ecf20Sopenharmony_ci int i; 8478c2ecf20Sopenharmony_ci enum r600_td td = R600_TD_DFLT; 8488c2ecf20Sopenharmony_ci 8498c2ecf20Sopenharmony_ci for (i = 0; i < R600_PM_NUMBER_OF_TC; i++) 8508c2ecf20Sopenharmony_ci WREG32(CG_FFCT_0 + (i * 4), (UTC_0(r600_utc[i]) | DTC_0(r600_dtc[i]))); 8518c2ecf20Sopenharmony_ci 8528c2ecf20Sopenharmony_ci if (td == R600_TD_AUTO) 8538c2ecf20Sopenharmony_ci WREG32_P(SCLK_PWRMGT_CNTL, 0, ~FIR_FORCE_TREND_SEL); 8548c2ecf20Sopenharmony_ci else 8558c2ecf20Sopenharmony_ci WREG32_P(SCLK_PWRMGT_CNTL, FIR_FORCE_TREND_SEL, ~FIR_FORCE_TREND_SEL); 8568c2ecf20Sopenharmony_ci if (td == R600_TD_UP) 8578c2ecf20Sopenharmony_ci WREG32_P(SCLK_PWRMGT_CNTL, 0, ~FIR_TREND_MODE); 8588c2ecf20Sopenharmony_ci if (td == R600_TD_DOWN) 8598c2ecf20Sopenharmony_ci WREG32_P(SCLK_PWRMGT_CNTL, FIR_TREND_MODE, ~FIR_TREND_MODE); 8608c2ecf20Sopenharmony_ci} 8618c2ecf20Sopenharmony_ci 8628c2ecf20Sopenharmony_civoid rv770_program_tpp(struct radeon_device *rdev) 8638c2ecf20Sopenharmony_ci{ 8648c2ecf20Sopenharmony_ci WREG32(CG_TPC, R600_TPC_DFLT); 8658c2ecf20Sopenharmony_ci} 8668c2ecf20Sopenharmony_ci 8678c2ecf20Sopenharmony_civoid rv770_program_sstp(struct radeon_device *rdev) 8688c2ecf20Sopenharmony_ci{ 8698c2ecf20Sopenharmony_ci WREG32(CG_SSP, (SSTU(R600_SSTU_DFLT) | SST(R600_SST_DFLT))); 8708c2ecf20Sopenharmony_ci} 8718c2ecf20Sopenharmony_ci 8728c2ecf20Sopenharmony_civoid rv770_program_engine_speed_parameters(struct radeon_device *rdev) 8738c2ecf20Sopenharmony_ci{ 8748c2ecf20Sopenharmony_ci WREG32_P(SPLL_CNTL_MODE, SPLL_DIV_SYNC, ~SPLL_DIV_SYNC); 8758c2ecf20Sopenharmony_ci} 8768c2ecf20Sopenharmony_ci 8778c2ecf20Sopenharmony_cistatic void rv770_enable_display_gap(struct radeon_device *rdev) 8788c2ecf20Sopenharmony_ci{ 8798c2ecf20Sopenharmony_ci u32 tmp = RREG32(CG_DISPLAY_GAP_CNTL); 8808c2ecf20Sopenharmony_ci 8818c2ecf20Sopenharmony_ci tmp &= ~(DISP1_GAP_MCHG_MASK | DISP2_GAP_MCHG_MASK); 8828c2ecf20Sopenharmony_ci tmp |= (DISP1_GAP_MCHG(R600_PM_DISPLAY_GAP_IGNORE) | 8838c2ecf20Sopenharmony_ci DISP2_GAP_MCHG(R600_PM_DISPLAY_GAP_IGNORE)); 8848c2ecf20Sopenharmony_ci WREG32(CG_DISPLAY_GAP_CNTL, tmp); 8858c2ecf20Sopenharmony_ci} 8868c2ecf20Sopenharmony_ci 8878c2ecf20Sopenharmony_civoid rv770_program_vc(struct radeon_device *rdev) 8888c2ecf20Sopenharmony_ci{ 8898c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 8908c2ecf20Sopenharmony_ci 8918c2ecf20Sopenharmony_ci WREG32(CG_FTV, pi->vrc); 8928c2ecf20Sopenharmony_ci} 8938c2ecf20Sopenharmony_ci 8948c2ecf20Sopenharmony_civoid rv770_clear_vc(struct radeon_device *rdev) 8958c2ecf20Sopenharmony_ci{ 8968c2ecf20Sopenharmony_ci WREG32(CG_FTV, 0); 8978c2ecf20Sopenharmony_ci} 8988c2ecf20Sopenharmony_ci 8998c2ecf20Sopenharmony_ciint rv770_upload_firmware(struct radeon_device *rdev) 9008c2ecf20Sopenharmony_ci{ 9018c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 9028c2ecf20Sopenharmony_ci int ret; 9038c2ecf20Sopenharmony_ci 9048c2ecf20Sopenharmony_ci rv770_reset_smc(rdev); 9058c2ecf20Sopenharmony_ci rv770_stop_smc_clock(rdev); 9068c2ecf20Sopenharmony_ci 9078c2ecf20Sopenharmony_ci ret = rv770_load_smc_ucode(rdev, pi->sram_end); 9088c2ecf20Sopenharmony_ci if (ret) 9098c2ecf20Sopenharmony_ci return ret; 9108c2ecf20Sopenharmony_ci 9118c2ecf20Sopenharmony_ci return 0; 9128c2ecf20Sopenharmony_ci} 9138c2ecf20Sopenharmony_ci 9148c2ecf20Sopenharmony_cistatic int rv770_populate_smc_acpi_state(struct radeon_device *rdev, 9158c2ecf20Sopenharmony_ci RV770_SMC_STATETABLE *table) 9168c2ecf20Sopenharmony_ci{ 9178c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 9188c2ecf20Sopenharmony_ci 9198c2ecf20Sopenharmony_ci u32 mpll_ad_func_cntl = 9208c2ecf20Sopenharmony_ci pi->clk_regs.rv770.mpll_ad_func_cntl; 9218c2ecf20Sopenharmony_ci u32 mpll_ad_func_cntl_2 = 9228c2ecf20Sopenharmony_ci pi->clk_regs.rv770.mpll_ad_func_cntl_2; 9238c2ecf20Sopenharmony_ci u32 mpll_dq_func_cntl = 9248c2ecf20Sopenharmony_ci pi->clk_regs.rv770.mpll_dq_func_cntl; 9258c2ecf20Sopenharmony_ci u32 mpll_dq_func_cntl_2 = 9268c2ecf20Sopenharmony_ci pi->clk_regs.rv770.mpll_dq_func_cntl_2; 9278c2ecf20Sopenharmony_ci u32 spll_func_cntl = 9288c2ecf20Sopenharmony_ci pi->clk_regs.rv770.cg_spll_func_cntl; 9298c2ecf20Sopenharmony_ci u32 spll_func_cntl_2 = 9308c2ecf20Sopenharmony_ci pi->clk_regs.rv770.cg_spll_func_cntl_2; 9318c2ecf20Sopenharmony_ci u32 spll_func_cntl_3 = 9328c2ecf20Sopenharmony_ci pi->clk_regs.rv770.cg_spll_func_cntl_3; 9338c2ecf20Sopenharmony_ci u32 mclk_pwrmgt_cntl; 9348c2ecf20Sopenharmony_ci u32 dll_cntl; 9358c2ecf20Sopenharmony_ci 9368c2ecf20Sopenharmony_ci table->ACPIState = table->initialState; 9378c2ecf20Sopenharmony_ci 9388c2ecf20Sopenharmony_ci table->ACPIState.flags &= ~PPSMC_SWSTATE_FLAG_DC; 9398c2ecf20Sopenharmony_ci 9408c2ecf20Sopenharmony_ci if (pi->acpi_vddc) { 9418c2ecf20Sopenharmony_ci rv770_populate_vddc_value(rdev, pi->acpi_vddc, 9428c2ecf20Sopenharmony_ci &table->ACPIState.levels[0].vddc); 9438c2ecf20Sopenharmony_ci if (pi->pcie_gen2) { 9448c2ecf20Sopenharmony_ci if (pi->acpi_pcie_gen2) 9458c2ecf20Sopenharmony_ci table->ACPIState.levels[0].gen2PCIE = 1; 9468c2ecf20Sopenharmony_ci else 9478c2ecf20Sopenharmony_ci table->ACPIState.levels[0].gen2PCIE = 0; 9488c2ecf20Sopenharmony_ci } else 9498c2ecf20Sopenharmony_ci table->ACPIState.levels[0].gen2PCIE = 0; 9508c2ecf20Sopenharmony_ci if (pi->acpi_pcie_gen2) 9518c2ecf20Sopenharmony_ci table->ACPIState.levels[0].gen2XSP = 1; 9528c2ecf20Sopenharmony_ci else 9538c2ecf20Sopenharmony_ci table->ACPIState.levels[0].gen2XSP = 0; 9548c2ecf20Sopenharmony_ci } else { 9558c2ecf20Sopenharmony_ci rv770_populate_vddc_value(rdev, pi->min_vddc_in_table, 9568c2ecf20Sopenharmony_ci &table->ACPIState.levels[0].vddc); 9578c2ecf20Sopenharmony_ci table->ACPIState.levels[0].gen2PCIE = 0; 9588c2ecf20Sopenharmony_ci } 9598c2ecf20Sopenharmony_ci 9608c2ecf20Sopenharmony_ci 9618c2ecf20Sopenharmony_ci mpll_ad_func_cntl_2 |= BIAS_GEN_PDNB | RESET_EN; 9628c2ecf20Sopenharmony_ci 9638c2ecf20Sopenharmony_ci mpll_dq_func_cntl_2 |= BIAS_GEN_PDNB | RESET_EN; 9648c2ecf20Sopenharmony_ci 9658c2ecf20Sopenharmony_ci mclk_pwrmgt_cntl = (MRDCKA0_RESET | 9668c2ecf20Sopenharmony_ci MRDCKA1_RESET | 9678c2ecf20Sopenharmony_ci MRDCKB0_RESET | 9688c2ecf20Sopenharmony_ci MRDCKB1_RESET | 9698c2ecf20Sopenharmony_ci MRDCKC0_RESET | 9708c2ecf20Sopenharmony_ci MRDCKC1_RESET | 9718c2ecf20Sopenharmony_ci MRDCKD0_RESET | 9728c2ecf20Sopenharmony_ci MRDCKD1_RESET); 9738c2ecf20Sopenharmony_ci 9748c2ecf20Sopenharmony_ci dll_cntl = 0xff000000; 9758c2ecf20Sopenharmony_ci 9768c2ecf20Sopenharmony_ci spll_func_cntl |= SPLL_RESET | SPLL_SLEEP | SPLL_BYPASS_EN; 9778c2ecf20Sopenharmony_ci 9788c2ecf20Sopenharmony_ci spll_func_cntl_2 &= ~SCLK_MUX_SEL_MASK; 9798c2ecf20Sopenharmony_ci spll_func_cntl_2 |= SCLK_MUX_SEL(4); 9808c2ecf20Sopenharmony_ci 9818c2ecf20Sopenharmony_ci table->ACPIState.levels[0].mclk.mclk770.vMPLL_AD_FUNC_CNTL = cpu_to_be32(mpll_ad_func_cntl); 9828c2ecf20Sopenharmony_ci table->ACPIState.levels[0].mclk.mclk770.vMPLL_AD_FUNC_CNTL_2 = cpu_to_be32(mpll_ad_func_cntl_2); 9838c2ecf20Sopenharmony_ci table->ACPIState.levels[0].mclk.mclk770.vMPLL_DQ_FUNC_CNTL = cpu_to_be32(mpll_dq_func_cntl); 9848c2ecf20Sopenharmony_ci table->ACPIState.levels[0].mclk.mclk770.vMPLL_DQ_FUNC_CNTL_2 = cpu_to_be32(mpll_dq_func_cntl_2); 9858c2ecf20Sopenharmony_ci 9868c2ecf20Sopenharmony_ci table->ACPIState.levels[0].mclk.mclk770.vMCLK_PWRMGT_CNTL = cpu_to_be32(mclk_pwrmgt_cntl); 9878c2ecf20Sopenharmony_ci table->ACPIState.levels[0].mclk.mclk770.vDLL_CNTL = cpu_to_be32(dll_cntl); 9888c2ecf20Sopenharmony_ci 9898c2ecf20Sopenharmony_ci table->ACPIState.levels[0].mclk.mclk770.mclk_value = 0; 9908c2ecf20Sopenharmony_ci 9918c2ecf20Sopenharmony_ci table->ACPIState.levels[0].sclk.vCG_SPLL_FUNC_CNTL = cpu_to_be32(spll_func_cntl); 9928c2ecf20Sopenharmony_ci table->ACPIState.levels[0].sclk.vCG_SPLL_FUNC_CNTL_2 = cpu_to_be32(spll_func_cntl_2); 9938c2ecf20Sopenharmony_ci table->ACPIState.levels[0].sclk.vCG_SPLL_FUNC_CNTL_3 = cpu_to_be32(spll_func_cntl_3); 9948c2ecf20Sopenharmony_ci 9958c2ecf20Sopenharmony_ci table->ACPIState.levels[0].sclk.sclk_value = 0; 9968c2ecf20Sopenharmony_ci 9978c2ecf20Sopenharmony_ci rv770_populate_mvdd_value(rdev, 0, &table->ACPIState.levels[0].mvdd); 9988c2ecf20Sopenharmony_ci 9998c2ecf20Sopenharmony_ci table->ACPIState.levels[1] = table->ACPIState.levels[0]; 10008c2ecf20Sopenharmony_ci table->ACPIState.levels[2] = table->ACPIState.levels[0]; 10018c2ecf20Sopenharmony_ci 10028c2ecf20Sopenharmony_ci return 0; 10038c2ecf20Sopenharmony_ci} 10048c2ecf20Sopenharmony_ci 10058c2ecf20Sopenharmony_ciint rv770_populate_initial_mvdd_value(struct radeon_device *rdev, 10068c2ecf20Sopenharmony_ci RV770_SMC_VOLTAGE_VALUE *voltage) 10078c2ecf20Sopenharmony_ci{ 10088c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 10098c2ecf20Sopenharmony_ci 10108c2ecf20Sopenharmony_ci if ((pi->s0_vid_lower_smio_cntl & pi->mvdd_mask_low) == 10118c2ecf20Sopenharmony_ci (pi->mvdd_low_smio[MVDD_LOW_INDEX] & pi->mvdd_mask_low) ) { 10128c2ecf20Sopenharmony_ci voltage->index = MVDD_LOW_INDEX; 10138c2ecf20Sopenharmony_ci voltage->value = cpu_to_be16(MVDD_LOW_VALUE); 10148c2ecf20Sopenharmony_ci } else { 10158c2ecf20Sopenharmony_ci voltage->index = MVDD_HIGH_INDEX; 10168c2ecf20Sopenharmony_ci voltage->value = cpu_to_be16(MVDD_HIGH_VALUE); 10178c2ecf20Sopenharmony_ci } 10188c2ecf20Sopenharmony_ci 10198c2ecf20Sopenharmony_ci return 0; 10208c2ecf20Sopenharmony_ci} 10218c2ecf20Sopenharmony_ci 10228c2ecf20Sopenharmony_cistatic int rv770_populate_smc_initial_state(struct radeon_device *rdev, 10238c2ecf20Sopenharmony_ci struct radeon_ps *radeon_state, 10248c2ecf20Sopenharmony_ci RV770_SMC_STATETABLE *table) 10258c2ecf20Sopenharmony_ci{ 10268c2ecf20Sopenharmony_ci struct rv7xx_ps *initial_state = rv770_get_ps(radeon_state); 10278c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 10288c2ecf20Sopenharmony_ci u32 a_t; 10298c2ecf20Sopenharmony_ci 10308c2ecf20Sopenharmony_ci table->initialState.levels[0].mclk.mclk770.vMPLL_AD_FUNC_CNTL = 10318c2ecf20Sopenharmony_ci cpu_to_be32(pi->clk_regs.rv770.mpll_ad_func_cntl); 10328c2ecf20Sopenharmony_ci table->initialState.levels[0].mclk.mclk770.vMPLL_AD_FUNC_CNTL_2 = 10338c2ecf20Sopenharmony_ci cpu_to_be32(pi->clk_regs.rv770.mpll_ad_func_cntl_2); 10348c2ecf20Sopenharmony_ci table->initialState.levels[0].mclk.mclk770.vMPLL_DQ_FUNC_CNTL = 10358c2ecf20Sopenharmony_ci cpu_to_be32(pi->clk_regs.rv770.mpll_dq_func_cntl); 10368c2ecf20Sopenharmony_ci table->initialState.levels[0].mclk.mclk770.vMPLL_DQ_FUNC_CNTL_2 = 10378c2ecf20Sopenharmony_ci cpu_to_be32(pi->clk_regs.rv770.mpll_dq_func_cntl_2); 10388c2ecf20Sopenharmony_ci table->initialState.levels[0].mclk.mclk770.vMCLK_PWRMGT_CNTL = 10398c2ecf20Sopenharmony_ci cpu_to_be32(pi->clk_regs.rv770.mclk_pwrmgt_cntl); 10408c2ecf20Sopenharmony_ci table->initialState.levels[0].mclk.mclk770.vDLL_CNTL = 10418c2ecf20Sopenharmony_ci cpu_to_be32(pi->clk_regs.rv770.dll_cntl); 10428c2ecf20Sopenharmony_ci 10438c2ecf20Sopenharmony_ci table->initialState.levels[0].mclk.mclk770.vMPLL_SS = 10448c2ecf20Sopenharmony_ci cpu_to_be32(pi->clk_regs.rv770.mpll_ss1); 10458c2ecf20Sopenharmony_ci table->initialState.levels[0].mclk.mclk770.vMPLL_SS2 = 10468c2ecf20Sopenharmony_ci cpu_to_be32(pi->clk_regs.rv770.mpll_ss2); 10478c2ecf20Sopenharmony_ci 10488c2ecf20Sopenharmony_ci table->initialState.levels[0].mclk.mclk770.mclk_value = 10498c2ecf20Sopenharmony_ci cpu_to_be32(initial_state->low.mclk); 10508c2ecf20Sopenharmony_ci 10518c2ecf20Sopenharmony_ci table->initialState.levels[0].sclk.vCG_SPLL_FUNC_CNTL = 10528c2ecf20Sopenharmony_ci cpu_to_be32(pi->clk_regs.rv770.cg_spll_func_cntl); 10538c2ecf20Sopenharmony_ci table->initialState.levels[0].sclk.vCG_SPLL_FUNC_CNTL_2 = 10548c2ecf20Sopenharmony_ci cpu_to_be32(pi->clk_regs.rv770.cg_spll_func_cntl_2); 10558c2ecf20Sopenharmony_ci table->initialState.levels[0].sclk.vCG_SPLL_FUNC_CNTL_3 = 10568c2ecf20Sopenharmony_ci cpu_to_be32(pi->clk_regs.rv770.cg_spll_func_cntl_3); 10578c2ecf20Sopenharmony_ci table->initialState.levels[0].sclk.vCG_SPLL_SPREAD_SPECTRUM = 10588c2ecf20Sopenharmony_ci cpu_to_be32(pi->clk_regs.rv770.cg_spll_spread_spectrum); 10598c2ecf20Sopenharmony_ci table->initialState.levels[0].sclk.vCG_SPLL_SPREAD_SPECTRUM_2 = 10608c2ecf20Sopenharmony_ci cpu_to_be32(pi->clk_regs.rv770.cg_spll_spread_spectrum_2); 10618c2ecf20Sopenharmony_ci 10628c2ecf20Sopenharmony_ci table->initialState.levels[0].sclk.sclk_value = 10638c2ecf20Sopenharmony_ci cpu_to_be32(initial_state->low.sclk); 10648c2ecf20Sopenharmony_ci 10658c2ecf20Sopenharmony_ci table->initialState.levels[0].arbValue = MC_CG_ARB_FREQ_F0; 10668c2ecf20Sopenharmony_ci 10678c2ecf20Sopenharmony_ci table->initialState.levels[0].seqValue = 10688c2ecf20Sopenharmony_ci rv770_get_seq_value(rdev, &initial_state->low); 10698c2ecf20Sopenharmony_ci 10708c2ecf20Sopenharmony_ci rv770_populate_vddc_value(rdev, 10718c2ecf20Sopenharmony_ci initial_state->low.vddc, 10728c2ecf20Sopenharmony_ci &table->initialState.levels[0].vddc); 10738c2ecf20Sopenharmony_ci rv770_populate_initial_mvdd_value(rdev, 10748c2ecf20Sopenharmony_ci &table->initialState.levels[0].mvdd); 10758c2ecf20Sopenharmony_ci 10768c2ecf20Sopenharmony_ci a_t = CG_R(0xffff) | CG_L(0); 10778c2ecf20Sopenharmony_ci table->initialState.levels[0].aT = cpu_to_be32(a_t); 10788c2ecf20Sopenharmony_ci 10798c2ecf20Sopenharmony_ci table->initialState.levels[0].bSP = cpu_to_be32(pi->dsp); 10808c2ecf20Sopenharmony_ci 10818c2ecf20Sopenharmony_ci if (pi->boot_in_gen2) 10828c2ecf20Sopenharmony_ci table->initialState.levels[0].gen2PCIE = 1; 10838c2ecf20Sopenharmony_ci else 10848c2ecf20Sopenharmony_ci table->initialState.levels[0].gen2PCIE = 0; 10858c2ecf20Sopenharmony_ci if (initial_state->low.flags & ATOM_PPLIB_R600_FLAGS_PCIEGEN2) 10868c2ecf20Sopenharmony_ci table->initialState.levels[0].gen2XSP = 1; 10878c2ecf20Sopenharmony_ci else 10888c2ecf20Sopenharmony_ci table->initialState.levels[0].gen2XSP = 0; 10898c2ecf20Sopenharmony_ci 10908c2ecf20Sopenharmony_ci if (rdev->family == CHIP_RV740) { 10918c2ecf20Sopenharmony_ci if (pi->mem_gddr5) { 10928c2ecf20Sopenharmony_ci if (initial_state->low.mclk <= pi->mclk_strobe_mode_threshold) 10938c2ecf20Sopenharmony_ci table->initialState.levels[0].strobeMode = 10948c2ecf20Sopenharmony_ci rv740_get_mclk_frequency_ratio(initial_state->low.mclk) | 0x10; 10958c2ecf20Sopenharmony_ci else 10968c2ecf20Sopenharmony_ci table->initialState.levels[0].strobeMode = 0; 10978c2ecf20Sopenharmony_ci 10988c2ecf20Sopenharmony_ci if (initial_state->low.mclk >= pi->mclk_edc_enable_threshold) 10998c2ecf20Sopenharmony_ci table->initialState.levels[0].mcFlags = SMC_MC_EDC_RD_FLAG | SMC_MC_EDC_WR_FLAG; 11008c2ecf20Sopenharmony_ci else 11018c2ecf20Sopenharmony_ci table->initialState.levels[0].mcFlags = 0; 11028c2ecf20Sopenharmony_ci } 11038c2ecf20Sopenharmony_ci } 11048c2ecf20Sopenharmony_ci 11058c2ecf20Sopenharmony_ci table->initialState.levels[1] = table->initialState.levels[0]; 11068c2ecf20Sopenharmony_ci table->initialState.levels[2] = table->initialState.levels[0]; 11078c2ecf20Sopenharmony_ci 11088c2ecf20Sopenharmony_ci table->initialState.flags |= PPSMC_SWSTATE_FLAG_DC; 11098c2ecf20Sopenharmony_ci 11108c2ecf20Sopenharmony_ci return 0; 11118c2ecf20Sopenharmony_ci} 11128c2ecf20Sopenharmony_ci 11138c2ecf20Sopenharmony_cistatic int rv770_populate_smc_vddc_table(struct radeon_device *rdev, 11148c2ecf20Sopenharmony_ci RV770_SMC_STATETABLE *table) 11158c2ecf20Sopenharmony_ci{ 11168c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 11178c2ecf20Sopenharmony_ci int i; 11188c2ecf20Sopenharmony_ci 11198c2ecf20Sopenharmony_ci for (i = 0; i < pi->valid_vddc_entries; i++) { 11208c2ecf20Sopenharmony_ci table->highSMIO[pi->vddc_table[i].vddc_index] = 11218c2ecf20Sopenharmony_ci pi->vddc_table[i].high_smio; 11228c2ecf20Sopenharmony_ci table->lowSMIO[pi->vddc_table[i].vddc_index] = 11238c2ecf20Sopenharmony_ci cpu_to_be32(pi->vddc_table[i].low_smio); 11248c2ecf20Sopenharmony_ci } 11258c2ecf20Sopenharmony_ci 11268c2ecf20Sopenharmony_ci table->voltageMaskTable.highMask[RV770_SMC_VOLTAGEMASK_VDDC] = 0; 11278c2ecf20Sopenharmony_ci table->voltageMaskTable.lowMask[RV770_SMC_VOLTAGEMASK_VDDC] = 11288c2ecf20Sopenharmony_ci cpu_to_be32(pi->vddc_mask_low); 11298c2ecf20Sopenharmony_ci 11308c2ecf20Sopenharmony_ci for (i = 0; 11318c2ecf20Sopenharmony_ci ((i < pi->valid_vddc_entries) && 11328c2ecf20Sopenharmony_ci (pi->max_vddc_in_table > 11338c2ecf20Sopenharmony_ci pi->vddc_table[i].vddc)); 11348c2ecf20Sopenharmony_ci i++); 11358c2ecf20Sopenharmony_ci 11368c2ecf20Sopenharmony_ci table->maxVDDCIndexInPPTable = 11378c2ecf20Sopenharmony_ci pi->vddc_table[i].vddc_index; 11388c2ecf20Sopenharmony_ci 11398c2ecf20Sopenharmony_ci return 0; 11408c2ecf20Sopenharmony_ci} 11418c2ecf20Sopenharmony_ci 11428c2ecf20Sopenharmony_cistatic int rv770_populate_smc_mvdd_table(struct radeon_device *rdev, 11438c2ecf20Sopenharmony_ci RV770_SMC_STATETABLE *table) 11448c2ecf20Sopenharmony_ci{ 11458c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 11468c2ecf20Sopenharmony_ci 11478c2ecf20Sopenharmony_ci if (pi->mvdd_control) { 11488c2ecf20Sopenharmony_ci table->lowSMIO[MVDD_HIGH_INDEX] |= 11498c2ecf20Sopenharmony_ci cpu_to_be32(pi->mvdd_low_smio[MVDD_HIGH_INDEX]); 11508c2ecf20Sopenharmony_ci table->lowSMIO[MVDD_LOW_INDEX] |= 11518c2ecf20Sopenharmony_ci cpu_to_be32(pi->mvdd_low_smio[MVDD_LOW_INDEX]); 11528c2ecf20Sopenharmony_ci 11538c2ecf20Sopenharmony_ci table->voltageMaskTable.highMask[RV770_SMC_VOLTAGEMASK_MVDD] = 0; 11548c2ecf20Sopenharmony_ci table->voltageMaskTable.lowMask[RV770_SMC_VOLTAGEMASK_MVDD] = 11558c2ecf20Sopenharmony_ci cpu_to_be32(pi->mvdd_mask_low); 11568c2ecf20Sopenharmony_ci } 11578c2ecf20Sopenharmony_ci 11588c2ecf20Sopenharmony_ci return 0; 11598c2ecf20Sopenharmony_ci} 11608c2ecf20Sopenharmony_ci 11618c2ecf20Sopenharmony_cistatic int rv770_init_smc_table(struct radeon_device *rdev, 11628c2ecf20Sopenharmony_ci struct radeon_ps *radeon_boot_state) 11638c2ecf20Sopenharmony_ci{ 11648c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 11658c2ecf20Sopenharmony_ci struct rv7xx_ps *boot_state = rv770_get_ps(radeon_boot_state); 11668c2ecf20Sopenharmony_ci RV770_SMC_STATETABLE *table = &pi->smc_statetable; 11678c2ecf20Sopenharmony_ci int ret; 11688c2ecf20Sopenharmony_ci 11698c2ecf20Sopenharmony_ci memset(table, 0, sizeof(RV770_SMC_STATETABLE)); 11708c2ecf20Sopenharmony_ci 11718c2ecf20Sopenharmony_ci pi->boot_sclk = boot_state->low.sclk; 11728c2ecf20Sopenharmony_ci 11738c2ecf20Sopenharmony_ci rv770_populate_smc_vddc_table(rdev, table); 11748c2ecf20Sopenharmony_ci rv770_populate_smc_mvdd_table(rdev, table); 11758c2ecf20Sopenharmony_ci 11768c2ecf20Sopenharmony_ci switch (rdev->pm.int_thermal_type) { 11778c2ecf20Sopenharmony_ci case THERMAL_TYPE_RV770: 11788c2ecf20Sopenharmony_ci case THERMAL_TYPE_ADT7473_WITH_INTERNAL: 11798c2ecf20Sopenharmony_ci table->thermalProtectType = PPSMC_THERMAL_PROTECT_TYPE_INTERNAL; 11808c2ecf20Sopenharmony_ci break; 11818c2ecf20Sopenharmony_ci case THERMAL_TYPE_NONE: 11828c2ecf20Sopenharmony_ci table->thermalProtectType = PPSMC_THERMAL_PROTECT_TYPE_NONE; 11838c2ecf20Sopenharmony_ci break; 11848c2ecf20Sopenharmony_ci case THERMAL_TYPE_EXTERNAL_GPIO: 11858c2ecf20Sopenharmony_ci default: 11868c2ecf20Sopenharmony_ci table->thermalProtectType = PPSMC_THERMAL_PROTECT_TYPE_EXTERNAL; 11878c2ecf20Sopenharmony_ci break; 11888c2ecf20Sopenharmony_ci } 11898c2ecf20Sopenharmony_ci 11908c2ecf20Sopenharmony_ci if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_HARDWAREDC) { 11918c2ecf20Sopenharmony_ci table->systemFlags |= PPSMC_SYSTEMFLAG_GPIO_DC; 11928c2ecf20Sopenharmony_ci 11938c2ecf20Sopenharmony_ci if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_DONT_WAIT_FOR_VBLANK_ON_ALERT) 11948c2ecf20Sopenharmony_ci table->extraFlags |= PPSMC_EXTRAFLAGS_AC2DC_DONT_WAIT_FOR_VBLANK; 11958c2ecf20Sopenharmony_ci 11968c2ecf20Sopenharmony_ci if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_GOTO_BOOT_ON_ALERT) 11978c2ecf20Sopenharmony_ci table->extraFlags |= PPSMC_EXTRAFLAGS_AC2DC_ACTION_GOTOINITIALSTATE; 11988c2ecf20Sopenharmony_ci } 11998c2ecf20Sopenharmony_ci 12008c2ecf20Sopenharmony_ci if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_STEPVDDC) 12018c2ecf20Sopenharmony_ci table->systemFlags |= PPSMC_SYSTEMFLAG_STEPVDDC; 12028c2ecf20Sopenharmony_ci 12038c2ecf20Sopenharmony_ci if (pi->mem_gddr5) 12048c2ecf20Sopenharmony_ci table->systemFlags |= PPSMC_SYSTEMFLAG_GDDR5; 12058c2ecf20Sopenharmony_ci 12068c2ecf20Sopenharmony_ci if ((rdev->family == CHIP_RV730) || (rdev->family == CHIP_RV710)) 12078c2ecf20Sopenharmony_ci ret = rv730_populate_smc_initial_state(rdev, radeon_boot_state, table); 12088c2ecf20Sopenharmony_ci else 12098c2ecf20Sopenharmony_ci ret = rv770_populate_smc_initial_state(rdev, radeon_boot_state, table); 12108c2ecf20Sopenharmony_ci if (ret) 12118c2ecf20Sopenharmony_ci return ret; 12128c2ecf20Sopenharmony_ci 12138c2ecf20Sopenharmony_ci if (rdev->family == CHIP_RV740) 12148c2ecf20Sopenharmony_ci ret = rv740_populate_smc_acpi_state(rdev, table); 12158c2ecf20Sopenharmony_ci else if ((rdev->family == CHIP_RV730) || (rdev->family == CHIP_RV710)) 12168c2ecf20Sopenharmony_ci ret = rv730_populate_smc_acpi_state(rdev, table); 12178c2ecf20Sopenharmony_ci else 12188c2ecf20Sopenharmony_ci ret = rv770_populate_smc_acpi_state(rdev, table); 12198c2ecf20Sopenharmony_ci if (ret) 12208c2ecf20Sopenharmony_ci return ret; 12218c2ecf20Sopenharmony_ci 12228c2ecf20Sopenharmony_ci table->driverState = table->initialState; 12238c2ecf20Sopenharmony_ci 12248c2ecf20Sopenharmony_ci return rv770_copy_bytes_to_smc(rdev, 12258c2ecf20Sopenharmony_ci pi->state_table_start, 12268c2ecf20Sopenharmony_ci (const u8 *)table, 12278c2ecf20Sopenharmony_ci sizeof(RV770_SMC_STATETABLE), 12288c2ecf20Sopenharmony_ci pi->sram_end); 12298c2ecf20Sopenharmony_ci} 12308c2ecf20Sopenharmony_ci 12318c2ecf20Sopenharmony_cistatic int rv770_construct_vddc_table(struct radeon_device *rdev) 12328c2ecf20Sopenharmony_ci{ 12338c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 12348c2ecf20Sopenharmony_ci u16 min, max, step; 12358c2ecf20Sopenharmony_ci u32 steps = 0; 12368c2ecf20Sopenharmony_ci u8 vddc_index = 0; 12378c2ecf20Sopenharmony_ci u32 i; 12388c2ecf20Sopenharmony_ci 12398c2ecf20Sopenharmony_ci radeon_atom_get_min_voltage(rdev, SET_VOLTAGE_TYPE_ASIC_VDDC, &min); 12408c2ecf20Sopenharmony_ci radeon_atom_get_max_voltage(rdev, SET_VOLTAGE_TYPE_ASIC_VDDC, &max); 12418c2ecf20Sopenharmony_ci radeon_atom_get_voltage_step(rdev, SET_VOLTAGE_TYPE_ASIC_VDDC, &step); 12428c2ecf20Sopenharmony_ci 12438c2ecf20Sopenharmony_ci steps = (max - min) / step + 1; 12448c2ecf20Sopenharmony_ci 12458c2ecf20Sopenharmony_ci if (steps > MAX_NO_VREG_STEPS) 12468c2ecf20Sopenharmony_ci return -EINVAL; 12478c2ecf20Sopenharmony_ci 12488c2ecf20Sopenharmony_ci for (i = 0; i < steps; i++) { 12498c2ecf20Sopenharmony_ci u32 gpio_pins, gpio_mask; 12508c2ecf20Sopenharmony_ci 12518c2ecf20Sopenharmony_ci pi->vddc_table[i].vddc = (u16)(min + i * step); 12528c2ecf20Sopenharmony_ci radeon_atom_get_voltage_gpio_settings(rdev, 12538c2ecf20Sopenharmony_ci pi->vddc_table[i].vddc, 12548c2ecf20Sopenharmony_ci SET_VOLTAGE_TYPE_ASIC_VDDC, 12558c2ecf20Sopenharmony_ci &gpio_pins, &gpio_mask); 12568c2ecf20Sopenharmony_ci pi->vddc_table[i].low_smio = gpio_pins & gpio_mask; 12578c2ecf20Sopenharmony_ci pi->vddc_table[i].high_smio = 0; 12588c2ecf20Sopenharmony_ci pi->vddc_mask_low = gpio_mask; 12598c2ecf20Sopenharmony_ci if (i > 0) { 12608c2ecf20Sopenharmony_ci if ((pi->vddc_table[i].low_smio != 12618c2ecf20Sopenharmony_ci pi->vddc_table[i - 1].low_smio ) || 12628c2ecf20Sopenharmony_ci (pi->vddc_table[i].high_smio != 12638c2ecf20Sopenharmony_ci pi->vddc_table[i - 1].high_smio)) 12648c2ecf20Sopenharmony_ci vddc_index++; 12658c2ecf20Sopenharmony_ci } 12668c2ecf20Sopenharmony_ci pi->vddc_table[i].vddc_index = vddc_index; 12678c2ecf20Sopenharmony_ci } 12688c2ecf20Sopenharmony_ci 12698c2ecf20Sopenharmony_ci pi->valid_vddc_entries = (u8)steps; 12708c2ecf20Sopenharmony_ci 12718c2ecf20Sopenharmony_ci return 0; 12728c2ecf20Sopenharmony_ci} 12738c2ecf20Sopenharmony_ci 12748c2ecf20Sopenharmony_cistatic u32 rv770_get_mclk_split_point(struct atom_memory_info *memory_info) 12758c2ecf20Sopenharmony_ci{ 12768c2ecf20Sopenharmony_ci if (memory_info->mem_type == MEM_TYPE_GDDR3) 12778c2ecf20Sopenharmony_ci return 30000; 12788c2ecf20Sopenharmony_ci 12798c2ecf20Sopenharmony_ci return 0; 12808c2ecf20Sopenharmony_ci} 12818c2ecf20Sopenharmony_ci 12828c2ecf20Sopenharmony_cistatic int rv770_get_mvdd_pin_configuration(struct radeon_device *rdev) 12838c2ecf20Sopenharmony_ci{ 12848c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 12858c2ecf20Sopenharmony_ci u32 gpio_pins, gpio_mask; 12868c2ecf20Sopenharmony_ci 12878c2ecf20Sopenharmony_ci radeon_atom_get_voltage_gpio_settings(rdev, 12888c2ecf20Sopenharmony_ci MVDD_HIGH_VALUE, SET_VOLTAGE_TYPE_ASIC_MVDDC, 12898c2ecf20Sopenharmony_ci &gpio_pins, &gpio_mask); 12908c2ecf20Sopenharmony_ci pi->mvdd_mask_low = gpio_mask; 12918c2ecf20Sopenharmony_ci pi->mvdd_low_smio[MVDD_HIGH_INDEX] = 12928c2ecf20Sopenharmony_ci gpio_pins & gpio_mask; 12938c2ecf20Sopenharmony_ci 12948c2ecf20Sopenharmony_ci radeon_atom_get_voltage_gpio_settings(rdev, 12958c2ecf20Sopenharmony_ci MVDD_LOW_VALUE, SET_VOLTAGE_TYPE_ASIC_MVDDC, 12968c2ecf20Sopenharmony_ci &gpio_pins, &gpio_mask); 12978c2ecf20Sopenharmony_ci pi->mvdd_low_smio[MVDD_LOW_INDEX] = 12988c2ecf20Sopenharmony_ci gpio_pins & gpio_mask; 12998c2ecf20Sopenharmony_ci 13008c2ecf20Sopenharmony_ci return 0; 13018c2ecf20Sopenharmony_ci} 13028c2ecf20Sopenharmony_ci 13038c2ecf20Sopenharmony_ciu8 rv770_get_memory_module_index(struct radeon_device *rdev) 13048c2ecf20Sopenharmony_ci{ 13058c2ecf20Sopenharmony_ci return (u8) ((RREG32(BIOS_SCRATCH_4) >> 16) & 0xff); 13068c2ecf20Sopenharmony_ci} 13078c2ecf20Sopenharmony_ci 13088c2ecf20Sopenharmony_cistatic int rv770_get_mvdd_configuration(struct radeon_device *rdev) 13098c2ecf20Sopenharmony_ci{ 13108c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 13118c2ecf20Sopenharmony_ci u8 memory_module_index; 13128c2ecf20Sopenharmony_ci struct atom_memory_info memory_info; 13138c2ecf20Sopenharmony_ci 13148c2ecf20Sopenharmony_ci memory_module_index = rv770_get_memory_module_index(rdev); 13158c2ecf20Sopenharmony_ci 13168c2ecf20Sopenharmony_ci if (radeon_atom_get_memory_info(rdev, memory_module_index, &memory_info)) { 13178c2ecf20Sopenharmony_ci pi->mvdd_control = false; 13188c2ecf20Sopenharmony_ci return 0; 13198c2ecf20Sopenharmony_ci } 13208c2ecf20Sopenharmony_ci 13218c2ecf20Sopenharmony_ci pi->mvdd_split_frequency = 13228c2ecf20Sopenharmony_ci rv770_get_mclk_split_point(&memory_info); 13238c2ecf20Sopenharmony_ci 13248c2ecf20Sopenharmony_ci if (pi->mvdd_split_frequency == 0) { 13258c2ecf20Sopenharmony_ci pi->mvdd_control = false; 13268c2ecf20Sopenharmony_ci return 0; 13278c2ecf20Sopenharmony_ci } 13288c2ecf20Sopenharmony_ci 13298c2ecf20Sopenharmony_ci return rv770_get_mvdd_pin_configuration(rdev); 13308c2ecf20Sopenharmony_ci} 13318c2ecf20Sopenharmony_ci 13328c2ecf20Sopenharmony_civoid rv770_enable_voltage_control(struct radeon_device *rdev, 13338c2ecf20Sopenharmony_ci bool enable) 13348c2ecf20Sopenharmony_ci{ 13358c2ecf20Sopenharmony_ci if (enable) 13368c2ecf20Sopenharmony_ci WREG32_P(GENERAL_PWRMGT, VOLT_PWRMGT_EN, ~VOLT_PWRMGT_EN); 13378c2ecf20Sopenharmony_ci else 13388c2ecf20Sopenharmony_ci WREG32_P(GENERAL_PWRMGT, 0, ~VOLT_PWRMGT_EN); 13398c2ecf20Sopenharmony_ci} 13408c2ecf20Sopenharmony_ci 13418c2ecf20Sopenharmony_cistatic void rv770_program_display_gap(struct radeon_device *rdev) 13428c2ecf20Sopenharmony_ci{ 13438c2ecf20Sopenharmony_ci u32 tmp = RREG32(CG_DISPLAY_GAP_CNTL); 13448c2ecf20Sopenharmony_ci 13458c2ecf20Sopenharmony_ci tmp &= ~(DISP1_GAP_MCHG_MASK | DISP2_GAP_MCHG_MASK); 13468c2ecf20Sopenharmony_ci if (rdev->pm.dpm.new_active_crtcs & 1) { 13478c2ecf20Sopenharmony_ci tmp |= DISP1_GAP_MCHG(R600_PM_DISPLAY_GAP_VBLANK); 13488c2ecf20Sopenharmony_ci tmp |= DISP2_GAP_MCHG(R600_PM_DISPLAY_GAP_IGNORE); 13498c2ecf20Sopenharmony_ci } else if (rdev->pm.dpm.new_active_crtcs & 2) { 13508c2ecf20Sopenharmony_ci tmp |= DISP1_GAP_MCHG(R600_PM_DISPLAY_GAP_IGNORE); 13518c2ecf20Sopenharmony_ci tmp |= DISP2_GAP_MCHG(R600_PM_DISPLAY_GAP_VBLANK); 13528c2ecf20Sopenharmony_ci } else { 13538c2ecf20Sopenharmony_ci tmp |= DISP1_GAP_MCHG(R600_PM_DISPLAY_GAP_IGNORE); 13548c2ecf20Sopenharmony_ci tmp |= DISP2_GAP_MCHG(R600_PM_DISPLAY_GAP_IGNORE); 13558c2ecf20Sopenharmony_ci } 13568c2ecf20Sopenharmony_ci WREG32(CG_DISPLAY_GAP_CNTL, tmp); 13578c2ecf20Sopenharmony_ci} 13588c2ecf20Sopenharmony_ci 13598c2ecf20Sopenharmony_cistatic void rv770_enable_dynamic_pcie_gen2(struct radeon_device *rdev, 13608c2ecf20Sopenharmony_ci bool enable) 13618c2ecf20Sopenharmony_ci{ 13628c2ecf20Sopenharmony_ci rv770_enable_bif_dynamic_pcie_gen2(rdev, enable); 13638c2ecf20Sopenharmony_ci 13648c2ecf20Sopenharmony_ci if (enable) 13658c2ecf20Sopenharmony_ci WREG32_P(GENERAL_PWRMGT, ENABLE_GEN2PCIE, ~ENABLE_GEN2PCIE); 13668c2ecf20Sopenharmony_ci else 13678c2ecf20Sopenharmony_ci WREG32_P(GENERAL_PWRMGT, 0, ~ENABLE_GEN2PCIE); 13688c2ecf20Sopenharmony_ci} 13698c2ecf20Sopenharmony_ci 13708c2ecf20Sopenharmony_cistatic void r7xx_program_memory_timing_parameters(struct radeon_device *rdev, 13718c2ecf20Sopenharmony_ci struct radeon_ps *radeon_new_state) 13728c2ecf20Sopenharmony_ci{ 13738c2ecf20Sopenharmony_ci if ((rdev->family == CHIP_RV730) || 13748c2ecf20Sopenharmony_ci (rdev->family == CHIP_RV710) || 13758c2ecf20Sopenharmony_ci (rdev->family == CHIP_RV740)) 13768c2ecf20Sopenharmony_ci rv730_program_memory_timing_parameters(rdev, radeon_new_state); 13778c2ecf20Sopenharmony_ci else 13788c2ecf20Sopenharmony_ci rv770_program_memory_timing_parameters(rdev, radeon_new_state); 13798c2ecf20Sopenharmony_ci} 13808c2ecf20Sopenharmony_ci 13818c2ecf20Sopenharmony_cistatic int rv770_upload_sw_state(struct radeon_device *rdev, 13828c2ecf20Sopenharmony_ci struct radeon_ps *radeon_new_state) 13838c2ecf20Sopenharmony_ci{ 13848c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 13858c2ecf20Sopenharmony_ci u16 address = pi->state_table_start + 13868c2ecf20Sopenharmony_ci offsetof(RV770_SMC_STATETABLE, driverState); 13878c2ecf20Sopenharmony_ci RV770_SMC_SWSTATE state = { 0 }; 13888c2ecf20Sopenharmony_ci int ret; 13898c2ecf20Sopenharmony_ci 13908c2ecf20Sopenharmony_ci ret = rv770_convert_power_state_to_smc(rdev, radeon_new_state, &state); 13918c2ecf20Sopenharmony_ci if (ret) 13928c2ecf20Sopenharmony_ci return ret; 13938c2ecf20Sopenharmony_ci 13948c2ecf20Sopenharmony_ci return rv770_copy_bytes_to_smc(rdev, address, (const u8 *)&state, 13958c2ecf20Sopenharmony_ci sizeof(RV770_SMC_SWSTATE), 13968c2ecf20Sopenharmony_ci pi->sram_end); 13978c2ecf20Sopenharmony_ci} 13988c2ecf20Sopenharmony_ci 13998c2ecf20Sopenharmony_ciint rv770_halt_smc(struct radeon_device *rdev) 14008c2ecf20Sopenharmony_ci{ 14018c2ecf20Sopenharmony_ci if (rv770_send_msg_to_smc(rdev, PPSMC_MSG_Halt) != PPSMC_Result_OK) 14028c2ecf20Sopenharmony_ci return -EINVAL; 14038c2ecf20Sopenharmony_ci 14048c2ecf20Sopenharmony_ci if (rv770_wait_for_smc_inactive(rdev) != PPSMC_Result_OK) 14058c2ecf20Sopenharmony_ci return -EINVAL; 14068c2ecf20Sopenharmony_ci 14078c2ecf20Sopenharmony_ci return 0; 14088c2ecf20Sopenharmony_ci} 14098c2ecf20Sopenharmony_ci 14108c2ecf20Sopenharmony_ciint rv770_resume_smc(struct radeon_device *rdev) 14118c2ecf20Sopenharmony_ci{ 14128c2ecf20Sopenharmony_ci if (rv770_send_msg_to_smc(rdev, PPSMC_MSG_Resume) != PPSMC_Result_OK) 14138c2ecf20Sopenharmony_ci return -EINVAL; 14148c2ecf20Sopenharmony_ci return 0; 14158c2ecf20Sopenharmony_ci} 14168c2ecf20Sopenharmony_ci 14178c2ecf20Sopenharmony_ciint rv770_set_sw_state(struct radeon_device *rdev) 14188c2ecf20Sopenharmony_ci{ 14198c2ecf20Sopenharmony_ci if (rv770_send_msg_to_smc(rdev, PPSMC_MSG_SwitchToSwState) != PPSMC_Result_OK) 14208c2ecf20Sopenharmony_ci DRM_DEBUG("rv770_set_sw_state failed\n"); 14218c2ecf20Sopenharmony_ci return 0; 14228c2ecf20Sopenharmony_ci} 14238c2ecf20Sopenharmony_ci 14248c2ecf20Sopenharmony_ciint rv770_set_boot_state(struct radeon_device *rdev) 14258c2ecf20Sopenharmony_ci{ 14268c2ecf20Sopenharmony_ci if (rv770_send_msg_to_smc(rdev, PPSMC_MSG_SwitchToInitialState) != PPSMC_Result_OK) 14278c2ecf20Sopenharmony_ci return -EINVAL; 14288c2ecf20Sopenharmony_ci return 0; 14298c2ecf20Sopenharmony_ci} 14308c2ecf20Sopenharmony_ci 14318c2ecf20Sopenharmony_civoid rv770_set_uvd_clock_before_set_eng_clock(struct radeon_device *rdev, 14328c2ecf20Sopenharmony_ci struct radeon_ps *new_ps, 14338c2ecf20Sopenharmony_ci struct radeon_ps *old_ps) 14348c2ecf20Sopenharmony_ci{ 14358c2ecf20Sopenharmony_ci struct rv7xx_ps *new_state = rv770_get_ps(new_ps); 14368c2ecf20Sopenharmony_ci struct rv7xx_ps *current_state = rv770_get_ps(old_ps); 14378c2ecf20Sopenharmony_ci 14388c2ecf20Sopenharmony_ci if ((new_ps->vclk == old_ps->vclk) && 14398c2ecf20Sopenharmony_ci (new_ps->dclk == old_ps->dclk)) 14408c2ecf20Sopenharmony_ci return; 14418c2ecf20Sopenharmony_ci 14428c2ecf20Sopenharmony_ci if (new_state->high.sclk >= current_state->high.sclk) 14438c2ecf20Sopenharmony_ci return; 14448c2ecf20Sopenharmony_ci 14458c2ecf20Sopenharmony_ci radeon_set_uvd_clocks(rdev, new_ps->vclk, new_ps->dclk); 14468c2ecf20Sopenharmony_ci} 14478c2ecf20Sopenharmony_ci 14488c2ecf20Sopenharmony_civoid rv770_set_uvd_clock_after_set_eng_clock(struct radeon_device *rdev, 14498c2ecf20Sopenharmony_ci struct radeon_ps *new_ps, 14508c2ecf20Sopenharmony_ci struct radeon_ps *old_ps) 14518c2ecf20Sopenharmony_ci{ 14528c2ecf20Sopenharmony_ci struct rv7xx_ps *new_state = rv770_get_ps(new_ps); 14538c2ecf20Sopenharmony_ci struct rv7xx_ps *current_state = rv770_get_ps(old_ps); 14548c2ecf20Sopenharmony_ci 14558c2ecf20Sopenharmony_ci if ((new_ps->vclk == old_ps->vclk) && 14568c2ecf20Sopenharmony_ci (new_ps->dclk == old_ps->dclk)) 14578c2ecf20Sopenharmony_ci return; 14588c2ecf20Sopenharmony_ci 14598c2ecf20Sopenharmony_ci if (new_state->high.sclk < current_state->high.sclk) 14608c2ecf20Sopenharmony_ci return; 14618c2ecf20Sopenharmony_ci 14628c2ecf20Sopenharmony_ci radeon_set_uvd_clocks(rdev, new_ps->vclk, new_ps->dclk); 14638c2ecf20Sopenharmony_ci} 14648c2ecf20Sopenharmony_ci 14658c2ecf20Sopenharmony_ciint rv770_restrict_performance_levels_before_switch(struct radeon_device *rdev) 14668c2ecf20Sopenharmony_ci{ 14678c2ecf20Sopenharmony_ci if (rv770_send_msg_to_smc(rdev, (PPSMC_Msg)(PPSMC_MSG_NoForcedLevel)) != PPSMC_Result_OK) 14688c2ecf20Sopenharmony_ci return -EINVAL; 14698c2ecf20Sopenharmony_ci 14708c2ecf20Sopenharmony_ci if (rv770_send_msg_to_smc(rdev, (PPSMC_Msg)(PPSMC_MSG_TwoLevelsDisabled)) != PPSMC_Result_OK) 14718c2ecf20Sopenharmony_ci return -EINVAL; 14728c2ecf20Sopenharmony_ci 14738c2ecf20Sopenharmony_ci return 0; 14748c2ecf20Sopenharmony_ci} 14758c2ecf20Sopenharmony_ci 14768c2ecf20Sopenharmony_ciint rv770_dpm_force_performance_level(struct radeon_device *rdev, 14778c2ecf20Sopenharmony_ci enum radeon_dpm_forced_level level) 14788c2ecf20Sopenharmony_ci{ 14798c2ecf20Sopenharmony_ci PPSMC_Msg msg; 14808c2ecf20Sopenharmony_ci 14818c2ecf20Sopenharmony_ci if (level == RADEON_DPM_FORCED_LEVEL_HIGH) { 14828c2ecf20Sopenharmony_ci if (rv770_send_msg_to_smc(rdev, PPSMC_MSG_ZeroLevelsDisabled) != PPSMC_Result_OK) 14838c2ecf20Sopenharmony_ci return -EINVAL; 14848c2ecf20Sopenharmony_ci msg = PPSMC_MSG_ForceHigh; 14858c2ecf20Sopenharmony_ci } else if (level == RADEON_DPM_FORCED_LEVEL_LOW) { 14868c2ecf20Sopenharmony_ci if (rv770_send_msg_to_smc(rdev, PPSMC_MSG_NoForcedLevel) != PPSMC_Result_OK) 14878c2ecf20Sopenharmony_ci return -EINVAL; 14888c2ecf20Sopenharmony_ci msg = (PPSMC_Msg)(PPSMC_MSG_TwoLevelsDisabled); 14898c2ecf20Sopenharmony_ci } else { 14908c2ecf20Sopenharmony_ci if (rv770_send_msg_to_smc(rdev, PPSMC_MSG_NoForcedLevel) != PPSMC_Result_OK) 14918c2ecf20Sopenharmony_ci return -EINVAL; 14928c2ecf20Sopenharmony_ci msg = (PPSMC_Msg)(PPSMC_MSG_ZeroLevelsDisabled); 14938c2ecf20Sopenharmony_ci } 14948c2ecf20Sopenharmony_ci 14958c2ecf20Sopenharmony_ci if (rv770_send_msg_to_smc(rdev, msg) != PPSMC_Result_OK) 14968c2ecf20Sopenharmony_ci return -EINVAL; 14978c2ecf20Sopenharmony_ci 14988c2ecf20Sopenharmony_ci rdev->pm.dpm.forced_level = level; 14998c2ecf20Sopenharmony_ci 15008c2ecf20Sopenharmony_ci return 0; 15018c2ecf20Sopenharmony_ci} 15028c2ecf20Sopenharmony_ci 15038c2ecf20Sopenharmony_civoid r7xx_start_smc(struct radeon_device *rdev) 15048c2ecf20Sopenharmony_ci{ 15058c2ecf20Sopenharmony_ci rv770_start_smc(rdev); 15068c2ecf20Sopenharmony_ci rv770_start_smc_clock(rdev); 15078c2ecf20Sopenharmony_ci} 15088c2ecf20Sopenharmony_ci 15098c2ecf20Sopenharmony_ci 15108c2ecf20Sopenharmony_civoid r7xx_stop_smc(struct radeon_device *rdev) 15118c2ecf20Sopenharmony_ci{ 15128c2ecf20Sopenharmony_ci rv770_reset_smc(rdev); 15138c2ecf20Sopenharmony_ci rv770_stop_smc_clock(rdev); 15148c2ecf20Sopenharmony_ci} 15158c2ecf20Sopenharmony_ci 15168c2ecf20Sopenharmony_cistatic void rv770_read_clock_registers(struct radeon_device *rdev) 15178c2ecf20Sopenharmony_ci{ 15188c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 15198c2ecf20Sopenharmony_ci 15208c2ecf20Sopenharmony_ci pi->clk_regs.rv770.cg_spll_func_cntl = 15218c2ecf20Sopenharmony_ci RREG32(CG_SPLL_FUNC_CNTL); 15228c2ecf20Sopenharmony_ci pi->clk_regs.rv770.cg_spll_func_cntl_2 = 15238c2ecf20Sopenharmony_ci RREG32(CG_SPLL_FUNC_CNTL_2); 15248c2ecf20Sopenharmony_ci pi->clk_regs.rv770.cg_spll_func_cntl_3 = 15258c2ecf20Sopenharmony_ci RREG32(CG_SPLL_FUNC_CNTL_3); 15268c2ecf20Sopenharmony_ci pi->clk_regs.rv770.cg_spll_spread_spectrum = 15278c2ecf20Sopenharmony_ci RREG32(CG_SPLL_SPREAD_SPECTRUM); 15288c2ecf20Sopenharmony_ci pi->clk_regs.rv770.cg_spll_spread_spectrum_2 = 15298c2ecf20Sopenharmony_ci RREG32(CG_SPLL_SPREAD_SPECTRUM_2); 15308c2ecf20Sopenharmony_ci pi->clk_regs.rv770.mpll_ad_func_cntl = 15318c2ecf20Sopenharmony_ci RREG32(MPLL_AD_FUNC_CNTL); 15328c2ecf20Sopenharmony_ci pi->clk_regs.rv770.mpll_ad_func_cntl_2 = 15338c2ecf20Sopenharmony_ci RREG32(MPLL_AD_FUNC_CNTL_2); 15348c2ecf20Sopenharmony_ci pi->clk_regs.rv770.mpll_dq_func_cntl = 15358c2ecf20Sopenharmony_ci RREG32(MPLL_DQ_FUNC_CNTL); 15368c2ecf20Sopenharmony_ci pi->clk_regs.rv770.mpll_dq_func_cntl_2 = 15378c2ecf20Sopenharmony_ci RREG32(MPLL_DQ_FUNC_CNTL_2); 15388c2ecf20Sopenharmony_ci pi->clk_regs.rv770.mclk_pwrmgt_cntl = 15398c2ecf20Sopenharmony_ci RREG32(MCLK_PWRMGT_CNTL); 15408c2ecf20Sopenharmony_ci pi->clk_regs.rv770.dll_cntl = RREG32(DLL_CNTL); 15418c2ecf20Sopenharmony_ci} 15428c2ecf20Sopenharmony_ci 15438c2ecf20Sopenharmony_cistatic void r7xx_read_clock_registers(struct radeon_device *rdev) 15448c2ecf20Sopenharmony_ci{ 15458c2ecf20Sopenharmony_ci if (rdev->family == CHIP_RV740) 15468c2ecf20Sopenharmony_ci rv740_read_clock_registers(rdev); 15478c2ecf20Sopenharmony_ci else if ((rdev->family == CHIP_RV730) || (rdev->family == CHIP_RV710)) 15488c2ecf20Sopenharmony_ci rv730_read_clock_registers(rdev); 15498c2ecf20Sopenharmony_ci else 15508c2ecf20Sopenharmony_ci rv770_read_clock_registers(rdev); 15518c2ecf20Sopenharmony_ci} 15528c2ecf20Sopenharmony_ci 15538c2ecf20Sopenharmony_civoid rv770_read_voltage_smio_registers(struct radeon_device *rdev) 15548c2ecf20Sopenharmony_ci{ 15558c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 15568c2ecf20Sopenharmony_ci 15578c2ecf20Sopenharmony_ci pi->s0_vid_lower_smio_cntl = 15588c2ecf20Sopenharmony_ci RREG32(S0_VID_LOWER_SMIO_CNTL); 15598c2ecf20Sopenharmony_ci} 15608c2ecf20Sopenharmony_ci 15618c2ecf20Sopenharmony_civoid rv770_reset_smio_status(struct radeon_device *rdev) 15628c2ecf20Sopenharmony_ci{ 15638c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 15648c2ecf20Sopenharmony_ci u32 sw_smio_index, vid_smio_cntl; 15658c2ecf20Sopenharmony_ci 15668c2ecf20Sopenharmony_ci sw_smio_index = 15678c2ecf20Sopenharmony_ci (RREG32(GENERAL_PWRMGT) & SW_SMIO_INDEX_MASK) >> SW_SMIO_INDEX_SHIFT; 15688c2ecf20Sopenharmony_ci switch (sw_smio_index) { 15698c2ecf20Sopenharmony_ci case 3: 15708c2ecf20Sopenharmony_ci vid_smio_cntl = RREG32(S3_VID_LOWER_SMIO_CNTL); 15718c2ecf20Sopenharmony_ci break; 15728c2ecf20Sopenharmony_ci case 2: 15738c2ecf20Sopenharmony_ci vid_smio_cntl = RREG32(S2_VID_LOWER_SMIO_CNTL); 15748c2ecf20Sopenharmony_ci break; 15758c2ecf20Sopenharmony_ci case 1: 15768c2ecf20Sopenharmony_ci vid_smio_cntl = RREG32(S1_VID_LOWER_SMIO_CNTL); 15778c2ecf20Sopenharmony_ci break; 15788c2ecf20Sopenharmony_ci case 0: 15798c2ecf20Sopenharmony_ci return; 15808c2ecf20Sopenharmony_ci default: 15818c2ecf20Sopenharmony_ci vid_smio_cntl = pi->s0_vid_lower_smio_cntl; 15828c2ecf20Sopenharmony_ci break; 15838c2ecf20Sopenharmony_ci } 15848c2ecf20Sopenharmony_ci 15858c2ecf20Sopenharmony_ci WREG32(S0_VID_LOWER_SMIO_CNTL, vid_smio_cntl); 15868c2ecf20Sopenharmony_ci WREG32_P(GENERAL_PWRMGT, SW_SMIO_INDEX(0), ~SW_SMIO_INDEX_MASK); 15878c2ecf20Sopenharmony_ci} 15888c2ecf20Sopenharmony_ci 15898c2ecf20Sopenharmony_civoid rv770_get_memory_type(struct radeon_device *rdev) 15908c2ecf20Sopenharmony_ci{ 15918c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 15928c2ecf20Sopenharmony_ci u32 tmp; 15938c2ecf20Sopenharmony_ci 15948c2ecf20Sopenharmony_ci tmp = RREG32(MC_SEQ_MISC0); 15958c2ecf20Sopenharmony_ci 15968c2ecf20Sopenharmony_ci if (((tmp & MC_SEQ_MISC0_GDDR5_MASK) >> MC_SEQ_MISC0_GDDR5_SHIFT) == 15978c2ecf20Sopenharmony_ci MC_SEQ_MISC0_GDDR5_VALUE) 15988c2ecf20Sopenharmony_ci pi->mem_gddr5 = true; 15998c2ecf20Sopenharmony_ci else 16008c2ecf20Sopenharmony_ci pi->mem_gddr5 = false; 16018c2ecf20Sopenharmony_ci 16028c2ecf20Sopenharmony_ci} 16038c2ecf20Sopenharmony_ci 16048c2ecf20Sopenharmony_civoid rv770_get_pcie_gen2_status(struct radeon_device *rdev) 16058c2ecf20Sopenharmony_ci{ 16068c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 16078c2ecf20Sopenharmony_ci u32 tmp; 16088c2ecf20Sopenharmony_ci 16098c2ecf20Sopenharmony_ci tmp = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL); 16108c2ecf20Sopenharmony_ci 16118c2ecf20Sopenharmony_ci if ((tmp & LC_OTHER_SIDE_EVER_SENT_GEN2) && 16128c2ecf20Sopenharmony_ci (tmp & LC_OTHER_SIDE_SUPPORTS_GEN2)) 16138c2ecf20Sopenharmony_ci pi->pcie_gen2 = true; 16148c2ecf20Sopenharmony_ci else 16158c2ecf20Sopenharmony_ci pi->pcie_gen2 = false; 16168c2ecf20Sopenharmony_ci 16178c2ecf20Sopenharmony_ci if (pi->pcie_gen2) { 16188c2ecf20Sopenharmony_ci if (tmp & LC_CURRENT_DATA_RATE) 16198c2ecf20Sopenharmony_ci pi->boot_in_gen2 = true; 16208c2ecf20Sopenharmony_ci else 16218c2ecf20Sopenharmony_ci pi->boot_in_gen2 = false; 16228c2ecf20Sopenharmony_ci } else 16238c2ecf20Sopenharmony_ci pi->boot_in_gen2 = false; 16248c2ecf20Sopenharmony_ci} 16258c2ecf20Sopenharmony_ci 16268c2ecf20Sopenharmony_ci#if 0 16278c2ecf20Sopenharmony_cistatic int rv770_enter_ulp_state(struct radeon_device *rdev) 16288c2ecf20Sopenharmony_ci{ 16298c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 16308c2ecf20Sopenharmony_ci 16318c2ecf20Sopenharmony_ci if (pi->gfx_clock_gating) { 16328c2ecf20Sopenharmony_ci WREG32_P(SCLK_PWRMGT_CNTL, 0, ~DYN_GFX_CLK_OFF_EN); 16338c2ecf20Sopenharmony_ci WREG32_P(SCLK_PWRMGT_CNTL, GFX_CLK_FORCE_ON, ~GFX_CLK_FORCE_ON); 16348c2ecf20Sopenharmony_ci WREG32_P(SCLK_PWRMGT_CNTL, 0, ~GFX_CLK_FORCE_ON); 16358c2ecf20Sopenharmony_ci RREG32(GB_TILING_CONFIG); 16368c2ecf20Sopenharmony_ci } 16378c2ecf20Sopenharmony_ci 16388c2ecf20Sopenharmony_ci WREG32_P(SMC_MSG, HOST_SMC_MSG(PPSMC_MSG_SwitchToMinimumPower), 16398c2ecf20Sopenharmony_ci ~HOST_SMC_MSG_MASK); 16408c2ecf20Sopenharmony_ci 16418c2ecf20Sopenharmony_ci udelay(7000); 16428c2ecf20Sopenharmony_ci 16438c2ecf20Sopenharmony_ci return 0; 16448c2ecf20Sopenharmony_ci} 16458c2ecf20Sopenharmony_ci 16468c2ecf20Sopenharmony_cistatic int rv770_exit_ulp_state(struct radeon_device *rdev) 16478c2ecf20Sopenharmony_ci{ 16488c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 16498c2ecf20Sopenharmony_ci int i; 16508c2ecf20Sopenharmony_ci 16518c2ecf20Sopenharmony_ci WREG32_P(SMC_MSG, HOST_SMC_MSG(PPSMC_MSG_ResumeFromMinimumPower), 16528c2ecf20Sopenharmony_ci ~HOST_SMC_MSG_MASK); 16538c2ecf20Sopenharmony_ci 16548c2ecf20Sopenharmony_ci udelay(7000); 16558c2ecf20Sopenharmony_ci 16568c2ecf20Sopenharmony_ci for (i = 0; i < rdev->usec_timeout; i++) { 16578c2ecf20Sopenharmony_ci if (((RREG32(SMC_MSG) & HOST_SMC_RESP_MASK) >> HOST_SMC_RESP_SHIFT) == 1) 16588c2ecf20Sopenharmony_ci break; 16598c2ecf20Sopenharmony_ci udelay(1000); 16608c2ecf20Sopenharmony_ci } 16618c2ecf20Sopenharmony_ci 16628c2ecf20Sopenharmony_ci if (pi->gfx_clock_gating) 16638c2ecf20Sopenharmony_ci WREG32_P(SCLK_PWRMGT_CNTL, DYN_GFX_CLK_OFF_EN, ~DYN_GFX_CLK_OFF_EN); 16648c2ecf20Sopenharmony_ci 16658c2ecf20Sopenharmony_ci return 0; 16668c2ecf20Sopenharmony_ci} 16678c2ecf20Sopenharmony_ci#endif 16688c2ecf20Sopenharmony_ci 16698c2ecf20Sopenharmony_cistatic void rv770_get_mclk_odt_threshold(struct radeon_device *rdev) 16708c2ecf20Sopenharmony_ci{ 16718c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 16728c2ecf20Sopenharmony_ci u8 memory_module_index; 16738c2ecf20Sopenharmony_ci struct atom_memory_info memory_info; 16748c2ecf20Sopenharmony_ci 16758c2ecf20Sopenharmony_ci pi->mclk_odt_threshold = 0; 16768c2ecf20Sopenharmony_ci 16778c2ecf20Sopenharmony_ci if ((rdev->family == CHIP_RV730) || (rdev->family == CHIP_RV710)) { 16788c2ecf20Sopenharmony_ci memory_module_index = rv770_get_memory_module_index(rdev); 16798c2ecf20Sopenharmony_ci 16808c2ecf20Sopenharmony_ci if (radeon_atom_get_memory_info(rdev, memory_module_index, &memory_info)) 16818c2ecf20Sopenharmony_ci return; 16828c2ecf20Sopenharmony_ci 16838c2ecf20Sopenharmony_ci if (memory_info.mem_type == MEM_TYPE_DDR2 || 16848c2ecf20Sopenharmony_ci memory_info.mem_type == MEM_TYPE_DDR3) 16858c2ecf20Sopenharmony_ci pi->mclk_odt_threshold = 30000; 16868c2ecf20Sopenharmony_ci } 16878c2ecf20Sopenharmony_ci} 16888c2ecf20Sopenharmony_ci 16898c2ecf20Sopenharmony_civoid rv770_get_max_vddc(struct radeon_device *rdev) 16908c2ecf20Sopenharmony_ci{ 16918c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 16928c2ecf20Sopenharmony_ci u16 vddc; 16938c2ecf20Sopenharmony_ci 16948c2ecf20Sopenharmony_ci if (radeon_atom_get_max_vddc(rdev, 0, 0, &vddc)) 16958c2ecf20Sopenharmony_ci pi->max_vddc = 0; 16968c2ecf20Sopenharmony_ci else 16978c2ecf20Sopenharmony_ci pi->max_vddc = vddc; 16988c2ecf20Sopenharmony_ci} 16998c2ecf20Sopenharmony_ci 17008c2ecf20Sopenharmony_civoid rv770_program_response_times(struct radeon_device *rdev) 17018c2ecf20Sopenharmony_ci{ 17028c2ecf20Sopenharmony_ci u32 voltage_response_time, backbias_response_time; 17038c2ecf20Sopenharmony_ci u32 acpi_delay_time, vbi_time_out; 17048c2ecf20Sopenharmony_ci u32 vddc_dly, bb_dly, acpi_dly, vbi_dly; 17058c2ecf20Sopenharmony_ci u32 reference_clock; 17068c2ecf20Sopenharmony_ci 17078c2ecf20Sopenharmony_ci voltage_response_time = (u32)rdev->pm.dpm.voltage_response_time; 17088c2ecf20Sopenharmony_ci backbias_response_time = (u32)rdev->pm.dpm.backbias_response_time; 17098c2ecf20Sopenharmony_ci 17108c2ecf20Sopenharmony_ci if (voltage_response_time == 0) 17118c2ecf20Sopenharmony_ci voltage_response_time = 1000; 17128c2ecf20Sopenharmony_ci 17138c2ecf20Sopenharmony_ci if (backbias_response_time == 0) 17148c2ecf20Sopenharmony_ci backbias_response_time = 1000; 17158c2ecf20Sopenharmony_ci 17168c2ecf20Sopenharmony_ci acpi_delay_time = 15000; 17178c2ecf20Sopenharmony_ci vbi_time_out = 100000; 17188c2ecf20Sopenharmony_ci 17198c2ecf20Sopenharmony_ci reference_clock = radeon_get_xclk(rdev); 17208c2ecf20Sopenharmony_ci 17218c2ecf20Sopenharmony_ci vddc_dly = (voltage_response_time * reference_clock) / 1600; 17228c2ecf20Sopenharmony_ci bb_dly = (backbias_response_time * reference_clock) / 1600; 17238c2ecf20Sopenharmony_ci acpi_dly = (acpi_delay_time * reference_clock) / 1600; 17248c2ecf20Sopenharmony_ci vbi_dly = (vbi_time_out * reference_clock) / 1600; 17258c2ecf20Sopenharmony_ci 17268c2ecf20Sopenharmony_ci rv770_write_smc_soft_register(rdev, 17278c2ecf20Sopenharmony_ci RV770_SMC_SOFT_REGISTER_delay_vreg, vddc_dly); 17288c2ecf20Sopenharmony_ci rv770_write_smc_soft_register(rdev, 17298c2ecf20Sopenharmony_ci RV770_SMC_SOFT_REGISTER_delay_bbias, bb_dly); 17308c2ecf20Sopenharmony_ci rv770_write_smc_soft_register(rdev, 17318c2ecf20Sopenharmony_ci RV770_SMC_SOFT_REGISTER_delay_acpi, acpi_dly); 17328c2ecf20Sopenharmony_ci rv770_write_smc_soft_register(rdev, 17338c2ecf20Sopenharmony_ci RV770_SMC_SOFT_REGISTER_mclk_chg_timeout, vbi_dly); 17348c2ecf20Sopenharmony_ci#if 0 17358c2ecf20Sopenharmony_ci /* XXX look up hw revision */ 17368c2ecf20Sopenharmony_ci if (WEKIVA_A21) 17378c2ecf20Sopenharmony_ci rv770_write_smc_soft_register(rdev, 17388c2ecf20Sopenharmony_ci RV770_SMC_SOFT_REGISTER_baby_step_timer, 17398c2ecf20Sopenharmony_ci 0x10); 17408c2ecf20Sopenharmony_ci#endif 17418c2ecf20Sopenharmony_ci} 17428c2ecf20Sopenharmony_ci 17438c2ecf20Sopenharmony_cistatic void rv770_program_dcodt_before_state_switch(struct radeon_device *rdev, 17448c2ecf20Sopenharmony_ci struct radeon_ps *radeon_new_state, 17458c2ecf20Sopenharmony_ci struct radeon_ps *radeon_current_state) 17468c2ecf20Sopenharmony_ci{ 17478c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 17488c2ecf20Sopenharmony_ci struct rv7xx_ps *new_state = rv770_get_ps(radeon_new_state); 17498c2ecf20Sopenharmony_ci struct rv7xx_ps *current_state = rv770_get_ps(radeon_current_state); 17508c2ecf20Sopenharmony_ci bool current_use_dc = false; 17518c2ecf20Sopenharmony_ci bool new_use_dc = false; 17528c2ecf20Sopenharmony_ci 17538c2ecf20Sopenharmony_ci if (pi->mclk_odt_threshold == 0) 17548c2ecf20Sopenharmony_ci return; 17558c2ecf20Sopenharmony_ci 17568c2ecf20Sopenharmony_ci if (current_state->high.mclk <= pi->mclk_odt_threshold) 17578c2ecf20Sopenharmony_ci current_use_dc = true; 17588c2ecf20Sopenharmony_ci 17598c2ecf20Sopenharmony_ci if (new_state->high.mclk <= pi->mclk_odt_threshold) 17608c2ecf20Sopenharmony_ci new_use_dc = true; 17618c2ecf20Sopenharmony_ci 17628c2ecf20Sopenharmony_ci if (current_use_dc == new_use_dc) 17638c2ecf20Sopenharmony_ci return; 17648c2ecf20Sopenharmony_ci 17658c2ecf20Sopenharmony_ci if (!current_use_dc && new_use_dc) 17668c2ecf20Sopenharmony_ci return; 17678c2ecf20Sopenharmony_ci 17688c2ecf20Sopenharmony_ci if ((rdev->family == CHIP_RV730) || (rdev->family == CHIP_RV710)) 17698c2ecf20Sopenharmony_ci rv730_program_dcodt(rdev, new_use_dc); 17708c2ecf20Sopenharmony_ci} 17718c2ecf20Sopenharmony_ci 17728c2ecf20Sopenharmony_cistatic void rv770_program_dcodt_after_state_switch(struct radeon_device *rdev, 17738c2ecf20Sopenharmony_ci struct radeon_ps *radeon_new_state, 17748c2ecf20Sopenharmony_ci struct radeon_ps *radeon_current_state) 17758c2ecf20Sopenharmony_ci{ 17768c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 17778c2ecf20Sopenharmony_ci struct rv7xx_ps *new_state = rv770_get_ps(radeon_new_state); 17788c2ecf20Sopenharmony_ci struct rv7xx_ps *current_state = rv770_get_ps(radeon_current_state); 17798c2ecf20Sopenharmony_ci bool current_use_dc = false; 17808c2ecf20Sopenharmony_ci bool new_use_dc = false; 17818c2ecf20Sopenharmony_ci 17828c2ecf20Sopenharmony_ci if (pi->mclk_odt_threshold == 0) 17838c2ecf20Sopenharmony_ci return; 17848c2ecf20Sopenharmony_ci 17858c2ecf20Sopenharmony_ci if (current_state->high.mclk <= pi->mclk_odt_threshold) 17868c2ecf20Sopenharmony_ci current_use_dc = true; 17878c2ecf20Sopenharmony_ci 17888c2ecf20Sopenharmony_ci if (new_state->high.mclk <= pi->mclk_odt_threshold) 17898c2ecf20Sopenharmony_ci new_use_dc = true; 17908c2ecf20Sopenharmony_ci 17918c2ecf20Sopenharmony_ci if (current_use_dc == new_use_dc) 17928c2ecf20Sopenharmony_ci return; 17938c2ecf20Sopenharmony_ci 17948c2ecf20Sopenharmony_ci if (current_use_dc && !new_use_dc) 17958c2ecf20Sopenharmony_ci return; 17968c2ecf20Sopenharmony_ci 17978c2ecf20Sopenharmony_ci if ((rdev->family == CHIP_RV730) || (rdev->family == CHIP_RV710)) 17988c2ecf20Sopenharmony_ci rv730_program_dcodt(rdev, new_use_dc); 17998c2ecf20Sopenharmony_ci} 18008c2ecf20Sopenharmony_ci 18018c2ecf20Sopenharmony_cistatic void rv770_retrieve_odt_values(struct radeon_device *rdev) 18028c2ecf20Sopenharmony_ci{ 18038c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 18048c2ecf20Sopenharmony_ci 18058c2ecf20Sopenharmony_ci if (pi->mclk_odt_threshold == 0) 18068c2ecf20Sopenharmony_ci return; 18078c2ecf20Sopenharmony_ci 18088c2ecf20Sopenharmony_ci if ((rdev->family == CHIP_RV730) || (rdev->family == CHIP_RV710)) 18098c2ecf20Sopenharmony_ci rv730_get_odt_values(rdev); 18108c2ecf20Sopenharmony_ci} 18118c2ecf20Sopenharmony_ci 18128c2ecf20Sopenharmony_cistatic void rv770_set_dpm_event_sources(struct radeon_device *rdev, u32 sources) 18138c2ecf20Sopenharmony_ci{ 18148c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 18158c2ecf20Sopenharmony_ci bool want_thermal_protection; 18168c2ecf20Sopenharmony_ci enum radeon_dpm_event_src dpm_event_src; 18178c2ecf20Sopenharmony_ci 18188c2ecf20Sopenharmony_ci switch (sources) { 18198c2ecf20Sopenharmony_ci case 0: 18208c2ecf20Sopenharmony_ci default: 18218c2ecf20Sopenharmony_ci want_thermal_protection = false; 18228c2ecf20Sopenharmony_ci break; 18238c2ecf20Sopenharmony_ci case (1 << RADEON_DPM_AUTO_THROTTLE_SRC_THERMAL): 18248c2ecf20Sopenharmony_ci want_thermal_protection = true; 18258c2ecf20Sopenharmony_ci dpm_event_src = RADEON_DPM_EVENT_SRC_DIGITAL; 18268c2ecf20Sopenharmony_ci break; 18278c2ecf20Sopenharmony_ci 18288c2ecf20Sopenharmony_ci case (1 << RADEON_DPM_AUTO_THROTTLE_SRC_EXTERNAL): 18298c2ecf20Sopenharmony_ci want_thermal_protection = true; 18308c2ecf20Sopenharmony_ci dpm_event_src = RADEON_DPM_EVENT_SRC_EXTERNAL; 18318c2ecf20Sopenharmony_ci break; 18328c2ecf20Sopenharmony_ci 18338c2ecf20Sopenharmony_ci case ((1 << RADEON_DPM_AUTO_THROTTLE_SRC_EXTERNAL) | 18348c2ecf20Sopenharmony_ci (1 << RADEON_DPM_AUTO_THROTTLE_SRC_THERMAL)): 18358c2ecf20Sopenharmony_ci want_thermal_protection = true; 18368c2ecf20Sopenharmony_ci dpm_event_src = RADEON_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL; 18378c2ecf20Sopenharmony_ci break; 18388c2ecf20Sopenharmony_ci } 18398c2ecf20Sopenharmony_ci 18408c2ecf20Sopenharmony_ci if (want_thermal_protection) { 18418c2ecf20Sopenharmony_ci WREG32_P(CG_THERMAL_CTRL, DPM_EVENT_SRC(dpm_event_src), ~DPM_EVENT_SRC_MASK); 18428c2ecf20Sopenharmony_ci if (pi->thermal_protection) 18438c2ecf20Sopenharmony_ci WREG32_P(GENERAL_PWRMGT, 0, ~THERMAL_PROTECTION_DIS); 18448c2ecf20Sopenharmony_ci } else { 18458c2ecf20Sopenharmony_ci WREG32_P(GENERAL_PWRMGT, THERMAL_PROTECTION_DIS, ~THERMAL_PROTECTION_DIS); 18468c2ecf20Sopenharmony_ci } 18478c2ecf20Sopenharmony_ci} 18488c2ecf20Sopenharmony_ci 18498c2ecf20Sopenharmony_civoid rv770_enable_auto_throttle_source(struct radeon_device *rdev, 18508c2ecf20Sopenharmony_ci enum radeon_dpm_auto_throttle_src source, 18518c2ecf20Sopenharmony_ci bool enable) 18528c2ecf20Sopenharmony_ci{ 18538c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 18548c2ecf20Sopenharmony_ci 18558c2ecf20Sopenharmony_ci if (enable) { 18568c2ecf20Sopenharmony_ci if (!(pi->active_auto_throttle_sources & (1 << source))) { 18578c2ecf20Sopenharmony_ci pi->active_auto_throttle_sources |= 1 << source; 18588c2ecf20Sopenharmony_ci rv770_set_dpm_event_sources(rdev, pi->active_auto_throttle_sources); 18598c2ecf20Sopenharmony_ci } 18608c2ecf20Sopenharmony_ci } else { 18618c2ecf20Sopenharmony_ci if (pi->active_auto_throttle_sources & (1 << source)) { 18628c2ecf20Sopenharmony_ci pi->active_auto_throttle_sources &= ~(1 << source); 18638c2ecf20Sopenharmony_ci rv770_set_dpm_event_sources(rdev, pi->active_auto_throttle_sources); 18648c2ecf20Sopenharmony_ci } 18658c2ecf20Sopenharmony_ci } 18668c2ecf20Sopenharmony_ci} 18678c2ecf20Sopenharmony_ci 18688c2ecf20Sopenharmony_cistatic int rv770_set_thermal_temperature_range(struct radeon_device *rdev, 18698c2ecf20Sopenharmony_ci int min_temp, int max_temp) 18708c2ecf20Sopenharmony_ci{ 18718c2ecf20Sopenharmony_ci int low_temp = 0 * 1000; 18728c2ecf20Sopenharmony_ci int high_temp = 255 * 1000; 18738c2ecf20Sopenharmony_ci 18748c2ecf20Sopenharmony_ci if (low_temp < min_temp) 18758c2ecf20Sopenharmony_ci low_temp = min_temp; 18768c2ecf20Sopenharmony_ci if (high_temp > max_temp) 18778c2ecf20Sopenharmony_ci high_temp = max_temp; 18788c2ecf20Sopenharmony_ci if (high_temp < low_temp) { 18798c2ecf20Sopenharmony_ci DRM_ERROR("invalid thermal range: %d - %d\n", low_temp, high_temp); 18808c2ecf20Sopenharmony_ci return -EINVAL; 18818c2ecf20Sopenharmony_ci } 18828c2ecf20Sopenharmony_ci 18838c2ecf20Sopenharmony_ci WREG32_P(CG_THERMAL_INT, DIG_THERM_INTH(high_temp / 1000), ~DIG_THERM_INTH_MASK); 18848c2ecf20Sopenharmony_ci WREG32_P(CG_THERMAL_INT, DIG_THERM_INTL(low_temp / 1000), ~DIG_THERM_INTL_MASK); 18858c2ecf20Sopenharmony_ci WREG32_P(CG_THERMAL_CTRL, DIG_THERM_DPM(high_temp / 1000), ~DIG_THERM_DPM_MASK); 18868c2ecf20Sopenharmony_ci 18878c2ecf20Sopenharmony_ci rdev->pm.dpm.thermal.min_temp = low_temp; 18888c2ecf20Sopenharmony_ci rdev->pm.dpm.thermal.max_temp = high_temp; 18898c2ecf20Sopenharmony_ci 18908c2ecf20Sopenharmony_ci return 0; 18918c2ecf20Sopenharmony_ci} 18928c2ecf20Sopenharmony_ci 18938c2ecf20Sopenharmony_ciint rv770_dpm_enable(struct radeon_device *rdev) 18948c2ecf20Sopenharmony_ci{ 18958c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 18968c2ecf20Sopenharmony_ci struct radeon_ps *boot_ps = rdev->pm.dpm.boot_ps; 18978c2ecf20Sopenharmony_ci int ret; 18988c2ecf20Sopenharmony_ci 18998c2ecf20Sopenharmony_ci if (pi->gfx_clock_gating) 19008c2ecf20Sopenharmony_ci rv770_restore_cgcg(rdev); 19018c2ecf20Sopenharmony_ci 19028c2ecf20Sopenharmony_ci if (rv770_dpm_enabled(rdev)) 19038c2ecf20Sopenharmony_ci return -EINVAL; 19048c2ecf20Sopenharmony_ci 19058c2ecf20Sopenharmony_ci if (pi->voltage_control) { 19068c2ecf20Sopenharmony_ci rv770_enable_voltage_control(rdev, true); 19078c2ecf20Sopenharmony_ci ret = rv770_construct_vddc_table(rdev); 19088c2ecf20Sopenharmony_ci if (ret) { 19098c2ecf20Sopenharmony_ci DRM_ERROR("rv770_construct_vddc_table failed\n"); 19108c2ecf20Sopenharmony_ci return ret; 19118c2ecf20Sopenharmony_ci } 19128c2ecf20Sopenharmony_ci } 19138c2ecf20Sopenharmony_ci 19148c2ecf20Sopenharmony_ci if (pi->dcodt) 19158c2ecf20Sopenharmony_ci rv770_retrieve_odt_values(rdev); 19168c2ecf20Sopenharmony_ci 19178c2ecf20Sopenharmony_ci if (pi->mvdd_control) { 19188c2ecf20Sopenharmony_ci ret = rv770_get_mvdd_configuration(rdev); 19198c2ecf20Sopenharmony_ci if (ret) { 19208c2ecf20Sopenharmony_ci DRM_ERROR("rv770_get_mvdd_configuration failed\n"); 19218c2ecf20Sopenharmony_ci return ret; 19228c2ecf20Sopenharmony_ci } 19238c2ecf20Sopenharmony_ci } 19248c2ecf20Sopenharmony_ci 19258c2ecf20Sopenharmony_ci if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_BACKBIAS) 19268c2ecf20Sopenharmony_ci rv770_enable_backbias(rdev, true); 19278c2ecf20Sopenharmony_ci 19288c2ecf20Sopenharmony_ci rv770_enable_spread_spectrum(rdev, true); 19298c2ecf20Sopenharmony_ci 19308c2ecf20Sopenharmony_ci if (pi->thermal_protection) 19318c2ecf20Sopenharmony_ci rv770_enable_thermal_protection(rdev, true); 19328c2ecf20Sopenharmony_ci 19338c2ecf20Sopenharmony_ci rv770_program_mpll_timing_parameters(rdev); 19348c2ecf20Sopenharmony_ci rv770_setup_bsp(rdev); 19358c2ecf20Sopenharmony_ci rv770_program_git(rdev); 19368c2ecf20Sopenharmony_ci rv770_program_tp(rdev); 19378c2ecf20Sopenharmony_ci rv770_program_tpp(rdev); 19388c2ecf20Sopenharmony_ci rv770_program_sstp(rdev); 19398c2ecf20Sopenharmony_ci rv770_program_engine_speed_parameters(rdev); 19408c2ecf20Sopenharmony_ci rv770_enable_display_gap(rdev); 19418c2ecf20Sopenharmony_ci rv770_program_vc(rdev); 19428c2ecf20Sopenharmony_ci 19438c2ecf20Sopenharmony_ci if (pi->dynamic_pcie_gen2) 19448c2ecf20Sopenharmony_ci rv770_enable_dynamic_pcie_gen2(rdev, true); 19458c2ecf20Sopenharmony_ci 19468c2ecf20Sopenharmony_ci ret = rv770_upload_firmware(rdev); 19478c2ecf20Sopenharmony_ci if (ret) { 19488c2ecf20Sopenharmony_ci DRM_ERROR("rv770_upload_firmware failed\n"); 19498c2ecf20Sopenharmony_ci return ret; 19508c2ecf20Sopenharmony_ci } 19518c2ecf20Sopenharmony_ci ret = rv770_init_smc_table(rdev, boot_ps); 19528c2ecf20Sopenharmony_ci if (ret) { 19538c2ecf20Sopenharmony_ci DRM_ERROR("rv770_init_smc_table failed\n"); 19548c2ecf20Sopenharmony_ci return ret; 19558c2ecf20Sopenharmony_ci } 19568c2ecf20Sopenharmony_ci 19578c2ecf20Sopenharmony_ci rv770_program_response_times(rdev); 19588c2ecf20Sopenharmony_ci r7xx_start_smc(rdev); 19598c2ecf20Sopenharmony_ci 19608c2ecf20Sopenharmony_ci if ((rdev->family == CHIP_RV730) || (rdev->family == CHIP_RV710)) 19618c2ecf20Sopenharmony_ci rv730_start_dpm(rdev); 19628c2ecf20Sopenharmony_ci else 19638c2ecf20Sopenharmony_ci rv770_start_dpm(rdev); 19648c2ecf20Sopenharmony_ci 19658c2ecf20Sopenharmony_ci if (pi->gfx_clock_gating) 19668c2ecf20Sopenharmony_ci rv770_gfx_clock_gating_enable(rdev, true); 19678c2ecf20Sopenharmony_ci 19688c2ecf20Sopenharmony_ci if (pi->mg_clock_gating) 19698c2ecf20Sopenharmony_ci rv770_mg_clock_gating_enable(rdev, true); 19708c2ecf20Sopenharmony_ci 19718c2ecf20Sopenharmony_ci rv770_enable_auto_throttle_source(rdev, RADEON_DPM_AUTO_THROTTLE_SRC_THERMAL, true); 19728c2ecf20Sopenharmony_ci 19738c2ecf20Sopenharmony_ci return 0; 19748c2ecf20Sopenharmony_ci} 19758c2ecf20Sopenharmony_ci 19768c2ecf20Sopenharmony_ciint rv770_dpm_late_enable(struct radeon_device *rdev) 19778c2ecf20Sopenharmony_ci{ 19788c2ecf20Sopenharmony_ci int ret; 19798c2ecf20Sopenharmony_ci 19808c2ecf20Sopenharmony_ci if (rdev->irq.installed && 19818c2ecf20Sopenharmony_ci r600_is_internal_thermal_sensor(rdev->pm.int_thermal_type)) { 19828c2ecf20Sopenharmony_ci PPSMC_Result result; 19838c2ecf20Sopenharmony_ci 19848c2ecf20Sopenharmony_ci ret = rv770_set_thermal_temperature_range(rdev, R600_TEMP_RANGE_MIN, R600_TEMP_RANGE_MAX); 19858c2ecf20Sopenharmony_ci if (ret) 19868c2ecf20Sopenharmony_ci return ret; 19878c2ecf20Sopenharmony_ci rdev->irq.dpm_thermal = true; 19888c2ecf20Sopenharmony_ci radeon_irq_set(rdev); 19898c2ecf20Sopenharmony_ci result = rv770_send_msg_to_smc(rdev, PPSMC_MSG_EnableThermalInterrupt); 19908c2ecf20Sopenharmony_ci 19918c2ecf20Sopenharmony_ci if (result != PPSMC_Result_OK) 19928c2ecf20Sopenharmony_ci DRM_DEBUG_KMS("Could not enable thermal interrupts.\n"); 19938c2ecf20Sopenharmony_ci } 19948c2ecf20Sopenharmony_ci 19958c2ecf20Sopenharmony_ci return 0; 19968c2ecf20Sopenharmony_ci} 19978c2ecf20Sopenharmony_ci 19988c2ecf20Sopenharmony_civoid rv770_dpm_disable(struct radeon_device *rdev) 19998c2ecf20Sopenharmony_ci{ 20008c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 20018c2ecf20Sopenharmony_ci 20028c2ecf20Sopenharmony_ci if (!rv770_dpm_enabled(rdev)) 20038c2ecf20Sopenharmony_ci return; 20048c2ecf20Sopenharmony_ci 20058c2ecf20Sopenharmony_ci rv770_clear_vc(rdev); 20068c2ecf20Sopenharmony_ci 20078c2ecf20Sopenharmony_ci if (pi->thermal_protection) 20088c2ecf20Sopenharmony_ci rv770_enable_thermal_protection(rdev, false); 20098c2ecf20Sopenharmony_ci 20108c2ecf20Sopenharmony_ci rv770_enable_spread_spectrum(rdev, false); 20118c2ecf20Sopenharmony_ci 20128c2ecf20Sopenharmony_ci if (pi->dynamic_pcie_gen2) 20138c2ecf20Sopenharmony_ci rv770_enable_dynamic_pcie_gen2(rdev, false); 20148c2ecf20Sopenharmony_ci 20158c2ecf20Sopenharmony_ci if (rdev->irq.installed && 20168c2ecf20Sopenharmony_ci r600_is_internal_thermal_sensor(rdev->pm.int_thermal_type)) { 20178c2ecf20Sopenharmony_ci rdev->irq.dpm_thermal = false; 20188c2ecf20Sopenharmony_ci radeon_irq_set(rdev); 20198c2ecf20Sopenharmony_ci } 20208c2ecf20Sopenharmony_ci 20218c2ecf20Sopenharmony_ci if (pi->gfx_clock_gating) 20228c2ecf20Sopenharmony_ci rv770_gfx_clock_gating_enable(rdev, false); 20238c2ecf20Sopenharmony_ci 20248c2ecf20Sopenharmony_ci if (pi->mg_clock_gating) 20258c2ecf20Sopenharmony_ci rv770_mg_clock_gating_enable(rdev, false); 20268c2ecf20Sopenharmony_ci 20278c2ecf20Sopenharmony_ci if ((rdev->family == CHIP_RV730) || (rdev->family == CHIP_RV710)) 20288c2ecf20Sopenharmony_ci rv730_stop_dpm(rdev); 20298c2ecf20Sopenharmony_ci else 20308c2ecf20Sopenharmony_ci rv770_stop_dpm(rdev); 20318c2ecf20Sopenharmony_ci 20328c2ecf20Sopenharmony_ci r7xx_stop_smc(rdev); 20338c2ecf20Sopenharmony_ci rv770_reset_smio_status(rdev); 20348c2ecf20Sopenharmony_ci} 20358c2ecf20Sopenharmony_ci 20368c2ecf20Sopenharmony_ciint rv770_dpm_set_power_state(struct radeon_device *rdev) 20378c2ecf20Sopenharmony_ci{ 20388c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 20398c2ecf20Sopenharmony_ci struct radeon_ps *new_ps = rdev->pm.dpm.requested_ps; 20408c2ecf20Sopenharmony_ci struct radeon_ps *old_ps = rdev->pm.dpm.current_ps; 20418c2ecf20Sopenharmony_ci int ret; 20428c2ecf20Sopenharmony_ci 20438c2ecf20Sopenharmony_ci ret = rv770_restrict_performance_levels_before_switch(rdev); 20448c2ecf20Sopenharmony_ci if (ret) { 20458c2ecf20Sopenharmony_ci DRM_ERROR("rv770_restrict_performance_levels_before_switch failed\n"); 20468c2ecf20Sopenharmony_ci return ret; 20478c2ecf20Sopenharmony_ci } 20488c2ecf20Sopenharmony_ci rv770_set_uvd_clock_before_set_eng_clock(rdev, new_ps, old_ps); 20498c2ecf20Sopenharmony_ci ret = rv770_halt_smc(rdev); 20508c2ecf20Sopenharmony_ci if (ret) { 20518c2ecf20Sopenharmony_ci DRM_ERROR("rv770_halt_smc failed\n"); 20528c2ecf20Sopenharmony_ci return ret; 20538c2ecf20Sopenharmony_ci } 20548c2ecf20Sopenharmony_ci ret = rv770_upload_sw_state(rdev, new_ps); 20558c2ecf20Sopenharmony_ci if (ret) { 20568c2ecf20Sopenharmony_ci DRM_ERROR("rv770_upload_sw_state failed\n"); 20578c2ecf20Sopenharmony_ci return ret; 20588c2ecf20Sopenharmony_ci } 20598c2ecf20Sopenharmony_ci r7xx_program_memory_timing_parameters(rdev, new_ps); 20608c2ecf20Sopenharmony_ci if (pi->dcodt) 20618c2ecf20Sopenharmony_ci rv770_program_dcodt_before_state_switch(rdev, new_ps, old_ps); 20628c2ecf20Sopenharmony_ci ret = rv770_resume_smc(rdev); 20638c2ecf20Sopenharmony_ci if (ret) { 20648c2ecf20Sopenharmony_ci DRM_ERROR("rv770_resume_smc failed\n"); 20658c2ecf20Sopenharmony_ci return ret; 20668c2ecf20Sopenharmony_ci } 20678c2ecf20Sopenharmony_ci ret = rv770_set_sw_state(rdev); 20688c2ecf20Sopenharmony_ci if (ret) { 20698c2ecf20Sopenharmony_ci DRM_ERROR("rv770_set_sw_state failed\n"); 20708c2ecf20Sopenharmony_ci return ret; 20718c2ecf20Sopenharmony_ci } 20728c2ecf20Sopenharmony_ci if (pi->dcodt) 20738c2ecf20Sopenharmony_ci rv770_program_dcodt_after_state_switch(rdev, new_ps, old_ps); 20748c2ecf20Sopenharmony_ci rv770_set_uvd_clock_after_set_eng_clock(rdev, new_ps, old_ps); 20758c2ecf20Sopenharmony_ci 20768c2ecf20Sopenharmony_ci return 0; 20778c2ecf20Sopenharmony_ci} 20788c2ecf20Sopenharmony_ci 20798c2ecf20Sopenharmony_ci#if 0 20808c2ecf20Sopenharmony_civoid rv770_dpm_reset_asic(struct radeon_device *rdev) 20818c2ecf20Sopenharmony_ci{ 20828c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 20838c2ecf20Sopenharmony_ci struct radeon_ps *boot_ps = rdev->pm.dpm.boot_ps; 20848c2ecf20Sopenharmony_ci 20858c2ecf20Sopenharmony_ci rv770_restrict_performance_levels_before_switch(rdev); 20868c2ecf20Sopenharmony_ci if (pi->dcodt) 20878c2ecf20Sopenharmony_ci rv770_program_dcodt_before_state_switch(rdev, boot_ps, boot_ps); 20888c2ecf20Sopenharmony_ci rv770_set_boot_state(rdev); 20898c2ecf20Sopenharmony_ci if (pi->dcodt) 20908c2ecf20Sopenharmony_ci rv770_program_dcodt_after_state_switch(rdev, boot_ps, boot_ps); 20918c2ecf20Sopenharmony_ci} 20928c2ecf20Sopenharmony_ci#endif 20938c2ecf20Sopenharmony_ci 20948c2ecf20Sopenharmony_civoid rv770_dpm_setup_asic(struct radeon_device *rdev) 20958c2ecf20Sopenharmony_ci{ 20968c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 20978c2ecf20Sopenharmony_ci 20988c2ecf20Sopenharmony_ci r7xx_read_clock_registers(rdev); 20998c2ecf20Sopenharmony_ci rv770_read_voltage_smio_registers(rdev); 21008c2ecf20Sopenharmony_ci rv770_get_memory_type(rdev); 21018c2ecf20Sopenharmony_ci if (pi->dcodt) 21028c2ecf20Sopenharmony_ci rv770_get_mclk_odt_threshold(rdev); 21038c2ecf20Sopenharmony_ci rv770_get_pcie_gen2_status(rdev); 21048c2ecf20Sopenharmony_ci 21058c2ecf20Sopenharmony_ci rv770_enable_acpi_pm(rdev); 21068c2ecf20Sopenharmony_ci 21078c2ecf20Sopenharmony_ci if (radeon_aspm != 0) { 21088c2ecf20Sopenharmony_ci if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_ASPM_L0s) 21098c2ecf20Sopenharmony_ci rv770_enable_l0s(rdev); 21108c2ecf20Sopenharmony_ci if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_ASPM_L1) 21118c2ecf20Sopenharmony_ci rv770_enable_l1(rdev); 21128c2ecf20Sopenharmony_ci if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_TURNOFFPLL_ASPML1) 21138c2ecf20Sopenharmony_ci rv770_enable_pll_sleep_in_l1(rdev); 21148c2ecf20Sopenharmony_ci } 21158c2ecf20Sopenharmony_ci} 21168c2ecf20Sopenharmony_ci 21178c2ecf20Sopenharmony_civoid rv770_dpm_display_configuration_changed(struct radeon_device *rdev) 21188c2ecf20Sopenharmony_ci{ 21198c2ecf20Sopenharmony_ci rv770_program_display_gap(rdev); 21208c2ecf20Sopenharmony_ci} 21218c2ecf20Sopenharmony_ci 21228c2ecf20Sopenharmony_ciunion power_info { 21238c2ecf20Sopenharmony_ci struct _ATOM_POWERPLAY_INFO info; 21248c2ecf20Sopenharmony_ci struct _ATOM_POWERPLAY_INFO_V2 info_2; 21258c2ecf20Sopenharmony_ci struct _ATOM_POWERPLAY_INFO_V3 info_3; 21268c2ecf20Sopenharmony_ci struct _ATOM_PPLIB_POWERPLAYTABLE pplib; 21278c2ecf20Sopenharmony_ci struct _ATOM_PPLIB_POWERPLAYTABLE2 pplib2; 21288c2ecf20Sopenharmony_ci struct _ATOM_PPLIB_POWERPLAYTABLE3 pplib3; 21298c2ecf20Sopenharmony_ci}; 21308c2ecf20Sopenharmony_ci 21318c2ecf20Sopenharmony_ciunion pplib_clock_info { 21328c2ecf20Sopenharmony_ci struct _ATOM_PPLIB_R600_CLOCK_INFO r600; 21338c2ecf20Sopenharmony_ci struct _ATOM_PPLIB_RS780_CLOCK_INFO rs780; 21348c2ecf20Sopenharmony_ci struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO evergreen; 21358c2ecf20Sopenharmony_ci struct _ATOM_PPLIB_SUMO_CLOCK_INFO sumo; 21368c2ecf20Sopenharmony_ci}; 21378c2ecf20Sopenharmony_ci 21388c2ecf20Sopenharmony_ciunion pplib_power_state { 21398c2ecf20Sopenharmony_ci struct _ATOM_PPLIB_STATE v1; 21408c2ecf20Sopenharmony_ci struct _ATOM_PPLIB_STATE_V2 v2; 21418c2ecf20Sopenharmony_ci}; 21428c2ecf20Sopenharmony_ci 21438c2ecf20Sopenharmony_cistatic void rv7xx_parse_pplib_non_clock_info(struct radeon_device *rdev, 21448c2ecf20Sopenharmony_ci struct radeon_ps *rps, 21458c2ecf20Sopenharmony_ci struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info, 21468c2ecf20Sopenharmony_ci u8 table_rev) 21478c2ecf20Sopenharmony_ci{ 21488c2ecf20Sopenharmony_ci rps->caps = le32_to_cpu(non_clock_info->ulCapsAndSettings); 21498c2ecf20Sopenharmony_ci rps->class = le16_to_cpu(non_clock_info->usClassification); 21508c2ecf20Sopenharmony_ci rps->class2 = le16_to_cpu(non_clock_info->usClassification2); 21518c2ecf20Sopenharmony_ci 21528c2ecf20Sopenharmony_ci if (ATOM_PPLIB_NONCLOCKINFO_VER1 < table_rev) { 21538c2ecf20Sopenharmony_ci rps->vclk = le32_to_cpu(non_clock_info->ulVCLK); 21548c2ecf20Sopenharmony_ci rps->dclk = le32_to_cpu(non_clock_info->ulDCLK); 21558c2ecf20Sopenharmony_ci } else { 21568c2ecf20Sopenharmony_ci rps->vclk = 0; 21578c2ecf20Sopenharmony_ci rps->dclk = 0; 21588c2ecf20Sopenharmony_ci } 21598c2ecf20Sopenharmony_ci 21608c2ecf20Sopenharmony_ci if (r600_is_uvd_state(rps->class, rps->class2)) { 21618c2ecf20Sopenharmony_ci if ((rps->vclk == 0) || (rps->dclk == 0)) { 21628c2ecf20Sopenharmony_ci rps->vclk = RV770_DEFAULT_VCLK_FREQ; 21638c2ecf20Sopenharmony_ci rps->dclk = RV770_DEFAULT_DCLK_FREQ; 21648c2ecf20Sopenharmony_ci } 21658c2ecf20Sopenharmony_ci } 21668c2ecf20Sopenharmony_ci 21678c2ecf20Sopenharmony_ci if (rps->class & ATOM_PPLIB_CLASSIFICATION_BOOT) 21688c2ecf20Sopenharmony_ci rdev->pm.dpm.boot_ps = rps; 21698c2ecf20Sopenharmony_ci if (rps->class & ATOM_PPLIB_CLASSIFICATION_UVDSTATE) 21708c2ecf20Sopenharmony_ci rdev->pm.dpm.uvd_ps = rps; 21718c2ecf20Sopenharmony_ci} 21728c2ecf20Sopenharmony_ci 21738c2ecf20Sopenharmony_cistatic void rv7xx_parse_pplib_clock_info(struct radeon_device *rdev, 21748c2ecf20Sopenharmony_ci struct radeon_ps *rps, int index, 21758c2ecf20Sopenharmony_ci union pplib_clock_info *clock_info) 21768c2ecf20Sopenharmony_ci{ 21778c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 21788c2ecf20Sopenharmony_ci struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev); 21798c2ecf20Sopenharmony_ci struct rv7xx_ps *ps = rv770_get_ps(rps); 21808c2ecf20Sopenharmony_ci u32 sclk, mclk; 21818c2ecf20Sopenharmony_ci struct rv7xx_pl *pl; 21828c2ecf20Sopenharmony_ci 21838c2ecf20Sopenharmony_ci switch (index) { 21848c2ecf20Sopenharmony_ci case 0: 21858c2ecf20Sopenharmony_ci pl = &ps->low; 21868c2ecf20Sopenharmony_ci break; 21878c2ecf20Sopenharmony_ci case 1: 21888c2ecf20Sopenharmony_ci pl = &ps->medium; 21898c2ecf20Sopenharmony_ci break; 21908c2ecf20Sopenharmony_ci case 2: 21918c2ecf20Sopenharmony_ci default: 21928c2ecf20Sopenharmony_ci pl = &ps->high; 21938c2ecf20Sopenharmony_ci break; 21948c2ecf20Sopenharmony_ci } 21958c2ecf20Sopenharmony_ci 21968c2ecf20Sopenharmony_ci if (rdev->family >= CHIP_CEDAR) { 21978c2ecf20Sopenharmony_ci sclk = le16_to_cpu(clock_info->evergreen.usEngineClockLow); 21988c2ecf20Sopenharmony_ci sclk |= clock_info->evergreen.ucEngineClockHigh << 16; 21998c2ecf20Sopenharmony_ci mclk = le16_to_cpu(clock_info->evergreen.usMemoryClockLow); 22008c2ecf20Sopenharmony_ci mclk |= clock_info->evergreen.ucMemoryClockHigh << 16; 22018c2ecf20Sopenharmony_ci 22028c2ecf20Sopenharmony_ci pl->vddc = le16_to_cpu(clock_info->evergreen.usVDDC); 22038c2ecf20Sopenharmony_ci pl->vddci = le16_to_cpu(clock_info->evergreen.usVDDCI); 22048c2ecf20Sopenharmony_ci pl->flags = le32_to_cpu(clock_info->evergreen.ulFlags); 22058c2ecf20Sopenharmony_ci } else { 22068c2ecf20Sopenharmony_ci sclk = le16_to_cpu(clock_info->r600.usEngineClockLow); 22078c2ecf20Sopenharmony_ci sclk |= clock_info->r600.ucEngineClockHigh << 16; 22088c2ecf20Sopenharmony_ci mclk = le16_to_cpu(clock_info->r600.usMemoryClockLow); 22098c2ecf20Sopenharmony_ci mclk |= clock_info->r600.ucMemoryClockHigh << 16; 22108c2ecf20Sopenharmony_ci 22118c2ecf20Sopenharmony_ci pl->vddc = le16_to_cpu(clock_info->r600.usVDDC); 22128c2ecf20Sopenharmony_ci pl->flags = le32_to_cpu(clock_info->r600.ulFlags); 22138c2ecf20Sopenharmony_ci } 22148c2ecf20Sopenharmony_ci 22158c2ecf20Sopenharmony_ci pl->mclk = mclk; 22168c2ecf20Sopenharmony_ci pl->sclk = sclk; 22178c2ecf20Sopenharmony_ci 22188c2ecf20Sopenharmony_ci /* patch up vddc if necessary */ 22198c2ecf20Sopenharmony_ci if (pl->vddc == 0xff01) { 22208c2ecf20Sopenharmony_ci if (pi->max_vddc) 22218c2ecf20Sopenharmony_ci pl->vddc = pi->max_vddc; 22228c2ecf20Sopenharmony_ci } 22238c2ecf20Sopenharmony_ci 22248c2ecf20Sopenharmony_ci if (rps->class & ATOM_PPLIB_CLASSIFICATION_ACPI) { 22258c2ecf20Sopenharmony_ci pi->acpi_vddc = pl->vddc; 22268c2ecf20Sopenharmony_ci if (rdev->family >= CHIP_CEDAR) 22278c2ecf20Sopenharmony_ci eg_pi->acpi_vddci = pl->vddci; 22288c2ecf20Sopenharmony_ci if (ps->low.flags & ATOM_PPLIB_R600_FLAGS_PCIEGEN2) 22298c2ecf20Sopenharmony_ci pi->acpi_pcie_gen2 = true; 22308c2ecf20Sopenharmony_ci else 22318c2ecf20Sopenharmony_ci pi->acpi_pcie_gen2 = false; 22328c2ecf20Sopenharmony_ci } 22338c2ecf20Sopenharmony_ci 22348c2ecf20Sopenharmony_ci if (rps->class2 & ATOM_PPLIB_CLASSIFICATION2_ULV) { 22358c2ecf20Sopenharmony_ci if (rdev->family >= CHIP_BARTS) { 22368c2ecf20Sopenharmony_ci eg_pi->ulv.supported = true; 22378c2ecf20Sopenharmony_ci eg_pi->ulv.pl = pl; 22388c2ecf20Sopenharmony_ci } 22398c2ecf20Sopenharmony_ci } 22408c2ecf20Sopenharmony_ci 22418c2ecf20Sopenharmony_ci if (pi->min_vddc_in_table > pl->vddc) 22428c2ecf20Sopenharmony_ci pi->min_vddc_in_table = pl->vddc; 22438c2ecf20Sopenharmony_ci 22448c2ecf20Sopenharmony_ci if (pi->max_vddc_in_table < pl->vddc) 22458c2ecf20Sopenharmony_ci pi->max_vddc_in_table = pl->vddc; 22468c2ecf20Sopenharmony_ci 22478c2ecf20Sopenharmony_ci /* patch up boot state */ 22488c2ecf20Sopenharmony_ci if (rps->class & ATOM_PPLIB_CLASSIFICATION_BOOT) { 22498c2ecf20Sopenharmony_ci u16 vddc, vddci, mvdd; 22508c2ecf20Sopenharmony_ci radeon_atombios_get_default_voltages(rdev, &vddc, &vddci, &mvdd); 22518c2ecf20Sopenharmony_ci pl->mclk = rdev->clock.default_mclk; 22528c2ecf20Sopenharmony_ci pl->sclk = rdev->clock.default_sclk; 22538c2ecf20Sopenharmony_ci pl->vddc = vddc; 22548c2ecf20Sopenharmony_ci pl->vddci = vddci; 22558c2ecf20Sopenharmony_ci } 22568c2ecf20Sopenharmony_ci 22578c2ecf20Sopenharmony_ci if ((rps->class & ATOM_PPLIB_CLASSIFICATION_UI_MASK) == 22588c2ecf20Sopenharmony_ci ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE) { 22598c2ecf20Sopenharmony_ci rdev->pm.dpm.dyn_state.max_clock_voltage_on_ac.sclk = pl->sclk; 22608c2ecf20Sopenharmony_ci rdev->pm.dpm.dyn_state.max_clock_voltage_on_ac.mclk = pl->mclk; 22618c2ecf20Sopenharmony_ci rdev->pm.dpm.dyn_state.max_clock_voltage_on_ac.vddc = pl->vddc; 22628c2ecf20Sopenharmony_ci rdev->pm.dpm.dyn_state.max_clock_voltage_on_ac.vddci = pl->vddci; 22638c2ecf20Sopenharmony_ci } 22648c2ecf20Sopenharmony_ci} 22658c2ecf20Sopenharmony_ci 22668c2ecf20Sopenharmony_ciint rv7xx_parse_power_table(struct radeon_device *rdev) 22678c2ecf20Sopenharmony_ci{ 22688c2ecf20Sopenharmony_ci struct radeon_mode_info *mode_info = &rdev->mode_info; 22698c2ecf20Sopenharmony_ci struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info; 22708c2ecf20Sopenharmony_ci union pplib_power_state *power_state; 22718c2ecf20Sopenharmony_ci int i, j; 22728c2ecf20Sopenharmony_ci union pplib_clock_info *clock_info; 22738c2ecf20Sopenharmony_ci union power_info *power_info; 22748c2ecf20Sopenharmony_ci int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo); 22758c2ecf20Sopenharmony_ci u16 data_offset; 22768c2ecf20Sopenharmony_ci u8 frev, crev; 22778c2ecf20Sopenharmony_ci struct rv7xx_ps *ps; 22788c2ecf20Sopenharmony_ci 22798c2ecf20Sopenharmony_ci if (!atom_parse_data_header(mode_info->atom_context, index, NULL, 22808c2ecf20Sopenharmony_ci &frev, &crev, &data_offset)) 22818c2ecf20Sopenharmony_ci return -EINVAL; 22828c2ecf20Sopenharmony_ci power_info = (union power_info *)(mode_info->atom_context->bios + data_offset); 22838c2ecf20Sopenharmony_ci 22848c2ecf20Sopenharmony_ci rdev->pm.dpm.ps = kcalloc(power_info->pplib.ucNumStates, 22858c2ecf20Sopenharmony_ci sizeof(struct radeon_ps), 22868c2ecf20Sopenharmony_ci GFP_KERNEL); 22878c2ecf20Sopenharmony_ci if (!rdev->pm.dpm.ps) 22888c2ecf20Sopenharmony_ci return -ENOMEM; 22898c2ecf20Sopenharmony_ci 22908c2ecf20Sopenharmony_ci for (i = 0; i < power_info->pplib.ucNumStates; i++) { 22918c2ecf20Sopenharmony_ci power_state = (union pplib_power_state *) 22928c2ecf20Sopenharmony_ci (mode_info->atom_context->bios + data_offset + 22938c2ecf20Sopenharmony_ci le16_to_cpu(power_info->pplib.usStateArrayOffset) + 22948c2ecf20Sopenharmony_ci i * power_info->pplib.ucStateEntrySize); 22958c2ecf20Sopenharmony_ci non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *) 22968c2ecf20Sopenharmony_ci (mode_info->atom_context->bios + data_offset + 22978c2ecf20Sopenharmony_ci le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset) + 22988c2ecf20Sopenharmony_ci (power_state->v1.ucNonClockStateIndex * 22998c2ecf20Sopenharmony_ci power_info->pplib.ucNonClockSize)); 23008c2ecf20Sopenharmony_ci if (power_info->pplib.ucStateEntrySize - 1) { 23018c2ecf20Sopenharmony_ci u8 *idx; 23028c2ecf20Sopenharmony_ci ps = kzalloc(sizeof(struct rv7xx_ps), GFP_KERNEL); 23038c2ecf20Sopenharmony_ci if (ps == NULL) { 23048c2ecf20Sopenharmony_ci kfree(rdev->pm.dpm.ps); 23058c2ecf20Sopenharmony_ci return -ENOMEM; 23068c2ecf20Sopenharmony_ci } 23078c2ecf20Sopenharmony_ci rdev->pm.dpm.ps[i].ps_priv = ps; 23088c2ecf20Sopenharmony_ci rv7xx_parse_pplib_non_clock_info(rdev, &rdev->pm.dpm.ps[i], 23098c2ecf20Sopenharmony_ci non_clock_info, 23108c2ecf20Sopenharmony_ci power_info->pplib.ucNonClockSize); 23118c2ecf20Sopenharmony_ci idx = (u8 *)&power_state->v1.ucClockStateIndices[0]; 23128c2ecf20Sopenharmony_ci for (j = 0; j < (power_info->pplib.ucStateEntrySize - 1); j++) { 23138c2ecf20Sopenharmony_ci clock_info = (union pplib_clock_info *) 23148c2ecf20Sopenharmony_ci (mode_info->atom_context->bios + data_offset + 23158c2ecf20Sopenharmony_ci le16_to_cpu(power_info->pplib.usClockInfoArrayOffset) + 23168c2ecf20Sopenharmony_ci (idx[j] * power_info->pplib.ucClockInfoSize)); 23178c2ecf20Sopenharmony_ci rv7xx_parse_pplib_clock_info(rdev, 23188c2ecf20Sopenharmony_ci &rdev->pm.dpm.ps[i], j, 23198c2ecf20Sopenharmony_ci clock_info); 23208c2ecf20Sopenharmony_ci } 23218c2ecf20Sopenharmony_ci } 23228c2ecf20Sopenharmony_ci } 23238c2ecf20Sopenharmony_ci rdev->pm.dpm.num_ps = power_info->pplib.ucNumStates; 23248c2ecf20Sopenharmony_ci return 0; 23258c2ecf20Sopenharmony_ci} 23268c2ecf20Sopenharmony_ci 23278c2ecf20Sopenharmony_civoid rv770_get_engine_memory_ss(struct radeon_device *rdev) 23288c2ecf20Sopenharmony_ci{ 23298c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi = rv770_get_pi(rdev); 23308c2ecf20Sopenharmony_ci struct radeon_atom_ss ss; 23318c2ecf20Sopenharmony_ci 23328c2ecf20Sopenharmony_ci pi->sclk_ss = radeon_atombios_get_asic_ss_info(rdev, &ss, 23338c2ecf20Sopenharmony_ci ASIC_INTERNAL_ENGINE_SS, 0); 23348c2ecf20Sopenharmony_ci pi->mclk_ss = radeon_atombios_get_asic_ss_info(rdev, &ss, 23358c2ecf20Sopenharmony_ci ASIC_INTERNAL_MEMORY_SS, 0); 23368c2ecf20Sopenharmony_ci 23378c2ecf20Sopenharmony_ci if (pi->sclk_ss || pi->mclk_ss) 23388c2ecf20Sopenharmony_ci pi->dynamic_ss = true; 23398c2ecf20Sopenharmony_ci else 23408c2ecf20Sopenharmony_ci pi->dynamic_ss = false; 23418c2ecf20Sopenharmony_ci} 23428c2ecf20Sopenharmony_ci 23438c2ecf20Sopenharmony_ciint rv770_dpm_init(struct radeon_device *rdev) 23448c2ecf20Sopenharmony_ci{ 23458c2ecf20Sopenharmony_ci struct rv7xx_power_info *pi; 23468c2ecf20Sopenharmony_ci struct atom_clock_dividers dividers; 23478c2ecf20Sopenharmony_ci int ret; 23488c2ecf20Sopenharmony_ci 23498c2ecf20Sopenharmony_ci pi = kzalloc(sizeof(struct rv7xx_power_info), GFP_KERNEL); 23508c2ecf20Sopenharmony_ci if (pi == NULL) 23518c2ecf20Sopenharmony_ci return -ENOMEM; 23528c2ecf20Sopenharmony_ci rdev->pm.dpm.priv = pi; 23538c2ecf20Sopenharmony_ci 23548c2ecf20Sopenharmony_ci rv770_get_max_vddc(rdev); 23558c2ecf20Sopenharmony_ci 23568c2ecf20Sopenharmony_ci pi->acpi_vddc = 0; 23578c2ecf20Sopenharmony_ci pi->min_vddc_in_table = 0; 23588c2ecf20Sopenharmony_ci pi->max_vddc_in_table = 0; 23598c2ecf20Sopenharmony_ci 23608c2ecf20Sopenharmony_ci ret = r600_get_platform_caps(rdev); 23618c2ecf20Sopenharmony_ci if (ret) 23628c2ecf20Sopenharmony_ci return ret; 23638c2ecf20Sopenharmony_ci 23648c2ecf20Sopenharmony_ci ret = rv7xx_parse_power_table(rdev); 23658c2ecf20Sopenharmony_ci if (ret) 23668c2ecf20Sopenharmony_ci return ret; 23678c2ecf20Sopenharmony_ci 23688c2ecf20Sopenharmony_ci if (rdev->pm.dpm.voltage_response_time == 0) 23698c2ecf20Sopenharmony_ci rdev->pm.dpm.voltage_response_time = R600_VOLTAGERESPONSETIME_DFLT; 23708c2ecf20Sopenharmony_ci if (rdev->pm.dpm.backbias_response_time == 0) 23718c2ecf20Sopenharmony_ci rdev->pm.dpm.backbias_response_time = R600_BACKBIASRESPONSETIME_DFLT; 23728c2ecf20Sopenharmony_ci 23738c2ecf20Sopenharmony_ci ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM, 23748c2ecf20Sopenharmony_ci 0, false, ÷rs); 23758c2ecf20Sopenharmony_ci if (ret) 23768c2ecf20Sopenharmony_ci pi->ref_div = dividers.ref_div + 1; 23778c2ecf20Sopenharmony_ci else 23788c2ecf20Sopenharmony_ci pi->ref_div = R600_REFERENCEDIVIDER_DFLT; 23798c2ecf20Sopenharmony_ci 23808c2ecf20Sopenharmony_ci pi->mclk_strobe_mode_threshold = 30000; 23818c2ecf20Sopenharmony_ci pi->mclk_edc_enable_threshold = 30000; 23828c2ecf20Sopenharmony_ci 23838c2ecf20Sopenharmony_ci pi->rlp = RV770_RLP_DFLT; 23848c2ecf20Sopenharmony_ci pi->rmp = RV770_RMP_DFLT; 23858c2ecf20Sopenharmony_ci pi->lhp = RV770_LHP_DFLT; 23868c2ecf20Sopenharmony_ci pi->lmp = RV770_LMP_DFLT; 23878c2ecf20Sopenharmony_ci 23888c2ecf20Sopenharmony_ci pi->voltage_control = 23898c2ecf20Sopenharmony_ci radeon_atom_is_voltage_gpio(rdev, SET_VOLTAGE_TYPE_ASIC_VDDC, 0); 23908c2ecf20Sopenharmony_ci 23918c2ecf20Sopenharmony_ci pi->mvdd_control = 23928c2ecf20Sopenharmony_ci radeon_atom_is_voltage_gpio(rdev, SET_VOLTAGE_TYPE_ASIC_MVDDC, 0); 23938c2ecf20Sopenharmony_ci 23948c2ecf20Sopenharmony_ci rv770_get_engine_memory_ss(rdev); 23958c2ecf20Sopenharmony_ci 23968c2ecf20Sopenharmony_ci pi->asi = RV770_ASI_DFLT; 23978c2ecf20Sopenharmony_ci pi->pasi = RV770_HASI_DFLT; 23988c2ecf20Sopenharmony_ci pi->vrc = RV770_VRC_DFLT; 23998c2ecf20Sopenharmony_ci 24008c2ecf20Sopenharmony_ci pi->power_gating = false; 24018c2ecf20Sopenharmony_ci 24028c2ecf20Sopenharmony_ci pi->gfx_clock_gating = true; 24038c2ecf20Sopenharmony_ci 24048c2ecf20Sopenharmony_ci pi->mg_clock_gating = true; 24058c2ecf20Sopenharmony_ci pi->mgcgtssm = true; 24068c2ecf20Sopenharmony_ci 24078c2ecf20Sopenharmony_ci pi->dynamic_pcie_gen2 = true; 24088c2ecf20Sopenharmony_ci 24098c2ecf20Sopenharmony_ci if (rdev->pm.int_thermal_type != THERMAL_TYPE_NONE) 24108c2ecf20Sopenharmony_ci pi->thermal_protection = true; 24118c2ecf20Sopenharmony_ci else 24128c2ecf20Sopenharmony_ci pi->thermal_protection = false; 24138c2ecf20Sopenharmony_ci 24148c2ecf20Sopenharmony_ci pi->display_gap = true; 24158c2ecf20Sopenharmony_ci 24168c2ecf20Sopenharmony_ci if (rdev->flags & RADEON_IS_MOBILITY) 24178c2ecf20Sopenharmony_ci pi->dcodt = true; 24188c2ecf20Sopenharmony_ci else 24198c2ecf20Sopenharmony_ci pi->dcodt = false; 24208c2ecf20Sopenharmony_ci 24218c2ecf20Sopenharmony_ci pi->ulps = true; 24228c2ecf20Sopenharmony_ci 24238c2ecf20Sopenharmony_ci pi->mclk_stutter_mode_threshold = 0; 24248c2ecf20Sopenharmony_ci 24258c2ecf20Sopenharmony_ci pi->sram_end = SMC_RAM_END; 24268c2ecf20Sopenharmony_ci pi->state_table_start = RV770_SMC_TABLE_ADDRESS; 24278c2ecf20Sopenharmony_ci pi->soft_regs_start = RV770_SMC_SOFT_REGISTERS_START; 24288c2ecf20Sopenharmony_ci 24298c2ecf20Sopenharmony_ci return 0; 24308c2ecf20Sopenharmony_ci} 24318c2ecf20Sopenharmony_ci 24328c2ecf20Sopenharmony_civoid rv770_dpm_print_power_state(struct radeon_device *rdev, 24338c2ecf20Sopenharmony_ci struct radeon_ps *rps) 24348c2ecf20Sopenharmony_ci{ 24358c2ecf20Sopenharmony_ci struct rv7xx_ps *ps = rv770_get_ps(rps); 24368c2ecf20Sopenharmony_ci struct rv7xx_pl *pl; 24378c2ecf20Sopenharmony_ci 24388c2ecf20Sopenharmony_ci r600_dpm_print_class_info(rps->class, rps->class2); 24398c2ecf20Sopenharmony_ci r600_dpm_print_cap_info(rps->caps); 24408c2ecf20Sopenharmony_ci printk("\tuvd vclk: %d dclk: %d\n", rps->vclk, rps->dclk); 24418c2ecf20Sopenharmony_ci if (rdev->family >= CHIP_CEDAR) { 24428c2ecf20Sopenharmony_ci pl = &ps->low; 24438c2ecf20Sopenharmony_ci printk("\t\tpower level 0 sclk: %u mclk: %u vddc: %u vddci: %u\n", 24448c2ecf20Sopenharmony_ci pl->sclk, pl->mclk, pl->vddc, pl->vddci); 24458c2ecf20Sopenharmony_ci pl = &ps->medium; 24468c2ecf20Sopenharmony_ci printk("\t\tpower level 1 sclk: %u mclk: %u vddc: %u vddci: %u\n", 24478c2ecf20Sopenharmony_ci pl->sclk, pl->mclk, pl->vddc, pl->vddci); 24488c2ecf20Sopenharmony_ci pl = &ps->high; 24498c2ecf20Sopenharmony_ci printk("\t\tpower level 2 sclk: %u mclk: %u vddc: %u vddci: %u\n", 24508c2ecf20Sopenharmony_ci pl->sclk, pl->mclk, pl->vddc, pl->vddci); 24518c2ecf20Sopenharmony_ci } else { 24528c2ecf20Sopenharmony_ci pl = &ps->low; 24538c2ecf20Sopenharmony_ci printk("\t\tpower level 0 sclk: %u mclk: %u vddc: %u\n", 24548c2ecf20Sopenharmony_ci pl->sclk, pl->mclk, pl->vddc); 24558c2ecf20Sopenharmony_ci pl = &ps->medium; 24568c2ecf20Sopenharmony_ci printk("\t\tpower level 1 sclk: %u mclk: %u vddc: %u\n", 24578c2ecf20Sopenharmony_ci pl->sclk, pl->mclk, pl->vddc); 24588c2ecf20Sopenharmony_ci pl = &ps->high; 24598c2ecf20Sopenharmony_ci printk("\t\tpower level 2 sclk: %u mclk: %u vddc: %u\n", 24608c2ecf20Sopenharmony_ci pl->sclk, pl->mclk, pl->vddc); 24618c2ecf20Sopenharmony_ci } 24628c2ecf20Sopenharmony_ci r600_dpm_print_ps_status(rdev, rps); 24638c2ecf20Sopenharmony_ci} 24648c2ecf20Sopenharmony_ci 24658c2ecf20Sopenharmony_civoid rv770_dpm_debugfs_print_current_performance_level(struct radeon_device *rdev, 24668c2ecf20Sopenharmony_ci struct seq_file *m) 24678c2ecf20Sopenharmony_ci{ 24688c2ecf20Sopenharmony_ci struct radeon_ps *rps = rdev->pm.dpm.current_ps; 24698c2ecf20Sopenharmony_ci struct rv7xx_ps *ps = rv770_get_ps(rps); 24708c2ecf20Sopenharmony_ci struct rv7xx_pl *pl; 24718c2ecf20Sopenharmony_ci u32 current_index = 24728c2ecf20Sopenharmony_ci (RREG32(TARGET_AND_CURRENT_PROFILE_INDEX) & CURRENT_PROFILE_INDEX_MASK) >> 24738c2ecf20Sopenharmony_ci CURRENT_PROFILE_INDEX_SHIFT; 24748c2ecf20Sopenharmony_ci 24758c2ecf20Sopenharmony_ci if (current_index > 2) { 24768c2ecf20Sopenharmony_ci seq_printf(m, "invalid dpm profile %d\n", current_index); 24778c2ecf20Sopenharmony_ci } else { 24788c2ecf20Sopenharmony_ci if (current_index == 0) 24798c2ecf20Sopenharmony_ci pl = &ps->low; 24808c2ecf20Sopenharmony_ci else if (current_index == 1) 24818c2ecf20Sopenharmony_ci pl = &ps->medium; 24828c2ecf20Sopenharmony_ci else /* current_index == 2 */ 24838c2ecf20Sopenharmony_ci pl = &ps->high; 24848c2ecf20Sopenharmony_ci seq_printf(m, "uvd vclk: %d dclk: %d\n", rps->vclk, rps->dclk); 24858c2ecf20Sopenharmony_ci if (rdev->family >= CHIP_CEDAR) { 24868c2ecf20Sopenharmony_ci seq_printf(m, "power level %d sclk: %u mclk: %u vddc: %u vddci: %u\n", 24878c2ecf20Sopenharmony_ci current_index, pl->sclk, pl->mclk, pl->vddc, pl->vddci); 24888c2ecf20Sopenharmony_ci } else { 24898c2ecf20Sopenharmony_ci seq_printf(m, "power level %d sclk: %u mclk: %u vddc: %u\n", 24908c2ecf20Sopenharmony_ci current_index, pl->sclk, pl->mclk, pl->vddc); 24918c2ecf20Sopenharmony_ci } 24928c2ecf20Sopenharmony_ci } 24938c2ecf20Sopenharmony_ci} 24948c2ecf20Sopenharmony_ci 24958c2ecf20Sopenharmony_ciu32 rv770_dpm_get_current_sclk(struct radeon_device *rdev) 24968c2ecf20Sopenharmony_ci{ 24978c2ecf20Sopenharmony_ci struct radeon_ps *rps = rdev->pm.dpm.current_ps; 24988c2ecf20Sopenharmony_ci struct rv7xx_ps *ps = rv770_get_ps(rps); 24998c2ecf20Sopenharmony_ci struct rv7xx_pl *pl; 25008c2ecf20Sopenharmony_ci u32 current_index = 25018c2ecf20Sopenharmony_ci (RREG32(TARGET_AND_CURRENT_PROFILE_INDEX) & CURRENT_PROFILE_INDEX_MASK) >> 25028c2ecf20Sopenharmony_ci CURRENT_PROFILE_INDEX_SHIFT; 25038c2ecf20Sopenharmony_ci 25048c2ecf20Sopenharmony_ci if (current_index > 2) { 25058c2ecf20Sopenharmony_ci return 0; 25068c2ecf20Sopenharmony_ci } else { 25078c2ecf20Sopenharmony_ci if (current_index == 0) 25088c2ecf20Sopenharmony_ci pl = &ps->low; 25098c2ecf20Sopenharmony_ci else if (current_index == 1) 25108c2ecf20Sopenharmony_ci pl = &ps->medium; 25118c2ecf20Sopenharmony_ci else /* current_index == 2 */ 25128c2ecf20Sopenharmony_ci pl = &ps->high; 25138c2ecf20Sopenharmony_ci return pl->sclk; 25148c2ecf20Sopenharmony_ci } 25158c2ecf20Sopenharmony_ci} 25168c2ecf20Sopenharmony_ci 25178c2ecf20Sopenharmony_ciu32 rv770_dpm_get_current_mclk(struct radeon_device *rdev) 25188c2ecf20Sopenharmony_ci{ 25198c2ecf20Sopenharmony_ci struct radeon_ps *rps = rdev->pm.dpm.current_ps; 25208c2ecf20Sopenharmony_ci struct rv7xx_ps *ps = rv770_get_ps(rps); 25218c2ecf20Sopenharmony_ci struct rv7xx_pl *pl; 25228c2ecf20Sopenharmony_ci u32 current_index = 25238c2ecf20Sopenharmony_ci (RREG32(TARGET_AND_CURRENT_PROFILE_INDEX) & CURRENT_PROFILE_INDEX_MASK) >> 25248c2ecf20Sopenharmony_ci CURRENT_PROFILE_INDEX_SHIFT; 25258c2ecf20Sopenharmony_ci 25268c2ecf20Sopenharmony_ci if (current_index > 2) { 25278c2ecf20Sopenharmony_ci return 0; 25288c2ecf20Sopenharmony_ci } else { 25298c2ecf20Sopenharmony_ci if (current_index == 0) 25308c2ecf20Sopenharmony_ci pl = &ps->low; 25318c2ecf20Sopenharmony_ci else if (current_index == 1) 25328c2ecf20Sopenharmony_ci pl = &ps->medium; 25338c2ecf20Sopenharmony_ci else /* current_index == 2 */ 25348c2ecf20Sopenharmony_ci pl = &ps->high; 25358c2ecf20Sopenharmony_ci return pl->mclk; 25368c2ecf20Sopenharmony_ci } 25378c2ecf20Sopenharmony_ci} 25388c2ecf20Sopenharmony_ci 25398c2ecf20Sopenharmony_civoid rv770_dpm_fini(struct radeon_device *rdev) 25408c2ecf20Sopenharmony_ci{ 25418c2ecf20Sopenharmony_ci int i; 25428c2ecf20Sopenharmony_ci 25438c2ecf20Sopenharmony_ci for (i = 0; i < rdev->pm.dpm.num_ps; i++) { 25448c2ecf20Sopenharmony_ci kfree(rdev->pm.dpm.ps[i].ps_priv); 25458c2ecf20Sopenharmony_ci } 25468c2ecf20Sopenharmony_ci kfree(rdev->pm.dpm.ps); 25478c2ecf20Sopenharmony_ci kfree(rdev->pm.dpm.priv); 25488c2ecf20Sopenharmony_ci} 25498c2ecf20Sopenharmony_ci 25508c2ecf20Sopenharmony_ciu32 rv770_dpm_get_sclk(struct radeon_device *rdev, bool low) 25518c2ecf20Sopenharmony_ci{ 25528c2ecf20Sopenharmony_ci struct rv7xx_ps *requested_state = rv770_get_ps(rdev->pm.dpm.requested_ps); 25538c2ecf20Sopenharmony_ci 25548c2ecf20Sopenharmony_ci if (low) 25558c2ecf20Sopenharmony_ci return requested_state->low.sclk; 25568c2ecf20Sopenharmony_ci else 25578c2ecf20Sopenharmony_ci return requested_state->high.sclk; 25588c2ecf20Sopenharmony_ci} 25598c2ecf20Sopenharmony_ci 25608c2ecf20Sopenharmony_ciu32 rv770_dpm_get_mclk(struct radeon_device *rdev, bool low) 25618c2ecf20Sopenharmony_ci{ 25628c2ecf20Sopenharmony_ci struct rv7xx_ps *requested_state = rv770_get_ps(rdev->pm.dpm.requested_ps); 25638c2ecf20Sopenharmony_ci 25648c2ecf20Sopenharmony_ci if (low) 25658c2ecf20Sopenharmony_ci return requested_state->low.mclk; 25668c2ecf20Sopenharmony_ci else 25678c2ecf20Sopenharmony_ci return requested_state->high.mclk; 25688c2ecf20Sopenharmony_ci} 25698c2ecf20Sopenharmony_ci 25708c2ecf20Sopenharmony_cibool rv770_dpm_vblank_too_short(struct radeon_device *rdev) 25718c2ecf20Sopenharmony_ci{ 25728c2ecf20Sopenharmony_ci u32 vblank_time = r600_dpm_get_vblank_time(rdev); 25738c2ecf20Sopenharmony_ci u32 switch_limit = 200; /* 300 */ 25748c2ecf20Sopenharmony_ci 25758c2ecf20Sopenharmony_ci /* RV770 */ 25768c2ecf20Sopenharmony_ci /* mclk switching doesn't seem to work reliably on desktop RV770s */ 25778c2ecf20Sopenharmony_ci if ((rdev->family == CHIP_RV770) && 25788c2ecf20Sopenharmony_ci !(rdev->flags & RADEON_IS_MOBILITY)) 25798c2ecf20Sopenharmony_ci switch_limit = 0xffffffff; /* disable mclk switching */ 25808c2ecf20Sopenharmony_ci 25818c2ecf20Sopenharmony_ci if (vblank_time < switch_limit) 25828c2ecf20Sopenharmony_ci return true; 25838c2ecf20Sopenharmony_ci else 25848c2ecf20Sopenharmony_ci return false; 25858c2ecf20Sopenharmony_ci 25868c2ecf20Sopenharmony_ci} 2587