Re: [V2 8/8] drm/amd/pm: add fan minimum pwm OD setting support for SMU13

2023-08-23 Thread Alex Deucher
Are there any restrictions on which fan control options you can
enable?  I.e., can you mess with all of these or are there several
discrete fan modes (acoustic, curve, min fan, etc.) that you have to
set up independently?  We should document the restrictions.

Alex

On Wed, Aug 23, 2023 at 2:45 AM Evan Quan  wrote:
>
> Add SMU13 fan minimum pwm OD setting support.
>
> Signed-off-by: Evan Quan 
> --
> v1->v2:
>   - add missing kerneldoc for the new interface(Alex)
> ---
>  Documentation/gpu/amdgpu/thermal.rst  |  6 ++
>  .../gpu/drm/amd/include/kgd_pp_interface.h|  2 +
>  drivers/gpu/drm/amd/pm/amdgpu_pm.c| 59 +++
>  drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h   |  2 +
>  drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c |  2 +
>  drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h  |  1 +
>  .../drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c  | 51 +++-
>  .../drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c  | 51 +++-
>  8 files changed, 172 insertions(+), 2 deletions(-)
>
> diff --git a/Documentation/gpu/amdgpu/thermal.rst 
> b/Documentation/gpu/amdgpu/thermal.rst
> index 073ab9e418b1..940f723472b8 100644
> --- a/Documentation/gpu/amdgpu/thermal.rst
> +++ b/Documentation/gpu/amdgpu/thermal.rst
> @@ -94,6 +94,12 @@ fan_target_temperature
>  .. kernel-doc:: drivers/gpu/drm/amd/pm/amdgpu_pm.c
> :doc: fan_target_temperature
>
> +fan_minimum_pwm
> +---
> +
> +.. kernel-doc:: drivers/gpu/drm/amd/pm/amdgpu_pm.c
> +   :doc: fan_minimum_pwm
> +
>  GFXOFF
>  ==
>
> diff --git a/drivers/gpu/drm/amd/include/kgd_pp_interface.h 
> b/drivers/gpu/drm/amd/include/kgd_pp_interface.h
> index c1065136f527..528c892f7c4b 100644
> --- a/drivers/gpu/drm/amd/include/kgd_pp_interface.h
> +++ b/drivers/gpu/drm/amd/include/kgd_pp_interface.h
> @@ -118,6 +118,7 @@ enum pp_clock_type {
> OD_ACOUSTIC_LIMIT,
> OD_ACOUSTIC_TARGET,
> OD_FAN_TARGET_TEMPERATURE,
> +   OD_FAN_MINIMUM_PWM,
>  };
>
>  enum amd_pp_sensors {
> @@ -197,6 +198,7 @@ enum PP_OD_DPM_TABLE_COMMAND {
> PP_OD_EDIT_ACOUSTIC_LIMIT,
> PP_OD_EDIT_ACOUSTIC_TARGET,
> PP_OD_EDIT_FAN_TARGET_TEMPERATURE,
> +   PP_OD_EDIT_FAN_MINIMUM_PWM,
>  };
>
>  struct pp_states_info {
> diff --git a/drivers/gpu/drm/amd/pm/amdgpu_pm.c 
> b/drivers/gpu/drm/amd/pm/amdgpu_pm.c
> index 682eef0c0eeb..fa6c4ab16ccf 100644
> --- a/drivers/gpu/drm/amd/pm/amdgpu_pm.c
> +++ b/drivers/gpu/drm/amd/pm/amdgpu_pm.c
> @@ -3772,6 +3772,57 @@ static umode_t fan_target_temperature_visible(struct 
> amdgpu_device *adev)
> return umode;
>  }
>
> +/**
> + * DOC: fan_minimum_pwm
> + *
> + * The amdgpu driver provides a sysfs API for checking and adjusting the
> + * minimum fan speed in PWM.
> + *
> + * Reading back the file shows you the current setting and the permitted
> + * ranges if changable.
> + *
> + * Writing an integer to the file, change the setting accordingly.
> + *
> + * When you have finished the editing, write "c" (commit) to the file to 
> commit
> + * your changes. NOTE: this will switch the fan control to auto mode.
> + */
> +static ssize_t fan_minimum_pwm_show(struct kobject *kobj,
> +   struct kobj_attribute *attr,
> +   char *buf)
> +{
> +   struct od_kobj *container = container_of(kobj, struct od_kobj, kobj);
> +   struct amdgpu_device *adev = (struct amdgpu_device *)container->priv;
> +
> +   return (ssize_t)amdgpu_retrieve_od_settings(adev, OD_FAN_MINIMUM_PWM, 
> buf);
> +}
> +
> +static ssize_t fan_minimum_pwm_store(struct kobject *kobj,
> +struct kobj_attribute *attr,
> +const char *buf,
> +size_t count)
> +{
> +   struct od_kobj *container = container_of(kobj, struct od_kobj, kobj);
> +   struct amdgpu_device *adev = (struct amdgpu_device *)container->priv;
> +
> +   return (ssize_t)amdgpu_distribute_custom_od_settings(adev,
> +
> PP_OD_EDIT_FAN_MINIMUM_PWM,
> +buf,
> +count);
> +}
> +
> +static umode_t fan_minimum_pwm_visible(struct amdgpu_device *adev)
> +{
> +   umode_t umode = ;
> +
> +   if (adev->pm.od_feature_mask & 
> OD_OPS_SUPPORT_FAN_MINIMUM_PWM_RETRIEVE)
> +   umode |= S_IRUSR | S_IRGRP | S_IROTH;
> +
> +   if (adev->pm.od_feature_mask & OD_OPS_SUPPORT_FAN_MINIMUM_PWM_SET)
> +   umode |= S_IWUSR;
> +
> +   return umode;
> +}
> +
>  static struct od_feature_set amdgpu_od_set = {
> .containers = {
> [0] = {
> @@ -3817,6 +3868,14 @@ static struct od_feature_set amdgpu_od_set = {
> .store = 
> fan_target_temperature_store,
> },
>  

[V2 8/8] drm/amd/pm: add fan minimum pwm OD setting support for SMU13

2023-08-23 Thread Evan Quan
Add SMU13 fan minimum pwm OD setting support.

Signed-off-by: Evan Quan 
--
v1->v2:
  - add missing kerneldoc for the new interface(Alex)
---
 Documentation/gpu/amdgpu/thermal.rst  |  6 ++
 .../gpu/drm/amd/include/kgd_pp_interface.h|  2 +
 drivers/gpu/drm/amd/pm/amdgpu_pm.c| 59 +++
 drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h   |  2 +
 drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c |  2 +
 drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h  |  1 +
 .../drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c  | 51 +++-
 .../drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c  | 51 +++-
 8 files changed, 172 insertions(+), 2 deletions(-)

diff --git a/Documentation/gpu/amdgpu/thermal.rst 
b/Documentation/gpu/amdgpu/thermal.rst
index 073ab9e418b1..940f723472b8 100644
--- a/Documentation/gpu/amdgpu/thermal.rst
+++ b/Documentation/gpu/amdgpu/thermal.rst
@@ -94,6 +94,12 @@ fan_target_temperature
 .. kernel-doc:: drivers/gpu/drm/amd/pm/amdgpu_pm.c
:doc: fan_target_temperature
 
+fan_minimum_pwm
+---
+
+.. kernel-doc:: drivers/gpu/drm/amd/pm/amdgpu_pm.c
+   :doc: fan_minimum_pwm
+
 GFXOFF
 ==
 
diff --git a/drivers/gpu/drm/amd/include/kgd_pp_interface.h 
b/drivers/gpu/drm/amd/include/kgd_pp_interface.h
index c1065136f527..528c892f7c4b 100644
--- a/drivers/gpu/drm/amd/include/kgd_pp_interface.h
+++ b/drivers/gpu/drm/amd/include/kgd_pp_interface.h
@@ -118,6 +118,7 @@ enum pp_clock_type {
OD_ACOUSTIC_LIMIT,
OD_ACOUSTIC_TARGET,
OD_FAN_TARGET_TEMPERATURE,
+   OD_FAN_MINIMUM_PWM,
 };
 
 enum amd_pp_sensors {
@@ -197,6 +198,7 @@ enum PP_OD_DPM_TABLE_COMMAND {
PP_OD_EDIT_ACOUSTIC_LIMIT,
PP_OD_EDIT_ACOUSTIC_TARGET,
PP_OD_EDIT_FAN_TARGET_TEMPERATURE,
+   PP_OD_EDIT_FAN_MINIMUM_PWM,
 };
 
 struct pp_states_info {
diff --git a/drivers/gpu/drm/amd/pm/amdgpu_pm.c 
b/drivers/gpu/drm/amd/pm/amdgpu_pm.c
index 682eef0c0eeb..fa6c4ab16ccf 100644
--- a/drivers/gpu/drm/amd/pm/amdgpu_pm.c
+++ b/drivers/gpu/drm/amd/pm/amdgpu_pm.c
@@ -3772,6 +3772,57 @@ static umode_t fan_target_temperature_visible(struct 
amdgpu_device *adev)
return umode;
 }
 
+/**
+ * DOC: fan_minimum_pwm
+ *
+ * The amdgpu driver provides a sysfs API for checking and adjusting the
+ * minimum fan speed in PWM.
+ *
+ * Reading back the file shows you the current setting and the permitted
+ * ranges if changable.
+ *
+ * Writing an integer to the file, change the setting accordingly.
+ *
+ * When you have finished the editing, write "c" (commit) to the file to commit
+ * your changes. NOTE: this will switch the fan control to auto mode.
+ */
+static ssize_t fan_minimum_pwm_show(struct kobject *kobj,
+   struct kobj_attribute *attr,
+   char *buf)
+{
+   struct od_kobj *container = container_of(kobj, struct od_kobj, kobj);
+   struct amdgpu_device *adev = (struct amdgpu_device *)container->priv;
+
+   return (ssize_t)amdgpu_retrieve_od_settings(adev, OD_FAN_MINIMUM_PWM, 
buf);
+}
+
+static ssize_t fan_minimum_pwm_store(struct kobject *kobj,
+struct kobj_attribute *attr,
+const char *buf,
+size_t count)
+{
+   struct od_kobj *container = container_of(kobj, struct od_kobj, kobj);
+   struct amdgpu_device *adev = (struct amdgpu_device *)container->priv;
+
+   return (ssize_t)amdgpu_distribute_custom_od_settings(adev,
+
PP_OD_EDIT_FAN_MINIMUM_PWM,
+buf,
+count);
+}
+
+static umode_t fan_minimum_pwm_visible(struct amdgpu_device *adev)
+{
+   umode_t umode = ;
+
+   if (adev->pm.od_feature_mask & OD_OPS_SUPPORT_FAN_MINIMUM_PWM_RETRIEVE)
+   umode |= S_IRUSR | S_IRGRP | S_IROTH;
+
+   if (adev->pm.od_feature_mask & OD_OPS_SUPPORT_FAN_MINIMUM_PWM_SET)
+   umode |= S_IWUSR;
+
+   return umode;
+}
+
 static struct od_feature_set amdgpu_od_set = {
.containers = {
[0] = {
@@ -3817,6 +3868,14 @@ static struct od_feature_set amdgpu_od_set = {
.store = 
fan_target_temperature_store,
},
},
+   [5] = {
+   .name = "fan_minimum_pwm",
+   .ops = {
+   .is_visible = 
fan_minimum_pwm_visible,
+   .show = fan_minimum_pwm_show,
+   .store = fan_minimum_pwm_store,
+   },
+   },
},
},
},