<div dir="auto"><div>Hi Evan,<div dir="auto"><br></div><div dir="auto">Bit of a drive by comment but I think that maybe all the *_fan_speed_percent() function names are a bit confusing if they no longer operate on percents but on a duty cycle unit of 0-255. No good idea what to call them though :-\</div><div dir="auto"><br></div><div dir="auto">Also max() could be used in a bunch of places instead of</div><div dir="auto"><br></div><div dir="auto"> <span style="font-family:sans-serif;font-size:12.8px">   if (speed > 255)</span></div><span style="font-family:sans-serif;font-size:12.8px">              speed = 255;</span><br><br>Regards,</div><div dir="auto">Nils<br><br><div class="gmail_quote" dir="auto"><div dir="ltr" class="gmail_attr">Den ons 7 juli 2021 03:59Evan Quan <<a href="mailto:evan.quan@amd.com">evan.quan@amd.com</a>> skrev:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Currently, the readout of fan speed pwm is transited into percent-based<br>
and then pwm-based. However, the transition into percent-based is totally<br>
unnecessary and make the final output less accurate.<br>
<br>
Change-Id: Ib99e088cda1875b4e2601f7077a178af6fe8a6cb<br>
Signed-off-by: Evan Quan <<a href="mailto:evan.quan@amd.com" target="_blank" rel="noreferrer">evan.quan@amd.com</a>><br>
---<br>
 drivers/gpu/drm/amd/pm/amdgpu_pm.c                 |  4 ----<br>
 .../gpu/drm/amd/pm/powerplay/hwmgr/smu7_hwmgr.c    |  4 ++--<br>
 .../gpu/drm/amd/pm/powerplay/hwmgr/smu7_thermal.c  | 12 ++++++------<br>
 .../gpu/drm/amd/pm/powerplay/hwmgr/vega10_hwmgr.c  |  2 +-<br>
 .../drm/amd/pm/powerplay/hwmgr/vega10_thermal.c    | 10 +++++-----<br>
 .../gpu/drm/amd/pm/powerplay/hwmgr/vega20_hwmgr.c  |  2 +-<br>
 .../drm/amd/pm/powerplay/hwmgr/vega20_thermal.c    | 12 ++++++------<br>
 drivers/gpu/drm/amd/pm/powerplay/si_dpm.c          | 10 +++++-----<br>
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c          | 12 ++----------<br>
 drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c     | 14 +++++++-------<br>
 10 files changed, 35 insertions(+), 47 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/pm/amdgpu_pm.c b/drivers/gpu/drm/amd/pm/amdgpu_pm.c<br>
index 769f58d5ae1a..e9c98e3f4cfb 100644<br>
--- a/drivers/gpu/drm/amd/pm/amdgpu_pm.c<br>
+++ b/drivers/gpu/drm/amd/pm/amdgpu_pm.c<br>
@@ -2469,8 +2469,6 @@ static ssize_t amdgpu_hwmon_set_pwm1(struct device *dev,<br>
                return err;<br>
        }<br>
<br>
-       value = (value * 100) / 255;<br>
-<br>
        if (adev->powerplay.pp_funcs->set_fan_speed_percent)<br>
                err = amdgpu_dpm_set_fan_speed_percent(adev, value);<br>
        else<br>
@@ -2515,8 +2513,6 @@ static ssize_t amdgpu_hwmon_get_pwm1(struct device *dev,<br>
        if (err)<br>
                return err;<br>
<br>
-       speed = (speed * 255) / 100;<br>
-<br>
        return sprintf(buf, "%i\n", speed);<br>
 }<br>
<br>
diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu7_hwmgr.c b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu7_hwmgr.c<br>
index 0541bfc81c1b..aa353a628c50 100644<br>
--- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu7_hwmgr.c<br>
+++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu7_hwmgr.c<br>
@@ -3212,7 +3212,7 @@ static int smu7_force_dpm_level(struct pp_hwmgr *hwmgr,<br>
<br>
        if (!ret) {<br>
                if (level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK && hwmgr->dpm_level != AMD_DPM_FORCED_LEVEL_PROFILE_PEAK)<br>
-                       smu7_fan_ctrl_set_fan_speed_percent(hwmgr, 100);<br>
+                       smu7_fan_ctrl_set_fan_speed_percent(hwmgr, 255);<br>
                else if (level != AMD_DPM_FORCED_LEVEL_PROFILE_PEAK && hwmgr->dpm_level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK)<br>
                        smu7_fan_ctrl_reset_fan_speed_to_default(hwmgr);<br>
        }<br>
@@ -4988,7 +4988,7 @@ static void smu7_set_fan_control_mode(struct pp_hwmgr *hwmgr, uint32_t mode)<br>
 {<br>
        switch (mode) {<br>
        case AMD_FAN_CTRL_NONE:<br>
-               smu7_fan_ctrl_set_fan_speed_percent(hwmgr, 100);<br>
+               smu7_fan_ctrl_set_fan_speed_percent(hwmgr, 255);<br>
                break;<br>
        case AMD_FAN_CTRL_MANUAL:<br>
                if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,<br>
diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu7_thermal.c b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu7_thermal.c<br>
index 6cfe148ed45b..70ccc127e3fd 100644<br>
--- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu7_thermal.c<br>
+++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu7_thermal.c<br>
@@ -70,12 +70,12 @@ int smu7_fan_ctrl_get_fan_speed_percent(struct pp_hwmgr *hwmgr,<br>
                return -EINVAL;<br>
<br>
<br>
-       tmp64 = (uint64_t)duty * 100;<br>
+       tmp64 = (uint64_t)duty * 255;<br>
        do_div(tmp64, duty100);<br>
        *speed = (uint32_t)tmp64;<br>
<br>
-       if (*speed > 100)<br>
-               *speed = 100;<br>
+       if (*speed > 255)<br>
+               *speed = 255;<br>
<br>
        return 0;<br>
 }<br>
@@ -214,8 +214,8 @@ int smu7_fan_ctrl_set_fan_speed_percent(struct pp_hwmgr *hwmgr,<br>
        if (hwmgr->thermal_controller.fanInfo.bNoFan)<br>
                return 0;<br>
<br>
-       if (speed > 100)<br>
-               speed = 100;<br>
+       if (speed > 255)<br>
+               speed = 255;<br>
<br>
        if (PP_CAP(PHM_PlatformCaps_MicrocodeFanControl))<br>
                smu7_fan_ctrl_stop_smc_fan_control(hwmgr);<br>
@@ -227,7 +227,7 @@ int smu7_fan_ctrl_set_fan_speed_percent(struct pp_hwmgr *hwmgr,<br>
                return -EINVAL;<br>
<br>
        tmp64 = (uint64_t)speed * duty100;<br>
-       do_div(tmp64, 100);<br>
+       do_div(tmp64, 255);<br>
        duty = (uint32_t)tmp64;<br>
<br>
        PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,<br>
diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_hwmgr.c b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_hwmgr.c<br>
index 25979106fd25..44c5e2588046 100644<br>
--- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_hwmgr.c<br>
+++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_hwmgr.c<br>
@@ -4199,7 +4199,7 @@ static void vega10_set_fan_control_mode(struct pp_hwmgr *hwmgr, uint32_t mode)<br>
<br>
        switch (mode) {<br>
        case AMD_FAN_CTRL_NONE:<br>
-               vega10_fan_ctrl_set_fan_speed_percent(hwmgr, 100);<br>
+               vega10_fan_ctrl_set_fan_speed_percent(hwmgr, 255);<br>
                break;<br>
        case AMD_FAN_CTRL_MANUAL:<br>
                if (PP_CAP(PHM_PlatformCaps_MicrocodeFanControl))<br>
diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_thermal.c b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_thermal.c<br>
index 9b46b27bd30c..6b4c4294afca 100644<br>
--- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_thermal.c<br>
+++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_thermal.c<br>
@@ -78,11 +78,11 @@ int vega10_fan_ctrl_get_fan_speed_percent(struct pp_hwmgr *hwmgr,<br>
<br>
        if (hwmgr->thermal_controller.<br>
                        advanceFanControlParameters.usMaxFanRPM != 0)<br>
-               percent = current_rpm * 100 /<br>
+               percent = current_rpm * 255 /<br>
                        hwmgr->thermal_controller.<br>
                        advanceFanControlParameters.usMaxFanRPM;<br>
<br>
-       *speed = percent > 100 ? 100 : percent;<br>
+       *speed = percent > 255 ? 255 : percent;<br>
<br>
        return 0;<br>
 }<br>
@@ -257,8 +257,8 @@ int vega10_fan_ctrl_set_fan_speed_percent(struct pp_hwmgr *hwmgr,<br>
        if (hwmgr->thermal_controller.fanInfo.bNoFan)<br>
                return 0;<br>
<br>
-       if (speed > 100)<br>
-               speed = 100;<br>
+       if (speed > 255)<br>
+               speed = 255;<br>
<br>
        if (PP_CAP(PHM_PlatformCaps_MicrocodeFanControl))<br>
                vega10_fan_ctrl_stop_smc_fan_control(hwmgr);<br>
@@ -270,7 +270,7 @@ int vega10_fan_ctrl_set_fan_speed_percent(struct pp_hwmgr *hwmgr,<br>
                return -EINVAL;<br>
<br>
        tmp64 = (uint64_t)speed * duty100;<br>
-       do_div(tmp64, 100);<br>
+       do_div(tmp64, 255);<br>
        duty = (uint32_t)tmp64;<br>
<br>
        WREG32_SOC15(THM, 0, mmCG_FDO_CTRL0,<br>
diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega20_hwmgr.c b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega20_hwmgr.c<br>
index 0791309586c5..cbe5f8027ee0 100644<br>
--- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega20_hwmgr.c<br>
+++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega20_hwmgr.c<br>
@@ -2769,7 +2769,7 @@ static void vega20_set_fan_control_mode(struct pp_hwmgr *hwmgr, uint32_t mode)<br>
 {<br>
        switch (mode) {<br>
        case AMD_FAN_CTRL_NONE:<br>
-               vega20_fan_ctrl_set_fan_speed_percent(hwmgr, 100);<br>
+               vega20_fan_ctrl_set_fan_speed_percent(hwmgr, 255);<br>
                break;<br>
        case AMD_FAN_CTRL_MANUAL:<br>
                if (PP_CAP(PHM_PlatformCaps_MicrocodeFanControl))<br>
diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega20_thermal.c b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega20_thermal.c<br>
index 43d754952bd9..eb007c00d7c6 100644<br>
--- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega20_thermal.c<br>
+++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega20_thermal.c<br>
@@ -129,12 +129,12 @@ int vega20_fan_ctrl_get_fan_speed_percent(struct pp_hwmgr *hwmgr,<br>
        if (!duty100)<br>
                return -EINVAL;<br>
<br>
-       tmp64 = (uint64_t)duty * 100;<br>
+       tmp64 = (uint64_t)duty * 255;<br>
        do_div(tmp64, duty100);<br>
        *speed = (uint32_t)tmp64;<br>
<br>
-       if (*speed > 100)<br>
-               *speed = 100;<br>
+       if (*speed > 255)<br>
+               *speed = 255;<br>
<br>
        return 0;<br>
 }<br>
@@ -147,8 +147,8 @@ int vega20_fan_ctrl_set_fan_speed_percent(struct pp_hwmgr *hwmgr,<br>
        uint32_t duty;<br>
        uint64_t tmp64;<br>
<br>
-       if (speed > 100)<br>
-               speed = 100;<br>
+       if (speed > 255)<br>
+               speed = 255;<br>
<br>
        if (PP_CAP(PHM_PlatformCaps_MicrocodeFanControl))<br>
                vega20_fan_ctrl_stop_smc_fan_control(hwmgr);<br>
@@ -160,7 +160,7 @@ int vega20_fan_ctrl_set_fan_speed_percent(struct pp_hwmgr *hwmgr,<br>
                return -EINVAL;<br>
<br>
        tmp64 = (uint64_t)speed * duty100;<br>
-       do_div(tmp64, 100);<br>
+       do_div(tmp64, 255);<br>
        duty = (uint32_t)tmp64;<br>
<br>
        WREG32_SOC15(THM, 0, mmCG_FDO_CTRL0,<br>
diff --git a/drivers/gpu/drm/amd/pm/powerplay/si_dpm.c b/drivers/gpu/drm/amd/pm/powerplay/si_dpm.c<br>
index 15c0b8af376f..96ca359c10a5 100644<br>
--- a/drivers/gpu/drm/amd/pm/powerplay/si_dpm.c<br>
+++ b/drivers/gpu/drm/amd/pm/powerplay/si_dpm.c<br>
@@ -6555,12 +6555,12 @@ static int si_dpm_get_fan_speed_percent(void *handle,<br>
        if (duty100 == 0)<br>
                return -EINVAL;<br>
<br>
-       tmp64 = (u64)duty * 100;<br>
+       tmp64 = (u64)duty * 255;<br>
        do_div(tmp64, duty100);<br>
        *speed = (u32)tmp64;<br>
<br>
-       if (*speed > 100)<br>
-               *speed = 100;<br>
+       if (*speed > 255)<br>
+               *speed = 255;<br>
<br>
        return 0;<br>
 }<br>
@@ -6580,7 +6580,7 @@ static int si_dpm_set_fan_speed_percent(void *handle,<br>
        if (si_pi->fan_is_controlled_by_smc)<br>
                return -EINVAL;<br>
<br>
-       if (speed > 100)<br>
+       if (speed > 255)<br>
                return -EINVAL;<br>
<br>
        duty100 = (RREG32(CG_FDO_CTRL1) & FMAX_DUTY100_MASK) >> FMAX_DUTY100_SHIFT;<br>
@@ -6589,7 +6589,7 @@ static int si_dpm_set_fan_speed_percent(void *handle,<br>
                return -EINVAL;<br>
<br>
        tmp64 = (u64)speed * duty100;<br>
-       do_div(tmp64, 100);<br>
+       do_div(tmp64, 255);<br>
        duty = (u32)tmp64;<br>
<br>
        tmp = RREG32(CG_FDO_CTRL0) & ~FDO_STATIC_DUTY_MASK;<br>
diff --git a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c<br>
index 54fb3d7d23ee..94c15526ad21 100644<br>
--- a/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c<br>
+++ b/drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c<br>
@@ -2565,23 +2565,17 @@ static int smu_get_fan_speed_percent(void *handle, u32 *speed)<br>
 {<br>
        struct smu_context *smu = handle;<br>
        int ret = 0;<br>
-       uint32_t percent;<br>
<br>
        if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled)<br>
                return -EOPNOTSUPP;<br>
<br>
        mutex_lock(&smu->mutex);<br>
<br>
-       if (smu->ppt_funcs->get_fan_speed_percent) {<br>
-               ret = smu->ppt_funcs->get_fan_speed_percent(smu, &percent);<br>
-               if (!ret) {<br>
-                       *speed = percent > 100 ? 100 : percent;<br>
-               }<br>
-       }<br>
+       if (smu->ppt_funcs->get_fan_speed_percent)<br>
+               ret = smu->ppt_funcs->get_fan_speed_percent(smu, speed);<br>
<br>
        mutex_unlock(&smu->mutex);<br>
<br>
-<br>
        return ret;<br>
 }<br>
<br>
@@ -2596,8 +2590,6 @@ static int smu_set_fan_speed_percent(void *handle, u32 speed)<br>
        mutex_lock(&smu->mutex);<br>
<br>
        if (smu->ppt_funcs->set_fan_speed_percent) {<br>
-               if (speed > 100)<br>
-                       speed = 100;<br>
                ret = smu->ppt_funcs->set_fan_speed_percent(smu, speed);<br>
                if (!ret && !(smu->user_dpm_profile.flags & SMU_DPM_USER_PROFILE_RESTORE)) {<br>
                        smu->user_dpm_profile.custom_fan_speed |= SMU_CUSTOM_FAN_SPEED_PWM;<br>
diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c b/drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c<br>
index 0cdf55a0dba2..f0ae0920c07e 100644<br>
--- a/drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c<br>
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c<br>
@@ -1191,8 +1191,8 @@ smu_v11_0_set_fan_speed_percent(struct smu_context *smu, uint32_t speed)<br>
        uint32_t duty100, duty;<br>
        uint64_t tmp64;<br>
<br>
-       if (speed > 100)<br>
-               speed = 100;<br>
+       if (speed > 255)<br>
+               speed = 255;<br>
<br>
        if (smu_v11_0_auto_fan_control(smu, 0))<br>
                return -EINVAL;<br>
@@ -1203,7 +1203,7 @@ smu_v11_0_set_fan_speed_percent(struct smu_context *smu, uint32_t speed)<br>
                return -EINVAL;<br>
<br>
        tmp64 = (uint64_t)speed * duty100;<br>
-       do_div(tmp64, 100);<br>
+       do_div(tmp64, 255);<br>
        duty = (uint32_t)tmp64;<br>
<br>
        WREG32_SOC15(THM, 0, mmCG_FDO_CTRL0,<br>
@@ -1274,12 +1274,12 @@ int smu_v11_0_get_fan_speed_percent(struct smu_context *smu,<br>
        if (!duty100)<br>
                return -EINVAL;<br>
<br>
-       tmp64 = (uint64_t)duty * 100;<br>
+       tmp64 = (uint64_t)duty * 255;<br>
        do_div(tmp64, duty100);<br>
        *speed = (uint32_t)tmp64;<br>
<br>
-       if (*speed > 100)<br>
-               *speed = 100;<br>
+       if (*speed > 255)<br>
+               *speed = 255;<br>
<br>
        return 0;<br>
 }<br>
@@ -1320,7 +1320,7 @@ smu_v11_0_set_fan_control_mode(struct smu_context *smu,<br>
<br>
        switch (mode) {<br>
        case AMD_FAN_CTRL_NONE:<br>
-               ret = smu_v11_0_set_fan_speed_percent(smu, 100);<br>
+               ret = smu_v11_0_set_fan_speed_percent(smu, 255);<br>
                break;<br>
        case AMD_FAN_CTRL_MANUAL:<br>
                ret = smu_v11_0_auto_fan_control(smu, 0);<br>
-- <br>
2.29.0<br>
<br>
_______________________________________________<br>
amd-gfx mailing list<br>
<a href="mailto:amd-gfx@lists.freedesktop.org" target="_blank" rel="noreferrer">amd-gfx@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/amd-gfx" rel="noreferrer noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/amd-gfx</a><br>
</blockquote></div></div></div>