drm/radeon/dpm: implement force performance level for cayman
authorAlex Deucher <alexander.deucher@amd.com>
Tue, 2 Jul 2013 22:43:53 +0000 (18:43 -0400)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 5 Jul 2013 22:09:38 +0000 (18:09 -0400)
Allows you to force a performance level via sysfs.

Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/radeon/ni_dpm.c
drivers/gpu/drm/radeon/radeon_asic.c
drivers/gpu/drm/radeon/radeon_asic.h

index a4cb99c2da8562ce5334395bd96df1c90406692b..bd96eaa3f01571b9ff291d62dfb6f2e9618d4ac4 100644 (file)
@@ -1037,13 +1037,37 @@ static int ni_restrict_performance_levels_before_switch(struct radeon_device *rd
                0 : -EINVAL;
 }
 
-static int ni_unrestrict_performance_levels_after_switch(struct radeon_device *rdev)
+int ni_dpm_force_performance_level(struct radeon_device *rdev,
+                                  enum radeon_dpm_forced_level level)
 {
-       if (ni_send_msg_to_smc_with_parameter(rdev, PPSMC_MSG_SetForcedLevels, 0) != PPSMC_Result_OK)
-               return -EINVAL;
+       struct radeon_ps *rps = rdev->pm.dpm.current_ps;
+       struct ni_ps *ps = ni_get_ps(rps);
+       u32 levels;
 
-       return (ni_send_msg_to_smc_with_parameter(rdev, PPSMC_MSG_SetEnabledLevels, 0) == PPSMC_Result_OK) ?
-               0 : -EINVAL;
+       if (level == RADEON_DPM_FORCED_LEVEL_HIGH) {
+               if (ni_send_msg_to_smc_with_parameter(rdev, PPSMC_MSG_SetEnabledLevels, 0) != PPSMC_Result_OK)
+                       return -EINVAL;
+
+               if (ni_send_msg_to_smc_with_parameter(rdev, PPSMC_MSG_SetForcedLevels, 1) != PPSMC_Result_OK)
+                       return -EINVAL;
+       } else if (level == RADEON_DPM_FORCED_LEVEL_LOW) {
+               if (ni_send_msg_to_smc_with_parameter(rdev, PPSMC_MSG_SetForcedLevels, 0) != PPSMC_Result_OK)
+                       return -EINVAL;
+
+               levels = ps->performance_level_count - 1;
+               if (ni_send_msg_to_smc_with_parameter(rdev, PPSMC_MSG_SetEnabledLevels, levels) != PPSMC_Result_OK)
+                       return -EINVAL;
+       } else if (level == RADEON_DPM_FORCED_LEVEL_AUTO) {
+               if (ni_send_msg_to_smc_with_parameter(rdev, PPSMC_MSG_SetForcedLevels, 0) != PPSMC_Result_OK)
+                       return -EINVAL;
+
+               if (ni_send_msg_to_smc_with_parameter(rdev, PPSMC_MSG_SetEnabledLevels, 0) != PPSMC_Result_OK)
+                       return -EINVAL;
+       }
+
+       rdev->pm.dpm.forced_level = level;
+
+       return 0;
 }
 
 static void ni_stop_smc(struct radeon_device *rdev)
@@ -3831,9 +3855,9 @@ int ni_dpm_set_power_state(struct radeon_device *rdev)
                return ret;
        }
 
-       ret = ni_unrestrict_performance_levels_after_switch(rdev);
+       ret = ni_dpm_force_performance_level(rdev, RADEON_DPM_FORCED_LEVEL_AUTO);
        if (ret) {
-               DRM_ERROR("ni_unrestrict_performance_levels_after_switch failed\n");
+               DRM_ERROR("ni_dpm_force_performance_level failed\n");
                return ret;
        }
 
index 221a0b31e649bd4a85d55aef97ec8e210fe592db..9c1b7b1c02683f58284870abd30626758ffffe83 100644 (file)
@@ -1940,6 +1940,7 @@ static struct radeon_asic cayman_asic = {
                .get_mclk = &ni_dpm_get_mclk,
                .print_power_state = &ni_dpm_print_power_state,
                .debugfs_print_current_performance_level = &ni_dpm_debugfs_print_current_performance_level,
+               .force_performance_level = &ni_dpm_force_performance_level,
        },
        .pflip = {
                .pre_page_flip = &evergreen_pre_page_flip,
index a053dc1e78662c09da49b5787dba3ad48b2104d4..2bacc777d549ccf7b70350a3fca58e337906f172 100644 (file)
@@ -617,6 +617,8 @@ void ni_dpm_print_power_state(struct radeon_device *rdev,
                              struct radeon_ps *ps);
 void ni_dpm_debugfs_print_current_performance_level(struct radeon_device *rdev,
                                                    struct seq_file *m);
+int ni_dpm_force_performance_level(struct radeon_device *rdev,
+                                  enum radeon_dpm_forced_level level);
 int trinity_dpm_init(struct radeon_device *rdev);
 int trinity_dpm_enable(struct radeon_device *rdev);
 void trinity_dpm_disable(struct radeon_device *rdev);