From: Armin Wolf <W_Armin@gmx.de>
To: rafael@kernel.org, lenb@kernel.org
Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org,
wse@tuxedocomputers.com
Subject: Re: [PATCH] ACPI: battery: Fix bogus cycle count values on systems without _BIX
Date: Tue, 1 Sep 2026 22:11:24 +0200 [thread overview]
Message-ID: <f2f17b0d-22a1-4a57-895b-318bb50456f3@gmx.de> (raw)
In-Reply-To: <20260806233817.622975-1-W_Armin@gmx.de>
Am 07.08.26 um 01:38 schrieb Armin Wolf:
> Devices supporting only the legacy _BIF ACPI control method cannot
> know the cycle count of the associated battery, so cycle_count always
> remains 0. Claiming support for POWER_SUPPLY_PROP_CYCLE_COUNT on
> such devices can thus mislead userspace applications and prevents
> power supply extensions from supplying correct cycle count values.
>
> Fix this by not claiming support for POWER_SUPPLY_PROP_CYCLE_COUNT
> on devices without _BIX.
Any thoughts on this? I tested it on my device, and so far everything seems
to work flawlessly.
Thanks,
Armin Wolf
> Signed-off-by: Armin Wolf <W_Armin@gmx.de>
> ---
> drivers/acpi/battery.c | 131 +++++++++++++++++++++++++++++++++++------
> 1 file changed, 113 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
> index 0084f308b790..b64f876f93cb 100644
> --- a/drivers/acpi/battery.c
> +++ b/drivers/acpi/battery.c
> @@ -324,7 +324,9 @@ static int acpi_battery_get_property(struct power_supply *psy,
> return ret;
> }
>
> -static const enum power_supply_property charge_battery_props[] = {
> +/* For devices supporting the _BIX ACPI control method */
> +
> +static const enum power_supply_property charge_battery_extended_props[] = {
> POWER_SUPPLY_PROP_STATUS,
> POWER_SUPPLY_PROP_PRESENT,
> POWER_SUPPLY_PROP_TECHNOLOGY,
> @@ -342,7 +344,7 @@ static const enum power_supply_property charge_battery_props[] = {
> POWER_SUPPLY_PROP_SERIAL_NUMBER,
> };
>
> -static const enum power_supply_property charge_battery_full_cap_broken_props[] = {
> +static const enum power_supply_property charge_battery_full_cap_broken_extended_props[] = {
> POWER_SUPPLY_PROP_STATUS,
> POWER_SUPPLY_PROP_PRESENT,
> POWER_SUPPLY_PROP_TECHNOLOGY,
> @@ -356,7 +358,7 @@ static const enum power_supply_property charge_battery_full_cap_broken_props[] =
> POWER_SUPPLY_PROP_SERIAL_NUMBER,
> };
>
> -static const enum power_supply_property energy_battery_props[] = {
> +static const enum power_supply_property energy_battery_extended_props[] = {
> POWER_SUPPLY_PROP_STATUS,
> POWER_SUPPLY_PROP_PRESENT,
> POWER_SUPPLY_PROP_TECHNOLOGY,
> @@ -374,7 +376,7 @@ static const enum power_supply_property energy_battery_props[] = {
> POWER_SUPPLY_PROP_SERIAL_NUMBER,
> };
>
> -static const enum power_supply_property energy_battery_full_cap_broken_props[] = {
> +static const enum power_supply_property energy_battery_full_cap_broken_extended_props[] = {
> POWER_SUPPLY_PROP_STATUS,
> POWER_SUPPLY_PROP_PRESENT,
> POWER_SUPPLY_PROP_TECHNOLOGY,
> @@ -388,6 +390,68 @@ static const enum power_supply_property energy_battery_full_cap_broken_props[] =
> POWER_SUPPLY_PROP_SERIAL_NUMBER,
> };
>
> +/* For devices supporting only the _BIF ACPI control method */
> +
> +static const enum power_supply_property charge_battery_props[] = {
> + POWER_SUPPLY_PROP_STATUS,
> + POWER_SUPPLY_PROP_PRESENT,
> + POWER_SUPPLY_PROP_TECHNOLOGY,
> + POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
> + POWER_SUPPLY_PROP_VOLTAGE_NOW,
> + POWER_SUPPLY_PROP_CURRENT_NOW,
> + POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
> + POWER_SUPPLY_PROP_CHARGE_FULL,
> + POWER_SUPPLY_PROP_CHARGE_NOW,
> + POWER_SUPPLY_PROP_CAPACITY,
> + POWER_SUPPLY_PROP_CAPACITY_LEVEL,
> + POWER_SUPPLY_PROP_MODEL_NAME,
> + POWER_SUPPLY_PROP_MANUFACTURER,
> + POWER_SUPPLY_PROP_SERIAL_NUMBER,
> +};
> +
> +static const enum power_supply_property charge_battery_full_cap_broken_props[] = {
> + POWER_SUPPLY_PROP_STATUS,
> + POWER_SUPPLY_PROP_PRESENT,
> + POWER_SUPPLY_PROP_TECHNOLOGY,
> + POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
> + POWER_SUPPLY_PROP_VOLTAGE_NOW,
> + POWER_SUPPLY_PROP_CURRENT_NOW,
> + POWER_SUPPLY_PROP_CHARGE_NOW,
> + POWER_SUPPLY_PROP_MODEL_NAME,
> + POWER_SUPPLY_PROP_MANUFACTURER,
> + POWER_SUPPLY_PROP_SERIAL_NUMBER,
> +};
> +
> +static const enum power_supply_property energy_battery_props[] = {
> + POWER_SUPPLY_PROP_STATUS,
> + POWER_SUPPLY_PROP_PRESENT,
> + POWER_SUPPLY_PROP_TECHNOLOGY,
> + POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
> + POWER_SUPPLY_PROP_VOLTAGE_NOW,
> + POWER_SUPPLY_PROP_POWER_NOW,
> + POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN,
> + POWER_SUPPLY_PROP_ENERGY_FULL,
> + POWER_SUPPLY_PROP_ENERGY_NOW,
> + POWER_SUPPLY_PROP_CAPACITY,
> + POWER_SUPPLY_PROP_CAPACITY_LEVEL,
> + POWER_SUPPLY_PROP_MODEL_NAME,
> + POWER_SUPPLY_PROP_MANUFACTURER,
> + POWER_SUPPLY_PROP_SERIAL_NUMBER,
> +};
> +
> +static const enum power_supply_property energy_battery_full_cap_broken_props[] = {
> + POWER_SUPPLY_PROP_STATUS,
> + POWER_SUPPLY_PROP_PRESENT,
> + POWER_SUPPLY_PROP_TECHNOLOGY,
> + POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
> + POWER_SUPPLY_PROP_VOLTAGE_NOW,
> + POWER_SUPPLY_PROP_POWER_NOW,
> + POWER_SUPPLY_PROP_ENERGY_NOW,
> + POWER_SUPPLY_PROP_MODEL_NAME,
> + POWER_SUPPLY_PROP_MANUFACTURER,
> + POWER_SUPPLY_PROP_SERIAL_NUMBER,
> +};
> +
> /* Battery Management */
> struct acpi_offsets {
> size_t offset; /* offset inside struct acpi_sbs_battery */
> @@ -875,6 +939,7 @@ static void __exit battery_hook_exit(void)
>
> static int sysfs_add_battery(struct acpi_battery *battery)
> {
> + bool extended_info_available = test_bit(ACPI_BATTERY_XINFO_PRESENT, &battery->flags);
> struct power_supply_config psy_cfg = {
> .drv_data = battery,
> .attr_grp = acpi_battery_groups,
> @@ -888,25 +953,55 @@ static int sysfs_add_battery(struct acpi_battery *battery)
>
> if (battery->power_unit == ACPI_BATTERY_POWER_UNIT_MA) {
> if (full_cap_broken) {
> - battery->bat_desc.properties =
> - charge_battery_full_cap_broken_props;
> - battery->bat_desc.num_properties =
> - ARRAY_SIZE(charge_battery_full_cap_broken_props);
> + if (extended_info_available) {
> + battery->bat_desc.properties =
> + charge_battery_full_cap_broken_extended_props;
> + battery->bat_desc.num_properties =
> + ARRAY_SIZE(charge_battery_full_cap_broken_extended_props);
> + } else {
> + battery->bat_desc.properties =
> + charge_battery_full_cap_broken_props;
> + battery->bat_desc.num_properties =
> + ARRAY_SIZE(charge_battery_full_cap_broken_props);
> + }
> } else {
> - battery->bat_desc.properties = charge_battery_props;
> - battery->bat_desc.num_properties =
> - ARRAY_SIZE(charge_battery_props);
> + if (extended_info_available) {
> + battery->bat_desc.properties =
> + charge_battery_extended_props;
> + battery->bat_desc.num_properties =
> + ARRAY_SIZE(charge_battery_extended_props);
> + } else {
> + battery->bat_desc.properties =
> + charge_battery_props;
> + battery->bat_desc.num_properties =
> + ARRAY_SIZE(charge_battery_props);
> + }
> }
> } else {
> if (full_cap_broken) {
> - battery->bat_desc.properties =
> - energy_battery_full_cap_broken_props;
> - battery->bat_desc.num_properties =
> - ARRAY_SIZE(energy_battery_full_cap_broken_props);
> + if (extended_info_available) {
> + battery->bat_desc.properties =
> + energy_battery_full_cap_broken_extended_props;
> + battery->bat_desc.num_properties =
> + ARRAY_SIZE(energy_battery_full_cap_broken_extended_props);
> + } else {
> + battery->bat_desc.properties =
> + energy_battery_full_cap_broken_props;
> + battery->bat_desc.num_properties =
> + ARRAY_SIZE(energy_battery_full_cap_broken_props);
> + }
> } else {
> - battery->bat_desc.properties = energy_battery_props;
> - battery->bat_desc.num_properties =
> - ARRAY_SIZE(energy_battery_props);
> + if (extended_info_available) {
> + battery->bat_desc.properties =
> + energy_battery_extended_props;
> + battery->bat_desc.num_properties =
> + ARRAY_SIZE(energy_battery_extended_props);
> + } else {
> + battery->bat_desc.properties =
> + energy_battery_props;
> + battery->bat_desc.num_properties =
> + ARRAY_SIZE(energy_battery_props);
> + }
> }
> }
>
next prev parent reply other threads:[~2026-09-01 20:11 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-06 23:38 Armin Wolf
2026-09-01 20:11 ` Armin Wolf [this message]
2026-09-01 20:16 ` Rafael J. Wysocki (Intel)
2026-09-01 20:18 ` Armin Wolf
2026-09-09 14:27 ` Rafael J. Wysocki (Intel)
2026-09-09 22:39 ` Armin Wolf
2026-09-10 10:33 ` Rafael J. Wysocki (Intel)
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=f2f17b0d-22a1-4a57-895b-318bb50456f3@gmx.de \
--to=w_armin@gmx.de \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=wse@tuxedocomputers.com \
/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®