meta-ampere: mtjade: bind smpro driver

Add script to bind smpro driver when the Host is available but it is not
bound before. This helps applications that use smpro driver works.

Tested:
1. Do A/C the system.
2. Turn ON the Host
3. Check if smpro nodes are available
  # ls /sys/bus/i2c/drivers/smpro-core/
  2-004e  2-004f  bind    uevent  unbind

Signed-off-by: Thang Q. Nguyen <thang@os.amperecomputing.com>
Change-Id: I6f96dc1f78ab77dae29bdc266949dcf7845de68c
diff --git a/meta-ampere/meta-common/recipes-ampere/host/ampere-hostctrl/ampere_host_check.sh b/meta-ampere/meta-common/recipes-ampere/host/ampere-hostctrl/ampere_host_check.sh
index 9759b88..ea60fcf 100644
--- a/meta-ampere/meta-common/recipes-ampere/host/ampere-hostctrl/ampere_host_check.sh
+++ b/meta-ampere/meta-common/recipes-ampere/host/ampere-hostctrl/ampere_host_check.sh
@@ -18,6 +18,10 @@
 		Get ss xyz.openbmc_project.Condition.HostFirmware \
 		CurrentFirmwareCondition | cut -d"." -f6)
 	if [ "$st" == "Running\"" ]; then
+		if command -v ampere_driver_binder.sh;
+		then
+			ampere_driver_binder.sh
+		fi
 		exit 0
 	fi
 	sleep 1
diff --git a/meta-ampere/meta-jade/recipes-ampere/platform/ampere-utils.bbappend b/meta-ampere/meta-jade/recipes-ampere/platform/ampere-utils.bbappend
index d3f4f1a..e3a63f1 100644
--- a/meta-ampere/meta-jade/recipes-ampere/platform/ampere-utils.bbappend
+++ b/meta-ampere/meta-jade/recipes-ampere/platform/ampere-utils.bbappend
@@ -6,6 +6,7 @@
                   file://ampere_power_util.sh \
                   file://ampere_firmware_upgrade.sh \
                   file://ampere_flash_bios.sh \
+                  file://ampere_driver_binder.sh \
                  "
 
 do_install:append() {
@@ -15,4 +16,5 @@
     install -m 0755 ${WORKDIR}/ampere_power_util.sh ${D}/${sbindir}/
     install -m 0755 ${WORKDIR}/ampere_firmware_upgrade.sh ${D}/${sbindir}/
     install -m 0755 ${WORKDIR}/ampere_flash_bios.sh ${D}/${sbindir}/
+    install -m 0755 ${WORKDIR}/ampere_driver_binder.sh ${D}/${sbindir}/
 }
diff --git a/meta-ampere/meta-jade/recipes-ampere/platform/ampere-utils/ampere_driver_binder.sh b/meta-ampere/meta-jade/recipes-ampere/platform/ampere-utils/ampere_driver_binder.sh
new file mode 100644
index 0000000..d419019
--- /dev/null
+++ b/meta-ampere/meta-jade/recipes-ampere/platform/ampere-utils/ampere_driver_binder.sh
@@ -0,0 +1,29 @@
+#!/bin/bash
+
+DELAY_BEFORE_BIND=5000000
+# Each driver include driver name and driver path
+declare -a DRIVER_NAMEs=("2-004f"
+                         "2-004e"
+                        )
+# Driver path should include / at the end
+declare -a DRIVER_PATHs=("/sys/bus/i2c/drivers/smpro-core/"
+                         "/sys/bus/i2c/drivers/smpro-core/"
+                        )
+
+# get length of an array
+arraylength=${#DRIVER_NAMEs[@]}
+
+usleep $DELAY_BEFORE_BIND
+# use for loop to read all values and indexes
+for (( i=0; i<"${arraylength}"; i++ ));
+do
+	bindFile="${DRIVER_PATHs[$i]}bind"
+	driverDir="${DRIVER_PATHs[$i]}${DRIVER_NAMEs[$i]}"
+	if [ -d "$driverDir" ]; then
+		echo "Driver ${DRIVER_NAMEs[$i]} is already bound."
+		continue;
+	fi
+	echo "${DRIVER_NAMEs[$i]}" > "$bindFile"
+done
+
+exit 0