meta-bletchley: use gpiomon instead of polling gpio value

Remove gpio polling of switch detect pin in power-ctrl and motor-init.
Use gpiomon and timeout commands instead to improve performance and
timing issue.

Signed-off-by: Potin Lai <potin.lai@quantatw.com>
Change-Id: I9e1eb26b070a57f424b341890733dc63c170bf79
diff --git a/meta-facebook/meta-bletchley/recipes-bletchley/plat-tools/files/bletchley-common-functions b/meta-facebook/meta-bletchley/recipes-bletchley/plat-tools/files/bletchley-common-functions
index 68d0c62..49bca93 100644
--- a/meta-facebook/meta-bletchley/recipes-bletchley/plat-tools/files/bletchley-common-functions
+++ b/meta-facebook/meta-bletchley/recipes-bletchley/plat-tools/files/bletchley-common-functions
@@ -38,6 +38,20 @@
     return 0
 }
 
+wait_gpio_falling()
+{
+    local NET_NAME=$1
+    local TIMEOUT_SEC=$2
+
+    mapfile -t -d " " GPIO_INFO < <(gpiofind "$NET_NAME")
+    if [ "${#GPIO_INFO[@]}" -ne 2 ]; then
+        echo "wait_gpio_falling: can not find gpio, $NET_NAME"
+        return 1
+    fi
+
+    timeout "$TIMEOUT_SEC" gpiomon --falling-edge --num-events=1 "${GPIO_INFO[0]}" "${GPIO_INFO[1]%$'\n'}"
+}
+
 set_fan()
 {
     FAN_ID=$1