2026-10-29 18:57:27 +02:00
#!/bin/sh
# Bananarchy kernel and runtime power management optimizations
2026-11-03 12:44:17 +02:00
chmod 0755 / 2>/dev/null || true
2026-10-29 18:57:27 +02:00
# 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
fi
# Reduce periodic VM stat shepherd and dirty writeback timer wakeups
2026-10-30 19:28:07 +02:00
{ echo 30 > /proc/sys/vm/stat_interval; } 2>/dev/null || true
{ echo 6000 > /proc/sys/vm/dirty_writeback_centisecs; } 2>/dev/null || true
{ echo 6000 > /proc/sys/vm/dirty_expire_centisecs; } 2>/dev/null || true
{ echo 0 > /proc/sys/kernel/nmi_watchdog; } 2>/dev/null || true
2026-11-05 08:07:10 +02:00
{ echo "1 4 1 1" > /proc/sys/kernel/printk; } 2>/dev/null || true
2026-11-01 11:56:28 +02:00
{ echo Y > /sys/module/workqueue/parameters/power_efficient; } 2>/dev/null || true
{ echo Y > /sys/module/printk/parameters/console_suspend; } 2>/dev/null || true
# Lower SPI controller (78b9000.spi) runtime PM autosuspend from 1000 ms to 50 ms
# and ensure runtime PM auto-suspend is enabled across SoC buses
for spi_dev in /sys/devices/platform/soc@0/*.spi; do
if [ -d " $spi_dev /power" ] ; then
{ echo 50 > " $spi_dev /power/autosuspend_delay_ms" ; } 2>/dev/null || true
{ echo auto > " $spi_dev /power/control" ; } 2>/dev/null || true
fi
done
for pm_dev in /sys/devices/platform/soc@0/1c00000.gpu /sys/devices/platform/soc@0/*.sdhci /sys/devices/platform/soc@0/*.serial /sys/devices/platform/soc@0/*.serial/*; do
if [ -w " $pm_dev /power/control" ] ; then
{ echo auto > " $pm_dev /power/control" ; } 2>/dev/null || true
fi
done
2026-10-29 18:57:27 +02:00
2026-11-03 12:44:17 +02:00
# 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.
2026-10-30 19:28:07 +02:00
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
2026-11-03 12:44:17 +02:00
{ 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
2026-10-30 19:28:07 +02:00
fi
done
2026-11-03 12:44:17 +02:00
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
2026-10-30 19:28:07 +02:00
# Enable IEEE 802.11 power save on WCN3620 wlan0
if command -v iw >/dev/null 2>& 1; then
iw dev wlan0 set power_save on 2>/dev/null || true
fi
2026-11-03 09:55:18 +02:00
# Restore any persistent Engineering Menu Wi-Fi/BT MAC and IMEI override state
if [ -x /usr/bin/bananarchy-engmenu-ctl ] ; then
/usr/bin/bananarchy-engmenu-ctl apply-boot >/dev/null 2>& 1 || true
fi
2026-10-30 19:28:07 +02:00
# Automount microSD card if present at boot (unbinds 7864900.sdhci when slot is empty)
2026-10-29 21:02:51 +02:00
if [ -x /usr/bin/sxmo_sdcard.sh ] ; then
/usr/bin/sxmo_sdcard.sh automount boot >/dev/null 2>& 1 &
fi