Commit a20136a67a995cd5b74e8c0fcb3b2f2e5b2848dd
Committed by
Rafael J. Wysocki
1 parent
514bcc5dfa
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>
Showing 1 changed file with 27 additions and 0 deletions Side-by-side Diff
drivers/acpi/battery.c
... | ... | @@ -121,6 +121,10 @@ |
121 | 121 | post-1.29 BIOS), but as of Nov. 2012, no such update is |
122 | 122 | available for the 2010 models. */ |
123 | 123 | ACPI_BATTERY_QUIRK_THINKPAD_MAH, |
124 | + /* for batteries reporting current capacity with design capacity | |
125 | + * on a full charge, but showing degradation in full charge cap. | |
126 | + */ | |
127 | + ACPI_BATTERY_QUIRK_DEGRADED_FULL_CHARGE, | |
124 | 128 | }; |
125 | 129 | |
126 | 130 | struct acpi_battery { |
... | ... | @@ -207,6 +211,12 @@ |
207 | 211 | return 0; |
208 | 212 | } |
209 | 213 | |
214 | +static bool acpi_battery_is_degraded(struct acpi_battery *battery) | |
215 | +{ | |
216 | + return battery->full_charge_capacity && battery->design_capacity && | |
217 | + battery->full_charge_capacity < battery->design_capacity; | |
218 | +} | |
219 | + | |
210 | 220 | static int acpi_battery_get_property(struct power_supply *psy, |
211 | 221 | enum power_supply_property psp, |
212 | 222 | union power_supply_propval *val) |
... | ... | @@ -483,6 +493,10 @@ |
483 | 493 | it's impossible to tell if they would need an adjustment |
484 | 494 | or not if their values were higher. */ |
485 | 495 | } |
496 | + if (test_bit(ACPI_BATTERY_QUIRK_DEGRADED_FULL_CHARGE, &battery->flags) && | |
497 | + battery->capacity_now > battery->full_charge_capacity) | |
498 | + battery->capacity_now = battery->full_charge_capacity; | |
499 | + | |
486 | 500 | return result; |
487 | 501 | } |
488 | 502 | |
... | ... | @@ -575,6 +589,10 @@ |
575 | 589 | battery->capacity_now = battery->capacity_now * |
576 | 590 | 10000 / battery->design_voltage; |
577 | 591 | } |
592 | + if (test_bit(ACPI_BATTERY_QUIRK_DEGRADED_FULL_CHARGE, &battery->flags) && | |
593 | + battery->capacity_now > battery->full_charge_capacity) | |
594 | + battery->capacity_now = battery->full_charge_capacity; | |
595 | + | |
578 | 596 | return result; |
579 | 597 | } |
580 | 598 | |
... | ... | @@ -884,6 +902,15 @@ |
884 | 902 | 10000 / battery->design_voltage; |
885 | 903 | } |
886 | 904 | } |
905 | + } | |
906 | + | |
907 | + if (test_bit(ACPI_BATTERY_QUIRK_DEGRADED_FULL_CHARGE, &battery->flags)) | |
908 | + return; | |
909 | + | |
910 | + if (acpi_battery_is_degraded(battery) && | |
911 | + battery->capacity_now > battery->full_charge_capacity) { | |
912 | + set_bit(ACPI_BATTERY_QUIRK_DEGRADED_FULL_CHARGE, &battery->flags); | |
913 | + battery->capacity_now = battery->full_charge_capacity; | |
887 | 914 | } |
888 | 915 | } |
889 | 916 |