meta-bletchley: phosphor-gpio-monitor: enable gpio presence feature

Ebable phosphor-gpio-monitor-presence feature, create service file and
environment file for each presence-sledX pin.

Signed-off-by: Potin Lai <potin.lai@quantatw.com>
Change-Id: I8ab59a635e22404457c42be152f4a033a173d930
diff --git a/meta-facebook/meta-bletchley/recipes-phosphor/gpio/phosphor-gpio-monitor/obmc/gpio/presence-sled1.conf b/meta-facebook/meta-bletchley/recipes-phosphor/gpio/phosphor-gpio-monitor/obmc/gpio/presence-sled1.conf
new file mode 100644
index 0000000..0eda88a
--- /dev/null
+++ b/meta-facebook/meta-bletchley/recipes-phosphor/gpio/phosphor-gpio-monitor/obmc/gpio/presence-sled1.conf
@@ -0,0 +1,4 @@
+INVENTORY=/system/chassis/presence/presence_sled1
+DEVPATH=/dev/input/event0
+KEY=58
+NAME=presence_sled1
\ No newline at end of file
diff --git a/meta-facebook/meta-bletchley/recipes-phosphor/gpio/phosphor-gpio-monitor/obmc/gpio/presence-sled2.conf b/meta-facebook/meta-bletchley/recipes-phosphor/gpio/phosphor-gpio-monitor/obmc/gpio/presence-sled2.conf
new file mode 100644
index 0000000..9afee97
--- /dev/null
+++ b/meta-facebook/meta-bletchley/recipes-phosphor/gpio/phosphor-gpio-monitor/obmc/gpio/presence-sled2.conf
@@ -0,0 +1,4 @@
+INVENTORY=/system/chassis/presence/presence_sled2
+DEVPATH=/dev/input/event0
+KEY=59
+NAME=presence_sled2
\ No newline at end of file
diff --git a/meta-facebook/meta-bletchley/recipes-phosphor/gpio/phosphor-gpio-monitor/obmc/gpio/presence-sled3.conf b/meta-facebook/meta-bletchley/recipes-phosphor/gpio/phosphor-gpio-monitor/obmc/gpio/presence-sled3.conf
new file mode 100644
index 0000000..088179d
--- /dev/null
+++ b/meta-facebook/meta-bletchley/recipes-phosphor/gpio/phosphor-gpio-monitor/obmc/gpio/presence-sled3.conf
@@ -0,0 +1,4 @@
+INVENTORY=/system/chassis/presence/presence_sled3
+DEVPATH=/dev/input/event0
+KEY=60
+NAME=presence_sled3
\ No newline at end of file
diff --git a/meta-facebook/meta-bletchley/recipes-phosphor/gpio/phosphor-gpio-monitor/obmc/gpio/presence-sled4.conf b/meta-facebook/meta-bletchley/recipes-phosphor/gpio/phosphor-gpio-monitor/obmc/gpio/presence-sled4.conf
new file mode 100644
index 0000000..4807461
--- /dev/null
+++ b/meta-facebook/meta-bletchley/recipes-phosphor/gpio/phosphor-gpio-monitor/obmc/gpio/presence-sled4.conf
@@ -0,0 +1,4 @@
+INVENTORY=/system/chassis/presence/presence_sled4
+DEVPATH=/dev/input/event0
+KEY=61
+NAME=presence_sled4
\ No newline at end of file
diff --git a/meta-facebook/meta-bletchley/recipes-phosphor/gpio/phosphor-gpio-monitor/obmc/gpio/presence-sled5.conf b/meta-facebook/meta-bletchley/recipes-phosphor/gpio/phosphor-gpio-monitor/obmc/gpio/presence-sled5.conf
new file mode 100644
index 0000000..b29352c
--- /dev/null
+++ b/meta-facebook/meta-bletchley/recipes-phosphor/gpio/phosphor-gpio-monitor/obmc/gpio/presence-sled5.conf
@@ -0,0 +1,4 @@
+INVENTORY=/system/chassis/presence/presence_sled5
+DEVPATH=/dev/input/event0
+KEY=62
+NAME=presence_sled5
\ No newline at end of file
diff --git a/meta-facebook/meta-bletchley/recipes-phosphor/gpio/phosphor-gpio-monitor/obmc/gpio/presence-sled6.conf b/meta-facebook/meta-bletchley/recipes-phosphor/gpio/phosphor-gpio-monitor/obmc/gpio/presence-sled6.conf
new file mode 100644
index 0000000..9564a3a
--- /dev/null
+++ b/meta-facebook/meta-bletchley/recipes-phosphor/gpio/phosphor-gpio-monitor/obmc/gpio/presence-sled6.conf
@@ -0,0 +1,4 @@
+INVENTORY=/system/chassis/presence/presence_sled6
+DEVPATH=/dev/input/event0
+KEY=63
+NAME=presence_sled6
\ No newline at end of file
diff --git a/meta-facebook/meta-bletchley/recipes-phosphor/gpio/phosphor-gpio-monitor_%.bbappend b/meta-facebook/meta-bletchley/recipes-phosphor/gpio/phosphor-gpio-monitor_%.bbappend
new file mode 100644
index 0000000..c65e729
--- /dev/null
+++ b/meta-facebook/meta-bletchley/recipes-phosphor/gpio/phosphor-gpio-monitor_%.bbappend
@@ -0,0 +1,22 @@
+FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
+
+inherit obmc-phosphor-systemd
+
+# Add service file link
+TMPL_PRESENT = "phosphor-gpio-presence@.service"
+INSTFMT_PRESENT = "phosphor-gpio-presence@presence-sled{0}.service"
+PRESENT_TGT = "multi-user.target"
+FMT_PRESENT = "../${TMPL_PRESENT}:${PRESENT_TGT}.requires/${INSTFMT_PRESENT}"
+SYSTEMD_LINK:${PN}-presence:append:bletchley = " ${@compose_list(d, 'FMT_PRESENT', 'OBMC_HOST_INSTANCES')}"
+
+# Add environment file
+SLED_PRESENT_ENV_FMT = "obmc/gpio/presence-sled{0}.conf"
+SYSTEMD_ENVIRONMENT_FILE:${PN}-presence:bletchley = " ${@compose_list(d, 'SLED_PRESENT_ENV_FMT', 'OBMC_HOST_INSTANCES')}"
+
+GPIO_PRESENCE_SLED_CONF="/etc/default/obmc/gpio/%i.conf"
+
+do_install:append:bletchley(){
+    # modify ConditionPathExists and EnvironmentFile to correct filepath
+    sed -i -e "s,ConditionPathExists=.*,ConditionPathExists=${GPIO_PRESENCE_SLED_CONF},g" ${D}${systemd_system_unitdir}/phosphor-gpio-presence@.service
+    sed -i -e "s,EnvironmentFile=.*,EnvironmentFile=${GPIO_PRESENCE_SLED_CONF},g" ${D}${systemd_system_unitdir}/phosphor-gpio-presence@.service
+}
diff --git a/meta-facebook/meta-bletchley/recipes-phosphor/images/fb-bletchley-phosphor-image.inc b/meta-facebook/meta-bletchley/recipes-phosphor/images/fb-bletchley-phosphor-image.inc
index f510041..65531cb 100644
--- a/meta-facebook/meta-bletchley/recipes-phosphor/images/fb-bletchley-phosphor-image.inc
+++ b/meta-facebook/meta-bletchley/recipes-phosphor/images/fb-bletchley-phosphor-image.inc
@@ -7,4 +7,5 @@
     idevicerestore \
     fw-update \
     phosphor-sel-logger \
+    phosphor-gpio-monitor-presence \
 "