Power supply monitor recipe, service, and conf

Add the Witherspoon power supply monitor application, service file, and
configuration files to the witherspoon-pfault-analysis recipe.

Moved OBMC_POWER_SUPPLY_INSTANCES to the global metadata so it can be
shared between recipes.

Resolves: openbmc/openbmc#1731

Depends-On: Ie364a3dc5b7f19cbc587450fc54f231d1ec280f7

Change-Id: I340a1d48a979a97624843e59a5ab1b1ad04056bb
Signed-off-by: Brandon Wyman <bjwyman@gmail.com>
diff --git a/meta-ibm/meta-witherspoon/conf/machine/witherspoon.conf b/meta-ibm/meta-witherspoon/conf/machine/witherspoon.conf
index 1d9e6f7..6e37167 100644
--- a/meta-ibm/meta-witherspoon/conf/machine/witherspoon.conf
+++ b/meta-ibm/meta-witherspoon/conf/machine/witherspoon.conf
@@ -5,6 +5,8 @@
 
 OBMC_MACHINE_FEATURES += "obmc-mrw obmc-ubi-fs openpower-ubi-fs"
 
+OBMC_POWER_SUPPLY_INSTANCES = "0 1"
+
 PREFERRED_PROVIDER_virtual/p9-vcs-workaround = 'vcs-pre-post'
 
 require conf/machine/include/ast2500.inc
diff --git a/meta-ibm/meta-witherspoon/recipes-phosphor/gpio/phosphor-gpio-monitor.bbappend b/meta-ibm/meta-witherspoon/recipes-phosphor/gpio/phosphor-gpio-monitor.bbappend
index 9d1ca66..b60a64b 100644
--- a/meta-ibm/meta-witherspoon/recipes-phosphor/gpio/phosphor-gpio-monitor.bbappend
+++ b/meta-ibm/meta-witherspoon/recipes-phosphor/gpio/phosphor-gpio-monitor.bbappend
@@ -1,14 +1,12 @@
 FILESEXTRAPATHS_append := "${THISDIR}/${PN}:"
 
-OBMC_POWERSUPPLY_INSTANCES = "0 1"
-
 TMPL_POWERSUPPLY = "phosphor-gpio-presence@.service"
 INSTFMT_POWERSUPPLY = "phosphor-gpio-presence@{0}.service"
 POWERSUPPLY_TGT = "${SYSTEMD_DEFAULT_TARGET}"
 FMT_POWERSUPPLY = "../${TMPL_POWERSUPPLY}:${POWERSUPPLY_TGT}.requires/${INSTFMT_POWERSUPPLY}"
 
-SYSTEMD_LINK_${PN}-presence += "${@compose_list(d, 'FMT_POWERSUPPLY', 'OBMC_POWERSUPPLY_INSTANCES')}"
+SYSTEMD_LINK_${PN}-presence += "${@compose_list(d, 'FMT_POWERSUPPLY', 'OBMC_POWER_SUPPLY_INSTANCES')}"
 
 POWERSUPPLY_ENV_FMT  = "obmc/gpio/phosphor-power-supply-{0}.conf"
 
-SYSTEMD_ENVIRONMENT_FILE_${PN}-presence += "${@compose_list(d, 'POWERSUPPLY_ENV_FMT', 'OBMC_POWERSUPPLY_INSTANCES')}"
+SYSTEMD_ENVIRONMENT_FILE_${PN}-presence += "${@compose_list(d, 'POWERSUPPLY_ENV_FMT', 'OBMC_POWER_SUPPLY_INSTANCES')}"
diff --git a/meta-ibm/meta-witherspoon/recipes-phosphor/power/witherspoon-pfault-analysis.bb b/meta-ibm/meta-witherspoon/recipes-phosphor/power/witherspoon-pfault-analysis.bb
index f9b0e2a..2f46f78 100644
--- a/meta-ibm/meta-witherspoon/recipes-phosphor/power/witherspoon-pfault-analysis.bb
+++ b/meta-ibm/meta-witherspoon/recipes-phosphor/power/witherspoon-pfault-analysis.bb
@@ -32,3 +32,15 @@
 
 SYSTEMD_SERVICE_${PN} += "${SEQ_MONITOR_SVC} ${SEQ_PGOOD_SVC}"
 SYSTEMD_LINK_${PN} += "${SEQ_MONITOR_FMT} ${SEQ_PGOOD_FMT}"
+
+PSU_MONITOR_TMPL = "witherspoon-power-supply-monitor@.service"
+PSU_MONITOR_INSTFMT = "witherspoon-power-supply-monitor@{0}.service"
+PSU_MONITOR_TGT = "${SYSTEMD_DEFAULT_TARGET}"
+PSU_MONITOR_FMT = "../${PSU_MONITOR_TMPL}:${PSU_MONITOR_TGT}.requires/${PSU_MONITOR_INSTFMT}"
+
+FILES_witherspoon-psu-monitor = "${sbindir}/witherspoon-psu-monitor"
+SYSTEMD_SERVICE_${PN} += "${PSU_MONITOR_TMPL}"
+SYSTEMD_LINK_${PN} += "${@compose_list(d, 'PSU_MONITOR_FMT', 'OBMC_POWER_SUPPLY_INSTANCES')}"
+
+PSU_MONITOR_ENV_FMT = "obmc/power-supply-monitor/power-supply-monitor-{0}.conf"
+SYSTEMD_ENVIRONMENT_FILE_${PN} += "${@compose_list(d, 'PSU_MONITOR_ENV_FMT', 'OBMC_POWER_SUPPLY_INSTANCES')}"
diff --git a/meta-ibm/meta-witherspoon/recipes-phosphor/power/witherspoon-pfault-analysis/obmc/power-supply-monitor/power-supply-monitor-0.conf b/meta-ibm/meta-witherspoon/recipes-phosphor/power/witherspoon-pfault-analysis/obmc/power-supply-monitor/power-supply-monitor-0.conf
new file mode 100644
index 0000000..a55828d
--- /dev/null
+++ b/meta-ibm/meta-witherspoon/recipes-phosphor/power/witherspoon-pfault-analysis/obmc/power-supply-monitor/power-supply-monitor-0.conf
@@ -0,0 +1,4 @@
+DEVPATH=/sys/bus/i2c/devices/3-0068
+INSTANCE=0
+INVENTORY=/system/chassis/power_supply0
+
diff --git a/meta-ibm/meta-witherspoon/recipes-phosphor/power/witherspoon-pfault-analysis/obmc/power-supply-monitor/power-supply-monitor-1.conf b/meta-ibm/meta-witherspoon/recipes-phosphor/power/witherspoon-pfault-analysis/obmc/power-supply-monitor/power-supply-monitor-1.conf
new file mode 100644
index 0000000..fea2ad0
--- /dev/null
+++ b/meta-ibm/meta-witherspoon/recipes-phosphor/power/witherspoon-pfault-analysis/obmc/power-supply-monitor/power-supply-monitor-1.conf
@@ -0,0 +1,4 @@
+DEVPATH=/sys/bus/i2c/devices/3-0069
+INSTANCE=1
+INVENTORY=/system/chassis/power_supply1
+
diff --git a/meta-ibm/meta-witherspoon/recipes-phosphor/power/witherspoon-pfault-analysis/witherspoon-power-supply-monitor@.service b/meta-ibm/meta-witherspoon/recipes-phosphor/power/witherspoon-pfault-analysis/witherspoon-power-supply-monitor@.service
new file mode 100644
index 0000000..e2b6b27
--- /dev/null
+++ b/meta-ibm/meta-witherspoon/recipes-phosphor/power/witherspoon-pfault-analysis/witherspoon-power-supply-monitor@.service
@@ -0,0 +1,15 @@
+[Unit]
+Description=Witherspoon Power Supply %I Monitor
+Wants=mapper-wait@-xyz-openbmc_project-inventory-system-chassis-power_supply%i.service
+After=mapper-wait@-xyz-openbmc_project-inventory-system-chassis-power_supply%i.service
+Wants=mapper-wait@-org-openbmc-control-power0.service
+After=mapper-wait@-org-openbmc-control-power0.service
+ConditionPathExists={envfiledir}/obmc/power-supply-monitor/power-supply-monitor-%i.conf
+
+[Service]
+EnvironmentFile={envfiledir}/obmc/power-supply-monitor/power-supply-monitor-%i.conf
+ExecStart=/usr/bin/env witherspoon-psu-monitor --path=${{DEVPATH}} --instance=${{INSTANCE}} --inventory=${{INVENTORY}}
+SysLogIdentifier=witherspoon-psu-monitor
+
+[Install]
+RequiredBy={SYSTEMD_DEFAULT_TARGET}