summaryrefslogtreecommitdiff
path: root/recipes-kernel/rs9113/files/rs9113/rs9113.init
blob: d5b31ec54dc852831a85aac37cccd12f46bdd5e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/bash
# Note that none of the INIT stuff below works in the current open-embedded.
### BEGIN INIT INFO
# Provides: rs9113
# Required-Start: mts-io
# Default-Start:  S
# Default-Stop:   0 6
# X-Start-Before: networking
# Short-Description: load the rs9113 drivers
# Description: rs9113 drivers are used to provide access to Bluetooth
#	       and WiFi.
### END INIT INFO

CONFIG=${CONFIG:-/etc/default/rs9113}
MTS_IODIR=/sys/devices/platform/mts-io
RS9113_RESET=${MTS_IODIR}/wifi-bt-reset
RS9113_INT=${MTS_IODIR}/wifi-bt-int
RS9113_WKUP=${MTS_IODIR}/wifi-bt-lpwkup

[ -f $CONFIG ] || exit 1

. $CONFIG

pid=$$
LOG_ERR=3
LOG_INFO=6
name=rs9113
format="%s[%d] %12.2fs: %s"

function syslog {
   pr=$1
   shift
   [[ $(cat /proc/uptime) =~ ([^[:space:]]+) ]]
   s=$(printf "${format}" $name $pid ${BASH_REMATCH[1]}  "$@")
   echo "<${pr}>${s}" >/dev/kmsg
}

function logpipe {
   OIFS="${IFS}"
   IFS=$'\n'
   while read ln ; do
        syslog $1 $ln
   done
   IFS="${OIFS}"
}

function rs9113_reset {
    for i in {1..10} ; do
        if [[ -f $RS9113_RESET ]] ; then
            break
        fi
        usleep 10000
    done
    
    # Reset the RS9113 chip is ready, and
    # wait for it to settle.
    for i in {1..10} ; do
        if [[ -f $RS9113_RESET ]] ; then
            echo 0 >$RS9113_RESET
            usleep $SLEEPTIME
            echo 1 >$RS9113_RESET
        else
            # No WiFi BT, so exit quietly
            exit 0
        fi
        syslog $LOG_INFO "After reset $i complete"
        for j in {0..250} ; do
            if /usr/bin/lsusb -d 1618:9113 ; then
                syslog $LOG_INFO "lsusb found 1618:9113 after reset $i"
                break 2
            fi
            usleep 100000
        done
        if ((i > 1)) ; then
           syslog $LOG_ERR "RS9113 not found after $i resets"
           /usr/bin/lsusb | logpipe $LOG_ERR
        fi
    done
}

case "$1" in
  start)
    if ((RS9113_LOAD == 0)) ; then
	# We don't want the driver loaded.
	exit 0
    fi
    rs9113_reset
    syslog $LOG_INFO "Loading rs9113 modules with COEX=$COEX_MODE and Country=$SET_COUNTRY_CODE"
    /usr/sbin/rs9113_load_modules.sh $CONFIG
    RETVAL=$?
    if [ $RETVAL -eq 0 ] ; then
        echo "OK"
    else
        echo "FAIL"
    fi
    ;;

  stop)
    syslog $LOG_INFO "Unloading rs9113 modules"
    /usr/sbin/rs9113_remove_modules.sh
    RETVAL=$?
    if [ $RETVAL -eq 0 ] ; then
        echo "OK"
    else
        echo "FAIL"
    fi
    ;;
  restart)
    $0 stop   
    sleep 1              
    $0 start    
    ;;
  status)
    for dir in /sys/class/net/rpine[0-9]* ; do
        if [[ -d ${dir} ]] ; then
            echo Driver is loaded
            exit 0
        fi
    done
    echo Driver is not loaded
    exit 3
    ;;
  reset)
    rs9113_reset
    ;;
  *)
    echo "Usage: $0 {start|stop|status|restart|reset}"
    exit 2
    ;;
esac

exit 0