#!/bin/sh
# SPDX-License-Identifier: MIT

[ "$1" = stop ] && [ -e /etc/enigma2/.deep ] || exit 0

# The C20 stock standby firmware can stall before it accepts the RTC alarm
# while secondary cores are parked. Use PSCI CPU_OFF through Linux hotplug.
for cpu in 3 2 1; do
	online=/sys/devices/system/cpu/cpu$cpu/online
	[ -e "$online" ] || continue
	state=$(cat "$online") || exit 1
	[ "$state" = 1 ] || continue
	if ! echo 0 > "$online"; then
		echo "GT Combo: could not offline CPU$cpu for deep standby" >&2
		exit 1
	fi
done
