public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
From: Mario Limonciello <superm1@kernel.org>
To: "Rafael J . Wysocki" <rafael@kernel.org>
Cc: Len Brown <lenb@kernel.org>, Pavel Machek <pavel@ucw.cz>,
	linux-acpi@vger.kernel.org (open list:ACPI),
	linux-pm@vger.kernel.org (open list:HIBERNATION (aka Software
	Suspend, aka swsusp)),
	Mario Limonciello <mario.limonciello@amd.com>
Subject: [PATCH 4/4] ACPI: battery: Wake system on AC plug or unplug in over s2idle
Date: Sat,  8 Feb 2025 10:22:10 -0600	[thread overview]
Message-ID: <20250208162210.3929473-5-superm1@kernel.org> (raw)
In-Reply-To: <20250208162210.3929473-1-superm1@kernel.org>

From: Mario Limonciello <mario.limonciello@amd.com>

On Windows the OS will wake up when plugged or unplugged from AC adapter.
Depending upon whether the system was plugged in or unplugged will
determine whether the "display turns on".  If there is no user activity
for some time then it goes back to sleep.

In Linux plugging or unplugging an adapter will wake the SoC from HW
sleep but then the Linux kernel puts it right back into HW sleep
immediately unless there is another interrupt active (such as a PME or
GPIO).

To get closer to the Windows behavior, record the state of the battery
when going into suspend and compare it when updating battery status
during the s2idle loop. If it's changed, wake the system.

This can be restored to previous behavior by disabling the ACPI battery
device `power/wakeup` sysfs file.

Link: https://learn.microsoft.com/en-us/windows-hardware/design/device-experiences/modern-standby-wake-sources#environmental-context-changes-1
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
 drivers/acpi/battery.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 72c8a509695e6..91f79927cc720 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -125,6 +125,7 @@ struct acpi_battery {
 	int state;
 	int power_unit;
 	int capacity_suspend;
+	int suspend_state;
 	unsigned long flags;
 };
 
@@ -1012,6 +1013,12 @@ static inline bool acpi_battery_should_wake(struct acpi_battery *battery)
 		return true;
 	}
 
+	if (battery->state != battery->suspend_state) {
+		pm_pr_dbg("Waking due to battery state changed from 0x%x to 0x%x",
+			  battery->suspend_state, battery->state);
+		return true;
+	}
+
 	return false;
 }
 
@@ -1313,6 +1320,7 @@ static int acpi_battery_suspend(struct device *dev)
 		return -EINVAL;
 
 	battery->capacity_suspend = battery->capacity_now;
+	battery->suspend_state = battery->state;
 
 	return 0;
 }
-- 
2.43.0


  parent reply	other threads:[~2025-02-08 16:22 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-08 16:22 [PATCH 0/4] Improvements to ACPI battery handling over s2idle Mario Limonciello
2025-02-08 16:22 ` [PATCH 1/4] PM: Add sysfs file for energy consumed over sleep cycle Mario Limonciello
2025-02-08 16:22 ` [PATCH 2/4] ACPI: battery: Save and report battery capacity over suspend Mario Limonciello
2025-02-10 15:23   ` Sebastian Reichel
2025-02-10 21:24     ` Mario Limonciello
2025-02-08 16:22 ` [PATCH 3/4] ACPI: battery: Refactor wakeup reasons in acpi_battery_update() Mario Limonciello
2025-02-08 16:22 ` Mario Limonciello [this message]
2025-02-08 17:59   ` [PATCH 4/4] ACPI: battery: Wake system on AC plug or unplug in over s2idle Rafael J. Wysocki
2025-02-09 13:14     ` Mario Limonciello
2025-02-12 13:49       ` Armin Wolf
2025-02-12 13:57         ` Rafael J. Wysocki
  -- strict thread matches above, loose matches on Subject: below --
2025-02-10 14:43 K G

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250208162210.3929473-5-superm1@kernel.org \
    --to=superm1@kernel.org \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mario.limonciello@amd.com \
    --cc=pavel@ucw.cz \
    --cc=rafael@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox