From: Zhang Rui <rui.zhang@intel.com>
To: "Brown, Len" <lenb@kernel.org>
Cc: "linux-acpi@vger.kernel.org" <linux-acpi@vger.kernel.org>,
"sitsofe@yahoo.com" <sitsofe@yahoo.com>
Subject: Re: [PATCH] ACPI battery: handle batteries tht report percentage remaining capacity correctly
Date: Wed, 13 Oct 2010 08:53:31 +0800 [thread overview]
Message-ID: <1286931211.2111.4093.camel@rui> (raw)
In-Reply-To: <1286929121.2111.4092.camel@rui>
On Wed, 2010-10-13 at 08:18 +0800, Zhang, Rui wrote:
> According to the ACPI spec, some kind of primary battery can
> report percentage battery remaining capacity directly to OS.
>
> In this case, it reports the LastFullChargedCapacity == 100,
> BatteryPresentRate == 0xFFFFFFFF, and BatteryRemaingCapacity a
> percentage value, which actually means RemainingBatteryPercentage.
>
> Now we found some battery follows this rule even if it's rechargeable.
> https://bugzilla.kernel.org/show_bug.cgi?id=15979
>
> Handle these batteries correctly in ACPI battery driver
> so that they won't break userspace.
>
Forgot to add,
Tested-by: Sitsofe Wheeler <sitsofe@yahoo.com>
> Signed-off-by: Zhang Rui <rui.zhang@intel.com>
> ---
> drivers/acpi/battery.c | 38 +++++++++++++++++++++++++++++++++++++-
> 1 file changed, 37 insertions(+), 1 deletion(-)
>
> Index: linux-2.6/drivers/acpi/battery.c
> ===================================================================
> --- linux-2.6.orig/drivers/acpi/battery.c
> +++ linux-2.6/drivers/acpi/battery.c
> @@ -98,6 +98,7 @@ enum {
> * due to bad math.
> */
> ACPI_BATTERY_QUIRK_SIGNED16_CURRENT,
> + ACPI_BATTERY_QUIRK_PERCENTAGE_CAPACITY,
> };
>
> struct acpi_battery {
> @@ -412,6 +413,8 @@ static int acpi_battery_get_info(struct
> result = extract_package(battery, buffer.pointer,
> info_offsets, ARRAY_SIZE(info_offsets));
> kfree(buffer.pointer);
> + if (test_bit(ACPI_BATTERY_QUIRK_PERCENTAGE_CAPACITY, &battery->flags))
> + battery->full_charge_capacity = battery->design_capacity;
> return result;
> }
>
> @@ -448,6 +451,10 @@ static int acpi_battery_get_state(struct
> battery->rate_now != -1)
> battery->rate_now = abs((s16)battery->rate_now);
>
> + if (test_bit(ACPI_BATTERY_QUIRK_PERCENTAGE_CAPACITY, &battery->flags)
> + && battery->capacity_now >= 0 && battery->capacity_now <= 100)
> + battery->capacity_now = (battery->capacity_now *
> + battery->full_charge_capacity) / 100;
> return result;
> }
>
> @@ -561,6 +568,33 @@ static void acpi_battery_quirks(struct a
> }
> }
>
> +/*
> + * According to the ACPI spec, some kinds of primary batteries can
> + * report percentage battery remaining capacity directly to OS.
> + * In this case, it reports the Last Full Charged Capacity == 100
> + * and BatteryPresentRate == 0xFFFFFFFF.
> + *
> + * Now we found some battery reports percentage remaining capacity
> + * even if it's rechargeable.
> + * https://bugzilla.kernel.org/show_bug.cgi?id=15979
> + *
> + * Handle this correctly so that they won't break userspace.
> + */
> +static void acpi_battery_quirks2(struct acpi_battery *battery)
> +{
> + if (test_bit(ACPI_BATTERY_QUIRK_PERCENTAGE_CAPACITY, &battery->flags))
> + return ;
> +
> + if (battery->full_charge_capacity == 100 &&
> + battery->rate_now == ACPI_BATTERY_VALUE_UNKNOWN &&
> + battery->capacity_now >=0 && battery->capacity_now <= 100) {
> + set_bit(ACPI_BATTERY_QUIRK_PERCENTAGE_CAPACITY, &battery->flags);
> + battery->full_charge_capacity = battery->design_capacity;
> + battery->capacity_now = (battery->capacity_now *
> + battery->full_charge_capacity) / 100;
> + }
> +}
> +
> static int acpi_battery_update(struct acpi_battery *battery)
> {
> int result, old_present = acpi_battery_present(battery);
> @@ -586,7 +620,9 @@ static int acpi_battery_update(struct ac
> if (!battery->bat.dev)
> sysfs_add_battery(battery);
> #endif
> - return acpi_battery_get_state(battery);
> + result = acpi_battery_get_state(battery);
> + acpi_battery_quirks2(battery);
> + return result;
> }
>
> /* --------------------------------------------------------------------------
>
>
next prev parent reply other threads:[~2010-10-13 0:56 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-13 0:18 [PATCH] ACPI battery: handle batteries tht report percentage remaining capacity correctly Zhang Rui
2010-10-13 0:53 ` Zhang Rui [this message]
2010-10-13 16:28 ` Len Brown
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=1286931211.2111.4093.camel@rui \
--to=rui.zhang@intel.com \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=sitsofe@yahoo.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