summaryrefslogtreecommitdiffstats
path: root/drivers/acpi/battery.c
diff options
context:
space:
mode:
authorLaszlo Toth <laszlth@gmail.com>2018-02-24 10:20:15 +0100
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2018-02-27 17:17:11 +0100
commita20136a67a995cd5b74e8c0fcb3b2f2e5b2848dd (patch)
tree7daabf42ed2d71c9966492595148993b93810998 /drivers/acpi/battery.c
parent514bcc5dfa69d64f7772cb6442721b9d1b83504d (diff)
downloadlinux-a20136a67a995cd5b74e8c0fcb3b2f2e5b2848dd.tar.bz2
ACPI: battery: do not export degraded capacity values over 100
With a degraded battery, full_charge_capacity can be less than design_capacity, however it's not sure that capacity_now's max will follow. Example from an affected machine: /sys/class/power_supply/BAT0/charge_full -> 4290000 /sys/class/power_supply/BAT0/charge_full_design -> 5900000 /sys/class/power_supply/BAT0/charge_now -> 5900000 /sys/class/power_supply/BAT0/capacity -> 137 The battery is a degraded one with a full charge, and charge_now is the value of charge_full_design instead of charge_full. Added a new quirk to test and correct this, and a new function to check if the battery is a degraded one or not. This keeps the possibility to be over 100 if it's really the case. Signed-off-by: Laszlo Toth <laszlth@gmail.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers/acpi/battery.c')
-rw-r--r--drivers/acpi/battery.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index b4580b2e8706..96ed134bacf8 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -121,6 +121,10 @@ enum {
post-1.29 BIOS), but as of Nov. 2012, no such update is
available for the 2010 models. */
ACPI_BATTERY_QUIRK_THINKPAD_MAH,
+ /* for batteries reporting current capacity with design capacity
+ * on a full charge, but showing degradation in full charge cap.
+ */
+ ACPI_BATTERY_QUIRK_DEGRADED_FULL_CHARGE,
};
struct acpi_battery {
@@ -207,6 +211,12 @@ static int acpi_battery_is_charged(struct acpi_battery *battery)
return 0;
}
+static bool acpi_battery_is_degraded(struct acpi_battery *battery)
+{
+ return battery->full_charge_capacity && battery->design_capacity &&
+ battery->full_charge_capacity < battery->design_capacity;
+}
+
static int acpi_battery_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
@@ -483,6 +493,10 @@ static int extract_battery_info(const int use_bix,
it's impossible to tell if they would need an adjustment
or not if their values were higher. */
}
+ if (test_bit(ACPI_BATTERY_QUIRK_DEGRADED_FULL_CHARGE, &battery->flags) &&
+ battery->capacity_now > battery->full_charge_capacity)
+ battery->capacity_now = battery->full_charge_capacity;
+
return result;
}
@@ -575,6 +589,10 @@ static int acpi_battery_get_state(struct acpi_battery *battery)
battery->capacity_now = battery->capacity_now *
10000 / battery->design_voltage;
}
+ if (test_bit(ACPI_BATTERY_QUIRK_DEGRADED_FULL_CHARGE, &battery->flags) &&
+ battery->capacity_now > battery->full_charge_capacity)
+ battery->capacity_now = battery->full_charge_capacity;
+
return result;
}
@@ -885,6 +903,15 @@ static void acpi_battery_quirks(struct acpi_battery *battery)
}
}
}
+
+ if (test_bit(ACPI_BATTERY_QUIRK_DEGRADED_FULL_CHARGE, &battery->flags))
+ return;
+
+ if (acpi_battery_is_degraded(battery) &&
+ battery->capacity_now > battery->full_charge_capacity) {
+ set_bit(ACPI_BATTERY_QUIRK_DEGRADED_FULL_CHARGE, &battery->flags);
+ battery->capacity_now = battery->full_charge_capacity;
+ }
}
static int acpi_battery_update(struct acpi_battery *battery, bool resume)