acpi/battery: fix wrong value of capacity_now reported by few battery types when fully charged (resend)
PATCH 1/1 acpi/battery: fix wrong value of capacity_now reported by few battery types when fully charged (resend)
It seems that some batteries (noticed on DELL JYPJ136) assume capacity_now = design_capacity when fully charged. This causes reported capacity to suddenly jump to >full_charge_capacity (and that means capacity reported to userspace is >100% and incorrect) values after 99%. This patch attempts to detect this bug and trims capacity_now properly.
---
Oops, I forgot to sign the previous one.
drivers/acpi/battery.c +8 -0
@@ -532,6 +532,14 @@ static int acpi_battery_get_state(struct acpi_battery *battery) " invalid.\n"); } +/* When fully charged, some batteries wrongly report +* capacity_now = design_capacity instead of = full_charge_capacity +*/ +if (battery->capacity_now == battery->design_capacity && + battery->full_charge_capacity !=ACPI_BATTERY_VALUE_UNKNOWN ) + battery->capacity_now = battery->full_charge_capacity; + +if (test_bit (ACPI_BATTERY_QUIRK_PERCENTAGE_CAPACITY , &battery->flags) && battery->capacity_now >=0 && battery->capacity_now <=100 ) battery->capacity_now = (battery->capacity_now *
Quoted 16 lines · Josef Gajdusek
It seems that some batteries (noticed on DELL JYPJ136) assume
capacity_now=design_capacitywhen fully charged. This causes reported capacity to suddenly jump to >full_charge_capacity (and that means capacity reported to userspace is >100% and incorrect) values after 99%. This patch attempts to detect this bug and trimscapacity_nowproperly.Signed-off-by Josef Gajdusek <[email protected]>---
Oops, I forgot to sign the previous one.drivers/acpi/battery.c +0
-0
drivers/acpi/battery.c static int acpi_battery_get_state(struct acpi_battery *battery) · line 538
Quoted 7 lines
drivers/acpi/battery.c +4
-0@@ -532,6 +532,14 @@ static int acpi_battery_get_state(struct acpi_battery *battery) " invalid.\n"); } +/* When fully charged, some batteries wrongly report +* capacity_now = design_capacity instead of = full_charge_capacity +*/ + if (battery->capacity_now == battery->design_capacity &&
Why don't you use the
battery->capacity_now > battery->full_charge_capacity
check here? That would be more robust, wouldn't it?
Quoted 12 lines
drivers/acpi/battery.c +4
-1+ battery->full_charge_capacity != ACPI_BATTERY_VALUE_UNKNOWN) + battery->capacity_now = battery->full_charge_capacity; + +if (test_bit (ACPI_BATTERY_QUIRK_PERCENTAGE_CAPACITY , &battery->flags) && battery->capacity_now >=0 && battery->capacity_now <=100 ) battery->capacity_now = (battery->capacity_now * --To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
It seems that some batteries (noticed on DELL JYPJ136) assume capacity_now = design_capacity when fully charged. This causes reported capacity to suddenly jump to >full_charge_capacity (and that means capacity reported to userspace is >100% and incorrect) values after 99%. This patch attempts to detect this bug, notifies userspace and trims the value to full_charge_capacity.
---
Relaxed the check as you suggested and added printk_once.
Quoted 5 lines
Why don't you use the
battery->capacity_now > battery->full_charge_capacitycheck here? That would be more robust, wouldn't it?
To allow userspace to see that there is some unknown bug we do not know yet with the battery. This is taken care of much more elegantly by the printk now.
drivers/acpi/battery.c +12 -0
@@ -532,6 +532,18 @@ static int acpi_battery_get_state(struct acpi_battery *battery) " invalid.\n"); } +/* When fully charged, some batteries wrongly report +* capacity_now = design_capacity instead of = full_charge_capacity +*/ +if (battery->capacity_now > battery->full_charge_capacity) { + battery->capacity_now = battery->full_charge_capacity; + printk_once(KERN_WARNING FW_BUG +"battery: reported current charge level (%d) " +"is higher than reported maximum charge level (%d)." +"This is normal on some systems.\n" , + battery->capacity_now, battery->full_charge_capacity); + } +if (test_bit (ACPI_BATTERY_QUIRK_PERCENTAGE_CAPACITY , &battery->flags) && battery->capacity_now >=0 && battery->capacity_now <=100 ) battery->capacity_now = (battery->capacity_now *
Quoted 26 lines · Josef Gajdusek
It seems that some batteries (noticed on DELL JYPJ136) assume
capacity_now=design_capacitywhen fully charged. This causes reported capacity to suddenly jump to >full_charge_capacity (and that means capacity reported to userspace is >100% and incorrect) values after 99%. This patch attempts to detect this bug, notifies userspace and trims the value tofull_charge_capacity.Signed-off-by Josef Gajdusek <[email protected]>---
Relaxed the check as you suggested and addedprintk_once.Quoted 5 lines
Why don't you use the
battery->capacity_now > battery->full_charge_capacitycheck here? That would be more robust, wouldn't it?
To allow userspace to see that there is some unknown bug we do not know yet with the battery. This is taken care of much more elegantly by the printk now.
drivers/acpi/battery.c +0
-0
drivers/acpi/battery.c static int acpi_battery_get_state(struct acpi_battery *battery) · line 538
Quoted 7 lines
drivers/acpi/battery.c +4
-0@@ -532,6 +532,18 @@ static int acpi_battery_get_state(struct acpi_battery *battery) " invalid.\n"); } +/* When fully charged, some batteries wrongly report +* capacity_now = design_capacity instead of = full_charge_capacity +*/ +if (battery->capacity_now > battery->full_charge_capacity) {
But it still is necessary to check if battery->full_charge_capacity is not ACPI_BATTERY_VALUE_UNKNOWN, isn't it?
Quoted 11 lines
drivers/acpi/battery.c +8
-0+ battery->capacity_now = battery->full_charge_capacity; + printk_once(KERN_WARNING FW_BUG +"battery: reported current charge level (%d) " +"is higher than reported maximum charge level (%d)." +"This is normal on some systems.\n" , + battery->capacity_now, battery->full_charge_capacity); + } +if (test_bit (ACPI_BATTERY_QUIRK_PERCENTAGE_CAPACITY , &battery->flags) && battery->capacity_now >=0 && battery->capacity_now <=100 ) battery->capacity_now = (battery->capacity_now *
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
It seems that some batteries (noticed on DELL JYPJ136) assume capacity_now = design_capacity when fully charged. This causes reported capacity to suddenly jump to >full_charge_capacity (and that means capacity reported to userspace is >100% and incorrect) values after 99%. This patch attempts to detect this bug, notifies userspace and trims the value to full_charge_capacity.
---
Quoted 4 lines
But it still is necessary to check if
battery->full_charge_capacityis notACPI_BATTERY_VALUE_UNKNOWN, isn't it?
Fixed, my mistake. When changing the checks, I somehow missed that the values are not unsigned.
drivers/acpi/battery.c +13 -0
@@ -532,6 +532,19 @@ static int acpi_battery_get_state(struct acpi_battery *battery) " invalid.\n"); } +/* When fully charged, some batteries wrongly report +* capacity_now = design_capacity instead of = full_charge_capacity +*/ +if (battery->capacity_now > battery->full_charge_capacity && + battery->full_charge_capacity !=ACPI_BATTERY_VALUE_UNKNOWN ) { + battery->capacity_now = battery->full_charge_capacity; + printk_once(KERN_WARNING FW_BUG +"battery: reported current charge level (%d) " +"is higher than reported maximum charge level (%d)." +"This is normal on some systems.\n" , + battery->capacity_now, battery->full_charge_capacity); + } +if (test_bit (ACPI_BATTERY_QUIRK_PERCENTAGE_CAPACITY , &battery->flags) && battery->capacity_now >=0 && battery->capacity_now <=100 ) battery->capacity_now = (battery->capacity_now *
Quoted 22 lines · Josef Gajdusek
It seems that some batteries (noticed on DELL JYPJ136) assume
capacity_now=design_capacitywhen fully charged. This causes reported capacity to suddenly jump to >full_charge_capacity (and that means capacity reported to userspace is >100% and incorrect) values after 99%. This patch attempts to detect this bug, notifies userspace and trims the value tofull_charge_capacity.Signed-off-by Josef Gajdusek <[email protected]>---
Quoted 4 lines
But it still is necessary to check if
battery->full_charge_capacityis notACPI_BATTERY_VALUE_UNKNOWN, isn't it?Fixed, my mistake. When changing the checks, I somehow missed that the values are not unsigned.
drivers/acpi/battery.c +0
-0
drivers/acpi/battery.c static int acpi_battery_get_state(struct acpi_battery *battery) · line 540
Quoted 9 lines
drivers/acpi/battery.c +6
-0@@ -532,6 +532,19 @@ static int acpi_battery_get_state(struct acpi_battery *battery) " invalid.\n"); } +/* When fully charged, some batteries wrongly report +* capacity_now = design_capacity instead of = full_charge_capacity +*/ +if (battery->capacity_now > battery->full_charge_capacity && + battery->full_charge_capacity !=ACPI_BATTERY_VALUE_UNKNOWN ) { + battery->capacity_now = battery->full_charge_capacity;
Thinking more about the printk_once(). Perhaps it only needs to be printed when battery->capacity_now != battery->design_capacity (it's a known issue otherwise).
drivers/acpi/battery.c static int acpi_battery_get_state(struct acpi_battery *battery) · line 544
Quoted 4 lines
drivers/acpi/battery.c +4
-0+ printk_once(KERN_WARNING FW_BUG +"battery: reported current charge level (%d) " +"is higher than reported maximum charge level (%d)." + "This is normal on some systems.\n",
Also I think that the line above doesn't add any real value. :-)
Quoted 11 lines
drivers/acpi/battery.c +3
-1+ battery->capacity_now, battery->full_charge_capacity); + } +if (test_bit (ACPI_BATTERY_QUIRK_PERCENTAGE_CAPACITY , &battery->flags) && battery->capacity_now >=0 && battery->capacity_now <=100 ) battery->capacity_now = (battery->capacity_now * --To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
It seems that some batteries (noticed on DELL JYPJ136) assume capacity_now = design_capacity when fully charged. This causes reported capacity to suddenly jump to >full_charge_capacity (and that means capacity reported to userspace is >100% and incorrect) values after 99%. This patch detects capacity_now > full_charge_capacity, notifies userspace (unless it is the known bug where capacity_now == design_capacity) and trims the value to full_charge_capacity.
---
Quoted 3 lines
Thinking more about the
printk_once(). Perhaps it only needs to be printed whenbattery->capacity_now!=battery->design_capacity(it's a known issue otherwise).
Changed. That was actually what I wanted to do originally, but I was unsure about the kernel policy on this sort of messages.
Quoted 6 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+ printk_once(KERN_WARNING FW_BUG + "battery: reported current charge level (%d) " + "is higher than reported maximum charge level (%d)." + "This is normal on some systems.\n",Also I think that the line above doesn't add any real value. :-)
Removed, now it really is not needed as there is not any known system for which capacity_now > full_charge_capacity && capacity_now != design_capacity would be considered "normal"
drivers/acpi/battery.c +13 -0
@@ -532,6 +532,19 @@ static int acpi_battery_get_state(struct acpi_battery *battery) " invalid.\n"); } +/* When fully charged, some batteries wrongly report +* capacity_now = design_capacity instead of = full_charge_capacity +*/ +if (battery->capacity_now > battery->full_charge_capacity && + battery->full_charge_capacity !=ACPI_BATTERY_VALUE_UNKNOWN ) { + battery->capacity_now = battery->full_charge_capacity; +if (battery->capacity_now != battery->design_capacity) + printk_once(KERN_WARNING FW_BUG +"battery: reported current charge level (%d) " +"is higher than reported maximum charge level (%d).\n" , + battery->capacity_now, battery->full_charge_capacity); + } +if (test_bit (ACPI_BATTERY_QUIRK_PERCENTAGE_CAPACITY , &battery->flags) && battery->capacity_now >=0 && battery->capacity_now <=100 ) battery->capacity_now = (battery->capacity_now *