public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
From: Richard Hughes <hughsient@gmail.com>
To: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
Cc: Alexey Starikovskiy <astarikovskiy@suse.de>,
	linux-acpi <linux-acpi@vger.kernel.org>, mjg <mjg@redhat.com>,
	Matthias Clasen <mclasen@redhat.com>
Subject: Re: [patch] ACPI battery driver emits POWER_SUPPLY_STATUS_FULL when power lead plugged in
Date: Sun, 25 Jan 2009 15:13:28 +0000	[thread overview]
Message-ID: <1232896408.3990.5.camel@hughsie-work.lan> (raw)
In-Reply-To: <20090125134203.GA12776@khazad-dum.debian.net>

[-- Attachment #1: Type: text/plain, Size: 923 bytes --]

On Sun, 2009-01-25 at 11:42 -0200, Henrique de Moraes Holschuh wrote:
>  So, the above test will still break on any proper battery subsystem with the
> high watermark set below 100%, as those systems update full_charge_capacity
> *only* when the cells really are full (and not because the EC decided to
> stop the charging before they were full).

This is what I observed when testing my patch.

The attached patch checks the last full and design charge, as this seems
to work in all cases I have here. In the case of broken batteries or
broken hardware, we just return UNKNOWN in this "settling" state, which
is much better for userspace than falling back to full.

With the attached patch userspace gets the right states. In the future,
maybe we can do some sort of metric over time (watching to see if the
present charge changes) but for the most part the patch fixes things up
for userspace.

Please review,

Richard.


[-- Attachment #2: 0001-battery-don-t-assume-we-are-fully-charged-when-not.patch --]
[-- Type: text/x-patch, Size: 2258 bytes --]

>From 3b0fb1239e5bc064766ffa3d7a45265e722fb9eb Mon Sep 17 00:00:00 2001
From: Richard Hughes <hughsient@gmail.com>
Date: Sun, 25 Jan 2009 15:05:50 +0000
Subject: [PATCH] battery: don't assume we are fully charged when not charging or discharging

On hardware like the T61 it can take a couple of seconds for the battery
to start charging after the power is connected, and we incorrectly tell
userspace that we are fully charged, and then go back to charging.

Only mark a battery as fully charged when the preset charge matches either
the last full charge, or the design charge.

Signed-off-by: Richard Hughes <hughsient@gmail.com>
---
 drivers/acpi/battery.c |   25 ++++++++++++++++++++++++-
 1 files changed, 24 insertions(+), 1 deletions(-)

diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 65132f9..69cbc57 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -138,6 +138,29 @@ static int acpi_battery_technology(struct acpi_battery *battery)
 
 static int acpi_battery_get_state(struct acpi_battery *battery);
 
+static int acpi_battery_is_charged(struct acpi_battery *battery)
+{
+	/* either charging or discharging */
+	if (battery->state != 0)
+		return 0;
+
+	/* battery not reporting charge */
+	if (battery->capacity_now == ACPI_BATTERY_VALUE_UNKNOWN ||
+	    battery->capacity_now == 0)
+		return 0;
+
+	/* good batteries update full_charge as the batteries degrade */
+	if (battery->full_charge_capacity == battery->capacity_now)
+		return 1;
+
+	/* fallback to using design values for broken batteries */
+	if (battery->design_capacity == battery->capacity_now)
+		return 1;
+
+	/* we don't do any sort of metric based on percentages */
+	return 0;
+}
+
 static int acpi_battery_get_property(struct power_supply *psy,
 				     enum power_supply_property psp,
 				     union power_supply_propval *val)
@@ -155,7 +178,7 @@ static int acpi_battery_get_property(struct power_supply *psy,
 			val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
 		else if (battery->state & 0x02)
 			val->intval = POWER_SUPPLY_STATUS_CHARGING;
-		else if (battery->state == 0)
+		else if (acpi_battery_is_charged(battery))
 			val->intval = POWER_SUPPLY_STATUS_FULL;
 		else
 			val->intval = POWER_SUPPLY_STATUS_UNKNOWN;
-- 
1.6.0.6


  reply	other threads:[~2009-01-25 15:14 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-23 16:57 ACPI battery driver emits POWER_SUPPLY_STATUS_FULL when power lead plugged in Richard Hughes
2009-01-23 19:00 ` Alexey Starikovskiy
2009-01-23 22:02   ` Henrique de Moraes Holschuh
2009-01-23 23:39     ` Richard Hughes
2009-01-24  0:14       ` Alexey Starikovskiy
2009-01-24 12:41         ` Henrique de Moraes Holschuh
2009-01-24 16:37           ` Alexey Starikovskiy
2009-01-25 10:28             ` [patch] " Richard Hughes
2009-01-25 10:55               ` Alexey Starikovskiy
2009-01-25 13:42               ` Henrique de Moraes Holschuh
2009-01-25 15:13                 ` Richard Hughes [this message]
2009-01-25 19:50                   ` Alexey Starikovskiy
2009-01-26  8:43                     ` Richard Hughes
2009-01-28 13:20                 ` [patch] ACPI battery driver emits POWER_SUPPLY_STATUS_FULL when power lead plugged in (resend) Richard Hughes
2009-01-30 14:07                   ` Henrique de Moraes Holschuh
2009-02-08  3:59                     ` Len Brown
2009-02-08 10:08                       ` Richard Hughes

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=1232896408.3990.5.camel@hughsie-work.lan \
    --to=hughsient@gmail.com \
    --cc=astarikovskiy@suse.de \
    --cc=hmh@hmh.eng.br \
    --cc=linux-acpi@vger.kernel.org \
    --cc=mclasen@redhat.com \
    --cc=mjg@redhat.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