summaryrefslogtreecommitdiff
path: root/recipes-kernel/rsi-91x/files/rs9113_load_modules.sh
blob: 3977a5c2d486183b2f9e945b1a76a0256f2540d0 (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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!/bin/bash

UNBIND=/sys/devices/soc0/soc/2100000.aips-bus/2190000.usdhc/driver/unbind
if [[ -f $UNBIND ]] ; then
    echo 2190000.usdhc >$UNBIND
fi
sleep 1

BIND="/sys/bus/soc/devices/soc0/soc/2100000.aips-bus/2190000.usdhc/subsystem/drivers/sdhci-esdhc-imx/bind"
if [[ -f $BIND ]] ; then
    echo 2190000.usdhc >$BIND
fi

defaults=/etc/default/rs9113
usage()
{
	echo "Configuration values:"
	echo "	COEX_MODE"
	echo "	COUNTRY_CODE"
	echo "	RSI_ANTENNA_DIVERSITY"
	echo "	ANT_SEL_VAL"
	echo "	RX_DATA_INACTIVE_INTERVAL"
	echo "  SLEEP_IND_GPIO_SEL"
	echo "  ULP_GPIO_READ"
	echo "  ULP_GPIO_WRITE"
 	echo "	PS_SLEEP_TYPE"
	echo "	MAX_SP_LEN"
	echo "  ENABLED_UAPSD"
	echo "  LP_HANDSHAKE_MODE"
	echo "  ULP_HANDSHAKE_MODE"
	echo "  PEER_DIST"
	echo "  BT_FEATURE_BITMAP"
	echo "  UART_DEBUG"
	echo "  EXT_OPT"
	echo "  BLE_ROLES"
	echo "  BT_BDR_MODE"
	echo "  THREE_WIRE_COEX"
	echo "  ANCHOR_POINT_GAP"
	echo "  HOST_INTF_ON_DEMAND"
	echo "  SLEEP_CLK_SOURCE_SEL"
	echo "  FEATURE_BITMAP_9116"
	echo "  ENABLE_40MHZ_IN_2G"
	echo "  XTAL_GOOD_TIME"
	echo "  RSI_ZONE_ENABLED"
	echo "Usage: $(basename $0) [config file]"
	echo ""
	echo "Config file is typically
		/etc/default/rs9113 with the above parameters."
	exit 1
}
if (($# > 1)); then
  usage
fi

if ((${#COEX_MODE}==0)) && [[ -r $defaults ]]; then
  set -e
  . $defaults
  set +e
fi

if (($# > 0)) && [[ -r $1 ]]; then
  set -e
  . $1
  set +e
fi
  
err=0
for x in COEX_MODE RSI_ANTENNA_DIVERSITY ANT_SEL_VAL ; do
  if [[ -z ${!x} ]] ; then
    echo Need to provide ${x} for configuration
    err=1
  fi
done

if((err)) ; then
  usage
fi

: ${COUNTRY_CODE:=00}
logger -s -p daemon.error "Using COUNTRY_CODE $COUNTRY_CODE"
cd /opt/rs9113/modules

# Remove cfg80211 if not the correct regulatory domain
if [[ $(lsmod) =~ [[:space:]]cfg80211[[:space:]] ]] ; then
  if ! [[ $(iw reg get) =~ [[:space:]]country[[:space:]]${COUNTRY_CODE}: ]] ; then
     logger -s -p daemon.alert "Removing modules related to cfg80211 to set up country code"
     /usr/sbin/rs9113_remove_modules.sh
  fi
fi
if [[ $(lsmod) =~ [[:space:]]cfg80211[[:space:]] ]] ; then
   logger -s -p daemon.error "ERROR: cfg80211 will not remove."
fi

modprobe cfg80211 ieee80211_regdom="$COUNTRY_CODE" 2>&1
modprobe mac80211
modprobe bluetooth

# rs9116
# dev_oper_mode
# 1 STA or AP
# 4 BT EDR
# 5 STA and BT EDR
# 6 AP and BT EDR
# 8 BT LE
# 9 STA and BT LE
# 10 AP and BT LE
# 12 BT EDR and BT LE
# 13 STA and BT EDR and BT LE
# 14 AP and BT EDR and BT LE
usbd="rsi_usb.ko"
sdiod="rsi_sdio.ko"
rsid="rsi_91x.ko"

case ${COEX_MODE} in
  1|2|3)
    DEV_OPER_MODE=1
    ;;
  4)
    DEV_OPER_MODE=4
    usbd="rsi_btusb.ko"
    sdiod="rsi_btsdio.ko"
    rsid="rsi_bt91x.ko"
    ;;
  5)
    DEV_OPER_MODE=5
    ;;
  6)
    DEV_OPER_MODE=6
    ;;
  8)
    DEV_OPER_MODE=8
    usbd="rsi_btusb.ko"
    sdiod="rsi_btsdio.ko"
    rsid="rsi_bt91x.ko"
    ;;
  9)
    DEV_OPER_MODE=9
    ;;
  10)
    DEV_OPER_MODE=10
    ;;
  12)
    DEV_OPER_MODE=12
    usbd="rsi_btusb.ko"
    sdiod="rsi_btsdio.ko"
    rsid="rsi_bt91x.ko"
    ;;
  13)
    DEV_OPER_MODE=13
    ;;
  14)
    DEV_OPER_MODE=14
    ;;
   *)
    logger -s -p daemon.error "Coexistance mode $COEX_MODE does not exist"
    usage9116
  esac

# Modes 4,8,12 require BT only driver

PARAMS=" dev_oper_mode=$DEV_OPER_MODE antenna_diversity=$RSI_ANTENNA_DIVERSITY antenna_sel=$ANT_SEL_VAL"

RS9116_VARS="RSI_ZONE_ENABLED LP_HANDSHAKE_MODE ULP_HANDSHAKE_MODE"
RS9116_VARS+=" BT_FEATURE_BITMAP CONFIG_PEER_DISTANCE ENABLE_40MHZ_IN_2G"
RS9116_VARS+=" THREE_WIRE_COEX ANCHOR_POINT_GAP HOST_INTF_ON_DEMAND"
RS9116_VARS+=" SLEEP_CLK_SOURCE_SEL FEATURE_BITMAP_9116"


for v in ${RS9116_VARS} ; do
    if [[ -n ${!v} ]] ; then
        PARAMS += ${v,,}=${!v}
    fi
done

hosts=$(find /sys/devices -type d -name mmc_host)

shim=$usbd
for d in $hosts ; do
    vendor=$(find $d -type f -name vendor)
    devname=$(find $d -type f -name device)
    if [[ -n $vendor ]] ; then
        VENDOR=$(cat $vendor)
    fi
    if [[ -n $vendor ]] ; then
        DEVNAME=$(cat $devname)
    fi
    if [[ $VENDOR == 0x041b ]] && [[ $DEVNAME == 0x9116 ]] ; then
        shim=$sdiod
    fi
done

#Use awk to split a very long line.
if ! insmod $rsid $PARAMS ; then
	echo "Failed: insmod $rsid $PARAMS" |  awk '{printf gensub("(.{0,60})","\\1\n","g")}' | logger -s -t rs9113_load_modules.sh -p daemon.error
fi
insmod $shim
# Wait for driver to load
((count=0))
while ((count < 10)) ; do
    if [[ -L /sys/class/bluetooth/hci0 ]] || [[ -L /sys/class/net/wlan0 ]] ; then
	break;
    fi
    usleep 100000
    ((count++))
done