drm/amd/powerplay: implement pwm1_enable hwmon interface for SMU11 (v2)
authorChengming Gui <Jack.Gui@amd.com>
Fri, 25 Jan 2019 08:21:27 +0000 (16:21 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Tue, 19 Mar 2019 20:04:01 +0000 (15:04 -0500)
1, set get_pwm1_enable and set_pwm1_enable functions to call
smu_get_fan_control_mode and smu_set_fan_control_mode for SMU11
2, implement set_fan_control_mode function

v2: add return value in set_fan_control_mode function

Signed-off-by: Chengming Gui <Jack.Gui@amd.com>
Reviewed-by: Huang Rui <ray.huang@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
drivers/gpu/drm/amd/powerplay/smu_v11_0.c

index 284d28acb8c10f094e9d48a49a1c734f83c1bc6a..b1e6e67d5c2f5b9c79cea7348a0a999e4cc43b79 100644 (file)
@@ -1382,11 +1382,14 @@ static ssize_t amdgpu_hwmon_get_pwm1_enable(struct device *dev,
 {
        struct amdgpu_device *adev = dev_get_drvdata(dev);
        u32 pwm_mode = 0;
+       if (is_support_sw_smu(adev)) {
+               pwm_mode = smu_get_fan_control_mode(&adev->smu);
+       } else {
+               if (!adev->powerplay.pp_funcs->get_fan_control_mode)
+                       return -EINVAL;
 
-       if (!adev->powerplay.pp_funcs->get_fan_control_mode)
-               return -EINVAL;
-
-       pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
+               pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
+       }
 
        return sprintf(buf, "%i\n", pwm_mode);
 }
@@ -1405,14 +1408,22 @@ static ssize_t amdgpu_hwmon_set_pwm1_enable(struct device *dev,
             (adev->ddev->switch_power_state != DRM_SWITCH_POWER_ON))
                return -EINVAL;
 
-       if (!adev->powerplay.pp_funcs->set_fan_control_mode)
-               return -EINVAL;
+       if (is_support_sw_smu(adev)) {
+               err = kstrtoint(buf, 10, &value);
+               if (err)
+                       return err;
 
-       err = kstrtoint(buf, 10, &value);
-       if (err)
-               return err;
+               smu_set_fan_control_mode(&adev->smu, value);
+       } else {
+               if (!adev->powerplay.pp_funcs->set_fan_control_mode)
+                       return -EINVAL;
+
+               err = kstrtoint(buf, 10, &value);
+               if (err)
+                       return err;
 
-       amdgpu_dpm_set_fan_control_mode(adev, value);
+               amdgpu_dpm_set_fan_control_mode(adev, value);
+       }
 
        return count;
 }
index f94d09db9305d92076a329191d8376da1a0ced0f..ef2b80749b878146407e43a8f28861f1b58bb1f8 100644 (file)
@@ -533,6 +533,7 @@ struct smu_funcs
        uint32_t (*get_mclk)(struct smu_context *smu, bool low);
        int (*get_current_rpm)(struct smu_context *smu, uint32_t *speed);
        uint32_t (*get_fan_control_mode)(struct smu_context *smu);
+       int (*set_fan_control_mode)(struct smu_context *smu, uint32_t mode);
        int (*get_fan_speed_percent)(struct smu_context *smu, uint32_t *speed);
        int (*set_fan_speed_percent)(struct smu_context *smu, uint32_t speed);
 };
@@ -669,6 +670,8 @@ struct smu_funcs
        ((smu)->ppt_funcs->set_cpu_power_state ? (smu)->ppt_funcs->set_cpu_power_state((smu)) : 0)
 #define smu_get_fan_control_mode(smu) \
        ((smu)->funcs->get_fan_control_mode ? (smu)->funcs->get_fan_control_mode((smu)) : 0)
+#define smu_set_fan_control_mode(smu, value) \
+       ((smu)->funcs->set_fan_control_mode ? (smu)->funcs->set_fan_control_mode((smu), (value)) : 0)
 #define smu_get_fan_speed_percent(smu, speed) \
        ((smu)->funcs->get_fan_speed_percent ? (smu)->funcs->get_fan_speed_percent((smu), (speed)) : 0)
 #define smu_set_fan_speed_percent(smu, speed) \
index 2eb5ad813ec8038b17811d6612be752bdf3e8983..75f42bc621c1348c8df7a5333cfff6e7a18a9550 100644 (file)
@@ -1834,6 +1834,36 @@ smu_v11_0_set_fan_speed_percent(struct smu_context *smu, uint32_t speed)
        return smu_v11_0_set_fan_static_mode(smu, FDO_PWM_MODE_STATIC);
 }
 
+static int
+smu_v11_0_set_fan_control_mode(struct smu_context *smu,
+                              uint32_t mode)
+{
+       int ret = 0;
+       bool start = 1;
+       bool stop  = 0;
+
+       switch (mode) {
+       case AMD_FAN_CTRL_NONE:
+               ret = smu_v11_0_set_fan_speed_percent(smu, 100);
+               break;
+       case AMD_FAN_CTRL_MANUAL:
+               ret = smu_v11_0_smc_fan_control(smu, stop);
+               break;
+       case AMD_FAN_CTRL_AUTO:
+               ret = smu_v11_0_smc_fan_control(smu, start);
+               break;
+       default:
+               break;
+       }
+
+       if (ret) {
+               pr_err("[%s]Set fan control mode failed!");
+               return -EINVAL;
+       }
+
+       return ret;
+}
+
 static const struct smu_funcs smu_v11_0_funcs = {
        .init_microcode = smu_v11_0_init_microcode,
        .load_microcode = smu_v11_0_load_microcode,
@@ -1886,6 +1916,7 @@ static const struct smu_funcs smu_v11_0_funcs = {
        .dpm_set_vce_enable = smu_v11_0_dpm_set_vce_enable,
        .get_current_rpm = smu_v11_0_get_current_rpm,
        .get_fan_control_mode = smu_v11_0_get_fan_control_mode,
+       .set_fan_control_mode = smu_v11_0_set_fan_control_mode,
        .get_fan_speed_percent = smu_v11_0_get_fan_speed_percent,
        .set_fan_speed_percent = smu_v11_0_set_fan_speed_percent,
 };