aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/battery.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi/battery.c')
-rw-r--r--drivers/acpi/battery.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 58b4517ce712..3f4602b8f287 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -31,6 +31,7 @@
31#include <linux/types.h> 31#include <linux/types.h>
32#include <linux/jiffies.h> 32#include <linux/jiffies.h>
33#include <linux/async.h> 33#include <linux/async.h>
34#include <linux/dmi.h>
34 35
35#ifdef CONFIG_ACPI_PROCFS_POWER 36#ifdef CONFIG_ACPI_PROCFS_POWER
36#include <linux/proc_fs.h> 37#include <linux/proc_fs.h>
@@ -45,6 +46,8 @@
45#include <linux/power_supply.h> 46#include <linux/power_supply.h>
46#endif 47#endif
47 48
49#define PREFIX "ACPI: "
50
48#define ACPI_BATTERY_VALUE_UNKNOWN 0xFFFFFFFF 51#define ACPI_BATTERY_VALUE_UNKNOWN 0xFFFFFFFF
49 52
50#define ACPI_BATTERY_CLASS "battery" 53#define ACPI_BATTERY_CLASS "battery"
@@ -85,6 +88,10 @@ static const struct acpi_device_id battery_device_ids[] = {
85 88
86MODULE_DEVICE_TABLE(acpi, battery_device_ids); 89MODULE_DEVICE_TABLE(acpi, battery_device_ids);
87 90
91/* For buggy DSDTs that report negative 16-bit values for either charging
92 * or discharging current and/or report 0 as 65536 due to bad math.
93 */
94#define QUIRK_SIGNED16_CURRENT 0x0001
88 95
89struct acpi_battery { 96struct acpi_battery {
90 struct mutex lock; 97 struct mutex lock;
@@ -112,6 +119,7 @@ struct acpi_battery {
112 int state; 119 int state;
113 int power_unit; 120 int power_unit;
114 u8 alarm_present; 121 u8 alarm_present;
122 long quirks;
115}; 123};
116 124
117#define to_acpi_battery(x) container_of(x, struct acpi_battery, bat); 125#define to_acpi_battery(x) container_of(x, struct acpi_battery, bat);
@@ -390,6 +398,11 @@ static int acpi_battery_get_state(struct acpi_battery *battery)
390 state_offsets, ARRAY_SIZE(state_offsets)); 398 state_offsets, ARRAY_SIZE(state_offsets));
391 battery->update_time = jiffies; 399 battery->update_time = jiffies;
392 kfree(buffer.pointer); 400 kfree(buffer.pointer);
401
402 if ((battery->quirks & QUIRK_SIGNED16_CURRENT) &&
403 battery->rate_now != -1)
404 battery->rate_now = abs((s16)battery->rate_now);
405
393 return result; 406 return result;
394} 407}
395 408
@@ -495,6 +508,14 @@ static void sysfs_remove_battery(struct acpi_battery *battery)
495} 508}
496#endif 509#endif
497 510
511static void acpi_battery_quirks(struct acpi_battery *battery)
512{
513 battery->quirks = 0;
514 if (dmi_name_in_vendors("Acer") && battery->power_unit) {
515 battery->quirks |= QUIRK_SIGNED16_CURRENT;
516 }
517}
518
498static int acpi_battery_update(struct acpi_battery *battery) 519static int acpi_battery_update(struct acpi_battery *battery)
499{ 520{
500 int result, old_present = acpi_battery_present(battery); 521 int result, old_present = acpi_battery_present(battery);
@@ -513,6 +534,7 @@ static int acpi_battery_update(struct acpi_battery *battery)
513 result = acpi_battery_get_info(battery); 534 result = acpi_battery_get_info(battery);
514 if (result) 535 if (result)
515 return result; 536 return result;
537 acpi_battery_quirks(battery);
516 acpi_battery_init_alarm(battery); 538 acpi_battery_init_alarm(battery);
517 } 539 }
518#ifdef CONFIG_ACPI_SYSFS_POWER 540#ifdef CONFIG_ACPI_SYSFS_POWER