mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Umang Jain <uajain@igalia.com>
To: "Rafael J. Wysocki" <rafael@kernel.org>, Len Brown <lenb@kernel.org>
Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org,
	kernel-dev@igalia.com, Umang Jain <uajain@igalia.com>
Subject: [PATCH v2 1/2] acpi: battery: Query Battery charge time ("_BCT") method
Date: Wed, 23 Sep 2026 13:59:31 +0530	[thread overview]
Message-ID: <20260923082932.1049270-2-uajain@igalia.com> (raw)
In-Reply-To: <20260923082932.1049270-1-uajain@igalia.com>

Add plumbing for querying the Battery Charge Time ("_BCT") method.
If present, set ACPI_BATTERY_BCT_PRESENT in battery flags to denote
that the method is supported in ACPI.

Signed-off-by: Umang Jain <uajain@igalia.com>
---
 drivers/acpi/battery.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 670853ec3a4d..a1b7a821abaf 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -76,6 +76,7 @@ MODULE_DEVICE_TABLE(acpi, battery_device_ids);
 enum {
 	ACPI_BATTERY_ALARM_PRESENT,
 	ACPI_BATTERY_XINFO_PRESENT,
+	ACPI_BATTERY_BCT_PRESENT,
 	ACPI_BATTERY_QUIRK_PERCENTAGE_CAPACITY,
 	/* On Lenovo Thinkpad models from 2010 and 2011, the power unit
 	 * switches between mWh and mAh depending on whether the system
@@ -110,6 +111,7 @@ struct acpi_battery {
 
 	struct mutex property_lock; /* Protects properties below. */
 	unsigned long update_time;
+	unsigned long long charge_time;
 	int revision;
 	int rate_now;
 	int capacity_now;
@@ -613,6 +615,10 @@ static int acpi_battery_get_state(struct acpi_battery *battery)
 	int result = 0;
 	acpi_status status = 0;
 	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
+	union acpi_object arg0 = { ACPI_TYPE_INTEGER };
+	struct acpi_object_list args = { 1, &arg0 };
+
+	arg0.integer.value = 100;
 
 	lockdep_assert_held(&battery->property_lock);
 
@@ -638,6 +644,15 @@ static int acpi_battery_get_state(struct acpi_battery *battery)
 	battery->update_time = jiffies;
 	kfree(buffer.pointer);
 
+	if (test_bit(ACPI_BATTERY_BCT_PRESENT, &battery->flags)) {
+		status = acpi_evaluate_integer(battery->device->handle, "_BCT",
+					       &args, &battery->charge_time);
+	if (ACPI_FAILURE(status))
+		acpi_handle_info(battery->device->handle,
+				 "_BCT evaluation failed: %s",
+				 acpi_format_exception(status));
+	}
+
 	/* For buggy DSDTs that report negative 16-bit values for either
 	 * charging or discharging current and/or report 0 as 65536
 	 * due to bad math.
@@ -1083,6 +1098,8 @@ static int acpi_battery_update(struct acpi_battery *battery, bool resume)
 			if (result)
 				return result;
 			acpi_battery_init_alarm(battery);
+			if (acpi_has_method(battery->device->handle, "_BCT"))
+				set_bit(ACPI_BATTERY_BCT_PRESENT, &battery->flags);
 		}
 
 		result = acpi_battery_get_state(battery);
-- 
2.55.0


  reply	other threads:[~2026-09-23  8:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-23  8:29 [PATCH v2 0/2] acpi: battery: Query BCT method and steamdeck Umang Jain
2026-09-23  8:29 ` Umang Jain [this message]
2026-09-23  8:29 ` [PATCH v2 2/2] acpi: battery: Handle Valve steamdeck devices quirk Umang Jain

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=20260923082932.1049270-2-uajain@igalia.com \
    --to=uajain@igalia.com \
    --cc=kernel-dev@igalia.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --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

all inboxes | Powered by JetHome®