[PATCH 3/3] drm/amd/powerplay: support hwmon max/min fan speed setting on Vega20

Evan Quan evan.quan at amd.com
Wed Oct 24 08:11:41 UTC 2018


Added support for hwmon max/min fan speed setting on Vega20.

Change-Id: Ieab42c744d6c54f8b85a71be80f7c6832ae7352b
Signed-off-by: Evan Quan <evan.quan at amd.com>
---
 .../drm/amd/powerplay/hwmgr/vega20_hwmgr.c    |  4 ++
 .../drm/amd/powerplay/hwmgr/vega20_thermal.c  | 56 ++++++++++++++++++-
 .../drm/amd/powerplay/hwmgr/vega20_thermal.h  |  4 ++
 3 files changed, 62 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
index 57143d51e3ee..2513e6be3219 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c
@@ -3539,6 +3539,10 @@ static const struct pp_hwmgr_func vega20_hwmgr_funcs = {
 		vega20_get_fan_control_mode,
 	.set_fan_control_mode =
 		vega20_set_fan_control_mode,
+	.set_fan_speed_max_rpm =
+		vega20_fan_ctrl_set_fan_speed_max_rpm,
+	.set_fan_speed_min_rpm =
+		vega20_fan_ctrl_set_fan_speed_min_rpm,
 	/* smu memory related */
 	.notify_cac_buffer_info =
 		vega20_notify_cac_buffer_info,
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_thermal.c b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_thermal.c
index ede54e87e287..da9fd2168dcb 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_thermal.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_thermal.c
@@ -118,7 +118,6 @@ int vega20_fan_ctrl_get_fan_speed_percent(struct pp_hwmgr *hwmgr,
 		uint32_t *speed)
 {
 	struct vega20_hwmgr *data = (struct vega20_hwmgr *)(hwmgr->backend);
-	PPTable_t *pp_table = &(data->smc_state_table.pp_table);
 	uint32_t current_rpm, percent = 0;
 	int ret = 0;
 
@@ -126,7 +125,8 @@ int vega20_fan_ctrl_get_fan_speed_percent(struct pp_hwmgr *hwmgr,
 	if (ret)
 		return ret;
 
-	percent = current_rpm * 100 / pp_table->FanMaximumRpm;
+	percent = (current_rpm * 100) /
+		hwmgr->thermal_controller.fanInfo.ulMaxRPM;
 
 	*speed = percent > 100 ? 100 : percent;
 
@@ -208,6 +208,58 @@ int vega20_fan_ctrl_set_fan_speed_rpm(struct pp_hwmgr *hwmgr, uint32_t speed)
 	return vega20_fan_ctrl_set_static_mode(hwmgr, FDO_PWM_MODE_STATIC_RPM);
 }
 
+int vega20_fan_ctrl_set_fan_speed_max_rpm(struct pp_hwmgr *hwmgr, uint32_t speed)
+{
+	struct vega20_hwmgr *data = (struct vega20_hwmgr *)(hwmgr->backend);
+	struct vega20_od8_settings *od8_settings = &(data->od8_settings);
+	int ret = 0;
+
+	if ((od8_settings->overdrive8_capabilities & OD8_ACOUSTIC_LIMIT_SCLK) &&
+	    (speed > od8_settings->od8_settings_array[OD8_SETTING_FAN_ACOUSTIC_LIMIT].max_value ||
+	     speed < od8_settings->od8_settings_array[OD8_SETTING_FAN_ACOUSTIC_LIMIT].min_value))
+		return -EINVAL;
+
+	ret = smum_send_msg_to_smc_with_parameter(hwmgr,
+			PPSMC_MSG_SetFanMaxRpm,
+			speed);
+	PP_ASSERT_WITH_CODE(!ret,
+			"Set FanMaxRpm Failed!",
+			return ret);
+
+	hwmgr->thermal_controller.fanInfo.ulMinRPM =
+		(speed * hwmgr->thermal_controller.fanInfo.ulMinPWM) / 255;
+
+	return ret;
+}
+
+int vega20_fan_ctrl_set_fan_speed_min_rpm(struct pp_hwmgr *hwmgr, uint32_t speed)
+{
+	struct vega20_hwmgr *data = (struct vega20_hwmgr *)(hwmgr->backend);
+	struct vega20_od8_settings *od8_settings = &(data->od8_settings);
+	int ret = 0;
+	uint32_t pwm = 0;
+
+	if ((od8_settings->overdrive8_capabilities & OD8_FAN_SPEED_MIN) &&
+	    (speed > od8_settings->od8_settings_array[OD8_FAN_SPEED_MIN].max_value ||
+	     speed < od8_settings->od8_settings_array[OD8_FAN_SPEED_MIN].min_value))
+		return -EINVAL;
+
+	if (speed > hwmgr->thermal_controller.fanInfo.ulMaxRPM)
+		return -EINVAL;
+
+	pwm = (speed * 255) / hwmgr->thermal_controller.fanInfo.ulMaxRPM;
+	ret = smum_send_msg_to_smc_with_parameter(hwmgr,
+			PPSMC_MSG_SetFanMinPwm,
+			pwm);
+	PP_ASSERT_WITH_CODE(!ret,
+			"Set FanMinPwm Failed!",
+			return ret);
+
+	hwmgr->thermal_controller.fanInfo.ulMinPWM = pwm;
+
+	return ret;
+}
+
 /**
 * Reads the remote temperature from the SIslands thermal controller.
 *
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_thermal.h b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_thermal.h
index 2d1769bbd24e..ddfc950e90ca 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_thermal.h
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_thermal.h
@@ -56,6 +56,10 @@ extern int vega20_fan_ctrl_get_fan_speed_rpm(struct pp_hwmgr *hwmgr,
 		uint32_t *speed);
 extern int vega20_fan_ctrl_set_fan_speed_rpm(struct pp_hwmgr *hwmgr,
 		uint32_t speed);
+extern int vega20_fan_ctrl_set_fan_speed_max_rpm(struct pp_hwmgr *hwmgr,
+		uint32_t speed);
+extern int vega20_fan_ctrl_set_fan_speed_min_rpm(struct pp_hwmgr *hwmgr,
+		uint32_t speed);
 extern int vega20_fan_ctrl_get_fan_speed_percent(struct pp_hwmgr *hwmgr,
 		uint32_t *speed);
 extern int vega20_fan_ctrl_set_fan_speed_percent(struct pp_hwmgr *hwmgr,
-- 
2.19.1



More information about the amd-gfx mailing list