summaryrefslogtreecommitdiff
path: root/recipes-kernel/rsi-91x/files/rs9113.init
blob: 2f570cfd7a357a9cb1a76954388e33405cfbf48f (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
#!/bin/bash
# Note that none of the INIT stuff below works in the current open-embedded.
### BEGIN INIT INFO
# Provides: rs9116
# Required-Start: mts-io
# Default-Start:  S
# Default-Stop:   0 6
# X-Start-Before: networking
# Short-Description: load the rs9116 drivers
# Description: rs9116 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
RS9116_RESET=${MTS_IODIR}/wifi-bt-reset

[ -f $CONFIG ] || exit 1

. $CONFIG

pid=$$
LOG_ERR=3
LOG_INFO=6
name=rs91x
format="%s[%d] %12.2fs: %s"
function has_reset {
    for i in {1..10} ; do
        if [[ -f $RS9116_RESET ]] ; then
            if [[ -f $RS9116_RESET ]] ; then
                return 0
            fi
            return 1
        fi
        usleep $SLEEPTIME
    done
    return 1
}

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 rs9116_reset {

    for i in {1..10} ; do
        if [[ -f $RS9116_RESET ]] ; then
            break
        fi
        usleep 10000
    done
        
    # Reset the RS9116 chip is ready, and
    # wait for it to settle.
        if [[ -f $RS9116_RESET ]] ; then
            echo 0 >$RS9116_RESET
            usleep $SLEEPTIME
            echo 1 >$RS9116_RESET
        else
            # No WiFi BT, but return 0 for development
            return 0
        fi
}

case "$1" in
  start)
    if ((RS9113_LOAD == 0)) ; then
	# We don't want the driver loaded.
	exit 0
    fi
    rs9116_reset
    syslog $LOG_INFO "Loading rs91x modules with COEX=$COEX_MODE and Country=$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 rs91x 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)
    rs9116_reset
    ;;
  *)
    echo "Usage: $0 {start|stop|status|restart|reset}"
    exit 2
    ;;
esac

exit 0