meta-bletchley: add systemd target for sled insertion and removal

Add target file for sled insertion and removal, add Requires for both
motor-init-calibration & host-ac-on service in seld insertion target,
and Conflicts in sled removal.

Signed-off-by: Potin Lai <potin.lai@quantatw.com>
Change-Id: I020694f868a352b0bcd2754a54cadd4a7d5487e5
diff --git a/meta-facebook/meta-bletchley/recipes-bletchley/detect-gpio-present/detect-sled-present_0.1.bb b/meta-facebook/meta-bletchley/recipes-bletchley/detect-gpio-present/detect-sled-present_0.1.bb
index f70a740..cfcebdc 100644
--- a/meta-facebook/meta-bletchley/recipes-bletchley/detect-gpio-present/detect-sled-present_0.1.bb
+++ b/meta-facebook/meta-bletchley/recipes-bletchley/detect-gpio-present/detect-sled-present_0.1.bb
@@ -11,6 +11,8 @@
 
 SRC_URI = " file://detect-sled-present \
             file://detect-sled-present@.service \
+            file://bletchley-sled-insertion@.target \
+            file://bletchley-sled-removal@.target \
           "
 
 do_install() {
@@ -19,9 +21,20 @@
 
     install -d ${D}${systemd_system_unitdir}
     install -m 0644 ${WORKDIR}/detect-sled-present@.service ${D}${systemd_system_unitdir}
+    install -m 0644 ${WORKDIR}/bletchley-sled-insertion@.target ${D}${systemd_system_unitdir}
+    install -m 0644 ${WORKDIR}/bletchley-sled-removal@.target ${D}${systemd_system_unitdir}
 }
 
 TGT = "${SYSTEMD_DEFAULT_TARGET}"
+
 SLED_PRESENT_INSTFMT="../detect-sled-present@.service:${TGT}.wants/detect-sled-present@{0}.service"
 SYSTEMD_SERVICE:${PN} += "detect-sled-present@.service"
 SYSTEMD_LINK:${PN} += "${@compose_list(d, 'SLED_PRESENT_INSTFMT', 'OBMC_HOST_INSTANCES')}"
+
+SLED_INSERT_INSTFMT="../bletchley-sled-insertion@.target:${TGT}.wants/bletchley-sled-insertion@{0}.target"
+SYSTEMD_SERVICE:${PN} += "bletchley-sled-insertion@.target"
+SYSTEMD_LINK:${PN} += "${@compose_list(d, 'SLED_INSERT_INSTFMT', 'OBMC_HOST_INSTANCES')}"
+
+SLED_REMOVE_INSTFMT="bletchley-sled-removal@.target:bletchley-sled-removal@{0}.target"
+SYSTEMD_SERVICE:${PN} += "bletchley-sled-removal@.target"
+SYSTEMD_LINK:${PN} += "${@compose_list(d, 'SLED_REMOVE_INSTFMT', 'OBMC_HOST_INSTANCES')}"
diff --git a/meta-facebook/meta-bletchley/recipes-bletchley/detect-gpio-present/files/bletchley-sled-insertion@.target b/meta-facebook/meta-bletchley/recipes-bletchley/detect-gpio-present/files/bletchley-sled-insertion@.target
new file mode 100644
index 0000000..6fef027
--- /dev/null
+++ b/meta-facebook/meta-bletchley/recipes-bletchley/detect-gpio-present/files/bletchley-sled-insertion@.target
@@ -0,0 +1,10 @@
+[Unit]
+Description=Bletchlet SLED%i insertion target
+
+Requires=host-ac-on@%i.service
+After=host-ac-on@%i.service
+Requires=motor-init-calibration@%i.service
+After=motor-init-calibration@%i.service
+Conflicts=bletchley-sled-removed@%i.target
+
+RefuseManualStop=yes
\ No newline at end of file
diff --git a/meta-facebook/meta-bletchley/recipes-bletchley/detect-gpio-present/files/bletchley-sled-removal@.target b/meta-facebook/meta-bletchley/recipes-bletchley/detect-gpio-present/files/bletchley-sled-removal@.target
new file mode 100644
index 0000000..55fd5c3
--- /dev/null
+++ b/meta-facebook/meta-bletchley/recipes-bletchley/detect-gpio-present/files/bletchley-sled-removal@.target
@@ -0,0 +1,8 @@
+[Unit]
+Description=Bletchlet SLED%i removal target
+
+Conflicts=motor-init-calibration@%i.service
+Conflicts=host-ac-on@%i.service
+Conflicts=bletchley-sled-insertion@%i.target
+
+RefuseManualStop=yes
\ No newline at end of file
diff --git a/meta-facebook/meta-bletchley/recipes-bletchley/detect-gpio-present/files/detect-sled-present b/meta-facebook/meta-bletchley/recipes-bletchley/detect-gpio-present/files/detect-sled-present
index 62830bf..b3c9db4 100644
--- a/meta-facebook/meta-bletchley/recipes-bletchley/detect-gpio-present/files/detect-sled-present
+++ b/meta-facebook/meta-bletchley/recipes-bletchley/detect-gpio-present/files/detect-sled-present
@@ -53,6 +53,9 @@
 
     # 0054: 24c64
     bind_i2c_driver "${I2C_BUS_NUM}-0054" "at24"
+
+    # start bletchley-sled-insertion target
+    /bin/systemctl start bletchley-sled-insertion@"${SLED_ID}".target
 }
 
 sled_remove_action()
@@ -83,6 +86,9 @@
 
     # # 0054: 24c64
     # unbind_i2c_driver "${I2C_BUS_NUM}-0054" "at24"
+
+    # start bletchley-sled-removal target
+    /bin/systemctl start bletchley-sled-removal@"${SLED_ID}".target
 }