drm/amd/pm: add fan minimum pwm OD setting support for SMU13
authorEvan Quan <evan.quan@amd.com>
Fri, 11 Aug 2023 11:52:12 +0000 (19:52 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Thu, 31 Aug 2023 21:14:21 +0000 (17:14 -0400)
Add SMU13 fan minimum pwm OD setting support.

Signed-off-by: Evan Quan <evan.quan@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Documentation/gpu/amdgpu/thermal.rst
drivers/gpu/drm/amd/include/kgd_pp_interface.h
drivers/gpu/drm/amd/pm/amdgpu_pm.c
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
drivers/gpu/drm/amd/pm/swsmu/inc/smu_types.h
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c

index aa2d157..2f6166f 100644 (file)
@@ -88,6 +88,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
 ======
 
index 0501d17..5a889f7 100644 (file)
@@ -117,6 +117,7 @@ enum pp_clock_type {
        OD_ACOUSTIC_LIMIT,
        OD_ACOUSTIC_TARGET,
        OD_FAN_TARGET_TEMPERATURE,
+       OD_FAN_MINIMUM_PWM,
 };
 
 enum amd_pp_sensors {
@@ -195,6 +196,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 {
index 060a38e..84e1af6 100644 (file)
@@ -3745,6 +3745,62 @@ 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.
+ *
+ * This setting works under auto fan control mode only. It can co-exist with
+ * other settings which can work also under auto mode. It adjusts the PMFW's
+ * behavior about the minimum fan speed in PWM the fan should spin. Setting
+ * via this interface will switch the fan control to auto mode implicitly.
+ */
+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 = 0000;
+
+       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] = {
@@ -3782,6 +3838,14 @@ static struct od_feature_set amdgpu_od_set = {
                                                .store = fan_target_temperature_store,
                                        },
                                },
+                               [4] = {
+                                       .name = "fan_minimum_pwm",
+                                       .ops = {
+                                               .is_visible = fan_minimum_pwm_visible,
+                                               .show = fan_minimum_pwm_show,
+                                               .store = fan_minimum_pwm_store,
+                                       },
+                               },
                        },
                },
        },
index 4860366..5efdba6 100644 (file)
@@ -322,6 +322,8 @@ struct config_table_setting
 #define OD_OPS_SUPPORT_ACOUSTIC_TARGET_THRESHOLD_SET           BIT(5)
 #define OD_OPS_SUPPORT_FAN_TARGET_TEMPERATURE_RETRIEVE         BIT(6)
 #define OD_OPS_SUPPORT_FAN_TARGET_TEMPERATURE_SET              BIT(7)
+#define OD_OPS_SUPPORT_FAN_MINIMUM_PWM_RETRIEVE                BIT(8)
+#define OD_OPS_SUPPORT_FAN_MINIMUM_PWM_SET             BIT(9)
 
 struct amdgpu_pm {
        struct mutex            mutex;
index 60feffd..206e233 100644 (file)
@@ -2489,6 +2489,8 @@ static enum smu_clk_type smu_convert_to_smuclk(enum pp_clock_type type)
                clk_type = SMU_OD_ACOUSTIC_TARGET; break;
        case OD_FAN_TARGET_TEMPERATURE:
                clk_type = SMU_OD_FAN_TARGET_TEMPERATURE; break;
+       case OD_FAN_MINIMUM_PWM:
+               clk_type = SMU_OD_FAN_MINIMUM_PWM; break;
        default:
                clk_type = SMU_CLK_COUNT; break;
        }
index 5a129e7..ebc789e 100644 (file)
@@ -284,6 +284,7 @@ enum smu_clk_type {
        SMU_OD_ACOUSTIC_LIMIT,
        SMU_OD_ACOUSTIC_TARGET,
        SMU_OD_FAN_TARGET_TEMPERATURE,
+       SMU_OD_FAN_MINIMUM_PWM,
        SMU_CLK_COUNT,
 };
 
index b377aee..93fb562 100644 (file)
 #define PP_OD_FEATURE_FAN_ACOUSTIC_LIMIT               7
 #define PP_OD_FEATURE_FAN_ACOUSTIC_TARGET              8
 #define PP_OD_FEATURE_FAN_TARGET_TEMPERATURE           9
+#define PP_OD_FEATURE_FAN_MINIMUM_PWM                  10
 
 #define LINK_SPEED_MAX                                 3
 
@@ -1147,6 +1148,10 @@ static void smu_v13_0_0_get_od_setting_limits(struct smu_context *smu,
                od_min_setting = overdrive_lowerlimits->FanTargetTemperature;
                od_max_setting = overdrive_upperlimits->FanTargetTemperature;
                break;
+       case PP_OD_FEATURE_FAN_MINIMUM_PWM:
+               od_min_setting = overdrive_lowerlimits->FanMinimumPwm;
+               od_max_setting = overdrive_upperlimits->FanMinimumPwm;
+               break;
        default:
                od_min_setting = od_max_setting = INT_MAX;
                break;
@@ -1449,6 +1454,24 @@ static int smu_v13_0_0_print_clk_levels(struct smu_context *smu,
                                      min_value, max_value);
                break;
 
+       case SMU_OD_FAN_MINIMUM_PWM:
+               if (!smu_v13_0_0_is_od_feature_supported(smu,
+                                                        PP_OD_FEATURE_FAN_CURVE_BIT))
+                       break;
+
+               size += sysfs_emit_at(buf, size, "FAN_MINIMUM_PWM:\n");
+               size += sysfs_emit_at(buf, size, "%d\n",
+                                       (int)od_table->OverDriveTable.FanMinimumPwm);
+
+               size += sysfs_emit_at(buf, size, "%s:\n", "OD_RANGE");
+               smu_v13_0_0_get_od_setting_limits(smu,
+                                                 PP_OD_FEATURE_FAN_MINIMUM_PWM,
+                                                 &min_value,
+                                                 &max_value);
+               size += sysfs_emit_at(buf, size, "MINIMUM_PWM: %u %u\n",
+                                     min_value, max_value);
+               break;
+
        case SMU_OD_RANGE:
                if (!smu_v13_0_0_is_od_feature_supported(smu, PP_OD_FEATURE_GFXCLK_BIT) &&
                    !smu_v13_0_0_is_od_feature_supported(smu, PP_OD_FEATURE_UCLK_BIT) &&
@@ -1763,6 +1786,28 @@ static int smu_v13_0_0_od_edit_dpm_table(struct smu_context *smu,
                od_table->OverDriveTable.FeatureCtrlMask |= BIT(PP_OD_FEATURE_FAN_CURVE_BIT);
                break;
 
+       case PP_OD_EDIT_FAN_MINIMUM_PWM:
+               if (!smu_v13_0_0_is_od_feature_supported(smu, PP_OD_FEATURE_FAN_CURVE_BIT)) {
+                       dev_warn(adev->dev, "Fan curve setting not supported!\n");
+                       return -ENOTSUPP;
+               }
+
+               smu_v13_0_0_get_od_setting_limits(smu,
+                                                 PP_OD_FEATURE_FAN_MINIMUM_PWM,
+                                                 &minimum,
+                                                 &maximum);
+               if (input[0] < minimum ||
+                   input[0] > maximum) {
+                       dev_info(adev->dev, "fan minimum pwm setting(%ld) must be within [%d, %d]!\n",
+                                input[0], minimum, maximum);
+                       return -EINVAL;
+               }
+
+               od_table->OverDriveTable.FanMinimumPwm = input[0];
+               od_table->OverDriveTable.FanMode = FAN_MODE_AUTO;
+               od_table->OverDriveTable.FeatureCtrlMask |= BIT(PP_OD_FEATURE_FAN_CURVE_BIT);
+               break;
+
        case PP_OD_RESTORE_DEFAULT_TABLE:
                feature_ctrlmask = od_table->OverDriveTable.FeatureCtrlMask;
                memcpy(od_table,
@@ -2026,7 +2071,9 @@ static void smu_v13_0_0_set_supported_od_feature_mask(struct smu_context *smu)
                                            OD_OPS_SUPPORT_ACOUSTIC_TARGET_THRESHOLD_RETRIEVE |
                                            OD_OPS_SUPPORT_ACOUSTIC_TARGET_THRESHOLD_SET |
                                            OD_OPS_SUPPORT_FAN_TARGET_TEMPERATURE_RETRIEVE |
-                                           OD_OPS_SUPPORT_FAN_TARGET_TEMPERATURE_SET;
+                                           OD_OPS_SUPPORT_FAN_TARGET_TEMPERATURE_SET |
+                                           OD_OPS_SUPPORT_FAN_MINIMUM_PWM_RETRIEVE |
+                                           OD_OPS_SUPPORT_FAN_MINIMUM_PWM_SET;
 }
 
 static int smu_v13_0_0_set_default_od_settings(struct smu_context *smu)
@@ -2090,6 +2137,8 @@ static int smu_v13_0_0_set_default_od_settings(struct smu_context *smu)
                        user_od_table_bak.OverDriveTable.AcousticTargetRpmThreshold;
                user_od_table->OverDriveTable.FanTargetTemperature =
                        user_od_table_bak.OverDriveTable.FanTargetTemperature;
+               user_od_table->OverDriveTable.FanMinimumPwm =
+                       user_od_table_bak.OverDriveTable.FanMinimumPwm;
        }
 
        smu_v13_0_0_set_supported_od_feature_mask(smu);
index c12ff7c..99bc449 100644 (file)
@@ -82,6 +82,7 @@
 #define PP_OD_FEATURE_FAN_ACOUSTIC_LIMIT               7
 #define PP_OD_FEATURE_FAN_ACOUSTIC_TARGET              8
 #define PP_OD_FEATURE_FAN_TARGET_TEMPERATURE           9
+#define PP_OD_FEATURE_FAN_MINIMUM_PWM                  10
 
 #define LINK_SPEED_MAX                                 3
 
@@ -1127,6 +1128,10 @@ static void smu_v13_0_7_get_od_setting_limits(struct smu_context *smu,
                od_min_setting = overdrive_lowerlimits->FanTargetTemperature;
                od_max_setting = overdrive_upperlimits->FanTargetTemperature;
                break;
+       case PP_OD_FEATURE_FAN_MINIMUM_PWM:
+               od_min_setting = overdrive_lowerlimits->FanMinimumPwm;
+               od_max_setting = overdrive_upperlimits->FanMinimumPwm;
+               break;
        default:
                od_min_setting = od_max_setting = INT_MAX;
                break;
@@ -1429,6 +1434,24 @@ static int smu_v13_0_7_print_clk_levels(struct smu_context *smu,
                                      min_value, max_value);
                break;
 
+       case SMU_OD_FAN_MINIMUM_PWM:
+               if (!smu_v13_0_7_is_od_feature_supported(smu,
+                                                        PP_OD_FEATURE_FAN_CURVE_BIT))
+                       break;
+
+               size += sysfs_emit_at(buf, size, "FAN_MINIMUM_PWM:\n");
+               size += sysfs_emit_at(buf, size, "%d\n",
+                                       (int)od_table->OverDriveTable.FanMinimumPwm);
+
+               size += sysfs_emit_at(buf, size, "%s:\n", "OD_RANGE");
+               smu_v13_0_7_get_od_setting_limits(smu,
+                                                 PP_OD_FEATURE_FAN_MINIMUM_PWM,
+                                                 &min_value,
+                                                 &max_value);
+               size += sysfs_emit_at(buf, size, "MINIMUM_PWM: %u %u\n",
+                                     min_value, max_value);
+               break;
+
        case SMU_OD_RANGE:
                if (!smu_v13_0_7_is_od_feature_supported(smu, PP_OD_FEATURE_GFXCLK_BIT) &&
                    !smu_v13_0_7_is_od_feature_supported(smu, PP_OD_FEATURE_UCLK_BIT) &&
@@ -1743,6 +1766,28 @@ static int smu_v13_0_7_od_edit_dpm_table(struct smu_context *smu,
                od_table->OverDriveTable.FeatureCtrlMask |= BIT(PP_OD_FEATURE_FAN_CURVE_BIT);
                break;
 
+       case PP_OD_EDIT_FAN_MINIMUM_PWM:
+               if (!smu_v13_0_7_is_od_feature_supported(smu, PP_OD_FEATURE_FAN_CURVE_BIT)) {
+                       dev_warn(adev->dev, "Fan curve setting not supported!\n");
+                       return -ENOTSUPP;
+               }
+
+               smu_v13_0_7_get_od_setting_limits(smu,
+                                                 PP_OD_FEATURE_FAN_MINIMUM_PWM,
+                                                 &minimum,
+                                                 &maximum);
+               if (input[0] < minimum ||
+                   input[0] > maximum) {
+                       dev_info(adev->dev, "fan minimum pwm setting(%ld) must be within [%d, %d]!\n",
+                                input[0], minimum, maximum);
+                       return -EINVAL;
+               }
+
+               od_table->OverDriveTable.FanMinimumPwm = input[0];
+               od_table->OverDriveTable.FanMode = FAN_MODE_AUTO;
+               od_table->OverDriveTable.FeatureCtrlMask |= BIT(PP_OD_FEATURE_FAN_CURVE_BIT);
+               break;
+
        case PP_OD_RESTORE_DEFAULT_TABLE:
                feature_ctrlmask = od_table->OverDriveTable.FeatureCtrlMask;
                memcpy(od_table,
@@ -2001,7 +2046,9 @@ static void smu_v13_0_7_set_supported_od_feature_mask(struct smu_context *smu)
                                            OD_OPS_SUPPORT_ACOUSTIC_TARGET_THRESHOLD_RETRIEVE |
                                            OD_OPS_SUPPORT_ACOUSTIC_TARGET_THRESHOLD_SET |
                                            OD_OPS_SUPPORT_FAN_TARGET_TEMPERATURE_RETRIEVE |
-                                           OD_OPS_SUPPORT_FAN_TARGET_TEMPERATURE_SET;
+                                           OD_OPS_SUPPORT_FAN_TARGET_TEMPERATURE_SET |
+                                           OD_OPS_SUPPORT_FAN_MINIMUM_PWM_RETRIEVE |
+                                           OD_OPS_SUPPORT_FAN_MINIMUM_PWM_SET;
 }
 
 static int smu_v13_0_7_set_default_od_settings(struct smu_context *smu)
@@ -2065,6 +2112,8 @@ static int smu_v13_0_7_set_default_od_settings(struct smu_context *smu)
                        user_od_table_bak.OverDriveTable.AcousticTargetRpmThreshold;
                user_od_table->OverDriveTable.FanTargetTemperature =
                        user_od_table_bak.OverDriveTable.FanTargetTemperature;
+               user_od_table->OverDriveTable.FanMinimumPwm =
+                       user_od_table_bak.OverDriveTable.FanMinimumPwm;
        }
 
        smu_v13_0_7_set_supported_od_feature_mask(smu);