Home | History | Annotate | Line # | Download | only in radeon
      1  1.3       mrg /*	$NetBSD: radeon_cypress_dpm.c,v 1.3 2022/07/15 06:42:08 mrg 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.3       mrg __KERNEL_RCSID(0, "$NetBSD: radeon_cypress_dpm.c,v 1.3 2022/07/15 06:42:08 mrg Exp $");
     29  1.1  riastrad 
     30  1.2  riastrad #include <linux/pci.h>
     31  1.2  riastrad 
     32  1.2  riastrad #include "atom.h"
     33  1.2  riastrad #include "cypress_dpm.h"
     34  1.2  riastrad #include "evergreend.h"
     35  1.2  riastrad #include "r600_dpm.h"
     36  1.1  riastrad #include "radeon.h"
     37  1.1  riastrad #include "radeon_asic.h"
     38  1.1  riastrad 
     39  1.1  riastrad #define SMC_RAM_END 0x8000
     40  1.1  riastrad 
     41  1.1  riastrad #define MC_CG_ARB_FREQ_F0           0x0a
     42  1.1  riastrad #define MC_CG_ARB_FREQ_F1           0x0b
     43  1.1  riastrad #define MC_CG_ARB_FREQ_F2           0x0c
     44  1.1  riastrad #define MC_CG_ARB_FREQ_F3           0x0d
     45  1.1  riastrad 
     46  1.1  riastrad #define MC_CG_SEQ_DRAMCONF_S0       0x05
     47  1.1  riastrad #define MC_CG_SEQ_DRAMCONF_S1       0x06
     48  1.1  riastrad #define MC_CG_SEQ_YCLK_SUSPEND      0x04
     49  1.1  riastrad #define MC_CG_SEQ_YCLK_RESUME       0x0a
     50  1.1  riastrad 
     51  1.1  riastrad struct rv7xx_ps *rv770_get_ps(struct radeon_ps *rps);
     52  1.1  riastrad struct rv7xx_power_info *rv770_get_pi(struct radeon_device *rdev);
     53  1.1  riastrad struct evergreen_power_info *evergreen_get_pi(struct radeon_device *rdev);
     54  1.1  riastrad 
     55  1.1  riastrad static void cypress_enable_bif_dynamic_pcie_gen2(struct radeon_device *rdev,
     56  1.1  riastrad 						 bool enable)
     57  1.1  riastrad {
     58  1.1  riastrad 	struct rv7xx_power_info *pi = rv770_get_pi(rdev);
     59  1.1  riastrad 	u32 tmp, bif;
     60  1.1  riastrad 
     61  1.1  riastrad 	tmp = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
     62  1.1  riastrad 	if (enable) {
     63  1.1  riastrad 		if ((tmp & LC_OTHER_SIDE_EVER_SENT_GEN2) &&
     64  1.1  riastrad 		    (tmp & LC_OTHER_SIDE_SUPPORTS_GEN2)) {
     65  1.1  riastrad 			if (!pi->boot_in_gen2) {
     66  1.1  riastrad 				bif = RREG32(CG_BIF_REQ_AND_RSP) & ~CG_CLIENT_REQ_MASK;
     67  1.1  riastrad 				bif |= CG_CLIENT_REQ(0xd);
     68  1.1  riastrad 				WREG32(CG_BIF_REQ_AND_RSP, bif);
     69  1.1  riastrad 
     70  1.1  riastrad 				tmp &= ~LC_HW_VOLTAGE_IF_CONTROL_MASK;
     71  1.1  riastrad 				tmp |= LC_HW_VOLTAGE_IF_CONTROL(1);
     72  1.1  riastrad 				tmp |= LC_GEN2_EN_STRAP;
     73  1.1  riastrad 
     74  1.1  riastrad 				tmp |= LC_CLR_FAILED_SPD_CHANGE_CNT;
     75  1.1  riastrad 				WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, tmp);
     76  1.1  riastrad 				udelay(10);
     77  1.1  riastrad 				tmp &= ~LC_CLR_FAILED_SPD_CHANGE_CNT;
     78  1.1  riastrad 				WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, tmp);
     79  1.1  riastrad 			}
     80  1.1  riastrad 		}
     81  1.1  riastrad 	} else {
     82  1.1  riastrad 		if (!pi->boot_in_gen2) {
     83  1.1  riastrad 			tmp &= ~LC_HW_VOLTAGE_IF_CONTROL_MASK;
     84  1.1  riastrad 			tmp &= ~LC_GEN2_EN_STRAP;
     85  1.1  riastrad 		}
     86  1.1  riastrad 		if ((tmp & LC_OTHER_SIDE_EVER_SENT_GEN2) ||
     87  1.1  riastrad 		    (tmp & LC_OTHER_SIDE_SUPPORTS_GEN2))
     88  1.1  riastrad 			WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, tmp);
     89  1.1  riastrad 	}
     90  1.1  riastrad }
     91  1.1  riastrad 
     92  1.1  riastrad static void cypress_enable_dynamic_pcie_gen2(struct radeon_device *rdev,
     93  1.1  riastrad 					     bool enable)
     94  1.1  riastrad {
     95  1.1  riastrad 	cypress_enable_bif_dynamic_pcie_gen2(rdev, enable);
     96  1.1  riastrad 
     97  1.1  riastrad 	if (enable)
     98  1.1  riastrad 		WREG32_P(GENERAL_PWRMGT, ENABLE_GEN2PCIE, ~ENABLE_GEN2PCIE);
     99  1.1  riastrad 	else
    100  1.1  riastrad 		WREG32_P(GENERAL_PWRMGT, 0, ~ENABLE_GEN2PCIE);
    101  1.1  riastrad }
    102  1.1  riastrad 
    103  1.1  riastrad #if 0
    104  1.1  riastrad static int cypress_enter_ulp_state(struct radeon_device *rdev)
    105  1.1  riastrad {
    106  1.1  riastrad 	struct rv7xx_power_info *pi = rv770_get_pi(rdev);
    107  1.1  riastrad 
    108  1.1  riastrad 	if (pi->gfx_clock_gating) {
    109  1.1  riastrad 		WREG32_P(SCLK_PWRMGT_CNTL, 0, ~DYN_GFX_CLK_OFF_EN);
    110  1.1  riastrad 		WREG32_P(SCLK_PWRMGT_CNTL, GFX_CLK_FORCE_ON, ~GFX_CLK_FORCE_ON);
    111  1.1  riastrad 		WREG32_P(SCLK_PWRMGT_CNTL, 0, ~GFX_CLK_FORCE_ON);
    112  1.1  riastrad 
    113  1.1  riastrad 		RREG32(GB_ADDR_CONFIG);
    114  1.1  riastrad 	}
    115  1.1  riastrad 
    116  1.1  riastrad 	WREG32_P(SMC_MSG, HOST_SMC_MSG(PPSMC_MSG_SwitchToMinimumPower),
    117  1.1  riastrad 		 ~HOST_SMC_MSG_MASK);
    118  1.1  riastrad 
    119  1.1  riastrad 	udelay(7000);
    120  1.1  riastrad 
    121  1.1  riastrad 	return 0;
    122  1.1  riastrad }
    123  1.1  riastrad #endif
    124  1.1  riastrad 
    125  1.1  riastrad static void cypress_gfx_clock_gating_enable(struct radeon_device *rdev,
    126  1.1  riastrad 					    bool enable)
    127  1.1  riastrad {
    128  1.1  riastrad 	struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
    129  1.1  riastrad 
    130  1.1  riastrad 	if (enable) {
    131  1.1  riastrad 		if (eg_pi->light_sleep) {
    132  1.1  riastrad 			WREG32(GRBM_GFX_INDEX, 0xC0000000);
    133  1.1  riastrad 
    134  1.1  riastrad 			WREG32_CG(CG_CGLS_TILE_0, 0xFFFFFFFF);
    135  1.1  riastrad 			WREG32_CG(CG_CGLS_TILE_1, 0xFFFFFFFF);
    136  1.1  riastrad 			WREG32_CG(CG_CGLS_TILE_2, 0xFFFFFFFF);
    137  1.1  riastrad 			WREG32_CG(CG_CGLS_TILE_3, 0xFFFFFFFF);
    138  1.1  riastrad 			WREG32_CG(CG_CGLS_TILE_4, 0xFFFFFFFF);
    139  1.1  riastrad 			WREG32_CG(CG_CGLS_TILE_5, 0xFFFFFFFF);
    140  1.1  riastrad 			WREG32_CG(CG_CGLS_TILE_6, 0xFFFFFFFF);
    141  1.1  riastrad 			WREG32_CG(CG_CGLS_TILE_7, 0xFFFFFFFF);
    142  1.1  riastrad 			WREG32_CG(CG_CGLS_TILE_8, 0xFFFFFFFF);
    143  1.1  riastrad 			WREG32_CG(CG_CGLS_TILE_9, 0xFFFFFFFF);
    144  1.1  riastrad 			WREG32_CG(CG_CGLS_TILE_10, 0xFFFFFFFF);
    145  1.1  riastrad 			WREG32_CG(CG_CGLS_TILE_11, 0xFFFFFFFF);
    146  1.1  riastrad 
    147  1.1  riastrad 			WREG32_P(SCLK_PWRMGT_CNTL, DYN_LIGHT_SLEEP_EN, ~DYN_LIGHT_SLEEP_EN);
    148  1.1  riastrad 		}
    149  1.1  riastrad 		WREG32_P(SCLK_PWRMGT_CNTL, DYN_GFX_CLK_OFF_EN, ~DYN_GFX_CLK_OFF_EN);
    150  1.1  riastrad 	} else {
    151  1.1  riastrad 		WREG32_P(SCLK_PWRMGT_CNTL, 0, ~DYN_GFX_CLK_OFF_EN);
    152  1.1  riastrad 		WREG32_P(SCLK_PWRMGT_CNTL, GFX_CLK_FORCE_ON, ~GFX_CLK_FORCE_ON);
    153  1.1  riastrad 		WREG32_P(SCLK_PWRMGT_CNTL, 0, ~GFX_CLK_FORCE_ON);
    154  1.1  riastrad 		RREG32(GB_ADDR_CONFIG);
    155  1.1  riastrad 
    156  1.1  riastrad 		if (eg_pi->light_sleep) {
    157  1.1  riastrad 			WREG32_P(SCLK_PWRMGT_CNTL, 0, ~DYN_LIGHT_SLEEP_EN);
    158  1.1  riastrad 
    159  1.1  riastrad 			WREG32(GRBM_GFX_INDEX, 0xC0000000);
    160  1.1  riastrad 
    161  1.1  riastrad 			WREG32_CG(CG_CGLS_TILE_0, 0);
    162  1.1  riastrad 			WREG32_CG(CG_CGLS_TILE_1, 0);
    163  1.1  riastrad 			WREG32_CG(CG_CGLS_TILE_2, 0);
    164  1.1  riastrad 			WREG32_CG(CG_CGLS_TILE_3, 0);
    165  1.1  riastrad 			WREG32_CG(CG_CGLS_TILE_4, 0);
    166  1.1  riastrad 			WREG32_CG(CG_CGLS_TILE_5, 0);
    167  1.1  riastrad 			WREG32_CG(CG_CGLS_TILE_6, 0);
    168  1.1  riastrad 			WREG32_CG(CG_CGLS_TILE_7, 0);
    169  1.1  riastrad 			WREG32_CG(CG_CGLS_TILE_8, 0);
    170  1.1  riastrad 			WREG32_CG(CG_CGLS_TILE_9, 0);
    171  1.1  riastrad 			WREG32_CG(CG_CGLS_TILE_10, 0);
    172  1.1  riastrad 			WREG32_CG(CG_CGLS_TILE_11, 0);
    173  1.1  riastrad 		}
    174  1.1  riastrad 	}
    175  1.1  riastrad }
    176  1.1  riastrad 
    177  1.1  riastrad static void cypress_mg_clock_gating_enable(struct radeon_device *rdev,
    178  1.1  riastrad 					   bool enable)
    179  1.1  riastrad {
    180  1.1  riastrad 	struct rv7xx_power_info *pi = rv770_get_pi(rdev);
    181  1.1  riastrad 	struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
    182  1.1  riastrad 
    183  1.1  riastrad 	if (enable) {
    184  1.1  riastrad 		u32 cgts_sm_ctrl_reg;
    185  1.1  riastrad 
    186  1.1  riastrad 		if (rdev->family == CHIP_CEDAR)
    187  1.1  riastrad 			cgts_sm_ctrl_reg = CEDAR_MGCGCGTSSMCTRL_DFLT;
    188  1.1  riastrad 		else if (rdev->family == CHIP_REDWOOD)
    189  1.1  riastrad 			cgts_sm_ctrl_reg = REDWOOD_MGCGCGTSSMCTRL_DFLT;
    190  1.1  riastrad 		else
    191  1.1  riastrad 			cgts_sm_ctrl_reg = CYPRESS_MGCGCGTSSMCTRL_DFLT;
    192  1.1  riastrad 
    193  1.1  riastrad 		WREG32(GRBM_GFX_INDEX, 0xC0000000);
    194  1.1  riastrad 
    195  1.1  riastrad 		WREG32_CG(CG_CGTT_LOCAL_0, CYPRESS_MGCGTTLOCAL0_DFLT);
    196  1.1  riastrad 		WREG32_CG(CG_CGTT_LOCAL_1, CYPRESS_MGCGTTLOCAL1_DFLT & 0xFFFFCFFF);
    197  1.1  riastrad 		WREG32_CG(CG_CGTT_LOCAL_2, CYPRESS_MGCGTTLOCAL2_DFLT);
    198  1.1  riastrad 		WREG32_CG(CG_CGTT_LOCAL_3, CYPRESS_MGCGTTLOCAL3_DFLT);
    199  1.1  riastrad 
    200  1.1  riastrad 		if (pi->mgcgtssm)
    201  1.1  riastrad 			WREG32(CGTS_SM_CTRL_REG, cgts_sm_ctrl_reg);
    202  1.1  riastrad 
    203  1.1  riastrad 		if (eg_pi->mcls) {
    204  1.1  riastrad 			WREG32_P(MC_CITF_MISC_RD_CG, MEM_LS_ENABLE, ~MEM_LS_ENABLE);
    205  1.1  riastrad 			WREG32_P(MC_CITF_MISC_WR_CG, MEM_LS_ENABLE, ~MEM_LS_ENABLE);
    206  1.1  riastrad 			WREG32_P(MC_CITF_MISC_VM_CG, MEM_LS_ENABLE, ~MEM_LS_ENABLE);
    207  1.1  riastrad 			WREG32_P(MC_HUB_MISC_HUB_CG, MEM_LS_ENABLE, ~MEM_LS_ENABLE);
    208  1.1  riastrad 			WREG32_P(MC_HUB_MISC_VM_CG, MEM_LS_ENABLE, ~MEM_LS_ENABLE);
    209  1.1  riastrad 			WREG32_P(MC_HUB_MISC_SIP_CG, MEM_LS_ENABLE, ~MEM_LS_ENABLE);
    210  1.1  riastrad 			WREG32_P(MC_XPB_CLK_GAT, MEM_LS_ENABLE, ~MEM_LS_ENABLE);
    211  1.1  riastrad 			WREG32_P(VM_L2_CG, MEM_LS_ENABLE, ~MEM_LS_ENABLE);
    212  1.1  riastrad 		}
    213  1.1  riastrad 	} else {
    214  1.1  riastrad 		WREG32(GRBM_GFX_INDEX, 0xC0000000);
    215  1.1  riastrad 
    216  1.1  riastrad 		WREG32_CG(CG_CGTT_LOCAL_0, 0xFFFFFFFF);
    217  1.1  riastrad 		WREG32_CG(CG_CGTT_LOCAL_1, 0xFFFFFFFF);
    218  1.1  riastrad 		WREG32_CG(CG_CGTT_LOCAL_2, 0xFFFFFFFF);
    219  1.1  riastrad 		WREG32_CG(CG_CGTT_LOCAL_3, 0xFFFFFFFF);
    220  1.1  riastrad 
    221  1.1  riastrad 		if (pi->mgcgtssm)
    222  1.1  riastrad 			WREG32(CGTS_SM_CTRL_REG, 0x81f44bc0);
    223  1.1  riastrad 	}
    224  1.1  riastrad }
    225  1.1  riastrad 
    226  1.1  riastrad void cypress_enable_spread_spectrum(struct radeon_device *rdev,
    227  1.1  riastrad 				    bool enable)
    228  1.1  riastrad {
    229  1.1  riastrad 	struct rv7xx_power_info *pi = rv770_get_pi(rdev);
    230  1.1  riastrad 
    231  1.1  riastrad 	if (enable) {
    232  1.1  riastrad 		if (pi->sclk_ss)
    233  1.1  riastrad 			WREG32_P(GENERAL_PWRMGT, DYN_SPREAD_SPECTRUM_EN, ~DYN_SPREAD_SPECTRUM_EN);
    234  1.1  riastrad 
    235  1.1  riastrad 		if (pi->mclk_ss)
    236  1.1  riastrad 			WREG32_P(MPLL_CNTL_MODE, SS_SSEN, ~SS_SSEN);
    237  1.1  riastrad 	} else {
    238  1.1  riastrad 		WREG32_P(CG_SPLL_SPREAD_SPECTRUM, 0, ~SSEN);
    239  1.1  riastrad 		WREG32_P(GENERAL_PWRMGT, 0, ~DYN_SPREAD_SPECTRUM_EN);
    240  1.1  riastrad 		WREG32_P(MPLL_CNTL_MODE, 0, ~SS_SSEN);
    241  1.1  riastrad 		WREG32_P(MPLL_CNTL_MODE, 0, ~SS_DSMODE_EN);
    242  1.1  riastrad 	}
    243  1.1  riastrad }
    244  1.1  riastrad 
    245  1.1  riastrad void cypress_start_dpm(struct radeon_device *rdev)
    246  1.1  riastrad {
    247  1.1  riastrad 	WREG32_P(GENERAL_PWRMGT, GLOBAL_PWRMGT_EN, ~GLOBAL_PWRMGT_EN);
    248  1.1  riastrad }
    249  1.1  riastrad 
    250  1.1  riastrad void cypress_enable_sclk_control(struct radeon_device *rdev,
    251  1.1  riastrad 				 bool enable)
    252  1.1  riastrad {
    253  1.1  riastrad 	if (enable)
    254  1.1  riastrad 		WREG32_P(SCLK_PWRMGT_CNTL, 0, ~SCLK_PWRMGT_OFF);
    255  1.1  riastrad 	else
    256  1.1  riastrad 		WREG32_P(SCLK_PWRMGT_CNTL, SCLK_PWRMGT_OFF, ~SCLK_PWRMGT_OFF);
    257  1.1  riastrad }
    258  1.1  riastrad 
    259  1.1  riastrad void cypress_enable_mclk_control(struct radeon_device *rdev,
    260  1.1  riastrad 				 bool enable)
    261  1.1  riastrad {
    262  1.1  riastrad 	if (enable)
    263  1.1  riastrad 		WREG32_P(MCLK_PWRMGT_CNTL, 0, ~MPLL_PWRMGT_OFF);
    264  1.1  riastrad 	else
    265  1.1  riastrad 		WREG32_P(MCLK_PWRMGT_CNTL, MPLL_PWRMGT_OFF, ~MPLL_PWRMGT_OFF);
    266  1.1  riastrad }
    267  1.1  riastrad 
    268  1.1  riastrad int cypress_notify_smc_display_change(struct radeon_device *rdev,
    269  1.1  riastrad 				      bool has_display)
    270  1.1  riastrad {
    271  1.1  riastrad 	PPSMC_Msg msg = has_display ?
    272  1.1  riastrad 		(PPSMC_Msg)PPSMC_MSG_HasDisplay : (PPSMC_Msg)PPSMC_MSG_NoDisplay;
    273  1.1  riastrad 
    274  1.1  riastrad 	if (rv770_send_msg_to_smc(rdev, msg) != PPSMC_Result_OK)
    275  1.1  riastrad 		return -EINVAL;
    276  1.1  riastrad 
    277  1.1  riastrad 	return 0;
    278  1.1  riastrad }
    279  1.1  riastrad 
    280  1.1  riastrad void cypress_program_response_times(struct radeon_device *rdev)
    281  1.1  riastrad {
    282  1.1  riastrad 	u32 reference_clock;
    283  1.1  riastrad 	u32 mclk_switch_limit;
    284  1.1  riastrad 
    285  1.1  riastrad 	reference_clock = radeon_get_xclk(rdev);
    286  1.1  riastrad 	mclk_switch_limit = (460 * reference_clock) / 100;
    287  1.1  riastrad 
    288  1.1  riastrad 	rv770_write_smc_soft_register(rdev,
    289  1.1  riastrad 				      RV770_SMC_SOFT_REGISTER_mclk_switch_lim,
    290  1.1  riastrad 				      mclk_switch_limit);
    291  1.1  riastrad 
    292  1.1  riastrad 	rv770_write_smc_soft_register(rdev,
    293  1.1  riastrad 				      RV770_SMC_SOFT_REGISTER_mvdd_chg_time, 1);
    294  1.1  riastrad 
    295  1.1  riastrad 	rv770_write_smc_soft_register(rdev,
    296  1.1  riastrad 				      RV770_SMC_SOFT_REGISTER_mc_block_delay, 0xAA);
    297  1.1  riastrad 
    298  1.1  riastrad 	rv770_program_response_times(rdev);
    299  1.1  riastrad 
    300  1.1  riastrad 	if (ASIC_IS_LOMBOK(rdev))
    301  1.1  riastrad 		rv770_write_smc_soft_register(rdev,
    302  1.1  riastrad 					      RV770_SMC_SOFT_REGISTER_is_asic_lombok, 1);
    303  1.1  riastrad 
    304  1.1  riastrad }
    305  1.1  riastrad 
    306  1.1  riastrad static int cypress_pcie_performance_request(struct radeon_device *rdev,
    307  1.1  riastrad 					    u8 perf_req, bool advertise)
    308  1.1  riastrad {
    309  1.1  riastrad #if defined(CONFIG_ACPI)
    310  1.1  riastrad 	struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
    311  1.1  riastrad #endif
    312  1.1  riastrad 	u32 tmp;
    313  1.1  riastrad 
    314  1.1  riastrad 	udelay(10);
    315  1.1  riastrad 	tmp = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
    316  1.1  riastrad 	if ((perf_req == PCIE_PERF_REQ_PECI_GEN1) && (tmp & LC_CURRENT_DATA_RATE))
    317  1.1  riastrad 		return 0;
    318  1.1  riastrad 
    319  1.1  riastrad #if defined(CONFIG_ACPI)
    320  1.1  riastrad 	if ((perf_req == PCIE_PERF_REQ_PECI_GEN1) ||
    321  1.1  riastrad 	    (perf_req == PCIE_PERF_REQ_PECI_GEN2)) {
    322  1.1  riastrad 		eg_pi->pcie_performance_request_registered = true;
    323  1.1  riastrad 		return radeon_acpi_pcie_performance_request(rdev, perf_req, advertise);
    324  1.1  riastrad 	} else if ((perf_req == PCIE_PERF_REQ_REMOVE_REGISTRY) &&
    325  1.1  riastrad 		   eg_pi->pcie_performance_request_registered) {
    326  1.1  riastrad 		eg_pi->pcie_performance_request_registered = false;
    327  1.1  riastrad 		return radeon_acpi_pcie_performance_request(rdev, perf_req, advertise);
    328  1.1  riastrad 	}
    329  1.1  riastrad #endif
    330  1.1  riastrad 
    331  1.1  riastrad 	return 0;
    332  1.1  riastrad }
    333  1.1  riastrad 
    334  1.1  riastrad void cypress_advertise_gen2_capability(struct radeon_device *rdev)
    335  1.1  riastrad {
    336  1.1  riastrad 	struct rv7xx_power_info *pi = rv770_get_pi(rdev);
    337  1.1  riastrad 	u32 tmp;
    338  1.1  riastrad 
    339  1.1  riastrad #if defined(CONFIG_ACPI)
    340  1.1  riastrad 	radeon_acpi_pcie_notify_device_ready(rdev);
    341  1.1  riastrad #endif
    342  1.1  riastrad 
    343  1.1  riastrad 	tmp = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
    344  1.1  riastrad 
    345  1.1  riastrad 	if ((tmp & LC_OTHER_SIDE_EVER_SENT_GEN2) &&
    346  1.1  riastrad 	    (tmp & LC_OTHER_SIDE_SUPPORTS_GEN2))
    347  1.1  riastrad 		pi->pcie_gen2 = true;
    348  1.1  riastrad 	else
    349  1.1  riastrad 		pi->pcie_gen2 = false;
    350  1.1  riastrad 
    351  1.1  riastrad 	if (!pi->pcie_gen2)
    352  1.1  riastrad 		cypress_pcie_performance_request(rdev, PCIE_PERF_REQ_PECI_GEN2, true);
    353  1.1  riastrad 
    354  1.1  riastrad }
    355  1.1  riastrad 
    356  1.1  riastrad static enum radeon_pcie_gen cypress_get_maximum_link_speed(struct radeon_ps *radeon_state)
    357  1.1  riastrad {
    358  1.1  riastrad 	struct rv7xx_ps *state = rv770_get_ps(radeon_state);
    359  1.1  riastrad 
    360  1.1  riastrad 	if (state->high.flags & ATOM_PPLIB_R600_FLAGS_PCIEGEN2)
    361  1.1  riastrad 		return 1;
    362  1.1  riastrad 	return 0;
    363  1.1  riastrad }
    364  1.1  riastrad 
    365  1.1  riastrad void cypress_notify_link_speed_change_after_state_change(struct radeon_device *rdev,
    366  1.1  riastrad 							 struct radeon_ps *radeon_new_state,
    367  1.1  riastrad 							 struct radeon_ps *radeon_current_state)
    368  1.1  riastrad {
    369  1.1  riastrad 	enum radeon_pcie_gen pcie_link_speed_target =
    370  1.1  riastrad 		cypress_get_maximum_link_speed(radeon_new_state);
    371  1.1  riastrad 	enum radeon_pcie_gen pcie_link_speed_current =
    372  1.1  riastrad 		cypress_get_maximum_link_speed(radeon_current_state);
    373  1.1  riastrad 	u8 request;
    374  1.1  riastrad 
    375  1.1  riastrad 	if (pcie_link_speed_target < pcie_link_speed_current) {
    376  1.1  riastrad 		if (pcie_link_speed_target == RADEON_PCIE_GEN1)
    377  1.1  riastrad 			request = PCIE_PERF_REQ_PECI_GEN1;
    378  1.1  riastrad 		else if (pcie_link_speed_target == RADEON_PCIE_GEN2)
    379  1.1  riastrad 			request = PCIE_PERF_REQ_PECI_GEN2;
    380  1.1  riastrad 		else
    381  1.1  riastrad 			request = PCIE_PERF_REQ_PECI_GEN3;
    382  1.1  riastrad 
    383  1.1  riastrad 		cypress_pcie_performance_request(rdev, request, false);
    384  1.1  riastrad 	}
    385  1.1  riastrad }
    386  1.1  riastrad 
    387  1.1  riastrad void cypress_notify_link_speed_change_before_state_change(struct radeon_device *rdev,
    388  1.1  riastrad 							  struct radeon_ps *radeon_new_state,
    389  1.1  riastrad 							  struct radeon_ps *radeon_current_state)
    390  1.1  riastrad {
    391  1.1  riastrad 	enum radeon_pcie_gen pcie_link_speed_target =
    392  1.1  riastrad 		cypress_get_maximum_link_speed(radeon_new_state);
    393  1.1  riastrad 	enum radeon_pcie_gen pcie_link_speed_current =
    394  1.1  riastrad 		cypress_get_maximum_link_speed(radeon_current_state);
    395  1.1  riastrad 	u8 request;
    396  1.1  riastrad 
    397  1.1  riastrad 	if (pcie_link_speed_target > pcie_link_speed_current) {
    398  1.1  riastrad 		if (pcie_link_speed_target == RADEON_PCIE_GEN1)
    399  1.1  riastrad 			request = PCIE_PERF_REQ_PECI_GEN1;
    400  1.1  riastrad 		else if (pcie_link_speed_target == RADEON_PCIE_GEN2)
    401  1.1  riastrad 			request = PCIE_PERF_REQ_PECI_GEN2;
    402  1.1  riastrad 		else
    403  1.1  riastrad 			request = PCIE_PERF_REQ_PECI_GEN3;
    404  1.1  riastrad 
    405  1.1  riastrad 		cypress_pcie_performance_request(rdev, request, false);
    406  1.1  riastrad 	}
    407  1.1  riastrad }
    408  1.1  riastrad 
    409  1.1  riastrad static int cypress_populate_voltage_value(struct radeon_device *rdev,
    410  1.1  riastrad 					  struct atom_voltage_table *table,
    411  1.1  riastrad 					  u16 value, RV770_SMC_VOLTAGE_VALUE *voltage)
    412  1.1  riastrad {
    413  1.1  riastrad 	unsigned int i;
    414  1.1  riastrad 
    415  1.1  riastrad 	for (i = 0; i < table->count; i++) {
    416  1.1  riastrad 		if (value <= table->entries[i].value) {
    417  1.1  riastrad 			voltage->index = (u8)i;
    418  1.1  riastrad 			voltage->value = cpu_to_be16(table->entries[i].value);
    419  1.1  riastrad 			break;
    420  1.1  riastrad 		}
    421  1.1  riastrad 	}
    422  1.1  riastrad 
    423  1.1  riastrad 	if (i == table->count)
    424  1.1  riastrad 		return -EINVAL;
    425  1.1  riastrad 
    426  1.1  riastrad 	return 0;
    427  1.1  riastrad }
    428  1.1  riastrad 
    429  1.1  riastrad u8 cypress_get_strobe_mode_settings(struct radeon_device *rdev, u32 mclk)
    430  1.1  riastrad {
    431  1.1  riastrad 	struct rv7xx_power_info *pi = rv770_get_pi(rdev);
    432  1.1  riastrad 	u8 result = 0;
    433  1.1  riastrad 	bool strobe_mode = false;
    434  1.1  riastrad 
    435  1.1  riastrad 	if (pi->mem_gddr5) {
    436  1.1  riastrad 		if (mclk <= pi->mclk_strobe_mode_threshold)
    437  1.1  riastrad 			strobe_mode = true;
    438  1.1  riastrad 		result = cypress_get_mclk_frequency_ratio(rdev, mclk, strobe_mode);
    439  1.1  riastrad 
    440  1.1  riastrad 		if (strobe_mode)
    441  1.1  riastrad 			result |= SMC_STROBE_ENABLE;
    442  1.1  riastrad 	}
    443  1.1  riastrad 
    444  1.1  riastrad 	return result;
    445  1.1  riastrad }
    446  1.1  riastrad 
    447  1.1  riastrad u32 cypress_map_clkf_to_ibias(struct radeon_device *rdev, u32 clkf)
    448  1.1  riastrad {
    449  1.1  riastrad 	u32 ref_clk = rdev->clock.mpll.reference_freq;
    450  1.1  riastrad 	u32 vco = clkf * ref_clk;
    451  1.1  riastrad 
    452  1.1  riastrad 	/* 100 Mhz ref clk */
    453  1.1  riastrad 	if (ref_clk == 10000) {
    454  1.1  riastrad 		if (vco > 500000)
    455  1.1  riastrad 			return 0xC6;
    456  1.1  riastrad 		if (vco > 400000)
    457  1.1  riastrad 			return 0x9D;
    458  1.1  riastrad 		if (vco > 330000)
    459  1.1  riastrad 			return 0x6C;
    460  1.1  riastrad 		if (vco > 250000)
    461  1.1  riastrad 			return 0x2B;
    462  1.1  riastrad 		if (vco >  160000)
    463  1.1  riastrad 			return 0x5B;
    464  1.1  riastrad 		if (vco > 120000)
    465  1.1  riastrad 			return 0x0A;
    466  1.1  riastrad 		return 0x4B;
    467  1.1  riastrad 	}
    468  1.1  riastrad 
    469  1.1  riastrad 	/* 27 Mhz ref clk */
    470  1.1  riastrad 	if (vco > 250000)
    471  1.1  riastrad 		return 0x8B;
    472  1.1  riastrad 	if (vco > 200000)
    473  1.1  riastrad 		return 0xCC;
    474  1.1  riastrad 	if (vco > 150000)
    475  1.1  riastrad 		return 0x9B;
    476  1.1  riastrad 	return 0x6B;
    477  1.1  riastrad }
    478  1.1  riastrad 
    479  1.1  riastrad static int cypress_populate_mclk_value(struct radeon_device *rdev,
    480  1.1  riastrad 				       u32 engine_clock, u32 memory_clock,
    481  1.1  riastrad 				       RV7XX_SMC_MCLK_VALUE *mclk,
    482  1.1  riastrad 				       bool strobe_mode, bool dll_state_on)
    483  1.1  riastrad {
    484  1.1  riastrad 	struct rv7xx_power_info *pi = rv770_get_pi(rdev);
    485  1.1  riastrad 
    486  1.1  riastrad 	u32 mpll_ad_func_cntl =
    487  1.1  riastrad 		pi->clk_regs.rv770.mpll_ad_func_cntl;
    488  1.1  riastrad 	u32 mpll_ad_func_cntl_2 =
    489  1.1  riastrad 		pi->clk_regs.rv770.mpll_ad_func_cntl_2;
    490  1.1  riastrad 	u32 mpll_dq_func_cntl =
    491  1.1  riastrad 		pi->clk_regs.rv770.mpll_dq_func_cntl;
    492  1.1  riastrad 	u32 mpll_dq_func_cntl_2 =
    493  1.1  riastrad 		pi->clk_regs.rv770.mpll_dq_func_cntl_2;
    494  1.1  riastrad 	u32 mclk_pwrmgt_cntl =
    495  1.1  riastrad 		pi->clk_regs.rv770.mclk_pwrmgt_cntl;
    496  1.1  riastrad 	u32 dll_cntl =
    497  1.1  riastrad 		pi->clk_regs.rv770.dll_cntl;
    498  1.1  riastrad 	u32 mpll_ss1 = pi->clk_regs.rv770.mpll_ss1;
    499  1.1  riastrad 	u32 mpll_ss2 = pi->clk_regs.rv770.mpll_ss2;
    500  1.1  riastrad 	struct atom_clock_dividers dividers;
    501  1.1  riastrad 	u32 ibias;
    502  1.1  riastrad 	u32 dll_speed;
    503  1.1  riastrad 	int ret;
    504  1.1  riastrad 	u32 mc_seq_misc7;
    505  1.1  riastrad 
    506  1.1  riastrad 	ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_MEMORY_PLL_PARAM,
    507  1.1  riastrad 					     memory_clock, strobe_mode, &dividers);
    508  1.1  riastrad 	if (ret)
    509  1.1  riastrad 		return ret;
    510  1.1  riastrad 
    511  1.1  riastrad 	if (!strobe_mode) {
    512  1.1  riastrad 		mc_seq_misc7 = RREG32(MC_SEQ_MISC7);
    513  1.1  riastrad 
    514  1.1  riastrad 		if(mc_seq_misc7 & 0x8000000)
    515  1.1  riastrad 			dividers.post_div = 1;
    516  1.1  riastrad 	}
    517  1.1  riastrad 
    518  1.1  riastrad 	ibias = cypress_map_clkf_to_ibias(rdev, dividers.whole_fb_div);
    519  1.1  riastrad 
    520  1.1  riastrad 	mpll_ad_func_cntl &= ~(CLKR_MASK |
    521  1.1  riastrad 			       YCLK_POST_DIV_MASK |
    522  1.1  riastrad 			       CLKF_MASK |
    523  1.1  riastrad 			       CLKFRAC_MASK |
    524  1.1  riastrad 			       IBIAS_MASK);
    525  1.1  riastrad 	mpll_ad_func_cntl |= CLKR(dividers.ref_div);
    526  1.1  riastrad 	mpll_ad_func_cntl |= YCLK_POST_DIV(dividers.post_div);
    527  1.1  riastrad 	mpll_ad_func_cntl |= CLKF(dividers.whole_fb_div);
    528  1.1  riastrad 	mpll_ad_func_cntl |= CLKFRAC(dividers.frac_fb_div);
    529  1.1  riastrad 	mpll_ad_func_cntl |= IBIAS(ibias);
    530  1.1  riastrad 
    531  1.1  riastrad 	if (dividers.vco_mode)
    532  1.1  riastrad 		mpll_ad_func_cntl_2 |= VCO_MODE;
    533  1.1  riastrad 	else
    534  1.1  riastrad 		mpll_ad_func_cntl_2 &= ~VCO_MODE;
    535  1.1  riastrad 
    536  1.1  riastrad 	if (pi->mem_gddr5) {
    537  1.1  riastrad 		mpll_dq_func_cntl &= ~(CLKR_MASK |
    538  1.1  riastrad 				       YCLK_POST_DIV_MASK |
    539  1.1  riastrad 				       CLKF_MASK |
    540  1.1  riastrad 				       CLKFRAC_MASK |
    541  1.1  riastrad 				       IBIAS_MASK);
    542  1.1  riastrad 		mpll_dq_func_cntl |= CLKR(dividers.ref_div);
    543  1.1  riastrad 		mpll_dq_func_cntl |= YCLK_POST_DIV(dividers.post_div);
    544  1.1  riastrad 		mpll_dq_func_cntl |= CLKF(dividers.whole_fb_div);
    545  1.1  riastrad 		mpll_dq_func_cntl |= CLKFRAC(dividers.frac_fb_div);
    546  1.1  riastrad 		mpll_dq_func_cntl |= IBIAS(ibias);
    547  1.1  riastrad 
    548  1.1  riastrad 		if (strobe_mode)
    549  1.1  riastrad 			mpll_dq_func_cntl &= ~PDNB;
    550  1.1  riastrad 		else
    551  1.1  riastrad 			mpll_dq_func_cntl |= PDNB;
    552  1.1  riastrad 
    553  1.1  riastrad 		if (dividers.vco_mode)
    554  1.1  riastrad 			mpll_dq_func_cntl_2 |= VCO_MODE;
    555  1.1  riastrad 		else
    556  1.1  riastrad 			mpll_dq_func_cntl_2 &= ~VCO_MODE;
    557  1.1  riastrad 	}
    558  1.1  riastrad 
    559  1.1  riastrad 	if (pi->mclk_ss) {
    560  1.1  riastrad 		struct radeon_atom_ss ss;
    561  1.1  riastrad 		u32 vco_freq = memory_clock * dividers.post_div;
    562  1.1  riastrad 
    563  1.1  riastrad 		if (radeon_atombios_get_asic_ss_info(rdev, &ss,
    564  1.1  riastrad 						     ASIC_INTERNAL_MEMORY_SS, vco_freq)) {
    565  1.1  riastrad 			u32 reference_clock = rdev->clock.mpll.reference_freq;
    566  1.1  riastrad 			u32 decoded_ref = rv740_get_decoded_reference_divider(dividers.ref_div);
    567  1.1  riastrad 			u32 clk_s = reference_clock * 5 / (decoded_ref * ss.rate);
    568  1.1  riastrad 			u32 clk_v = ss.percentage *
    569  1.1  riastrad 				(0x4000 * dividers.whole_fb_div + 0x800 * dividers.frac_fb_div) / (clk_s * 625);
    570  1.1  riastrad 
    571  1.1  riastrad 			mpll_ss1 &= ~CLKV_MASK;
    572  1.1  riastrad 			mpll_ss1 |= CLKV(clk_v);
    573  1.1  riastrad 
    574  1.1  riastrad 			mpll_ss2 &= ~CLKS_MASK;
    575  1.1  riastrad 			mpll_ss2 |= CLKS(clk_s);
    576  1.1  riastrad 		}
    577  1.1  riastrad 	}
    578  1.1  riastrad 
    579  1.1  riastrad 	dll_speed = rv740_get_dll_speed(pi->mem_gddr5,
    580  1.1  riastrad 					memory_clock);
    581  1.1  riastrad 
    582  1.1  riastrad 	mclk_pwrmgt_cntl &= ~DLL_SPEED_MASK;
    583  1.1  riastrad 	mclk_pwrmgt_cntl |= DLL_SPEED(dll_speed);
    584  1.1  riastrad 	if (dll_state_on)
    585  1.1  riastrad 		mclk_pwrmgt_cntl |= (MRDCKA0_PDNB |
    586  1.1  riastrad 				     MRDCKA1_PDNB |
    587  1.1  riastrad 				     MRDCKB0_PDNB |
    588  1.1  riastrad 				     MRDCKB1_PDNB |
    589  1.1  riastrad 				     MRDCKC0_PDNB |
    590  1.1  riastrad 				     MRDCKC1_PDNB |
    591  1.1  riastrad 				     MRDCKD0_PDNB |
    592  1.1  riastrad 				     MRDCKD1_PDNB);
    593  1.1  riastrad 	else
    594  1.1  riastrad 		mclk_pwrmgt_cntl &= ~(MRDCKA0_PDNB |
    595  1.1  riastrad 				      MRDCKA1_PDNB |
    596  1.1  riastrad 				      MRDCKB0_PDNB |
    597  1.1  riastrad 				      MRDCKB1_PDNB |
    598  1.1  riastrad 				      MRDCKC0_PDNB |
    599  1.1  riastrad 				      MRDCKC1_PDNB |
    600  1.1  riastrad 				      MRDCKD0_PDNB |
    601  1.1  riastrad 				      MRDCKD1_PDNB);
    602  1.1  riastrad 
    603  1.1  riastrad 	mclk->mclk770.mclk_value = cpu_to_be32(memory_clock);
    604  1.1  riastrad 	mclk->mclk770.vMPLL_AD_FUNC_CNTL = cpu_to_be32(mpll_ad_func_cntl);
    605  1.1  riastrad 	mclk->mclk770.vMPLL_AD_FUNC_CNTL_2 = cpu_to_be32(mpll_ad_func_cntl_2);
    606  1.1  riastrad 	mclk->mclk770.vMPLL_DQ_FUNC_CNTL = cpu_to_be32(mpll_dq_func_cntl);
    607  1.1  riastrad 	mclk->mclk770.vMPLL_DQ_FUNC_CNTL_2 = cpu_to_be32(mpll_dq_func_cntl_2);
    608  1.1  riastrad 	mclk->mclk770.vMCLK_PWRMGT_CNTL = cpu_to_be32(mclk_pwrmgt_cntl);
    609  1.1  riastrad 	mclk->mclk770.vDLL_CNTL = cpu_to_be32(dll_cntl);
    610  1.1  riastrad 	mclk->mclk770.vMPLL_SS = cpu_to_be32(mpll_ss1);
    611  1.1  riastrad 	mclk->mclk770.vMPLL_SS2 = cpu_to_be32(mpll_ss2);
    612  1.1  riastrad 
    613  1.1  riastrad 	return 0;
    614  1.1  riastrad }
    615  1.1  riastrad 
    616  1.1  riastrad u8 cypress_get_mclk_frequency_ratio(struct radeon_device *rdev,
    617  1.1  riastrad 				    u32 memory_clock, bool strobe_mode)
    618  1.1  riastrad {
    619  1.1  riastrad 	u8 mc_para_index;
    620  1.1  riastrad 
    621  1.1  riastrad 	if (rdev->family >= CHIP_BARTS) {
    622  1.1  riastrad 		if (strobe_mode) {
    623  1.1  riastrad 			if (memory_clock < 10000)
    624  1.1  riastrad 				mc_para_index = 0x00;
    625  1.1  riastrad 			else if (memory_clock > 47500)
    626  1.1  riastrad 				mc_para_index = 0x0f;
    627  1.1  riastrad 			else
    628  1.1  riastrad 				mc_para_index = (u8)((memory_clock - 10000) / 2500);
    629  1.1  riastrad 		} else {
    630  1.1  riastrad 			if (memory_clock < 65000)
    631  1.1  riastrad 				mc_para_index = 0x00;
    632  1.1  riastrad 			else if (memory_clock > 135000)
    633  1.1  riastrad 				mc_para_index = 0x0f;
    634  1.1  riastrad 			else
    635  1.1  riastrad 				mc_para_index = (u8)((memory_clock - 60000) / 5000);
    636  1.1  riastrad 		}
    637  1.1  riastrad 	} else {
    638  1.1  riastrad 		if (strobe_mode) {
    639  1.1  riastrad 			if (memory_clock < 10000)
    640  1.1  riastrad 				mc_para_index = 0x00;
    641  1.1  riastrad 			else if (memory_clock > 47500)
    642  1.1  riastrad 				mc_para_index = 0x0f;
    643  1.1  riastrad 			else
    644  1.1  riastrad 				mc_para_index = (u8)((memory_clock - 10000) / 2500);
    645  1.1  riastrad 		} else {
    646  1.1  riastrad 			if (memory_clock < 40000)
    647  1.1  riastrad 				mc_para_index = 0x00;
    648  1.1  riastrad 			else if (memory_clock > 115000)
    649  1.1  riastrad 				mc_para_index = 0x0f;
    650  1.1  riastrad 			else
    651  1.1  riastrad 				mc_para_index = (u8)((memory_clock - 40000) / 5000);
    652  1.1  riastrad 		}
    653  1.1  riastrad 	}
    654  1.1  riastrad 	return mc_para_index;
    655  1.1  riastrad }
    656  1.1  riastrad 
    657  1.1  riastrad static int cypress_populate_mvdd_value(struct radeon_device *rdev,
    658  1.1  riastrad 				       u32 mclk,
    659  1.1  riastrad 				       RV770_SMC_VOLTAGE_VALUE *voltage)
    660  1.1  riastrad {
    661  1.1  riastrad 	struct rv7xx_power_info *pi = rv770_get_pi(rdev);
    662  1.1  riastrad 	struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
    663  1.1  riastrad 
    664  1.1  riastrad 	if (!pi->mvdd_control) {
    665  1.1  riastrad 		voltage->index = eg_pi->mvdd_high_index;
    666  1.1  riastrad 		voltage->value = cpu_to_be16(MVDD_HIGH_VALUE);
    667  1.1  riastrad 		return 0;
    668  1.1  riastrad 	}
    669  1.1  riastrad 
    670  1.1  riastrad 	if (mclk <= pi->mvdd_split_frequency) {
    671  1.1  riastrad 		voltage->index = eg_pi->mvdd_low_index;
    672  1.1  riastrad 		voltage->value = cpu_to_be16(MVDD_LOW_VALUE);
    673  1.1  riastrad 	} else {
    674  1.1  riastrad 		voltage->index = eg_pi->mvdd_high_index;
    675  1.1  riastrad 		voltage->value = cpu_to_be16(MVDD_HIGH_VALUE);
    676  1.1  riastrad 	}
    677  1.1  riastrad 
    678  1.1  riastrad 	return 0;
    679  1.1  riastrad }
    680  1.1  riastrad 
    681  1.1  riastrad int cypress_convert_power_level_to_smc(struct radeon_device *rdev,
    682  1.1  riastrad 				       struct rv7xx_pl *pl,
    683  1.1  riastrad 				       RV770_SMC_HW_PERFORMANCE_LEVEL *level,
    684  1.1  riastrad 				       u8 watermark_level)
    685  1.1  riastrad {
    686  1.1  riastrad 	struct rv7xx_power_info *pi = rv770_get_pi(rdev);
    687  1.1  riastrad 	struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
    688  1.1  riastrad 	int ret;
    689  1.1  riastrad 	bool dll_state_on;
    690  1.1  riastrad 
    691  1.1  riastrad 	level->gen2PCIE = pi->pcie_gen2 ?
    692  1.1  riastrad 		((pl->flags & ATOM_PPLIB_R600_FLAGS_PCIEGEN2) ? 1 : 0) : 0;
    693  1.1  riastrad 	level->gen2XSP  = (pl->flags & ATOM_PPLIB_R600_FLAGS_PCIEGEN2) ? 1 : 0;
    694  1.1  riastrad 	level->backbias = (pl->flags & ATOM_PPLIB_R600_FLAGS_BACKBIASENABLE) ? 1 : 0;
    695  1.1  riastrad 	level->displayWatermark = watermark_level;
    696  1.1  riastrad 
    697  1.1  riastrad 	ret = rv740_populate_sclk_value(rdev, pl->sclk, &level->sclk);
    698  1.1  riastrad 	if (ret)
    699  1.1  riastrad 		return ret;
    700  1.1  riastrad 
    701  1.1  riastrad 	level->mcFlags =  0;
    702  1.1  riastrad 	if (pi->mclk_stutter_mode_threshold &&
    703  1.1  riastrad 	    (pl->mclk <= pi->mclk_stutter_mode_threshold) &&
    704  1.1  riastrad 	    !eg_pi->uvd_enabled) {
    705  1.1  riastrad 		level->mcFlags |= SMC_MC_STUTTER_EN;
    706  1.1  riastrad 		if (eg_pi->sclk_deep_sleep)
    707  1.1  riastrad 			level->stateFlags |= PPSMC_STATEFLAG_AUTO_PULSE_SKIP;
    708  1.1  riastrad 		else
    709  1.1  riastrad 			level->stateFlags &= ~PPSMC_STATEFLAG_AUTO_PULSE_SKIP;
    710  1.1  riastrad 	}
    711  1.1  riastrad 
    712  1.1  riastrad 	if (pi->mem_gddr5) {
    713  1.1  riastrad 		if (pl->mclk > pi->mclk_edc_enable_threshold)
    714  1.1  riastrad 			level->mcFlags |= SMC_MC_EDC_RD_FLAG;
    715  1.1  riastrad 
    716  1.1  riastrad 		if (pl->mclk > eg_pi->mclk_edc_wr_enable_threshold)
    717  1.1  riastrad 			level->mcFlags |= SMC_MC_EDC_WR_FLAG;
    718  1.1  riastrad 
    719  1.1  riastrad 		level->strobeMode = cypress_get_strobe_mode_settings(rdev, pl->mclk);
    720  1.1  riastrad 
    721  1.1  riastrad 		if (level->strobeMode & SMC_STROBE_ENABLE) {
    722  1.1  riastrad 			if (cypress_get_mclk_frequency_ratio(rdev, pl->mclk, true) >=
    723  1.1  riastrad 			    ((RREG32(MC_SEQ_MISC7) >> 16) & 0xf))
    724  1.1  riastrad 				dll_state_on = ((RREG32(MC_SEQ_MISC5) >> 1) & 0x1) ? true : false;
    725  1.1  riastrad 			else
    726  1.1  riastrad 				dll_state_on = ((RREG32(MC_SEQ_MISC6) >> 1) & 0x1) ? true : false;
    727  1.1  riastrad 		} else
    728  1.1  riastrad 			dll_state_on = eg_pi->dll_default_on;
    729  1.1  riastrad 
    730  1.1  riastrad 		ret = cypress_populate_mclk_value(rdev,
    731  1.1  riastrad 						  pl->sclk,
    732  1.1  riastrad 						  pl->mclk,
    733  1.1  riastrad 						  &level->mclk,
    734  1.1  riastrad 						  (level->strobeMode & SMC_STROBE_ENABLE) != 0,
    735  1.1  riastrad 						  dll_state_on);
    736  1.1  riastrad 	} else {
    737  1.1  riastrad 		ret = cypress_populate_mclk_value(rdev,
    738  1.1  riastrad 						  pl->sclk,
    739  1.1  riastrad 						  pl->mclk,
    740  1.1  riastrad 						  &level->mclk,
    741  1.1  riastrad 						  true,
    742  1.1  riastrad 						  true);
    743  1.1  riastrad 	}
    744  1.1  riastrad 	if (ret)
    745  1.1  riastrad 		return ret;
    746  1.1  riastrad 
    747  1.1  riastrad 	ret = cypress_populate_voltage_value(rdev,
    748  1.1  riastrad 					     &eg_pi->vddc_voltage_table,
    749  1.1  riastrad 					     pl->vddc,
    750  1.1  riastrad 					     &level->vddc);
    751  1.1  riastrad 	if (ret)
    752  1.1  riastrad 		return ret;
    753  1.1  riastrad 
    754  1.1  riastrad 	if (eg_pi->vddci_control) {
    755  1.1  riastrad 		ret = cypress_populate_voltage_value(rdev,
    756  1.1  riastrad 						     &eg_pi->vddci_voltage_table,
    757  1.1  riastrad 						     pl->vddci,
    758  1.1  riastrad 						     &level->vddci);
    759  1.1  riastrad 		if (ret)
    760  1.1  riastrad 			return ret;
    761  1.1  riastrad 	}
    762  1.1  riastrad 
    763  1.1  riastrad 	ret = cypress_populate_mvdd_value(rdev, pl->mclk, &level->mvdd);
    764  1.1  riastrad 
    765  1.1  riastrad 	return ret;
    766  1.1  riastrad }
    767  1.1  riastrad 
    768  1.1  riastrad static int cypress_convert_power_state_to_smc(struct radeon_device *rdev,
    769  1.1  riastrad 					      struct radeon_ps *radeon_state,
    770  1.1  riastrad 					      RV770_SMC_SWSTATE *smc_state)
    771  1.1  riastrad {
    772  1.1  riastrad 	struct rv7xx_ps *state = rv770_get_ps(radeon_state);
    773  1.1  riastrad 	struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
    774  1.1  riastrad 	int ret;
    775  1.1  riastrad 
    776  1.1  riastrad 	if (!(radeon_state->caps & ATOM_PPLIB_DISALLOW_ON_DC))
    777  1.1  riastrad 		smc_state->flags |= PPSMC_SWSTATE_FLAG_DC;
    778  1.1  riastrad 
    779  1.1  riastrad 	ret = cypress_convert_power_level_to_smc(rdev,
    780  1.1  riastrad 						 &state->low,
    781  1.1  riastrad 						 &smc_state->levels[0],
    782  1.1  riastrad 						 PPSMC_DISPLAY_WATERMARK_LOW);
    783  1.1  riastrad 	if (ret)
    784  1.1  riastrad 		return ret;
    785  1.1  riastrad 
    786  1.1  riastrad 	ret = cypress_convert_power_level_to_smc(rdev,
    787  1.1  riastrad 						 &state->medium,
    788  1.1  riastrad 						 &smc_state->levels[1],
    789  1.1  riastrad 						 PPSMC_DISPLAY_WATERMARK_LOW);
    790  1.1  riastrad 	if (ret)
    791  1.1  riastrad 		return ret;
    792  1.1  riastrad 
    793  1.1  riastrad 	ret = cypress_convert_power_level_to_smc(rdev,
    794  1.1  riastrad 						 &state->high,
    795  1.1  riastrad 						 &smc_state->levels[2],
    796  1.1  riastrad 						 PPSMC_DISPLAY_WATERMARK_HIGH);
    797  1.1  riastrad 	if (ret)
    798  1.1  riastrad 		return ret;
    799  1.1  riastrad 
    800  1.1  riastrad 	smc_state->levels[0].arbValue = MC_CG_ARB_FREQ_F1;
    801  1.1  riastrad 	smc_state->levels[1].arbValue = MC_CG_ARB_FREQ_F2;
    802  1.1  riastrad 	smc_state->levels[2].arbValue = MC_CG_ARB_FREQ_F3;
    803  1.1  riastrad 
    804  1.1  riastrad 	if (eg_pi->dynamic_ac_timing) {
    805  1.1  riastrad 		smc_state->levels[0].ACIndex = 2;
    806  1.1  riastrad 		smc_state->levels[1].ACIndex = 3;
    807  1.1  riastrad 		smc_state->levels[2].ACIndex = 4;
    808  1.1  riastrad 	} else {
    809  1.1  riastrad 		smc_state->levels[0].ACIndex = 0;
    810  1.1  riastrad 		smc_state->levels[1].ACIndex = 0;
    811  1.1  riastrad 		smc_state->levels[2].ACIndex = 0;
    812  1.1  riastrad 	}
    813  1.1  riastrad 
    814  1.1  riastrad 	rv770_populate_smc_sp(rdev, radeon_state, smc_state);
    815  1.1  riastrad 
    816  1.1  riastrad 	return rv770_populate_smc_t(rdev, radeon_state, smc_state);
    817  1.1  riastrad }
    818  1.1  riastrad 
    819  1.1  riastrad static void cypress_convert_mc_registers(struct evergreen_mc_reg_entry *entry,
    820  1.1  riastrad 					 SMC_Evergreen_MCRegisterSet *data,
    821  1.1  riastrad 					 u32 num_entries, u32 valid_flag)
    822  1.1  riastrad {
    823  1.1  riastrad 	u32 i, j;
    824  1.1  riastrad 
    825  1.1  riastrad 	for (i = 0, j = 0; j < num_entries; j++) {
    826  1.1  riastrad 		if (valid_flag & (1 << j)) {
    827  1.1  riastrad 			data->value[i] = cpu_to_be32(entry->mc_data[j]);
    828  1.1  riastrad 			i++;
    829  1.1  riastrad 		}
    830  1.1  riastrad 	}
    831  1.1  riastrad }
    832  1.1  riastrad 
    833  1.1  riastrad static void cypress_convert_mc_reg_table_entry_to_smc(struct radeon_device *rdev,
    834  1.1  riastrad 						      struct rv7xx_pl *pl,
    835  1.1  riastrad 						      SMC_Evergreen_MCRegisterSet *mc_reg_table_data)
    836  1.1  riastrad {
    837  1.1  riastrad 	struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
    838  1.1  riastrad 	u32 i = 0;
    839  1.1  riastrad 
    840  1.1  riastrad 	for (i = 0; i < eg_pi->mc_reg_table.num_entries; i++) {
    841  1.1  riastrad 		if (pl->mclk <=
    842  1.1  riastrad 		    eg_pi->mc_reg_table.mc_reg_table_entry[i].mclk_max)
    843  1.1  riastrad 			break;
    844  1.1  riastrad 	}
    845  1.1  riastrad 
    846  1.1  riastrad 	if ((i == eg_pi->mc_reg_table.num_entries) && (i > 0))
    847  1.1  riastrad 		--i;
    848  1.1  riastrad 
    849  1.1  riastrad 	cypress_convert_mc_registers(&eg_pi->mc_reg_table.mc_reg_table_entry[i],
    850  1.1  riastrad 				     mc_reg_table_data,
    851  1.1  riastrad 				     eg_pi->mc_reg_table.last,
    852  1.1  riastrad 				     eg_pi->mc_reg_table.valid_flag);
    853  1.1  riastrad }
    854  1.1  riastrad 
    855  1.1  riastrad static void cypress_convert_mc_reg_table_to_smc(struct radeon_device *rdev,
    856  1.1  riastrad 						struct radeon_ps *radeon_state,
    857  1.1  riastrad 						SMC_Evergreen_MCRegisters *mc_reg_table)
    858  1.1  riastrad {
    859  1.1  riastrad 	struct rv7xx_ps *state = rv770_get_ps(radeon_state);
    860  1.1  riastrad 
    861  1.1  riastrad 	cypress_convert_mc_reg_table_entry_to_smc(rdev,
    862  1.1  riastrad 						  &state->low,
    863  1.1  riastrad 						  &mc_reg_table->data[2]);
    864  1.1  riastrad 	cypress_convert_mc_reg_table_entry_to_smc(rdev,
    865  1.1  riastrad 						  &state->medium,
    866  1.1  riastrad 						  &mc_reg_table->data[3]);
    867  1.1  riastrad 	cypress_convert_mc_reg_table_entry_to_smc(rdev,
    868  1.1  riastrad 						  &state->high,
    869  1.1  riastrad 						  &mc_reg_table->data[4]);
    870  1.1  riastrad }
    871  1.1  riastrad 
    872  1.1  riastrad int cypress_upload_sw_state(struct radeon_device *rdev,
    873  1.1  riastrad 			    struct radeon_ps *radeon_new_state)
    874  1.1  riastrad {
    875  1.1  riastrad 	struct rv7xx_power_info *pi = rv770_get_pi(rdev);
    876  1.1  riastrad 	u16 address = pi->state_table_start +
    877  1.1  riastrad 		offsetof(RV770_SMC_STATETABLE, driverState);
    878  1.1  riastrad 	RV770_SMC_SWSTATE state = { 0 };
    879  1.1  riastrad 	int ret;
    880  1.1  riastrad 
    881  1.1  riastrad 	ret = cypress_convert_power_state_to_smc(rdev, radeon_new_state, &state);
    882  1.1  riastrad 	if (ret)
    883  1.1  riastrad 		return ret;
    884  1.1  riastrad 
    885  1.1  riastrad 	return rv770_copy_bytes_to_smc(rdev, address, (u8 *)&state,
    886  1.1  riastrad 				    sizeof(RV770_SMC_SWSTATE),
    887  1.1  riastrad 				    pi->sram_end);
    888  1.1  riastrad }
    889  1.1  riastrad 
    890  1.1  riastrad int cypress_upload_mc_reg_table(struct radeon_device *rdev,
    891  1.1  riastrad 				struct radeon_ps *radeon_new_state)
    892  1.1  riastrad {
    893  1.1  riastrad 	struct rv7xx_power_info *pi = rv770_get_pi(rdev);
    894  1.1  riastrad 	struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
    895  1.1  riastrad 	SMC_Evergreen_MCRegisters mc_reg_table = { 0 };
    896  1.1  riastrad 	u16 address;
    897  1.1  riastrad 
    898  1.1  riastrad 	cypress_convert_mc_reg_table_to_smc(rdev, radeon_new_state, &mc_reg_table);
    899  1.1  riastrad 
    900  1.1  riastrad 	address = eg_pi->mc_reg_table_start +
    901  1.1  riastrad 		(u16)offsetof(SMC_Evergreen_MCRegisters, data[2]);
    902  1.1  riastrad 
    903  1.1  riastrad 	return rv770_copy_bytes_to_smc(rdev, address,
    904  1.1  riastrad 				       (u8 *)&mc_reg_table.data[2],
    905  1.1  riastrad 				       sizeof(SMC_Evergreen_MCRegisterSet) * 3,
    906  1.1  riastrad 				       pi->sram_end);
    907  1.1  riastrad }
    908  1.1  riastrad 
    909  1.1  riastrad u32 cypress_calculate_burst_time(struct radeon_device *rdev,
    910  1.1  riastrad 				 u32 engine_clock, u32 memory_clock)
    911  1.1  riastrad {
    912  1.1  riastrad 	struct rv7xx_power_info *pi = rv770_get_pi(rdev);
    913  1.1  riastrad 	u32 multiplier = pi->mem_gddr5 ? 1 : 2;
    914  1.1  riastrad 	u32 result = (4 * multiplier * engine_clock) / (memory_clock / 2);
    915  1.1  riastrad 	u32 burst_time;
    916  1.1  riastrad 
    917  1.1  riastrad 	if (result <= 4)
    918  1.1  riastrad 		burst_time = 0;
    919  1.1  riastrad 	else if (result < 8)
    920  1.1  riastrad 		burst_time = result - 4;
    921  1.1  riastrad 	else {
    922  1.1  riastrad 		burst_time = result / 2 ;
    923  1.1  riastrad 		if (burst_time > 18)
    924  1.1  riastrad 			burst_time = 18;
    925  1.1  riastrad 	}
    926  1.1  riastrad 
    927  1.1  riastrad 	return burst_time;
    928  1.1  riastrad }
    929  1.1  riastrad 
    930  1.1  riastrad void cypress_program_memory_timing_parameters(struct radeon_device *rdev,
    931  1.1  riastrad 					      struct radeon_ps *radeon_new_state)
    932  1.1  riastrad {
    933  1.1  riastrad 	struct rv7xx_ps *new_state = rv770_get_ps(radeon_new_state);
    934  1.1  riastrad 	u32 mc_arb_burst_time = RREG32(MC_ARB_BURST_TIME);
    935  1.1  riastrad 
    936  1.1  riastrad 	mc_arb_burst_time &= ~(STATE1_MASK | STATE2_MASK | STATE3_MASK);
    937  1.1  riastrad 
    938  1.1  riastrad 	mc_arb_burst_time |= STATE1(cypress_calculate_burst_time(rdev,
    939  1.1  riastrad 								 new_state->low.sclk,
    940  1.1  riastrad 								 new_state->low.mclk));
    941  1.1  riastrad 	mc_arb_burst_time |= STATE2(cypress_calculate_burst_time(rdev,
    942  1.1  riastrad 								 new_state->medium.sclk,
    943  1.1  riastrad 								 new_state->medium.mclk));
    944  1.1  riastrad 	mc_arb_burst_time |= STATE3(cypress_calculate_burst_time(rdev,
    945  1.1  riastrad 								 new_state->high.sclk,
    946  1.1  riastrad 								 new_state->high.mclk));
    947  1.1  riastrad 
    948  1.1  riastrad 	rv730_program_memory_timing_parameters(rdev, radeon_new_state);
    949  1.1  riastrad 
    950  1.1  riastrad 	WREG32(MC_ARB_BURST_TIME, mc_arb_burst_time);
    951  1.1  riastrad }
    952  1.1  riastrad 
    953  1.1  riastrad static void cypress_populate_mc_reg_addresses(struct radeon_device *rdev,
    954  1.1  riastrad 					      SMC_Evergreen_MCRegisters *mc_reg_table)
    955  1.1  riastrad {
    956  1.1  riastrad 	struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
    957  1.1  riastrad 	u32 i, j;
    958  1.1  riastrad 
    959  1.1  riastrad 	for (i = 0, j = 0; j < eg_pi->mc_reg_table.last; j++) {
    960  1.1  riastrad 		if (eg_pi->mc_reg_table.valid_flag & (1 << j)) {
    961  1.1  riastrad 			mc_reg_table->address[i].s0 =
    962  1.1  riastrad 				cpu_to_be16(eg_pi->mc_reg_table.mc_reg_address[j].s0);
    963  1.1  riastrad 			mc_reg_table->address[i].s1 =
    964  1.1  riastrad 				cpu_to_be16(eg_pi->mc_reg_table.mc_reg_address[j].s1);
    965  1.1  riastrad 			i++;
    966  1.1  riastrad 		}
    967  1.1  riastrad 	}
    968  1.1  riastrad 
    969  1.1  riastrad 	mc_reg_table->last = (u8)i;
    970  1.1  riastrad }
    971  1.1  riastrad 
    972  1.1  riastrad static void cypress_set_mc_reg_address_table(struct radeon_device *rdev)
    973  1.1  riastrad {
    974  1.1  riastrad 	struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
    975  1.1  riastrad 	u32 i = 0;
    976  1.1  riastrad 
    977  1.1  riastrad 	eg_pi->mc_reg_table.mc_reg_address[i].s0 = MC_SEQ_RAS_TIMING_LP >> 2;
    978  1.1  riastrad 	eg_pi->mc_reg_table.mc_reg_address[i].s1 = MC_SEQ_RAS_TIMING >> 2;
    979  1.1  riastrad 	i++;
    980  1.1  riastrad 
    981  1.1  riastrad 	eg_pi->mc_reg_table.mc_reg_address[i].s0 = MC_SEQ_CAS_TIMING_LP >> 2;
    982  1.1  riastrad 	eg_pi->mc_reg_table.mc_reg_address[i].s1 = MC_SEQ_CAS_TIMING >> 2;
    983  1.1  riastrad 	i++;
    984  1.1  riastrad 
    985  1.1  riastrad 	eg_pi->mc_reg_table.mc_reg_address[i].s0 = MC_SEQ_MISC_TIMING_LP >> 2;
    986  1.1  riastrad 	eg_pi->mc_reg_table.mc_reg_address[i].s1 = MC_SEQ_MISC_TIMING >> 2;
    987  1.1  riastrad 	i++;
    988  1.1  riastrad 
    989  1.1  riastrad 	eg_pi->mc_reg_table.mc_reg_address[i].s0 = MC_SEQ_MISC_TIMING2_LP >> 2;
    990  1.1  riastrad 	eg_pi->mc_reg_table.mc_reg_address[i].s1 = MC_SEQ_MISC_TIMING2 >> 2;
    991  1.1  riastrad 	i++;
    992  1.1  riastrad 
    993  1.1  riastrad 	eg_pi->mc_reg_table.mc_reg_address[i].s0 = MC_SEQ_RD_CTL_D0_LP >> 2;
    994  1.1  riastrad 	eg_pi->mc_reg_table.mc_reg_address[i].s1 = MC_SEQ_RD_CTL_D0 >> 2;
    995  1.1  riastrad 	i++;
    996  1.1  riastrad 
    997  1.1  riastrad 	eg_pi->mc_reg_table.mc_reg_address[i].s0 = MC_SEQ_RD_CTL_D1_LP >> 2;
    998  1.1  riastrad 	eg_pi->mc_reg_table.mc_reg_address[i].s1 = MC_SEQ_RD_CTL_D1 >> 2;
    999  1.1  riastrad 	i++;
   1000  1.1  riastrad 
   1001  1.1  riastrad 	eg_pi->mc_reg_table.mc_reg_address[i].s0 = MC_SEQ_WR_CTL_D0_LP >> 2;
   1002  1.1  riastrad 	eg_pi->mc_reg_table.mc_reg_address[i].s1 = MC_SEQ_WR_CTL_D0 >> 2;
   1003  1.1  riastrad 	i++;
   1004  1.1  riastrad 
   1005  1.1  riastrad 	eg_pi->mc_reg_table.mc_reg_address[i].s0 = MC_SEQ_WR_CTL_D1_LP >> 2;
   1006  1.1  riastrad 	eg_pi->mc_reg_table.mc_reg_address[i].s1 = MC_SEQ_WR_CTL_D1 >> 2;
   1007  1.1  riastrad 	i++;
   1008  1.1  riastrad 
   1009  1.1  riastrad 	eg_pi->mc_reg_table.mc_reg_address[i].s0 = MC_SEQ_PMG_CMD_EMRS_LP >> 2;
   1010  1.1  riastrad 	eg_pi->mc_reg_table.mc_reg_address[i].s1 = MC_PMG_CMD_EMRS >> 2;
   1011  1.1  riastrad 	i++;
   1012  1.1  riastrad 
   1013  1.1  riastrad 	eg_pi->mc_reg_table.mc_reg_address[i].s0 = MC_SEQ_PMG_CMD_MRS_LP >> 2;
   1014  1.1  riastrad 	eg_pi->mc_reg_table.mc_reg_address[i].s1 = MC_PMG_CMD_MRS >> 2;
   1015  1.1  riastrad 	i++;
   1016  1.1  riastrad 
   1017  1.1  riastrad 	eg_pi->mc_reg_table.mc_reg_address[i].s0 = MC_SEQ_PMG_CMD_MRS1_LP >> 2;
   1018  1.1  riastrad 	eg_pi->mc_reg_table.mc_reg_address[i].s1 = MC_PMG_CMD_MRS1 >> 2;
   1019  1.1  riastrad 	i++;
   1020  1.1  riastrad 
   1021  1.1  riastrad 	eg_pi->mc_reg_table.mc_reg_address[i].s0 = MC_SEQ_MISC1 >> 2;
   1022  1.1  riastrad 	eg_pi->mc_reg_table.mc_reg_address[i].s1 = MC_SEQ_MISC1 >> 2;
   1023  1.1  riastrad 	i++;
   1024  1.1  riastrad 
   1025  1.1  riastrad 	eg_pi->mc_reg_table.mc_reg_address[i].s0 = MC_SEQ_RESERVE_M >> 2;
   1026  1.1  riastrad 	eg_pi->mc_reg_table.mc_reg_address[i].s1 = MC_SEQ_RESERVE_M >> 2;
   1027  1.1  riastrad 	i++;
   1028  1.1  riastrad 
   1029  1.1  riastrad 	eg_pi->mc_reg_table.mc_reg_address[i].s0 = MC_SEQ_MISC3 >> 2;
   1030  1.1  riastrad 	eg_pi->mc_reg_table.mc_reg_address[i].s1 = MC_SEQ_MISC3 >> 2;
   1031  1.1  riastrad 	i++;
   1032  1.1  riastrad 
   1033  1.1  riastrad 	eg_pi->mc_reg_table.last = (u8)i;
   1034  1.1  riastrad }
   1035  1.1  riastrad 
   1036  1.1  riastrad static void cypress_retrieve_ac_timing_for_one_entry(struct radeon_device *rdev,
   1037  1.1  riastrad 						     struct evergreen_mc_reg_entry *entry)
   1038  1.1  riastrad {
   1039  1.1  riastrad 	struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
   1040  1.1  riastrad 	u32 i;
   1041  1.1  riastrad 
   1042  1.1  riastrad 	for (i = 0; i < eg_pi->mc_reg_table.last; i++)
   1043  1.1  riastrad 		entry->mc_data[i] =
   1044  1.1  riastrad 			RREG32(eg_pi->mc_reg_table.mc_reg_address[i].s1 << 2);
   1045  1.1  riastrad 
   1046  1.1  riastrad }
   1047  1.1  riastrad 
   1048  1.1  riastrad static void cypress_retrieve_ac_timing_for_all_ranges(struct radeon_device *rdev,
   1049  1.1  riastrad 						      struct atom_memory_clock_range_table *range_table)
   1050  1.1  riastrad {
   1051  1.1  riastrad 	struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
   1052  1.1  riastrad 	u32 i, j;
   1053  1.1  riastrad 
   1054  1.1  riastrad 	for (i = 0; i < range_table->num_entries; i++) {
   1055  1.1  riastrad 		eg_pi->mc_reg_table.mc_reg_table_entry[i].mclk_max =
   1056  1.1  riastrad 			range_table->mclk[i];
   1057  1.1  riastrad 		radeon_atom_set_ac_timing(rdev, range_table->mclk[i]);
   1058  1.1  riastrad 		cypress_retrieve_ac_timing_for_one_entry(rdev,
   1059  1.1  riastrad 							 &eg_pi->mc_reg_table.mc_reg_table_entry[i]);
   1060  1.1  riastrad 	}
   1061  1.1  riastrad 
   1062  1.1  riastrad 	eg_pi->mc_reg_table.num_entries = range_table->num_entries;
   1063  1.1  riastrad 	eg_pi->mc_reg_table.valid_flag = 0;
   1064  1.1  riastrad 
   1065  1.1  riastrad 	for (i = 0; i < eg_pi->mc_reg_table.last; i++) {
   1066  1.1  riastrad 		for (j = 1; j < range_table->num_entries; j++) {
   1067  1.1  riastrad 			if (eg_pi->mc_reg_table.mc_reg_table_entry[j-1].mc_data[i] !=
   1068  1.1  riastrad 			    eg_pi->mc_reg_table.mc_reg_table_entry[j].mc_data[i]) {
   1069  1.1  riastrad 				eg_pi->mc_reg_table.valid_flag |= (1 << i);
   1070  1.1  riastrad 				break;
   1071  1.1  riastrad 			}
   1072  1.1  riastrad 		}
   1073  1.1  riastrad 	}
   1074  1.1  riastrad }
   1075  1.1  riastrad 
   1076  1.1  riastrad static int cypress_initialize_mc_reg_table(struct radeon_device *rdev)
   1077  1.1  riastrad {
   1078  1.1  riastrad 	struct rv7xx_power_info *pi = rv770_get_pi(rdev);
   1079  1.1  riastrad 	u8 module_index = rv770_get_memory_module_index(rdev);
   1080  1.1  riastrad 	struct atom_memory_clock_range_table range_table = { 0 };
   1081  1.1  riastrad 	int ret;
   1082  1.1  riastrad 
   1083  1.1  riastrad 	ret = radeon_atom_get_mclk_range_table(rdev,
   1084  1.1  riastrad 					       pi->mem_gddr5,
   1085  1.1  riastrad 					       module_index, &range_table);
   1086  1.1  riastrad 	if (ret)
   1087  1.1  riastrad 		return ret;
   1088  1.1  riastrad 
   1089  1.1  riastrad 	cypress_retrieve_ac_timing_for_all_ranges(rdev, &range_table);
   1090  1.1  riastrad 
   1091  1.1  riastrad 	return 0;
   1092  1.1  riastrad }
   1093  1.1  riastrad 
   1094  1.1  riastrad static void cypress_wait_for_mc_sequencer(struct radeon_device *rdev, u8 value)
   1095  1.1  riastrad {
   1096  1.1  riastrad 	u32 i, j;
   1097  1.1  riastrad 	u32 channels = 2;
   1098  1.1  riastrad 
   1099  1.1  riastrad 	if ((rdev->family == CHIP_CYPRESS) ||
   1100  1.1  riastrad 	    (rdev->family == CHIP_HEMLOCK))
   1101  1.1  riastrad 		channels = 4;
   1102  1.1  riastrad 	else if (rdev->family == CHIP_CEDAR)
   1103  1.1  riastrad 		channels = 1;
   1104  1.1  riastrad 
   1105  1.1  riastrad 	for (i = 0; i < channels; i++) {
   1106  1.1  riastrad 		if ((rdev->family == CHIP_CYPRESS) ||
   1107  1.1  riastrad 		    (rdev->family == CHIP_HEMLOCK)) {
   1108  1.1  riastrad 			WREG32_P(MC_CONFIG_MCD, MC_RD_ENABLE_MCD(i), ~MC_RD_ENABLE_MCD_MASK);
   1109  1.1  riastrad 			WREG32_P(MC_CG_CONFIG_MCD, MC_RD_ENABLE_MCD(i), ~MC_RD_ENABLE_MCD_MASK);
   1110  1.1  riastrad 		} else {
   1111  1.1  riastrad 			WREG32_P(MC_CONFIG, MC_RD_ENABLE(i), ~MC_RD_ENABLE_MASK);
   1112  1.1  riastrad 			WREG32_P(MC_CG_CONFIG, MC_RD_ENABLE(i), ~MC_RD_ENABLE_MASK);
   1113  1.1  riastrad 		}
   1114  1.1  riastrad 		for (j = 0; j < rdev->usec_timeout; j++) {
   1115  1.1  riastrad 			if (((RREG32(MC_SEQ_CG) & CG_SEQ_RESP_MASK) >> CG_SEQ_RESP_SHIFT) == value)
   1116  1.1  riastrad 				break;
   1117  1.1  riastrad 			udelay(1);
   1118  1.1  riastrad 		}
   1119  1.1  riastrad 	}
   1120  1.1  riastrad }
   1121  1.1  riastrad 
   1122  1.1  riastrad static void cypress_force_mc_use_s1(struct radeon_device *rdev,
   1123  1.1  riastrad 				    struct radeon_ps *radeon_boot_state)
   1124  1.1  riastrad {
   1125  1.1  riastrad 	struct rv7xx_ps *boot_state = rv770_get_ps(radeon_boot_state);
   1126  1.1  riastrad 	u32 strobe_mode;
   1127  1.1  riastrad 	u32 mc_seq_cg;
   1128  1.1  riastrad 	int i;
   1129  1.1  riastrad 
   1130  1.1  riastrad 	if (RREG32(MC_SEQ_STATUS_M) & PMG_PWRSTATE)
   1131  1.1  riastrad 		return;
   1132  1.1  riastrad 
   1133  1.1  riastrad 	radeon_atom_set_ac_timing(rdev, boot_state->low.mclk);
   1134  1.1  riastrad 	radeon_mc_wait_for_idle(rdev);
   1135  1.1  riastrad 
   1136  1.1  riastrad 	if ((rdev->family == CHIP_CYPRESS) ||
   1137  1.1  riastrad 	    (rdev->family == CHIP_HEMLOCK)) {
   1138  1.1  riastrad 		WREG32(MC_CONFIG_MCD, 0xf);
   1139  1.1  riastrad 		WREG32(MC_CG_CONFIG_MCD, 0xf);
   1140  1.1  riastrad 	} else {
   1141  1.1  riastrad 		WREG32(MC_CONFIG, 0xf);
   1142  1.1  riastrad 		WREG32(MC_CG_CONFIG, 0xf);
   1143  1.1  riastrad 	}
   1144  1.1  riastrad 
   1145  1.1  riastrad 	for (i = 0; i < rdev->num_crtc; i++)
   1146  1.1  riastrad 		radeon_wait_for_vblank(rdev, i);
   1147  1.1  riastrad 
   1148  1.1  riastrad 	WREG32(MC_SEQ_CG, MC_CG_SEQ_YCLK_SUSPEND);
   1149  1.1  riastrad 	cypress_wait_for_mc_sequencer(rdev, MC_CG_SEQ_YCLK_SUSPEND);
   1150  1.1  riastrad 
   1151  1.1  riastrad 	strobe_mode = cypress_get_strobe_mode_settings(rdev,
   1152  1.1  riastrad 						       boot_state->low.mclk);
   1153  1.1  riastrad 
   1154  1.1  riastrad 	mc_seq_cg = CG_SEQ_REQ(MC_CG_SEQ_DRAMCONF_S1);
   1155  1.1  riastrad 	mc_seq_cg |= SEQ_CG_RESP(strobe_mode);
   1156  1.1  riastrad 	WREG32(MC_SEQ_CG, mc_seq_cg);
   1157  1.1  riastrad 
   1158  1.1  riastrad 	for (i = 0; i < rdev->usec_timeout; i++) {
   1159  1.1  riastrad 		if (RREG32(MC_SEQ_STATUS_M) & PMG_PWRSTATE)
   1160  1.1  riastrad 			break;
   1161  1.1  riastrad 		udelay(1);
   1162  1.1  riastrad 	}
   1163  1.1  riastrad 
   1164  1.1  riastrad 	mc_seq_cg &= ~CG_SEQ_REQ_MASK;
   1165  1.1  riastrad 	mc_seq_cg |= CG_SEQ_REQ(MC_CG_SEQ_YCLK_RESUME);
   1166  1.1  riastrad 	WREG32(MC_SEQ_CG, mc_seq_cg);
   1167  1.1  riastrad 
   1168  1.1  riastrad 	cypress_wait_for_mc_sequencer(rdev, MC_CG_SEQ_YCLK_RESUME);
   1169  1.1  riastrad }
   1170  1.1  riastrad 
   1171  1.1  riastrad static void cypress_copy_ac_timing_from_s1_to_s0(struct radeon_device *rdev)
   1172  1.1  riastrad {
   1173  1.1  riastrad 	struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
   1174  1.1  riastrad 	u32 value;
   1175  1.1  riastrad 	u32 i;
   1176  1.1  riastrad 
   1177  1.1  riastrad 	for (i = 0; i < eg_pi->mc_reg_table.last; i++) {
   1178  1.1  riastrad 		value = RREG32(eg_pi->mc_reg_table.mc_reg_address[i].s1 << 2);
   1179  1.1  riastrad 		WREG32(eg_pi->mc_reg_table.mc_reg_address[i].s0 << 2, value);
   1180  1.1  riastrad 	}
   1181  1.1  riastrad }
   1182  1.1  riastrad 
   1183  1.1  riastrad static void cypress_force_mc_use_s0(struct radeon_device *rdev,
   1184  1.1  riastrad 				    struct radeon_ps *radeon_boot_state)
   1185  1.1  riastrad {
   1186  1.1  riastrad 	struct rv7xx_ps *boot_state = rv770_get_ps(radeon_boot_state);
   1187  1.1  riastrad 	u32 strobe_mode;
   1188  1.1  riastrad 	u32 mc_seq_cg;
   1189  1.1  riastrad 	int i;
   1190  1.1  riastrad 
   1191  1.1  riastrad 	cypress_copy_ac_timing_from_s1_to_s0(rdev);
   1192  1.1  riastrad 	radeon_mc_wait_for_idle(rdev);
   1193  1.1  riastrad 
   1194  1.1  riastrad 	if ((rdev->family == CHIP_CYPRESS) ||
   1195  1.1  riastrad 	    (rdev->family == CHIP_HEMLOCK)) {
   1196  1.1  riastrad 		WREG32(MC_CONFIG_MCD, 0xf);
   1197  1.1  riastrad 		WREG32(MC_CG_CONFIG_MCD, 0xf);
   1198  1.1  riastrad 	} else {
   1199  1.1  riastrad 		WREG32(MC_CONFIG, 0xf);
   1200  1.1  riastrad 		WREG32(MC_CG_CONFIG, 0xf);
   1201  1.1  riastrad 	}
   1202  1.1  riastrad 
   1203  1.1  riastrad 	for (i = 0; i < rdev->num_crtc; i++)
   1204  1.1  riastrad 		radeon_wait_for_vblank(rdev, i);
   1205  1.1  riastrad 
   1206  1.1  riastrad 	WREG32(MC_SEQ_CG, MC_CG_SEQ_YCLK_SUSPEND);
   1207  1.1  riastrad 	cypress_wait_for_mc_sequencer(rdev, MC_CG_SEQ_YCLK_SUSPEND);
   1208  1.1  riastrad 
   1209  1.1  riastrad 	strobe_mode = cypress_get_strobe_mode_settings(rdev,
   1210  1.1  riastrad 						       boot_state->low.mclk);
   1211  1.1  riastrad 
   1212  1.1  riastrad 	mc_seq_cg = CG_SEQ_REQ(MC_CG_SEQ_DRAMCONF_S0);
   1213  1.1  riastrad 	mc_seq_cg |= SEQ_CG_RESP(strobe_mode);
   1214  1.1  riastrad 	WREG32(MC_SEQ_CG, mc_seq_cg);
   1215  1.1  riastrad 
   1216  1.1  riastrad 	for (i = 0; i < rdev->usec_timeout; i++) {
   1217  1.1  riastrad 		if (!(RREG32(MC_SEQ_STATUS_M) & PMG_PWRSTATE))
   1218  1.1  riastrad 			break;
   1219  1.1  riastrad 		udelay(1);
   1220  1.1  riastrad 	}
   1221  1.1  riastrad 
   1222  1.1  riastrad 	mc_seq_cg &= ~CG_SEQ_REQ_MASK;
   1223  1.1  riastrad 	mc_seq_cg |= CG_SEQ_REQ(MC_CG_SEQ_YCLK_RESUME);
   1224  1.1  riastrad 	WREG32(MC_SEQ_CG, mc_seq_cg);
   1225  1.1  riastrad 
   1226  1.1  riastrad 	cypress_wait_for_mc_sequencer(rdev, MC_CG_SEQ_YCLK_RESUME);
   1227  1.1  riastrad }
   1228  1.1  riastrad 
   1229  1.1  riastrad static int cypress_populate_initial_mvdd_value(struct radeon_device *rdev,
   1230  1.1  riastrad 					       RV770_SMC_VOLTAGE_VALUE *voltage)
   1231  1.1  riastrad {
   1232  1.1  riastrad 	struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
   1233  1.1  riastrad 
   1234  1.1  riastrad 	voltage->index = eg_pi->mvdd_high_index;
   1235  1.1  riastrad 	voltage->value = cpu_to_be16(MVDD_HIGH_VALUE);
   1236  1.1  riastrad 
   1237  1.1  riastrad 	return 0;
   1238  1.1  riastrad }
   1239  1.1  riastrad 
   1240  1.1  riastrad int cypress_populate_smc_initial_state(struct radeon_device *rdev,
   1241  1.1  riastrad 				       struct radeon_ps *radeon_initial_state,
   1242  1.1  riastrad 				       RV770_SMC_STATETABLE *table)
   1243  1.1  riastrad {
   1244  1.1  riastrad 	struct rv7xx_ps *initial_state = rv770_get_ps(radeon_initial_state);
   1245  1.1  riastrad 	struct rv7xx_power_info *pi = rv770_get_pi(rdev);
   1246  1.1  riastrad 	struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
   1247  1.1  riastrad 	u32 a_t;
   1248  1.1  riastrad 
   1249  1.1  riastrad 	table->initialState.levels[0].mclk.mclk770.vMPLL_AD_FUNC_CNTL =
   1250  1.1  riastrad 		cpu_to_be32(pi->clk_regs.rv770.mpll_ad_func_cntl);
   1251  1.1  riastrad 	table->initialState.levels[0].mclk.mclk770.vMPLL_AD_FUNC_CNTL_2 =
   1252  1.1  riastrad 		cpu_to_be32(pi->clk_regs.rv770.mpll_ad_func_cntl_2);
   1253  1.1  riastrad 	table->initialState.levels[0].mclk.mclk770.vMPLL_DQ_FUNC_CNTL =
   1254  1.1  riastrad 		cpu_to_be32(pi->clk_regs.rv770.mpll_dq_func_cntl);
   1255  1.1  riastrad 	table->initialState.levels[0].mclk.mclk770.vMPLL_DQ_FUNC_CNTL_2 =
   1256  1.1  riastrad 		cpu_to_be32(pi->clk_regs.rv770.mpll_dq_func_cntl_2);
   1257  1.1  riastrad 	table->initialState.levels[0].mclk.mclk770.vMCLK_PWRMGT_CNTL =
   1258  1.1  riastrad 		cpu_to_be32(pi->clk_regs.rv770.mclk_pwrmgt_cntl);
   1259  1.1  riastrad 	table->initialState.levels[0].mclk.mclk770.vDLL_CNTL =
   1260  1.1  riastrad 		cpu_to_be32(pi->clk_regs.rv770.dll_cntl);
   1261  1.1  riastrad 
   1262  1.1  riastrad 	table->initialState.levels[0].mclk.mclk770.vMPLL_SS =
   1263  1.1  riastrad 		cpu_to_be32(pi->clk_regs.rv770.mpll_ss1);
   1264  1.1  riastrad 	table->initialState.levels[0].mclk.mclk770.vMPLL_SS2 =
   1265  1.1  riastrad 		cpu_to_be32(pi->clk_regs.rv770.mpll_ss2);
   1266  1.1  riastrad 
   1267  1.1  riastrad 	table->initialState.levels[0].mclk.mclk770.mclk_value =
   1268  1.1  riastrad 		cpu_to_be32(initial_state->low.mclk);
   1269  1.1  riastrad 
   1270  1.1  riastrad 	table->initialState.levels[0].sclk.vCG_SPLL_FUNC_CNTL =
   1271  1.1  riastrad 		cpu_to_be32(pi->clk_regs.rv770.cg_spll_func_cntl);
   1272  1.1  riastrad 	table->initialState.levels[0].sclk.vCG_SPLL_FUNC_CNTL_2 =
   1273  1.1  riastrad 		cpu_to_be32(pi->clk_regs.rv770.cg_spll_func_cntl_2);
   1274  1.1  riastrad 	table->initialState.levels[0].sclk.vCG_SPLL_FUNC_CNTL_3 =
   1275  1.1  riastrad 		cpu_to_be32(pi->clk_regs.rv770.cg_spll_func_cntl_3);
   1276  1.1  riastrad 	table->initialState.levels[0].sclk.vCG_SPLL_SPREAD_SPECTRUM =
   1277  1.1  riastrad 		cpu_to_be32(pi->clk_regs.rv770.cg_spll_spread_spectrum);
   1278  1.1  riastrad 	table->initialState.levels[0].sclk.vCG_SPLL_SPREAD_SPECTRUM_2 =
   1279  1.1  riastrad 		cpu_to_be32(pi->clk_regs.rv770.cg_spll_spread_spectrum_2);
   1280  1.1  riastrad 
   1281  1.1  riastrad 	table->initialState.levels[0].sclk.sclk_value =
   1282  1.1  riastrad 		cpu_to_be32(initial_state->low.sclk);
   1283  1.1  riastrad 
   1284  1.1  riastrad 	table->initialState.levels[0].arbValue = MC_CG_ARB_FREQ_F0;
   1285  1.1  riastrad 
   1286  1.1  riastrad 	table->initialState.levels[0].ACIndex = 0;
   1287  1.1  riastrad 
   1288  1.1  riastrad 	cypress_populate_voltage_value(rdev,
   1289  1.1  riastrad 				       &eg_pi->vddc_voltage_table,
   1290  1.1  riastrad 				       initial_state->low.vddc,
   1291  1.1  riastrad 				       &table->initialState.levels[0].vddc);
   1292  1.1  riastrad 
   1293  1.1  riastrad 	if (eg_pi->vddci_control)
   1294  1.1  riastrad 		cypress_populate_voltage_value(rdev,
   1295  1.1  riastrad 					       &eg_pi->vddci_voltage_table,
   1296  1.1  riastrad 					       initial_state->low.vddci,
   1297  1.1  riastrad 					       &table->initialState.levels[0].vddci);
   1298  1.1  riastrad 
   1299  1.1  riastrad 	cypress_populate_initial_mvdd_value(rdev,
   1300  1.1  riastrad 					    &table->initialState.levels[0].mvdd);
   1301  1.1  riastrad 
   1302  1.1  riastrad 	a_t = CG_R(0xffff) | CG_L(0);
   1303  1.1  riastrad 	table->initialState.levels[0].aT = cpu_to_be32(a_t);
   1304  1.1  riastrad 
   1305  1.1  riastrad 	table->initialState.levels[0].bSP = cpu_to_be32(pi->dsp);
   1306  1.1  riastrad 
   1307  1.1  riastrad 
   1308  1.1  riastrad 	if (pi->boot_in_gen2)
   1309  1.1  riastrad 		table->initialState.levels[0].gen2PCIE = 1;
   1310  1.1  riastrad 	else
   1311  1.1  riastrad 		table->initialState.levels[0].gen2PCIE = 0;
   1312  1.1  riastrad 	if (initial_state->low.flags & ATOM_PPLIB_R600_FLAGS_PCIEGEN2)
   1313  1.1  riastrad 		table->initialState.levels[0].gen2XSP = 1;
   1314  1.1  riastrad 	else
   1315  1.1  riastrad 		table->initialState.levels[0].gen2XSP = 0;
   1316  1.1  riastrad 
   1317  1.1  riastrad 	if (pi->mem_gddr5) {
   1318  1.1  riastrad 		table->initialState.levels[0].strobeMode =
   1319  1.1  riastrad 			cypress_get_strobe_mode_settings(rdev,
   1320  1.1  riastrad 							 initial_state->low.mclk);
   1321  1.1  riastrad 
   1322  1.1  riastrad 		if (initial_state->low.mclk > pi->mclk_edc_enable_threshold)
   1323  1.1  riastrad 			table->initialState.levels[0].mcFlags = SMC_MC_EDC_RD_FLAG | SMC_MC_EDC_WR_FLAG;
   1324  1.1  riastrad 		else
   1325  1.1  riastrad 			table->initialState.levels[0].mcFlags =  0;
   1326  1.1  riastrad 	}
   1327  1.1  riastrad 
   1328  1.1  riastrad 	table->initialState.levels[1] = table->initialState.levels[0];
   1329  1.1  riastrad 	table->initialState.levels[2] = table->initialState.levels[0];
   1330  1.1  riastrad 
   1331  1.1  riastrad 	table->initialState.flags |= PPSMC_SWSTATE_FLAG_DC;
   1332  1.1  riastrad 
   1333  1.1  riastrad 	return 0;
   1334  1.1  riastrad }
   1335  1.1  riastrad 
   1336  1.1  riastrad int cypress_populate_smc_acpi_state(struct radeon_device *rdev,
   1337  1.1  riastrad 				    RV770_SMC_STATETABLE *table)
   1338  1.1  riastrad {
   1339  1.1  riastrad 	struct rv7xx_power_info *pi = rv770_get_pi(rdev);
   1340  1.1  riastrad 	struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
   1341  1.1  riastrad 	u32 mpll_ad_func_cntl =
   1342  1.1  riastrad 		pi->clk_regs.rv770.mpll_ad_func_cntl;
   1343  1.1  riastrad 	u32 mpll_ad_func_cntl_2 =
   1344  1.1  riastrad 		pi->clk_regs.rv770.mpll_ad_func_cntl_2;
   1345  1.1  riastrad 	u32 mpll_dq_func_cntl =
   1346  1.1  riastrad 		pi->clk_regs.rv770.mpll_dq_func_cntl;
   1347  1.1  riastrad 	u32 mpll_dq_func_cntl_2 =
   1348  1.1  riastrad 		pi->clk_regs.rv770.mpll_dq_func_cntl_2;
   1349  1.1  riastrad 	u32 spll_func_cntl =
   1350  1.1  riastrad 		pi->clk_regs.rv770.cg_spll_func_cntl;
   1351  1.1  riastrad 	u32 spll_func_cntl_2 =
   1352  1.1  riastrad 		pi->clk_regs.rv770.cg_spll_func_cntl_2;
   1353  1.1  riastrad 	u32 spll_func_cntl_3 =
   1354  1.1  riastrad 		pi->clk_regs.rv770.cg_spll_func_cntl_3;
   1355  1.1  riastrad 	u32 mclk_pwrmgt_cntl =
   1356  1.1  riastrad 		pi->clk_regs.rv770.mclk_pwrmgt_cntl;
   1357  1.1  riastrad 	u32 dll_cntl =
   1358  1.1  riastrad 		pi->clk_regs.rv770.dll_cntl;
   1359  1.1  riastrad 
   1360  1.1  riastrad 	table->ACPIState = table->initialState;
   1361  1.1  riastrad 
   1362  1.1  riastrad 	table->ACPIState.flags &= ~PPSMC_SWSTATE_FLAG_DC;
   1363  1.1  riastrad 
   1364  1.1  riastrad 	if (pi->acpi_vddc) {
   1365  1.1  riastrad 		cypress_populate_voltage_value(rdev,
   1366  1.1  riastrad 					       &eg_pi->vddc_voltage_table,
   1367  1.1  riastrad 					       pi->acpi_vddc,
   1368  1.1  riastrad 					       &table->ACPIState.levels[0].vddc);
   1369  1.1  riastrad 		if (pi->pcie_gen2) {
   1370  1.1  riastrad 			if (pi->acpi_pcie_gen2)
   1371  1.1  riastrad 				table->ACPIState.levels[0].gen2PCIE = 1;
   1372  1.1  riastrad 			else
   1373  1.1  riastrad 				table->ACPIState.levels[0].gen2PCIE = 0;
   1374  1.1  riastrad 		} else
   1375  1.1  riastrad 			table->ACPIState.levels[0].gen2PCIE = 0;
   1376  1.1  riastrad 		if (pi->acpi_pcie_gen2)
   1377  1.1  riastrad 			table->ACPIState.levels[0].gen2XSP = 1;
   1378  1.1  riastrad 		else
   1379  1.1  riastrad 			table->ACPIState.levels[0].gen2XSP = 0;
   1380  1.1  riastrad 	} else {
   1381  1.1  riastrad 		cypress_populate_voltage_value(rdev,
   1382  1.1  riastrad 					       &eg_pi->vddc_voltage_table,
   1383  1.1  riastrad 					       pi->min_vddc_in_table,
   1384  1.1  riastrad 					       &table->ACPIState.levels[0].vddc);
   1385  1.1  riastrad 		table->ACPIState.levels[0].gen2PCIE = 0;
   1386  1.1  riastrad 	}
   1387  1.1  riastrad 
   1388  1.1  riastrad 	if (eg_pi->acpi_vddci) {
   1389  1.1  riastrad 		if (eg_pi->vddci_control) {
   1390  1.1  riastrad 			cypress_populate_voltage_value(rdev,
   1391  1.1  riastrad 						       &eg_pi->vddci_voltage_table,
   1392  1.1  riastrad 						       eg_pi->acpi_vddci,
   1393  1.1  riastrad 						       &table->ACPIState.levels[0].vddci);
   1394  1.1  riastrad 		}
   1395  1.1  riastrad 	}
   1396  1.1  riastrad 
   1397  1.1  riastrad 	mpll_ad_func_cntl &= ~PDNB;
   1398  1.1  riastrad 
   1399  1.1  riastrad 	mpll_ad_func_cntl_2 |= BIAS_GEN_PDNB | RESET_EN;
   1400  1.1  riastrad 
   1401  1.1  riastrad 	if (pi->mem_gddr5)
   1402  1.1  riastrad 		mpll_dq_func_cntl &= ~PDNB;
   1403  1.1  riastrad 	mpll_dq_func_cntl_2 |= BIAS_GEN_PDNB | RESET_EN | BYPASS;
   1404  1.1  riastrad 
   1405  1.1  riastrad 	mclk_pwrmgt_cntl |= (MRDCKA0_RESET |
   1406  1.1  riastrad 			     MRDCKA1_RESET |
   1407  1.1  riastrad 			     MRDCKB0_RESET |
   1408  1.1  riastrad 			     MRDCKB1_RESET |
   1409  1.1  riastrad 			     MRDCKC0_RESET |
   1410  1.1  riastrad 			     MRDCKC1_RESET |
   1411  1.1  riastrad 			     MRDCKD0_RESET |
   1412  1.1  riastrad 			     MRDCKD1_RESET);
   1413  1.1  riastrad 
   1414  1.1  riastrad 	mclk_pwrmgt_cntl &= ~(MRDCKA0_PDNB |
   1415  1.1  riastrad 			      MRDCKA1_PDNB |
   1416  1.1  riastrad 			      MRDCKB0_PDNB |
   1417  1.1  riastrad 			      MRDCKB1_PDNB |
   1418  1.1  riastrad 			      MRDCKC0_PDNB |
   1419  1.1  riastrad 			      MRDCKC1_PDNB |
   1420  1.1  riastrad 			      MRDCKD0_PDNB |
   1421  1.1  riastrad 			      MRDCKD1_PDNB);
   1422  1.1  riastrad 
   1423  1.1  riastrad 	dll_cntl |= (MRDCKA0_BYPASS |
   1424  1.1  riastrad 		     MRDCKA1_BYPASS |
   1425  1.1  riastrad 		     MRDCKB0_BYPASS |
   1426  1.1  riastrad 		     MRDCKB1_BYPASS |
   1427  1.1  riastrad 		     MRDCKC0_BYPASS |
   1428  1.1  riastrad 		     MRDCKC1_BYPASS |
   1429  1.1  riastrad 		     MRDCKD0_BYPASS |
   1430  1.1  riastrad 		     MRDCKD1_BYPASS);
   1431  1.1  riastrad 
   1432  1.1  riastrad 	/* evergreen only */
   1433  1.1  riastrad 	if (rdev->family <= CHIP_HEMLOCK)
   1434  1.1  riastrad 		spll_func_cntl |= SPLL_RESET | SPLL_SLEEP | SPLL_BYPASS_EN;
   1435  1.1  riastrad 
   1436  1.1  riastrad 	spll_func_cntl_2 &= ~SCLK_MUX_SEL_MASK;
   1437  1.1  riastrad 	spll_func_cntl_2 |= SCLK_MUX_SEL(4);
   1438  1.1  riastrad 
   1439  1.1  riastrad 	table->ACPIState.levels[0].mclk.mclk770.vMPLL_AD_FUNC_CNTL =
   1440  1.1  riastrad 		cpu_to_be32(mpll_ad_func_cntl);
   1441  1.1  riastrad 	table->ACPIState.levels[0].mclk.mclk770.vMPLL_AD_FUNC_CNTL_2 =
   1442  1.1  riastrad 		cpu_to_be32(mpll_ad_func_cntl_2);
   1443  1.1  riastrad 	table->ACPIState.levels[0].mclk.mclk770.vMPLL_DQ_FUNC_CNTL =
   1444  1.1  riastrad 		cpu_to_be32(mpll_dq_func_cntl);
   1445  1.1  riastrad 	table->ACPIState.levels[0].mclk.mclk770.vMPLL_DQ_FUNC_CNTL_2 =
   1446  1.1  riastrad 		cpu_to_be32(mpll_dq_func_cntl_2);
   1447  1.1  riastrad 	table->ACPIState.levels[0].mclk.mclk770.vMCLK_PWRMGT_CNTL =
   1448  1.1  riastrad 		cpu_to_be32(mclk_pwrmgt_cntl);
   1449  1.1  riastrad 	table->ACPIState.levels[0].mclk.mclk770.vDLL_CNTL = cpu_to_be32(dll_cntl);
   1450  1.1  riastrad 
   1451  1.1  riastrad 	table->ACPIState.levels[0].mclk.mclk770.mclk_value = 0;
   1452  1.1  riastrad 
   1453  1.1  riastrad 	table->ACPIState.levels[0].sclk.vCG_SPLL_FUNC_CNTL =
   1454  1.1  riastrad 		cpu_to_be32(spll_func_cntl);
   1455  1.1  riastrad 	table->ACPIState.levels[0].sclk.vCG_SPLL_FUNC_CNTL_2 =
   1456  1.1  riastrad 		cpu_to_be32(spll_func_cntl_2);
   1457  1.1  riastrad 	table->ACPIState.levels[0].sclk.vCG_SPLL_FUNC_CNTL_3 =
   1458  1.1  riastrad 		cpu_to_be32(spll_func_cntl_3);
   1459  1.1  riastrad 
   1460  1.1  riastrad 	table->ACPIState.levels[0].sclk.sclk_value = 0;
   1461  1.1  riastrad 
   1462  1.1  riastrad 	cypress_populate_mvdd_value(rdev, 0, &table->ACPIState.levels[0].mvdd);
   1463  1.1  riastrad 
   1464  1.1  riastrad 	if (eg_pi->dynamic_ac_timing)
   1465  1.1  riastrad 		table->ACPIState.levels[0].ACIndex = 1;
   1466  1.1  riastrad 
   1467  1.1  riastrad 	table->ACPIState.levels[1] = table->ACPIState.levels[0];
   1468  1.1  riastrad 	table->ACPIState.levels[2] = table->ACPIState.levels[0];
   1469  1.1  riastrad 
   1470  1.1  riastrad 	return 0;
   1471  1.1  riastrad }
   1472  1.1  riastrad 
   1473  1.1  riastrad static void cypress_trim_voltage_table_to_fit_state_table(struct radeon_device *rdev,
   1474  1.1  riastrad 							  struct atom_voltage_table *voltage_table)
   1475  1.1  riastrad {
   1476  1.1  riastrad 	unsigned int i, diff;
   1477  1.1  riastrad 
   1478  1.1  riastrad 	if (voltage_table->count <= MAX_NO_VREG_STEPS)
   1479  1.1  riastrad 		return;
   1480  1.1  riastrad 
   1481  1.1  riastrad 	diff = voltage_table->count - MAX_NO_VREG_STEPS;
   1482  1.1  riastrad 
   1483  1.1  riastrad 	for (i= 0; i < MAX_NO_VREG_STEPS; i++)
   1484  1.1  riastrad 		voltage_table->entries[i] = voltage_table->entries[i + diff];
   1485  1.1  riastrad 
   1486  1.1  riastrad 	voltage_table->count = MAX_NO_VREG_STEPS;
   1487  1.1  riastrad }
   1488  1.1  riastrad 
   1489  1.1  riastrad int cypress_construct_voltage_tables(struct radeon_device *rdev)
   1490  1.1  riastrad {
   1491  1.1  riastrad 	struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
   1492  1.1  riastrad 	int ret;
   1493  1.1  riastrad 
   1494  1.1  riastrad 	ret = radeon_atom_get_voltage_table(rdev, SET_VOLTAGE_TYPE_ASIC_VDDC, 0,
   1495  1.1  riastrad 					    &eg_pi->vddc_voltage_table);
   1496  1.1  riastrad 	if (ret)
   1497  1.1  riastrad 		return ret;
   1498  1.1  riastrad 
   1499  1.1  riastrad 	if (eg_pi->vddc_voltage_table.count > MAX_NO_VREG_STEPS)
   1500  1.1  riastrad 		cypress_trim_voltage_table_to_fit_state_table(rdev,
   1501  1.1  riastrad 							      &eg_pi->vddc_voltage_table);
   1502  1.1  riastrad 
   1503  1.1  riastrad 	if (eg_pi->vddci_control) {
   1504  1.1  riastrad 		ret = radeon_atom_get_voltage_table(rdev, SET_VOLTAGE_TYPE_ASIC_VDDCI, 0,
   1505  1.1  riastrad 						    &eg_pi->vddci_voltage_table);
   1506  1.1  riastrad 		if (ret)
   1507  1.1  riastrad 			return ret;
   1508  1.1  riastrad 
   1509  1.1  riastrad 		if (eg_pi->vddci_voltage_table.count > MAX_NO_VREG_STEPS)
   1510  1.1  riastrad 			cypress_trim_voltage_table_to_fit_state_table(rdev,
   1511  1.1  riastrad 								      &eg_pi->vddci_voltage_table);
   1512  1.1  riastrad 	}
   1513  1.1  riastrad 
   1514  1.1  riastrad 	return 0;
   1515  1.1  riastrad }
   1516  1.1  riastrad 
   1517  1.1  riastrad static void cypress_populate_smc_voltage_table(struct radeon_device *rdev,
   1518  1.1  riastrad 					       struct atom_voltage_table *voltage_table,
   1519  1.1  riastrad 					       RV770_SMC_STATETABLE *table)
   1520  1.1  riastrad {
   1521  1.1  riastrad 	unsigned int i;
   1522  1.1  riastrad 
   1523  1.1  riastrad 	for (i = 0; i < voltage_table->count; i++) {
   1524  1.1  riastrad 		table->highSMIO[i] = 0;
   1525  1.1  riastrad 		table->lowSMIO[i] |= cpu_to_be32(voltage_table->entries[i].smio_low);
   1526  1.1  riastrad 	}
   1527  1.1  riastrad }
   1528  1.1  riastrad 
   1529  1.1  riastrad int cypress_populate_smc_voltage_tables(struct radeon_device *rdev,
   1530  1.1  riastrad 					RV770_SMC_STATETABLE *table)
   1531  1.1  riastrad {
   1532  1.1  riastrad 	struct rv7xx_power_info *pi = rv770_get_pi(rdev);
   1533  1.1  riastrad 	struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
   1534  1.1  riastrad 	unsigned char i;
   1535  1.1  riastrad 
   1536  1.1  riastrad 	if (eg_pi->vddc_voltage_table.count) {
   1537  1.1  riastrad 		cypress_populate_smc_voltage_table(rdev,
   1538  1.1  riastrad 						   &eg_pi->vddc_voltage_table,
   1539  1.1  riastrad 						   table);
   1540  1.1  riastrad 
   1541  1.1  riastrad 		table->voltageMaskTable.highMask[RV770_SMC_VOLTAGEMASK_VDDC] = 0;
   1542  1.1  riastrad 		table->voltageMaskTable.lowMask[RV770_SMC_VOLTAGEMASK_VDDC] =
   1543  1.1  riastrad 			cpu_to_be32(eg_pi->vddc_voltage_table.mask_low);
   1544  1.1  riastrad 
   1545  1.1  riastrad 		for (i = 0; i < eg_pi->vddc_voltage_table.count; i++) {
   1546  1.1  riastrad 			if (pi->max_vddc_in_table <=
   1547  1.1  riastrad 			    eg_pi->vddc_voltage_table.entries[i].value) {
   1548  1.1  riastrad 				table->maxVDDCIndexInPPTable = i;
   1549  1.1  riastrad 				break;
   1550  1.1  riastrad 			}
   1551  1.1  riastrad 		}
   1552  1.1  riastrad 	}
   1553  1.1  riastrad 
   1554  1.1  riastrad 	if (eg_pi->vddci_voltage_table.count) {
   1555  1.1  riastrad 		cypress_populate_smc_voltage_table(rdev,
   1556  1.1  riastrad 						   &eg_pi->vddci_voltage_table,
   1557  1.1  riastrad 						   table);
   1558  1.1  riastrad 
   1559  1.1  riastrad 		table->voltageMaskTable.highMask[RV770_SMC_VOLTAGEMASK_VDDCI] = 0;
   1560  1.1  riastrad 		table->voltageMaskTable.lowMask[RV770_SMC_VOLTAGEMASK_VDDCI] =
   1561  1.1  riastrad 			cpu_to_be32(eg_pi->vddci_voltage_table.mask_low);
   1562  1.1  riastrad 	}
   1563  1.1  riastrad 
   1564  1.1  riastrad 	return 0;
   1565  1.1  riastrad }
   1566  1.1  riastrad 
   1567  1.1  riastrad static u32 cypress_get_mclk_split_point(struct atom_memory_info *memory_info)
   1568  1.1  riastrad {
   1569  1.1  riastrad 	if ((memory_info->mem_type == MEM_TYPE_GDDR3) ||
   1570  1.1  riastrad 	    (memory_info->mem_type == MEM_TYPE_DDR3))
   1571  1.1  riastrad 		return 30000;
   1572  1.1  riastrad 
   1573  1.1  riastrad 	return 0;
   1574  1.1  riastrad }
   1575  1.1  riastrad 
   1576  1.1  riastrad int cypress_get_mvdd_configuration(struct radeon_device *rdev)
   1577  1.1  riastrad {
   1578  1.1  riastrad 	struct rv7xx_power_info *pi = rv770_get_pi(rdev);
   1579  1.1  riastrad 	struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
   1580  1.1  riastrad 	u8 module_index;
   1581  1.1  riastrad 	struct atom_memory_info memory_info;
   1582  1.1  riastrad 	u32 tmp = RREG32(GENERAL_PWRMGT);
   1583  1.1  riastrad 
   1584  1.1  riastrad 	if (!(tmp & BACKBIAS_PAD_EN)) {
   1585  1.1  riastrad 		eg_pi->mvdd_high_index = 0;
   1586  1.1  riastrad 		eg_pi->mvdd_low_index = 1;
   1587  1.1  riastrad 		pi->mvdd_control = false;
   1588  1.1  riastrad 		return 0;
   1589  1.1  riastrad 	}
   1590  1.1  riastrad 
   1591  1.1  riastrad 	if (tmp & BACKBIAS_VALUE)
   1592  1.1  riastrad 		eg_pi->mvdd_high_index = 1;
   1593  1.1  riastrad 	else
   1594  1.1  riastrad 		eg_pi->mvdd_high_index = 0;
   1595  1.1  riastrad 
   1596  1.1  riastrad 	eg_pi->mvdd_low_index =
   1597  1.1  riastrad 		(eg_pi->mvdd_high_index == 0) ? 1 : 0;
   1598  1.1  riastrad 
   1599  1.1  riastrad 	module_index = rv770_get_memory_module_index(rdev);
   1600  1.1  riastrad 
   1601  1.1  riastrad 	if (radeon_atom_get_memory_info(rdev, module_index, &memory_info)) {
   1602  1.1  riastrad 		pi->mvdd_control = false;
   1603  1.1  riastrad 		return 0;
   1604  1.1  riastrad 	}
   1605  1.1  riastrad 
   1606  1.1  riastrad 	pi->mvdd_split_frequency =
   1607  1.1  riastrad 		cypress_get_mclk_split_point(&memory_info);
   1608  1.1  riastrad 
   1609  1.1  riastrad 	if (pi->mvdd_split_frequency == 0) {
   1610  1.1  riastrad 		pi->mvdd_control = false;
   1611  1.1  riastrad 		return 0;
   1612  1.1  riastrad 	}
   1613  1.1  riastrad 
   1614  1.1  riastrad 	return 0;
   1615  1.1  riastrad }
   1616  1.1  riastrad 
   1617  1.1  riastrad static int cypress_init_smc_table(struct radeon_device *rdev,
   1618  1.1  riastrad 				  struct radeon_ps *radeon_boot_state)
   1619  1.1  riastrad {
   1620  1.1  riastrad 	struct rv7xx_power_info *pi = rv770_get_pi(rdev);
   1621  1.1  riastrad 	RV770_SMC_STATETABLE *table = &pi->smc_statetable;
   1622  1.1  riastrad 	int ret;
   1623  1.1  riastrad 
   1624  1.1  riastrad 	memset(table, 0, sizeof(RV770_SMC_STATETABLE));
   1625  1.1  riastrad 
   1626  1.1  riastrad 	cypress_populate_smc_voltage_tables(rdev, table);
   1627  1.1  riastrad 
   1628  1.1  riastrad 	switch (rdev->pm.int_thermal_type) {
   1629  1.2  riastrad 	case THERMAL_TYPE_EVERGREEN:
   1630  1.2  riastrad 	case THERMAL_TYPE_EMC2103_WITH_INTERNAL:
   1631  1.1  riastrad 		table->thermalProtectType = PPSMC_THERMAL_PROTECT_TYPE_INTERNAL;
   1632  1.1  riastrad 		break;
   1633  1.2  riastrad 	case THERMAL_TYPE_NONE:
   1634  1.1  riastrad 		table->thermalProtectType = PPSMC_THERMAL_PROTECT_TYPE_NONE;
   1635  1.1  riastrad 		break;
   1636  1.2  riastrad 	default:
   1637  1.1  riastrad 		table->thermalProtectType = PPSMC_THERMAL_PROTECT_TYPE_EXTERNAL;
   1638  1.1  riastrad 		break;
   1639  1.1  riastrad 	}
   1640  1.1  riastrad 
   1641  1.1  riastrad 	if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_HARDWAREDC)
   1642  1.1  riastrad 		table->systemFlags |= PPSMC_SYSTEMFLAG_GPIO_DC;
   1643  1.1  riastrad 
   1644  1.1  riastrad 	if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_REGULATOR_HOT)
   1645  1.1  riastrad 		table->systemFlags |= PPSMC_SYSTEMFLAG_REGULATOR_HOT;
   1646  1.1  riastrad 
   1647  1.1  riastrad 	if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_STEPVDDC)
   1648  1.1  riastrad 		table->systemFlags |= PPSMC_SYSTEMFLAG_STEPVDDC;
   1649  1.1  riastrad 
   1650  1.1  riastrad 	if (pi->mem_gddr5)
   1651  1.1  riastrad 		table->systemFlags |= PPSMC_SYSTEMFLAG_GDDR5;
   1652  1.1  riastrad 
   1653  1.1  riastrad 	ret = cypress_populate_smc_initial_state(rdev, radeon_boot_state, table);
   1654  1.1  riastrad 	if (ret)
   1655  1.1  riastrad 		return ret;
   1656  1.1  riastrad 
   1657  1.1  riastrad 	ret = cypress_populate_smc_acpi_state(rdev, table);
   1658  1.1  riastrad 	if (ret)
   1659  1.1  riastrad 		return ret;
   1660  1.1  riastrad 
   1661  1.1  riastrad 	table->driverState = table->initialState;
   1662  1.1  riastrad 
   1663  1.1  riastrad 	return rv770_copy_bytes_to_smc(rdev,
   1664  1.1  riastrad 				       pi->state_table_start,
   1665  1.1  riastrad 				       (u8 *)table, sizeof(RV770_SMC_STATETABLE),
   1666  1.1  riastrad 				       pi->sram_end);
   1667  1.1  riastrad }
   1668  1.1  riastrad 
   1669  1.1  riastrad int cypress_populate_mc_reg_table(struct radeon_device *rdev,
   1670  1.1  riastrad 				  struct radeon_ps *radeon_boot_state)
   1671  1.1  riastrad {
   1672  1.1  riastrad 	struct rv7xx_power_info *pi = rv770_get_pi(rdev);
   1673  1.1  riastrad 	struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
   1674  1.1  riastrad 	struct rv7xx_ps *boot_state = rv770_get_ps(radeon_boot_state);
   1675  1.1  riastrad 	SMC_Evergreen_MCRegisters mc_reg_table = { 0 };
   1676  1.1  riastrad 
   1677  1.1  riastrad 	rv770_write_smc_soft_register(rdev,
   1678  1.1  riastrad 				      RV770_SMC_SOFT_REGISTER_seq_index, 1);
   1679  1.1  riastrad 
   1680  1.1  riastrad 	cypress_populate_mc_reg_addresses(rdev, &mc_reg_table);
   1681  1.1  riastrad 
   1682  1.1  riastrad 	cypress_convert_mc_reg_table_entry_to_smc(rdev,
   1683  1.1  riastrad 						  &boot_state->low,
   1684  1.1  riastrad 						  &mc_reg_table.data[0]);
   1685  1.1  riastrad 
   1686  1.1  riastrad 	cypress_convert_mc_registers(&eg_pi->mc_reg_table.mc_reg_table_entry[0],
   1687  1.1  riastrad 				     &mc_reg_table.data[1], eg_pi->mc_reg_table.last,
   1688  1.1  riastrad 				     eg_pi->mc_reg_table.valid_flag);
   1689  1.1  riastrad 
   1690  1.1  riastrad 	cypress_convert_mc_reg_table_to_smc(rdev, radeon_boot_state, &mc_reg_table);
   1691  1.1  riastrad 
   1692  1.1  riastrad 	return rv770_copy_bytes_to_smc(rdev, eg_pi->mc_reg_table_start,
   1693  1.1  riastrad 				       (u8 *)&mc_reg_table, sizeof(SMC_Evergreen_MCRegisters),
   1694  1.1  riastrad 				       pi->sram_end);
   1695  1.1  riastrad }
   1696  1.1  riastrad 
   1697  1.1  riastrad int cypress_get_table_locations(struct radeon_device *rdev)
   1698  1.1  riastrad {
   1699  1.1  riastrad 	struct rv7xx_power_info *pi = rv770_get_pi(rdev);
   1700  1.1  riastrad 	struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
   1701  1.1  riastrad 	u32 tmp;
   1702  1.1  riastrad 	int ret;
   1703  1.1  riastrad 
   1704  1.1  riastrad 	ret = rv770_read_smc_sram_dword(rdev,
   1705  1.1  riastrad 					EVERGREEN_SMC_FIRMWARE_HEADER_LOCATION +
   1706  1.1  riastrad 					EVERGREEN_SMC_FIRMWARE_HEADER_stateTable,
   1707  1.1  riastrad 					&tmp, pi->sram_end);
   1708  1.1  riastrad 	if (ret)
   1709  1.1  riastrad 		return ret;
   1710  1.1  riastrad 
   1711  1.1  riastrad 	pi->state_table_start = (u16)tmp;
   1712  1.1  riastrad 
   1713  1.1  riastrad 	ret = rv770_read_smc_sram_dword(rdev,
   1714  1.1  riastrad 					EVERGREEN_SMC_FIRMWARE_HEADER_LOCATION +
   1715  1.1  riastrad 					EVERGREEN_SMC_FIRMWARE_HEADER_softRegisters,
   1716  1.1  riastrad 					&tmp, pi->sram_end);
   1717  1.1  riastrad 	if (ret)
   1718  1.1  riastrad 		return ret;
   1719  1.1  riastrad 
   1720  1.1  riastrad 	pi->soft_regs_start = (u16)tmp;
   1721  1.1  riastrad 
   1722  1.1  riastrad 	ret = rv770_read_smc_sram_dword(rdev,
   1723  1.1  riastrad 					EVERGREEN_SMC_FIRMWARE_HEADER_LOCATION +
   1724  1.1  riastrad 					EVERGREEN_SMC_FIRMWARE_HEADER_mcRegisterTable,
   1725  1.1  riastrad 					&tmp, pi->sram_end);
   1726  1.1  riastrad 	if (ret)
   1727  1.1  riastrad 		return ret;
   1728  1.1  riastrad 
   1729  1.1  riastrad 	eg_pi->mc_reg_table_start = (u16)tmp;
   1730  1.1  riastrad 
   1731  1.1  riastrad 	return 0;
   1732  1.1  riastrad }
   1733  1.1  riastrad 
   1734  1.1  riastrad void cypress_enable_display_gap(struct radeon_device *rdev)
   1735  1.1  riastrad {
   1736  1.1  riastrad 	u32 tmp = RREG32(CG_DISPLAY_GAP_CNTL);
   1737  1.1  riastrad 
   1738  1.1  riastrad 	tmp &= ~(DISP1_GAP_MASK | DISP2_GAP_MASK);
   1739  1.1  riastrad 	tmp |= (DISP1_GAP(R600_PM_DISPLAY_GAP_IGNORE) |
   1740  1.1  riastrad 		DISP2_GAP(R600_PM_DISPLAY_GAP_IGNORE));
   1741  1.1  riastrad 
   1742  1.1  riastrad 	tmp &= ~(DISP1_GAP_MCHG_MASK | DISP2_GAP_MCHG_MASK);
   1743  1.1  riastrad 	tmp |= (DISP1_GAP_MCHG(R600_PM_DISPLAY_GAP_VBLANK) |
   1744  1.1  riastrad 		DISP2_GAP_MCHG(R600_PM_DISPLAY_GAP_IGNORE));
   1745  1.1  riastrad 	WREG32(CG_DISPLAY_GAP_CNTL, tmp);
   1746  1.1  riastrad }
   1747  1.1  riastrad 
   1748  1.1  riastrad static void cypress_program_display_gap(struct radeon_device *rdev)
   1749  1.1  riastrad {
   1750  1.1  riastrad 	u32 tmp, pipe;
   1751  1.1  riastrad 	int i;
   1752  1.1  riastrad 
   1753  1.1  riastrad 	tmp = RREG32(CG_DISPLAY_GAP_CNTL) & ~(DISP1_GAP_MASK | DISP2_GAP_MASK);
   1754  1.1  riastrad 	if (rdev->pm.dpm.new_active_crtc_count > 0)
   1755  1.1  riastrad 		tmp |= DISP1_GAP(R600_PM_DISPLAY_GAP_VBLANK_OR_WM);
   1756  1.1  riastrad 	else
   1757  1.1  riastrad 		tmp |= DISP1_GAP(R600_PM_DISPLAY_GAP_IGNORE);
   1758  1.1  riastrad 
   1759  1.1  riastrad 	if (rdev->pm.dpm.new_active_crtc_count > 1)
   1760  1.1  riastrad 		tmp |= DISP2_GAP(R600_PM_DISPLAY_GAP_VBLANK_OR_WM);
   1761  1.1  riastrad 	else
   1762  1.1  riastrad 		tmp |= DISP2_GAP(R600_PM_DISPLAY_GAP_IGNORE);
   1763  1.1  riastrad 
   1764  1.1  riastrad 	WREG32(CG_DISPLAY_GAP_CNTL, tmp);
   1765  1.1  riastrad 
   1766  1.1  riastrad 	tmp = RREG32(DCCG_DISP_SLOW_SELECT_REG);
   1767  1.1  riastrad 	pipe = (tmp & DCCG_DISP1_SLOW_SELECT_MASK) >> DCCG_DISP1_SLOW_SELECT_SHIFT;
   1768  1.1  riastrad 
   1769  1.1  riastrad 	if ((rdev->pm.dpm.new_active_crtc_count > 0) &&
   1770  1.1  riastrad 	    (!(rdev->pm.dpm.new_active_crtcs & (1 << pipe)))) {
   1771  1.1  riastrad 		/* find the first active crtc */
   1772  1.1  riastrad 		for (i = 0; i < rdev->num_crtc; i++) {
   1773  1.1  riastrad 			if (rdev->pm.dpm.new_active_crtcs & (1 << i))
   1774  1.1  riastrad 				break;
   1775  1.1  riastrad 		}
   1776  1.1  riastrad 		if (i == rdev->num_crtc)
   1777  1.1  riastrad 			pipe = 0;
   1778  1.1  riastrad 		else
   1779  1.1  riastrad 			pipe = i;
   1780  1.1  riastrad 
   1781  1.1  riastrad 		tmp &= ~DCCG_DISP1_SLOW_SELECT_MASK;
   1782  1.1  riastrad 		tmp |= DCCG_DISP1_SLOW_SELECT(pipe);
   1783  1.1  riastrad 		WREG32(DCCG_DISP_SLOW_SELECT_REG, tmp);
   1784  1.1  riastrad 	}
   1785  1.1  riastrad 
   1786  1.1  riastrad 	cypress_notify_smc_display_change(rdev, rdev->pm.dpm.new_active_crtc_count > 0);
   1787  1.1  riastrad }
   1788  1.1  riastrad 
   1789  1.1  riastrad void cypress_dpm_setup_asic(struct radeon_device *rdev)
   1790  1.1  riastrad {
   1791  1.1  riastrad 	struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
   1792  1.1  riastrad 
   1793  1.1  riastrad 	rv740_read_clock_registers(rdev);
   1794  1.1  riastrad 	rv770_read_voltage_smio_registers(rdev);
   1795  1.1  riastrad 	rv770_get_max_vddc(rdev);
   1796  1.1  riastrad 	rv770_get_memory_type(rdev);
   1797  1.1  riastrad 
   1798  1.1  riastrad 	if (eg_pi->pcie_performance_request)
   1799  1.1  riastrad 		eg_pi->pcie_performance_request_registered = false;
   1800  1.1  riastrad 
   1801  1.1  riastrad 	if (eg_pi->pcie_performance_request)
   1802  1.1  riastrad 		cypress_advertise_gen2_capability(rdev);
   1803  1.1  riastrad 
   1804  1.1  riastrad 	rv770_get_pcie_gen2_status(rdev);
   1805  1.1  riastrad 
   1806  1.1  riastrad 	rv770_enable_acpi_pm(rdev);
   1807  1.1  riastrad }
   1808  1.1  riastrad 
   1809  1.1  riastrad int cypress_dpm_enable(struct radeon_device *rdev)
   1810  1.1  riastrad {
   1811  1.1  riastrad 	struct rv7xx_power_info *pi = rv770_get_pi(rdev);
   1812  1.1  riastrad 	struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
   1813  1.1  riastrad 	struct radeon_ps *boot_ps = rdev->pm.dpm.boot_ps;
   1814  1.1  riastrad 	int ret;
   1815  1.1  riastrad 
   1816  1.1  riastrad 	if (pi->gfx_clock_gating)
   1817  1.1  riastrad 		rv770_restore_cgcg(rdev);
   1818  1.1  riastrad 
   1819  1.1  riastrad 	if (rv770_dpm_enabled(rdev))
   1820  1.1  riastrad 		return -EINVAL;
   1821  1.1  riastrad 
   1822  1.1  riastrad 	if (pi->voltage_control) {
   1823  1.1  riastrad 		rv770_enable_voltage_control(rdev, true);
   1824  1.1  riastrad 		ret = cypress_construct_voltage_tables(rdev);
   1825  1.1  riastrad 		if (ret) {
   1826  1.1  riastrad 			DRM_ERROR("cypress_construct_voltage_tables failed\n");
   1827  1.1  riastrad 			return ret;
   1828  1.1  riastrad 		}
   1829  1.1  riastrad 	}
   1830  1.1  riastrad 
   1831  1.1  riastrad 	if (pi->mvdd_control) {
   1832  1.1  riastrad 		ret = cypress_get_mvdd_configuration(rdev);
   1833  1.1  riastrad 		if (ret) {
   1834  1.1  riastrad 			DRM_ERROR("cypress_get_mvdd_configuration failed\n");
   1835  1.1  riastrad 			return ret;
   1836  1.1  riastrad 		}
   1837  1.1  riastrad 	}
   1838  1.1  riastrad 
   1839  1.1  riastrad 	if (eg_pi->dynamic_ac_timing) {
   1840  1.1  riastrad 		cypress_set_mc_reg_address_table(rdev);
   1841  1.1  riastrad 		cypress_force_mc_use_s0(rdev, boot_ps);
   1842  1.1  riastrad 		ret = cypress_initialize_mc_reg_table(rdev);
   1843  1.1  riastrad 		if (ret)
   1844  1.1  riastrad 			eg_pi->dynamic_ac_timing = false;
   1845  1.1  riastrad 		cypress_force_mc_use_s1(rdev, boot_ps);
   1846  1.1  riastrad 	}
   1847  1.1  riastrad 
   1848  1.1  riastrad 	if (rdev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_BACKBIAS)
   1849  1.1  riastrad 		rv770_enable_backbias(rdev, true);
   1850  1.1  riastrad 
   1851  1.1  riastrad 	if (pi->dynamic_ss)
   1852  1.1  riastrad 		cypress_enable_spread_spectrum(rdev, true);
   1853  1.1  riastrad 
   1854  1.1  riastrad 	if (pi->thermal_protection)
   1855  1.1  riastrad 		rv770_enable_thermal_protection(rdev, true);
   1856  1.1  riastrad 
   1857  1.1  riastrad 	rv770_setup_bsp(rdev);
   1858  1.1  riastrad 	rv770_program_git(rdev);
   1859  1.1  riastrad 	rv770_program_tp(rdev);
   1860  1.1  riastrad 	rv770_program_tpp(rdev);
   1861  1.1  riastrad 	rv770_program_sstp(rdev);
   1862  1.1  riastrad 	rv770_program_engine_speed_parameters(rdev);
   1863  1.1  riastrad 	cypress_enable_display_gap(rdev);
   1864  1.1  riastrad 	rv770_program_vc(rdev);
   1865  1.1  riastrad 
   1866  1.1  riastrad 	if (pi->dynamic_pcie_gen2)
   1867  1.1  riastrad 		cypress_enable_dynamic_pcie_gen2(rdev, true);
   1868  1.1  riastrad 
   1869  1.1  riastrad 	ret = rv770_upload_firmware(rdev);
   1870  1.1  riastrad 	if (ret) {
   1871  1.1  riastrad 		DRM_ERROR("rv770_upload_firmware failed\n");
   1872  1.1  riastrad 		return ret;
   1873  1.1  riastrad 	}
   1874  1.1  riastrad 
   1875  1.1  riastrad 	ret = cypress_get_table_locations(rdev);
   1876  1.1  riastrad 	if (ret) {
   1877  1.1  riastrad 		DRM_ERROR("cypress_get_table_locations failed\n");
   1878  1.1  riastrad 		return ret;
   1879  1.1  riastrad 	}
   1880  1.1  riastrad 	ret = cypress_init_smc_table(rdev, boot_ps);
   1881  1.1  riastrad 	if (ret) {
   1882  1.1  riastrad 		DRM_ERROR("cypress_init_smc_table failed\n");
   1883  1.1  riastrad 		return ret;
   1884  1.1  riastrad 	}
   1885  1.1  riastrad 	if (eg_pi->dynamic_ac_timing) {
   1886  1.1  riastrad 		ret = cypress_populate_mc_reg_table(rdev, boot_ps);
   1887  1.1  riastrad 		if (ret) {
   1888  1.1  riastrad 			DRM_ERROR("cypress_populate_mc_reg_table failed\n");
   1889  1.1  riastrad 			return ret;
   1890  1.1  riastrad 		}
   1891  1.1  riastrad 	}
   1892  1.1  riastrad 
   1893  1.1  riastrad 	cypress_program_response_times(rdev);
   1894  1.1  riastrad 
   1895  1.1  riastrad 	r7xx_start_smc(rdev);
   1896  1.1  riastrad 
   1897  1.1  riastrad 	ret = cypress_notify_smc_display_change(rdev, false);
   1898  1.1  riastrad 	if (ret) {
   1899  1.1  riastrad 		DRM_ERROR("cypress_notify_smc_display_change failed\n");
   1900  1.1  riastrad 		return ret;
   1901  1.1  riastrad 	}
   1902  1.1  riastrad 	cypress_enable_sclk_control(rdev, true);
   1903  1.1  riastrad 
   1904  1.1  riastrad 	if (eg_pi->memory_transition)
   1905  1.1  riastrad 		cypress_enable_mclk_control(rdev, true);
   1906  1.1  riastrad 
   1907  1.1  riastrad 	cypress_start_dpm(rdev);
   1908  1.1  riastrad 
   1909  1.1  riastrad 	if (pi->gfx_clock_gating)
   1910  1.1  riastrad 		cypress_gfx_clock_gating_enable(rdev, true);
   1911  1.1  riastrad 
   1912  1.1  riastrad 	if (pi->mg_clock_gating)
   1913  1.1  riastrad 		cypress_mg_clock_gating_enable(rdev, true);
   1914  1.1  riastrad 
   1915  1.1  riastrad 	rv770_enable_auto_throttle_source(rdev, RADEON_DPM_AUTO_THROTTLE_SRC_THERMAL, true);
   1916  1.1  riastrad 
   1917  1.1  riastrad 	return 0;
   1918  1.1  riastrad }
   1919  1.1  riastrad 
   1920  1.1  riastrad void cypress_dpm_disable(struct radeon_device *rdev)
   1921  1.1  riastrad {
   1922  1.1  riastrad 	struct rv7xx_power_info *pi = rv770_get_pi(rdev);
   1923  1.1  riastrad 	struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
   1924  1.1  riastrad 	struct radeon_ps *boot_ps = rdev->pm.dpm.boot_ps;
   1925  1.1  riastrad 
   1926  1.1  riastrad 	if (!rv770_dpm_enabled(rdev))
   1927  1.1  riastrad 		return;
   1928  1.1  riastrad 
   1929  1.1  riastrad 	rv770_clear_vc(rdev);
   1930  1.1  riastrad 
   1931  1.1  riastrad 	if (pi->thermal_protection)
   1932  1.1  riastrad 		rv770_enable_thermal_protection(rdev, false);
   1933  1.1  riastrad 
   1934  1.1  riastrad 	if (pi->dynamic_pcie_gen2)
   1935  1.1  riastrad 		cypress_enable_dynamic_pcie_gen2(rdev, false);
   1936  1.1  riastrad 
   1937  1.1  riastrad 	if (rdev->irq.installed &&
   1938  1.1  riastrad 	    r600_is_internal_thermal_sensor(rdev->pm.int_thermal_type)) {
   1939  1.1  riastrad 		rdev->irq.dpm_thermal = false;
   1940  1.1  riastrad 		radeon_irq_set(rdev);
   1941  1.1  riastrad 	}
   1942  1.1  riastrad 
   1943  1.1  riastrad 	if (pi->gfx_clock_gating)
   1944  1.1  riastrad 		cypress_gfx_clock_gating_enable(rdev, false);
   1945  1.1  riastrad 
   1946  1.1  riastrad 	if (pi->mg_clock_gating)
   1947  1.1  riastrad 		cypress_mg_clock_gating_enable(rdev, false);
   1948  1.1  riastrad 
   1949  1.1  riastrad 	rv770_stop_dpm(rdev);
   1950  1.1  riastrad 	r7xx_stop_smc(rdev);
   1951  1.1  riastrad 
   1952  1.1  riastrad 	cypress_enable_spread_spectrum(rdev, false);
   1953  1.1  riastrad 
   1954  1.1  riastrad 	if (eg_pi->dynamic_ac_timing)
   1955  1.1  riastrad 		cypress_force_mc_use_s1(rdev, boot_ps);
   1956  1.1  riastrad 
   1957  1.1  riastrad 	rv770_reset_smio_status(rdev);
   1958  1.1  riastrad }
   1959  1.1  riastrad 
   1960  1.1  riastrad int cypress_dpm_set_power_state(struct radeon_device *rdev)
   1961  1.1  riastrad {
   1962  1.1  riastrad 	struct evergreen_power_info *eg_pi = evergreen_get_pi(rdev);
   1963  1.1  riastrad 	struct radeon_ps *new_ps = rdev->pm.dpm.requested_ps;
   1964  1.1  riastrad 	struct radeon_ps *old_ps = rdev->pm.dpm.current_ps;
   1965  1.1  riastrad 	int ret;
   1966  1.1  riastrad 
   1967  1.1  riastrad 	ret = rv770_restrict_performance_levels_before_switch(rdev);
   1968  1.1  riastrad 	if (ret) {
   1969  1.3       mrg 		DRM_ERROR("rv770_restrict_performance_levels_before_switch failed: %d\n", ret);
   1970  1.1  riastrad 		return ret;
   1971  1.1  riastrad 	}
   1972  1.1  riastrad 	if (eg_pi->pcie_performance_request)
   1973  1.1  riastrad 		cypress_notify_link_speed_change_before_state_change(rdev, new_ps, old_ps);
   1974  1.1  riastrad 
   1975  1.1  riastrad 	rv770_set_uvd_clock_before_set_eng_clock(rdev, new_ps, old_ps);
   1976  1.1  riastrad 	ret = rv770_halt_smc(rdev);
   1977  1.1  riastrad 	if (ret) {
   1978  1.1  riastrad 		DRM_ERROR("rv770_halt_smc failed\n");
   1979  1.1  riastrad 		return ret;
   1980  1.1  riastrad 	}
   1981  1.1  riastrad 	ret = cypress_upload_sw_state(rdev, new_ps);
   1982  1.1  riastrad 	if (ret) {
   1983  1.1  riastrad 		DRM_ERROR("cypress_upload_sw_state failed\n");
   1984  1.1  riastrad 		return ret;
   1985  1.1  riastrad 	}
   1986  1.1  riastrad 	if (eg_pi->dynamic_ac_timing) {
   1987  1.1  riastrad 		ret = cypress_upload_mc_reg_table(rdev, new_ps);
   1988  1.1  riastrad 		if (ret) {
   1989  1.1  riastrad 			DRM_ERROR("cypress_upload_mc_reg_table failed\n");
   1990  1.1  riastrad 			return ret;
   1991  1.1  riastrad 		}
   1992  1.1  riastrad 	}
   1993  1.1  riastrad 
   1994  1.1  riastrad 	cypress_program_memory_timing_parameters(rdev, new_ps);
   1995  1.1  riastrad 
   1996  1.1  riastrad 	ret = rv770_resume_smc(rdev);
   1997  1.1  riastrad 	if (ret) {
   1998  1.1  riastrad 		DRM_ERROR("rv770_resume_smc failed\n");
   1999  1.1  riastrad 		return ret;
   2000  1.1  riastrad 	}
   2001  1.1  riastrad 	ret = rv770_set_sw_state(rdev);
   2002  1.1  riastrad 	if (ret) {
   2003  1.1  riastrad 		DRM_ERROR("rv770_set_sw_state failed\n");
   2004  1.1  riastrad 		return ret;
   2005  1.1  riastrad 	}
   2006  1.1  riastrad 	rv770_set_uvd_clock_after_set_eng_clock(rdev, new_ps, old_ps);
   2007  1.1  riastrad 
   2008  1.1  riastrad 	if (eg_pi->pcie_performance_request)
   2009  1.1  riastrad 		cypress_notify_link_speed_change_after_state_change(rdev, new_ps, old_ps);
   2010  1.1  riastrad 
   2011  1.1  riastrad 	return 0;
   2012  1.1  riastrad }
   2013  1.1  riastrad 
   2014  1.1  riastrad #if 0
   2015  1.1  riastrad void cypress_dpm_reset_asic(struct radeon_device *rdev)
   2016  1.1  riastrad {
   2017  1.1  riastrad 	rv770_restrict_performance_levels_before_switch(rdev);
   2018  1.1  riastrad 	rv770_set_boot_state(rdev);
   2019  1.1  riastrad }
   2020  1.1  riastrad #endif
   2021  1.1  riastrad 
   2022  1.1  riastrad void cypress_dpm_display_configuration_changed(struct radeon_device *rdev)
   2023  1.1  riastrad {
   2024  1.1  riastrad 	cypress_program_display_gap(rdev);
   2025  1.1  riastrad }
   2026  1.1  riastrad 
   2027  1.1  riastrad int cypress_dpm_init(struct radeon_device *rdev)
   2028  1.1  riastrad {
   2029  1.1  riastrad 	struct rv7xx_power_info *pi;
   2030  1.1  riastrad 	struct evergreen_power_info *eg_pi;
   2031  1.1  riastrad 	struct atom_clock_dividers dividers;
   2032  1.1  riastrad 	int ret;
   2033  1.1  riastrad 
   2034  1.1  riastrad 	eg_pi = kzalloc(sizeof(struct evergreen_power_info), GFP_KERNEL);
   2035  1.1  riastrad 	if (eg_pi == NULL)
   2036  1.1  riastrad 		return -ENOMEM;
   2037  1.1  riastrad 	rdev->pm.dpm.priv = eg_pi;
   2038  1.1  riastrad 	pi = &eg_pi->rv7xx;
   2039  1.1  riastrad 
   2040  1.1  riastrad 	rv770_get_max_vddc(rdev);
   2041  1.1  riastrad 
   2042  1.1  riastrad 	eg_pi->ulv.supported = false;
   2043  1.1  riastrad 	pi->acpi_vddc = 0;
   2044  1.1  riastrad 	eg_pi->acpi_vddci = 0;
   2045  1.1  riastrad 	pi->min_vddc_in_table = 0;
   2046  1.1  riastrad 	pi->max_vddc_in_table = 0;
   2047  1.1  riastrad 
   2048  1.1  riastrad 	ret = r600_get_platform_caps(rdev);
   2049  1.1  riastrad 	if (ret)
   2050  1.1  riastrad 		return ret;
   2051  1.1  riastrad 
   2052  1.1  riastrad 	ret = rv7xx_parse_power_table(rdev);
   2053  1.1  riastrad 	if (ret)
   2054  1.1  riastrad 		return ret;
   2055  1.1  riastrad 
   2056  1.1  riastrad 	if (rdev->pm.dpm.voltage_response_time == 0)
   2057  1.1  riastrad 		rdev->pm.dpm.voltage_response_time = R600_VOLTAGERESPONSETIME_DFLT;
   2058  1.1  riastrad 	if (rdev->pm.dpm.backbias_response_time == 0)
   2059  1.1  riastrad 		rdev->pm.dpm.backbias_response_time = R600_BACKBIASRESPONSETIME_DFLT;
   2060  1.1  riastrad 
   2061  1.1  riastrad 	ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
   2062  1.1  riastrad 					     0, false, &dividers);
   2063  1.1  riastrad 	if (ret)
   2064  1.1  riastrad 		pi->ref_div = dividers.ref_div + 1;
   2065  1.1  riastrad 	else
   2066  1.1  riastrad 		pi->ref_div = R600_REFERENCEDIVIDER_DFLT;
   2067  1.1  riastrad 
   2068  1.1  riastrad 	pi->mclk_strobe_mode_threshold = 40000;
   2069  1.1  riastrad 	pi->mclk_edc_enable_threshold = 40000;
   2070  1.1  riastrad 	eg_pi->mclk_edc_wr_enable_threshold = 40000;
   2071  1.1  riastrad 
   2072  1.1  riastrad 	pi->rlp = RV770_RLP_DFLT;
   2073  1.1  riastrad 	pi->rmp = RV770_RMP_DFLT;
   2074  1.1  riastrad 	pi->lhp = RV770_LHP_DFLT;
   2075  1.1  riastrad 	pi->lmp = RV770_LMP_DFLT;
   2076  1.1  riastrad 
   2077  1.1  riastrad 	pi->voltage_control =
   2078  1.1  riastrad 		radeon_atom_is_voltage_gpio(rdev, SET_VOLTAGE_TYPE_ASIC_VDDC, 0);
   2079  1.1  riastrad 
   2080  1.1  riastrad 	pi->mvdd_control =
   2081  1.1  riastrad 		radeon_atom_is_voltage_gpio(rdev, SET_VOLTAGE_TYPE_ASIC_MVDDC, 0);
   2082  1.1  riastrad 
   2083  1.1  riastrad 	eg_pi->vddci_control =
   2084  1.1  riastrad 		radeon_atom_is_voltage_gpio(rdev, SET_VOLTAGE_TYPE_ASIC_VDDCI, 0);
   2085  1.1  riastrad 
   2086  1.1  riastrad 	rv770_get_engine_memory_ss(rdev);
   2087  1.1  riastrad 
   2088  1.1  riastrad 	pi->asi = RV770_ASI_DFLT;
   2089  1.1  riastrad 	pi->pasi = CYPRESS_HASI_DFLT;
   2090  1.1  riastrad 	pi->vrc = CYPRESS_VRC_DFLT;
   2091  1.1  riastrad 
   2092  1.1  riastrad 	pi->power_gating = false;
   2093  1.1  riastrad 
   2094  1.1  riastrad 	if ((rdev->family == CHIP_CYPRESS) ||
   2095  1.1  riastrad 	    (rdev->family == CHIP_HEMLOCK))
   2096  1.1  riastrad 		pi->gfx_clock_gating = false;
   2097  1.1  riastrad 	else
   2098  1.1  riastrad 		pi->gfx_clock_gating = true;
   2099  1.1  riastrad 
   2100  1.1  riastrad 	pi->mg_clock_gating = true;
   2101  1.1  riastrad 	pi->mgcgtssm = true;
   2102  1.1  riastrad 	eg_pi->ls_clock_gating = false;
   2103  1.1  riastrad 	eg_pi->sclk_deep_sleep = false;
   2104  1.1  riastrad 
   2105  1.1  riastrad 	pi->dynamic_pcie_gen2 = true;
   2106  1.1  riastrad 
   2107  1.1  riastrad 	if (rdev->pm.int_thermal_type != THERMAL_TYPE_NONE)
   2108  1.1  riastrad 		pi->thermal_protection = true;
   2109  1.1  riastrad 	else
   2110  1.1  riastrad 		pi->thermal_protection = false;
   2111  1.1  riastrad 
   2112  1.1  riastrad 	pi->display_gap = true;
   2113  1.1  riastrad 
   2114  1.1  riastrad 	if (rdev->flags & RADEON_IS_MOBILITY)
   2115  1.1  riastrad 		pi->dcodt = true;
   2116  1.1  riastrad 	else
   2117  1.1  riastrad 		pi->dcodt = false;
   2118  1.1  riastrad 
   2119  1.1  riastrad 	pi->ulps = true;
   2120  1.1  riastrad 
   2121  1.1  riastrad 	eg_pi->dynamic_ac_timing = true;
   2122  1.1  riastrad 	eg_pi->abm = true;
   2123  1.1  riastrad 	eg_pi->mcls = true;
   2124  1.1  riastrad 	eg_pi->light_sleep = true;
   2125  1.1  riastrad 	eg_pi->memory_transition = true;
   2126  1.1  riastrad #if defined(CONFIG_ACPI)
   2127  1.1  riastrad 	eg_pi->pcie_performance_request =
   2128  1.1  riastrad 		radeon_acpi_is_pcie_performance_request_supported(rdev);
   2129  1.1  riastrad #else
   2130  1.1  riastrad 	eg_pi->pcie_performance_request = false;
   2131  1.1  riastrad #endif
   2132  1.1  riastrad 
   2133  1.1  riastrad 	if ((rdev->family == CHIP_CYPRESS) ||
   2134  1.1  riastrad 	    (rdev->family == CHIP_HEMLOCK) ||
   2135  1.1  riastrad 	    (rdev->family == CHIP_JUNIPER))
   2136  1.1  riastrad 		eg_pi->dll_default_on = true;
   2137  1.1  riastrad 	else
   2138  1.1  riastrad 		eg_pi->dll_default_on = false;
   2139  1.1  riastrad 
   2140  1.1  riastrad 	eg_pi->sclk_deep_sleep = false;
   2141  1.1  riastrad 	pi->mclk_stutter_mode_threshold = 0;
   2142  1.1  riastrad 
   2143  1.1  riastrad 	pi->sram_end = SMC_RAM_END;
   2144  1.1  riastrad 
   2145  1.1  riastrad 	return 0;
   2146  1.1  riastrad }
   2147  1.1  riastrad 
   2148  1.1  riastrad void cypress_dpm_fini(struct radeon_device *rdev)
   2149  1.1  riastrad {
   2150  1.1  riastrad 	int i;
   2151  1.1  riastrad 
   2152  1.1  riastrad 	for (i = 0; i < rdev->pm.dpm.num_ps; i++) {
   2153  1.1  riastrad 		kfree(rdev->pm.dpm.ps[i].ps_priv);
   2154  1.1  riastrad 	}
   2155  1.1  riastrad 	kfree(rdev->pm.dpm.ps);
   2156  1.1  riastrad 	kfree(rdev->pm.dpm.priv);
   2157  1.1  riastrad }
   2158  1.1  riastrad 
   2159  1.1  riastrad bool cypress_dpm_vblank_too_short(struct radeon_device *rdev)
   2160  1.1  riastrad {
   2161  1.1  riastrad 	struct rv7xx_power_info *pi = rv770_get_pi(rdev);
   2162  1.1  riastrad 	u32 vblank_time = r600_dpm_get_vblank_time(rdev);
   2163  1.1  riastrad 	/* we never hit the non-gddr5 limit so disable it */
   2164  1.1  riastrad 	u32 switch_limit = pi->mem_gddr5 ? 450 : 0;
   2165  1.1  riastrad 
   2166  1.1  riastrad 	if (vblank_time < switch_limit)
   2167  1.1  riastrad 		return true;
   2168  1.1  riastrad 	else
   2169  1.1  riastrad 		return false;
   2170  1.1  riastrad 
   2171  1.1  riastrad }
   2172