Skip to contentSkip to conversation

acpi: battery: Accept charges over the design capacity as full

PATCH Applied André Almeida 4 participants 5 messages Oct 8, 2021 – Oct 13, 2021 ACPI

lore
Share & tools
lore
#0 lore raw

cover acpi: battery: Accept charges over the design capacity as full

Hi,

We have come across a battery that, when brand new, can go above the reported maximum charge, leading to reports like this:

$ cat /sys/class/power_supply/BAT1/uevent

POWER_SUPPLY_NAME=BAT1
POWER_SUPPLY_TYPE=Battery
POWER_SUPPLY_STATUS=Unknown
POWER_SUPPLY_PRESENT=1
POWER_SUPPLY_CHARGE_FULL_DESIGN=4160000
POWER_SUPPLY_CHARGE_FULL=4538000
POWER_SUPPLY_CHARGE_NOW=4539000
POWER_SUPPLY_CAPACITY=100
POWER_SUPPLY_CAPACITY_LEVEL=Full
[...]

And then userspace get confused by Unknown and some programs even say "Charging: 100%". After applying this patch, kernel reports "Full", which for practical reasons is true, even if the battery will charge a bit more. After some time, the battery health degrades and the maximum charge meets the design expectation. Ideally this would be fixed in the battery firmware, but it's not always possible to do that.

André Almeida (1):
acpi: battery: Accept charges over the design capacity as full

 drivers/acpi/battery.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Signature · 1 line
2.33.0
#1 lore raw

PATCH 1/1 acpi: battery: Accept charges over the design capacity as full

Some buggy firmware and/or brand new batteries can support a charge that's slightly over the reported design capacity. In such cases, the kernel will report to userspace that the charging state of the battery is "Unknown", when in reality the battery charge is "Full", at least from the design capacity point of view. Make the fallback condition accepts capacities over the designed capacity so userspace knows that is full.

---
 drivers/acpi/battery.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/battery.c +1 -1
index dae91f906cea..8afa85d6eb6a 100644
@@ -169,7 +169,7 @@ static int acpi_battery_is_charged(struct acpi_battery *battery)
 		return 1;
 
 	/* fallback to using design values for broken batteries */
-	if (battery->design_capacity == battery->capacity_now)
+	if (battery->design_capacity <= battery->capacity_now)
 		return 1;
 
 	/* we don't do any sort of metric based on percentages */
Signature · 1 line
2.33.0
Reviewed-by on v1 1/1
#2 lore raw

Hi,

Quoted 8 lines · André Almeida

Some buggy firmware and/or brand new batteries can support a charge that's slightly over the reported design capacity. In such cases, the kernel will report to userspace that the charging state of the battery is "Unknown", when in reality the battery charge is "Full", at least from the design capacity point of view. Make the fallback condition accepts capacities over the designed capacity so userspace knows that is full.

Thanks, patch looks good to me:

Regards,

Hans

Quoted 18 lines
---
 drivers/acpi/battery.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/battery.c +1 -1
index dae91f906cea..8afa85d6eb6a 100644
@@ -169,7 +169,7 @@ static int acpi_battery_is_charged(struct acpi_battery *battery)
 		return 1;
 
 	/* fallback to using design values for broken batteries */
-	if (battery->design_capacity == battery->capacity_now)
+	if (battery->design_capacity <= battery->capacity_now)
 		return 1;
 
 	/* we don't do any sort of metric based on percentages */
Reviewed-by on v1 1/1
#3 lore raw
In reply to André Almeida

Hi,

Quoted 17 lines · André Almeida

Some buggy firmware and/or brand new batteries can support a charge that's slightly over the reported design capacity. In such cases, the kernel will report to userspace that the charging state of the battery is "Unknown", when in reality the battery charge is "Full", at least from the design capacity point of view. Make the fallback condition accepts capacities over the designed capacity so userspace knows that is full.

---
 drivers/acpi/battery.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/battery.c +0 -0
index dae91f906cea..8afa85d6eb6a 100644

drivers/acpi/battery.c static int acpi_battery_is_charged(struct acpi_battery *battery) · line 175

Quoted 8 lines
drivers/acpi/battery.c +1 -1
@@ -169,7 +169,7 @@ static int acpi_battery_is_charged(struct acpi_battery *battery)
 		return 1;
 
 	/* fallback to using design values for broken batteries */
-	if (battery->design_capacity == battery->capacity_now)
+	if (battery->design_capacity <= battery->capacity_now)
 		return 1;
 
 	/* we don't do any sort of metric based on percentages */

-- Sebastian

maintainer Applied
#4 lore raw
Quoted 23 lines · Sebastian Reichel

Hi,

Quoted 19 lines · André Almeida

Some buggy firmware and/or brand new batteries can support a charge that's slightly over the reported design capacity. In such cases, the kernel will report to userspace that the charging state of the battery is "Unknown", when in reality the battery charge is "Full", at least from the design capacity point of view. Make the fallback condition accepts capacities over the designed capacity so userspace knows that is full.

---
 drivers/acpi/battery.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/battery.c +0 -0
index dae91f906cea..8afa85d6eb6a 100644
@@ -169,7 +169,7 @@ static int acpi_battery_is_charged(struct acpi_battery *battery)
              return 1;
 
Quoted 8 lines

drivers/acpi/battery.c static int acpi_battery_is_charged(struct acpi_battery *battery) · line 175

Quoted 6 lines
drivers/acpi/battery.c +1 -1
      /* fallback to using design values for broken batteries */
-     if (battery->design_capacity == battery->capacity_now)
+     if (battery->design_capacity <= battery->capacity_now)
              return 1;
 
      /* we don't do any sort of metric based on percentages */

Applied as 5.16 material, thanks!