meta-ampere: Support software workaround for PSU redundancy issue

When system only uses single PSU ( ex : PSU1 ) to power ON normal 12V,
HSC2 will be trigged Fault event (FET health).
At this time, plugging in PSU2 in system, the PSU2 won't deliver power to
+12V_MB because HSC2 is protected by Fault event.
Due to HSC2 protected, the PSU redundancy mechanism can't be created.
Once PSU1 is plugged out at this moment, system will crash ( reset )
because +12V_MB dropped.
Support detecting PSU plug event and reset the Hot-Swap feature by
disabling and then enabling again it through PMBUS command to clear the
event.

Tested:
1. Plug only PSU1 to power ON system (12V)
2. Wait until host is booted, check POUT:
    $ ipmitool  sdr | grep "POUT"
    PSU1_POUT        | 112 Watts         | ok
    PSU2_POUT        | 0 Watts           | ok
3. Plug in PSU2 in system, check POUT:
   $ ipmitool sdr | grep "POUT"
   PSU1_POUT        | 64 Watts          | ok
   PSU2_POUT        | 48 Watts          | ok
4. Unplug AC power PSU1, check POUT:
   $ ipmitool sdr | grep "POUT"
   PSU1_POUT        | 0 Watts           | ok
   PSU2_POUT        | 128 Watts         | ok
5. Plug in AC power PSU1, check POUT:
   $ ipmitool sdr | grep "POUT"
   PSU1_POUT        | 80 Watts          | ok
   PSU2_POUT        | 64 Watts          | ok
6. Repeat 1. to 5. with PSU2.

Signed-off-by: Chanh Nguyen <chanh@os.amperecomputing.com>
Change-Id: Ia6e00cd7b08de48059f2450e7eaf108418d0a026
diff --git a/meta-ampere/meta-jade/recipes-phosphor/gpio/psu-hotswap-reset.bb b/meta-ampere/meta-jade/recipes-phosphor/gpio/psu-hotswap-reset.bb
new file mode 100644
index 0000000..9f7b24f
--- /dev/null
+++ b/meta-ampere/meta-jade/recipes-phosphor/gpio/psu-hotswap-reset.bb
@@ -0,0 +1,33 @@
+SUMMARY = "Ampere Computing LLC PSU Hot Swap Reseting application"
+PR = "r1"
+LICENSE = "Apache-2.0"
+LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
+
+inherit obmc-phosphor-systemd
+inherit allarch
+
+DEPENDS += "virtual/obmc-gpio-monitor"
+RDEPENDS_${PN} += "virtual/obmc-gpio-monitor"
+
+OBMC_PSU_MONITOR_INSTANCES = "PSU1_B25 PSU2_B25"
+
+# Copies config file having arguments for psu
+# via GPIO assertion
+SYSTEMD_ENVIRONMENT_FILE_${PN} +="obmc/gpio/PSU1_B25 \
+                                  obmc/gpio/PSU2_B25 \
+                                 "
+SYSTEMD_SERVICE_${PN} ?= "psu1_hotswap_reset.service psu2_hotswap_reset.service"
+
+SRC_URI += "file://ampere_psu_reset_hotswap.sh"
+
+do_install() {
+        install -d ${D}${bindir}
+        install -m 0755 ${WORKDIR}/ampere_psu_reset_hotswap.sh \
+        ${D}${bindir}/ampere_psu_reset_hotswap.sh
+}
+
+GPIO_MONITOR_TMPL = "phosphor-gpio-monitor@.service"
+GPIO_MONITOR_TGTFMT = "phosphor-gpio-monitor@{0}.service"
+TGT = "multi-user.target"
+PSU_MONITOR_FMT = "../${GPIO_MONITOR_TMPL}:${TGT}.requires/${GPIO_MONITOR_TGTFMT}"
+SYSTEMD_LINK_${PN} += "${@compose_list(d, 'PSU_MONITOR_FMT', 'OBMC_PSU_MONITOR_INSTANCES', 'OBMC_HOST_INSTANCES')}"