1#!/bin/bash
2
3# shellcheck disable=SC2046
4
5function usage() {
6	echo "usage: ampere_gpio_utils.sh [power] [on|off]";
7}
8
9set_gpio_power_off() {
10	echo "Setting GPIO before Power off"
11}
12
13set_gpio_power_on() {
14	echo "Setting GPIO before Power on"
15	val=$(gpioget $(gpiofind host0-ready))
16	if [ "$val" == 1 ]; then
17		exit
18	fi
19	gpioset $(gpiofind spi0-program-sel)=1
20	gpioset $(gpiofind spi0-backup-sel)=0
21}
22
23if [ $# -lt 2 ]; then
24	echo "Total number of parameter=$#"
25	echo "Insufficient parameter"
26	usage;
27	exit 0;
28fi
29
30if [ "$1" == "power" ]; then
31	if [ "$2" == "on" ]; then
32		set_gpio_power_on
33	elif [ "$2" == "off" ]; then
34		set_gpio_power_off
35	fi
36	exit 0;
37else
38	echo "Invalid parameter1=$1"
39	usage;
40	exit 0;
41fi
42