dt-bindings: Document the Rockchip RGA bindings
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8723bs / hal / OUTSRC-BTCoexist / HalBtc8192e1Ant.c
1 //============================================================\r
2 // Description:\r
3 //\r
4 // This file is for 8192e1ant Co-exist mechanism\r
5 //\r
6 // History\r
7 // 2012/11/15 Cosa first check in.\r
8 //\r
9 //============================================================\r
10 \r
11 //============================================================\r
12 // include files\r
13 //============================================================\r
14 #include "Mp_Precomp.h"\r
15 #if(BT_30_SUPPORT == 1)\r
16 //============================================================\r
17 // Global variables, these are static variables\r
18 //============================================================\r
19 static COEX_DM_8192E_1ANT               GLCoexDm8192e1Ant;\r
20 static PCOEX_DM_8192E_1ANT      pCoexDm=&GLCoexDm8192e1Ant;\r
21 static COEX_STA_8192E_1ANT              GLCoexSta8192e1Ant;\r
22 static PCOEX_STA_8192E_1ANT     pCoexSta=&GLCoexSta8192e1Ant;\r
23 \r
24 const char *const GLBtInfoSrc8192e1Ant[]={\r
25         "BT Info[wifi fw]",\r
26         "BT Info[bt rsp]",\r
27         "BT Info[bt auto report]",\r
28 };\r
29 \r
30 u4Byte  GLCoexVerDate8192e1Ant=20130729;\r
31 u4Byte  GLCoexVer8192e1Ant=0x10;\r
32 \r
33 //============================================================\r
34 // local function proto type if needed\r
35 //============================================================\r
36 //============================================================\r
37 // local function start with halbtc8192e1ant_\r
38 //============================================================\r
39 u1Byte\r
40 halbtc8192e1ant_BtRssiState(\r
41         u1Byte                  levelNum,\r
42         u1Byte                  rssiThresh,\r
43         u1Byte                  rssiThresh1\r
44         )\r
45 {\r
46         s4Byte                  btRssi=0;\r
47         u1Byte                  btRssiState=pCoexSta->preBtRssiState;\r
48 \r
49         btRssi = pCoexSta->btRssi;\r
50 \r
51         if(levelNum == 2)\r
52         {                       \r
53                 if( (pCoexSta->preBtRssiState == BTC_RSSI_STATE_LOW) ||\r
54                         (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_LOW))\r
55                 {\r
56                         if(btRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8192E_1ANT))\r
57                         {\r
58                                 btRssiState = BTC_RSSI_STATE_HIGH;\r
59                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to High\n"));\r
60                         }\r
61                         else\r
62                         {\r
63                                 btRssiState = BTC_RSSI_STATE_STAY_LOW;\r
64                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at Low\n"));\r
65                         }\r
66                 }\r
67                 else\r
68                 {\r
69                         if(btRssi < rssiThresh)\r
70                         {\r
71                                 btRssiState = BTC_RSSI_STATE_LOW;\r
72                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to Low\n"));\r
73                         }\r
74                         else\r
75                         {\r
76                                 btRssiState = BTC_RSSI_STATE_STAY_HIGH;\r
77                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at High\n"));\r
78                         }\r
79                 }\r
80         }\r
81         else if(levelNum == 3)\r
82         {\r
83                 if(rssiThresh > rssiThresh1)\r
84                 {\r
85                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi thresh error!!\n"));\r
86                         return pCoexSta->preBtRssiState;\r
87                 }\r
88                 \r
89                 if( (pCoexSta->preBtRssiState == BTC_RSSI_STATE_LOW) ||\r
90                         (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_LOW))\r
91                 {\r
92                         if(btRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8192E_1ANT))\r
93                         {\r
94                                 btRssiState = BTC_RSSI_STATE_MEDIUM;\r
95                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to Medium\n"));\r
96                         }\r
97                         else\r
98                         {\r
99                                 btRssiState = BTC_RSSI_STATE_STAY_LOW;\r
100                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at Low\n"));\r
101                         }\r
102                 }\r
103                 else if( (pCoexSta->preBtRssiState == BTC_RSSI_STATE_MEDIUM) ||\r
104                         (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_MEDIUM))\r
105                 {\r
106                         if(btRssi >= (rssiThresh1+BTC_RSSI_COEX_THRESH_TOL_8192E_1ANT))\r
107                         {\r
108                                 btRssiState = BTC_RSSI_STATE_HIGH;\r
109                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to High\n"));\r
110                         }\r
111                         else if(btRssi < rssiThresh)\r
112                         {\r
113                                 btRssiState = BTC_RSSI_STATE_LOW;\r
114                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to Low\n"));\r
115                         }\r
116                         else\r
117                         {\r
118                                 btRssiState = BTC_RSSI_STATE_STAY_MEDIUM;\r
119                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at Medium\n"));\r
120                         }\r
121                 }\r
122                 else\r
123                 {\r
124                         if(btRssi < rssiThresh1)\r
125                         {\r
126                                 btRssiState = BTC_RSSI_STATE_MEDIUM;\r
127                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to Medium\n"));\r
128                         }\r
129                         else\r
130                         {\r
131                                 btRssiState = BTC_RSSI_STATE_STAY_HIGH;\r
132                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at High\n"));\r
133                         }\r
134                 }\r
135         }\r
136                 \r
137         pCoexSta->preBtRssiState = btRssiState;\r
138 \r
139         return btRssiState;\r
140 }\r
141 \r
142 u1Byte\r
143 halbtc8192e1ant_WifiRssiState(\r
144         IN      PBTC_COEXIST            pBtCoexist,\r
145         IN      u1Byte                  index,\r
146         IN      u1Byte                  levelNum,\r
147         IN      u1Byte                  rssiThresh,\r
148         IN      u1Byte                  rssiThresh1\r
149         )\r
150 {\r
151         s4Byte                  wifiRssi=0;\r
152         u1Byte                  wifiRssiState=pCoexSta->preWifiRssiState[index];\r
153 \r
154         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);\r
155         \r
156         if(levelNum == 2)\r
157         {\r
158                 if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_LOW) ||\r
159                         (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_LOW))\r
160                 {\r
161                         if(wifiRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8192E_1ANT))\r
162                         {\r
163                                 wifiRssiState = BTC_RSSI_STATE_HIGH;\r
164                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to High\n"));\r
165                         }\r
166                         else\r
167                         {\r
168                                 wifiRssiState = BTC_RSSI_STATE_STAY_LOW;\r
169                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state stay at Low\n"));\r
170                         }\r
171                 }\r
172                 else\r
173                 {\r
174                         if(wifiRssi < rssiThresh)\r
175                         {\r
176                                 wifiRssiState = BTC_RSSI_STATE_LOW;\r
177                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to Low\n"));\r
178                         }\r
179                         else\r
180                         {\r
181                                 wifiRssiState = BTC_RSSI_STATE_STAY_HIGH;\r
182                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state stay at High\n"));\r
183                         }\r
184                 }\r
185         }\r
186         else if(levelNum == 3)\r
187         {\r
188                 if(rssiThresh > rssiThresh1)\r
189                 {\r
190                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI thresh error!!\n"));\r
191                         return pCoexSta->preWifiRssiState[index];\r
192                 }\r
193                 \r
194                 if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_LOW) ||\r
195                         (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_LOW))\r
196                 {\r
197                         if(wifiRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8192E_1ANT))\r
198                         {\r
199                                 wifiRssiState = BTC_RSSI_STATE_MEDIUM;\r
200                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to Medium\n"));\r
201                         }\r
202                         else\r
203                         {\r
204                                 wifiRssiState = BTC_RSSI_STATE_STAY_LOW;\r
205                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state stay at Low\n"));\r
206                         }\r
207                 }\r
208                 else if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_MEDIUM) ||\r
209                         (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_MEDIUM))\r
210                 {\r
211                         if(wifiRssi >= (rssiThresh1+BTC_RSSI_COEX_THRESH_TOL_8192E_1ANT))\r
212                         {\r
213                                 wifiRssiState = BTC_RSSI_STATE_HIGH;\r
214                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to High\n"));\r
215                         }\r
216                         else if(wifiRssi < rssiThresh)\r
217                         {\r
218                                 wifiRssiState = BTC_RSSI_STATE_LOW;\r
219                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to Low\n"));\r
220                         }\r
221                         else\r
222                         {\r
223                                 wifiRssiState = BTC_RSSI_STATE_STAY_MEDIUM;\r
224                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state stay at Medium\n"));\r
225                         }\r
226                 }\r
227                 else\r
228                 {\r
229                         if(wifiRssi < rssiThresh1)\r
230                         {\r
231                                 wifiRssiState = BTC_RSSI_STATE_MEDIUM;\r
232                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to Medium\n"));\r
233                         }\r
234                         else\r
235                         {\r
236                                 wifiRssiState = BTC_RSSI_STATE_STAY_HIGH;\r
237                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state stay at High\n"));\r
238                         }\r
239                 }\r
240         }\r
241                 \r
242         pCoexSta->preWifiRssiState[index] = wifiRssiState;\r
243 \r
244         return wifiRssiState;\r
245 }\r
246 \r
247 VOID\r
248 halbtc8192e1ant_UpdateRaMask(\r
249         IN      PBTC_COEXIST            pBtCoexist,\r
250         IN      BOOLEAN                         bForceExec,\r
251         IN      u1Byte                          type,\r
252         IN      u4Byte                          rateMask\r
253         )\r
254 {\r
255         if(BTC_RATE_DISABLE == type)\r
256         {\r
257                 pCoexDm->curRaMask |= rateMask;         // disable rate\r
258         }\r
259         else if(BTC_RATE_ENABLE == type)\r
260         {\r
261                 pCoexDm->curRaMask &= ~rateMask;        // enable rate\r
262         }\r
263         \r
264         if( bForceExec || (pCoexDm->preRaMask != pCoexDm->curRaMask))\r
265         {\r
266                 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_UPDATE_RAMASK, &pCoexDm->curRaMask);\r
267         }\r
268         pCoexDm->preRaMask = pCoexDm->curRaMask;\r
269 }\r
270 \r
271 VOID\r
272 halbtc8192e1ant_MonitorBtCtr(\r
273         IN      PBTC_COEXIST            pBtCoexist\r
274         )\r
275 {\r
276         u4Byte                  regHPTxRx, regLPTxRx, u4Tmp;\r
277         u4Byte                  regHPTx=0, regHPRx=0, regLPTx=0, regLPRx=0;\r
278         u1Byte                  u1Tmp;\r
279         \r
280         regHPTxRx = 0x770;\r
281         regLPTxRx = 0x774;\r
282 \r
283         u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regHPTxRx);\r
284         regHPTx = u4Tmp & bMaskLWord;\r
285         regHPRx = (u4Tmp & bMaskHWord)>>16;\r
286 \r
287         u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regLPTxRx);\r
288         regLPTx = u4Tmp & bMaskLWord;\r
289         regLPRx = (u4Tmp & bMaskHWord)>>16;\r
290                 \r
291         pCoexSta->highPriorityTx = regHPTx;\r
292         pCoexSta->highPriorityRx = regHPRx;\r
293         pCoexSta->lowPriorityTx = regLPTx;\r
294         pCoexSta->lowPriorityRx = regLPRx;\r
295 \r
296         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], High Priority Tx/Rx (reg 0x%x)=0x%x(%d)/0x%x(%d)\n", \r
297                 regHPTxRx, regHPTx, regHPTx, regHPRx, regHPRx));\r
298         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], Low Priority Tx/Rx (reg 0x%x)=0x%x(%d)/0x%x(%d)\n", \r
299                 regLPTxRx, regLPTx, regLPTx, regLPRx, regLPRx));\r
300 \r
301         // reset counter\r
302         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0xc);\r
303 }\r
304 \r
305 VOID\r
306 halbtc8192e1ant_QueryBtInfo(\r
307         IN      PBTC_COEXIST            pBtCoexist\r
308         )\r
309 {\r
310         u1Byte                  H2C_Parameter[1] ={0};\r
311 \r
312         pCoexSta->bC2hBtInfoReqSent = TRUE;\r
313 \r
314         H2C_Parameter[0] |= BIT0;       // trigger\r
315 \r
316         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], Query Bt Info, FW write 0x61=0x%x\n", \r
317                 H2C_Parameter[0]));\r
318 \r
319         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x61, 1, H2C_Parameter);\r
320 }\r
321 \r
322 BOOLEAN\r
323 halbtc8192e1ant_IsWifiStatusChanged(\r
324         IN      PBTC_COEXIST            pBtCoexist\r
325         )\r
326 {\r
327         static BOOLEAN  bPreWifiBusy=FALSE, bPreUnder4way=FALSE, bPreBtHsOn=FALSE;\r
328         BOOLEAN bWifiBusy=FALSE, bUnder4way=FALSE, bBtHsOn=FALSE;\r
329         BOOLEAN bWifiConnected=FALSE;\r
330 \r
331         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
332         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);\r
333         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
334         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &bUnder4way);\r
335 \r
336         if(bWifiConnected)\r
337         {\r
338                 if(bWifiBusy != bPreWifiBusy)\r
339                 {\r
340                         bPreWifiBusy = bWifiBusy;\r
341                         return TRUE;\r
342                 }\r
343                 if(bUnder4way != bPreUnder4way)\r
344                 {\r
345                         bPreUnder4way = bUnder4way;\r
346                         return TRUE;\r
347                 }\r
348                 if(bBtHsOn != bPreBtHsOn)\r
349                 {\r
350                         bPreBtHsOn = bBtHsOn;\r
351                         return TRUE;\r
352                 }\r
353         }\r
354 \r
355         return FALSE;\r
356 }\r
357 \r
358 VOID\r
359 halbtc8192e1ant_UpdateBtLinkInfo(\r
360         IN      PBTC_COEXIST            pBtCoexist\r
361         )\r
362 {\r
363         PBTC_BT_LINK_INFO       pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
364 \r
365         pBtLinkInfo->bBtLinkExist = pCoexSta->bBtLinkExist;\r
366         pBtLinkInfo->bScoExist = pCoexSta->bScoExist;\r
367         pBtLinkInfo->bA2dpExist = pCoexSta->bA2dpExist;\r
368         pBtLinkInfo->bPanExist = pCoexSta->bPanExist;\r
369         pBtLinkInfo->bHidExist = pCoexSta->bHidExist;\r
370 \r
371         // check if Sco only\r
372         if( pBtLinkInfo->bScoExist &&\r
373                 !pBtLinkInfo->bA2dpExist &&\r
374                 !pBtLinkInfo->bPanExist &&\r
375                 !pBtLinkInfo->bHidExist )\r
376                 pBtLinkInfo->bScoOnly = TRUE;\r
377         else\r
378                 pBtLinkInfo->bScoOnly = FALSE;\r
379 \r
380         // check if A2dp only\r
381         if( !pBtLinkInfo->bScoExist &&\r
382                 pBtLinkInfo->bA2dpExist &&\r
383                 !pBtLinkInfo->bPanExist &&\r
384                 !pBtLinkInfo->bHidExist )\r
385                 pBtLinkInfo->bA2dpOnly = TRUE;\r
386         else\r
387                 pBtLinkInfo->bA2dpOnly = FALSE;\r
388 \r
389         // check if Pan only\r
390         if( !pBtLinkInfo->bScoExist &&\r
391                 !pBtLinkInfo->bA2dpExist &&\r
392                 pBtLinkInfo->bPanExist &&\r
393                 !pBtLinkInfo->bHidExist )\r
394                 pBtLinkInfo->bPanOnly = TRUE;\r
395         else\r
396                 pBtLinkInfo->bPanOnly = FALSE;\r
397         \r
398         // check if Hid only\r
399         if( !pBtLinkInfo->bScoExist &&\r
400                 !pBtLinkInfo->bA2dpExist &&\r
401                 !pBtLinkInfo->bPanExist &&\r
402                 pBtLinkInfo->bHidExist )\r
403                 pBtLinkInfo->bHidOnly = TRUE;\r
404         else\r
405                 pBtLinkInfo->bHidOnly = FALSE;\r
406 }\r
407 \r
408 u1Byte\r
409 halbtc8192e1ant_ActionAlgorithm(\r
410         IN      PBTC_COEXIST            pBtCoexist\r
411         )\r
412 {\r
413         PBTC_BT_LINK_INFO       pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
414         BOOLEAN                         bBtHsOn=FALSE;\r
415         u1Byte                          algorithm=BT_8192E_1ANT_COEX_ALGO_UNDEFINED;\r
416         u1Byte                          numOfDiffProfile=0;\r
417 \r
418         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
419                 \r
420         if(!pBtLinkInfo->bBtLinkExist)\r
421         {\r
422                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], No BT link exists!!!\n"));\r
423                 return algorithm;\r
424         }\r
425 \r
426         if(pBtLinkInfo->bScoExist)\r
427                 numOfDiffProfile++;\r
428         if(pBtLinkInfo->bHidExist)\r
429                 numOfDiffProfile++;\r
430         if(pBtLinkInfo->bPanExist)\r
431                 numOfDiffProfile++;\r
432         if(pBtLinkInfo->bA2dpExist)\r
433                 numOfDiffProfile++;\r
434         \r
435         if(numOfDiffProfile == 1)\r
436         {\r
437                 if(pBtLinkInfo->bScoExist)\r
438                 {\r
439                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO only\n"));\r
440                         algorithm = BT_8192E_1ANT_COEX_ALGO_SCO;\r
441                 }\r
442                 else\r
443                 {\r
444                         if(pBtLinkInfo->bHidExist)\r
445                         {\r
446                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID only\n"));\r
447                                 algorithm = BT_8192E_1ANT_COEX_ALGO_HID;\r
448                         }\r
449                         else if(pBtLinkInfo->bA2dpExist)\r
450                         {\r
451                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], A2DP only\n"));\r
452                                 algorithm = BT_8192E_1ANT_COEX_ALGO_A2DP;\r
453                         }\r
454                         else if(pBtLinkInfo->bPanExist)\r
455                         {\r
456                                 if(bBtHsOn)\r
457                                 {\r
458                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], PAN(HS) only\n"));\r
459                                         algorithm = BT_8192E_1ANT_COEX_ALGO_PANHS;\r
460                                 }\r
461                                 else\r
462                                 {\r
463                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], PAN(EDR) only\n"));\r
464                                         algorithm = BT_8192E_1ANT_COEX_ALGO_PANEDR;\r
465                                 }\r
466                         }\r
467                 }\r
468         }\r
469         else if(numOfDiffProfile == 2)\r
470         {\r
471                 if(pBtLinkInfo->bScoExist)\r
472                 {\r
473                         if(pBtLinkInfo->bHidExist)\r
474                         {\r
475                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + HID\n"));\r
476                                 algorithm = BT_8192E_1ANT_COEX_ALGO_HID;\r
477                         }\r
478                         else if(pBtLinkInfo->bA2dpExist)\r
479                         {\r
480                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + A2DP ==> SCO\n"));\r
481                                 algorithm = BT_8192E_1ANT_COEX_ALGO_SCO;\r
482                         }\r
483                         else if(pBtLinkInfo->bPanExist)\r
484                         {\r
485                                 if(bBtHsOn)\r
486                                 {\r
487                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + PAN(HS)\n"));\r
488                                         algorithm = BT_8192E_1ANT_COEX_ALGO_SCO;\r
489                                 }\r
490                                 else\r
491                                 {\r
492                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + PAN(EDR)\n"));\r
493                                         algorithm = BT_8192E_1ANT_COEX_ALGO_PANEDR_HID;\r
494                                 }\r
495                         }\r
496                 }\r
497                 else\r
498                 {\r
499                         if( pBtLinkInfo->bHidExist &&\r
500                                 pBtLinkInfo->bA2dpExist )\r
501                         {\r
502                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID + A2DP\n"));\r
503                                 algorithm = BT_8192E_1ANT_COEX_ALGO_HID_A2DP;\r
504                         }\r
505                         else if( pBtLinkInfo->bHidExist &&\r
506                                 pBtLinkInfo->bPanExist )\r
507                         {\r
508                                 if(bBtHsOn)\r
509                                 {\r
510                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID + PAN(HS)\n"));\r
511                                         algorithm = BT_8192E_1ANT_COEX_ALGO_HID_A2DP;\r
512                                 }\r
513                                 else\r
514                                 {\r
515                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID + PAN(EDR)\n"));\r
516                                         algorithm = BT_8192E_1ANT_COEX_ALGO_PANEDR_HID;\r
517                                 }\r
518                         }\r
519                         else if( pBtLinkInfo->bPanExist &&\r
520                                 pBtLinkInfo->bA2dpExist )\r
521                         {\r
522                                 if(bBtHsOn)\r
523                                 {\r
524                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], A2DP + PAN(HS)\n"));\r
525                                         algorithm = BT_8192E_1ANT_COEX_ALGO_A2DP_PANHS;\r
526                                 }\r
527                                 else\r
528                                 {\r
529                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], A2DP + PAN(EDR)\n"));\r
530                                         algorithm = BT_8192E_1ANT_COEX_ALGO_PANEDR_A2DP;\r
531                                 }\r
532                         }\r
533                 }\r
534         }\r
535         else if(numOfDiffProfile == 3)\r
536         {\r
537                 if(pBtLinkInfo->bScoExist)\r
538                 {\r
539                         if( pBtLinkInfo->bHidExist &&\r
540                                 pBtLinkInfo->bA2dpExist )\r
541                         {\r
542                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + HID + A2DP ==> HID\n"));\r
543                                 algorithm = BT_8192E_1ANT_COEX_ALGO_HID;\r
544                         }\r
545                         else if( pBtLinkInfo->bHidExist &&\r
546                                 pBtLinkInfo->bPanExist )\r
547                         {\r
548                                 if(bBtHsOn)\r
549                                 {\r
550                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + HID + PAN(HS)\n"));\r
551                                         algorithm = BT_8192E_1ANT_COEX_ALGO_HID_A2DP;\r
552                                 }\r
553                                 else\r
554                                 {\r
555                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + HID + PAN(EDR)\n"));\r
556                                         algorithm = BT_8192E_1ANT_COEX_ALGO_PANEDR_HID;\r
557                                 }\r
558                         }\r
559                         else if( pBtLinkInfo->bPanExist &&\r
560                                 pBtLinkInfo->bA2dpExist )\r
561                         {\r
562                                 if(bBtHsOn)\r
563                                 {\r
564                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + A2DP + PAN(HS)\n"));\r
565                                         algorithm = BT_8192E_1ANT_COEX_ALGO_SCO;\r
566                                 }\r
567                                 else\r
568                                 {\r
569                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + A2DP + PAN(EDR) ==> HID\n"));\r
570                                         algorithm = BT_8192E_1ANT_COEX_ALGO_PANEDR_HID;\r
571                                 }\r
572                         }\r
573                 }\r
574                 else\r
575                 {\r
576                         if( pBtLinkInfo->bHidExist &&\r
577                                 pBtLinkInfo->bPanExist &&\r
578                                 pBtLinkInfo->bA2dpExist )\r
579                         {\r
580                                 if(bBtHsOn)\r
581                                 {\r
582                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID + A2DP + PAN(HS)\n"));\r
583                                         algorithm = BT_8192E_1ANT_COEX_ALGO_HID_A2DP;\r
584                                 }\r
585                                 else\r
586                                 {\r
587                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID + A2DP + PAN(EDR)\n"));\r
588                                         algorithm = BT_8192E_1ANT_COEX_ALGO_HID_A2DP_PANEDR;\r
589                                 }\r
590                         }\r
591                 }\r
592         }\r
593         else if(numOfDiffProfile >= 3)\r
594         {\r
595                 if(pBtLinkInfo->bScoExist)\r
596                 {\r
597                         if( pBtLinkInfo->bHidExist &&\r
598                                 pBtLinkInfo->bPanExist &&\r
599                                 pBtLinkInfo->bA2dpExist )\r
600                         {\r
601                                 if(bBtHsOn)\r
602                                 {\r
603                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Error!!! SCO + HID + A2DP + PAN(HS)\n"));\r
604 \r
605                                 }\r
606                                 else\r
607                                 {\r
608                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n"));\r
609                                         algorithm = BT_8192E_1ANT_COEX_ALGO_PANEDR_HID;\r
610                                 }\r
611                         }\r
612                 }\r
613         }\r
614 \r
615         return algorithm;\r
616 }\r
617 \r
618 VOID\r
619 halbtc8192e1ant_SetFwDacSwingLevel(\r
620         IN      PBTC_COEXIST            pBtCoexist,\r
621         IN      u1Byte                  dacSwingLvl\r
622         )\r
623 {\r
624         u1Byte                  H2C_Parameter[1] ={0};\r
625 \r
626         // There are several type of dacswing\r
627         // 0x18/ 0x10/ 0xc/ 0x8/ 0x4/ 0x6\r
628         H2C_Parameter[0] = dacSwingLvl;\r
629 \r
630         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], Set Dac Swing Level=0x%x\n", dacSwingLvl));\r
631         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], FW write 0x64=0x%x\n", H2C_Parameter[0]));\r
632 \r
633         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x64, 1, H2C_Parameter);\r
634 }\r
635 \r
636 VOID\r
637 halbtc8192e1ant_SetFwDecBtPwr(\r
638         IN      PBTC_COEXIST            pBtCoexist,\r
639         IN      u1Byte                          decBtPwrLvl\r
640         )\r
641 {\r
642         u1Byte                  H2C_Parameter[1] ={0};\r
643         \r
644         H2C_Parameter[0] = decBtPwrLvl;\r
645 \r
646         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], decrease Bt Power level = %d, FW write 0x62=0x%x\n", \r
647                 decBtPwrLvl, H2C_Parameter[0]));\r
648 \r
649         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x62, 1, H2C_Parameter);\r
650 }\r
651 \r
652 VOID\r
653 halbtc8192e1ant_DecBtPwr(\r
654         IN      PBTC_COEXIST            pBtCoexist,\r
655         IN      BOOLEAN                         bForceExec,\r
656         IN      u1Byte                          decBtPwrLvl\r
657         )\r
658 {\r
659         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], %s Dec BT power level = %d\n",  \r
660                 (bForceExec? "force to":""), decBtPwrLvl));\r
661         pCoexDm->curBtDecPwrLvl = decBtPwrLvl;\r
662 \r
663         if(!bForceExec)\r
664         {\r
665                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], BtDecPwrLvl=%d, curBtDecPwrLvl=%d\n", \r
666                         pCoexDm->preBtDecPwrLvl, pCoexDm->curBtDecPwrLvl));\r
667 \r
668                 if(pCoexDm->preBtDecPwrLvl == pCoexDm->curBtDecPwrLvl) \r
669                         return;\r
670         }\r
671         halbtc8192e1ant_SetFwDecBtPwr(pBtCoexist, pCoexDm->curBtDecPwrLvl);\r
672 \r
673         pCoexDm->preBtDecPwrLvl = pCoexDm->curBtDecPwrLvl;\r
674 }\r
675 \r
676 VOID\r
677 halbtc8192e1ant_SetBtAutoReport(\r
678         IN      PBTC_COEXIST            pBtCoexist,\r
679         IN      BOOLEAN                 bEnableAutoReport\r
680         )\r
681 {\r
682         u1Byte                  H2C_Parameter[1] ={0};\r
683         \r
684         H2C_Parameter[0] = 0;\r
685 \r
686         if(bEnableAutoReport)\r
687         {\r
688                 H2C_Parameter[0] |= BIT0;\r
689         }\r
690 \r
691         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], BT FW auto report : %s, FW write 0x68=0x%x\n", \r
692                 (bEnableAutoReport? "Enabled!!":"Disabled!!"), H2C_Parameter[0]));\r
693 \r
694         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x68, 1, H2C_Parameter);    \r
695 }\r
696 \r
697 VOID\r
698 halbtc8192e1ant_BtAutoReport(\r
699         IN      PBTC_COEXIST            pBtCoexist,\r
700         IN      BOOLEAN                 bForceExec,\r
701         IN      BOOLEAN                 bEnableAutoReport\r
702         )\r
703 {\r
704         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], %s BT Auto report = %s\n",  \r
705                 (bForceExec? "force to":""), ((bEnableAutoReport)? "Enabled":"Disabled")));\r
706         pCoexDm->bCurBtAutoReport = bEnableAutoReport;\r
707 \r
708         if(!bForceExec)\r
709         {\r
710                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], bPreBtAutoReport=%d, bCurBtAutoReport=%d\n", \r
711                         pCoexDm->bPreBtAutoReport, pCoexDm->bCurBtAutoReport));\r
712 \r
713                 if(pCoexDm->bPreBtAutoReport == pCoexDm->bCurBtAutoReport) \r
714                         return;\r
715         }\r
716         halbtc8192e1ant_SetBtAutoReport(pBtCoexist, pCoexDm->bCurBtAutoReport);\r
717 \r
718         pCoexDm->bPreBtAutoReport = pCoexDm->bCurBtAutoReport;\r
719 }\r
720 \r
721 VOID\r
722 halbtc8192e1ant_FwDacSwingLvl(\r
723         IN      PBTC_COEXIST            pBtCoexist,\r
724         IN      BOOLEAN                 bForceExec,\r
725         IN      u1Byte                  fwDacSwingLvl\r
726         )\r
727 {\r
728         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], %s set FW Dac Swing level = %d\n",  \r
729                 (bForceExec? "force to":""), fwDacSwingLvl));\r
730         pCoexDm->curFwDacSwingLvl = fwDacSwingLvl;\r
731 \r
732         if(!bForceExec)\r
733         {\r
734                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], preFwDacSwingLvl=%d, curFwDacSwingLvl=%d\n", \r
735                         pCoexDm->preFwDacSwingLvl, pCoexDm->curFwDacSwingLvl));\r
736 \r
737                 if(pCoexDm->preFwDacSwingLvl == pCoexDm->curFwDacSwingLvl) \r
738                         return;\r
739         }\r
740 \r
741         halbtc8192e1ant_SetFwDacSwingLevel(pBtCoexist, pCoexDm->curFwDacSwingLvl);\r
742 \r
743         pCoexDm->preFwDacSwingLvl = pCoexDm->curFwDacSwingLvl;\r
744 }\r
745 \r
746 VOID\r
747 halbtc8192e1ant_SetSwPenaltyTxRateAdaptive(\r
748         IN      PBTC_COEXIST            pBtCoexist,\r
749         IN      BOOLEAN                 bLowPenaltyRa\r
750         )\r
751 {\r
752         u1Byte  tmpU1;\r
753 \r
754         tmpU1 = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x4fd);\r
755         tmpU1 |= BIT0;\r
756         if(bLowPenaltyRa)\r
757         {\r
758                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], Tx rate adaptive, set low penalty!!\n"));\r
759                 tmpU1 &= ~BIT2;\r
760         }\r
761         else\r
762         {\r
763                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], Tx rate adaptive, set normal!!\n"));\r
764                 tmpU1 |= BIT2;\r
765         }\r
766 \r
767         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x4fd, tmpU1);\r
768 }\r
769 \r
770 VOID\r
771 halbtc8192e1ant_LowPenaltyRa(\r
772         IN      PBTC_COEXIST            pBtCoexist,\r
773         IN      BOOLEAN                 bForceExec,\r
774         IN      BOOLEAN                 bLowPenaltyRa\r
775         )\r
776 {\r
777         return;\r
778         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW, ("[BTCoex], %s turn LowPenaltyRA = %s\n",  \r
779                 (bForceExec? "force to":""), ((bLowPenaltyRa)? "ON":"OFF")));\r
780         pCoexDm->bCurLowPenaltyRa = bLowPenaltyRa;\r
781 \r
782         if(!bForceExec)\r
783         {\r
784                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL, ("[BTCoex], bPreLowPenaltyRa=%d, bCurLowPenaltyRa=%d\n", \r
785                         pCoexDm->bPreLowPenaltyRa, pCoexDm->bCurLowPenaltyRa));\r
786 \r
787                 if(pCoexDm->bPreLowPenaltyRa == pCoexDm->bCurLowPenaltyRa) \r
788                         return;\r
789         }\r
790         halbtc8192e1ant_SetSwPenaltyTxRateAdaptive(pBtCoexist, pCoexDm->bCurLowPenaltyRa);\r
791 \r
792         pCoexDm->bPreLowPenaltyRa = pCoexDm->bCurLowPenaltyRa;\r
793 }\r
794 \r
795 VOID\r
796 halbtc8192e1ant_SetDacSwingReg(\r
797         IN      PBTC_COEXIST            pBtCoexist,\r
798         IN      u4Byte                  level\r
799         )\r
800 {\r
801         u1Byte  val=(u1Byte)level;\r
802 \r
803         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], Write SwDacSwing = 0x%x\n", level));\r
804         pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x883, 0x3e, val);\r
805 }\r
806 \r
807 VOID\r
808 halbtc8192e1ant_SetSwFullTimeDacSwing(\r
809         IN      PBTC_COEXIST            pBtCoexist,\r
810         IN      BOOLEAN                 bSwDacSwingOn,\r
811         IN      u4Byte                  swDacSwingLvl\r
812         )\r
813 {\r
814         if(bSwDacSwingOn)\r
815         {\r
816                 halbtc8192e1ant_SetDacSwingReg(pBtCoexist, swDacSwingLvl);\r
817         }\r
818         else\r
819         {\r
820                 halbtc8192e1ant_SetDacSwingReg(pBtCoexist, 0x18);\r
821         }\r
822 }\r
823 \r
824 VOID\r
825 halbtc8192e1ant_DacSwing(\r
826         IN      PBTC_COEXIST            pBtCoexist,\r
827         IN      BOOLEAN                 bForceExec,\r
828         IN      BOOLEAN                 bDacSwingOn,\r
829         IN      u4Byte                  dacSwingLvl\r
830         )\r
831 {\r
832         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW, ("[BTCoex], %s turn DacSwing=%s, dacSwingLvl=0x%x\n",  \r
833                 (bForceExec? "force to":""), ((bDacSwingOn)? "ON":"OFF"), dacSwingLvl));\r
834         pCoexDm->bCurDacSwingOn = bDacSwingOn;\r
835         pCoexDm->curDacSwingLvl = dacSwingLvl;\r
836 \r
837         if(!bForceExec)\r
838         {\r
839                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL, ("[BTCoex], bPreDacSwingOn=%d, preDacSwingLvl=0x%x, bCurDacSwingOn=%d, curDacSwingLvl=0x%x\n", \r
840                         pCoexDm->bPreDacSwingOn, pCoexDm->preDacSwingLvl,\r
841                         pCoexDm->bCurDacSwingOn, pCoexDm->curDacSwingLvl));\r
842 \r
843                 if( (pCoexDm->bPreDacSwingOn == pCoexDm->bCurDacSwingOn) &&\r
844                         (pCoexDm->preDacSwingLvl == pCoexDm->curDacSwingLvl) )\r
845                         return;\r
846         }\r
847         delay_ms(30);\r
848         halbtc8192e1ant_SetSwFullTimeDacSwing(pBtCoexist, bDacSwingOn, dacSwingLvl);\r
849 \r
850         pCoexDm->bPreDacSwingOn = pCoexDm->bCurDacSwingOn;\r
851         pCoexDm->preDacSwingLvl = pCoexDm->curDacSwingLvl;\r
852 }\r
853 \r
854 VOID\r
855 halbtc8192e1ant_SetCoexTable(\r
856         IN      PBTC_COEXIST    pBtCoexist,\r
857         IN      u4Byte          val0x6c0,\r
858         IN      u4Byte          val0x6c4,\r
859         IN      u4Byte          val0x6c8,\r
860         IN      u1Byte          val0x6cc\r
861         )\r
862 {\r
863         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], set coex table, set 0x6c0=0x%x\n", val0x6c0));\r
864         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c0, val0x6c0);\r
865 \r
866         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], set coex table, set 0x6c4=0x%x\n", val0x6c4));\r
867         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c4, val0x6c4);\r
868 \r
869         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], set coex table, set 0x6c8=0x%x\n", val0x6c8));\r
870         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c8, val0x6c8);\r
871 \r
872         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], set coex table, set 0x6cc=0x%x\n", val0x6cc));\r
873         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cc, val0x6cc);\r
874 }\r
875 \r
876 VOID\r
877 halbtc8192e1ant_CoexTable(\r
878         IN      PBTC_COEXIST            pBtCoexist,\r
879         IN      BOOLEAN                 bForceExec,\r
880         IN      u4Byte                  val0x6c0,\r
881         IN      u4Byte                  val0x6c4,\r
882         IN      u4Byte                  val0x6c8,\r
883         IN      u1Byte                  val0x6cc\r
884         )\r
885 {\r
886         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW, ("[BTCoex], %s write Coex Table 0x6c0=0x%x, 0x6c4=0x%x, 0x6c8=0x%x, 0x6cc=0x%x\n", \r
887                 (bForceExec? "force to":""), val0x6c0, val0x6c4, val0x6c8, val0x6cc));\r
888         pCoexDm->curVal0x6c0 = val0x6c0;\r
889         pCoexDm->curVal0x6c4 = val0x6c4;\r
890         pCoexDm->curVal0x6c8 = val0x6c8;\r
891         pCoexDm->curVal0x6cc = val0x6cc;\r
892 \r
893         if(!bForceExec)\r
894         {\r
895                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL, ("[BTCoex], preVal0x6c0=0x%x, preVal0x6c4=0x%x, preVal0x6c8=0x%x, preVal0x6cc=0x%x !!\n", \r
896                         pCoexDm->preVal0x6c0, pCoexDm->preVal0x6c4, pCoexDm->preVal0x6c8, pCoexDm->preVal0x6cc));\r
897                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL, ("[BTCoex], curVal0x6c0=0x%x, curVal0x6c4=0x%x, curVal0x6c8=0x%x, curVal0x6cc=0x%x !!\n", \r
898                         pCoexDm->curVal0x6c0, pCoexDm->curVal0x6c4, pCoexDm->curVal0x6c8, pCoexDm->curVal0x6cc));\r
899         \r
900                 if( (pCoexDm->preVal0x6c0 == pCoexDm->curVal0x6c0) &&\r
901                         (pCoexDm->preVal0x6c4 == pCoexDm->curVal0x6c4) &&\r
902                         (pCoexDm->preVal0x6c8 == pCoexDm->curVal0x6c8) &&\r
903                         (pCoexDm->preVal0x6cc == pCoexDm->curVal0x6cc) )\r
904                         return;\r
905         }\r
906         halbtc8192e1ant_SetCoexTable(pBtCoexist, val0x6c0, val0x6c4, val0x6c8, val0x6cc);\r
907 \r
908         pCoexDm->preVal0x6c0 = pCoexDm->curVal0x6c0;\r
909         pCoexDm->preVal0x6c4 = pCoexDm->curVal0x6c4;\r
910         pCoexDm->preVal0x6c8 = pCoexDm->curVal0x6c8;\r
911         pCoexDm->preVal0x6cc = pCoexDm->curVal0x6cc;\r
912 }\r
913 \r
914 VOID\r
915 halbtc8192e1ant_CoexTableWithType(\r
916         IN      PBTC_COEXIST            pBtCoexist,\r
917         IN      BOOLEAN                         bForceExec,\r
918         IN      u1Byte                          type\r
919         )\r
920 {\r
921         switch(type)\r
922         {\r
923                 case 0:\r
924                         halbtc8192e1ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0x55555555, 0xffffff, 0x3);\r
925                         break;\r
926                 case 1:\r
927                         halbtc8192e1ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0x5a5a5a5a, 0xffffff, 0x3);\r
928                         break;\r
929                 case 2:\r
930                         halbtc8192e1ant_CoexTable(pBtCoexist, bForceExec, 0x5a5a5a5a, 0x5a5a5a5a, 0xffffff, 0x3);\r
931                         break;\r
932                 case 3:\r
933                         halbtc8192e1ant_CoexTable(pBtCoexist, bForceExec, 0xaaaaaaaa, 0xaaaaaaaa, 0xffffff, 0x3);\r
934                         break;\r
935                 case 4:\r
936                         halbtc8192e1ant_CoexTable(pBtCoexist, bForceExec, 0xffffffff, 0xffffffff, 0xffffff, 0x3);\r
937                         break;\r
938                 case 5:\r
939                         halbtc8192e1ant_CoexTable(pBtCoexist, bForceExec, 0x5fff5fff, 0x5fff5fff, 0xffffff, 0x3);\r
940                         break;\r
941                 case 6:\r
942                         halbtc8192e1ant_CoexTable(pBtCoexist, bForceExec, 0x55ff55ff, 0x5a5a5a5a, 0xffffff, 0x3);\r
943                         break;\r
944                 case 7:\r
945                         halbtc8192e1ant_CoexTable(pBtCoexist, bForceExec, 0xddffddff, 0xddffddff, 0xffffff, 0x3);\r
946                         break;\r
947                 case 8:\r
948                         halbtc8192e1ant_CoexTable(pBtCoexist, bForceExec, 0x55ff55ff, 0x5afa5afa, 0xffffff, 0x3);\r
949                         break;          \r
950                 case 9:\r
951                         halbtc8192e1ant_CoexTable(pBtCoexist, bForceExec, 0x5f5f5f5f, 0x5f5f5f5f, 0xffffff, 0x3);\r
952                         break;\r
953                 default:\r
954                         break;\r
955         }\r
956 }\r
957 \r
958 VOID\r
959 halbtc8192e1ant_SetFwIgnoreWlanAct(\r
960         IN      PBTC_COEXIST            pBtCoexist,\r
961         IN      BOOLEAN                 bEnable\r
962         )\r
963 {\r
964         u1Byte                  H2C_Parameter[1] ={0};\r
965                 \r
966         if(bEnable)\r
967         {\r
968                 H2C_Parameter[0] |= BIT0;               // function enable\r
969         }\r
970         \r
971         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], set FW for BT Ignore Wlan_Act, FW write 0x63=0x%x\n", \r
972                 H2C_Parameter[0]));\r
973 \r
974         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x63, 1, H2C_Parameter);\r
975 }\r
976 \r
977 VOID\r
978 halbtc8192e1ant_IgnoreWlanAct(\r
979         IN      PBTC_COEXIST            pBtCoexist,\r
980         IN      BOOLEAN                 bForceExec,\r
981         IN      BOOLEAN                 bEnable\r
982         )\r
983 {\r
984         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], %s turn Ignore WlanAct %s\n", \r
985                 (bForceExec? "force to":""), (bEnable? "ON":"OFF")));\r
986         pCoexDm->bCurIgnoreWlanAct = bEnable;\r
987 \r
988         if(!bForceExec)\r
989         {\r
990                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], bPreIgnoreWlanAct = %d, bCurIgnoreWlanAct = %d!!\n", \r
991                         pCoexDm->bPreIgnoreWlanAct, pCoexDm->bCurIgnoreWlanAct));\r
992 \r
993                 if(pCoexDm->bPreIgnoreWlanAct == pCoexDm->bCurIgnoreWlanAct)\r
994                         return;\r
995         }\r
996         halbtc8192e1ant_SetFwIgnoreWlanAct(pBtCoexist, bEnable);\r
997 \r
998         pCoexDm->bPreIgnoreWlanAct = pCoexDm->bCurIgnoreWlanAct;\r
999 }\r
1000 \r
1001 VOID\r
1002 halbtc8192e1ant_SetFwPstdma(\r
1003         IN      PBTC_COEXIST            pBtCoexist,\r
1004         IN      u1Byte                  byte1,\r
1005         IN      u1Byte                  byte2,\r
1006         IN      u1Byte                  byte3,\r
1007         IN      u1Byte                  byte4,\r
1008         IN      u1Byte                  byte5\r
1009         )\r
1010 {\r
1011         u1Byte                  H2C_Parameter[5] ={0};\r
1012 \r
1013         H2C_Parameter[0] = byte1;       \r
1014         H2C_Parameter[1] = byte2;       \r
1015         H2C_Parameter[2] = byte3;\r
1016         H2C_Parameter[3] = byte4;\r
1017         H2C_Parameter[4] = byte5;\r
1018 \r
1019         pCoexDm->psTdmaPara[0] = byte1;\r
1020         pCoexDm->psTdmaPara[1] = byte2;\r
1021         pCoexDm->psTdmaPara[2] = byte3;\r
1022         pCoexDm->psTdmaPara[3] = byte4;\r
1023         pCoexDm->psTdmaPara[4] = byte5;\r
1024         \r
1025         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], FW write 0x60(5bytes)=0x%x%08x\n", \r
1026                 H2C_Parameter[0], \r
1027                 H2C_Parameter[1]<<24|H2C_Parameter[2]<<16|H2C_Parameter[3]<<8|H2C_Parameter[4]));\r
1028 \r
1029         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x60, 5, H2C_Parameter);\r
1030 }\r
1031 \r
1032 VOID\r
1033 halbtc8192e1ant_SetLpsRpwm(\r
1034         IN      PBTC_COEXIST            pBtCoexist,\r
1035         IN      u1Byte                  lpsVal,\r
1036         IN      u1Byte                  rpwmVal\r
1037         )\r
1038 {\r
1039         u1Byte  lps=lpsVal;\r
1040         u1Byte  rpwm=rpwmVal;\r
1041         \r
1042         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_LPS_VAL, &lps);\r
1043         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_RPWM_VAL, &rpwm);\r
1044 }\r
1045 \r
1046 VOID\r
1047 halbtc8192e1ant_LpsRpwm(\r
1048         IN      PBTC_COEXIST            pBtCoexist,\r
1049         IN      BOOLEAN                 bForceExec,\r
1050         IN      u1Byte                  lpsVal,\r
1051         IN      u1Byte                  rpwmVal\r
1052         )\r
1053 {\r
1054         BOOLEAN bForceExecPwrCmd=FALSE;\r
1055         \r
1056         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], %s set lps/rpwm=0x%x/0x%x \n", \r
1057                 (bForceExec? "force to":""), lpsVal, rpwmVal));\r
1058         pCoexDm->curLps = lpsVal;\r
1059         pCoexDm->curRpwm = rpwmVal;\r
1060 \r
1061         if(!bForceExec)\r
1062         {\r
1063                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], preLps/curLps=0x%x/0x%x, preRpwm/curRpwm=0x%x/0x%x!!\n", \r
1064                         pCoexDm->preLps, pCoexDm->curLps, pCoexDm->preRpwm, pCoexDm->curRpwm));\r
1065 \r
1066                 if( (pCoexDm->preLps == pCoexDm->curLps) &&\r
1067                         (pCoexDm->preRpwm == pCoexDm->curRpwm) )\r
1068                 {\r
1069                         return;\r
1070                 }\r
1071         }\r
1072         halbtc8192e1ant_SetLpsRpwm(pBtCoexist, lpsVal, rpwmVal);\r
1073 \r
1074         pCoexDm->preLps = pCoexDm->curLps;\r
1075         pCoexDm->preRpwm = pCoexDm->curRpwm;\r
1076 }\r
1077 \r
1078 VOID\r
1079 halbtc8192e1ant_SetAntPath(\r
1080         IN      PBTC_COEXIST            pBtCoexist,\r
1081         IN      u1Byte                          antPosType,\r
1082         IN      BOOLEAN                         bInitHwCfg,\r
1083         IN      BOOLEAN                         bWifiOff\r
1084         )\r
1085 {\r
1086         u4Byte                  u4Tmp=0;\r
1087         \r
1088         if(bInitHwCfg)\r
1089         {       \r
1090                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x944, 0x24);\r
1091                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x930, 0x700700);                \r
1092                 if(pBtCoexist->chipInterface == BTC_INTF_USB)\r
1093                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x64, 0x30430004);\r
1094                 else\r
1095                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x64, 0x30030004);\r
1096 \r
1097                 // 0x4c[27][24]='00', Set Antenna to BB\r
1098                 u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);\r
1099                 u4Tmp &= ~BIT24;\r
1100                 u4Tmp &= ~BIT27;\r
1101                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x4c, u4Tmp);\r
1102         }\r
1103         else if(bWifiOff)\r
1104         {\r
1105                 if(pBtCoexist->chipInterface == BTC_INTF_USB)\r
1106                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x64, 0x30430004);\r
1107                 else\r
1108                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x64, 0x30030004);\r
1109 \r
1110                 // 0x4c[27][24]='11', Set Antenna to BT, 0x64[8:7]=0, 0x64[2]=1\r
1111                 u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);\r
1112                 u4Tmp |= BIT24;\r
1113                 u4Tmp |= BIT27;\r
1114                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x4c, u4Tmp);\r
1115         }\r
1116         \r
1117         // ext switch setting\r
1118         switch(antPosType)\r
1119         {\r
1120                 case BTC_ANT_PATH_WIFI:\r
1121                         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x92c, 0x4);\r
1122                         break;\r
1123                 case BTC_ANT_PATH_BT:\r
1124                         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x92c, 0x20);\r
1125                         break;\r
1126                 default:\r
1127                 case BTC_ANT_PATH_PTA:\r
1128                         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x92c, 0x4);\r
1129                         break;\r
1130         }\r
1131 }\r
1132 \r
1133 VOID\r
1134 halbtc8192e1ant_PsTdma(\r
1135         IN      PBTC_COEXIST            pBtCoexist,\r
1136         IN      BOOLEAN                 bForceExec,\r
1137         IN      BOOLEAN                 bTurnOn,\r
1138         IN      u1Byte                  type\r
1139         )\r
1140 {\r
1141         BOOLEAN                 bTurnOnByCnt=FALSE;\r
1142         u1Byte                  psTdmaTypeByCnt=0, rssiAdjustVal=0;\r
1143 \r
1144         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], %s turn %s PS TDMA, type=%d\n", \r
1145                 (bForceExec? "force to":""), (bTurnOn? "ON":"OFF"), type));\r
1146         pCoexDm->bCurPsTdmaOn = bTurnOn;\r
1147         pCoexDm->curPsTdma = type;\r
1148 \r
1149         if(!bForceExec)\r
1150         {\r
1151                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], bPrePsTdmaOn = %d, bCurPsTdmaOn = %d!!\n", \r
1152                         pCoexDm->bPrePsTdmaOn, pCoexDm->bCurPsTdmaOn));\r
1153                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], prePsTdma = %d, curPsTdma = %d!!\n", \r
1154                         pCoexDm->prePsTdma, pCoexDm->curPsTdma));\r
1155 \r
1156                 if( (pCoexDm->bPrePsTdmaOn == pCoexDm->bCurPsTdmaOn) &&\r
1157                         (pCoexDm->prePsTdma == pCoexDm->curPsTdma) )\r
1158                         return;\r
1159         }\r
1160         if(bTurnOn)\r
1161         {\r
1162                 switch(type)\r
1163                 {\r
1164                         default:\r
1165                                 halbtc8192e1ant_SetFwPstdma(pBtCoexist, 0x53, 0x2c, 0x03, 0x10, 0x50);\r
1166                                 break;\r
1167                         case 1:\r
1168                                 halbtc8192e1ant_SetFwPstdma(pBtCoexist, 0x53, 0x2c, 0x03, 0x10, 0x50);\r
1169                                 rssiAdjustVal = 11;\r
1170                                 break;\r
1171                         case 2:\r
1172                                 halbtc8192e1ant_SetFwPstdma(pBtCoexist, 0x53, 0x25, 0x03, 0x10, 0x50);\r
1173                                 rssiAdjustVal = 14;\r
1174                                 break;\r
1175                         case 3:\r
1176                                 halbtc8192e1ant_SetFwPstdma(pBtCoexist, 0x93, 0x25, 0x3, 0x10, 0x40);\r
1177                                 break;\r
1178                         case 4:\r
1179                                 halbtc8192e1ant_SetFwPstdma(pBtCoexist, 0x93, 0x15, 0x3, 0x14, 0x0);\r
1180                                 rssiAdjustVal = 17;\r
1181                                 break;\r
1182                         case 5:\r
1183                                 halbtc8192e1ant_SetFwPstdma(pBtCoexist, 0x61, 0x15, 0x3, 0x31, 0x0);\r
1184                                 break;\r
1185                         case 6:\r
1186                                 halbtc8192e1ant_SetFwPstdma(pBtCoexist, 0x13, 0xa, 0x3, 0x0, 0x0);\r
1187                                 break;\r
1188                         case 7:\r
1189                                 halbtc8192e1ant_SetFwPstdma(pBtCoexist, 0x13, 0xc, 0x5, 0x0, 0x0);\r
1190                                 break;\r
1191                         case 8: \r
1192                                 halbtc8192e1ant_SetFwPstdma(pBtCoexist, 0x93, 0x25, 0x3, 0x10, 0x0);\r
1193                                 break;\r
1194                         case 9: \r
1195                                 halbtc8192e1ant_SetFwPstdma(pBtCoexist, 0x53, 0x1e, 0x03, 0x10, 0x50);\r
1196                                 rssiAdjustVal = 18;\r
1197                                 break;\r
1198                         case 10:        \r
1199                                 halbtc8192e1ant_SetFwPstdma(pBtCoexist, 0x13, 0xa, 0xa, 0x0, 0x40);\r
1200                                 break;\r
1201                         case 11:        \r
1202                                 halbtc8192e1ant_SetFwPstdma(pBtCoexist, 0x53, 0x12, 0x03, 0x10, 0x50);\r
1203                                 rssiAdjustVal = 20;\r
1204                                 break;\r
1205                         case 12:\r
1206                                 halbtc8192e1ant_SetFwPstdma(pBtCoexist, 0xeb, 0xa, 0x3, 0x31, 0x18);\r
1207                                 break;\r
1208 \r
1209                         case 15:\r
1210                                 halbtc8192e1ant_SetFwPstdma(pBtCoexist, 0x13, 0xa, 0x3, 0x8, 0x0);\r
1211                                 break;\r
1212                         case 16:\r
1213                                 halbtc8192e1ant_SetFwPstdma(pBtCoexist, 0x93, 0x15, 0x3, 0x10, 0x0);\r
1214                                 rssiAdjustVal = 18;\r
1215                                 break;\r
1216 \r
1217                         case 18:\r
1218                                 halbtc8192e1ant_SetFwPstdma(pBtCoexist, 0x93, 0x25, 0x3, 0x10, 0x0);\r
1219                                 rssiAdjustVal = 14;\r
1220                                 break;                  \r
1221                                 \r
1222                         case 20:\r
1223                                 halbtc8192e1ant_SetFwPstdma(pBtCoexist, 0x13, 0x25, 0x25, 0x0, 0x0);\r
1224                                 break;\r
1225                         case 21:\r
1226                                 halbtc8192e1ant_SetFwPstdma(pBtCoexist, 0x93, 0x20, 0x3, 0x10, 0x40);\r
1227                                 break;\r
1228                         case 22:\r
1229                                 halbtc8192e1ant_SetFwPstdma(pBtCoexist, 0x13, 0x8, 0x8, 0x0, 0x40);\r
1230                                 break;\r
1231                         case 23:\r
1232                                 halbtc8192e1ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x3, 0x31, 0x18);\r
1233                                 rssiAdjustVal = 22;\r
1234                                 break;\r
1235                         case 24:\r
1236                                 halbtc8192e1ant_SetFwPstdma(pBtCoexist, 0xe3, 0x15, 0x3, 0x31, 0x18);\r
1237                                 rssiAdjustVal = 22;\r
1238                                 break;\r
1239                         case 25:\r
1240                                 halbtc8192e1ant_SetFwPstdma(pBtCoexist, 0xe3, 0xa, 0x3, 0x31, 0x18);\r
1241                                 rssiAdjustVal = 22;\r
1242                                 break;\r
1243                         case 26:\r
1244                                 halbtc8192e1ant_SetFwPstdma(pBtCoexist, 0xe3, 0xa, 0x3, 0x31, 0x18);\r
1245                                 rssiAdjustVal = 22;\r
1246                                 break;\r
1247                         case 27:\r
1248                                 halbtc8192e1ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x3, 0x31, 0x98);\r
1249                                 rssiAdjustVal = 22;\r
1250                                 break;\r
1251                         case 28:\r
1252                                 halbtc8192e1ant_SetFwPstdma(pBtCoexist, 0x69, 0x25, 0x3, 0x31, 0x0);\r
1253                                 break;\r
1254                         case 29:\r
1255                                 halbtc8192e1ant_SetFwPstdma(pBtCoexist, 0xab, 0x1a, 0x1a, 0x1, 0x10);\r
1256                                 break;\r
1257                         case 30:\r
1258                                 halbtc8192e1ant_SetFwPstdma(pBtCoexist, 0x93, 0x15, 0x3, 0x14, 0x0);\r
1259                                 break;\r
1260                         case 31:\r
1261                                 halbtc8192e1ant_SetFwPstdma(pBtCoexist, 0xd3, 0x1a, 0x1a, 0, 0x58);\r
1262                                 break;\r
1263                         case 32:\r
1264                                 halbtc8192e1ant_SetFwPstdma(pBtCoexist, 0xab, 0xa, 0x3, 0x31, 0x90);\r
1265                                 break;\r
1266                         case 33:\r
1267                                 halbtc8192e1ant_SetFwPstdma(pBtCoexist, 0xa3, 0x25, 0x3, 0x30, 0x90);\r
1268                                 break;\r
1269                         case 34:\r
1270                                 halbtc8192e1ant_SetFwPstdma(pBtCoexist, 0xd3, 0x1a, 0x1a, 0x0, 0x10);\r
1271                                 break;\r
1272                         case 35:\r
1273                                 halbtc8192e1ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0x0, 0x10);\r
1274                                 break;\r
1275                         case 36:\r
1276                                 halbtc8192e1ant_SetFwPstdma(pBtCoexist, 0xd3, 0x12, 0x3, 0x14, 0x50);\r
1277                                 break;\r
1278                         case 37:\r
1279                                 halbtc8192e1ant_SetFwPstdma(pBtCoexist, 0x53, 0x25, 0x3, 0x10, 0x50);\r
1280                                 break;\r
1281                         case 38:\r
1282                                 halbtc8192e1ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x12, 0xe1, 0x90);\r
1283                                 break;\r
1284                 }\r
1285         }\r
1286         else\r
1287         {\r
1288                 // disable PS tdma\r
1289                 switch(type)\r
1290                 {\r
1291                         case 8:         //0x778 = 1, ant2PTA\r
1292                                 halbtc8192e1ant_SetFwPstdma(pBtCoexist, 0x8, 0x0, 0x0, 0x0, 0x0);\r
1293                                 halbtc8192e1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, FALSE, FALSE);\r
1294                                 break;\r
1295                         case 0:         //0x778 = 1, ant2BT\r
1296                         default:\r
1297                                 halbtc8192e1ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x0, 0x0);\r
1298                                 delay_ms(5);\r
1299                                 halbtc8192e1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FALSE, FALSE);\r
1300                                 break;\r
1301                         case 9:         //0x778 = 1, ant2WIFI\r
1302                                 halbtc8192e1ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x0, 0x0);\r
1303                                 halbtc8192e1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_WIFI, FALSE, FALSE);\r
1304                                 break;\r
1305                         case 10:        //0x778 = 3, ant2BT\r
1306                                 halbtc8192e1ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x8, 0x0);\r
1307                                 delay_ms(5);\r
1308                                 halbtc8192e1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FALSE, FALSE);\r
1309                                 break;\r
1310                 }\r
1311         }\r
1312         rssiAdjustVal =0;\r
1313         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE, &rssiAdjustVal);\r
1314 \r
1315         // update pre state\r
1316         pCoexDm->bPrePsTdmaOn = pCoexDm->bCurPsTdmaOn;\r
1317         pCoexDm->prePsTdma = pCoexDm->curPsTdma;\r
1318 }\r
1319 \r
1320 VOID\r
1321 halbtc8192e1ant_SetSwitchSsType(\r
1322         IN      PBTC_COEXIST            pBtCoexist,\r
1323         IN      u1Byte                          ssType\r
1324         )\r
1325 {\r
1326         u1Byte  mimoPs=BTC_MIMO_PS_DYNAMIC;\r
1327 \r
1328         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], REAL set SS Type = %d\n", ssType));\r
1329 \r
1330         if(ssType == 1)\r
1331         {\r
1332                 halbtc8192e1ant_UpdateRaMask(pBtCoexist, FORCE_EXEC, BTC_RATE_DISABLE, 0xfff00000);     // disable 2ss\r
1333                 halbtc8192e1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 0);\r
1334                 // switch ofdm path\r
1335                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0xc04, 0x11);\r
1336                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0xd04, 0x1);\r
1337                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x90c, 0x81111111);\r
1338                 // switch cck patch\r
1339                 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xe77, 0x4, 0x1);\r
1340                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0xa07, 0x81);\r
1341                 mimoPs=BTC_MIMO_PS_STATIC;\r
1342         }\r
1343         else if(ssType == 2)\r
1344         {\r
1345                 halbtc8192e1ant_UpdateRaMask(pBtCoexist, FORCE_EXEC, BTC_RATE_ENABLE, 0xfff00000);      // enable 2ss\r
1346                 halbtc8192e1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8);\r
1347                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0xc04, 0x33);\r
1348                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0xd04, 0x3);\r
1349                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x90c, 0x81121313);\r
1350                 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xe77, 0x4, 0x0);\r
1351                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0xa07, 0x41);\r
1352                 mimoPs=BTC_MIMO_PS_DYNAMIC;\r
1353         }\r
1354         \r
1355         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_SEND_MIMO_PS, &mimoPs);     // set rx 1ss or 2ss\r
1356 }\r
1357 \r
1358 VOID\r
1359 halbtc8192e1ant_SwitchSsType(\r
1360         IN      PBTC_COEXIST            pBtCoexist,\r
1361         IN      BOOLEAN                         bForceExec,\r
1362         IN      u1Byte                          newSsType\r
1363         )\r
1364 {\r
1365         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], %s Switch SS Type = %d\n",  \r
1366                 (bForceExec? "force to":""), newSsType));\r
1367         pCoexDm->curSsType = newSsType;\r
1368 \r
1369         if(!bForceExec)\r
1370         {\r
1371                 if(pCoexDm->preSsType == pCoexDm->curSsType) \r
1372                         return;\r
1373         }\r
1374         halbtc8192e1ant_SetSwitchSsType(pBtCoexist, pCoexDm->curSsType);\r
1375 \r
1376         pCoexDm->preSsType = pCoexDm->curSsType;\r
1377 }\r
1378 \r
1379 VOID\r
1380 halbtc8192e1ant_CoexAllOff(\r
1381         IN      PBTC_COEXIST            pBtCoexist\r
1382         )\r
1383 {\r
1384         halbtc8192e1ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
1385 \r
1386         // hw all off\r
1387         halbtc8192e1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
1388 }\r
1389 \r
1390 BOOLEAN\r
1391 halbtc8192e1ant_IsCommonAction(\r
1392         IN      PBTC_COEXIST            pBtCoexist\r
1393         )\r
1394 {\r
1395         BOOLEAN                 bCommon=FALSE, bWifiConnected=FALSE, bWifiBusy=FALSE;\r
1396 \r
1397         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
1398         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);\r
1399 \r
1400         if(!bWifiConnected && \r
1401                 BT_8192E_1ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus)\r
1402         {\r
1403                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi non connected-idle + BT non connected-idle!!\n"));            \r
1404                 bCommon = TRUE;\r
1405         }\r
1406         else if(bWifiConnected && \r
1407                 (BT_8192E_1ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus) )\r
1408         {\r
1409                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi connected + BT non connected-idle!!\n"));\r
1410 \r
1411                 bCommon = TRUE;\r
1412         }\r
1413         else if(!bWifiConnected && \r
1414                 (BT_8192E_1ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus) )\r
1415         {\r
1416                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi non connected-idle + BT connected-idle!!\n"));\r
1417 \r
1418                 bCommon = TRUE;\r
1419         }\r
1420         else if(bWifiConnected && \r
1421                 (BT_8192E_1ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus) )\r
1422         {\r
1423                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi connected + BT connected-idle!!\n"));\r
1424 \r
1425                 bCommon = TRUE;\r
1426         }\r
1427         else if(!bWifiConnected && \r
1428                 (BT_8192E_1ANT_BT_STATUS_CONNECTED_IDLE != pCoexDm->btStatus) )\r
1429         {\r
1430                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi non connected-idle + BT Busy!!\n"));\r
1431                 \r
1432                 bCommon = TRUE;\r
1433         }\r
1434         else\r
1435         {       \r
1436                 bCommon = FALSE;\r
1437         }\r
1438         \r
1439         return bCommon;\r
1440 }\r
1441 \r
1442 \r
1443 VOID\r
1444 halbtc8192e1ant_TdmaDurationAdjustForAcl(\r
1445         IN      PBTC_COEXIST            pBtCoexist,\r
1446         IN      u1Byte                          wifiStatus\r
1447         )\r
1448 {\r
1449         static s4Byte           up,dn,m,n,WaitCount;\r
1450         s4Byte                  result;   //0: no change, +1: increase WiFi duration, -1: decrease WiFi duration\r
1451         u1Byte                  retryCount=0, btInfoExt;\r
1452 \r
1453         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], TdmaDurationAdjustForAcl()\n"));\r
1454 \r
1455         if( (BT_8192E_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN == wifiStatus) ||\r
1456                 (BT_8192E_1ANT_WIFI_STATUS_CONNECTED_SCAN == wifiStatus) ||\r
1457                 (BT_8192E_1ANT_WIFI_STATUS_CONNECTED_SPECIAL_PKT == wifiStatus) )\r
1458         {\r
1459                 if( pCoexDm->curPsTdma != 1 &&\r
1460                         pCoexDm->curPsTdma != 2 &&\r
1461                         pCoexDm->curPsTdma != 3 &&\r
1462                         pCoexDm->curPsTdma != 9 )\r
1463                 {\r
1464                         halbtc8192e1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
1465                         pCoexDm->psTdmaDuAdjType = 9;\r
1466 \r
1467                         up = 0;\r
1468                         dn = 0;\r
1469                         m = 1;\r
1470                         n= 3;\r
1471                         result = 0;\r
1472                         WaitCount = 0;\r
1473                 }               \r
1474                 return;\r
1475         }\r
1476 \r
1477         if(!pCoexDm->bAutoTdmaAdjust)\r
1478         {\r
1479                 pCoexDm->bAutoTdmaAdjust = TRUE;\r
1480                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], first run TdmaDurationAdjust()!!\n"));\r
1481 \r
1482                 halbtc8192e1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
1483                 pCoexDm->psTdmaDuAdjType = 2;\r
1484                 //============\r
1485                 up = 0;\r
1486                 dn = 0;\r
1487                 m = 1;\r
1488                 n= 3;\r
1489                 result = 0;\r
1490                 WaitCount = 0;\r
1491         }\r
1492         else\r
1493         {\r
1494                 //accquire the BT TRx retry count from BT_Info byte2\r
1495                 retryCount = pCoexSta->btRetryCnt;\r
1496                 btInfoExt = pCoexSta->btInfoExt;\r
1497                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], retryCount = %d\n", retryCount));\r
1498                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], up=%d, dn=%d, m=%d, n=%d, WaitCount=%d\n", \r
1499                         up, dn, m, n, WaitCount));\r
1500                 result = 0;\r
1501                 WaitCount++; \r
1502                   \r
1503                 if(retryCount == 0)  // no retry in the last 2-second duration\r
1504                 {\r
1505                         up++;\r
1506                         dn--;\r
1507 \r
1508                         if (dn <= 0)\r
1509                                 dn = 0;                          \r
1510 \r
1511                         if(up >= n)     // if ³sÄò n ­Ó2¬í retry count¬°0, «h½Õ¼eWiFi duration\r
1512                         {\r
1513                                 WaitCount = 0; \r
1514                                 n = 3;\r
1515                                 up = 0;\r
1516                                 dn = 0;\r
1517                                 result = 1; \r
1518                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], Increase wifi duration!!\n"));\r
1519                         }\r
1520                 }\r
1521                 else if (retryCount <= 3)       // <=3 retry in the last 2-second duration\r
1522                 {\r
1523                         up--; \r
1524                         dn++;\r
1525 \r
1526                         if (up <= 0)\r
1527                                 up = 0;\r
1528 \r
1529                         if (dn == 2)    // if ³sÄò 2 ­Ó2¬í retry count< 3, «h½Õ¯¶WiFi duration\r
1530                         {\r
1531                                 if (WaitCount <= 2)\r
1532                                         m++; // ÁקK¤@ª½¦b¨â­Ólevel¤¤¨Ó¦^\r
1533                                 else\r
1534                                         m = 1;\r
1535 \r
1536                                 if ( m >= 20) //m ³Ì¤j­È = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration.\r
1537                                         m = 20;\r
1538 \r
1539                                 n = 3*m;\r
1540                                 up = 0;\r
1541                                 dn = 0;\r
1542                                 WaitCount = 0;\r
1543                                 result = -1; \r
1544                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], Decrease wifi duration for retryCounter<3!!\n"));\r
1545                         }\r
1546                 }\r
1547                 else  //retry count > 3, ¥u­n1¦¸ retry count > 3, «h½Õ¯¶WiFi duration\r
1548                 {\r
1549                         if (WaitCount == 1)\r
1550                                 m++; // ÁקK¤@ª½¦b¨â­Ólevel¤¤¨Ó¦^\r
1551                         else\r
1552                                 m = 1;\r
1553 \r
1554                         if ( m >= 20) //m ³Ì¤j­È = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration.\r
1555                                 m = 20;\r
1556 \r
1557                         n = 3*m;\r
1558                         up = 0;\r
1559                         dn = 0;\r
1560                         WaitCount = 0; \r
1561                         result = -1;\r
1562                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], Decrease wifi duration for retryCounter>3!!\n"));\r
1563                 }\r
1564 \r
1565                 if(result == -1)\r
1566                 {\r
1567                         if( (BT_INFO_8192E_1ANT_A2DP_BASIC_RATE(btInfoExt)) &&\r
1568                                 ((pCoexDm->curPsTdma == 1) ||(pCoexDm->curPsTdma == 2)) )\r
1569                         {\r
1570                                 halbtc8192e1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
1571                                 pCoexDm->psTdmaDuAdjType = 9;\r
1572                         }\r
1573                         else if(pCoexDm->curPsTdma == 1)\r
1574                         {\r
1575                                 halbtc8192e1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
1576                                 pCoexDm->psTdmaDuAdjType = 2;\r
1577                         }\r
1578                         else if(pCoexDm->curPsTdma == 2)\r
1579                         {\r
1580                                 halbtc8192e1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
1581                                 pCoexDm->psTdmaDuAdjType = 9;\r
1582                         }\r
1583                         else if(pCoexDm->curPsTdma == 9)\r
1584                         {\r
1585                                 halbtc8192e1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
1586                                 pCoexDm->psTdmaDuAdjType = 11;\r
1587                         }\r
1588                 }\r
1589                 else if(result == 1)\r
1590                 {\r
1591                         if( (BT_INFO_8192E_1ANT_A2DP_BASIC_RATE(btInfoExt)) &&\r
1592                                 ((pCoexDm->curPsTdma == 1) ||(pCoexDm->curPsTdma == 2)) )\r
1593                         {\r
1594                                 halbtc8192e1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
1595                                 pCoexDm->psTdmaDuAdjType = 9;\r
1596                         }\r
1597                         else if(pCoexDm->curPsTdma == 11)\r
1598                         {\r
1599                                 halbtc8192e1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
1600                                 pCoexDm->psTdmaDuAdjType = 9;\r
1601                         }\r
1602                         else if(pCoexDm->curPsTdma == 9)\r
1603                         {\r
1604                                 halbtc8192e1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
1605                                 pCoexDm->psTdmaDuAdjType = 2;\r
1606                         }\r
1607                         else if(pCoexDm->curPsTdma == 2)\r
1608                         {\r
1609                                 halbtc8192e1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);\r
1610                                 pCoexDm->psTdmaDuAdjType = 1;\r
1611                         }\r
1612                 }\r
1613 \r
1614                 if( pCoexDm->curPsTdma != 1 &&\r
1615                         pCoexDm->curPsTdma != 2 &&\r
1616                         pCoexDm->curPsTdma != 9 &&\r
1617                         pCoexDm->curPsTdma != 11 )\r
1618                 {\r
1619                         // recover to previous adjust type\r
1620                         halbtc8192e1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, pCoexDm->psTdmaDuAdjType);\r
1621                 }\r
1622         }\r
1623 }\r
1624 \r
1625 u1Byte\r
1626 halbtc8192e1ant_PsTdmaTypeByWifiRssi(\r
1627         IN      s4Byte  wifiRssi,\r
1628         IN      s4Byte  preWifiRssi,\r
1629         IN      u1Byte  wifiRssiThresh\r
1630         )\r
1631 {\r
1632         u1Byte  psTdmaType=0;\r
1633         \r
1634         if(wifiRssi > preWifiRssi)\r
1635         {\r
1636                 if(wifiRssi > (wifiRssiThresh+5))\r
1637                 {\r
1638                         psTdmaType = 26;\r
1639                 }\r
1640                 else\r
1641                 {\r
1642                         psTdmaType = 25;\r
1643                 }\r
1644         }\r
1645         else\r
1646         {\r
1647                 if(wifiRssi > wifiRssiThresh)\r
1648                 {\r
1649                         psTdmaType = 26;\r
1650                 }\r
1651                 else\r
1652                 {\r
1653                         psTdmaType = 25;\r
1654                 }\r
1655         }\r
1656 \r
1657         return psTdmaType;\r
1658 }\r
1659 \r
1660 VOID\r
1661 halbtc8192e1ant_PsTdmaCheckForPowerSaveState(\r
1662         IN      PBTC_COEXIST            pBtCoexist,\r
1663         IN      BOOLEAN                 bNewPsState\r
1664         )\r
1665 {\r
1666         u1Byte  lpsMode=0x0;\r
1667 \r
1668         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_LPS_MODE, &lpsMode);\r
1669         \r
1670         if(lpsMode)     // already under LPS state\r
1671         {\r
1672                 if(bNewPsState)         \r
1673                 {\r
1674                         // keep state under LPS, do nothing.\r
1675                 }\r
1676                 else\r
1677                 {\r
1678                         // will leave LPS state, turn off psTdma first\r
1679                         halbtc8192e1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
1680                 }\r
1681         }\r
1682         else                                            // NO PS state\r
1683         {\r
1684                 if(bNewPsState)\r
1685                 {\r
1686                         // will enter LPS state, turn off psTdma first\r
1687                         halbtc8192e1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
1688                 }\r
1689                 else\r
1690                 {\r
1691                         // keep state under NO PS state, do nothing.\r
1692                 }\r
1693         }\r
1694 }\r
1695 \r
1696 VOID\r
1697 halbtc8192e1ant_PowerSaveState(\r
1698         IN      PBTC_COEXIST            pBtCoexist,\r
1699         IN      u1Byte                          psType,\r
1700         IN      u1Byte                          lpsVal,\r
1701         IN      u1Byte                          rpwmVal\r
1702         )\r
1703 {\r
1704         BOOLEAN         bLowPwrDisable=FALSE;\r
1705 \r
1706         switch(psType)\r
1707         {\r
1708                 case BTC_PS_WIFI_NATIVE:\r
1709                         // recover to original 32k low power setting\r
1710                         bLowPwrDisable = FALSE;\r
1711                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);\r
1712                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_NORMAL_LPS, NULL);\r
1713                         break;\r
1714                 case BTC_PS_LPS_ON:\r
1715                         halbtc8192e1ant_PsTdmaCheckForPowerSaveState(pBtCoexist, TRUE);\r
1716                         halbtc8192e1ant_LpsRpwm(pBtCoexist, NORMAL_EXEC, lpsVal, rpwmVal);\r
1717                         // when coex force to enter LPS, do not enter 32k low power.\r
1718                         bLowPwrDisable = TRUE;\r
1719                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);\r
1720                         // power save must executed before psTdma.\r
1721                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_ENTER_LPS, NULL);\r
1722                         break;\r
1723                 case BTC_PS_LPS_OFF:\r
1724                         halbtc8192e1ant_PsTdmaCheckForPowerSaveState(pBtCoexist, FALSE);\r
1725                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_LEAVE_LPS, NULL);\r
1726                         break;\r
1727                 default:\r
1728                         break;\r
1729         }\r
1730 }\r
1731 \r
1732 \r
1733 VOID\r
1734 halbtc8192e1ant_ActionWifiOnly(\r
1735         IN      PBTC_COEXIST            pBtCoexist\r
1736         )\r
1737 {\r
1738         halbtc8192e1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
1739         halbtc8192e1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 9);      \r
1740 }\r
1741 \r
1742 VOID\r
1743 halbtc8192e1ant_MonitorBtEnableDisable(\r
1744         IN      PBTC_COEXIST            pBtCoexist\r
1745         )\r
1746 {\r
1747         static BOOLEAN  bPreBtDisabled=FALSE;\r
1748         static u4Byte           btDisableCnt=0;\r
1749         BOOLEAN                 bBtActive=TRUE, bBtDisabled=FALSE;\r
1750 \r
1751         // This function check if bt is disabled\r
1752 \r
1753         if(     pCoexSta->highPriorityTx == 0 &&\r
1754                 pCoexSta->highPriorityRx == 0 &&\r
1755                 pCoexSta->lowPriorityTx == 0 &&\r
1756                 pCoexSta->lowPriorityRx == 0)\r
1757         {\r
1758                 bBtActive = FALSE;\r
1759         }\r
1760         if(     pCoexSta->highPriorityTx == 0xffff &&\r
1761                 pCoexSta->highPriorityRx == 0xffff &&\r
1762                 pCoexSta->lowPriorityTx == 0xffff &&\r
1763                 pCoexSta->lowPriorityRx == 0xffff)\r
1764         {\r
1765                 bBtActive = FALSE;\r
1766         }\r
1767         if(bBtActive)\r
1768         {\r
1769                 btDisableCnt = 0;\r
1770                 bBtDisabled = FALSE;\r
1771                 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_DISABLE, &bBtDisabled);\r
1772                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], BT is enabled !!\n"));\r
1773         }\r
1774         else\r
1775         {\r
1776                 btDisableCnt++;\r
1777                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], bt all counters=0, %d times!!\n", \r
1778                                 btDisableCnt));\r
1779                 if(btDisableCnt >= 2)\r
1780                 {\r
1781                         bBtDisabled = TRUE;\r
1782                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_DISABLE, &bBtDisabled);\r
1783                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], BT is disabled !!\n"));\r
1784                         halbtc8192e1ant_ActionWifiOnly(pBtCoexist);\r
1785                 }\r
1786         }\r
1787         if(bPreBtDisabled != bBtDisabled)\r
1788         {\r
1789                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], BT is from %s to %s!!\n", \r
1790                         (bPreBtDisabled ? "disabled":"enabled"), \r
1791                         (bBtDisabled ? "disabled":"enabled")));\r
1792                 bPreBtDisabled = bBtDisabled;\r
1793                 if(!bBtDisabled)\r
1794                 {\r
1795                 }\r
1796                 else\r
1797                 {\r
1798                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_LEAVE_LPS, NULL);\r
1799                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_NORMAL_LPS, NULL);\r
1800                 }\r
1801         }\r
1802 }\r
1803 \r
1804 //=============================================\r
1805 //\r
1806 //      Software Coex Mechanism start\r
1807 //\r
1808 //=============================================\r
1809 \r
1810 // SCO only or SCO+PAN(HS)\r
1811 VOID\r
1812 halbtc8192e1ant_ActionSco(\r
1813         IN      PBTC_COEXIST            pBtCoexist\r
1814         )\r
1815 {\r
1816 }\r
1817 \r
1818 VOID\r
1819 halbtc8192e1ant_ActionHid(\r
1820         IN      PBTC_COEXIST            pBtCoexist\r
1821         )\r
1822 {\r
1823 }\r
1824 \r
1825 //A2DP only / PAN(EDR) only/ A2DP+PAN(HS)\r
1826 VOID\r
1827 halbtc8192e1ant_ActionA2dp(\r
1828         IN      PBTC_COEXIST            pBtCoexist\r
1829         )\r
1830 {\r
1831 }\r
1832 \r
1833 VOID\r
1834 halbtc8192e1ant_ActionA2dpPanHs(\r
1835         IN      PBTC_COEXIST            pBtCoexist\r
1836         )\r
1837 {\r
1838 }\r
1839 \r
1840 VOID\r
1841 halbtc8192e1ant_ActionPanEdr(\r
1842         IN      PBTC_COEXIST            pBtCoexist\r
1843         )\r
1844 {\r
1845 }\r
1846 \r
1847 //PAN(HS) only\r
1848 VOID\r
1849 halbtc8192e1ant_ActionPanHs(\r
1850         IN      PBTC_COEXIST            pBtCoexist\r
1851         )\r
1852 {\r
1853 }\r
1854 \r
1855 //PAN(EDR)+A2DP\r
1856 VOID\r
1857 halbtc8192e1ant_ActionPanEdrA2dp(\r
1858         IN      PBTC_COEXIST            pBtCoexist\r
1859         )\r
1860 {\r
1861 }\r
1862 \r
1863 VOID\r
1864 halbtc8192e1ant_ActionPanEdrHid(\r
1865         IN      PBTC_COEXIST            pBtCoexist\r
1866         )\r
1867 {\r
1868 }\r
1869 \r
1870 // HID+A2DP+PAN(EDR)\r
1871 VOID\r
1872 halbtc8192e1ant_ActionHidA2dpPanEdr(\r
1873         IN      PBTC_COEXIST            pBtCoexist\r
1874         )\r
1875 {\r
1876 }\r
1877 \r
1878 VOID\r
1879 halbtc8192e1ant_ActionHidA2dp(\r
1880         IN      PBTC_COEXIST            pBtCoexist\r
1881         )\r
1882 {\r
1883 }\r
1884 \r
1885 //=============================================\r
1886 //\r
1887 //      Non-Software Coex Mechanism start\r
1888 //\r
1889 //=============================================\r
1890 VOID\r
1891 halbtc8192e1ant_ActionBtInquiry(\r
1892         IN      PBTC_COEXIST            pBtCoexist\r
1893         )\r
1894 {\r
1895         PBTC_BT_LINK_INFO       pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
1896         BOOLEAN                         bWifiConnected=FALSE, bBtHsOn=FALSE;\r
1897         \r
1898         // Note:\r
1899         // Do not do DacSwing here, use original setting.\r
1900         \r
1901         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
1902 \r
1903         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
1904         if(bBtHsOn)\r
1905                 return;\r
1906 \r
1907         if(!bWifiConnected)\r
1908         {\r
1909                 halbtc8192e1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
1910                 \r
1911                 halbtc8192e1ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
1912 \r
1913                 halbtc8192e1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
1914                 halbtc8192e1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
1915         }\r
1916         else if( (pBtLinkInfo->bScoExist) ||\r
1917                         (pBtLinkInfo->bHidOnly) )\r
1918         {\r
1919                 // SCO/HID-only busy\r
1920                 halbtc8192e1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
1921                 \r
1922                 halbtc8192e1ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
1923 \r
1924                 halbtc8192e1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);\r
1925                 halbtc8192e1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 1);\r
1926         }\r
1927         else\r
1928         {\r
1929                 halbtc8192e1ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x0);\r
1930 \r
1931                 halbtc8192e1ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
1932 \r
1933                 halbtc8192e1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 30);\r
1934                 halbtc8192e1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
1935         }\r
1936 }\r
1937 \r
1938 VOID\r
1939 halbtc8192e1ant_ActionBtScoHidOnlyBusy(\r
1940         IN      PBTC_COEXIST            pBtCoexist,\r
1941         IN      u1Byte                          wifiStatus\r
1942         )\r
1943 {\r
1944         PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
1945         u1Byte          btRssiState=BTC_RSSI_STATE_HIGH;\r
1946 \r
1947         if(BT_8192E_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN == wifiStatus)\r
1948         {               \r
1949                 halbtc8192e1ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
1950                 halbtc8192e1ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
1951         \r
1952                 halbtc8192e1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
1953                 halbtc8192e1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
1954         }\r
1955         else\r
1956         {\r
1957                 if(pBtLinkInfo->bHidOnly)\r
1958                 {\r
1959                         halbtc8192e1ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
1960                         halbtc8192e1ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
1961                 \r
1962                         halbtc8192e1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
1963                         halbtc8192e1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
1964                 }\r
1965                 else\r
1966                 {\r
1967                         // dec bt power for diff level\r
1968                         btRssiState = halbtc8192e1ant_BtRssiState(3, 34, 42);\r
1969                         if( (btRssiState == BTC_RSSI_STATE_LOW) ||\r
1970                                 (btRssiState == BTC_RSSI_STATE_STAY_LOW) )\r
1971                         {\r
1972                                 halbtc8192e1ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
1973                         }\r
1974                         else if( (btRssiState == BTC_RSSI_STATE_MEDIUM) ||\r
1975                                         (btRssiState == BTC_RSSI_STATE_STAY_MEDIUM) )\r
1976                         {\r
1977                                 halbtc8192e1ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
1978                         }\r
1979                         else if( (btRssiState == BTC_RSSI_STATE_HIGH) ||\r
1980                                         (btRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
1981                         {\r
1982                                 halbtc8192e1ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 6);\r
1983                         }\r
1984 \r
1985                         // sw dacSwing\r
1986                         halbtc8192e1ant_DacSwing(pBtCoexist, NORMAL_EXEC, TRUE, 0xc);\r
1987 \r
1988                         halbtc8192e1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
1989                         halbtc8192e1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);                  \r
1990                 }\r
1991         }\r
1992 }\r
1993 \r
1994 VOID\r
1995 halbtc8192e1ant_ActionHs(\r
1996         IN      PBTC_COEXIST            pBtCoexist\r
1997         )\r
1998 {\r
1999         PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
2000 \r
2001         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action for HS!!!\n"));\r
2002 \r
2003         halbtc8192e1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
2004 \r
2005         if(BT_8192E_1ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus)\r
2006         {\r
2007                 // error, should not be here\r
2008                 pCoexDm->errorCondition = 1;\r
2009         }\r
2010         else if(BT_8192E_1ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus)\r
2011         {\r
2012                 halbtc8192e1ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
2013                 halbtc8192e1ant_DacSwing(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2014 \r
2015                 halbtc8192e1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 10);\r
2016                 halbtc8192e1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
2017         }\r
2018         else if(BT_8192E_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus && \r
2019                         !pBtCoexist->btLinkInfo.bHidOnly)\r
2020         {\r
2021                 if(pCoexDm->curSsType == 1)\r
2022                 {\r
2023                         halbtc8192e1ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
2024                         halbtc8192e1ant_DacSwing(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2025                         halbtc8192e1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 10);\r
2026                         halbtc8192e1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
2027                 }\r
2028         }\r
2029         else\r
2030         {\r
2031                 halbtc8192e1ant_ActionBtScoHidOnlyBusy(pBtCoexist,\r
2032                         BT_8192E_1ANT_WIFI_STATUS_CONNECTED_BUSY);\r
2033         }\r
2034 }\r
2035 \r
2036 VOID\r
2037 halbtc8192e1ant_ActionWifiConnectedBtAclBusy(\r
2038         IN      PBTC_COEXIST            pBtCoexist,\r
2039         IN      u1Byte                          wifiStatus\r
2040         )\r
2041 {\r
2042         PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
2043 \r
2044         if(pBtLinkInfo->bHidOnly)\r
2045         {\r
2046                 halbtc8192e1ant_ActionBtScoHidOnlyBusy(pBtCoexist, wifiStatus);\r
2047                 pCoexDm->bAutoTdmaAdjust = FALSE;\r
2048                 return;\r
2049         }\r
2050         \r
2051         halbtc8192e1ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
2052         halbtc8192e1ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
2053 \r
2054         if( (pBtLinkInfo->bA2dpOnly) ||\r
2055                 (pBtLinkInfo->bHidExist&&pBtLinkInfo->bA2dpExist) )\r
2056         {\r
2057                 halbtc8192e1ant_TdmaDurationAdjustForAcl(pBtCoexist, wifiStatus);\r
2058         }\r
2059         else if( (pBtLinkInfo->bPanOnly) ||\r
2060                         (pBtLinkInfo->bHidExist&&pBtLinkInfo->bPanExist) )\r
2061         {\r
2062                 halbtc8192e1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2063                 pCoexDm->bAutoTdmaAdjust = FALSE;\r
2064         }\r
2065         else\r
2066         {\r
2067                 if( (BT_8192E_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN == wifiStatus) ||\r
2068                         (BT_8192E_1ANT_WIFI_STATUS_CONNECTED_SCAN == wifiStatus) ||\r
2069                         (BT_8192E_1ANT_WIFI_STATUS_CONNECTED_SPECIAL_PKT == wifiStatus) )\r
2070                         halbtc8192e1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
2071                 else\r
2072                         halbtc8192e1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2073                 pCoexDm->bAutoTdmaAdjust = FALSE;\r
2074         }\r
2075                 \r
2076         halbtc8192e1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 1);\r
2077 }\r
2078 \r
2079 \r
2080 VOID\r
2081 halbtc8192e1ant_ActionWifiNotConnected(\r
2082         IN      PBTC_COEXIST            pBtCoexist\r
2083         )\r
2084 {\r
2085         // power save state\r
2086         halbtc8192e1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
2087 \r
2088         halbtc8192e1ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
2089         halbtc8192e1ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
2090 \r
2091         halbtc8192e1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
2092         halbtc8192e1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);  \r
2093 }\r
2094 \r
2095 VOID\r
2096 halbtc8192e1ant_ActionWifiNotConnectedAssoAuthScan(\r
2097         IN      PBTC_COEXIST            pBtCoexist\r
2098         )\r
2099 {\r
2100         halbtc8192e1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
2101 \r
2102         halbtc8192e1ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
2103         halbtc8192e1ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
2104 \r
2105         halbtc8192e1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
2106         halbtc8192e1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
2107 }\r
2108 \r
2109 VOID\r
2110 halbtc8192e1ant_ActionWifiConnectedScan(\r
2111         IN      PBTC_COEXIST            pBtCoexist\r
2112         )\r
2113 {\r
2114         // power save state\r
2115         if(BT_8192E_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus && !pBtCoexist->btLinkInfo.bHidOnly)\r
2116                 halbtc8192e1ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x0);\r
2117         else\r
2118                 halbtc8192e1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
2119 \r
2120         if(BT_8192E_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus)\r
2121         {\r
2122                 halbtc8192e1ant_ActionWifiConnectedBtAclBusy(pBtCoexist,\r
2123                         BT_8192E_1ANT_WIFI_STATUS_CONNECTED_SCAN);\r
2124         }\r
2125         else if( (BT_8192E_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||\r
2126                         (BT_8192E_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )\r
2127         {\r
2128                 halbtc8192e1ant_ActionBtScoHidOnlyBusy(pBtCoexist,\r
2129                         BT_8192E_1ANT_WIFI_STATUS_CONNECTED_SCAN);\r
2130         }\r
2131         else\r
2132         {               \r
2133                 halbtc8192e1ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
2134                 halbtc8192e1ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
2135                 halbtc8192e1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
2136                 halbtc8192e1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
2137         }\r
2138 }\r
2139 \r
2140 \r
2141 VOID\r
2142 halbtc8192e1ant_ActionWifiConnectedSpecialPacket(\r
2143         IN      PBTC_COEXIST            pBtCoexist\r
2144         )\r
2145 {\r
2146         // power save state\r
2147         if(BT_8192E_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus && !pBtCoexist->btLinkInfo.bHidOnly)\r
2148                 halbtc8192e1ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x0);\r
2149         else\r
2150                 halbtc8192e1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
2151 \r
2152         if(BT_8192E_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus)\r
2153         {\r
2154                 halbtc8192e1ant_ActionWifiConnectedBtAclBusy(pBtCoexist,\r
2155                         BT_8192E_1ANT_WIFI_STATUS_CONNECTED_SPECIAL_PKT);\r
2156         }\r
2157         else\r
2158         {               \r
2159                 halbtc8192e1ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
2160                 halbtc8192e1ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
2161                 halbtc8192e1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
2162                 halbtc8192e1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
2163         }\r
2164 }\r
2165 \r
2166 VOID\r
2167 halbtc8192e1ant_ActionWifiConnected(\r
2168         IN      PBTC_COEXIST            pBtCoexist\r
2169         )\r
2170 {\r
2171         BOOLEAN         bWifiConnected=FALSE, bWifiBusy=FALSE;\r
2172         BOOLEAN         bScan=FALSE, bLink=FALSE, bRoam=FALSE;\r
2173         BOOLEAN         bUnder4way=FALSE;\r
2174         u4Byte          wifiBw;\r
2175 \r
2176         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], CoexForWifiConnect()===>\n"));\r
2177 \r
2178         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
2179         if(!bWifiConnected)\r
2180         {\r
2181                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], CoexForWifiConnect(), return for wifi not connected<===\n"));\r
2182                 return;\r
2183         }\r
2184 \r
2185         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &bUnder4way);\r
2186         if(bUnder4way)\r
2187         {\r
2188                 halbtc8192e1ant_ActionWifiConnectedSpecialPacket(pBtCoexist);\r
2189                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], CoexForWifiConnect(), return for wifi is under 4way<===\n"));\r
2190                 return;\r
2191         }\r
2192 \r
2193         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);\r
2194         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);\r
2195         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);\r
2196         if(bScan || bLink || bRoam)\r
2197         {\r
2198                 halbtc8192e1ant_ActionWifiConnectedScan(pBtCoexist);\r
2199                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], CoexForWifiConnect(), return for wifi is under scan<===\n"));\r
2200                 return;\r
2201         }\r
2202 \r
2203         // power save state\r
2204         if(BT_8192E_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus && !pBtCoexist->btLinkInfo.bHidOnly)\r
2205                 halbtc8192e1ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x0);\r
2206         else\r
2207                 halbtc8192e1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
2208 \r
2209         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);      \r
2210         if(!bWifiBusy)\r
2211         {\r
2212                 if(BT_8192E_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus)\r
2213                 {\r
2214                         halbtc8192e1ant_ActionWifiConnectedBtAclBusy(pBtCoexist, \r
2215                                 BT_8192E_1ANT_WIFI_STATUS_CONNECTED_IDLE);\r
2216                 }\r
2217                 else if( (BT_8192E_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||\r
2218                         (BT_8192E_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )\r
2219                 {\r
2220                         halbtc8192e1ant_ActionBtScoHidOnlyBusy(pBtCoexist,\r
2221                                 BT_8192E_1ANT_WIFI_STATUS_CONNECTED_IDLE);\r
2222                 }\r
2223                 else\r
2224                 {                               \r
2225                         halbtc8192e1ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
2226                         halbtc8192e1ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
2227                         halbtc8192e1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
2228                         halbtc8192e1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
2229                 }\r
2230         }\r
2231         else\r
2232         {\r
2233                 if(BT_8192E_1ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus)\r
2234                 {                               \r
2235                         halbtc8192e1ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
2236                         halbtc8192e1ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
2237                         halbtc8192e1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);\r
2238                         halbtc8192e1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
2239                 }\r
2240                 else if(BT_8192E_1ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus)\r
2241                 {                               \r
2242                         halbtc8192e1ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
2243                         halbtc8192e1ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0);                    \r
2244                         halbtc8192e1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);\r
2245                         halbtc8192e1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
2246                 }\r
2247                 else if(BT_8192E_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus)\r
2248                 {\r
2249                         halbtc8192e1ant_ActionWifiConnectedBtAclBusy(pBtCoexist,\r
2250                                 BT_8192E_1ANT_WIFI_STATUS_CONNECTED_BUSY);\r
2251                 }\r
2252                 else if( (BT_8192E_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||\r
2253                         (BT_8192E_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )\r
2254                 {\r
2255                         halbtc8192e1ant_ActionBtScoHidOnlyBusy(pBtCoexist,\r
2256                                 BT_8192E_1ANT_WIFI_STATUS_CONNECTED_BUSY);\r
2257                 }\r
2258                 else \r
2259                 {                               \r
2260                         halbtc8192e1ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
2261                         halbtc8192e1ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
2262                         halbtc8192e1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
2263                         halbtc8192e1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
2264                 }\r
2265         }\r
2266 }\r
2267 \r
2268 VOID\r
2269 halbtc8192e1ant_RunSwCoexistMechanism(\r
2270         IN      PBTC_COEXIST            pBtCoexist\r
2271         )\r
2272 {\r
2273         BOOLEAN                         bWifiUnder5G=FALSE, bWifiBusy=FALSE, bWifiConnected=FALSE;\r
2274         u1Byte                          btInfoOriginal=0, btRetryCnt=0;\r
2275         u1Byte                          algorithm=0;\r
2276 \r
2277         return;\r
2278 \r
2279         algorithm = halbtc8192e1ant_ActionAlgorithm(pBtCoexist);\r
2280         pCoexDm->curAlgorithm = algorithm;\r
2281 \r
2282         if(halbtc8192e1ant_IsCommonAction(pBtCoexist))\r
2283         {\r
2284         }\r
2285         else\r
2286         {\r
2287                 switch(pCoexDm->curAlgorithm)\r
2288                 {\r
2289                         case BT_8192E_1ANT_COEX_ALGO_SCO:\r
2290                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = SCO.\n"));\r
2291                                 halbtc8192e1ant_ActionSco(pBtCoexist);\r
2292                                 break;\r
2293                         case BT_8192E_1ANT_COEX_ALGO_HID:\r
2294                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = HID.\n"));\r
2295                                 halbtc8192e1ant_ActionHid(pBtCoexist);\r
2296                                 break;\r
2297                         case BT_8192E_1ANT_COEX_ALGO_A2DP:\r
2298                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = A2DP.\n"));\r
2299                                 halbtc8192e1ant_ActionA2dp(pBtCoexist);\r
2300                                 break;\r
2301                         case BT_8192E_1ANT_COEX_ALGO_A2DP_PANHS:\r
2302                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = A2DP+PAN(HS).\n"));\r
2303                                 halbtc8192e1ant_ActionA2dpPanHs(pBtCoexist);\r
2304                                 break;\r
2305                         case BT_8192E_1ANT_COEX_ALGO_PANEDR:\r
2306                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = PAN(EDR).\n"));\r
2307                                 halbtc8192e1ant_ActionPanEdr(pBtCoexist);\r
2308                                 break;\r
2309                         case BT_8192E_1ANT_COEX_ALGO_PANHS:\r
2310                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = HS mode.\n"));\r
2311                                 halbtc8192e1ant_ActionPanHs(pBtCoexist);\r
2312                                 break;\r
2313                         case BT_8192E_1ANT_COEX_ALGO_PANEDR_A2DP:\r
2314                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = PAN+A2DP.\n"));\r
2315                                 halbtc8192e1ant_ActionPanEdrA2dp(pBtCoexist);\r
2316                                 break;\r
2317                         case BT_8192E_1ANT_COEX_ALGO_PANEDR_HID:\r
2318                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = PAN(EDR)+HID.\n"));\r
2319                                 halbtc8192e1ant_ActionPanEdrHid(pBtCoexist);\r
2320                                 break;\r
2321                         case BT_8192E_1ANT_COEX_ALGO_HID_A2DP_PANEDR:\r
2322                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = HID+A2DP+PAN.\n"));\r
2323                                 halbtc8192e1ant_ActionHidA2dpPanEdr(pBtCoexist);\r
2324                                 break;\r
2325                         case BT_8192E_1ANT_COEX_ALGO_HID_A2DP:\r
2326                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = HID+A2DP.\n"));\r
2327                                 halbtc8192e1ant_ActionHidA2dp(pBtCoexist);\r
2328                                 break;\r
2329                         default:\r
2330                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = coexist All Off!!\n"));\r
2331                                 halbtc8192e1ant_CoexAllOff(pBtCoexist);\r
2332                                 break;\r
2333                 }\r
2334                 pCoexDm->preAlgorithm = pCoexDm->curAlgorithm;\r
2335         }\r
2336 }\r
2337 \r
2338 VOID\r
2339 halbtc8192e1ant_RunCoexistMechanism(\r
2340         IN      PBTC_COEXIST            pBtCoexist\r
2341         )\r
2342 {\r
2343         PBTC_BT_LINK_INFO       pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
2344         BOOLEAN bWifiConnected=FALSE, bBtHsOn=FALSE;\r
2345 \r
2346         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], RunCoexistMechanism()===>\n"));\r
2347 \r
2348         if(pBtCoexist->bManualControl)\r
2349         {\r
2350                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n"));\r
2351                 return;\r
2352         }\r
2353 \r
2354         if(pBtCoexist->bStopCoexDm)\r
2355         {\r
2356                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n"));\r
2357                 return;\r
2358         }\r
2359 \r
2360         if(pCoexSta->bUnderIps)\r
2361         {\r
2362                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], wifi is under IPS !!!\n"));\r
2363                 return;\r
2364         }\r
2365         \r
2366         halbtc8192e1ant_RunSwCoexistMechanism(pBtCoexist);\r
2367 \r
2368         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
2369         if(pCoexSta->bC2hBtInquiryPage)\r
2370         {\r
2371                 halbtc8192e1ant_ActionBtInquiry(pBtCoexist);\r
2372                 return;\r
2373         }\r
2374 \r
2375         // 1ss or 2ss\r
2376         if(pBtLinkInfo->bScoExist)\r
2377         {\r
2378                 halbtc8192e1ant_SwitchSsType(pBtCoexist, NORMAL_EXEC, 1);\r
2379         }\r
2380         else if(bBtHsOn)\r
2381         {\r
2382                 if(pBtLinkInfo->bHidOnly)\r
2383                         halbtc8192e1ant_SwitchSsType(pBtCoexist, NORMAL_EXEC, 2);\r
2384                 else\r
2385                         halbtc8192e1ant_SwitchSsType(pBtCoexist, NORMAL_EXEC, 1);\r
2386         }\r
2387         else\r
2388                 halbtc8192e1ant_SwitchSsType(pBtCoexist, NORMAL_EXEC, 2);\r
2389         \r
2390         if(bBtHsOn)\r
2391         {\r
2392                 halbtc8192e1ant_ActionHs(pBtCoexist);\r
2393                 return;\r
2394         }\r
2395 \r
2396         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
2397         if(!bWifiConnected)\r
2398         {\r
2399                 BOOLEAN bScan=FALSE, bLink=FALSE, bRoam=FALSE;\r
2400                 \r
2401                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], wifi is non connected-idle !!!\n"));\r
2402 \r
2403                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);\r
2404                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);\r
2405                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);\r
2406 \r
2407                 if(bScan || bLink || bRoam)\r
2408                         halbtc8192e1ant_ActionWifiNotConnectedAssoAuthScan(pBtCoexist);\r
2409                 else\r
2410                         halbtc8192e1ant_ActionWifiNotConnected(pBtCoexist);\r
2411         }\r
2412         else\r
2413         {\r
2414                 halbtc8192e1ant_ActionWifiConnected(pBtCoexist);\r
2415         }\r
2416 }\r
2417 \r
2418 VOID\r
2419 halbtc8192e1ant_InitCoexDm(\r
2420         IN      PBTC_COEXIST            pBtCoexist\r
2421         )\r
2422 {       \r
2423         // force to reset coex mechanism\r
2424         halbtc8192e1ant_FwDacSwingLvl(pBtCoexist, FORCE_EXEC, 6);\r
2425         halbtc8192e1ant_DecBtPwr(pBtCoexist, FORCE_EXEC, 0);\r
2426 \r
2427         halbtc8192e1ant_SwitchSsType(pBtCoexist, FORCE_EXEC, 2);\r
2428 \r
2429         halbtc8192e1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8);\r
2430         halbtc8192e1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 0);\r
2431 }\r
2432 \r
2433 //============================================================\r
2434 // work around function start with wa_halbtc8192e1ant_\r
2435 //============================================================\r
2436 //============================================================\r
2437 // extern function start with EXhalbtc8192e1ant_\r
2438 //============================================================\r
2439 VOID\r
2440 EXhalbtc8192e1ant_PowerOnSetting(\r
2441         IN      PBTC_COEXIST            pBtCoexist\r
2442         )\r
2443 {\r
2444 }\r
2445 \r
2446 VOID\r
2447 EXhalbtc8192e1ant_InitHwConfig(\r
2448         IN      PBTC_COEXIST            pBtCoexist,\r
2449         IN      BOOLEAN                         bWifiOnly\r
2450         )\r
2451 {\r
2452         u4Byte  u4Tmp=0;\r
2453         u2Byte  u2Tmp=0;\r
2454         u1Byte  u1Tmp=0;\r
2455 \r
2456         BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], 1Ant Init HW Config!!\n"));\r
2457 \r
2458         // antenna sw ctrl to bt\r
2459         halbtc8192e1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, TRUE, FALSE);\r
2460         \r
2461         halbtc8192e1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 0);\r
2462 \r
2463         // antenna switch control parameter\r
2464         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x858, 0x55555555);\r
2465 \r
2466         // coex parameters\r
2467         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x778, 0x1);\r
2468         // 0x790[5:0]=0x5\r
2469         u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x790);\r
2470         u1Tmp &= 0xc0;\r
2471         u1Tmp |= 0x5;\r
2472         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x790, u1Tmp);\r
2473 \r
2474         // enable counter statistics\r
2475         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4);\r
2476 \r
2477         // enable PTA\r
2478         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x40, 0x20);\r
2479         // enable mailbox interface\r
2480         u2Tmp = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x40);\r
2481         u2Tmp |= BIT9;\r
2482         pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x40, u2Tmp);\r
2483 \r
2484         // enable PTA I2C mailbox \r
2485         u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x101);\r
2486         u1Tmp |= BIT4;\r
2487         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x101, u1Tmp);\r
2488 \r
2489         // enable bt clock when wifi is disabled.\r
2490         u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x93);\r
2491         u1Tmp |= BIT0;\r
2492         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x93, u1Tmp);\r
2493         // enable bt clock when suspend.\r
2494         u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x7);\r
2495         u1Tmp |= BIT0;\r
2496         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x7, u1Tmp);\r
2497 }\r
2498 \r
2499 VOID\r
2500 EXhalbtc8192e1ant_InitCoexDm(\r
2501         IN      PBTC_COEXIST            pBtCoexist\r
2502         )\r
2503 {\r
2504         BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], Coex Mechanism Init!!\n"));\r
2505 \r
2506         pBtCoexist->bStopCoexDm = FALSE;\r
2507         \r
2508         halbtc8192e1ant_InitCoexDm(pBtCoexist);\r
2509 }\r
2510 \r
2511 VOID\r
2512 EXhalbtc8192e1ant_DisplayCoexInfo(\r
2513         IN      PBTC_COEXIST            pBtCoexist\r
2514         )\r
2515 {\r
2516         PBTC_BOARD_INFO         pBoardInfo=&pBtCoexist->boardInfo;\r
2517         PBTC_STACK_INFO         pStackInfo=&pBtCoexist->stackInfo;\r
2518         PBTC_BT_LINK_INFO       pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
2519         pu1Byte                         cliBuf=pBtCoexist->cliBuf;\r
2520         u1Byte                          u1Tmp[4], i, btInfoExt, psTdmaCase=0;\r
2521         u4Byte                          u4Tmp[4];\r
2522         u4Byte                          fwVer=0, btPatchVer=0;\r
2523 \r
2524         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[BT Coexist info]============");\r
2525         CL_PRINTF(cliBuf);\r
2526 \r
2527         if(pBtCoexist->bManualControl)\r
2528         {\r
2529                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[Under Manual Control]============");\r
2530                 CL_PRINTF(cliBuf);\r
2531                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ==========================================");\r
2532                 CL_PRINTF(cliBuf);\r
2533         }       \r
2534         if(pBtCoexist->bStopCoexDm)\r
2535         {\r
2536                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[Coex is STOPPED]============");\r
2537                 CL_PRINTF(cliBuf);\r
2538                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ==========================================");\r
2539                 CL_PRINTF(cliBuf);\r
2540         }\r
2541 \r
2542         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ", "Ant PG number/ Ant mechanism:", \\r
2543                 pBoardInfo->pgAntNum, pBoardInfo->btdmAntNum);\r
2544         CL_PRINTF(cliBuf);      \r
2545         \r
2546         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %d", "BT stack/ hci ext ver", \\r
2547                 ((pStackInfo->bProfileNotified)? "Yes":"No"), pStackInfo->hciVersion);\r
2548         CL_PRINTF(cliBuf);\r
2549 \r
2550         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_BT_PATCH_VER, &btPatchVer);\r
2551         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);\r
2552         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d_%d/ 0x%x/ 0x%x(%d)", "CoexVer/ FwVer/ PatchVer", \\r
2553                 GLCoexVerDate8192e1Ant, GLCoexVer8192e1Ant, fwVer, btPatchVer, btPatchVer);\r
2554         CL_PRINTF(cliBuf);\r
2555 \r
2556         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ", "Wifi channel informed to BT", \\r
2557                 pCoexDm->wifiChnlInfo[0], pCoexDm->wifiChnlInfo[1],\r
2558                 pCoexDm->wifiChnlInfo[2]);\r
2559         CL_PRINTF(cliBuf);\r
2560 \r
2561         // wifi status\r
2562         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Wifi Status]============");\r
2563         CL_PRINTF(cliBuf);\r
2564         pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_WIFI_STATUS);\r
2565 \r
2566         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[BT Status]============");\r
2567         CL_PRINTF(cliBuf);\r
2568 \r
2569         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d] ", "BT [status/ rssi/ retryCnt]", \\r
2570                 ((pBtCoexist->btInfo.bBtDisabled)? ("disabled"):        ((pCoexSta->bC2hBtInquiryPage)?("inquiry/page scan"):((BT_8192E_1ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus)? "non-connected idle":\r
2571                 (  (BT_8192E_1ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus)? "connected-idle":"busy")))),\r
2572                 pCoexSta->btRssi, pCoexSta->btRetryCnt);\r
2573         CL_PRINTF(cliBuf);\r
2574         \r
2575         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d", "SCO/HID/PAN/A2DP", \\r
2576                 pBtLinkInfo->bScoExist, pBtLinkInfo->bHidExist, pBtLinkInfo->bPanExist, pBtLinkInfo->bA2dpExist);\r
2577         CL_PRINTF(cliBuf);\r
2578         pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_BT_LINK_INFO);      \r
2579 \r
2580         btInfoExt = pCoexSta->btInfoExt;\r
2581         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "BT Info A2DP rate", \\r
2582                 (btInfoExt&BIT0)? "Basic rate":"EDR rate");\r
2583         CL_PRINTF(cliBuf);      \r
2584 \r
2585         for(i=0; i<BT_INFO_SRC_8192E_1ANT_MAX; i++)\r
2586         {\r
2587                 if(pCoexSta->btInfoC2hCnt[i])\r
2588                 {                               \r
2589                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)", GLBtInfoSrc8192e1Ant[i], \\r
2590                                 pCoexSta->btInfoC2h[i][0], pCoexSta->btInfoC2h[i][1],\r
2591                                 pCoexSta->btInfoC2h[i][2], pCoexSta->btInfoC2h[i][3],\r
2592                                 pCoexSta->btInfoC2h[i][4], pCoexSta->btInfoC2h[i][5],\r
2593                                 pCoexSta->btInfoC2h[i][6], pCoexSta->btInfoC2hCnt[i]);\r
2594                         CL_PRINTF(cliBuf);\r
2595                 }\r
2596         }\r
2597 \r
2598         if(!pBtCoexist->bManualControl)\r
2599         {\r
2600                 // Sw mechanism \r
2601                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Sw mechanism]============");\r
2602                 CL_PRINTF(cliBuf);\r
2603         \r
2604                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %d ", "DelBA/ BtCtrlAgg/ AggSize", \\r
2605                         (pBtCoexist->btInfo.bRejectAggPkt? "Yes":"No"), (pBtCoexist->btInfo.bBtCtrlAggBufSize? "Yes":"No"),\r
2606                                 pBtCoexist->btInfo.aggBufSize);\r
2607                 CL_PRINTF(cliBuf);\r
2608                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x ", "Rate Mask", \\r
2609                                 pBtCoexist->btInfo.raMask);\r
2610                 CL_PRINTF(cliBuf);\r
2611         \r
2612                 // Fw mechanism         \r
2613                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Fw mechanism]============");\r
2614                 CL_PRINTF(cliBuf);      \r
2615 \r
2616                 psTdmaCase = pCoexDm->curPsTdma;\r
2617                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (auto:%d)", "PS TDMA", \\r
2618                         pCoexDm->psTdmaPara[0], pCoexDm->psTdmaPara[1],\r
2619                         pCoexDm->psTdmaPara[2], pCoexDm->psTdmaPara[3],\r
2620                         pCoexDm->psTdmaPara[4], psTdmaCase, pCoexDm->bAutoTdmaAdjust);\r
2621                 CL_PRINTF(cliBuf);\r
2622 \r
2623                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x ", "Latest error condition(should be 0)", \\r
2624                         pCoexDm->errorCondition);\r
2625                 CL_PRINTF(cliBuf);\r
2626                 \r
2627                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "IgnWlanAct", \\r
2628                         pCoexDm->bCurIgnoreWlanAct);\r
2629                 CL_PRINTF(cliBuf);\r
2630         }\r
2631 \r
2632         // Hw setting           \r
2633         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Hw setting]============");\r
2634         CL_PRINTF(cliBuf);      \r
2635 \r
2636         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xc04);\r
2637         u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xd04);\r
2638         u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x90c);\r
2639         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0xc04/ 0xd04/ 0x90c", \\r
2640                 u4Tmp[0], u4Tmp[1], u4Tmp[2]);\r
2641         CL_PRINTF(cliBuf);\r
2642 \r
2643         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x778);\r
2644         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x778", \\r
2645                 u1Tmp[0]);\r
2646         CL_PRINTF(cliBuf);\r
2647         \r
2648         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x92c);\r
2649         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x930);\r
2650         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "0x92c/ 0x930", \\r
2651                 (u1Tmp[0]), u4Tmp[0]);\r
2652         CL_PRINTF(cliBuf);\r
2653 \r
2654         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x40);\r
2655         u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x4f);\r
2656         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "0x40/ 0x4f", \\r
2657                 u1Tmp[0], u1Tmp[1]);\r
2658         CL_PRINTF(cliBuf);\r
2659 \r
2660         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x550);\r
2661         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x522);\r
2662         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "0x550(bcn ctrl)/0x522", \\r
2663                 u4Tmp[0], u1Tmp[0]);\r
2664         CL_PRINTF(cliBuf);\r
2665 \r
2666         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xc50);\r
2667         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0xc50(dig)", \\r
2668                 u4Tmp[0]);\r
2669         CL_PRINTF(cliBuf);\r
2670 \r
2671         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c0);\r
2672         u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c4);\r
2673         u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c8);\r
2674         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x6cc);\r
2675         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)", \\r
2676                 u4Tmp[0], u4Tmp[1], u4Tmp[2], u1Tmp[0]);\r
2677         CL_PRINTF(cliBuf);\r
2678 \r
2679         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "0x770(hp rx[31:16]/tx[15:0])", \\r
2680                 pCoexSta->highPriorityRx, pCoexSta->highPriorityTx);\r
2681         CL_PRINTF(cliBuf);\r
2682         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "0x774(lp rx[31:16]/tx[15:0])", \\r
2683                 pCoexSta->lowPriorityRx, pCoexSta->lowPriorityTx);\r
2684         CL_PRINTF(cliBuf);\r
2685 #if(BT_AUTO_REPORT_ONLY_8192E_1ANT == 1)\r
2686         halbtc8192e1ant_MonitorBtCtr(pBtCoexist);\r
2687 #endif\r
2688         \r
2689         pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_COEX_STATISTICS);\r
2690 }\r
2691 \r
2692 \r
2693 VOID\r
2694 EXhalbtc8192e1ant_IpsNotify(\r
2695         IN      PBTC_COEXIST            pBtCoexist,\r
2696         IN      u1Byte                  type\r
2697         )\r
2698 {\r
2699         u4Byte  u4Tmp=0;\r
2700 \r
2701         if(pBtCoexist->bManualControl ||        pBtCoexist->bStopCoexDm)\r
2702                 return;\r
2703 \r
2704         if(BTC_IPS_ENTER == type)\r
2705         {\r
2706                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], IPS ENTER notify\n"));\r
2707                 pCoexSta->bUnderIps = TRUE;\r
2708                 halbtc8192e1ant_CoexAllOff(pBtCoexist);\r
2709                 halbtc8192e1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FALSE, TRUE);\r
2710         }\r
2711         else if(BTC_IPS_LEAVE == type)\r
2712         {\r
2713                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], IPS LEAVE notify\n"));\r
2714                 pCoexSta->bUnderIps = FALSE;\r
2715         }\r
2716 }\r
2717 \r
2718 VOID\r
2719 EXhalbtc8192e1ant_LpsNotify(\r
2720         IN      PBTC_COEXIST            pBtCoexist,\r
2721         IN      u1Byte                  type\r
2722         )\r
2723 {\r
2724         if(pBtCoexist->bManualControl || pBtCoexist->bStopCoexDm)\r
2725                 return;\r
2726 \r
2727         if(BTC_LPS_ENABLE == type)\r
2728         {\r
2729                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], LPS ENABLE notify\n"));\r
2730                 pCoexSta->bUnderLps = TRUE;\r
2731         }\r
2732         else if(BTC_LPS_DISABLE == type)\r
2733         {\r
2734                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], LPS DISABLE notify\n"));\r
2735                 pCoexSta->bUnderLps = FALSE;\r
2736         }\r
2737 }\r
2738 \r
2739 VOID\r
2740 EXhalbtc8192e1ant_ScanNotify(\r
2741         IN      PBTC_COEXIST            pBtCoexist,\r
2742         IN      u1Byte                  type\r
2743         )\r
2744 {\r
2745         BOOLEAN                 bWifiConnected=FALSE, bBtHsOn=FALSE;    \r
2746 \r
2747         if(pBtCoexist->bManualControl ||\r
2748                 pBtCoexist->bStopCoexDm ||\r
2749                 pBtCoexist->btInfo.bBtDisabled )\r
2750                 return;\r
2751 \r
2752         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
2753         if(pCoexSta->bC2hBtInquiryPage)\r
2754         {\r
2755                 halbtc8192e1ant_ActionBtInquiry(pBtCoexist);\r
2756                 return;\r
2757         }\r
2758         else if(bBtHsOn)\r
2759         {\r
2760                 halbtc8192e1ant_ActionHs(pBtCoexist);\r
2761                 return;\r
2762         }\r
2763 \r
2764         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
2765         if(BTC_SCAN_START == type)\r
2766         {       \r
2767                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], SCAN START notify\n"));\r
2768                 if(!bWifiConnected)     // non-connected scan\r
2769                 {\r
2770                         halbtc8192e1ant_ActionWifiNotConnectedAssoAuthScan(pBtCoexist);\r
2771                 }\r
2772                 else    // wifi is connected\r
2773                 {\r
2774                         halbtc8192e1ant_ActionWifiConnectedScan(pBtCoexist);\r
2775                 }\r
2776         }\r
2777         else if(BTC_SCAN_FINISH == type)\r
2778         {\r
2779                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], SCAN FINISH notify\n"));\r
2780                 if(!bWifiConnected)     // non-connected scan\r
2781                 {\r
2782                         halbtc8192e1ant_ActionWifiNotConnected(pBtCoexist);\r
2783                 }\r
2784                 else\r
2785                 {\r
2786                         halbtc8192e1ant_ActionWifiConnected(pBtCoexist);\r
2787                 }\r
2788         }\r
2789 }\r
2790 \r
2791 VOID\r
2792 EXhalbtc8192e1ant_ConnectNotify(\r
2793         IN      PBTC_COEXIST            pBtCoexist,\r
2794         IN      u1Byte                  type\r
2795         )\r
2796 {\r
2797         BOOLEAN bWifiConnected=FALSE, bBtHsOn=FALSE;\r
2798 \r
2799         if(pBtCoexist->bManualControl ||\r
2800                 pBtCoexist->bStopCoexDm ||\r
2801                 pBtCoexist->btInfo.bBtDisabled )\r
2802                 return;\r
2803 \r
2804         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
2805         if(pCoexSta->bC2hBtInquiryPage)\r
2806         {\r
2807                 halbtc8192e1ant_ActionBtInquiry(pBtCoexist);\r
2808                 return;\r
2809         }\r
2810         else if(bBtHsOn)\r
2811         {\r
2812                 halbtc8192e1ant_ActionHs(pBtCoexist);\r
2813                 return;\r
2814         }\r
2815 \r
2816         if(BTC_ASSOCIATE_START == type)\r
2817         {\r
2818                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], CONNECT START notify\n"));\r
2819                 halbtc8192e1ant_ActionWifiNotConnectedAssoAuthScan(pBtCoexist);\r
2820         }\r
2821         else if(BTC_ASSOCIATE_FINISH == type)\r
2822         {\r
2823                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], CONNECT FINISH notify\n"));\r
2824                 \r
2825                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
2826                 if(!bWifiConnected) // non-connected scan\r
2827                 {\r
2828                         halbtc8192e1ant_ActionWifiNotConnected(pBtCoexist);\r
2829                 }\r
2830                 else\r
2831                 {\r
2832                         halbtc8192e1ant_ActionWifiConnected(pBtCoexist);\r
2833                 }\r
2834         }\r
2835 }\r
2836 \r
2837 VOID\r
2838 EXhalbtc8192e1ant_MediaStatusNotify(\r
2839         IN      PBTC_COEXIST                    pBtCoexist,\r
2840         IN      u1Byte                          type\r
2841         )\r
2842 {\r
2843         u1Byte                  H2C_Parameter[3] ={0};\r
2844         u4Byte                  wifiBw;\r
2845         u1Byte                  wifiCentralChnl;\r
2846 \r
2847         if(pBtCoexist->bManualControl ||\r
2848                 pBtCoexist->bStopCoexDm ||\r
2849                 pBtCoexist->btInfo.bBtDisabled )\r
2850                 return;\r
2851 \r
2852         if(BTC_MEDIA_CONNECT == type)\r
2853         {\r
2854                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], MEDIA connect notify\n"));\r
2855         }\r
2856         else\r
2857         {\r
2858                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], MEDIA disconnect notify\n"));\r
2859         }\r
2860 \r
2861         // only 2.4G we need to inform bt the chnl mask\r
2862         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL, &wifiCentralChnl);\r
2863         if( (BTC_MEDIA_CONNECT == type) &&\r
2864                 (wifiCentralChnl <= 14) )\r
2865         {\r
2866                 H2C_Parameter[0] = 0x1;\r
2867                 H2C_Parameter[1] = wifiCentralChnl;\r
2868                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
2869                 if(BTC_WIFI_BW_HT40 == wifiBw)\r
2870                         H2C_Parameter[2] = 0x30;\r
2871                 else\r
2872                         H2C_Parameter[2] = 0x20;\r
2873         }\r
2874                 \r
2875         pCoexDm->wifiChnlInfo[0] = H2C_Parameter[0];\r
2876         pCoexDm->wifiChnlInfo[1] = H2C_Parameter[1];\r
2877         pCoexDm->wifiChnlInfo[2] = H2C_Parameter[2];\r
2878         \r
2879         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], FW write 0x66=0x%x\n", \r
2880                 H2C_Parameter[0]<<16|H2C_Parameter[1]<<8|H2C_Parameter[2]));\r
2881 \r
2882         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x66, 3, H2C_Parameter);\r
2883 }\r
2884 \r
2885 VOID\r
2886 EXhalbtc8192e1ant_SpecialPacketNotify(\r
2887         IN      PBTC_COEXIST                    pBtCoexist,\r
2888         IN      u1Byte                          type\r
2889         )\r
2890 {\r
2891         BOOLEAN bBtHsOn=FALSE;\r
2892 \r
2893         if(pBtCoexist->bManualControl ||\r
2894                 pBtCoexist->bStopCoexDm ||\r
2895                 pBtCoexist->btInfo.bBtDisabled )\r
2896                 return;\r
2897 \r
2898         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
2899         if(pCoexSta->bC2hBtInquiryPage)\r
2900         {\r
2901                 halbtc8192e1ant_ActionBtInquiry(pBtCoexist);\r
2902                 return;\r
2903         }\r
2904         else if(bBtHsOn)\r
2905         {\r
2906                 halbtc8192e1ant_ActionHs(pBtCoexist);\r
2907                 return;\r
2908         }\r
2909 \r
2910         if( BTC_PACKET_DHCP == type ||\r
2911                 BTC_PACKET_EAPOL == type )\r
2912         {\r
2913                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], special Packet(%d) notify\n", type));\r
2914                 halbtc8192e1ant_ActionWifiConnectedSpecialPacket(pBtCoexist);\r
2915         }\r
2916 }\r
2917 \r
2918 VOID\r
2919 EXhalbtc8192e1ant_BtInfoNotify(\r
2920         IN      PBTC_COEXIST            pBtCoexist,\r
2921         IN      pu1Byte                 tmpBuf,\r
2922         IN      u1Byte                  length\r
2923         )\r
2924 {\r
2925         PBTC_BT_LINK_INFO       pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
2926         u1Byte                          btInfo=0;\r
2927         u1Byte                          i, rspSource=0;\r
2928         static u4Byte           setBtPsdMode=0;\r
2929         BOOLEAN                         bBtBusy=FALSE;\r
2930         BOOLEAN                         bWifiConnected=FALSE;\r
2931         BOOLEAN                         bBtCtrlAggBufSize=FALSE;\r
2932 \r
2933         pCoexSta->bC2hBtInfoReqSent = FALSE;\r
2934 \r
2935         rspSource = tmpBuf[0]&0xf;\r
2936         if(rspSource >= BT_INFO_SRC_8192E_1ANT_MAX)\r
2937                 rspSource = BT_INFO_SRC_8192E_1ANT_WIFI_FW;\r
2938         pCoexSta->btInfoC2hCnt[rspSource]++;\r
2939 \r
2940         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], Bt info[%d], length=%d, hex data=[", rspSource, length));\r
2941         for(i=0; i<length; i++)\r
2942         {\r
2943                 pCoexSta->btInfoC2h[rspSource][i] = tmpBuf[i];\r
2944                 if(i == 1)\r
2945                         btInfo = tmpBuf[i];\r
2946                 if(i == length-1)\r
2947                 {\r
2948                         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("0x%02x]\n", tmpBuf[i]));\r
2949                 }\r
2950                 else\r
2951                 {\r
2952                         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("0x%02x, ", tmpBuf[i]));\r
2953                 }\r
2954         }\r
2955 \r
2956         if(pBtCoexist->btInfo.bBtDisabled)\r
2957         {\r
2958                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), return for BT is disabled <===\n"));\r
2959                 return;\r
2960         }       \r
2961 \r
2962         if(pBtCoexist->bManualControl)\r
2963         {\r
2964                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), return for Manual CTRL<===\n"));\r
2965                 return;\r
2966         }\r
2967         if(pBtCoexist->bStopCoexDm)\r
2968         {\r
2969                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), return for Coex STOPPED!!<===\n"));\r
2970                 return;\r
2971         }\r
2972 \r
2973         if(BT_INFO_SRC_8192E_1ANT_WIFI_FW != rspSource)\r
2974         {\r
2975                 pCoexSta->btRetryCnt =  // [3:0]\r
2976                         pCoexSta->btInfoC2h[rspSource][2]&0xf;\r
2977 \r
2978                 pCoexSta->btRssi =\r
2979                         pCoexSta->btInfoC2h[rspSource][3]*2+10;\r
2980 \r
2981                 pCoexSta->btInfoExt = \r
2982                         pCoexSta->btInfoC2h[rspSource][4];\r
2983 \r
2984                 // Here we need to resend some wifi info to BT\r
2985                 // because bt is reset and loss of the info.\r
2986                 if( (pCoexSta->btInfoExt & BIT1) )\r
2987                 {                       \r
2988                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n"));\r
2989                         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
2990                         if(bWifiConnected)\r
2991                         {\r
2992                                 EXhalbtc8192e1ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_CONNECT);\r
2993                         }\r
2994                         else\r
2995                         {\r
2996                                 EXhalbtc8192e1ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);\r
2997                         }\r
2998 \r
2999                         setBtPsdMode = 0;\r
3000                 }\r
3001 \r
3002                 // test-chip bt patch only rsp the status for BT_RSP, \r
3003                 // so temporary we consider the following only under BT_RSP\r
3004                 if(BT_INFO_SRC_8192E_1ANT_BT_RSP == rspSource)\r
3005                 {\r
3006                         if( (pCoexSta->btInfoExt & BIT3) )\r
3007                         {\r
3008                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n"));\r
3009                                 halbtc8192e1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, FALSE);\r
3010                         }\r
3011                         else\r
3012                         {\r
3013                                 // BT already NOT ignore Wlan active, do nothing here.\r
3014                         }\r
3015 #if(BT_AUTO_REPORT_ONLY_8192E_1ANT == 0)\r
3016                         if( (pCoexSta->btInfoExt & BIT4) )\r
3017                         {\r
3018                                 // BT auto report already enabled, do nothing\r
3019                         }\r
3020                         else\r
3021                         {\r
3022                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT ext info bit4 check, set BT to enable Auto Report!!\n"));\r
3023                                 halbtc8192e1ant_BtAutoReport(pBtCoexist, FORCE_EXEC, TRUE);\r
3024                         }\r
3025 #endif\r
3026                 }\r
3027         }\r
3028                 \r
3029         // check BIT2 first ==> check if bt is under inquiry or page scan\r
3030         if(btInfo & BT_INFO_8192E_1ANT_B_INQ_PAGE)\r
3031                 pCoexSta->bC2hBtInquiryPage = TRUE;\r
3032         else\r
3033                 pCoexSta->bC2hBtInquiryPage = FALSE;\r
3034 \r
3035         // set link exist status\r
3036         if(!(btInfo&BT_INFO_8192E_1ANT_B_CONNECTION))\r
3037         {\r
3038                 pCoexSta->bBtLinkExist = FALSE;\r
3039                 pCoexSta->bPanExist = FALSE;\r
3040                 pCoexSta->bA2dpExist = FALSE;\r
3041                 pCoexSta->bHidExist = FALSE;\r
3042                 pCoexSta->bScoExist = FALSE;\r
3043         }\r
3044         else // connection exists \r
3045         {\r
3046                 pCoexSta->bBtLinkExist = TRUE;\r
3047                 if(btInfo & BT_INFO_8192E_1ANT_B_FTP)\r
3048                         pCoexSta->bPanExist = TRUE;\r
3049                 else\r
3050                         pCoexSta->bPanExist = FALSE;\r
3051                 if(btInfo & BT_INFO_8192E_1ANT_B_A2DP)\r
3052                         pCoexSta->bA2dpExist = TRUE;\r
3053                 else\r
3054                         pCoexSta->bA2dpExist = FALSE;\r
3055                 if(btInfo & BT_INFO_8192E_1ANT_B_HID)\r
3056                         pCoexSta->bHidExist = TRUE;\r
3057                 else\r
3058                         pCoexSta->bHidExist = FALSE;\r
3059                 if(btInfo & BT_INFO_8192E_1ANT_B_SCO_ESCO)\r
3060                         pCoexSta->bScoExist = TRUE;\r
3061                 else\r
3062                         pCoexSta->bScoExist = FALSE;\r
3063         }\r
3064 \r
3065         halbtc8192e1ant_UpdateBtLinkInfo(pBtCoexist);\r
3066 \r
3067         if(!(btInfo&BT_INFO_8192E_1ANT_B_CONNECTION))\r
3068         {\r
3069                 pCoexDm->btStatus = BT_8192E_1ANT_BT_STATUS_NON_CONNECTED_IDLE;\r
3070                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), bt non-connected idle!!!\n"));\r
3071         }\r
3072         else if(btInfo == BT_INFO_8192E_1ANT_B_CONNECTION)      // connection exists but no busy\r
3073         {\r
3074                 pCoexDm->btStatus = BT_8192E_1ANT_BT_STATUS_CONNECTED_IDLE;\r
3075                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), bt connected-idle!!!\n"));\r
3076         }               \r
3077         else if((btInfo&BT_INFO_8192E_1ANT_B_SCO_ESCO) ||\r
3078                 (btInfo&BT_INFO_8192E_1ANT_B_SCO_BUSY))\r
3079         {\r
3080                 pCoexDm->btStatus = BT_8192E_1ANT_BT_STATUS_SCO_BUSY;\r
3081                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), bt sco busy!!!\n"));\r
3082         }\r
3083         else if( (btInfo&BT_INFO_8192E_1ANT_B_ACL_BUSY) ||\r
3084                         (btInfo&BT_INFO_8192E_1ANT_B_A2DP) ||\r
3085                         (btInfo&BT_INFO_8192E_1ANT_B_FTP) )\r
3086         {\r
3087                 if(BT_8192E_1ANT_BT_STATUS_ACL_BUSY != pCoexDm->btStatus)\r
3088                         pCoexDm->bAutoTdmaAdjust = FALSE;\r
3089                 pCoexDm->btStatus = BT_8192E_1ANT_BT_STATUS_ACL_BUSY;\r
3090                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), bt acl busy!!!\n"));\r
3091         }\r
3092         else\r
3093         {\r
3094                 pCoexDm->btStatus = BT_8192E_1ANT_BT_STATUS_MAX;\r
3095                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), bt non-defined state!!!\n"));\r
3096         }\r
3097 \r
3098         // ra mask check\r
3099         if(pBtLinkInfo->bScoExist || pBtLinkInfo->bHidExist)\r
3100         {\r
3101                 halbtc8192e1ant_UpdateRaMask(pBtCoexist, NORMAL_EXEC, BTC_RATE_DISABLE, 0x00000003);    // disable tx cck 1M/2M\r
3102         }\r
3103         else\r
3104         {\r
3105                 halbtc8192e1ant_UpdateRaMask(pBtCoexist, NORMAL_EXEC, BTC_RATE_ENABLE, 0x00000003);     // enable tx cck 1M/2M\r
3106         }\r
3107         \r
3108         if( (BT_8192E_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus) ||\r
3109                 (BT_8192E_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||\r
3110                 (BT_8192E_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )\r
3111         {\r
3112                 bBtBusy = TRUE;\r
3113                 if(pBtLinkInfo->bHidExist)\r
3114                         bBtCtrlAggBufSize = TRUE;\r
3115         }\r
3116         else\r
3117         {\r
3118                 bBtBusy = FALSE;\r
3119         }\r
3120         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bBtBusy);\r
3121 \r
3122         //============================================\r
3123         //      Aggregation related setting\r
3124         //============================================\r
3125         // if sco, reject AddBA\r
3126         //pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT, &bRejApAggPkt);\r
3127 \r
3128         // decide BT control aggregation buf size or not\r
3129         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE, &bBtCtrlAggBufSize);\r
3130         // real update aggregation setting\r
3131         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);\r
3132         //============================================\r
3133 \r
3134         halbtc8192e1ant_RunCoexistMechanism(pBtCoexist);\r
3135 }\r
3136 \r
3137 VOID\r
3138 EXhalbtc8192e1ant_HaltNotify(\r
3139         IN      PBTC_COEXIST                    pBtCoexist\r
3140         )\r
3141 {\r
3142         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], Halt notify\n"));\r
3143 \r
3144         pBtCoexist->bStopCoexDm = TRUE;\r
3145         halbtc8192e1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, TRUE);\r
3146 \r
3147         halbtc8192e1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
3148         \r
3149         halbtc8192e1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FALSE, TRUE);\r
3150 \r
3151         EXhalbtc8192e1ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);\r
3152 }\r
3153 \r
3154 VOID\r
3155 EXhalbtc8192e1ant_PnpNotify(\r
3156         IN      PBTC_COEXIST                    pBtCoexist,\r
3157         IN      u1Byte                          pnpState\r
3158         )\r
3159 {\r
3160         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], Pnp notify\n"));\r
3161 \r
3162         if(BTC_WIFI_PNP_SLEEP == pnpState)\r
3163         {\r
3164                 pBtCoexist->bStopCoexDm = TRUE;\r
3165                 halbtc8192e1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, TRUE);\r
3166                 halbtc8192e1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
3167                 halbtc8192e1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 9);      \r
3168         }\r
3169         else if(BTC_WIFI_PNP_WAKE_UP == pnpState)\r
3170         {\r
3171                 \r
3172         }\r
3173 }\r
3174 \r
3175 VOID\r
3176 EXhalbtc8192e1ant_Periodical(\r
3177         IN      PBTC_COEXIST                    pBtCoexist\r
3178         )\r
3179 {\r
3180         static u1Byte           disVerInfoCnt=0;\r
3181         u4Byte                          fwVer=0, btPatchVer=0;\r
3182         PBTC_BOARD_INFO         pBoardInfo=&pBtCoexist->boardInfo;\r
3183         PBTC_STACK_INFO         pStackInfo=&pBtCoexist->stackInfo;\r
3184 \r
3185         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], ==========================Periodical===========================\n"));\r
3186 \r
3187         if(disVerInfoCnt <= 5)\r
3188         {\r
3189                 disVerInfoCnt += 1;\r
3190                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], ****************************************************************\n"));\r
3191                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], Ant PG Num/ Ant Mech/ Ant Pos = %d/ %d/ %d\n", \\r
3192                         pBoardInfo->pgAntNum, pBoardInfo->btdmAntNum, pBoardInfo->btdmAntPos));\r
3193                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], BT stack/ hci ext ver = %s / %d\n", \\r
3194                         ((pStackInfo->bProfileNotified)? "Yes":"No"), pStackInfo->hciVersion));\r
3195                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_BT_PATCH_VER, &btPatchVer);\r
3196                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);\r
3197                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], CoexVer/ FwVer/ PatchVer = %d_%x/ 0x%x/ 0x%x(%d)\n", \\r
3198                         GLCoexVerDate8192e1Ant, GLCoexVer8192e1Ant, fwVer, btPatchVer, btPatchVer));\r
3199                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], ****************************************************************\n"));\r
3200         }\r
3201 #if(BT_AUTO_REPORT_ONLY_8192E_1ANT == 0)\r
3202         halbtc8192e1ant_QueryBtInfo(pBtCoexist);\r
3203         halbtc8192e1ant_MonitorBtCtr(pBtCoexist);\r
3204         halbtc8192e1ant_MonitorBtEnableDisable(pBtCoexist);\r
3205 #else\r
3206         if( halbtc8192e1ant_IsWifiStatusChanged(pBtCoexist) ||\r
3207                 pCoexDm->bAutoTdmaAdjust)\r
3208         {\r
3209                 halbtc8192e1ant_RunCoexistMechanism(pBtCoexist);\r
3210         }\r
3211 #endif\r
3212 }\r
3213 \r
3214 VOID\r
3215 EXhalbtc8192e1ant_DbgControl(\r
3216         IN      PBTC_COEXIST                    pBtCoexist,\r
3217         IN      u1Byte                          opCode,\r
3218         IN      u1Byte                          opLen,\r
3219         IN      pu1Byte                         pData\r
3220         )\r
3221 {\r
3222         switch(opCode)\r
3223         {\r
3224                 case BTC_DBG_SET_COEX_NORMAL:\r
3225                         pBtCoexist->bManualControl = FALSE;\r
3226                         halbtc8192e1ant_InitCoexDm(pBtCoexist);\r
3227                         break;\r
3228                 case BTC_DBG_SET_COEX_WIFI_ONLY:\r
3229                         pBtCoexist->bManualControl = TRUE;\r
3230                         halbtc8192e1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
3231                         halbtc8192e1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 9);      \r
3232                         break;\r
3233                 case BTC_DBG_SET_COEX_BT_ONLY:\r
3234                         // todo\r
3235                         break;\r
3236                 default:\r
3237                         break;\r
3238         }\r
3239 }\r
3240 #endif\r
3241 \r