Battery charge control thresholds in sysfs

Currently we have an option to set the battery charge limit in BIOS. However, that setting is not propagated to the kernel and thus is not visible to the userspace.

For example my KDE battery applet still shows the battery as charging even when upper limit is reached. Also, it incorrectly calculates the battery wear.

I suppose this happens because kernel does not provide the information in sysfs:

+++ Battery Status: BAT1
/sys/class/power_supply/BAT1/manufacturer                   = NVT
/sys/class/power_supply/BAT1/model_name                     = Framewo
/sys/class/power_supply/BAT1/cycle_count                    =    126
/sys/class/power_supply/BAT1/charge_full_design             =   3572 [mAh]
/sys/class/power_supply/BAT1/charge_full                    =   3208 [mAh]
/sys/class/power_supply/BAT1/charge_now                     =   2304 [mAh]
/sys/class/power_supply/BAT1/current_now                    =    346 [mA]
/sys/class/power_supply/BAT1/status                         = Discharging

/sys/class/power_supply/BAT1/charge_control_start_threshold = (not available) 
/sys/class/power_supply/BAT1/charge_control_end_threshold   = (not available) 

Charge                                                      =   71.8 [%]
Capacity                                                    =   89.8 [%]

Note the missing thresholds and charge limit (90%) mistakenly treated as actual capacity.

Any ideas on what needs to be done to support that in the kernel? My understanding is thath it could be supported, since overall battery info is detected and is more or less accurate.


charge_now?/ charge_full* 100 = 71.8%

charge_full_design/charge_full *100 = 89.7%

Question:: charge_full_design = 3572 [mAh] as design is 5500 [mAh]

Different units. Design voltage is 15.4V, so
3572 mAh * 15.4V = 55.0 Wh (which is the design capacity of the battery)

1 Like

Yes :blush: that should have been 5500mWh

So, exposing the charge threshold in sysfs is something I’m working on. The limit is mediated by the EC, and exposing it in sysfs requires the installation of a battery “extension” (it’s a kernel interface that allows one driver to add sysfs entries to an ACPI battery node owned by another driver.)

I’m planning on seeking upstream approval for this patch soon. For now, though, some teasers:

(rigel) ~ % ls /sys/class/power_supply/BAT1 
alarm           charge_full_design  device        power          subsystem   voltage_min_design
capacity        charge_now          hwmon2        present        technology  voltage_now
capacity_level  current_now         manufacturer  serial_number  type
charge_full     cycle_count         model_name    status         uevent

(rigel) ~ % sudo modprobe framework_acpi

(rigel) ~ % sudo dmesg | tail -n 1
[159509.633091] ACPI: battery: new extension: Framework Laptop Battery Extension

(rigel) ~ % ls /sys/class/power_supply/BAT1/charge_control_end_threshold 

(rigel) ~ % cat /sys/class/power_supply/BAT1/charge_control_end_threshold

(rigel) ~ % echo 80 | sudo tee /sys/class/power_supply/BAT1/charge_control_end_threshold


Does charge_full/charge_full_design represent true battery wear? I’ve been using an 11th-gen laptop for 5 months and have battery charge capped at 80%. 10% wear seems too high.

[fw ~]$ cd /sys/class/power_supply/BAT1
[fw BAT1]$ cat charge_full charge_full_design charge_now

Also cycle_count reports zero. But I guess that’s because I haven’t been using any battery manager so the kernel doesn’t know.

Hi @DHowett.

Have you got any further with your efforts to expose the battery charge limit setting to OS control?


Been wondering about it as well. My old-ish huawei laptop exposed those entries just fine, but the AMD framework does not - a pity. I actually used to change those depending on my use case, rebooting to BIOS is rather inconvenient, not to mention only the max charge can be changed.

You can change these with the ectool from userspace from memory (which requires david’s currently out of tree patch to support the amdfw)

Thanks for the heads up, but that’s still a workaround for me. I do use the console, but I’d like to make use of Plasma’s powerdevil / activity profiles, which means GUI. Sadly, that only works if charge_control_start_threshold and charge_control_end_threshold are exposed…