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