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 3/4] ACPI: battery: Refactor wakeup reasons in acpi_battery_update()
Date: Sat,  8 Feb 2025 10:22:09 -0600	[thread overview]
Message-ID: <20250208162210.3929473-4-superm1@kernel.org> (raw)
In-Reply-To: <20250208162210.3929473-1-superm1@kernel.org>

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

Another reason to wake is to be introduced, so refactor the code
to make it easier to follow. Also introduce PM debug messages so
that it's more obvious when these wake events have occurred.

Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
 drivers/acpi/battery.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index f21bfd02a26d1..72c8a509695e6 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -999,6 +999,22 @@ static void acpi_battery_quirks(struct acpi_battery *battery)
 	}
 }
 
+static inline bool acpi_battery_should_wake(struct acpi_battery *battery)
+{
+	if (battery->state & ACPI_BATTERY_STATE_CRITICAL) {
+		pm_pr_dbg("Waking due critical battery level");
+		return true;
+	}
+
+	if (test_bit(ACPI_BATTERY_ALARM_PRESENT, &battery->flags) &&
+	    battery->capacity_now <= battery->alarm) {
+		pm_pr_dbg("Waking due to battery alarm");
+		return true;
+	}
+
+	return false;
+}
+
 static int acpi_battery_update(struct acpi_battery *battery, bool resume)
 {
 	int result = acpi_battery_get_status(battery);
@@ -1038,13 +1054,7 @@ static int acpi_battery_update(struct acpi_battery *battery, bool resume)
 		return 0;
 	}
 
-	/*
-	 * Wakeup the system if battery is critical low
-	 * or lower than the alarm level
-	 */
-	if ((battery->state & ACPI_BATTERY_STATE_CRITICAL) ||
-	    (test_bit(ACPI_BATTERY_ALARM_PRESENT, &battery->flags) &&
-	     (battery->capacity_now <= battery->alarm)))
+	if (acpi_battery_should_wake(battery))
 		acpi_pm_wakeup_event(&battery->device->dev);
 
 	return result;
-- 
2.43.0


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

Thread overview: 11+ 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 ` Mario Limonciello [this message]
2025-02-08 16:22 ` [PATCH 4/4] ACPI: battery: Wake system on AC plug or unplug in over s2idle Mario Limonciello
2025-02-08 17:59   ` 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

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-4-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