From 284d483bdf2742334221ad10f9e9b151c540368f Mon Sep 17 00:00:00 2001 From: John Klug Date: Tue, 11 Oct 2016 16:34:03 -0500 Subject: Fix missing resets. --- recipes-bsp/multitech/mts-io/mts-io.init | 111 ++++++++++++++++++++++--------- 1 file changed, 80 insertions(+), 31 deletions(-) (limited to 'recipes-bsp/multitech') diff --git a/recipes-bsp/multitech/mts-io/mts-io.init b/recipes-bsp/multitech/mts-io/mts-io.init index 03bb5b0..45d45df 100644 --- a/recipes-bsp/multitech/mts-io/mts-io.init +++ b/recipes-bsp/multitech/mts-io/mts-io.init @@ -10,74 +10,106 @@ ### END INIT INFO ((fail=0)) +# To log debug, set LOGDBG to /usr/bin/LOGGER +if ((DEBUG)) ; then + LOGDBG=/usr/bin/logger +else + LOGDBG=":" +fi +${LOGDBG} -p daemon.info 'mts-io script' sysdir=/sys/devices/platform/mts-io gpiodir=/sys/class/gpio USBRST=${sysdir}/usbhub-reset -RST[0]="${sysdir}/mtq-reset" -RST[1]="${sysdir}/ap1-reset" -RST[2]="${sysdir}/ap2-reset" -RST[3]="${sysdir}/gnss-reset" -RST[4]="${sysdir}/secure-reset" -RST[5]="${sysdir}/eth-reset" -RS9113RST="${sysdir}/wifi-bt-reset" +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}/gnss-reset" +RST[7]="${sysdir}/secure-reset" +RST[8]="${sysdir}/eth-reset" +RST[9]="${sysdir}/sm1-reset" -USLPTIME=30000 # 30 milliseconds from Redpine Signals Reset Spec + +USLPTIME=60000 # 30 milliseconds from Redpine Signals Reset Spec WAIT="/bin/busybox usleep ${USLPTIME}" reset_path() { pin=$1 - /usr/bin/logger -t "mts-io" -p info Reset $pin - + ${LOGDBG} -t "mts-io" -p daemon.info Reset $pin if [[ -f ${pin} ]] ; then if ! ( (echo 1 >${pin}) && (echo 0 >${pin}) && ${WAIT} && (echo 1 >${pin}) ) ; then - /usr/bin/logger -t "mts-io" -p error -s "Failed write to ${pin}" + /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 - /usr/bin/logger -t "mts-io" -p error -s "${pin} does not exist" - return 1 + ${LOGDBG} -t "mts-io" -p daemon.info "${pin} does not exist" fi return 0 } reset_array() { + fail=0 ((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 error -s "Failed write to ${RST[$i]}" + /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 - /usr/bin/logger -t "mts-io" -p info -s "${RST[$i]} does not exist" + ${LOGDBG} -t "mts-io" -p daemon.info "${RST[$i]} does not exist" RST[$i]="" fi ((i--)) done - while ((i>0)) ; do - if ((${#RST[$i] > 0)) && [[ -f ${RST[$i]} ]] ; then + ((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 error -s "Failed write to ${RST[$i]}" + /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 - /usr/bin/logger -t "mts-io" -p info -s "${RST[$i]} does not exist" + ${LOGDBG} -t "mts-io" -p daemon.info "${RST[$i]} does not exist" fi + ((i--)) done ${WAIT} - 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 error -s "Failed write to ${RST[$i]}" + ((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 - /usr/bin/logger -t "mts-io" -p info -s "${RST[$i]} does not exist" + ${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="" - mts_hw_version="" if [[ -d $sysdir/ap1 ]]; then ap1_product_id=$(cat $sysdir/ap1/product-id) @@ -91,17 +123,17 @@ mfser_init() { found_ap1=0 if [[ $ap1_product_id =~ ^MTAC-MFSER- ]]; then - /usr/bin/logger -t "mts-io" -p info -s "Linking /dev/mfser to /dev/ttyAP1" + /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 info -s "Linking /dev/mfser-2 to /dev/ttyAP2" + /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 info -s "Linking /dev/mfser to /dev/ttyAP2" + /usr/bin/logger -t "mts-io" -p daemon.info -s "Linking /dev/mfser to /dev/ttyAP2" ln -sf /dev/ttyAP2 /dev/mfser fi fi @@ -110,15 +142,16 @@ mfser_init() { case $1 in start) - /usr/bin/logger -t "mts-io" -p info -s "Loading mts-io module" + /usr/bin/logger -t "mts-io" -p daemon.info -s "Loading mts-io module" if ! modprobe mts_io ; then ((fail++)) fi + /usr/bin/logger -t "mts-io" -p daemon.info -s "Resetting system modules" read_card_info if ! reset_path $USBRST ; then ((fail++)) fi - /bin/busybox usleep 100000 + /bin/busybox usleep $USLPTIME reset_array mts-io-sysfs store radio-reset 0 mfser_init @@ -135,7 +168,7 @@ case $1 in ;; stop) - /usr/bin/logger -t "mts-io" -p info -s "Unloading mts-io module" + /usr/bin/logger -t "mts-io" -p daemon.info -s "Unloading mts-io module" modprobe -r mts_io RETVAL=$? if ((RETVAL == 0)) ; then @@ -149,6 +182,22 @@ case $1 in 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 + mts-io-sysfs store radio-reset 0 + mfser_init + if ((fail == 0)) ; then + echo "OK" + else + echo "FAIL" + fi + exit $fail + ;; status) if [[ -d ${sysdir} ]] ; then echo Driver is loaded -- cgit v1.2.3