drm/amd/powerplay: refine pwm1_enable callback functions for vi.
authorRex Zhu <Rex.Zhu@amd.com>
Fri, 5 May 2017 08:50:36 +0000 (16:50 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 10 May 2017 17:36:35 +0000 (13:36 -0400)
Use the new enums for setting and getting the fan control mode.
Fixes problems due to previous inconsistencies between enums.

Signed-off-by: Rex Zhu <Rex.Zhu@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c
drivers/gpu/drm/amd/powerplay/hwmgr/smu7_thermal.c
drivers/gpu/drm/amd/powerplay/hwmgr/smu7_thermal.h
drivers/gpu/drm/amd/powerplay/inc/hwmgr.h

index b3d42858f68b6f75bfc33ac1c9e7635b43b0a64c..a74a3db3056c9c4a991e2b4525eb09de8a234a0a 100644 (file)
@@ -4334,26 +4334,31 @@ static int smu7_print_clock_levels(struct pp_hwmgr *hwmgr,
 
 static int smu7_set_fan_control_mode(struct pp_hwmgr *hwmgr, uint32_t mode)
 {
-       if (mode) {
-               /* stop auto-manage */
-               if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
-                               PHM_PlatformCaps_MicrocodeFanControl))
-                       smu7_fan_ctrl_stop_smc_fan_control(hwmgr);
-               smu7_fan_ctrl_set_static_mode(hwmgr, mode);
-       } else
-               /* restart auto-manage */
-               smu7_fan_ctrl_reset_fan_speed_to_default(hwmgr);
+       int result = 0;
 
-       return 0;
+       switch (mode) {
+       case AMD_FAN_CTRL_NONE:
+               result = smu7_fan_ctrl_set_fan_speed_percent(hwmgr, 100);
+               break;
+       case AMD_FAN_CTRL_MANUAL:
+               if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
+                       PHM_PlatformCaps_MicrocodeFanControl))
+                       result = smu7_fan_ctrl_stop_smc_fan_control(hwmgr);
+               break;
+       case AMD_FAN_CTRL_AUTO:
+               result = smu7_fan_ctrl_set_static_mode(hwmgr, mode);
+               if (!result)
+                       result = smu7_fan_ctrl_start_smc_fan_control(hwmgr);
+               break;
+       default:
+               break;
+       }
+       return result;
 }
 
 static int smu7_get_fan_control_mode(struct pp_hwmgr *hwmgr)
 {
-       if (hwmgr->fan_ctrl_is_in_default_mode)
-               return hwmgr->fan_ctrl_default_mode;
-       else
-               return PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
-                               CG_FDO_CTRL2, FDO_PWM_MODE);
+       return hwmgr->fan_ctrl_enabled ? AMD_FAN_CTRL_AUTO : AMD_FAN_CTRL_MANUAL;
 }
 
 static int smu7_get_sclk_od(struct pp_hwmgr *hwmgr)
index 436ca5ce82480d3957ff632f9976f13ab40bbdae..baddb569a8b8283881f8dc8f6d5d87e00927c8b2 100644 (file)
@@ -112,10 +112,9 @@ int smu7_fan_ctrl_get_fan_speed_rpm(struct pp_hwmgr *hwmgr, uint32_t *speed)
 */
 int smu7_fan_ctrl_set_static_mode(struct pp_hwmgr *hwmgr, uint32_t mode)
 {
-
        if (hwmgr->fan_ctrl_is_in_default_mode) {
                hwmgr->fan_ctrl_default_mode =
-                               PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device,     CGS_IND_REG__SMC,
+                               PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
                                                CG_FDO_CTRL2, FDO_PWM_MODE);
                hwmgr->tmin =
                                PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
@@ -149,7 +148,7 @@ int smu7_fan_ctrl_set_default_mode(struct pp_hwmgr *hwmgr)
        return 0;
 }
 
-static int smu7_fan_ctrl_start_smc_fan_control(struct pp_hwmgr *hwmgr)
+int smu7_fan_ctrl_start_smc_fan_control(struct pp_hwmgr *hwmgr)
 {
        int result;
 
@@ -179,6 +178,7 @@ static int smu7_fan_ctrl_start_smc_fan_control(struct pp_hwmgr *hwmgr)
                                PPSMC_MSG_SetFanTemperatureTarget,
                                hwmgr->thermal_controller.
                                advanceFanControlParameters.ucTargetTemperature);
+       hwmgr->fan_ctrl_enabled = true;
 
        return result;
 }
@@ -186,6 +186,7 @@ static int smu7_fan_ctrl_start_smc_fan_control(struct pp_hwmgr *hwmgr)
 
 int smu7_fan_ctrl_stop_smc_fan_control(struct pp_hwmgr *hwmgr)
 {
+       hwmgr->fan_ctrl_enabled = false;
        return smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_StopFanControl);
 }
 
@@ -280,7 +281,7 @@ int smu7_fan_ctrl_set_fan_speed_rpm(struct pp_hwmgr *hwmgr, uint32_t speed)
        PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
                                CG_TACH_STATUS, TACH_PERIOD, tach_period);
 
-       return smu7_fan_ctrl_set_static_mode(hwmgr, FDO_PWM_MODE_STATIC);
+       return smu7_fan_ctrl_set_static_mode(hwmgr, FDO_PWM_MODE_STATIC_RPM);
 }
 
 /**
index 2ed774db42c7b922f2b8ac77921a7bdb4b91ef7f..ba71b608fa752d5ac7b6ba4dd3d2b4fd7ce7cee9 100644 (file)
@@ -54,6 +54,6 @@ extern int smu7_fan_ctrl_get_fan_speed_rpm(struct pp_hwmgr *hwmgr, uint32_t *spe
 extern int smu7_fan_ctrl_stop_smc_fan_control(struct pp_hwmgr *hwmgr);
 extern int smu7_thermal_enable_alert(struct pp_hwmgr *hwmgr);
 extern int smu7_thermal_disable_alert(struct pp_hwmgr *hwmgr);
-
+extern int smu7_fan_ctrl_start_smc_fan_control(struct pp_hwmgr *hwmgr);
 #endif
 
index e4574c215c38ec41ede1b28c42306a845b9e4713..805b9df452a3dc828e138e01169b77e11c43297c 100644 (file)
@@ -764,6 +764,7 @@ struct pp_hwmgr {
        struct pp_thermal_controller_info thermal_controller;
        bool fan_ctrl_is_in_default_mode;
        uint32_t fan_ctrl_default_mode;
+       bool fan_ctrl_enabled;
        uint32_t tmin;
        struct phm_microcode_version_info microcode_version_info;
        uint32_t ps_size;