rs780_dpm.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076
  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. * Authors: Alex Deucher
  23. */
  24. #include "drmP.h"
  25. #include "radeon.h"
  26. #include "radeon_asic.h"
  27. #include "rs780d.h"
  28. #include "r600_dpm.h"
  29. #include "rs780_dpm.h"
  30. #include "atom.h"
  31. #include <linux/seq_file.h>
  32. static struct igp_ps *rs780_get_ps(struct radeon_ps *rps)
  33. {
  34. struct igp_ps *ps = rps->ps_priv;
  35. return ps;
  36. }
  37. static struct igp_power_info *rs780_get_pi(struct radeon_device *rdev)
  38. {
  39. struct igp_power_info *pi = rdev->pm.dpm.priv;
  40. return pi;
  41. }
  42. static void rs780_get_pm_mode_parameters(struct radeon_device *rdev)
  43. {
  44. struct igp_power_info *pi = rs780_get_pi(rdev);
  45. struct radeon_mode_info *minfo = &rdev->mode_info;
  46. struct drm_crtc *crtc;
  47. struct radeon_crtc *radeon_crtc;
  48. int i;
  49. /* defaults */
  50. pi->crtc_id = 0;
  51. pi->refresh_rate = 60;
  52. for (i = 0; i < rdev->num_crtc; i++) {
  53. crtc = (struct drm_crtc *)minfo->crtcs[i];
  54. if (crtc && crtc->enabled) {
  55. radeon_crtc = to_radeon_crtc(crtc);
  56. pi->crtc_id = radeon_crtc->crtc_id;
  57. if (crtc->mode.htotal && crtc->mode.vtotal)
  58. pi->refresh_rate = drm_mode_vrefresh(&crtc->mode);
  59. break;
  60. }
  61. }
  62. }
  63. static void rs780_voltage_scaling_enable(struct radeon_device *rdev, bool enable);
  64. static int rs780_initialize_dpm_power_state(struct radeon_device *rdev,
  65. struct radeon_ps *boot_ps)
  66. {
  67. struct atom_clock_dividers dividers;
  68. struct igp_ps *default_state = rs780_get_ps(boot_ps);
  69. int i, ret;
  70. ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
  71. default_state->sclk_low, false, &dividers);
  72. if (ret)
  73. return ret;
  74. r600_engine_clock_entry_set_reference_divider(rdev, 0, dividers.ref_div);
  75. r600_engine_clock_entry_set_feedback_divider(rdev, 0, dividers.fb_div);
  76. r600_engine_clock_entry_set_post_divider(rdev, 0, dividers.post_div);
  77. if (dividers.enable_post_div)
  78. r600_engine_clock_entry_enable_post_divider(rdev, 0, true);
  79. else
  80. r600_engine_clock_entry_enable_post_divider(rdev, 0, false);
  81. r600_engine_clock_entry_set_step_time(rdev, 0, R600_SST_DFLT);
  82. r600_engine_clock_entry_enable_pulse_skipping(rdev, 0, false);
  83. r600_engine_clock_entry_enable(rdev, 0, true);
  84. for (i = 1; i < R600_PM_NUMBER_OF_SCLKS; i++)
  85. r600_engine_clock_entry_enable(rdev, i, false);
  86. r600_enable_mclk_control(rdev, false);
  87. r600_voltage_control_enable_pins(rdev, 0);
  88. return 0;
  89. }
  90. static int rs780_initialize_dpm_parameters(struct radeon_device *rdev,
  91. struct radeon_ps *boot_ps)
  92. {
  93. int ret = 0;
  94. int i;
  95. r600_set_bsp(rdev, R600_BSU_DFLT, R600_BSP_DFLT);
  96. r600_set_at(rdev, 0, 0, 0, 0);
  97. r600_set_git(rdev, R600_GICST_DFLT);
  98. for (i = 0; i < R600_PM_NUMBER_OF_TC; i++)
  99. r600_set_tc(rdev, i, 0, 0);
  100. r600_select_td(rdev, R600_TD_DFLT);
  101. r600_set_vrc(rdev, 0);
  102. r600_set_tpu(rdev, R600_TPU_DFLT);
  103. r600_set_tpc(rdev, R600_TPC_DFLT);
  104. r600_set_sstu(rdev, R600_SSTU_DFLT);
  105. r600_set_sst(rdev, R600_SST_DFLT);
  106. r600_set_fctu(rdev, R600_FCTU_DFLT);
  107. r600_set_fct(rdev, R600_FCT_DFLT);
  108. r600_set_vddc3d_oorsu(rdev, R600_VDDC3DOORSU_DFLT);
  109. r600_set_vddc3d_oorphc(rdev, R600_VDDC3DOORPHC_DFLT);
  110. r600_set_vddc3d_oorsdc(rdev, R600_VDDC3DOORSDC_DFLT);
  111. r600_set_ctxcgtt3d_rphc(rdev, R600_CTXCGTT3DRPHC_DFLT);
  112. r600_set_ctxcgtt3d_rsdc(rdev, R600_CTXCGTT3DRSDC_DFLT);
  113. r600_vid_rt_set_vru(rdev, R600_VRU_DFLT);
  114. r600_vid_rt_set_vrt(rdev, R600_VOLTAGERESPONSETIME_DFLT);
  115. r600_vid_rt_set_ssu(rdev, R600_SPLLSTEPUNIT_DFLT);
  116. ret = rs780_initialize_dpm_power_state(rdev, boot_ps);
  117. r600_power_level_set_voltage_index(rdev, R600_POWER_LEVEL_LOW, 0);
  118. r600_power_level_set_voltage_index(rdev, R600_POWER_LEVEL_MEDIUM, 0);
  119. r600_power_level_set_voltage_index(rdev, R600_POWER_LEVEL_HIGH, 0);
  120. r600_power_level_set_mem_clock_index(rdev, R600_POWER_LEVEL_LOW, 0);
  121. r600_power_level_set_mem_clock_index(rdev, R600_POWER_LEVEL_MEDIUM, 0);
  122. r600_power_level_set_mem_clock_index(rdev, R600_POWER_LEVEL_HIGH, 0);
  123. r600_power_level_set_eng_clock_index(rdev, R600_POWER_LEVEL_LOW, 0);
  124. r600_power_level_set_eng_clock_index(rdev, R600_POWER_LEVEL_MEDIUM, 0);
  125. r600_power_level_set_eng_clock_index(rdev, R600_POWER_LEVEL_HIGH, 0);
  126. r600_power_level_set_watermark_id(rdev, R600_POWER_LEVEL_LOW, R600_DISPLAY_WATERMARK_HIGH);
  127. r600_power_level_set_watermark_id(rdev, R600_POWER_LEVEL_MEDIUM, R600_DISPLAY_WATERMARK_HIGH);
  128. r600_power_level_set_watermark_id(rdev, R600_POWER_LEVEL_HIGH, R600_DISPLAY_WATERMARK_HIGH);
  129. r600_power_level_enable(rdev, R600_POWER_LEVEL_CTXSW, false);
  130. r600_power_level_enable(rdev, R600_POWER_LEVEL_HIGH, false);
  131. r600_power_level_enable(rdev, R600_POWER_LEVEL_MEDIUM, false);
  132. r600_power_level_enable(rdev, R600_POWER_LEVEL_LOW, true);
  133. r600_power_level_set_enter_index(rdev, R600_POWER_LEVEL_LOW);
  134. r600_set_vrc(rdev, RS780_CGFTV_DFLT);
  135. return ret;
  136. }
  137. static void rs780_start_dpm(struct radeon_device *rdev)
  138. {
  139. r600_enable_sclk_control(rdev, false);
  140. r600_enable_mclk_control(rdev, false);
  141. r600_dynamicpm_enable(rdev, true);
  142. radeon_wait_for_vblank(rdev, 0);
  143. radeon_wait_for_vblank(rdev, 1);
  144. r600_enable_spll_bypass(rdev, true);
  145. r600_wait_for_spll_change(rdev);
  146. r600_enable_spll_bypass(rdev, false);
  147. r600_wait_for_spll_change(rdev);
  148. r600_enable_spll_bypass(rdev, true);
  149. r600_wait_for_spll_change(rdev);
  150. r600_enable_spll_bypass(rdev, false);
  151. r600_wait_for_spll_change(rdev);
  152. r600_enable_sclk_control(rdev, true);
  153. }
  154. static void rs780_preset_ranges_slow_clk_fbdiv_en(struct radeon_device *rdev)
  155. {
  156. WREG32_P(FVTHROT_SLOW_CLK_FEEDBACK_DIV_REG1, RANGE_SLOW_CLK_FEEDBACK_DIV_EN,
  157. ~RANGE_SLOW_CLK_FEEDBACK_DIV_EN);
  158. WREG32_P(FVTHROT_SLOW_CLK_FEEDBACK_DIV_REG1,
  159. RANGE0_SLOW_CLK_FEEDBACK_DIV(RS780_SLOWCLKFEEDBACKDIV_DFLT),
  160. ~RANGE0_SLOW_CLK_FEEDBACK_DIV_MASK);
  161. }
  162. static void rs780_preset_starting_fbdiv(struct radeon_device *rdev)
  163. {
  164. u32 fbdiv = (RREG32(CG_SPLL_FUNC_CNTL) & SPLL_FB_DIV_MASK) >> SPLL_FB_DIV_SHIFT;
  165. WREG32_P(FVTHROT_FBDIV_REG1, STARTING_FEEDBACK_DIV(fbdiv),
  166. ~STARTING_FEEDBACK_DIV_MASK);
  167. WREG32_P(FVTHROT_FBDIV_REG2, FORCED_FEEDBACK_DIV(fbdiv),
  168. ~FORCED_FEEDBACK_DIV_MASK);
  169. WREG32_P(FVTHROT_FBDIV_REG1, FORCE_FEEDBACK_DIV, ~FORCE_FEEDBACK_DIV);
  170. }
  171. static void rs780_voltage_scaling_init(struct radeon_device *rdev)
  172. {
  173. struct igp_power_info *pi = rs780_get_pi(rdev);
  174. struct drm_device *dev = rdev->ddev;
  175. u32 fv_throt_pwm_fb_div_range[3];
  176. u32 fv_throt_pwm_range[4];
  177. if (dev->pdev->device == 0x9614) {
  178. fv_throt_pwm_fb_div_range[0] = RS780D_FVTHROTPWMFBDIVRANGEREG0_DFLT;
  179. fv_throt_pwm_fb_div_range[1] = RS780D_FVTHROTPWMFBDIVRANGEREG1_DFLT;
  180. fv_throt_pwm_fb_div_range[2] = RS780D_FVTHROTPWMFBDIVRANGEREG2_DFLT;
  181. } else if ((dev->pdev->device == 0x9714) ||
  182. (dev->pdev->device == 0x9715)) {
  183. fv_throt_pwm_fb_div_range[0] = RS880D_FVTHROTPWMFBDIVRANGEREG0_DFLT;
  184. fv_throt_pwm_fb_div_range[1] = RS880D_FVTHROTPWMFBDIVRANGEREG1_DFLT;
  185. fv_throt_pwm_fb_div_range[2] = RS880D_FVTHROTPWMFBDIVRANGEREG2_DFLT;
  186. } else {
  187. fv_throt_pwm_fb_div_range[0] = RS780_FVTHROTPWMFBDIVRANGEREG0_DFLT;
  188. fv_throt_pwm_fb_div_range[1] = RS780_FVTHROTPWMFBDIVRANGEREG1_DFLT;
  189. fv_throt_pwm_fb_div_range[2] = RS780_FVTHROTPWMFBDIVRANGEREG2_DFLT;
  190. }
  191. if (pi->pwm_voltage_control) {
  192. fv_throt_pwm_range[0] = pi->min_voltage;
  193. fv_throt_pwm_range[1] = pi->min_voltage;
  194. fv_throt_pwm_range[2] = pi->max_voltage;
  195. fv_throt_pwm_range[3] = pi->max_voltage;
  196. } else {
  197. fv_throt_pwm_range[0] = pi->invert_pwm_required ?
  198. RS780_FVTHROTPWMRANGE3_GPIO_DFLT : RS780_FVTHROTPWMRANGE0_GPIO_DFLT;
  199. fv_throt_pwm_range[1] = pi->invert_pwm_required ?
  200. RS780_FVTHROTPWMRANGE2_GPIO_DFLT : RS780_FVTHROTPWMRANGE1_GPIO_DFLT;
  201. fv_throt_pwm_range[2] = pi->invert_pwm_required ?
  202. RS780_FVTHROTPWMRANGE1_GPIO_DFLT : RS780_FVTHROTPWMRANGE2_GPIO_DFLT;
  203. fv_throt_pwm_range[3] = pi->invert_pwm_required ?
  204. RS780_FVTHROTPWMRANGE0_GPIO_DFLT : RS780_FVTHROTPWMRANGE3_GPIO_DFLT;
  205. }
  206. WREG32_P(FVTHROT_PWM_CTRL_REG0,
  207. STARTING_PWM_HIGHTIME(pi->max_voltage),
  208. ~STARTING_PWM_HIGHTIME_MASK);
  209. WREG32_P(FVTHROT_PWM_CTRL_REG0,
  210. NUMBER_OF_CYCLES_IN_PERIOD(pi->num_of_cycles_in_period),
  211. ~NUMBER_OF_CYCLES_IN_PERIOD_MASK);
  212. WREG32_P(FVTHROT_PWM_CTRL_REG0, FORCE_STARTING_PWM_HIGHTIME,
  213. ~FORCE_STARTING_PWM_HIGHTIME);
  214. if (pi->invert_pwm_required)
  215. WREG32_P(FVTHROT_PWM_CTRL_REG0, INVERT_PWM_WAVEFORM, ~INVERT_PWM_WAVEFORM);
  216. else
  217. WREG32_P(FVTHROT_PWM_CTRL_REG0, 0, ~INVERT_PWM_WAVEFORM);
  218. rs780_voltage_scaling_enable(rdev, true);
  219. WREG32(FVTHROT_PWM_CTRL_REG1,
  220. (MIN_PWM_HIGHTIME(pi->min_voltage) |
  221. MAX_PWM_HIGHTIME(pi->max_voltage)));
  222. WREG32(FVTHROT_PWM_US_REG0, RS780_FVTHROTPWMUSREG0_DFLT);
  223. WREG32(FVTHROT_PWM_US_REG1, RS780_FVTHROTPWMUSREG1_DFLT);
  224. WREG32(FVTHROT_PWM_DS_REG0, RS780_FVTHROTPWMDSREG0_DFLT);
  225. WREG32(FVTHROT_PWM_DS_REG1, RS780_FVTHROTPWMDSREG1_DFLT);
  226. WREG32_P(FVTHROT_PWM_FEEDBACK_DIV_REG1,
  227. RANGE0_PWM_FEEDBACK_DIV(fv_throt_pwm_fb_div_range[0]),
  228. ~RANGE0_PWM_FEEDBACK_DIV_MASK);
  229. WREG32(FVTHROT_PWM_FEEDBACK_DIV_REG2,
  230. (RANGE1_PWM_FEEDBACK_DIV(fv_throt_pwm_fb_div_range[1]) |
  231. RANGE2_PWM_FEEDBACK_DIV(fv_throt_pwm_fb_div_range[2])));
  232. WREG32(FVTHROT_PWM_FEEDBACK_DIV_REG3,
  233. (RANGE0_PWM(fv_throt_pwm_range[1]) |
  234. RANGE1_PWM(fv_throt_pwm_range[2])));
  235. WREG32(FVTHROT_PWM_FEEDBACK_DIV_REG4,
  236. (RANGE2_PWM(fv_throt_pwm_range[1]) |
  237. RANGE3_PWM(fv_throt_pwm_range[2])));
  238. }
  239. static void rs780_clk_scaling_enable(struct radeon_device *rdev, bool enable)
  240. {
  241. if (enable)
  242. WREG32_P(FVTHROT_CNTRL_REG, ENABLE_FV_THROT | ENABLE_FV_UPDATE,
  243. ~(ENABLE_FV_THROT | ENABLE_FV_UPDATE));
  244. else
  245. WREG32_P(FVTHROT_CNTRL_REG, 0,
  246. ~(ENABLE_FV_THROT | ENABLE_FV_UPDATE));
  247. }
  248. static void rs780_voltage_scaling_enable(struct radeon_device *rdev, bool enable)
  249. {
  250. if (enable)
  251. WREG32_P(FVTHROT_CNTRL_REG, ENABLE_FV_THROT_IO, ~ENABLE_FV_THROT_IO);
  252. else
  253. WREG32_P(FVTHROT_CNTRL_REG, 0, ~ENABLE_FV_THROT_IO);
  254. }
  255. static void rs780_set_engine_clock_wfc(struct radeon_device *rdev)
  256. {
  257. WREG32(FVTHROT_UTC0, RS780_FVTHROTUTC0_DFLT);
  258. WREG32(FVTHROT_UTC1, RS780_FVTHROTUTC1_DFLT);
  259. WREG32(FVTHROT_UTC2, RS780_FVTHROTUTC2_DFLT);
  260. WREG32(FVTHROT_UTC3, RS780_FVTHROTUTC3_DFLT);
  261. WREG32(FVTHROT_UTC4, RS780_FVTHROTUTC4_DFLT);
  262. WREG32(FVTHROT_DTC0, RS780_FVTHROTDTC0_DFLT);
  263. WREG32(FVTHROT_DTC1, RS780_FVTHROTDTC1_DFLT);
  264. WREG32(FVTHROT_DTC2, RS780_FVTHROTDTC2_DFLT);
  265. WREG32(FVTHROT_DTC3, RS780_FVTHROTDTC3_DFLT);
  266. WREG32(FVTHROT_DTC4, RS780_FVTHROTDTC4_DFLT);
  267. }
  268. static void rs780_set_engine_clock_sc(struct radeon_device *rdev)
  269. {
  270. WREG32_P(FVTHROT_FBDIV_REG2,
  271. FB_DIV_TIMER_VAL(RS780_FBDIVTIMERVAL_DFLT),
  272. ~FB_DIV_TIMER_VAL_MASK);
  273. WREG32_P(FVTHROT_CNTRL_REG,
  274. REFRESH_RATE_DIVISOR(0) | MINIMUM_CIP(0xf),
  275. ~(REFRESH_RATE_DIVISOR_MASK | MINIMUM_CIP_MASK));
  276. }
  277. static void rs780_set_engine_clock_tdc(struct radeon_device *rdev)
  278. {
  279. WREG32_P(FVTHROT_CNTRL_REG, 0, ~(FORCE_TREND_SEL | TREND_SEL_MODE));
  280. }
  281. static void rs780_set_engine_clock_ssc(struct radeon_device *rdev)
  282. {
  283. WREG32(FVTHROT_FB_US_REG0, RS780_FVTHROTFBUSREG0_DFLT);
  284. WREG32(FVTHROT_FB_US_REG1, RS780_FVTHROTFBUSREG1_DFLT);
  285. WREG32(FVTHROT_FB_DS_REG0, RS780_FVTHROTFBDSREG0_DFLT);
  286. WREG32(FVTHROT_FB_DS_REG1, RS780_FVTHROTFBDSREG1_DFLT);
  287. WREG32_P(FVTHROT_FBDIV_REG1, MAX_FEEDBACK_STEP(1), ~MAX_FEEDBACK_STEP_MASK);
  288. }
  289. static void rs780_program_at(struct radeon_device *rdev)
  290. {
  291. struct igp_power_info *pi = rs780_get_pi(rdev);
  292. WREG32(FVTHROT_TARGET_REG, 30000000 / pi->refresh_rate);
  293. WREG32(FVTHROT_CB1, 1000000 * 5 / pi->refresh_rate);
  294. WREG32(FVTHROT_CB2, 1000000 * 10 / pi->refresh_rate);
  295. WREG32(FVTHROT_CB3, 1000000 * 30 / pi->refresh_rate);
  296. WREG32(FVTHROT_CB4, 1000000 * 50 / pi->refresh_rate);
  297. }
  298. static void rs780_disable_vbios_powersaving(struct radeon_device *rdev)
  299. {
  300. WREG32_P(CG_INTGFX_MISC, 0, ~0xFFF00000);
  301. }
  302. static void rs780_force_voltage(struct radeon_device *rdev, u16 voltage)
  303. {
  304. struct igp_ps *current_state = rs780_get_ps(rdev->pm.dpm.current_ps);
  305. if ((current_state->max_voltage == RS780_VDDC_LEVEL_HIGH) &&
  306. (current_state->min_voltage == RS780_VDDC_LEVEL_HIGH))
  307. return;
  308. WREG32_P(GFX_MACRO_BYPASS_CNTL, SPLL_BYPASS_CNTL, ~SPLL_BYPASS_CNTL);
  309. udelay(1);
  310. WREG32_P(FVTHROT_PWM_CTRL_REG0,
  311. STARTING_PWM_HIGHTIME(voltage),
  312. ~STARTING_PWM_HIGHTIME_MASK);
  313. WREG32_P(FVTHROT_PWM_CTRL_REG0,
  314. FORCE_STARTING_PWM_HIGHTIME, ~FORCE_STARTING_PWM_HIGHTIME);
  315. WREG32_P(FVTHROT_PWM_FEEDBACK_DIV_REG1, 0,
  316. ~RANGE_PWM_FEEDBACK_DIV_EN);
  317. udelay(1);
  318. WREG32_P(GFX_MACRO_BYPASS_CNTL, 0, ~SPLL_BYPASS_CNTL);
  319. }
  320. static void rs780_force_fbdiv(struct radeon_device *rdev, u32 fb_div)
  321. {
  322. struct igp_ps *current_state = rs780_get_ps(rdev->pm.dpm.current_ps);
  323. if (current_state->sclk_low == current_state->sclk_high)
  324. return;
  325. WREG32_P(GFX_MACRO_BYPASS_CNTL, SPLL_BYPASS_CNTL, ~SPLL_BYPASS_CNTL);
  326. WREG32_P(FVTHROT_FBDIV_REG2, FORCED_FEEDBACK_DIV(fb_div),
  327. ~FORCED_FEEDBACK_DIV_MASK);
  328. WREG32_P(FVTHROT_FBDIV_REG1, STARTING_FEEDBACK_DIV(fb_div),
  329. ~STARTING_FEEDBACK_DIV_MASK);
  330. WREG32_P(FVTHROT_FBDIV_REG1, FORCE_FEEDBACK_DIV, ~FORCE_FEEDBACK_DIV);
  331. udelay(100);
  332. WREG32_P(GFX_MACRO_BYPASS_CNTL, 0, ~SPLL_BYPASS_CNTL);
  333. }
  334. static int rs780_set_engine_clock_scaling(struct radeon_device *rdev,
  335. struct radeon_ps *new_ps,
  336. struct radeon_ps *old_ps)
  337. {
  338. struct atom_clock_dividers min_dividers, max_dividers, current_max_dividers;
  339. struct igp_ps *new_state = rs780_get_ps(new_ps);
  340. struct igp_ps *old_state = rs780_get_ps(old_ps);
  341. int ret;
  342. if ((new_state->sclk_high == old_state->sclk_high) &&
  343. (new_state->sclk_low == old_state->sclk_low))
  344. return 0;
  345. ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
  346. new_state->sclk_low, false, &min_dividers);
  347. if (ret)
  348. return ret;
  349. ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
  350. new_state->sclk_high, false, &max_dividers);
  351. if (ret)
  352. return ret;
  353. ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
  354. old_state->sclk_high, false, &current_max_dividers);
  355. if (ret)
  356. return ret;
  357. if ((min_dividers.ref_div != max_dividers.ref_div) ||
  358. (min_dividers.post_div != max_dividers.post_div) ||
  359. (max_dividers.ref_div != current_max_dividers.ref_div) ||
  360. (max_dividers.post_div != current_max_dividers.post_div))
  361. return -EINVAL;
  362. rs780_force_fbdiv(rdev, max_dividers.fb_div);
  363. if (max_dividers.fb_div > min_dividers.fb_div) {
  364. WREG32_P(FVTHROT_FBDIV_REG0,
  365. MIN_FEEDBACK_DIV(min_dividers.fb_div) |
  366. MAX_FEEDBACK_DIV(max_dividers.fb_div),
  367. ~(MIN_FEEDBACK_DIV_MASK | MAX_FEEDBACK_DIV_MASK));
  368. WREG32_P(FVTHROT_FBDIV_REG1, 0, ~FORCE_FEEDBACK_DIV);
  369. }
  370. return 0;
  371. }
  372. static void rs780_set_engine_clock_spc(struct radeon_device *rdev,
  373. struct radeon_ps *new_ps,
  374. struct radeon_ps *old_ps)
  375. {
  376. struct igp_ps *new_state = rs780_get_ps(new_ps);
  377. struct igp_ps *old_state = rs780_get_ps(old_ps);
  378. struct igp_power_info *pi = rs780_get_pi(rdev);
  379. if ((new_state->sclk_high == old_state->sclk_high) &&
  380. (new_state->sclk_low == old_state->sclk_low))
  381. return;
  382. if (pi->crtc_id == 0)
  383. WREG32_P(CG_INTGFX_MISC, 0, ~FVTHROT_VBLANK_SEL);
  384. else
  385. WREG32_P(CG_INTGFX_MISC, FVTHROT_VBLANK_SEL, ~FVTHROT_VBLANK_SEL);
  386. }
  387. static void rs780_activate_engine_clk_scaling(struct radeon_device *rdev,
  388. struct radeon_ps *new_ps,
  389. struct radeon_ps *old_ps)
  390. {
  391. struct igp_ps *new_state = rs780_get_ps(new_ps);
  392. struct igp_ps *old_state = rs780_get_ps(old_ps);
  393. if ((new_state->sclk_high == old_state->sclk_high) &&
  394. (new_state->sclk_low == old_state->sclk_low))
  395. return;
  396. if (new_state->sclk_high == new_state->sclk_low)
  397. return;
  398. rs780_clk_scaling_enable(rdev, true);
  399. }
  400. static u32 rs780_get_voltage_for_vddc_level(struct radeon_device *rdev,
  401. enum rs780_vddc_level vddc)
  402. {
  403. struct igp_power_info *pi = rs780_get_pi(rdev);
  404. if (vddc == RS780_VDDC_LEVEL_HIGH)
  405. return pi->max_voltage;
  406. else if (vddc == RS780_VDDC_LEVEL_LOW)
  407. return pi->min_voltage;
  408. else
  409. return pi->max_voltage;
  410. }
  411. static void rs780_enable_voltage_scaling(struct radeon_device *rdev,
  412. struct radeon_ps *new_ps)
  413. {
  414. struct igp_ps *new_state = rs780_get_ps(new_ps);
  415. struct igp_power_info *pi = rs780_get_pi(rdev);
  416. enum rs780_vddc_level vddc_high, vddc_low;
  417. udelay(100);
  418. if ((new_state->max_voltage == RS780_VDDC_LEVEL_HIGH) &&
  419. (new_state->min_voltage == RS780_VDDC_LEVEL_HIGH))
  420. return;
  421. vddc_high = rs780_get_voltage_for_vddc_level(rdev,
  422. new_state->max_voltage);
  423. vddc_low = rs780_get_voltage_for_vddc_level(rdev,
  424. new_state->min_voltage);
  425. WREG32_P(GFX_MACRO_BYPASS_CNTL, SPLL_BYPASS_CNTL, ~SPLL_BYPASS_CNTL);
  426. udelay(1);
  427. if (vddc_high > vddc_low) {
  428. WREG32_P(FVTHROT_PWM_FEEDBACK_DIV_REG1,
  429. RANGE_PWM_FEEDBACK_DIV_EN, ~RANGE_PWM_FEEDBACK_DIV_EN);
  430. WREG32_P(FVTHROT_PWM_CTRL_REG0, 0, ~FORCE_STARTING_PWM_HIGHTIME);
  431. } else if (vddc_high == vddc_low) {
  432. if (pi->max_voltage != vddc_high) {
  433. WREG32_P(FVTHROT_PWM_CTRL_REG0,
  434. STARTING_PWM_HIGHTIME(vddc_high),
  435. ~STARTING_PWM_HIGHTIME_MASK);
  436. WREG32_P(FVTHROT_PWM_CTRL_REG0,
  437. FORCE_STARTING_PWM_HIGHTIME,
  438. ~FORCE_STARTING_PWM_HIGHTIME);
  439. }
  440. }
  441. WREG32_P(GFX_MACRO_BYPASS_CNTL, 0, ~SPLL_BYPASS_CNTL);
  442. }
  443. static void rs780_set_uvd_clock_before_set_eng_clock(struct radeon_device *rdev,
  444. struct radeon_ps *new_ps,
  445. struct radeon_ps *old_ps)
  446. {
  447. struct igp_ps *new_state = rs780_get_ps(new_ps);
  448. struct igp_ps *current_state = rs780_get_ps(old_ps);
  449. if ((new_ps->vclk == old_ps->vclk) &&
  450. (new_ps->dclk == old_ps->dclk))
  451. return;
  452. if (new_state->sclk_high >= current_state->sclk_high)
  453. return;
  454. radeon_set_uvd_clocks(rdev, new_ps->vclk, new_ps->dclk);
  455. }
  456. static void rs780_set_uvd_clock_after_set_eng_clock(struct radeon_device *rdev,
  457. struct radeon_ps *new_ps,
  458. struct radeon_ps *old_ps)
  459. {
  460. struct igp_ps *new_state = rs780_get_ps(new_ps);
  461. struct igp_ps *current_state = rs780_get_ps(old_ps);
  462. if ((new_ps->vclk == old_ps->vclk) &&
  463. (new_ps->dclk == old_ps->dclk))
  464. return;
  465. if (new_state->sclk_high < current_state->sclk_high)
  466. return;
  467. radeon_set_uvd_clocks(rdev, new_ps->vclk, new_ps->dclk);
  468. }
  469. int rs780_dpm_enable(struct radeon_device *rdev)
  470. {
  471. struct igp_power_info *pi = rs780_get_pi(rdev);
  472. struct radeon_ps *boot_ps = rdev->pm.dpm.boot_ps;
  473. int ret;
  474. rs780_get_pm_mode_parameters(rdev);
  475. rs780_disable_vbios_powersaving(rdev);
  476. if (r600_dynamicpm_enabled(rdev))
  477. return -EINVAL;
  478. ret = rs780_initialize_dpm_parameters(rdev, boot_ps);
  479. if (ret)
  480. return ret;
  481. rs780_start_dpm(rdev);
  482. rs780_preset_ranges_slow_clk_fbdiv_en(rdev);
  483. rs780_preset_starting_fbdiv(rdev);
  484. if (pi->voltage_control)
  485. rs780_voltage_scaling_init(rdev);
  486. rs780_clk_scaling_enable(rdev, true);
  487. rs780_set_engine_clock_sc(rdev);
  488. rs780_set_engine_clock_wfc(rdev);
  489. rs780_program_at(rdev);
  490. rs780_set_engine_clock_tdc(rdev);
  491. rs780_set_engine_clock_ssc(rdev);
  492. if (pi->gfx_clock_gating)
  493. r600_gfx_clockgating_enable(rdev, true);
  494. return 0;
  495. }
  496. void rs780_dpm_disable(struct radeon_device *rdev)
  497. {
  498. struct igp_power_info *pi = rs780_get_pi(rdev);
  499. r600_dynamicpm_enable(rdev, false);
  500. rs780_clk_scaling_enable(rdev, false);
  501. rs780_voltage_scaling_enable(rdev, false);
  502. if (pi->gfx_clock_gating)
  503. r600_gfx_clockgating_enable(rdev, false);
  504. if (rdev->irq.installed &&
  505. (rdev->pm.int_thermal_type == THERMAL_TYPE_RV6XX)) {
  506. rdev->irq.dpm_thermal = false;
  507. radeon_irq_set(rdev);
  508. }
  509. }
  510. int rs780_dpm_set_power_state(struct radeon_device *rdev)
  511. {
  512. struct igp_power_info *pi = rs780_get_pi(rdev);
  513. struct radeon_ps *new_ps = rdev->pm.dpm.requested_ps;
  514. struct radeon_ps *old_ps = rdev->pm.dpm.current_ps;
  515. int ret;
  516. rs780_get_pm_mode_parameters(rdev);
  517. rs780_set_uvd_clock_before_set_eng_clock(rdev, new_ps, old_ps);
  518. if (pi->voltage_control) {
  519. rs780_force_voltage(rdev, pi->max_voltage);
  520. mdelay(5);
  521. }
  522. ret = rs780_set_engine_clock_scaling(rdev, new_ps, old_ps);
  523. if (ret)
  524. return ret;
  525. rs780_set_engine_clock_spc(rdev, new_ps, old_ps);
  526. rs780_activate_engine_clk_scaling(rdev, new_ps, old_ps);
  527. if (pi->voltage_control)
  528. rs780_enable_voltage_scaling(rdev, new_ps);
  529. rs780_set_uvd_clock_after_set_eng_clock(rdev, new_ps, old_ps);
  530. return 0;
  531. }
  532. void rs780_dpm_setup_asic(struct radeon_device *rdev)
  533. {
  534. }
  535. void rs780_dpm_display_configuration_changed(struct radeon_device *rdev)
  536. {
  537. rs780_get_pm_mode_parameters(rdev);
  538. rs780_program_at(rdev);
  539. }
  540. union igp_info {
  541. struct _ATOM_INTEGRATED_SYSTEM_INFO info;
  542. struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 info_2;
  543. };
  544. union power_info {
  545. struct _ATOM_POWERPLAY_INFO info;
  546. struct _ATOM_POWERPLAY_INFO_V2 info_2;
  547. struct _ATOM_POWERPLAY_INFO_V3 info_3;
  548. struct _ATOM_PPLIB_POWERPLAYTABLE pplib;
  549. struct _ATOM_PPLIB_POWERPLAYTABLE2 pplib2;
  550. struct _ATOM_PPLIB_POWERPLAYTABLE3 pplib3;
  551. };
  552. union pplib_clock_info {
  553. struct _ATOM_PPLIB_R600_CLOCK_INFO r600;
  554. struct _ATOM_PPLIB_RS780_CLOCK_INFO rs780;
  555. struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO evergreen;
  556. struct _ATOM_PPLIB_SUMO_CLOCK_INFO sumo;
  557. };
  558. union pplib_power_state {
  559. struct _ATOM_PPLIB_STATE v1;
  560. struct _ATOM_PPLIB_STATE_V2 v2;
  561. };
  562. static void rs780_parse_pplib_non_clock_info(struct radeon_device *rdev,
  563. struct radeon_ps *rps,
  564. struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info,
  565. u8 table_rev)
  566. {
  567. rps->caps = le32_to_cpu(non_clock_info->ulCapsAndSettings);
  568. rps->class = le16_to_cpu(non_clock_info->usClassification);
  569. rps->class2 = le16_to_cpu(non_clock_info->usClassification2);
  570. if (ATOM_PPLIB_NONCLOCKINFO_VER1 < table_rev) {
  571. rps->vclk = le32_to_cpu(non_clock_info->ulVCLK);
  572. rps->dclk = le32_to_cpu(non_clock_info->ulDCLK);
  573. } else {
  574. rps->vclk = 0;
  575. rps->dclk = 0;
  576. }
  577. if (r600_is_uvd_state(rps->class, rps->class2)) {
  578. if ((rps->vclk == 0) || (rps->dclk == 0)) {
  579. rps->vclk = RS780_DEFAULT_VCLK_FREQ;
  580. rps->dclk = RS780_DEFAULT_DCLK_FREQ;
  581. }
  582. }
  583. if (rps->class & ATOM_PPLIB_CLASSIFICATION_BOOT)
  584. rdev->pm.dpm.boot_ps = rps;
  585. if (rps->class & ATOM_PPLIB_CLASSIFICATION_UVDSTATE)
  586. rdev->pm.dpm.uvd_ps = rps;
  587. }
  588. static void rs780_parse_pplib_clock_info(struct radeon_device *rdev,
  589. struct radeon_ps *rps,
  590. union pplib_clock_info *clock_info)
  591. {
  592. struct igp_ps *ps = rs780_get_ps(rps);
  593. u32 sclk;
  594. sclk = le16_to_cpu(clock_info->rs780.usLowEngineClockLow);
  595. sclk |= clock_info->rs780.ucLowEngineClockHigh << 16;
  596. ps->sclk_low = sclk;
  597. sclk = le16_to_cpu(clock_info->rs780.usHighEngineClockLow);
  598. sclk |= clock_info->rs780.ucHighEngineClockHigh << 16;
  599. ps->sclk_high = sclk;
  600. switch (le16_to_cpu(clock_info->rs780.usVDDC)) {
  601. case ATOM_PPLIB_RS780_VOLTAGE_NONE:
  602. default:
  603. ps->min_voltage = RS780_VDDC_LEVEL_UNKNOWN;
  604. ps->max_voltage = RS780_VDDC_LEVEL_UNKNOWN;
  605. break;
  606. case ATOM_PPLIB_RS780_VOLTAGE_LOW:
  607. ps->min_voltage = RS780_VDDC_LEVEL_LOW;
  608. ps->max_voltage = RS780_VDDC_LEVEL_LOW;
  609. break;
  610. case ATOM_PPLIB_RS780_VOLTAGE_HIGH:
  611. ps->min_voltage = RS780_VDDC_LEVEL_HIGH;
  612. ps->max_voltage = RS780_VDDC_LEVEL_HIGH;
  613. break;
  614. case ATOM_PPLIB_RS780_VOLTAGE_VARIABLE:
  615. ps->min_voltage = RS780_VDDC_LEVEL_LOW;
  616. ps->max_voltage = RS780_VDDC_LEVEL_HIGH;
  617. break;
  618. }
  619. ps->flags = le32_to_cpu(clock_info->rs780.ulFlags);
  620. if (rps->class & ATOM_PPLIB_CLASSIFICATION_BOOT) {
  621. ps->sclk_low = rdev->clock.default_sclk;
  622. ps->sclk_high = rdev->clock.default_sclk;
  623. ps->min_voltage = RS780_VDDC_LEVEL_HIGH;
  624. ps->max_voltage = RS780_VDDC_LEVEL_HIGH;
  625. }
  626. }
  627. static int rs780_parse_power_table(struct radeon_device *rdev)
  628. {
  629. struct radeon_mode_info *mode_info = &rdev->mode_info;
  630. struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
  631. union pplib_power_state *power_state;
  632. int i;
  633. union pplib_clock_info *clock_info;
  634. union power_info *power_info;
  635. int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
  636. u16 data_offset;
  637. u8 frev, crev;
  638. struct igp_ps *ps;
  639. if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
  640. &frev, &crev, &data_offset))
  641. return -EINVAL;
  642. power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
  643. rdev->pm.dpm.ps = kzalloc(sizeof(struct radeon_ps) *
  644. power_info->pplib.ucNumStates, GFP_KERNEL);
  645. if (!rdev->pm.dpm.ps)
  646. return -ENOMEM;
  647. for (i = 0; i < power_info->pplib.ucNumStates; i++) {
  648. power_state = (union pplib_power_state *)
  649. (mode_info->atom_context->bios + data_offset +
  650. le16_to_cpu(power_info->pplib.usStateArrayOffset) +
  651. i * power_info->pplib.ucStateEntrySize);
  652. non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
  653. (mode_info->atom_context->bios + data_offset +
  654. le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset) +
  655. (power_state->v1.ucNonClockStateIndex *
  656. power_info->pplib.ucNonClockSize));
  657. if (power_info->pplib.ucStateEntrySize - 1) {
  658. clock_info = (union pplib_clock_info *)
  659. (mode_info->atom_context->bios + data_offset +
  660. le16_to_cpu(power_info->pplib.usClockInfoArrayOffset) +
  661. (power_state->v1.ucClockStateIndices[0] *
  662. power_info->pplib.ucClockInfoSize));
  663. ps = kzalloc(sizeof(struct igp_ps), GFP_KERNEL);
  664. if (ps == NULL) {
  665. kfree(rdev->pm.dpm.ps);
  666. return -ENOMEM;
  667. }
  668. rdev->pm.dpm.ps[i].ps_priv = ps;
  669. rs780_parse_pplib_non_clock_info(rdev, &rdev->pm.dpm.ps[i],
  670. non_clock_info,
  671. power_info->pplib.ucNonClockSize);
  672. rs780_parse_pplib_clock_info(rdev,
  673. &rdev->pm.dpm.ps[i],
  674. clock_info);
  675. }
  676. }
  677. rdev->pm.dpm.num_ps = power_info->pplib.ucNumStates;
  678. return 0;
  679. }
  680. int rs780_dpm_init(struct radeon_device *rdev)
  681. {
  682. struct igp_power_info *pi;
  683. int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
  684. union igp_info *info;
  685. u16 data_offset;
  686. u8 frev, crev;
  687. int ret;
  688. pi = kzalloc(sizeof(struct igp_power_info), GFP_KERNEL);
  689. if (pi == NULL)
  690. return -ENOMEM;
  691. rdev->pm.dpm.priv = pi;
  692. ret = r600_get_platform_caps(rdev);
  693. if (ret)
  694. return ret;
  695. ret = rs780_parse_power_table(rdev);
  696. if (ret)
  697. return ret;
  698. pi->voltage_control = false;
  699. pi->gfx_clock_gating = true;
  700. if (atom_parse_data_header(rdev->mode_info.atom_context, index, NULL,
  701. &frev, &crev, &data_offset)) {
  702. info = (union igp_info *)(rdev->mode_info.atom_context->bios + data_offset);
  703. /* Get various system informations from bios */
  704. switch (crev) {
  705. case 1:
  706. pi->num_of_cycles_in_period =
  707. info->info.ucNumberOfCyclesInPeriod;
  708. pi->num_of_cycles_in_period |=
  709. info->info.ucNumberOfCyclesInPeriodHi << 8;
  710. pi->invert_pwm_required =
  711. (pi->num_of_cycles_in_period & 0x8000) ? true : false;
  712. pi->boot_voltage = info->info.ucStartingPWM_HighTime;
  713. pi->max_voltage = info->info.ucMaxNBVoltage;
  714. pi->max_voltage |= info->info.ucMaxNBVoltageHigh << 8;
  715. pi->min_voltage = info->info.ucMinNBVoltage;
  716. pi->min_voltage |= info->info.ucMinNBVoltageHigh << 8;
  717. pi->inter_voltage_low =
  718. le16_to_cpu(info->info.usInterNBVoltageLow);
  719. pi->inter_voltage_high =
  720. le16_to_cpu(info->info.usInterNBVoltageHigh);
  721. pi->voltage_control = true;
  722. pi->bootup_uma_clk = info->info.usK8MemoryClock * 100;
  723. break;
  724. case 2:
  725. pi->num_of_cycles_in_period =
  726. le16_to_cpu(info->info_2.usNumberOfCyclesInPeriod);
  727. pi->invert_pwm_required =
  728. (pi->num_of_cycles_in_period & 0x8000) ? true : false;
  729. pi->boot_voltage =
  730. le16_to_cpu(info->info_2.usBootUpNBVoltage);
  731. pi->max_voltage =
  732. le16_to_cpu(info->info_2.usMaxNBVoltage);
  733. pi->min_voltage =
  734. le16_to_cpu(info->info_2.usMinNBVoltage);
  735. pi->system_config =
  736. le32_to_cpu(info->info_2.ulSystemConfig);
  737. pi->pwm_voltage_control =
  738. (pi->system_config & 0x4) ? true : false;
  739. pi->voltage_control = true;
  740. pi->bootup_uma_clk = le32_to_cpu(info->info_2.ulBootUpUMAClock);
  741. break;
  742. default:
  743. DRM_ERROR("No integrated system info for your GPU\n");
  744. return -EINVAL;
  745. }
  746. if (pi->min_voltage > pi->max_voltage)
  747. pi->voltage_control = false;
  748. if (pi->pwm_voltage_control) {
  749. if ((pi->num_of_cycles_in_period == 0) ||
  750. (pi->max_voltage == 0) ||
  751. (pi->min_voltage == 0))
  752. pi->voltage_control = false;
  753. } else {
  754. if ((pi->num_of_cycles_in_period == 0) ||
  755. (pi->max_voltage == 0))
  756. pi->voltage_control = false;
  757. }
  758. return 0;
  759. }
  760. radeon_dpm_fini(rdev);
  761. return -EINVAL;
  762. }
  763. void rs780_dpm_print_power_state(struct radeon_device *rdev,
  764. struct radeon_ps *rps)
  765. {
  766. struct igp_ps *ps = rs780_get_ps(rps);
  767. r600_dpm_print_class_info(rps->class, rps->class2);
  768. r600_dpm_print_cap_info(rps->caps);
  769. printk("\tuvd vclk: %d dclk: %d\n", rps->vclk, rps->dclk);
  770. printk("\t\tpower level 0 sclk: %u vddc_index: %d\n",
  771. ps->sclk_low, ps->min_voltage);
  772. printk("\t\tpower level 1 sclk: %u vddc_index: %d\n",
  773. ps->sclk_high, ps->max_voltage);
  774. r600_dpm_print_ps_status(rdev, rps);
  775. }
  776. void rs780_dpm_fini(struct radeon_device *rdev)
  777. {
  778. int i;
  779. for (i = 0; i < rdev->pm.dpm.num_ps; i++) {
  780. kfree(rdev->pm.dpm.ps[i].ps_priv);
  781. }
  782. kfree(rdev->pm.dpm.ps);
  783. kfree(rdev->pm.dpm.priv);
  784. }
  785. u32 rs780_dpm_get_sclk(struct radeon_device *rdev, bool low)
  786. {
  787. struct igp_ps *requested_state = rs780_get_ps(rdev->pm.dpm.requested_ps);
  788. if (low)
  789. return requested_state->sclk_low;
  790. else
  791. return requested_state->sclk_high;
  792. }
  793. u32 rs780_dpm_get_mclk(struct radeon_device *rdev, bool low)
  794. {
  795. struct igp_power_info *pi = rs780_get_pi(rdev);
  796. return pi->bootup_uma_clk;
  797. }
  798. void rs780_dpm_debugfs_print_current_performance_level(struct radeon_device *rdev,
  799. struct seq_file *m)
  800. {
  801. struct radeon_ps *rps = rdev->pm.dpm.current_ps;
  802. struct igp_ps *ps = rs780_get_ps(rps);
  803. u32 current_fb_div = RREG32(FVTHROT_STATUS_REG0) & CURRENT_FEEDBACK_DIV_MASK;
  804. u32 func_cntl = RREG32(CG_SPLL_FUNC_CNTL);
  805. u32 ref_div = ((func_cntl & SPLL_REF_DIV_MASK) >> SPLL_REF_DIV_SHIFT) + 1;
  806. u32 post_div = ((func_cntl & SPLL_SW_HILEN_MASK) >> SPLL_SW_HILEN_SHIFT) + 1 +
  807. ((func_cntl & SPLL_SW_LOLEN_MASK) >> SPLL_SW_LOLEN_SHIFT) + 1;
  808. u32 sclk = (rdev->clock.spll.reference_freq * current_fb_div) /
  809. (post_div * ref_div);
  810. seq_printf(m, "uvd vclk: %d dclk: %d\n", rps->vclk, rps->dclk);
  811. /* guess based on the current sclk */
  812. if (sclk < (ps->sclk_low + 500))
  813. seq_printf(m, "power level 0 sclk: %u vddc_index: %d\n",
  814. ps->sclk_low, ps->min_voltage);
  815. else
  816. seq_printf(m, "power level 1 sclk: %u vddc_index: %d\n",
  817. ps->sclk_high, ps->max_voltage);
  818. }
  819. /* get the current sclk in 10 khz units */
  820. u32 rs780_dpm_get_current_sclk(struct radeon_device *rdev)
  821. {
  822. u32 current_fb_div = RREG32(FVTHROT_STATUS_REG0) & CURRENT_FEEDBACK_DIV_MASK;
  823. u32 func_cntl = RREG32(CG_SPLL_FUNC_CNTL);
  824. u32 ref_div = ((func_cntl & SPLL_REF_DIV_MASK) >> SPLL_REF_DIV_SHIFT) + 1;
  825. u32 post_div = ((func_cntl & SPLL_SW_HILEN_MASK) >> SPLL_SW_HILEN_SHIFT) + 1 +
  826. ((func_cntl & SPLL_SW_LOLEN_MASK) >> SPLL_SW_LOLEN_SHIFT) + 1;
  827. u32 sclk = (rdev->clock.spll.reference_freq * current_fb_div) /
  828. (post_div * ref_div);
  829. return sclk;
  830. }
  831. /* get the current mclk in 10 khz units */
  832. u32 rs780_dpm_get_current_mclk(struct radeon_device *rdev)
  833. {
  834. struct igp_power_info *pi = rs780_get_pi(rdev);
  835. return pi->bootup_uma_clk;
  836. }
  837. int rs780_dpm_force_performance_level(struct radeon_device *rdev,
  838. enum radeon_dpm_forced_level level)
  839. {
  840. struct igp_power_info *pi = rs780_get_pi(rdev);
  841. struct radeon_ps *rps = rdev->pm.dpm.current_ps;
  842. struct igp_ps *ps = rs780_get_ps(rps);
  843. struct atom_clock_dividers dividers;
  844. int ret;
  845. rs780_clk_scaling_enable(rdev, false);
  846. rs780_voltage_scaling_enable(rdev, false);
  847. if (level == RADEON_DPM_FORCED_LEVEL_HIGH) {
  848. if (pi->voltage_control)
  849. rs780_force_voltage(rdev, pi->max_voltage);
  850. ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
  851. ps->sclk_high, false, &dividers);
  852. if (ret)
  853. return ret;
  854. rs780_force_fbdiv(rdev, dividers.fb_div);
  855. } else if (level == RADEON_DPM_FORCED_LEVEL_LOW) {
  856. ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
  857. ps->sclk_low, false, &dividers);
  858. if (ret)
  859. return ret;
  860. rs780_force_fbdiv(rdev, dividers.fb_div);
  861. if (pi->voltage_control)
  862. rs780_force_voltage(rdev, pi->min_voltage);
  863. } else {
  864. if (pi->voltage_control)
  865. rs780_force_voltage(rdev, pi->max_voltage);
  866. if (ps->sclk_high != ps->sclk_low) {
  867. WREG32_P(FVTHROT_FBDIV_REG1, 0, ~FORCE_FEEDBACK_DIV);
  868. rs780_clk_scaling_enable(rdev, true);
  869. }
  870. if (pi->voltage_control) {
  871. rs780_voltage_scaling_enable(rdev, true);
  872. rs780_enable_voltage_scaling(rdev, rps);
  873. }
  874. }
  875. rdev->pm.dpm.forced_level = level;
  876. return 0;
  877. }