drm/amdgpu/pm: Fix the power source flag error
authorMa Jun <Jun.Ma2@amd.com>
Wed, 17 Jan 2024 06:35:29 +0000 (14:35 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Thu, 25 Jan 2024 20:41:06 +0000 (15:41 -0500)
The power source flag should be updated when
[1] System receives an interrupt indicating that the power source
has changed.
[2] System resumes from suspend or runtime suspend

Signed-off-by: Ma Jun <Jun.Ma2@amd.com>
Reviewed-by: Lijo Lazar <lijo.lazar@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Cc: stable@vger.kernel.org
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c
drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0.c

index c16703868e5ca2a3f0a7f6c7e3757b8e6ba036d0..a54663f2e2ab9f149463f12c200fef7c32fc37a6 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <linux/firmware.h>
 #include <linux/pci.h>
+#include <linux/power_supply.h>
 #include <linux/reboot.h>
 
 #include "amdgpu.h"
@@ -817,16 +818,8 @@ static int smu_late_init(void *handle)
         * handle the switch automatically. Driver involvement
         * is unnecessary.
         */
-       if (!smu->dc_controlled_by_gpio) {
-               ret = smu_set_power_source(smu,
-                                          adev->pm.ac_power ? SMU_POWER_SOURCE_AC :
-                                          SMU_POWER_SOURCE_DC);
-               if (ret) {
-                       dev_err(adev->dev, "Failed to switch to %s mode!\n",
-                               adev->pm.ac_power ? "AC" : "DC");
-                       return ret;
-               }
-       }
+       adev->pm.ac_power = power_supply_is_system_supplied() > 0;
+       smu_set_ac_dc(smu);
 
        if ((amdgpu_ip_version(adev, MP1_HWIP, 0) == IP_VERSION(13, 0, 1)) ||
            (amdgpu_ip_version(adev, MP1_HWIP, 0) == IP_VERSION(13, 0, 3)))
index 5a314d0316c1c8410d1f44281e5cc487e4947e81..c7bfa68bf00f400f3396c9853d2c08c6bf971659 100644 (file)
@@ -1442,10 +1442,12 @@ static int smu_v11_0_irq_process(struct amdgpu_device *adev,
                        case 0x3:
                                dev_dbg(adev->dev, "Switched to AC mode!\n");
                                schedule_work(&smu->interrupt_work);
+                               adev->pm.ac_power = true;
                                break;
                        case 0x4:
                                dev_dbg(adev->dev, "Switched to DC mode!\n");
                                schedule_work(&smu->interrupt_work);
+                               adev->pm.ac_power = false;
                                break;
                        case 0x7:
                                /*
index 771a3d457c335e2cc08582a3e4e3a3ba853d2928..c486182ff275222fedfaa1e27c417f9be80d19d0 100644 (file)
@@ -1379,10 +1379,12 @@ static int smu_v13_0_irq_process(struct amdgpu_device *adev,
                        case 0x3:
                                dev_dbg(adev->dev, "Switched to AC mode!\n");
                                smu_v13_0_ack_ac_dc_interrupt(smu);
+                               adev->pm.ac_power = true;
                                break;
                        case 0x4:
                                dev_dbg(adev->dev, "Switched to DC mode!\n");
                                smu_v13_0_ack_ac_dc_interrupt(smu);
+                               adev->pm.ac_power = false;
                                break;
                        case 0x7:
                                /*