Linux ACPI
 help / color / mirror / Atom feed
From: Umang Jain <uajain@igalia.com>
To: "Rafael J. Wysocki (Intel)" <rafael@kernel.org>
Cc: Len Brown <lenb@kernel.org>,
	linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org,
	kernel-dev@igalia.com
Subject: Re: [PATCH v2 1/2] acpi: battery: Query Battery charge time ("_BCT") method
Date: Tue, 13 Oct 2026 21:12:26 +0200	[thread overview]
Message-ID: <bbe784378cf3f8c0ce43ce24d22465b7@igalia.com> (raw)
In-Reply-To: <CAJZ5v0i0UPcGiiAxNbjUnzn=8D2jcTCo_wtM8aMbOKhqb37EDA@mail.gmail.com>

Hi Rafael,

Thanks for the review.

On 2026-10-12 17:15, Rafael J. Wysocki (Intel) wrote:
> On Wed, Sep 23, 2026 at 10:28 AM Umang Jain <uajain@igalia.com> wrote:
>>
>> 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;
> 
> This doesn't need to be unsigned long long.  As per the spec, unsigned
> int should be sufficient.
> 
>>         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;
> 
> Please move the definitions of the variables related to _BCT
> evaluation to the code block where it gets evaluated.
> 
>>
>>         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);
> 
> Currently, you only need to evaluate _BCT to implement the quirk in
> the second patch AFAICS, so it is not useful to evaluate _BCT if the
> quirk is not going to be used.  Any chance to rearrange the code to
> avoid evaluating _BCT when it is not needed?

Currently yes, _BCT is not useful in all cases, but since it is a ACPI
specification component, I didn't keep it behind the quirk and read as a
global param to read out.

I've re-arranged the code to evaluate _BCT if the quirk is present, but
want to double sure if that's the design we need to go ahead with?

> 
>> +       if (ACPI_FAILURE(status))
>> +               acpi_handle_info(battery->device->handle,
>> +                                "_BCT evaluation failed: %s",
>> +                                acpi_format_exception(status));
> 
> Missing indentation.

Looks fine to me, what's wrong? The patches sent are sanitized with
./scripts/checkpatch.pl, unless I am missing something?
> 
>> +       }
>> +
>>         /* 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);
>> --

  reply	other threads:[~2026-10-13 19:12 UTC|newest]

Thread overview: 7+ 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 ` [PATCH v2 1/2] acpi: battery: Query Battery charge time ("_BCT") method Umang Jain
2026-10-12 15:15   ` Rafael J. Wysocki (Intel)
2026-10-13 19:12     ` Umang Jain [this message]
2026-09-23  8:29 ` [PATCH v2 2/2] acpi: battery: Handle Valve steamdeck devices quirk Umang Jain
2026-10-12 15:19   ` Rafael J. Wysocki (Intel)
2026-10-10 16:57 ` [PATCH v2 0/2] acpi: battery: Query BCT method and steamdeck 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=bbe784378cf3f8c0ce43ce24d22465b7@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