From 1b852dbd0052630a0541b0e79321924eab26a8aa Mon Sep 17 00:00:00 2001 From: Alex Deucher Date: Thu, 3 Oct 2013 10:08:20 -0400 Subject: [PATCH] drm/radeon: automatically switch between states on ac power events (v2) Some laptops require automatic switching to battery states when on DC power to avoid going over their power envelop. Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=70053 v2: enforce battery states when on battery power Signed-off-by: Alex Deucher --- drivers/gpu/drm/radeon/radeon_pm.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/radeon/radeon_pm.c b/drivers/gpu/drm/radeon/radeon_pm.c index 4f6b7fc..aa96646b 100644 --- a/drivers/gpu/drm/radeon/radeon_pm.c +++ b/drivers/gpu/drm/radeon/radeon_pm.c @@ -69,13 +69,17 @@ void radeon_pm_acpi_event_handler(struct radeon_device *rdev) { if ((rdev->pm.pm_method == PM_METHOD_DPM) && rdev->pm.dpm_enabled) { mutex_lock(&rdev->pm.mutex); - if (power_supply_is_system_supplied() > 0) + if (power_supply_is_system_supplied() > 0) { rdev->pm.dpm.ac_power = true; - else + rdev->pm.dpm.user_state = POWER_STATE_TYPE_BALANCED; + } else { rdev->pm.dpm.ac_power = false; + rdev->pm.dpm.user_state = POWER_STATE_TYPE_BATTERY; + } if (rdev->asic->dpm.enable_bapm) radeon_dpm_enable_bapm(rdev, rdev->pm.dpm.ac_power); mutex_unlock(&rdev->pm.mutex); + radeon_pm_compute_clocks(rdev); } else if (rdev->pm.pm_method == PM_METHOD_PROFILE) { if (rdev->pm.profile == PM_PROFILE_AUTO) { mutex_lock(&rdev->pm.mutex); @@ -832,8 +836,14 @@ static void radeon_dpm_change_power_state_locked(struct radeon_device *rdev) if (rdev->pm.dpm.user_state != rdev->pm.dpm.state) { /* add other state override checks here */ if ((!rdev->pm.dpm.thermal_active) && - (!rdev->pm.dpm.uvd_active)) - rdev->pm.dpm.state = rdev->pm.dpm.user_state; + (!rdev->pm.dpm.uvd_active)) { + /* force battery mode when on battery power */ + if (!rdev->pm.dpm.ac_power && + (rdev->pm.dpm.user_state != POWER_STATE_TYPE_BATTERY)) + rdev->pm.dpm.state = rdev->pm.dpm.user_state = POWER_STATE_TYPE_BATTERY; + else + rdev->pm.dpm.state = rdev->pm.dpm.user_state; + } } dpm_state = rdev->pm.dpm.state; -- 1.8.3.1