xref: /dragonfly/sys/dev/drm/radeon/trinity_smc.c (revision c6f73aab)
157e252bfSMichael Neumann /*
257e252bfSMichael Neumann  * Copyright 2012 Advanced Micro Devices, Inc.
357e252bfSMichael Neumann  *
457e252bfSMichael Neumann  * Permission is hereby granted, free of charge, to any person obtaining a
557e252bfSMichael Neumann  * copy of this software and associated documentation files (the "Software"),
657e252bfSMichael Neumann  * to deal in the Software without restriction, including without limitation
757e252bfSMichael Neumann  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
857e252bfSMichael Neumann  * and/or sell copies of the Software, and to permit persons to whom the
957e252bfSMichael Neumann  * Software is furnished to do so, subject to the following conditions:
1057e252bfSMichael Neumann  *
1157e252bfSMichael Neumann  * The above copyright notice and this permission notice shall be included in
1257e252bfSMichael Neumann  * all copies or substantial portions of the Software.
1357e252bfSMichael Neumann  *
1457e252bfSMichael Neumann  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1557e252bfSMichael Neumann  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1657e252bfSMichael Neumann  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
1757e252bfSMichael Neumann  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
1857e252bfSMichael Neumann  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
1957e252bfSMichael Neumann  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2057e252bfSMichael Neumann  * OTHER DEALINGS IN THE SOFTWARE.
2157e252bfSMichael Neumann  *
2257e252bfSMichael Neumann  */
2357e252bfSMichael Neumann 
2457e252bfSMichael Neumann #include <drm/drmP.h>
2557e252bfSMichael Neumann #include "radeon.h"
2657e252bfSMichael Neumann #include "trinityd.h"
2757e252bfSMichael Neumann #include "trinity_dpm.h"
2857e252bfSMichael Neumann #include "ppsmc.h"
2957e252bfSMichael Neumann 
trinity_notify_message_to_smu(struct radeon_device * rdev,u32 id)3057e252bfSMichael Neumann static int trinity_notify_message_to_smu(struct radeon_device *rdev, u32 id)
3157e252bfSMichael Neumann {
3257e252bfSMichael Neumann 	int i;
3357e252bfSMichael Neumann 	u32 v = 0;
3457e252bfSMichael Neumann 
3557e252bfSMichael Neumann 	WREG32(SMC_MESSAGE_0, id);
3657e252bfSMichael Neumann 	for (i = 0; i < rdev->usec_timeout; i++) {
3757e252bfSMichael Neumann 		if (RREG32(SMC_RESP_0) != 0)
3857e252bfSMichael Neumann 			break;
39c4ef309bSzrj 		udelay(1);
4057e252bfSMichael Neumann 	}
4157e252bfSMichael Neumann 	v = RREG32(SMC_RESP_0);
4257e252bfSMichael Neumann 
4357e252bfSMichael Neumann 	if (v != 1) {
4457e252bfSMichael Neumann 		if (v == 0xFF) {
4557e252bfSMichael Neumann 			DRM_ERROR("SMC failed to handle the message!\n");
4657e252bfSMichael Neumann 			return -EINVAL;
4757e252bfSMichael Neumann 		} else if (v == 0xFE) {
4857e252bfSMichael Neumann 			DRM_ERROR("Unknown SMC message!\n");
4957e252bfSMichael Neumann 			return -EINVAL;
5057e252bfSMichael Neumann 		}
5157e252bfSMichael Neumann 	}
5257e252bfSMichael Neumann 
5357e252bfSMichael Neumann 	return 0;
5457e252bfSMichael Neumann }
5557e252bfSMichael Neumann 
trinity_dpm_bapm_enable(struct radeon_device * rdev,bool enable)56*4cd92098Szrj int trinity_dpm_bapm_enable(struct radeon_device *rdev, bool enable)
57*4cd92098Szrj {
58*4cd92098Szrj 	if (enable)
59*4cd92098Szrj 		return trinity_notify_message_to_smu(rdev, PPSMC_MSG_EnableBAPM);
60*4cd92098Szrj 	else
61*4cd92098Szrj 		return trinity_notify_message_to_smu(rdev, PPSMC_MSG_DisableBAPM);
62*4cd92098Szrj }
63*4cd92098Szrj 
trinity_dpm_config(struct radeon_device * rdev,bool enable)6457e252bfSMichael Neumann int trinity_dpm_config(struct radeon_device *rdev, bool enable)
6557e252bfSMichael Neumann {
6657e252bfSMichael Neumann 	if (enable)
6757e252bfSMichael Neumann 		WREG32_SMC(SMU_SCRATCH0, 1);
6857e252bfSMichael Neumann 	else
6957e252bfSMichael Neumann 		WREG32_SMC(SMU_SCRATCH0, 0);
7057e252bfSMichael Neumann 
7157e252bfSMichael Neumann 	return trinity_notify_message_to_smu(rdev, PPSMC_MSG_DPM_Config);
7257e252bfSMichael Neumann }
7357e252bfSMichael Neumann 
trinity_dpm_force_state(struct radeon_device * rdev,u32 n)7457e252bfSMichael Neumann int trinity_dpm_force_state(struct radeon_device *rdev, u32 n)
7557e252bfSMichael Neumann {
7657e252bfSMichael Neumann 	WREG32_SMC(SMU_SCRATCH0, n);
7757e252bfSMichael Neumann 
7857e252bfSMichael Neumann 	return trinity_notify_message_to_smu(rdev, PPSMC_MSG_DPM_ForceState);
7957e252bfSMichael Neumann }
8057e252bfSMichael Neumann 
trinity_dpm_n_levels_disabled(struct radeon_device * rdev,u32 n)8157e252bfSMichael Neumann int trinity_dpm_n_levels_disabled(struct radeon_device *rdev, u32 n)
8257e252bfSMichael Neumann {
8357e252bfSMichael Neumann 	WREG32_SMC(SMU_SCRATCH0, n);
8457e252bfSMichael Neumann 
8557e252bfSMichael Neumann 	return trinity_notify_message_to_smu(rdev, PPSMC_MSG_DPM_N_LevelsDisabled);
8657e252bfSMichael Neumann }
8757e252bfSMichael Neumann 
trinity_uvd_dpm_config(struct radeon_device * rdev)8857e252bfSMichael Neumann int trinity_uvd_dpm_config(struct radeon_device *rdev)
8957e252bfSMichael Neumann {
9057e252bfSMichael Neumann 	return trinity_notify_message_to_smu(rdev, PPSMC_MSG_UVD_DPM_Config);
9157e252bfSMichael Neumann }
9257e252bfSMichael Neumann 
trinity_dpm_no_forced_level(struct radeon_device * rdev)9357e252bfSMichael Neumann int trinity_dpm_no_forced_level(struct radeon_device *rdev)
9457e252bfSMichael Neumann {
9557e252bfSMichael Neumann 	return trinity_notify_message_to_smu(rdev, PPSMC_MSG_NoForcedLevel);
9657e252bfSMichael Neumann }
9757e252bfSMichael Neumann 
trinity_dce_enable_voltage_adjustment(struct radeon_device * rdev,bool enable)9857e252bfSMichael Neumann int trinity_dce_enable_voltage_adjustment(struct radeon_device *rdev,
9957e252bfSMichael Neumann 					  bool enable)
10057e252bfSMichael Neumann {
10157e252bfSMichael Neumann 	if (enable)
10257e252bfSMichael Neumann 		return trinity_notify_message_to_smu(rdev, PPSMC_MSG_DCE_AllowVoltageAdjustment);
10357e252bfSMichael Neumann 	else
10457e252bfSMichael Neumann 		return trinity_notify_message_to_smu(rdev, PPSMC_MSG_DCE_RemoveVoltageAdjustment);
10557e252bfSMichael Neumann }
10657e252bfSMichael Neumann 
trinity_gfx_dynamic_mgpg_config(struct radeon_device * rdev)10757e252bfSMichael Neumann int trinity_gfx_dynamic_mgpg_config(struct radeon_device *rdev)
10857e252bfSMichael Neumann {
10957e252bfSMichael Neumann 	return trinity_notify_message_to_smu(rdev, PPSMC_MSG_PG_SIMD_Config);
11057e252bfSMichael Neumann }
11157e252bfSMichael Neumann 
trinity_acquire_mutex(struct radeon_device * rdev)11257e252bfSMichael Neumann void trinity_acquire_mutex(struct radeon_device *rdev)
11357e252bfSMichael Neumann {
11457e252bfSMichael Neumann 	int i;
11557e252bfSMichael Neumann 
11657e252bfSMichael Neumann 	WREG32(SMC_INT_REQ, 1);
11757e252bfSMichael Neumann 	for (i = 0; i < rdev->usec_timeout; i++) {
11857e252bfSMichael Neumann 		if ((RREG32(SMC_INT_REQ) & 0xffff) == 1)
11957e252bfSMichael Neumann 			break;
120c4ef309bSzrj 		udelay(1);
12157e252bfSMichael Neumann 	}
12257e252bfSMichael Neumann }
12357e252bfSMichael Neumann 
trinity_release_mutex(struct radeon_device * rdev)12457e252bfSMichael Neumann void trinity_release_mutex(struct radeon_device *rdev)
12557e252bfSMichael Neumann {
12657e252bfSMichael Neumann 	WREG32(SMC_INT_REQ, 0);
12757e252bfSMichael Neumann }
128