8723BU: Update 8723BU wifi driver to version v4.3.16_14189.20150519_BTCOEX2015119...
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8723bu / hal / OUTSRC-BTCoexist / HalBtc8821a2Ant.c
1 //============================================================\r
2 // Description:\r
3 //\r
4 // This file is for RTL8821A 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 \r
16 #if WPP_SOFTWARE_TRACE\r
17 #include "HalBtc8821a2Ant.tmh"\r
18 #endif\r
19 \r
20 #if(BT_30_SUPPORT == 1)\r
21 //============================================================\r
22 // Global variables, these are static variables\r
23 //============================================================\r
24 static COEX_DM_8821A_2ANT               GLCoexDm8821a2Ant;\r
25 static PCOEX_DM_8821A_2ANT      pCoexDm=&GLCoexDm8821a2Ant;\r
26 static COEX_STA_8821A_2ANT              GLCoexSta8821a2Ant;\r
27 static PCOEX_STA_8821A_2ANT     pCoexSta=&GLCoexSta8821a2Ant;\r
28 \r
29 const char *const GLBtInfoSrc8821a2Ant[]={\r
30         "BT Info[wifi fw]",\r
31         "BT Info[bt rsp]",\r
32         "BT Info[bt auto report]",\r
33 };\r
34 \r
35 u4Byte  GLCoexVerDate8821a2Ant=20150128;\r
36 u4Byte  GLCoexVer8821a2Ant=0x51;\r
37 \r
38 //============================================================\r
39 // local function proto type if needed\r
40 //============================================================\r
41 //============================================================\r
42 // local function start with halbtc8821a2ant_\r
43 //============================================================\r
44 u1Byte\r
45 halbtc8821a2ant_BtRssiState(\r
46         u1Byte                  levelNum,\r
47         u1Byte                  rssiThresh,\r
48         u1Byte                  rssiThresh1\r
49         )\r
50 {\r
51         s4Byte                  btRssi=0;\r
52         u1Byte                  btRssiState=pCoexSta->preBtRssiState;\r
53 \r
54         btRssi = pCoexSta->btRssi;\r
55 \r
56         if(levelNum == 2)\r
57         {                       \r
58                 if( (pCoexSta->preBtRssiState == BTC_RSSI_STATE_LOW) ||\r
59                         (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_LOW))\r
60                 {\r
61                         if(btRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT))\r
62                         {\r
63                                 btRssiState = BTC_RSSI_STATE_HIGH;\r
64                         }\r
65                         else\r
66                         {\r
67                                 btRssiState = BTC_RSSI_STATE_STAY_LOW;\r
68                         }\r
69                 }\r
70                 else\r
71                 {\r
72                         if(btRssi < rssiThresh)\r
73                         {\r
74                                 btRssiState = BTC_RSSI_STATE_LOW;\r
75                         }\r
76                         else\r
77                         {\r
78                                 btRssiState = BTC_RSSI_STATE_STAY_HIGH;\r
79                         }\r
80                 }\r
81         }\r
82         else if(levelNum == 3)\r
83         {\r
84                 if(rssiThresh > rssiThresh1)\r
85                 {\r
86                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Rssi thresh error!!\n"));\r
87                         return pCoexSta->preBtRssiState;\r
88                 }\r
89                 \r
90                 if( (pCoexSta->preBtRssiState == BTC_RSSI_STATE_LOW) ||\r
91                         (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_LOW))\r
92                 {\r
93                         if(btRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT))\r
94                         {\r
95                                 btRssiState = BTC_RSSI_STATE_MEDIUM;\r
96                         }\r
97                         else\r
98                         {\r
99                                 btRssiState = BTC_RSSI_STATE_STAY_LOW;\r
100                         }\r
101                 }\r
102                 else if( (pCoexSta->preBtRssiState == BTC_RSSI_STATE_MEDIUM) ||\r
103                         (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_MEDIUM))\r
104                 {\r
105                         if(btRssi >= (rssiThresh1+BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT))\r
106                         {\r
107                                 btRssiState = BTC_RSSI_STATE_HIGH;\r
108                         }\r
109                         else if(btRssi < rssiThresh)\r
110                         {\r
111                                 btRssiState = BTC_RSSI_STATE_LOW;\r
112                         }\r
113                         else\r
114                         {\r
115                                 btRssiState = BTC_RSSI_STATE_STAY_MEDIUM;\r
116                         }\r
117                 }\r
118                 else\r
119                 {\r
120                         if(btRssi < rssiThresh1)\r
121                         {\r
122                                 btRssiState = BTC_RSSI_STATE_MEDIUM;\r
123                         }\r
124                         else\r
125                         {\r
126                                 btRssiState = BTC_RSSI_STATE_STAY_HIGH;\r
127                         }\r
128                 }\r
129         }\r
130                 \r
131         pCoexSta->preBtRssiState = btRssiState;\r
132 \r
133         return btRssiState;\r
134 }\r
135 \r
136 u1Byte\r
137 halbtc8821a2ant_WifiRssiState(\r
138         IN      PBTC_COEXIST            pBtCoexist,\r
139         IN      u1Byte                  index,\r
140         IN      u1Byte                  levelNum,\r
141         IN      u1Byte                  rssiThresh,\r
142         IN      u1Byte                  rssiThresh1\r
143         )\r
144 {\r
145         s4Byte                  wifiRssi=0;\r
146         u1Byte                  wifiRssiState=pCoexSta->preWifiRssiState[index];\r
147 \r
148         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);\r
149         \r
150         if(levelNum == 2)\r
151         {\r
152                 if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_LOW) ||\r
153                         (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_LOW))\r
154                 {\r
155                         if(wifiRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT))\r
156                         {\r
157                                 wifiRssiState = BTC_RSSI_STATE_HIGH;\r
158                         }\r
159                         else\r
160                         {\r
161                                 wifiRssiState = BTC_RSSI_STATE_STAY_LOW;\r
162                         }\r
163                 }\r
164                 else\r
165                 {\r
166                         if(wifiRssi < rssiThresh)\r
167                         {\r
168                                 wifiRssiState = BTC_RSSI_STATE_LOW;\r
169                         }\r
170                         else\r
171                         {\r
172                                 wifiRssiState = BTC_RSSI_STATE_STAY_HIGH;\r
173                         }\r
174                 }\r
175         }\r
176         else if(levelNum == 3)\r
177         {\r
178                 if(rssiThresh > rssiThresh1)\r
179                 {\r
180                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], wifi RSSI thresh error!!\n"));\r
181                         return pCoexSta->preWifiRssiState[index];\r
182                 }\r
183                 \r
184                 if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_LOW) ||\r
185                         (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_LOW))\r
186                 {\r
187                         if(wifiRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT))\r
188                         {\r
189                                 wifiRssiState = BTC_RSSI_STATE_MEDIUM;\r
190                         }\r
191                         else\r
192                         {\r
193                                 wifiRssiState = BTC_RSSI_STATE_STAY_LOW;\r
194                         }\r
195                 }\r
196                 else if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_MEDIUM) ||\r
197                         (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_MEDIUM))\r
198                 {\r
199                         if(wifiRssi >= (rssiThresh1+BTC_RSSI_COEX_THRESH_TOL_8821A_2ANT))\r
200                         {\r
201                                 wifiRssiState = BTC_RSSI_STATE_HIGH;\r
202                         }\r
203                         else if(wifiRssi < rssiThresh)\r
204                         {\r
205                                 wifiRssiState = BTC_RSSI_STATE_LOW;\r
206                         }\r
207                         else\r
208                         {\r
209                                 wifiRssiState = BTC_RSSI_STATE_STAY_MEDIUM;\r
210                         }\r
211                 }\r
212                 else\r
213                 {\r
214                         if(wifiRssi < rssiThresh1)\r
215                         {\r
216                                 wifiRssiState = BTC_RSSI_STATE_MEDIUM;\r
217                         }\r
218                         else\r
219                         {\r
220                                 wifiRssiState = BTC_RSSI_STATE_STAY_HIGH;\r
221                         }\r
222                 }\r
223         }\r
224                 \r
225         pCoexSta->preWifiRssiState[index] = wifiRssiState;\r
226 \r
227         return wifiRssiState;\r
228 }\r
229 \r
230 VOID\r
231 halbtc8821a2ant_MonitorBtEnableDisable(\r
232         IN      PBTC_COEXIST            pBtCoexist\r
233         )\r
234 {\r
235         static BOOLEAN  bPreBtDisabled=FALSE;\r
236         static u4Byte   btDisableCnt=0;\r
237         BOOLEAN                 bBtActive=TRUE, bBtDisabled=FALSE;\r
238 \r
239         // This function check if bt is disabled\r
240 \r
241         if(     pCoexSta->highPriorityTx == 0 &&\r
242                 pCoexSta->highPriorityRx == 0 &&\r
243                 pCoexSta->lowPriorityTx == 0 &&\r
244                 pCoexSta->lowPriorityRx == 0)\r
245         {\r
246                 bBtActive = FALSE;\r
247         }\r
248         if(     pCoexSta->highPriorityTx == 0xffff &&\r
249                 pCoexSta->highPriorityRx == 0xffff &&\r
250                 pCoexSta->lowPriorityTx == 0xffff &&\r
251                 pCoexSta->lowPriorityRx == 0xffff)\r
252         {\r
253                 bBtActive = FALSE;\r
254         }\r
255         if(bBtActive)\r
256         {\r
257                 btDisableCnt = 0;\r
258                 bBtDisabled = FALSE;\r
259                 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_DISABLE, &bBtDisabled);\r
260                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT is enabled !!\n"));\r
261         }\r
262         else\r
263         {\r
264                 btDisableCnt++;\r
265                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], bt all counters=0, %d times!!\n", \r
266                                 btDisableCnt));\r
267                 if(btDisableCnt >= 2)\r
268                 {\r
269                         bBtDisabled = TRUE;\r
270                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_DISABLE, &bBtDisabled);\r
271                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT is disabled !!\n"));\r
272                 }\r
273         }\r
274         if(bPreBtDisabled != bBtDisabled)\r
275         {\r
276                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT is from %s to %s!!\n", \r
277                         (bPreBtDisabled ? "disabled":"enabled"), \r
278                         (bBtDisabled ? "disabled":"enabled")));\r
279                 bPreBtDisabled = bBtDisabled;\r
280                 if(!bBtDisabled)\r
281                 {\r
282                 }\r
283                 else\r
284                 {\r
285                 }\r
286         }\r
287 }\r
288 \r
289 VOID\r
290 halbtc8821a2ant_LimitedRx(\r
291         IN      PBTC_COEXIST            pBtCoexist,\r
292         IN      BOOLEAN                         bForceExec,\r
293         IN      BOOLEAN                         bRejApAggPkt,\r
294         IN      BOOLEAN                         bBtCtrlAggBufSize,\r
295         IN      u1Byte                          aggBufSize\r
296         )\r
297 {\r
298         BOOLEAN bRejectRxAgg=bRejApAggPkt;\r
299         BOOLEAN bBtCtrlRxAggSize=bBtCtrlAggBufSize;\r
300         u1Byte  rxAggSize=aggBufSize;\r
301 \r
302         //============================================\r
303         //      Rx Aggregation related setting\r
304         //============================================\r
305         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT, &bRejectRxAgg);\r
306         // decide BT control aggregation buf size or not\r
307         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE, &bBtCtrlRxAggSize);\r
308         // aggregation buf size, only work when BT control Rx aggregation size.\r
309         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_AGG_BUF_SIZE, &rxAggSize);\r
310         // real update aggregation setting\r
311         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);\r
312 }\r
313 \r
314 VOID\r
315 halbtc8821a2ant_MonitorBtCtr(\r
316         IN      PBTC_COEXIST            pBtCoexist\r
317         )\r
318 {\r
319         u4Byte                  regHPTxRx, regLPTxRx, u4Tmp;\r
320         u4Byte                  regHPTx=0, regHPRx=0, regLPTx=0, regLPRx=0;\r
321         u1Byte                  u1Tmp;\r
322         \r
323         PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
324         \r
325         regHPTxRx = 0x770;\r
326         regLPTxRx = 0x774;\r
327 \r
328         u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regHPTxRx);\r
329         regHPTx = u4Tmp & bMaskLWord;\r
330         regHPRx = (u4Tmp & bMaskHWord)>>16;\r
331 \r
332         u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regLPTxRx);\r
333         regLPTx = u4Tmp & bMaskLWord;\r
334         regLPRx = (u4Tmp & bMaskHWord)>>16;\r
335                 \r
336         pCoexSta->highPriorityTx = regHPTx;\r
337         pCoexSta->highPriorityRx = regHPRx;\r
338         pCoexSta->lowPriorityTx = regLPTx;\r
339         pCoexSta->lowPriorityRx = regLPRx;\r
340 \r
341         if ( (pCoexSta->lowPriorityRx >= 950)  &&  (pCoexSta->lowPriorityRx >= pCoexSta->lowPriorityTx) && (!pCoexSta->bUnderIps) )\r
342         {\r
343                 pBtLinkInfo->bSlaveRole = TRUE;\r
344         }\r
345         else\r
346         {\r
347                 pBtLinkInfo->bSlaveRole = FALSE;\r
348         }\r
349 \r
350         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], High Priority Tx/Rx (reg 0x%x)=0x%x(%d)/0x%x(%d)\n", \r
351                 regHPTxRx, regHPTx, regHPTx, regHPRx, regHPRx));\r
352         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Low Priority Tx/Rx (reg 0x%x)=0x%x(%d)/0x%x(%d)\n", \r
353                 regLPTxRx, regLPTx, regLPTx, regLPRx, regLPRx));\r
354 \r
355         // reset counter\r
356         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0xc);\r
357 }\r
358 \r
359 VOID\r
360 halbtc8821a2ant_MonitorWiFiCtr(\r
361         IN      PBTC_COEXIST            pBtCoexist\r
362         )\r
363 {\r
364         u4Byte  u4Tmp;\r
365         u2Byte  u2Tmp[3];\r
366         s4Byte  wifiRssi=0;\r
367         BOOLEAN bWifiBusy = FALSE, bWifiUnderBMode = FALSE;\r
368         static u1Byte nCCKLockCounter = 0;\r
369 \r
370 \r
371         if (pCoexSta->bUnderIps)\r
372         {\r
373                 pCoexSta->nCRCOK_CCK = 0;\r
374                 pCoexSta->nCRCOK_11g = 0;\r
375                 pCoexSta->nCRCOK_11n = 0;\r
376                 pCoexSta->nCRCOK_11nAgg = 0;\r
377 \r
378                 pCoexSta->nCRCErr_CCK = 0;\r
379                 pCoexSta->nCRCErr_11g = 0;\r
380                 pCoexSta->nCRCErr_11n = 0;\r
381                 pCoexSta->nCRCErr_11nAgg = 0;   \r
382         }\r
383         else\r
384         {\r
385                 pCoexSta->nCRCOK_CCK    = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xf88);\r
386                 pCoexSta->nCRCOK_11g    = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xf94);\r
387                 pCoexSta->nCRCOK_11n    = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xf90);\r
388                 pCoexSta->nCRCOK_11nAgg= pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xfb8);\r
389 \r
390                 pCoexSta->nCRCErr_CCK    = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xf84);\r
391                 pCoexSta->nCRCErr_11g    = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xf96);\r
392                 pCoexSta->nCRCErr_11n    = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xf92);\r
393                 pCoexSta->nCRCErr_11nAgg = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xfba);                \r
394         }\r
395 \r
396         //reset counter\r
397         pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xf16, 0x1, 0x1);\r
398         pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xf16, 0x1, 0x0);\r
399 }\r
400 \r
401 VOID\r
402 halbtc8821a2ant_QueryBtInfo(\r
403         IN      PBTC_COEXIST            pBtCoexist\r
404         )\r
405 {\r
406         u1Byte                  H2C_Parameter[1] ={0};\r
407 \r
408         pCoexSta->bC2hBtInfoReqSent = TRUE;\r
409 \r
410         H2C_Parameter[0] |= BIT0;       // trigger\r
411 \r
412         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Query Bt Info, FW write 0x61=0x%x\n", \r
413                 H2C_Parameter[0]));\r
414 \r
415         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x61, 1, H2C_Parameter);\r
416 }\r
417 \r
418 BOOLEAN\r
419 halbtc8821a2ant_IsWifiStatusChanged(\r
420         IN      PBTC_COEXIST            pBtCoexist\r
421         )\r
422 {\r
423         static BOOLEAN  bPreWifiBusy=FALSE, bPreUnder4way=FALSE, bPreBtHsOn=FALSE;\r
424         BOOLEAN                 bWifiBusy=FALSE, bUnder4way=FALSE, bBtHsOn=FALSE;\r
425         BOOLEAN                 bWifiConnected=FALSE;\r
426         u1Byte                  wifiRssiState=BTC_RSSI_STATE_HIGH;\r
427         \r
428 \r
429         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
430         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);\r
431         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
432         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &bUnder4way);\r
433 \r
434         if(bWifiConnected)\r
435         {\r
436                 if(bWifiBusy != bPreWifiBusy)\r
437                 {\r
438                         bPreWifiBusy = bWifiBusy;\r
439                         return TRUE;\r
440                 }\r
441                 if(bUnder4way != bPreUnder4way)\r
442                 {\r
443                         bPreUnder4way = bUnder4way;\r
444                         return TRUE;\r
445                 }\r
446                 if(bBtHsOn != bPreBtHsOn)\r
447                 {\r
448                         bPreBtHsOn = bBtHsOn;\r
449                         return TRUE;\r
450                 }\r
451 \r
452 \r
453                 wifiRssiState = halbtc8821a2ant_WifiRssiState(pBtCoexist,3, 2, BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);    \r
454 \r
455                 if ( (BTC_RSSI_STATE_HIGH ==wifiRssiState ) ||  (BTC_RSSI_STATE_LOW ==wifiRssiState ))\r
456                 {\r
457                         return TRUE;\r
458                 }\r
459         \r
460         }\r
461 \r
462         return FALSE;\r
463 }\r
464 \r
465 VOID\r
466 halbtc8821a2ant_UpdateBtLinkInfo(\r
467         IN      PBTC_COEXIST            pBtCoexist\r
468         )\r
469 {\r
470         PBTC_STACK_INFO         pStackInfo=&pBtCoexist->stackInfo;\r
471         PBTC_BT_LINK_INFO       pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
472         BOOLEAN                         bBtHsOn=FALSE;\r
473 \r
474 #if(BT_AUTO_REPORT_ONLY_8821A_2ANT == 1)        // profile from bt patch\r
475         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
476 \r
477         pBtLinkInfo->bBtLinkExist = pCoexSta->bBtLinkExist;\r
478         pBtLinkInfo->bScoExist = pCoexSta->bScoExist;\r
479         pBtLinkInfo->bA2dpExist = pCoexSta->bA2dpExist;\r
480         pBtLinkInfo->bPanExist = pCoexSta->bPanExist;\r
481         pBtLinkInfo->bHidExist = pCoexSta->bHidExist;\r
482 \r
483         // work around for HS mode.\r
484         if(bBtHsOn)\r
485         {\r
486                 pBtLinkInfo->bPanExist = TRUE;\r
487                 pBtLinkInfo->bBtLinkExist = TRUE;\r
488         }\r
489 #else   // profile from bt stack\r
490         pBtLinkInfo->bBtLinkExist = pStackInfo->bBtLinkExist;\r
491         pBtLinkInfo->bScoExist = pStackInfo->bScoExist;\r
492         pBtLinkInfo->bA2dpExist = pStackInfo->bA2dpExist;\r
493         pBtLinkInfo->bPanExist = pStackInfo->bPanExist;\r
494         pBtLinkInfo->bHidExist = pStackInfo->bHidExist;\r
495 \r
496         //for win-8 stack HID report error\r
497         if(!pStackInfo->bHidExist)\r
498                 pStackInfo->bHidExist = pCoexSta->bHidExist;  //sync  BTInfo with BT firmware and stack\r
499         // when stack HID report error, here we use the info from bt fw.\r
500         if(!pStackInfo->bBtLinkExist)\r
501                 pStackInfo->bBtLinkExist = pCoexSta->bBtLinkExist;      \r
502 #endif\r
503         // check if Sco only\r
504         if( pBtLinkInfo->bScoExist &&\r
505                 !pBtLinkInfo->bA2dpExist &&\r
506                 !pBtLinkInfo->bPanExist &&\r
507                 !pBtLinkInfo->bHidExist )\r
508                 pBtLinkInfo->bScoOnly = TRUE;\r
509         else\r
510                 pBtLinkInfo->bScoOnly = FALSE;\r
511 \r
512         // check if A2dp only\r
513         if( !pBtLinkInfo->bScoExist &&\r
514                 pBtLinkInfo->bA2dpExist &&\r
515                 !pBtLinkInfo->bPanExist &&\r
516                 !pBtLinkInfo->bHidExist )\r
517                 pBtLinkInfo->bA2dpOnly = TRUE;\r
518         else\r
519                 pBtLinkInfo->bA2dpOnly = FALSE;\r
520 \r
521         // check if Pan only\r
522         if( !pBtLinkInfo->bScoExist &&\r
523                 !pBtLinkInfo->bA2dpExist &&\r
524                 pBtLinkInfo->bPanExist &&\r
525                 !pBtLinkInfo->bHidExist )\r
526                 pBtLinkInfo->bPanOnly = TRUE;\r
527         else\r
528                 pBtLinkInfo->bPanOnly = FALSE;\r
529         \r
530         // check if Hid only\r
531         if( !pBtLinkInfo->bScoExist &&\r
532                 !pBtLinkInfo->bA2dpExist &&\r
533                 !pBtLinkInfo->bPanExist &&\r
534                 pBtLinkInfo->bHidExist )\r
535                 pBtLinkInfo->bHidOnly = TRUE;\r
536         else\r
537                 pBtLinkInfo->bHidOnly = FALSE;\r
538 }\r
539 \r
540 u1Byte\r
541 halbtc8821a2ant_ActionAlgorithm(\r
542         IN      PBTC_COEXIST            pBtCoexist\r
543         )\r
544 {\r
545         PBTC_BT_LINK_INFO       pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
546         BOOLEAN                         bBtHsOn=FALSE;\r
547         u1Byte                          algorithm=BT_8821A_2ANT_COEX_ALGO_UNDEFINED;\r
548         u1Byte                          numOfDiffProfile=0;\r
549 \r
550         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
551                 \r
552         if(!pBtLinkInfo->bBtLinkExist)\r
553         {\r
554                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], No BT link exists!!!\n"));\r
555                 return algorithm;\r
556         }\r
557 \r
558         if(pBtLinkInfo->bScoExist)\r
559                 numOfDiffProfile++;\r
560         if(pBtLinkInfo->bHidExist)\r
561                 numOfDiffProfile++;\r
562         if(pBtLinkInfo->bPanExist)\r
563                 numOfDiffProfile++;\r
564         if(pBtLinkInfo->bA2dpExist)\r
565                 numOfDiffProfile++;\r
566         \r
567         if(numOfDiffProfile == 1)\r
568         {\r
569                 if(pBtLinkInfo->bScoExist)\r
570                 {\r
571                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO only\n"));\r
572                         algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;\r
573                 }\r
574                 else\r
575                 {\r
576                         if(pBtLinkInfo->bHidExist)\r
577                         {\r
578                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], HID only\n"));\r
579                                 algorithm = BT_8821A_2ANT_COEX_ALGO_HID;\r
580                         }\r
581                         else if(pBtLinkInfo->bA2dpExist)\r
582                         {\r
583                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], A2DP only\n"));\r
584                                 algorithm = BT_8821A_2ANT_COEX_ALGO_A2DP;\r
585                         }\r
586                         else if(pBtLinkInfo->bPanExist)\r
587                         {\r
588                                 if(bBtHsOn)\r
589                                 {\r
590                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], PAN(HS) only\n"));\r
591                                         algorithm = BT_8821A_2ANT_COEX_ALGO_PANHS;\r
592                                 }\r
593                                 else\r
594                                 {\r
595                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], PAN(EDR) only\n"));\r
596                                         algorithm = BT_8821A_2ANT_COEX_ALGO_PANEDR;\r
597                                 }\r
598                         }\r
599                 }\r
600         }\r
601         else if(numOfDiffProfile == 2)\r
602         {\r
603                 if(pBtLinkInfo->bScoExist)\r
604                 {\r
605                         if(pBtLinkInfo->bHidExist)\r
606                         {\r
607                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO + HID\n"));\r
608                                 algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;\r
609                         }\r
610                         else if(pBtLinkInfo->bA2dpExist)\r
611                         {\r
612                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO + A2DP ==> SCO\n"));\r
613                                 algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;\r
614                         }\r
615                         else if(pBtLinkInfo->bPanExist)\r
616                         {\r
617                                 if(bBtHsOn)\r
618                                 {\r
619                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO + PAN(HS)\n"));\r
620                                         algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;\r
621                                 }\r
622                                 else\r
623                                 {\r
624                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO + PAN(EDR)\n"));\r
625                                         algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;\r
626                                 }\r
627                         }\r
628                 }\r
629                 else\r
630                 {\r
631                         if( pBtLinkInfo->bHidExist &&\r
632                                 pBtLinkInfo->bA2dpExist )\r
633                         {\r
634 #if 0\r
635                                 if(pStackInfo->numOfHid >= 2)\r
636                                 {\r
637                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], HID*2 + A2DP\n"));\r
638                                         algorithm = BT_8821A_2ANT_COEX_ALGO_HID_A2DP_PANEDR;\r
639                                 }\r
640                                 else\r
641 #endif\r
642                                 {                       \r
643                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], HID + A2DP\n"));\r
644                                         algorithm = BT_8821A_2ANT_COEX_ALGO_HID_A2DP;\r
645                                 }\r
646                         }\r
647                         else if( pBtLinkInfo->bHidExist &&\r
648                                 pBtLinkInfo->bPanExist )\r
649                         {\r
650                                 if(bBtHsOn)\r
651                                 {\r
652                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], HID + PAN(HS)\n"));\r
653                                         algorithm = BT_8821A_2ANT_COEX_ALGO_HID;\r
654                                 }\r
655                                 else\r
656                                 {\r
657                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], HID + PAN(EDR)\n"));\r
658                                         algorithm = BT_8821A_2ANT_COEX_ALGO_PANEDR_HID;\r
659                                 }\r
660                         }\r
661                         else if( pBtLinkInfo->bPanExist &&\r
662                                 pBtLinkInfo->bA2dpExist )\r
663                         {\r
664                                 if(bBtHsOn)\r
665                                 {\r
666                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], A2DP + PAN(HS)\n"));\r
667                                         algorithm = BT_8821A_2ANT_COEX_ALGO_A2DP_PANHS;\r
668                                 }\r
669                                 else\r
670                                 {\r
671                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], A2DP + PAN(EDR)\n"));\r
672                                         algorithm = BT_8821A_2ANT_COEX_ALGO_PANEDR_A2DP;\r
673                                 }\r
674                         }\r
675                 }\r
676         }\r
677         else if(numOfDiffProfile == 3)\r
678         {\r
679                 if(pBtLinkInfo->bScoExist)\r
680                 {\r
681                         if( pBtLinkInfo->bHidExist &&\r
682                                 pBtLinkInfo->bA2dpExist )\r
683                         {\r
684                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO + HID + A2DP ==> SCO\n"));\r
685                                 algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;\r
686                         }\r
687                         else if( pBtLinkInfo->bHidExist &&\r
688                                 pBtLinkInfo->bPanExist )\r
689                         {\r
690                                 if(bBtHsOn)\r
691                                 {\r
692                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO + HID + PAN(HS) ==> SCO\n"));\r
693                                         algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;\r
694                                 }\r
695                                 else\r
696                                 {\r
697                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO + HID + PAN(EDR) ==> SCO\n"));\r
698                                         algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;\r
699                                 }\r
700                         }\r
701                         else if( pBtLinkInfo->bPanExist &&\r
702                                 pBtLinkInfo->bA2dpExist )\r
703                         {\r
704                                 if(bBtHsOn)\r
705                                 {\r
706                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO + A2DP + PAN(HS)\n"));\r
707                                         algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;\r
708                                 }\r
709                                 else\r
710                                 {\r
711                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO + A2DP + PAN(EDR) ==> HID\n"));\r
712                                         algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;\r
713                                 }\r
714                         }\r
715                 }\r
716                 else\r
717                 {\r
718                         if( pBtLinkInfo->bHidExist &&\r
719                                 pBtLinkInfo->bPanExist &&\r
720                                 pBtLinkInfo->bA2dpExist )\r
721                         {\r
722                                 if(bBtHsOn)\r
723                                 {\r
724                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], HID + A2DP + PAN(HS)\n"));\r
725                                         algorithm = BT_8821A_2ANT_COEX_ALGO_HID_A2DP;\r
726                                 }\r
727                                 else\r
728                                 {\r
729                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], HID + A2DP + PAN(EDR)\n"));\r
730                                         algorithm = BT_8821A_2ANT_COEX_ALGO_HID_A2DP_PANEDR;\r
731                                 }\r
732                         }\r
733                 }\r
734         }\r
735         else if(numOfDiffProfile >= 3)\r
736         {\r
737                 if(pBtLinkInfo->bScoExist)\r
738                 {\r
739                         if( pBtLinkInfo->bHidExist &&\r
740                                 pBtLinkInfo->bPanExist &&\r
741                                 pBtLinkInfo->bA2dpExist )\r
742                         {\r
743                                 if(bBtHsOn)\r
744                                 {\r
745                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Error!!! SCO + HID + A2DP + PAN(HS)\n"));\r
746 \r
747                                 }\r
748                                 else\r
749                                 {\r
750                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n"));\r
751                                         algorithm = BT_8821A_2ANT_COEX_ALGO_SCO;\r
752                                 }\r
753                         }\r
754                 }\r
755         }\r
756 \r
757         return algorithm;\r
758 }\r
759 \r
760 VOID\r
761 halbtc8821a2ant_SetFwDacSwingLevel(\r
762         IN      PBTC_COEXIST            pBtCoexist,\r
763         IN      u1Byte                  dacSwingLvl\r
764         )\r
765 {\r
766         u1Byte                  H2C_Parameter[1] ={0};\r
767 \r
768         // There are several type of dacswing\r
769         // 0x18/ 0x10/ 0xc/ 0x8/ 0x4/ 0x6\r
770         H2C_Parameter[0] = dacSwingLvl;\r
771 \r
772         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Set Dac Swing Level=0x%x\n", dacSwingLvl));\r
773         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], FW write 0x64=0x%x\n", H2C_Parameter[0]));\r
774 \r
775         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x64, 1, H2C_Parameter);\r
776 }\r
777 \r
778 VOID\r
779 halbtc8821a2ant_SetFwDecBtPwr(\r
780         IN      PBTC_COEXIST            pBtCoexist,\r
781         IN      u1Byte                          decBtPwrLvl\r
782         )\r
783 {\r
784         u1Byte                  H2C_Parameter[1] ={0};\r
785         \r
786         H2C_Parameter[0] = decBtPwrLvl;\r
787 \r
788         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], decrease Bt Power level = %d, FW write 0x62=0x%x\n", \r
789                 decBtPwrLvl, H2C_Parameter[0]));\r
790 \r
791         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x62, 1, H2C_Parameter);    \r
792 }\r
793 \r
794 VOID\r
795 halbtc8821a2ant_DecBtPwr(\r
796         IN      PBTC_COEXIST            pBtCoexist,\r
797         IN      BOOLEAN                         bForceExec,\r
798         IN      u1Byte                          decBtPwrLvl\r
799         )\r
800 {\r
801         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s Dec BT power level = %d\n",  \r
802                 (bForceExec? "force to":""), decBtPwrLvl));\r
803         pCoexDm->curBtDecPwrLvl = decBtPwrLvl;\r
804 \r
805         if(!bForceExec)\r
806         {\r
807                 if(pCoexDm->preBtDecPwrLvl == pCoexDm->curBtDecPwrLvl) \r
808                         return;\r
809         }\r
810         halbtc8821a2ant_SetFwDecBtPwr(pBtCoexist, pCoexDm->curBtDecPwrLvl);\r
811 \r
812         pCoexDm->preBtDecPwrLvl = pCoexDm->curBtDecPwrLvl;\r
813 }\r
814 \r
815 VOID\r
816 halbtc8821a2ant_SetBtAutoReport(\r
817         IN      PBTC_COEXIST            pBtCoexist,\r
818         IN      BOOLEAN                 bEnableAutoReport\r
819         )\r
820 {\r
821         u1Byte                  H2C_Parameter[1] ={0};\r
822         \r
823         H2C_Parameter[0] = 0;\r
824 \r
825         if(bEnableAutoReport)\r
826         {\r
827                 H2C_Parameter[0] |= BIT0;\r
828         }\r
829 \r
830         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], BT FW auto report : %s, FW write 0x68=0x%x\n", \r
831                 (bEnableAutoReport? "Enabled!!":"Disabled!!"), H2C_Parameter[0]));\r
832 \r
833         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x68, 1, H2C_Parameter);    \r
834 }\r
835 \r
836 VOID\r
837 halbtc8821a2ant_BtAutoReport(\r
838         IN      PBTC_COEXIST            pBtCoexist,\r
839         IN      BOOLEAN                 bForceExec,\r
840         IN      BOOLEAN                 bEnableAutoReport\r
841         )\r
842 {\r
843         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s BT Auto report = %s\n",  \r
844                 (bForceExec? "force to":""), ((bEnableAutoReport)? "Enabled":"Disabled")));\r
845         pCoexDm->bCurBtAutoReport = bEnableAutoReport;\r
846 \r
847         if(!bForceExec)\r
848         {\r
849                 if(pCoexDm->bPreBtAutoReport == pCoexDm->bCurBtAutoReport) \r
850                         return;\r
851         }\r
852         halbtc8821a2ant_SetBtAutoReport(pBtCoexist, pCoexDm->bCurBtAutoReport);\r
853 \r
854         pCoexDm->bPreBtAutoReport = pCoexDm->bCurBtAutoReport;\r
855 }\r
856 \r
857 VOID\r
858 halbtc8821a2ant_FwDacSwingLvl(\r
859         IN      PBTC_COEXIST            pBtCoexist,\r
860         IN      BOOLEAN                 bForceExec,\r
861         IN      u1Byte                  fwDacSwingLvl\r
862         )\r
863 {\r
864         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s set FW Dac Swing level = %d\n",  \r
865                 (bForceExec? "force to":""), fwDacSwingLvl));\r
866         pCoexDm->curFwDacSwingLvl = fwDacSwingLvl;\r
867 \r
868         if(!bForceExec)\r
869         {\r
870                 if(pCoexDm->preFwDacSwingLvl == pCoexDm->curFwDacSwingLvl) \r
871                         return;\r
872         }\r
873 \r
874         halbtc8821a2ant_SetFwDacSwingLevel(pBtCoexist, pCoexDm->curFwDacSwingLvl);\r
875 \r
876         pCoexDm->preFwDacSwingLvl = pCoexDm->curFwDacSwingLvl;\r
877 }\r
878 \r
879 VOID\r
880 halbtc8821a2ant_SetSwRfRxLpfCorner(\r
881         IN      PBTC_COEXIST            pBtCoexist,\r
882         IN      BOOLEAN                 bRxRfShrinkOn\r
883         )\r
884 {\r
885         if(bRxRfShrinkOn)\r
886         {\r
887                 //Shrink RF Rx LPF corner\r
888                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Shrink RF Rx LPF corner!!\n"));\r
889                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff, 0xffffc);\r
890         }\r
891         else\r
892         {\r
893                 //Resume RF Rx LPF corner\r
894                 // After initialized, we can use pCoexDm->btRf0x1eBackup\r
895                 if(pBtCoexist->bInitilized)\r
896                 {\r
897                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Resume RF Rx LPF corner!!\n"));\r
898                         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff, pCoexDm->btRf0x1eBackup);\r
899                 }\r
900         }\r
901 }\r
902 \r
903 VOID\r
904 halbtc8821a2ant_RfShrink(\r
905         IN      PBTC_COEXIST            pBtCoexist,\r
906         IN      BOOLEAN                 bForceExec,\r
907         IN      BOOLEAN                 bRxRfShrinkOn\r
908         )\r
909 {\r
910         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn Rx RF Shrink = %s\n",  \r
911                 (bForceExec? "force to":""), ((bRxRfShrinkOn)? "ON":"OFF")));\r
912         pCoexDm->bCurRfRxLpfShrink = bRxRfShrinkOn;\r
913 \r
914         if(!bForceExec)\r
915         {\r
916                 if(pCoexDm->bPreRfRxLpfShrink == pCoexDm->bCurRfRxLpfShrink) \r
917                         return;\r
918         }\r
919         halbtc8821a2ant_SetSwRfRxLpfCorner(pBtCoexist, pCoexDm->bCurRfRxLpfShrink);\r
920 \r
921         pCoexDm->bPreRfRxLpfShrink = pCoexDm->bCurRfRxLpfShrink;\r
922 }\r
923 \r
924 VOID\r
925 halbtc8821a2ant_SetSwPenaltyTxRateAdaptive(\r
926         IN      PBTC_COEXIST            pBtCoexist,\r
927         IN      BOOLEAN                 bLowPenaltyRa\r
928         )\r
929 {\r
930         u1Byte                  H2C_Parameter[6] ={0};\r
931         \r
932         H2C_Parameter[0] = 0x6; // opCode, 0x6= Retry_Penalty\r
933 \r
934         if(bLowPenaltyRa)\r
935         {\r
936                 H2C_Parameter[1] |= BIT0;\r
937                 H2C_Parameter[2] = 0x00;  //normal rate except MCS7/6/5, OFDM54/48/36\r
938                 H2C_Parameter[3] = 0xf7;  //MCS7 or OFDM54\r
939                 H2C_Parameter[4] = 0xf8;  //MCS6 or OFDM48\r
940                 H2C_Parameter[5] = 0xf9;        //MCS5 or OFDM36        \r
941         }\r
942 \r
943         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set WiFi Low-Penalty Retry: %s", \r
944                 (bLowPenaltyRa? "ON!!":"OFF!!")) );\r
945 \r
946         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x69, 6, H2C_Parameter);\r
947 }\r
948 \r
949 VOID\r
950 halbtc8821a2ant_LowPenaltyRa(\r
951         IN      PBTC_COEXIST            pBtCoexist,\r
952         IN      BOOLEAN                 bForceExec,\r
953         IN      BOOLEAN                 bLowPenaltyRa\r
954         )\r
955 {\r
956         //return;\r
957         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn LowPenaltyRA = %s\n",  \r
958                 (bForceExec? "force to":""), ((bLowPenaltyRa)? "ON":"OFF")));\r
959         pCoexDm->bCurLowPenaltyRa = bLowPenaltyRa;\r
960 \r
961         if(!bForceExec)\r
962         {\r
963                 if(pCoexDm->bPreLowPenaltyRa == pCoexDm->bCurLowPenaltyRa) \r
964                         return;\r
965         }\r
966         halbtc8821a2ant_SetSwPenaltyTxRateAdaptive(pBtCoexist, pCoexDm->bCurLowPenaltyRa);\r
967 \r
968         pCoexDm->bPreLowPenaltyRa = pCoexDm->bCurLowPenaltyRa;\r
969 }\r
970 \r
971 VOID\r
972 halbtc8821a2ant_SetDacSwingReg(\r
973         IN      PBTC_COEXIST            pBtCoexist,\r
974         IN      u4Byte                  level\r
975         )\r
976 {\r
977         u1Byte  val=(u1Byte)level;\r
978 \r
979         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Write SwDacSwing = 0x%x\n", level));\r
980         pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xc5b, 0x3e, val);\r
981 }\r
982 \r
983 VOID\r
984 halbtc8821a2ant_SetSwFullTimeDacSwing(\r
985         IN      PBTC_COEXIST            pBtCoexist,\r
986         IN      BOOLEAN                 bSwDacSwingOn,\r
987         IN      u4Byte                  swDacSwingLvl\r
988         )\r
989 {\r
990         if(bSwDacSwingOn)\r
991         {\r
992                 halbtc8821a2ant_SetDacSwingReg(pBtCoexist, swDacSwingLvl);\r
993         }\r
994         else\r
995         {\r
996                 halbtc8821a2ant_SetDacSwingReg(pBtCoexist, 0x18);\r
997         }\r
998 }\r
999 \r
1000 \r
1001 VOID\r
1002 halbtc8821a2ant_DacSwing(\r
1003         IN      PBTC_COEXIST            pBtCoexist,\r
1004         IN      BOOLEAN                 bForceExec,\r
1005         IN      BOOLEAN                 bDacSwingOn,\r
1006         IN      u4Byte                  dacSwingLvl\r
1007         )\r
1008 {\r
1009         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn DacSwing=%s, dacSwingLvl=0x%x\n",  \r
1010                 (bForceExec? "force to":""), ((bDacSwingOn)? "ON":"OFF"), dacSwingLvl));\r
1011         pCoexDm->bCurDacSwingOn = bDacSwingOn;\r
1012         pCoexDm->curDacSwingLvl = dacSwingLvl;\r
1013 \r
1014         if(!bForceExec)\r
1015         {\r
1016                 if( (pCoexDm->bPreDacSwingOn == pCoexDm->bCurDacSwingOn) &&\r
1017                         (pCoexDm->preDacSwingLvl == pCoexDm->curDacSwingLvl) )\r
1018                         return;\r
1019         }\r
1020         delay_ms(30);\r
1021         halbtc8821a2ant_SetSwFullTimeDacSwing(pBtCoexist, bDacSwingOn, dacSwingLvl);\r
1022 \r
1023         pCoexDm->bPreDacSwingOn = pCoexDm->bCurDacSwingOn;\r
1024         pCoexDm->preDacSwingLvl = pCoexDm->curDacSwingLvl;\r
1025 }\r
1026 \r
1027 VOID\r
1028 halbtc8821a2ant_SetAdcBackOff(\r
1029         IN      PBTC_COEXIST            pBtCoexist,\r
1030         IN      BOOLEAN                 bAdcBackOff\r
1031         )\r
1032 {\r
1033         if(bAdcBackOff)\r
1034         {\r
1035                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BB BackOff Level On!\n"));\r
1036                 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x8db, 0x60, 0x3);\r
1037         }\r
1038         else\r
1039         {\r
1040                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BB BackOff Level Off!\n"));\r
1041                 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x8db, 0x60, 0x1);\r
1042         }\r
1043 }\r
1044 \r
1045 VOID\r
1046 halbtc8821a2ant_AdcBackOff(\r
1047         IN      PBTC_COEXIST            pBtCoexist,\r
1048         IN      BOOLEAN                 bForceExec,\r
1049         IN      BOOLEAN                 bAdcBackOff\r
1050         )\r
1051 {\r
1052         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn AdcBackOff = %s\n",  \r
1053                 (bForceExec? "force to":""), ((bAdcBackOff)? "ON":"OFF")));\r
1054         pCoexDm->bCurAdcBackOff = bAdcBackOff;\r
1055 \r
1056         if(!bForceExec)\r
1057         {\r
1058                 if(pCoexDm->bPreAdcBackOff == pCoexDm->bCurAdcBackOff) \r
1059                         return;\r
1060         }\r
1061         halbtc8821a2ant_SetAdcBackOff(pBtCoexist, pCoexDm->bCurAdcBackOff);\r
1062 \r
1063         pCoexDm->bPreAdcBackOff = pCoexDm->bCurAdcBackOff;\r
1064 }\r
1065 \r
1066 VOID\r
1067 halbtc8821a2ant_SetAgcTable(\r
1068         IN      PBTC_COEXIST            pBtCoexist,\r
1069         IN      BOOLEAN                 bAgcTableEn\r
1070         )\r
1071 {\r
1072         u1Byte          rssiAdjustVal=0;\r
1073 \r
1074         //=================BB AGC Gain Table\r
1075         if(bAgcTableEn)\r
1076         {\r
1077                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BB Agc Table On!\n"));\r
1078                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x6e1A0001);\r
1079                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x6d1B0001);\r
1080                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x6c1C0001);\r
1081                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x6b1D0001);\r
1082                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x6a1E0001);\r
1083                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x691F0001);\r
1084                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x68200001);\r
1085         }\r
1086         else\r
1087         {\r
1088                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BB Agc Table Off!\n"));\r
1089                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xaa1A0001);\r
1090                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa91B0001);\r
1091                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa81C0001);\r
1092                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa71D0001);\r
1093                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa61E0001);\r
1094                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa51F0001);\r
1095                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa4200001);\r
1096         }\r
1097         \r
1098         \r
1099         //=================RF Gain\r
1100         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xef, 0xfffff, 0x02000);\r
1101         if(bAgcTableEn)\r
1102         {\r
1103                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Agc Table On!\n"));\r
1104                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x3b, 0xfffff, 0x38fff);\r
1105                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x3b, 0xfffff, 0x38ffe);\r
1106         }\r
1107         else\r
1108         {\r
1109                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Agc Table Off!\n"));\r
1110                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x3b, 0xfffff, 0x380c3);\r
1111                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x3b, 0xfffff, 0x28ce6);\r
1112         }\r
1113         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xef, 0xfffff, 0x0);\r
1114 \r
1115         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xed, 0xfffff, 0x1);\r
1116         if(bAgcTableEn)\r
1117         {\r
1118                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Agc Table On!\n"));\r
1119                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x40, 0xfffff, 0x38fff);\r
1120                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x40, 0xfffff, 0x38ffe);\r
1121         }\r
1122         else\r
1123         {\r
1124                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Agc Table Off!\n"));\r
1125                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x40, 0xfffff, 0x380c3);\r
1126                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x40, 0xfffff, 0x28ce6);\r
1127         }\r
1128         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xed, 0xfffff, 0x0);\r
1129 \r
1130         // set rssiAdjustVal for wifi module.\r
1131         if(bAgcTableEn)\r
1132         {\r
1133                 rssiAdjustVal = 8;\r
1134         }\r
1135         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON, &rssiAdjustVal);\r
1136 }\r
1137 \r
1138 VOID\r
1139 halbtc8821a2ant_AgcTable(\r
1140         IN      PBTC_COEXIST            pBtCoexist,\r
1141         IN      BOOLEAN                 bForceExec,\r
1142         IN      BOOLEAN                 bAgcTableEn\r
1143         )\r
1144 {\r
1145         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s %s Agc Table\n",  \r
1146                 (bForceExec? "force to":""), ((bAgcTableEn)? "Enable":"Disable")));\r
1147         pCoexDm->bCurAgcTableEn = bAgcTableEn;\r
1148 \r
1149         if(!bForceExec)\r
1150         {\r
1151                 if(pCoexDm->bPreAgcTableEn == pCoexDm->bCurAgcTableEn) \r
1152                         return;\r
1153         }\r
1154         halbtc8821a2ant_SetAgcTable(pBtCoexist, bAgcTableEn);\r
1155 \r
1156         pCoexDm->bPreAgcTableEn = pCoexDm->bCurAgcTableEn;\r
1157 }\r
1158 \r
1159 VOID\r
1160 halbtc8821a2ant_SetCoexTable(\r
1161         IN      PBTC_COEXIST    pBtCoexist,\r
1162         IN      u4Byte          val0x6c0,\r
1163         IN      u4Byte          val0x6c4,\r
1164         IN      u4Byte          val0x6c8,\r
1165         IN      u1Byte          val0x6cc\r
1166         )\r
1167 {\r
1168         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set coex table, set 0x6c0=0x%x\n", val0x6c0));\r
1169         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c0, val0x6c0);\r
1170 \r
1171         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set coex table, set 0x6c4=0x%x\n", val0x6c4));\r
1172         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c4, val0x6c4);\r
1173 \r
1174         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set coex table, set 0x6c8=0x%x\n", val0x6c8));\r
1175         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c8, val0x6c8);\r
1176 \r
1177         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set coex table, set 0x6cc=0x%x\n", val0x6cc));\r
1178         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cc, val0x6cc);\r
1179 }\r
1180 \r
1181 VOID\r
1182 halbtc8821a2ant_CoexTable(\r
1183         IN      PBTC_COEXIST            pBtCoexist,\r
1184         IN      BOOLEAN                 bForceExec,\r
1185         IN      u4Byte                  val0x6c0,\r
1186         IN      u4Byte                  val0x6c4,\r
1187         IN      u4Byte                  val0x6c8,\r
1188         IN      u1Byte                  val0x6cc\r
1189         )\r
1190 {\r
1191         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s write Coex Table 0x6c0=0x%x, 0x6c4=0x%x, 0x6c8=0x%x, 0x6cc=0x%x\n", \r
1192                 (bForceExec? "force to":""), val0x6c0, val0x6c4, val0x6c8, val0x6cc));\r
1193         pCoexDm->curVal0x6c0 = val0x6c0;\r
1194         pCoexDm->curVal0x6c4 = val0x6c4;\r
1195         pCoexDm->curVal0x6c8 = val0x6c8;\r
1196         pCoexDm->curVal0x6cc = val0x6cc;\r
1197 \r
1198         if(!bForceExec)\r
1199         {       \r
1200                 if( (pCoexDm->preVal0x6c0 == pCoexDm->curVal0x6c0) &&\r
1201                         (pCoexDm->preVal0x6c4 == pCoexDm->curVal0x6c4) &&\r
1202                         (pCoexDm->preVal0x6c8 == pCoexDm->curVal0x6c8) &&\r
1203                         (pCoexDm->preVal0x6cc == pCoexDm->curVal0x6cc) )\r
1204                         return;\r
1205         }\r
1206         halbtc8821a2ant_SetCoexTable(pBtCoexist, val0x6c0, val0x6c4, val0x6c8, val0x6cc);\r
1207 \r
1208         pCoexDm->preVal0x6c0 = pCoexDm->curVal0x6c0;\r
1209         pCoexDm->preVal0x6c4 = pCoexDm->curVal0x6c4;\r
1210         pCoexDm->preVal0x6c8 = pCoexDm->curVal0x6c8;\r
1211         pCoexDm->preVal0x6cc = pCoexDm->curVal0x6cc;\r
1212 }\r
1213 \r
1214 VOID\r
1215 halbtc8821a2ant_CoexTableWithType(\r
1216         IN      PBTC_COEXIST            pBtCoexist,\r
1217         IN      BOOLEAN                         bForceExec,\r
1218         IN      u1Byte                          type\r
1219         )\r
1220 {\r
1221         pCoexSta->nCoexTableType = type;\r
1222         \r
1223         switch(type)\r
1224         {\r
1225                 case 0:\r
1226                         halbtc8821a2ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0x55555555, 0xffffff, 0x3);\r
1227                         break;\r
1228                 case 1:\r
1229                         halbtc8821a2ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0x5afa5afa, 0xffffff, 0x3);\r
1230                         break;\r
1231                 case 2:\r
1232                         halbtc8821a2ant_CoexTable(pBtCoexist, bForceExec, 0x5ada5ada, 0x5ada5ada, 0xffffff, 0x3);\r
1233                         break;\r
1234                 case 3:\r
1235                         halbtc8821a2ant_CoexTable(pBtCoexist, bForceExec, 0xaaaaaaaa, 0xaaaaaaaa, 0xffffff, 0x3);\r
1236                         break;\r
1237                 case 4:\r
1238                         halbtc8821a2ant_CoexTable(pBtCoexist, bForceExec, 0xffffffff, 0xffffffff, 0xffffff, 0x3);\r
1239                         break;\r
1240                 case 5:\r
1241                         halbtc8821a2ant_CoexTable(pBtCoexist, bForceExec, 0x5fff5fff, 0x5fff5fff, 0xffffff, 0x3);\r
1242                         break;\r
1243                 case 6:\r
1244                         halbtc8821a2ant_CoexTable(pBtCoexist, bForceExec, 0x55ff55ff, 0x5a5a5a5a, 0xffffff, 0x3);\r
1245                         break;\r
1246                 case 7:\r
1247                         halbtc8821a2ant_CoexTable(pBtCoexist, bForceExec, 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3);\r
1248                         break;\r
1249                 case 8:\r
1250                         halbtc8821a2ant_CoexTable(pBtCoexist, bForceExec, 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3);\r
1251                         break;\r
1252                 case 9:\r
1253                         halbtc8821a2ant_CoexTable(pBtCoexist, bForceExec, 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3);\r
1254                         break;\r
1255                 case 10:\r
1256                         halbtc8821a2ant_CoexTable(pBtCoexist, bForceExec, 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3);\r
1257                         break;\r
1258                 case 11:\r
1259                         halbtc8821a2ant_CoexTable(pBtCoexist, bForceExec, 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3);\r
1260                         break;\r
1261                 case 12:\r
1262                         halbtc8821a2ant_CoexTable(pBtCoexist, bForceExec, 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3);\r
1263                         break;\r
1264                 case 13:\r
1265                         halbtc8821a2ant_CoexTable(pBtCoexist, bForceExec, 0x5fff5fff, 0xaaaaaaaa, 0xffffff, 0x3);\r
1266                         break;\r
1267                 case 14:\r
1268                         halbtc8821a2ant_CoexTable(pBtCoexist, bForceExec, 0x5fff5fff, 0x5ada5ada, 0xffffff, 0x3);\r
1269                         break;\r
1270                 case 15:\r
1271                         halbtc8821a2ant_CoexTable(pBtCoexist, bForceExec, 0x55dd55dd, 0xaaaaaaaa, 0xffffff, 0x3);\r
1272                         break;\r
1273                 case 16:\r
1274                         halbtc8821a2ant_CoexTable(pBtCoexist, bForceExec, 0x5fdf5fdf, 0x5fdb5fdb, 0xffffff, 0x3);\r
1275                         break;\r
1276                 case 17:\r
1277                         halbtc8821a2ant_CoexTable(pBtCoexist, bForceExec, 0xfafafafa, 0xfafafafa, 0xffffff, 0x3);\r
1278                         break;\r
1279                 default:\r
1280                         break;\r
1281         }\r
1282 }\r
1283 \r
1284 VOID\r
1285 halbtc8821a2ant_SetFwIgnoreWlanAct(\r
1286         IN      PBTC_COEXIST            pBtCoexist,\r
1287         IN      BOOLEAN                 bEnable\r
1288         )\r
1289 {\r
1290         u1Byte                  H2C_Parameter[1] ={0};\r
1291                 \r
1292         if(bEnable)\r
1293         {\r
1294                 H2C_Parameter[0] |= BIT0;               // function enable\r
1295         }\r
1296         \r
1297         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set FW for BT Ignore Wlan_Act, FW write 0x63=0x%x\n", \r
1298                 H2C_Parameter[0]));\r
1299 \r
1300         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x63, 1, H2C_Parameter);\r
1301 }\r
1302 \r
1303 VOID\r
1304 halbtc8821a2ant_SetLpsRpwm(\r
1305         IN      PBTC_COEXIST            pBtCoexist,\r
1306         IN      u1Byte                  lpsVal,\r
1307         IN      u1Byte                  rpwmVal\r
1308         )\r
1309 {\r
1310         u1Byte  lps=lpsVal;\r
1311         u1Byte  rpwm=rpwmVal;\r
1312         \r
1313         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_LPS_VAL, &lps);\r
1314         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_RPWM_VAL, &rpwm);\r
1315 }\r
1316 \r
1317 VOID\r
1318 halbtc8821a2ant_LpsRpwm(\r
1319         IN      PBTC_COEXIST            pBtCoexist,\r
1320         IN      BOOLEAN                 bForceExec,\r
1321         IN      u1Byte                  lpsVal,\r
1322         IN      u1Byte                  rpwmVal\r
1323         )\r
1324 {\r
1325         BOOLEAN bForceExecPwrCmd=FALSE;\r
1326         \r
1327         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s set lps/rpwm=0x%x/0x%x \n", \r
1328                 (bForceExec? "force to":""), lpsVal, rpwmVal));\r
1329         pCoexDm->curLps = lpsVal;\r
1330         pCoexDm->curRpwm = rpwmVal;\r
1331 \r
1332         if(!bForceExec)\r
1333         {\r
1334                 if( (pCoexDm->preLps == pCoexDm->curLps) &&\r
1335                         (pCoexDm->preRpwm == pCoexDm->curRpwm) )\r
1336                 {\r
1337                         return;\r
1338                 }\r
1339         }\r
1340         halbtc8821a2ant_SetLpsRpwm(pBtCoexist, lpsVal, rpwmVal);\r
1341 \r
1342         pCoexDm->preLps = pCoexDm->curLps;\r
1343         pCoexDm->preRpwm = pCoexDm->curRpwm;\r
1344 }\r
1345 \r
1346 VOID\r
1347 halbtc8821a2ant_IgnoreWlanAct(\r
1348         IN      PBTC_COEXIST            pBtCoexist,\r
1349         IN      BOOLEAN                 bForceExec,\r
1350         IN      BOOLEAN                 bEnable\r
1351         )\r
1352 {\r
1353         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn Ignore WlanAct %s\n", \r
1354                 (bForceExec? "force to":""), (bEnable? "ON":"OFF")));\r
1355         pCoexDm->bCurIgnoreWlanAct = bEnable;\r
1356 \r
1357         if(!bForceExec)\r
1358         {\r
1359                 if(pCoexDm->bPreIgnoreWlanAct == pCoexDm->bCurIgnoreWlanAct)\r
1360                         return;\r
1361         }\r
1362         halbtc8821a2ant_SetFwIgnoreWlanAct(pBtCoexist, bEnable);\r
1363 \r
1364         pCoexDm->bPreIgnoreWlanAct = pCoexDm->bCurIgnoreWlanAct;\r
1365 }\r
1366 \r
1367 VOID\r
1368 halbtc8821a2ant_SetFwPstdma(\r
1369         IN      PBTC_COEXIST            pBtCoexist,\r
1370         IN      u1Byte                  byte1,\r
1371         IN      u1Byte                  byte2,\r
1372         IN      u1Byte                  byte3,\r
1373         IN      u1Byte                  byte4,\r
1374         IN      u1Byte                  byte5\r
1375         )\r
1376 {\r
1377         u1Byte                  H2C_Parameter[5] ={0};\r
1378          \r
1379         H2C_Parameter[0] = byte1;       \r
1380         H2C_Parameter[1] = byte2;       \r
1381         H2C_Parameter[2] = byte3;\r
1382         H2C_Parameter[3] = byte4;\r
1383         H2C_Parameter[4] = byte5;\r
1384 \r
1385         pCoexDm->psTdmaPara[0] = byte1;\r
1386         pCoexDm->psTdmaPara[1] = byte2;\r
1387         pCoexDm->psTdmaPara[2] = byte3;\r
1388         pCoexDm->psTdmaPara[3] = byte4;\r
1389         pCoexDm->psTdmaPara[4] = byte5;\r
1390         \r
1391         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], FW write 0x60(5bytes)=0x%x%08x\n", \r
1392                 H2C_Parameter[0], \r
1393                 H2C_Parameter[1]<<24|H2C_Parameter[2]<<16|H2C_Parameter[3]<<8|H2C_Parameter[4]));\r
1394 \r
1395         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x60, 5, H2C_Parameter);\r
1396 }\r
1397 \r
1398 VOID\r
1399 halbtc8821a2ant_SwMechanism1(\r
1400         IN      PBTC_COEXIST    pBtCoexist,     \r
1401         IN      BOOLEAN         bShrinkRxLPF,\r
1402         IN      BOOLEAN         bLowPenaltyRA,\r
1403         IN      BOOLEAN         bLimitedDIG, \r
1404         IN      BOOLEAN         bBTLNAConstrain\r
1405         ) \r
1406 {\r
1407         /*\r
1408         u4Byte  wifiBw;\r
1409         \r
1410         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
1411         \r
1412         if(BTC_WIFI_BW_HT40 != wifiBw)  //only shrink RF Rx LPF for HT40\r
1413         {\r
1414                 if (bShrinkRxLPF)\r
1415                         bShrinkRxLPF = FALSE;\r
1416         }\r
1417         */\r
1418         \r
1419         //halbtc8821a2ant_RfShrink(pBtCoexist, NORMAL_EXEC, bShrinkRxLPF);\r
1420         halbtc8821a2ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, bLowPenaltyRA);\r
1421 }\r
1422 \r
1423 VOID\r
1424 halbtc8821a2ant_SwMechanism2(\r
1425         IN      PBTC_COEXIST    pBtCoexist,     \r
1426         IN      BOOLEAN         bAGCTableShift,\r
1427         IN      BOOLEAN         bADCBackOff,\r
1428         IN      BOOLEAN         bSWDACSwing,\r
1429         IN      u4Byte          dacSwingLvl\r
1430         ) \r
1431 {\r
1432         //halbtc8821a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, bAGCTableShift);\r
1433         //halbtc8821a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, bADCBackOff);\r
1434         halbtc8821a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, bSWDACSwing, dacSwingLvl);\r
1435 }\r
1436 \r
1437 VOID\r
1438 halbtc8821a2ant_SetAntPath(\r
1439         IN      PBTC_COEXIST            pBtCoexist,\r
1440         IN      u1Byte                          antPosType,\r
1441         IN      BOOLEAN                         bInitHwCfg,\r
1442         IN      BOOLEAN                         bWifiOff\r
1443         )\r
1444 {\r
1445         PBTC_BOARD_INFO         pBoardInfo=&pBtCoexist->boardInfo;\r
1446         u4Byte                          u4Tmp=0;\r
1447         u1Byte                          H2C_Parameter[2] ={0};\r
1448         \r
1449         if(bInitHwCfg)\r
1450         {\r
1451                 // 0x4c[23]=0, 0x4c[24]=1  Antenna control by WL/BT\r
1452                 u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);\r
1453                 u4Tmp &=~BIT23;\r
1454                 u4Tmp |= BIT24;\r
1455                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x4c, u4Tmp);\r
1456 \r
1457                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x974, 0x3ff);\r
1458                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0xcb4, 0x77);\r
1459 \r
1460                 if(pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT) \r
1461                 {\r
1462                         //tell firmware "antenna inverse"  ==> WRONG firmware antenna control code.==>need fw to fix\r
1463                         H2C_Parameter[0] = 1;\r
1464                         H2C_Parameter[1] = 1;\r
1465                         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x65, 2, H2C_Parameter);\r
1466                 }\r
1467                 else\r
1468                 {\r
1469                         //tell firmware "no antenna inverse" ==> WRONG firmware antenna control code.==>need fw to fix\r
1470                         H2C_Parameter[0] = 0;\r
1471                         H2C_Parameter[1] = 1;\r
1472                         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x65, 2, H2C_Parameter);\r
1473                 }\r
1474         }\r
1475         \r
1476         // ext switch setting\r
1477         switch(antPosType)\r
1478         {\r
1479                 case BTC_ANT_WIFI_AT_MAIN:\r
1480                         pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xcb7, 0x30, 0x1);\r
1481                         break;\r
1482                 case BTC_ANT_WIFI_AT_AUX:\r
1483                         pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xcb7, 0x30, 0x2);\r
1484                         break;\r
1485         }\r
1486 }\r
1487 \r
1488 VOID\r
1489 halbtc8821a2ant_PsTdma(\r
1490         IN      PBTC_COEXIST            pBtCoexist,\r
1491         IN      BOOLEAN                 bForceExec,\r
1492         IN      BOOLEAN                 bTurnOn,\r
1493         IN      u1Byte                  type\r
1494         )\r
1495 {\r
1496         BOOLEAN                 bTurnOnByCnt=FALSE;\r
1497         u1Byte                  psTdmaTypeByCnt=0;\r
1498         u1Byte                  wifiRssiState1, btRssiState;\r
1499 \r
1500         \r
1501         wifiRssiState1 = halbtc8821a2ant_WifiRssiState(pBtCoexist, 1, 2, BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);\r
1502         btRssiState = halbtc8821a2ant_BtRssiState(2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);\r
1503 \r
1504         if (!(BTC_RSSI_HIGH(wifiRssiState1) && BTC_RSSI_HIGH(btRssiState)) && bTurnOn)\r
1505         {\r
1506                 type = type +100;  //for WiFi RSSI low or BT RSSI low\r
1507         }\r
1508 \r
1509         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn %s PS TDMA, type=%d\n", \r
1510                 (bForceExec? "force to":""), (bTurnOn? "ON":"OFF"), type));\r
1511         pCoexDm->bCurPsTdmaOn = bTurnOn;\r
1512         pCoexDm->curPsTdma = type;\r
1513 \r
1514         if(!bForceExec)\r
1515         {\r
1516                 if( (pCoexDm->bPrePsTdmaOn == pCoexDm->bCurPsTdmaOn) &&\r
1517                         (pCoexDm->prePsTdma == pCoexDm->curPsTdma) )\r
1518                         return;\r
1519         }       \r
1520         if(bTurnOn)\r
1521         {\r
1522                 switch(type)\r
1523                 {\r
1524                         case 1:\r
1525                         default:\r
1526                                 //halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0xe1, 0x90);\r
1527                                 halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x3c, 0x03, 0xf1, 0x90);\r
1528                                 break;\r
1529                         case 2:\r
1530                                 //halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x12, 0xe1, 0x90);\r
1531                                 halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x2d, 0x03, 0xf1, 0x90);\r
1532                                 break;\r
1533                         case 3:\r
1534                                 halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1c, 0x3, 0xf1, 0x90);\r
1535                                 break;\r
1536                         case 4:\r
1537                                 halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x10, 0x03, 0xf1, 0x90);\r
1538                                 break;\r
1539                         case 5:\r
1540                                 //halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0x60, 0x90);\r
1541                                 halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x3c, 0x3, 0x70, 0x90);                           \r
1542                                 break;\r
1543                         case 6:\r
1544                                 //halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x12, 0x60, 0x90);\r
1545                                 halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x2d, 0x3, 0x70, 0x90);\r
1546                                 break;\r
1547                         case 7:\r
1548                                 halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1c, 0x3, 0x70, 0x90);\r
1549                                 break;\r
1550                         case 8: \r
1551                                 halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xa3, 0x10, 0x3, 0x70, 0x90);\r
1552                                 break;\r
1553                         case 9: \r
1554                                 //halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0xe1, 0x90);\r
1555                                 halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x3c, 0x03, 0xf1, 0x90);\r
1556                                 break;\r
1557                         case 10:        \r
1558                                 //halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x12, 0xe1, 0x90);\r
1559                                 halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x2d, 0x03, 0xf1, 0x90);\r
1560                                 break;\r
1561                         case 11:        \r
1562                                 //halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0xa, 0xa, 0xe1, 0x90);\r
1563                                 halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1c, 0x3, 0xf1, 0x90);\r
1564                                 break;\r
1565                         case 12:\r
1566                                 //halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x5, 0x5, 0xe1, 0x90);\r
1567                                 halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x10, 0x3, 0xf1, 0x90);\r
1568                                 break;\r
1569                         case 13:\r
1570                                 //halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0x60, 0x90);\r
1571                                 halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x3c, 0x3, 0x70, 0x90);           \r
1572                                 break;\r
1573                         case 14:\r
1574                                 //halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x12, 0x60, 0x90);\r
1575                                 halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x2d, 0x3, 0x70, 0x90);           \r
1576                                 break;\r
1577                         case 15:\r
1578                                 //halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0xa, 0xa, 0x60, 0x90);\r
1579                                 halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1c, 0x3, 0x70, 0x90);           \r
1580                                 break;\r
1581                         case 16:\r
1582                                 //halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x5, 0x5, 0x60, 0x90);\r
1583                                 halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x10, 0x3, 0x70, 0x90);           \r
1584                                 break;\r
1585                         case 17:\r
1586                                 halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xa3, 0x2f, 0x2f, 0x60, 0x90);\r
1587                                 break;\r
1588                         case 18:\r
1589                                 halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x5, 0x5, 0xe1, 0x90);\r
1590                                 break;                  \r
1591                         case 19:\r
1592                                 halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x25, 0xe1, 0x90);\r
1593                                 break;\r
1594                         case 20:\r
1595                                 halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x25, 0x60, 0x90);\r
1596                                 break;\r
1597                         case 21:\r
1598                                 halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x15, 0x03, 0x70, 0x90);\r
1599                                 break;  \r
1600                         case 23:\r
1601                                 halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1c, 0x03, 0xf1, 0x10);\r
1602                                 break;\r
1603                         case 24:\r
1604                         case 124:\r
1605                                 halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xd3, 0x3c, 0x03, 0x70, 0x50);\r
1606                                 break;\r
1607                         case 71:\r
1608                                 //halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0xe1, 0x90);\r
1609 \r
1610                                 halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x3c, 0x03, 0xf1, 0x90);\r
1611                                 break;\r
1612                         case 101:\r
1613                         case 105:\r
1614                         case 171:       \r
1615                                 halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xd3, 0x3a, 0x03, 0x70, 0x50);\r
1616                                 break;\r
1617                         case 102:\r
1618                         case 106:\r
1619                         case 110:\r
1620                         case 114:       \r
1621                                 halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xd3, 0x2d, 0x03, 0x70, 0x50);\r
1622                                 break;  \r
1623                         case 103:\r
1624                         case 107:\r
1625                         case 111:\r
1626                         case 115:       \r
1627                                 halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xd3, 0x1c, 0x03, 0x70, 0x50);\r
1628                                 break;          \r
1629                         case 104:\r
1630                         case 108:\r
1631                         case 112:\r
1632                         case 116:       \r
1633                                 halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xd3, 0x10, 0x03, 0x70, 0x50);\r
1634                                 break;  \r
1635                         case 109:\r
1636                                 halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x3c, 0x03, 0xf1, 0x90);\r
1637                                 break;\r
1638                         case 113:       \r
1639                                 halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x3c, 0x03, 0x70, 0x90);\r
1640                                 break;\r
1641                         case 121:       \r
1642                                 halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x15, 0x03, 0x70, 0x90);\r
1643                                 break;  \r
1644                         case 22:\r
1645                         case 122:\r
1646                                 halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x35, 0x03, 0x71, 0x11);\r
1647                                 break;\r
1648                         case 123:\r
1649                                 halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0xd3, 0x1c, 0x03, 0x70, 0x50);\r
1650                                 break;\r
1651                 }\r
1652         }\r
1653         else\r
1654         {\r
1655                 // disable PS tdma\r
1656                 switch(type)\r
1657                 {\r
1658                         case 0:\r
1659                                 halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x40, 0x0);\r
1660                                 break;\r
1661                         case 1:\r
1662                                 halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x48, 0x0);\r
1663                                 break;\r
1664                         default:\r
1665                                 halbtc8821a2ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x40, 0x0);\r
1666                                 break;\r
1667                 }\r
1668         }\r
1669 \r
1670         // update pre state\r
1671         pCoexDm->bPrePsTdmaOn = pCoexDm->bCurPsTdmaOn;\r
1672         pCoexDm->prePsTdma = pCoexDm->curPsTdma;\r
1673 }\r
1674 \r
1675 VOID\r
1676 halbtc8821a2ant_PsTdmaCheckForPowerSaveState(\r
1677         IN      PBTC_COEXIST            pBtCoexist,\r
1678         IN      BOOLEAN                 bNewPsState\r
1679         )\r
1680 {\r
1681         u1Byte  lpsMode=0x0;\r
1682 \r
1683         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_LPS_MODE, &lpsMode);\r
1684         \r
1685         if(lpsMode)     // already under LPS state\r
1686         {\r
1687                 if(bNewPsState)         \r
1688                 {\r
1689                         // keep state under LPS, do nothing.\r
1690                 }\r
1691                 else\r
1692                 {\r
1693                         // will leave LPS state, turn off psTdma first\r
1694                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 1);\r
1695                 }\r
1696         }\r
1697         else                                            // NO PS state\r
1698         {\r
1699                 if(bNewPsState)\r
1700                 {\r
1701                         // will enter LPS state, turn off psTdma first\r
1702                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 1);\r
1703                 }\r
1704                 else\r
1705                 {\r
1706                         // keep state under NO PS state, do nothing.\r
1707                 }\r
1708         }\r
1709 }\r
1710 \r
1711 VOID\r
1712 halbtc8821a2ant_PowerSaveState(\r
1713         IN      PBTC_COEXIST            pBtCoexist,\r
1714         IN      u1Byte                          psType,\r
1715         IN      u1Byte                          lpsVal,\r
1716         IN      u1Byte                          rpwmVal\r
1717         )\r
1718 {\r
1719         BOOLEAN         bLowPwrDisable=FALSE;\r
1720         \r
1721         switch(psType)\r
1722         {\r
1723                 case BTC_PS_WIFI_NATIVE:\r
1724                         // recover to original 32k low power setting\r
1725                         bLowPwrDisable = FALSE;\r
1726                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);\r
1727                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_NORMAL_LPS, NULL);\r
1728                         pCoexSta->bForceLpsOn = FALSE;\r
1729                         break;\r
1730                 case BTC_PS_LPS_ON:\r
1731                         halbtc8821a2ant_PsTdmaCheckForPowerSaveState(pBtCoexist, TRUE);\r
1732                         halbtc8821a2ant_LpsRpwm(pBtCoexist, NORMAL_EXEC, lpsVal, rpwmVal);                      \r
1733                         // when coex force to enter LPS, do not enter 32k low power.\r
1734                         bLowPwrDisable = TRUE;\r
1735                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);\r
1736                         // power save must executed before psTdma.                      \r
1737                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_ENTER_LPS, NULL);\r
1738                         pCoexSta->bForceLpsOn = TRUE;\r
1739                         break;\r
1740                 case BTC_PS_LPS_OFF:\r
1741                         halbtc8821a2ant_PsTdmaCheckForPowerSaveState(pBtCoexist, FALSE);\r
1742                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_LEAVE_LPS, NULL);\r
1743                         pCoexSta->bForceLpsOn = FALSE;\r
1744                         break;\r
1745                 default:\r
1746                         break;\r
1747         }\r
1748 }\r
1749 \r
1750 \r
1751 VOID\r
1752 halbtc8821a2ant_CoexAllOff(\r
1753         IN      PBTC_COEXIST            pBtCoexist\r
1754         )\r
1755 {\r
1756         // fw all off\r
1757         halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);               \r
1758         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 1);\r
1759         halbtc8821a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
1760         halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
1761 \r
1762         // sw all off\r
1763         halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
1764         halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
1765 \r
1766         // hw all off\r
1767         //pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);\r
1768         halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
1769 }\r
1770 \r
1771 VOID\r
1772 halbtc8821a2ant_CoexUnder5G(\r
1773         IN      PBTC_COEXIST            pBtCoexist\r
1774         )\r
1775 {\r
1776         halbtc8821a2ant_CoexAllOff(pBtCoexist);\r
1777 \r
1778         halbtc8821a2ant_IgnoreWlanAct(pBtCoexist, NORMAL_EXEC, TRUE);\r
1779 }\r
1780 \r
1781 VOID\r
1782 halbtc8821a2ant_InitCoexDm(\r
1783         IN      PBTC_COEXIST            pBtCoexist\r
1784         )\r
1785 {       \r
1786         // force to reset coex mechanism\r
1787         halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
1788         \r
1789         halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);               \r
1790         halbtc8821a2ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 1);\r
1791         halbtc8821a2ant_FwDacSwingLvl(pBtCoexist, FORCE_EXEC, 6);\r
1792         halbtc8821a2ant_DecBtPwr(pBtCoexist, FORCE_EXEC, 0);\r
1793 \r
1794         halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
1795         halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
1796 }\r
1797 \r
1798 VOID\r
1799 halbtc8821a2ant_ActionBtInquiry(\r
1800         IN      PBTC_COEXIST            pBtCoexist\r
1801         )\r
1802 {\r
1803         u1Byte          wifiRssiState, wifiRssiState1, btRssiState;\r
1804         BOOLEAN bWifiConnected=FALSE;\r
1805         BOOLEAN bLowPwrDisable=TRUE;\r
1806         BOOLEAN         bScan=FALSE, bLink=FALSE, bRoam=FALSE;\r
1807 \r
1808 \r
1809         wifiRssiState = halbtc8821a2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
1810         wifiRssiState1 = halbtc8821a2ant_WifiRssiState(pBtCoexist, 1, 2, BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);\r
1811         btRssiState = halbtc8821a2ant_BtRssiState(2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);\r
1812         \r
1813         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);\r
1814         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
1815 \r
1816         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);\r
1817         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);\r
1818         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);\r
1819                 \r
1820         \r
1821         halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);               \r
1822 \r
1823         if(bScan || bLink || bRoam)\r
1824         {\r
1825                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi link process + BT Inq/Page!!\n"));\r
1826                 halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 15);         \r
1827                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 22);\r
1828         }\r
1829         else if(bWifiConnected)\r
1830         {\r
1831                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi connected + BT Inq/Page!!\n"));\r
1832                 halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 15);         \r
1833                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 22);\r
1834         }\r
1835         else\r
1836         {\r
1837                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi no-link + BT Inq/Page!!\n"));\r
1838                 halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
1839                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 1);\r
1840         }       \r
1841         \r
1842         halbtc8821a2ant_FwDacSwingLvl(pBtCoexist, FORCE_EXEC, 6);\r
1843         halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
1844 \r
1845         halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
1846         halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
1847         \r
1848 }\r
1849 \r
1850 \r
1851 VOID\r
1852 halbtc8821a2ant_ActionWiFiLinkProcess(\r
1853         IN      PBTC_COEXIST            pBtCoexist\r
1854         )\r
1855 {\r
1856         u1Byte  u1Tmpa, u1Tmpb;\r
1857         \r
1858         halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 15);         \r
1859         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 22);\r
1860 \r
1861         halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
1862         halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
1863 \r
1864 \r
1865 \r
1866         u1Tmpa = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x765);\r
1867         u1Tmpb = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x76e);\r
1868 \r
1869         RT_TRACE(COMP_COEX, DBG_LOUD, ("############# [BTCoex], 0x765=0x%x, 0x76e=0x%x\n", u1Tmpa, u1Tmpb));\r
1870 }\r
1871 \r
1872 BOOLEAN\r
1873 halbtc8821a2ant_ActionWifiIdleProcess(\r
1874         IN      PBTC_COEXIST            pBtCoexist\r
1875         )\r
1876 {       \r
1877         u1Byte          wifiRssiState, wifiRssiState1, btRssiState;\r
1878         u4Byte          wifiBw;\r
1879         u1Byte          apNum=0;\r
1880 \r
1881         wifiRssiState = halbtc8821a2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
1882         //wifiRssiState1 = halbtc8821a2ant_WifiRssiState(pBtCoexist, 1, 2, BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);\r
1883         wifiRssiState1 = halbtc8821a2ant_WifiRssiState(pBtCoexist, 1, 2, BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES-20, 0);\r
1884         btRssiState = halbtc8821a2ant_BtRssiState(2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);\r
1885 \r
1886         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_AP_NUM, &apNum);\r
1887 \r
1888         // define the office environment\r
1889         if(BTC_RSSI_HIGH(wifiRssiState1) && \r
1890                         (pCoexSta->bHidExist == TRUE) && (pCoexSta->bA2dpExist == TRUE))\r
1891         {\r
1892 \r
1893                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi  idle process for BT HID+A2DP exist!!\n"));\r
1894                 \r
1895                 halbtc8821a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, TRUE, 0x6);\r
1896                 halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
1897 \r
1898                 // sw all off\r
1899                 halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
1900                 halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
1901 \r
1902                 halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
1903 \r
1904                 halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);               \r
1905                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 1);\r
1906 \r
1907                 return TRUE;\r
1908         }\r
1909         else\r
1910         {\r
1911                 halbtc8821a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, TRUE, 0x18);\r
1912                 return FALSE;   \r
1913         }\r
1914         \r
1915         \r
1916 }\r
1917 \r
1918 \r
1919 \r
1920 BOOLEAN\r
1921 halbtc8821a2ant_IsCommonAction(\r
1922         IN      PBTC_COEXIST            pBtCoexist\r
1923         )\r
1924 {\r
1925         u1Byte                  btRssiState=BTC_RSSI_STATE_HIGH;\r
1926         BOOLEAN                 bCommon=FALSE, bWifiConnected=FALSE, bWifiBusy=FALSE;\r
1927         BOOLEAN                 bBtHsOn=FALSE, bLowPwrDisable=FALSE;\r
1928 \r
1929         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
1930         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
1931         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);\r
1932 \r
1933         if(!bWifiConnected)\r
1934         {\r
1935                 bLowPwrDisable = FALSE;\r
1936                 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);\r
1937                 halbtc8821a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
1938                 \r
1939                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi non-connected idle!!\n"));\r
1940 \r
1941                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);\r
1942                 halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
1943                 \r
1944                 halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);                       \r
1945                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 1);\r
1946                 halbtc8821a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
1947                 halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
1948                 \r
1949                 halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
1950                 halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
1951 \r
1952                 bCommon = TRUE;\r
1953         }\r
1954         else\r
1955         {\r
1956                 if(BT_8821A_2ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus)\r
1957                 {\r
1958                         bLowPwrDisable = FALSE;\r
1959                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);\r
1960                         halbtc8821a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
1961                         \r
1962                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi connected + BT non connected-idle!!\n"));\r
1963 \r
1964                         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);\r
1965                         halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
1966 \r
1967                         halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);                       \r
1968                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 1);              \r
1969                         halbtc8821a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 0xb);\r
1970                         halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
1971 \r
1972                 halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
1973                         halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
1974 \r
1975                         bCommon = TRUE;\r
1976                 }\r
1977                 else if(BT_8821A_2ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus)\r
1978                 {\r
1979                         bLowPwrDisable = TRUE;\r
1980                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);\r
1981 \r
1982                         if(bBtHsOn)\r
1983                                 return FALSE;\r
1984                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi connected + BT connected-idle!!\n"));\r
1985                         halbtc8821a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
1986                         \r
1987                         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);\r
1988                         halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
1989 \r
1990                         halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);                       \r
1991                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 1);\r
1992                         halbtc8821a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 0xb);\r
1993                         halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
1994 \r
1995                         halbtc8821a2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
1996                         halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
1997 \r
1998                         bCommon = TRUE;\r
1999                 }\r
2000                 else\r
2001                 {\r
2002                         bLowPwrDisable = TRUE;\r
2003                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);\r
2004 \r
2005                         if(bWifiBusy)\r
2006                         {\r
2007                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi Connected-Busy + BT Busy!!\n"));\r
2008                                 bCommon = FALSE;\r
2009                                 //bCommon = halbtc8821a2ant_ActionWifiIdleProcess(pBtCoexist);  \r
2010                         }\r
2011                         else\r
2012                         {\r
2013                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi Connected-Idle + BT Busy!!\n"));\r
2014                                 //bCommon = FALSE;      \r
2015                                 bCommon = halbtc8821a2ant_ActionWifiIdleProcess(pBtCoexist);                    \r
2016                         }\r
2017                 }       \r
2018         }\r
2019 \r
2020         return bCommon;\r
2021 }\r
2022 VOID\r
2023 halbtc8821a2ant_TdmaDurationAdjust(\r
2024         IN      PBTC_COEXIST            pBtCoexist,\r
2025         IN      BOOLEAN                 bScoHid,\r
2026         IN      BOOLEAN                 bTxPause,\r
2027         IN      u1Byte                  maxInterval\r
2028         )\r
2029 {\r
2030         static s4Byte           up,dn,m,n,WaitCount;\r
2031         s4Byte                  result;   //0: no change, +1: increase WiFi duration, -1: decrease WiFi duration\r
2032         u1Byte                  retryCount=0;\r
2033 \r
2034         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], TdmaDurationAdjust()\n"));\r
2035 \r
2036         if(!pCoexDm->bAutoTdmaAdjust)\r
2037         {\r
2038                 pCoexDm->bAutoTdmaAdjust = TRUE;\r
2039                 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], first run TdmaDurationAdjust()!!\n"));\r
2040                 {\r
2041                         if(bScoHid)\r
2042                         {\r
2043                                 if(bTxPause)\r
2044                                 {\r
2045                                         if(maxInterval == 1)\r
2046                                         {\r
2047                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 13);\r
2048                                                 pCoexDm->psTdmaDuAdjType = 13;  \r
2049                                         }\r
2050                                         else if(maxInterval == 2)\r
2051                                         {\r
2052                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2053                                                 pCoexDm->psTdmaDuAdjType = 14;  \r
2054                                         }\r
2055                                         else if(maxInterval == 3)\r
2056                                         {\r
2057                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2058                                                 pCoexDm->psTdmaDuAdjType = 15;  \r
2059                                         }\r
2060                                         else\r
2061                                         {\r
2062                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2063                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2064                                         }\r
2065                                 }\r
2066                                 else\r
2067                                 {\r
2068                                         if(maxInterval == 1)\r
2069                                         {\r
2070                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
2071                                                 pCoexDm->psTdmaDuAdjType = 9;   \r
2072                                         }\r
2073                                         else if(maxInterval == 2)\r
2074                                         {\r
2075                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2076                                                 pCoexDm->psTdmaDuAdjType = 10;  \r
2077                                         }\r
2078                                         else if(maxInterval == 3)\r
2079                                         {\r
2080                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2081                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2082                                         }\r
2083                                         else\r
2084                                         {\r
2085                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2086                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2087                                         }\r
2088                                 }\r
2089                         }\r
2090                         else\r
2091                         {\r
2092                                 if(bTxPause)\r
2093                                 {\r
2094                                         if(maxInterval == 1)\r
2095                                         {\r
2096                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);\r
2097                                                 pCoexDm->psTdmaDuAdjType = 5;   \r
2098                                         }\r
2099                                         else if(maxInterval == 2)\r
2100                                         {\r
2101                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2102                                                 pCoexDm->psTdmaDuAdjType = 6;   \r
2103                                         }\r
2104                                         else if(maxInterval == 3)\r
2105                                         {\r
2106                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2107                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2108                                         }\r
2109                                         else\r
2110                                         {\r
2111                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2112                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2113                                         }\r
2114                                 }\r
2115                                 else\r
2116                                 {\r
2117                                         if(maxInterval == 1)\r
2118                                         {\r
2119                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);\r
2120                                                 pCoexDm->psTdmaDuAdjType = 1;   \r
2121                                         }\r
2122                                         else if(maxInterval == 2)\r
2123                                         {\r
2124                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2125                                                 pCoexDm->psTdmaDuAdjType = 2;   \r
2126                                         }\r
2127                                         else if(maxInterval == 3)\r
2128                                         {\r
2129                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2130                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2131                                         }\r
2132                                         else\r
2133                                         {\r
2134                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2135                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2136                                         }\r
2137                                 }\r
2138                         }\r
2139                 }\r
2140                 //============\r
2141                 up = 0;\r
2142                 dn = 0;\r
2143                 m = 1;\r
2144                 n= 3;\r
2145                 result = 0;\r
2146                 WaitCount = 0;\r
2147         }\r
2148         else\r
2149         {\r
2150                 //accquire the BT TRx retry count from BT_Info byte2\r
2151                 retryCount = pCoexSta->btRetryCnt;\r
2152                 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], retryCount = %d\n", retryCount));\r
2153                 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], up=%d, dn=%d, m=%d, n=%d, WaitCount=%d\n", \r
2154                         up, dn, m, n, WaitCount));\r
2155                 result = 0;\r
2156                 WaitCount++; \r
2157                   \r
2158                 if(retryCount == 0)  // no retry in the last 2-second duration\r
2159                 {\r
2160                         up++;\r
2161                         dn--;\r
2162 \r
2163                         if (dn <= 0)\r
2164                                 dn = 0;                          \r
2165 \r
2166                         if(up >= n)     // if ³sÄò n ­Ó2¬í retry count¬°0, «h½Õ¼eWiFi duration\r
2167                         {\r
2168                                 WaitCount = 0; \r
2169                                 n = 3;\r
2170                                 up = 0;\r
2171                                 dn = 0;\r
2172                                 result = 1; \r
2173                                 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Increase wifi duration!!\n"));\r
2174                         }\r
2175                 }\r
2176                 else if (retryCount <= 3)       // <=3 retry in the last 2-second duration\r
2177                 {\r
2178                         up--; \r
2179                         dn++;\r
2180 \r
2181                         if (up <= 0)\r
2182                                 up = 0;\r
2183 \r
2184                         if (dn == 2)    // if ³sÄò 2 ­Ó2¬í retry count< 3, «h½Õ¯¶WiFi duration\r
2185                         {\r
2186                                 if (WaitCount <= 2)\r
2187                                         m++; // ÁקK¤@ª½¦b¨â­Ólevel¤¤¨Ó¦^\r
2188                                 else\r
2189                                         m = 1;\r
2190 \r
2191                                 if ( m >= 20) //m ³Ì¤j­È = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration.\r
2192                                         m = 20;\r
2193 \r
2194                                 n = 3*m;\r
2195                                 up = 0;\r
2196                                 dn = 0;\r
2197                                 WaitCount = 0;\r
2198                                 result = -1; \r
2199                                 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Decrease wifi duration for retryCounter<3!!\n"));\r
2200                         }\r
2201                 }\r
2202                 else  //retry count > 3, ¥u­n1¦¸ retry count > 3, «h½Õ¯¶WiFi duration\r
2203                 {\r
2204                         if (WaitCount == 1)\r
2205                                 m++; // ÁקK¤@ª½¦b¨â­Ólevel¤¤¨Ó¦^\r
2206                         else\r
2207                                 m = 1;\r
2208 \r
2209                         if ( m >= 20) //m ³Ì¤j­È = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration.\r
2210                                 m = 20;\r
2211 \r
2212                         n = 3*m;\r
2213                         up = 0;\r
2214                         dn = 0;\r
2215                         WaitCount = 0; \r
2216                         result = -1;\r
2217                         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Decrease wifi duration for retryCounter>3!!\n"));\r
2218                 }\r
2219 \r
2220                 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], max Interval = %d\n", maxInterval));\r
2221                 if(maxInterval == 1)\r
2222                 {\r
2223                         if(bTxPause)\r
2224                         {\r
2225                                 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], TxPause = 1\n"));\r
2226 \r
2227                                 if(pCoexDm->curPsTdma == 71)\r
2228                                 {\r
2229                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);\r
2230                                         pCoexDm->psTdmaDuAdjType = 5;\r
2231                                 }\r
2232                                 else if(pCoexDm->curPsTdma == 1)\r
2233                                 {\r
2234                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);\r
2235                                         pCoexDm->psTdmaDuAdjType = 5;\r
2236                                 }\r
2237                                 else if(pCoexDm->curPsTdma == 2)\r
2238                                 {\r
2239                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2240                                         pCoexDm->psTdmaDuAdjType = 6;\r
2241                                 }\r
2242                                 else if(pCoexDm->curPsTdma == 3)\r
2243                                 {\r
2244                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2245                                         pCoexDm->psTdmaDuAdjType = 7;\r
2246                                 }\r
2247                                 else if(pCoexDm->curPsTdma == 4)\r
2248                                 {\r
2249                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);\r
2250                                         pCoexDm->psTdmaDuAdjType = 8;\r
2251                                 }\r
2252                                 if(pCoexDm->curPsTdma == 9)\r
2253                                 {\r
2254                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 13);\r
2255                                         pCoexDm->psTdmaDuAdjType = 13;\r
2256                                 }\r
2257                                 else if(pCoexDm->curPsTdma == 10)\r
2258                                 {\r
2259                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2260                                         pCoexDm->psTdmaDuAdjType = 14;\r
2261                                 }\r
2262                                 else if(pCoexDm->curPsTdma == 11)\r
2263                                 {\r
2264                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2265                                         pCoexDm->psTdmaDuAdjType = 15;\r
2266                                 }\r
2267                                 else if(pCoexDm->curPsTdma == 12)\r
2268                                 {\r
2269                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);\r
2270                                         pCoexDm->psTdmaDuAdjType = 16;\r
2271                                 }\r
2272                                 \r
2273                                 if(result == -1)\r
2274                                 {                                       \r
2275                                         if(pCoexDm->curPsTdma == 5)\r
2276                                         {\r
2277                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2278                                                 pCoexDm->psTdmaDuAdjType = 6;\r
2279                                         }\r
2280                                         else if(pCoexDm->curPsTdma == 6)\r
2281                                         {\r
2282                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2283                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2284                                         }\r
2285                                         else if(pCoexDm->curPsTdma == 7)\r
2286                                         {\r
2287                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);\r
2288                                                 pCoexDm->psTdmaDuAdjType = 8;\r
2289                                         }\r
2290                                         else if(pCoexDm->curPsTdma == 13)\r
2291                                         {\r
2292                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2293                                                 pCoexDm->psTdmaDuAdjType = 14;\r
2294                                         }\r
2295                                         else if(pCoexDm->curPsTdma == 14)\r
2296                                         {\r
2297                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2298                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2299                                         }\r
2300                                         else if(pCoexDm->curPsTdma == 15)\r
2301                                         {\r
2302                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);\r
2303                                                 pCoexDm->psTdmaDuAdjType = 16;\r
2304                                         }\r
2305                                 } \r
2306                                 else if (result == 1)\r
2307                                 {\r
2308                                         if(pCoexDm->curPsTdma == 8)\r
2309                                         {\r
2310                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2311                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2312                                         }\r
2313                                         else if(pCoexDm->curPsTdma == 7)\r
2314                                         {\r
2315                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2316                                                 pCoexDm->psTdmaDuAdjType = 6;\r
2317                                         }\r
2318                                         else if(pCoexDm->curPsTdma == 6)\r
2319                                         {\r
2320                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);\r
2321                                                 pCoexDm->psTdmaDuAdjType = 5;\r
2322                                         }\r
2323                                         else if(pCoexDm->curPsTdma == 16)\r
2324                                         {\r
2325                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2326                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2327                                         }\r
2328                                         else if(pCoexDm->curPsTdma == 15)\r
2329                                         {\r
2330                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2331                                                 pCoexDm->psTdmaDuAdjType = 14;\r
2332                                         }\r
2333                                         else if(pCoexDm->curPsTdma == 14)\r
2334                                         {\r
2335                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 13);\r
2336                                                 pCoexDm->psTdmaDuAdjType = 13;\r
2337                                         }\r
2338                                 }\r
2339                         }\r
2340                         else\r
2341                         {\r
2342                                 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], TxPause = 0\n"));\r
2343                                 if(pCoexDm->curPsTdma == 5)\r
2344                                 {\r
2345                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 71);\r
2346                                         pCoexDm->psTdmaDuAdjType = 71;\r
2347                                 }\r
2348                                 else if(pCoexDm->curPsTdma == 6)\r
2349                                 {\r
2350                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2351                                         pCoexDm->psTdmaDuAdjType = 2;\r
2352                                 }\r
2353                                 else if(pCoexDm->curPsTdma == 7)\r
2354                                 {\r
2355                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2356                                         pCoexDm->psTdmaDuAdjType = 3;\r
2357                                 }\r
2358                                 else if(pCoexDm->curPsTdma == 8)\r
2359                                 {\r
2360                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);\r
2361                                         pCoexDm->psTdmaDuAdjType = 4;\r
2362                                 }\r
2363                                 if(pCoexDm->curPsTdma == 13)\r
2364                                 {\r
2365                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
2366                                         pCoexDm->psTdmaDuAdjType = 9;\r
2367                                 }\r
2368                                 else if(pCoexDm->curPsTdma == 14)\r
2369                                 {\r
2370                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2371                                         pCoexDm->psTdmaDuAdjType = 10;\r
2372                                 }\r
2373                                 else if(pCoexDm->curPsTdma == 15)\r
2374                                 {\r
2375                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2376                                         pCoexDm->psTdmaDuAdjType = 11;\r
2377                                 }\r
2378                                 else if(pCoexDm->curPsTdma == 16)\r
2379                                 {\r
2380                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);\r
2381                                         pCoexDm->psTdmaDuAdjType = 12;\r
2382                                 }\r
2383                                 \r
2384                                 if(result == -1)\r
2385                                 {\r
2386                                         if(pCoexDm->curPsTdma == 71)\r
2387                                         {\r
2388                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);\r
2389                                                 pCoexDm->psTdmaDuAdjType = 1;\r
2390                                         }\r
2391                                         else if(pCoexDm->curPsTdma == 1)\r
2392                                         {\r
2393                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2394                                                 pCoexDm->psTdmaDuAdjType = 2;\r
2395                                         }\r
2396                                         else if(pCoexDm->curPsTdma == 2)\r
2397                                         {\r
2398                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2399                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2400                                         }\r
2401                                         else if(pCoexDm->curPsTdma == 3)\r
2402                                         {\r
2403                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);\r
2404                                                 pCoexDm->psTdmaDuAdjType = 4;\r
2405                                         }\r
2406                                         else if(pCoexDm->curPsTdma == 9)\r
2407                                         {\r
2408                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2409                                                 pCoexDm->psTdmaDuAdjType = 10;\r
2410                                         }\r
2411                                         else if(pCoexDm->curPsTdma == 10)\r
2412                                         {\r
2413                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2414                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2415                                         }\r
2416                                         else if(pCoexDm->curPsTdma == 11)\r
2417                                         {\r
2418                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);\r
2419                                                 pCoexDm->psTdmaDuAdjType = 12;\r
2420                                         }\r
2421                                 } \r
2422                                 else if (result == 1)\r
2423                                 {\r
2424                                         if(pCoexDm->curPsTdma == 4)\r
2425                                         {\r
2426                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2427                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2428                                         }\r
2429                                         else if(pCoexDm->curPsTdma == 3)\r
2430                                         {\r
2431                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2432                                                 pCoexDm->psTdmaDuAdjType = 2;\r
2433                                         }\r
2434                                         else if(pCoexDm->curPsTdma == 2)\r
2435                                         {\r
2436                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);\r
2437                                                 pCoexDm->psTdmaDuAdjType = 1;\r
2438                                         }\r
2439                                         else if(pCoexDm->curPsTdma == 1)\r
2440                                         {\r
2441                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 71);\r
2442                                                 pCoexDm->psTdmaDuAdjType = 71;\r
2443                                         }\r
2444                                         else if(pCoexDm->curPsTdma == 12)\r
2445                                         {\r
2446                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2447                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2448                                         }\r
2449                                         else if(pCoexDm->curPsTdma == 11)\r
2450                                         {\r
2451                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2452                                                 pCoexDm->psTdmaDuAdjType = 10;\r
2453                                         }\r
2454                                         else if(pCoexDm->curPsTdma == 10)\r
2455                                         {\r
2456                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
2457                                                 pCoexDm->psTdmaDuAdjType = 9;\r
2458                                         }\r
2459                                 }\r
2460                         }\r
2461                 }\r
2462                 else if(maxInterval == 2)\r
2463                 {\r
2464                         if(bTxPause)\r
2465                         {\r
2466                                 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], TxPause = 1\n"));\r
2467                                 if(pCoexDm->curPsTdma == 1)\r
2468                                 {\r
2469                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2470                                         pCoexDm->psTdmaDuAdjType = 6;\r
2471                                 }\r
2472                                 else if(pCoexDm->curPsTdma == 2)\r
2473                                 {\r
2474                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2475                                         pCoexDm->psTdmaDuAdjType = 6;\r
2476                                 }\r
2477                                 else if(pCoexDm->curPsTdma == 3)\r
2478                                 {\r
2479                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2480                                         pCoexDm->psTdmaDuAdjType = 7;\r
2481                                 }\r
2482                                 else if(pCoexDm->curPsTdma == 4)\r
2483                                 {\r
2484                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);\r
2485                                         pCoexDm->psTdmaDuAdjType = 8;\r
2486                                 }\r
2487                                 if(pCoexDm->curPsTdma == 9)\r
2488                                 {\r
2489                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2490                                         pCoexDm->psTdmaDuAdjType = 14;\r
2491                                 }\r
2492                                 else if(pCoexDm->curPsTdma == 10)\r
2493                                 {\r
2494                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2495                                         pCoexDm->psTdmaDuAdjType = 14;\r
2496                                 }\r
2497                                 else if(pCoexDm->curPsTdma == 11)\r
2498                                 {\r
2499                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2500                                         pCoexDm->psTdmaDuAdjType = 15;\r
2501                                 }\r
2502                                 else if(pCoexDm->curPsTdma == 12)\r
2503                                 {\r
2504                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);\r
2505                                         pCoexDm->psTdmaDuAdjType = 16;\r
2506                                 }\r
2507                                 if(result == -1)\r
2508                                 {\r
2509                                         if(pCoexDm->curPsTdma == 5) \r
2510                                         {\r
2511                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2512                                                 pCoexDm->psTdmaDuAdjType = 6;\r
2513                                         }\r
2514                                         else if(pCoexDm->curPsTdma == 6)\r
2515                                         {\r
2516                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2517                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2518                                         }\r
2519                                         else if(pCoexDm->curPsTdma == 7)\r
2520                                         {\r
2521                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);\r
2522                                                 pCoexDm->psTdmaDuAdjType = 8;\r
2523                                         }\r
2524                                         else if(pCoexDm->curPsTdma == 13)\r
2525                                         {\r
2526                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2527                                                 pCoexDm->psTdmaDuAdjType = 14;\r
2528                                         }\r
2529                                         else if(pCoexDm->curPsTdma == 14)\r
2530                                         {\r
2531                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2532                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2533                                         }\r
2534                                         else if(pCoexDm->curPsTdma == 15)\r
2535                                         {\r
2536                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);\r
2537                                                 pCoexDm->psTdmaDuAdjType = 16;\r
2538                                         }\r
2539                                 } \r
2540                                 else if (result == 1)\r
2541                                 {\r
2542                                         if(pCoexDm->curPsTdma == 8)\r
2543                                         {\r
2544                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2545                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2546                                         }\r
2547                                         else if(pCoexDm->curPsTdma == 7)\r
2548                                         {\r
2549                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2550                                                 pCoexDm->psTdmaDuAdjType = 6;\r
2551                                         }\r
2552                                         else if(pCoexDm->curPsTdma == 6)\r
2553                                         {\r
2554                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2555                                                 pCoexDm->psTdmaDuAdjType = 6;\r
2556                                         }                                       \r
2557                                         else if(pCoexDm->curPsTdma == 16)\r
2558                                         {\r
2559                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2560                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2561                                         }\r
2562                                         else if(pCoexDm->curPsTdma == 15)\r
2563                                         {\r
2564                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2565                                                 pCoexDm->psTdmaDuAdjType = 14;\r
2566                                         }\r
2567                                         else if(pCoexDm->curPsTdma == 14)\r
2568                                         {\r
2569                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2570                                                 pCoexDm->psTdmaDuAdjType = 14;\r
2571                                         }\r
2572                                 }\r
2573                         }\r
2574                         else\r
2575                         {\r
2576                                 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], TxPause = 0\n"));\r
2577                                 if(pCoexDm->curPsTdma == 5)\r
2578                                 {\r
2579                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2580                                         pCoexDm->psTdmaDuAdjType = 2;\r
2581                                 }\r
2582                                 else if(pCoexDm->curPsTdma == 6)\r
2583                                 {\r
2584                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2585                                         pCoexDm->psTdmaDuAdjType = 2;\r
2586                                 }\r
2587                                 else if(pCoexDm->curPsTdma == 7)\r
2588                                 {\r
2589                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2590                                         pCoexDm->psTdmaDuAdjType = 3;\r
2591                                 }\r
2592                                 else if(pCoexDm->curPsTdma == 8)\r
2593                                 {\r
2594                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);\r
2595                                         pCoexDm->psTdmaDuAdjType = 4;\r
2596                                 }\r
2597                                 if(pCoexDm->curPsTdma == 13)\r
2598                                 {\r
2599                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2600                                         pCoexDm->psTdmaDuAdjType = 10;\r
2601                                 }\r
2602                                 else if(pCoexDm->curPsTdma == 14)\r
2603                                 {\r
2604                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2605                                         pCoexDm->psTdmaDuAdjType = 10;\r
2606                                 }\r
2607                                 else if(pCoexDm->curPsTdma == 15)\r
2608                                 {\r
2609                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2610                                         pCoexDm->psTdmaDuAdjType = 11;\r
2611                                 }\r
2612                                 else if(pCoexDm->curPsTdma == 16)\r
2613                                 {\r
2614                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);\r
2615                                         pCoexDm->psTdmaDuAdjType = 12;\r
2616                                 }\r
2617                                 if(result == -1)\r
2618                                 {\r
2619                                         if(pCoexDm->curPsTdma == 1)\r
2620                                         {\r
2621                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2622                                                 pCoexDm->psTdmaDuAdjType = 2;\r
2623                                         }\r
2624                                         else if(pCoexDm->curPsTdma == 2)\r
2625                                         {\r
2626                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2627                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2628                                         }\r
2629                                         else if(pCoexDm->curPsTdma == 3)\r
2630                                         {\r
2631                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);\r
2632                                                 pCoexDm->psTdmaDuAdjType = 4;\r
2633                                         }\r
2634                                         else if(pCoexDm->curPsTdma == 9)\r
2635                                         {\r
2636                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2637                                                 pCoexDm->psTdmaDuAdjType = 10;\r
2638                                         }\r
2639                                         else if(pCoexDm->curPsTdma == 10)\r
2640                                         {\r
2641                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2642                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2643                                         }\r
2644                                         else if(pCoexDm->curPsTdma == 11)\r
2645                                         {\r
2646                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);\r
2647                                                 pCoexDm->psTdmaDuAdjType = 12;\r
2648                                         }\r
2649                                 } \r
2650                                 else if (result == 1)\r
2651                                 {\r
2652                                         if(pCoexDm->curPsTdma == 4)\r
2653                                         {\r
2654                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2655                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2656                                         }\r
2657                                         else if(pCoexDm->curPsTdma == 3)\r
2658                                         {\r
2659                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2660                                                 pCoexDm->psTdmaDuAdjType = 2;\r
2661                                         }\r
2662                                         else if(pCoexDm->curPsTdma == 2)\r
2663                                         {\r
2664                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2665                                                 pCoexDm->psTdmaDuAdjType = 2;\r
2666                                         }\r
2667                                         else if(pCoexDm->curPsTdma == 12)\r
2668                                         {\r
2669                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2670                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2671                                         }\r
2672                                         else if(pCoexDm->curPsTdma == 11)\r
2673                                         {\r
2674                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2675                                                 pCoexDm->psTdmaDuAdjType = 10;\r
2676                                         }\r
2677                                         else if(pCoexDm->curPsTdma == 10)\r
2678                                         {\r
2679                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2680                                                 pCoexDm->psTdmaDuAdjType = 10;\r
2681                                         }\r
2682                                 }\r
2683                         }\r
2684                 }\r
2685                 else if(maxInterval == 3)\r
2686                 {\r
2687                         if(bTxPause)\r
2688                         {\r
2689                                 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], TxPause = 1\n"));\r
2690                                 if(pCoexDm->curPsTdma == 1)\r
2691                                 {\r
2692                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2693                                         pCoexDm->psTdmaDuAdjType = 7;\r
2694                                 }\r
2695                                 else if(pCoexDm->curPsTdma == 2)\r
2696                                 {\r
2697                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2698                                         pCoexDm->psTdmaDuAdjType = 7;\r
2699                                 }\r
2700                                 else if(pCoexDm->curPsTdma == 3)\r
2701                                 {\r
2702                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2703                                         pCoexDm->psTdmaDuAdjType = 7;\r
2704                                 }\r
2705                                 else if(pCoexDm->curPsTdma == 4)\r
2706                                 {\r
2707                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);\r
2708                                         pCoexDm->psTdmaDuAdjType = 8;\r
2709                                 }\r
2710                                 if(pCoexDm->curPsTdma == 9)\r
2711                                 {\r
2712                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2713                                         pCoexDm->psTdmaDuAdjType = 15;\r
2714                                 }\r
2715                                 else if(pCoexDm->curPsTdma == 10)\r
2716                                 {\r
2717                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2718                                         pCoexDm->psTdmaDuAdjType = 15;\r
2719                                 }\r
2720                                 else if(pCoexDm->curPsTdma == 11)\r
2721                                 {\r
2722                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2723                                         pCoexDm->psTdmaDuAdjType = 15;\r
2724                                 }\r
2725                                 else if(pCoexDm->curPsTdma == 12)\r
2726                                 {\r
2727                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);\r
2728                                         pCoexDm->psTdmaDuAdjType = 16;\r
2729                                 }\r
2730                                 if(result == -1)\r
2731                                 {\r
2732                                         if(pCoexDm->curPsTdma == 5) \r
2733                                         {\r
2734                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2735                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2736                                         }\r
2737                                         else if(pCoexDm->curPsTdma == 6)\r
2738                                         {\r
2739                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2740                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2741                                         }\r
2742                                         else if(pCoexDm->curPsTdma == 7)\r
2743                                         {\r
2744                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);\r
2745                                                 pCoexDm->psTdmaDuAdjType = 8;\r
2746                                         }\r
2747                                         else if(pCoexDm->curPsTdma == 13)\r
2748                                         {\r
2749                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2750                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2751                                         }\r
2752                                         else if(pCoexDm->curPsTdma == 14)\r
2753                                         {\r
2754                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2755                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2756                                         }\r
2757                                         else if(pCoexDm->curPsTdma == 15)\r
2758                                         {\r
2759                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);\r
2760                                                 pCoexDm->psTdmaDuAdjType = 16;\r
2761                                         }\r
2762                                 } \r
2763                                 else if (result == 1)\r
2764                                 {\r
2765                                         if(pCoexDm->curPsTdma == 8)\r
2766                                         {\r
2767                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2768                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2769                                         }\r
2770                                         else if(pCoexDm->curPsTdma == 7)\r
2771                                         {\r
2772                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2773                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2774                                         }\r
2775                                         else if(pCoexDm->curPsTdma == 6)\r
2776                                         {\r
2777                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2778                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2779                                         }                                       \r
2780                                         else if(pCoexDm->curPsTdma == 16)\r
2781                                         {\r
2782                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2783                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2784                                         }\r
2785                                         else if(pCoexDm->curPsTdma == 15)\r
2786                                         {\r
2787                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2788                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2789                                         }\r
2790                                         else if(pCoexDm->curPsTdma == 14)\r
2791                                         {\r
2792                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2793                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2794                                         }\r
2795                                 }\r
2796                         }\r
2797                         else\r
2798                         {\r
2799                                 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], TxPause = 0\n"));\r
2800                                 if(pCoexDm->curPsTdma == 5)\r
2801                                 {\r
2802                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2803                                         pCoexDm->psTdmaDuAdjType = 3;\r
2804                                 }\r
2805                                 else if(pCoexDm->curPsTdma == 6)\r
2806                                 {\r
2807                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2808                                         pCoexDm->psTdmaDuAdjType = 3;\r
2809                                 }\r
2810                                 else if(pCoexDm->curPsTdma == 7)\r
2811                                 {\r
2812                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2813                                         pCoexDm->psTdmaDuAdjType = 3;\r
2814                                 }\r
2815                                 else if(pCoexDm->curPsTdma == 8)\r
2816                                 {\r
2817                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);\r
2818                                         pCoexDm->psTdmaDuAdjType = 4;\r
2819                                 }\r
2820                                 if(pCoexDm->curPsTdma == 13)\r
2821                                 {\r
2822                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2823                                         pCoexDm->psTdmaDuAdjType = 11;\r
2824                                 }\r
2825                                 else if(pCoexDm->curPsTdma == 14)\r
2826                                 {\r
2827                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2828                                         pCoexDm->psTdmaDuAdjType = 11;\r
2829                                 }\r
2830                                 else if(pCoexDm->curPsTdma == 15)\r
2831                                 {\r
2832                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2833                                         pCoexDm->psTdmaDuAdjType = 11;\r
2834                                 }\r
2835                                 else if(pCoexDm->curPsTdma == 16)\r
2836                                 {\r
2837                                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);\r
2838                                         pCoexDm->psTdmaDuAdjType = 12;\r
2839                                 }\r
2840                                 if(result == -1)\r
2841                                 {\r
2842                                         if(pCoexDm->curPsTdma == 1)\r
2843                                         {\r
2844                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2845                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2846                                         }\r
2847                                         else if(pCoexDm->curPsTdma == 2)\r
2848                                         {\r
2849                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2850                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2851                                         }\r
2852                                         else if(pCoexDm->curPsTdma == 3)\r
2853                                         {\r
2854                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);\r
2855                                                 pCoexDm->psTdmaDuAdjType = 4;\r
2856                                         }\r
2857                                         else if(pCoexDm->curPsTdma == 9)\r
2858                                         {\r
2859                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2860                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2861                                         }\r
2862                                         else if(pCoexDm->curPsTdma == 10)\r
2863                                         {\r
2864                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2865                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2866                                         }\r
2867                                         else if(pCoexDm->curPsTdma == 11)\r
2868                                         {\r
2869                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);\r
2870                                                 pCoexDm->psTdmaDuAdjType = 12;\r
2871                                         }\r
2872                                 } \r
2873                                 else if (result == 1)\r
2874                                 {\r
2875                                         if(pCoexDm->curPsTdma == 4)\r
2876                                         {\r
2877                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2878                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2879                                         }\r
2880                                         else if(pCoexDm->curPsTdma == 3)\r
2881                                         {\r
2882                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2883                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2884                                         }\r
2885                                         else if(pCoexDm->curPsTdma == 2)\r
2886                                         {\r
2887                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2888                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2889                                         }\r
2890                                         else if(pCoexDm->curPsTdma == 12)\r
2891                                         {\r
2892                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2893                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2894                                         }\r
2895                                         else if(pCoexDm->curPsTdma == 11)\r
2896                                         {\r
2897                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2898                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2899                                         }\r
2900                                         else if(pCoexDm->curPsTdma == 10)\r
2901                                         {\r
2902                                                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2903                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2904                                         }\r
2905                                 }\r
2906                         }\r
2907                 }\r
2908         }\r
2909 \r
2910         // if current PsTdma not match with the recorded one (when scan, dhcp...), \r
2911         // then we have to adjust it back to the previous record one.\r
2912         if(pCoexDm->curPsTdma != pCoexDm->psTdmaDuAdjType)\r
2913         {\r
2914                 BOOLEAN bScan=FALSE, bLink=FALSE, bRoam=FALSE;\r
2915                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], PsTdma type dismatch!!!, curPsTdma=%d, recordPsTdma=%d\n", \r
2916                         pCoexDm->curPsTdma, pCoexDm->psTdmaDuAdjType));\r
2917 \r
2918                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);\r
2919                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);\r
2920                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);\r
2921                 \r
2922                 if( !bScan && !bLink && !bRoam)\r
2923                 {\r
2924                         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, pCoexDm->psTdmaDuAdjType);\r
2925                 }\r
2926                 else\r
2927                 {\r
2928                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], roaming/link/scan is under progress, will adjust next time!!!\n"));\r
2929                 }\r
2930         }\r
2931 }\r
2932 \r
2933 // SCO only or SCO+PAN(HS)\r
2934 VOID\r
2935 halbtc8821a2ant_ActionSco(\r
2936         IN      PBTC_COEXIST            pBtCoexist\r
2937         )\r
2938 {\r
2939         PBTC_BT_LINK_INFO       pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
2940         u1Byte  wifiRssiState, btRssiState;\r
2941         u4Byte  wifiBw;\r
2942 \r
2943         wifiRssiState = halbtc8821a2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
2944         btRssiState = halbtc8821a2ant_BtRssiState(2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);\r
2945 \r
2946         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);\r
2947 \r
2948         halbtc8821a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
2949         \r
2950         halbtc8821a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 4);\r
2951 \r
2952         if(BTC_RSSI_HIGH(btRssiState))\r
2953                 halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
2954         else    \r
2955                 halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
2956         \r
2957         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
2958 \r
2959         if (BTC_WIFI_BW_LEGACY == wifiBw) //for SCO quality at 11b/g mode\r
2960         {\r
2961                 halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
2962         }\r
2963         else  //for SCO quality & wifi performance balance at 11n mode\r
2964         {\r
2965                 if(BTC_WIFI_BW_HT40 == wifiBw)\r
2966                         halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 8);\r
2967                 else\r
2968                 {\r
2969                         if(pBtLinkInfo->bScoOnly)\r
2970                                 halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 17);\r
2971                         else\r
2972                                 halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 12);\r
2973                 }\r
2974         }\r
2975 \r
2976         halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);                       \r
2977         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0); //for voice quality\r
2978 \r
2979         // sw mechanism\r
2980         if(BTC_WIFI_BW_HT40 == wifiBw)\r
2981         {\r
2982                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
2983                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2984                 {\r
2985                         halbtc8821a2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);\r
2986                         halbtc8821a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,TRUE,0x18);                  \r
2987                 }\r
2988                 else\r
2989                 {\r
2990                         halbtc8821a2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);\r
2991                         halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,TRUE,0x18); \r
2992                 }               \r
2993         }\r
2994         else\r
2995         {\r
2996                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
2997                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2998                 {\r
2999                         halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);\r
3000                         halbtc8821a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,TRUE,0x18);\r
3001                 }\r
3002                 else\r
3003                 {\r
3004                         halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);\r
3005                         halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,TRUE,0x18);\r
3006                 }               \r
3007         }\r
3008 }\r
3009 \r
3010 \r
3011 VOID\r
3012 halbtc8821a2ant_ActionHid(\r
3013         IN      PBTC_COEXIST            pBtCoexist\r
3014         )\r
3015 {\r
3016         u1Byte  wifiRssiState, btRssiState;     \r
3017         u4Byte  wifiBw;\r
3018 \r
3019         wifiRssiState = halbtc8821a2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
3020         btRssiState = halbtc8821a2ant_BtRssiState(2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);\r
3021 \r
3022         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);\r
3023 \r
3024         halbtc8821a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
3025         \r
3026         halbtc8821a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
3027 \r
3028         if(BTC_RSSI_HIGH(btRssiState))\r
3029                 halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
3030         else    \r
3031                 halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
3032 \r
3033         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
3034 \r
3035         if (BTC_WIFI_BW_LEGACY == wifiBw) //for HID at 11b/g mode\r
3036         {\r
3037                 halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);\r
3038         }\r
3039         else  //for HID quality & wifi performance balance at 11n mode\r
3040         {\r
3041                 halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
3042         }\r
3043 \r
3044         halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);                       \r
3045 \r
3046         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 24);\r
3047 \r
3048         // sw mechanism\r
3049         if(BTC_WIFI_BW_HT40 == wifiBw)\r
3050         {\r
3051                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3052                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3053                 {\r
3054                         halbtc8821a2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);\r
3055                         halbtc8821a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3056                 }\r
3057                 else\r
3058                 {\r
3059                         halbtc8821a2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);\r
3060                         halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3061                 }       \r
3062         }\r
3063         else\r
3064         {\r
3065                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3066                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3067                 {\r
3068                         halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);\r
3069                         halbtc8821a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3070                 }\r
3071                 else\r
3072                 {\r
3073                         halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);\r
3074                         halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3075                 }               \r
3076         }\r
3077 }\r
3078 \r
3079 //A2DP only / PAN(EDR) only/ A2DP+PAN(HS)\r
3080 VOID\r
3081 halbtc8821a2ant_ActionA2dp(\r
3082         IN      PBTC_COEXIST            pBtCoexist\r
3083         )\r
3084 {\r
3085         u1Byte          wifiRssiState, wifiRssiState1, btRssiState;\r
3086         u4Byte          wifiBw;\r
3087         u1Byte          apNum=0;\r
3088 \r
3089         wifiRssiState = halbtc8821a2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
3090         wifiRssiState1 = halbtc8821a2ant_WifiRssiState(pBtCoexist, 1, 2, BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);\r
3091         btRssiState = halbtc8821a2ant_BtRssiState(2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);\r
3092 \r
3093         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_AP_NUM, &apNum);\r
3094 \r
3095         // define the office environment\r
3096         if( (apNum >= 10) && BTC_RSSI_HIGH(wifiRssiState1) && BTC_RSSI_HIGH(btRssiState))\r
3097         {\r
3098                 //DbgPrint(" AP#>10(%d)\n", apNum);\r
3099                 halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);                       \r
3100                 \r
3101                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);\r
3102                 halbtc8821a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
3103                 halbtc8821a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);      \r
3104                 halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);                   \r
3105                                         \r
3106                 halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
3107 \r
3108                 halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);               \r
3109                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 1);\r
3110 \r
3111                 // sw mechanism\r
3112                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
3113                 if(BTC_WIFI_BW_HT40 == wifiBw)\r
3114                 {\r
3115                         halbtc8821a2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
3116                         halbtc8821a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,TRUE,0x6);\r
3117                 }\r
3118                 else\r
3119                 {\r
3120                         halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3121                         halbtc8821a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,TRUE,0x6);           \r
3122                 }\r
3123                 return;\r
3124                 \r
3125         }\r
3126 \r
3127         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);\r
3128         halbtc8821a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
3129 \r
3130         halbtc8821a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);      \r
3131 \r
3132         if(BTC_RSSI_HIGH(btRssiState))\r
3133                 halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
3134         else    \r
3135                 halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
3136 \r
3137                 \r
3138         if (BTC_RSSI_HIGH(wifiRssiState1) && BTC_RSSI_HIGH(btRssiState))\r
3139         {\r
3140                 halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);\r
3141                 halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);               \r
3142         }\r
3143         else\r
3144         {\r
3145                 halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 13);\r
3146                 halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);           \r
3147         }\r
3148         \r
3149 \r
3150         if( (btRssiState == BTC_RSSI_STATE_HIGH) ||\r
3151                 (btRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3152         {\r
3153                 halbtc8821a2ant_TdmaDurationAdjust(pBtCoexist, FALSE, FALSE, 1);\r
3154         }\r
3155         else\r
3156         {\r
3157                 halbtc8821a2ant_TdmaDurationAdjust(pBtCoexist, FALSE, TRUE, 1);\r
3158         }\r
3159 \r
3160         // sw mechanism\r
3161         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
3162         if(BTC_WIFI_BW_HT40 == wifiBw)\r
3163         {\r
3164                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3165                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3166                 {\r
3167                         halbtc8821a2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
3168                         halbtc8821a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3169                 }\r
3170                 else\r
3171                 {\r
3172                         halbtc8821a2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
3173                         halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3174                 }\r
3175         }\r
3176         else\r
3177         {\r
3178                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3179                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3180                 {\r
3181                         halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3182                         halbtc8821a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3183                 }\r
3184                 else\r
3185                 {\r
3186                         halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3187                         halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3188                 }               \r
3189         }\r
3190 }\r
3191 \r
3192 VOID\r
3193 halbtc8821a2ant_ActionA2dpPanHs(\r
3194         IN      PBTC_COEXIST            pBtCoexist\r
3195         )\r
3196 {\r
3197         u1Byte          wifiRssiState, wifiRssiState1, btRssiState;\r
3198         u4Byte          wifiBw;\r
3199 \r
3200         wifiRssiState = halbtc8821a2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
3201         wifiRssiState1 = halbtc8821a2ant_WifiRssiState(pBtCoexist, 1, 2, BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);  \r
3202         btRssiState = halbtc8821a2ant_BtRssiState(2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);\r
3203 \r
3204         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);\r
3205 \r
3206         halbtc8821a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
3207         \r
3208         halbtc8821a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
3209 \r
3210         if(BTC_RSSI_HIGH(btRssiState))\r
3211                 halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
3212         else    \r
3213                 halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
3214 \r
3215         if (BTC_RSSI_HIGH(wifiRssiState1) && BTC_RSSI_HIGH(btRssiState))\r
3216         {\r
3217                 halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);\r
3218                 halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);               \r
3219         }\r
3220         else\r
3221         {\r
3222                 halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 13);\r
3223                 halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);           \r
3224         }\r
3225 \r
3226         halbtc8821a2ant_TdmaDurationAdjust(pBtCoexist, FALSE, TRUE, 2);\r
3227 \r
3228         // sw mechanism\r
3229         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
3230         if(BTC_WIFI_BW_HT40 == wifiBw)\r
3231         {\r
3232                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3233                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3234                 {\r
3235                         halbtc8821a2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
3236                         halbtc8821a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3237                 }\r
3238                 else\r
3239                 {\r
3240                         halbtc8821a2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
3241                         halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3242                 }\r
3243         }\r
3244         else\r
3245         {\r
3246                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3247                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3248                 {\r
3249                         halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3250                         halbtc8821a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3251                 }\r
3252                 else\r
3253                 {\r
3254                         halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3255                         halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3256                 }               \r
3257         }\r
3258 }\r
3259 \r
3260 VOID\r
3261 halbtc8821a2ant_ActionPanEdr(\r
3262         IN      PBTC_COEXIST            pBtCoexist\r
3263         )\r
3264 {\r
3265         u1Byte          wifiRssiState,wifiRssiState1, btRssiState;\r
3266         u4Byte          wifiBw;\r
3267 \r
3268         wifiRssiState = halbtc8821a2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
3269         wifiRssiState1 = halbtc8821a2ant_WifiRssiState(pBtCoexist, 1, 2, BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);  \r
3270         btRssiState = halbtc8821a2ant_BtRssiState(2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);\r
3271 \r
3272         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);\r
3273 \r
3274         halbtc8821a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
3275 \r
3276         halbtc8821a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
3277 \r
3278         if(BTC_RSSI_HIGH(btRssiState))\r
3279                 halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
3280         else    \r
3281                 halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
3282 \r
3283         if (BTC_RSSI_HIGH(wifiRssiState1) && BTC_RSSI_HIGH(btRssiState))\r
3284         {\r
3285                 halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 10);\r
3286                 halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);               \r
3287         }\r
3288         else\r
3289         {\r
3290                 halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 13);\r
3291                 halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);           \r
3292         }\r
3293         \r
3294         if( (btRssiState == BTC_RSSI_STATE_HIGH) ||\r
3295                 (btRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3296         {\r
3297                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);       //1->3 for TENCENT spp profile delay time\r
3298         }\r
3299         else\r
3300         {\r
3301                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);       \r
3302         }\r
3303         \r
3304         // sw mechanism\r
3305         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
3306         if(BTC_WIFI_BW_HT40 == wifiBw)\r
3307         {\r
3308                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3309                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3310                 {\r
3311                         halbtc8821a2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
3312                         halbtc8821a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3313                 }\r
3314                 else\r
3315                 {\r
3316                         halbtc8821a2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
3317                         halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3318                 }\r
3319         }\r
3320         else\r
3321         {\r
3322                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3323                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3324                 {\r
3325                         halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3326                         halbtc8821a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3327                 }\r
3328                 else\r
3329                 {\r
3330                         halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3331                         halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3332                 }\r
3333         }\r
3334 }\r
3335 \r
3336 \r
3337 //PAN(HS) only\r
3338 VOID\r
3339 halbtc8821a2ant_ActionPanHs(\r
3340         IN      PBTC_COEXIST            pBtCoexist\r
3341         )\r
3342 {\r
3343         u1Byte          wifiRssiState, wifiRssiState1, btRssiState;\r
3344         u4Byte          wifiBw;\r
3345 \r
3346         wifiRssiState = halbtc8821a2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
3347         wifiRssiState1 = halbtc8821a2ant_WifiRssiState(pBtCoexist, 1, 2, BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);  \r
3348         btRssiState = halbtc8821a2ant_BtRssiState(2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);\r
3349 \r
3350         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);\r
3351 \r
3352         halbtc8821a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
3353 \r
3354         halbtc8821a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
3355 \r
3356         if(BTC_RSSI_HIGH(btRssiState))\r
3357                 halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
3358         else\r
3359                 halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
3360         \r
3361         halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);\r
3362         \r
3363         halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);               \r
3364         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 1);\r
3365 \r
3366         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
3367         if(BTC_WIFI_BW_HT40 == wifiBw)\r
3368         {\r
3369                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3370                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3371                 {\r
3372                         halbtc8821a2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
3373                         halbtc8821a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3374                 }\r
3375                 else\r
3376                 {\r
3377                         halbtc8821a2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
3378                         halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3379                 }\r
3380         }\r
3381         else\r
3382         {\r
3383                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3384                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3385                 {\r
3386                         halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3387                         halbtc8821a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3388                 }\r
3389                 else\r
3390                 {\r
3391                         halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3392                         halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3393                 }\r
3394         }\r
3395 }\r
3396 \r
3397 //PAN(EDR)+A2DP\r
3398 VOID\r
3399 halbtc8821a2ant_ActionPanEdrA2dp(\r
3400         IN      PBTC_COEXIST            pBtCoexist\r
3401         )\r
3402 {\r
3403         u1Byte          wifiRssiState, wifiRssiState1, btRssiState;\r
3404         u4Byte          wifiBw;\r
3405 \r
3406         wifiRssiState = halbtc8821a2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
3407         wifiRssiState1 = halbtc8821a2ant_WifiRssiState(pBtCoexist, 1, 2, BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);  \r
3408         btRssiState = halbtc8821a2ant_BtRssiState(2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);\r
3409 \r
3410         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);\r
3411 \r
3412         halbtc8821a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
3413 \r
3414         halbtc8821a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
3415 \r
3416         if(BTC_RSSI_HIGH(btRssiState))\r
3417                 halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
3418         else    \r
3419                 halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
3420 \r
3421         if (BTC_RSSI_HIGH(wifiRssiState1) && BTC_RSSI_HIGH(btRssiState))                \r
3422                 halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);               \r
3423         else\r
3424                 halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);\r
3425 \r
3426         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
3427 \r
3428         if( (btRssiState == BTC_RSSI_STATE_HIGH) ||\r
3429                 (btRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3430         {\r
3431                 halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 12);\r
3432                 \r
3433                 if(BTC_WIFI_BW_HT40 == wifiBw)\r
3434                         halbtc8821a2ant_TdmaDurationAdjust(pBtCoexist, FALSE, TRUE, 3);\r
3435                 else\r
3436                         halbtc8821a2ant_TdmaDurationAdjust(pBtCoexist, FALSE, FALSE, 3);\r
3437         }\r
3438         else\r
3439         {\r
3440                 halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 13);\r
3441                 halbtc8821a2ant_TdmaDurationAdjust(pBtCoexist, FALSE, TRUE, 3);\r
3442         }\r
3443         \r
3444         // sw mechanism \r
3445         if(BTC_WIFI_BW_HT40 == wifiBw)\r
3446         {\r
3447                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3448                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3449                 {\r
3450                         halbtc8821a2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
3451                         halbtc8821a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3452                 }\r
3453                 else\r
3454                 {\r
3455                         halbtc8821a2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
3456                         halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3457                 }\r
3458         }\r
3459         else\r
3460         {\r
3461                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3462                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3463                 {\r
3464                         halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3465                         halbtc8821a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3466                 }\r
3467                 else\r
3468                 {\r
3469                         halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3470                         halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3471                 }\r
3472         }\r
3473 }\r
3474 \r
3475 VOID\r
3476 halbtc8821a2ant_ActionPanEdrHid(\r
3477         IN      PBTC_COEXIST            pBtCoexist\r
3478         )\r
3479 {\r
3480         u1Byte          wifiRssiState, wifiRssiState1, btRssiState;\r
3481         u4Byte          wifiBw;\r
3482 \r
3483         wifiRssiState = halbtc8821a2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
3484         wifiRssiState1 = halbtc8821a2ant_WifiRssiState(pBtCoexist, 1, 2, BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);  \r
3485         btRssiState = halbtc8821a2ant_BtRssiState(2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);\r
3486         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
3487 \r
3488         halbtc8821a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
3489 \r
3490         if(BTC_RSSI_HIGH(btRssiState))\r
3491                 halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
3492         else    \r
3493                 halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
3494 \r
3495         if (BTC_RSSI_HIGH(wifiRssiState1) && BTC_RSSI_HIGH(btRssiState))        \r
3496         {\r
3497                 halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);\r
3498                 halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);               \r
3499         }\r
3500         else\r
3501         {\r
3502                 halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 14);\r
3503                 halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);\r
3504         }\r
3505 \r
3506         if( (btRssiState == BTC_RSSI_STATE_HIGH) ||\r
3507                 (btRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3508         {\r
3509                 if(BTC_WIFI_BW_HT40 == wifiBw)\r
3510                 {\r
3511                         halbtc8821a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 3);\r
3512                         //halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 11);\r
3513                         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x780);\r
3514                 }\r
3515                 else\r
3516                 {\r
3517                         halbtc8821a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
3518                         //halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);\r
3519                         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);\r
3520                 }\r
3521                 halbtc8821a2ant_TdmaDurationAdjust(pBtCoexist, TRUE, FALSE, 2);\r
3522         }\r
3523         else\r
3524         {\r
3525                 halbtc8821a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
3526                 //halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 14);\r
3527                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);\r
3528                 halbtc8821a2ant_TdmaDurationAdjust(pBtCoexist, TRUE, TRUE, 2);\r
3529         }\r
3530         \r
3531         // sw mechanism\r
3532         if(BTC_WIFI_BW_HT40 == wifiBw)\r
3533         {\r
3534                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3535                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3536                 {\r
3537                         halbtc8821a2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);\r
3538                         halbtc8821a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3539                 }\r
3540                 else\r
3541                 {\r
3542                         halbtc8821a2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);\r
3543                         halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3544                 }\r
3545         }\r
3546         else\r
3547         {\r
3548                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3549                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3550                 {\r
3551                         halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);\r
3552                         halbtc8821a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3553                 }\r
3554                 else\r
3555                 {\r
3556                         halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);\r
3557                         halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3558                 }\r
3559         }\r
3560 }\r
3561 \r
3562 // HID+A2DP+PAN(EDR)\r
3563 VOID\r
3564 halbtc8821a2ant_ActionHidA2dpPanEdr(\r
3565         IN      PBTC_COEXIST            pBtCoexist\r
3566         )\r
3567 {\r
3568         u1Byte          wifiRssiState,wifiRssiState1,  btRssiState;\r
3569         u4Byte          wifiBw;\r
3570 \r
3571         wifiRssiState = halbtc8821a2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
3572         wifiRssiState1 = halbtc8821a2ant_WifiRssiState(pBtCoexist, 1, 2, BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);  \r
3573         btRssiState = halbtc8821a2ant_BtRssiState(2, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);\r
3574 \r
3575         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);\r
3576 \r
3577         halbtc8821a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
3578 \r
3579         halbtc8821a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
3580 \r
3581         if(BTC_RSSI_HIGH(btRssiState))\r
3582                 halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
3583         else    \r
3584                 halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
3585 \r
3586         if (BTC_RSSI_HIGH(wifiRssiState1) && BTC_RSSI_HIGH(btRssiState))\r
3587         {\r
3588                 halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);\r
3589                 halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);               \r
3590         }\r
3591         else\r
3592         {\r
3593                 halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 14);\r
3594                 halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);           \r
3595         }\r
3596 \r
3597         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
3598 \r
3599         if( (btRssiState == BTC_RSSI_STATE_HIGH) ||\r
3600                 (btRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3601         {\r
3602                 if(BTC_WIFI_BW_HT40 == wifiBw)\r
3603                         halbtc8821a2ant_TdmaDurationAdjust(pBtCoexist, TRUE, TRUE, 3);\r
3604                 else\r
3605                         halbtc8821a2ant_TdmaDurationAdjust(pBtCoexist, TRUE, FALSE, 3);\r
3606         }\r
3607         else\r
3608         {\r
3609                 halbtc8821a2ant_TdmaDurationAdjust(pBtCoexist, TRUE, TRUE, 3);\r
3610         }\r
3611 \r
3612         // sw mechanism\r
3613         if(BTC_WIFI_BW_HT40 == wifiBw)\r
3614         {\r
3615                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3616                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3617                 {\r
3618                         halbtc8821a2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);\r
3619                         halbtc8821a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3620                 }\r
3621                 else\r
3622                 {\r
3623                         halbtc8821a2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);\r
3624                         halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3625                 }\r
3626         }\r
3627         else\r
3628         {\r
3629                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3630                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3631                 {\r
3632                         halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);\r
3633                         halbtc8821a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3634                 }\r
3635                 else\r
3636                 {\r
3637                         halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);\r
3638                         halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3639                 }\r
3640         }\r
3641 }\r
3642 \r
3643 VOID\r
3644 halbtc8821a2ant_ActionHidA2dp(\r
3645         IN      PBTC_COEXIST            pBtCoexist\r
3646         )\r
3647 {\r
3648         u1Byte          wifiRssiState, wifiRssiState1, btRssiState;\r
3649         u4Byte          wifiBw;\r
3650         u1Byte          apNum=0;\r
3651 \r
3652         wifiRssiState = halbtc8821a2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
3653         //btRssiState = halbtc8821a2ant_BtRssiState(2, 29, 0);\r
3654         wifiRssiState1 = halbtc8821a2ant_WifiRssiState(pBtCoexist, 1, 2, BT_8821A_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);  \r
3655         btRssiState = halbtc8821a2ant_BtRssiState(3, BT_8821A_2ANT_BT_RSSI_COEXSWITCH_THRES, 37);\r
3656 \r
3657         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);\r
3658         \r
3659         halbtc8821a2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, TRUE, 0x5);\r
3660 \r
3661         halbtc8821a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
3662 \r
3663         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
3664         if(BTC_WIFI_BW_LEGACY == wifiBw)\r
3665         {\r
3666                 if(BTC_RSSI_HIGH(btRssiState))\r
3667                         halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
3668                 else if(BTC_RSSI_MEDIUM(btRssiState))\r
3669                         halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
3670                 else    \r
3671                         halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
3672         }\r
3673         else\r
3674         {       // only 802.11N mode we have to dec bt power to 4 degree\r
3675                 if(BTC_RSSI_HIGH(btRssiState))\r
3676                 {\r
3677                         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_AP_NUM, &apNum);\r
3678                         // need to check ap Number of Not\r
3679                         if(apNum < 10)\r
3680                                 halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 4);\r
3681                         else\r
3682                                 halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
3683                 }\r
3684                 else if(BTC_RSSI_MEDIUM(btRssiState))\r
3685                         halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
3686                 else    \r
3687                         halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
3688         }\r
3689 \r
3690         if (BTC_RSSI_HIGH(wifiRssiState1) && BTC_RSSI_HIGH(btRssiState))\r
3691         {\r
3692                 halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);\r
3693                 halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);               \r
3694         }\r
3695         else\r
3696         {\r
3697                 halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 14);\r
3698                 halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);           \r
3699         }\r
3700 \r
3701         if( (btRssiState == BTC_RSSI_STATE_HIGH) ||\r
3702                 (btRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3703         {\r
3704                 //halbtc8821a2ant_TdmaDurationAdjust(pBtCoexist, TRUE, FALSE, 3);\r
3705                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 23);\r
3706         }\r
3707         else\r
3708         {\r
3709                 //halbtc8821a2ant_TdmaDurationAdjust(pBtCoexist, TRUE, TRUE, 3);\r
3710                 halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 23);\r
3711         }\r
3712         \r
3713         // sw mechanism\r
3714         if(BTC_WIFI_BW_HT40 == wifiBw)\r
3715         {\r
3716                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3717                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3718                 {\r
3719                         halbtc8821a2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);\r
3720                         halbtc8821a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3721                 }\r
3722                 else\r
3723                 {\r
3724                         halbtc8821a2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);\r
3725                         halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3726                 }\r
3727         }\r
3728         else\r
3729         {\r
3730                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3731                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3732                 {\r
3733                         halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);\r
3734                         halbtc8821a2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3735                 }\r
3736                 else\r
3737                 {\r
3738                         halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);\r
3739                         halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3740                 }\r
3741         }\r
3742 }\r
3743 \r
3744 VOID\r
3745 halbtc8821a2ant_ActionBtWhckTest(\r
3746         IN      PBTC_COEXIST            pBtCoexist\r
3747         )\r
3748 {\r
3749         halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
3750 \r
3751         // sw all off\r
3752         halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3753         halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3754 \r
3755         halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
3756         \r
3757         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 1);\r
3758         halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
3759 }\r
3760 \r
3761 VOID\r
3762 halbtc8821a2ant_ActionWifiMultiPort(\r
3763         IN      PBTC_COEXIST            pBtCoexist\r
3764         )\r
3765 {               \r
3766         halbtc8821a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
3767         halbtc8821a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
3768 \r
3769         // sw all off\r
3770         halbtc8821a2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3771         halbtc8821a2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3772 \r
3773         // hw all off\r
3774         //pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);\r
3775         halbtc8821a2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
3776 \r
3777         halbtc8821a2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);               \r
3778         halbtc8821a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 1);\r
3779 }\r
3780 \r
3781 VOID\r
3782 halbtc8821a2ant_RunCoexistMechanism(\r
3783         IN      PBTC_COEXIST            pBtCoexist\r
3784         )\r
3785 {\r
3786         BOOLEAN                         bWifiUnder5G=FALSE, bBtHsOn=FALSE;\r
3787         u1Byte                          btInfoOriginal=0, btRetryCnt=0;\r
3788         u1Byte                          algorithm=0;\r
3789         u4Byte                          numOfWifiLink=0;\r
3790         u4Byte                          wifiLinkStatus=0;\r
3791         PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
3792         BOOLEAN                         bMiracastPlusBt=FALSE;\r
3793         BOOLEAN                         bScan=FALSE, bLink=FALSE, bRoam=FALSE;\r
3794 \r
3795         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], RunCoexistMechanism()===>\n"));\r
3796 \r
3797         if(pBtCoexist->bManualControl)\r
3798         {\r
3799                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n"));\r
3800                 return;\r
3801         }\r
3802 \r
3803         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_5G, &bWifiUnder5G);\r
3804         if(bWifiUnder5G)\r
3805         {\r
3806                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], RunCoexistMechanism(), run 5G coex setting!!<===\n"));\r
3807                 halbtc8821a2ant_CoexUnder5G(pBtCoexist);\r
3808                 return;\r
3809         }\r
3810 \r
3811         if(pCoexSta->bUnderIps)\r
3812         {\r
3813                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], wifi is under IPS !!!\n"));\r
3814                 return;\r
3815         }\r
3816 \r
3817         if(pCoexSta->bBtWhckTest)\r
3818         {\r
3819                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT is under WHCK TEST!!!\n"));\r
3820                 halbtc8821a2ant_ActionBtWhckTest(pBtCoexist);\r
3821                 return;\r
3822         }\r
3823 \r
3824         algorithm = halbtc8821a2ant_ActionAlgorithm(pBtCoexist);\r
3825         if(pCoexSta->bC2hBtInquiryPage && (BT_8821A_2ANT_COEX_ALGO_PANHS!=algorithm))\r
3826         {\r
3827                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT is under inquiry/page scan !!\n"));\r
3828                 halbtc8821a2ant_ActionBtInquiry(pBtCoexist);\r
3829                 return;\r
3830         }\r
3831         else\r
3832         {\r
3833 \r
3834         }\r
3835 \r
3836         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);\r
3837         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);\r
3838         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);\r
3839 \r
3840         if(bScan || bLink || bRoam)\r
3841         {\r
3842                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], WiFi is under Link Process !!\n"));\r
3843                 halbtc8821a2ant_ActionWiFiLinkProcess(pBtCoexist);\r
3844                 return;\r
3845         }\r
3846 \r
3847         //for P2P\r
3848 \r
3849         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus);\r
3850         numOfWifiLink = wifiLinkStatus>>16;\r
3851         \r
3852         if((numOfWifiLink>=2) || (wifiLinkStatus&WIFI_P2P_GO_CONNECTED))\r
3853         {\r
3854                 RT_TRACE(COMP_COEX, DBG_LOUD, ("############# [BTCoex],  Multi-Port numOfWifiLink = %d, wifiLinkStatus = 0x%x\n", numOfWifiLink,wifiLinkStatus) );\r
3855 \r
3856                 if(pBtLinkInfo->bBtLinkExist)\r
3857                 {\r
3858                         bMiracastPlusBt = TRUE;\r
3859                 }\r
3860                 else\r
3861                 {\r
3862                         bMiracastPlusBt = FALSE;\r
3863                 }\r
3864                 \r
3865                 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_MIRACAST_PLUS_BT, &bMiracastPlusBt);\r
3866                 halbtc8821a2ant_ActionWifiMultiPort(pBtCoexist);\r
3867                 \r
3868                 return;\r
3869         }\r
3870         else\r
3871         {\r
3872                 bMiracastPlusBt = FALSE;\r
3873                 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_MIRACAST_PLUS_BT, &bMiracastPlusBt);\r
3874         }\r
3875 \r
3876         pCoexDm->curAlgorithm = algorithm;\r
3877         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Algorithm = %d \n", pCoexDm->curAlgorithm));\r
3878 \r
3879         if(halbtc8821a2ant_IsCommonAction(pBtCoexist))\r
3880         {\r
3881                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant common.\n"));\r
3882                 pCoexDm->bAutoTdmaAdjust = FALSE;\r
3883         }\r
3884         else\r
3885         {\r
3886                 if(pCoexDm->curAlgorithm != pCoexDm->preAlgorithm)\r
3887                 {\r
3888                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], preAlgorithm=%d, curAlgorithm=%d\n", \r
3889                                 pCoexDm->preAlgorithm, pCoexDm->curAlgorithm));\r
3890                         pCoexDm->bAutoTdmaAdjust = FALSE;\r
3891                 }\r
3892                 switch(pCoexDm->curAlgorithm)\r
3893                 {\r
3894                         case BT_8821A_2ANT_COEX_ALGO_SCO:\r
3895                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = SCO.\n"));\r
3896                                 halbtc8821a2ant_ActionSco(pBtCoexist);\r
3897                                 break;\r
3898                         case BT_8821A_2ANT_COEX_ALGO_HID:\r
3899                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = HID.\n"));\r
3900                                 halbtc8821a2ant_ActionHid(pBtCoexist);\r
3901                                 break;\r
3902                         case BT_8821A_2ANT_COEX_ALGO_A2DP:\r
3903                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = A2DP.\n"));\r
3904                                 halbtc8821a2ant_ActionA2dp(pBtCoexist);\r
3905                                 break;\r
3906                         case BT_8821A_2ANT_COEX_ALGO_A2DP_PANHS:\r
3907                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = A2DP+PAN(HS).\n"));\r
3908                                 halbtc8821a2ant_ActionA2dpPanHs(pBtCoexist);\r
3909                                 break;\r
3910                         case BT_8821A_2ANT_COEX_ALGO_PANEDR:\r
3911                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = PAN(EDR).\n"));\r
3912                                 halbtc8821a2ant_ActionPanEdr(pBtCoexist);\r
3913                                 break;\r
3914                         case BT_8821A_2ANT_COEX_ALGO_PANHS:\r
3915                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = HS mode.\n"));\r
3916                                 halbtc8821a2ant_ActionPanHs(pBtCoexist);\r
3917                                 break;\r
3918                         case BT_8821A_2ANT_COEX_ALGO_PANEDR_A2DP:\r
3919                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = PAN+A2DP.\n"));\r
3920                                 halbtc8821a2ant_ActionPanEdrA2dp(pBtCoexist);\r
3921                                 break;\r
3922                         case BT_8821A_2ANT_COEX_ALGO_PANEDR_HID:\r
3923                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = PAN(EDR)+HID.\n"));\r
3924                                 halbtc8821a2ant_ActionPanEdrHid(pBtCoexist);\r
3925                                 break;\r
3926                         case BT_8821A_2ANT_COEX_ALGO_HID_A2DP_PANEDR:\r
3927                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = HID+A2DP+PAN.\n"));\r
3928                                 halbtc8821a2ant_ActionHidA2dpPanEdr(pBtCoexist);\r
3929                                 break;\r
3930                         case BT_8821A_2ANT_COEX_ALGO_HID_A2DP:\r
3931                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = HID+A2DP.\n"));\r
3932                                 halbtc8821a2ant_ActionHidA2dp(pBtCoexist);\r
3933                                 break;\r
3934                         default:\r
3935                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = coexist All Off!!\n"));\r
3936                                 halbtc8821a2ant_CoexAllOff(pBtCoexist);\r
3937                                 break;\r
3938                 }\r
3939                 pCoexDm->preAlgorithm = pCoexDm->curAlgorithm;\r
3940         }\r
3941 }\r
3942 \r
3943 VOID\r
3944 halbtc8821a2ant_WifiOffHwCfg(\r
3945         IN      PBTC_COEXIST            pBtCoexist\r
3946         )\r
3947 {\r
3948         BOOLEAN bIsInMpMode = FALSE;\r
3949         u1Byte H2C_Parameter[2] ={0};\r
3950         u4Byte fwVer=0;\r
3951 \r
3952         // set wlan_act to low\r
3953         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4);\r
3954 \r
3955         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x780); //WiFi goto standby while GNT_BT 0-->1\r
3956         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);\r
3957         if(fwVer >= 0x180000)\r
3958         {\r
3959                 /* Use H2C to set GNT_BT to HIGH */\r
3960                 H2C_Parameter[0] = 1;\r
3961                 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x6E, 1, H2C_Parameter);\r
3962         }\r
3963         else\r
3964         {\r
3965                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x765, 0x18);\r
3966         }\r
3967 }\r
3968 \r
3969 VOID\r
3970 halbtc8821a2ant_InitHwConfig(\r
3971         IN      PBTC_COEXIST            pBtCoexist,\r
3972         IN      BOOLEAN                         bBackUp\r
3973         )\r
3974 {\r
3975         PBTC_BOARD_INFO         pBoardInfo=&pBtCoexist->boardInfo;\r
3976         u4Byte  u4Tmp=0, fwVer;\r
3977         u2Byte                          u2Tmp=0;\r
3978         u1Byte  u1Tmp=0;\r
3979         u1Byte                          H2C_Parameter[2] ={0};\r
3980                 \r
3981 \r
3982         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], 2Ant Init HW Config!!\n"));\r
3983 \r
3984         // backup rf 0x1e value\r
3985         pCoexDm->btRf0x1eBackup = \r
3986                 pBtCoexist->fBtcGetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff);  \r
3987 \r
3988         // 0x790[5:0]=0x5\r
3989         u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x790);\r
3990         u1Tmp &= 0xc0;\r
3991         u1Tmp |= 0x5;\r
3992         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x790, u1Tmp);\r
3993 \r
3994         //Antenna config        \r
3995         halbtc8821a2ant_SetAntPath(pBtCoexist, BTC_ANT_WIFI_AT_MAIN, TRUE, FALSE);\r
3996         pCoexSta->disVerInfoCnt = 0;\r
3997 \r
3998         // PTA parameter\r
3999         halbtc8821a2ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 0);\r
4000         \r
4001         // Enable counter statistics\r
4002         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4); //0x76e[3] =1, WLAN_Act control by PTA\r
4003         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x778, 0x3);\r
4004         pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x40, 0x20, 0x1);\r
4005 }\r
4006 \r
4007 //============================================================\r
4008 // work around function start with wa_halbtc8821a2ant_\r
4009 //============================================================\r
4010 //============================================================\r
4011 // extern function start with EXhalbtc8821a2ant_\r
4012 //============================================================\r
4013 VOID\r
4014 EXhalbtc8821a2ant_PowerOnSetting(\r
4015         IN      PBTC_COEXIST            pBtCoexist\r
4016         )\r
4017 {\r
4018 \r
4019 }\r
4020 \r
4021 VOID\r
4022 EXhalbtc8821a2ant_PreLoadFirmware(\r
4023         IN      PBTC_COEXIST            pBtCoexist\r
4024         )\r
4025 {\r
4026         PBTC_BOARD_INFO         pBoardInfo=&pBtCoexist->boardInfo;\r
4027         u1Byte u1Tmp=0x4; /* Set BIT2 by default since it's 2ant case */\r
4028 \r
4029         // \r
4030         // S0 or S1 setting and Local register setting(By the setting fw can get ant number, S0/S1, ... info)\r
4031         // Local setting bit define\r
4032         //      BIT0: "0" for no antenna inverse; "1" for antenna inverse \r
4033         //      BIT1: "0" for internal switch; "1" for external switch\r
4034         //      BIT2: "0" for one antenna; "1" for two antenna\r
4035         // NOTE: here default all internal switch and 1-antenna ==> BIT1=0 and BIT2=0\r
4036         if(pBtCoexist->chipInterface == BTC_INTF_USB)\r
4037         {\r
4038                 // fixed at S0 for USB interface\r
4039                 u1Tmp |= 0x1;   // antenna inverse\r
4040                 pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0xfe08, u1Tmp);\r
4041         }\r
4042         else\r
4043         {\r
4044                 // for PCIE and SDIO interface, we check efuse 0xc3[6]\r
4045                 if(pBoardInfo->singleAntPath == 0)\r
4046                 {\r
4047                 }\r
4048                 else if(pBoardInfo->singleAntPath == 1)\r
4049                 {\r
4050                         // set to S0\r
4051                         u1Tmp |= 0x1;   // antenna inverse\r
4052                 }\r
4053 \r
4054                 if(pBtCoexist->chipInterface == BTC_INTF_PCI)\r
4055                 {       \r
4056                         pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0x384, u1Tmp);\r
4057                 }\r
4058                 else if(pBtCoexist->chipInterface == BTC_INTF_SDIO)\r
4059                 {\r
4060                         pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0x60, u1Tmp);\r
4061                 }                       \r
4062         }\r
4063 }\r
4064 \r
4065 VOID\r
4066 EXhalbtc8821a2ant_InitHwConfig(\r
4067         IN      PBTC_COEXIST            pBtCoexist,\r
4068         IN      BOOLEAN                         bWifiOnly\r
4069         )\r
4070 {\r
4071         halbtc8821a2ant_InitHwConfig(pBtCoexist, TRUE);\r
4072 }\r
4073 \r
4074 VOID\r
4075 EXhalbtc8821a2ant_InitCoexDm(\r
4076         IN      PBTC_COEXIST            pBtCoexist\r
4077         )\r
4078 {\r
4079         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Coex Mechanism Init!!\n"));\r
4080         \r
4081         halbtc8821a2ant_InitCoexDm(pBtCoexist);\r
4082 }\r
4083 \r
4084 VOID\r
4085 EXhalbtc8821a2ant_DisplayCoexInfo(\r
4086         IN      PBTC_COEXIST            pBtCoexist\r
4087         )\r
4088 {\r
4089         PBTC_BOARD_INFO         pBoardInfo=&pBtCoexist->boardInfo;\r
4090         PBTC_STACK_INFO         pStackInfo=&pBtCoexist->stackInfo;\r
4091         PBTC_BT_LINK_INFO       pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
4092         pu1Byte                         cliBuf=pBtCoexist->cliBuf;\r
4093         u1Byte                          u1Tmp[4], i, btInfoExt, psTdmaCase=0;\r
4094         u4Byte                          u4Tmp[4];\r
4095         u4Byte                          faOfdm, faCck;\r
4096         u4Byte                          fwVer=0, btPatchVer=0;\r
4097 \r
4098         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[BT Coexist info]============");\r
4099         CL_PRINTF(cliBuf);\r
4100 \r
4101         if(pBtCoexist->bManualControl)\r
4102         {\r
4103                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[Under Manual Control]============");\r
4104                 CL_PRINTF(cliBuf);\r
4105                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ==========================================");\r
4106                 CL_PRINTF(cliBuf);\r
4107         }\r
4108 \r
4109         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ", "Ant PG number/ Ant mechanism:", \\r
4110                 pBoardInfo->pgAntNum, pBoardInfo->btdmAntNum);\r
4111         CL_PRINTF(cliBuf);\r
4112         \r
4113         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %d", "BT stack/ hci ext ver", \\r
4114                 ((pStackInfo->bProfileNotified)? "Yes":"No"), pStackInfo->hciVersion);\r
4115         CL_PRINTF(cliBuf);\r
4116 \r
4117         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_BT_PATCH_VER, &btPatchVer);\r
4118         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);\r
4119         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d_%x/ 0x%x/ 0x%x(%d)", "CoexVer/ FwVer/ PatchVer", \\r
4120                 GLCoexVerDate8821a2Ant, GLCoexVer8821a2Ant, fwVer, btPatchVer, btPatchVer);\r
4121         CL_PRINTF(cliBuf);\r
4122 \r
4123         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ", "Wifi channel informed to BT", \\r
4124                 pCoexDm->wifiChnlInfo[0], pCoexDm->wifiChnlInfo[1],\r
4125                 pCoexDm->wifiChnlInfo[2]);\r
4126         CL_PRINTF(cliBuf);\r
4127         \r
4128         // wifi status\r
4129         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Wifi Status]============");\r
4130         CL_PRINTF(cliBuf);\r
4131         pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_WIFI_STATUS);\r
4132 \r
4133         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[BT Status]============");\r
4134         CL_PRINTF(cliBuf);\r
4135 \r
4136         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %ddBm/ %d] ", "BT [status/ rssi/ retryCnt]", \\r
4137                 ((pBtCoexist->btInfo.bBtDisabled)? ("disabled"):        ((pCoexSta->bC2hBtInquiryPage)?("inquiry/page scan"):((BT_8821A_2ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus)? "non-connected idle":\r
4138                 (  (BT_8821A_2ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus)? "connected-idle":"busy")))),\r
4139                 pCoexSta->btRssi-100, pCoexSta->btRetryCnt);\r
4140         CL_PRINTF(cliBuf);\r
4141 \r
4142         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d", "SCO/HID/PAN/A2DP", \\r
4143                 pBtLinkInfo->bScoExist, pBtLinkInfo->bHidExist, pBtLinkInfo->bPanExist, pBtLinkInfo->bA2dpExist);\r
4144         CL_PRINTF(cliBuf);\r
4145 \r
4146         if (pStackInfo->bProfileNotified)\r
4147         {\r
4148                 pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_BT_LINK_INFO);      \r
4149         }\r
4150         else\r
4151         {\r
4152                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "BT Role", \\r
4153                 (pBtLinkInfo->bSlaveRole )? "Slave":"Master");\r
4154                 CL_PRINTF(cliBuf);      \r
4155         }       \r
4156 \r
4157         btInfoExt = pCoexSta->btInfoExt;\r
4158         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "BT Info A2DP rate", \\r
4159                 (btInfoExt&BIT0)? "Basic rate":"EDR rate");\r
4160         CL_PRINTF(cliBuf);      \r
4161 \r
4162         for(i=0; i<BT_INFO_SRC_8821A_2ANT_MAX; i++)\r
4163         {\r
4164                 if(pCoexSta->btInfoC2hCnt[i])\r
4165                 {                               \r
4166                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)", GLBtInfoSrc8821a2Ant[i], \\r
4167                                 pCoexSta->btInfoC2h[i][0], pCoexSta->btInfoC2h[i][1],\r
4168                                 pCoexSta->btInfoC2h[i][2], pCoexSta->btInfoC2h[i][3],\r
4169                                 pCoexSta->btInfoC2h[i][4], pCoexSta->btInfoC2h[i][5],\r
4170                                 pCoexSta->btInfoC2h[i][6], pCoexSta->btInfoC2hCnt[i]);\r
4171                         CL_PRINTF(cliBuf);\r
4172                 }\r
4173         }\r
4174 \r
4175         // Sw mechanism \r
4176         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Sw mechanism]============");\r
4177         CL_PRINTF(cliBuf);\r
4178         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d ", "SM1[ShRf/ LpRA/ LimDig]", \\r
4179                 pCoexDm->bCurRfRxLpfShrink, pCoexDm->bCurLowPenaltyRa, pCoexDm->bLimitedDig);\r
4180         CL_PRINTF(cliBuf);\r
4181         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d(0x%x) ", "SM2[AgcT/ AdcB/ SwDacSwing(lvl)]", \\r
4182                 pCoexDm->bCurAgcTableEn, pCoexDm->bCurAdcBackOff, pCoexDm->bCurDacSwingOn, pCoexDm->curDacSwingLvl);\r
4183         CL_PRINTF(cliBuf);\r
4184 \r
4185         // Fw mechanism         \r
4186         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Fw mechanism]============");\r
4187         CL_PRINTF(cliBuf);      \r
4188 \r
4189         psTdmaCase = pCoexDm->curPsTdma;\r
4190         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (auto:%d)", "PS TDMA", \\r
4191                 pCoexDm->psTdmaPara[0], pCoexDm->psTdmaPara[1],\r
4192                 pCoexDm->psTdmaPara[2], pCoexDm->psTdmaPara[3],\r
4193                 pCoexDm->psTdmaPara[4], psTdmaCase, pCoexDm->bAutoTdmaAdjust);\r
4194         CL_PRINTF(cliBuf);\r
4195 \r
4196         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "Coex Table Type", \\r
4197                         pCoexSta->nCoexTableType);\r
4198                 CL_PRINTF(cliBuf);\r
4199 \r
4200         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ", "DecBtPwr/ IgnWlanAct", \\r
4201                 pCoexDm->curBtDecPwrLvl, pCoexDm->bCurIgnoreWlanAct);\r
4202         CL_PRINTF(cliBuf);\r
4203 \r
4204         // Hw setting           \r
4205         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Hw setting]============");\r
4206         CL_PRINTF(cliBuf);      \r
4207 \r
4208         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "RF-A, 0x1e initVal", \\r
4209                 pCoexDm->btRf0x1eBackup);\r
4210         CL_PRINTF(cliBuf);\r
4211 \r
4212         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x778);\r
4213         u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0xc5b);\r
4214         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x880);\r
4215         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x778/0x880[29:25]/0xc58[29:25]", \\r
4216                 u1Tmp[0], (u4Tmp[0]&0x3e000000) >> 25, ((u1Tmp[1]&0x3e)>>1));\r
4217         CL_PRINTF(cliBuf);\r
4218 \r
4219         u4Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x764);\r
4220         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x76e);\r
4221         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x764/ 0x765/ 0x76e", \\r
4222                 (u4Tmp[0]&0xff), (u4Tmp[0]&0xff00)>>8, u1Tmp[0]);\r
4223         CL_PRINTF(cliBuf);\r
4224         \r
4225         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xcb4);\r
4226         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "0xcb4[7:0](ctrl)/ 0xcb4[29:28](val)", \\r
4227                 u4Tmp[0]&0xff, ((u4Tmp[0]&0x30000000)>>28));\r
4228         CL_PRINTF(cliBuf);\r
4229 \r
4230         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x40);\r
4231         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);\r
4232         u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x974);\r
4233         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x40/ 0x4c[24:23]/ 0x974", \\r
4234                 u1Tmp[0], ((u4Tmp[0]&0x01800000)>>23), u4Tmp[1]);\r
4235         CL_PRINTF(cliBuf);\r
4236 \r
4237         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x550);\r
4238         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x522);\r
4239         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "0x550(bcn ctrl)/0x522", \\r
4240                 u4Tmp[0], u1Tmp[0]);\r
4241         CL_PRINTF(cliBuf);\r
4242 \r
4243         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xc50);\r
4244         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x49c);\r
4245         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "0xc50(dig)/0x49c(null-drop)", \\r
4246                 u4Tmp[0]&0xff, u1Tmp[0]);\r
4247         CL_PRINTF(cliBuf);\r
4248 \r
4249         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda0);\r
4250         u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda4);\r
4251         u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda8);\r
4252         u4Tmp[3] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xcf0);\r
4253 \r
4254         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0xa5b);\r
4255         u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0xa5c);\r
4256 \r
4257         faOfdm = ((u4Tmp[0]&0xffff0000) >> 16) +  ((u4Tmp[1]&0xffff0000) >> 16) + (u4Tmp[1] & 0xffff) +  (u4Tmp[2] & 0xffff) + \\r
4258                              ((u4Tmp[3]&0xffff0000) >> 16) + (u4Tmp[3] & 0xffff) ;\r
4259         faCck = (u1Tmp[0] << 8) + u1Tmp[1];\r
4260         \r
4261         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "OFDM-CCA/OFDM-FA/CCK-FA", \\r
4262                 u4Tmp[0]&0xffff, faOfdm, faCck);\r
4263         CL_PRINTF(cliBuf);\r
4264 \r
4265         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", "CRC_OK CCK/11g/11n/11n-Agg", \\r
4266                 pCoexSta->nCRCOK_CCK, pCoexSta->nCRCOK_11g, pCoexSta->nCRCOK_11n, pCoexSta->nCRCOK_11nAgg);\r
4267         CL_PRINTF(cliBuf);\r
4268 \r
4269         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", "CRC_Err CCK/11g/11n/11n-Agg", \\r
4270                 pCoexSta->nCRCErr_CCK, pCoexSta->nCRCErr_11g, pCoexSta->nCRCErr_11n, pCoexSta->nCRCErr_11nAgg);\r
4271         CL_PRINTF(cliBuf);      \r
4272 \r
4273         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c0);\r
4274         u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c4);\r
4275         u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c8);\r
4276         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x6cc);\r
4277         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)", \\r
4278                 u4Tmp[0], u4Tmp[1], u4Tmp[2], u1Tmp[0]);\r
4279         CL_PRINTF(cliBuf);\r
4280 \r
4281         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "0x770(high-pri rx/tx)", \\r
4282                 pCoexSta->highPriorityRx, pCoexSta->highPriorityTx);\r
4283         CL_PRINTF(cliBuf);\r
4284         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "0x774(low-pri rx/tx)", \\r
4285                 pCoexSta->lowPriorityRx, pCoexSta->lowPriorityTx);\r
4286         CL_PRINTF(cliBuf);\r
4287 #if(BT_AUTO_REPORT_ONLY_8821A_2ANT == 1)\r
4288         //halbtc8821a2ant_MonitorBtCtr(pBtCoexist);\r
4289 #endif\r
4290         pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_COEX_STATISTICS);\r
4291 }\r
4292 \r
4293 \r
4294 VOID\r
4295 EXhalbtc8821a2ant_IpsNotify(\r
4296         IN      PBTC_COEXIST            pBtCoexist,\r
4297         IN      u1Byte                  type\r
4298         )\r
4299 {\r
4300         if(BTC_IPS_ENTER == type)\r
4301         {\r
4302                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], IPS ENTER notify\n"));\r
4303                 pCoexSta->bUnderIps = TRUE;\r
4304                 halbtc8821a2ant_WifiOffHwCfg(pBtCoexist);\r
4305                 halbtc8821a2ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, TRUE);\r
4306                 halbtc8821a2ant_CoexAllOff(pBtCoexist);\r
4307         }\r
4308         else if(BTC_IPS_LEAVE == type)\r
4309         {\r
4310                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], IPS LEAVE notify\n"));\r
4311                 pCoexSta->bUnderIps = FALSE;\r
4312                 halbtc8821a2ant_InitHwConfig(pBtCoexist, FALSE);\r
4313                 halbtc8821a2ant_InitCoexDm(pBtCoexist);\r
4314                 halbtc8821a2ant_QueryBtInfo(pBtCoexist);\r
4315         }\r
4316 }\r
4317 \r
4318 VOID\r
4319 EXhalbtc8821a2ant_LpsNotify(\r
4320         IN      PBTC_COEXIST            pBtCoexist,\r
4321         IN      u1Byte                  type\r
4322         )\r
4323 {\r
4324         if(BTC_LPS_ENABLE == type)\r
4325         {\r
4326                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], LPS ENABLE notify\n"));\r
4327                 pCoexSta->bUnderLps = TRUE;\r
4328         }\r
4329         else if(BTC_LPS_DISABLE == type)\r
4330         {\r
4331                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], LPS DISABLE notify\n"));\r
4332                 pCoexSta->bUnderLps = FALSE;\r
4333         }\r
4334 }\r
4335 \r
4336 VOID\r
4337 EXhalbtc8821a2ant_ScanNotify(\r
4338         IN      PBTC_COEXIST            pBtCoexist,\r
4339         IN      u1Byte                  type\r
4340         )\r
4341 {\r
4342         u1Byte  u1Tmpa, u1Tmpb; \r
4343         \r
4344         u1Tmpa = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x765);\r
4345         u1Tmpb = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x76e);\r
4346          \r
4347         if(BTC_SCAN_START == type)\r
4348         {\r
4349                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCAN START notify\n"));\r
4350         }\r
4351         else if(BTC_SCAN_FINISH == type)\r
4352         {\r
4353                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCAN FINISH notify\n"));\r
4354         }\r
4355 \r
4356         RT_TRACE(COMP_COEX, DBG_LOUD, ("############# [BTCoex], 0x765=0x%x, 0x76e=0x%x\n", u1Tmpa, u1Tmpb));\r
4357 }\r
4358 \r
4359 VOID\r
4360 EXhalbtc8821a2ant_ConnectNotify(\r
4361         IN      PBTC_COEXIST            pBtCoexist,\r
4362         IN      u1Byte                  type\r
4363         )\r
4364 {\r
4365         if(BTC_ASSOCIATE_START == type)\r
4366         {\r
4367                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CONNECT START notify\n"));\r
4368         }\r
4369         else if(BTC_ASSOCIATE_FINISH == type)\r
4370         {\r
4371                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CONNECT FINISH notify\n"));\r
4372         }\r
4373 }\r
4374 \r
4375 VOID\r
4376 EXhalbtc8821a2ant_MediaStatusNotify(\r
4377         IN      PBTC_COEXIST            pBtCoexist,\r
4378         IN      u1Byte                          type\r
4379         )\r
4380 {\r
4381         u1Byte                  H2C_Parameter[3] ={0};\r
4382         u4Byte                  wifiBw;\r
4383         u1Byte                  wifiCentralChnl;\r
4384         u1Byte                  apNum=0;\r
4385 \r
4386         if(BTC_MEDIA_CONNECT == type)\r
4387         {\r
4388                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], MEDIA connect notify\n"));\r
4389         }\r
4390         else\r
4391         {\r
4392                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], MEDIA disconnect notify\n"));\r
4393         }\r
4394 \r
4395         // only 2.4G we need to inform bt the chnl mask\r
4396         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL, &wifiCentralChnl);\r
4397         if( (BTC_MEDIA_CONNECT == type) &&\r
4398                 (wifiCentralChnl <= 14) )\r
4399         {\r
4400                 H2C_Parameter[0] = 0x1;\r
4401                 H2C_Parameter[1] = wifiCentralChnl;\r
4402                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
4403                 if(BTC_WIFI_BW_HT40 == wifiBw)\r
4404                         H2C_Parameter[2] = 0x30;\r
4405                 else\r
4406                 {\r
4407                         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_AP_NUM, &apNum);\r
4408                         if(apNum < 10)\r
4409                                 H2C_Parameter[2] = 0x30;\r
4410                         else\r
4411                                 H2C_Parameter[2] = 0x20;\r
4412                 }\r
4413         }\r
4414         \r
4415         pCoexDm->wifiChnlInfo[0] = H2C_Parameter[0];\r
4416         pCoexDm->wifiChnlInfo[1] = H2C_Parameter[1];\r
4417         pCoexDm->wifiChnlInfo[2] = H2C_Parameter[2];\r
4418         \r
4419         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], FW write 0x66=0x%x\n", \r
4420                 H2C_Parameter[0]<<16|H2C_Parameter[1]<<8|H2C_Parameter[2]));\r
4421 \r
4422         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x66, 3, H2C_Parameter);    \r
4423 }\r
4424 \r
4425 VOID\r
4426 EXhalbtc8821a2ant_SpecialPacketNotify(\r
4427         IN      PBTC_COEXIST                    pBtCoexist,\r
4428         IN      u1Byte                          type\r
4429         )\r
4430 {\r
4431         if(type == BTC_PACKET_DHCP)\r
4432         {\r
4433                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], DHCP Packet notify\n"));\r
4434         }\r
4435 }\r
4436 \r
4437 VOID\r
4438 EXhalbtc8821a2ant_BtInfoNotify(\r
4439         IN      PBTC_COEXIST            pBtCoexist,\r
4440         IN      pu1Byte                 tmpBuf,\r
4441         IN      u1Byte                  length\r
4442         )\r
4443 {\r
4444         PBTC_BT_LINK_INFO       pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
4445         u1Byte                  btInfo=0;\r
4446         u1Byte                  i, rspSource=0;\r
4447         BOOLEAN                 bBtBusy=FALSE, bLimitedDig=FALSE;\r
4448         BOOLEAN                 bWifiConnected=FALSE, bWifiUnder5G=FALSE;\r
4449         static BOOLEAN          bPreScoExist=FALSE;\r
4450         u4Byte                          raMask=0x0;\r
4451 \r
4452         pCoexSta->bC2hBtInfoReqSent = FALSE;\r
4453         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_5G, &bWifiUnder5G);\r
4454         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
4455 \r
4456         rspSource = tmpBuf[0]&0xf;\r
4457         if(rspSource >= BT_INFO_SRC_8821A_2ANT_MAX)\r
4458                 rspSource = BT_INFO_SRC_8821A_2ANT_WIFI_FW;\r
4459         pCoexSta->btInfoC2hCnt[rspSource]++;\r
4460 \r
4461         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Bt info[%d], length=%d, hex data=[", rspSource, length));\r
4462         for(i=0; i<length; i++)\r
4463         {\r
4464                 pCoexSta->btInfoC2h[rspSource][i] = tmpBuf[i];\r
4465                 if(i == 1)\r
4466                         btInfo = tmpBuf[i];\r
4467                 if(i == length-1)\r
4468                 {\r
4469                         RT_TRACE(COMP_COEX, DBG_LOUD, ("0x%02x]\n", tmpBuf[i]));\r
4470                 }\r
4471                 else\r
4472                 {\r
4473                         RT_TRACE(COMP_COEX, DBG_LOUD, ("0x%02x, ", tmpBuf[i]));\r
4474                 }\r
4475         }\r
4476 \r
4477         if(pBtCoexist->bManualControl)\r
4478         {\r
4479                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), return for Manual CTRL<===\n"));\r
4480                 return;\r
4481         }\r
4482 \r
4483         // if 0xff, it means BT is under WHCK test\r
4484         if (btInfo == 0xff)\r
4485                 pCoexSta->bBtWhckTest = TRUE;\r
4486         else\r
4487                 pCoexSta->bBtWhckTest = FALSE;\r
4488 \r
4489         if(BT_INFO_SRC_8821A_2ANT_WIFI_FW != rspSource)\r
4490         {\r
4491                 pCoexSta->btRetryCnt =  // [3:0]\r
4492                         pCoexSta->btInfoC2h[rspSource][2]&0xf;\r
4493 \r
4494                 pCoexSta->btRssi =\r
4495                         pCoexSta->btInfoC2h[rspSource][3]*2+10;\r
4496 \r
4497                 pCoexSta->btInfoExt = \r
4498                         pCoexSta->btInfoC2h[rspSource][4];\r
4499 \r
4500                 pCoexSta->bBtTxRxMask = (pCoexSta->btInfoC2h[rspSource][2]&0x40);\r
4501                 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TX_RX_MASK, &pCoexSta->bBtTxRxMask);\r
4502                 if(pCoexSta->bBtTxRxMask)\r
4503                 {\r
4504                         /* BT into is responded by BT FW and BT RF REG 0x3C != 0x01 => Need to switch BT TRx Mask */                            \r
4505                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Switch BT TRx Mask since BT RF REG 0x3C != 0x01\n"));\r
4506                         pBtCoexist->fBtcSetBtReg(pBtCoexist, BTC_BT_REG_RF, 0x3c, 0x01);\r
4507                 }\r
4508 \r
4509                 // Here we need to resend some wifi info to BT\r
4510                 // because bt is reset and loss of the info.\r
4511                 if( (pCoexSta->btInfoExt & BIT1) )\r
4512                 {\r
4513                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n"));\r
4514                         if(bWifiConnected)\r
4515                         {\r
4516                                 EXhalbtc8821a2ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_CONNECT);\r
4517                         }\r
4518                         else\r
4519                         {\r
4520                                 EXhalbtc8821a2ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);\r
4521                         }\r
4522                 }\r
4523 \r
4524                 \r
4525                 if(!pBtCoexist->bManualControl && !bWifiUnder5G)\r
4526                 {\r
4527                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT ext info = 0x%x!!\n", pCoexSta->btInfoExt));\r
4528                         if( (pCoexSta->btInfoExt&BIT3) )\r
4529                         {\r
4530                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT ext info bit3=1, bWifiConnected=%d\n", bWifiConnected));\r
4531                                 if(bWifiConnected)\r
4532                                 {\r
4533                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n"));\r
4534                                         halbtc8821a2ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, FALSE);\r
4535                                 }\r
4536                         }\r
4537                         else\r
4538                         {\r
4539                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT ext info bit3=0, bWifiConnected=%d\n", bWifiConnected));\r
4540                                 // BT already NOT ignore Wlan active, do nothing here.\r
4541                                 if(!bWifiConnected)\r
4542                                 {\r
4543                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT ext info bit3 check, set BT to ignore Wlan active!!\n"));\r
4544                                         halbtc8821a2ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, TRUE);\r
4545                                 }\r
4546                         }\r
4547                 }\r
4548 \r
4549 #if(BT_AUTO_REPORT_ONLY_8821A_2ANT == 0)\r
4550                 if( (pCoexSta->btInfoExt & BIT4) )\r
4551                 {\r
4552                         // BT auto report already enabled, do nothing\r
4553                 }\r
4554                 else\r
4555                 {\r
4556                         halbtc8821a2ant_BtAutoReport(pBtCoexist, FORCE_EXEC, TRUE);\r
4557                 }\r
4558 #endif\r
4559         }\r
4560 \r
4561         // check BIT2 first ==> check if bt is under inquiry or page scan\r
4562         if(btInfo & BT_INFO_8821A_2ANT_B_INQ_PAGE)\r
4563                 pCoexSta->bC2hBtInquiryPage = TRUE;\r
4564         else\r
4565                 pCoexSta->bC2hBtInquiryPage = FALSE;\r
4566 \r
4567         // set link exist status\r
4568         if(!(btInfo&BT_INFO_8821A_2ANT_B_CONNECTION))\r
4569         {\r
4570                 pCoexSta->bBtLinkExist = FALSE;\r
4571                 pCoexSta->bPanExist = FALSE;\r
4572                 pCoexSta->bA2dpExist = FALSE;\r
4573                 pCoexSta->bHidExist = FALSE;\r
4574                 pCoexSta->bScoExist = FALSE;\r
4575         }\r
4576         else    // connection exists\r
4577         {\r
4578                 pCoexSta->bBtLinkExist = TRUE;\r
4579                 if(btInfo & BT_INFO_8821A_2ANT_B_FTP)\r
4580                         pCoexSta->bPanExist = TRUE;\r
4581                 else\r
4582                         pCoexSta->bPanExist = FALSE;\r
4583                 if(btInfo & BT_INFO_8821A_2ANT_B_A2DP)\r
4584                         pCoexSta->bA2dpExist = TRUE;\r
4585                 else\r
4586                         pCoexSta->bA2dpExist = FALSE;\r
4587                 if(btInfo & BT_INFO_8821A_2ANT_B_HID)\r
4588                         pCoexSta->bHidExist = TRUE;\r
4589                 else\r
4590                         pCoexSta->bHidExist = FALSE;\r
4591                 if(btInfo & BT_INFO_8821A_2ANT_B_SCO_ESCO)\r
4592                         pCoexSta->bScoExist = TRUE;\r
4593                 else\r
4594                         pCoexSta->bScoExist = FALSE;\r
4595         \r
4596                 if ( (pCoexSta->bHidExist == FALSE) && (pCoexSta->bC2hBtInquiryPage == FALSE) && (pCoexSta->bScoExist == FALSE))\r
4597                 {\r
4598                         if (pCoexSta->highPriorityTx  + pCoexSta->highPriorityRx >= 160) \r
4599                                 pCoexSta->bHidExist = TRUE;\r
4600                 }\r
4601         }\r
4602 \r
4603         halbtc8821a2ant_UpdateBtLinkInfo(pBtCoexist);\r
4604         \r
4605         if(!(btInfo&BT_INFO_8821A_2ANT_B_CONNECTION))\r
4606         {\r
4607                 pCoexDm->btStatus = BT_8821A_2ANT_BT_STATUS_NON_CONNECTED_IDLE;\r
4608                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n"));\r
4609         }\r
4610         else if(btInfo == BT_INFO_8821A_2ANT_B_CONNECTION)      // connection exists but no busy\r
4611         {\r
4612                 pCoexDm->btStatus = BT_8821A_2ANT_BT_STATUS_CONNECTED_IDLE;\r
4613                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n"));\r
4614         }\r
4615         else if((btInfo&BT_INFO_8821A_2ANT_B_SCO_ESCO) ||\r
4616                 (btInfo&BT_INFO_8821A_2ANT_B_SCO_BUSY))\r
4617         {\r
4618                 pCoexDm->btStatus = BT_8821A_2ANT_BT_STATUS_SCO_BUSY;\r
4619                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT SCO busy!!!\n"));\r
4620         }\r
4621         else if(btInfo&BT_INFO_8821A_2ANT_B_ACL_BUSY)\r
4622         {\r
4623                 pCoexDm->btStatus = BT_8821A_2ANT_BT_STATUS_ACL_BUSY;\r
4624                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT ACL busy!!!\n"));\r
4625         }\r
4626         else\r
4627         {\r
4628                 pCoexDm->btStatus = BT_8821A_2ANT_BT_STATUS_MAX;\r
4629                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n"));\r
4630         }\r
4631         \r
4632         if( (BT_8821A_2ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus) ||\r
4633                 (BT_8821A_2ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||\r
4634                 (BT_8821A_2ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )\r
4635         {\r
4636                 bBtBusy = TRUE;\r
4637                 bLimitedDig = TRUE;\r
4638         }\r
4639         else\r
4640         {\r
4641                 bBtBusy = FALSE;\r
4642                 bLimitedDig = FALSE;\r
4643         }\r
4644 \r
4645         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bBtBusy);\r
4646 \r
4647         pCoexDm->bLimitedDig = bLimitedDig;\r
4648         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_LIMITED_DIG, &bLimitedDig);\r
4649 \r
4650         halbtc8821a2ant_RunCoexistMechanism(pBtCoexist);\r
4651 }\r
4652 \r
4653 VOID\r
4654 EXhalbtc8821a2ant_HaltNotify(\r
4655         IN      PBTC_COEXIST                    pBtCoexist\r
4656         )\r
4657 {\r
4658         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Halt notify\n"));\r
4659 \r
4660         halbtc8821a2ant_WifiOffHwCfg(pBtCoexist);\r
4661         //remove due to interrupt is disabled that polling c2h will fail and delay 100ms.\r
4662         //pBtCoexist->fBtcSetBtReg(pBtCoexist, BTC_BT_REG_RF, 0x3c, 0x15); //BT goto standby while GNT_BT 1-->0\r
4663         halbtc8821a2ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, TRUE);\r
4664         \r
4665         EXhalbtc8821a2ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);\r
4666 }\r
4667 \r
4668 VOID\r
4669 EXhalbtc8821a2ant_PnpNotify(\r
4670         IN      PBTC_COEXIST                    pBtCoexist,\r
4671         IN      u1Byte                          pnpState\r
4672         )\r
4673 {\r
4674         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Pnp notify\n"));\r
4675 \r
4676         if(BTC_WIFI_PNP_SLEEP == pnpState)\r
4677         {\r
4678                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Pnp notify to SLEEP\n"));\r
4679         }\r
4680         else if(BTC_WIFI_PNP_WAKE_UP == pnpState)\r
4681         {\r
4682                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Pnp notify to WAKE UP\n"));\r
4683                 halbtc8821a2ant_InitHwConfig(pBtCoexist, FALSE);\r
4684                 halbtc8821a2ant_InitCoexDm(pBtCoexist);\r
4685                 halbtc8821a2ant_QueryBtInfo(pBtCoexist);\r
4686         }\r
4687 }\r
4688 \r
4689 VOID\r
4690 EXhalbtc8821a2ant_Periodical(\r
4691         IN      PBTC_COEXIST                    pBtCoexist\r
4692         )\r
4693 {\r
4694         //static u1Byte         disVerInfoCnt=0;\r
4695         u4Byte                          fwVer=0, btPatchVer=0;\r
4696         PBTC_BOARD_INFO         pBoardInfo=&pBtCoexist->boardInfo;\r
4697         PBTC_STACK_INFO         pStackInfo=&pBtCoexist->stackInfo;\r
4698 \r
4699         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ==========================Periodical===========================\n"));\r
4700 \r
4701         if(pCoexSta->disVerInfoCnt <= 5)\r
4702         {\r
4703                 pCoexSta->disVerInfoCnt += 1;\r
4704                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ****************************************************************\n"));\r
4705                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Ant PG Num/ Ant Mech/ Ant Pos = %d/ %d/ %d\n",\r
4706                         pBoardInfo->pgAntNum, pBoardInfo->btdmAntNum, pBoardInfo->btdmAntPos));\r
4707                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT stack/ hci ext ver = %s / %d\n",\r
4708                         ((pStackInfo->bProfileNotified)? "Yes":"No"), pStackInfo->hciVersion));\r
4709                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_BT_PATCH_VER, &btPatchVer);\r
4710                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);\r
4711                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CoexVer/ FwVer/ PatchVer = %d_%x/ 0x%x/ 0x%x(%d)\n",\r
4712                         GLCoexVerDate8821a2Ant, GLCoexVer8821a2Ant, fwVer, btPatchVer, btPatchVer));\r
4713                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ****************************************************************\n"));\r
4714 \r
4715                 if (pCoexSta->disVerInfoCnt == 3)\r
4716                 {\r
4717                         //Antenna config to set 0x765 = 0x0 (GNT_BT control by PTA) after initial \r
4718                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Set GNT_BT control by PTA\n"));\r
4719                         halbtc8821a2ant_SetAntPath(pBtCoexist, BTC_ANT_WIFI_AT_MAIN, FALSE, FALSE);\r
4720                 }\r
4721         }\r
4722 \r
4723 #if(BT_AUTO_REPORT_ONLY_8821A_2ANT == 0)\r
4724         halbtc8821a2ant_QueryBtInfo(pBtCoexist);        \r
4725         halbtc8821a2ant_MonitorBtEnableDisable(pBtCoexist);\r
4726 #else\r
4727         halbtc8821a2ant_MonitorBtCtr(pBtCoexist);\r
4728         halbtc8821a2ant_MonitorWiFiCtr(pBtCoexist);\r
4729         \r
4730         if( halbtc8821a2ant_IsWifiStatusChanged(pBtCoexist) ||\r
4731                 pCoexDm->bAutoTdmaAdjust)\r
4732         {\r
4733                 halbtc8821a2ant_RunCoexistMechanism(pBtCoexist);\r
4734         }\r
4735 #endif\r
4736 }\r
4737 \r
4738 \r
4739 #endif\r
4740 \r