From 58348aa03921541fb22e3b857bbd9e3e66781650 Mon Sep 17 00:00:00 2001 From: ro8inmorgan Date: Tue, 20 May 2025 10:18:21 +0200 Subject: [PATCH 1/2] old script with some changes --- skeleton/SYSTEM/tg5040/bin/suspend | 85 ++++++++++++++++++++++++++---- 1 file changed, 76 insertions(+), 9 deletions(-) diff --git a/skeleton/SYSTEM/tg5040/bin/suspend b/skeleton/SYSTEM/tg5040/bin/suspend index f4b479798..f6085f8a0 100755 --- a/skeleton/SYSTEM/tg5040/bin/suspend +++ b/skeleton/SYSTEM/tg5040/bin/suspend @@ -1,16 +1,83 @@ #!/bin/sh set -euo pipefail +exec 0<&- -resume() { - echo "Resumed from suspend..." +wpa_running= +hciattach_running= +bluetoothd_running= + +asound_state_dir=/tmp/asound-suspend + +before() { + >&2 echo "Preparing for suspend..." + # /mnt/SDCARD/Emus/tg5040/PORTS.pak/bin/i2cset -yfr 6 0x34 0x25 0x21 + echo disabled > /sys/devices/platform/soc/7081400.s_twi/i2c-6/6-0034/axp2202-bat-power-supply.0/power_supply/axp2202-battery/power/wakeup + echo disabled > /sys/devices/platform/soc/7081400.s_twi/i2c-6/6-0034/axp2202-usb-power-supply.0/power_supply/axp2202-usb/power/wakeup + echo disabled > /sys/devices/platform/soc/7081400.s_twi/i2c-6/6-0034/power/wakeup + + # >&2 echo "Saving mixer state..." + # mkdir -p "$asound_state_dir" + # alsactl --file "$asound_state_dir/asound.state.pre" store || true + + if pgrep wpa_supplicant; then + wpa_running=1 + >&2 echo "Stopping wpa_supplicant..." + killall -9 wpa_supplicant || true + fi + ifconfig wlan0 down || true + + if pgrep hciattach; then + hciattach_running=1 + >&2 echo "Stopping hciattach..." + /etc/init.d/hciattach stop || true + fi + if pgrep bluetoothd; then + bluetoothd_running=1 + >&2 echo "Stopping bluetoothd..." + /etc/bluetooth/bluetoothd stop || true + killall -15 bluealsa || true + fi + + >&2 echo "Blocking wireless..." + echo 0 >/sys/class/rfkill/rfkill0/state || true } -main() { - echo "Preparing for suspend..." - sync - echo mem > /sys/power/state - echo "Resuming..." - resume +after() { + >&2 echo "Resumed from suspend." + + echo enabled > /sys/devices/platform/soc/7081400.s_twi/i2c-6/6-0034/axp2202-bat-power-supply.0/power_supply/axp2202-battery/power/wakeup + echo enabled > /sys/devices/platform/soc/7081400.s_twi/i2c-6/6-0034/axp2202-usb-power-supply.0/power_supply/axp2202-usb/power/wakeup + echo enabled > /sys/devices/platform/soc/7081400.s_twi/i2c-6/6-0034/power/wakeup + # /mnt/SDCARD/Emus/tg5040/PORTS.pak/bin/i2cset -yfr 6 0x34 0x25 0x20 + # >&2 echo "Restoring mixer state..." + # alsactl --file "$asound_state_dir/asound.state.post" store || true + # alsactl --file "$asound_state_dir/asound.state.pre" restore || true + + # >&2 echo "Unblocking wireless..." + # echo 1 >/sys/class/rfkill/rfkill0/state || true + ifconfig wlan0 up || true + if [ -n "$wpa_running" ]; then + >&2 echo "Starting wpa_supplicant..." + wpa_supplicant -B -iwlan0 -Dnl80211 -c/etc/wifi/wpa_supplicant.conf -I/etc/wifi/wpa_supplicant_overlay.conf -O/etc/wifi/sockets || true + (( udhcpc -i wlan0 &)&) + fi + + + if [ -n "$hciattach_running" ]; then + >&2 echo "Starting hciattach..." + /etc/init.d/hciattach start || true + fi + if [ -n "$bluetoothd_running" ]; then + >&2 echo "Starting bluetoothd..." + /etc/bluetooth/bluetoothd start || true + /usr/bin/bluetoothctl power on || true + fi } -main +before + +>&2 echo "Suspending..." +echo mem >/sys/power/state + +# Resume services in background to reduce UI latency +after From c0c522ba80a05908deff7d6dd734a3f27240953b Mon Sep 17 00:00:00 2001 From: ro8inmorgan Date: Tue, 20 May 2025 11:08:33 +0200 Subject: [PATCH 2/2] Ok this seems to be the real fix, the axp2202 controller is not clearing wakeup locks correctly seems to be a bug in the driver and so thus it cannot always write to /sys/power/state as it will be locked by the axp controller. Running through all wakeup files in sysf for /sys/devices/platform/soc/7081400.s_twi/i2c-6/6-0034/ And throwing them a disabled it will stop the controller from generating wake locks and the system will be able to suspend correctly. I will set them back to enabled on resume too for correct system functionality --- skeleton/SYSTEM/tg5040/bin/suspend | 83 ++++++++++++++++-------------- 1 file changed, 43 insertions(+), 40 deletions(-) diff --git a/skeleton/SYSTEM/tg5040/bin/suspend b/skeleton/SYSTEM/tg5040/bin/suspend index f6085f8a0..10fcd34fe 100755 --- a/skeleton/SYSTEM/tg5040/bin/suspend +++ b/skeleton/SYSTEM/tg5040/bin/suspend @@ -11,43 +11,45 @@ asound_state_dir=/tmp/asound-suspend before() { >&2 echo "Preparing for suspend..." # /mnt/SDCARD/Emus/tg5040/PORTS.pak/bin/i2cset -yfr 6 0x34 0x25 0x21 - echo disabled > /sys/devices/platform/soc/7081400.s_twi/i2c-6/6-0034/axp2202-bat-power-supply.0/power_supply/axp2202-battery/power/wakeup - echo disabled > /sys/devices/platform/soc/7081400.s_twi/i2c-6/6-0034/axp2202-usb-power-supply.0/power_supply/axp2202-usb/power/wakeup - echo disabled > /sys/devices/platform/soc/7081400.s_twi/i2c-6/6-0034/power/wakeup + for f in $(find /sys/devices/platform/soc/7081400.s_twi/i2c-6/6-0034/ -name wakeup); do + echo "Disabling wakeup in $f" + echo disabled > "$f" + done # >&2 echo "Saving mixer state..." # mkdir -p "$asound_state_dir" # alsactl --file "$asound_state_dir/asound.state.pre" store || true - if pgrep wpa_supplicant; then - wpa_running=1 - >&2 echo "Stopping wpa_supplicant..." - killall -9 wpa_supplicant || true - fi - ifconfig wlan0 down || true + # if pgrep wpa_supplicant; then + # wpa_running=1 + # >&2 echo "Stopping wpa_supplicant..." + # killall -9 wpa_supplicant || true + # fi + # ifconfig wlan0 down || true - if pgrep hciattach; then - hciattach_running=1 - >&2 echo "Stopping hciattach..." - /etc/init.d/hciattach stop || true - fi - if pgrep bluetoothd; then - bluetoothd_running=1 - >&2 echo "Stopping bluetoothd..." - /etc/bluetooth/bluetoothd stop || true - killall -15 bluealsa || true - fi + # if pgrep hciattach; then + # hciattach_running=1 + # >&2 echo "Stopping hciattach..." + # /etc/init.d/hciattach stop || true + # fi + # if pgrep bluetoothd; then + # bluetoothd_running=1 + # >&2 echo "Stopping bluetoothd..." + # /etc/bluetooth/bluetoothd stop || true + # killall -15 bluealsa || true + # fi - >&2 echo "Blocking wireless..." - echo 0 >/sys/class/rfkill/rfkill0/state || true + # >&2 echo "Blocking wireless..." + # echo 0 >/sys/class/rfkill/rfkill0/state || true } after() { >&2 echo "Resumed from suspend." - echo enabled > /sys/devices/platform/soc/7081400.s_twi/i2c-6/6-0034/axp2202-bat-power-supply.0/power_supply/axp2202-battery/power/wakeup - echo enabled > /sys/devices/platform/soc/7081400.s_twi/i2c-6/6-0034/axp2202-usb-power-supply.0/power_supply/axp2202-usb/power/wakeup - echo enabled > /sys/devices/platform/soc/7081400.s_twi/i2c-6/6-0034/power/wakeup + for f in $(find /sys/devices/platform/soc/7081400.s_twi/i2c-6/6-0034/ -name wakeup); do + echo "Disabling wakeup in $f" + echo enabled > "$f" + done # /mnt/SDCARD/Emus/tg5040/PORTS.pak/bin/i2cset -yfr 6 0x34 0x25 0x20 # >&2 echo "Restoring mixer state..." # alsactl --file "$asound_state_dir/asound.state.post" store || true @@ -55,28 +57,29 @@ after() { # >&2 echo "Unblocking wireless..." # echo 1 >/sys/class/rfkill/rfkill0/state || true - ifconfig wlan0 up || true - if [ -n "$wpa_running" ]; then - >&2 echo "Starting wpa_supplicant..." - wpa_supplicant -B -iwlan0 -Dnl80211 -c/etc/wifi/wpa_supplicant.conf -I/etc/wifi/wpa_supplicant_overlay.conf -O/etc/wifi/sockets || true - (( udhcpc -i wlan0 &)&) - fi + # ifconfig wlan0 up || true + # if [ -n "$wpa_running" ]; then + # >&2 echo "Starting wpa_supplicant..." + # wpa_supplicant -B -iwlan0 -Dnl80211 -c/etc/wifi/wpa_supplicant.conf -I/etc/wifi/wpa_supplicant_overlay.conf -O/etc/wifi/sockets || true + # (( udhcpc -i wlan0 &)&) + # fi - if [ -n "$hciattach_running" ]; then - >&2 echo "Starting hciattach..." - /etc/init.d/hciattach start || true - fi - if [ -n "$bluetoothd_running" ]; then - >&2 echo "Starting bluetoothd..." - /etc/bluetooth/bluetoothd start || true - /usr/bin/bluetoothctl power on || true - fi + # if [ -n "$hciattach_running" ]; then + # >&2 echo "Starting hciattach..." + # /etc/init.d/hciattach start || true + # fi + # if [ -n "$bluetoothd_running" ]; then + # >&2 echo "Starting bluetoothd..." + # /etc/bluetooth/bluetoothd start || true + # /usr/bin/bluetoothctl power on || true + # fi } before >&2 echo "Suspending..." +sync echo mem >/sys/power/state # Resume services in background to reduce UI latency