All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] drm/amd/powerplay: retrieve correct minimum RPM speed by MinPWM
@ 2018-10-24  8:11 Evan Quan
       [not found] ` <20181024081141.18647-1-evan.quan-5C7GfCeVMHo@public.gmane.org>
  0 siblings, 1 reply; 9+ messages in thread
From: Evan Quan @ 2018-10-24  8:11 UTC (permalink / raw)
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW; +Cc: Evan Quan

Retrieve the correct minimum RPM speed for Vega20. And MinPWM
is needed to recalculate the MinRPM on maximum RPM speed change.

Change-Id: I552bd8ada74b0336257ea1a10c004b5211acc36f
Signed-off-by: Evan Quan <evan.quan@amd.com>
---
 drivers/gpu/drm/amd/powerplay/hwmgr/vega20_processpptables.c | 4 +++-
 drivers/gpu/drm/amd/powerplay/inc/hwmgr.h                    | 1 +
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_processpptables.c b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_processpptables.c
index f7e8bbdc20b0..7170fb36b67a 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_processpptables.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_processpptables.c
@@ -805,7 +805,9 @@ static int init_powerplay_table_information(
 
 	hwmgr->thermal_controller.ucType = powerplay_table->ucThermalControllerType;
 	pptable_information->uc_thermal_controller_type = powerplay_table->ucThermalControllerType;
-	hwmgr->thermal_controller.fanInfo.ulMinRPM = 0;
+	hwmgr->thermal_controller.fanInfo.ulMinPWM = powerplay_table->smcPPTable.FanPwmMin;
+	hwmgr->thermal_controller.fanInfo.ulMinRPM = (powerplay_table->smcPPTable.FanPwmMin *
+		powerplay_table->smcPPTable.FanMaximumRpm) / 255;
 	hwmgr->thermal_controller.fanInfo.ulMaxRPM = powerplay_table->smcPPTable.FanMaximumRpm;
 
 	set_hw_cap(hwmgr,
diff --git a/drivers/gpu/drm/amd/powerplay/inc/hwmgr.h b/drivers/gpu/drm/amd/powerplay/inc/hwmgr.h
index e5a60aa44b5d..687f73fe4cf5 100644
--- a/drivers/gpu/drm/amd/powerplay/inc/hwmgr.h
+++ b/drivers/gpu/drm/amd/powerplay/inc/hwmgr.h
@@ -628,6 +628,7 @@ struct pp_fan_info {
 	uint8_t   ucTachometerPulsesPerRevolution;
 	uint32_t   ulMinRPM;
 	uint32_t   ulMaxRPM;
+	uint32_t   ulMinPWM;
 };
 
 struct pp_advance_fan_control_parameters {
-- 
2.19.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/3] drm/amd/powerplay: added hwmon interfaces for setting max/min fan speed
       [not found] ` <20181024081141.18647-1-evan.quan-5C7GfCeVMHo@public.gmane.org>
@ 2018-10-24  8:11   ` Evan Quan
       [not found]     ` <20181024081141.18647-2-evan.quan-5C7GfCeVMHo@public.gmane.org>
  2018-10-24  8:11   ` [PATCH 3/3] drm/amd/powerplay: support hwmon max/min fan speed setting on Vega20 Evan Quan
  1 sibling, 1 reply; 9+ messages in thread
From: Evan Quan @ 2018-10-24  8:11 UTC (permalink / raw)
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW; +Cc: Evan Quan

New hwmon interfaces for maximum and minimum fan speed setting.

Change-Id: Ic9ec9f2427c6d3425e1c7e7b765d7d01a92f9a26
Signed-off-by: Evan Quan <evan.quan@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h       |  6 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c        | 56 ++++++++++++++++++-
 .../gpu/drm/amd/include/kgd_pp_interface.h    |  2 +
 drivers/gpu/drm/amd/powerplay/amd_powerplay.c | 46 +++++++++++++++
 drivers/gpu/drm/amd/powerplay/inc/hwmgr.h     |  2 +
 5 files changed, 110 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h
index f972cd156795..12c4e461a7bc 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h
@@ -364,6 +364,12 @@ enum amdgpu_pcie_gen {
 		((adev)->powerplay.pp_funcs->enable_mgpu_fan_boost(\
 			(adev)->powerplay.pp_handle))
 
+#define amdgpu_dpm_set_fan_speed_max_rpm(adev, s) \
+		((adev)->powerplay.pp_funcs->set_fan_speed_max_rpm)((adev)->powerplay.pp_handle, (s))
+
+#define amdgpu_dpm_set_fan_speed_min_rpm(adev, s) \
+		((adev)->powerplay.pp_funcs->set_fan_speed_min_rpm)((adev)->powerplay.pp_handle, (s))
+
 struct amdgpu_dpm {
 	struct amdgpu_ps        *ps;
 	/* number of valid power states */
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
index 8e94255654ed..92da37bb51ba 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
@@ -1265,6 +1265,32 @@ static ssize_t amdgpu_hwmon_get_fan1_min(struct device *dev,
 	return snprintf(buf, PAGE_SIZE, "%d\n", min_rpm);
 }
 
+static ssize_t amdgpu_hwmon_set_fan1_min(struct device *dev,
+				     struct device_attribute *attr,
+				     const char *buf, size_t count)
+{
+	struct amdgpu_device *adev = dev_get_drvdata(dev);
+	int err;
+	u32 value;
+
+	/* Can't adjust fan when the card is off */
+	if  ((adev->flags & AMD_IS_PX) &&
+	     (adev->ddev->switch_power_state != DRM_SWITCH_POWER_ON))
+		return -EINVAL;
+
+	err = kstrtou32(buf, 10, &value);
+	if (err)
+		return err;
+
+	if (adev->powerplay.pp_funcs->set_fan_speed_min_rpm) {
+		err = amdgpu_dpm_set_fan_speed_min_rpm(adev, value);
+		if (err)
+			return err;
+	}
+
+	return count;
+}
+
 static ssize_t amdgpu_hwmon_get_fan1_max(struct device *dev,
 					 struct device_attribute *attr,
 					 char *buf)
@@ -1285,6 +1311,32 @@ static ssize_t amdgpu_hwmon_get_fan1_max(struct device *dev,
 	return snprintf(buf, PAGE_SIZE, "%d\n", max_rpm);
 }
 
+static ssize_t amdgpu_hwmon_set_fan1_max(struct device *dev,
+				     struct device_attribute *attr,
+				     const char *buf, size_t count)
+{
+	struct amdgpu_device *adev = dev_get_drvdata(dev);
+	int err;
+	u32 value;
+
+	/* Can't adjust fan when the card is off */
+	if  ((adev->flags & AMD_IS_PX) &&
+	     (adev->ddev->switch_power_state != DRM_SWITCH_POWER_ON))
+		return -EINVAL;
+
+	err = kstrtou32(buf, 10, &value);
+	if (err)
+		return err;
+
+	if (adev->powerplay.pp_funcs->set_fan_speed_max_rpm) {
+		err = amdgpu_dpm_set_fan_speed_max_rpm(adev, value);
+		if (err)
+			return err;
+	}
+
+	return count;
+}
+
 static ssize_t amdgpu_hwmon_get_fan1_target(struct device *dev,
 					   struct device_attribute *attr,
 					   char *buf)
@@ -1628,8 +1680,8 @@ static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_pwm1_
 static SENSOR_DEVICE_ATTR(pwm1_min, S_IRUGO, amdgpu_hwmon_get_pwm1_min, NULL, 0);
 static SENSOR_DEVICE_ATTR(pwm1_max, S_IRUGO, amdgpu_hwmon_get_pwm1_max, NULL, 0);
 static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, amdgpu_hwmon_get_fan1_input, NULL, 0);
-static SENSOR_DEVICE_ATTR(fan1_min, S_IRUGO, amdgpu_hwmon_get_fan1_min, NULL, 0);
-static SENSOR_DEVICE_ATTR(fan1_max, S_IRUGO, amdgpu_hwmon_get_fan1_max, NULL, 0);
+static SENSOR_DEVICE_ATTR(fan1_min, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_fan1_min, amdgpu_hwmon_set_fan1_min, 0);
+static SENSOR_DEVICE_ATTR(fan1_max, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_fan1_max, amdgpu_hwmon_set_fan1_max, 0);
 static SENSOR_DEVICE_ATTR(fan1_target, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_fan1_target, amdgpu_hwmon_set_fan1_target, 0);
 static SENSOR_DEVICE_ATTR(fan1_enable, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_fan1_enable, amdgpu_hwmon_set_fan1_enable, 0);
 static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, amdgpu_hwmon_show_vddgfx, NULL, 0);
diff --git a/drivers/gpu/drm/amd/include/kgd_pp_interface.h b/drivers/gpu/drm/amd/include/kgd_pp_interface.h
index 980e696989b1..1af55997bdb9 100644
--- a/drivers/gpu/drm/amd/include/kgd_pp_interface.h
+++ b/drivers/gpu/drm/amd/include/kgd_pp_interface.h
@@ -276,6 +276,8 @@ struct amd_pm_funcs {
 		struct amd_pp_simple_clock_info *clocks);
 	int (*notify_smu_enable_pwe)(void *handle);
 	int (*enable_mgpu_fan_boost)(void *handle);
+	int (*set_fan_speed_max_rpm)(void *handle, uint32_t rpm);
+	int (*set_fan_speed_min_rpm)(void *handle, uint32_t rpm);
 };
 
 #endif
diff --git a/drivers/gpu/drm/amd/powerplay/amd_powerplay.c b/drivers/gpu/drm/amd/powerplay/amd_powerplay.c
index 586f1ff9f73e..f10237b4d057 100644
--- a/drivers/gpu/drm/amd/powerplay/amd_powerplay.c
+++ b/drivers/gpu/drm/amd/powerplay/amd_powerplay.c
@@ -603,6 +603,50 @@ static int pp_dpm_set_fan_speed_rpm(void *handle, uint32_t rpm)
 	return ret;
 }
 
+static int pp_dpm_set_fan_speed_max_rpm(void *handle, uint32_t rpm)
+{
+	struct pp_hwmgr *hwmgr = handle;
+	int ret = 0;
+
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
+
+	if (hwmgr->hwmgr_func->set_fan_speed_max_rpm == NULL) {
+		pr_info("%s was not implemented.\n", __func__);
+		return -EOPNOTSUPP;
+	}
+	mutex_lock(&hwmgr->smu_lock);
+	ret = hwmgr->hwmgr_func->set_fan_speed_max_rpm(hwmgr, rpm);
+	mutex_unlock(&hwmgr->smu_lock);
+
+	if (!ret)
+		hwmgr->thermal_controller.fanInfo.ulMaxRPM = rpm;
+
+	return ret;
+}
+
+static int pp_dpm_set_fan_speed_min_rpm(void *handle, uint32_t rpm)
+{
+	struct pp_hwmgr *hwmgr = handle;
+	int ret = 0;
+
+	if (!hwmgr || !hwmgr->pm_en)
+		return -EINVAL;
+
+	if (hwmgr->hwmgr_func->set_fan_speed_min_rpm == NULL) {
+		pr_info("%s was not implemented.\n", __func__);
+		return -EOPNOTSUPP;
+	}
+	mutex_lock(&hwmgr->smu_lock);
+	ret = hwmgr->hwmgr_func->set_fan_speed_min_rpm(hwmgr, rpm);
+	mutex_unlock(&hwmgr->smu_lock);
+
+	if (!ret)
+		hwmgr->thermal_controller.fanInfo.ulMinRPM = rpm;
+
+	return ret;
+}
+
 static int pp_dpm_get_pp_num_states(void *handle,
 		struct pp_states_info *data)
 {
@@ -1342,6 +1386,8 @@ static const struct amd_pm_funcs pp_dpm_funcs = {
 	.get_fan_speed_percent = pp_dpm_get_fan_speed_percent,
 	.get_fan_speed_rpm = pp_dpm_get_fan_speed_rpm,
 	.set_fan_speed_rpm = pp_dpm_set_fan_speed_rpm,
+	.set_fan_speed_max_rpm = pp_dpm_set_fan_speed_max_rpm,
+	.set_fan_speed_min_rpm = pp_dpm_set_fan_speed_min_rpm,
 	.get_pp_num_states = pp_dpm_get_pp_num_states,
 	.get_pp_table = pp_dpm_get_pp_table,
 	.set_pp_table = pp_dpm_set_pp_table,
diff --git a/drivers/gpu/drm/amd/powerplay/inc/hwmgr.h b/drivers/gpu/drm/amd/powerplay/inc/hwmgr.h
index 687f73fe4cf5..0242bc039a48 100644
--- a/drivers/gpu/drm/amd/powerplay/inc/hwmgr.h
+++ b/drivers/gpu/drm/amd/powerplay/inc/hwmgr.h
@@ -269,6 +269,8 @@ struct pp_hwmgr_func {
 	int (*get_fan_speed_percent)(struct pp_hwmgr *hwmgr, uint32_t *speed);
 	int (*set_fan_speed_rpm)(struct pp_hwmgr *hwmgr, uint32_t percent);
 	int (*get_fan_speed_rpm)(struct pp_hwmgr *hwmgr, uint32_t *speed);
+	int (*set_fan_speed_max_rpm)(struct pp_hwmgr *hwmgr, uint32_t max_rpm);
+	int (*set_fan_speed_min_rpm)(struct pp_hwmgr *hwmgr, uint32_t min_rpm);
 	int (*reset_fan_speed_to_default)(struct pp_hwmgr *hwmgr);
 	int (*uninitialize_thermal_controller)(struct pp_hwmgr *hwmgr);
 	int (*register_irq_handlers)(struct pp_hwmgr *hwmgr);
-- 
2.19.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/3] drm/amd/powerplay: support hwmon max/min fan speed setting on Vega20
       [not found] ` <20181024081141.18647-1-evan.quan-5C7GfCeVMHo@public.gmane.org>
  2018-10-24  8:11   ` [PATCH 2/3] drm/amd/powerplay: added hwmon interfaces for setting max/min fan speed Evan Quan
@ 2018-10-24  8:11   ` Evan Quan
       [not found]     ` <20181024081141.18647-3-evan.quan-5C7GfCeVMHo@public.gmane.org>
  1 sibling, 1 reply; 9+ messages in thread
From: Evan Quan @ 2018-10-24  8:11 UTC (permalink / raw)
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW; +Cc: Evan Quan

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

Change-Id: Ieab42c744d6c54f8b85a71be80f7c6832ae7352b
Signed-off-by: Evan Quan <evan.quan@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

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/3] drm/amd/powerplay: added hwmon interfaces for setting max/min fan speed
       [not found]     ` <20181024081141.18647-2-evan.quan-5C7GfCeVMHo@public.gmane.org>
@ 2018-10-24  8:36       ` Zhu, Rex
       [not found]         ` <BYAPR12MB2775F650496C7DA583461501FBF60-ZGDeBxoHBPmJeBUhB162ZQdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
  0 siblings, 1 reply; 9+ messages in thread
From: Zhu, Rex @ 2018-10-24  8:36 UTC (permalink / raw)
  To: Quan, Evan, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW


[-- Attachment #1.1: Type: text/plain, Size: 10045 bytes --]

One question: how to exit the max/min fan speed and return to auto mode?


Best Regards

Rex



________________________________
From: amd-gfx <amd-gfx-bounces-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org> on behalf of Evan Quan <evan.quan-5C7GfCeVMHo@public.gmane.org>
Sent: Wednesday, October 24, 2018 4:11 PM
To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
Cc: Quan, Evan
Subject: [PATCH 2/3] drm/amd/powerplay: added hwmon interfaces for setting max/min fan speed

New hwmon interfaces for maximum and minimum fan speed setting.

Change-Id: Ic9ec9f2427c6d3425e1c7e7b765d7d01a92f9a26
Signed-off-by: Evan Quan <evan.quan-5C7GfCeVMHo@public.gmane.org>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h       |  6 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c        | 56 ++++++++++++++++++-
 .../gpu/drm/amd/include/kgd_pp_interface.h    |  2 +
 drivers/gpu/drm/amd/powerplay/amd_powerplay.c | 46 +++++++++++++++
 drivers/gpu/drm/amd/powerplay/inc/hwmgr.h     |  2 +
 5 files changed, 110 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h
index f972cd156795..12c4e461a7bc 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h
@@ -364,6 +364,12 @@ enum amdgpu_pcie_gen {
                 ((adev)->powerplay.pp_funcs->enable_mgpu_fan_boost(\
                         (adev)->powerplay.pp_handle))

+#define amdgpu_dpm_set_fan_speed_max_rpm(adev, s) \
+               ((adev)->powerplay.pp_funcs->set_fan_speed_max_rpm)((adev)->powerplay.pp_handle, (s))
+
+#define amdgpu_dpm_set_fan_speed_min_rpm(adev, s) \
+               ((adev)->powerplay.pp_funcs->set_fan_speed_min_rpm)((adev)->powerplay.pp_handle, (s))
+
 struct amdgpu_dpm {
         struct amdgpu_ps        *ps;
         /* number of valid power states */
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
index 8e94255654ed..92da37bb51ba 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
@@ -1265,6 +1265,32 @@ static ssize_t amdgpu_hwmon_get_fan1_min(struct device *dev,
         return snprintf(buf, PAGE_SIZE, "%d\n", min_rpm);
 }

+static ssize_t amdgpu_hwmon_set_fan1_min(struct device *dev,
+                                    struct device_attribute *attr,
+                                    const char *buf, size_t count)
+{
+       struct amdgpu_device *adev = dev_get_drvdata(dev);
+       int err;
+       u32 value;
+
+       /* Can't adjust fan when the card is off */
+       if  ((adev->flags & AMD_IS_PX) &&
+            (adev->ddev->switch_power_state != DRM_SWITCH_POWER_ON))
+               return -EINVAL;
+
+       err = kstrtou32(buf, 10, &value);
+       if (err)
+               return err;
+
+       if (adev->powerplay.pp_funcs->set_fan_speed_min_rpm) {
+               err = amdgpu_dpm_set_fan_speed_min_rpm(adev, value);
+               if (err)
+                       return err;
+       }
+
+       return count;
+}
+
 static ssize_t amdgpu_hwmon_get_fan1_max(struct device *dev,
                                          struct device_attribute *attr,
                                          char *buf)
@@ -1285,6 +1311,32 @@ static ssize_t amdgpu_hwmon_get_fan1_max(struct device *dev,
         return snprintf(buf, PAGE_SIZE, "%d\n", max_rpm);
 }

+static ssize_t amdgpu_hwmon_set_fan1_max(struct device *dev,
+                                    struct device_attribute *attr,
+                                    const char *buf, size_t count)
+{
+       struct amdgpu_device *adev = dev_get_drvdata(dev);
+       int err;
+       u32 value;
+
+       /* Can't adjust fan when the card is off */
+       if  ((adev->flags & AMD_IS_PX) &&
+            (adev->ddev->switch_power_state != DRM_SWITCH_POWER_ON))
+               return -EINVAL;
+
+       err = kstrtou32(buf, 10, &value);
+       if (err)
+               return err;
+
+       if (adev->powerplay.pp_funcs->set_fan_speed_max_rpm) {
+               err = amdgpu_dpm_set_fan_speed_max_rpm(adev, value);
+               if (err)
+                       return err;
+       }
+
+       return count;
+}
+
 static ssize_t amdgpu_hwmon_get_fan1_target(struct device *dev,
                                            struct device_attribute *attr,
                                            char *buf)
@@ -1628,8 +1680,8 @@ static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_pwm1_
 static SENSOR_DEVICE_ATTR(pwm1_min, S_IRUGO, amdgpu_hwmon_get_pwm1_min, NULL, 0);
 static SENSOR_DEVICE_ATTR(pwm1_max, S_IRUGO, amdgpu_hwmon_get_pwm1_max, NULL, 0);
 static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, amdgpu_hwmon_get_fan1_input, NULL, 0);
-static SENSOR_DEVICE_ATTR(fan1_min, S_IRUGO, amdgpu_hwmon_get_fan1_min, NULL, 0);
-static SENSOR_DEVICE_ATTR(fan1_max, S_IRUGO, amdgpu_hwmon_get_fan1_max, NULL, 0);
+static SENSOR_DEVICE_ATTR(fan1_min, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_fan1_min, amdgpu_hwmon_set_fan1_min, 0);
+static SENSOR_DEVICE_ATTR(fan1_max, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_fan1_max, amdgpu_hwmon_set_fan1_max, 0);
 static SENSOR_DEVICE_ATTR(fan1_target, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_fan1_target, amdgpu_hwmon_set_fan1_target, 0);
 static SENSOR_DEVICE_ATTR(fan1_enable, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_fan1_enable, amdgpu_hwmon_set_fan1_enable, 0);
 static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, amdgpu_hwmon_show_vddgfx, NULL, 0);
diff --git a/drivers/gpu/drm/amd/include/kgd_pp_interface.h b/drivers/gpu/drm/amd/include/kgd_pp_interface.h
index 980e696989b1..1af55997bdb9 100644
--- a/drivers/gpu/drm/amd/include/kgd_pp_interface.h
+++ b/drivers/gpu/drm/amd/include/kgd_pp_interface.h
@@ -276,6 +276,8 @@ struct amd_pm_funcs {
                 struct amd_pp_simple_clock_info *clocks);
         int (*notify_smu_enable_pwe)(void *handle);
         int (*enable_mgpu_fan_boost)(void *handle);
+       int (*set_fan_speed_max_rpm)(void *handle, uint32_t rpm);
+       int (*set_fan_speed_min_rpm)(void *handle, uint32_t rpm);
 };

 #endif
diff --git a/drivers/gpu/drm/amd/powerplay/amd_powerplay.c b/drivers/gpu/drm/amd/powerplay/amd_powerplay.c
index 586f1ff9f73e..f10237b4d057 100644
--- a/drivers/gpu/drm/amd/powerplay/amd_powerplay.c
+++ b/drivers/gpu/drm/amd/powerplay/amd_powerplay.c
@@ -603,6 +603,50 @@ static int pp_dpm_set_fan_speed_rpm(void *handle, uint32_t rpm)
         return ret;
 }

+static int pp_dpm_set_fan_speed_max_rpm(void *handle, uint32_t rpm)
+{
+       struct pp_hwmgr *hwmgr = handle;
+       int ret = 0;
+
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
+
+       if (hwmgr->hwmgr_func->set_fan_speed_max_rpm == NULL) {
+               pr_info("%s was not implemented.\n", __func__);
+               return -EOPNOTSUPP;
+       }
+       mutex_lock(&hwmgr->smu_lock);
+       ret = hwmgr->hwmgr_func->set_fan_speed_max_rpm(hwmgr, rpm);
+       mutex_unlock(&hwmgr->smu_lock);
+
+       if (!ret)
+               hwmgr->thermal_controller.fanInfo.ulMaxRPM = rpm;
+
+       return ret;
+}
+
+static int pp_dpm_set_fan_speed_min_rpm(void *handle, uint32_t rpm)
+{
+       struct pp_hwmgr *hwmgr = handle;
+       int ret = 0;
+
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
+
+       if (hwmgr->hwmgr_func->set_fan_speed_min_rpm == NULL) {
+               pr_info("%s was not implemented.\n", __func__);
+               return -EOPNOTSUPP;
+       }
+       mutex_lock(&hwmgr->smu_lock);
+       ret = hwmgr->hwmgr_func->set_fan_speed_min_rpm(hwmgr, rpm);
+       mutex_unlock(&hwmgr->smu_lock);
+
+       if (!ret)
+               hwmgr->thermal_controller.fanInfo.ulMinRPM = rpm;
+
+       return ret;
+}
+
 static int pp_dpm_get_pp_num_states(void *handle,
                 struct pp_states_info *data)
 {
@@ -1342,6 +1386,8 @@ static const struct amd_pm_funcs pp_dpm_funcs = {
         .get_fan_speed_percent = pp_dpm_get_fan_speed_percent,
         .get_fan_speed_rpm = pp_dpm_get_fan_speed_rpm,
         .set_fan_speed_rpm = pp_dpm_set_fan_speed_rpm,
+       .set_fan_speed_max_rpm = pp_dpm_set_fan_speed_max_rpm,
+       .set_fan_speed_min_rpm = pp_dpm_set_fan_speed_min_rpm,
         .get_pp_num_states = pp_dpm_get_pp_num_states,
         .get_pp_table = pp_dpm_get_pp_table,
         .set_pp_table = pp_dpm_set_pp_table,
diff --git a/drivers/gpu/drm/amd/powerplay/inc/hwmgr.h b/drivers/gpu/drm/amd/powerplay/inc/hwmgr.h
index 687f73fe4cf5..0242bc039a48 100644
--- a/drivers/gpu/drm/amd/powerplay/inc/hwmgr.h
+++ b/drivers/gpu/drm/amd/powerplay/inc/hwmgr.h
@@ -269,6 +269,8 @@ struct pp_hwmgr_func {
         int (*get_fan_speed_percent)(struct pp_hwmgr *hwmgr, uint32_t *speed);
         int (*set_fan_speed_rpm)(struct pp_hwmgr *hwmgr, uint32_t percent);
         int (*get_fan_speed_rpm)(struct pp_hwmgr *hwmgr, uint32_t *speed);
+       int (*set_fan_speed_max_rpm)(struct pp_hwmgr *hwmgr, uint32_t max_rpm);
+       int (*set_fan_speed_min_rpm)(struct pp_hwmgr *hwmgr, uint32_t min_rpm);
         int (*reset_fan_speed_to_default)(struct pp_hwmgr *hwmgr);
         int (*uninitialize_thermal_controller)(struct pp_hwmgr *hwmgr);
         int (*register_irq_handlers)(struct pp_hwmgr *hwmgr);
--
2.19.1

_______________________________________________
amd-gfx mailing list
amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
amd-gfx Info Page - freedesktop.org<https://lists.freedesktop.org/mailman/listinfo/amd-gfx>
lists.freedesktop.org
To see the collection of prior postings to the list, visit the amd-gfx Archives.. Using amd-gfx: To post a message to all the list members, send email to amd-gfx-PD4FTy7X32lNgt0PjOBp9xlNPtJONSTn@public.gmane.org You can subscribe to the list, or change your existing subscription, in the sections below.



[-- Attachment #1.2: Type: text/html, Size: 20634 bytes --]

[-- Attachment #2: Type: text/plain, Size: 154 bytes --]

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/3] drm/amd/powerplay: support hwmon max/min fan speed setting on Vega20
       [not found]     ` <20181024081141.18647-3-evan.quan-5C7GfCeVMHo@public.gmane.org>
@ 2018-10-24  8:37       ` Zhu, Rex
       [not found]         ` <BYAPR12MB277564C5DF32AFE83E33F7D8FBF60-ZGDeBxoHBPmJeBUhB162ZQdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
  0 siblings, 1 reply; 9+ messages in thread
From: Zhu, Rex @ 2018-10-24  8:37 UTC (permalink / raw)
  To: Quan, Evan, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW


[-- Attachment #1.1: Type: text/plain, Size: 6792 bytes --]

-       percent = current_rpm * 100 / pp_table->FanMaximumRpm;
+       percent = (current_rpm * 100) /
+               hwmgr->thermal_controller.fanInfo.ulMaxRPM;


Better check hwmgr->thermal_controller.fanInfo.ulMaxRPM not equal to 0.


Best Regards

Rex

________________________________
From: amd-gfx <amd-gfx-bounces-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org> on behalf of Evan Quan <evan.quan-5C7GfCeVMHo@public.gmane.org>
Sent: Wednesday, October 24, 2018 4:11 PM
To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
Cc: Quan, Evan
Subject: [PATCH 3/3] drm/amd/powerplay: support hwmon max/min fan speed setting on Vega20

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

Change-Id: Ieab42c744d6c54f8b85a71be80f7c6832ae7352b
Signed-off-by: Evan Quan <evan.quan-5C7GfCeVMHo@public.gmane.org>
---
 .../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

_______________________________________________
amd-gfx mailing list
amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
amd-gfx Info Page - freedesktop.org<https://lists.freedesktop.org/mailman/listinfo/amd-gfx>
lists.freedesktop.org
To see the collection of prior postings to the list, visit the amd-gfx Archives.. Using amd-gfx: To post a message to all the list members, send email to amd-gfx-PD4FTy7X32lNgt0PjOBp9xlNPtJONSTn@public.gmane.org You can subscribe to the list, or change your existing subscription, in the sections below.



[-- Attachment #1.2: Type: text/html, Size: 14617 bytes --]

[-- Attachment #2: Type: text/plain, Size: 154 bytes --]

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* RE: [PATCH 2/3] drm/amd/powerplay: added hwmon interfaces for setting max/min fan speed
       [not found]         ` <BYAPR12MB2775F650496C7DA583461501FBF60-ZGDeBxoHBPmJeBUhB162ZQdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
@ 2018-10-24  8:47           ` Quan, Evan
       [not found]             ` <SN6PR12MB26563DA5F631ECD8A372CDE0E4F60-kxOKjb6HO/FeL/N0e1LXkAdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
  0 siblings, 1 reply; 9+ messages in thread
From: Quan, Evan @ 2018-10-24  8:47 UTC (permalink / raw)
  To: Zhu, Rex, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW


[-- Attachment #1.1: Type: text/plain, Size: 10442 bytes --]

This can be performed under auto mode.
The settings are always effective unless user resets them back.

Regards,
Evan
From: Zhu, Rex
Sent: 2018年10月24日 16:36
To: Quan, Evan <Evan.Quan@amd.com>; amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH 2/3] drm/amd/powerplay: added hwmon interfaces for setting max/min fan speed


One question: how to exit the max/min fan speed and return to auto mode?



Best Regards

Rex



________________________________
From: amd-gfx <amd-gfx-bounces@lists.freedesktop.org<mailto:amd-gfx-bounces@lists.freedesktop.org>> on behalf of Evan Quan <evan.quan@amd.com<mailto:evan.quan@amd.com>>
Sent: Wednesday, October 24, 2018 4:11 PM
To: amd-gfx@lists.freedesktop.org<mailto:amd-gfx@lists.freedesktop.org>
Cc: Quan, Evan
Subject: [PATCH 2/3] drm/amd/powerplay: added hwmon interfaces for setting max/min fan speed

New hwmon interfaces for maximum and minimum fan speed setting.

Change-Id: Ic9ec9f2427c6d3425e1c7e7b765d7d01a92f9a26
Signed-off-by: Evan Quan <evan.quan@amd.com<mailto:evan.quan@amd.com>>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h       |  6 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c        | 56 ++++++++++++++++++-
 .../gpu/drm/amd/include/kgd_pp_interface.h    |  2 +
 drivers/gpu/drm/amd/powerplay/amd_powerplay.c | 46 +++++++++++++++
 drivers/gpu/drm/amd/powerplay/inc/hwmgr.h     |  2 +
 5 files changed, 110 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h
index f972cd156795..12c4e461a7bc 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h
@@ -364,6 +364,12 @@ enum amdgpu_pcie_gen {
                 ((adev)->powerplay.pp_funcs->enable_mgpu_fan_boost(\
                         (adev)->powerplay.pp_handle))

+#define amdgpu_dpm_set_fan_speed_max_rpm(adev, s) \
+               ((adev)->powerplay.pp_funcs->set_fan_speed_max_rpm)((adev)->powerplay.pp_handle, (s))
+
+#define amdgpu_dpm_set_fan_speed_min_rpm(adev, s) \
+               ((adev)->powerplay.pp_funcs->set_fan_speed_min_rpm)((adev)->powerplay.pp_handle, (s))
+
 struct amdgpu_dpm {
         struct amdgpu_ps        *ps;
         /* number of valid power states */
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
index 8e94255654ed..92da37bb51ba 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
@@ -1265,6 +1265,32 @@ static ssize_t amdgpu_hwmon_get_fan1_min(struct device *dev,
         return snprintf(buf, PAGE_SIZE, "%d\n", min_rpm);
 }

+static ssize_t amdgpu_hwmon_set_fan1_min(struct device *dev,
+                                    struct device_attribute *attr,
+                                    const char *buf, size_t count)
+{
+       struct amdgpu_device *adev = dev_get_drvdata(dev);
+       int err;
+       u32 value;
+
+       /* Can't adjust fan when the card is off */
+       if  ((adev->flags & AMD_IS_PX) &&
+            (adev->ddev->switch_power_state != DRM_SWITCH_POWER_ON))
+               return -EINVAL;
+
+       err = kstrtou32(buf, 10, &value);
+       if (err)
+               return err;
+
+       if (adev->powerplay.pp_funcs->set_fan_speed_min_rpm) {
+               err = amdgpu_dpm_set_fan_speed_min_rpm(adev, value);
+               if (err)
+                       return err;
+       }
+
+       return count;
+}
+
 static ssize_t amdgpu_hwmon_get_fan1_max(struct device *dev,
                                          struct device_attribute *attr,
                                          char *buf)
@@ -1285,6 +1311,32 @@ static ssize_t amdgpu_hwmon_get_fan1_max(struct device *dev,
         return snprintf(buf, PAGE_SIZE, "%d\n", max_rpm);
 }

+static ssize_t amdgpu_hwmon_set_fan1_max(struct device *dev,
+                                    struct device_attribute *attr,
+                                    const char *buf, size_t count)
+{
+       struct amdgpu_device *adev = dev_get_drvdata(dev);
+       int err;
+       u32 value;
+
+       /* Can't adjust fan when the card is off */
+       if  ((adev->flags & AMD_IS_PX) &&
+            (adev->ddev->switch_power_state != DRM_SWITCH_POWER_ON))
+               return -EINVAL;
+
+       err = kstrtou32(buf, 10, &value);
+       if (err)
+               return err;
+
+       if (adev->powerplay.pp_funcs->set_fan_speed_max_rpm) {
+               err = amdgpu_dpm_set_fan_speed_max_rpm(adev, value);
+               if (err)
+                       return err;
+       }
+
+       return count;
+}
+
 static ssize_t amdgpu_hwmon_get_fan1_target(struct device *dev,
                                            struct device_attribute *attr,
                                            char *buf)
@@ -1628,8 +1680,8 @@ static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_pwm1_
 static SENSOR_DEVICE_ATTR(pwm1_min, S_IRUGO, amdgpu_hwmon_get_pwm1_min, NULL, 0);
 static SENSOR_DEVICE_ATTR(pwm1_max, S_IRUGO, amdgpu_hwmon_get_pwm1_max, NULL, 0);
 static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, amdgpu_hwmon_get_fan1_input, NULL, 0);
-static SENSOR_DEVICE_ATTR(fan1_min, S_IRUGO, amdgpu_hwmon_get_fan1_min, NULL, 0);
-static SENSOR_DEVICE_ATTR(fan1_max, S_IRUGO, amdgpu_hwmon_get_fan1_max, NULL, 0);
+static SENSOR_DEVICE_ATTR(fan1_min, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_fan1_min, amdgpu_hwmon_set_fan1_min, 0);
+static SENSOR_DEVICE_ATTR(fan1_max, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_fan1_max, amdgpu_hwmon_set_fan1_max, 0);
 static SENSOR_DEVICE_ATTR(fan1_target, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_fan1_target, amdgpu_hwmon_set_fan1_target, 0);
 static SENSOR_DEVICE_ATTR(fan1_enable, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_fan1_enable, amdgpu_hwmon_set_fan1_enable, 0);
 static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, amdgpu_hwmon_show_vddgfx, NULL, 0);
diff --git a/drivers/gpu/drm/amd/include/kgd_pp_interface.h b/drivers/gpu/drm/amd/include/kgd_pp_interface.h
index 980e696989b1..1af55997bdb9 100644
--- a/drivers/gpu/drm/amd/include/kgd_pp_interface.h
+++ b/drivers/gpu/drm/amd/include/kgd_pp_interface.h
@@ -276,6 +276,8 @@ struct amd_pm_funcs {
                 struct amd_pp_simple_clock_info *clocks);
         int (*notify_smu_enable_pwe)(void *handle);
         int (*enable_mgpu_fan_boost)(void *handle);
+       int (*set_fan_speed_max_rpm)(void *handle, uint32_t rpm);
+       int (*set_fan_speed_min_rpm)(void *handle, uint32_t rpm);
 };

 #endif
diff --git a/drivers/gpu/drm/amd/powerplay/amd_powerplay.c b/drivers/gpu/drm/amd/powerplay/amd_powerplay.c
index 586f1ff9f73e..f10237b4d057 100644
--- a/drivers/gpu/drm/amd/powerplay/amd_powerplay.c
+++ b/drivers/gpu/drm/amd/powerplay/amd_powerplay.c
@@ -603,6 +603,50 @@ static int pp_dpm_set_fan_speed_rpm(void *handle, uint32_t rpm)
         return ret;
 }

+static int pp_dpm_set_fan_speed_max_rpm(void *handle, uint32_t rpm)
+{
+       struct pp_hwmgr *hwmgr = handle;
+       int ret = 0;
+
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
+
+       if (hwmgr->hwmgr_func->set_fan_speed_max_rpm == NULL) {
+               pr_info("%s was not implemented.\n", __func__);
+               return -EOPNOTSUPP;
+       }
+       mutex_lock(&hwmgr->smu_lock);
+       ret = hwmgr->hwmgr_func->set_fan_speed_max_rpm(hwmgr, rpm);
+       mutex_unlock(&hwmgr->smu_lock);
+
+       if (!ret)
+               hwmgr->thermal_controller.fanInfo.ulMaxRPM = rpm;
+
+       return ret;
+}
+
+static int pp_dpm_set_fan_speed_min_rpm(void *handle, uint32_t rpm)
+{
+       struct pp_hwmgr *hwmgr = handle;
+       int ret = 0;
+
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
+
+       if (hwmgr->hwmgr_func->set_fan_speed_min_rpm == NULL) {
+               pr_info("%s was not implemented.\n", __func__);
+               return -EOPNOTSUPP;
+       }
+       mutex_lock(&hwmgr->smu_lock);
+       ret = hwmgr->hwmgr_func->set_fan_speed_min_rpm(hwmgr, rpm);
+       mutex_unlock(&hwmgr->smu_lock);
+
+       if (!ret)
+               hwmgr->thermal_controller.fanInfo.ulMinRPM = rpm;
+
+       return ret;
+}
+
 static int pp_dpm_get_pp_num_states(void *handle,
                 struct pp_states_info *data)
 {
@@ -1342,6 +1386,8 @@ static const struct amd_pm_funcs pp_dpm_funcs = {
         .get_fan_speed_percent = pp_dpm_get_fan_speed_percent,
         .get_fan_speed_rpm = pp_dpm_get_fan_speed_rpm,
         .set_fan_speed_rpm = pp_dpm_set_fan_speed_rpm,
+       .set_fan_speed_max_rpm = pp_dpm_set_fan_speed_max_rpm,
+       .set_fan_speed_min_rpm = pp_dpm_set_fan_speed_min_rpm,
         .get_pp_num_states = pp_dpm_get_pp_num_states,
         .get_pp_table = pp_dpm_get_pp_table,
         .set_pp_table = pp_dpm_set_pp_table,
diff --git a/drivers/gpu/drm/amd/powerplay/inc/hwmgr.h b/drivers/gpu/drm/amd/powerplay/inc/hwmgr.h
index 687f73fe4cf5..0242bc039a48 100644
--- a/drivers/gpu/drm/amd/powerplay/inc/hwmgr.h
+++ b/drivers/gpu/drm/amd/powerplay/inc/hwmgr.h
@@ -269,6 +269,8 @@ struct pp_hwmgr_func {
         int (*get_fan_speed_percent)(struct pp_hwmgr *hwmgr, uint32_t *speed);
         int (*set_fan_speed_rpm)(struct pp_hwmgr *hwmgr, uint32_t percent);
         int (*get_fan_speed_rpm)(struct pp_hwmgr *hwmgr, uint32_t *speed);
+       int (*set_fan_speed_max_rpm)(struct pp_hwmgr *hwmgr, uint32_t max_rpm);
+       int (*set_fan_speed_min_rpm)(struct pp_hwmgr *hwmgr, uint32_t min_rpm);
         int (*reset_fan_speed_to_default)(struct pp_hwmgr *hwmgr);
         int (*uninitialize_thermal_controller)(struct pp_hwmgr *hwmgr);
         int (*register_irq_handlers)(struct pp_hwmgr *hwmgr);
--
2.19.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org<mailto:amd-gfx@lists.freedesktop.org>
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
amd-gfx Info Page - freedesktop.org<https://lists.freedesktop.org/mailman/listinfo/amd-gfx>
lists.freedesktop.org
To see the collection of prior postings to the list, visit the amd-gfx Archives.. Using amd-gfx: To post a message to all the list members, send email to amd-gfx@lists.freedesktop.org<mailto:amd-gfx@lists.freedesktop.org>. You can subscribe to the list, or change your existing subscription, in the sections below.



[-- Attachment #1.2: Type: text/html, Size: 23879 bytes --]

[-- Attachment #2: Type: text/plain, Size: 154 bytes --]

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* RE: [PATCH 3/3] drm/amd/powerplay: support hwmon max/min fan speed setting on Vega20
       [not found]         ` <BYAPR12MB277564C5DF32AFE83E33F7D8FBF60-ZGDeBxoHBPmJeBUhB162ZQdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
@ 2018-10-24  8:53           ` Quan, Evan
  0 siblings, 0 replies; 9+ messages in thread
From: Quan, Evan @ 2018-10-24  8:53 UTC (permalink / raw)
  To: Zhu, Rex, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW


[-- Attachment #1.1: Type: text/plain, Size: 7071 bytes --]

Sure

From: Zhu, Rex
Sent: 2018年10月24日 16:37
To: Quan, Evan <Evan.Quan@amd.com>; amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH 3/3] drm/amd/powerplay: support hwmon max/min fan speed setting on Vega20


-       percent = current_rpm * 100 / pp_table->FanMaximumRpm;
+       percent = (current_rpm * 100) /
+               hwmgr->thermal_controller.fanInfo.ulMaxRPM;


Better check hwmgr->thermal_controller.fanInfo.ulMaxRPM not equal to 0.



Best Regards

Rex

________________________________
From: amd-gfx <amd-gfx-bounces@lists.freedesktop.org<mailto:amd-gfx-bounces@lists.freedesktop.org>> on behalf of Evan Quan <evan.quan@amd.com<mailto:evan.quan@amd.com>>
Sent: Wednesday, October 24, 2018 4:11 PM
To: amd-gfx@lists.freedesktop.org<mailto:amd-gfx@lists.freedesktop.org>
Cc: Quan, Evan
Subject: [PATCH 3/3] drm/amd/powerplay: support hwmon max/min fan speed setting on Vega20

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

Change-Id: Ieab42c744d6c54f8b85a71be80f7c6832ae7352b
Signed-off-by: Evan Quan <evan.quan@amd.com<mailto:evan.quan@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

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org<mailto:amd-gfx@lists.freedesktop.org>
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
amd-gfx Info Page - freedesktop.org<https://lists.freedesktop.org/mailman/listinfo/amd-gfx>
lists.freedesktop.org
To see the collection of prior postings to the list, visit the amd-gfx Archives.. Using amd-gfx: To post a message to all the list members, send email to amd-gfx@lists.freedesktop.org<mailto:amd-gfx@lists.freedesktop.org>. You can subscribe to the list, or change your existing subscription, in the sections below.



[-- Attachment #1.2: Type: text/html, Size: 17602 bytes --]

[-- Attachment #2: Type: text/plain, Size: 154 bytes --]

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/3] drm/amd/powerplay: added hwmon interfaces for setting max/min fan speed
       [not found]             ` <SN6PR12MB26563DA5F631ECD8A372CDE0E4F60-kxOKjb6HO/FeL/N0e1LXkAdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
@ 2018-10-24  9:04               ` Zhu, Rex
       [not found]                 ` <BYAPR12MB27756445D4157DD337C5B6B2FBF60-ZGDeBxoHBPmJeBUhB162ZQdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
  0 siblings, 1 reply; 9+ messages in thread
From: Zhu, Rex @ 2018-10-24  9:04 UTC (permalink / raw)
  To: Quan, Evan, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW


[-- Attachment #1.1: Type: text/plain, Size: 11379 bytes --]

I think when user set max/min fan speed, the fan control mode will switch to

manual mode.

so if user need to exit the max/min fan speed, user need to reset to auto mode.


Do we need to let user enter manual mode first before set max/min fan speed?


Best Regards

Rex



________________________________
From: Quan, Evan
Sent: Wednesday, October 24, 2018 4:47 PM
To: Zhu, Rex; amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
Subject: RE: [PATCH 2/3] drm/amd/powerplay: added hwmon interfaces for setting max/min fan speed


This can be performed under auto mode.

The settings are always effective unless user resets them back.



Regards,

Evan

From: Zhu, Rex
Sent: 2018年10月24日 16:36
To: Quan, Evan <Evan.Quan-5C7GfCeVMHo@public.gmane.org>; amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
Subject: Re: [PATCH 2/3] drm/amd/powerplay: added hwmon interfaces for setting max/min fan speed



One question: how to exit the max/min fan speed and return to auto mode?



Best Regards

Rex





________________________________

From: amd-gfx <amd-gfx-bounces-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org<mailto:amd-gfx-bounces@lists.freedesktop.org>> on behalf of Evan Quan <evan.quan-5C7GfCeVMHo@public.gmane.org<mailto:evan.quan-5C7GfCeVMHo@public.gmane.org>>
Sent: Wednesday, October 24, 2018 4:11 PM
To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org<mailto:amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org>
Cc: Quan, Evan
Subject: [PATCH 2/3] drm/amd/powerplay: added hwmon interfaces for setting max/min fan speed



New hwmon interfaces for maximum and minimum fan speed setting.

Change-Id: Ic9ec9f2427c6d3425e1c7e7b765d7d01a92f9a26
Signed-off-by: Evan Quan <evan.quan-5C7GfCeVMHo@public.gmane.org<mailto:evan.quan-5C7GfCeVMHo@public.gmane.org>>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h       |  6 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c        | 56 ++++++++++++++++++-
 .../gpu/drm/amd/include/kgd_pp_interface.h    |  2 +
 drivers/gpu/drm/amd/powerplay/amd_powerplay.c | 46 +++++++++++++++
 drivers/gpu/drm/amd/powerplay/inc/hwmgr.h     |  2 +
 5 files changed, 110 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h
index f972cd156795..12c4e461a7bc 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h
@@ -364,6 +364,12 @@ enum amdgpu_pcie_gen {
                 ((adev)->powerplay.pp_funcs->enable_mgpu_fan_boost(\
                         (adev)->powerplay.pp_handle))

+#define amdgpu_dpm_set_fan_speed_max_rpm(adev, s) \
+               ((adev)->powerplay.pp_funcs->set_fan_speed_max_rpm)((adev)->powerplay.pp_handle, (s))
+
+#define amdgpu_dpm_set_fan_speed_min_rpm(adev, s) \
+               ((adev)->powerplay.pp_funcs->set_fan_speed_min_rpm)((adev)->powerplay.pp_handle, (s))
+
 struct amdgpu_dpm {
         struct amdgpu_ps        *ps;
         /* number of valid power states */
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
index 8e94255654ed..92da37bb51ba 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
@@ -1265,6 +1265,32 @@ static ssize_t amdgpu_hwmon_get_fan1_min(struct device *dev,
         return snprintf(buf, PAGE_SIZE, "%d\n", min_rpm);
 }

+static ssize_t amdgpu_hwmon_set_fan1_min(struct device *dev,
+                                    struct device_attribute *attr,
+                                    const char *buf, size_t count)
+{
+       struct amdgpu_device *adev = dev_get_drvdata(dev);
+       int err;
+       u32 value;
+
+       /* Can't adjust fan when the card is off */
+       if  ((adev->flags & AMD_IS_PX) &&
+            (adev->ddev->switch_power_state != DRM_SWITCH_POWER_ON))
+               return -EINVAL;
+
+       err = kstrtou32(buf, 10, &value);
+       if (err)
+               return err;
+
+       if (adev->powerplay.pp_funcs->set_fan_speed_min_rpm) {
+               err = amdgpu_dpm_set_fan_speed_min_rpm(adev, value);
+               if (err)
+                       return err;
+       }
+
+       return count;
+}
+
 static ssize_t amdgpu_hwmon_get_fan1_max(struct device *dev,
                                          struct device_attribute *attr,
                                          char *buf)
@@ -1285,6 +1311,32 @@ static ssize_t amdgpu_hwmon_get_fan1_max(struct device *dev,
         return snprintf(buf, PAGE_SIZE, "%d\n", max_rpm);
 }

+static ssize_t amdgpu_hwmon_set_fan1_max(struct device *dev,
+                                    struct device_attribute *attr,
+                                    const char *buf, size_t count)
+{
+       struct amdgpu_device *adev = dev_get_drvdata(dev);
+       int err;
+       u32 value;
+
+       /* Can't adjust fan when the card is off */
+       if  ((adev->flags & AMD_IS_PX) &&
+            (adev->ddev->switch_power_state != DRM_SWITCH_POWER_ON))
+               return -EINVAL;
+
+       err = kstrtou32(buf, 10, &value);
+       if (err)
+               return err;
+
+       if (adev->powerplay.pp_funcs->set_fan_speed_max_rpm) {
+               err = amdgpu_dpm_set_fan_speed_max_rpm(adev, value);
+               if (err)
+                       return err;
+       }
+
+       return count;
+}
+
 static ssize_t amdgpu_hwmon_get_fan1_target(struct device *dev,
                                            struct device_attribute *attr,
                                            char *buf)
@@ -1628,8 +1680,8 @@ static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_pwm1_
 static SENSOR_DEVICE_ATTR(pwm1_min, S_IRUGO, amdgpu_hwmon_get_pwm1_min, NULL, 0);
 static SENSOR_DEVICE_ATTR(pwm1_max, S_IRUGO, amdgpu_hwmon_get_pwm1_max, NULL, 0);
 static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, amdgpu_hwmon_get_fan1_input, NULL, 0);
-static SENSOR_DEVICE_ATTR(fan1_min, S_IRUGO, amdgpu_hwmon_get_fan1_min, NULL, 0);
-static SENSOR_DEVICE_ATTR(fan1_max, S_IRUGO, amdgpu_hwmon_get_fan1_max, NULL, 0);
+static SENSOR_DEVICE_ATTR(fan1_min, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_fan1_min, amdgpu_hwmon_set_fan1_min, 0);
+static SENSOR_DEVICE_ATTR(fan1_max, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_fan1_max, amdgpu_hwmon_set_fan1_max, 0);
 static SENSOR_DEVICE_ATTR(fan1_target, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_fan1_target, amdgpu_hwmon_set_fan1_target, 0);
 static SENSOR_DEVICE_ATTR(fan1_enable, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_fan1_enable, amdgpu_hwmon_set_fan1_enable, 0);
 static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, amdgpu_hwmon_show_vddgfx, NULL, 0);
diff --git a/drivers/gpu/drm/amd/include/kgd_pp_interface.h b/drivers/gpu/drm/amd/include/kgd_pp_interface.h
index 980e696989b1..1af55997bdb9 100644
--- a/drivers/gpu/drm/amd/include/kgd_pp_interface.h
+++ b/drivers/gpu/drm/amd/include/kgd_pp_interface.h
@@ -276,6 +276,8 @@ struct amd_pm_funcs {
                 struct amd_pp_simple_clock_info *clocks);
         int (*notify_smu_enable_pwe)(void *handle);
         int (*enable_mgpu_fan_boost)(void *handle);
+       int (*set_fan_speed_max_rpm)(void *handle, uint32_t rpm);
+       int (*set_fan_speed_min_rpm)(void *handle, uint32_t rpm);
 };

 #endif
diff --git a/drivers/gpu/drm/amd/powerplay/amd_powerplay.c b/drivers/gpu/drm/amd/powerplay/amd_powerplay.c
index 586f1ff9f73e..f10237b4d057 100644
--- a/drivers/gpu/drm/amd/powerplay/amd_powerplay.c
+++ b/drivers/gpu/drm/amd/powerplay/amd_powerplay.c
@@ -603,6 +603,50 @@ static int pp_dpm_set_fan_speed_rpm(void *handle, uint32_t rpm)
         return ret;
 }

+static int pp_dpm_set_fan_speed_max_rpm(void *handle, uint32_t rpm)
+{
+       struct pp_hwmgr *hwmgr = handle;
+       int ret = 0;
+
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
+
+       if (hwmgr->hwmgr_func->set_fan_speed_max_rpm == NULL) {
+               pr_info("%s was not implemented.\n", __func__);
+               return -EOPNOTSUPP;
+       }
+       mutex_lock(&hwmgr->smu_lock);
+       ret = hwmgr->hwmgr_func->set_fan_speed_max_rpm(hwmgr, rpm);
+       mutex_unlock(&hwmgr->smu_lock);
+
+       if (!ret)
+               hwmgr->thermal_controller.fanInfo.ulMaxRPM = rpm;
+
+       return ret;
+}
+
+static int pp_dpm_set_fan_speed_min_rpm(void *handle, uint32_t rpm)
+{
+       struct pp_hwmgr *hwmgr = handle;
+       int ret = 0;
+
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
+
+       if (hwmgr->hwmgr_func->set_fan_speed_min_rpm == NULL) {
+               pr_info("%s was not implemented.\n", __func__);
+               return -EOPNOTSUPP;
+       }
+       mutex_lock(&hwmgr->smu_lock);
+       ret = hwmgr->hwmgr_func->set_fan_speed_min_rpm(hwmgr, rpm);
+       mutex_unlock(&hwmgr->smu_lock);
+
+       if (!ret)
+               hwmgr->thermal_controller.fanInfo.ulMinRPM = rpm;
+
+       return ret;
+}
+
 static int pp_dpm_get_pp_num_states(void *handle,
                 struct pp_states_info *data)
 {
@@ -1342,6 +1386,8 @@ static const struct amd_pm_funcs pp_dpm_funcs = {
         .get_fan_speed_percent = pp_dpm_get_fan_speed_percent,
         .get_fan_speed_rpm = pp_dpm_get_fan_speed_rpm,
         .set_fan_speed_rpm = pp_dpm_set_fan_speed_rpm,
+       .set_fan_speed_max_rpm = pp_dpm_set_fan_speed_max_rpm,
+       .set_fan_speed_min_rpm = pp_dpm_set_fan_speed_min_rpm,
         .get_pp_num_states = pp_dpm_get_pp_num_states,
         .get_pp_table = pp_dpm_get_pp_table,
         .set_pp_table = pp_dpm_set_pp_table,
diff --git a/drivers/gpu/drm/amd/powerplay/inc/hwmgr.h b/drivers/gpu/drm/amd/powerplay/inc/hwmgr.h
index 687f73fe4cf5..0242bc039a48 100644
--- a/drivers/gpu/drm/amd/powerplay/inc/hwmgr.h
+++ b/drivers/gpu/drm/amd/powerplay/inc/hwmgr.h
@@ -269,6 +269,8 @@ struct pp_hwmgr_func {
         int (*get_fan_speed_percent)(struct pp_hwmgr *hwmgr, uint32_t *speed);
         int (*set_fan_speed_rpm)(struct pp_hwmgr *hwmgr, uint32_t percent);
         int (*get_fan_speed_rpm)(struct pp_hwmgr *hwmgr, uint32_t *speed);
+       int (*set_fan_speed_max_rpm)(struct pp_hwmgr *hwmgr, uint32_t max_rpm);
+       int (*set_fan_speed_min_rpm)(struct pp_hwmgr *hwmgr, uint32_t min_rpm);
         int (*reset_fan_speed_to_default)(struct pp_hwmgr *hwmgr);
         int (*uninitialize_thermal_controller)(struct pp_hwmgr *hwmgr);
         int (*register_irq_handlers)(struct pp_hwmgr *hwmgr);
--
2.19.1

_______________________________________________
amd-gfx mailing list
amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org<mailto:amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org>
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

amd-gfx Info Page - freedesktop.org<https://lists.freedesktop.org/mailman/listinfo/amd-gfx>

lists.freedesktop.org

To see the collection of prior postings to the list, visit the amd-gfx Archives.. Using amd-gfx: To post a message to all the list members, send email to amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org<mailto:amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org>. You can subscribe to the list, or change your existing subscription, in the sections below.




[-- Attachment #1.2: Type: text/html, Size: 23931 bytes --]

[-- Attachment #2: Type: text/plain, Size: 154 bytes --]

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* RE: [PATCH 2/3] drm/amd/powerplay: added hwmon interfaces for setting max/min fan speed
       [not found]                 ` <BYAPR12MB27756445D4157DD337C5B6B2FBF60-ZGDeBxoHBPmJeBUhB162ZQdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
@ 2018-10-24  9:18                   ` Quan, Evan
  0 siblings, 0 replies; 9+ messages in thread
From: Quan, Evan @ 2018-10-24  9:18 UTC (permalink / raw)
  To: Zhu, Rex, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW


[-- Attachment #1.1: Type: text/plain, Size: 11619 bytes --]

Not necessary per my understanding.
As the max/min fan speeds are kind of global settings regardless of the fan control mode.
Also the SMU fw should be able to apply the settings at runtime(at least for Vega20, that’s the case).
So, no need to switch to manual mode first.

Regards,
Evan
From: Zhu, Rex
Sent: 2018年10月24日 17:04
To: Quan, Evan <Evan.Quan@amd.com>; amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH 2/3] drm/amd/powerplay: added hwmon interfaces for setting max/min fan speed


I think when user set max/min fan speed, the fan control mode will switch to

manual mode.

so if user need to exit the max/min fan speed, user need to reset to auto mode.



Do we need to let user enter manual mode first before set max/min fan speed?



Best Regards

Rex



________________________________
From: Quan, Evan
Sent: Wednesday, October 24, 2018 4:47 PM
To: Zhu, Rex; amd-gfx@lists.freedesktop.org<mailto:amd-gfx@lists.freedesktop.org>
Subject: RE: [PATCH 2/3] drm/amd/powerplay: added hwmon interfaces for setting max/min fan speed


This can be performed under auto mode.

The settings are always effective unless user resets them back.



Regards,

Evan

From: Zhu, Rex
Sent: 2018年10月24日 16:36
To: Quan, Evan <Evan.Quan@amd.com<mailto:Evan.Quan@amd.com>>; amd-gfx@lists.freedesktop.org<mailto:amd-gfx@lists.freedesktop.org>
Subject: Re: [PATCH 2/3] drm/amd/powerplay: added hwmon interfaces for setting max/min fan speed



One question: how to exit the max/min fan speed and return to auto mode?



Best Regards

Rex





________________________________

From: amd-gfx <amd-gfx-bounces@lists.freedesktop.org<mailto:amd-gfx-bounces@lists.freedesktop.org>> on behalf of Evan Quan <evan.quan@amd.com<mailto:evan.quan@amd.com>>
Sent: Wednesday, October 24, 2018 4:11 PM
To: amd-gfx@lists.freedesktop.org<mailto:amd-gfx@lists.freedesktop.org>
Cc: Quan, Evan
Subject: [PATCH 2/3] drm/amd/powerplay: added hwmon interfaces for setting max/min fan speed



New hwmon interfaces for maximum and minimum fan speed setting.

Change-Id: Ic9ec9f2427c6d3425e1c7e7b765d7d01a92f9a26
Signed-off-by: Evan Quan <evan.quan@amd.com<mailto:evan.quan@amd.com>>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h       |  6 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c        | 56 ++++++++++++++++++-
 .../gpu/drm/amd/include/kgd_pp_interface.h    |  2 +
 drivers/gpu/drm/amd/powerplay/amd_powerplay.c | 46 +++++++++++++++
 drivers/gpu/drm/amd/powerplay/inc/hwmgr.h     |  2 +
 5 files changed, 110 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h
index f972cd156795..12c4e461a7bc 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h
@@ -364,6 +364,12 @@ enum amdgpu_pcie_gen {
                 ((adev)->powerplay.pp_funcs->enable_mgpu_fan_boost(\
                         (adev)->powerplay.pp_handle))

+#define amdgpu_dpm_set_fan_speed_max_rpm(adev, s) \
+               ((adev)->powerplay.pp_funcs->set_fan_speed_max_rpm)((adev)->powerplay.pp_handle, (s))
+
+#define amdgpu_dpm_set_fan_speed_min_rpm(adev, s) \
+               ((adev)->powerplay.pp_funcs->set_fan_speed_min_rpm)((adev)->powerplay.pp_handle, (s))
+
 struct amdgpu_dpm {
         struct amdgpu_ps        *ps;
         /* number of valid power states */
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
index 8e94255654ed..92da37bb51ba 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
@@ -1265,6 +1265,32 @@ static ssize_t amdgpu_hwmon_get_fan1_min(struct device *dev,
         return snprintf(buf, PAGE_SIZE, "%d\n", min_rpm);
 }

+static ssize_t amdgpu_hwmon_set_fan1_min(struct device *dev,
+                                    struct device_attribute *attr,
+                                    const char *buf, size_t count)
+{
+       struct amdgpu_device *adev = dev_get_drvdata(dev);
+       int err;
+       u32 value;
+
+       /* Can't adjust fan when the card is off */
+       if  ((adev->flags & AMD_IS_PX) &&
+            (adev->ddev->switch_power_state != DRM_SWITCH_POWER_ON))
+               return -EINVAL;
+
+       err = kstrtou32(buf, 10, &value);
+       if (err)
+               return err;
+
+       if (adev->powerplay.pp_funcs->set_fan_speed_min_rpm) {
+               err = amdgpu_dpm_set_fan_speed_min_rpm(adev, value);
+               if (err)
+                       return err;
+       }
+
+       return count;
+}
+
 static ssize_t amdgpu_hwmon_get_fan1_max(struct device *dev,
                                          struct device_attribute *attr,
                                          char *buf)
@@ -1285,6 +1311,32 @@ static ssize_t amdgpu_hwmon_get_fan1_max(struct device *dev,
         return snprintf(buf, PAGE_SIZE, "%d\n", max_rpm);
 }

+static ssize_t amdgpu_hwmon_set_fan1_max(struct device *dev,
+                                    struct device_attribute *attr,
+                                    const char *buf, size_t count)
+{
+       struct amdgpu_device *adev = dev_get_drvdata(dev);
+       int err;
+       u32 value;
+
+       /* Can't adjust fan when the card is off */
+       if  ((adev->flags & AMD_IS_PX) &&
+            (adev->ddev->switch_power_state != DRM_SWITCH_POWER_ON))
+               return -EINVAL;
+
+       err = kstrtou32(buf, 10, &value);
+       if (err)
+               return err;
+
+       if (adev->powerplay.pp_funcs->set_fan_speed_max_rpm) {
+               err = amdgpu_dpm_set_fan_speed_max_rpm(adev, value);
+               if (err)
+                       return err;
+       }
+
+       return count;
+}
+
 static ssize_t amdgpu_hwmon_get_fan1_target(struct device *dev,
                                            struct device_attribute *attr,
                                            char *buf)
@@ -1628,8 +1680,8 @@ static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_pwm1_
 static SENSOR_DEVICE_ATTR(pwm1_min, S_IRUGO, amdgpu_hwmon_get_pwm1_min, NULL, 0);
 static SENSOR_DEVICE_ATTR(pwm1_max, S_IRUGO, amdgpu_hwmon_get_pwm1_max, NULL, 0);
 static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, amdgpu_hwmon_get_fan1_input, NULL, 0);
-static SENSOR_DEVICE_ATTR(fan1_min, S_IRUGO, amdgpu_hwmon_get_fan1_min, NULL, 0);
-static SENSOR_DEVICE_ATTR(fan1_max, S_IRUGO, amdgpu_hwmon_get_fan1_max, NULL, 0);
+static SENSOR_DEVICE_ATTR(fan1_min, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_fan1_min, amdgpu_hwmon_set_fan1_min, 0);
+static SENSOR_DEVICE_ATTR(fan1_max, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_fan1_max, amdgpu_hwmon_set_fan1_max, 0);
 static SENSOR_DEVICE_ATTR(fan1_target, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_fan1_target, amdgpu_hwmon_set_fan1_target, 0);
 static SENSOR_DEVICE_ATTR(fan1_enable, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_fan1_enable, amdgpu_hwmon_set_fan1_enable, 0);
 static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, amdgpu_hwmon_show_vddgfx, NULL, 0);
diff --git a/drivers/gpu/drm/amd/include/kgd_pp_interface.h b/drivers/gpu/drm/amd/include/kgd_pp_interface.h
index 980e696989b1..1af55997bdb9 100644
--- a/drivers/gpu/drm/amd/include/kgd_pp_interface.h
+++ b/drivers/gpu/drm/amd/include/kgd_pp_interface.h
@@ -276,6 +276,8 @@ struct amd_pm_funcs {
                 struct amd_pp_simple_clock_info *clocks);
         int (*notify_smu_enable_pwe)(void *handle);
         int (*enable_mgpu_fan_boost)(void *handle);
+       int (*set_fan_speed_max_rpm)(void *handle, uint32_t rpm);
+       int (*set_fan_speed_min_rpm)(void *handle, uint32_t rpm);
 };

 #endif
diff --git a/drivers/gpu/drm/amd/powerplay/amd_powerplay.c b/drivers/gpu/drm/amd/powerplay/amd_powerplay.c
index 586f1ff9f73e..f10237b4d057 100644
--- a/drivers/gpu/drm/amd/powerplay/amd_powerplay.c
+++ b/drivers/gpu/drm/amd/powerplay/amd_powerplay.c
@@ -603,6 +603,50 @@ static int pp_dpm_set_fan_speed_rpm(void *handle, uint32_t rpm)
         return ret;
 }

+static int pp_dpm_set_fan_speed_max_rpm(void *handle, uint32_t rpm)
+{
+       struct pp_hwmgr *hwmgr = handle;
+       int ret = 0;
+
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
+
+       if (hwmgr->hwmgr_func->set_fan_speed_max_rpm == NULL) {
+               pr_info("%s was not implemented.\n", __func__);
+               return -EOPNOTSUPP;
+       }
+       mutex_lock(&hwmgr->smu_lock);
+       ret = hwmgr->hwmgr_func->set_fan_speed_max_rpm(hwmgr, rpm);
+       mutex_unlock(&hwmgr->smu_lock);
+
+       if (!ret)
+               hwmgr->thermal_controller.fanInfo.ulMaxRPM = rpm;
+
+       return ret;
+}
+
+static int pp_dpm_set_fan_speed_min_rpm(void *handle, uint32_t rpm)
+{
+       struct pp_hwmgr *hwmgr = handle;
+       int ret = 0;
+
+       if (!hwmgr || !hwmgr->pm_en)
+               return -EINVAL;
+
+       if (hwmgr->hwmgr_func->set_fan_speed_min_rpm == NULL) {
+               pr_info("%s was not implemented.\n", __func__);
+               return -EOPNOTSUPP;
+       }
+       mutex_lock(&hwmgr->smu_lock);
+       ret = hwmgr->hwmgr_func->set_fan_speed_min_rpm(hwmgr, rpm);
+       mutex_unlock(&hwmgr->smu_lock);
+
+       if (!ret)
+               hwmgr->thermal_controller.fanInfo.ulMinRPM = rpm;
+
+       return ret;
+}
+
 static int pp_dpm_get_pp_num_states(void *handle,
                 struct pp_states_info *data)
 {
@@ -1342,6 +1386,8 @@ static const struct amd_pm_funcs pp_dpm_funcs = {
         .get_fan_speed_percent = pp_dpm_get_fan_speed_percent,
         .get_fan_speed_rpm = pp_dpm_get_fan_speed_rpm,
         .set_fan_speed_rpm = pp_dpm_set_fan_speed_rpm,
+       .set_fan_speed_max_rpm = pp_dpm_set_fan_speed_max_rpm,
+       .set_fan_speed_min_rpm = pp_dpm_set_fan_speed_min_rpm,
         .get_pp_num_states = pp_dpm_get_pp_num_states,
         .get_pp_table = pp_dpm_get_pp_table,
         .set_pp_table = pp_dpm_set_pp_table,
diff --git a/drivers/gpu/drm/amd/powerplay/inc/hwmgr.h b/drivers/gpu/drm/amd/powerplay/inc/hwmgr.h
index 687f73fe4cf5..0242bc039a48 100644
--- a/drivers/gpu/drm/amd/powerplay/inc/hwmgr.h
+++ b/drivers/gpu/drm/amd/powerplay/inc/hwmgr.h
@@ -269,6 +269,8 @@ struct pp_hwmgr_func {
         int (*get_fan_speed_percent)(struct pp_hwmgr *hwmgr, uint32_t *speed);
         int (*set_fan_speed_rpm)(struct pp_hwmgr *hwmgr, uint32_t percent);
         int (*get_fan_speed_rpm)(struct pp_hwmgr *hwmgr, uint32_t *speed);
+       int (*set_fan_speed_max_rpm)(struct pp_hwmgr *hwmgr, uint32_t max_rpm);
+       int (*set_fan_speed_min_rpm)(struct pp_hwmgr *hwmgr, uint32_t min_rpm);
         int (*reset_fan_speed_to_default)(struct pp_hwmgr *hwmgr);
         int (*uninitialize_thermal_controller)(struct pp_hwmgr *hwmgr);
         int (*register_irq_handlers)(struct pp_hwmgr *hwmgr);
--
2.19.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org<mailto:amd-gfx@lists.freedesktop.org>
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

amd-gfx Info Page - freedesktop.org<https://lists.freedesktop.org/mailman/listinfo/amd-gfx>

lists.freedesktop.org

To see the collection of prior postings to the list, visit the amd-gfx Archives.. Using amd-gfx: To post a message to all the list members, send email to amd-gfx@lists.freedesktop.org<mailto:amd-gfx@lists.freedesktop.org>. You can subscribe to the list, or change your existing subscription, in the sections below.




[-- Attachment #1.2: Type: text/html, Size: 30721 bytes --]

[-- Attachment #2: Type: text/plain, Size: 154 bytes --]

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2018-10-24  9:18 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-24  8:11 [PATCH 1/3] drm/amd/powerplay: retrieve correct minimum RPM speed by MinPWM Evan Quan
     [not found] ` <20181024081141.18647-1-evan.quan-5C7GfCeVMHo@public.gmane.org>
2018-10-24  8:11   ` [PATCH 2/3] drm/amd/powerplay: added hwmon interfaces for setting max/min fan speed Evan Quan
     [not found]     ` <20181024081141.18647-2-evan.quan-5C7GfCeVMHo@public.gmane.org>
2018-10-24  8:36       ` Zhu, Rex
     [not found]         ` <BYAPR12MB2775F650496C7DA583461501FBF60-ZGDeBxoHBPmJeBUhB162ZQdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2018-10-24  8:47           ` Quan, Evan
     [not found]             ` <SN6PR12MB26563DA5F631ECD8A372CDE0E4F60-kxOKjb6HO/FeL/N0e1LXkAdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2018-10-24  9:04               ` Zhu, Rex
     [not found]                 ` <BYAPR12MB27756445D4157DD337C5B6B2FBF60-ZGDeBxoHBPmJeBUhB162ZQdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2018-10-24  9:18                   ` Quan, Evan
2018-10-24  8:11   ` [PATCH 3/3] drm/amd/powerplay: support hwmon max/min fan speed setting on Vega20 Evan Quan
     [not found]     ` <20181024081141.18647-3-evan.quan-5C7GfCeVMHo@public.gmane.org>
2018-10-24  8:37       ` Zhu, Rex
     [not found]         ` <BYAPR12MB277564C5DF32AFE83E33F7D8FBF60-ZGDeBxoHBPmJeBUhB162ZQdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2018-10-24  8:53           ` Quan, Evan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.