summaryrefslogtreecommitdiff
path: root/recipes-bsp/multitech/mts-io/mts-io.init
diff options
context:
space:
mode:
Diffstat (limited to 'recipes-bsp/multitech/mts-io/mts-io.init')
-rwxr-xr-xrecipes-bsp/multitech/mts-io/mts-io.init405
1 files changed, 405 insertions, 0 deletions
diff --git a/recipes-bsp/multitech/mts-io/mts-io.init b/recipes-bsp/multitech/mts-io/mts-io.init
new file mode 100755
index 0000000..966d5ae
--- /dev/null
+++ b/recipes-bsp/multitech/mts-io/mts-io.init
@@ -0,0 +1,405 @@
+#!/bin/bash
+### BEGIN INIT INFO
+# Provides: mts-io
+# Default-Start: S
+# Default-Stop:
+# Short-Description: load the mts-io driver
+# Description: mts-io driver initializes the Conduit hardware and
+# provides user mode access through the driver to the
+# Conduit features.
+### END INIT INFO
+
+. /etc/default/mts-io
+
+i2c=/sys/bus/i2c/devices/
+GPSCONFIGTYPE="/var/run/config/gpstype"
+DEVTREE="/sys/kernel/config/device-tree/overlays/"
+
+((fail=0))
+# To log debug, set LOGDBG to /usr/bin/LOGGER
+if ((DEBUG)) ; then
+ LOGDBG=/usr/bin/logger
+ ${LOGDBG} -t "mts-io" -p daemon.info -s "LOGDBG turned on"
+else
+ LOGDBG=":"
+fi
+
+hw=""
+hw_name=""
+MTAC_MODULES=""
+((HASAP=0))
+
+sethwtype() {
+ # mts-io must be loaded before trying this
+ hw=$(${SYSFS} show hw-version)
+ hw_name=(${hw//-/ })
+
+ # Only MTCDT and MTCDTIP have accessory cards, and
+ # MTCDTIPHP does not have accessory cards.
+ ((HASAP==0))
+ case $hw_name in
+ MTCDTIPHP)
+ ;;
+ MTCDT|MTCDTIP)
+ ((HASAP = 1))
+ ;;
+ *)
+ ;;
+ esac
+ MTAC_MODULES=$(cd /lib/modules/$(uname -r)/extra/;ls mtac_* 2>/dev/null)
+}
+
+setdevtree() {
+ # add device tree overlays, if they exist.
+ [[ -d /lib/dtoverlays ]] || return 1
+ (
+ cd /lib/dtoverlays
+ for f in $(ls ${hw}*) ; do
+ if ! [[ -d ${DEVTREE} ]] ; then
+ mount configfs
+ fi
+ f1=${f/#${hw}-/}
+ f2=${f1/%.dtbo}
+ # f2 is the extracted device name
+ /bin/mkdir ${DEVTREE}/$f2
+ /bin/cat $f >${DEVTREE}/$f2/dtbo
+ done
+ )
+}
+
+
+SYSFS="/usr/sbin/mts-io-sysfs"
+LRST="/usr/sbin/mts-util-lora2-reset"
+
+${LOGDBG} -p daemon.info 'mts-io script'
+sysdir=/sys/devices/platform/mts-io
+gpiodir=/sys/class/gpio
+port1=${sysdir}/ap1
+port2=${sysdir}/ap2
+
+USBRST=${sysdir}/usbhub-reset
+NEED_I2C_RESET=0
+HWVER=""
+HWNAME=""
+HWLVL=""
+
+
+RST[0]="${sysdir}/wifi-bt-reset"
+RST[1]="${sysdir}/mtq-reset"
+RST[2]="${sysdir}/ap1/reset"
+RST[3]="${sysdir}/ap1/creset"
+RST[4]="${sysdir}/ap2/reset"
+RST[5]="${sysdir}/ap2/creset"
+RST[6]="${sysdir}/secure-reset"
+RST[7]="${sysdir}/eth-reset"
+RST[8]="${sysdir}/sm1-reset"
+
+# GPSGNSSRESET is now set low during boot and is special cased.
+#if ((GPSGNSSRESET)) ; then
+# RST[9]="${sysdir}/gnss-reset"
+#fi
+
+WPIN[0]="${sysdir}/ap1/cdone"
+WPIN[1]="${sysdir}/ap2/cdone"
+
+USLPTIME=60000 # 30 milliseconds from Redpine Signals Reset Spec
+WAIT="/bin/busybox usleep ${USLPTIME}"
+
+# Wait 10 WAIT intervals for pins to come high
+waitpins() {
+ ((i=0))
+ while((i < ${#WPIN[@]})) ; do
+ ((j=0))
+ while [[ -r ${WPIN[$i]} ]] && ! (($(cat ${WPIN[$i]}))) ; do
+ logger -t "mts-io" -p daemon.error -s "Wait on ${WPIN[$i]}"
+ ${WAIT}
+ ((j++))
+ if ((j > 10)) ; then
+ ((fail++))
+ ${LOGDBG} -t "mts-io" -p daemon.error -s "Ready failure on ${WPIN[$i]}"
+ break
+ fi
+ done
+ ((i++))
+ done
+}
+
+reset_path() {
+ pin=$1
+ ${LOGDBG} -t "mts-io" -p daemon.info Reset $pin
+ if [[ -f ${pin} ]] ; then
+ if ! ( (echo 1 >${pin}) && ${WAIT} && (echo 0 >${pin}) && ${WAIT} && (echo 1 >${pin}) ) ; then
+ /usr/bin/logger -t "mts-io" -p daemon.error -s "Failed write to ${pin}"
+ return 1
+ fi
+ sleep 2
+
+ ${LOGDBG} -t "mts-io" -p daemon.info Completeed reset $pin
+ else
+ ${LOGDBG} -t "mts-io" -p daemon.info "${pin} does not exist"
+ fi
+ return 0
+}
+reset_array() {
+ ((i=${#RST[@]}-1))
+ while ((i>=0)) ; do
+ if [[ -f ${RST[$i]} ]] ; then
+ if ! ( (echo 1 >${RST[i]}) ) ; then
+ /usr/bin/logger -t "mts-io" -p daemon.error -s "Failed write to ${RST[$i]}"
+ fail=1
+ else
+ ${LOGDBG} -t "mts-io" -p daemon.error -s "Wrote 1 to ${RST[$i]}"
+ fi
+ else
+ ${LOGDBG} -t "mts-io" -p daemon.info "${RST[$i]} does not exist"
+ RST[$i]=""
+ fi
+ ((i--))
+ done
+ ((DBG)) && (cd $sysdir ; head gnss-reset eth-reset wifi-bt-reset usbhub-reset | logger -p daemon.info)
+ ((i=${#RST[@]}-1))
+ while ((i>=0)) ; do
+ ${LOGDBG} -s -p daemon.info "i value is $i RST is ${RST[$i]} count is ${#RST[$i]}"
+ if ((${#RST[$i]} > 0)) && [[ -f ${RST[$i]} ]] ; then
+ if ! ( (echo 0 >${RST[i]}) ) ; then
+ /usr/bin/logger -t "mts-io" -p daemon.error -s "Failed write to ${RST[$i]}"
+ fail=1
+ else
+ ${LOGDBG} -t "mts-io" -p daemon.error -s "Wrote 0 to ${RST[$i]}"
+ :
+ fi
+ else
+ ${LOGDBG} -t "mts-io" -p daemon.info "${RST[$i]} does not exist"
+ fi
+ ((i--))
+ done
+ ${WAIT}
+ ((DBG)) && (cd $sysdir ; head gnss-reset eth-reset wifi-bt-reset usbhub-reset | logger -p daemon.info)
+ ((i=${#RST[@]}-1))
+ while ((i>=0)) ; do
+ if ((${#RST[$i]} > 0)) && [[ -f ${RST[$i]} ]] ; then
+ if ! ( (echo 1 >${RST[$i]}) ) ; then
+ /usr/bin/logger -t "mts-io" -p daemon.error -s "Failed write to ${RST[$i]}"
+ fail=1
+ else
+ ${LOGDBG} -t "mts-io" -p daemon.error -s "Wrote 1 to ${RST[$i]}"
+ fi
+ else
+ ${LOGDBG} -t "mts-io" -p daemon.info "${RST[$i]} does not exist"
+ fi
+ ((i--))
+ done
+ ((DBG)) && (cd $sysdir ; head gnss-reset eth-reset wifi-bt-reset usbhub-reset | logger -p daemon.info)
+ return $fail
+}
+read_card_info() {
+ ap1_product_id=""
+ ap2_product_id=""
+
+ if [[ -d $sysdir/ap1 ]]; then
+ ap1_product_id=$(cat $sysdir/ap1/product-id)
+ fi
+ if [[ -d $sysdir/ap2 ]]; then
+ ap2_product_id=$(cat $sysdir/ap2/product-id)
+ fi
+
+ lora_hw=$(${SYSFS} show lora/hw-version 2> /dev/null)
+
+ if [ -d $port1 ] && [[ $(cat $port1/hw-version) = $lora_hw ]]; then
+ modprobe spidev
+ ln -sf /dev/spidev32766.2 /dev/spidev0.0
+ elif [ -d $port2 ] && [[ $(cat $port2/hw-version) = $lora_hw ]]; then
+ modprobe spidev
+ ln -sf /dev/spidev32765.2 /dev/spidev0.0
+ elif [[ ${hw_name} == MTCAP ]]; then
+ modprobe spidev
+ elif [[ ${hw_name} == MTCDTIPHP ]]; then
+ modprobe spidev
+ ln -sf /dev/spidev32766.2 /dev/spidev0.0
+ fi
+}
+
+mfser_init() {
+ found_ap1=0
+
+ if [[ $ap1_product_id =~ ^MTAC-MFSER- ]]; then
+ /usr/bin/logger -t "mts-io" -p daemon.info -s "Linking /dev/mfser to /dev/ttyAP1"
+ ln -sf /dev/ttyAP1 /dev/mfser
+ found_ap1=1
+ fi
+
+ if [[ $ap2_product_id =~ ^MTAC-MFSER- ]]; then
+ if [[ $found_ap1 = 1 ]]; then
+ /usr/bin/logger -t "mts-io" -p daemon.info -s "Linking /dev/mfser-2 to /dev/ttyAP2"
+ ln -sf /dev/ttyAP2 /dev/mfser-2
+ else
+ /usr/bin/logger -t "mts-io" -p daemon.info -s "Linking /dev/mfser to /dev/ttyAP2"
+ ln -sf /dev/ttyAP2 /dev/mfser
+ fi
+ fi
+
+}
+
+set_gpslink() {
+ [[ -d /var/run/config ]] || mkdir /var/run/config
+ gpscap=$(cat ${sysdir}/capability/gps)
+
+ # For all hardware except MTCDTIPHP, the gpscapability
+ # flag indicates whether or not we have a GPS.
+ if ! [[ ${hw_name} =~ ^MTCDTIPHP$ ]] && ((gpscap == 0)) ; then
+ return
+ fi
+
+ # Oldest MTRV1 uses venuse on ttyS1.
+ if [[ ${hw_name} == MTRV1 ]] && [[ ${hw} != MTRV1-0.0 ]] ; then
+ ln -sf /dev/ttyXRUSB0 /dev/gps0
+ echo "u-blox" >"$GPSCONFIGTYPE"
+ return
+ fi
+
+ if [[ ${hw_name} == MTR ]] || [[ ${hw_name} == MTRV1 ]] || [[ ${hw_name} == MTHS ]] ; then
+ ln -sf /dev/ttyS1 /dev/gps0
+ echo "venus" >"$GPSCONFIGTYPE"
+ return
+ fi
+
+ if [[ ${hw} == MTCDT ]] && [[ ${HWLVL} == 0.0 ]] ; then
+ # No GPS
+ return
+ fi
+ if [[ ${hw_name} == MTCDTIPHP ]] ; then
+ NEED_I2C_RESET=1
+ ln -sf /dev/ttyXRUSB0 /dev/gps0
+ return
+ fi
+ # Default MTCDT-0.1
+ echo "u-blox" >"$GPSCONFIGTYPE"
+ ln -sf /dev/ttyXRUSB2 /dev/gps0
+}
+
+case $1 in
+ start)
+ # Point the firmware API at our i2c EEPROMs
+ echo -n ${i2c} > /sys/module/firmware_class/parameters/path
+
+ /usr/bin/logger -t "mts-io" -p daemon.info -s "Loading mts-io module"
+ if ! modprobe mts_io ; then
+ ((fail++))
+ fi
+
+ sethwtype
+ setdevtree
+
+ if ((HASAP == 1)) ; then
+ # install mtac explicitly or any unused modules will cause
+ # junk to the log as mtac is loaded and unloaded each time.
+ modprobe mtac
+ for f in ${MTAC_MODULES} ; do
+ modprobe ${f//.ko} 2>&1 | grep -v 'No such device or address'
+ done
+ fi
+ set_gpslink # Set GPS symlink.
+ /usr/bin/logger -t "mts-io" -p daemon.info -s "Resetting system modules"
+ read_card_info
+ has_gnss_reset=0
+ # On boot, gnss-reset will be low
+ if [[ -f ${sysdir}/gnss-reset ]] ; then
+ if (($(mts-io-sysfs show gnss-reset) == 1)) ; then
+ mts-io-sysfs store gnss-reset 0
+ fi
+ has_gnss_reset=1
+ fi
+ /bin/busybox usleep $USLPTIME
+ reset_array
+ if ((has_gnss_reset)) ; then
+ mts-io-sysfs store gnss-reset 1
+ fi
+ # use radio-reset init script for radio-reset
+ mfser_init
+
+ waitpins
+ # Fix Telit error -62 and Redpine wrong USB speed detection on reset.
+ sleep 1
+ if ! reset_path $USBRST ; then
+ ((fail++))
+ fi
+
+ if ((${#lora_hw} > 0)) && [[ ${lora_hw} =~ ^MTCDTIPHP-LORA-2\.1 ]] ; then
+ if [[ -x ${LRST} ]] ; then
+ ${LRST} -g -f
+ else
+ /usr/bin/logger -t "mts-io" -p daemon.err -s "ERROR: Missing ${LRST} -- Cannot initialize LoRa."
+ fi
+ fi
+
+ if [[ -d ${DEVTREE} ]] ; then
+ /bin/umount configfs
+ fi
+
+ if ((fail == 0)) ; then
+ echo "OK"
+ else
+ echo "FAIL"
+ fi
+ exit $fail
+ ;;
+
+ stop)
+ /usr/bin/logger -t "mts-io" -p daemon.info -s "Unloading mtac modules and mts-io module"
+ MTAC_MODULES=$(lsmod | grep '^mtac_' | sed -e 's/_/-/' -e 's/ .*//')
+
+ for f in ${MTAC_MODULES} ; do
+ if ! modprobe -r "$f" ; then
+ rmmod "$f"
+ fi
+ done
+ if ! modprobe -r mtac ; then
+ rmmod mtac
+ fi
+
+ if ! modprobe -r mts-io ; then
+ rmmod mtsio
+ fi
+ RETVAL=$?
+ if ((RETVAL == 0)) ; then
+ echo "OK"
+ else
+ echo "FAIL"
+ fi
+ ;;
+ restart)
+ $0 stop
+ sleep 1
+ $0 start
+ ;;
+ reload)
+ /usr/bin/logger -t "mts-io" -p daemon.info -s "Resetting system modules"
+ if ! reset_path $USBRST ; then
+ ((fail++))
+ fi
+ /bin/busybox usleep $USLPTIME
+ reset_array
+ # Use radio-reset init script for radio-reset
+ mfser_init
+ if ((fail == 0)) ; then
+ echo "OK"
+ else
+ echo "FAIL"
+ fi
+ exit $fail
+ ;;
+ status)
+ if [[ -d ${sysdir} ]] ; then
+ echo Driver is loaded
+ exit 0
+ else
+ echo Driver is not loaded
+ exit 3
+ fi
+ ;;
+ *)
+ echo "Usage: $0 {start|stop|status|restart}"
+ exit 2
+ ;;
+esac
+