From: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
To: astarikovskiy@suse.de
Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] battery: Fix charge_now returned by broken batteries
Date: Sun, 04 Oct 2009 17:24:13 +0200 [thread overview]
Message-ID: <1254669853.26496.0.camel@carter> (raw)
Some broken batteries like my DELL NR2227 or a friend's DELL GK4798 return
the design_capacity (charge_full_design) as capacity_now (charge_now)
when completely charged.
I noticed this when looking at a battery plugin that reported "127% charged".
Some of these plugins have already "fixed" this in userspace by coding
something like min(percentage, 100)).
Reading /sys/class/power_supply/BAT0/* my battery reported:
charge_full = 5980000
charge_full_design = 7650000
I let my battery discharge a little bit and then I started charging it.
At the same time, I read charge_now every second:
...
5850000 (charging)
5850000 (charging)
5850000 (charging)
...
5900000 (charging)
5900000 (charging)
5900000 (charging)
...
5950000 (charging)
5950000 (charging)
5950000 (charging)
7650000 (charged)
7650000 (charged)
7650000 (charged)
7650000 (charged)
...
So I discovered that the battery wrongly returns charge_full_design when
completely charged instead of charge_full.
This patch fixes this by returning min(capacity_now, full_charge_capacity)
on both procfs and sysfs.
Now the userspace plugins report the correct 100% and their userspace check
may not be needed (if this error is the only one producing >100% results).
Signed-off-by: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
---
drivers/acpi/battery.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
--- linux-2.6.31.1/drivers/acpi/battery.c.old 2009-10-04 15:50:37.743999621 +0200
+++ linux-2.6.31.1/drivers/acpi/battery.c 2009-10-04 16:33:47.843696066 +0200
@@ -210,7 +210,10 @@ static int acpi_battery_get_property(str
break;
case POWER_SUPPLY_PROP_CHARGE_NOW:
case POWER_SUPPLY_PROP_ENERGY_NOW:
- val->intval = battery->capacity_now * 1000;
+ /* broken batteries return the design_capacity
+ as capacity_now when completely charged */
+ val->intval = min(battery->capacity_now,
+ battery->full_charge_capacity) * 1000;
break;
case POWER_SUPPLY_PROP_MODEL_NAME:
val->strval = battery->model_number;
@@ -617,8 +620,12 @@ static int acpi_battery_print_state(stru
if (battery->capacity_now == ACPI_BATTERY_VALUE_UNKNOWN)
seq_printf(seq, "remaining capacity: unknown\n");
else
+ /* broken batteries return the design_capacity
+ as capacity_now when completely charged */
seq_printf(seq, "remaining capacity: %d %sh\n",
- battery->capacity_now, acpi_battery_units(battery));
+ min(battery->capacity_now,
+ battery->full_charge_capacity),
+ acpi_battery_units(battery));
if (battery->voltage_now == ACPI_BATTERY_VALUE_UNKNOWN)
seq_printf(seq, "present voltage: unknown\n");
else
next reply other threads:[~2009-10-04 15:24 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-04 15:24 Miguel Ojeda [this message]
2009-10-04 16:45 ` [PATCH] battery: Fix charge_now returned by broken batteries Henrique de Moraes Holschuh
2009-10-04 17:46 ` Miguel Ojeda
2009-10-04 18:57 ` Alexey Starikovskiy
2009-10-04 20:46 ` Rafael J. Wysocki
2009-10-04 21:36 ` Alexey Starikovskiy
2009-10-04 21:36 ` Alexey Starikovskiy
2009-10-04 21:55 ` Miguel Ojeda
2009-10-04 21:55 ` Miguel Ojeda
2009-10-04 22:38 ` Alexey Starikovskiy
2009-10-04 22:38 ` Alexey Starikovskiy
2009-10-04 23:53 ` Miguel Ojeda
2009-10-04 23:53 ` Miguel Ojeda
2009-10-05 0:18 ` Alexey Starikovskiy
2009-10-05 0:18 ` Alexey Starikovskiy
2009-10-06 17:05 ` Miguel Ojeda
2009-10-06 17:05 ` Miguel Ojeda
2009-10-10 12:04 ` Pavel Machek
2009-10-10 20:53 ` Miguel Ojeda
2009-10-10 21:25 ` Pavel Machek
2009-10-10 21:44 ` Miguel Ojeda
2009-10-10 22:49 ` Pavel Machek
2009-10-10 21:52 ` Henrique de Moraes Holschuh
2009-10-04 22:43 ` Rafael J. Wysocki
2009-10-04 22:56 ` Alexey Starikovskiy
2009-10-04 22:56 ` Alexey Starikovskiy
2009-10-04 23:58 ` Miguel Ojeda
2009-10-04 23:58 ` Miguel Ojeda
2009-10-04 21:42 ` Miguel Ojeda
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=1254669853.26496.0.camel@carter \
--to=miguel.ojeda.sandonis@gmail.com \
--cc=astarikovskiy@suse.de \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.