rv770_dpm.h 9.4 KB

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