meta-quanta: gbs: detect SlimSAS cable presence

Add gpio configuration for SlimSAS cable0~3 and
detect cables connected or not

Signed-off-by: George Hung <george.hung@quantatw.com>
Change-Id: I46f48dab5f11117cd1ee1fb770ae111cbf80cf89
diff --git a/meta-gbs/recipes-phosphor/gpio/phosphor-gpio-monitor/obmc/gpio/slimsas-cable-0.conf b/meta-gbs/recipes-phosphor/gpio/phosphor-gpio-monitor/obmc/gpio/slimsas-cable-0.conf
new file mode 100644
index 0000000..e26c8f5
--- /dev/null
+++ b/meta-gbs/recipes-phosphor/gpio/phosphor-gpio-monitor/obmc/gpio/slimsas-cable-0.conf
@@ -0,0 +1,6 @@
+#The gpio 70 is a real gpio, which is used to
+#store the sas cable 0 present signal
+INVENTORY=/system/chassis/cable/ss_cab0_prsnt
+DEVPATH=/dev/input/event0
+KEY=70
+NAME=ss_cab0_prsnt
diff --git a/meta-gbs/recipes-phosphor/gpio/phosphor-gpio-monitor/obmc/gpio/slimsas-cable-1.conf b/meta-gbs/recipes-phosphor/gpio/phosphor-gpio-monitor/obmc/gpio/slimsas-cable-1.conf
new file mode 100644
index 0000000..e6a18ee
--- /dev/null
+++ b/meta-gbs/recipes-phosphor/gpio/phosphor-gpio-monitor/obmc/gpio/slimsas-cable-1.conf
@@ -0,0 +1,6 @@
+#The gpio 71 is a real gpio, which is used to
+#store the sas cable 1 present signal
+INVENTORY=/system/chassis/cable/ss_cab1_prsnt
+DEVPATH=/dev/input/event0
+KEY=71
+NAME=ss_cab1_prsnt
diff --git a/meta-gbs/recipes-phosphor/gpio/phosphor-gpio-monitor/obmc/gpio/slimsas-cable-2.conf b/meta-gbs/recipes-phosphor/gpio/phosphor-gpio-monitor/obmc/gpio/slimsas-cable-2.conf
new file mode 100644
index 0000000..490f97f
--- /dev/null
+++ b/meta-gbs/recipes-phosphor/gpio/phosphor-gpio-monitor/obmc/gpio/slimsas-cable-2.conf
@@ -0,0 +1,6 @@
+#The gpio 72 is a real gpio, which is used to
+#store the sas cable 2 present signal
+INVENTORY=/system/chassis/cable/ss_cab2_prsnt
+DEVPATH=/dev/input/event0
+KEY=72
+NAME=ss_cab2_prsnt
diff --git a/meta-gbs/recipes-phosphor/gpio/phosphor-gpio-monitor/obmc/gpio/slimsas-cable-3.conf b/meta-gbs/recipes-phosphor/gpio/phosphor-gpio-monitor/obmc/gpio/slimsas-cable-3.conf
new file mode 100644
index 0000000..f3579ab
--- /dev/null
+++ b/meta-gbs/recipes-phosphor/gpio/phosphor-gpio-monitor/obmc/gpio/slimsas-cable-3.conf
@@ -0,0 +1,6 @@
+#The gpio 73 is a real gpio, which is used to
+#store the sas cable 3 present signal
+INVENTORY=/system/chassis/cable/ss_cab3_prsnt
+DEVPATH=/dev/input/event0
+KEY=73
+NAME=ss_cab3_prsnt
diff --git a/meta-gbs/recipes-phosphor/gpio/phosphor-gpio-monitor/phosphor-gpio-presence@.service.replace b/meta-gbs/recipes-phosphor/gpio/phosphor-gpio-monitor/phosphor-gpio-presence@.service.replace
new file mode 100644
index 0000000..3ab9970
--- /dev/null
+++ b/meta-gbs/recipes-phosphor/gpio/phosphor-gpio-monitor/phosphor-gpio-presence@.service.replace
@@ -0,0 +1,14 @@
+[Unit]
+Description=Phosphor GPIO %I Presence
+Wants=mapper-wait@-xyz-openbmc_project-inventory.service
+After=mapper-wait@-xyz-openbmc_project-inventory.service
+ConditionPathExists=/etc/default/obmc/gpio/slimsas-cable-%i.conf
+StartLimitBurst=10
+
+[Service]
+Restart=on-failure
+EnvironmentFile=/etc/default/obmc/gpio/slimsas-cable-%i.conf
+ExecStart=/usr/bin/phosphor-gpio-presence --path=${DEVPATH} --inventory=${INVENTORY} --key=${KEY} --name=${NAME} --drivers=${DRIVERS} --extra-ifaces=${EXTRA_IFACES}
+
+[Install]
+RequiredBy=multi-user.target
diff --git a/meta-gbs/recipes-phosphor/gpio/phosphor-gpio-monitor_%.bbappend b/meta-gbs/recipes-phosphor/gpio/phosphor-gpio-monitor_%.bbappend
new file mode 100644
index 0000000..50974f7
--- /dev/null
+++ b/meta-gbs/recipes-phosphor/gpio/phosphor-gpio-monitor_%.bbappend
@@ -0,0 +1,26 @@
+inherit obmc-phosphor-systemd
+
+FILESEXTRAPATHS_prepend_gbs := "${THISDIR}/${PN}:"
+
+SRC_URI_append_gbs = " file://phosphor-gpio-presence@.service.replace"
+
+TMPL_SLIMSASCABLE = "phosphor-gpio-presence@.service"
+INSTFMT_SLIMSASCABLE = "phosphor-gpio-presence@{0}.service"
+SLIMSASCABLE_TGT = "multi-user.target"
+FMT_SLIMSASCABLE = "../${TMPL_SLIMSASCABLE}:${SLIMSASCABLE_TGT}.requires/${INSTFMT_SLIMSASCABLE}"
+SYSTEMD_ENVIRONMENT_FILE_${PN}_append_gbs +="obmc/gpio/slimsas-cable-0.conf"
+SYSTEMD_ENVIRONMENT_FILE_${PN}_append_gbs +="obmc/gpio/slimsas-cable-1.conf"
+SYSTEMD_ENVIRONMENT_FILE_${PN}_append_gbs +="obmc/gpio/slimsas-cable-2.conf"
+SYSTEMD_ENVIRONMENT_FILE_${PN}_append_gbs +="obmc/gpio/slimsas-cable-3.conf"
+GBS_OBMC_SLIMSAS_CABLE_INSTANCES = "0 1 2 3"
+
+SYSTEMD_LINK_${PN}-presence_append_gbs = " ${@compose_list(d, 'FMT_SLIMSASCABLE', 'GBS_OBMC_SLIMSAS_CABLE_INSTANCES')}"
+
+GBS_SLIMSASCABLE_ENV_FMT  = "obmc/gpio/slimsas-cable-{0}.conf"
+
+SYSTEMD_ENVIRONMENT_FILE_${PN}-presence_gbs = " ${@compose_list(d, 'GBS_SLIMSASCABLE_ENV_FMT', 'GBS_OBMC_SLIMSAS_CABLE_INSTANCES')}"
+
+do_install_append_gbs() {
+    install -d ${D}${systemd_system_unitdir}
+    install -m 0644 ${WORKDIR}/phosphor-gpio-presence@.service.replace ${D}${systemd_system_unitdir}/phosphor-gpio-presence@.service
+}