Disable OCC active on host stop

The OCC active sensor drives the binding and unbinding
of the OCC device driver to the OCC's. Need to ensure
if the host is stopped for any reason, that the OCC
sensors are set to non-active.

Resolves openbmc/openbmc#2148

Change-Id: I5e4bc5469ddda16c961b9f46c771c101b7092cd6
Signed-off-by: Andrew Geissler <andrewg@us.ibm.com>
diff --git a/meta-openbmc-machines/meta-openpower/common/recipes-phosphor/occ/openpower-occ-control.bb b/meta-openbmc-machines/meta-openpower/common/recipes-phosphor/occ/openpower-occ-control.bb
index 390ea72..0befe27 100644
--- a/meta-openbmc-machines/meta-openpower/common/recipes-phosphor/occ/openpower-occ-control.bb
+++ b/meta-openbmc-machines/meta-openpower/common/recipes-phosphor/occ/openpower-occ-control.bb
@@ -10,7 +10,15 @@
 
 require ${PN}.inc
 
+SRC_URI += "file://occ-active.sh"
+do_install_append() {
+        install -d ${D}${bindir}
+        install -m 0755 ${WORKDIR}/occ-active.sh \
+            ${D}${bindir}/occ-active.sh
+}
+
 DBUS_SERVICE_${PN} += "org.open_power.OCC.Control.service"
+SYSTEMD_SERVICE_${PN} += "op-occ-disable@.service"
 
 DEPENDS += "virtual/${PN}-config-native"
 DEPENDS += " \
@@ -21,6 +29,8 @@
         phosphor-dbus-interfaces \
         openpower-dbus-interfaces-native \
         autoconf-archive-native \
+        obmc-targets \
+        systemd \
         "
 
 RDEPENDS_${PN} += " \
@@ -33,4 +43,11 @@
 EXTRA_OECONF = "YAML_PATH=${STAGING_DATADIR_NATIVE}/${PN}"
 EXTRA_OECONF_append = "${@bb.utils.contains('OBMC_MACHINE_FEATURES', 'i2c-occ', ' --enable-i2c-occ', '', d)}"
 
+# Ensure host stop target requires occ disable service
+OCC_DISABLE_TMPL = "op-occ-disable@.service"
+HOST_STOP_TGTFMT = "obmc-host-stop@{0}.target"
+OCC_DISABLE_INSTFMT = "op-occ-disable@{0}.service"
+HOST_STOP_OCC_DISABLE_FMT = "../${OCC_DISABLE_TMPL}:${HOST_STOP_TGTFMT}.requires/${OCC_DISABLE_INSTFMT}"
+SYSTEMD_LINK_${PN} += "${@compose_list_zip(d, 'HOST_STOP_OCC_DISABLE_FMT', 'OBMC_HOST_INSTANCES')}"
+
 S = "${WORKDIR}/git"