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/plat-svc/files/bletchley-early-sys-init b/meta-facebook/meta-bletchley/recipes-bletchley/plat-svc/files/bletchley-early-sys-init
index 2d41c94..a0b5c5a 100755
--- a/meta-facebook/meta-bletchley/recipes-bletchley/plat-svc/files/bletchley-early-sys-init
+++ b/meta-facebook/meta-bletchley/recipes-bletchley/plat-svc/files/bletchley-early-sys-init
@@ -1,61 +1,7 @@
#!/bin/bash -e
-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
-}
-
-set_fan()
-{
- FAN_ID=$1
- FAN_DUTY=$2
- SYSFA_PWM_PATH=""
-
- for file in /sys/devices/platform/pwm-fan"$FAN_ID"/hwmon/hwmon*/pwm1
- do
- if [ -e "$file" ]; then
- SYSFA_PWM_PATH="$file"
- break
- fi
- done
-
- if [ -z "$SYSFA_PWM_PATH" ]; then
- echo "set_fan: pwm file not found, chekc fan id ($FAN_ID)"
- return 1
- fi
-
- if [ "$FAN_DUTY" -lt 0 ] || [ "$FAN_DUTY" -gt 100 ]; then
- echo "set_fan: incorrect fan duty, $FAN_DUTY"
- return 1
- fi
-
- # convert duty (0-100) to pwm value (0-255)
- PWM_VAL=$(printf "%.0f" $((FAN_DUTY*255/100)))
-
- echo -n "set_fan: set fan$FAN_ID = $FAN_DUTY"
- if ! echo "$PWM_VAL" > "$SYSFA_PWM_PATH"; then
- echo " failed"
- return 1
- fi
-
- echo " success"
- return 0
-}
+# shellcheck source=meta-facebook/meta-bletchley/recipes-bletchley/plat-tools/files/bletchley-common-functions
+source /usr/libexec/bletchley-common-functions
# set initial value for GPIO output pins
set_gpio SEL_SPI2_MUX 1