[PATCH 4/6] drm/amd/powerplay: add get_temperature interface for raven

Hawking Zhang Hawking.Zhang at amd.com
Wed May 24 11:13:45 UTC 2017


Change-Id: I542b3a5f4e2955dda0b7c9f8c32512b2888ab1c3
Signed-off-by: Hawking Zhang <Hawking.Zhang at amd.com>
---
 drivers/gpu/drm/amd/powerplay/hwmgr/rv_hwmgr.c | 27 ++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/rv_hwmgr.c b/drivers/gpu/drm/amd/powerplay/hwmgr/rv_hwmgr.c
index 8a1f0d9..01413ca1 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/rv_hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/rv_hwmgr.c
@@ -35,6 +35,7 @@
 #include "rv_hwmgr.h"
 #include "power_state.h"
 #include "rv_smumgr.h"
+#include "pp_soc15.h"
 
 #define RAVEN_MAX_DEEPSLEEP_DIVIDER_ID     5
 #define RAVEN_MINIMUM_ENGINE_CLOCK         800   //8Mhz, the low boundary of engine clock allowed on this chip
@@ -42,7 +43,6 @@
 #define RAVEN_DISPCLK_BYPASS_THRESHOLD     10000 //100mhz
 #define SMC_RAM_END                     0x40000
 
-
 static const unsigned long PhwRaven_Magic = (unsigned long) PHM_Rv_Magic;
 
 struct phm_vq_budgeting_settings RV_VQTable[] =
@@ -574,6 +574,7 @@ static int rv_hwmgr_backend_init(struct pp_hwmgr *hwmgr)
 	hwmgr->platform_descriptor.minimumClocksReductionPercentage = 50;
 
 	rv_init_vq_budget_table(hwmgr);
+
 	return result;
 }
 
@@ -959,10 +960,32 @@ static int rv_get_max_high_clocks(struct pp_hwmgr *hwmgr, struct amd_pp_simple_c
 	return -EINVAL;
 }
 
+static int rv_thermal_get_temperature(struct pp_hwmgr *hwmgr)
+{
+	uint32_t reg_offset = soc15_get_register_offset(THM_HWID, 0,
+			mmTHM_TCON_CUR_TMP_BASE_IDX, mmTHM_TCON_CUR_TMP);
+	uint32_t reg_value = cgs_read_register(hwmgr->device, reg_offset);
+	int cur_temp =
+		(reg_value & THM_TCON_CUR_TMP__CUR_TEMP_MASK) >> THM_TCON_CUR_TMP__CUR_TEMP__SHIFT;
+
+	if (cur_temp & THM_TCON_CUR_TMP__CUR_TEMP_RANGE_SEL_MASK)
+		cur_temp = ((cur_temp / 8) - 49) * PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
+	else
+		cur_temp = (cur_temp / 8) * PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
+
+	return cur_temp;
+}
+
 static int rv_read_sensor(struct pp_hwmgr *hwmgr, int idx,
 			  void *value, int *size)
 {
-	return -EINVAL;
+	switch (idx) {
+	case AMDGPU_PP_SENSOR_GPU_TEMP:
+		*((uint32_t *)value) = rv_thermal_get_temperature(hwmgr);
+		return 0;
+	default:
+		return -EINVAL;
+	}
 }
 
 static const struct pp_hwmgr_func rv_hwmgr_funcs = {
-- 
2.7.4



More information about the amd-gfx mailing list