op_bluetooth_work: workaround BT freezes
[openpandora.oe.git] / recipes / pandora-system / pandora-scripts / op_bluetooth_work.sh
1 #!/bin/sh
2
3 kernel_major=`uname -r | cut -c 1`
4 if [ "$kernel_major" = "2" ]; then
5         # new kernel only (for now)
6         exit 0
7 fi
8
9 if [ "$1" = "1" ]; then
10         if [ ! -e /sys/class/gpio/gpio15/value ]; then
11                 echo 15 > /sys/class/gpio/export
12                 sleep 0.2
13                 echo out > /sys/class/gpio/gpio15/direction
14         fi
15         echo 0 > /sys/devices/platform/omap_uart.0/sleep_timeout
16         echo 1 > /sys/class/gpio/gpio15/value
17         hciattach /dev/ttyO0 texasalt 3000000
18         INTERFACE="`hciconfig | grep "^hci" | cut -d ':' -f 1`"
19         if [ -z "$INTERFACE" ]; then
20                 killall hciattach
21                 echo 0 > /sys/class/gpio/gpio15/value
22                 exit 1
23         fi
24         echo 255 > '/sys/class/leds/pandora::bluetooth/brightness'
25         exit 0
26 elif [ "$1" = "0" ]; then
27         killall hciattach
28         echo 0 > /sys/class/gpio/gpio15/value
29         echo 0 > '/sys/class/leds/pandora::bluetooth/brightness'
30         echo 10 > /sys/devices/platform/omap_uart.0/sleep_timeout
31         exit 0
32 else
33         echo "invalid argument"
34         exit 1
35 fi
36