Add Gear S2 firmware
[platform/adaptation/bluetooth-firmware-bcm.git] / scripts / bt-dev-start-exynos3250.sh
1 #!/bin/sh
2
3 GREP="/bin/grep"
4 MKNOD="/bin/mknod"
5 AWK="/usr/bin/awk"
6 RFKILL="/usr/sbin/rfkill"
7 CP="/bin/cp"
8
9 #
10 # Script for registering Broadcom UART BT device
11 #
12 BT_UART_DEVICE=/dev/ttySAC0
13 BT_CHIP_TYPE=bcm2035
14 BCM_TOOL=/usr/bin/bcmtool_4343w
15
16 BCM_TOOL_DBG_LOG=/var/lib/bluetooth/bcmtool_log
17
18 # If you want to enable bcmtool debug log, please uncomment below #
19 #ENABLE_BCMTOOL_DEBUG="-DEBUG"
20
21 HCI_CONFIG=/usr/bin/hciconfig
22 HCI_ATTACH=/usr/bin/hciattach
23
24 BT_ADDR=/csa/bluetooth/.bd_addr
25 BCM_WIFI_CID=/opt/etc/.cid.info
26
27 SYSLOG_PATH=/var/log/messages
28
29 UART_SPEED=3000000
30
31 #Firmware Loading timeout:  Unit * 100ms
32 # Example : 34 is 3.4 sec
33 TIMEOUT=34
34
35 HARDWARE=`grep Hardware /proc/cpuinfo | awk "{print \\$3}"`
36 REVISION=`grep Revision /proc/cpuinfo | awk "{print \\$3}"`
37 BCM_PACKAGING_TYPE=`cat ${BCM_WIFI_CID}`
38
39 BCM_FIRMWARE="BCM4343A1_001.002.009.0035.0096_ORC_Orbis_WC1-S.hcd"
40
41 if [ "$HARDWARE" == "WC1-S" ] && ( [ "$REVISION" == "0000" ] || [ "$REVISION" == "0001" ] )
42 then
43         BCM_FIRMWARE="BCM4334W0_001.002.003.0014.0017_Ponte_Solo_Semco_B58_13.5dBm.hcd"
44 else
45         if [ "${BCM_PACKAGING_TYPE}" == "semco" ] || [ "${BCM_PACKAGING_TYPE}" == "samsung" ] ; then
46                 BCM_FIRMWARE="BCM4343A1_001.002.009.0035.0096_ORC_Orbis_WC1-S.hcd"
47                 echo "Package type is semco"
48         elif [ "${BCM_PACKAGING_TYPE}" == "murata" ] ; then
49                 BCM_FIRMWARE="BCM4343A1_001.002.009.0022.0050_Murata_Type-1FR.hcd"
50                 echo "Package type is murata"
51         else
52                 echo "Package type is not detected(${BCM_PACKAGING_TYPE})"
53         fi
54 fi
55
56 BCM_CHIP_NAME="BCM4343W"
57
58 echo "Check for Bluetooth device status"
59 if (${HCI_CONFIG} | grep hci); then
60         echo "Bluetooth device is UP"
61         ${HCI_CONFIG} hci0 up
62         exit 1
63 fi
64
65 ${RFKILL} unblock bluetooth
66
67 echo "BCM_FIRMWARE: $BCM_FIRMWARE, HARDWARE: $HARDWARE, REVISION: $REVISION"
68
69 # Set BT address: This will internally check for the file presence
70 /usr/bin/setbd
71
72 #if the setbd return non 0, which means incorrect bd address file, then exit
73 if [ $? -ne 0 ]
74 then
75         exit 1
76 fi
77
78 echo "Registering Bluetooth device"
79
80 $BCM_TOOL $BT_UART_DEVICE -TYPE=${BCM_CHIP_NAME} $ENABLE_BCMTOOL_DEBUG \
81         -FILE=/usr/etc/bluetooth/$BCM_FIRMWARE -BAUD=$UART_SPEED \
82         -ADDR=$BT_ADDR >$BCM_TOOL_DBG_LOG  2>&1 &
83 bcmtool_pid=$!
84
85 #Check next timeout seconds for bcmtool success
86 for (( i=1; i<=$TIMEOUT; i++))
87 do
88         sleep 0.1
89         kill -0 $bcmtool_pid
90         bcmtool_alive=$?
91
92         if [ $i -eq $TIMEOUT ]
93         then
94                 echo "time expired happen $i"
95                 kill -TERM $bcmtool_pid
96                 /usr/sbin/rfkill block bluetooth
97                 ${CP} $SYSLOG_PATH /var/lib/bluetooth/
98                 exit 1
99         fi
100
101         if [ $bcmtool_alive -eq 0 ]
102         then
103                 echo "Continue....$i"
104                 continue
105         else
106                 echo "Break.......$i"
107                 break
108         fi
109 done
110
111 # Attaching Broadcom device
112 if (${HCI_ATTACH} $BT_UART_DEVICE -s $UART_SPEED $BT_CHIP_TYPE $UART_SPEED flow); then
113         /bin/sleep 0.1
114         echo "HCIATTACH success"
115 else
116         echo "HCIATTACH failed"
117         ${RFKILL} block bluetooth
118         ${CP} $SYSLOG_PATH /var/lib/bluetooth/
119 fi