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 */ 238c2ecf20Sopenharmony_ci#ifndef __RV770_DPM_H__ 248c2ecf20Sopenharmony_ci#define __RV770_DPM_H__ 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci#include "radeon.h" 278c2ecf20Sopenharmony_ci#include "rv770_smc.h" 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_cistruct rv770_clock_registers { 308c2ecf20Sopenharmony_ci u32 cg_spll_func_cntl; 318c2ecf20Sopenharmony_ci u32 cg_spll_func_cntl_2; 328c2ecf20Sopenharmony_ci u32 cg_spll_func_cntl_3; 338c2ecf20Sopenharmony_ci u32 cg_spll_spread_spectrum; 348c2ecf20Sopenharmony_ci u32 cg_spll_spread_spectrum_2; 358c2ecf20Sopenharmony_ci u32 mpll_ad_func_cntl; 368c2ecf20Sopenharmony_ci u32 mpll_ad_func_cntl_2; 378c2ecf20Sopenharmony_ci u32 mpll_dq_func_cntl; 388c2ecf20Sopenharmony_ci u32 mpll_dq_func_cntl_2; 398c2ecf20Sopenharmony_ci u32 mclk_pwrmgt_cntl; 408c2ecf20Sopenharmony_ci u32 dll_cntl; 418c2ecf20Sopenharmony_ci u32 mpll_ss1; 428c2ecf20Sopenharmony_ci u32 mpll_ss2; 438c2ecf20Sopenharmony_ci}; 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_cistruct rv730_clock_registers { 468c2ecf20Sopenharmony_ci u32 cg_spll_func_cntl; 478c2ecf20Sopenharmony_ci u32 cg_spll_func_cntl_2; 488c2ecf20Sopenharmony_ci u32 cg_spll_func_cntl_3; 498c2ecf20Sopenharmony_ci u32 cg_spll_spread_spectrum; 508c2ecf20Sopenharmony_ci u32 cg_spll_spread_spectrum_2; 518c2ecf20Sopenharmony_ci u32 mclk_pwrmgt_cntl; 528c2ecf20Sopenharmony_ci u32 dll_cntl; 538c2ecf20Sopenharmony_ci u32 mpll_func_cntl; 548c2ecf20Sopenharmony_ci u32 mpll_func_cntl2; 558c2ecf20Sopenharmony_ci u32 mpll_func_cntl3; 568c2ecf20Sopenharmony_ci u32 mpll_ss; 578c2ecf20Sopenharmony_ci u32 mpll_ss2; 588c2ecf20Sopenharmony_ci}; 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ciunion r7xx_clock_registers { 618c2ecf20Sopenharmony_ci struct rv770_clock_registers rv770; 628c2ecf20Sopenharmony_ci struct rv730_clock_registers rv730; 638c2ecf20Sopenharmony_ci}; 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_cistruct vddc_table_entry { 668c2ecf20Sopenharmony_ci u16 vddc; 678c2ecf20Sopenharmony_ci u8 vddc_index; 688c2ecf20Sopenharmony_ci u8 high_smio; 698c2ecf20Sopenharmony_ci u32 low_smio; 708c2ecf20Sopenharmony_ci}; 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci#define MAX_NO_OF_MVDD_VALUES 2 738c2ecf20Sopenharmony_ci#define MAX_NO_VREG_STEPS 32 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_cistruct rv7xx_power_info { 768c2ecf20Sopenharmony_ci /* flags */ 778c2ecf20Sopenharmony_ci bool mem_gddr5; 788c2ecf20Sopenharmony_ci bool pcie_gen2; 798c2ecf20Sopenharmony_ci bool dynamic_pcie_gen2; 808c2ecf20Sopenharmony_ci bool acpi_pcie_gen2; 818c2ecf20Sopenharmony_ci bool boot_in_gen2; 828c2ecf20Sopenharmony_ci bool voltage_control; /* vddc */ 838c2ecf20Sopenharmony_ci bool mvdd_control; 848c2ecf20Sopenharmony_ci bool sclk_ss; 858c2ecf20Sopenharmony_ci bool mclk_ss; 868c2ecf20Sopenharmony_ci bool dynamic_ss; 878c2ecf20Sopenharmony_ci bool gfx_clock_gating; 888c2ecf20Sopenharmony_ci bool mg_clock_gating; 898c2ecf20Sopenharmony_ci bool mgcgtssm; 908c2ecf20Sopenharmony_ci bool power_gating; 918c2ecf20Sopenharmony_ci bool thermal_protection; 928c2ecf20Sopenharmony_ci bool display_gap; 938c2ecf20Sopenharmony_ci bool dcodt; 948c2ecf20Sopenharmony_ci bool ulps; 958c2ecf20Sopenharmony_ci /* registers */ 968c2ecf20Sopenharmony_ci union r7xx_clock_registers clk_regs; 978c2ecf20Sopenharmony_ci u32 s0_vid_lower_smio_cntl; 988c2ecf20Sopenharmony_ci /* voltage */ 998c2ecf20Sopenharmony_ci u32 vddc_mask_low; 1008c2ecf20Sopenharmony_ci u32 mvdd_mask_low; 1018c2ecf20Sopenharmony_ci u32 mvdd_split_frequency; 1028c2ecf20Sopenharmony_ci u32 mvdd_low_smio[MAX_NO_OF_MVDD_VALUES]; 1038c2ecf20Sopenharmony_ci u16 max_vddc; 1048c2ecf20Sopenharmony_ci u16 max_vddc_in_table; 1058c2ecf20Sopenharmony_ci u16 min_vddc_in_table; 1068c2ecf20Sopenharmony_ci struct vddc_table_entry vddc_table[MAX_NO_VREG_STEPS]; 1078c2ecf20Sopenharmony_ci u8 valid_vddc_entries; 1088c2ecf20Sopenharmony_ci /* dc odt */ 1098c2ecf20Sopenharmony_ci u32 mclk_odt_threshold; 1108c2ecf20Sopenharmony_ci u8 odt_value_0[2]; 1118c2ecf20Sopenharmony_ci u8 odt_value_1[2]; 1128c2ecf20Sopenharmony_ci /* stored values */ 1138c2ecf20Sopenharmony_ci u32 boot_sclk; 1148c2ecf20Sopenharmony_ci u16 acpi_vddc; 1158c2ecf20Sopenharmony_ci u32 ref_div; 1168c2ecf20Sopenharmony_ci u32 active_auto_throttle_sources; 1178c2ecf20Sopenharmony_ci u32 mclk_stutter_mode_threshold; 1188c2ecf20Sopenharmony_ci u32 mclk_strobe_mode_threshold; 1198c2ecf20Sopenharmony_ci u32 mclk_edc_enable_threshold; 1208c2ecf20Sopenharmony_ci u32 bsp; 1218c2ecf20Sopenharmony_ci u32 bsu; 1228c2ecf20Sopenharmony_ci u32 pbsp; 1238c2ecf20Sopenharmony_ci u32 pbsu; 1248c2ecf20Sopenharmony_ci u32 dsp; 1258c2ecf20Sopenharmony_ci u32 psp; 1268c2ecf20Sopenharmony_ci u32 asi; 1278c2ecf20Sopenharmony_ci u32 pasi; 1288c2ecf20Sopenharmony_ci u32 vrc; 1298c2ecf20Sopenharmony_ci u32 restricted_levels; 1308c2ecf20Sopenharmony_ci u32 rlp; 1318c2ecf20Sopenharmony_ci u32 rmp; 1328c2ecf20Sopenharmony_ci u32 lhp; 1338c2ecf20Sopenharmony_ci u32 lmp; 1348c2ecf20Sopenharmony_ci /* smc offsets */ 1358c2ecf20Sopenharmony_ci u16 state_table_start; 1368c2ecf20Sopenharmony_ci u16 soft_regs_start; 1378c2ecf20Sopenharmony_ci u16 sram_end; 1388c2ecf20Sopenharmony_ci /* scratch structs */ 1398c2ecf20Sopenharmony_ci RV770_SMC_STATETABLE smc_statetable; 1408c2ecf20Sopenharmony_ci}; 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_cistruct rv7xx_pl { 1438c2ecf20Sopenharmony_ci u32 sclk; 1448c2ecf20Sopenharmony_ci u32 mclk; 1458c2ecf20Sopenharmony_ci u16 vddc; 1468c2ecf20Sopenharmony_ci u16 vddci; /* eg+ only */ 1478c2ecf20Sopenharmony_ci u32 flags; 1488c2ecf20Sopenharmony_ci enum radeon_pcie_gen pcie_gen; /* si+ only */ 1498c2ecf20Sopenharmony_ci}; 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_cistruct rv7xx_ps { 1528c2ecf20Sopenharmony_ci struct rv7xx_pl high; 1538c2ecf20Sopenharmony_ci struct rv7xx_pl medium; 1548c2ecf20Sopenharmony_ci struct rv7xx_pl low; 1558c2ecf20Sopenharmony_ci bool dc_compatible; 1568c2ecf20Sopenharmony_ci}; 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_ci#define RV770_RLP_DFLT 10 1598c2ecf20Sopenharmony_ci#define RV770_RMP_DFLT 25 1608c2ecf20Sopenharmony_ci#define RV770_LHP_DFLT 25 1618c2ecf20Sopenharmony_ci#define RV770_LMP_DFLT 10 1628c2ecf20Sopenharmony_ci#define RV770_VRC_DFLT 0x003f 1638c2ecf20Sopenharmony_ci#define RV770_ASI_DFLT 1000 1648c2ecf20Sopenharmony_ci#define RV770_HASI_DFLT 200000 1658c2ecf20Sopenharmony_ci#define RV770_MGCGTTLOCAL0_DFLT 0x00100000 1668c2ecf20Sopenharmony_ci#define RV7XX_MGCGTTLOCAL0_DFLT 0 1678c2ecf20Sopenharmony_ci#define RV770_MGCGTTLOCAL1_DFLT 0xFFFF0000 1688c2ecf20Sopenharmony_ci#define RV770_MGCGCGTSSMCTRL_DFLT 0x55940000 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ci#define MVDD_LOW_INDEX 0 1718c2ecf20Sopenharmony_ci#define MVDD_HIGH_INDEX 1 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_ci#define MVDD_LOW_VALUE 0 1748c2ecf20Sopenharmony_ci#define MVDD_HIGH_VALUE 0xffff 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci#define RV770_DEFAULT_VCLK_FREQ 53300 /* 10 khz */ 1778c2ecf20Sopenharmony_ci#define RV770_DEFAULT_DCLK_FREQ 40000 /* 10 khz */ 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_ci/* rv730/rv710 */ 1808c2ecf20Sopenharmony_ciint rv730_populate_sclk_value(struct radeon_device *rdev, 1818c2ecf20Sopenharmony_ci u32 engine_clock, 1828c2ecf20Sopenharmony_ci RV770_SMC_SCLK_VALUE *sclk); 1838c2ecf20Sopenharmony_ciint rv730_populate_mclk_value(struct radeon_device *rdev, 1848c2ecf20Sopenharmony_ci u32 engine_clock, u32 memory_clock, 1858c2ecf20Sopenharmony_ci LPRV7XX_SMC_MCLK_VALUE mclk); 1868c2ecf20Sopenharmony_civoid rv730_read_clock_registers(struct radeon_device *rdev); 1878c2ecf20Sopenharmony_ciint rv730_populate_smc_acpi_state(struct radeon_device *rdev, 1888c2ecf20Sopenharmony_ci RV770_SMC_STATETABLE *table); 1898c2ecf20Sopenharmony_ciint rv730_populate_smc_initial_state(struct radeon_device *rdev, 1908c2ecf20Sopenharmony_ci struct radeon_ps *radeon_initial_state, 1918c2ecf20Sopenharmony_ci RV770_SMC_STATETABLE *table); 1928c2ecf20Sopenharmony_civoid rv730_program_memory_timing_parameters(struct radeon_device *rdev, 1938c2ecf20Sopenharmony_ci struct radeon_ps *radeon_state); 1948c2ecf20Sopenharmony_civoid rv730_power_gating_enable(struct radeon_device *rdev, 1958c2ecf20Sopenharmony_ci bool enable); 1968c2ecf20Sopenharmony_civoid rv730_start_dpm(struct radeon_device *rdev); 1978c2ecf20Sopenharmony_civoid rv730_stop_dpm(struct radeon_device *rdev); 1988c2ecf20Sopenharmony_civoid rv730_program_dcodt(struct radeon_device *rdev, bool use_dcodt); 1998c2ecf20Sopenharmony_civoid rv730_get_odt_values(struct radeon_device *rdev); 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_ci/* rv740 */ 2028c2ecf20Sopenharmony_ciint rv740_populate_sclk_value(struct radeon_device *rdev, u32 engine_clock, 2038c2ecf20Sopenharmony_ci RV770_SMC_SCLK_VALUE *sclk); 2048c2ecf20Sopenharmony_ciint rv740_populate_mclk_value(struct radeon_device *rdev, 2058c2ecf20Sopenharmony_ci u32 engine_clock, u32 memory_clock, 2068c2ecf20Sopenharmony_ci RV7XX_SMC_MCLK_VALUE *mclk); 2078c2ecf20Sopenharmony_civoid rv740_read_clock_registers(struct radeon_device *rdev); 2088c2ecf20Sopenharmony_ciint rv740_populate_smc_acpi_state(struct radeon_device *rdev, 2098c2ecf20Sopenharmony_ci RV770_SMC_STATETABLE *table); 2108c2ecf20Sopenharmony_civoid rv740_enable_mclk_spread_spectrum(struct radeon_device *rdev, 2118c2ecf20Sopenharmony_ci bool enable); 2128c2ecf20Sopenharmony_ciu8 rv740_get_mclk_frequency_ratio(u32 memory_clock); 2138c2ecf20Sopenharmony_ciu32 rv740_get_dll_speed(bool is_gddr5, u32 memory_clock); 2148c2ecf20Sopenharmony_ciu32 rv740_get_decoded_reference_divider(u32 encoded_ref); 2158c2ecf20Sopenharmony_ci 2168c2ecf20Sopenharmony_ci/* rv770 */ 2178c2ecf20Sopenharmony_ciu32 rv770_map_clkf_to_ibias(struct radeon_device *rdev, u32 clkf); 2188c2ecf20Sopenharmony_ciint rv770_populate_vddc_value(struct radeon_device *rdev, u16 vddc, 2198c2ecf20Sopenharmony_ci RV770_SMC_VOLTAGE_VALUE *voltage); 2208c2ecf20Sopenharmony_ciint rv770_populate_mvdd_value(struct radeon_device *rdev, u32 mclk, 2218c2ecf20Sopenharmony_ci RV770_SMC_VOLTAGE_VALUE *voltage); 2228c2ecf20Sopenharmony_ciu8 rv770_get_seq_value(struct radeon_device *rdev, 2238c2ecf20Sopenharmony_ci struct rv7xx_pl *pl); 2248c2ecf20Sopenharmony_ciint rv770_populate_initial_mvdd_value(struct radeon_device *rdev, 2258c2ecf20Sopenharmony_ci RV770_SMC_VOLTAGE_VALUE *voltage); 2268c2ecf20Sopenharmony_ciu32 rv770_calculate_memory_refresh_rate(struct radeon_device *rdev, 2278c2ecf20Sopenharmony_ci u32 engine_clock); 2288c2ecf20Sopenharmony_civoid rv770_program_response_times(struct radeon_device *rdev); 2298c2ecf20Sopenharmony_ciint rv770_populate_smc_sp(struct radeon_device *rdev, 2308c2ecf20Sopenharmony_ci struct radeon_ps *radeon_state, 2318c2ecf20Sopenharmony_ci RV770_SMC_SWSTATE *smc_state); 2328c2ecf20Sopenharmony_ciint rv770_populate_smc_t(struct radeon_device *rdev, 2338c2ecf20Sopenharmony_ci struct radeon_ps *radeon_state, 2348c2ecf20Sopenharmony_ci RV770_SMC_SWSTATE *smc_state); 2358c2ecf20Sopenharmony_civoid rv770_read_voltage_smio_registers(struct radeon_device *rdev); 2368c2ecf20Sopenharmony_civoid rv770_get_memory_type(struct radeon_device *rdev); 2378c2ecf20Sopenharmony_civoid r7xx_start_smc(struct radeon_device *rdev); 2388c2ecf20Sopenharmony_ciu8 rv770_get_memory_module_index(struct radeon_device *rdev); 2398c2ecf20Sopenharmony_civoid rv770_get_max_vddc(struct radeon_device *rdev); 2408c2ecf20Sopenharmony_civoid rv770_get_pcie_gen2_status(struct radeon_device *rdev); 2418c2ecf20Sopenharmony_civoid rv770_enable_acpi_pm(struct radeon_device *rdev); 2428c2ecf20Sopenharmony_civoid rv770_restore_cgcg(struct radeon_device *rdev); 2438c2ecf20Sopenharmony_cibool rv770_dpm_enabled(struct radeon_device *rdev); 2448c2ecf20Sopenharmony_civoid rv770_enable_voltage_control(struct radeon_device *rdev, 2458c2ecf20Sopenharmony_ci bool enable); 2468c2ecf20Sopenharmony_civoid rv770_enable_backbias(struct radeon_device *rdev, 2478c2ecf20Sopenharmony_ci bool enable); 2488c2ecf20Sopenharmony_civoid rv770_enable_thermal_protection(struct radeon_device *rdev, 2498c2ecf20Sopenharmony_ci bool enable); 2508c2ecf20Sopenharmony_civoid rv770_enable_auto_throttle_source(struct radeon_device *rdev, 2518c2ecf20Sopenharmony_ci enum radeon_dpm_auto_throttle_src source, 2528c2ecf20Sopenharmony_ci bool enable); 2538c2ecf20Sopenharmony_civoid rv770_setup_bsp(struct radeon_device *rdev); 2548c2ecf20Sopenharmony_civoid rv770_program_git(struct radeon_device *rdev); 2558c2ecf20Sopenharmony_civoid rv770_program_tp(struct radeon_device *rdev); 2568c2ecf20Sopenharmony_civoid rv770_program_tpp(struct radeon_device *rdev); 2578c2ecf20Sopenharmony_civoid rv770_program_sstp(struct radeon_device *rdev); 2588c2ecf20Sopenharmony_civoid rv770_program_engine_speed_parameters(struct radeon_device *rdev); 2598c2ecf20Sopenharmony_civoid rv770_program_vc(struct radeon_device *rdev); 2608c2ecf20Sopenharmony_civoid rv770_clear_vc(struct radeon_device *rdev); 2618c2ecf20Sopenharmony_ciint rv770_upload_firmware(struct radeon_device *rdev); 2628c2ecf20Sopenharmony_civoid rv770_stop_dpm(struct radeon_device *rdev); 2638c2ecf20Sopenharmony_civoid r7xx_stop_smc(struct radeon_device *rdev); 2648c2ecf20Sopenharmony_civoid rv770_reset_smio_status(struct radeon_device *rdev); 2658c2ecf20Sopenharmony_ciint rv770_restrict_performance_levels_before_switch(struct radeon_device *rdev); 2668c2ecf20Sopenharmony_ciint rv770_dpm_force_performance_level(struct radeon_device *rdev, 2678c2ecf20Sopenharmony_ci enum radeon_dpm_forced_level level); 2688c2ecf20Sopenharmony_ciint rv770_halt_smc(struct radeon_device *rdev); 2698c2ecf20Sopenharmony_ciint rv770_resume_smc(struct radeon_device *rdev); 2708c2ecf20Sopenharmony_ciint rv770_set_sw_state(struct radeon_device *rdev); 2718c2ecf20Sopenharmony_ciint rv770_set_boot_state(struct radeon_device *rdev); 2728c2ecf20Sopenharmony_ciint rv7xx_parse_power_table(struct radeon_device *rdev); 2738c2ecf20Sopenharmony_civoid rv770_set_uvd_clock_before_set_eng_clock(struct radeon_device *rdev, 2748c2ecf20Sopenharmony_ci struct radeon_ps *new_ps, 2758c2ecf20Sopenharmony_ci struct radeon_ps *old_ps); 2768c2ecf20Sopenharmony_civoid rv770_set_uvd_clock_after_set_eng_clock(struct radeon_device *rdev, 2778c2ecf20Sopenharmony_ci struct radeon_ps *new_ps, 2788c2ecf20Sopenharmony_ci struct radeon_ps *old_ps); 2798c2ecf20Sopenharmony_civoid rv770_get_engine_memory_ss(struct radeon_device *rdev); 2808c2ecf20Sopenharmony_ci 2818c2ecf20Sopenharmony_ci/* smc */ 2828c2ecf20Sopenharmony_ciint rv770_write_smc_soft_register(struct radeon_device *rdev, 2838c2ecf20Sopenharmony_ci u16 reg_offset, u32 value); 2848c2ecf20Sopenharmony_ci 2858c2ecf20Sopenharmony_ci#endif 286