<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p style="margin-top:0;margin-bottom:0">One question: how to exit the max/min fan speed and return to auto mode?</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">Best Regards</p>
<p style="margin-top:0;margin-bottom:0">Rex<br>
</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<br>
<br>
<div style="color: rgb(0, 0, 0);">
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font style="font-size:11pt" color="#000000" face="Calibri, sans-serif"><b>From:</b> amd-gfx <amd-gfx-bounces@lists.freedesktop.org> on behalf of Evan Quan <evan.quan@amd.com><br>
<b>Sent:</b> Wednesday, October 24, 2018 4:11 PM<br>
<b>To:</b> amd-gfx@lists.freedesktop.org<br>
<b>Cc:</b> Quan, Evan<br>
<b>Subject:</b> [PATCH 2/3] drm/amd/powerplay: added hwmon interfaces for setting max/min fan speed</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">New hwmon interfaces for maximum and minimum fan speed setting.<br>
<br>
Change-Id: Ic9ec9f2427c6d3425e1c7e7b765d7d01a92f9a26<br>
Signed-off-by: Evan Quan <evan.quan@amd.com><br>
---<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h       |  6 ++<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c        | 56 ++++++++++++++++++-<br>
 .../gpu/drm/amd/include/kgd_pp_interface.h    |  2 +<br>
 drivers/gpu/drm/amd/powerplay/amd_powerplay.c | 46 +++++++++++++++<br>
 drivers/gpu/drm/amd/powerplay/inc/hwmgr.h     |  2 +<br>
 5 files changed, 110 insertions(+), 2 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h<br>
index f972cd156795..12c4e461a7bc 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h<br>
@@ -364,6 +364,12 @@ enum amdgpu_pcie_gen {<br>
                 ((adev)->powerplay.pp_funcs->enable_mgpu_fan_boost(\<br>
                         (adev)->powerplay.pp_handle))<br>
 <br>
+#define amdgpu_dpm_set_fan_speed_max_rpm(adev, s) \<br>
+               ((adev)->powerplay.pp_funcs->set_fan_speed_max_rpm)((adev)->powerplay.pp_handle, (s))<br>
+<br>
+#define amdgpu_dpm_set_fan_speed_min_rpm(adev, s) \<br>
+               ((adev)->powerplay.pp_funcs->set_fan_speed_min_rpm)((adev)->powerplay.pp_handle, (s))<br>
+<br>
 struct amdgpu_dpm {<br>
         struct amdgpu_ps        *ps;<br>
         /* number of valid power states */<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c<br>
index 8e94255654ed..92da37bb51ba 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c<br>
@@ -1265,6 +1265,32 @@ static ssize_t amdgpu_hwmon_get_fan1_min(struct device *dev,<br>
         return snprintf(buf, PAGE_SIZE, "%d\n", min_rpm);<br>
 }<br>
 <br>
+static ssize_t amdgpu_hwmon_set_fan1_min(struct device *dev,<br>
+                                    struct device_attribute *attr,<br>
+                                    const char *buf, size_t count)<br>
+{<br>
+       struct amdgpu_device *adev = dev_get_drvdata(dev);<br>
+       int err;<br>
+       u32 value;<br>
+<br>
+       /* Can't adjust fan when the card is off */<br>
+       if  ((adev->flags & AMD_IS_PX) &&<br>
+            (adev->ddev->switch_power_state != DRM_SWITCH_POWER_ON))<br>
+               return -EINVAL;<br>
+<br>
+       err = kstrtou32(buf, 10, &value);<br>
+       if (err)<br>
+               return err;<br>
+<br>
+       if (adev->powerplay.pp_funcs->set_fan_speed_min_rpm) {<br>
+               err = amdgpu_dpm_set_fan_speed_min_rpm(adev, value);<br>
+               if (err)<br>
+                       return err;<br>
+       }<br>
+<br>
+       return count;<br>
+}<br>
+<br>
 static ssize_t amdgpu_hwmon_get_fan1_max(struct device *dev,<br>
                                          struct device_attribute *attr,<br>
                                          char *buf)<br>
@@ -1285,6 +1311,32 @@ static ssize_t amdgpu_hwmon_get_fan1_max(struct device *dev,<br>
         return snprintf(buf, PAGE_SIZE, "%d\n", max_rpm);<br>
 }<br>
 <br>
+static ssize_t amdgpu_hwmon_set_fan1_max(struct device *dev,<br>
+                                    struct device_attribute *attr,<br>
+                                    const char *buf, size_t count)<br>
+{<br>
+       struct amdgpu_device *adev = dev_get_drvdata(dev);<br>
+       int err;<br>
+       u32 value;<br>
+<br>
+       /* Can't adjust fan when the card is off */<br>
+       if  ((adev->flags & AMD_IS_PX) &&<br>
+            (adev->ddev->switch_power_state != DRM_SWITCH_POWER_ON))<br>
+               return -EINVAL;<br>
+<br>
+       err = kstrtou32(buf, 10, &value);<br>
+       if (err)<br>
+               return err;<br>
+<br>
+       if (adev->powerplay.pp_funcs->set_fan_speed_max_rpm) {<br>
+               err = amdgpu_dpm_set_fan_speed_max_rpm(adev, value);<br>
+               if (err)<br>
+                       return err;<br>
+       }<br>
+<br>
+       return count;<br>
+}<br>
+<br>
 static ssize_t amdgpu_hwmon_get_fan1_target(struct device *dev,<br>
                                            struct device_attribute *attr,<br>
                                            char *buf)<br>
@@ -1628,8 +1680,8 @@ static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_pwm1_<br>
 static SENSOR_DEVICE_ATTR(pwm1_min, S_IRUGO, amdgpu_hwmon_get_pwm1_min, NULL, 0);<br>
 static SENSOR_DEVICE_ATTR(pwm1_max, S_IRUGO, amdgpu_hwmon_get_pwm1_max, NULL, 0);<br>
 static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, amdgpu_hwmon_get_fan1_input, NULL, 0);<br>
-static SENSOR_DEVICE_ATTR(fan1_min, S_IRUGO, amdgpu_hwmon_get_fan1_min, NULL, 0);<br>
-static SENSOR_DEVICE_ATTR(fan1_max, S_IRUGO, amdgpu_hwmon_get_fan1_max, NULL, 0);<br>
+static SENSOR_DEVICE_ATTR(fan1_min, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_fan1_min, amdgpu_hwmon_set_fan1_min, 0);<br>
+static SENSOR_DEVICE_ATTR(fan1_max, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_fan1_max, amdgpu_hwmon_set_fan1_max, 0);<br>
 static SENSOR_DEVICE_ATTR(fan1_target, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_fan1_target, amdgpu_hwmon_set_fan1_target, 0);<br>
 static SENSOR_DEVICE_ATTR(fan1_enable, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_fan1_enable, amdgpu_hwmon_set_fan1_enable, 0);<br>
 static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, amdgpu_hwmon_show_vddgfx, NULL, 0);<br>
diff --git a/drivers/gpu/drm/amd/include/kgd_pp_interface.h b/drivers/gpu/drm/amd/include/kgd_pp_interface.h<br>
index 980e696989b1..1af55997bdb9 100644<br>
--- a/drivers/gpu/drm/amd/include/kgd_pp_interface.h<br>
+++ b/drivers/gpu/drm/amd/include/kgd_pp_interface.h<br>
@@ -276,6 +276,8 @@ struct amd_pm_funcs {<br>
                 struct amd_pp_simple_clock_info *clocks);<br>
         int (*notify_smu_enable_pwe)(void *handle);<br>
         int (*enable_mgpu_fan_boost)(void *handle);<br>
+       int (*set_fan_speed_max_rpm)(void *handle, uint32_t rpm);<br>
+       int (*set_fan_speed_min_rpm)(void *handle, uint32_t rpm);<br>
 };<br>
 <br>
 #endif<br>
diff --git a/drivers/gpu/drm/amd/powerplay/amd_powerplay.c b/drivers/gpu/drm/amd/powerplay/amd_powerplay.c<br>
index 586f1ff9f73e..f10237b4d057 100644<br>
--- a/drivers/gpu/drm/amd/powerplay/amd_powerplay.c<br>
+++ b/drivers/gpu/drm/amd/powerplay/amd_powerplay.c<br>
@@ -603,6 +603,50 @@ static int pp_dpm_set_fan_speed_rpm(void *handle, uint32_t rpm)<br>
         return ret;<br>
 }<br>
 <br>
+static int pp_dpm_set_fan_speed_max_rpm(void *handle, uint32_t rpm)<br>
+{<br>
+       struct pp_hwmgr *hwmgr = handle;<br>
+       int ret = 0;<br>
+<br>
+       if (!hwmgr || !hwmgr->pm_en)<br>
+               return -EINVAL;<br>
+<br>
+       if (hwmgr->hwmgr_func->set_fan_speed_max_rpm == NULL) {<br>
+               pr_info("%s was not implemented.\n", __func__);<br>
+               return -EOPNOTSUPP;<br>
+       }<br>
+       mutex_lock(&hwmgr->smu_lock);<br>
+       ret = hwmgr->hwmgr_func->set_fan_speed_max_rpm(hwmgr, rpm);<br>
+       mutex_unlock(&hwmgr->smu_lock);<br>
+<br>
+       if (!ret)<br>
+               hwmgr->thermal_controller.fanInfo.ulMaxRPM = rpm;<br>
+<br>
+       return ret;<br>
+}<br>
+<br>
+static int pp_dpm_set_fan_speed_min_rpm(void *handle, uint32_t rpm)<br>
+{<br>
+       struct pp_hwmgr *hwmgr = handle;<br>
+       int ret = 0;<br>
+<br>
+       if (!hwmgr || !hwmgr->pm_en)<br>
+               return -EINVAL;<br>
+<br>
+       if (hwmgr->hwmgr_func->set_fan_speed_min_rpm == NULL) {<br>
+               pr_info("%s was not implemented.\n", __func__);<br>
+               return -EOPNOTSUPP;<br>
+       }<br>
+       mutex_lock(&hwmgr->smu_lock);<br>
+       ret = hwmgr->hwmgr_func->set_fan_speed_min_rpm(hwmgr, rpm);<br>
+       mutex_unlock(&hwmgr->smu_lock);<br>
+<br>
+       if (!ret)<br>
+               hwmgr->thermal_controller.fanInfo.ulMinRPM = rpm;<br>
+<br>
+       return ret;<br>
+}<br>
+<br>
 static int pp_dpm_get_pp_num_states(void *handle,<br>
                 struct pp_states_info *data)<br>
 {<br>
@@ -1342,6 +1386,8 @@ static const struct amd_pm_funcs pp_dpm_funcs = {<br>
         .get_fan_speed_percent = pp_dpm_get_fan_speed_percent,<br>
         .get_fan_speed_rpm = pp_dpm_get_fan_speed_rpm,<br>
         .set_fan_speed_rpm = pp_dpm_set_fan_speed_rpm,<br>
+       .set_fan_speed_max_rpm = pp_dpm_set_fan_speed_max_rpm,<br>
+       .set_fan_speed_min_rpm = pp_dpm_set_fan_speed_min_rpm,<br>
         .get_pp_num_states = pp_dpm_get_pp_num_states,<br>
         .get_pp_table = pp_dpm_get_pp_table,<br>
         .set_pp_table = pp_dpm_set_pp_table,<br>
diff --git a/drivers/gpu/drm/amd/powerplay/inc/hwmgr.h b/drivers/gpu/drm/amd/powerplay/inc/hwmgr.h<br>
index 687f73fe4cf5..0242bc039a48 100644<br>
--- a/drivers/gpu/drm/amd/powerplay/inc/hwmgr.h<br>
+++ b/drivers/gpu/drm/amd/powerplay/inc/hwmgr.h<br>
@@ -269,6 +269,8 @@ struct pp_hwmgr_func {<br>
         int (*get_fan_speed_percent)(struct pp_hwmgr *hwmgr, uint32_t *speed);<br>
         int (*set_fan_speed_rpm)(struct pp_hwmgr *hwmgr, uint32_t percent);<br>
         int (*get_fan_speed_rpm)(struct pp_hwmgr *hwmgr, uint32_t *speed);<br>
+       int (*set_fan_speed_max_rpm)(struct pp_hwmgr *hwmgr, uint32_t max_rpm);<br>
+       int (*set_fan_speed_min_rpm)(struct pp_hwmgr *hwmgr, uint32_t min_rpm);<br>
         int (*reset_fan_speed_to_default)(struct pp_hwmgr *hwmgr);<br>
         int (*uninitialize_thermal_controller)(struct pp_hwmgr *hwmgr);<br>
         int (*register_irq_handlers)(struct pp_hwmgr *hwmgr);<br>
-- <br>
2.19.1<br>
<br>
_______________________________________________<br>
amd-gfx mailing list<br>
amd-gfx@lists.freedesktop.org<br>
<a href="https://lists.freedesktop.org/mailman/listinfo/amd-gfx" id="LPlnk568164" class="OWAAutoLink" previewremoved="true">https://lists.freedesktop.org/mailman/listinfo/amd-gfx</a>
<div id="LPBorder_GT_15403698863000.14269909928300328" style="margin-bottom: 20px; overflow: auto; width: 100%; text-indent: 0px;">
<table id="LPContainer_15403698862980.8796761397604639" style="width: 90%; background-color: rgb(255, 255, 255); position: relative; overflow: auto; padding-top: 20px; padding-bottom: 20px; margin-top: 20px; border-top: 1px dotted rgb(200, 200, 200); border-bottom: 1px dotted rgb(200, 200, 200);" role="presentation" cellspacing="0">
<tbody>
<tr style="border-spacing: 0px;" valign="top">
<td id="TextCell_15403698863000.8597383540435837" style="vertical-align: top; position: relative; padding: 0px; display: table-cell;" colspan="2">
<div id="LPRemovePreviewContainer_15403698863000.8055293495204474"></div>
<div id="LPTitle_15403698863000.9916224528545828" style="top: 0px; color: rgb(0, 120, 215); font-weight: 400; font-size: 21px; font-family: "wf_segoe-ui_light", "Segoe UI Light", "Segoe WP Light", "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif; line-height: 21px;">
<a id="LPUrlAnchor_15403698863000.14093576092280713" style="text-decoration: none;" href="https://lists.freedesktop.org/mailman/listinfo/amd-gfx" target="_blank">amd-gfx Info Page - freedesktop.org</a></div>
<div id="LPMetadata_15403698863000.39120505537129757" style="margin: 10px 0px 16px; color: rgb(102, 102, 102); font-weight: 400; font-family: "wf_segoe-ui_normal", "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif; font-size: 14px; line-height: 14px;">
lists.freedesktop.org</div>
<div id="LPDescription_15403698863000.17702711523041492" style="display: block; color: rgb(102, 102, 102); font-weight: 400; font-family: "wf_segoe-ui_normal", "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif; font-size: 14px; line-height: 20px; max-height: 100px; overflow: hidden;">
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. You can subscribe to the list, or change your existing subscription, in
 the sections below.</div>
</td>
</tr>
</tbody>
</table>
</div>
<br>
</div>
</span></font></div>
</div>
</div>
</body>
</html>