summaryrefslogtreecommitdiff
path: root/recipes-kernel/rs9113/files/rs9113/rs9113.init
blob: d9fb21e4577c6756f87738d38e42c1b3f923e393 (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
#!/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

case "$1" in
  start)
    if ((RS9113_LOAD == 0)) ; then
	# We don't want the driver loaded.
	exit 0
    fi
    # Reset the RS9113 chip is ready, and
    # wait for it to settle.
    count=0
    while : ; do
        if [ -f "$RS9113_RESET" ] ; then
            echo 1 >$RS9113_RESET
            usleep $SLEEPTIME
            echo 0 >$RS9113_RESET
            usleep $SLEEPTIME
            echo 1 >$RS9113_RESET
            N=1
            while [ $N -lt 20 ] ; do
                INT=$(cat $RS9113_INT)
                if ((INT != 1)) ; then
                    usleep $INTSLEEPTIME
                else
                    break
                fi
            done
            if [ $INT -ne 1 ] ; then
                logger -t rs9113 -p error -s "$RS9113_INT is $INT"
            fi
        else
            # No WiFi BT, so exit quietly
            exit 0
        fi
        if /usr/bin/lsusb -d 1618:9113 >/dev/null ; then
            break
        fi
        sleep 15
        ((count++))
        if ((count > 5)) ; then
           logger -t rs9113 -p error -s "RS9113 not found after $count resets"
           break
        fi
    done
    /usr/bin/logger -t "rs9113" -p info -s "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)
    /usr/bin/logger -t "rs9113" -p info -s "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
    ;;
  *)
    "Usage: $0 {start|stop|status|restart}"
    exit 2
    ;;
esac

exit 0