public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ACPI: battery: add state_of_health support to power_supply
@ 2026-04-23  7:58 luoxueqin
  2026-04-24  1:22 ` Sebastian Reichel
  0 siblings, 1 reply; 2+ messages in thread
From: luoxueqin @ 2026-04-23  7:58 UTC (permalink / raw)
  To: lenb, linux-acpi, linux-kernel; +Cc: Xueqin Luo

From: Xueqin Luo <luoxueqin@kylinos.cn>

Add support for POWER_SUPPLY_PROP_STATE_OF_HEALTH in ACPI battery
driver.

State of Health is calculated as the ratio between full charge capacity
and design capacity, expressed as a percentage.

The value is computed as:
    SOH = full_charge_capacity * 100 / design_capacity

Only valid ACPI battery capacity values are used for the calculation.
If either full charge capacity or design capacity is not available,
the property returns -ENODEV.

Signed-off-by: Xueqin Luo <luoxueqin@kylinos.cn>
---
 drivers/acpi/battery.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index b4c25474f42f..6e6396aad2c8 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -267,6 +267,15 @@ static int acpi_battery_get_property(struct power_supply *psy,
 		else
 			val->intval = battery->full_charge_capacity * 1000;
 		break;
+	case POWER_SUPPLY_PROP_STATE_OF_HEALTH:
+		if (!ACPI_BATTERY_CAPACITY_VALID(battery->full_charge_capacity) ||
+		    !ACPI_BATTERY_CAPACITY_VALID(battery->design_capacity))
+			return -ENODEV;
+
+		full_capacity = battery->full_charge_capacity;
+		val->intval = DIV_ROUND_CLOSEST_ULL(full_capacity * 100ULL,
+					battery->design_capacity);
+		break;
 	case POWER_SUPPLY_PROP_CHARGE_NOW:
 	case POWER_SUPPLY_PROP_ENERGY_NOW:
 		if (battery->capacity_now == ACPI_BATTERY_VALUE_UNKNOWN)
@@ -323,6 +332,7 @@ static const enum power_supply_property charge_battery_props[] = {
 	POWER_SUPPLY_PROP_CURRENT_NOW,
 	POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
 	POWER_SUPPLY_PROP_CHARGE_FULL,
+	POWER_SUPPLY_PROP_STATE_OF_HEALTH,
 	POWER_SUPPLY_PROP_CHARGE_NOW,
 	POWER_SUPPLY_PROP_CAPACITY,
 	POWER_SUPPLY_PROP_CAPACITY_LEVEL,
@@ -355,6 +365,7 @@ static const enum power_supply_property energy_battery_props[] = {
 	POWER_SUPPLY_PROP_POWER_NOW,
 	POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN,
 	POWER_SUPPLY_PROP_ENERGY_FULL,
+	POWER_SUPPLY_PROP_STATE_OF_HEALTH,
 	POWER_SUPPLY_PROP_ENERGY_NOW,
 	POWER_SUPPLY_PROP_CAPACITY,
 	POWER_SUPPLY_PROP_CAPACITY_LEVEL,
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ACPI: battery: add state_of_health support to power_supply
  2026-04-23  7:58 [PATCH] ACPI: battery: add state_of_health support to power_supply luoxueqin
@ 2026-04-24  1:22 ` Sebastian Reichel
  0 siblings, 0 replies; 2+ messages in thread
From: Sebastian Reichel @ 2026-04-24  1:22 UTC (permalink / raw)
  To: luoxueqin; +Cc: lenb, linux-acpi, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1434 bytes --]

Hi,

On Thu, Apr 23, 2026 at 03:58:53PM +0800, luoxueqin wrote:
> From: Xueqin Luo <luoxueqin@kylinos.cn>
> 
> Add support for POWER_SUPPLY_PROP_STATE_OF_HEALTH in ACPI battery
> driver.
> 
> State of Health is calculated as the ratio between full charge capacity
> and design capacity, expressed as a percentage.
> 
> The value is computed as:
>     SOH = full_charge_capacity * 100 / design_capacity

$ grep -A15 state_of_health Documentation/ABI/testing/sysfs-class-power
What:		/sys/class/power_supply/<supply_name>/state_of_health
Date:		August 2025
Contact:	linux-arm-msm@vger.kernel.org
Description:
		The state_of_health parameter quantifies the overall condition
		of a battery as a percentage, reflecting its ability to deliver
		rated performance relative to its original specifications. It is
		dynamically computed using a combination of learned capacity
		and impedance-based degradation indicators, both of which evolve
		over the battery's lifecycle.
		Note that the exact algorithms are kept secret by most battery
		vendors and the value from different battery vendors cannot be
		compared with each other as there is no vendor-agnostic definition
		of "performance". Also this usually cannot be used for any
		calculations (i.e. this is not the factor between charge_full and
		charge_full_design).

		Access: Read

		Valid values: 0 - 100 (percent)

Greetings,

-- Sebastian

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-04-24  1:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-23  7:58 [PATCH] ACPI: battery: add state_of_health support to power_supply luoxueqin
2026-04-24  1:22 ` Sebastian Reichel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox