power: fix LBC charger FSM, BMS-VM fuel gauge, WCN36xx BMPS, WCD clock gating, and battery UI

This commit is contained in:
Luxferre committed 2026-11-03 12:44:17 +02:00
1 parent ebdb0f8ee2
commit 06d991d4fa
47 files changed
+727 -45

No files matched your search

@@ -2,4 +2,4 @@
level=ERR
[connection]
wifi.powersave=2
wifi.powersave=3
+25 -6
View File
@@ -1,6 +1,8 @@
#!/bin/sh
# Bananarchy kernel and runtime power management optimizations
chmod 0755 / 2>/dev/null || true
# Disable fbcon cursor blinking (eliminates 5 Hz fb_flashcursor + drm_fb_helper_damage_work wakeups)
if [ -w /sys/class/graphics/fbcon/cursor_blink ]; then
echo 0 > /sys/class/graphics/fbcon/cursor_blink 2>/dev/null || true
@@ -29,16 +31,33 @@ for pm_dev in /sys/devices/platform/soc@0/1c00000.gpu /sys/devices/platform/soc@
fi
done
# Tune CPUFreq schedutil governor for rapid downclocking to 200 MHz at idle
# (qcom-cpufreq reports transition_latency=UINT_MAX, causing schedutil rate_limit_us
# to default to 6442450 us = 6.44s without this override)
# Tune CPUFreq schedutil governor to avoid 22 Hz frequency/RPM voltage thrashing at idle
# while keeping interactive ramp-up responsive. Allow video group (dwm/xlocker) to switch
# scaling_governor to powersave (200 MHz) while the screen is off.
for gov_dir in /sys/devices/system/cpu/cpufreq/schedutil /sys/devices/system/cpu/cpufreq/policy*/schedutil /sys/devices/system/cpu/cpu*/cpufreq/schedutil; do
if [ -d "$gov_dir" ]; then
{ echo 2000 > "$gov_dir/rate_limit_us"; } 2>/dev/null || true
{ echo 20000 > "$gov_dir/up_rate_limit_us"; } 2>/dev/null || true
{ echo 1000 > "$gov_dir/down_rate_limit_us"; } 2>/dev/null || true
{ echo 40000 > "$gov_dir/rate_limit_us"; } 2>/dev/null || true
{ echo 40000 > "$gov_dir/up_rate_limit_us"; } 2>/dev/null || true
{ echo 10000 > "$gov_dir/down_rate_limit_us"; } 2>/dev/null || true
fi
done
for gov_file in /sys/devices/system/cpu/cpufreq/policy*/scaling_governor /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do
if [ -e "$gov_file" ]; then
chgrp video "$gov_file" 2>/dev/null || true
chmod 0664 "$gov_file" 2>/dev/null || true
fi
done
# Ensure rootfs pm8916_lbc and pm8916_bms_vm modules are active if initramfs loaded an older build
if [ -r /sys/class/power_supply/pm8916-lbc-chgr/constant_charge_current ]; then
_chg_cur=0
read -r _chg_cur < /sys/class/power_supply/pm8916-lbc-chgr/constant_charge_current 2>/dev/null || _chg_cur=0
if [ "${_chg_cur:-0}" -lt 500000 ] 2>/dev/null; then
modprobe -r pm8916_bms_vm pm8916_lbc 2>/dev/null || true
modprobe pm8916_lbc 2>/dev/null || true
modprobe pm8916_bms_vm 2>/dev/null || true
fi
fi
# Enable IEEE 802.11 power save on WCN3620 wlan0
if command -v iw >/dev/null 2>&1; then
@@ -1,2 +1,3 @@
SUBSYSTEM=="leds", ACTION=="add", RUN+="/bin/chgrp video /sys/class/leds/%k/brightness", RUN+="/bin/chmod 0664 /sys/class/leds/%k/brightness"
SUBSYSTEM=="backlight", ACTION=="add", RUN+="/bin/chgrp video /sys/class/backlight/%k/brightness /sys/class/backlight/%k/bl_power", RUN+="/bin/chmod 0664 /sys/class/backlight/%k/brightness /sys/class/backlight/%k/bl_power"
SUBSYSTEM=="cpu", ACTION=="add", RUN+="/bin/chgrp video /sys/devices/system/cpu/cpufreq/policy0/scaling_governor /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor", RUN+="/bin/chmod 0664 /sys/devices/system/cpu/cpufreq/policy0/scaling_governor /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor"
@@ -53,6 +53,7 @@ unset WAYLAND_DISPLAY
unset SWAYSOCK
mkdir -p "$XDG_RUNTIME_DIR" "$XDG_CACHE_HOME/sxmo" "$XDG_CONFIG_HOME/sxmo"
rm -f "$XDG_RUNTIME_DIR/sxmo.led.lock" "$XDG_RUNTIME_DIR"/sxmo_bat_state_* 2>/dev/null || true
touch "$XDG_CACHE_HOME/sxmo/sxmo.noidle" "$XDG_CACHE_HOME/sxmo/sxmo.nosuspend"
[ -n "${DBUS_SESSION_BUS_ADDRESS:-}" ] && printf "%s\n" "$DBUS_SESSION_BUS_ADDRESS" > "$XDG_RUNTIME_DIR/dbus.bus"
printf "unlock\n" > "$XDG_RUNTIME_DIR/sxmo.state"
Binary file not shown.
+1 -4
View File
@@ -70,11 +70,8 @@ mainloop() {
fi
while : ; do
if [ "$(cat /tmp/sxmo_dsds_active 2>/dev/null || echo 0)" = "1" ]; then
if doas -n true 2>/dev/null; then
doas -n /usr/libexec/msm-modem-uim-selection dsds-daemon 2>/dev/null || true
else
doas -n /usr/libexec/msm-modem-uim-selection dsds-daemon 2>/dev/null || \
/usr/libexec/msm-modem-uim-selection dsds-daemon 2>/dev/null || true
fi
sleep 10
else
sleep 120
+10
View File
@@ -49,9 +49,19 @@ xorgdisplay() {
if [ -w /sys/class/backlight/backlight/bl_power ]; then
printf '4\n' > /sys/class/backlight/backlight/bl_power 2>/dev/null || true
fi
if [ -w /sys/devices/system/cpu/cpufreq/policy0/scaling_governor ]; then
printf 'powersave\n' > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor 2>/dev/null || true
fi
pkill -STOP -x conky 2>/dev/null || true
xset s off s noblank >/dev/null 2>&1 || true
;;
on)
if [ -w /sys/devices/system/cpu/cpufreq/policy0/scaling_governor ]; then
printf 'schedutil\n' > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor 2>/dev/null || true
fi
if [ ! -f /tmp/bananarchy_screen_locked ]; then
pkill -CONT -x conky 2>/dev/null || true
fi
xset s off s noblank >/dev/null 2>&1 || true
if [ -w /sys/class/backlight/backlight/bl_power ]; then
printf '0\n' > /sys/class/backlight/backlight/bl_power 2>/dev/null || true
Binary file not shown.
@@ -747,6 +747,7 @@ mount_root_partition() {
splash_set_error "Unable to mount root partition\nhttps://postmarketos.org/troubleshooting"
fail_halt_boot
fi
chmod 0755 /sysroot 2>/dev/null || true
if [ -e /sysroot/.stowaways/pmos/etc/os-release ]; then
umount /sysroot
@@ -5,7 +5,14 @@ export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/10000}"
export DISPLAY="${DISPLAY:-:0}"
export PATH="/usr/share/sxmo/default_hooks:/usr/bin:/bin:/usr/sbin:/sbin:$PATH"
if [ "$(id -u)" = "0" ]; then
chmod 0755 / 2>/dev/null || true
rm -rf "$XDG_RUNTIME_DIR/sxmo.led.lock" 2>/dev/null || true
exec /bin/su -s /bin/sh user -c 'HOME=/home/user DISPLAY="$1" XDG_RUNTIME_DIR="$2" shift 2; exec "$@"' -- "$DISPLAY" "$XDG_RUNTIME_DIR" "$0" "$@"
fi
SET_LED_PATH="$XDG_RUNTIME_DIR/sxmo_hook_battery_set_led"
FORCE_UPDATE=0
if [ "${1:-}" = "udev" ]; then
object="/org/freedesktop/UPower/devices/battery_default"
@@ -13,6 +20,10 @@ if [ "${1:-}" = "udev" ]; then
if [ "${2:-}" != "recheck" ]; then
(sleep 2; "$0" udev recheck >/dev/null 2>&1) &
fi
elif [ "${1:-}" = "force" ]; then
FORCE_UPDATE=1
object="/org/freedesktop/UPower/devices/battery_default"
event="device changed"
else
object="${1:-/org/freedesktop/UPower/devices/battery_default}"
event="${2:-device changed}"
@@ -109,15 +120,22 @@ fi
CACHE_FILE="${XDG_RUNTIME_DIR:-/tmp}/sxmo_bat_state_${name}"
ICON_FILE="${XDG_RUNTIME_DIR:-/run/user/10000}/sxmo_status/${SXMO_STATUS_NAME:-default}/040-battery-icon-${name}"
NEW_VAL="${state}:${percentage}"
if [ -r "$CACHE_FILE" ] && [ -f "$ICON_FILE" ]; then
if [ "$FORCE_UPDATE" != "1" ] && [ -r "$CACHE_FILE" ] && [ -f "$ICON_FILE" ]; then
OLD_VAL=""
read -r OLD_VAL < "$CACHE_FILE" 2>/dev/null || true
if [ "$OLD_VAL" = "$NEW_VAL" ]; then
exit 0
fi
fi
printf '%s\n' "$NEW_VAL" > "$CACHE_FILE"
chown 10000:10000 "$CACHE_FILE" 2>/dev/null || true
printf '%s\n' "$NEW_VAL" > "$CACHE_FILE" 2>/dev/null || {
rm -f "$CACHE_FILE" 2>/dev/null || true
printf '%s\n' "$NEW_VAL" > "$CACHE_FILE" 2>/dev/null || true
}
if [ "$(id -u)" = "0" ]; then
chown 10000:10000 "$CACHE_FILE" "$SET_LED_PATH" "${XDG_RUNTIME_DIR:-/run/user/10000}/sxmo.led.lock" 2>/dev/null || true
fi
sxmo_hook_statusbar.sh battery "$name" "$state" "$percentage"
chown -R 10000:10000 "${XDG_RUNTIME_DIR:-/run/user/10000}/sxmo_status" 2>/dev/null || true
if [ "$(id -u)" = "0" ]; then
chown -R 10000:10000 "${XDG_RUNTIME_DIR:-/run/user/10000}/sxmo_status" 2>/dev/null || true
fi
@@ -520,7 +520,6 @@ case "$1" in
set_network "$@"
;;
battery)
is_screen_dark && exit 0
shift
set_battery "$@"
;;
@@ -544,7 +543,7 @@ case "$1" in
set_modem
fi
set_network wifi wlan0
sxmo_hook_battery.sh 2>/dev/null || true
sxmo_hook_battery.sh force 2>/dev/null || true
fi
;;
periodics) # 60 s loop
@@ -575,7 +574,7 @@ case "$1" in
set_notifications
set_notch
set_network wifi wlan0
sxmo_hook_battery.sh 2>/dev/null || true
sxmo_hook_battery.sh force 2>/dev/null || true
;;
*)
exit # swallow it !