drm/amd/pm: restore user customized OD settings properly for Sienna Cichlid
authorEvan Quan <evan.quan@amd.com>
Wed, 21 Jul 2021 10:52:35 +0000 (18:52 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 28 Jul 2021 20:37:18 +0000 (16:37 -0400)
Properly restore those committed and non-committed user customized OD
settings.

Signed-off-by: Evan Quan <evan.quan@amd.com>
Reviewed-by: Lijo Lazar <lijo.lazar@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c

index 83d8e53ca1f888d111e00f6a0fb9ccd3969fe867..90e40aacb8f690c14402dcb86d91312f8b6940c3 100644 (file)
@@ -1954,18 +1954,29 @@ static int sienna_cichlid_set_default_od_settings(struct smu_context *smu)
                (OverDriveTable_t *)smu->smu_table.overdrive_table;
        OverDriveTable_t *boot_od_table =
                (OverDriveTable_t *)smu->smu_table.boot_overdrive_table;
+       OverDriveTable_t *user_od_table =
+               (OverDriveTable_t *)smu->smu_table.user_overdrive_table;
        int ret = 0;
 
+       /*
+        * For S3/S4/Runpm resume, no need to setup those overdrive tables again as
+        *   - either they already have the default OD settings got during cold bootup
+        *   - or they have some user customized OD settings which cannot be overwritten
+        */
+       if (smu->adev->in_suspend)
+               return 0;
+
        ret = smu_cmn_update_table(smu, SMU_TABLE_OVERDRIVE,
-                                  0, (void *)od_table, false);
+                                  0, (void *)boot_od_table, false);
        if (ret) {
                dev_err(smu->adev->dev, "Failed to get overdrive table!\n");
                return ret;
        }
 
-       memcpy(boot_od_table, od_table, sizeof(OverDriveTable_t));
+       sienna_cichlid_dump_od_table(smu, boot_od_table);
 
-       sienna_cichlid_dump_od_table(smu, od_table);
+       memcpy(od_table, boot_od_table, sizeof(OverDriveTable_t));
+       memcpy(user_od_table, boot_od_table, sizeof(OverDriveTable_t));
 
        return 0;
 }
@@ -2128,13 +2139,20 @@ static int sienna_cichlid_od_edit_dpm_table(struct smu_context *smu,
                fallthrough;
 
        case PP_OD_COMMIT_DPM_TABLE:
-               sienna_cichlid_dump_od_table(smu, od_table);
+               if (memcmp(od_table, table_context->user_overdrive_table, sizeof(OverDriveTable_t))) {
+                       sienna_cichlid_dump_od_table(smu, od_table);
+                       ret = smu_cmn_update_table(smu, SMU_TABLE_OVERDRIVE, 0, (void *)od_table, true);
+                       if (ret) {
+                               dev_err(smu->adev->dev, "Failed to import overdrive table!\n");
+                               return ret;
+                       }
+                       memcpy(table_context->user_overdrive_table, od_table, sizeof(OverDriveTable_t));
+                       smu->user_dpm_profile.user_od = true;
 
-               ret = smu_cmn_update_table(smu, SMU_TABLE_OVERDRIVE,
-                                          0, (void *)od_table, true);
-               if (ret) {
-                       dev_err(smu->adev->dev, "Failed to import overdrive table!\n");
-                       return ret;
+                       if (!memcmp(table_context->user_overdrive_table,
+                                   table_context->boot_overdrive_table,
+                                   sizeof(OverDriveTable_t)))
+                               smu->user_dpm_profile.user_od = false;
                }
                break;
 
@@ -3902,6 +3920,7 @@ static const struct pptable_funcs sienna_cichlid_ppt_funcs = {
        .set_soft_freq_limited_range = smu_v11_0_set_soft_freq_limited_range,
        .set_default_od_settings = sienna_cichlid_set_default_od_settings,
        .od_edit_dpm_table = sienna_cichlid_od_edit_dpm_table,
+       .restore_user_od_settings = smu_v11_0_restore_user_od_settings,
        .run_btc = sienna_cichlid_run_btc,
        .set_power_source = smu_v11_0_set_power_source,
        .get_pp_feature_mask = smu_cmn_get_pp_feature_mask,