summaryrefslogtreecommitdiff
path: root/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-gpio-config/ampere_gpio_utils.sh
blob: 5d1a1a27a06a26f9cfcac8d96cb9f25a0a9ad964 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash

# shellcheck source=/dev/null
source /usr/sbin/gpio-defs.sh
source /usr/sbin/gpio-lib.sh

function usage() {
	echo "usage: ampere_gpio_utils.sh [power] [on|off]";
}

set_gpio_power_off() {
	echo "Setting GPIO before Power off"
	gpio_configure_output "$OCP_MAIN_PWREN" 0
	rm -f /run/openbmc/host@0-on
}

set_gpio_power_on() {
	echo "Setting GPIO before Power on"
	val=$(gpio_get_val "$S0_CPU_FW_BOOT_OK")
	if [ "$val" == 1 ]; then
		exit
	fi
	gpio_configure_output "$OCP_MAIN_PWREN" 1
	gpio_configure_output "$SPI0_PROGRAM_SEL" 1
	gpio_configure_output "$SPI0_BACKUP_SEL" 0
}

if [ $# -lt 2 ]; then
	echo "Total number of parameter=$#"
	echo "Insufficient parameter"
	usage;
	exit 0;
fi

if [ "$1" == "power" ]; then
	if [ "$2" == "on" ]; then
		set_gpio_power_on
	elif [ "$2" == "off" ]; then
		set_gpio_power_off
	fi
	exit 0;
else
	echo "Invalid parameter1=$1"
	usage;
	exit 0;
fi
exit 0;