<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"><font size="2"><span style="font-size:11pt;">-       percent = current_rpm * 100 / pp_table->FanMaximumRpm;<br>
+       percent = (current_rpm * 100) /<br>
+               hwmgr->thermal_controller.fanInfo.ulMaxRPM;</span></font><br>
</p>
<br>
<p style="margin-top:0;margin-bottom:0">Better check <font size="2"><span style="font-size:11pt;">hwmgr->thermal_controller.fanInfo.ulMaxRPM</span></font> not equal to 0.</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>
<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 3/3] drm/amd/powerplay: support hwmon max/min fan speed setting on Vega20</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">Added support for hwmon max/min fan speed setting on Vega20.<br>
<br>
Change-Id: Ieab42c744d6c54f8b85a71be80f7c6832ae7352b<br>
Signed-off-by: Evan Quan <evan.quan@amd.com><br>
---<br>
 .../drm/amd/powerplay/hwmgr/vega20_hwmgr.c    |  4 ++<br>
 .../drm/amd/powerplay/hwmgr/vega20_thermal.c  | 56 ++++++++++++++++++-<br>
 .../drm/amd/powerplay/hwmgr/vega20_thermal.h  |  4 ++<br>
 3 files changed, 62 insertions(+), 2 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c<br>
index 57143d51e3ee..2513e6be3219 100644<br>
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c<br>
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c<br>
@@ -3539,6 +3539,10 @@ static const struct pp_hwmgr_func vega20_hwmgr_funcs = {<br>
                 vega20_get_fan_control_mode,<br>
         .set_fan_control_mode =<br>
                 vega20_set_fan_control_mode,<br>
+       .set_fan_speed_max_rpm =<br>
+               vega20_fan_ctrl_set_fan_speed_max_rpm,<br>
+       .set_fan_speed_min_rpm =<br>
+               vega20_fan_ctrl_set_fan_speed_min_rpm,<br>
         /* smu memory related */<br>
         .notify_cac_buffer_info =<br>
                 vega20_notify_cac_buffer_info,<br>
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_thermal.c b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_thermal.c<br>
index ede54e87e287..da9fd2168dcb 100644<br>
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_thermal.c<br>
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_thermal.c<br>
@@ -118,7 +118,6 @@ int vega20_fan_ctrl_get_fan_speed_percent(struct pp_hwmgr *hwmgr,<br>
                 uint32_t *speed)<br>
 {<br>
         struct vega20_hwmgr *data = (struct vega20_hwmgr *)(hwmgr->backend);<br>
-       PPTable_t *pp_table = &(data->smc_state_table.pp_table);<br>
         uint32_t current_rpm, percent = 0;<br>
         int ret = 0;<br>
 <br>
@@ -126,7 +125,8 @@ int vega20_fan_ctrl_get_fan_speed_percent(struct pp_hwmgr *hwmgr,<br>
         if (ret)<br>
                 return ret;<br>
 <br>
-       percent = current_rpm * 100 / pp_table->FanMaximumRpm;<br>
+       percent = (current_rpm * 100) /<br>
+               hwmgr->thermal_controller.fanInfo.ulMaxRPM;<br>
 <br>
         *speed = percent > 100 ? 100 : percent;<br>
 <br>
@@ -208,6 +208,58 @@ int vega20_fan_ctrl_set_fan_speed_rpm(struct pp_hwmgr *hwmgr, uint32_t speed)<br>
         return vega20_fan_ctrl_set_static_mode(hwmgr, FDO_PWM_MODE_STATIC_RPM);<br>
 }<br>
 <br>
+int vega20_fan_ctrl_set_fan_speed_max_rpm(struct pp_hwmgr *hwmgr, uint32_t speed)<br>
+{<br>
+       struct vega20_hwmgr *data = (struct vega20_hwmgr *)(hwmgr->backend);<br>
+       struct vega20_od8_settings *od8_settings = &(data->od8_settings);<br>
+       int ret = 0;<br>
+<br>
+       if ((od8_settings->overdrive8_capabilities & OD8_ACOUSTIC_LIMIT_SCLK) &&<br>
+           (speed > od8_settings->od8_settings_array[OD8_SETTING_FAN_ACOUSTIC_LIMIT].max_value ||<br>
+            speed < od8_settings->od8_settings_array[OD8_SETTING_FAN_ACOUSTIC_LIMIT].min_value))<br>
+               return -EINVAL;<br>
+<br>
+       ret = smum_send_msg_to_smc_with_parameter(hwmgr,<br>
+                       PPSMC_MSG_SetFanMaxRpm,<br>
+                       speed);<br>
+       PP_ASSERT_WITH_CODE(!ret,<br>
+                       "Set FanMaxRpm Failed!",<br>
+                       return ret);<br>
+<br>
+       hwmgr->thermal_controller.fanInfo.ulMinRPM =<br>
+               (speed * hwmgr->thermal_controller.fanInfo.ulMinPWM) / 255;<br>
+<br>
+       return ret;<br>
+}<br>
+<br>
+int vega20_fan_ctrl_set_fan_speed_min_rpm(struct pp_hwmgr *hwmgr, uint32_t speed)<br>
+{<br>
+       struct vega20_hwmgr *data = (struct vega20_hwmgr *)(hwmgr->backend);<br>
+       struct vega20_od8_settings *od8_settings = &(data->od8_settings);<br>
+       int ret = 0;<br>
+       uint32_t pwm = 0;<br>
+<br>
+       if ((od8_settings->overdrive8_capabilities & OD8_FAN_SPEED_MIN) &&<br>
+           (speed > od8_settings->od8_settings_array[OD8_FAN_SPEED_MIN].max_value ||<br>
+            speed < od8_settings->od8_settings_array[OD8_FAN_SPEED_MIN].min_value))<br>
+               return -EINVAL;<br>
+<br>
+       if (speed > hwmgr->thermal_controller.fanInfo.ulMaxRPM)<br>
+               return -EINVAL;<br>
+<br>
+       pwm = (speed * 255) / hwmgr->thermal_controller.fanInfo.ulMaxRPM;<br>
+       ret = smum_send_msg_to_smc_with_parameter(hwmgr,<br>
+                       PPSMC_MSG_SetFanMinPwm,<br>
+                       pwm);<br>
+       PP_ASSERT_WITH_CODE(!ret,<br>
+                       "Set FanMinPwm Failed!",<br>
+                       return ret);<br>
+<br>
+       hwmgr->thermal_controller.fanInfo.ulMinPWM = pwm;<br>
+<br>
+       return ret;<br>
+}<br>
+<br>
 /**<br>
 * Reads the remote temperature from the SIslands thermal controller.<br>
 *<br>
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_thermal.h b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_thermal.h<br>
index 2d1769bbd24e..ddfc950e90ca 100644<br>
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_thermal.h<br>
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_thermal.h<br>
@@ -56,6 +56,10 @@ extern int vega20_fan_ctrl_get_fan_speed_rpm(struct pp_hwmgr *hwmgr,<br>
                 uint32_t *speed);<br>
 extern int vega20_fan_ctrl_set_fan_speed_rpm(struct pp_hwmgr *hwmgr,<br>
                 uint32_t speed);<br>
+extern int vega20_fan_ctrl_set_fan_speed_max_rpm(struct pp_hwmgr *hwmgr,<br>
+               uint32_t speed);<br>
+extern int vega20_fan_ctrl_set_fan_speed_min_rpm(struct pp_hwmgr *hwmgr,<br>
+               uint32_t speed);<br>
 extern int vega20_fan_ctrl_get_fan_speed_percent(struct pp_hwmgr *hwmgr,<br>
                 uint32_t *speed);<br>
 extern int vega20_fan_ctrl_set_fan_speed_percent(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="LPlnk381309" class="OWAAutoLink" previewremoved="true">https://lists.freedesktop.org/mailman/listinfo/amd-gfx</a>
<div id="LPBorder_GT_15403701438120.35346562924862934" style="margin-bottom: 20px; overflow: auto; width: 100%; text-indent: 0px;">
<table id="LPContainer_15403701438100.09324088395310604" 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_15403701438100.42838297273526393" style="vertical-align: top; position: relative; padding: 0px; display: table-cell;" colspan="2">
<div id="LPRemovePreviewContainer_15403701438100.12312966594444197"></div>
<div id="LPTitle_15403701438100.6054106554689949" 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_15403701438120.9937893318723561" 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_15403701438120.035970050768817985" 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_15403701438120.9681582559548375" 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>