meta-romulus: Add CPLD workaround

Romulus power on scripts requires a workaround to trigger CPLD to give
pgood signal after vcs_workaround.
Add this as cpld_trigger service that runs after vcs_workaround and
before obmc-host-start-pre.

Change-Id: I0723bad38a5832f0bb2a8776129885308a8e644a
Signed-off-by: Lei YU <mine260309@gmail.com>
diff --git a/meta-romulus/conf/machine/romulus.conf b/meta-romulus/conf/machine/romulus.conf
index ef39de9..ae1e644 100644
--- a/meta-romulus/conf/machine/romulus.conf
+++ b/meta-romulus/conf/machine/romulus.conf
@@ -5,6 +5,9 @@
 
 OBMC_MACHINE_FEATURES += "obmc-mrw"
 
+PREFERRED_PROVIDER_virtual/p9-vcs-workaround = 'cpld-trigger'
+
 require conf/machine/include/ast2500.inc
 require conf/machine/include/obmc-bsp-common.inc
 require conf/machine/include/ibm.inc
+require conf/machine/include/p9.inc
\ No newline at end of file
diff --git a/meta-romulus/recipes-phosphor/chassis/cpld-trigger.bb b/meta-romulus/recipes-phosphor/chassis/cpld-trigger.bb
new file mode 100644
index 0000000..4fb9e20
--- /dev/null
+++ b/meta-romulus/recipes-phosphor/chassis/cpld-trigger.bb
@@ -0,0 +1,28 @@
+SUMMARY = "Romulus CPLD Trigger"
+DESCRIPTION = "Romulus power on workaround to trigger CPLD to continue power sequence"
+PR = "r0"
+
+inherit obmc-phosphor-systemd
+inherit obmc-phosphor-license
+
+RDEPENDS_${PN} += "obmc-pydevtools"
+
+PROVIDES += 'virtual/p9-vcs-workaround'
+RPROVIDES_${PN} += 'virtual-p9-vcs-workaround'
+
+S = "${WORKDIR}"
+SRC_URI += "file://cpld_trigger.sh"
+
+do_install() {
+        install -d ${D}${bindir}
+        install -m 0755 ${WORKDIR}/cpld_trigger.sh ${D}${bindir}/cpld_trigger.sh
+}
+
+TMPL = "cpld_trigger@.service"
+INSTFMT = "cpld_trigger@{0}.service"
+TGTFMT = "obmc-chassis-start@{0}.target"
+FMT = "../${TMPL}:${TGTFMT}.wants/${INSTFMT}"
+
+SYSTEMD_SERVICE_${PN} += "${TMPL}"
+SYSTEMD_LINK_${PN} += "${@compose_list(d, 'FMT', 'OBMC_CHASSIS_INSTANCES')}"
+
diff --git a/meta-romulus/recipes-phosphor/chassis/cpld-trigger/cpld_trigger.sh b/meta-romulus/recipes-phosphor/chassis/cpld-trigger/cpld_trigger.sh
new file mode 100644
index 0000000..9c7bf9a
--- /dev/null
+++ b/meta-romulus/recipes-phosphor/chassis/cpld-trigger/cpld_trigger.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+# Trigger CPLD to give pgood signal
+gpioutil -p S7 -d out -v 0
diff --git a/meta-romulus/recipes-phosphor/chassis/cpld-trigger/cpld_trigger@.service b/meta-romulus/recipes-phosphor/chassis/cpld-trigger/cpld_trigger@.service
new file mode 100644
index 0000000..e961418
--- /dev/null
+++ b/meta-romulus/recipes-phosphor/chassis/cpld-trigger/cpld_trigger@.service
@@ -0,0 +1,15 @@
+[Unit]
+Description=Trigger CPLD to give pgood
+Wants=vcs_workaround@%i.service
+After=vcs_workaround@%i.service
+Wants=obmc-host-start-pre@%i.target
+Before=obmc-host-start-pre@%i.target
+Conflicts=obmc-chassis-stop@%i.target
+
+[Service]
+ExecStart={bindir}/cpld_trigger.sh
+Type=oneshot
+RemainAfterExit=yes
+
+[Install]
+WantedBy=obmc-chassis-start@%i.target