Revert "drm/amdgpu: Revert "drm/amdgpu: getting fan speed pwm for vega10 properly""
authorjsg <jsg@openbsd.org>
Thu, 19 Jan 2023 00:15:38 +0000 (00:15 +0000)
committerjsg <jsg@openbsd.org>
Thu, 19 Jan 2023 00:15:38 +0000 (00:15 +0000)
From Alex Deucher
f905e03c8ff65d80c24f42d8b93df3cec5a7ab12 in linux-6.1.y/6.1.7
30b8e7b8ee3be003e0df85c857c5cd0e0bd58b82 in mainline linux

sys/dev/pci/drm/amd/pm/powerplay/hwmgr/vega10_thermal.c

index dad3e37..190af79 100644 (file)
@@ -67,22 +67,21 @@ int vega10_fan_ctrl_get_fan_speed_info(struct pp_hwmgr *hwmgr,
 int vega10_fan_ctrl_get_fan_speed_pwm(struct pp_hwmgr *hwmgr,
                uint32_t *speed)
 {
-       uint32_t current_rpm;
-       uint32_t percent = 0;
-
-       if (hwmgr->thermal_controller.fanInfo.bNoFan)
-               return 0;
+       struct amdgpu_device *adev = hwmgr->adev;
+       uint32_t duty100, duty;
+       uint64_t tmp64;
 
-       if (vega10_get_current_rpm(hwmgr, &current_rpm))
-               return -1;
+       duty100 = REG_GET_FIELD(RREG32_SOC15(THM, 0, mmCG_FDO_CTRL1),
+                               CG_FDO_CTRL1, FMAX_DUTY100);
+       duty = REG_GET_FIELD(RREG32_SOC15(THM, 0, mmCG_THERMAL_STATUS),
+                               CG_THERMAL_STATUS, FDO_PWM_DUTY);
 
-       if (hwmgr->thermal_controller.
-                       advanceFanControlParameters.usMaxFanRPM != 0)
-               percent = current_rpm * 255 /
-                       hwmgr->thermal_controller.
-                       advanceFanControlParameters.usMaxFanRPM;
+       if (!duty100)
+               return -EINVAL;
 
-       *speed = MIN(percent, 255);
+       tmp64 = (uint64_t)duty * 255;
+       do_div(tmp64, duty100);
+       *speed = MIN((uint32_t)tmp64, 255);
 
        return 0;
 }