xref: /openbmc/linux/drivers/gpu/drm/radeon/trinity_smc.c (revision 0898782247ae533d1f4e47a06bc5d4870931b284)
1d70229f7SAlex Deucher /*
2d70229f7SAlex Deucher  * Copyright 2012 Advanced Micro Devices, Inc.
3d70229f7SAlex Deucher  *
4d70229f7SAlex Deucher  * Permission is hereby granted, free of charge, to any person obtaining a
5d70229f7SAlex Deucher  * copy of this software and associated documentation files (the "Software"),
6d70229f7SAlex Deucher  * to deal in the Software without restriction, including without limitation
7d70229f7SAlex Deucher  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8d70229f7SAlex Deucher  * and/or sell copies of the Software, and to permit persons to whom the
9d70229f7SAlex Deucher  * Software is furnished to do so, subject to the following conditions:
10d70229f7SAlex Deucher  *
11d70229f7SAlex Deucher  * The above copyright notice and this permission notice shall be included in
12d70229f7SAlex Deucher  * all copies or substantial portions of the Software.
13d70229f7SAlex Deucher  *
14d70229f7SAlex Deucher  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15d70229f7SAlex Deucher  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16d70229f7SAlex Deucher  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17d70229f7SAlex Deucher  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18d70229f7SAlex Deucher  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19d70229f7SAlex Deucher  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20d70229f7SAlex Deucher  * OTHER DEALINGS IN THE SOFTWARE.
21d70229f7SAlex Deucher  *
22d70229f7SAlex Deucher  */
23d70229f7SAlex Deucher 
24d70229f7SAlex Deucher #include "radeon.h"
25d70229f7SAlex Deucher #include "trinityd.h"
26d70229f7SAlex Deucher #include "trinity_dpm.h"
27d70229f7SAlex Deucher #include "ppsmc.h"
28d70229f7SAlex Deucher 
trinity_notify_message_to_smu(struct radeon_device * rdev,u32 id)29d70229f7SAlex Deucher static int trinity_notify_message_to_smu(struct radeon_device *rdev, u32 id)
30d70229f7SAlex Deucher {
31d70229f7SAlex Deucher 	int i;
32d70229f7SAlex Deucher 	u32 v = 0;
33d70229f7SAlex Deucher 
34d70229f7SAlex Deucher 	WREG32(SMC_MESSAGE_0, id);
35d70229f7SAlex Deucher 	for (i = 0; i < rdev->usec_timeout; i++) {
36d70229f7SAlex Deucher 		if (RREG32(SMC_RESP_0) != 0)
37d70229f7SAlex Deucher 			break;
38d70229f7SAlex Deucher 		udelay(1);
39d70229f7SAlex Deucher 	}
40d70229f7SAlex Deucher 	v = RREG32(SMC_RESP_0);
41d70229f7SAlex Deucher 
42d70229f7SAlex Deucher 	if (v != 1) {
43d70229f7SAlex Deucher 		if (v == 0xFF) {
44d70229f7SAlex Deucher 			DRM_ERROR("SMC failed to handle the message!\n");
45d70229f7SAlex Deucher 			return -EINVAL;
46d70229f7SAlex Deucher 		} else if (v == 0xFE) {
47d70229f7SAlex Deucher 			DRM_ERROR("Unknown SMC message!\n");
48d70229f7SAlex Deucher 			return -EINVAL;
49d70229f7SAlex Deucher 		}
50d70229f7SAlex Deucher 	}
51d70229f7SAlex Deucher 
52d70229f7SAlex Deucher 	return 0;
53d70229f7SAlex Deucher }
54d70229f7SAlex Deucher 
trinity_dpm_bapm_enable(struct radeon_device * rdev,bool enable)55*ef4e0365SAlex Deucher int trinity_dpm_bapm_enable(struct radeon_device *rdev, bool enable)
56*ef4e0365SAlex Deucher {
57*ef4e0365SAlex Deucher 	if (enable)
58*ef4e0365SAlex Deucher 		return trinity_notify_message_to_smu(rdev, PPSMC_MSG_EnableBAPM);
59*ef4e0365SAlex Deucher 	else
60*ef4e0365SAlex Deucher 		return trinity_notify_message_to_smu(rdev, PPSMC_MSG_DisableBAPM);
61*ef4e0365SAlex Deucher }
62*ef4e0365SAlex Deucher 
trinity_dpm_config(struct radeon_device * rdev,bool enable)63d70229f7SAlex Deucher int trinity_dpm_config(struct radeon_device *rdev, bool enable)
64d70229f7SAlex Deucher {
65d70229f7SAlex Deucher 	if (enable)
66d70229f7SAlex Deucher 		WREG32_SMC(SMU_SCRATCH0, 1);
67d70229f7SAlex Deucher 	else
68d70229f7SAlex Deucher 		WREG32_SMC(SMU_SCRATCH0, 0);
69d70229f7SAlex Deucher 
70d70229f7SAlex Deucher 	return trinity_notify_message_to_smu(rdev, PPSMC_MSG_DPM_Config);
71d70229f7SAlex Deucher }
72d70229f7SAlex Deucher 
trinity_dpm_force_state(struct radeon_device * rdev,u32 n)73d70229f7SAlex Deucher int trinity_dpm_force_state(struct radeon_device *rdev, u32 n)
74d70229f7SAlex Deucher {
75d70229f7SAlex Deucher 	WREG32_SMC(SMU_SCRATCH0, n);
76d70229f7SAlex Deucher 
77d70229f7SAlex Deucher 	return trinity_notify_message_to_smu(rdev, PPSMC_MSG_DPM_ForceState);
78d70229f7SAlex Deucher }
79d70229f7SAlex Deucher 
trinity_dpm_n_levels_disabled(struct radeon_device * rdev,u32 n)809b5de596SAlex Deucher int trinity_dpm_n_levels_disabled(struct radeon_device *rdev, u32 n)
819b5de596SAlex Deucher {
829b5de596SAlex Deucher 	WREG32_SMC(SMU_SCRATCH0, n);
839b5de596SAlex Deucher 
849b5de596SAlex Deucher 	return trinity_notify_message_to_smu(rdev, PPSMC_MSG_DPM_N_LevelsDisabled);
859b5de596SAlex Deucher }
869b5de596SAlex Deucher 
trinity_uvd_dpm_config(struct radeon_device * rdev)870c4aaeaeSAlex Deucher int trinity_uvd_dpm_config(struct radeon_device *rdev)
880c4aaeaeSAlex Deucher {
890c4aaeaeSAlex Deucher 	return trinity_notify_message_to_smu(rdev, PPSMC_MSG_UVD_DPM_Config);
900c4aaeaeSAlex Deucher }
910c4aaeaeSAlex Deucher 
trinity_dpm_no_forced_level(struct radeon_device * rdev)92d70229f7SAlex Deucher int trinity_dpm_no_forced_level(struct radeon_device *rdev)
93d70229f7SAlex Deucher {
94d70229f7SAlex Deucher 	return trinity_notify_message_to_smu(rdev, PPSMC_MSG_NoForcedLevel);
95d70229f7SAlex Deucher }
96d70229f7SAlex Deucher 
trinity_dce_enable_voltage_adjustment(struct radeon_device * rdev,bool enable)97d70229f7SAlex Deucher int trinity_dce_enable_voltage_adjustment(struct radeon_device *rdev,
98d70229f7SAlex Deucher 					  bool enable)
99d70229f7SAlex Deucher {
100d70229f7SAlex Deucher 	if (enable)
101d70229f7SAlex Deucher 		return trinity_notify_message_to_smu(rdev, PPSMC_MSG_DCE_AllowVoltageAdjustment);
102d70229f7SAlex Deucher 	else
103d70229f7SAlex Deucher 		return trinity_notify_message_to_smu(rdev, PPSMC_MSG_DCE_RemoveVoltageAdjustment);
104d70229f7SAlex Deucher }
105d70229f7SAlex Deucher 
trinity_gfx_dynamic_mgpg_config(struct radeon_device * rdev)106d70229f7SAlex Deucher int trinity_gfx_dynamic_mgpg_config(struct radeon_device *rdev)
107d70229f7SAlex Deucher {
108d70229f7SAlex Deucher 	return trinity_notify_message_to_smu(rdev, PPSMC_MSG_PG_SIMD_Config);
109d70229f7SAlex Deucher }
110d70229f7SAlex Deucher 
trinity_acquire_mutex(struct radeon_device * rdev)111d70229f7SAlex Deucher void trinity_acquire_mutex(struct radeon_device *rdev)
112d70229f7SAlex Deucher {
113d70229f7SAlex Deucher 	int i;
114d70229f7SAlex Deucher 
115d70229f7SAlex Deucher 	WREG32(SMC_INT_REQ, 1);
116d70229f7SAlex Deucher 	for (i = 0; i < rdev->usec_timeout; i++) {
117d70229f7SAlex Deucher 		if ((RREG32(SMC_INT_REQ) & 0xffff) == 1)
118d70229f7SAlex Deucher 			break;
119d70229f7SAlex Deucher 		udelay(1);
120d70229f7SAlex Deucher 	}
121d70229f7SAlex Deucher }
122d70229f7SAlex Deucher 
trinity_release_mutex(struct radeon_device * rdev)123d70229f7SAlex Deucher void trinity_release_mutex(struct radeon_device *rdev)
124d70229f7SAlex Deucher {
125d70229f7SAlex Deucher 	WREG32(SMC_INT_REQ, 0);
126d70229f7SAlex Deucher }
127