Message ID | 1232896408.3990.5.camel@hughsie-work.lan (mailing list archive) |
---|---|
State | Superseded, archived |
Headers | show |
Richard Hughes wrote: > 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. > else > val->intval = POWER_SUPPLY_STATUS_UNKNOWN; This last else should return STATUS_NOT_CHARGING, IMHO. We know this little bit about it. > > Please review, > > Richard. > > -- To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Sun, 2009-01-25 at 22:50 +0300, Alexey Starikovskiy wrote: > > val->intval = POWER_SUPPLY_STATUS_UNKNOWN; > This last else should return STATUS_NOT_CHARGING, IMHO. We know this > little bit about it. I don't think so; I mean it just as well means STATUS_NOT_DISCHARGING. We don't actually know what the battery is doing internally, hence the UNKNOWN. Richard. -- To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
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