1 1.2 riastrad /* $NetBSD: rv770_dpm.h,v 1.3 2021/12/18 23:45:43 riastradh Exp $ */ 2 1.2 riastrad 3 1.1 riastrad /* 4 1.1 riastrad * Copyright 2011 Advanced Micro Devices, Inc. 5 1.1 riastrad * 6 1.1 riastrad * Permission is hereby granted, free of charge, to any person obtaining a 7 1.1 riastrad * copy of this software and associated documentation files (the "Software"), 8 1.1 riastrad * to deal in the Software without restriction, including without limitation 9 1.1 riastrad * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 1.1 riastrad * and/or sell copies of the Software, and to permit persons to whom the 11 1.1 riastrad * Software is furnished to do so, subject to the following conditions: 12 1.1 riastrad * 13 1.1 riastrad * The above copyright notice and this permission notice shall be included in 14 1.1 riastrad * all copies or substantial portions of the Software. 15 1.1 riastrad * 16 1.1 riastrad * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 1.1 riastrad * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 1.1 riastrad * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 1.1 riastrad * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 1.1 riastrad * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 1.1 riastrad * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 1.1 riastrad * OTHER DEALINGS IN THE SOFTWARE. 23 1.1 riastrad * 24 1.1 riastrad */ 25 1.1 riastrad #ifndef __RV770_DPM_H__ 26 1.1 riastrad #define __RV770_DPM_H__ 27 1.1 riastrad 28 1.3 riastrad #include "radeon.h" 29 1.1 riastrad #include "rv770_smc.h" 30 1.1 riastrad 31 1.1 riastrad struct rv770_clock_registers { 32 1.1 riastrad u32 cg_spll_func_cntl; 33 1.1 riastrad u32 cg_spll_func_cntl_2; 34 1.1 riastrad u32 cg_spll_func_cntl_3; 35 1.1 riastrad u32 cg_spll_spread_spectrum; 36 1.1 riastrad u32 cg_spll_spread_spectrum_2; 37 1.1 riastrad u32 mpll_ad_func_cntl; 38 1.1 riastrad u32 mpll_ad_func_cntl_2; 39 1.1 riastrad u32 mpll_dq_func_cntl; 40 1.1 riastrad u32 mpll_dq_func_cntl_2; 41 1.1 riastrad u32 mclk_pwrmgt_cntl; 42 1.1 riastrad u32 dll_cntl; 43 1.1 riastrad u32 mpll_ss1; 44 1.1 riastrad u32 mpll_ss2; 45 1.1 riastrad }; 46 1.1 riastrad 47 1.1 riastrad struct rv730_clock_registers { 48 1.1 riastrad u32 cg_spll_func_cntl; 49 1.1 riastrad u32 cg_spll_func_cntl_2; 50 1.1 riastrad u32 cg_spll_func_cntl_3; 51 1.1 riastrad u32 cg_spll_spread_spectrum; 52 1.1 riastrad u32 cg_spll_spread_spectrum_2; 53 1.1 riastrad u32 mclk_pwrmgt_cntl; 54 1.1 riastrad u32 dll_cntl; 55 1.1 riastrad u32 mpll_func_cntl; 56 1.1 riastrad u32 mpll_func_cntl2; 57 1.1 riastrad u32 mpll_func_cntl3; 58 1.1 riastrad u32 mpll_ss; 59 1.1 riastrad u32 mpll_ss2; 60 1.1 riastrad }; 61 1.1 riastrad 62 1.1 riastrad union r7xx_clock_registers { 63 1.1 riastrad struct rv770_clock_registers rv770; 64 1.1 riastrad struct rv730_clock_registers rv730; 65 1.1 riastrad }; 66 1.1 riastrad 67 1.1 riastrad struct vddc_table_entry { 68 1.1 riastrad u16 vddc; 69 1.1 riastrad u8 vddc_index; 70 1.1 riastrad u8 high_smio; 71 1.1 riastrad u32 low_smio; 72 1.1 riastrad }; 73 1.1 riastrad 74 1.1 riastrad #define MAX_NO_OF_MVDD_VALUES 2 75 1.1 riastrad #define MAX_NO_VREG_STEPS 32 76 1.1 riastrad 77 1.1 riastrad struct rv7xx_power_info { 78 1.1 riastrad /* flags */ 79 1.1 riastrad bool mem_gddr5; 80 1.1 riastrad bool pcie_gen2; 81 1.1 riastrad bool dynamic_pcie_gen2; 82 1.1 riastrad bool acpi_pcie_gen2; 83 1.1 riastrad bool boot_in_gen2; 84 1.1 riastrad bool voltage_control; /* vddc */ 85 1.1 riastrad bool mvdd_control; 86 1.1 riastrad bool sclk_ss; 87 1.1 riastrad bool mclk_ss; 88 1.1 riastrad bool dynamic_ss; 89 1.1 riastrad bool gfx_clock_gating; 90 1.1 riastrad bool mg_clock_gating; 91 1.1 riastrad bool mgcgtssm; 92 1.1 riastrad bool power_gating; 93 1.1 riastrad bool thermal_protection; 94 1.1 riastrad bool display_gap; 95 1.1 riastrad bool dcodt; 96 1.1 riastrad bool ulps; 97 1.1 riastrad /* registers */ 98 1.1 riastrad union r7xx_clock_registers clk_regs; 99 1.1 riastrad u32 s0_vid_lower_smio_cntl; 100 1.1 riastrad /* voltage */ 101 1.1 riastrad u32 vddc_mask_low; 102 1.1 riastrad u32 mvdd_mask_low; 103 1.1 riastrad u32 mvdd_split_frequency; 104 1.1 riastrad u32 mvdd_low_smio[MAX_NO_OF_MVDD_VALUES]; 105 1.1 riastrad u16 max_vddc; 106 1.1 riastrad u16 max_vddc_in_table; 107 1.1 riastrad u16 min_vddc_in_table; 108 1.1 riastrad struct vddc_table_entry vddc_table[MAX_NO_VREG_STEPS]; 109 1.1 riastrad u8 valid_vddc_entries; 110 1.1 riastrad /* dc odt */ 111 1.1 riastrad u32 mclk_odt_threshold; 112 1.1 riastrad u8 odt_value_0[2]; 113 1.1 riastrad u8 odt_value_1[2]; 114 1.1 riastrad /* stored values */ 115 1.1 riastrad u32 boot_sclk; 116 1.1 riastrad u16 acpi_vddc; 117 1.1 riastrad u32 ref_div; 118 1.1 riastrad u32 active_auto_throttle_sources; 119 1.1 riastrad u32 mclk_stutter_mode_threshold; 120 1.1 riastrad u32 mclk_strobe_mode_threshold; 121 1.1 riastrad u32 mclk_edc_enable_threshold; 122 1.1 riastrad u32 bsp; 123 1.1 riastrad u32 bsu; 124 1.1 riastrad u32 pbsp; 125 1.1 riastrad u32 pbsu; 126 1.1 riastrad u32 dsp; 127 1.1 riastrad u32 psp; 128 1.1 riastrad u32 asi; 129 1.1 riastrad u32 pasi; 130 1.1 riastrad u32 vrc; 131 1.1 riastrad u32 restricted_levels; 132 1.1 riastrad u32 rlp; 133 1.1 riastrad u32 rmp; 134 1.1 riastrad u32 lhp; 135 1.1 riastrad u32 lmp; 136 1.1 riastrad /* smc offsets */ 137 1.1 riastrad u16 state_table_start; 138 1.1 riastrad u16 soft_regs_start; 139 1.1 riastrad u16 sram_end; 140 1.1 riastrad /* scratch structs */ 141 1.1 riastrad RV770_SMC_STATETABLE smc_statetable; 142 1.1 riastrad }; 143 1.1 riastrad 144 1.1 riastrad struct rv7xx_pl { 145 1.1 riastrad u32 sclk; 146 1.1 riastrad u32 mclk; 147 1.1 riastrad u16 vddc; 148 1.1 riastrad u16 vddci; /* eg+ only */ 149 1.1 riastrad u32 flags; 150 1.1 riastrad enum radeon_pcie_gen pcie_gen; /* si+ only */ 151 1.1 riastrad }; 152 1.1 riastrad 153 1.1 riastrad struct rv7xx_ps { 154 1.1 riastrad struct rv7xx_pl high; 155 1.1 riastrad struct rv7xx_pl medium; 156 1.1 riastrad struct rv7xx_pl low; 157 1.1 riastrad bool dc_compatible; 158 1.1 riastrad }; 159 1.1 riastrad 160 1.1 riastrad #define RV770_RLP_DFLT 10 161 1.1 riastrad #define RV770_RMP_DFLT 25 162 1.1 riastrad #define RV770_LHP_DFLT 25 163 1.1 riastrad #define RV770_LMP_DFLT 10 164 1.1 riastrad #define RV770_VRC_DFLT 0x003f 165 1.1 riastrad #define RV770_ASI_DFLT 1000 166 1.1 riastrad #define RV770_HASI_DFLT 200000 167 1.1 riastrad #define RV770_MGCGTTLOCAL0_DFLT 0x00100000 168 1.1 riastrad #define RV7XX_MGCGTTLOCAL0_DFLT 0 169 1.1 riastrad #define RV770_MGCGTTLOCAL1_DFLT 0xFFFF0000 170 1.1 riastrad #define RV770_MGCGCGTSSMCTRL_DFLT 0x55940000 171 1.1 riastrad 172 1.1 riastrad #define MVDD_LOW_INDEX 0 173 1.1 riastrad #define MVDD_HIGH_INDEX 1 174 1.1 riastrad 175 1.1 riastrad #define MVDD_LOW_VALUE 0 176 1.1 riastrad #define MVDD_HIGH_VALUE 0xffff 177 1.1 riastrad 178 1.1 riastrad #define RV770_DEFAULT_VCLK_FREQ 53300 /* 10 khz */ 179 1.1 riastrad #define RV770_DEFAULT_DCLK_FREQ 40000 /* 10 khz */ 180 1.1 riastrad 181 1.1 riastrad /* rv730/rv710 */ 182 1.1 riastrad int rv730_populate_sclk_value(struct radeon_device *rdev, 183 1.1 riastrad u32 engine_clock, 184 1.1 riastrad RV770_SMC_SCLK_VALUE *sclk); 185 1.1 riastrad int rv730_populate_mclk_value(struct radeon_device *rdev, 186 1.1 riastrad u32 engine_clock, u32 memory_clock, 187 1.1 riastrad LPRV7XX_SMC_MCLK_VALUE mclk); 188 1.1 riastrad void rv730_read_clock_registers(struct radeon_device *rdev); 189 1.1 riastrad int rv730_populate_smc_acpi_state(struct radeon_device *rdev, 190 1.1 riastrad RV770_SMC_STATETABLE *table); 191 1.1 riastrad int rv730_populate_smc_initial_state(struct radeon_device *rdev, 192 1.1 riastrad struct radeon_ps *radeon_initial_state, 193 1.1 riastrad RV770_SMC_STATETABLE *table); 194 1.1 riastrad void rv730_program_memory_timing_parameters(struct radeon_device *rdev, 195 1.1 riastrad struct radeon_ps *radeon_state); 196 1.1 riastrad void rv730_power_gating_enable(struct radeon_device *rdev, 197 1.1 riastrad bool enable); 198 1.1 riastrad void rv730_start_dpm(struct radeon_device *rdev); 199 1.1 riastrad void rv730_stop_dpm(struct radeon_device *rdev); 200 1.1 riastrad void rv730_program_dcodt(struct radeon_device *rdev, bool use_dcodt); 201 1.1 riastrad void rv730_get_odt_values(struct radeon_device *rdev); 202 1.1 riastrad 203 1.1 riastrad /* rv740 */ 204 1.1 riastrad int rv740_populate_sclk_value(struct radeon_device *rdev, u32 engine_clock, 205 1.1 riastrad RV770_SMC_SCLK_VALUE *sclk); 206 1.1 riastrad int rv740_populate_mclk_value(struct radeon_device *rdev, 207 1.1 riastrad u32 engine_clock, u32 memory_clock, 208 1.1 riastrad RV7XX_SMC_MCLK_VALUE *mclk); 209 1.1 riastrad void rv740_read_clock_registers(struct radeon_device *rdev); 210 1.1 riastrad int rv740_populate_smc_acpi_state(struct radeon_device *rdev, 211 1.1 riastrad RV770_SMC_STATETABLE *table); 212 1.1 riastrad void rv740_enable_mclk_spread_spectrum(struct radeon_device *rdev, 213 1.1 riastrad bool enable); 214 1.1 riastrad u8 rv740_get_mclk_frequency_ratio(u32 memory_clock); 215 1.1 riastrad u32 rv740_get_dll_speed(bool is_gddr5, u32 memory_clock); 216 1.1 riastrad u32 rv740_get_decoded_reference_divider(u32 encoded_ref); 217 1.1 riastrad 218 1.1 riastrad /* rv770 */ 219 1.1 riastrad u32 rv770_map_clkf_to_ibias(struct radeon_device *rdev, u32 clkf); 220 1.1 riastrad int rv770_populate_vddc_value(struct radeon_device *rdev, u16 vddc, 221 1.1 riastrad RV770_SMC_VOLTAGE_VALUE *voltage); 222 1.1 riastrad int rv770_populate_mvdd_value(struct radeon_device *rdev, u32 mclk, 223 1.1 riastrad RV770_SMC_VOLTAGE_VALUE *voltage); 224 1.1 riastrad u8 rv770_get_seq_value(struct radeon_device *rdev, 225 1.1 riastrad struct rv7xx_pl *pl); 226 1.1 riastrad int rv770_populate_initial_mvdd_value(struct radeon_device *rdev, 227 1.1 riastrad RV770_SMC_VOLTAGE_VALUE *voltage); 228 1.1 riastrad u32 rv770_calculate_memory_refresh_rate(struct radeon_device *rdev, 229 1.1 riastrad u32 engine_clock); 230 1.1 riastrad void rv770_program_response_times(struct radeon_device *rdev); 231 1.1 riastrad int rv770_populate_smc_sp(struct radeon_device *rdev, 232 1.1 riastrad struct radeon_ps *radeon_state, 233 1.1 riastrad RV770_SMC_SWSTATE *smc_state); 234 1.1 riastrad int rv770_populate_smc_t(struct radeon_device *rdev, 235 1.1 riastrad struct radeon_ps *radeon_state, 236 1.1 riastrad RV770_SMC_SWSTATE *smc_state); 237 1.1 riastrad void rv770_read_voltage_smio_registers(struct radeon_device *rdev); 238 1.1 riastrad void rv770_get_memory_type(struct radeon_device *rdev); 239 1.1 riastrad void r7xx_start_smc(struct radeon_device *rdev); 240 1.1 riastrad u8 rv770_get_memory_module_index(struct radeon_device *rdev); 241 1.1 riastrad void rv770_get_max_vddc(struct radeon_device *rdev); 242 1.1 riastrad void rv770_get_pcie_gen2_status(struct radeon_device *rdev); 243 1.1 riastrad void rv770_enable_acpi_pm(struct radeon_device *rdev); 244 1.1 riastrad void rv770_restore_cgcg(struct radeon_device *rdev); 245 1.1 riastrad bool rv770_dpm_enabled(struct radeon_device *rdev); 246 1.1 riastrad void rv770_enable_voltage_control(struct radeon_device *rdev, 247 1.1 riastrad bool enable); 248 1.1 riastrad void rv770_enable_backbias(struct radeon_device *rdev, 249 1.1 riastrad bool enable); 250 1.1 riastrad void rv770_enable_thermal_protection(struct radeon_device *rdev, 251 1.1 riastrad bool enable); 252 1.1 riastrad void rv770_enable_auto_throttle_source(struct radeon_device *rdev, 253 1.1 riastrad enum radeon_dpm_auto_throttle_src source, 254 1.1 riastrad bool enable); 255 1.1 riastrad void rv770_setup_bsp(struct radeon_device *rdev); 256 1.1 riastrad void rv770_program_git(struct radeon_device *rdev); 257 1.1 riastrad void rv770_program_tp(struct radeon_device *rdev); 258 1.1 riastrad void rv770_program_tpp(struct radeon_device *rdev); 259 1.1 riastrad void rv770_program_sstp(struct radeon_device *rdev); 260 1.1 riastrad void rv770_program_engine_speed_parameters(struct radeon_device *rdev); 261 1.1 riastrad void rv770_program_vc(struct radeon_device *rdev); 262 1.1 riastrad void rv770_clear_vc(struct radeon_device *rdev); 263 1.1 riastrad int rv770_upload_firmware(struct radeon_device *rdev); 264 1.1 riastrad void rv770_stop_dpm(struct radeon_device *rdev); 265 1.1 riastrad void r7xx_stop_smc(struct radeon_device *rdev); 266 1.1 riastrad void rv770_reset_smio_status(struct radeon_device *rdev); 267 1.1 riastrad int rv770_restrict_performance_levels_before_switch(struct radeon_device *rdev); 268 1.1 riastrad int rv770_dpm_force_performance_level(struct radeon_device *rdev, 269 1.1 riastrad enum radeon_dpm_forced_level level); 270 1.1 riastrad int rv770_halt_smc(struct radeon_device *rdev); 271 1.1 riastrad int rv770_resume_smc(struct radeon_device *rdev); 272 1.1 riastrad int rv770_set_sw_state(struct radeon_device *rdev); 273 1.1 riastrad int rv770_set_boot_state(struct radeon_device *rdev); 274 1.1 riastrad int rv7xx_parse_power_table(struct radeon_device *rdev); 275 1.1 riastrad void rv770_set_uvd_clock_before_set_eng_clock(struct radeon_device *rdev, 276 1.1 riastrad struct radeon_ps *new_ps, 277 1.1 riastrad struct radeon_ps *old_ps); 278 1.1 riastrad void rv770_set_uvd_clock_after_set_eng_clock(struct radeon_device *rdev, 279 1.1 riastrad struct radeon_ps *new_ps, 280 1.1 riastrad struct radeon_ps *old_ps); 281 1.1 riastrad void rv770_get_engine_memory_ss(struct radeon_device *rdev); 282 1.1 riastrad 283 1.1 riastrad /* smc */ 284 1.1 riastrad int rv770_write_smc_soft_register(struct radeon_device *rdev, 285 1.1 riastrad u16 reg_offset, u32 value); 286 1.1 riastrad 287 1.1 riastrad #endif 288