drm/amd/pm: correct the fan speed retrieving in PWM for some SMU13 asics
authorjsg <jsg@openbsd.org>
Mon, 9 Jan 2023 04:32:29 +0000 (04:32 +0000)
committerjsg <jsg@openbsd.org>
Mon, 9 Jan 2023 04:32:29 +0000 (04:32 +0000)
From Evan Quan
54b6a040f38075711751c61b2300a8ce7cb1741f in linux-6.1.y/6.1.4
e73fc71e8f015d61f3adca7659cb209fd5117aa5 in mainline linux

sys/dev/pci/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c
sys/dev/pci/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c

index 3d15cc7..9d16b42 100644 (file)
@@ -1419,12 +1419,23 @@ out:
 static int smu_v13_0_0_get_fan_speed_pwm(struct smu_context *smu,
                                         uint32_t *speed)
 {
+       int ret;
+
        if (!speed)
                return -EINVAL;
 
-       return smu_v13_0_0_get_smu_metrics_data(smu,
-                                               METRICS_CURR_FANPWM,
-                                               speed);
+       ret = smu_v13_0_0_get_smu_metrics_data(smu,
+                                              METRICS_CURR_FANPWM,
+                                              speed);
+       if (ret) {
+               dev_err(smu->adev->dev, "Failed to get fan speed(PWM)!");
+               return ret;
+       }
+
+       /* Convert the PMFW output which is in percent to pwm(255) based */
+       *speed = MIN(*speed * 255 / 100, 255);
+
+       return 0;
 }
 
 static int smu_v13_0_0_get_fan_speed_rpm(struct smu_context *smu,
index 94b6652..21f192e 100644 (file)
@@ -1363,12 +1363,23 @@ static int smu_v13_0_7_populate_umd_state_clk(struct smu_context *smu)
 static int smu_v13_0_7_get_fan_speed_pwm(struct smu_context *smu,
                                         uint32_t *speed)
 {
+       int ret;
+
        if (!speed)
                return -EINVAL;
 
-       return smu_v13_0_7_get_smu_metrics_data(smu,
-                                               METRICS_CURR_FANPWM,
-                                               speed);
+       ret = smu_v13_0_7_get_smu_metrics_data(smu,
+                                              METRICS_CURR_FANPWM,
+                                              speed);
+       if (ret) {
+               dev_err(smu->adev->dev, "Failed to get fan speed(PWM)!");
+               return ret;
+       }
+
+       /* Convert the PMFW output which is in percent to pwm(255) based */
+       *speed = MIN(*speed * 255 / 100, 255);
+
+       return 0;
 }
 
 static int smu_v13_0_7_get_fan_speed_rpm(struct smu_context *smu,