meta-bletchley: introduce Bletchley common functions
Add a common functions script for reusing the functions which are
called frequently.
This patch depends on the patchs below:
* https://lore.kernel.org/all/20220613095150.21917-4-potin.lai.pt@gmail.com/
Signed-off-by: Potin Lai <potin.lai@quantatw.com>
Change-Id: I6e1602b00f1b0a19e77506be6eabe18c796e52fe
diff --git a/meta-facebook/meta-bletchley/recipes-bletchley/motor-ctrl/files/power-ctrl b/meta-facebook/meta-bletchley/recipes-bletchley/motor-ctrl/files/power-ctrl
index def4689..e430f8f 100755
--- a/meta-facebook/meta-bletchley/recipes-bletchley/motor-ctrl/files/power-ctrl
+++ b/meta-facebook/meta-bletchley/recipes-bletchley/motor-ctrl/files/power-ctrl
@@ -6,6 +6,9 @@
export PATH=$PATH:/usr/sbin:/usr/libexec
+# shellcheck source=meta-facebook/meta-bletchley/recipes-bletchley/plat-tools/files/bletchley-common-functions
+source /usr/libexec/bletchley-common-functions
+
DELAY_POWER_ON="0.5"
DELAY_POWER_OFF="5"
DELAY_POWER_RECOVERY_MODE="10"
@@ -189,42 +192,6 @@
echo "$bus"
}
-function set_gpio()
-{
- NET_NAME=$1
- OUT_VAL=$2
- mapfile -t -d " " GPIO_INFO < <(gpiofind "$NET_NAME")
- if [ "${#GPIO_INFO[@]}" -ne 2 ]; then
- echo "set_gpio: can not find gpio, $NET_NAME"
- return 1
- fi
- echo -n "set_gpio: set $NET_NAME = $OUT_VAL"
- if ! gpioset "${GPIO_INFO[0]}" "${GPIO_INFO[1]%$'\n'}"="$OUT_VAL"; then
- echo " failed"
- return 1
- fi
- echo " success"
- return 0
-}
-
-function get_gpio()
-{
- NET_NAME=$1
- RET_VAL=2
-
- mapfile -t -d " " GPIO_INFO < <(gpiofind "$NET_NAME")
- if [ "${#GPIO_INFO[@]}" -ne 2 ]; then
- echo "get_gpio: can not find gpio, $NET_NAME" >&2
- return 1
- fi
- if ! RET_VAL=$(gpioget "${GPIO_INFO[0]}" "${GPIO_INFO[1]%$'\n'}") ; then
- echo "get_gpio: get ${NET_NAME} failed" >&2
- return 1
- fi
- echo "${RET_VAL}"
- return 0
-}
-
function get_ac_status()
{
i2c_bus=$(get_bus_num "$1")
@@ -619,8 +586,7 @@
fi
#Check if sled is present
-SLED_PRESENT=$(get_gpio "presence-sled${SLED_NUM}")
-if [ "$SLED_PRESENT" != 0 ];then
+if ! is_sled_present "${SLED_NUM}"; then
echo "${SLED} is not present!"
exit 1
elif ! is_valid_sled_action "$ACTION"; then