#!/bin/sh
### BEGIN INIT INFO
# Provides:          qiba-shutdown
# Required-Start:
# Required-Stop:     sendsigs
# Default-Start:
# Default-Stop:      0 6
# Short-Description: Perform board shutdown tasks
# Description:
### END INIT INFO

[ -e /usr/bin/qiba-exstreamerl.sh ] && source /usr/bin/qiba-exstreamerl.sh

PATH=/sbin:/bin:/usr/sbin:/usr/bin

echo "Shutting down board ..."

if ! [ -z $LEGACY_HW_TYPE ] && ! [ $LEGACY_HW_TYPE = "55" ]; then
	#disable amplifier on boards other than L400
	if [ -d /sys/class/gpio/gpio17 ]; then
  		echo "0" > /sys/class/gpio/gpio17/value
	fi
fi

# L400: Shutdown function.
#
# Performs final termination tasks required for the L400 board.
#
# Returns:
#  <ret>: 0 on SUCCESS, otherwise error code.
exstreamerl_shutdown() {
	local ret=0
	local f="${FUNCNAME[0]}"

	# Terminate I2C GPIO Expanders setup.
	[ ${ret} -eq 0 ] && gpioexp_term || ret=$?

	if [ ${ret} -eq 0 ]; then
		log_inf "${f}" "Setup OK"
	else
		log_err "${f}" "Setup FAILED (${ret})"
	fi

	return ${ret}
}

if ! [ -z $LEGACY_HW_TYPE ] && [ $LEGACY_HW_TYPE = "55" ]; then
	echo "Shutting down the L400 board"
	[ -e /usr/bin/qiba-exstreamerl.sh ] && exstreamerl_shutdown
fi

exit 0

