[PATCH 2/2] drm/amd/amdgpu: expose fan rpm though hwmon

Alex Deucher alexdeucher at gmail.com
Mon Oct 31 18:06:54 UTC 2016


On Sat, Oct 29, 2016 at 4:28 PM, Grazvydas Ignotas <notasas at gmail.com> wrote:
> Only for cards that are supported by powerplay.
>
> Signed-off-by: Grazvydas Ignotas <notasas at gmail.com>

Applied the series.  Thanks!

Alex

> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h |  5 +++++
>  drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c  | 21 +++++++++++++++++++++
>  2 files changed, 26 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h
> index bd85e35..e45bd05 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h
> @@ -317,6 +317,11 @@ struct amdgpu_dpm_funcs {
>               (adev)->powerplay.pp_funcs->get_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \
>               (adev)->pm.funcs->get_fan_speed_percent((adev), (s)))
>
> +#define amdgpu_dpm_get_fan_speed_rpm(adev, s) \
> +       ((adev)->pp_enabled ?                                           \
> +             (adev)->powerplay.pp_funcs->get_fan_speed_rpm((adev)->powerplay.pp_handle, (s)) : \
> +             -EINVAL)
> +
>  #define amdgpu_dpm_get_sclk(adev, l) \
>         ((adev)->pp_enabled ?                                           \
>               (adev)->powerplay.pp_funcs->get_sclk((adev)->powerplay.pp_handle, (l)) : \
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> index 274f330..723ae68 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
> @@ -737,6 +737,21 @@ static ssize_t amdgpu_hwmon_get_pwm1(struct device *dev,
>         return sprintf(buf, "%i\n", speed);
>  }
>
> +static ssize_t amdgpu_hwmon_get_fan1_input(struct device *dev,
> +                                          struct device_attribute *attr,
> +                                          char *buf)
> +{
> +       struct amdgpu_device *adev = dev_get_drvdata(dev);
> +       int err;
> +       u32 speed;
> +
> +       err = amdgpu_dpm_get_fan_speed_rpm(adev, &speed);
> +       if (err)
> +               return err;
> +
> +       return sprintf(buf, "%i\n", speed);
> +}
> +
>  static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, amdgpu_hwmon_show_temp, NULL, 0);
>  static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO, amdgpu_hwmon_show_temp_thresh, NULL, 0);
>  static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IRUGO, amdgpu_hwmon_show_temp_thresh, NULL, 1);
> @@ -744,6 +759,7 @@ static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_pwm1, amdgpu
>  static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_pwm1_enable, amdgpu_hwmon_set_pwm1_enable, 0);
>  static SENSOR_DEVICE_ATTR(pwm1_min, S_IRUGO, amdgpu_hwmon_get_pwm1_min, NULL, 0);
>  static SENSOR_DEVICE_ATTR(pwm1_max, S_IRUGO, amdgpu_hwmon_get_pwm1_max, NULL, 0);
> +static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, amdgpu_hwmon_get_fan1_input, NULL, 0);
>
>  static struct attribute *hwmon_attributes[] = {
>         &sensor_dev_attr_temp1_input.dev_attr.attr,
> @@ -753,6 +769,7 @@ static struct attribute *hwmon_attributes[] = {
>         &sensor_dev_attr_pwm1_enable.dev_attr.attr,
>         &sensor_dev_attr_pwm1_min.dev_attr.attr,
>         &sensor_dev_attr_pwm1_max.dev_attr.attr,
> +       &sensor_dev_attr_fan1_input.dev_attr.attr,
>         NULL
>  };
>
> @@ -804,6 +821,10 @@ static umode_t hwmon_attributes_visible(struct kobject *kobj,
>              attr == &sensor_dev_attr_pwm1_min.dev_attr.attr))
>                 return 0;
>
> +       /* requires powerplay */
> +       if (attr == &sensor_dev_attr_fan1_input.dev_attr.attr)
> +               return 0;
> +
>         return effective_mode;
>  }
>
> --
> 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