wl1251-modules: update the rc script to set driver params
[openpandora.oe.git] / recipes / pandora-system / wl1251-modules / rc.wl1251
1 #!/bin/sh
2 DESC="WL1251 MAC80211 Wireless LAN driver"
3 NAME="wl1251"
4
5 sysfs_path="/sys/bus/mmc/devices/mmc2:0001/mmc2:0001:1"
6 ps_rate_threshold=30000
7 use_fw_ps=Y
8
9 if [ -f /etc/pandora/conf/wl1251 ]; then
10         . /etc/pandora/conf/wl1251
11 fi
12
13 d_stop() {
14         if `grep -q wl1251 /proc/modules` ; then
15                 ifconfig wlan0 down
16                 rmmod board_omap3pandora_wifi wl1251_sdio wl1251 2> /dev/null
17         fi
18 }
19
20 d_start() {
21         wl1251_args=""
22         if modinfo wl1251 2> /dev/null | grep -q '\<use_fw_ps\>'; then
23                 wl1251_args="use_fw_ps=$use_fw_ps"
24         fi
25         modprobe wl1251 $wl1251_args
26         modprobe wl1251_sdio
27         # this does not exist on newer kernels
28         modprobe board-omap3pandora-wifi 2> /dev/null
29
30         # find our phy index, they change every time driver module is reinserted
31         # assume our interface is wlan0
32         phy_idx=0
33         for a in `seq 20` ; do
34                 if [ -e /sys/class/net/wlan0 ] ; then
35                         phy_idx=$(cat /sys/class/net/wlan0/phy80211/index)
36                         break
37                 else
38                         sleep 0.2
39                 fi
40         done
41
42         # restore phy related LED triggers (they come from mac80211.ko)
43         if [ -e /sys/class/leds/ ] ; then
44                 for led in /sys/class/leds/* ; do
45                         trigger=$(grep "$(basename $led)" /etc/default/leds | grep phy | \
46                                         awk '{print $2}' | sed -e 's/.*phy[0-9]*\(.*\)/\1/')
47                         if [ "x$trigger" != "x" ] ; then
48                                 echo "phy${phy_idx}$trigger" > "$led/trigger"
49                         fi
50                 done
51         fi
52
53         # some driver configuration
54         if [ -d "$sysfs_path" ]; then
55                 test -n "$ps_rate_threshold" && echo "$ps_rate_threshold" > $sysfs_path/ps_rate_threshold
56                 test -n "$long_doze_mode" && echo "$long_doze_mode" > $sysfs_path/long_doze_mode
57         fi
58 }
59
60 case "$1" in
61   start)
62         echo -n "Starting $DESC: $NAME"
63         d_start &
64         echo "."
65         ;;
66   stop)
67         echo -n "Stopping $DESC: $NAME"
68         d_stop
69         echo "."
70         ;;
71   restart|force-reload)
72         echo -n "Restarting $DESC: $NAME"
73         d_stop
74         sleep 1
75         d_start
76         echo "."
77         ;;
78   *)
79         echo "Usage: $0 {start|stop|restart|force-reload}" >&2
80         exit 1
81         ;;
82 esac
83
84 exit 0