meta-ampere: mtjade: don't configure OCP GPIO when BMC rebooted

Configure OCP_AUX_PWREN and/or OCP_MAIN_PWREN GPIOs, even without
changing their values, make the OCP power glitched which consequently
makes the Host OS generates many calltrace message.
When BMC is rebooted, the ampere-gpio-poweron@service service is
triggered that reconfigure these GPIOs.
This comit prevents this case by checking if the Host is currently ON to
skip the reconfiguration.

Tested:
1. Boot the BMC and Host CPU.
2. Reboot BMC. Ensure no call trace for OCP

Signed-off-by: Thang Q. Nguyen <thang@os.amperecomputing.com>
Change-Id: I621e025adf72baf84bffd011ea0e04229f739755
diff --git a/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-gpio-config/ampere-gpio-poweroff@.service b/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-gpio-config/ampere-gpio-poweroff@.service
index 78862eb..fe776a5 100644
--- a/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-gpio-config/ampere-gpio-poweroff@.service
+++ b/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-gpio-config/ampere-gpio-poweroff@.service
@@ -1,10 +1,10 @@
 [Unit]
 Description=Ampere set GPIOs before power off
 Requires=op-wait-power-off@%i.service
-Before=op-wait-power-off@%i.service
+After=op-wait-power-off@%i.service
 Conflicts=obmc-chassis-poweron@%i.target
 
 [Service]
 Type=oneshot
 ExecStart=/usr/bin/env ampere_gpio_utils.sh power off
-SyslogIdentifier=ampere_gpio_utils
\ No newline at end of file
+SyslogIdentifier=ampere_gpio_utils
diff --git a/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-gpio-config/ampere_gpio_utils.sh b/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-gpio-config/ampere_gpio_utils.sh
index 1a098f4..5d1a1a2 100644
--- a/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-gpio-config/ampere_gpio_utils.sh
+++ b/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-gpio-config/ampere_gpio_utils.sh
@@ -10,14 +10,16 @@
 
 set_gpio_power_off() {
 	echo "Setting GPIO before Power off"
-	gpio_configure_output "$OCP_AUX_PWREN" 1
 	gpio_configure_output "$OCP_MAIN_PWREN" 0
-	gpio_configure_output "$SPI0_PROGRAM_SEL" 0
+	rm -f /run/openbmc/host@0-on
 }
 
 set_gpio_power_on() {
 	echo "Setting GPIO before Power on"
-	gpio_configure_output "$OCP_AUX_PWREN" 1
+	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