meta-hpe: add missing gxp ehci owner reset recipe

Change-Id: I03f741a0e11cecd49028d78a740f1d9e8678f878
Signed-off-by: Charles Kearney <charles.kearney@hpe.com>
diff --git a/meta-hpe/meta-common/recipes-hpe/vehci/host-ehci-owner-reset.bb b/meta-hpe/meta-common/recipes-hpe/vehci/host-ehci-owner-reset.bb
new file mode 100644
index 0000000..b2335e1
--- /dev/null
+++ b/meta-hpe/meta-common/recipes-hpe/vehci/host-ehci-owner-reset.bb
@@ -0,0 +1,44 @@
+SUMMARY = "GXP EHCI Owner Reset"
+PR = "r1"
+LICENSE = "Apache-2.0"
+LIC_FILES_CHKSUM = "file://${HPEBASE}/COPYING.apache-2.0;md5=34400b68072d710fecd0a2940a0d1658"
+
+inherit obmc-phosphor-systemd
+
+DEPENDS += "phosphor-gpio-monitor"
+RDEPENDS:${PN} += "phosphor-gpio-monitor-monitor"
+
+SYSTEMD_ENVIRONMENT_FILE:${PN} += "obmc/gpio/port_owner_udc0"
+SYSTEMD_ENVIRONMENT_FILE:${PN} += "obmc/gpio/port_owner_udc1"
+SYSTEMD_ENVIRONMENT_FILE:${PN} += "obmc/gpio/port_owner_udc2"
+
+UDC0_GPIO = "port_owner_udc0"
+UDC1_GPIO = "port_owner_udc1"
+UDC2_GPIO = "port_owner_udc2"
+TMPL_GPIO = "phosphor-gpio-monitor@.service"
+INSTFMT_GPIO = "phosphor-gpio-monitor@{0}.service"
+TGT_GPIO = "multi-user.target.requires"
+FMT_GPIO = "../${TMPL_GPIO}:${TGT_GPIO}/${INSTFMT_GPIO}"
+SYSTEMD_LINK:${PN} += "${@compose_list(d, 'FMT_GPIO', 'UDC0_GPIO')}"
+SYSTEMD_LINK:${PN} += "${@compose_list(d, 'FMT_GPIO', 'UDC1_GPIO')}"
+SYSTEMD_LINK:${PN} += "${@compose_list(d, 'FMT_GPIO', 'UDC2_GPIO')}"
+
+UDC0_VEHCI = "udc0"
+UDC1_VEHCI = "udc1"
+UDC2_VEHCI = "udc2"
+TMPL_VEHCI = "host-ehci-owner-reset@.service"
+INSTFMT_VEHCI = "host-ehci-owner-reset@{0}.service"
+FMT_VEHCI = "${TMPL_VEHCI}:${INSTFMT_VEHCI}"
+SYSTEMD_LINK:${PN} += "${@compose_list(d, 'FMT_VEHCI', 'UDC0_VEHCI')}"
+SYSTEMD_LINK:${PN} += "${@compose_list(d, 'FMT_VEHCI', 'UDC1_VEHCI')}"
+SYSTEMD_LINK:${PN} += "${@compose_list(d, 'FMT_VEHCI', 'UDC2_VEHCI')}"
+
+SYSTEMD_SERVICE:${PN} += "host-ehci-owner-reset@.service"
+
+SRC_URI += "file://udc-reconnect.sh"
+SRC_URI += "file://host-ehci-owner-reset@.service"
+
+do_install() {
+	install -d ${D}${bindir}
+	install -m 755 ${WORKDIR}/udc-reconnect.sh ${D}${bindir}
+}
diff --git a/meta-hpe/meta-common/recipes-hpe/vehci/host-ehci-owner-reset/host-ehci-owner-reset@.service b/meta-hpe/meta-common/recipes-hpe/vehci/host-ehci-owner-reset/host-ehci-owner-reset@.service
new file mode 100644
index 0000000..2a44b9f
--- /dev/null
+++ b/meta-hpe/meta-common/recipes-hpe/vehci/host-ehci-owner-reset/host-ehci-owner-reset@.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=GXP EHCI Owner Reset Service
+Wants=start-ipkvm.service
+After=start-ipkvm.service
+StartLimitIntervalSec=0
+
+[Service]
+Type=oneshot
+ExecStart=/bin/sh -c "udc-reconnect.sh %i"
+SyslogIdentifier=host-ehci-owner-reset@%i
+
diff --git a/meta-hpe/meta-common/recipes-hpe/vehci/host-ehci-owner-reset/obmc/gpio/port_owner_udc0 b/meta-hpe/meta-common/recipes-hpe/vehci/host-ehci-owner-reset/obmc/gpio/port_owner_udc0
new file mode 100644
index 0000000..0e7b368
--- /dev/null
+++ b/meta-hpe/meta-common/recipes-hpe/vehci/host-ehci-owner-reset/obmc/gpio/port_owner_udc0
@@ -0,0 +1,5 @@
+DEVPATH=/dev/input/by-path/platform-ahb@80000000:vuhc-event
+KEY=200
+POLARITY=1
+TARGET=host-ehci-owner-reset@udc0.service
+EXTRA_ARGS=--continue
diff --git a/meta-hpe/meta-common/recipes-hpe/vehci/host-ehci-owner-reset/obmc/gpio/port_owner_udc1 b/meta-hpe/meta-common/recipes-hpe/vehci/host-ehci-owner-reset/obmc/gpio/port_owner_udc1
new file mode 100644
index 0000000..48ac8f0
--- /dev/null
+++ b/meta-hpe/meta-common/recipes-hpe/vehci/host-ehci-owner-reset/obmc/gpio/port_owner_udc1
@@ -0,0 +1,5 @@
+DEVPATH=/dev/input/by-path/platform-ahb@80000000:vuhc-event
+KEY=201
+POLARITY=1
+TARGET=host-ehci-owner-reset@udc1.service
+EXTRA_ARGS=--continue
diff --git a/meta-hpe/meta-common/recipes-hpe/vehci/host-ehci-owner-reset/obmc/gpio/port_owner_udc2 b/meta-hpe/meta-common/recipes-hpe/vehci/host-ehci-owner-reset/obmc/gpio/port_owner_udc2
new file mode 100644
index 0000000..52d360b
--- /dev/null
+++ b/meta-hpe/meta-common/recipes-hpe/vehci/host-ehci-owner-reset/obmc/gpio/port_owner_udc2
@@ -0,0 +1,5 @@
+DEVPATH=/dev/input/by-path/platform-ahb@80000000:vuhc-event
+KEY=202
+POLARITY=1
+TARGET=host-ehci-owner-reset@udc2.service
+EXTRA_ARGS=--continue
diff --git a/meta-hpe/meta-common/recipes-hpe/vehci/host-ehci-owner-reset/udc-reconnect.sh b/meta-hpe/meta-common/recipes-hpe/vehci/host-ehci-owner-reset/udc-reconnect.sh
new file mode 100644
index 0000000..c90489d
--- /dev/null
+++ b/meta-hpe/meta-common/recipes-hpe/vehci/host-ehci-owner-reset/udc-reconnect.sh
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+if [ "$1" = "udc0" ]; then
+  function=$(cat /sys/class/udc/80401000.udc/function)
+  if [ "func-$function" != "func-" ]; then
+    echo "UDC0 owner is changed"
+    echo disconnect > /sys/class/udc/80401000.udc/soft_connect
+    sleep 3
+    echo connect > /sys/class/udc/80401000.udc/soft_connect
+  else
+    echo "UDC0 is not attached"
+  fi
+else
+ if [ "$1" = "udc1" ]; then
+  function=$(cat /sys/class/udc/80402000.udc/function)
+  if [ "func-$function" != "func-" ]; then
+    echo "UDC1 owner is changed"
+    echo disconnect > /sys/class/udc/80402000.udc/soft_connect
+    sleep 3
+    echo connect > /sys/class/udc/80402000.udc/soft_connect
+  else
+    echo "UDC1 is not attached"
+  fi
+ else
+  if [ "$1" = "udc2" ]; then
+  function=$(cat /sys/class/udc/80403000.udc/function)
+   if [ "func-$function" != "func-" ]; then
+    echo "UDC2 owner is changed"
+    echo disconnect > /sys/class/udc/80403000.udc/soft_connect
+    sleep 3
+    echo connect > /sys/class/udc/80403000.udc/soft_connect
+   else
+    echo "UDC2 is not attached"
+   fi
+  fi
+ fi
+fi
diff --git a/meta-hpe/meta-common/recipes-phosphor/packagegroups/packagegroup-hpe-apps.bb b/meta-hpe/meta-common/recipes-phosphor/packagegroups/packagegroup-hpe-apps.bb
index db77bbb..5f711a2 100644
--- a/meta-hpe/meta-common/recipes-phosphor/packagegroups/packagegroup-hpe-apps.bb
+++ b/meta-hpe/meta-common/recipes-phosphor/packagegroups/packagegroup-hpe-apps.bb
@@ -44,4 +44,5 @@
         webui-vue \
         phosphor-ipmi-ipmb \
         dbus-sensors \
+        host-ehci-owner-reset \
         "