rules: add battery charge limit udev and hwdb files

Set per battery-specific start/stop charge limits in udev as environment
variable with the option to allow a user to override the default 60%
start and 80% stop charge limit.

Signed-off-by: Kate Hsuan <hpa@redhat.com>
This commit is contained in:
Jelle van der Waa 2024-07-22 18:40:03 +08:00 committed by Kate Hsuan
parent 669a1c2a27
commit 16277c88c4
3 changed files with 39 additions and 0 deletions

View file

@ -0,0 +1,30 @@
# This file is part of upower.
#
# The lookup keys are composed in:
# 60-upower-battery.rules
#
# Match string format:
# battery:<kernel>:<model_name>:dmi:<dmi pattern>
#
# The kernel is the name of battery in /sys/class/power_supply for
# differentiating between multiple batteries.
#
# The model_name is battery model name in for example
# /sys/class/power_supply/BAT0/model_name.
#
# The full DMI string of the running machine can be read from
# /sys/class/dmi/id/modalias
# That requires a kernel built with CONFIG_DMIID set, which is common.
# The full DMI string is not needed here and the meaning of individual parts
# can be seen in the source of the DMIID kernel module
# https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/firmware/dmi-id.c
#
# To add local overrides, create a new file
# /etc/udev/hwdb.d/61-battery-local.hwdb
# and add your rules there. To load the new rules execute (as root):
# systemd-hwdb update
# udevadm trigger -v -p /sys/class/power_supply/BAT
# where BAT is the battery in question.
battery:*:*:dmi:*
CHARGE_LIMIT=60,80

View file

@ -0,0 +1,7 @@
ACTION=="remove", GOTO="battery_end"
SUBSYSTEM=="power_supply",ATTR{charge_control_start_threshold}!="" \
IMPORT{builtin}="hwdb 'battery:$kernel:$attr{model_name}:$attr{[dmi/id]modalias}'", \
GOTO="battery_end"
LABEL="battery_end"

View file

@ -1,10 +1,12 @@
rules = [
'60-upower-battery.rules',
'95-upower-wup.rules',
'95-upower-hid.rules',
]
hwdb = [
'95-upower-hid.hwdb',
'60-upower-battery.hwdb',
]
if os_backend == 'linux'