From: Jeremy Klarenbeek <[email protected]>

There are some platforms that don't have a dedicated
GPIO line to manage the AC/DC switch. In this case,
the SI SMC automatically notices when switching to DC,
but needs to be notified when switching to AC.

Fixup and use si_notify_hw_of_powersource() which was
previously hidden behind an "#if 0".

This fixes some SI laptop GPUs to be able to use their
performance power states after switching from DC to AC.

Some affected GPUs are:
FirePro W4170M - Dell Precision M2800
Radeon HD 8790M - Dell Latitude E6540

Co-developed-by: Timur Kristóf <[email protected]>
Signed-off-by: Timur Kristóf <[email protected]>
Signed-off-by: Jeremy Klarenbeek <[email protected]>
---
 drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c 
b/drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c
index 04f3ba5f8f46..832953941266 100644
--- a/drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c
+++ b/drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c
@@ -3888,16 +3888,18 @@ static void 
si_notify_hardware_vpu_recovery_event(struct amdgpu_device *adev)
 }
 #endif
 
-#if 0
-static int si_notify_hw_of_powersource(struct amdgpu_device *adev, bool 
ac_power)
+static void si_notify_hw_of_powersource(void *handle)
 {
-       if (ac_power)
-               return (amdgpu_si_send_msg_to_smc(adev, PPSMC_MSG_RunningOnAC) 
== PPSMC_Result_OK) ?
-                       0 : -EINVAL;
+       struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 
-       return 0;
+       /* Check if the platform already manages the AC/DC switch via dedicated 
GPIO. */
+       if (adev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_HARDWAREDC)
+               return;
+
+       /* The SMU automatically notices DC, but needs to be notified when 
switching to AC. */
+       if (adev->pm.ac_power)
+               amdgpu_si_send_msg_to_smc(adev, PPSMC_MSG_RunningOnAC);
 }
-#endif
 
 static PPSMC_Result si_send_msg_to_smc_with_parameter(struct amdgpu_device 
*adev,
                                                      PPSMC_Msg msg, u32 
parameter)
@@ -8166,6 +8168,7 @@ static const struct amd_pm_funcs si_dpm_funcs = {
        .get_vce_clock_state = amdgpu_get_vce_clock_state,
        .read_sensor = &si_dpm_read_sensor,
        .pm_compute_clocks = amdgpu_legacy_dpm_compute_clocks,
+       .notify_ac_dc = si_notify_hw_of_powersource,
 };
 
 static const struct amdgpu_irq_src_funcs si_dpm_irq_funcs = {
-- 
2.54.0

Reply via email to