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 <linux/pci.h> 268c2ecf20Sopenharmony_ci#include <linux/seq_file.h> 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci#include "atom.h" 298c2ecf20Sopenharmony_ci#include "r600_dpm.h" 308c2ecf20Sopenharmony_ci#include "radeon.h" 318c2ecf20Sopenharmony_ci#include "radeon_asic.h" 328c2ecf20Sopenharmony_ci#include "rs780_dpm.h" 338c2ecf20Sopenharmony_ci#include "rs780d.h" 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_cistatic struct igp_ps *rs780_get_ps(struct radeon_ps *rps) 368c2ecf20Sopenharmony_ci{ 378c2ecf20Sopenharmony_ci struct igp_ps *ps = rps->ps_priv; 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci return ps; 408c2ecf20Sopenharmony_ci} 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_cistatic struct igp_power_info *rs780_get_pi(struct radeon_device *rdev) 438c2ecf20Sopenharmony_ci{ 448c2ecf20Sopenharmony_ci struct igp_power_info *pi = rdev->pm.dpm.priv; 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci return pi; 478c2ecf20Sopenharmony_ci} 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_cistatic void rs780_get_pm_mode_parameters(struct radeon_device *rdev) 508c2ecf20Sopenharmony_ci{ 518c2ecf20Sopenharmony_ci struct igp_power_info *pi = rs780_get_pi(rdev); 528c2ecf20Sopenharmony_ci struct radeon_mode_info *minfo = &rdev->mode_info; 538c2ecf20Sopenharmony_ci struct drm_crtc *crtc; 548c2ecf20Sopenharmony_ci struct radeon_crtc *radeon_crtc; 558c2ecf20Sopenharmony_ci int i; 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci /* defaults */ 588c2ecf20Sopenharmony_ci pi->crtc_id = 0; 598c2ecf20Sopenharmony_ci pi->refresh_rate = 60; 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci for (i = 0; i < rdev->num_crtc; i++) { 628c2ecf20Sopenharmony_ci crtc = (struct drm_crtc *)minfo->crtcs[i]; 638c2ecf20Sopenharmony_ci if (crtc && crtc->enabled) { 648c2ecf20Sopenharmony_ci radeon_crtc = to_radeon_crtc(crtc); 658c2ecf20Sopenharmony_ci pi->crtc_id = radeon_crtc->crtc_id; 668c2ecf20Sopenharmony_ci if (crtc->mode.htotal && crtc->mode.vtotal) 678c2ecf20Sopenharmony_ci pi->refresh_rate = drm_mode_vrefresh(&crtc->mode); 688c2ecf20Sopenharmony_ci break; 698c2ecf20Sopenharmony_ci } 708c2ecf20Sopenharmony_ci } 718c2ecf20Sopenharmony_ci} 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_cistatic void rs780_voltage_scaling_enable(struct radeon_device *rdev, bool enable); 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_cistatic int rs780_initialize_dpm_power_state(struct radeon_device *rdev, 768c2ecf20Sopenharmony_ci struct radeon_ps *boot_ps) 778c2ecf20Sopenharmony_ci{ 788c2ecf20Sopenharmony_ci struct atom_clock_dividers dividers; 798c2ecf20Sopenharmony_ci struct igp_ps *default_state = rs780_get_ps(boot_ps); 808c2ecf20Sopenharmony_ci int i, ret; 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM, 838c2ecf20Sopenharmony_ci default_state->sclk_low, false, ÷rs); 848c2ecf20Sopenharmony_ci if (ret) 858c2ecf20Sopenharmony_ci return ret; 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci r600_engine_clock_entry_set_reference_divider(rdev, 0, dividers.ref_div); 888c2ecf20Sopenharmony_ci r600_engine_clock_entry_set_feedback_divider(rdev, 0, dividers.fb_div); 898c2ecf20Sopenharmony_ci r600_engine_clock_entry_set_post_divider(rdev, 0, dividers.post_div); 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ci if (dividers.enable_post_div) 928c2ecf20Sopenharmony_ci r600_engine_clock_entry_enable_post_divider(rdev, 0, true); 938c2ecf20Sopenharmony_ci else 948c2ecf20Sopenharmony_ci r600_engine_clock_entry_enable_post_divider(rdev, 0, false); 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci r600_engine_clock_entry_set_step_time(rdev, 0, R600_SST_DFLT); 978c2ecf20Sopenharmony_ci r600_engine_clock_entry_enable_pulse_skipping(rdev, 0, false); 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci r600_engine_clock_entry_enable(rdev, 0, true); 1008c2ecf20Sopenharmony_ci for (i = 1; i < R600_PM_NUMBER_OF_SCLKS; i++) 1018c2ecf20Sopenharmony_ci r600_engine_clock_entry_enable(rdev, i, false); 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci r600_enable_mclk_control(rdev, false); 1048c2ecf20Sopenharmony_ci r600_voltage_control_enable_pins(rdev, 0); 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci return 0; 1078c2ecf20Sopenharmony_ci} 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_cistatic int rs780_initialize_dpm_parameters(struct radeon_device *rdev, 1108c2ecf20Sopenharmony_ci struct radeon_ps *boot_ps) 1118c2ecf20Sopenharmony_ci{ 1128c2ecf20Sopenharmony_ci int ret = 0; 1138c2ecf20Sopenharmony_ci int i; 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci r600_set_bsp(rdev, R600_BSU_DFLT, R600_BSP_DFLT); 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci r600_set_at(rdev, 0, 0, 0, 0); 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ci r600_set_git(rdev, R600_GICST_DFLT); 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci for (i = 0; i < R600_PM_NUMBER_OF_TC; i++) 1228c2ecf20Sopenharmony_ci r600_set_tc(rdev, i, 0, 0); 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ci r600_select_td(rdev, R600_TD_DFLT); 1258c2ecf20Sopenharmony_ci r600_set_vrc(rdev, 0); 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci r600_set_tpu(rdev, R600_TPU_DFLT); 1288c2ecf20Sopenharmony_ci r600_set_tpc(rdev, R600_TPC_DFLT); 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci r600_set_sstu(rdev, R600_SSTU_DFLT); 1318c2ecf20Sopenharmony_ci r600_set_sst(rdev, R600_SST_DFLT); 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci r600_set_fctu(rdev, R600_FCTU_DFLT); 1348c2ecf20Sopenharmony_ci r600_set_fct(rdev, R600_FCT_DFLT); 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci r600_set_vddc3d_oorsu(rdev, R600_VDDC3DOORSU_DFLT); 1378c2ecf20Sopenharmony_ci r600_set_vddc3d_oorphc(rdev, R600_VDDC3DOORPHC_DFLT); 1388c2ecf20Sopenharmony_ci r600_set_vddc3d_oorsdc(rdev, R600_VDDC3DOORSDC_DFLT); 1398c2ecf20Sopenharmony_ci r600_set_ctxcgtt3d_rphc(rdev, R600_CTXCGTT3DRPHC_DFLT); 1408c2ecf20Sopenharmony_ci r600_set_ctxcgtt3d_rsdc(rdev, R600_CTXCGTT3DRSDC_DFLT); 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ci r600_vid_rt_set_vru(rdev, R600_VRU_DFLT); 1438c2ecf20Sopenharmony_ci r600_vid_rt_set_vrt(rdev, R600_VOLTAGERESPONSETIME_DFLT); 1448c2ecf20Sopenharmony_ci r600_vid_rt_set_ssu(rdev, R600_SPLLSTEPUNIT_DFLT); 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_ci ret = rs780_initialize_dpm_power_state(rdev, boot_ps); 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ci r600_power_level_set_voltage_index(rdev, R600_POWER_LEVEL_LOW, 0); 1498c2ecf20Sopenharmony_ci r600_power_level_set_voltage_index(rdev, R600_POWER_LEVEL_MEDIUM, 0); 1508c2ecf20Sopenharmony_ci r600_power_level_set_voltage_index(rdev, R600_POWER_LEVEL_HIGH, 0); 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ci r600_power_level_set_mem_clock_index(rdev, R600_POWER_LEVEL_LOW, 0); 1538c2ecf20Sopenharmony_ci r600_power_level_set_mem_clock_index(rdev, R600_POWER_LEVEL_MEDIUM, 0); 1548c2ecf20Sopenharmony_ci r600_power_level_set_mem_clock_index(rdev, R600_POWER_LEVEL_HIGH, 0); 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_ci r600_power_level_set_eng_clock_index(rdev, R600_POWER_LEVEL_LOW, 0); 1578c2ecf20Sopenharmony_ci r600_power_level_set_eng_clock_index(rdev, R600_POWER_LEVEL_MEDIUM, 0); 1588c2ecf20Sopenharmony_ci r600_power_level_set_eng_clock_index(rdev, R600_POWER_LEVEL_HIGH, 0); 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_ci r600_power_level_set_watermark_id(rdev, R600_POWER_LEVEL_LOW, R600_DISPLAY_WATERMARK_HIGH); 1618c2ecf20Sopenharmony_ci r600_power_level_set_watermark_id(rdev, R600_POWER_LEVEL_MEDIUM, R600_DISPLAY_WATERMARK_HIGH); 1628c2ecf20Sopenharmony_ci r600_power_level_set_watermark_id(rdev, R600_POWER_LEVEL_HIGH, R600_DISPLAY_WATERMARK_HIGH); 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ci r600_power_level_enable(rdev, R600_POWER_LEVEL_CTXSW, false); 1658c2ecf20Sopenharmony_ci r600_power_level_enable(rdev, R600_POWER_LEVEL_HIGH, false); 1668c2ecf20Sopenharmony_ci r600_power_level_enable(rdev, R600_POWER_LEVEL_MEDIUM, false); 1678c2ecf20Sopenharmony_ci r600_power_level_enable(rdev, R600_POWER_LEVEL_LOW, true); 1688c2ecf20Sopenharmony_ci 1698c2ecf20Sopenharmony_ci r600_power_level_set_enter_index(rdev, R600_POWER_LEVEL_LOW); 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_ci r600_set_vrc(rdev, RS780_CGFTV_DFLT); 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_ci return ret; 1748c2ecf20Sopenharmony_ci} 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_cistatic void rs780_start_dpm(struct radeon_device *rdev) 1778c2ecf20Sopenharmony_ci{ 1788c2ecf20Sopenharmony_ci r600_enable_sclk_control(rdev, false); 1798c2ecf20Sopenharmony_ci r600_enable_mclk_control(rdev, false); 1808c2ecf20Sopenharmony_ci 1818c2ecf20Sopenharmony_ci r600_dynamicpm_enable(rdev, true); 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_ci radeon_wait_for_vblank(rdev, 0); 1848c2ecf20Sopenharmony_ci radeon_wait_for_vblank(rdev, 1); 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_ci r600_enable_spll_bypass(rdev, true); 1878c2ecf20Sopenharmony_ci r600_wait_for_spll_change(rdev); 1888c2ecf20Sopenharmony_ci r600_enable_spll_bypass(rdev, false); 1898c2ecf20Sopenharmony_ci r600_wait_for_spll_change(rdev); 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_ci r600_enable_spll_bypass(rdev, true); 1928c2ecf20Sopenharmony_ci r600_wait_for_spll_change(rdev); 1938c2ecf20Sopenharmony_ci r600_enable_spll_bypass(rdev, false); 1948c2ecf20Sopenharmony_ci r600_wait_for_spll_change(rdev); 1958c2ecf20Sopenharmony_ci 1968c2ecf20Sopenharmony_ci r600_enable_sclk_control(rdev, true); 1978c2ecf20Sopenharmony_ci} 1988c2ecf20Sopenharmony_ci 1998c2ecf20Sopenharmony_ci 2008c2ecf20Sopenharmony_cistatic void rs780_preset_ranges_slow_clk_fbdiv_en(struct radeon_device *rdev) 2018c2ecf20Sopenharmony_ci{ 2028c2ecf20Sopenharmony_ci WREG32_P(FVTHROT_SLOW_CLK_FEEDBACK_DIV_REG1, RANGE_SLOW_CLK_FEEDBACK_DIV_EN, 2038c2ecf20Sopenharmony_ci ~RANGE_SLOW_CLK_FEEDBACK_DIV_EN); 2048c2ecf20Sopenharmony_ci 2058c2ecf20Sopenharmony_ci WREG32_P(FVTHROT_SLOW_CLK_FEEDBACK_DIV_REG1, 2068c2ecf20Sopenharmony_ci RANGE0_SLOW_CLK_FEEDBACK_DIV(RS780_SLOWCLKFEEDBACKDIV_DFLT), 2078c2ecf20Sopenharmony_ci ~RANGE0_SLOW_CLK_FEEDBACK_DIV_MASK); 2088c2ecf20Sopenharmony_ci} 2098c2ecf20Sopenharmony_ci 2108c2ecf20Sopenharmony_cistatic void rs780_preset_starting_fbdiv(struct radeon_device *rdev) 2118c2ecf20Sopenharmony_ci{ 2128c2ecf20Sopenharmony_ci u32 fbdiv = (RREG32(CG_SPLL_FUNC_CNTL) & SPLL_FB_DIV_MASK) >> SPLL_FB_DIV_SHIFT; 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_ci WREG32_P(FVTHROT_FBDIV_REG1, STARTING_FEEDBACK_DIV(fbdiv), 2158c2ecf20Sopenharmony_ci ~STARTING_FEEDBACK_DIV_MASK); 2168c2ecf20Sopenharmony_ci 2178c2ecf20Sopenharmony_ci WREG32_P(FVTHROT_FBDIV_REG2, FORCED_FEEDBACK_DIV(fbdiv), 2188c2ecf20Sopenharmony_ci ~FORCED_FEEDBACK_DIV_MASK); 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_ci WREG32_P(FVTHROT_FBDIV_REG1, FORCE_FEEDBACK_DIV, ~FORCE_FEEDBACK_DIV); 2218c2ecf20Sopenharmony_ci} 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_cistatic void rs780_voltage_scaling_init(struct radeon_device *rdev) 2248c2ecf20Sopenharmony_ci{ 2258c2ecf20Sopenharmony_ci struct igp_power_info *pi = rs780_get_pi(rdev); 2268c2ecf20Sopenharmony_ci struct drm_device *dev = rdev->ddev; 2278c2ecf20Sopenharmony_ci u32 fv_throt_pwm_fb_div_range[3]; 2288c2ecf20Sopenharmony_ci u32 fv_throt_pwm_range[4]; 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_ci if (dev->pdev->device == 0x9614) { 2318c2ecf20Sopenharmony_ci fv_throt_pwm_fb_div_range[0] = RS780D_FVTHROTPWMFBDIVRANGEREG0_DFLT; 2328c2ecf20Sopenharmony_ci fv_throt_pwm_fb_div_range[1] = RS780D_FVTHROTPWMFBDIVRANGEREG1_DFLT; 2338c2ecf20Sopenharmony_ci fv_throt_pwm_fb_div_range[2] = RS780D_FVTHROTPWMFBDIVRANGEREG2_DFLT; 2348c2ecf20Sopenharmony_ci } else if ((dev->pdev->device == 0x9714) || 2358c2ecf20Sopenharmony_ci (dev->pdev->device == 0x9715)) { 2368c2ecf20Sopenharmony_ci fv_throt_pwm_fb_div_range[0] = RS880D_FVTHROTPWMFBDIVRANGEREG0_DFLT; 2378c2ecf20Sopenharmony_ci fv_throt_pwm_fb_div_range[1] = RS880D_FVTHROTPWMFBDIVRANGEREG1_DFLT; 2388c2ecf20Sopenharmony_ci fv_throt_pwm_fb_div_range[2] = RS880D_FVTHROTPWMFBDIVRANGEREG2_DFLT; 2398c2ecf20Sopenharmony_ci } else { 2408c2ecf20Sopenharmony_ci fv_throt_pwm_fb_div_range[0] = RS780_FVTHROTPWMFBDIVRANGEREG0_DFLT; 2418c2ecf20Sopenharmony_ci fv_throt_pwm_fb_div_range[1] = RS780_FVTHROTPWMFBDIVRANGEREG1_DFLT; 2428c2ecf20Sopenharmony_ci fv_throt_pwm_fb_div_range[2] = RS780_FVTHROTPWMFBDIVRANGEREG2_DFLT; 2438c2ecf20Sopenharmony_ci } 2448c2ecf20Sopenharmony_ci 2458c2ecf20Sopenharmony_ci if (pi->pwm_voltage_control) { 2468c2ecf20Sopenharmony_ci fv_throt_pwm_range[0] = pi->min_voltage; 2478c2ecf20Sopenharmony_ci fv_throt_pwm_range[1] = pi->min_voltage; 2488c2ecf20Sopenharmony_ci fv_throt_pwm_range[2] = pi->max_voltage; 2498c2ecf20Sopenharmony_ci fv_throt_pwm_range[3] = pi->max_voltage; 2508c2ecf20Sopenharmony_ci } else { 2518c2ecf20Sopenharmony_ci fv_throt_pwm_range[0] = pi->invert_pwm_required ? 2528c2ecf20Sopenharmony_ci RS780_FVTHROTPWMRANGE3_GPIO_DFLT : RS780_FVTHROTPWMRANGE0_GPIO_DFLT; 2538c2ecf20Sopenharmony_ci fv_throt_pwm_range[1] = pi->invert_pwm_required ? 2548c2ecf20Sopenharmony_ci RS780_FVTHROTPWMRANGE2_GPIO_DFLT : RS780_FVTHROTPWMRANGE1_GPIO_DFLT; 2558c2ecf20Sopenharmony_ci fv_throt_pwm_range[2] = pi->invert_pwm_required ? 2568c2ecf20Sopenharmony_ci RS780_FVTHROTPWMRANGE1_GPIO_DFLT : RS780_FVTHROTPWMRANGE2_GPIO_DFLT; 2578c2ecf20Sopenharmony_ci fv_throt_pwm_range[3] = pi->invert_pwm_required ? 2588c2ecf20Sopenharmony_ci RS780_FVTHROTPWMRANGE0_GPIO_DFLT : RS780_FVTHROTPWMRANGE3_GPIO_DFLT; 2598c2ecf20Sopenharmony_ci } 2608c2ecf20Sopenharmony_ci 2618c2ecf20Sopenharmony_ci WREG32_P(FVTHROT_PWM_CTRL_REG0, 2628c2ecf20Sopenharmony_ci STARTING_PWM_HIGHTIME(pi->max_voltage), 2638c2ecf20Sopenharmony_ci ~STARTING_PWM_HIGHTIME_MASK); 2648c2ecf20Sopenharmony_ci 2658c2ecf20Sopenharmony_ci WREG32_P(FVTHROT_PWM_CTRL_REG0, 2668c2ecf20Sopenharmony_ci NUMBER_OF_CYCLES_IN_PERIOD(pi->num_of_cycles_in_period), 2678c2ecf20Sopenharmony_ci ~NUMBER_OF_CYCLES_IN_PERIOD_MASK); 2688c2ecf20Sopenharmony_ci 2698c2ecf20Sopenharmony_ci WREG32_P(FVTHROT_PWM_CTRL_REG0, FORCE_STARTING_PWM_HIGHTIME, 2708c2ecf20Sopenharmony_ci ~FORCE_STARTING_PWM_HIGHTIME); 2718c2ecf20Sopenharmony_ci 2728c2ecf20Sopenharmony_ci if (pi->invert_pwm_required) 2738c2ecf20Sopenharmony_ci WREG32_P(FVTHROT_PWM_CTRL_REG0, INVERT_PWM_WAVEFORM, ~INVERT_PWM_WAVEFORM); 2748c2ecf20Sopenharmony_ci else 2758c2ecf20Sopenharmony_ci WREG32_P(FVTHROT_PWM_CTRL_REG0, 0, ~INVERT_PWM_WAVEFORM); 2768c2ecf20Sopenharmony_ci 2778c2ecf20Sopenharmony_ci rs780_voltage_scaling_enable(rdev, true); 2788c2ecf20Sopenharmony_ci 2798c2ecf20Sopenharmony_ci WREG32(FVTHROT_PWM_CTRL_REG1, 2808c2ecf20Sopenharmony_ci (MIN_PWM_HIGHTIME(pi->min_voltage) | 2818c2ecf20Sopenharmony_ci MAX_PWM_HIGHTIME(pi->max_voltage))); 2828c2ecf20Sopenharmony_ci 2838c2ecf20Sopenharmony_ci WREG32(FVTHROT_PWM_US_REG0, RS780_FVTHROTPWMUSREG0_DFLT); 2848c2ecf20Sopenharmony_ci WREG32(FVTHROT_PWM_US_REG1, RS780_FVTHROTPWMUSREG1_DFLT); 2858c2ecf20Sopenharmony_ci WREG32(FVTHROT_PWM_DS_REG0, RS780_FVTHROTPWMDSREG0_DFLT); 2868c2ecf20Sopenharmony_ci WREG32(FVTHROT_PWM_DS_REG1, RS780_FVTHROTPWMDSREG1_DFLT); 2878c2ecf20Sopenharmony_ci 2888c2ecf20Sopenharmony_ci WREG32_P(FVTHROT_PWM_FEEDBACK_DIV_REG1, 2898c2ecf20Sopenharmony_ci RANGE0_PWM_FEEDBACK_DIV(fv_throt_pwm_fb_div_range[0]), 2908c2ecf20Sopenharmony_ci ~RANGE0_PWM_FEEDBACK_DIV_MASK); 2918c2ecf20Sopenharmony_ci 2928c2ecf20Sopenharmony_ci WREG32(FVTHROT_PWM_FEEDBACK_DIV_REG2, 2938c2ecf20Sopenharmony_ci (RANGE1_PWM_FEEDBACK_DIV(fv_throt_pwm_fb_div_range[1]) | 2948c2ecf20Sopenharmony_ci RANGE2_PWM_FEEDBACK_DIV(fv_throt_pwm_fb_div_range[2]))); 2958c2ecf20Sopenharmony_ci 2968c2ecf20Sopenharmony_ci WREG32(FVTHROT_PWM_FEEDBACK_DIV_REG3, 2978c2ecf20Sopenharmony_ci (RANGE0_PWM(fv_throt_pwm_range[1]) | 2988c2ecf20Sopenharmony_ci RANGE1_PWM(fv_throt_pwm_range[2]))); 2998c2ecf20Sopenharmony_ci WREG32(FVTHROT_PWM_FEEDBACK_DIV_REG4, 3008c2ecf20Sopenharmony_ci (RANGE2_PWM(fv_throt_pwm_range[1]) | 3018c2ecf20Sopenharmony_ci RANGE3_PWM(fv_throt_pwm_range[2]))); 3028c2ecf20Sopenharmony_ci} 3038c2ecf20Sopenharmony_ci 3048c2ecf20Sopenharmony_cistatic void rs780_clk_scaling_enable(struct radeon_device *rdev, bool enable) 3058c2ecf20Sopenharmony_ci{ 3068c2ecf20Sopenharmony_ci if (enable) 3078c2ecf20Sopenharmony_ci WREG32_P(FVTHROT_CNTRL_REG, ENABLE_FV_THROT | ENABLE_FV_UPDATE, 3088c2ecf20Sopenharmony_ci ~(ENABLE_FV_THROT | ENABLE_FV_UPDATE)); 3098c2ecf20Sopenharmony_ci else 3108c2ecf20Sopenharmony_ci WREG32_P(FVTHROT_CNTRL_REG, 0, 3118c2ecf20Sopenharmony_ci ~(ENABLE_FV_THROT | ENABLE_FV_UPDATE)); 3128c2ecf20Sopenharmony_ci} 3138c2ecf20Sopenharmony_ci 3148c2ecf20Sopenharmony_cistatic void rs780_voltage_scaling_enable(struct radeon_device *rdev, bool enable) 3158c2ecf20Sopenharmony_ci{ 3168c2ecf20Sopenharmony_ci if (enable) 3178c2ecf20Sopenharmony_ci WREG32_P(FVTHROT_CNTRL_REG, ENABLE_FV_THROT_IO, ~ENABLE_FV_THROT_IO); 3188c2ecf20Sopenharmony_ci else 3198c2ecf20Sopenharmony_ci WREG32_P(FVTHROT_CNTRL_REG, 0, ~ENABLE_FV_THROT_IO); 3208c2ecf20Sopenharmony_ci} 3218c2ecf20Sopenharmony_ci 3228c2ecf20Sopenharmony_cistatic void rs780_set_engine_clock_wfc(struct radeon_device *rdev) 3238c2ecf20Sopenharmony_ci{ 3248c2ecf20Sopenharmony_ci WREG32(FVTHROT_UTC0, RS780_FVTHROTUTC0_DFLT); 3258c2ecf20Sopenharmony_ci WREG32(FVTHROT_UTC1, RS780_FVTHROTUTC1_DFLT); 3268c2ecf20Sopenharmony_ci WREG32(FVTHROT_UTC2, RS780_FVTHROTUTC2_DFLT); 3278c2ecf20Sopenharmony_ci WREG32(FVTHROT_UTC3, RS780_FVTHROTUTC3_DFLT); 3288c2ecf20Sopenharmony_ci WREG32(FVTHROT_UTC4, RS780_FVTHROTUTC4_DFLT); 3298c2ecf20Sopenharmony_ci 3308c2ecf20Sopenharmony_ci WREG32(FVTHROT_DTC0, RS780_FVTHROTDTC0_DFLT); 3318c2ecf20Sopenharmony_ci WREG32(FVTHROT_DTC1, RS780_FVTHROTDTC1_DFLT); 3328c2ecf20Sopenharmony_ci WREG32(FVTHROT_DTC2, RS780_FVTHROTDTC2_DFLT); 3338c2ecf20Sopenharmony_ci WREG32(FVTHROT_DTC3, RS780_FVTHROTDTC3_DFLT); 3348c2ecf20Sopenharmony_ci WREG32(FVTHROT_DTC4, RS780_FVTHROTDTC4_DFLT); 3358c2ecf20Sopenharmony_ci} 3368c2ecf20Sopenharmony_ci 3378c2ecf20Sopenharmony_cistatic void rs780_set_engine_clock_sc(struct radeon_device *rdev) 3388c2ecf20Sopenharmony_ci{ 3398c2ecf20Sopenharmony_ci WREG32_P(FVTHROT_FBDIV_REG2, 3408c2ecf20Sopenharmony_ci FB_DIV_TIMER_VAL(RS780_FBDIVTIMERVAL_DFLT), 3418c2ecf20Sopenharmony_ci ~FB_DIV_TIMER_VAL_MASK); 3428c2ecf20Sopenharmony_ci 3438c2ecf20Sopenharmony_ci WREG32_P(FVTHROT_CNTRL_REG, 3448c2ecf20Sopenharmony_ci REFRESH_RATE_DIVISOR(0) | MINIMUM_CIP(0xf), 3458c2ecf20Sopenharmony_ci ~(REFRESH_RATE_DIVISOR_MASK | MINIMUM_CIP_MASK)); 3468c2ecf20Sopenharmony_ci} 3478c2ecf20Sopenharmony_ci 3488c2ecf20Sopenharmony_cistatic void rs780_set_engine_clock_tdc(struct radeon_device *rdev) 3498c2ecf20Sopenharmony_ci{ 3508c2ecf20Sopenharmony_ci WREG32_P(FVTHROT_CNTRL_REG, 0, ~(FORCE_TREND_SEL | TREND_SEL_MODE)); 3518c2ecf20Sopenharmony_ci} 3528c2ecf20Sopenharmony_ci 3538c2ecf20Sopenharmony_cistatic void rs780_set_engine_clock_ssc(struct radeon_device *rdev) 3548c2ecf20Sopenharmony_ci{ 3558c2ecf20Sopenharmony_ci WREG32(FVTHROT_FB_US_REG0, RS780_FVTHROTFBUSREG0_DFLT); 3568c2ecf20Sopenharmony_ci WREG32(FVTHROT_FB_US_REG1, RS780_FVTHROTFBUSREG1_DFLT); 3578c2ecf20Sopenharmony_ci WREG32(FVTHROT_FB_DS_REG0, RS780_FVTHROTFBDSREG0_DFLT); 3588c2ecf20Sopenharmony_ci WREG32(FVTHROT_FB_DS_REG1, RS780_FVTHROTFBDSREG1_DFLT); 3598c2ecf20Sopenharmony_ci 3608c2ecf20Sopenharmony_ci WREG32_P(FVTHROT_FBDIV_REG1, MAX_FEEDBACK_STEP(1), ~MAX_FEEDBACK_STEP_MASK); 3618c2ecf20Sopenharmony_ci} 3628c2ecf20Sopenharmony_ci 3638c2ecf20Sopenharmony_cistatic void rs780_program_at(struct radeon_device *rdev) 3648c2ecf20Sopenharmony_ci{ 3658c2ecf20Sopenharmony_ci struct igp_power_info *pi = rs780_get_pi(rdev); 3668c2ecf20Sopenharmony_ci 3678c2ecf20Sopenharmony_ci WREG32(FVTHROT_TARGET_REG, 30000000 / pi->refresh_rate); 3688c2ecf20Sopenharmony_ci WREG32(FVTHROT_CB1, 1000000 * 5 / pi->refresh_rate); 3698c2ecf20Sopenharmony_ci WREG32(FVTHROT_CB2, 1000000 * 10 / pi->refresh_rate); 3708c2ecf20Sopenharmony_ci WREG32(FVTHROT_CB3, 1000000 * 30 / pi->refresh_rate); 3718c2ecf20Sopenharmony_ci WREG32(FVTHROT_CB4, 1000000 * 50 / pi->refresh_rate); 3728c2ecf20Sopenharmony_ci} 3738c2ecf20Sopenharmony_ci 3748c2ecf20Sopenharmony_cistatic void rs780_disable_vbios_powersaving(struct radeon_device *rdev) 3758c2ecf20Sopenharmony_ci{ 3768c2ecf20Sopenharmony_ci WREG32_P(CG_INTGFX_MISC, 0, ~0xFFF00000); 3778c2ecf20Sopenharmony_ci} 3788c2ecf20Sopenharmony_ci 3798c2ecf20Sopenharmony_cistatic void rs780_force_voltage(struct radeon_device *rdev, u16 voltage) 3808c2ecf20Sopenharmony_ci{ 3818c2ecf20Sopenharmony_ci struct igp_ps *current_state = rs780_get_ps(rdev->pm.dpm.current_ps); 3828c2ecf20Sopenharmony_ci 3838c2ecf20Sopenharmony_ci if ((current_state->max_voltage == RS780_VDDC_LEVEL_HIGH) && 3848c2ecf20Sopenharmony_ci (current_state->min_voltage == RS780_VDDC_LEVEL_HIGH)) 3858c2ecf20Sopenharmony_ci return; 3868c2ecf20Sopenharmony_ci 3878c2ecf20Sopenharmony_ci WREG32_P(GFX_MACRO_BYPASS_CNTL, SPLL_BYPASS_CNTL, ~SPLL_BYPASS_CNTL); 3888c2ecf20Sopenharmony_ci 3898c2ecf20Sopenharmony_ci udelay(1); 3908c2ecf20Sopenharmony_ci 3918c2ecf20Sopenharmony_ci WREG32_P(FVTHROT_PWM_CTRL_REG0, 3928c2ecf20Sopenharmony_ci STARTING_PWM_HIGHTIME(voltage), 3938c2ecf20Sopenharmony_ci ~STARTING_PWM_HIGHTIME_MASK); 3948c2ecf20Sopenharmony_ci 3958c2ecf20Sopenharmony_ci WREG32_P(FVTHROT_PWM_CTRL_REG0, 3968c2ecf20Sopenharmony_ci FORCE_STARTING_PWM_HIGHTIME, ~FORCE_STARTING_PWM_HIGHTIME); 3978c2ecf20Sopenharmony_ci 3988c2ecf20Sopenharmony_ci WREG32_P(FVTHROT_PWM_FEEDBACK_DIV_REG1, 0, 3998c2ecf20Sopenharmony_ci ~RANGE_PWM_FEEDBACK_DIV_EN); 4008c2ecf20Sopenharmony_ci 4018c2ecf20Sopenharmony_ci udelay(1); 4028c2ecf20Sopenharmony_ci 4038c2ecf20Sopenharmony_ci WREG32_P(GFX_MACRO_BYPASS_CNTL, 0, ~SPLL_BYPASS_CNTL); 4048c2ecf20Sopenharmony_ci} 4058c2ecf20Sopenharmony_ci 4068c2ecf20Sopenharmony_cistatic void rs780_force_fbdiv(struct radeon_device *rdev, u32 fb_div) 4078c2ecf20Sopenharmony_ci{ 4088c2ecf20Sopenharmony_ci struct igp_ps *current_state = rs780_get_ps(rdev->pm.dpm.current_ps); 4098c2ecf20Sopenharmony_ci 4108c2ecf20Sopenharmony_ci if (current_state->sclk_low == current_state->sclk_high) 4118c2ecf20Sopenharmony_ci return; 4128c2ecf20Sopenharmony_ci 4138c2ecf20Sopenharmony_ci WREG32_P(GFX_MACRO_BYPASS_CNTL, SPLL_BYPASS_CNTL, ~SPLL_BYPASS_CNTL); 4148c2ecf20Sopenharmony_ci 4158c2ecf20Sopenharmony_ci WREG32_P(FVTHROT_FBDIV_REG2, FORCED_FEEDBACK_DIV(fb_div), 4168c2ecf20Sopenharmony_ci ~FORCED_FEEDBACK_DIV_MASK); 4178c2ecf20Sopenharmony_ci WREG32_P(FVTHROT_FBDIV_REG1, STARTING_FEEDBACK_DIV(fb_div), 4188c2ecf20Sopenharmony_ci ~STARTING_FEEDBACK_DIV_MASK); 4198c2ecf20Sopenharmony_ci WREG32_P(FVTHROT_FBDIV_REG1, FORCE_FEEDBACK_DIV, ~FORCE_FEEDBACK_DIV); 4208c2ecf20Sopenharmony_ci 4218c2ecf20Sopenharmony_ci udelay(100); 4228c2ecf20Sopenharmony_ci 4238c2ecf20Sopenharmony_ci WREG32_P(GFX_MACRO_BYPASS_CNTL, 0, ~SPLL_BYPASS_CNTL); 4248c2ecf20Sopenharmony_ci} 4258c2ecf20Sopenharmony_ci 4268c2ecf20Sopenharmony_cistatic int rs780_set_engine_clock_scaling(struct radeon_device *rdev, 4278c2ecf20Sopenharmony_ci struct radeon_ps *new_ps, 4288c2ecf20Sopenharmony_ci struct radeon_ps *old_ps) 4298c2ecf20Sopenharmony_ci{ 4308c2ecf20Sopenharmony_ci struct atom_clock_dividers min_dividers, max_dividers, current_max_dividers; 4318c2ecf20Sopenharmony_ci struct igp_ps *new_state = rs780_get_ps(new_ps); 4328c2ecf20Sopenharmony_ci struct igp_ps *old_state = rs780_get_ps(old_ps); 4338c2ecf20Sopenharmony_ci int ret; 4348c2ecf20Sopenharmony_ci 4358c2ecf20Sopenharmony_ci if ((new_state->sclk_high == old_state->sclk_high) && 4368c2ecf20Sopenharmony_ci (new_state->sclk_low == old_state->sclk_low)) 4378c2ecf20Sopenharmony_ci return 0; 4388c2ecf20Sopenharmony_ci 4398c2ecf20Sopenharmony_ci ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM, 4408c2ecf20Sopenharmony_ci new_state->sclk_low, false, &min_dividers); 4418c2ecf20Sopenharmony_ci if (ret) 4428c2ecf20Sopenharmony_ci return ret; 4438c2ecf20Sopenharmony_ci 4448c2ecf20Sopenharmony_ci ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM, 4458c2ecf20Sopenharmony_ci new_state->sclk_high, false, &max_dividers); 4468c2ecf20Sopenharmony_ci if (ret) 4478c2ecf20Sopenharmony_ci return ret; 4488c2ecf20Sopenharmony_ci 4498c2ecf20Sopenharmony_ci ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM, 4508c2ecf20Sopenharmony_ci old_state->sclk_high, false, ¤t_max_dividers); 4518c2ecf20Sopenharmony_ci if (ret) 4528c2ecf20Sopenharmony_ci return ret; 4538c2ecf20Sopenharmony_ci 4548c2ecf20Sopenharmony_ci if ((min_dividers.ref_div != max_dividers.ref_div) || 4558c2ecf20Sopenharmony_ci (min_dividers.post_div != max_dividers.post_div) || 4568c2ecf20Sopenharmony_ci (max_dividers.ref_div != current_max_dividers.ref_div) || 4578c2ecf20Sopenharmony_ci (max_dividers.post_div != current_max_dividers.post_div)) 4588c2ecf20Sopenharmony_ci return -EINVAL; 4598c2ecf20Sopenharmony_ci 4608c2ecf20Sopenharmony_ci rs780_force_fbdiv(rdev, max_dividers.fb_div); 4618c2ecf20Sopenharmony_ci 4628c2ecf20Sopenharmony_ci if (max_dividers.fb_div > min_dividers.fb_div) { 4638c2ecf20Sopenharmony_ci WREG32_P(FVTHROT_FBDIV_REG0, 4648c2ecf20Sopenharmony_ci MIN_FEEDBACK_DIV(min_dividers.fb_div) | 4658c2ecf20Sopenharmony_ci MAX_FEEDBACK_DIV(max_dividers.fb_div), 4668c2ecf20Sopenharmony_ci ~(MIN_FEEDBACK_DIV_MASK | MAX_FEEDBACK_DIV_MASK)); 4678c2ecf20Sopenharmony_ci 4688c2ecf20Sopenharmony_ci WREG32_P(FVTHROT_FBDIV_REG1, 0, ~FORCE_FEEDBACK_DIV); 4698c2ecf20Sopenharmony_ci } 4708c2ecf20Sopenharmony_ci 4718c2ecf20Sopenharmony_ci return 0; 4728c2ecf20Sopenharmony_ci} 4738c2ecf20Sopenharmony_ci 4748c2ecf20Sopenharmony_cistatic void rs780_set_engine_clock_spc(struct radeon_device *rdev, 4758c2ecf20Sopenharmony_ci struct radeon_ps *new_ps, 4768c2ecf20Sopenharmony_ci struct radeon_ps *old_ps) 4778c2ecf20Sopenharmony_ci{ 4788c2ecf20Sopenharmony_ci struct igp_ps *new_state = rs780_get_ps(new_ps); 4798c2ecf20Sopenharmony_ci struct igp_ps *old_state = rs780_get_ps(old_ps); 4808c2ecf20Sopenharmony_ci struct igp_power_info *pi = rs780_get_pi(rdev); 4818c2ecf20Sopenharmony_ci 4828c2ecf20Sopenharmony_ci if ((new_state->sclk_high == old_state->sclk_high) && 4838c2ecf20Sopenharmony_ci (new_state->sclk_low == old_state->sclk_low)) 4848c2ecf20Sopenharmony_ci return; 4858c2ecf20Sopenharmony_ci 4868c2ecf20Sopenharmony_ci if (pi->crtc_id == 0) 4878c2ecf20Sopenharmony_ci WREG32_P(CG_INTGFX_MISC, 0, ~FVTHROT_VBLANK_SEL); 4888c2ecf20Sopenharmony_ci else 4898c2ecf20Sopenharmony_ci WREG32_P(CG_INTGFX_MISC, FVTHROT_VBLANK_SEL, ~FVTHROT_VBLANK_SEL); 4908c2ecf20Sopenharmony_ci 4918c2ecf20Sopenharmony_ci} 4928c2ecf20Sopenharmony_ci 4938c2ecf20Sopenharmony_cistatic void rs780_activate_engine_clk_scaling(struct radeon_device *rdev, 4948c2ecf20Sopenharmony_ci struct radeon_ps *new_ps, 4958c2ecf20Sopenharmony_ci struct radeon_ps *old_ps) 4968c2ecf20Sopenharmony_ci{ 4978c2ecf20Sopenharmony_ci struct igp_ps *new_state = rs780_get_ps(new_ps); 4988c2ecf20Sopenharmony_ci struct igp_ps *old_state = rs780_get_ps(old_ps); 4998c2ecf20Sopenharmony_ci 5008c2ecf20Sopenharmony_ci if ((new_state->sclk_high == old_state->sclk_high) && 5018c2ecf20Sopenharmony_ci (new_state->sclk_low == old_state->sclk_low)) 5028c2ecf20Sopenharmony_ci return; 5038c2ecf20Sopenharmony_ci 5048c2ecf20Sopenharmony_ci if (new_state->sclk_high == new_state->sclk_low) 5058c2ecf20Sopenharmony_ci return; 5068c2ecf20Sopenharmony_ci 5078c2ecf20Sopenharmony_ci rs780_clk_scaling_enable(rdev, true); 5088c2ecf20Sopenharmony_ci} 5098c2ecf20Sopenharmony_ci 5108c2ecf20Sopenharmony_cistatic u32 rs780_get_voltage_for_vddc_level(struct radeon_device *rdev, 5118c2ecf20Sopenharmony_ci enum rs780_vddc_level vddc) 5128c2ecf20Sopenharmony_ci{ 5138c2ecf20Sopenharmony_ci struct igp_power_info *pi = rs780_get_pi(rdev); 5148c2ecf20Sopenharmony_ci 5158c2ecf20Sopenharmony_ci if (vddc == RS780_VDDC_LEVEL_HIGH) 5168c2ecf20Sopenharmony_ci return pi->max_voltage; 5178c2ecf20Sopenharmony_ci else if (vddc == RS780_VDDC_LEVEL_LOW) 5188c2ecf20Sopenharmony_ci return pi->min_voltage; 5198c2ecf20Sopenharmony_ci else 5208c2ecf20Sopenharmony_ci return pi->max_voltage; 5218c2ecf20Sopenharmony_ci} 5228c2ecf20Sopenharmony_ci 5238c2ecf20Sopenharmony_cistatic void rs780_enable_voltage_scaling(struct radeon_device *rdev, 5248c2ecf20Sopenharmony_ci struct radeon_ps *new_ps) 5258c2ecf20Sopenharmony_ci{ 5268c2ecf20Sopenharmony_ci struct igp_ps *new_state = rs780_get_ps(new_ps); 5278c2ecf20Sopenharmony_ci struct igp_power_info *pi = rs780_get_pi(rdev); 5288c2ecf20Sopenharmony_ci enum rs780_vddc_level vddc_high, vddc_low; 5298c2ecf20Sopenharmony_ci 5308c2ecf20Sopenharmony_ci udelay(100); 5318c2ecf20Sopenharmony_ci 5328c2ecf20Sopenharmony_ci if ((new_state->max_voltage == RS780_VDDC_LEVEL_HIGH) && 5338c2ecf20Sopenharmony_ci (new_state->min_voltage == RS780_VDDC_LEVEL_HIGH)) 5348c2ecf20Sopenharmony_ci return; 5358c2ecf20Sopenharmony_ci 5368c2ecf20Sopenharmony_ci vddc_high = rs780_get_voltage_for_vddc_level(rdev, 5378c2ecf20Sopenharmony_ci new_state->max_voltage); 5388c2ecf20Sopenharmony_ci vddc_low = rs780_get_voltage_for_vddc_level(rdev, 5398c2ecf20Sopenharmony_ci new_state->min_voltage); 5408c2ecf20Sopenharmony_ci 5418c2ecf20Sopenharmony_ci WREG32_P(GFX_MACRO_BYPASS_CNTL, SPLL_BYPASS_CNTL, ~SPLL_BYPASS_CNTL); 5428c2ecf20Sopenharmony_ci 5438c2ecf20Sopenharmony_ci udelay(1); 5448c2ecf20Sopenharmony_ci if (vddc_high > vddc_low) { 5458c2ecf20Sopenharmony_ci WREG32_P(FVTHROT_PWM_FEEDBACK_DIV_REG1, 5468c2ecf20Sopenharmony_ci RANGE_PWM_FEEDBACK_DIV_EN, ~RANGE_PWM_FEEDBACK_DIV_EN); 5478c2ecf20Sopenharmony_ci 5488c2ecf20Sopenharmony_ci WREG32_P(FVTHROT_PWM_CTRL_REG0, 0, ~FORCE_STARTING_PWM_HIGHTIME); 5498c2ecf20Sopenharmony_ci } else if (vddc_high == vddc_low) { 5508c2ecf20Sopenharmony_ci if (pi->max_voltage != vddc_high) { 5518c2ecf20Sopenharmony_ci WREG32_P(FVTHROT_PWM_CTRL_REG0, 5528c2ecf20Sopenharmony_ci STARTING_PWM_HIGHTIME(vddc_high), 5538c2ecf20Sopenharmony_ci ~STARTING_PWM_HIGHTIME_MASK); 5548c2ecf20Sopenharmony_ci 5558c2ecf20Sopenharmony_ci WREG32_P(FVTHROT_PWM_CTRL_REG0, 5568c2ecf20Sopenharmony_ci FORCE_STARTING_PWM_HIGHTIME, 5578c2ecf20Sopenharmony_ci ~FORCE_STARTING_PWM_HIGHTIME); 5588c2ecf20Sopenharmony_ci } 5598c2ecf20Sopenharmony_ci } 5608c2ecf20Sopenharmony_ci 5618c2ecf20Sopenharmony_ci WREG32_P(GFX_MACRO_BYPASS_CNTL, 0, ~SPLL_BYPASS_CNTL); 5628c2ecf20Sopenharmony_ci} 5638c2ecf20Sopenharmony_ci 5648c2ecf20Sopenharmony_cistatic void rs780_set_uvd_clock_before_set_eng_clock(struct radeon_device *rdev, 5658c2ecf20Sopenharmony_ci struct radeon_ps *new_ps, 5668c2ecf20Sopenharmony_ci struct radeon_ps *old_ps) 5678c2ecf20Sopenharmony_ci{ 5688c2ecf20Sopenharmony_ci struct igp_ps *new_state = rs780_get_ps(new_ps); 5698c2ecf20Sopenharmony_ci struct igp_ps *current_state = rs780_get_ps(old_ps); 5708c2ecf20Sopenharmony_ci 5718c2ecf20Sopenharmony_ci if ((new_ps->vclk == old_ps->vclk) && 5728c2ecf20Sopenharmony_ci (new_ps->dclk == old_ps->dclk)) 5738c2ecf20Sopenharmony_ci return; 5748c2ecf20Sopenharmony_ci 5758c2ecf20Sopenharmony_ci if (new_state->sclk_high >= current_state->sclk_high) 5768c2ecf20Sopenharmony_ci return; 5778c2ecf20Sopenharmony_ci 5788c2ecf20Sopenharmony_ci radeon_set_uvd_clocks(rdev, new_ps->vclk, new_ps->dclk); 5798c2ecf20Sopenharmony_ci} 5808c2ecf20Sopenharmony_ci 5818c2ecf20Sopenharmony_cistatic void rs780_set_uvd_clock_after_set_eng_clock(struct radeon_device *rdev, 5828c2ecf20Sopenharmony_ci struct radeon_ps *new_ps, 5838c2ecf20Sopenharmony_ci struct radeon_ps *old_ps) 5848c2ecf20Sopenharmony_ci{ 5858c2ecf20Sopenharmony_ci struct igp_ps *new_state = rs780_get_ps(new_ps); 5868c2ecf20Sopenharmony_ci struct igp_ps *current_state = rs780_get_ps(old_ps); 5878c2ecf20Sopenharmony_ci 5888c2ecf20Sopenharmony_ci if ((new_ps->vclk == old_ps->vclk) && 5898c2ecf20Sopenharmony_ci (new_ps->dclk == old_ps->dclk)) 5908c2ecf20Sopenharmony_ci return; 5918c2ecf20Sopenharmony_ci 5928c2ecf20Sopenharmony_ci if (new_state->sclk_high < current_state->sclk_high) 5938c2ecf20Sopenharmony_ci return; 5948c2ecf20Sopenharmony_ci 5958c2ecf20Sopenharmony_ci radeon_set_uvd_clocks(rdev, new_ps->vclk, new_ps->dclk); 5968c2ecf20Sopenharmony_ci} 5978c2ecf20Sopenharmony_ci 5988c2ecf20Sopenharmony_ciint rs780_dpm_enable(struct radeon_device *rdev) 5998c2ecf20Sopenharmony_ci{ 6008c2ecf20Sopenharmony_ci struct igp_power_info *pi = rs780_get_pi(rdev); 6018c2ecf20Sopenharmony_ci struct radeon_ps *boot_ps = rdev->pm.dpm.boot_ps; 6028c2ecf20Sopenharmony_ci int ret; 6038c2ecf20Sopenharmony_ci 6048c2ecf20Sopenharmony_ci rs780_get_pm_mode_parameters(rdev); 6058c2ecf20Sopenharmony_ci rs780_disable_vbios_powersaving(rdev); 6068c2ecf20Sopenharmony_ci 6078c2ecf20Sopenharmony_ci if (r600_dynamicpm_enabled(rdev)) 6088c2ecf20Sopenharmony_ci return -EINVAL; 6098c2ecf20Sopenharmony_ci ret = rs780_initialize_dpm_parameters(rdev, boot_ps); 6108c2ecf20Sopenharmony_ci if (ret) 6118c2ecf20Sopenharmony_ci return ret; 6128c2ecf20Sopenharmony_ci rs780_start_dpm(rdev); 6138c2ecf20Sopenharmony_ci 6148c2ecf20Sopenharmony_ci rs780_preset_ranges_slow_clk_fbdiv_en(rdev); 6158c2ecf20Sopenharmony_ci rs780_preset_starting_fbdiv(rdev); 6168c2ecf20Sopenharmony_ci if (pi->voltage_control) 6178c2ecf20Sopenharmony_ci rs780_voltage_scaling_init(rdev); 6188c2ecf20Sopenharmony_ci rs780_clk_scaling_enable(rdev, true); 6198c2ecf20Sopenharmony_ci rs780_set_engine_clock_sc(rdev); 6208c2ecf20Sopenharmony_ci rs780_set_engine_clock_wfc(rdev); 6218c2ecf20Sopenharmony_ci rs780_program_at(rdev); 6228c2ecf20Sopenharmony_ci rs780_set_engine_clock_tdc(rdev); 6238c2ecf20Sopenharmony_ci rs780_set_engine_clock_ssc(rdev); 6248c2ecf20Sopenharmony_ci 6258c2ecf20Sopenharmony_ci if (pi->gfx_clock_gating) 6268c2ecf20Sopenharmony_ci r600_gfx_clockgating_enable(rdev, true); 6278c2ecf20Sopenharmony_ci 6288c2ecf20Sopenharmony_ci return 0; 6298c2ecf20Sopenharmony_ci} 6308c2ecf20Sopenharmony_ci 6318c2ecf20Sopenharmony_civoid rs780_dpm_disable(struct radeon_device *rdev) 6328c2ecf20Sopenharmony_ci{ 6338c2ecf20Sopenharmony_ci struct igp_power_info *pi = rs780_get_pi(rdev); 6348c2ecf20Sopenharmony_ci 6358c2ecf20Sopenharmony_ci r600_dynamicpm_enable(rdev, false); 6368c2ecf20Sopenharmony_ci 6378c2ecf20Sopenharmony_ci rs780_clk_scaling_enable(rdev, false); 6388c2ecf20Sopenharmony_ci rs780_voltage_scaling_enable(rdev, false); 6398c2ecf20Sopenharmony_ci 6408c2ecf20Sopenharmony_ci if (pi->gfx_clock_gating) 6418c2ecf20Sopenharmony_ci r600_gfx_clockgating_enable(rdev, false); 6428c2ecf20Sopenharmony_ci 6438c2ecf20Sopenharmony_ci if (rdev->irq.installed && 6448c2ecf20Sopenharmony_ci (rdev->pm.int_thermal_type == THERMAL_TYPE_RV6XX)) { 6458c2ecf20Sopenharmony_ci rdev->irq.dpm_thermal = false; 6468c2ecf20Sopenharmony_ci radeon_irq_set(rdev); 6478c2ecf20Sopenharmony_ci } 6488c2ecf20Sopenharmony_ci} 6498c2ecf20Sopenharmony_ci 6508c2ecf20Sopenharmony_ciint rs780_dpm_set_power_state(struct radeon_device *rdev) 6518c2ecf20Sopenharmony_ci{ 6528c2ecf20Sopenharmony_ci struct igp_power_info *pi = rs780_get_pi(rdev); 6538c2ecf20Sopenharmony_ci struct radeon_ps *new_ps = rdev->pm.dpm.requested_ps; 6548c2ecf20Sopenharmony_ci struct radeon_ps *old_ps = rdev->pm.dpm.current_ps; 6558c2ecf20Sopenharmony_ci int ret; 6568c2ecf20Sopenharmony_ci 6578c2ecf20Sopenharmony_ci rs780_get_pm_mode_parameters(rdev); 6588c2ecf20Sopenharmony_ci 6598c2ecf20Sopenharmony_ci rs780_set_uvd_clock_before_set_eng_clock(rdev, new_ps, old_ps); 6608c2ecf20Sopenharmony_ci 6618c2ecf20Sopenharmony_ci if (pi->voltage_control) { 6628c2ecf20Sopenharmony_ci rs780_force_voltage(rdev, pi->max_voltage); 6638c2ecf20Sopenharmony_ci mdelay(5); 6648c2ecf20Sopenharmony_ci } 6658c2ecf20Sopenharmony_ci 6668c2ecf20Sopenharmony_ci ret = rs780_set_engine_clock_scaling(rdev, new_ps, old_ps); 6678c2ecf20Sopenharmony_ci if (ret) 6688c2ecf20Sopenharmony_ci return ret; 6698c2ecf20Sopenharmony_ci rs780_set_engine_clock_spc(rdev, new_ps, old_ps); 6708c2ecf20Sopenharmony_ci 6718c2ecf20Sopenharmony_ci rs780_activate_engine_clk_scaling(rdev, new_ps, old_ps); 6728c2ecf20Sopenharmony_ci 6738c2ecf20Sopenharmony_ci if (pi->voltage_control) 6748c2ecf20Sopenharmony_ci rs780_enable_voltage_scaling(rdev, new_ps); 6758c2ecf20Sopenharmony_ci 6768c2ecf20Sopenharmony_ci rs780_set_uvd_clock_after_set_eng_clock(rdev, new_ps, old_ps); 6778c2ecf20Sopenharmony_ci 6788c2ecf20Sopenharmony_ci return 0; 6798c2ecf20Sopenharmony_ci} 6808c2ecf20Sopenharmony_ci 6818c2ecf20Sopenharmony_civoid rs780_dpm_setup_asic(struct radeon_device *rdev) 6828c2ecf20Sopenharmony_ci{ 6838c2ecf20Sopenharmony_ci 6848c2ecf20Sopenharmony_ci} 6858c2ecf20Sopenharmony_ci 6868c2ecf20Sopenharmony_civoid rs780_dpm_display_configuration_changed(struct radeon_device *rdev) 6878c2ecf20Sopenharmony_ci{ 6888c2ecf20Sopenharmony_ci rs780_get_pm_mode_parameters(rdev); 6898c2ecf20Sopenharmony_ci rs780_program_at(rdev); 6908c2ecf20Sopenharmony_ci} 6918c2ecf20Sopenharmony_ci 6928c2ecf20Sopenharmony_ciunion igp_info { 6938c2ecf20Sopenharmony_ci struct _ATOM_INTEGRATED_SYSTEM_INFO info; 6948c2ecf20Sopenharmony_ci struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 info_2; 6958c2ecf20Sopenharmony_ci}; 6968c2ecf20Sopenharmony_ci 6978c2ecf20Sopenharmony_ciunion power_info { 6988c2ecf20Sopenharmony_ci struct _ATOM_POWERPLAY_INFO info; 6998c2ecf20Sopenharmony_ci struct _ATOM_POWERPLAY_INFO_V2 info_2; 7008c2ecf20Sopenharmony_ci struct _ATOM_POWERPLAY_INFO_V3 info_3; 7018c2ecf20Sopenharmony_ci struct _ATOM_PPLIB_POWERPLAYTABLE pplib; 7028c2ecf20Sopenharmony_ci struct _ATOM_PPLIB_POWERPLAYTABLE2 pplib2; 7038c2ecf20Sopenharmony_ci struct _ATOM_PPLIB_POWERPLAYTABLE3 pplib3; 7048c2ecf20Sopenharmony_ci}; 7058c2ecf20Sopenharmony_ci 7068c2ecf20Sopenharmony_ciunion pplib_clock_info { 7078c2ecf20Sopenharmony_ci struct _ATOM_PPLIB_R600_CLOCK_INFO r600; 7088c2ecf20Sopenharmony_ci struct _ATOM_PPLIB_RS780_CLOCK_INFO rs780; 7098c2ecf20Sopenharmony_ci struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO evergreen; 7108c2ecf20Sopenharmony_ci struct _ATOM_PPLIB_SUMO_CLOCK_INFO sumo; 7118c2ecf20Sopenharmony_ci}; 7128c2ecf20Sopenharmony_ci 7138c2ecf20Sopenharmony_ciunion pplib_power_state { 7148c2ecf20Sopenharmony_ci struct _ATOM_PPLIB_STATE v1; 7158c2ecf20Sopenharmony_ci struct _ATOM_PPLIB_STATE_V2 v2; 7168c2ecf20Sopenharmony_ci}; 7178c2ecf20Sopenharmony_ci 7188c2ecf20Sopenharmony_cistatic void rs780_parse_pplib_non_clock_info(struct radeon_device *rdev, 7198c2ecf20Sopenharmony_ci struct radeon_ps *rps, 7208c2ecf20Sopenharmony_ci struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info, 7218c2ecf20Sopenharmony_ci u8 table_rev) 7228c2ecf20Sopenharmony_ci{ 7238c2ecf20Sopenharmony_ci rps->caps = le32_to_cpu(non_clock_info->ulCapsAndSettings); 7248c2ecf20Sopenharmony_ci rps->class = le16_to_cpu(non_clock_info->usClassification); 7258c2ecf20Sopenharmony_ci rps->class2 = le16_to_cpu(non_clock_info->usClassification2); 7268c2ecf20Sopenharmony_ci 7278c2ecf20Sopenharmony_ci if (ATOM_PPLIB_NONCLOCKINFO_VER1 < table_rev) { 7288c2ecf20Sopenharmony_ci rps->vclk = le32_to_cpu(non_clock_info->ulVCLK); 7298c2ecf20Sopenharmony_ci rps->dclk = le32_to_cpu(non_clock_info->ulDCLK); 7308c2ecf20Sopenharmony_ci } else { 7318c2ecf20Sopenharmony_ci rps->vclk = 0; 7328c2ecf20Sopenharmony_ci rps->dclk = 0; 7338c2ecf20Sopenharmony_ci } 7348c2ecf20Sopenharmony_ci 7358c2ecf20Sopenharmony_ci if (r600_is_uvd_state(rps->class, rps->class2)) { 7368c2ecf20Sopenharmony_ci if ((rps->vclk == 0) || (rps->dclk == 0)) { 7378c2ecf20Sopenharmony_ci rps->vclk = RS780_DEFAULT_VCLK_FREQ; 7388c2ecf20Sopenharmony_ci rps->dclk = RS780_DEFAULT_DCLK_FREQ; 7398c2ecf20Sopenharmony_ci } 7408c2ecf20Sopenharmony_ci } 7418c2ecf20Sopenharmony_ci 7428c2ecf20Sopenharmony_ci if (rps->class & ATOM_PPLIB_CLASSIFICATION_BOOT) 7438c2ecf20Sopenharmony_ci rdev->pm.dpm.boot_ps = rps; 7448c2ecf20Sopenharmony_ci if (rps->class & ATOM_PPLIB_CLASSIFICATION_UVDSTATE) 7458c2ecf20Sopenharmony_ci rdev->pm.dpm.uvd_ps = rps; 7468c2ecf20Sopenharmony_ci} 7478c2ecf20Sopenharmony_ci 7488c2ecf20Sopenharmony_cistatic void rs780_parse_pplib_clock_info(struct radeon_device *rdev, 7498c2ecf20Sopenharmony_ci struct radeon_ps *rps, 7508c2ecf20Sopenharmony_ci union pplib_clock_info *clock_info) 7518c2ecf20Sopenharmony_ci{ 7528c2ecf20Sopenharmony_ci struct igp_ps *ps = rs780_get_ps(rps); 7538c2ecf20Sopenharmony_ci u32 sclk; 7548c2ecf20Sopenharmony_ci 7558c2ecf20Sopenharmony_ci sclk = le16_to_cpu(clock_info->rs780.usLowEngineClockLow); 7568c2ecf20Sopenharmony_ci sclk |= clock_info->rs780.ucLowEngineClockHigh << 16; 7578c2ecf20Sopenharmony_ci ps->sclk_low = sclk; 7588c2ecf20Sopenharmony_ci sclk = le16_to_cpu(clock_info->rs780.usHighEngineClockLow); 7598c2ecf20Sopenharmony_ci sclk |= clock_info->rs780.ucHighEngineClockHigh << 16; 7608c2ecf20Sopenharmony_ci ps->sclk_high = sclk; 7618c2ecf20Sopenharmony_ci switch (le16_to_cpu(clock_info->rs780.usVDDC)) { 7628c2ecf20Sopenharmony_ci case ATOM_PPLIB_RS780_VOLTAGE_NONE: 7638c2ecf20Sopenharmony_ci default: 7648c2ecf20Sopenharmony_ci ps->min_voltage = RS780_VDDC_LEVEL_UNKNOWN; 7658c2ecf20Sopenharmony_ci ps->max_voltage = RS780_VDDC_LEVEL_UNKNOWN; 7668c2ecf20Sopenharmony_ci break; 7678c2ecf20Sopenharmony_ci case ATOM_PPLIB_RS780_VOLTAGE_LOW: 7688c2ecf20Sopenharmony_ci ps->min_voltage = RS780_VDDC_LEVEL_LOW; 7698c2ecf20Sopenharmony_ci ps->max_voltage = RS780_VDDC_LEVEL_LOW; 7708c2ecf20Sopenharmony_ci break; 7718c2ecf20Sopenharmony_ci case ATOM_PPLIB_RS780_VOLTAGE_HIGH: 7728c2ecf20Sopenharmony_ci ps->min_voltage = RS780_VDDC_LEVEL_HIGH; 7738c2ecf20Sopenharmony_ci ps->max_voltage = RS780_VDDC_LEVEL_HIGH; 7748c2ecf20Sopenharmony_ci break; 7758c2ecf20Sopenharmony_ci case ATOM_PPLIB_RS780_VOLTAGE_VARIABLE: 7768c2ecf20Sopenharmony_ci ps->min_voltage = RS780_VDDC_LEVEL_LOW; 7778c2ecf20Sopenharmony_ci ps->max_voltage = RS780_VDDC_LEVEL_HIGH; 7788c2ecf20Sopenharmony_ci break; 7798c2ecf20Sopenharmony_ci } 7808c2ecf20Sopenharmony_ci ps->flags = le32_to_cpu(clock_info->rs780.ulFlags); 7818c2ecf20Sopenharmony_ci 7828c2ecf20Sopenharmony_ci if (rps->class & ATOM_PPLIB_CLASSIFICATION_BOOT) { 7838c2ecf20Sopenharmony_ci ps->sclk_low = rdev->clock.default_sclk; 7848c2ecf20Sopenharmony_ci ps->sclk_high = rdev->clock.default_sclk; 7858c2ecf20Sopenharmony_ci ps->min_voltage = RS780_VDDC_LEVEL_HIGH; 7868c2ecf20Sopenharmony_ci ps->max_voltage = RS780_VDDC_LEVEL_HIGH; 7878c2ecf20Sopenharmony_ci } 7888c2ecf20Sopenharmony_ci} 7898c2ecf20Sopenharmony_ci 7908c2ecf20Sopenharmony_cistatic int rs780_parse_power_table(struct radeon_device *rdev) 7918c2ecf20Sopenharmony_ci{ 7928c2ecf20Sopenharmony_ci struct radeon_mode_info *mode_info = &rdev->mode_info; 7938c2ecf20Sopenharmony_ci struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info; 7948c2ecf20Sopenharmony_ci union pplib_power_state *power_state; 7958c2ecf20Sopenharmony_ci int i; 7968c2ecf20Sopenharmony_ci union pplib_clock_info *clock_info; 7978c2ecf20Sopenharmony_ci union power_info *power_info; 7988c2ecf20Sopenharmony_ci int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo); 7998c2ecf20Sopenharmony_ci u16 data_offset; 8008c2ecf20Sopenharmony_ci u8 frev, crev; 8018c2ecf20Sopenharmony_ci struct igp_ps *ps; 8028c2ecf20Sopenharmony_ci 8038c2ecf20Sopenharmony_ci if (!atom_parse_data_header(mode_info->atom_context, index, NULL, 8048c2ecf20Sopenharmony_ci &frev, &crev, &data_offset)) 8058c2ecf20Sopenharmony_ci return -EINVAL; 8068c2ecf20Sopenharmony_ci power_info = (union power_info *)(mode_info->atom_context->bios + data_offset); 8078c2ecf20Sopenharmony_ci 8088c2ecf20Sopenharmony_ci rdev->pm.dpm.ps = kcalloc(power_info->pplib.ucNumStates, 8098c2ecf20Sopenharmony_ci sizeof(struct radeon_ps), 8108c2ecf20Sopenharmony_ci GFP_KERNEL); 8118c2ecf20Sopenharmony_ci if (!rdev->pm.dpm.ps) 8128c2ecf20Sopenharmony_ci return -ENOMEM; 8138c2ecf20Sopenharmony_ci 8148c2ecf20Sopenharmony_ci for (i = 0; i < power_info->pplib.ucNumStates; i++) { 8158c2ecf20Sopenharmony_ci power_state = (union pplib_power_state *) 8168c2ecf20Sopenharmony_ci (mode_info->atom_context->bios + data_offset + 8178c2ecf20Sopenharmony_ci le16_to_cpu(power_info->pplib.usStateArrayOffset) + 8188c2ecf20Sopenharmony_ci i * power_info->pplib.ucStateEntrySize); 8198c2ecf20Sopenharmony_ci non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *) 8208c2ecf20Sopenharmony_ci (mode_info->atom_context->bios + data_offset + 8218c2ecf20Sopenharmony_ci le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset) + 8228c2ecf20Sopenharmony_ci (power_state->v1.ucNonClockStateIndex * 8238c2ecf20Sopenharmony_ci power_info->pplib.ucNonClockSize)); 8248c2ecf20Sopenharmony_ci if (power_info->pplib.ucStateEntrySize - 1) { 8258c2ecf20Sopenharmony_ci clock_info = (union pplib_clock_info *) 8268c2ecf20Sopenharmony_ci (mode_info->atom_context->bios + data_offset + 8278c2ecf20Sopenharmony_ci le16_to_cpu(power_info->pplib.usClockInfoArrayOffset) + 8288c2ecf20Sopenharmony_ci (power_state->v1.ucClockStateIndices[0] * 8298c2ecf20Sopenharmony_ci power_info->pplib.ucClockInfoSize)); 8308c2ecf20Sopenharmony_ci ps = kzalloc(sizeof(struct igp_ps), GFP_KERNEL); 8318c2ecf20Sopenharmony_ci if (ps == NULL) { 8328c2ecf20Sopenharmony_ci kfree(rdev->pm.dpm.ps); 8338c2ecf20Sopenharmony_ci return -ENOMEM; 8348c2ecf20Sopenharmony_ci } 8358c2ecf20Sopenharmony_ci rdev->pm.dpm.ps[i].ps_priv = ps; 8368c2ecf20Sopenharmony_ci rs780_parse_pplib_non_clock_info(rdev, &rdev->pm.dpm.ps[i], 8378c2ecf20Sopenharmony_ci non_clock_info, 8388c2ecf20Sopenharmony_ci power_info->pplib.ucNonClockSize); 8398c2ecf20Sopenharmony_ci rs780_parse_pplib_clock_info(rdev, 8408c2ecf20Sopenharmony_ci &rdev->pm.dpm.ps[i], 8418c2ecf20Sopenharmony_ci clock_info); 8428c2ecf20Sopenharmony_ci } 8438c2ecf20Sopenharmony_ci } 8448c2ecf20Sopenharmony_ci rdev->pm.dpm.num_ps = power_info->pplib.ucNumStates; 8458c2ecf20Sopenharmony_ci return 0; 8468c2ecf20Sopenharmony_ci} 8478c2ecf20Sopenharmony_ci 8488c2ecf20Sopenharmony_ciint rs780_dpm_init(struct radeon_device *rdev) 8498c2ecf20Sopenharmony_ci{ 8508c2ecf20Sopenharmony_ci struct igp_power_info *pi; 8518c2ecf20Sopenharmony_ci int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo); 8528c2ecf20Sopenharmony_ci union igp_info *info; 8538c2ecf20Sopenharmony_ci u16 data_offset; 8548c2ecf20Sopenharmony_ci u8 frev, crev; 8558c2ecf20Sopenharmony_ci int ret; 8568c2ecf20Sopenharmony_ci 8578c2ecf20Sopenharmony_ci pi = kzalloc(sizeof(struct igp_power_info), GFP_KERNEL); 8588c2ecf20Sopenharmony_ci if (pi == NULL) 8598c2ecf20Sopenharmony_ci return -ENOMEM; 8608c2ecf20Sopenharmony_ci rdev->pm.dpm.priv = pi; 8618c2ecf20Sopenharmony_ci 8628c2ecf20Sopenharmony_ci ret = r600_get_platform_caps(rdev); 8638c2ecf20Sopenharmony_ci if (ret) 8648c2ecf20Sopenharmony_ci return ret; 8658c2ecf20Sopenharmony_ci 8668c2ecf20Sopenharmony_ci ret = rs780_parse_power_table(rdev); 8678c2ecf20Sopenharmony_ci if (ret) 8688c2ecf20Sopenharmony_ci return ret; 8698c2ecf20Sopenharmony_ci 8708c2ecf20Sopenharmony_ci pi->voltage_control = false; 8718c2ecf20Sopenharmony_ci pi->gfx_clock_gating = true; 8728c2ecf20Sopenharmony_ci 8738c2ecf20Sopenharmony_ci if (atom_parse_data_header(rdev->mode_info.atom_context, index, NULL, 8748c2ecf20Sopenharmony_ci &frev, &crev, &data_offset)) { 8758c2ecf20Sopenharmony_ci info = (union igp_info *)(rdev->mode_info.atom_context->bios + data_offset); 8768c2ecf20Sopenharmony_ci 8778c2ecf20Sopenharmony_ci /* Get various system informations from bios */ 8788c2ecf20Sopenharmony_ci switch (crev) { 8798c2ecf20Sopenharmony_ci case 1: 8808c2ecf20Sopenharmony_ci pi->num_of_cycles_in_period = 8818c2ecf20Sopenharmony_ci info->info.ucNumberOfCyclesInPeriod; 8828c2ecf20Sopenharmony_ci pi->num_of_cycles_in_period |= 8838c2ecf20Sopenharmony_ci info->info.ucNumberOfCyclesInPeriodHi << 8; 8848c2ecf20Sopenharmony_ci pi->invert_pwm_required = 8858c2ecf20Sopenharmony_ci (pi->num_of_cycles_in_period & 0x8000) ? true : false; 8868c2ecf20Sopenharmony_ci pi->boot_voltage = info->info.ucStartingPWM_HighTime; 8878c2ecf20Sopenharmony_ci pi->max_voltage = info->info.ucMaxNBVoltage; 8888c2ecf20Sopenharmony_ci pi->max_voltage |= info->info.ucMaxNBVoltageHigh << 8; 8898c2ecf20Sopenharmony_ci pi->min_voltage = info->info.ucMinNBVoltage; 8908c2ecf20Sopenharmony_ci pi->min_voltage |= info->info.ucMinNBVoltageHigh << 8; 8918c2ecf20Sopenharmony_ci pi->inter_voltage_low = 8928c2ecf20Sopenharmony_ci le16_to_cpu(info->info.usInterNBVoltageLow); 8938c2ecf20Sopenharmony_ci pi->inter_voltage_high = 8948c2ecf20Sopenharmony_ci le16_to_cpu(info->info.usInterNBVoltageHigh); 8958c2ecf20Sopenharmony_ci pi->voltage_control = true; 8968c2ecf20Sopenharmony_ci pi->bootup_uma_clk = info->info.usK8MemoryClock * 100; 8978c2ecf20Sopenharmony_ci break; 8988c2ecf20Sopenharmony_ci case 2: 8998c2ecf20Sopenharmony_ci pi->num_of_cycles_in_period = 9008c2ecf20Sopenharmony_ci le16_to_cpu(info->info_2.usNumberOfCyclesInPeriod); 9018c2ecf20Sopenharmony_ci pi->invert_pwm_required = 9028c2ecf20Sopenharmony_ci (pi->num_of_cycles_in_period & 0x8000) ? true : false; 9038c2ecf20Sopenharmony_ci pi->boot_voltage = 9048c2ecf20Sopenharmony_ci le16_to_cpu(info->info_2.usBootUpNBVoltage); 9058c2ecf20Sopenharmony_ci pi->max_voltage = 9068c2ecf20Sopenharmony_ci le16_to_cpu(info->info_2.usMaxNBVoltage); 9078c2ecf20Sopenharmony_ci pi->min_voltage = 9088c2ecf20Sopenharmony_ci le16_to_cpu(info->info_2.usMinNBVoltage); 9098c2ecf20Sopenharmony_ci pi->system_config = 9108c2ecf20Sopenharmony_ci le32_to_cpu(info->info_2.ulSystemConfig); 9118c2ecf20Sopenharmony_ci pi->pwm_voltage_control = 9128c2ecf20Sopenharmony_ci (pi->system_config & 0x4) ? true : false; 9138c2ecf20Sopenharmony_ci pi->voltage_control = true; 9148c2ecf20Sopenharmony_ci pi->bootup_uma_clk = le32_to_cpu(info->info_2.ulBootUpUMAClock); 9158c2ecf20Sopenharmony_ci break; 9168c2ecf20Sopenharmony_ci default: 9178c2ecf20Sopenharmony_ci DRM_ERROR("No integrated system info for your GPU\n"); 9188c2ecf20Sopenharmony_ci return -EINVAL; 9198c2ecf20Sopenharmony_ci } 9208c2ecf20Sopenharmony_ci if (pi->min_voltage > pi->max_voltage) 9218c2ecf20Sopenharmony_ci pi->voltage_control = false; 9228c2ecf20Sopenharmony_ci if (pi->pwm_voltage_control) { 9238c2ecf20Sopenharmony_ci if ((pi->num_of_cycles_in_period == 0) || 9248c2ecf20Sopenharmony_ci (pi->max_voltage == 0) || 9258c2ecf20Sopenharmony_ci (pi->min_voltage == 0)) 9268c2ecf20Sopenharmony_ci pi->voltage_control = false; 9278c2ecf20Sopenharmony_ci } else { 9288c2ecf20Sopenharmony_ci if ((pi->num_of_cycles_in_period == 0) || 9298c2ecf20Sopenharmony_ci (pi->max_voltage == 0)) 9308c2ecf20Sopenharmony_ci pi->voltage_control = false; 9318c2ecf20Sopenharmony_ci } 9328c2ecf20Sopenharmony_ci 9338c2ecf20Sopenharmony_ci return 0; 9348c2ecf20Sopenharmony_ci } 9358c2ecf20Sopenharmony_ci radeon_dpm_fini(rdev); 9368c2ecf20Sopenharmony_ci return -EINVAL; 9378c2ecf20Sopenharmony_ci} 9388c2ecf20Sopenharmony_ci 9398c2ecf20Sopenharmony_civoid rs780_dpm_print_power_state(struct radeon_device *rdev, 9408c2ecf20Sopenharmony_ci struct radeon_ps *rps) 9418c2ecf20Sopenharmony_ci{ 9428c2ecf20Sopenharmony_ci struct igp_ps *ps = rs780_get_ps(rps); 9438c2ecf20Sopenharmony_ci 9448c2ecf20Sopenharmony_ci r600_dpm_print_class_info(rps->class, rps->class2); 9458c2ecf20Sopenharmony_ci r600_dpm_print_cap_info(rps->caps); 9468c2ecf20Sopenharmony_ci printk("\tuvd vclk: %d dclk: %d\n", rps->vclk, rps->dclk); 9478c2ecf20Sopenharmony_ci printk("\t\tpower level 0 sclk: %u vddc_index: %d\n", 9488c2ecf20Sopenharmony_ci ps->sclk_low, ps->min_voltage); 9498c2ecf20Sopenharmony_ci printk("\t\tpower level 1 sclk: %u vddc_index: %d\n", 9508c2ecf20Sopenharmony_ci ps->sclk_high, ps->max_voltage); 9518c2ecf20Sopenharmony_ci r600_dpm_print_ps_status(rdev, rps); 9528c2ecf20Sopenharmony_ci} 9538c2ecf20Sopenharmony_ci 9548c2ecf20Sopenharmony_civoid rs780_dpm_fini(struct radeon_device *rdev) 9558c2ecf20Sopenharmony_ci{ 9568c2ecf20Sopenharmony_ci int i; 9578c2ecf20Sopenharmony_ci 9588c2ecf20Sopenharmony_ci for (i = 0; i < rdev->pm.dpm.num_ps; i++) { 9598c2ecf20Sopenharmony_ci kfree(rdev->pm.dpm.ps[i].ps_priv); 9608c2ecf20Sopenharmony_ci } 9618c2ecf20Sopenharmony_ci kfree(rdev->pm.dpm.ps); 9628c2ecf20Sopenharmony_ci kfree(rdev->pm.dpm.priv); 9638c2ecf20Sopenharmony_ci} 9648c2ecf20Sopenharmony_ci 9658c2ecf20Sopenharmony_ciu32 rs780_dpm_get_sclk(struct radeon_device *rdev, bool low) 9668c2ecf20Sopenharmony_ci{ 9678c2ecf20Sopenharmony_ci struct igp_ps *requested_state = rs780_get_ps(rdev->pm.dpm.requested_ps); 9688c2ecf20Sopenharmony_ci 9698c2ecf20Sopenharmony_ci if (low) 9708c2ecf20Sopenharmony_ci return requested_state->sclk_low; 9718c2ecf20Sopenharmony_ci else 9728c2ecf20Sopenharmony_ci return requested_state->sclk_high; 9738c2ecf20Sopenharmony_ci} 9748c2ecf20Sopenharmony_ci 9758c2ecf20Sopenharmony_ciu32 rs780_dpm_get_mclk(struct radeon_device *rdev, bool low) 9768c2ecf20Sopenharmony_ci{ 9778c2ecf20Sopenharmony_ci struct igp_power_info *pi = rs780_get_pi(rdev); 9788c2ecf20Sopenharmony_ci 9798c2ecf20Sopenharmony_ci return pi->bootup_uma_clk; 9808c2ecf20Sopenharmony_ci} 9818c2ecf20Sopenharmony_ci 9828c2ecf20Sopenharmony_civoid rs780_dpm_debugfs_print_current_performance_level(struct radeon_device *rdev, 9838c2ecf20Sopenharmony_ci struct seq_file *m) 9848c2ecf20Sopenharmony_ci{ 9858c2ecf20Sopenharmony_ci struct radeon_ps *rps = rdev->pm.dpm.current_ps; 9868c2ecf20Sopenharmony_ci struct igp_ps *ps = rs780_get_ps(rps); 9878c2ecf20Sopenharmony_ci u32 current_fb_div = RREG32(FVTHROT_STATUS_REG0) & CURRENT_FEEDBACK_DIV_MASK; 9888c2ecf20Sopenharmony_ci u32 func_cntl = RREG32(CG_SPLL_FUNC_CNTL); 9898c2ecf20Sopenharmony_ci u32 ref_div = ((func_cntl & SPLL_REF_DIV_MASK) >> SPLL_REF_DIV_SHIFT) + 1; 9908c2ecf20Sopenharmony_ci u32 post_div = ((func_cntl & SPLL_SW_HILEN_MASK) >> SPLL_SW_HILEN_SHIFT) + 1 + 9918c2ecf20Sopenharmony_ci ((func_cntl & SPLL_SW_LOLEN_MASK) >> SPLL_SW_LOLEN_SHIFT) + 1; 9928c2ecf20Sopenharmony_ci u32 sclk = (rdev->clock.spll.reference_freq * current_fb_div) / 9938c2ecf20Sopenharmony_ci (post_div * ref_div); 9948c2ecf20Sopenharmony_ci 9958c2ecf20Sopenharmony_ci seq_printf(m, "uvd vclk: %d dclk: %d\n", rps->vclk, rps->dclk); 9968c2ecf20Sopenharmony_ci 9978c2ecf20Sopenharmony_ci /* guess based on the current sclk */ 9988c2ecf20Sopenharmony_ci if (sclk < (ps->sclk_low + 500)) 9998c2ecf20Sopenharmony_ci seq_printf(m, "power level 0 sclk: %u vddc_index: %d\n", 10008c2ecf20Sopenharmony_ci ps->sclk_low, ps->min_voltage); 10018c2ecf20Sopenharmony_ci else 10028c2ecf20Sopenharmony_ci seq_printf(m, "power level 1 sclk: %u vddc_index: %d\n", 10038c2ecf20Sopenharmony_ci ps->sclk_high, ps->max_voltage); 10048c2ecf20Sopenharmony_ci} 10058c2ecf20Sopenharmony_ci 10068c2ecf20Sopenharmony_ci/* get the current sclk in 10 khz units */ 10078c2ecf20Sopenharmony_ciu32 rs780_dpm_get_current_sclk(struct radeon_device *rdev) 10088c2ecf20Sopenharmony_ci{ 10098c2ecf20Sopenharmony_ci u32 current_fb_div = RREG32(FVTHROT_STATUS_REG0) & CURRENT_FEEDBACK_DIV_MASK; 10108c2ecf20Sopenharmony_ci u32 func_cntl = RREG32(CG_SPLL_FUNC_CNTL); 10118c2ecf20Sopenharmony_ci u32 ref_div = ((func_cntl & SPLL_REF_DIV_MASK) >> SPLL_REF_DIV_SHIFT) + 1; 10128c2ecf20Sopenharmony_ci u32 post_div = ((func_cntl & SPLL_SW_HILEN_MASK) >> SPLL_SW_HILEN_SHIFT) + 1 + 10138c2ecf20Sopenharmony_ci ((func_cntl & SPLL_SW_LOLEN_MASK) >> SPLL_SW_LOLEN_SHIFT) + 1; 10148c2ecf20Sopenharmony_ci u32 sclk = (rdev->clock.spll.reference_freq * current_fb_div) / 10158c2ecf20Sopenharmony_ci (post_div * ref_div); 10168c2ecf20Sopenharmony_ci 10178c2ecf20Sopenharmony_ci return sclk; 10188c2ecf20Sopenharmony_ci} 10198c2ecf20Sopenharmony_ci 10208c2ecf20Sopenharmony_ci/* get the current mclk in 10 khz units */ 10218c2ecf20Sopenharmony_ciu32 rs780_dpm_get_current_mclk(struct radeon_device *rdev) 10228c2ecf20Sopenharmony_ci{ 10238c2ecf20Sopenharmony_ci struct igp_power_info *pi = rs780_get_pi(rdev); 10248c2ecf20Sopenharmony_ci 10258c2ecf20Sopenharmony_ci return pi->bootup_uma_clk; 10268c2ecf20Sopenharmony_ci} 10278c2ecf20Sopenharmony_ci 10288c2ecf20Sopenharmony_ciint rs780_dpm_force_performance_level(struct radeon_device *rdev, 10298c2ecf20Sopenharmony_ci enum radeon_dpm_forced_level level) 10308c2ecf20Sopenharmony_ci{ 10318c2ecf20Sopenharmony_ci struct igp_power_info *pi = rs780_get_pi(rdev); 10328c2ecf20Sopenharmony_ci struct radeon_ps *rps = rdev->pm.dpm.current_ps; 10338c2ecf20Sopenharmony_ci struct igp_ps *ps = rs780_get_ps(rps); 10348c2ecf20Sopenharmony_ci struct atom_clock_dividers dividers; 10358c2ecf20Sopenharmony_ci int ret; 10368c2ecf20Sopenharmony_ci 10378c2ecf20Sopenharmony_ci rs780_clk_scaling_enable(rdev, false); 10388c2ecf20Sopenharmony_ci rs780_voltage_scaling_enable(rdev, false); 10398c2ecf20Sopenharmony_ci 10408c2ecf20Sopenharmony_ci if (level == RADEON_DPM_FORCED_LEVEL_HIGH) { 10418c2ecf20Sopenharmony_ci if (pi->voltage_control) 10428c2ecf20Sopenharmony_ci rs780_force_voltage(rdev, pi->max_voltage); 10438c2ecf20Sopenharmony_ci 10448c2ecf20Sopenharmony_ci ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM, 10458c2ecf20Sopenharmony_ci ps->sclk_high, false, ÷rs); 10468c2ecf20Sopenharmony_ci if (ret) 10478c2ecf20Sopenharmony_ci return ret; 10488c2ecf20Sopenharmony_ci 10498c2ecf20Sopenharmony_ci rs780_force_fbdiv(rdev, dividers.fb_div); 10508c2ecf20Sopenharmony_ci } else if (level == RADEON_DPM_FORCED_LEVEL_LOW) { 10518c2ecf20Sopenharmony_ci ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM, 10528c2ecf20Sopenharmony_ci ps->sclk_low, false, ÷rs); 10538c2ecf20Sopenharmony_ci if (ret) 10548c2ecf20Sopenharmony_ci return ret; 10558c2ecf20Sopenharmony_ci 10568c2ecf20Sopenharmony_ci rs780_force_fbdiv(rdev, dividers.fb_div); 10578c2ecf20Sopenharmony_ci 10588c2ecf20Sopenharmony_ci if (pi->voltage_control) 10598c2ecf20Sopenharmony_ci rs780_force_voltage(rdev, pi->min_voltage); 10608c2ecf20Sopenharmony_ci } else { 10618c2ecf20Sopenharmony_ci if (pi->voltage_control) 10628c2ecf20Sopenharmony_ci rs780_force_voltage(rdev, pi->max_voltage); 10638c2ecf20Sopenharmony_ci 10648c2ecf20Sopenharmony_ci if (ps->sclk_high != ps->sclk_low) { 10658c2ecf20Sopenharmony_ci WREG32_P(FVTHROT_FBDIV_REG1, 0, ~FORCE_FEEDBACK_DIV); 10668c2ecf20Sopenharmony_ci rs780_clk_scaling_enable(rdev, true); 10678c2ecf20Sopenharmony_ci } 10688c2ecf20Sopenharmony_ci 10698c2ecf20Sopenharmony_ci if (pi->voltage_control) { 10708c2ecf20Sopenharmony_ci rs780_voltage_scaling_enable(rdev, true); 10718c2ecf20Sopenharmony_ci rs780_enable_voltage_scaling(rdev, rps); 10728c2ecf20Sopenharmony_ci } 10738c2ecf20Sopenharmony_ci } 10748c2ecf20Sopenharmony_ci 10758c2ecf20Sopenharmony_ci rdev->pm.dpm.forced_level = level; 10768c2ecf20Sopenharmony_ci 10778c2ecf20Sopenharmony_ci return 0; 10788c2ecf20Sopenharmony_ci} 1079