forked from Minki/linux
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. http://bugzilla.kernel.org/show_bug.cgi?id=12632 Signed-off-by: Richard Hughes <hughsient@gmail.com> Acked-by: Alexey Starikovskiy <astarikovskiy@suse.de> Acked-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br> Signed-off-by: Len Brown <len.brown@intel.com>
This commit is contained in:
parent
e83102cab0
commit
56f382a087
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user