Skip to content

Commit

Permalink
ACPI / Battery: Change 16-bit signed negative battery current into co…
Browse files Browse the repository at this point in the history
…rrect value

This patch is for some machines which report the battery current
as a 16-bit signed negative when it is charging. This is caused
by DSDT bug. The commit bc76f90
has resolved the problem for Acer laptops. But some other machines
also have such problem.

    https://bugzilla.kernel.org/show_bug.cgi?id=33722

Since it is improper that the current is above 32A on laptops
whether on AC or on battery, this patch is to check the current and
 take its absolute value as current and producing a message when it
is negative in s16.

Remove Acer quirk, as this workaround handles Acer too.

Signed-off-by: Lan Tianyu <tianyu.lan@intel.com>
Signed-off-by: Len Brown <len.brown@intel.com>
  • Loading branch information
Lan Tianyu authored and lenb committed Jul 14, 2011
1 parent ae6f618 commit 55003b2
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions drivers/acpi/battery.c
Expand Up @@ -94,11 +94,6 @@ MODULE_DEVICE_TABLE(acpi, battery_device_ids);
enum {
ACPI_BATTERY_ALARM_PRESENT,
ACPI_BATTERY_XINFO_PRESENT,
/* For buggy DSDTs that report negative 16-bit values for either
* charging or discharging current and/or report 0 as 65536
* due to bad math.
*/
ACPI_BATTERY_QUIRK_SIGNED16_CURRENT,
ACPI_BATTERY_QUIRK_PERCENTAGE_CAPACITY,
};

Expand Down Expand Up @@ -465,9 +460,17 @@ static int acpi_battery_get_state(struct acpi_battery *battery)
battery->update_time = jiffies;
kfree(buffer.pointer);

if (test_bit(ACPI_BATTERY_QUIRK_SIGNED16_CURRENT, &battery->flags) &&
battery->rate_now != -1)
/* For buggy DSDTs that report negative 16-bit values for either
* charging or discharging current and/or report 0 as 65536
* due to bad math.
*/
if (battery->power_unit == ACPI_BATTERY_POWER_UNIT_MA &&
battery->rate_now != ACPI_BATTERY_VALUE_UNKNOWN &&
(s16)(battery->rate_now) < 0) {
battery->rate_now = abs((s16)battery->rate_now);
printk_once(KERN_WARNING FW_BUG "battery: (dis)charge rate"
" invalid.\n");
}

if (test_bit(ACPI_BATTERY_QUIRK_PERCENTAGE_CAPACITY, &battery->flags)
&& battery->capacity_now >= 0 && battery->capacity_now <= 100)
Expand Down Expand Up @@ -577,14 +580,6 @@ static void sysfs_remove_battery(struct acpi_battery *battery)
battery->bat.dev = NULL;
}

static void acpi_battery_quirks(struct acpi_battery *battery)
{
if (dmi_name_in_vendors("Acer") &&
battery->power_unit == ACPI_BATTERY_POWER_UNIT_MA) {
set_bit(ACPI_BATTERY_QUIRK_SIGNED16_CURRENT, &battery->flags);
}
}

/*
* According to the ACPI spec, some kinds of primary batteries can
* report percentage battery remaining capacity directly to OS.
Expand Down Expand Up @@ -628,7 +623,6 @@ static int acpi_battery_update(struct acpi_battery *battery)
result = acpi_battery_get_info(battery);
if (result)
return result;
acpi_battery_quirks(battery);
acpi_battery_init_alarm(battery);
}
if (!battery->bat.dev)
Expand Down

0 comments on commit 55003b2

Please sign in to comment.