Page MenuHomeFreeBSD

Add _BTP method to control method batteries
Needs ReviewPublic

Authored by georg.lindenberg_web.de on Jul 31 2020, 9:18 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Apr 19, 3:58 PM
Unknown Object (File)
Feb 23 2024, 9:48 AM
Unknown Object (File)
Dec 20 2023, 7:17 AM
Unknown Object (File)
Dec 7 2023, 2:25 AM
Unknown Object (File)
Nov 25 2023, 12:21 AM
Unknown Object (File)
Nov 15 2023, 9:29 AM
Unknown Object (File)
Nov 10 2023, 10:20 PM
Unknown Object (File)
Nov 5 2023, 5:12 AM

Details

Reviewers
hrs
takawata
Summary

_BTP is an optional, write-only method in control method batteries.
It allows you to set a warning level (trip point), which will
generate a devd CMBAT event.
If supported, sysctl dev.battery.X.warning_level is created.

Test Plan

acpidump -dt |grep _BTP tells you whether your battery supports this.
I tested it on a Thinkpad x220.
It should be noted that I am fairly new at kernel programming.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 35027
Build 32012: arc lint + arc unit

Event Timeline

Looks good. I have one comment inline.

sys/dev/acpica/acpi_cmbat.c
619

How about allowing 0 to clear trip point ?

For some reason I overlooked that the battery device exists, no matter whether the battery is plugged in or not. E.g. if you unplug the battery after booting, and plug it in again, the sysctl won't care, and display a wrong value. I'll think about this.

sys/dev/acpica/acpi_cmbat.c
619

How about allowing 0 to clear trip point ?

Yes, sounds good.

Updating D25908: Add _BTP method to control method batteries

On device attach, we check for the optional method (_BTP). If it exists,
a sysctl is created, dev.battery.X.warning_level.

Since the battery initialization is mostly done in
acpi_cmbat_init_battery(), which also gets called after resuming from a
sleep state (where the battery can be unplugged), I added code there,
too: acpi_cmbat_btp_set(). This will initially set the warning level to
20%.

A sysctl handler function will change the warning level, if the user
chooses so.

Updating D25908: Add _BTP method to control method batteries

On device attach, we check for the optional method (_BTP). If it exists,
a sysctl is created, dev.battery.X.warning_level.

Since the battery initialization is mostly done in
acpi_cmbat_init_battery(), which also gets called after resuming from a
sleep state (where the battery can be unplugged), I added code there,
too: acpi_cmbat_btp_set(). This will initially set the warning level to
20%.

A sysctl handler function will change the warning level, if the user
chooses so.