VM-BMS sanity fix and configurable runtime power policies
Kernel (source-only, ABI-preserving, patch 0007): - pm8916_bms_vm.c: bound VADC raw samples to 8000..16000 (~2.34-4.69 V) with a 3.7 V nominal fallback in raw_to_uv(); reject out-of-window FIFO samples in the IRQ handler and probe pre-read. Fixes the 19.2 V / "Over voltage" / 100% misreport from an uninitialised 0xffff sample after a hard reset (also covers the OCV register reads on probe/resume). - wcn36xx: listen_interval becomes a module parameter (1-10, default 5, was hardcoded 3) so the beacon skip is configurable at module load. Runtime power policy (/etc/bananarchy-power-policy.conf): - WIFI_LISTEN_INTERVAL drives /etc/modprobe.d/10-bananarchy-power.conf. - MODEM_DRX_MODE (0 or 6-9) applies Qualcomm AT$QCDRX at boot and on wake. Standard AT+CPSMS / AT+CEDRXS are unsupported on this modem firmware. - DSDS_SECONDARY_MODE=eco parks the secondary GW provisioning session after DSDS_PARK_DELAY seconds of a dark panel and restores it on wake, capturing the actual slot and AID. Uses QMI provisioning sessions, not SIM power-off (which clears PIN verification). Default active keeps both SIMs reachable. - New bananarchy-power-policy.sh, OpenRC default-runlevel service, doas rule, and hooks in sxmo_wm.sh display off/on. Live-verified on nokia-argon: DRX 6 readback, eco park/unpark round-trip, Wi-Fi param 5, status output, module vermagic match, both SIMs registered. Rebuilt image with --mkinitfs: initramfs and rootfs carry the new modules (SHA-256 match), boot.img keeps the byte-identical known-good zImage + DTB. Docs updated (BATTERY-OPTIMIZATION-ANALYSIS.md section 15, CHANGELOG, MANUAL, README, AGENTS).
This commit is contained in:
1 parent
b5a1e0c5f9
commit
bc1c19a483
20 files changed
+470
-2
No files matched your search
@@ -0,0 +1,24 @@
|
||||
# Bananarchy runtime power policy. Read by bananarchy-power-policy.sh.
|
||||
# Edit as root, then run: doas /usr/bin/bananarchy-power-policy.sh apply
|
||||
# (or reboot). Every knob is deliberately conservative by default.
|
||||
|
||||
# wcn36xx beacon listen interval (1-10). Higher values cut idle Wi-Fi RX
|
||||
# wakeups but delay inbound packets. 0 removes the module option and uses
|
||||
# the driver default. Applied at module load, so changes need a reboot or
|
||||
# a wcn36xx module reload.
|
||||
WIFI_LISTEN_INTERVAL=5
|
||||
|
||||
# Qualcomm modem DRX mode via AT$QCDRX (0, 6-9). 0 = firmware default, no
|
||||
# policy. 6-9 = progressively longer paging cycles: lower modem idle
|
||||
# current, longer call/SMS setup latency. Values above 6 are undocumented
|
||||
# on this firmware; 9 made the AT channel briefly unresponsive in testing.
|
||||
MODEM_DRX_MODE=0
|
||||
|
||||
# Secondary SIM (DSDS) policy while the panel is dark:
|
||||
# active = keep both subscriptions provisioned (default)
|
||||
# eco = deactivate the secondary GW provisioning session after
|
||||
# DSDS_PARK_DELAY seconds of darkness, and reactivate it on wake.
|
||||
# SIM2 is unreachable while parked. This uses QMI provisioning
|
||||
# sessions, not SIM power-off, so a PIN-locked SIM stays locked.
|
||||
DSDS_SECONDARY_MODE=active
|
||||
DSDS_PARK_DELAY=300
|
||||
@@ -52,6 +52,8 @@ permit nopass :wheel as root cmd bananarchy-bt-obex
|
||||
permit nopass :wheel as root cmd /usr/bin/bananarchy-privacy-ctl
|
||||
permit nopass :wheel as root cmd bananarchy-privacy-ctl
|
||||
permit nopass :wheel as root cmd /usr/bin/bananarchy-display-power-sync
|
||||
permit nopass :wheel as root cmd /usr/bin/bananarchy-power-policy.sh
|
||||
permit nopass :wheel as root cmd bananarchy-power-policy.sh
|
||||
permit nopass :wheel as root cmd bananarchy-display-power-sync
|
||||
permit nopass :wheel as root cmd /usr/bin/plymouth args quit
|
||||
permit nopass :wheel as root cmd plymouth args quit
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
#!/sbin/openrc-run
|
||||
|
||||
name="Bananarchy power policy"
|
||||
description="Apply Wi-Fi, modem DRX and DSDS runtime power policy"
|
||||
|
||||
depend() {
|
||||
need rmtfs
|
||||
after modemmanager msm-modem-uim-selection msm8909-modem-wwan-port
|
||||
}
|
||||
|
||||
start() {
|
||||
ebegin "Applying Bananarchy power policy"
|
||||
/usr/bin/bananarchy-power-policy.sh boot >/dev/null 2>&1 || true
|
||||
eend 0
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
# Generated by bananarchy-power-policy.sh from /etc/bananarchy-power-policy.conf
|
||||
options wcn36xx listen_interval=5
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
+177
@@ -0,0 +1,177 @@
|
||||
#!/bin/sh
|
||||
# Bananarchy runtime power policy: Wi-Fi listen interval, modem DRX, DSDS.
|
||||
# Runs as root; re-execs through doas -n when called from the X session.
|
||||
set -u
|
||||
|
||||
CONF=/etc/bananarchy-power-policy.conf
|
||||
MODPROBE=/etc/modprobe.d/10-bananarchy-power.conf
|
||||
RUNDIR=/run/bananarchy-power-policy
|
||||
PARKED="$RUNDIR/parked"
|
||||
AIDFILE="$RUNDIR/secondary.aid"
|
||||
SLOTFILE="$RUNDIR/secondary.slot"
|
||||
TOKEN="$RUNDIR/token"
|
||||
QMI="timeout 8 qmicli --silent -pd qrtr://0"
|
||||
|
||||
if [ "$(id -u)" != "0" ]; then
|
||||
exec doas -n "$0" "$@"
|
||||
fi
|
||||
|
||||
WIFI_LISTEN_INTERVAL=5
|
||||
MODEM_DRX_MODE=0
|
||||
DSDS_SECONDARY_MODE=active
|
||||
DSDS_PARK_DELAY=300
|
||||
[ -r "$CONF" ] && . "$CONF"
|
||||
|
||||
mkdir -p "$RUNDIR" 2>/dev/null || true
|
||||
|
||||
log() {
|
||||
printf 'bananarchy-power-policy: %s\n' "$*" >&2
|
||||
}
|
||||
|
||||
write_modprobe() {
|
||||
n="$WIFI_LISTEN_INTERVAL"
|
||||
case "$n" in ''|*[!0-9]*) n=0 ;; esac
|
||||
if [ "$n" -lt 1 ] || [ "$n" -gt 10 ]; then
|
||||
n=0
|
||||
fi
|
||||
if [ "$n" = "0" ]; then
|
||||
rm -f "$MODPROBE" 2>/dev/null || true
|
||||
return 0
|
||||
fi
|
||||
mkdir -p "$(dirname "$MODPROBE")" 2>/dev/null || true
|
||||
printf '# Generated by bananarchy-power-policy.sh from %s\n' "$CONF" > "$MODPROBE" || return 1
|
||||
printf 'options wcn36xx listen_interval=%s\n' "$n" >> "$MODPROBE" || return 1
|
||||
}
|
||||
|
||||
apply_modem_drx() {
|
||||
case "$MODEM_DRX_MODE" in
|
||||
0) return 0 ;;
|
||||
6|7|8|9) ;;
|
||||
*)
|
||||
log "invalid MODEM_DRX_MODE=$MODEM_DRX_MODE (use 0 or 6-9)"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
[ -c /dev/wwan0at0 ] || {
|
||||
log "no modem AT port"
|
||||
return 1
|
||||
}
|
||||
out="$(timeout 6 /usr/libexec/msm-modem-uim-selection at auto "AT\$QCDRX=$MODEM_DRX_MODE" 2>/dev/null || true)"
|
||||
case "$out" in
|
||||
*OK*) return 0 ;;
|
||||
*)
|
||||
log "AT\$QCDRX=$MODEM_DRX_MODE failed: $out"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
secondary_aid() {
|
||||
$QMI --uim-get-card-status 2>/dev/null | awk '
|
||||
/Slot \[2\]/ { s=1; next }
|
||||
s && /^Slot \[/ { exit }
|
||||
s && /Application ID:/ { g=1; next }
|
||||
s && g && NF { gsub(/^[ \t]+/, ""); print; exit }
|
||||
'
|
||||
}
|
||||
|
||||
secondary_slot() {
|
||||
$QMI --uim-get-card-status 2>/dev/null | awk '
|
||||
/Secondary GW: slot/ {
|
||||
for (i = 1; i <= NF; i++)
|
||||
if ($i == "slot") { gsub(/[^0-9]/, "", $(i+1)); print $(i+1); exit }
|
||||
}
|
||||
'
|
||||
}
|
||||
|
||||
park() {
|
||||
[ -f "$PARKED" ] && return 0
|
||||
aid="$(secondary_aid)"
|
||||
slot="$(secondary_slot)"
|
||||
[ -n "$aid" ] && [ -n "$slot" ] || {
|
||||
log "cannot read secondary SIM AID/slot"
|
||||
return 1
|
||||
}
|
||||
if $QMI --uim-change-provisioning-session='activate=no,session-type=secondary-gw-provisioning' >/dev/null 2>&1; then
|
||||
printf '%s\n' "$aid" > "$AIDFILE"
|
||||
printf '%s\n' "$slot" > "$SLOTFILE"
|
||||
: > "$PARKED"
|
||||
log "secondary SIM (slot $slot) parked"
|
||||
return 0
|
||||
fi
|
||||
log "failed to deactivate secondary GW session"
|
||||
return 1
|
||||
}
|
||||
|
||||
unpark() {
|
||||
[ -f "$PARKED" ] || return 0
|
||||
aid=""
|
||||
slot=""
|
||||
[ -r "$AIDFILE" ] && { read -r aid < "$AIDFILE" 2>/dev/null || aid=""; }
|
||||
[ -r "$SLOTFILE" ] && { read -r slot < "$SLOTFILE" 2>/dev/null || slot=""; }
|
||||
[ -z "$slot" ] && slot=2
|
||||
if [ -n "$aid" ] && $QMI --uim-change-provisioning-session="slot=$slot,activate=yes,session-type=secondary-gw-provisioning,aid=$aid" >/dev/null 2>&1; then
|
||||
log "secondary SIM (slot $slot) restored"
|
||||
else
|
||||
log "failed to reactivate secondary GW session"
|
||||
fi
|
||||
rm -f "$PARKED" "$AIDFILE" "$SLOTFILE"
|
||||
}
|
||||
|
||||
screenoff() {
|
||||
[ "$DSDS_SECONDARY_MODE" = "eco" ] || return 0
|
||||
token="$(date +%s)-$$"
|
||||
printf '%s\n' "$token" > "$TOKEN"
|
||||
(
|
||||
sleep "$DSDS_PARK_DELAY"
|
||||
cur=""
|
||||
[ -r "$TOKEN" ] && { read -r cur < "$TOKEN" 2>/dev/null || cur=""; }
|
||||
[ "$cur" = "$token" ] || exit 0
|
||||
"$0" _park >/dev/null 2>&1
|
||||
) &
|
||||
}
|
||||
|
||||
screenon() {
|
||||
rm -f "$TOKEN" 2>/dev/null || true
|
||||
unpark
|
||||
apply_modem_drx || true
|
||||
}
|
||||
|
||||
boot() {
|
||||
rm -f "$TOKEN" "$PARKED" "$AIDFILE" "$SLOTFILE" 2>/dev/null || true
|
||||
write_modprobe || true
|
||||
apply_modem_drx || true
|
||||
}
|
||||
|
||||
status() {
|
||||
printf 'WIFI_LISTEN_INTERVAL=%s\n' "$WIFI_LISTEN_INTERVAL"
|
||||
printf 'MODEM_DRX_MODE=%s\n' "$MODEM_DRX_MODE"
|
||||
printf 'DSDS_SECONDARY_MODE=%s\n' "$DSDS_SECONDARY_MODE"
|
||||
printf 'DSDS_PARK_DELAY=%s\n' "$DSDS_PARK_DELAY"
|
||||
if [ -f "$PARKED" ]; then
|
||||
printf 'secondary_parked=yes\n'
|
||||
else
|
||||
printf 'secondary_parked=no\n'
|
||||
fi
|
||||
if [ -r "$MODPROBE" ]; then
|
||||
printf 'modprobe_conf=%s (%s)\n' "$MODPROBE" "$(tail -n 1 "$MODPROBE")"
|
||||
else
|
||||
printf 'modprobe_conf=absent\n'
|
||||
fi
|
||||
printf 'wcn36xx_param=%s\n' "$(cat /sys/module/wcn36xx/parameters/listen_interval 2>/dev/null || echo n/a)"
|
||||
printf 'modem_drx_now=%s\n' "$(timeout 6 /usr/libexec/msm-modem-uim-selection at auto 'AT$QCDRX?' 2>/dev/null | tr -d '\r' | grep -o '\$QCDRX: [0-9]*' | head -n 1)"
|
||||
}
|
||||
|
||||
case "${1:-}" in
|
||||
boot|apply) boot ;;
|
||||
screenoff) screenoff ;;
|
||||
screenon) screenon ;;
|
||||
_park) park ;;
|
||||
unpark) unpark ;;
|
||||
status) status ;;
|
||||
*)
|
||||
printf 'Usage: %s [boot|apply|screenoff|screenon|unpark|status]\n' "${0##*/}" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
exit 0
|
||||
@@ -58,6 +58,8 @@ xorgdisplay() {
|
||||
fi
|
||||
xset s off s noblank >/dev/null 2>&1 || true
|
||||
xset dpms force off >/dev/null 2>&1 || true
|
||||
# Power policy: park the secondary SIM after the configured dark delay.
|
||||
/usr/bin/bananarchy-power-policy.sh screenoff >/dev/null 2>&1 &
|
||||
;;
|
||||
on)
|
||||
if [ -w /sys/devices/system/cpu/cpufreq/policy0/scaling_governor ]; then
|
||||
@@ -101,6 +103,8 @@ xorgdisplay() {
|
||||
# U1: record every wake so the idle-blank grace guard can suppress an
|
||||
# immediate re-blank (also covers dwm's wake_phone() path).
|
||||
date +%s > /tmp/bananarchy_last_wake 2>/dev/null || true
|
||||
# Power policy: restore the secondary SIM and re-apply modem DRX.
|
||||
/usr/bin/bananarchy-power-policy.sh screenon >/dev/null 2>&1 &
|
||||
;;
|
||||
"")
|
||||
_cur_bl=14
|
||||
|
||||
Reference in new issue
Block a user