meta-facebook: harma: auto power on

The harma BMC will power on the host
if the CMM performs a host DC cycle or lifts leakage detection.

We can't obtain the correct value from the CPLD
because the MB CPLD has no power at this stage.
Therefore, we need to choose a direct GPIO instead of
the original SGPIO pin.

Change-Id: I0b4c4d3b2950ae489d07972a0bf221074a426d13
Signed-off-by: Peter Yin <peter.yin@quantatw.com>
diff --git a/meta-facebook/meta-harma/recipes-phosphor/gpio/phosphor-gpio-monitor/deassert-power-hsc-good.service b/meta-facebook/meta-harma/recipes-phosphor/gpio/phosphor-gpio-monitor/deassert-power-hsc-good.service
deleted file mode 100644
index 9c5aee1..0000000
--- a/meta-facebook/meta-harma/recipes-phosphor/gpio/phosphor-gpio-monitor/deassert-power-hsc-good.service
+++ /dev/null
@@ -1,8 +0,0 @@
-[Unit]
-Description=Deassert Power HSC Good Status
-
-[Service]
-Type=oneshot
-ExecStart=/usr/libexec/phosphor-gpio-monitor/deassert-power-hsc-good
-
-SyslogIdentifier=deassert-power-hsc-good
diff --git a/meta-facebook/meta-harma/recipes-phosphor/gpio/phosphor-gpio-monitor/host-power-off b/meta-facebook/meta-harma/recipes-phosphor/gpio/phosphor-gpio-monitor/host-power-off
new file mode 100644
index 0000000..121db3f
--- /dev/null
+++ b/meta-facebook/meta-harma/recipes-phosphor/gpio/phosphor-gpio-monitor/host-power-off
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+#To avoid AC cycle trigger this script.
+sleep 5
+
+# Set Host Power Off
+obmcutil poweroff
diff --git a/meta-facebook/meta-harma/recipes-phosphor/gpio/phosphor-gpio-monitor/host-power-off.service b/meta-facebook/meta-harma/recipes-phosphor/gpio/phosphor-gpio-monitor/host-power-off.service
new file mode 100644
index 0000000..ad9dfaa
--- /dev/null
+++ b/meta-facebook/meta-harma/recipes-phosphor/gpio/phosphor-gpio-monitor/host-power-off.service
@@ -0,0 +1,8 @@
+[Unit]
+Description=Host power off assertion
+
+[Service]
+Type=oneshot
+ExecStart=/usr/libexec/phosphor-gpio-monitor/host-power-off
+
+SyslogIdentifier=host-power-off
diff --git a/meta-facebook/meta-harma/recipes-phosphor/gpio/phosphor-gpio-monitor/deassert-power-hsc-good b/meta-facebook/meta-harma/recipes-phosphor/gpio/phosphor-gpio-monitor/host-power-on
similarity index 86%
rename from meta-facebook/meta-harma/recipes-phosphor/gpio/phosphor-gpio-monitor/deassert-power-hsc-good
rename to meta-facebook/meta-harma/recipes-phosphor/gpio/phosphor-gpio-monitor/host-power-on
index ad9fc7c..d556137 100644
--- a/meta-facebook/meta-harma/recipes-phosphor/gpio/phosphor-gpio-monitor/deassert-power-hsc-good
+++ b/meta-facebook/meta-harma/recipes-phosphor/gpio/phosphor-gpio-monitor/host-power-on
@@ -1,6 +1,6 @@
 #!/bin/bash
 
+sleep 1
+
 # Set Host Power On
 obmcutil poweron
-
-exit 0
diff --git a/meta-facebook/meta-harma/recipes-phosphor/gpio/phosphor-gpio-monitor/host-power-on.service b/meta-facebook/meta-harma/recipes-phosphor/gpio/phosphor-gpio-monitor/host-power-on.service
new file mode 100644
index 0000000..c4bc3f1
--- /dev/null
+++ b/meta-facebook/meta-harma/recipes-phosphor/gpio/phosphor-gpio-monitor/host-power-on.service
@@ -0,0 +1,8 @@
+[Unit]
+Description=Host power on assertion
+
+[Service]
+Type=oneshot
+ExecStart=/usr/libexec/phosphor-gpio-monitor/host-power-on
+
+SyslogIdentifier=host-power-on
diff --git a/meta-facebook/meta-harma/recipes-phosphor/gpio/phosphor-gpio-monitor/plat-phosphor-multi-gpio-monitor.json b/meta-facebook/meta-harma/recipes-phosphor/gpio/phosphor-gpio-monitor/plat-phosphor-multi-gpio-monitor.json
index 8d14905..7402df4 100644
--- a/meta-facebook/meta-harma/recipes-phosphor/gpio/phosphor-gpio-monitor/plat-phosphor-multi-gpio-monitor.json
+++ b/meta-facebook/meta-harma/recipes-phosphor/gpio/phosphor-gpio-monitor/plat-phosphor-multi-gpio-monitor.json
@@ -86,16 +86,6 @@
         "Continue": true
     },
     {
-        "Name": "cpu0-err-alert",
-        "ChipId": "0",
-        "GpioNum": 21,
-        "EventMon": "FALLING",
-        "Targets": {
-            "FALLING": ["assert-gpio-log@cpu0-err-alert.service"]
-        },
-        "Continue": true
-    },
-    {
         "Name": "reset-cause-platrst",
         "ChipId": "0",
         "GpioNum": 16,
@@ -158,18 +148,19 @@
         "GpioNum": 92,
         "EventMon": "BOTH",
         "Targets": {
-            "RISING": ["deassert-gpio-log@leakage-detect-alert.service"],
-            "FALLING": ["assert-gpio-log@leakage-detect-alert.service"]
+            "RISING": ["deassert-gpio-log@leakage-detect-alert.service", "host-power-on.service"],
+            "FALLING": ["assert-gpio-log@leakage-detect-alert.service", "host-power-off.service"]
         },
         "Continue": true
     },
     {
         "Name": "power-hsc-good",
-        "ChipId": "2",
-        "GpioNum": 10,
-        "EventMon": "RISING",
+        "ChipId": "0",
+        "GpioNum": 21,
+        "EventMon": "BOTH",
         "Targets": {
-            "RISING": ["deassert-power-hsc-good.service"]
+            "RISING": ["host-power-on.service"],
+            "FALLING": ["host-power-off.service"]
         },
         "Continue": true
     }
diff --git a/meta-facebook/meta-harma/recipes-phosphor/gpio/phosphor-gpio-monitor_%.bbappend b/meta-facebook/meta-harma/recipes-phosphor/gpio/phosphor-gpio-monitor_%.bbappend
index 19bb06f..791fe26 100644
--- a/meta-facebook/meta-harma/recipes-phosphor/gpio/phosphor-gpio-monitor_%.bbappend
+++ b/meta-facebook/meta-harma/recipes-phosphor/gpio/phosphor-gpio-monitor_%.bbappend
@@ -14,10 +14,12 @@
             file://deassert-post-end.service \
             file://deassert-power-good \
             file://deassert-power-good.service \
-            file://deassert-power-hsc-good \
-            file://deassert-power-hsc-good.service \
             file://deassert-reset-button \
             file://deassert-reset-button.service \
+            file://host-power-off \
+            file://host-power-off.service \
+            file://host-power-on \
+            file://host-power-on.service \
             file://logging \
             file://multi-gpios-sys-init \
             file://multi-gpios-sys-init.service \
@@ -67,7 +69,8 @@
     install -m 0755 ${WORKDIR}/assert-power-good ${D}${libexecdir}/${PN}/
     install -m 0755 ${WORKDIR}/deassert-power-good ${D}${libexecdir}/${PN}/
 
-    install -m 0755 ${WORKDIR}/deassert-power-hsc-good ${D}${libexecdir}/${PN}/
+    install -m 0755 ${WORKDIR}/host-power-off ${D}${libexecdir}/${PN}/
+    install -m 0755 ${WORKDIR}/host-power-on ${D}${libexecdir}/${PN}/
 }
 
 SYSTEMD_OVERRIDE:${PN}-monitor += "phosphor-multi-gpio-monitor.conf:phosphor-multi-gpio-monitor.service.d/phosphor-multi-gpio-monitor.conf"