summaryrefslogtreecommitdiffstats
path: root/drivers/acpi/battery.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi/battery.c')
-rw-r--r--drivers/acpi/battery.c41
1 files changed, 40 insertions, 1 deletions
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 0d7116f34b95..130f513e08c9 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -35,6 +35,7 @@
35#include <linux/delay.h> 35#include <linux/delay.h>
36#include <linux/slab.h> 36#include <linux/slab.h>
37#include <linux/suspend.h> 37#include <linux/suspend.h>
38#include <linux/delay.h>
38#include <asm/unaligned.h> 39#include <asm/unaligned.h>
39 40
40#ifdef CONFIG_ACPI_PROCFS_POWER 41#ifdef CONFIG_ACPI_PROCFS_POWER
@@ -534,6 +535,20 @@ static int acpi_battery_get_state(struct acpi_battery *battery)
534 " invalid.\n"); 535 " invalid.\n");
535 } 536 }
536 537
538 /*
539 * When fully charged, some batteries wrongly report
540 * capacity_now = design_capacity instead of = full_charge_capacity
541 */
542 if (battery->capacity_now > battery->full_charge_capacity
543 && battery->full_charge_capacity != ACPI_BATTERY_VALUE_UNKNOWN) {
544 battery->capacity_now = battery->full_charge_capacity;
545 if (battery->capacity_now != battery->design_capacity)
546 printk_once(KERN_WARNING FW_BUG
547 "battery: reported current charge level (%d) "
548 "is higher than reported maximum charge level (%d).\n",
549 battery->capacity_now, battery->full_charge_capacity);
550 }
551
537 if (test_bit(ACPI_BATTERY_QUIRK_PERCENTAGE_CAPACITY, &battery->flags) 552 if (test_bit(ACPI_BATTERY_QUIRK_PERCENTAGE_CAPACITY, &battery->flags)
538 && battery->capacity_now >= 0 && battery->capacity_now <= 100) 553 && battery->capacity_now >= 0 && battery->capacity_now <= 100)
539 battery->capacity_now = (battery->capacity_now * 554 battery->capacity_now = (battery->capacity_now *
@@ -1151,6 +1166,28 @@ static struct dmi_system_id bat_dmi_table[] = {
1151 {}, 1166 {},
1152}; 1167};
1153 1168
1169/*
1170 * Some machines'(E,G Lenovo Z480) ECs are not stable
1171 * during boot up and this causes battery driver fails to be
1172 * probed due to failure of getting battery information
1173 * from EC sometimes. After several retries, the operation
1174 * may work. So add retry code here and 20ms sleep between
1175 * every retries.
1176 */
1177static int acpi_battery_update_retry(struct acpi_battery *battery)
1178{
1179 int retry, ret;
1180
1181 for (retry = 5; retry; retry--) {
1182 ret = acpi_battery_update(battery, false);
1183 if (!ret)
1184 break;
1185
1186 msleep(20);
1187 }
1188 return ret;
1189}
1190
1154static int acpi_battery_add(struct acpi_device *device) 1191static int acpi_battery_add(struct acpi_device *device)
1155{ 1192{
1156 int result = 0; 1193 int result = 0;
@@ -1169,9 +1206,11 @@ static int acpi_battery_add(struct acpi_device *device)
1169 mutex_init(&battery->sysfs_lock); 1206 mutex_init(&battery->sysfs_lock);
1170 if (acpi_has_method(battery->device->handle, "_BIX")) 1207 if (acpi_has_method(battery->device->handle, "_BIX"))
1171 set_bit(ACPI_BATTERY_XINFO_PRESENT, &battery->flags); 1208 set_bit(ACPI_BATTERY_XINFO_PRESENT, &battery->flags);
1172 result = acpi_battery_update(battery, false); 1209
1210 result = acpi_battery_update_retry(battery);
1173 if (result) 1211 if (result)
1174 goto fail; 1212 goto fail;
1213
1175#ifdef CONFIG_ACPI_PROCFS_POWER 1214#ifdef CONFIG_ACPI_PROCFS_POWER
1176 result = acpi_battery_add_fs(device); 1215 result = acpi_battery_add_fs(device);
1177#endif 1216#endif