[PATCH 07/26] drm/amd/powerplay: implement pwm1_enable hwmon interface for SMU11
Alex Deucher
alexdeucher at gmail.com
Tue Feb 26 03:58:36 UTC 2019
On Mon, Feb 25, 2019 at 7:13 AM Huang Rui <ray.huang at amd.com> wrote:
>
> From: Chengming Gui <Jack.Gui at amd.com>
>
> 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 at amd.com>
> Reviewed-by: Huang Rui <ray.huang at amd.com>
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 31 +++++++++++++++++---------
> drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h | 3 +++
> drivers/gpu/drm/amd/powerplay/smu_v11_0.c | 31 ++++++++++++++++++++++++++
> 3 files changed, 55 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> index d40aa39..ac991f9 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> @@ -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 either clause has { }, both should. E.g.,
if () {
...
} else {
...
}
With that fixed:
Reviewed-by: Alex Deucher <alexander.deucher at amd.com>
> + 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;
> }
> diff --git a/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h b/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
> index f94d09d..ef2b807 100644
> --- a/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
> +++ b/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
> @@ -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) \
> diff --git a/drivers/gpu/drm/amd/powerplay/smu_v11_0.c b/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
> index d8917b2..aaa1bd8 100644
> --- a/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
> +++ b/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
> @@ -1833,6 +1833,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,
> @@ -1885,6 +1915,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,
> };
> --
> 2.7.4
>
> _______________________________________________
> amd-gfx mailing list
> amd-gfx at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
More information about the amd-gfx
mailing list